diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-09-16 06:43:27 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-09-16 10:14:08 +0200 |
commit | fdffaef6ea21d165f1026940d5150a694dc85c46 (patch) | |
tree | a3d60620b68208a44afad8dd830211761fda7fbf /vcl | |
parent | d2d8cda6c2bf93149acbe9a04389d056709d7ed2 (diff) |
vcl menu: More abstraction around MenuBar to get dynamic_cast to one place.
Change-Id: Idbefee0e4230a3c75646e87143f5c3042221aee9
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/window/menu.cxx | 67 | ||||
-rw-r--r-- | vcl/source/window/menubarwindow.cxx | 12 | ||||
-rw-r--r-- | vcl/source/window/menubarwindow.hxx | 34 | ||||
-rw-r--r-- | vcl/source/window/menufloatingwindow.hxx | 2 | ||||
-rw-r--r-- | vcl/source/window/menuwindow.hxx | 35 |
5 files changed, 95 insertions, 55 deletions
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 01ee1626237b..28fb6fa687ff 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -2386,6 +2386,15 @@ void Menu::HighlightItem( sal_uInt16 nItemPos ) // - MenuBar - +IMenuBarWindow* MenuBar::getMenuBarWindow() +{ + // so far just a dynamic_cast, hopefully to be turned into something saner + // at some stage + IMenuBarWindow *pWin = dynamic_cast<IMenuBarWindow*>(pWindow); + assert(pWin); + return pWin; +} + MenuBar::MenuBar() : Menu(), mbCloseBtnVisible(false), @@ -2414,17 +2423,15 @@ MenuBar::~MenuBar() void MenuBar::ClosePopup(Menu *pMenu) { - MenuBarWindow* p = dynamic_cast<MenuBarWindow*>(ImplGetWindow()); - if (p) - p->PopupClosed(pMenu); + getMenuBarWindow()->PopupClosed(pMenu); } sal_uLong MenuBar::DeactivateMenuBar(sal_uLong nFocusId) { - nFocusId = dynamic_cast<MenuBarWindow*>(ImplGetWindow())->GetFocusId(); + nFocusId = getMenuBarWindow()->GetFocusId(); if (nFocusId) { - dynamic_cast<MenuBarWindow*>(ImplGetWindow())->SetFocusId(0); + getMenuBarWindow()->SetFocusId(0); ImplGetSVData()->maWinData.mbNoDeactivate = false; } @@ -2433,7 +2440,7 @@ sal_uLong MenuBar::DeactivateMenuBar(sal_uLong nFocusId) void MenuBar::MenuBarKeyInput(const KeyEvent& rEvent) { - ((MenuBarWindow*)(dynamic_cast<MenuBar*>(this))->ImplGetWindow())->KeyInput(rEvent); + pWindow->KeyInput(rEvent); } void MenuBar::ShowCloseButton(bool bShow) @@ -2450,8 +2457,7 @@ void MenuBar::ShowButtons( bool bClose, bool bFloat, bool bHide ) mbCloseBtnVisible = bClose; mbFloatBtnVisible = bFloat; mbHideBtnVisible = bHide; - if ( ImplGetWindow() ) - ((MenuBarWindow*)ImplGetWindow())->ShowButtons( bClose, bFloat, bHide ); + getMenuBarWindow()->ShowButtons(bClose, bFloat, bHide); } } @@ -2460,20 +2466,21 @@ void MenuBar::SetDisplayable( bool bDisplayable ) if( bDisplayable != mbDisplayable ) { mbDisplayable = bDisplayable; - MenuBarWindow* pMenuWin = (MenuBarWindow*) ImplGetWindow(); - if( pMenuWin ) - pMenuWin->ImplLayoutChanged(); + getMenuBarWindow()->LayoutChanged(); } } Window* MenuBar::ImplCreate( Window* pParent, Window* pWindow, MenuBar* pMenu ) { - if ( !pWindow ) - pWindow = new MenuBarWindow( pParent ); + MenuBarWindow *pMenuBarWindow = dynamic_cast<MenuBarWindow*>(pWindow); + if (!pMenuBarWindow) + { + pWindow = pMenuBarWindow = new MenuBarWindow( pParent ); + } pMenu->pStartedFrom = 0; pMenu->pWindow = pWindow; - ((MenuBarWindow*)pWindow)->SetMenu( pMenu ); + pMenuBarWindow->SetMenu(pMenu); long nHeight = pMenu->ImplCalcSize( pWindow ).Height(); // depending on the native implementation or the displayable flag @@ -2488,10 +2495,10 @@ Window* MenuBar::ImplCreate( Window* pParent, Window* pWindow, MenuBar* pMenu ) void MenuBar::ImplDestroy( MenuBar* pMenu, bool bDelete ) { - MenuBarWindow* pWindow = (MenuBarWindow*) pMenu->ImplGetWindow(); - if ( pWindow && bDelete ) + Window *pWindow = pMenu->ImplGetWindow(); + if (pWindow && bDelete) { - pWindow->KillActivePopup(); + pMenu->getMenuBarWindow()->KillActivePopup(); delete pWindow; } pMenu->pWindow = NULL; @@ -2509,27 +2516,27 @@ bool MenuBar::ImplHandleKeyEvent( const KeyEvent& rKEvent, bool bFromMenu ) // check for enabled, if this method is called from another window... Window* pWin = ImplGetWindow(); if ( pWin && pWin->IsEnabled() && pWin->IsInputEnabled() && ! pWin->IsInModalMode() ) - bDone = ((MenuBarWindow*)pWin)->ImplHandleKeyEvent( rKEvent, bFromMenu ); + bDone = getMenuBarWindow()->HandleKeyEvent( rKEvent, bFromMenu ); return bDone; } void MenuBar::SelectItem(sal_uInt16 nId) { - MenuBarWindow* pMenuWin = (MenuBarWindow*) ImplGetWindow(); + IMenuBarWindow* pMenuWin = getMenuBarWindow(); - if( pMenuWin ) + if (pWindow) { - pMenuWin->GrabFocus(); + pWindow->GrabFocus(); nId = GetItemPos( nId ); // #99705# popup the selected menu pMenuWin->SetAutoPopup( true ); - if( ITEMPOS_INVALID != pMenuWin->nHighlightedItem ) + if (ITEMPOS_INVALID != pMenuWin->GetHighlightedItem()) { pMenuWin->KillActivePopup(); pMenuWin->ChangeHighlightItem( ITEMPOS_INVALID, false ); } - if( nId != ITEMPOS_INVALID ) + if (nId != ITEMPOS_INVALID) pMenuWin->ChangeHighlightItem( nId, false ); } } @@ -2608,29 +2615,27 @@ bool MenuBar::HandleMenuCommandEvent( Menu *pMenu, sal_uInt16 nCommandEventId ) sal_uInt16 MenuBar::AddMenuBarButton( const Image& i_rImage, const Link& i_rLink, const OUString& i_rToolTip, sal_uInt16 i_nPos ) { - return pWindow ? static_cast<MenuBarWindow*>(pWindow)->AddMenuBarButton( i_rImage, i_rLink, i_rToolTip, i_nPos ) : 0; + return getMenuBarWindow()->AddMenuBarButton(i_rImage, i_rLink, i_rToolTip, i_nPos); } void MenuBar::SetMenuBarButtonHighlightHdl( sal_uInt16 nId, const Link& rLink ) { - if( pWindow ) - static_cast<MenuBarWindow*>(pWindow)->SetMenuBarButtonHighlightHdl( nId, rLink ); + getMenuBarWindow()->SetMenuBarButtonHighlightHdl(nId, rLink); } Rectangle MenuBar::GetMenuBarButtonRectPixel( sal_uInt16 nId ) { - return pWindow ? static_cast<MenuBarWindow*>(pWindow)->GetMenuBarButtonRectPixel( nId ) : Rectangle(); + return getMenuBarWindow()->GetMenuBarButtonRectPixel(nId); } void MenuBar::RemoveMenuBarButton( sal_uInt16 nId ) { - if( pWindow ) - static_cast<MenuBarWindow*>(pWindow)->RemoveMenuBarButton( nId ); + getMenuBarWindow()->RemoveMenuBarButton(nId); } -bool MenuBar::HandleMenuButtonEvent( Menu *, sal_uInt16 i_nButtonId ) const +bool MenuBar::HandleMenuButtonEvent( Menu *, sal_uInt16 i_nButtonId ) { - return static_cast<MenuBarWindow*>(pWindow)->HandleMenuButtonEvent( i_nButtonId ); + return getMenuBarWindow()->HandleMenuButtonEvent(i_nButtonId); } // bool PopupMenu::bAnyPopupInExecute = false; diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx index af254ee3e8d4..4645df4fafb4 100644 --- a/vcl/source/window/menubarwindow.cxx +++ b/vcl/source/window/menubarwindow.cxx @@ -690,11 +690,11 @@ Rectangle MenuBarWindow::ImplGetItemRect( sal_uInt16 nPos ) void MenuBarWindow::KeyInput( const KeyEvent& rKEvent ) { - if ( !ImplHandleKeyEvent( rKEvent ) ) + if ( !HandleKeyEvent( rKEvent ) ) Window::KeyInput( rKEvent ); } -bool MenuBarWindow::ImplHandleKeyEvent( const KeyEvent& rKEvent, bool bFromMenu ) +bool MenuBarWindow::HandleKeyEvent( const KeyEvent& rKEvent, bool bFromMenu ) { if( ! pMenu ) return false; @@ -986,7 +986,7 @@ void MenuBarWindow::StateChanged( StateChangedType nType ) } -void MenuBarWindow::ImplLayoutChanged() +void MenuBarWindow::LayoutChanged() { if( pMenu ) { @@ -1037,7 +1037,7 @@ void MenuBarWindow::DataChanged( const DataChangedEvent& rDCEvt ) (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) { ImplInitStyleSettings(); - ImplLayoutChanged(); + LayoutChanged(); } } @@ -1085,7 +1085,7 @@ sal_uInt16 MenuBarWindow::AddMenuBarButton( const Image& i_rImage, const Link& i aCloseBtn.InsertItem(nId, i_rImage, 0, 0); aCloseBtn.calcMinSize(); ShowButtons(aCloseBtn.IsItemVisible(IID_DOCUMENTCLOSE), aFloatBtn.IsVisible(), aHideBtn.IsVisible()); - ImplLayoutChanged(); + LayoutChanged(); if( pMenu->mpSalMenu ) pMenu->mpSalMenu->AddMenuBarButton( SalMenuButtonItem( nId, i_rImage, i_rToolTip ) ); @@ -1131,7 +1131,7 @@ void MenuBarWindow::RemoveMenuBarButton( sal_uInt16 nId ) aCloseBtn.RemoveItem(nPos); m_aAddButtons.erase( nId ); aCloseBtn.calcMinSize(); - ImplLayoutChanged(); + LayoutChanged(); if( pMenu->mpSalMenu ) pMenu->mpSalMenu->RemoveMenuBarButton( nId ); diff --git a/vcl/source/window/menubarwindow.hxx b/vcl/source/window/menubarwindow.hxx index a2ce2be8fd23..f5da9566dbd0 100644 --- a/vcl/source/window/menubarwindow.hxx +++ b/vcl/source/window/menubarwindow.hxx @@ -54,7 +54,7 @@ public: /** Class that implements the actual window of the menu bar. */ -class MenuBarWindow : public MenuWindow, public Window +class MenuBarWindow : public Window, public IMenuBarWindow { friend class MenuBar; friend class Menu; @@ -85,11 +85,11 @@ private: std::map< sal_uInt16, AddButtonEntry > m_aAddButtons; void HighlightItem( sal_uInt16 nPos, bool bHighlight ); - void ChangeHighlightItem( sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true ); + virtual void ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true) SAL_OVERRIDE; sal_uInt16 ImplFindEntry( const Point& rMousePos ) const; void ImplCreatePopup( bool bPreSelectFirst ); - bool ImplHandleKeyEvent( const KeyEvent& rKEvent, bool bFromMenu = true ); + virtual bool HandleKeyEvent(const KeyEvent& rKEvent, bool bFromMenu = true) SAL_OVERRIDE; Rectangle ImplGetItemRect( sal_uInt16 nPos ); void ImplInitStyleSettings(); @@ -109,7 +109,7 @@ public: MenuBarWindow( Window* pParent ); virtual ~MenuBarWindow(); - void ShowButtons( bool bClose, bool bFloat, bool bHide ); + virtual void ShowButtons(bool bClose, bool bFloat, bool bHide); virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE; virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE; @@ -119,25 +119,25 @@ public: virtual void Resize() SAL_OVERRIDE; virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE; - void SetFocusId( sal_uLong nId ) { nSaveFocusId = nId; } - sal_uLong GetFocusId() const { return nSaveFocusId; } + virtual void SetFocusId(sal_uLong nId) SAL_OVERRIDE { nSaveFocusId = nId; } + virtual sal_uLong GetFocusId() const SAL_OVERRIDE { return nSaveFocusId; } - void SetMenu( MenuBar* pMenu ); - void KillActivePopup(); - void PopupClosed( Menu* pMenu ); - sal_uInt16 GetHighlightedItem() const { return nHighlightedItem; } + virtual void SetMenu(MenuBar* pMenu) SAL_OVERRIDE; + virtual void KillActivePopup() SAL_OVERRIDE; + virtual void PopupClosed(Menu* pMenu) SAL_OVERRIDE; + virtual sal_uInt16 GetHighlightedItem() const SAL_OVERRIDE { return nHighlightedItem; } virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE; - void SetAutoPopup( bool bAuto ) { mbAutoPopup = bAuto; } - void ImplLayoutChanged(); + virtual void SetAutoPopup(bool bAuto) SAL_OVERRIDE { mbAutoPopup = bAuto; } + virtual void LayoutChanged() SAL_OVERRIDE; Size MinCloseButtonSize(); /// Add an arbitrary button to the menubar that will appear next to the close button. - sal_uInt16 AddMenuBarButton( const Image&, const Link&, const OUString&, sal_uInt16 nPos ); - void SetMenuBarButtonHighlightHdl( sal_uInt16 nId, const Link& ); - Rectangle GetMenuBarButtonRectPixel( sal_uInt16 nId ); - void RemoveMenuBarButton( sal_uInt16 nId ); - bool HandleMenuButtonEvent( sal_uInt16 i_nButtonId ); + virtual sal_uInt16 AddMenuBarButton(const Image&, const Link&, const OUString&, sal_uInt16 nPos) SAL_OVERRIDE; + virtual void SetMenuBarButtonHighlightHdl(sal_uInt16 nId, const Link&) SAL_OVERRIDE; + virtual Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId) SAL_OVERRIDE; + virtual void RemoveMenuBarButton(sal_uInt16 nId) SAL_OVERRIDE; + virtual bool HandleMenuButtonEvent(sal_uInt16 i_nButtonId) SAL_OVERRIDE; }; #endif // INCLUDED_VCL_SOURCE_WINDOW_MENUBARWINDOW_HXX diff --git a/vcl/source/window/menufloatingwindow.hxx b/vcl/source/window/menufloatingwindow.hxx index c2f84c7eb2ab..f650527f3851 100644 --- a/vcl/source/window/menufloatingwindow.hxx +++ b/vcl/source/window/menufloatingwindow.hxx @@ -30,7 +30,7 @@ /** Class that implements the actual window of the floating menu. */ -class MenuFloatingWindow : public MenuWindow, public FloatingWindow +class MenuFloatingWindow : public FloatingWindow, public MenuWindow { friend void Menu::ImplFillLayoutData() const; friend Menu::~Menu(); diff --git a/vcl/source/window/menuwindow.hxx b/vcl/source/window/menuwindow.hxx index 820d54842627..73c99df8828e 100644 --- a/vcl/source/window/menuwindow.hxx +++ b/vcl/source/window/menuwindow.hxx @@ -21,9 +21,14 @@ #define INCLUDED_VCL_SOURCE_WINDOW_MENUWINDOW_HXX #include <sal/types.h> +#include <tools/solar.h> +#include <vcl/event.hxx> class HelpEvent; +class Image; +class Link; class Menu; +class MenuBar; class Rectangle; class Window; @@ -46,6 +51,7 @@ common class for MenuFloatingWindow and MenuBarWindow: class MenuWindow { public: + virtual ~MenuWindow() {} /// Sets up some visual properties of the underlying window. void ImplInitMenuWindow(Window* pWin, bool bFont, bool bMenuBar); @@ -55,5 +61,34 @@ public: const HelpEvent& rHEvt, const Rectangle &rHighlightRect); }; +/// Interface for the MenuBarWindow functionality. +class IMenuBarWindow : public MenuWindow +{ +public: + virtual ~IMenuBarWindow() {} + + virtual sal_uLong GetFocusId() const = 0; + virtual void SetFocusId(sal_uLong nId) = 0; + + virtual bool HandleKeyEvent(const KeyEvent& rKEvent, bool bFromMenu = true) = 0; + virtual void LayoutChanged() = 0; + virtual void PopupClosed(Menu* pMenu) = 0; + virtual void ShowButtons(bool bClose, bool bFloat, bool bHide) = 0; + + virtual void ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true ) = 0; + virtual sal_uInt16 GetHighlightedItem() const = 0; + + virtual void SetAutoPopup(bool bAuto) = 0; + virtual void SetMenu(MenuBar* pMenu) = 0; + virtual void KillActivePopup() = 0; + + /// Add an arbitrary button to the menubar that will appear next to the close button. + virtual sal_uInt16 AddMenuBarButton(const Image&, const Link&, const OUString&, sal_uInt16 nPos) = 0; + virtual void SetMenuBarButtonHighlightHdl(sal_uInt16 nId, const Link&) = 0; + virtual Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId) = 0; + virtual void RemoveMenuBarButton(sal_uInt16 nId) = 0; + virtual bool HandleMenuButtonEvent(sal_uInt16 i_nButtonId) = 0; +}; + #endif // INCLUDED_VCL_SOURCE_WINDOW_MENUWINDOW_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |