summaryrefslogtreecommitdiff
path: root/vcl/source/window/menubarwindow.hxx
blob: f59ddeac772ebf2f4a2cf87d75c8116efe36577c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_VCL_SOURCE_WINDOW_MENUBARWINDOW_HXX
#define INCLUDED_VCL_SOURCE_WINDOW_MENUBARWINDOW_HXX

#include "menuwindow.hxx"

#include <vcl/button.hxx>
#include <vcl/menu.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/window.hxx>

class Button;

/** Toolbox that holds the close button (right hand side of the menubar).

This is also used by the online update check; when an update is available, it
inserts here the button that leads to the download of the update.
*/
class DecoToolBox : public ToolBox
{
    long lastSize;
    Size maMinSize;

    using Window::ImplInit;
public:
             DecoToolBox( vcl::Window* pParent, WinBits nStyle = 0 );
    virtual ~DecoToolBox() {}

    void    ImplInit();

    void    DataChanged( const DataChangedEvent& rDCEvt ) override;

    void    SetImages( long nMaxHeight = 0, bool bForce = false );

    void    calcMinSize();
    const Size& getMinSize() { return maMinSize;}

    Image   maImage;
};


/** Class that implements the actual window of the menu bar.
*/
class MenuBarWindow : public vcl::Window, public MenuWindow
{
    friend class MenuBar;
    friend class Menu;

private:
    struct AddButtonEntry
    {
        sal_uInt16    m_nId;
        Link<MenuBar::MenuBarButtonCallbackArg&,bool>  m_aSelectLink;
        Link<MenuBar::MenuBarButtonCallbackArg&,bool>  m_aHighlightLink;

        AddButtonEntry() : m_nId( 0 ) {}
    };

    Menu*           pMenu;
    PopupMenu*      pActivePopup;
    sal_uInt16      nHighlightedItem;
    sal_uInt16      nRolloveredItem;
    sal_uLong       nSaveFocusId;
    bool            mbAutoPopup;
    bool            bIgnoreFirstMove;
    bool            bStayActive;
    bool            mbHideAccel;
    bool            mbMenuKey;

    VclPtr<DecoToolBox>  aCloseBtn;
    VclPtr<PushButton>   aFloatBtn;
    VclPtr<PushButton>   aHideBtn;

    std::map< sal_uInt16, AddButtonEntry > m_aAddButtons;

    void            HighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, bool bHighlight);
    void    ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true);

    sal_uInt16      ImplFindEntry( const Point& rMousePos ) const;
    void            ImplCreatePopup( bool bPreSelectFirst );
    bool    HandleKeyEvent(const KeyEvent& rKEvent, bool bFromMenu = true);
    Rectangle       ImplGetItemRect( sal_uInt16 nPos );

    void            ImplInitStyleSettings();

    virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;

    DECL_LINK_TYPED( CloseHdl, ToolBox*, void );
    DECL_LINK_TYPED( ToolboxEventHdl, VclWindowEvent&, void );
    DECL_LINK_TYPED( ShowHideListener, VclWindowEvent&, void );

    void            StateChanged( StateChangedType nType ) override;
    void            DataChanged( const DataChangedEvent& rDCEvt ) override;
    void            LoseFocus() override;
    void            GetFocus() override;

public:
    explicit        MenuBarWindow( vcl::Window* pParent );
    virtual         ~MenuBarWindow();
    virtual void    dispose() override;

    void    ShowButtons(bool bClose, bool bFloat, bool bHide);

    virtual void    MouseMove( const MouseEvent& rMEvt ) override;
    virtual void    MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual void    MouseButtonUp( const MouseEvent& rMEvt ) override;
    virtual void    KeyInput( const KeyEvent& rKEvent ) override;
    virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) override;
    virtual void    Resize() override;
    virtual void    RequestHelp( const HelpEvent& rHEvt ) override;

    void    SetFocusId(sal_uLong nId) { nSaveFocusId = nId; }
    sal_uLong GetFocusId() const { return nSaveFocusId; }

    void    SetMenu(MenuBar* pMenu);
    void    SetHeight(long nHeight);
    void    KillActivePopup();
    void    PopupClosed(Menu* pMenu);
    sal_uInt16 GetHighlightedItem() const { return nHighlightedItem; }
    virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;

    void    SetAutoPopup(bool bAuto) { mbAutoPopup = bAuto; }
    void    LayoutChanged();
    Size            MinCloseButtonSize();

    /// Add an arbitrary button to the menubar that will appear next to the close button.
    sal_uInt16 AddMenuBarButton(const Image&, const Link<MenuBar::MenuBarButtonCallbackArg&,bool>&, const OUString&);
    void SetMenuBarButtonHighlightHdl(sal_uInt16 nId, const Link<MenuBar::MenuBarButtonCallbackArg&,bool>&);
    Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId);
    void RemoveMenuBarButton(sal_uInt16 nId);
    bool HandleMenuButtonEvent(sal_uInt16 i_nButtonId);
    void SetMBWHideAccel(bool val) { mbHideAccel = val; }
    bool GetMBWHideAccel() const { return mbHideAccel; }
    void SetMBWMenuKey(bool val) { mbMenuKey = val; }
    bool GetMBWMenuKey() const { return mbMenuKey; }
};

#endif // INCLUDED_VCL_SOURCE_WINDOW_MENUBARWINDOW_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */