plug-ins/imagemap/imap_file.c plug-ins/imagemap/imap_main.c

2005-01-22  Maurits Rijk  <m.rijk@chello.nl>

	* plug-ins/imagemap/imap_file.c
	* plug-ins/imagemap/imap_main.c
	* plug-ins/imagemap/imap_menu.c
	* plug-ins/imagemap/imap_menu_funcs.[ch]
	* plug-ins/imagemap/imap_misc.[ch]
	* plug-ins/imagemap/imap_object.[ch]
	* plug-ins/imagemap/imap_selection.c: cleaning up code, mostly
	replacing homebrewn stuff that is now in either GTK or one of the
	GIMP libs. More to come.
This commit is contained in:
Maurits Rijk 2005-01-22 20:25:00 +00:00 committed by Maurits Rijk
parent 8b9a69255e
commit 46e92b1ee9
11 changed files with 82 additions and 291 deletions

View File

@ -1,3 +1,15 @@
2005-01-22 Maurits Rijk <m.rijk@chello.nl>
* plug-ins/imagemap/imap_file.c
* plug-ins/imagemap/imap_main.c
* plug-ins/imagemap/imap_menu.c
* plug-ins/imagemap/imap_menu_funcs.[ch]
* plug-ins/imagemap/imap_misc.[ch]
* plug-ins/imagemap/imap_object.[ch]
* plug-ins/imagemap/imap_selection.c: cleaning up code, mostly
replacing homebrewn stuff that is now in either GTK or one of the
GIMP libs. More to come.
2005-01-22 Sven Neumann <sven@gimp.org>
* app/widgets/gimpselectiondata.c: include <stdio.h> for sscanf().

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,7 +28,6 @@
#include "imap_file.h"
#include "imap_main.h"
#include "imap_misc.h"
#include "libgimp/stdplugins-intl.h"
@ -122,6 +121,7 @@ do_file_exists_dialog (GtkWidget *parent)
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
message);
g_free (message);
g_signal_connect (dialog, "response",
G_CALLBACK (really_overwrite_cb),
parent);
@ -188,14 +188,19 @@ void
do_file_error_dialog (const char *error,
const char *filename)
{
static Alert_t *alert;
GtkWidget *dialog;
if (!alert)
alert = create_alert (GTK_STOCK_DIALOG_ERROR);
dialog = gtk_message_dialog_new_with_markup
(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
error,
gimp_filename_to_utf8 (filename));
alert_set_text(alert, error, gimp_filename_to_utf8 (filename));
alert_set_text (alert, error, filename);
default_dialog_show (alert->dialog);
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
dialog);
gtk_dialog_run (GTK_DIALOG (dialog));
}

View File

@ -123,7 +123,7 @@ static void query(void)
"",
"Maurits Rijk",
"Maurits Rijk",
"1998-2002",
"1998-2005",
N_("_ImageMap..."),
"RGB*, GRAY*, INDEXED*",
GIMP_PLUGIN,
@ -725,24 +725,31 @@ clear_map_info(void)
static void
do_data_changed_dialog(void (*continue_cb)(gpointer), gpointer param)
{
static Alert_t *alert;
GtkWidget *dialog;
if (!alert) {
alert = create_confirm_alert(GTK_STOCK_DIALOG_WARNING);
alert_set_text(alert, _("Some data has been changed!"),
_("Do you really want to discard your changes?"));
}
default_dialog_set_ok_cb(alert->dialog, continue_cb, param);
default_dialog_show(alert->dialog);
dialog = gtk_message_dialog_new_with_markup
(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("Some data has been changed!"),
_("Do you really want to discard your changes?"));
gint result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_YES)
continue_cb (param);
gtk_widget_destroy (dialog);
}
static void
check_if_changed(void (*func)(gpointer), gpointer param)
{
if (object_list_get_changed(_shapes))
do_data_changed_dialog(func, param);
if (object_list_get_changed (_shapes))
do_data_changed_dialog (func, param);
else
func(param);
func (param);
}
static void
@ -834,7 +841,7 @@ save_as_cern(gpointer param, OutputFunc_t output)
write_cern_comment(param, output);
output(param, "-:Please do not edit lines starting with \"#$\"\n");
write_cern_comment(param, output);
output(param, "VERSION:2.0\n");
output(param, "VERSION:2.3\n");
write_cern_comment(param, output);
output(param, "TITLE:%s\n", _map_info.title);
write_cern_comment(param, output);
@ -870,7 +877,7 @@ save_as_csim(gpointer param, OutputFunc_t output)
output(param, "<!-- #$-:GIMP Imagemap Plugin by Maurits Rijk -->\n");
output(param,
"<!-- #$-:Please do not edit lines starting with \"#$\" -->\n");
output(param, "<!-- #$VERSION:2.0 -->\n");
output(param, "<!-- #$VERSION:2.3 -->\n");
output(param, "<!-- #$AUTHOR:%s -->\n", _map_info.author);
description = g_strdup(_map_info.description);
@ -894,7 +901,7 @@ save_as_ncsa(gpointer param, OutputFunc_t output)
output(param, "#$-:Image Map file created by GIMP Imagemap Plugin\n");
output(param, "#$-:GIMP Imagemap Plugin by Maurits Rijk\n");
output(param, "#$-:Please do not edit lines starting with \"#$\"\n");
output(param, "#$VERSION:2.0\n");
output(param, "#$VERSION:2.3\n");
output(param, "#$TITLE:%s\n", _map_info.title);
output(param, "#$AUTHOR:%s\n", _map_info.author);
output(param, "#$FORMAT:ncsa\n");
@ -946,34 +953,30 @@ save_as(const gchar *filename)
}
}
static void
resize_image_ok_cb(gpointer data)
{
gint per_x = _image_width * 100 / _map_info.old_image_width;
gint per_y = _image_height * 100 / _map_info.old_image_height;
object_list_resize(_shapes, per_x, per_y);
preview_thaw();
}
static void
resize_image_cancel_cb(gpointer data)
{
preview_thaw();
}
static void
do_image_size_changed_dialog(void)
{
static Alert_t *alert;
GtkWidget *dialog;
if (!alert) {
alert = create_confirm_alert(GTK_STOCK_DIALOG_WARNING);
alert_set_text(alert, _("Image size has changed."),
_("Resize area's?"));
}
default_dialog_set_ok_cb(alert->dialog, resize_image_ok_cb, NULL);
default_dialog_set_cancel_cb(alert->dialog, resize_image_cancel_cb, NULL);
default_dialog_show(alert->dialog);
dialog = gtk_message_dialog_new_with_markup
(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("Image size has changed."),
_("Resize area's?"));
gint result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_YES)
{
gint per_x = _image_width * 100 / _map_info.old_image_width;
gint per_y = _image_height * 100 / _map_info.old_image_height;
object_list_resize(_shapes, per_x, per_y);
}
preview_thaw();
gtk_widget_destroy (dialog);
}
static void

View File

