1
0

labelwnd.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include <precomp.h>
  2. #include "labelwnd.h"
  3. #include <api/locales/xlatstr.h>
  4. #include <api/wnd/paintsets.h>
  5. #include <tataki/canvas/bltcanvas.h>
  6. #include <tataki/color/skinclr.h>
  7. #include <api/wnd/notifmsg.h>
  8. #include <tataki/region/region.h>
  9. #include <api/wnd/PaintCanvas.h>
  10. static SkinColor labelfg(L"wasabi.labelwnd.foreground");
  11. static SkinColor labelbg(L"wasabi.labelwnd.background", L"Text backgrounds");
  12. #define DEF_LABEL_HEIGHT 0
  13. #define DEF_LABEL_FONTSIZE 16
  14. LabelWnd::LabelWnd() {
  15. show_label = FALSE;
  16. labelsize = DEF_LABEL_FONTSIZE;
  17. labelHeight = 0;
  18. margin=0;
  19. setVirtual(0);
  20. }
  21. void LabelWnd::getClientRect(RECT *r) {
  22. LABELWND_PARENT::getClientRect(r);
  23. r->top += getLabelHeight();
  24. }
  25. int LabelWnd::onResize() {
  26. LABELWND_PARENT::onResize();
  27. invalidateLabel();
  28. /* if (getLabelHeight() <= 0) return 0;
  29. RECT r,ir;
  30. LABELWND_PARENT::getClientRect(&r);
  31. LABELWND_PARENT::getNonClientRect(&ir);
  32. ir.bottom = ir.top + getLabelHeight()+margin;
  33. invalidateRect(&ir);*/
  34. return 1;
  35. }
  36. int LabelWnd::onPaint(Canvas *canvas) {
  37. if (getLabelHeight() <= 0) return LABELWND_PARENT::onPaint(canvas);
  38. PaintBltCanvas paintcanvas;
  39. if (canvas == NULL) {
  40. if (!paintcanvas.beginPaintNC(this)) return 0;
  41. canvas = &paintcanvas;
  42. }
  43. RECT r;
  44. LabelWnd::getNonClientRect(&r);
  45. if (canvas->isFixedCoords()) { // handle possible double buffer
  46. // convert to canvas coords
  47. r.right -= r.left; r.left = 0;
  48. r.bottom -= r.top; r.top = 0;
  49. }
  50. r.bottom = r.top + getLabelHeight();
  51. if (margin) {
  52. r.left+=margin;
  53. r.right-=margin;
  54. r.bottom+=margin*2;
  55. }
  56. LABELWND_PARENT::onPaint(canvas);
  57. int got_focus = gotFocus() || forceFocus();
  58. if (wantRenderBaseTexture()) {
  59. WASABI_API_WND->skin_renderBaseTexture(getBaseTextureWindow(), canvas, r, this);
  60. }
  61. #ifdef WASABI_COMPILE_PAINTSETS
  62. WASABI_API_WND->paintset_render(Paintset::LABEL, canvas, &r, got_focus ? 255 : 64);
  63. #endif
  64. Wasabi::FontInfo fontInfo;
  65. fontInfo.opaque=false;
  66. fontInfo.pointSize = getLabelHeight()-1;
  67. const wchar_t *name = getName();
  68. if (name == NULL || *name == '\0')
  69. name = L"Label";
  70. #define LEFTMARGIN 3
  71. fontInfo.color = labelbg;
  72. const wchar_t *xname = name;
  73. switch(wantTranslation())
  74. {
  75. case 1:
  76. xname = _(name);
  77. break;
  78. case 2:
  79. xname = __(name);
  80. break;
  81. }
  82. canvas->textOut(r.left+LEFTMARGIN+1, r.top+1, xname, &fontInfo);
  83. fontInfo.color = labelfg;
  84. canvas->textOut(r.left+LEFTMARGIN, r.top, xname, &fontInfo);
  85. return 1;
  86. }
  87. void LabelWnd::onSetName() {
  88. LABELWND_PARENT::onSetName();
  89. // make sure label gets repainted
  90. if (isInited()) {
  91. RECT r;
  92. LabelWnd::getNonClientRect(&r);
  93. r.bottom = r.top + getLabelHeight();
  94. invalidateRect(&r);
  95. }
  96. }
  97. //CUTint LabelWnd::childNotify(api_window *child, int msg, intptr_t param1, intptr_t param2) {
  98. //CUT switch (msg) {
  99. //CUT case CHILD_WINDOWSHADE_CAPABLE: return show_label;
  100. //CUT case CHILD_WINDOWSHADE_ENABLE: return TRUE;
  101. //CUT }
  102. //CUT return LABELWND_PARENT::childNotify(child, msg, param1, param2);
  103. //CUT}
  104. int LabelWnd::showLabel(int show) {
  105. show_label = show;
  106. setFontSize(-1);
  107. if (isPostOnInit()) {
  108. onResize();
  109. }
  110. return 1;
  111. }
  112. int LabelWnd::getLabelHeight() {
  113. return show_label ? labelHeight : 0;
  114. }
  115. void LabelWnd::setMargin(int newmargin) {
  116. margin = newmargin;
  117. RECT r;
  118. getNonClientRect(&r);
  119. r.bottom = getLabelHeight()+margin;
  120. invalidateRect(&r);
  121. }
  122. int LabelWnd::onGetFocus() {
  123. LABELWND_PARENT::onGetFocus();
  124. invalidateLabel();
  125. return 1;
  126. }
  127. int LabelWnd::onKillFocus() {
  128. LABELWND_PARENT::onKillFocus();
  129. invalidateLabel();
  130. return 1;
  131. }
  132. void LabelWnd::invalidateLabel() {
  133. if (labelHeight <= 0) return;
  134. RECT ncr;
  135. RECT cr;
  136. // RECT lr;
  137. LabelWnd::getNonClientRect(&ncr);
  138. LabelWnd::getClientRect(&cr);
  139. RegionI nonClientRgn(&ncr);
  140. RegionI clientRgn(&cr);
  141. nonClientRgn.subtractRgn(&clientRgn);
  142. invalidateRgn(&nonClientRgn);
  143. // SubtractRect(&lr, &ncr, &cr); // PORT ME
  144. // invalidateRect(&lr);
  145. }
  146. int LabelWnd::wantFocus() {
  147. return (labelHeight > 0);
  148. }
  149. void LabelWnd::reloadResources()
  150. {
  151. LABELWND_PARENT::reloadResources();
  152. if (isPostOnInit())
  153. onResize();
  154. invalidateLabel();
  155. }
  156. int LabelWnd::setFontSize(int size)
  157. {
  158. LABELWND_PARENT::setFontSize(size);
  159. TextInfoCanvas blt(this);
  160. Wasabi::FontInfo fontInfo;
  161. #ifndef WASABINOMAINAPI
  162. fontInfo.pointSize = labelsize+api->metrics_getDelta();
  163. #else
  164. fontInfo.pointSize = labelsize;
  165. //MULTIAPI-FIXME: not handling delta
  166. #endif
  167. labelHeight = blt.getTextHeight(&fontInfo) + 1;
  168. invalidate();
  169. if (isPostOnInit()) onResize();
  170. return 1;
  171. }