popupmenu.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29 
30 
31 #pragma once
32 
33 #include "../api_gui.h"
34 #include "../gui_component.h"
35 #include "../../Display/Window/input_event.h"
36 #include "popupmenu_item.h"
37 
38 namespace clan
39 {
42 
43 class PixelBuffer;
44 class PopupMenu;
45 
46 class PopupMenu_Impl;
47 
49 class CL_API_GUI PopupMenu
50 {
53 public:
54  PopupMenu();
55 
56  virtual ~PopupMenu();
57 
61  static PopupMenu create_null_object();
62 
66 public:
68  bool is_null() const { return !impl; }
69 
71  void throw_if_null() const;
72 
76  std::string get_class() const;
77 
83  PopupMenuItem get_item(int id);
84 
90  PopupMenuItem get_item_at(int index);
91 
95  int get_item_count() const;
96 
100  int get_minimum_width() const;
101 
105  virtual Size get_css_size() const;
106 
110 public:
112  Callback_v0 &func_close();
113 
117 public:
119  void start(GUIComponent *parent, const Point &pos);
120 
128  PopupMenuItem insert_item(const std::string &text, int id = -1, int index = -1);
129 
136  PopupMenuItem insert_item_accel(const std::string &text, const std::string &accel_text="", int id = -1, int index = -1);
137 
143  PopupMenuItem insert_separator(int index = -1);
144 
148  void set_minimum_width(int width_pixels);
149 
153  void set_maximum_height(int height_pixels);
154 
158  void set_class_name(const std::string &class_name);
159 
161  int find_item(const std::string &text, bool case_sensitive = false);
162 
166  void clear();
167 
171 private:
172  std::shared_ptr<PopupMenu_Impl> impl;
173 
174  friend class MenuBar;
175  friend class MenuBar_Impl;
176  friend class PopupMenuWindow;
178 };
179 
180 }
181 
GUI base component class.
Definition: gui_component.h:81
Pop-up menu.
Definition: popupmenu.h:49
2D (x,y) point structure - Integer
Definition: point.h:63
Popup menu item.
Definition: popupmenu_item.h:46
2D (width,height) size structure - Integer
Definition: size.h:157
bool is_null() const
Returns true if this object is invalid.
Definition: popupmenu.h:68
Menu bar component.
Definition: menubar.h:45
Callback_v0.
Definition: callback_v0.h:152