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
41namespace Pt {
42namespace Forms {
43
44class MenuItem;
45class MenuBarItem;
46class MenuSubItem;
47class MenuItemBase;
48
70class PT_FORMS_API Menu : public Pt::Forms::Popup, protected MenuBase
71{
72 public:
73 friend class MenuBar;
74 friend class MenuSubItem;
75
76 public:
80
83 virtual ~Menu();
84
87 double iconWidth() const;
88
94 const Pt::Gfx::Brush& background() const;
95
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;
177 Pt::Gfx::Brush _brush;
178 Pt::Gfx::Pen _pen;
179 bool _isOpen;
180};
181
182}}
183
184#endif
Policy based Auto pointer.
Definition SmartPtr.h:291
Reports that a widget is closing.
Definition CloseEvent.h:50
Pointer entered a widget.
Definition EnterEvent.h:49
Arranges children in a single row or column.
Definition FlowLayout.h:72
Pointer left a widget.
Definition LeaveEvent.h:49
Represents a top-level entry in a menu bar.
Definition MenuBarItem.h:54
MenuBase()
Creates an unassociated menu coordination interface.
Represents the common content and activation behavior of a menu item.
Definition MenuItemBase.h:55
Represents a command that can be chosen from a menu.
Definition MenuItem.h:50
Represents a menu item that opens a nested menu.
Definition MenuSubItem.h:57
void addItem(MenuSubItem &item)
Adds submenu entry item to this menu.
void removeItem(MenuItem &item)
Removes command item from this menu.
void addItem(MenuItem &item)
Adds command item to this menu.
void onProcessMouseEvent(const Pt::Forms::MouseEvent &ev)
Routes event when the window accepts input.
virtual void onPaint(PaintContext &ctx, const Pt::Gfx::RectF &rect)
Fills rect with the current window background.
void removeItem(MenuSubItem &item)
Removes submenu entry item from this menu.
virtual bool onEnterEvent(const Pt::Forms::EnterEvent &ev)
Restores the default cursor, handles the event, and returns consumption.
virtual void onShowEvent(const Pt::Forms::ShowEvent &ev)
Processes event and invalidates the window.
double iconWidth() const
Returns the width reserved for item icons.
void setContour(const Pt::Gfx::Pen &p)
Sets a local contour pen.
void setBackground(const Pt::Gfx::Brush &b)
Sets a local background brush.
const Pt::Gfx::Brush & background() const
Returns the background brush.
const Pt::Gfx::Pen & contour() const
Returns the contour pen.
virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent &ev)
Handles a pointer-leave event and returns whether it was consumed.
virtual bool onMouseEvent(const Pt::Forms::MouseEvent &ev)
Handles a mouse event and returns whether it was consumed.
virtual void onCloseEvent(const Pt::Forms::CloseEvent &ev)
Hides, detaches, closes, and sends closed().
virtual ~Menu()
Destroys the menu.
virtual void onInvalidate()
Updates the cached background and repaints the complete window.
Menu()
Creates a detached popup menu.
Pointer movement or button change.
Definition MouseEvent.h:134
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Represents a borderless transient window.
Definition Popup.h:48
Reports that a widget was shown or hidden.
Definition ShowEvent.h:48
Stores named appearance options.
Definition StyleOptions.h:646
Common type of every visual Forms object.
Definition Widget.h:105
Fill color, gradient or texture.
Definition Brush.h:151
Outline color, width and style.
Definition Pen.h:59
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33