gccv/text.h
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 #ifndef GCCV_TEXT_H
00026 #define GCCV_TEXT_H
00027
00028 #include "rectangle.h"
00029 #include "structs.h"
00030 #include <gtk/gtk.h>
00031 #include <gdk/gdkkeysyms.h>
00032 #include <pango/pango.h>
00033 #include <list>
00034 #include <string>
00035
00037 namespace gccv {
00038
00057 #define GCCV_TEXT_PROP(type,member) \
00058 public: \
00059 void Set##member (type val) { \
00060 m_##member = val; \
00061 SetPosition (m_x, m_y); \
00062 } \
00063 type Get##member (void) const {return m_##member;} \
00064 private: \
00065 type m_##member;
00066
00067
00068 class TextPrivate;
00069 class TextLine;
00070 class TextRun;
00071 class TextTag;
00072 class TextTagList;
00073
00079 class Text: public Rectangle
00080 {
00081 friend class TextPrivate;
00082 public:
00091 Text (Canvas *canvas, double x, double y);
00101 Text (Group *parent, double x, double y, ItemClient *client = NULL);
00105 virtual ~Text ();
00106
00114 void SetPosition (double x, double y);
00120 void SetText (char const *text);
00126 void SetText (std::string const &text);
00132 void SetFontDescription (PangoFontDescription *desc);
00138 void SetColor (GOColor color);
00144 void SetEditing (bool editing);
00145
00152 void GetBounds (Rect *ink, Rect *logical);
00156 char const *GetText ();
00157
00164 void InsertTextTag (TextTag *tag, bool rebuild_attributes = true);
00171 void DeleteTextTag (TextTag *tag, bool rebuild_attributes = true);
00175 std::list <TextTag *> const *GetTags () {return &m_Tags;}
00176
00182 void SetCurTagList (TextTagList *l);
00183
00189 void ApplyTagsToSelection (TextTagList const *l);
00190
00200 void ReplaceText (std::string &str, int pos, unsigned length);
00201 unsigned GetCursorPosition () {return m_CurPos;}
00202 void GetSelectionBounds (unsigned &start, unsigned &end);
00203 void SetSelectionBounds (unsigned start, unsigned end);
00204 unsigned GetIndexAt (double x, double y);
00205 bool GetPositionAtIndex (unsigned index, Rect &rect);
00206
00207
00214 void Draw (cairo_t *cr, bool is_vector) const;
00221 void Move (double x, double y);
00222
00223
00229 bool OnKeyPressed (GdkEventKey *event);
00235 bool OnKeyReleased (GdkEventKey *event);
00243 void OnButtonPressed (double x, double y);
00251 void OnDrag (double x, double y);
00252
00253
00258 static PangoContext *GetContext ();
00259
00263 unsigned GetDefaultFontSize () { return (m_FontDesc)? (double) pango_font_description_get_size (m_FontDesc) / PANGO_SCALE: 0; }
00267 void RebuildAttributes ();
00275 void SetInterline (double interline, bool emit_changed = false);
00283 void SetJustification (GtkJustification justification, bool emit_changed = false);
00284
00285 private:
00286 double m_x, m_y;
00287 unsigned long m_BlinkSignal;
00288 bool m_CursorVisible;
00289 unsigned m_CurPos, m_StartSel;
00290 std::list <TextRun *> m_Runs;
00291 std::list <TextTag *> m_Tags;
00292 std::string m_Text;
00293 GtkIMContext *m_ImContext;
00294 PangoFontDescription *m_FontDesc;
00295 TextTagList *m_CurTags;
00296 TextLine *m_Lines;
00297 unsigned m_LinesNumber;
00298 GOColor m_Color;
00299
00308 GCCV_TEXT_PROP (double, Padding)
00317 GCCV_TEXT_PROP (Anchor, Anchor)
00328 GCCV_TEXT_PROP (double, LineOffset)
00332 GCU_RO_PROP (GtkJustification, Justification)
00336 GCU_RO_PROP (double, Interline)
00340 GCU_RO_PROP (double, Width)
00344 GCU_RO_PROP (double, Height)
00348 GCU_RO_PROP (double, Ascent)
00352 GCU_RO_PROP (double, Y)
00353 };
00354
00355 }
00356
00357 #endif // GCCV_TEXT_H