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
This commit is contained in:
Robert Roebling
1999-02-05 13:25:40 +00:00
parent 341c92a8b4
commit 342b6a2fe4
10 changed files with 115 additions and 45 deletions

View File

@@ -102,6 +102,8 @@ public:
void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
void OnCloseWindow( wxCloseEvent& event ); void OnCloseWindow( wxCloseEvent& event );
void OnMenuHighlight( wxMenuEvent& event );
// implementation // implementation

View File

@@ -49,15 +49,14 @@ public:
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
wxMenuItem* FindMenuItemById( int id ) const; wxMenuItem* FindMenuItemById( int id ) const;
inline wxMenuItem* FindItemForId( int id ) const inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); }
{ return FindMenuItemById( id ); }
void Check( int id, bool check ); void Check( int id, bool check );
bool Checked( int id ) const; bool Checked( int id ) const;
void Enable( int id, bool enable ); void Enable( int id, bool enable );
bool Enabled( int id ) const; bool Enabled( int id ) const;
inline bool IsEnabled(int Id) const { return Enabled(Id); } inline bool IsEnabled( int id ) const { return Enabled(id); }
inline bool IsChecked(int Id) const { return Checked(Id); } inline bool IsChecked( int id ) const { return Checked(id); }
wxString GetLabel( int id ) const; wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label ); void SetLabel( int id, const wxString &label );
@@ -66,8 +65,11 @@ public:
void SetLabelTop( int pos, const wxString& label ); void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const; wxString GetLabelTop( int pos ) const;
int GetMenuCount() const { return m_menus.Number(); } virtual void SetHelpString( int id, const wxString& helpString );
wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); } 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; wxList m_menus;
GtkWidget *m_menubar; GtkWidget *m_menubar;

View File

@@ -102,6 +102,8 @@ public:
void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp void OnActivate( wxActivateEvent &WXUNUSED(event) ) { } // called from docview.cpp
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
void OnCloseWindow( wxCloseEvent& event ); void OnCloseWindow( wxCloseEvent& event );
void OnMenuHighlight( wxMenuEvent& event );
// implementation // implementation

View File

@@ -49,15 +49,14 @@ public:
int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
wxMenuItem* FindMenuItemById( int id ) const; wxMenuItem* FindMenuItemById( int id ) const;
inline wxMenuItem* FindItemForId( int id ) const inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); }
{ return FindMenuItemById( id ); }
void Check( int id, bool check ); void Check( int id, bool check );
bool Checked( int id ) const; bool Checked( int id ) const;
void Enable( int id, bool enable ); void Enable( int id, bool enable );
bool Enabled( int id ) const; bool Enabled( int id ) const;
inline bool IsEnabled(int Id) const { return Enabled(Id); } inline bool IsEnabled( int id ) const { return Enabled(id); }
inline bool IsChecked(int Id) const { return Checked(Id); } inline bool IsChecked( int id ) const { return Checked(id); }
wxString GetLabel( int id ) const; wxString GetLabel( int id ) const;
void SetLabel( int id, const wxString &label ); void SetLabel( int id, const wxString &label );
@@ -66,8 +65,11 @@ public:
void SetLabelTop( int pos, const wxString& label ); void SetLabelTop( int pos, const wxString& label );
wxString GetLabelTop( int pos ) const; wxString GetLabelTop( int pos ) const;
int GetMenuCount() const { return m_menus.Number(); } virtual void SetHelpString( int id, const wxString& helpString );
wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); } 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; wxList m_menus;
GtkWidget *m_menubar; GtkWidget *m_menubar;

View File

@@ -56,10 +56,10 @@ bool MyApp::OnInit(void)
// Make a menubar // Make a menubar
wxMenu *fileMenu = new wxMenu; wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_EXIT, "E&xit"); fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_HELP, "&About"); helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
wxMenuBar* menuBar = new wxMenuBar; wxMenuBar* menuBar = new wxMenuBar;

View File

