inkscape.cpp revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#define __INKSCAPE_C__
/*
* Interface to main application
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 authors
* g++ port Copyright (C) 2003 Nathan Hurst
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "debug/simple-event.h"
#include "debug/event-tracker.h"
#ifndef WIN32
# define HAS_PROC_SELF_EXE //to get path of executable
#else
// For now to get at is_os_wide().
#define _WIN32_IE 0x0400
//#define HAS_SHGetSpecialFolderPath
#define HAS_SHGetSpecialFolderLocation
#define HAS_GetModuleFileName
# include <shlobj.h>
#endif
#include <signal.h>
#include <gtk/gtkmessagedialog.h>
#include "helper/sp-marshal.h"
#include "dialogs/debugdialog.h"
#include "application/application.h"
#include "application/editor.h"
#include "preferences.h"
#include "document.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
#include "event-context.h"
#include "inkscape-private.h"
#include "prefs-utils.h"
/* Backbones of configuration xml data */
#include "menus-skeleton.h"
enum {
MODIFY_SELECTION, // global: one of selections modified
CHANGE_SELECTION, // global: one of selections changed
CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
SET_SELECTION, // global: one of selections set
SET_EVENTCONTEXT, // tool switched
ACTIVATE_DESKTOP, // some desktop got focus
DEACTIVATE_DESKTOP, // some desktop lost focus
SHUTDOWN_SIGNAL, // inkscape is quitting
DIALOGS_HIDE, // user pressed F12
DIALOGS_UNHIDE, // user pressed F12
EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
// may not be reflected by a selection change and thus needs a separate signal
};
/*################################
# FORWARD DECLARATIONS
################################*/
static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
static bool inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
unsigned int skel_size,
struct Inkscape::Application {
// for overriding things like the warning dlg's
};
struct Inkscape::ApplicationClass {
/* Signals */
void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
};
static GObjectClass * parent_class;
static void (* segv_handler) (int) = NULL;
#ifdef WIN32
#define INKSCAPE_PROFILE_DIR "Inkscape"
#else
#define INKSCAPE_PROFILE_DIR ".inkscape"
#endif
#define MENUS_FILE "menus.xml"
/**
* Retrieves the GType for the Inkscape Application object.
*/
inkscape_get_type (void)
{
if (!type) {
sizeof (Inkscape::ApplicationClass),
sizeof (Inkscape::Application),
4,
};
}
return type;
}
/**
* Initializes the inkscape class, registering all of its signal handlers
* and virtual functions
*/
static void
{
G_TYPE_NONE, 2,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 1,
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
G_TYPE_NONE, 0);
}
static void
{
if (!inkscape) {
} else {
}
}
static void
{
// we don't otherwise unref, so why here?
}
/* fixme: This is not the best place */
}
gtk_main_quit ();
}
void
inkscape_ref (void)
{
if (inkscape)
}
void
inkscape_unref (void)
{
if (inkscape)
}
static void
{
desktop->set_active (true);
}
static void
{
desktop->set_active (false);
}
/* fixme: This is EVIL, and belongs to main after all */
#define SP_INDENT 8
static void
inkscape_segv_handler (int signum)
{
/* let any SIGABRTs seen from within this handler dump core */
/* Kill loops */
if (recursion) {
abort ();
}
/* originally, the document name was retrieved from
* the sodipod:docname attribute */
if (docname) {
/* fixme: Quick hack to remove emergency file suffix */
d = d0;
if (*d) {
n[63] = '\0';
docname = n;
}
}
}
}
// try saving to the profile location
if (!file) {
// try saving to /tmp
}
if (!file) {
// try saving to the current directory
}
if (file) {
} else {
failednames = g_slist_prepend (failednames, (docname) ? g_strdup (docname) : g_strdup (_("Untitled document")));
}
count++;
}
}
if (savednames) {
}
}
if (failednames) {
}
}
fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
/* Show nice dialog box */
char const *sstr = N_("Automatic backups of unsaved documents were done to the following locations:\n");
}
}
len += 1;
if (savednames) {
}
}
if (failednames) {
}
}
*(b + pos) = '\0';
GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
}
else
{
g_message( "Error: %s", b );
}
g_free (b);
(* segv_handler) (signum);
}
void
{
/* fixme: load application defaults */
#ifndef WIN32
#endif
/* Attempt to load the preferences, and set the save_preferences flag to TRUE
if we could, or FALSE if we couldn't */
/* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON */
#ifdef WIN32
#define DEFAULT_LOG_REDIRECT true
#else
#define DEFAULT_LOG_REDIRECT false
#endif
{
}
/* Initialize the extensions */
return;
}
/**
* Returns the current Inkscape::Application global object
*/
{
return inkscape;
}
{
}
/**
* Preference management
* We use '.' as separator
*
* Returns TRUE if the config file was successfully loaded, FALSE if not.
*/
bool
inkscape_load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton,
{
bool result;
/* No such file */
_("Cannot create directory %s.\n%s"),
_("%s is not a valid directory.\n%s"),
_("Cannot create file %s.\n%s"),
_("Cannot write file %s.\n%s"),
_("Although Inkscape will run, it will use default settings,\n"
"and any changes made in preferences will not be saved."));
return result;
}
/* Not a regular file */
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notreg, safeFn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
}
/* Not an valid xml file */
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notxml, safeFn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
}
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notsp, safeFn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
}
/** \todo this is a hack, need to figure out how to get
* a reasonable merge working with the menus.xml file */
if (skel_size == MENUS_SKELETON_SIZE) {
if (INKSCAPE)
} else {
}
return true;
}
/**
* Menus management
*
*/
bool
{
bool retval = false;
_("%s is not a regular file.\n%s"),
_("%s not a valid XML file, or\n"
"you don't have read permissions on it.\n%s"),
_("%s is not a valid menus file.\n%s"),
_("Inkscape will run with default menus.\n"
"New menus will not be saved."));
} else {
retval = true;
}
return retval;
}
/**
* We use '.' as separator
* \param inkscape Unused
*/
{
return NULL;
}
while ((s) && (*s)) {
/* Find next name */
if (e) {
len = e++ - s;
} else {
}
{
break;
}
}
return NULL;
}
s = e;
}
return repr;
}
void
{
return;
}
}
}
void
{
return;
}
}
}
void
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop)) {
}
}
void
{
return;
}
}
}
void
{
return;
}
}
}
void
{
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop)) {
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (desktop));
}
}
void
{
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop)) {
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, SP_DT_SELECTION (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (new_desktop));
} else {
if (SP_DT_SELECTION(desktop))
}
}
// if this was the last desktop, shut down the program
}
}
void
{
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop)) {
return;
}
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, SP_DT_EVENTCONTEXT (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, SP_DT_SELECTION (desktop));
}
/**
* Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
*/
void
{
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop))
}
inkscape_find_desktop_by_dkey (unsigned int dkey)
{
}
return NULL;
}
unsigned int
{
unsigned int dkey = 0;
}
return dkey;
}
{
if (dkey_current < inkscape_maximum_dkey()) {
// find next existing
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
} else {
// find first existing
for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
}
g_assert (d);
return d;
}
{
if (dkey_current > 0) {
// find prev existing
for (signed int i = dkey_current - 1; i >= 0; i--) {
d = inkscape_find_desktop_by_dkey (i);
if (d) {
break;
}
}
}
if (!d) {
// find last existing
}
g_assert (d);
return d;
}
void
{
}
void
{
}
void
{
else
{
}
}
void
{
else
{
}
}
void
{
if (inkscape->dialogs_toggle) {
} else {
}
}
void
{
}
/**
* fixme: These need probably signals too
*/
void
{
{
}
else
{
}
}
void
{
{
}
else
{
}
return;
}
inkscape_active_desktop (void)
{
return NULL;
}
}
inkscape_active_document (void)
{
if (SP_ACTIVE_DESKTOP) {
return SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);
}
return NULL;
}
if (!document) {
return false;
}
return false;
}
}
return true;
}
{
if (SP_ACTIVE_DESKTOP) {
return SP_DT_EVENTCONTEXT (SP_ACTIVE_DESKTOP);
}
return NULL;
}
/*#####################
# HELPERS
#####################*/
static bool
inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
unsigned int skel_size,
{
bool use_gui = (Inkscape::NSApplication::Application::getNewGui())? Inkscape::NSApplication::Application::getUseGui() : inkscape->use_gui;
{
if (use_gui) {
// Cannot create directory
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_mkdir, safeDn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
} else {
return false;
}
}
if (use_gui) {
// Not a directory
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notdir, safeDn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
} else {
return false;
}
}
if (!fh) {
if (use_gui) {
/* Cannot create file */
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_ccf, safeFn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
} else {
return false;
}
}
if (use_gui) {
/* Cannot create file */
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_cwf, safeFn, warn);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
return false;
} else {
return false;
}
}
return true;
}
void
{
}
}
/**
* Handler for Inkscape's Exit verb. This emits the shutdown signal,
* saves the preferences if appropriate, and quits.
*/
void
{
//emit shutdown signal so that dialogs could remember layout
gtk_main_quit ();
}
gchar *
homedir_path(const char *filename)
{
if (!homedir) {
homedir = g_get_home_dir();
if ( utf8Path )
{
g_warning( "g_get_home_dir() post A IS NOT UTF-8" );
}
}
}
if (!homedir) {
if ( utf8Path )
{
g_warning( "g_get_home_dir() post B IS NOT UTF-8" );
}
}
}
}
/**
* Get, or guess, or decide the location where the preferences.xml
* file should be located.
*/
gchar *
profile_path(const char *filename)
{
if (!prefdir) {
// prefer c:\Documents and Settings\UserName\Application Data\ to
// c:\Documents and Settings\userName\;
if (!prefdir) {
ITEMIDLIST *pidl = 0;
if ( PrintWin32::is_os_wide() ) {
}
} else {
}
}
if ( utf8Path ) {
g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
utf8Path = 0;
} else {
}
}
/* not compiling yet...
// Remember to free the list pointer
IMalloc * imalloc = 0;
if ( SHGetMalloc(&imalloc) == NOERROR) {
imalloc->lpVtbl->Free( imalloc, pidl );
imalloc->lpVtbl->Release( imalloc );
}
*/
}
}
#endif
if (!prefdir) {
}
}
}
{
return repr->firstChild();
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :