gimpui.c 3.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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 
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

Sven Neumann's avatar
Sven Neumann committed
20 21
#include "config.h"

22 23 24
#include "gimp.h"
#include "gimpui.h"

25
#include "libgimpwidgets/gimpwidgets.h"
26
#include "libgimpwidgets/gimpwidgets-private.h"
27

28 29 30 31 32 33 34 35

/*  local function prototypes  */

static void  gimp_ui_help_func (const gchar *help_data);


/*  public functions  */

36 37 38 39 40
/**
 * gimp_ui_init:
 * @prog_name: The name of the plug-in which will be passed as argv[0] to
 *             gtk_init(). It's a convention to use the name of the
 *             executable and _not_ the PDB procedure name or something.
41 42
 * @preview: %TRUE if the plug-in has some kind of preview in it's UI.
 *           Note that passing %TRUE is recommended also if one of the
43 44 45
 *           used GIMP Library widgets contains a preview (like the image
 *           menu returned by gimp_image_menu_new()).
 *
46 47 48
 * This function initializes GTK+ with gtk_init() and initializes GDK's 
 * image rendering subsystem (GdkRGB) to follow the GIMP main program's 
 * colormap allocation/installation policy.
49 50 51
 *
 * The GIMP's colormap policy can be determinded by the user with the
 * gimprc variables @min_colors and @install_cmap.
52
 **/
53
void
54 55
gimp_ui_init (const gchar *prog_name,
	      gboolean     preview)
56
{
57 58 59 60
  static gboolean initialized = FALSE;

  GimpWidgetsVTable vtable;

61 62
  gint    argc;
  gchar **argv;
63
  gchar  *user_gtkrc;
64 65 66 67 68 69 70 71 72 73 74 75 76

  g_return_if_fail (prog_name != NULL);

  if (initialized)
    return;

  argc    = 1;
  argv    = g_new (gchar *, 1);
  argv[0] = g_strdup (prog_name);

  gtk_init (&argc, &argv);
  gtk_rc_parse (gimp_gtkrc ());

77 78 79 80
  user_gtkrc = gimp_personal_rc_file ("gtkrc");
  gtk_rc_parse (user_gtkrc);
  g_free (user_gtkrc);

81 82
  gdk_rgb_set_min_colors (gimp_min_colors ());
  gdk_rgb_set_install (gimp_install_cmap ());
83

84
  gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
85 86 87 88 89 90 91

  /*  Set the gamma after installing the colormap because
   *  gtk_preview_set_gamma() initializes GdkRGB if not already done
   */
  if (preview)
    gtk_preview_set_gamma (gimp_gamma ());

92 93 94 95 96 97 98 99 100 101 102
  /*  Initialize the eeky vtable needed by libgimpwidgets  */
  vtable.unit_get_number_of_units = gimp_unit_get_number_of_units;
  vtable.unit_get_number_of_built_in_units = gimp_unit_get_number_of_built_in_units;
  vtable.unit_get_factor          = gimp_unit_get_factor;
  vtable.unit_get_digits          = gimp_unit_get_digits;
  vtable.unit_get_identifier      = gimp_unit_get_identifier;
  vtable.unit_get_symbol          = gimp_unit_get_symbol;
  vtable.unit_get_abbreviation    = gimp_unit_get_abbreviation;
  vtable.unit_get_singular        = gimp_unit_get_singular;
  vtable.unit_get_plural          = gimp_unit_get_plural;

103 104 105 106
  gimp_widgets_init (&vtable,
                     gimp_ui_help_func,
                     gimp_palette_get_foreground,
                     gimp_palette_get_background);
107

108 109 110
  if (! gimp_show_tool_tips ())
    gimp_help_disable_tooltips ();

111 112
  initialized = TRUE;
}
113 114 115 116 117 118 119 120 121


/*  private functions  */

static void
gimp_ui_help_func (const gchar *help_data)
{
  gimp_help (gimp_get_progname (), (gchar *) help_data);
}