/////////////////////////////////////////////////////////////////////////////
-// Name: menu.cpp
+// Name: src/gtk1/menu.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
#include "wx/wxprec.h"
#include "wx/menu.h"
-#include "wx/log.h"
-#include "wx/intl.h"
-#include "wx/app.h"
-#include "wx/bitmap.h"
+#include "wx/stockitem.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/app.h"
+ #include "wx/bitmap.h"
+#endif
#if wxUSE_ACCEL
#include "wx/accel.h"
void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style)
{
// the parent window is known after wxFrame::SetMenu()
- m_needParent = FALSE;
+ m_needParent = false;
m_style = style;
m_invokingWindow = (wxWindow*) NULL;
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
if ( !wxMenuBarBase::Append( menu, title ) )
- return FALSE;
+ return false;
return GtkAppend(menu, title);
}
frame->UpdateMenuBarSize();
}
- return TRUE;
+ return true;
}
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
if ( !wxMenuBarBase::Insert(pos, menu, title) )
- return FALSE;
+ return false;
// TODO
if ( !GtkAppend(menu, title, (int)pos) )
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
return label;
}
-void wxMenuItem::SetText( const wxString& str )
+void wxMenuItem::SetText( const wxString& string )
{
+ wxString str = string;
+ if ( str.empty() && !IsSeparator() )
+ {
+ wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?"));
+ str = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR |
+ wxSTOCK_WITH_MNEMONIC);
+ }
+
// Some optimization to avoid flicker
wxString oldLabel = m_text;
oldLabel = wxStripMenuCodes(oldLabel);
- oldLabel.Replace(wxT("_"), wxT(""));
+ oldLabel.Replace(wxT("_"), wxEmptyString);
wxString label1 = wxStripMenuCodes(str);
wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format
wxCharBuffer oldbuf = wxGTK_CONV( GetGtkHotKey(*this) ); // and as <control>foo
++pc;
}
- m_hotKey = wxT("");
+ m_hotKey = wxEmptyString;
if(*pc == wxT('\t'))
{
pc++;
m_hotKey = pc;
}
-
- // wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() );
}
#if wxUSE_ACCEL
return (wxAcceleratorEntry *)NULL;
}
- // as wxGetAccelFromString() looks for TAB, insert a dummy one here
+ // accelerator parsing code looks for them after a TAB, so insert a dummy
+ // one here
wxString label;
label << wxT('\t') << GetHotKey();
- return wxGetAccelFromString(label);
+ return wxAcceleratorEntry::Create(label);
}
#endif // wxUSE_ACCEL
bool wxMenuItem::IsChecked() const
{
- wxCHECK_MSG( m_menuItem, FALSE, wxT("invalid menu item") );
+ wxCHECK_MSG( m_menuItem, false, wxT("invalid menu item") );
- wxCHECK_MSG( IsCheckable(), FALSE,
+ wxCHECK_MSG( IsCheckable(), false,
wxT("can't get state of uncheckable item!") );
return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
GtkWidget *menuItem;
wxString text;
- GtkLabel* label;
+ GtkLabel* label = NULL;
if ( mitem->IsSeparator() )
{
text = mitem->GetText();
const wxBitmap *bitmap = &mitem->GetBitmap();
- // TODO
+ // TODO
wxUnusedVar(bitmap);
menuItem = gtk_menu_item_new_with_label( wxGTK_CONV( text ) );
label = GTK_LABEL( GTK_BIN(menuItem)->child );
// gtk_widget_lock_accelerators(mitem->GetMenuItem());
}
- return TRUE;
+ return true;
}
wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
hotkey << wxT("Down" );
break;
case WXK_PAGEUP:
- case WXK_PRIOR:
- hotkey << wxT("Prior" );
+ hotkey << wxT("PgUp" );
break;
case WXK_PAGEDOWN:
- case WXK_NEXT:
- hotkey << wxT("Next" );
+ hotkey << wxT("PgDn" );
break;
case WXK_LEFT:
hotkey << wxT("Left" );
case WXK_NUMPAD_DOWN:
hotkey << wxT("KP_Down" );
break;
- case WXK_NUMPAD_PRIOR: case WXK_NUMPAD_PAGEUP:
- hotkey << wxT("KP_Prior" );
+ case WXK_NUMPAD_PAGEUP:
+ hotkey << wxT("KP_PgUp" );
break;
- case WXK_NUMPAD_NEXT: case WXK_NUMPAD_PAGEDOWN:
- hotkey << wxT("KP_Next" );
+ case WXK_NUMPAD_PAGEDOWN:
+ hotkey << wxT("KP_PgDn" );
break;
case WXK_NUMPAD_END:
hotkey << wxT("KP_End" );
hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
break;
*/
- // if there are any other keys wxGetAccelFromString() may
+ // if there are any other keys wxAcceleratorEntry::Create() may
// return, we should process them here
default:
extern "C" WXDLLIMPEXP_CORE
void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
{
- *is_waiting = FALSE;
+ *is_waiting = false;
}
WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )
}
#endif // wxUSE_MENUS_NATIVE
-