/////////////////////////////////////////////////////////////////////////////
// Name: src/gtk/menu.cpp
-// Purpose:
+// Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#if wxUSE_MENUS
+
#include "wx/menu.h"
#ifndef WX_PRECOMP
static wxString wxReplaceUnderscore( const wxString& title )
{
- const wxChar *pc;
-
// GTK 1.2 wants to have "_" instead of "&" for accelerators
wxString str;
- pc = title;
- while (*pc != wxT('\0'))
+
+ for ( wxString::const_iterator pc = title.begin(); pc != title.end(); ++pc )
{
- if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
+ if ((*pc == wxT('&')) && (pc+1 != title.end()) && (*(pc+1) == wxT('&')))
{
// "&" is doubled to indicate "&" instead of accelerator
++pc;
str << *pc;
}
- ++pc;
}
// wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
{
- if (g_isIdle)
- wxapp_install_idle_handler();
-
event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler();
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_style = style;
- m_invokingWindow = (wxWindow*) NULL;
+ m_invokingWindow = NULL;
- if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
- !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
+ if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
+ !CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
{
wxFAIL_MSG( wxT("wxMenuBar creation failed") );
return;
if (style & wxMB_DOCKABLE)
{
m_widget = gtk_handle_box_new();
- gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
- gtk_widget_show( GTK_WIDGET(m_menubar) );
+ gtk_container_add(GTK_CONTAINER(m_widget), m_menubar);
+ gtk_widget_show(m_menubar);
}
else
{
- m_widget = GTK_WIDGET(m_menubar);
+ m_widget = m_menubar;
}
PostCreation();
extern "C" {
static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
{
- if (g_isIdle)
- wxapp_install_idle_handler();
-
int id = menu->FindMenuIdByMenuItem(widget);
/* should find it for normal (not popup) menu */
extern "C" {
static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
{
- if (g_isIdle) wxapp_install_idle_handler();
-
int id = menu->FindMenuIdByMenuItem(widget);
wxASSERT( id != -1 ); // should find it!
extern "C" {
static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
{
- if (g_isIdle) wxapp_install_idle_handler();
-
int id = menu->FindMenuIdByMenuItem(widget);
wxASSERT( id != -1 ); // should find it!
gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods);
if (accel_key != 0)
{
- gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem),
+ gtk_widget_remove_accelerator(m_menuItem,
m_parentMenu->m_accel,
accel_key,
accel_mods );
{
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
- gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem),
+ gtk_widget_remove_accelerator( m_menuItem,
m_parentMenu->m_accel,
accel_key,
accel_mods );
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
if (accel_key != 0)
{
- gtk_widget_add_accelerator( GTK_WIDGET(m_menuItem),
+ gtk_widget_add_accelerator( m_menuItem,
"activate",
m_parentMenu->m_accel,
accel_key,
{
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
- gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem),
+ gtk_widget_remove_accelerator( m_menuItem,
m_parentMenu->m_accel,
accel_key,
accel_mods );
wxString text;
// '\t' is the deliminator indicating a hot key
- const wxChar *pc = str;
- while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) )
+ wxString::const_iterator pc = str.begin();
+ while ( pc != str.end() && *pc != wxT('\t') )
{
- if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
- {
- // "&" is doubled to indicate "&" instead of accelerator
- ++pc;
- text << wxT('&');
- }
- else if (*pc == wxT('&'))
+ if (*pc == wxT('&'))
{
- text << wxT('_');
+ wxString::const_iterator next = pc + 1;
+ if (next != str.end() && *next == wxT('&'))
+ {
+ // "&" is doubled to indicate "&" instead of accelerator
+ ++pc;
+ text << wxT('&');
+ }
+ else
+ {
+ text << wxT('_');
+ }
}
else if ( *pc == wxT('_') ) // escape underscores
{
if(*pc == wxT('\t'))
{
pc++;
- *hotKey = pc;
+ hotKey->assign(pc, str.end());
}
}
{
// see wxMenu::Init
gtk_widget_unref( m_menu );
+ g_object_unref( m_accel );
+
// if the menu is inserted in another menu at this time, there was
// one more reference to it:
if ( m_owner )
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
if (accel_key != 0)
{
- gtk_widget_add_accelerator (GTK_WIDGET(menuItem),
+ gtk_widget_add_accelerator (menuItem,
"activate",
m_accel,
accel_key,
{
// if the accelerator was taken from a stock ID, just get it back from GTK+ stock
if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
- gtk_widget_add_accelerator( GTK_WIDGET(menuItem),
+ gtk_widget_add_accelerator( menuItem,
"activate",
m_accel,
accel_key,
}
#endif // __WXGTK20__
+
+#endif // wxUSE_MENUS