From ab73fe8d1dc54cb83e3a18868db770c96760fbb6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Aug 2006 22:24:57 +0000 Subject: [PATCH] added stock menu items support git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 ++++ samples/menu/menu.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/gtk/menu.cpp | 46 ++++++++++++++++++++++++++++++------------ 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f1f9a75..e80105a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -63,6 +63,10 @@ wxMac: - Add parameter to the --enable-universal_binary configure option for the path to the SDK. +wxGTK: + +- Automatically use stock items for the menu items with standard ids + 2.7.0 ----- diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index c956f21..6d19fa4 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -378,6 +378,59 @@ MyFrame::MyFrame() // create the menubar wxMenu *fileMenu = new wxMenu; + wxMenu *stockSubMenu = new wxMenu; + stockSubMenu->Append(wxID_ADD, "wxID_ADD"); + stockSubMenu->Append(wxID_APPLY, "wxID_APPLY"); + stockSubMenu->Append(wxID_BOLD, "wxID_BOLD"); + stockSubMenu->Append(wxID_CANCEL, "wxID_CANCEL"); + stockSubMenu->Append(wxID_CLEAR, "wxID_CLEAR"); + stockSubMenu->Append(wxID_CLOSE, "wxID_CLOSE"); + stockSubMenu->Append(wxID_COPY, "wxID_COPY"); + stockSubMenu->Append(wxID_CUT, "wxID_CUT"); + stockSubMenu->Append(wxID_DELETE, "wxID_DELETE"); + stockSubMenu->Append(wxID_FIND, "wxID_FIND"); + stockSubMenu->Append(wxID_REPLACE, "wxID_REPLACE"); + stockSubMenu->Append(wxID_BACKWARD, "wxID_BACKWARD"); + stockSubMenu->Append(wxID_DOWN, "wxID_DOWN"); + stockSubMenu->Append(wxID_FORWARD, "wxID_FORWARD"); + stockSubMenu->Append(wxID_UP, "wxID_UP"); + stockSubMenu->Append(wxID_HELP, "wxID_HELP"); + stockSubMenu->Append(wxID_HOME, "wxID_HOME"); + stockSubMenu->Append(wxID_INDENT, "wxID_INDENT"); + stockSubMenu->Append(wxID_INDEX, "wxID_INDEX"); + stockSubMenu->Append(wxID_ITALIC, "wxID_ITALIC"); + stockSubMenu->Append(wxID_JUSTIFY_CENTER, "wxID_JUSTIFY_CENTER"); + stockSubMenu->Append(wxID_JUSTIFY_FILL, "wxID_JUSTIFY_FILL"); + stockSubMenu->Append(wxID_JUSTIFY_LEFT, "wxID_JUSTIFY_LEFT"); + stockSubMenu->Append(wxID_JUSTIFY_RIGHT, "wxID_JUSTIFY_RIGHT"); + stockSubMenu->Append(wxID_NEW, "wxID_NEW"); + stockSubMenu->Append(wxID_NO, "wxID_NO"); + stockSubMenu->Append(wxID_OK, "wxID_OK"); + stockSubMenu->Append(wxID_OPEN, "wxID_OPEN"); + stockSubMenu->Append(wxID_PASTE, "wxID_PASTE"); + stockSubMenu->Append(wxID_PREFERENCES, "wxID_PREFERENCES"); + stockSubMenu->Append(wxID_PRINT, "wxID_PRINT"); + stockSubMenu->Append(wxID_PREVIEW, "wxID_PREVIEW"); + stockSubMenu->Append(wxID_PROPERTIES, "wxID_PROPERTIES"); + stockSubMenu->Append(wxID_EXIT, "wxID_EXIT"); + stockSubMenu->Append(wxID_REDO, "wxID_REDO"); + stockSubMenu->Append(wxID_REFRESH, "wxID_REFRESH"); + stockSubMenu->Append(wxID_REMOVE, "wxID_REMOVE"); + stockSubMenu->Append(wxID_REVERT_TO_SAVED, "wxID_REVERT_TO_SAVED"); + stockSubMenu->Append(wxID_SAVE, "wxID_SAVE"); + stockSubMenu->Append(wxID_SAVEAS, "wxID_SAVEAS"); + stockSubMenu->Append(wxID_STOP, "wxID_STOP"); + stockSubMenu->Append(wxID_UNDELETE, "wxID_UNDELETE"); + stockSubMenu->Append(wxID_UNDERLINE, "wxID_UNDERLINE"); + stockSubMenu->Append(wxID_UNDO, "wxID_UNDO"); + stockSubMenu->Append(wxID_UNINDENT, "wxID_UNINDENT"); + stockSubMenu->Append(wxID_YES, "wxID_YES"); + stockSubMenu->Append(wxID_ZOOM_100, "wxID_ZOOM_100"); + stockSubMenu->Append(wxID_ZOOM_FIT, "wxID_ZOOM_FIT"); + stockSubMenu->Append(wxID_ZOOM_IN, "wxID_ZOOM_IN"); + stockSubMenu->Append(wxID_ZOOM_OUT, "wxID_ZOOM_OUT"); + fileMenu->AppendSubMenu(stockSubMenu, _T("&Standard items demo")); + #if USE_LOG_WINDOW wxMenuItem *item = new wxMenuItem(fileMenu, Menu_File_ClearLog, _T("Clear &log\tCtrl-L")); @@ -386,7 +439,8 @@ MyFrame::MyFrame() #endif fileMenu->Append(item); fileMenu->AppendSeparator(); -#endif +#endif // USE_LOG_WINDOW + fileMenu->Append(Menu_File_Quit, _T("E&xit\tAlt-X"), _T("Quit menu sample")); wxMenu *menubarMenu = new wxMenu; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index f27623a..f11a157 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -23,6 +23,7 @@ #include "wx/accel.h" #endif // wxUSE_ACCEL +#include "wx/stockitem.h" #include "wx/gtk/private.h" #include @@ -945,37 +946,56 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { menuItem = gtk_separator_menu_item_new(); } - else if (mitem->GetBitmap().Ok()) + else if ( mitem->GetBitmap().Ok() || + (mitem->GetKind() == wxITEM_NORMAL && + wxIsStockID(mitem->GetId())) ) { text = mitem->GetText(); - const wxBitmap *bitmap = &mitem->GetBitmap(); + wxBitmap bitmap(mitem->GetBitmap()); menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) ); GtkWidget *image; - if (bitmap->HasPixbuf()) + if ( !bitmap.Ok() ) { - image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf()); + // use stock bitmap for this item if available on the assumption + // that it never hurts to follow GTK+ conventions more closely + const char *stock = wxGetStockGtkID(mitem->GetId()); + image = stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU) + : NULL; } - else + else // we have a custom bitmap { - GdkPixmap *gdk_pixmap = bitmap->GetPixmap(); - GdkBitmap *gdk_bitmap = bitmap->GetMask() ? - bitmap->GetMask()->GetBitmap() : - (GdkBitmap*) NULL; - image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap ); + wxASSERT_MSG( mitem->GetKind() == wxITEM_NORMAL, + _T("only normal menu items can have bitmaps") ); + + if ( bitmap.HasPixbuf() ) + { + image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf()); + } + else + { + GdkPixmap *gdk_pixmap = bitmap.GetPixmap(); + GdkBitmap *gdk_bitmap = bitmap.GetMask() ? + bitmap.GetMask()->GetBitmap() : + (GdkBitmap*) NULL; + image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap ); + } } - gtk_widget_show(image); + if ( image ) + { + gtk_widget_show(image); - gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image ); + gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image ); + } m_prevRadio = NULL; } else // a normal item { // text has "_" instead of "&" after mitem->SetText() so don't use it - text = mitem->GetText() ; + text = mitem->GetText() ; switch ( mitem->GetKind() ) { -- 2.7.4