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;
34 if (!type) {
35 GtkTypeInfo info = {
36 "SPViewWidget",
37 sizeof(SPViewWidget),
38 sizeof(SPViewWidgetClass),
39 (GtkClassInitFunc) sp_view_widget_class_init,
40 (GtkObjectInitFunc) sp_view_widget_init,
41 NULL, NULL, NULL
42 };
43 type = gtk_type_unique(GTK_TYPE_EVENT_BOX, &info);
44 }
46 return type;
47 }
49 /**
50 * Callback to initialize the SPViewWidget vtable.
51 */
52 static void sp_view_widget_class_init(SPViewWidgetClass *vwc)
53 {
54 GtkObjectClass *object_class = GTK_OBJECT_CLASS(vwc);
56 widget_parent_class = (GtkEventBoxClass*) gtk_type_class(GTK_TYPE_EVENT_BOX);
58 object_class->destroy = sp_view_widget_destroy;
59 }
61 /**
62 * Callback to initialize the SPViewWidget.
63 */
64 static void sp_view_widget_init(SPViewWidget *vw)
65 {
66 vw->view = NULL;
67 }
69 /**
70 * Callback to disconnect from view and destroy SPViewWidget.
71 *
72 * Apparently, this gets only called when a desktop is closed, but then twice!
73 */
74 static void sp_view_widget_destroy(GtkObject *object)
75 {
76 SPViewWidget *vw = SP_VIEW_WIDGET(object);
78 if (vw->view) {
79 vw->view->close();
80 Inkscape::GC::release(vw->view);
81 vw->view = NULL;
82 }
84 if (((GtkObjectClass *) (widget_parent_class))->destroy) {
85 (* ((GtkObjectClass *) (widget_parent_class))->destroy)(object);
86 }
88 Inkscape::GC::request_early_collection();
89 }
91 /**
92 * Connects widget to view's 'resized' signal and calls virtual set_view()
93 * function.
94 */
95 void sp_view_widget_set_view(SPViewWidget *vw, Inkscape::UI::View::View *view)
96 {
97 g_return_if_fail(vw != NULL);
98 g_return_if_fail(SP_IS_VIEW_WIDGET(vw));
99 g_return_if_fail(view != NULL);
101 g_return_if_fail(vw->view == NULL);
103 vw->view = view;
104 Inkscape::GC::anchor(view);
106 if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view) {
107 ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view(vw, view);
108 }
109 }
111 /**
112 * Calls the virtual shutdown() function of the SPViewWidget.
113 */
114 bool sp_view_widget_shutdown(SPViewWidget *vw)
115 {
116 g_return_val_if_fail(vw != NULL, TRUE);
117 g_return_val_if_fail(SP_IS_VIEW_WIDGET(vw), TRUE);
119 if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown) {
120 return ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown(vw);
121 }
123 return FALSE;
124 }
128 /*
129 Local Variables:
130 mode:c++
131 c-file-style:"stroustrup"
132 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
133 indent-tabs-mode:nil
134 fill-column:99
135 End:
136 */
137 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :