The Gnome Chemistry Utils  0.14.0
gccv/text.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gccv/text.h
6  *
7  * Copyright (C) 2008-2010 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCCV_TEXT_H
26 #define GCCV_TEXT_H
27 
28 #include "rectangle.h"
29 #include "structs.h"
30 #include <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32 #include <pango/pango.h>
33 #include <list>
34 #include <string>
35 
37 namespace gccv {
38 
57 #define GCCV_TEXT_PROP(type,member) \
58 public: \
59  void Set##member (type val) { \
60  m_##member = val; \
61  SetPosition (m_x, m_y); \
62  } \
63  type Get##member (void) const {return m_##member;} \
64 private: \
65  type m_##member;
66 
67 // These are private classes
68 class TextPrivate;
69 class TextLine;
70 class TextRun;
71 class TextTag;
72 class TextTagList;
73 
79 class Text: public Rectangle
80 {
81 friend class TextPrivate;
82 public:
91  Text (Canvas *canvas, double x, double y);
101  Text (Group *parent, double x, double y, ItemClient *client = NULL);
105  virtual ~Text ();
106 
114  void SetPosition (double x, double y);
120  void SetText (char const *text);
126  void SetText (std::string const &text);
132  void SetFontDescription (PangoFontDescription *desc);
138  void SetColor (GOColor color);
144  void SetEditing (bool editing);
145 
152  void GetBounds (Rect *ink, Rect *logical);
156  char const *GetText ();
157 
164  void InsertTextTag (TextTag *tag, bool rebuild_attributes = true);
171  void DeleteTextTag (TextTag *tag, bool rebuild_attributes = true);
175  std::list <TextTag *> const *GetTags () {return &m_Tags;}
176 
182  void SetCurTagList (TextTagList *l);
183 
189  void ApplyTagsToSelection (TextTagList const *l);
190 
200  void ReplaceText (std::string &str, int pos, unsigned length);
201  unsigned GetCursorPosition () {return m_CurPos;}
202  void GetSelectionBounds (unsigned &start, unsigned &end);
203  void SetSelectionBounds (unsigned start, unsigned end);
204  unsigned GetIndexAt (double x, double y);
205  bool GetPositionAtIndex (unsigned index, Rect &rect);
206 
207  // virtual methods
214  void Draw (cairo_t *cr, bool is_vector) const;
221  void Move (double x, double y);
222 
223  // events related methods
229  bool OnKeyPressed (GdkEventKey *event);
235  bool OnKeyReleased (GdkEventKey *event);
243  void OnButtonPressed (double x, double y);
251  void OnDrag (double x, double y);
252 
253  // static methods
258  static PangoContext *GetContext ();
259 
263  unsigned GetDefaultFontSize () { return (m_FontDesc)? (double) pango_font_description_get_size (m_FontDesc) / PANGO_SCALE: 0; }
267  void RebuildAttributes ();
275  void SetInterline (double interline, bool emit_changed = false);
283  void SetJustification (GtkJustification justification, bool emit_changed = false);
284 
285 private:
286  double m_x, m_y;
287  unsigned long m_BlinkSignal;
288  bool m_CursorVisible;
289  unsigned m_CurPos, m_StartSel;
290  std::list <TextRun *> m_Runs;
291  std::list <TextTag *> m_Tags;
292  std::string m_Text;
293  GtkIMContext *m_ImContext;
294  PangoFontDescription *m_FontDesc;
295  TextTagList *m_CurTags;
296  TextLine *m_Lines;
297  unsigned m_LinesNumber;
298  GOColor m_Color;
299 
308 GCCV_TEXT_PROP (double, Padding)
328 GCCV_TEXT_PROP (double, LineOffset)
332 GCU_RO_PROP (GtkJustification, Justification)
336 GCU_RO_PROP (double, Interline)
340 GCU_RO_PROP (double, Width)
344 GCU_RO_PROP (double, Height)
348 GCU_RO_PROP (double, Ascent)
352 GCU_RO_PROP (double, Y)
353 };
354 
355 } // namespace gccv
356 
357 #endif // GCCV_TEXT_H