ClanLib  2.3.7
css_layout.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 */
28 
29 #pragma once
30 
31 #include "api_csslayout.h"
32 #include "../Core/Signals/callback_2.h"
33 #include "../Core/System/uniqueptr.h"
34 #include <memory>
35 
36 class CL_CSSBoxElement;
37 class CL_GraphicContext;
38 class CL_CSSLayoutObject;
40 class CL_CSSLayoutText;
41 class CL_CSSLayoutNode;
43 class CL_CSSLayout_Impl;
44 class CL_Size;
45 class CL_Point;
46 class CL_Image;
47 class CL_Rect;
48 
50 {
51 public:
52  CL_CSSLayout();
53 
54  bool is_null() const;
55 
56  void load_xml(const CL_String &filename, const CL_String &style_sheet);
57  void layout(CL_GraphicContext &gc, const CL_Rect &viewport);
58  void render(CL_GraphicContext &gc) { render_impl(gc); }
59 
60  template<typename GUIComponent>
61  void render(CL_GraphicContext &gc, GUIComponent *component)
62  {
63  render_impl(gc, CL_UniquePtr<ClipWrapper>(new GUIComponentWrapper<GUIComponent>(component)));
64  }
65 
66  CL_CSSHitTestResult hit_test(CL_GraphicContext &gc, const CL_Point &pos);
67  void clear_selection();
68  void set_selection(CL_CSSLayoutNode start, size_t start_text_offset, CL_CSSLayoutNode end, size_t end_text_offset);
69 
70  void clear();
71  void set_root_element(CL_CSSLayoutElement element);
72  CL_CSSLayoutElement get_root_element();
73 
74  void set_html_body_element(CL_CSSLayoutElement element);
75  CL_CSSLayoutElement get_html_body_element();
76 
77  CL_CSSLayoutObject create_object();
78  CL_CSSLayoutElement create_element(const CL_String &name = CL_String());
79  CL_CSSLayoutText create_text(const CL_String &text);
80 
81  CL_CSSLayoutElement find_element(const CL_String &name);
82 
83  // CL_Image on_get_image(CL_GraphicContext &gc, const CL_String &uri);
85 
87  {
88  public:
89  virtual ~ClipWrapper() { }
90  virtual void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) = 0;
91  virtual void reset_cliprect(CL_GraphicContext &gc) = 0;
92  virtual void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) = 0;
93  virtual void pop_cliprect(CL_GraphicContext &gc) = 0;
94  };
95 
96 private:
97  void render_impl(CL_GraphicContext &gc, CL_UniquePtr<ClipWrapper> wrapper = CL_UniquePtr<ClipWrapper>());
98 
99  template<typename GUIComponent>
100  class GUIComponentWrapper : public ClipWrapper
101  {
102  public:
103  GUIComponentWrapper(GUIComponent *component) : component(component) { }
104  void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) { component->set_cliprect(gc, rect); }
105  void reset_cliprect(CL_GraphicContext &gc) { component->reset_cliprect(gc); }
106  void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) { component->push_cliprect(gc, rect); }
107  void pop_cliprect(CL_GraphicContext &gc) { component->pop_cliprect(gc); }
108 
109  private:
110  GUIComponent *component;
111  };
112 
113  CL_CSSLayout(CL_SharedPtr<CL_CSSLayout_Impl> impl);
114  CL_SharedPtr<CL_CSSLayout_Impl> impl;
115  friend class CL_CSSLayout_Impl;
116 };