1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/gtk/notebook.cpp
3 // Purpose:
4 // Author:      Robert Roebling
5 // Copyright:   (c) 1998 Robert Roebling, Vadim Zeitlin
6 // Licence:     wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8 
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11 
12 #if wxUSE_NOTEBOOK
13 
14 #include "wx/notebook.h"
15 
16 #ifndef WX_PRECOMP
17     #include "wx/intl.h"
18     #include "wx/log.h"
19     #include "wx/utils.h"
20     #include "wx/msgdlg.h"
21     #include "wx/bitmap.h"
22 #endif
23 
24 #include "wx/imaglist.h"
25 #include "wx/fontutil.h"
26 
27 #include "wx/gtk/private.h"
28 #include "wx/gtk/private/image.h"
29 #include "wx/gtk/private/stylecontext.h"
30 
31 //-----------------------------------------------------------------------------
32 // wxGtkNotebookPage
33 //-----------------------------------------------------------------------------
34 
35 // VZ: this is rather ugly as we keep the pages themselves in an array (it
36 //     allows us to have quite a few functions implemented in the base class)
37 //     but the page data is kept in a separate list, so we must maintain them
38 //     in sync manually... of course, the list had been there before the base
39 //     class which explains it but it still would be nice to do something
40 //     about this one day
41 
42 class wxGtkNotebookPage: public wxObject
43 {
44 public:
45     GtkWidget* m_box;
46     GtkWidget* m_label;
47     GtkWidget* m_image;
48     int m_imageIndex;
49 };
50 
51 
52 #include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxGtkNotebookPagesList)53 WX_DEFINE_LIST(wxGtkNotebookPagesList)
54 
55 extern "C" {
56 static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*);
57 }
58 
59 //-----------------------------------------------------------------------------
60 // "switch_page"
61 //-----------------------------------------------------------------------------
62 
63 extern "C" {
64 static void
switch_page_after(GtkNotebook * widget,GtkNotebookPage *,guint,wxNotebook * win)65 switch_page_after(GtkNotebook* widget, GtkNotebookPage*, guint, wxNotebook* win)
66 {
67     g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win);
68 
69     win->GTKOnPageChanged();
70 }
71 }
72 
73 extern "C" {
74 static void
switch_page(GtkNotebook * widget,GtkNotebookPage *,int page,wxNotebook * win)75 switch_page(GtkNotebook* widget, GtkNotebookPage*, int page, wxNotebook* win)
76 {
77     win->m_oldSelection = gtk_notebook_get_current_page(widget);
78 
79     if (win->SendPageChangingEvent(page))
80         // allow change, unblock handler for changed event
81         g_signal_handlers_unblock_by_func(widget, (void*)switch_page_after, win);
82     else
83         // change vetoed, unblock handler to set selection back
84         g_signal_handlers_unblock_by_func(widget, (void*)event_after, win);
85 }
86 }
87 
88 //-----------------------------------------------------------------------------
89 // "event_after" from m_widget
90 //-----------------------------------------------------------------------------
91 
92 extern "C" {
event_after(GtkNotebook * widget,GdkEvent *,wxNotebook * win)93 static void event_after(GtkNotebook* widget, GdkEvent*, wxNotebook* win)
94 {
95     g_signal_handlers_block_by_func(widget, (void*)event_after, win);
96     g_signal_handlers_block_by_func(widget, (void*)switch_page, win);
97 
98     // restore previous selection
99     gtk_notebook_set_current_page(widget, win->m_oldSelection);
100 
101     g_signal_handlers_unblock_by_func(widget, (void*)switch_page, win);
102 }
103 }
104 
105 //-----------------------------------------------------------------------------
106 // InsertChild callback for wxNotebook
107 //-----------------------------------------------------------------------------
108 
AddChildGTK(wxWindowGTK * child)109 void wxNotebook::AddChildGTK(wxWindowGTK* child)
110 {
111     // Hack Alert! (Part I): This sets the notebook as the parent of the child
112     // widget, and takes care of some details such as updating the state and
113     // style of the child to reflect its new location.  We do this early
114     // because without it GetBestSize (which is used to set the initial size
115     // of controls if an explicit size is not given) will often report
116     // incorrect sizes since the widget's style context is not fully known.
117     // See bug #901694 for details
118     // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863)
119     gtk_widget_set_parent(child->m_widget, m_widget);
120 
121     // NOTE: This should be considered a temporary workaround until we can
122     // work out the details and implement delaying the setting of the initial
123     // size of widgets until the size is really needed.
124 }
125 
126 //-----------------------------------------------------------------------------
127 // wxNotebook
128 //-----------------------------------------------------------------------------
129 
wxBEGIN_EVENT_TABLE(wxNotebook,wxBookCtrlBase)130 wxBEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
131     EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
132 wxEND_EVENT_TABLE()
133 
134 void wxNotebook::Init()
135 {
136     m_padding = 0;
137     m_oldSelection = -1;
138     m_themeEnabled = true;
139 }
140 
wxNotebook()141 wxNotebook::wxNotebook()
142 {
143     Init();
144 }
145 
wxNotebook(wxWindow * parent,wxWindowID id,const wxPoint & pos,const wxSize & size,long style,const wxString & name)146 wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
147       const wxPoint& pos, const wxSize& size,
148       long style, const wxString& name )
149 {
150     Init();
151     Create( parent, id, pos, size, style, name );
152 }
153 
~wxNotebook()154 wxNotebook::~wxNotebook()
155 {
156     // Ensure that we don't generate page changing events during the
157     // destruction, this is unexpected and may reference the already (half)
158     // destroyed parent window, for example. So make sure our switch_page
159     // callback is not called from inside DeleteAllPages() by disconnecting all
160     // the callbacks associated with this widget.
161     GTKDisconnect(m_widget);
162 
163     DeleteAllPages();
164 }
165 
Create(wxWindow * parent,wxWindowID id,const wxPoint & pos,const wxSize & size,long style,const wxString & name)166 bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
167                         const wxPoint& pos, const wxSize& size,
168                         long style, const wxString& name )
169 {
170     if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
171         style |= wxBK_TOP;
172 
173     if (!PreCreation( parent, pos, size ) ||
174         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
175     {
176         wxFAIL_MSG( wxT("wxNoteBook creation failed") );
177         return false;
178     }
179 
180 
181     m_widget = gtk_notebook_new();
182     g_object_ref(m_widget);
183 
184     gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
185 
186     g_signal_connect (m_widget, "switch_page",
187                       G_CALLBACK(switch_page), this);
188 
189     g_signal_connect_after (m_widget, "switch_page",
190                       G_CALLBACK(switch_page_after), this);
191     g_signal_handlers_block_by_func(m_widget, (void*)switch_page_after, this);
192 
193     g_signal_connect(m_widget, "event_after", G_CALLBACK(event_after), this);
194     g_signal_handlers_block_by_func(m_widget, (void*)event_after, this);
195 
196     m_parent->DoAddChild( this );
197 
198     if (m_windowStyle & wxBK_RIGHT)
199         gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
200     if (m_windowStyle & wxBK_LEFT)
201         gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
202     if (m_windowStyle & wxBK_BOTTOM)
203         gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
204 
205     PostCreation(size);
206 
207     return true;
208 }
209 
GetSelection() const210 int wxNotebook::GetSelection() const
211 {
212     wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid notebook") );
213 
214     return gtk_notebook_get_current_page( GTK_NOTEBOOK(m_widget) );
215 }
216 
GetPageText(size_t page) const217 wxString wxNotebook::GetPageText( size_t page ) const
218 {
219     wxCHECK_MSG(page < GetPageCount(), wxEmptyString, "invalid notebook index");
220 
221     GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label);
222     return wxGTK_CONV_BACK(gtk_label_get_text(label));
223 }
224 
GetPageImage(size_t page) const225 int wxNotebook::GetPageImage( size_t page ) const
226 {
227     wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
228 
229     return GetNotebookPage(page)->m_imageIndex;
230 }
231 
GetNotebookPage(int page) const232 wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
233 {
234     return m_pagesData.Item(page)->GetData();
235 }
236 
DoSetSelection(size_t page,int flags)237 int wxNotebook::DoSetSelection( size_t page, int flags )
238 {
239     wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
240 
241     int selOld = GetSelection();
242 
243     if ( !(flags & SetSelection_SendEvent) )
244     {
245         g_signal_handlers_block_by_func(m_widget, (void*)switch_page, this);
246     }
247 
248     gtk_notebook_set_current_page( GTK_NOTEBOOK(m_widget), page );
249 
250     if ( !(flags & SetSelection_SendEvent) )
251     {
252         g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
253     }
254 
255     m_selection = page;
256 
257     wxNotebookPage *client = GetPage(page);
258     if ( client )
259         client->SetFocus();
260 
261     return selOld;
262 }
263 
GTKOnPageChanged()264 void wxNotebook::GTKOnPageChanged()
265 {
266     m_selection = gtk_notebook_get_current_page(GTK_NOTEBOOK(m_widget));
267 
268     SendPageChangedEvent(m_oldSelection);
269 }
270 
SetPageText(size_t page,const wxString & text)271 bool wxNotebook::SetPageText( size_t page, const wxString &text )
272 {
273     wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");
274 
275     GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label);
276     gtk_label_set_text(label, wxGTK_CONV(text));
277 
278     return true;
279 }
280 
SetPageImage(size_t page,int image)281 bool wxNotebook::SetPageImage( size_t page, int image )
282 {
283     wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");
284 
285     wxGtkNotebookPage* pageData = GetNotebookPage(page);
286     if (image >= 0)
287     {
288         wxCHECK_MSG(HasImageList(), false, "invalid notebook imagelist");
289         if (pageData->m_image == NULL)
290         {
291             pageData->m_image = wxGtkImage::New();
292             gtk_widget_show(pageData->m_image);
293             gtk_box_pack_start(GTK_BOX(pageData->m_box),
294                 pageData->m_image, false, false, m_padding);
295         }
296         WX_GTK_IMAGE(pageData->m_image)->Set(GetImageList()->GetBitmap(image));
297     }
298     else if (pageData->m_image)
299     {
300         gtk_container_remove(GTK_CONTAINER(pageData->m_box), pageData->m_image);
301         pageData->m_image = NULL;
302     }
303     pageData->m_imageIndex = image;
304 
305     return true;
306 }
307 
CalcSizeFromPage(const wxSize & sizePage) const308 wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
309 {
310     // Compute the max size of the tab labels.
311     wxSize sizeTabMax;
312     const size_t pageCount = GetPageCount();
313     for ( size_t n = 0; n < pageCount; n++ )
314     {
315         GtkRequisition req;
316         gtk_widget_get_preferred_size(GetNotebookPage(n)->m_box, NULL, &req);
317         sizeTabMax.IncTo(wxSize(req.width, req.height));
318     }
319 
320     wxSize sizeFull(sizePage);
321 #ifdef __WXGTK3__
322     GtkBorder b;
323     if (gtk_check_version(3,20,0) == NULL)
324     {
325         wxGtkStyleContext sc;
326         sc.Add(GTK_TYPE_NOTEBOOK, "notebook", "notebook", "frame", NULL);
327         gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &b);
328         sizeFull.IncBy(b.left + b.right, b.top + b.bottom);
329 
330         sc.Add(G_TYPE_NONE, "header", IsVertical() ? "top" : "left", NULL);
331         sc.Add(G_TYPE_NONE, "tabs", NULL);
332         sc.Add(G_TYPE_NONE, "tab", NULL);
333 
334         wxSize tabMin;
335         gtk_style_context_get(sc, GTK_STATE_FLAG_NORMAL,
336             "min-width", &tabMin.x, "min-height", &tabMin.y, NULL);
337         sizeTabMax.IncTo(tabMin);
338 
339         gtk_style_context_get_margin(sc, GTK_STATE_FLAG_NORMAL, &b);
340         sizeTabMax.IncBy(b.left + b.right, b.top + b.bottom);
341         gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &b);
342         sizeTabMax.IncBy(b.left + b.right, b.top + b.bottom);
343         gtk_style_context_get_padding(sc, GTK_STATE_FLAG_NORMAL, &b);
344         sizeTabMax.IncBy(b.left + b.right, b.top + b.bottom);
345     }
346     else
347     {
348         // Size of tab labels may be reported as zero if we're called too early.
349         // 17 is observed value for text-only label with default Adwaita theme.
350         sizeTabMax.IncTo(wxSize(17, 17));
351 
352         GtkStyleContext* sc = gtk_widget_get_style_context(m_widget);
353         gtk_style_context_save(sc);
354         gtk_style_context_add_region(sc, "tab", GtkRegionFlags(0));
355         gtk_style_context_add_class(sc, "top");
356         gtk_style_context_get_padding(sc, GTK_STATE_FLAG_NORMAL, &b);
357         sizeTabMax.IncBy(b.left + b.right, b.top + b.bottom);
358         gtk_style_context_restore(sc);
359 
360         sizeFull.IncBy(2 * gtk_container_get_border_width(GTK_CONTAINER(m_widget)));
361     }
362 #else // !__WXGTK3__
363     // Size of tab labels may be reported as zero if we're called too early.
364     // 21 is observed value for text-only label with default Adwaita theme.
365     sizeTabMax.IncTo(wxSize(21, 21));
366 
367     int tab_hborder, tab_vborder, focus_width;
368     g_object_get(G_OBJECT(m_widget),
369         "tab-hborder", &tab_hborder, "tab-vborder", &tab_vborder, NULL);
370     gtk_widget_style_get(m_widget, "focus-line-width", &focus_width, NULL);
371     sizeTabMax.x += 2 * (tab_hborder + focus_width + m_widget->style->xthickness);
372     sizeTabMax.y += 2 * (tab_vborder + focus_width + m_widget->style->ythickness);
373 
374     sizeFull.x += 2 * m_widget->style->xthickness;
375     sizeFull.y += 2 * m_widget->style->ythickness;
376 #endif // !__WXGTK3__
377 
378     if ( IsVertical() )
379         sizeFull.y += sizeTabMax.y;
380     else
381         sizeFull.x += sizeTabMax.x;
382 
383     return sizeFull;
384 }
385 
SetPadding(const wxSize & padding)386 void wxNotebook::SetPadding( const wxSize &padding )
387 {
388     wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
389 
390     m_padding = padding.GetWidth();
391 
392     for (size_t i = GetPageCount(); i--;)
393     {
394         wxGtkNotebookPage* pageData = GetNotebookPage(i);
395         if (pageData->m_image)
396         {
397             gtk_box_set_child_packing(GTK_BOX(pageData->m_box),
398                 pageData->m_image, false, false, m_padding, GTK_PACK_START);
399         }
400         gtk_box_set_child_packing(GTK_BOX(pageData->m_box),
401             pageData->m_label, false, false, m_padding, GTK_PACK_END);
402     }
403 }
404 
SetTabSize(const wxSize & WXUNUSED (sz))405 void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
406 {
407     wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
408 }
409 
DeleteAllPages()410 bool wxNotebook::DeleteAllPages()
411 {
412     for (size_t i = GetPageCount(); i--;)
413         DeletePage(i);
414 
415     return wxNotebookBase::DeleteAllPages();
416 }
417 
DoRemovePage(size_t page)418 wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
419 {
420     // We cannot remove the page yet, as GTK sends the "switch_page"
421     // signal before it has removed the notebook-page from its
422     // corresponding list. Thus, if we were to remove the page from
423     // m_pages at this point, the two lists of pages would be out
424     // of sync during the PAGE_CHANGING/PAGE_CHANGED events.
425     wxNotebookPage *client = GetPage(page);
426     if ( !client )
427         return NULL;
428 
429     // we don't need to unparent the client->m_widget; GTK+ will do
430     // that for us (and will throw a warning if we do it!)
431     gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
432 
433     // It's safe to remove the page now.
434     wxASSERT_MSG(GetPage(page) == client, wxT("pages changed during delete"));
435     wxNotebookBase::DoRemovePage(page);
436 
437     wxGtkNotebookPage* p = GetNotebookPage(page);
438     m_pagesData.DeleteObject(p);
439     delete p;
440 
441     return client;
442 }
443 
InsertPage(size_t position,wxNotebookPage * win,const wxString & text,bool select,int imageId)444 bool wxNotebook::InsertPage( size_t position,
445                              wxNotebookPage* win,
446                              const wxString& text,
447                              bool select,
448                              int imageId )
449 {
450     wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );
451 
452     wxCHECK_MSG( win->GetParent() == this, false,
453                wxT("Can't add a page whose parent is not the notebook!") );
454 
455     wxCHECK_MSG( position <= GetPageCount(), false,
456                  wxT("invalid page index in wxNotebookPage::InsertPage()") );
457 
458     // Hack Alert! (Part II): See above in wxNotebook::AddChildGTK
459     // why this has to be done.
460     gtk_widget_unparent(win->m_widget);
461 
462     if (m_themeEnabled)
463         win->SetThemeEnabled(true);
464 
465     GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
466 
467     wxGtkNotebookPage* pageData = new wxGtkNotebookPage;
468 
469     m_pages.insert(m_pages.begin() + position, win);
470     m_pagesData.Insert(position, pageData);
471 
472     // set the label image and text
473     // this must be done before adding the page, as GetPageText
474     // and GetPageImage will otherwise return wrong values in
475     // the page-changed event that results from inserting the
476     // first page.
477     pageData->m_imageIndex = imageId;
478 
479     pageData->m_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
480 #ifndef __WXGTK3__
481     gtk_container_set_border_width(GTK_CONTAINER(pageData->m_box), 2);
482 #endif
483 
484     pageData->m_image = NULL;
485     if (imageId != -1)
486     {
487         if (HasImageList())
488         {
489             const wxBitmap bitmap = GetImageList()->GetBitmap(imageId);
490             pageData->m_image = wxGtkImage::New();
491             WX_GTK_IMAGE(pageData->m_image)->Set(bitmap);
492             gtk_box_pack_start(GTK_BOX(pageData->m_box),
493                 pageData->m_image, false, false, m_padding);
494         }
495         else
496         {
497             wxFAIL_MSG("invalid notebook imagelist");
498         }
499     }
500 
501     /* set the label text */
502     pageData->m_label = gtk_label_new(wxGTK_CONV(wxStripMenuCodes(text)));
503 
504     if (m_windowStyle & wxBK_LEFT)
505         gtk_label_set_angle(GTK_LABEL(pageData->m_label), 90);
506     if (m_windowStyle & wxBK_RIGHT)
507         gtk_label_set_angle(GTK_LABEL(pageData->m_label), 270);
508 
509     gtk_box_pack_end(GTK_BOX(pageData->m_box),
510         pageData->m_label, false, false, m_padding);
511 
512     gtk_widget_show_all(pageData->m_box);
513 
514     // Inserting the page may generate selection changing events that are not
515     // expected here: we will send them ourselves below if necessary.
516     g_signal_handlers_block_by_func(m_widget, (void*)switch_page, this);
517     gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position);
518     g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
519 
520     /* apply current style */
521 #ifdef __WXGTK3__
522     GTKApplyStyle(pageData->m_label, NULL);
523 #else
524     GtkRcStyle *style = GTKCreateWidgetStyle();
525     if ( style )
526     {
527         gtk_widget_modify_style(pageData->m_label, style);
528         g_object_unref(style);
529     }
530 #endif
531 
532     DoSetSelectionAfterInsertion(position, select);
533 
534     InvalidateBestSize();
535     return true;
536 }
537 
538 // helper for HitTest(): check if the point lies inside the given widget which
539 // is the child of the notebook whose position and border size are passed as
540 // parameters
541 static bool
IsPointInsideWidget(const wxPoint & pt,GtkWidget * w,gint x,gint y,gint border=0)542 IsPointInsideWidget(const wxPoint& pt, GtkWidget *w,
543                     gint x, gint y, gint border = 0)
544 {
545     GtkAllocation a;
546     gtk_widget_get_allocation(w, &a);
547     return
548         (pt.x >= a.x - x - border) &&
549         (pt.x <= a.x - x + border + a.width) &&
550         (pt.y >= a.y - y - border) &&
551         (pt.y <= a.y - y + border + a.height);
552 }
553 
HitTest(const wxPoint & pt,long * flags) const554 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
555 {
556     GtkAllocation a;
557     gtk_widget_get_allocation(m_widget, &a);
558     const int x = a.x;
559     const int y = a.y;
560 
561     const size_t count = GetPageCount();
562 
563     for (size_t i = 0; i < count; i++)
564     {
565         wxGtkNotebookPage* pageData = GetNotebookPage(i);
566         GtkWidget* box = pageData->m_box;
567 
568         if (!gtk_widget_get_child_visible(box))
569             continue;
570 
571         const gint border = gtk_container_get_border_width(GTK_CONTAINER(box));
572 
573         if ( IsPointInsideWidget(pt, box, x, y, border) )
574         {
575             // ok, we're inside this tab -- now find out where, if needed
576             if ( flags )
577             {
578                 if (pageData->m_image && IsPointInsideWidget(pt, pageData->m_image, x, y))
579                 {
580                     *flags = wxBK_HITTEST_ONICON;
581                 }
582                 else if (IsPointInsideWidget(pt, pageData->m_label, x, y))
583                 {
584                     *flags = wxBK_HITTEST_ONLABEL;
585                 }
586                 else
587                 {
588                     *flags = wxBK_HITTEST_ONITEM;
589                 }
590             }
591 
592             return i;
593         }
594     }
595 
596     if ( flags )
597     {
598         *flags = wxBK_HITTEST_NOWHERE;
599         wxWindowBase * page = GetCurrentPage();
600         if ( page )
601         {
602             // rect origin is in notebook's parent coordinates
603             wxRect rect = page->GetRect();
604 
605             // adjust it to the notebook's coordinates
606             wxPoint pos = GetPosition();
607             rect.x -= pos.x;
608             rect.y -= pos.y;
609             if ( rect.Contains( pt ) )
610                 *flags |= wxBK_HITTEST_ONPAGE;
611         }
612     }
613 
614     return wxNOT_FOUND;
615 }
616 
OnNavigationKey(wxNavigationKeyEvent & event)617 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
618 {
619     if (event.IsWindowChange())
620         AdvanceSelection( event.GetDirection() );
621     else
622         event.Skip();
623 }
624 
625 #if wxUSE_CONSTRAINTS
626 
627 // override these 2 functions to do nothing: everything is done in OnSize
SetConstraintSizes(bool WXUNUSED (recurse))628 void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
629 {
630     // don't set the sizes of the pages - their correct size is not yet known
631     wxControl::SetConstraintSizes(false);
632 }
633 
DoPhase(int WXUNUSED (nPhase))634 bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
635 {
636     return true;
637 }
638 
639 #endif
640 
DoApplyWidgetStyle(GtkRcStyle * style)641 void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style)
642 {
643     GTKApplyStyle(m_widget, style);
644     for (size_t i = GetPageCount(); i--;)
645         GTKApplyStyle(GetNotebookPage(i)->m_label, style);
646 }
647 
GTKGetWindow(wxArrayGdkWindows & windows) const648 GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const
649 {
650     windows.push_back(gtk_widget_get_window(m_widget));
651 #ifdef __WXGTK3__
652     GdkWindow* window = GTKFindWindow(m_widget);
653     if (window)
654         windows.push_back(window);
655 #else
656     windows.push_back(GTK_NOTEBOOK(m_widget)->event_window);
657 #endif
658 
659     return NULL;
660 }
661 
662 // static
663 wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant WXUNUSED (variant))664 wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
665 {
666     return GetDefaultAttributesFromGTKWidget(gtk_notebook_new());
667 }
668 
669 #endif
670