gimp/app/palette_select.c
Michael Natterer a11f33345d The GIMP Help System part II: press "F1" while browsing a menu to show the
1999-10-03  Michael Natterer  <mitch@gimp.org>

	The GIMP Help System part II: press "F1" while browsing a menu
	to show the help page for the menu entry you're currently over
	with the mouse.

	* app/color_notebook.c: all color selectors have to register with
	a help page now.

	* app/color_select.[ch]: register with a help string. Removed
	the dialog part of the files because it's use was deprecated
	anyway (use color notebooks instead).

	* app/colormap_dialog.i.c
	* app/colormap_dialog.p.h
	* app/palette.c
	* app/palette_select.c: use a color notebook instead of a color
	selector.

	* app/gimphelp.c
	* app/gimpui.c: minor changes.

	* app/gimprc.c: "use help" defaults to TRUE now.

	* app/lc_dialog.c
	* app/lc_dialogP.h: a special help function which shows the help
	for the currently selected notebook page.

	* app/menus.c: some weird code which catches "key_press_event"
	in all menu shells and pops up the corresp. help page for the
	selected item. Embedded the GtkItemFactoryEntry in a new
	GimpItemFactoryEntry to allow a help path to be stored.
	Will be partially exported and moved to gimphelp.[ch] later to
	catch key_press for plug-in menu items (don't try this now ;-)

	* app/app_procs.c
	* app/brush_edit.c
	* app/brush_select.c
	* app/channel_ops.c
	* app/channels_dialog.c
	* app/commands.c
	* app/convert.c
	* app/devices.c
	* app/file_new_dialog.c
	* app/fileops.c
	* app/gdisplay.c
	* app/gdisplay_color.c
	* app/gdisplay_color_ui.c
	* app/gdisplay_ops.c
	* app/global_edit.c
	* app/gradient.c
	* app/gradient_select.c
	* app/interface.c
	* app/layers_dialog.c
	* app/module_db.c
	* app/paths_dialog.c
	* app/pattern_select.c
	* app/preferences_dialog.c
	* app/qmask.c
	* app/resize.c
	* app/undo_history.c: changed all dialog constructors to point
	to the right place in the new help file structure.

	* configure.in
	* help/*: the basic new help file structure.

	* modules/colorsel_gtk.c
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: register a help page.

	* plug-ins/helpbrowser/helpbrowser.c: load the help files
	according to the new help file structure.
1999-10-03 13:50:19 +00:00

303 lines
7.6 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
* Copyright (C) 1998 Andy Thomas (alt@picnic.demon.co.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "gimpui.h"
#include "palette_entries.h"
#include "session.h"
#include "palette_select.h"
#include "libgimp/gimpintl.h"
/* List of active dialogs */
static GSList *active_dialogs = NULL;
/* local function prototypes */
static void palette_select_close_callback (GtkWidget *, gpointer);
static void palette_select_edit_callback (GtkWidget *, gpointer);
void
palette_select_set_text_all (PaletteEntriesP entries)
{
gint pos = 0;
char *num_buf;
GSList *aclist = active_dialogs;
GSList *plist;
PaletteSelectP psp;
PaletteEntriesP p_entries = NULL;
plist = palette_entries_list;
while (plist)
{
p_entries = (PaletteEntriesP) plist->data;
plist = g_slist_next (plist);
if (p_entries == entries)
break;
pos++;
}
if(p_entries == NULL)
return; /* This is actually and error */
num_buf = g_strdup_printf("%d",p_entries->n_colors);;
while(aclist)
{
char *num_copy = g_strdup(num_buf);
psp = (PaletteSelectP)aclist->data;
gtk_clist_set_text(GTK_CLIST(psp->clist),pos,1,num_copy);
aclist = g_slist_next(aclist);
}
}
void
palette_select_refresh_all ()
{
GSList *list = active_dialogs;
PaletteSelectP psp;
while(list)
{
psp = (PaletteSelectP)list->data;
gtk_clist_freeze(GTK_CLIST(psp->clist));
gtk_clist_clear(GTK_CLIST(psp->clist));
palette_clist_init(psp->clist,psp->shell,psp->gc);
gtk_clist_thaw(GTK_CLIST(psp->clist));
list = g_slist_next(list);
}
}
void
palette_select_clist_insert_all (PaletteEntriesP p_entries)
{
GSList *aclist = active_dialogs;
PaletteEntriesP chk_entries;
PaletteSelectP psp;
GSList *plist;
gint pos = 0;
plist = palette_entries_list;
while (plist)
{
chk_entries = (PaletteEntriesP) plist->data;
plist = g_slist_next (plist);
/* to make sure we get something! */
if (chk_entries == NULL)
{
return;
}
if (strcmp(p_entries->name, chk_entries->name) == 0)
break;
pos++;
}
while(aclist)
{
psp = (PaletteSelectP)aclist->data;
gtk_clist_freeze(GTK_CLIST(psp->clist));
palette_insert_clist(psp->clist,psp->shell,psp->gc,p_entries,pos);
gtk_clist_thaw(GTK_CLIST(psp->clist));
aclist = g_slist_next(aclist);
}
/* if(gradient_select_dialog) */
/* { */
/* gtk_clist_set_text(GTK_CLIST(gradient_select_dialog->clist),n,1,grad->name); */
/* } */
}
void
palette_select_free (PaletteSelectP psp)
{
if (psp)
{
/* if(psp->callback_name) */
/* g_free(gsp->callback_name); */
/* remove from active list */
active_dialogs = g_slist_remove(active_dialogs,psp);
g_free (psp);
}
}
static void
palette_select_edit_callback (GtkWidget *widget,
gpointer client_data)
{
PaletteEntriesP p_entries = NULL;
PaletteSelectP psp = (PaletteSelectP)client_data;
GList *sel_list;
sel_list = GTK_CLIST(psp->clist)->selection;
if(sel_list)
{
while (sel_list)
{
gint row;
row = GPOINTER_TO_INT (sel_list->data);
p_entries =
(PaletteEntriesP) gtk_clist_get_row_data (GTK_CLIST (psp->clist),
row);
palette_create_edit (p_entries);
/* One only */
return;
}
}
}
static void
palette_select_close_callback (GtkWidget *widget,
gpointer client_data)
{
PaletteSelectP psp;
psp = (PaletteSelectP) client_data;
if (GTK_WIDGET_VISIBLE (psp->shell))
gtk_widget_hide (psp->shell);
gtk_widget_destroy (psp->shell);
palette_select_free (psp);
/* Free memory if poping down dialog which is not the main one */
/* if(gsp != gradient_select_dialog) */
/* { */
/* grad_change_callbacks(gsp,1); */
/* gtk_widget_destroy(gsp->shell); */
/* grad_select_free(gsp); */
/* } */
}
PaletteSelectP
palette_new_selection (gchar *title,
gchar *initial_palette)
{
PaletteSelectP psp;
/* gradient_t *grad = NULL; */
GSList *list;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *scrolled_win;
PaletteEntriesP p_entries = NULL;
int select_pos;
palette_select_palette_init ();
psp = g_new (struct _PaletteSelect, 1);
psp->callback_name = NULL;
/* The shell and main vbox */
psp->shell = gimp_dialog_new (title ? title : _("Palette Selection"),
"palette_selection",
gimp_standard_help_func,
"dialogs/palette_selection.html",
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
_("Edit"), palette_select_edit_callback,
psp, NULL, TRUE, FALSE,
_("Close"), palette_select_close_callback,
psp, NULL, FALSE, TRUE,
NULL);
vbox = gtk_vbox_new (FALSE, 1);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 1);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox), vbox);
/* clist preview of gradients */
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
psp->clist = gtk_clist_new (3);
gtk_clist_set_shadow_type (GTK_CLIST (psp->clist), GTK_SHADOW_IN);
gtk_clist_set_row_height (GTK_CLIST (psp->clist), SM_PREVIEW_HEIGHT + 2);
gtk_widget_set_usize (psp->clist, 203, 200);
gtk_clist_set_column_title (GTK_CLIST (psp->clist), 0, _("Palette"));
gtk_clist_set_column_title (GTK_CLIST (psp->clist), 1, _("Ncols"));
gtk_clist_set_column_title (GTK_CLIST (psp->clist), 2, _("Name"));
gtk_clist_column_titles_show (GTK_CLIST(psp->clist));
gtk_clist_set_column_width (GTK_CLIST (psp->clist), 0, SM_PREVIEW_WIDTH + 2);
hbox = gtk_hbox_new (FALSE, 8);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (scrolled_win), psp->clist);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_widget_show (scrolled_win);
gtk_widget_show (psp->clist);
/* gtk_signal_connect(GTK_OBJECT(gsp->clist), "select_row", */
/* GTK_SIGNAL_FUNC(sel_list_item_update), */
/* (gpointer) gsp); */
select_pos = -1;
if (initial_palette && strlen (initial_palette))
{
list = palette_entries_list;
while (list)
{
p_entries = (PaletteEntriesP) list->data;
list = g_slist_next (list);
if (strcmp (p_entries->name, initial_palette) > 0)
break;
select_pos++;
}
}
gtk_widget_realize (psp->shell);
psp->gc = gdk_gc_new (psp->shell->window);
palette_clist_init (psp->clist, psp->shell, psp->gc);
/* Now show the dialog */
gtk_widget_show (vbox);
gtk_widget_show (psp->shell);
if (select_pos != -1)
{
gtk_clist_select_row (GTK_CLIST (psp->clist), select_pos, -1);
gtk_clist_moveto (GTK_CLIST (psp->clist), select_pos, 0, 0.0, 0.0);
}
else
gtk_clist_select_row (GTK_CLIST (psp->clist), 0, -1);
active_dialogs = g_slist_append (active_dialogs, psp);
return psp;
}