1
0

abstractwndhold.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #include "precomp.h"
  2. #include <api/syscb/api_syscb.h>
  3. #include "abstractwndhold.h"
  4. #include <api/service/svc_enum.h>
  5. #include <api/wnd/wndclass/guiobjwnd.h>
  6. #include <api/service/svcs/svc_wndcreate.h>
  7. #include <api/script/scriptguid.h>
  8. #include <api/script/objects/c_script/c_guiobject.h>
  9. #include <api/script/objects/c_script/c_group.h>
  10. #include <api/wnd/notifmsg.h>
  11. #define CB_ABSTRACTLOAD 0x1125
  12. AbstractWndHolder::AbstractWndHolder(const wchar_t *grpid, int autoresize) : ServiceWndHolder(NULL, NULL)
  13. {
  14. scripts_enabled = 1;
  15. groupid = grpid;
  16. group_item = NULL;
  17. guid = INVALID_GUID;
  18. group = NULL;
  19. cbreg = 0;
  20. inselfresize = 0;
  21. autoresizefromcontent = autoresize;
  22. allow_deferred_content = 0;
  23. need_deferred_load = 0;
  24. }
  25. AbstractWndHolder::AbstractWndHolder(SkinItem *groupitem, int autoresize) : ServiceWndHolder(NULL, NULL) {
  26. group_item = groupitem;
  27. guid = INVALID_GUID;
  28. group = NULL;
  29. cbreg = 0;
  30. inselfresize = 0;
  31. autoresizefromcontent = autoresize;
  32. allow_deferred_content = 0;
  33. need_deferred_load = 0;
  34. }
  35. AbstractWndHolder::AbstractWndHolder(GUID g, int autoresize) : ServiceWndHolder(NULL, NULL) {
  36. guid = g;
  37. group = NULL;
  38. cbreg = 0;
  39. group_item = NULL;
  40. inselfresize = 0;
  41. autoresizefromcontent = autoresize;
  42. allow_deferred_content = 0;
  43. need_deferred_load = 0;
  44. }
  45. AbstractWndHolder::~AbstractWndHolder() {
  46. if (group) {
  47. #ifdef WASABI_COMPILE_SKIN
  48. WASABI_API_SKIN->group_destroy(group);
  49. #endif
  50. group = NULL;
  51. }
  52. if (cbreg) WASABI_API_SYSCB->syscb_deregisterCallback(this);
  53. }
  54. int AbstractWndHolder::onInit() {
  55. ABSTRACTWNDHOLDER_PARENT::onInit();
  56. createChild();
  57. return 1;
  58. }
  59. ifc_window *AbstractWndHolder::rootwndholder_getRootWnd() {
  60. if (group != NULL) return group;
  61. return ABSTRACTWNDHOLDER_PARENT::rootwndholder_getRootWnd();
  62. }
  63. void AbstractWndHolder::abstract_setContent(const wchar_t *group_id, int autoresize)
  64. {
  65. setBothContent(group_id, INVALID_GUID, autoresize);
  66. }
  67. void AbstractWndHolder::abstract_setContentBySkinItem(SkinItem *item, int autoresize) {
  68. setContentSkinItem(item, autoresize);
  69. }
  70. void AbstractWndHolder::abstract_setContent(GUID g, int autoresize) {
  71. setBothContent(NULL, g, autoresize);
  72. }
  73. void AbstractWndHolder::setBothContent(const wchar_t *group_id, GUID g, int autoresize)
  74. {
  75. group_item = NULL;
  76. if (autoresize != -1)
  77. autoresizefromcontent = autoresize;
  78. if (WCSCASEEQLSAFE(groupid, group_id) || (guid != INVALID_GUID && guid == g)) return;
  79. GUID _g = nsGUID::fromCharW(group_id);
  80. if (g == INVALID_GUID && _g != INVALID_GUID) {
  81. groupid = NULL;
  82. guid = _g;
  83. } else {
  84. groupid = group_id;
  85. guid = g;
  86. }
  87. createChild();
  88. }
  89. void AbstractWndHolder::setContentSkinItem(SkinItem *item, int autoresize)
  90. {
  91. if (autoresize != -1)
  92. autoresizefromcontent = autoresize;
  93. groupid.trunc(0);
  94. guid = INVALID_GUID;
  95. group_item = item;
  96. createChild();
  97. }
  98. int AbstractWndHolder::onGroupChange(const wchar_t *grpid)
  99. {
  100. if (WCSCASEEQLSAFE(groupid, grpid))
  101. {
  102. createChild();
  103. notifyParent(ChildNotify::GROUPRELOAD);
  104. notifyParent(ChildNotify::AUTOWHCHANGED);
  105. }
  106. return 1;
  107. }
  108. void AbstractWndHolder::createChild() {
  109. if (!isInited()) return;
  110. destroyContent();
  111. if (allow_deferred_content && !isVisible())
  112. need_deferred_load = 1;
  113. else
  114. doLoadContent();
  115. }
  116. void AbstractWndHolder::destroyContent()
  117. {
  118. if (group != NULL) {
  119. #ifdef WASABI_COMPILE_SKIN
  120. WASABI_API_SKIN->group_destroy(group);
  121. #endif
  122. if (cbreg) {
  123. WASABI_API_SYSCB->syscb_deregisterCallback(this);
  124. cbreg=0;
  125. }
  126. ABSTRACTWNDHOLDER_PARENT::setChild(NULL, NULL);
  127. }
  128. group = NULL;
  129. }
  130. int AbstractWndHolder::onDeferredCallback(intptr_t p1, intptr_t p2)
  131. {
  132. if (p1 == CB_ABSTRACTLOAD) {
  133. doLoadContent();
  134. return 1;
  135. }
  136. return ABSTRACTWNDHOLDER_PARENT::onDeferredCallback(p1, p2);
  137. }
  138. #include <bfc/util/profiler.h>
  139. void AbstractWndHolder::doLoadContent() {
  140. int didsomething = 0;
  141. need_deferred_load = 0;
  142. if (group_item != NULL) {
  143. #ifdef WASABI_COMPILE_SKIN
  144. group = WASABI_API_SKIN->group_createBySkinItem(group_item, scripts_enabled);
  145. #endif
  146. if (group) {
  147. if (!cbreg) {
  148. WASABI_API_SYSCB->syscb_registerCallback(this);
  149. cbreg=1;
  150. }
  151. group->setParent(this);
  152. group->init(this);
  153. abstract_onNewContent();
  154. didsomething = 1;
  155. }
  156. } else if (!groupid.isempty()) {
  157. #ifdef WASABI_COMPILE_SKIN
  158. group = WASABI_API_SKIN->group_create(groupid, scripts_enabled);
  159. #endif
  160. if (group) {
  161. if (!cbreg) {
  162. WASABI_API_SYSCB->syscb_registerCallback(this);
  163. cbreg=1;
  164. }
  165. group->setParent(this);
  166. group->init(this);
  167. abstract_onNewContent();
  168. didsomething = 1;
  169. }
  170. } else if (guid != INVALID_GUID) {
  171. svc_windowCreate *svc = WindowCreateByGuidEnum(guid).getNext();
  172. ABSTRACTWNDHOLDER_PARENT::setChild(svc->createWindowByGuid(guid, this), svc);
  173. abstract_onNewContent();
  174. didsomething = 1;
  175. }
  176. if (didsomething && isPostOnInit())
  177. {
  178. onResize();
  179. }
  180. }
  181. void AbstractWndHolder::abstract_onNewContent()
  182. {
  183. if (isPostOnInit()) {
  184. ifc_window *w = getDesktopParent();
  185. if (w != NULL) {
  186. if (w->enumMinMaxEnforcer(0)) {
  187. w->signalMinMaxEnforcerChanged();
  188. }
  189. }
  190. }
  191. }
  192. GuiObject *AbstractWndHolder::abstract_findObject(const wchar_t *object_id)
  193. {
  194. ifc_window *w = rootwndholder_getRootWnd();
  195. if (w == NULL) return NULL;
  196. GuiObject *o = static_cast<GuiObject *>(w->getInterface(guiObjectGuid));
  197. return o->guiobject_findObject(object_id);
  198. }
  199. ScriptObject *AbstractWndHolder::abstract_findScriptObject(const wchar_t *object_id)
  200. {
  201. ifc_window *w = rootwndholder_getRootWnd();
  202. if (w == NULL) return NULL;
  203. GuiObject *o = static_cast<GuiObject *>(w->getInterface(guiObjectGuid));
  204. GuiObject *fo = o->guiobject_findObject(object_id);
  205. if (fo != NULL) return fo->guiobject_getScriptObject();
  206. return NULL;
  207. }
  208. GuiObject *AbstractWndHolder::abstract_getContent() {
  209. ifc_window *w = rootwndholder_getRootWnd();
  210. if (w == NULL) return NULL;
  211. return static_cast<GuiObject *>(w->getInterface(guiObjectGuid));
  212. }
  213. ScriptObject *AbstractWndHolder::abstract_getContentScriptObject() {
  214. ifc_window *w = rootwndholder_getRootWnd();
  215. if (w == NULL) return NULL;
  216. return static_cast<ScriptObject *>(w->getInterface(scriptObjectGuid));
  217. }
  218. int AbstractWndHolder::onResize() {
  219. int rt = ABSTRACTWNDHOLDER_PARENT::onResize();
  220. if (group != NULL && abstract_wantAutoResizeFromContent()) {
  221. if (inselfresize) return rt;
  222. inselfresize=1;
  223. int w = group->getPreferences(SUGGESTED_W);
  224. int h = group->getPreferences(SUGGESTED_H);
  225. resize(NOCHANGE, NOCHANGE, w == AUTOWH ? NOCHANGE : w, h == AUTOWH ? NOCHANGE : h);
  226. inselfresize = 0;
  227. }
  228. return rt;
  229. }
  230. void AbstractWndHolder::onSetVisible( int show )
  231. {
  232. ABSTRACTWNDHOLDER_PARENT::onSetVisible( show );
  233. if ( allow_deferred_content )
  234. {
  235. if ( show & need_deferred_load )
  236. {
  237. doLoadContent();
  238. }
  239. if ( !show && !need_deferred_load )
  240. {
  241. destroyContent();
  242. need_deferred_load = 1;
  243. }
  244. }
  245. }
  246. void AbstractWndHolder::abstract_setScriptsEnabled(int en)
  247. {
  248. if (scripts_enabled == en) return;
  249. scripts_enabled = en;
  250. if (group != NULL) {
  251. destroyContent();
  252. doLoadContent();
  253. }
  254. }
  255. int AbstractWndHolder::abstact_getScriptsEnabled() {
  256. return scripts_enabled;
  257. }