X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/587ce561e1deabbfacf0d619fdd6bb3899430720..866592d872daa1f4e3d44948d7d3a6c90b0af9d0:/src/gtk/notebook.cpp diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 3de79f8445..aa910af6ed 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -12,6 +12,9 @@ #endif #include "wx/notebook.h" + +#if wxUSE_NOTEBOOK + #include "wx/panel.h" #include "wx/utils.h" #include "wx/imaglist.h" @@ -124,43 +127,6 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* if (win->GetAutoLayout()) win->Layout(); } -//----------------------------------------------------------------------------- -// "key_press_event" -//----------------------------------------------------------------------------- - -static gint -gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook ) -{ - if (g_isIdle) wxapp_install_idle_handler(); - - if (g_blockEventsOnDrag) return FALSE; - - if (!notebook->m_hasVMT) return FALSE; - - /* this code makes jumping down from the handles of the notebooks - to the actual items in the visible notebook page possible with - the down-arrow key */ - - if (gdk_event->keyval != GDK_Down) return FALSE; - - if (notebook != notebook->FindFocus()) return FALSE; - - if (notebook->m_pages.GetCount() == 0) return FALSE; - - wxNode *node = notebook->m_pages.Nth( notebook->GetSelection() ); - - if (!node) return FALSE; - - wxNotebookPage *page = (wxNotebookPage*) node->Data(); - - // don't let others the key event - gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); - - page->m_client->SetFocus(); - - return TRUE; -} - //----------------------------------------------------------------------------- // InsertChild callback for wxNotebook //----------------------------------------------------------------------------- @@ -184,6 +150,7 @@ void wxNotebook::Init() { m_imageList = (wxImageList *) NULL; m_pages.DeleteContents( TRUE ); + m_lastSelection = -1; } wxNotebook::wxNotebook() @@ -216,7 +183,13 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, m_acceptsFocus = TRUE; m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; - PreCreation( parent, id, pos, size, style, name ); + if (!PreCreation( parent, pos, size ) || + !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) + { + wxFAIL_MSG( _T("wxNoteBook creation failed") ); + return FALSE; + } + m_widget = gtk_notebook_new(); @@ -231,9 +204,6 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, m_parent->DoAddChild( this ); - gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event", - GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this ); - PostCreation(); Show( TRUE ); @@ -241,6 +211,19 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, return TRUE; } +void wxNotebook::SetFocus() +{ + if (m_pages.GetCount() == 0) return; + + wxNode *node = m_pages.Nth( GetSelection() ); + + if (!node) return; + + wxNotebookPage *page = (wxNotebookPage*) node->Data(); + + page->m_client->SetFocus(); +} + int wxNotebook::GetSelection() const { wxCHECK_MSG( m_widget != NULL, -1, _T("invalid notebook") ); @@ -251,11 +234,9 @@ int wxNotebook::GetSelection() const GtkNotebook *notebook = GTK_NOTEBOOK(m_widget); - GtkNotebookPage *page = GTK_NOTEBOOK_PAGE( notebook->cur_page ); + if (notebook->cur_page == NULL) return m_lastSelection; - wxCHECK_MSG( page, -1, "no notebook page selected/current" ); - - return g_list_index( pages, (gpointer)page ); + return g_list_index( pages, (gpointer)(notebook->cur_page) ); } int wxNotebook::GetPageCount() const @@ -276,7 +257,7 @@ wxString wxNotebook::GetPageText( int page ) const if (nb_page) return nb_page->m_text; else - return ""; + return _T(""); } int wxNotebook::GetPageImage( int page ) const @@ -462,9 +443,14 @@ bool wxNotebook::DeletePage( int page ) wxNotebookPage* nb_page = GetNotebookPage(page); if (!nb_page) return FALSE; + /* GTK sets GtkNotebook.cur_page to NULL before sending + the switvh page event */ + m_lastSelection = GetSelection(); + nb_page->m_client->Destroy(); - m_pages.DeleteObject( nb_page ); + + m_lastSelection = -1; return TRUE; } @@ -508,15 +494,15 @@ bool wxNotebook::InsertPage( int position, wxWindow* win, const wxString& text, page->m_box = gtk_hbox_new( FALSE, 0 ); gtk_container_border_width( GTK_CONTAINER(page->m_box), 2 ); + gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); + if (position < 0) gtk_notebook_append_page( notebook, win->m_widget, page->m_box ); else gtk_notebook_insert_page( notebook, win->m_widget, page->m_box, position ); - page->m_page = GTK_NOTEBOOK_PAGE( g_list_last(notebook->children)->data ); - - gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); + page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data; /* set the label image */ page->m_image = imageId; @@ -619,3 +605,4 @@ bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent) +#endif \ No newline at end of file