]>
Commit | Line | Data |
---|---|---|
88310e2e VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: Vadim Zeitlin | |
907f37b3 | 5 | // Modified by: |
88310e2e VZ |
6 | // Created: 11.06.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
6c9a19aa | 9 | // Licence: wxWindows licence |
88310e2e VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a3b46648 | 13 | #pragma implementation "notebook.h" |
88310e2e VZ |
14 | #endif |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
1e6feb95 | 20 | #pragma hdrstop |
88310e2e VZ |
21 | #endif |
22 | ||
1e6feb95 VZ |
23 | #if wxUSE_NOTEBOOK |
24 | ||
88310e2e VZ |
25 | // wxWindows |
26 | #ifndef WX_PRECOMP | |
3096bd2f | 27 | #include "wx/string.h" |
88310e2e VZ |
28 | #endif // WX_PRECOMP |
29 | ||
3096bd2f VZ |
30 | #include "wx/log.h" |
31 | #include "wx/imaglist.h" | |
32 | #include "wx/event.h" | |
33 | #include "wx/control.h" | |
34 | #include "wx/notebook.h" | |
04eb05b0 | 35 | #include "wx/app.h" |
88310e2e | 36 | |
3096bd2f | 37 | #include "wx/msw/private.h" |
88310e2e VZ |
38 | |
39 | // Windows standard headers | |
40 | #ifndef __WIN95__ | |
2432b92d | 41 | #error "wxNotebook is only supported Windows 95 and above" |
88310e2e VZ |
42 | #endif //Win95 |
43 | ||
aaab7c01 VZ |
44 | #include <windowsx.h> // for SetWindowFont |
45 | ||
b39dbf34 JS |
46 | #ifdef __GNUWIN32_OLD__ |
47 | #include "wx/msw/gnuwin32/extra.h" | |
65fd5cb0 | 48 | #endif |
57c208c5 | 49 | |
b39dbf34 | 50 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) |
c42404a5 | 51 | #include <commctrl.h> |
88310e2e VZ |
52 | #endif |
53 | ||
85b43fbf JS |
54 | #include "wx/msw/winundef.h" |
55 | ||
56 | #if wxUSE_UXTHEME | |
57 | #include "wx/msw/uxtheme.h" | |
58 | ||
59 | #include "wx/radiobut.h" | |
60 | #include "wx/radiobox.h" | |
61 | #include "wx/checkbox.h" | |
62 | #include "wx/bmpbuttn.h" | |
63 | #include "wx/statline.h" | |
64 | #include "wx/statbox.h" | |
65 | #include "wx/stattext.h" | |
66 | #include "wx/slider.h" | |
67 | #include "wx/scrolwin.h" | |
68 | #include "wx/panel.h" | |
69 | #endif | |
70 | ||
88310e2e VZ |
71 | // ---------------------------------------------------------------------------- |
72 | // macros | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | // check that the page index is valid | |
8d34bf5c | 76 | #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) |
88310e2e VZ |
77 | |
78 | // hide the ugly cast | |
79 | #define m_hwnd (HWND)GetHWND() | |
80 | ||
74b31181 VZ |
81 | // ---------------------------------------------------------------------------- |
82 | // constants | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | // This is a work-around for missing defines in gcc-2.95 headers | |
86 | #ifndef TCS_RIGHT | |
87 | #define TCS_RIGHT 0x0002 | |
88 | #endif | |
89 | ||
90 | #ifndef TCS_VERTICAL | |
91 | #define TCS_VERTICAL 0x0080 | |
92 | #endif | |
93 | ||
94 | #ifndef TCS_BOTTOM | |
95 | #define TCS_BOTTOM TCS_RIGHT | |
96 | #endif | |
97 | ||
88310e2e VZ |
98 | // ---------------------------------------------------------------------------- |
99 | // event table | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
51741307 SC |
102 | #include <wx/listimpl.cpp> |
103 | ||
104 | WX_DEFINE_LIST( wxNotebookPageInfoList ) ; | |
105 | ||
2e4df4bf VZ |
106 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
107 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
108 | ||
d9317fd4 | 109 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
88310e2e VZ |
110 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) |
111 | ||
9026ad85 | 112 | EVT_SIZE(wxNotebook::OnSize) |
42e69d6b | 113 | |
88310e2e | 114 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) |
d9317fd4 | 115 | END_EVENT_TABLE() |
88310e2e | 116 | |
51596bcb | 117 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
118 | WX_DEFINE_FLAGS( wxNotebookStyle ) |
119 | ||
3ff066a4 | 120 | wxBEGIN_FLAGS( wxNotebookStyle ) |
bc9fb572 JS |
121 | // new style border flags, we put them first to |
122 | // use them for streaming out | |
3ff066a4 SC |
123 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
124 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
125 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
126 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
127 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
128 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
bc9fb572 JS |
129 | |
130 | // old style border flags | |
3ff066a4 SC |
131 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
132 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
133 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
134 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
135 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 136 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
137 | |
138 | // standard window styles | |
3ff066a4 SC |
139 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
140 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
141 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
142 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 143 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
144 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
145 | wxFLAGS_MEMBER(wxVSCROLL) | |
146 | wxFLAGS_MEMBER(wxHSCROLL) | |
147 | ||
148 | wxFLAGS_MEMBER(wxNB_FIXEDWIDTH) | |
149 | wxFLAGS_MEMBER(wxNB_LEFT) | |
150 | wxFLAGS_MEMBER(wxNB_RIGHT) | |
151 | wxFLAGS_MEMBER(wxNB_BOTTOM) | |
152 | ||
153 | wxEND_FLAGS( wxNotebookStyle ) | |
51741307 | 154 | |
51596bcb | 155 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h") |
51741307 SC |
156 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject , "wx/notebook.h" ) |
157 | ||
3ff066a4 | 158 | wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo * , wxNotebookPageInfoList ) ; |
51596bcb | 159 | |
f0a126fe SC |
160 | template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, wxxVariantArray &value) |
161 | { | |
0c6b0084 | 162 | wxListCollectionToVariantArray<wxNotebookPageInfoList::compatibility_iterator>( theList , value ) ; |
f0a126fe SC |
163 | } |
164 | ||
3ff066a4 SC |
165 | wxBEGIN_PROPERTIES_TABLE(wxNotebook) |
166 | wxEVENT_PROPERTY( PageChanging , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING , wxNotebookEvent ) | |
167 | wxEVENT_PROPERTY( PageChanged , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED , wxNotebookEvent ) | |
c5ca409b | 168 | |
3ff066a4 SC |
169 | wxPROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
170 | wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
171 | wxEND_PROPERTIES_TABLE() | |
51596bcb | 172 | |
3ff066a4 SC |
173 | wxBEGIN_HANDLERS_TABLE(wxNotebook) |
174 | wxEND_HANDLERS_TABLE() | |
51596bcb | 175 | |
3ff066a4 | 176 | wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51596bcb | 177 | |
51741307 | 178 | |
3ff066a4 SC |
179 | wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo) |
180 | wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
181 | wxREADONLY_PROPERTY( Text , wxString , GetText , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
182 | wxREADONLY_PROPERTY( Selected , bool , GetSelected , false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) | |
183 | wxREADONLY_PROPERTY( ImageId , int , GetImageId , -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
184 | wxEND_PROPERTIES_TABLE() | |
51741307 | 185 | |
3ff066a4 SC |
186 | wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo) |
187 | wxEND_HANDLERS_TABLE() | |
51741307 | 188 | |
3ff066a4 | 189 | wxCONSTRUCTOR_4( wxNotebookPageInfo , wxNotebookPage* , Page , wxString , Text , bool , Selected , int , ImageId ) |
51741307 | 190 | |
51596bcb | 191 | #else |
d9317fd4 | 192 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) |
51741307 | 193 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo, wxObject ) |
51596bcb | 194 | #endif |
d9317fd4 | 195 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) |
88310e2e VZ |
196 | |
197 | // ============================================================================ | |
198 | // implementation | |
199 | // ============================================================================ | |
200 | ||
201 | // ---------------------------------------------------------------------------- | |
202 | // wxNotebook construction | |
203 | // ---------------------------------------------------------------------------- | |
204 | ||
51741307 SC |
205 | const wxNotebookPageInfoList& wxNotebook::GetPageInfos() const |
206 | { | |
207 | wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos ) ; | |
208 | WX_CLEAR_LIST( wxNotebookPageInfoList , *list ) ; | |
34a0c9f4 | 209 | for( size_t i = 0 ; i < GetPageCount() ; ++i ) |
51741307 SC |
210 | { |
211 | wxNotebookPageInfo *info = new wxNotebookPageInfo() ; | |
34a0c9f4 | 212 | info->Create( const_cast<wxNotebook*>(this)->GetPage(i) , GetPageText(i) , GetSelection() == int(i) , GetPageImage(i) ) ; |
51741307 SC |
213 | list->Append( info ) ; |
214 | } | |
215 | return m_pageInfos ; | |
216 | } | |
217 | ||
88310e2e VZ |
218 | // common part of all ctors |
219 | void wxNotebook::Init() | |
220 | { | |
1e6feb95 | 221 | m_imageList = NULL; |
88310e2e VZ |
222 | m_nSelection = -1; |
223 | } | |
224 | ||
225 | // default for dynamic class | |
226 | wxNotebook::wxNotebook() | |
227 | { | |
228 | Init(); | |
229 | } | |
230 | ||
231 | // the same arguments as for wxControl | |
232 | wxNotebook::wxNotebook(wxWindow *parent, | |
8b9518ee | 233 | wxWindowID id, |
88310e2e VZ |
234 | const wxPoint& pos, |
235 | const wxSize& size, | |
8b9518ee | 236 | long style, |
88310e2e VZ |
237 | const wxString& name) |
238 | { | |
239 | Init(); | |
240 | ||
241 | Create(parent, id, pos, size, style, name); | |
242 | } | |
243 | ||
244 | // Create() function | |
245 | bool wxNotebook::Create(wxWindow *parent, | |
8b9518ee | 246 | wxWindowID id, |
88310e2e VZ |
247 | const wxPoint& pos, |
248 | const wxSize& size, | |
8b9518ee | 249 | long style, |
88310e2e VZ |
250 | const wxString& name) |
251 | { | |
04eb05b0 JS |
252 | // Does ComCtl32 support non-top tabs? |
253 | int verComCtl32 = wxApp::GetComCtl32Version(); | |
254 | if ( verComCtl32 < 470 || verComCtl32 >= 600 ) | |
255 | { | |
256 | if (style & wxNB_BOTTOM) | |
257 | style &= ~wxNB_BOTTOM; | |
258 | ||
259 | if (style & wxNB_LEFT) | |
260 | style &= ~wxNB_LEFT; | |
261 | ||
262 | if (style & wxNB_RIGHT) | |
263 | style &= ~wxNB_RIGHT; | |
264 | } | |
265 | ||
6dd16e4f VZ |
266 | if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL, |
267 | wxDefaultValidator, name) ) | |
b8bdaa7c | 268 | return false; |
88310e2e | 269 | |
fda7962d | 270 | if ( !MSWCreateControl(WC_TABCONTROL, wxEmptyString, pos, size) ) |
b8bdaa7c | 271 | return false; |
907f37b3 | 272 | |
0df3fbd7 VZ |
273 | SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE))); |
274 | ||
b8bdaa7c | 275 | return true; |
0df3fbd7 VZ |
276 | } |
277 | ||
278 | WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const | |
279 | { | |
280 | WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle); | |
281 | ||
282 | tabStyle |= WS_TABSTOP | TCS_TABS; | |
283 | ||
2b5f62a0 | 284 | if ( style & wxNB_MULTILINE ) |
0df3fbd7 VZ |
285 | tabStyle |= TCS_MULTILINE; |
286 | if ( style & wxNB_FIXEDWIDTH ) | |
287 | tabStyle |= TCS_FIXEDWIDTH; | |
288 | ||
289 | if ( style & wxNB_BOTTOM ) | |
290 | tabStyle |= TCS_RIGHT; | |
291 | else if ( style & wxNB_LEFT ) | |
292 | tabStyle |= TCS_VERTICAL; | |
293 | else if ( style & wxNB_RIGHT ) | |
294 | tabStyle |= TCS_VERTICAL | TCS_RIGHT; | |
295 | ||
296 | // ex style | |
297 | if ( exstyle ) | |
298 | { | |
299 | // note that we never want to have the default WS_EX_CLIENTEDGE style | |
300 | // as it looks too ugly for the notebooks | |
301 | *exstyle = 0; | |
302 | } | |
303 | ||
304 | return tabStyle; | |
88310e2e VZ |
305 | } |
306 | ||
88310e2e VZ |
307 | // ---------------------------------------------------------------------------- |
308 | // wxNotebook accessors | |
309 | // ---------------------------------------------------------------------------- | |
07b8d7ec | 310 | |
8d34bf5c | 311 | size_t wxNotebook::GetPageCount() const |
88310e2e VZ |
312 | { |
313 | // consistency check | |
1e6feb95 | 314 | wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) ); |
88310e2e | 315 | |
1e6feb95 | 316 | return m_pages.Count(); |
88310e2e VZ |
317 | } |
318 | ||
319 | int wxNotebook::GetRowCount() const | |
320 | { | |
321 | return TabCtrl_GetRowCount(m_hwnd); | |
322 | } | |
323 | ||
8d34bf5c | 324 | int wxNotebook::SetSelection(size_t nPage) |
88310e2e | 325 | { |
223d09f6 | 326 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
88310e2e | 327 | |
34a0c9f4 | 328 | if ( int(nPage) != m_nSelection ) |
2b5f62a0 VZ |
329 | { |
330 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); | |
331 | event.SetSelection(nPage); | |
332 | event.SetOldSelection(m_nSelection); | |
333 | event.SetEventObject(this); | |
334 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
335 | { | |
336 | // program allows the page change | |
337 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
338 | (void)GetEventHandler()->ProcessEvent(event); | |
339 | ||
340 | TabCtrl_SetCurSel(m_hwnd, nPage); | |
341 | } | |
342 | } | |
88310e2e | 343 | |
2b5f62a0 | 344 | return m_nSelection; |
88310e2e VZ |
345 | } |
346 | ||
8d34bf5c | 347 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) |
88310e2e | 348 | { |
b8bdaa7c | 349 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e VZ |
350 | |
351 | TC_ITEM tcItem; | |
352 | tcItem.mask = TCIF_TEXT; | |
837e5743 | 353 | tcItem.pszText = (wxChar *)strText.c_str(); |
88310e2e VZ |
354 | |
355 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
356 | } | |
357 | ||
8d34bf5c | 358 | wxString wxNotebook::GetPageText(size_t nPage) const |
88310e2e | 359 | { |
fda7962d | 360 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); |
88310e2e | 361 | |
837e5743 | 362 | wxChar buf[256]; |
88310e2e VZ |
363 | TC_ITEM tcItem; |
364 | tcItem.mask = TCIF_TEXT; | |
365 | tcItem.pszText = buf; | |
366 | tcItem.cchTextMax = WXSIZEOF(buf); | |
367 | ||
368 | wxString str; | |
369 | if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ) | |
370 | str = tcItem.pszText; | |
371 | ||
372 | return str; | |
373 | } | |
374 | ||
8d34bf5c | 375 | int wxNotebook::GetPageImage(size_t nPage) const |
88310e2e | 376 | { |
223d09f6 | 377 | wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") ); |
88310e2e VZ |
378 | |
379 | TC_ITEM tcItem; | |
380 | tcItem.mask = TCIF_IMAGE; | |
381 | ||
382 | return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1; | |
383 | } | |
384 | ||
8d34bf5c | 385 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) |
88310e2e | 386 | { |
b8bdaa7c | 387 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e VZ |
388 | |
389 | TC_ITEM tcItem; | |
390 | tcItem.mask = TCIF_IMAGE; | |
391 | tcItem.iImage = nImage; | |
392 | ||
393 | return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0; | |
394 | } | |
395 | ||
396 | void wxNotebook::SetImageList(wxImageList* imageList) | |
907f37b3 | 397 | { |
07b8d7ec VZ |
398 | wxNotebookBase::SetImageList(imageList); |
399 | ||
400 | if ( imageList ) | |
1e6feb95 | 401 | { |
07b8d7ec | 402 | TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST()); |
1e6feb95 | 403 | } |
b656febd VS |
404 | } |
405 | ||
d9506e77 VZ |
406 | // ---------------------------------------------------------------------------- |
407 | // wxNotebook size settings | |
408 | // ---------------------------------------------------------------------------- | |
409 | ||
410 | void wxNotebook::SetPageSize(const wxSize& size) | |
411 | { | |
412 | // transform the page size into the notebook size | |
413 | RECT rc; | |
414 | rc.left = | |
415 | rc.top = 0; | |
416 | rc.right = size.x; | |
417 | rc.bottom = size.y; | |
418 | ||
b8bdaa7c | 419 | TabCtrl_AdjustRect(GetHwnd(), true, &rc); |
d9506e77 VZ |
420 | |
421 | // and now set it | |
422 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
423 | } | |
424 | ||
425 | void wxNotebook::SetPadding(const wxSize& padding) | |
426 | { | |
427 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
428 | } | |
42e69d6b VZ |
429 | |
430 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
431 | // style. | |
432 | void wxNotebook::SetTabSize(const wxSize& sz) | |
433 | { | |
434 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
435 | } | |
436 | ||
2ce7af35 JS |
437 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const |
438 | { | |
439 | wxSize sizeTotal = sizePage; | |
440 | ||
441 | // We need to make getting tab size part of the wxWindows API. | |
442 | wxSize tabSize(0, 0); | |
443 | if (GetPageCount() > 0) | |
444 | { | |
445 | RECT rect; | |
446 | TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect); | |
447 | tabSize.x = rect.right - rect.left; | |
448 | tabSize.y = rect.bottom - rect.top; | |
449 | } | |
450 | if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) ) | |
451 | { | |
452 | sizeTotal.x += tabSize.x + 7; | |
453 | sizeTotal.y += 7; | |
454 | } | |
455 | else | |
456 | { | |
457 | sizeTotal.x += 7; | |
458 | sizeTotal.y += tabSize.y + 7; | |
459 | } | |
460 | ||
461 | return sizeTotal; | |
462 | } | |
463 | ||
2015f2b3 VZ |
464 | void wxNotebook::AdjustPageSize(wxNotebookPage *page) |
465 | { | |
466 | wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") ); | |
467 | ||
468 | RECT rc; | |
469 | rc.left = | |
470 | rc.top = 0; | |
471 | ||
472 | // get the page size from the notebook size | |
473 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
b8bdaa7c | 474 | TabCtrl_AdjustRect(m_hwnd, false, &rc); |
2015f2b3 VZ |
475 | |
476 | page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); | |
477 | } | |
478 | ||
88310e2e VZ |
479 | // ---------------------------------------------------------------------------- |
480 | // wxNotebook operations | |
481 | // ---------------------------------------------------------------------------- | |
482 | ||
621793f4 | 483 | // remove one page from the notebook, without deleting |
8d34bf5c | 484 | wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) |
621793f4 | 485 | { |
df7145da VZ |
486 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); |
487 | if ( !pageRemoved ) | |
488 | return NULL; | |
621793f4 | 489 | |
df7145da | 490 | TabCtrl_DeleteItem(m_hwnd, nPage); |
621793f4 | 491 | |
df7145da VZ |
492 | if ( m_pages.IsEmpty() ) |
493 | { | |
494 | // no selection any more, the notebook becamse empty | |
495 | m_nSelection = -1; | |
496 | } | |
497 | else // notebook still not empty | |
498 | { | |
43a997b6 VZ |
499 | // change the selected page if it was deleted or became invalid |
500 | int selNew; | |
34a0c9f4 | 501 | if ( m_nSelection == int(GetPageCount()) ) |
df7145da | 502 | { |
43a997b6 VZ |
503 | // last page deleted, make the new last page the new selection |
504 | selNew = m_nSelection - 1; | |
df7145da | 505 | } |
34a0c9f4 | 506 | else if ( int(nPage) <= m_nSelection ) |
43a997b6 VZ |
507 | { |
508 | // we must show another page, even if it has the same index | |
509 | selNew = m_nSelection; | |
510 | } | |
511 | else // nothing changes for the currently selected page | |
512 | { | |
513 | selNew = -1; | |
df7145da | 514 | |
43a997b6 VZ |
515 | // we still must refresh the current page: this needs to be done |
516 | // for some unknown reason if the tab control shows the up-down | |
517 | // control (i.e. when there are too many pages) -- otherwise after | |
518 | // deleting a page nothing at all is shown | |
68d31398 JS |
519 | if (m_nSelection >= 0) |
520 | m_pages[m_nSelection]->Refresh(); | |
43a997b6 VZ |
521 | } |
522 | ||
523 | if ( selNew != -1 ) | |
524 | { | |
525 | // m_nSelection must be always valid so reset it before calling | |
526 | // SetSelection() | |
527 | m_nSelection = -1; | |
528 | SetSelection(selNew); | |
529 | } | |
df7145da | 530 | } |
47f12f58 | 531 | |
df7145da | 532 | return pageRemoved; |
621793f4 JS |
533 | } |
534 | ||
88310e2e VZ |
535 | // remove all pages |
536 | bool wxNotebook::DeleteAllPages() | |
537 | { | |
8d34bf5c VZ |
538 | size_t nPageCount = GetPageCount(); |
539 | size_t nPage; | |
88310e2e | 540 | for ( nPage = 0; nPage < nPageCount; nPage++ ) |
1e6feb95 | 541 | delete m_pages[nPage]; |
88310e2e | 542 | |
1e6feb95 | 543 | m_pages.Clear(); |
88310e2e | 544 | |
907f37b3 VZ |
545 | TabCtrl_DeleteAllItems(m_hwnd); |
546 | ||
47f12f58 JS |
547 | m_nSelection = -1; |
548 | ||
b8bdaa7c | 549 | return true; |
88310e2e VZ |
550 | } |
551 | ||
88310e2e | 552 | // same as AddPage() but does it at given position |
8d34bf5c | 553 | bool wxNotebook::InsertPage(size_t nPage, |
88310e2e VZ |
554 | wxNotebookPage *pPage, |
555 | const wxString& strText, | |
556 | bool bSelect, | |
557 | int imageId) | |
558 | { | |
b8bdaa7c VZ |
559 | wxCHECK_MSG( pPage != NULL, false, _T("NULL page in wxNotebook::InsertPage") ); |
560 | wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false, | |
22f3361e | 561 | _T("invalid index in wxNotebook::InsertPage") ); |
88310e2e | 562 | |
efa14cf2 VZ |
563 | wxASSERT_MSG( pPage->GetParent() == this, |
564 | _T("notebook pages must have notebook as parent") ); | |
43427087 | 565 | |
85b43fbf | 566 | #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO |
b8bdaa7c VZ |
567 | static bool g_TestedForTheme = false; |
568 | static bool g_UseTheme = false; | |
c02e5a31 JS |
569 | if (!g_TestedForTheme) |
570 | { | |
571 | int commCtrlVersion = wxTheApp->GetComCtl32Version() ; | |
572 | ||
573 | g_UseTheme = (commCtrlVersion >= 600); | |
b8bdaa7c | 574 | g_TestedForTheme = true; |
c02e5a31 JS |
575 | } |
576 | ||
85b43fbf JS |
577 | // Automatically apply the theme background, |
578 | // changing the colour of the panel to match the | |
579 | // tab page colour. This won't work well with all | |
580 | // themes but it's a start. | |
c02e5a31 | 581 | if (g_UseTheme && wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel))) |
85b43fbf JS |
582 | { |
583 | ApplyThemeBackground(pPage, GetThemeBackgroundColour()); | |
584 | } | |
585 | #endif | |
586 | ||
22f3361e VZ |
587 | // add a new tab to the control |
588 | // ---------------------------- | |
58a8ab88 | 589 | |
22f3361e VZ |
590 | // init all fields to 0 |
591 | TC_ITEM tcItem; | |
592 | wxZeroMemory(tcItem); | |
58a8ab88 | 593 | |
22f3361e VZ |
594 | // set the image, if any |
595 | if ( imageId != -1 ) | |
596 | { | |
597 | tcItem.mask |= TCIF_IMAGE; | |
598 | tcItem.iImage = imageId; | |
599 | } | |
88310e2e | 600 | |
22f3361e VZ |
601 | // and the text |
602 | if ( !strText.IsEmpty() ) | |
603 | { | |
604 | tcItem.mask |= TCIF_TEXT; | |
605 | tcItem.pszText = (wxChar *)strText.c_str(); // const_cast | |
606 | } | |
43427087 | 607 | |
22f3361e VZ |
608 | // fit the notebook page to the tab control's display area: this should be |
609 | // done before adding it to the notebook or TabCtrl_InsertItem() will | |
610 | // change the notebooks size itself! | |
2015f2b3 | 611 | AdjustPageSize(pPage); |
43427087 | 612 | |
22f3361e | 613 | // finally do insert it |
2015f2b3 VZ |
614 | if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) |
615 | { | |
22f3361e | 616 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); |
88310e2e | 617 | |
b8bdaa7c | 618 | return false; |
22f3361e | 619 | } |
88310e2e | 620 | |
22f3361e VZ |
621 | // succeeded: save the pointer to the page |
622 | m_pages.Insert(pPage, nPage); | |
42e69d6b | 623 | |
2015f2b3 VZ |
624 | // for the first page (only) we need to adjust the size again because the |
625 | // notebook size changed: the tabs which hadn't been there before are now | |
626 | // shown | |
627 | if ( m_pages.GetCount() == 1 ) | |
628 | { | |
629 | AdjustPageSize(pPage); | |
630 | } | |
631 | ||
22f3361e VZ |
632 | // hide the page: unless it is selected, it shouldn't be shown (and if it |
633 | // is selected it will be shown later) | |
634 | HWND hwnd = GetWinHwnd(pPage); | |
635 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); | |
0398b1d6 | 636 | |
22f3361e VZ |
637 | // this updates internal flag too -- otherwise it would get out of sync |
638 | // with the real state | |
b8bdaa7c | 639 | pPage->Show(false); |
43427087 | 640 | |
96d37807 | 641 | |
22f3361e VZ |
642 | // now deal with the selection |
643 | // --------------------------- | |
644 | ||
645 | // if the inserted page is before the selected one, we must update the | |
646 | // index of the selected page | |
34a0c9f4 | 647 | if ( int(nPage) <= m_nSelection ) |
22f3361e VZ |
648 | { |
649 | // one extra page added | |
650 | m_nSelection++; | |
651 | } | |
652 | ||
653 | // some page should be selected: either this one or the first one if there | |
654 | // is still no selection | |
655 | int selNew = -1; | |
656 | if ( bSelect ) | |
657 | selNew = nPage; | |
658 | else if ( m_nSelection == -1 ) | |
659 | selNew = 0; | |
660 | ||
661 | if ( selNew != -1 ) | |
662 | SetSelection(selNew); | |
663 | ||
b8bdaa7c | 664 | return true; |
88310e2e VZ |
665 | } |
666 | ||
e450aa69 | 667 | int wxNotebook::HitTest(const wxPoint& pt, long *flags) const |
ef094fa0 JS |
668 | { |
669 | TC_HITTESTINFO hitTestInfo; | |
670 | hitTestInfo.pt.x = pt.x; | |
671 | hitTestInfo.pt.y = pt.y; | |
e450aa69 | 672 | int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo); |
ef094fa0 | 673 | |
e450aa69 VZ |
674 | if ( flags ) |
675 | { | |
676 | *flags = 0; | |
677 | ||
678 | if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) | |
679 | *flags |= wxNB_HITTEST_NOWHERE; | |
680 | if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) | |
681 | *flags |= wxNB_HITTEST_ONITEM; | |
682 | if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) | |
683 | *flags |= wxNB_HITTEST_ONICON; | |
684 | if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) | |
685 | *flags |= wxNB_HITTEST_ONLABEL; | |
686 | } | |
ef094fa0 JS |
687 | |
688 | return item; | |
689 | } | |
690 | ||
e450aa69 | 691 | |
88310e2e VZ |
692 | // ---------------------------------------------------------------------------- |
693 | // wxNotebook callbacks | |
694 | // ---------------------------------------------------------------------------- | |
695 | ||
9026ad85 | 696 | void wxNotebook::OnSize(wxSizeEvent& event) |
88310e2e | 697 | { |
b5c3b538 VZ |
698 | // fit the notebook page to the tab control's display area |
699 | RECT rc; | |
700 | rc.left = rc.top = 0; | |
701 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
702 | ||
b8bdaa7c | 703 | TabCtrl_AdjustRect(m_hwnd, false, &rc); |
4b7f2165 VZ |
704 | |
705 | int width = rc.right - rc.left, | |
706 | height = rc.bottom - rc.top; | |
1e6feb95 | 707 | size_t nCount = m_pages.Count(); |
c86f1403 | 708 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { |
1e6feb95 | 709 | wxNotebookPage *pPage = m_pages[nPage]; |
4b7f2165 | 710 | pPage->SetSize(rc.left, rc.top, width, height); |
b5c3b538 VZ |
711 | } |
712 | ||
88310e2e VZ |
713 | event.Skip(); |
714 | } | |
715 | ||
716 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
717 | { | |
718 | // is it our tab control? | |
719 | if ( event.GetEventObject() == this ) | |
5d1d2d46 | 720 | { |
5d1d2d46 VZ |
721 | int sel = event.GetOldSelection(); |
722 | if ( sel != -1 ) | |
b8bdaa7c | 723 | m_pages[sel]->Show(false); |
0398b1d6 | 724 | |
5d1d2d46 VZ |
725 | sel = event.GetSelection(); |
726 | if ( sel != -1 ) | |
727 | { | |
1e6feb95 | 728 | wxNotebookPage *pPage = m_pages[sel]; |
b8bdaa7c | 729 | pPage->Show(true); |
1d5b3bf0 VZ |
730 | pPage->SetFocus(); |
731 | ||
732 | // If the newly focused window is not a child of the new page, | |
733 | // SetFocus was not successful and the notebook itself should be | |
734 | // focused | |
735 | wxWindow *currentFocus = FindFocus(); | |
736 | wxWindow *startFocus = currentFocus; | |
737 | while ( currentFocus && currentFocus != pPage && currentFocus != this ) | |
738 | currentFocus = currentFocus->GetParent(); | |
739 | ||
740 | if ( startFocus == pPage || currentFocus != pPage ) | |
741 | SetFocus(); | |
742 | ||
743 | } | |
744 | else // no pages in the notebook, give the focus to itself | |
745 | { | |
746 | SetFocus(); | |
5d1d2d46 | 747 | } |
0398b1d6 | 748 | |
5d1d2d46 VZ |
749 | m_nSelection = sel; |
750 | } | |
88310e2e VZ |
751 | |
752 | // we want to give others a chance to process this message as well | |
753 | event.Skip(); | |
754 | } | |
755 | ||
b8bdaa7c | 756 | bool wxNotebook::MSWTranslateMessage(WXMSG *wxmsg) |
88310e2e | 757 | { |
b8bdaa7c | 758 | const MSG * const msg = (MSG *)wxmsg; |
88310e2e | 759 | |
1d5b3bf0 VZ |
760 | // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook. |
761 | // TAB will be passed to the currently selected page, CTRL+TAB and | |
762 | // CTRL+SHIFT+TAB will be processed by the notebook itself. do not | |
763 | // intercept SHIFT+TAB. This goes to the parent of the notebook which will | |
764 | // process it. | |
b8bdaa7c VZ |
765 | if ( msg->message == WM_KEYDOWN && msg->wParam == VK_TAB && |
766 | msg->hwnd == m_hwnd && | |
1d5b3bf0 | 767 | (wxIsCtrlDown() || !wxIsShiftDown()) ) |
b8bdaa7c VZ |
768 | { |
769 | return MSWProcessMessage(wxmsg); | |
770 | } | |
d9506e77 | 771 | |
b8bdaa7c | 772 | return false; |
88310e2e VZ |
773 | } |
774 | ||
775 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
776 | { | |
d9506e77 VZ |
777 | if ( event.IsWindowChange() ) { |
778 | // change pages | |
779 | AdvanceSelection(event.GetDirection()); | |
780 | } | |
781 | else { | |
b8bdaa7c | 782 | // we get this event in 3 cases |
d9506e77 VZ |
783 | // |
784 | // a) one of our pages might have generated it because the user TABbed | |
785 | // out from it in which case we should propagate the event upwards and | |
786 | // our parent will take care of setting the focus to prev/next sibling | |
787 | // | |
788 | // or | |
789 | // | |
790 | // b) the parent panel wants to give the focus to us so that we | |
791 | // forward it to our selected page. We can't deal with this in | |
792 | // OnSetFocus() because we don't know which direction the focus came | |
793 | // from in this case and so can't choose between setting the focus to | |
794 | // first or last panel child | |
b8bdaa7c VZ |
795 | // |
796 | // or | |
797 | // | |
798 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
799 | // | |
800 | wxWindow * const parent = GetParent(); | |
801 | ||
802 | const bool isFromParent = event.GetEventObject() == parent; | |
803 | const bool isFromSelf = event.GetEventObject() == this; | |
804 | ||
805 | if ( isFromParent || isFromSelf ) | |
d9506e77 | 806 | { |
b8bdaa7c VZ |
807 | // no, it doesn't come from child, case (b) or (c): forward to a |
808 | // page but only if direction is backwards (TAB) or from ourselves, | |
809 | if ( m_nSelection != -1 && | |
810 | (!event.GetDirection() || isFromSelf) ) | |
d9506e77 VZ |
811 | { |
812 | // so that the page knows that the event comes from it's parent | |
813 | // and is being propagated downwards | |
814 | event.SetEventObject(this); | |
815 | ||
1e6feb95 | 816 | wxWindow *page = m_pages[m_nSelection]; |
d9506e77 VZ |
817 | if ( !page->GetEventHandler()->ProcessEvent(event) ) |
818 | { | |
819 | page->SetFocus(); | |
820 | } | |
821 | //else: page manages focus inside it itself | |
822 | } | |
b8bdaa7c | 823 | else // otherwise set the focus to the notebook itself |
d9506e77 | 824 | { |
d9506e77 VZ |
825 | SetFocus(); |
826 | } | |
827 | } | |
828 | else | |
829 | { | |
b8bdaa7c VZ |
830 | // it comes from our child, case (a), pass to the parent, but only |
831 | // if the direction is forwards. Otherwise set the focus to the | |
832 | // notebook itself. The notebook is always the 'first' control of a | |
833 | // page. | |
834 | if ( !event.GetDirection() ) | |
835 | { | |
836 | SetFocus(); | |
837 | } | |
838 | else if ( parent ) | |
839 | { | |
d9506e77 VZ |
840 | event.SetCurrentFocus(this); |
841 | parent->GetEventHandler()->ProcessEvent(event); | |
842 | } | |
843 | } | |
88310e2e | 844 | } |
88310e2e VZ |
845 | } |
846 | ||
847 | // ---------------------------------------------------------------------------- | |
848 | // wxNotebook base class virtuals | |
849 | // ---------------------------------------------------------------------------- | |
b5c3b538 | 850 | |
0b481c72 VZ |
851 | #if wxUSE_CONSTRAINTS |
852 | ||
b5c3b538 VZ |
853 | // override these 2 functions to do nothing: everything is done in OnSize |
854 | ||
4b7f2165 | 855 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
b5c3b538 VZ |
856 | { |
857 | // don't set the sizes of the pages - their correct size is not yet known | |
b8bdaa7c | 858 | wxControl::SetConstraintSizes(false); |
b5c3b538 VZ |
859 | } |
860 | ||
4b7f2165 | 861 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
b5c3b538 | 862 | { |
b8bdaa7c | 863 | return true; |
b5c3b538 VZ |
864 | } |
865 | ||
0b481c72 VZ |
866 | #endif // wxUSE_CONSTRAINTS |
867 | ||
0df3fbd7 VZ |
868 | // ---------------------------------------------------------------------------- |
869 | // wxNotebook Windows message handlers | |
870 | // ---------------------------------------------------------------------------- | |
871 | ||
872 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
873 | WXWORD pos, WXHWND control) | |
874 | { | |
875 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
876 | // up-down control | |
877 | if ( control ) | |
b8bdaa7c | 878 | return false; |
0df3fbd7 VZ |
879 | |
880 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
881 | } | |
882 | ||
a23fd0e1 | 883 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) |
88310e2e | 884 | { |
93a19f17 | 885 | wxNotebookEvent event(wxEVT_NULL, m_windowId); |
88310e2e VZ |
886 | |
887 | NMHDR* hdr = (NMHDR *)lParam; | |
888 | switch ( hdr->code ) { | |
889 | case TCN_SELCHANGE: | |
890 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
891 | break; | |
892 | ||
893 | case TCN_SELCHANGING: | |
894 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
895 | break; | |
896 | ||
fd3f686c | 897 | default: |
a23fd0e1 | 898 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
88310e2e VZ |
899 | } |
900 | ||
93a19f17 VZ |
901 | event.SetSelection(TabCtrl_GetCurSel(m_hwnd)); |
902 | event.SetOldSelection(m_nSelection); | |
88310e2e | 903 | event.SetEventObject(this); |
a23fd0e1 | 904 | event.SetInt(idCtrl); |
88310e2e | 905 | |
fd3f686c VZ |
906 | bool processed = GetEventHandler()->ProcessEvent(event); |
907 | *result = !event.IsAllowed(); | |
908 | return processed; | |
88310e2e VZ |
909 | } |
910 | ||
85b43fbf JS |
911 | // Windows only: attempts to get colour for UX theme page background |
912 | wxColour wxNotebook::GetThemeBackgroundColour() | |
913 | { | |
914 | #if wxUSE_UXTHEME | |
915 | if (wxUxThemeEngine::Get()) | |
916 | { | |
2142d7ba | 917 | wxUxThemeHandle hTheme(this, L"TAB"); |
85b43fbf JS |
918 | if (hTheme) |
919 | { | |
920 | // This is total guesswork. | |
921 | // See PlatformSDK\Include\Tmschema.h for values | |
922 | COLORREF themeColor; | |
2142d7ba VZ |
923 | wxUxThemeEngine::Get()->GetThemeColor |
924 | ( | |
925 | hTheme, | |
926 | 10 /* TABP_BODY */, | |
927 | 1 /* NORMAL */, | |
928 | 3821, /* FILLCOLORHINT */ | |
929 | & themeColor | |
930 | ); | |
85b43fbf JS |
931 | |
932 | wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor)); | |
933 | return colour; | |
934 | } | |
935 | } | |
2142d7ba VZ |
936 | #endif // wxUSE_UXTHEME |
937 | ||
85b43fbf JS |
938 | return GetBackgroundColour(); |
939 | } | |
940 | ||
941 | // Windows only: attempts to apply the UX theme page background to this page | |
840015f0 | 942 | #if wxUSE_UXTHEME |
85b43fbf | 943 | void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour) |
840015f0 MB |
944 | #else |
945 | void wxNotebook::ApplyThemeBackground(wxWindow*, const wxColour&) | |
946 | #endif | |
85b43fbf JS |
947 | { |
948 | #if wxUSE_UXTHEME | |
949 | // Don't set the background for buttons since this will | |
950 | // switch it into ownerdraw mode | |
951 | if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton))) | |
952 | // This is essential, otherwise you'll see dark grey | |
953 | // corners in the buttons. | |
954 | ((wxButton*)window)->wxControl::SetBackgroundColour(colour); | |
955 | else if (window->IsKindOf(CLASSINFO(wxStaticText)) || | |
956 | window->IsKindOf(CLASSINFO(wxStaticBox)) || | |
957 | window->IsKindOf(CLASSINFO(wxStaticLine)) || | |
958 | window->IsKindOf(CLASSINFO(wxRadioButton)) || | |
959 | window->IsKindOf(CLASSINFO(wxRadioBox)) || | |
960 | window->IsKindOf(CLASSINFO(wxCheckBox)) || | |
961 | window->IsKindOf(CLASSINFO(wxBitmapButton)) || | |
962 | window->IsKindOf(CLASSINFO(wxSlider)) || | |
963 | window->IsKindOf(CLASSINFO(wxPanel)) || | |
964 | (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) || | |
965 | window->IsKindOf(CLASSINFO(wxScrolledWindow)) | |
966 | ) | |
967 | { | |
968 | window->SetBackgroundColour(colour); | |
969 | } | |
970 | ||
fc10daf3 | 971 | for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() ) |
85b43fbf JS |
972 | { |
973 | wxWindow *child = node->GetData(); | |
974 | ApplyThemeBackground(child, colour); | |
975 | } | |
976 | #endif | |
977 | } | |
978 | ||
c02e5a31 JS |
979 | long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
980 | { | |
b8bdaa7c VZ |
981 | static bool g_TestedForTheme = false; |
982 | static bool g_UseTheme = false; | |
c02e5a31 JS |
983 | switch ( nMsg ) |
984 | { | |
985 | case WM_ERASEBKGND: | |
986 | { | |
987 | if (!g_TestedForTheme) | |
988 | { | |
989 | int commCtrlVersion = wxTheApp->GetComCtl32Version() ; | |
990 | ||
991 | g_UseTheme = (commCtrlVersion >= 600); | |
b8bdaa7c | 992 | g_TestedForTheme = true; |
c02e5a31 JS |
993 | } |
994 | ||
995 | // If using XP themes, it seems we can get away | |
996 | // with not drawing a background, which reduces flicker. | |
997 | if (g_UseTheme) | |
b8bdaa7c | 998 | return true; |
c02e5a31 JS |
999 | } |
1000 | } | |
1001 | ||
1002 | return wxControl::MSWWindowProc(nMsg, wParam, lParam); | |
1003 | } | |
1004 | ||
1005 | ||
1e6feb95 | 1006 | #endif // wxUSE_NOTEBOOK |