Commit 6a8e6e4d authored by Jody Goldberg's avatar Jody Goldberg

More background work for the new cell format dialog.

- Add some utilities to make the dash styles available.
- Add a new canvas item to use them.
parent e21cbc0c
No preview for this file type
No preview for this file type
......@@ -130,35 +130,61 @@ border_fetch (StyleBorderType const line_type,
return border;
}
gint
border_get_width (StyleBorderType const line_type)
{
g_return_val_if_fail (line_type >= BORDER_NONE, 0);
g_return_val_if_fail (line_type < BORDER_MAX, 0);
/* The caller should handle NONE */
if (line_type == BORDER_NONE)
return 0;
return style_border_data[line_type-1].width;
}
void
border_set_gc_dash (GdkGC *gc, StyleBorderType const line_type)
{
GdkLineStyle style = GDK_LINE_SOLID;
int i;
g_return_if_fail (gc != NULL);
g_return_if_fail (line_type >= BORDER_NONE);
g_return_if_fail (line_type < BORDER_MAX);
/* The caller should handle NONE */
if (line_type == BORDER_NONE)
return;
i = line_type - 1;
if (style_border_data[i].pattern != NULL)
style = GDK_LINE_DOUBLE_DASH;
gdk_gc_set_line_attributes (gc,
style_border_data[i].width,
style,
GDK_CAP_ROUND, GDK_JOIN_MITER);
if (style_border_data[i].pattern != NULL) {
struct LineDotPattern const * const pat =
style_border_data[i].pattern;
gdk_gc_set_dashes (gc, style_border_data[i].offset,
pat->pattern, pat->elements);
}
/* The background should never be drawn */
gdk_gc_set_background (gc, &gs_white);
}
GdkGC *
border_get_gc (MStyleBorder * border, GdkWindow * window)
border_get_gc (MStyleBorder *border, GdkWindow *window)
{
g_return_val_if_fail (border != NULL, NULL);
if (border->gc == NULL) {
GdkLineStyle style = GDK_LINE_SOLID;
int i = border->line_type - 1;
g_return_val_if_fail (border->line_type > BORDER_NONE, NULL);
g_return_val_if_fail (border->line_type < BORDER_MAX, NULL);
border->gc = gdk_gc_new (window);
if (style_border_data[i].pattern != NULL)
style = GDK_LINE_DOUBLE_DASH;
gdk_gc_set_line_attributes (border->gc,
style_border_data[i].width,
style,
GDK_CAP_ROUND, GDK_JOIN_MITER);
if (style_border_data[i].pattern != NULL) {
struct LineDotPattern const * const pat =
style_border_data[i].pattern;
gdk_gc_set_dashes (border->gc, style_border_data[i].offset,
pat->pattern, pat->elements);
}
/* The background should never be drawn */
gdk_gc_set_background (border->gc, &gs_white);
border_set_gc_dash (border->gc, border->line_type);
gdk_gc_set_foreground (border->gc, &border->color->color);
}
......
......@@ -35,10 +35,12 @@ struct _MStyleBorder {
void border_unref (MStyleBorder *border);
MStyleBorder *border_ref (MStyleBorder *border);
MStyleBorder *border_fetch (StyleBorderType const line_type,
StyleColor *color,
StyleColor *color,
MStyleElementType const orientation);
GdkGC * border_get_gc (MStyleBorder *border, GdkWindow *window);
gint border_get_width (StyleBorderType const line_type);
void border_set_gc_dash (GdkGC *gc, StyleBorderType const line_type);
GdkGC *border_get_gc (MStyleBorder *border, GdkWindow *window);
void border_draw (GdkDrawable * drawable, const MStyleBorder *border,
int x1, int y1, int x2, int y2);
......
......@@ -130,35 +130,61 @@ border_fetch (StyleBorderType const line_type,
return border;
}
gint
border_get_width (StyleBorderType const line_type)
{
g_return_val_if_fail (line_type >= BORDER_NONE, 0);
g_return_val_if_fail (line_type < BORDER_MAX, 0);
/* The caller should handle NONE */
if (line_type == BORDER_NONE)
return 0;
return style_border_data[line_type-1].width;
}
void
border_set_gc_dash (GdkGC *gc, StyleBorderType const line_type)
{
GdkLineStyle style = GDK_LINE_SOLID;
int i;
g_return_if_fail (gc != NULL);
g_return_if_fail (line_type >= BORDER_NONE);
g_return_if_fail (line_type < BORDER_MAX);
/* The caller should handle NONE */
if (line_type == BORDER_NONE)
return;
i = line_type - 1;
if (style_border_data[i].pattern != NULL)
style = GDK_LINE_DOUBLE_DASH;
gdk_gc_set_line_attributes (gc,
style_border_data[i].width,
style,
GDK_CAP_ROUND, GDK_JOIN_MITER);
if (style_border_data[i].pattern != NULL) {
struct LineDotPattern const * const pat =
style_border_data[i].pattern;
gdk_gc_set_dashes (gc, style_border_data[i].offset,
pat->pattern, pat->elements);
}
/* The background should never be drawn */
gdk_gc_set_background (gc, &gs_white);
}
GdkGC *
border_get_gc (MStyleBorder * border, GdkWindow * window)
border_get_gc (MStyleBorder *border, GdkWindow *window)
{
g_return_val_if_fail (border != NULL, NULL);
if (border->gc == NULL) {
GdkLineStyle style = GDK_LINE_SOLID;
int i = border->line_type - 1;
g_return_val_if_fail (border->line_type > BORDER_NONE, NULL);
g_return_val_if_fail (border->line_type < BORDER_MAX, NULL);
border->gc = gdk_gc_new (window);
if (style_border_data[i].pattern != NULL)
style = GDK_LINE_DOUBLE_DASH;
gdk_gc_set_line_attributes (border->gc,
style_border_data[i].width,
style,
GDK_CAP_ROUND, GDK_JOIN_MITER);
if (style_border_data[i].pattern != NULL) {
struct LineDotPattern const * const pat =
style_border_data[i].pattern;
gdk_gc_set_dashes (border->gc, style_border_data[i].offset,
pat->pattern, pat->elements);
}
/* The background should never be drawn */
gdk_gc_set_background (border->gc, &gs_white);
border_set_gc_dash (border->gc, border->line_type);
gdk_gc_set_foreground (border->gc, &border->color->color);
}
......
......@@ -35,10 +35,12 @@ struct _MStyleBorder {
void border_unref (MStyleBorder *border);
MStyleBorder *border_ref (MStyleBorder *border);
MStyleBorder *border_fetch (StyleBorderType const line_type,
StyleColor *color,
StyleColor *color,
MStyleElementType const orientation);
GdkGC * border_get_gc (MStyleBorder *border, GdkWindow *window);
gint border_get_width (StyleBorderType const line_type);
void border_set_gc_dash (GdkGC *gc, StyleBorderType const line_type);
GdkGC *border_get_gc (MStyleBorder *border, GdkWindow *window);
void border_draw (GdkDrawable * drawable, const MStyleBorder *border,
int x1, int y1, int x2, int y2);
......
......@@ -22,5 +22,6 @@ libwidgets_a_SOURCES = \
widget-editable-label.c \
widget-editable-label.h \
widget-font-selector.c \
widget-font-selector.h
widget-font-selector.h \
gnumeric-dashed-canvas-line.c \
gnumeric-dashed-canvas-line.h
#include <config.h>
#include "gnumeric-dashed-canvas-line.h"
/*
* A utility class to provide advanced dashed line support to the gnome-canvas-line.
* We need not just the predefined dash styles, we need to be able to set the styles directly.
*/
static void gnumeric_dashed_canvas_line_class_init (GnumericDashedCanvasLineClass *klass);
static void gnumeric_dashed_canvas_line_init (GnumericDashedCanvasLine *line);
static void gnumeric_dashed_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height);
static GnumericDashedCanvasLineClass *gnumeric_dashed_canvas_line_class;
static GnomeCanvasLineClass *parent_class;
GtkType
gnumeric_dashed_canvas_line_get_type (void)
{
static GtkType line_type = 0;
if (!line_type) {
GtkTypeInfo line_info = {
"GnumericDashedCanvasLine",
sizeof (GnumericDashedCanvasLine),
sizeof (GnumericDashedCanvasLineClass),
(GtkClassInitFunc) gnumeric_dashed_canvas_line_class_init,
(GtkObjectInitFunc) gnumeric_dashed_canvas_line_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
line_type = gtk_type_unique (gnome_canvas_line_get_type (), &line_info);
}
return line_type;
}
static void
gnumeric_dashed_canvas_line_class_init (GnumericDashedCanvasLineClass *klass)
{
gnumeric_dashed_canvas_line_class = klass;
parent_class = gtk_type_class (gnome_canvas_line_get_type ());
klass->real_draw = parent_class->parent_class.draw;
parent_class->parent_class.draw = &gnumeric_dashed_canvas_line_draw;
}
static void
gnumeric_dashed_canvas_line_init (GnumericDashedCanvasLine *line)
{
line->dash_style_index = BORDER_THIN;
}
static void
gnumeric_dashed_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
gnumeric_dashed_canvas_line_class->
real_draw (item, drawable, x, y, width, height);
}
void
gnumeric_dashed_canvas_line_set_dash_index (GnumericDashedCanvasLine *line,
StyleBorderType const indx,
guint const rgba)
{
#if 0
/* FIXME FIXME FIXME setting the width seems to negate any
* attempts to set the dash.
*/
gint const width = border_get_width (indx);
gnome_canvas_item_set (GNOME_CANVAS_ITEM (line),
"width_pixels", width,
NULL);
#endif
line->dash_style_index = indx;
border_set_gc_dash (line->line.gc, indx);
/* HACK HACK HACK
* FIXME FIXME FIXME
* Force a redraw by setting the colour
* How should this be done correctly ? */
gnome_canvas_item_set (GNOME_CANVAS_ITEM (line),
"fill_color_rgba", rgba,
NULL);
}
#ifndef GNUMERIC_DASHED_CANVAS_LINE_H
#define GNUMERIC_DASHED_CANVAS_LINE_H
/* dashed Line item for the canvas */
#include <gnome.h>
#include "border.h"
#define GNUMERIC_TYPE_DASHED_CANVAS_LINE\
(gnumeric_dashed_canvas_line_get_type ())
#define GNUMERIC_DASHED_CANVAS_LINE(obj)\
(GTK_CHECK_CAST ((obj), GNUMERIC_TYPE_DASHED_CANVAS_LINE, GnumericDashedCanvasLine))
#define GNUMERIC_DASHED_CANVAS_LINE_CLASS(klass)\
(GTK_CHECK_CLASS_CAST ((klass), GNUMERIC_TYPE_DASHED_CANVAS_LINE, GnumericDashedCanvasLineClass))
#define GNUMERIC_IS_DASHED_CANVAS_LINE(obj)\
(GTK_CHECK_TYPE ((obj), GNUMERIC_TYPE_DASHED_CANVAS_LINE))
#define GNUMERIC_IS_DASHED_CANVAS_LINE_CLASS(klass)\
(GTK_CHECK_CLASS_TYPE ((klass), GNUMERIC_TYPE_DASHED_CANVAS_LINE))
typedef struct _GnumericDashedCanvasLine GnumericDashedCanvasLine;
typedef struct _GnumericDashedCanvasLineClass GnumericDashedCanvasLineClass;
struct _GnumericDashedCanvasLine {
GnomeCanvasLine line;
/* Public : */
StyleBorderType dash_style_index;
};
struct _GnumericDashedCanvasLineClass {
GnomeCanvasLineClass parent_class;
void (*real_draw)(GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height);
};
void gnumeric_dashed_canvas_line_set_dash_index (GnumericDashedCanvasLine *line,
StyleBorderType const indx,
guint const rgba);
/* Standard Gtk function */
GtkType gnumeric_dashed_canvas_line_get_type (void);
#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