1
0

framewnd.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. #include <precomp.h>
  2. #include "framewnd.h"
  3. #include <api/wnd/notifmsg.h>
  4. #include <bfc/bfc_assert.h>
  5. #include <tataki/canvas/canvas.h>
  6. #include <api/wnd/PaintCanvas.h>
  7. #include <bfc/wasabi_std_wnd.h>
  8. #define DC_FWFOCUS 0x5122
  9. FrameWnd::FrameWnd()
  10. {
  11. // sizer = NULL;
  12. SNAP=1;
  13. snapoffsety=0;
  14. snapoffsetx=0;
  15. nchild = 0;
  16. for (int i = 0; i < MAXCHILD; i++) {
  17. children[i] = NULL;
  18. rwchildren[i] = NULL;
  19. hidey[i] = 0;
  20. windowshaded[i] = 0;
  21. }
  22. vert = DIVIDER_UNDEFINED;
  23. divideside = SDP_FROMLEFT;
  24. pullbarpos = PULLBAR_HALF;
  25. minwidth = PULLBAR_QUARTER-PULLBAR_EIGHTH;
  26. maxwidth = PULLBAR_HALF;
  27. resizeable = 0;
  28. slidemode = FRAMEWND_SQUISH;
  29. prevpullbarpos = -1;
  30. maxpixels=0;
  31. minpixels=0;
  32. noMaxRestriction = false;
  33. ZERO(sizerRect);
  34. h_bitmap = L"wasabi.framewnd.horizontaldivider";
  35. v_bitmap = L"wasabi.framewnd.verticaldivider";
  36. h_grabber = L"wasabi.framewnd.horizontalgrabber";
  37. v_grabber = L"wasabi.framewnd.verticalgrabber";
  38. ws_bitmap = L"wasabi.framewnd.windowshade";
  39. resizing = 0;
  40. }
  41. void FrameWnd::Set_v_bitmap(const wchar_t *new_v_bitmap)
  42. {
  43. v_bitmap=new_v_bitmap;
  44. if (isInited())
  45. {
  46. invalidate();
  47. onResize();
  48. }
  49. }
  50. void FrameWnd::Set_v_grabber(const wchar_t *new_v_grabber)
  51. {
  52. v_grabber=new_v_grabber;
  53. if (isInited())
  54. {
  55. invalidate();
  56. onResize();
  57. }
  58. }
  59. FrameWnd::~FrameWnd() {
  60. #ifdef WASABI_COMPILE_CONFIG
  61. if (getId() != NULL) {
  62. StringPrintfW buf(L"FrameWnd/ws,%s", getId());
  63. WASABI_API_CONFIG->setIntPrivate(buf, windowshaded[0]);
  64. }
  65. #endif
  66. if (children[0]) // do we have any basewnd ?
  67. for (int i = 0; i < nchild; i++) delete children[i];
  68. }
  69. int FrameWnd::onInit() {
  70. int i;
  71. FRAMEWND_PARENT::onInit();
  72. ASSERT(vert != DIVIDER_UNDEFINED || nchild == 0);
  73. // have to set children for frame windows
  74. // fill in members
  75. nchild = 0;
  76. // make children create their windows
  77. for (i = 0; i < MAXCHILD; i++) {
  78. if (rwchildren[i] != NULL) {
  79. if (rwchildren[i]->init(this) != 0) {
  80. rwchildren[i]->setParent(this);
  81. nchild++;
  82. }
  83. }
  84. }
  85. prevpullbarpos = pullbarpos;
  86. if (nchild >= MAXCHILD) {
  87. int which = (divideside == SDP_FROMLEFT) ? 0 : 1;
  88. rwchildren[which]->bringToFront();
  89. }
  90. #ifdef WASABI_COMPILE_CONFIG
  91. if (getId() != NULL) {
  92. StringPrintfW buf(L"FrameWnd/ws,%s", getId());
  93. int ws = WASABI_API_CONFIG->getIntPrivate(buf, /*rwchildren[0] && rwchildren[0]->childNotify(NULL, CHILD_WINDOWSHADE_CAPABLE)*/ 0);
  94. if (ws) {
  95. windowshade(0, !ws);
  96. windowshade(0, ws);
  97. pullbarpos = 0;
  98. }
  99. }
  100. #endif
  101. return 1;
  102. }
  103. int FrameWnd::getCursorType(int x, int y) {
  104. RECT r;
  105. getClientRect(&r);
  106. POINT pt={x,y};
  107. if (y > r.top + getLabelHeight() && Wasabi::Std::pointInRect(sizerRect, pt)) {
  108. if (vert == DIVIDER_HORIZONTAL) return BASEWND_CURSOR_NORTHSOUTH;
  109. else return BASEWND_CURSOR_EASTWEST;
  110. }
  111. return BASEWND_CURSOR_POINTER;
  112. }
  113. int FrameWnd::setChildren(BaseWnd *newchild1, BaseWnd *newchild2) {
  114. return _setChildren(newchild1, newchild2, newchild1, newchild2);
  115. }
  116. int FrameWnd::setChildrenRootWnd(ifc_window *child1, ifc_window *child2/* =NULL */) {
  117. return _setChildren(child1, child2, NULL, NULL);
  118. }
  119. int FrameWnd::_setChildren(ifc_window *child1, ifc_window *child2, BaseWnd *child1b, BaseWnd *child2b) {
  120. if (child1b) { // we can delete them later
  121. children[0] = child1b;
  122. children[1] = child2b;
  123. }
  124. rwchildren[0] = child1;
  125. rwchildren[1] = child2;
  126. nchild = 0;
  127. if (rwchildren[0] != NULL) nchild++;
  128. if (rwchildren[1] != NULL) nchild++;
  129. ASSERTPR(nchild >= 1, "framewnd must have one or more children");
  130. if (isInited()) {
  131. invalidate();
  132. onResize();
  133. }
  134. return nchild;
  135. }
  136. ifc_window *FrameWnd::enumChild(int which) {
  137. if (which < 0 || which >= MAXCHILD) return NULL;
  138. return rwchildren[which];
  139. }
  140. int FrameWnd::childNotify(ifc_window *which, int msg, intptr_t param1, intptr_t param2) {
  141. // ASSERT(which == rwchildren[0] || which == rwchildren[1] || which == NULL);
  142. switch (msg) {
  143. case ChildNotify::FRAMEWND_SETTITLEWIDTH:
  144. if (pullbarpos == param1) return 0;
  145. ASSERT(param1 >= 0);
  146. if (which == rwchildren[0]) {
  147. // rwchildren[1]->invalidate(); //FG> removed due to change in redraw layout
  148. // rwchildren[1]->repaint();
  149. ASSERT(divideside == SDP_FROMLEFT);
  150. } else {
  151. // rwchildren[0]->invalidate();
  152. // rwchildren[0]->repaint();
  153. ASSERT(divideside == SDP_FROMRIGHT);
  154. }
  155. pullbarpos = param1;
  156. // do it
  157. onResize();
  158. return 1;
  159. case ChildNotify::HIDEYHIDEY:
  160. if (which == rwchildren[0]) hidey[0] = 1;
  161. else if (which == rwchildren[1]) hidey[1] = 1;
  162. which->setVisible(FALSE);
  163. onResize();
  164. return 1;
  165. case ChildNotify::UNHIDEYHIDEY:
  166. if (which == rwchildren[0]) hidey[0] = 0;
  167. else if (which == rwchildren[1]) hidey[1] = 0;
  168. which->setVisible(TRUE);
  169. onResize();
  170. return 1;
  171. case ChildNotify::FRAMEWND_QUERY_SLIDE_MODE:
  172. return getSlideMode();
  173. case ChildNotify::FRAMEWND_SET_SLIDE_MODE:
  174. setSlideMode((FrameWndSlideMode)param1);
  175. break;
  176. case ChildNotify::GOTFOCUS:
  177. case ChildNotify::KILLFOCUS:
  178. invalidateLabel();
  179. break;
  180. }
  181. return FRAMEWND_PARENT::childNotify(which, msg, param1, param2);
  182. }
  183. /*int FrameWnd::forceFocus() {
  184. if (!canShowFocus()) return 0; // we aren't showing a label
  185. int v = 0;
  186. if (nchild > 0 && rwchildren[0] != NULL) {
  187. if (!rwchildren[0]->canShowFocus()) v |= rwchildren[0]->gotFocus();
  188. }
  189. if (nchild > 1 && rwchildren[1] != NULL) {
  190. if (!rwchildren[1]->canShowFocus()) v |= rwchildren[1]->gotFocus();
  191. }
  192. return v;
  193. }*/
  194. void FrameWnd::setDividerType(FrameWndDividerType type) {
  195. vert = type;
  196. ASSERT(vert == DIVIDER_VERTICAL || vert == DIVIDER_HORIZONTAL);
  197. if (isInited())
  198. onResize();
  199. }
  200. FrameWndDividerType FrameWnd::getDividerType() {
  201. return vert;
  202. }
  203. int FrameWnd::ConvertPixToProp() {
  204. RECT r;
  205. int w;
  206. getClientRect(&r);
  207. if(vert == DIVIDER_VERTICAL) {
  208. w = r.right-r.left;
  209. } else {
  210. w = r.bottom-r.top;
  211. }
  212. w = (pullbarpos * PULLBAR_FULL) / w;
  213. return w;
  214. }
  215. int FrameWnd::convertPropToPix(int prop) {
  216. RECT r;
  217. int w;
  218. getClientRect(&r);
  219. if(vert == DIVIDER_VERTICAL) {
  220. w = r.right-r.left;
  221. } else {
  222. w = r.bottom-r.top;
  223. }
  224. return (w * prop) / PULLBAR_FULL;
  225. }
  226. int FrameWnd::setDividerPosNoCfg(int from, int pos) {
  227. divideside = from;
  228. ASSERT(pos >= 0);
  229. pullbarpos = pos;
  230. if (isInited())
  231. onResize();
  232. StringPrintfW buf(L"FrameWnd/%s,p", getId());
  233. WASABI_API_CONFIG->setIntPrivate(buf, pullbarpos);
  234. return 1;
  235. }
  236. int FrameWnd::setDividerPos(int from, int pos) {
  237. #ifdef WASABI_COMPILE_CONFIG
  238. if (getId() != NULL) {
  239. StringPrintfW buf(L"FrameWnd/%s,p", getId());
  240. pos = WASABI_API_CONFIG->getIntPrivate(buf, pos);
  241. if (pos <= 0) pos = 0;
  242. else if (pos >= PULLBAR_FULL) pos = PULLBAR_FULL;
  243. }
  244. #endif
  245. return setDividerPosNoCfg(from, pos);
  246. }
  247. void FrameWnd::getDividerPos(int *from, int *pos) {
  248. if (from != NULL) *from = divideside;
  249. if (pos != NULL) *pos = pullbarpos;
  250. }
  251. int FrameWnd::setResizeable(int is) {
  252. int prev = resizeable;
  253. resizeable = is;
  254. return prev;
  255. }
  256. void FrameWnd::setMinWidth(int min) {
  257. //ASSERT(min >= 0);
  258. minpixels = min;
  259. }
  260. void FrameWnd::setMaxWidth(int max)
  261. {
  262. //ASSERT(max >= 0);
  263. maxpixels=max;
  264. noMaxRestriction = (max == 0);
  265. //maxwidth = max;
  266. }
  267. void FrameWnd::setSlideMode(FrameWndSlideMode mode) {
  268. slidemode = mode;
  269. if (isInited())
  270. onResize();
  271. }
  272. FrameWndSlideMode FrameWnd::getSlideMode() {
  273. return slidemode;
  274. }
  275. int FrameWnd::dragEnter(ifc_window *sourceWnd) {
  276. ifc_window *ch = getWindowShadedChild();
  277. if (ch == NULL) return FRAMEWND_PARENT::dragEnter(sourceWnd);
  278. return ch->getDragInterface()->dragEnter(sourceWnd);
  279. }
  280. int FrameWnd::dragOver(int x, int y, ifc_window *sourceWnd) {
  281. ifc_window *ch = getWindowShadedChild();
  282. if (ch == NULL) return FRAMEWND_PARENT::dragOver(x, y, sourceWnd);
  283. return ch->getDragInterface()->dragOver(-1, -1, sourceWnd);
  284. }
  285. int FrameWnd::dragLeave(ifc_window *sourceWnd) {
  286. ifc_window *ch = getWindowShadedChild();
  287. if (ch == NULL) return FRAMEWND_PARENT::dragLeave(sourceWnd);
  288. return ch->getDragInterface()->dragLeave(sourceWnd);
  289. }
  290. int FrameWnd::dragDrop(ifc_window *sourceWnd, int x, int y) {
  291. ifc_window *ch = getWindowShadedChild();
  292. if (ch == NULL) return FRAMEWND_PARENT::dragDrop(sourceWnd, x, y);
  293. return ch->getDragInterface()->dragDrop(sourceWnd, x, y);
  294. }
  295. int FrameWnd::onResize()
  296. {
  297. int rt = FRAMEWND_PARENT::onResize();
  298. if (!isInited()) return rt;
  299. RECT r;
  300. int sizerwidth = SIZERWIDTH;
  301. if (!isInited()) {
  302. prevpullbarpos = pullbarpos;
  303. return 1; // no window to resize
  304. }
  305. getClientRect(&r);
  306. ASSERT(nchild >= 0);
  307. if (nchild == 0) {
  308. prevpullbarpos = pullbarpos;
  309. return 1;
  310. }
  311. if (hidey[0] && hidey[1]) return 0; // both windows are hiding
  312. // if we have only one child, it takes up all the room
  313. if (hidey[0]) {
  314. rwchildren[1]->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  315. return 1;
  316. } else if (hidey[1]) {
  317. rwchildren[0]->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  318. return 1;
  319. }
  320. if (nchild == 1) {
  321. if (rwchildren[0] != NULL) rwchildren[0]->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  322. else if (rwchildren[1] != NULL) rwchildren[1]->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  323. return 1;
  324. }
  325. #ifdef ASSERTS_ENABLED
  326. for (int i = 0; i < nchild; i++) {
  327. ASSERT(rwchildren[i] != NULL);
  328. }
  329. #endif
  330. if (!resizeable) sizerwidth = 0;
  331. // resize the subwindows
  332. int w;
  333. if (vert == DIVIDER_VERTICAL) {
  334. w = r.right-r.left;
  335. } else {
  336. w = r.bottom-r.top;
  337. }
  338. int clientwidth = w; // the logical width
  339. switch (pullbarpos) {
  340. case PULLBAR_FULL: /*w = w;*/ break;
  341. case PULLBAR_HALF: w = w/2; break;
  342. case PULLBAR_QUARTER: w = w/4; break;
  343. case PULLBAR_THREEQUARTER: w = w - w/4; break;
  344. case PULLBAR_EIGHTH: w = w/8; break;
  345. default: w = pullbarpos; break;
  346. }
  347. // maxpixels holds normally a negative or zero value!
  348. if (divideside == SDP_FROMRIGHT)
  349. {
  350. w = (clientwidth - w);
  351. if (maxpixels < 1 && w < -maxpixels) w = -maxpixels; // Martin> This fixes an ugly drawing overlap
  352. // TODO: check non-relative width as well, imoh we should rewrite this function from scrap.
  353. }
  354. else // FROMLEFT
  355. {
  356. if (maxpixels < 1 && w > clientwidth + maxpixels)
  357. w = clientwidth + maxpixels;
  358. if (w < minpixels)
  359. w = minpixels;
  360. }
  361. RECT r1, r2;
  362. if (slidemode == FRAMEWND_COVER) { // cover mode
  363. ASSERTPR(vert == DIVIDER_VERTICAL, "finish implementing");
  364. if (divideside == SDP_FROMRIGHT) {
  365. Wasabi::Std::setRect(&r1, r.left, r.top, r.right-r.left, r.bottom-r.top); //FG> delay resize
  366. Wasabi::Std::setRect(&r2, r.left+w, r.top, r.left+clientwidth - w, r.bottom-r.top);
  367. } else {
  368. Wasabi::Std::setRect(&r1, r.left, r.top, r.left+w, r.bottom-r.top); //FG> delay resize
  369. Wasabi::Std::setRect(&r2, r.left, r.top, r.right-r.left, r.bottom-r.top);
  370. }
  371. sizerRect.top = r.top;
  372. sizerRect.bottom = r.bottom;
  373. sizerRect.left = r.left + w;
  374. sizerRect.right = r.left + w + sizerwidth;
  375. } else { // squish mode
  376. // left-right
  377. if (vert == DIVIDER_VERTICAL) {
  378. sizerRect.top = r.top;
  379. sizerRect.bottom = r.bottom;
  380. if (divideside == SDP_FROMLEFT) { // from left
  381. //FG> Warning, this is using a rect for x,y,W,H and NOT l,r,t,b
  382. Wasabi::Std::setRect(&r1, r.left, r.top, w, r.bottom-r.top);
  383. Wasabi::Std::setRect(&r2, r.left+w+sizerwidth, r.top, (r.right-r.left)-(w+sizerwidth), r.bottom-r.top);
  384. sizerRect.left = r.left+w;
  385. sizerRect.right = sizerRect.left + sizerwidth;
  386. }
  387. else { // from right
  388. //FG> Warning, this is using a rect for x,y,W,H and NOT l,r,t,b
  389. Wasabi::Std::setRect(&r1, r.left, r.top, w-sizerwidth, r.bottom-r.top);
  390. Wasabi::Std::setRect(&r2, r.left+w, r.top, (r.right-r.left)-w, r.bottom-r.top);
  391. sizerRect.left = r.left+w-sizerwidth;
  392. sizerRect.right = r.left+w;
  393. }
  394. } else {
  395. // top-bottom
  396. //FG> Warning, this is using a rect for x,y,W,H and NOT l,r,t,b
  397. Wasabi::Std::setRect(&r1, r.left, r.top, r.right-r.left, w);
  398. Wasabi::Std::setRect(&r2, r.left, r.top+w+sizerwidth, r.right-r.left, (r.bottom-r.top)-(w+sizerwidth));
  399. sizerRect.top = r.top+w;
  400. sizerRect.bottom = r.top+w+sizerwidth;
  401. sizerRect.left = r.left;
  402. sizerRect.right = r.right;
  403. }
  404. }
  405. //FG> Choose resizing order. optimizes redraw by avoiding temporary overlap of rwchildren
  406. bool reverse = false;
  407. if (vert == DIVIDER_VERTICAL) {
  408. RECT o;
  409. rwchildren[0]->getNonClientRect(&o);
  410. reverse = (r1.right > o.right);
  411. } else {
  412. RECT o;
  413. rwchildren[0]->getNonClientRect(&o);
  414. reverse = (r1.bottom > o.bottom);
  415. }
  416. //FG> actually resize rwchildren
  417. //FG> Warning, this is using a rect for x,y,W,H and NOT l,r,t,b
  418. if (reverse) {
  419. rwchildren[1]->resize(r2.left, r2.top, r2.right, r2.bottom);
  420. rwchildren[0]->resize(r1.left, r1.top, r1.right, r1.bottom);
  421. } else {
  422. rwchildren[0]->resize(r1.left, r1.top, r1.right, r1.bottom);
  423. rwchildren[1]->resize(r2.left, r2.top, r2.right, r2.bottom);
  424. }
  425. onResizeChildren(r1, r2);
  426. // RECT ri = sizerRect;
  427. #if 0
  428. if (vert == DIVIDER_HORIZONTAL) {
  429. ri.left -= 2;
  430. ri.right += 2;
  431. } else {
  432. ri.top -= 2;
  433. ri.bottom += 2;
  434. }
  435. #endif
  436. // invalidateRect(&ri);
  437. invalidate();
  438. repaint();
  439. prevpullbarpos = pullbarpos;
  440. return 1;
  441. }
  442. void FrameWnd::onResizeChildren(RECT leftr, RECT rightr) {
  443. }
  444. int FrameWnd::onPaint(Canvas *canvas) {
  445. RECT d;
  446. getClientRect(&d);
  447. if ((d.left >= d.right) || (d.top >= d.bottom)) {
  448. return FRAMEWND_PARENT::onPaint(canvas);
  449. }
  450. RECT cr;
  451. // PaintBltCanvas paintcanvas;
  452. PaintCanvas paintcanvas;
  453. // if only 1 child, we don't paint anything
  454. if (nchild <= 1) return FRAMEWND_PARENT::onPaint(canvas);
  455. if (canvas == NULL) {
  456. if (!paintcanvas.beginPaint(this)) return 0;
  457. canvas = &paintcanvas;
  458. }
  459. FRAMEWND_PARENT::onPaint(canvas);
  460. getClientRect(&cr);
  461. if (wantRenderBaseTexture() || !isVirtual())
  462. renderBaseTexture(canvas, cr);
  463. if (resizeable) {
  464. RECT r = sizerRect;
  465. if (vert == DIVIDER_HORIZONTAL) {
  466. r.left -= 2;
  467. r.right += 2;
  468. } else {
  469. r.top -= 2;
  470. r.bottom += 2;
  471. }
  472. AutoSkinBitmap &bitmap = (vert == DIVIDER_VERTICAL) ? v_bitmap : h_bitmap;
  473. bitmap.stretchToRectAlpha(canvas, &r);
  474. if (vert == DIVIDER_VERTICAL) {
  475. int h = sizerRect.bottom - sizerRect.top;
  476. int gh = v_grabber.getHeight();
  477. if (h > gh) {
  478. RECT rr = sizerRect;
  479. rr.top += (h - gh) / 2;
  480. rr.bottom -= (h - gh) / 2;
  481. v_grabber.stretchToRectAlpha(canvas, &rr);
  482. }
  483. } else {
  484. int w = sizerRect.right - sizerRect.left;
  485. int gw = h_grabber.getWidth();
  486. if (w > gw) {
  487. RECT rr = sizerRect;
  488. rr.left += (w - gw) / 2;
  489. rr.right -= (w - gw) / 2;
  490. h_grabber.stretchToRectAlpha(canvas, &rr);
  491. }
  492. }
  493. if (windowshaded[0]) {
  494. RECT wr = cr;
  495. if (vert == DIVIDER_VERTICAL) {
  496. wr.right = r.left;
  497. } else if (vert == DIVIDER_HORIZONTAL) {
  498. wr.bottom = r.top;
  499. }
  500. ws_bitmap.stretchToRect(canvas, &wr);
  501. }
  502. }
  503. return 1;
  504. }
  505. int FrameWnd::onLeftButtonDown(int x, int y) {
  506. FRAMEWND_PARENT::onLeftButtonDown(x, y);
  507. if (!resizeable) return 1;
  508. POINT p = { x, y };
  509. if (Wasabi::Std::pointInRect(sizerRect, p)) {
  510. beginCapture();
  511. RECT r;
  512. getClientRect(&r);
  513. x -= r.left;
  514. y -= r.top;
  515. snapoffsety= y - (y % SNAP);
  516. snapoffsetx= x - (x % SNAP);
  517. resizing = 1;
  518. return 1;
  519. }
  520. return 0;
  521. }
  522. int FrameWnd::onMouseMove(int x, int y) {
  523. int pos, mpos;
  524. RECT r;
  525. if (!resizing) return 1;
  526. FRAMEWND_PARENT::onMouseMove(x,y);
  527. prevpullbarpos = pullbarpos;
  528. getClientRect(&r);
  529. x -= r.left;
  530. y -= r.top;
  531. if (vert == DIVIDER_VERTICAL) {
  532. pos = r.right - r.left;
  533. if ((x - (x % SNAP)) == snapoffsetx)
  534. return 1;
  535. mpos=x;
  536. snapoffsetx=(x - (x % SNAP));
  537. } else {
  538. pos = r.bottom - r.top;
  539. if ((y - (y % SNAP)) == snapoffsety)
  540. return 1;
  541. mpos=y;
  542. snapoffsety=y - (y % SNAP);
  543. }
  544. ASSERT(pos != 0);
  545. if (mpos < 0) mpos = 0;
  546. if (mpos > pos) mpos = pos;
  547. if(divideside == SDP_FROMLEFT) {
  548. pullbarpos = mpos;
  549. } else {
  550. pullbarpos = pos-mpos;
  551. }
  552. int realMinPixels;
  553. if (minpixels)
  554. {
  555. realMinPixels=minpixels;
  556. if (minpixels<0)
  557. realMinPixels = (r.bottom - r.top) + minpixels;
  558. }
  559. else
  560. realMinPixels = convertPropToPix(minwidth);
  561. if (divideside == SDP_FROMLEFT)
  562. {
  563. if (pullbarpos < realMinPixels)
  564. {
  565. if (rwchildren[0] != NULL && rwchildren[0]->childNotify(NULL, ChildNotify::FRAMEWND_WINDOWSHADE_CAPABLE, 0, 0)) {
  566. pullbarpos = 0;
  567. windowshade(0, TRUE);
  568. } else {
  569. pullbarpos = realMinPixels;
  570. }
  571. } else {
  572. windowshade(0, FALSE);
  573. }
  574. } else if (divideside == SDP_FROMRIGHT) {
  575. if (pullbarpos < realMinPixels) {
  576. if (rwchildren[1] != NULL /* && rwchildren[1]->childNotify(NULL, CHILD_WINDOWSHADE_CAPABLE) */) {
  577. pullbarpos = /*convertPropToPix(PULLBAR_FULL)-*/0;
  578. windowshade(1, TRUE);
  579. } else {
  580. pullbarpos = realMinPixels;
  581. }
  582. } else {
  583. windowshade(1, FALSE);
  584. }
  585. }
  586. if (!windowshaded[0] && !windowshaded[1]) {
  587. // if (pullbarpos > pos-convertPropToPix(minwidth))
  588. // pullbarpos = pos-convertPropToPix(minwidth);
  589. int realMaxPixels;
  590. if (maxpixels || noMaxRestriction)
  591. {
  592. realMaxPixels=maxpixels;
  593. if (maxpixels<0 || noMaxRestriction)
  594. {
  595. if (vert == DIVIDER_VERTICAL)
  596. realMaxPixels = (r.right - r.left) + maxpixels;
  597. else
  598. realMaxPixels = (r.bottom - r.top) + maxpixels;
  599. }
  600. }
  601. else
  602. realMaxPixels=convertPropToPix(maxwidth);
  603. if (pullbarpos > realMaxPixels)
  604. pullbarpos = realMaxPixels;
  605. }
  606. ASSERT(pullbarpos >= 0);
  607. if (pullbarpos != prevpullbarpos && isInited())
  608. onResize();
  609. return 1;
  610. }
  611. int FrameWnd::onLeftButtonUp(int x, int y) {
  612. FRAMEWND_PARENT::onLeftButtonUp(x, y);
  613. if (resizing) {
  614. endCapture();
  615. resizing = 0;
  616. #ifdef WASABI_COMPILE_CONFIG
  617. if (getId() != NULL) {
  618. StringPrintfW buf(L"FrameWnd/%s,p", getId());
  619. WASABI_API_CONFIG->setIntPrivate(buf, pullbarpos);
  620. }
  621. #endif
  622. return 1;
  623. }
  624. return 0;
  625. }
  626. void FrameWnd::windowshade(int which, int shaded) {
  627. ASSERT(which == 0 || which == 1);
  628. if (!!windowshaded[which] == !!shaded) return;
  629. if (rwchildren[which] == NULL) return;
  630. rwchildren[which]->childNotify(NULL, ChildNotify::FRAMEWND_WINDOWSHADE_ENABLE, shaded, 0);
  631. windowshaded[which] = shaded;
  632. rwchildren[which]->setVisible(!shaded);
  633. }
  634. ifc_window *FrameWnd::getWindowShadedChild() {
  635. if (nchild != 2) return NULL;
  636. if (!(windowshaded[0] | windowshaded[1])) return NULL;
  637. return windowshaded[0] ? rwchildren[0] : rwchildren[1];
  638. }
  639. int FrameWnd::onGetFocus() {
  640. postDeferredCallback(DC_FWFOCUS, 0);
  641. return 1;
  642. }
  643. int FrameWnd::onDeferredCallback(intptr_t p1, intptr_t p2) {
  644. switch (p1) {
  645. case DC_FWFOCUS:
  646. if (rwchildren[0]) rwchildren[0]->setFocus();
  647. break;
  648. default:
  649. return FRAMEWND_PARENT::onDeferredCallback(p1, p2);
  650. }
  651. return 1;
  652. }
  653. void FrameWnd::setSnap(int snap)
  654. {
  655. if (snap>0)
  656. SNAP=snap;
  657. }