]> git.saurik.com Git - wxWidgets.git/commitdiff
added stock menu items support
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Aug 2006 22:24:57 +0000 (22:24 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Aug 2006 22:24:57 +0000 (22:24 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
samples/menu/menu.cpp
src/gtk/menu.cpp

index f1f9a753b77206cfa9d84698478bfbf54ccb64c9..e80105aeffe721238ce7db4740fbe9ee9a45f702 100644 (file)
@@ -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
 -----
index c956f21df5d08e365b03498a8aa5875bde5ef9c3..6d19fa4af40222acda5de9646a53d8d1e21d14b4 100644 (file)
@@ -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;
index f27623a98089824be06b8ac7edaeeec5fffab133..f11a1571d57c29bbdac581ddbbdd3c95d9017b78 100644 (file)
@@ -23,6 +23,7 @@
     #include "wx/accel.h"
 #endif // wxUSE_ACCEL
 
+#include "wx/stockitem.h"
 #include "wx/gtk/private.h"
 
 #include <gdk/gdkkeysyms.h>
@@ -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() )
         {