1
0

xuitabsheet.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include <precomp.h>
  2. #include "xuitabsheet.h"
  3. #include <bfc/parse/paramparser.h>
  4. static ScriptTabSheetController TabsheetController;
  5. ScriptTabSheetController *tabsheetController=&TabsheetController;
  6. // -----------------------------------------------------------------------
  7. const wchar_t ScriptTabSheetXuiObjectStr[] = L"Wasabi:TabSheet"; // This is the xml tag
  8. char ScriptTabSheetXuiSvcName[] = "Wasabi:TabSheet xui object";
  9. XMLParamPair ScriptTabSheet::params[] = {
  10. {SCRIPTTABSHEET_SETCHILDREN, L"CHILDREN"},
  11. {SCRIPTTABSHEET_SETCONTENTMARGINBOTTOM, L"CONTENT_MARGIN_BOTTOM"},
  12. {SCRIPTTABSHEET_SETCONTENTMARGINLEFT, L"CONTENT_MARGIN_LEFT"},
  13. {SCRIPTTABSHEET_SETCONTENTMARGINRIGHT, L"CONTENT_MARGIN_RIGHT"},
  14. {SCRIPTTABSHEET_SETCONTENTMARGINTOP, L"CONTENT_MARGIN_TOP"},
  15. {SCRIPTTABSHEET_SETTYPE, L"TYPE"},
  16. {SCRIPTTABSHEET_SETWINDOWTYPE, L"WINDOWTYPE"},
  17. };
  18. // -----------------------------------------------------------------------
  19. ScriptTabSheet::ScriptTabSheet() : TypeSheet(0) {
  20. getScriptObject()->vcpu_setInterface(tabsheetGuid, (void *)static_cast<ScriptTabSheet*>(this));
  21. getScriptObject()->vcpu_setClassName(L"TabSheet"); // this is the script class name
  22. getScriptObject()->vcpu_setController(tabsheetController);
  23. myxuihandle = newXuiHandle();
  24. CreateXMLParameters(myxuihandle);
  25. wndtype = 0;
  26. type = TABSHEET_GROUPS;
  27. left_margin = right_margin = bottom_margin = top_margin = 0;
  28. }
  29. void ScriptTabSheet::CreateXMLParameters(int master_handle)
  30. {
  31. //SCRIPTTABSHEET_PARENT::CreateXMLParameters(master_handle);
  32. int numParams = sizeof(params) / sizeof(params[0]);
  33. hintNumberOfParams(myxuihandle, numParams);
  34. for (int i = 0;i < numParams;i++)
  35. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  36. }
  37. // -----------------------------------------------------------------------
  38. ScriptTabSheet::~ScriptTabSheet() {
  39. children_id.deleteAll();
  40. }
  41. // -----------------------------------------------------------------------
  42. int ScriptTabSheet::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value)
  43. {
  44. if (xuihandle != myxuihandle)
  45. return SCRIPTTABSHEET_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  46. switch (xmlattributeid)
  47. {
  48. case SCRIPTTABSHEET_SETWINDOWTYPE:
  49. setWindowType(value);
  50. break;
  51. case SCRIPTTABSHEET_SETCHILDREN:
  52. setChildrenIds(value);
  53. break;
  54. case SCRIPTTABSHEET_SETTYPE:
  55. setType(value);
  56. break;
  57. case SCRIPTTABSHEET_SETCONTENTMARGINLEFT:
  58. case SCRIPTTABSHEET_SETCONTENTMARGINTOP:
  59. case SCRIPTTABSHEET_SETCONTENTMARGINRIGHT:
  60. case SCRIPTTABSHEET_SETCONTENTMARGINBOTTOM:
  61. setContentMarginX(value, xmlattributeid);
  62. break;
  63. default:
  64. return 0;
  65. }
  66. return 1;
  67. }
  68. // -----------------------------------------------------------------------
  69. void ScriptTabSheet::setWindowType(const wchar_t *paramvalue) {
  70. if (WCSEQLSAFE(wndtype, paramvalue)) return;
  71. wndtype = paramvalue;
  72. reloadChildren();
  73. }
  74. // -----------------------------------------------------------------------
  75. void ScriptTabSheet::setChildrenIds(const wchar_t *paramvalue) {
  76. if (WCSEQLSAFE(paramvalue, L"")) {
  77. children_id.removeAll();
  78. }
  79. ParamParser pp(paramvalue);
  80. for (int i=0;i<pp.getNumItems();i++)
  81. children_id.addItem(new StringW(pp.enumItem(i)));
  82. reloadChildren();
  83. }
  84. // -----------------------------------------------------------------------
  85. void ScriptTabSheet::setType(const wchar_t *paramvalue) {
  86. int ttype = WTOI(paramvalue);
  87. if (type == ttype) return;
  88. type = ttype;
  89. setButtonType(type);
  90. }
  91. // -----------------------------------------------------------------------
  92. void ScriptTabSheet::reloadChildren() {
  93. if (!isInited()) return;
  94. killChildren();
  95. for (int i=0;i<children_id.getNumItems();i++) {
  96. GuiObjectWnd *w = new GuiObjectWnd;
  97. //w->abstract_setAllowDeferredContent(1);
  98. w->setContent(children_id.enumItem(i)->getValue());
  99. addChild(w);
  100. }
  101. TypeSheet::setWindowType(wndtype);
  102. if (!wndtype.isempty())
  103. TypeSheet::load();
  104. }
  105. // -----------------------------------------------------------------------
  106. int ScriptTabSheet::onInit() {
  107. int r = SCRIPTTABSHEET_PARENT::onInit();
  108. setButtonType(type);
  109. reloadChildren();
  110. return r;
  111. }
  112. void ScriptTabSheet::setContentMarginX(const wchar_t *value, int what) {
  113. switch (what) {
  114. case SCRIPTTABSHEET_SETCONTENTMARGINLEFT:
  115. setContentMarginLeft(WTOI(value));
  116. break;
  117. case SCRIPTTABSHEET_SETCONTENTMARGINTOP:
  118. setContentMarginTop(WTOI(value));
  119. break;
  120. case SCRIPTTABSHEET_SETCONTENTMARGINRIGHT:
  121. setContentMarginRight(WTOI(value));
  122. break;
  123. case SCRIPTTABSHEET_SETCONTENTMARGINBOTTOM:
  124. setContentMarginBottom(WTOI(value));
  125. break;
  126. }
  127. }
  128. // -----------------------------------------------------------------------
  129. // Script Object
  130. // -- Functions table -------------------------------------
  131. function_descriptor_struct ScriptTabSheetController::exportedFunction[] = {
  132. {L"getCurPage", 0, (void*)ScriptTabSheetController::tabsheet_getCurPage },
  133. {L"setCurPage", 1, (void*)ScriptTabSheetController::tabsheet_setCurPage },
  134. };
  135. ScriptObject *ScriptTabSheetController::instantiate() {
  136. ScriptTabSheet *sts = new ScriptTabSheet;
  137. ASSERT(sts != NULL);
  138. return sts->getScriptObject();
  139. }
  140. void ScriptTabSheetController::destroy(ScriptObject *o) {
  141. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  142. ASSERT(sts != NULL);
  143. delete sts;
  144. }
  145. void *ScriptTabSheetController::encapsulate(ScriptObject *o) {
  146. return NULL; // no encapsulation for tabsheet yet
  147. }
  148. void ScriptTabSheetController::deencapsulate(void *o) {
  149. }
  150. int ScriptTabSheetController::getNumFunctions() {
  151. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  152. }
  153. const function_descriptor_struct *ScriptTabSheetController::getExportedFunctions() {
  154. return exportedFunction;
  155. }
  156. scriptVar ScriptTabSheetController::tabsheet_getCurPage(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  157. SCRIPT_FUNCTION_INIT
  158. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  159. int a = 0;
  160. if (sts) a = sts->getCurPage();
  161. return MAKE_SCRIPT_INT(a);
  162. }
  163. scriptVar ScriptTabSheetController::tabsheet_getNumPages(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  164. SCRIPT_FUNCTION_INIT
  165. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  166. int a = 0;
  167. if (sts) a = sts->getNumPages();
  168. return MAKE_SCRIPT_INT(a);
  169. }
  170. scriptVar ScriptTabSheetController::tabsheet_setCurPage(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar a) {
  171. SCRIPT_FUNCTION_INIT
  172. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  173. int _a = GET_SCRIPT_INT(a);
  174. if (sts) sts->setCurPage(_a);
  175. RETURN_SCRIPT_VOID;
  176. }
  177. scriptVar ScriptTabSheetController::tabsheet_nextPage(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  178. SCRIPT_FUNCTION_INIT
  179. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  180. if (sts) sts->nextPage();
  181. RETURN_SCRIPT_VOID;
  182. }
  183. scriptVar ScriptTabSheetController::tabsheet_previousPage(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  184. SCRIPT_FUNCTION_INIT
  185. ScriptTabSheet *sts = static_cast<ScriptTabSheet *>(o->vcpu_getInterface(tabsheetGuid));
  186. if (sts) sts->previousPage();
  187. RETURN_SCRIPT_VOID;
  188. }