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;
68 class CSSComputedValues;
70 
72 
74 {
75  float top;
76  float baseline;
77  float bottom;
78 };
79 
81 class CL_API_GUI GUIComponent
82 {
85 public:
87  GUIComponent(GUIComponent *parent, const std::string &tag_name = "component");
88 
93  GUIComponent(GUIManager *manager, const GUITopLevelDescription &description, const std::string &tag_name = "window");
94 
99  GUIComponent(GUIComponent *owner, const GUITopLevelDescription &description, const std::string &tag_name = "window");
100 
101  virtual ~GUIComponent();
102 
106 public:
110  Rect get_geometry() const;
111 
113  Rect get_viewport() const;
114 
116  Rect get_content_box() const;
117 
119  int get_width() const;
120 
122  int get_height() const;
123 
125  Size get_size() const;
126 
128  Rect get_window_geometry() const;
129 
131  std::string get_tag_name() const;
132 
134  std::string get_id() const;
135 
137  bool get_class(const std::string &name) const;
138 
140  bool get_pseudo_class(const std::string &name) const;
141 
143  std::vector<std::string> get_classes() const;
144 
146  std::vector<std::string> get_pseudo_classes() const;
147 
149  const CSSComputedValues &get_css_values() const;
150 
152  bool has_focus() const;
153 
155  bool get_allow_resize() const;
156 
158  bool get_clip_children() const;
159 
162  {
166  focus_parent
167  };
168 
170  FocusPolicy get_focus_policy() const;
171 
173  std::string get_component_group_name() const;
174 
176  bool is_selected_in_group() const;
177 
179  bool get_blocks_default_action() const;
180 
182  ResourceManager get_resources() const;
183 
185  GUIManager get_gui_manager() const;
186 
188 
189  const GUIComponent *get_parent_component() const;
190 
194  GUIComponent *get_parent_component();
195 
197 
198  const GUIComponent *get_owner_component() const;
199 
203  GUIComponent *get_owner_component();
204 
206  std::vector<GUIComponent*> get_child_components() const;
207 
209  const GUIComponent *get_first_child() const;
210 
214  GUIComponent *get_first_child();
215 
217  const GUIComponent *get_last_child() const;
218 
220  GUIComponent *get_next_component_in_tree();
221 
223  GUIComponent *get_previous_component_in_tree();
224 
228  GUIComponent *get_last_child();
229 
231  std::vector<GUIComponent*> get_child_component_group(const std::string &group_name) const;
232 
234  GUIComponent *get_group_selected_component();
235 
237  GUIComponent *get_named_item(const std::string &id);
238 
240  bool has_child_components() const;
241 
243  const GUIComponent *get_previous_sibling() const;
244 
248  GUIComponent *get_previous_sibling();
249 
251  const GUIComponent *get_next_sibling() const;
252 
256  GUIComponent *get_next_sibling();
257 
261  bool is_descendant_of(GUIComponent *component);
262 
266  bool is_ancestor_of(GUIComponent *component);
267 
269  const GUIComponent *get_top_level_component() const;
270 
272  GUITopLevelWindow *get_top_level_window() const;
273 
277  GUIComponent *get_top_level_component();
278 
280  Canvas get_canvas() const;
281 
283  InputContext get_ic();
284 
286  bool is_enabled() const;
287 
289  bool is_visible() const;
290 
292  bool is_active() const;
293 
295  GUIComponent *get_component_at(const Point &point);
296 
300  virtual float get_preferred_content_width();
301 
305  virtual float get_preferred_content_height(float width);
306 
308  Point window_to_component_coords(const Point &window_point) const;
309 
311  Rect window_to_component_coords(const Rect &window_rect) const;
312 
314  Point component_to_window_coords(const Point &component_point) const;
315 
317  Rect component_to_window_coords(const Rect &component_rect) const;
318 
320  Point screen_to_component_coords(const Point &screen_point) const;
321 
323  Point component_to_screen_coords(const Point &component_point) const;
324 
326  GUILayout get_layout() const;
327 
329  DisplayWindow get_display_window() const;
330 
332  bool is_default();
333 
335  bool is_cancel();
336 
338  bool is_double_click_enabled() const;
339 
341  bool get_constant_repaint() const;
342 
344  Font get_font() const;
345 
347  Rect get_render_text_box(Canvas &canvas, const std::string &str) const;
348 
350  Size get_render_text_size(Canvas &canvas, const std::string &str) const;
351 
353  Rect get_render_text_span_box(Canvas &canvas, const std::string &str, const Rect &content_rect) const;
354 
356  Rect get_content_shrink_box() const;
357 
359  std::string get_property(const std::string &property, const std::string &default_value) const;
360 
362  int get_property_int(const std::string &property, const std::string &default_value) const;
363 
367 public:
370 
372  Callback_v1<std::shared_ptr<GUIMessage> &> &func_process_message();
373 
375  Callback_0<bool> &func_close();
376 
378  Callback_0<bool> &func_activated();
379 
381  Callback_0<bool> &func_deactivated();
382 
384  Callback_0<bool> &func_focus_lost();
385 
387  Callback_0<bool> &func_focus_gained();
388 
390  Callback_0<bool> &func_pointer_enter();
391 
393  Callback_0<bool> &func_pointer_exit();
394 
396  Callback_v1<std::shared_ptr<GUIMessage> &> &func_filter_message();
397 
400 
402  Callback_1<bool, const InputEvent &> &func_input_pressed();
403 
405  Callback_1<bool, const InputEvent &> &func_input_released();
406 
408  Callback_1<bool, const InputEvent &> &func_input_doubleclick();
409 
411  Callback_1<bool, const InputEvent &> &func_input_pointer_moved();
412 
414  Callback_v1<bool> &func_visibility_change();
415 
417  Signal_v0 &sig_style_changed();
418 
420  Callback_v0 &func_enablemode_changed();
421 
423  Callback_v0 &func_resized();
424 
426  Callback_v1<Rect &> &func_constrain_resize();
427 
429 
432  virtual Callback_2<GUIComponent*, GUIComponent*, std::string> &func_create_custom_component();
433 
437 public:
439  void render(Canvas &canvas, const Rect &clip_rect, bool include_children = true);
440 
442 
444  void paint();
445 
449  void paint(const Rect &clip_rect);
450 
452  int exec();
453 
455 
457  void exit_with_code(int exit_code);
458 
460  void set_geometry(Rect geometry);
461 
463  void reset_geometry();
464 
466  void set_window_geometry(Rect geometry, bool client_area = false);
467 
469  void set_tag_name(const std::string &name);
470 
474  bool set_class(const std::string &name, bool enable);
475 
477  void set_id(const std::string &name);
478 
482  void set_style(const std::string &name);
483 
485  void set_style(const CSSPropertyValue &value, bool enable);
486 
490  bool set_pseudo_class(const std::string &name, bool enable);
491 
493  void update_layout();
494 
496  void set_enabled(bool enable = true);
497 
499  void set_clip_children(bool clip = true, const Rect &clip_rect=Rect(0,0,0,0));
500 
505  void set_visible(bool visible = true, bool activate_root_win=true);
506 
510  void set_focus(bool enable = true);
511 
513  void capture_mouse(bool capture);
514 
516  void capture_proximity(bool capture);
517 
519  void set_focus_policy(FocusPolicy policy);
520 
522  void set_double_click_enabled(bool enable);
523 
527  void set_component_group_name(const std::string &str);
528 
530  void set_selected_in_component_group(bool selected);
531 
533  void create_components(const DomDocument &gui_xml);
534 
538  void create_components(const std::string &fullname);
539 
543  void create_components(IODevice &file);
544 
549  void create_components(const std::string &filename, const FileSystem &fs);
550 
551  // Request an asynchronous redraw of the specified area.
552  void request_repaint();
553 
557  void request_repaint(Rect rect);
558 
560  void set_cliprect(Canvas &canvas, const Rect &rect);
561 
563  void reset_cliprect(Canvas &canvas);
564 
566  void push_cliprect(Canvas &canvas, const Rect &rect);
567 
569  void pop_cliprect(Canvas &canvas);
570 
572  void delete_child_components();
573 
575  void set_parent_component(GUIComponent *new_parent);
576 
578  void set_layout(GUILayout &layout);
579 
581  void set_cursor(const Cursor &cursor);
582 
586  void set_cursor(enum StandardCursor type);
587 
589  void focus_next();
590 
592  void focus_previous();
593 
595 
596  void set_default(bool value);
597 
599 
600  void set_cancel(bool value);
601 
603  void set_blocks_default_action(bool block);
604 
606  void set_constant_repaint(bool enable);
607 
608  Rect render_text_span(Canvas &canvas, const std::string &text, const Rect &content_rect);
609  Rect render_text(Canvas &canvas, const std::string &text);
610  Rect render_text(Canvas &canvas, const std::string &text, int xpos, int baseline);
611 
613  VerticalTextPosition get_vertical_text_align(Canvas &canvas);
614 
616  VerticalTextPosition get_vertical_text_align(Canvas &canvas, const Rect &rect);
617 
621 public:
622  std::unique_ptr<GUIComponent_Impl> impl;
623 
624 private:
628  GUIComponent(GUIComponent &other);
629 
630  GUIComponent &operator =(const GUIComponent &other);
631 
633 };
634 
635 }
636 
Definition: css_computed_values.h:58
DisplayWindowDescription GUITopLevelDescription
Definition: gui_component.h:69
StandardCursor
Standard Cursor.
Definition: display_window.h:67
2D Graphics Canvas
Definition: canvas.h:70
Definition: gui_component.h:165
I/O Device interface.
Definition: iodevice.h:51
Definition: gui_component.h:73
Mouse cursor class.
Definition: cursor.h:48
Layout management base class.
Definition: gui_layout.h:47
float baseline
Definition: gui_component.h:76
std::unique_ptr< GUIComponent_Impl > impl
Definition: gui_component.h:622
GUI base component class.
Definition: gui_component.h:81
DOM Document class.
Definition: dom_document.h:65
float bottom
Definition: gui_component.h:77
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
Callback_v2.
Definition: callback_v2.h:156
Definition: gui_component.h:163
Virtual File System (VFS).
Definition: file_system.h:48
Resource manager.
Definition: resource_manager.h:45
FocusPolicy
Focus policies.
Definition: gui_component.h:161
Definition: gui_component.h:164
Callback_v1.
Definition: callback_v1.h:156
GUI manager.
Definition: gui_manager.h:64
Definition: css_property_value.h:41
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:75
Callback_v0.
Definition: callback_v0.h:152