1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/notebook.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/notebook.h"
22 #include "wx/msgdlg.h"
23 #include "wx/bitmap.h"
26 #include "wx/imaglist.h"
27 #include "wx/fontutil.h"
29 #include "wx/gtk1/private.h"
30 #include "wx/gtk1/win_gtk.h"
32 #include <gdk/gdkkeysyms.h>
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
)
39 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
)
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 extern void wxapp_install_idle_handler();
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 extern bool g_blockEventsOnDrag
;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 // VZ: this is rather ugly as we keep the pages themselves in an array (it
59 // allows us to have quite a few functions implemented in the base class)
60 // but the page data is kept in a separate list, so we must maintain them
61 // in sync manually... of course, the list had been there before the base
62 // class which explains it but it still would be nice to do something
65 class wxGtkNotebookPage
: public wxObject
71 m_page
= (GtkNotebookPage
*) NULL
;
72 m_box
= (GtkWidget
*) NULL
;
77 GtkNotebookPage
*m_page
;
79 GtkWidget
*m_box
; // in which the label and image are packed
83 #include "wx/listimpl.cpp"
84 WX_DEFINE_LIST(wxGtkNotebookPagesList
)
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
92 static void gtk_notebook_page_change_callback(GtkNotebook
*WXUNUSED(widget
),
93 GtkNotebookPage
*WXUNUSED(page
),
95 wxNotebook
*notebook
)
97 // are you trying to call SetSelection() from a notebook event handler?
99 wxCHECK_RET( !notebook
->m_inSwitchPage
,
100 _T("gtk_notebook_page_change_callback reentered") );
102 notebook
->m_inSwitchPage
= true;
104 wxapp_install_idle_handler();
106 int old
= notebook
->GetSelection();
108 if (notebook
->m_skipNextPageChangeEvent
)
110 // this event was programatically generated by ChangeSelection() and thus must
112 notebook
->m_skipNextPageChangeEvent
= false;
114 // make wxNotebook::GetSelection() return the correct (i.e. consistent
115 // with wxNotebookEvent::GetSelection()) value even though the page is
116 // not really changed in GTK+
117 notebook
->m_selection
= page
;
121 wxNotebookEvent
eventChanging( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
122 notebook
->GetId(), page
, old
);
123 eventChanging
.SetEventObject( notebook
);
125 if ( (notebook
->GetEventHandler()->ProcessEvent(eventChanging
)) &&
126 !eventChanging
.IsAllowed() )
128 /* program doesn't allow the page change */
129 g_signal_stop_emission_by_name (notebook
->m_widget
,
132 else // change allowed
134 // make wxNotebook::GetSelection() return the correct (i.e. consistent
135 // with wxNotebookEvent::GetSelection()) value even though the page is
136 // not really changed in GTK+
137 notebook
->m_selection
= page
;
139 wxNotebookEvent
eventChanged( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
140 notebook
->GetId(), page
, old
);
141 eventChanged
.SetEventObject( notebook
);
142 notebook
->GetEventHandler()->ProcessEvent( eventChanged
);
146 notebook
->m_inSwitchPage
= FALSE
;
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
155 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
158 wxapp_install_idle_handler();
160 if ((win
->m_x
== alloc
->x
) &&
161 (win
->m_y
== alloc
->y
) &&
162 (win
->m_width
== alloc
->width
) &&
163 (win
->m_height
== alloc
->height
))
168 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
170 /* GTK 1.2 up to version 1.2.5 is broken so that we have to call allocate
171 here in order to make repositioning after resizing to take effect. */
172 if ((gtk_major_version
== 1) &&
173 (gtk_minor_version
== 2) &&
174 (gtk_micro_version
< 6) &&
176 (GTK_WIDGET_REALIZED(win
->m_wxwindow
)))
178 gtk_widget_size_allocate( win
->m_wxwindow
, alloc
);
183 //-----------------------------------------------------------------------------
184 // "realize" from m_widget
185 //-----------------------------------------------------------------------------
189 gtk_notebook_realized_callback( GtkWidget
* WXUNUSED(widget
), wxWindow
*win
)
192 wxapp_install_idle_handler();
194 /* GTK 1.2 up to version 1.2.5 is broken so that we have to call a queue_resize
195 here in order to make repositioning before showing to take effect. */
196 gtk_widget_queue_resize( win
->m_widget
);
202 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
207 static gint
gtk_notebook_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxNotebook
*notebook
)
210 wxapp_install_idle_handler();
212 if (!notebook
->m_hasVMT
) return FALSE
;
213 if (g_blockEventsOnDrag
) return FALSE
;
215 /* win is a control: tab can be propagated up */
216 if ((gdk_event
->keyval
== GDK_Left
) || (gdk_event
->keyval
== GDK_Right
))
219 int nMax
= notebook
->GetPageCount();
220 if ( nMax
-- ) // decrement it to get the last valid index
222 int nSel
= notebook
->GetSelection();
224 // change selection wrapping if it becomes invalid
225 page
= (gdk_event
->keyval
!= GDK_Left
) ? nSel
== nMax ?
0
230 else // notebook is empty, no next page
235 // m_selection = page;
236 gtk_notebook_set_page( GTK_NOTEBOOK(widget
), page
);
238 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
242 /* win is a control: tab can be propagated up */
243 if ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
))
245 int sel
= notebook
->GetSelection();
248 wxGtkNotebookPage
*nb_page
= notebook
->GetNotebookPage(sel
);
249 wxCHECK_MSG( nb_page
, FALSE
, _T("invalid selection in wxNotebook") );
251 wxNavigationKeyEvent event
;
252 event
.SetEventObject( notebook
);
253 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
254 event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
255 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
256 event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) ||
257 (gdk_event
->keyval
== GDK_Left
) || (gdk_event
->keyval
== GDK_Right
) );
258 event
.SetCurrentFocus( notebook
);
260 wxNotebookPage
*client
= notebook
->GetPage(sel
);
261 if ( !client
->GetEventHandler()->ProcessEvent( event
) )
266 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
274 //-----------------------------------------------------------------------------
275 // InsertChild callback for wxNotebook
276 //-----------------------------------------------------------------------------
278 static void wxInsertChildInNotebook( wxNotebook
* parent
, wxWindow
* child
)
280 // Hack Alert! (Part I): This sets the notebook as the parent of the child
281 // widget, and takes care of some details such as updating the state and
282 // style of the child to reflect its new location. We do this early
283 // because without it GetBestSize (which is used to set the initial size
284 // of controls if an explicit size is not given) will often report
285 // incorrect sizes since the widget's style context is not fully known.
286 // See bug #901694 for details
287 // (http://sourceforge.net/tracker/?func=detail&aid=901694&group_id=9863&atid=109863)
288 gtk_widget_set_parent(child
->m_widget
, parent
->m_widget
);
290 // NOTE: This should be considered a temporary workaround until we can
291 // work out the details and implement delaying the setting of the initial
292 // size of widgets until the size is really needed.
295 //-----------------------------------------------------------------------------
297 //-----------------------------------------------------------------------------
299 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
,wxControl
)
301 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
302 EVT_NAVIGATION_KEY(wxNotebook
::OnNavigationKey
)
305 void wxNotebook
::Init()
308 m_inSwitchPage
= false;
310 m_imageList
= (wxImageList
*) NULL
;
312 m_themeEnabled
= true;
315 wxNotebook
::wxNotebook()
320 wxNotebook
::wxNotebook( wxWindow
*parent
, wxWindowID id
,
321 const wxPoint
& pos
, const wxSize
& size
,
322 long style
, const wxString
& name
)
325 Create( parent
, id
, pos
, size
, style
, name
);
328 wxNotebook
::~wxNotebook()
333 bool wxNotebook
::Create(wxWindow
*parent
, wxWindowID id
,
334 const wxPoint
& pos
, const wxSize
& size
,
335 long style
, const wxString
& name
)
338 m_acceptsFocus
= true;
339 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInNotebook
;
341 if ( (style
& wxBK_ALIGN_MASK
) == wxBK_DEFAULT
)
344 if (!PreCreation( parent
, pos
, size
) ||
345 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
347 wxFAIL_MSG( wxT("wxNoteBook creation failed") );
352 m_widget
= gtk_notebook_new();
354 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
356 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
357 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback
), (gpointer
)this );
359 m_parent
->DoAddChild( this );
361 if (m_windowStyle
& wxBK_RIGHT
)
362 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget
), GTK_POS_RIGHT
);
363 if (m_windowStyle
& wxBK_LEFT
)
364 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget
), GTK_POS_LEFT
);
365 if (m_windowStyle
& wxBK_BOTTOM
)
366 gtk_notebook_set_tab_pos( GTK_NOTEBOOK(m_widget
), GTK_POS_BOTTOM
);
368 gtk_signal_connect( GTK_OBJECT(m_widget
), "key_press_event",
369 GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback
), (gpointer
)this );
373 gtk_signal_connect( GTK_OBJECT(m_widget
), "realize",
374 GTK_SIGNAL_FUNC(gtk_notebook_realized_callback
), (gpointer
) this );
379 int wxNotebook
::GetSelection() const
381 wxCHECK_MSG( m_widget
!= NULL
, -1, wxT("invalid notebook") );
383 if ( m_selection
== -1 )
385 GList
*nb_pages
= GTK_NOTEBOOK(m_widget
)->children
;
387 if (g_list_length(nb_pages
) != 0)
389 GtkNotebook
*notebook
= GTK_NOTEBOOK(m_widget
);
391 gpointer cur
= notebook
->cur_page
;
394 wxConstCast(this, wxNotebook
)->m_selection
=
395 g_list_index( nb_pages
, cur
);
403 wxString wxNotebook
::GetPageText( size_t page
) const
405 wxCHECK_MSG( m_widget
!= NULL
, wxEmptyString
, wxT("invalid notebook") );
407 wxGtkNotebookPage
* nb_page
= GetNotebookPage(page
);
409 return nb_page
->m_text
;
411 return wxEmptyString
;
414 int wxNotebook
::GetPageImage( size_t page
) const
416 wxCHECK_MSG( m_widget
!= NULL
, -1, wxT("invalid notebook") );
418 wxGtkNotebookPage
* nb_page
= GetNotebookPage(page
);
420 return nb_page
->m_image
;
425 wxGtkNotebookPage
* wxNotebook
::GetNotebookPage( int page
) const
427 wxCHECK_MSG( m_widget
!= NULL
, (wxGtkNotebookPage
*) NULL
, wxT("invalid notebook") );
429 wxCHECK_MSG( page
< (int)m_pagesData
.GetCount(), (wxGtkNotebookPage
*) NULL
, wxT("invalid notebook index") );
431 return m_pagesData
.Item(page
)->GetData();
434 int wxNotebook
::DoSetSelection( size_t page
, int flags
)
436 wxCHECK_MSG( m_widget
!= NULL
, -1, wxT("invalid notebook") );
438 wxCHECK_MSG( page
< m_pagesData
.GetCount(), -1, wxT("invalid notebook index") );
440 int selOld
= GetSelection();
442 if ( !(flags
& SetSelection_SendEvent
) )
443 m_skipNextPageChangeEvent
= true;
445 // cache the selection
447 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page
);
450 if ( !(flags
& SetSelection_SendEvent
) )
452 // gtk_notebook_set_current_page will emit the switch-page signal which will be
453 // caught by our gtk_notebook_page_change_callback which should have reset the
455 wxASSERT(!m_skipNextPageChangeEvent
);
457 #endif // __WXDEBUG__
459 wxNotebookPage
*client
= GetPage(page
);
466 bool wxNotebook
::SetPageText( size_t page
, const wxString
&text
)
468 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid notebook") );
470 wxGtkNotebookPage
* nb_page
= GetNotebookPage(page
);
472 wxCHECK_MSG( nb_page
, FALSE
, wxT("SetPageText: invalid page index") );
474 nb_page
->m_text
= text
;
476 gtk_label_set( nb_page
->m_label
, wxGTK_CONV( nb_page
->m_text
) );
481 bool wxNotebook
::SetPageImage( size_t page
, int image
)
483 /* HvdH 28-12-98: now it works, but it's a bit of a kludge */
485 wxGtkNotebookPage
* nb_page
= GetNotebookPage(page
);
487 if (!nb_page
) return FALSE
;
489 /* Optimization posibility: return immediately if image unchanged.
490 * Not enabled because it may break existing (stupid) code that
491 * manipulates the imagelist to cycle images */
493 /* if (image == nb_page->m_image) return true; */
495 /* For different cases:
496 1) no image -> no image
501 if (image
== -1 && nb_page
->m_image
== -1)
502 return true; /* Case 1): Nothing to do. */
504 GtkWidget
*pixmapwid
= (GtkWidget
*) NULL
;
506 if (nb_page
->m_image
!= -1)
508 /* Case 2) or 4). There is already an image in the gtkhbox. Let's find it */
510 GList
*child
= gtk_container_children(GTK_CONTAINER(nb_page
->m_box
));
513 if (GTK_IS_PIXMAP(child
->data
))
515 pixmapwid
= GTK_WIDGET(child
->data
);
521 /* We should have the pixmap widget now */
522 wxASSERT(pixmapwid
!= NULL
);
526 /* If there's no new widget, just remove the old from the box */
527 gtk_container_remove(GTK_CONTAINER(nb_page
->m_box
), pixmapwid
);
528 nb_page
->m_image
= -1;
530 return true; /* Case 2) */
534 /* Only cases 3) and 4) left */
535 wxASSERT( m_imageList
!= NULL
); /* Just in case */
537 /* Construct the new pixmap */
538 const wxBitmap
*bmp
= m_imageList
->GetBitmapPtr(image
);
539 GdkPixmap
*pixmap
= bmp
->GetPixmap();
540 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
541 if ( bmp
->GetMask() )
543 mask
= bmp
->GetMask()->GetBitmap();
546 if (pixmapwid
== NULL
)
548 /* Case 3) No old pixmap. Create a new one and prepend it to the hbox */
549 pixmapwid
= gtk_pixmap_new (pixmap
, mask
);
551 /* CHECKME: Are these pack flags okay? */
552 gtk_box_pack_start(GTK_BOX(nb_page
->m_box
), pixmapwid
, FALSE
, FALSE
, m_padding
);
553 gtk_widget_show(pixmapwid
);
557 /* Case 4) Simply replace the pixmap */
558 gtk_pixmap_set(GTK_PIXMAP(pixmapwid
), pixmap
, mask
);
561 nb_page
->m_image
= image
;
566 void wxNotebook
::SetPageSize( const wxSize
&WXUNUSED(size
) )
568 wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
571 void wxNotebook
::SetPadding( const wxSize
&padding
)
573 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid notebook") );
575 m_padding
= padding
.GetWidth();
578 for (i
=0; i
<int(GetPageCount()); i
++)
580 wxGtkNotebookPage
* nb_page
= GetNotebookPage(i
);
581 wxASSERT(nb_page
!= NULL
);
583 if (nb_page
->m_image
!= -1)
585 // gtk_box_set_child_packing sets padding on BOTH sides
586 // icon provides left padding, label provides center and right
587 int image
= nb_page
->m_image
;
589 SetPageImage(i
,image
);
591 wxASSERT(nb_page
->m_label
);
592 gtk_box_set_child_packing(GTK_BOX(nb_page
->m_box
),
593 GTK_WIDGET(nb_page
->m_label
),
594 FALSE
, FALSE
, m_padding
, GTK_PACK_END
);
598 void wxNotebook
::SetTabSize(const wxSize
& WXUNUSED(sz
))
600 wxFAIL_MSG( wxT("wxNotebook::SetTabSize not implemented") );
603 bool wxNotebook
::DeleteAllPages()
605 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid notebook") );
607 while (m_pagesData
.GetCount() > 0)
608 DeletePage( m_pagesData
.GetCount()-1 );
610 wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") );
612 InvalidateBestSize();
613 return wxNotebookBase
::DeleteAllPages();
616 wxNotebookPage
*wxNotebook
::DoRemovePage( size_t page
)
618 if ( m_selection
!= -1 && (size_t)m_selection
>= page
)
620 // the index will become invalid after the page is deleted
624 wxNotebookPage
*client
= wxNotebookBase
::DoRemovePage(page
);
628 gtk_widget_ref( client
->m_widget
);
629 gtk_widget_unrealize( client
->m_widget
);
630 gtk_widget_unparent( client
->m_widget
);
632 // gtk_notebook_remove_page() sends "switch_page" signal with some strange
633 // new page index (when deleting selected page 0, new page is 1 although,
634 // clearly, the selection should stay 0), so suppress this
635 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
636 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback
), (gpointer
) this );
638 gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget
), page
);
640 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
641 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback
), (gpointer
)this );
643 wxGtkNotebookPage
* p
= GetNotebookPage(page
);
644 m_pagesData
.DeleteObject(p
);
650 bool wxNotebook
::InsertPage( size_t position
,
652 const wxString
& text
,
656 wxCHECK_MSG( m_widget
!= NULL
, FALSE
, wxT("invalid notebook") );
658 wxCHECK_MSG( win
->GetParent() == this, FALSE
,
659 wxT("Can't add a page whose parent is not the notebook!") );
661 wxCHECK_MSG( position
<= GetPageCount(), FALSE
,
662 _T("invalid page index in wxNotebookPage::InsertPage()") );
664 // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
665 // why this has to be done. NOTE: using gtk_widget_unparent here does not
666 // work as it seems to undo too much and will cause errors in the
667 // gtk_notebook_insert_page below, so instead just clear the parent by
669 win
->m_widget
->parent
= NULL
;
671 // don't receive switch page during addition
672 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
673 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback
), (gpointer
) this );
676 win
->SetThemeEnabled(true);
678 GtkNotebook
*notebook
= GTK_NOTEBOOK(m_widget
);
680 wxGtkNotebookPage
*nb_page
= new wxGtkNotebookPage();
682 if ( position
== GetPageCount() )
683 m_pagesData
.Append( nb_page
);
685 m_pagesData
.Insert( position
, nb_page
);
687 m_pages
.Insert(win
, position
);
689 nb_page
->m_box
= gtk_hbox_new( FALSE
, 1 );
690 gtk_container_border_width( GTK_CONTAINER(nb_page
->m_box
), 2 );
692 gtk_signal_connect( GTK_OBJECT(win
->m_widget
), "size_allocate",
693 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)win
);
695 gtk_notebook_insert_page( notebook
, win
->m_widget
, nb_page
->m_box
, position
);
697 nb_page
->m_page
= (GtkNotebookPage
*) g_list_last(notebook
->children
)->data
;
699 /* set the label image */
700 nb_page
->m_image
= imageId
;
704 wxASSERT( m_imageList
!= NULL
);
706 const wxBitmap
*bmp
= m_imageList
->GetBitmapPtr(imageId
);
707 GdkPixmap
*pixmap
= bmp
->GetPixmap();
708 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
709 if ( bmp
->GetMask() )
711 mask
= bmp
->GetMask()->GetBitmap();
714 GtkWidget
*pixmapwid
= gtk_pixmap_new (pixmap
, mask
);
716 gtk_box_pack_start(GTK_BOX(nb_page
->m_box
), pixmapwid
, FALSE
, FALSE
, m_padding
);
718 gtk_widget_show(pixmapwid
);
721 /* set the label text */
723 nb_page
->m_text
= text
;
724 if (nb_page
->m_text
.empty()) nb_page
->m_text
= wxEmptyString
;
726 nb_page
->m_label
= GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page
->m_text
)) );
727 gtk_box_pack_end( GTK_BOX(nb_page
->m_box
), GTK_WIDGET(nb_page
->m_label
), FALSE
, FALSE
, m_padding
);
729 /* apply current style */
730 GtkRcStyle
*style
= CreateWidgetStyle();
733 gtk_widget_modify_style(GTK_WIDGET(nb_page
->m_label
), style
);
734 gtk_rc_style_unref(style
);
738 gtk_widget_show( GTK_WIDGET(nb_page
->m_label
) );
739 if (select
&& (m_pagesData
.GetCount() > 1))
741 SetSelection( position
);
744 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
745 GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback
), (gpointer
)this );
747 InvalidateBestSize();
751 // helper for HitTest(): check if the point lies inside the given widget which
752 // is the child of the notebook whose position and border size are passed as
755 IsPointInsideWidget(const wxPoint
& pt
, GtkWidget
*w
,
756 gint x
, gint y
, gint border
= 0)
759 (pt
.x
>= w
->allocation
.x
- x
- border
) &&
760 (pt
.x
<= w
->allocation
.x
- x
+ border
+ w
->allocation
.width
) &&
761 (pt
.y
>= w
->allocation
.y
- y
- border
) &&
762 (pt
.y
<= w
->allocation
.y
- y
+ border
+ w
->allocation
.height
);
765 int wxNotebook
::HitTest(const wxPoint
& pt
, long *flags
) const
767 const gint x
= m_widget
->allocation
.x
;
768 const gint y
= m_widget
->allocation
.y
;
770 const size_t count
= GetPageCount();
773 // MR: Code to fix HitTest index return when tabs are scrolled.
774 // No idea if it would work for GTK1
776 GtkNotebook
* notebook
= GTK_NOTEBOOK(m_widget
);
777 if (gtk_notebook_get_scrollable(notebook
));
778 i
= g_list_position( notebook
->children
, notebook
->first_tab
);
781 for ( ; i
< count
; i
++ )
783 wxGtkNotebookPage
* nb_page
= GetNotebookPage(i
);
784 GtkWidget
*box
= nb_page
->m_box
;
786 // VZ: don't know how to find the border width in GTK+ 1.2
787 const gint border
= 0;
788 if ( IsPointInsideWidget(pt
, box
, x
, y
, border
) )
790 // ok, we're inside this tab -- now find out where, if needed
793 GtkWidget
*pixmap
= NULL
;
795 GList
*children
= gtk_container_children(GTK_CONTAINER(box
));
796 for ( GList
*child
= children
; child
; child
= child
->next
)
798 if ( GTK_IS_PIXMAP(child
->data
) )
800 pixmap
= GTK_WIDGET(child
->data
);
806 g_list_free(children
);
808 if ( pixmap
&& IsPointInsideWidget(pt
, pixmap
, x
, y
) )
810 *flags
= wxBK_HITTEST_ONICON
;
812 else if ( IsPointInsideWidget(pt
, GTK_WIDGET(nb_page
->m_label
), x
, y
) )
814 *flags
= wxBK_HITTEST_ONLABEL
;
818 *flags
= wxBK_HITTEST_ONITEM
;
827 *flags
= wxBK_HITTEST_NOWHERE
;
832 void wxNotebook
::OnNavigationKey(wxNavigationKeyEvent
& event
)
834 if (event
.IsWindowChange())
835 AdvanceSelection( event
.GetDirection() );
840 #if wxUSE_CONSTRAINTS
842 // override these 2 functions to do nothing: everything is done in OnSize
843 void wxNotebook
::SetConstraintSizes( bool WXUNUSED(recurse
) )
845 // don't set the sizes of the pages - their correct size is not yet known
846 wxControl
::SetConstraintSizes(FALSE
);
849 bool wxNotebook
::DoPhase( int WXUNUSED(nPhase
) )
856 void wxNotebook
::DoApplyWidgetStyle(GtkRcStyle
*style
)
858 gtk_widget_modify_style(m_widget
, style
);
859 size_t cnt
= m_pagesData
.GetCount();
860 for (size_t i
= 0; i
< cnt
; i
++)
861 gtk_widget_modify_style(GTK_WIDGET(GetNotebookPage(i
)->m_label
), style
);
864 bool wxNotebook
::IsOwnGtkWindow( GdkWindow
*window
)
866 return ((m_widget
->window
== window
) ||
867 (NOTEBOOK_PANEL(m_widget
) == window
));
872 wxNotebook
::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
874 return GetDefaultAttributesFromGTKWidget(gtk_notebook_new
);
877 //-----------------------------------------------------------------------------
879 //-----------------------------------------------------------------------------
881 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)