image-new-dialog.c 21.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
18 19 20

#include "config.h"

Sven Neumann's avatar
Sven Neumann committed
21 22
#include <gtk/gtk.h>

23
#include "libgimpmath/gimpmath.h"
24
#include "libgimpbase/gimpbase.h"
25
#include "libgimpwidgets/gimpwidgets.h"
26

27
#include "gui-types.h"
28

29
#include "core/gimp.h"
Michael Natterer's avatar
Michael Natterer committed
30
#include "core/gimpcoreconfig.h"
Michael Natterer's avatar
Michael Natterer committed
31
#include "core/gimpimage.h"
Michael Natterer's avatar
Michael Natterer committed
32 33
#include "core/gimpimage-new.h"

34 35
#include "widgets/gimpenummenu.h"

36
#include "file-new-dialog.h"
37

38
#include "gimprc.h"
39

40
#include "libgimp/gimpintl.h"
41

42

43 44
typedef struct
{
45
  GtkWidget          *dialog;
46

47
  GtkWidget          *confirm_dialog;
48

49
  GtkWidget          *size_se;
50
  GtkWidget          *memsize_label;
51 52
  GtkWidget          *resolution_se;
  GtkWidget          *couple_resolutions;
53

54 55
  GtkWidget          *type_w;
  GtkWidget          *fill_type_w;
56

57
  GimpImageNewValues *values;
58
  gdouble             size;
Michael Natterer's avatar
Michael Natterer committed
59 60

  Gimp               *gimp;
61
} NewImageInfo;
62

Michael Natterer's avatar
Michael Natterer committed
63

Michael Natterer's avatar
Michael Natterer committed
64 65
/*  local function prototypes  */

66
static void   file_new_confirm_dialog      (NewImageInfo *info);
67

68 69 70 71 72 73 74 75
static void   file_new_ok_callback         (GtkWidget    *widget,
					    gpointer      data);
static void   file_new_reset_callback      (GtkWidget    *widget,
					    gpointer      data);
static void   file_new_cancel_callback     (GtkWidget    *widget,
					    gpointer      data);
static void   file_new_resolution_callback (GtkWidget    *widget,
					    gpointer      data);
76 77 78 79
static void   file_new_image_type_callback (GtkWidget    *widget,
                                            gpointer      data);
static void   file_new_fill_type_callback  (GtkWidget    *widget,
                                            gpointer      data);
80 81
static void   file_new_image_size_callback (GtkWidget    *widget,
					    gpointer      data);
82

Michael Natterer's avatar
Michael Natterer committed
83

Michael Natterer's avatar
Michael Natterer committed
84
/*  public functions  */
85

86
void
Michael Natterer's avatar
Michael Natterer committed
87 88
file_new_dialog_create (Gimp      *gimp,
                        GimpImage *gimage)
89
{
Michael Natterer's avatar
Michael Natterer committed
90 91 92 93 94 95 96 97 98 99 100 101 102
  NewImageInfo *info;
  GtkWidget    *top_vbox;
  GtkWidget    *hbox;
  GtkWidget    *vbox;
  GtkWidget    *abox;
  GtkWidget    *frame;
  GtkWidget    *table;
  GtkWidget    *separator;
  GtkWidget    *label;
  GtkObject    *adjustment;
  GtkWidget    *spinbutton;
  GtkWidget    *spinbutton2;

Michael Natterer's avatar
Michael Natterer committed
103 104 105
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (! gimage || GIMP_IS_IMAGE (gimage));

Michael Natterer's avatar
Michael Natterer committed
106 107
  info = g_new0 (NewImageInfo, 1);

Michael Natterer's avatar
Michael Natterer committed
108 109 110
  info->gimp           = gimp;

  info->values         = gimp_image_new_values_new (gimp, gimage);
111

112 113
  info->confirm_dialog = NULL;
  info->size           = 0.0;
114

115 116 117 118 119
  info->dialog = gimp_dialog_new (_("New Image"), "new_image",
				  gimp_standard_help_func,
				  "dialogs/file_new.html",
				  GTK_WIN_POS_MOUSE,
				  FALSE, FALSE, TRUE,
120

121 122
				  GTK_STOCK_CANCEL, file_new_cancel_callback,
				  info, NULL, NULL, FALSE, TRUE,
123

124 125 126
				  GIMP_STOCK_RESET, file_new_reset_callback,
				  info, NULL, NULL, FALSE, FALSE,

127 128 129
				  GTK_STOCK_OK, file_new_ok_callback,
				  info, NULL, NULL, TRUE, FALSE,

130
				  NULL);
131

132
  /*  vbox holding the rest of the dialog  */
133
  top_vbox = gtk_vbox_new (FALSE, 4);
134
  gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4);
135
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->dialog)->vbox),
136 137 138
		      top_vbox, TRUE, TRUE, 0);
  gtk_widget_show (top_vbox);

139
  /*  Image size frame  */
140 141 142
  frame = gtk_frame_new (_("Image Size"));
  gtk_box_pack_start (GTK_BOX (top_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);
143 144 145

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
146
  gtk_container_add (GTK_CONTAINER (frame), vbox);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
  gtk_widget_show (vbox);

  table = gtk_table_new (7, 2, FALSE);
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
  gtk_table_set_row_spacing (GTK_TABLE (table), 1, 4);
  gtk_table_set_row_spacing (GTK_TABLE (table), 2, 4);
  gtk_table_set_row_spacing (GTK_TABLE (table), 4, 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

  /*  the pixel size labels  */
  label = gtk_label_new (_("Width:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  label = gtk_label_new (_("Height:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  /*  a separator after the pixel section  */
  separator = gtk_hseparator_new ();
  gtk_table_attach_defaults (GTK_TABLE (table), separator, 0, 2, 2, 3);
  gtk_widget_show (separator);

  /*  the unit size labels  */
  label = gtk_label_new (_("Width:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  label = gtk_label_new (_("Height:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  /*  create the sizeentry which keeps it all together  */
  abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
  gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5);
192
  info->size_se =
Michael Natterer's avatar
Michael Natterer committed
193
    gimp_size_entry_new (0, info->values->unit, "%a", FALSE, FALSE, TRUE, 75,
194
			 GIMP_SIZE_ENTRY_UPDATE_SIZE);
195 196 197
  gtk_table_set_col_spacing (GTK_TABLE (info->size_se), 1, 2);
  gtk_container_add (GTK_CONTAINER (abox), info->size_se);
  gtk_widget_show (info->size_se);
198 199 200 201 202 203
  gtk_widget_show (abox);

  /*  height in units  */
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 2);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
204
  gtk_widget_set_size_request (spinbutton, 75, -1);
205
  /*  add the "height in units" spinbutton to the sizeentry  */
206
  gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
207 208 209 210 211 212 213 214
			     0, 1, 2, 3);
  gtk_widget_show (spinbutton);

  /*  height in pixels  */
  hbox = gtk_hbox_new (FALSE, 2);
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton2 = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton2), TRUE);
215
  gtk_widget_set_size_request (spinbutton2, 75, -1);
216 217 218 219 220 221 222
  gtk_box_pack_start (GTK_BOX (hbox), spinbutton2, FALSE, FALSE, 0);
  gtk_widget_show (spinbutton2);

  label = gtk_label_new (_("Pixels"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

223 224 225 226
  info->memsize_label = gtk_label_new (NULL);
  gtk_box_pack_end (GTK_BOX (hbox), info->memsize_label, FALSE, FALSE, 0);
  gtk_widget_show (info->memsize_label);

227 228
  /*  add the "height in pixels" spinbutton to the main table  */
  gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 1, 2);
229
  gtk_widget_show (hbox);
230

231
  /*  register the height spinbuttons with the sizeentry  */
232
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
233 234 235 236 237 238 239
                             GTK_SPIN_BUTTON (spinbutton),
			     GTK_SPIN_BUTTON (spinbutton2));

  /*  width in units  */
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 2);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
240
  gtk_widget_set_size_request (spinbutton, 75, -1);
241
  /*  add the "width in units" spinbutton to the sizeentry  */
242
  gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
243 244 245 246 247 248 249 250 251
			     0, 1, 1, 2);
  gtk_widget_show (spinbutton);

  /*  width in pixels  */
  abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
  gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 0, 1);
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton2 = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton2), TRUE);
252
  gtk_widget_set_size_request (spinbutton2, 75, -1);
253 254 255 256 257 258
  /*  add the "width in pixels" spinbutton to the main table  */
  gtk_container_add (GTK_CONTAINER (abox), spinbutton2);
  gtk_widget_show (spinbutton2);
  gtk_widget_show (abox);

  /*  register the width spinbuttons with the sizeentry  */
259
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
260 261 262 263
                             GTK_SPIN_BUTTON (spinbutton),
			     GTK_SPIN_BUTTON (spinbutton2));

  /*  initialize the sizeentry  */
