2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-10-10 23:59:12 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpsessioninfo.c
|
2008-05-17 00:06:42 +08:00
|
|
|
* Copyright (C) 2001-2008 Michael Natterer <mitch@gimp.org>
|
2003-10-10 23:59:12 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-10-10 23:59:12 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-10-10 23:59:12 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-10 23:59:12 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "widgets-types.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
#include "gimpdialogfactory.h"
|
|
|
|
#include "gimpdock.h"
|
2009-09-26 20:26:49 +08:00
|
|
|
#include "gimpdockwindow.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
#include "gimpsessioninfo.h"
|
2007-05-25 19:42:28 +08:00
|
|
|
#include "gimpsessioninfo-aux.h"
|
|
|
|
#include "gimpsessioninfo-book.h"
|
|
|
|
#include "gimpsessioninfo-dock.h"
|
2009-09-20 23:06:36 +08:00
|
|
|
#include "gimpsessioninfo-private.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-21 01:08:48 +08:00
|
|
|
#include "gimp-log.h"
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SESSION_INFO_POSITION,
|
|
|
|
SESSION_INFO_SIZE,
|
|
|
|
SESSION_INFO_OPEN,
|
|
|
|
SESSION_INFO_AUX,
|
2007-05-25 04:06:34 +08:00
|
|
|
SESSION_INFO_DOCK
|
2003-10-10 23:59:12 +08:00
|
|
|
};
|
|
|
|
|
2003-11-14 04:57:59 +08:00
|
|
|
#define DEFAULT_SCREEN -1
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-26 20:26:49 +08:00
|
|
|
static void gimp_session_info_config_iface_init (GimpConfigInterface *iface);
|
|
|
|
static void gimp_session_info_finalize (GObject *object);
|
|
|
|
static gint64 gimp_session_info_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
static gboolean gimp_session_info_serialize (GimpConfig *config,
|
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean gimp_session_info_deserialize (GimpConfig *config,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean gimp_session_info_is_for_dock_window (GimpSessionInfo *info);
|
2008-05-17 00:06:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpSessionInfo, gimp_session_info, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
|
|
|
gimp_session_info_config_iface_init))
|
2008-05-14 05:17:11 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_session_info_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_session_info_class_init (GimpSessionInfoClass *klass)
|
2007-05-25 03:22:06 +08:00
|
|
|
{
|
2008-05-14 05:17:11 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_session_info_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_session_info_get_memsize;
|
2009-09-20 23:06:36 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GimpSessionInfoPrivate));
|
2007-05-25 03:22:06 +08:00
|
|
|
}
|
|
|
|
|
2008-05-14 05:17:11 +08:00
|
|
|
static void
|
|
|
|
gimp_session_info_init (GimpSessionInfo *info)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p = G_TYPE_INSTANCE_GET_PRIVATE (info,
|
|
|
|
GIMP_TYPE_SESSION_INFO,
|
|
|
|
GimpSessionInfoPrivate);
|
|
|
|
info->p->screen = DEFAULT_SCREEN;
|
2008-05-17 00:06:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_session_info_config_iface_init (GimpConfigInterface *iface)
|
|
|
|
{
|
|
|
|
iface->serialize = gimp_session_info_serialize;
|
|
|
|
iface->deserialize = gimp_session_info_deserialize;
|
2008-05-14 05:17:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_session_info_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpSessionInfo *info = GIMP_SESSION_INFO (object);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-14 07:43:57 +08:00
|
|
|
gimp_session_info_clear_info (info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-14 05:17:11 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
gimp_session_info_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
GimpSessionInfo *info = GIMP_SESSION_INFO (object);
|
|
|
|
#endif
|
|
|
|
gint64 memsize = 0;
|
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_session_info_serialize (GimpConfig *config,
|
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2008-05-17 00:06:42 +08:00
|
|
|
GimpSessionInfo *info = GIMP_SESSION_INFO (config);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
gimp_config_writer_open (writer, "position");
|
2009-09-20 23:06:36 +08:00
|
|
|
gimp_config_writer_printf (writer, "%d %d", info->p->x, info->p->y);
|
2003-10-10 23:59:12 +08:00
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->width > 0 && info->p->height > 0)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, "size");
|
2009-09-20 23:06:36 +08:00
|
|
|
gimp_config_writer_printf (writer, "%d %d", info->p->width, info->p->height);
|
2003-10-10 23:59:12 +08:00
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->open)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
|
|
|
gimp_config_writer_open (writer, "open-on-exit");
|
2003-11-14 04:57:59 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->screen != DEFAULT_SCREEN)
|
|
|
|
gimp_config_writer_printf (writer, "%d", info->p->screen);
|
2003-11-14 04:57:59 +08:00
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
}
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->aux_info)
|
|
|
|
gimp_session_info_aux_serialize (writer, info->p->aux_info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->books)
|
|
|
|
gimp_session_info_dock_serialize (writer, info->p->books);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
return TRUE;
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
2008-03-22 09:10:51 +08:00
|
|
|
/*
|
|
|
|
* This function is just like gimp_scanner_parse_int(), but it is allows
|
|
|
|
* to detect the special value '-0'. This is used as in X geometry strings.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
gimp_session_info_parse_offset (GScanner *scanner,
|
|
|
|
gint *dest,
|
|
|
|
gboolean *negative)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) == '-')
|
|
|
|
{
|
|
|
|
*negative = TRUE;
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*negative = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_INT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
if (*negative)
|
|
|
|
*dest = -scanner->value.v_int64;
|
|
|
|
else
|
|
|
|
*dest = scanner->value.v_int64;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_session_info_deserialize (GimpConfig *config,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2008-05-17 00:06:42 +08:00
|
|
|
GimpSessionInfo *info = GIMP_SESSION_INFO (config);
|
|
|
|
GTokenType token;
|
|
|
|
guint scope_id;
|
|
|
|
guint old_scope_id;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
scope_id = g_type_qname (G_TYPE_FROM_INSTANCE (config));
|
|
|
|
old_scope_id = g_scanner_set_scope (scanner, scope_id);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id, "position",
|
2003-10-10 23:59:12 +08:00
|
|
|
GINT_TO_POINTER (SESSION_INFO_POSITION));
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id, "size",
|
2003-10-10 23:59:12 +08:00
|
|
|
GINT_TO_POINTER (SESSION_INFO_SIZE));
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id, "open-on-exit",
|
2003-10-10 23:59:12 +08:00
|
|
|
GINT_TO_POINTER (SESSION_INFO_OPEN));
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id, "aux-info",
|
2003-10-10 23:59:12 +08:00
|
|
|
GINT_TO_POINTER (SESSION_INFO_AUX));
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id, "dock",
|
2003-10-10 23:59:12 +08:00
|
|
|
GINT_TO_POINTER (SESSION_INFO_DOCK));
|
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
|
|
|
|
{
|
|
|
|
case SESSION_INFO_POSITION:
|
|
|
|
token = G_TOKEN_INT;
|
2008-03-22 09:10:51 +08:00
|
|
|
if (! gimp_session_info_parse_offset (scanner,
|
2009-09-20 23:06:36 +08:00
|
|
|
&info->p->x,
|
|
|
|
&info->p->right_align))
|
2003-10-10 23:59:12 +08:00
|
|
|
goto error;
|
2008-03-22 09:10:51 +08:00
|
|
|
if (! gimp_session_info_parse_offset (scanner,
|
2009-09-20 23:06:36 +08:00
|
|
|
&info->p->y,
|
|
|
|
&info->p->bottom_align))
|
2003-10-10 23:59:12 +08:00
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_SIZE:
|
|
|
|
token = G_TOKEN_INT;
|
2009-09-20 23:06:36 +08:00
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->p->width))
|
2003-10-10 23:59:12 +08:00
|
|
|
goto error;
|
2009-09-20 23:06:36 +08:00
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->p->height))
|
2003-10-10 23:59:12 +08:00
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_OPEN:
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = TRUE;
|
2003-11-13 23:50:23 +08:00
|
|
|
|
2003-11-14 20:05:13 +08:00
|
|
|
/* the screen number is optional */
|
2003-11-14 01:44:41 +08:00
|
|
|
if (g_scanner_peek_next_token (scanner) == G_TOKEN_RIGHT_PAREN)
|
|
|
|
break;
|
|
|
|
|
2003-11-13 23:50:23 +08:00
|
|
|
token = G_TOKEN_INT;
|
2009-09-20 23:06:36 +08:00
|
|
|
if (! gimp_scanner_parse_int (scanner, &info->p->screen))
|
2003-11-13 23:50:23 +08:00
|
|
|
goto error;
|
2003-10-10 23:59:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_AUX:
|
2007-05-25 03:22:06 +08:00
|
|
|
token = gimp_session_info_aux_deserialize (scanner,
|
2009-09-20 23:06:36 +08:00
|
|
|
&info->p->aux_info);
|
2003-10-12 00:50:35 +08:00
|
|
|
if (token != G_TOKEN_LEFT_PAREN)
|
|
|
|
goto error;
|
2003-10-10 23:59:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SESSION_INFO_DOCK:
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->factory_entry)
|
2003-10-10 23:59:12 +08:00
|
|
|
goto error;
|
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_set_scope (scanner, scope_id + 1);
|
|
|
|
token = gimp_session_info_dock_deserialize (scanner, scope_id + 1,
|
2007-05-25 04:06:34 +08:00
|
|
|
info);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
|
|
|
if (token == G_TOKEN_LEFT_PAREN)
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_set_scope (scanner, scope_id);
|
2003-10-10 23:59:12 +08:00
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
error:
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
g_scanner_scope_remove_symbol (scanner, scope_id, "position");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope_id, "size");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope_id, "open-on-exit");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope_id, "aux-info");
|
|
|
|
g_scanner_scope_remove_symbol (scanner, scope_id, "dock");
|
|
|
|
|
|
|
|
g_scanner_set_scope (scanner, old_scope_id);
|
|
|
|
|
|
|
|
return gimp_config_deserialize_return (scanner, token, nest_level);
|
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 17:43:41 +08:00
|
|
|
/**
|
2009-09-26 20:26:49 +08:00
|
|
|
* gimp_session_info_is_for_dock_window:
|
2009-09-20 17:43:41 +08:00
|
|
|
* @info:
|
|
|
|
*
|
|
|
|
* Helper function to determine if the session info is for a dock. It
|
|
|
|
* uses the dialog factory entry state and the associated widget state
|
|
|
|
* if any to determine that.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if session info is for a dock, %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
static gboolean
|
2009-09-26 20:26:49 +08:00
|
|
|
gimp_session_info_is_for_dock_window (GimpSessionInfo *info)
|
2009-09-20 17:43:41 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
gboolean entry_state_for_dock = info->p->factory_entry == NULL;
|
|
|
|
gboolean widget_state_for_dock = (info->p->widget == NULL ||
|
2009-09-26 20:26:49 +08:00
|
|
|
GIMP_IS_DOCK_WINDOW (info->p->widget));
|
2009-09-20 17:43:41 +08:00
|
|
|
|
|
|
|
return entry_state_for_dock && widget_state_for_dock;
|
|
|
|
}
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpSessionInfo *
|
|
|
|
gimp_session_info_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_SESSION_INFO, NULL);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_restore (GimpSessionInfo *info,
|
|
|
|
GimpDialogFactory *factory)
|
|
|
|
{
|
2003-11-13 23:50:23 +08:00
|
|
|
GdkDisplay *display;
|
2003-11-14 04:57:59 +08:00
|
|
|
GdkScreen *screen = NULL;
|
2003-11-13 23:50:23 +08:00
|
|
|
|
2008-05-14 05:29:00 +08:00
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
2003-10-10 23:59:12 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory));
|
|
|
|
|
2003-11-13 23:50:23 +08:00
|
|
|
display = gdk_display_get_default ();
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->screen != DEFAULT_SCREEN)
|
|
|
|
screen = gdk_display_get_screen (display, info->p->screen);
|
2003-11-13 23:50:23 +08:00
|
|
|
|
|
|
|
if (! screen)
|
|
|
|
screen = gdk_display_get_default_screen (display);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = FALSE;
|
|
|
|
info->p->screen = DEFAULT_SCREEN;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->factory_entry && ! info->p->factory_entry->dockable)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2009-09-21 01:08:48 +08:00
|
|
|
GIMP_LOG (DIALOG_FACTORY, "restoring toplevel \"%s\" (info %p)",
|
|
|
|
info->p->factory_entry->identifier,
|
|
|
|
info);
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
dialog =
|
2003-11-13 23:50:23 +08:00
|
|
|
gimp_dialog_factory_dialog_new (factory, screen,
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->factory_entry->identifier,
|
|
|
|
info->p->factory_entry->view_size,
|
2004-09-01 06:41:15 +08:00
|
|
|
TRUE);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (dialog && info->p->aux_info)
|
|
|
|
gimp_session_info_aux_set_list (dialog, info->p->aux_info);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-21 01:08:48 +08:00
|
|
|
GIMP_LOG (DIALOG_FACTORY, "restoring dock (info %p)",
|
|
|
|
info);
|
|
|
|
|
2007-05-25 04:06:34 +08:00
|
|
|
gimp_session_info_dock_restore (info, factory, screen);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
/* This function mostly lifted from
|
|
|
|
* gtk+/gdk/gdkscreen.c:gdk_screen_get_monitor_at_window()
|
|
|
|
*/
|
2006-04-21 15:02:42 +08:00
|
|
|
static gint
|
2008-03-22 07:54:46 +08:00
|
|
|
gimp_session_info_get_appropriate_monitor (GdkScreen *screen,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2006-04-21 02:41:38 +08:00
|
|
|
{
|
|
|
|
GdkRectangle rect;
|
2006-04-21 15:02:42 +08:00
|
|
|
gint area = 0;
|
|
|
|
gint monitor = -1;
|
|
|
|
gint num_monitors;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.width = w;
|
2006-04-21 02:41:38 +08:00
|
|
|
rect.height = h;
|
|
|
|
|
|
|
|
num_monitors = gdk_screen_get_n_monitors (screen);
|
2006-04-21 15:02:42 +08:00
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
for (i = 0; i < num_monitors; i++)
|
|
|
|
{
|
2006-04-21 15:02:42 +08:00
|
|
|
GdkRectangle geometry;
|
|
|
|
|
|
|
|
gdk_screen_get_monitor_geometry (screen, i, &geometry);
|
|
|
|
|
|
|
|
if (gdk_rectangle_intersect (&rect, &geometry, &geometry) &&
|
|
|
|
geometry.width * geometry.height > area)
|
|
|
|
{
|
|
|
|
area = geometry.width * geometry.height;
|
2006-04-21 02:41:38 +08:00
|
|
|
monitor = i;
|
|
|
|
}
|
|
|
|
}
|
2006-04-21 15:02:42 +08:00
|
|
|
|
2006-04-21 02:41:38 +08:00
|
|
|
if (monitor >= 0)
|
|
|
|
return monitor;
|
|
|
|
else
|
|
|
|
return gdk_screen_get_monitor_at_point (screen,
|
|
|
|
rect.x + rect.width / 2,
|
|
|
|
rect.y + rect.height / 2);
|
|
|
|
}
|
|
|
|
|
2009-09-20 19:13:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_session_info_apply_geometry:
|
|
|
|
* @info:
|
|
|
|
*
|
|
|
|
* Apply the geometry stored in the session info object to the
|
|
|
|
* associated widget.
|
|
|
|
**/
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
2009-09-20 19:13:50 +08:00
|
|
|
gimp_session_info_apply_geometry (GimpSessionInfo *info)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2006-04-21 02:41:38 +08:00
|
|
|
GdkScreen *screen;
|
2008-03-22 07:43:21 +08:00
|
|
|
GdkRectangle rect;
|
2006-04-21 02:41:38 +08:00
|
|
|
gchar geom[32];
|
2008-03-22 07:43:21 +08:00
|
|
|
gint monitor;
|
|
|
|
gboolean use_size;
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-05-14 05:29:00 +08:00
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
2009-09-20 23:06:36 +08:00
|
|
|
g_return_if_fail (GTK_IS_WINDOW (info->p->widget));
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
screen = gtk_widget_get_screen (info->p->widget);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 17:43:41 +08:00
|
|
|
use_size = (gimp_session_info_get_remember_size (info) &&
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->width > 0 &&
|
|
|
|
info->p->height > 0);
|
2008-03-22 07:43:21 +08:00
|
|
|
|
|
|
|
if (use_size)
|
2006-04-21 02:41:38 +08:00
|
|
|
{
|
2008-03-22 07:54:46 +08:00
|
|
|
monitor = gimp_session_info_get_appropriate_monitor (screen,
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->x,
|
|
|
|
info->p->y,
|
|
|
|
info->p->width,
|
|
|
|
info->p->height);
|
2006-04-21 02:41:38 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
monitor = gdk_screen_get_monitor_at_point (screen, info->p->x, info->p->y);
|
2006-04-21 02:41:38 +08:00
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2008-03-22 07:43:21 +08:00
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->x = CLAMP (info->p->x,
|
2008-03-22 09:10:51 +08:00
|
|
|
rect.x,
|
2009-09-20 23:06:36 +08:00
|
|
|
rect.x + rect.width - (info->p->width > 0 ?
|
|
|
|
info->p->width : 128));
|
|
|
|
info->p->y = CLAMP (info->p->y,
|
2008-03-22 09:10:51 +08:00
|
|
|
rect.y,
|
2009-09-20 23:06:36 +08:00
|
|
|
rect.y + rect.height - (info->p->height > 0 ?
|
|
|
|
info->p->height : 128));
|
2008-03-22 07:43:21 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->right_align && info->p->bottom_align)
|
2008-03-22 09:10:51 +08:00
|
|
|
{
|
|
|
|
g_strlcpy (geom, "-0-0", sizeof (geom));
|
2008-03-22 07:43:21 +08:00
|
|
|
}
|
2009-09-20 23:06:36 +08:00
|
|
|
else if (info->p->right_align)
|
2008-03-22 07:43:21 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
g_snprintf (geom, sizeof (geom), "-0%+d", info->p->y);
|
2008-03-22 09:10:51 +08:00
|
|
|
}
|
2009-09-20 23:06:36 +08:00
|
|
|
else if (info->p->bottom_align)
|
2008-03-22 09:10:51 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
g_snprintf (geom, sizeof (geom), "%+d-0", info->p->x);
|
2008-03-22 09:10:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
g_snprintf (geom, sizeof (geom), "%+d%+d", info->p->x, info->p->y);
|
2008-03-22 07:43:21 +08:00
|
|
|
}
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
gtk_window_parse_geometry (GTK_WINDOW (info->p->widget), geom);
|
2008-03-22 07:43:21 +08:00
|
|
|
|
|
|
|
if (use_size)
|
2009-09-20 23:06:36 +08:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (info->p->widget),
|
|
|
|
info->p->width, info->p->height);
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
2009-09-20 19:13:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_session_info_read_geometry:
|
|
|
|
* @info:
|
|
|
|
*
|
|
|
|
* Read geometry related information from the associated widget.
|
|
|
|
**/
|
2003-10-10 23:59:12 +08:00
|
|
|
void
|
2009-09-20 19:13:50 +08:00
|
|
|
gimp_session_info_read_geometry (GimpSessionInfo *info)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
GdkWindow *window;
|
|
|
|
|
2008-05-14 05:29:00 +08:00
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
2009-09-20 23:06:36 +08:00
|
|
|
g_return_if_fail (GTK_IS_WINDOW (info->p->widget));
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
window = gtk_widget_get_window (info->p->widget);
|
2009-03-23 00:35:53 +08:00
|
|
|
|
|
|
|
if (window)
|
2003-10-10 23:59:12 +08:00
|
|
|
{
|
2008-07-23 19:45:39 +08:00
|
|
|
gint x, y;
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gdk_window_get_root_origin (window, &x, &y);
|
2008-07-23 19:45:39 +08:00
|
|
|
|
|
|
|
/* Don't write negative values to the sessionrc, they are
|
|
|
|
* interpreted as relative to the right, respective bottom edge
|
|
|
|
* of the screen.
|
|
|
|
*/
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->x = MAX (0, x);
|
|
|
|
info->p->y = MAX (0, y);
|
2003-10-10 23:59:12 +08:00
|
|
|
|
2009-09-20 17:43:41 +08:00
|
|
|
if (gimp_session_info_get_remember_size (info))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
gdk_drawable_get_size (GDK_DRAWABLE (window),
|
2009-09-20 23:06:36 +08:00
|
|
|
&info->p->width, &info->p->height);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->width = 0;
|
|
|
|
info->p->height = 0;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = FALSE;
|
2004-03-14 02:19:46 +08:00
|
|
|
|
2009-09-20 17:43:41 +08:00
|
|
|
if (gimp_session_info_get_remember_if_open (info))
|
2004-03-14 02:19:46 +08:00
|
|
|
{
|
|
|
|
GimpDialogVisibilityState visibility;
|
|
|
|
|
|
|
|
visibility =
|
2009-09-20 23:06:36 +08:00
|
|
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (info->p->widget),
|
2004-03-14 02:19:46 +08:00
|
|
|
GIMP_DIALOG_VISIBILITY_KEY));
|
|
|
|
|
|
|
|
switch (visibility)
|
|
|
|
{
|
|
|
|
case GIMP_DIALOG_VISIBILITY_UNKNOWN:
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = GTK_WIDGET_VISIBLE (info->p->widget);
|
2004-03-14 02:19:46 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_DIALOG_VISIBILITY_INVISIBLE:
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = FALSE;
|
2004-03-14 02:19:46 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_DIALOG_VISIBILITY_VISIBLE:
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->open = TRUE;
|
2004-03-14 02:19:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 04:57:59 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->screen = DEFAULT_SCREEN;
|
2003-11-14 04:57:59 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->open)
|
2003-11-13 23:50:23 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (info->p->widget);
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen (info->p->widget);
|
2003-11-14 04:57:59 +08:00
|
|
|
|
|
|
|
if (screen != gdk_display_get_default_screen (display))
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->screen = gdk_screen_get_number (screen);
|
2003-11-13 23:50:23 +08:00
|
|
|
}
|
2003-10-10 23:59:12 +08:00
|
|
|
}
|
2008-05-14 07:43:57 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_get_info (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
2009-09-20 23:06:36 +08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (info->p->widget));
|
2008-05-14 07:43:57 +08:00
|
|
|
|
2009-09-20 19:13:50 +08:00
|
|
|
gimp_session_info_read_geometry (info);
|
2008-05-14 07:43:57 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->aux_info = gimp_session_info_aux_get_list (info->p->widget);
|
2008-05-14 07:43:57 +08:00
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->factory_entry == NULL ||
|
|
|
|
(info->p->factory_entry &&
|
|
|
|
info->p->factory_entry->dockable))
|
2009-09-26 20:26:49 +08:00
|
|
|
{
|
|
|
|
GimpDock *dock = NULL;
|
|
|
|
|
|
|
|
dock = gimp_dock_window_get_dock (GIMP_DOCK_WINDOW (info->p->widget));
|
|
|
|
|
|
|
|
info->p->books = gimp_session_info_dock_from_widget (dock);
|
|
|
|
}
|
2008-05-14 07:43:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_clear_info (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->aux_info)
|
2008-05-14 07:43:57 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
g_list_foreach (info->p->aux_info,
|
2008-05-14 07:43:57 +08:00
|
|
|
(GFunc) gimp_session_info_aux_free, NULL);
|
2009-09-20 23:06:36 +08:00
|
|
|
g_list_free (info->p->aux_info);
|
|
|
|
info->p->aux_info = NULL;
|
2008-05-14 07:43:57 +08:00
|
|
|
}
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
if (info->p->books)
|
2008-05-14 07:43:57 +08:00
|
|
|
{
|
2009-09-20 23:06:36 +08:00
|
|
|
g_list_foreach (info->p->books,
|
2008-05-14 07:43:57 +08:00
|
|
|
(GFunc) gimp_session_info_book_free, NULL);
|
2009-09-20 23:06:36 +08:00
|
|
|
g_list_free (info->p->books);
|
|
|
|
info->p->books = NULL;
|
2008-05-14 07:43:57 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-20 17:43:41 +08:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_session_info_is_singleton (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-26 20:26:49 +08:00
|
|
|
return (! gimp_session_info_is_for_dock_window (info) &&
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->factory_entry &&
|
|
|
|
info->p->factory_entry->singleton);
|
2009-09-20 17:43:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_session_info_is_session_managed (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-26 20:26:49 +08:00
|
|
|
return (gimp_session_info_is_for_dock_window (info) ||
|
2009-09-20 23:06:36 +08:00
|
|
|
(info->p->factory_entry &&
|
|
|
|
info->p->factory_entry->session_managed));
|
2009-09-20 17:43:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_session_info_get_remember_size (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-26 20:26:49 +08:00
|
|
|
return (gimp_session_info_is_for_dock_window (info) ||
|
2009-09-20 23:06:36 +08:00
|
|
|
(info->p->factory_entry &&
|
|
|
|
info->p->factory_entry->remember_size));
|
2009-09-20 17:43:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_session_info_get_remember_if_open (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-26 20:26:49 +08:00
|
|
|
return (gimp_session_info_is_for_dock_window (info) ||
|
2009-09-20 23:06:36 +08:00
|
|
|
(info->p->factory_entry &&
|
|
|
|
info->p->factory_entry->remember_if_open));
|
2009-09-20 17:43:41 +08:00
|
|
|
}
|
2009-09-20 20:51:03 +08:00
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_session_info_get_widget (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->widget;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_set_widget (GimpSessionInfo *info,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->widget = widget;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpDialogFactoryEntry *
|
|
|
|
gimp_session_info_get_factory_entry (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->factory_entry;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_session_info_set_factory_entry (GimpSessionInfo *info,
|
|
|
|
GimpDialogFactoryEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
info->p->factory_entry = entry;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_session_info_get_open (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->open;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_session_info_get_x (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->x;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_session_info_get_y (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->y;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_session_info_get_width (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->width;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_session_info_get_height (GimpSessionInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
|
|
|
|
|
2009-09-20 23:06:36 +08:00
|
|
|
return info->p->height;
|
2009-09-20 20:51:03 +08:00
|
|
|
}
|