GammaManagerAPI.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #include "GammaManagerAPI.h"
  2. #include "api.h"
  3. #include <api/syscb/callbacks/skincb.h>
  4. GammaManagerAPI::GammaManagerAPI()
  5. {
  6. curSetSel = NULL;
  7. inTransaction=0;
  8. }
  9. void GammaManagerAPI::StartTransaction()
  10. {
  11. inTransaction++;
  12. }
  13. void GammaManagerAPI::EndTransaction()
  14. {
  15. inTransaction--;
  16. if (inTransaction == 0)
  17. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::COLORTHEMESLISTCHANGED);
  18. }
  19. size_t GammaManagerAPI::getNumGammaSets()
  20. {
  21. return gammasets.size();
  22. }
  23. const wchar_t *GammaManagerAPI::enumGammaSet(size_t n)
  24. {
  25. return gammasets[n]->name;
  26. }
  27. int GammaManagerAPI::getNumGammaGroups(const wchar_t *gammaset)
  28. {
  29. if (gammaset == NULL || !*gammaset) return 0;
  30. for (size_t i = 0;i != gammasets.size();i++)
  31. {
  32. if (IsKeyword(gammasets[i]->name, gammaset))
  33. return (int)gammasets[i]->gammagroups.size();
  34. }
  35. return -1;
  36. }
  37. const wchar_t *GammaManagerAPI::enumGammaGroup(const wchar_t *gammaset, int n)
  38. {
  39. if (gammaset == NULL || !*gammaset) return 0;
  40. for (size_t i = 0;i != gammasets.size();i++)
  41. {
  42. if (IsKeyword(gammaset, gammasets[i]->name))
  43. {
  44. if (n < 0 || n >= (int)gammasets[i]->gammagroups.size())
  45. {
  46. return gammasets[i]->generalgroup.getName();
  47. }
  48. const wchar_t * ret = gammasets[i]->gammagroups[n]->getName();
  49. return ret;
  50. }
  51. }
  52. return NULL;
  53. }
  54. ColorThemeGroup *GammaManagerAPI::enumColorThemeGroup(int colorset, int colorgroup)
  55. {
  56. GammaSet *set = gammasets[colorset];
  57. if (set != NULL)
  58. {
  59. if (colorgroup < 0 || colorgroup >= (int)set->gammagroups.size())
  60. {
  61. return &set->generalgroup;
  62. }
  63. ColorThemeGroup *grp = set->gammagroups[colorgroup];
  64. return grp;
  65. }
  66. return NULL;
  67. }
  68. ColorThemeGroup *GammaManagerAPI::getColorThemeGroup(const wchar_t *colorset, const wchar_t *colorgroup)
  69. {
  70. for (size_t i = 0;i < gammasets.size();i++)
  71. {
  72. GammaSet *s = gammasets[i];
  73. if (IsKeyword(s->name, colorset))
  74. {
  75. if (IsKeyword(s->generalgroup.getName(), colorgroup))
  76. {
  77. ColorThemeGroupI *g = &s->generalgroup;
  78. return g;
  79. }
  80. for (size_t j = 0;j < s->gammagroups.size();j++)
  81. {
  82. ColorThemeGroupI *g = s->gammagroups[j];
  83. if (IsKeyword(g->getName(), colorgroup))
  84. {
  85. return g;
  86. }
  87. }
  88. }
  89. }
  90. return NULL;
  91. }
  92. void GammaManagerAPI::deleteAllGammaSets()
  93. {
  94. //gammasets.deleteAll();
  95. for (auto obj : gammasets)
  96. {
  97. delete obj;
  98. }
  99. gammasets.clear();
  100. curSetSel = NULL;
  101. }
  102. void GammaManagerAPI::deleteGammaSet(const wchar_t *set)
  103. {
  104. for (size_t i = 0;i < gammasets.size();i++)
  105. {
  106. if (IsKeyword(gammasets[i]->name, set))
  107. {
  108. GammaSet *s = gammasets[i];
  109. delete s;
  110. gammasets.erase(gammasets.begin() + i);
  111. i--;
  112. }
  113. }
  114. if (!inTransaction)
  115. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::COLORTHEMESLISTCHANGED);
  116. }
  117. void GammaManagerAPI::renameGammaSet( const wchar_t *set, const wchar_t *newname )
  118. {
  119. for ( GammaSet *l_gammaset : gammasets )
  120. {
  121. if ( IsKeyword( l_gammaset->name, set ) )
  122. {
  123. l_gammaset->SetName( newname );
  124. if ( !inTransaction )
  125. WASABI_API_SYSCB->syscb_issueCallback( SysCallback::SKINCB, SkinCallback::COLORTHEMESLISTCHANGED );
  126. return;
  127. }
  128. }
  129. }
  130. size_t GammaManagerAPI::newGammaSet(const wchar_t *set)
  131. {
  132. for (size_t i = 0;i != gammasets.size();i++)
  133. {
  134. if (IsKeyword(gammasets[i]->name, set))
  135. return i;
  136. }
  137. GammaSet *curset = new GammaSet(set);/*
  138. for (size_t i = 0;i < gammasets.size();i++)
  139. {
  140. for (size_t j = 0;j < gammasets[i]->gammagroups.size();j++)
  141. {
  142. ColorThemeGroup * g = gammasets[i]->gammagroups[j];
  143. if (curset->haveGroup(g->getName()))
  144. continue;
  145. curset->gammagroups.push_back(new ColorThemeGroupI(g->getName(), 0, 0, 0, 0, 0));
  146. }
  147. }*/
  148. size_t index = gammasets.size();
  149. gammasets.push_back(curset); //Martin> better add set after the loop than before
  150. if (!inTransaction)
  151. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::COLORTHEMESLISTCHANGED);
  152. return index;
  153. }
  154. void GammaManagerAPI::updateGammaSet(const wchar_t *set)
  155. {
  156. for (size_t i = 0;i < gammasets.size();i++)
  157. {
  158. GammaSet *s = gammasets[i];
  159. if (IsKeyword(s->name, set))
  160. {
  161. for (size_t i = 0;i < gammasets.size();i++)
  162. {
  163. for (size_t j = 0;j < gammasets[i]->gammagroups.size();j++)
  164. {
  165. ColorThemeGroup * g = gammasets[i]->gammagroups[j];
  166. if (s->haveGroup(g->getName())) continue;
  167. s->gammagroups.push_back(new ColorThemeGroupI(g->getName(), 0, 0, 0, 0, 0));
  168. }
  169. }
  170. }
  171. }
  172. }
  173. void GammaManagerAPI::setGammaSet(const wchar_t *set)
  174. {
  175. size_t i;
  176. for (i = 0;i != gammasets.size();i++)
  177. {
  178. if (IsKeyword(gammasets[i]->name, set))
  179. {
  180. setGammaSetInternal(gammasets[i]);
  181. return ;
  182. }
  183. }
  184. if (i) // i will still be 0 if getNumItems() was 0
  185. setGammaSetInternal(gammasets[0]);
  186. }
  187. void GammaManagerAPI::setGammaSetInternal(GammaSet *set)
  188. {
  189. //if (curSetSel == set) return;
  190. curSetSel = set;
  191. //PORT
  192. #ifdef WIN32
  193. SetCursor(LoadCursor(NULL, IDC_WAIT));
  194. #endif
  195. #ifdef LINUX
  196. XDefineCursor( Linux::getDisplay(), WASABI_API_WND->main_getRootWnd()->gethWnd(),
  197. XCreateFontCursor( Linux::getDisplay(), XC_watch ) );
  198. #endif
  199. if (WASABI_API_SKIN)
  200. WASABI_API_SKIN->reapplySkinFilters();
  201. //PORT
  202. #ifdef WIN32
  203. SetCursor(LoadCursor(NULL, IDC_ARROW));
  204. #endif
  205. #ifdef LINUX
  206. XUndefineCursor( Linux::getDisplay(), WASABI_API_WND->main_getRootWnd()->gethWnd() );
  207. #endif
  208. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::COLORTHEMECHANGED);
  209. }
  210. int GammaManagerAPI::getGammaForGroup(const wchar_t *group, int *r, int *g, int *b, int *gray, int *boost)
  211. {
  212. if (curSetSel)
  213. {
  214. size_t l = curSetSel->gammagroups.size();
  215. for (size_t i = 0;i < l;i++)
  216. {
  217. if (group && IsKeyword(group, curSetSel->gammagroups[i]->getName()))
  218. {
  219. *r = min(4095, max( -4095, curSetSel->gammagroups[i]->getRed() + curSetSel->generalgroup.getRed()));
  220. *g = min(4095, max( -4095, curSetSel->gammagroups[i]->getGreen() + curSetSel->generalgroup.getGreen()));
  221. *b = min(4095, max( -4095, curSetSel->gammagroups[i]->getBlue() + curSetSel->generalgroup.getBlue()));
  222. *gray = curSetSel->gammagroups[i]->getGray() | curSetSel->generalgroup.getGray();
  223. *boost = curSetSel->gammagroups[i]->getBoost() || curSetSel->generalgroup.getBoost();
  224. return 1;
  225. }
  226. }
  227. *r = min(4095, max( -4095, curSetSel->generalgroup.getRed()));
  228. *g = min(4095, max( -4095, curSetSel->generalgroup.getGreen()));
  229. *b = min(4095, max( -4095, curSetSel->generalgroup.getBlue()));
  230. *gray = curSetSel->generalgroup.getGray();
  231. *boost = curSetSel->generalgroup.getBoost();
  232. return 1;
  233. }
  234. return 0;
  235. }
  236. void GammaManagerAPI::resetGammaSet( const wchar_t *set )
  237. {
  238. for ( GammaSet *l_gammaset : gammasets )
  239. {
  240. if ( IsKeyword( l_gammaset->name, set ) )
  241. {
  242. //gammasets[i]->gammagroups.deleteAll();
  243. for ( ColorThemeGroupI *obj : l_gammaset->gammagroups )
  244. delete obj;
  245. l_gammaset->gammagroups.clear();
  246. break;
  247. }
  248. }
  249. }
  250. void GammaManagerAPI::addGammaGroup( const wchar_t *set, ColorThemeGroup *group )
  251. {
  252. for ( GammaSet *l_gammaset : gammasets )
  253. {
  254. if ( IsKeyword( l_gammaset->name, set ) )
  255. {
  256. for ( size_t j = 0; j < l_gammaset->gammagroups.size(); j++ )
  257. {
  258. ColorThemeGroupI *g = l_gammaset->gammagroups[ j ];
  259. if ( IsKeyword( g->getName(), group->getName() ) )
  260. {
  261. l_gammaset->gammagroups[ j ] = new ColorThemeGroupI( *group );
  262. delete g;
  263. return;
  264. }
  265. }
  266. l_gammaset->gammagroups.push_back( new ColorThemeGroupI( *group ) );
  267. break;
  268. }
  269. }
  270. }
  271. void GammaManagerAPI::addGammaGroup2(size_t i, ColorThemeGroup *group)
  272. {
  273. for (size_t j = 0;j < gammasets[i]->gammagroups.size();j++)
  274. {
  275. ColorThemeGroupI * g = gammasets[i]->gammagroups[j];
  276. if (IsKeyword(g->getName(), group->getName()))
  277. {
  278. gammasets[i]->gammagroups[j] = new ColorThemeGroupI(*group);
  279. delete g;
  280. return;
  281. }
  282. }
  283. gammasets[i]->gammagroups.push_back(new ColorThemeGroupI(*group));
  284. }
  285. const wchar_t *GammaManagerAPI::getGammaSet()
  286. {
  287. return curSetSel ? curSetSel->name : NULL;
  288. }
  289. #define CBCLASS ColorThemeGroupI
  290. START_DISPATCH;
  291. CB(COLORTHEMEGROUPGETNAME, getName);
  292. CB(COLORTHEMEGROUPGETRED, getRed);
  293. CB(COLORTHEMEGROUPGETGREEN, getGreen);
  294. CB(COLORTHEMEGROUPGETBLUE, getBlue);
  295. CB(COLORTHEMEGROUPGETGRAY, getGray);
  296. CB(COLORTHEMEGROUPGETBOOST, getBoost);
  297. VCB(COLORTHEMEGROUPSETNAME, setName);
  298. VCB(COLORTHEMEGROUPSETRED, setRed);
  299. VCB(COLORTHEMEGROUPSETGREEN, setGreen);
  300. VCB(COLORTHEMEGROUPSETBLUE, setBlue);
  301. VCB(COLORTHEMEGROUPSETGRAY, setGray);
  302. VCB(COLORTHEMEGROUPSETBOOST, setBoost);
  303. END_DISPATCH;
  304. #undef CBCLASS
  305. #define CBCLASS GammaManagerAPI
  306. START_DISPATCH;
  307. CB(API_COLORTHEMES_GETNUMGAMMASETS, getNumGammaSets);
  308. CB(API_COLORTHEMES_ENUMGAMMASET, enumGammaSet);
  309. VCB(API_COLORTHEMES_DELETEGAMMASET, deleteGammaSet);
  310. VCB(API_COLORTHEMES_DELETEALLGAMMASETS, deleteAllGammaSets);
  311. VCB(API_COLORTHEMES_RESETGAMMASET, resetGammaSet);
  312. VCB(API_COLORTHEMES_RENAMEGAMMASET, renameGammaSet);
  313. CB(API_COLORTHEMES_NEWGAMMASET, newGammaSet);
  314. VCB(API_COLORTHEMES_UPDATEGAMMASET, updateGammaSet);
  315. CB(API_COLORTHEMES_GETNUMGAMMAGROUPS, getNumGammaGroups);
  316. CB(API_COLORTHEMES_ENUMGAMMAGROUP, enumGammaGroup);
  317. CB(API_COLORTHEMES_ENUMCOLORTHEMEGROUP, enumColorThemeGroup);
  318. CB(API_COLORTHEMES_GETCOLORTHEMEGROUP, getColorThemeGroup);
  319. CB(API_COLORTHEMES_GETGAMMAFORGROUP, getGammaForGroup);
  320. VCB(API_COLORTHEMES_ADDGAMMAGROUP, addGammaGroup);
  321. VCB(API_COLORTHEMES_ADDGAMMAGROUP2, addGammaGroup2);
  322. CB(API_COLORTHEMES_GETGAMMASET, getGammaSet);
  323. VCB(API_COLORTHEMES_SETGAMMASET, setGammaSet);
  324. VCB(API_COLORTHEMES_STARTTRANSACTION, StartTransaction);
  325. VCB(API_COLORTHEMES_ENDTRANSACTION, EndTransaction);
  326. END_DISPATCH;
  327. #undef CBCLASS