Commit 3c2433f5 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

doh. doh doh. doh doh doh. doh doh doh doh.


2003-04-21  Jody Goldberg <jody@gnome.org>

	* dialog-hyperlink.c (dialog_hyperlink) : doh.
	* dialog-pivottable.c (dialog_pivottable) : doh doh.
	* dialog-summary.c (dialog_summary_update) : doh doh doh.
	* dialog-zoom.c (dialog_zoom) : doh doh doh doh.
parent 593e39e0
2003-04-21 Jody Goldberg <jody@gnome.org>
* dialog-hyperlink.c (dialog_hyperlink) : doh.
* dialog-pivottable.c (dialog_pivottable) : doh doh.
* dialog-summary.c (dialog_summary_update) : doh doh doh.
* dialog-zoom.c (dialog_zoom) : doh doh doh doh.
2003-04-21 Jukka Pekka <jiivonen@hutcs.cs.hut.fi>
* dialog-solver.c (dialog_init): Killed a run time warning.
......
......@@ -144,357 +144,6 @@ enum {
#define MINOR_PIXMAP_HEIGHT 60
#define BORDER 5
#define MINOR_KEY "minor_chart_type"
#define MAJOR_KEY "major_chart_type"
#define FIRST_MINOR_TYPE "first_minor_type"
static GdkPixbuf *
get_pixbuf (xmlNode const *node)
{
static GHashTable *cache = NULL;
xmlChar *sample_image_file;
xmlNode *sample_image_file_node;
GdkPixbuf *pixbuf;
g_return_val_if_fail (node != NULL, NULL);
if (cache != NULL) {
pixbuf = g_hash_table_lookup (cache, node);
if (pixbuf != NULL)
return pixbuf;
} else
cache = g_hash_table_new (g_direct_hash, g_direct_equal);
sample_image_file_node = e_xml_get_child_by_name (node, "sample_image_file");
g_return_val_if_fail (sample_image_file_node != NULL, NULL);
sample_image_file = xmlNodeGetContent (sample_image_file_node);
g_return_val_if_fail (sample_image_file != NULL, NULL);
pixbuf = gnumeric_load_pixbuf (sample_image_file);
xmlFree (sample_image_file);
g_hash_table_insert (cache, (gpointer)node, pixbuf);
return pixbuf;
}
static void
get_pos (int col, int row, double *x, double *y)
{
*x = (col-1) * (MINOR_PIXMAP_WIDTH + BORDER) + BORDER;
*y = (row-1) * (MINOR_PIXMAP_HEIGHT + BORDER) + BORDER;
}
/*
* graph_typeselect_minor :
*
* @typesel :
* @item : A CanvasItem in the selector.
*
* Moves the typesel::selector overlay above the @item.
* Assumes that the item is visible
*/
static void
graph_typeselect_minor (GraphGuruTypeSelector *typesel,
GnomeCanvasItem *item)
{
xmlNode *minor, *tmp;
double x1, y1, x2, y2;
char *description;
if (typesel->current_minor_item == item)
return;
minor = g_object_get_data (G_OBJECT (item), MINOR_KEY);
g_return_if_fail(minor != NULL);
/* clear the current plot */
if (typesel->sample_plot != NULL) {
gtk_object_destroy (GTK_OBJECT (typesel->sample_plot));
typesel->sample_plot = NULL;
}
tmp = e_xml_get_child_by_name_by_lang_list (
minor, "description", NULL);
description = (tmp != NULL) ? xmlNodeGetContent (tmp) : NULL;
typesel->current_minor = minor;
typesel->current_minor_item = item;
gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2);
gnome_canvas_item_set (GNOME_CANVAS_ITEM (typesel->selector),
"x1", x1-1., "y1", y1-1.,
"x2", x2+1., "y2", y2+1.,
NULL);
gtk_label_set_text (typesel->label, description);
gtk_widget_set_sensitive (typesel->sample_button, TRUE);
if (description != NULL)
xmlFree (description);
gnm_graph_plot_set_type (typesel->plot, minor);
}
static gboolean
graph_typeselect_minor_x_y (GraphGuruTypeSelector *typesel,
double x, double y)
{
GnomeCanvasItem *item = gnome_canvas_get_item_at (
GNOME_CANVAS (typesel->canvas), x, y);
if (item != NULL && item != typesel->selector) {
graph_typeselect_minor (typesel, item);
return TRUE;
}
return FALSE;
}
static void
minor_chart_type_get_pos (xmlNode const *node, int *col, int *row)
{
*col = *row = -1;
node = e_xml_get_child_by_name (node, "position");
g_return_if_fail (node != NULL);
*col = e_xml_get_integer_prop_by_name (node, "col");
*row = e_xml_get_integer_prop_by_name (node, "row");
}
static gboolean
cb_key_press_event (G_GNUC_UNUSED GtkWidget *wrapper,
GdkEventKey *event,
GraphGuruTypeSelector *typesel)
{
GtkCornerType corner;
int row, col;
double x, y;
xmlNode const *minor = g_object_get_data (
G_OBJECT (typesel->current_minor_item), MINOR_KEY);
g_return_val_if_fail (minor != NULL, FALSE);
minor_chart_type_get_pos (minor, &col, &row);
switch (event->keyval){
case GDK_KP_Left: case GDK_Left:
corner = GTK_CORNER_BOTTOM_RIGHT;
--col;
break;
case GDK_KP_Up: case GDK_Up:
corner = GTK_CORNER_BOTTOM_RIGHT;
--row;
break;
case GDK_KP_Right: case GDK_Right:
corner = GTK_CORNER_TOP_LEFT;
++col;
break;
case GDK_KP_Down: case GDK_Down:
corner = GTK_CORNER_TOP_LEFT;
++row;
break;
default:
return FALSE;
}
get_pos (col, row, &x, &y);
graph_typeselect_minor_x_y (typesel, x, y);
return TRUE;
}
static gint
cb_button_press_event (GtkWidget *widget, GdkEventButton *event,
GraphGuruTypeSelector *typesel)
{
if (event->button == 1) {
GnomeCanvas *c = GNOME_CANVAS (widget);
double x, y;
gnome_canvas_window_to_world (c, event->x, event->y, &x, &y);
graph_typeselect_minor_x_y (typesel, x, y);
}
return FALSE;
}
static void
cb_selection_changed (G_GNUC_UNUSED GtkTreeSelection *ignored,
GraphGuruTypeSelector *typesel)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection (typesel->list_view);
GtkTreeIter iter;
GnomeCanvasItem *item;
GnomeCanvasGroup *group;
if (typesel->current_major_item != NULL)
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (typesel->current_major_item));
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_tree_model_get (GTK_TREE_MODEL (typesel->model), &iter,
MAJOR_TYPE_CANVAS_GROUP, &group,
-1);
gnome_canvas_item_show (GNOME_CANVAS_ITEM (group));
typesel->current_major_item = group;
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (typesel->selector));
item = g_object_get_data (G_OBJECT (group), FIRST_MINOR_TYPE);
if (item != NULL)
graph_typeselect_minor (typesel, item);
gnome_canvas_item_show (GNOME_CANVAS_ITEM (typesel->selector));
}
static void
cb_sample_pressed (G_GNUC_UNUSED GtkWidget *button,
GraphGuruTypeSelector *typesel)
{
if (typesel->current_major_item == NULL)
return;
if (typesel->sample_plot == NULL) {
#if 0
GuppiRootGroupView *plot = gup_gnm_graph_get_view (state->graph);
g_return_if_fail (plot != NULL);
typesel->sample_plot = guppi_element_view_make_canvas_item (
GUPPI_ELEMENT_VIEW (plot),
GNOME_CANVAS (typesel->canvas),
typesel->plot_group);
guppi_root_group_item_set_resize_semantics (
GUPPI_ROOT_GROUP_ITEM (typesel->sample_plot),
ROOT_GROUP_RESIZE_FILL_SPACE);
#endif
}
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (typesel->current_major_item));
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (typesel->selector));
gnome_canvas_item_show (GNOME_CANVAS_ITEM (typesel->plot_group));
/* guppi_root_group_item_best_fit (GUPPI_ROOT_GROUP_ITEM(typesel->sample_plot)); */
}
static void
cb_sample_released (G_GNUC_UNUSED GtkWidget *button,
GraphGuruTypeSelector *typesel)
{
if (typesel->current_major_item == NULL)
return;
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (typesel->plot_group));
gnome_canvas_item_show (GNOME_CANVAS_ITEM (typesel->current_major_item));
gnome_canvas_item_show (GNOME_CANVAS_ITEM (typesel->selector));
gnome_canvas_set_scroll_region (GNOME_CANVAS (typesel->canvas), 0, 0,
MINOR_PIXMAP_WIDTH*3 + BORDER*5,
MINOR_PIXMAP_HEIGHT*3 + BORDER*5);
}
typedef struct {
GraphGuruTypeSelector *typesel;
GnomeCanvasGroup *group;
GnomeCanvasItem *current_item;
xmlNode *current_minor;
int col, row;
} minor_list_closure;
static void
minor_list_init (xmlNode *minor, minor_list_closure *closure)
{
double x1, y1, w, h;
GnomeCanvasItem *item;
int col, row;
GdkPixbuf *image = get_pixbuf (minor);
g_return_if_fail (image != NULL);
minor_chart_type_get_pos (minor, &col, &row);
get_pos (col, row, &x1, &y1);
w = gdk_pixbuf_get_width (image);
if (w > MINOR_PIXMAP_WIDTH)
w = MINOR_PIXMAP_WIDTH;
h = gdk_pixbuf_get_height (image);
if (h > MINOR_PIXMAP_HEIGHT)
h = MINOR_PIXMAP_HEIGHT;
item = gnome_canvas_item_new (closure->group,
gnome_canvas_pixbuf_get_type (),
"x", x1, "y", y1,
"width", w, "height", h,
"pixbuf", image,
NULL);
g_object_set_data (G_OBJECT (item), MINOR_KEY, (gpointer)minor);
if (closure->current_minor == NULL ||
closure->row > row ||
(closure->row == row && closure->col > col)) {
closure->current_minor = minor;
closure->current_item = item;
closure->col = col;
closure->row = row;
}
}
static void
major_list_init (GraphGuruTypeSelector *typesel, xmlNode *major)
{
xmlChar *name;
xmlNode *node;
GnomeCanvasGroup *group;
GtkTreeIter iter;
minor_list_closure closure;
/* be really anal when parsing a user editable file */
node = e_xml_get_child_by_name_by_lang_list (major, "name", NULL);
g_return_if_fail (node != NULL);
name = xmlNodeGetContent (node);
g_return_if_fail (name != NULL);
/* Define a canvas group for all the minor types */
group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (
gnome_canvas_root (GNOME_CANVAS (typesel->canvas)),
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL));
gnome_canvas_item_hide (GNOME_CANVAS_ITEM (group));
g_object_set_data (G_OBJECT (group), MAJOR_KEY, (gpointer)major);
gtk_list_store_append (typesel->model, &iter);
gtk_list_store_set (typesel->model, &iter,
MAJOR_TYPE_IMAGE, get_pixbuf (major),
MAJOR_TYPE_NAME, name,
MAJOR_TYPE_CANVAS_GROUP, group,
-1);
xmlFree (name);
closure.typesel = typesel;
closure.group = group;
closure.current_minor = NULL;
/* Init the list and the canvas group for each major type */
for (node = major->xmlChildrenNode; node != NULL; node = node->next)
if (!strcmp (node->name, "Minor"))
minor_list_init (node, &closure);
g_object_set_data (G_OBJECT (group), FIRST_MINOR_TYPE,
closure.current_item);
}
static void
cb_canvas_realized (G_GNUC_UNUSED GtkWidget *widget,
G_GNUC_UNUSED gpointer data)
{
/*gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE); */
}
static void graph_guru_select_plot (GraphGuruState *s, xmlNode *plot, int seriesID);
static void
......@@ -1405,159 +1054,6 @@ cb_graph_guru_series_delete (G_GNUC_UNUSED GtkWidget *button,
}
}
static GtkWidget *
graph_guru_type_selector_new (void)
{
static xmlDoc *doc;
xmlNode *major;
GtkTreeSelection *selection;
GraphGuruTypeSelector *typesel;
GtkWidget *tmp, *vbox, *hbox;
guint32 select_color;
typesel = g_new0 (GraphGuruTypeSelector, 1);
typesel->current_major_item = NULL;
typesel->current_minor_item = NULL;
typesel->current_minor = NULL;
typesel->sample_plot = NULL;
hbox = gtk_hbox_new (FALSE, 5);
/* List of major types */
typesel->model = gtk_list_store_new (NUM_COLUMNS,
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
G_TYPE_POINTER);
typesel->list_view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (
GTK_TREE_MODEL (typesel->model)));
gtk_tree_view_append_column (typesel->list_view,
gtk_tree_view_column_new_with_attributes ("",
gtk_cell_renderer_pixbuf_new (),
"pixbuf", MAJOR_TYPE_IMAGE,
NULL));
gtk_tree_view_append_column (typesel->list_view,
gtk_tree_view_column_new_with_attributes (_("Plot Type"),
gtk_cell_renderer_text_new (),
"text", MAJOR_TYPE_NAME,
NULL));
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (typesel->list_view),
TRUE, TRUE, 0);
selection = gtk_tree_view_get_selection (typesel->list_view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (selection,
"changed",
G_CALLBACK (cb_selection_changed), typesel);
/* Setup an aa canvas to display the sample image & the sample plot. */
typesel->canvas = gnome_canvas_new_aa ();
g_signal_connect (G_OBJECT (typesel->canvas),
"realize",
G_CALLBACK (cb_canvas_realized), typesel);
typesel->plot_group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (
gnome_canvas_root (GNOME_CANVAS (typesel->canvas)),
gnome_canvas_group_get_type (),
"x", 0.0,
"y", 0.0,
NULL));
/*guppi_plot_canvas_set_insensitive (GUPPI_PLOT_CANVAS (typesel->canvas)); */
gtk_widget_set_usize (typesel->canvas,
MINOR_PIXMAP_WIDTH*3 + BORDER*5,
MINOR_PIXMAP_HEIGHT*3 + BORDER*5);
gnome_canvas_set_scroll_region (GNOME_CANVAS (typesel->canvas), 0, 0,
MINOR_PIXMAP_WIDTH*3 + BORDER*5,
MINOR_PIXMAP_HEIGHT*3 + BORDER*5);
g_signal_connect_after (G_OBJECT (typesel->canvas),
"key_press_event",
G_CALLBACK (cb_key_press_event), typesel);
g_signal_connect (GTK_OBJECT (typesel->canvas),
"button_press_event",
G_CALLBACK (cb_button_press_event), typesel);
tmp = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (tmp), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (tmp), typesel->canvas);
gtk_box_pack_start (GTK_BOX (hbox), tmp, FALSE, TRUE, 0);
if (doc == NULL) {
char *plots_path = g_build_filename (
gnumeric_sys_data_dir (NULL), "plot-types.xml", NULL);
doc = xmlParseFile (plots_path);
g_free (plots_path);
}
g_return_val_if_fail (doc != NULL, NULL);
/* Init the list and the canvas group for each major type */
major = e_xml_get_child_by_name (doc->xmlRootNode, "MajorMinor");
for (major = major->xmlChildrenNode; major != NULL; major = major->next)
if (!strcmp (major->name, "Major"))
major_list_init (typesel, major);
#if 1
/* hard code for now until I figure out where to get a decent colour */
select_color = 0xe090f840;
#else
{
GdkColor *color = typesel->canvas->style->base + GTK_STATE_SELECTED;
select_color |= ((color->red >> 8) & 0xff) << 24;
select_color |= ((color->green >> 8) & 0xff) << 16;
select_color |= ((color->blue >> 8) & 0xff) << 8;
select_color = 0x40; /* alpha of 25% */
}
#endif
/* The alpha blended selection box */
typesel->selector = gnome_canvas_item_new (
gnome_canvas_root (GNOME_CANVAS (typesel->canvas)),
gnome_canvas_rect_get_type (),
"fill_color_rgba", select_color,
"outline_color_rgba", 0x000000ff, /* black */
"width_pixels", 1,
NULL);
/* Setup the description label */
typesel->label = GTK_LABEL (gtk_label_new (""));
gtk_label_set_justify (typesel->label, GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (typesel->label, TRUE);
gtk_misc_set_alignment (GTK_MISC (typesel->label), 0., .2);
gtk_misc_set_padding (GTK_MISC (typesel->label), 5, 5);
/* ICK ! How can I set the number of lines without looking at fonts */
gtk_widget_set_usize (GTK_WIDGET (typesel->label), 350, 65);
vbox = gtk_vbox_new (FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
hbox = gtk_hbox_new (FALSE, 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
/* Set up sample button */
typesel->sample_button = gtk_button_new_with_label (_("Show\nSample"));
gtk_widget_set_sensitive (typesel->sample_button, FALSE);
g_signal_connect (G_OBJECT (typesel->sample_button),
"pressed",
G_CALLBACK (cb_sample_pressed), typesel);
g_signal_connect (G_OBJECT (typesel->sample_button), "released",
G_CALLBACK (cb_sample_released), typesel);
tmp = gtk_frame_new (_("Description"));
gtk_container_add (GTK_CONTAINER (tmp), GTK_WIDGET (typesel->label));
gtk_box_pack_start (GTK_BOX (hbox), tmp, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), typesel->sample_button, FALSE, TRUE, 0);
typesel->notebook = gtk_notebook_new ();
gtk_notebook_append_page (GTK_NOTEBOOK (typesel->notebook),
vbox, gtk_label_new (_("Basic Types")));
return typesel->notebook;
}
static gboolean
graph_guru_init (GraphGuruState *s)
{
......@@ -1694,7 +1190,7 @@ dialog_graph_guru (WorkbookControlGUI *wbcg, GnmGraph *graph, int page)
state->initial_page = page;
if (page == 0) {
GtkWidget *w = graph_guru_type_selector_new ();
GtkWidget *w = NULL; /* typeselector */
gtk_notebook_prepend_page (state->steps, w, NULL);
gtk_widget_show_all (w);
}
......
......@@ -422,7 +422,7 @@ dialog_hyperlink (WorkbookControlGUI *wbcg, SheetControl *sc)
gui = gnm_glade_xml_new (COMMAND_CONTEXT (wbcg),
"hyperlink.glade", NULL, NULL);
if (state->gui == NULL)
if (gui == NULL)
return;
/* make sure that all hlink types are registered */
......
......@@ -85,7 +85,7 @@ dialog_pivottable (WorkbookControlGUI *wbcg)
gui = gnm_glade_xml_new (COMMAND_CONTEXT (wbcg),
"pivottable.glade", NULL, NULL);
if (state->gui == NULL)
if (gui == NULL)
return;
state = g_new (PivotTableGuru, 1);
......
......@@ -221,7 +221,7 @@ dialog_summary_update (WorkbookControlGUI *wbcg, gboolean open_dialog)
if (gui == NULL)
return;
dialog = glade_xml_get_widget (state->gui, "SummaryInformation");
dialog = glade_xml_get_widget (gui, "SummaryInformation");
g_return_if_fail (dialog != NULL);
state = g_new (SummaryState, 1);
......
......@@ -149,7 +149,7 @@ dialog_zoom (WorkbookControlGUI *wbcg, Sheet *sheet)
return;
gui = gnm_glade_xml_new (COMMAND_CONTEXT (wbcg),
"dialog-zoom.glade", NULL, NULL);
if (state->gui == NULL)
if (gui == NULL)
return;
state = g_new (ZoomState, 1);
......
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