1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "menuwindow.hxx"
24 #include <vcl/toolkit/button.hxx>
25 #include <vcl/menu.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/window.hxx>
33 /** Toolbox that holds the close button (right hand side of the menubar).
35 This is also used by the online update check; when an update is available, it
36 inserts here the button that leads to the download of the update.
38 class DecoToolBox
: public ToolBox
44 explicit DecoToolBox(vcl::Window
* pParent
);
46 void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
48 void SetImages( tools::Long nMaxHeight
, bool bForce
= false );
51 const Size
& getMinSize() const { return maMinSize
;}
57 /** Class that implements the actual window of the menu bar.
59 class MenuBarWindow
: public vcl::Window
, public MenuWindow
67 Link
<MenuBarButtonCallbackArg
&,bool> m_aSelectLink
;
68 Link
<MenuBarButtonCallbackArg
&,bool> m_aHighlightLink
;
72 VclPtr
<PopupMenu
> m_pActivePopup
;
73 VclPtr
<PopupMenu
> mpParentPopup
;
74 sal_uInt16 m_nHighlightedItem
;
75 sal_uInt16 m_nRolloveredItem
;
76 VclPtr
<vcl::Window
> m_xSaveFocusId
;
78 bool m_bIgnoreFirstMove
;
80 VclPtr
<DecoToolBox
> m_aCloseBtn
;
81 VclPtr
<PushButton
> m_aFloatBtn
;
82 VclPtr
<PushButton
> m_aHideBtn
;
84 std::map
< sal_uInt16
, AddButtonEntry
> m_aAddButtons
;
86 void HighlightItem(vcl::RenderContext
& rRenderContext
, sal_uInt16 nPos
);
87 void ChangeHighlightItem(sal_uInt16 n
, bool bSelectPopupEntry
, bool bAllowRestoreFocus
= true, bool bDefaultToDocument
= true);
89 sal_uInt16
ImplFindEntry( const Point
& rMousePos
) const;
90 void ImplCreatePopup( bool bPreSelectFirst
);
91 bool HandleKeyEvent(const KeyEvent
& rKEvent
, bool bFromMenu
= true);
92 tools::Rectangle
ImplGetItemRect( sal_uInt16 nPos
) const;
94 void ImplInitStyleSettings();
96 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
98 DECL_LINK( CloseHdl
, ToolBox
*, void );
99 DECL_LINK( ToolboxEventHdl
, VclWindowEvent
&, void );
100 DECL_LINK( ShowHideListener
, VclWindowEvent
&, void );
102 void StateChanged( StateChangedType nType
) override
;
103 void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
104 void LoseFocus() override
;
105 void GetFocus() override
;
108 explicit MenuBarWindow( vcl::Window
* pParent
);
109 virtual ~MenuBarWindow() override
;
110 virtual void dispose() override
;
112 void ShowButtons(bool bClose
, bool bFloat
, bool bHide
);
114 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
115 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
116 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
117 virtual void KeyInput( const KeyEvent
& rKEvent
) override
;
118 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
119 virtual void Resize() override
;
120 virtual void RequestHelp( const HelpEvent
& rHEvt
) override
;
122 void SetMenu(MenuBar
* pMenu
);
123 void SetHeight(tools::Long nHeight
);
124 void KillActivePopup();
125 void PopupClosed(Menu
const * pMenu
);
126 sal_uInt16
GetHighlightedItem() const { return m_nHighlightedItem
; }
127 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
129 void SetAutoPopup(bool bAuto
) { mbAutoPopup
= bAuto
; }
130 void LayoutChanged();
131 Size
const & MinCloseButtonSize() const;
133 /// Add an arbitrary button to the menubar that will appear next to the close button.
134 sal_uInt16
AddMenuBarButton(const Image
&, const Link
<MenuBarButtonCallbackArg
&,bool>&, const OUString
&);
135 void SetMenuBarButtonHighlightHdl(sal_uInt16 nId
, const Link
<MenuBarButtonCallbackArg
&,bool>&);
136 tools::Rectangle
GetMenuBarButtonRectPixel(sal_uInt16 nId
);
137 void RemoveMenuBarButton(sal_uInt16 nId
);
138 bool HandleMenuButtonEvent(sal_uInt16 i_nButtonId
);
139 bool CanGetFocus() const;
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */