summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoel Holdsworth <joel@airwebreathe.org.uk>2007-07-28 12:32:01 +0000
committerjoelholdsworth <joelholdsworth@users.sourceforge.net>2007-07-28 12:32:01 +0000
commit246fcd5198c0a53e27f309777a8ae23e98221753 (patch)
tree22d7909d4ddc490f4cf408afa1a81e6bec601ee2 /src
parentFilter effects dialog: (diff)
downloadinkscape-246fcd5198c0a53e27f309777a8ae23e98221753.tar.gz
inkscape-246fcd5198c0a53e27f309777a8ae23e98221753.zip
Gtkmm-ified the desktop window object, and modified the file dialogs so that they are correctly parented
(bzr r3328)
Diffstat (limited to 'src')
-rw-r--r--src/desktop.cpp33
-rw-r--r--src/desktop.h14
-rw-r--r--src/file.cpp36
-rw-r--r--src/file.h14
-rw-r--r--src/helper/window.cpp23
-rw-r--r--src/helper/window.h12
-rw-r--r--src/interface.cpp113
-rw-r--r--src/ui/dialog/filedialog.cpp60
-rw-r--r--src/ui/dialog/filedialog.h9
-rw-r--r--src/ui/view/edit-widget-interface.h5
-rw-r--r--src/ui/view/edit-widget.cpp8
-rw-r--r--src/ui/view/edit-widget.h2
-rw-r--r--src/verbs.cpp18
-rw-r--r--src/widgets/desktop-widget.cpp55
-rw-r--r--src/widgets/desktop-widget.h14
15 files changed, 236 insertions, 180 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 859e15bd8..4cfc279cc 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -1030,9 +1030,9 @@ SPDesktop::setWindowTransient (void *p, int transient_policy)
_widget->setTransient (p, transient_policy);
}
-void SPDesktop::getToplevel( GtkWidget*& toplevel )
+void SPDesktop::getToplevel( Gtk::Widget*& toplevel )
{
- toplevel = GTK_WIDGET( _widget->getWindow() );
+ toplevel = (Gtk::Widget*)_widget->getWindow();
}
void
@@ -1077,6 +1077,35 @@ SPDesktop::shutdown()
return _widget->shutdown();
}
+bool SPDesktop::onDeleteUI (GdkEventAny*)
+{
+ if(shutdown()) return true;
+ destroyWidget();
+ return false;
+}
+
+/**
+ * onWindowStateEvent
+ *
+ * Called when the window changes its maximize/fullscreen/iconify/pinned state.
+ * Since GTK doesn't have a way to query this state information directly, we
+ * record it for the desktop here, and also possibly trigger a layout.
+ */
+bool
+SPDesktop::onWindowStateEvent (GdkEventWindowState* event)
+{
+ // Record the desktop window's state
+ window_state = event->new_window_state;
+
+ // Layout may differ depending on full-screen mode or not
+ GdkWindowState changed = event->changed_mask;
+ if (changed & (GDK_WINDOW_STATE_FULLSCREEN|GDK_WINDOW_STATE_MAXIMIZED)) {
+ layoutWidget();
+ }
+
+ return false;
+}
+
void
SPDesktop::setToolboxFocusTo (gchar const *label)
{
diff --git a/src/desktop.h b/src/desktop.h
index 4c255ecbb..3bf6fa65a 100644
--- a/src/desktop.h
+++ b/src/desktop.h
@@ -25,8 +25,10 @@
#include "config.h"
#endif
+#include <gdk/gdkevents.h>
#include <gtk/gtktypeutils.h>
#include <sigc++/sigc++.h>
+
#include "libnr/nr-matrix.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-rect.h"
@@ -48,8 +50,15 @@ struct SPObject;
struct SPStyle;
struct SPViewWidget;
+namespace Gtk
+{
+ class Widget;
+}
+
typedef int sp_verb_t;
+
+
namespace Inkscape {
class Application;
class MessageContext;
@@ -229,7 +238,7 @@ struct SPDesktop : public Inkscape::UI::View::View
void setWindowPosition (NR::Point p);
void setWindowSize (gint w, gint h);
void setWindowTransient (void* p, int transient_policy=1);
- void getToplevel( GtkWidget*& toplevel );
+ void getToplevel( Gtk::Widget*& toplevel );
void presentWindow();
bool warnDialog (gchar *text);
void toggleRulers();
@@ -274,6 +283,9 @@ struct SPDesktop : public Inkscape::UI::View::View
virtual void mouseover() {}
virtual void mouseout() {}
+ virtual bool onDeleteUI (GdkEventAny*);
+ virtual bool onWindowStateEvent (GdkEventWindowState* event);
+
private:
Inkscape::UI::View::EditWidgetInterface *_widget;
Inkscape::Application *_inkscape;
diff --git a/src/file.cpp b/src/file.cpp
index 69d6da610..436cd0ee0 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -359,7 +359,7 @@ static Inkscape::UI::Dialog::FileOpenDialog *openDialogInstance = NULL;
* Can select single or multiple files for opening.
*/
void
-sp_file_open_dialog(gpointer object, gpointer data)
+sp_file_open_dialog(Gtk::Window &parentWindow, gpointer object, gpointer data)
{
//# Get the current directory for finding files
@@ -385,6 +385,7 @@ sp_file_open_dialog(gpointer object, gpointer data)
if (!openDialogInstance) {
openDialogInstance =
Inkscape::UI::Dialog::FileOpenDialog::create(
+ parentWindow,
open_path,
Inkscape::UI::Dialog::SVG_TYPES,
(char const *)_("Select file to open"));
@@ -496,7 +497,7 @@ sp_file_vacuum()
* document; is true for normal save, false for temporary saves
*/
static bool
-file_save(SPDocument *doc, const Glib::ustring &uri,
+file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
Inkscape::Extension::Extension *key, bool saveas, bool official)
{
if (!doc || uri.size()<1) //Safety check
@@ -523,7 +524,7 @@ file_save(SPDocument *doc, const Glib::ustring &uri,
g_free(safeUri);
return FALSE;
} catch (Inkscape::Extension::Output::no_overwrite &e) {
- return sp_file_save_dialog(doc);
+ return sp_file_save_dialog(parentWindow, doc);
}
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
@@ -540,7 +541,7 @@ file_save(SPDocument *doc, const Glib::ustring &uri,
* \param ascopy (optional) wether to set the documents->uri to the new filename or not
*/
bool
-sp_file_save_dialog(SPDocument *doc, bool is_copy)
+sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
{
Inkscape::XML::Node *repr = sp_document_repr_root(doc);
@@ -614,6 +615,7 @@ sp_file_save_dialog(SPDocument *doc, bool is_copy)
}
Inkscape::UI::Dialog::FileSaveDialog *saveDialog =
Inkscape::UI::Dialog::FileSaveDialog::create(
+ parentWindow,
save_loc,
Inkscape::UI::Dialog::SVG_TYPES,
(char const *) _("Select file to save to"),
@@ -640,6 +642,7 @@ sp_file_save_dialog(SPDocument *doc, bool is_copy)
Inkscape::Extension::Extension *selectionType = saveDialog->getSelectionType();
delete saveDialog;
+
saveDialog = 0;
if (fileName.size() > 0) {
@@ -650,7 +653,7 @@ sp_file_save_dialog(SPDocument *doc, bool is_copy)
else
g_warning( "Error converting save filename to UTF-8." );
- success = file_save(doc, fileName, selectionType, TRUE, !is_copy);
+ success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy);
if (success)
prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc));
@@ -670,7 +673,7 @@ sp_file_save_dialog(SPDocument *doc, bool is_copy)
* Save a document, displaying a SaveAs dialog if necessary.
*/
bool
-sp_file_save_document(SPDocument *doc)
+sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc)
{
bool success = true;
@@ -681,11 +684,11 @@ sp_file_save_document(SPDocument *doc)
if ( doc->uri == NULL
|| repr->attribute("inkscape:output_extension") == NULL )
{
- return sp_file_save_dialog(doc, FALSE);
+ return sp_file_save_dialog(parentWindow, doc, FALSE);
} else {
fn = g_strdup(doc->uri);
gchar const *ext = repr->attribute("inkscape:output_extension");
- success = file_save(doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
+ success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
g_free((void *) fn);
}
} else {
@@ -701,7 +704,7 @@ sp_file_save_document(SPDocument *doc)
* Save a document.
*/
bool
-sp_file_save(gpointer object, gpointer data)
+sp_file_save(Gtk::Window &parentWindow, gpointer object, gpointer data)
{
if (!SP_ACTIVE_DOCUMENT)
return false;
@@ -709,7 +712,7 @@ sp_file_save(gpointer object, gpointer data)
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Saving document..."));
sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
- return sp_file_save_document(SP_ACTIVE_DOCUMENT);
+ return sp_file_save_document(parentWindow, SP_ACTIVE_DOCUMENT);
}
@@ -717,12 +720,12 @@ sp_file_save(gpointer object, gpointer data)
* Save a document, always displaying the SaveAs dialog.
*/
bool
-sp_file_save_as(gpointer object, gpointer data)
+sp_file_save_as(Gtk::Window &parentWindow, gpointer object, gpointer data)
{
if (!SP_ACTIVE_DOCUMENT)
return false;
sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
- return sp_file_save_dialog(SP_ACTIVE_DOCUMENT, FALSE);
+ return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE);
}
@@ -731,12 +734,12 @@ sp_file_save_as(gpointer object, gpointer data)
* Save a copy of a document, always displaying a sort of SaveAs dialog.
*/
bool
-sp_file_save_a_copy(gpointer object, gpointer data)
+sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer object, gpointer data)
{
if (!SP_ACTIVE_DOCUMENT)
return false;
sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
- return sp_file_save_dialog(SP_ACTIVE_DOCUMENT, TRUE);
+ return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE);
}
@@ -879,7 +882,7 @@ static Inkscape::UI::Dialog::FileOpenDialog *importDialogInstance = NULL;
* Display an Open dialog, import a resource if OK pressed.
*/
void
-sp_file_import(GtkWidget *widget)
+sp_file_import(Gtk::Window &parentWindow)
{
static Glib::ustring import_path;
@@ -890,7 +893,8 @@ sp_file_import(GtkWidget *widget)
if (!importDialogInstance) {
importDialogInstance =
Inkscape::UI::Dialog::FileOpenDialog::create(
- import_path,
+ parentWindow,
+ import_path,
Inkscape::UI::Dialog::IMPORT_TYPES,
(char const *)_("Select file to import"));
}
diff --git a/src/file.h b/src/file.h
index 18e4068a1..9bff1ca12 100644
--- a/src/file.h
+++ b/src/file.h
@@ -68,7 +68,7 @@ bool sp_file_open(
* Displays a file open dialog. Calls sp_file_open on
* an OK.
*/
-void sp_file_open_dialog (gpointer object, gpointer data);
+void sp_file_open_dialog (Gtk::Window &parentWindow, gpointer object, gpointer data);
/**
* Reverts file to disk-copy on "YES"
@@ -82,29 +82,29 @@ void sp_file_revert_dialog ();
/**
*
*/
-bool sp_file_save (gpointer object, gpointer data);
+bool sp_file_save (Gtk::Window &parentWindow, gpointer object, gpointer data);
/**
* Saves the given document. Displays a file select dialog
* to choose the new name.
*/
-bool sp_file_save_as (gpointer object, gpointer data);
+bool sp_file_save_as (Gtk::Window &parentWindow, gpointer object, gpointer data);
/**
* Saves a copy of the given document. Displays a file select dialog
* to choose a name for the copy.
*/
-bool sp_file_save_a_copy (gpointer object, gpointer data);
+bool sp_file_save_a_copy (Gtk::Window &parentWindow, gpointer object, gpointer data);
/**
* Saves the given document. Displays a file select dialog
* if needed.
*/
-bool sp_file_save_document (SPDocument *document);
+bool sp_file_save_document (Gtk::Window &parentWindow, SPDocument *document);
/* Do the saveas dialog with a document as the parameter */
-bool sp_file_save_dialog (SPDocument *doc, bool bAsCopy = FALSE);
+bool sp_file_save_dialog (Gtk::Window &parentWindow, SPDocument *doc, bool bAsCopy = FALSE);
/*######################
@@ -115,7 +115,7 @@ bool sp_file_save_dialog (SPDocument *doc, bool bAsCopy = FALSE);
* Displays a file selector dialog, to allow the
* user to import data into the current document.
*/
-void sp_file_import (GtkWidget * widget);
+void sp_file_import (Gtk::Window &parentWindow);
/**
* Imports a resource
diff --git a/src/helper/window.cpp b/src/helper/window.cpp
index 346bd19f1..6f898ee3e 100644
--- a/src/helper/window.cpp
+++ b/src/helper/window.cpp
@@ -13,14 +13,15 @@
# include <config.h>
#endif
#include <gtk/gtkwindow.h>
+#include <gtkmm/window.h>
#include "inkscape.h"
#include "shortcuts.h"
#include "desktop.h"
#include "event-context.h"
+#include "window.h"
-static gboolean
-sp_window_key_press (GtkWidget *widget, GdkEventKey *event)
+static bool on_window_key_press(GdkEventKey* event)
{
unsigned int shortcut;
shortcut = get_group0_keyval (event) |
@@ -33,6 +34,23 @@ sp_window_key_press (GtkWidget *widget, GdkEventKey *event)
return sp_shortcut_invoke (shortcut, SP_ACTIVE_DESKTOP);
}
+Gtk::Window *
+Inkscape::UI::window_new (const gchar *title, unsigned int resizeable)
+{
+ Gtk::Window *window = new Gtk::Window(Gtk::WINDOW_TOPLEVEL);
+ window->set_title (title);
+ window->set_resizable (resizeable);
+ window->signal_key_press_event().connect(sigc::ptr_fun(&on_window_key_press));
+
+ return window;
+}
+
+static gboolean
+sp_window_key_press (GtkWidget *widget, GdkEventKey *event)
+{
+ return on_window_key_press(event);
+}
+
GtkWidget *
sp_window_new (const gchar *title, unsigned int resizeable)
{
@@ -44,4 +62,3 @@ sp_window_new (const gchar *title, unsigned int resizeable)
return window;
}
-
diff --git a/src/helper/window.h b/src/helper/window.h
index 764cb0413..7f06fe423 100644
--- a/src/helper/window.h
+++ b/src/helper/window.h
@@ -11,9 +11,21 @@
*/
#include <gtk/gtkwidget.h>
+#include <gtkmm/window.h>
+/*
+ * This function is depreciated. Use Inkscape::UI::window_new instead.
+ */
GtkWidget *sp_window_new (const gchar *title, unsigned int resizeable);
+namespace Inkscape {
+namespace UI {
+
+Gtk::Window *window_new (const gchar *title, unsigned int resizeable);
+
+}
+}
+
#endif
/*
diff --git a/src/interface.cpp b/src/interface.cpp
index f43c31d30..eada69c34 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -40,6 +40,7 @@
#include "widgets/desktop-widget.h"
#include "sp-item-group.h"
#include "sp-namedview.h"
+#include "ui/view/view.h"
#include "helper/action.h"
#include "helper/gnome-utils.h"
@@ -63,15 +64,9 @@
#include "desktop-style.h"
#include "style.h"
-
using Inkscape::IO::StringOutputStream;
using Inkscape::IO::Base64OutputStream;
-/* forward declaration */
-static gint sp_ui_delete(GtkWidget *widget, GdkEvent *event, Inkscape::UI::View::View *view);
-static void sp_ui_state_event(GtkWidget *widget, GdkEventWindowState *event, SPDesktop*desktop);
-
-
/* Drag and Drop */
typedef enum {
URI_LIST,
@@ -135,26 +130,26 @@ sp_create_window(SPViewWidget *vw, gboolean editable)
g_return_if_fail(vw != NULL);
g_return_if_fail(SP_IS_VIEW_WIDGET(vw));
- GtkWidget *win = sp_window_new("", TRUE);
-
- if (editable) {
- g_object_set_data(G_OBJECT(vw), "window", win);
- reinterpret_cast<SPDesktopWidget*>(vw)->window =
- static_cast<GtkWindow*>((void*)win);
- }
+ Gtk::Window *win = Inkscape::UI::window_new("", TRUE);
if (editable) {
- SPDesktop* desktop = SP_DESKTOP_WIDGET(vw)->desktop;
+ g_object_set_data(G_OBJECT(vw), "window", win);
+
+ SPDesktopWidget *desktop_widget = reinterpret_cast<SPDesktopWidget*>(vw);
+ SPDesktop* desktop = desktop_widget->desktop;
+
+ desktop_widget->window = win;
/* fixme: doesn't allow making window any smaller than this */
- gtk_window_set_default_size((GtkWindow *) win, 640, 480);
- g_object_set_data(G_OBJECT(win), "desktop", desktop);
- g_object_set_data(G_OBJECT(win), "desktopwidget", vw);
- g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(sp_ui_delete), vw->view);
-
- g_signal_connect(G_OBJECT(win), "window_state_event", G_CALLBACK(sp_ui_state_event), static_cast<SPDesktop*>(vw->view));
- g_signal_connect(G_OBJECT(win), "focus_in_event", G_CALLBACK(sp_desktop_widget_set_focus), vw);
-
+ win->set_default_size(640, 480);
+
+ win->set_data("desktop", desktop);
+ win->set_data("desktopwidget", desktop_widget);
+
+ win->signal_delete_event().connect(sigc::mem_fun(*(SPDesktop*)vw->view, &SPDesktop::onDeleteUI));
+ win->signal_window_state_event().connect(sigc::mem_fun(*desktop, &SPDesktop::onWindowStateEvent));
+ win->signal_focus_in_event().connect(sigc::mem_fun(*desktop_widget, &SPDesktopWidget::onFocusInEvent));
+
gint prefs_geometry =
(2==prefs_get_int_attribute("options.savewindowgeometry", "value", 0));
if (prefs_geometry) {
@@ -191,18 +186,18 @@ sp_create_window(SPViewWidget *vw, gboolean editable)
}
}
if (maxed) {
- gtk_window_maximize(GTK_WINDOW(win));
+ win->maximize();
}
if (full) {
- gtk_window_fullscreen(GTK_WINDOW(win));
+ win->fullscreen();
}
}
} else {
- gtk_window_set_policy(GTK_WINDOW(win), TRUE, TRUE, TRUE);
+ gtk_window_set_policy(GTK_WINDOW(win->gobj()), TRUE, TRUE, TRUE);
}
- gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(vw));
+ gtk_container_add(GTK_CONTAINER(win->gobj()), GTK_WIDGET(vw));
gtk_widget_show(GTK_WIDGET(vw));
if ( completeDropTargets == 0 || completeDropTargetsCount == 0 )
@@ -236,16 +231,16 @@ sp_create_window(SPViewWidget *vw, gboolean editable)
}
}
- gtk_drag_dest_set(win,
+ gtk_drag_dest_set((GtkWidget*)win->gobj(),
GTK_DEST_DEFAULT_ALL,
completeDropTargets,
completeDropTargetsCount,
GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE));
- g_signal_connect(G_OBJECT(win),
+ g_signal_connect(G_OBJECT(win->gobj()),
"drag_data_received",
G_CALLBACK(sp_ui_drag_data_received),
NULL);
- gtk_widget_show(win);
+ win->show();
// needed because the first ACTIVATE_DESKTOP was sent when there was no window yet
inkscape_reactivate_desktop(SP_DESKTOP_WIDGET(vw)->desktop);
@@ -329,59 +324,6 @@ sp_ui_close_all(void)
return TRUE;
}
-static gint
-sp_ui_delete(GtkWidget *widget, GdkEvent *event, Inkscape::UI::View::View *view)
-{
- return view->shutdown();
-}
-
-/**
- * sp_ui_state_event
- *
- * Called when the window changes its maximize/fullscreen/iconify/pinned state.
- * Since GTK doesn't have a way to query this state information directly, we
- * record it for the desktop here, and also possibly trigger a layout.
- */
-static void
-sp_ui_state_event(GtkWidget *widget, GdkEventWindowState *event, SPDesktop* desktop)
-{
- // Record the desktop window's state
- desktop->window_state = event->new_window_state;
-
- // Layout may differ depending on full-screen mode or not
- GdkWindowState changed = event->changed_mask;
- if (changed & (GDK_WINDOW_STATE_FULLSCREEN|GDK_WINDOW_STATE_MAXIMIZED)) {
- desktop->layoutWidget();
- }
-/*
- // debug info
- g_message("State event desktop=0x%p", desktop);
- GdkWindowState state = event->new_window_state;
- GdkWindowState changed = event->changed_mask;
- if (changed & GDK_WINDOW_STATE_WITHDRAWN) {
- g_message("-- WIDTHDRAWN = %d", 0!=(state&GDK_WINDOW_STATE_WITHDRAWN));
- }
- if (changed & GDK_WINDOW_STATE_ICONIFIED) {
- g_message("-- ICONIFIED = %d", 0!=(state&GDK_WINDOW_STATE_ICONIFIED));
- }
- if (changed & GDK_WINDOW_STATE_MAXIMIZED) {
- g_message("-- MAXIMIZED = %d", 0!=(state&GDK_WINDOW_STATE_MAXIMIZED));
- }
- if (changed & GDK_WINDOW_STATE_STICKY) {
- g_message("-- STICKY = %d", 0!=(state&GDK_WINDOW_STATE_STICKY));
- }
- if (changed & GDK_WINDOW_STATE_FULLSCREEN) {
- g_message("-- FULLSCREEN = %d", 0!=(state&GDK_WINDOW_STATE_FULLSCREEN));
- }
- if (changed & GDK_WINDOW_STATE_ABOVE) {
- g_message("-- ABOVE = %d", 0!=(state&GDK_WINDOW_STATE_ABOVE));
- }
- if (changed & GDK_WINDOW_STATE_BELOW) {
- g_message("-- BELOW = %d", 0!=(state&GDK_WINDOW_STATE_BELOW));
- }
-*/
-}
-
/*
* Some day when the right-click menus are ready to start working
* smarter with the verbs, we'll need to change this NULL being
@@ -1355,15 +1297,16 @@ sp_ui_overwrite_file(gchar const *filename)
bool return_value = FALSE;
if (Inkscape::IO::file_test(filename, G_FILE_TEST_EXISTS)) {
- GtkWidget* ancestor = 0;
+ Gtk::Widget* ancestor = NULL;
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if ( desktop ) {
desktop->getToplevel( ancestor );
}
- GtkWindow *window = GTK_WIDGET_TOPLEVEL(ancestor) ? GTK_WINDOW( ancestor ) : 0;
+ Gtk::Window *window = ancestor->is_toplevel() ?
+ dynamic_cast<Gtk::Window*>( ancestor ) : 0;
gchar* baseName = g_path_get_basename( filename );
gchar* dirName = g_path_get_dirname( filename );
- GtkWidget* dialog = gtk_message_dialog_new_with_markup( window,
+ GtkWidget* dialog = gtk_message_dialog_new_with_markup( window->gobj(),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp
index 08c0d4116..4336b1f8b 100644
--- a/src/ui/dialog/filedialog.cpp
+++ b/src/ui/dialog/filedialog.cpp
@@ -715,8 +715,9 @@ public:
/**
*
*/
- FileDialogBase(const Glib::ustring &title, FileDialogType type, gchar const* preferenceBase) :
- Gtk::FileChooserDialog(title),
+ FileDialogBase(Gtk::Window& parentWindow, const Glib::ustring &title,
+ FileDialogType type, gchar const* preferenceBase) :
+ Gtk::FileChooserDialog(parentWindow, title),
preferenceBase(preferenceBase ? preferenceBase : "unknown"),
dialogType(type)
{
@@ -726,9 +727,9 @@ public:
/**
*
*/
- FileDialogBase(const Glib::ustring &title,
+ FileDialogBase(Gtk::Window& parentWindow, const Glib::ustring &title,
Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
- Gtk::FileChooserDialog(title, dialogType),
+ Gtk::FileChooserDialog(parentWindow, title, dialogType),
preferenceBase(preferenceBase ? preferenceBase : "unknown"),
dialogType(type)
{
@@ -848,7 +849,8 @@ class FileOpenDialogImpl : public FileOpenDialog, public FileDialogBase
{
public:
- FileOpenDialogImpl(const Glib::ustring &dir,
+ FileOpenDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title);
@@ -947,10 +949,11 @@ void FileOpenDialogImpl::createFilterMenu()
/**
* Constructor. Not called directly. Use the factory.
*/
-FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
+FileOpenDialogImpl::FileOpenDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title) :
- FileDialogBase(title, fileTypes, "dialogs.open")
+ FileDialogBase(parentWindow, title, fileTypes, "dialogs.open")
{
@@ -1003,11 +1006,12 @@ FileOpenDialogImpl::FileOpenDialogImpl(const Glib::ustring &dir,
/**
* Public factory. Called by file.cpp, among others.
*/
-FileOpenDialog *FileOpenDialog::create(const Glib::ustring &path,
+FileOpenDialog *FileOpenDialog::create(Gtk::Window &parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title)
{
- FileOpenDialog *dialog = new FileOpenDialogImpl(path, fileTypes, title);
+ FileOpenDialog *dialog = new FileOpenDialogImpl(parentWindow, path, fileTypes, title);
return dialog;
}
@@ -1128,7 +1132,8 @@ class FileSaveDialogImpl : public FileSaveDialog, public FileDialogBase
{
public:
- FileSaveDialogImpl(const Glib::ustring &dir,
+ FileSaveDialogImpl(Gtk::Window &parentWindow,
+ const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key);
@@ -1307,11 +1312,12 @@ void FileSaveDialogImpl::createFileTypeMenu()
/**
* Constructor
*/
-FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
+FileSaveDialogImpl::FileSaveDialogImpl(Gtk::Window &parentWindow,
+ const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key) :
- FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
+ FileDialogBase(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.save_as")
{
/* One file at a time */
set_select_multiple(false);
@@ -1402,12 +1408,13 @@ FileSaveDialogImpl::FileSaveDialogImpl(const Glib::ustring &dir,
/**
* Public factory method. Used in file.cpp
*/
-FileSaveDialog *FileSaveDialog::create(const Glib::ustring &path,
+FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key)
{
- FileSaveDialog *dialog = new FileSaveDialogImpl(path, fileTypes, title, default_key);
+ FileSaveDialog *dialog = new FileSaveDialogImpl(parentWindow, path, fileTypes, title, default_key);
return dialog;
}
@@ -1616,10 +1623,11 @@ class FileExportDialogImpl : public FileExportDialog, public FileDialogBase
{
public:
- FileExportDialogImpl(const Glib::ustring &dir,
- FileDialogType fileTypes,
- const Glib::ustring &title,
- const Glib::ustring &default_key);
+ FileExportDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key);
virtual ~FileExportDialogImpl();
@@ -1919,11 +1927,12 @@ void FileExportDialogImpl::createFileTypeMenu()
/**
* Constructor
*/
-FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
+FileExportDialogImpl::FileExportDialogImpl(Gtk::Window& parentWindow,
+ const Glib::ustring &dir,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key) :
- FileDialogBase(title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
+ FileDialogBase(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "dialogs.export"),
sourceX0Spinner("X0", _("Left edge of source")),
sourceY0Spinner("Y0", _("Top edge of source")),
sourceX1Spinner("X1", _("Right edge of source")),
@@ -2103,12 +2112,13 @@ FileExportDialogImpl::FileExportDialogImpl(const Glib::ustring &dir,
/**
* Public factory method. Used in file.cpp
*/
-FileExportDialog *FileExportDialog::create(const Glib::ustring &path,
- FileDialogType fileTypes,
- const Glib::ustring &title,
- const Glib::ustring &default_key)
+FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key)
{
- FileExportDialog *dialog = new FileExportDialogImpl(path, fileTypes, title, default_key);
+ FileExportDialog *dialog = new FileExportDialogImpl(parentWindow, path, fileTypes, title, default_key);
return dialog;
}
diff --git a/src/ui/dialog/filedialog.h b/src/ui/dialog/filedialog.h
index c573dbe5d..5499603d3 100644
--- a/src/ui/dialog/filedialog.h
+++ b/src/ui/dialog/filedialog.h
@@ -79,7 +79,8 @@ public:
* @param fileTypes one of FileDialogTypes
* @param title the title of the dialog
*/
- static FileOpenDialog *create(const Glib::ustring &path,
+ static FileOpenDialog *create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title);
@@ -139,7 +140,8 @@ public:
* @param title the title of the dialog
* @param key a list of file types from which the user can select
*/
- static FileSaveDialog *create(const Glib::ustring &path,
+ static FileSaveDialog *create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key);
@@ -218,7 +220,8 @@ public:
* @param title the title of the dialog
* @param key a list of file types from which the user can select
*/
- static FileExportDialog *create(const Glib::ustring &path,
+ static FileExportDialog *create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &default_key);
diff --git a/src/ui/view/edit-widget-interface.h b/src/ui/view/edit-widget-interface.h
index 1df0bff45..4c9ad8b02 100644
--- a/src/ui/view/edit-widget-interface.h
+++ b/src/ui/view/edit-widget-interface.h
@@ -16,10 +16,11 @@
#ifndef INKSCAPE_UI_VIEW_EDIT_WIDGET_IFACE_H
#define INKSCAPE_UI_VIEW_EDIT_WIDGET_IFACE_H
-#include "gdk/gdktypes.h"
#include "libnr/nr-point.h"
#include "message.h"
+#include <gtkmm/window.h>
+
namespace Inkscape {
namespace UI {
namespace View {
@@ -30,7 +31,7 @@ struct EditWidgetInterface
virtual ~EditWidgetInterface() {}
/// Returns pointer to window UI object as void*
- virtual void *getWindow() = 0;
+ virtual Gtk::Window *getWindow() = 0;
/// Set the widget's title
virtual void setTitle (gchar const*) = 0;
diff --git a/src/ui/view/edit-widget.cpp b/src/ui/view/edit-widget.cpp
index 8e423c8fb..d5b782865 100644
--- a/src/ui/view/edit-widget.cpp
+++ b/src/ui/view/edit-widget.cpp
@@ -178,7 +178,7 @@ void
EditWidget::onActionFileOpen()
{
// g_warning("onActionFileOpen called");
- sp_file_open_dialog (NULL, NULL);
+ sp_file_open_dialog (*this, NULL, NULL);
}
void
@@ -1110,7 +1110,7 @@ EditWidget::initStatusbar()
//========================================
//----------implements EditWidgetInterface
-void *
+Gtk::Window *
EditWidget::getWindow()
{
return this;
@@ -1231,7 +1231,7 @@ EditWidget::shutdown()
{
case Gtk::RESPONSE_YES:
sp_document_ref(doc);
- if (sp_file_save_document(doc)) {
+ if (sp_file_save_document(*this, doc)) {
sp_document_unref(doc);
} else { // save dialog cancelled or save failed
sp_document_unref(doc);
@@ -1279,7 +1279,7 @@ EditWidget::shutdown()
{
case Gtk::RESPONSE_YES:
sp_document_ref(doc);
- if (sp_file_save_document(doc)) {
+ if (sp_file_save_document(*this, doc)) {
sp_document_unref(doc);
} else { // save dialog cancelled or save failed
sp_document_unref(doc);
diff --git a/src/ui/view/edit-widget.h b/src/ui/view/edit-widget.h
index bedb94f98..7f68abcf5 100644
--- a/src/ui/view/edit-widget.h
+++ b/src/ui/view/edit-widget.h
@@ -97,7 +97,7 @@ public:
void onUriChanged();
// from EditWidgetInterface
- virtual void *getWindow();
+ virtual Gtk::Window* getWindow();
virtual void setTitle (gchar const*);
virtual void layout();
virtual void present();
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 5a0540776..a81157ab8 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -790,24 +790,31 @@ FileVerb::perform(SPAction *action, void *data, void *pdata)
Inkscape::UI::View::View *current_view = sp_action_get_view(action);
SPDocument *current_document = current_view->doc();
#endif
+
+ SPDesktop *desktop = dynamic_cast<SPDesktop*>(sp_action_get_view(action));
+ Gtk::Window *parent = NULL;
+ if(desktop == NULL) return;
+ desktop->getToplevel((Gtk::Widget*&)parent);
+ if(parent == NULL) return;
+
switch ((long) data) {
case SP_VERB_FILE_NEW:
sp_file_new_default();
break;
case SP_VERB_FILE_OPEN:
- sp_file_open_dialog(NULL, NULL);
+ sp_file_open_dialog(*parent, NULL, NULL);
break;
case SP_VERB_FILE_REVERT:
sp_file_revert_dialog();
break;
case SP_VERB_FILE_SAVE:
- sp_file_save(NULL, NULL);
+ sp_file_save(*parent, NULL, NULL);
break;
case SP_VERB_FILE_SAVE_AS:
- sp_file_save_as(NULL, NULL);
+ sp_file_save_as(*parent, NULL, NULL);
break;
case SP_VERB_FILE_SAVE_A_COPY:
- sp_file_save_a_copy(NULL, NULL);
+ sp_file_save_a_copy(*parent, NULL, NULL);
break;
case SP_VERB_FILE_PRINT:
sp_file_print();
@@ -822,7 +829,7 @@ FileVerb::perform(SPAction *action, void *data, void *pdata)
sp_file_print_preview(NULL, NULL);
break;
case SP_VERB_FILE_IMPORT:
- sp_file_import(NULL);
+ sp_file_import(*parent);
break;
case SP_VERB_FILE_EXPORT:
sp_file_export_dialog(NULL);
@@ -842,6 +849,7 @@ FileVerb::perform(SPAction *action, void *data, void *pdata)
default:
break;
}
+
} // end of sp_verb_action_file_perform()
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 9716191ed..4dca563aa 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -395,7 +395,8 @@ sp_desktop_widget_destroy (GtkObject *object)
void
SPDesktopWidget::updateTitle(gchar const* uri)
{
- GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
if (window) {
gchar const *fname = ( TRUE
? uri
@@ -414,7 +415,7 @@ SPDesktopWidget::updateTitle(gchar const* uri)
g_string_printf (name, _("%s - Inkscape"), fname);
}
}
- gtk_window_set_title (window, name->str);
+ window->set_title (name->str);
g_string_free (name, TRUE);
}
}
@@ -602,14 +603,19 @@ SPDesktopWidget::shutdown()
switch (response) {
case GTK_RESPONSE_YES:
- sp_document_ref(doc);
- if (sp_file_save_document(doc)) {
+ {
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
+ sp_document_ref(doc);
+ if (sp_file_save_document(*window, doc)) {
sp_document_unref(doc);
} else { // save dialog cancelled or save failed
sp_document_unref(doc);
return TRUE;
}
+
break;
+ }
case GTK_RESPONSE_NO:
break;
default: // cancel pressed, or dialog was closed
@@ -666,14 +672,20 @@ SPDesktopWidget::shutdown()
switch (response) {
case GTK_RESPONSE_YES:
- sp_document_ref(doc);
- if (sp_file_save_dialog(doc)) {
+ {
+ sp_document_ref(doc);
+
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
+ if (sp_file_save_dialog(*window, doc)) {
sp_document_unref(doc);
} else { // save dialog cancelled or save failed
sp_document_unref(doc);
return TRUE;
}
+
break;
+ }
case GTK_RESPONSE_NO:
allow_data_loss = TRUE;
break;
@@ -773,32 +785,35 @@ SPDesktopWidget::getWindowGeometry (gint &x, gint &y, gint &w, gint &h)
{
gboolean vis = GTK_WIDGET_VISIBLE (this);
- GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
if (window)
{
- gtk_window_get_size (window, &w, &h);
- gtk_window_get_position (window, &x, &y);
+ window->get_size (w, h);
+ window->get_position (x, y);
}
}
void
SPDesktopWidget::setWindowPosition (NR::Point p)
{
- GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
if (window)
{
- gtk_window_move (window, gint(round(p[NR::X])), gint(round(p[NR::Y])));
+ window->move (gint(round(p[NR::X])), gint(round(p[NR::Y])));
}
}
void
SPDesktopWidget::setWindowSize (gint w, gint h)
{
- GtkWindow *window = GTK_WINDOW (gtk_object_get_data (GTK_OBJECT(this), "window"));
+ Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
+
if (window)
{
- gtk_window_set_default_size (window, w, h);
- gtk_window_reshow_with_initial_size (window);
+ window->set_default_size (w, h);
+ window->reshow_with_initial_size ();
}
}
@@ -1131,16 +1146,14 @@ sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget
}
/* we make the desktop window with focus active, signal is connected in interface.c */
-
-gint
-sp_desktop_widget_set_focus (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
+bool SPDesktopWidget::onFocusInEvent(GdkEventFocus*)
{
- inkscape_activate_desktop (dtw->desktop);
+ inkscape_activate_desktop (desktop);
/* give focus to canvas widget */
- gtk_widget_grab_focus (GTK_WIDGET (dtw->canvas));
-
- return FALSE;
+ gtk_widget_grab_focus (GTK_WIDGET (canvas));
+
+ return false;
}
static gdouble
diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h
index ef70a21d1..fbd350b12 100644
--- a/src/widgets/desktop-widget.h
+++ b/src/widgets/desktop-widget.h
@@ -32,8 +32,6 @@ GtkType sp_desktop_widget_get_type();
void sp_desktop_widget_destroy (SPDesktopWidget* dtw);
-gint sp_desktop_widget_set_focus(GtkWidget *widget, GdkEvent *event, 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);
@@ -66,7 +64,7 @@ struct SPDesktopWidget {
SPDesktop *desktop;
- GtkWindow *window;
+ Gtk::Window *window;
// The root vbox of the window layout.
GtkWidget *vbox;
@@ -113,7 +111,7 @@ struct SPDesktopWidget {
virtual void setTitle (gchar const *uri)
{ _dtw->updateTitle (uri); }
- virtual void* getWindow()
+ virtual Gtk::Window* getWindow()
{ return _dtw->window; }
virtual void layout()
{ sp_desktop_widget_layout (_dtw); }
@@ -138,7 +136,11 @@ struct SPDesktopWidget {
virtual bool shutdown()
{ return _dtw->shutdown(); }
virtual void destroy()
- { gtk_widget_destroy (static_cast<GtkWidget*>((void*)(_dtw->window)));}
+ {
+ if(_dtw->window != NULL)
+ delete _dtw->window;
+ _dtw->window = NULL;
+ }
virtual void requestCanvasUpdate()
{ _dtw->requestCanvasUpdate(); }
@@ -202,6 +204,8 @@ struct SPDesktopWidget {
void enableInteraction();
void disableInteraction();
void updateTitle(gchar const *uri);
+
+ bool onFocusInEvent(GdkEventFocus*);
};
/// The SPDesktopWidget vtable