This is the same as r64127 for wxGTK.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64145
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
- // implementation only from now on
- void SetInvokingWindow( wxWindow *win );
- void UnsetInvokingWindow( wxWindow *win );
-
// common part of Append and Insert
bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1);
// common part of Append and Insert
bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1);
+ virtual void Attach(wxFrame *frame);
+ virtual void Detach();
+
GtkAccelGroup *m_accel;
GtkWidget *m_menubar;
long m_style;
GtkAccelGroup *m_accel;
GtkWidget *m_menubar;
long m_style;
- wxWindow *m_invokingWindow;
private:
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
private:
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
- m_frameMenuBar->UnsetInvokingWindow( this );
+ m_frameMenuBar->Attach( this );
if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
{
if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
{
- m_frameMenuBar->SetInvokingWindow( this );
-
m_frameMenuBar->SetParent(this);
gtk_pizza_put( GTK_PIZZA(m_mainWidget),
m_frameMenuBar->m_widget,
m_frameMenuBar->SetParent(this);
gtk_pizza_put( GTK_PIZZA(m_mainWidget),
m_frameMenuBar->m_widget,
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
menu_bar->m_widget,
0, 0, m_width, wxMENU_HEIGHT );
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
menu_bar->m_widget,
0, 0, m_width, wxMENU_HEIGHT );
- menu_bar->SetInvokingWindow(active_child_frame);
+ menu_bar->Attach(active_child_frame);
}
}
m_justInserted = false;
}
}
m_justInserted = false;
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
menu_bar->m_widget,
0, 0, m_width, wxMENU_HEIGHT );
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
menu_bar->m_widget,
0, 0, m_width, wxMENU_HEIGHT );
- menu_bar->SetInvokingWindow( child_frame );
+
+ // Attach() asserts if we call it for an already
+ // attached menu bar so don't do it if we're already
+ // associated with this frame (it would be nice to get
+ // rid of this check and ensure that this doesn't
+ // happen...)
+ if ( menu_bar->GetFrame() != child_frame )
+ menu_bar->Attach( child_frame );
}
visible_child_menu = true;
}
}
visible_child_menu = true;
}
{
if (menu_bar->Show(false))
{
{
if (menu_bar->Show(false))
{
- menu_bar->UnsetInvokingWindow( child_frame );
if (visible_child_menu)
{
m_frameMenuBar->Show( false );
if (visible_child_menu)
{
m_frameMenuBar->Show( false );
- m_frameMenuBar->UnsetInvokingWindow( this );
+ m_frameMenuBar->Detach();
}
else
{
m_frameMenuBar->Show( true );
}
else
{
m_frameMenuBar->Show( true );
- m_frameMenuBar->SetInvokingWindow( this );
+ m_frameMenuBar->Attach( this );
m_frameMenuBar->m_width = m_width;
m_frameMenuBar->m_height = wxMENU_HEIGHT;
m_frameMenuBar->m_width = m_width;
m_frameMenuBar->m_height = wxMENU_HEIGHT;
if (handler && handler->ProcessEvent(event))
return;
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win)
win->HandleWindowEvent( event );
}
if (win)
win->HandleWindowEvent( event );
}
// the parent window is known after wxFrame::SetMenu()
m_needParent = false;
m_style = 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") ))
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();
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
- wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
+ DetachFromFrame( menuitem->GetSubMenu(), win );
node = node->GetNext();
}
}
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();
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
- wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
+ AttachToFrame( menuitem->GetSubMenu(), win );
node = node->GetNext();
}
}
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();
wxWindow *top_frame = win;
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
while (node)
{
wxMenu *menu = node->GetData();
while (node)
{
wxMenu *menu = node->GetData();
- wxMenubarSetInvokingWindow( menu, win );
+ AttachToFrame( menu, win );
node = node->GetNext();
}
}
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 (top_frame->GetParent() && !(top_frame->IsTopLevel()))
top_frame = top_frame->GetParent();
while (node)
{
wxMenu *menu = node->GetData();
while (node)
{
wxMenu *menu = node->GetData();
- wxMenubarUnsetInvokingWindow( menu, win );
+ DetachFromFrame( menu, top_frame );
node = node->GetNext();
}
node = node->GetNext();
}
+
+ wxMenuBarBase::Detach();
}
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
}
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
GTK_SIGNAL_FUNC(gtk_menu_open_callback),
(gpointer)menu );
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)
- 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
// 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.
// see (and refactor :) similar code in Remove
// below.
- wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
-
- if( frame )
- frame->UpdateMenuBarSize();
+ m_menuBarFrame->UpdateMenuBarSize();
gtk_widget_destroy( menu->m_owner );
menu->m_owner = NULL;
gtk_widget_destroy( menu->m_owner );
menu->m_owner = NULL;
{
// OPTIMISE ME: see comment in GtkAppend
{
// OPTIMISE ME: see comment in GtkAppend
- wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
-
- if( frame )
- frame->UpdateMenuBarSize();
+ m_menuBarFrame->UpdateMenuBarSize();
int id = menu->FindMenuIdByMenuItem(widget);
/* should find it for normal (not popup) menu */
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))
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
// 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)
{
// should be fixed instead of working around it here...
if (frame)
{
if (handler && handler->ProcessEvent(event))
return;
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win) win->HandleWindowEvent( event );
}
}
if (win) win->HandleWindowEvent( event );
}
}
if (handler && handler->ProcessEvent(event))
return;
if (handler && handler->ProcessEvent(event))
return;
- wxWindow *win = menu->GetInvokingWindow();
+ wxWindow *win = menu->GetWindow();
if (win)
win->HandleWindowEvent( event );
}
if (win)
win->HandleWindowEvent( event );
}
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
gtk_widget_show( mitem->GetSubMenu()->m_menu );
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);