source: trunk/third/evolution/shell/evolution-shell-component-dnd.c @ 16787

Revision 16787, 14.8 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16786, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* evolution-shell-component-dnd.c
3 *
4 * Copyright (C) 2000, 2001 Ximian, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Author: Chris Toshok
21 */
22
23#include <gal/util/e-util.h>
24
25#include "Evolution.h"
26#include "evolution-shell-component-dnd.h"
27
28
29#define PARENT_TYPE (bonobo_object_get_type ())
30
31static BonoboObjectClass *parent_class;
32
33/* Source Folder stuff */
34
35struct _DndSourceFolderPrivate {
36        DndSourceFolderBeginDragFn begin_drag;
37        DndSourceFolderGetDataFn get_data;
38        DndSourceFolderDeleteDataFn delete_data;
39        DndSourceFolderEndDragFn end_drag;
40        gpointer user_data;
41};
42
43/* GtkObject methods */
44static void
45dnd_source_destroy (GtkObject *object)
46{
47        EvolutionShellComponentDndSourceFolder *folder;
48        DndSourceFolderPrivate *priv;
49
50        folder = EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (object);
51        priv = folder->priv;
52
53        g_return_if_fail (priv != NULL);
54
55        g_free (priv);
56       
57        GTK_OBJECT_CLASS (parent_class)->destroy (object);
58}
59
60static void
61impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_beginDrag (PortableServer_Servant servant, const CORBA_char * physical_uri,
62                                                               const CORBA_char * folder_type, GNOME_Evolution_ShellComponentDnd_ActionSet * possible_actions,
63                                                               GNOME_Evolution_ShellComponentDnd_Action * suggested_action, CORBA_Environment * ev)
64{
65        BonoboObject *bonobo_object;
66        EvolutionShellComponentDndSourceFolder *folder;
67        DndSourceFolderPrivate *priv;
68
69        bonobo_object = bonobo_object_from_servant (servant);
70        folder = EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (bonobo_object);
71        priv = folder->priv;
72
73        priv->begin_drag (folder, physical_uri, folder_type, possible_actions, suggested_action, priv->user_data);
74}
75
76static void
77impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_getData (PortableServer_Servant servant,
78                                                             const GNOME_Evolution_ShellComponentDnd_SourceFolder_Context * source_context,
79                                                             const GNOME_Evolution_ShellComponentDnd_Action action, const CORBA_char * dnd_type,
80                                                             GNOME_Evolution_ShellComponentDnd_Data ** data, CORBA_Environment * ev)
81{
82        BonoboObject *bonobo_object;
83        EvolutionShellComponentDndSourceFolder *folder;
84        DndSourceFolderPrivate *priv;
85
86        bonobo_object = bonobo_object_from_servant (servant);
87        folder = EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (bonobo_object);
88        priv = folder->priv;
89
90        priv->get_data (folder, source_context, action, dnd_type, data, ev, priv->user_data);
91}
92
93static void
94impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_deleteData (PortableServer_Servant servant,
95                                                                const GNOME_Evolution_ShellComponentDnd_SourceFolder_Context * source_context,
96                                                                CORBA_Environment * ev)
97{
98        BonoboObject *bonobo_object;
99        EvolutionShellComponentDndSourceFolder *folder;
100        DndSourceFolderPrivate *priv;
101
102        bonobo_object = bonobo_object_from_servant (servant);
103        folder = EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (bonobo_object);
104        priv = folder->priv;
105
106        priv->delete_data (folder, source_context, priv->user_data);
107}
108
109static void
110impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_endDrag (PortableServer_Servant servant,
111                                                             const GNOME_Evolution_ShellComponentDnd_SourceFolder_Context * source_context,
112                                                             CORBA_Environment * ev)
113{
114        BonoboObject *bonobo_object;
115        EvolutionShellComponentDndSourceFolder *folder;
116        DndSourceFolderPrivate *priv;
117
118        bonobo_object = bonobo_object_from_servant (servant);
119        folder = EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (bonobo_object);
120        priv = folder->priv;
121
122        priv->end_drag (folder, source_context, priv->user_data);
123}
124
125static POA_GNOME_Evolution_ShellComponentDnd_SourceFolder__vepv SourceFolder_vepv;
126
127static POA_GNOME_Evolution_ShellComponentDnd_SourceFolder *
128create_dnd_source_servant (void)
129{
130        POA_GNOME_Evolution_ShellComponentDnd_SourceFolder *servant;
131        CORBA_Environment ev;
132
133        servant = (POA_GNOME_Evolution_ShellComponentDnd_SourceFolder *)g_new0 (BonoboObjectServant, 1);
134        servant->vepv = &SourceFolder_vepv;
135
136        CORBA_exception_init (&ev);
137        POA_GNOME_Evolution_ShellComponentDnd_SourceFolder__init ((PortableServer_Servant) servant, &ev);
138        if (ev._major != CORBA_NO_EXCEPTION) {
139                g_free (servant);
140                CORBA_exception_free (&ev);
141                return NULL;
142        }
143
144        CORBA_exception_free (&ev);
145
146        return servant;
147}
148
149static void
150source_corba_class_init (void)
151{
152        POA_GNOME_Evolution_ShellComponentDnd_SourceFolder__vepv *vepv;
153        POA_GNOME_Evolution_ShellComponentDnd_SourceFolder__epv *epv;
154        PortableServer_ServantBase__epv *base_epv;
155
156        base_epv = g_new0 (PortableServer_ServantBase__epv, 1);
157        base_epv->_private = NULL;
158        base_epv->finalize = NULL;
159        base_epv->default_POA = NULL;
160
161        epv = g_new0 (POA_GNOME_Evolution_ShellComponentDnd_SourceFolder__epv, 1);
162        epv->beginDrag = impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_beginDrag;
163        epv->getData = impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_getData;
164        epv->deleteData = impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_deleteData;
165        epv->endDrag = impl_GNOME_Evolution_ShellComponentDnd_SourceFolder_endDrag;
166
167        vepv = &SourceFolder_vepv;
168        vepv->_base_epv = base_epv;
169        vepv->Bonobo_Unknown_epv = bonobo_object_get_epv ();
170        vepv->GNOME_Evolution_ShellComponentDnd_SourceFolder_epv = epv;
171}
172
173static void
174evolution_shell_component_dnd_source_folder_class_init (EvolutionShellComponentDndSourceFolderClass *klass)
175{
176        GtkObjectClass *object_class;
177
178        object_class = GTK_OBJECT_CLASS (klass);
179        object_class->destroy = dnd_source_destroy;
180
181        parent_class = gtk_type_class (PARENT_TYPE);
182
183        source_corba_class_init ();
184}
185
186static void
187evolution_shell_component_dnd_source_folder_init (EvolutionShellComponentDndSourceFolder *folder)
188{
189        DndSourceFolderPrivate *priv;
190
191        priv = g_new (DndSourceFolderPrivate, 1);
192
193        folder->priv = priv;
194}
195
196
197E_MAKE_TYPE (evolution_shell_component_dnd_source_folder, "EvolutionShellComponentDndSourceFolder",
198             EvolutionShellComponentDndSourceFolder, evolution_shell_component_dnd_source_folder_class_init,
199             evolution_shell_component_dnd_source_folder_init, PARENT_TYPE);
200
201static void
202evolution_shell_component_dnd_source_folder_construct (EvolutionShellComponentDndSourceFolder *dnd_source,
203                                                       DndSourceFolderBeginDragFn begin_drag,
204                                                       DndSourceFolderGetDataFn get_data,
205                                                       DndSourceFolderDeleteDataFn delete_data,
206                                                       DndSourceFolderEndDragFn end_drag,
207                                                       gpointer user_data,
208                                                       GNOME_Evolution_ShellComponentDnd_SourceFolder corba_object)
209{
210        DndSourceFolderPrivate *priv;
211
212        g_return_if_fail (dnd_source != NULL);
213        g_return_if_fail (IS_EVOLUTION_SHELL_COMPONENT_DND_SOURCE_FOLDER (dnd_source));
214        g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
215
216        priv = dnd_source->priv;
217
218        priv->begin_drag = begin_drag;
219        priv->get_data = get_data;
220        priv->delete_data = delete_data;
221        priv->end_drag = end_drag;
222        priv->user_data = user_data;
223
224        bonobo_object_construct (BONOBO_OBJECT (dnd_source), corba_object);
225}
226
227EvolutionShellComponentDndSourceFolder*
228evolution_shell_component_dnd_source_folder_new (DndSourceFolderBeginDragFn begin_drag,
229                                                 DndSourceFolderGetDataFn get_data,
230                                                 DndSourceFolderDeleteDataFn delete_data,
231                                                 DndSourceFolderEndDragFn end_drag,
232                                                 gpointer user_data)
233{
234        EvolutionShellComponentDndSourceFolder *dnd_source;
235        POA_GNOME_Evolution_ShellComponentDnd_SourceFolder *servant;
236        GNOME_Evolution_ShellComponentDnd_SourceFolder corba_object;
237
238        g_return_val_if_fail (begin_drag != NULL, NULL);
239        g_return_val_if_fail (get_data != NULL, NULL);
240        g_return_val_if_fail (delete_data != NULL, NULL);
241        g_return_val_if_fail (end_drag != NULL, NULL);
242
243        servant = create_dnd_source_servant();
244        if (servant == NULL)
245                return NULL;
246
247        dnd_source = gtk_type_new (evolution_shell_component_dnd_source_folder_get_type ());
248        corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (dnd_source),
249                                                       servant);
250
251        evolution_shell_component_dnd_source_folder_construct (dnd_source,
252                                                               begin_drag, get_data,
253                                                               delete_data, end_drag,
254                                                               user_data,
255                                                               corba_object);
256        return dnd_source;
257}
258
259
260
261/* Destination Folder stuff */
262
263struct _DndDestinationFolderPrivate {
264        DndDestinationFolderHandleMotionFn handle_motion;
265        DndDestinationFolderHandleDropFn handle_drop;
266        gpointer user_data;
267};
268
269/* GtkObject methods */
270static void
271dnd_destination_destroy (GtkObject *object)
272{
273        EvolutionShellComponentDndDestinationFolder *folder;
274        DndDestinationFolderPrivate *priv;
275
276        folder = EVOLUTION_SHELL_COMPONENT_DND_DESTINATION_FOLDER (object);
277        priv = folder->priv;
278
279        g_return_if_fail (priv != NULL);
280
281        g_free (priv);
282       
283        GTK_OBJECT_CLASS (parent_class)->destroy (object);
284}
285
286/* CORBA interface */
287static CORBA_boolean
288impl_GNOME_Evolution_ShellComponentDnd_DestinationFolder_handleMotion (PortableServer_Servant servant,
289                                                                       const CORBA_char* physical_uri,
290                                                                       const CORBA_char *folder_type,
291                                                                       const GNOME_Evolution_ShellComponentDnd_DestinationFolder_Context * destination_context,
292                                                                       GNOME_Evolution_ShellComponentDnd_Action * suggested_action, CORBA_Environment * ev)
293{
294        BonoboObject *bonobo_object;
295        EvolutionShellComponentDndDestinationFolder *folder;
296        DndDestinationFolderPrivate *priv;
297
298        bonobo_object = bonobo_object_from_servant (servant);
299        folder = EVOLUTION_SHELL_COMPONENT_DND_DESTINATION_FOLDER (bonobo_object);
300        priv = folder->priv;
301
302        return priv->handle_motion (folder, physical_uri, folder_type, destination_context, suggested_action, priv->user_data);
303}
304
305static CORBA_boolean
306impl_GNOME_Evolution_ShellComponentDnd_DestinationFolder_handleDrop (PortableServer_Servant servant,
307                                                                     const CORBA_char *physical_uri,
308                                                                     const CORBA_char *folder_type,
309                                                                     const GNOME_Evolution_ShellComponentDnd_DestinationFolder_Context * destination_context,
310                                                                     const GNOME_Evolution_ShellComponentDnd_Action action,
311                                                                     const GNOME_Evolution_ShellComponentDnd_Data * data, CORBA_Environment * ev)
312{
313        BonoboObject *bonobo_object;
314        EvolutionShellComponentDndDestinationFolder *folder;
315        DndDestinationFolderPrivate *priv;
316
317        bonobo_object = bonobo_object_from_servant (servant);
318        folder = EVOLUTION_SHELL_COMPONENT_DND_DESTINATION_FOLDER (bonobo_object);
319        priv = folder->priv;
320
321        return priv->handle_drop (folder, physical_uri, folder_type, destination_context, action, data, priv->user_data);
322}
323
324static POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder__vepv DestinationFolder_vepv;
325
326static POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder *
327create_dnd_destination_servant (void)
328{
329        POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder *servant;
330        CORBA_Environment ev;
331
332        servant = (POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder *)g_new0 (BonoboObjectServant, 1);
333        servant->vepv = &DestinationFolder_vepv;
334
335        CORBA_exception_init (&ev);
336        POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder__init ((PortableServer_Servant) servant, &ev);
337        if (ev._major != CORBA_NO_EXCEPTION) {
338                g_free (servant);
339                CORBA_exception_free (&ev);
340                return NULL;
341        }
342
343        CORBA_exception_free (&ev);
344
345        return servant;
346}
347
348static void
349destination_corba_class_init (void)
350{
351        POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder__vepv *vepv;
352        POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder__epv *epv;
353        PortableServer_ServantBase__epv *base_epv;
354
355        base_epv = g_new0 (PortableServer_ServantBase__epv, 1);
356        base_epv->_private = NULL;
357        base_epv->finalize = NULL;
358        base_epv->default_POA = NULL;
359
360        epv = g_new0 (POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder__epv, 1);
361        epv->handleMotion = impl_GNOME_Evolution_ShellComponentDnd_DestinationFolder_handleMotion;
362        epv->handleDrop = impl_GNOME_Evolution_ShellComponentDnd_DestinationFolder_handleDrop;
363
364        vepv = &DestinationFolder_vepv;
365        vepv->_base_epv = base_epv;
366        vepv->Bonobo_Unknown_epv = bonobo_object_get_epv ();
367        vepv->GNOME_Evolution_ShellComponentDnd_DestinationFolder_epv = epv;
368}
369
370static void
371evolution_shell_component_dnd_destination_folder_class_init (EvolutionShellComponentDndDestinationFolderClass *klass)
372{
373        GtkObjectClass *object_class;
374
375        object_class = GTK_OBJECT_CLASS (klass);
376        object_class->destroy = dnd_destination_destroy;
377
378        parent_class = gtk_type_class (PARENT_TYPE);
379
380        destination_corba_class_init ();
381}
382
383static void
384evolution_shell_component_dnd_destination_folder_init (EvolutionShellComponentDndDestinationFolder *folder)
385{
386        DndDestinationFolderPrivate *priv;
387
388        priv = g_new (DndDestinationFolderPrivate, 1);
389
390        folder->priv = priv;
391}
392
393
394E_MAKE_TYPE (evolution_shell_component_dnd_destination_folder, "EvolutionShellComponentDndDestinationFolder",
395             EvolutionShellComponentDndDestinationFolder, evolution_shell_component_dnd_destination_folder_class_init,
396             evolution_shell_component_dnd_destination_folder_init, PARENT_TYPE);
397
398static void
399evolution_shell_component_dnd_destination_folder_construct (EvolutionShellComponentDndDestinationFolder *dnd_destination,
400                                                            DndDestinationFolderHandleMotionFn handle_motion,
401                                                            DndDestinationFolderHandleDropFn handle_drop,
402                                                            gpointer user_data,
403                                                            GNOME_Evolution_ShellComponentDnd_DestinationFolder corba_object)
404{
405        DndDestinationFolderPrivate *priv;
406
407        g_return_if_fail (dnd_destination != NULL);
408        g_return_if_fail (IS_EVOLUTION_SHELL_COMPONENT_DND_DESTINATION_FOLDER (dnd_destination));
409        g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
410
411        priv = dnd_destination->priv;
412
413        priv->handle_motion = handle_motion;
414        priv->handle_drop = handle_drop;
415        priv->user_data = user_data;
416
417        bonobo_object_construct (BONOBO_OBJECT (dnd_destination), corba_object);
418}
419
420EvolutionShellComponentDndDestinationFolder*
421evolution_shell_component_dnd_destination_folder_new (DndDestinationFolderHandleMotionFn handle_motion,
422                                                      DndDestinationFolderHandleDropFn handle_drop,
423                                                      gpointer user_data)
424{
425        EvolutionShellComponentDndDestinationFolder *dnd_destination;
426        POA_GNOME_Evolution_ShellComponentDnd_DestinationFolder *servant;
427        GNOME_Evolution_ShellComponentDnd_DestinationFolder corba_object;
428
429        g_return_val_if_fail (handle_motion != NULL, NULL);
430        g_return_val_if_fail (handle_drop != NULL, NULL);
431
432        servant = create_dnd_destination_servant();
433        if (servant == NULL)
434                return NULL;
435
436        dnd_destination = gtk_type_new (evolution_shell_component_dnd_destination_folder_get_type ());
437        corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (dnd_destination),
438                                                       servant);
439
440        evolution_shell_component_dnd_destination_folder_construct (dnd_destination,
441                                                                    handle_motion, handle_drop,
442                                                                    user_data,
443                                                                    corba_object);
444        return dnd_destination;
445}
446
Note: See TracBrowser for help on using the repository browser.