From: Jon A. Cruz Date: Fri, 8 Jan 2010 09:16:41 +0000 (-0800) Subject: C++-ification pass. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=14436564bb2e08caedc3899e7be87c3abaea21c5;p=inkscape.git C++-ification pass. --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 0e4d4caf3..70f7c4b15 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -605,8 +605,10 @@ SPDesktop::change_document (SPDocument *theDocument) Gtk::Window *parent = this->getToplevel(); g_assert(parent != NULL); SPDesktopWidget *dtw = (SPDesktopWidget *) parent->get_data("desktopwidget"); - if (dtw) dtw->desktop = this; - sp_desktop_widget_update_namedview(dtw); + if (dtw) { + dtw->desktop = this; + } + dtw->updateNamedview(); _namedview_modified (namedview, SP_OBJECT_MODIFIED_FLAG, this); _document_replaced_signal.emit (this, theDocument); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 6c330b5f3..babb5b5b6 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -48,7 +48,6 @@ #include "sp-image.h" #include "sp-item.h" #include "sp-namedview.h" -#include "toolbox.h" #include "ui/dialog/dialog-manager.h" #include "ui/dialog/swatches.h" #include "ui/icon-names.h" @@ -56,12 +55,14 @@ #include "ui/widget/layer-selector.h" #include "ui/widget/selected-style.h" #include "ui/uxmanager.h" -#include "widgets/button.h" -#include "widgets/ruler.h" -#include "widgets/spinbutton-events.h" -#include "widgets/spw-utilities.h" -#include "widgets/toolbox.h" -#include "widgets/widget-sizes.h" + +// We're in the "widgets" directory, so no need to explicitly prefix these: +#include "button.h" +#include "ruler.h" +#include "spinbutton-events.h" +#include "spw-utilities.h" +#include "toolbox.h" +#include "widget-sizes.h" #if defined (SOLARIS) && (SOLARIS == 8) #include "round.h" @@ -90,7 +91,6 @@ enum { /* SPDesktopWidget */ static void sp_desktop_widget_class_init (SPDesktopWidgetClass *klass); -static void sp_desktop_widget_init (SPDesktopWidget *widget); static void sp_desktop_widget_destroy (GtkObject *object); static void sp_desktop_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation); @@ -102,7 +102,6 @@ static void sp_dtw_color_profile_event(EgeColorProfTracker *widget, SPDesktopWid static void cms_adjust_toggled( GtkWidget *button, gpointer data ); static void cms_adjust_set_sensitive( SPDesktopWidget *dtw, bool enabled ); static void sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget *dtw); -static void sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw); static gdouble sp_dtw_zoom_value_to_display (gdouble value); static gdouble sp_dtw_zoom_display_to_value (gdouble value); @@ -246,7 +245,7 @@ SPDesktopWidget::window_get_pointer() /** * Registers SPDesktopWidget class and returns its type number. */ -GType sp_desktop_widget_get_type(void) +GType SPDesktopWidget::getType(void) { static GtkType type = 0; if (!type) { @@ -259,7 +258,7 @@ GType sp_desktop_widget_get_type(void) 0, // class_data sizeof(SPDesktopWidget), 0, // n_preallocs - (GInstanceInitFunc)sp_desktop_widget_init, + (GInstanceInitFunc)SPDesktopWidget::init, 0 // value_table }; type = g_type_register_static(SP_TYPE_VIEW_WIDGET, "SPDesktopWidget", &info, static_cast(0)); @@ -287,8 +286,7 @@ sp_desktop_widget_class_init (SPDesktopWidgetClass *klass) /** * Callback for SPDesktopWidget object initialization. */ -static void -sp_desktop_widget_init (SPDesktopWidget *dtw) +void SPDesktopWidget::init( SPDesktopWidget *dtw ) { GtkWidget *widget; GtkWidget *tbl; @@ -712,23 +710,22 @@ sp_desktop_widget_realize (GtkWidget *widget) dtw->desktop->set_display_area (d.x0, d.y0, d.x1, d.y1, 10); - sp_desktop_widget_update_namedview(dtw); + dtw->updateNamedview(); } /* This is just to provide access to common functionality from sp_desktop_widget_realize() above as well as from SPDesktop::change_document() */ -void -sp_desktop_widget_update_namedview (SPDesktopWidget *dtw) { - g_return_if_fail(dtw); - - /* Listen on namedview modification */ +void SPDesktopWidget::updateNamedview() +{ + // Listen on namedview modification // originally (prior to the sigc++ conversion) the signal was simply // connected twice rather than disconnecting the first connection - dtw->modified_connection.disconnect(); - dtw->modified_connection = dtw->desktop->namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw)); - sp_desktop_widget_namedview_modified (dtw->desktop->namedview, SP_OBJECT_MODIFIED_FLAG, dtw); + modified_connection.disconnect(); + + modified_connection = desktop->namedview->connectModified(sigc::mem_fun(*this, &SPDesktopWidget::namedviewModified)); + namedviewModified(desktop->namedview, SP_OBJECT_MODIFIED_FLAG); - dtw->updateTitle(SP_DOCUMENT_NAME (dtw->desktop->doc())); + updateTitle(SP_DOCUMENT_NAME (desktop->doc())); } /** @@ -1204,18 +1201,18 @@ sp_desktop_widget_fullscreen(SPDesktopWidget *dtw) /** * Hide whatever the user does not want to see in the window */ -void -sp_desktop_widget_layout (SPDesktopWidget *dtw) +void SPDesktopWidget::layoutWidgets() { + SPDesktopWidget *dtw = this; Glib::ustring pref_root; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (dtw->desktop->is_focusMode()) { - pref_root = "/focus/"; + pref_root = "/focus/"; } else if (dtw->desktop->is_fullscreen()) { - pref_root = "/fullscreen/"; + pref_root = "/fullscreen/"; } else { - pref_root = "/window/"; + pref_root = "/window/"; } #ifndef GDK_WINDOWING_QUARTZ @@ -1233,10 +1230,10 @@ sp_desktop_widget_layout (SPDesktopWidget *dtw) } if (!prefs->getBool(pref_root + "snaptoolbox/state", true)) { - gtk_widget_hide_all (dtw->snap_toolbox); - } else { - gtk_widget_show_all (dtw->snap_toolbox); - } + gtk_widget_hide_all (dtw->snap_toolbox); + } else { + gtk_widget_show_all (dtw->snap_toolbox); + } if (!prefs->getBool(pref_root + "toppanel/state", true)) { gtk_widget_hide_all (dtw->aux_toolbox); @@ -1341,8 +1338,12 @@ SPDesktopWidget::isToolboxButtonActive (const gchar* id) return isActive; } -SPViewWidget * -sp_desktop_widget_new (SPNamedView *namedview) +SPViewWidget *sp_desktop_widget_new( SPNamedView *namedview ) +{ + return SP_VIEW_WIDGET(SPDesktopWidget::createInstance(namedview)); +} + +SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = (SPDesktopWidget*)g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL); @@ -1367,7 +1368,7 @@ sp_desktop_widget_new (SPNamedView *namedview) sp_view_widget_set_view (SP_VIEW_WIDGET (dtw), dtw->desktop); /* Listen on namedview modification */ - dtw->modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw)); + dtw->modified_connection = namedview->connectModified(sigc::mem_fun(*dtw, &SPDesktopWidget::namedviewModified)); dtw->layer_selector->setDesktop(dtw->desktop); @@ -1377,7 +1378,7 @@ sp_desktop_widget_new (SPNamedView *namedview) gtk_box_pack_start (GTK_BOX (dtw->vbox), dtw->menubar, FALSE, FALSE, 0); #endif - sp_desktop_widget_layout (dtw); + dtw->layoutWidgets(); std::vector toolboxes; toolboxes.push_back(dtw->tool_toolbox); @@ -1388,7 +1389,7 @@ sp_desktop_widget_new (SPNamedView *namedview) dtw->panels->setDesktop( dtw->desktop ); - return SP_VIEW_WIDGET (dtw); + return dtw; } void @@ -1443,22 +1444,22 @@ sp_desktop_widget_update_vruler (SPDesktopWidget *dtw) } -static void -sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw) +void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) { SPNamedView *nv=SP_NAMEDVIEW(obj); + if (flags & SP_OBJECT_MODIFIED_FLAG) { - dtw->dt2r = 1.0 / nv->doc_units->unittobase; - dtw->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? + this->dt2r = 1.0 / nv->doc_units->unittobase; + this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? - sp_ruler_set_metric (GTK_RULER (dtw->vruler), nv->getDefaultMetric()); - sp_ruler_set_metric (GTK_RULER (dtw->hruler), nv->getDefaultMetric()); + sp_ruler_set_metric(GTK_RULER (this->vruler), nv->getDefaultMetric()); + sp_ruler_set_metric(GTK_RULER (this->hruler), nv->getDefaultMetric()); - gtk_tooltips_set_tip (dtw->tt, dtw->hruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL); - gtk_tooltips_set_tip (dtw->tt, dtw->vruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL); + gtk_tooltips_set_tip(this->tt, this->hruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL); + gtk_tooltips_set_tip(this->tt, this->vruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL); - sp_desktop_widget_update_rulers (dtw); - update_snap_toolbox(dtw->desktop, NULL, dtw->snap_toolbox); + sp_desktop_widget_update_rulers(this); + update_snap_toolbox(this->desktop, NULL, this->snap_toolbox); } } diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h index 04146cac6..c9bedb1ab 100644 --- a/src/widgets/desktop-widget.h +++ b/src/widgets/desktop-widget.h @@ -5,6 +5,7 @@ * SPDesktopWidget: handling Gtk events on a desktop. * * Authors: + * Jon A. Cruz (c) 2010 * John Bintz (c) 2006 * Ralf Stephan (c) 2005, distrib. under GPL2 * ? -2004 @@ -26,28 +27,23 @@ typedef struct _EgeColorProfTracker EgeColorProfTracker; -#define SP_TYPE_DESKTOP_WIDGET (sp_desktop_widget_get_type ()) +#define SP_TYPE_DESKTOP_WIDGET SPDesktopWidget::getType() #define SP_DESKTOP_WIDGET(o) (GTK_CHECK_CAST ((o), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidget)) #define SP_DESKTOP_WIDGET_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidgetClass)) #define SP_IS_DESKTOP_WIDGET(o) (GTK_CHECK_TYPE ((o), SP_TYPE_DESKTOP_WIDGET)) #define SP_IS_DESKTOP_WIDGET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), SP_TYPE_DESKTOP_WIDGET)) -GtkType sp_desktop_widget_get_type(); - void sp_desktop_widget_destroy (SPDesktopWidget* dtw); void sp_desktop_widget_show_decorations(SPDesktopWidget *dtw, gboolean show); void sp_desktop_widget_iconify(SPDesktopWidget *dtw); void sp_desktop_widget_maximize(SPDesktopWidget *dtw); void sp_desktop_widget_fullscreen(SPDesktopWidget *dtw); -void sp_desktop_widget_layout(SPDesktopWidget *dtw); void sp_desktop_widget_update_zoom(SPDesktopWidget *dtw); void sp_desktop_widget_update_rulers (SPDesktopWidget *dtw); void sp_desktop_widget_update_hruler (SPDesktopWidget *dtw); void sp_desktop_widget_update_vruler (SPDesktopWidget *dtw); -void sp_desktop_widget_update_namedview (SPDesktopWidget *dtw); - /* Show/hide rulers & scrollbars */ void sp_desktop_widget_toggle_rulers (SPDesktopWidget *dtw); void sp_desktop_widget_toggle_scrollbars (SPDesktopWidget *dtw); @@ -86,8 +82,6 @@ struct SPDesktopWidget { GtkWidget *hscrollbar, *vscrollbar, *vscrollbar_box; - GtkWidget *tool_toolbox, *aux_toolbox, *commands_toolbox, *snap_toolbox; - /* Rulers */ GtkWidget *hruler, *vruler; GtkWidget *hruler_box, *vruler_box; // eventboxes for setting tooltips @@ -129,8 +123,11 @@ struct SPDesktopWidget { { _dtw->updateTitle (uri); } virtual Gtk::Window* getWindow() { return _dtw->window; } - virtual void layout() - { sp_desktop_widget_layout (_dtw); } + + virtual void layout() { + _dtw->layoutWidgets(); + } + virtual void present() { _dtw->presentWindow(); } virtual void getGeometry (gint &x, gint &y, gint &w, gint &h) @@ -231,6 +228,22 @@ struct SPDesktopWidget { Inkscape::UI::Widget::Dock* getDock(); + static GtkType getType(); + static SPDesktopWidget* createInstance(SPNamedView *namedview); + + void updateNamedview(); + +private: + GtkWidget *tool_toolbox; + GtkWidget *aux_toolbox; + GtkWidget *commands_toolbox,; + GtkWidget *snap_toolbox; + + static void init(SPDesktopWidget *widget); + void layoutWidgets(); + + void namedviewModified(SPObject *obj, guint flags); + }; /// The SPDesktopWidget vtable