summaryrefslogtreecommitdiff
path: root/libs/libgnomecanvasmm/libgnomecanvasmm/properties.cc
blob: f786e57836e7dbe254b593f4bcec29af1611787b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// -*- c++ -*-
/* $Id$ */

/* properties.cc
 *
 * Copyright (C) 2002 The Free Software Foundation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <libgnomecanvasmm/properties.h>

namespace Gnome
{

namespace Canvas
{

namespace Properties
{

PropertyBase::PropertyBase(const char* name)
: name_(name)
{}

PropertyBase::~PropertyBase()
{}

const char* PropertyBase::get_name() const
{
  return name_;
}

/////////////////////////////
// Property<Gdk::Color>

Property<Gdk::Color>::Property(const char* name, const Gdk::Color& value) :
  PropertyBase(name),
  value_(value),
  value_gobj_used_(true),
  value_string_used_(false),
  value_rgba_(0)
{}

Property<Gdk::Color>::Property(const char* name, const Glib::ustring& color) :
  PropertyBase(name),
  value_gobj_used_(false),
  value_string_(color),
  value_string_used_ (true),
  value_rgba_(0)
{}

Property<Gdk::Color>::Property(const char* name, const guint& rgba_color) :
  PropertyBase(name),
  value_gobj_used_(false),
  value_string_used_(false),
  value_rgba_(rgba_color)
{}

void Property<Gdk::Color>::set_value_in_object(Glib::Object& object) const
{
  //Set the appropriate property name with the appropriately-typed value:
  if(value_string_used_) {
    
    Glib::PropertyProxy<Glib::ustring> proxy(&object, get_name());
    if (value_string_ == "")
      proxy.reset_value ();
    else
      proxy.set_value(value_string_);

  } else if(value_gobj_used_) {
    
    Glib::PropertyProxy<Gdk::Color> proxy(&object, get_name());
    proxy.set_value(value_);

  } else {
    
    Glib::PropertyProxy<guint> proxy(&object, get_name());
    proxy.set_value(value_rgba_);
  }
}

/////////////////////////////
// Property<Pango::FontDescription>
Property<Pango::FontDescription>::Property(const char* name, const Pango::FontDescription& value) :
  PropertyBase(name),
  value_(value)
{}

Property<Pango::FontDescription>::Property(const char* name, const Glib::ustring& font) :
  PropertyBase(name),
  value_(0),
  value_string_(font)
{}

void Property<Pango::FontDescription>::set_value_in_object(Glib::Object& object) const
{
  if(value_string_.size())
  {
    Glib::PropertyProxy<Glib::ustring> proxy(&object, get_name());
    proxy.set_value(value_string_);
  }
  else
  {
    Glib::PropertyProxy<Pango::FontDescription> proxy(&object, get_name());
    proxy.set_value(value_);
  }
}


/////////////////////////////
// Property< Glib::RefPtr<Gdk::Bitmap> >
Property< Glib::RefPtr<Gdk::Bitmap> >::Property(const char* name, const Glib::RefPtr<Gdk::Bitmap>& value)
  : PropertyBase(name), 
    value_(value)
{}

void Property< Glib::RefPtr<Gdk::Bitmap> >::set_value_in_object(Glib::Object& object) const
{
  Glib::PropertyProxy< Glib::RefPtr<Gdk::Bitmap> > proxy(&object, get_name());
  proxy.set_value(value_);
}


font::font(const Pango::FontDescription& v)
  : Property<Pango::FontDescription>("font-desc", v)
{}

font::font(const Glib::ustring& v)
  : Property<Pango::FontDescription>("font", v)
{}

fill_color::fill_color(const Gdk::Color& v)
  : Property<Gdk::Color>("fill_color_gdk",v)
{}

fill_color::fill_color(const Glib::ustring& v)
  : Property<Gdk::Color>("fill_color",v)
{}

outline_color::outline_color(const Gdk::Color& v)
  : Property<Gdk::Color>("outline_color_gdk", v)
{}

outline_color::outline_color(const Glib::ustring& v)
  : Property<Gdk::Color>("outline_color", v)
{}

// GNOMEMM_PROPERTY_IMPL(C++ name, C property name, C++ type)
#define GNOMEMM_PROPERTY_IMPL(N,N2,T) \
N::N(const T& v) \
  : Property<T >(#N2, v) \
{}

// CanvasLine
GNOMEMM_PROPERTY_IMPL(arrow_shape_a,arrow_shape_a,double)
GNOMEMM_PROPERTY_IMPL(arrow_shape_b,arrow_shape_b,double)
GNOMEMM_PROPERTY_IMPL(arrow_shape_c,arrow_shape_c,double)
GNOMEMM_PROPERTY_IMPL(cap_style,cap_style,Gdk::CapStyle)
GNOMEMM_PROPERTY_IMPL(first_arrowhead,first_arrowhead,bool)
GNOMEMM_PROPERTY_IMPL(join_style,join_style,Gdk::JoinStyle)
GNOMEMM_PROPERTY_IMPL(last_arrowhead,last_arrowhead,bool)
GNOMEMM_PROPERTY_IMPL(line_style,line_style,Gdk::LineStyle)
GNOMEMM_PROPERTY_IMPL(smooth,smooth,bool)
GNOMEMM_PROPERTY_IMPL(spline_steps,spline_steps,guint)

// CanvasText
GNOMEMM_PROPERTY_IMPL(clip,clip,bool)
GNOMEMM_PROPERTY_IMPL(clip_height,clip_height,double)
GNOMEMM_PROPERTY_IMPL(clip_width,clip_width,double)
GNOMEMM_PROPERTY_IMPL(wrap_mode,wrap_mode,Gtk::WrapMode)
GNOMEMM_PROPERTY_IMPL(justification,justification,Gtk::Justification)
GNOMEMM_PROPERTY_IMPL(direction,direction,Gtk::DirectionType)
GNOMEMM_PROPERTY_IMPL(text_height,text_height,double)
GNOMEMM_PROPERTY_IMPL(text_width,text_width,double)
GNOMEMM_PROPERTY_IMPL(x_offset,x_offset,double)
GNOMEMM_PROPERTY_IMPL(y_offset,y_offset,double)
GNOMEMM_PROPERTY_IMPL(text,text,Glib::ustring)
GNOMEMM_PROPERTY_IMPL(markup,markup,Glib::ustring)
GNOMEMM_PROPERTY_IMPL(editable,editable,bool)
GNOMEMM_PROPERTY_IMPL(visible,visible,bool)
GNOMEMM_PROPERTY_IMPL(cursor_visible,cursor_visible,bool)
GNOMEMM_PROPERTY_IMPL(cursor_blink,cursor_blink,bool)
GNOMEMM_PROPERTY_IMPL(grow_height,grow_height,bool)
GNOMEMM_PROPERTY_IMPL(pixels_above_lines,pixels_above_lines,int)
GNOMEMM_PROPERTY_IMPL(pixels_below_lines,pixels_below_lines,int)
GNOMEMM_PROPERTY_IMPL(pixels_inside_wrap,pixels_inside_wrap,int)
GNOMEMM_PROPERTY_IMPL(left_margin,left_margin,int)
GNOMEMM_PROPERTY_IMPL(right_margin,right_margin,int)
GNOMEMM_PROPERTY_IMPL(indent,indent,int)

// CanvasWidget
GNOMEMM_PROPERTY_IMPL(size_pixels,size_pixels,bool)

// CanvasImage, CanvasWidget
GNOMEMM_PROPERTY_IMPL(height,height,double)
GNOMEMM_PROPERTY_IMPL(width,width,double)

// CanvasRect, CanvasEllipse
GNOMEMM_PROPERTY_IMPL(x1,x1,double)
GNOMEMM_PROPERTY_IMPL(x2,x2,double)
GNOMEMM_PROPERTY_IMPL(y1,y1,double)
GNOMEMM_PROPERTY_IMPL(y2,y2,double)

// CanvasImage, CanvasText, CanvasWidget
GNOMEMM_PROPERTY_IMPL(anchor,anchor,Gtk::AnchorType)

// CanvasPolygon, CanvasRect, CanvasEllipse
GNOMEMM_PROPERTY_IMPL(outline_stipple,outline_stipple,Glib::RefPtr<Gdk::Bitmap>)
GNOMEMM_PROPERTY_IMPL(wind,wind,guint)
GNOMEMM_PROPERTY_IMPL(miterlimit,miterlimit,double)

// CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse
GNOMEMM_PROPERTY_IMPL(width_pixels,width_pixels,guint)
GNOMEMM_PROPERTY_IMPL(width_units,width_units,double)

// CanvasGroup, CanvasImage, CanvasText, CanvasWidget
GNOMEMM_PROPERTY_IMPL(x,x,double)
GNOMEMM_PROPERTY_IMPL(y,y,double)

// CanvasLine, CanvasPolygon, CanvasRect, CanvasEllipse, CanvasText
GNOMEMM_PROPERTY_IMPL(fill_stipple,fill_stipple,Glib::RefPtr<Gdk::Bitmap>)

} /* namespace Properties */
} /* namespace Canvas */
} /* namespace Gnome */