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