xuithemeslist.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. #include <precomp.h>
  2. #include "xuithemeslist.h"
  3. #include <api/wnd/popup.h>
  4. #include "../Agave/Language/api_language.h"
  5. #include "resource.h"
  6. #ifndef _WASABIRUNTIME
  7. BEGIN_SERVICES(ColorThemesList_Svc);
  8. DECLARE_SERVICE(XuiObjectCreator<ColorThemesListXuiSvc>);
  9. DECLARE_SERVICE(XuiObjectCreator<NakedColorThemesListXuiSvc>);
  10. DECLARE_SERVICE(ActionCreator<ThemesSlotActionSvc>);
  11. END_SERVICES(ColorThemesList_Svc, _ColorThemesList_Svc);
  12. #ifdef _X86_
  13. extern "C" { int _link_ColorThemesListXuiSvc; }
  14. #else
  15. extern "C" { int __link_ColorThemesListXuiSvc; }
  16. #endif
  17. #endif
  18. int ThemesSlotActionSvc::onActionId(int pvtid, const wchar_t *action, const wchar_t *param, int p1, int p2, void *data, int datalen, ifc_window *source) {
  19. PopupMenu p_load;
  20. for (int i=0;i<10;i++)
  21. {
  22. StringW s = ColorThemesList::getSlot(i), no_set = WASABI_API_LNGSTRINGW(IDS_NO_SET);
  23. p_load.addCommand(StringPrintfW(WASABI_API_LNGSTRINGW(IDS_SLOT_X_X), i+1, s.isempty() ? no_set/*L"no set"*/ : s), 200+i, 0, s.isempty());
  24. }
  25. int r = p_load.popAtMouse();
  26. if (r >= 200 && r < 210)
  27. {
  28. StringW set = ColorThemesList::getSlot(r-200);
  29. if (!set.isempty())
  30. WASABI_API_SKIN->colortheme_setColorSet(set);
  31. }
  32. return 1;
  33. }
  34. // -----------------------------------------------------------------------
  35. const wchar_t ColorThemesListXuiObjectStr[] = L"ColorThemes:List"; // This is the xml tag
  36. char ColorThemesListXuiSvcName[] = "ColorThemes:List xui object";
  37. const wchar_t NakedColorThemesListXuiObjectStr[] = L"ColorThemes:Mgr"; // This is the xml tag
  38. char NakedColorThemesListXuiSvcName[] = "ColorThemes:Mgr xui object";
  39. XMLParamPair ColorThemesList::params[] = {
  40. {CTLIST_NOHSCROLL, L"NOHSCROLL"},
  41. };
  42. // -----------------------------------------------------------------------
  43. ColorThemesList::ColorThemesList() {
  44. setPreventMultipleSelection(1);
  45. ensure_on_paint = -1;
  46. setAutoSort(1);
  47. nohscroll = 0;
  48. xuihandle = newXuiHandle();
  49. CreateXMLParameters(xuihandle);
  50. WASABI_API_SYSCB->syscb_registerCallback(static_cast<SkinCallbackI*>(this));
  51. }
  52. void ColorThemesList::CreateXMLParameters(int master_handle)
  53. {
  54. //THEMESLIST_PARENT::CreateXMLParameters(master_handle);
  55. int numParams = sizeof(params) / sizeof(params[0]);
  56. hintNumberOfParams(xuihandle, numParams);
  57. for (int i = 0;i < numParams;i++)
  58. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  59. }
  60. // -----------------------------------------------------------------------
  61. ColorThemesList::~ColorThemesList() {
  62. WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<SkinCallbackI*>(this));
  63. }
  64. // -----------------------------------------------------------------------
  65. NakedColorThemesList::NakedColorThemesList() {
  66. xuihandle = newXuiHandle();
  67. WASABI_API_SYSCB->syscb_registerCallback(static_cast<SkinCallbackI*>(this));
  68. }
  69. // -----------------------------------------------------------------------
  70. NakedColorThemesList::~NakedColorThemesList() {
  71. items.deleteAll();
  72. WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<SkinCallbackI*>(this));
  73. }
  74. // -----------------------------------------------------------------------
  75. int ColorThemesList::onInit() {
  76. THEMESLIST_PARENT::onInit();
  77. addColumn(L"Theme",250);
  78. //loadThemes();
  79. return 1;
  80. }
  81. // -----------------------------------------------------------------------
  82. int ColorThemesList::onResize() {
  83. THEMESLIST_PARENT::onResize();
  84. if (nohscroll) {
  85. RECT r;
  86. getClientRect(&r);
  87. ListColumn *col = getColumn(0);
  88. col->setWidth(r.right-r.left-4);
  89. }
  90. return 1;
  91. }
  92. // -----------------------------------------------------------------------
  93. void ColorThemesList::onDoubleClick(int itemnum) {
  94. colorthemes_switch();
  95. }
  96. // -----------------------------------------------------------------------
  97. int ColorThemesList::onRightClick(int itemnum) {
  98. THEMESLIST_PARENT::onRightClick(itemnum);
  99. PopupMenu p_save;
  100. PopupMenu p_load;
  101. PopupMenu p;
  102. StringW no_set = WASABI_API_LNGSTRINGW(IDS_NO_SET);
  103. for (int i=0;i<10;i++)
  104. {
  105. StringW s = getSlot(i);
  106. p_save.addCommand(StringPrintfW(WASABI_API_LNGSTRINGW(IDS_SLOT_X_X), i+1, s.isempty() ? no_set : s), 100+i);
  107. }
  108. for (int i=0;i<10;i++) {
  109. StringW s = getSlot(i);
  110. p_load.addCommand(StringPrintfW(WASABI_API_LNGSTRINGW(IDS_SLOT_X_X), i+1, s.isempty() ? no_set : s), 200+i, 0, s.isempty());
  111. }
  112. p.addSubMenu(&p_load, WASABI_API_LNGSTRINGW(IDS_XUITHEME_LOAD));
  113. p.addSubMenu(&p_save, WASABI_API_LNGSTRINGW(IDS_XUITHEME_SAVE));
  114. int r = p.popAtMouse();
  115. if (r >= 100 && r < 110) {
  116. int sel = getFirstItemSelected();
  117. if (sel >= 0) {
  118. wchar_t set[256+11]=L"";
  119. getItemLabel(sel, 0, set, 255); set[255] = 0;
  120. int p = (getItemData(sel) & 0xFFFF0000) >> 16;
  121. if (p)
  122. WCSCPYN(set, StringPrintfW(L"{coloredit}%s", set), 255+11);
  123. setSlot(r-100, set);
  124. }
  125. }
  126. else if (r >= 200 && r < 210) {
  127. StringW set = getSlot(r-200);
  128. if (!set.isempty())
  129. WASABI_API_SKIN->colortheme_setColorSet(set);
  130. }
  131. return 1;
  132. }
  133. void ColorThemesList::setSlot(int i, const wchar_t *set) {
  134. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"%s/slot%d", WASABI_API_SKIN->getSkinName(), i+1), set);
  135. }
  136. const wchar_t *ColorThemesList::getSlot(int i) {
  137. static wchar_t set[256]=L"";
  138. WASABI_API_CONFIG->getStringPrivate(StringPrintfW(L"%s/slot%d", WASABI_API_SKIN->getSkinName(), i+1), set, 256, L"");
  139. return set;
  140. }
  141. // -----------------------------------------------------------------------
  142. int ColorThemesList::onAction(const wchar_t *action, const wchar_t *param, int x, int y, intptr_t p1, intptr_t p2, void *data, size_t datalen, ifc_window *source) {
  143. if (!_wcsicmp(action, L"colorthemes_switch")) { colorthemes_switch(); return 1; }
  144. if (!_wcsicmp(action, L"colorthemes_next")) { colorthemes_next(); return 1; }
  145. if (!_wcsicmp(action, L"colorthemes_previous")) { colorthemes_previous(); return 1; }
  146. return THEMESLIST_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
  147. }
  148. // -----------------------------------------------------------------------
  149. int NakedColorThemesList::onAction(const wchar_t *action, const wchar_t *param, int x, int y, intptr_t p1, intptr_t p2, void *data, size_t datalen, ifc_window *source) {
  150. if (!_wcsicmp(action, L"colorthemes_next")) { colorthemes_next(); return 1; }
  151. if (!_wcsicmp(action, L"colorthemes_previous")) { colorthemes_previous(); return 1; }
  152. return THEMESLIST2_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
  153. }
  154. // -----------------------------------------------------------------------
  155. void ColorThemesList::colorthemes_switch() {
  156. int sel = getFirstItemSelected();
  157. if (sel >= 0) {
  158. wchar_t set[256+11]=L"";
  159. getItemLabel(sel, 0, set, 255); set[255] = 0;
  160. int p = (getItemData(sel) & 0xFFFF0000) >> 16;
  161. if (p)
  162. WCSCPYN(set, StringPrintfW(L"{coloredit}%s", set), 255+11);
  163. WASABI_API_SKIN->colortheme_setColorSet(set);
  164. }
  165. }
  166. // -----------------------------------------------------------------------
  167. void ColorThemesList::colorthemes_advance(int n)
  168. {
  169. StringW curs = WASABI_API_SKIN->colortheme_getColorSet();
  170. curs.trunc(255);
  171. wchar_t txt[256+11] = {0};
  172. int i;
  173. for (i=0;i<getNumItems();i++)
  174. {
  175. getItemLabel(i, 0, txt, 255);
  176. int p = (getItemData(i) & 0xFFFF0000) >> 16;
  177. txt[256] = 0;
  178. if (p)
  179. WCSCPYN(txt, StringPrintfW(L"{coloredit}%s", txt), 255+11);
  180. if (!_wcsicmp(txt, curs))
  181. break;
  182. }
  183. if (i >= WASABI_API_SKIN->colortheme_getNumColorSets()) return;
  184. i += n;
  185. if (i < 0) i = WASABI_API_SKIN->colortheme_getNumColorSets()-1;
  186. i %= WASABI_API_SKIN->colortheme_getNumColorSets();
  187. getItemLabel(i, 0, txt, 255); txt[255] = 0;
  188. int p = (getItemData(i) & 0xFFFF0000) >> 16;
  189. if (p)
  190. WCSCPYN(txt, StringPrintfW(L"{coloredit}%s", txt), 255+11);
  191. ensure_on_paint = i;
  192. WASABI_API_SKIN->colortheme_setColorSet(txt);
  193. invalidate();
  194. }
  195. // -----------------------------------------------------------------------
  196. int ColorThemesList::getTextBold(LPARAM lParam) {
  197. if (WCSCASEEQLSAFE(WASABI_API_SKIN->colortheme_enumColorSet(lParam & 0xFFFF), WASABI_API_SKIN->colortheme_getColorSet())) return 1;
  198. return THEMESLIST_PARENT::getTextBold(lParam);
  199. }
  200. // -----------------------------------------------------------------------
  201. void ColorThemesList::colorthemes_next() {
  202. colorthemes_advance(1);
  203. }
  204. // -----------------------------------------------------------------------
  205. void ColorThemesList::colorthemes_previous() {
  206. colorthemes_advance(-1);
  207. }
  208. // -----------------------------------------------------------------------
  209. void NakedColorThemesList::colorthemes_advance(int n) {
  210. StringW curs = WASABI_API_SKIN->colortheme_getColorSet();
  211. curs.trunc(255);
  212. wchar_t txt[256+11] = {0};
  213. int i;
  214. for (i=0;i<items.getNumItems();i++)
  215. {
  216. WCSCPYN(txt, items.enumItem(i)->getName(), 256);
  217. int p = (items.enumItem(i)->getData() & 0xFFFF0000) >> 16;
  218. txt[256] = 0;
  219. if (p)
  220. {
  221. WCSCPYN(txt, StringPrintfW(L"{coloredit}%s", txt), 255+11);
  222. }
  223. if (!_wcsicmp(txt, curs))
  224. break;
  225. }
  226. if (i >= WASABI_API_SKIN->colortheme_getNumColorSets()) return;
  227. i += n;
  228. if (i < 0) i = WASABI_API_SKIN->colortheme_getNumColorSets()-1;
  229. i %= WASABI_API_SKIN->colortheme_getNumColorSets();
  230. WCSCPYN(txt, items.enumItem(i)->getName(), 256);
  231. int p = (items.enumItem(i)->getData() & 0xFFFF0000) >> 16;
  232. if (p)
  233. {
  234. WCSCPYN(txt, StringPrintfW(L"{coloredit}%s", txt), 255+11);
  235. }
  236. WASABI_API_SKIN->colortheme_setColorSet(txt);
  237. }
  238. // -----------------------------------------------------------------------
  239. void NakedColorThemesList::colorthemes_next() {
  240. colorthemes_advance(1);
  241. }
  242. // -----------------------------------------------------------------------
  243. void NakedColorThemesList::colorthemes_previous() {
  244. colorthemes_advance(-1);
  245. }
  246. // -----------------------------------------------------------------------
  247. void ColorThemesList::onSetVisible(int show) {
  248. THEMESLIST_PARENT::onSetVisible(show);
  249. if (show) loadThemes();
  250. else getDesktopParent()->setFocus();
  251. }
  252. // -----------------------------------------------------------------------
  253. void NakedColorThemesList::onSetVisible(int show) {
  254. THEMESLIST2_PARENT::onSetVisible(show);
  255. if (show) loadThemes();
  256. }
  257. // -----------------------------------------------------------------------
  258. void ColorThemesList::loadThemes()
  259. {
  260. setAutoSort(0);
  261. deleteAllItems();
  262. const wchar_t *curset = WASABI_API_SKIN->colortheme_getColorSet();
  263. for (int i=0;i<WASABI_API_SKIN->colortheme_getNumColorSets();i++) {
  264. const wchar_t *set = WASABI_API_SKIN->colortheme_enumColorSet(i);
  265. int p = 0;
  266. if (!_wcsnicmp(set, L"{coloredit}", 11)) {
  267. set += 11;
  268. p = 1 << 16;
  269. }
  270. addItem(set, p | i);
  271. }
  272. setAutoSort(1);
  273. resort();
  274. if (curset != NULL) {
  275. wchar_t set[256+11]=L"";
  276. for (int i=0;i<WASABI_API_SKIN->colortheme_getNumColorSets();i++)
  277. {
  278. getItemLabel(i, 0, set, 255); set[255]=0;
  279. int p = (getItemData(i) & 0xFFFF0000) >> 16;
  280. if (p)
  281. WCSCPYN(set, StringPrintfW(L"{coloredit}%s", set), 255+11);
  282. if (set && !_wcsicmp(curset,set))
  283. {
  284. setSelected(i, 1);
  285. ensureItemVisible(i);
  286. return;
  287. }
  288. }
  289. }
  290. }
  291. // -----------------------------------------------------------------------
  292. void NakedColorThemesList::loadThemes()
  293. {
  294. items.setAutoSort(0);
  295. items.deleteAll();
  296. //CUT: const wchar_t *curset = WASABI_API_SKIN->colortheme_getColorSet();
  297. for (int i=0;i<WASABI_API_SKIN->colortheme_getNumColorSets();i++)
  298. {
  299. const wchar_t *set = WASABI_API_SKIN->colortheme_enumColorSet(i);
  300. int p = 0;
  301. if (!_wcsnicmp(set, L"{coloredit}", 11))
  302. {
  303. set += 11;
  304. p = 1 << 16;
  305. }
  306. NakedItem *n = new NakedItem(set, p|i);
  307. items.addItem(n);
  308. }
  309. items.setAutoSort(1);
  310. items.sort(TRUE);
  311. }
  312. // -----------------------------------------------------------------------
  313. int ColorThemesList::setXuiParam(int _xuihandle, int xmlattrid, const wchar_t *name, const wchar_t *value) {
  314. if (xuihandle == _xuihandle) {
  315. switch (xmlattrid) {
  316. case CTLIST_NOHSCROLL: nohscroll = WTOI(value); return 1;
  317. }
  318. }
  319. return THEMESLIST_PARENT::setXuiParam(_xuihandle, xmlattrid, name, value);
  320. }
  321. int ColorThemesList::onPaint(Canvas *canvas) {
  322. if (ensure_on_paint > -1) ensureItemVisible(ensure_on_paint);
  323. ensure_on_paint = -1;
  324. THEMESLIST_PARENT::onPaint(canvas);
  325. return 1;
  326. }