Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5279 lines
146 KiB

  1. #include "ctlspriv.h"
  2. #include "image.h"
  3. #define ANIMSTEPS 10
  4. #define ANIMSTEPTIME 5
  5. #define CX_CHEVRON (g_cxScrollbar)
  6. #define CX_OFFSET (2 * g_cxEdge)
  7. #define GRABWIDTH 5
  8. //*** RBC_* -- commands
  9. #define RBC_QUERY 0
  10. #define RBC_SET 1
  11. typedef struct tagREBARBAND
  12. {
  13. UINT fStyle;
  14. COLORREF clrFore;
  15. COLORREF clrBack;
  16. LPTSTR lpText;
  17. int cxText; // width of header text
  18. int iImage;
  19. int cxMinChild; // min width for hwndChild
  20. int cyMinChild; // min height for hwndChild
  21. int cxBmp;
  22. int cyBmp;
  23. int x; // left edge of band, relative to rebar
  24. int y; // top edge of band, relative to rebar
  25. int cx; // total width of band
  26. int cy; // height of band
  27. int cxRequest; // 'requested' width for band; either requested by host or used as temp var during size recalculation
  28. int cxMin; // min width for band
  29. int cxIdeal; // hwndChild's desired width
  30. int cyMaxChild; // hwndChild's max height
  31. int cyIntegral; // ??
  32. int cyChild; // this differs from cyMinChild only in RBBS_VARIABLEHEIGHT mode
  33. HWND hwndChild;
  34. HBITMAP hbmBack;
  35. UINT wID;
  36. LPARAM lParam;
  37. BOOL fChevron; // band is showing chevron button
  38. RECT rcChevron; // chevron button rect
  39. UINT wChevState; // chevron button state (DFCS_PUSHED, etc.)
  40. } RBB, *PRBB;
  41. class CReBar
  42. {
  43. public:
  44. private:
  45. void _CacheThemeInfo(BOOL fOpenNew);
  46. int _GetGripperWidth();
  47. void _Realize(HDC hdcParam, BOOL fBackground, BOOL fForceRepaint);
  48. LRESULT _SendNotify(UINT uBand, int iCode);
  49. BOOL _InvalidateRect(RECT* prc);
  50. static LRESULT s_DragCallback(HWND hwnd, UINT code, WPARAM wp, LPARAM lp);
  51. BOOL _CanBandMove(PRBB prbb);
  52. void _BandCalcMinWidth(PRBB prbb);
  53. BOOL _ShouldDrawGripper(PRBB prbb);
  54. BOOL _BandCalcTextExtent(PRBB prbb, HDC hdcIn);
  55. int _BandGetHeight(PRBB prbb);
  56. UINT _GetRowCount();
  57. int _GetLineHeight(UINT iStart, UINT iEnd);
  58. void _BandRecalcChevron(PRBB prbb, BOOL fChevron);
  59. void _ResizeChildren();
  60. BOOL _MoveBand(UINT iFrom, UINT iTo);
  61. int _Recalc(LPRECT prc, BOOL fForce = FALSE);
  62. void _ResizeNow();
  63. void _Resize(BOOL fForceHeightChange);
  64. void _SetRecalc(BOOL fRecalc);
  65. BOOL _SetRedraw(BOOL fRedraw);
  66. BOOL _AfterSetFont();
  67. BOOL _OnSetFont(HFONT hFont);
  68. BOOL _SetFont(WPARAM wParam);
  69. void _VertMungeGripperRect(LPRECT lprc);
  70. void _DrawChevron(PRBB prbb, HDC hdc);
  71. void _UpdateChevronState(PRBB prbb, WORD wControlState);
  72. void _DrawBand(PRBB prbb, HDC hdc);
  73. void _OnPaint(HDC hdcIn);
  74. void _BandTileBlt(PRBB prbb, int x, int y, int cx, int cy, HDC hdcDst, HDC hdcSrc);
  75. int _InternalHitTest(LPRBHITTESTINFO prbht, int x, int y);
  76. int _HitTest(LPRBHITTESTINFO prbht);
  77. BOOL _EraseBkgnd(HDC hdc, int iBand);
  78. BOOL _GetBarInfo(LPREBARINFO lprbi);
  79. BOOL _SetBarInfo(LPREBARINFO lprbi);
  80. BOOL _GetBandInfo(UINT uBand, LPREBARBANDINFO lprbbi);
  81. BOOL _ValidateBandInfo(LPREBARBANDINFO *pprbbi, LPREBARBANDINFO prbbi);
  82. BOOL _SetBandInfo(UINT uBand, LPREBARBANDINFO lprbbi, BOOL fAllowRecalc);
  83. BOOL _ReallocBands(UINT cBands);
  84. BOOL _RecalcFirst(int nCmd, PRBB prbbDelHide);
  85. BOOL _ShowBand(UINT uBand, BOOL fShow);
  86. BOOL _DeleteBand(UINT uBand);
  87. BOOL _InsertBand(UINT uBand, LPREBARBANDINFO lprbbi);
  88. PRBB _GetFirstInRow(PRBB prbbRow);
  89. PRBB _GetLastInRow(PRBB prbbRow, BOOL fStopAtFixed);
  90. PRBB _GetPrev(PRBB prbb, UINT uStyleSkip);
  91. PRBB _GetNext(PRBB prbb, UINT uStyleSkip);
  92. int _CountBands(UINT uStyleSkip);
  93. PRBB _EnumBand(int i, UINT uStyleSkip);
  94. int _MinX(PRBB prbb);
  95. int _MaxX(PRBB prbb);
  96. BOOL _MinimizeBand(UINT uBand, BOOL fAnim);
  97. BOOL _MaximizeBand(UINT uBand, BOOL fIdeal, BOOL fAnim);
  98. void _ToggleBand(BOOL fAnim);
  99. void _SetCursor(int x, int y, BOOL fMouseDown);
  100. BOOL _SetBandPos(PRBB prbb, int xLeft);
  101. BOOL _SetBandPosAnim(PRBB prbb, int xLeft);
  102. void _OnBeginDrag(UINT uBand);
  103. void _PassBreak(PRBB prbbSrc, PRBB prbbDest);
  104. void _GetClientRect(LPRECT prc);
  105. BOOL _RecalcIfMove(PRBB prbb);
  106. BOOL _RoomForBandVert(PRBB prbbSkip);
  107. BOOL _MakeNewRow(PRBB prbb, int y);
  108. void _DragBand(int x, int y);
  109. HPALETTE _SetPalette(HPALETTE hpal);
  110. BOOL _OnDestroy();
  111. void _InitPaletteHack();
  112. UINT _IDToIndex(UINT id);
  113. int _GetRowHeight(UINT uRow);
  114. int _GrowBand(PRBB prbb, int dy, BOOL fResize, int iLineHeight);
  115. int _SizeDifference(LPRECT prc);
  116. int _GetRowHeightExtra(PRBB *pprbb, PRBB prbbSkip);
  117. BOOL _BandsAtMinHeight();
  118. BOOL _SizeBandsToRect(LPRECT prc);
  119. void _SizeBandToRowHeight(int i, int uRowHeight);
  120. void _SizeBandsToRowHeight();
  121. BOOL _OkayToChangeBreak(PRBB prbb, UINT uMsg);
  122. LRESULT _SizeBarToRect(DWORD dwFlags, LPRECT prc);
  123. void _AutoSize();
  124. LRESULT _GetBandBorders(int wParam, LPRECT prc);
  125. void _OnStyleChanged(WPARAM wParam, LPSTYLESTRUCT lpss);
  126. void _OnMouseMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  127. void _OnPushChevron(HWND hwnd, PRBB prbb, LPARAM lParamNM);
  128. void _InvalidateBorders(PRBB prbb);
  129. void _OnCreate(HWND hwnd, LPCREATESTRUCT pcs);
  130. static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  131. LRESULT _WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  132. PRBB CReBar::_GetPrevVisible(PRBB prbb)
  133. {
  134. return _GetPrev(prbb, RBBS_HIDDEN);
  135. }
  136. PRBB CReBar::_GetNextVisible(PRBB prbb)
  137. {
  138. return _GetNext(prbb, RBBS_HIDDEN);
  139. }
  140. BOOL CReBar::_DragSize(int xLeft)
  141. {
  142. // adjust the captured band's starting location to the given location
  143. return _SetBandPos(_GetBand(_uCapture), xLeft);
  144. }
  145. int _FudgeWidth(int cx)
  146. {
  147. if (_UseBandBorders())
  148. cx += g_cxEdge;
  149. return cx + _mBand.cxLeftWidth + _mBand.cxRightWidth;
  150. }
  151. int _BandWidth(PRBB prbb)
  152. {
  153. ASSERT(!(prbb->fStyle & RBBS_HIDDEN));
  154. return _FudgeWidth(prbb->cx);
  155. }
  156. int _BandMinWidth(PRBB prbb)
  157. {
  158. ASSERT(!(prbb->fStyle & RBBS_HIDDEN));
  159. return _FudgeWidth(prbb->cxMin);
  160. }
  161. BOOL _UseBandBorders()
  162. {
  163. return _ci.style & RBS_BANDBORDERS;
  164. }
  165. BOOL _UseChevron(PRBB prbb)
  166. {
  167. return (prbb->fStyle & RBBS_USECHEVRON) &&
  168. !(prbb->fStyle & RBBS_FIXEDSIZE) &&
  169. (prbb->cxIdeal > prbb->cxMinChild);
  170. }
  171. BOOL _ShowText(PRBB prbb)
  172. {
  173. return !(prbb->fStyle & RBBS_HIDETITLE) && prbb->lpText && prbb->lpText[0];
  174. }
  175. BOOL _IsVertical()
  176. {
  177. return (_ci.style & CCS_VERT);
  178. }
  179. BOOL _IsVerticalGripper()
  180. {
  181. return _IsVertical() && (_ci.style & RBS_VERTICALGRIPPER);
  182. }
  183. PRBB _GetLastBand()
  184. {
  185. if (_cBands > 0)
  186. return _GetBand(_cBands - 1);
  187. return NULL;
  188. }
  189. BOOL _IsBandStartOfRow(PRBB prbb)
  190. {
  191. return (prbb->x == _mBand.cxLeftWidth) && !(prbb->fStyle & RBBS_HIDDEN);
  192. }
  193. PRBB _GetBand(UINT i)
  194. {
  195. _ValidateRangeInd(i);
  196. return &_rbbList[i];
  197. }
  198. UINT _BandToIndex(PRBB prbb)
  199. {
  200. return (UINT)(prbb - _rbbList);
  201. }
  202. int _GetHeaderWidth(PRBB prbb)
  203. {
  204. return (prbb->cxMin - (prbb->cxMinChild + (_UseChevron(prbb) ? CX_CHEVRON : 0)));
  205. }
  206. BOOL _IsBandVisible(PRBB prbb)
  207. {
  208. return !(prbb->fStyle & RBBS_HIDDEN);
  209. }
  210. BOOL _IsRowAtMinHeight(PRBB* pprbb)
  211. {
  212. return !_GetRowHeightExtra(pprbb, NULL);
  213. }
  214. int _GetBarHeight()
  215. {
  216. return (_cBands && _cy == 0) ? _Recalc(NULL, TRUE) : _cy;
  217. }
  218. BOOL _IsValidIndex(UINT i)
  219. {
  220. return (BOOL)(i < _cBands);
  221. }
  222. BOOL _IsValidBand(PRBB prbb)
  223. {
  224. return _IsValidIndex(_BandToIndex(prbb));
  225. }
  226. COLORREF _GetBkColor()
  227. {
  228. if (_clrBk == CLR_DEFAULT)
  229. return g_clrBtnFace;
  230. else
  231. return _clrBk;
  232. }
  233. COLORREF _GetTextColor()
  234. {
  235. if (_clrText == CLR_DEFAULT)
  236. return g_clrBtnText;
  237. else
  238. return _clrText;
  239. }
  240. COLORREF _BandGetBkColor(PRBB prbb)
  241. {
  242. switch(prbb->clrBack)
  243. {
  244. case CLR_NONE:
  245. // CLR_NONE means "use our dad's color"
  246. return _GetBkColor();
  247. case CLR_DEFAULT:
  248. return g_clrBtnFace;
  249. default:
  250. return prbb->clrBack;
  251. }
  252. }
  253. COLORREF _BandGetTextColor(PRBB prbb)
  254. {
  255. switch (prbb->clrFore)
  256. {
  257. case CLR_NONE:
  258. // CLR_NONE means "use our dad's color"
  259. return _GetTextColor();
  260. case CLR_DEFAULT:
  261. return g_clrBtnText;
  262. default:
  263. return prbb->clrFore;
  264. }
  265. }
  266. //
  267. // Our use of CLR_DEFAULT for the band background colors is new for
  268. // version 5.01. Since we don't want to confuse apps by returning
  269. // CLR_DEFAULT when they used to see a real colorref, we convert it
  270. // before returning it to them. If the background color is CLR_NONE,
  271. // though, we need to return it without conversion (like version 4 did).
  272. // The *External functions handle these cases.
  273. //
  274. COLORREF _BandGetTextColorExternal(PRBB prbb)
  275. {
  276. if (prbb->clrFore == CLR_NONE)
  277. return CLR_NONE;
  278. else
  279. return _BandGetTextColor(prbb);
  280. }
  281. COLORREF _BandGetBkColorExternal(PRBB prbb)
  282. {
  283. if (prbb->clrBack == CLR_NONE)
  284. return CLR_NONE;
  285. else
  286. return _BandGetBkColor(prbb);
  287. }
  288. BOOL _ValidateRangePtr(PRBB prbb)
  289. {
  290. #ifdef DEBUG
  291. if (prbb < _GetBand(0)) {
  292. ASSERT(0);
  293. return FALSE;
  294. }
  295. if (_GetLastBand() + 1 < prbb) {
  296. // +1 to allow for "p = first; p < last+1; p++" kinds of loops
  297. ASSERT(0);
  298. return FALSE;
  299. }
  300. #endif
  301. return TRUE;
  302. }
  303. BOOL _ValidateRangeInd(UINT i)
  304. {
  305. #ifdef DEBUG
  306. if ( !IsInRange(i, 0, _cBands) ) { // if !(0 <= i <= _cBands)
  307. // +1 to allow for "p = first; p < last+1; p++" kinds of loops
  308. ASSERT(0);
  309. return FALSE;
  310. }
  311. #endif
  312. return TRUE;
  313. }
  314. CCONTROLINFO _ci;
  315. HPALETTE _hpal;
  316. BOOL _fResizeRecursed;
  317. BOOL _fResizePending;
  318. BOOL _fResizeNotify;
  319. BOOL _fRedraw;
  320. BOOL _fRecalcPending;
  321. BOOL _fRecalc;
  322. BOOL _fParentDrag;
  323. BOOL _fRefreshPending;
  324. BOOL _fResizing;
  325. BOOL _fUserPalette;
  326. BOOL _fFontCreated;
  327. BOOL _fFullOnDrag;
  328. BOOL _fHasBorder;
  329. HDRAGPROXY _hDragProxy;
  330. HWND _hwndToolTips;
  331. int _xBmpOrg;
  332. int _yBmpOrg;
  333. int _cyFont;
  334. int _cy;
  335. int _cxImage;
  336. int _cyImage;
  337. int _xStart;
  338. MARGINS _mBand;
  339. HIMAGELIST _himl;
  340. HFONT _hFont;
  341. UINT _cBands;
  342. UINT _uCapture;
  343. UINT _uResizeNext; // this marks the next band to resize vertically if needed and allowed (VARIABLEHEIGHT set)
  344. POINT _ptCapture;
  345. PRBB _rbbList;
  346. COLORREF _clrBk;
  347. COLORREF _clrText;
  348. DWORD _dwStyleEx;
  349. COLORSCHEME _clrsc;
  350. POINT _ptLastDragPos;
  351. PRBB _prbbHot; // band w/ hot chevron
  352. HTHEME _hTheme;
  353. friend BOOL InitReBarClass(HINSTANCE hInstance);
  354. };
  355. void CReBar::_CacheThemeInfo(BOOL fOpenNew)
  356. {
  357. if (_hTheme)
  358. {
  359. CloseThemeData(_hTheme);
  360. }
  361. _hTheme = NULL;
  362. if (fOpenNew)
  363. {
  364. _hTheme = OpenThemeData(_ci.hwnd, L"Rebar");
  365. }
  366. if (_hTheme)
  367. {
  368. // Get the cached metrics. These are things that can be slow to get during a calculation
  369. GetThemeMargins(_hTheme, NULL, RP_BAND, 0, TMT_CONTENTMARGINS, NULL, &_mBand);
  370. SetWindowBits(_ci.hwnd, GWL_STYLE, WS_BORDER, 0);
  371. }
  372. else
  373. {
  374. if (_fHasBorder)
  375. {
  376. SetWindowBits(_ci.hwnd, GWL_STYLE, WS_BORDER, WS_BORDER);
  377. }
  378. ZeroMemory(&_mBand, SIZEOF(_mBand));
  379. }
  380. _AfterSetFont();
  381. }
  382. int CReBar::_GetGripperWidth()
  383. {
  384. BOOL fVert;
  385. RECT rcClient;
  386. RECT rc;
  387. if (!_hTheme)
  388. return GRABWIDTH;
  389. GetClientRect(_ci.hwnd, &rcClient);
  390. fVert = _IsVerticalGripper();
  391. SetRect(&rc, 0, 0, fVert?RECTWIDTH(rcClient):3, fVert?3:RECTHEIGHT(rcClient));
  392. GetThemeBackgroundExtent(_hTheme, NULL, RP_GRIPPER, 0, &rc, &rc);
  393. return fVert?RECTHEIGHT(rc):RECTWIDTH(rc);
  394. }
  395. ///
  396. //
  397. // Map a rect to parent should be based on the visual right edge
  398. // for calculating the client coordinates for a RTL mirrored windows.
  399. // This routine should only be used when calculating client
  400. // coordinates in a RTL mirrored window. [samera]
  401. //
  402. BOOL MapRectInRTLMirroredWindow( LPRECT lprc, HWND hwnd)
  403. {
  404. int iWidth = lprc->right - lprc->left;
  405. int iHeight = lprc->bottom- lprc->top;
  406. RECT rc={0,0,0,0};
  407. if (hwnd) {
  408. GetClientRect(hwnd, &rc);
  409. MapWindowPoints(hwnd, NULL, (LPPOINT)&rc.left, 2);
  410. }
  411. lprc->left = rc.right - lprc->right;
  412. lprc->top = lprc->top-rc.top;
  413. lprc->bottom = lprc->top + iHeight;
  414. lprc->right = lprc->left + iWidth;
  415. return TRUE;
  416. }
  417. void CReBar::_Realize(HDC hdcParam, BOOL fBackground, BOOL fForceRepaint)
  418. {
  419. if (_hpal)
  420. {
  421. HDC hdc = hdcParam ? hdcParam : GetDC(_ci.hwnd);
  422. if (hdc)
  423. {
  424. BOOL fRepaint;
  425. SelectPalette(hdc, _hpal, fBackground);
  426. fRepaint = RealizePalette(hdc) || fForceRepaint;
  427. if (!hdcParam)
  428. ReleaseDC(_ci.hwnd, hdc);
  429. if (fRepaint)
  430. {
  431. InvalidateRect(_ci.hwnd, NULL, TRUE);
  432. }
  433. }
  434. }
  435. }
  436. //////////////////////////////////////////////////////////////////
  437. // _SendNotify
  438. //
  439. // sends a wm_notify of code iCode and packages up all the data for you
  440. // for band uBand
  441. //
  442. //////////////////////////////////////////////////////////////////
  443. LRESULT CReBar::_SendNotify(UINT uBand, int iCode)
  444. {
  445. NMREBAR nm = {0};
  446. nm.uBand = uBand;
  447. if (uBand != (UINT)-1) {
  448. nm.dwMask = RBNM_ID | RBNM_STYLE | RBNM_LPARAM;
  449. nm.wID = _GetBand(uBand)->wID;
  450. nm.fStyle = _GetBand(uBand)->fStyle;
  451. nm.lParam = _GetBand(uBand)->lParam;
  452. }
  453. return CCSendNotify(&_ci, iCode, &nm.hdr);
  454. }
  455. BOOL CReBar::_InvalidateRect(RECT* prc)
  456. {
  457. if (_fRedraw)
  458. {
  459. RECT rc;
  460. if (prc && _IsVertical())
  461. {
  462. CopyRect(&rc, prc);
  463. FlipRect(&rc);
  464. prc = &rc;
  465. }
  466. _fRefreshPending = FALSE;
  467. InvalidateRect(_ci.hwnd, prc, TRUE);
  468. return TRUE;
  469. }
  470. else
  471. {
  472. _fRefreshPending = TRUE;
  473. return FALSE;
  474. }
  475. }
  476. LRESULT CReBar::s_DragCallback(HWND hwnd, UINT code, WPARAM wp, LPARAM lp)
  477. {
  478. CReBar* prb = (CReBar*)GetWindowPtr(hwnd, 0);
  479. LRESULT lres;
  480. switch (code)
  481. {
  482. case DPX_DRAGHIT:
  483. if (lp)
  484. {
  485. int iBand;
  486. RBHITTESTINFO rbht;
  487. rbht.pt.x = ((POINTL *)lp)->x;
  488. rbht.pt.y = ((POINTL *)lp)->y;
  489. MapWindowPoints(NULL, prb->_ci.hwnd, &rbht.pt, 1);
  490. iBand = prb->_HitTest(&rbht);
  491. *(DWORD*)wp = rbht.flags;
  492. lres = (LRESULT)(iBand != -1 ? prb->_rbbList[iBand].wID : -1);
  493. }
  494. else
  495. lres = -1;
  496. break;
  497. case DPX_GETOBJECT:
  498. lres = (LRESULT)GetItemObject(&prb->_ci, RBN_GETOBJECT, &IID_IDropTarget, (LPNMOBJECTNOTIFY)lp);
  499. break;
  500. default:
  501. lres = -1;
  502. break;
  503. }
  504. return lres;
  505. }
  506. // ----------------------------------------------------------------------------
  507. //
  508. // _CanBandMove
  509. //
  510. // returns TRUE if the given band can be moved and FALSE if it cannot
  511. //
  512. // ----------------------------------------------------------------------------
  513. BOOL CReBar::_CanBandMove(PRBB prbb)
  514. {
  515. // If there is only one visible band it cannot move
  516. if (_EnumBand(1, RBBS_HIDDEN) > _GetLastBand())
  517. return FALSE;
  518. ASSERT(!(prbb->fStyle & RBBS_HIDDEN));
  519. if ((_ci.style & RBS_FIXEDORDER)
  520. && (prbb == _EnumBand(0, RBBS_HIDDEN)))
  521. // the first (visible) band in fixed order rebars can't be moved
  522. return(FALSE);
  523. // fixed size bands can't be moved
  524. return(!(prbb->fStyle & RBBS_FIXEDSIZE));
  525. }
  526. // ----------------------------------------------------------------------------
  527. //
  528. // _BandCalcMinWidth
  529. //
  530. // calculates minimum width for the given band
  531. //
  532. // ----------------------------------------------------------------------------
  533. void CReBar::_BandCalcMinWidth(PRBB prbb)
  534. {
  535. BOOL fDrawGripper = _ShouldDrawGripper(prbb);
  536. BOOL fVertical;
  537. int cEdge;
  538. BOOL fEmpty = (prbb->iImage == -1 && !_ShowText(prbb));
  539. if (prbb->fStyle & RBBS_HIDDEN)
  540. {
  541. ASSERT(0);
  542. return;
  543. }
  544. // did the user specify the size explicitly?
  545. if (prbb->fStyle & RBBS_FIXEDHEADERSIZE)
  546. return;
  547. prbb->cxMin = prbb->cxMinChild;
  548. if (_UseChevron(prbb))
  549. prbb->cxMin += CX_CHEVRON;
  550. if (!fDrawGripper && fEmpty)
  551. return;
  552. fVertical = (_ci.style & CCS_VERT);
  553. if (_IsVerticalGripper())
  554. {
  555. prbb->cxMin += 4 * g_cyEdge;
  556. prbb->cxMin += max(_cyImage, _cyFont);
  557. }
  558. else
  559. {
  560. cEdge = fVertical ? g_cyEdge : g_cxEdge;
  561. prbb->cxMin += 2 * cEdge;
  562. if (fDrawGripper)
  563. {
  564. prbb->cxMin += _GetGripperWidth() * (fVertical ? g_cyBorder : g_cxBorder);
  565. if (fEmpty)
  566. return;
  567. }
  568. prbb->cxMin += 2 * cEdge;
  569. if (prbb->iImage != -1)
  570. prbb->cxMin += (fVertical ? _cyImage : _cxImage);
  571. if (_ShowText(prbb))
  572. {
  573. if (fVertical)
  574. prbb->cxMin += _cyFont;
  575. else
  576. prbb->cxMin += prbb->cxText;
  577. if (prbb->iImage != -1)
  578. // has both image and text -- add in edge between 'em
  579. prbb->cxMin += cEdge;
  580. }
  581. }
  582. }
  583. BOOL CReBar::_ShouldDrawGripper(PRBB prbb)
  584. {
  585. if (prbb->fStyle & RBBS_NOGRIPPER)
  586. return FALSE;
  587. if ((prbb->fStyle & RBBS_GRIPPERALWAYS) || _CanBandMove(prbb))
  588. return TRUE;
  589. return FALSE;
  590. }
  591. // ----------------------------------------------------------------------------
  592. //
  593. // _BandCalcTextExtent
  594. //
  595. // computes the horizontal extent of the given band's title text in the current
  596. // title font for the rebar
  597. //
  598. // returns TRUE if text extent changed, FALSE otherwise
  599. //
  600. // ----------------------------------------------------------------------------
  601. BOOL CReBar::_BandCalcTextExtent(PRBB prbb, HDC hdcIn)
  602. {
  603. HDC hdc = hdcIn;
  604. HFONT hFontOld;
  605. int cx;
  606. if (prbb->fStyle & RBBS_HIDDEN)
  607. {
  608. ASSERT(0); // caller should have skipped
  609. return FALSE;
  610. }
  611. if (!_ShowText(prbb))
  612. {
  613. cx = 0;
  614. }
  615. else
  616. {
  617. RECT rc = {0,0,0,0};
  618. HRESULT hr = E_FAIL;
  619. if (!hdcIn && !(hdc = GetDC(_ci.hwnd)))
  620. return FALSE;
  621. hFontOld = SelectFont(hdc, _hFont);
  622. if (_hTheme)
  623. hr = GetThemeTextExtent(_hTheme, hdc, 0, 0, prbb->lpText, -1, DT_CALCRECT, &rc, &rc);
  624. if (FAILED(hr))
  625. {
  626. DrawText(hdc, prbb->lpText, lstrlen(prbb->lpText), &rc, DT_CALCRECT);
  627. }
  628. SelectObject(hdc, hFontOld);
  629. cx = RECTWIDTH(rc);
  630. if (!hdcIn)
  631. ReleaseDC(_ci.hwnd, hdc);
  632. }
  633. if (prbb->cxText != cx)
  634. {
  635. prbb->cxText = cx;
  636. _BandCalcMinWidth(prbb);
  637. return TRUE;
  638. }
  639. return FALSE;
  640. }
  641. // ----------------------------------------------------------------------------
  642. //
  643. // _BandGetHeight
  644. //
  645. // returns minimum height for the given band
  646. // TODO: make this a field in the band structure instead of always calling this
  647. //
  648. // ----------------------------------------------------------------------------
  649. int CReBar::_BandGetHeight(PRBB prbb)
  650. {
  651. UINT cy = 0;
  652. BOOL fVertical = (_ci.style & CCS_VERT);
  653. UINT cyCheck, cyBorder;
  654. cyBorder = (fVertical ? g_cxEdge : g_cyEdge) * 2;
  655. if (prbb->hwndChild)
  656. {
  657. cy = prbb->cyChild;
  658. if (!(prbb->fStyle & RBBS_CHILDEDGE))
  659. // add edge to top and bottom of child window
  660. cy -= cyBorder;
  661. }
  662. if (_ShowText(prbb) && !fVertical)
  663. {
  664. cyCheck = _cyFont;
  665. if (cyCheck > cy)
  666. cy = cyCheck;
  667. }
  668. if (prbb->iImage != -1)
  669. {
  670. cyCheck = (fVertical) ? _cxImage : _cyImage;
  671. if (cyCheck > cy)
  672. cy = cyCheck;
  673. }
  674. return(cy + cyBorder);
  675. }
  676. // ----------------------------------------------------------------------------
  677. //
  678. // _GetRowCount
  679. //
  680. // returns the number of rows in the rebar's current configuration
  681. //
  682. // ----------------------------------------------------------------------------
  683. UINT CReBar::_GetRowCount()
  684. {
  685. UINT i;
  686. UINT cRows = 0;
  687. for (i = 0; i < _cBands; i++)
  688. {
  689. PRBB prbb = _GetBand(i);
  690. if (!(prbb->fStyle & RBBS_HIDDEN) &&
  691. _IsBandStartOfRow(prbb))
  692. {
  693. cRows++;
  694. }
  695. }
  696. return cRows;
  697. }
  698. // ----------------------------------------------------------------------------
  699. //
  700. // _GetLineHeight
  701. //
  702. // returns the height of the line of bands from iStart to iEnd, inclusively
  703. //
  704. // ----------------------------------------------------------------------------
  705. int CReBar::_GetLineHeight(UINT iStart, UINT iEnd)
  706. {
  707. int cy = 0;
  708. PRBB prbb;
  709. int cyMinChild = 0;
  710. int iMinExtra = -1;
  711. if (!(_ci.style & RBS_VARHEIGHT))
  712. {
  713. // for fixed height bars, line height is maximum height of ALL bands
  714. iStart = 0;
  715. iEnd = _cBands - 1;
  716. }
  717. UINT i = iStart;
  718. for (prbb = _rbbList + i; i <= iEnd; prbb++, i++)
  719. {
  720. if (prbb->fStyle & RBBS_HIDDEN)
  721. continue;
  722. cy = max(cy, (int)_BandGetHeight(prbb));
  723. if (prbb->cyMinChild > cyMinChild)
  724. {
  725. cyMinChild = prbb->cyMinChild;
  726. }
  727. }
  728. i = iStart;
  729. for (prbb = _rbbList + i; i <= iEnd; prbb++, i++)
  730. {
  731. if (prbb->fStyle & RBBS_HIDDEN)
  732. continue;
  733. if ((prbb->fStyle & RBBS_VARIABLEHEIGHT) && prbb->cyIntegral)
  734. {
  735. int iExtra = (cy - prbb->cyMinChild) % prbb->cyIntegral;
  736. if ((iMinExtra == -1) || (iExtra < iMinExtra))
  737. {
  738. iMinExtra = iExtra;
  739. }
  740. }
  741. }
  742. if (iMinExtra != -1)
  743. {
  744. cy -= iMinExtra;
  745. }
  746. if (cy < cyMinChild)
  747. {
  748. cy = cyMinChild;
  749. }
  750. return cy;
  751. }
  752. // _BandRecalcChevron: update & refresh chevron
  753. void CReBar::_BandRecalcChevron(PRBB prbb, BOOL fChevron)
  754. {
  755. RECT rcChevron;
  756. if (fChevron)
  757. {
  758. rcChevron.right = prbb->x + prbb->cx;
  759. rcChevron.left = rcChevron.right - CX_CHEVRON;
  760. rcChevron.top = prbb->y;
  761. rcChevron.bottom = rcChevron.top + prbb->cy;
  762. }
  763. else
  764. SetRect(&rcChevron, -1, -1, -1, -1);
  765. if (!EqualRect(&rcChevron, &prbb->rcChevron))
  766. {
  767. if (prbb->fChevron)
  768. _InvalidateRect(&prbb->rcChevron);
  769. prbb->fChevron = fChevron;
  770. CopyRect(&prbb->rcChevron, &rcChevron);
  771. if (prbb->fChevron)
  772. _InvalidateRect(&prbb->rcChevron);
  773. }
  774. }
  775. void CReBar::_InvalidateBorders(PRBB prbb)
  776. {
  777. if (_mBand.cxLeftWidth ||
  778. _mBand.cyTopHeight ||
  779. _mBand.cxRightWidth ||
  780. _mBand.cyBottomHeight)
  781. {
  782. RECT rcOuter = {prbb->x - _mBand.cxLeftWidth,
  783. prbb->y - _mBand.cyTopHeight,
  784. prbb->x + prbb->cx + _mBand.cxRightWidth,
  785. prbb->y + prbb->cy + _mBand.cyBottomHeight};
  786. RECT rcInner = {prbb->x + _mBand.cxLeftWidth,
  787. prbb->y + _mBand.cyTopHeight,
  788. prbb->x + prbb->cx - _mBand.cxRightWidth,
  789. prbb->y + prbb->cy - _mBand.cyBottomHeight};
  790. if (_ci.style & CCS_VERT)
  791. {
  792. FlipRect(&rcOuter);
  793. FlipRect(&rcInner);
  794. }
  795. HRGN hrgnOuter = CreateRectRgnIndirect(&rcOuter);
  796. if (hrgnOuter)
  797. {
  798. HRGN hrgnInner = CreateRectRgnIndirect(&rcInner);
  799. if (hrgnInner)
  800. {
  801. CombineRgn(hrgnOuter, hrgnOuter, hrgnInner, RGN_DIFF);
  802. DeleteObject(hrgnInner);
  803. }
  804. InvalidateRgn(_ci.hwnd, hrgnOuter, FALSE);
  805. DeleteObject(hrgnOuter);
  806. }
  807. }
  808. }
  809. // ----------------------------------------------------------------------------
  810. //
  811. // _ResizeChildren
  812. //
  813. // resizes children to fit properly in their respective bands' bounding rects
  814. //
  815. // ----------------------------------------------------------------------------
  816. void CReBar::_ResizeChildren()
  817. {
  818. int cx, cy, x, y, cxHeading;
  819. HDWP hdwp;
  820. BOOL fVertical = (_ci.style & CCS_VERT);
  821. PRBB prbb, prbbEnd;
  822. if (!_cBands || !_fRedraw)
  823. return;
  824. hdwp = BeginDeferWindowPos(_cBands);
  825. prbb = _GetBand(0);
  826. prbbEnd = _GetLastBand();
  827. for ( ; prbb <= prbbEnd ; prbb++)
  828. {
  829. NMREBARCHILDSIZE nm;
  830. BOOL fChevron = FALSE;
  831. if (prbb->fStyle & RBBS_HIDDEN)
  832. continue;
  833. if (!prbb->hwndChild)
  834. continue;
  835. cxHeading = _GetHeaderWidth(prbb);
  836. x = prbb->x + cxHeading;
  837. cx = prbb->cx - cxHeading;
  838. // if we're not giving child ideal size, make space for chevron button
  839. if ((cx < prbb->cxIdeal) && _UseChevron(prbb))
  840. {
  841. fChevron = TRUE;
  842. cx -= CX_CHEVRON;
  843. }
  844. if (!(prbb->fStyle & RBBS_FIXEDSIZE))
  845. {
  846. if (fVertical)
  847. {
  848. PRBB prbbNext = _GetNextVisible(prbb);
  849. if (prbbNext && !_IsBandStartOfRow(prbbNext))
  850. cx -= g_cyEdge * 2;
  851. }
  852. else
  853. cx -= CX_OFFSET;
  854. }
  855. if (cx < 0)
  856. cx = 0;
  857. y = prbb->y;
  858. cy = prbb->cy;
  859. if (prbb->cyChild && (prbb->cyChild < cy))
  860. {
  861. if (!(prbb->fStyle & RBBS_TOPALIGN))
  862. {
  863. y += (cy - prbb->cyChild) / 2;
  864. }
  865. cy = prbb->cyChild;
  866. }
  867. nm.rcChild.left = x;
  868. nm.rcChild.top = y;
  869. nm.rcChild.right = x + cx;
  870. nm.rcChild.bottom = y + cy;
  871. nm.rcBand.left = prbb->x + _GetHeaderWidth(prbb);
  872. nm.rcBand.right = prbb->x + prbb->cx;
  873. nm.rcBand.top = prbb->y;
  874. nm.rcBand.bottom = prbb->y + prbb->cy;
  875. nm.uBand = _BandToIndex(prbb);
  876. nm.wID = prbb->wID;
  877. if (fVertical)
  878. {
  879. FlipRect(&nm.rcChild);
  880. FlipRect(&nm.rcBand);
  881. }
  882. CCSendNotify(&_ci, RBN_CHILDSIZE, &nm.hdr);
  883. if (!_IsValidBand(prbb))
  884. {
  885. // somebody responded to notify by nuking bands; bail
  886. break;
  887. }
  888. _BandRecalcChevron(prbb, fChevron);
  889. _InvalidateBorders(prbb);
  890. DeferWindowPos(hdwp, prbb->hwndChild, NULL, nm.rcChild.left, nm.rcChild.top,
  891. RECTWIDTH(nm.rcChild), RECTHEIGHT(nm.rcChild), SWP_NOZORDER);
  892. }
  893. EndDeferWindowPos(hdwp);
  894. }
  895. // ----------------------------------------------------------------------------
  896. //
  897. // _MoveBand
  898. //
  899. // moves the band from one position to another in the rebar's band array,
  900. // updating the rebar's iCapture field as needed
  901. //
  902. // returns TRUE or FALSE if something moved
  903. // ----------------------------------------------------------------------------
  904. BOOL CReBar::_MoveBand(UINT iFrom, UINT iTo)
  905. {
  906. RBB rbbMove;
  907. int iShift;
  908. BOOL fCaptureChanged = (_uCapture == -1);
  909. if (iFrom != iTo)
  910. {
  911. rbbMove = *_GetBand(iFrom);
  912. if (_uCapture == iFrom)
  913. {
  914. _uCapture = iTo;
  915. fCaptureChanged = TRUE;
  916. }
  917. iShift = (iFrom > iTo) ? -1 : 1;
  918. while (iFrom != iTo)
  919. {
  920. if (!fCaptureChanged && (_uCapture == (iFrom + iShift)))
  921. {
  922. _uCapture = iFrom;
  923. fCaptureChanged = TRUE;
  924. }
  925. *_GetBand(iFrom) = *_GetBand(iFrom + iShift);
  926. iFrom += iShift;
  927. }
  928. *_GetBand(iTo) = rbbMove;
  929. return TRUE;
  930. }
  931. return(FALSE);
  932. }
  933. // ----------------------------------------------------------------------------
  934. //
  935. // _Recalc
  936. //
  937. // recomputes bounding rects for all bands in given rebar
  938. //
  939. // ----------------------------------------------------------------------------
  940. int CReBar::_Recalc(LPRECT prc, BOOL fForce /* = FALSE */)
  941. {
  942. PRBB prbb = _GetBand(0);
  943. PRBB prbbWalk;
  944. UINT cHidden; // # of hidden guys we've seen in current row
  945. int cxRow;
  946. int cxMin;
  947. UINT i;
  948. UINT j;
  949. UINT k;
  950. UINT iFixed = 0xFFFF;
  951. int cy;
  952. int y;
  953. int x;
  954. int cxBar;
  955. RECT rc;
  956. HWND hwndSize;
  957. BOOL fNewLine = FALSE;
  958. BOOL fChanged;
  959. BOOL fVertical = (_ci.style & CCS_VERT);
  960. BOOL fBandBorders;
  961. int iBarWidth;
  962. if (!_cBands)
  963. return(0);
  964. if ((_ci.style & CCS_NORESIZE) || (_ci.style & CCS_NOPARENTALIGN))
  965. {
  966. // size based on rebar window itself
  967. hwndSize = _ci.hwnd;
  968. }
  969. else if (!(hwndSize = _ci.hwndParent))
  970. {
  971. // size based on parent window -- if no parent window, bail now
  972. return(0);
  973. }
  974. if (!_fRecalc && !fForce)
  975. {
  976. // defer this recalc
  977. _fRecalcPending = TRUE;
  978. return 0;
  979. }
  980. else
  981. {
  982. _fRecalcPending = FALSE;
  983. }
  984. if (prc)
  985. {
  986. rc = *prc;
  987. }
  988. else
  989. {
  990. GetClientRect(hwndSize, &rc);
  991. }
  992. iBarWidth = (fVertical ? (rc.bottom - rc.top) : (rc.right - rc.left));
  993. // this can happen because we adjust the client rect, but wedon't change
  994. // the getminmaxinfo.
  995. if (iBarWidth <= 0)
  996. iBarWidth = 1;
  997. cxBar = iBarWidth;
  998. fBandBorders = _UseBandBorders();
  999. for (i = 0; i < _cBands; i++)
  1000. {
  1001. _rbbList[i].cx = _rbbList[i].cxRequest;
  1002. }
  1003. y = 0;
  1004. i = 0;
  1005. // Main Loop -- loop until all bands are calculated
  1006. while (i < _cBands)
  1007. {
  1008. TraceMsg(TF_REBAR, "_Recalc: outer loop i=%d", i);
  1009. if (fBandBorders && (y > 0))
  1010. y += g_cyEdge;
  1011. y += _mBand.cyTopHeight;
  1012. ReLoop:
  1013. cxRow = 0;
  1014. cxMin = _mBand.cxLeftWidth + _mBand.cxRightWidth;
  1015. x = _mBand.cxLeftWidth;
  1016. cHidden = 0;
  1017. // Row Loop -- loop until hard line break is found or soft line break
  1018. // is necessary
  1019. for (j = i, prbbWalk = prbb; j < _cBands; j++, prbbWalk++)
  1020. {
  1021. TraceMsg(TF_REBAR, "_Recalc: inner loop j=%d", j);
  1022. if (prbbWalk->fStyle & RBBS_HIDDEN)
  1023. {
  1024. ++cHidden;
  1025. continue;
  1026. }
  1027. if (j > i + cHidden)
  1028. {
  1029. // not the first band in the row -- check for break style
  1030. if ((prbbWalk->fStyle & RBBS_BREAK) && !(prbbWalk->fStyle & RBBS_FIXEDSIZE))
  1031. break;
  1032. if (fBandBorders)
  1033. // add in space for vertical etch on palettized display
  1034. cxMin += g_cxEdge;
  1035. }
  1036. if (prbbWalk->fStyle & RBBS_FIXEDSIZE)
  1037. {
  1038. // remember location of branding brick
  1039. iFixed = j;
  1040. // if this is the first band, the next band cannot have a forced break.
  1041. if (i + cHidden == j)
  1042. {
  1043. // if the first index in the row (i) plus the number of hidden items (cHidden) leaves us at this band,
  1044. // then it's the first visible in this row.
  1045. PRBB prbbNextVis = _GetNextVisible(prbbWalk);
  1046. if (prbbNextVis && (prbbNextVis->fStyle & RBBS_BREAK))
  1047. {
  1048. // can't do this unilaterally because on startup
  1049. // some folks (net meeting) initialize it in reverse order
  1050. // and we whack off this break bit incorrectly
  1051. if (_fRedraw && IsWindowVisible(_ci.hwnd))
  1052. prbbNextVis->fStyle &= ~RBBS_BREAK;
  1053. }
  1054. }
  1055. prbbWalk->cx = prbbWalk->cxMin;
  1056. }
  1057. if (prbbWalk->cx < prbbWalk->cxMin)
  1058. prbbWalk->cx = prbbWalk->cxMin;
  1059. cxMin += prbbWalk->cxMin; // update running total of min widths
  1060. // read the assert comment below
  1061. if (j > i + cHidden)
  1062. {
  1063. // not the first band in row -- check for need to autobreak
  1064. if ((cxMin > cxBar) && (_OkayToChangeBreak(prbbWalk, RBAB_AUTOSIZE)))
  1065. // autobreak here
  1066. break;
  1067. if (fBandBorders)
  1068. {
  1069. // add in space for vertical etch on palettized display
  1070. cxRow += g_cxEdge;
  1071. }
  1072. }
  1073. cxRow += prbbWalk->cx; // update running total of current widths
  1074. cxRow += _mBand.cxLeftWidth + _mBand.cxRightWidth;
  1075. }
  1076. if (!i)
  1077. {
  1078. // first row -- handle proper placement of branding band
  1079. if (iFixed == 0xFFFF)
  1080. {
  1081. // branding band not yet found; look in the remaining bands
  1082. k = j;
  1083. for ( ; j < _cBands; j++)
  1084. {
  1085. if (_GetBand(j)->fStyle & RBBS_HIDDEN)
  1086. continue;
  1087. if (_GetBand(j)->fStyle & RBBS_FIXEDSIZE)
  1088. {
  1089. // branding band found; move to 1st row and recompute
  1090. ASSERT(j != k);
  1091. _MoveBand(j, k);
  1092. goto ReLoop;
  1093. }
  1094. }
  1095. // no branding band found -- reset j and continue on
  1096. j = k;
  1097. }
  1098. else
  1099. {
  1100. // we have a branding band; move it to
  1101. // the rightmost position in the row
  1102. _MoveBand(iFixed, j - 1);
  1103. }
  1104. TraceMsg(TF_REBAR, "_Recalc: after brand i=%d", i);
  1105. }
  1106. // variant:
  1107. // now the current row of bands is from i to j - 1
  1108. // n.b. i (and some following bands) might be hidden
  1109. // assert that j != i because then the above variant won't be true
  1110. ASSERT(j != i);
  1111. if (cxRow > cxBar)
  1112. {
  1113. // bands are too long -- shrink bands from right to left
  1114. for (k = i; k < j; k++)
  1115. {
  1116. prbbWalk--;
  1117. if (prbbWalk->fStyle & RBBS_HIDDEN)
  1118. continue;
  1119. if (prbbWalk->cx > prbbWalk->cxMin)
  1120. {
  1121. cxRow -= prbbWalk->cx - prbbWalk->cxMin;
  1122. prbbWalk->cx = prbbWalk->cxMin;
  1123. if (cxRow <= cxBar)
  1124. {
  1125. prbbWalk->cx += cxBar - cxRow;
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. TraceMsg(TF_REBAR, "_Recalc: after shrink i=%d", i);
  1131. }
  1132. else if (cxRow < cxBar)
  1133. {
  1134. // bands are too short -- grow rightmost non-minimized band
  1135. for (k = j - 1; k >= i; k--)
  1136. {
  1137. ASSERT(k != (UINT)-1); // catch infinite loop
  1138. prbbWalk--;
  1139. if ((k == i) ||
  1140. (!(prbbWalk->fStyle & (RBBS_HIDDEN | RBBS_FIXEDSIZE)) &&
  1141. (prbbWalk->cx > prbb->cxMin)))
  1142. {
  1143. // the k == i check means we've made it to the first
  1144. // band on this row and so he has to get the cx change
  1145. if (prbbWalk->fStyle & RBBS_HIDDEN)
  1146. {
  1147. ASSERT(k == i);
  1148. prbbWalk = _GetNextVisible(prbbWalk);
  1149. if (!prbbWalk)
  1150. break;
  1151. }
  1152. prbbWalk->cx += cxBar - cxRow;
  1153. break;
  1154. }
  1155. }
  1156. TraceMsg(TF_REBAR, "_Recalc: after grow i=%d", i);
  1157. }
  1158. // items from index i to index j-1 (inclusive) WILL fit on one line
  1159. cy = _GetLineHeight(i, j - 1);
  1160. fChanged = FALSE; // set if any bands on current row changed position
  1161. for ( ; i < j; i++, prbb++)
  1162. {
  1163. if (prbb->fStyle & RBBS_HIDDEN)
  1164. continue;
  1165. // go through row of bands, updating positions and heights,
  1166. // invalidating as needed
  1167. if ((prbb->y != y) || (prbb->x != x) || (prbb->cy != cy))
  1168. {
  1169. TraceMsg(TF_REBAR, "_Recalc: invalidate i=%d", _BandToIndex(prbb));
  1170. fChanged = TRUE;
  1171. rc.left = min(prbb->x, x);
  1172. rc.top = min(prbb->y, y);
  1173. rc.right = cxBar;
  1174. rc.bottom = max(prbb->y + prbb->cy, y + cy);
  1175. if (fBandBorders)
  1176. {
  1177. // acount for etch line that will need to move
  1178. rc.left -= g_cxEdge;
  1179. rc.bottom += g_cyEdge/2;
  1180. }
  1181. else
  1182. {
  1183. rc.left -= _mBand.cxLeftWidth;
  1184. rc.right += _mBand.cxRightWidth;
  1185. rc.top -= _mBand.cyTopHeight;
  1186. rc.bottom += _mBand.cyBottomHeight;
  1187. }
  1188. if (!prc)
  1189. {
  1190. _InvalidateRect(&rc);
  1191. }
  1192. }
  1193. prbb->x = x;
  1194. prbb->y = y;
  1195. prbb->cy = cy;
  1196. x += _BandWidth(prbb);
  1197. }
  1198. // i and prbb now refer to the first band in the next row of bands
  1199. y += cy + _mBand.cyBottomHeight;
  1200. }
  1201. _cy = y;
  1202. return(y);
  1203. }
  1204. // ----------------------------------------------------------------------------
  1205. //
  1206. // _ResizeNow
  1207. //
  1208. // recomputes bounding rects for all bands and then resizes rebar and children
  1209. // based on these rects
  1210. //
  1211. // ----------------------------------------------------------------------------
  1212. void CReBar::_ResizeNow()
  1213. {
  1214. RECT rc;
  1215. BOOL bMirroredWnd=(_ci.dwExStyle&RTL_MIRRORED_WINDOW);
  1216. if (!_ci.hwndParent)
  1217. return;
  1218. GetWindowRect(_ci.hwnd, &rc);
  1219. //
  1220. // If this is a mirrored window, we don't won't to refect the
  1221. // coordinates since they are coming from the screen coord
  1222. // which they are not mirrored. [samera]
  1223. //
  1224. if (bMirroredWnd)
  1225. MapRectInRTLMirroredWindow(&rc, _ci.hwndParent);
  1226. else
  1227. MapWindowPoints(HWND_DESKTOP, _ci.hwndParent, (LPPOINT)&rc, 2);
  1228. _ResizeChildren();
  1229. NewSize(_ci.hwnd, _cy, _ci.style, rc.left, rc.top, RECTWIDTH(rc), RECTHEIGHT(rc));
  1230. if (_fResizeNotify)
  1231. CCSendNotify(&_ci, RBN_HEIGHTCHANGE, NULL);
  1232. _fResizeNotify = FALSE;
  1233. _fResizePending = FALSE;
  1234. }
  1235. void CReBar::_Resize(BOOL fForceHeightChange)
  1236. {
  1237. int cy;
  1238. StartOver:
  1239. // lots of the code relies on having cy calculated synchronously with _Resize,
  1240. // but we're going to delay the actual changing of the window
  1241. cy = _cy;
  1242. _Recalc(NULL);
  1243. if (_fResizing)
  1244. {
  1245. _fResizeRecursed = TRUE;
  1246. return;
  1247. }
  1248. _fResizing = TRUE;
  1249. // true overrides always
  1250. if (fForceHeightChange || (cy != _cy))
  1251. _fResizeNotify = TRUE;
  1252. if (_fRedraw)
  1253. {
  1254. _ResizeNow();
  1255. }
  1256. else
  1257. {
  1258. _fResizePending = TRUE;
  1259. }
  1260. _fResizing = FALSE;
  1261. // we do this to avoid infinite loop... _Resize can cause NewSize which causes
  1262. // a notify in which the parent sizes us, which causes us to loop.
  1263. // if the parent does any message pumping during the NewSize, we're in a loop
  1264. if (_fResizeRecursed)
  1265. {
  1266. _fResizeRecursed = FALSE;
  1267. fForceHeightChange = FALSE;
  1268. goto StartOver;
  1269. }
  1270. }
  1271. void CReBar::_SetRecalc(BOOL fRecalc)
  1272. {
  1273. _fRecalc = fRecalc;
  1274. if (fRecalc) {
  1275. if (_fRecalcPending)
  1276. _Recalc(NULL);
  1277. }
  1278. }
  1279. BOOL CReBar::_SetRedraw(BOOL fRedraw)
  1280. {
  1281. BOOL fOld = _fRedraw;
  1282. _fRedraw = fRedraw;
  1283. if (fRedraw)
  1284. {
  1285. // save off _fRefreshPending since this can
  1286. // get changed by call to _ResizeNow
  1287. BOOL fRefreshPending = _fRefreshPending;
  1288. if (_fResizePending)
  1289. _ResizeNow();
  1290. if (fRefreshPending)
  1291. _InvalidateRect(NULL);
  1292. }
  1293. return fOld;
  1294. }
  1295. BOOL CReBar::_AfterSetFont()
  1296. {
  1297. BOOL fChange = FALSE;
  1298. UINT i;
  1299. HFONT hOldFont;
  1300. HDC hdc = GetDC(_ci.hwnd);
  1301. if (!hdc)
  1302. return FALSE;
  1303. hOldFont = SelectFont(hdc, _hFont);
  1304. TEXTMETRIC tm;
  1305. if (_hTheme)
  1306. {
  1307. GetThemeTextMetrics(_hTheme, hdc, 0, 0, &tm);
  1308. }
  1309. else
  1310. {
  1311. GetTextMetrics(hdc, &tm);
  1312. }
  1313. if (_cyFont != tm.tmHeight)
  1314. {
  1315. _cyFont = tm.tmHeight;
  1316. fChange = TRUE;
  1317. }
  1318. // adjust bands
  1319. for (i = 0; i < _cBands; i++)
  1320. {
  1321. if (_GetBand(i)->fStyle & RBBS_HIDDEN)
  1322. continue;
  1323. fChange |= _BandCalcTextExtent(_GetBand(i), hdc);
  1324. }
  1325. SelectObject(hdc, hOldFont);
  1326. ReleaseDC(_ci.hwnd, hdc);
  1327. if (fChange)
  1328. {
  1329. _Resize(FALSE);
  1330. // invalidate, o.w. title doesn't redraw 1st time after font growth
  1331. _InvalidateRect(NULL);
  1332. }
  1333. return TRUE;
  1334. }
  1335. BOOL CReBar::_OnSetFont(HFONT hFont)
  1336. {
  1337. if (_fFontCreated) {
  1338. DeleteObject(_hFont);
  1339. }
  1340. _hFont = hFont;
  1341. _fFontCreated = FALSE;
  1342. if (!_hFont)
  1343. _SetFont(0);
  1344. else
  1345. return _AfterSetFont();
  1346. return TRUE;
  1347. }
  1348. // ----------------------------------------------------------------------------
  1349. //
  1350. // _SetFont
  1351. //
  1352. // sets the rebar band title font to the current system-wide caption font
  1353. //
  1354. // ----------------------------------------------------------------------------
  1355. BOOL CReBar::_SetFont(WPARAM wParam)
  1356. {
  1357. NONCLIENTMETRICS ncm;
  1358. HFONT hOldFont;
  1359. if ((wParam != 0) && (wParam != SPI_SETNONCLIENTMETRICS))
  1360. return(FALSE);
  1361. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  1362. if (!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0))
  1363. return(FALSE);
  1364. hOldFont = _hFont;
  1365. ncm.lfCaptionFont.lfWeight = FW_NORMAL;
  1366. if (!(_hFont = CreateFontIndirect(&ncm.lfCaptionFont)))
  1367. {
  1368. _hFont = hOldFont;
  1369. return(FALSE);
  1370. }
  1371. _fFontCreated = TRUE;
  1372. if (hOldFont)
  1373. DeleteObject(hOldFont);
  1374. return _AfterSetFont();
  1375. }
  1376. // ----------------------------------------------------------------------------
  1377. //
  1378. // Draws a horizontal or vertical dotted line from the given (x,y) location
  1379. // for the given length (c). (From TReeView's TV_DrawDottedLine)
  1380. //
  1381. // ----------------------------------------------------------------------------
  1382. void CReBar::_VertMungeGripperRect(LPRECT lprc)
  1383. {
  1384. if (_IsVerticalGripper()) {
  1385. OffsetRect(lprc, -lprc->left + lprc->top, -lprc->top + lprc->left);
  1386. lprc->bottom -= g_cyEdge;
  1387. } else {
  1388. FlipRect(lprc);
  1389. }
  1390. }
  1391. void CReBar::_DrawChevron(PRBB prbb, HDC hdc)
  1392. {
  1393. RECT rc;
  1394. DWORD dwFlags = prbb->wChevState | DCHF_HORIZONTAL | DCHF_TRANSPARENT;
  1395. CopyRect(&rc, &prbb->rcChevron);
  1396. int iPart;
  1397. if (_IsVertical())
  1398. {
  1399. FlipRect(&rc);
  1400. iPart = RP_CHEVRONVERT;
  1401. }
  1402. else
  1403. {
  1404. dwFlags |= DCHF_TOPALIGN;
  1405. iPart = RP_CHEVRON;
  1406. }
  1407. DrawChevron(_hTheme, iPart, hdc, &rc, dwFlags);
  1408. }
  1409. void CReBar::_UpdateChevronState(PRBB prbb, WORD wControlState)
  1410. {
  1411. if (prbb)
  1412. {
  1413. // if no change in state, bail
  1414. if (!(wControlState ^ prbb->wChevState))
  1415. return;
  1416. prbb->wChevState = wControlState;
  1417. // if active (pushed or hottracked)
  1418. if (!(wControlState & DCHF_INACTIVE)) {
  1419. // then we're now the hot band
  1420. _prbbHot = prbb;
  1421. }
  1422. // else if we were the hot band then clear
  1423. else if (prbb == _prbbHot) {
  1424. _prbbHot = NULL;
  1425. }
  1426. // clear background & repaint
  1427. _InvalidateRect(&prbb->rcChevron);
  1428. UpdateWindow(_ci.hwnd);
  1429. }
  1430. }
  1431. // ----------------------------------------------------------------------------
  1432. //
  1433. // _DrawBand
  1434. //
  1435. // draws the title icon and title text of the given band into the given DC;
  1436. // also the band's chevron
  1437. //
  1438. // ----------------------------------------------------------------------------
  1439. void CReBar::_DrawBand(PRBB prbb, HDC hdc)
  1440. {
  1441. COLORREF clrBackSave, clrForeSave;
  1442. int iModeSave;
  1443. BOOL fVertical = _IsVertical();
  1444. BOOL fDrawHorizontal = (!fVertical || _IsVerticalGripper());
  1445. NMCUSTOMDRAW nmcd;
  1446. LRESULT dwRet;
  1447. if (prbb->fStyle & RBBS_HIDDEN)
  1448. {
  1449. ASSERT(0);
  1450. return;
  1451. }
  1452. clrForeSave = SetTextColor(hdc, _BandGetTextColor(prbb));
  1453. clrBackSave = SetBkColor(hdc, _BandGetBkColor(prbb));
  1454. if (prbb->hbmBack || _hTheme)
  1455. iModeSave = SetBkMode(hdc, TRANSPARENT);
  1456. nmcd.hdc = hdc;
  1457. nmcd.dwItemSpec = prbb->wID;
  1458. nmcd.uItemState = 0;
  1459. nmcd.lItemlParam = prbb->lParam;
  1460. nmcd.rc.top = prbb->y;
  1461. nmcd.rc.left = prbb->x;
  1462. nmcd.rc.bottom = nmcd.rc.top + prbb->cy;
  1463. nmcd.rc.right = nmcd.rc.left + _GetHeaderWidth(prbb);
  1464. if (_ci.style & CCS_VERT)
  1465. {
  1466. FlipRect(&nmcd.rc);
  1467. }
  1468. RECT rcTemp = {0, 0, 0, 0};
  1469. HRGN hrgnOld = CreateRectRgnIndirect(&rcTemp);
  1470. if (GetClipRgn(hdc, hrgnOld) == 0)
  1471. {
  1472. DeleteObject(hrgnOld);
  1473. hrgnOld = NULL;
  1474. }
  1475. if (_ci.style & CCS_VERT)
  1476. {
  1477. IntersectClipRect(hdc, prbb->y, prbb->x, prbb->y + prbb->cy, prbb->x + prbb->cx);
  1478. }
  1479. else
  1480. {
  1481. IntersectClipRect(hdc, prbb->x, prbb->y, prbb->x + prbb->cx, prbb->y + prbb->cy);
  1482. }
  1483. if (_hTheme)
  1484. {
  1485. RECT rcBand = {prbb->x - _mBand.cxLeftWidth,
  1486. prbb->y - _mBand.cyTopHeight,
  1487. prbb->x + prbb->cx + _mBand.cxRightWidth,
  1488. prbb->y + prbb->cy + _mBand.cyBottomHeight};
  1489. if (_ci.style & CCS_VERT)
  1490. {
  1491. FlipRect(&rcBand);
  1492. }
  1493. DrawThemeBackground(_hTheme, hdc, RP_BAND, 0, &rcBand, 0);
  1494. }
  1495. dwRet = CICustomDrawNotify(&_ci, CDDS_ITEMPREPAINT, &nmcd);
  1496. if (!(dwRet & CDRF_SKIPDEFAULT))
  1497. {
  1498. int cy = prbb->cy;
  1499. int yCenter = prbb->y + (cy / 2);
  1500. if (_IsVerticalGripper())
  1501. {
  1502. cy = _GetHeaderWidth(prbb);
  1503. yCenter = prbb->x + (cy / 2);
  1504. }
  1505. int xStart = prbb->x;
  1506. if (_ShouldDrawGripper(prbb))
  1507. {
  1508. RECT rc;
  1509. if (_hTheme)
  1510. {
  1511. int cxGripper = _GetGripperWidth();
  1512. int iPart = RP_GRIPPER;
  1513. SetRect(&rc, xStart, prbb->y, xStart + cxGripper, prbb->y + cy);
  1514. if (fVertical)
  1515. {
  1516. iPart = RP_GRIPPERVERT;
  1517. _VertMungeGripperRect(&rc);
  1518. }
  1519. DrawThemeBackground(_hTheme, hdc, iPart, 0, &rc, 0);
  1520. xStart += cxGripper;
  1521. }
  1522. else
  1523. {
  1524. int c;
  1525. int dy;
  1526. c = 3 * g_cyBorder;
  1527. xStart += 2 * g_cxBorder;
  1528. dy = g_cxEdge;
  1529. SetRect(&rc, xStart, prbb->y + dy, xStart + c, prbb->y + cy - dy);
  1530. if (fVertical)
  1531. {
  1532. _VertMungeGripperRect(&rc);
  1533. if (_IsVerticalGripper())
  1534. xStart = rc.left;
  1535. }
  1536. CCDrawEdge(hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE, &(_clrsc));
  1537. xStart += c;
  1538. }
  1539. }
  1540. xStart += 2 * (fVertical ? g_cyEdge : g_cxEdge);
  1541. if (prbb->iImage != -1)
  1542. {
  1543. int yStart;
  1544. IMAGELISTDRAWPARAMS imldp = {0};
  1545. yStart = yCenter - ((!fDrawHorizontal ? _cxImage : _cyImage) / 2);
  1546. imldp.cbSize = sizeof(imldp);
  1547. imldp.himl = _himl;
  1548. imldp.i = prbb->iImage;
  1549. imldp.hdcDst = hdc;
  1550. imldp.x = (!fDrawHorizontal ? yStart : xStart);
  1551. imldp.y = (!fDrawHorizontal ? xStart : yStart);
  1552. imldp.rgbBk = CLR_DEFAULT;
  1553. imldp.rgbFg = CLR_DEFAULT;
  1554. imldp.fStyle = ILD_TRANSPARENT;
  1555. imldp.fState = 0;
  1556. ImageList_DrawIndirect(&imldp);
  1557. xStart += (fDrawHorizontal ? (_cxImage + g_cxEdge) : (_cyImage + g_cyEdge));
  1558. }
  1559. if (_ShowText(prbb))
  1560. {
  1561. UINT uFormat=0;
  1562. RECT rcText;
  1563. HRESULT hr = E_FAIL;
  1564. rcText.left = fDrawHorizontal ? xStart : yCenter - (prbb->cxText / 2);
  1565. rcText.top = fDrawHorizontal ? yCenter - (_cyFont / 2) : xStart;
  1566. if (fDrawHorizontal)
  1567. rcText.top -= 1; // fudge
  1568. rcText.right = rcText.left + prbb->cxText;
  1569. rcText.bottom = rcText.top + _cyFont;
  1570. // for clients >= v5, we draw text with prefix processing (& underlines next char)
  1571. if (CCGetUIState(&(_ci)) & UISF_HIDEACCEL)
  1572. uFormat= DT_HIDEPREFIX;
  1573. HFONT hFontSave = SelectFont(hdc, _hFont);
  1574. if (_hTheme)
  1575. hr = DrawThemeText(_hTheme, hdc, 0, 0, prbb->lpText, lstrlen(prbb->lpText), uFormat, 0, &rcText);
  1576. if (FAILED(hr))
  1577. {
  1578. DrawText(hdc, prbb->lpText, lstrlen(prbb->lpText), &rcText, uFormat);
  1579. }
  1580. SelectObject(hdc, hFontSave);
  1581. }
  1582. // maybe draw chevron
  1583. if (_UseChevron(prbb) && prbb->fChevron)
  1584. _DrawChevron(prbb, hdc);
  1585. }
  1586. if (dwRet & CDRF_NOTIFYPOSTPAINT)
  1587. CICustomDrawNotify(&_ci, CDDS_ITEMPOSTPAINT, &nmcd);
  1588. if (prbb->hbmBack || _hTheme)
  1589. SetBkMode(hdc, iModeSave);
  1590. SetTextColor(hdc, clrForeSave);
  1591. SetBkColor(hdc, clrBackSave);
  1592. SelectClipRgn(hdc, hrgnOld);
  1593. if (hrgnOld)
  1594. {
  1595. DeleteObject(hrgnOld);
  1596. }
  1597. }
  1598. // ----------------------------------------------------------------------------
  1599. //
  1600. // _OnPaint
  1601. //
  1602. // processes WM_PAINT message
  1603. //
  1604. // ----------------------------------------------------------------------------
  1605. void CReBar::_OnPaint(HDC hdcIn)
  1606. {
  1607. HDC hdc = hdcIn;
  1608. PAINTSTRUCT ps;
  1609. UINT i;
  1610. NMCUSTOMDRAW nmcd;
  1611. if (!hdcIn)
  1612. {
  1613. hdc = BeginPaint(_ci.hwnd, &ps);
  1614. }
  1615. nmcd.hdc = hdc;
  1616. nmcd.uItemState = 0;
  1617. nmcd.lItemlParam = 0;
  1618. nmcd.rc = ps.rcPaint;
  1619. _ci.dwCustom = CICustomDrawNotify(&_ci, CDDS_PREPAINT, &nmcd);
  1620. if (!(_ci.dwCustom & CDRF_SKIPDEFAULT))
  1621. {
  1622. for (i = 0; i < _cBands; i++) {
  1623. if (_GetBand(i)->fStyle & RBBS_HIDDEN)
  1624. continue;
  1625. _DrawBand(_GetBand(i), hdc);
  1626. }
  1627. }
  1628. if (_ci.dwCustom & CDRF_NOTIFYPOSTPAINT)
  1629. CICustomDrawNotify(&_ci, CDDS_POSTPAINT, &nmcd);
  1630. if (!hdcIn)
  1631. EndPaint(_ci.hwnd, &ps);
  1632. }
  1633. // ----------------------------------------------------------------------------
  1634. //
  1635. // _BandTileBlt
  1636. //
  1637. // Fills the given rectangle with the rebar's background bitmap, tiling if
  1638. // necessary
  1639. //
  1640. // ----------------------------------------------------------------------------
  1641. void CReBar::_BandTileBlt(PRBB prbb, int x, int y, int cx, int cy, HDC hdcDst, HDC hdcSrc)
  1642. {
  1643. int xOff = 0;
  1644. int yOff = 0;
  1645. BOOL fxTile, fyTile;
  1646. int cxPart, cyPart;
  1647. int iPixelOffset = 0;
  1648. if (!(prbb->fStyle & RBBS_FIXEDBMP))
  1649. {
  1650. if (_ci.style & CCS_VERT)
  1651. {
  1652. xOff = -prbb->y;
  1653. yOff = -prbb->x;
  1654. }
  1655. else
  1656. {
  1657. xOff = -prbb->x;
  1658. yOff = -prbb->y;
  1659. }
  1660. }
  1661. xOff += x;
  1662. if (xOff >= prbb->cxBmp)
  1663. xOff %= prbb->cxBmp;
  1664. yOff += y;
  1665. if (yOff >= prbb->cyBmp)
  1666. yOff %= prbb->cyBmp;
  1667. ReCheck:
  1668. fxTile = ((xOff + cx) > prbb->cxBmp);
  1669. fyTile = ((yOff + cy) > prbb->cyBmp);
  1670. if (!fxTile && !fyTile)
  1671. {
  1672. // no tiling needed -- blt and leave
  1673. BitBlt(hdcDst, x , y, cx, cy, hdcSrc, xOff + iPixelOffset, yOff, SRCCOPY);
  1674. return;
  1675. }
  1676. if (!fxTile)
  1677. {
  1678. // vertically tile
  1679. cyPart = prbb->cyBmp - yOff;
  1680. BitBlt(hdcDst, x, y, cx, cyPart, hdcSrc, xOff + iPixelOffset, yOff, SRCCOPY);
  1681. y += cyPart;
  1682. cy -= cyPart;
  1683. yOff = 0;
  1684. goto ReCheck;
  1685. }
  1686. if (!fyTile)
  1687. {
  1688. // horizontally tile
  1689. cxPart = prbb->cxBmp - xOff;
  1690. BitBlt(hdcDst, x, y, cxPart, cy, hdcSrc, xOff + iPixelOffset, yOff, SRCCOPY);
  1691. x += cxPart;
  1692. cx -= cxPart;
  1693. xOff = 0;
  1694. goto ReCheck;
  1695. }
  1696. // tile both ways
  1697. cyPart = prbb->cyBmp - yOff;
  1698. _BandTileBlt(prbb, x, y, cx, cyPart, hdcDst, hdcSrc);
  1699. y += cyPart;
  1700. cy -= cyPart;
  1701. yOff = 0;
  1702. goto ReCheck;
  1703. }
  1704. // this is using virtual coordinate space (internal always horizontal)
  1705. int CReBar::_InternalHitTest(LPRBHITTESTINFO prbht, int x, int y)
  1706. {
  1707. BOOL fVert = (_ci.style & CCS_VERT);
  1708. UINT i;
  1709. PRBB prbb = _GetBand(0);
  1710. int cx;
  1711. RBHITTESTINFO rbht;
  1712. if (!prbht)
  1713. prbht = &rbht;
  1714. for (i = 0; i < _cBands; i++, prbb++)
  1715. {
  1716. if (prbb->fStyle & RBBS_HIDDEN)
  1717. continue;
  1718. if (x >= prbb->x - _mBand.cxLeftWidth &&
  1719. y >= prbb->y - _mBand.cyTopHeight &&
  1720. x <= prbb->x + prbb->cx + _mBand.cxRightWidth &&
  1721. y <= prbb->y + prbb->cy + _mBand.cyTopHeight)
  1722. {
  1723. cx = _GetHeaderWidth(prbb);
  1724. if (x <= prbb->x + cx + _mBand.cxRightWidth)
  1725. {
  1726. prbht->flags = RBHT_CAPTION;
  1727. if (_IsVerticalGripper())
  1728. {
  1729. if (y - prbb->y < _GetGripperWidth())
  1730. prbht->flags = RBHT_GRABBER;
  1731. }
  1732. else
  1733. {
  1734. cx = _GetGripperWidth() * (fVert ? g_cyBorder : g_cxBorder);
  1735. if (_ShouldDrawGripper(_GetBand(i)) &&
  1736. (x <= prbb->x + cx + _mBand.cxRightWidth))
  1737. {
  1738. prbht->flags = RBHT_GRABBER;
  1739. }
  1740. }
  1741. }
  1742. else
  1743. {
  1744. POINT pt;
  1745. pt.x = x;
  1746. pt.y = y;
  1747. if (_UseChevron(prbb) &&
  1748. prbb->fChevron &&
  1749. PtInRect(&prbb->rcChevron, pt))
  1750. {
  1751. prbht->flags = RBHT_CHEVRON;
  1752. }
  1753. else
  1754. {
  1755. prbht->flags = RBHT_CLIENT;
  1756. }
  1757. }
  1758. prbht->iBand = i;
  1759. return i;
  1760. }
  1761. }
  1762. prbht->flags = RBHT_NOWHERE;
  1763. prbht->iBand = -1;
  1764. return -1;
  1765. }
  1766. // ----------------------------------------------------------------------------
  1767. //
  1768. // _HitTest
  1769. //
  1770. // returns the index to the band that the given point lies in, or -1 if outside
  1771. // of all bands. Also, sets flags to indicate which part of the band the
  1772. // point lies in.
  1773. //
  1774. // ----------------------------------------------------------------------------
  1775. int CReBar::_HitTest(LPRBHITTESTINFO prbht)
  1776. {
  1777. BOOL fVert = (_ci.style & CCS_VERT);
  1778. POINT pt;
  1779. if (fVert)
  1780. {
  1781. pt.x = prbht->pt.y;
  1782. pt.y = prbht->pt.x;
  1783. }
  1784. else
  1785. pt = prbht->pt;
  1786. return _InternalHitTest(prbht, pt.x, pt.y);
  1787. }
  1788. // ----------------------------------------------------------------------------
  1789. //
  1790. // _EraseBkgnd
  1791. //
  1792. // processes WM_ERASEBKGND message by drawing band borders, if necessary, and
  1793. // filling in the rebar bands with their background color
  1794. //
  1795. // ----------------------------------------------------------------------------
  1796. BOOL CReBar::_EraseBkgnd(HDC hdc, int iBand)
  1797. {
  1798. BOOL fVertical = (_ci.style & CCS_VERT);
  1799. NMCUSTOMDRAW nmcd;
  1800. LRESULT dwItemRet;
  1801. BOOL fBandBorders = _UseBandBorders();
  1802. RECT rcClient;
  1803. HDC hdcMem = NULL;
  1804. UINT i;
  1805. PRBB prbb = _GetBand(0);
  1806. nmcd.hdc = hdc;
  1807. nmcd.uItemState = 0;
  1808. nmcd.lItemlParam = 0;
  1809. _ci.dwCustom = CICustomDrawNotify(&_ci, CDDS_PREERASE, &nmcd);
  1810. if (!(_ci.dwCustom & CDRF_SKIPDEFAULT))
  1811. {
  1812. COLORREF clrBk;
  1813. GetClientRect(_ci.hwnd, &rcClient);
  1814. if (_hTheme)
  1815. {
  1816. RECT rcClip;
  1817. if (GetClipBox(hdc, &rcClip) == NULLREGION)
  1818. rcClip = rcClient;
  1819. if (CCShouldAskForBits(&_ci, _hTheme, 0, 0))
  1820. CCForwardPrint(&_ci, hdc);
  1821. DrawThemeBackground(_hTheme, hdc, 0, 0, &rcClient, &rcClip);
  1822. }
  1823. else
  1824. {
  1825. clrBk = _GetBkColor();
  1826. if (clrBk != CLR_NONE)
  1827. {
  1828. FillRectClr(hdc, &rcClient, clrBk);
  1829. }
  1830. }
  1831. for (i = 0; i < _cBands; i++, prbb++)
  1832. {
  1833. if (prbb->fStyle & RBBS_HIDDEN)
  1834. continue;
  1835. if (fVertical)
  1836. SetRect(&nmcd.rc, prbb->y, prbb->x, prbb->y + prbb->cy, prbb->x + prbb->cx);
  1837. else
  1838. SetRect(&nmcd.rc, prbb->x, prbb->y, prbb->x + prbb->cx, prbb->y + prbb->cy);
  1839. if (fBandBorders)
  1840. {
  1841. if (prbb->x != _mBand.cxLeftWidth)
  1842. {
  1843. // draw etch between bands on same row
  1844. if (fVertical)
  1845. {
  1846. nmcd.rc.right += g_cxEdge / 2;
  1847. nmcd.rc.top -= g_cyEdge;
  1848. CCThemeDrawEdge(_hTheme, hdc, &nmcd.rc, RP_BAND, 0, EDGE_ETCHED, BF_TOP, &(_clrsc));
  1849. nmcd.rc.right -= g_cxEdge / 2;
  1850. nmcd.rc.top += g_cyEdge;
  1851. }
  1852. else
  1853. {
  1854. nmcd.rc.bottom += g_cyEdge / 2;
  1855. nmcd.rc.left -= g_cxEdge;
  1856. CCThemeDrawEdge(_hTheme, hdc, &nmcd.rc, RP_BAND, 0, EDGE_ETCHED, BF_LEFT, &(_clrsc));
  1857. nmcd.rc.bottom -= g_cyEdge / 2;
  1858. nmcd.rc.left += g_cxEdge;
  1859. }
  1860. }
  1861. else
  1862. {
  1863. // draw etch between rows
  1864. if (fVertical)
  1865. {
  1866. rcClient.right = prbb->y + prbb->cy + g_cxEdge;
  1867. CCThemeDrawEdge(_hTheme, hdc, &rcClient, RP_BAND, 0, EDGE_ETCHED, BF_RIGHT, &(_clrsc));
  1868. }
  1869. else
  1870. {
  1871. rcClient.bottom = prbb->y + prbb->cy + g_cyEdge;
  1872. CCThemeDrawEdge(_hTheme, hdc, &rcClient, RP_BAND, 0, EDGE_ETCHED, BF_BOTTOM, &(_clrsc));
  1873. }
  1874. }
  1875. }
  1876. nmcd.dwItemSpec = prbb->wID;
  1877. nmcd.uItemState = 0;
  1878. dwItemRet = CICustomDrawNotify(&_ci, CDDS_ITEMPREERASE, &nmcd);
  1879. if (!(dwItemRet & CDRF_SKIPDEFAULT))
  1880. {
  1881. if (prbb->hbmBack)
  1882. {
  1883. if (!hdcMem)
  1884. {
  1885. hdcMem = CreateCompatibleDC(hdc);
  1886. if (!hdcMem)
  1887. continue;
  1888. _Realize(hdc, TRUE, FALSE);
  1889. }
  1890. SelectObject(hdcMem, prbb->hbmBack);
  1891. _BandTileBlt(prbb, nmcd.rc.left, nmcd.rc.top, nmcd.rc.right - nmcd.rc.left,
  1892. nmcd.rc.bottom - nmcd.rc.top, hdc, hdcMem);
  1893. }
  1894. else if (_hTheme)
  1895. {
  1896. DrawThemeBackground(_hTheme, hdc, RP_BAND, 0, &nmcd.rc, 0);
  1897. }
  1898. else
  1899. {
  1900. // if the color for this band is the same as the
  1901. // rebar's default background color, then we
  1902. // don't need to paint this specially
  1903. COLORREF clr = _BandGetBkColor(prbb);
  1904. if (clr != _GetBkColor())
  1905. {
  1906. FillRectClr(hdc, &nmcd.rc, clr);
  1907. }
  1908. }
  1909. }
  1910. if (dwItemRet & CDRF_NOTIFYPOSTERASE)
  1911. CICustomDrawNotify(&_ci, CDDS_ITEMPOSTERASE, &nmcd);
  1912. }
  1913. if (hdcMem)
  1914. {
  1915. DeleteDC(hdcMem);
  1916. }
  1917. }
  1918. if (_ci.dwCustom & CDRF_NOTIFYPOSTERASE)
  1919. {
  1920. nmcd.uItemState = 0;
  1921. nmcd.dwItemSpec = 0;
  1922. nmcd.lItemlParam = 0;
  1923. CICustomDrawNotify(&_ci, CDDS_POSTERASE, &nmcd);
  1924. }
  1925. return(TRUE);
  1926. }
  1927. // ----------------------------------------------------------------------------
  1928. //
  1929. // _GetBarInfo
  1930. //
  1931. // retrieves the indicated values from the rebar's internal structure
  1932. //
  1933. // ----------------------------------------------------------------------------
  1934. BOOL CReBar::_GetBarInfo(LPREBARINFO lprbi)
  1935. {
  1936. if (lprbi->cbSize != sizeof(REBARINFO))
  1937. return(FALSE);
  1938. if (lprbi->fMask & RBIM_IMAGELIST)
  1939. lprbi->himl = _himl;
  1940. return(TRUE);
  1941. }
  1942. // ----------------------------------------------------------------------------
  1943. //
  1944. // _SetBarInfo
  1945. //
  1946. // sets the indicated values in the rebar's internal structure, recalculating
  1947. // and refreshing as needed
  1948. //
  1949. // ----------------------------------------------------------------------------
  1950. BOOL CReBar::_SetBarInfo(LPREBARINFO lprbi)
  1951. {
  1952. if (lprbi->cbSize != sizeof(REBARINFO))
  1953. return(FALSE);
  1954. if (lprbi->fMask & RBIM_IMAGELIST)
  1955. {
  1956. HIMAGELIST himl = _himl;
  1957. int cxOld, cyOld;
  1958. //todo:validate lprbi->himl
  1959. _himl = lprbi->himl;
  1960. cxOld = _cxImage;
  1961. cyOld = _cyImage;
  1962. ImageList_GetIconSize(_himl, (LPINT)&_cxImage, (LPINT)&_cyImage);
  1963. if ((_cxImage != cxOld) || (_cyImage != cyOld))
  1964. {
  1965. UINT i;
  1966. for (i = 0; i < _cBands; i++) {
  1967. if (_GetBand(i)->fStyle & RBBS_HIDDEN)
  1968. continue;
  1969. _BandCalcMinWidth(_GetBand(i));
  1970. }
  1971. _Resize(FALSE);
  1972. }
  1973. else
  1974. _InvalidateRect(NULL);
  1975. lprbi->himl = himl;
  1976. }
  1977. return(TRUE);
  1978. }
  1979. // ----------------------------------------------------------------------------
  1980. //
  1981. // _GetBandInfo
  1982. //
  1983. // retrieves the indicated values from the specified band's internal structure
  1984. //
  1985. // ----------------------------------------------------------------------------
  1986. BOOL CReBar::_GetBandInfo(UINT uBand, LPREBARBANDINFO lprbbi)
  1987. {
  1988. PRBB prbb;
  1989. if (!_IsValidIndex(uBand) || lprbbi->cbSize > SIZEOF(REBARBANDINFO))
  1990. return(FALSE);
  1991. prbb = _GetBand(uBand);
  1992. if (lprbbi->fMask & RBBIM_SIZE) {
  1993. if (prbb->fStyle & RBBS_FIXEDSIZE)
  1994. lprbbi->cx = prbb->cx;
  1995. else
  1996. lprbbi->cx = prbb->cxRequest;
  1997. }
  1998. if (lprbbi->fMask & RBBIM_STYLE)
  1999. lprbbi->fStyle = prbb->fStyle;
  2000. if (lprbbi->fMask & RBBIM_COLORS)
  2001. {
  2002. lprbbi->clrFore = _BandGetTextColorExternal(prbb);
  2003. lprbbi->clrBack = _BandGetBkColorExternal(prbb);
  2004. }
  2005. if (lprbbi->fMask & RBBIM_TEXT)
  2006. {
  2007. UINT cch = prbb->lpText ? lstrlen(prbb->lpText) : 0;
  2008. if (!lprbbi->cch || !lprbbi->lpText || (lprbbi->cch <= cch))
  2009. {
  2010. lprbbi->cch = cch + 1;
  2011. }
  2012. else if (prbb->lpText)
  2013. {
  2014. StringCchCopy(lprbbi->lpText, lprbbi->cch, prbb->lpText);
  2015. }
  2016. else
  2017. {
  2018. // no text -- so just make it an empty string
  2019. lprbbi->lpText[0] = 0;
  2020. }
  2021. }
  2022. if (lprbbi->fMask & RBBIM_IMAGE)
  2023. lprbbi->iImage = prbb->iImage;
  2024. if (lprbbi->fMask & RBBIM_CHILD)
  2025. lprbbi->hwndChild = prbb->hwndChild;
  2026. if (lprbbi->fMask & RBBIM_CHILDSIZE)
  2027. {
  2028. // HACKHACK: (tjgreen) Subtract the offset we added in SetBandInfo (see
  2029. // comments there).
  2030. lprbbi->cxMinChild = prbb->cxMinChild ? prbb->cxMinChild - CX_OFFSET : 0;
  2031. lprbbi->cyMinChild = prbb->cyMinChild;
  2032. }
  2033. if (lprbbi->fMask & RBBIM_BACKGROUND)
  2034. lprbbi->hbmBack = prbb->hbmBack;
  2035. if (lprbbi->fMask & RBBIM_ID)
  2036. lprbbi->wID = prbb->wID;
  2037. if (lprbbi->cbSize > REBARBANDINFO_V3_SIZE)
  2038. {
  2039. if ((lprbbi->fMask & RBBIM_CHILDSIZE) && (prbb->fStyle & RBBS_VARIABLEHEIGHT))
  2040. {
  2041. lprbbi->cyIntegral = prbb->cyIntegral;
  2042. lprbbi->cyMaxChild = prbb->cyMaxChild;
  2043. lprbbi->cyChild = prbb->cyChild;
  2044. }
  2045. if (lprbbi->fMask & RBBIM_HEADERSIZE)
  2046. lprbbi->cxHeader = _GetHeaderWidth(prbb);
  2047. if (lprbbi->fMask & RBBIM_IDEALSIZE)
  2048. // HACKHACK: (tjgreen) Subtract the offset we added in SetBandInfo (see
  2049. // comments there).
  2050. lprbbi->cxIdeal = prbb->cxIdeal ? prbb->cxIdeal - CX_OFFSET : 0;
  2051. if (lprbbi->fMask & RBBIM_LPARAM)
  2052. lprbbi->lParam = prbb->lParam;
  2053. }
  2054. return(TRUE);
  2055. }
  2056. BOOL CReBar::_ValidateBandInfo(LPREBARBANDINFO *pprbbi, LPREBARBANDINFO prbbi)
  2057. {
  2058. BOOL fRet = ((*pprbbi)->cbSize == sizeof(REBARBANDINFO));
  2059. if (!fRet)
  2060. {
  2061. if ((*pprbbi)->cbSize < SIZEOF(REBARBANDINFO))
  2062. {
  2063. hmemcpy(prbbi, (*pprbbi), (*pprbbi)->cbSize);
  2064. (*pprbbi) = prbbi;
  2065. prbbi->cbSize = SIZEOF(REBARBANDINFO);
  2066. fRet = TRUE;
  2067. }
  2068. }
  2069. return fRet;
  2070. }
  2071. // ----------------------------------------------------------------------------
  2072. //
  2073. // _SetBandInfo
  2074. //
  2075. // sets the indicated values in the specified band's internal structure,
  2076. // recalculating and refreshing as needed
  2077. //
  2078. // ----------------------------------------------------------------------------
  2079. BOOL CReBar::_SetBandInfo(UINT uBand, LPREBARBANDINFO lprbbi, BOOL fAllowRecalc)
  2080. {
  2081. PRBB prbb;
  2082. BOOL fRefresh = FALSE;
  2083. BOOL fRecalc = FALSE;
  2084. BOOL fRecalcMin = FALSE;
  2085. BOOL fTextChanged = FALSE;
  2086. REBARBANDINFO rbbi = {0};
  2087. RECT rc;
  2088. if (!_IsValidIndex(uBand) || !_ValidateBandInfo(&lprbbi, &rbbi))
  2089. return(FALSE);
  2090. prbb = _GetBand(uBand);
  2091. if (lprbbi->fMask & RBBIM_TEXT)
  2092. {
  2093. if (!lprbbi->lpText || !prbb->lpText || lstrcmp(lprbbi->lpText, prbb->lpText))
  2094. {
  2095. if (lprbbi->lpText != prbb->lpText) {
  2096. Str_Set(&prbb->lpText, lprbbi->lpText);
  2097. fTextChanged = TRUE;
  2098. }
  2099. }
  2100. }
  2101. if (lprbbi->fMask & RBBIM_STYLE)
  2102. {
  2103. UINT fStylePrev = prbb->fStyle;
  2104. UINT fChanged = lprbbi->fStyle ^ fStylePrev;
  2105. prbb->fStyle = lprbbi->fStyle;
  2106. if (fChanged)
  2107. fRecalc = TRUE;
  2108. if ((prbb->fStyle & RBBS_FIXEDSIZE) && !(fStylePrev & RBBS_FIXEDSIZE))
  2109. prbb->cxMin = prbb->cx;
  2110. else if (fChanged & RBBS_FIXEDSIZE)
  2111. fRecalcMin = TRUE;
  2112. if (fChanged & RBBS_GRIPPERALWAYS)
  2113. fRecalcMin = TRUE;
  2114. if (fChanged & RBBS_HIDDEN)
  2115. _ShowBand(uBand, !(prbb->fStyle & RBBS_HIDDEN));
  2116. if (fChanged & RBBS_HIDETITLE)
  2117. fTextChanged = TRUE;
  2118. // can't have both of these
  2119. if (prbb->fStyle & RBBS_FIXEDSIZE)
  2120. prbb->fStyle &= ~RBBS_BREAK;
  2121. }
  2122. // RBBIM_TEXT does calculations that want to take some RBBIM_STYLE bits
  2123. // into account, so delay those calculations until we grab the style bits.
  2124. //
  2125. if (fTextChanged && !(prbb->fStyle & RBBS_HIDDEN))
  2126. {
  2127. if (_BandCalcTextExtent(prbb, NULL))
  2128. fRecalc = TRUE;
  2129. else
  2130. fRefresh = TRUE;
  2131. }
  2132. if (lprbbi->fMask & RBBIM_IDEALSIZE)
  2133. {
  2134. // HACKHACK: (tjgreen) Add an offset to the width the caller specifies.
  2135. // This offset gets clipped off in _ResizeChildren, so the child window is
  2136. // rendered with the width specified by caller, and we get a little space on
  2137. // the toolbar after the buttons. If caller specifies zero-width, though,
  2138. // we don't want this extra space, so don't add offset.
  2139. int cxIdeal = lprbbi->cxIdeal ? lprbbi->cxIdeal + CX_OFFSET : 0;
  2140. if (cxIdeal != prbb->cxIdeal)
  2141. {
  2142. prbb->cxIdeal = cxIdeal;
  2143. fRecalcMin = TRUE;
  2144. fRecalc = TRUE;
  2145. }
  2146. }
  2147. if (lprbbi->fMask & RBBIM_SIZE)
  2148. {
  2149. if (prbb->cxRequest != (int)lprbbi->cx)
  2150. {
  2151. fRecalc = TRUE;
  2152. prbb->cxRequest = lprbbi->cx;
  2153. }
  2154. if (prbb->fStyle & RBBS_FIXEDSIZE)
  2155. prbb->cxMin = prbb->cxRequest;
  2156. }
  2157. if (lprbbi->fMask & RBBIM_HEADERSIZE)
  2158. {
  2159. if ((lprbbi->cxHeader == -1) ||
  2160. !(prbb->fStyle & RBBS_FIXEDHEADERSIZE) ||
  2161. (prbb->cxMin != (int)lprbbi->cxHeader + prbb->cxMinChild))
  2162. {
  2163. if (lprbbi->cxHeader == -1)
  2164. {
  2165. prbb->fStyle &= ~RBBS_FIXEDHEADERSIZE;
  2166. fRecalcMin = TRUE;
  2167. }
  2168. else
  2169. {
  2170. prbb->fStyle |= RBBS_FIXEDHEADERSIZE;
  2171. prbb->cxMin = lprbbi->cxHeader + prbb->cxMinChild;
  2172. }
  2173. fRecalc = TRUE;
  2174. fRefresh = TRUE;
  2175. }
  2176. }
  2177. if (lprbbi->fMask & RBBIM_COLORS)
  2178. {
  2179. prbb->clrFore = lprbbi->clrFore;
  2180. prbb->clrBack = lprbbi->clrBack;
  2181. fRefresh = TRUE;
  2182. }
  2183. if ((lprbbi->fMask & RBBIM_IMAGE) && (prbb->iImage != lprbbi->iImage))
  2184. {
  2185. BOOL fToggleBmp = ((prbb->iImage == -1) || (lprbbi->iImage == -1));
  2186. prbb->iImage = lprbbi->iImage;
  2187. if (fToggleBmp)
  2188. {
  2189. fRecalc = TRUE;
  2190. fRecalcMin = TRUE;
  2191. }
  2192. else
  2193. fRefresh = TRUE;
  2194. }
  2195. if (lprbbi->fMask & RBBIM_CHILD &&
  2196. lprbbi->hwndChild != prbb->hwndChild &&
  2197. (NULL == lprbbi->hwndChild ||
  2198. !IsChild(lprbbi->hwndChild, _ci.hwnd)))
  2199. {
  2200. if (IsWindow(prbb->hwndChild))
  2201. ShowWindow(prbb->hwndChild, SW_HIDE);
  2202. prbb->hwndChild = lprbbi->hwndChild;
  2203. if (prbb->hwndChild)
  2204. {
  2205. SetParent(prbb->hwndChild, _ci.hwnd);
  2206. ShowWindow(prbb->hwndChild, SW_SHOW);
  2207. }
  2208. fRecalc = TRUE;
  2209. }
  2210. if (lprbbi->fMask & RBBIM_CHILDSIZE)
  2211. {
  2212. int cyChildOld = prbb->cyChild;
  2213. if (lprbbi->cyMinChild != -1)
  2214. prbb->cyMinChild = lprbbi->cyMinChild;
  2215. if (prbb->fStyle & RBBS_VARIABLEHEIGHT)
  2216. {
  2217. BOOL fIntegralLarger = FALSE;
  2218. if (lprbbi->cyIntegral != -1)
  2219. {
  2220. fIntegralLarger = ((int)lprbbi->cyIntegral > prbb->cyIntegral);
  2221. prbb->cyIntegral = lprbbi->cyIntegral;
  2222. }
  2223. if (lprbbi->cyMaxChild != -1)
  2224. prbb->cyMaxChild = lprbbi->cyMaxChild;
  2225. if (lprbbi->cyChild != -1)
  2226. prbb->cyChild = lprbbi->cyChild;
  2227. if (prbb->cyChild < prbb->cyMinChild)
  2228. prbb->cyChild = prbb->cyMinChild;
  2229. if (prbb->cyChild > prbb->cyMaxChild)
  2230. prbb->cyChild = prbb->cyMaxChild;
  2231. // validate the child size. cyChild must be cyMinChild plux n*cyIntegral
  2232. if (prbb->cyIntegral)
  2233. {
  2234. int iExtra;
  2235. iExtra = (prbb->cyChild - prbb->cyMinChild) % prbb->cyIntegral;
  2236. // Don't change cyChild if it is already an valid integral height
  2237. if (iExtra)
  2238. {
  2239. if (fIntegralLarger)
  2240. {
  2241. // Round up
  2242. prbb->cyChild += (prbb->cyIntegral - iExtra);
  2243. }
  2244. else
  2245. {
  2246. // Round down
  2247. prbb->cyChild -= iExtra;
  2248. }
  2249. }
  2250. }
  2251. }
  2252. else
  2253. {
  2254. // if we're not in variable height mode, then
  2255. // the cyChild is the same as cyMinChild.
  2256. // this is a little peculiar, but done this way for backcompat.
  2257. // cyMinChild came before cyChild
  2258. prbb->cyChild = lprbbi->cyMinChild;
  2259. }
  2260. if (lprbbi->cxMinChild != -1)
  2261. {
  2262. // HACKHACK: (tjgreen) Add an offset to the width the caller specifies.
  2263. // This offset gets clipped off in _ResizeChildren, so the child window is
  2264. // rendered with the width specified by caller, and we get a little space on
  2265. // the toolbar after the buttons. However, if caller specifies zero-width or
  2266. // if the band is fixed size, we don't want this extra space, so don't add offset.
  2267. int cxMinChild = lprbbi->cxMinChild;
  2268. if ((lprbbi->cxMinChild != 0) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  2269. cxMinChild += CX_OFFSET;
  2270. if (prbb->cxMinChild != cxMinChild)
  2271. {
  2272. int cxOldHeaderMin = _GetHeaderWidth(prbb);
  2273. if (prbb->fStyle & RBBS_FIXEDSIZE)
  2274. fRecalc = TRUE;
  2275. prbb->cxMinChild = cxMinChild;
  2276. if (prbb->fStyle & RBBS_FIXEDHEADERSIZE)
  2277. prbb->cxMin = cxOldHeaderMin + prbb->cxMinChild;
  2278. fRecalcMin = TRUE;
  2279. }
  2280. if (cyChildOld != prbb->cyChild)
  2281. {
  2282. // TODO: revisit optimization:
  2283. // if (_BandGetHeight(prbb) != prbb->cy)
  2284. fRecalc = TRUE;
  2285. }
  2286. }
  2287. }
  2288. if (lprbbi->fMask & RBBIM_BACKGROUND)
  2289. {
  2290. DIBSECTION dib;
  2291. if (lprbbi->hbmBack && !GetObject(lprbbi->hbmBack, sizeof(DIBSECTION), &dib))
  2292. return(FALSE);
  2293. prbb->hbmBack = lprbbi->hbmBack;
  2294. prbb->cxBmp = dib.dsBm.bmWidth;
  2295. prbb->cyBmp = dib.dsBm.bmHeight;
  2296. fRefresh = TRUE;
  2297. }
  2298. if (lprbbi->fMask & RBBIM_ID)
  2299. prbb->wID = lprbbi->wID;
  2300. if (lprbbi->fMask & RBBIM_LPARAM)
  2301. prbb->lParam = lprbbi->lParam;
  2302. if (fRecalcMin && !(prbb->fStyle & RBBS_HIDDEN))
  2303. _BandCalcMinWidth(prbb);
  2304. if (fAllowRecalc)
  2305. {
  2306. if (fRecalc)
  2307. _Resize(FALSE);
  2308. if (fRefresh || fRecalc)
  2309. {
  2310. // '|| fRecalc' so we catch add/grow of text.
  2311. // testcase: remove title from band; add back; make sure the text
  2312. // shows up (used to just leave old band contents there)
  2313. SetRect(&rc, prbb->x, prbb->y, prbb->x + prbb->cx, prbb->y + prbb->cy);
  2314. _InvalidateRect(&rc);
  2315. }
  2316. }
  2317. return(TRUE);
  2318. }
  2319. // ----------------------------------------------------------------------------
  2320. //
  2321. // _ReallocBands
  2322. //
  2323. // reallocates the array of bands pointed to by _rbbList to the given
  2324. // number of bands
  2325. //
  2326. // ----------------------------------------------------------------------------
  2327. BOOL CReBar::_ReallocBands(UINT cBands)
  2328. {
  2329. PRBB rbbList;
  2330. if (!(rbbList = (PRBB) CCLocalReAlloc(_rbbList, sizeof(RBB) * cBands)) && cBands)
  2331. return(FALSE);
  2332. _rbbList = rbbList;
  2333. return(TRUE);
  2334. }
  2335. //
  2336. // NOTES
  2337. // for now caller does this in two calls (query, set). eventually we
  2338. // should be able to have it do everything up front.
  2339. BOOL CReBar::_RecalcFirst(int nCmd, PRBB prbbDelHide)
  2340. {
  2341. switch (nCmd) {
  2342. case RBC_QUERY:
  2343. {
  2344. BOOL fRecalcFirst;
  2345. // if we're nuking the 1st visible guy,
  2346. // and there are visible guys after us,
  2347. // then we need to recompute stuff
  2348. //
  2349. // for a testcase, start w/:
  2350. // row1: 'standard buttons' + 'brand'
  2351. // row2: 'address' + 'links'
  2352. // now hide 'standard buttons', you should end up w/:
  2353. // row1: 'address' + 'links' + 'brand'
  2354. // if there's a bug, you'll end up w/ (since the break isn't recomputed):
  2355. // row1: 'brand'
  2356. // row2: 'address' + 'links'
  2357. // fRecalcFirst = (!uBand && _cBands);
  2358. // if brbbDelHide is the first non-hidden band, and there are other non-hidden bands after it, fRecalcFirst = TRUE;
  2359. fRecalcFirst = (_EnumBand(0, RBBS_HIDDEN) == prbbDelHide) &&
  2360. _GetNextVisible(prbbDelHide);
  2361. return fRecalcFirst;
  2362. }
  2363. case RBC_SET: // set
  2364. {
  2365. PRBB prbb1 = _EnumBand(0, RBBS_HIDDEN);
  2366. if (_IsValidBand(prbb1) && (prbb1->fStyle & RBBS_FIXEDSIZE))
  2367. {
  2368. PRBB prbb2 = _EnumBand(1, RBBS_HIDDEN);
  2369. if (_IsValidBand(prbb2))
  2370. {
  2371. // get rid of line break on NEW first item
  2372. prbb2->fStyle &= ~RBBS_BREAK;
  2373. }
  2374. if (_ci.style & RBS_FIXEDORDER)
  2375. {
  2376. // this is because the min width is now based on it's movability --
  2377. // and since we are deleting (or hiding) the first item,
  2378. // the new first item becomes immovable
  2379. _BandCalcMinWidth(prbb1);
  2380. }
  2381. }
  2382. return TRUE;
  2383. }
  2384. default:
  2385. ASSERT(0);
  2386. }
  2387. return FALSE;
  2388. }
  2389. // ----------------------------------------------------------------------------
  2390. //
  2391. // _ShowBand
  2392. //
  2393. // updates show/hide state for the indicated band in the rebar's band array
  2394. // (rbbList).
  2395. //
  2396. // ----------------------------------------------------------------------------
  2397. BOOL CReBar::_ShowBand(UINT uBand, BOOL fShow)
  2398. {
  2399. PRBB prbb;
  2400. BOOL fRecalcFirst;
  2401. if (!_IsValidIndex(uBand))
  2402. return(FALSE);
  2403. prbb = _GetBand(uBand);
  2404. // if we're nuking the 1st visible guy,
  2405. // then we need to recompute stuff
  2406. fRecalcFirst = _RecalcFirst(RBC_QUERY, prbb);
  2407. if (fShow)
  2408. {
  2409. prbb->fStyle &= ~RBBS_HIDDEN;
  2410. if (!_BandCalcTextExtent(prbb, NULL))
  2411. _BandCalcMinWidth(prbb);
  2412. if (prbb->hwndChild)
  2413. ShowWindow(prbb->hwndChild, SW_SHOW);
  2414. }
  2415. else
  2416. {
  2417. prbb->fStyle |= RBBS_HIDDEN;
  2418. if (prbb->hwndChild)
  2419. ShowWindow(prbb->hwndChild, SW_HIDE);
  2420. }
  2421. if (fRecalcFirst)
  2422. _RecalcFirst(RBC_SET, NULL);
  2423. _InvalidateRect(NULL);
  2424. // Since _Resize is followed by _AutoSize,
  2425. // redraw must be TRUE for _Resize to do anything.
  2426. BOOL fRedrawOld = _SetRedraw(TRUE);
  2427. _Resize(FALSE);
  2428. _AutoSize();
  2429. _SetRedraw(fRedrawOld);
  2430. return(TRUE);
  2431. }
  2432. // ----------------------------------------------------------------------------
  2433. //
  2434. // _DeleteBand
  2435. //
  2436. // deletes the indicated band from the rebar's band array (rbbList) and
  2437. // decrements the rebar's band count (cBands)
  2438. //
  2439. // ----------------------------------------------------------------------------
  2440. BOOL CReBar::_DeleteBand(UINT uBand)
  2441. {
  2442. PRBB prbb;
  2443. PRBB prbbStop;
  2444. BOOL fRecalcFirst;
  2445. NMREBAR nm = {0};
  2446. // we need to clean up
  2447. //
  2448. // a) captured band and
  2449. // b) hottracked band
  2450. //
  2451. // before we delete this band
  2452. if (_uCapture != -1)
  2453. {
  2454. _SendNotify(_uCapture, RBN_ENDDRAG);
  2455. _OnBeginDrag((UINT)-1);
  2456. }
  2457. if (!_IsValidIndex(uBand))
  2458. return FALSE;
  2459. prbb = _GetBand(uBand);
  2460. // Notify the client of the delete
  2461. _SendNotify(uBand, RBN_DELETINGBAND);
  2462. nm.dwMask = RBNM_ID;
  2463. nm.wID = _GetBand(uBand)->wID; // Save this
  2464. Str_Set(&prbb->lpText, NULL);
  2465. // don't destroy the hbmBack 'cause it's given to us by app
  2466. // if we're nuking the 1st visible guy,
  2467. // then we need to recompute stuff
  2468. // if this is the first visible guy and there are other visible bands after it, fRecalcFirst = TRUE
  2469. fRecalcFirst = _RecalcFirst(RBC_QUERY, prbb);
  2470. if (IsWindow(prbb->hwndChild))
  2471. ShowWindow(prbb->hwndChild, SW_HIDE);
  2472. // prbbStop gets the address of the last band
  2473. prbbStop = _GetLastBand();
  2474. for ( ; prbb < prbbStop; prbb++)
  2475. *prbb = *(prbb + 1);
  2476. _cBands--;
  2477. if (_uResizeNext >= uBand && _uResizeNext > 0)
  2478. {
  2479. // (defer RBBS_HIDDEN stuff to use of uResizeNext)
  2480. _uResizeNext--;
  2481. }
  2482. // Notify the client of the delete
  2483. CCSendNotify(&_ci, RBN_DELETEDBAND, &nm.hdr);
  2484. if (fRecalcFirst)
  2485. _RecalcFirst(RBC_SET, NULL);
  2486. _ReallocBands(_cBands);
  2487. _InvalidateRect(NULL);
  2488. _Resize(FALSE);
  2489. _AutoSize();
  2490. return(TRUE);
  2491. }
  2492. // ----------------------------------------------------------------------------
  2493. //
  2494. // _InsertBand
  2495. //
  2496. // inserts a new band at the given position in the rebar's band array (rbbList),
  2497. // increments the rebar's band count (cBands), and sets the band's structure
  2498. // based on the given REBARBANDINFO structure.
  2499. //
  2500. // ----------------------------------------------------------------------------
  2501. BOOL CReBar::_InsertBand(UINT uBand, LPREBARBANDINFO lprbbi)
  2502. {
  2503. PRBB prbb;
  2504. REBARBANDINFO rbbi = {0};
  2505. if (!_ValidateBandInfo(&lprbbi, &rbbi))
  2506. return(FALSE);
  2507. if (uBand == -1)
  2508. uBand = _cBands;
  2509. else if (uBand > _cBands)
  2510. return(FALSE);
  2511. if (!_ReallocBands(_cBands + 1))
  2512. return(FALSE);
  2513. ++_cBands;
  2514. MoveMemory(_GetBand(uBand + 1), _GetBand(uBand), (_cBands-1-uBand) * sizeof(_rbbList[0]));
  2515. prbb = _GetBand(uBand);
  2516. // movememory does not zero init for us...
  2517. ZeroMemory(prbb, SIZEOF(RBB));
  2518. // Init text color
  2519. if (_clrText == CLR_NONE)
  2520. {
  2521. // Default to system text color
  2522. prbb->clrFore = CLR_DEFAULT;
  2523. }
  2524. else
  2525. {
  2526. // Default to rebar's custom text color
  2527. prbb->clrFore = CLR_NONE;
  2528. }
  2529. // Init background color
  2530. if (_clrBk == CLR_NONE)
  2531. {
  2532. // Default to system background color
  2533. prbb->clrBack = CLR_DEFAULT;
  2534. }
  2535. else
  2536. {
  2537. // Default to rebar's custom background color
  2538. prbb->clrBack = CLR_NONE;
  2539. }
  2540. prbb->iImage = -1;
  2541. prbb->cyMaxChild = MAXINT;
  2542. prbb->wChevState = DCHF_INACTIVE;
  2543. ASSERT(prbb->fStyle == 0);
  2544. ASSERT(prbb->lpText == NULL);
  2545. ASSERT(prbb->cxText == 0);
  2546. ASSERT(prbb->hwndChild == NULL);
  2547. ASSERT(prbb->cxMinChild == 0);
  2548. ASSERT(prbb->cyMinChild == 0);
  2549. ASSERT(prbb->hbmBack == 0);
  2550. ASSERT(prbb->x == 0);
  2551. ASSERT(prbb->y == 0);
  2552. ASSERT(prbb->cx == 0);
  2553. ASSERT(prbb->cy == 0);
  2554. if (!_SetBandInfo(uBand, lprbbi, FALSE))
  2555. {
  2556. _DeleteBand(uBand);
  2557. return(FALSE);
  2558. }
  2559. if (!(prbb->fStyle & RBBS_HIDDEN))
  2560. {
  2561. PRBB prbbFirst = _EnumBand(0, RBBS_HIDDEN);
  2562. if (!prbb->cxMin)
  2563. _BandCalcMinWidth(prbb);
  2564. if (prbbFirst != prbb)
  2565. {
  2566. int cxMin = prbbFirst->cxMin;
  2567. _BandCalcMinWidth(prbbFirst);
  2568. }
  2569. _Resize(FALSE);
  2570. }
  2571. _SizeBandToRowHeight(uBand, -1);
  2572. if (_CountBands(RBBS_HIDDEN) == 1)
  2573. {
  2574. // typcially, when you insert a band, we put it in a row with another band.
  2575. // thus the total bounding rect doesn't change. however, on the addition of the first band,
  2576. // the bound rect does change, so we need to autosize as necessary.
  2577. _AutoSize();
  2578. }
  2579. return(TRUE);
  2580. }
  2581. BOOL InitReBarClass(HINSTANCE hInstance)
  2582. {
  2583. WNDCLASS wc;
  2584. wc.lpfnWndProc = CReBar::s_WndProc;
  2585. wc.lpszClassName= c_szReBarClass;
  2586. wc.style = CS_GLOBALCLASS | CS_DBLCLKS;
  2587. wc.cbClsExtra = 0;
  2588. wc.cbWndExtra = sizeof(CReBar*);
  2589. wc.hInstance = hInstance; // use DLL instance if in DLL
  2590. wc.hIcon = NULL;
  2591. wc.hCursor = NULL;
  2592. wc.hbrBackground= (HBRUSH)(COLOR_BTNFACE + 1);
  2593. wc.lpszMenuName = NULL;
  2594. return (RegisterClass(&wc) || (GetLastError() == ERROR_CLASS_ALREADY_EXISTS));
  2595. }
  2596. // get the first band in the same row as rbbRow
  2597. // n.b. we may return an RBBS_HIDDEN band!
  2598. PRBB CReBar::_GetFirstInRow(PRBB prbbRow)
  2599. {
  2600. // n.b. we don't pay attention to hidden here, that's up to caller.
  2601. // in fact we *can't*, since there might be no non-hidden guys left
  2602. // (e.g. when _OnDestroy is deleting all the bands), in which case
  2603. // we'd loop forever.
  2604. while (prbbRow > _GetBand(0) && !_IsBandStartOfRow(prbbRow))
  2605. {
  2606. _ValidateRangePtr(prbbRow);
  2607. prbbRow--;
  2608. }
  2609. return prbbRow;
  2610. }
  2611. // get the last band in the same row as rbbRow.
  2612. // fStopAtFixed says whether to continue over fixed bands or
  2613. // stop at them
  2614. // n.b. we may return an RBBS_HIDDEN band!
  2615. PRBB CReBar::_GetLastInRow(PRBB prbbRow, BOOL fStopAtFixed)
  2616. {
  2617. do
  2618. {
  2619. prbbRow++;
  2620. }
  2621. while (prbbRow <= _GetLastBand() && !_IsBandStartOfRow(prbbRow) &&
  2622. (!fStopAtFixed || (prbbRow->fStyle & (RBBS_FIXEDSIZE|RBBS_HIDDEN)) == RBBS_FIXEDSIZE));
  2623. // loop steps to the start of the NEXT line
  2624. prbbRow--;
  2625. return prbbRow;
  2626. }
  2627. //*** _GetPrev, _GetNext -- get prev (next) band, skipping guys
  2628. // of style uStyleSkip (e.g. RBBS_HIDDEN)
  2629. PRBB CReBar::_GetPrev(PRBB prbb, UINT uStyleSkip)
  2630. {
  2631. while (--prbb >= _GetBand(0))
  2632. {
  2633. if (prbb->fStyle & uStyleSkip)
  2634. continue;
  2635. return prbb;
  2636. }
  2637. return NULL;
  2638. }
  2639. PRBB CReBar::_GetNext(PRBB prbb, UINT uStyleSkip)
  2640. {
  2641. while (++prbb <= _GetLastBand())
  2642. {
  2643. if (prbb->fStyle & uStyleSkip)
  2644. continue;
  2645. return prbb;
  2646. }
  2647. return NULL;
  2648. }
  2649. //*** _CountBands -- get count of bands, skipping guys
  2650. // of style uStyleSkip (e.g. RBBS_HIDDEN)
  2651. int CReBar::_CountBands(UINT uStyleSkip)
  2652. {
  2653. int i;
  2654. PRBB prbb;
  2655. if (_cBands == 0)
  2656. return 0;
  2657. i = 0;
  2658. for (prbb = _GetBand(0); prbb <= _GetLastBand(); prbb++)
  2659. {
  2660. if (prbb->fStyle & uStyleSkip)
  2661. continue;
  2662. i++;
  2663. }
  2664. return i;
  2665. }
  2666. //*** _EnumBand -- get Nth band, skipping guys
  2667. // of style uStyleSkip (e.g. RBBS_HIDDEN)
  2668. // 'skipping' means don't include in count
  2669. PRBB CReBar::_EnumBand(int i, UINT uStyleSkip)
  2670. {
  2671. PRBB prbb;
  2672. for (prbb = _GetBand(0); prbb <= _GetLastBand(); prbb++)
  2673. {
  2674. if (prbb->fStyle & uStyleSkip)
  2675. continue;
  2676. if (i-- == 0)
  2677. break;
  2678. }
  2679. // if we found it, this is the band;
  2680. // if we ran out of bands, this is 1 past the end
  2681. return prbb;
  2682. }
  2683. // returns the minimum x position prbb can be
  2684. int CReBar::_MinX(PRBB prbb)
  2685. {
  2686. int xLimit = 0;
  2687. ASSERT(!(prbb->fStyle & RBBS_HIDDEN)); // o.w. might loop forever
  2688. while (!_IsBandStartOfRow(prbb))
  2689. {
  2690. prbb--;
  2691. if (!(prbb->fStyle & RBBS_HIDDEN))
  2692. xLimit += _FudgeWidth(prbb->cxMin);
  2693. }
  2694. return xLimit + _mBand.cxLeftWidth;
  2695. }
  2696. int CReBar::_MaxX(PRBB prbb)
  2697. {
  2698. int xLimit = 0;
  2699. if (prbb)
  2700. {
  2701. PRBB prbbLast = _rbbList + _cBands;
  2702. PRBB prbbWalk;
  2703. for (prbbWalk = prbb; prbbWalk < prbbLast; prbbWalk++)
  2704. {
  2705. if (prbbWalk->fStyle & RBBS_HIDDEN)
  2706. continue;
  2707. if (_IsBandStartOfRow(prbbWalk))
  2708. break;
  2709. if (prbbWalk != prbb)
  2710. xLimit += _FudgeWidth(prbbWalk->cxMin);
  2711. else
  2712. xLimit += prbbWalk->cxMin;
  2713. }
  2714. prbbWalk = _GetPrevVisible(prbbWalk); // prbbWalk--;
  2715. if (prbbWalk)
  2716. xLimit = prbbWalk->x + prbbWalk->cx - xLimit;
  2717. }
  2718. return xLimit;
  2719. }
  2720. BOOL CReBar::_MinimizeBand(UINT uBand, BOOL fAnim)
  2721. {
  2722. PRBB prbb;
  2723. if (!_IsValidIndex(uBand))
  2724. return FALSE;
  2725. prbb = _GetBand(uBand);
  2726. if (prbb->fStyle & RBBS_FIXEDSIZE)
  2727. return FALSE;
  2728. ASSERT(!(prbb->fStyle & RBBS_HIDDEN));
  2729. if (_IsBandStartOfRow(prbb))
  2730. {
  2731. // if it's the start of a row, the way to minimize it is to maximize the next guy
  2732. // if it's on the same row
  2733. prbb = _GetNextVisible(prbb);
  2734. if (!prbb || _IsBandStartOfRow(prbb))
  2735. return FALSE;
  2736. return _MaximizeBand(_BandToIndex(prbb), FALSE, fAnim);
  2737. }
  2738. if (fAnim)
  2739. return _SetBandPosAnim(prbb, prbb->x + (prbb->cx - prbb->cxMin));
  2740. else
  2741. return _SetBandPos(prbb, prbb->x + (prbb->cx - prbb->cxMin));
  2742. }
  2743. // fIdeal - FALSE == full maximization...
  2744. // TRUE == go to cxIdeal
  2745. // fAnim - TRUE means we were called due to UI action (via _ToggleBand), so animate
  2746. BOOL CReBar::_MaximizeBand(UINT uBand, BOOL fIdeal, BOOL fAnim)
  2747. {
  2748. int x, dx;
  2749. BOOL fChanged = FALSE;
  2750. PRBB prbbMaximize;
  2751. if (!_IsValidIndex(uBand))
  2752. return FALSE;
  2753. prbbMaximize = _GetBand(uBand);
  2754. if (prbbMaximize->fStyle & RBBS_FIXEDSIZE)
  2755. return FALSE;
  2756. dx = prbbMaximize->cxIdeal + _GetHeaderWidth(prbbMaximize) - prbbMaximize->cx;
  2757. if (fIdeal && dx > 0)
  2758. {
  2759. PRBB prbb;
  2760. // first move the next guy over if possible.
  2761. prbb = _GetNextVisible(prbbMaximize);
  2762. if (prbb && (!_IsBandStartOfRow(prbb)))
  2763. {
  2764. int dxRbb;
  2765. x = _MaxX(prbb);
  2766. // dxRbb is the maximum that prbb can move
  2767. dxRbb = x - prbb->x;
  2768. if (dxRbb > dx)
  2769. {
  2770. // if that's more than enough space, then limit dx
  2771. dxRbb = dx;
  2772. }
  2773. x = prbb->x + dxRbb;
  2774. fChanged |= (fAnim)?_SetBandPosAnim(prbb, x):_SetBandPos(prbb,x);
  2775. dx -= dxRbb;
  2776. }
  2777. if (dx)
  2778. {
  2779. int dxRbb;
  2780. // the one on the right didn't move enough.
  2781. // now move us back
  2782. x = _MinX(prbbMaximize);
  2783. dxRbb = prbbMaximize->x - x;
  2784. if (dxRbb > dx)
  2785. {
  2786. x = prbbMaximize->x - dx;
  2787. }
  2788. fChanged |= (fAnim)?_SetBandPosAnim(prbbMaximize, x):_SetBandPos(prbbMaximize, x);
  2789. }
  2790. }
  2791. else
  2792. {
  2793. x = _MinX(prbbMaximize);
  2794. fChanged |= (fAnim)?_SetBandPosAnim(prbbMaximize, x):_SetBandPos(prbbMaximize, x);
  2795. prbbMaximize = _GetNextVisible(prbbMaximize);
  2796. if (prbbMaximize && !_IsBandStartOfRow(prbbMaximize))
  2797. {
  2798. x = _MaxX(prbbMaximize);
  2799. fChanged |= (fAnim)?_SetBandPosAnim(prbbMaximize, x):_SetBandPos(prbbMaximize, x);
  2800. }
  2801. }
  2802. return fChanged;
  2803. }
  2804. // ----------------------------------------------------------------------------
  2805. //
  2806. // _ToggleBand
  2807. //
  2808. // switches a band between it's maximized and minimized state, based on where
  2809. // the user clicked
  2810. //
  2811. // ----------------------------------------------------------------------------
  2812. void CReBar::_ToggleBand(BOOL fAnim)
  2813. {
  2814. BOOL fDidSomething = FALSE;
  2815. // try to maximize this band. if failed (meaning already maximize)
  2816. // then minimize
  2817. if (CCSendNotify(&_ci, RBN_MINMAX, NULL))
  2818. return;
  2819. fDidSomething = _MaximizeBand(_uCapture, TRUE,fAnim);
  2820. if (!fDidSomething)
  2821. fDidSomething = _MinimizeBand(_uCapture,fAnim);
  2822. if (fDidSomething)
  2823. CCPlaySound(TEXT("ShowBand"));
  2824. }
  2825. // ----------------------------------------------------------------------------
  2826. //
  2827. // _SetCursor
  2828. //
  2829. // sets the cursor to either the move cursor or the arrow cursor, depending
  2830. // on whether or not the cursor is on a band's caption
  2831. //
  2832. // ----------------------------------------------------------------------------
  2833. void CReBar::_SetCursor(int x, int y, BOOL fMouseDown)
  2834. {
  2835. int iBand;
  2836. RBHITTESTINFO rbht;
  2837. rbht.pt.x = x;
  2838. rbht.pt.y = y;
  2839. iBand = _HitTest(&rbht);
  2840. if (rbht.flags == RBHT_GRABBER)
  2841. {
  2842. if (fMouseDown)
  2843. SetCursor(LoadCursor(HINST_THISDLL, (_ci.style & CCS_VERT) ? MAKEINTRESOURCE(IDC_DIVOPENV) : MAKEINTRESOURCE(IDC_DIVOPEN) ));
  2844. else
  2845. SetCursor(LoadCursor(NULL, (_ci.style & CCS_VERT) ? IDC_SIZENS : IDC_SIZEWE));
  2846. return;
  2847. }
  2848. if ((fMouseDown) && ((rbht.flags == RBHT_GRABBER) || (rbht.flags == RBHT_CAPTION) && _ShouldDrawGripper(_GetBand(iBand))))
  2849. {
  2850. // No longer IE3 compatible, per RichSt
  2851. SetCursor(LoadCursor(NULL, IDC_SIZEALL));
  2852. return;
  2853. }
  2854. SetCursor(LoadCursor(NULL, IDC_ARROW));
  2855. }
  2856. // adjust's a band's (prbb) starting location to the given location
  2857. BOOL CReBar::_SetBandPos(PRBB prbb, int xLeft)
  2858. {
  2859. RECT rc;
  2860. PRBB prbbPrev;
  2861. int xRight;
  2862. BOOL fBandBorders = _UseBandBorders();
  2863. BOOL fRight;
  2864. if (!prbb)
  2865. return (FALSE);
  2866. ASSERT(!(prbb->fStyle & RBBS_HIDDEN));
  2867. ASSERT((xLeft >= 0)); // We've got problems if someone is trying to set us negative
  2868. if (prbb->x == xLeft)
  2869. return(FALSE);
  2870. prbbPrev = _GetPrevVisible(prbb);
  2871. // band has moved within valid range -- adjust band sizes and redraw
  2872. // window
  2873. fRight = (prbb->x < xLeft);
  2874. SetRect(&rc, prbb->x - _mBand.cxLeftWidth, prbb->y- _mBand.cyTopHeight, prbb->x + prbb->cxMin + _mBand.cxRightWidth, prbb->y + prbb->cy + _mBand.cyBottomHeight);
  2875. xRight = prbb->x + prbb->cx;
  2876. prbb->x = xLeft;
  2877. prbb->cx = xRight - xLeft;
  2878. prbb->cxRequest = prbb->cx;
  2879. if (fRight)
  2880. {
  2881. if (prbbPrev)
  2882. {
  2883. //moving right
  2884. prbbPrev->cx = prbb->x - _mBand.cxRightWidth - prbbPrev->x - _mBand.cxLeftWidth;
  2885. if (fBandBorders)
  2886. {
  2887. prbbPrev->cx -= g_cxEdge;
  2888. rc.left -= g_cxEdge;
  2889. }
  2890. rc.left = rc.left - _mBand.cxRightWidth;
  2891. prbbPrev->cxRequest = prbbPrev->cx;
  2892. //check for compacting of following bands
  2893. while (prbb && prbb->cx < prbb->cxMin)
  2894. {
  2895. prbb->cx = prbb->cxMin;
  2896. prbb->cxRequest = prbb->cx;
  2897. xLeft += _BandWidth(prbb);
  2898. prbb = _GetNextVisible(prbb); // prbb++;
  2899. if (prbb)
  2900. {
  2901. xRight = prbb->x + prbb->cx;
  2902. prbb->x = xLeft;
  2903. prbb->cx = xRight - xLeft;
  2904. prbb->cxRequest = prbb->cx;
  2905. }
  2906. }
  2907. if (prbb)
  2908. rc.right = xLeft + prbb->cxMin + _mBand.cxRightWidth;
  2909. }
  2910. }
  2911. else
  2912. {
  2913. //moving left
  2914. //check for compacting of preceding bands
  2915. while (prbbPrev)
  2916. {
  2917. if (fBandBorders)
  2918. xLeft -= g_cxEdge;
  2919. prbbPrev->cx = xLeft - prbbPrev->x - _mBand.cxLeftWidth - _mBand.cxRightWidth;
  2920. prbbPrev->cxRequest = prbbPrev->cx;
  2921. if (prbbPrev->cx < prbbPrev->cxMin)
  2922. {
  2923. prbbPrev->x = xLeft - _mBand.cxLeftWidth - _mBand.cxRightWidth - prbbPrev->cxMin;
  2924. prbbPrev->cx = prbbPrev->cxMin;
  2925. prbbPrev->cxRequest = prbbPrev->cx;
  2926. xLeft = prbbPrev->x;
  2927. prbbPrev = _GetPrevVisible(prbbPrev); // prbbPrev--
  2928. }
  2929. else
  2930. {
  2931. break;
  2932. }
  2933. }
  2934. rc.left = xLeft - _mBand.cxLeftWidth - _mBand.cxRightWidth;
  2935. }
  2936. if (fBandBorders)
  2937. rc.bottom += g_cyEdge / 2;
  2938. _ResizeChildren();
  2939. if (_InvalidateRect(&rc))
  2940. {
  2941. UpdateWindow(_ci.hwnd);
  2942. }
  2943. return(TRUE);
  2944. }
  2945. BOOL CReBar::_SetBandPosAnim(PRBB prbb, int xLeft)
  2946. {
  2947. int ctr=0,dx, xCur = prbb->x;
  2948. DWORD dwStartTime;
  2949. if (xCur == xLeft)
  2950. return FALSE;
  2951. dwStartTime=GetTickCount();
  2952. dx = (xLeft - xCur)/ANIMSTEPS;
  2953. if (dx != 0)
  2954. {
  2955. if (xCur < xLeft)
  2956. {
  2957. // move right
  2958. for (; xCur < (xLeft-dx); ctr++,xCur += dx)
  2959. {
  2960. _SetBandPos(prbb, xCur);
  2961. // If something caused us to take more than 10 times the time we
  2962. // should be, break out, and let the final _SetBandPos finish
  2963. if (GetTickCount() - dwStartTime > 10*ANIMSTEPS*ANIMSTEPTIME)
  2964. break;
  2965. Sleep(ANIMSTEPTIME);
  2966. // Start slowing us down 80% of the way through
  2967. // Cut speed by 2/3 each time, but never move less than 4 pixels
  2968. if ((ctr >= 4*ANIMSTEPS/5) && (dx >= 4))
  2969. dx = 2*dx/3;
  2970. }
  2971. }
  2972. else
  2973. {
  2974. // move left
  2975. for (; xCur > (xLeft-dx); ctr++, xCur += dx)
  2976. {
  2977. _SetBandPos(prbb, xCur);
  2978. if (GetTickCount() > (dwStartTime + 10*ANIMSTEPS*ANIMSTEPTIME))
  2979. break;
  2980. Sleep(ANIMSTEPTIME);
  2981. if ((ctr >= 4*ANIMSTEPS/5) && (dx <= -4))
  2982. dx = 2*dx/3;
  2983. }
  2984. }
  2985. }
  2986. _SetBandPos(prbb, xLeft);
  2987. return TRUE;
  2988. }
  2989. void CReBar::_OnBeginDrag(UINT uBand)
  2990. {
  2991. _uCapture = uBand;
  2992. _ptLastDragPos.x = -1;
  2993. _ptLastDragPos.y = -1;
  2994. if (_uCapture == -1)
  2995. {
  2996. // aborting drag
  2997. _fParentDrag = FALSE;
  2998. _fFullOnDrag = FALSE;
  2999. // we could have unwrapped rows, in which case, we need to grow bands (but not wrap)
  3000. // to fill the empty space.
  3001. if (_ci.style & RBS_AUTOSIZE)
  3002. {
  3003. _SizeBandsToRect(NULL);
  3004. _SizeBandsToRowHeight();
  3005. }
  3006. }
  3007. else
  3008. {
  3009. _fParentDrag = TRUE;
  3010. _fFullOnDrag = TRUE;
  3011. }
  3012. }
  3013. int minmax(int x, int min, int max)
  3014. {
  3015. x = max(x, min);
  3016. x = min(x, max);
  3017. return x;
  3018. }
  3019. // pass the break bit along
  3020. void CReBar::_PassBreak(PRBB prbbSrc, PRBB prbbDest)
  3021. {
  3022. if (prbbSrc->fStyle & RBBS_BREAK)
  3023. {
  3024. prbbSrc->fStyle &= ~RBBS_BREAK;
  3025. if (prbbDest)
  3026. prbbDest->fStyle |= RBBS_BREAK;
  3027. }
  3028. }
  3029. void CReBar::_GetClientRect(LPRECT prc)
  3030. {
  3031. GetClientRect(_ci.hwnd, prc);
  3032. if (_ci.style & CCS_VERT)
  3033. FlipRect(prc);
  3034. }
  3035. //tells if prbb is the first band and the next band is fixed.
  3036. // if this is true then we need to do a recalc if we move prbb
  3037. BOOL CReBar::_RecalcIfMove(PRBB prbb)
  3038. {
  3039. if (_EnumBand(0, RBBS_HIDDEN) == prbb)
  3040. {
  3041. PRBB prbbNext = _GetNextVisible(prbb);
  3042. if (prbbNext && prbbNext->fStyle & RBBS_FIXEDSIZE)
  3043. return TRUE;
  3044. }
  3045. return FALSE;
  3046. }
  3047. // find out if the prbb at it's min height could fit within the current window
  3048. // if all the others shrunk as much as they could
  3049. BOOL CReBar::_RoomForBandVert(PRBB prbbSkip)
  3050. {
  3051. int yExtra = 0;
  3052. UINT cBands = _cBands;
  3053. int iNewRowHeight = prbbSkip->cyMinChild;
  3054. PRBB prbb = _GetBand(0);
  3055. if (_UseBandBorders())
  3056. iNewRowHeight += g_cyEdge;
  3057. iNewRowHeight += _mBand.cyBottomHeight + _mBand.cyTopHeight;
  3058. while (prbb)
  3059. {
  3060. if (_IsBandVisible(prbb))
  3061. {
  3062. if (_IsBandStartOfRow(prbb))
  3063. {
  3064. yExtra += _GetRowHeightExtra(&prbb, prbbSkip);
  3065. if (yExtra >= iNewRowHeight)
  3066. return TRUE;
  3067. continue;
  3068. }
  3069. }
  3070. prbb = _GetNextVisible(prbb);
  3071. }
  3072. return FALSE;
  3073. }
  3074. // we should make a new row if prbb isn't the start of the row already
  3075. // and we're off the end of the control
  3076. //
  3077. // poweruser hack of holding the control down will make a new row if you hit the border between lines
  3078. BOOL CReBar::_MakeNewRow(PRBB prbb, int y)
  3079. {
  3080. BOOL fRet = FALSE;
  3081. RECT rc;
  3082. // if we're off the top of the control, move this band to the end (or beginning)
  3083. _GetClientRect(&rc);
  3084. InflateRect(&rc, 0, -g_cyEdge);
  3085. if (!(_ci.style & RBS_FIXEDORDER))
  3086. {
  3087. int iOutsideLimit = g_cyEdge * 4; // how far do you have to move outside the bounds of the window to force a new row
  3088. if (_RoomForBandVert(prbb))
  3089. {
  3090. iOutsideLimit = -g_cyEdge;
  3091. }
  3092. if (y < rc.top - iOutsideLimit)
  3093. { // top of control
  3094. PRBB prbbNext = _EnumBand(0, RBBS_HIDDEN);
  3095. if (prbbNext == prbb)
  3096. prbbNext = _GetNextVisible(prbb);
  3097. fRet |= _MoveBand(_BandToIndex(prbb), 0);
  3098. ASSERT(prbbNext <= _GetLastBand());
  3099. if (prbbNext && !(prbbNext->fStyle & RBBS_BREAK))
  3100. {
  3101. prbbNext->fStyle |= RBBS_BREAK;
  3102. fRet = TRUE;
  3103. }
  3104. }
  3105. else if (y >= rc.bottom)
  3106. {
  3107. // move to the end
  3108. if (!(prbb->fStyle & RBBS_BREAK))
  3109. {
  3110. prbb->fStyle |= RBBS_BREAK;
  3111. fRet = TRUE;
  3112. }
  3113. prbb->cyChild = prbb->cyMinChild;
  3114. fRet |= _MoveBand(_BandToIndex(prbb), _cBands-1);
  3115. }
  3116. else
  3117. {
  3118. // create a new row in the middle
  3119. if (!_IsBandStartOfRow(prbb) && GetAsyncKeyState(VK_CONTROL) < 0)
  3120. {
  3121. // make sure they're on different rows and on the border
  3122. if (y > prbb->y + prbb->cy + _mBand.cyBottomHeight &&
  3123. y < prbb->y + prbb->cy + _mBand.cyBottomHeight + g_cyEdge)
  3124. {
  3125. PRBB prbbLast = _GetLastInRow(prbb, FALSE); // move it right before the first in this row
  3126. prbb->fStyle |= RBBS_BREAK;
  3127. _MoveBand(_BandToIndex(prbb), _BandToIndex(prbbLast));
  3128. fRet = TRUE;
  3129. }
  3130. }
  3131. }
  3132. }
  3133. else
  3134. {
  3135. // fixed guys can't move, they can only make a new row
  3136. if (!_IsBandStartOfRow(prbb))
  3137. {
  3138. if (y > prbb->y + prbb->cy + _mBand.cyBottomHeight)
  3139. {
  3140. prbb->fStyle |= RBBS_BREAK;
  3141. fRet = TRUE;
  3142. }
  3143. }
  3144. }
  3145. return fRet;
  3146. }
  3147. // ----------------------------------------------------------------------------
  3148. //
  3149. // _DragBand
  3150. //
  3151. // resizes the currently tracked band based on the user's mouse movement as
  3152. // indicated in the given point (x, y)
  3153. //
  3154. // ----------------------------------------------------------------------------
  3155. void CReBar::_DragBand(int x, int y)
  3156. {
  3157. PRBB prbb = _GetBand(_uCapture);
  3158. UINT iHit = -1;
  3159. // Do nothing if the mouse didn't actually move
  3160. // otherwise, multiple WM_MOUSEMOVE messages will be generated by resizing windows
  3161. if (x==_ptLastDragPos.x && y==_ptLastDragPos.y)
  3162. return;
  3163. else
  3164. {
  3165. _ptLastDragPos.x = x;
  3166. _ptLastDragPos.y = y;
  3167. }
  3168. if (_ci.style & CCS_VERT)
  3169. SWAP(x,y, int);
  3170. if (!_fFullOnDrag)
  3171. {
  3172. // don't begin dragging until mouse is moved outside of an edge-thick
  3173. // tolerance border
  3174. if ((y < (_ptCapture.y - g_cyEdge)) || (y > (_ptCapture.y + g_cyEdge)) ||
  3175. (x < (_ptCapture.x - g_cxEdge)) || (x > (_ptCapture.x + g_cxEdge)))
  3176. {
  3177. // did parent abort?
  3178. if (_SendNotify(_uCapture, RBN_BEGINDRAG))
  3179. return;
  3180. if (!_IsValidBand(prbb))
  3181. {
  3182. // somebody responded to RBN_BEGINDRAG by nuking bands; bail
  3183. return;
  3184. }
  3185. _fFullOnDrag = TRUE;
  3186. }
  3187. else
  3188. return;
  3189. }
  3190. // bail for right now on fRecalcIfMoved (ie3 did the same thing). nice feature for later
  3191. if (!_CanBandMove(prbb))
  3192. return;
  3193. /* what type of drag operation depends on what we drag hit on.
  3194. if we hit on the band before us, or ourself
  3195. and it's the same row
  3196. and we're not the first band of the row
  3197. then we just to a size move
  3198. otherwise if we hit on a band then we do a move
  3199. if we hit outside of any band, we grow to meet the cursor
  3200. in all of the above, a band that's hit must be NOT fixed and not hidden
  3201. */
  3202. BOOL fResize = FALSE;
  3203. RECT rc;
  3204. _GetClientRect(&rc);
  3205. if (y < rc.bottom - 1)
  3206. {
  3207. iHit = _InternalHitTest(NULL, x, y);
  3208. }
  3209. if (iHit != -1)
  3210. {
  3211. PRBB prbbPrev = _GetPrevVisible(prbb);
  3212. PRBB prbbHit = _GetBand(iHit);
  3213. prbbHit = _GetPrev(++prbbHit, RBBS_FIXEDSIZE); // skip over fixed guys
  3214. if (prbbHit)
  3215. {
  3216. ASSERT(prbbHit >= _rbbList);
  3217. // this should never happen.
  3218. if (prbbHit < _rbbList)
  3219. return;
  3220. iHit = _BandToIndex(prbbHit);
  3221. // if we're on the same row ... and it's us or the previous one
  3222. if (prbbHit->y == prbb->y && (prbbHit == prbb || prbbHit == prbbPrev))
  3223. {
  3224. if (x < _GetGripperWidth() + _mBand.cxLeftWidth &&
  3225. !(_ci.style & RBS_FIXEDORDER))
  3226. {
  3227. // special case dragging to the far left. there's no other way to move to first in row
  3228. _PassBreak(prbbHit, prbb);
  3229. if (_MoveBand(_uCapture, iHit))
  3230. fResize = TRUE;
  3231. }
  3232. else if (!_IsBandStartOfRow(prbb))
  3233. {
  3234. // and we're not the first band of the row
  3235. // then just size it
  3236. int xLeft = _xStart + (x - _ptCapture.x);
  3237. xLeft = minmax(xLeft, _MinX(prbb), _MaxX(prbb));
  3238. _DragSize(xLeft);
  3239. }
  3240. }
  3241. else if (_MakeNewRow(prbb, y))
  3242. {
  3243. fResize = TRUE;
  3244. }
  3245. else
  3246. { // otherwise do a move if we're not in a fixed order
  3247. if (!(_ci.style & RBS_FIXEDORDER))
  3248. {
  3249. if (iHit < _BandToIndex(prbb))
  3250. iHit++; // +1 because if you hit a band, you're moving to the right of him
  3251. // if one with a break is moving, the next one inherits the break
  3252. _PassBreak(prbb, _GetNextVisible(prbb));
  3253. _MoveBand(_uCapture, iHit);
  3254. }
  3255. else
  3256. {
  3257. if (iHit < _BandToIndex(prbb))
  3258. _PassBreak(prbb, _GetNextVisible(prbb));
  3259. }
  3260. fResize = TRUE;
  3261. }
  3262. }
  3263. }
  3264. else if (_MakeNewRow(prbb, y))
  3265. {
  3266. fResize = TRUE;
  3267. }
  3268. if (fResize)
  3269. {
  3270. _Resize(FALSE);
  3271. _AutoSize();
  3272. }
  3273. }
  3274. HPALETTE CReBar::_SetPalette(HPALETTE hpal)
  3275. {
  3276. HPALETTE hpalOld = _hpal;
  3277. if (hpal != hpalOld)
  3278. {
  3279. if (!_fUserPalette)
  3280. {
  3281. if (_hpal)
  3282. {
  3283. DeleteObject(_hpal);
  3284. _hpal = NULL;
  3285. }
  3286. }
  3287. if (hpal)
  3288. {
  3289. _fUserPalette = TRUE;
  3290. _hpal = hpal;
  3291. }
  3292. _InvalidateRect(NULL);
  3293. }
  3294. return hpalOld;
  3295. }
  3296. // ----------------------------------------------------------------------------
  3297. //
  3298. // _OnDestroy
  3299. //
  3300. // frees all memory allocated by rebar
  3301. //
  3302. // ----------------------------------------------------------------------------
  3303. BOOL CReBar::_OnDestroy()
  3304. {
  3305. UINT c = _cBands;
  3306. _SetRedraw(FALSE);
  3307. _SetRecalc(FALSE);
  3308. while (c--)
  3309. _DeleteBand(c);
  3310. // so that we don't keep trying to autosize
  3311. _ci.style &= ~RBS_AUTOSIZE;
  3312. ASSERT(!_rbbList);
  3313. _SetPalette(NULL);
  3314. if (_hFont && _fFontCreated)
  3315. {
  3316. DeleteObject(_hFont);
  3317. }
  3318. if ((_ci.style & RBS_TOOLTIPS) && IsWindow(_hwndToolTips))
  3319. {
  3320. DestroyWindow (_hwndToolTips);
  3321. _hwndToolTips = NULL;
  3322. }
  3323. // don't destroy the himl 'cause it's given to us by app
  3324. if (_hDragProxy)
  3325. DestroyDragProxy(_hDragProxy);
  3326. if (_hTheme)
  3327. CloseThemeData(_hTheme);
  3328. return TRUE;
  3329. }
  3330. // ----------------------------------------------------------------------------
  3331. //
  3332. // _InitPaletteHack
  3333. //
  3334. // this is a hack to use the halftone palette until we have a way of asking
  3335. // the client what palette they are using
  3336. //
  3337. // ----------------------------------------------------------------------------
  3338. void CReBar::_InitPaletteHack()
  3339. {
  3340. if (!_fUserPalette)
  3341. {
  3342. HDC hdc = CreateCompatibleDC(NULL);
  3343. if (hdc)
  3344. {
  3345. if (GetDeviceCaps(hdc, BITSPIXEL) <= 8)
  3346. {
  3347. if (_hpal)
  3348. DeleteObject(_hpal);
  3349. _hpal = CreateHalftonePalette(hdc); // this is a hack
  3350. }
  3351. DeleteDC(hdc);
  3352. }
  3353. }
  3354. }
  3355. UINT CReBar::_IDToIndex(UINT id)
  3356. {
  3357. UINT i;
  3358. REBARBANDINFO rbbi;
  3359. rbbi.cbSize = sizeof(REBARBANDINFO);
  3360. rbbi.fMask = RBBIM_ID;
  3361. for (i = 0; i < _cBands; i++)
  3362. {
  3363. if (_GetBandInfo(i, &rbbi))
  3364. {
  3365. if (rbbi.wID == (WORD)id)
  3366. return i;
  3367. }
  3368. }
  3369. return -1;
  3370. }
  3371. int CReBar::_GetRowHeight(UINT uRow)
  3372. {
  3373. if (uRow < _cBands)
  3374. {
  3375. // move back to start of line
  3376. PRBB prbbFirst = _GetFirstInRow(_GetBand(uRow));
  3377. PRBB prbbLast = _GetLastInRow(_GetBand(uRow), FALSE);
  3378. return _GetLineHeight(_BandToIndex(prbbFirst), _BandToIndex(prbbLast));
  3379. }
  3380. return -1;
  3381. }
  3382. // fOneStep == whether to allow only one cyIntegral or as many as will fit to
  3383. // fill dy
  3384. int CReBar::_GrowBand(PRBB prbb, int dy, BOOL fResize, int iLineHeight)
  3385. {
  3386. int dyBand = 0; // how much the band changes
  3387. if (prbb->cyIntegral)
  3388. {
  3389. if (iLineHeight == -1)
  3390. {
  3391. iLineHeight = _GetRowHeight(_BandToIndex(prbb));
  3392. }
  3393. // get the proposed new size
  3394. int cyDesiredHeight = min(iLineHeight + dy, prbb->cyMaxChild) - prbb->cyMinChild;
  3395. // Limit new height to band's min and max
  3396. int iNumOfIntegrals = max(cyDesiredHeight / prbb->cyIntegral, 0);
  3397. int cyNewHeight = prbb->cyMinChild + (iNumOfIntegrals * prbb->cyIntegral);
  3398. DebugMsg(TF_REBAR, TEXT("REBAR._gb Band {%d}, Line Height {%d} Desired Height {%d} New Height {%d} Old Height {%d} dy {%d}"), _BandToIndex(prbb), iLineHeight, cyDesiredHeight + prbb->cyMinChild, cyNewHeight, prbb->cyChild, dy);
  3399. dyBand = cyNewHeight - prbb->cyChild;
  3400. prbb->cyChild = cyNewHeight;
  3401. if (fResize)
  3402. {
  3403. _Resize(TRUE);
  3404. }
  3405. }
  3406. return dyBand;
  3407. }
  3408. // returns the delta in size that the rebar is from prc.
  3409. // taking into account vertical mode
  3410. int CReBar::_SizeDifference(LPRECT prc)
  3411. {
  3412. int d;
  3413. d = (_IsVertical() ? RECTWIDTH(*prc) : RECTHEIGHT(*prc))
  3414. - _cy;
  3415. return d;
  3416. }
  3417. // returns how much this row could shrink
  3418. int CReBar::_GetRowHeightExtra(PRBB *pprbb, PRBB prbbSkip)
  3419. {
  3420. // this is the largest minimum child size for the row.
  3421. // even if something is not at it's min size, if it's smaller than this
  3422. // then it doesn't matter because someone else on that row can't be sized
  3423. int yLimit = 0;
  3424. int yExtra = 0;
  3425. PRBB prbb = *pprbb;
  3426. while (prbb)
  3427. {
  3428. if (prbb != prbbSkip)
  3429. {
  3430. int yMin;
  3431. int yExtraBand = 0;
  3432. // the min height is the cyChild if it's not variable height
  3433. yMin = prbb->cyChild;
  3434. if (prbb->fStyle & RBBS_VARIABLEHEIGHT)
  3435. {
  3436. // if it is variable height, and there's still room to shrink, then cyMinChild is
  3437. // the minimum.
  3438. if (prbb->cyChild >= prbb->cyMinChild + prbb->cyIntegral)
  3439. {
  3440. yMin = prbb->cyMinChild;
  3441. yExtraBand = prbb->cyChild - prbb->cyMinChild;
  3442. }
  3443. }
  3444. if (yMin == yLimit)
  3445. {
  3446. if (yExtraBand > yExtra)
  3447. yExtra = yExtraBand;
  3448. }
  3449. else if (yMin > yLimit)
  3450. {
  3451. yExtra = yExtraBand;
  3452. }
  3453. }
  3454. prbb = _GetNextVisible(prbb);
  3455. }
  3456. *pprbb = prbb;
  3457. return yExtra;
  3458. }
  3459. // are allt he bands at the minimum size?
  3460. BOOL CReBar::_BandsAtMinHeight()
  3461. {
  3462. BOOL fRet = TRUE;
  3463. PRBB prbb = _GetBand(0);
  3464. while (prbb)
  3465. {
  3466. if (_IsBandVisible(prbb))
  3467. {
  3468. if (_IsBandStartOfRow(prbb))
  3469. {
  3470. fRet = _IsRowAtMinHeight(&prbb);
  3471. if (!fRet)
  3472. break;
  3473. continue;
  3474. }
  3475. }
  3476. prbb = _GetNextVisible(prbb);
  3477. }
  3478. return fRet;
  3479. }
  3480. // this is like _SizeBarToRect except that it resizes the actual bands if they
  3481. // are VARIABLEHEIGHT
  3482. BOOL CReBar::_SizeBandsToRect(LPRECT prc)
  3483. {
  3484. int dy;
  3485. RECT rc;
  3486. BOOL fRedrawOld;
  3487. BOOL fChanged = FALSE;
  3488. // Turn recalc on to ensure calculations actually do something
  3489. // (else we can loop forever since _cy never actually changes).
  3490. _SetRecalc(TRUE);
  3491. if (prc)
  3492. {
  3493. rc = *prc;
  3494. }
  3495. else
  3496. {
  3497. GetClientRect(_ci.hwnd, &rc);
  3498. }
  3499. DebugMsg(TF_REBAR, TEXT("REBAR._sbandstr starting rect is {%d, %d, %d, %d}"), rc.left, rc.top, rc.right, rc.bottom);
  3500. fRedrawOld = _SetRedraw(FALSE);
  3501. dy = _SizeDifference(&rc);
  3502. for (int iAttempt = 0; (iAttempt < 2) && dy; iAttempt++)
  3503. {
  3504. PRBB prbb = _rbbList;
  3505. BOOL fValidBand = FALSE;
  3506. while ((prbb - _rbbList < (int)_cBands) && !fValidBand)
  3507. {
  3508. if (!(prbb->fStyle & RBBS_HIDDEN) && (prbb->fStyle & RBBS_VARIABLEHEIGHT) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  3509. {
  3510. fValidBand = TRUE;
  3511. }
  3512. else
  3513. {
  3514. prbb++;
  3515. }
  3516. }
  3517. if ((prbb - _rbbList < (int)_cBands) && !(prbb->fStyle & RBBS_HIDDEN) && (prbb->fStyle & RBBS_VARIABLEHEIGHT) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  3518. {
  3519. PRBB prbbMaxIntegral = prbb;
  3520. do {
  3521. if (!(prbb->fStyle & RBBS_HIDDEN) && (prbb->fStyle & RBBS_VARIABLEHEIGHT) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  3522. {
  3523. if (prbbMaxIntegral->cyIntegral < prbb->cyIntegral)
  3524. {
  3525. prbbMaxIntegral = prbb;
  3526. }
  3527. }
  3528. prbb++;
  3529. }
  3530. while ((prbb - _rbbList < (int)_cBands) && !_IsBandStartOfRow(prbb));
  3531. int old_cyChild = prbbMaxIntegral->cyChild;
  3532. if (prbbMaxIntegral->cyIntegral)
  3533. {
  3534. _GrowBand(prbbMaxIntegral, dy, FALSE, -1);
  3535. }
  3536. else
  3537. {
  3538. prbbMaxIntegral->cyChild += dy;
  3539. }
  3540. if (prbbMaxIntegral->cyChild != old_cyChild)
  3541. {
  3542. fChanged = TRUE;
  3543. }
  3544. UINT uFirst = _BandToIndex(_GetFirstInRow(prbbMaxIntegral));
  3545. UINT uLast = _BandToIndex(_GetLastInRow(prbbMaxIntegral, FALSE));
  3546. for (UINT uBand = uFirst; uBand <= uLast; uBand++)
  3547. {
  3548. prbb = _GetBand(uBand);
  3549. // if it's a variable height kind of guy, grow/shrink it
  3550. if ((prbb != prbbMaxIntegral) && !(prbb->fStyle & RBBS_HIDDEN) && (prbb->fStyle & RBBS_VARIABLEHEIGHT) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  3551. {
  3552. old_cyChild = prbb->cyChild;
  3553. if (prbb->cyIntegral && prbbMaxIntegral->cyIntegral)
  3554. {
  3555. prbb->cyChild = prbbMaxIntegral->cyChild - ((prbbMaxIntegral->cyChild - prbb->cyMinChild) % prbb->cyIntegral);
  3556. }
  3557. else
  3558. {
  3559. prbb->cyChild = prbbMaxIntegral->cyChild;
  3560. }
  3561. if (prbb->cyChild != old_cyChild)
  3562. {
  3563. fChanged = TRUE;
  3564. }
  3565. }
  3566. }
  3567. for (UINT uBand = uLast + 1; uBand < _cBands; uBand++)
  3568. {
  3569. prbb = _GetBand(uBand);
  3570. if (!(prbb->fStyle & RBBS_HIDDEN) && (prbb->fStyle & RBBS_VARIABLEHEIGHT) && !(prbb->fStyle & RBBS_FIXEDSIZE))
  3571. {
  3572. if (prbb->cyChild != prbb->cyMinChild)
  3573. {
  3574. prbb->cyChild = prbb->cyMinChild;
  3575. fChanged = TRUE;
  3576. }
  3577. }
  3578. }
  3579. }
  3580. if (fChanged)
  3581. {
  3582. _Resize(TRUE);
  3583. dy = _SizeDifference(&rc);
  3584. }
  3585. }
  3586. _SetRedraw(fRedrawOld);
  3587. return fChanged;
  3588. }
  3589. void CReBar::_SizeBandToRowHeight(int i, int uRowHeight)
  3590. {
  3591. PRBB prbb = _GetBand(i);
  3592. if (prbb && prbb->fStyle & RBBS_VARIABLEHEIGHT)
  3593. {
  3594. if (uRowHeight == -1)
  3595. uRowHeight = _GetRowHeight(i);
  3596. if (uRowHeight > prbb->cyChild)
  3597. {
  3598. _GrowBand(prbb, 0, TRUE, uRowHeight);
  3599. }
  3600. }
  3601. }
  3602. // in the process of sizing, one band in a row of several bands might have
  3603. // grow pretty large. we need to let the other bands have a chance to fill
  3604. // the extra space as well
  3605. void CReBar::_SizeBandsToRowHeight()
  3606. {
  3607. UINT i;
  3608. int iRowHeight = -1;
  3609. for (i = 0; i < _cBands; i++)
  3610. {
  3611. PRBB prbb = _GetBand(i);
  3612. if (prbb->fStyle & RBBS_HIDDEN)
  3613. continue;
  3614. if (_IsBandStartOfRow(prbb))
  3615. iRowHeight = _GetRowHeight(i);
  3616. _SizeBandToRowHeight(i, iRowHeight);
  3617. }
  3618. }
  3619. BOOL CReBar::_OkayToChangeBreak(PRBB prbb, UINT uMsg)
  3620. {
  3621. NMREBARAUTOBREAK nm;
  3622. nm.uBand = _BandToIndex(prbb);
  3623. nm.wID = prbb->wID;
  3624. nm.lParam = prbb->lParam;
  3625. nm.uMsg = uMsg;
  3626. nm.fStyleCurrent = prbb->fStyle;
  3627. nm.fAutoBreak = TRUE;
  3628. CCSendNotify(&_ci, RBN_AUTOBREAK, &nm.hdr);
  3629. return nm.fAutoBreak;
  3630. }
  3631. // this will add/remove rebar band breaks to get to the requested size.
  3632. // it returns TRUE/FALSE whether something was done or not.
  3633. LRESULT CReBar::_SizeBarToRect(DWORD dwFlags, LPRECT prc)
  3634. {
  3635. BOOL fChanged = FALSE;
  3636. RECT rc;
  3637. BOOL fRedrawOld = _SetRedraw(FALSE);
  3638. if (!prc)
  3639. {
  3640. GetClientRect(_ci.hwnd, &rc);
  3641. prc = &rc;
  3642. }
  3643. if (_cBands)
  3644. {
  3645. int c;
  3646. UINT cBands = _cBands;
  3647. BOOL fRearrangeBands = (_cBands > 0);
  3648. BOOL fGrowing = TRUE;
  3649. // if we're shrinking the rebar, we first want to shrink the bands before we start
  3650. // removing breaks
  3651. c = _SizeDifference(prc);
  3652. if (c < 0)
  3653. fGrowing = FALSE;
  3654. fChanged = _SizeBandsToRect(prc);
  3655. if (!fGrowing && !_BandsAtMinHeight())
  3656. {
  3657. // if we're shrinking and all the bands are not down to
  3658. // the minimum height, don't try doing any of the breaking stuff
  3659. goto Bail;
  3660. }
  3661. while (fRearrangeBands)
  3662. {
  3663. int cyRowHalf = _GetRowHeight(_cBands-1) / 2 ;
  3664. REBARBANDINFO rbbi;
  3665. PRBB prbb;
  3666. fRearrangeBands = FALSE;
  3667. rbbi.cbSize = sizeof(REBARBANDINFO);
  3668. rbbi.fMask = RBBIM_STYLE;
  3669. c = _SizeDifference(prc);
  3670. if (c < -cyRowHalf)
  3671. {
  3672. // we've shrunk the rebar, try to remove breaks
  3673. while (--cBands)
  3674. {
  3675. prbb = _GetBand(cBands);
  3676. if (prbb->fStyle & RBBS_HIDDEN)
  3677. continue;
  3678. if ((prbb->fStyle & RBBS_BREAK) && (_OkayToChangeBreak(prbb, RBAB_AUTOSIZE)))
  3679. {
  3680. fChanged = TRUE;
  3681. fRearrangeBands = TRUE;
  3682. rbbi.fStyle = prbb->fStyle & ~RBBS_BREAK;
  3683. _SetBandInfo(cBands, &rbbi, TRUE);
  3684. break;
  3685. }
  3686. }
  3687. }
  3688. else if (c > cyRowHalf)
  3689. {
  3690. // we're enlarging the rebar
  3691. while (--cBands)
  3692. {
  3693. prbb = _GetBand(cBands);
  3694. if (prbb->fStyle & RBBS_HIDDEN)
  3695. continue;
  3696. if ((!(prbb->fStyle & (RBBS_BREAK | RBBS_FIXEDSIZE))) && (_OkayToChangeBreak(prbb, RBAB_AUTOSIZE)))
  3697. {
  3698. // no break here, add it
  3699. fChanged = TRUE;
  3700. fRearrangeBands = TRUE;
  3701. rbbi.fStyle = (prbb->fStyle | RBBS_BREAK);
  3702. _SetBandInfo(cBands, &rbbi, TRUE);
  3703. break;
  3704. }
  3705. }
  3706. }
  3707. }
  3708. // if we did as much breaking as we could
  3709. // and we walked all the way down to the 0th band (we start at the Nth band)
  3710. // then we try to grow the bands that are VARIABLEHEIGHT
  3711. // for fGrowing, see comment at top of function
  3712. //
  3713. // wedo the % because cBands == _cBands if we didn't go through
  3714. // any of the breaking loops at all
  3715. if (!(cBands % _cBands) && fGrowing)
  3716. fChanged |= _SizeBandsToRect(prc);
  3717. }
  3718. Bail:
  3719. _SizeBandsToRowHeight();
  3720. _SetRedraw(fRedrawOld);
  3721. if (prc && (dwFlags & RBSTR_CHANGERECT))
  3722. {
  3723. if (_IsVertical())
  3724. {
  3725. prc->right = prc->left + _cy;
  3726. }
  3727. else
  3728. {
  3729. prc->bottom = prc->top + _cy;
  3730. }
  3731. }
  3732. return (LRESULT)fChanged;
  3733. }
  3734. void CReBar::_AutoSize()
  3735. {
  3736. NMRBAUTOSIZE nm;
  3737. // if this is an internal autosize call, but we're not in autosize mode
  3738. // do nothing
  3739. if (!(_ci.style & RBS_AUTOSIZE))
  3740. return;
  3741. GetClientRect(_ci.hwnd, &nm.rcTarget);
  3742. nm.fChanged = (BOOL) _SizeBarToRect(0, &nm.rcTarget);
  3743. GetClientRect(_ci.hwnd, &nm.rcActual);
  3744. CCSendNotify(&_ci, RBN_AUTOSIZE, &nm.hdr);
  3745. }
  3746. LRESULT CReBar::_GetBandBorders(int wParam, LPRECT prc)
  3747. {
  3748. BOOL fBandBorders = _UseBandBorders();
  3749. PRBB prbb = &_rbbList[wParam];
  3750. prc->left = _GetHeaderWidth(prbb);
  3751. if (fBandBorders)
  3752. {
  3753. prc->left += 2*g_cxEdge;
  3754. prc->right = 0;
  3755. prc->top = g_cyEdge/2;
  3756. prc->bottom = g_cyEdge /2;
  3757. }
  3758. else
  3759. {
  3760. prc->right = 0;
  3761. prc->top = 0;
  3762. prc->bottom = 0;
  3763. }
  3764. if (_ci.style & CCS_VERT)
  3765. FlipRect(prc);
  3766. return 0;
  3767. }
  3768. void CReBar::_OnStyleChanged(WPARAM wParam, LPSTYLESTRUCT lpss)
  3769. {
  3770. if (wParam == GWL_STYLE)
  3771. {
  3772. DWORD dwChanged;
  3773. _ci.style = lpss->styleNew;
  3774. dwChanged = (lpss->styleOld ^ lpss->styleNew);
  3775. // update to reflect style change
  3776. if (dwChanged & CCS_VERT)
  3777. {
  3778. DebugMsg(TF_REBAR, TEXT("REBAR._osc ReBar is now {%s}"), (lpss->styleNew & CCS_VERT) ? TEXT("Horizontal") : TEXT("Vertical"));
  3779. UINT i;
  3780. for (i = 0; i < _cBands; i++)
  3781. {
  3782. PRBB prbb = _GetBand(i);
  3783. if (prbb->fStyle & RBBS_HIDDEN)
  3784. continue;
  3785. if (!(lpss->styleNew & CCS_VERT))
  3786. {
  3787. prbb->cyChild = 0;
  3788. _cy = 0;
  3789. }
  3790. _BandCalcMinWidth(prbb);
  3791. }
  3792. }
  3793. if (dwChanged & RBS_REGISTERDROP)
  3794. {
  3795. if (_ci.style & RBS_REGISTERDROP)
  3796. {
  3797. ASSERT(!_hDragProxy);
  3798. _hDragProxy = CreateDragProxy(_ci.hwnd, s_DragCallback, TRUE);
  3799. }
  3800. else
  3801. {
  3802. ASSERT(_hDragProxy);
  3803. DestroyDragProxy(_hDragProxy);
  3804. }
  3805. }
  3806. }
  3807. else if (wParam == GWL_EXSTYLE)
  3808. {
  3809. //
  3810. // If the RTL_MIRROR extended style bit had changed, let's
  3811. // repaint the control window
  3812. //
  3813. if ((_ci.dwExStyle&RTL_MIRRORED_WINDOW) != (lpss->styleNew&RTL_MIRRORED_WINDOW))
  3814. {
  3815. _InvalidateRect(NULL);
  3816. }
  3817. //
  3818. // Save the new ex-style bits
  3819. //
  3820. _ci.dwExStyle = lpss->styleNew;
  3821. }
  3822. }
  3823. void CReBar::_OnMouseMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3824. {
  3825. RelayToToolTips(_hwndToolTips, hwnd, uMsg, wParam, lParam);
  3826. if (_uCapture != -1)
  3827. {
  3828. // captured band -- mouse is down
  3829. if (hwnd != GetCapture() && !_fParentDrag)
  3830. {
  3831. _SendNotify(_uCapture, RBN_ENDDRAG);
  3832. _OnBeginDrag((UINT)-1);
  3833. }
  3834. else
  3835. _DragBand(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  3836. }
  3837. else
  3838. {
  3839. // hottracking
  3840. int iBand;
  3841. PRBB prbb = NULL;
  3842. PRBB prbbHotOld = _prbbHot;
  3843. RBHITTESTINFO rbht;
  3844. rbht.pt.x = GET_X_LPARAM(lParam);
  3845. rbht.pt.y = GET_Y_LPARAM(lParam);
  3846. iBand = _HitTest(&rbht);
  3847. if (iBand != -1)
  3848. prbb = _GetBand(iBand);
  3849. if (prbbHotOld && (prbbHotOld->wChevState & DCHF_PUSHED))
  3850. return;
  3851. if (prbb && (rbht.flags & RBHT_CHEVRON))
  3852. {
  3853. SetCapture(hwnd);
  3854. _UpdateChevronState(prbb, DCHF_HOT);
  3855. if (prbb == prbbHotOld)
  3856. prbbHotOld = NULL;
  3857. }
  3858. if (prbbHotOld)
  3859. {
  3860. CCReleaseCapture(&_ci);
  3861. _UpdateChevronState(prbbHotOld, DCHF_INACTIVE);
  3862. }
  3863. }
  3864. }
  3865. void CReBar::_OnPushChevron(HWND hwnd, PRBB prbb, LPARAM lParamNM)
  3866. {
  3867. NMREBARCHEVRON nm;
  3868. nm.uBand = _BandToIndex(prbb);
  3869. nm.wID = prbb->wID;
  3870. nm.lParam = prbb->lParam;
  3871. nm.lParamNM = lParamNM;
  3872. CopyRect(&nm.rc, &prbb->rcChevron);
  3873. if (_IsVertical())
  3874. FlipRect(&nm.rc);
  3875. _UpdateChevronState(prbb, DCHF_PUSHED);
  3876. CCReleaseCapture(&_ci);
  3877. CCSendNotify(&_ci, RBN_CHEVRONPUSHED, &nm.hdr);
  3878. _UpdateChevronState(_prbbHot, DCHF_INACTIVE);
  3879. }
  3880. void CReBar::_OnCreate(HWND hwnd, LPCREATESTRUCT pcs)
  3881. {
  3882. InitGlobalColors();
  3883. _uCapture = -1;
  3884. _clrBk = CLR_NONE;
  3885. _clrText = CLR_NONE;
  3886. // Init the dwSize because we block-copy it back to the app
  3887. _clrsc.dwSize = sizeof(COLORSCHEME);
  3888. _clrsc.clrBtnHighlight = _clrsc.clrBtnShadow = CLR_DEFAULT;
  3889. _fRedraw = TRUE;
  3890. _fRecalc = TRUE;
  3891. CIInitialize(&_ci, hwnd, pcs);
  3892. _CacheThemeInfo(TRUE);
  3893. if (!(_ci.style & (CCS_TOP | CCS_NOMOVEY | CCS_BOTTOM)))
  3894. {
  3895. _ci.style |= CCS_TOP;
  3896. SetWindowLong(hwnd, GWL_STYLE, _ci.style);
  3897. }
  3898. if (_ci.style & WS_BORDER)
  3899. _fHasBorder = TRUE;
  3900. _SetFont(0);
  3901. if (pcs->lpCreateParams)
  3902. _SetBarInfo((LPREBARINFO) (pcs->lpCreateParams));
  3903. }
  3904. LRESULT CALLBACK CReBar::s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3905. {
  3906. CReBar* prb = (CReBar*) GetWindowPtr(hwnd, 0);
  3907. if (prb)
  3908. {
  3909. LRESULT lres = prb->_WndProc(hwnd, uMsg, wParam, lParam);
  3910. if (uMsg == WM_NCDESTROY)
  3911. {
  3912. SetWindowPtr(hwnd, 0, 0);
  3913. delete prb;
  3914. }
  3915. return lres;
  3916. }
  3917. else if (uMsg == WM_NCCREATE)
  3918. {
  3919. prb = new CReBar();
  3920. if (prb)
  3921. {
  3922. SetWindowPtr(hwnd, 0, prb);
  3923. return prb->_WndProc(hwnd, uMsg, wParam, lParam);
  3924. }
  3925. return FALSE;
  3926. }
  3927. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  3928. }
  3929. LRESULT CReBar::_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3930. {
  3931. switch (uMsg)
  3932. {
  3933. case WM_SETREDRAW:
  3934. _SetRecalc(BOOLFROMPTR(wParam));
  3935. return _SetRedraw(BOOLFROMPTR(wParam));
  3936. case WM_NCCREATE:
  3937. _OnCreate(hwnd, (LPCREATESTRUCT)lParam);
  3938. return TRUE;
  3939. case WM_NCDESTROY:
  3940. _OnDestroy();
  3941. break;
  3942. case WM_CREATE:
  3943. // Do delayed stuff for speed.
  3944. PostMessage(hwnd, RB_PRIV_DODELAYEDSTUFF, 0, 0);
  3945. goto CallDWP;
  3946. case RB_PRIV_DODELAYEDSTUFF:
  3947. // Delay done stuff for speed:
  3948. if (_ci.style & RBS_REGISTERDROP)
  3949. _hDragProxy = CreateDragProxy(_ci.hwnd, s_DragCallback, TRUE);
  3950. if (_ci.style & RBS_TOOLTIPS)
  3951. {
  3952. TOOLINFO ti;
  3953. // don't bother setting the rect because we'll do it below
  3954. // in FlushToolTipsMgr;
  3955. ti.cbSize = sizeof(ti);
  3956. ti.uFlags = TTF_IDISHWND;
  3957. ti.hwnd = hwnd;
  3958. ti.uId = (UINT_PTR)hwnd;
  3959. ti.lpszText = 0;
  3960. _hwndToolTips = CreateWindowEx(WS_EX_TRANSPARENT, c_szSToolTipsClass, NULL,
  3961. WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  3962. hwnd, NULL, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  3963. SendMessage(_hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO) &ti);
  3964. }
  3965. _InitPaletteHack();
  3966. break;
  3967. case WM_NCHITTEST:
  3968. {
  3969. RBHITTESTINFO rbht;
  3970. int iBand;
  3971. rbht.pt.x = GET_X_LPARAM(lParam);
  3972. rbht.pt.y = GET_Y_LPARAM(lParam);
  3973. ScreenToClient(_ci.hwnd, &rbht.pt);
  3974. iBand = _HitTest(&rbht);
  3975. {
  3976. NMMOUSE nm;
  3977. LRESULT lres;
  3978. nm.dwItemSpec = iBand;
  3979. nm.pt = rbht.pt;
  3980. nm.dwHitInfo = rbht.flags;
  3981. // send to the parent to give them a chance to override
  3982. lres = CCSendNotify(&_ci, NM_NCHITTEST, &nm.hdr);
  3983. if (lres)
  3984. return lres;
  3985. }
  3986. }
  3987. return HTCLIENT;
  3988. case WM_NCCALCSIZE:
  3989. if (_ci.style & WS_BORDER)
  3990. {
  3991. InflateRect((LPRECT) lParam, -g_cxEdge, -g_cyEdge);
  3992. break;
  3993. }
  3994. goto CallDWP;
  3995. case WM_NCPAINT:
  3996. if (_ci.style & WS_BORDER)
  3997. {
  3998. RECT rc;
  3999. HDC hdc;
  4000. GetWindowRect(hwnd, &rc);
  4001. OffsetRect(&rc, -rc.left, -rc.top);
  4002. hdc = GetWindowDC(hwnd);
  4003. if (hdc)
  4004. {
  4005. CCDrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT, &(_clrsc));
  4006. ReleaseDC(hwnd, hdc);
  4007. }
  4008. break;
  4009. }
  4010. goto CallDWP;
  4011. case WM_PALETTECHANGED:
  4012. if ((HWND)wParam == hwnd)
  4013. break;
  4014. case WM_QUERYNEWPALETTE:
  4015. // Want to pass FALSE if WM_QUERYNEWPALETTE...
  4016. _Realize(NULL, uMsg == WM_PALETTECHANGED, uMsg == WM_PALETTECHANGED);
  4017. return TRUE;
  4018. case WM_PAINT:
  4019. case WM_PRINTCLIENT:
  4020. _OnPaint((HDC)wParam);
  4021. break;
  4022. case WM_ERASEBKGND:
  4023. if (_EraseBkgnd((HDC) wParam, -1))
  4024. return(TRUE);
  4025. goto CallDWP;
  4026. case WM_SYSCOLORCHANGE:
  4027. _InitPaletteHack();
  4028. if (_hwndToolTips)
  4029. SendMessage(_hwndToolTips, uMsg, wParam, lParam);
  4030. InitGlobalColors();
  4031. InvalidateRect(_ci.hwnd, NULL, TRUE);
  4032. break;
  4033. case RB_SETPALETTE:
  4034. return (LRESULT)_SetPalette((HPALETTE)lParam);
  4035. case RB_GETPALETTE:
  4036. return (LRESULT)_hpal;
  4037. case RB_GETBANDMARGINS:
  4038. {
  4039. MARGINS* pMargin = (MARGINS*)lParam;
  4040. if (pMargin)
  4041. *pMargin = _mBand;
  4042. return 1;
  4043. }
  4044. case WM_SIZE:
  4045. _AutoSize();
  4046. _Resize(FALSE);
  4047. break;
  4048. case WM_GETFONT:
  4049. return (LRESULT)_hFont;
  4050. case WM_COMMAND:
  4051. case WM_DRAWITEM:
  4052. case WM_MEASUREITEM:
  4053. case WM_VKEYTOITEM:
  4054. case WM_CHARTOITEM:
  4055. SendMessage(_ci.hwndParent, uMsg, wParam, lParam);
  4056. break;
  4057. case WM_LBUTTONDBLCLK: // DBLCLK sent in place of LBUTTONDOWN
  4058. case WM_RBUTTONDOWN: // right button drags too
  4059. case WM_LBUTTONDOWN:
  4060. {
  4061. RBHITTESTINFO rbht;
  4062. PRBB prbb = NULL;
  4063. rbht.pt.x = GET_X_LPARAM(lParam);
  4064. rbht.pt.y = GET_Y_LPARAM(lParam);
  4065. RelayToToolTips(_hwndToolTips, hwnd, uMsg, wParam, lParam);
  4066. int iBand = _HitTest(&rbht);
  4067. if (iBand != -1)
  4068. prbb = _GetBand(iBand);
  4069. if (!prbb)
  4070. {
  4071. /* nothing */ ;
  4072. }
  4073. else if (rbht.flags & RBHT_CHEVRON)
  4074. {
  4075. _OnPushChevron(hwnd, prbb, 0);
  4076. }
  4077. else if (rbht.flags != RBHT_CLIENT && _ShouldDrawGripper(prbb))
  4078. {
  4079. _uCapture = iBand;
  4080. _ptCapture = rbht.pt;
  4081. if (_ci.style & CCS_VERT)
  4082. SWAP(_ptCapture.x, _ptCapture.y, int);
  4083. _xStart = prbb->x;
  4084. SetCapture(hwnd);
  4085. _fFullOnDrag = FALSE;
  4086. if (uMsg == WM_LBUTTONDBLCLK && (_ci.style & RBS_DBLCLKTOGGLE))
  4087. _ToggleBand(TRUE);
  4088. }
  4089. }
  4090. break;
  4091. case WM_SETCURSOR:
  4092. // Give the parent first crack, if it sets the cursor then
  4093. // leave it at that. Otherwise if the cursor is over our
  4094. // window then set it to what we want it to be.
  4095. if (!DefWindowProc(hwnd, uMsg, wParam, lParam) && (hwnd == (HWND)wParam))
  4096. {
  4097. POINT pt;
  4098. GetMessagePosClient(_ci.hwnd, &pt);
  4099. _SetCursor(pt.x, pt.y, (HIWORD(lParam) == WM_LBUTTONDOWN || HIWORD(lParam) == WM_RBUTTONDOWN));
  4100. }
  4101. return TRUE;
  4102. case WM_MOUSEMOVE:
  4103. _OnMouseMove(hwnd, uMsg, wParam, lParam);
  4104. break;
  4105. case WM_RBUTTONUP:
  4106. if (!_fFullOnDrag && !_fParentDrag) {
  4107. CCReleaseCapture(&_ci);
  4108. // if we're not doing drag drop, go to def window proc so that
  4109. // wm_contextmenu gets propagated
  4110. _OnBeginDrag((UINT)-1);
  4111. goto CallDWP;
  4112. }
  4113. // fall through
  4114. case WM_LBUTTONUP:
  4115. RelayToToolTips(_hwndToolTips, hwnd, uMsg, wParam, lParam);
  4116. if (_uCapture != -1)
  4117. {
  4118. UINT uiIndex;
  4119. if (!_fParentDrag)
  4120. CCReleaseCapture(&_ci);
  4121. // if there was no significant mouse motion, treat as a click
  4122. if (!(_ci.style & RBS_DBLCLKTOGGLE) && !_fFullOnDrag)
  4123. _ToggleBand(TRUE);
  4124. _GetBand(_uCapture)->fStyle &= ~RBBS_DRAGBREAK;
  4125. CCSendNotify(&_ci, RBN_LAYOUTCHANGED, NULL);
  4126. _SendNotify(_uCapture, RBN_ENDDRAG);
  4127. _OnBeginDrag((UINT)-1);
  4128. for (uiIndex = 0; uiIndex < _cBands; uiIndex++) {
  4129. if (_GetBand(uiIndex)->fStyle & RBBS_HIDDEN)
  4130. continue;
  4131. _BandCalcMinWidth(_GetBand(uiIndex));
  4132. }
  4133. _SizeBandsToRect(NULL);
  4134. _InvalidateRect(NULL);
  4135. }
  4136. break;
  4137. case WM_WININICHANGE:
  4138. InitGlobalMetrics(wParam);
  4139. if (_fFontCreated)
  4140. _SetFont(wParam);
  4141. if (_hwndToolTips)
  4142. SendMessage(_hwndToolTips, uMsg, wParam, lParam);
  4143. for (DWORD dwIndex = 0; dwIndex < _cBands; dwIndex++)
  4144. {
  4145. PRBB prbb = _rbbList + dwIndex;
  4146. SendMessage(prbb->hwndChild, WM_WININICHANGE, wParam, lParam);
  4147. }
  4148. break;
  4149. case WM_SETFONT:
  4150. _OnSetFont((HFONT)wParam);
  4151. break;
  4152. case WM_NOTIFYFORMAT:
  4153. return(CIHandleNotifyFormat(&_ci, lParam));
  4154. case WM_NOTIFY:
  4155. // We are just going to pass this on to the real parent
  4156. // Note that -1 is used as the hwndFrom. This prevents SendNotifyEx
  4157. // from updating the NMHDR structure.
  4158. return(SendNotifyEx(_ci.hwndParent, (HWND) -1,
  4159. ((LPNMHDR) lParam)->code, (LPNMHDR) lParam, _ci.bUnicode));
  4160. case WM_STYLECHANGED:
  4161. _OnStyleChanged(wParam, (LPSTYLESTRUCT)lParam);
  4162. break;
  4163. case WM_UPDATEUISTATE:
  4164. if (CCOnUIState(&(_ci), WM_UPDATEUISTATE, wParam, lParam))
  4165. {
  4166. InvalidateRect(hwnd, NULL, TRUE);
  4167. }
  4168. goto CallDWP;
  4169. case RB_SETBANDINFOA:
  4170. case RB_INSERTBANDA:
  4171. if (EVAL(lParam))
  4172. {
  4173. LPWSTR lpStrings = NULL;
  4174. LPSTR lpAnsiString;
  4175. int iResult;
  4176. // lParam starts out pointing to a REBARBANDINFOA, and
  4177. // we secretly change it into a REBARBANDINFOW, and then
  4178. // change it back.
  4179. LPREBARBANDINFOW prbiW = (LPREBARBANDINFOW)lParam;
  4180. LPREBARBANDINFOA prbiA = (LPREBARBANDINFOA)lParam;
  4181. COMPILETIME_ASSERT(sizeof(REBARBANDINFOW) == sizeof(REBARBANDINFOA));
  4182. // Bug#94345 - raymondc - Is it safe to modify the incoming
  4183. // REBARBANDINFOA structure?
  4184. lpAnsiString = prbiA->lpText;
  4185. if ((prbiA->fMask & RBBIM_TEXT) && prbiA->lpText) {
  4186. lpStrings = ProduceWFromA(_ci.uiCodePage, lpAnsiString);
  4187. if (!lpStrings)
  4188. return -1;
  4189. // Presto! Now it's a REBARBANDINFOW!
  4190. prbiW->lpText = lpStrings;
  4191. }
  4192. if (uMsg == RB_INSERTBANDA)
  4193. iResult = _InsertBand((UINT) wParam, prbiW);
  4194. else
  4195. iResult = _SetBandInfo((UINT) wParam, prbiW, TRUE);
  4196. // Change-o! Now it's a REBARBANDINFOA!
  4197. prbiA->lpText = lpAnsiString;
  4198. if (lpStrings)
  4199. FreeProducedString(lpStrings);
  4200. return iResult;
  4201. }
  4202. case RB_INSERTBAND:
  4203. return(_InsertBand((UINT) wParam, (LPREBARBANDINFO) lParam));
  4204. case RB_DELETEBAND:
  4205. return(_DeleteBand((UINT) wParam));
  4206. case RB_SHOWBAND:
  4207. return(_ShowBand((UINT) wParam, BOOLFROMPTR(lParam)));
  4208. case RB_GETBANDINFOA:
  4209. {
  4210. LPREBARBANDINFOA prbbi = (LPREBARBANDINFOA)lParam;
  4211. LPWSTR pszW = NULL;
  4212. LPSTR lpAnsiString = prbbi->lpText;
  4213. int iResult;
  4214. if (prbbi->fMask & RBBIM_TEXT) {
  4215. pszW = (LPWSTR)LocalAlloc(LPTR, prbbi->cch * sizeof(WCHAR));
  4216. if (!pszW)
  4217. return 0;
  4218. prbbi->lpText = (LPSTR)pszW;
  4219. }
  4220. iResult = _GetBandInfo((UINT)wParam, (LPREBARBANDINFO)lParam);
  4221. if (pszW) {
  4222. ConvertWToAN(_ci.uiCodePage, lpAnsiString, prbbi->cch, (LPWSTR)prbbi->lpText, -1);
  4223. prbbi->lpText = lpAnsiString;
  4224. LocalFree(pszW);
  4225. }
  4226. return iResult;
  4227. }
  4228. // we have getbandinfoold because in ie3, we did not thunk
  4229. // and getbandinfo always return OS native string (dumb)
  4230. case RB_GETBANDINFOOLD:
  4231. case RB_GETBANDINFO:
  4232. return(_GetBandInfo((UINT) wParam, (LPREBARBANDINFO) lParam));
  4233. case RB_GETTOOLTIPS:
  4234. return (LPARAM)_hwndToolTips;
  4235. case RB_SETTOOLTIPS:
  4236. _hwndToolTips = (HWND)wParam;
  4237. break;
  4238. case RB_SETBKCOLOR:
  4239. {
  4240. COLORREF clr = _clrBk;
  4241. _clrBk = (COLORREF)lParam;
  4242. if (clr != _clrBk)
  4243. InvalidateRect(_ci.hwnd, NULL, TRUE);
  4244. return clr;
  4245. }
  4246. case RB_GETBKCOLOR:
  4247. return _clrBk;
  4248. case RB_SETTEXTCOLOR:
  4249. {
  4250. COLORREF clr = _clrText;
  4251. _clrText = (COLORREF)lParam;
  4252. return clr;
  4253. }
  4254. case RB_GETTEXTCOLOR:
  4255. return _clrText;
  4256. case RB_IDTOINDEX:
  4257. return _IDToIndex((UINT) wParam);
  4258. case RB_GETROWCOUNT:
  4259. return(_GetRowCount());
  4260. case RB_GETROWHEIGHT:
  4261. return _GetRowHeight((UINT)wParam);
  4262. case RB_GETBANDBORDERS:
  4263. return _GetBandBorders((UINT)wParam, (LPRECT)lParam);
  4264. case RB_GETBANDCOUNT:
  4265. return(_cBands);
  4266. case RB_SETBANDINFO:
  4267. return(_SetBandInfo((UINT) wParam, (LPREBARBANDINFO) lParam, TRUE));
  4268. case RB_GETBARINFO:
  4269. return(_GetBarInfo((LPREBARINFO) lParam));
  4270. case RB_SETBARINFO:
  4271. return(_SetBarInfo((LPREBARINFO) lParam));
  4272. case RB_SETPARENT:
  4273. {
  4274. HWND hwndOld = _ci.hwndParent;
  4275. _ci.hwndParent = (HWND) wParam;
  4276. return (LRESULT)hwndOld;
  4277. }
  4278. break;
  4279. case RB_GETRECT:
  4280. if (_IsValidIndex((UINT)wParam))
  4281. {
  4282. PRBB prbb = _GetBand((UINT)wParam);
  4283. LPRECT lprc = (LPRECT) lParam;
  4284. lprc->left = prbb->x;
  4285. lprc->top = prbb->y;
  4286. lprc->right = prbb->x + prbb->cx;
  4287. lprc->bottom = prbb->y + prbb->cy;
  4288. return(TRUE);
  4289. }
  4290. break;
  4291. case RB_HITTEST:
  4292. return(_HitTest((LPRBHITTESTINFO) lParam));
  4293. case RB_SIZETORECT:
  4294. return _SizeBarToRect((DWORD)wParam, (LPRECT)lParam);
  4295. case RB_BEGINDRAG:
  4296. if (_IsValidIndex((UINT)wParam)) {
  4297. // -1 means do it yourself.
  4298. // -2 means use what you had saved before
  4299. if (lParam != (LPARAM)-2) {
  4300. if (lParam == (LPARAM)-1) {
  4301. GetMessagePosClient(_ci.hwnd, &_ptCapture);
  4302. } else {
  4303. _ptCapture.x = GET_X_LPARAM(lParam);
  4304. _ptCapture.y = GET_Y_LPARAM(lParam);
  4305. }
  4306. if (_ci.style & CCS_VERT)
  4307. SWAP(_ptCapture.x, _ptCapture.y, int);
  4308. }
  4309. _xStart = _GetBand((UINT)wParam)->x;
  4310. _OnBeginDrag((UINT)wParam);
  4311. }
  4312. break;
  4313. case RB_GETBARHEIGHT:
  4314. return _GetBarHeight();
  4315. case RB_ENDDRAG:
  4316. _OnBeginDrag((UINT)-1);
  4317. break;
  4318. case RB_DRAGMOVE:
  4319. if (_uCapture != -1) {
  4320. if (lParam == (LPARAM)-1) {
  4321. lParam = GetMessagePosClient(_ci.hwnd, NULL);
  4322. }
  4323. _DragBand(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  4324. }
  4325. break;
  4326. case RB_MINIMIZEBAND:
  4327. _MinimizeBand((UINT) wParam,FALSE);
  4328. break;
  4329. case RB_MAXIMIZEBAND:
  4330. _MaximizeBand((UINT)wParam, BOOLFROMPTR(lParam),FALSE);
  4331. break;
  4332. case RB_MOVEBAND:
  4333. if (!_IsValidIndex((UINT)wParam) || !_IsValidIndex((UINT)lParam))
  4334. break;
  4335. return _MoveBand((UINT) wParam, (UINT) lParam);
  4336. case RB_GETDROPTARGET:
  4337. if (!_hDragProxy)
  4338. _hDragProxy = CreateDragProxy(_ci.hwnd, s_DragCallback, FALSE);
  4339. GetDragProxyTarget(_hDragProxy, (IDropTarget**)lParam);
  4340. break;
  4341. case RB_GETCOLORSCHEME:
  4342. {
  4343. LPCOLORSCHEME lpclrsc = (LPCOLORSCHEME) lParam;
  4344. if (lpclrsc) {
  4345. if (lpclrsc->dwSize == sizeof(COLORSCHEME))
  4346. *lpclrsc = _clrsc;
  4347. }
  4348. return (LRESULT) lpclrsc;
  4349. }
  4350. case RB_SETCOLORSCHEME:
  4351. if (lParam) {
  4352. if (((LPCOLORSCHEME) lParam)->dwSize == sizeof(COLORSCHEME)) {
  4353. _clrsc.clrBtnHighlight = ((LPCOLORSCHEME) lParam)->clrBtnHighlight;
  4354. _clrsc.clrBtnShadow = ((LPCOLORSCHEME) lParam)->clrBtnShadow;
  4355. InvalidateRect(hwnd, NULL, FALSE);
  4356. if (_ci.style & WS_BORDER)
  4357. CCInvalidateFrame(hwnd);
  4358. }
  4359. }
  4360. break;
  4361. case RB_PUSHCHEVRON:
  4362. if (_IsValidIndex((UINT)wParam)) {
  4363. PRBB prbb = _GetBand((UINT)wParam);
  4364. _OnPushChevron(hwnd, prbb, lParam);
  4365. }
  4366. break;
  4367. case RB_SETWINDOWTHEME:
  4368. if (lParam)
  4369. {
  4370. SetWindowTheme(hwnd, (LPWSTR)lParam, NULL);
  4371. }
  4372. break;
  4373. case WM_THEMECHANGED:
  4374. _CacheThemeInfo((BOOL)wParam);
  4375. InvalidateRect(_ci.hwnd, NULL, TRUE);
  4376. return 0;
  4377. default:
  4378. LRESULT lres;
  4379. if (CCWndProc(&_ci, uMsg, wParam, lParam, &lres))
  4380. return lres;
  4381. CallDWP:
  4382. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  4383. }
  4384. return 0;
  4385. }