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         type &GetRef##member (void) {return m_##member;}        \
00047 private:        \
00048         type m_##member;
00049 
00050 // These are private classes
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         // virtual methods
00098         void Draw (cairo_t *cr, bool is_vector) const;
00099         void Move (double x, double y);
00100 
00101         // events related methods
00102         bool OnKeyPressed (GdkEventKey *event);
00103         void OnButtonPressed (double x, double y);
00104         void OnDrag (double x, double y);
00105 
00106         // static methods
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 }   //  namespace gccv
00137 
00138 #endif  //      GCCV_TEXT_H

Generated on Thu Jun 25 13:24:20 2009 for The Gnome Chemistry Utils by  doxygen 1.5.9