// Name: src/gtk1/menu.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#endif // wxUSE_ACCEL
#include "wx/gtk1/private.h"
+#include "wx/gtk1/private/mnemonics.h"
#include <gdk/gdkkeysyms.h>
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win)
win->HandleWindowEvent( event );
}
// wxMenuBar
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
-
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 = NULL;
if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
!CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
{
}
-static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
+static void DetachFromFrame( wxMenu *menu, wxWindow *win )
{
- menu->SetInvokingWindow( NULL );
-
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
- wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
+ DetachFromFrame( menuitem->GetSubMenu(), win );
node = node->GetNext();
}
}
-static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
+static void AttachToFrame( wxMenu *menu, wxWindow *win )
{
- menu->SetInvokingWindow( win );
-
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
- wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
+ AttachToFrame( menuitem->GetSubMenu(), win );
node = node->GetNext();
}
}
-void wxMenuBar::SetInvokingWindow( wxWindow *win )
+void wxMenuBar::Attach( wxFrame *win )
{
- m_invokingWindow = win;
+ wxMenuBarBase::Attach(win);
+
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
while (node)
{
wxMenu *menu = node->GetData();
- wxMenubarSetInvokingWindow( menu, win );
+ AttachToFrame( menu, win );
node = node->GetNext();
}
}
-void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
+void wxMenuBar::Detach()
{
- m_invokingWindow = NULL;
- wxWindow *top_frame = win;
+ wxWindow *top_frame = m_menuBarFrame;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
while (node)
{
wxMenu *menu = node->GetData();
- wxMenubarUnsetInvokingWindow( menu, win );
+ DetachFromFrame( menu, top_frame );
node = node->GetNext();
}
+
+ wxMenuBarBase::Detach();
}
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
GTK_SIGNAL_FUNC(gtk_menu_open_callback),
(gpointer)menu );
- // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
- // addings menu later on.
- if (m_invokingWindow)
+ if (m_menuBarFrame)
{
- wxMenubarSetInvokingWindow( menu, m_invokingWindow );
+ AttachToFrame( menu, m_menuBarFrame );
// OPTIMISE ME: we should probably cache this, or pass it
// directly, but for now this is a minimal
// see (and refactor :) similar code in Remove
// below.
- wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
-
- if( frame )
- frame->UpdateMenuBarSize();
+ m_menuBarFrame->UpdateMenuBarSize();
}
return true;
gtk_widget_destroy( menu->m_owner );
menu->m_owner = NULL;
- if (m_invokingWindow)
+ if (m_menuBarFrame)
{
// OPTIMISE ME: see comment in GtkAppend
- wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
-
- if( frame )
- frame->UpdateMenuBarSize();
+ m_menuBarFrame->UpdateMenuBarSize();
}
return menu;
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
{
- if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelText(menuString))
+ if (wxMenuItem::GetLabelText(menu->GetTitle()) == wxMenuItem::GetLabelText(menuString))
{
int res = menu->FindItem( itemString );
if (res != wxNOT_FOUND)
wxMenu* menu = node->GetData();
- return wxConvertFromGTKToWXLabel(menu->GetTitle());
+ return menu->GetTitle();
}
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
int id = menu->FindMenuIdByMenuItem(widget);
/* should find it for normal (not popup) menu */
- wxASSERT_MSG( (id != -1) || (menu->GetInvokingWindow() != NULL),
+ wxASSERT_MSG( (id != -1) || (menu->GetWindow() != NULL),
wxT("menu item not found in gtk_menu_clicked_callback") );
if (!menu->IsEnabled(id))
// FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
// normally wxMenu::SendEvent() should be enough, if it doesn't work
- // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
+ // in wxGTK then we have a bug in wxMenu::GetWindow() which
// should be fixed instead of working around it here...
if (frame)
{
// If it is attached then let the frame send the event.
// Don't call frame->ProcessCommand(id) because it toggles
// checkable items and we've already done that above.
- wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
+ wxCommandEvent commandEvent(wxEVT_MENU, id);
commandEvent.SetEventObject(frame);
if (item->IsCheckable())
commandEvent.SetInt(item->IsChecked());
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win) win->HandleWindowEvent( event );
}
}
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win)
win->HandleWindowEvent( event );
}
// wxMenuItem
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
-
wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
int id,
const wxString& name,
// wxMenu
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
-
void wxMenu::Init()
{
m_accel = gtk_accel_group_new();
}
}
+wxString wxMenu::GetTitle() const
+{
+ return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
+}
+
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{
GtkWidget *menuItem;
// TODO
menuItem = gtk_menu_item_new();
}
- else if (mitem->GetBitmap().Ok())
+ else if (mitem->GetBitmap().IsOk())
{
text = mitem->wxMenuItemBase::GetItemLabel();
const wxBitmap *bitmap = &mitem->GetBitmap();
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
gtk_widget_show( mitem->GetSubMenu()->m_menu );
-
- // if adding a submenu to a menu already existing in the menu bar, we
- // must set invoking window to allow processing events from this
- // submenu
- if ( m_invokingWindow )
- wxMenubarSetInvokingWindow(mitem->GetSubMenu(), m_invokingWindow);
}
else
{