gimp/app/dialogs/tips-dialog.c

326 lines
9.1 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
1999-03-07 20:56:03 +08:00
#include "config.h"
1997-11-25 06:05:25 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
1997-11-25 06:05:25 +08:00
#include "tips_dialog.h"
#include "gimprc.h"
#include "gimpui.h"
1997-11-25 06:05:25 +08:00
1999-03-07 20:56:03 +08:00
#include "libgimp/gimpenv.h"
#include "libgimp/gimpintl.h"
#include "wilber.h"
#define TIPS_DIR_NAME "tips"
1997-11-25 06:05:25 +08:00
static void tips_dialog_destroy (GtkWidget *widget, gpointer data);
static void tips_show_previous (GtkWidget *widget, gpointer data);
static void tips_show_next (GtkWidget *widget, gpointer data);
static void tips_toggle_update (GtkWidget *widget, gpointer data);
static void read_tips_file (gchar *filename);
1997-11-25 06:05:25 +08:00
static GtkWidget *tips_dialog = NULL;
static GtkWidget *tips_label;
static gchar **tips_text = NULL;
static gint tips_count = 0;
static gint old_show_tips;
1997-11-25 06:05:25 +08:00
void
tips_dialog_create (void)
1997-11-25 06:05:25 +08:00
{
GtkWidget *vbox;
GtkWidget *vbox2;
GtkWidget *hbox;
Add default to Cancel button, remove unset GTK_RECEIVES_DEFAULT from Sat Feb 20 16:12:33 CST 1999 Shawn T. Amundson <amundson@gimp.org> * app/tips_dialog.c: Add default to Cancel button, remove unset GTK_RECEIVES_DEFAULT from prev/next buttons (they are like toolbar buttons), changed abreviated prev to previous, prev/next button are now same size, cancel button is in a button box. Added vboxes where necessary to prevent prev/next and check button from filling vertically. * app/app_procs.c: when splashscreen dialog is larger than the logo, (due to huge font), center logo. * app/file_new_dialog.c: patch from Marco Lamb <lm@geocities.com> disallows resizing, changes vertical expanding of widgets to not occur * app/palette.c: patch from Marco Lamb <lm@geocities.com>. Makes +/- buttons for zoom pixmaps (eventually, these can be replaced with a magnifying glass with a little +/- I think), so that they no longer expand as they did before. I modified his patch so it did not create a misused toolbar. I did some other stuff here too, moved Close button to the left, made it the window's default, and unset GTK_RECEIVES_DEFAULT off of the non-bottom buttons. * app/actionarea.c: another patch from Marco Lamb <lm@geocities.com>. This one changes buttons to be put in a button box which is right justified. If we decide later that spread is better, we can change this easy enough. * app/tools/zoom_in.xpm, app/tools/zoom_out.xpm: + and - graphics. * libgimp/gimpunit.h libgimp/gimpunit.c: New files from Michael Natterer <mitschel@cs.tu-berlin.de>, gimp_unit_* routines. * app/gimage.h app/gimpimage.h app/gimpimage.c app/gimpimageP.h app/xcf.c: Patches from Michael Natterer <mitschel@cs.tu-berlin.de>, which keep a unit assocated with an image.
1999-02-21 10:08:15 +08:00
GtkWidget *bbox;
1999-04-20 19:13:33 +08:00
GtkWidget *frame;
1997-11-25 06:05:25 +08:00
GtkWidget *preview;
GtkWidget *button;
gchar *temp;
guchar *utemp;
guchar *src;
guchar *dest;
gint x;
gint y;
1997-11-25 06:05:25 +08:00
if (tips_count == 0)
{
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
temp = g_strdup_printf ("%s" G_DIR_SEPARATOR_S TIPS_DIR_NAME
G_DIR_SEPARATOR_S "%s",
gimp_data_directory (),
_("gimp_tips.txt"));
1999-03-07 20:56:03 +08:00
read_tips_file (temp);
1997-11-25 06:05:25 +08:00
g_free (temp);
}
if (last_tip >= tips_count || last_tip < 0)
last_tip = 0;
if (!tips_dialog)
{
tips_dialog = gtk_window_new (GTK_WINDOW_DIALOG);
gtk_window_set_wmclass (GTK_WINDOW (tips_dialog), "tip_of_the_day", "Gimp");
1999-12-15 07:09:54 +08:00
gtk_window_set_title (GTK_WINDOW (tips_dialog), _("GIMP Tip of the Day"));
gtk_window_set_position (GTK_WINDOW (tips_dialog), GTK_WIN_POS_CENTER);
gtk_window_set_policy (GTK_WINDOW (tips_dialog), FALSE, TRUE, FALSE);
1997-11-25 06:05:25 +08:00
gtk_signal_connect (GTK_OBJECT (tips_dialog), "delete_event",
GTK_SIGNAL_FUNC (tips_dialog_destroy),
NULL);
gtk_signal_connect (GTK_OBJECT (tips_dialog), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&tips_dialog);
/* destroy the tips window if the mainlevel gtk_main() function is left */
gtk_quit_add_destroy (1, GTK_OBJECT (tips_dialog));
1997-11-25 06:05:25 +08:00
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (tips_dialog), vbox);
1997-11-25 06:05:25 +08:00
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 5);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
1997-11-25 06:05:25 +08:00
tips_label = gtk_label_new (tips_text[last_tip]);
gtk_label_set_justify (GTK_LABEL (tips_label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (tips_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), tips_label, TRUE, TRUE, 3);
gtk_widget_show (tips_label);
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (vbox2), frame, TRUE, FALSE, 0);
1997-11-25 06:05:25 +08:00
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview), wilber_width, wilber_height);
utemp = g_new (guchar, wilber_width * 3);
src = (guchar *)wilber_data;
1997-11-25 06:05:25 +08:00
for (y = 0; y < wilber_height; y++)
{
dest = utemp;
1997-11-25 06:05:25 +08:00
for (x = 0; x < wilber_width; x++)
{
HEADER_PIXEL (src, dest);
1997-11-25 06:05:25 +08:00
dest += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), utemp, 0, y, wilber_width);
1997-11-25 06:05:25 +08:00
}
g_free(utemp);
1999-04-20 19:13:33 +08:00
gtk_container_add (GTK_CONTAINER (frame), preview);
1997-11-25 06:05:25 +08:00
gtk_widget_show (preview);
1999-04-20 19:13:33 +08:00
gtk_widget_show (frame);
gtk_widget_show (vbox2);
hbox = gtk_hbox_new (FALSE, 15);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
button =
gtk_check_button_new_with_label (_("Show tip next time GIMP starts"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
show_tips);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
GTK_SIGNAL_FUNC (tips_toggle_update),
(gpointer) &show_tips);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
1997-11-25 06:05:25 +08:00
old_show_tips = show_tips;
1997-11-25 06:05:25 +08:00
bbox = gtk_hbutton_box_new ();
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
1997-11-25 06:05:25 +08:00
button = gtk_button_new_with_label (_("Close"));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_window_set_default (GTK_WINDOW (tips_dialog), button);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (tips_dialog_destroy),
NULL);
gtk_container_add (GTK_CONTAINER (bbox), button);
gtk_widget_show (button);
Add default to Cancel button, remove unset GTK_RECEIVES_DEFAULT from Sat Feb 20 16:12:33 CST 1999 Shawn T. Amundson <amundson@gimp.org> * app/tips_dialog.c: Add default to Cancel button, remove unset GTK_RECEIVES_DEFAULT from prev/next buttons (they are like toolbar buttons), changed abreviated prev to previous, prev/next button are now same size, cancel button is in a button box. Added vboxes where necessary to prevent prev/next and check button from filling vertically. * app/app_procs.c: when splashscreen dialog is larger than the logo, (due to huge font), center logo. * app/file_new_dialog.c: patch from Marco Lamb <lm@geocities.com> disallows resizing, changes vertical expanding of widgets to not occur * app/palette.c: patch from Marco Lamb <lm@geocities.com>. Makes +/- buttons for zoom pixmaps (eventually, these can be replaced with a magnifying glass with a little +/- I think), so that they no longer expand as they did before. I modified his patch so it did not create a misused toolbar. I did some other stuff here too, moved Close button to the left, made it the window's default, and unset GTK_RECEIVES_DEFAULT off of the non-bottom buttons. * app/actionarea.c: another patch from Marco Lamb <lm@geocities.com>. This one changes buttons to be put in a button box which is right justified. If we decide later that spread is better, we can change this easy enough. * app/tools/zoom_in.xpm, app/tools/zoom_out.xpm: + and - graphics. * libgimp/gimpunit.h libgimp/gimpunit.c: New files from Michael Natterer <mitschel@cs.tu-berlin.de>, gimp_unit_* routines. * app/gimage.h app/gimpimage.h app/gimpimage.c app/gimpimageP.h app/xcf.c: Patches from Michael Natterer <mitschel@cs.tu-berlin.de>, which keep a unit assocated with an image.
1999-02-21 10:08:15 +08:00
bbox = gtk_hbutton_box_new ();
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), 5);
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
1997-11-25 06:05:25 +08:00
button = gtk_button_new_with_label (_("Previous Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (tips_show_previous),
NULL);
gtk_container_add (GTK_CONTAINER (bbox), button);
gtk_widget_show (button);
1997-11-25 06:05:25 +08:00
button = gtk_button_new_with_label (_("Next Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (tips_show_next),
NULL);
gtk_container_add (GTK_CONTAINER (bbox), button);
gtk_widget_show (button);
1999-10-04 16:40:33 +08:00
/* Connect the "F1" help key */
1999-10-04 16:40:33 +08:00
gimp_help_connect_help_accel (tips_dialog,
gimp_standard_help_func,
"dialogs/tip_of_the_day.html");
1997-11-25 06:05:25 +08:00
}
if (!GTK_WIDGET_VISIBLE (tips_dialog))
{
gtk_widget_show (tips_dialog);
}
else
{
gdk_window_raise (tips_dialog->window);
}
}
static void
tips_dialog_destroy (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
GList *update = NULL; /* options that should be updated in .gimprc */
GList *remove = NULL; /* options that should be commented out */
gtk_widget_destroy (tips_dialog);
1997-11-25 06:05:25 +08:00
/* the last-shown-tip is now saved in sessionrc */
1997-11-25 06:05:25 +08:00
if (show_tips != old_show_tips)
{
update = g_list_append (update, "show-tips");
remove = g_list_append (remove, "dont-show-tips");
old_show_tips = show_tips;
save_gimprc (&update, &remove);
1997-11-25 06:05:25 +08:00
}
g_list_free (update);
g_list_free (remove);
}
1997-11-25 06:05:25 +08:00
static void
tips_show_previous (GtkWidget *widget,
gpointer data)
{
last_tip--;
if (last_tip < 0)
last_tip = tips_count - 1;
gtk_label_set (GTK_LABEL (tips_label), tips_text[last_tip]);
1997-11-25 06:05:25 +08:00
}
static void
1997-11-25 06:05:25 +08:00
tips_show_next (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
last_tip++;
if (last_tip >= tips_count)
last_tip = 0;
1997-11-25 06:05:25 +08:00
gtk_label_set (GTK_LABEL (tips_label), tips_text[last_tip]);
}
static void
tips_toggle_update (GtkWidget *widget,
gpointer data)
{
gint *toggle_val;
1997-11-25 06:05:25 +08:00
toggle_val = (gint *) data;
1997-11-25 06:05:25 +08:00
if (GTK_TOGGLE_BUTTON (widget)->active)
*toggle_val = TRUE;
else
*toggle_val = FALSE;
}
static void
store_tip (gchar *str)
1997-11-25 06:05:25 +08:00
{
tips_count++;
tips_text = g_realloc (tips_text, sizeof (gchar *) * tips_count);
1997-11-25 06:05:25 +08:00
tips_text[tips_count - 1] = str;
}
static void
read_tips_file (gchar *filename)
1997-11-25 06:05:25 +08:00
{
FILE *fp;
gchar *tip = NULL;
gchar *str = NULL;
1997-11-25 06:05:25 +08:00
1999-08-20 17:24:56 +08:00
fp = fopen (filename, "rt");
1997-11-25 06:05:25 +08:00
if (!fp)
{
store_tip (_("Your GIMP tips file appears to be missing!\n"
"There should be a file called gimp_tips.txt in\n"
"the tips subdirectory of the GIMP data directory.\n"
"Please check your installation."));
1997-11-25 06:05:25 +08:00
return;
}
str = g_new (char, 1024);
while (!feof (fp))
{
if (!fgets (str, 1024, fp))
continue;
1997-11-25 06:05:25 +08:00
if (str[0] == '#' || str[0] == '\n')
{
if (tip != NULL)
{
tip[strlen (tip) - 1] = '\000';
1997-11-25 06:05:25 +08:00
store_tip (tip);
tip = NULL;
}
}
else
{
if (tip == NULL)
{
tip = g_malloc (strlen (str) + 1);
strcpy (tip, str);
}
else
{
tip = g_realloc (tip, strlen (tip) + strlen (str) + 1);
strcat (tip, str);
}
}
}
if (tip != NULL)
store_tip (tip);
g_free (str);
fclose (fp);
}