264
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
Michael Natterer's avatar
Michael Natterer committed
265
				  info->values->xresolution, FALSE);
266
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
Michael Natterer's avatar
Michael Natterer committed
267
				  info->values->yresolution, FALSE);
268

269
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 0,
270 271
					 GIMP_MIN_IMAGE_SIZE,
					 GIMP_MAX_IMAGE_SIZE);
272
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 1,
273 274 275
					 GIMP_MIN_IMAGE_SIZE,
					 GIMP_MAX_IMAGE_SIZE);

Michael Natterer's avatar
Michael Natterer committed
276 277 278 279
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 0,
			      info->values->width);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 1,
			      info->values->height);
280

281 282 283 284 285 286
  g_signal_connect (G_OBJECT (info->size_se), "refval_changed",
		    G_CALLBACK (file_new_image_size_callback),
		    info);
  g_signal_connect (G_OBJECT (info->size_se), "value_changed",
		    G_CALLBACK (file_new_image_size_callback),
		    info);
287 288

  /*  initialize the size label  */
289
  file_new_image_size_callback (info->size_se, info);
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

  /*  the resolution labels  */
  label = gtk_label_new (_("Resolution X:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  label = gtk_label_new (_("Y:"));
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 6, 7,
		    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
  gtk_widget_show (label);

  /*  the resolution sizeentry  */
  adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
  spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 2);
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
308
  gtk_widget_set_size_request (spinbutton, 75, -1);
309

310
  info->resolution_se =
Michael Natterer's avatar
Michael Natterer committed
311
    gimp_size_entry_new (1, gimp->config->default_resolution_units,
Michael Natterer's avatar
Michael Natterer committed
312
			 _("pixels/%a"),
313 314 315 316 317
		         FALSE, FALSE, FALSE, 75,
		         GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
  gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 1, 2);
  gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 2, 2);
  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->resolution_se),
318
			     GTK_SPIN_BUTTON (spinbutton), NULL);
319
  gtk_table_attach_defaults (GTK_TABLE (info->resolution_se), spinbutton,
320 321
			     1, 2, 0, 1);
  gtk_widget_show (spinbutton);
322 323 324 325 326 327

  abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
  gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 5, 7);
  gtk_widget_show (abox);

  gtk_container_add (GTK_CONTAINER (abox), info->resolution_se);  
328
  gtk_widget_show (info->resolution_se);
329

330
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
331 332
					 0, GIMP_MIN_RESOLUTION,
					 GIMP_MAX_RESOLUTION);
333
  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
334 335 336
					 1, GIMP_MIN_RESOLUTION,
					 GIMP_MAX_RESOLUTION);

Michael Natterer's avatar
Michael Natterer committed
337 338 339 340
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0,
			      info->values->xresolution);
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1,
			      info->values->yresolution);
341

342 343 344
  g_signal_connect (G_OBJECT (info->resolution_se), "value_changed",
		    G_CALLBACK (file_new_resolution_callback),
		    info);
345

346
  /*  the resolution chainbutton  */
347
  info->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
348
  gimp_chain_button_set_active
349
    (GIMP_CHAIN_BUTTON (info->couple_resolutions),
Michael Natterer's avatar
Michael Natterer committed
350 351
     ABS (info->values->xresolution - info->values->yresolution)
     < GIMP_MIN_RESOLUTION);
352 353 354
  gtk_table_attach_defaults (GTK_TABLE (info->resolution_se),
			     info->couple_resolutions, 2, 3, 0, 2);
  gtk_widget_show (info->couple_resolutions);
355

356 357
  /*  hbox containing the Image type and fill type frames  */
  hbox = gtk_hbox_new (FALSE, 2);
358
  gtk_box_pack_start (GTK_BOX (top_vbox), hbox, FALSE, FALSE, 0);
359
  gtk_widget_show (hbox);
360

361
  /*  frame for Image Type  */
362 363 364 365 366 367 368 369 370
  frame = gimp_enum_radio_frame_new (GIMP_TYPE_IMAGE_BASE_TYPE,
                                     gtk_label_new (_("Image Type")),
                                     2,
                                     G_CALLBACK (file_new_image_type_callback),
                                     info,
                                     &info->type_w);
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (info->type_w),
                               GINT_TO_POINTER (info->values->type));

371 372 373
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

374
  /* frame for Fill Type */
