File: menu.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (182 lines) | stat: -rw-r--r-- 5,773 bytes parent folder | download | duplicates (10)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/osx/menu.h
// Purpose:     wxMenu, wxMenuBar classes
// Author:      Stefan Csomor
// Modified by:
// Created:     1998-01-01
// Copyright:   (c) Stefan Csomor
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_MENU_H_
#define _WX_MENU_H_

class WXDLLIMPEXP_FWD_CORE wxFrame;

#include "wx/arrstr.h"

// ----------------------------------------------------------------------------
// Menu
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_FWD_CORE wxMenuImpl ;

class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase
{
public:
    // ctors & dtor
    wxMenu(const wxString& title, long style = 0)
        : wxMenuBase(title, style) { Init(); }

    wxMenu(long style = 0) : wxMenuBase(style) { Init(); }

    virtual ~wxMenu();

    virtual void Break();

    virtual void SetTitle(const wxString& title);

    bool ProcessCommand(wxCommandEvent& event);

    // get the menu handle
    WXHMENU GetHMenu() const ;

    // implementation only from now on
    // -------------------------------

    bool HandleCommandUpdateStatus( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
    bool HandleCommandProcess( wxMenuItem* menuItem, wxWindow* senderWindow = NULL);
    void HandleMenuItemHighlighted( wxMenuItem* menuItem );
    void HandleMenuOpened();
    void HandleMenuClosed();

    wxMenuImpl* GetPeer() { return m_peer; }

    // make sure we can veto
    void SetAllowRearrange( bool allow );
    bool AllowRearrange() const { return m_allowRearrange; }

    // if a menu is used purely for internal implementation reasons (eg wxChoice)
    // we don't want native menu events being triggered
    void SetNoEventsMode( bool noEvents );
    bool GetNoEventsMode() const { return m_noEventsMode; }
protected:
    // hide special menu items like exit, preferences etc
    // that are expected in the app menu
    void DoRearrange() ;

    bool DoHandleMenuEvent( wxEvent& evt );
    virtual wxMenuItem* DoAppend(wxMenuItem *item);
    virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
    virtual wxMenuItem* DoRemove(wxMenuItem *item);

private:
    // common part of all ctors
    void Init();

    // common part of Do{Append,Insert}(): behaves as Append if pos == -1
    bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);

    // Common part of HandleMenu{Opened,Closed}().
    void DoHandleMenuOpenedOrClosed(wxEventType evtType);


    // if TRUE, insert a break before appending the next item
    bool m_doBreak;

    // in this menu rearranging of menu items (esp hiding) is allowed
    bool m_allowRearrange;

    // don't trigger native events
    bool m_noEventsMode;

    wxMenuImpl* m_peer;

    DECLARE_DYNAMIC_CLASS(wxMenu)
};

#if wxOSX_USE_COCOA_OR_CARBON

// the iphone only has popup-menus

// ----------------------------------------------------------------------------
// Menu Bar (a la Windows)
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
{
public:
    // ctors & dtor
        // default constructor
    wxMenuBar();
        // unused under MSW
    wxMenuBar(long style);
        // menubar takes ownership of the menus arrays but copies the titles
    wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0);
    virtual ~wxMenuBar();

    // menubar construction
    virtual bool Append( wxMenu *menu, const wxString &title );
    virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
    virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
    virtual wxMenu *Remove(size_t pos);

    virtual void EnableTop( size_t pos, bool flag );
    virtual bool IsEnabledTop(size_t pos) const;
    virtual void SetMenuLabel( size_t pos, const wxString& label );
    virtual wxString GetMenuLabel( size_t pos ) const;
    virtual bool Enable( bool enable = true );
    // for virtual function hiding
    virtual void Enable( int itemid, bool enable )
    {
        wxMenuBarBase::Enable( itemid, enable );
    }

    // implementation from now on
    void Detach();

        // returns TRUE if we're attached to a frame
    bool IsAttached() const { return m_menuBarFrame != NULL; }
        // get the frame we live in
    wxFrame *GetFrame() const { return m_menuBarFrame; }
        // attach to a frame
    void Attach(wxFrame *frame);

    // if the menubar is modified, the display is not updated automatically,
    // call this function to update it (m_menuBarFrame should be !NULL)
    void Refresh(bool eraseBackground = true, const wxRect *rect = NULL);

#if wxABI_VERSION >= 30001
    wxMenu *OSXGetAppleMenu() const { return m_appleMenu; }
#endif

    static void SetAutoWindowMenu( bool enable ) { s_macAutoWindowMenu = enable ; }
    static bool GetAutoWindowMenu() { return s_macAutoWindowMenu ; }

    void MacInstallMenuBar() ;
    static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
    static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
    static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }


    static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; }
protected:
    // common part of all ctors
    void Init();

    static bool     s_macAutoWindowMenu ;
    static WXHMENU  s_macWindowMenuHandle ;

private:
    static wxMenuBar*            s_macInstalledMenuBar ;
    static wxMenuBar*            s_macCommonMenuBar ;

    wxMenu* m_rootMenu;
    wxMenu* m_appleMenu;

    DECLARE_DYNAMIC_CLASS(wxMenuBar)
};

#endif

#endif // _WX_MENU_H_