gui_component.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "api_gui.h"
00036 #include "../Core/System/sharedptr.h"
00037 #include "../Core/Signals/callback_0.h"
00038 #include "../Core/Signals/callback_1.h"
00039 #include "../Core/Signals/callback_v0.h"
00040 #include "../Core/Signals/callback_v1.h"
00041 #include "../Core/Signals/callback_v2.h"
00042 #include "../Core/Signals/callback_v3.h"
00043 #include "../Core/Signals/callback_2.h"
00044 #include "../Core/IOData/virtual_directory.h"
00045 #include "../Display/Window/display_window_description.h"
00046 #include "../Display/Window/display_window.h"
00047 #include "../Display/Render/graphic_context.h"
00048 #include "../Display/Window/input_context.h"
00049 #include "gui_layout.h"
00050 #include <vector>
00051 
00052 class CL_DomDocument;
00053 class CL_GraphicContext;
00054 class CL_InputContext;
00055 class CL_InputEvent;
00056 class CL_Cursor;
00057 class CL_GUIMessage;
00058 class CL_GUIManager;
00059 class CL_GUITheme;
00060 class CL_ResourceManager;
00061 class CL_GUIConsumedKeys;
00062 class CL_CSSLayout;
00063 class CL_CSSLayoutElement;
00064 class CL_GUIComponent_Impl;
00065 
00066 typedef CL_DisplayWindowDescription CL_GUITopLevelDescription;
00067 
00071 class CL_API_GUI CL_GUIComponent
00072 {
00075 public:
00077         CL_GUIComponent(CL_GUIComponent *parent);
00078 
00083         CL_GUIComponent(CL_GUIManager *manager, CL_GUITopLevelDescription description);
00084 
00089         CL_GUIComponent(CL_GUIComponent *owner, CL_GUITopLevelDescription description);
00090 
00091         virtual ~CL_GUIComponent();
00092 
00096 public:
00098         CL_Rect get_geometry() const;
00099 
00101         int get_width() const;
00102 
00104         int get_height() const;
00105 
00107         CL_Size get_size() const;
00108 
00110         CL_Rect get_window_geometry() const;
00111 
00113         CL_StringRef get_type_name() const;
00114 
00116         CL_StringRef get_class_name() const;
00117 
00119         CL_StringRef get_id_name() const;
00120 
00122         CL_StringRef get_element_name() const;
00123 
00125         bool has_focus() const;
00126 
00128         bool get_allow_resize() const;
00129 
00131         bool get_clip_children() const;
00132 
00134         enum FocusPolicy
00135         {
00136                 focus_refuse,
00137                 focus_local,
00138                 focus_group,
00139                 focus_parent
00140         };
00141 
00143         FocusPolicy get_focus_policy() const;
00144 
00146         CL_StringRef get_component_group_name() const;
00147 
00149         bool is_selected_in_group() const;
00150 
00152         bool get_blocks_default_action() const;
00153 
00155         CL_ResourceManager get_resources() const;
00156 
00158         CL_GUIManager get_gui_manager() const;
00159 
00161         CL_GUITheme get_theme() const;
00162 
00164 
00165         const CL_GUIComponent *get_parent_component() const;
00166 
00170         CL_GUIComponent *get_parent_component();
00171 
00173 
00174         const CL_GUIComponent *get_owner_component() const;
00175 
00179         CL_GUIComponent *get_owner_component();
00180 
00182         std::vector<CL_GUIComponent*> get_child_components() const;
00183 
00185         const CL_GUIComponent *get_first_child() const;
00186 
00190         CL_GUIComponent *get_first_child();
00191 
00193         const CL_GUIComponent *get_last_child() const;
00194 
00196         CL_GUIComponent *get_next_component_in_tree();
00197 
00199         CL_GUIComponent *get_previous_component_in_tree();
00200 
00204         CL_GUIComponent *get_last_child();
00205 
00207         std::vector<CL_GUIComponent*> get_child_component_group(const CL_String &group_name) const;
00208 
00210         CL_GUIComponent *get_group_selected_component();
00211 
00213         CL_GUIComponent *get_named_item(const CL_StringRef &id);
00214 
00216         bool has_child_components() const;
00217 
00219         const CL_GUIComponent *get_previous_sibling() const;
00220 
00224         CL_GUIComponent *get_previous_sibling();
00225 
00227         const CL_GUIComponent *get_next_sibling() const;
00228 
00232         CL_GUIComponent *get_next_sibling();
00233 
00237         bool is_descendant_of(CL_GUIComponent *component);
00238 
00242         bool is_ancestor_of(CL_GUIComponent *component);
00243 
00245         const CL_GUIComponent *get_top_level_component() const;
00246 
00250         CL_GUIComponent *get_top_level_component();
00251 
00253         CL_GraphicContext& get_gc();
00254 
00256         CL_InputContext& get_ic();
00257 
00259         bool is_enabled() const;
00260 
00262         bool is_visible() const;
00263 
00265         bool is_active() const;
00266 
00268         CL_GUIComponent *get_component_at(const CL_Point &point);
00269 
00271         virtual CL_Size get_preferred_size() const;
00272 
00274         int get_preferred_width() const;
00275 
00277         int get_preferred_height() const;
00278 
00280         CL_Point window_to_component_coords(const CL_Point &window_point) const;
00281 
00283         CL_Rect window_to_component_coords(const CL_Rect &window_rect) const;
00284 
00286         CL_Point component_to_window_coords(const CL_Point &component_point) const;
00287 
00289         CL_Rect component_to_window_coords(const CL_Rect &component_rect) const;
00290 
00292         CL_Point screen_to_component_coords(const CL_Point &screen_point) const;
00293 
00295         CL_Point component_to_screen_coords(const CL_Point &component_point) const;
00296 
00298         CL_GUILayout get_layout() const;
00299 
00301         CL_DisplayWindow get_display_window() const;
00302 
00304         bool is_default();
00305 
00307         bool is_cancel();
00308 
00310         bool is_double_click_enabled() const;
00311 
00313         bool get_constant_repaint() const;
00314 
00316         CL_CSSLayout get_css_layout();
00317 
00319         CL_CSSLayoutElement get_css_element();
00320 
00324 public:
00326         CL_Callback_v2<CL_GraphicContext &, const CL_Rect &> &func_render();
00327 
00329         CL_Callback_v1<CL_GUIMessage &> &func_process_message();
00330 
00332         CL_Callback_0<bool> &func_close();
00333 
00335         CL_Callback_0<bool> &func_activated();
00336 
00338         CL_Callback_0<bool> &func_deactivated();
00339 
00341         CL_Callback_0<bool> &func_focus_lost();
00342 
00344         CL_Callback_0<bool> &func_focus_gained();
00345 
00347         CL_Callback_0<bool> &func_pointer_enter();
00348 
00350         CL_Callback_0<bool> &func_pointer_exit();
00351 
00353         CL_Callback_v1<CL_GUIMessage&> &func_filter_message();
00354 
00356         CL_Callback_1<bool, const CL_InputEvent &> &func_input();
00357 
00359         CL_Callback_1<bool, const CL_InputEvent &> &func_input_pressed();
00360 
00362         CL_Callback_1<bool, const CL_InputEvent &> &func_input_released();
00363 
00365         CL_Callback_1<bool, const CL_InputEvent &> &func_input_doubleclick();
00366 
00368         CL_Callback_1<bool, const CL_InputEvent &> &func_input_pointer_moved();
00369 
00371         CL_Callback_v1<bool> &func_visibility_change();
00372 
00374         CL_Callback_v0 &func_style_changed();
00375 
00377         CL_Callback_v0 &func_enablemode_changed();
00378 
00380         CL_Callback_v0 &func_resized();
00381 
00383         CL_Callback_v1<CL_Rect &> &func_constrain_resize();
00384 
00386 
00389         virtual CL_Callback_2<CL_GUIComponent*, CL_GUIComponent*, CL_String> &func_create_custom_component();
00390 
00394 public:
00396         void render(CL_GraphicContext &gc, const CL_Rect &clip_rect, bool include_children = true);
00397 
00399 
00401         void paint();
00402 
00406         void paint(const CL_Rect &clip_rect);
00407 
00409         int exec();
00410 
00412 
00414         void exit_with_code(int exit_code);
00415 
00417         void set_geometry(CL_Rect geometry);
00418 
00420         void set_window_geometry(CL_Rect geometry);
00421 
00423         void set_type_name(const CL_StringRef &name); 
00424 
00426         void set_class_name(const CL_StringRef &name);
00427 
00429         void set_id_name(const CL_StringRef &name);
00430 
00432         void set_enabled(bool enable = true);
00433 
00435         void set_clip_children(bool clip = true, const CL_Rect &clip_rect=CL_Rect(0,0,0,0));
00436 
00441         void set_visible(bool visible = true, bool activate_root_win=true);
00442 
00446         void set_focus(bool enable = true);
00447 
00449         void capture_mouse(bool capture);
00450 
00452         void capture_proximity(bool capture);
00453 
00455         void set_focus_policy(FocusPolicy policy);
00456 
00458         void set_double_click_enabled(bool enable);
00459 
00463         void set_component_group_name(const CL_StringRef &str);
00464 
00466         void set_selected_in_component_group(bool selected);
00467 
00469         void create_components(const CL_DomDocument &gui_xml);
00470 
00474         void create_components(const CL_StringRef &fullname);
00475 
00479         void create_components(CL_IODevice &file);
00480 
00485         void create_components(const CL_StringRef &filename, const CL_VirtualDirectory &dir);
00486 
00487         // Request an asynchronous redraw of the specified area.
00488         void request_repaint();
00489 
00493         void request_repaint(CL_Rect rect);
00494 
00496         void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect);
00497 
00499         void reset_cliprect(CL_GraphicContext &gc);
00500 
00502         void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect);
00503 
00505         void pop_cliprect(CL_GraphicContext &gc);
00506 
00508         void delete_child_components();
00509 
00511         void set_parent_component(CL_GUIComponent *new_parent);
00512 
00514         void set_layout(CL_GUILayout &layout);
00515 
00517         void set_cursor(const CL_Cursor &cursor);
00518 
00522         void set_cursor(enum CL_StandardCursor type);
00523 
00525         void focus_next();
00526 
00528         void focus_previous();
00529 
00531 
00532         void set_default(bool value);
00533 
00535 
00536         void set_cancel(bool value);
00537 
00539         void set_blocks_default_action(bool block);
00540 
00542         void set_constant_repaint(bool enable);
00543 
00545         void load_css_layout(const CL_String &xml_filename, const CL_String &css_filename);
00546 
00550 private:
00551         CL_SharedPtr<CL_GUIComponent_Impl> impl;
00552 
00556         CL_GUIComponent(CL_GUIComponent &other);
00557 
00558         CL_GUIComponent &operator =(const CL_GUIComponent &other);
00559 
00560         CL_GraphicContext dummy_gc;
00561         CL_InputContext dummy_ic;
00562 
00563         friend class CL_GUIManager_Impl;
00564 
00565         friend class CL_GUIComponent_Impl;
00566 
00567         friend class CL_Window;
00568 
00569         friend class CL_Window_Impl;
00571 };
00572