titlebox.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include <precomp.h>
  2. #include "titlebox.h"
  3. #include <api/script/objects/guiobject.h>
  4. #include <api/script/scriptobj.h>
  5. #include <api/script/objects/c_script/c_text.h>
  6. #include <api/skin/widgets/customobject.h>
  7. TitleBox::TitleBox() {
  8. titleleft = NULL;
  9. titleright = NULL;
  10. titlecenter = NULL;
  11. content = NULL;
  12. centered = 0;
  13. }
  14. TitleBox::~TitleBox() {
  15. delete titleleft;
  16. delete titleright;
  17. delete titlecenter;
  18. delete content;
  19. }
  20. int TitleBox::onResize() {
  21. int rt = TITLEBOX_PARENT::onResize();
  22. if (!isInited()) return 0;
  23. RECT r, d;
  24. getClientRect(&r);
  25. int textwidth = titlecenter ? titlecenter->getPreferences(SUGGESTED_W) : 0;
  26. d = r;
  27. if (titleleft) {
  28. if (!getCentered())
  29. d.right = d.left + titleleft->getPreferences(SUGGESTED_W);
  30. else
  31. d.right = d.left + ((r.right-r.left) - textwidth) / 2;
  32. d.bottom = d.top + titleleft->getPreferences(SUGGESTED_H);
  33. titleleft->resize(d.left, d.top, d.right-d.left, d.bottom-d.top);
  34. }
  35. if (titlecenter) {
  36. d.left = d.right;
  37. d.right = d.left + titlecenter->getPreferences(SUGGESTED_W);
  38. d.bottom = d.top + titlecenter->getPreferences(SUGGESTED_H);
  39. titlecenter->resize(d.left, d.top, d.right-d.left, d.bottom-d.top);
  40. }
  41. if (titleright) {
  42. d.left = d.right;
  43. d.right = r.right;
  44. d.bottom = d.top + titleright->getPreferences(SUGGESTED_H);
  45. titleright->resize(d.left, d.top, d.right-d.left, d.bottom-d.top);
  46. }
  47. return rt;
  48. }
  49. int TitleBox::onInit() {
  50. int rt = TITLEBOX_PARENT::onInit();
  51. titleleft = new GuiObjectWnd();
  52. titleleft->setContent(L"wasabi.titlebox.left.group");
  53. titlecenter = new GuiObjectWnd();
  54. titlecenter->setContent(L"wasabi.titlebox.center.group");
  55. titleright = new GuiObjectWnd();
  56. titleright->setContent(L"wasabi.titlebox.right.group");
  57. titleleft->setParent(this);
  58. titlecenter->setParent(this);
  59. titleright->setParent(this);
  60. titleleft->init(this);
  61. titlecenter->init(this);
  62. titleright->init(this);
  63. setContent(L"wasabi.titlebox.main.group");
  64. return rt;
  65. }
  66. void TitleBox::setSubContent(int setcontent) {
  67. if (setcontent) {
  68. delete content;
  69. content = NULL;
  70. }
  71. GuiObject *myself = getContent();
  72. if (myself != NULL)
  73. {
  74. if (setcontent)
  75. {
  76. GuiObject *holder = findObject(L"titlebox.content"); // get the <CustomObject />
  77. if (holder != NULL) {
  78. CustomObject *obj = static_cast<CustomObject*>(holder->guiobject_getScriptObject()->vcpu_getInterface(customObjectGuid));
  79. if (obj != NULL) {
  80. content = new GuiObjectWnd();
  81. content->setContent(content_id);
  82. obj->customobject_setRootWnd(content); // and give it our content, it'll init it as needed
  83. }
  84. }
  85. }
  86. GuiObject *text = titlecenter->getContent()->guiobject_findObject(L"titlebox.text");
  87. if (text != NULL) {
  88. StringW name = getTitle();
  89. if (name.isempty()) {
  90. ifc_window *cr = content->getContentRootWnd();
  91. if (cr != NULL)
  92. name = cr->getRootWndName();
  93. }
  94. if (name.isempty())
  95. name = myself->guiobject_getRootWnd()->getRootWndName();
  96. if (!name.isempty())
  97. {
  98. name += suffix;
  99. C_Text ctext(*text);
  100. ctext.setText(name);
  101. }
  102. }
  103. }
  104. if (isPostOnInit())
  105. onResize();
  106. }
  107. void TitleBox::onNewContent() {
  108. TITLEBOX_PARENT::onNewContent();
  109. setSubContent();
  110. }
  111. void TitleBox::setCentered(int _centered) {
  112. centered = _centered;
  113. if (isInited())
  114. onResize();
  115. }
  116. void TitleBox::setTitle(const wchar_t *t) {
  117. title = t;
  118. setName(title);
  119. if (isInited())
  120. setSubContent(0);
  121. }
  122. void TitleBox::setSuffix(const wchar_t *_suffix) {
  123. if (!WCSICMPSAFE(suffix, _suffix)) return;
  124. suffix = _suffix;
  125. if (isInited())
  126. setSubContent(0);
  127. }
  128. void TitleBox::setChildGroup(const wchar_t *grp) {
  129. content_id = grp;
  130. if (isInited())
  131. setSubContent();
  132. }
  133. int TitleBox::getPreferences(int what) {
  134. /* GuiObject *contentGuiObj = findObject("titlebox.content");
  135. if (contentGuiObj != NULL) {
  136. // FUCKO, this is a huge hack but I don't have time to make autowidth/heightsource be a GuiObject thing instead of a group thing right now
  137. int x, y, rx, ry, w, rw, h, rh;
  138. contentGuiObj->guiobject_getGuiPosition(&x, &y, &w, &h, &rx, &ry, &rw, &rh);
  139. if (w == AUTOWH) { w = contentGuiObj->guiobject_getAutoWidth(); rw = 0; }
  140. if (h == AUTOWH) { h = contentGuiObj->guiobject_getAutoHeight(); rh = 0; }
  141. if (what == SUGGESTED_W) {
  142. int p = contentGuiObj->guiobject_getRootWnd()->getPreferences(SUGGESTED_W);
  143. if (rx == 0 && rw == 1)
  144. return p - w;
  145. else if (rx == 0 && rw == 0)
  146. return p + x + w;
  147. } else if (what == SUGGESTED_H) {
  148. int p = contentGuiObj->guiobject_getRootWnd()->getPreferences(SUGGESTED_H);
  149. if (ry == 0 && rh == 1)
  150. return p + y + ((-h)-y);
  151. else if (ry == 0 && rh == 0)
  152. return p + y + h;
  153. }
  154. ifc_window *contentGuiRootWnd = contentGuiObj->guiobject_getRootWnd();
  155. return contentGuiRootWnd->getPreferences(what);
  156. }*/
  157. return TITLEBOX_PARENT::getPreferences(what);
  158. }