]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/notebook.cpp
Misc validity fixes to samples/xrc/rc/*.xrc.
[wxWidgets.git] / src / gtk / notebook.cpp
CommitLineData
53b28675 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/gtk/notebook.cpp
53b28675
RR
3// Purpose:
4// Author: Robert Roebling
01111366 5// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
65571936 6// Licence: wxWindows licence
53b28675
RR
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
88a7a4e1
WS
12#if wxUSE_NOTEBOOK
13
53b28675 14#include "wx/notebook.h"
dcf924a3 15
88a7a4e1
WS
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
e4db172a 18 #include "wx/log.h"
de6185e2 19 #include "wx/utils.h"
246c5004 20 #include "wx/msgdlg.h"
0bca0373 21 #include "wx/bitmap.h"
88a7a4e1 22#endif
dcf924a3 23
53b28675 24#include "wx/imaglist.h"
c077ee94 25#include "wx/fontutil.h"
83624f79 26
9dc44eff 27#include <gtk/gtk.h>
9e691f46 28#include "wx/gtk/private.h"
9dc44eff 29#include "wx/gtk/private/gtk2-compat.h"
9e691f46 30
219f895a 31//-----------------------------------------------------------------------------
80a58c99 32// wxGtkNotebookPage
219f895a
RR
33//-----------------------------------------------------------------------------
34
07b8d7ec
VZ
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
80a58c99 42class wxGtkNotebookPage: public wxObject
219f895a
RR
43{
44public:
c58d2238
PC
45 GtkWidget* m_box;
46 GtkWidget* m_label;
47 GtkWidget* m_image;
48 int m_imageIndex;
219f895a
RR
49};
50
c077ee94 51
07b8d7ec 52#include "wx/listimpl.cpp"
28c91b7d 53WX_DEFINE_LIST(wxGtkNotebookPagesList)
07b8d7ec 54
75c6febf
PC
55extern "C" {
56static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*);
57}
c077ee94 58
ff829f3f 59//-----------------------------------------------------------------------------
5b011451 60// "switch_page"
ff829f3f
VZ
61//-----------------------------------------------------------------------------
62
865bb325 63extern "C" {
75c6febf 64static void
681be2ef 65switch_page_after(GtkNotebook* widget, GtkNotebookPage*, guint, wxNotebook* win)
ff829f3f 66{
75c6febf 67 g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win);
681be2ef
VZ
68
69 win->GTKOnPageChanged();
75c6febf
PC
70}
71}
36202885 72
75c6febf
PC
73extern "C" {
74static void
75switch_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);
1d6fcbcc 82 else
75c6febf
PC
83 // change vetoed, unblock handler to set selection back
84 g_signal_handlers_unblock_by_func(widget, (void*)event_after, win);
c9882624
RR
85}
86}
ef44a621 87
75c6febf
PC
88//-----------------------------------------------------------------------------
89// "event_after" from m_widget
90//-----------------------------------------------------------------------------
91
c9882624 92extern "C" {
75c6febf 93static void event_after(GtkNotebook* widget, GdkEvent*, wxNotebook* win)
c9882624 94{
75c6febf
PC
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);
ff829f3f 102}
865bb325 103}
ff829f3f 104
6ca41e57
RR
105//-----------------------------------------------------------------------------
106// InsertChild callback for wxNotebook
107//-----------------------------------------------------------------------------
108
48200154 109void wxNotebook::AddChildGTK(wxWindowGTK* child)
6ca41e57 110{
fff8475e
RD
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
2ded391d 118 // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863)
48200154 119 gtk_widget_set_parent(child->m_widget, m_widget);
fff8475e
RD
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.
6ca41e57
RR
124}
125
53b28675
RR
126//-----------------------------------------------------------------------------
127// wxNotebook
128//-----------------------------------------------------------------------------
129
8dba4c72 130BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
b98d804b
RR
131 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
132END_EVENT_TABLE()
f861258f 133
ff829f3f 134void wxNotebook::Init()
53b28675 135{
b318dc42 136 m_padding = 0;
c9882624 137 m_oldSelection = -1;
de6185e2 138 m_themeEnabled = true;
ff829f3f
VZ
139}
140
141wxNotebook::wxNotebook()
142{
b292e2f5 143 Init();
ff7b1510 144}
53b28675 145
debe6624 146wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
53b28675 147 const wxPoint& pos, const wxSize& size,
debe6624 148 long style, const wxString& name )
53b28675 149{
b292e2f5
RR
150 Init();
151 Create( parent, id, pos, size, style, name );
ff7b1510 152}
53b28675 153
ff829f3f 154wxNotebook::~wxNotebook()
53b28675 155{
b292e2f5 156 DeleteAllPages();
ff7b1510 157}
53b28675 158
debe6624 159bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
07b8d7ec
VZ
160 const wxPoint& pos, const wxSize& size,
161 long style, const wxString& name )
53b28675 162{
90f9b8ef
JS
163 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
164 style |= wxBK_TOP;
165
4dcaf11a
RR
166 if (!PreCreation( parent, pos, size ) ||
167 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
168 {
223d09f6 169 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
de6185e2 170 return false;
4dcaf11a
RR
171 }
172
ff829f3f 173
b292e2f5 174 m_widget = gtk_notebook_new();
9ff9d30c 175 g_object_ref(m_widget);
53b28675 176
b292e2f5 177 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
caac5181 178
9fa72bd2 179 g_signal_connect (m_widget, "switch_page",
75c6febf 180 G_CALLBACK(switch_page), this);
c9882624
RR
181
182 g_signal_connect_after (m_widget, "switch_page",
75c6febf
PC
183 G_CALLBACK(switch_page_after), this);
184 g_signal_handlers_block_by_func(m_widget, (void*)switch_page_after, this);
185
186 g_signal_connect(m_widget, "event_after", G_CALLBACK(event_after), this);
187 g_signal_handlers_block_by_func(m_widget, (void*)event_after, this);
ff829f3f 188
f03fc89f 189 m_parent->DoAddChild( this );
ef44a621 190
df034cc6 191 if (m_windowStyle & wxBK_RIGHT)
8712c6e7 192 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
df034cc6 193 if (m_windowStyle & wxBK_LEFT)
8712c6e7 194 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
df034cc6 195 if (m_windowStyle & wxBK_BOTTOM)
8712c6e7 196 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
a3a7f879 197
abdeb9e7 198 PostCreation(size);
ff829f3f 199
de6185e2 200 return true;
ff7b1510 201}
53b28675 202
ff829f3f 203int wxNotebook::GetSelection() const
53b28675 204{
7e837615 205 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid notebook") );
53b28675 206
c9882624 207 return gtk_notebook_get_current_page( GTK_NOTEBOOK(m_widget) );
ff7b1510 208}
53b28675 209
789d0a3d 210wxString wxNotebook::GetPageText( size_t page ) const
53b28675 211{
c58d2238 212 wxCHECK_MSG(page < GetPageCount(), wxEmptyString, "invalid notebook index");
ef44a621 213
c58d2238
PC
214 GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label);
215 return wxGTK_CONV_BACK(gtk_label_get_text(label));
ff7b1510 216}
53b28675 217
789d0a3d 218int wxNotebook::GetPageImage( size_t page ) const
53b28675 219{
7e837615 220 wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
a81258be 221
c58d2238 222 return GetNotebookPage(page)->m_imageIndex;
ff7b1510 223}
53b28675 224
80a58c99 225wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
53b28675 226{
07b8d7ec 227 return m_pagesData.Item(page)->GetData();
ff7b1510 228}
53b28675 229
1d6fcbcc 230int wxNotebook::DoSetSelection( size_t page, int flags )
53b28675 231{
7e837615 232 wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
ff829f3f 233
587ce561 234 int selOld = GetSelection();
a6aa9b1e 235
1d6fcbcc 236 if ( !(flags & SetSelection_SendEvent) )
c9882624 237 {
75c6febf 238 g_signal_handlers_block_by_func(m_widget, (void*)switch_page, this);
c9882624 239 }
1d6fcbcc 240
38f1df7c 241 gtk_notebook_set_current_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 242
1d6fcbcc
VZ
243 if ( !(flags & SetSelection_SendEvent) )
244 {
75c6febf 245 g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
1d6fcbcc 246 }
1d6fcbcc 247
681be2ef
VZ
248 m_selection = page;
249
07b8d7ec
VZ
250 wxNotebookPage *client = GetPage(page);
251 if ( client )
252 client->SetFocus();
b656febd 253
07b8d7ec 254 return selOld;
ff7b1510 255}
53b28675 256
681be2ef
VZ
257void wxNotebook::GTKOnPageChanged()
258{
259 m_selection = gtk_notebook_get_current_page(GTK_NOTEBOOK(m_widget));
260
261 SendPageChangedEvent(m_oldSelection);
262}
263
789d0a3d 264bool wxNotebook::SetPageText( size_t page, const wxString &text )
53b28675 265{
c58d2238 266 wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");
ff829f3f 267
c58d2238
PC
268 GtkLabel* label = GTK_LABEL(GetNotebookPage(page)->m_label);
269 gtk_label_set_text(label, wxGTK_CONV(text));
a6aa9b1e 270
de6185e2 271 return true;
ff7b1510 272}
53b28675 273
789d0a3d 274bool wxNotebook::SetPageImage( size_t page, int image )
53b28675 275{
c58d2238 276 wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");
f861258f 277
c58d2238
PC
278 wxGtkNotebookPage* pageData = GetNotebookPage(page);
279 if (image >= 0)
3eb78d7e 280 {
abfdefed
VZ
281 wxCHECK_MSG(HasImageList(), false, "invalid notebook imagelist");
282 const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(image);
c58d2238
PC
283 if (bitmap == NULL)
284 return false;
285 if (pageData->m_image)
8712c6e7 286 {
c58d2238
PC
287 gtk_image_set_from_pixbuf(
288 GTK_IMAGE(pageData->m_image), bitmap->GetPixbuf());
8712c6e7 289 }
c58d2238 290 else
8712c6e7 291 {
c58d2238
PC
292 pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
293 gtk_widget_show(pageData->m_image);
294 gtk_box_pack_start(GTK_BOX(pageData->m_box),
295 pageData->m_image, false, false, m_padding);
3eb78d7e
RR
296 }
297 }
c58d2238 298 else if (pageData->m_image)
3eb78d7e 299 {
c58d2238
PC
300 gtk_widget_destroy(pageData->m_image);
301 pageData->m_image = NULL;
3eb78d7e 302 }
c58d2238 303 pageData->m_imageIndex = image;
53b28675 304
de6185e2 305 return true;
ff7b1510 306}
53b28675 307
864181f4 308wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
53b28675 309{
864181f4
VZ
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;
1897abe1 316 gtk_widget_get_preferred_size(GetNotebookPage(n)->m_box, NULL, &req);
864181f4
VZ
317 sizeTabMax.IncTo(wxSize(req.width, req.height));
318 }
319
320 // Unfortunately this doesn't account for the real tab size and I don't
321 // know how to find it, e.g. where do the margins below come from.
322 const int PAGE_MARGIN = 3;
323 const int TAB_MARGIN = 4;
324
325 sizeTabMax.IncBy(3*TAB_MARGIN);
326
327 wxSize sizeFull(sizePage);
328 if ( IsVertical() )
329 sizeFull.y += sizeTabMax.y;
330 else
331 sizeFull.x += sizeTabMax.x;
332
333 sizeFull.IncBy(2*PAGE_MARGIN);
334
335 return sizeFull;
ff7b1510 336}
53b28675 337
b318dc42 338void wxNotebook::SetPadding( const wxSize &padding )
53b28675 339{
b318dc42
JS
340 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
341
342 m_padding = padding.GetWidth();
343
c58d2238 344 for (size_t i = GetPageCount(); i--;)
b318dc42 345 {
c58d2238
PC
346 wxGtkNotebookPage* pageData = GetNotebookPage(i);
347 if (pageData->m_image)
b318dc42 348 {
c58d2238
PC
349 gtk_box_set_child_packing(GTK_BOX(pageData->m_box),
350 pageData->m_image, false, false, m_padding, GTK_PACK_START);
b318dc42 351 }
c58d2238
PC
352 gtk_box_set_child_packing(GTK_BOX(pageData->m_box),
353 pageData->m_label, false, false, m_padding, GTK_PACK_END);
b318dc42 354 }
ff7b1510 355}
53b28675 356
74e3313b 357void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
ca8b28f2 358{
223d09f6 359 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
ca8b28f2
JS
360}
361
ff829f3f 362bool wxNotebook::DeleteAllPages()
53b28675 363{
c58d2238
PC
364 for (size_t i = GetPageCount(); i--;)
365 DeletePage(i);
a81258be 366
10199e27 367 return wxNotebookBase::DeleteAllPages();
ff7b1510 368}
53b28675 369
acb69c13 370wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
53b28675 371{
a27555e4
RR
372 // We cannot remove the page yet, as GTK sends the "switch_page"
373 // signal before it has removed the notebook-page from its
374 // corresponding list. Thus, if we were to remove the page from
375 // m_pages at this point, the two lists of pages would be out
376 // of sync during the PAGE_CHANGING/PAGE_CHANGED events.
377 wxNotebookPage *client = GetPage(page);
10199e27
VZ
378 if ( !client )
379 return NULL;
fed46e72 380
9c862cfb
RR
381 // we don't need to unparent the client->m_widget; GTK+ will do
382 // that for us (and will throw a warning if we do it!)
587ce561 383 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
ff829f3f 384
a27555e4
RR
385 // It's safe to remove the page now.
386 wxASSERT_MSG(GetPage(page) == client, wxT("pages changed during delete"));
387 wxNotebookBase::DoRemovePage(page);
388
222ed1d6
MB
389 wxGtkNotebookPage* p = GetNotebookPage(page);
390 m_pagesData.DeleteObject(p);
391 delete p;
03647350 392
07b8d7ec 393 return client;
ff7b1510 394}
53b28675 395
789d0a3d 396bool wxNotebook::InsertPage( size_t position,
07b8d7ec
VZ
397 wxNotebookPage* win,
398 const wxString& text,
399 bool select,
400 int imageId )
53b28675 401{
de6185e2 402 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid notebook") );
a81258be 403
de6185e2 404 wxCHECK_MSG( win->GetParent() == this, false,
223d09f6 405 wxT("Can't add a page whose parent is not the notebook!") );
8aadf227 406
de6185e2 407 wxCHECK_MSG( position <= GetPageCount(), false,
9a83f860 408 wxT("invalid page index in wxNotebookPage::InsertPage()") );
07b8d7ec 409
48200154 410 // Hack Alert! (Part II): See above in wxNotebook::AddChildGTK
9ff9d30c
PC
411 // why this has to be done.
412 gtk_widget_unparent(win->m_widget);
d7f1759a 413
a2d93e73 414 if (m_themeEnabled)
de6185e2 415 win->SetThemeEnabled(true);
a2d93e73 416
587ce561 417 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
53b28675 418
c58d2238 419 wxGtkNotebookPage* pageData = new wxGtkNotebookPage;
a6aa9b1e 420
07b8d7ec 421 m_pages.Insert(win, position);
c58d2238 422 m_pagesData.Insert(position, pageData);
8aadf227 423
f986fe76
VZ
424 // set the label image and text
425 // this must be done before adding the page, as GetPageText
426 // and GetPageImage will otherwise return wrong values in
427 // the page-changed event that results from inserting the
428 // first page.
c58d2238 429 pageData->m_imageIndex = imageId;
f986fe76 430
1897abe1 431 pageData->m_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
c58d2238 432 gtk_container_set_border_width(GTK_CONTAINER(pageData->m_box), 2);
a6aa9b1e 433
c58d2238 434 pageData->m_image = NULL;
3eb78d7e 435 if (imageId != -1)
e4a81a2e 436 {
abfdefed 437 if (HasImageList())
c58d2238 438 {
abfdefed 439 const wxBitmap* bitmap = GetImageList()->GetBitmapPtr(imageId);
c58d2238
PC
440 pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
441 gtk_box_pack_start(GTK_BOX(pageData->m_box),
442 pageData->m_image, false, false, m_padding);
443 }
444 else
4c2ea599 445 {
c58d2238 446 wxFAIL_MSG("invalid notebook imagelist");
4c2ea599 447 }
3eb78d7e 448 }
24d20a8f 449
587ce561 450 /* set the label text */
c58d2238
PC
451 pageData->m_label = gtk_label_new(wxGTK_CONV(wxStripMenuCodes(text)));
452 gtk_box_pack_end(GTK_BOX(pageData->m_box),
453 pageData->m_label, false, false, m_padding);
454
455 gtk_widget_show_all(pageData->m_box);
456 gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position);
279b5e2e 457
97357eec 458 /* apply current style */
9dc44eff
PC
459#ifdef __WXGTK3__
460 GTKApplyStyle(pageData->m_label, NULL);
461#else
496e7ec6 462 GtkRcStyle *style = GTKCreateWidgetStyle();
97357eec
VS
463 if ( style )
464 {
c58d2238 465 gtk_widget_modify_style(pageData->m_label, style);
385e8575 466 g_object_unref(style);
88d19775 467 }
9dc44eff 468#endif
88d19775 469
c58d2238 470 if (select && GetPageCount() > 1)
587ce561 471 {
c9882624 472 SetSelection( position );
587ce561 473 }
741fd203 474
37144cf0 475 InvalidateBestSize();
de6185e2 476 return true;
ff7b1510 477}
53b28675 478
279b5e2e
VZ
479// helper for HitTest(): check if the point lies inside the given widget which
480// is the child of the notebook whose position and border size are passed as
481// parameters
482static bool
483IsPointInsideWidget(const wxPoint& pt, GtkWidget *w,
484 gint x, gint y, gint border = 0)
485{
385e8575
PC
486 GtkAllocation a;
487 gtk_widget_get_allocation(w, &a);
279b5e2e 488 return
385e8575
PC
489 (pt.x >= a.x - x - border) &&
490 (pt.x <= a.x - x + border + a.width) &&
491 (pt.y >= a.y - y - border) &&
492 (pt.y <= a.y - y + border + a.height);
279b5e2e
VZ
493}
494
495int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
496{
385e8575
PC
497 GtkAllocation a;
498 gtk_widget_get_allocation(m_widget, &a);
499 const int x = a.x;
500 const int y = a.y;
279b5e2e
VZ
501
502 const size_t count = GetPageCount();
f660b206
MR
503 size_t i = 0;
504
1897abe1 505#ifndef __WXGTK3__
f660b206 506 GtkNotebook * notebook = GTK_NOTEBOOK(m_widget);
a5bb4f82 507 if (gtk_notebook_get_scrollable(notebook))
f660b206 508 i = g_list_position( notebook->children, notebook->first_tab );
385e8575 509#endif
f660b206
MR
510
511 for ( ; i < count; i++ )
279b5e2e 512 {
c58d2238
PC
513 wxGtkNotebookPage* pageData = GetNotebookPage(i);
514 GtkWidget* box = pageData->m_box;
279b5e2e 515
279b5e2e 516 const gint border = gtk_container_get_border_width(GTK_CONTAINER(box));
68567a96 517
279b5e2e
VZ
518 if ( IsPointInsideWidget(pt, box, x, y, border) )
519 {
520 // ok, we're inside this tab -- now find out where, if needed
521 if ( flags )
522 {
c58d2238 523 if (pageData->m_image && IsPointInsideWidget(pt, pageData->m_image, x, y))
279b5e2e 524 {
9804d540 525 *flags = wxBK_HITTEST_ONICON;
279b5e2e 526 }
c58d2238 527 else if (IsPointInsideWidget(pt, pageData->m_label, x, y))
279b5e2e 528 {
9804d540 529 *flags = wxBK_HITTEST_ONLABEL;
279b5e2e
VZ
530 }
531 else
532 {
9804d540 533 *flags = wxBK_HITTEST_ONITEM;
279b5e2e
VZ
534 }
535 }
536
537 return i;
538 }
539 }
540
541 if ( flags )
d0a84b63 542 {
9804d540 543 *flags = wxBK_HITTEST_NOWHERE;
d0a84b63
VZ
544 wxWindowBase * page = GetCurrentPage();
545 if ( page )
546 {
547 // rect origin is in notebook's parent coordinates
548 wxRect rect = page->GetRect();
549
550 // adjust it to the notebook's coordinates
551 wxPoint pos = GetPosition();
552 rect.x -= pos.x;
553 rect.y -= pos.y;
22a35096 554 if ( rect.Contains( pt ) )
9804d540 555 *flags |= wxBK_HITTEST_ONPAGE;
d0a84b63
VZ
556 }
557 }
279b5e2e
VZ
558
559 return wxNOT_FOUND;
560}
561
b98d804b
RR
562void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
563{
f861258f 564 if (event.IsWindowChange())
b98d804b 565 AdvanceSelection( event.GetDirection() );
f861258f 566 else
b98d804b
RR
567 event.Skip();
568}
569
93d38175
VS
570#if wxUSE_CONSTRAINTS
571
5a8c929e 572// override these 2 functions to do nothing: everything is done in OnSize
e3e65dac 573void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
5a8c929e 574{
b292e2f5 575 // don't set the sizes of the pages - their correct size is not yet known
de6185e2 576 wxControl::SetConstraintSizes(false);
5a8c929e
VZ
577}
578
e3e65dac 579bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
5a8c929e 580{
de6185e2 581 return true;
5a8c929e
VZ
582}
583
93d38175
VS
584#endif
585
f40fdaa3 586void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style)
a81258be 587{
9dc44eff 588 GTKApplyStyle(m_widget, style);
c58d2238 589 for (size_t i = GetPageCount(); i--;)
9dc44eff 590 GTKApplyStyle(GetNotebookPage(i)->m_label, style);
a81258be
RR
591}
592
ef5c70f9 593GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const
58d1c1ae 594{
385e8575 595 windows.push_back(gtk_widget_get_window(m_widget));
9dc44eff
PC
596#ifdef __WXGTK3__
597 // no access to internal GdkWindows
598#else
ef5c70f9 599 windows.push_back(GTK_NOTEBOOK(m_widget)->event_window);
9dc44eff 600#endif
ef5c70f9
VZ
601
602 return NULL;
58d1c1ae
RR
603}
604
9d522606
RD
605// static
606wxVisualAttributes
607wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
608{
7fff16b8 609 return GetDefaultAttributesFromGTKWidget(gtk_notebook_new());
9d522606
RD
610}
611
a3a7f879 612#endif