dialogs-constructors.c 21.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 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.
 */

#include "config.h"

#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

25
#include "dialogs-types.h"
26

27
#include "core/gimp.h"
28
29
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
30
#include "core/gimpimage-colormap.h"
31

32
#include "config/gimpguiconfig.h"
33

34
#include "widgets/gimpbrusheditor.h"
Michael Natterer's avatar
Michael Natterer committed
35
#include "widgets/gimpbrushfactoryview.h"
Michael Natterer's avatar
Michael Natterer committed
36
#include "widgets/gimpbufferview.h"
37
#include "widgets/gimpchanneltreeview.h"
38
#include "widgets/gimpcoloreditor.h"
39
#include "widgets/gimpcolormapeditor.h"
40
#include "widgets/gimpcontainergridview.h"
41
#include "widgets/gimpcontainertreeview.h"
42
#include "widgets/gimpcontainerview-utils.h"
43
#include "widgets/gimpcursorview.h"
44
#include "widgets/gimpdataeditor.h"
45
#include "widgets/gimpdevicestatus.h"
46
#include "widgets/gimpdialogfactory.h"
47
#include "widgets/gimpdockable.h"
Michael Natterer's avatar
Michael Natterer committed
48
#include "widgets/gimpdocumentview.h"
49
#include "widgets/gimperrorconsole.h"
50
#include "widgets/gimperrordialog.h"
51
#include "widgets/gimpfontview.h"
52
#include "widgets/gimpgradienteditor.h"
53
#include "widgets/gimphelp-ids.h"
54
55
#include "widgets/gimphistogrameditor.h"
#include "widgets/gimpimageview.h"
56
#include "widgets/gimplayertreeview.h"
57
#include "widgets/gimpmenudock.h"
58
#include "widgets/gimppaletteeditor.h"
59
#include "widgets/gimppatternfactoryview.h"
60
#include "widgets/gimpsamplepointeditor.h"
61
#include "widgets/gimpselectioneditor.h"
62
#include "widgets/gimptemplateview.h"
63
#include "widgets/gimptoolbox.h"
64
#include "widgets/gimptooloptionseditor.h"
65
#include "widgets/gimptoolview.h"
66
#include "widgets/gimpundoeditor.h"
67
#include "widgets/gimpvectorstreeview.h"
68

69
#include "display/gimpnavigationeditor.h"
70

71
#include "about-dialog.h"
72
#include "dialogs.h"
73
#include "dialogs-constructors.h"
74
#include "file-open-dialog.h"
75
#include "file-open-location-dialog.h"
76
#include "file-save-dialog.h"
77
78
#include "image-new-dialog.h"
#include "module-dialog.h"
79
#include "preferences-dialog.h"
80
#include "quit-dialog.h"
81
#include "tips-dialog.h"
82

83
#include "gimp-intl.h"
84
85


86
87
/*  local function prototypes  */

88
89
static void   dialogs_indexed_palette_selected (GimpColormapEditor *editor,
                                                GdkModifierType     state,
90
                                                gpointer            data);
91

92

93
94
95
/**********************/
/*  toplevel dialogs  */
/**********************/
96

97
GtkWidget *
98
99
100
dialogs_image_new_new (GimpDialogFactory *factory,
                       GimpContext       *context,
                       gint               preview_size)
101
{
102
  return image_new_dialog_new (context->gimp);
103
104
}

105
106
107
108
109
110
111
112
GtkWidget *
dialogs_file_open_new (GimpDialogFactory *factory,
                       GimpContext       *context,
                       gint               preview_size)
{
  return file_open_dialog_new (context->gimp);
}

113
114
115
116
117
118
119
120
GtkWidget *
dialogs_file_open_location_new (GimpDialogFactory *factory,
                                GimpContext       *context,
                                gint               preview_size)
{
  return file_open_location_dialog_new (context->gimp);
}

121
122
123
124
125
126
127
128
GtkWidget *
dialogs_file_save_new (GimpDialogFactory *factory,
                       GimpContext       *context,
                       gint               preview_size)
{
  return file_save_dialog_new (context->gimp);
}

129
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
130
dialogs_preferences_get (GimpDialogFactory *factory,
131
132
			 GimpContext       *context,
                         gint               preview_size)
133
{
134
  return preferences_dialog_create (context->gimp);
135
136
137
}

GtkWidget *
138
139
140
dialogs_module_get (GimpDialogFactory *factory,
                    GimpContext       *context,
                    gint               preview_size)
141
{
142
  return module_dialog_new (context->gimp);
143
144
145
}

GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
146
dialogs_tips_get (GimpDialogFactory *factory,
147
148
		  GimpContext       *context,
                  gint               preview_size)
149
{
150
  return tips_dialog_create (context->gimp);
151
152
153
}

GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
154
dialogs_about_get (GimpDialogFactory *factory,
155
156
		   GimpContext       *context,
                   gint               preview_size)
157
158
159
160
{
  return about_dialog_create ();
}

161
162
163
164
165
166
167
GtkWidget *
dialogs_error_get (GimpDialogFactory *factory,
                   GimpContext       *context,
                   gint               preview_size)
{
  return gimp_error_dialog_new (_("GIMP Message"), GIMP_STOCK_WARNING);
}
168

169
170
171
172
173
174
175
176
GtkWidget *
dialogs_quit_get (GimpDialogFactory *factory,
                  GimpContext       *context,
                  gint               preview_size)
{
  return quit_dialog_new (context->gimp);
}

177

178
/***********/
179
/*  docks  */
180
/***********/
181

182
183
184
185
186
187
GtkWidget *
dialogs_toolbox_get (GimpDialogFactory *factory,
		     GimpContext       *context,
                     gint               preview_size)
{
  /*  we pass "global_dock_factory", _not_ "global_toolbox_factory" to
188
   *  the toolbox constructor, because the global_toolbox_factory has no
189
190
191
192
193
   *  dockables registered
   */
  return gimp_toolbox_new (global_dock_factory, context->gimp);
}

Michael Natterer's avatar
Michael Natterer committed
194
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
195
dialogs_dock_new (GimpDialogFactory *factory,
196
197
		  GimpContext       *context,
                  gint               preview_size)
Michael Natterer's avatar
Michael Natterer committed
198
{
199
200
201
  return gimp_menu_dock_new (factory,
                             context->gimp->images,
                             context->gimp->displays);
Michael Natterer's avatar
Michael Natterer committed
202
203
204
}


205
206
207
208
/***************/
/*  dockables  */
/***************/

209
210
/*****  the dockable constructor  *****/

211
GtkWidget *
212
213
214
215
dialogs_dockable_constructor (GimpDialogFactory      *factory,
                              GimpDialogFactoryEntry *entry,
                              GimpContext            *context,
                              gint                    preview_size)
216
{
217
218
  GtkWidget *dockable = NULL;
  GtkWidget *widget;
219

220
  widget = entry->new_func (factory, context, preview_size);
221

222
223
224
225
226
227
228
229
230
231
  if (widget)
    {
      dockable = gimp_dockable_new (entry->name, entry->blurb,
                                    entry->stock_id, entry->help_id);
      gtk_container_add (GTK_CONTAINER (dockable), widget);
      gtk_widget_show (widget);
    }

  return dockable;
}
232
233


234
235
236
/*****  singleton dialogs  *****/

GtkWidget *
237
dialogs_tool_options_new (GimpDialogFactory *factory,
238
239
240
241
242
			  GimpContext       *context,
                          gint               preview_size)
{
  return gimp_tool_options_editor_new (context->gimp,
                                       factory->menu_factory);
243
244
}

245
GtkWidget *
246
dialogs_device_status_new (GimpDialogFactory *factory,
247
248
249
                           GimpContext       *context,
                           gint               preview_size)
{
250
  return gimp_device_status_new (context->gimp);
251
252
}

253
GtkWidget *
254
dialogs_error_console_new (GimpDialogFactory *factory,
255
256
257
			   GimpContext       *context,
                           gint               preview_size)
{
258
259
  return gimp_error_console_new (context->gimp,
                                 factory->menu_factory);
260
261
}

262
263
264
265
266
GtkWidget *
dialogs_cursor_view_new (GimpDialogFactory *factory,
                         GimpContext       *context,
                         gint               preview_size)
{
267
  return gimp_cursor_view_new ();
268
269
}

270
271

/*****  list views  *****/
272

273
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
274
dialogs_image_list_view_new (GimpDialogFactory *factory,
275
276
			     GimpContext       *context,
                             gint               preview_size)
277
{
278
  return gimp_image_view_new (GIMP_VIEW_TYPE_LIST,
279
280
                              context->gimp->images,
                              context,
281
                              preview_size, 1,
282
                              factory->menu_factory);
283
284
}

285
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
286
dialogs_brush_list_view_new (GimpDialogFactory *factory,
287
288
			     GimpContext       *context,
                             gint               preview_size)
289
{
290
  return gimp_brush_factory_view_new (GIMP_VIEW_TYPE_LIST,
291
				      context->gimp->brush_factory,
Michael Natterer's avatar
Michael Natterer committed
292
293
				      context,
				      TRUE,
294
				      preview_size, 1,
295
                                      factory->menu_factory);
296
297
}

298
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
299
dialogs_pattern_list_view_new (GimpDialogFactory *factory,
300
301
			       GimpContext       *context,
                               gint               preview_size)
302
{
303
  return gimp_pattern_factory_view_new (GIMP_VIEW_TYPE_LIST,
304
305
306
307
                                        context->gimp->pattern_factory,
                                        context,
                                        preview_size, 1,
                                        factory->menu_factory);
308
309
}

310
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
311
dialogs_gradient_list_view_new (GimpDialogFactory *factory,
312
313
				GimpContext       *context,
                                gint               preview_size)
314
{
315
  return gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST,
316
317
318
                                     context->gimp->gradient_factory,
                                     context,
                                     preview_size, 1,
319
                                     factory->menu_factory, "<Gradients>",
320
321
                                     "/gradients-popup",
                                     "gradients");
322
323
}

324
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
325
dialogs_palette_list_view_new (GimpDialogFactory *factory,
326
327
			       GimpContext       *context,
                               gint               preview_size)
328
{
329
  return gimp_data_factory_view_new (GIMP_VIEW_TYPE_LIST,
330
331
332
                                     context->gimp->palette_factory,
                                     context,
                                     preview_size, 1,
333
                                     factory->menu_factory, "<Palettes>",
334
335
                                     "/palettes-popup",
                                     "palettes");
336
337
}

338
339
340
341
342
GtkWidget *
dialogs_font_list_view_new (GimpDialogFactory *factory,
                            GimpContext       *context,
                            gint               preview_size)
{
343
  return gimp_font_view_new (GIMP_VIEW_TYPE_LIST,
344
345
346
347
                             context->gimp->fonts,
                             context,
                             preview_size, 1,
                             factory->menu_factory);
348
349
}

350
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
351
dialogs_tool_list_view_new (GimpDialogFactory *factory,
352
353
			    GimpContext       *context,
                            gint               preview_size)
354
{
355
  return gimp_tool_view_new (GIMP_VIEW_TYPE_LIST,
356
357
358
359
                             context->gimp->tool_info_list,
                             context,
                             preview_size, 0,
                             factory->menu_factory);
360
361
}

Michael Natterer's avatar
Michael Natterer committed
362
363
GtkWidget *
dialogs_buffer_list_view_new (GimpDialogFactory *factory,
364
365
			      GimpContext       *context,
                              gint               preview_size)
Michael Natterer's avatar
Michael Natterer committed
366
{
367
  return gimp_buffer_view_new (GIMP_VIEW_TYPE_LIST,
368
			       context->gimp->named_buffers,
Michael Natterer's avatar
Michael Natterer committed
369
			       context,
370
			       preview_size, 1,
371
                               factory->menu_factory);
372
373
374
}

GtkWidget *
375
376
377
dialogs_document_list_view_new (GimpDialogFactory *factory,
                                GimpContext       *context,
                                gint               preview_size)
378
{
379
  return gimp_document_view_new (GIMP_VIEW_TYPE_LIST,
380
381
                                 context->gimp->documents,
                                 context,
382
                                 preview_size, 0,
383
384
385
386
                                 factory->menu_factory);
}

GtkWidget *
387
388
389
dialogs_template_list_view_new (GimpDialogFactory *factory,
                                GimpContext       *context,
                                gint               preview_size)
390
{
391
  return gimp_template_view_new (GIMP_VIEW_TYPE_LIST,
392
393
394
395
                                 context->gimp->templates,
                                 context,
                                 preview_size, 0,
                                 factory->menu_factory);
Michael Natterer's avatar
Michael Natterer committed
396
397
}

398

399
/*****  grid views  *****/
400

401
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
402
dialogs_image_grid_view_new (GimpDialogFactory *factory,
403
404
			     GimpContext       *context,
                             gint               preview_size)
405
{
406
  return gimp_image_view_new (GIMP_VIEW_TYPE_GRID,
407
408
                              context->gimp->images,
                              context,
409
                              preview_size, 1,
410
                              factory->menu_factory);
411
412
}

413
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
414
dialogs_brush_grid_view_new (GimpDialogFactory *factory,
415
416
			     GimpContext       *context,
                             gint               preview_size)
417
{
418
  return gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
419
				      context->gimp->brush_factory,
Michael Natterer's avatar
Michael Natterer committed
420
421
				      context,
				      TRUE,
422
				      preview_size, 1,
423
                                      factory->menu_factory);
424
425
}

426
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
427
dialogs_pattern_grid_view_new (GimpDialogFactory *factory,
428
429
			       GimpContext       *context,
                               gint               preview_size)
430
{
431
  return gimp_pattern_factory_view_new (GIMP_VIEW_TYPE_GRID,
432
433
434
435
                                        context->gimp->pattern_factory,
                                        context,
                                        preview_size, 1,
                                        factory->menu_factory);
436
437
}

438
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
439
dialogs_gradient_grid_view_new (GimpDialogFactory *factory,
440
441
				GimpContext       *context,
                                gint               preview_size)
442
{
443
  return gimp_data_factory_view_new (GIMP_VIEW_TYPE_GRID,
444
445
446
                                     context->gimp->gradient_factory,
                                     context,
                                     preview_size, 1,
447
                                     factory->menu_factory, "<Gradients>",
448
449
                                     "/gradients-popup",
                                     "gradients");
450
451
}

452
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
453
dialogs_palette_grid_view_new (GimpDialogFactory *factory,
454
455
			       GimpContext       *context,
                               gint               preview_size)
456
{
457
  return gimp_data_factory_view_new (GIMP_VIEW_TYPE_GRID,
458
459
460
                                     context->gimp->palette_factory,
                                     context,
                                     preview_size, 1,
461
                                     factory->menu_factory, "<Palettes>",
462
463
                                     "/palettes-popup",
                                     "palettes");
464
465
}

466
467
468
469
470
GtkWidget *
dialogs_font_grid_view_new (GimpDialogFactory *factory,
                            GimpContext       *context,
                            gint               preview_size)
{
471
  return gimp_font_view_new (GIMP_VIEW_TYPE_GRID,
472
473
474
475
                             context->gimp->fonts,
                             context,
                             preview_size, 1,
                             factory->menu_factory);
476
477
}

478
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
479
dialogs_tool_grid_view_new (GimpDialogFactory *factory,
480
481
			    GimpContext       *context,
                            gint               preview_size)
482
{
483
  return gimp_tool_view_new (GIMP_VIEW_TYPE_GRID,
484
485
486
487
                             context->gimp->tool_info_list,
                             context,
                             preview_size, 1,
                             factory->menu_factory);
488
489
}

Michael Natterer's avatar
Michael Natterer committed
490
491
GtkWidget *
dialogs_buffer_grid_view_new (GimpDialogFactory *factory,
492
493
			      GimpContext       *context,
                              gint               preview_size)
Michael Natterer's avatar
Michael Natterer committed
494
{
495
  return gimp_buffer_view_new (GIMP_VIEW_TYPE_GRID,
496
			       context->gimp->named_buffers,
Michael Natterer's avatar
Michael Natterer committed
497
			       context,
498
			       preview_size, 1,
499
                               factory->menu_factory);
500
501
502
}

GtkWidget *
503
504
505
dialogs_document_grid_view_new (GimpDialogFactory *factory,
                                GimpContext       *context,
                                gint               preview_size)
506
{
507
  return gimp_document_view_new (GIMP_VIEW_TYPE_GRID,
508
509
                                 context->gimp->documents,
                                 context,
510
511
512
513
514
515
516
517
518
519
520
521
522
                                 preview_size, 0,
                                 factory->menu_factory);
}

GtkWidget *
dialogs_template_grid_view_new (GimpDialogFactory *factory,
                                GimpContext       *context,
                                gint               preview_size)
{
  return gimp_template_view_new (GIMP_VIEW_TYPE_GRID,
                                 context->gimp->templates,
                                 context,
                                 preview_size, 0,
523
                                 factory->menu_factory);
Michael Natterer's avatar
Michael Natterer committed
524
525
}

526

527
/*****  image related dialogs  *****/
528
529

GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
530
dialogs_layer_list_view_new (GimpDialogFactory *factory,
531
532
			     GimpContext       *context,
                             gint               preview_size)
533
{
534
535
536
  if (preview_size < 1)
    preview_size = context->gimp->config->layer_preview_size;

537
538
539
540
541
  return gimp_item_tree_view_new (GIMP_TYPE_LAYER_TREE_VIEW,
                                  preview_size, 2,
                                  gimp_context_get_image (context),
                                  factory->menu_factory, "<Layers>",
                                  "/layers-popup");
542
543
}

544
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
545
dialogs_channel_list_view_new (GimpDialogFactory *factory,
546
547
			       GimpContext       *context,
                               gint               preview_size)
