Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / rebar.h
1 // Win32++   Version 7.3\r
2 // Released: 30th November 2011\r
3 //\r
4 //      David Nash\r
5 //      email: [email protected]\r
6 //      url: https://sourceforge.net/projects/win32-framework\r
7 //\r
8 //\r
9 // Copyright (c) 2005-2011  David Nash\r
10 //\r
11 // Permission is hereby granted, free of charge, to\r
12 // any person obtaining a copy of this software and\r
13 // associated documentation files (the "Software"),\r
14 // to deal in the Software without restriction, including\r
15 // without limitation the rights to use, copy, modify,\r
16 // merge, publish, distribute, sublicense, and/or sell\r
17 // copies of the Software, and to permit persons to whom\r
18 // the Software is furnished to do so, subject to the\r
19 // following conditions:\r
20 //\r
21 // The above copyright notice and this permission notice\r
22 // shall be included in all copies or substantial portions\r
23 // of the Software.\r
24 //\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.\r
34 //\r
35 ////////////////////////////////////////////////////////\r
36 \r
37 \r
38 #ifndef _WIN32XX_REBAR_H_\r
39 #define _WIN32XX_REBAR_H_\r
40 \r
41 #include "wincore.h"\r
42 #include "gdi.h"\r
43 #include "controls.h"\r
44 \r
45 namespace Win32xx\r
46 {\r
47 \r
48         struct ReBarTheme\r
49         {\r
50                 BOOL UseThemes;                 // TRUE if themes are used\r
51                 COLORREF clrBkgnd1;             // Colour 1 for rebar background\r
52                 COLORREF clrBkgnd2;             // Colour 2 for rebar background\r
53                 COLORREF clrBand1;              // Colour 1 for rebar band background. Use NULL if not required\r
54                 COLORREF clrBand2;              // Colour 2 for rebar band background. Use NULL if not required\r
55                 BOOL FlatStyle;                 // Bands are rendered with flat rather than raised style\r
56                 BOOL BandsLeft;                 // Position bands left on rearrange\r
57                 BOOL LockMenuBand;              // Lock MenuBar's band in dedicated top row, without gripper\r
58                 BOOL RoundBorders;              // Use rounded band borders\r
59                 BOOL ShortBands;        // Allows bands to be shorter than maximum available width\r
60                 BOOL UseLines;                  // Displays horizontal lines between bands\r
61         };\r
62 \r
63         ////////////////////////////////////\r
64         // Declaration of the CReBar class\r
65         //\r
66         class CReBar : public CWnd\r
67         {\r
68         public:\r
69                 CReBar();\r
70                 virtual ~CReBar();\r
71 \r
72                 // Operations\r
73                 BOOL DeleteBand(const int nBand) const;\r
74                 int  HitTest(RBHITTESTINFO& rbht);\r
75                 HWND HitTest(POINT pt);\r
76                 int  IDToIndex(UINT uBandID) const;\r
77                 BOOL InsertBand(const int nBand, REBARBANDINFO& rbbi) const;\r
78                 BOOL IsBandVisible(int nBand) const;\r
79                 void MaximizeBand(UINT uBand, BOOL fIdeal = FALSE);\r
80                 void MinimizeBand(UINT uBand);\r
81                 BOOL MoveBand(UINT uFrom, UINT uTo);\r
82                 void MoveBandsLeft();\r
83                 BOOL ResizeBand(const int nBand, const CSize& sz) const;\r
84                 BOOL ShowGripper(int nBand, BOOL fShow) const;\r
85                 BOOL ShowBand(int nBand, BOOL fShow) const;\r
86                 BOOL SizeToRect(CRect& rect) const;\r
87                 \r
88                 // Attributes\r
89                 int  GetBand(const HWND hWnd) const;\r
90                 CRect GetBandBorders(int nBand) const;\r
91                 int  GetBandCount() const;\r
92                 BOOL GetBandInfo(const int nBand, REBARBANDINFO& rbbi) const;\r
93                 CRect GetBandRect(int i) const;\r
94                 UINT GetBarHeight() const;\r
95                 BOOL GetBarInfo(REBARINFO& rbi) const;\r
96                 HWND GetMenuBar() {return m_hMenuBar;}\r
97                 ReBarTheme& GetReBarTheme() {return m_Theme;}\r
98                 UINT GetRowCount() const;\r
99                 int  GetRowHeight(int nRow) const;\r
100                 UINT GetSizeofRBBI() const;\r
101                 CToolTip* GetToolTips() const;\r
102                 BOOL SetBandBitmap(const int nBand, const CBitmap* pBackground) const;\r
103                 BOOL SetBandColor(const int nBand, const COLORREF clrFore, const COLORREF clrBack) const;\r
104                 BOOL SetBandInfo(const int nBand, REBARBANDINFO& rbbi) const;\r
105                 BOOL SetBarInfo(REBARINFO& rbi) const;\r
106                 void SetMenuBar(HWND hMenuBar) {m_hMenuBar = hMenuBar;}\r
107                 void SetReBarTheme(ReBarTheme& Theme);\r
108                 void SetToolTips(CToolTip* pToolTip) const;\r
109 \r
110         protected:\r
111         //Overridables\r
112                 virtual BOOL OnEraseBkgnd(CDC* pDC);\r
113                 virtual void PreCreate(CREATESTRUCT& cs);\r
114                 virtual void PreRegisterClass(WNDCLASS &wc);\r
115                 virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
116 \r
117         private:\r
118                 CReBar(const CReBar&);                          // Disable copy construction\r
119                 CReBar& operator = (const CReBar&); // Disable assignment operator\r
120 \r
121                 ReBarTheme m_Theme;\r
122                 BOOL m_bIsDragging;\r
123                 HWND m_hMenuBar;\r
124                 LPARAM m_Orig_lParam;\r
125         };\r
126 \r
127 }\r
128 \r
129 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
130 \r
131 \r
132 namespace Win32xx\r
133 {\r
134 \r
135         ///////////////////////////////////\r
136         // Definitions for the CReBar class\r
137         //\r
138         inline CReBar::CReBar() : m_bIsDragging(FALSE), m_hMenuBar(0), m_Orig_lParam(0L)\r
139         {\r
140                 ZeroMemory(&m_Theme, sizeof(ReBarTheme));\r
141         }\r
142 \r
143         inline CReBar::~CReBar()\r
144         {\r
145         }\r
146 \r
147         inline BOOL CReBar::DeleteBand(int nBand) const\r
148         // Deletes a band from a rebar control.\r
149         {\r
150                 assert(::IsWindow(m_hWnd));\r
151                 return (BOOL)SendMessage(RB_DELETEBAND, nBand, 0L);\r
152         }\r
153 \r
154         inline int CReBar::GetBand(HWND hWnd) const\r
155         // Returns the zero based band number for this window handle\r
156         {\r
157                 assert(::IsWindow(m_hWnd));\r
158 \r
159                 int nResult = -1;\r
160                 if (NULL == hWnd) return nResult;\r
161 \r
162                 for (int nBand = 0; nBand < GetBandCount(); ++nBand)\r
163                 {\r
164                         REBARBANDINFO rbbi = {0};\r
165                         rbbi.cbSize = GetSizeofRBBI();\r
166                         rbbi.fMask = RBBIM_CHILD;\r
167                         GetBandInfo(nBand, rbbi);\r
168                         if (rbbi.hwndChild == hWnd)\r
169                                 nResult = nBand;\r
170                 }\r
171 \r
172                 return nResult;\r
173         }\r
174 \r
175         inline CRect CReBar::GetBandBorders(int nBand) const\r
176         // Retrieves the borders of a band.\r
177         {\r
178                 assert(::IsWindow(m_hWnd));\r
179 \r
180                 CRect rc;\r
181                 SendMessage(RB_GETBANDBORDERS, nBand, (LPARAM)&rc);\r
182                 return rc;\r
183         }\r
184 \r
185         inline int  CReBar::GetBandCount() const\r
186         // Retrieves the count of bands currently in the rebar control.\r
187         {\r
188                 assert(::IsWindow(m_hWnd));\r
189                 return (int)SendMessage(RB_GETBANDCOUNT, 0L, 0L);\r
190         }\r
191 \r
192         inline BOOL CReBar::GetBandInfo(int nBand, REBARBANDINFO& rbbi) const\r
193         // Retrieves information about a specified band in a rebar control.\r
194         {\r
195                 assert(::IsWindow(m_hWnd));\r
196                 assert(nBand >=  0);\r
197 \r
198                 // REBARBANDINFO describes individual BAND characteristics\r
199                 rbbi.cbSize = GetSizeofRBBI();\r
200                 return (BOOL)SendMessage(RB_GETBANDINFO, nBand, (LPARAM)&rbbi);\r
201         }\r
202 \r
203         inline CRect CReBar::GetBandRect(int i) const\r
204         // Retrieves the bounding rectangle for a given band in a rebar control.\r
205         {\r
206                 assert(::IsWindow(m_hWnd));\r
207                 CRect rc;\r
208                 SendMessage(RB_GETRECT, i, (LPARAM)&rc);\r
209                 return rc;\r
210         }\r
211 \r
212         inline UINT CReBar::GetBarHeight() const\r
213         // Retrieves the height of the rebar control.\r
214         {\r
215                 assert(::IsWindow(m_hWnd));\r
216                 return (UINT)SendMessage(RB_GETBARHEIGHT, 0L, 0L);\r
217         }\r
218 \r
219         inline BOOL CReBar::GetBarInfo(REBARINFO& rbi) const\r
220         // Retrieves information about the rebar control and the image list it uses.\r
221         {\r
222                 assert(::IsWindow(m_hWnd));\r
223 \r
224                 // REBARINFO describes overall rebar control characteristics\r
225                 rbi.cbSize = GetSizeofRBBI();\r
226                 return (BOOL)SendMessage(RB_GETBARINFO, 0L, (LPARAM)&rbi);\r
227         }\r
228 \r
229         inline UINT CReBar::GetRowCount() const\r
230         // Retrieves the number of rows of bands in a rebar control.\r
231         {\r
232                 assert(::IsWindow(m_hWnd));\r
233                 return (UINT)SendMessage(RB_GETROWCOUNT, 0L, 0L);\r
234         }\r
235 \r
236         inline int CReBar::GetRowHeight(int nRow) const\r
237         // Retrieves the height of a specified row in a rebar control.\r
238         {\r
239                 assert(::IsWindow(m_hWnd));\r
240                 return (int)SendMessage(RB_GETROWHEIGHT, nRow, 0L);\r
241         }\r
242 \r
243         inline UINT CReBar::GetSizeofRBBI() const\r
244         // The size of the REBARBANDINFO struct changes according to _WIN32_WINNT\r
245         // sizeof(REBARBANDINFO) can report an incorrect size for older Window versions,\r
246         // or newer Window version without XP themes enabled.\r
247         // Use this function to get a safe size for REBARBANDINFO.\r
248         {\r
249                 assert(::IsWindow(m_hWnd));\r
250 \r
251                 UINT uSizeof = sizeof(REBARBANDINFO);\r
252 \r
253         #if defined REBARBANDINFO_V6_SIZE       // only defined for VS2008 or higher\r
254           #if !defined (_WIN32_WINNT) || _WIN32_WINNT >= 0x0600\r
255                 if ((GetWinVersion() < 2600) || (GetComCtlVersion() < 610)) // Vista and Vista themes?\r
256                         uSizeof = REBARBANDINFO_V6_SIZE;\r
257           #endif\r
258         #endif\r
259 \r
260                 return uSizeof;\r
261         }\r
262 \r
263         inline CToolTip* CReBar::GetToolTips() const\r
264         // Retrieves the handle to any ToolTip control associated with the rebar control.\r
265         {\r
266                 assert(::IsWindow(m_hWnd));\r
267                 return (CToolTip*)FromHandle( (HWND)SendMessage(RB_GETTOOLTIPS, 0L, 0L) );\r
268         }\r
269 \r
270         inline int CReBar::HitTest(RBHITTESTINFO& rbht)\r
271         // Determines which portion of a rebar band is at a given point on the screen,\r
272         //  if a rebar band exists at that point.\r
273         {\r
274                 assert(::IsWindow(m_hWnd));\r
275                 return (int)SendMessage(RB_HITTEST, 0L, (LPARAM)&rbht);\r
276         }\r
277 \r
278         inline HWND CReBar::HitTest(POINT pt)\r
279         // Return the child HWND at the given point\r
280         {\r
281                 assert(::IsWindow(m_hWnd));\r
282 \r
283                 // Convert the point to client co-ordinates\r
284                 ScreenToClient(pt);\r
285 \r
286                 // Get the rebar band with the point\r
287                 RBHITTESTINFO rbhti = {0};\r
288                 rbhti.pt = pt;\r
289                 int iBand = HitTest(rbhti);\r
290 \r
291                 if (iBand >= 0)\r
292                 {\r
293                         // Get the rebar band's hWnd\r
294                         REBARBANDINFO rbbi = {0};\r
295                         rbbi.cbSize = GetSizeofRBBI();\r
296                         rbbi.fMask = RBBIM_CHILD;\r
297                         GetBandInfo(iBand, rbbi);\r
298 \r
299                         return rbbi.hwndChild;\r
300                 }\r
301                 else\r
302                         return NULL;\r
303         }\r
304 \r
305         inline int CReBar::IDToIndex(UINT uBandID) const\r
306         // Converts a band identifier to a band index in a rebar control.\r
307         {\r
308                 assert(::IsWindow(m_hWnd));\r
309                 return (int)SendMessage(RB_IDTOINDEX, (WPARAM)uBandID, 0L);\r
310         }\r
311 \r
312         inline BOOL CReBar::InsertBand(int nBand, REBARBANDINFO& rbbi) const\r
313         // Inserts a new band in a rebar control.\r
314         {\r
315                 assert(::IsWindow(m_hWnd));\r
316 \r
317                 rbbi.cbSize = GetSizeofRBBI();\r
318                 return (BOOL)SendMessage(RB_INSERTBAND, nBand, (LPARAM)&rbbi);\r
319         }\r
320 \r
321         inline BOOL CReBar::IsBandVisible(int nBand) const\r
322         // Returns true if the band is visible\r
323         {\r
324                 assert(::IsWindow(m_hWnd));\r
325 \r
326                 REBARBANDINFO rbbi = {0};\r
327                 rbbi.cbSize = GetSizeofRBBI();\r
328                 rbbi.fMask = RBBIM_STYLE;\r
329                 GetBandInfo(nBand, rbbi);\r
330 \r
331                 return !(rbbi.fStyle & RBBS_HIDDEN);\r
332         }\r
333 \r
334         inline BOOL CReBar::OnEraseBkgnd(CDC* pDC)\r
335         {\r
336                 BOOL Erase = TRUE;\r
337                 if (!m_Theme.UseThemes)\r
338                         Erase = FALSE;\r
339 \r
340                 if (!m_Theme.clrBkgnd1 && !m_Theme.clrBkgnd2 && !m_Theme.clrBand1 && !m_Theme.clrBand2)\r
341                         Erase = FALSE;\r
342 \r
343                 if (Erase)\r
344                 {\r
345                         CRect rcReBar = GetClientRect();\r
346                         int BarWidth = rcReBar.Width();\r
347                         int BarHeight = rcReBar.Height();\r
348 \r
349                         // Create and set up our memory DC\r
350                         CMemDC MemDC(pDC);\r
351                         MemDC.CreateCompatibleBitmap(pDC, BarWidth, BarHeight);\r
352 \r
353                         // Draw to ReBar background to the memory DC\r
354                         rcReBar.right = 600;\r
355                         MemDC.GradientFill(m_Theme.clrBkgnd1, m_Theme.clrBkgnd2, rcReBar, TRUE);\r
356                         if (BarWidth >= 600)\r
357                         {\r
358                                 rcReBar.left = 600;\r
359                                 rcReBar.right = BarWidth;\r
360                                 MemDC.SolidFill(m_Theme.clrBkgnd2, rcReBar);\r
361                         }\r
362 \r
363                         if (m_Theme.clrBand1 || m_Theme.clrBand2)\r
364                         {\r
365                                 // Draw the individual band backgrounds\r
366                                 for (int nBand = 0 ; nBand < GetBandCount(); ++nBand)\r
367                                 {\r
368                                         if (IsBandVisible(nBand))\r
369                                         {\r
370                                                 if (nBand != GetBand(m_hMenuBar))\r
371                                                 {\r
372                                                         // Determine the size of this band\r
373                                                         CRect rcBand = GetBandRect(nBand);\r
374 \r
375                                                         // Determine the size of the child window\r
376                                                         REBARBANDINFO rbbi = {0};\r
377                                                         rbbi.cbSize = GetSizeofRBBI();\r
378                                                         rbbi.fMask = RBBIM_CHILD ;\r
379                                                         GetBandInfo(nBand, rbbi);\r
380                                                         CRect rcChild;\r
381                                                         ::GetWindowRect(rbbi.hwndChild, &rcChild);\r
382                                                         int ChildWidth = rcChild.right - rcChild.left;\r
383 \r
384                                                         // Determine our drawing rectangle\r
385                                                         CRect rcDraw = rcBand;\r
386                                                         rcDraw.bottom = rcDraw.top + (rcBand.bottom - rcBand.top)/2;\r
387                                                         int xPad = IsXPThemed()? 2: 0;\r
388                                                         rcDraw.left -= xPad;\r
389 \r
390                                                         // Fill the Source CDC with the band's background\r
391                                                         CMemDC SourceDC(pDC);\r
392                                                         SourceDC.CreateCompatibleBitmap(pDC, BarWidth, BarHeight);\r
393                                                         CRect rcBorder = GetBandBorders(nBand);\r
394                                                         rcDraw.right = rcBand.left + ChildWidth + rcBorder.left;\r
395                                                         SourceDC.SolidFill(m_Theme.clrBand1, rcDraw);\r
396                                                         rcDraw.top = rcDraw.bottom;\r
397                                                         rcDraw.bottom = rcBand.bottom;\r
398                                                         SourceDC.GradientFill(m_Theme.clrBand1, m_Theme.clrBand2, rcDraw, FALSE);\r
399 \r
400                                                         // Set Curve amount for rounded edges\r
401                                                         int Curve = m_Theme.RoundBorders? 12 : 0;\r
402 \r
403                                                         // Create our mask for rounded edges using RoundRect\r
404                                                         CMemDC MaskDC(pDC);\r
405                                                         MaskDC.CreateCompatibleBitmap(pDC, BarWidth, BarHeight);\r
406 \r
407                                                         rcDraw.top = rcBand.top;\r
408                                                         if (!m_Theme.FlatStyle)\r
409                                                                 ::InflateRect(&rcDraw, 1, 1);\r
410 \r
411                                                         int left = rcDraw.left;\r
412                                                         int right = rcDraw.right;\r
413                                                         int top = rcDraw.top;\r
414                                                         int bottom = rcDraw.bottom;\r
415                                                         int cx = rcDraw.right - rcBand.left + xPad;\r
416                                                         int cy = rcDraw.bottom - rcBand.top;\r
417 \r
418                                                         if (m_Theme.FlatStyle)\r
419                                                         {\r
420                                                                 MaskDC.SolidFill(RGB(0,0,0), rcDraw);\r
421                                                                 MaskDC.BitBlt(left, top, cx, cy, &MaskDC, left, top, PATINVERT);\r
422                                                                 MaskDC.RoundRect(left, top, right, bottom, Curve, Curve);\r
423                                                         }\r
424                                                         else\r
425                                                         {\r
426                                                                 MaskDC.SolidFill(RGB(0,0,0), rcDraw);\r
427                                                                 MaskDC.RoundRect(left, top, right, bottom, Curve, Curve);\r
428                                                                 MaskDC.BitBlt(left, top, cx, cy, &MaskDC, left, top, PATINVERT);\r
429                                                         }\r
430 \r
431                                                         // Copy Source DC to Memory DC using the RoundRect mask\r
432                                                         MemDC.BitBlt(left, top, cx, cy, &SourceDC, left, top, SRCINVERT);\r
433                                                         MemDC.BitBlt(left, top, cx, cy, &MaskDC,   left, top, SRCAND);\r
434                                                         MemDC.BitBlt(left, top, cx, cy, &SourceDC, left, top, SRCINVERT);\r
435 \r
436                                                         // Extra drawing to prevent jagged edge while moving bands\r
437                                                         if (m_bIsDragging)\r
438                                                         {\r
439                                                                 CClientDC ReBarDC(this);\r
440                                                                 ReBarDC.BitBlt(rcDraw.right - ChildWidth, rcDraw.top, ChildWidth, cy, &MemDC, rcDraw.right - ChildWidth, rcDraw.top, SRCCOPY);\r
441                                                         }\r
442                                                 }\r
443                                         }\r
444                                 }\r
445                         }\r
446 \r
447                         if (m_Theme.UseLines)\r
448                         {\r
449                                 // Draw lines between bands\r
450                                 for (int j = 0; j < GetBandCount()-1; ++j)\r
451                                 {\r
452                                         rcReBar = GetBandRect(j);\r
453                                         rcReBar.left = MAX(0, rcReBar.left - 4);\r
454                                         rcReBar.bottom +=2;\r
455                                         MemDC.DrawEdge(rcReBar, EDGE_ETCHED, BF_BOTTOM | BF_ADJUST);\r
456                                 }\r
457                         }\r
458 \r
459                         // Copy the Memory DC to the window's DC\r
460                         pDC->BitBlt(0, 0, BarWidth, BarHeight, &MemDC, 0, 0, SRCCOPY);\r
461                 }\r
462                 \r
463                 return Erase;\r
464         }\r
465 \r
466         inline void CReBar::PreCreate(CREATESTRUCT &cs)\r
467         // Sets the CREATESTRUCT paramaters prior to window creation\r
468         {\r
469                 cs.style = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |\r
470                          CCS_NODIVIDER | RBS_VARHEIGHT | RBS_BANDBORDERS ;\r
471 \r
472                 cs.cy = 100;\r
473         }\r
474 \r
475         inline void CReBar::PreRegisterClass(WNDCLASS &wc)\r
476         {\r
477                 // Set the Window Class\r
478                 wc.lpszClassName =  REBARCLASSNAME;\r
479         }\r
480 \r
481         inline void CReBar::MaximizeBand(UINT uBand, BOOL fIdeal /*= FALSE*/)\r
482         // Resizes a band in a rebar control to either its ideal or largest size.\r
483         {\r
484                 assert(::IsWindow(m_hWnd));\r
485                 SendMessage(RB_MAXIMIZEBAND, (WPARAM)uBand, (LPARAM)fIdeal);\r
486         }\r
487 \r
488         inline void CReBar::MinimizeBand(UINT uBand)\r
489         // Resizes a band in a rebar control to its smallest size.\r
490         {\r
491                 assert(::IsWindow(m_hWnd));\r
492                 SendMessage(RB_MINIMIZEBAND, (WPARAM)uBand, 0L);\r
493         }\r
494 \r
495         inline BOOL CReBar::MoveBand(UINT uFrom, UINT uTo)\r
496         // Moves a band from one index to another.\r
497         {\r
498                 assert(::IsWindow(m_hWnd));\r
499                 return (BOOL)SendMessage(RB_MOVEBAND, (WPARAM)uFrom, (LPARAM)uTo);\r
500         }\r
501 \r
502         inline void CReBar::MoveBandsLeft()\r
503         // Repositions the bands so they are left justified\r
504         {\r
505                 assert(::IsWindow(m_hWnd));\r
506 \r
507                 int OldrcTop = -1;\r
508                 for (int nBand = GetBandCount() -1; nBand >= 0; --nBand)\r
509                 {\r
510                         CRect rc = GetBandRect(nBand);\r
511                         if (rc.top != OldrcTop)\r
512                         {\r
513                                 // Maximize the last band on each row\r
514                                 if (IsBandVisible(nBand))\r
515                                 {\r
516                                         ::SendMessage(GetHwnd(), RB_MAXIMIZEBAND, nBand, 0L);\r
517                                         OldrcTop = rc.top;\r
518                                 }\r
519                         }\r
520                 }\r
521         }\r
522 \r
523         inline BOOL CReBar::ResizeBand(int nBand, const CSize& sz) const\r
524         // Sets a band's size\r
525         {\r
526                 assert(::IsWindow(m_hWnd));\r
527 \r
528                 REBARBANDINFO rbbi = {0};\r
529                 rbbi.cbSize = GetSizeofRBBI();\r
530                 rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_SIZE;\r
531 \r
532                 GetBandInfo(nBand, rbbi);\r
533                 rbbi.cx         = sz.cx + 2;\r
534                 rbbi.cxMinChild = sz.cx + 2;\r
535                 rbbi.cyMinChild = sz.cy;\r
536                 rbbi.cyMaxChild = sz.cy;\r
537 \r
538                 return SetBandInfo(nBand, rbbi );\r
539         }\r
540 \r
541         inline BOOL CReBar::SetBandBitmap(int nBand, const CBitmap* pBackground) const\r
542         // Sets the band's bitmaps\r
543         {\r
544                 assert(::IsWindow(m_hWnd));\r
545                 assert(pBackground);\r
546 \r
547                 REBARBANDINFO rbbi = {0};\r
548                 rbbi.cbSize = GetSizeofRBBI();\r
549                 rbbi.fMask  = RBBIM_STYLE;\r
550                 GetBandInfo(nBand, rbbi);\r
551                 rbbi.fMask  |= RBBIM_BACKGROUND;\r
552                 rbbi.hbmBack = *pBackground;\r
553 \r
554                 return (BOOL)SendMessage(RB_SETBANDINFO, nBand, (LPARAM)&rbbi);\r
555         }\r
556 \r
557         inline BOOL CReBar::SetBandColor(int nBand, COLORREF clrFore, COLORREF clrBack) const\r
558         // Sets the band's color\r
559         // Note:        No effect with XP themes enabled\r
560         //                      No effect if a bitmap has been set\r
561         {\r
562                 assert(::IsWindow(m_hWnd));\r
563 \r
564                 REBARBANDINFO rbbi = {0};\r
565                 rbbi.cbSize = GetSizeofRBBI();\r
566                 rbbi.fMask = RBBIM_COLORS;\r
567                 rbbi.clrFore = clrFore;\r
568                 rbbi.clrBack = clrBack;\r
569 \r
570                 return (BOOL)SendMessage(RB_SETBANDINFO, nBand, (LPARAM)&rbbi);\r
571         }\r
572 \r
573         inline BOOL CReBar::SetBandInfo(int nBand, REBARBANDINFO& rbbi) const\r
574         // Sets the characteristics of a rebar control.\r
575         {\r
576                 assert(::IsWindow(m_hWnd));\r
577                 assert(nBand >= 0);\r
578 \r
579                 // REBARBANDINFO describes individual BAND characteristics0\r
580                 rbbi.cbSize = GetSizeofRBBI();\r
581                 return (BOOL)SendMessage(RB_SETBANDINFO, nBand, (LPARAM)&rbbi);\r
582         }\r
583 \r
584         inline BOOL CReBar::SetBarInfo(REBARINFO& rbi) const\r
585         // REBARINFO associates an image list with the rebar\r
586         // A band will also need to set RBBIM_IMAGE\r
587         {\r
588                 assert(::IsWindow(m_hWnd));\r
589 \r
590                 rbi.cbSize = GetSizeofRBBI();\r
591                 return (BOOL)SendMessage(RB_SETBARINFO, 0L, (LPARAM)&rbi);\r
592         }\r
593 \r
594         inline void CReBar::SetReBarTheme(ReBarTheme& Theme)\r
595         {\r
596                 m_Theme.UseThemes    = Theme.UseThemes;\r
597                 m_Theme.clrBkgnd1    = Theme.clrBkgnd1;\r
598                 m_Theme.clrBkgnd2    = Theme.clrBkgnd2;\r
599                 m_Theme.clrBand1     = Theme.clrBand1;\r
600                 m_Theme.clrBand2     = Theme.clrBand2;\r
601                 m_Theme.BandsLeft    = Theme.BandsLeft;\r
602                 m_Theme.LockMenuBand = Theme.LockMenuBand;\r
603                 m_Theme.ShortBands   = Theme.ShortBands;\r
604                 m_Theme.UseLines     = Theme.UseLines;\r
605                 m_Theme.FlatStyle    = Theme.FlatStyle;\r
606                 m_Theme.RoundBorders = Theme.RoundBorders;\r
607 \r
608                 if (IsWindow())\r
609                 {\r
610                         if (m_Theme.LockMenuBand)\r
611                                 ShowGripper(GetBand(m_hMenuBar), FALSE);\r
612                         else\r
613                                 ShowGripper(GetBand(m_hMenuBar), TRUE);\r
614                 \r
615                         Invalidate();\r
616                 }\r
617         }\r
618 \r
619         inline BOOL CReBar::ShowBand(int nBand, BOOL fShow) const\r
620         // Show or hide a band\r
621         {\r
622                 assert(::IsWindow(m_hWnd));\r
623                 return (BOOL)SendMessage(RB_SHOWBAND, (WPARAM)nBand, (LPARAM)fShow);\r
624         }\r
625 \r
626         inline BOOL CReBar::ShowGripper(int nBand, BOOL fShow) const\r
627         // Show or hide the band's gripper\r
628         {\r
629                 assert(::IsWindow(m_hWnd));\r
630 \r
631                 REBARBANDINFO rbbi = {0};\r
632                 rbbi.cbSize = GetSizeofRBBI();\r
633                 rbbi.fMask = RBBIM_STYLE;\r
634                 GetBandInfo(nBand, rbbi);\r
635                 if (fShow)\r
636                 {\r
637                         rbbi.fStyle |= RBBS_GRIPPERALWAYS;\r
638                         rbbi.fStyle &= ~RBBS_NOGRIPPER;\r
639                 }\r
640                 else\r
641                 {\r
642                         rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;\r
643                         rbbi.fStyle |= RBBS_NOGRIPPER;\r
644                 }\r
645 \r
646                 return SetBandInfo(nBand, rbbi);\r
647         }\r
648 \r
649         inline BOOL CReBar::SizeToRect(CRect& rect) const\r
650         // Attempts to find the best layout of the bands for the given rectangle.\r
651         // The rebar bands will be arranged and wrapped as necessary to fit the rectangle.\r
652         {\r
653                 assert(::IsWindow(m_hWnd));\r
654                 return (BOOL)SendMessage(RB_SIZETORECT, 0, (LPARAM) (LPRECT)rect);\r
655         }\r
656 \r
657         inline void CReBar::SetToolTips(CToolTip* pToolTip) const\r
658         // Associates a ToolTip control with the rebar control. \r
659         {\r
660                 assert(::IsWindow(m_hWnd));\r
661                 HWND hToolTip = pToolTip? pToolTip->GetHwnd() : (HWND)0;\r
662                 SendMessage(RB_SETTOOLTIPS, WPARAM(hToolTip), 0);\r
663         }\r
664 \r
665         inline LRESULT CReBar::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
666         {\r
667                 switch (uMsg)\r
668                 {\r
669                 case WM_MOUSEMOVE:\r
670                         if (m_Theme.UseThemes && m_Theme.LockMenuBand)\r
671                         {\r
672                                 // We want to lock the first row in place, but allow other bands to move!\r
673                                 // Use move messages to limit the resizing of bands\r
674                                 int y = GET_Y_LPARAM(lParam);\r
675 \r
676                                 if (y <= GetRowHeight(0))\r
677                                         return 0L;      // throw this message away\r
678                         }\r
679                         break;\r
680                 case WM_LBUTTONDOWN:\r
681                         m_Orig_lParam = lParam; // Store the x,y position\r
682                         m_bIsDragging = TRUE;\r
683                         break;\r
684                 case WM_LBUTTONUP:\r
685                         if (m_Theme.UseThemes && m_Theme.LockMenuBand)\r
686                         {\r
687                                 // Use move messages to limit the resizing of bands\r
688                                 int y = GET_Y_LPARAM(lParam);\r
689 \r
690                                 if (y <= GetRowHeight(0))\r
691                                 {\r
692                                         // Use x,y from WM_LBUTTONDOWN for WM_LBUTTONUP position\r
693                                         lParam = m_Orig_lParam;\r
694                                 }\r
695                         }\r
696                         m_bIsDragging = FALSE;\r
697                         break;\r
698                 case UWM_GETREBARTHEME:\r
699                         {\r
700                                 ReBarTheme& rm = GetReBarTheme();\r
701                                 return (LRESULT)&rm;\r
702                         }\r
703                 case UWM_TOOLBAR_RESIZE:\r
704                         {\r
705                                 HWND hToolBar = (HWND)wParam;\r
706                                 LPSIZE pToolBarSize = (LPSIZE)lParam;\r
707                                 ResizeBand(GetBand(hToolBar), *pToolBarSize);\r
708                         }\r
709                         break;\r
710                 }\r
711 \r
712                 // pass unhandled messages on for default processing\r
713                 return CWnd::WndProcDefault(uMsg, wParam, lParam);\r
714         }\r
715 \r
716 } // namespace Win32xx\r
717 \r
718 #endif // #ifndef _WIN32XX_REBAR_H_\r

UCC git Repository :: git.ucc.asn.au