1 /** \file
2 * SPViewWidget implementation.
3 *
4 * Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * Ralf Stephan <ralf@ark.in-berlin.de>
7 *
8 * Copyright (C) 2001-2002 Lauris Kaplinski
9 * Copyright (C) 2001 Ximian, Inc.
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #include "view.h"
15 #include "view-widget.h"
17 //using namespace Inkscape::UI::View;
19 /* SPViewWidget */
21 static void sp_view_widget_class_init(SPViewWidgetClass *vwc);
22 static void sp_view_widget_init(SPViewWidget *widget);
23 static void sp_view_widget_destroy(GtkObject *object);
25 static GtkEventBoxClass *widget_parent_class;
27 /**
28 * Registers the SPViewWidget class with Glib and returns its type number.
29 */
30 GtkType sp_view_widget_get_type(void)
31 {
32 static GtkType type = 0;
33 //TODO: switch to GObject
34 // GtkType and such calls were deprecated a while back with the
35 // introduction of GObject as a separate layer, with GType instead. --JonCruz
36 if (!type) {
37 GtkTypeInfo info = {
38 (gchar*) "SPViewWidget",
39 sizeof(SPViewWidget),
40 sizeof(SPViewWidgetClass),
41 (GtkClassInitFunc) sp_view_widget_class_init,
42 (GtkObjectInitFunc) sp_view_widget_init,
43 NULL, NULL, NULL
44 };
45 type = gtk_type_unique(GTK_TYPE_EVENT_BOX, &info);
46 }
48 return type;
49 }
51 /**
52 * Callback to initialize the SPViewWidget vtable.
53 */
54 static void sp_view_widget_class_init(SPViewWidgetClass *vwc)
55 {
56 GtkObjectClass *object_class = GTK_OBJECT_CLASS(vwc);
58 widget_parent_class = (GtkEventBoxClass*) gtk_type_class(GTK_TYPE_EVENT_BOX);
60 object_class->destroy = sp_view_widget_destroy;
61 }
63 /**
64 * Callback to initialize the SPViewWidget.
65 */
66 static void sp_view_widget_init(SPViewWidget *vw)
67 {
68 vw->view = NULL;
69 }
71 /**
72 * Callback to disconnect from view and destroy SPViewWidget.
73 *
74 * Apparently, this gets only called when a desktop is closed, but then twice!
75 */
76 static void sp_view_widget_destroy(GtkObject *object)
77 {
78 SPViewWidget *vw = SP_VIEW_WIDGET(object);
80 if (vw->view) {
81 vw->view->close();
82 Inkscape::GC::release(vw->view);
83 vw->view = NULL;
84 }
86 if (((GtkObjectClass *) (widget_parent_class))->destroy) {
87 (* ((GtkObjectClass *) (widget_parent_class))->destroy)(object);
88 }
90 Inkscape::GC::request_early_collection();
91 }
93 /**
94 * Connects widget to view's 'resized' signal and calls virtual set_view()
95 * function.
96 */
97 void sp_view_widget_set_view(SPViewWidget *vw, Inkscape::UI::View::View *view)
98 {
99 g_return_if_fail(vw != NULL);
100 g_return_if_fail(SP_IS_VIEW_WIDGET(vw));
101 g_return_if_fail(view != NULL);
103 g_return_if_fail(vw->view == NULL);
105 vw->view = view;
106 Inkscape::GC::anchor(view);
108 if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view) {
109 ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view(vw, view);
110 }
111 }
113 /**
114 * Calls the virtual shutdown() function of the SPViewWidget.
115 */
116 bool sp_view_widget_shutdown(SPViewWidget *vw)
117 {
118 g_return_val_if_fail(vw != NULL, TRUE);
119 g_return_val_if_fail(SP_IS_VIEW_WIDGET(vw), TRUE);
121 if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown) {
122 return ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown(vw);
123 }
125 return FALSE;
126 }
130 /*
131 Local Variables:
132 mode:c++
133 c-file-style:"stroustrup"
134 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
135 indent-tabs-mode:nil
136 fill-column:99
137 End:
138 */
139 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :