dialogs.c 9.89 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
#include "gui-types.h"
24

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

28 29
#include "widgets/gimpdialogfactory.h"

30 31
#include "menus/menus.h"

32 33 34 35
#include "dialogs.h"
#include "dialogs-constructors.h"


36 37 38
GimpDialogFactory *global_dialog_factory  = NULL;
GimpDialogFactory *global_dock_factory    = NULL;
GimpDialogFactory *global_toolbox_factory = NULL;
39 40


41
static const GimpDialogFactoryEntry toplevel_entries[] =
42
{
43
  /*  foreign toplevels without constructor  */
44 45 46 47 48
  { "gimp-file-open-dialog",
    NULL, 0, TRUE,  TRUE,  TRUE,  FALSE },
  { "gimp-file-save-dialog",
    NULL, 0, TRUE,  TRUE,  TRUE,  FALSE },

49 50 51
  { "gimp-brightness-contrast-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-color-picker-tool-dialog",
52
    NULL, 0, TRUE,  TRUE,  TRUE, FALSE },
53 54
  { "gimp-colorize-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
55 56 57 58 59 60 61 62 63
  { "gimp-crop-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-curves-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-color-balance-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-hue-saturation-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-levels-tool-dialog",
64
    NULL, 0, TRUE,  TRUE,  TRUE, FALSE },
65 66
  { "gimp-measure-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
67 68 69 70 71 72 73 74
  { "gimp-posterize-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-rotate-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-scale-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-shear-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
75 76
  { "gimp-text-tool-dialog",
    NULL, 0, TRUE,  TRUE,  TRUE,  FALSE },
77 78 79 80 81
  { "gimp-threshold-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-perspective-tool-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },

82 83 84 85 86 87 88 89 90 91
  { "gimp-toolbox-color-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-gradient-editor-color-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },
  { "gimp-palette-editor-color-dialog",
    NULL, 0, TRUE,  TRUE,  FALSE, FALSE },

  { "gimp-colormap-editor-color-dialog",
    NULL, 0, FALSE, TRUE,  FALSE, FALSE },

92
  /*  ordinary toplevels  */
93 94 95
  { "gimp-file-new-dialog",           dialogs_file_new_new,
    0, FALSE, TRUE,  FALSE, FALSE },
  { "gimp-file-open-location-dialog", dialogs_file_open_location_new,
96 97 98
    0, FALSE, TRUE,  FALSE, FALSE },

  /*  singleton toplevels  */
99
  { "gimp-preferences-dialog",     dialogs_preferences_get,
100
    0, TRUE,  TRUE,  FALSE, FALSE },
101
  { "gimp-module-manager-dialog",  dialogs_module_browser_get,
102
    0, TRUE,  TRUE,  TRUE,  FALSE },
103
  { "gimp-tips-dialog",            dialogs_tips_get,
104
    0, TRUE,  FALSE, FALSE, FALSE },
105
  { "gimp-about-dialog",           dialogs_about_get,
106 107
    0, TRUE,  FALSE, FALSE, FALSE },
  { "gimp-error-dialog",           dialogs_error_get,
108
    0, TRUE,  FALSE, FALSE, FALSE }
109 110
};

111
static const GimpDialogFactoryEntry dock_entries[] =
112
{
113
  /*  singleton dockables  */
114 115
  { "gimp-tool-options",     dialogs_tool_options_get,
    0, TRUE,  FALSE, FALSE, TRUE },
116 117
  { "gimp-device-status",    dialogs_device_status_get,
    0, TRUE,  FALSE, FALSE, TRUE  },
118 119 120
  { "gimp-error-console",    dialogs_error_console_get,
    0, TRUE,  FALSE, FALSE, TRUE },

121
  /*  list views  */
122
  { "gimp-image-list",       dialogs_image_list_view_new,
123
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
124
  { "gimp-brush-list",       dialogs_brush_list_view_new,
125
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
126
  { "gimp-pattern-list",     dialogs_pattern_list_view_new,
127
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
128
  { "gimp-gradient-list",    dialogs_gradient_list_view_new,
129
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
130
  { "gimp-palette-list",     dialogs_palette_list_view_new,
131
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
132
  { "gimp-font-list",        dialogs_font_list_view_new,
133
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
134
  { "gimp-tool-list",        dialogs_tool_list_view_new,
135
    GIMP_VIEW_SIZE_SMALL, FALSE, FALSE, FALSE, TRUE },
136
  { "gimp-buffer-list",      dialogs_buffer_list_view_new,
137
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
138
  { "gimp-document-list",    dialogs_document_list_new,
139
    GIMP_VIEW_SIZE_LARGE,  FALSE, FALSE, FALSE, TRUE },
140
  { "gimp-template-list",    dialogs_template_list_new,
141
    GIMP_VIEW_SIZE_SMALL,  FALSE, FALSE, FALSE, TRUE },
142

143
  /*  grid views  */
144
  { "gimp-image-grid",       dialogs_image_grid_view_new,
145
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
146
  { "gimp-brush-grid",       dialogs_brush_grid_view_new,
147
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
148
  { "gimp-pattern-grid",     dialogs_pattern_grid_view_new,
149
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
150
  { "gimp-gradient-grid",    dialogs_gradient_grid_view_new,
151
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
152
  { "gimp-palette-grid",     dialogs_palette_grid_view_new,
153
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
154
  { "gimp-font-grid",        dialogs_font_grid_view_new,
155
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
156
  { "gimp-tool-grid",        dialogs_tool_grid_view_new,
157
    GIMP_VIEW_SIZE_SMALL, FALSE, FALSE, FALSE, TRUE },
158
  { "gimp-buffer-grid",      dialogs_buffer_grid_view_new,
159
    GIMP_VIEW_SIZE_MEDIUM, FALSE, FALSE, FALSE, TRUE },
160
  { "gimp-document-grid",    dialogs_document_grid_new,
161
    GIMP_VIEW_SIZE_LARGE,  FALSE, FALSE, FALSE, TRUE },
162

163
  /*  image related  */
164 165 166 167 168 169 170 171
  { "gimp-layer-list",       dialogs_layer_list_view_new,
    0, FALSE, FALSE, FALSE, TRUE },
  { "gimp-channel-list",     dialogs_channel_list_view_new,
    0, FALSE, FALSE, FALSE, TRUE },
  { "gimp-vectors-list",     dialogs_vectors_list_view_new,
    0, FALSE, FALSE, FALSE, TRUE },
  { "gimp-indexed-palette",  dialogs_indexed_palette_new,
    0, FALSE, FALSE, FALSE, TRUE },
172 173
  { "gimp-histogram-editor", dialogs_histogram_editor_new,
    0, FALSE, FALSE, FALSE, TRUE },
174 175 176 177 178
  { "gimp-selection-editor", dialogs_selection_editor_new,
    0, FALSE, FALSE, FALSE, TRUE },
  { "gimp-undo-history",     dialogs_undo_history_new,
    0, FALSE, FALSE, FALSE, TRUE },

179 180
  /*  display related  */
  { "gimp-navigation-view",  dialogs_navigation_view_new,
181 182
    0, FALSE, FALSE, FALSE, TRUE },

183 184 185
  /*  editors  */
  { "gimp-color-editor",     dialogs_color_editor_new,
    0, FALSE, FALSE, FALSE, TRUE },
186

187
  /*  singleton editors  */
188 189 190 191 192 193
  { "gimp-brush-editor",     dialogs_brush_editor_get,
    0, TRUE,  FALSE, FALSE, TRUE },
  { "gimp-gradient-editor",  dialogs_gradient_editor_get,
    0, TRUE,  FALSE, FALSE, TRUE },
  { "gimp-palette-editor",   dialogs_palette_editor_get,
    0, TRUE,  FALSE, FALSE, TRUE },
194 195 196 197 198
};


/*  public functions  */

199
void
Michael Natterer's avatar
Michael Natterer committed
200
dialogs_init (Gimp *gimp)
201
{
202 203
  gint i;

204 205
  g_return_if_fail (GIMP_IS_GIMP (gimp));

Michael Natterer's avatar
Michael Natterer committed
206 207 208 209
  global_dialog_factory = gimp_dialog_factory_new ("toplevel",
						   gimp_get_user_context (gimp),
						   NULL,
						   NULL);
210

211 212
  global_toolbox_factory = gimp_dialog_factory_new ("toolbox",
                                                    gimp_get_user_context (gimp),
213
                                                    global_menu_factory,
214 215
                                                    dialogs_toolbox_get);

Michael Natterer's avatar
Michael Natterer committed
216 217
  global_dock_factory = gimp_dialog_factory_new ("dock",
						 gimp_get_user_context (gimp),
218
						 global_menu_factory,
Michael Natterer's avatar
Michael Natterer committed
219
						 dialogs_dock_new);
220

Michael Natterer's avatar
Michael Natterer committed
221
  for (i = 0; i < G_N_ELEMENTS (toplevel_entries); i++)
222 223 224
    gimp_dialog_factory_register_entry (global_dialog_factory,
					toplevel_entries[i].identifier,
					toplevel_entries[i].new_func,
225
					toplevel_entries[i].preview_size,
226 227
					toplevel_entries[i].singleton,
					toplevel_entries[i].session_managed,
228 229
					toplevel_entries[i].remember_size,
					toplevel_entries[i].remember_if_open);
230

Michael Natterer's avatar
Michael Natterer committed
231
  for (i = 0; i < G_N_ELEMENTS (dock_entries); i++)
232 233 234
    gimp_dialog_factory_register_entry (global_dock_factory,
					dock_entries[i].identifier,
					dock_entries[i].new_func,
235
					dock_entries[i].preview_size,
236 237
					dock_entries[i].singleton,
					dock_entries[i].session_managed,
238 239
					dock_entries[i].remember_size,
					dock_entries[i].remember_if_open);
240
}
241 242

void
Michael Natterer's avatar
Michael Natterer committed
243
dialogs_exit (Gimp *gimp)
244
{
245 246
  g_return_if_fail (GIMP_IS_GIMP (gimp));

247 248
  if (global_dialog_factory)
    {
249
      g_object_unref (global_dialog_factory);
250 251 252
      global_dialog_factory = NULL;
    }

253 254 255 256 257 258 259 260
  /*  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)
    {
261
      g_object_unref (global_toolbox_factory);
262 263 264
      global_toolbox_factory = NULL;
    }

265 266
  if (global_dock_factory)
    {
267
      g_object_unref (global_dock_factory);
268 269
      global_dock_factory = NULL;
    }
270
}
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

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;
}