dialogs.c 11.7 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
/* 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>

23 24
#include "libgimpwidgets/gimpwidgets.h"

25
#include "dialogs-types.h"
26

Michael Natterer's avatar
Michael Natterer committed
27
#include "core/gimp.h"
28 29
#include "core/gimpcontext.h"

30
#include "widgets/gimpdialogfactory.h"
31
#include "widgets/gimphelp-ids.h"
32
#include "widgets/gimpmenufactory.h"
33

34 35 36
#include "dialogs.h"
#include "dialogs-constructors.h"

37 38
#include "gimp-intl.h"

39

40 41 42
GimpDialogFactory *global_dialog_factory  = NULL;
GimpDialogFactory *global_dock_factory    = NULL;
GimpDialogFactory *global_toolbox_factory = NULL;
43 44


45 46 47 48 49 50 51 52 53
#define FOREIGN(id,remember_size) \
  { id, NULL, NULL, NULL, NULL, \
    NULL, 0, TRUE,  TRUE, remember_size, FALSE }

#define TOPLEVEL(id,new_func,singleton,session_managed,remember_size) \
  { id, NULL, NULL, NULL, NULL, \
    new_func, 0, singleton, session_managed, remember_size, FALSE }


54
static const GimpDialogFactoryEntry toplevel_entries[] =
55
{
56
  /*  foreign toplevels without constructor  */
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  FOREIGN ("gimp-brightness-contrast-tool-dialog", FALSE),
  FOREIGN ("gimp-color-picker-tool-dialog",        TRUE),
  FOREIGN ("gimp-colorize-tool-dialog",            FALSE),
  FOREIGN ("gimp-crop-tool-dialog",                FALSE),
  FOREIGN ("gimp-curves-tool-dialog",              TRUE),
  FOREIGN ("gimp-color-balance-tool-dialog",       FALSE),
  FOREIGN ("gimp-hue-saturation-tool-dialog",      FALSE),
  FOREIGN ("gimp-levels-tool-dialog",              TRUE),
  FOREIGN ("gimp-measure-tool-dialog",             FALSE),
  FOREIGN ("gimp-posterize-tool-dialog",           FALSE),
  FOREIGN ("gimp-rotate-tool-dialog",              FALSE),
  FOREIGN ("gimp-scale-tool-dialog",               FALSE),
  FOREIGN ("gimp-shear-tool-dialog",               FALSE),
  FOREIGN ("gimp-text-tool-dialog",                TRUE),
  FOREIGN ("gimp-threshold-tool-dialog",           FALSE),
  FOREIGN ("gimp-perspective-tool-dialog",         FALSE),

  FOREIGN ("gimp-toolbox-color-dialog",            FALSE),
  FOREIGN ("gimp-gradient-editor-color-dialog",    FALSE),
  FOREIGN ("gimp-palette-editor-color-dialog",     FALSE),
  FOREIGN ("gimp-colormap-editor-color-dialog",    FALSE),
78

79
  /*  ordinary toplevels  */
80 81 82 83 84 85 86 87
  TOPLEVEL ("gimp-image-new-dialog",
            dialogs_image_new_new,          FALSE, TRUE, FALSE),
  TOPLEVEL ("gimp-file-open-dialog",
            dialogs_file_open_new,          TRUE,  TRUE, TRUE),
  TOPLEVEL ("gimp-file-open-location-dialog",
            dialogs_file_open_location_new, FALSE, TRUE, FALSE),
  TOPLEVEL ("gimp-file-save-dialog",
            dialogs_file_save_new,          FALSE, TRUE, TRUE),
88 89

  /*  singleton toplevels  */
90 91 92 93 94 95 96 97 98 99 100 101
  TOPLEVEL ("gimp-preferences-dialog",
            dialogs_preferences_get, TRUE, TRUE,  FALSE),
  TOPLEVEL ("gimp-module-dialog",
            dialogs_module_get,      TRUE, TRUE,  TRUE),
  TOPLEVEL ("gimp-tips-dialog",
            dialogs_tips_get,        TRUE, FALSE, FALSE),
  TOPLEVEL ("gimp-about-dialog",
            dialogs_about_get,       TRUE, FALSE, FALSE),
  TOPLEVEL ("gimp-error-dialog",
            dialogs_error_get,       TRUE, FALSE, FALSE),
  TOPLEVEL ("gimp-quit-dialog",
            dialogs_quit_get,        TRUE, FALSE, FALSE)
102 103
};

104 105 106 107 108 109 110 111 112 113 114 115
#define DOCKABLE(id,name,blurb,stock_id,help_id,\
                 new_func,preview_size,singleton) \
  { id, name, blurb, stock_id, help_id, \
    new_func, preview_size, singleton, FALSE, FALSE, TRUE }

