wndmgrapi.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #include <precomp.h>
  2. #include "wndmgrapi.h"
  3. #include <api/wndmgr/autopopup.h>
  4. #include <api/wndmgr/skinembed.h>
  5. #include <api/wndmgr/animate.h>
  6. #include <api/wnd/wndtrack.h>
  7. #include <api/skin/skinparse.h>
  8. #include <api/wndmgr/msgbox.h>
  9. #include <api/util/varmgr.h>
  10. wndmgr_api *wndManagerApi = NULL;
  11. WndMgrApi::WndMgrApi()
  12. {
  13. skinEmbedder = new SkinEmbedder();
  14. windowTracker = new WindowTracker();
  15. }
  16. WndMgrApi::~WndMgrApi()
  17. {
  18. delete skinEmbedder;
  19. skinEmbedder = NULL;
  20. delete windowTracker;
  21. windowTracker = NULL;
  22. }
  23. void WndMgrApi::wndTrackAdd(ifc_window *wnd)
  24. {
  25. if (wnd == NULL)
  26. {
  27. DebugString("wndTrackAdd, illegal param : wnd == NULL\n");
  28. return ;
  29. }
  30. windowTracker->addWindow(wnd);
  31. }
  32. void WndMgrApi::wndTrackRemove(ifc_window *wnd)
  33. {
  34. if (wnd == NULL)
  35. {
  36. DebugString("wndTrackAdd, illegal param : wnd == NULL\n");
  37. return ;
  38. }
  39. windowTracker->removeWindow(wnd);
  40. }
  41. bool WndMgrApi::wndTrackDock(ifc_window *wnd, RECT *r, int mask)
  42. {
  43. return windowTracker->autoDock(wnd, r, mask);
  44. }
  45. bool WndMgrApi::wndTrackDock2(ifc_window *wnd, RECT *r, RECT *orig_r, int mask)
  46. {
  47. return windowTracker->autoDock(wnd, r, orig_r, mask);
  48. }
  49. void WndMgrApi::wndTrackStartCooperative(ifc_window *wnd)
  50. {
  51. windowTracker->startCooperativeMove(wnd);
  52. }
  53. void WndMgrApi::wndTrackEndCooperative(void)
  54. {
  55. windowTracker->endCooperativeMove();
  56. }
  57. int WndMgrApi::wndTrackWasCooperative(void)
  58. {
  59. return windowTracker->wasCooperativeMove();
  60. }
  61. void WndMgrApi::wndTrackInvalidateAll()
  62. {
  63. windowTracker->invalidateAllWindows();
  64. }
  65. int WndMgrApi::skinwnd_toggleByGuid(GUID g, const wchar_t *prefered_container, int container_flag, RECT *sourceanimrect, int transcient)
  66. {
  67. return skinEmbedder->toggle(g, prefered_container, container_flag, sourceanimrect, transcient);
  68. }
  69. int WndMgrApi::skinwnd_toggleByGroupId(const wchar_t *groupid, const wchar_t *prefered_container, int container_flag, RECT *sourceanimrect, int transcient)
  70. {
  71. return skinEmbedder->toggle(groupid, prefered_container, container_flag, sourceanimrect, transcient);
  72. }
  73. ifc_window *WndMgrApi::skinwnd_createByGuid(GUID g, const wchar_t *prefered_container, int container_flag, RECT *sourceanimrect, int transcient, int starthidden, int *isnew)
  74. {
  75. return skinEmbedder->create(g, prefered_container, container_flag, sourceanimrect, transcient, starthidden, isnew);
  76. }
  77. ifc_window *WndMgrApi::skinwnd_createByGroupId(const wchar_t *groupid, const wchar_t *prefered_container, int container_flag, RECT *sourceanimrect, int transcient, int starthidden, int *isnew)
  78. {
  79. return skinEmbedder->create(groupid, prefered_container, container_flag, sourceanimrect, transcient, starthidden, isnew);
  80. }
  81. void WndMgrApi::skinwnd_destroy(ifc_window *w, RECT *destanimrect)
  82. {
  83. skinEmbedder->destroy(w, destanimrect);
  84. }
  85. int WndMgrApi::skinwnd_getNumByGuid(GUID g)
  86. {
  87. return skinEmbedder->getNumItems(g);
  88. }
  89. ifc_window *WndMgrApi::skinwnd_enumByGuid(GUID g, int n)
  90. {
  91. return skinEmbedder->enumItem(g, n);
  92. }
  93. int WndMgrApi::skinwnd_getNumByGroupId(const wchar_t *groupid)
  94. {
  95. return skinEmbedder->getNumItems(groupid);
  96. }
  97. ifc_window *WndMgrApi::skinwnd_enumByGroupId(const wchar_t *groupid, int n)
  98. {
  99. return skinEmbedder->enumItem(groupid, n);
  100. }
  101. void WndMgrApi::skinwnd_attachToSkin(ifc_window *w, int side, int size)
  102. {
  103. skinEmbedder->attachToSkin(w, side, size);
  104. }
  105. ScriptObject *WndMgrApi::skin_getContainer(const wchar_t *container_name)
  106. {
  107. Container *c = SkinParser::getContainer(container_name);
  108. if (c != NULL) return c->getScriptObject();
  109. return NULL;
  110. }
  111. ScriptObject *WndMgrApi::skin_getLayout(ScriptObject *container, const wchar_t *layout_name)
  112. {
  113. ASSERT(container != NULL);
  114. Container *c = static_cast<Container *>(container->vcpu_getInterface(containerGuid));
  115. if (c != NULL)
  116. {
  117. Layout *l = c->getLayout(layout_name);
  118. if (l != NULL) return l->getScriptObject();
  119. }
  120. return NULL;
  121. }
  122. void WndMgrApi::wndholder_register(WindowHolder *wh)
  123. {
  124. skinEmbedder->registerWindowHolder(wh);
  125. }
  126. void WndMgrApi::wndholder_unregister(WindowHolder *wh)
  127. {
  128. skinEmbedder->unregisterWindowHolder(wh);
  129. }
  130. int WndMgrApi::messageBox(const wchar_t *txt, const wchar_t *title, int flags, const wchar_t *not_anymore_identifier, ifc_window *parentwnd)
  131. {
  132. #ifdef WASABI_WNDMGR_OSMSGBOX
  133. #ifdef WIN32
  134. int f = 0;
  135. if (flags & MSGBOX_OK) f |= MB_OK;
  136. if (flags & MSGBOX_CANCEL) f |= MB_OKCANCEL;
  137. if (flags & MSGBOX_YES) f |= MB_YESNO;
  138. if ((flags & MSGBOX_YES) && (flags & MSGBOX_CANCEL)) f |= MB_YESNOCANCEL;
  139. int r = MessageBoxW(parentwnd ? parentwnd->gethWnd() : NULL, txt, title, f);
  140. if (r == IDOK) r = MSGBOX_OK;
  141. if (r == IDCANCEL) r = MSGBOX_CANCEL;
  142. if (r == IDYES) r = MSGBOX_YES;
  143. if (r == IDNO) r = MSGBOX_NO;
  144. return r;
  145. #else
  146. // port me!
  147. #endif
  148. #else
  149. MsgBox _mb(txt, title, flags, not_anymore_identifier);
  150. return _mb.run();
  151. #endif
  152. }
  153. void WndMgrApi::drawAnimatedRects(const RECT *r1, const RECT *r2)
  154. {
  155. if (r1 == NULL)
  156. {
  157. DebugString("drawAnimatedRects, illegal param : r1 == NULL\n");
  158. return ;
  159. }
  160. if (r2 == NULL)
  161. {
  162. DebugString("drawAnimatedRects, illegal param : r2 == NULL\n");
  163. return ;
  164. }
  165. AnimatedRects::draw(r1, r2);
  166. }
  167. int WndMgrApi::autopopup_registerGuid(GUID g, const wchar_t *desc, const wchar_t *prefered_container, int container_flag)
  168. {
  169. return AutoPopup::registerGuid(SKINPARTID_NONE, g, desc, prefered_container, container_flag);
  170. }
  171. int WndMgrApi::autopopup_registerGroupId(const wchar_t *groupid, const wchar_t *desc, const wchar_t *prefered_container, int container_flag)
  172. {
  173. return AutoPopup::registerGroupId(SKINPARTID_NONE, groupid, desc, prefered_container, container_flag);
  174. }
  175. void WndMgrApi::autopopup_unregister(int id)
  176. {
  177. AutoPopup::unregister(id);
  178. }
  179. int WndMgrApi::autopopup_getNumGuids()
  180. {
  181. return AutoPopup::getNumGuids();
  182. }
  183. GUID WndMgrApi::autopopup_enumGuid(int n)
  184. {
  185. return AutoPopup::enumGuid(n);
  186. }
  187. int WndMgrApi::autopopup_getNumGroups()
  188. {
  189. return AutoPopup::getNumGroups();
  190. }
  191. const wchar_t *WndMgrApi::autopopup_enumGroup(int n)
  192. {
  193. return AutoPopup::enumGroup(n);
  194. }
  195. const wchar_t *WndMgrApi::autopopup_enumGuidDescription(int n)
  196. {
  197. return AutoPopup::enumGuidDescription(n);
  198. }
  199. const wchar_t *WndMgrApi::autopopup_enumGroupDescription(int n)
  200. {
  201. return AutoPopup::enumGroupDescription(n);
  202. }
  203. const wchar_t *WndMgrApi::varmgr_translate(const wchar_t *str)
  204. {
  205. StringW *s = PublicVarManager::translate_nocontext(str);
  206. if (s)
  207. {
  208. ret.swap(s);
  209. delete s;
  210. return ret.getValueSafe();
  211. }
  212. return str;
  213. }
  214. Stack<ifc_window*> WndMgrApi::modal_wnd_stack;
  215. ifc_window *WndMgrApi::getModalWnd()
  216. {
  217. if (!modal_wnd_stack.peek()) return NULL;
  218. return modal_wnd_stack.top();
  219. }
  220. void WndMgrApi::pushModalWnd(ifc_window *wnd)
  221. {
  222. modal_wnd_stack.push(wnd);
  223. }
  224. void WndMgrApi::popModalWnd(ifc_window *wnd)
  225. {
  226. if (getModalWnd() != wnd) return ;
  227. modal_wnd_stack.pop();
  228. }
  229. Container *WndMgrApi::newDynamicContainer(const wchar_t *name, int transcient)
  230. {
  231. return SkinParser::newDynamicContainer(name, transcient);
  232. }