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
00039 #define GCCV_TEXT_PROP(type,member) \
00040 public: \
00041 void Set##member (type val) { \
00042 m_##member = val; \
00043 SetPosition (m_x, m_y); \
00044 } \
00045 type Get##member (void) const {return m_##member;} \
00046 type &GetRef##member (void) {return m_##member;} \
00047 private: \
00048 type m_##member;
00049
00050
00051 class TextPrivate;
00052 class TextLine;
00053 class TextRun;
00054 class TextTag;
00055 class TextTagList;
00056
00057 class Text: public Rectangle
00058 {
00059 friend class TextPrivate;
00060 public:
00061 Text (Canvas *canvas, double x, double y);
00062 Text (Group *parent, double x, double y, ItemClient *client = NULL);
00063 virtual ~Text ();
00064
00065 void SetPosition (double x, double y);
00066 void SetText (char const *text);
00067 void SetText (std::string const &text);
00068 void SetFontDescription (PangoFontDescription *desc);
00069 void SetEditing (bool editing);
00070
00071 void GetBounds (Rect *ink, Rect *logical);
00072 char const *GetText ();
00073
00074 void InsertTextTag (TextTag *tag, bool rebuild_attributes = true);
00075 std::list <TextTag *> const *GetTags () {return &m_Tags;}
00076
00077 void SetCurTagList (TextTagList *l);
00078
00079 void ApplyTagsToSelection (TextTagList const *l);
00080
00090 void ReplaceText (std::string &str, int pos, unsigned length);
00091 unsigned GetCursorPosition () {return m_CurPos;}
00092 void GetSelectionBounds (unsigned &start, unsigned &end);
00093 void SetSelectionBounds (unsigned start, unsigned end);
00094 unsigned GetIndexAt (double x, double y);
00095 bool GetPositionAtIndex (unsigned index, Rect &rect);
00096
00097
00098 void Draw (cairo_t *cr, bool is_vector) const;
00099 void Move (double x, double y);
00100
00101
00102 bool OnKeyPressed (GdkEventKey *event);
00103 void OnButtonPressed (double x, double y);
00104 void OnDrag (double x, double y);
00105
00106
00107 static PangoContext *GetContext ();
00108
00109 unsigned GetDefaultFontSize () { return (m_FontDesc)? (double) pango_font_description_get_size (m_FontDesc) / PANGO_SCALE: 0; }
00110 void RebuildAttributes ();
00111
00112 private:
00113 double m_x, m_y;
00114 unsigned long m_BlinkSignal;
00115 bool m_CursorVisible;
00116 unsigned m_CurPos, m_StartSel;
00117 std::list <TextRun *> m_Runs;
00118 std::list <TextTag *> m_Tags;
00119 std::string m_Text;
00120 GtkIMContext *m_ImContext;
00121 PangoFontDescription *m_FontDesc;
00122 TextTagList *m_CurTags;
00123 TextLine *m_Lines;
00124 unsigned m_LinesNumber;
00125
00126 GCCV_TEXT_PROP (double, Padding)
00127 GCCV_TEXT_PROP (Anchor, Anchor)
00128 GCCV_TEXT_PROP (double, LineOffset)
00129 GCCV_TEXT_PROP (GtkJustification, Justification)
00130 GCU_RO_PROP (double, Width)
00131 GCU_RO_PROP (double, Height)
00132 GCU_RO_PROP (double, Ascent)
00133 GCU_RO_PROP (double, Y)
00134 };
00135
00136 }
00137
00138 #endif // GCCV_TEXT_H