]> git.saurik.com Git - wxWidgets.git/commitdiff
Remove flicker in Undo/Redo menus by only updating
authorJulian Smart <julian@anthemion.co.uk>
Tue, 18 Jun 2002 15:12:36 +0000 (15:12 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 18 Jun 2002 15:12:36 +0000 (15:12 +0000)
if we have some new text

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15876 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/cmdproc.cpp

index afdc6fff29acf7ef07a2e56433f60513c0b99888..4326cda8093744de433fed184961a292363e27ba 100644 (file)
@@ -220,6 +220,19 @@ void wxCommandProcessor::Initialize()
     SetMenuStrings();
 }
 
+// This reduces flicker in wxGTK+
+static void wxSetMenuLabelOptimally(wxMenu* menu, int id, const wxString& label)
+{
+    wxString oldLabel = menu->GetLabel(id);
+    oldLabel = wxStripMenuCodes(oldLabel.BeforeFirst('\t'));
+#ifdef __WXGTK__
+    oldLabel.Replace(wxT("_"), wxT("")); // GTK+ only
+#endif
+    wxString label1 = wxStripMenuCodes(label.BeforeFirst('\t'));
+    if (oldLabel != label1)
+        menu->SetLabel(id, label);
+}
+
 void wxCommandProcessor::SetMenuStrings()
 {
 #if wxUSE_MENUS
@@ -237,7 +250,9 @@ void wxCommandProcessor::SetMenuStrings()
             else
                 buf = wxString(_("Can't &Undo ")) + commandName + m_undoAccelerator;
 
-            m_commandEditMenu->SetLabel(wxID_UNDO, buf);
+            //m_commandEditMenu->SetLabel(wxID_UNDO, buf);
+            wxSetMenuLabelOptimally(m_commandEditMenu, wxID_UNDO, buf);
+            
             m_commandEditMenu->Enable(wxID_UNDO, canUndo);
 
             // We can redo, if we're not at the end of the history.
@@ -247,23 +262,23 @@ void wxCommandProcessor::SetMenuStrings()
                 wxString redoCommandName(redoCommand->GetName());
                 if (redoCommandName == wxT("")) redoCommandName = _("Unnamed command");
                 buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
-                m_commandEditMenu->SetLabel(wxID_REDO, buf);
+                wxSetMenuLabelOptimally(m_commandEditMenu, wxID_REDO, buf);
                 m_commandEditMenu->Enable(wxID_REDO, TRUE);
             }
             else
             {
-                m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo") + m_redoAccelerator);
+                wxSetMenuLabelOptimally(m_commandEditMenu, wxID_REDO, _("&Redo") + m_redoAccelerator);
                 m_commandEditMenu->Enable(wxID_REDO, FALSE);
             }
         }
         else
         {
-            m_commandEditMenu->SetLabel(wxID_UNDO, _("&Undo") + m_undoAccelerator);
+            wxSetMenuLabelOptimally(m_commandEditMenu, wxID_UNDO, _("&Undo") + m_undoAccelerator);
             m_commandEditMenu->Enable(wxID_UNDO, FALSE);
 
             if (m_commands.Number() == 0)
             {
-                m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo") + m_redoAccelerator);
+                wxSetMenuLabelOptimally(m_commandEditMenu, wxID_REDO, _("&Redo") + m_redoAccelerator);
                 m_commandEditMenu->Enable(wxID_REDO, FALSE);
             }
             else
@@ -274,7 +289,7 @@ void wxCommandProcessor::SetMenuStrings()
                 wxString redoCommandName(redoCommand->GetName());
                 if (redoCommandName == wxT("")) redoCommandName = _("Unnamed command");
                 buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
-                m_commandEditMenu->SetLabel(wxID_REDO, buf);
+                wxSetMenuLabelOptimally(m_commandEditMenu, wxID_REDO, buf);
                 m_commandEditMenu->Enable(wxID_REDO, TRUE);
             }
         }