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 MenuMenuItem;
48 class MenuBaseItem;
49 
50 class PT_FORMS_API Menu : public Pt::Forms::Popup, protected MenuBase
51 {
52  public:
53  friend class MenuBar;
54  friend class MenuMenuItem;
55 
56  public:
57  Menu();
58 
59  virtual ~Menu();
60 
61  double iconWidth() const;
62 
63  const Pt::Gfx::Brush& background() const;
64 
65  void setBackground(const Pt::Gfx::Brush& b);
66 
67  const Pt::Gfx::Pen& contour() const;
68 
69  void setContour(const Pt::Gfx::Pen& p);
70 
71  void addItem(MenuItem& item);
72 
73  void addItem(MenuSubItem& item);
74 
75  void removeItem(MenuItem& item);
76 
77  void removeItem(MenuSubItem& item);
78 
79  protected:
80  //Pt::Forms::Popup
81  virtual void onInvalidate();
82 
83  virtual void onPaintEvent(const Pt::Forms::PaintEvent& ev);
84 
85  virtual void onCloseEvent(const Pt::Forms::CloseEvent& ev);
86 
87  virtual void onShowEvent(const Pt::Forms::ShowEvent& ev);
88 
89  virtual bool onMouseEvent(const Pt::Forms::MouseEvent& ev);
90 
91  virtual bool onEnterEvent(const Pt::Forms::EnterEvent& ev);
92 
93  virtual bool onLeaveEvent(const Pt::Forms::LeaveEvent& ev);
94 
95  virtual void onRenderBackground( const Pt::Forms::StyleOptions& options, Pt::Gfx::Painter& painter,
96  const Pt::Gfx::RectF& rect) const;
97 
98  //MenuBase
99  virtual void onAddMenu(MenuMenuItem& item);
100 
101  virtual void onRemoveMenu(MenuMenuItem& item);
102 
103  virtual void onCloseMenu(MenuMenuItem& item);
104 
105  virtual void onOpenMenu(MenuMenuItem& item);
106 
107  virtual void onCancel();
108 
109  virtual Pt::Forms::Widget* onFindMenu(const Pt::Gfx::PointF& screenPos);
110 
111  protected:
112  void onProcessMouseEvent(const Pt::Forms::MouseEvent& ev);
113 
114  private:
115  void onItemTriggered(MenuBaseItem& m);
116 
117  void drawBorder(Pt::Gfx::Painter& painter, const Pt::Gfx::RectF& borderRect) const;
118 
119  private:
120  MenuBaseItem* _currentItem;
121  Pt::Forms::FlowLayout _layout;
122  Pt::ssize_t _iconWidth;
123  Pt::AutoPtr<Pt::Gfx::Brush> _background;
124  Pt::AutoPtr<Pt::Gfx::Pen> _contour;
125  Pt::Gfx::Brush _brush;
126  Pt::Gfx::Pen _pen;
127  bool _isOpen;
128 };
129 
130 }}
131 
132 #endif
Rect with floating-point coordinates.
Definition: Rect.h:44
Attributes for the drawing of outlines.
Definition: Pen.h:52
Point with floating-point X and Y coordinates.
Definition: Point.h:44
2D painter for Gfx paint surfaces.
Definition: Painter.h:42