1
0

buttwnd.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. #include <precomp.h>
  2. // bitmap-style buttons
  3. #include "buttwnd.h"
  4. #include <bfc/wasabi_std.h>
  5. #include <tataki/canvas/bltcanvas.h>
  6. #include <tataki/region/region.h>
  7. #include <api/wnd/notifmsg.h>
  8. #include <api/wndmgr/msgbox.h>
  9. #include <api/wnd/PaintCanvas.h>
  10. #define DEFAULT_BUTTON_HEIGHT 20
  11. ButtonWnd::ButtonWnd(const wchar_t *button_text)
  12. {
  13. if (button_text != NULL)
  14. setName(button_text);
  15. currgn = NULL;
  16. hirgn = NULL;
  17. normalrgn = NULL;
  18. pushedrgn = NULL;
  19. activatedrgn = NULL;
  20. base_texture = NULL;
  21. xShift=0;
  22. yShift=0;
  23. textsize = DEFAULT_BUTTON_TEXT_SIZE;
  24. alignment = TEXTALIGN_CENTER;
  25. activated = 0;
  26. userhilite = 0;
  27. userdown = 0;
  28. use_base_texture = 0;
  29. center_bitmap = 0;
  30. enabled = 1;
  31. checked=0;
  32. autodim=0;
  33. borders = 1;
  34. borderstyle = 0;
  35. setBorderStyle(L"button_normal");
  36. iwantfocus = 1;
  37. color_text = L"wasabi.button.text";
  38. color_hilite = L"wasabi.button.hiliteText";
  39. color_dimmed = L"wasabi.button.dimmedText";
  40. checkbmp = L"wasabi.popup.menu.check";
  41. inactivealpha = 255;
  42. activealpha = 255;
  43. setRectRgn(1);
  44. retcode = MSGBOX_ABORTED;
  45. forcedown=0;
  46. }
  47. ButtonWnd::~ButtonWnd() {
  48. delete normalrgn;
  49. delete pushedrgn;
  50. delete hirgn;
  51. delete activatedrgn;
  52. }
  53. void ButtonWnd::checkState(POINT *pt) {
  54. POINT pt2;
  55. if (pt == NULL) {
  56. pt = &pt2;
  57. Wasabi::Std::getMousePos(pt);
  58. }
  59. api_region *old = currgn;
  60. if (getDown()) { // button is down
  61. if (pushedrgn)
  62. currgn = pushedrgn;
  63. else
  64. currgn = normalrgn;
  65. } else { // button is not down
  66. if (hirgn && getHilite())
  67. currgn = hirgn;
  68. else
  69. currgn = normalrgn;
  70. }
  71. if (old != currgn) invalidateWindowRegion();
  72. }
  73. void ButtonWnd::onCancelCapture() {
  74. BUTTONWND_PARENT::onCancelCapture();
  75. checkState();
  76. }
  77. int ButtonWnd::onMouseMove(int x, int y) {
  78. POINT pt;
  79. checkState(&pt);
  80. return BUTTONWND_PARENT::onMouseMove(x, y);
  81. }
  82. api_region *ButtonWnd::getRegion() {
  83. if (borders) return NULL;
  84. return currgn;
  85. }
  86. void ButtonWnd::setModalRetCode(int r) { retcode = r; }
  87. int ButtonWnd::getModalRetCode() const { return retcode; }
  88. void ButtonWnd::onLeaveArea() {
  89. BUTTONWND_PARENT::onLeaveArea();
  90. if (hirgn || getDown()) invalidate();
  91. }
  92. void ButtonWnd::onEnterArea() {
  93. BUTTONWND_PARENT::onEnterArea();
  94. if (hirgn) invalidate();
  95. }
  96. /*BOOL ButtonWnd::mouseInRegion(int x, int y) {
  97. POINT pos={x,y};
  98. POINT p2=pos;
  99. RECT r;
  100. getClientRect(&r);
  101. pos.x-=r.left;
  102. pos.y-=r.top;
  103. return (((!currgn || rectrgn) && PtInRect(&r, p2)) || (currgn && currgn->ptInRegion(&pos)));
  104. }*/
  105. int ButtonWnd::setBitmaps(const wchar_t *_normal, const wchar_t *_pushed, const wchar_t *_hilited, const wchar_t *_activated) {
  106. if (_normal) { delete normalrgn; normalrgn = NULL; }
  107. if (_pushed) { delete pushedrgn; pushedrgn = NULL; }
  108. if (_hilited) { delete hirgn; hirgn = NULL; }
  109. if (_activated) { delete activatedrgn; activatedrgn = NULL; }
  110. if (_normal) {
  111. normalbmp = _normal;
  112. normalrgn = new RegionI(normalbmp.getBitmap());
  113. currgn = normalrgn;
  114. }
  115. if (_pushed) {
  116. pushedbmp = _pushed;
  117. pushedrgn = new RegionI(pushedbmp.getBitmap());
  118. }
  119. if (_hilited) {
  120. hilitebmp = _hilited;
  121. hirgn = new RegionI(hilitebmp.getBitmap());
  122. }
  123. if (_activated) {
  124. activatedbmp = _activated;
  125. activatedrgn = new RegionI(activatedbmp.getBitmap());
  126. }
  127. if (isPostOnInit())
  128. invalidate();
  129. return 1;
  130. }
  131. SkinBitmap *ButtonWnd::getNormalBitmap() {
  132. return normalbmp.getBitmap();
  133. }
  134. void ButtonWnd::freeResources() {
  135. BUTTONWND_PARENT::freeResources();
  136. delete normalrgn;
  137. delete pushedrgn;
  138. delete hirgn;
  139. delete activatedrgn;
  140. pushedrgn=NULL;
  141. normalrgn=NULL;
  142. hirgn=NULL;
  143. activatedrgn=NULL;
  144. currgn=NULL;
  145. }
  146. void ButtonWnd::reloadResources() {
  147. BUTTONWND_PARENT::reloadResources();
  148. if (normalbmp.getBitmap())
  149. normalrgn = new RegionI(normalbmp.getBitmap());
  150. if (pushedbmp.getBitmap())
  151. pushedrgn = new RegionI(pushedbmp.getBitmap());
  152. if (hilitebmp.getBitmap())
  153. hirgn = new RegionI(hilitebmp.getBitmap());
  154. if (activatedbmp.getBitmap())
  155. activatedrgn = new RegionI(activatedbmp.getBitmap());
  156. currgn = normalrgn;
  157. }
  158. int ButtonWnd::setBitmapCenter(int centerit) {
  159. return center_bitmap = !!centerit;
  160. }
  161. int ButtonWnd::setBitmaps(OSMODULEHANDLE hInst, int _normal, int _pushed, int _hilited, int _activated, const wchar_t *_colorgroup)
  162. {
  163. if (_normal) { delete normalrgn; normalrgn = NULL; }
  164. if (_pushed) { delete pushedrgn; pushedrgn = NULL; }
  165. if (_hilited) { delete hirgn; hirgn = NULL; }
  166. if (_activated) { delete activatedrgn; activatedrgn = NULL; }
  167. if (_colorgroup == NULL)
  168. _colorgroup = colorgroup;
  169. if (_normal)
  170. {
  171. normalbmp.setHInstanceBitmapColorGroup(_colorgroup);
  172. #ifdef _WIN32
  173. normalbmp.setHInstance(hInst);
  174. #else
  175. #warning port me?
  176. #endif
  177. normalbmp = _normal;
  178. normalrgn = new RegionI(normalbmp.getBitmap());
  179. }
  180. if (_pushed) {
  181. pushedbmp.setHInstanceBitmapColorGroup(_colorgroup);
  182. #ifdef _WIN32
  183. pushedbmp.setHInstance(hInst);
  184. #else
  185. #warning port me?
  186. #endif
  187. pushedbmp = _pushed;
  188. pushedrgn = new RegionI(pushedbmp.getBitmap());
  189. }
  190. if (_hilited) {
  191. hilitebmp.setHInstanceBitmapColorGroup(_colorgroup);
  192. #ifdef _WIN32
  193. hilitebmp.setHInstance(hInst);
  194. #else
  195. #warning port me?
  196. #endif
  197. hilitebmp = _hilited;
  198. hirgn = new RegionI(hilitebmp.getBitmap());
  199. }
  200. if (_activated) {
  201. activatedbmp.setHInstanceBitmapColorGroup(_colorgroup);
  202. #ifdef _WIN32
  203. activatedbmp.setHInstance(hInst);
  204. #else
  205. #warning port me?
  206. #endif
  207. activatedbmp = _activated;
  208. activatedrgn = new RegionI(activatedbmp.getBitmap());
  209. }
  210. return 1;
  211. }
  212. void ButtonWnd::setUseBaseTexture(int useit)
  213. {
  214. if (use_base_texture == useit) return;
  215. use_base_texture = useit;
  216. invalidate();
  217. }
  218. void ButtonWnd::setBaseTexture(SkinBitmap *bmp, int x, int y, int tile)
  219. {
  220. base_texture = bmp;
  221. use_base_texture = TRUE;
  222. tile_base_texture=tile;
  223. xShift=x;
  224. yShift=y;
  225. invalidate();
  226. }
  227. int ButtonWnd::setButtonText(const wchar_t *text, int size)
  228. {
  229. textsize = size;
  230. ASSERT(textsize > 0);
  231. setName(text);
  232. invalidate();
  233. return 1;
  234. }
  235. const wchar_t * ButtonWnd::getButtonText()
  236. {
  237. return getName();
  238. }
  239. void ButtonWnd::setTextAlign(TextAlign align)
  240. {
  241. alignment = align;
  242. invalidate();
  243. }
  244. int ButtonWnd::getWidth()
  245. {
  246. int addl=0;
  247. if (checked) {
  248. addl=checkbmp.getWidth()+3;
  249. }
  250. if (rightbmp.getBitmap())
  251. addl+=rightbmp.getWidth()+3;
  252. if (normalbmp == NULL)
  253. {
  254. TextInfoCanvas blt(this);
  255. Wasabi::FontInfo fontInfo;
  256. fontInfo.pointSize = textsize;
  257. StringPrintfW lstr(L"j%sj", getNameSafe(L""));
  258. if (wcschr(lstr, '\t')) lstr.cat(L" ");
  259. int a=MAX((blt.getTextWidth(lstr, &fontInfo)*11)/10,8)+addl;
  260. return a;
  261. }
  262. return normalbmp.getWidth()+addl;
  263. }
  264. int ButtonWnd::getHeight()
  265. {
  266. int minh=0;
  267. if (checked>0)
  268. minh=checkbmp.getHeight();
  269. if (rightbmp.getBitmap())
  270. minh=MAX(rightbmp.getHeight(),minh);
  271. if (normalbmp == NULL)
  272. {
  273. TextInfoCanvas blt(this);
  274. Wasabi::FontInfo fontInfo;
  275. fontInfo.pointSize = textsize;
  276. int r = MAX(MAX((blt.getTextHeight(getName(), &fontInfo)*11)/10,minh),4);
  277. return r;
  278. }
  279. return MAX(normalbmp.getHeight(),minh);
  280. }
  281. void ButtonWnd::enableButton(int _enabled) {
  282. _enabled = !!_enabled;
  283. if (enabled != _enabled) invalidate();
  284. enabled = _enabled;
  285. onEnable(enabled);
  286. }
  287. int ButtonWnd::getEnabled() const {
  288. return enabled;
  289. }
  290. int ButtonWnd::onPaint(Canvas *canvas)
  291. {
  292. PaintBltCanvas paintcanvas;
  293. SkinBitmap *bmp;
  294. RECT r;
  295. int labelxoffs=0;
  296. int offset = (enabled&&(getPushed()||getDown())) ? 1 : 0;
  297. if (checked) labelxoffs+=3+checkbmp.getWidth();
  298. if (canvas == NULL) {
  299. if (!paintcanvas.beginPaint(this)) return 0;
  300. canvas = &paintcanvas;
  301. }
  302. BUTTONWND_PARENT::onPaint(canvas);
  303. bmp = normalbmp;
  304. if (pushedbmp && (getDown() || getPushed())) bmp = pushedbmp;
  305. else if ((getHilite() || userhilite) && hilitebmp) bmp = hilitebmp;
  306. else if (activatedbmp && getActivatedButton()) bmp = activatedbmp;
  307. getClientRect(&r);
  308. RECT nr = r;
  309. // RECT fcr = r;
  310. if (use_base_texture)
  311. {
  312. if (!base_texture)
  313. renderBaseTexture(canvas, r);
  314. else {
  315. RECT cr;
  316. cr.left = xShift;
  317. cr.top = yShift;
  318. cr.right = cr.left + (r.right-r.left);
  319. cr.bottom = cr.top + (r.bottom-r.top);
  320. if (tile_base_texture) base_texture->blitTile(canvas, &r,xShift,yShift);
  321. else base_texture->stretchToRectAlpha(canvas, &cr, &r, getPaintingAlpha());
  322. }
  323. }
  324. else
  325. {
  326. if (borders)
  327. {
  328. int sysobj = -1;
  329. if (!enabled)
  330. sysobj = dsoDisabled;
  331. else
  332. sysobj = (getPushed() || getDown()) ? dsoPushed : dsoNormal;
  333. if (sysobj != -1) canvas->drawSysObject(&nr, sysobj, getPaintingAlpha());
  334. }
  335. }
  336. if (checked>0)
  337. {
  338. RECT ar;
  339. int c=(r.top+r.bottom)/2;
  340. ar.left=r.left;
  341. ar.top=c-checkbmp.getHeight()/2;
  342. ar.bottom=ar.top+checkbmp.getHeight();
  343. ar.right=r.left+checkbmp.getWidth();
  344. checkbmp.getBitmap()->stretchToRectAlpha(canvas,&ar,getPaintingAlpha());
  345. }
  346. if (rightbmp.getBitmap()) {
  347. RECT ar;
  348. int c=(r.top+r.bottom)/2;
  349. ar.top=c-rightbmp.getHeight()/2;
  350. ar.bottom=ar.top+rightbmp.getHeight();
  351. ar.right=r.right;
  352. ar.left=ar.right-rightbmp.getWidth();
  353. int alpha = getPaintingAlpha();
  354. if (!getEnabled()) alpha /= 2;
  355. rightbmp.getBitmap()->stretchToRectAlpha(canvas, &ar, alpha);
  356. }
  357. if (bmp != NULL) {
  358. RECT br = r;
  359. if (center_bitmap) {
  360. int w = (r.right - r.left) - getWidth() - labelxoffs;
  361. int h = (r.bottom - r.top) - getHeight();
  362. br.top = r.top + h/2 + offset;
  363. br.bottom = br.top + getHeight();
  364. br.left = r.left + w/2 + labelxoffs + offset;
  365. br.right = br.left + getWidth() - (rightbmp.getBitmap()?rightbmp.getWidth()+3:0);
  366. } else {
  367. br.left += labelxoffs;
  368. br.right -= (rightbmp.getBitmap()?rightbmp.getWidth()+3:0);
  369. }
  370. int alpha2;
  371. if (!hilitebmp && enabled && autodim) {
  372. alpha2=128;
  373. if (getHilite() || userhilite) alpha2=255;
  374. } else alpha2 = enabled ? 255 : 64;
  375. bmp->stretchToRectAlpha(canvas, &br,autodim ? (getPaintingAlpha()+alpha2)>>1 : getPaintingAlpha());
  376. }
  377. if (getName() != NULL)
  378. {
  379. Wasabi::FontInfo fontInfo;
  380. fontInfo.opaque = false;
  381. fontInfo.pointSize = textsize;;
  382. int textw, texth;
  383. canvas->getTextExtent(getName(), &textw, &texth, &fontInfo);
  384. if (!enabled)
  385. fontInfo.color = color_dimmed;
  386. else if (userhilite)
  387. fontInfo.color = color_hilite;
  388. else
  389. fontInfo.color = color_text;
  390. int h=(r.bottom-r.top-texth)/2;
  391. if (h<0) h=0;
  392. r.left += offset + labelxoffs;
  393. r.right += offset - (rightbmp.getBitmap()?rightbmp.getWidth()+3:0);
  394. r.top += offset+h;
  395. r.bottom = r.top+texth;
  396. switch (alignment)
  397. {
  398. case TEXTALIGN_CENTER:
  399. canvas->textOutCentered(&r, getName(), &fontInfo);
  400. break;
  401. case TEXTALIGN_RIGHT:
  402. canvas->textOut(r.right-textw, r.top, textw, texth, getName(), &fontInfo);
  403. break;
  404. case TEXTALIGN_LEFT:
  405. if (!wcsstr(getName(), L"\t"))
  406. {
  407. canvas->textOut(r.left, r.top, r.right-r.left, r.bottom-r.top, getName(), &fontInfo);
  408. }
  409. else
  410. {
  411. StringW lstr(getName());
  412. wchar_t *p=wcsstr(lstr.getNonConstVal(),L"\t");
  413. if (p) *p++=0;
  414. else p=L"";
  415. int tw=canvas->getTextWidth(p, &fontInfo);
  416. canvas->textOut(r.left, r.top, r.right-r.left-tw, r.bottom-r.top, lstr, &fontInfo);
  417. canvas->textOut(r.right-tw, r.top, tw, r.bottom-r.top, p, &fontInfo);
  418. }
  419. break;
  420. case TEXTALIGN_LEFT_ELLIPSIS:
  421. if (!wcsstr(getName(),L"\t"))
  422. {
  423. canvas->textOutEllipsed(r.left, r.top, r.right-r.left, r.bottom-r.top, getName(), &fontInfo);
  424. }
  425. else
  426. {
  427. StringW lstr(getName());
  428. wchar_t *p=wcsstr(lstr.getNonConstVal(),L"\t");
  429. if (p) *p++=0;
  430. else p=L"";
  431. int tw=canvas->getTextWidth(p, &fontInfo);
  432. canvas->textOutEllipsed(r.left, r.top, r.right-r.left-tw, r.bottom-r.top, lstr, &fontInfo);
  433. canvas->textOutEllipsed(r.right-tw, r.top, tw, r.bottom-r.top, p, &fontInfo);
  434. }
  435. break;
  436. }
  437. /*
  438. if (textjustify == BUTTONJUSTIFY_CENTER)
  439. canvas->textOutCentered(&r, getName());
  440. else if (textjustify == BUTTONJUSTIFY_LEFT)
  441. {
  442. if (!STRSTR(getName(),"\t"))
  443. canvas->textOutEllipsed(r.left, r.top, r.right-r.left, r.bottom-r.top, getName());
  444. else
  445. {
  446. char *lstr=STRDUP(getName());
  447. char *p=STRSTR(lstr,"\t");
  448. if (p) *p++=0;
  449. else p="";
  450. int tw=canvas->getTextWidth(p);
  451. canvas->textOutEllipsed(r.left, r.top, r.right-r.left-tw, r.bottom-r.top, lstr);
  452. canvas->textOutEllipsed(r.right-tw, r.top, tw, r.bottom-r.top, p);
  453. FREE(lstr);
  454. }
  455. }
  456. */
  457. }
  458. /* if (enabled && gotFocus() && wantFocus()) { // SKIN ME
  459. fcr.left+=3;
  460. fcr.right-=3;
  461. fcr.top+=3;
  462. fcr.bottom-=3;
  463. DrawFocusRect(canvas->getHDC(), &fcr);
  464. }*/
  465. return 1;
  466. }
  467. void ButtonWnd::onLeftPush(int x, int y)
  468. {
  469. notifyParent(ChildNotify::BUTTON_LEFTPUSH);
  470. invalidate();
  471. }
  472. void ButtonWnd::onRightPush(int x, int y) {
  473. notifyParent(ChildNotify::BUTTON_RIGHTPUSH);
  474. invalidate();
  475. }
  476. void ButtonWnd::onLeftDoubleClick(int x, int y) {
  477. notifyParent(ChildNotify::BUTTON_LEFTDOUBLECLICK);
  478. }
  479. void ButtonWnd::onRightDoubleClick(int x, int y) {
  480. notifyParent(ChildNotify::BUTTON_RIGHTDOUBLECLICK);
  481. }
  482. void ButtonWnd::setHilite(int h) {
  483. h = !!h;
  484. if (userhilite != h) {
  485. userhilite = h;
  486. invalidate();
  487. }
  488. }
  489. int ButtonWnd::getHilite() {
  490. return userhilite || BUTTONWND_PARENT::getHilite();
  491. }
  492. int ButtonWnd::getPushed() const {
  493. return userdown || forcedown;
  494. }
  495. void ButtonWnd::setPushed(int p) {
  496. p = !!p;
  497. if (userdown != p)
  498. {
  499. userdown=p;
  500. invalidate();
  501. }
  502. }
  503. int ButtonWnd::onResize() {
  504. BUTTONWND_PARENT::onResize();
  505. // invalidate();
  506. return 1;
  507. }
  508. void ButtonWnd::setCheckBitmap(const wchar_t *checkbm) {
  509. checkbmp = checkbm;
  510. }
  511. int ButtonWnd::setRightBitmap(const wchar_t *bitmap) {
  512. rightbmp=bitmap;
  513. return 1;
  514. }
  515. void ButtonWnd::setActivatedButton(int a) {
  516. if (activated != a) {
  517. activated = a;
  518. invalidate();
  519. onActivateButton(activated);
  520. }
  521. }
  522. void ButtonWnd::setActivatedNoCallback(int a) {
  523. // also force invalidate.
  524. activated = a;
  525. invalidate();
  526. }
  527. int ButtonWnd::onActivateButton(int active) {
  528. return 1;
  529. }
  530. int ButtonWnd::getActivatedButton() {
  531. return activated;
  532. }
  533. void ButtonWnd::setBorders(int b) {
  534. b = !!b;
  535. if (borders != b) {
  536. borders = b;
  537. setRectRgn(borders);
  538. invalidate();
  539. }
  540. }
  541. void ButtonWnd::setBorderStyle(const wchar_t *style) {
  542. if (style == NULL) style = L"";
  543. if (borderstyle && !WCSICMP(borderstyle, style)) return;
  544. // borderstyle = style;
  545. using namespace DrawSysObj;
  546. static struct {
  547. const wchar_t *style;
  548. int normal, pushed, disabled;
  549. } chart[] = {
  550. { L"button_normal", BUTTON, BUTTON_PUSHED, BUTTON_DISABLED },
  551. { L"osbutton_normal", OSBUTTON, OSBUTTON_PUSHED, OSBUTTON_DISABLED },
  552. { L"osbutton_close", OSBUTTON_CLOSE, OSBUTTON_CLOSE_PUSHED, OSBUTTON_CLOSE_DISABLED },
  553. { L"osbutton_minimize", OSBUTTON_MINIMIZE, OSBUTTON_MINIMIZE_PUSHED, OSBUTTON_MINIMIZE_DISABLED },
  554. { L"osbutton_maximize", OSBUTTON_MAXIMIZE, OSBUTTON_MAXIMIZE_PUSHED, OSBUTTON_MAXIMIZE_DISABLED },
  555. { NULL, BUTTON, BUTTON_PUSHED, BUTTON_DISABLED },
  556. };
  557. dsoNormal = dsoPushed = dsoDisabled = -1;
  558. for (int i = 0; ; i++) {
  559. if (chart[i].style == NULL) return;
  560. if (!WCSICMP(chart[i].style, style)) {
  561. borderstyle = chart[i].style;
  562. dsoNormal = chart[i].normal;
  563. dsoPushed = chart[i].pushed;
  564. dsoDisabled = chart[i].disabled;
  565. }
  566. }
  567. invalidate();
  568. }
  569. const wchar_t *ButtonWnd::getBorderStyle() {
  570. return borderstyle;
  571. }
  572. void ButtonWnd::setInactiveAlpha(int a) {
  573. inactivealpha=a;
  574. }
  575. void ButtonWnd::setActiveAlpha(int a) {
  576. activealpha=a;
  577. }
  578. int ButtonWnd::onGetFocus() {
  579. BUTTONWND_PARENT::onGetFocus();
  580. // invalidate();
  581. return 1;
  582. }
  583. int ButtonWnd::onKillFocus() {
  584. BUTTONWND_PARENT::onKillFocus();
  585. // invalidate();
  586. return 1;
  587. }
  588. void ButtonWnd::setColors(const wchar_t *text, const wchar_t *hilite, const wchar_t *dimmed) {
  589. color_text=text;
  590. color_hilite=hilite;
  591. color_dimmed=dimmed;
  592. invalidate();
  593. }
  594. void ButtonWnd::setTextColor(const wchar_t *text) {
  595. color_text=text;
  596. invalidate();
  597. }
  598. void ButtonWnd::setTextHoverColor(const wchar_t *hilite) {
  599. color_hilite=hilite;
  600. invalidate();
  601. }
  602. void ButtonWnd::setTextDimmedColor(const wchar_t *dimmed) {
  603. color_dimmed=dimmed;
  604. invalidate();
  605. }
  606. int ButtonWnd::onEnable(int is) {
  607. return BUTTONWND_PARENT::onEnable(is);
  608. }
  609. int ButtonWnd::getPreferences(int what) {
  610. switch (what) {
  611. case SUGGESTED_W: {
  612. if (!normalBmpStr.isempty()) return normalbmp.getWidth();
  613. return getWidth();
  614. }
  615. case SUGGESTED_H: {
  616. if (!normalBmpStr.isempty()) return normalbmp.getHeight();
  617. return getHeight();
  618. }
  619. }
  620. return BUTTONWND_PARENT::getPreferences(what);
  621. }
  622. int ButtonWnd::onInit() {
  623. int r = BUTTONWND_PARENT::onInit();
  624. currgn = normalrgn;
  625. return r;
  626. }
  627. int ButtonWnd::onChar(unsigned int c)
  628. {
  629. switch (c) {
  630. #ifdef _WIN32
  631. case VK_RETURN:
  632. case VK_SPACE:
  633. postDeferredCallback(DEFEREDCB_DOWN, 0, 0);
  634. postDeferredCallback(DEFEREDCB_UP, 0, 250);
  635. //return BUTTONWND_PARENT::onChar(c);
  636. break;
  637. #else
  638. #warning port me
  639. #endif
  640. default:
  641. return BUTTONWND_PARENT::onChar(c);
  642. }
  643. return 1;
  644. }
  645. int ButtonWnd::onDeferredCallback(intptr_t p1, intptr_t p2) {
  646. switch (p1) {
  647. case DEFEREDCB_DOWN:
  648. forcedown = 1;
  649. invalidate();
  650. break;
  651. case DEFEREDCB_UP:
  652. forcedown = 0;
  653. invalidate();
  654. RECT r;
  655. getClientRect(&r);
  656. onLeftPush(r.left+(r.right-r.left)/2, r.top+(r.bottom-r.top)/2);
  657. default:
  658. return BUTTONWND_PARENT::onDeferredCallback(p1, p2);
  659. }
  660. return 1;
  661. }