// popup menu and reset after it's hidden. Notice that you probably want to
// use GetWindow() below instead of GetInvokingWindow() as the latter only
// returns non-NULL for the top level menus
+ //
+ // NB: avoid calling SetInvokingWindow() directly if possible, use
+ // wxMenuInvokingWindowSetter class below instead
void SetInvokingWindow(wxWindow *win);
wxWindow *GetInvokingWindow() const { return m_invokingWindow; }
#endif
#endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
+// ----------------------------------------------------------------------------
+// Helper class used in the implementation only: sets the invoking window of
+// the given menu in its ctor and resets it in dtor.
+// ----------------------------------------------------------------------------
+
+class wxMenuInvokingWindowSetter
+{
+public:
+ // Ctor sets the invoking window for the given menu.
+ //
+ // The menu lifetime must be greater than that of this class.
+ wxMenuInvokingWindowSetter(wxMenu& menu, wxWindow *win)
+ : m_menu(menu)
+ {
+ menu.SetInvokingWindow(win);
+ }
+
+ // Dtor resets the invoking window.
+ ~wxMenuInvokingWindowSetter()
+ {
+ m_menu.SetInvokingWindow(NULL);
+ }
+
+private:
+ wxMenu& m_menu;
+
+ wxDECLARE_NO_COPY_CLASS(wxMenuInvokingWindowSetter);
+};
+
#endif // wxUSE_MENUS
-#endif
- // _WX_MENU_H_BASE_
+#endif // _WX_MENU_H_BASE_
bool wxTaskBarIconCustomStatusItemImpl::PopupMenu(wxMenu *menu)
{
- wxASSERT(menu);
- menu->SetInvokingWindow(m_iconWindow);
+ wxCHECK_MSG(menu, false, "can't popup a NULL menu");
+
+ wxMenuInvokingWindowSetter setInvokingWin(*menu, m_iconWindow);
menu->UpdateUI();
if([m_cocoaNSStatusItem respondsToSelector:@selector(popUpStatusItemMenu:)])
eventNumber:0 clickCount:1 pressure:0.0];
[NSMenu popUpContextMenu:menu->GetNSMenu() withEvent:nsevent forView:m_iconWindow->GetNSView()];
}
- menu->SetInvokingWindow(NULL);
return true;
}
{
wxCHECK_MSG( menu, false, "can't popup NULL menu" );
+ wxMenuInvokingWindowSetter
+ setInvokingWin(*menu, static_cast<wxWindow *>(this));
+
wxCurrentPopupMenu = menu;
const bool rc = DoPopupMenu(menu, x, y);
wxCurrentPopupMenu = NULL;
{
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
- wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
-
- menu->SetInvokingWindow( this );
-
menu->UpdateUI();
wxPoint pos;
gtk_main_iteration();
}
- menu->SetInvokingWindow( NULL );
-
return true;
}
*is_waiting = false;
}
-WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )
-{
- menu->SetInvokingWindow( win );
-
- wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
- while (node)
- {
- wxMenuItem *menuitem = node->GetData();
- if (menuitem->IsSubMenu())
- {
- SetInvokingWindow( menuitem->GetSubMenu(), win );
- }
-
- node = node->GetNext();
- }
-}
-
extern "C" WXDLLIMPEXP_CORE
void wxPopupMenuPositionCallback( GtkMenu *menu,
gint *x, gint *y,
// the same code in taskbar.cpp as well. This
// is ugly code duplication, I know.
- SetInvokingWindow( menu, this );
-
menu->UpdateUI();
bool is_waiting = true;
menu->SetId(1); /* Mark as popped-up */
menu->CreateMenu(NULL, widget, menu, 0);
- menu->SetInvokingWindow(this);
menu->UpdateUI();
bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y)
{
- menu->SetInvokingWindow(this);
menu->UpdateUI();
if ( x == wxDefaultCoord && y == wxDefaultCoord )
// for example) and so we do need to process the event immediately
wxYieldForCommandsOnly();
- menu->SetInvokingWindow(NULL);
-
return true;
}
bool bIsWaiting = true;
int nHeight;
- pMenu->SetInvokingWindow(this);
pMenu->UpdateUI();
if ( nX == -1 && nY == -1 )
::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
}
- pMenu->SetInvokingWindow(NULL);
return true;
} // end of wxWindowOS2::DoPopupMenu
#endif // wxUSE_MENUS_NATIVE
{
public:
wxBlindPlateWindow() { Init(); }
-
+
// Old-style constructor (no default values for coordinates to avoid
// ambiguity with the new one)
wxBlindPlateWindow(wxWindow *parent,
const wxString& name = wxPanelNameStr)
{
Init();
-
+
Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), style, name);
}
-
+
// Constructor
wxBlindPlateWindow(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxString& name = wxPanelNameStr)
{
Init();
-
+
Create(parent, winid, pos, size, style, name);
}
-
+
// Pseudo ctor
bool Create(wxWindow *parent,
wxWindowID winid = wxID_ANY,
{
if ( !wxWindow::Create(parent, winid, pos, size, style, name) )
return false;
-
+
// so that non-solid background renders correctly under GTK+:
SetThemeEnabled(true);
return true;
}
-
+
virtual ~wxBlindPlateWindow();
-
+
virtual bool AcceptsFocus() const
{
return false;
}
-
+
protected:
// common part of all ctors
void Init()
{
}
-
+
DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow)
DECLARE_EVENT_TABLE()
};
m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
#endif
-
+
switch ( variant )
{
case wxWINDOW_VARIANT_NORMAL :
{
if ( !wxWindowBase::SetBackgroundStyle(style) )
return false;
-
+
if ( m_peer )
m_peer->SetBackgroundStyle(style);
return true;
bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
{
#ifndef __WXUNIVERSAL__
- menu->SetInvokingWindow((wxWindow*)this);
menu->UpdateUI();
if ( x == wxDefaultCoord && y == wxDefaultCoord )
ClientToScreen( &x , &y ) ;
}
menu->GetPeer()->PopUp(this, x, y);
- menu->SetInvokingWindow( NULL );
return true;
#else
// actually this shouldn't be called, because universal is having its own implementation
if ( m_tooltip )
m_tooltip->SetWindow(this);
-
+
if (m_peer)
m_peer->SetToolTip(tooltip);
}
m_peer->SetVisibility( show ) ;
#ifdef __WXOSX_IPHONE__
- // only when there's no native event support
+ // only when there's no native event support
if ( !IsTopLevel() )
#endif
{
wxShowEvent eventShow(GetId(), show);
eventShow.SetEventObject(this);
-
+
HandleWindowEvent(eventShow);
}
-
+
return true;
}
if (child->IsTopLevel())
continue;
-
+
if ( !IsClientAreaChild(child) )
continue;
Update();
#endif // 0
- menu->SetInvokingWindow(this);
-
- // wxLogDebug( "Name of invoking window %s", menu->GetInvokingWindow()->GetName().c_str() );
-
menu->Popup(ClientToScreen(wxPoint(x, y)), wxSize(0,0));
// this is not very useful if the menu was popped up because of the mouse
// remove the handler
PopEventHandler(true /* delete it */);
- menu->SetInvokingWindow(NULL);
-
#ifdef __WXMSW__
SetCursor(cursorOld);
#endif // __WXMSW__