desktop-widget.cpp revision c13deb2864f592ee41c14855ec09dca84e13025f
#define __SP_DESKTOP_WIDGET_C__
/** \file
* Desktop widget implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
* bulia byak <buliabyak@users.sf.net>
* Ralf Stephan <ralf@ark.in-berlin.de>
* John Bintz <jcoswell@coswellproductions.org>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
*
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2006 John Bintz
* Copyright (C) 2004 MenTaLguY
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "macros.h"
#include "inkscape-private.h"
#include "desktop-handles.h"
#include "desktop-events.h"
#include "document.h"
#include "desktop-widget.h"
#include "sp-namedview.h"
#include "interface.h"
#include "toolbox.h"
#include "prefs-utils.h"
#include "preferences.h"
#include "file.h"
#include "display/canvas-arena.h"
#include "display/nr-arena.h"
#include "widgets/widget-sizes.h"
#include "widgets/spw-utilities.h"
#include "widgets/spinbutton-events.h"
#include "widgets/layer-selector.h"
#include "ui/dialog/dialog-manager.h"
#include "ui/widget/selected-style.h"
#include "sp-item.h"
#include "dialogs/swatches.h"
#include "conn-avoid-ref.h"
#include "ege-select-one-action.h"
#include "ege-color-prof-tracker.h"
#include "color-profile-fns.h"
#include "xml/node-observer.h"
#include "box3d-context.h"
#include "sp-image.h"
#if defined (SOLARIS_2_8)
#include "round.h"
#endif
#ifdef WITH_INKBOARD
#endif
enum {
};
//---------------------------------------------------------------------
/* SPDesktopWidget */
static void sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw);
public:
PrefWatcher();
virtual ~PrefWatcher();
private:
};
PrefWatcher::PrefWatcher() :
NodeObserver(),
dtws(),
_tracker(0)
{
}
{
}
void PrefWatcher::hook(EgeColorProfTracker */*tracker*/, gint screen, gint monitor, PrefWatcher */*watcher*/)
{
#if ENABLE_LCMS
unsigned char* buf = 0;
#endif // ENABLE_LCMS
}
{
}
{
}
{
#if ENABLE_LCMS
(void)name;
bool refresh = false;
if ( !id ) {
// bad
}
}
refresh = true;
refresh = true;
}
if ( refresh ) {
(*it)->requestCanvasUpdate();
}
}
#else
{
(void)node;
(void)name;
#endif // ENABLE_LCMS
}
}
static PrefWatcher* watcher = 0;
void
{
// make sure the important messages are displayed immediately!
}
}
{
gint x,y;
}
/**
* Registers SPDesktopWidget class and returns its type number.
*/
{
if (!type) {
sizeof(SPDesktopWidgetClass),
0, // base_init
0, // base_finalize
0, // class_finalize
0, // class_data
sizeof(SPDesktopWidget),
0, // n_preallocs
0 // value_table
};
type = g_type_register_static(SP_TYPE_VIEW_WIDGET, "SPDesktopWidget", &info, static_cast<GTypeFlags>(0));
}
return type;
}
/**
* SPDesktopWidget vtable initialization
*/
static void
{
}
/**
* Callback for SPDesktopWidget object initialization.
*/
static void
{
/* Main table */
//gtk_widget_set_usize (dtw->statusbar, -1, BOTTOM_BAR_HEIGHT);
{
}
/* Horizontal ruler */
eventbox = gtk_event_box_new ();
gtk_tooltips_set_tip (dtw->tt, dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), widget->style->xthickness, 0);
g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_hruler_event), dtw);
/* Vertical ruler */
eventbox = gtk_event_box_new ();
gtk_tooltips_set_tip (dtw->tt, dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 0, 1, 1, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), 0, widget->style->ythickness);
g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_vruler_event), dtw);
g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_vruler_event), dtw);
/* Horizontal scrollbar */
gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_SHRINK), 0, 0);
/* Vertical scrollbar and the sticky zoom button */
NULL,
"sticky_zoom",
_("Zoom drawing if window size changes"),
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dtw->sticky_zoom), prefs_get_int_attribute ("options.stickyzoom", "value", 0));
gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_FILL), 0, 0);
if ( verb ) {
}
}
NULL,
"color_management",
tip,
#if ENABLE_LCMS
{
if ( enabled ) {
long long int active = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
if ( active ) {
}
}
}
g_signal_connect_after( G_OBJECT(dtw->cms_adjust), "clicked", G_CALLBACK(cms_adjust_toggled), dtw );
#else
#endif // ENABLE_LCMS
gtk_table_attach( GTK_TABLE(canvas_tbl), dtw->cms_adjust, 2, 3, 2, 3, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_SHRINK), 0, 0);
{
if ( prefs ) {
if (!watcher) {
watcher = new PrefWatcher();
}
} else {
g_warning("NULL preferences instance encountered");
}
}
/* Canvas */
#if ENABLE_LCMS
dtw->canvas->enable_cms_display_adj = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 ) != 0;
#endif // ENABLE_LCMS
gtk_widget_set_extension_events(GTK_WIDGET (dtw->canvas) , GDK_EXTENSION_EVENTS_ALL); //set extension events for tablets, unless disabled in preferences
gtk_table_attach (GTK_TABLE (canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0);
/* Dock */
bool create_dock =
prefs_get_int_attribute_limited ("options.dialogtype", "value", Inkscape::UI::Dialog::FLOATING, 0, 1) ==
if (create_dock) {
/* Prevent the paned from catching F6 and F8 by unsetting the default callbacks */
}
gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (paned->gobj()), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
} else {
gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
}
// connect scrollbar signals
g_signal_connect (G_OBJECT (dtw->hadj), "value-changed", G_CALLBACK (sp_desktop_widget_adjustment_value_changed), dtw);
g_signal_connect (G_OBJECT (dtw->vadj), "value-changed", G_CALLBACK (sp_desktop_widget_adjustment_value_changed), dtw);
// zoom status spinbutton
dtw->zoom_status = gtk_spin_button_new_with_range (log(SP_DESKTOP_ZOOM_MIN)/log(2), log(SP_DESKTOP_ZOOM_MAX)/log(2), 0.1);
gtk_signal_connect (GTK_OBJECT (dtw->zoom_status), "focus-in-event", GTK_SIGNAL_FUNC (spinbutton_focus_in), dtw->zoom_status);
gtk_signal_connect (GTK_OBJECT (dtw->zoom_status), "key-press-event", GTK_SIGNAL_FUNC (spinbutton_keypress), dtw->zoom_status);
dtw->zoom_update = g_signal_connect (G_OBJECT (dtw->zoom_status), "value_changed", G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
dtw->zoom_update = g_signal_connect (G_OBJECT (dtw->zoom_status), "populate_popup", G_CALLBACK (sp_dtw_zoom_populate_popup), dtw);
// cursor coordinates
gtk_table_attach(GTK_TABLE(dtw->coord_status), gtk_vseparator_new(), 0,1, 0,2, GTK_FILL, GTK_FILL, 0, 0);
eventbox = gtk_event_box_new ();
gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_x, 2,3, 0,1, GTK_FILL, GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_y, 2,3, 1,2, GTK_FILL, GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(dtw->coord_status), gtk_label_new("Z:"), 3,4, 0,2, GTK_FILL, GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->zoom_status, 4,5, 0,2, GTK_FILL, GTK_FILL, 0, 0);
// FIXME: need to unreference on container destruction to avoid leak
//dtw->layer_selector->set_size_request(-1, SP_ICON_SIZE_BUTTON);
gtk_box_pack_start(GTK_BOX(dtw->statusbar), GTK_WIDGET(dtw->layer_selector->gobj()), FALSE, FALSE, 1);
#if ENABLE_LCMS
{
bool enabled = false;
}
}
#endif // ENABLE_LCMS
g_signal_connect( G_OBJECT(dtw->_tracker), "changed", G_CALLBACK(sp_dtw_color_profile_event), dtw );
#endif
// display the initial welcome message in the statusbar
gtk_label_set_markup (GTK_LABEL (dtw->select_status), _("<b>Welcome to Inkscape!</b> Use shape or freehand tools to create objects; use selector (arrow) to move or transform them."));
// space label 2 pixels from left edge
}
/**
* Called before SPDesktopWidget destruction.
*/
static void
{
if ( watcher ) {
}
g_signal_handlers_disconnect_by_func(G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK(sp_dtw_zoom_input), dtw);
g_signal_handlers_disconnect_by_func(G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK(sp_dtw_zoom_output), dtw);
g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_populate_popup), dtw);
g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->canvas), (gpointer) G_CALLBACK (sp_desktop_widget_event), dtw);
}
}
}
/**
* Set the title in the desktop-window (if desktop has an own window).
*
* The title has form file name: desktop number - Inkscape.
* The desktop number is only shown if it's 2 or higher,
*/
void
{
if (window) {
? uri
: g_basename(uri) );
} else {
}
} else {
} else {
}
}
}
}
{
return dock;
}
/**
* Callback to allocate space for desktop widget.
*/
static void
{
return;
}
if (GTK_WIDGET_REALIZED (widget)) {
}
/* Calculate zoom per pixel */
/* Find new visible area */
/* Calculate adjusted zoom */
} else {
}
} else {
}
// this->size_allocate (widget, allocation);
}
}
/**
* Callback to realize desktop widget.
*/
static void
{
NRRect d;
d.x0 = 0.0;
d.y0 = 0.0;
}
/* This is just to provide access to common functionality from sp_desktop_widget_realize() above
as well as from SPDesktop::change_document() */
void
/* Listen on namedview modification */
// originally (prior to the sigc++ conversion) the signal was simply
// connected twice rather than disconnecting the first connection
dtw->modified_connection = dtw->desktop->namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
}
/**
* Callback to handle desktop widget event.
*/
static gint
{
// defocus any spinbuttons
}
} else {
}
}
} else {
// The keypress events need to be passed to desktop handler explicitly,
// because otherwise the event contexts only receive keypresses when the mouse cursor
// is over the canvas. This redirection is only done for keypresses and only if there's no
// current item on the canvas, because item events and all mouse events are caught
// and passed on by the canvas acetate (I think). --bb
}
}
return FALSE;
}
{
#if ENABLE_LCMS
// Handle profile changes
gint monitor = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_toplevel(GTK_WIDGET(dtw))->window);
bool enabled = false;
}
#endif // ENABLE_LCMS
}
{
#if ENABLE_LCMS
}
#endif // ENABLE_LCMS
}
{
if ( verb ) {
if ( act ) {
}
}
}
void
{
/* update active desktop indicator */
}
void
{
/* update inactive desktop indicator */
}
/**
* Shuts down the desktop object for the view being closed. It checks
* to see if the document has been edited, and if so prompts the user
* to save, discard, or cancel. Returns TRUE if the shutdown operation
* is cancelled or if the save is cancelled or fails, FALSE otherwise.
*/
bool
{
if (doc->isModifiedSinceSave()) {
/** \todo
* FIXME !!! obviously this will have problems if the document
* name contains markup characters
*/
_("<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
"If you close without saving, your changes will be discarded."),
// fix for bug 1767940:
switch (response) {
case GTK_RESPONSE_YES:
{
} else { // save dialog cancelled or save failed
return TRUE;
}
break;
}
case GTK_RESPONSE_NO:
break;
default: // cancel pressed, or dialog was closed
return TRUE;
break;
}
}
/* Code to check data loss */
bool allow_data_loss = FALSE;
while (sp_document_repr_root(doc)->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
/** \todo
* FIXME !!! obviously this will have problems if the document
* name contains markup characters
*/
_("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\n\n"
"Do you want to save this file as an Inkscape SVG?"),
Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name());
// fix for bug 1767940:
switch (response) {
case GTK_RESPONSE_YES:
{
} else { // save dialog cancelled or save failed
return TRUE;
}
break;
}
case GTK_RESPONSE_NO:
break;
default: // cancel pressed, or dialog was closed
return TRUE;
break;
}
}
}
/* Save window geometry to prefs for use as a default.
* Use depends on setting of "options.savewindowgeometry".
* But we save the info here regardless of the setting.
*/
{
gint w, h, x, y;
desktop->getWindowGeometry(x, y, w, h);
// Don't save geom for maximized windows. It
// just tells you the current maximized size, which is not
// as useful as whatever value it had previously.
}
}
return FALSE;
}
/**
* \pre this->desktop->main != 0
*/
void
}
void
while (gtk_events_pending())
}
void
{
if (_interaction_disabled_counter == 0) {
}
}
void
{
if (_interaction_disabled_counter == 0) {
}
}
void
{
}
void
{
if (zoom_status)
}
void
{
(void)vis; // TODO figure out why it is here but not used.
if (window)
{
window->get_position (x, y);
}
}
void
{
if (window)
{
}
}
void
{
if (window)
{
window->set_default_size (w, h);
}
}
/**
* \note transientizing does not work on windows; when you minimize a document
* and then open it back, only its transient emerges and you cannot access
* the document window. The document window must be restored by rightclicking
* the taskbar button and pressing "Restore"
*/
void
{
if (w)
{
gtk_window_set_transient_for (GTK_WINDOW(p), w);
/*
* This enables "aggressive" transientization,
* i.e. dialogs always emerging on top when you switch documents. Note
* however that this breaks "click to raise" policy of a window
* manager because the switched-to document will be raised at once
* (so that its transients also could raise)
*/
if (transient_policy == 2)
// without this, a transient window not always emerges on top
gtk_window_present (w);
}
}
void
{
if (w)
gtk_window_present (w);
}
bool
{
if (w)
{
w,
"%s", text);
if (response == GTK_RESPONSE_YES)
return true;
}
return false;
}
void
{
if (GTK_IS_WINDOW(topw)) {
} else {
}
}
}
void
{
if (GTK_IS_WINDOW(topw)) {
} else {
// Save geometry to prefs before maximizing so that
// something useful is stored there, because GTK doesn't maintain
// a separate non-maximized size.
{
gint w, h, x, y;
dtw->getWindowGeometry(x, y, w, h);
}
}
}
}
void
{
#ifdef HAVE_GTK_WINDOW_FULLSCREEN
if (GTK_IS_WINDOW(topw)) {
// widget layout is triggered by the resulting window_state_event
} else {
// Save geometry to prefs before maximizing so that
// something useful is stored there, because GTK doesn't maintain
// a separate non-maximized size.
{
gint w, h, x, y;
dtw->getWindowGeometry(x, y, w, h);
}
// widget layout is triggered by the resulting window_state_event
}
}
#endif /* HAVE_GTK_WINDOW_FULLSCREEN */
}
/**
* Hide whatever the user does not want to see in the window
*/
void
{
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.commands" : "window.commands", "state", 1) == 0) {
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.toppanel" : "window.toppanel", "state", 1) == 0) {
} else {
// we cannot just show_all because that will show all tools' panels;
// this is a function from toolbox.cpp that shows only the current tool's panel
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.toolbox" : "window.toolbox", "state", 1) == 0) {
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.statusbar" : "window.statusbar", "state", 1) == 0) {
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.panels" : "window.panels", "state", 1) == 0) {
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1) == 0) {
} else {
}
if (prefs_get_int_attribute (fullscreen ? "fullscreen.rulers" : "window.rulers", "state", 1) == 0) {
} else {
}
}
void
{
{
}
}
void
{
}
}
void
{
if (hb) {
}
}
bool
{
bool isActive = false;
if ( !thing ) {
//g_message( "Unable to locate item for {%s}", id );
} else if ( GTK_IS_TOGGLE_BUTTON(thing) ) {
isActive = gtk_toggle_button_get_active( b ) != 0;
} else if ( GTK_IS_TOGGLE_ACTION(thing) ) {
} else {
//g_message( "Item for {%s} is of an unsupported type", id );
}
return isActive;
}
{
// Add the shape geometry to libavoid for autorouting connectors.
// This needs desktop set for its spacing preferences.
/* Once desktop is set, we can update rulers */
/* Listen on namedview modification */
dtw->modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
return SP_VIEW_WIDGET (dtw);
}
void
{
/// \todo fixme:
}
void
{
}
void
{
/* The viewbox (in integers) must exactly match the size of SPCanvasbuf's pixel buffer.
* This is important because the former is being used for drawing the ruler, whereas
* the latter is used for drawing e.g. the grids and guides. Only when the viewbox
* coincides with the pixel buffer, everything will line up nicely.
*/
}
void
{
/* The viewbox (in integers) must exactly match the size of SPCanvasbuf's pixel buffer.
* This is important because the former is being used for drawing the ruler, whereas
* the latter is used for drawing e.g. the grids and guides. Only when the viewbox
* coincides with the pixel buffer, everything will line up nicely.
*/
}
static void
{
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
}
static void
{
return;
/* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
}
/* we make the desktop window with focus active, signal is connected in interface.c */
{
{
}
}
return false;
}
static gdouble
{
}
static gdouble
{
}
static gint
{
if (sp_dtw_zoom_value_to_display (new_scrolled) == new_typed) { // the new value is set by scrolling
*new_val = new_scrolled;
} else { // the new value is typed in
}
return TRUE;
}
static bool
{
gchar b[64];
if (val < 10) {
} else {
}
return TRUE;
}
static void
{
}
static void
{
}
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
static void
{
}
void
{
g_signal_handlers_block_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (dtw->zoom_status), log(dtw->desktop->current_zoom()) / log(2));
g_signal_handlers_unblock_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
}
void
{
prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 0);
} else {
prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 1);
}
}
void
{
prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 0);
} else {
prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1);
}
}
{
} else {
}
}
}
/* Unused
void
sp_spw_toggle_menubar (SPDesktopWidget *dtw, bool is_fullscreen)
{
if (GTK_WIDGET_VISIBLE (dtw->menubar)) {
gtk_widget_hide_all (dtw->menubar);
prefs_set_int_attribute (is_fullscreen ? "fullscreen.menu" : "window.menu", "state", 0);
} else {
gtk_widget_show_all (dtw->menubar);
prefs_set_int_attribute (is_fullscreen ? "fullscreen.menu" : "window.menu", "state", 1);
}
}
*/
static void
{
}
}
void
{
if (!dtw) return;
/* The desktop region we always show unconditionally */
/* Canvas region we always show unconditionally */
/* Viewbox is always included into scrollable region */
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :