From: Robert Roebling Date: Sun, 25 Apr 1999 15:10:52 +0000 (+0000) Subject: Backgrounds work again X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1e133b7d6438b9144b8f68cf6b514d03eaaf698b?ds=inline Backgrounds work again splitter sample compiles with Unicode if a wxClientDC is used on an unrealized widget, the widget's realization is forced in wxClientDC added underscores to wxMenuBar - don't work.. tried to figure out why wxFrame doesn't get keyboard input git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2281 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index fdf148ba75..e747a14d87 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -48,6 +48,7 @@ public: wxMenuBar(); wxMenuBar(long style); wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + ~wxMenuBar(); // menubar construction void Append( wxMenu *menu, const wxString &title ); @@ -88,12 +89,15 @@ public: wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); } #endif // WXWIN_COMPATIBILITY - // implementation + // implementation only wxList& GetMenus() { return m_menus; } -protected: - wxList m_menus; - GtkWidget *m_menubar; + GtkAccelGroup *m_accel; + GtkItemFactory *m_factory; + +private: + wxList m_menus; + GtkWidget *m_menubar; }; //----------------------------------------------------------------------------- @@ -170,14 +174,14 @@ public: void SetInvokingWindow( wxWindow *win ); wxWindow *GetInvokingWindow(); - // implementation only + // implementation GTK only GtkWidget *m_menu; // GtkMenu GtkWidget *m_owner; - GtkAccelGroup *m_accel; GtkItemFactory *m_factory; private: + wxString m_title; wxList m_items; wxWindow *m_invokingWindow; diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index fdf148ba75..e747a14d87 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -48,6 +48,7 @@ public: wxMenuBar(); wxMenuBar(long style); wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + ~wxMenuBar(); // menubar construction void Append( wxMenu *menu, const wxString &title ); @@ -88,12 +89,15 @@ public: wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); } #endif // WXWIN_COMPATIBILITY - // implementation + // implementation only wxList& GetMenus() { return m_menus; } -protected: - wxList m_menus; - GtkWidget *m_menubar; + GtkAccelGroup *m_accel; + GtkItemFactory *m_factory; + +private: + wxList m_menus; + GtkWidget *m_menubar; }; //----------------------------------------------------------------------------- @@ -170,14 +174,14 @@ public: void SetInvokingWindow( wxWindow *win ); wxWindow *GetInvokingWindow(); - // implementation only + // implementation GTK only GtkWidget *m_menu; // GtkMenu GtkWidget *m_owner; - GtkAccelGroup *m_accel; GtkItemFactory *m_factory; private: + wxString m_title; wxList m_items; wxWindow *m_invokingWindow; diff --git a/samples/splitter/test.cpp b/samples/splitter/test.cpp index 928ab32142..d01cb9f0fd 100644 --- a/samples/splitter/test.cpp +++ b/samples/splitter/test.cpp @@ -46,7 +46,7 @@ public: return FALSE; wxString str; - str.Printf("Sash position = %d", newSashPosition); + str.Printf( _T("Sash position = %d"), newSashPosition); m_frame->SetStatusText(str); return TRUE; @@ -219,15 +219,19 @@ void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) ) void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) ) { wxString str; - str.Printf("%d", m_splitter->GetMinimumPaneSize()); + str.Printf( _T("%d"), m_splitter->GetMinimumPaneSize()); str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this); if ( str.IsEmpty() ) return; +/* + What is atoi in Unicode? + int minsize = atoi(str); m_splitter->SetMinimumPaneSize(minsize); - str.Printf("Min pane size = %d", minsize); + str.Printf( _T("Min pane size = %d"), minsize); SetStatusText(str, 1); +*/ } void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event) @@ -248,7 +252,7 @@ void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event) void MyFrame::UpdatePosition() { wxString str; - str.Printf("Sash position = %d", m_splitter->GetSashPosition()); + str.Printf( _("Sash position = %d"), m_splitter->GetSashPosition()); SetStatusText(str); } diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index ffd5d9ef15..918e0a52db 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -109,10 +109,23 @@ wxWindowDC::wxWindowDC( wxWindow *window ) m_owner = (wxWindow *)NULL; if (!window) return; + GtkWidget *widget = window->m_wxwindow; if (!widget) return; + m_window = widget->window; + + /* not realized ? */ + if (!m_window) + { + /* force realization */ + gtk_widget_realize( widget ); + m_window = widget->window; + } + + /* still not realized ? */ if (!m_window) return; + if (window->m_wxwindow) m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); else diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index bf4f14a3c2..5d169310b8 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -249,13 +249,6 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child ) /* resize on OnInternalIdle */ parent->m_sizeSet = FALSE; - - if (parent->m_windowStyle & wxTAB_TRAVERSAL) - { - /* we now allow a window to get the focus as long as it - doesn't have any children. */ - GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS ); - } } //----------------------------------------------------------------------------- @@ -335,8 +328,14 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, /* m_wxwindow only represents the client area without toolbar and menubar */ m_wxwindow = gtk_myfixed_new(); gtk_widget_show( m_wxwindow ); - GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); + + /* we allow the frame to get the focus as otherwise no + keye vents will get sent to it. the point with this is + that the menu's key accelerators work by interceting + key events here */ + GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); + GTK_WIDGET_SET_FLAGS (m_wxwindow, GTK_HAS_FOCUS); if (m_parent) m_parent->AddChild( this ); @@ -763,6 +762,11 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar) { + /* support for native key accelerators indicated by underscroes */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + gtk_accel_group_attach( m_frameMenuBar->m_accel, GTK_OBJECT(m_wxwindow)); +#endif + wxNode *node = m_frameMenuBar->GetMenus().First(); while (node) { @@ -788,6 +792,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) } } + /* resize window in OnInternalIdle */ m_sizeSet = FALSE; } diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index d2df6c95f6..dd3d6850bf 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -28,13 +28,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) wxMenuBar::wxMenuBar( long style ) { - m_needParent = FALSE; // hmmm + /* the parent window is known after wxFrame::SetMenu() */ + m_needParent = FALSE; PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); m_menus.DeleteContents( TRUE ); + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + m_accel = gtk_accel_group_new(); + m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "
", m_accel ); + m_menubar = gtk_item_factory_get_widget( m_factory, "
" ); +#else m_menubar = gtk_menu_bar_new(); +#endif if (style & wxMB_DOCKABLE) { @@ -54,13 +62,21 @@ wxMenuBar::wxMenuBar( long style ) wxMenuBar::wxMenuBar() { - m_needParent = FALSE; // hmmm + /* the parent window is known after wxFrame::SetMenu() */ + m_needParent = FALSE; PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); m_menus.DeleteContents( TRUE ); + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + m_accel = gtk_accel_group_new(); + m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "
", m_accel ); + m_menubar = gtk_item_factory_get_widget( m_factory, "
" ); +#else m_menubar = gtk_menu_bar_new(); +#endif m_widget = GTK_WIDGET(m_menubar); @@ -69,29 +85,70 @@ wxMenuBar::wxMenuBar() Show( TRUE ); } +wxMenuBar::~wxMenuBar() +{ + // how to destroy a GtkItemFactory ? +} + void wxMenuBar::Append( wxMenu *menu, const wxString &title ) { m_menus.Append( menu ); - wxString s = _T(""); + /* GTK 1.2 wants to have "_" instead of "&" for accelerators */ + wxString str; for ( const wxChar *pc = title; *pc != _T('\0'); pc++ ) { if (*pc == _T('&')) { pc++; /* skip it */ -#if (GTK_MINOR_VERSION > 0) - // s << '_'; not yet +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + str << _T('_'); #endif } - s << *pc; + str << *pc; } - menu->SetTitle(s); - menu->m_owner = gtk_menu_item_new_with_label( MBSTRINGCAST s.mbc_str() ); + /* this doesn't have much effect right now */ + menu->SetTitle( str ); + + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + + /* local buffer in multibyte form */ + char buf[200]; + strcpy( buf, "/" ); + strcat( buf, str.mb_str() ); + + GtkItemFactoryEntry entry; + entry.path = buf; + entry.accelerator = (gchar*) NULL; + entry.callback = (GtkItemFactoryCallback) NULL; + entry.callback_action = 0; + entry.item_type = ""; + + 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 tmp = _T("
/"); + for ( const wxChar *pc = str; *pc != _T('\0'); pc++ ) + { + if (*pc == _T('_')) pc++; /* skip it */ + tmp << *pc; + } + + menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() ); + + gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); + +#else + + menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() ); gtk_widget_show( menu->m_owner ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); + +#endif } static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) @@ -420,7 +477,7 @@ void wxMenuItem::SetName( const wxString& str ) if (m_menuItem) { GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); - gtk_label_set( label, m_text.mbc_str()); + gtk_label_set( label, m_text.mb_str()); } } @@ -525,16 +582,18 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool mitem->SetText(item); mitem->SetHelp(helpStr); mitem->SetCheckable(checkable); - const wxChar *text = mitem->GetText(); #if (GTK_MINOR_VERSION > 0) - wxChar buf[100]; - wxStrcpy( buf, _T("/") ); - wxStrcat( buf, text ); + /* text has "_" instead of "&" after mitem->SetText() */ + wxString text( mitem->GetText() ); + + /* local buffer in multibyte form */ + char buf[200]; + strcpy( buf, "/" ); + strcat( buf, text.mb_str() ); - const wxWX2MBbuf pbuf = wxConv_current->cWX2MB(buf); GtkItemFactoryEntry entry; - entry.path = MBSTRINGCAST pbuf; + entry.path = buf; entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; entry.callback_action = 0; @@ -553,12 +612,12 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool s << *pc; } - GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mbc_str() ); + GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() ); #else - GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text) - : gtk_menu_item_new_with_label(text); + GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( item.mb_str() ) + : gtk_menu_item_new_with_label( item.mb_str() ); gtk_signal_connect( GTK_OBJECT(menuItem), "activate", GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 86fc0bed68..45c3bbaab1 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -281,12 +281,11 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e if (g_blockEventsOnDrag) return FALSE; /* - printf( "OnKeyPress from " ); + wxPrintf( _T("OnKeyPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ - long key_code = 0; switch (gdk_event->keyval) { @@ -572,6 +571,13 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { +/* + wxPrintf( _T("1) OnButtonPress from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); +*/ + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -585,20 +591,31 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton gtk_widget_grab_focus (win->m_wxwindow); /* - printf( "GrabFocus from " ); + wxPrintf( _T("GrabFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ } +/* + else + { + wxPrintf( _T("No GrabFocus from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) + wxPrintf( _T(" because it already has") ); + wxPrintf( _T(".\n") ); + } +*/ } /* - printf( "OnButtonPress from " ); + wxPrintf( _T("2) OnButtonPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ wxEventType event_type = wxEVT_LEFT_DOWN; @@ -948,12 +965,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( /* - printf( "OnSetFocus from " ); + wxPrintf( _T("OnSetFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( " " ); - printf( WXSTRINGCAST win->GetLabel() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); @@ -984,10 +1001,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED } /* - printf( "OnKillFocus from " ); + wxPrintf( _T("OnKillFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); @@ -1314,14 +1333,14 @@ gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) { wxColour bg( win->m_backgroundColour ); - win->SetBackgroundColour( wxNullColour ); + win->m_backgroundColour = wxNullColour; win->SetBackgroundColour( bg ); } if (win->m_foregroundColour != *wxBLACK) { wxColour fg( win->m_foregroundColour ); - win->SetForegroundColour( wxNullColour ); + win->m_foregroundColour = wxNullColour; win->SetForegroundColour( fg ); } @@ -1781,12 +1800,13 @@ void wxWindow::PostCreation() #endif } - ConnectWidget( GetConnectWidget() ); + GtkWidget *connect_widget = GetConnectWidget(); + + ConnectWidget( connect_widget ); -/* we cannot set colours, fonts and cursors before the widget has - been realized, so we do this directly after realization */ - - gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + /* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(connect_widget), "realize", GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); m_hasVMT = TRUE; @@ -2641,8 +2661,9 @@ void wxWindow::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; if (!m_backgroundColour.Ok()) return; - if (!m_widget->window) return; - + GtkWidget *connect_widget = GetConnectWidget(); + if (!connect_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { /* wxMSW doesn't clear the window here. I don't do that diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index ffd5d9ef15..918e0a52db 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -109,10 +109,23 @@ wxWindowDC::wxWindowDC( wxWindow *window ) m_owner = (wxWindow *)NULL; if (!window) return; + GtkWidget *widget = window->m_wxwindow; if (!widget) return; + m_window = widget->window; + + /* not realized ? */ + if (!m_window) + { + /* force realization */ + gtk_widget_realize( widget ); + m_window = widget->window; + } + + /* still not realized ? */ if (!m_window) return; + if (window->m_wxwindow) m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); else diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index bf4f14a3c2..5d169310b8 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -249,13 +249,6 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child ) /* resize on OnInternalIdle */ parent->m_sizeSet = FALSE; - - if (parent->m_windowStyle & wxTAB_TRAVERSAL) - { - /* we now allow a window to get the focus as long as it - doesn't have any children. */ - GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS ); - } } //----------------------------------------------------------------------------- @@ -335,8 +328,14 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, /* m_wxwindow only represents the client area without toolbar and menubar */ m_wxwindow = gtk_myfixed_new(); gtk_widget_show( m_wxwindow ); - GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); + + /* we allow the frame to get the focus as otherwise no + keye vents will get sent to it. the point with this is + that the menu's key accelerators work by interceting + key events here */ + GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); + GTK_WIDGET_SET_FLAGS (m_wxwindow, GTK_HAS_FOCUS); if (m_parent) m_parent->AddChild( this ); @@ -763,6 +762,11 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar) { + /* support for native key accelerators indicated by underscroes */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + gtk_accel_group_attach( m_frameMenuBar->m_accel, GTK_OBJECT(m_wxwindow)); +#endif + wxNode *node = m_frameMenuBar->GetMenus().First(); while (node) { @@ -788,6 +792,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar ) } } + /* resize window in OnInternalIdle */ m_sizeSet = FALSE; } diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index d2df6c95f6..dd3d6850bf 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -28,13 +28,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) wxMenuBar::wxMenuBar( long style ) { - m_needParent = FALSE; // hmmm + /* the parent window is known after wxFrame::SetMenu() */ + m_needParent = FALSE; PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); m_menus.DeleteContents( TRUE ); + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + m_accel = gtk_accel_group_new(); + m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "
", m_accel ); + m_menubar = gtk_item_factory_get_widget( m_factory, "
" ); +#else m_menubar = gtk_menu_bar_new(); +#endif if (style & wxMB_DOCKABLE) { @@ -54,13 +62,21 @@ wxMenuBar::wxMenuBar( long style ) wxMenuBar::wxMenuBar() { - m_needParent = FALSE; // hmmm + /* the parent window is known after wxFrame::SetMenu() */ + m_needParent = FALSE; PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); m_menus.DeleteContents( TRUE ); + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + m_accel = gtk_accel_group_new(); + m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "
", m_accel ); + m_menubar = gtk_item_factory_get_widget( m_factory, "
" ); +#else m_menubar = gtk_menu_bar_new(); +#endif m_widget = GTK_WIDGET(m_menubar); @@ -69,29 +85,70 @@ wxMenuBar::wxMenuBar() Show( TRUE ); } +wxMenuBar::~wxMenuBar() +{ + // how to destroy a GtkItemFactory ? +} + void wxMenuBar::Append( wxMenu *menu, const wxString &title ) { m_menus.Append( menu ); - wxString s = _T(""); + /* GTK 1.2 wants to have "_" instead of "&" for accelerators */ + wxString str; for ( const wxChar *pc = title; *pc != _T('\0'); pc++ ) { if (*pc == _T('&')) { pc++; /* skip it */ -#if (GTK_MINOR_VERSION > 0) - // s << '_'; not yet +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + str << _T('_'); #endif } - s << *pc; + str << *pc; } - menu->SetTitle(s); - menu->m_owner = gtk_menu_item_new_with_label( MBSTRINGCAST s.mbc_str() ); + /* this doesn't have much effect right now */ + menu->SetTitle( str ); + + /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + + /* local buffer in multibyte form */ + char buf[200]; + strcpy( buf, "/" ); + strcat( buf, str.mb_str() ); + + GtkItemFactoryEntry entry; + entry.path = buf; + entry.accelerator = (gchar*) NULL; + entry.callback = (GtkItemFactoryCallback) NULL; + entry.callback_action = 0; + entry.item_type = ""; + + 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 tmp = _T("
/"); + for ( const wxChar *pc = str; *pc != _T('\0'); pc++ ) + { + if (*pc == _T('_')) pc++; /* skip it */ + tmp << *pc; + } + + menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() ); + + gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); + +#else + + menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() ); gtk_widget_show( menu->m_owner ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); + +#endif } static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) @@ -420,7 +477,7 @@ void wxMenuItem::SetName( const wxString& str ) if (m_menuItem) { GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); - gtk_label_set( label, m_text.mbc_str()); + gtk_label_set( label, m_text.mb_str()); } } @@ -525,16 +582,18 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool mitem->SetText(item); mitem->SetHelp(helpStr); mitem->SetCheckable(checkable); - const wxChar *text = mitem->GetText(); #if (GTK_MINOR_VERSION > 0) - wxChar buf[100]; - wxStrcpy( buf, _T("/") ); - wxStrcat( buf, text ); + /* text has "_" instead of "&" after mitem->SetText() */ + wxString text( mitem->GetText() ); + + /* local buffer in multibyte form */ + char buf[200]; + strcpy( buf, "/" ); + strcat( buf, text.mb_str() ); - const wxWX2MBbuf pbuf = wxConv_current->cWX2MB(buf); GtkItemFactoryEntry entry; - entry.path = MBSTRINGCAST pbuf; + entry.path = buf; entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; entry.callback_action = 0; @@ -553,12 +612,12 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool s << *pc; } - GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mbc_str() ); + GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() ); #else - GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text) - : gtk_menu_item_new_with_label(text); + GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( item.mb_str() ) + : gtk_menu_item_new_with_label( item.mb_str() ); gtk_signal_connect( GTK_OBJECT(menuItem), "activate", GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 86fc0bed68..45c3bbaab1 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -281,12 +281,11 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e if (g_blockEventsOnDrag) return FALSE; /* - printf( "OnKeyPress from " ); + wxPrintf( _T("OnKeyPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ - long key_code = 0; switch (gdk_event->keyval) { @@ -572,6 +571,13 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) { +/* + wxPrintf( _T("1) OnButtonPress from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); +*/ + if (!win->HasVMT()) return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; @@ -585,20 +591,31 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton gtk_widget_grab_focus (win->m_wxwindow); /* - printf( "GrabFocus from " ); + wxPrintf( _T("GrabFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ } +/* + else + { + wxPrintf( _T("No GrabFocus from ") ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + wxPrintf( win->GetClassInfo()->GetClassName() ); + if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) + wxPrintf( _T(" because it already has") ); + wxPrintf( _T(".\n") ); + } +*/ } /* - printf( "OnButtonPress from " ); + wxPrintf( _T("2) OnButtonPress from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(".\n") ); */ wxEventType event_type = wxEVT_LEFT_DOWN; @@ -948,12 +965,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED( /* - printf( "OnSetFocus from " ); + wxPrintf( _T("OnSetFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( " " ); - printf( WXSTRINGCAST win->GetLabel() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); @@ -984,10 +1001,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED } /* - printf( "OnKillFocus from " ); + wxPrintf( _T("OnKillFocus from ") ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - printf( win->GetClassInfo()->GetClassName() ); - printf( ".\n" ); + wxPrintf( win->GetClassInfo()->GetClassName() ); + wxPrintf( _T(" ") ); + wxPrintf( win->GetLabel() ); + wxPrintf( _T(".\n") ); */ wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); @@ -1314,14 +1333,14 @@ gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) { wxColour bg( win->m_backgroundColour ); - win->SetBackgroundColour( wxNullColour ); + win->m_backgroundColour = wxNullColour; win->SetBackgroundColour( bg ); } if (win->m_foregroundColour != *wxBLACK) { wxColour fg( win->m_foregroundColour ); - win->SetForegroundColour( wxNullColour ); + win->m_foregroundColour = wxNullColour; win->SetForegroundColour( fg ); } @@ -1781,12 +1800,13 @@ void wxWindow::PostCreation() #endif } - ConnectWidget( GetConnectWidget() ); + GtkWidget *connect_widget = GetConnectWidget(); + + ConnectWidget( connect_widget ); -/* we cannot set colours, fonts and cursors before the widget has - been realized, so we do this directly after realization */ - - gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + /* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(connect_widget), "realize", GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); m_hasVMT = TRUE; @@ -2641,8 +2661,9 @@ void wxWindow::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; if (!m_backgroundColour.Ok()) return; - if (!m_widget->window) return; - + GtkWidget *connect_widget = GetConnectWidget(); + if (!connect_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { /* wxMSW doesn't clear the window here. I don't do that