From c7f1a920b1aeaa6760da4c99fd533ee01d5081b8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 20 Jul 2014 15:28:20 +0000 Subject: [PATCH] supporting menu dimension retrieval for menubars, fixes #2570 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76943 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/core/private.h | 5 +++++ include/wx/osx/menu.h | 5 +++++ src/osx/cocoa/menu.mm | 11 ++++++++++- src/osx/menu_osx.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 5f45f0ccd1..fec62fa63e 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -202,6 +202,11 @@ public : wxMenu* GetWXPeer() { return m_peer ; } virtual void PopUp( wxWindow *win, int x, int y ) = 0; + + virtual void GetMenuBarDimensions(int &x, int &y, int &width, int &height) const + { + x = y = width = height = -1; + } static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); static wxMenuImpl* CreateRootMenu( wxMenu* peer ); diff --git a/include/wx/osx/menu.h b/include/wx/osx/menu.h index 9eded8593b..8906eb3365 100644 --- a/include/wx/osx/menu.h +++ b/include/wx/osx/menu.h @@ -160,6 +160,11 @@ public: static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; } + + virtual void DoGetPosition(int *x, int *y) const; + virtual void DoGetSize(int *width, int *height) const; + virtual void DoGetClientSize(int *width, int *height) const; + protected: // common part of all ctors void Init(); diff --git a/src/osx/cocoa/menu.mm b/src/osx/cocoa/menu.mm index fd03afd950..1e77373e5a 100644 --- a/src/osx/cocoa/menu.mm +++ b/src/osx/cocoa/menu.mm @@ -253,7 +253,16 @@ public : [popUpButtonCell performClickWithFrame:frame inView:view]; [popUpButtonCell release]; } - + + virtual void GetMenuBarDimensions(int &x, int &y, int &width, int &height) const wxOVERRIDE + { + NSRect r = [(NSScreen*)[[NSScreen screens] objectAtIndex:0] frame]; + height = [m_osxMenu menuBarHeight]; + x = r.origin.x; + y = r.origin.y; + width = r.size.width; + } + WXHMENU GetHMenu() wxOVERRIDE { return m_osxMenu; } static wxMenuImpl* Create( wxMenu* peer, const wxString& title ); diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 0b4b1fc296..5a15d80071 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -1022,4 +1022,34 @@ void wxMenuBar::Attach(wxFrame *frame) wxMenuBarBase::Attach( frame ) ; } +void wxMenuBar::DoGetPosition(int *x, int *y) const +{ + int _x,_y,_width,_height; + + m_rootMenu->GetPeer()->GetMenuBarDimensions(_x, _y, _width, _height); + + if (x) + *x = _x; + if (y) + *y = _y; +} + +void wxMenuBar::DoGetSize(int *width, int *height) const +{ + int _x,_y,_width,_height; + + m_rootMenu->GetPeer()->GetMenuBarDimensions(_x, _y, _width, _height); + + if (width) + *width = _width; + if (height) + *height = _height; +} + +void wxMenuBar::DoGetClientSize(int *width, int *height) const +{ + DoGetSize(width, height); +} + + #endif // wxUSE_MENUS