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 TextRun;
00053 class TextTag;
00054 class TextTagList;
00055
00056 class Text: public Rectangle
00057 {
00058 friend class TextPrivate;
00059 public:
00060 Text (Canvas *canvas, double x, double y);
00061 Text (Group *parent, double x, double y, ItemClient *client = NULL);
00062 virtual ~Text ();
00063
00064 void SetPosition (double x, double y);
00065 void SetText (char const *text);
00066 void SetText (std::string const &text);
00067 void SetFontDescription (PangoFontDescription *desc);
00068 void SetEditing (bool editing);
00069
00070 void GetBounds (Rect *ink, Rect *logical);
00071 char const *GetText ();
00072
00073 void InsertTextTag (TextTag *tag);
00074 std::list <TextTag *> const *GetTags () {return &m_Tags;}
00075
00076 void SetCurTagList (TextTagList *l);
00077
00078 void ApplyCurTagsToSelection ();
00079
00089 void ReplaceText (std::string &str, int pos, unsigned length);
00090 unsigned GetCursorPosition () {return m_CurPos;}
00091
00092
00093 void Draw (cairo_t *cr, bool is_vector) const;
00094 void Move (double x, double y);
00095
00096
00097 bool OnKeyPressed (GdkEventKey *event);
00098
00099
00100 static PangoContext *GetContext ();
00101
00102 unsigned GetDefaultFontSize () { return (m_FontDesc)? (double) pango_font_description_get_size (m_FontDesc) / PANGO_SCALE: 0; }
00103
00104 private:
00105 void RebuildAttributes ();
00106
00107 private:
00108 double m_x, m_y;
00109 unsigned long m_BlinkSignal;
00110 bool m_CursorVisible;
00111 unsigned m_CurPos;
00112 std::list <TextRun *> m_Runs;
00113 std::list <TextTag *> m_Tags;
00114 std::string m_Text;
00115 GtkIMContext *m_ImContext;
00116 PangoFontDescription *m_FontDesc;
00117 TextTagList *m_CurTags;
00118
00119
00120 GCCV_TEXT_PROP (double, Padding)
00121 GCCV_TEXT_PROP (Anchor, Anchor)
00122 GCCV_TEXT_PROP (double, LineOffset)
00123 GCU_RO_PROP (double, Width)
00124 GCU_RO_PROP (double, Height)
00125 GCU_RO_PROP (double, Ascent)
00126 GCU_RO_PROP (double, Y)
00127 };
00128
00129 }
00130
00131 #endif // GCCV_TEXT_H