Commit a8fed65a authored by Arturo Espinosa's avatar Arturo Espinosa

Added a pattern selector widget, use color pickers, pattern selector -Miguel

parent 5837f657
1998-09-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (create_background_radio): Use the new
pattern selector.
(create_foreground_radio, create_background_radio): Use the new
gnome color pickers.
* src/pattern-selector.c (pattern_selector_select): New widget.
This is a patter selector.
1998-09-08 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_button_press): Lots of changes to
......
1998-09-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (create_background_radio): Use the new
pattern selector.
(create_foreground_radio, create_background_radio): Use the new
gnome color pickers.
* src/pattern-selector.c (pattern_selector_select): New widget.
This is a patter selector.
1998-09-08 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_button_press): Lots of changes to
......
1998-09-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (create_background_radio): Use the new
pattern selector.
(create_foreground_radio, create_background_radio): Use the new
gnome color pickers.
* src/pattern-selector.c (pattern_selector_select): New widget.
This is a patter selector.
1998-09-08 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_button_press): Lots of changes to
......
1998-09-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/dialog-cell-format.c (create_background_radio): Use the new
pattern selector.
(create_foreground_radio, create_background_radio): Use the new
gnome color pickers.
* src/pattern-selector.c (pattern_selector_select): New widget.
This is a patter selector.
1998-09-08 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-object.c (sheet_button_press): Lots of changes to
......
......@@ -52,6 +52,8 @@ GNUMERIC_BASE_SOURCES = \
item-grid.c \
item-grid.h \
parser.y \
pattern-selector.c \
pattern-selector.h \
sheet.c \
sheet.h \
sheet-object.c \
......
......@@ -13,6 +13,7 @@
#include "gnumeric-sheet.h"
#include "dialogs.h"
#include "format.h"
#include "pattern-selector.h"
/* The main dialog box */
static GtkWidget *cell_format_prop_win = 0;
......@@ -33,7 +34,6 @@ static GtkWidget *auto_return;
/* These points to the radio buttons of the coloring page */
static GSList *foreground_radio_list;
static GSList *background_radio_list;
static GdkPixmap *patterns [GNUMERIC_SHEET_PATTERNS];
/* Points to the first cell in the selection */
static Cell *first_cell;
......@@ -638,7 +638,7 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
static GtkWidget *
create_foreground_radio (GtkWidget *prop_win)
{
GtkWidget *frame, *table, *r1, *r2;
GtkWidget *frame, *table, *r1, *r2, *cs;
int e = GTK_FILL | GTK_EXPAND;
frame = gtk_frame_new (_("Text color"));
......@@ -650,68 +650,14 @@ create_foreground_radio (GtkWidget *prop_win)
r2 = gtk_radio_button_new_with_label (foreground_radio_list,
_("Use this color"));
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 0, 0);
/* gtk_table_attach (GTK_TABLE (table), cs, 1, 2, 1, 2, 0, 0, 0, 0); */
cs = gnome_color_picker_new ();
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs, 1, 2, 1, 2, 0, 0, 0, 0);
return frame;
}
static void
create_stipples (GnomeCanvas *canvas)
{
GnomeCanvasGroup *group;
GdkWindow *window;
int i;
group = GNOME_CANVAS_GROUP (gnome_canvas_root (canvas));
window = GTK_WIDGET (canvas)->window;
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++){
GnomeCanvasRE *item;
int x, y;
x = i % 7;
y = i / 7;
item = GNOME_CANVAS_RE (gnome_canvas_item_new (
group,
gnome_canvas_rect_get_type (),
"x1", (double) x * 10.0,
"y1", (double) y * 10.0,
"x2", (double) x * 10.0 + 8.0,
"y2", (double) y * 10.0 + 8.0,
"fill_color", "black",
"width_pixels", (int) 1,
"outline_color","black",
NULL));
patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
gdk_gc_set_stipple (item->fill_gc, patterns [i]);
gdk_gc_set_fill (item->fill_gc, GDK_STIPPLED);
}
}
static GtkWidget *
create_pattern_preview (GtkWidget *prop_win)
{
GnomeCanvas *canvas;
canvas = (GnomeCanvas *) gnome_canvas_new ();
gnome_canvas_set_size (canvas, 280, 80);
gnome_canvas_set_scroll_region (canvas, 0.0, 0.0, 70.0, 80.0);
gnome_canvas_set_pixels_per_unit (canvas, 1.0);
gtk_signal_connect_after (
GTK_OBJECT (canvas), "realize",
GTK_SIGNAL_FUNC (create_stipples), NULL);
return GTK_WIDGET (canvas);
}
static GtkWidget *
create_background_radio (GtkWidget *prop_win)
{
......@@ -721,28 +667,29 @@ create_background_radio (GtkWidget *prop_win)
frame = gtk_frame_new (_("Background configuration"));
table = gtk_table_new (2, 2, 0);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_container_border_width (GTK_CONTAINER (frame), 5);
/* The radio buttons */
r1 = gtk_radio_button_new_with_label (NULL, _("None"));
background_radio_list = GTK_RADIO_BUTTON (r1)->group;
r2 = gtk_radio_button_new_with_label (background_radio_list,
_("Use solid color"));
r3 = gtk_radio_button_new_with_label (background_radio_list,
_("Use a pattern"));
r2 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (r1), _("Use solid color"));
r3 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (r1), _("Use a pattern"));
/* The color selectors */
cs1 = gtk_label_new ("color selector goes here");
cs2 = gtk_label_new ("color selector goes here");
cs1 = gnome_color_picker_new ();
cs2 = gnome_color_picker_new ();
/* Create the pattern preview */
p = create_pattern_preview (prop_win);
p = pattern_selector_new (0);
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r3, 0, 1, 2, 3, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r3, 0, 1, 2, 3, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs1, 1, 2, 1, 2, 0, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), cs2, 1, 2, 2, 3, 0, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), cs1, 1, 2, 1, 2, 0, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs2, 1, 2, 2, 3, 0, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), p, 0, 2, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
return frame;
}
......
......@@ -13,6 +13,7 @@
#include "gnumeric-sheet.h"
#include "dialogs.h"
#include "format.h"
#include "pattern-selector.h"
/* The main dialog box */
static GtkWidget *cell_format_prop_win = 0;
......@@ -33,7 +34,6 @@ static GtkWidget *auto_return;
/* These points to the radio buttons of the coloring page */
static GSList *foreground_radio_list;
static GSList *background_radio_list;
static GdkPixmap *patterns [GNUMERIC_SHEET_PATTERNS];
/* Points to the first cell in the selection */
static Cell *first_cell;
......@@ -638,7 +638,7 @@ apply_font_format (Style *style, Sheet *sheet, CellList *cells)
static GtkWidget *
create_foreground_radio (GtkWidget *prop_win)
{
GtkWidget *frame, *table, *r1, *r2;
GtkWidget *frame, *table, *r1, *r2, *cs;
int e = GTK_FILL | GTK_EXPAND;
frame = gtk_frame_new (_("Text color"));
......@@ -650,68 +650,14 @@ create_foreground_radio (GtkWidget *prop_win)
r2 = gtk_radio_button_new_with_label (foreground_radio_list,
_("Use this color"));
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 0, 0);
/* gtk_table_attach (GTK_TABLE (table), cs, 1, 2, 1, 2, 0, 0, 0, 0); */
cs = gnome_color_picker_new ();
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs, 1, 2, 1, 2, 0, 0, 0, 0);
return frame;
}
static void
create_stipples (GnomeCanvas *canvas)
{
GnomeCanvasGroup *group;
GdkWindow *window;
int i;
group = GNOME_CANVAS_GROUP (gnome_canvas_root (canvas));
window = GTK_WIDGET (canvas)->window;
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++){
GnomeCanvasRE *item;
int x, y;
x = i % 7;
y = i / 7;
item = GNOME_CANVAS_RE (gnome_canvas_item_new (
group,
gnome_canvas_rect_get_type (),
"x1", (double) x * 10.0,
"y1", (double) y * 10.0,
"x2", (double) x * 10.0 + 8.0,
"y2", (double) y * 10.0 + 8.0,
"fill_color", "black",
"width_pixels", (int) 1,
"outline_color","black",
NULL));
patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
gdk_gc_set_stipple (item->fill_gc, patterns [i]);
gdk_gc_set_fill (item->fill_gc, GDK_STIPPLED);
}
}
static GtkWidget *
create_pattern_preview (GtkWidget *prop_win)
{
GnomeCanvas *canvas;
canvas = (GnomeCanvas *) gnome_canvas_new ();
gnome_canvas_set_size (canvas, 280, 80);
gnome_canvas_set_scroll_region (canvas, 0.0, 0.0, 70.0, 80.0);
gnome_canvas_set_pixels_per_unit (canvas, 1.0);
gtk_signal_connect_after (
GTK_OBJECT (canvas), "realize",
GTK_SIGNAL_FUNC (create_stipples), NULL);
return GTK_WIDGET (canvas);
}
static GtkWidget *
create_background_radio (GtkWidget *prop_win)
{
......@@ -721,28 +667,29 @@ create_background_radio (GtkWidget *prop_win)
frame = gtk_frame_new (_("Background configuration"));
table = gtk_table_new (2, 2, 0);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_container_border_width (GTK_CONTAINER (frame), 5);
/* The radio buttons */
r1 = gtk_radio_button_new_with_label (NULL, _("None"));
background_radio_list = GTK_RADIO_BUTTON (r1)->group;
r2 = gtk_radio_button_new_with_label (background_radio_list,
_("Use solid color"));
r3 = gtk_radio_button_new_with_label (background_radio_list,
_("Use a pattern"));
r2 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (r1), _("Use solid color"));
r3 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (r1), _("Use a pattern"));
/* The color selectors */
cs1 = gtk_label_new ("color selector goes here");
cs2 = gtk_label_new ("color selector goes here");
cs1 = gnome_color_picker_new ();
cs2 = gnome_color_picker_new ();
/* Create the pattern preview */
p = create_pattern_preview (prop_win);
p = pattern_selector_new (0);
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r3, 0, 1, 2, 3, e, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), r1, 0, 1, 0, 1, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r2, 0, 1, 1, 2, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), r3, 0, 1, 2, 3, e, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs1, 1, 2, 1, 2, 0, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), cs2, 1, 2, 2, 3, 0, 0, 0, 0);
gtk_table_attach (GTK_TABLE (table), cs1, 1, 2, 1, 2, 0, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), cs2, 1, 2, 2, 3, 0, 0, 4, 2);
gtk_table_attach (GTK_TABLE (table), p, 0, 2, 3, 4, GTK_FILL | GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
return frame;
}
......
/*
* pattern-selector.c: A widget that displays the Gnumeric patterns.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "gnumeric-sheet.h"
#include "pattern-selector.h"
#define PIXS_PER_SQUARE 30
#define BORDER 4
static GnomeCanvasClass *parent_class;
void
pattern_selector_select (PatternSelector *ps, int pattern)
{
int x, y;
g_return_if_fail (ps != NULL);
g_return_if_fail (IS_PATTERN_SELECTOR (ps));
g_return_if_fail (pattern >= 0 && pattern < GNUMERIC_SHEET_PATTERNS);
x = pattern % 7;
y = pattern / 7;
if (ps->selector == NULL){
ps->selector = gnome_canvas_item_new (
GNOME_CANVAS_GROUP (GNOME_CANVAS (ps)->root),
gnome_canvas_rect_get_type (),
"x1", 0.0, "y1", 0.0, "x2", 0.0, "y2", 0.0,
"outline_color", "black",
"width_pixels", 3,
NULL);
}
ps->selected_item = pattern;
gnome_canvas_item_set (
ps->selector,
"x1", (double) x * PIXS_PER_SQUARE + BORDER,
"y1", (double) y * PIXS_PER_SQUARE + BORDER,
"x2", (double) (x+1) * PIXS_PER_SQUARE - BORDER,
"y2", (double) (y+1) * PIXS_PER_SQUARE - BORDER,
NULL);
}
GtkWidget *
pattern_selector_new (int initial_pattern)
{
PatternSelector *ps;
GnomeCanvas *canvas;
ps = gtk_type_new (pattern_selector_get_type ());
canvas = GNOME_CANVAS (ps);
gnome_canvas_set_size (canvas, 7*PIXS_PER_SQUARE, 2*PIXS_PER_SQUARE);
gnome_canvas_set_scroll_region (canvas, 0, 0, 7*PIXS_PER_SQUARE, 2*PIXS_PER_SQUARE);
gnome_canvas_set_pixels_per_unit (canvas, 1.0);
pattern_selector_select (ps, initial_pattern);
return GTK_WIDGET (ps);
}
static int
click_on_pattern (GnomeCanvasItem *item, GdkEvent *event, void *num)
{
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
{
int pattern = GPOINTER_TO_INT (num);
PatternSelector *ps = PATTERN_SELECTOR (item->canvas);
pattern_selector_select (ps, pattern);
}
return TRUE;
}
static void
pattern_selector_realize (GtkWidget *widget)
{
PatternSelector *ps = PATTERN_SELECTOR (widget);
GdkWindow *window;
GnomeCanvasGroup *group;
int i;
if (GTK_WIDGET_CLASS (parent_class)->realize)
(*GTK_WIDGET_CLASS (parent_class)->realize)(widget);
window = widget->window;
group = GNOME_CANVAS_GROUP (gnome_canvas_root (GNOME_CANVAS (widget)));
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++){
GnomeCanvasRE *item;
int x, y;
x = i % 7;
y = i / 7;
item = GNOME_CANVAS_RE (gnome_canvas_item_new (
group,
gnome_canvas_rect_get_type (),
"x1", (double) x * PIXS_PER_SQUARE + BORDER,
"y1", (double) y * PIXS_PER_SQUARE + BORDER,
"x2", (double) (x + 1) * PIXS_PER_SQUARE - BORDER,
"y2", (double) (y + 1) * PIXS_PER_SQUARE - BORDER,
"fill_color", "black",
"width_pixels", (int) 1,
"outline_color","black",
NULL));
ps->patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
gdk_gc_set_stipple (item->fill_gc, ps->patterns [i]);
gdk_gc_set_fill (item->fill_gc, GDK_STIPPLED);
gtk_signal_connect (GTK_OBJECT (item), "event",
GTK_SIGNAL_FUNC (click_on_pattern), GINT_TO_POINTER (i));
}
}
static void
pattern_selector_unrealize (GtkWidget *widget)
{
PatternSelector *ps = PATTERN_SELECTOR (widget);
int i;
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++)
gdk_pixmap_unref (ps->patterns [i]);
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget);
}
static void
pattern_selector_class_init (PatternSelectorClass *class)
{
GtkWidgetClass *widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gnome_canvas_get_type());
widget_class->realize = pattern_selector_realize;
widget_class->unrealize = pattern_selector_unrealize;
}
static void
pattern_selector_init (PatternSelector *pattern_selector)
{
GnomeCanvas *canvas = GNOME_CANVAS (pattern_selector);
GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_DEFAULT);
}
GtkType
pattern_selector_get_type (void)
{
static GtkType pattern_selector_type = 0;
if (!pattern_selector_type){
GtkTypeInfo pattern_selector_info = {
"PatternSelector",
sizeof (PatternSelector),
sizeof (PatternSelectorClass),
(GtkClassInitFunc) pattern_selector_class_init,
(GtkObjectInitFunc) pattern_selector_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
pattern_selector_type = gtk_type_unique (gnome_canvas_get_type (), &pattern_selector_info);
}
return pattern_selector_type;
}
#ifndef PATTERN_SELECTOR_H
#define PATTERN_SELECTOR_H
#define PATTERN_SELECTOR_TYPE (pattern_selector_get_type ())
#define PATTERN_SELECTOR(obj) (GTK_CHECK_CAST((obj), PATTERN_SELECTOR_TYPE, PatternSelector))
#define PATTERN_SELECTOR_CLASS(k) (GTK_CHECK_CLASS_CAST((obj), PATTERN_SELECTOR_TYPE))
#define IS_PATTERN_SELECTOR(o) (GTK_CHECK_TYPE((o), PATTERN_SELECTOR_TYPE))
typedef struct {
GnomeCanvas canvas;
GdkPixmap *patterns [GNUMERIC_SHEET_PATTERNS];
int selected_item;
GnomeCanvasItem *selector;
} PatternSelector;
typedef struct {
GnomeCanvasClass parent_class;
} PatternSelectorClass;
GtkType pattern_selector_get_type (void);
GtkWidget *pattern_selector_new (int pattern);
void pattern_selector_select (PatternSelector *ps, int pattern);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment