desktop-widget.cpp revision 385709d739bf6cc29c933d533868f011ebc9fd73
#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 "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/widget/selected-style.h"
#include "sp-item.h"
#include "dialogs/swatches.h"
#include "conn-avoid-ref.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);
void
{
// make sure the important messages are displayed immediately!
}
// FIXME: TODO: remove <b></b> before displaying as tooltip
}
{
gint x,y;
}
/**
* Registers SPDesktopWidget class and returns its type number.
*/
sp_desktop_widget_get_type (void)
{
if (!type) {
static const GtkTypeInfo info = {
"SPDesktopWidget",
sizeof (SPDesktopWidget),
sizeof (SPDesktopWidgetClass),
};
}
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 (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 (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 (tbl), dtw->hscrollbar, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_FILL), 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 (tbl), dtw->vscrollbar_box, 2, 3, 0, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
/* Canvas */
gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
// 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);
#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
{
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 {
}
}
}
}
/**
* 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;
/* 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;
}
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
{
"Document modified");
/** \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."),
/** \todo
* FIXME !!! Gtk 2.3+ gives us gtk_message_dialog_set_markup()
* (and actually even
* gtk_message_dialog_new_with_markup(..., format, ...)!) --
* until then, we will have to be a little bit evil here and
* poke at GtkMessageDialog::label, which is private...
*/
switch (response) {
case GTK_RESPONSE_YES:
if (sp_file_save_document(doc)) {
} 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) {
"Document modified");
/** \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 in another format?"),
Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name());
/** \todo
* FIXME !!! Gtk 2.3+ gives us gtk_message_dialog_set_markup()
* (and actually even
* gtk_message_dialog_new_with_markup(..., format, ...)!) --
* until then, we will have to be a little bit evil here and
* poke at GtkMessageDialog::label, which is private...
*/
switch (response) {
case GTK_RESPONSE_YES:
if (sp_file_save_dialog(doc)) {
} 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;
}
}
}
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
{
if (window)
{
gtk_window_get_size (window, &w, &h);
gtk_window_get_position (window, &x, &y);
}
}
void
{
if (window)
{
}
}
void
{
if (window)
{
gtk_window_set_default_size (window, 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,
text);
if (response == GTK_RESPONSE_YES)
return true;
}
return false;
}
void
{
#ifdef HAVE_GTK_WINDOW_FULLSCREEN
if (GTK_IS_WINDOW(topw)) {
} else {
}
}
#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
{
}
}
bool
{
return gtk_toggle_button_get_active (b) != 0;
}
{
// 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
{
}
static void
{
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
}
static void
{
return;
}
/* we make the desktop window with focus active, signal is connected in interface.c */
{
/* give focus to canvas widget */
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];
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);
}
}
/* 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 :