title.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include <precomp.h>
  2. #include "title.h"
  3. #include <api/wndmgr/layout.h>
  4. #include <api/wnd/paintset.h>
  5. #include <api/skin/widgets/text.h>
  6. #include <api/locales/xlatstr.h>
  7. #include <api/wnd/cwndtrack.h>
  8. #include <api/util/varmgr.h>
  9. #include <api/wnd/PaintCanvas.h>
  10. #define DC_MAXIMIZE 0x9831
  11. const wchar_t titleBarXuiObjectStr[] = L"TitleBar"; // This is the xml tag
  12. char titleBarXuiSvcName[] = "TitleBar xui object"; // this is the name of the xuiservice
  13. XMLParamPair Title::params[] = {
  14. {TITLE_SETBORDER, L"BORDER"},
  15. {TITLE_SETDBLCLKACTION, L"DBLCLICKACTION"},
  16. {TITLE_SETMAXIMIZE, L"MAXIMIZE"},
  17. {TITLE_SETSTREAKS, L"STREAKS"},
  18. {TITLE_SETTITLE, L"TITLE"},
  19. };
  20. Title::Title()
  21. {
  22. getScriptObject()->vcpu_setInterface(titleGuid, (void *)static_cast<Title *>(this));
  23. getScriptObject()->vcpu_setClassName(L"Title");
  24. getScriptObject()->vcpu_setController(titleController);
  25. dostreaks = 1;
  26. doborder = 1;
  27. m_maximize = 0;
  28. getGuiObject()->guiobject_setMover(1);
  29. xuihandle = newXuiHandle();
  30. CreateXMLParameters(xuihandle);
  31. }
  32. void Title::CreateXMLParameters(int master_handle)
  33. {
  34. //TITLE_PARENT::CreateXMLParameters(master_handle);
  35. int numParams = sizeof(params) / sizeof(params[0]);
  36. hintNumberOfParams(xuihandle, numParams);
  37. for (int i = 0;i < numParams;i++)
  38. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  39. }
  40. Title::~Title()
  41. {}
  42. int Title::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *strval)
  43. {
  44. if (xuihandle != _xuihandle) return TITLE_PARENT::setXuiParam(_xuihandle, attrid, name, strval);
  45. switch (attrid)
  46. {
  47. case TITLE_SETTITLE:
  48. setTitle(strval);
  49. break;
  50. case TITLE_SETSTREAKS:
  51. setStreaks(WTOI(strval));
  52. break;
  53. case TITLE_SETBORDER:
  54. setBorder(WTOI(strval));
  55. break;
  56. case TITLE_SETMAXIMIZE:
  57. m_maximize = WTOI(strval);
  58. break;
  59. case TITLE_SETDBLCLKACTION:
  60. dblClickAction = strval;
  61. break;
  62. default:
  63. return 0;
  64. }
  65. return 1;
  66. }
  67. void Title::setStreaks(int s)
  68. {
  69. if (s == dostreaks) return ;
  70. dostreaks = s;
  71. invalidate();
  72. }
  73. void Title::setBorder(int b)
  74. {
  75. if (b == doborder) return ;
  76. doborder = b;
  77. invalidate();
  78. }
  79. int Title::getPreferences(int what)
  80. {
  81. if (what == SUGGESTED_W) return 128;
  82. if (what == SUGGESTED_H) return 22;
  83. return TITLE_PARENT::getPreferences(what);
  84. }
  85. int Title::onPaint(Canvas *canvas)
  86. {
  87. const wchar_t *tempname = title;
  88. //StringW tempname(title);
  89. PaintCanvas paintcanvas;
  90. if (canvas == NULL)
  91. {
  92. if (!paintcanvas.beginPaint(this)) return 0;
  93. canvas = &paintcanvas;
  94. }
  95. TITLE_PARENT::onPaint(canvas);
  96. #ifdef WA3COMPATIBILITY
  97. //tempname = PublicVarManager::translate(title, getGuiObject());
  98. #else
  99. tempname = title;
  100. #endif
  101. #ifdef WASABI_COMPILE_PAINTSETS
  102. RECT pr(TITLE_PARENT::clientRect());
  103. const wchar_t *t = NULL;
  104. switch(wantTranslation())
  105. {
  106. case 0:
  107. t = tempname;
  108. break;
  109. case 1:
  110. t = _(tempname);
  111. break;
  112. case 2:
  113. t = __(tempname);
  114. break;
  115. }
  116. paintset_renderTitle(t, canvas, &pr, getPaintingAlpha(), dostreaks, doborder);
  117. #endif
  118. return 1;
  119. }
  120. void Title::setTitle(const wchar_t *t)
  121. {
  122. title = t;
  123. title.toupper();
  124. }
  125. const wchar_t *Title::getTitle()
  126. {
  127. return title;
  128. }
  129. int Title::onLeftButtonDblClk(int x, int y)
  130. {
  131. if (m_maximize)
  132. postDeferredCallback(DC_MAXIMIZE, 0);
  133. else
  134. {
  135. #ifdef WASABI_COMPILE_WNDMGR
  136. if (dblClickAction)
  137. {
  138. const wchar_t *toCheck = L"SWITCH;";
  139. if (!WCSNICMP(dblClickAction, toCheck, 7))
  140. {
  141. onLeftButtonUp(x, y);
  142. getGuiObject()->guiobject_getParentGroup()->getParentContainer()->switchToLayout(dblClickAction.getValue() + 7);
  143. }
  144. }
  145. #endif
  146. }
  147. ifc_window *b = getParent();
  148. if (b)
  149. return b->onLeftButtonDblClk(x, y);
  150. return TITLE_PARENT::onLeftButtonDblClk(x, y);
  151. }
  152. int Title::onDeferredCallback(intptr_t param1, intptr_t param2)
  153. {
  154. switch (param1)
  155. {
  156. #ifdef WASABI_COMPILE_WNDMGR
  157. case DC_MAXIMIZE:
  158. Container *c = getGuiObject()->guiobject_getParentGroup()->getParentContainer();
  159. if (c)
  160. {
  161. Layout *l = c->getCurrentLayout();
  162. if (l)
  163. {
  164. if (l->isMaximized()) l->restore();
  165. else l->maximize();
  166. }
  167. }
  168. return 1;
  169. #endif
  170. }
  171. return TITLE_PARENT::onDeferredCallback(param1, param2);
  172. }
  173. TitleScriptController _titleController;
  174. TitleScriptController *titleController = &_titleController;
  175. // -- Functions table -------------------------------------
  176. function_descriptor_struct TitleScriptController::exportedFunction[] = {
  177. {L"fake", 0, (void*)Title::script_vcpu_fake },
  178. };
  179. const wchar_t *TitleScriptController::getClassName()
  180. {
  181. return L"Title";
  182. }
  183. const wchar_t *TitleScriptController::getAncestorClassName()
  184. {
  185. return L"GuiObject";
  186. }
  187. ScriptObject *TitleScriptController::instantiate()
  188. {
  189. Title *t = new Title;
  190. ASSERT(t != NULL);
  191. return t->getScriptObject();
  192. }
  193. void TitleScriptController::destroy(ScriptObject *o)
  194. {
  195. Title *t = static_cast<Title *>(o->vcpu_getInterface(titleGuid));
  196. ASSERT(t != NULL);
  197. delete t;
  198. }
  199. void *TitleScriptController::encapsulate(ScriptObject *o)
  200. {
  201. return NULL; // no encapsulation for title yet
  202. }
  203. void TitleScriptController::deencapsulate(void *o)
  204. {}
  205. int TitleScriptController::getNumFunctions()
  206. {
  207. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  208. }
  209. const function_descriptor_struct *TitleScriptController::getExportedFunctions()
  210. {
  211. return exportedFunction;
  212. }
  213. GUID TitleScriptController::getClassGuid()
  214. {
  215. return titleGuid;
  216. }
  217. const wchar_t *Title::vcpu_getClassName()
  218. {
  219. return L"Title";
  220. }
  221. scriptVar Title::script_vcpu_fake(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  222. {
  223. SCRIPT_FUNCTION_INIT
  224. RETURN_SCRIPT_VOID;
  225. }