libgnomecanvasmm
properties.h
Go to the documentation of this file.
1 #ifndef _LIBGNOMECANVASMM_PROPERTIES_H_
2 #define _LIBGNOMECANVASMM_PROPERTIES_H_
3 
4 // -*- c++ -*-
5 /* $Id: properties.h 2019 2009-01-27 08:29:42Z murrayc $ */
6 
7 /* properties.h
8  *
9  * Copyright (C) 1999-2002 The Free Software Foundation
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 //#include <gtk/gtkpacker.h> //For GtkAnchorType.
27 
28 
29 #include <glibmm/propertyproxy.h>
30 #include <gdkmm/color.h>
31 #include <gdkmm/bitmap.h>
32 #include <pangomm/fontdescription.h>
33 #include <gtkmm/enums.h>
34 
35 namespace Gnome
36 {
37 
38 namespace Canvas
39 {
40 
41 namespace Properties
42 {
43 
45 {
46 public:
47  PropertyBase(const char* name);
48  ~PropertyBase();
49 
50  const char* get_name() const;
51 
52 protected:
53  const char* name_;
54 };
55 
56 template <class T_Value>
57 class Property : public PropertyBase
58 {
59 public:
60  Property(const char* name, const T_Value& value)
61  : PropertyBase(name), value_(value)
62  {}
63 
64  void set_value_in_object(Glib::Object& object) const
65  {
66  Glib::PropertyProxy<T_Value> proxy(&object, get_name());
67  proxy.set_value(value_);
68  }
69 
70 protected:
71  T_Value value_;
72 };
73 
74 
79 template <class O, class T>
80 O& operator << (O& object, const Property<T>& property)
81 {
82  property.set_value_in_object(object);
83  return object;
84 }
85 
86 /********* specializations *********/
87 
88 //Colors can be specified with a string or a Gdk::Color, or an rgba guint.
89 template<>
90 class Property<Gdk::Color> : public PropertyBase
91 {
92 public:
93  Property(const char* name, const Gdk::Color& value);
94  Property(const char* name, const Glib::ustring& color);
95  Property(const char* name, const guint& rgba_color);
96 
97  void set_value_in_object(Glib::Object& object) const;
98 
99 protected:
100  Gdk::Color value_;
101  bool value_gobj_used_; //Whether the Gdk::Value was intialised in the constructor.
102  Glib::ustring value_string_;
104  guint value_rgba_;
105 };
106 
107 //Font can be specified with a string or a Pango::FontDescription.
108 template<>
109 class Property<Pango::FontDescription> : public PropertyBase
110 {
111 public:
112  Property(const char* name, const Pango::FontDescription& value);
113  Property(const char* name, const Glib::ustring& font);
114 
115  void set_value_in_object(Glib::Object& object) const;
116 
117 protected:
118  Pango::FontDescription value_;
119  Glib::ustring value_string_;
120 };
121 
122 
123 //We now define some specific properties.
124 //Some of these are unusual, so we define them manually.
125 //Others are regular so we define them with a macro:
126 
127 
128 class font : public Property<Pango::FontDescription> //Used by CanvasText.
129 {
130 public:
131  font(const Pango::FontDescription& v);
132 
133  font(const Glib::ustring& v);
134 };
135 
136 template<>
137 class Property< Glib::RefPtr<Gdk::Bitmap> > : public PropertyBase
138 {
139 public:
140  Property(const char* name, const Glib::RefPtr<Gdk::Bitmap>& value);
141 
142  void set_value_in_object(Glib::Object& object) const;
143 
144 protected:
145  Glib::RefPtr<Gdk::Bitmap> value_;
146 };
147 
148 class fill_color : public Property<Gdk::Color>
149 {
150 public:
151  fill_color(const Gdk::Color& v);
152 
153  fill_color(const Glib::ustring& v);
154 };
155 
156 class outline_color : public Property<Gdk::Color>
157 {
158 public:
159  outline_color(const Gdk::Color& v);
160 
161  outline_color(const Glib::ustring& v);
162 };
163 
164 
165 // GNOMEMM_PROPERTY(C++ name, C property name, C++ type)
166 #define GNOMEMM_PROPERTY(N,N2,T) \
167 class N : public Property<T > \
168 { \
169 public: \
170  N(const T& v); \
171 };
172 
173 
174 // CanvasLine
175 GNOMEMM_PROPERTY(arrow_shape_a,arrow_shape_a,double)
176 GNOMEMM_PROPERTY(arrow_shape_b,arrow_shape_b,double)
177 GNOMEMM_PROPERTY(arrow_shape_c,arrow_shape_c,double)
178 GNOMEMM_PROPERTY(cap_style,cap_style,Gdk::CapStyle)
179 GNOMEMM_PROPERTY(first_arrowhead,first_arrowhead,bool)
180 GNOMEMM_PROPERTY(join_style,join_style,Gdk::JoinStyle)
181 GNOMEMM_PROPERTY(last_arrowhead,last_arrowhead,bool)
182 GNOMEMM_PROPERTY(line_style,line_style,Gdk::LineStyle)
183 GNOMEMM_PROPERTY(smooth,smooth,bool)
184 GNOMEMM_PROPERTY(spline_steps,spline_steps,guint)
185 
186 // CanvasText
187 GNOMEMM_PROPERTY(clip,clip,bool)
188 GNOMEMM_PROPERTY(clip_height,clip_height,double)
189 GNOMEMM_PROPERTY(clip_width,clip_width,double)
190 GNOMEMM_PROPERTY(justification,justification,Gtk::Justification)
191 GNOMEMM_PROPERTY(direction,direction,Gtk::DirectionType)
192 GNOMEMM_PROPERTY(wrap_mode,wrap_mode,Gtk::WrapMode)
193 GNOMEMM_PROPERTY(text_height,text_height,double)
194 GNOMEMM_PROPERTY(text_width,text_width,double)
195 GNOMEMM_PROPERTY(x_offset,x_offset,double)
196 GNOMEMM_PROPERTY(y_offset,y_offset,double)
197 GNOMEMM_PROPERTY(text,text,Glib::ustring)
198 GNOMEMM_PROPERTY(markup,markup,Glib::ustring)
199 GNOMEMM_PROPERTY(editable,editable,bool)
200 GNOMEMM_PROPERTY(visible,visible,bool)
201 GNOMEMM_PROPERTY(cursor_visible,cursor_visible,bool)
202 GNOMEMM_PROPERTY(cursor_blink,cursor_blink,bool)
203 GNOMEMM_PROPERTY(grow_height,grow_height,bool)
204 GNOMEMM_PROPERTY(pixels_above_lines,pixels_above_lines,int)
205 GNOMEMM_PROPERTY(pixels_below_lines,pixels_below_lines,int)
206 GNOMEMM_PROPERTY(pixels_inside_wrap,pixels_inside_wrap,int)
207 GNOMEMM_PROPERTY(left_margin,left_margin,int)
208 GNOMEMM_PROPERTY(right_margin,right_margin,int)
209 GNOMEMM_PROPERTY(indent,indent,int)
210 
211 // CanvasWidget
212 GNOMEMM_PROPERTY(size_pixels,size_pixels,bool)
213 
214 // CanvasImage, CanvasWidget
215 GNOMEMM_PROPERTY(height,height,double)
216 GNOMEMM_PROPERTY(width,width,double)
217 
218 // CanvasRect, CanvasEllipse
219 GNOMEMM_PROPERTY(x1,x1,double)
220 GNOMEMM_PROPERTY(x2,x2,double)
221 GNOMEMM_PROPERTY(y1,y1,double)
222 GNOMEMM_PROPERTY(y2,y2,double)
223 
224 // CanvasImage, CanvasText, CanvasWidget
225 GNOMEMM_PROPERTY(anchor,anchor,Gtk::AnchorType)
226 
227 // CanvasPolygon, CanvasRect, CanvasEllipse
228 GNOMEMM_PROPERTY(outline_stipple,outline_stipple,Glib::RefPtr<Gdk::Bitmap>)
229 GNOMEMM_PROPERTY(wind,wind,guint)
230 GNOMEMM_PROPERTY(miterlimit,miterlimit,double)
231 
232 // CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse
233 GNOMEMM_PROPERTY(width_pixels,width_pixels,guint)
234 GNOMEMM_PROPERTY(width_units,width_units,double)
235 
236 // CanvasGroup, CanvasImage, CanvasText, CanvasWidget
237 GNOMEMM_PROPERTY(x,x,double)
238 GNOMEMM_PROPERTY(y,y,double)
239 
240 // CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse, CanvasText
241 GNOMEMM_PROPERTY(fill_stipple,fill_stipple,Glib::RefPtr<Gdk::Bitmap>)
242 
243 } /* namespace Properties */
244 } /* namespace Canvas */
245 } /* namespace Gnome */
246 
247 #endif /* _LIBGNOMECANVASMM_PROPERTIES_H_ */
248 
#define GNOMEMM_PROPERTY(N, N2, T)
Definition: properties.h:166
Definition: bpath.h:149
Definition: affinetrans.h:29
void set_value_in_object(Glib::Object &object) const
Definition: properties.h:64
Property(const char *name, const T_Value &value)
Definition: properties.h:60
Definition: properties.h:128
guint value_rgba_
Definition: properties.h:104
const char * name_
Definition: properties.h:53
Definition: properties.h:57
Definition: properties.h:44
Definition: properties.h:156
T_Value value_
Definition: properties.h:71
Pango::FontDescription value_
Definition: properties.h:118
font(const Pango::FontDescription &v)
Gdk::Color value_
Definition: properties.h:100
bool value_string_used_
Definition: properties.h:103
Definition: properties.h:148
Glib::ustring value_string_
Definition: properties.h:102
Glib::RefPtr< Gdk::Bitmap > value_
Definition: properties.h:145
Glib::ustring value_string_
Definition: properties.h:119
bool value_gobj_used_
Definition: properties.h:101