ClanLib  2.3.7
gui_component.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 
32 
33 #pragma once
34 
35 #include "api_gui.h"
36 #include "../Core/System/sharedptr.h"
37 #include "../Core/Signals/callback_0.h"
38 #include "../Core/Signals/callback_1.h"
39 #include "../Core/Signals/callback_v0.h"
40 #include "../Core/Signals/callback_v1.h"
41 #include "../Core/Signals/callback_v2.h"
42 #include "../Core/Signals/callback_v3.h"
43 #include "../Core/Signals/callback_2.h"
44 #include "../Core/IOData/virtual_directory.h"
45 #include "../Display/Window/display_window_description.h"
46 #include "../Display/Window/display_window.h"
47 #include "../Display/Render/graphic_context.h"
48 #include "../Display/Window/input_context.h"
49 #include "gui_layout.h"
50 #include <vector>
51 
52 class CL_DomDocument;
53 class CL_GraphicContext;
54 class CL_InputContext;
55 class CL_InputEvent;
56 class CL_Cursor;
57 class CL_GUIMessage;
58 class CL_GUIManager;
59 class CL_GUITheme;
60 class CL_ResourceManager;
61 class CL_GUIConsumedKeys;
62 class CL_CSSLayout;
64 class CL_GUIComponent_Impl;
65 
67 
72 {
75 public:
78 
84 
90 
91  virtual ~CL_GUIComponent();
92 
96 public:
98  CL_Rect get_geometry() const;
99 
101  int get_width() const;
102 
104  int get_height() const;
105 
107  CL_Size get_size() const;
108 
110  CL_Rect get_window_geometry() const;
111 
113  CL_StringRef get_type_name() const;
114 
116  CL_StringRef get_class_name() const;
117 
119  CL_StringRef get_id_name() const;
120 
122  CL_StringRef get_element_name() const;
123 
125  bool has_focus() const;
126 
128  bool get_allow_resize() const;
129 
131  bool get_clip_children() const;
132 
135  {
139  focus_parent
140  };
141 
143  FocusPolicy get_focus_policy() const;
144 
146  CL_StringRef get_component_group_name() const;
147 
149  bool is_selected_in_group() const;
150 
152  bool get_blocks_default_action() const;
153 
155  CL_ResourceManager get_resources() const;
156 
158  CL_GUIManager get_gui_manager() const;
159 
161  CL_GUITheme get_theme() const;
162 
164 
165  const CL_GUIComponent *get_parent_component() const;
166 
170  CL_GUIComponent *get_parent_component();
171 
173 
174  const CL_GUIComponent *get_owner_component() const;
175 
179  CL_GUIComponent *get_owner_component();
180 
182  std::vector<CL_GUIComponent*> get_child_components() const;
183 
185  const CL_GUIComponent *get_first_child() const;
186 
190  CL_GUIComponent *get_first_child();
191 
193  const CL_GUIComponent *get_last_child() const;
194 
196  CL_GUIComponent *get_next_component_in_tree();
197 
199  CL_GUIComponent *get_previous_component_in_tree();
200 
204  CL_GUIComponent *get_last_child();
205 
207  std::vector<CL_GUIComponent*> get_child_component_group(const CL_String &group_name) const;
208 
210  CL_GUIComponent *get_group_selected_component();
211 
213  CL_GUIComponent *get_named_item(const CL_StringRef &id);
214 
216  bool has_child_components() const;
217 
219  const CL_GUIComponent *get_previous_sibling() const;
220 
224  CL_GUIComponent *get_previous_sibling();
225 
227  const CL_GUIComponent *get_next_sibling() const;
228 
232  CL_GUIComponent *get_next_sibling();
233 
237  bool is_descendant_of(CL_GUIComponent *component);
238 
242  bool is_ancestor_of(CL_GUIComponent *component);
243 
245  const CL_GUIComponent *get_top_level_component() const;
246 
250  CL_GUIComponent *get_top_level_component();
251 
253  CL_GraphicContext& get_gc();
254 
256  CL_InputContext& get_ic();
257 
259  bool is_enabled() const;
260 
262  bool is_visible() const;
263 
265  bool is_active() const;
266 
268  CL_GUIComponent *get_component_at(const CL_Point &point);
269 
271  virtual CL_Size get_preferred_size() const;
272 
274  int get_preferred_width() const;
275 
277  int get_preferred_height() const;
278 
280  CL_Point window_to_component_coords(const CL_Point &window_point) const;
281 
283  CL_Rect window_to_component_coords(const CL_Rect &window_rect) const;
284 
286  CL_Point component_to_window_coords(const CL_Point &component_point) const;
287 
289  CL_Rect component_to_window_coords(const CL_Rect &component_rect) const;
290 
292  CL_Point screen_to_component_coords(const CL_Point &screen_point) const;
293 
295  CL_Point component_to_screen_coords(const CL_Point &component_point) const;
296 
298  CL_GUILayout get_layout() const;
299 
301  CL_DisplayWindow get_display_window() const;
302 
304  bool is_default();
305 
307  bool is_cancel();
308 
310  bool is_double_click_enabled() const;
311 
313  bool get_constant_repaint() const;
314 
316  CL_CSSLayout get_css_layout();
317 
319  CL_CSSLayoutElement get_css_element();
320 
324 public:
327 
329  CL_Callback_v1<CL_GUIMessage &> &func_process_message();
330 
332  CL_Callback_0<bool> &func_close();
333 
335  CL_Callback_0<bool> &func_activated();
336 
338  CL_Callback_0<bool> &func_deactivated();
339 
341  CL_Callback_0<bool> &func_focus_lost();
342 
344  CL_Callback_0<bool> &func_focus_gained();
345 
347  CL_Callback_0<bool> &func_pointer_enter();
348 
350  CL_Callback_0<bool> &func_pointer_exit();
351 
353  CL_Callback_v1<CL_GUIMessage&> &func_filter_message();
354 
357 
359  CL_Callback_1<bool, const CL_InputEvent &> &func_input_pressed();
360 
362  CL_Callback_1<bool, const CL_InputEvent &> &func_input_released();
363 
365  CL_Callback_1<bool, const CL_InputEvent &> &func_input_doubleclick();
366 
368  CL_Callback_1<bool, const CL_InputEvent &> &func_input_pointer_moved();
369 
371  CL_Callback_v1<bool> &func_visibility_change();
372 
374  CL_Callback_v0 &func_style_changed();
375 
377  CL_Callback_v0 &func_enablemode_changed();
378 
380  CL_Callback_v0 &func_resized();
381 
383  CL_Callback_v1<CL_Rect &> &func_constrain_resize();
384 
386 
389  virtual CL_Callback_2<CL_GUIComponent*, CL_GUIComponent*, CL_String> &func_create_custom_component();
390 
394 public:
396  void render(CL_GraphicContext &gc, const CL_Rect &clip_rect, bool include_children = true);
397 
399 
401  void paint();
402 
406  void paint(const CL_Rect &clip_rect);
407 
409  int exec();
410 
412 
414  void exit_with_code(int exit_code);
415 
417  void set_geometry(CL_Rect geometry);
418 
420  void set_window_geometry(CL_Rect geometry);
421 
423  void set_type_name(const CL_StringRef &name);
424 
426  void set_class_name(const CL_StringRef &name);
427 
429  void set_id_name(const CL_StringRef &name);
430 
432  void set_enabled(bool enable = true);
433 
435  void set_clip_children(bool clip = true, const CL_Rect &clip_rect=CL_Rect(0,0,0,0));
436 
441  void set_visible(bool visible = true, bool activate_root_win=true);
442 
446  void set_focus(bool enable = true);
447 
449  void capture_mouse(bool capture);
450 
452  void capture_proximity(bool capture);
453 
455  void set_focus_policy(FocusPolicy policy);
456 
458  void set_double_click_enabled(bool enable);
459 
463  void set_component_group_name(const CL_StringRef &str);
464 
466  void set_selected_in_component_group(bool selected);
467 
469  void create_components(const CL_DomDocument &gui_xml);
470 
474  void create_components(const CL_StringRef &fullname);
475 
479  void create_components(CL_IODevice &file);
480 
485  void create_components(const CL_StringRef &filename, const CL_VirtualDirectory &dir);
486 
487  // Request an asynchronous redraw of the specified area.
488  void request_repaint();
489 
493  void request_repaint(CL_Rect rect);
494 
496  void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect);
497 
499  void reset_cliprect(CL_GraphicContext &gc);
500 
502  void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect);
503 
505  void pop_cliprect(CL_GraphicContext &gc);
506 
508  void delete_child_components();
509 
511  void set_parent_component(CL_GUIComponent *new_parent);
512 
514  void set_layout(CL_GUILayout &layout);
515 
517  void set_cursor(const CL_Cursor &cursor);
518 
522  void set_cursor(enum CL_StandardCursor type);
523 
525  void focus_next();
526 
528  void focus_previous();
529 
531 
532  void set_default(bool value);
533 
535 
536  void set_cancel(bool value);
537 
539  void set_blocks_default_action(bool block);
540 
542  void set_constant_repaint(bool enable);
543 
545  void load_css_layout(const CL_String &xml_filename, const CL_String &css_filename);
546 
550 private:
551  CL_SharedPtr<CL_GUIComponent_Impl> impl;
552 
557 
558  CL_GUIComponent &operator =(const CL_GUIComponent &other);
559 
560  CL_GraphicContext dummy_gc;
561  CL_InputContext dummy_ic;
562 
563  friend class CL_GUIManager_Impl;
564 
565  friend class CL_GUIComponent_Impl;
566 
567  friend class CL_Window;
568 
569  friend class CL_Window_Impl;
571 };
572