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