Boost.UI
User Interface Boost library
widget.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_WIDGET_HPP
9 #define BOOST_UI_WIDGET_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/coord.hpp>
18 #include <boost/ui/string.hpp>
19 #include <boost/ui/event.hpp>
20 #include <boost/ui/font.hpp>
21 #include <boost/ui/layout.hpp>
22 #include <boost/ui/detail/shared_count.hpp>
23 #include <boost/ui/detail/event.hpp>
24 
26 namespace boost {
28 namespace ui {
29 
30 
31 #ifndef DOXYGEN
32 
33 namespace detail {
34 class widget_detail_base;
35 } // namespace detail
36 
37 #endif
38 
44 
45 class BOOST_UI_DECL widget
46 {
47 public:
48  widget();
49  virtual ~widget();
50 
51 #ifndef DOXYGEN
52  widget(const widget& other);
53  widget& operator=(const widget& other);
54 #endif
55 
58  { return ui::layout::item(*this); }
59 
61  widget& append(const widget& w);
63  { return append(w); }
65 
67  widget& move(coord_type x, coord_type y);
68  widget& move(const point& pos)
69  { move(pos.x(), pos.y()); return *this; }
71 
73  widget& resize(coord_type width, coord_type height);
74 
76  coord_type x() const;
77 
79  coord_type y() const;
80 
82  coord_type width() const;
83 
85  coord_type height() const;
86 
88  point pos() const { return point(x(), y()); }
89 
91  size dimensions() const
92  { return size(width(), height()); }
93 
95  rect bounds() const
96  { return rect(x(), y(), width(), height()); }
97 
99  widget& enable(bool do_enable = true);
100 
102  widget& disable() { return enable(false); }
103 
105  bool is_enabled() const;
106 
108  widget& show(bool do_show = true);
109 
111  widget& hide() { return show(false); }
112 
114  bool is_shown() const;
115 
118  widget& tooltip(const uistring& text);
119 
121  uistring tooltip() const;
122 
124  widget& font(const ui::font& f);
125 
127  ui::font font() const;
128 
130  BOOST_UI_DETAIL_HANDLER(resize, widget);
132 
134  BOOST_UI_DETAIL_HANDLER(key_press, widget);
135  BOOST_UI_DETAIL_HANDLER_EVENT(key_press_event, widget, key_event);
136  BOOST_UI_DETAIL_HANDLER(key_down, widget);
137  BOOST_UI_DETAIL_HANDLER_EVENT(key_down_event, widget, key_event);
138  BOOST_UI_DETAIL_HANDLER(key_up, widget);
139  BOOST_UI_DETAIL_HANDLER_EVENT(key_up_event, widget, key_event);
141 
143  BOOST_UI_DETAIL_HANDLER(left_mouse_down, widget);
144  BOOST_UI_DETAIL_HANDLER_EVENT(left_mouse_down_event, widget, mouse_event);
145  BOOST_UI_DETAIL_HANDLER(left_mouse_up, widget);
146  BOOST_UI_DETAIL_HANDLER_EVENT(left_mouse_up_event, widget, mouse_event);
147  BOOST_UI_DETAIL_HANDLER(right_mouse_down, widget);
148  BOOST_UI_DETAIL_HANDLER_EVENT(right_mouse_down_event, widget, mouse_event);
149  BOOST_UI_DETAIL_HANDLER(right_mouse_up, widget);
150  BOOST_UI_DETAIL_HANDLER_EVENT(right_mouse_up_event, widget, mouse_event);
151  BOOST_UI_DETAIL_HANDLER(middle_mouse_down, widget);
152  BOOST_UI_DETAIL_HANDLER_EVENT(middle_mouse_down_event, widget, mouse_event);
153  BOOST_UI_DETAIL_HANDLER(middle_mouse_up, widget);
154  BOOST_UI_DETAIL_HANDLER_EVENT(middle_mouse_up_event, widget, mouse_event);
155  BOOST_UI_DETAIL_HANDLER(left_mouse_double_click, widget);
156  BOOST_UI_DETAIL_HANDLER_EVENT(left_mouse_double_click_event, widget, mouse_event);
157  BOOST_UI_DETAIL_HANDLER(right_mouse_double_click, widget);
158  BOOST_UI_DETAIL_HANDLER_EVENT(right_mouse_double_click_event, widget, mouse_event);
159  BOOST_UI_DETAIL_HANDLER(middle_mouse_double_click, widget);
160  BOOST_UI_DETAIL_HANDLER_EVENT(middle_mouse_double_click_event, widget, mouse_event);
161  BOOST_UI_DETAIL_HANDLER(mouse_move, widget);
162  BOOST_UI_DETAIL_HANDLER_EVENT(mouse_move_event, widget, mouse_event);
163  BOOST_UI_DETAIL_HANDLER(mouse_drag, widget);
164  BOOST_UI_DETAIL_HANDLER_EVENT(mouse_drag_event, widget, mouse_event);
165  BOOST_UI_DETAIL_HANDLER(mouse_enter, widget);
166  BOOST_UI_DETAIL_HANDLER_EVENT(mouse_enter_event, widget, mouse_event);
167  BOOST_UI_DETAIL_HANDLER(mouse_leave, widget);
168  BOOST_UI_DETAIL_HANDLER_EVENT(mouse_leave_event, widget, mouse_event);
169  BOOST_UI_DETAIL_HANDLER(context_menu, widget);
170  BOOST_UI_DETAIL_HANDLER_EVENT(context_menu_event, widget, mouse_event);
171  BOOST_UI_DETAIL_HANDLER(mouse_wheel, widget);
172  BOOST_UI_DETAIL_HANDLER_EVENT(mouse_wheel_event, widget, wheel_event);
174 
176  bool native_valid() const BOOST_NOEXCEPT { return native_handle() != NULL; }
177 
179  typedef void* native_handle_type;
180 
182  native_handle_type native_handle();
183  const native_handle_type native_handle() const;
185 
186 protected:
187 #ifndef DOXYGEN
188  void detail_set_detail_impl(detail::widget_detail_base* d);
189  template <class TDetail>
190  TDetail* get_detail_impl() { return dynamic_cast<TDetail*>(m_detail_impl); }
191  template <class TDetail>
192  const TDetail* get_detail_impl() const { return dynamic_cast<const TDetail*>(m_detail_impl); }
193 #endif
194 
195 private:
196  void delete_last_detail_impl();
197 
198  void on_resize_raw(const boost::function<void()>& hanlder);
199 
200  void on_key_press_raw(const boost::function<void()>& handler);
201  void on_key_press_event_raw(const boost::function<void(key_event&)>& handler);
202  void on_key_down_raw(const boost::function<void()>& handler);
203  void on_key_down_event_raw(const boost::function<void(key_event&)>& handler);
204  void on_key_up_raw(const boost::function<void()>& handler);
205  void on_key_up_event_raw(const boost::function<void(key_event&)>& handler);
206 
207  void on_left_mouse_down_raw(const boost::function<void()>& handler);
208  void on_left_mouse_down_event_raw(const boost::function<void(mouse_event&)>& handler);
209  void on_left_mouse_up_raw(const boost::function<void()>& handler);
210  void on_left_mouse_up_event_raw(const boost::function<void(mouse_event&)>& handler);
211  void on_right_mouse_down_raw(const boost::function<void()>& handler);
212  void on_right_mouse_down_event_raw(const boost::function<void(mouse_event&)>& handler);
213  void on_right_mouse_up_raw(const boost::function<void()>& handler);
214  void on_right_mouse_up_event_raw(const boost::function<void(mouse_event&)>& handler);
215  void on_middle_mouse_down_raw(const boost::function<void()>& handler);
216  void on_middle_mouse_down_event_raw(const boost::function<void(mouse_event&)>& handler);
217  void on_middle_mouse_up_raw(const boost::function<void()>& handler);
218  void on_middle_mouse_up_event_raw(const boost::function<void(mouse_event&)>& handler);
219  void on_left_mouse_double_click_raw(const boost::function<void()>& handler);
220  void on_left_mouse_double_click_event_raw(const boost::function<void(mouse_event&)>& handler);
221  void on_right_mouse_double_click_raw(const boost::function<void()>& handler);
222  void on_right_mouse_double_click_event_raw(const boost::function<void(mouse_event&)>& handler);
223  void on_middle_mouse_double_click_raw(const boost::function<void()>& handler);
224  void on_middle_mouse_double_click_event_raw(const boost::function<void(mouse_event&)>& handler);
225  void on_mouse_move_raw(const boost::function<void()>& handler);
226  void on_mouse_move_event_raw(const boost::function<void(mouse_event&)>& handler);
227  void on_mouse_drag_raw(const boost::function<void()>& handler);
228  void on_mouse_drag_event_raw(const boost::function<void(mouse_event&)>& handler);
229  void on_mouse_enter_raw(const boost::function<void()>& handler);
230  void on_mouse_enter_event_raw(const boost::function<void(mouse_event&)>& handler);
231  void on_mouse_leave_raw(const boost::function<void()>& handler);
232  void on_mouse_leave_event_raw(const boost::function<void(mouse_event&)>& handler);
233  void on_context_menu_raw(const boost::function<void()>& handler);
234  void on_context_menu_event_raw(const boost::function<void(mouse_event&)>& handler);
235  void on_mouse_wheel_raw(const boost::function<void()>& handler);
236  void on_mouse_wheel_event_raw(const boost::function<void(wheel_event&)>& handler);
237 
238  detail::widget_detail_base* m_detail_impl;
239  detail::shared_count m_shared_count;
240 
241 #ifndef DOXYGEN
242  friend class native_helper;
243 #endif
244 };
245 
248 
249 class BOOST_UI_DECL native_widget : public widget
250 {
251 public:
253  explicit native_widget(native_handle_type handle);
254 };
255 
256 } // namespace ui
257 } // namespace boost
258 
259 #endif // BOOST_UI_WIDGET_HPP
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
boost::ui::basic_point::y
T y() const
Returns y coordinate.
Definition: coord.hpp:179
boost::ui::rect
basic_rect< coord_type > rect
2D rectangle coordinates
Definition: coord.hpp:424
boost::ui::widget::move
widget & move(const point &pos)
Moves widget to specified position.
Definition: widget.hpp:68
boost::ui::basic_point
2D point data structure with custom coordinates type
Definition: coord.hpp:119
config.hpp
Configuration options.
font.hpp
Font class.
boost::ui::widget::layout
ui::layout::item layout()
Returns layout::item with this widget.
Definition: widget.hpp:57
event.hpp
Event classes.
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::native_widget
Widget that wraps previously created native widget.
Definition: widget.hpp:249
boost::ui::mouse_event
Mouse event class that holds information about mouse when event was generated.
Definition: event.hpp:144
boost::ui::size
basic_size< coord_type > size
2D size coordinates
Definition: coord.hpp:416
boost::ui::basic_point::x
T x() const
Returns x coordinate.
Definition: coord.hpp:171
string.hpp
String class and operations.
boost::ui::widget::operator<<
widget & operator<<(const widget &w)
Creates native widget and appends it to this widget.
Definition: widget.hpp:62
boost::ui::widget::native_valid
bool native_valid() const noexcept
Returns true only if native widget was created.
Definition: widget.hpp:176
boost::ui::point
basic_point< coord_type > point
2D point coordinates
Definition: coord.hpp:420
boost::ui::widget::hide
widget & hide()
Hides widget.
Definition: widget.hpp:111
boost::ui::widget::pos
point pos() const
Returns widget position relative to the parent widget client area.
Definition: widget.hpp:88
layout.hpp
Layout classes.
boost::ui::layout::item
Layout item with arrangement parameters.
Definition: layout.hpp:35
boost::ui::coord_type
int coord_type
Widget coordinates signed number type.
Definition: coord.hpp:412
boost::ui::basic_size
2D size of object data structure with custom coordinates type
Definition: coord.hpp:48
boost::ui::wheel_event
Mouse wheel event class.
Definition: event.hpp:180
boost::ui::key_event
Keyboard event class that holds information about keyboard when event was generated.
Definition: event.hpp:113
boost::ui::widget::dimensions
size dimensions() const
Returns widget size.
Definition: widget.hpp:91
boost::ui::basic_rect
2D rectangle plane figure data structure with custom coordinates type
Definition: coord.hpp:259
boost::ui::widget
Base class for all widgets.
Definition: widget.hpp:45
boost::ui::widget::native_handle_type
void * native_handle_type
Implementation-defined widget type.
Definition: widget.hpp:179
boost::ui::widget::bounds
rect bounds() const
Returns widget bounds in client coordinates.
Definition: widget.hpp:95
boost::ui::font
Font class.
Definition: font.hpp:30
coord.hpp
Coordinates classes.
boost::ui::widget::disable
widget & disable()
Disables widget.
Definition: widget.hpp:102