[Libreoffice-commits] core.git: include/vcl vcl/source

Jan Holesovsky kendy at collabora.com
Tue Sep 9 02:02:29 PDT 2014


 include/vcl/menu.hxx       |   11 +++++-
 vcl/source/window/menu.cxx |   75 ++++++++++++++++++++++-----------------------
 2 files changed, 47 insertions(+), 39 deletions(-)

New commits:
commit e2e2b03b185639e72669b50b674e5feec5e706cd
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 9 10:10:53 2014 +0200

    vcl: Virtual functions do not work in constructors, avoid IsMenuBar() there.
    
    Actually, this cleans this up further - Menu is an abstract class, so make its
    constructor protected; which allows us to move the native menu construction
    accordingly.
    
    Change-Id: I774cf4ed0cd62b54074fa287d1a7192aced7efee

diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index 741ed21..98bf847 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -153,7 +153,6 @@ private:
     SalMenu*            mpSalMenu;
 
 protected:
-    SAL_DLLPRIVATE void             ImplInit();
     SAL_DLLPRIVATE void             ImplLoadRes( const ResId& rResId );
     SAL_DLLPRIVATE Menu*            ImplGetStartMenu();
     SAL_DLLPRIVATE Menu*            ImplFindSelectMenu();
@@ -203,8 +202,16 @@ public:
     SAL_DLLPRIVATE Window*  ImplGetWindow() const { return pWindow; }
     void ImplSelectWithStart( Menu* pStartMenu = NULL );
 
+protected:
+
+    /** The Menu constructor is protected.
+
+    The callers are supposed to instantiate either PopupMenu or MenuBar, but
+    not a Menu directly.
+    */
+    Menu();
+
 public:
-                        Menu();
     virtual             ~Menu();
 
     virtual void        Activate();
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 56a1d5d..9e81810 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -111,8 +111,22 @@ static void ImplSetMenuItemData( MenuItemData* pData )
 }
 
 Menu::Menu()
+    : mpFirstDel(NULL),
+      pItemList(new MenuItemList),
+      pLogo(NULL),
+      pStartedFrom(NULL),
+      pWindow(NULL),
+      nEventId(0),
+      mnHighlightedItemPos(ITEMPOS_INVALID),
+      nMenuFlags(0),
+      nDefaultItem(0),
+      nSelectedId(0),
+      bCanceled(false),
+      bInCallback(false),
+      bKilled(false),
+      mpLayoutData(NULL),
+      mpSalMenu(NULL)
 {
-    ImplInit();
 }
 
 Menu::~Menu()
@@ -161,27 +175,6 @@ Menu::~Menu()
     ImplSetSalMenu( NULL );
 }
 
-void Menu::ImplInit()
-{
-    mnHighlightedItemPos = ITEMPOS_INVALID;
-    mpSalMenu       = NULL;
-    nMenuFlags      = 0;
-    nDefaultItem    = 0;
-    nSelectedId     = 0;
-    pItemList       = new MenuItemList;
-    pLogo           = NULL;
-    pStartedFrom    = NULL;
-    pWindow         = NULL;
-    nEventId        = 0;
-    bCanceled       = false;
-    bInCallback     = false;
-    bKilled         = false;
-    mpLayoutData    = NULL;
-    mpFirstDel      = NULL;         // Dtor notification list
-    // Native-support: returns NULL if not supported
-    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(IsMenuBar(), this);
-}
-
 void Menu::ImplLoadRes( const ResId& rResId )
 {
     ResMgr* pMgr = rResId.GetResMgr();
@@ -2472,21 +2465,25 @@ void Menu::HighlightItem( sal_uInt16 nItemPos )
 
 // - MenuBar -
 
-MenuBar::MenuBar() : Menu()
+MenuBar::MenuBar()
+    : Menu(),
+      mbCloserVisible(false),
+      mbFloatBtnVisible(false),
+      mbHideBtnVisible(false),
+      mbDisplayable(true)
 {
-    mbDisplayable       = true;
-    mbCloserVisible     = false;
-    mbFloatBtnVisible   = false;
-    mbHideBtnVisible    = false;
+    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
 }
 
-MenuBar::MenuBar( const MenuBar& rMenu ) : Menu()
+MenuBar::MenuBar( const MenuBar& rMenu )
+    : Menu(),
+      mbCloserVisible(false),
+      mbFloatBtnVisible(false),
+      mbHideBtnVisible(false),
+      mbDisplayable(true)
 {
-    mbDisplayable       = true;
-    mbCloserVisible     = false;
-    mbFloatBtnVisible   = false;
-    mbHideBtnVisible    = false;
-    *this               = rMenu;
+    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
+    *this = rMenu;
 }
 
 MenuBar::~MenuBar()
@@ -2694,19 +2691,23 @@ bool MenuBar::HandleMenuButtonEvent( Menu *, sal_uInt16 i_nButtonId ) const
 // bool PopupMenu::bAnyPopupInExecute = false;
 
 PopupMenu::PopupMenu()
+    : pRefAutoSubMenu(NULL)
 {
-    pRefAutoSubMenu = NULL;
+    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
 }
 
 PopupMenu::PopupMenu( const ResId& rResId )
+    : pRefAutoSubMenu(NULL)
 {
-    pRefAutoSubMenu = NULL;
+    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
     ImplLoadRes( rResId );
 }
 
-PopupMenu::PopupMenu( const PopupMenu& rMenu ) : Menu()
+PopupMenu::PopupMenu( const PopupMenu& rMenu )
+    : Menu(),
+      pRefAutoSubMenu(NULL)
 {
-    pRefAutoSubMenu = NULL;
+    mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
     *this = rMenu;
 }
 


More information about the Libreoffice-commits mailing list