gccv/text.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * gccv/text.h 
00006  *
00007  * Copyright (C) 2008 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
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 // These are private classes
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         // virtual methods
00093         void Draw (cairo_t *cr, bool is_vector) const;
00094         void Move (double x, double y);
00095 
00096         // events related methods
00097         bool OnKeyPressed (GdkEventKey *event);
00098 
00099         // static methods
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 }   //  namespace gccv
00130 
00131 #endif  //      GCCV_TEXT_H

Generated on Wed Mar 25 12:27:20 2009 for The Gnome Chemistry Utils by  doxygen 1.5.8