156 lines
4.5 KiB
C
156 lines
4.5 KiB
C
/* LIBPIKA - The PIKA Library
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
*
|
|
* pikapaletteselectbutton.c
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
*
|
|
* 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 3 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
|
|
* Library 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, see
|
|
* <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <gegl.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "libpikawidgets/pikawidgets.h"
|
|
|
|
#include "pika.h"
|
|
|
|
#include "pikauitypes.h"
|
|
#include "pikapaletteselectbutton.h"
|
|
#include "pikauimarshal.h"
|
|
|
|
#include "libpika-intl.h"
|
|
|
|
|
|
/**
|
|
* SECTION: pikapaletteselectbutton
|
|
* @title: PikaPaletteSelectButton
|
|
* @short_description: A button which pops up a palette selection dialog.
|
|
*
|
|
* A button which pops up a palette selection dialog.
|
|
**/
|
|
|
|
struct _PikaPaletteSelectButton
|
|
{
|
|
PikaResourceSelectButton parent_instance;
|
|
|
|
GtkWidget *label;
|
|
GtkWidget *button;
|
|
};
|
|
|
|
|
|
static void pika_palette_select_button_draw_interior (PikaResourceSelectButton *self);
|
|
|
|
|
|
static const GtkTargetEntry drag_target = { "application/x-pika-palette-name", 0, 0 };
|
|
|
|
|
|
G_DEFINE_FINAL_TYPE (PikaPaletteSelectButton,
|
|
pika_palette_select_button,
|
|
PIKA_TYPE_RESOURCE_SELECT_BUTTON)
|
|
|
|
|
|
static void
|
|
pika_palette_select_button_class_init (PikaPaletteSelectButtonClass *klass)
|
|
{
|
|
PikaResourceSelectButtonClass *superclass = PIKA_RESOURCE_SELECT_BUTTON_CLASS (klass);
|
|
|
|
superclass->draw_interior = pika_palette_select_button_draw_interior;
|
|
superclass->resource_type = PIKA_TYPE_PALETTE;
|
|
}
|
|
|
|
static void
|
|
pika_palette_select_button_init (PikaPaletteSelectButton *self)
|
|
{
|
|
GtkWidget *hbox;
|
|
GtkWidget *image;
|
|
|
|
self->button = gtk_button_new ();
|
|
gtk_container_add (GTK_CONTAINER (self), self->button);
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
gtk_container_add (GTK_CONTAINER (self->button), hbox);
|
|
|
|
image = gtk_image_new_from_icon_name (PIKA_ICON_PALETTE,
|
|
GTK_ICON_SIZE_BUTTON);
|
|
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
|
|
|
|
self->label = gtk_label_new ("unknown");
|
|
gtk_box_pack_start (GTK_BOX (hbox), self->label, TRUE, TRUE, 4);
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (self));
|
|
|
|
pika_resource_select_button_set_drag_target (PIKA_RESOURCE_SELECT_BUTTON (self),
|
|
hbox,
|
|
&drag_target);
|
|
pika_resource_select_button_set_clickable (PIKA_RESOURCE_SELECT_BUTTON (self),
|
|
self->button);
|
|
}
|
|
|
|
static void
|
|
pika_palette_select_button_draw_interior (PikaResourceSelectButton *self)
|
|
{
|
|
PikaPaletteSelectButton *palette_select= PIKA_PALETTE_SELECT_BUTTON (self);
|
|
PikaResource *resource;
|
|
gchar *name = NULL;
|
|
|
|
resource = pika_resource_select_button_get_resource (self);
|
|
|
|
if (resource)
|
|
name = pika_resource_get_name (resource);
|
|
|
|
gtk_label_set_text (GTK_LABEL (palette_select->label), name);
|
|
}
|
|
|
|
|
|
/**
|
|
* pika_palette_select_button_new:
|
|
* @title: (nullable): Title of the dialog to use or %NULL to use the default title.
|
|
* @resource: (nullable): Initial palette.
|
|
*
|
|
* Creates a new #GtkWidget that lets a user choose a palette.
|
|
* You can put this widget in a table in a plug-in dialog.
|
|
*
|
|
* When palette is NULL, initial choice is from context.
|
|
*
|
|
* Returns: A #GtkWidget that you can use in your UI.
|
|
*
|
|
* Since: 2.4
|
|
*/
|
|
GtkWidget *
|
|
pika_palette_select_button_new (const gchar *title,
|
|
PikaResource *resource)
|
|
{
|
|
GtkWidget *self;
|
|
|
|
if (resource == NULL)
|
|
resource = PIKA_RESOURCE (pika_context_get_palette ());
|
|
|
|
if (title)
|
|
self = g_object_new (PIKA_TYPE_PALETTE_SELECT_BUTTON,
|
|
"title", title,
|
|
"resource", resource,
|
|
NULL);
|
|
else
|
|
self = g_object_new (PIKA_TYPE_PALETTE_SELECT_BUTTON,
|
|
"resource", resource,
|
|
NULL);
|
|
|
|
pika_palette_select_button_draw_interior (PIKA_RESOURCE_SELECT_BUTTON (self));
|
|
|
|
return self;
|
|
}
|