375 376 377 378 379 380 381 382 383
  frame = gimp_enum_radio_frame_new (GIMP_TYPE_FILL_TYPE,
                                     gtk_label_new (_("Fill Type")),
                                     2,
                                     G_CALLBACK (file_new_fill_type_callback),
                                     info,
                                     &info->fill_type_w);
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (info->fill_type_w),
                               GINT_TO_POINTER (info->values->fill_type));

384 385 386
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame);

387
  gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (info->size_se));
388

389
  gtk_widget_show (info->dialog);
390
}
Michael Natterer's avatar
Michael Natterer committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439


/*  private functions  */

static void
file_new_ok_callback (GtkWidget *widget,
		      gpointer   data)
{
  NewImageInfo       *info;
  GimpImageNewValues *values;

  info = (NewImageInfo*) data;
  values = info->values;

  /* get the image size in pixels */
  values->width = 
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0));
  values->height = 
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1));

  /* get the resolution in dpi */
  values->xresolution =
    gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0);
  values->yresolution =
    gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1);

  /* get the units */
  values->unit =
    gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->size_se));
  values->res_unit =
    gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->resolution_se));

  if (info->size > gimprc.max_new_image_size)
    {
      file_new_confirm_dialog (info);
    }
  else
    {
      gtk_widget_destroy (info->dialog);
      gimp_image_new_create_image (info->gimp, values);
      gimp_image_new_values_free (values);
      g_free (info);
    }
}

static void
file_new_reset_callback (GtkWidget *widget,
			 gpointer   data)
{
440 441
  NewImageInfo   *info;
  GimpCoreConfig *config;
Michael Natterer's avatar
Michael Natterer committed
442 443 444

  info = (NewImageInfo *) data;

445 446
  config = info->gimp->config;

447 448 449
  g_signal_handlers_block_by_func (G_OBJECT (info->resolution_se),
                                   file_new_resolution_callback,
                                   info);
Michael Natterer's avatar
Michael Natterer committed
450 451 452

  gimp_chain_button_set_active
    (GIMP_CHAIN_BUTTON (info->couple_resolutions),
453 454
     ABS (config->default_xresolution -
	  config->default_yresolution) < GIMP_MIN_RESOLUTION);
Michael Natterer's avatar
Michael Natterer committed
455 456

  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0,
457
			      config->default_xresolution);
Michael Natterer's avatar
Michael Natterer committed
458
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1,
459
			      config->default_yresolution);
Michael Natterer's avatar
Michael Natterer committed
460
  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->resolution_se),
461
			    config->default_resolution_units);
Michael Natterer's avatar
Michael Natterer committed
462

463 464 465
  g_signal_handlers_unblock_by_func (G_OBJECT (info->resolution_se),
                                     file_new_resolution_callback,
                                     info);
Michael Natterer's avatar
Michael Natterer committed
466 467

  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
468
				  config->default_xresolution, TRUE);
Michael Natterer's avatar
Michael Natterer committed
469
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
470
				  config->default_yresolution, TRUE);
Michael Natterer's avatar
Michael Natterer committed
471
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 0,
472
			      config->default_width);
Michael Natterer's avatar
Michael Natterer committed
473
  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 1,
474
			      config->default_height);
Michael Natterer's avatar
Michael Natterer committed
475
  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->size_se),
476
			    config->default_units);
Michael Natterer's avatar
Michael Natterer committed
477

478 479
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (info->type_w),
                               GINT_TO_POINTER (config->default_type));
480

481
  gimp_radio_group_set_active (GTK_RADIO_BUTTON (info->fill_type_w),
482
                               GINT_TO_POINTER (GIMP_BACKGROUND_FILL));
Michael Natterer's avatar
Michael Natterer committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
}

static void
file_new_cancel_callback (GtkWidget *widget,
			  gpointer   data)
{
  NewImageInfo *info;

  info = (NewImageInfo*) data;

  gtk_widget_destroy (info->dialog);
  gimp_image_new_values_free (info->values);
  g_free (info);
}

/*  local callback of file_new_confirm_dialog()  */
static void
file_new_confirm_dialog_callback (GtkWidget *widget,
				  gboolean   create,
				  gpointer   data)
{
  NewImageInfo *info;

  info = (NewImageInfo*) data;

  info->confirm_dialog = NULL;

  if (create)
    {
      gtk_widget_destroy (info->dialog);
      gimp_image_new_create_image (info->gimp, info->values);
      gimp_image_new_values_free (info->values);
      g_free (info);
    }
  else
    {
      gtk_widget_set_sensitive (info->dialog, TRUE);
    }
}

