From 354aa1e366a57d896e2cf0943c687b24e8db688c Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 30 Oct 1999 15:08:33 +0000 Subject: [PATCH] Some work on tabbing and menu accels, Added a missing "Activate()" to docvwmdi sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4271 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/menuitem.h | 3 +- include/wx/gtk1/menuitem.h | 3 +- samples/controls/controls.cpp | 4 +-- samples/dnd/dnd.cpp | 9 +++-- samples/docvwmdi/view.cpp | 1 + samples/docvwmdi/view.h | 56 +++++++++++++++--------------- src/gtk/button.cpp | 29 +++++++++++++--- src/gtk/listbox.cpp | 58 ++++++++++++++++++------------- src/gtk/menu.cpp | 65 ++++++++++++++++++++--------------- src/gtk/radiobox.cpp | 3 +- src/gtk/spinctrl.cpp | 1 + src/gtk/window.cpp | 30 ++++++++++++---- src/gtk1/button.cpp | 29 +++++++++++++--- src/gtk1/listbox.cpp | 58 ++++++++++++++++++------------- src/gtk1/menu.cpp | 65 ++++++++++++++++++++--------------- src/gtk1/radiobox.cpp | 3 +- src/gtk1/spinctrl.cpp | 1 + src/gtk1/window.cpp | 30 ++++++++++++---- 18 files changed, 292 insertions(+), 156 deletions(-) diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index 8152ab4d6a..58b65fc25d 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -30,7 +30,7 @@ public: ~wxMenuItem(); // implement base class virtuals - virtual void SetText( const wxString& str ) { DoSetText(str); } + virtual void SetText( const wxString& str ); virtual void Enable( bool enable = TRUE ); virtual void Check( bool check = TRUE ); virtual bool IsChecked() const; @@ -38,6 +38,7 @@ public: // implementation void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; } + wxString GetFactoryPath() const; wxString GetHotKey() const { return m_hotKey; } diff --git a/include/wx/gtk1/menuitem.h b/include/wx/gtk1/menuitem.h index 8152ab4d6a..58b65fc25d 100644 --- a/include/wx/gtk1/menuitem.h +++ b/include/wx/gtk1/menuitem.h @@ -30,7 +30,7 @@ public: ~wxMenuItem(); // implement base class virtuals - virtual void SetText( const wxString& str ) { DoSetText(str); } + virtual void SetText( const wxString& str ); virtual void Enable( bool enable = TRUE ); virtual void Check( bool check = TRUE ); virtual bool IsChecked() const; @@ -38,6 +38,7 @@ public: // implementation void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; } + wxString GetFactoryPath() const; wxString GetHotKey() const { return m_hotKey; } diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index bdcad24a1c..4b6f62cee1 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -407,10 +407,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) wxPanel *panel = new wxPanel(m_notebook); m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), - 5, choices, wxLB_ALWAYS_SB | wxLB_MULTIPLE ); + 5, choices, wxLB_ALWAYS_SB ); m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED, wxPoint(10,90), wxSize(120,70), - 5, choices, wxLB_SORT | wxLB_EXTENDED ); + 5, choices, wxLB_SORT ); SetControlClientData("listbox", m_listbox); SetControlClientData("listbox", m_listboxSorted); diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 7b1cc72b94..1009775055 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -871,10 +871,13 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) ) { // start drag operation wxTextDataObject textData(m_strText); - wxDropSource source(textData, this, - wxCURSOR_PENCIL, // for copy + wxDropSource source(textData, this +#ifdef __WXMSW__ + ,wxCURSOR_PENCIL, // for copy wxCURSOR_SPRAYCAN, // for move - wxCURSOR_QUESTION_ARROW); // for nothing + wxCURSOR_QUESTION_ARROW // for nothing +#endif + ); const char *pc; diff --git a/samples/docvwmdi/view.cpp b/samples/docvwmdi/view.cpp index 80adc13467..5a41fff149 100644 --- a/samples/docvwmdi/view.cpp +++ b/samples/docvwmdi/view.cpp @@ -57,6 +57,7 @@ bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) frame->SetSize(-1, -1, x, y); #endif frame->Show(TRUE); + Activate(TRUE); return TRUE; } diff --git a/samples/docvwmdi/view.h b/samples/docvwmdi/view.h index 74038ede6e..f446349856 100644 --- a/samples/docvwmdi/view.h +++ b/samples/docvwmdi/view.h @@ -20,19 +20,20 @@ class MyCanvas: public wxScrolledWindow { - public: +public: wxView *view; MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style); virtual void OnDraw(wxDC& dc); void OnMouseEvent(wxMouseEvent& event); -DECLARE_EVENT_TABLE() +private: + DECLARE_EVENT_TABLE() }; class MyTextWindow: public wxTextCtrl { - public: +public: wxView *view; MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style); @@ -40,40 +41,41 @@ class MyTextWindow: public wxTextCtrl class DrawingView: public wxView { - DECLARE_DYNAMIC_CLASS(DrawingView) - private: - public: - wxFrame *frame; - MyCanvas *canvas; +public: + wxFrame *frame; + MyCanvas *canvas; - DrawingView(void) { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; }; - ~DrawingView(void) {}; + DrawingView() { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; } + ~DrawingView() {} - bool OnCreate(wxDocument *doc, long flags); - void OnDraw(wxDC *dc); - void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); - bool OnClose(bool deleteWindow = TRUE); + bool OnCreate(wxDocument *doc, long flags); + void OnDraw(wxDC *dc); + void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); + bool OnClose(bool deleteWindow = TRUE); - void OnCut(wxCommandEvent& event); + void OnCut(wxCommandEvent& event); -DECLARE_EVENT_TABLE() +private: + DECLARE_DYNAMIC_CLASS(DrawingView) + DECLARE_EVENT_TABLE() }; class TextEditView: public wxView { - DECLARE_DYNAMIC_CLASS(TextEditView) - private: - public: - wxFrame *frame; - MyTextWindow *textsw; +public: + wxFrame *frame; + MyTextWindow *textsw; - TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; } - ~TextEditView(void) {} + TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; } + ~TextEditView() {} - bool OnCreate(wxDocument *doc, long flags); - void OnDraw(wxDC *dc); - void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); - bool OnClose(bool deleteWindow = TRUE); + bool OnCreate(wxDocument *doc, long flags); + void OnDraw(wxDC *dc); + void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); + bool OnClose(bool deleteWindow = TRUE); + +private: + DECLARE_DYNAMIC_CLASS(TextEditView) }; #endif diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index cd85a483ae..c12fd52778 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -80,16 +80,37 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, return FALSE; } - - m_widget = gtk_button_new_with_label( "" ); +/* + wxString label2( label ); + for (size_t i = 0; i < label2.Len(); i++) + { + if (label2.GetChar(i) == wxT('&')) + label2.SetChar(i,wxT('_')); + } + GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() ); + gtk_widget_show( accel_label ); + + m_widget = gtk_button_new(); + gtk_container_add( GTK_CONTAINER(m_widget), accel_label ); + + gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget ); + + guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() ); + gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) ); + + wxControl::SetLabel( label ); +*/ + + m_widget = gtk_button_new_with_label(""); + + SetLabel( label ); + #if (GTK_MINOR_VERSION > 0) if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); #endif - SetLabel(label); - int x = 0; int y = 0; wxFont new_font( parent->GetFont() ); GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 9027f25b83..bdf69d7e36 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -26,12 +26,9 @@ #include "wx/tooltip.h" #endif -#if wxUSE_DRAG_AND_DROP -#include "wx/dnd.h" -#endif - #include "gdk/gdk.h" #include "gtk/gtk.h" +#include "gdk/gdkkeysyms.h" //----------------------------------------------------------------------------- // idle system @@ -170,32 +167,52 @@ gtk_listbox_button_press_callback( GtkWidget *widget, // "key_press_event" //----------------------------------------------------------------------------- -#if wxUSE_CHECKLISTBOX static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); - if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnDrag) + return FALSE; - if (!listbox->m_hasVMT) return FALSE; + bool ret = FALSE; - if (gdk_event->keyval != ' ') return FALSE; + if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) + { + wxNavigationKeyEvent new_event; + /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ + new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); + new_event.SetCurrentFocus( listbox ); + ret = listbox->GetEventHandler()->ProcessEvent( new_event ); + } + +#if wxUSE_CHECKLISTBOX + if ((gdk_event->keyval != ' ') && (listbox->m_hasCheckBoxes) && (!ret)) + { + int sel = listbox->GtkGetIndex( widget ); - int sel = listbox->GtkGetIndex( widget ); + wxCheckListBox *clb = (wxCheckListBox *)listbox; - wxCheckListBox *clb = (wxCheckListBox *)listbox; + clb->Check( sel, !clb->IsChecked(sel) ); - clb->Check( sel, !clb->IsChecked(sel) ); + wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); + new_event.SetEventObject( listbox ); + new_event.SetInt( sel ); + ret = listbox->GetEventHandler()->ProcessEvent( new_event ); + } +#endif // wxUSE_CHECKLISTBOX - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); - event.SetEventObject( listbox ); - event.SetInt( sel ); - listbox->GetEventHandler()->ProcessEvent( event ); + if (ret) + { + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); + return TRUE; + } return FALSE; } -#endif // wxUSE_CHECKLISTBOX //----------------------------------------------------------------------------- // "select" and "deselect" @@ -461,15 +478,10 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) (GtkSignalFunc)gtk_listbox_button_release_callback, (gpointer) this ); -#if wxUSE_CHECKLISTBOX - if (m_hasCheckBoxes) - { - gtk_signal_connect( GTK_OBJECT(list_item), + gtk_signal_connect( GTK_OBJECT(list_item), "key_press_event", (GtkSignalFunc)gtk_listbox_key_press_callback, (gpointer)this ); - } -#endif // wxUSE_CHECKLISTBOX gtk_widget_show( list_item ); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 1d042b817d..69b01eda04 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -561,7 +561,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, m_menuItem = (GtkWidget *) NULL; - // call it after initializing m_menuItem to NULL DoSetText(text); } @@ -570,6 +569,23 @@ wxMenuItem::~wxMenuItem() // don't delete menu items, the menus take care of that } +void wxMenuItem::SetText( const wxString& str ) +{ + DoSetText(str); + + if (m_menuItem) + { + GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); + + /* set new text */ + gtk_label_set( label, m_text.mb_str()); + + /* reparse key accel */ + guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() ); + gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) ); + } +} + // it's valid for this function to be called even if m_menuItem == NULL void wxMenuItem::DoSetText( const wxString& str ) { @@ -593,7 +609,7 @@ void wxMenuItem::DoSetText( const wxString& str ) #endif } else - m_text << *pc; + m_text << *pc; } /* only GTK 1.2 knows about hot keys */ @@ -605,12 +621,6 @@ void wxMenuItem::DoSetText( const wxString& str ) m_hotKey = pc; } #endif - - if (m_menuItem) - { - GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); - gtk_label_set( label, m_text.mb_str()); - } } void wxMenuItem::Check( bool check ) @@ -644,6 +654,19 @@ bool wxMenuItem::IsChecked() const return ((GtkCheckMenuItem*)m_menuItem)->active != 0; } +wxString wxMenuItem::GetFactoryPath() const +{ + /* in order to get the pointer to the item we need the item text _without_ underscores */ + wxString path( wxT("
/") ); + for ( const wxChar *pc = m_text; *pc != wxT('\0'); pc++ ) + { + while (*pc == wxT('_')) pc++; /* skip it */ + path << *pc; + } + + return path; +} + //----------------------------------------------------------------------------- // wxMenu //----------------------------------------------------------------------------- @@ -848,20 +871,13 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel)); entry.accelerator = s_accel; #else - entry.accelerator = NULL; + entry.accelerator = (char*) NULL; #endif gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ - /* in order to get the pointer to the item we need the item text _without_ underscores */ - wxString s = wxT("
/"); - for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ ) - { - while (*pc == wxT('_')) pc++; /* skip it */ - s << *pc; - } - - GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() ); + wxString path( mitem->GetFactoryPath() ); + GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() ); #else @@ -911,15 +927,8 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ - /* in order to get the pointer to the item we need the item text _without_ underscores */ - wxString s = wxT("
/"); - for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ ) - { - if (*pc == wxT('_')) pc++; /* skip it */ - s << *pc; - } - - GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, s.mb_str() ); + wxString path( mitem->GetFactoryPath() ); + GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() ); #else @@ -990,6 +999,8 @@ void wxMenu::Delete( int id ) wxMenuItem *item = (wxMenuItem*)node->Data(); if (item->GetId() == id) { + /* TODO: this code doesn't delete the item factory item and + this seems impossible as of GTK 1.2.6. */ gtk_widget_destroy( item->GetMenuItem() ); m_items.DeleteNode( node ); return; diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 2d30dff5e1..9d5d677395 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -20,6 +20,7 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +#include "gdk/gdkkeysyms.h" #include "wx/gtk/win_gtk.h" //----------------------------------------------------------------------------- @@ -117,7 +118,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", - GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), GTK_WIDGET(m_radio), diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 5a46da4048..7f04c11479 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -97,6 +97,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_needParent = TRUE; + m_acceptsFocus = TRUE; wxSize new_size = size; if (new_size.y == -1) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index ccd1269827..1b7eca62e5 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2486,19 +2486,37 @@ void wxWindow::SetFocus() { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); - GtkWidget *connect_widget = GetConnectWidget(); - if (connect_widget) + wxNode *node = m_children.First(); + while (node) { - if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) + wxWindow *child = (wxWindow*) node->Data(); + if (child->AcceptsFocus()) + { + child->SetFocus(); + return; + } + node = node->Next(); + } + + if (m_wxwindow) + { + gtk_widget_grab_focus (m_wxwindow); + return; + } + + if (m_widget) + { + if (GTK_WIDGET_CAN_FOCUS(m_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) { - gtk_widget_grab_focus (connect_widget); + gtk_widget_grab_focus (m_widget); } - else if (GTK_IS_CONTAINER(connect_widget)) + else if (GTK_IS_CONTAINER(m_widget)) { - gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD ); + gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD ); } else { + // ? } } } diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index cd85a483ae..c12fd52778 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -80,16 +80,37 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label, return FALSE; } - - m_widget = gtk_button_new_with_label( "" ); +/* + wxString label2( label ); + for (size_t i = 0; i < label2.Len(); i++) + { + if (label2.GetChar(i) == wxT('&')) + label2.SetChar(i,wxT('_')); + } + GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() ); + gtk_widget_show( accel_label ); + + m_widget = gtk_button_new(); + gtk_container_add( GTK_CONTAINER(m_widget), accel_label ); + + gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget ); + + guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() ); + gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) ); + + wxControl::SetLabel( label ); +*/ + + m_widget = gtk_button_new_with_label(""); + + SetLabel( label ); + #if (GTK_MINOR_VERSION > 0) if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); #endif - SetLabel(label); - int x = 0; int y = 0; wxFont new_font( parent->GetFont() ); GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 9027f25b83..bdf69d7e36 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -26,12 +26,9 @@ #include "wx/tooltip.h" #endif -#if wxUSE_DRAG_AND_DROP -#include "wx/dnd.h" -#endif - #include "gdk/gdk.h" #include "gtk/gtk.h" +#include "gdk/gdkkeysyms.h" //----------------------------------------------------------------------------- // idle system @@ -170,32 +167,52 @@ gtk_listbox_button_press_callback( GtkWidget *widget, // "key_press_event" //----------------------------------------------------------------------------- -#if wxUSE_CHECKLISTBOX static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { - if (g_isIdle) wxapp_install_idle_handler(); + if (g_isIdle) + wxapp_install_idle_handler(); - if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnDrag) + return FALSE; - if (!listbox->m_hasVMT) return FALSE; + bool ret = FALSE; - if (gdk_event->keyval != ' ') return FALSE; + if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) + { + wxNavigationKeyEvent new_event; + /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ + new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); + new_event.SetCurrentFocus( listbox ); + ret = listbox->GetEventHandler()->ProcessEvent( new_event ); + } + +#if wxUSE_CHECKLISTBOX + if ((gdk_event->keyval != ' ') && (listbox->m_hasCheckBoxes) && (!ret)) + { + int sel = listbox->GtkGetIndex( widget ); - int sel = listbox->GtkGetIndex( widget ); + wxCheckListBox *clb = (wxCheckListBox *)listbox; - wxCheckListBox *clb = (wxCheckListBox *)listbox; + clb->Check( sel, !clb->IsChecked(sel) ); - clb->Check( sel, !clb->IsChecked(sel) ); + wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); + new_event.SetEventObject( listbox ); + new_event.SetInt( sel ); + ret = listbox->GetEventHandler()->ProcessEvent( new_event ); + } +#endif // wxUSE_CHECKLISTBOX - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); - event.SetEventObject( listbox ); - event.SetInt( sel ); - listbox->GetEventHandler()->ProcessEvent( event ); + if (ret) + { + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); + return TRUE; + } return FALSE; } -#endif // wxUSE_CHECKLISTBOX //----------------------------------------------------------------------------- // "select" and "deselect" @@ -461,15 +478,10 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) (GtkSignalFunc)gtk_listbox_button_release_callback, (gpointer) this ); -#if wxUSE_CHECKLISTBOX - if (m_hasCheckBoxes) - { - gtk_signal_connect( GTK_OBJECT(list_item), + gtk_signal_connect( GTK_OBJECT(list_item), "key_press_event", (GtkSignalFunc)gtk_listbox_key_press_callback, (gpointer)this ); - } -#endif // wxUSE_CHECKLISTBOX gtk_widget_show( list_item ); diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 1d042b817d..69b01eda04 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -561,7 +561,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, m_menuItem = (GtkWidget *) NULL; - // call it after initializing m_menuItem to NULL DoSetText(text); } @@ -570,6 +569,23 @@ wxMenuItem::~wxMenuItem() // don't delete menu items, the menus take care of that } +void wxMenuItem::SetText( const wxString& str ) +{ + DoSetText(str); + + if (m_menuItem) + { + GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); + + /* set new text */ + gtk_label_set( label, m_text.mb_str()); + + /* reparse key accel */ + guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() ); + gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) ); + } +} + // it's valid for this function to be called even if m_menuItem == NULL void wxMenuItem::DoSetText( const wxString& str ) { @@ -593,7 +609,7 @@ void wxMenuItem::DoSetText( const wxString& str ) #endif } else - m_text << *pc; + m_text << *pc; } /* only GTK 1.2 knows about hot keys */ @@ -605,12 +621,6 @@ void wxMenuItem::DoSetText( const wxString& str ) m_hotKey = pc; } #endif - - if (m_menuItem) - { - GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); - gtk_label_set( label, m_text.mb_str()); - } } void wxMenuItem::Check( bool check ) @@ -644,6 +654,19 @@ bool wxMenuItem::IsChecked() const return ((GtkCheckMenuItem*)m_menuItem)->active != 0; } +wxString wxMenuItem::GetFactoryPath() const +{ + /* in order to get the pointer to the item we need the item text _without_ underscores */ + wxString path( wxT("
/") ); + for ( const wxChar *pc = m_text; *pc != wxT('\0'); pc++ ) + { + while (*pc == wxT('_')) pc++; /* skip it */ + path << *pc; + } + + return path; +} + //----------------------------------------------------------------------------- // wxMenu //----------------------------------------------------------------------------- @@ -848,20 +871,13 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel)); entry.accelerator = s_accel; #else - entry.accelerator = NULL; + entry.accelerator = (char*) NULL; #endif gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ - /* in order to get the pointer to the item we need the item text _without_ underscores */ - wxString s = wxT("
/"); - for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ ) - { - while (*pc == wxT('_')) pc++; /* skip it */ - s << *pc; - } - - GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() ); + wxString path( mitem->GetFactoryPath() ); + GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() ); #else @@ -911,15 +927,8 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ - /* in order to get the pointer to the item we need the item text _without_ underscores */ - wxString s = wxT("
/"); - for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ ) - { - if (*pc == wxT('_')) pc++; /* skip it */ - s << *pc; - } - - GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, s.mb_str() ); + wxString path( mitem->GetFactoryPath() ); + GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() ); #else @@ -990,6 +999,8 @@ void wxMenu::Delete( int id ) wxMenuItem *item = (wxMenuItem*)node->Data(); if (item->GetId() == id) { + /* TODO: this code doesn't delete the item factory item and + this seems impossible as of GTK 1.2.6. */ gtk_widget_destroy( item->GetMenuItem() ); m_items.DeleteNode( node ); return; diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 2d30dff5e1..9d5d677395 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -20,6 +20,7 @@ #include "gdk/gdk.h" #include "gtk/gtk.h" +#include "gdk/gdkkeysyms.h" #include "wx/gtk/win_gtk.h" //----------------------------------------------------------------------------- @@ -117,7 +118,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", - GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), GTK_WIDGET(m_radio), diff --git a/src/gtk1/spinctrl.cpp b/src/gtk1/spinctrl.cpp index 5a46da4048..7f04c11479 100644 --- a/src/gtk1/spinctrl.cpp +++ b/src/gtk1/spinctrl.cpp @@ -97,6 +97,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_needParent = TRUE; + m_acceptsFocus = TRUE; wxSize new_size = size; if (new_size.y == -1) diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index ccd1269827..1b7eca62e5 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2486,19 +2486,37 @@ void wxWindow::SetFocus() { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); - GtkWidget *connect_widget = GetConnectWidget(); - if (connect_widget) + wxNode *node = m_children.First(); + while (node) { - if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) + wxWindow *child = (wxWindow*) node->Data(); + if (child->AcceptsFocus()) + { + child->SetFocus(); + return; + } + node = node->Next(); + } + + if (m_wxwindow) + { + gtk_widget_grab_focus (m_wxwindow); + return; + } + + if (m_widget) + { + if (GTK_WIDGET_CAN_FOCUS(m_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) { - gtk_widget_grab_focus (connect_widget); + gtk_widget_grab_focus (m_widget); } - else if (GTK_IS_CONTAINER(connect_widget)) + else if (GTK_IS_CONTAINER(m_widget)) { - gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD ); + gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD ); } else { + // ? } } }