Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #pragma once
00030
00031 #include "api_csslayout.h"
00032 #include "../Core/Signals/callback_2.h"
00033 #include "../Core/System/uniqueptr.h"
00034 #include <memory>
00035
00036 class CL_CSSBoxElement;
00037 class CL_GraphicContext;
00038 class CL_CSSLayoutObject;
00039 class CL_CSSLayoutElement;
00040 class CL_CSSLayoutText;
00041 class CL_CSSLayoutNode;
00042 class CL_CSSHitTestResult;
00043 class CL_CSSLayout_Impl;
00044 class CL_Size;
00045 class CL_Point;
00046 class CL_Image;
00047 class CL_Rect;
00048
00049 class CL_API_CSSLAYOUT CL_CSSLayout
00050 {
00051 public:
00052 CL_CSSLayout();
00053
00054 bool is_null() const;
00055
00056 void load_xml(const CL_String &filename, const CL_String &style_sheet);
00057 void layout(CL_GraphicContext &gc, const CL_Rect &viewport);
00058 void render(CL_GraphicContext &gc) { render_impl(gc); }
00059
00060 template<typename GUIComponent>
00061 void render(CL_GraphicContext &gc, GUIComponent *component)
00062 {
00063 render_impl(gc, CL_UniquePtr<ClipWrapper>(new GUIComponentWrapper<GUIComponent>(component)));
00064 }
00065
00066 CL_CSSHitTestResult hit_test(CL_GraphicContext &gc, const CL_Point &pos);
00067 void clear_selection();
00068 void set_selection(CL_CSSLayoutNode start, size_t start_text_offset, CL_CSSLayoutNode end, size_t end_text_offset);
00069
00070 void clear();
00071 void set_root_element(CL_CSSLayoutElement element);
00072 CL_CSSLayoutElement get_root_element();
00073
00074 void set_html_body_element(CL_CSSLayoutElement element);
00075 CL_CSSLayoutElement get_html_body_element();
00076
00077 CL_CSSLayoutObject create_object();
00078 CL_CSSLayoutElement create_element(const CL_String &name = CL_String());
00079 CL_CSSLayoutText create_text(const CL_String &text);
00080
00081 CL_CSSLayoutElement find_element(const CL_String &name);
00082
00083
00084 CL_Callback_2<CL_Image, CL_GraphicContext &, const CL_String &> &func_get_image();
00085
00086 class ClipWrapper
00087 {
00088 public:
00089 virtual ~ClipWrapper() { }
00090 virtual void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) = 0;
00091 virtual void reset_cliprect(CL_GraphicContext &gc) = 0;
00092 virtual void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) = 0;
00093 virtual void pop_cliprect(CL_GraphicContext &gc) = 0;
00094 };
00095
00096 private:
00097 void render_impl(CL_GraphicContext &gc, CL_UniquePtr<ClipWrapper> wrapper = CL_UniquePtr<ClipWrapper>());
00098
00099 template<typename GUIComponent>
00100 class GUIComponentWrapper : public ClipWrapper
00101 {
00102 public:
00103 GUIComponentWrapper(GUIComponent *component) : component(component) { }
00104 void set_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) { component->set_cliprect(gc, rect); }
00105 void reset_cliprect(CL_GraphicContext &gc) { component->reset_cliprect(gc); }
00106 void push_cliprect(CL_GraphicContext &gc, const CL_Rect &rect) { component->push_cliprect(gc, rect); }
00107 void pop_cliprect(CL_GraphicContext &gc) { component->pop_cliprect(gc); }
00108
00109 private:
00110 GUIComponent *component;
00111 };
00112
00113 CL_CSSLayout(CL_SharedPtr<CL_CSSLayout_Impl> impl);
00114 CL_SharedPtr<CL_CSSLayout_Impl> impl;
00115 friend class CL_CSSLayout_Impl;
00116 };