diff --git a/plug-ins/imagemap/imap_about.c b/plug-ins/imagemap/imap_about.c index 81b4414845..0b34844e4f 100644 --- a/plug-ins/imagemap/imap_about.c +++ b/plug-ins/imagemap/imap_about.c @@ -30,7 +30,9 @@ #include "libgimp/stdplugins-intl.h" void -do_about_dialog(void) +do_about_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static GtkWidget *dialog; if (!dialog) diff --git a/plug-ins/imagemap/imap_about.h b/plug-ins/imagemap/imap_about.h index 4834a75547..cf30eeb392 100644 --- a/plug-ins/imagemap/imap_about.h +++ b/plug-ins/imagemap/imap_about.h @@ -23,6 +23,8 @@ #ifndef _IMAP_ABOUT_H #define _IMAP_ABOUT_H -void do_about_dialog(void); +void do_about_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); #endif /* _IMAP_ABOUT_H */ diff --git a/plug-ins/imagemap/imap_file.c b/plug-ins/imagemap/imap_file.c index 45bb059bf2..97aa1621b0 100644 --- a/plug-ins/imagemap/imap_file.c +++ b/plug-ins/imagemap/imap_file.c @@ -49,7 +49,7 @@ open_cb (GtkWidget *dialog, return; } - load (filename); + load (filename, data); g_free (filename); } @@ -57,7 +57,9 @@ open_cb (GtkWidget *dialog, } void -do_file_open_dialog (void) +do_file_open_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static GtkWidget *dialog; @@ -84,7 +86,7 @@ do_file_open_dialog (void) &dialog); g_signal_connect (dialog, "response", G_CALLBACK (open_cb), - dialog); + user_data); } gtk_window_present (GTK_WINDOW (dialog)); @@ -109,7 +111,9 @@ save_cb (GtkWidget *dialog, } void -do_file_save_as_dialog (void) +do_file_save_as_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static GtkWidget *dialog; diff --git a/plug-ins/imagemap/imap_file.h b/plug-ins/imagemap/imap_file.h index c661eaa3db..e3e8af3fe6 100644 --- a/plug-ins/imagemap/imap_file.h +++ b/plug-ins/imagemap/imap_file.h @@ -23,9 +23,14 @@ #ifndef _IMAP_FILE_H #define _IMAP_FILE_H -void do_file_open_dialog(void); -void do_file_save_as_dialog(void); -void do_file_error_dialog(const char *error, const char *filename); +void do_file_open_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_file_save_as_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_file_error_dialog (const char *error, + const char *filename); gboolean load_csim (const char* filename); gboolean load_cern (const char* filename); diff --git a/plug-ins/imagemap/imap_grid.c b/plug-ins/imagemap/imap_grid.c index e4d425f2cd..bccac86f1b 100644 --- a/plug-ins/imagemap/imap_grid.c +++ b/plug-ins/imagemap/imap_grid.c @@ -68,12 +68,13 @@ static gint grid_top = 0; static GridType_t grid_type = GRID_LINES; static void -grid_settings_ok_cb(gpointer data) +grid_settings_ok_cb (gpointer data) { - GridDialog_t *param = (GridDialog_t*) data; - gboolean new_snap; + GimpImap *imap = GIMP_IMAP (data); + GridDialog_t *param = (GridDialog_t*) imap->grid_data; + gboolean new_snap; - new_snap = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(param->snap)); + new_snap = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (param->snap)); grid_width = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(param->width)); grid_height = gtk_spin_button_get_value_as_int( @@ -83,18 +84,24 @@ grid_settings_ok_cb(gpointer data) grid_top = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(param->top)); - if (grid_snap != new_snap) { - grid_snap = new_snap; - menu_check_grid(grid_snap); - } + if (grid_snap != new_snap) + { + GAction *action; + + grid_snap = new_snap; + + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "grid"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), grid_snap); + } preview_redraw(); } static void -snap_toggled_cb(GtkWidget *widget, gpointer data) +snap_toggled_cb (GtkWidget *widget, + gpointer data) { GridDialog_t *param = (GridDialog_t*) data; - gint sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + gint sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); gtk_widget_set_sensitive(param->type_frame, sensitive); gtk_widget_set_sensitive(param->granularity_frame, sensitive); @@ -170,7 +177,7 @@ left_changed_cb(GtkWidget *widget, gpointer data) } static void -top_changed_cb(GtkWidget *widget, gpointer data) +top_changed_cb (GtkWidget *widget, gpointer data) { GridDialog_t *dialog = (GridDialog_t*) data; @@ -183,18 +190,21 @@ top_changed_cb(GtkWidget *widget, gpointer data) } static GridDialog_t* -create_grid_settings_dialog(void) +create_grid_settings_dialog (gpointer user_data) { - GridDialog_t *data = g_new(GridDialog_t, 1); + GimpImap *imap = GIMP_IMAP (user_data); + GridDialog_t *data = g_new (GridDialog_t, 1); DefaultDialog_t *dialog; - GtkWidget *main_grid, *grid, *label; - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *button; - GtkWidget *chain_button; + GtkWidget *main_grid, *grid, *label; + GtkWidget *frame; + GtkWidget *hbox; + GtkWidget *button; + GtkWidget *chain_button; data->dialog = dialog = make_default_dialog(_("Grid Settings")); - default_dialog_set_ok_cb(dialog, grid_settings_ok_cb, (gpointer) data); + imap->grid_data = data; + + default_dialog_set_ok_cb (dialog, grid_settings_ok_cb, (gpointer) imap); main_grid = default_dialog_add_grid (dialog); data->snap = gtk_check_button_new_with_mnemonic(_("_Snap-to grid enabled")); @@ -290,7 +300,7 @@ create_grid_settings_dialog(void) G_CALLBACK (toggle_preview_cb), (gpointer) data); gtk_widget_show(data->preview); - snap_toggled_cb(data->snap, data); + snap_toggled_cb (data->snap, data); gtk_widget_show(grid); gtk_widget_show(frame); @@ -299,19 +309,21 @@ create_grid_settings_dialog(void) } void -do_grid_settings_dialog(void) +do_grid_settings_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static GridDialog_t* dialog; GtkWidget *type; if (!dialog) - dialog = create_grid_settings_dialog(); + dialog = create_grid_settings_dialog (user_data); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->snap), grid_snap); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->width), grid_width); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->height), grid_height); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->left), grid_left); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(dialog->top), grid_top); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->snap), grid_snap); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->width), grid_width); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->height), grid_height); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->left), grid_left); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->top), grid_top); if (grid_type == GRID_HIDDEN) type = dialog->hidden; @@ -319,9 +331,9 @@ do_grid_settings_dialog(void) type = dialog->lines; else type = dialog->crosses; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(type), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(type), TRUE); - default_dialog_show(dialog->dialog); + default_dialog_show (dialog->dialog); } static void @@ -352,7 +364,9 @@ draw_crosses(cairo_t *cr, gint width, gint height) } void -draw_grid(cairo_t *cr, gint width, gint height) +draw_grid (cairo_t *cr, + gint width, + gint height) { if (grid_snap && grid_type != GRID_HIDDEN) { @@ -370,28 +384,38 @@ draw_grid(cairo_t *cr, gint width, gint height) } void -toggle_grid(void) +toggle_grid (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { - grid_snap = !grid_snap; - preview_redraw(); + GtkToggleToolButton *grid_toggle; + + grid_snap = ! grid_snap; + preview_redraw(); + + g_simple_action_set_state (action, new_state); + grid_toggle = GTK_TOGGLE_TOOL_BUTTON (GIMP_IMAP (user_data)->grid_toggle); + + gtk_toggle_tool_button_set_active (grid_toggle, grid_snap); } static gint -grid_nearest_x(gint x) +grid_nearest_x (gint x) { return grid_left + (x - grid_left + grid_width / 2) / grid_width * grid_width; } static gint -grid_nearest_y(gint y) +grid_nearest_y (gint y) { return grid_top + (y - grid_top + grid_height / 2) / grid_height * grid_height; } void -round_to_grid(gint *x, gint *y) +round_to_grid (gint *x, + gint *y) { if (grid_snap) { *x = grid_nearest_x(*x); diff --git a/plug-ins/imagemap/imap_grid.h b/plug-ins/imagemap/imap_grid.h index 84deb95988..a5fedcdec3 100644 --- a/plug-ins/imagemap/imap_grid.h +++ b/plug-ins/imagemap/imap_grid.h @@ -23,12 +23,19 @@ #ifndef _IMAP_GRID_H #define _IMAP_GRID_H -void do_grid_settings_dialog (void); -void draw_grid (cairo_t *cr, gint width, gint height); -void toggle_grid (void); -void round_to_grid (gint *x, gint *y); +void do_grid_settings_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void draw_grid (cairo_t *cr, + gint width, + gint height); +void toggle_grid (GSimpleAction *action, + GVariant *new_state, + gpointer user_data); +void round_to_grid (gint *x, + gint *y); -gboolean grid_near_x (gint x); -gboolean grid_near_y (gint y); +gboolean grid_near_x (gint x); +gboolean grid_near_y (gint y); #endif /* _IMAP_GRID_H */ diff --git a/plug-ins/imagemap/imap_icons.h b/plug-ins/imagemap/imap_icons.h index 7b56d41517..195d2b568d 100644 --- a/plug-ins/imagemap/imap_icons.h +++ b/plug-ins/imagemap/imap_icons.h @@ -23,16 +23,16 @@ #ifndef _IMAP_ICONS_H #define _IMAP_ICONS_H -#define IMAP_ARROW "imap-arrow" -#define IMAP_CIRCLE "imap-circle" -#define IMAP_COORD "imap-coord" -#define IMAP_DIMENSION "imap-dimension" -#define IMAP_JAVA "imap-java" -#define IMAP_LINK "imap-link" -#define IMAP_POLYGON "imap-polygon" -#define IMAP_RECTANGLE "imap-rectangle" -#define IMAP_TO_BACK "imap-to-back" -#define IMAP_TO_FRONT "imap-to-front" +#define IMAP_ARROW "imagemap-arrow" +#define IMAP_CIRCLE "imagemap-circle" +#define IMAP_COORD "imagemap-coord" +#define IMAP_DIMENSION "imagemap-dimension" +#define IMAP_JAVA "imagemap-java" +#define IMAP_LINK "imagemap-link" +#define IMAP_POLYGON "imagemap-polygon" +#define IMAP_RECTANGLE "imagemap-rectangle" +#define IMAP_TO_BACK "imagemap-to-back" +#define IMAP_TO_FRONT "imagemap-to-front" void init_icons (void); diff --git a/plug-ins/imagemap/imap_main.c b/plug-ins/imagemap/imap_main.c index 7c794c916a..9d92fcf0aa 100644 --- a/plug-ins/imagemap/imap_main.c +++ b/plug-ins/imagemap/imap_main.c @@ -39,6 +39,7 @@ #include "imap_default_dialog.h" #include "imap_edit_area_info.h" #include "imap_file.h" +#include "imap_grid.h" #include "imap_icons.h" #include "imap_main.h" #include "imap_menu.h" @@ -61,25 +62,10 @@ #define GET_REAL_COORD(x) ((x) / _zoom_factor) -typedef struct _Imap Imap; -typedef struct _ImapClass ImapClass; - -struct _Imap -{ - GimpPlugIn parent_instance; -}; - -struct _ImapClass -{ - GimpPlugInClass parent_class; -}; - - -#define IMAP_TYPE (imap_get_type ()) -#define IMAP (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IMAP_TYPE, Imap)) - GType imap_get_type (void) G_GNUC_CONST; +static void gimp_imap_finalize (GObject *object); + static GList * imap_query_procedures (GimpPlugIn *plug_in); static GimpProcedure * imap_create_procedure (GimpPlugIn *plug_in, const gchar *name); @@ -92,14 +78,21 @@ static GimpValueArray * imap_run (GimpProcedure *procedure, const GimpValueArray *args, gpointer run_data); -static gint dialog (GimpDrawable *drawable); -static gint zoom_in (void); -static gint zoom_out (void); +static gint dialog (GimpImap *imap); +static gint zoom_in (gpointer data); +static gint zoom_out (gpointer data); + +static void on_app_activate (GApplication *gapp, + gpointer user_data); +static void window_destroy (GtkWidget *widget, + gpointer data); -G_DEFINE_TYPE (Imap, imap, GIMP_TYPE_PLUG_IN) -GIMP_MAIN (IMAP_TYPE) + +G_DEFINE_TYPE (GimpImap, gimp_imap, GIMP_TYPE_PLUG_IN) + +GIMP_MAIN (GIMP_TYPE_IMAP) DEFINE_STD_SET_I18N @@ -127,11 +120,60 @@ static gpointer _button_press_param; static int run_flag = 0; +static const GActionEntry ACTIONS[] = +{ + /* Sub-menu options */ + { "open", do_file_open_dialog }, + { "save", save }, + { "save-as", do_file_save_as_dialog }, + { "close", do_close }, + { "quit", do_quit }, + + { "cut", do_cut }, + { "copy", do_copy }, + { "paste", do_paste }, + { "select-all", do_select_all }, + { "deselect-all", do_deselect_all }, + { "clear", do_clear }, + { "undo", do_undo }, + { "redo", do_redo }, + { "zoom-in", do_zoom_in }, + { "zoom-out", do_zoom_out }, + { "move-to-front", do_move_to_front }, + { "send-to-back", do_send_to_back }, + { "move-up", do_move_up }, + { "move-down", do_move_down }, + { "insert-point", polygon_insert_point }, + { "delete-point", polygon_delete_point }, + + { "preferences", do_preferences_dialog }, + { "source", do_source_dialog }, + { "edit-area-info", do_edit_selected_shape }, + { "edit-map-info", do_settings_dialog }, + { "grid-settings", do_grid_settings_dialog }, + { "use-gimp-guides", do_use_gimp_guides_dialog }, + { "create-guides", do_create_guides_dialog }, + + { "contents", imap_help }, + { "about", do_about_dialog }, + + /* Toggle Options */ + { "grid", NULL, NULL, "false", toggle_grid }, + { "area-list", NULL, NULL, "true", toggle_area_list }, + + /* Radio Options */ + { "zoom", set_zoom_factor, "s", "'1'", NULL }, + { "colormode", set_preview_color, "s", "'color'", NULL }, + { "shape", set_func, "s", "'arrow'", NULL }, +}; static void -imap_class_init (ImapClass *klass) +gimp_imap_class_init (GimpImapClass *klass) { - GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass); + GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = gimp_imap_finalize; plug_in_class->query_procedures = imap_query_procedures; plug_in_class->create_procedure = imap_create_procedure; @@ -139,10 +181,20 @@ imap_class_init (ImapClass *klass) } static void -imap_init (Imap *imap) +gimp_imap_init (GimpImap *imap) { } +static void +gimp_imap_finalize (GObject *object) +{ + GimpImap *imap = GIMP_IMAP (object); + + G_OBJECT_CLASS (gimp_imap_parent_class)->finalize (object); + + g_clear_object (&imap->builder); +} + static GList * imap_query_procedures (GimpPlugIn *plug_in) { @@ -151,7 +203,7 @@ imap_query_procedures (GimpPlugIn *plug_in) static GimpProcedure * imap_create_procedure (GimpPlugIn *plug_in, - const gchar *name) + const gchar *name) { GimpProcedure *procedure = NULL; @@ -183,15 +235,395 @@ imap_create_procedure (GimpPlugIn *plug_in, static GimpValueArray * imap_run (GimpProcedure *procedure, - GimpRunMode run_mode, - GimpImage *image, - gint n_drawables, - GimpDrawable **drawables, - const GimpValueArray *args, - gpointer run_data) + GimpRunMode run_mode, + GimpImage *image, + gint n_drawables, + GimpDrawable **drawables, + const GimpValueArray *args, + gpointer run_data) { + GimpImap *imap; + gegl_init (NULL, NULL); + imap = GIMP_IMAP (gimp_procedure_get_plug_in (procedure)); + imap->app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE); + imap->success = FALSE; + + imap->builder = gtk_builder_new_from_string ( + "" + "" + "" + "File" + "
" + "" + "Open" + "app.open" + "" + "" + "Save" + "app.save" + "" + "" + "Save As" + "app.save-as" + "" + "
" + "
" + "" + "Close" + "app.close" + "" + "" + "Quit" + "app.quit" + "" + "
" + "
" + "" + "Edit" + "
" + "" + "Undo" + "app.undo" + "" + "" + "Redo" + "app.redo" + "" + "" + "Cut" + "app.cut" + "" + "" + "Copy" + "app.copy" + "" + "" + "Paste" + "app.paste" + "" + "" + "Clear" + "app.clear" + "" + "
" + "
" + "" + "Select All" + "app.select-all" + "" + "" + "Deselect All" + "app.deselect-all" + "" + "
" + "
" + "" + "Edit Area Info" + "app.edit-area-info" + "" + "
" + "
" + "" + "Preferences" + "app.preferences" + "" + "
" + "
" + "" + "View" + "
" + "" + "Area List" + "app.area-list" + "" + "" + "Source..." + "app.source" + "" + "
" + "
" + "" + "Color" + "app.colormode" + "color" + "" + "" + "Gray" + "app.colormode" + "gray" + "" + "
" + "
" + "" + "Zoom In" + "app.zoom-in" + "" + "" + "Zoom Out" + "app.zoom-out" + "" + "" + "Zoom To" + "
" + "" + "1:1" + "app.zoom" + "1" + "" + "" + "1:2" + "app.zoom" + "2" + "" + "" + "1:3" + "app.zoom" + "3" + "" + "" + "1:4" + "app.zoom" + "4" + "" + "" + "1:5" + "app.zoom" + "5" + "" + "" + "1:6" + "app.zoom" + "6" + "" + "" + "1:7" + "app.zoom" + "7" + "" + "" + "1:8" + "app.zoom" + "8" + "" + "
" + "
" + "
" + "
" + "" + "Mappings" + "
" + "" + "Arrow" + "app.shape" + "arrow" + "" + "" + "Rectangle" + "app.shape" + "rectangle" + "" + "" + "Circle" + "app.shape" + "circle" + "" + "" + "Polygon" + "app.shape" + "polygon" + "" + "
" + "
" + "" + "Edit Map Info..." + "app.edit-map-info" + "" + "
" + "
" + "" + "Tools" + "
" + "" + "Grid" + "app.grid" + "" + "" + "Grid Settings..." + "app.grid-settings" + "" + "
" + "
" + "" + "Use GIMP Guides..." + "app.use-gimp-guides" + "" + "" + "Create Guides..." + "app.create-guides" + "" + "
" + "
" + "" + "Help" + "
" + "" + "Contents" + "app.contents" + "" + "" + "About" + "app.about" + "" + "
" + "
" + "
" + + "" + "
" + "" + "Move Up" + "app.move-up" + "" + "" + "Move Down" + "app.move-down" + "" + "
" + "
" + + "" + "
" + "" + "Edit Map Info..." + "app.edit-map-info" + "" + "" + "Tools" + "
" + "" + "Arrow" + "app.shape" + "arrow" + "" + "" + "Rectangle" + "app.shape" + "rectangle" + "" + "" + "Circle" + "app.shape" + "circle" + "" + "" + "Polygon" + "app.shape" + "polygon" + "" + "
" + "
" + "" + "Zoom" + "
" + "" + "Zoom In" + "app.zoom-in" + "" + "" + "Zoom Out" + "app.zoom-out" + "" + "
" + "
" + "" + "Grid" + "app.grid" + "" + "" + "Grid Settings..." + "app.grid-settings" + "" + "" + "Create Guides..." + "app.create-guides" + "" + "" + "Paste" + "app.paste" + "" + "
" + "
" + + "" + "
" + "" + "Edit Area Info..." + "app.edit-area-info" + "" + "" + "Delete Area" + "app.clear" + "" + "" + "Move Up" + "app.move-up" + "" + "" + "Move Down" + "app.move-down" + "" + "" + "Cut" + "app.cut" + "" + "" + "Copy" + "app.copy" + "" + "
" + "
" + + "" + "
" + "" + "Insert Point" + "app.insert-point" + "" + "" + "Delete Point" + "app.delete-point" + "" + "" + "Edit Area Info..." + "app.edit-area-info" + "" + "" + "Delete Area" + "app.delete-area" + "" + "" + "Move Up" + "app.move-up" + "" + "" + "Move Down" + "app.move-down" + "" + "" + "Cut" + "app.cut" + "" + "" + "Copy" + "app.copy" + "" + "
" + "
" + "
", + -1); + if (n_drawables != 1) { GError *error = NULL; @@ -214,13 +646,18 @@ imap_run (GimpProcedure *procedure, _image_height = gimp_image_get_height (image); _map_info.color = gimp_drawable_is_rgb (_drawable); + imap->drawable = _drawable; if (run_mode != GIMP_RUN_INTERACTIVE) return gimp_procedure_new_return_values (procedure, GIMP_PDB_CALLING_ERROR, NULL); - if (! dialog (_drawable)) + g_signal_connect (imap->app, "activate", G_CALLBACK (on_app_activate), imap); + g_application_run (G_APPLICATION (imap->app), 0, NULL); + g_clear_object (&imap->app); + + if (! imap->success) return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, NULL); @@ -231,107 +668,109 @@ imap_run (GimpProcedure *procedure, } GtkWidget* -get_dialog(void) +get_dialog (void) { return _dlg; } MRU_t* -get_mru(void) +get_mru (void) { - if (!_mru) - _mru = mru_create(); - return _mru; + if (!_mru) + _mru = mru_create(); + return _mru; } MapInfo_t* -get_map_info(void) +get_map_info (void) { - return &_map_info; + return &_map_info; } PreferencesData_t* -get_preferences(void) +get_preferences (void) { - return &_preferences; + return &_preferences; } static void -init_preferences(void) +init_preferences (void) { - ColorSelData_t *colors = &_preferences.colors; + ColorSelData_t *colors = &_preferences.colors; - colors->normal_fg.red = 0; - colors->normal_fg.green = 0xFFFF; - colors->normal_fg.blue = 0; + colors->normal_fg.red = 0; + colors->normal_fg.green = 0xFFFF; + colors->normal_fg.blue = 0; - colors->normal_bg.red = 0; - colors->normal_bg.green = 0; - colors->normal_bg.blue = 0xFFFF; + colors->normal_bg.red = 0; + colors->normal_bg.green = 0; + colors->normal_bg.blue = 0xFFFF; - colors->selected_fg.red = 0xFFFF; - colors->selected_fg.green = 0; - colors->selected_fg.blue = 0; + colors->selected_fg.red = 0xFFFF; + colors->selected_fg.green = 0; + colors->selected_fg.blue = 0; - colors->selected_bg.red = 0; - colors->selected_bg.green = 0; - colors->selected_bg.blue = 0xFFFF; + colors->selected_bg.red = 0; + colors->selected_bg.green = 0; + colors->selected_bg.blue = 0xFFFF; - colors->interactive_fg.red = 0xFFFF; - colors->interactive_fg.green = 0; - colors->interactive_fg.blue = 0xFFFF; + colors->interactive_fg.red = 0xFFFF; + colors->interactive_fg.green = 0; + colors->interactive_fg.blue = 0xFFFF; - colors->interactive_bg.red = 0xFFFF; - colors->interactive_bg.green = 0xFFFF; - colors->interactive_bg.blue = 0; + colors->interactive_bg.red = 0xFFFF; + colors->interactive_bg.green = 0xFFFF; + colors->interactive_bg.blue = 0; - preferences_load(&_preferences); + preferences_load (&_preferences); - mru_set_size(_mru, _preferences.mru_size); - command_list_set_undo_level(_preferences.undo_levels); + mru_set_size (_mru, _preferences.mru_size); + command_list_set_undo_level (_preferences.undo_levels); } gint -get_image_width(void) +get_image_width (void) { - return _image_width; + return _image_width; } gint -get_image_height(void) +get_image_height (void) { - return _image_height; + return _image_height; } void -set_busy_cursor(void) +set_busy_cursor (void) { - preview_set_cursor(_preview, GDK_WATCH); + preview_set_cursor(_preview, GDK_WATCH); } void -remove_busy_cursor(void) +remove_busy_cursor (void) { gdk_window_set_cursor(gtk_widget_get_window (_dlg), NULL); } static gint -zoom_in(void) +zoom_in (gpointer data) { - if (_zoom_factor < MAX_ZOOM_FACTOR) { - set_zoom(_zoom_factor + 1); - menu_set_zoom(_zoom_factor); - } + if (_zoom_factor < MAX_ZOOM_FACTOR) + { + set_zoom (_zoom_factor + 1); + menu_set_zoom (data, _zoom_factor); + } return _zoom_factor; } static gint -zoom_out(void) +zoom_out (gpointer data) { - if (_zoom_factor > 1) { - set_zoom(_zoom_factor - 1); - menu_set_zoom(_zoom_factor); - } + if (_zoom_factor > 1) + { + set_zoom (_zoom_factor - 1); + menu_set_zoom (data, _zoom_factor); + } return _zoom_factor; } @@ -393,11 +832,23 @@ draw_polygon(cairo_t *cr, GList *list) } void -set_preview_color (GtkRadioAction *action, GtkRadioAction *current, - gpointer user_data) +set_preview_color (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { - _map_info.show_gray = (gtk_radio_action_get_current_value (current) == 1); - set_zoom(_zoom_factor); + gchar *str; + + str = g_strdup_printf ("%s", g_variant_get_string (new_state, NULL)); + + if (! strcmp (str, "gray")) + _map_info.show_gray = 1; + else + _map_info.show_gray = 0; + + g_free (str); + g_simple_action_set_state (action, new_state); + + set_zoom (_zoom_factor); } void @@ -407,11 +858,20 @@ preview_redraw(void) } void -set_zoom_factor (GtkRadioAction *action, GtkRadioAction *current, - gpointer user_data) +set_zoom_factor (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { - gint factor = gtk_radio_action_get_current_value (current); - set_zoom (factor + 1); + gchar *str; + gint factor = 1; + + str = g_strdup_printf ("%s", g_variant_get_string (new_state, NULL)); + factor = atoi (str); + g_free (str); + + set_zoom (factor); + + g_simple_action_set_state (action, new_state); } const gchar * @@ -433,29 +893,30 @@ arrow_on_button_press (GtkWidget *widget, { if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { - do_popup_menu (event); + do_popup_menu (event, data); } else if (event->button == 1) { if (event->type == GDK_2BUTTON_PRESS) - edit_shape((gint) event->x, (gint) event->y); + edit_shape ((gint) event->x, (gint) event->y); else - select_shape(widget, event); + select_shape (widget, event); } return FALSE; } static void -set_arrow_func(void) +set_arrow_func (gpointer data) { - _button_press_func = arrow_on_button_press; - _cursor = GDK_TOP_LEFT_ARROW; + _button_press_func = arrow_on_button_press; + _button_press_param = data; + _cursor = GDK_TOP_LEFT_ARROW; } static void -set_object_func(gboolean (*func)(GtkWidget*, GdkEventButton*, - gpointer), gpointer param) +set_object_func (gboolean (*func)(GtkWidget*, GdkEventButton*, + gpointer), gpointer param) { _button_press_func = func; _button_press_param = param; @@ -463,27 +924,44 @@ set_object_func(gboolean (*func)(GtkWidget*, GdkEventButton*, } void -set_func(GtkRadioAction *action, GtkRadioAction *current, - gpointer user_data) +set_func (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { - gint value = gtk_radio_action_get_current_value (current); + gchar *str; + gint value = 0; + + str = g_strdup_printf ("%s", g_variant_get_string (new_state, NULL)); + if (! strcmp (str, "arrow")) + value = 0; + else if (! strcmp (str, "rectangle")) + value = 1; + else if (! strcmp (str, "circle")) + value = 2; + else if (! strcmp (str, "polygon")) + value = 3; + + g_free (str); + switch (value) { case 0: - set_arrow_func(); + set_arrow_func (user_data); break; case 1: - set_object_func(object_on_button_press, get_rectangle_factory); + set_object_func (object_on_button_press, get_rectangle_factory); break; case 2: - set_object_func(object_on_button_press, get_circle_factory); + set_object_func (object_on_button_press, get_circle_factory); break; case 3: - set_object_func(object_on_button_press, get_polygon_factory); + set_object_func (object_on_button_press, get_polygon_factory); break; default: break; } + + g_simple_action_set_state (action, new_state); } void @@ -505,33 +983,36 @@ update_shape(Object_t *obj) } void -do_edit_selected_shape(void) +do_edit_selected_shape (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { object_list_edit_selected(_shapes); } void -do_popup_menu(GdkEventButton *event) +do_popup_menu (GdkEventButton *event, + gpointer data) { - gint x = GET_REAL_COORD((gint) event->x); - gint y = GET_REAL_COORD((gint) event->y); - Object_t *obj = object_list_find(_shapes, x, y); - if (obj) { - obj->class->do_popup(obj, event); - } else { - do_main_popup_menu(event); - } + gint x = GET_REAL_COORD((gint) event->x); + gint y = GET_REAL_COORD((gint) event->y); + Object_t *obj = object_list_find (_shapes, x, y); + + if (obj) + obj->class->do_popup (obj, event, data); + else + do_main_popup_menu (event, data); } static void -set_all_sensitivities(void) +set_all_sensitivities (gpointer data) { - gint count = object_list_nr_selected(_shapes); - menu_shapes_selected(count); + gint count = object_list_nr_selected (_shapes); + menu_shapes_selected (count, data); } static void -main_set_title(const char *filename) +main_set_title (const char *filename) { char *title, *p; @@ -552,33 +1033,34 @@ main_set_dimension(gint width, gint height) } void -main_clear_dimension(void) +main_clear_dimension (void) { - statusbar_clear_dimension(_statusbar); + statusbar_clear_dimension (_statusbar); } void -show_url(void) +show_url (void) { _show_url = TRUE; } void -hide_url(void) +hide_url (void) { _show_url = FALSE; statusbar_clear_status(_statusbar); } void -select_shape(GtkWidget *widget, GdkEventButton *event) +select_shape (GtkWidget *widget, + GdkEventButton *event) { Object_t *obj; - gint x = GET_REAL_COORD((gint) event->x); - gint y = GET_REAL_COORD((gint) event->y); + gint x = GET_REAL_COORD ((gint) event->x); + gint y = GET_REAL_COORD ((gint) event->y); MoveSashFunc_t sash_func; - obj = object_list_near_sash(_shapes, x, y, &sash_func); + obj = object_list_near_sash (_shapes, x, y, &sash_func); if (obj) { /* Start resizing */ Command_t *command = move_sash_command_new(widget, obj, x, y, sash_func); command_execute(command); @@ -634,17 +1116,21 @@ edit_shape(gint x, gint y) } void -do_zoom_in(void) +do_zoom_in (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - gint factor = zoom_in(); - menu_set_zoom_sensitivity(factor); + gint factor = zoom_in (user_data); + menu_set_zoom_sensitivity (user_data, factor); } void -do_zoom_out(void) +do_zoom_out (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - gint factor = zoom_out(); - menu_set_zoom_sensitivity(factor); + gint factor = zoom_out (user_data); + menu_set_zoom_sensitivity (user_data, factor); } void @@ -654,7 +1140,7 @@ draw_shapes(cairo_t *cr) } static void -clear_map_info(void) +clear_map_info (void) { const gchar *author = g_get_real_name(); @@ -671,26 +1157,28 @@ clear_map_info(void) } static void -do_data_changed_dialog(void (*continue_cb)(gpointer), gpointer param) +do_data_changed_dialog (void (*continue_cb)(gpointer), + gpointer param) { - GtkWidget *dialog = gtk_message_dialog_new - (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("Some data has been changed!")); - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - _("Do you really want to discard your changes?")); + GtkWidget *dialog = gtk_message_dialog_new + (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("Some data has been changed!")); + gtk_message_dialog_format_secondary_text + (GTK_MESSAGE_DIALOG (dialog), + _("Do you really want to discard your changes?")); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) - continue_cb (param); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) + continue_cb (param); - gtk_widget_destroy (dialog); + gtk_widget_destroy (dialog); } static void -check_if_changed(void (*func)(gpointer), gpointer param) +check_if_changed (void (*func)(gpointer), + gpointer param) { if (object_list_get_changed (_shapes)) do_data_changed_dialog (func, param); @@ -699,76 +1187,96 @@ check_if_changed(void (*func)(gpointer), gpointer param) } static void -close_current(void) +close_current (gpointer data) { - selection_freeze(_selection); - object_list_remove_all(_shapes); - selection_thaw(_selection); - clear_map_info(); - main_set_title(NULL); - set_all_sensitivities(); - preview_redraw(); - object_list_clear_changed(_shapes); - command_list_remove_all(); + selection_freeze (_selection); + object_list_remove_all (_shapes); + selection_thaw (_selection); + clear_map_info (); + main_set_title (NULL); + set_all_sensitivities (data); + preview_redraw (); + object_list_clear_changed (_shapes); + command_list_remove_all (); } static void -really_close(gpointer data) +really_close (gpointer data) { - close_current(); + close_current (data); } void -do_close(void) +do_close (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - check_if_changed(really_close, NULL); + check_if_changed (really_close, user_data); } static void -really_quit(gpointer data) +really_quit (gpointer data) { - preferences_save(&_preferences); - run_flag = 1; - gtk_widget_destroy(_dlg); + GimpImap *imap = NULL; + + if (data) + { + imap = GIMP_IMAP (data); + imap->success = TRUE; + } + + preferences_save (&_preferences); + run_flag = 1; + + window_destroy (_dlg, imap); } void -do_quit(void) +do_quit (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - check_if_changed(really_quit, NULL); + check_if_changed (really_quit, user_data); } void -do_undo(void) +do_undo (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - selection_freeze(_selection); - last_command_undo(); - selection_thaw(_selection); - preview_redraw(); + selection_freeze (_selection); + last_command_undo (); + selection_thaw (_selection); + preview_redraw (); } void -do_redo(void) +do_redo (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - selection_freeze(_selection); - last_command_redo(); - selection_thaw(_selection); - preview_redraw(); + selection_freeze (_selection); + last_command_redo (); + selection_thaw (_selection); + preview_redraw (); } void -save(void) +save (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { - if (_filename) - save_as(_filename); - else - do_file_save_as_dialog(); + if (_filename) + save_as (_filename); + else + do_file_save_as_dialog (NULL, NULL, NULL); } static void -write_cern_comment(gpointer param, OutputFunc_t output) +write_cern_comment (gpointer param, + OutputFunc_t output) { - output(param, "rect (4096,4096) (4096,4096) imap:#$"); + output(param, "rect (4096,4096) (4096,4096) imap:#$"); } static void @@ -864,18 +1372,22 @@ static void save_to_file (gpointer param, const char *format, ...) G_GNUC_PRINTF(2,3); -static void -save_to_file(gpointer param, const char* format, ...) -{ - va_list ap; - va_start(ap, format); - vfprintf((FILE*)param, format, ap); - va_end(ap); +static void +save_to_file (gpointer param, + const char* format, + ...) +{ + va_list ap; + + va_start (ap, format); + vfprintf ((FILE*) param, format, ap); + va_end(ap); } void -dump_output(gpointer param, OutputFunc_t output) +dump_output (gpointer param, + OutputFunc_t output) { if (_map_info.map_format == NCSA) save_as_ncsa(param, output); @@ -886,7 +1398,7 @@ dump_output(gpointer param, OutputFunc_t output) } void -save_as(const gchar *filename) +save_as (const gchar *filename) { FILE *out = g_fopen(filename, "w"); if (out) { @@ -902,7 +1414,7 @@ save_as(const gchar *filename) } static void -do_image_size_changed_dialog(void) +do_image_size_changed_dialog (void) { GtkWidget *dialog = gtk_message_dialog_new_with_markup (NULL, @@ -925,62 +1437,77 @@ do_image_size_changed_dialog(void) } static void -really_load(gpointer data) +really_load (gpointer data) { - gchar *filename = (gchar*) data; - close_current(); + GimpImap *imap = GIMP_IMAP (data); + gchar *filename = imap->tmp_filename; + close_current (imap); - selection_freeze(_selection); - _map_info.old_image_width = _image_width; - _map_info.old_image_height = _image_height; - if (load_csim(filename)) { + selection_freeze(_selection); + _map_info.old_image_width = _image_width; + _map_info.old_image_height = _image_height; + if (load_csim(filename)) + { _map_info.map_format = CSIM; if (_image_width != _map_info.old_image_width || - _image_height != _map_info.old_image_height) { - do_image_size_changed_dialog(); - } - } else if (load_ncsa(filename)) { - _map_info.map_format = NCSA; - } else if (load_cern(filename)) { - _map_info.map_format = CERN; - } else { - do_file_error_dialog( _("Couldn't read file:"), filename); - selection_thaw(_selection); - close_current(); - return; - } + _image_height != _map_info.old_image_height) + { + do_image_size_changed_dialog(); + } + } + else if (load_ncsa(filename)) + { + _map_info.map_format = NCSA; + } + else if (load_cern(filename)) + { + _map_info.map_format = CERN; + } + else + { + do_file_error_dialog ( _("Couldn't read file:"), filename); + selection_thaw(_selection); + close_current (imap); + return; + } mru_set_first(_mru, filename); - menu_build_mru_items(_mru); - selection_thaw(_selection); - main_set_title(filename); - object_list_clear_changed(_shapes); - preview_redraw(); + selection_thaw (_selection); + main_set_title (filename); + object_list_clear_changed (_shapes); + preview_redraw (); } void -load(const gchar *filename) +load (const gchar *filename, + gpointer data) { - static gchar *tmp_filename; - g_strreplace(&tmp_filename, filename); - check_if_changed(really_load, (gpointer) tmp_filename); + GimpImap *imap = GIMP_IMAP (data); + + g_strreplace (&imap->tmp_filename, filename); + check_if_changed (really_load, imap); } void -toggle_area_list(void) +toggle_area_list (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { selection_toggle_visibility(_selection); + g_simple_action_set_state (action, new_state); } static gboolean -close_callback(GtkWidget *widget, gpointer data) +close_callback (GtkWidget *widget, + gpointer data) { - do_quit(); - return TRUE; + do_quit (NULL, NULL, NULL); + return TRUE; } static gboolean -preview_move(GtkWidget *widget, GdkEventMotion *event) +preview_move (GtkWidget *widget, + GdkEventMotion *event) { gint x = GET_REAL_COORD((gint) event->x); gint y = GET_REAL_COORD((gint) event->y); @@ -1024,10 +1551,12 @@ preview_leave(GtkWidget *widget, GdkEventCrossing *event) } static gboolean -button_press(GtkWidget* widget, GdkEventButton* event, gpointer data) +button_press (GtkWidget* widget, + GdkEventButton* event, + gpointer data) { if (_button_press_func) - return _button_press_func(widget, event, _button_press_param); + return _button_press_func (widget, event, _button_press_param); return FALSE; } @@ -1039,20 +1568,24 @@ static guint _keyval; static gint _dx, _dy; static void -move_sash_selected_objects(gint dx, gint dy, gboolean fast) +move_sash_selected_objects (gint dx, + gint dy, + gboolean fast) { if (fast) { dx *= 5; dy *= 5; } - object_list_move_sash_selected(_shapes, dx, dy); + object_list_move_sash_selected (_shapes, dx, dy); preview_redraw (); } static void -move_selected_objects(gint dx, gint dy, gboolean fast) +move_selected_objects (gint dx, + gint dy, + gboolean fast) { if (fast) { dx *= 5; @@ -1141,7 +1674,7 @@ key_press_cb(GtkWidget *widget, GdkEventKey *event) } static gboolean -key_release_cb(GtkWidget *widget, GdkEventKey *event) +key_release_cb (GtkWidget *widget, GdkEventKey *event) { _keyval = event->keyval; _timeout = g_timeout_add(250, key_timeout_cb, NULL); @@ -1149,68 +1682,87 @@ key_release_cb(GtkWidget *widget, GdkEventKey *event) } static void -geometry_changed(Object_t *obj, gpointer data) +geometry_changed (Object_t *obj, + gpointer data) { preview_redraw(); } static void -data_changed(Object_t *obj, gpointer data) +data_changed (Object_t *obj, + gpointer data) { - preview_redraw(); - set_all_sensitivities(); + preview_redraw (); + set_all_sensitivities (data); } static void -data_selected(Object_t *obj, gpointer data) +data_selected (Object_t *obj, + gpointer data) { - set_all_sensitivities(); + set_all_sensitivities (data); } void -imap_help (void) +imap_help (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { gimp_standard_help_func ("plug-in-imagemap", NULL); } void -do_cut (void) +do_cut (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (cut_command_new (_shapes)); } void -do_copy (void) +do_copy (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (copy_command_new (_shapes)); } void -do_paste (void) +do_paste (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (paste_command_new (_shapes)); } void -do_select_all(void) +do_select_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (select_all_command_new (_shapes)); } void -do_deselect_all(void) +do_deselect_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (unselect_all_command_new (_shapes, NULL)); } void -do_clear(void) +do_clear (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (clear_command_new(_shapes)); } void -do_move_up(void) +do_move_up (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { /* Fix me! Command_t *command = object_up_command_new(_current_obj->list, @@ -1220,7 +1772,9 @@ do_move_up(void) } void -do_move_down(void) +do_move_down (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { /* Fix me! Command_t *command = object_down_command_new(_current_obj->list, @@ -1230,25 +1784,33 @@ do_move_down(void) } void -do_move_to_front(void) +do_move_to_front (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute(move_to_front_command_new(_shapes)); } void -do_send_to_back(void) +do_send_to_back (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute(send_to_back_command_new(_shapes)); } void -do_use_gimp_guides_dialog(void) +do_use_gimp_guides_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (gimp_guides_command_new (_shapes, _drawable)); } void -do_create_guides_dialog(void) +do_create_guides_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { command_execute (guides_command_new (_shapes)); } @@ -1266,100 +1828,266 @@ factory_move_down(void) } static gint -dialog (GimpDrawable *drawable) +dialog (GimpImap *imap) { - GtkWidget *dlg; - GtkWidget *hbox; - GtkWidget *main_vbox; - GtkWidget *tools; + GtkWidget *hbox; + GtkWidget *menubar; + GMenuModel *model; + GtkWidget *toolbar; + GtkWidget *main_vbox; + GtkWidget *tools; - gimp_ui_init (PLUG_IN_BINARY); + gimp_ui_init (PLUG_IN_BINARY); - set_arrow_func (); + set_arrow_func (imap); - _shapes = make_object_list(); + _shapes = make_object_list(); - _dlg = dlg = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_resizable(GTK_WINDOW(dlg), TRUE); + _dlg = imap->dlg = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_resizable (GTK_WINDOW (imap->dlg), TRUE); - main_set_title(NULL); - gimp_help_connect (dlg, gimp_standard_help_func, PLUG_IN_PROC, NULL, NULL); + main_set_title (NULL); + gimp_help_connect (imap->dlg, gimp_standard_help_func, PLUG_IN_PROC, NULL, NULL); - gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); + gtk_window_set_position (GTK_WINDOW (imap->dlg), GTK_WIN_POS_MOUSE); - gimp_window_set_transient (GTK_WINDOW (dlg)); + gtk_window_set_application (GTK_WINDOW (_dlg), imap->app); + gimp_window_set_transient (GTK_WINDOW (imap->dlg)); - g_signal_connect (dlg, "delete-event", - G_CALLBACK (close_callback), NULL); - g_signal_connect (dlg, "key-press-event", - G_CALLBACK (key_press_cb), NULL); - g_signal_connect (dlg, "key-release-event", - G_CALLBACK (key_release_cb), NULL); + g_action_map_add_action_entries (G_ACTION_MAP (imap->app), + ACTIONS, G_N_ELEMENTS (ACTIONS), + imap); - g_signal_connect (dlg, "destroy", - G_CALLBACK (gtk_main_quit), - NULL); + g_signal_connect (imap->dlg, "delete-event", + G_CALLBACK (close_callback), NULL); + g_signal_connect (imap->dlg, "key-press-event", + G_CALLBACK (key_press_cb), NULL); + g_signal_connect (imap->dlg, "key-release-event", + G_CALLBACK (key_release_cb), NULL); - main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add (GTK_CONTAINER (dlg), main_vbox); - gtk_widget_show (main_vbox); + g_signal_connect (imap->dlg, "destroy", + G_CALLBACK (window_destroy), + NULL); - init_icons(); + main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (imap->dlg), main_vbox); + gtk_widget_show (main_vbox); - /* Create menu */ - make_menu(main_vbox, dlg); + init_icons(); - /* Create toolbar */ - make_toolbar(main_vbox, dlg); + /* Create menu */ + make_menu (imap); + model = G_MENU_MODEL (gtk_builder_get_object (imap->builder, "imap-menubar")); + menubar = gtk_menu_bar_new_from_model (model); - /* Dialog area */ - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1); - gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 0); - gtk_widget_show(hbox); + gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, FALSE, 0); + gtk_widget_show (menubar); - tools = make_tools(dlg); - /* selection_set_edit_command(tools, factory_edit); */ - gtk_box_pack_start(GTK_BOX(hbox), tools, FALSE, FALSE, 0); + /* Create toolbar */ + toolbar = gtk_toolbar_new (); - _preview = make_preview (drawable); + add_tool_button (toolbar, "app.open", GIMP_ICON_DOCUMENT_OPEN, + _("Open"), _("Open")); + add_tool_button (toolbar, "app.save", GIMP_ICON_DOCUMENT_SAVE, + _("Save"), _("Save")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.preferences", GIMP_ICON_PREFERENCES_SYSTEM, + _("Preferences"), _("Preferences")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.undo", GIMP_ICON_EDIT_UNDO, + _("Undo"), _("Undo")); + add_tool_button (toolbar, "app.redo", GIMP_ICON_EDIT_REDO, + _("Redo"), _("Redo")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.cut", GIMP_ICON_EDIT_CUT, + _("Cut"), _("Cut")); + add_tool_button (toolbar, "app.copy", GIMP_ICON_EDIT_COPY, + _("Copy"), _("Copy")); + add_tool_button (toolbar, "app.paste", GIMP_ICON_EDIT_PASTE, + _("Paste"), _("Paste")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.zoom-in", GIMP_ICON_ZOOM_IN, + _("Zoom In"), _("Zoom In")); + add_tool_button (toolbar, "app.zoom-out", GIMP_ICON_ZOOM_OUT, + _("Zoom Out"), _("Zoom Out")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.edit-map-info", GIMP_ICON_DIALOG_INFORMATION, + _("Edit Map Info"), _("Edit Map Info")); + add_tool_separator (toolbar, FALSE); + add_tool_button (toolbar, "app.move-to-front", IMAP_TO_FRONT, + _("Move Area to Front"), _("Move Area to Front")); + add_tool_button (toolbar, "app.send-to-back", IMAP_TO_BACK, + _("Move Area to Bottom"), _("Move Area to Bottom")); + add_tool_separator (toolbar, FALSE); + imap->grid_toggle = add_toggle_button (toolbar, "app.grid", GIMP_ICON_GRID, + _("Grid"), _("Grid")); + add_tool_separator (toolbar, FALSE); - g_signal_connect(_preview->preview, "motion-notify-event", - G_CALLBACK(preview_move), NULL); - g_signal_connect(_preview->preview, "enter-notify-event", - G_CALLBACK(preview_enter), NULL); - g_signal_connect(_preview->preview, "leave-notify-event", - G_CALLBACK(preview_leave), NULL); - g_signal_connect(_preview->preview, "button-press-event", - G_CALLBACK(button_press), NULL); - gtk_box_pack_start (GTK_BOX (hbox), _preview->window, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (toolbar), 0); + gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, FALSE, 0); + gtk_widget_show (toolbar); - object_list_add_geometry_cb(_shapes, geometry_changed, NULL); - object_list_add_update_cb(_shapes, data_changed, NULL); - object_list_add_add_cb(_shapes, data_changed, NULL); - object_list_add_remove_cb(_shapes, data_changed, NULL); - object_list_add_move_cb(_shapes, data_changed, NULL); - object_list_add_select_cb(_shapes, data_selected, NULL); + /* Dialog area */ + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); - /* Selection */ - _selection = make_selection(_shapes); - selection_set_move_up_command(_selection, factory_move_up); - selection_set_move_down_command(_selection, factory_move_down); - gtk_box_pack_start(GTK_BOX(hbox), _selection->container, FALSE, FALSE, 0); + /* Pointer tools area */ + tools = gtk_toolbar_new (); + add_toggle_button (tools, "app.shape::arrow", GIMP_ICON_CURSOR, + _("Arrow"), _("Select Existing Area")); + add_toggle_button (tools, "app.shape::rectangle", IMAP_RECTANGLE, + _("Rectangle"), _("Define Rectangle area")); + add_toggle_button (tools, "app.shape::circle", IMAP_CIRCLE, + _("Circle"), _("Define Circle/Oval area")); + add_toggle_button (tools, "app.shape::polygon", IMAP_POLYGON, + _("Polygon"), _("Define Polygon area")); + add_tool_separator (tools, FALSE); + add_tool_button (tools, "app.edit-area-info", GIMP_ICON_EDIT, + _("Edit Area Info..."), _("Edit selected area info")); - _statusbar = make_statusbar(main_vbox, dlg); - statusbar_set_zoom(_statusbar, 1); + gtk_orientable_set_orientation (GTK_ORIENTABLE (tools), + GTK_ORIENTATION_VERTICAL); + gtk_toolbar_set_style (GTK_TOOLBAR (tools), GTK_TOOLBAR_ICONS); + gtk_container_set_border_width (GTK_CONTAINER (tools), 0); + gtk_widget_show (tools); + gtk_box_pack_start (GTK_BOX (hbox), tools, FALSE, FALSE, 0); - gtk_widget_show(dlg); + _preview = make_preview (imap->drawable, imap); - _mru = mru_create(); - init_preferences(); + g_signal_connect(_preview->preview, "motion-notify-event", + G_CALLBACK (preview_move), NULL); + g_signal_connect(_preview->preview, "enter-notify-event", + G_CALLBACK (preview_enter), NULL); + g_signal_connect(_preview->preview, "leave-notify-event", + G_CALLBACK (preview_leave), NULL); + g_signal_connect(_preview->preview, "button-press-event", + G_CALLBACK (button_press), NULL); + gtk_box_pack_start (GTK_BOX (hbox), _preview->window, TRUE, TRUE, 0); - clear_map_info(); + object_list_add_geometry_cb (_shapes, geometry_changed, NULL); + object_list_add_update_cb (_shapes, data_changed, imap); + object_list_add_add_cb (_shapes, data_changed, imap); + object_list_add_remove_cb (_shapes, data_changed, imap); + object_list_add_move_cb (_shapes, data_changed, imap); + object_list_add_select_cb (_shapes, data_selected, imap); - if (!mru_empty(_mru)) - menu_build_mru_items(_mru); + /* Selection */ + _selection = make_selection (_shapes, imap); + selection_set_move_up_command (_selection, factory_move_up); + selection_set_move_down_command (_selection, factory_move_down); + gtk_box_pack_start (GTK_BOX (hbox), _selection->container, FALSE, FALSE, 0); - gtk_main(); + _statusbar = make_statusbar (main_vbox, imap->dlg); + statusbar_set_zoom (_statusbar, 1); - return run_flag; + gtk_widget_show (imap->dlg); + + _mru = mru_create (); + init_preferences (); + + clear_map_info (); + + imap->success = TRUE; + + return run_flag; +} + +static void +on_app_activate (GApplication *gapp, + gpointer user_data) +{ + GimpImap *imap = GIMP_IMAP (user_data); + + dialog (imap); + + gtk_application_set_accels_for_action (imap->app, "app.save-as", (const char*[]) { "S", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.close", (const char*[]) { "w", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.quit", (const char*[]) { "q", NULL }); + + gtk_application_set_accels_for_action (imap->app, "app.cut", (const char*[]) { "x", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.copy", (const char*[]) { "c", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.paste", (const char*[]) { "p", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.select-all", (const char*[]) { "A", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.deselect-all", (const char*[]) { "A", NULL }); + + gtk_application_set_accels_for_action (imap->app, "app.zoom-in", (const char*[]) { "plus", NULL }); + gtk_application_set_accels_for_action (imap->app, "app.zoom-out", (const char*[]) { "minus", NULL }); +} + +static void +window_destroy (GtkWidget *widget, + gpointer data) +{ + if (data) + { + GimpImap *imap = GIMP_IMAP (data); + + gtk_application_remove_window (imap->app, GTK_WINDOW (imap->dlg)); + } + else + { + gtk_widget_destroy (_dlg); + } +} + +GtkWidget * +add_tool_button (GtkWidget *toolbar, + const char *action, + const char *icon, + const char *label, + const char *tooltip) +{ + GtkWidget *tool_icon; + GtkToolItem *tool_button; + + tool_icon = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_BUTTON); + gtk_widget_show (GTK_WIDGET (tool_icon)); + tool_button = gtk_tool_button_new (tool_icon, label); + gtk_widget_show (GTK_WIDGET (tool_button)); + gtk_tool_item_set_tooltip_text (tool_button, tooltip); + gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (tool_button), action); + + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_button, -1); + + return GTK_WIDGET (tool_button); +} + +GtkWidget * +add_toggle_button (GtkWidget *toolbar, + const char *action, + const char *icon, + const char *label, + const char *tooltip) +{ + GtkWidget *tool_icon; + GtkToolItem *toggle_tool_button; + + tool_icon = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_BUTTON); + gtk_widget_show (GTK_WIDGET (tool_icon)); + + toggle_tool_button = gtk_toggle_tool_button_new (); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toggle_tool_button), + tool_icon); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (toggle_tool_button), label); + gtk_widget_show (GTK_WIDGET (toggle_tool_button)); + gtk_tool_item_set_tooltip_text (toggle_tool_button, tooltip); + gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (toggle_tool_button), action); + + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toggle_tool_button, -1); + + return GTK_WIDGET (toggle_tool_button); +} + +void +add_tool_separator (GtkWidget *toolbar, + gboolean expand) +{ + GtkToolItem *item; + + item = gtk_separator_tool_item_new (); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE); + gtk_tool_item_set_expand (item, expand); + gtk_widget_show (GTK_WIDGET (item)); } diff --git a/plug-ins/imagemap/imap_main.h b/plug-ins/imagemap/imap_main.h index b22327d011..6aa3de8192 100644 --- a/plug-ins/imagemap/imap_main.h +++ b/plug-ins/imagemap/imap_main.h @@ -24,49 +24,70 @@ #define _IMAP_MAIN_H #include "imap_mru.h" +#include "imap_grid.h" #include "imap_object.h" #include "imap_preferences.h" #include "imap_preview.h" +struct _GimpImap +{ + GimpPlugIn parent_instance; + GtkApplication *app; + + GtkWidget *dlg; + GtkWidget *grid_toggle; + + gpointer grid_data; + gchar *tmp_filename; + GimpDrawable *drawable; + gboolean success; + + GtkBuilder *builder; +}; + #define PLUG_IN_PROC "plug-in-imagemap" #define PLUG_IN_BINARY "imagemap" #define PLUG_IN_ROLE "gimp-imagemap" +#define GIMP_TYPE_IMAP (gimp_imap_get_type ()) +G_DECLARE_FINAL_TYPE (GimpImap, gimp_imap, GIMP, IMAP, GimpPlugIn) + typedef enum {NCSA, CERN, CSIM} MapFormat_t; typedef struct { MapFormat_t map_format; - gchar *image_name; - gchar *title; - gchar *author; - gchar *default_url; - gchar *description; - gint old_image_width; - gint old_image_height; + gchar *image_name; + gchar *title; + gchar *author; + gchar *default_url; + gchar *description; + gint old_image_width; + gint old_image_height; gboolean color; /* Color (TRUE) or Gray (FALSE) */ gboolean show_gray; } MapInfo_t; -void main_set_dimension(gint width, gint height); -void main_clear_dimension(void); -void load(const gchar *filename); -void save_as(const gchar *filename); -void dump_output(gpointer param, OutputFunc_t output); -GtkWidget *get_dialog(void); -MRU_t *get_mru(void); -MapInfo_t *get_map_info(void); -PreferencesData_t *get_preferences(void); +void main_set_dimension (gint width, gint height); +void main_clear_dimension (void); +void load (const gchar *filename, + gpointer data); +void save_as (const gchar *filename); +void dump_output (gpointer param, OutputFunc_t output); +GtkWidget *get_dialog (void); +MRU_t *get_mru (void); +MapInfo_t *get_map_info (void); +PreferencesData_t *get_preferences (void); -gint get_image_width(void); -gint get_image_height(void); +gint get_image_width (void); +gint get_image_height (void); -void set_busy_cursor(void); -void remove_busy_cursor(void); +void set_busy_cursor (void); +void remove_busy_cursor (void); -void main_toolbar_set_grid(gboolean active); +void main_toolbar_set_grid (gboolean active); -void set_zoom(gint zoom_factor); -gint get_real_coord(gint coord); +void set_zoom (gint zoom_factor); +gint get_real_coord (gint coord); void draw_line(cairo_t *cr, gint x1, gint y1, gint x2, gint y2); void draw_rectangle(cairo_t *cr, gboolean filled, gint x, gint y, @@ -83,43 +104,101 @@ void update_shape(Object_t *obj); void select_shape(GtkWidget *widget, GdkEventButton *event); void edit_shape(gint x, gint y); -void do_popup_menu(GdkEventButton *event); +void do_popup_menu (GdkEventButton *event, + gpointer data); void draw_shapes(cairo_t *cr); void show_url(void); void hide_url(void); -void set_preview_color (GtkRadioAction *action, - GtkRadioAction *current, +void set_preview_color (GSimpleAction *action, + GVariant *new_state, gpointer user_data); -void set_zoom_factor (GtkRadioAction *action, - GtkRadioAction *current, +void set_zoom_factor (GSimpleAction *action, + GVariant *new_state, gpointer user_data); -void set_func (GtkRadioAction *action, - GtkRadioAction *current, +void set_func (GSimpleAction *action, + GVariant *new_state, gpointer user_data); -void do_edit_selected_shape (void); -void do_zoom_in (void); -void do_zoom_out (void); -void do_close (void); -void do_quit (void); -void do_undo (void); -void do_redo (void); -void do_cut (void); -void do_copy (void); -void do_paste (void); -void do_select_all (void); -void do_deselect_all (void); -void do_clear (void); -void do_move_up (void); -void do_move_down (void); -void do_move_to_front (void); -void do_send_to_back (void); -void do_use_gimp_guides_dialog (void); -void do_create_guides_dialog (void); -void save (void); -void imap_help (void); -void toggle_area_list (void); +void do_edit_selected_shape (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_zoom_in (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_zoom_out (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_close (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_quit (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_undo (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_redo (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_cut (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_copy (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_paste (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_select_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_deselect_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_clear (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_move_up (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_move_down (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_move_to_front (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_send_to_back (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_use_gimp_guides_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void do_create_guides_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void save (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void imap_help (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +void toggle_area_list (GSimpleAction *action, + GVariant *new_state, + gpointer user_data); const gchar * get_image_name (void); +GtkWidget * add_tool_button (GtkWidget *toolbar, + const char *action, + const char *icon, + const char *label, + const char *tooltip); +GtkWidget * add_toggle_button (GtkWidget *toolbar, + const char *action, + const char *icon, + const char *label, + const char *tooltip); +void add_tool_separator (GtkWidget *toolbar, + gboolean expand); + #endif /* _IMAP_MAIN_H */ diff --git a/plug-ins/imagemap/imap_menu.c b/plug-ins/imagemap/imap_menu.c index 734867944d..cd56650052 100644 --- a/plug-ins/imagemap/imap_menu.c +++ b/plug-ins/imagemap/imap_menu.c @@ -41,505 +41,145 @@ #include "libgimp/stdplugins-intl.h" -static Menu_t _menu; -static GtkUIManager *ui_manager; - -GtkWidget* -menu_get_widget(const gchar *path) +void +menu_set_zoom_sensitivity (gpointer data, + gint factor) { - return gtk_ui_manager_get_widget (ui_manager, path); -} + GAction *action; + GimpImap *imap = GIMP_IMAP (data); -static void -set_sensitive (const gchar *path, gboolean sensitive) -{ - GtkAction *action = gtk_ui_manager_get_action (ui_manager, path); - g_object_set (action, "sensitive", sensitive, NULL); -} + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "zoom-in"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), factor < 8); -static void -menu_mru(GtkWidget *widget, gpointer data) -{ - MRU_t *mru = get_mru(); - char *filename = (char*) data; - - if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { - load(filename); - } else { - do_file_error_dialog(_("Error opening file"), filename); - mru_remove(mru, filename); - menu_build_mru_items(mru); - } + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "zoom-out"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), factor > 1); } void -menu_set_zoom_sensitivity(gint factor) +menu_set_zoom (gpointer data, + gint factor) { - set_sensitive ("/MainMenu/ViewMenu/ZoomIn", factor < 8); - set_sensitive ("/MainMenu/ViewMenu/ZoomOut", factor > 1); + menu_set_zoom_sensitivity (data, factor); } void -menu_set_zoom(gint factor) -{ - menu_set_zoom_sensitivity (factor); -} - -void -menu_shapes_selected(gint count) +menu_shapes_selected (gint count, + gpointer data) { + GimpImap *imap = GIMP_IMAP (data); gboolean sensitive = (count > 0); + GAction *action; - set_sensitive ("/MainMenu/EditMenu/Cut", sensitive); - set_sensitive ("/MainMenu/EditMenu/Copy", sensitive); - set_sensitive ("/MainMenu/EditMenu/Clear", sensitive); - set_sensitive ("/MainMenu/EditMenu/EditAreaInfo", sensitive); - set_sensitive ("/MainMenu/EditMenu/DeselectAll", sensitive); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "cut"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "copy"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "clear"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "edit-area-info"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "deselect-all"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive); } static void -command_list_changed(Command_t *command, gpointer data) +command_list_changed (Command_t *command, + gpointer data) { - GtkAction *action; - gchar *label; + GAction *action; + GimpImap *imap; + gchar *label; - action = gtk_ui_manager_get_action (ui_manager, "/MainMenu/EditMenu/Undo"); + imap = GIMP_IMAP (data); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "undo"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), command != NULL); label = g_strdup_printf (_("_Undo %s"), command && command->name ? command->name : ""); - - g_object_set (action, - "label", label, - "sensitive", command != NULL, - NULL); + /* TODO: Find a way to change GAction label in menu for undo */ g_free (label); - command = command_list_get_redo_command(); + command = command_list_get_redo_command (); - action = gtk_ui_manager_get_action (ui_manager, "/MainMenu/EditMenu/Redo"); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "redo"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), command != NULL); label = g_strdup_printf (_("_Redo %s"), command && command->name ? command->name : ""); - g_object_set (action, - "label", label, - "sensitive", command != NULL, - NULL); + /* TODO: Find a way to change GAction label in menu for redo */ g_free (label); } static void -paste_buffer_added(Object_t *obj, gpointer data) +paste_buffer_added (Object_t *obj, gpointer data) { - set_sensitive("/MainMenu/EditMenu/Paste", TRUE); + GAction *action; + GimpImap *imap = GIMP_IMAP (data); + + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "paste"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE); } static void -paste_buffer_removed(Object_t *obj, gpointer data) +paste_buffer_removed (Object_t *obj, gpointer data) { - set_sensitive("/MainMenu/EditMenu/Paste", FALSE); + GAction *action; + GimpImap *imap = GIMP_IMAP (data); + + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "paste"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); } -/* Normal items */ -static const GtkActionEntry entries[] = -{ - { "FileMenu", NULL, - N_("_File") }, - { "Open", GIMP_ICON_DOCUMENT_OPEN, - N_("_Open..."), NULL, N_("Open"), - do_file_open_dialog}, - { "Save", GIMP_ICON_DOCUMENT_SAVE, - N_("_Save..."), NULL, N_("Save"), - save}, - { "SaveAs", GIMP_ICON_DOCUMENT_SAVE_AS, - N_("Save _As..."), "S", NULL, - do_file_save_as_dialog}, - { "Close", GIMP_ICON_CLOSE, N_("_Close"), "w", NULL, do_close}, - { "Quit", GIMP_ICON_APPLICATION_EXIT, - N_("_Quit"), "q", NULL, do_quit}, - - { "EditMenu", NULL, N_("_Edit") }, - { "Undo", GIMP_ICON_EDIT_UNDO, - N_("_Undo"), NULL, N_("Undo"), do_undo}, - { "Redo", GIMP_ICON_EDIT_REDO, - N_("_Redo"), NULL, N_("Redo"), do_redo}, - { "Cut", GIMP_ICON_EDIT_CUT, - N_("Cu_t"), "x", N_("Cut"), do_cut}, - { "Copy", GIMP_ICON_EDIT_COPY, - N_("_Copy"), "c", N_("Copy"), do_copy}, - { "Paste", GIMP_ICON_EDIT_PASTE, - N_("_Paste"), "v", N_("Paste"), do_paste}, - { "Clear", GIMP_ICON_EDIT_DELETE, - N_("_Delete"), NULL, N_("Delete"), do_clear}, - { "SelectAll", NULL, - N_("Select _All"), "A", NULL, do_select_all}, - { "DeselectAll", NULL, - N_("D_eselect All"), "A", NULL, - do_deselect_all}, - { "EditAreaInfo", GIMP_ICON_EDIT - , N_("Edit Area _Info..."), NULL, - N_("Edit selected area info"), do_edit_selected_shape}, - { "Preferences", GIMP_ICON_PREFERENCES_SYSTEM, - N_("_Preferences"), NULL, N_("Preferences"), - do_preferences_dialog}, - { "MoveToFront", IMAP_TO_FRONT, "", NULL, N_("Move Area to Front"), - do_move_to_front}, - { "SendToBack", IMAP_TO_BACK, "", NULL, N_("Move Area to Bottom"), - do_send_to_back}, - { "DeleteArea", NULL, N_("Delete Area"), NULL, NULL, NULL}, - { "MoveUp", GIMP_ICON_GO_UP, N_("Move Up"), NULL, NULL, NULL}, - { "MoveDown", GIMP_ICON_GO_DOWN, N_("Move Down"), NULL, NULL, NULL}, - - { "InsertPoint", NULL, N_("Insert Point"), NULL, NULL, polygon_insert_point}, - { "DeletePoint", NULL, N_("Delete Point"), NULL, NULL, polygon_delete_point}, - - { "ViewMenu", NULL, N_("_View") }, - { "Source", NULL, N_("Source..."), NULL, NULL, do_source_dialog}, - { "ZoomIn", GIMP_ICON_ZOOM_IN, N_("Zoom _In"), "plus", N_("Zoom in"), do_zoom_in}, - { "ZoomOut", GIMP_ICON_ZOOM_OUT, N_("Zoom _Out"), "minus", N_("Zoom out"), do_zoom_out}, - { "ZoomToMenu", NULL, N_("_Zoom To") }, - - { "MappingMenu", NULL, N_("_Mapping") }, - { "EditMapInfo", GIMP_ICON_DIALOG_INFORMATION, N_("Edit Map Info..."), NULL, - N_("Edit Map Info"), do_settings_dialog}, - - { "ToolsMenu", NULL, N_("_Tools") }, - { "GridSettings", NULL, N_("Grid Settings..."), NULL, NULL, - do_grid_settings_dialog}, - { "UseGimpGuides", NULL, N_("Use GIMP Guides..."), NULL, NULL, - do_use_gimp_guides_dialog}, - { "CreateGuides", NULL, N_("Create Guides..."), NULL, NULL, - do_create_guides_dialog}, - - { "HelpMenu", NULL, N_("_Help") }, - { "Contents", GIMP_ICON_HELP, N_("_Contents"), NULL, NULL, imap_help}, - { "About", GIMP_ICON_HELP_ABOUT, N_("_About"), NULL, NULL, do_about_dialog}, - - { "ZoomMenu", NULL, N_("_Zoom") }, -}; - -/* Toggle items */ -static const GtkToggleActionEntry toggle_entries[] = { - { "AreaList", NULL, N_("Area List"), NULL, NULL, NULL, TRUE }, - { "Grid", GIMP_ICON_GRID, N_("_Grid"), NULL, N_("Grid"), toggle_grid, FALSE } -}; - -static const GtkRadioActionEntry color_entries[] = { - { "Color", NULL, N_("Color"), NULL, NULL, 0}, - { "Gray", NULL, N_("Gray"), NULL, NULL, 1}, -}; - -static const GtkRadioActionEntry mapping_entries[] = { - { "Arrow", GIMP_ICON_CURSOR, N_("Arrow"), NULL, - N_("Select existing area"), 0}, - { "Rectangle", IMAP_RECTANGLE, N_("Rectangle"), NULL, - N_("Define Rectangle area"), 1}, - { "Circle", IMAP_CIRCLE, N_("Circle"), NULL, - N_("Define Circle/Oval area"), 2}, - { "Polygon", IMAP_POLYGON, N_("Polygon"), NULL, - N_("Define Polygon area"), 3}, -}; - -static const GtkRadioActionEntry zoom_entries[] = { - { "Zoom1:1", NULL, "1:1", NULL, NULL, 0}, - { "Zoom1:2", NULL, "1:2", NULL, NULL, 1}, - { "Zoom1:3", NULL, "1:3", NULL, NULL, 2}, - { "Zoom1:4", NULL, "1:4", NULL, NULL, 3}, - { "Zoom1:5", NULL, "1:5", NULL, NULL, 4}, - { "Zoom1:6", NULL, "1:6", NULL, NULL, 5}, - { "Zoom1:7", NULL, "1:7", NULL, NULL, 6}, - { "Zoom1:8", NULL, "1:8", NULL, NULL, 7}, -}; - -static const gchar ui_description[] = -"" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -" " -" " -"" -" " -" " -" " -" " -" " -" " -""; - Menu_t* -make_menu(GtkWidget *main_vbox, GtkWidget *window) +make_menu (GimpImap *imap) { - GtkWidget *menubar; - GtkActionGroup *action_group; - GtkAccelGroup *accel_group; - GError *error; + GAction *action; - action_group = gtk_action_group_new ("MenuActions"); - gtk_action_group_set_translation_domain (action_group, NULL); + paste_buffer_add_add_cb (paste_buffer_added, imap); + paste_buffer_add_remove_cb (paste_buffer_removed, imap); - gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), - window); - gtk_action_group_add_toggle_actions (action_group, toggle_entries, - G_N_ELEMENTS (toggle_entries), window); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "paste"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); - gtk_action_group_add_radio_actions (action_group, color_entries, - G_N_ELEMENTS (color_entries), 0, - G_CALLBACK (set_preview_color), NULL); - gtk_action_group_add_radio_actions (action_group, zoom_entries, - G_N_ELEMENTS (zoom_entries), 0, - G_CALLBACK (set_zoom_factor), NULL); - gtk_action_group_add_radio_actions (action_group, mapping_entries, - G_N_ELEMENTS (mapping_entries), 0, - G_CALLBACK (set_func), window); + menu_shapes_selected (0, imap); - ui_manager = gtk_ui_manager_new (); - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + menu_set_zoom_sensitivity (imap, 1); - accel_group = gtk_ui_manager_get_accel_group (ui_manager); - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + command_list_add_update_cb (command_list_changed, imap); - error = NULL; - if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, - &error)) - { - g_warning ("building menus failed: %s", error->message); - g_error_free (error); - /* exit (EXIT_FAILURE); */ - } + command_list_changed (NULL, imap); - menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); - gtk_widget_show (menubar); - gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, FALSE, 0); - - paste_buffer_add_add_cb(paste_buffer_added, NULL); - paste_buffer_add_remove_cb(paste_buffer_removed, NULL); - - set_sensitive ("/MainMenu/EditMenu/Paste", FALSE); - menu_shapes_selected (0); - - menu_set_zoom_sensitivity (1); - - command_list_add_update_cb (command_list_changed, NULL); - - command_list_changed (NULL, NULL); - - return &_menu; + return NULL; } void -menu_build_mru_items(MRU_t *mru) +do_main_popup_menu (GdkEventButton *event, + gpointer data) { - GList *p; - gint position = 0; - int i; + GtkWidget *menu; + GMenuModel *model; + GimpImap *imap = GIMP_IMAP (data); - return; + model = G_MENU_MODEL (gtk_builder_get_object (imap->builder, "imap-main-popup")); + menu = gtk_menu_new_from_model (model); - if (_menu.nr_off_mru_items) { - GList *children; - - children = gtk_container_get_children(GTK_CONTAINER(_menu.open_recent)); - p = g_list_nth(children, position); - for (i = 0; i < _menu.nr_off_mru_items; i++, p = p->next) { - gtk_widget_destroy((GtkWidget*) p->data); - } - g_list_free(children); - } - - i = 0; - for (p = mru->list; p; p = p->next, i++) { - GtkWidget *item = insert_item_with_label(_menu.open_recent, position++, - (gchar*) p->data, - menu_mru, p->data); - if (i < 9) { - guchar accelerator_key = '1' + i; - add_accelerator(item, accelerator_key, GDK_CONTROL_MASK); - } - } - _menu.nr_off_mru_items = i; -} - -void -do_main_popup_menu(GdkEventButton *event) -{ - GtkWidget *popup = gtk_ui_manager_get_widget (ui_manager, "/PopupMenu"); - - gtk_menu_popup_at_pointer (GTK_MENU (popup), (GdkEvent *) event); -} - -void -menu_check_grid(gboolean check) -{ - GtkAction *action = gtk_ui_manager_get_action (ui_manager, - "/MainMenu/ToolsMenu/Grid"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), check); + gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (imap->dlg), NULL); + gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) event); } GtkWidget* -make_toolbar(GtkWidget *main_vbox, GtkWidget *window) +make_selection_toolbar (GimpImap *imap) { - GtkWidget *toolbar; + GtkWidget *toolbar = gtk_toolbar_new (); - toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar"); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); - gtk_container_set_border_width (GTK_CONTAINER (toolbar), 0); - gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, FALSE, 0); - gtk_widget_show (toolbar); - - return toolbar; -} - -GtkWidget* -make_tools(GtkWidget *window) -{ - GtkWidget *toolbar; - - toolbar = gtk_ui_manager_get_widget (ui_manager, "/Tools"); - gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), - GTK_ORIENTATION_VERTICAL); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); - gtk_container_set_border_width (GTK_CONTAINER (toolbar), 0); - gtk_widget_show (toolbar); - - return toolbar; -} - -GtkWidget* -make_selection_toolbar(void) -{ - GtkWidget *toolbar; - - toolbar = gtk_ui_manager_get_widget (ui_manager, "/Selection"); + add_tool_button (toolbar, "app.move-up", GIMP_ICON_GO_UP, + _("Move Up"), _("Move Up")); + add_tool_button (toolbar, "app.move-down", GIMP_ICON_GO_DOWN, + _("Move Down"), _("Move Down")); + add_tool_button (toolbar, "app.edit-area-info", GIMP_ICON_EDIT, + _("Edit Area Info..."), _("Edit selected area info")); + add_tool_button (toolbar, "app.clear", GIMP_ICON_EDIT_DELETE, + _("Delete"), _("Delete")); gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), diff --git a/plug-ins/imagemap/imap_menu.h b/plug-ins/imagemap/imap_menu.h index e34743f368..990b0f14f5 100644 --- a/plug-ins/imagemap/imap_menu.h +++ b/plug-ins/imagemap/imap_menu.h @@ -47,19 +47,19 @@ typedef struct { gint nr_off_mru_items; } Menu_t; -GtkWidget *menu_get_widget(const gchar *path); -Menu_t *make_menu(GtkWidget *main_vbox, GtkWidget *window); -void menu_build_mru_items(MRU_t *mru); -void menu_set_zoom_sensitivity(gint factor); +Menu_t *make_menu (GimpImap *imap); +void menu_build_mru_items (MRU_t *mru); +void menu_set_zoom_sensitivity (gpointer data, + gint factor); -void menu_set_zoom(gint factor); -void menu_check_grid(gboolean check); -void menu_shapes_selected(gint count); +void menu_set_zoom (gpointer data, + gint factor); +void menu_shapes_selected (gint count, + gpointer imap); -void do_main_popup_menu(GdkEventButton *event); +void do_main_popup_menu (GdkEventButton *event, + gpointer data); -GtkWidget *make_toolbar(GtkWidget *main_vbox, GtkWidget *window); -GtkWidget *make_tools(GtkWidget *window); -GtkWidget *make_selection_toolbar(void); +GtkWidget *make_selection_toolbar (GimpImap *imap); #endif /* _IMAP_MENU_H */ diff --git a/plug-ins/imagemap/imap_menu_funcs.c b/plug-ins/imagemap/imap_menu_funcs.c index 264a6cb45d..72f6a069c7 100644 --- a/plug-ins/imagemap/imap_menu_funcs.c +++ b/plug-ins/imagemap/imap_menu_funcs.c @@ -46,13 +46,16 @@ add_accelerator(GtkWidget *widget, guint accelerator_key, } GtkWidget* -insert_item_with_label(GtkWidget *parent, gint position, gchar *label, - MenuCallback activate, gpointer data) +insert_item_with_label (GtkWidget *parent, + gint position, + gchar *label, + MenuCallback activate, + gpointer data) { - GtkWidget *item = gtk_image_menu_item_new_with_mnemonic(label); - gtk_menu_shell_insert(GTK_MENU_SHELL(parent), item, position); - g_signal_connect(item, "activate", G_CALLBACK(activate), data); - gtk_widget_show(item); + GtkWidget *item = gtk_menu_item_new_with_mnemonic (label); + gtk_menu_shell_insert (GTK_MENU_SHELL (parent), item, position); + g_signal_connect (item, "activate", G_CALLBACK (activate), data); + gtk_widget_show (item); return item; } diff --git a/plug-ins/imagemap/imap_object.h b/plug-ins/imagemap/imap_object.h index da68c0033c..8cfa163a30 100644 --- a/plug-ins/imagemap/imap_object.h +++ b/plug-ins/imagemap/imap_object.h @@ -75,7 +75,9 @@ struct ObjectClass_t { void (*write_csim)(Object_t *obj, gpointer param, OutputFunc_t output); void (*write_cern)(Object_t *obj, gpointer param, OutputFunc_t output); void (*write_ncsa)(Object_t *obj, gpointer param, OutputFunc_t output); - void (*do_popup)(Object_t *obj, GdkEventButton *event); + void (*do_popup)(Object_t *obj, + GdkEventButton *event, + gpointer data); const gchar* (*get_icon_name)(void); }; diff --git a/plug-ins/imagemap/imap_object_popup.c b/plug-ins/imagemap/imap_object_popup.c index 99f8d74e9d..46ff2c2a50 100644 --- a/plug-ins/imagemap/imap_object_popup.c +++ b/plug-ins/imagemap/imap_object_popup.c @@ -32,7 +32,10 @@ #include "libgimp/stdplugins-intl.h" void -object_handle_popup(ObjectPopup_t *popup, Object_t *obj, GdkEventButton *event) +object_handle_popup (ObjectPopup_t *popup, + Object_t *obj, + GdkEventButton *event, + GimpImap *imap) { /* int position = object_get_position_in_list(obj) + 1; */ @@ -42,18 +45,25 @@ object_handle_popup(ObjectPopup_t *popup, Object_t *obj, GdkEventButton *event) (position < g_list_length(obj->list->list)) ? TRUE : FALSE); #endif + gtk_menu_attach_to_widget (GTK_MENU (popup->menu), GTK_WIDGET (imap->dlg), NULL); gtk_menu_popup_at_pointer (GTK_MENU (popup->menu), (GdkEvent *) event); } void -object_do_popup(Object_t *obj, GdkEventButton *event) +object_do_popup (Object_t *obj, + GdkEventButton *event, + gpointer data) { - static ObjectPopup_t *popup; + static ObjectPopup_t *popup; + GMenuModel *model; + GimpImap *imap = GIMP_IMAP (data); - if (!popup) + if (! popup) { - popup = g_new (ObjectPopup_t, 1); - popup->menu = menu_get_widget ("/ObjectPopupMenu"); + popup = g_new (ObjectPopup_t, 1); + model = G_MENU_MODEL (gtk_builder_get_object + (imap->builder, "imap-object-popup")); + popup->menu = gtk_menu_new_from_model (model); } - object_handle_popup (popup, obj, event); + object_handle_popup (popup, obj, event, imap); } diff --git a/plug-ins/imagemap/imap_object_popup.h b/plug-ins/imagemap/imap_object_popup.h index bc7afee14c..c03723706e 100644 --- a/plug-ins/imagemap/imap_object_popup.h +++ b/plug-ins/imagemap/imap_object_popup.h @@ -32,8 +32,12 @@ typedef struct { Object_t *obj; } ObjectPopup_t; -void object_handle_popup(ObjectPopup_t *popup, Object_t *obj, - GdkEventButton *event); -void object_do_popup(Object_t *obj, GdkEventButton *event); +void object_handle_popup (ObjectPopup_t *popup, + Object_t *obj, + GdkEventButton *event, + GimpImap *imap); +void object_do_popup (Object_t *obj, + GdkEventButton *event, + gpointer data); #endif /* _IMAP_OBJECT_POPUP_H */ diff --git a/plug-ins/imagemap/imap_polygon.c b/plug-ins/imagemap/imap_polygon.c index 17b6e3ec13..72d957b058 100644 --- a/plug-ins/imagemap/imap_polygon.c +++ b/plug-ins/imagemap/imap_polygon.c @@ -65,7 +65,9 @@ static void polygon_write_cern(Object_t* obj, gpointer param, OutputFunc_t output); static void polygon_write_ncsa(Object_t* obj, gpointer param, OutputFunc_t output); -static void polygon_do_popup(Object_t *obj, GdkEventButton *event); +static void polygon_do_popup (Object_t *obj, + GdkEventButton *event, + gpointer data); static const gchar* polygon_get_icon_name(void); static ObjectClass_t polygon_class = { @@ -656,7 +658,9 @@ static gint _insert_x; static gint _insert_y; void -polygon_insert_point(void) +polygon_insert_point (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { Command_t *command = insert_point_command_new (_current_obj, _insert_x, _insert_y, _insert_edge); @@ -664,7 +668,9 @@ polygon_insert_point(void) } void -polygon_delete_point(void) +polygon_delete_point (GSimpleAction *action, + GVariant *new_state, + gpointer user_data) { Command_t *command = delete_point_command_new(_current_obj, _sash_point); command_execute (command); @@ -708,30 +714,41 @@ polygon_near_edge(Object_t *obj, gint x, gint y) } static void -polygon_handle_popup (GdkEventButton *event, gboolean near_sash, - gboolean near_edge) +polygon_handle_popup (GdkEventButton *event, + GimpImap *imap, + gboolean near_sash, + gboolean near_edge) { - GtkWidget *popup = menu_get_widget ("/PolygonPopupMenu"); - GtkWidget *delete = menu_get_widget ("/PolygonPopupMenu/DeletePoint"); - GtkWidget *insert = menu_get_widget ("/PolygonPopupMenu/InsertPoint"); + GtkWidget *menu; + GMenuModel *model; + GAction *action; - gtk_widget_set_sensitive (delete, near_sash); - gtk_widget_set_sensitive (insert, near_edge); + model = G_MENU_MODEL (gtk_builder_get_object (imap->builder, "imap-polygon-popup")); + menu = gtk_menu_new_from_model (model); - gtk_menu_popup_at_pointer (GTK_MENU (popup), (GdkEvent *) event); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "insert-point"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), near_edge); + action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "delete-point"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), near_sash); + + gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (imap->dlg), NULL); + gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *) event); } static void -polygon_do_popup(Object_t *obj, GdkEventButton *event) +polygon_do_popup (Object_t *obj, + GdkEventButton *event, + gpointer data) { - gint x = get_real_coord ((gint) event->x); - gint y = get_real_coord ((gint) event->y); + gint x = get_real_coord ((gint) event->x); + gint y = get_real_coord ((gint) event->y); + GimpImap *imap = GIMP_IMAP (data); _current_obj = obj; if (polygon_near_sash (obj, x, y)) { - polygon_handle_popup (event, TRUE, FALSE); + polygon_handle_popup (event, imap, TRUE, FALSE); } else { @@ -739,13 +756,14 @@ polygon_do_popup(Object_t *obj, GdkEventButton *event) if (_insert_edge) { _insert_x = x; - _insert_y = y; + _insert_y = y; - polygon_handle_popup (event, FALSE, TRUE); + polygon_handle_popup (event,imap, FALSE, TRUE); + } + else + { + object_do_popup (obj, event, imap); } - else { - object_do_popup (obj, event); - } } } diff --git a/plug-ins/imagemap/imap_polygon.h b/plug-ins/imagemap/imap_polygon.h index 13ce29e963..34be49954e 100644 --- a/plug-ins/imagemap/imap_polygon.h +++ b/plug-ins/imagemap/imap_polygon.h @@ -25,21 +25,29 @@ #include "imap_object.h" -typedef struct { - Object_t obj; - GList *points; +typedef struct +{ + Object_t obj; + GList *points; } Polygon_t; #define ObjectToPolygon(obj) ((Polygon_t*) (obj)) -Object_t *create_polygon (GList *points); -ObjectFactory_t *get_polygon_factory (guint state); +Object_t *create_polygon (GList *points); +ObjectFactory_t *get_polygon_factory (guint state); -void polygon_insert_point (void); -void polygon_delete_point (void); +void polygon_insert_point (GSimpleAction *action, + GVariant *new_state, + gpointer user_data); +void polygon_delete_point (GSimpleAction *action, + GVariant *new_state, + gpointer user_data); -void polygon_remove_last_point (Polygon_t *polygon); -void polygon_append_point (Polygon_t *polygon, gint x, gint y); -GdkPoint *new_point (gint x, gint y); +void polygon_remove_last_point (Polygon_t *polygon); +void polygon_append_point (Polygon_t *polygon, + gint x, + gint y); +GdkPoint *new_point (gint x, + gint y); #endif /* _IMAP_POLYGON_H */ diff --git a/plug-ins/imagemap/imap_preferences.c b/plug-ins/imagemap/imap_preferences.c index b586c5ce71..421099011c 100644 --- a/plug-ins/imagemap/imap_preferences.c +++ b/plug-ins/imagemap/imap_preferences.c @@ -271,7 +271,7 @@ preferences_save(PreferencesData_t *data) } static void -preferences_ok_cb(gpointer data) +preferences_ok_cb (gpointer data) { PreferencesDialog_t *param = (PreferencesDialog_t*) data; PreferencesData_t *old_data = param->old_data; @@ -299,12 +299,11 @@ preferences_ok_cb(gpointer data) GTK_TOGGLE_BUTTON(param->use_doublesized)); old_data->mru_size = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(param->mru_size)); + gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(param->mru_size)); old_data->undo_levels = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(param->undo_levels)); - mru_set_size(mru, old_data->mru_size); - menu_build_mru_items(mru); - command_list_set_undo_level(old_data->undo_levels); + gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(param->undo_levels)); + mru_set_size (mru, old_data->mru_size); + command_list_set_undo_level (old_data->undo_levels); get_button_colors (param, colors); @@ -504,7 +503,9 @@ create_preferences_dialog(void) } void -do_preferences_dialog(void) +do_preferences_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static PreferencesDialog_t *dialog; PreferencesData_t *old_data; diff --git a/plug-ins/imagemap/imap_preferences.h b/plug-ins/imagemap/imap_preferences.h index 524f7c8572..f83cd31187 100644 --- a/plug-ins/imagemap/imap_preferences.h +++ b/plug-ins/imagemap/imap_preferences.h @@ -49,8 +49,10 @@ typedef struct { ColorSelData_t colors; } PreferencesData_t; -void do_preferences_dialog(void); -gboolean preferences_load(PreferencesData_t *data); -void preferences_save(PreferencesData_t *data); +void do_preferences_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); +gboolean preferences_load (PreferencesData_t *data); +void preferences_save (PreferencesData_t *data); #endif /* _IMAP_PREFERENCES_H */ diff --git a/plug-ins/imagemap/imap_preview.c b/plug-ins/imagemap/imap_preview.c index cc0cb0a16e..15b069f168 100644 --- a/plug-ins/imagemap/imap_preview.c +++ b/plug-ins/imagemap/imap_preview.c @@ -128,10 +128,12 @@ render_preview (Preview_t *preview_base, } static gboolean -arrow_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) +arrow_cb (GtkWidget *widget, + GdkEventButton *event, + gpointer data) { if (event->button == 1) - do_main_popup_menu(event); + do_main_popup_menu (event, data); return TRUE; } @@ -254,9 +256,10 @@ scroll_adj_changed (GtkAdjustment *adj, } Preview_t * -make_preview (GimpDrawable *drawable) +make_preview (GimpDrawable *drawable, + gpointer imap) { - Preview_t *data = g_new(Preview_t, 1); + Preview_t *data = g_new (Preview_t, 1); GtkAdjustment *hadj; GtkAdjustment *vadj; GtkWidget *preview; @@ -310,7 +313,7 @@ make_preview (GimpDrawable *drawable) g_signal_connect (button, "button-press-event", G_CALLBACK (arrow_cb), - NULL); + imap); arrow = gtk_image_new_from_icon_name (GIMP_ICON_GO_NEXT, GTK_ICON_SIZE_BUTTON); diff --git a/plug-ins/imagemap/imap_preview.h b/plug-ins/imagemap/imap_preview.h index 99750acdb7..f970cc6720 100644 --- a/plug-ins/imagemap/imap_preview.h +++ b/plug-ins/imagemap/imap_preview.h @@ -39,8 +39,9 @@ typedef struct { GdkCursorType cursor; } Preview_t; -Preview_t *make_preview(GimpDrawable *drawable); -void preview_redraw(void); +Preview_t *make_preview (GimpDrawable *drawable, + gpointer imap); +void preview_redraw (void); void preview_unset_tmp_obj (Object_t *obj); void preview_set_tmp_obj (Object_t *obj); diff --git a/plug-ins/imagemap/imap_selection.c b/plug-ins/imagemap/imap_selection.c index 7b54f7b95d..327c438436 100644 --- a/plug-ins/imagemap/imap_selection.c +++ b/plug-ins/imagemap/imap_selection.c @@ -307,7 +307,8 @@ render_comment (GtkTreeViewColumn *column, GtkCellRenderer *cell, } Selection_t* -make_selection(ObjectList_t *object_list) +make_selection (ObjectList_t *object_list, + GimpImap *imap) { Selection_t *data = g_new(Selection_t, 1); GtkWidget *swin, *frame, *hbox; @@ -331,7 +332,7 @@ make_selection(ObjectList_t *object_list) gtk_container_add(GTK_CONTAINER(frame), hbox); gtk_widget_show(hbox); - toolbar = make_selection_toolbar (); + toolbar = make_selection_toolbar (imap); gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0); /* Create selection */ @@ -418,7 +419,7 @@ make_selection(ObjectList_t *object_list) /* Callbacks we are interested in */ data->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); gtk_tree_selection_set_mode (data->selection, GTK_SELECTION_MULTIPLE); - g_signal_connect (data->selection, "changed", G_CALLBACK(changed_cb), data); + g_signal_connect (data->selection, "changed", G_CALLBACK (changed_cb), data); /* Set object list callbacks we're interested in */ object_list_add_add_cb (object_list, object_added_cb, data); diff --git a/plug-ins/imagemap/imap_selection.h b/plug-ins/imagemap/imap_selection.h index cb13afb22a..1cedfe2d97 100644 --- a/plug-ins/imagemap/imap_selection.h +++ b/plug-ins/imagemap/imap_selection.h @@ -46,7 +46,8 @@ typedef struct { CommandFactory_t cmd_edit; } Selection_t; -Selection_t *make_selection(ObjectList_t *list); +Selection_t *make_selection (ObjectList_t *list, + GimpImap *imap); void selection_toggle_visibility(Selection_t *selection); void selection_freeze(Selection_t *selection); void selection_thaw(Selection_t *selection); diff --git a/plug-ins/imagemap/imap_settings.c b/plug-ins/imagemap/imap_settings.c index f5099dc529..f3bd68eb67 100644 --- a/plug-ins/imagemap/imap_settings.c +++ b/plug-ins/imagemap/imap_settings.c @@ -35,21 +35,21 @@ typedef struct { DefaultDialog_t *dialog; - BrowseWidget_t *imagename; - GtkWidget *filename; - GtkWidget *title; - GtkWidget *author; - GtkWidget *default_url; - GtkWidget *ncsa; - GtkWidget *cern; - GtkWidget *csim; - GtkTextBuffer *description; + BrowseWidget_t *imagename; + GtkWidget *filename; + GtkWidget *title; + GtkWidget *author; + GtkWidget *default_url; + GtkWidget *ncsa; + GtkWidget *cern; + GtkWidget *csim; + GtkTextBuffer *description; } SettingsDialog_t; static MapFormat_t _map_format = CSIM; static void -settings_ok_cb(gpointer data) +settings_ok_cb (gpointer data) { SettingsDialog_t *param = (SettingsDialog_t*) data; MapInfo_t *info = get_map_info(); @@ -72,14 +72,14 @@ settings_ok_cb(gpointer data) } static void -type_toggled_cb(GtkWidget *widget, gpointer data) +type_toggled_cb (GtkWidget *widget, gpointer data) { if (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) _map_format = (MapFormat_t) data; } static SettingsDialog_t* -create_settings_dialog(void) +create_settings_dialog (void) { SettingsDialog_t *data = g_new(SettingsDialog_t, 1); GtkWidget *grid, *view, *frame, *hbox, *label, *swin; @@ -155,7 +155,9 @@ create_settings_dialog(void) } void -do_settings_dialog(void) +do_settings_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static SettingsDialog_t *dialog; const char *filename = get_filename(); diff --git a/plug-ins/imagemap/imap_settings.h b/plug-ins/imagemap/imap_settings.h index 4b375d6fd2..fe4c309e44 100644 --- a/plug-ins/imagemap/imap_settings.h +++ b/plug-ins/imagemap/imap_settings.h @@ -23,6 +23,8 @@ #ifndef _IMAP_SETTINGS_H #define _IMAP_SETTINGS_H -void do_settings_dialog(void); +void do_settings_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); #endif /* _IMAP_SETTINGS_H */ diff --git a/plug-ins/imagemap/imap_source.c b/plug-ins/imagemap/imap_source.c index 40ba1b7ea4..5c1ebcbfb8 100644 --- a/plug-ins/imagemap/imap_source.c +++ b/plug-ins/imagemap/imap_source.c @@ -38,7 +38,7 @@ static void save_to_view (GtkTextBuffer *buffer, ...) G_GNUC_PRINTF(2,3); static void -save_to_view(GtkTextBuffer *buffer, const char* format, ...) +save_to_view (GtkTextBuffer *buffer, const char* format, ...) { va_list ap; char scratch[1024]; @@ -53,7 +53,9 @@ save_to_view(GtkTextBuffer *buffer, const char* format, ...) } void -do_source_dialog(void) +do_source_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { static DefaultDialog_t *dialog; static GtkWidget *text; diff --git a/plug-ins/imagemap/imap_source.h b/plug-ins/imagemap/imap_source.h index a090515f75..8728f3a6f1 100644 --- a/plug-ins/imagemap/imap_source.h +++ b/plug-ins/imagemap/imap_source.h @@ -23,6 +23,8 @@ #ifndef _IMAP_SOURCE_H #define _IMAP_SOURCE_H -void do_source_dialog(void); +void do_source_dialog (GSimpleAction *action, + GVariant *parameter, + gpointer user_data); #endif /* _IMAP_SOURCE_H */