Menu.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_MENU_H
30 #define PT_FORMS_MENU_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/MenuBase.h>
34 #include <Pt/Forms/Popup.h>
35 #include <Pt/Forms/FlowLayout.h>
36 #include <Pt/Forms/StyleOptions.h>
37 #include <Pt/Gfx/Brush.h>
38 #include <Pt/Gfx/Pen.h>
39 #include <Pt/SmartPtr.h>
40 
41 namespace Pt {
42 namespace Forms {
43 
44 class MenuItem;
45 class MenuBarItem;
46 class MenuSubItem;
47 class MenuItemBase;
48 
70 class PT_FORMS_API Menu : public Pt::Forms::Popup, protected MenuBase
71 {
72  public:
73  friend class MenuBar;
74  friend class MenuSubItem;
75 
76  public:
79  Menu();
80 
83  virtual ~Menu();
84 
87  double iconWidth() const;
88 
94  const Pt::Gfx::Brush& background() const;
95 
98  void setBackground(const Pt::Gfx::Brush& b);
99 
105  const Pt::Gfx::Pen& contour() const;
106 
109  void setContour(const Pt::Gfx::Pen& p);
110 
115  void addItem(MenuItem& item);
116 
121  void addItem(MenuSubItem& item);
122 
125  void removeItem(MenuItem& item);
126 
129  void removeItem(MenuSubItem& item);
130 
131  protected:
132  //Pt::Forms::Popup
133  virtual void onInvalidate();
134 
135  virtual void onPaint(PaintContext& ctx, const Pt::Gfx::RectF& rect);
136 
137  virtual void onCloseEvent(const Pt::Forms::CloseEvent& ev);
138 
139  virtual void onShowEvent(const Pt::Forms::ShowEvent& ev);
140 
141  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
142 
143  virtual bool onEnterEvent(const Pt::Forms::EnterEvent& ev);
144 
145  virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent& ev);
146 
147  virtual void onRenderBackground( const Pt::Forms::StyleOptions& options, Pt::Forms::Painter& painter,
148  const Pt::Gfx::RectF& rect) const;
149 
150  //MenuBase
151  virtual void onAddMenu(MenuSubItem& item);
152 
153  virtual void onRemoveMenu(MenuSubItem& item);
154 
155  virtual void onCloseMenu(MenuSubItem& item);
156 
157  virtual void onOpenMenu(MenuSubItem& item);
158 
159  virtual void onCancel();
160 
161  virtual Pt::Forms::Widget* onFindMenu(const Pt::Gfx::PointF& screenPos);
162 
163  protected:
165 
166  private:
167  void onItemTriggered(MenuItemBase& m);
168 
169  void drawBorder(Pt::Forms::Painter& painter, const Pt::Gfx::RectF& borderRect) const;
170 
171  private:
172  MenuItemBase* _currentItem;
173  Pt::Forms::FlowLayout _layout;
174  Pt::ssize_t _iconWidth;
175  Pt::AutoPtr<Pt::Gfx::Brush> _background;
176  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
177  Pt::Gfx::Brush _brush;
178  Pt::Gfx::Pen _pen;
179  bool _isOpen;
180 };
181 
182 }}
183 
184 #endif
Core module.
Definition: Allocator.h:33
Pointer entered a widget.
Definition: EnterEvent.h:49
Menu()
Creates a detached popup menu.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void removeItem(MenuItem &item)
Removes command item from this menu.
virtual void onCloseEvent(const Pt::Forms::CloseEvent &ev)
Hides, detaches, closes, and sends closed().
virtual bool onEnterEvent(const Pt::Forms::EnterEvent &ev)
Restores the default cursor, handles the event, and returns consumption.
Defines the coordination interface shared by menu containers.
Definition: MenuBase.h:51
Reports that a widget is closing.
Definition: CloseEvent.h:50
void removeItem(MenuSubItem &item)
Removes submenu entry item from this menu.
Draws on a Forms paint surface or paint context.
Definition: Painter.h:53
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
virtual void onPaint(PaintContext &ctx, const Pt::Gfx::RectF &rect)
Fills rect with the current window background.
virtual bool onMouseEvent(const Pt::Forms::MouseEvent &ev)
Handles a mouse event and returns whether it was consumed.
virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent &ev)
Handles a pointer-leave event and returns whether it was consumed.
Common type of every visual Forms object.
Definition: Widget.h:105
void addItem(MenuItem &item)
Adds command item to this menu.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Represents a menu item that opens a nested menu.
Definition: MenuSubItem.h:57
double iconWidth() const
Returns the width reserved for item icons.
Represents a horizontal bar of top-level menus.
Definition: MenuBar.h:78
Arranges children in a single row or column.
Definition: FlowLayout.h:72
Stores named appearance options.
Definition: StyleOptions.h:646
Represents a popup menu containing commands and nested menus.
Definition: Menu.h:71
void setBackground(const Pt::Gfx::Brush &b)
Sets a local background brush.
const Pt::Gfx::Brush & background() const
Returns the background brush.
Pointer left a widget.
Definition: LeaveEvent.h:49
const Pt::Gfx::Pen & contour() const
Returns the contour pen.
Reports that a widget was shown or hidden.
Definition: ShowEvent.h:48
virtual void onShowEvent(const Pt::Forms::ShowEvent &ev)
Processes event and invalidates the window.
Fill description for shapes and text.
Definition: Brush.h:145
virtual ~Menu()
Destroys the menu.
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual void onInvalidate()
Updates the cached background and repaints the complete window.
void onProcessMouseEvent(const Pt::Forms::MouseEvent &ev)
Routes event when the window accepts input.
Represents the common content and activation behavior of a menu item.
Definition: MenuItemBase.h:55
void setContour(const Pt::Gfx::Pen &p)
Sets a local contour pen.
Pointer movement or button change.
Definition: MouseEvent.h:134
Represents a command that can be chosen from a menu.
Definition: MenuItem.h:50
void addItem(MenuSubItem &item)
Adds submenu entry item to this menu.
Represents a borderless transient window.
Definition: Popup.h:48