]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/notebook.cpp
Upported menu bitmaps from 2.4.2
[wxWidgets.git] / src / gtk / notebook.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: notebook.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "notebook.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/notebook.h"
18
19 #if wxUSE_NOTEBOOK
20
21 #include "wx/panel.h"
22 #include "wx/utils.h"
23 #include "wx/imaglist.h"
24 #include "wx/intl.h"
25 #include "wx/log.h"
26 #include "wx/bitmap.h"
27
28 #include "wx/gtk/private.h"
29 #include "wx/gtk/win_gtk.h"
30
31 #include <gdk/gdkkeysyms.h>
32
33 // ----------------------------------------------------------------------------
34 // events
35 // ----------------------------------------------------------------------------
36
37 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
38 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
39
40 //-----------------------------------------------------------------------------
41 // idle system
42 //-----------------------------------------------------------------------------
43
44 extern void wxapp_install_idle_handler();
45 extern bool g_isIdle;
46
47 //-----------------------------------------------------------------------------
48 // data
49 //-----------------------------------------------------------------------------
50
51 extern bool g_blockEventsOnDrag;
52
53 //-----------------------------------------------------------------------------
54 // wxGtkNotebookPage
55 //-----------------------------------------------------------------------------
56
57 // VZ: this is rather ugly as we keep the pages themselves in an array (it
58 // allows us to have quite a few functions implemented in the base class)
59 // but the page data is kept in a separate list, so we must maintain them
60 // in sync manually... of course, the list had been there before the base
61 // class which explains it but it still would be nice to do something
62 // about this one day
63
64 class wxGtkNotebookPage: public wxObject
65 {
66 public:
67 wxGtkNotebookPage()
68 {
69 m_image = -1;
70 m_page = (GtkNotebookPage *) NULL;
71 m_box = (GtkWidget *) NULL;
72 }
73
74 wxString m_text;
75 int m_image;
76 GtkNotebookPage *m_page;
77 GtkLabel *m_label;
78 GtkWidget *m_box; // in which the label and image are packed
79 };
80
81 #include "wx/listimpl.cpp"
82 WX_DEFINE_LIST(wxGtkNotebookPagesList);
83
84 //-----------------------------------------------------------------------------
85 // "switch_page"
86 //-----------------------------------------------------------------------------
87
88 static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
89 GtkNotebookPage *WXUNUSED(page),
90 gint page,
91 wxNotebook *notebook )
92 {
93 // are you trying to call SetSelection() from a notebook event handler?
94 // you shouldn't!
95 wxCHECK_RET( !notebook->m_inSwitchPage,
96 _T("gtk_notebook_page_change_callback reentered") );
97
98 notebook->m_inSwitchPage = TRUE;
99 if (g_isIdle)
100 wxapp_install_idle_handler();
101
102 int old = notebook->GetSelection();
103
104 wxNotebookEvent eventChanging( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,
105 notebook->GetId(), page, old );
106 eventChanging.SetEventObject( notebook );
107
108 if ( (notebook->GetEventHandler()->ProcessEvent(eventChanging)) &&
109 !eventChanging.IsAllowed() )
110 {
111 /* program doesn't allow the page change */
112 gtk_signal_emit_stop_by_name( GTK_OBJECT(notebook->m_widget),
113 "switch_page" );
114 }
115 else // change allowed
116 {
117 // make wxNotebook::GetSelection() return the correct (i.e. consistent
118 // with wxNotebookEvent::GetSelection()) value even though the page is
119 // not really changed in GTK+
120 notebook->m_selection = page;
121
122 wxNotebookEvent eventChanged( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
123 notebook->GetId(), page, old );
124 eventChanged.SetEventObject( notebook );
125 notebook->GetEventHandler()->ProcessEvent( eventChanged );
126 }
127
128 notebook->m_inSwitchPage = FALSE;
129 }
130
131 //-----------------------------------------------------------------------------
132 // "size_allocate"
133 //-----------------------------------------------------------------------------
134
135 static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
136 {
137 if (g_isIdle)
138 wxapp_install_idle_handler();
139
140 if ((win->m_x == alloc->x) &&
141 (win->m_y == alloc->y) &&
142 (win->m_width == alloc->width) &&
143 (win->m_height == alloc->height))
144 {
145 return;
146 }
147
148 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
149
150 /* GTK 1.2 up to version 1.2.5 is broken so that we have to call allocate
151 here in order to make repositioning after resizing to take effect. */
152 if ((gtk_major_version == 1) &&
153 (gtk_minor_version == 2) &&
154 (gtk_micro_version < 6) &&
155 (win->m_wxwindow) &&
156 (GTK_WIDGET_REALIZED(win->m_wxwindow)))
157 {
158 gtk_widget_size_allocate( win->m_wxwindow, alloc );
159 }
160 }
161
162 //-----------------------------------------------------------------------------
163 // "realize" from m_widget
164 //-----------------------------------------------------------------------------
165
166 static gint
167 gtk_notebook_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
168 {
169 if (g_isIdle)
170 wxapp_install_idle_handler();
171
172 /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize
173 here in order to make repositioning before showing to take effect. */
174 gtk_widget_queue_resize( win->m_widget );
175
176 return FALSE;
177 }
178
179 //-----------------------------------------------------------------------------
180 // "key_press_event"
181 //-----------------------------------------------------------------------------
182
183 static gint gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *win )
184 {
185 if (g_isIdle)
186 wxapp_install_idle_handler();
187
188 if (!win->m_hasVMT) return FALSE;
189 if (g_blockEventsOnDrag) return FALSE;
190
191 /* win is a control: tab can be propagated up */
192 if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
193 {
194 int sel = win->GetSelection();
195 if (sel == -1)
196 return TRUE;
197 wxGtkNotebookPage *nb_page = win->GetNotebookPage(sel);
198 wxCHECK_MSG( nb_page, FALSE, _T("invalid selection in wxNotebook") );
199
200 wxNavigationKeyEvent event;
201 event.SetEventObject( win );
202 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
203 event.SetDirection( (gdk_event->keyval == GDK_Tab) );
204 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
205 event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
206 event.SetCurrentFocus( win );
207
208 wxNotebookPage *client = win->GetPage(sel);
209 if ( !client->GetEventHandler()->ProcessEvent( event ) )
210 {
211 client->SetFocus();
212 }
213
214 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
215 return TRUE;
216 }
217
218 return FALSE;
219 }
220
221 //-----------------------------------------------------------------------------
222 // InsertChild callback for wxNotebook
223 //-----------------------------------------------------------------------------
224
225 static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
226 {
227 // Hack alert! We manually set the child window
228 // parent field so that GTK can query the
229 // notebook's style and font.
230 child->m_widget->parent = parent->m_widget;
231 }
232
233 //-----------------------------------------------------------------------------
234 // wxNotebook
235 //-----------------------------------------------------------------------------
236
237 IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl)
238
239 BEGIN_EVENT_TABLE(wxNotebook, wxControl)
240 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
241 END_EVENT_TABLE()
242
243 void wxNotebook::Init()
244 {
245 m_padding = 0;
246 m_inSwitchPage = FALSE;
247
248 m_imageList = (wxImageList *) NULL;
249 m_selection = -1;
250 m_themeEnabled = TRUE;
251 }
252
253 wxNotebook::wxNotebook()
254 {
255 Init();
256 }
257
258 wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
259 const wxPoint& pos, const wxSize& size,
260 long style, const wxString& name )
261 {
262 Init();
263 Create( parent, id, pos, size, style, name );
264 }
265
266 wxNotebook::~wxNotebook()
267 {
268 DeleteAllPages();
269 }
270
271 bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
272 const wxPoint& pos, const wxSize& size,
273 long style, const wxString& name )
274 {
275 m_needParent = TRUE;
276 m_acceptsFocus = TRUE;
277 m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
278
279 if (!PreCreation( parent, pos, size ) ||
280 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
281 {
282 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
283 return FALSE;
284 }
285
286
287 m_widget = gtk_notebook_new();
288
289 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
290
291 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
292 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
293
294 m_parent->DoAddChild( this );
295
296 if (m_windowStyle & wxNB_RIGHT)
297 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_RIGHT );
298 if (m_windowStyle & wxNB_LEFT)
299 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_LEFT );
300 if (m_windowStyle & wxNB_BOTTOM)
301 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget), GTK_POS_BOTTOM );
302
303 gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event",
304 GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this );
305
306 PostCreation();
307
308 SetFont( parent->GetFont() );
309
310 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
311 GTK_SIGNAL_FUNC(gtk_notebook_realized_callback), (gpointer) this );
312
313 Show( TRUE );
314
315 return TRUE;
316 }
317
318 int wxNotebook::GetSelection() const
319 {
320 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
321
322 if ( m_selection == -1 )
323 {
324 GList *nb_pages = GTK_NOTEBOOK(m_widget)->children;
325
326 if (g_list_length(nb_pages) != 0)
327 {
328 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
329
330 gpointer cur = notebook->cur_page;
331 if ( cur != NULL )
332 {
333 wxConstCast(this, wxNotebook)->m_selection =
334 g_list_index( nb_pages, cur );
335 }
336 }
337 }
338
339 return m_selection;
340 }
341
342 wxString wxNotebook::GetPageText( size_t page ) const
343 {
344 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid notebook") );
345
346 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
347 if (nb_page)
348 return nb_page->m_text;
349 else
350 return wxT("");
351 }
352
353 int wxNotebook::GetPageImage( size_t page ) const
354 {
355 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
356
357 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
358 if (nb_page)
359 return nb_page->m_image;
360 else
361 return -1;
362 }
363
364 wxGtkNotebookPage* wxNotebook::GetNotebookPage( int page ) const
365 {
366 wxCHECK_MSG( m_widget != NULL, (wxGtkNotebookPage*) NULL, wxT("invalid notebook") );
367
368 wxCHECK_MSG( page < (int)m_pagesData.GetCount(), (wxGtkNotebookPage*) NULL, wxT("invalid notebook index") );
369
370 return m_pagesData.Item(page)->GetData();
371 }
372
373 int wxNotebook::SetSelection( size_t page )
374 {
375 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid notebook") );
376
377 wxCHECK_MSG( page < m_pagesData.GetCount(), -1, wxT("invalid notebook index") );
378
379 int selOld = GetSelection();
380
381 // cache the selection
382 m_selection = page;
383 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page );
384
385 wxNotebookPage *client = GetPage(page);
386 if ( client )
387 client->SetFocus();
388
389 return selOld;
390 }
391
392 bool wxNotebook::SetPageText( size_t page, const wxString &text )
393 {
394 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
395
396 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
397
398 wxCHECK_MSG( nb_page, FALSE, wxT("SetPageText: invalid page index") );
399
400 nb_page->m_text = text;
401
402 gtk_label_set( nb_page->m_label, wxGTK_CONV( nb_page->m_text ) );
403
404 return TRUE;
405 }
406
407 bool wxNotebook::SetPageImage( size_t page, int image )
408 {
409 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
410
411 wxGtkNotebookPage* nb_page = GetNotebookPage(page);
412
413 if (!nb_page) return FALSE;
414
415 /* Optimization posibility: return immediately if image unchanged.
416 * Not enabled because it may break existing (stupid) code that
417 * manipulates the imagelist to cycle images */
418
419 /* if (image == nb_page->m_image) return TRUE; */
420
421 /* For different cases:
422 1) no image -> no image
423 2) image -> no image
424 3) no image -> image
425 4) image -> image */
426
427 if (image == -1 && nb_page->m_image == -1)
428 return TRUE; /* Case 1): Nothing to do. */
429
430 GtkWidget *pixmapwid = (GtkWidget*) NULL;
431
432 if (nb_page->m_image != -1)
433 {
434 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
435
436 GList *child = gtk_container_children(GTK_CONTAINER(nb_page->m_box));
437 while (child)
438 {
439 if (GTK_IS_PIXMAP(child->data))
440 {
441 pixmapwid = GTK_WIDGET(child->data);
442 break;
443 }
444 child = child->next;
445 }
446
447 /* We should have the pixmap widget now */
448 wxASSERT(pixmapwid != NULL);
449
450 if (image == -1)
451 {
452 /* If there's no new widget, just remove the old from the box */
453 gtk_container_remove(GTK_CONTAINER(nb_page->m_box), pixmapwid);
454 nb_page->m_image = -1;
455
456 return TRUE; /* Case 2) */
457 }
458 }
459
460 /* Only cases 3) and 4) left */
461 wxASSERT( m_imageList != NULL ); /* Just in case */
462
463 /* Construct the new pixmap */
464 const wxBitmap *bmp = m_imageList->GetBitmap(image);
465 GdkPixmap *pixmap = bmp->GetPixmap();
466 GdkBitmap *mask = (GdkBitmap*) NULL;
467 if ( bmp->GetMask() )
468 {
469 mask = bmp->GetMask()->GetBitmap();
470 }
471
472 if (pixmapwid == NULL)
473 {
474 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
475 pixmapwid = gtk_pixmap_new (pixmap, mask );
476
477 /* CHECKME: Are these pack flags okay? */
478 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
479 gtk_widget_show(pixmapwid);
480 }
481 else
482 {
483 /* Case 4) Simply replace the pixmap */
484 gtk_pixmap_set(GTK_PIXMAP(pixmapwid), pixmap, mask);
485 }
486
487 nb_page->m_image = image;
488
489 return TRUE;
490 }
491
492 void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
493 {
494 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
495 }
496
497 void wxNotebook::SetPadding( const wxSize &padding )
498 {
499 wxCHECK_RET( m_widget != NULL, wxT("invalid notebook") );
500
501 m_padding = padding.GetWidth();
502
503 int i;
504 for (i=0; i<int(GetPageCount()); i++)
505 {
506 wxGtkNotebookPage* nb_page = GetNotebookPage(i);
507 wxASSERT(nb_page != NULL);
508
509 if (nb_page->m_image != -1)
510 {
511 // gtk_box_set_child_packing sets padding on BOTH sides
512 // icon provides left padding, label provides center and right
513 int image = nb_page->m_image;
514 SetPageImage(i,-1);
515 SetPageImage(i,image);
516 }
517 wxASSERT(nb_page->m_label);
518 gtk_box_set_child_packing(GTK_BOX(nb_page->m_box),
519 GTK_WIDGET(nb_page->m_label),
520 FALSE, FALSE, m_padding, GTK_PACK_END);
521 }
522 }
523
524 void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
525 {
526 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
527 }
528
529 bool wxNotebook::DeleteAllPages()
530 {
531 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
532
533 while (m_pagesData.GetCount() > 0)
534 DeletePage( m_pagesData.GetCount()-1 );
535
536 wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") );
537
538 return wxNotebookBase::DeleteAllPages();
539 }
540
541 bool wxNotebook::DeletePage( size_t page )
542 {
543 if ( m_selection == (int)m_pagesData.GetCount() - 1 )
544 {
545 // the index will become invalid after the page is deleted
546 m_selection = -1;
547 }
548
549 // it will call our DoRemovePage() to do the real work
550 return wxNotebookBase::DeletePage(page);
551 }
552
553 wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
554 {
555 wxNotebookPage *client = wxNotebookBase::DoRemovePage(page);
556 if ( !client )
557 return NULL;
558
559 gtk_widget_ref( client->m_widget );
560 gtk_widget_unrealize( client->m_widget );
561 gtk_widget_unparent( client->m_widget );
562
563 // gtk_notebook_remove_page() sends "switch_page" signal with some strange
564 // new page index (when deleting selected page 0, new page is 1 although,
565 // clearly, the selection should stay 0), so suppress this
566 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
567 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
568
569 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
570
571 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
572 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
573
574 wxGtkNotebookPage* p = GetNotebookPage(page);
575 m_pagesData.DeleteObject(p);
576 delete p;
577
578 return client;
579 }
580
581 bool wxNotebook::InsertPage( size_t position,
582 wxNotebookPage* win,
583 const wxString& text,
584 bool select,
585 int imageId )
586 {
587 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
588
589 wxCHECK_MSG( win->GetParent() == this, FALSE,
590 wxT("Can't add a page whose parent is not the notebook!") );
591
592 wxCHECK_MSG( position <= GetPageCount(), FALSE,
593 _T("invalid page index in wxNotebookPage::InsertPage()") );
594
595 // Hack alert part II! See above in InsertChildInNotebook
596 // callback why this has to be done.
597 win->m_widget->parent = NULL;
598
599 // don't receive switch page during addition
600 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
601 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
602
603 if (m_themeEnabled)
604 win->SetThemeEnabled(TRUE);
605
606 GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
607
608 wxGtkNotebookPage *nb_page = new wxGtkNotebookPage();
609
610 if ( position == GetPageCount() )
611 m_pagesData.Append( nb_page );
612 else
613 m_pagesData.Insert( m_pagesData.Item( position ), nb_page );
614
615 m_pages.Insert(win, position);
616
617 nb_page->m_box = gtk_hbox_new( FALSE, 1 );
618 gtk_container_border_width( GTK_CONTAINER(nb_page->m_box), 2 );
619
620 gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
621 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
622
623 #ifndef __VMS
624 // On VMS position is unsigned and thus always positive
625 if (position < 0)
626 gtk_notebook_append_page( notebook, win->m_widget, nb_page->m_box );
627 else
628 #endif
629 gtk_notebook_insert_page( notebook, win->m_widget, nb_page->m_box, position );
630
631 nb_page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;
632
633 /* set the label image */
634 nb_page->m_image = imageId;
635
636 if (imageId != -1)
637 {
638 wxASSERT( m_imageList != NULL );
639
640 const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
641 GdkPixmap *pixmap = bmp->GetPixmap();
642 GdkBitmap *mask = (GdkBitmap*) NULL;
643 if ( bmp->GetMask() )
644 {
645 mask = bmp->GetMask()->GetBitmap();
646 }
647
648 GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
649
650 gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
651
652 gtk_widget_show(pixmapwid);
653 }
654
655 /* set the label text */
656 nb_page->m_text = text;
657 if (nb_page->m_text.IsEmpty()) nb_page->m_text = wxT("");
658
659 nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
660 gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );
661
662 /* show the label */
663 gtk_widget_show( GTK_WIDGET(nb_page->m_label) );
664 if (select && (m_pagesData.GetCount() > 1))
665 {
666 #ifndef __VMS
667 // On VMS position is unsigned and thus always positive
668 if (position < 0)
669 SetSelection( GetPageCount()-1 );
670 else
671 #endif
672 SetSelection( position );
673 }
674
675 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
676 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
677
678 return TRUE;
679 }
680
681 // helper for HitTest(): check if the point lies inside the given widget which
682 // is the child of the notebook whose position and border size are passed as
683 // parameters
684 static bool
685 IsPointInsideWidget(const wxPoint& pt, GtkWidget *w,
686 gint x, gint y, gint border = 0)
687 {
688 return
689 (pt.x >= w->allocation.x - x - border) &&
690 (pt.x <= w->allocation.x - x + border + w->allocation.width) &&
691 (pt.y >= w->allocation.y - y - border) &&
692 (pt.y <= w->allocation.y - y + border + w->allocation.height);
693 }
694
695 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
696 {
697 const gint x = m_widget->allocation.x;
698 const gint y = m_widget->allocation.y;
699
700 const size_t count = GetPageCount();
701 for ( size_t i = 0; i < count; i++ )
702 {
703 wxGtkNotebookPage* nb_page = GetNotebookPage(i);
704 GtkWidget *box = nb_page->m_box;
705
706 // VZ: don't know how to find the border width in GTK+ 1.2
707 #ifdef __WXGTK20__
708 const gint border = gtk_container_get_border_width(GTK_CONTAINER(box));
709 #else // !GTK+ 2.x
710 const gint border = 0;
711 #endif
712 if ( IsPointInsideWidget(pt, box, x, y, border) )
713 {
714 // ok, we're inside this tab -- now find out where, if needed
715 if ( flags )
716 {
717 GtkWidget *pixmap = NULL;
718
719 GList *children = gtk_container_children(GTK_CONTAINER(box));
720 for ( GList *child = children; child; child = child->next )
721 {
722 if ( GTK_IS_PIXMAP(child->data) )
723 {
724 pixmap = GTK_WIDGET(child->data);
725 break;
726 }
727 }
728
729 if ( children )
730 g_list_free(children);
731
732 if ( pixmap && IsPointInsideWidget(pt, pixmap, x, y) )
733 {
734 *flags = wxNB_HITTEST_ONICON;
735 }
736 else if ( IsPointInsideWidget(pt, GTK_WIDGET(nb_page->m_label), x, y) )
737 {
738 *flags = wxNB_HITTEST_ONLABEL;
739 }
740 else
741 {
742 *flags = wxNB_HITTEST_ONITEM;
743 }
744 }
745
746 return i;
747 }
748 }
749
750 if ( flags )
751 *flags = wxNB_HITTEST_NOWHERE;
752
753 return wxNOT_FOUND;
754 }
755
756 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
757 {
758 if (event.IsWindowChange())
759 AdvanceSelection( event.GetDirection() );
760 else
761 event.Skip();
762 }
763
764 #if wxUSE_CONSTRAINTS
765
766 // override these 2 functions to do nothing: everything is done in OnSize
767 void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
768 {
769 // don't set the sizes of the pages - their correct size is not yet known
770 wxControl::SetConstraintSizes(FALSE);
771 }
772
773 bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
774 {
775 return TRUE;
776 }
777
778 #endif
779
780 void wxNotebook::ApplyWidgetStyle()
781 {
782 // TODO, font for labels etc
783
784 SetWidgetStyle();
785 gtk_widget_set_style( m_widget, m_widgetStyle );
786 }
787
788 bool wxNotebook::IsOwnGtkWindow( GdkWindow *window )
789 {
790 return ((m_widget->window == window) ||
791 (NOTEBOOK_PANEL(m_widget) == window));
792 }
793
794 //-----------------------------------------------------------------------------
795 // wxNotebookEvent
796 //-----------------------------------------------------------------------------
797
798 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
799
800 #endif