MenuBar.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_MENUBAR_H
30 #define PT_FORMS_MENUBAR_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Forms/MenuBase.h>
34 #include <Pt/Forms/MenuBarItem.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 
43 namespace Forms {
44 
45 class Menu;
46 class MenuBar;
47 
76 class PT_FORMS_API MenuBar : public Control
77  , protected MenuBase
78 {
79  typedef Control Base;
80 
81  public:
85 
88  virtual ~MenuBar();
89 
95  void addItem(MenuBarItem& item);
96 
99  void removeItem(MenuBarItem& item);
100 
106  const Pt::Gfx::Brush& background() const;
107 
111 
117  const Pt::Gfx::Pen& contour() const;
118 
121  void setContour(const Pt::Gfx::Pen& p);
122 
123  protected:
124 
125  virtual Pt::Forms::Widget* onFindMenu(const Pt::Gfx::PointF& screenPos);
126 
127  virtual void onAddMenu(MenuSubItem& item);
128 
129  virtual void onRemoveMenu(MenuSubItem& item);
130 
131  virtual void onOpenMenu(MenuSubItem& item);
132 
133  virtual void onCloseMenu(MenuSubItem& item);
134 
135  virtual void onCancel();
136 
137  virtual void onInvalidate();
138 
140 
141  virtual void onLayout(const Pt::Gfx::RectF& rect);
142 
143  virtual void onPaint(PaintContext& context, const Pt::Gfx::RectF& rect);
144 
145  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
146 
147  virtual bool onTouchEvent(const Pt::Forms::TouchEvent& ev);
148 
149  void onItemClicked(MenuItemBase& item);
150 
152 
153  private:
154  Pt::Forms::FlowLayout _layout;
155  MenuSubItem* _currentItem;
156  Pt::AutoPtr<Pt::Gfx::Brush> _background;
157  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
158  Pt::Gfx::Brush _brush;
159  Pt::Gfx::Pen _pen;
160 };
161 
162 }}
163 
164 #endif
Core module.
Definition: Allocator.h:33
Touch press, move, or release.
Definition: TouchEvent.h:51
void removeItem(MenuBarItem &item)
Removes top-level entry item from this menu bar.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void addItem(MenuBarItem &item)
Adds top-level entry item to this menu bar.
MenuBar()
Creates an empty menu bar.
Defines the coordination interface shared by menu containers.
Definition: MenuBase.h:51
virtual bool onMouseEvent(const Pt::Forms::MouseEvent &ev)
Handles mouse input in local coordinates.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
Size with floating-point width and height.
Definition: Size.h:47
Common type of every visual Forms object.
Definition: Widget.h:105
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Reusable view used as application content.
Definition: Control.h:107
Represents a menu item that opens a nested menu.
Definition: MenuSubItem.h:57
virtual void onLayout(const Pt::Gfx::RectF &rect)
Assigns geometry to direct children within rect.
virtual ~MenuBar()
Destroys the menu bar.
void setBackground(const Pt::Gfx::Brush &b)
Sets a local background brush.
virtual void onInvalidate()
Updates derived state after invalidation.
Represents a horizontal bar of top-level menus.
Definition: MenuBar.h:78
Arranges children in a single row or column.
Definition: FlowLayout.h:72
Widget that hosts controls on a paint surface.
Definition: View.h:86
virtual bool onTouchEvent(const Pt::Forms::TouchEvent &ev)
Handles touch input in local coordinates.
void onProcessMouseEvent(const Pt::Forms::MouseEvent &ev)
Routes mouse input to the frontmost eligible child or this control.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Fill description for shapes and text.
Definition: Brush.h:145
const Pt::Gfx::Pen & contour() const
Returns the contour pen.
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy &policy)
Measures intrinsic content for effective policy policy.
const Pt::Gfx::Brush & background() const
Returns the background brush.
Represents a top-level entry in a menu bar.
Definition: MenuBarItem.h:54
Represents the common content and activation behavior of a menu item.
Definition: MenuItemBase.h:55
Pointer movement or button change.
Definition: MouseEvent.h:134
virtual void onPaint(PaintContext &context, const Pt::Gfx::RectF &rect)
Paints custom content in local coordinates.
void setContour(const Pt::Gfx::Pen &p)
Sets a local contour pen.