static void
file_new_confirm_dialog (NewImageInfo *info)
{
  gchar *size;
  gchar *max_size;
  gchar *text;

  gtk_widget_set_sensitive (info->dialog, FALSE);

532 533
  size     = gimp_image_new_get_memsize_string (info->size);
  max_size = gimp_image_new_get_memsize_string (gimprc.max_new_image_size);
Michael Natterer's avatar
Michael Natterer committed
534 535 536

  /* xgettext:no-c-format */
	    
537 538
  text = g_strdup_printf (_("You are trying to create an image with\n"
			    "an initial size of %s.\n\n"
Michael Natterer's avatar
Michael Natterer committed
539
			    "Choose OK to create this image anyway.\n"
540
			    "Choose Cancel if you did not intend to\n"
Michael Natterer's avatar
Michael Natterer committed
541 542 543 544
			    "create such a large image.\n\n"
			    "To prevent this dialog from appearing,\n"
			    "increase the \"Maximum Image Size\"\n"
			    "setting (currently %s) in the\n"
545
			    "Preferences dialog."),
Michael Natterer's avatar
Michael Natterer committed
546 547 548 549 550 551
                          size, max_size);

  info->confirm_dialog =
    gimp_query_boolean_box (_("Confirm Image Size"),
			    gimp_standard_help_func,
			    "dialogs/file_new.html#confirm_size",
552
			    GTK_STOCK_DIALOG_INFO,
Michael Natterer's avatar
Michael Natterer committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
			    text,
			    GTK_STOCK_OK, GTK_STOCK_CANCEL,
			    NULL, NULL,
			    file_new_confirm_dialog_callback,
			    info);

  g_free (text);
  g_free (max_size);
  g_free (size);

  gtk_widget_show (info->confirm_dialog);
}

static void
file_new_resolution_callback (GtkWidget *widget,
			      gpointer   data)
{
  NewImageInfo *info;

  static gdouble xres = 0.0;
  static gdouble yres = 0.0;
  gdouble new_xres;
  gdouble new_yres;

  info = (NewImageInfo *) data;

  new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
  new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);

  if (gimp_chain_button_get_active
      (GIMP_CHAIN_BUTTON (info->couple_resolutions)))
    {
585 586 587
      g_signal_handlers_block_by_func (G_OBJECT (info->resolution_se),
                                       file_new_resolution_callback,
                                       info);
Michael Natterer's avatar
Michael Natterer committed
588 589 590 591 592 593 594 595 596 597 598 599 600

      if (new_xres != xres)
	{
	  yres = new_yres = xres = new_xres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1, yres);
	}

      if (new_yres != yres)
	{
	  xres = new_xres = yres = new_yres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0, xres);
	}

601 602 603
      g_signal_handlers_unblock_by_func (G_OBJECT (info->resolution_se),
                                         file_new_resolution_callback,
                                         info);
Michael Natterer's avatar
Michael Natterer committed
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    }
  else
    {
      if (new_xres != xres)
	xres = new_xres;
      if (new_yres != yres)
	yres = new_yres;
    }

  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
				  xres, FALSE);
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
				  yres, FALSE);

  file_new_image_size_callback (widget, data);
}

621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
static void
file_new_image_type_callback (GtkWidget *widget,
                              gpointer   data)
{
  NewImageInfo *info;

  info = (NewImageInfo*) data;

  gimp_radio_button_update (widget, &info->values->type);
  
  file_new_image_size_callback (widget, data);
}

static void
file_new_fill_type_callback (GtkWidget *widget,
                             gpointer   data)
{
  NewImageInfo *info;

  info = (NewImageInfo*) data;

  gimp_radio_button_update (widget, &info->values->fill_type);
  
  file_new_image_size_callback (widget, data);
}

Michael Natterer's avatar
Michael Natterer committed
647 648 649 650 651
static void
file_new_image_size_callback (GtkWidget *widget,
			      gpointer   data)
{
  NewImageInfo *info;
652
  gchar        *text;
Michael Natterer's avatar
Michael Natterer committed
653 654 655 656 657 658 659 660

  info = (NewImageInfo*) data;

  info->values->width = 
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0));
  info->values->height =
    RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1));

661
  info->size = gimp_image_new_calculate_memsize (info->values);
Michael Natterer's avatar
Michael Natterer committed
662

663
  text = gimp_image_new_get_memsize_string (info->size);
664
  gtk_label_set_text (GTK_LABEL (info->memsize_label), text);
Michael Natterer's avatar
Michael Natterer committed
665 666
  g_free (text);
}