Revert, revert, try another thing
[gnumeric.git] / wizards / graphics / graphic-type.c
blob29f3976febfa36c73a0752c57211a99fd55504eb
1 /*
2 * Gnumeric, the GNOME spreadsheet.
4 * Graphics Wizard bootstap file
6 * Author:
7 * Miguel de Icaza (miguel@gnu.org)
8 */
9 #include <config.h>
10 #include <gnome.h>
11 #include "gnumeric.h"
12 #include <glade/glade.h>
13 #include "idl/Graph.h"
14 #include "wizard.h"
15 #include "graphic-type.h"
17 typedef struct {
18 char *description;
19 int col, row;
20 PlotParameters par;
21 } subtype_info_t;
23 static subtype_info_t column_subtypes [] = {
25 N_("Clustered columns. Compares values between categories"),
26 1, 1,
28 TRUE,
29 GNOME_Graph_CHART_TYPE_CLUSTERED,
30 GNOME_Graph_PLOT_COLBAR,
31 GNOME_Graph_COLBAR_FLAT,
32 GNOME_Graph_DIR_COL
37 N_("Stacked columns. Compares the values brought by each category"),
38 1, 2,
40 TRUE,
41 GNOME_Graph_CHART_TYPE_STACKED,
42 GNOME_Graph_PLOT_COLBAR,
43 GNOME_Graph_COLBAR_FLAT,
44 GNOME_Graph_DIR_COL
50 N_("Stacked columns, 100%. Compares between the categories the values broght to a total"),
51 1, 3,
53 TRUE,
54 GNOME_Graph_CHART_TYPE_STACKED_FULL,
55 GNOME_Graph_PLOT_COLBAR,
56 GNOME_Graph_COLBAR_FLAT,
57 GNOME_Graph_DIR_COL
61 { NULL }
64 static subtype_info_t bar_subtypes [] = {
66 N_("Clustered bars. Compares values between categories"),
67 1, 1,
69 TRUE,
70 GNOME_Graph_CHART_TYPE_CLUSTERED,
71 GNOME_Graph_PLOT_COLBAR,
72 GNOME_Graph_COLBAR_FLAT,
73 GNOME_Graph_DIR_BAR
78 N_("Stacked bars. Compares the values brought by each category"),
79 1, 2,
81 TRUE,
82 GNOME_Graph_CHART_TYPE_STACKED,
83 GNOME_Graph_PLOT_COLBAR,
84 GNOME_Graph_COLBAR_FLAT,
85 GNOME_Graph_DIR_BAR
91 N_("Stacked bars, 100%. Compares between the categories the values broght to a total"),
92 1, 3,
94 TRUE,
95 GNOME_Graph_CHART_TYPE_STACKED_FULL,
96 GNOME_Graph_PLOT_COLBAR,
97 GNOME_Graph_COLBAR_FLAT,
98 GNOME_Graph_DIR_BAR
102 { NULL }
105 static subtype_info_t lines_subtypes [] = {
107 N_("Lines. FIXME: Add nice explanation"),
108 1, 1,
110 TRUE,
111 GNOME_Graph_CHART_TYPE_CLUSTERED,
112 GNOME_Graph_PLOT_LINES,
113 GNOME_Graph_COLBAR_FLAT,
114 GNOME_Graph_DIR_COL,
115 GNOME_Graph_LINE_PLAIN,
120 N_("Stacked Lines. FIXME: Add nice explanation"),
121 1, 2,
123 TRUE,
124 GNOME_Graph_CHART_TYPE_STACKED,
125 GNOME_Graph_PLOT_LINES,
126 GNOME_Graph_COLBAR_FLAT,
127 GNOME_Graph_DIR_COL,
128 GNOME_Graph_LINE_PLAIN
134 N_("Stacked lines, 100%. FIXME: Add nice explanation"),
135 1, 3,
137 TRUE,
138 GNOME_Graph_CHART_TYPE_STACKED_FULL,
139 GNOME_Graph_PLOT_LINES,
140 GNOME_Graph_COLBAR_FLAT,
141 GNOME_Graph_DIR_COL,
142 GNOME_Graph_LINE_PLAIN
147 N_("Lines with markers. FIXME: Add nice explanation"),
148 2, 1,
150 TRUE,
151 GNOME_Graph_CHART_TYPE_CLUSTERED,
152 GNOME_Graph_PLOT_LINES,
153 GNOME_Graph_COLBAR_FLAT,
154 GNOME_Graph_DIR_COL,
155 GNOME_Graph_LINE_MARKERS,
160 N_("Stacked lines with markers. FIXME: Add nice explanation"),
161 2, 2,
163 TRUE,
164 GNOME_Graph_CHART_TYPE_STACKED,
165 GNOME_Graph_PLOT_LINES,
166 GNOME_Graph_COLBAR_FLAT,
167 GNOME_Graph_DIR_COL,
168 GNOME_Graph_LINE_MARKERS
173 N_("Stacked lines with markers, 100%. FIXME: Add nice explanation"),
174 2, 3,
176 TRUE,
177 GNOME_Graph_CHART_TYPE_STACKED_FULL,
178 GNOME_Graph_PLOT_LINES,
179 GNOME_Graph_COLBAR_FLAT,
180 GNOME_Graph_DIR_COL,
181 GNOME_Graph_LINE_MARKERS
185 { NULL }
188 static subtype_info_t scatter_subtypes [] = {
190 N_("Scatter points"),
191 1, 1,
193 FALSE,
194 GNOME_Graph_CHART_TYPE_SCATTER,
195 0, /* plot_mode ignored */
196 0, /* col_bar_mode ignored */
197 0, /* direction ignored */
198 GNOME_Graph_LINE_PLAIN,
199 0, /* pie_mode ignored */
200 0, /* pie_dim ignored */
201 GNOME_Graph_SCATTER_POINTS,
202 GNOME_Graph_SCATTER_CONN_NONE,
207 N_("Scatter points connected with lines"),
208 3, 1,
210 FALSE,
211 GNOME_Graph_CHART_TYPE_SCATTER,
212 0, /* plot_mode ignored */
213 0, /* col_bar_mode ignored */
214 0, /* direction ignored */
215 GNOME_Graph_LINE_PLAIN,
216 0, /* pie_mode ignored */
217 0, /* pie_dim ignored */
218 GNOME_Graph_SCATTER_POINTS,
219 GNOME_Graph_SCATTER_CONN_LINES,
224 N_("Scatter data connected with lines"),
225 3, 2,
227 FALSE,
228 GNOME_Graph_CHART_TYPE_SCATTER,
229 0, /* plot_mode ignored */
230 0, /* col_bar_mode ignored */
231 0, /* direction ignored */
232 GNOME_Graph_LINE_PLAIN,
233 0, /* pie_mode ignored */
234 0, /* pie_dim ignored */
235 GNOME_Graph_SCATTER_NONE,
236 GNOME_Graph_SCATTER_CONN_LINES,
240 { NULL }
243 static subtype_info_t area_subtypes [] = {
245 N_("Area 1: FIXME add nice description"),
246 1, 1,
248 TRUE,
249 GNOME_Graph_CHART_TYPE_CLUSTERED,
250 GNOME_Graph_PLOT_AREA,
251 GNOME_Graph_COLBAR_FLAT,
252 GNOME_Graph_DIR_COL
257 N_("Stacked area. FIXME: add nic description"),
258 1, 2,
260 TRUE,
261 GNOME_Graph_CHART_TYPE_STACKED,
262 GNOME_Graph_PLOT_AREA,
263 GNOME_Graph_COLBAR_FLAT,
264 GNOME_Graph_DIR_COL
270 N_("Stacked Area, 100%. FIXME: add nice description"),
271 1, 3,
273 TRUE,
274 GNOME_Graph_CHART_TYPE_STACKED_FULL,
275 GNOME_Graph_PLOT_AREA,
276 GNOME_Graph_COLBAR_FLAT,
277 GNOME_Graph_DIR_COL
281 { NULL }
284 static struct {
285 char *text;
286 char *icon_name;
287 subtype_info_t *subtypes;
288 } graphic_types [] = {
289 { N_("Column"), "chart_column", column_subtypes },
290 { N_("Bar"), "chart_bar", bar_subtypes },
291 { N_("Lines"), "chart_line", lines_subtypes },
292 { N_("Scatter"), "chart_scatter", scatter_subtypes },
293 { N_("Areas"), "chart_area", area_subtypes },
294 { NULL, NULL, NULL }
297 void
298 graphic_type_show_page (WizardGraphicContext *gc, int n)
300 gtk_notebook_set_page (gc->graphic_types_notebook, n);
301 graphic_type_set_chart_mode (gc->chart, &graphic_types [n].subtypes [0].par);
304 void
305 graphic_type_show_preview (WizardGraphicContext *gc)
307 gc->last_graphic_type_page = gtk_notebook_get_current_page (gc->graphic_types_notebook);
308 gtk_notebook_set_page (gc->graphic_types_notebook, 5);
311 void
312 graphic_type_restore_view (WizardGraphicContext *gc)
314 gtk_notebook_set_page (gc->graphic_types_notebook, gc->last_graphic_type_page);
315 gc->last_graphic_type_page = -1;
318 static void
319 graphic_type_selected (GtkCList *clist, gint row, gint column, GdkEvent *event,
320 WizardGraphicContext *gc)
322 graphic_type_show_page (gc, row);
325 void
326 graphic_type_set_chart_mode (GNOME_Graph_Chart chart, PlotParameters *par)
328 CORBA_Environment ev;
330 CORBA_exception_init (&ev);
332 GNOME_Graph_Chart__set_chart_type (chart, par->chart_type, &ev);
333 GNOME_Graph_Chart__set_plot_mode (chart, par->plot_mode, &ev);
334 GNOME_Graph_Chart__set_col_bar_mode (chart, par->col_bar_mode, &ev);
335 GNOME_Graph_Chart__set_direction (chart, par->direction, &ev);
336 GNOME_Graph_Chart__set_line_mode (chart, par->line_mode, &ev);
337 GNOME_Graph_Chart__set_pie_mode (chart, par->pie_mode, &ev);
338 GNOME_Graph_Chart__set_pie_dim (chart, par->pie_dim, &ev);
339 GNOME_Graph_Chart__set_scatter_mode (chart, par->scatter_mode, &ev);
340 GNOME_Graph_Chart__set_scatter_conn (chart, par->scatter_conn, &ev);
341 GNOME_Graph_Chart__set_surface_mode (chart, par->surface_mode, &ev);
342 GNOME_Graph_Chart__set_with_labels (chart, par->with_labels, &ev);
343 CORBA_exception_free (&ev);
346 static void
347 graph_type_button_clicked (GtkWidget *widget, subtype_info_t *type)
349 WizardGraphicContext *gc = gtk_object_get_user_data (GTK_OBJECT (widget));
350 GtkLabel *label = GTK_LABEL (glade_xml_get_widget (gc->gui, "plot-description"));
352 gtk_label_set_text (label, type->description);
353 graphic_type_set_chart_mode (gc->chart, &type->par);
356 static void
357 show_sample_pressed (GtkWidget *button, WizardGraphicContext *gc)
359 graphic_type_show_preview (gc);
362 static void
363 show_sample_released (GtkWidget *button, WizardGraphicContext *gc)
365 graphic_type_restore_view (gc);
368 void
369 graphic_type_boot (GladeXML *gui, WizardGraphicContext *gc)
371 GtkCList *clist = GTK_CLIST (glade_xml_get_widget (gui, "graphic-type-clist"));
372 GtkTable *table = GTK_TABLE (glade_xml_get_widget (gui, "graphic-selector-table"));
373 GtkObject *show_sample = GTK_OBJECT(glade_xml_get_widget (gui, "show-sample"));
374 int i;
376 gc->graphic_types_notebook = GTK_NOTEBOOK (gtk_notebook_new ());
377 gtk_widget_show (GTK_WIDGET (gc->graphic_types_notebook));
378 gtk_table_attach (table, GTK_WIDGET (gc->graphic_types_notebook),
379 1, 2, 1, 3,
380 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
381 0, 0);
382 gtk_notebook_set_show_tabs (gc->graphic_types_notebook, FALSE);
383 gtk_container_set_border_width (GTK_CONTAINER (gc->graphic_types_notebook), 0);
384 gtk_notebook_set_show_border (gc->graphic_types_notebook, FALSE);
386 gtk_clist_set_column_width (clist, 0, 16);
387 gtk_clist_set_column_justification (clist, 1, GTK_JUSTIFY_LEFT);
388 gtk_signal_connect (GTK_OBJECT (clist), "select_row",
389 GTK_SIGNAL_FUNC (graphic_type_selected), gc);
391 for (i = 0; graphic_types [i].text; i++){
392 GtkWidget *display_table;
393 subtype_info_t *type_info;
394 char *clist_text [2];
395 int j;
397 clist_text [0] = "";
398 clist_text [1] = _(graphic_types [i].text);
399 gtk_clist_append (clist, clist_text);
401 type_info = graphic_types [i].subtypes;
403 display_table = gtk_table_new (0, 0, 0);
404 gtk_widget_show (display_table);
405 gtk_notebook_append_page (gc->graphic_types_notebook, display_table, NULL);
407 for (j = 0; type_info [j].description != NULL; j++){
408 GtkWidget *happy_button, *pix;
409 char *button_name;
411 happy_button = gtk_button_new ();
412 gtk_widget_show (happy_button);
413 gtk_button_set_relief (GTK_BUTTON (happy_button), GTK_RELIEF_NONE);
415 button_name = g_strdup_printf (
416 "%s/%s_%d_%d.png",
417 GNUMERIC_ICONSDIR, graphic_types [i].icon_name,
418 type_info [j].col, type_info [j].row);
419 pix = gnome_pixmap_new_from_file (button_name);
420 if (pix){
421 gtk_container_add (GTK_CONTAINER (happy_button), pix);
422 gtk_widget_show (pix);
424 g_free (button_name);
426 gtk_table_attach (
427 GTK_TABLE (display_table), happy_button,
428 type_info [j].row, type_info [j].row+1,
429 type_info [j].col, type_info [j].col+1,
430 0, 0, 4, 4);
432 gtk_signal_connect (
433 GTK_OBJECT (happy_button), "clicked",
434 GTK_SIGNAL_FUNC(graph_type_button_clicked), &type_info [j]);
435 gtk_object_set_user_data (GTK_OBJECT (happy_button), gc);
437 if (i == 0 && j == 0)
438 gtk_button_clicked (GTK_BUTTON (happy_button));
444 BonoboViewFrame *frame;
445 GtkWidget *view;
447 frame = graphic_context_new_chart_view_frame (gc);
448 view = bonobo_view_frame_get_wrapper (frame);
449 gtk_widget_show (view);
450 gtk_notebook_append_page (gc->graphic_types_notebook, view, NULL);
453 gtk_clist_select_row (clist, 0, 1);
454 gtk_clist_thaw (clist);
457 * Connect the "Show Preview" button
460 gtk_signal_connect (
461 show_sample, "pressed", GTK_SIGNAL_FUNC (show_sample_pressed), gc);
462 gtk_signal_connect (
463 show_sample, "released", GTK_SIGNAL_FUNC (show_sample_released), gc);
467 * Set a chart mode default
469 void
470 graphic_type_init_preview (WizardGraphicContext *gc)
472 graphic_type_set_chart_mode (gc->chart, &column_subtypes [0].par);