Commit 479e65e3 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

improved handling of parent widget; probably just being paranoid here.

2004-10-13  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpmessagedialog.c: improved handling of parent
	widget; probably just being paranoid here.

	* app/actions/image-commands.c
	* app/dialogs/image-new-dialog.c: ported memory size confirmation
	dialogs to GimpMessageDialog.
parent 3eb00e03
2004-10-13 Sven Neumann <sven@gimp.org>
* app/widgets/gimpmessagedialog.c: improved handling of parent
widget; probably just being paranoid here.
* app/actions/image-commands.c
* app/dialogs/image-new-dialog.c: ported memory size confirmation
dialogs to GimpMessageDialog.
2004-10-13 DindinX <dindinx@gimp.org>
* libgimpwidgets/gimppreview.[ch]: added a new function to set the
......
......@@ -46,6 +46,8 @@
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
......@@ -79,8 +81,6 @@ typedef struct _LayerMergeOptions LayerMergeOptions;
struct _LayerMergeOptions
{
GtkWidget *query_box;
GimpContext *context;
GimpImage *gimage;
GimpMergeType merge_type;
......@@ -89,20 +89,21 @@ struct _LayerMergeOptions
/* local function prototypes */
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_warn (ImageResizeOptions *options,
const gchar *warning_title,
const gchar *warning_message);
static void image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data);
static void image_scale_implement (ImageResizeOptions *options);
static void image_merge_layers_response (GtkWidget *widget,
gint response_id,
LayerMergeOptions *options);
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_confirm_large (ImageResizeOptions *options,
gint64 new_memsize,
gint64 max_memsize);
static void image_scale_confirm_small (ImageResizeOptions *options);
static void image_scale_confirm_response (GtkWidget *widget,
gint response_id,
ImageResizeOptions *options);
static void image_scale_implement (ImageResizeOptions *options);
static void image_merge_layers_response (GtkWidget *dialog,
gint response_id,
LayerMergeOptions *options);
/* public functions */
......@@ -370,6 +371,7 @@ image_merge_layers_cmd_callback (GtkAction *action,
{
LayerMergeOptions *options;
GimpImage *gimage;
GtkWidget *dialog;
GtkWidget *widget;
GtkWidget *frame;
return_if_no_image (gimage, data);
......@@ -381,28 +383,24 @@ image_merge_layers_cmd_callback (GtkAction *action,
options->gimage = gimage;
options->merge_type = GIMP_EXPAND_AS_NECESSARY;
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
_("Merge Layers"), "gimp-image-merge-layers",
GIMP_STOCK_MERGE_DOWN,
_("Layers Merge Options"),
widget,
gimp_standard_help_func,
GIMP_HELP_IMAGE_MERGE_LAYERS,
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
_("Merge Layers"),
"gimp-image-merge-layers",
GIMP_STOCK_MERGE_DOWN,
_("Layers Merge Options"),
widget,
gimp_standard_help_func,
GIMP_HELP_IMAGE_MERGE_LAYERS,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
NULL);
g_signal_connect (options->query_box, "response",
g_signal_connect (dialog, "response",
G_CALLBACK (image_merge_layers_response),
options);
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free,
options);
frame = gimp_int_radio_group_new (TRUE, _("Final, Merged Layer should be:"),
G_CALLBACK (gimp_radio_button_update),
&options->merge_type, options->merge_type,
......@@ -419,11 +417,10 @@ image_merge_layers_cmd_callback (GtkAction *action,
NULL);
gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
frame);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), frame);
gtk_widget_show (frame);
gtk_widget_show (options->query_box);
gtk_widget_show (dialog);
}
void
......@@ -528,38 +525,11 @@ image_scale_callback (GtkWidget *widget,
switch (scale_check)
{
case GIMP_IMAGE_SCALE_TOO_BIG:
{
gchar *size_str;
gchar *max_size_str;
gchar *warning_message;
size_str = gimp_memsize_to_string (new_memsize);
max_size_str = gimp_memsize_to_string (max_memsize);
warning_message = g_strdup_printf
(_("You are trying to create an image with a size of %s.\n\n"
"Choose OK to create this image anyway.\n"
"Choose Cancel if you did not intend to create such a "
"large image.\n\n"
"To prevent this dialog from appearing, increase the "
"\"Maximum Image Size\" setting (currently %s) in the "
"Preferences dialog."),
size_str, max_size_str);
g_free (size_str);
g_free (max_size_str);
image_scale_warn (options, _("Image exceeds maximum image size"),
warning_message);
g_free (warning_message);
}
image_scale_confirm_large (options, new_memsize, max_memsize);
break;
case GIMP_IMAGE_SCALE_TOO_SMALL:
image_scale_warn (options, _("Layer Too Small"),
_("The chosen image size will shrink some layers "
"completely away. Is this what you want?"));
image_scale_confirm_small (options);
break;
case GIMP_IMAGE_SCALE_OK:
......@@ -570,35 +540,78 @@ image_scale_callback (GtkWidget *widget,
}
}
static void
image_scale_warn (ImageResizeOptions *options,
const gchar *warning_title,
const gchar *warning_message)
static GtkWidget *
image_scale_confirm_dialog (ImageResizeOptions *options)
{
GtkWidget *dialog;
dialog = gimp_query_boolean_box (warning_title,
options->dialog->shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_DIALOG_QUESTION,
warning_message,
GTK_STOCK_OK, GTK_STOCK_CANCEL,
G_OBJECT (options->dialog->shell),
"destroy",
image_scale_warn_callback,
options);
dialog = gimp_message_dialog_new (_("Confirm Scaling"),
GIMP_STOCK_WARNING,
options->dialog->shell,
GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GIMP_STOCK_SCALE, GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (image_scale_confirm_response),
options);
return dialog;
}
static void
image_scale_confirm_large (ImageResizeOptions *options,
gint64 new_memsize,
gint64 max_memsize)
{
GtkWidget *dialog = image_scale_confirm_dialog (options);
gchar *size;
size = gimp_memsize_to_string (new_memsize);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("You are trying to create an image "
"with a size of %s."), size);
g_free (size);
size = gimp_memsize_to_string (max_memsize);
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Scaling the image to the choosen size will "
"make it use more memory than what is "
"configured as \"Maximum Image Size\" in the "
"Preferences dialog (currently %s)."), size);
g_free (size);
gtk_widget_show (dialog);
}
static void
image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data)
image_scale_confirm_small (ImageResizeOptions *options)
{
ImageResizeOptions *options = data;
GtkWidget *dialog = image_scale_confirm_dialog (options);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Scaling the image to the choosen size "
"will shrink some layers completely "
"away."));
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Is this what you want to do?"));
gtk_widget_show (dialog);
}
if (do_scale)
static void
image_scale_confirm_response (GtkWidget *dialog,
gint response_id,
ImageResizeOptions *options)
{
gtk_widget_destroy (dialog);
if (response_id == GTK_RESPONSE_OK)
{
image_scale_implement (options);
gtk_widget_destroy (options->dialog->shell);
......@@ -663,10 +676,12 @@ image_scale_implement (ImageResizeOptions *options)
}
static void
image_merge_layers_response (GtkWidget *widget,
image_merge_layers_response (GtkWidget *dialog,
gint response_id,
LayerMergeOptions *options)
{
gtk_widget_destroy (dialog);
if (response_id == GTK_RESPONSE_OK)
{
gimp_image_merge_visible_layers (options->gimage,
......@@ -675,5 +690,5 @@ image_merge_layers_response (GtkWidget *widget,
gimp_image_flush (options->gimage);
}
gtk_widget_destroy (options->query_box);
g_free (options);
}
......@@ -39,6 +39,8 @@
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "widgets/gimptemplateeditor.h"
#include "image-new-dialog.h"
......@@ -233,63 +235,67 @@ image_new_template_select (GimpContainerView *view,
/* the confirm dialog */
static void
image_new_confirm_dialog_callback (GtkWidget *widget,
gboolean create,
gpointer data)
image_new_confirm_response (GtkWidget *dialog,
gint response_id,
ImageNewDialog *data)
{
ImageNewDialog *dialog = data;
gtk_widget_destroy (dialog);
dialog->confirm_dialog = NULL;
data->confirm_dialog = NULL;
if (create)
image_new_create_image (dialog);
if (response_id == GTK_RESPONSE_OK)
image_new_create_image (data);
else
gtk_widget_set_sensitive (dialog->dialog, TRUE);
gtk_widget_set_sensitive (data->dialog, TRUE);
}
static void
image_new_confirm_dialog (ImageNewDialog *dialog)
image_new_confirm_dialog (ImageNewDialog *data)
{
gchar *size_str;
gchar *max_size_str;
gchar *text;
size_str = gimp_memsize_to_string (dialog->template->initial_size);
max_size_str = gimp_memsize_to_string (GIMP_GUI_CONFIG (dialog->gimp->config)->max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image with "
"an initial size of %s.\n\n"
"Choose OK to create this image anyway.\n"
"Choose Cancel if you did not intend to "
"create such a large image.\n\n"
"To prevent this dialog from appearing, "
"increase the \"Maximum Image Size\" "
"setting (currently %s) in the "
"Preferences dialog."),
size_str, max_size_str);
g_free (size_str);
g_free (max_size_str);
dialog->confirm_dialog =
gimp_query_boolean_box (_("Confirm Image Size"),
dialog->dialog,
gimp_standard_help_func, NULL,
GIMP_STOCK_INFO,
text,
GTK_STOCK_OK, GTK_STOCK_CANCEL,
NULL, NULL,
image_new_confirm_dialog_callback,
dialog);
g_free (text);
gtk_window_set_transient_for (GTK_WINDOW (dialog->confirm_dialog),
GTK_WINDOW (dialog->dialog));
gtk_widget_set_sensitive (dialog->dialog, FALSE);
gtk_widget_show (dialog->confirm_dialog);
GimpGuiConfig *config;
GtkWidget *dialog;
gchar *size;
if (data->confirm_dialog)
{
gtk_window_present (GTK_WINDOW (data->confirm_dialog));
return;
}
data->confirm_dialog =
dialog = gimp_message_dialog_new (_("Confirm Image Size"),
GIMP_STOCK_WARNING,
data->dialog,
GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func, NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (image_new_confirm_response),
data);
size = gimp_memsize_to_string (data->template->initial_size);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("You are trying to create an image "
"with a size of %s."), size);
g_free (size);
config = GIMP_GUI_CONFIG (data->gimp->config);
size = gimp_memsize_to_string (config->max_new_image_size);
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("An image of the choosen size will use more "
"memory than what is configured as "
"\"Maximum Image Size\" in the Preferences "
"dialog (currently %s)."), size);
g_free (size);
gtk_widget_set_sensitive (data->dialog, FALSE);
gtk_widget_show (dialog);
}
static void
......
......@@ -77,12 +77,6 @@ gimp_message_dialog_new (const gchar *title,
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
if (parent)
{
if (! GTK_IS_WINDOW (parent))
parent = gtk_widget_get_toplevel (parent);
}
dialog = g_object_new (GIMP_TYPE_MESSAGE_DIALOG,
"title", title,
"role", "gimp-message-dialog",
......@@ -93,10 +87,22 @@ gimp_message_dialog_new (const gchar *title,
if (parent)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
if (! GTK_IS_WINDOW (parent))
parent = gtk_widget_get_toplevel (parent);
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
if (GTK_IS_WINDOW (parent))
{
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent));
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
}
else
{
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (parent));
}
}
va_start (args, help_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment