]> matita.cs.unibo.it Git - helm.git/blob - src/control-factory.c
made executable again
[helm.git] / src / control-factory.c
1
2 #include <bonobo.h>
3 #include <bonobo/bonobo-shlib-factory.h>
4
5 #include <gtkmathview.h>
6
7 #include "control-factory.h"
8
9 enum {
10   MATH_VIEW_WIDTH,
11   MATH_VIEW_HEIGHT,
12   MATH_VIEW_TOP_X,
13   MATH_VIEW_TOP_Y,
14   MATH_VIEW_FONT_SIZE,
15   MATH_VIEW_ANTI_ALIASING,
16   MATH_VIEW_TRANSPARENCY,
17   MATH_VIEW_VERBOSITY,
18   MATH_VIEW_FONT_MANAGER
19 } math_args;
20
21
22 /*static char *
23 make_reg_id(const char *iid)
24 {
25         char *id;
26         id = bonobo_activation_make_registration_id(iid,Display_String(gdk_display));
27         return id;
28 }*/
29
30 static void
31 get_prop(BonoboPropertyBag      *bag,
32          BonoboArg      *arg,
33          guint          arg_id,
34          CORBA_Environment *ev,
35          gpointer       user_data)
36 {
37   GtkMathView *math_view;
38
39   g_return_if_fail(GTK_IS_MATH_VIEW(user_data));
40
41   math_view = GTK_MATH_VIEW(user_data);
42
43   switch(arg_id)
44     {
45     case MATH_VIEW_WIDTH:
46       {
47         gint i = gtk_math_view_get_width(math_view);
48         g_assert(arg->_type == BONOBO_ARG_INT);
49         BONOBO_ARG_SET_INT(arg,i);
50       }
51       break;
52     case MATH_VIEW_HEIGHT:
53       {
54         guint i = gtk_math_view_get_height(math_view);
55                         
56         g_assert(arg->_type == BONOBO_ARG_INT);
57         BONOBO_ARG_SET_INT(arg,i);      
58       }
59       break;
60     case MATH_VIEW_TOP_X:
61       {
62         guint new_top_y,new_top_x;
63                         
64         g_assert(arg->_type == BONOBO_ARG_INT);
65         gtk_math_view_get_top(math_view,&new_top_x, &new_top_y);
66         BONOBO_ARG_SET_INT(arg,new_top_x);
67       }
68       break;
69     case MATH_VIEW_TOP_Y:
70       {
71         guint new_top_y,new_top_x;
72
73         g_assert(arg->_type == BONOBO_ARG_INT);
74         gtk_math_view_get_top(math_view,&new_top_x,&new_top_y);
75         BONOBO_ARG_SET_INT(arg,new_top_y);
76       }         
77       break;
78     case MATH_VIEW_FONT_SIZE:
79       {
80         guint i = gtk_math_view_get_font_size(math_view);
81         g_assert(arg->_type == BONOBO_ARG_INT);
82                         
83         BONOBO_ARG_SET_INT(arg,i);
84       }
85       break;
86     case MATH_VIEW_ANTI_ALIASING:
87       {
88         gboolean i = gtk_math_view_get_anti_aliasing(math_view);
89         g_assert(arg->_type == BONOBO_ARG_BOOLEAN);
90                         
91         BONOBO_ARG_SET_BOOLEAN(arg,i);
92       }
93       break;
94     case MATH_VIEW_TRANSPARENCY:
95       {
96         gboolean i = gtk_math_view_get_transparency(math_view);
97         g_assert(arg->_type == BONOBO_ARG_BOOLEAN);
98                         
99         BONOBO_ARG_SET_BOOLEAN(arg,i);
100       }
101       break;
102     case MATH_VIEW_VERBOSITY:
103       {
104         gint i = gtk_math_view_get_log_verbosity(math_view);
105         g_assert(arg->_type == BONOBO_ARG_INT);
106                         
107         BONOBO_ARG_SET_INT(arg,i);
108       }
109       break;
110     case MATH_VIEW_FONT_MANAGER:
111       {gint i = (gint) gtk_math_view_get_font_manager_type(math_view);
112       BONOBO_ARG_SET_INT(arg,i);
113       }
114       break;
115     default:
116       g_assert(FALSE);
117     }
118 }
119
120 static void
121 set_prop(BonoboPropertyBag      *bag,
122          const BonoboArg        *arg,
123          guint          arg_id,
124          CORBA_Environment *ev,
125          gpointer       user_data)
126 {
127   GtkMathView *math_view;
128
129   g_return_if_fail(GTK_IS_MATH_VIEW(user_data));
130
131   math_view = GTK_MATH_VIEW(user_data);
132
133   switch(arg_id)
134     {
135       /*case MATH_VIEW_WIDTH:
136         g_assert(arg->_type == BONOBO_ARG_INT);
137                         
138         guint i = gtk_math_view_set_width(math_view);
139         BONOBO_ARG_SET_INT(arg,i);
140         break;
141         case MATH_VIEW_HEIGHT:
142         g_assert(arg->_type == BONOBO_ARG_INT);
143                         
144         guint i = gtk_math_view_get_height(math_view);
145         BONOBO_ARG_SET_INT(arg,i);      
146         break;*/
147     case MATH_VIEW_TOP_X:
148       {
149         guint old_top_y;
150         g_assert(arg->_type == BONOBO_ARG_INT);
151                         
152         gtk_math_view_get_top(math_view, NULL, &old_top_y);
153         gtk_math_view_set_top(math_view, BONOBO_ARG_GET_INT(arg), old_top_y);
154       }
155       break;
156     case MATH_VIEW_TOP_Y:
157       {
158         guint old_top_x;
159         g_assert(arg->_type == BONOBO_ARG_INT);
160
161         gtk_math_view_get_top(math_view, &old_top_x, NULL);
162         gtk_math_view_set_top(math_view, BONOBO_ARG_GET_INT(arg), old_top_x);
163       }
164       break;
165     case MATH_VIEW_FONT_SIZE:
166       {
167         guint i = gtk_math_view_get_font_size(math_view);
168         g_assert(arg->_type == BONOBO_ARG_INT);
169                         
170         BONOBO_ARG_SET_INT(arg,i);
171       }
172       break;
173     case MATH_VIEW_ANTI_ALIASING:
174       {
175         gboolean i = gtk_math_view_get_anti_aliasing(math_view);
176         g_assert(arg->_type == BONOBO_ARG_BOOLEAN);
177                         
178         BONOBO_ARG_SET_BOOLEAN(arg,i);
179       }
180       break;
181     case MATH_VIEW_TRANSPARENCY:
182       {
183         gboolean i = gtk_math_view_get_transparency(math_view);
184         g_assert(arg->_type == BONOBO_ARG_BOOLEAN);
185                         
186         BONOBO_ARG_SET_BOOLEAN(arg,i);
187       }
188       break;
189     case MATH_VIEW_VERBOSITY:
190       {
191         gint i = gtk_math_view_get_log_verbosity(math_view);
192         g_assert(arg->_type == BONOBO_ARG_INT);
193                         
194         BONOBO_ARG_SET_INT(arg,i);
195       }
196       break;
197     case MATH_VIEW_FONT_MANAGER:
198       {
199         gint i = (gint) gtk_math_view_get_font_manager_type(math_view);
200         BONOBO_ARG_SET_INT(arg,i);
201       }
202       break;
203     default:
204       g_assert(FALSE);
205     }
206 }
207
208 static BonoboObject*
209 gtk_math_view_control_factory(BonoboGenericFactory* factory, const gchar* component_id, gpointer closure)
210 {
211   BonoboControl *control;
212   BonoboPropertyBag *prop_bag;
213   GtkWidget *math_view;
214         
215   math_view = gtk_math_view_new(NULL,NULL);
216   gtk_widget_show(math_view);
217
218   control = bonobo_control_new(math_view);
219
220   /*
221   persist_file = gtk_math_view_persist_file_new(GTK_MATH_VIEW(math_view));
222   bonobo_object_add_interface(BONOBO_OBJECT(control), persist_file);
223   */
224
225   prop_bag = bonobo_property_bag_new(get_prop, set_prop, math_view);
226   bonobo_control_set_properties(control, BONOBO_OBJREF(prop_bag), NULL);
227         
228   bonobo_property_bag_add(prop_bag,"width",MATH_VIEW_WIDTH,BONOBO_ARG_INT,
229                           NULL,"width",0);
230   bonobo_property_bag_add(prop_bag,"height",MATH_VIEW_HEIGHT,BONOBO_ARG_INT,
231                           NULL,"height",0);
232   bonobo_property_bag_add(prop_bag,"top_x",MATH_VIEW_TOP_X,BONOBO_ARG_INT,
233                           NULL,"top_x",0);
234   bonobo_property_bag_add(prop_bag,"top_y",MATH_VIEW_TOP_Y,BONOBO_ARG_INT,
235                           NULL,"top_y",0);
236   bonobo_property_bag_add(prop_bag,"font_size",MATH_VIEW_FONT_SIZE,BONOBO_ARG_INT,
237                           NULL,"font_size",0);
238   bonobo_property_bag_add(prop_bag,"anti_aliasing",MATH_VIEW_ANTI_ALIASING,BONOBO_ARG_BOOLEAN,
239                           NULL,"anti_aliasing",0);
240   bonobo_property_bag_add(prop_bag,"transparency",MATH_VIEW_TRANSPARENCY,BONOBO_ARG_BOOLEAN,
241                           NULL,"transparency",0);
242   bonobo_property_bag_add(prop_bag,"verbosity",MATH_VIEW_VERBOSITY,BONOBO_ARG_INT,
243                           NULL,"verbosity",0);
244   bonobo_property_bag_add(prop_bag,"font_manager",MATH_VIEW_FONT_MANAGER,BONOBO_ARG_NULL,
245                           NULL,"font_manager",0);
246
247   bonobo_object_unref(BONOBO_OBJECT(prop_bag));
248
249   return BONOBO_OBJECT(control);
250 }
251
252 BONOBO_ACTIVATION_SHLIB_FACTORY (CONTROL_FACTORY_ID, "GtkMathView Factory", gtk_math_view_control_factory, NULL);
253