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
35namespace Gnome
36{
37
38namespace Canvas
39{
40
41namespace Properties
42{
43
45{
46public:
47 PropertyBase(const char* name);
49
50 const char* get_name() const;
51
52protected:
53 const char* name_;
54};
55
56template <class T_Value>
57class Property : public PropertyBase
58{
59public:
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
70protected:
71 T_Value value_;
72};
73
74
79template <class O, class T>
80O& 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.
89template<>
90class Property<Gdk::Color> : public PropertyBase
91{
92public:
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
99protected:
100 Gdk::Color value_;
101 bool value_gobj_used_; //Whether the Gdk::Value was intialised in the constructor.
102 Glib::ustring value_string_;
105};
106
107//Font can be specified with a string or a Pango::FontDescription.
108template<>
109class Property<Pango::FontDescription> : public PropertyBase
110{
111public:
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
117protected:
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
128class font : public Property<Pango::FontDescription> //Used by CanvasText.
129{
130public:
131 font(const Pango::FontDescription& v);
132
133 font(const Glib::ustring& v);
134};
135
136template<>
137class Property< Glib::RefPtr<Gdk::Bitmap> > : public PropertyBase
138{
139public:
140 Property(const char* name, const Glib::RefPtr<Gdk::Bitmap>& value);
141
142 void set_value_in_object(Glib::Object& object) const;
143
144protected:
145 Glib::RefPtr<Gdk::Bitmap> value_;
146};
147
148class fill_color : public Property<Gdk::Color>
149{
150public:
151 fill_color(const Gdk::Color& v);
152
153 fill_color(const Glib::ustring& v);
154};
155
156class outline_color : public Property<Gdk::Color>
157{
158public:
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) \
167class N : public Property<T > \
168{ \
169public: \
170 N(const T& v); \
171};
172
173
174// CanvasLine
175GNOMEMM_PROPERTY(arrow_shape_a,arrow_shape_a,double)
176GNOMEMM_PROPERTY(arrow_shape_b,arrow_shape_b,double)
177GNOMEMM_PROPERTY(arrow_shape_c,arrow_shape_c,double)
178GNOMEMM_PROPERTY(cap_style,cap_style,Gdk::CapStyle)
179GNOMEMM_PROPERTY(first_arrowhead,first_arrowhead,bool)
180GNOMEMM_PROPERTY(join_style,join_style,Gdk::JoinStyle)
181GNOMEMM_PROPERTY(last_arrowhead,last_arrowhead,bool)
182GNOMEMM_PROPERTY(line_style,line_style,Gdk::LineStyle)
183GNOMEMM_PROPERTY(smooth,smooth,bool)
184GNOMEMM_PROPERTY(spline_steps,spline_steps,guint)
185
186// CanvasText
187GNOMEMM_PROPERTY(clip,clip,bool)
188GNOMEMM_PROPERTY(clip_height,clip_height,double)
189GNOMEMM_PROPERTY(clip_width,clip_width,double)
190GNOMEMM_PROPERTY(justification,justification,Gtk::Justification)
191GNOMEMM_PROPERTY(direction,direction,Gtk::DirectionType)
192GNOMEMM_PROPERTY(wrap_mode,wrap_mode,Gtk::WrapMode)
193GNOMEMM_PROPERTY(text_height,text_height,double)
194GNOMEMM_PROPERTY(text_width,text_width,double)
195GNOMEMM_PROPERTY(x_offset,x_offset,double)
196GNOMEMM_PROPERTY(y_offset,y_offset,double)
197GNOMEMM_PROPERTY(text,text,Glib::ustring)
198GNOMEMM_PROPERTY(markup,markup,Glib::ustring)
199GNOMEMM_PROPERTY(editable,editable,bool)
200GNOMEMM_PROPERTY(visible,visible,bool)
201GNOMEMM_PROPERTY(cursor_visible,cursor_visible,bool)
202GNOMEMM_PROPERTY(cursor_blink,cursor_blink,bool)
203GNOMEMM_PROPERTY(grow_height,grow_height,bool)
204GNOMEMM_PROPERTY(pixels_above_lines,pixels_above_lines,int)
205GNOMEMM_PROPERTY(pixels_below_lines,pixels_below_lines,int)
206GNOMEMM_PROPERTY(pixels_inside_wrap,pixels_inside_wrap,int)
207GNOMEMM_PROPERTY(left_margin,left_margin,int)
208GNOMEMM_PROPERTY(right_margin,right_margin,int)
209GNOMEMM_PROPERTY(indent,indent,int)
210
211// CanvasWidget
212GNOMEMM_PROPERTY(size_pixels,size_pixels,bool)
213
214// CanvasImage, CanvasWidget
215GNOMEMM_PROPERTY(height,height,double)
216GNOMEMM_PROPERTY(width,width,double)
217
218// CanvasRect, CanvasEllipse
219GNOMEMM_PROPERTY(x1,x1,double)
220GNOMEMM_PROPERTY(x2,x2,double)
221GNOMEMM_PROPERTY(y1,y1,double)
222GNOMEMM_PROPERTY(y2,y2,double)
223
224// CanvasImage, CanvasText, CanvasWidget
225GNOMEMM_PROPERTY(anchor,anchor,Gtk::AnchorType)
226
227// CanvasPolygon, CanvasRect, CanvasEllipse
228GNOMEMM_PROPERTY(outline_stipple,outline_stipple,Glib::RefPtr<Gdk::Bitmap>)
229GNOMEMM_PROPERTY(wind,wind,guint)
230GNOMEMM_PROPERTY(miterlimit,miterlimit,double)
231
232// CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse
233GNOMEMM_PROPERTY(width_pixels,width_pixels,guint)
234GNOMEMM_PROPERTY(width_units,width_units,double)
235
236// CanvasGroup, CanvasImage, CanvasText, CanvasWidget
237GNOMEMM_PROPERTY(x,x,double)
238GNOMEMM_PROPERTY(y,y,double)
239
240// CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse, CanvasText
241GNOMEMM_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
Definition: properties.h:45
const char * name_
Definition: properties.h:53
Property(const char *name, const Gdk::Color &value)
Property(const char *name, const Glib::ustring &color)
bool value_gobj_used_
Definition: properties.h:101
Property(const char *name, const guint &rgba_color)
guint value_rgba_
Definition: properties.h:104
Glib::ustring value_string_
Definition: properties.h:102
Gdk::Color value_
Definition: properties.h:100
void set_value_in_object(Glib::Object &object) const
bool value_string_used_
Definition: properties.h:103
Property(const char *name, const Glib::RefPtr< Gdk::Bitmap > &value)
Glib::RefPtr< Gdk::Bitmap > value_
Definition: properties.h:145
Pango::FontDescription value_
Definition: properties.h:118
Glib::ustring value_string_
Definition: properties.h:119
Property(const char *name, const Pango::FontDescription &value)
Property(const char *name, const Glib::ustring &font)
Definition: properties.h:58
void set_value_in_object(Glib::Object &object) const
Definition: properties.h:64
T_Value value_
Definition: properties.h:71
Property(const char *name, const T_Value &value)
Definition: properties.h:60
Definition: properties.h:149
fill_color(const Glib::ustring &v)
Definition: properties.h:129
font(const Glib::ustring &v)
font(const Pango::FontDescription &v)
Definition: properties.h:157
outline_color(const Glib::ustring &v)
Definition: bpath.h:150
O & operator<<(O &object, const Property< T > &property)
Allow use of << operator on objects: For instance: canvasgroup << Gnome::Canvas::CanvasHelpers::x(2);...
Definition: properties.h:80
Definition: affinetrans.h:30
#define GNOMEMM_PROPERTY(N, N2, T)
Definition: properties.h:166