1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * gimpdocked.c
5  * Copyright (C) 2003  Michael Natterer <mitch@gimp.org>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include "config.h"
22 
23 #include <string.h>
24 
25 #include <gegl.h>
26 #include <gtk/gtk.h>
27 
28 #include "widgets-types.h"
29 
30 #include "core/gimpcontext.h"
31 #include "core/gimpmarshal.h"
32 
33 #include "gimpdocked.h"
34 #include "gimpsessioninfo-aux.h"
35 
36 
37 enum
38 {
39   TITLE_CHANGED,
40   LAST_SIGNAL
41 };
42 
43 
44 /*  local function prototypes  */
45 
46 static void    gimp_docked_iface_set_aux_info (GimpDocked *docked,
47                                                GList      *aux_info);
48 static GList * gimp_docked_iface_get_aux_info (GimpDocked *docked);
49 
50 
51 G_DEFINE_INTERFACE (GimpDocked, gimp_docked, GTK_TYPE_WIDGET)
52 
53 
54 static guint docked_signals[LAST_SIGNAL] = { 0 };
55 
56 
57 /*  private functions  */
58 
59 
60 static void
gimp_docked_default_init(GimpDockedInterface * iface)61 gimp_docked_default_init (GimpDockedInterface *iface)
62 {
63   docked_signals[TITLE_CHANGED] =
64     g_signal_new ("title-changed",
65                   GIMP_TYPE_DOCKED,
66                   G_SIGNAL_RUN_FIRST,
67                   G_STRUCT_OFFSET (GimpDockedInterface, title_changed),
68                   NULL, NULL,
69                   gimp_marshal_VOID__VOID,
70                   G_TYPE_NONE, 0);
71 
72   iface->get_aux_info = gimp_docked_iface_get_aux_info;
73   iface->set_aux_info = gimp_docked_iface_set_aux_info;
74 }
75 
76 #define AUX_INFO_SHOW_BUTTON_BAR "show-button-bar"
77 
78 static void
gimp_docked_iface_set_aux_info(GimpDocked * docked,GList * aux_info)79 gimp_docked_iface_set_aux_info (GimpDocked *docked,
80                                 GList      *aux_info)
81 {
82   GList *list;
83 
84   for (list = aux_info; list; list = g_list_next (list))
85     {
86       GimpSessionInfoAux *aux = list->data;
87 
88       if (strcmp (aux->name, AUX_INFO_SHOW_BUTTON_BAR) == 0)
89         {
90           gboolean show = g_ascii_strcasecmp (aux->value, "false");
91 
92           gimp_docked_set_show_button_bar (docked, show);
93         }
94     }
95 }
96 
97 static GList *
gimp_docked_iface_get_aux_info(GimpDocked * docked)98 gimp_docked_iface_get_aux_info (GimpDocked *docked)
99 {
100   if (gimp_docked_has_button_bar (docked))
101     {
102       gboolean show = gimp_docked_get_show_button_bar (docked);
103 
104       return g_list_append (NULL,
105                             gimp_session_info_aux_new (AUX_INFO_SHOW_BUTTON_BAR,
106                                                        show ? "true" : "false"));
107     }
108 
109   return NULL;
110 }
111 
112 
113 /*  public functions  */
114 
115 
116 void
gimp_docked_title_changed(GimpDocked * docked)117 gimp_docked_title_changed (GimpDocked *docked)
118 {
119   g_return_if_fail (GIMP_IS_DOCKED (docked));
120 
121   g_signal_emit (docked, docked_signals[TITLE_CHANGED], 0);
122 }
123 
124 void
gimp_docked_set_aux_info(GimpDocked * docked,GList * aux_info)125 gimp_docked_set_aux_info (GimpDocked *docked,
126                           GList      *aux_info)
127 {
128   GimpDockedInterface *docked_iface;
129 
130   g_return_if_fail (GIMP_IS_DOCKED (docked));
131 
132   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
133 
134   if (docked_iface->set_aux_info)
135     docked_iface->set_aux_info (docked, aux_info);
136 }
137 
138 GList *
gimp_docked_get_aux_info(GimpDocked * docked)139 gimp_docked_get_aux_info (GimpDocked *docked)
140 {
141   GimpDockedInterface *docked_iface;
142 
143   g_return_val_if_fail (GIMP_IS_DOCKED (docked), NULL);
144 
145   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
146 
147   if (docked_iface->get_aux_info)
148     return docked_iface->get_aux_info (docked);
149 
150   return NULL;
151 }
152 
153 GtkWidget *
gimp_docked_get_preview(GimpDocked * docked,GimpContext * context,GtkIconSize size)154 gimp_docked_get_preview (GimpDocked  *docked,
155                          GimpContext *context,
156                          GtkIconSize  size)
157 {
158   GimpDockedInterface *docked_iface;
159 
160   g_return_val_if_fail (GIMP_IS_DOCKED (docked), NULL);
161 
162   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
163 
164   if (docked_iface->get_preview)
165     return docked_iface->get_preview (docked, context, size);
166 
167   return NULL;
168 }
169 
170 gboolean
gimp_docked_get_prefer_icon(GimpDocked * docked)171 gimp_docked_get_prefer_icon (GimpDocked *docked)
172 {
173   GimpDockedInterface *docked_iface;
174 
175   g_return_val_if_fail (GIMP_IS_DOCKED (docked), FALSE);
176 
177   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
178 
179   if (docked_iface->get_prefer_icon)
180     return docked_iface->get_prefer_icon (docked);
181 
182   return FALSE;
183 }
184 
185 GimpUIManager *
gimp_docked_get_menu(GimpDocked * docked,const gchar ** ui_path,gpointer * popup_data)186 gimp_docked_get_menu (GimpDocked     *docked,
187                       const gchar   **ui_path,
188                       gpointer       *popup_data)
189 {
190   GimpDockedInterface *docked_iface;
191 
192   g_return_val_if_fail (GIMP_IS_DOCKED (docked), NULL);
193   g_return_val_if_fail (ui_path != NULL, NULL);
194   g_return_val_if_fail (popup_data != NULL, NULL);
195 
196   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
197 
198   if (docked_iface->get_menu)
199     return docked_iface->get_menu (docked, ui_path, popup_data);
200 
201   return NULL;
202 }
203 
204 gchar *
gimp_docked_get_title(GimpDocked * docked)205 gimp_docked_get_title (GimpDocked *docked)
206 {
207   GimpDockedInterface *docked_iface;
208 
209   g_return_val_if_fail (GIMP_IS_DOCKED (docked), NULL);
210 
211   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
212 
213   if (docked_iface->get_title)
214     return docked_iface->get_title (docked);
215 
216   return NULL;
217 }
218 
219 void
gimp_docked_set_context(GimpDocked * docked,GimpContext * context)220 gimp_docked_set_context (GimpDocked  *docked,
221                          GimpContext *context)
222 {
223   GimpDockedInterface *docked_iface;
224 
225   g_return_if_fail (GIMP_IS_DOCKED (docked));
226   g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
227 
228   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
229 
230   if (docked_iface->set_context)
231     docked_iface->set_context (docked, context);
232 }
233 
234 gboolean
gimp_docked_has_button_bar(GimpDocked * docked)235 gimp_docked_has_button_bar (GimpDocked *docked)
236 {
237   GimpDockedInterface *docked_iface;
238 
239   g_return_val_if_fail (GIMP_IS_DOCKED (docked), FALSE);
240 
241   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
242 
243   if (docked_iface->has_button_bar)
244     return docked_iface->has_button_bar (docked);
245 
246   return FALSE;
247 }
248 
249 void
gimp_docked_set_show_button_bar(GimpDocked * docked,gboolean show)250 gimp_docked_set_show_button_bar (GimpDocked *docked,
251                                  gboolean    show)
252 {
253   GimpDockedInterface *docked_iface;
254 
255   g_return_if_fail (GIMP_IS_DOCKED (docked));
256 
257   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
258 
259   if (docked_iface->set_show_button_bar)
260     docked_iface->set_show_button_bar (docked, show ? TRUE : FALSE);
261 }
262 
263 gboolean
gimp_docked_get_show_button_bar(GimpDocked * docked)264 gimp_docked_get_show_button_bar (GimpDocked *docked)
265 {
266   GimpDockedInterface *docked_iface;
267 
268   g_return_val_if_fail (GIMP_IS_DOCKED (docked), FALSE);
269 
270   docked_iface = GIMP_DOCKED_GET_INTERFACE (docked);
271 
272   if (docked_iface->get_show_button_bar)
273     return docked_iface->get_show_button_bar (docked);
274 
275   return FALSE;
276 }
277