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-2009 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 private:        \
00047         type m_##member;
00048 
00049 // These are private classes
00050 class TextPrivate;
00051 class TextLine;
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 SetColor (GOColor color);
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         void DeleteTextTag (TextTag *tag, bool rebuild_attributes = true);
00076         std::list <TextTag *> const *GetTags () {return &m_Tags;}
00077 
00078         void SetCurTagList (TextTagList *l);
00079 
00080         void ApplyTagsToSelection (TextTagList const *l);
00081 
00091         void ReplaceText (std::string &str, int pos, unsigned length);
00092         unsigned GetCursorPosition () {return m_CurPos;}
00093         void GetSelectionBounds (unsigned &start, unsigned &end);
00094         void SetSelectionBounds (unsigned start, unsigned end);
00095         unsigned GetIndexAt (double x, double y);
00096         bool GetPositionAtIndex (unsigned index, Rect &rect);
00097 
00098         // virtual methods
00099         void Draw (cairo_t *cr, bool is_vector) const;
00100         void Move (double x, double y);
00101 
00102         // events related methods
00103         bool OnKeyPressed (GdkEventKey *event);
00104         bool OnKeyReleased (GdkEventKey *event);
00105         void OnButtonPressed (double x, double y);
00106         void OnDrag (double x, double y);
00107 
00108         // static methods
00109         static PangoContext *GetContext ();
00110 
00111         unsigned GetDefaultFontSize () { return (m_FontDesc)? (double) pango_font_description_get_size (m_FontDesc) / PANGO_SCALE: 0; }
00112         void RebuildAttributes ();
00113         void SetInterline (double interline, bool emit_changed = false);
00114         void SetJustification (GtkJustification justification, bool emit_changed = false);
00115 
00116 private:
00117         double m_x, m_y;
00118         unsigned long m_BlinkSignal;
00119         bool m_CursorVisible;
00120         unsigned m_CurPos, m_StartSel;
00121         std::list <TextRun *> m_Runs;
00122         std::list <TextTag *> m_Tags;
00123         std::string m_Text;
00124         GtkIMContext *m_ImContext;
00125         PangoFontDescription *m_FontDesc;
00126         TextTagList *m_CurTags;
00127         TextLine *m_Lines;
00128         unsigned m_LinesNumber;
00129         GOColor m_Color;
00130 
00131 GCCV_TEXT_PROP (double, Padding)
00132 GCCV_TEXT_PROP (Anchor, Anchor)
00133 GCCV_TEXT_PROP (double, LineOffset)
00134 GCU_RO_PROP (GtkJustification, Justification)
00135 GCU_RO_PROP (double, Interline)
00136 GCU_RO_PROP (double, Width)
00137 GCU_RO_PROP (double, Height)
00138 GCU_RO_PROP (double, Ascent)
00139 GCU_RO_PROP (double, Y)
00140 };
00141 
00142 }   //  namespace gccv
00143 
00144 #endif  //      GCCV_TEXT_H
Generated on Tue Apr 13 14:55:01 2010 for The Gnome Chemistry Utils by  doxygen 1.6.3