1
0

wndapi.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #include <precomp.h>
  2. #include <api.h>
  3. #include "wndapi.h"
  4. #include <api/wnd/api_window.h>
  5. #include <tataki/canvas/ifc_canvas.h>
  6. #include <api/wnd/deactivatemgr.h>
  7. #include <api/wnd/wndtrack.h>
  8. #include <api/syscb/callbacks/consolecb.h>
  9. #include <api/wnd/keyboard.h>
  10. #ifdef WASABI_COMPILE_SKIN
  11. // #include <api/skin/groupmgr.h>
  12. #endif
  13. #ifdef WASABI_COMPILE_PAINTSETS
  14. #ifdef WASABI_COMPILE_IMGLDR
  15. #include <api/wnd/paintset.h>
  16. #endif
  17. #endif
  18. #ifdef WASABI_COMPILE_SKIN
  19. //#include <api/skin/skin.h>
  20. #endif
  21. #include <bfc/stack.h>
  22. #include <tataki/region/region.h>
  23. wnd_api *wndApi = NULL;
  24. #ifndef ODS
  25. #define ODS(msg1, msg2) __ODS(__LINE__, msg1, msg2, 0);
  26. #endif
  27. static Stack<ifc_window*> modal_wnd_stack;
  28. static void __ODS(int line, wchar_t *message1, wchar_t *message2, int severity) {
  29. StringPrintfW s(L"wndApi(%d): %s: %s\n", line, message1, message2);
  30. #ifdef WIN32
  31. DebugStringW(L"%s\n", s);
  32. #endif
  33. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::CONSOLE, ConsoleCallback::DEBUGMESSAGE, severity, reinterpret_cast<intptr_t>(s.getValue()));
  34. }
  35. WndApi::WndApi()
  36. {
  37. }
  38. WndApi::~WndApi()
  39. {
  40. }
  41. void WndApi::main_setRootWnd(ifc_window *w) {
  42. genericwnd = w;
  43. }
  44. ifc_window *WndApi::main_getRootWnd() {
  45. return genericwnd;
  46. }
  47. ifc_window *WndApi::getModalWnd() {
  48. if (!modal_wnd_stack.peek()) return NULL;
  49. return modal_wnd_stack.top();
  50. }
  51. void WndApi::pushModalWnd(ifc_window *w) {
  52. modal_wnd_stack.push(w);
  53. }
  54. void WndApi::popModalWnd(ifc_window *w) {
  55. if (getModalWnd() != w) return;
  56. modal_wnd_stack.pop();
  57. }
  58. /* TODO: Benski> move to api_wndmgr */
  59. ifc_window *WndApi::rootWndFromPoint(POINT *pt) {
  60. return WindowTracker::rootWndFromPoint(pt);
  61. }
  62. ifc_window *WndApi::rootWndFromOSHandle(OSWINDOWHANDLE wnd) {
  63. return WindowTracker::rootWndFromHwnd(wnd);
  64. }
  65. void WndApi::registerRootWnd(ifc_window *wnd) {
  66. WindowTracker::addRootWnd(wnd);
  67. }
  68. void WndApi::unregisterRootWnd(ifc_window *wnd) {
  69. WindowTracker::removeRootWnd(wnd);
  70. }
  71. /* --- end TO MOVE ---*/
  72. int WndApi::rootwndIsValid(ifc_window *wnd) {
  73. return windowTracker->checkWindow(wnd);
  74. }
  75. void WndApi::hookKeyboard(ifc_window *hooker) {
  76. Keyboard::hookKeyboard(hooker);
  77. }
  78. void WndApi::unhookKeyboard(ifc_window *hooker) {
  79. Keyboard::unhookKeyboard(hooker);
  80. }
  81. void WndApi::kbdReset() {
  82. Keyboard::reset();
  83. }
  84. // so when a key is pressed in a basewnd, it is first intercepted and sent to these functions to check if the system should handle it instead of the wnd...
  85. int WndApi::interceptOnChar(unsigned int c) {
  86. return Keyboard::interceptOnChar(c);
  87. }
  88. int WndApi::interceptOnKeyDown(int k) {
  89. return Keyboard::interceptOnKeyDown(k);
  90. }
  91. int WndApi::interceptOnKeyUp(int k) {
  92. return Keyboard::interceptOnKeyUp(k);
  93. }
  94. int WndApi::interceptOnSysKeyDown(int k, int kd) {
  95. return Keyboard::interceptOnSysKeyDown(k, kd);
  96. }
  97. int WndApi::interceptOnSysKeyUp(int k, int kd) {
  98. return Keyboard::interceptOnSysKeyUp(k, kd);
  99. }
  100. // ... if not, then it is sent to the wnd, and if the wnd doesn't need it, it is then forwarded to the system again, for default handling :
  101. int WndApi::forwardOnChar(ifc_window *from, unsigned int c, int kd) {
  102. return Keyboard::onForwardOnChar(from, c, kd);
  103. }
  104. int WndApi::forwardOnKeyDown(ifc_window *from, int k, int kd) {
  105. return Keyboard::onForwardOnKeyDown(from, k, kd);
  106. }
  107. int WndApi::forwardOnKeyUp(ifc_window *from, int k, int kd) {
  108. return Keyboard::onForwardOnKeyUp(from, k, kd);
  109. }
  110. int WndApi::forwardOnSysKeyDown(ifc_window *from, int k, int kd) {
  111. return Keyboard::onForwardOnSysKeyDown(from, k, kd);
  112. }
  113. int WndApi::forwardOnSysKeyUp(ifc_window *from, int k, int kd) {
  114. return Keyboard::onForwardOnSysKeyUp(from, k, kd);
  115. }
  116. int WndApi::forwardOnKillFocus() {
  117. return Keyboard::onForwardOnKillFocus();
  118. }
  119. void WndApi::popupexit_register(PopupExitCallback *cb, ifc_window *watched)
  120. {
  121. popupExitChecker.registerCallback(cb, watched);
  122. }
  123. void WndApi::popupexit_deregister(PopupExitCallback *cb)
  124. {
  125. popupExitChecker.deregisterCallback(cb);
  126. }
  127. int WndApi::popupexit_check(ifc_window *w) {
  128. return popupExitChecker.check(w);
  129. }
  130. void WndApi::popupexit_signal()
  131. {
  132. popupExitChecker.signal();
  133. }
  134. #define RenderBaseTexture renderBaseTexture //CUT
  135. void WndApi::skin_renderBaseTexture(ifc_window *basetexturewnd, ifc_canvas *c, const RECT *r, ifc_window *destwnd, int alpha) {
  136. if (c == NULL) {
  137. ODS(L"illegal param", L"c == NULL");
  138. return;
  139. }
  140. if (basetexturewnd == NULL) {
  141. ODS(L"illegal param", L"base == NULL");
  142. BaseCloneCanvas canvas(c);
  143. canvas.fillRect(r, 0xFF00FF);
  144. return;
  145. }
  146. if (destwnd == NULL) {
  147. ODS(L"illegal param", L"destwnd == NULL");
  148. return;
  149. }
  150. renderBaseTexture(basetexturewnd, c, *r, destwnd, alpha);
  151. }
  152. void WndApi::skin_registerBaseTextureWindow(ifc_window *window, const wchar_t *bitmap) {
  153. if (window == NULL) {
  154. ODS(L"illegal param", L"window == NULL");
  155. return;
  156. }
  157. BaseTexture *s = new BaseTexture(window, bitmap);
  158. baseTextureList.addItem(s);
  159. }
  160. void WndApi::skin_unregisterBaseTextureWindow(ifc_window *window) {
  161. if (window == NULL) {
  162. ODS(L"illegal param", L"window == NULL");
  163. return;
  164. }
  165. for (int i=0;i<baseTextureList.getNumItems();i++) {
  166. if (baseTextureList.enumItem(i)->getWnd() == window) {
  167. BaseTexture *s = baseTextureList.enumItem(i);
  168. baseTextureList.delByPos(i);
  169. delete s;
  170. if (baseTextureList.getNumItems() == 0)
  171. baseTextureList.removeAll();
  172. break;
  173. }
  174. }
  175. }
  176. void WndApi::appdeactivation_push_disallow(ifc_window *from_whom) {
  177. AppDeactivationMgr::push_disallow(from_whom);
  178. }
  179. void WndApi::appdeactivation_pop_disallow(ifc_window *from_whom) {
  180. AppDeactivationMgr::pop_disallow(from_whom);
  181. }
  182. int WndApi::appdeactivation_isallowed(ifc_window *w) {
  183. return AppDeactivationMgr::is_deactivation_allowed(w);
  184. }
  185. void WndApi::appdeactivation_setbypass(int i) {
  186. AppDeactivationMgr::setbypass(i);
  187. }
  188. #ifdef WASABI_COMPILE_PAINTSETS
  189. #ifdef WASABI_COMPILE_IMGLDR
  190. void WndApi::paintset_render(int set, ifc_canvas *c, const RECT *r, int alpha) {
  191. if (c == NULL) {
  192. ODS(L"illegal param", L"c == NULL");
  193. return;
  194. }
  195. if (r == NULL) {
  196. ODS(L"illegal param", L"r == NULL");
  197. return;
  198. }
  199. paintset_renderPaintSet(set, c, r, alpha);
  200. }
  201. #ifdef WASABI_COMPILE_FONTS
  202. void WndApi::paintset_renderTitle(const wchar_t *t, ifc_canvas *c, const RECT *r, int alpha) {
  203. if (c == NULL) {
  204. ODS(L"illegal param", L"c == NULL");
  205. return;
  206. }
  207. if (r == NULL) {
  208. ODS(L"illegal param", L"r == NULL");
  209. return;
  210. }
  211. ::paintset_renderTitle(t, c, r, alpha);
  212. }
  213. #endif // WASABI_COMPILE_FONTS
  214. #endif // WASABI_COMPILE_IMGLDR
  215. #endif // WASABI_COMPILE_PAINTSETS
  216. BaseTexture *WndApi::getBaseTexture(ifc_window *b) {
  217. if (b == NULL) return NULL;
  218. for (int i=0;i<baseTextureList.getNumItems();i++)
  219. if (baseTextureList.enumItem(i)->getWnd() == b)
  220. return baseTextureList.enumItem(i);
  221. return NULL;
  222. }
  223. void WndApi::renderBaseTexture(ifc_window *base, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha) {
  224. renderBaseTexture(base, getBaseTexture(base), c, r, dest, alpha);
  225. }
  226. void WndApi::renderBaseTexture(ifc_window *base, BaseTexture *bt, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha) {
  227. if (!bt) {
  228. DebugString("Warning, no base texture found in renderBaseTexture\n");
  229. return;
  230. }
  231. bt->renderBaseTexture(base, c, r, dest, alpha);
  232. }
  233. #ifndef SAFEROUND
  234. #define SAFEROUND(d) ((float)(int)d == d) ? (int)d : (d - (float)(int)d > 0) ? ((int)d)+1 : ((int)d)-1
  235. #endif
  236. void BaseTexture::renderBaseTexture(ifc_window *wndbase, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha)
  237. {
  238. // pick our basetexture
  239. AutoSkinBitmap *b = &texture;
  240. if(!b) return;
  241. // srcRect is the source rectangle in the basetexture
  242. RECT srcRect;
  243. // destProjectedRect is the basetexture rectangle projected to dest coordinates
  244. RECT destProjectedRect;
  245. ifc_window *p = dest;
  246. POINT pt;
  247. int sx=0, sy=0;
  248. while (p && p != wndbase) {
  249. if (!p->isVirtual()) {
  250. p->getPosition(&pt);
  251. sx += pt.x;
  252. sy += pt.y;
  253. }
  254. p = p->getParent();
  255. }
  256. ASSERT(p);
  257. wndbase->getNonClientRect(&destProjectedRect);
  258. Wasabi::Std::offsetRect(&destProjectedRect, -sx, -sy);
  259. Wasabi::Std::setRect(&srcRect, 0, 0, b->getWidth(), b->getHeight());
  260. #if 0
  261. // NONPORTABLE
  262. HDC hdc=c->getHDC();
  263. HRGN oldRgn=CreateRectRgn(0,0,0,0);
  264. HRGN newRgn=CreateRectRgnIndirect(&r);
  265. int cs=GetClipRgn(hdc,oldRgn);
  266. ExtSelectClipRgn(hdc,newRgn,(cs!=1)?RGN_COPY:RGN_AND);
  267. #endif
  268. #ifdef _WIN32
  269. // TODO: review: wtf does this even accomplish? we're still blitting to c at the end
  270. BaseCloneCanvas clone(c);
  271. RegionI oldRgn;
  272. RegionI newRgn(&r);
  273. int cs = clone.getClipRgn(&oldRgn);
  274. if ( cs ) newRgn.andRegion(&oldRgn);
  275. clone.selectClipRgn( &newRgn );
  276. #endif
  277. b->stretchToRectAlpha(c, &srcRect, &destProjectedRect, alpha);
  278. #ifdef _WIN32
  279. // TODO: review: wtf does this even accomplish? we're still blitting to c at the end
  280. clone.selectClipRgn(cs ? &oldRgn : NULL);
  281. #endif
  282. }
  283. int WndApi::forwardOnMouseWheel(int l, int a) {
  284. return 0;
  285. }
  286. #ifdef WASABI_COMPILE_PAINTSETS
  287. int WndApi::paintset_present(int set) {
  288. return ::paintset_present(set);
  289. }
  290. #endif
  291. void WndApi::setDefaultDropTarget(void *dt) {
  292. default_drop_target = dt;
  293. }
  294. void *WndApi::getDefaultDropTarget() {
  295. return default_drop_target;
  296. }
  297. int WndApi::pushKeyboardLock() {
  298. return ++kbdlock;
  299. }
  300. int WndApi::popKeyboardLock() {
  301. return --kbdlock;
  302. }
  303. int WndApi::isKeyboardLocked() {
  304. return kbdlock;
  305. }
  306. ifc_window *WndApi::genericwnd = NULL;
  307. PtrList<BaseTexture> WndApi::baseTextureList;
  308. void *WndApi::default_drop_target = NULL;
  309. int WndApi::kbdlock = 0;