Commit 3d9da82f authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

new functions gimp_window_add_accel_group() and

2001-04-20  Michael Natterer  <mitch@gimp.org>

	* app/gimpui.[ch]: new functions gimp_window_add_accel_group() and
	gimp_window_remove_accel_group() which do the ugly accel context
	hack described below.

	* app/interface.c
	* app/gui/layers-dialog.c: use the new functions.

	* app/disp_callbacks.c
	* app/gui/layers-commands.c: removed stuff which is now done
	automatically.
parent c1e2f4e2
2001-04-20 Michael Natterer <mitch@gimp.org>
* app/gimpui.[ch]: new functions gimp_window_add_accel_group() and
gimp_window_remove_accel_group() which do the ugly accel context
hack described below.
* app/interface.c
* app/gui/layers-dialog.c: use the new functions.
* app/disp_callbacks.c
* app/gui/layers-commands.c: removed stuff which is now done
automatically.
2001-04-20 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
......
......@@ -64,13 +64,8 @@ layers_get_callback_context (GtkWidget *widget)
popup_gimage = (GimpImage *) gtk_item_factory_popup_data_from_widget (widget);
if (ifactory)
{
accel_gimage = (GimpImage *) gtk_object_get_data (GTK_OBJECT (ifactory),
"gimp-accel-context");
if (accel_gimage)
gtk_object_set_data (GTK_OBJECT (ifactory), "gimp-accel-context", NULL);
}
accel_gimage = (GimpImage *) gtk_object_get_data (GTK_OBJECT (ifactory),
"gimp-accel-context");
if (popup_gimage)
return popup_gimage;
......
......@@ -151,10 +151,6 @@ gdisplay_shell_events (GtkWidget *widget,
switch (event->type)
{
case GDK_KEY_PRESS:
gtk_object_set_data (GTK_OBJECT (gdisp->ifactory), "gimp-accel-context",
gdisp->gimage);
/* fallthrough */
case GDK_BUTTON_PRESS:
/* Setting the context's display automatically sets the image, too */
gimp_context_set_display (gimp_context_get_user (), gdisp);
......
......@@ -151,10 +151,6 @@ gdisplay_shell_events (GtkWidget *widget,
switch (event->type)
{
case GDK_KEY_PRESS:
gtk_object_set_data (GTK_OBJECT (gdisp->ifactory), "gimp-accel-context",
gdisp->gimage);
/* fallthrough */
case GDK_BUTTON_PRESS:
/* Setting the context's display automatically sets the image, too */
gimp_context_set_display (gimp_context_get_user (), gdisp);
......
......@@ -151,10 +151,6 @@ gdisplay_shell_events (GtkWidget *widget,
switch (event->type)
{
case GDK_KEY_PRESS:
gtk_object_set_data (GTK_OBJECT (gdisp->ifactory), "gimp-accel-context",
gdisp->gimage);
/* fallthrough */
case GDK_BUTTON_PRESS:
/* Setting the context's display automatically sets the image, too */
gimp_context_set_display (gimp_context_get_user (), gdisp);
......
......@@ -79,6 +79,19 @@ gdisplay_delete (GtkWidget *widget,
return TRUE;
}
static gboolean
gdisplay_get_accel_context (gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
if (gdisp)
return gdisp->gimage;
return NULL;
}
void
create_display_shell (GDisplay *gdisp,
gint width,
......@@ -185,8 +198,10 @@ create_display_shell (GDisplay *gdisp,
gdisp->ifactory = menus_get_image_factory ();
/* The accelerator table for images */
gtk_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory->accel_group);
gimp_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory,
gdisplay_get_accel_context,
gdisp);
/* connect the "F1" help key */
gimp_help_connect_help_accel (gdisp->shell,
......
......@@ -79,6 +79,19 @@ gdisplay_delete (GtkWidget *widget,
return TRUE;
}
static gboolean
gdisplay_get_accel_context (gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
if (gdisp)
return gdisp->gimage;
return NULL;
}
void
create_display_shell (GDisplay *gdisp,
gint width,
......@@ -185,8 +198,10 @@ create_display_shell (GDisplay *gdisp,
gdisp->ifactory = menus_get_image_factory ();
/* The accelerator table for images */
gtk_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory->accel_group);
gimp_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory,
gdisplay_get_accel_context,
gdisp);
/* connect the "F1" help key */
gimp_help_connect_help_accel (gdisp->shell,
......
......@@ -220,3 +220,95 @@ gimp_menu_position (GtkMenu *menu,
*x = MAX (*x, 0);
*y = MAX (*y, 0);
}
typedef struct _GimpAccelContextData GimpAccelContextData;
struct _GimpAccelContextData
{
GtkItemFactory *item_factory;
GimpGetAccelContextFunc get_context_func;
gpointer get_context_data;
};
static gboolean
gimp_window_accel_key_press (GtkWidget *widget,
GdkEvent *event,
GimpAccelContextData *context_data)
{
gpointer accel_context;
accel_context =
context_data->get_context_func (context_data->get_context_data);
gtk_object_set_data (GTK_OBJECT (context_data->item_factory),
"gimp-accel-context", accel_context);
return FALSE;
}
static gboolean
gimp_window_accel_key_release (GtkWidget *widget,
GdkEvent *event,
GimpAccelContextData *context_data)
{
gtk_object_set_data (GTK_OBJECT (context_data->item_factory),
"gimp-accel-context", NULL);
return FALSE;
}
void
gimp_window_add_accel_group (GtkWindow *window,
GtkItemFactory *item_factory,
GimpGetAccelContextFunc get_context_func,
gpointer get_context_data)
{
if (get_context_func)
{
GimpAccelContextData *context_data;
context_data = g_new0 (GimpAccelContextData, 1);
context_data->item_factory = item_factory;
context_data->get_context_func = get_context_func;
context_data->get_context_data = get_context_data;
gtk_object_set_data_full (GTK_OBJECT (window), "gimp-accel-conext-data",
context_data,
(GtkDestroyNotify) g_free);
gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
GTK_SIGNAL_FUNC (gimp_window_accel_key_press),
context_data);
gtk_signal_connect (GTK_OBJECT (window), "key_release_event",
GTK_SIGNAL_FUNC (gimp_window_accel_key_release),
context_data);
}
gtk_window_add_accel_group (window, item_factory->accel_group);
}
void
gimp_window_remove_accel_group (GtkWindow *window,
GtkItemFactory *item_factory)
{
GimpAccelContextData *context_data;
context_data = gtk_object_get_data (GTK_OBJECT (window),
"gimp-accel-conext-data");
if (context_data)
{
gtk_signal_disconnect_by_func (GTK_OBJECT (window),
GTK_SIGNAL_FUNC (gimp_window_accel_key_press),
context_data);
gtk_signal_disconnect_by_func (GTK_OBJECT (window),
GTK_SIGNAL_FUNC (gimp_window_accel_key_release),
context_data);
gtk_object_set_data (GTK_OBJECT (window), "gimp-accel-conext-data", NULL);
}
gtk_window_remove_accel_group (window, item_factory->accel_group);
}
......@@ -23,17 +23,25 @@
#define __GIMP_UI_H__
/* a simple message box */
void gimp_message_box (gchar *message,
GtkCallback callback,
gpointer data);
void gimp_message_box (gchar *message,
GtkCallback callback,
gpointer data);
void gimp_dialog_hide (GtkWidget *dialog);
void gimp_dialog_hide (GtkWidget *dialog);
void gimp_menu_position (GtkMenu *menu,
gint *x,
gint *y);
void gimp_menu_position (GtkMenu *menu,
gint *x,
gint *y);
typedef gpointer (* GimpGetAccelContextFunc) (gpointer data);
void gimp_window_add_accel_group (GtkWindow *window,
GtkItemFactory *item_factory,
GimpGetAccelContextFunc get_context_func,
gpointer get_context_data);
void gimp_window_remove_accel_group (GtkWindow *window,
GtkItemFactory *item_factory);
#endif /* __GIMP_UI_H__ */
......@@ -64,13 +64,8 @@ layers_get_callback_context (GtkWidget *widget)
popup_gimage = (GimpImage *) gtk_item_factory_popup_data_from_widget (widget);
if (ifactory)
{
accel_gimage = (GimpImage *) gtk_object_get_data (GTK_OBJECT (ifactory),
"gimp-accel-context");
if (accel_gimage)
gtk_object_set_data (GTK_OBJECT (ifactory), "gimp-accel-context", NULL);
}
accel_gimage = (GimpImage *) gtk_object_get_data (GTK_OBJECT (ifactory),
"gimp-accel-context");
if (popup_gimage)
return popup_gimage;
......
......@@ -1501,16 +1501,17 @@ layer_list_events (GtkWidget *widget,
/* layers dialog callbacks */
/*****************************/
static gboolean
layers_dialog_button_press (GtkWidget *widget,
GdkEvent *event,
LayersDialog *layers_dialog)
static gpointer
layers_dialog_get_accel_context (gpointer data)
{
gtk_object_set_data (GTK_OBJECT (layers_dialog->ifactory),
"gimp-accel-context",
layers_dialog->gimage);
LayersDialog *layers_dialog;
return FALSE;
layers_dialog = (LayersDialog *) data;
if (layers_dialog)
return layers_dialog->gimage;
return NULL;
}
static void
......@@ -1520,12 +1521,10 @@ layers_dialog_map_callback (GtkWidget *widget,
if (! layersD)
return;
gtk_signal_connect (GTK_OBJECT (lc_dialog->shell), "key_press_event",
GTK_SIGNAL_FUNC (layers_dialog_button_press),
layersD);
gtk_window_add_accel_group (GTK_WINDOW (lc_dialog->shell),
layersD->ifactory->accel_group);
gimp_window_add_accel_group (GTK_WINDOW (lc_dialog->shell),
layersD->ifactory,
layers_dialog_get_accel_context,
layersD);
}
static void
......@@ -1535,12 +1534,8 @@ layers_dialog_unmap_callback (GtkWidget *widget,
if (! layersD)
return;
gtk_signal_disconnect_by_func (GTK_OBJECT (lc_dialog->shell),
GTK_SIGNAL_FUNC (layers_dialog_button_press),
layersD);
gtk_window_remove_accel_group (GTK_WINDOW (lc_dialog->shell),
layersD->ifactory->accel_group);
gimp_window_remove_accel_group (GTK_WINDOW (lc_dialog->shell),
layersD->ifactory);
}
/***************************/
......
......@@ -79,6 +79,19 @@ gdisplay_delete (GtkWidget *widget,
return TRUE;
}
static gboolean
gdisplay_get_accel_context (gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
if (gdisp)
return gdisp->gimage;
return NULL;
}
void
create_display_shell (GDisplay *gdisp,
gint width,
......@@ -185,8 +198,10 @@ create_display_shell (GDisplay *gdisp,
gdisp->ifactory = menus_get_image_factory ();
/* The accelerator table for images */
gtk_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory->accel_group);
gimp_window_add_accel_group (GTK_WINDOW (gdisp->shell),
gdisp->ifactory,
gdisplay_get_accel_context,
gdisp);
/* connect the "F1" help key */
gimp_help_connect_help_accel (gdisp->shell,
......
......@@ -220,3 +220,95 @@ gimp_menu_position (GtkMenu *menu,
*x = MAX (*x, 0);
*y = MAX (*y, 0);
}
typedef struct _GimpAccelContextData GimpAccelContextData;
struct _GimpAccelContextData
{
GtkItemFactory *item_factory;
GimpGetAccelContextFunc get_context_func;
gpointer get_context_data;
};
static gboolean
gimp_window_accel_key_press (GtkWidget *widget,
GdkEvent *event,
GimpAccelContextData *context_data)
{
gpointer accel_context;
accel_context =
context_data->get_context_func (context_data->get_context_data);
gtk_object_set_data (GTK_OBJECT (context_data->item_factory),
"gimp-accel-context", accel_context);
return FALSE;
}
static gboolean
gimp_window_accel_key_release (GtkWidget *widget,
GdkEvent *event,
GimpAccelContextData *context_data)
{
gtk_object_set_data (GTK_OBJECT (context_data->item_factory),
"gimp-accel-context", NULL);
return FALSE;
}
void
gimp_window_add_accel_group (GtkWindow *window,
GtkItemFactory *item_factory,
GimpGetAccelContextFunc get_context_func,
gpointer get_context_data)
{
if (get_context_func)
{
GimpAccelContextData *context_data;
context_data = g_new0 (GimpAccelContextData, 1);
context_data->item_factory = item_factory;
context_data->get_context_func = get_context_func;
context_data->get_context_data = get_context_data;
gtk_object_set_data_full (GTK_OBJECT (window), "gimp-accel-conext-data",
context_data,
(GtkDestroyNotify) g_free);
gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
GTK_SIGNAL_FUNC (gimp_window_accel_key_press),
context_data);
gtk_signal_connect (GTK_OBJECT (window), "key_release_event",
GTK_SIGNAL_FUNC (gimp_window_accel_key_release),
context_data);
}
gtk_window_add_accel_group (window, item_factory->accel_group);
}
void
gimp_window_remove_accel_group (GtkWindow *window,
GtkItemFactory *item_factory)
{
GimpAccelContextData *context_data;
context_data = gtk_object_get_data (GTK_OBJECT (window),
"gimp-accel-conext-data");
if (context_data)
{
gtk_signal_disconnect_by_func (GTK_OBJECT (window),
GTK_SIGNAL_FUNC (gimp_window_accel_key_press),
context_data);
gtk_signal_disconnect_by_func (GTK_OBJECT (window),
GTK_SIGNAL_FUNC (gimp_window_accel_key_release),
context_data);
gtk_object_set_data (GTK_OBJECT (window), "gimp-accel-conext-data", NULL);
}
gtk_window_remove_accel_group (window, item_factory->accel_group);
}
......@@ -23,17 +23,25 @@
#define __GIMP_UI_H__
/* a simple message box */
void gimp_message_box (gchar *message,
GtkCallback callback,
gpointer data);
void gimp_message_box (gchar *message,
GtkCallback callback,
gpointer data);
void gimp_dialog_hide (GtkWidget *dialog);
void gimp_dialog_hide (GtkWidget *dialog);
void gimp_menu_position (GtkMenu *menu,
gint *x,
gint *y);
void gimp_menu_position (GtkMenu *menu,
gint *x,
gint *y);
typedef gpointer (* GimpGetAccelContextFunc) (gpointer data);
void gimp_window_add_accel_group (GtkWindow *window,
GtkItemFactory *item_factory,
GimpGetAccelContextFunc get_context_func,
gpointer get_context_data);
void gimp_window_remove_accel_group (GtkWindow *window,
GtkItemFactory *item_factory);
#endif /* __GIMP_UI_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment