gimpimagedock.c 5.73 KB
Newer Older
Michael Natterer's avatar
Michael Natterer committed
1
2
3
4
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpimagedock.c
5
 * Copyright (C) 2001-2005 Michael Natterer <mitch@gimp.org>
Michael Natterer's avatar
Michael Natterer committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * 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>

26
#include "widgets-types.h"
Michael Natterer's avatar
Michael Natterer committed
27

28
29
#include "config/gimpguiconfig.h"

30
#include "core/gimp.h"
31
#include "core/gimpcontainer.h"
32
#include "core/gimpcontext.h"
33

Michael Natterer's avatar
Michael Natterer committed
34
35
#include "gimpdialogfactory.h"
#include "gimpimagedock.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "gimpmenufactory.h"
#include "gimpuimanager.h"


static void      gimp_image_dock_class_init      (GimpImageDockClass    *klass);
static void      gimp_image_dock_init            (GimpImageDock         *dock);

static GObject * gimp_image_dock_constructor     (GType                  type,
                                                  guint                  n_params,
                                                  GObjectConstructParam *params);

static void      gimp_image_dock_destroy         (GtkObject             *object);

static void      gimp_image_dock_display_changed (GimpContext           *context,
                                                  GimpObject            *display,
                                                  GimpImageDock         *dock);
static void      gimp_image_dock_image_flush     (GimpImage             *image,
                                                  GimpImageDock         *dock);
Michael Natterer's avatar
Michael Natterer committed
54
55
56
57
58


static GimpDockClass *parent_class = NULL;


59
GType
Michael Natterer's avatar
Michael Natterer committed
60
61
gimp_image_dock_get_type (void)
{
62
  static GType dock_type = 0;
Michael Natterer's avatar
Michael Natterer committed
63
64
65

  if (! dock_type)
    {
66
      static const GTypeInfo dock_info =
Michael Natterer's avatar
Michael Natterer committed
67
      {
68
69
70
71
72
73
74
75
76
        sizeof (GimpImageDockClass),
        NULL,           /* base_init */
        NULL,           /* base_finalize */
        (GClassInitFunc) gimp_image_dock_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GimpImageDock),
        0,              /* n_preallocs */
        (GInstanceInitFunc) gimp_image_dock_init,
Michael Natterer's avatar
Michael Natterer committed
77
78
      };

79
80
81
      dock_type = g_type_register_static (GIMP_TYPE_DOCK,
                                          "GimpImageDock",
                                          &dock_info, 0);
Michael Natterer's avatar
Michael Natterer committed
82
83
84
85
86
87
88
89
    }

  return dock_type;
}

static void
gimp_image_dock_class_init (GimpImageDockClass *klass)
{
90
91
  GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
Michael Natterer's avatar
Michael Natterer committed
92

93
  parent_class = g_type_class_peek_parent (klass);
Michael Natterer's avatar
Michael Natterer committed
94

95
  object_class->constructor = gimp_image_dock_constructor;
96

97
  gtk_object_class->destroy = gimp_image_dock_destroy;
98

99
  klass->ui_manager_name    = "<Dock>";
Michael Natterer's avatar
Michael Natterer committed
100
101
102
103
104
}

static void
gimp_image_dock_init (GimpImageDock *dock)
{
105
106
  dock->ui_manager             = NULL;
  dock->image_flush_handler_id = 0;
Michael Natterer's avatar
Michael Natterer committed
107
108
}

109
110
111
112
static GObject *
gimp_image_dock_constructor (GType                  type,
                             guint                  n_params,
                             GObjectConstructParam *params)
Michael Natterer's avatar
Michael Natterer committed
113
{
114
115
  GObject       *object;
  GimpImageDock *dock;
116
117
  GimpGuiConfig *config;
  GtkAccelGroup *accel_group;
118
119

  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
Michael Natterer's avatar
Michael Natterer committed
120
121
122

  dock = GIMP_IMAGE_DOCK (object);

123
  config = GIMP_GUI_CONFIG (GIMP_DOCK (dock)->context->gimp->config);
124

125
126
127
128
129
  dock->ui_manager =
    gimp_menu_factory_manager_new (GIMP_DOCK (dock)->dialog_factory->menu_factory,
                                   GIMP_IMAGE_DOCK_GET_CLASS (dock)->ui_manager_name,
                                   dock,
                                   config->tearoff_menus);
130

131
132
  accel_group =
    gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (dock->ui_manager));
133

134
  gtk_window_add_accel_group (GTK_WINDOW (object), accel_group);
Michael Natterer's avatar
Michael Natterer committed
135

136
137
138
139
  dock->image_flush_handler_id =
    gimp_container_add_handler (GIMP_DOCK (dock)->context->gimp->images, "flush",
                                G_CALLBACK (gimp_image_dock_image_flush),
                                dock);
Michael Natterer's avatar
Michael Natterer committed
140

141
142
143
  g_signal_connect_object (GIMP_DOCK (dock)->context, "display-changed",
			   G_CALLBACK (gimp_image_dock_display_changed),
			   dock, 0);
144

145
  return object;
146
147
148
}

static void
149
gimp_image_dock_destroy (GtkObject *object)
150
{
151
  GimpImageDock *dock = GIMP_IMAGE_DOCK (object);
152

153
  if (dock->image_flush_handler_id)
154
    {
155
156
157
      gimp_container_remove_handler (GIMP_DOCK (dock)->context->gimp->images,
                                     dock->image_flush_handler_id);
      dock->image_flush_handler_id = 0;
158
    }
159

160
  if (dock->ui_manager)
161
    {
162
163
      g_object_unref (dock->ui_manager);
      dock->ui_manager = NULL;
164
165
    }

166
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
Michael Natterer's avatar
Michael Natterer committed
167
168
}

Michael Natterer's avatar
Michael Natterer committed
169
static void
170
171
172
gimp_image_dock_display_changed (GimpContext   *context,
                                 GimpObject    *display,
                                 GimpImageDock *dock)
Michael Natterer's avatar
Michael Natterer committed
173
{
174
  gimp_ui_manager_update (dock->ui_manager, display);
Michael Natterer's avatar
Michael Natterer committed
175
176
177
}

static void
178
179
gimp_image_dock_image_flush (GimpImage     *image,
                             GimpImageDock *dock)
Michael Natterer's avatar
Michael Natterer committed
180
{
181
  if (image == gimp_context_get_image (GIMP_DOCK (dock)->context))
Michael Natterer's avatar
Michael Natterer committed
182
    {
183
      GimpObject *display = gimp_context_get_display (GIMP_DOCK (dock)->context);
Michael Natterer's avatar
Michael Natterer committed
184

185
186
      if (display)
        gimp_ui_manager_update (dock->ui_manager, display);
Michael Natterer's avatar
Michael Natterer committed
187
188
    }
}