gui_component.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 <memory>
35 #include "../Core/Signals/callback_0.h"
36 #include "../Core/Signals/callback_1.h"
37 #include "../Core/Signals/callback_v0.h"
38 #include "../Core/Signals/callback_v1.h"
39 #include "../Core/Signals/callback_v2.h"
40 #include "../Core/Signals/callback_v3.h"
41 #include "../Core/Signals/callback_2.h"
42 #include "../Core/Signals/signal_v1.h"
43 #include "../Core/IOData/file_system.h"
44 #include "../Display/Window/display_window_description.h"
45 #include "../Display/Window/display_window.h"
46 #include "../Display/Render/graphic_context.h"
47 #include "../Display/Window/input_context.h"
48 #include "../Display/2D/canvas.h"
49 #include "gui_layout.h"
50 #include <vector>
51 
52 namespace clan
53 {
56 
57 class DomDocument;
58 class Canvas;
59 class InputContext;
60 class InputEvent;
61 class Cursor;
62 class GUIMessage;
63 class GUIManager;
64 class GUITopLevelWindow;
65 class ResourceManager;
66 class GUIConsumedKeys;
67 class GUIComponent_Impl;
69 
71 
73 {
74  float top;
75  float baseline;
76  float bottom;
77 };
78 
80 class CL_API_GUI GUIComponent
81 {
84 public:
86  GUIComponent(GUIComponent *parent, const std::string &tag_name = "component");
87 
92  GUIComponent(GUIManager *manager, const GUITopLevelDescription &description, const std::string &tag_name = "window");
93 
98  GUIComponent(GUIComponent *owner, const GUITopLevelDescription &description, const std::string &tag_name = "window");
99 
100  virtual ~GUIComponent();
101 
105 public:
109  Rect get_geometry() const;
110 
112  Rect get_viewport() const;
113 
115  Rect get_content_box() const;
116 
118  int get_width() const;
119 
121  int get_height() const;
122 
124  Size get_size() const;
125 
127  Rect get_window_geometry() const;
128 
130  std::string get_tag_name() const;
131 
133  std::string get_id() const;
134 
136  bool get_class(const std::string &name) const;
137 
139  bool get_pseudo_class(const std::string &name) const;
140 
142  std::vector<std::string> get_classes() const;
143 
145  std::vector<std::string> get_pseudo_classes() const;
146 
148  const CSSComputedValues &get_css_values() const;
149 
151  bool has_focus() const;
152 
154  bool get_allow_resize() const;
155 
157  bool get_clip_children() const;
158 
161  {
165  focus_parent
166  };
167 
169  FocusPolicy get_focus_policy() const;
170 
172  std::string get_component_group_name() const;
173 
175  bool is_selected_in_group() const;
176 
178  bool get_blocks_default_action() const;
179 
181  ResourceManager get_resources() const;
182 
184  GUIManager get_gui_manager() const;
185 
187 
188  const GUIComponent *get_parent_component() const;
189 
193  GUIComponent *get_parent_component();
194 
196 
197  const GUIComponent *get_owner_component() const;
198 
202  GUIComponent *get_owner_component();
203 
205  std::vector<GUIComponent*> get_child_components() const;
206 
208  const GUIComponent *get_first_child() const;
209 
213  GUIComponent *get_first_child();
214 
216  const GUIComponent *get_last_child() const;
217 
219  GUIComponent *get_next_component_in_tree();
220 
222  GUIComponent *get_previous_component_in_tree();
223 
227  GUIComponent *get_last_child();
228 
230  std::vector<GUIComponent*> get_child_component_group(const std::string &group_name) const;
231 
233  GUIComponent *get_group_selected_component();
234 
236  GUIComponent *get_named_item(const std::string &id);
237 
239  bool has_child_components() const;
240 
242  const GUIComponent *get_previous_sibling() const;
243 
247  GUIComponent *get_previous_sibling();
248 
250  const GUIComponent *get_next_sibling() const;
251 
255  GUIComponent *get_next_sibling();
256 
260  bool is_descendant_of(GUIComponent *component);
261 
265  bool is_ancestor_of(GUIComponent *component);
266 
268  const GUIComponent *get_top_level_component() const;
269 
271  GUITopLevelWindow *get_top_level_window() const;
272 
276  GUIComponent *get_top_level_component();
277 
279  Canvas get_canvas() const;
280 
282  InputContext get_ic();
283 
285  bool is_enabled() const;
286 
288  bool is_visible() const;
289 
291  bool is_active() const;
292 
294  GUIComponent *get_component_at(const Point &point);
295 
299  virtual float get_preferred_content_width();
300 
304  virtual float get_preferred_content_height(float width);
305 
307  Point window_to_component_coords(const Point &window_point) const;
308 
310  Rect window_to_component_coords(const Rect &window_rect) const;
311 
313  Point component_to_window_coords(const Point &component_point) const;
314 
316  Rect component_to_window_coords(const Rect &component_rect) const;
317 
319  Point screen_to_component_coords(const Point &screen_point) const;
320 
322  Point component_to_screen_coords(const Point &component_point) const;
323 
325  GUILayout get_layout() const;
326 
328  DisplayWindow get_display_window() const;
329 
331  bool is_default();
332 
334  bool is_cancel();
335 
337  bool is_double_click_enabled() const;
338 
340  bool get_constant_repaint() const;
341 
343  Font get_font() const;
344 
346  Rect get_render_text_box(Canvas &canvas, const std::string &str) const;
347 
349  Size get_render_text_size(Canvas &canvas, const std::string &str) const;
350 
352  Rect get_render_text_span_box(Canvas &canvas, const std::string &str, const Rect &content_rect) const;
353 
355  Rect get_content_shrink_box() const;
356 
358  std::string get_property(const std::string &property, const std::string &default_value) const;
359 
361  int get_property_int(const std::string &property, const std::string &default_value) const;
362 
366 public:
369 
371  Callback_v1<std::shared_ptr<GUIMessage> &> &func_process_message();
372 
374  Callback_0<bool> &func_close();
375 
377  Callback_0<bool> &func_activated();
378 
380  Callback_0<bool> &func_deactivated();
381 
383  Callback_0<bool> &func_focus_lost();
384 
386  Callback_0<bool> &func_focus_gained();
387 
389  Callback_0<bool> &func_pointer_enter();
390 
392  Callback_0<bool> &func_pointer_exit();
393 
395  Callback_v1<std::shared_ptr<GUIMessage> &> &func_filter_message();
396 /*
398  Callback_v1<CSSComputedBox &> &func_apply_properties();
399 */
402 
404  Callback_1<bool, const InputEvent &> &func_input_pressed();
405 
407  Callback_1<bool, const InputEvent &> &func_input_released();
408 
410  Callback_1<bool, const InputEvent &> &func_input_doubleclick();
411 
413  Callback_1<bool, const InputEvent &> &func_input_pointer_moved();
414 
416  Callback_v1<bool> &func_visibility_change();
417 
419  Signal_v0 &sig_style_changed();
420 
422  Callback_v0 &func_enablemode_changed();
423 
425  Callback_v0 &func_resized();
426 
428  Callback_v1<Rect &> &func_constrain_resize();
429 
431 
434  virtual Callback_2<GUIComponent*, GUIComponent*, std::string> &func_create_custom_component();
435 
439 public:
441  void render(Canvas &canvas, const Rect &clip_rect, bool include_children = true);
442 
444 
446  void paint();
447 
451  void paint(const Rect &clip_rect);
452 
454  int exec();
455 
457 
459  void exit_with_code(int exit_code);
460 
462  void set_geometry(Rect geometry);
463 
465  void reset_geometry();
466 
468  void set_window_geometry(Rect geometry, bool client_area = false);
469 
471  void set_tag_name(const std::string &name);
472 
476  bool set_class(const std::string &name, bool enable);
477 
479  void set_id(const std::string &name);
480 
484  bool set_pseudo_class(const std::string &name, bool enable);
485 
487  void update_layout();
488 
490  void set_enabled(bool enable = true);
491 
493  void set_clip_children(bool clip = true, const Rect &clip_rect=Rect(0,0,0,0));
494 
499  void set_visible(bool visible = true, bool activate_root_win=true);
500 
504  void set_focus(bool enable = true);
505 
507  void capture_mouse(bool capture);
508 
510  void capture_proximity(bool capture);
511 
513  void set_focus_policy(FocusPolicy policy);
514 
516  void set_double_click_enabled(bool enable);
517 
521  void set_component_group_name(const std::string &str);
522 
524  void set_selected_in_component_group(bool selected);
525 
527  void create_components(const DomDocument &gui_xml);
528 
532  void create_components(const std::string &fullname);
533 
537  void create_components(IODevice &file);
538 
543  void create_components(const std::string &filename, const FileSystem &fs);
544 
545  // Request an asynchronous redraw of the specified area.
546  void request_repaint();
547 
551  void request_repaint(Rect rect);
552 
554  void set_cliprect(Canvas &canvas, const Rect &rect);
555 
557  void reset_cliprect(Canvas &canvas);
558 
560  void push_cliprect(Canvas &canvas, const Rect &rect);
561 
563  void pop_cliprect(Canvas &canvas);
564 
566  void delete_child_components();
567 
569  void set_parent_component(GUIComponent *new_parent);
570 
572  void set_layout(GUILayout &layout);
573 
575  void set_cursor(const Cursor &cursor);
576 
580  void set_cursor(enum StandardCursor type);
581 
583  void focus_next();
584 
586  void focus_previous();
587 
589 
590  void set_default(bool value);
591 
593 
594  void set_cancel(bool value);
595 
597  void set_blocks_default_action(bool block);
598 
600  void set_constant_repaint(bool enable);
601 
602  Rect render_text_span(Canvas &canvas, const std::string &text, const Rect &content_rect);
603  Rect render_text(Canvas &canvas, const std::string &text);
604  Rect render_text(Canvas &canvas, const std::string &text, int xpos, int baseline);
605 
607  VerticalTextPosition get_vertical_text_align(Canvas &canvas);
608 
610  VerticalTextPosition get_vertical_text_align(Canvas &canvas, const Rect &rect);
611 
615 public:
616  std::unique_ptr<GUIComponent_Impl> impl;
617 
618 private:
622  GUIComponent(GUIComponent &other);
623 
624  GUIComponent &operator =(const GUIComponent &other);
625 
627 };
628 
629 }
630 
Definition: css_computed_values.h:58
DisplayWindowDescription GUITopLevelDescription
Definition: gui_component.h:68
StandardCursor
Standard Cursor.
Definition: display_window.h:67
2D Graphics Canvas
Definition: canvas.h:70
Definition: gui_component.h:164
I/O Device interface.
Definition: iodevice.h:51
Definition: gui_component.h:72
Mouse cursor class.
Definition: cursor.h:48
Layout management base class.
Definition: gui_layout.h:47
float baseline
Definition: gui_component.h:75
std::unique_ptr< GUIComponent_Impl > impl
Definition: gui_component.h:616
GUI base component class.
Definition: gui_component.h:80
DOM Document class.
Definition: dom_document.h:65
float bottom
Definition: gui_component.h:76
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
Callback_v2.
Definition: callback_v2.h:156
Definition: gui_component.h:162
Virtual File System (VFS).
Definition: file_system.h:48
Resource manager.
Definition: resource_manager.h:45
FocusPolicy
Focus policies.
Definition: gui_component.h:160
Definition: gui_component.h:163
Callback_v1.
Definition: callback_v1.h:156
GUI manager.
Definition: gui_manager.h:64
2D (x,y) point structure - Integer
Definition: point.h:63
InputContext.
Definition: input_context.h:45
Callback_2.
Definition: callback_2.h:156
Display window description class.
Definition: display_window_description.h:53
Font class.
Definition: font.h:52
2D (width,height) size structure - Integer
Definition: size.h:157
Signal_v0.
Definition: signal_v0.h:107
Top-level window class.
Definition: display_window.h:85
Callback_1.
Definition: callback_1.h:156
float top
Definition: gui_component.h:74
Callback_v0.
Definition: callback_v0.h:152