4
* Interface to main application
7
* Lauris Kaplinski <lauris@kaplinski.com>
8
* bulia byak <buliabyak@users.sf.net>
10
* Copyright (C) 1999-2005 authors
11
* g++ port Copyright (C) 2003 Nathan Hurst
13
* Released under GNU GPL, read the file 'COPYING' for more information
21
#include "debug/simple-event.h"
22
#include "debug/event-tracker.h"
25
# define HAS_PROC_SELF_EXE //to get path of executable
28
// For now to get at is_os_wide().
29
# include "extension/internal/win32.h"
30
using Inkscape::Extension::Internal::PrintWin32;
32
#define _WIN32_IE 0x0400
33
//#define HAS_SHGetSpecialFolderPath
34
#define HAS_SHGetSpecialFolderLocation
35
#define HAS_GetModuleFileName
41
#include <gtk/gtkmain.h>
42
#include <gtk/gtkmessagedialog.h>
44
#include <glibmm/i18n.h>
45
#include "helper/sp-marshal.h"
46
#include "dialogs/debugdialog.h"
47
#include "application/application.h"
48
#include "application/editor.h"
49
#include "preferences.h"
54
#include "desktop-handles.h"
55
#include "selection.h"
56
#include "event-context.h"
57
#include "inkscape-private.h"
58
#include "prefs-utils.h"
62
#include "extension/init.h"
64
static Inkscape::Application *inkscape = NULL;
66
/* Backbones of configuration xml data */
67
#include "menus-skeleton.h"
70
MODIFY_SELECTION, // global: one of selections modified
71
CHANGE_SELECTION, // global: one of selections changed
72
CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
73
SET_SELECTION, // global: one of selections set
74
SET_EVENTCONTEXT, // tool switched
75
ACTIVATE_DESKTOP, // some desktop got focus
76
DEACTIVATE_DESKTOP, // some desktop lost focus
77
SHUTDOWN_SIGNAL, // inkscape is quitting
78
DIALOGS_HIDE, // user pressed F12
79
DIALOGS_UNHIDE, // user pressed F12
80
EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
81
// may not be reflected by a selection change and thus needs a separate signal
85
#define DESKTOP_IS_ACTIVE(d) ((d) == inkscape->desktops->data)
88
/*################################
89
# FORWARD DECLARATIONS
90
################################*/
92
gboolean inkscape_app_use_gui( Inkscape::Application const * app );
94
static void inkscape_class_init (Inkscape::ApplicationClass *klass);
95
static void inkscape_init (SPObject *object);
96
static void inkscape_dispose (GObject *object);
98
static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
99
static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
101
static bool inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
102
unsigned int skel_size,
103
const gchar *e_mkdir,
104
const gchar *e_notdir,
109
struct Inkscape::Application {
111
Inkscape::XML::Document *menus;
115
gboolean dialogs_toggle;
116
gboolean use_gui; // may want to consider a virtual function
117
// for overriding things like the warning dlg's
120
struct Inkscape::ApplicationClass {
121
GObjectClass object_class;
124
void (* change_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
125
void (* change_subselection) (Inkscape::Application * inkscape, SPDesktop *desktop);
126
void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
127
void (* set_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
128
void (* set_eventcontext) (Inkscape::Application * inkscape, SPEventContext * eventcontext);
129
void (* activate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
130
void (* deactivate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
131
void (* destroy_document) (Inkscape::Application *inkscape, SPDocument *doc);
132
void (* color_set) (Inkscape::Application *inkscape, SPColor *color, double opacity);
133
void (* shut_down) (Inkscape::Application *inkscape);
134
void (* dialogs_hide) (Inkscape::Application *inkscape);
135
void (* dialogs_unhide) (Inkscape::Application *inkscape);
136
void (* external_change) (Inkscape::Application *inkscape);
139
static GObjectClass * parent_class;
140
static guint inkscape_signals[LAST_SIGNAL] = {0};
142
static void (* segv_handler) (int) = NULL;
145
#define INKSCAPE_PROFILE_DIR "Inkscape"
147
#define INKSCAPE_PROFILE_DIR ".inkscape"
150
#define MENUS_FILE "menus.xml"
154
* Retrieves the GType for the Inkscape Application object.
157
inkscape_get_type (void)
159
static GType type = 0;
162
sizeof (Inkscape::ApplicationClass),
164
(GClassInitFunc) inkscape_class_init,
166
sizeof (Inkscape::Application),
168
(GInstanceInitFunc) inkscape_init,
171
type = g_type_register_static (G_TYPE_OBJECT, "Inkscape_Application", &info, (GTypeFlags)0);
178
* Initializes the inkscape class, registering all of its signal handlers
179
* and virtual functions
182
inkscape_class_init (Inkscape::ApplicationClass * klass)
184
GObjectClass * object_class;
186
object_class = (GObjectClass *) klass;
188
parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
190
inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection",
191
G_TYPE_FROM_CLASS (klass),
193
G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
195
sp_marshal_NONE__POINTER_UINT,
197
G_TYPE_POINTER, G_TYPE_UINT);
198
inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
199
G_TYPE_FROM_CLASS (klass),
201
G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
203
sp_marshal_NONE__POINTER,
206
inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
207
G_TYPE_FROM_CLASS (klass),
209
G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
211
sp_marshal_NONE__POINTER,
214
inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection",
215
G_TYPE_FROM_CLASS (klass),
217
G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
219
sp_marshal_NONE__POINTER,
222
inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
223
G_TYPE_FROM_CLASS (klass),
225
G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
227
sp_marshal_NONE__POINTER,
230
inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
231
G_TYPE_FROM_CLASS (klass),
233
G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
235
sp_marshal_NONE__POINTER,
238
inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
239
G_TYPE_FROM_CLASS (klass),
241
G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
243
sp_marshal_NONE__POINTER,
246
inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down",
247
G_TYPE_FROM_CLASS (klass),
249
G_STRUCT_OFFSET (Inkscape::ApplicationClass, shut_down),
251
g_cclosure_marshal_VOID__VOID,
253
inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide",
254
G_TYPE_FROM_CLASS (klass),
256
G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_hide),
258
g_cclosure_marshal_VOID__VOID,
260
inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide",
261
G_TYPE_FROM_CLASS (klass),
263
G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_unhide),
265
g_cclosure_marshal_VOID__VOID,
267
inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change",
268
G_TYPE_FROM_CLASS (klass),
270
G_STRUCT_OFFSET (Inkscape::ApplicationClass, external_change),
272
g_cclosure_marshal_VOID__VOID,
275
object_class->dispose = inkscape_dispose;
277
klass->activate_desktop = inkscape_activate_desktop_private;
278
klass->deactivate_desktop = inkscape_deactivate_desktop_private;
283
inkscape_init (SPObject * object)
286
inkscape = (Inkscape::Application *) object;
288
g_assert_not_reached ();
291
inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL);
293
inkscape->documents = NULL;
294
inkscape->desktops = NULL;
296
inkscape->dialogs_toggle = TRUE;
301
inkscape_dispose (GObject *object)
303
Inkscape::Application *inkscape = (Inkscape::Application *) object;
305
while (inkscape->documents) {
306
// we don't otherwise unref, so why here?
307
sp_document_unref((SPDocument *)inkscape->documents->data);
310
g_assert (!inkscape->desktops);
312
Inkscape::Preferences::save();
314
if (inkscape->menus) {
315
/* fixme: This is not the best place */
316
Inkscape::GC::release(inkscape->menus);
317
inkscape->menus = NULL;
320
G_OBJECT_CLASS (parent_class)->dispose (object);
330
g_object_ref (G_OBJECT (inkscape));
335
inkscape_unref (void)
338
g_object_unref (G_OBJECT (inkscape));
343
inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
345
desktop->set_active (true);
350
inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
352
desktop->set_active (false);
356
/* fixme: This is EVIL, and belongs to main after all */
362
inkscape_segv_handler (int signum)
364
using Inkscape::Debug::SimpleEvent;
365
using Inkscape::Debug::EventTracker;
366
using Inkscape::Debug::Logger;
368
static gint recursion = FALSE;
370
/* let any SIGABRTs seen from within this handler dump core */
371
signal(SIGABRT, SIG_DFL);
379
EventTracker<SimpleEvent<Inkscape::Debug::Event::CORE> > tracker("crash");
380
tracker.set<SimpleEvent<> >("emergency-save");
382
fprintf(stderr, "\nEmergency save activated!\n");
384
time_t sptime = time (NULL);
385
struct tm *sptm = localtime (&sptime);
387
strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
390
GSList *savednames = NULL;
391
GSList *failednames = NULL;
392
for (GSList *l = inkscape->documents; l != NULL; l = l->next) {
394
Inkscape::XML::Node *repr;
395
doc = (SPDocument *) l->data;
396
repr = sp_document_repr_root (doc);
397
if (repr->attribute("sodipodi:modified")) {
398
const gchar *docname, *d0, *d;
399
gchar n[64], c[1024];
402
/* originally, the document name was retrieved from
403
* the sodipod:docname attribute */
406
/* fixme: Quick hack to remove emergency file suffix */
407
d0 = strrchr ((char*)docname, '.');
408
if (d0 && (d0 > docname)) {
409
d0 = strrchr ((char*)(d0 - 1), '.');
410
if (d0 && (d0 > docname)) {
412
while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
414
memcpy (n, docname, MIN (d0 - docname - 1, 64));
422
if (!docname || !*docname) docname = "emergency";
423
// try saving to the profile location
424
g_snprintf (c, 1024, "%.256s.%s.%d", docname, sptstr, count);
425
gchar * location = homedir_path(c);
426
Inkscape::IO::dump_fopen_call(location, "E");
427
file = Inkscape::IO::fopen_utf8name(location, "w");
430
// try saving to /tmp
431
g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d", docname, sptstr, count);
432
Inkscape::IO::dump_fopen_call(c, "G");
433
file = Inkscape::IO::fopen_utf8name(c, "w");
436
// try saving to the current directory
437
g_snprintf (c, 1024, "inkscape-%.256s.%s.%d", docname, sptstr, count);
438
Inkscape::IO::dump_fopen_call(c, "F");
439
file = Inkscape::IO::fopen_utf8name(c, "w");
442
sp_repr_save_stream (sp_repr_document (repr), file, SP_SVG_NS_URI);
443
savednames = g_slist_prepend (savednames, g_strdup (c));
446
docname = repr->attribute("sodipodi:docname");
447
failednames = g_slist_prepend (failednames, (docname) ? g_strdup (docname) : g_strdup (_("Untitled document")));
453
savednames = g_slist_reverse (savednames);
454
failednames = g_slist_reverse (failednames);
456
fprintf (stderr, "\nEmergency save document locations:\n");
457
for (GSList *l = savednames; l != NULL; l = l->next) {
458
fprintf (stderr, " %s\n", (gchar *) l->data);
462
fprintf (stderr, "\nFailed to do emergency save for documents:\n");
463
for (GSList *l = failednames; l != NULL; l = l->next) {
464
fprintf (stderr, " %s\n", (gchar *) l->data);
468
Inkscape::Preferences::save();
470
fprintf (stderr, "Emergency save completed. Inkscape will close now.\n");
471
fprintf (stderr, "If you can reproduce this crash, please file a bug at www.inkscape.org\n");
472
fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
474
/* Show nice dialog box */
476
char const *istr = N_("Inkscape encountered an internal error and will close now.\n");
477
char const *sstr = N_("Automatic backups of unsaved documents were done to the following locations:\n");
478
char const *fstr = N_("Automatic backup of the following documents failed:\n");
479
gint nllen = strlen ("\n");
480
gint len = strlen (istr) + strlen (sstr) + strlen (fstr);
481
for (GSList *l = savednames; l != NULL; l = l->next) {
482
len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
484
for (GSList *l = failednames; l != NULL; l = l->next) {
485
len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
488
gchar *b = g_new (gchar, len);
491
memcpy (b + pos, istr, len);
495
memcpy (b + pos, sstr, len);
497
for (GSList *l = savednames; l != NULL; l = l->next) {
498
memset (b + pos, ' ', SP_INDENT);
500
len = strlen ((gchar *) l->data);
501
memcpy (b + pos, l->data, len);
503
memcpy (b + pos, "\n", nllen);
509
memcpy (b + pos, fstr, len);
511
for (GSList *l = failednames; l != NULL; l = l->next) {
512
memset (b + pos, ' ', SP_INDENT);
514
len = strlen ((gchar *) l->data);
515
memcpy (b + pos, l->data, len);
517
memcpy (b + pos, "\n", nllen);
523
if ( inkscape_get_instance() && inkscape_app_use_gui( inkscape_get_instance() ) ) {
524
GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
525
gtk_dialog_run (GTK_DIALOG (msgbox));
526
gtk_widget_destroy (msgbox);
530
g_message( "Error: %s", b );
537
(* segv_handler) (signum);
543
inkscape_application_init (const gchar *argv0, gboolean use_gui)
545
inkscape = (Inkscape::Application *)g_object_new (SP_TYPE_INKSCAPE, NULL);
546
/* fixme: load application defaults */
548
segv_handler = signal (SIGSEGV, inkscape_segv_handler);
549
signal (SIGFPE, inkscape_segv_handler);
550
signal (SIGILL, inkscape_segv_handler);
552
signal (SIGBUS, inkscape_segv_handler);
554
signal (SIGABRT, inkscape_segv_handler);
556
inkscape->use_gui = use_gui;
557
inkscape->argv0 = g_strdup(argv0);
559
/* Attempt to load the preferences, and set the save_preferences flag to TRUE
560
if we could, or FALSE if we couldn't */
561
Inkscape::Preferences::load();
562
inkscape_load_menus(inkscape);
564
/* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON */
566
#define DEFAULT_LOG_REDIRECT true
568
#define DEFAULT_LOG_REDIRECT false
571
if (prefs_get_int_attribute("dialogs.debug", "redirect", DEFAULT_LOG_REDIRECT))
573
Inkscape::UI::Dialogs::DebugDialog::getInstance()->captureLogMessages();
576
/* Initialize the extensions */
577
Inkscape::Extension::init();
583
* Returns the current Inkscape::Application global object
585
Inkscape::Application *
586
inkscape_get_instance()
591
gboolean inkscape_app_use_gui( Inkscape::Application const * app )
597
* Preference management
598
* We use '.' as separator
600
* Returns TRUE if the config file was successfully loaded, FALSE if not.
603
inkscape_load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton,
604
unsigned int skel_size, const gchar *e_notreg, const gchar *e_notxml,
605
const gchar *e_notsp, const gchar *warn)
607
gchar *fn = profile_path(filename);
608
if (!Inkscape::IO::file_test(fn, G_FILE_TEST_EXISTS)) {
611
result = inkscape_init_config (config, filename, skeleton,
613
_("Cannot create directory %s.\n%s"),
614
_("%s is not a valid directory.\n%s"),
615
_("Cannot create file %s.\n%s"),
616
_("Cannot write file %s.\n%s"),
617
_("Although Inkscape will run, it will use default settings,\n"
618
"and any changes made in preferences will not be saved."));
623
if (!Inkscape::IO::file_test(fn, G_FILE_TEST_IS_REGULAR)) {
624
/* Not a regular file */
625
gchar *safeFn = Inkscape::IO::sanitizeString(fn);
626
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notreg, safeFn, warn);
627
gtk_dialog_run (GTK_DIALOG (w));
628
gtk_widget_destroy (w);
634
Inkscape::XML::Document *doc = sp_repr_read_file (fn, NULL);
636
/* Not an valid xml file */
637
gchar *safeFn = Inkscape::IO::sanitizeString(fn);
638
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notxml, safeFn, warn);
639
gtk_dialog_run (GTK_DIALOG (w));
640
gtk_widget_destroy (w);
646
Inkscape::XML::Node *root = sp_repr_document_root (doc);
647
if (strcmp (root->name(), "inkscape")) {
648
gchar *safeFn = Inkscape::IO::sanitizeString(fn);
649
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notsp, safeFn, warn);
650
gtk_dialog_run (GTK_DIALOG (w));
651
gtk_widget_destroy (w);
652
Inkscape::GC::release(doc);
658
/** \todo this is a hack, need to figure out how to get
659
* a reasonable merge working with the menus.xml file */
660
if (skel_size == MENUS_SKELETON_SIZE) {
662
INKSCAPE->menus = doc;
665
config->root()->mergeFrom(doc->root(), "id");
668
Inkscape::GC::release(doc);
678
inkscape_load_menus (Inkscape::Application *inkscape)
680
gchar *fn = profile_path(MENUS_FILE);
682
if (Inkscape::IO::file_test(fn, G_FILE_TEST_EXISTS)) {
683
retval = inkscape_load_config (MENUS_FILE,
687
_("%s is not a regular file.\n%s"),
688
_("%s not a valid XML file, or\n"
689
"you don't have read permissions on it.\n%s"),
690
_("%s is not a valid menus file.\n%s"),
691
_("Inkscape will run with default menus.\n"
692
"New menus will not be saved."));
694
INKSCAPE->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL);
695
if (INKSCAPE->menus != NULL)
703
* We use '.' as separator
704
* \param inkscape Unused
706
Inkscape::XML::Node *
707
inkscape_get_repr (Inkscape::Application *inkscape, const gchar *key)
713
Inkscape::XML::Node *repr = sp_repr_document_root (Inkscape::Preferences::get());
714
g_assert (!(strcmp (repr->name(), "inkscape")));
716
gchar const *s = key;
717
while ((s) && (*s)) {
720
gchar const *e = strchr (s, '.');
728
Inkscape::XML::Node* child;
729
for (child = repr->firstChild(); child != NULL; child = child->next()) {
730
gchar const *id = child->attribute("id");
731
if ((id) && (strlen (id) == len) && (!strncmp (id, s, len)))
749
inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
751
if (Inkscape::NSApplication::Application::getNewGui()) {
752
Inkscape::NSApplication::Editor::selectionModified (selection, flags);
755
g_return_if_fail (selection != NULL);
757
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
758
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
764
inkscape_selection_changed (Inkscape::Selection * selection)
766
if (Inkscape::NSApplication::Application::getNewGui()) {
767
Inkscape::NSApplication::Editor::selectionChanged (selection);
770
g_return_if_fail (selection != NULL);
772
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
773
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
778
inkscape_subselection_changed (SPDesktop *desktop)
780
if (Inkscape::NSApplication::Application::getNewGui()) {
781
Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
784
g_return_if_fail (desktop != NULL);
786
if (DESKTOP_IS_ACTIVE (desktop)) {
787
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
793
inkscape_selection_set (Inkscape::Selection * selection)
795
if (Inkscape::NSApplication::Application::getNewGui()) {
796
Inkscape::NSApplication::Editor::selectionSet (selection);
799
g_return_if_fail (selection != NULL);
801
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
802
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
803
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
809
inkscape_eventcontext_set (SPEventContext * eventcontext)
811
if (Inkscape::NSApplication::Application::getNewGui()) {
812
Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
815
g_return_if_fail (eventcontext != NULL);
816
g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
818
if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
819
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
825
inkscape_add_desktop (SPDesktop * desktop)
827
g_return_if_fail (desktop != NULL);
829
if (Inkscape::NSApplication::Application::getNewGui())
831
Inkscape::NSApplication::Editor::addDesktop (desktop);
834
g_return_if_fail (inkscape != NULL);
836
g_assert (!g_slist_find (inkscape->desktops, desktop));
838
inkscape->desktops = g_slist_append (inkscape->desktops, desktop);
840
if (DESKTOP_IS_ACTIVE (desktop)) {
841
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
842
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (desktop));
843
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, SP_DT_SELECTION (desktop));
844
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (desktop));
851
inkscape_remove_desktop (SPDesktop * desktop)
853
g_return_if_fail (desktop != NULL);
854
if (Inkscape::NSApplication::Application::getNewGui())
856
Inkscape::NSApplication::Editor::removeDesktop (desktop);
859
g_return_if_fail (inkscape != NULL);
861
g_assert (g_slist_find (inkscape->desktops, desktop));
863
if (DESKTOP_IS_ACTIVE (desktop)) {
864
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
865
if (inkscape->desktops->next != NULL) {
866
SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
867
inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
868
inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
869
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
870
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (new_desktop));
871
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, SP_DT_SELECTION (new_desktop));
872
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (new_desktop));
874
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
875
if (SP_DT_SELECTION(desktop))
876
SP_DT_SELECTION(desktop)->clear();
880
inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
882
// if this was the last desktop, shut down the program
883
if (inkscape->desktops == NULL) {
884
inkscape_exit (inkscape);
891
inkscape_activate_desktop (SPDesktop * desktop)
893
g_return_if_fail (desktop != NULL);
894
if (Inkscape::NSApplication::Application::getNewGui())
896
Inkscape::NSApplication::Editor::activateDesktop (desktop);
899
g_return_if_fail (inkscape != NULL);
901
if (DESKTOP_IS_ACTIVE (desktop)) {
905
g_assert (g_slist_find (inkscape->desktops, desktop));
907
SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
909
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
911
inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
912
inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
914
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
915
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (desktop));
916
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, SP_DT_SELECTION (desktop));
917
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (desktop));
922
* Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
925
inkscape_reactivate_desktop (SPDesktop * desktop)
927
g_return_if_fail (desktop != NULL);
928
if (Inkscape::NSApplication::Application::getNewGui())
930
Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
933
g_return_if_fail (inkscape != NULL);
935
if (DESKTOP_IS_ACTIVE (desktop))
936
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
942
inkscape_find_desktop_by_dkey (unsigned int dkey)
944
for (GSList *r = inkscape->desktops; r; r = r->next) {
945
if (((SPDesktop *) r->data)->dkey == dkey)
946
return ((SPDesktop *) r->data);
955
inkscape_maximum_dkey()
957
unsigned int dkey = 0;
959
for (GSList *r = inkscape->desktops; r; r = r->next) {
960
if (((SPDesktop *) r->data)->dkey > dkey)
961
dkey = ((SPDesktop *) r->data)->dkey;
970
inkscape_next_desktop ()
973
unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
975
if (dkey_current < inkscape_maximum_dkey()) {
976
// find next existing
977
for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
978
d = inkscape_find_desktop_by_dkey (i);
984
// find first existing
985
for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
986
d = inkscape_find_desktop_by_dkey (i);
1001
inkscape_prev_desktop ()
1003
SPDesktop *d = NULL;
1004
unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1006
if (dkey_current > 0) {
1007
// find prev existing
1008
for (signed int i = dkey_current - 1; i >= 0; i--) {
1009
d = inkscape_find_desktop_by_dkey (i);
1016
// find last existing
1017
d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1028
inkscape_switch_desktops_next ()
1030
inkscape_next_desktop()->presentWindow();
1036
inkscape_switch_desktops_prev ()
1038
inkscape_prev_desktop()->presentWindow();
1044
inkscape_dialogs_hide ()
1046
if (Inkscape::NSApplication::Application::getNewGui())
1047
Inkscape::NSApplication::Editor::hideDialogs();
1050
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1051
inkscape->dialogs_toggle = FALSE;
1058
inkscape_dialogs_unhide ()
1060
if (Inkscape::NSApplication::Application::getNewGui())
1061
Inkscape::NSApplication::Editor::unhideDialogs();
1064
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1065
inkscape->dialogs_toggle = TRUE;
1072
inkscape_dialogs_toggle ()
1074
if (inkscape->dialogs_toggle) {
1075
inkscape_dialogs_hide ();
1077
inkscape_dialogs_unhide ();
1082
inkscape_external_change ()
1084
g_return_if_fail (inkscape != NULL);
1086
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1090
* fixme: These need probably signals too
1093
inkscape_add_document (SPDocument *document)
1095
g_return_if_fail (document != NULL);
1097
if (!Inkscape::NSApplication::Application::getNewGui())
1099
g_assert (!g_slist_find (inkscape->documents, document));
1100
inkscape->documents = g_slist_append (inkscape->documents, document);
1104
Inkscape::NSApplication::Editor::addDocument (document);
1111
inkscape_remove_document (SPDocument *document)
1113
g_return_if_fail (document != NULL);
1115
if (!Inkscape::NSApplication::Application::getNewGui())
1117
g_assert (g_slist_find (inkscape->documents, document));
1118
inkscape->documents = g_slist_remove (inkscape->documents, document);
1122
Inkscape::NSApplication::Editor::removeDocument (document);
1129
inkscape_active_desktop (void)
1131
if (Inkscape::NSApplication::Application::getNewGui())
1132
return Inkscape::NSApplication::Editor::getActiveDesktop();
1134
if (inkscape->desktops == NULL) {
1138
return (SPDesktop *) inkscape->desktops->data;
1142
inkscape_active_document (void)
1144
if (Inkscape::NSApplication::Application::getNewGui())
1145
return Inkscape::NSApplication::Editor::getActiveDocument();
1147
if (SP_ACTIVE_DESKTOP) {
1148
return SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
1154
bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1155
SPDocument const* document = desktop.doc();
1159
for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1160
SPDesktop *other_desktop=(SPDesktop *)iter->data;
1161
SPDocument *other_document=other_desktop->doc();
1162
if ( other_document == document && other_desktop != &desktop ) {
1170
inkscape_active_event_context (void)
1172
if (SP_ACTIVE_DESKTOP) {
1173
return SP_DT_EVENTCONTEXT (SP_ACTIVE_DESKTOP);
1181
/*#####################
1183
#####################*/
1186
inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
1187
unsigned int skel_size,
1188
const gchar *e_mkdir,
1189
const gchar *e_notdir,
1194
gchar *dn = profile_path(NULL);
1195
bool use_gui = (Inkscape::NSApplication::Application::getNewGui())? Inkscape::NSApplication::Application::getUseGui() : inkscape->use_gui;
1196
if (!Inkscape::IO::file_test(dn, G_FILE_TEST_EXISTS)) {
1197
if (Inkscape::IO::mkdir_utf8name(dn))
1200
// Cannot create directory
1201
gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1202
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_mkdir, safeDn, warn);
1203
gtk_dialog_run (GTK_DIALOG (w));
1204
gtk_widget_destroy (w);
1209
g_warning(e_mkdir, dn, warn);
1214
} else if (!Inkscape::IO::file_test(dn, G_FILE_TEST_IS_DIR)) {
1217
gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1218
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notdir, safeDn, warn);
1219
gtk_dialog_run (GTK_DIALOG (w));
1220
gtk_widget_destroy (w);
1225
g_warning(e_notdir, dn, warn);
1232
gchar *fn = profile_path(config_name);
1234
Inkscape::IO::dump_fopen_call(fn, "H");
1235
FILE *fh = Inkscape::IO::fopen_utf8name(fn, "w");
1238
/* Cannot create file */
1239
gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1240
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_ccf, safeFn, warn);
1241
gtk_dialog_run (GTK_DIALOG (w));
1242
gtk_widget_destroy (w);
1247
g_warning(e_ccf, fn, warn);
1252
if ( fwrite(skeleton, 1, skel_size, fh) != skel_size ) {
1254
/* Cannot create file */
1255
gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1256
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_cwf, safeFn, warn);
1257
gtk_dialog_run (GTK_DIALOG (w));
1258
gtk_widget_destroy (w);
1264
g_warning(e_cwf, fn, warn);
1277
inkscape_refresh_display (Inkscape::Application *inkscape)
1279
for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1280
(static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1286
* Handler for Inkscape's Exit verb. This emits the shutdown signal,
1287
* saves the preferences if appropriate, and quits.
1290
inkscape_exit (Inkscape::Application *inkscape)
1292
g_assert (INKSCAPE);
1294
//emit shutdown signal so that dialogs could remember layout
1295
g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1297
Inkscape::Preferences::save();
1302
homedir_path(const char *filename)
1304
static const gchar *homedir = NULL;
1306
homedir = g_get_home_dir();
1307
gchar* utf8Path = g_filename_to_utf8( homedir, -1, NULL, NULL, NULL );
1311
if (!g_utf8_validate(homedir, -1, NULL)) {
1312
g_warning( "g_get_home_dir() post A IS NOT UTF-8" );
1317
gchar * path = g_path_get_dirname(INKSCAPE->argv0);
1318
gchar* utf8Path = g_filename_to_utf8( path, -1, NULL, NULL, NULL );
1323
if (!g_utf8_validate(homedir, -1, NULL)) {
1324
g_warning( "g_get_home_dir() post B IS NOT UTF-8" );
1328
return g_build_filename(homedir, filename, NULL);
1333
* Get, or guess, or decide the location where the preferences.xml
1334
* file should be located.
1337
profile_path(const char *filename)
1339
static const gchar *prefdir = NULL;
1341
#ifdef HAS_SHGetSpecialFolderLocation
1342
// prefer c:\Documents and Settings\UserName\Application Data\ to
1343
// c:\Documents and Settings\userName\;
1345
ITEMIDLIST *pidl = 0;
1346
if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) {
1347
gchar * utf8Path = NULL;
1349
if ( PrintWin32::is_os_wide() ) {
1350
wchar_t pathBuf[MAX_PATH+1];
1351
g_assert(sizeof(wchar_t) == sizeof(gunichar2));
1353
if ( SHGetPathFromIDListW( pidl, pathBuf ) ) {
1354
utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL );
1357
char pathBuf[MAX_PATH+1];
1359
if ( SHGetPathFromIDListA( pidl, pathBuf ) ) {
1360
utf8Path = g_filename_to_utf8( pathBuf, -1, NULL, NULL, NULL );
1365
if (!g_utf8_validate(utf8Path, -1, NULL)) {
1366
g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
1375
/* not compiling yet...
1377
// Remember to free the list pointer
1378
IMalloc * imalloc = 0;
1379
if ( SHGetMalloc(&imalloc) == NOERROR) {
1380
imalloc->lpVtbl->Free( imalloc, pidl );
1381
imalloc->lpVtbl->Release( imalloc );
1388
prefdir = homedir_path(NULL);
1391
return g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, filename, NULL);
1394
Inkscape::XML::Node *
1395
inkscape_get_menus (Inkscape::Application * inkscape)
1397
Inkscape::XML::Node *repr = sp_repr_document_root (inkscape->menus);
1398
g_assert (!(strcmp (repr->name(), "inkscape")));
1399
return repr->firstChild();
1407
c-file-style:"stroustrup"
1408
c-file-offsets:((innamespace . 0)(inline-open . 0))
1409
indent-tabs-mode:nil
1413
// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :