Commit 5d9fa2dc authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

support showing the color of colored tabs

2002-03-14  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* dialog-sheet-order.c : support showing the color
	  of colored tabs

2002-03-14  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* gnumeric-cell-renderer-text.[ch] : new renderer to make
	  sure not to obscure colored backgrounds on selection
	* Makefile.am : added gnumeric-cell-renderer-text.[ch]
parent 72db56eb
2002-03-14 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-sheet-order.c : support showing the color
of colored tabs
2002-03-14 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* dialog-solver.c (cb_dialog_solve_clicked): If the problem is
......
......@@ -5,7 +5,25 @@
*
* Author:
* Jody Goldberg <jody@gnome.org>
* Andreas J. Guelzow <aguelzow@taliesin.ca>
*
* (C) Copyright 2000, 2001, 2002 Jody Goldberg <jody@gnome.org>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include "dialogs.h"
......@@ -16,7 +34,9 @@
#include <workbook-view.h>
#include <workbook.h>
#include <sheet.h>
#include <style-color.h>
#include <commands.h>
#include <widgets/gnumeric-cell-renderer-text.h>
#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>
......@@ -47,6 +67,8 @@ enum {
SHEET_POINTER,
IS_EDITABLE_COLUMN,
IS_DELETED,
BACKGROUND_COLOUR_POINTER,
FOREGROUND_COLOUR_POINTER,
NUM_COLMNS
};
......@@ -149,8 +171,15 @@ populate_sheet_list (SheetManager *state)
int i, n = workbook_sheet_count (wb_control_workbook (WORKBOOK_CONTROL (state->wbcg)));
GtkCellRenderer *renderer;
state->model = gtk_list_store_new (NUM_COLMNS, GDK_TYPE_PIXBUF,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
state->model = gtk_list_store_new (NUM_COLMNS,
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_POINTER,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN,
GDK_TYPE_COLOR,
GDK_TYPE_COLOR);
state->sheet_list = GTK_TREE_VIEW (gtk_tree_view_new_with_model
(GTK_TREE_MODEL (state->model)));
selection = gtk_tree_view_get_selection (state->sheet_list);
......@@ -158,6 +187,15 @@ populate_sheet_list (SheetManager *state)
for (i = 0 ; i < n ; i++) {
Sheet *sheet = workbook_sheet_by_index (
wb_control_workbook (WORKBOOK_CONTROL (state->wbcg)), i);
GdkColor *color = &sheet->tab_color->color;
int contrast;
GdkColor text_color;
if (color == NULL)
color = &gs_white;
contrast = color->red + color->green + color->blue;
text_color = (contrast >= 0x18000) ? gs_black : gs_white;
gtk_list_store_append (state->model, &iter);
gtk_list_store_set (state->model, &iter,
SHEET_PIX, state->sheet_image,
......@@ -166,6 +204,8 @@ populate_sheet_list (SheetManager *state)
SHEET_POINTER, sheet,
IS_EDITABLE_COLUMN, TRUE,
IS_DELETED, FALSE,
BACKGROUND_COLOUR_POINTER, color,
FOREGROUND_COLOUR_POINTER, &text_color,
-1);
if (sheet == cur_sheet)
gtk_tree_selection_select_iter (selection, &iter);
......@@ -181,19 +221,23 @@ populate_sheet_list (SheetManager *state)
gtk_tree_view_append_column (state->sheet_list, column);
column = gtk_tree_view_column_new_with_attributes (_("Current Name"),
gtk_cell_renderer_text_new (),
"text", SHEET_NAME,
"strikethrough", IS_DELETED,
NULL);
gnumeric_cell_renderer_text_new (),
"text", SHEET_NAME,
"strikethrough", IS_DELETED,
"background_gdk",BACKGROUND_COLOUR_POINTER,
"foreground_gdk",FOREGROUND_COLOUR_POINTER,
NULL);
gtk_tree_view_append_column (state->sheet_list, column);
renderer = gtk_cell_renderer_text_new ();
renderer = gnumeric_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("New Name"),
renderer,
"text", SHEET_NEW_NAME,
"editable", IS_EDITABLE_COLUMN,
"strikethrough", IS_DELETED,
NULL);
renderer,
"text", SHEET_NEW_NAME,
"editable", IS_EDITABLE_COLUMN,
"strikethrough", IS_DELETED,
"background_gdk",BACKGROUND_COLOUR_POINTER,
"foreground_gdk",FOREGROUND_COLOUR_POINTER,
NULL);
gtk_tree_view_append_column (state->sheet_list, column);
g_signal_connect (G_OBJECT (renderer), "edited",
G_CALLBACK (cb_name_edited), state);
......@@ -218,6 +262,7 @@ cb_item_move (SheetManager *state, gint direction)
gint row;
gboolean is_deleted;
gboolean is_editable;
GdkColor *back, *front;
GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list);
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
......@@ -229,6 +274,8 @@ cb_item_move (SheetManager *state, gint direction)
IS_EDITABLE_COLUMN, &is_editable,
SHEET_POINTER, &sheet,
IS_DELETED, &is_deleted,
BACKGROUND_COLOUR_POINTER, &back,
FOREGROUND_COLOUR_POINTER, &front,
-1);
row = location_of_iter (&iter, state->model);
if (row + direction < 0)
......@@ -242,6 +289,8 @@ cb_item_move (SheetManager *state, gint direction)
IS_EDITABLE_COLUMN, is_editable,
SHEET_POINTER, sheet,
IS_DELETED, is_deleted,
BACKGROUND_COLOUR_POINTER, back,
FOREGROUND_COLOUR_POINTER, front,
-1);
g_free (name);
g_free (new_name);
......@@ -299,6 +348,8 @@ cb_add_clicked (GtkWidget *ignore, SheetManager *state)
SHEET_POINTER, NULL,
IS_EDITABLE_COLUMN, TRUE,
IS_DELETED, FALSE,
BACKGROUND_COLOUR_POINTER, &gs_white,
FOREGROUND_COLOUR_POINTER, &gs_black,
-1);
gtk_tree_selection_select_iter (selection, &iter);
g_free (name);
......
......@@ -882,7 +882,7 @@ sheet_object_clone (SheetObject const *so, Sheet *sheet)
*
**/
void
sheet_object_clone_sheet (const Sheet *src, Sheet *dst, Range *range)
sheet_object_clone_sheet (Sheet const *src, Sheet *dst, Range *range)
{
SheetObject *so;
SheetObject *new_so;
......
2002-03-14 Andreas J. Guelzow <aguelzow@taliesin.ca>
* gnumeric-cell-renderer-text.[ch] : new renderer to make
sure not to obscure colored backgrounds on selection
* Makefile.am : added gnumeric-cell-renderer-text.[ch]
2002-03-12 Jody Goldberg <jody@gnome.org>
* widget-editable-label.c : rewrite.
......
......@@ -14,6 +14,8 @@ libwidgets_a_SOURCES = \
widget-font-selector.h \
gnumeric-cell-renderer.c \
gnumeric-cell-renderer.h \
gnumeric-cell-renderer-text.c \
gnumeric-cell-renderer-text.h \
gnumeric-dashed-canvas-line.c \
gnumeric-dashed-canvas-line.h \
gnumeric-expr-entry.c \
......
/* gnumeric-cell-renderer-text.c
* Copyright (C) 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include "gnumeric-cell-renderer-text.h"
static void gnumeric_cell_renderer_text_class_init
(GnumericCellRendererTextClass *cell_text_class);
static void gnumeric_cell_renderer_text_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags);
static GtkCellRendererTextClass *parent_class = NULL;
GType
gnumeric_cell_renderer_text_get_type (void)
{
static GType cell_text_type = 0;
if (!cell_text_type)
{
static const GTypeInfo cell_text_info =
{
sizeof (GnumericCellRendererTextClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc)gnumeric_cell_renderer_text_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkCellRendererText),
0, /* n_preallocs */
(GInstanceInitFunc) NULL,
};
cell_text_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "GnumericCellRendererText", &cell_text_info, 0);
}
return cell_text_type;
}
static void
gnumeric_cell_renderer_text_class_init (GnumericCellRendererTextClass *class)
{
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (object_class);
cell_class->render = gnumeric_cell_renderer_text_render;
}
GtkCellRenderer *
gnumeric_cell_renderer_text_new (void)
{
return GTK_CELL_RENDERER (g_object_new (GNUMERIC_TYPE_CELL_RENDERER_TEXT, NULL));
}
static void
gnumeric_cell_renderer_text_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags)
{
GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
GtkStateType state;
if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (GTK_WIDGET_HAS_FOCUS (widget))
state = GTK_STATE_SELECTED;
else
state = GTK_STATE_ACTIVE;
}
else
{
if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
state = GTK_STATE_INSENSITIVE;
else
state = GTK_STATE_NORMAL;
}
if ( state == GTK_STATE_SELECTED && celltext->background_set)
{
GdkColor color;
GdkGC *gc;
color.red = celltext->background.red;
color.green = celltext->background.green;
color.blue = celltext->background.blue;
gc = gdk_gc_new (window);
gdk_gc_set_rgb_fg_color (gc, &color);
gdk_draw_rectangle (window,
gc,
TRUE,
background_area->x,
background_area->y + cell->ypad,
background_area->width,
background_area->height - 2 * cell->ypad);
g_object_unref (G_OBJECT (gc));
}
GTK_CELL_RENDERER_CLASS (parent_class)->render (cell, window, widget, background_area,
cell_area, expose_area, flags);
}
/* gnumeric-cell-renderer-text.h
* Copyright (C) 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GNUMERIC_CELL_RENDERER_TEXT_H__
#define __GNUMERIC_CELL_RENDERER_TEXT_H__
#include <gtk/gtkcellrenderertext.h>
G_BEGIN_DECLS
#define GNUMERIC_TYPE_CELL_RENDERER_TEXT (gnumeric_cell_renderer_text_get_type ())
#define GNUMERIC_CELL_RENDERER_TEXT(obj) (GTK_CHECK_CAST ((obj), GNUMERIC_TYPE_CELL_RENDERER_TEXT, GnumericCellRendererText))
#define GNUMERIC_CELL_RENDERER_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNUMERIC_TYPE_CELL_RENDERER_TEXT, GnumericCellRendererTextClass))
#define GNUMERIC_IS_CELL_RENDERER_TEXT(obj) (GTK_CHECK_TYPE ((obj), GNUMERIC_TYPE_CELL_RENDERER_TEXT))
#define GNUMERIC_IS_CELL_RENDERER_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNUMERIC_TYPE_CELL_RENDERER_TEXT))
#define GNUMERIC_CELL_RENDERER_TEXT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GNUMERIC_TYPE_CELL_RENDERER_TEXT, GnumericCellRendererTextClass))
typedef struct _GnumericCellRendererText GnumericCellRendererText;
typedef struct _GnumericCellRendererTextClass GnumericCellRendererTextClass;
struct _GnumericCellRendererText
{
GtkCellRendererText parent;
};
struct _GnumericCellRendererTextClass
{
GtkCellRendererTextClass parent_class;
};
GType gnumeric_cell_renderer_text_get_type (void);
GtkCellRenderer *gnumeric_cell_renderer_text_new (void);
G_END_DECLS
#endif /* __GTK_CELL_RENDERER_TEXT_H__ */
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