1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /** |
---|
3 | * bonobo-view-frame.c: view frame object. |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Nat Friedman (nat@helixcode.com) |
---|
7 | * Miguel de Icaza (miguel@kernel.org) |
---|
8 | * |
---|
9 | * Copyright 1999, 2000 Helix Code, Inc. |
---|
10 | */ |
---|
11 | #include <config.h> |
---|
12 | #include <gtk/gtksignal.h> |
---|
13 | #include <gtk/gtkmarshal.h> |
---|
14 | #include <gtk/gtkplug.h> |
---|
15 | #include <bonobo/bonobo-exception.h> |
---|
16 | #include <bonobo/bonobo-main.h> |
---|
17 | #include <bonobo/bonobo-view.h> |
---|
18 | #include <bonobo/bonobo-view-frame.h> |
---|
19 | #include <gdk/gdkprivate.h> |
---|
20 | #include <libgnomeui/gnome-canvas.h> |
---|
21 | #include <gdk/gdkkeysyms.h> |
---|
22 | |
---|
23 | enum { |
---|
24 | USER_ACTIVATE, |
---|
25 | USER_CONTEXT, |
---|
26 | LAST_SIGNAL |
---|
27 | }; |
---|
28 | |
---|
29 | #define PARENT_TYPE BONOBO_CONTROL_FRAME_TYPE |
---|
30 | |
---|
31 | static guint view_frame_signals [LAST_SIGNAL]; |
---|
32 | |
---|
33 | /* Parent object class in GTK hierarchy */ |
---|
34 | static GtkObjectClass *bonobo_view_frame_parent_class; |
---|
35 | |
---|
36 | struct _BonoboViewFramePrivate { |
---|
37 | GtkWidget *wrapper; |
---|
38 | BonoboClientSite *client_site; |
---|
39 | BonoboUIContainer *ui_container; |
---|
40 | Bonobo_View view; |
---|
41 | }; |
---|
42 | |
---|
43 | static Bonobo_ClientSite |
---|
44 | impl_Bonobo_ViewFrame_getClientSite (PortableServer_Servant servant, |
---|
45 | CORBA_Environment *ev) |
---|
46 | { |
---|
47 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (bonobo_object_from_servant (servant)); |
---|
48 | |
---|
49 | return bonobo_object_dup_ref ( |
---|
50 | BONOBO_OBJREF (view_frame->priv->client_site), ev); |
---|
51 | } |
---|
52 | |
---|
53 | static gboolean |
---|
54 | bonobo_view_frame_wrapper_button_press_cb (GtkWidget *wrapper, |
---|
55 | GdkEventButton *event, |
---|
56 | gpointer data) |
---|
57 | { |
---|
58 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (data); |
---|
59 | |
---|
60 | bonobo_object_ref (BONOBO_OBJECT (view_frame)); |
---|
61 | |
---|
62 | /* Check for double click. */ |
---|
63 | if (event->type == GDK_2BUTTON_PRESS) |
---|
64 | gtk_signal_emit (GTK_OBJECT (view_frame), view_frame_signals [USER_ACTIVATE]); |
---|
65 | |
---|
66 | /* Check for right click. */ |
---|
67 | else if (event->type == GDK_BUTTON_PRESS && |
---|
68 | event->button == 3) |
---|
69 | gtk_signal_emit (GTK_OBJECT (view_frame), view_frame_signals [USER_CONTEXT]); |
---|
70 | |
---|
71 | bonobo_object_unref (BONOBO_OBJECT (view_frame)); |
---|
72 | |
---|
73 | return FALSE; |
---|
74 | } |
---|
75 | |
---|
76 | static gboolean |
---|
77 | bonobo_view_frame_key_press_cb (GtkWidget *wrapper, |
---|
78 | GdkEventKey *event, |
---|
79 | gpointer data) |
---|
80 | { |
---|
81 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (data); |
---|
82 | |
---|
83 | bonobo_object_ref (BONOBO_OBJECT (view_frame)); |
---|
84 | |
---|
85 | /* Hitting enter will activate the embedded component too. */ |
---|
86 | if (event->keyval == GDK_Return) |
---|
87 | gtk_signal_emit (GTK_OBJECT (view_frame), view_frame_signals [USER_ACTIVATE]); |
---|
88 | |
---|
89 | bonobo_object_unref (BONOBO_OBJECT (view_frame)); |
---|
90 | |
---|
91 | return FALSE; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * bonobo_view_frame_construct: |
---|
96 | * @view_frame: The BonoboViewFrame object to be initialized. |
---|
97 | * @wrapper: A BonoboWrapper widget which the new ViewFrame will use to cover its enclosed View. |
---|
98 | * @client_site: the client site to which the newly-created ViewFrame will belong. |
---|
99 | * @ui_container: |
---|
100 | * |
---|
101 | * Initializes @view_frame with the parameters. |
---|
102 | * |
---|
103 | * Returns: the initialized BonoboViewFrame object @view_frame that implements the |
---|
104 | * Bonobo::ViewFrame CORBA service. |
---|
105 | */ |
---|
106 | BonoboViewFrame * |
---|
107 | bonobo_view_frame_construct (BonoboViewFrame *view_frame, |
---|
108 | BonoboClientSite *client_site, |
---|
109 | Bonobo_UIContainer ui_container) |
---|
110 | { |
---|
111 | GtkWidget *wrapper; |
---|
112 | |
---|
113 | g_return_val_if_fail (view_frame != NULL, NULL); |
---|
114 | g_return_val_if_fail (BONOBO_IS_VIEW_FRAME (view_frame), NULL); |
---|
115 | g_return_val_if_fail (client_site != NULL, NULL); |
---|
116 | g_return_val_if_fail (BONOBO_IS_CLIENT_SITE (client_site), NULL); |
---|
117 | |
---|
118 | bonobo_control_frame_construct ( |
---|
119 | BONOBO_CONTROL_FRAME (view_frame), ui_container); |
---|
120 | |
---|
121 | view_frame->priv->client_site = client_site; |
---|
122 | |
---|
123 | /* |
---|
124 | * Create the BonoboWrapper which will cover the remote |
---|
125 | * BonoboView. |
---|
126 | */ |
---|
127 | wrapper = bonobo_wrapper_new (); |
---|
128 | if (wrapper == NULL) { |
---|
129 | bonobo_object_unref (BONOBO_OBJECT (view_frame)); |
---|
130 | return NULL; |
---|
131 | } |
---|
132 | gtk_object_ref (GTK_OBJECT (wrapper)); |
---|
133 | view_frame->priv->wrapper = wrapper; |
---|
134 | gtk_container_add (GTK_CONTAINER (wrapper), |
---|
135 | bonobo_control_frame_get_widget ( |
---|
136 | BONOBO_CONTROL_FRAME (view_frame))); |
---|
137 | |
---|
138 | /* |
---|
139 | * Connect signal handlers to catch activation events (double |
---|
140 | * click and hitting Enter) on the wrapper. These will cause |
---|
141 | * the ViewFrame to emit the USER_ACTIVATE signal. |
---|
142 | */ |
---|
143 | gtk_signal_connect (GTK_OBJECT (wrapper), "button_press_event", |
---|
144 | GTK_SIGNAL_FUNC (bonobo_view_frame_wrapper_button_press_cb), |
---|
145 | view_frame); |
---|
146 | gtk_signal_connect (GTK_OBJECT (wrapper), "key_press_event", |
---|
147 | GTK_SIGNAL_FUNC (bonobo_view_frame_key_press_cb), |
---|
148 | view_frame); |
---|
149 | |
---|
150 | return view_frame; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * bonobo_view_frame_new: |
---|
155 | * @client_site: the client site to which the newly-created ViewFrame will belong. |
---|
156 | * @ui_container: A CORBA object for the container's UIContainer server. |
---|
157 | * |
---|
158 | * Returns: BonoboViewFrame object that implements the |
---|
159 | * Bonobo::ViewFrame CORBA service. |
---|
160 | */ |
---|
161 | BonoboViewFrame * |
---|
162 | bonobo_view_frame_new (BonoboClientSite *client_site, |
---|
163 | Bonobo_UIContainer ui_container) |
---|
164 | { |
---|
165 | BonoboViewFrame *view_frame; |
---|
166 | |
---|
167 | g_return_val_if_fail (client_site != NULL, NULL); |
---|
168 | g_return_val_if_fail (BONOBO_IS_CLIENT_SITE (client_site), NULL); |
---|
169 | |
---|
170 | view_frame = gtk_type_new (BONOBO_VIEW_FRAME_TYPE); |
---|
171 | |
---|
172 | return bonobo_view_frame_construct (view_frame, client_site, ui_container); |
---|
173 | } |
---|
174 | |
---|
175 | static void |
---|
176 | bonobo_view_frame_destroy (GtkObject *object) |
---|
177 | { |
---|
178 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (object); |
---|
179 | |
---|
180 | if (view_frame->priv->view != CORBA_OBJECT_NIL) |
---|
181 | bonobo_object_release_unref (view_frame->priv->view, NULL); |
---|
182 | |
---|
183 | bonobo_view_frame_parent_class->destroy (object); |
---|
184 | } |
---|
185 | |
---|
186 | static void |
---|
187 | bonobo_view_frame_finalize (GtkObject *object) |
---|
188 | { |
---|
189 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (object); |
---|
190 | |
---|
191 | gtk_object_unref (GTK_OBJECT (view_frame->priv->wrapper)); |
---|
192 | g_free (view_frame->priv); |
---|
193 | |
---|
194 | bonobo_view_frame_parent_class->finalize (object); |
---|
195 | } |
---|
196 | |
---|
197 | static void |
---|
198 | bonobo_view_frame_class_init (BonoboViewFrameClass *klass) |
---|
199 | { |
---|
200 | GtkObjectClass *object_class = (GtkObjectClass *) klass; |
---|
201 | POA_Bonobo_ViewFrame__epv *epv = &klass->epv; |
---|
202 | |
---|
203 | bonobo_view_frame_parent_class = gtk_type_class (PARENT_TYPE); |
---|
204 | |
---|
205 | view_frame_signals [USER_ACTIVATE] = |
---|
206 | gtk_signal_new ("user_activate", |
---|
207 | GTK_RUN_LAST, |
---|
208 | object_class->type, |
---|
209 | GTK_SIGNAL_OFFSET (BonoboViewFrameClass, user_activate), |
---|
210 | gtk_marshal_NONE__NONE, |
---|
211 | GTK_TYPE_NONE, 0); |
---|
212 | |
---|
213 | view_frame_signals [USER_CONTEXT] = |
---|
214 | gtk_signal_new ("user_context", |
---|
215 | GTK_RUN_LAST, |
---|
216 | object_class->type, |
---|
217 | GTK_SIGNAL_OFFSET (BonoboViewFrameClass, user_context), |
---|
218 | gtk_marshal_NONE__NONE, |
---|
219 | GTK_TYPE_NONE, 0); |
---|
220 | |
---|
221 | gtk_object_class_add_signals ( |
---|
222 | object_class, |
---|
223 | view_frame_signals, |
---|
224 | LAST_SIGNAL); |
---|
225 | |
---|
226 | object_class->destroy = bonobo_view_frame_destroy; |
---|
227 | object_class->finalize = bonobo_view_frame_finalize; |
---|
228 | |
---|
229 | epv->getClientSite = impl_Bonobo_ViewFrame_getClientSite; |
---|
230 | } |
---|
231 | |
---|
232 | static void |
---|
233 | bonobo_view_frame_init (BonoboObject *object) |
---|
234 | { |
---|
235 | BonoboViewFrame *view_frame = BONOBO_VIEW_FRAME (object); |
---|
236 | |
---|
237 | view_frame->priv = g_new0 (BonoboViewFramePrivate, 1); |
---|
238 | } |
---|
239 | |
---|
240 | BONOBO_X_TYPE_FUNC_FULL (BonoboViewFrame, |
---|
241 | Bonobo_ViewFrame, |
---|
242 | PARENT_TYPE, |
---|
243 | bonobo_view_frame); |
---|
244 | |
---|
245 | /** |
---|
246 | * bonobo_view_frame_bind_to_view: |
---|
247 | * @view_frame: A BonoboViewFrame object. |
---|
248 | * @view: The CORBA object for the BonoboView embedded |
---|
249 | * in this ViewFrame. |
---|
250 | * |
---|
251 | * Associates @view with this @view_frame. |
---|
252 | */ |
---|
253 | void |
---|
254 | bonobo_view_frame_bind_to_view (BonoboViewFrame *view_frame, Bonobo_View view) |
---|
255 | { |
---|
256 | g_return_if_fail (view_frame != NULL); |
---|
257 | g_return_if_fail (view != CORBA_OBJECT_NIL); |
---|
258 | g_return_if_fail (BONOBO_IS_VIEW_FRAME (view_frame)); |
---|
259 | |
---|
260 | bonobo_control_frame_bind_to_control ( |
---|
261 | BONOBO_CONTROL_FRAME (view_frame), |
---|
262 | (Bonobo_Control) view); |
---|
263 | |
---|
264 | view_frame->priv->view = bonobo_object_dup_ref (view, NULL); |
---|
265 | } |
---|
266 | |
---|
267 | /** |
---|
268 | * bonobo_view_frame_get_view: |
---|
269 | * @view_frame: A BonoboViewFrame object. |
---|
270 | * @view: The CORBA object for the BonoboView embedded |
---|
271 | * in this ViewFrame. |
---|
272 | * |
---|
273 | * Associates @view with this @view_frame. |
---|
274 | */ |
---|
275 | Bonobo_View |
---|
276 | bonobo_view_frame_get_view (BonoboViewFrame *view_frame) |
---|
277 | { |
---|
278 | g_return_val_if_fail (view_frame != NULL, CORBA_OBJECT_NIL); |
---|
279 | g_return_val_if_fail (BONOBO_IS_VIEW_FRAME (view_frame), CORBA_OBJECT_NIL); |
---|
280 | |
---|
281 | return view_frame->priv->view; |
---|
282 | } |
---|
283 | |
---|
284 | /** |
---|
285 | * bonobo_view_frame_set_covered: |
---|
286 | * @view_frame: A BonoboViewFrame object whose embedded View should be |
---|
287 | * either covered or uncovered. |
---|
288 | * @covered: %TRUE if the View should be covered. %FALSE if it should |
---|
289 | * be uncovered. |
---|
290 | * |
---|
291 | * This function either covers or uncovers the View embedded in a |
---|
292 | * BonoboViewFrame. If the View is covered, then the embedded widgets |
---|
293 | * will receive no Gtk events, such as mouse movements, keypresses, |
---|
294 | * and exposures. When the View is uncovered, all events pass through |
---|
295 | * to the BonoboView's widgets normally. |
---|
296 | */ |
---|
297 | void |
---|
298 | bonobo_view_frame_set_covered (BonoboViewFrame *view_frame, gboolean covered) |
---|
299 | { |
---|
300 | GtkWidget *wrapper; |
---|
301 | |
---|
302 | g_return_if_fail (view_frame != NULL); |
---|
303 | g_return_if_fail (BONOBO_IS_VIEW_FRAME (view_frame)); |
---|
304 | |
---|
305 | wrapper = bonobo_view_frame_get_wrapper (view_frame); |
---|
306 | bonobo_wrapper_set_covered (BONOBO_WRAPPER (wrapper), covered); |
---|
307 | } |
---|
308 | |
---|
309 | |
---|
310 | /** |
---|
311 | * bonobo_view_frame_get_ui_container: |
---|
312 | * @view_frame: A BonoboViewFrame object. |
---|
313 | * |
---|
314 | * Returns: The BonoboUIContainer associated with this ViewFrame. See |
---|
315 | * also bonobo_view_frame_set_ui_container(). |
---|
316 | */ |
---|
317 | Bonobo_UIContainer |
---|
318 | bonobo_view_frame_get_ui_container (BonoboViewFrame *view_frame) |
---|
319 | { |
---|
320 | g_return_val_if_fail (view_frame != NULL, NULL); |
---|
321 | g_return_val_if_fail (BONOBO_IS_VIEW_FRAME (view_frame), NULL); |
---|
322 | |
---|
323 | return bonobo_control_frame_get_ui_container ( |
---|
324 | BONOBO_CONTROL_FRAME (view_frame)); |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * bonobo_view_frame_view_activate: |
---|
329 | * @view_frame: The BonoboViewFrame object whose view should be |
---|
330 | * activated. |
---|
331 | * |
---|
332 | * Activates the BonoboView embedded in @view_frame by calling the |
---|
333 | * activate() #Bonobo_Control interface method on it. |
---|
334 | */ |
---|
335 | void |
---|
336 | bonobo_view_frame_view_activate (BonoboViewFrame *view_frame) |
---|
337 | { |
---|
338 | g_return_if_fail (view_frame != NULL); |
---|
339 | g_return_if_fail (BONOBO_IS_VIEW_FRAME (view_frame)); |
---|
340 | |
---|
341 | bonobo_control_frame_control_activate ( |
---|
342 | BONOBO_CONTROL_FRAME (view_frame)); |
---|
343 | } |
---|
344 | |
---|
345 | |
---|
346 | /** |
---|
347 | * bonobo_view_frame_view_deactivate: |
---|
348 | * @view_frame: The BonoboViewFrame object whose view should be |
---|
349 | * deactivated. |
---|
350 | * |
---|
351 | * Deactivates the BonoboView embedded in @view_frame by calling a the |
---|
352 | * activate() CORBA method on it with the parameter %FALSE. |
---|
353 | */ |
---|
354 | void |
---|
355 | bonobo_view_frame_view_deactivate (BonoboViewFrame *view_frame) |
---|
356 | { |
---|
357 | g_return_if_fail (view_frame != NULL); |
---|
358 | g_return_if_fail (BONOBO_IS_VIEW_FRAME (view_frame)); |
---|
359 | |
---|
360 | bonobo_control_frame_control_deactivate ( |
---|
361 | BONOBO_CONTROL_FRAME (view_frame)); |
---|
362 | } |
---|
363 | |
---|
364 | /** |
---|
365 | * bonobo_view_frame_get_wrapper: |
---|
366 | * @view_frame: A BonoboViewFrame object. |
---|
367 | * |
---|
368 | * Returns: The BonoboWrapper widget associated with this ViewFrame. |
---|
369 | */ |
---|
370 | GtkWidget * |
---|
371 | bonobo_view_frame_get_wrapper (BonoboViewFrame *view_frame) |
---|
372 | { |
---|
373 | g_return_val_if_fail (view_frame != NULL, NULL); |
---|
374 | g_return_val_if_fail (BONOBO_IS_VIEW_FRAME (view_frame), NULL); |
---|
375 | |
---|
376 | return GTK_WIDGET (view_frame->priv->wrapper); |
---|
377 | } |
---|
378 | |
---|
379 | /** |
---|
380 | * bonobo_view_frame_set_zoom_factor: |
---|
381 | * @view_frame: A BonoboViewFrame object. |
---|
382 | * @zoom: a zoom factor. 1.0 means one-to-one mapping. |
---|
383 | * |
---|
384 | * Requests the associated view to change its zoom factor the the value in @zoom. |
---|
385 | */ |
---|
386 | void |
---|
387 | bonobo_view_frame_set_zoom_factor (BonoboViewFrame *view_frame, double zoom) |
---|
388 | { |
---|
389 | CORBA_Environment ev; |
---|
390 | |
---|
391 | g_return_if_fail (view_frame != NULL); |
---|
392 | g_return_if_fail (BONOBO_IS_VIEW_FRAME (view_frame)); |
---|
393 | g_return_if_fail (zoom > 0.0); |
---|
394 | |
---|
395 | CORBA_exception_init (&ev); |
---|
396 | Bonobo_View_setZoomFactor (view_frame->priv->view, zoom, &ev); |
---|
397 | if (BONOBO_EX (&ev)) { |
---|
398 | bonobo_object_check_env ( |
---|
399 | BONOBO_OBJECT (view_frame), |
---|
400 | (CORBA_Object) view_frame->priv->view, &ev); |
---|
401 | } |
---|
402 | CORBA_exception_free (&ev); |
---|
403 | } |
---|
404 | |
---|
405 | /** |
---|
406 | * bonobo_view_frame_get_client_site: |
---|
407 | * @view_frame: The view frame |
---|
408 | * |
---|
409 | * Returns the BonoboClientSite associated with this view frame |
---|
410 | */ |
---|
411 | BonoboClientSite * |
---|
412 | bonobo_view_frame_get_client_site (BonoboViewFrame *view_frame) |
---|
413 | { |
---|
414 | g_return_val_if_fail (view_frame != NULL, NULL); |
---|
415 | g_return_val_if_fail (BONOBO_IS_VIEW_FRAME (view_frame), NULL); |
---|
416 | |
---|
417 | return view_frame->priv->client_site; |
---|
418 | } |
---|
419 | |
---|