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 
48 class PT_FORMS_API MenuBar : public Control
49  , protected MenuBase
50 {
51  typedef Control Base;
52 
53  public:
54  MenuBar();
55 
56  virtual ~MenuBar();
57 
58  void addItem(MenuBarItem& item);
59 
60  void removeItem(MenuBarItem& item);
61 
62  const Pt::Gfx::Brush& background() const;
63 
64  void setBackground(const Pt::Gfx::Brush& b);
65 
66  const Pt::Gfx::Pen& contour() const;
67 
68  void setContour(const Pt::Gfx::Pen& p);
69 
70  protected:
71 
72  virtual Pt::Forms::Widget* onFindMenu(const Pt::Gfx::PointF& screenPos);
73 
74  virtual void onAddMenu(MenuMenuItem& item);
75 
76  virtual void onRemoveMenu(MenuMenuItem& item);
77 
78  virtual void onOpenMenu(MenuMenuItem& item);
79 
80  virtual void onCloseMenu(MenuMenuItem& item);
81 
82  virtual void onCancel();
83 
84  virtual void onInvalidate();
85 
86  virtual Pt::Gfx::SizeF onMeasure(const Pt::Forms::SizePolicy& policy);
87 
88  virtual void onLayout(const Pt::Gfx::RectF& rect);
89 
90  virtual void onPaint(PaintSurface& surface, const Pt::Gfx::RectF& rect);
91 
92  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
93 
94  virtual bool onTouchEvent(const Pt::Forms::TouchEvent& ev);
95 
96  void onItemClicked(MenuBaseItem& item);
97 
98  void onProcessMouseEvent(const Pt::Forms::MouseEvent& ev);
99 
100  private:
101  Pt::Forms::FlowLayout _layout;
102  MenuMenuItem* _currentItem;
103  Pt::AutoPtr<Pt::Gfx::Brush> _background;
104  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
105  Pt::Gfx::Brush _brush;
106  Pt::Gfx::Pen _pen;
107 };
108 
109 }}
110 
111 #endif
Rect with floating-point coordinates.
Definition: Rect.h:44
Attributes for the drawing of outlines.
Definition: Pen.h:52
Size with floating-point width and height.
Definition: Size.h:44
Point with floating-point X and Y coordinates.
Definition: Point.h:44