From 342b6a2fe480fa6f6ee80fdb51cb009c30b35305 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 5 Feb 1999 13:25:40 +0000 Subject: [PATCH] Added menu_highlight behaviour as in wxMSW (statusbar) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1606 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/frame.h | 2 ++ include/wx/gtk/menu.h | 14 ++++++++------ include/wx/gtk1/frame.h | 2 ++ include/wx/gtk1/menu.h | 14 ++++++++------ samples/toolbar/test.cpp | 4 ++-- src/generic/dcpsg.cpp | 30 +++++------------------------- src/gtk/frame.cpp | 24 ++++++++++++++++++++++++ src/gtk/menu.cpp | 23 ++++++++++++++++++++--- src/gtk1/frame.cpp | 24 ++++++++++++++++++++++++ src/gtk1/menu.cpp | 23 ++++++++++++++++++++--- 10 files changed, 115 insertions(+), 45 deletions(-) diff --git a/include/wx/gtk/frame.h b/include/wx/gtk/frame.h index 0dd712f946..7fcfc639e3 100644 --- a/include/wx/gtk/frame.h +++ b/include/wx/gtk/frame.h @@ -102,6 +102,8 @@ public: void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp void OnSize( wxSizeEvent &event ); void OnCloseWindow( wxCloseEvent& event ); + + void OnMenuHighlight( wxMenuEvent& event ); // implementation diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index 860e0b8d14..18844219c9 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -49,15 +49,14 @@ public: int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; wxMenuItem* FindMenuItemById( int id ) const; - inline wxMenuItem* FindItemForId( int id ) const - { return FindMenuItemById( id ); } + inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); } void Check( int id, bool check ); bool Checked( int id ) const; void Enable( int id, bool enable ); bool Enabled( int id ) const; - inline bool IsEnabled(int Id) const { return Enabled(Id); } - inline bool IsChecked(int Id) const { return Checked(Id); } + inline bool IsEnabled( int id ) const { return Enabled(id); } + inline bool IsChecked( int id ) const { return Checked(id); } wxString GetLabel( int id ) const; void SetLabel( int id, const wxString &label ); @@ -66,8 +65,11 @@ public: void SetLabelTop( int pos, const wxString& label ); wxString GetLabelTop( int pos ) const; - int GetMenuCount() const { return m_menus.Number(); } - wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); } + virtual void SetHelpString( int id, const wxString& helpString ); + virtual wxString GetHelpString( int id ) const; + + inline int GetMenuCount() const { return m_menus.Number(); } + inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } wxList m_menus; GtkWidget *m_menubar; diff --git a/include/wx/gtk1/frame.h b/include/wx/gtk1/frame.h index 0dd712f946..7fcfc639e3 100644 --- a/include/wx/gtk1/frame.h +++ b/include/wx/gtk1/frame.h @@ -102,6 +102,8 @@ public: void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp void OnSize( wxSizeEvent &event ); void OnCloseWindow( wxCloseEvent& event ); + + void OnMenuHighlight( wxMenuEvent& event ); // implementation diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index 860e0b8d14..18844219c9 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -49,15 +49,14 @@ public: int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; wxMenuItem* FindMenuItemById( int id ) const; - inline wxMenuItem* FindItemForId( int id ) const - { return FindMenuItemById( id ); } + inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); } void Check( int id, bool check ); bool Checked( int id ) const; void Enable( int id, bool enable ); bool Enabled( int id ) const; - inline bool IsEnabled(int Id) const { return Enabled(Id); } - inline bool IsChecked(int Id) const { return Checked(Id); } + inline bool IsEnabled( int id ) const { return Enabled(id); } + inline bool IsChecked( int id ) const { return Checked(id); } wxString GetLabel( int id ) const; void SetLabel( int id, const wxString &label ); @@ -66,8 +65,11 @@ public: void SetLabelTop( int pos, const wxString& label ); wxString GetLabelTop( int pos ) const; - int GetMenuCount() const { return m_menus.Number(); } - wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); } + virtual void SetHelpString( int id, const wxString& helpString ); + virtual wxString GetHelpString( int id ) const; + + inline int GetMenuCount() const { return m_menus.Number(); } + inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } wxList m_menus; GtkWidget *m_menubar; diff --git a/samples/toolbar/test.cpp b/samples/toolbar/test.cpp index cd661ac65c..9d6232483a 100644 --- a/samples/toolbar/test.cpp +++ b/samples/toolbar/test.cpp @@ -56,10 +56,10 @@ bool MyApp::OnInit(void) // Make a menubar wxMenu *fileMenu = new wxMenu; - fileMenu->Append(wxID_EXIT, "E&xit"); + fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" ); wxMenu *helpMenu = new wxMenu; - helpMenu->Append(wxID_HELP, "&About"); + helpMenu->Append(wxID_HELP, "&About", "About toolbar sample"); wxMenuBar* menuBar = new wxMenuBar; diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 4fac5ff954..f592a769c8 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -64,11 +64,6 @@ #endif -#ifdef __WXGTK__ -#include "gtk/gtk.h" -#include "gdk/gdk.h" -#endif - //----------------------------------------------------------------------------- // start and end of document/page //----------------------------------------------------------------------------- @@ -1480,28 +1475,13 @@ bool wxPostScriptDC::Blit( long xdest, long ydest, wxCHECK_MSG( source, FALSE, "invalid source dc" ); - wxClientDC *srcDC = (wxClientDC*)source; + /* blit into a bitmap */ wxBitmap bitmap( fwidth, fheight ); - -#ifdef __WXGTK__ - /* just take any GC so we don't have to create our own. */ - - GtkStyle *style = gtk_widget_get_default_style (); - GdkGC *gc = style->white_gc; - - /* copy from either window or bitmap */ - - gdk_window_copy_area( bitmap.GetPixmap(), gc, 0, 0, - srcDC->GetWindow(), - xsrc, ysrc, fwidth, fheight ); -#else wxMemoryDC memDC; memDC.SelectObject(bitmap); - // TODO: Do we want to blit transparently? - memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); + memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */ memDC.SelectObject(wxNullBitmap); -#endif /* draw bitmap. scaling and positioning is done there */ @@ -1518,9 +1498,9 @@ long wxPostScriptDC::GetCharHeight() return 12; } -void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, - long *descent, long *externalLeading, wxFont *theFont, - bool WXUNUSED(use16)) +void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, + long *descent, long *externalLeading, wxFont *theFont, + bool WXUNUSED(use16) ) { wxFont *fontToUse = theFont; diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index d809e69266..af7887cf2c 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -105,6 +105,7 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC BEGIN_EVENT_TABLE(wxFrame, wxWindow) EVT_SIZE(wxFrame::OnSize) EVT_CLOSE(wxFrame::OnCloseWindow) + EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) @@ -564,6 +565,29 @@ wxMenuBar *wxFrame::GetMenuBar() const return m_frameMenuBar; } +void wxFrame::OnMenuHighlight(wxMenuEvent& event) +{ + if (GetStatusBar()) + { + if (event.GetMenuId() == -1) + { + SetStatusText(""); + } + else + { + wxMenuBar *menuBar = GetMenuBar(); + if (menuBar) + { + int menuId = event.GetMenuId(); + wxString helpString; + helpString = menuBar->GetHelpString(menuId); + if (helpString != "") + SetStatusText(helpString); + } + } + } +} + wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 27173bba72..110c8f958f 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -152,6 +152,7 @@ bool wxMenuBar::Enabled( int id ) const { wxMenuItem* item = FindMenuItemById( id ); if (item) return item->IsEnabled(); + return FALSE; } @@ -161,7 +162,7 @@ wxString wxMenuBar::GetLabel( int id ) const if (item) return item->GetText(); - return ""; + return wxString(""); } void wxMenuBar::SetLabel( int id, const wxString &label ) @@ -204,6 +205,23 @@ void wxMenuBar::SetLabelTop( int pos, const wxString& label ) menu->SetTitle( label ); } +void wxMenuBar::SetHelpString( int id, const wxString& helpString ) +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) item->SetHelp( helpString ); +} + +wxString wxMenuBar::GetHelpString( int id ) const +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) + return item->GetHelp(); + else + return wxString(""); +} + //----------------------------------------------------------------------------- // "activate" //----------------------------------------------------------------------------- @@ -262,9 +280,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; - wxCommandEvent event( wxEVT_MENU_HIGHLIGHT, id ); + wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); event.SetEventObject( menu ); - event.SetInt(id ); /* wxMSW doesn't call callback here either diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index d809e69266..af7887cf2c 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -105,6 +105,7 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC BEGIN_EVENT_TABLE(wxFrame, wxWindow) EVT_SIZE(wxFrame::OnSize) EVT_CLOSE(wxFrame::OnCloseWindow) + EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) @@ -564,6 +565,29 @@ wxMenuBar *wxFrame::GetMenuBar() const return m_frameMenuBar; } +void wxFrame::OnMenuHighlight(wxMenuEvent& event) +{ + if (GetStatusBar()) + { + if (event.GetMenuId() == -1) + { + SetStatusText(""); + } + else + { + wxMenuBar *menuBar = GetMenuBar(); + if (menuBar) + { + int menuId = event.GetMenuId(); + wxString helpString; + helpString = menuBar->GetHelpString(menuId); + if (helpString != "") + SetStatusText(helpString); + } + } + } +} + wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 27173bba72..110c8f958f 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -152,6 +152,7 @@ bool wxMenuBar::Enabled( int id ) const { wxMenuItem* item = FindMenuItemById( id ); if (item) return item->IsEnabled(); + return FALSE; } @@ -161,7 +162,7 @@ wxString wxMenuBar::GetLabel( int id ) const if (item) return item->GetText(); - return ""; + return wxString(""); } void wxMenuBar::SetLabel( int id, const wxString &label ) @@ -204,6 +205,23 @@ void wxMenuBar::SetLabelTop( int pos, const wxString& label ) menu->SetTitle( label ); } +void wxMenuBar::SetHelpString( int id, const wxString& helpString ) +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) item->SetHelp( helpString ); +} + +wxString wxMenuBar::GetHelpString( int id ) const +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) + return item->GetHelp(); + else + return wxString(""); +} + //----------------------------------------------------------------------------- // "activate" //----------------------------------------------------------------------------- @@ -262,9 +280,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; - wxCommandEvent event( wxEVT_MENU_HIGHLIGHT, id ); + wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); event.SetEventObject( menu ); - event.SetInt(id ); /* wxMSW doesn't call callback here either -- 2.45.2