@@ -64,11 +64,6 @@
#endif #endif
#ifdef __WXGTK__
#include "gtk/gtk.h"
#include "gdk/gdk.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// start and end of document/page // start and end of document/page
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -1480,28 +1475,13 @@ bool wxPostScriptDC::Blit( long xdest, long ydest,
wxCHECK_MSG( source, FALSE, "invalid source dc" ); wxCHECK_MSG( source, FALSE, "invalid source dc" );
wxClientDC *srcDC = (wxClientDC*)source; /* blit into a bitmap */
wxBitmap bitmap( fwidth, fheight ); 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; wxMemoryDC memDC;
memDC.SelectObject(bitmap); memDC.SelectObject(bitmap);
// TODO: Do we want to blit transparently? memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
memDC.Blit(0, 0, fwidth, fheight, source, xsrc, ysrc, rop);
memDC.SelectObject(wxNullBitmap); memDC.SelectObject(wxNullBitmap);
#endif
/* draw bitmap. scaling and positioning is done there */ /* draw bitmap. scaling and positioning is done there */
@@ -1518,9 +1498,9 @@ long wxPostScriptDC::GetCharHeight()
return 12; return 12;
} }
void wxPostScriptDC::GetTextExtent (const wxString& string, long *x, long *y, void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y,
long *descent, long *externalLeading, wxFont *theFont, long *descent, long *externalLeading, wxFont *theFont,
bool WXUNUSED(use16)) bool WXUNUSED(use16) )
{ {
wxFont *fontToUse = theFont; wxFont *fontToUse = theFont;

View File

@@ -105,6 +105,7 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC
BEGIN_EVENT_TABLE(wxFrame, wxWindow) BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_SIZE(wxFrame::OnSize) EVT_SIZE(wxFrame::OnSize)
EVT_CLOSE(wxFrame::OnCloseWindow) EVT_CLOSE(wxFrame::OnCloseWindow)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
END_EVENT_TABLE() END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
@@ -564,6 +565,29 @@ wxMenuBar *wxFrame::GetMenuBar() const
return m_frameMenuBar; 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) wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
{ {
wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); wxASSERT_MSG( (m_widget != NULL), "invalid frame" );

View File

@@ -152,6 +152,7 @@ bool wxMenuBar::Enabled( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsEnabled(); if (item) return item->IsEnabled();
return FALSE; return FALSE;
} }
@@ -161,7 +162,7 @@ wxString wxMenuBar::GetLabel( int id ) const
if (item) return item->GetText(); if (item) return item->GetText();
return ""; return wxString("");
} }
void wxMenuBar::SetLabel( int id, const wxString &label ) void wxMenuBar::SetLabel( int id, const wxString &label )
@@ -204,6 +205,23 @@ void wxMenuBar::SetLabelTop( int pos, const wxString& label )
menu->SetTitle( 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" // "activate"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -262,9 +280,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id)) return;
wxCommandEvent event( wxEVT_MENU_HIGHLIGHT, id ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
event.SetInt(id );
/* wxMSW doesn't call callback here either /* wxMSW doesn't call callback here either

View File

@@ -105,6 +105,7 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC
BEGIN_EVENT_TABLE(wxFrame, wxWindow) BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_SIZE(wxFrame::OnSize) EVT_SIZE(wxFrame::OnSize)
EVT_CLOSE(wxFrame::OnCloseWindow) EVT_CLOSE(wxFrame::OnCloseWindow)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
END_EVENT_TABLE() END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
@@ -564,6 +565,29 @@ wxMenuBar *wxFrame::GetMenuBar() const
return m_frameMenuBar; 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) wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
{ {
wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); wxASSERT_MSG( (m_widget != NULL), "invalid frame" );

View File

@@ -152,6 +152,7 @@ bool wxMenuBar::Enabled( int id ) const
{ {
wxMenuItem* item = FindMenuItemById( id ); wxMenuItem* item = FindMenuItemById( id );
if (item) return item->IsEnabled(); if (item) return item->IsEnabled();
return FALSE; return FALSE;
} }
@@ -161,7 +162,7 @@ wxString wxMenuBar::GetLabel( int id ) const
if (item) return item->GetText(); if (item) return item->GetText();
return ""; return wxString("");
} }
void wxMenuBar::SetLabel( int id, const wxString &label ) void wxMenuBar::SetLabel( int id, const wxString &label )
@@ -204,6 +205,23 @@ void wxMenuBar::SetLabelTop( int pos, const wxString& label )
menu->SetTitle( 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" // "activate"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -262,9 +280,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
if (!menu->IsEnabled(id)) return; if (!menu->IsEnabled(id)) return;
wxCommandEvent event( wxEVT_MENU_HIGHLIGHT, id ); wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
event.SetInt(id );
/* wxMSW doesn't call callback here either /* wxMSW doesn't call callback here either