548
{
549
550
551
  if (preview_size < 1)
    preview_size = context->gimp->config->layer_preview_size;

552
553
554
555
556
  return gimp_item_tree_view_new (GIMP_TYPE_CHANNEL_TREE_VIEW,
                                  preview_size, 1,
                                  gimp_context_get_image (context),
                                  factory->menu_factory, "<Channels>",
                                  "/channels-popup");
557
558
}

559
560
561
562
GtkWidget *
dialogs_vectors_list_view_new (GimpDialogFactory *factory,
			       GimpContext       *context,
                               gint               preview_size)
563
564
565
566
{
  if (preview_size < 1)
    preview_size = context->gimp->config->layer_preview_size;

567
568
569
570
571
  return gimp_item_tree_view_new (GIMP_TYPE_VECTORS_TREE_VIEW,
                                  preview_size, 1,
                                  gimp_context_get_image (context),
                                  factory->menu_factory, "<Vectors>",
                                  "/vectors-popup");
572
573
}

574
GtkWidget *
575
dialogs_colormap_editor_new (GimpDialogFactory *factory,
576
577
			     GimpContext       *context,
                             gint               preview_size)
578
579
580
{
  GtkWidget *view;

581
  view = gimp_colormap_editor_new (factory->menu_factory);
582

583
  g_signal_connect (view, "selected",
584
		    G_CALLBACK (dialogs_indexed_palette_selected),
585
		    NULL);
586

587
  return view;
588
589
}

590
591
592
593
594
GtkWidget *
dialogs_histogram_editor_new (GimpDialogFactory *factory,
                              GimpContext       *context,
                              gint               preview_size)
{
595
  return gimp_histogram_editor_new ();
596
597
}

598
599
600
601
602
GtkWidget *
dialogs_selection_editor_new (GimpDialogFactory *factory,
                              GimpContext       *context,
                              gint               preview_size)
{
603
  return gimp_selection_editor_new (factory->menu_factory);
604
605
}

606
GtkWidget *
607
608
609
dialogs_undo_editor_new (GimpDialogFactory *factory,
                         GimpContext       *context,
                         gint               preview_size)
610
{
611
612
  return gimp_undo_editor_new (context->gimp->config,
                               factory->menu_factory);
613
614
}

615
616
617
618
619
620
621
622
GtkWidget *
dialogs_sample_point_editor_new (GimpDialogFactory *factory,
                                 GimpContext       *context,
                                 gint               preview_size)
{
  return gimp_sample_point_editor_new (factory->menu_factory);
}

623

624
/*****  display related dialogs  *****/
625

626
GtkWidget *
627
628
629
dialogs_navigation_editor_new (GimpDialogFactory *factory,
                               GimpContext       *context,
                               gint               preview_size)
630
{
631
  return gimp_navigation_editor_new (factory->menu_factory);
632
633
634
}


635
/*****  misc dockables  *****/
636

637
GtkWidget *
638
639
640
dialogs_color_editor_new (GimpDialogFactory *factory,
                          GimpContext       *context,
                          gint               preview_size)
641
{
642
  return gimp_color_editor_new (context);
643
644
}

645

646
/*********************/
647
/*****  editors  *****/
648
/*********************/
649
650
651
652
653
654

GtkWidget *
dialogs_brush_editor_get (GimpDialogFactory *factory,
			  GimpContext       *context,
                          gint               preview_size)
{
655
  return gimp_brush_editor_new (context->gimp);
656
657
658
659
660
661
662
}

GtkWidget *
dialogs_gradient_editor_get (GimpDialogFactory *factory,
			     GimpContext       *context,
                             gint               preview_size)
{
663
664
  return gimp_gradient_editor_new (context->gimp,
                                   factory->menu_factory);
665
666
667
668
669
670
671
}

GtkWidget *
dialogs_palette_editor_get (GimpDialogFactory *factory,
			    GimpContext       *context,
                            gint               preview_size)
{
672
673
  return gimp_palette_editor_new (context->gimp,
                                  factory->menu_factory);
674
675
676
}


677
678
/*  private functions  */

679
static void
680
dialogs_indexed_palette_selected (GimpColormapEditor *editor,
681
                                  GdkModifierType     state,
682
				  gpointer            data)
683
{
684
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
685

686
  if (image_editor->gimage)
687
    {
688
689
690
691
692
      GimpRGB color;
      gint    index;

      index = gimp_colormap_editor_col_index (editor);

693
      gimp_image_get_colormap_entry (image_editor->gimage, index, &color);
694
695

      if (state & GDK_CONTROL_MASK)
696
        gimp_context_set_background (image_editor->context, &color);
697
      else
698
        gimp_context_set_foreground (image_editor->context, &color);
699
    }
700
}