inkscape.cpp revision 5d0b21ece5dcf0880147dced446995a109b482db
#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 <set>
#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 <glib.h>
#include <string>
#include <cstring>
#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"
#include "message-stack.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) = SIG_DFL;
static void (* abrt_handler) (int) = SIG_DFL;
static void (* fpe_handler) (int) = SIG_DFL;
static void (* ill_handler) (int) = SIG_DFL;
static void (* bus_handler) (int) = SIG_DFL;
#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);
}
#ifdef WIN32
typedef int uid_t;
#define getuid() 0
#endif
/**
* static gint inkscape_autosave(gpointer);
*
* Callback passed to g_timeout_add_seconds()
* Responsible for autosaving all open documents
*/
{
// Use UID for separating autosave-documents between users if directory is multiuser
{
if ( tmp ) {
autosave_dir = tmp;
} else {
}
}
if( !autosave_dir_ptr ){
g_warning("Cannot open autosave directory!");
return TRUE;
}
++docnum;
// TODO replace this with SP_DOCUMENT() when linking issues are addressed:
// g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->name : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)");
if (doc->isModifiedSinceSave()) {
gchar *oldest_autosave = 0;
// Look for previous autosaves
if ( oldest_autosave ) {
}
}
count ++;
}
}
}
// g_debug("%d previous autosaves exists. Max = %d", count, autosave_max);
// Have we reached the limit for number of autosaves?
if ( count >= autosave_max ){
// Remove the oldest file
if ( oldest_autosave ) {
}
}
if ( oldest_autosave ) {
oldest_autosave = 0;
}
// Set the filename we will actually save to
baseName = 0;
// g_debug("Filename: %s", full_path);
// Try to save the file
if (file) {
try{
}
}
else {
}
if (errortext) {
}
}
}
return TRUE;
}
void inkscape_autosave_init()
{
static guint32 autosave_timeout_id = 0;
// Turn off any previously initiated timeouts
if ( autosave_timeout_id ) {
autosave_timeout_id = 0;
}
// g_debug("options.autosave.enable = %lld", prefs_get_int_attribute_limited("options.autosave", "enable", 1, 0, 1));
// Is autosave enabled?
autosave_timeout_id = 0;
} else {
// Turn on autosave
// g_debug("options.autosave.interval = %lld", prefs_get_int_attribute("options.autosave", "interval", 10));
#else
#endif
}
}
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)
}
/* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */
/* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */
inkscape_mapalt() {
}
/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
{
}else{
}
}
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_crash_handler (int /*signum*/)
{
/*
* reset all signal handlers: any further crashes should just be allowed
* to crash normally.
* */
#ifndef WIN32
#endif
/* Stop bizarre loops */
if (recursion) {
abort ();
}
if (doc->isModifiedSinceSave()) {
/* 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 *istr = _("Inkscape encountered an internal error and will close now.\n");
char const *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
char const *fstr = _("Automatic backup of the following documents failed:\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);
/* on exit, allow restored signal handler to take over and crash us */
}
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.
* Use only if use_gui is enabled
*/
#ifdef WIN32
#define DEFAULT_LOG_REDIRECT true
#else
#define DEFAULT_LOG_REDIRECT false
#endif
{
}
/* Check for global remapping of Alt key */
if(use_gui)
{
}
/* 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;
}
if ( !prefs ) {
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;
}
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
}
void
{
{
return;
}
if (DESKTOP_IS_ACTIVE (desktop)) {
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
} else {
if (sp_desktop_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_desktop_event_context (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_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_desktop_document (SP_ACTIVE_DESKTOP);
}
return NULL;
}
if (!document) {
return false;
}
return false;
}
}
return true;
}
{
if (SP_ACTIVE_DESKTOP) {
return sp_desktop_event_context (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;
}
}
// Also create (empty for now) subdirectories for the user's stuff
{
}
{
}
{
}
{
}
{
}
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();
}
void
{
}
}
/*
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 :