Use wxMenuBar::Attach/Detach() instead of SetInvokingWindow() in wxGTK1.
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
This commit is contained in:
@@ -37,17 +37,15 @@ public:
|
|||||||
virtual void SetMenuLabel( size_t pos, const wxString& label );
|
virtual void SetMenuLabel( size_t pos, const wxString& label );
|
||||||
virtual wxString GetMenuLabel( size_t pos ) const;
|
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
|
// common part of Append and Insert
|
||||||
bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1);
|
bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1);
|
||||||
|
|
||||||
|
virtual void Attach(wxFrame *frame);
|
||||||
|
virtual void Detach();
|
||||||
|
|
||||||
GtkAccelGroup *m_accel;
|
GtkAccelGroup *m_accel;
|
||||||
GtkWidget *m_menubar;
|
GtkWidget *m_menubar;
|
||||||
long m_style;
|
long m_style;
|
||||||
wxWindow *m_invokingWindow;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
|
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
|
||||||
|
@@ -552,7 +552,7 @@ void wxFrame::DetachMenuBar()
|
|||||||
|
|
||||||
if ( m_frameMenuBar )
|
if ( m_frameMenuBar )
|
||||||
{
|
{
|
||||||
m_frameMenuBar->UnsetInvokingWindow( this );
|
m_frameMenuBar->Attach( this );
|
||||||
|
|
||||||
if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
|
if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
|
||||||
{
|
{
|
||||||
@@ -577,8 +577,6 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
|
|||||||
|
|
||||||
if (m_frameMenuBar)
|
if (m_frameMenuBar)
|
||||||
{
|
{
|
||||||
m_frameMenuBar->SetInvokingWindow( this );
|
|
||||||
|
|
||||||
m_frameMenuBar->SetParent(this);
|
m_frameMenuBar->SetParent(this);
|
||||||
gtk_pizza_put( GTK_PIZZA(m_mainWidget),
|
gtk_pizza_put( GTK_PIZZA(m_mainWidget),
|
||||||
m_frameMenuBar->m_widget,
|
m_frameMenuBar->m_widget,
|
||||||
|
@@ -178,7 +178,7 @@ void wxMDIParentFrame::OnInternalIdle()
|
|||||||
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
|
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
|
||||||
menu_bar->m_widget,
|
menu_bar->m_widget,
|
||||||
0, 0, m_width, wxMENU_HEIGHT );
|
0, 0, m_width, wxMENU_HEIGHT );
|
||||||
menu_bar->SetInvokingWindow(active_child_frame);
|
menu_bar->Attach(active_child_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_justInserted = false;
|
m_justInserted = false;
|
||||||
@@ -209,7 +209,14 @@ void wxMDIParentFrame::OnInternalIdle()
|
|||||||
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
|
gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
|
||||||
menu_bar->m_widget,
|
menu_bar->m_widget,
|
||||||
0, 0, m_width, wxMENU_HEIGHT );
|
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;
|
||||||
}
|
}
|
||||||
@@ -217,7 +224,7 @@ void wxMDIParentFrame::OnInternalIdle()
|
|||||||
{
|
{
|
||||||
if (menu_bar->Show(false))
|
if (menu_bar->Show(false))
|
||||||
{
|
{
|
||||||
menu_bar->UnsetInvokingWindow( child_frame );
|
menu_bar->Detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,12 +240,12 @@ void wxMDIParentFrame::OnInternalIdle()
|
|||||||
if (visible_child_menu)
|
if (visible_child_menu)
|
||||||
{
|
{
|
||||||
m_frameMenuBar->Show( false );
|
m_frameMenuBar->Show( false );
|
||||||
m_frameMenuBar->UnsetInvokingWindow( this );
|
m_frameMenuBar->Detach();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_frameMenuBar->Show( true );
|
m_frameMenuBar->Show( true );
|
||||||
m_frameMenuBar->SetInvokingWindow( this );
|
m_frameMenuBar->Attach( this );
|
||||||
|
|
||||||
m_frameMenuBar->m_width = m_width;
|
m_frameMenuBar->m_width = m_width;
|
||||||
m_frameMenuBar->m_height = wxMENU_HEIGHT;
|
m_frameMenuBar->m_height = wxMENU_HEIGHT;
|
||||||
|
@@ -141,7 +141,7 @@ static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
|
|||||||
if (handler && handler->ProcessEvent(event))
|
if (handler && handler->ProcessEvent(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxWindow *win = menu->GetInvokingWindow();
|
wxWindow *win = menu->GetWindow();
|
||||||
if (win)
|
if (win)
|
||||||
win->HandleWindowEvent( event );
|
win->HandleWindowEvent( event );
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,6 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st
|
|||||||
// the parent window is known after wxFrame::SetMenu()
|
// the parent window is known after wxFrame::SetMenu()
|
||||||
m_needParent = false;
|
m_needParent = false;
|
||||||
m_style = style;
|
m_style = style;
|
||||||
m_invokingWindow = NULL;
|
|
||||||
|
|
||||||
if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
|
if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
|
||||||
!CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
|
!CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
|
||||||
@@ -241,10 +240,8 @@ wxMenuBar::~wxMenuBar()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
|
static void DetachFromFrame( wxMenu *menu, wxWindow *win )
|
||||||
{
|
{
|
||||||
menu->SetInvokingWindow( NULL );
|
|
||||||
|
|
||||||
wxWindow *top_frame = win;
|
wxWindow *top_frame = win;
|
||||||
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
||||||
top_frame = top_frame->GetParent();
|
top_frame = top_frame->GetParent();
|
||||||
@@ -257,15 +254,13 @@ static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
|
|||||||
{
|
{
|
||||||
wxMenuItem *menuitem = node->GetData();
|
wxMenuItem *menuitem = node->GetData();
|
||||||
if (menuitem->IsSubMenu())
|
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;
|
wxWindow *top_frame = win;
|
||||||
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
||||||
top_frame = top_frame->GetParent();
|
top_frame = top_frame->GetParent();
|
||||||
@@ -280,14 +275,15 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
|
|||||||
{
|
{
|
||||||
wxMenuItem *menuitem = node->GetData();
|
wxMenuItem *menuitem = node->GetData();
|
||||||
if (menuitem->IsSubMenu())
|
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;
|
wxWindow *top_frame = win;
|
||||||
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
||||||
top_frame = top_frame->GetParent();
|
top_frame = top_frame->GetParent();
|
||||||
@@ -301,15 +297,14 @@ void wxMenuBar::SetInvokingWindow( wxWindow *win )
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxMenu *menu = node->GetData();
|
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 = m_menuBarFrame;
|
||||||
wxWindow *top_frame = win;
|
|
||||||
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
|
||||||
top_frame = top_frame->GetParent();
|
top_frame = top_frame->GetParent();
|
||||||
|
|
||||||
@@ -320,9 +315,11 @@ void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxMenu *menu = node->GetData();
|
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 )
|
||||||
@@ -370,11 +367,9 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
|
|||||||
GTK_SIGNAL_FUNC(gtk_menu_open_callback),
|
GTK_SIGNAL_FUNC(gtk_menu_open_callback),
|
||||||
(gpointer)menu );
|
(gpointer)menu );
|
||||||
|
|
||||||
// m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
|
if (m_menuBarFrame)
|
||||||
// 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
|
// OPTIMISE ME: we should probably cache this, or pass it
|
||||||
// directly, but for now this is a minimal
|
// directly, but for now this is a minimal
|
||||||
@@ -382,10 +377,7 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
|
|||||||
// see (and refactor :) similar code in Remove
|
// see (and refactor :) similar code in Remove
|
||||||
// below.
|
// below.
|
||||||
|
|
||||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
m_menuBarFrame->UpdateMenuBarSize();
|
||||||
|
|
||||||
if( frame )
|
|
||||||
frame->UpdateMenuBarSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -429,13 +421,10 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
|||||||
gtk_widget_destroy( menu->m_owner );
|
gtk_widget_destroy( menu->m_owner );
|
||||||
menu->m_owner = NULL;
|
menu->m_owner = NULL;
|
||||||
|
|
||||||
if (m_invokingWindow)
|
if (m_menuBarFrame)
|
||||||
{
|
{
|
||||||
// OPTIMISE ME: see comment in GtkAppend
|
// OPTIMISE ME: see comment in GtkAppend
|
||||||
wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
|
m_menuBarFrame->UpdateMenuBarSize();
|
||||||
|
|
||||||
if( frame )
|
|
||||||
frame->UpdateMenuBarSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
@@ -578,7 +567,7 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
int id = menu->FindMenuIdByMenuItem(widget);
|
int id = menu->FindMenuIdByMenuItem(widget);
|
||||||
|
|
||||||
/* should find it for normal (not popup) menu */
|
/* 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") );
|
wxT("menu item not found in gtk_menu_clicked_callback") );
|
||||||
|
|
||||||
if (!menu->IsEnabled(id))
|
if (!menu->IsEnabled(id))
|
||||||
@@ -619,7 +608,7 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
|
|
||||||
// FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
|
// FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
|
||||||
// normally wxMenu::SendEvent() should be enough, if it doesn't work
|
// 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...
|
// should be fixed instead of working around it here...
|
||||||
if (frame)
|
if (frame)
|
||||||
{
|
{
|
||||||
@@ -665,7 +654,7 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
if (handler && handler->ProcessEvent(event))
|
if (handler && handler->ProcessEvent(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxWindow *win = menu->GetInvokingWindow();
|
wxWindow *win = menu->GetWindow();
|
||||||
if (win) win->HandleWindowEvent( event );
|
if (win) win->HandleWindowEvent( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,7 +682,7 @@ static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
|
|||||||
if (handler && handler->ProcessEvent(event))
|
if (handler && handler->ProcessEvent(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxWindow *win = menu->GetInvokingWindow();
|
wxWindow *win = menu->GetWindow();
|
||||||
if (win)
|
if (win)
|
||||||
win->HandleWindowEvent( event );
|
win->HandleWindowEvent( event );
|
||||||
}
|
}
|
||||||
@@ -1091,12 +1080,6 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
|||||||
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
|
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
|
||||||
|
|
||||||
gtk_widget_show( 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
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user