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
00031
00032 #pragma once
00033
00034 #include "../../Core/System/sharedptr.h"
00035 #include "../../Core/Math/rect.h"
00036 #include "../../Core/Math/size.h"
00037 #include "color.h"
00038
00039 class CL_Font;
00040 class CL_GraphicContext;
00041 class CL_Point;
00042 class CL_Size;
00043 class CL_SpanLayout_Impl;
00044 class CL_Image;
00045 class CL_SpanComponent;
00046
00050 enum CL_SpanAlign
00051 {
00052 cl_left,
00053 cl_right,
00054 cl_center,
00055 cl_justify
00056 };
00057
00061 class CL_SpanComponent
00062 {
00063 public:
00064 virtual ~CL_SpanComponent() { }
00065
00069 virtual CL_Size get_size() const = 0;
00070
00074 virtual void set_geometry(const CL_Rect &geometry) = 0;
00075 };
00076
00080 template<typename T>
00081 class CL_SpanComponentBinder : public CL_SpanComponent
00082 {
00083 public:
00084
00088 CL_SpanComponentBinder(T *component)
00089 : component(component)
00090 {
00091 }
00092
00096 CL_Size get_size() const
00097 {
00098 return component->get_size();
00099 }
00100
00104 void set_geometry(const CL_Rect &geometry)
00105 {
00106 component->set_geometry(geometry);
00107 }
00108
00109 private:
00110 T *component;
00111 };
00112
00116 class CL_SpanLayout
00117 {
00120 public:
00121 CL_SpanLayout();
00122 ~CL_SpanLayout();
00124
00125 struct HitTestResult
00126 {
00127 HitTestResult() : object_id(-1), offset(0) {}
00128
00129 enum Type
00130 {
00131 no_objects_available,
00132 outside_top,
00133 outside_left,
00134 outside_right,
00135 outside_bottom,
00136 inside
00137 } type;
00138
00139 int object_id;
00140 int offset;
00141 };
00142
00145 public:
00147 void clear();
00148
00155 void add_text(const CL_String &text, const CL_Font &font, const CL_Colorf &color = CL_Colorf::white, int id = -1);
00156
00162 void add_image(const CL_Image &image, int baseline_offset = 0, int id = -1);
00163
00164 template<typename T>
00165
00171 void add_component(T *component, int baseline_offset = 0, int id = -1)
00172 {
00173 add_component_helper(new CL_SpanComponentBinder<T>(component), baseline_offset, id);
00174 }
00175
00180 void layout(CL_GraphicContext &gc, int max_width);
00181
00185 void set_position(const CL_Point &pos);
00186
00190 CL_Size get_size() const;
00191
00195 std::vector<CL_Rect> get_rect_by_id(int id) const;
00196
00197
00204 HitTestResult hit_test(CL_GraphicContext &gc, const CL_Point &pos);
00205
00209 void draw_layout(CL_GraphicContext &gc);
00210
00215 void draw_layout_ellipsis(CL_GraphicContext &gc, const CL_Rect &content_rect);
00216
00218 void set_component_geometry();
00219
00225 CL_Size find_preferred_size(CL_GraphicContext &gc);
00226
00231 void set_selection_range(CL_String::size_type start, CL_String::size_type end);
00232
00237 void set_selection_colors(const CL_Colorf &foreground, const CL_Colorf &background);
00238
00240 void show_cursor();
00241
00243 void hide_cursor();
00244
00248 void set_cursor_pos(CL_String::size_type pos);
00249
00253 void set_cursor_overwrite_mode(bool enable);
00254
00258 void set_cursor_color(const CL_Colorf &color);
00259
00263 CL_String get_combined_text() const;
00264
00270 void set_align(CL_SpanAlign align);
00271
00273 int get_first_baseline_offset();
00274
00276 int get_last_baseline_offset();
00277
00279
00282 private:
00283
00289 void add_component_helper(CL_SpanComponent *component, int baseline_offset, int id);
00290
00291 CL_SharedPtr<CL_SpanLayout_Impl> impl;
00293 };