Code

Get rid of the SP_DT_* macros which do nothing more than provide additional, confusin...
[inkscape.git] / src / ui / view / view-widget.cpp
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     
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     }
45     
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);
57     
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     }
87 }
89 /**
90  * Connects widget to view's 'resized' signal and calls virtual set_view()
91  * function.
92  */
93 void sp_view_widget_set_view(SPViewWidget *vw, Inkscape::UI::View::View *view)
94 {
95     g_return_if_fail(vw != NULL);
96     g_return_if_fail(SP_IS_VIEW_WIDGET(vw));
97     g_return_if_fail(view != NULL);
98     
99     g_return_if_fail(vw->view == NULL);
100     
101     vw->view = view;
102     Inkscape::GC::anchor(view);
104     if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view) {
105         ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->set_view(vw, view);
106     }
109 /**
110  * Calls the virtual shutdown() function of the SPViewWidget.
111  */
112 bool sp_view_widget_shutdown(SPViewWidget *vw)
114     g_return_val_if_fail(vw != NULL, TRUE);
115     g_return_val_if_fail(SP_IS_VIEW_WIDGET(vw), TRUE);
117     if (((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown) {
118         return ((SPViewWidgetClass *) G_OBJECT_GET_CLASS(vw))->shutdown(vw);
119     }
121     return FALSE;
126 /*
127   Local Variables:
128   mode:c++
129   c-file-style:"stroustrup"
130   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131   indent-tabs-mode:nil
132   fill-column:99
133   End:
134 */
135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :