xuiframe.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #include <precomp.h>
  2. #include "xuiframe.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <api/script/scriptguid.h>
  5. const wchar_t ScriptFrameXuiObjectStr[] = L"Wasabi:Frame"; // This is the xml tag
  6. char ScriptFrameXuiSvcName[] = "Wasabi:ScriptFrame xui object";
  7. XMLParamPair ScriptFrame::params[] = {
  8. {SCRIPTFRAME_SETORIENTATION, L"ORIENTATION"},
  9. {SCRIPTFRAME_SETLEFT, L"LEFT"}, // TOP/BOTTOM IS ALIAS FOR LEFT/RIGHT
  10. {SCRIPTFRAME_SETLEFT, L"TOP"},
  11. {SCRIPTFRAME_SETRIGHT, L"RIGHT"},
  12. {SCRIPTFRAME_SETRIGHT, L"BOTTOM"},
  13. {SCRIPTFRAME_SETFROM, L"FROM"},
  14. {SCRIPTFRAME_SETWIDTH, L"WIDTH"},
  15. {SCRIPTFRAME_SETWIDTH, L"HEIGHT"}, // HEIGHT IS AN ALIAS FOR WIDTH
  16. {SCRIPTFRAME_SETRESIZEABLE, L"RESIZABLE"},
  17. {SCRIPTFRAME_SETMAXWIDTH, L"MAXWIDTH"},
  18. {SCRIPTFRAME_SETMAXWIDTH, L"MAXHEIGHT"}, //ALIAS
  19. {SCRIPTFRAME_SETMINWIDTH, L"MINWIDTH"},
  20. {SCRIPTFRAME_SETMINWIDTH, L"MINHEIGHT"}, //ALIAS
  21. {SCRIPTFRAME_SETV_BITMAP, L"VBITMAP"}, // to override wasabi.framewnd.verticaldivider
  22. {SCRIPTFRAME_SETV_GRABBER, L"VGRABBER"}, // to override wasabi.framewnd.verticalgrabber
  23. };
  24. ScriptFrame::ScriptFrame()
  25. {
  26. getScriptObject()->vcpu_setInterface(scriptFrameGuid, (void *)static_cast<ScriptFrame *>(this));
  27. getScriptObject()->vcpu_setClassName(L"Frame");
  28. getScriptObject()->vcpu_setController(frameController);
  29. setVirtual(1);
  30. myxuihandle = newXuiHandle();
  31. CreateXMLParameters(myxuihandle);
  32. orientation = DIVIDER_VERTICAL;
  33. from = SDP_FROMLEFT;
  34. resizable = 1;
  35. width = 128;
  36. rootwndleft = rootwndright = NULL;
  37. }
  38. void ScriptFrame::CreateXMLParameters(int master_handle)
  39. {
  40. //SCRIPTFRAME_PARENT::CreateXMLParameters(master_handle);
  41. int numParams = sizeof(params) / sizeof(params[0]);
  42. hintNumberOfParams(myxuihandle, numParams);
  43. for (int i = 0;i < numParams;i++)
  44. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  45. }
  46. ScriptFrame::~ScriptFrame() {
  47. if (rootwndright) {
  48. WASABI_API_SKIN->group_destroy(rootwndright);
  49. rootwndright = NULL;
  50. }
  51. if (rootwndleft) {
  52. WASABI_API_SKIN->group_destroy(rootwndleft);
  53. rootwndleft = NULL;
  54. }
  55. }
  56. // XuiObject automatically calls this back for all parameters registered using addParam
  57. // encountered in the xml source
  58. int ScriptFrame::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  59. if (xuihandle != myxuihandle)
  60. return SCRIPTFRAME_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  61. switch (xmlattributeid) {
  62. case SCRIPTFRAME_SETORIENTATION: setOrientation(value); break;
  63. case SCRIPTFRAME_SETLEFT: setLeft(value); break;
  64. case SCRIPTFRAME_SETRIGHT: setRight(value); break;
  65. case SCRIPTFRAME_SETFROM: setFrom(value); break;
  66. case SCRIPTFRAME_SETWIDTH: setWidth(value); break;
  67. case SCRIPTFRAME_SETRESIZEABLE: setResize(value); break;
  68. case SCRIPTFRAME_SETMAXWIDTH: setMaxWidth((!_wcsicmp(value, L"null")) ? 0 : WTOI(value)); break;
  69. case SCRIPTFRAME_SETMINWIDTH: setMinWidth(WTOI(value)); break;
  70. case SCRIPTFRAME_SETSNAP: setSnap(WTOI(value)); break;
  71. case SCRIPTFRAME_SETV_BITMAP:
  72. Set_v_bitmap(value);
  73. break;
  74. case SCRIPTFRAME_SETV_GRABBER:
  75. Set_v_grabber(value);
  76. break;
  77. default:
  78. return 0;
  79. }
  80. return 1;
  81. }
  82. int ScriptFrame::onInit()
  83. {
  84. if (!left.isempty()) rootwndleft = WASABI_API_SKIN->group_create(left);
  85. if (!right.isempty()) rootwndright = WASABI_API_SKIN->group_create(right);
  86. /* GuiObject *gl = rootwndleft ? static_cast<GuiObject *>(rootwndleft->getInterface(guiObjectGuid)) : NULL;
  87. GuiObject *gr = rootwndright ? static_cast<GuiObject *>(rootwndleft->getInterface(guiObjectGuid)) : NULL;
  88. if (gl) gl->guiobject_setParentGroup(getGuiObject()->guiobject_getParentGroup());
  89. if (gr) gr->guiobject_setParentGroup(getGuiObject()->guiobject_getParentGroup());*/
  90. if (rootwndleft) rootwndleft->setParent(this);
  91. if (rootwndright) rootwndright->setParent(this);
  92. setChildrenRootWnd(rootwndleft, rootwndright);
  93. setDividerType(static_cast<FrameWndDividerType>(orientation));
  94. setDividerPos(from, width);
  95. setResizeable(resizable);
  96. SCRIPTFRAME_PARENT::onInit();
  97. return 1;
  98. }
  99. void ScriptFrame::onResizeChildren(RECT leftr, RECT rightr) {
  100. /* if (rootwndleft) rootwndleft->invalidate();
  101. if (rootwndright) rootwndright->invalidate();*/
  102. invalidate();
  103. }
  104. void ScriptFrame::setOrientation(const wchar_t *orient) {
  105. if (!WCSICMP(orient, L"v") || !WCSICMP(orient, L"vertical"))
  106. orientation = DIVIDER_VERTICAL;
  107. if (!WCSICMP(orient, L"h") || !WCSICMP(orient, L"horizontal"))
  108. orientation = DIVIDER_HORIZONTAL;
  109. }
  110. void ScriptFrame::setLeft(const wchar_t *groupname) {
  111. left = groupname;
  112. }
  113. void ScriptFrame::setRight(const wchar_t *groupname) {
  114. right = groupname;
  115. }
  116. void ScriptFrame::setFrom(const wchar_t *f) {
  117. if (!WCSICMP(f, L"l") || !WCSICMP(f, L"left") || !WCSICMP(f, L"t") || !WCSICMP(f, L"top"))
  118. from = SDP_FROMLEFT;
  119. if (!WCSICMP(f, L"r") || !WCSICMP(f, L"right") || !WCSICMP(f, L"b") || !WCSICMP(f, L"bottom"))
  120. from = SDP_FROMRIGHT;
  121. }
  122. void ScriptFrame::setWidth(const wchar_t *w) {
  123. width = WTOI(w);
  124. }
  125. void ScriptFrame::setResize(const wchar_t *w) {
  126. resizable = WTOI(w);
  127. if (isInited())
  128. setResizeable(resizable);
  129. }
  130. FrameScriptController _frameController;
  131. FrameScriptController *frameController = &_frameController;
  132. // -- Functions table -------------------------------------
  133. function_descriptor_struct FrameScriptController::exportedFunction[] =
  134. {
  135. {L"setPosition", 1, (void*)ScriptFrame::script_vcpu_setPosition },
  136. {L"getPosition", 0, (void*)ScriptFrame::script_vcpu_getPosition },
  137. };
  138. // --------------------------------------------------------
  139. const wchar_t *FrameScriptController::getClassName()
  140. {
  141. return L"Frame";
  142. }
  143. const wchar_t *FrameScriptController::getAncestorClassName()
  144. {
  145. return L"GuiObject";
  146. }
  147. ScriptObject *FrameScriptController::instantiate()
  148. {
  149. ScriptFrame *t = new ScriptFrame;
  150. ASSERT(t != NULL);
  151. return t->getScriptObject();
  152. }
  153. void FrameScriptController::destroy(ScriptObject *o)
  154. {
  155. ScriptFrame *t = static_cast<ScriptFrame *>(o->vcpu_getInterface(scriptFrameGuid));
  156. ASSERT(t != NULL);
  157. delete t;
  158. }
  159. void *FrameScriptController::encapsulate(ScriptObject *o)
  160. {
  161. return NULL; // no encapsulation for Wasabi:Frame yet
  162. }
  163. void FrameScriptController::deencapsulate(void *o)
  164. {}
  165. int FrameScriptController::getNumFunctions()
  166. {
  167. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  168. }
  169. const function_descriptor_struct *FrameScriptController::getExportedFunctions()
  170. {
  171. return exportedFunction;
  172. }
  173. GUID FrameScriptController::getClassGuid()
  174. {
  175. return scriptFrameGuid;
  176. }
  177. const wchar_t *ScriptFrame::vcpu_getClassName()
  178. {
  179. return L"Frame";
  180. }
  181. scriptVar ScriptFrame::script_vcpu_setPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar t)
  182. {
  183. SCRIPT_FUNCTION_INIT
  184. ASSERT(t.type == SCRIPT_INT);
  185. ScriptFrame *fr = static_cast<ScriptFrame *>(o->vcpu_getInterface(scriptFrameGuid));
  186. if (fr)
  187. fr->setDividerPosNoCfg(fr->from, ::GET_SCRIPT_INT(t));
  188. RETURN_SCRIPT_VOID;
  189. }
  190. scriptVar ScriptFrame::script_vcpu_getPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  191. {
  192. SCRIPT_FUNCTION_INIT
  193. ScriptFrame *fr = static_cast<ScriptFrame *>(o->vcpu_getInterface(scriptFrameGuid));
  194. if (fr)
  195. {
  196. int pos, from;
  197. fr->getDividerPos(&from, &pos);
  198. return MAKE_SCRIPT_INT(pos);
  199. }
  200. return MAKE_SCRIPT_INT(0);
  201. }