@ -158,7 +158,7 @@ static GtkActionEntry entries[] = {
{ "Open", GTK_STOCK_OPEN, "_Open...", NULL, "Open", do_file_open_dialog},
{ "OpenRecentMenu", NULL, "Open Recent" },
{ "Save", GTK_STOCK_SAVE, "_Save...", NULL, "Save", save},
{ "SaveAs", GTK_STOCK_SAVE_AS, "Save _as...", NULL, NULL,
{ "SaveAs", GTK_STOCK_SAVE_AS, "Save _as...", "<shift><control>S", NULL,
do_file_save_as_dialog},
{ "Close", GTK_STOCK_CLOSE, NULL, NULL, NULL, do_close},
{ "Quit", GTK_STOCK_QUIT, NULL, NULL, NULL, do_quit},
@ -169,7 +169,7 @@ static GtkActionEntry entries[] = {
{ "Cut", GTK_STOCK_CUT, NULL, NULL, "Cut", do_cut},
{ "Copy", GTK_STOCK_COPY, NULL, NULL, "Copy", do_copy},
{ "Paste", GTK_STOCK_PASTE, NULL, NULL, "Paste", do_paste},
{ "Clear", GTK_STOCK_CLEAR, NULL, "<control>K", NULL, do_clear},
{ "Clear", GTK_STOCK_DELETE, NULL, "Delete", NULL, do_clear},
{ "SelectAll", NULL, "Select _All", "<control>A", NULL, do_select_all},
{ "DeselectAll", NULL, "Deselect _All", "<shift><control>A", NULL,
do_deselect_all},
@ -183,8 +183,8 @@ static GtkActionEntry entries[] = {
{ "ViewMenu", NULL, "_View" },
{ "Source", NULL, "Source...", NULL, NULL, NULL},
{ "ZoomIn", GTK_STOCK_ZOOM_IN, NULL, NULL, "Zoom in", NULL},
{ "ZoomOut", GTK_STOCK_ZOOM_OUT, NULL, NULL, "Zoom out", NULL},
{ "ZoomIn", GTK_STOCK_ZOOM_IN, NULL, "plus", "Zoom in", NULL},
{ "ZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "minus", "Zoom out", NULL},
{ "ZoomToMenu", NULL, "_Zoom To" },
{ "MappingMenu", NULL, "_Mapping" },

View File

@ -46,42 +46,6 @@ add_accelerator(GtkWidget *widget, guint accelerator_key,
GTK_ACCEL_VISIBLE);
}
static GtkWidget*
append_item(GtkWidget *parent, GtkWidget *item)
{
gtk_menu_shell_append(GTK_MENU_SHELL(parent), item);
gtk_widget_show(item);
return item;
}
static GtkWidget*
append_active_item(GtkWidget *parent, GtkWidget *item, MenuCallback activate,
gpointer data)
{
g_signal_connect(item, "activate", G_CALLBACK(activate), data);
return append_item(parent, item);
}
/* Fix me: check if 'gpointer data' can work */
GtkWidget*
make_item_with_label(GtkWidget *parent, gchar *label, MenuCallback activate,
gpointer data)
{
return append_active_item(parent, gtk_menu_item_new_with_mnemonic(label),
activate, data);
}
GtkWidget*
make_item_with_image(GtkWidget *parent, const gchar *stock_id,
MenuCallback activate, gpointer data)
{
return append_active_item(parent,
gtk_image_menu_item_new_from_stock(
stock_id, accelerator_group),
activate, data);
}
GtkWidget*
prepend_item_with_label(GtkWidget *parent, gchar *label,
MenuCallback activate, gpointer data)
@ -106,68 +70,6 @@ insert_item_with_label(GtkWidget *parent, gint position, gchar *label,
return item;
}
GtkWidget*
make_check_item(GtkWidget *parent, gchar *label, MenuCallback activate,
gpointer data)
{
return append_active_item(
parent, gtk_check_menu_item_new_with_mnemonic(label),
activate, data);
}
GtkWidget*
make_radio_item(GtkWidget *parent, GSList *group, gchar *label,
MenuCallback activate, gpointer data)
{
return append_active_item(
parent, gtk_radio_menu_item_new_with_mnemonic(group, label),
activate, data);
}
void
make_separator(GtkWidget *parent)
{
(void) append_item(parent, gtk_menu_item_new());
}
void
insert_separator(GtkWidget *parent, gint position)
{
GtkWidget *item = gtk_menu_item_new();
gtk_menu_shell_insert(GTK_MENU_SHELL(parent), item, position);
gtk_widget_show(item);
}
GtkWidget*
make_sub_menu(GtkWidget *parent, gchar *label)
{
GtkWidget *sub_menu = gtk_menu_new();
GtkWidget *item;
item = append_item(parent, gtk_menu_item_new_with_mnemonic(label));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub_menu);
return sub_menu;
}
GtkWidget*
make_menu_bar_item(GtkWidget *menu_bar, gchar *label)
{
GtkWidget *menu = gtk_menu_new();
GtkWidget *item = gtk_menu_item_new_with_mnemonic(label);
GtkWidget *tearoff = gtk_tearoff_menu_item_new();
gtk_menu_shell_insert(GTK_MENU_SHELL(menu), tearoff, 0);
gtk_widget_show(tearoff);
gtk_widget_show(item);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), item);
gtk_menu_set_accel_group(GTK_MENU(menu), accelerator_group);
return menu;
}
void
menu_command(GtkWidget *widget, gpointer data)
{

View File

@ -36,15 +36,7 @@ GtkWidget *prepend_item_with_label(GtkWidget *parent, gchar *label,
GtkWidget *insert_item_with_label(GtkWidget *parent, gint position,
gchar *label, MenuCallback activate,
gpointer data);
GtkWidget *make_check_item(GtkWidget *parent, gchar *label,
MenuCallback activate, gpointer data);
GtkWidget *make_radio_item(GtkWidget *parent, GSList *group, gchar *label,
MenuCallback activate, gpointer data);
void make_separator(GtkWidget *parent);
void insert_separator(GtkWidget *parent, gint position);
GtkWidget *make_sub_menu(GtkWidget *parent, gchar *label);
GtkWidget *make_menu_bar_item(GtkWidget *menu_bar, gchar *label);
void menu_command(GtkWidget *widget, gpointer data);
void add_accelerator(GtkWidget *widget, guint accelerator_key,

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -64,94 +64,6 @@ make_toolbar_stock_icon(GtkWidget *toolbar, const gchar *stock_id,
callback, udata);
}
GtkWidget*
make_toolbar_radio_icon(GtkWidget *toolbar, const gchar *stock_id,
GtkWidget *prev, const char *identifier,
const char *tooltip,
void (*callback)(GtkWidget*, gpointer),
gpointer udata)
{
GtkToolItem *item;
if (prev)
item = gtk_radio_tool_button_new_with_stock_from_widget
(GTK_RADIO_TOOL_BUTTON (prev), stock_id);
else
item = gtk_radio_tool_button_new_from_stock (NULL, stock_id);
g_signal_connect (item, "toggled", G_CALLBACK (callback), udata);
return make_toolbar_icon (toolbar, item, identifier, tooltip,
callback, udata);
}
GtkWidget*
make_toolbar_toggle_icon(GtkWidget *toolbar, const gchar *stock_id,
const char *identifier, const char *tooltip,
void (*callback)(GtkWidget*, gpointer),
gpointer udata)
{
GtkToolItem *item = gtk_toggle_tool_button_new_from_stock (stock_id);
g_signal_connect (item, "toggled", G_CALLBACK (callback), udata);
return make_toolbar_icon (toolbar, item, identifier, tooltip,
callback, udata);
}
static Alert_t*
create_base_alert(const gchar *stock_id)
{
Alert_t *alert = g_new(Alert_t, 1);
DefaultDialog_t *dialog;
GtkWidget *hbox;
GtkWidget *image;
alert->dialog = dialog = make_default_dialog("");
default_dialog_hide_apply_button(dialog);
hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start(GTK_BOX(dialog->vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show(hbox);
image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
gtk_container_add(GTK_CONTAINER(hbox), image);
gtk_widget_show(image);
alert->label = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(alert->label), 0.0, 0.0);
gtk_container_add(GTK_CONTAINER(hbox), alert->label);
gtk_widget_show(alert->label);
return alert;
}
Alert_t*
create_alert(const gchar *stock_id)
{
Alert_t *alert = create_base_alert(stock_id);
default_dialog_hide_cancel_button(alert->dialog);
return alert;
}
Alert_t*
create_confirm_alert(const gchar *stock_id)
{
return create_base_alert(stock_id);
}
void
alert_set_text(Alert_t *alert, const char *primary_text,
const char *secondary_text)
{
gchar *text;
text =
g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
primary_text, secondary_text);
gtk_label_set_markup (GTK_LABEL(alert->label), text);
g_free(text);
}
#define SASH_SIZE 8
static gint _sash_size = SASH_SIZE;

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,30 +30,10 @@ GtkWidget *make_toolbar_stock_icon(GtkWidget *toolbar, const gchar *stock_id,
const char *tooltip,
void (*callback)(GtkWidget*, gpointer),
gpointer udata);
GtkWidget *make_toolbar_radio_icon(GtkWidget *toolbar, const gchar *stock_id,
GtkWidget *prev, const char *identifier,
const char *tooltip,
void (*callback)(GtkWidget*, gpointer),
gpointer udata);
GtkWidget *make_toolbar_toggle_icon(GtkWidget *toolbar, const gchar *stock_id,
const char *identifier,
const char *tooltip,
void (*callback)(GtkWidget*, gpointer),
gpointer udata);
void set_sash_size(gboolean double_size);
void draw_sash(GdkWindow *window, GdkGC *gc, gint x, gint y);
gboolean near_sash(gint sash_x, gint sash_y, gint x, gint y);
typedef struct {
DefaultDialog_t *dialog;
GtkWidget *label;
} Alert_t;
Alert_t *create_alert(const gchar *stock_id);
Alert_t *create_confirm_alert(const gchar *stock_id);
void alert_set_text(Alert_t *alert, const char *primary_text,
const char *secondary_text);
#endif /* _IMAP_MISC_H */

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2003 Maurits Rijk lpeek.mrijk@consunet.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -375,23 +375,6 @@ object_emit_update_signal(Object_t *obj)
object_list_callback_call(&obj->list->update_cb, obj);
}
GdkPixmap*
object_get_icon(Object_t *obj, GtkWidget *widget, GdkBitmap **mask)
{
#ifdef _NOT_READY_YET_
/* This won't work: can't get a pixmap from a stock icon */
if (!obj->class->icon) {
GtkWidget *image = gtk_image_new_from_stock(
obj->class->get_stock_icon_name(), GTK_ICON_SIZE_MENU);
gtk_image_get_pixmap(GTK_IMAGE(image), &obj->class->icon,
&obj->class->mask);
}
*mask = obj->class->mask;
#endif
return obj->class->icon;
}
void
do_object_locked_dialog(void)
{

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -104,7 +104,6 @@ void object_set_mouse_out(Object_t *obj, const gchar *mouse_out);
void object_set_focus(Object_t *obj, const gchar *focus);
void object_set_blur(Object_t *obj, const gchar *blur);
gint object_get_position_in_list(Object_t *obj);
GdkPixmap* object_get_icon(Object_t *obj, GtkWidget *widget, GdkBitmap **mask);
void object_emit_changed_signal(Object_t *obj);
void object_emit_geometry_signal(Object_t *obj);
@ -131,6 +130,9 @@ void object_emit_update_signal(Object_t *obj);
#define object_fill_info_tab(obj, data) \
((obj)->class->fill_info_tab((obj), (data)))
#define object_get_stock_icon_name(obj) \
((obj)->class->get_stock_icon_name())
typedef struct {
Object_t *obj;
gboolean (*finish)(Object_t *obj, gint x, gint y);

View File

@ -3,7 +3,7 @@
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
* Copyright (C) 1998-2005 Maurits Rijk m.rijk@chello.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -329,7 +329,7 @@ render_image (GtkTreeViewColumn *column, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
{
Object_t *obj = selection_get_object (tree_model, iter);
g_object_set(cell, "stock-id", obj->class->get_stock_icon_name(), NULL);
g_object_set(cell, "stock-id", object_get_stock_icon_name(obj), NULL);
}
static void