2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_MENUBARCOMPONENT_JUCEHEADER__
27 #define __JUCE_MENUBARCOMPONENT_JUCEHEADER__
29 #include "juce_MenuBarModel.h"
32 //==============================================================================
38 class JUCE_API MenuBarComponent
: public Component
,
39 private MenuBarModel::Listener
,
43 //==============================================================================
44 /** Creates a menu bar.
46 @param model the model object to use to control this bar. You can
47 pass 0 into this if you like, and set the model later
48 using the setModel() method
50 MenuBarComponent (MenuBarModel
* model
);
55 //==============================================================================
56 /** Changes the model object to use to control the bar.
58 This can be a null pointer, in which case the bar will be empty. Don't delete the object
59 that is passed-in while it's still being used by this MenuBar.
61 void setModel (MenuBarModel
* newModel
);
63 /** Returns the current menu bar model being used.
65 MenuBarModel
* getModel() const noexcept
;
67 //==============================================================================
68 /** Pops up one of the menu items.
70 This lets you manually open one of the menus - it could be triggered by a
71 key shortcut, for example.
73 void showMenu (int menuIndex
);
75 //==============================================================================
77 void paint (Graphics
& g
);
81 void mouseEnter (const MouseEvent
& e
);
83 void mouseExit (const MouseEvent
& e
);
85 void mouseDown (const MouseEvent
& e
);
87 void mouseDrag (const MouseEvent
& e
);
89 void mouseUp (const MouseEvent
& e
);
91 void mouseMove (const MouseEvent
& e
);
93 void handleCommandMessage (int commandId
);
95 bool keyPressed (const KeyPress
& key
);
97 void menuBarItemsChanged (MenuBarModel
* menuBarModel
);
99 void menuCommandInvoked (MenuBarModel
* menuBarModel
,
100 const ApplicationCommandTarget::InvocationInfo
& info
);
103 //==============================================================================
106 StringArray menuNames
;
107 Array
<int> xPositions
;
108 int itemUnderMouse
, currentPopupIndex
, topLevelIndexClicked
;
109 int lastMouseX
, lastMouseY
;
111 int getItemAt (int x
, int y
);
112 void setItemUnderMouse (int index
);
113 void setOpenItem (int index
);
114 void updateItemUnderMouse (int x
, int y
);
115 void timerCallback();
116 void repaintMenuItem (int index
);
117 void menuDismissed (int topLevelIndex
, int itemId
);
118 static void menuBarMenuDismissedCallback (int, MenuBarComponent
*, int);
120 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuBarComponent
);
123 #endif // __JUCE_MENUBARCOMPONENT_JUCEHEADER__