#define LISTGRID(id,name,blurb,stock_id,help_id,\
                 preview_size) \
  { "gimp-"#id"-list", name, blurb, stock_id, help_id, \
    dialogs_##id##_list_view_new, preview_size, FALSE, FALSE, FALSE, TRUE }, \
  { "gimp-"#id"-grid", name, blurb, stock_id, help_id, \
    dialogs_##id##_grid_view_new, preview_size, FALSE, FALSE, FALSE, TRUE }

116
static const GimpDialogFactoryEntry dock_entries[] =
117
{
118
  /*  singleton dockables  */
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  DOCKABLE ("gimp-tool-options",
            N_("Tool Options"), NULL, GIMP_STOCK_TOOL_OPTIONS,
            GIMP_HELP_TOOL_OPTIONS_DIALOG,
            dialogs_tool_options_get, 0, TRUE),
  DOCKABLE ("gimp-device-status",
            N_("Devices"), N_("Device Status"), GIMP_STOCK_DEVICE_STATUS,
            GIMP_HELP_DEVICE_STATUS_DIALOG,
            dialogs_device_status_get, 0, TRUE),
  DOCKABLE ("gimp-error-console",
            N_("Errors"), N_("Error Console"), GIMP_STOCK_WARNING,
            GIMP_HELP_ERRORS_DIALOG,
            dialogs_error_console_get, 0, TRUE),

  /*  list & grid views  */
  LISTGRID (image, N_("Images"), NULL, GIMP_STOCK_IMAGES,
            GIMP_HELP_IMAGE_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (brush, N_("Brushes"), NULL, GIMP_STOCK_BRUSH,
            GIMP_HELP_BRUSH_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (pattern, N_("Patterns"), NULL, GIMP_STOCK_PATTERN,
            GIMP_HELP_PATTERN_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (gradient, N_("Gradients"), NULL, GIMP_STOCK_GRADIENT,
            GIMP_HELP_GRADIENT_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (palette, N_("Palettes"), NULL, GIMP_STOCK_PALETTE,
            GIMP_HELP_PALETTE_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (font, N_("Fonts"), NULL, GIMP_STOCK_FONT,
            GIMP_HELP_FONT_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (tool, N_("Tools"), NULL, GIMP_STOCK_TOOLS,
            GIMP_HELP_TOOLS_DIALOG, GIMP_VIEW_SIZE_SMALL),
  LISTGRID (buffer, N_("Buffers"), NULL, GIMP_STOCK_BUFFER,
            GIMP_HELP_BUFFER_DIALOG, GIMP_VIEW_SIZE_MEDIUM),
  LISTGRID (document, N_("History"), N_("Document History"), GTK_STOCK_OPEN,
            GIMP_HELP_DOCUMENT_DIALOG, GIMP_VIEW_SIZE_LARGE),
  LISTGRID (template, N_("Templates"), N_("Image Templates"), GIMP_STOCK_TEMPLATE,
            GIMP_HELP_TEMPLATE_DIALOG, GIMP_VIEW_SIZE_SMALL),
153

154
  /*  image related  */
155 156 157 158 159 160 161 162 163 164 165 166 167
  DOCKABLE ("gimp-layer-list",
            N_("Layers"), NULL, GIMP_STOCK_LAYERS,
            GIMP_HELP_LAYER_DIALOG,
            dialogs_layer_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-channel-list",
            N_("Channels"), NULL, GIMP_STOCK_CHANNELS,
            GIMP_HELP_CHANNEL_DIALOG,
            dialogs_channel_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-vectors-list",
            N_("Paths"), NULL, GIMP_STOCK_PATHS,
            GIMP_HELP_PATH_DIALOG,
            dialogs_vectors_list_view_new, 0, FALSE),
  DOCKABLE ("gimp-indexed-palette",
168
            N_("Colormap"), NULL, GIMP_STOCK_INDEXED_PALETTE,
169 170 171 172 173 174 175 176 177 178 179 180 181 182
            GIMP_HELP_INDEXED_PALETTE_DIALOG,
            dialogs_colormap_editor_new, 0, FALSE),
  DOCKABLE ("gimp-histogram-editor",
            N_("Histogram"), NULL, GIMP_STOCK_HISTOGRAM,
            GIMP_HELP_HISTOGRAM_DIALOG,
            dialogs_histogram_editor_new, 0, FALSE),
  DOCKABLE ("gimp-selection-editor",
            N_("Selection"), N_("Selection Editor"), GIMP_STOCK_SELECTION,
            GIMP_HELP_SELECTION_DIALOG,
            dialogs_selection_editor_new, 0, FALSE),
  DOCKABLE ("gimp-undo-history",
            N_("Undo"), N_("Undo History"), GIMP_STOCK_UNDO_HISTORY,
            GIMP_HELP_UNDO_DIALOG,
            dialogs_undo_editor_new, 0, FALSE),
183

184
  /*  display related  */
185 186 187 188
  DOCKABLE ("gimp-navigation-view",
            N_("Navigation"), N_("Display Navigation"), GIMP_STOCK_NAVIGATION,
            GIMP_HELP_NAVIGATION_DIALOG,
            dialogs_navigation_editor_new, 0, FALSE),
189

190
  /*  editors  */
191 192 193 194
  DOCKABLE ("gimp-color-editor",
            N_("FG/BG"), N_("FG/BG Color"), GIMP_STOCK_DEFAULT_COLORS,
            GIMP_HELP_COLOR_DIALOG,
            dialogs_color_editor_new, 0, FALSE),
195

196
  /*  singleton editors  */
197 198 199 200 201 202 203 204 205 206 207 208
  DOCKABLE ("gimp-brush-editor",
            N_("Brush Editor"), NULL, GIMP_STOCK_BRUSH,
            GIMP_HELP_BRUSH_EDITOR_DIALOG,
            dialogs_brush_editor_get, 0, TRUE),
  DOCKABLE ("gimp-gradient-editor",
            N_("Gradient Editor"), NULL, GIMP_STOCK_GRADIENT,
            GIMP_HELP_GRADIENT_EDITOR_DIALOG,
            dialogs_gradient_editor_get, 0, TRUE),
  DOCKABLE ("gimp-palette-editor",
            N_("Palette Editor"), NULL, GIMP_STOCK_PALETTE,
            GIMP_HELP_PALETTE_EDITOR_DIALOG,
            dialogs_palette_editor_get, 0, TRUE)
209 210 211 212 213
};


/*  public functions  */

214
void
215 216
dialogs_init (Gimp            *gimp,
              GimpMenuFactory *menu_factory)
217
{
218 219
  gint i;

220
  g_return_if_fail (GIMP_IS_GIMP (gimp));
221
  g_return_if_fail (GIMP_IS_MENU_FACTORY (menu_factory));
222

Michael Natterer's avatar
Michael Natterer committed
223 224 225 226
  global_dialog_factory = gimp_dialog_factory_new ("toplevel",
						   gimp_get_user_context (gimp),
						   NULL,
						   NULL);
227

228 229
  global_toolbox_factory = gimp_dialog_factory_new ("toolbox",
                                                    gimp_get_user_context (gimp),
230
                                                    menu_factory,
231
                                                    dialogs_toolbox_get);
232 233
  gimp_dialog_factory_set_constructor (global_toolbox_factory,
                                       dialogs_dockable_constructor);
234

Michael Natterer's avatar
Michael Natterer committed
235 236
  global_dock_factory = gimp_dialog_factory_new ("dock",
						 gimp_get_user_context (gimp),
237
						 menu_factory,
Michael Natterer's avatar
Michael Natterer committed
238
						 dialogs_dock_new);
239 240
  gimp_dialog_factory_set_constructor (global_dock_factory,
                                       dialogs_dockable_constructor);
241

Michael Natterer's avatar
Michael Natterer committed
242
  for (i = 0; i < G_N_ELEMENTS (toplevel_entries); i++)
243 244
    gimp_dialog_factory_register_entry (global_dialog_factory,
					toplevel_entries[i].identifier,
245 246 247 248
					gettext (toplevel_entries[i].name),
					gettext (toplevel_entries[i].blurb),
					toplevel_entries[i].stock_id,
					toplevel_entries[i].help_id,
249
					toplevel_entries[i].new_func,
250
					toplevel_entries[i].preview_size,
251 252
					toplevel_entries[i].singleton,
					toplevel_entries[i].session_managed,
253 254
					toplevel_entries[i].remember_size,
					toplevel_entries[i].remember_if_open);
255

Michael Natterer's avatar
Michael Natterer committed
256
  for (i = 0; i < G_N_ELEMENTS (dock_entries); i++)
257 258
    gimp_dialog_factory_register_entry (global_dock_factory,
					dock_entries[i].identifier,
259 260 261 262
					gettext (dock_entries[i].name),
					gettext (dock_entries[i].blurb),
					dock_entries[i].stock_id,
					dock_entries[i].help_id,
263
					dock_entries[i].new_func,
264
					dock_entries[i].preview_size,
265 266
					dock_entries[i].singleton,
					dock_entries[i].session_managed,
267 268
					dock_entries[i].remember_size,
					dock_entries[i].remember_if_open);
269
}
270 271

void
Michael Natterer's avatar
Michael Natterer committed
272
dialogs_exit (Gimp *gimp)
273
{
274 275
  g_return_if_fail (GIMP_IS_GIMP (gimp));

276 277
  if (global_dialog_factory)
    {
278
      g_object_unref (global_dialog_factory);
279 280 281
      global_dialog_factory = NULL;
    }

282 283 284 285 286 287 288 289
  /*  destroy the "global_toolbox_factory" _before_ destroying the
   *  "global_dock_factory" because the "global_toolbox_factory" owns
   *  dockables which were created by the "global_dock_factory".  This
   *  way they are properly removed from the "global_dock_factory", which
   *  would complain about stale entries otherwise.
   */
  if (global_toolbox_factory)
    {
290
      g_object_unref (global_toolbox_factory);
291 292 293
      global_toolbox_factory = NULL;
    }

294 295
  if (global_dock_factory)
    {
296
      g_object_unref (global_dock_factory);
297 298
      global_dock_factory = NULL;
    }
299
}
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

GtkWidget *
dialogs_get_toolbox (void)
{
  GList *list;

  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (global_toolbox_factory), NULL);

  for (list = global_toolbox_factory->open_dialogs;
       list;
       list = g_list_next (list))
    {
      if (GTK_WIDGET_TOPLEVEL (list->data))
        return list->data;
    }

  return NULL;
}