]>
Commit | Line | Data |
---|---|---|
88310e2e | 1 | /////////////////////////////////////////////////////////////////////////////// |
2ddb4d13 | 2 | // Name: src/msw/notebook.cpp |
88310e2e VZ |
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> | |
65571936 | 9 | // Licence: wxWindows licence |
88310e2e VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
88310e2e VZ |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
1e6feb95 | 16 | #pragma hdrstop |
88310e2e VZ |
17 | #endif |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_NOTEBOOK |
20 | ||
e4db172a WS |
21 | #include "wx/notebook.h" |
22 | ||
88310e2e | 23 | #ifndef WX_PRECOMP |
e4db172a WS |
24 | #include "wx/string.h" |
25 | #include "wx/dc.h" | |
26 | #include "wx/log.h" | |
d5da0ce7 | 27 | #include "wx/event.h" |
670f9935 | 28 | #include "wx/app.h" |
ed4b0fdc | 29 | #include "wx/dcclient.h" |
f38924e8 | 30 | #include "wx/dcmemory.h" |
93fbbe07 | 31 | #include "wx/control.h" |
88310e2e VZ |
32 | #endif // WX_PRECOMP |
33 | ||
3096bd2f | 34 | #include "wx/imaglist.h" |
25057aba | 35 | #include "wx/sysopt.h" |
88310e2e | 36 | |
3096bd2f | 37 | #include "wx/msw/private.h" |
88310e2e | 38 | |
c1f3a149 | 39 | #include <windowsx.h> |
aaab7c01 | 40 | |
2cef71bc | 41 | #include <commctrl.h> |
88310e2e | 42 | |
85b43fbf JS |
43 | #include "wx/msw/winundef.h" |
44 | ||
45 | #if wxUSE_UXTHEME | |
caf95d2a | 46 | #include "wx/msw/uxtheme.h" |
85b43fbf JS |
47 | #endif |
48 | ||
88310e2e VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | // check that the page index is valid | |
8d34bf5c | 54 | #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount()) |
88310e2e | 55 | |
014ee083 VZ |
56 | // you can set USE_NOTEBOOK_ANTIFLICKER to 0 for desktop Windows versions too |
57 | // to disable code whih results in flicker-less notebook redrawing at the | |
58 | // expense of some extra GDI resource consumption | |
254fbd14 | 59 | #ifdef __WXWINCE__ |
014ee083 VZ |
60 | // notebooks are never resized under CE anyhow |
61 | #define USE_NOTEBOOK_ANTIFLICKER 0 | |
254fbd14 | 62 | #else |
014ee083 | 63 | #define USE_NOTEBOOK_ANTIFLICKER 1 |
254fbd14 JS |
64 | #endif |
65 | ||
74b31181 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // constants | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | // This is a work-around for missing defines in gcc-2.95 headers | |
71 | #ifndef TCS_RIGHT | |
72 | #define TCS_RIGHT 0x0002 | |
73 | #endif | |
74 | ||
75 | #ifndef TCS_VERTICAL | |
76 | #define TCS_VERTICAL 0x0080 | |
77 | #endif | |
78 | ||
79 | #ifndef TCS_BOTTOM | |
80 | #define TCS_BOTTOM TCS_RIGHT | |
81 | #endif | |
82 | ||
014ee083 VZ |
83 | // ---------------------------------------------------------------------------- |
84 | // global variables | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | #if USE_NOTEBOOK_ANTIFLICKER | |
88 | ||
89 | // the pointer to standard spin button wnd proc | |
90 | static WXFARPROC gs_wndprocNotebookSpinBtn = (WXFARPROC)NULL; | |
91 | ||
6143d3b6 | 92 | // the pointer to standard tab control wnd proc |
e1cffcd6 | 93 | static WXFARPROC gs_wndprocNotebook = (WXFARPROC)NULL; |
6143d3b6 VZ |
94 | |
95 | LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd, | |
96 | UINT message, | |
97 | WPARAM wParam, | |
98 | LPARAM lParam); | |
99 | ||
014ee083 VZ |
100 | #endif // USE_NOTEBOOK_ANTIFLICKER |
101 | ||
88310e2e VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // event table | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
7ec69821 | 106 | #include "wx/listimpl.cpp" |
51741307 | 107 | |
259c43f6 | 108 | WX_DEFINE_LIST( wxNotebookPageInfoList ) |
51741307 | 109 | |
2e4df4bf VZ |
110 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
111 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
112 | ||
d9317fd4 | 113 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) |
7ec69821 | 114 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) |
9026ad85 | 115 | EVT_SIZE(wxNotebook::OnSize) |
88310e2e | 116 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) |
014ee083 VZ |
117 | |
118 | #if USE_NOTEBOOK_ANTIFLICKER | |
119 | EVT_ERASE_BACKGROUND(wxNotebook::OnEraseBackground) | |
120 | EVT_PAINT(wxNotebook::OnPaint) | |
121 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
d9317fd4 | 122 | END_EVENT_TABLE() |
88310e2e | 123 | |
51596bcb | 124 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
125 | WX_DEFINE_FLAGS( wxNotebookStyle ) |
126 | ||
3ff066a4 | 127 | wxBEGIN_FLAGS( wxNotebookStyle ) |
bc9fb572 JS |
128 | // new style border flags, we put them first to |
129 | // use them for streaming out | |
3ff066a4 SC |
130 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
131 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
132 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
133 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
134 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
135 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
078cf5cb | 136 | |
bc9fb572 | 137 | // old style border flags |
3ff066a4 SC |
138 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
139 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
140 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
141 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
142 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 143 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
144 | |
145 | // standard window styles | |
3ff066a4 SC |
146 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
147 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
148 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
149 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 150 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
151 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
152 | wxFLAGS_MEMBER(wxVSCROLL) | |
153 | wxFLAGS_MEMBER(wxHSCROLL) | |
154 | ||
155 | wxFLAGS_MEMBER(wxNB_FIXEDWIDTH) | |
2ddb4d13 WS |
156 | wxFLAGS_MEMBER(wxBK_DEFAULT) |
157 | wxFLAGS_MEMBER(wxBK_TOP) | |
158 | wxFLAGS_MEMBER(wxBK_LEFT) | |
159 | wxFLAGS_MEMBER(wxBK_RIGHT) | |
160 | wxFLAGS_MEMBER(wxBK_BOTTOM) | |
b554cf63 JS |
161 | wxFLAGS_MEMBER(wxNB_NOPAGETHEME) |
162 | wxFLAGS_MEMBER(wxNB_FLAT) | |
3ff066a4 SC |
163 | |
164 | wxEND_FLAGS( wxNotebookStyle ) | |
51741307 | 165 | |
51596bcb | 166 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h") |
51741307 SC |
167 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject , "wx/notebook.h" ) |
168 | ||
3ff066a4 | 169 | wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo * , wxNotebookPageInfoList ) ; |
51596bcb | 170 | |
f0a126fe SC |
171 | template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, wxxVariantArray &value) |
172 | { | |
0c6b0084 | 173 | wxListCollectionToVariantArray<wxNotebookPageInfoList::compatibility_iterator>( theList , value ) ; |
f0a126fe SC |
174 | } |
175 | ||
3ff066a4 SC |
176 | wxBEGIN_PROPERTIES_TABLE(wxNotebook) |
177 | wxEVENT_PROPERTY( PageChanging , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING , wxNotebookEvent ) | |
178 | wxEVENT_PROPERTY( PageChanged , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED , wxNotebookEvent ) | |
c5ca409b | 179 | |
3ff066a4 | 180 | wxPROPERTY_COLLECTION( PageInfos , wxNotebookPageInfoList , wxNotebookPageInfo* , AddPageInfo , GetPageInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 181 | wxPROPERTY_FLAGS( WindowStyle , wxNotebookStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 182 | wxEND_PROPERTIES_TABLE() |
51596bcb | 183 | |
3ff066a4 SC |
184 | wxBEGIN_HANDLERS_TABLE(wxNotebook) |
185 | wxEND_HANDLERS_TABLE() | |
51596bcb | 186 | |
078cf5cb | 187 | wxCONSTRUCTOR_5( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51596bcb | 188 | |
51741307 | 189 | |
3ff066a4 | 190 | wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo) |
af498247 | 191 | wxREADONLY_PROPERTY( Page , wxNotebookPage* , GetPage , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
3ff066a4 SC |
192 | wxREADONLY_PROPERTY( Text , wxString , GetText , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
193 | wxREADONLY_PROPERTY( Selected , bool , GetSelected , false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) | |
194 | wxREADONLY_PROPERTY( ImageId , int , GetImageId , -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
195 | wxEND_PROPERTIES_TABLE() | |
51741307 | 196 | |
3ff066a4 SC |
197 | wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo) |
198 | wxEND_HANDLERS_TABLE() | |
51741307 | 199 | |
078cf5cb | 200 | wxCONSTRUCTOR_4( wxNotebookPageInfo , wxNotebookPage* , Page , wxString , Text , bool , Selected , int , ImageId ) |
51741307 | 201 | |
51596bcb | 202 | #else |
d9317fd4 | 203 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) |
51741307 | 204 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo, wxObject ) |
51596bcb | 205 | #endif |
d9317fd4 | 206 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) |
88310e2e VZ |
207 | |
208 | // ============================================================================ | |
209 | // implementation | |
210 | // ============================================================================ | |
211 | ||
212 | // ---------------------------------------------------------------------------- | |
213 | // wxNotebook construction | |
214 | // ---------------------------------------------------------------------------- | |
215 | ||
51741307 SC |
216 | const wxNotebookPageInfoList& wxNotebook::GetPageInfos() const |
217 | { | |
218 | wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos ) ; | |
219 | WX_CLEAR_LIST( wxNotebookPageInfoList , *list ) ; | |
34a0c9f4 | 220 | for( size_t i = 0 ; i < GetPageCount() ; ++i ) |
51741307 SC |
221 | { |
222 | wxNotebookPageInfo *info = new wxNotebookPageInfo() ; | |
34a0c9f4 | 223 | info->Create( const_cast<wxNotebook*>(this)->GetPage(i) , GetPageText(i) , GetSelection() == int(i) , GetPageImage(i) ) ; |
51741307 SC |
224 | list->Append( info ) ; |
225 | } | |
226 | return m_pageInfos ; | |
227 | } | |
228 | ||
88310e2e VZ |
229 | // common part of all ctors |
230 | void wxNotebook::Init() | |
231 | { | |
7ec69821 WS |
232 | m_imageList = NULL; |
233 | m_nSelection = -1; | |
caf95d2a VZ |
234 | |
235 | #if wxUSE_UXTHEME | |
7ec69821 | 236 | m_hbrBackground = NULL; |
caf95d2a | 237 | #endif // wxUSE_UXTHEME |
dfb47d83 VZ |
238 | |
239 | #if USE_NOTEBOOK_ANTIFLICKER | |
7ec69821 | 240 | m_hasSubclassedUpdown = false; |
dfb47d83 | 241 | #endif // USE_NOTEBOOK_ANTIFLICKER |
88310e2e VZ |
242 | } |
243 | ||
244 | // default for dynamic class | |
245 | wxNotebook::wxNotebook() | |
246 | { | |
247 | Init(); | |
248 | } | |
249 | ||
250 | // the same arguments as for wxControl | |
251 | wxNotebook::wxNotebook(wxWindow *parent, | |
8b9518ee | 252 | wxWindowID id, |
88310e2e VZ |
253 | const wxPoint& pos, |
254 | const wxSize& size, | |
8b9518ee | 255 | long style, |
88310e2e VZ |
256 | const wxString& name) |
257 | { | |
258 | Init(); | |
259 | ||
260 | Create(parent, id, pos, size, style, name); | |
261 | } | |
262 | ||
263 | // Create() function | |
264 | bool wxNotebook::Create(wxWindow *parent, | |
8b9518ee | 265 | wxWindowID id, |
88310e2e VZ |
266 | const wxPoint& pos, |
267 | const wxSize& size, | |
8b9518ee | 268 | long style, |
88310e2e VZ |
269 | const wxString& name) |
270 | { | |
45418059 JS |
271 | #ifdef __WXWINCE__ |
272 | // Not sure why, but without this style, there is no border | |
273 | // around the notebook tabs. | |
274 | if (style & wxNB_FLAT) | |
275 | style |= wxBORDER_SUNKEN; | |
276 | #endif | |
c3732409 | 277 | |
e4db172a | 278 | #if !wxUSE_UXTHEME |
7cc1ad29 JS |
279 | // ComCtl32 notebook tabs simply don't work unless they're on top if we have uxtheme, we can |
280 | // work around it later (after control creation), but if we don't have uxtheme, we have to clear | |
281 | // those styles | |
df10208f VZ |
282 | const int verComCtl32 = wxApp::GetComCtl32Version(); |
283 | if ( verComCtl32 == 600 ) | |
04eb05b0 | 284 | { |
5483756f | 285 | style &= ~(wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT); |
04eb05b0 | 286 | } |
7cc1ad29 | 287 | #endif //wxUSE_UXTHEME |
078cf5cb | 288 | |
c1637c89 VZ |
289 | LPCTSTR className = WC_TABCONTROL; |
290 | ||
6143d3b6 | 291 | #if USE_NOTEBOOK_ANTIFLICKER |
c1637c89 VZ |
292 | // SysTabCtl32 class has natively CS_HREDRAW and CS_VREDRAW enabled and it |
293 | // causes horrible flicker when resizing notebook, so get rid of it by | |
294 | // using a class without these styles (but otherwise identical to it) | |
295 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) | |
296 | { | |
297 | static ClassRegistrar s_clsNotebook; | |
298 | if ( !s_clsNotebook.IsInitialized() ) | |
299 | { | |
300 | // get a copy of standard class and modify it | |
301 | WNDCLASS wc; | |
302 | ||
6143d3b6 | 303 | if ( ::GetClassInfo(NULL, WC_TABCONTROL, &wc) ) |
c1637c89 | 304 | { |
6143d3b6 VZ |
305 | gs_wndprocNotebook = |
306 | wx_reinterpret_cast(WXFARPROC, wc.lpfnWndProc); | |
c1637c89 VZ |
307 | wc.lpszClassName = wxT("_wx_SysTabCtl32"); |
308 | wc.style &= ~(CS_HREDRAW | CS_VREDRAW); | |
6143d3b6 VZ |
309 | wc.hInstance = wxGetInstance(); |
310 | wc.lpfnWndProc = wxNotebookWndProc; | |
c1637c89 VZ |
311 | s_clsNotebook.Register(wc); |
312 | } | |
313 | else | |
314 | { | |
315 | wxLogLastError(_T("GetClassInfoEx(SysTabCtl32)")); | |
316 | } | |
317 | } | |
318 | ||
319 | // use our custom class if available but fall back to the standard | |
320 | // notebook if we failed to register it | |
321 | if ( s_clsNotebook.IsRegistered() ) | |
322 | { | |
323 | // it's ok to use c_str() here as the static s_clsNotebook object | |
324 | // has sufficiently long lifetime | |
325 | className = s_clsNotebook.GetName().c_str(); | |
326 | } | |
327 | } | |
6143d3b6 | 328 | #endif // USE_NOTEBOOK_ANTIFLICKER |
c1637c89 | 329 | |
6dd16e4f VZ |
330 | if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL, |
331 | wxDefaultValidator, name) ) | |
b8bdaa7c | 332 | return false; |
88310e2e | 333 | |
c1637c89 | 334 | if ( !MSWCreateControl(className, wxEmptyString, pos, size) ) |
b8bdaa7c | 335 | return false; |
907f37b3 | 336 | |
7dccdf81 VZ |
337 | #if wxUSE_UXTHEME |
338 | if ( HasFlag(wxNB_NOPAGETHEME) || | |
339 | wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) ) | |
f2b7be7a | 340 | { |
7dccdf81 | 341 | SetBackgroundColour(GetThemeBackgroundColour()); |
f2b7be7a | 342 | } |
30556182 VZ |
343 | else // use themed background by default |
344 | { | |
345 | // create backing store | |
346 | UpdateBgBrush(); | |
347 | } | |
e4db172a | 348 | |
7cc1ad29 JS |
349 | // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the |
350 | // control is simply not rendered correctly), so we disable themes | |
351 | // if possible, otherwise we simply clear the styles. | |
352 | // It's probably not possible to have UXTHEME without ComCtl32 6 or better, but lets | |
353 | // check it anyway. | |
354 | const int verComCtl32 = wxApp::GetComCtl32Version(); | |
e4db172a | 355 | if ( verComCtl32 == 600 ) |
7cc1ad29 JS |
356 | { |
357 | // check if we use themes at all -- if we don't, we're still okay | |
5483756f | 358 | if ( wxUxThemeEngine::GetIfActive() && (style & (wxBK_BOTTOM|wxBK_LEFT|wxBK_RIGHT))) |
7cc1ad29 JS |
359 | { |
360 | wxUxThemeEngine::GetIfActive()->SetWindowTheme((HWND)this->GetHandle(), L"", L""); | |
361 | SetBackgroundColour(GetThemeBackgroundColour()); //correct the background color for the new non-themed control | |
362 | } | |
363 | } | |
7dccdf81 | 364 | #endif // wxUSE_UXTHEME |
b554cf63 JS |
365 | |
366 | // Undocumented hack to get flat notebook style | |
367 | // In fact, we should probably only do this in some | |
368 | // curcumstances, i.e. if we know we will have a border | |
369 | // at the bottom (the tab control doesn't draw it itself) | |
370 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
371 | if (HasFlag(wxNB_FLAT)) | |
372 | { | |
01c8cbf5 | 373 | SendMessage(GetHwnd(), CCM_SETVERSION, COMCTL32_VERSION, 0); |
b554cf63 JS |
374 | if (!m_hasBgCol) |
375 | SetBackgroundColour(*wxWHITE); | |
376 | } | |
377 | #endif | |
b8bdaa7c | 378 | return true; |
0df3fbd7 VZ |
379 | } |
380 | ||
381 | WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const | |
382 | { | |
383 | WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle); | |
384 | ||
385 | tabStyle |= WS_TABSTOP | TCS_TABS; | |
386 | ||
2b5f62a0 | 387 | if ( style & wxNB_MULTILINE ) |
0df3fbd7 VZ |
388 | tabStyle |= TCS_MULTILINE; |
389 | if ( style & wxNB_FIXEDWIDTH ) | |
390 | tabStyle |= TCS_FIXEDWIDTH; | |
391 | ||
2ddb4d13 | 392 | if ( style & wxBK_BOTTOM ) |
0df3fbd7 | 393 | tabStyle |= TCS_RIGHT; |
2ddb4d13 | 394 | else if ( style & wxBK_LEFT ) |
0df3fbd7 | 395 | tabStyle |= TCS_VERTICAL; |
2ddb4d13 | 396 | else if ( style & wxBK_RIGHT ) |
c3732409 | 397 | tabStyle |= TCS_VERTICAL | TCS_RIGHT; |
0df3fbd7 VZ |
398 | |
399 | // ex style | |
400 | if ( exstyle ) | |
401 | { | |
402 | // note that we never want to have the default WS_EX_CLIENTEDGE style | |
403 | // as it looks too ugly for the notebooks | |
404 | *exstyle = 0; | |
405 | } | |
406 | ||
407 | return tabStyle; | |
88310e2e VZ |
408 | } |
409 | ||
caf95d2a VZ |
410 | wxNotebook::~wxNotebook() |
411 | { | |
412 | #if wxUSE_UXTHEME | |
413 | if ( m_hbrBackground ) | |
414 | ::DeleteObject((HBRUSH)m_hbrBackground); | |
415 | #endif // wxUSE_UXTHEME | |
416 | } | |
417 | ||
88310e2e VZ |
418 | // ---------------------------------------------------------------------------- |
419 | // wxNotebook accessors | |
420 | // ---------------------------------------------------------------------------- | |
07b8d7ec | 421 | |
8d34bf5c | 422 | size_t wxNotebook::GetPageCount() const |
88310e2e | 423 | { |
8ecd5de2 WS |
424 | // consistency check |
425 | wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(GetHwnd()) ); | |
88310e2e | 426 | |
8ecd5de2 | 427 | return m_pages.Count(); |
88310e2e VZ |
428 | } |
429 | ||
430 | int wxNotebook::GetRowCount() const | |
431 | { | |
8ecd5de2 | 432 | return TabCtrl_GetRowCount(GetHwnd()); |
88310e2e VZ |
433 | } |
434 | ||
8d34bf5c | 435 | int wxNotebook::SetSelection(size_t nPage) |
88310e2e | 436 | { |
8ecd5de2 WS |
437 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); |
438 | ||
439 | if ( int(nPage) != m_nSelection ) | |
2b5f62a0 | 440 | { |
8ecd5de2 WS |
441 | wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); |
442 | event.SetSelection(nPage); | |
443 | event.SetOldSelection(m_nSelection); | |
444 | event.SetEventObject(this); | |
445 | if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) | |
446 | { | |
447 | // program allows the page change | |
448 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
449 | (void)GetEventHandler()->ProcessEvent(event); | |
2b5f62a0 | 450 | |
8ecd5de2 WS |
451 | TabCtrl_SetCurSel(GetHwnd(), nPage); |
452 | } | |
2b5f62a0 | 453 | } |
88310e2e | 454 | |
8ecd5de2 | 455 | return m_nSelection; |
88310e2e VZ |
456 | } |
457 | ||
8d34bf5c | 458 | bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) |
88310e2e | 459 | { |
8ecd5de2 | 460 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e | 461 | |
8ecd5de2 WS |
462 | TC_ITEM tcItem; |
463 | tcItem.mask = TCIF_TEXT; | |
464 | tcItem.pszText = (wxChar *)strText.c_str(); | |
88310e2e | 465 | |
88a01064 JS |
466 | if ( !HasFlag(wxNB_MULTILINE) ) |
467 | return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; | |
468 | ||
469 | // multiline - we need to set new page size if a line is added or removed | |
470 | int rows = GetRowCount(); | |
471 | bool ret = TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; | |
472 | ||
473 | if ( ret && rows != GetRowCount() ) | |
474 | { | |
475 | const wxRect r = GetPageSize(); | |
476 | const size_t count = m_pages.Count(); | |
477 | for ( size_t page = 0; page < count; page++ ) | |
478 | m_pages[page]->SetSize(r); | |
479 | } | |
480 | ||
481 | return ret; | |
88310e2e VZ |
482 | } |
483 | ||
8d34bf5c | 484 | wxString wxNotebook::GetPageText(size_t nPage) const |
88310e2e | 485 | { |
8ecd5de2 | 486 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") ); |
88310e2e | 487 | |
8ecd5de2 WS |
488 | wxChar buf[256]; |
489 | TC_ITEM tcItem; | |
490 | tcItem.mask = TCIF_TEXT; | |
491 | tcItem.pszText = buf; | |
492 | tcItem.cchTextMax = WXSIZEOF(buf); | |
88310e2e | 493 | |
8ecd5de2 WS |
494 | wxString str; |
495 | if ( TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ) | |
496 | str = tcItem.pszText; | |
88310e2e | 497 | |
8ecd5de2 | 498 | return str; |
88310e2e VZ |
499 | } |
500 | ||
8d34bf5c | 501 | int wxNotebook::GetPageImage(size_t nPage) const |
88310e2e | 502 | { |
8ecd5de2 | 503 | wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); |
88310e2e | 504 | |
8ecd5de2 WS |
505 | TC_ITEM tcItem; |
506 | tcItem.mask = TCIF_IMAGE; | |
88310e2e | 507 | |
8ecd5de2 | 508 | return TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ? tcItem.iImage : wxNOT_FOUND; |
88310e2e VZ |
509 | } |
510 | ||
8d34bf5c | 511 | bool wxNotebook::SetPageImage(size_t nPage, int nImage) |
88310e2e | 512 | { |
8ecd5de2 | 513 | wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") ); |
88310e2e | 514 | |
8ecd5de2 WS |
515 | TC_ITEM tcItem; |
516 | tcItem.mask = TCIF_IMAGE; | |
517 | tcItem.iImage = nImage; | |
88310e2e | 518 | |
8ecd5de2 | 519 | return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0; |
88310e2e VZ |
520 | } |
521 | ||
522 | void wxNotebook::SetImageList(wxImageList* imageList) | |
907f37b3 | 523 | { |
8ecd5de2 | 524 | wxNotebookBase::SetImageList(imageList); |
07b8d7ec | 525 | |
8ecd5de2 WS |
526 | if ( imageList ) |
527 | { | |
528 | (void) TabCtrl_SetImageList(GetHwnd(), (HIMAGELIST)imageList->GetHIMAGELIST()); | |
529 | } | |
b656febd VS |
530 | } |
531 | ||
d9506e77 VZ |
532 | // ---------------------------------------------------------------------------- |
533 | // wxNotebook size settings | |
534 | // ---------------------------------------------------------------------------- | |
535 | ||
c3732409 VZ |
536 | wxRect wxNotebook::GetPageSize() const |
537 | { | |
538 | wxRect r; | |
539 | ||
540 | RECT rc; | |
541 | ::GetClientRect(GetHwnd(), &rc); | |
542 | ||
543 | // This check is to work around a bug in TabCtrl_AdjustRect which will | |
628eae0b VZ |
544 | // cause a crash on win2k or on XP with themes disabled if either |
545 | // wxNB_MULTILINE is used or tabs are placed on a side, if the rectangle | |
546 | // is too small. | |
547 | // | |
548 | // The value of 20 is chosen arbitrarily but seems to work | |
549 | if ( rc.right > 20 && rc.bottom > 20 ) | |
c3732409 | 550 | { |
01c8cbf5 | 551 | TabCtrl_AdjustRect(GetHwnd(), false, &rc); |
c3732409 VZ |
552 | |
553 | wxCopyRECTToRect(rc, r); | |
554 | } | |
555 | ||
556 | return r; | |
557 | } | |
558 | ||
d9506e77 VZ |
559 | void wxNotebook::SetPageSize(const wxSize& size) |
560 | { | |
561 | // transform the page size into the notebook size | |
562 | RECT rc; | |
563 | rc.left = | |
564 | rc.top = 0; | |
565 | rc.right = size.x; | |
566 | rc.bottom = size.y; | |
567 | ||
b8bdaa7c | 568 | TabCtrl_AdjustRect(GetHwnd(), true, &rc); |
d9506e77 VZ |
569 | |
570 | // and now set it | |
571 | SetSize(rc.right - rc.left, rc.bottom - rc.top); | |
572 | } | |
573 | ||
574 | void wxNotebook::SetPadding(const wxSize& padding) | |
575 | { | |
576 | TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y); | |
577 | } | |
42e69d6b VZ |
578 | |
579 | // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH | |
580 | // style. | |
581 | void wxNotebook::SetTabSize(const wxSize& sz) | |
582 | { | |
583 | ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y)); | |
584 | } | |
585 | ||
2ce7af35 JS |
586 | wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const |
587 | { | |
588 | wxSize sizeTotal = sizePage; | |
078cf5cb | 589 | |
77ffb593 | 590 | // We need to make getting tab size part of the wxWidgets API. |
8b5d5223 | 591 | wxSize tabSize; |
2ce7af35 JS |
592 | if (GetPageCount() > 0) |
593 | { | |
594 | RECT rect; | |
595 | TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect); | |
596 | tabSize.x = rect.right - rect.left; | |
597 | tabSize.y = rect.bottom - rect.top; | |
598 | } | |
2ddb4d13 | 599 | if ( HasFlag(wxBK_LEFT) || HasFlag(wxBK_RIGHT) ) |
2ce7af35 JS |
600 | { |
601 | sizeTotal.x += tabSize.x + 7; | |
602 | sizeTotal.y += 7; | |
603 | } | |
604 | else | |
605 | { | |
606 | sizeTotal.x += 7; | |
607 | sizeTotal.y += tabSize.y + 7; | |
608 | } | |
609 | ||
610 | return sizeTotal; | |
611 | } | |
612 | ||
2015f2b3 VZ |
613 | void wxNotebook::AdjustPageSize(wxNotebookPage *page) |
614 | { | |
615 | wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") ); | |
616 | ||
c3732409 VZ |
617 | const wxRect r = GetPageSize(); |
618 | if ( !r.IsEmpty() ) | |
14a6b6e5 | 619 | { |
c3732409 | 620 | page->SetSize(r); |
14a6b6e5 | 621 | } |
2015f2b3 VZ |
622 | } |
623 | ||
88310e2e VZ |
624 | // ---------------------------------------------------------------------------- |
625 | // wxNotebook operations | |
626 | // ---------------------------------------------------------------------------- | |
627 | ||
621793f4 | 628 | // remove one page from the notebook, without deleting |
8d34bf5c | 629 | wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage) |
621793f4 | 630 | { |
df7145da VZ |
631 | wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage); |
632 | if ( !pageRemoved ) | |
633 | return NULL; | |
621793f4 | 634 | |
01c8cbf5 | 635 | TabCtrl_DeleteItem(GetHwnd(), nPage); |
621793f4 | 636 | |
df7145da VZ |
637 | if ( m_pages.IsEmpty() ) |
638 | { | |
639 | // no selection any more, the notebook becamse empty | |
640 | m_nSelection = -1; | |
641 | } | |
642 | else // notebook still not empty | |
643 | { | |
01c8cbf5 | 644 | int selNew = TabCtrl_GetCurSel(GetHwnd()); |
623f5f70 | 645 | if (selNew != -1) |
df7145da | 646 | { |
623f5f70 | 647 | // No selection change, just refresh the current selection. |
078cf5cb WS |
648 | // Because it could be that the slection index changed |
649 | // we need to update it. | |
623f5f70 JS |
650 | // Note: this does not mean the selection it self changed. |
651 | m_nSelection = selNew; | |
652 | m_pages[m_nSelection]->Refresh(); | |
df7145da | 653 | } |
623f5f70 | 654 | else if (int(nPage) == m_nSelection) |
43a997b6 | 655 | { |
623f5f70 | 656 | // The selection was deleted. |
078cf5cb | 657 | |
623f5f70 JS |
658 | // Determine new selection. |
659 | if (m_nSelection == int(GetPageCount())) | |
660 | selNew = m_nSelection - 1; | |
661 | else | |
662 | selNew = m_nSelection; | |
078cf5cb | 663 | |
43a997b6 VZ |
664 | // m_nSelection must be always valid so reset it before calling |
665 | // SetSelection() | |
666 | m_nSelection = -1; | |
667 | SetSelection(selNew); | |
668 | } | |
623f5f70 JS |
669 | else |
670 | { | |
671 | wxFAIL; // Windows did not behave ok. | |
672 | } | |
df7145da | 673 | } |
47f12f58 | 674 | |
df7145da | 675 | return pageRemoved; |
621793f4 JS |
676 | } |
677 | ||
88310e2e VZ |
678 | // remove all pages |
679 | bool wxNotebook::DeleteAllPages() | |
680 | { | |
7ec69821 WS |
681 | size_t nPageCount = GetPageCount(); |
682 | size_t nPage; | |
683 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
684 | delete m_pages[nPage]; | |
88310e2e | 685 | |
7ec69821 | 686 | m_pages.Clear(); |
88310e2e | 687 | |
7ec69821 | 688 | TabCtrl_DeleteAllItems(GetHwnd()); |
907f37b3 | 689 | |
7ec69821 | 690 | m_nSelection = -1; |
47f12f58 | 691 | |
7ec69821 WS |
692 | InvalidateBestSize(); |
693 | return true; | |
88310e2e VZ |
694 | } |
695 | ||
88310e2e | 696 | // same as AddPage() but does it at given position |
8d34bf5c | 697 | bool wxNotebook::InsertPage(size_t nPage, |
88310e2e VZ |
698 | wxNotebookPage *pPage, |
699 | const wxString& strText, | |
700 | bool bSelect, | |
701 | int imageId) | |
702 | { | |
b8bdaa7c VZ |
703 | wxCHECK_MSG( pPage != NULL, false, _T("NULL page in wxNotebook::InsertPage") ); |
704 | wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false, | |
22f3361e | 705 | _T("invalid index in wxNotebook::InsertPage") ); |
88310e2e | 706 | |
efa14cf2 VZ |
707 | wxASSERT_MSG( pPage->GetParent() == this, |
708 | _T("notebook pages must have notebook as parent") ); | |
43427087 | 709 | |
22f3361e VZ |
710 | // add a new tab to the control |
711 | // ---------------------------- | |
58a8ab88 | 712 | |
22f3361e VZ |
713 | // init all fields to 0 |
714 | TC_ITEM tcItem; | |
715 | wxZeroMemory(tcItem); | |
58a8ab88 | 716 | |
22f3361e VZ |
717 | // set the image, if any |
718 | if ( imageId != -1 ) | |
719 | { | |
720 | tcItem.mask |= TCIF_IMAGE; | |
721 | tcItem.iImage = imageId; | |
722 | } | |
88310e2e | 723 | |
22f3361e | 724 | // and the text |
8b5d5223 | 725 | if ( !strText.empty() ) |
22f3361e VZ |
726 | { |
727 | tcItem.mask |= TCIF_TEXT; | |
728 | tcItem.pszText = (wxChar *)strText.c_str(); // const_cast | |
729 | } | |
43427087 | 730 | |
e830a6a6 RD |
731 | // hide the page: unless it is selected, it shouldn't be shown (and if it |
732 | // is selected it will be shown later) | |
733 | HWND hwnd = GetWinHwnd(pPage); | |
734 | SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE); | |
735 | ||
736 | // this updates internal flag too -- otherwise it would get out of sync | |
737 | // with the real state | |
738 | pPage->Show(false); | |
739 | ||
740 | ||
22f3361e VZ |
741 | // fit the notebook page to the tab control's display area: this should be |
742 | // done before adding it to the notebook or TabCtrl_InsertItem() will | |
743 | // change the notebooks size itself! | |
2015f2b3 | 744 | AdjustPageSize(pPage); |
43427087 | 745 | |
22f3361e | 746 | // finally do insert it |
01c8cbf5 | 747 | if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 ) |
2015f2b3 | 748 | { |
22f3361e | 749 | wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str()); |
88310e2e | 750 | |
b8bdaa7c | 751 | return false; |
22f3361e | 752 | } |
88310e2e | 753 | |
22f3361e VZ |
754 | // succeeded: save the pointer to the page |
755 | m_pages.Insert(pPage, nPage); | |
42e69d6b | 756 | |
56b9925b VZ |
757 | // we may need to adjust the size again if the notebook size changed: |
758 | // normally this only happens for the first page we add (the tabs which | |
759 | // hadn't been there before are now shown) but for a multiline notebook it | |
760 | // can happen for any page at all as a new row could have been started | |
761 | if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) ) | |
2015f2b3 VZ |
762 | { |
763 | AdjustPageSize(pPage); | |
764 | } | |
765 | ||
22f3361e VZ |
766 | // now deal with the selection |
767 | // --------------------------- | |
768 | ||
769 | // if the inserted page is before the selected one, we must update the | |
770 | // index of the selected page | |
34a0c9f4 | 771 | if ( int(nPage) <= m_nSelection ) |
22f3361e VZ |
772 | { |
773 | // one extra page added | |
774 | m_nSelection++; | |
775 | } | |
776 | ||
777 | // some page should be selected: either this one or the first one if there | |
778 | // is still no selection | |
779 | int selNew = -1; | |
780 | if ( bSelect ) | |
781 | selNew = nPage; | |
782 | else if ( m_nSelection == -1 ) | |
783 | selNew = 0; | |
784 | ||
785 | if ( selNew != -1 ) | |
786 | SetSelection(selNew); | |
787 | ||
37144cf0 | 788 | InvalidateBestSize(); |
25057aba | 789 | |
b8bdaa7c | 790 | return true; |
88310e2e VZ |
791 | } |
792 | ||
e450aa69 | 793 | int wxNotebook::HitTest(const wxPoint& pt, long *flags) const |
ef094fa0 JS |
794 | { |
795 | TC_HITTESTINFO hitTestInfo; | |
796 | hitTestInfo.pt.x = pt.x; | |
797 | hitTestInfo.pt.y = pt.y; | |
e450aa69 | 798 | int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo); |
ef094fa0 | 799 | |
e450aa69 VZ |
800 | if ( flags ) |
801 | { | |
802 | *flags = 0; | |
803 | ||
804 | if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE) | |
805 | *flags |= wxNB_HITTEST_NOWHERE; | |
806 | if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM) | |
807 | *flags |= wxNB_HITTEST_ONITEM; | |
808 | if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON) | |
809 | *flags |= wxNB_HITTEST_ONICON; | |
810 | if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL) | |
811 | *flags |= wxNB_HITTEST_ONLABEL; | |
812 | } | |
ef094fa0 JS |
813 | |
814 | return item; | |
815 | } | |
816 | ||
014ee083 VZ |
817 | // ---------------------------------------------------------------------------- |
818 | // flicker-less notebook redraw | |
819 | // ---------------------------------------------------------------------------- | |
820 | ||
821 | #if USE_NOTEBOOK_ANTIFLICKER | |
822 | ||
823 | // wnd proc for the spin button | |
824 | LRESULT APIENTRY _EXPORT wxNotebookSpinBtnWndProc(HWND hwnd, | |
825 | UINT message, | |
826 | WPARAM wParam, | |
827 | LPARAM lParam) | |
828 | { | |
829 | if ( message == WM_ERASEBKGND ) | |
830 | return 0; | |
831 | ||
832 | return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebookSpinBtn, | |
833 | hwnd, message, wParam, lParam); | |
834 | } | |
835 | ||
6143d3b6 VZ |
836 | LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd, |
837 | UINT message, | |
838 | WPARAM wParam, | |
839 | LPARAM lParam) | |
840 | { | |
841 | return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebook, | |
842 | hwnd, message, wParam, lParam); | |
843 | } | |
844 | ||
014ee083 VZ |
845 | void wxNotebook::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) |
846 | { | |
847 | // do nothing here | |
848 | } | |
849 | ||
850 | void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
851 | { | |
852 | wxPaintDC dc(this); | |
853 | wxMemoryDC memdc; | |
854 | RECT rc; | |
855 | ::GetClientRect(GetHwnd(), &rc); | |
856 | wxBitmap bmp(rc.right, rc.bottom); | |
857 | memdc.SelectObject(bmp); | |
858 | ||
859 | // if there is no special brush just use the solid background colour | |
64c288fa | 860 | #if wxUSE_UXTHEME |
014ee083 | 861 | HBRUSH hbr = (HBRUSH)m_hbrBackground; |
64c288fa JS |
862 | #else |
863 | HBRUSH hbr = 0; | |
e4db172a | 864 | #endif |
e32703a9 | 865 | wxBrush brush; |
014ee083 | 866 | if ( !hbr ) |
e32703a9 VZ |
867 | { |
868 | brush = wxBrush(GetBackgroundColour()); | |
869 | hbr = GetHbrushOf(brush); | |
870 | } | |
014ee083 VZ |
871 | |
872 | ::FillRect(GetHdcOf(memdc), &rc, hbr); | |
873 | ||
874 | MSWDefWindowProc(WM_PAINT, (WPARAM)memdc.GetHDC(), 0); | |
875 | ||
876 | dc.Blit(0, 0, rc.right, rc.bottom, &memdc, 0, 0); | |
877 | } | |
878 | ||
879 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
e450aa69 | 880 | |
88310e2e VZ |
881 | // ---------------------------------------------------------------------------- |
882 | // wxNotebook callbacks | |
883 | // ---------------------------------------------------------------------------- | |
884 | ||
9026ad85 | 885 | void wxNotebook::OnSize(wxSizeEvent& event) |
88310e2e | 886 | { |
7dccdf81 | 887 | if ( GetPageCount() == 0 ) |
f7eaa62f JS |
888 | { |
889 | // Prevents droppings on resize, but does cause some flicker | |
890 | // when there are no pages. | |
2aa24b60 | 891 | Refresh(); |
f7eaa62f JS |
892 | event.Skip(); |
893 | return; | |
894 | } | |
254fbd14 JS |
895 | #ifndef __WXWINCE__ |
896 | else | |
897 | { | |
898 | // Without this, we can sometimes get droppings at the edges | |
899 | // of a notebook, for example a notebook in a splitter window. | |
900 | // This needs to be reconciled with the RefreshRect calls | |
901 | // at the end of this function, which weren't enough to prevent | |
902 | // the droppings. | |
01c8cbf5 | 903 | |
254fbd14 JS |
904 | wxSize sz = GetClientSize(); |
905 | ||
906 | // Refresh right side | |
907 | wxRect rect(sz.x-4, 0, 4, sz.y); | |
908 | RefreshRect(rect); | |
01c8cbf5 | 909 | |
254fbd14 JS |
910 | // Refresh bottom side |
911 | rect = wxRect(0, sz.y-4, sz.x, 4); | |
912 | RefreshRect(rect); | |
01c8cbf5 | 913 | |
254fbd14 JS |
914 | // Refresh left side |
915 | rect = wxRect(0, 0, 4, sz.y); | |
916 | RefreshRect(rect); | |
917 | } | |
014ee083 | 918 | #endif // !__WXWINCE__ |
f7eaa62f | 919 | |
c1637c89 | 920 | // fit all the notebook pages to the tab control's display area |
56b9925b | 921 | |
c1637c89 VZ |
922 | RECT rc; |
923 | rc.left = rc.top = 0; | |
924 | GetSize((int *)&rc.right, (int *)&rc.bottom); | |
56b9925b | 925 | |
c1637c89 VZ |
926 | // save the total size, we'll use it below |
927 | int widthNbook = rc.right - rc.left, | |
928 | heightNbook = rc.bottom - rc.top; | |
929 | ||
930 | // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it | |
931 | // returns completely false values for multiline tab controls after the tabs | |
932 | // are added but before getting the first WM_SIZE (off by ~50 pixels, see | |
933 | // | |
934 | // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863 | |
935 | // | |
936 | // and the only work around I could find was this ugly hack... without it | |
937 | // simply toggling the "multiline" checkbox in the notebook sample resulted | |
938 | // in a noticeable page displacement | |
939 | if ( HasFlag(wxNB_MULTILINE) ) | |
940 | { | |
941 | // avoid an infinite recursion: we get another notification too! | |
942 | static bool s_isInOnSize = false; | |
4b7f2165 | 943 | |
c1637c89 VZ |
944 | if ( !s_isInOnSize ) |
945 | { | |
946 | s_isInOnSize = true; | |
947 | SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, | |
948 | MAKELPARAM(rc.right, rc.bottom)); | |
949 | s_isInOnSize = false; | |
950 | } | |
951 | } | |
b5c3b538 | 952 | |
e2f6f8da RD |
953 | #if wxUSE_UXTHEME |
954 | // background bitmap size has changed, update the brush using it too | |
955 | UpdateBgBrush(); | |
956 | #endif // wxUSE_UXTHEME | |
957 | ||
01c8cbf5 | 958 | TabCtrl_AdjustRect(GetHwnd(), false, &rc); |
c1637c89 VZ |
959 | |
960 | int width = rc.right - rc.left, | |
961 | height = rc.bottom - rc.top; | |
962 | size_t nCount = m_pages.Count(); | |
963 | for ( size_t nPage = 0; nPage < nCount; nPage++ ) { | |
964 | wxNotebookPage *pPage = m_pages[nPage]; | |
965 | pPage->SetSize(rc.left, rc.top, width, height); | |
966 | } | |
967 | ||
968 | ||
969 | // unless we had already repainted everything, we now need to refresh | |
970 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) | |
971 | { | |
972 | // invalidate areas not covered by pages | |
973 | RefreshRect(wxRect(0, 0, widthNbook, rc.top), false); | |
974 | RefreshRect(wxRect(0, rc.top, rc.left, height), false); | |
975 | RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom), | |
976 | false); | |
3550706d | 977 | RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.right, height), |
c1637c89 VZ |
978 | false); |
979 | } | |
980 | ||
014ee083 VZ |
981 | #if USE_NOTEBOOK_ANTIFLICKER |
982 | // subclass the spin control used by the notebook to scroll pages to | |
983 | // prevent it from flickering on resize | |
dfb47d83 | 984 | if ( !m_hasSubclassedUpdown ) |
014ee083 VZ |
985 | { |
986 | // iterate over all child windows to find spin button | |
987 | for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD); | |
988 | child; | |
989 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
990 | { | |
991 | wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child); | |
992 | ||
993 | // see if it exists, if no wxWindow found then assume it's the spin | |
994 | // btn | |
995 | if ( !childWindow ) | |
996 | { | |
997 | // subclass the spin button to override WM_ERASEBKGND | |
dfb47d83 VZ |
998 | if ( !gs_wndprocNotebookSpinBtn ) |
999 | gs_wndprocNotebookSpinBtn = (WXFARPROC)wxGetWindowProc(child); | |
014ee083 VZ |
1000 | |
1001 | wxSetWindowProc(child, wxNotebookSpinBtnWndProc); | |
dfb47d83 | 1002 | m_hasSubclassedUpdown = true; |
014ee083 VZ |
1003 | break; |
1004 | } | |
1005 | } | |
1006 | } | |
1007 | #endif // USE_NOTEBOOK_ANTIFLICKER | |
1008 | ||
c1637c89 | 1009 | event.Skip(); |
88310e2e VZ |
1010 | } |
1011 | ||
1012 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
1013 | { | |
1014 | // is it our tab control? | |
1015 | if ( event.GetEventObject() == this ) | |
5d1d2d46 | 1016 | { |
5d1d2d46 VZ |
1017 | int sel = event.GetOldSelection(); |
1018 | if ( sel != -1 ) | |
b8bdaa7c | 1019 | m_pages[sel]->Show(false); |
0398b1d6 | 1020 | |
5d1d2d46 VZ |
1021 | sel = event.GetSelection(); |
1022 | if ( sel != -1 ) | |
1023 | { | |
1e6feb95 | 1024 | wxNotebookPage *pPage = m_pages[sel]; |
b8bdaa7c | 1025 | pPage->Show(true); |
e1cffcd6 | 1026 | } |
2ff53fd3 | 1027 | |
e1cffcd6 VZ |
1028 | // Changing the page should give the focus to it but, as per bug report |
1029 | // http://sf.net/tracker/index.php?func=detail&aid=1150659&group_id=9863&atid=109863, | |
1030 | // we should not set the focus to it directly since it erroneously | |
1031 | // selects radio buttons and breaks keyboard handling for a notebook's | |
1032 | // scroll buttons. So give focus to the notebook and not the page. | |
1d5b3bf0 | 1033 | |
e1cffcd6 VZ |
1034 | // but don't do this is the notebook is hidden |
1035 | if ( ::IsWindowVisible(GetHwnd()) ) | |
1036 | SetFocus(); | |
0398b1d6 | 1037 | |
5d1d2d46 VZ |
1038 | m_nSelection = sel; |
1039 | } | |
88310e2e VZ |
1040 | |
1041 | // we want to give others a chance to process this message as well | |
1042 | event.Skip(); | |
1043 | } | |
1044 | ||
b8bdaa7c | 1045 | bool wxNotebook::MSWTranslateMessage(WXMSG *wxmsg) |
88310e2e | 1046 | { |
b8bdaa7c | 1047 | const MSG * const msg = (MSG *)wxmsg; |
88310e2e | 1048 | |
1d5b3bf0 VZ |
1049 | // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook. |
1050 | // TAB will be passed to the currently selected page, CTRL+TAB and | |
1051 | // CTRL+SHIFT+TAB will be processed by the notebook itself. do not | |
1052 | // intercept SHIFT+TAB. This goes to the parent of the notebook which will | |
1053 | // process it. | |
b8bdaa7c | 1054 | if ( msg->message == WM_KEYDOWN && msg->wParam == VK_TAB && |
01c8cbf5 | 1055 | msg->hwnd == GetHwnd() && |
1d5b3bf0 | 1056 | (wxIsCtrlDown() || !wxIsShiftDown()) ) |
b8bdaa7c VZ |
1057 | { |
1058 | return MSWProcessMessage(wxmsg); | |
1059 | } | |
d9506e77 | 1060 | |
b8bdaa7c | 1061 | return false; |
88310e2e VZ |
1062 | } |
1063 | ||
1064 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
1065 | { | |
d9506e77 VZ |
1066 | if ( event.IsWindowChange() ) { |
1067 | // change pages | |
1068 | AdvanceSelection(event.GetDirection()); | |
1069 | } | |
1070 | else { | |
b8bdaa7c | 1071 | // we get this event in 3 cases |
d9506e77 VZ |
1072 | // |
1073 | // a) one of our pages might have generated it because the user TABbed | |
1074 | // out from it in which case we should propagate the event upwards and | |
1075 | // our parent will take care of setting the focus to prev/next sibling | |
1076 | // | |
1077 | // or | |
1078 | // | |
1079 | // b) the parent panel wants to give the focus to us so that we | |
1080 | // forward it to our selected page. We can't deal with this in | |
1081 | // OnSetFocus() because we don't know which direction the focus came | |
1082 | // from in this case and so can't choose between setting the focus to | |
1083 | // first or last panel child | |
b8bdaa7c VZ |
1084 | // |
1085 | // or | |
1086 | // | |
1087 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
1088 | // | |
1089 | wxWindow * const parent = GetParent(); | |
1090 | ||
3c99602b MB |
1091 | // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE |
1092 | const bool isFromParent = event.GetEventObject() == (wxObject*) parent; | |
1093 | const bool isFromSelf = event.GetEventObject() == (wxObject*) this; | |
b8bdaa7c VZ |
1094 | |
1095 | if ( isFromParent || isFromSelf ) | |
d9506e77 | 1096 | { |
b8bdaa7c VZ |
1097 | // no, it doesn't come from child, case (b) or (c): forward to a |
1098 | // page but only if direction is backwards (TAB) or from ourselves, | |
1099 | if ( m_nSelection != -1 && | |
1100 | (!event.GetDirection() || isFromSelf) ) | |
d9506e77 VZ |
1101 | { |
1102 | // so that the page knows that the event comes from it's parent | |
1103 | // and is being propagated downwards | |
1104 | event.SetEventObject(this); | |
1105 | ||
1e6feb95 | 1106 | wxWindow *page = m_pages[m_nSelection]; |
d9506e77 VZ |
1107 | if ( !page->GetEventHandler()->ProcessEvent(event) ) |
1108 | { | |
1109 | page->SetFocus(); | |
1110 | } | |
1111 | //else: page manages focus inside it itself | |
1112 | } | |
b8bdaa7c | 1113 | else // otherwise set the focus to the notebook itself |
d9506e77 | 1114 | { |
d9506e77 VZ |
1115 | SetFocus(); |
1116 | } | |
1117 | } | |
1118 | else | |
1119 | { | |
b8bdaa7c VZ |
1120 | // it comes from our child, case (a), pass to the parent, but only |
1121 | // if the direction is forwards. Otherwise set the focus to the | |
1122 | // notebook itself. The notebook is always the 'first' control of a | |
1123 | // page. | |
1124 | if ( !event.GetDirection() ) | |
1125 | { | |
1126 | SetFocus(); | |
1127 | } | |
1128 | else if ( parent ) | |
1129 | { | |
d9506e77 VZ |
1130 | event.SetCurrentFocus(this); |
1131 | parent->GetEventHandler()->ProcessEvent(event); | |
1132 | } | |
1133 | } | |
88310e2e | 1134 | } |
88310e2e VZ |
1135 | } |
1136 | ||
caf95d2a VZ |
1137 | #if wxUSE_UXTHEME |
1138 | ||
c3732409 | 1139 | bool wxNotebook::DoDrawBackground(WXHDC hDC, wxWindow *child) |
caf95d2a | 1140 | { |
c3732409 VZ |
1141 | wxUxThemeHandle theme(child ? child : this, L"TAB"); |
1142 | if ( !theme ) | |
1143 | return false; | |
1144 | ||
1145 | // get the notebook client rect (we're not interested in drawing tabs | |
1146 | // themselves) | |
1147 | wxRect r = GetPageSize(); | |
1148 | if ( r.IsEmpty() ) | |
1149 | return false; | |
1150 | ||
c4a95f6f | 1151 | RECT rc; |
c3732409 VZ |
1152 | wxCopyRectToRECT(r, rc); |
1153 | ||
1154 | // map rect to the coords of the window we're drawing in | |
1155 | if ( child ) | |
1156 | ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2); | |
1157 | ||
2ff53fd3 JS |
1158 | // we have the content area (page size), but we need to draw all of the |
1159 | // background for it to be aligned correctly | |
1160 | wxUxThemeEngine::Get()->GetThemeBackgroundExtent | |
1161 | ( | |
1162 | theme, | |
1163 | (HDC) hDC, | |
1164 | 9 /* TABP_PANE */, | |
1165 | 0, | |
1166 | &rc, | |
1167 | &rc | |
1168 | ); | |
c3732409 VZ |
1169 | wxUxThemeEngine::Get()->DrawThemeBackground |
1170 | ( | |
1171 | theme, | |
92199f4c | 1172 | (HDC) hDC, |
c3732409 VZ |
1173 | 9 /* TABP_PANE */, |
1174 | 0, | |
1175 | &rc, | |
1176 | NULL | |
1177 | ); | |
1178 | ||
1179 | return true; | |
1180 | } | |
de359565 | 1181 | |
c3732409 VZ |
1182 | WXHBRUSH wxNotebook::QueryBgBitmap() |
1183 | { | |
1184 | wxRect r = GetPageSize(); | |
1185 | if ( r.IsEmpty() ) | |
1186 | return 0; | |
c4a95f6f VZ |
1187 | |
1188 | WindowHDC hDC(GetHwnd()); | |
1189 | MemoryHDC hDCMem(hDC); | |
c3732409 | 1190 | CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height); |
c4a95f6f VZ |
1191 | |
1192 | SelectInHDC selectBmp(hDCMem, hBmp); | |
caf95d2a | 1193 | |
c3732409 VZ |
1194 | if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) ) |
1195 | return 0; | |
0f770734 | 1196 | |
de359565 | 1197 | return (WXHBRUSH)::CreatePatternBrush(hBmp); |
c4a95f6f | 1198 | } |
caf95d2a | 1199 | |
c4a95f6f VZ |
1200 | void wxNotebook::UpdateBgBrush() |
1201 | { | |
1202 | if ( m_hbrBackground ) | |
1203 | ::DeleteObject((HBRUSH)m_hbrBackground); | |
caf95d2a | 1204 | |
c4a95f6f VZ |
1205 | if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() ) |
1206 | { | |
de359565 | 1207 | m_hbrBackground = QueryBgBitmap(); |
caf95d2a | 1208 | } |
c3732409 | 1209 | else // no themes or we've got user-defined solid colour |
caf95d2a VZ |
1210 | { |
1211 | m_hbrBackground = NULL; | |
1212 | } | |
1213 | } | |
1214 | ||
2bae4332 | 1215 | WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd) |
caf95d2a | 1216 | { |
caf95d2a VZ |
1217 | if ( m_hbrBackground ) |
1218 | { | |
1219 | // before drawing with the background brush, we need to position it | |
1220 | // correctly | |
caf95d2a | 1221 | RECT rc; |
2bae4332 | 1222 | ::GetWindowRect((HWND)hWnd, &rc); |
caf95d2a VZ |
1223 | |
1224 | ::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1); | |
1225 | ||
5c836c46 | 1226 | if ( !::SetBrushOrgEx((HDC)hDC, -rc.left, -rc.top, NULL) ) |
caf95d2a VZ |
1227 | { |
1228 | wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)")); | |
1229 | } | |
c4a95f6f VZ |
1230 | |
1231 | return m_hbrBackground; | |
5c836c46 VZ |
1232 | } |
1233 | ||
2bae4332 | 1234 | return wxNotebookBase::MSWGetBgBrushForChild(hDC, hWnd); |
5c836c46 | 1235 | } |
caf95d2a | 1236 | |
c3732409 | 1237 | bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child) |
07c19327 | 1238 | { |
c3732409 VZ |
1239 | // solid background colour overrides themed background drawing |
1240 | if ( !UseBgCol() && DoDrawBackground(hDC, child) ) | |
1241 | return true; | |
de359565 | 1242 | |
4dab5279 JS |
1243 | // If we're using a solid colour (for example if we've switched off |
1244 | // theming for this notebook), paint it | |
1245 | if (UseBgCol()) | |
1246 | { | |
1247 | wxRect r = GetPageSize(); | |
1248 | if ( r.IsEmpty() ) | |
1249 | return false; | |
1250 | ||
1251 | RECT rc; | |
1252 | wxCopyRectToRECT(r, rc); | |
1253 | ||
1254 | // map rect to the coords of the window we're drawing in | |
1255 | if ( child ) | |
1256 | ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2); | |
1257 | ||
1258 | wxBrush brush(GetBackgroundColour()); | |
1259 | HBRUSH hbr = GetHbrushOf(brush); | |
01c8cbf5 | 1260 | |
4dab5279 JS |
1261 | ::FillRect((HDC) hDC, &rc, hbr); |
1262 | ||
1263 | return true; | |
1264 | } | |
1265 | ||
c3732409 | 1266 | return wxNotebookBase::MSWPrintChild(hDC, child); |
07c19327 VZ |
1267 | } |
1268 | ||
caf95d2a VZ |
1269 | #endif // wxUSE_UXTHEME |
1270 | ||
25057aba JS |
1271 | // Windows only: attempts to get colour for UX theme page background |
1272 | wxColour wxNotebook::GetThemeBackgroundColour() const | |
1273 | { | |
1274 | #if wxUSE_UXTHEME | |
1275 | if (wxUxThemeEngine::Get()) | |
1276 | { | |
1277 | wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB"); | |
1278 | if (hTheme) | |
1279 | { | |
1280 | // This is total guesswork. | |
1281 | // See PlatformSDK\Include\Tmschema.h for values | |
1282 | COLORREF themeColor; | |
1283 | wxUxThemeEngine::Get()->GetThemeColor( | |
1284 | hTheme, | |
1285 | 10 /* TABP_BODY */, | |
1286 | 1 /* NORMAL */, | |
1287 | 3821 /* FILLCOLORHINT */, | |
1288 | &themeColor); | |
1289 | ||
1290 | /* | |
1291 | [DS] Workaround for WindowBlinds: | |
1292 | Some themes return a near black theme color using FILLCOLORHINT, | |
1293 | this makes notebook pages have an ugly black background and makes | |
1294 | text (usually black) unreadable. Retry again with FILLCOLOR. | |
1295 | ||
1296 | This workaround potentially breaks appearance of some themes, | |
1297 | but in practice it already fixes some themes. | |
1298 | */ | |
1299 | if (themeColor == 1) | |
1300 | { | |
1301 | wxUxThemeEngine::Get()->GetThemeColor( | |
1302 | hTheme, | |
1303 | 10 /* TABP_BODY */, | |
1304 | 1 /* NORMAL */, | |
1305 | 3802 /* FILLCOLOR */, | |
1306 | &themeColor); | |
1307 | } | |
1308 | ||
7dccdf81 | 1309 | return wxRGBToColour(themeColor); |
25057aba JS |
1310 | } |
1311 | } | |
1312 | #endif // wxUSE_UXTHEME | |
1313 | ||
1314 | return GetBackgroundColour(); | |
1315 | } | |
1316 | ||
88310e2e VZ |
1317 | // ---------------------------------------------------------------------------- |
1318 | // wxNotebook base class virtuals | |
1319 | // ---------------------------------------------------------------------------- | |
b5c3b538 | 1320 | |
0b481c72 VZ |
1321 | #if wxUSE_CONSTRAINTS |
1322 | ||
b5c3b538 VZ |
1323 | // override these 2 functions to do nothing: everything is done in OnSize |
1324 | ||
4b7f2165 | 1325 | void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse)) |
b5c3b538 VZ |
1326 | { |
1327 | // don't set the sizes of the pages - their correct size is not yet known | |
b8bdaa7c | 1328 | wxControl::SetConstraintSizes(false); |
b5c3b538 VZ |
1329 | } |
1330 | ||
4b7f2165 | 1331 | bool wxNotebook::DoPhase(int WXUNUSED(nPhase)) |
b5c3b538 | 1332 | { |
b8bdaa7c | 1333 | return true; |
b5c3b538 VZ |
1334 | } |
1335 | ||
0b481c72 VZ |
1336 | #endif // wxUSE_CONSTRAINTS |
1337 | ||
0df3fbd7 VZ |
1338 | // ---------------------------------------------------------------------------- |
1339 | // wxNotebook Windows message handlers | |
1340 | // ---------------------------------------------------------------------------- | |
1341 | ||
1342 | bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode, | |
1343 | WXWORD pos, WXHWND control) | |
1344 | { | |
1345 | // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the | |
1346 | // up-down control | |
1347 | if ( control ) | |
b8bdaa7c | 1348 | return false; |
0df3fbd7 VZ |
1349 | |
1350 | return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control); | |
1351 | } | |
1352 | ||
a23fd0e1 | 1353 | bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) |
88310e2e | 1354 | { |
93a19f17 | 1355 | wxNotebookEvent event(wxEVT_NULL, m_windowId); |
88310e2e VZ |
1356 | |
1357 | NMHDR* hdr = (NMHDR *)lParam; | |
1358 | switch ( hdr->code ) { | |
1359 | case TCN_SELCHANGE: | |
1360 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); | |
1361 | break; | |
1362 | ||
1363 | case TCN_SELCHANGING: | |
1364 | event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING); | |
1365 | break; | |
1366 | ||
fd3f686c | 1367 | default: |
a23fd0e1 | 1368 | return wxControl::MSWOnNotify(idCtrl, lParam, result); |
88310e2e VZ |
1369 | } |
1370 | ||
01c8cbf5 | 1371 | event.SetSelection(TabCtrl_GetCurSel(GetHwnd())); |
93a19f17 | 1372 | event.SetOldSelection(m_nSelection); |
88310e2e | 1373 | event.SetEventObject(this); |
a23fd0e1 | 1374 | event.SetInt(idCtrl); |
88310e2e | 1375 | |
fd3f686c VZ |
1376 | bool processed = GetEventHandler()->ProcessEvent(event); |
1377 | *result = !event.IsAllowed(); | |
1378 | return processed; | |
88310e2e VZ |
1379 | } |
1380 | ||
1e6feb95 | 1381 | #endif // wxUSE_NOTEBOOK |