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