MenuSubItem.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 #ifndef PT_FORMS_MENUSUBITEM_H
30 #define PT_FORMS_MENUSUBITEM_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/MenuBase.h>
34 #include <Pt/Forms/MenuItemBase.h>
35 #include <Pt/Forms/Button.h>
36 #include <Pt/Forms/Control.h>
37 #include <Pt/Forms/FlowLayout.h>
38 #include <Pt/SmartPtr.h>
39 #include <vector>
40 
41 namespace Pt {
42 namespace Forms {
43 
44 class Menu;
45 class MenuBar;
46 
56 class PT_FORMS_API MenuSubItem : public MenuItemBase
57 {
58  friend class Menu;
59 
60  public:
63  typedef MenuItemBase Base;
64 
65  public:
69 
72  virtual ~MenuSubItem();
73 
79  void setMenu(Menu* menu);
80 
83  const Menu* menu() const
84  {
85  return _menu;
86  }
87 
91  {
92  return _menu;
93  }
94 
101  {
102  _parentMenu = p;
103  }
104 
107  void cancel();
108 
111  void closeMenu();
112 
115  void openMenu();
116 
119  bool isMenuOpen() const
120  {
121  return _isOpen;
122  }
123 
124  protected:
125  virtual const std::vector<Key> onGetShortcuts();
126 
127  virtual const std::vector<Pt::Char> onGetMnemonics();
128 
129  virtual void onShortcut(const Key& key);
130 
131  virtual void onMnemonic(Pt::Char m);
132 
133  virtual void onPaint(PaintContext& context, const Pt::Gfx::RectF& updateRect);
134 
135  private:
136  MenuBase* _parentMenu;
137  Menu* _menu;
138  bool _isOpen;
139 };
140 
141 }}
142 
143 #endif
Core module.
Definition: Allocator.h:33
virtual void onShortcut(const Key &key)
Handles an activated form shortcut.
void closeMenu()
Closes the nested menu.
void cancel()
Cancels the nested menu interaction.
void openMenu()
Opens the nested menu.
bool isMenuOpen() const
Returns true if the nested menu is open.
Definition: MenuSubItem.h:119
Menu * menu()
Returns the nested menu, or 0 when none is assigned.
Definition: MenuSubItem.h:90
virtual ~MenuSubItem()
Destroys the item.
Defines the coordination interface shared by menu containers.
Definition: MenuBase.h:51
MenuSubItem()
Creates an item without a nested menu.
virtual const std::vector< Pt::Char > onGetMnemonics()
Returns mnemonics registered by this control.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
const Menu * menu() const
Returns the nested menu, or 0 when none is assigned.
Definition: MenuSubItem.h:83
virtual void onMnemonic(Pt::Char m)
Handles an activated form mnemonic.
Unicode character type.
Definition: String.h:67
Represents a menu item that opens a nested menu.
Definition: MenuSubItem.h:57
void setParentMenu(MenuBase *p)
Sets the containing menu coordinator.
Definition: MenuSubItem.h:100
virtual void onPaint(PaintContext &context, const Pt::Gfx::RectF &updateRect)
Paints custom content in local coordinates.
virtual const std::vector< Key > onGetShortcuts()
Returns shortcuts registered by this control.
Key code and modifiers.
Definition: Key.h:23
Represents a popup menu containing commands and nested menus.
Definition: Menu.h:71
MenuItemBase Base
Defines the inherited menu item type.
Definition: MenuSubItem.h:63
Rect with floating-point coordinates.
Definition: Rect.h:47
Represents the common content and activation behavior of a menu item.
Definition: MenuItemBase.h:55
void setMenu(Menu *menu)
Associates menu with this item.