Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / statusbar.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_STATUSBAR_H_\r
39 #define _WIN32XX_STATUSBAR_H_\r
40 \r
41 #include "wincore.h"\r
42 \r
43 namespace Win32xx\r
44 {\r
45 \r
46         //////////////////////////////////////\r
47         // Declaration of the CStatusBar class\r
48         //\r
49         class CStatusBar : public CWnd\r
50         {\r
51         public:\r
52                 CStatusBar();\r
53                 virtual ~CStatusBar() {}\r
54 \r
55         // Overridables\r
56                 virtual void PreCreate(CREATESTRUCT& cs);\r
57                 virtual void PreRegisterClass(WNDCLASS &wc);\r
58 \r
59         // Attributes\r
60                 int GetParts();\r
61                 HICON GetPartIcon(int iPart);\r
62                 CRect GetPartRect(int iPart);\r
63                 CString GetPartText(int iPart) const;\r
64                 BOOL IsSimple();\r
65                 BOOL SetPartIcon(int iPart, HICON hIcon);\r
66                 BOOL SetPartText(int iPart, LPCTSTR szText, UINT Style = 0) const;\r
67                 BOOL SetPartWidth(int iPart, int iWidth) const;\r
68 \r
69         // Operations\r
70                 CStatusBar(const CStatusBar&);                          // Disable copy construction\r
71                 CStatusBar& operator = (const CStatusBar&); // Disable assignment operator\r
72 \r
73                 BOOL CreateParts(int iParts, const int iPaneWidths[]) const;\r
74                 void SetSimple(BOOL fSimple = TRUE);\r
75         };\r
76 \r
77 }\r
78 \r
79 \r
80 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
81 \r
82 \r
83 namespace Win32xx\r
84 {\r
85 \r
86         //////////////////////////////////////\r
87         // Definitions for the CStatusBar class\r
88         //\r
89         inline CStatusBar::CStatusBar()\r
90         {\r
91         }\r
92 \r
93         inline BOOL CStatusBar::CreateParts(int iParts, const int iPaneWidths[]) const\r
94         // Sets the number of parts in a status window and the coordinate of the right edge of each part. \r
95         // If an element of iPaneWidths is -1, the right edge of the corresponding part extends\r
96         //  to the border of the window\r
97         {\r
98                 assert(::IsWindow(m_hWnd));\r
99                 assert(iParts <= 256);  \r
100                 \r
101                 return (BOOL)SendMessage(SB_SETPARTS, iParts, (LPARAM)iPaneWidths);             \r
102         }\r
103 \r
104         inline int CStatusBar::GetParts()\r
105         {\r
106                 assert(::IsWindow(m_hWnd));\r
107                 return (int)SendMessage(SB_GETPARTS, 0L, 0L);\r
108         }\r
109 \r
110         inline HICON CStatusBar::GetPartIcon(int iPart)\r
111         {\r
112                 assert(::IsWindow(m_hWnd));\r
113                 return (HICON)SendMessage(SB_GETICON, (WPARAM)iPart, 0L);\r
114         }\r
115 \r
116         inline CRect CStatusBar::GetPartRect(int iPart)\r
117         {\r
118                 assert(::IsWindow(m_hWnd));\r
119                 \r
120                 CRect rc;\r
121                 SendMessage(SB_GETRECT, (WPARAM)iPart, (LPARAM)&rc);\r
122                 return rc;\r
123         }\r
124 \r
125         inline CString CStatusBar::GetPartText(int iPart) const\r
126         {\r
127                 assert(::IsWindow(m_hWnd));\r
128                 CString PaneText;\r
129                 \r
130                 // Get size of Text array\r
131                 int iChars = LOWORD (SendMessage(SB_GETTEXTLENGTH, iPart, 0L));\r
132 \r
133                 std::vector<TCHAR> Text( iChars +1, _T('\0') );\r
134                 TCHAR* pTextArray = &Text[0];\r
135 \r
136                 SendMessage(SB_GETTEXT, iPart, (LPARAM)pTextArray);\r
137                 PaneText = pTextArray;                  \r
138                 return PaneText;\r
139         }\r
140 \r
141         inline BOOL CStatusBar::IsSimple()\r
142         {\r
143                 assert(::IsWindow(m_hWnd));\r
144                 return (BOOL)SendMessage(SB_ISSIMPLE, 0L, 0L);\r
145         }\r
146 \r
147         inline void CStatusBar::PreCreate(CREATESTRUCT &cs)\r
148         {\r
149                 cs.style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CCS_BOTTOM | SBARS_SIZEGRIP;\r
150         }\r
151 \r
152         inline void CStatusBar::PreRegisterClass(WNDCLASS &wc)\r
153         {\r
154                 // Set the Window Class\r
155                 wc.lpszClassName =  STATUSCLASSNAME;\r
156         }\r
157 \r
158         inline BOOL CStatusBar::SetPartText(int iPart, LPCTSTR szText, UINT Style) const\r
159         // Available Styles: Combinations of ...\r
160         //0                                     The text is drawn with a border to appear lower than the plane of the window.\r
161         //SBT_NOBORDERS         The text is drawn without borders.\r
162         //SBT_OWNERDRAW         The text is drawn by the parent window.\r
163         //SBT_POPOUT            The text is drawn with a border to appear higher than the plane of the window.\r
164         //SBT_RTLREADING        The text will be displayed in the opposite direction to the text in the parent window.\r
165         {\r
166                 assert(::IsWindow(m_hWnd));\r
167                 \r
168                 BOOL bResult = FALSE;\r
169                 if (SendMessage(SB_GETPARTS, 0L, 0L) >= iPart)\r
170                         bResult = (BOOL)SendMessage(SB_SETTEXT, iPart | Style, (LPARAM)szText);\r
171 \r
172                 return bResult;\r
173         }\r
174 \r
175         inline BOOL CStatusBar::SetPartIcon(int iPart, HICON hIcon)\r
176         {\r
177                 assert(::IsWindow(m_hWnd));\r
178                 return (BOOL)SendMessage(SB_SETICON, (WPARAM)iPart, (LPARAM) hIcon);\r
179         }\r
180 \r
181         inline BOOL CStatusBar::SetPartWidth(int iPart, int iWidth) const\r
182         {\r
183                 // This changes the width of an existing pane, or creates a new pane\r
184                 // with the specified width.\r
185                 // A width of -1 for the last part sets the width to the border of the window.\r
186 \r
187                 assert(::IsWindow(m_hWnd));\r
188                 assert(iPart >= 0 && iPart <= 255);\r
189 \r
190                 // Fill the PartWidths vector with the current width of the statusbar parts\r
191                 int PartsCount = (int)SendMessage(SB_GETPARTS, 0L, 0L);\r
192                 std::vector<int> PartWidths(PartsCount, 0);\r
193                 int* pPartWidthArray = &PartWidths[0];\r
194                 SendMessage(SB_GETPARTS, PartsCount, (LPARAM)pPartWidthArray);\r
195 \r
196                 // Fill the NewPartWidths vector with the new width of the statusbar parts\r
197                 int NewPartsCount = MAX(iPart+1, PartsCount);   \r
198                 std::vector<int> NewPartWidths(NewPartsCount, 0);;\r
199                 NewPartWidths = PartWidths;\r
200                 int* pNewPartWidthArray = &NewPartWidths[0];\r
201                 \r
202                 if (0 == iPart)\r
203                         pNewPartWidthArray[iPart] = iWidth;\r
204                 else\r
205                 {\r
206                         if (iWidth >= 0)\r
207                                 pNewPartWidthArray[iPart] = pNewPartWidthArray[iPart -1] + iWidth;\r
208                         else\r
209                                 pNewPartWidthArray[iPart] = -1;\r
210                 }\r
211 \r
212                 // Set the statusbar parts with our new parts count and part widths\r
213                 BOOL bResult = (BOOL)SendMessage(SB_SETPARTS, NewPartsCount, (LPARAM)pNewPartWidthArray);\r
214 \r
215                 return bResult;\r
216         }\r
217 \r
218         inline void CStatusBar::SetSimple(BOOL fSimple /* = TRUE*/)\r
219         {\r
220                 assert(::IsWindow(m_hWnd));\r
221                 SendMessage(SB_SIMPLE, (WPARAM)fSimple, 0L);\r
222         }\r
223 \r
224 } // namespace Win32xx\r
225 \r
226 #endif // #ifndef _WIN32XX_STATUSBAR_H_\r

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