1
0

virtualhostwnd.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include "precomp.h"
  2. #include "virtualhostwnd.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <tataki/region/api_region.h>
  5. VirtualHostWnd::VirtualHostWnd() {
  6. group = new GuiObjectWnd();
  7. fittoclient = 0;
  8. xoffset = 0;
  9. yoffset = 0;
  10. groupwidth = 0;
  11. groupheight = 0;
  12. scripts_enabled = 1;
  13. }
  14. VirtualHostWnd::~VirtualHostWnd() {
  15. delete group;
  16. }
  17. int VirtualHostWnd::onInit() {
  18. GuiObjectWnd::onInit();
  19. group->setVirtual(0);
  20. group->setStartHidden(1);
  21. group->setParent(this);
  22. group->init(this);
  23. group->deferedInvalidate();
  24. group->setCloaked(1); // magic!
  25. group->setVisible(1);
  26. return 1;
  27. }
  28. void VirtualHostWnd::virtualhostwnd_setContent(const char *_groupname) {
  29. group->setContent(_groupname);
  30. if (isPostOnInit())
  31. virtualhostwnd_onNewContent();
  32. }
  33. void VirtualHostWnd::virtualhostwnd_setContent(SkinItem *groupitem) {
  34. group->setContentBySkinItem(groupitem);
  35. if (isPostOnInit())
  36. virtualhostwnd_onNewContent();
  37. }
  38. void VirtualHostWnd::virtualhostwnd_onNewContent() {
  39. }
  40. #ifdef WASABI_COMPILE_SCRIPT
  41. ScriptObject *VirtualHostWnd::virtualhostwnd_findScriptObject(const char *object_id) {
  42. return group->findScriptObject(object_id);
  43. }
  44. #endif
  45. #ifdef WASABI_COMPILE_SKIN
  46. GuiObject *VirtualHostWnd::virtualhostwnd_getContent() {
  47. return group->getContent();
  48. }
  49. ScriptObject *VirtualHostWnd::virtualhostwnd_getContentScriptObject() {
  50. return group->getContentScriptObject();
  51. }
  52. GuiObject *VirtualHostWnd::virtualhostwnd_findObject(const char *object_id) {
  53. return group->findObject(object_id);
  54. }
  55. #endif
  56. api_window *VirtualHostWnd::virtualhostwnd_getContentRootWnd() {
  57. return group->getContentRootWnd();
  58. }
  59. int VirtualHostWnd::onPaint(Canvas *c) {
  60. GuiObjectWnd::onPaint(c);
  61. virtualhostwnd_onPaintBackground(c);
  62. if (group == NULL) return 1;
  63. RECT wr;
  64. Canvas *cv = NULL;
  65. group->getNonClientRect(&wr);
  66. group->paint(NULL, NULL);
  67. cv = group->getFrameBuffer();
  68. if (cv != NULL) {
  69. BltCanvas *bltcanvas = static_cast<BltCanvas *>(cv); // HACK!
  70. bltcanvas->/*getSkinBitmap()->*/blitAlpha(c, xoffset, yoffset);
  71. }
  72. return 1;
  73. }
  74. void VirtualHostWnd::virtualhostwnd_onPaintBackground(Canvas *c) {
  75. RECT r;
  76. getClientRect(&r);
  77. c->fillRect(&r, RGB(255,255,255));
  78. }
  79. int VirtualHostWnd::onResize() {
  80. GuiObjectWnd::onResize();
  81. if (group != NULL) {
  82. RECT r;
  83. getClientRect(&r);
  84. if (fittoclient) {
  85. xoffset = 0;
  86. yoffset = 0;
  87. groupwidth = r.right-r.left;
  88. groupheight = r.bottom-r.top;
  89. } else {
  90. groupwidth = group->getGuiObject()->guiobject_getAutoWidth();
  91. groupheight = group->getGuiObject()->guiobject_getAutoHeight();
  92. if (groupwidth == AUTOWH) groupwidth = 320;
  93. if (groupheight == AUTOWH) groupheight = 200;
  94. int cw = r.right-r.left;
  95. int ch = r.bottom-r.top;
  96. xoffset = (cw - groupwidth)/2;
  97. yoffset = (ch - groupheight)/2;
  98. }
  99. group->resize(xoffset+r.left, yoffset+r.top, groupwidth, groupheight);
  100. }
  101. return 1;
  102. }
  103. void VirtualHostWnd::virtualhostwnd_getContentRect(RECT *r) {
  104. ASSERT(r != NULL);
  105. getClientRect(r);
  106. r->left += xoffset;
  107. r->top += yoffset;
  108. r->right = r->left + groupwidth;
  109. r->bottom = r->top + groupheight;
  110. }
  111. void VirtualHostWnd::virtualhostwnd_fitToClient(int fit) {
  112. fittoclient = fit;
  113. if (isPostOnInit()) {
  114. onResize();
  115. invalidate();
  116. }
  117. }
  118. void VirtualHostWnd::onChildInvalidate(api_region *r, api_window *who) {
  119. GuiObjectWnd::onChildInvalidate(r, who);
  120. api_region *clone = r->clone();
  121. clone->offset(xoffset, yoffset);
  122. invalidateRgn(clone);
  123. r->disposeClone(clone);
  124. }
  125. int VirtualHostWnd::onLeftButtonDown(int x, int y) {
  126. // DO NOT CALL GuiObjectWnd::onLeftButtonDown(x, y);
  127. x -= xoffset;
  128. y -= yoffset;
  129. return group->wndProc(group->gethWnd(), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
  130. }
  131. int VirtualHostWnd::onLeftButtonUp(int x, int y){
  132. // DO NOT CALL GuiObjectWnd::onLeftButtonUp(x, y);
  133. x -= xoffset;
  134. y -= yoffset;
  135. return group->wndProc(group->gethWnd(), WM_LBUTTONUP, 0, MAKELPARAM(x, y));
  136. }
  137. int VirtualHostWnd::onRightButtonDown(int x, int y){
  138. // DO NOT CALL GuiObjectWnd::onRightButtonDown(x, y);
  139. x -= xoffset;
  140. y -= yoffset;
  141. return group->wndProc(group->gethWnd(), WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(x, y));
  142. }
  143. int VirtualHostWnd::onRightButtonUp(int x, int y){
  144. // DO NOT CALL GuiObjectWnd::onRightButtonUp(x, y);
  145. x -= xoffset;
  146. y -= yoffset;
  147. return group->wndProc(group->gethWnd(), WM_RBUTTONUP, 0, MAKELPARAM(x, y));
  148. }
  149. int VirtualHostWnd::onLeftButtonDblClk(int x, int y){
  150. // DO NOT CALL GuiObjectWnd::onLeftButtonDblClk(x, y);
  151. x -= xoffset;
  152. y -= yoffset;
  153. return group->wndProc(group->gethWnd(), WM_RBUTTONDBLCLK, 0, MAKELPARAM(x, y));
  154. }
  155. int VirtualHostWnd::onRightButtonDblClk(int x, int y){
  156. // DO NOT CALL GuiObjectWnd::onRightButtonDblClk(x, y);
  157. x -= xoffset;
  158. y -= yoffset;
  159. return group->wndProc(group->gethWnd(), WM_LBUTTONDBLCLK, 0, MAKELPARAM(x, y));
  160. }
  161. int VirtualHostWnd::onMouseMove(int x, int y){
  162. // DO NOT CALL GuiObjectWnd::onMouseMove(x, y);
  163. x -= xoffset;
  164. y -= yoffset;
  165. return group->wndProc(group->gethWnd(), WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
  166. }