index ab440595f24e0e6a06c12e934cb8aa2e3698c4fa..4620b15328e0137603f11dcf50078cf0426513a5 100644 (file)
-#define __SP_DESKTOP_WIDGET_C__
-
/** \file
* Desktop widget implementation
*/
/** \file
* Desktop widget implementation
*/
* Ralf Stephan <ralf@ark.in-berlin.de>
* John Bintz <jcoswell@coswellproductions.org>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Ralf Stephan <ralf@ark.in-berlin.de>
* John Bintz <jcoswell@coswellproductions.org>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2006 John Bintz
*
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2006 John Bintz
#include <extension/db.h>
#include "file.h"
#include "helper/units.h"
#include <extension/db.h>
#include "file.h"
#include "helper/units.h"
+#include "helper/unit-tracker.h"
#include "inkscape-private.h"
#include "interface.h"
#include "macros.h"
#include "inkscape-private.h"
#include "interface.h"
#include "macros.h"
#include "ui/widget/layer-selector.h"
#include "ui/widget/selected-style.h"
#include "ui/uxmanager.h"
#include "ui/widget/layer-selector.h"
#include "ui/widget/selected-style.h"
#include "ui/uxmanager.h"
+#include "util/ege-appear-time-tracker.h"
// We're in the "widgets" directory, so no need to explicitly prefix these:
#include "button.h"
// We're in the "widgets" directory, so no need to explicitly prefix these:
#include "button.h"
using Inkscape::round;
#endif
using Inkscape::round;
#endif
-
+using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::UXManager;
using Inkscape::UI::ToolboxFactory;
+using ege::AppearTimeTracker;
#ifdef WITH_INKBOARD
#endif
#ifdef WITH_INKBOARD
#endif
SPViewWidgetClass *dtw_parent_class;
SPViewWidgetClass *dtw_parent_class;
+static GTimer *baseTimer = 0;
+static bool timeReported = false;
+
+static void timeGoing(gchar const* id)
+{
+ if ( !baseTimer ) {
+ g_message("Starting time at point [%s]", id);
+ baseTimer = g_timer_new();
+ }
+}
+
+static void checkTime(gchar const* msg)
+{
+ if ( baseTimer && !timeReported ) {
+ timeReported = true;
+ g_timer_stop(baseTimer);
+ gulong msCount = 0;
+ gdouble secs = g_timer_elapsed( baseTimer, &msCount );
+ g_message("Time ended at %2.3f with [%s]", secs, msg);
+ }
+}
+
+
+
class CMSPrefWatcher {
public:
CMSPrefWatcher() :
class CMSPrefWatcher {
public:
CMSPrefWatcher() :
return Geom::Point(x,y);
}
return Geom::Point(x,y);
}
+static GTimer *overallTimer = 0;
+
/**
* Registers SPDesktopWidget class and returns its type number.
*/
/**
* Registers SPDesktopWidget class and returns its type number.
*/
{
static GtkType type = 0;
if (!type) {
{
static GtkType type = 0;
if (!type) {
+ timeGoing("SPDesktopWidget::getType");
GTypeInfo info = {
sizeof(SPDesktopWidgetClass),
0, // base_init
GTypeInfo info = {
sizeof(SPDesktopWidgetClass),
0, // base_init
0 // value_table
};
type = g_type_register_static(SP_TYPE_VIEW_WIDGET, "SPDesktopWidget", &info, static_cast<GTypeFlags>(0));
0 // value_table
};
type = g_type_register_static(SP_TYPE_VIEW_WIDGET, "SPDesktopWidget", &info, static_cast<GTypeFlags>(0));
+ // Begin a timer to watch for the first desktop to appear on-screen
+ overallTimer = g_timer_new();
}
return type;
}
}
return type;
}
static void
sp_desktop_widget_class_init (SPDesktopWidgetClass *klass)
{
static void
sp_desktop_widget_class_init (SPDesktopWidgetClass *klass)
{
+ timeGoing("sp_desktop_widget_class_init");
dtw_parent_class = (SPViewWidgetClass*)gtk_type_class (SP_TYPE_VIEW_WIDGET);
GtkObjectClass *object_class = (GtkObjectClass *) klass;
dtw_parent_class = (SPViewWidgetClass*)gtk_type_class (SP_TYPE_VIEW_WIDGET);
GtkObjectClass *object_class = (GtkObjectClass *) klass;
*/
void SPDesktopWidget::init( SPDesktopWidget *dtw )
{
*/
void SPDesktopWidget::init( SPDesktopWidget *dtw )
{
+ timeGoing("SPDesktopWidget::init");
GtkWidget *widget;
GtkWidget *tbl;
GtkWidget *canvas_tbl;
GtkWidget *widget;
GtkWidget *tbl;
GtkWidget *canvas_tbl;
dtw->hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end( GTK_BOX (dtw->vbox), dtw->hbox, TRUE, TRUE, 0 );
gtk_widget_show(dtw->hbox);
dtw->hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end( GTK_BOX (dtw->vbox), dtw->hbox, TRUE, TRUE, 0 );
gtk_widget_show(dtw->hbox);
-
+
dtw->aux_toolbox = ToolboxFactory::createAuxToolbox();
gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->aux_toolbox, FALSE, TRUE, 0);
dtw->aux_toolbox = ToolboxFactory::createAuxToolbox();
gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->aux_toolbox, FALSE, TRUE, 0);
gtk_widget_show_all (dtw->vbox);
gtk_widget_grab_focus (GTK_WIDGET(dtw->canvas));
gtk_widget_show_all (dtw->vbox);
gtk_widget_grab_focus (GTK_WIDGET(dtw->canvas));
+
+ // If this is the first desktop created, report the time it takes to show up
+ if ( overallTimer ) {
+ if ( prefs->getBool("/dialogs/debug/trackAppear", false) ) {
+ // Time tracker takes ownership of the timer.
+ AppearTimeTracker *tracker = new AppearTimeTracker(overallTimer, GTK_WIDGET(dtw), "first SPDesktopWidget");
+ tracker->setAutodelete(true);
+ } else {
+ g_timer_destroy(overallTimer);
+ }
+ overallTimer = 0;
+ }
}
/**
}
/**
NRRect d;
d.x0 = 0.0;
d.y0 = 0.0;
NRRect d;
d.x0 = 0.0;
d.y0 = 0.0;
- d.x1 = sp_document_width (dtw->desktop->doc());
- d.y1 = sp_document_height (dtw->desktop->doc());
+ d.x1 = (dtw->desktop->doc())->getWidth ();
+ d.y1 = (dtw->desktop->doc())->getHeight ();
if ((fabs (d.x1 - d.x0) < 1.0) || (fabs (d.y1 - d.y0) < 1.0)) return;
if ((fabs (d.x1 - d.x0) < 1.0) || (fabs (d.y1 - d.y0) < 1.0)) return;
modified_connection = desktop->namedview->connectModified(sigc::mem_fun(*this, &SPDesktopWidget::namedviewModified));
namedviewModified(desktop->namedview, SP_OBJECT_MODIFIED_FLAG);
modified_connection = desktop->namedview->connectModified(sigc::mem_fun(*this, &SPDesktopWidget::namedviewModified));
namedviewModified(desktop->namedview, SP_OBJECT_MODIFIED_FLAG);
- updateTitle(SP_DOCUMENT_NAME (desktop->doc()));
+ updateTitle( desktop->doc()->getName() );
}
/**
}
/**
GTK_BUTTONS_NONE,
_("<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
"If you close without saving, your changes will be discarded."),
GTK_BUTTONS_NONE,
_("<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
"If you close without saving, your changes will be discarded."),
- SP_DOCUMENT_NAME(doc));
+ doc->getName());
// fix for bug 1767940:
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
// fix for bug 1767940:
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
{
Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
{
Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
- sp_document_ref(doc);
+ doc->doRef();
sp_namedview_document_from_window(desktop);
if (sp_file_save_document(*window, doc)) {
sp_namedview_document_from_window(desktop);
if (sp_file_save_document(*window, doc)) {
- sp_document_unref(doc);
+ doc->doUnref();
} else { // save dialog cancelled or save failed
} else { // save dialog cancelled or save failed
- sp_document_unref(doc);
+ doc->doUnref();
return TRUE;
}
return TRUE;
}
}
/* Code to check data loss */
bool allow_data_loss = FALSE;
}
/* Code to check data loss */
bool allow_data_loss = FALSE;
- while (sp_document_repr_root(doc)->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
+ while (doc->getReprRoot()->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
GtkWidget *dialog;
/** \todo
GtkWidget *dialog;
/** \todo
GTK_BUTTONS_NONE,
_("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\n\n"
"Do you want to save this file as Inkscape SVG?"),
GTK_BUTTONS_NONE,
_("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\n\n"
"Do you want to save this file as Inkscape SVG?"),
- SP_DOCUMENT_NAME(doc)? SP_DOCUMENT_NAME(doc) : "Unnamed",
+ doc->getName() ? doc->getName() : "Unnamed",
SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE);
// fix for bug 1767940:
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE);
// fix for bug 1767940:
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
switch (response) {
case GTK_RESPONSE_YES:
{
switch (response) {
case GTK_RESPONSE_YES:
{
- sp_document_ref(doc);
+ doc->doRef();
Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
if (sp_file_save_dialog(*window, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG)) {
Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
if (sp_file_save_dialog(*window, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG)) {
- sp_document_unref(doc);
+ doc->doUnref();
} else { // save dialog cancelled or save failed
} else { // save dialog cancelled or save failed
- sp_document_unref(doc);
+ doc->doUnref();
return TRUE;
}
return TRUE;
}
{
SPDesktopWidget* dtw = SPDesktopWidget::createInstance(namedview);
{
SPDesktopWidget* dtw = SPDesktopWidget::createInstance(namedview);
- UXManager::getInstance()->addTrack(dtw);
-
return SP_VIEW_WIDGET(dtw);
}
return SP_VIEW_WIDGET(dtw);
}
toolboxes.push_back(dtw->aux_toolbox);
toolboxes.push_back(dtw->commands_toolbox);
toolboxes.push_back(dtw->snap_toolbox);
toolboxes.push_back(dtw->aux_toolbox);
toolboxes.push_back(dtw->commands_toolbox);
toolboxes.push_back(dtw->snap_toolbox);
- UXManager::getInstance()->connectToDesktop( toolboxes, dtw->desktop );
dtw->panels->setDesktop( dtw->desktop );
dtw->panels->setDesktop( dtw->desktop );
+ UXManager::getInstance()->addTrack(dtw);
+ UXManager::getInstance()->connectToDesktop( toolboxes, dtw->desktop );
+
return dtw;
}
return dtw;
}
sp_ruler_set_metric(GTK_RULER (this->vruler), nv->getDefaultMetric());
sp_ruler_set_metric(GTK_RULER (this->hruler), nv->getDefaultMetric());
sp_ruler_set_metric(GTK_RULER (this->vruler), nv->getDefaultMetric());
sp_ruler_set_metric(GTK_RULER (this->hruler), nv->getDefaultMetric());
+ /* This loops through all the grandchildren of aux toolbox,
+ * and for each that it finds, it performs an sp_search_by_data_recursive(),
+ * looking for widgets that hold some "tracker" data (this is used by
+ * all toolboxes to refer to the unit selector). The default document units
+ * is then selected within these unit selectors.
+ *
+ * Of course it would be nice to be able to refer to the toolbox and the
+ * unit selector directly by name, but I don't yet see a way to do that.
+ *
+ * This should solve: https://bugs.launchpad.net/inkscape/+bug/362995
+ */
+ if (GTK_IS_CONTAINER(aux_toolbox)) {
+ GList *ch = gtk_container_get_children (GTK_CONTAINER(aux_toolbox));
+ for (GList *i = ch; i != NULL; i = i->next) {
+ if (GTK_IS_CONTAINER(i->data)) {
+ GList *grch = gtk_container_get_children (GTK_CONTAINER(i->data));
+ for (GList *j = grch; j != NULL; j = j->next) {
+ if (!GTK_IS_WIDGET(j->data)) // wasn't a widget
+ continue;
+
+ gpointer t = sp_search_by_data_recursive(GTK_WIDGET(j->data), (gpointer) "tracker");
+ if (t == NULL) // didn't find any tracker data
+ continue;
+
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>( t );
+ if (tracker == NULL) // it's null when inkscape is first opened
+ continue;
+
+ tracker->setActiveUnit( nv->doc_units );
+ } // grandchildren
+ } // if child is a container
+ } // children
+ } // if aux_toolbox is a container
+
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);
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);
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/options/bitmapautoreload/value", true)) {
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/options/bitmapautoreload/value", true)) {
- GSList const *imageList = sp_document_get_resource_list(desktop->doc(), "image");
+ GSList const *imageList = (desktop->doc())->getResourceList("image");
for (GSList const *p = imageList; p; p = p->next) {
SPImage* image = SP_IMAGE(p->data);
sp_image_refresh_if_outdated( image );
for (GSList const *p = imageList; p; p = p->next) {
SPImage* image = SP_IMAGE(p->data);
sp_image_refresh_if_outdated( image );
/* The desktop region we always show unconditionally */
SPDocument *doc = dtw->desktop->doc();
/* The desktop region we always show unconditionally */
SPDocument *doc = dtw->desktop->doc();
- Geom::Rect darea ( Geom::Point(-sp_document_width(doc), -sp_document_height(doc)),
- Geom::Point(2 * sp_document_width(doc), 2 * sp_document_height(doc)) );
+ Geom::Rect darea ( Geom::Point(-doc->getWidth(), -doc->getHeight()),
+ Geom::Point(2 * doc->getWidth(), 2 * doc->getHeight()) );
SPObject* root = doc->root;
SPItem* item = SP_ITEM(root);
SPObject* root = doc->root;
SPItem* item = SP_ITEM(root);
- Geom::OptRect deskarea = Geom::unify(darea, sp_item_bbox_desktop(item));
+ Geom::OptRect deskarea = Geom::unify(darea, item->getBboxDesktop());
/* Canvas region we always show unconditionally */
Geom::Rect carea( Geom::Point(deskarea->min()[Geom::X] * scale - 64, deskarea->max()[Geom::Y] * -scale - 64),
/* Canvas region we always show unconditionally */
Geom::Rect carea( Geom::Point(deskarea->min()[Geom::X] * scale - 64, deskarea->max()[Geom::Y] * -scale - 64),