00001
00002
00003
00004
00005
00006
00007
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "config.h"
00033
00034 #include <math.h>
00035 #include <string.h>
00036 #include <glib.h>
00037 #include <gtk/gtk.h>
00038 #include <glib/gi18n.h>
00039 #include <gtkextra/gtksheet.h>
00040 #include <gtkhtml/gtkhtml.h>
00041 #include <libgnomeprint/gnome-print.h>
00042 #include <libgnomeprint/gnome-print-paper.h>
00043 #include <libgnomeprint/gnome-print-job.h>
00044 #include <libgnomeprintui/gnome-print-preview.h>
00045 #include <libgnomeprintui/gnome-print-job-preview.h>
00046 #include "types.h"
00047 #include "dim_list_menu.h"
00048 #include "edit.h"
00049 #include "filter.h"
00050 #include "main.h"
00051 #include "menus.h"
00052 #include "field.h"
00053 #include "sort.h"
00054 #include "fileout.h"
00055
00056 static GtkWidget * select_dlg = NULL;
00057
00058 #define WRITETAG(x) gtk_html_write (html, handle, (x), strlen((x)));
00059
00063 static gint page_num, pages;
00064 static GnomeFont *font;
00065 static GtkHTML *html;
00066 static gshort row = 0;
00069 static GList * thead_list = NULL;
00070 static GtkWidget * entry1 = NULL;
00072 gchar *newrow[2];
00073 static gint widthx;
00074 static gchar *spaces;
00075 static gchar *pos_text;
00076 static size_t local_len;
00077 static GtkTextBuffer * buffer;
00080 typedef struct
00081 {
00082 gdouble group_total;
00083 gdouble grand_total;
00084 gint skip_over;
00085 gboolean do_group;
00086 gboolean error;
00087 gboolean do_total;
00088 gint16 field;
00089 gint16 list_col;
00090 gint16 justification;
00091 gint16 formatting;
00092 gint16 decimal_places;
00093 gint16 width;
00094 gint16 type;
00095 } QlColInfo;
00096
00097 enum {
00098 REPORT_COL,
00099 FROM_COL,
00100 LAST_COL
00101 };
00102
00110 typedef struct
00111 {
00112 QlCurrFormat curr_fmt;
00113 QlDateFormat date_fmt;
00114 QlTimeFormat time_fmt;
00116 gint txt_format;
00117 QlFieldInfo * field_info;
00119 GtkHTMLStream * temp;
00120 }QlTHead;
00121
00123 static void
00124 close_filetab (GtkWidget G_GNUC_UNUSED * w, gpointer data)
00125 {
00126 gint tab_index;
00127 QlTabData * tab;
00128
00129 tab = (QlTabData*) data;
00130 g_return_if_fail (tab);
00131 if (check_if_changed (tab))
00132 {
00133
00134 ask_about_save (tab);
00135 tab->file->changed = FALSE;
00136 dim_all_menus(tab->qlc);
00137 return;
00138 }
00139 tab_index = gtk_notebook_get_current_page (tab->qlc->notebook);
00140 gtk_notebook_remove_page (tab->qlc->notebook, tab_index);
00141 dim_all_menus (tab->qlc);
00142 }
00143
00144 static void
00145 close_report (GtkWidget G_GNUC_UNUSED * w, gpointer data)
00146 {
00147 gint tab_index;
00148 QlTabData * tab;
00149
00150 tab = (QlTabData*) data;
00151 g_return_if_fail (tab);
00152 tab_index = gtk_notebook_get_current_page (tab->qlc->notebook);
00153 gtk_notebook_remove_page (tab->qlc->notebook, tab_index);
00154 dim_all_menus (tab->qlc);
00155 }
00156
00157 GtkWidget *
00158 tab_label_box (QlTabData * tab, const gchar * label_text)
00159 {
00160 GtkWidget * label_box, * label, * tab_close;
00161 GtkWidget * tab_image;
00162 GtkRcStyle *rcstyle;
00163
00164 label_box = gtk_hbox_new (FALSE, 0);
00165 label = gtk_label_new (label_text);
00166 gtk_box_pack_start (GTK_BOX(label_box), label, FALSE, FALSE, 5);
00167 tab_close = gtk_button_new();
00168 gtk_button_set_relief(GTK_BUTTON(tab_close), GTK_RELIEF_NONE);
00169 gtk_button_set_focus_on_click (GTK_BUTTON (tab_close), FALSE);
00171 rcstyle = gtk_rc_style_new ();
00172 rcstyle->xthickness = rcstyle->ythickness = 0;
00173 gtk_widget_modify_style (tab_close, rcstyle);
00174 g_object_unref (rcstyle);
00175 tab_image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
00176 gtk_container_add(GTK_CONTAINER(tab_close), tab_image);
00177 gtk_box_pack_start (GTK_BOX(label_box), tab_close, FALSE, FALSE, 0);
00178 gtk_widget_show_all (label_box);
00179
00180 if ((tab->file->file_path) && (!tab->file->report_ptr))
00181 g_signal_connect (tab_close, "clicked", G_CALLBACK (close_filetab), tab);
00182 else
00183 g_signal_connect (tab_close, "clicked", G_CALLBACK (close_report), tab);
00184 return label_box;
00185 }
00186
00193 static void
00194 thead_cb (gpointer theadp, gpointer tabp)
00195 {
00196 gchar * buf;
00197 QlTabData * tab = (QlTabData*) tabp;
00198 QlFieldInfo * field;
00199 QlTHead * thead = (QlTHead*)theadp;
00200 GtkHTMLStream * handle = thead->temp;
00201
00202 field = ql_get_fieldinfo (tab, thead->field_info->sheet_column);
00203 buf = g_strconcat ("<td><b>", field->name, "</b></td>\n", NULL);
00204 WRITETAG(buf);
00205 g_free (buf);
00206 }
00207
00208 static void
00209 tbl_row_cb (gpointer theadp, gpointer tabp)
00210 {
00211 gchar * buf, * tag;
00212 QlTabData * tab = (QlTabData*) tabp;
00213 QlTHead * thead = (QlTHead*)theadp;
00214 GtkHTMLStream * handle = thead->temp;
00215
00216 buf = NULL;
00217
00219 buf = gtk_sheet_cell_get_text (tab->view->sheet, row,
00220 thead->field_info->sheet_column);
00221 if (!buf)
00222 buf = " ";
00223 tag = g_strconcat ("<td>", buf, "</td>\n", NULL);
00224 WRITETAG(tag);
00225 g_free (buf);
00226 }
00227
00234 static void
00235 html_on_screen (QlTabData * tab)
00236 {
00237 GtkWidget *scrolled_window;
00238 GtkWidget *html_widget;
00239 gchar * buf;
00240 gshort c, field_num;
00241 GtkHTMLStream * handle = NULL;
00242
00243 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
00244 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
00245 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
00246 html_widget = gtk_html_new ();
00247 html = GTK_HTML (html_widget);
00248 gtk_html_set_allow_frameset (html, FALSE);
00249 gtk_html_load_empty (html);
00250 gtk_html_set_editable (html, FALSE);
00251 gtk_container_add (GTK_CONTAINER (scrolled_window), html_widget);
00252 handle = gtk_html_begin_content (html, "text/html; charset=UTF-8");
00253 WRITETAG("<html><head>\n");
00254 WRITETAG("<meta name=\"Generator\" content=\"QUICKLIST\">\n");
00255 WRITETAG("</head><body>\n");
00256 buf = g_strconcat ("<h1>", tab->file->report_ptr->header, "</h1>\n", NULL);
00257 WRITETAG(buf);
00258 g_free (buf);
00259 buf = g_strconcat ("<h2>", tab->file->report_ptr->name, "</h2>\n", NULL);
00260 WRITETAG(buf);
00261 g_free (buf);
00262 for (c = 0; c < tab->file->report_ptr->last_column; c++)
00263 {
00264 QlFieldInfo * field;
00265 QlTHead * thead = g_new0 (QlTHead, 1);
00267 field = g_new0(QlFieldInfo, 1);
00268 thead->field_info = field;
00269 thead->field_info->sheet_column = c + 1;
00270 field_num = tab->file->report_ptr->column[c+1].field;
00271 field = ql_get_fieldinfo (tab, field_num);
00272 thead->field_info->type = field->type;
00273 thead->temp = handle;
00274
00275 switch (thead->field_info->type)
00276 {
00277 case FIELD_TYPE_NUMERIC :
00278 {
00279 thead->curr_fmt = field->formatting;
00280 break;
00281 }
00282 case FIELD_TYPE_DATE :
00283 {
00284 thead->date_fmt = field->formatting;
00285 break;
00286 }
00287 case FIELD_TYPE_TIME :
00288 {
00289 thead->time_fmt = field->formatting;
00290 break;
00291 }
00292 case FIELD_TYPE_TEXT :
00293 {
00294 thead->txt_format = field->formatting;
00295 break;
00296 }
00297 }
00298 thead_list = g_list_append (thead_list, thead);
00299 }
00300
00301 WRITETAG ("<table border=\"1\"><tr>\n");
00302 g_list_foreach (thead_list, thead_cb, tab);
00303 WRITETAG ("</tr>\n");
00304
00305
00306 for (row = 0; row < tab->file->last_row; row++)
00307 {
00308 WRITETAG ("<tr>\n");
00309 g_list_foreach (thead_list, tbl_row_cb, tab);
00310 WRITETAG ("</tr>\n");
00311 }
00312 WRITETAG("</table>\n</body></html>\n");
00314 gtk_notebook_append_page (tab->qlc->notebook, scrolled_window,
00315 tab_label_box(tab, tab->file->report_ptr->name));
00316 gtk_widget_show_all (scrolled_window);
00317 }
00318
00319 static void
00320 print_footer (GtkHTML G_GNUC_UNUSED *fhtml, GnomePrintContext *context,
00321 gdouble x, gdouble y, gdouble width, gdouble G_GNUC_UNUSED height,
00322 gpointer G_GNUC_UNUSED user_data)
00323 {
00324
00325 gchar *text = g_strdup_printf (_("- %d of %d -"), page_num, pages);
00326 gdouble tw = gnome_font_get_width_utf8 (font, "text");
00327
00328 if (font) {
00329 gnome_print_newpath (context);
00330 gnome_print_setrgbcolor (context, .0, .0, .0);
00331 gnome_print_moveto (context, x + (width - tw)/2, y - gnome_font_get_ascender (font));
00332 gnome_print_setfont (context, font);
00333 gnome_print_show (context, text);
00334 }
00335 g_free (text);
00336 page_num++;
00337 }
00338
00339 void
00340 print_cb (GtkWidget G_GNUC_UNUSED * widget, gpointer G_GNUC_UNUSED data)
00341 {
00342 GnomePrintJob *print_master;
00343 GnomePrintContext *print_context;
00344
00345 print_master = gnome_print_job_new (NULL);
00346 gtk_html_print_set_master (html, print_master);
00347
00348 print_context = gnome_print_job_get_context (print_master);
00349 font = gnome_font_find_closest ("Helvetica", 12);
00350 page_num = 1;
00351 pages = gtk_html_print_get_pages_num (html, print_context,
00352 .0, gnome_font_get_ascender (font) - gnome_font_get_descender (font));
00353 gtk_html_print_with_header_footer (html, print_context,
00354 .0, gnome_font_get_ascender (font) - gnome_font_get_descender (font),
00355 NULL, print_footer, NULL);
00356 if (font)
00357 g_object_unref (font);
00358 gnome_print_job_render (print_master, print_context);
00359 }
00360
00361 void
00362 print_preview_cb (GtkWidget G_GNUC_UNUSED * widget, gpointer G_GNUC_UNUSED data)
00363 {
00364 GnomePrintJob *print_master;
00365 GnomePrintContext *print_context;
00366 GtkWidget *preview;
00367
00368 print_master = gnome_print_job_new (NULL);
00369 gtk_html_print_set_master (html, print_master);
00370
00371 print_context = gnome_print_job_get_context (print_master);
00372 font = gnome_font_find_closest ("Helvetica", 12);
00373
00374 page_num = 1;
00375 pages = gtk_html_print_get_pages_num (html, print_context,
00376 .0, gnome_font_get_ascender (font) - gnome_font_get_descender (font));
00377 gtk_html_print_with_header_footer (html, print_context,
00378 .0, gnome_font_get_ascender (font) - gnome_font_get_descender (font),
00379 NULL, print_footer, NULL);
00380 if (font)
00381 g_object_unref (font);
00382
00383 gnome_print_job_close (print_master);
00384 preview = gnome_print_job_preview_new (print_master, "Print Preview");
00385 gtk_widget_show (preview);
00386
00387 g_object_unref (print_master);
00388 }
00389
00392
00393 static void
00394 report_set_col_field (QlTabData * tab, gint col)
00395 {
00396 tab->view->report_sel_col = col;
00397 tab->view->report_sel_field = tab->file->report_ptr->column[col].field;
00398 }
00399
00400 static void
00401 display_column (QlTabData * tab, gint colx)
00402 {
00403 gint fieldx;
00404 gint rowx;
00405 gint list_mode_col;
00406 gchar *text;
00407 QlReportColumn *this_column;
00408 QlFieldInfo * field;
00409
00410 this_column = &tab->file->report_ptr->column[colx];
00411
00412 fieldx = this_column->field;
00413 field = ql_get_fieldinfo (tab, fieldx);
00414 list_mode_col = field->sheet_column;
00415 gtk_sheet_set_column_width (tab->view->report_sheet,
00416 colx, this_column->width * 8);
00417 gtk_sheet_column_button_add_label (tab->view->report_sheet,
00418 colx, field->name);
00419 gtk_sheet_column_set_justification (tab->view->report_sheet,
00420 colx, field->justification);
00421
00422
00423 if (this_column->group)
00424 gtk_sheet_set_cell_text (tab->view->report_sheet,
00425 0, colx, _("Group"));
00426 else
00427 gtk_sheet_cell_clear (tab->view->report_sheet, 0, colx);
00428
00429 if (this_column->total)
00430 gtk_sheet_set_cell_text (tab->view->report_sheet, 1, colx,
00431 _("Total"));
00432 else
00433 gtk_sheet_cell_clear (tab->view->report_sheet, 1, colx);
00434
00435
00436 for (rowx = 2; rowx < 8; rowx++)
00437 {
00438 gtk_sheet_cell_clear (tab->view->report_sheet, rowx, colx);
00439 if (tab->view->adjust_rows[rowx] >= 0)
00440 {
00441 text = gtk_sheet_cell_get_text (tab->view->sheet,
00442 tab->view->adjust_rows[rowx], list_mode_col);
00443 if (text)
00444 gtk_sheet_set_cell_text (tab->view->report_sheet,
00445 rowx, colx, text);
00446 }
00447 }
00448 }
00449
00450 static void
00451 display_all_columns (QlTabData * tab)
00452 {
00453 gint colx;
00454 big_draw_start (tab);
00455 for (colx = 0; colx <= tab->file->report_ptr->last_column; colx++)
00456 display_column (tab, colx);
00457 big_draw_end (tab);
00458 }
00459
00460 static void
00461 new_report_column_width (GtkSheet G_GNUC_UNUSED * sheet, gint col,
00462 gint width, gpointer data)
00463 {
00464 QlTabData * tab;
00465
00466 tab = (QlTabData*)data;
00467 front_is_changed (tab);
00468
00469 if (width > 640)
00470 tab->file->report_ptr->column[col].width = 80;
00471 else
00472 tab->file->report_ptr->column[col].width = width / 8;
00473 }
00474
00475
00476
00477 static gint
00478 pick6rows (QlTabData * tab)
00479 {
00480 gint hits = 0;
00481 gint rowx, torow, fromrow;
00482
00483
00484 for (rowx = 0; rowx < 6; rowx++)
00485 {
00486 if (rowx <= tab->file->last_row)
00487 tab->view->adjust_rows[rowx + 2] = rowx;
00488 else
00489 tab->view->adjust_rows[rowx + 2] = 0;
00490 }
00491
00492 torow = fromrow = 0;
00493 do
00494 {
00495 if (row_is_visible (tab, fromrow))
00496 {
00497 hits++;
00498 tab->view->adjust_rows[torow + 2] = fromrow;
00499 torow++;
00500 }
00501 }
00502 while (++fromrow <= tab->file->last_row && torow < 6);
00503 for (; torow < 6; torow++)
00504 tab->view->adjust_rows[torow + 2] = -1;
00505 if (!hits)
00506 level1_error (tab, _("No rows match the current filter"));
00507 return hits;
00508 }
00509
00510
00511 static void
00512 pos_delete (GtkObject G_GNUC_UNUSED * object, gpointer data)
00513 {
00514 gint reportx;
00515 QlTabData * tab = (QlTabData*) data;
00516
00517
00519 for (reportx = tab->file->report_no; reportx < tab->file->report_ct - 1;
00520 reportx++)
00521 memcpy (&tab->file->reports[reportx], &tab->file->reports[reportx + 1],
00522 sizeof (QlReportInfo));
00523 tab->file->report_ct--;
00524 }
00525
00526
00527 static void
00528 pos_get_dim (QlTabData * tab)
00529 {
00530 tab->file->report_ptr->width =
00531 GTK_WIDGET (tab->view->report_win)->allocation.width;
00532 tab->file->report_ptr->height =
00533 GTK_WIDGET (tab->view->report_win)->allocation.height;
00534 }
00535
00536
00537 static void
00538 pos_list_mode (GtkObject G_GNUC_UNUSED * object, gpointer data)
00539 {
00540 QlTabData * tab = (QlTabData*)data;
00541 pos_get_dim (tab);
00542 dim_all_menus (tab->qlc);
00543 }
00544
00545
00546 void
00547 pos_justify (gint jx)
00548 {
00549 GtkTextIter justify_iter;
00550
00551 gint half;
00552 if (jx == GTK_JUSTIFY_LEFT)
00553 {
00554 gtk_text_buffer_get_end_iter (buffer, &justify_iter);
00555 gtk_text_buffer_insert (buffer, &justify_iter, pos_text, local_len);
00556 gtk_text_buffer_insert (buffer, &justify_iter, spaces,
00557 widthx - local_len);
00558 return;
00559 }
00560
00561 if (jx == GTK_JUSTIFY_RIGHT)
00562 {
00563 gtk_text_buffer_get_end_iter (buffer, &justify_iter);
00564 gtk_text_buffer_insert (buffer, &justify_iter, spaces,
00565 widthx - local_len);
00566 gtk_text_buffer_insert (buffer, &justify_iter, pos_text,
00567 local_len);
00568 return;
00569 }
00570
00571
00572 half = (widthx - local_len) / 2;
00573 gtk_text_buffer_get_end_iter (buffer, &justify_iter);
00574 gtk_text_buffer_insert (buffer, &justify_iter, spaces, half);
00575 gtk_text_buffer_insert (buffer, &justify_iter, pos_text, local_len);
00576 gtk_text_buffer_insert (buffer, &justify_iter, spaces,
00577 widthx - local_len - half);
00578 }
00579
00580 static gboolean
00581 report_activate (GtkSheet G_GNUC_UNUSED * sheet, gint rrow, gint col, gpointer data)
00582 {
00583 QlTabData * tab;
00584
00585 tab = (QlTabData*)data;
00586 g_return_val_if_fail (tab, FALSE);
00587 if (rrow < 0 || col < 0)
00588 return TRUE;
00589 report_set_col_field (tab, col);
00590 dim_all_menus (tab->qlc);
00591 return TRUE;
00592 }
00593
00594 static void
00595 select_report_range (GtkSheet G_GNUC_UNUSED * sheet, GtkSheetRange * range,
00596 gpointer data)
00597 {
00598 QlTabData * tab;
00599 GtkSheetRange local_range;
00600
00601 tab = (QlTabData*)data;
00602 local_range = *range;
00603 if (local_range.col0 == local_range.coli)
00604 {
00605 report_set_col_field (tab, local_range.col0);
00606 dim_all_menus (tab->qlc);
00607 }
00612 }
00613
00614 static void
00615 sort_change (QlTabData * tab, GtkObject G_GNUC_UNUSED * object, gpointer entry)
00616 {
00617 tab->file->report_ptr->sort = GPOINTER_TO_INT (entry) - 1;
00618 if (!entry)
00619 return;
00620 sort_do_it (tab, tab->file->report_ptr->sort);
00621 pick6rows (tab);
00622 display_all_columns (tab);
00623 }
00624
00625 static void
00626 filter_change (QlTabData * tab, GtkObject G_GNUC_UNUSED * object,
00627 gpointer entry)
00628 {
00629 tab->file->report_ptr->filter = GPOINTER_TO_INT (entry) - 1;
00630 filter_do_apply (tab, tab->file->report_ptr->filter);
00631 pick6rows (tab);
00632 display_all_columns (tab);
00633 }
00634
00635
00636 static GtkWidget *
00637 sort_filter_menu (QlTabData * tab)
00638 {
00639
00640
00641
00642
00643
00644
00645
00646
00647
00649
00650 GtkWidget *menu, *menu_item, *name_label;
00651 gint sortx;
00652 gint filterx;
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 menu = gtk_menu_new ();
00667 menu_item = gtk_menu_item_new_with_label (_("-Do not sort-"));
00668 gtk_widget_show (menu_item);
00669 g_signal_connect (GTK_OBJECT (menu_item),
00670 "activate", G_CALLBACK (sort_change), GINT_TO_POINTER (0));
00671 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, 1, 0, 1);
00672
00673 for (sortx = 0; sortx < tab->file->sort_ct; sortx++)
00674 {
00675 menu_item =
00676 gtk_menu_item_new_with_label (tab->file->sorts[sortx].name);
00677 gtk_widget_show (menu_item);
00678 {
00679
00680 gint t;
00681 t = sortx + 1;
00682 g_signal_connect (GTK_OBJECT (menu_item), "activate",
00683 G_CALLBACK (sort_change), GINT_TO_POINTER (t));
00684 }
00685 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, 1, 0, 1);
00686 }
00687
00688
00689
00690
00691
00692
00693
00694
00695 name_label = gtk_label_new (_("Sort rule: "));
00696
00697
00698
00699 menu = gtk_menu_new ();
00700 menu_item = gtk_menu_item_new_with_label (_("-Print all rows-"));
00701 gtk_widget_show (menu_item);
00702 g_signal_connect (GTK_OBJECT (menu_item), "activate",
00703 G_CALLBACK (filter_change), GINT_TO_POINTER (0));
00704 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, 1, 0, 1);
00705
00706
00707 for (filterx = 0; filterx < tab->file->filter_ct; filterx++)
00708 {
00709 menu_item = gtk_menu_item_new_with_label (tab->file->filters
00710 [filterx].name);
00711 gtk_widget_show (menu_item);
00712 {
00713
00714 gint t;
00715 t = filterx + 1;
00716 g_signal_connect (GTK_OBJECT (menu_item), "activate",
00717 G_CALLBACK (filter_change), GINT_TO_POINTER (t));
00718 }
00719 gtk_menu_attach (GTK_MENU (menu), menu_item, 0, 1, 0, 1);
00720 }
00721
00722
00723
00724
00725
00726
00727 name_label = gtk_label_new (_("Filter: "));
00728
00729
00730
00731
00732 return NULL;
00733 }
00734
00735
00736 static void
00737 adjust_preview (GtkObject G_GNUC_UNUSED * object, gpointer data)
00738 {
00739 gchar *text;
00740 QlTabData * tab;
00741
00742 tab = (QlTabData*) data;
00743 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry1)));
00744 if (check_entry (tab, text))
00745 {
00746 g_free (text);
00747 return;
00748 }
00749 tab->file->report_ptr->name = g_strdup(text);
00750 g_free (text);
00751 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tab->view->entry2)));
00752 if (check_entry (tab, text))
00753 {
00754 g_free (text);
00755 return;
00756 }
00757 tab->file->report_ptr->header = g_strdup(text);
00758 g_free (text);
00759 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tab->view->entry3)));
00760 if (check_entry (tab, text))
00761 {
00762 g_free (text);
00763 return;
00764 }
00765 tab->file->report_ptr->footer = g_strdup(text);
00766 g_free (text);
00767 html_on_screen (tab);
00768 }
00769
00770
00771 static void
00772 adjust_report (QlTabData * tab)
00773 {
00774 gchar *temp_file_name;
00775 gint rowx;
00776 GtkWidget *vbox;
00777 GtkWidget *menu_bar;
00778 GtkWidget *hbox1;
00779 GtkWidget *name_label;
00780
00781
00782 GtkWidget *hbox2;
00783
00784 GtkWidget *header_label;
00785
00786 GtkWidget *hbox3;
00787
00788 GtkWidget *scrolled_window;
00789
00790 GtkWidget *hbox5;
00791 GtkWidget *footer_label;
00792
00793 GtkWidget *hbox6;
00794 GtkWidget *preview_button;
00795 GtkWidget *edit_list_button;
00796 GtkWidget *delete_button;
00797
00798 pick6rows (tab);
00799
00800
00801 tab->view->report_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00802 gtk_container_set_border_width (GTK_CONTAINER (tab->view->report_win), 5);
00803 tab->view->display_mode = DISPLAY_REPORT;
00804 tab->view->report_mode = DISPLAY_EDIT;
00805 temp_file_name = g_strconcat (tab->file->file_name, " (",
00806 _("Edit Report Layout"), ")", NULL);
00807 gtk_window_set_title (GTK_WINDOW (tab->view->report_win), temp_file_name);
00808 g_free (temp_file_name);
00809
00810 gtk_window_set_resizable (GTK_WINDOW (tab->view->report_win), TRUE);
00811
00812
00813 vbox = gtk_vbox_new (FALSE, 3);
00814 menu_bar = build_report_mb (tab->qlc);
00815 gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, TRUE, 0);
00816
00817
00818 hbox1 = gtk_hbox_new (FALSE, 5);
00819 name_label = gtk_label_new (_("Report Name"));
00820 gtk_box_pack_start (GTK_BOX (hbox1), name_label, FALSE, FALSE, 0);
00821
00822 entry1 = gtk_entry_new ();
00823 gtk_box_pack_start (GTK_BOX (hbox1), entry1, TRUE, TRUE, 0);
00824 gtk_box_pack_start (GTK_BOX (vbox), hbox1, FALSE, FALSE, 0);
00825 gtk_entry_set_text (GTK_ENTRY (entry1),
00826 tab->file->report_ptr->name);
00827
00828
00829 hbox2 = gtk_hbox_new (FALSE, 5);
00830 header_label = gtk_label_new (_("Print at top of page"));
00831 gtk_box_pack_start (GTK_BOX (hbox2), header_label, FALSE, FALSE, 0);
00832
00833 tab->view->entry2 = gtk_entry_new ();
00834 gtk_entry_set_max_length (GTK_ENTRY (tab->view->entry2), 80);
00835 gtk_box_pack_start (GTK_BOX (hbox2), tab->view->entry2, TRUE, TRUE, 0);
00836 gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
00837 gtk_entry_set_text (GTK_ENTRY (tab->view->entry2),
00838 tab->file->report_ptr->header);
00839
00840
00841 hbox3 = sort_filter_menu (tab);
00842 gtk_box_pack_start (GTK_BOX (vbox), hbox3, FALSE, FALSE, 0);
00843
00844
00845 tab->view->report_sheet = GTK_SHEET (gtk_sheet_new_browser (8,
00846 tab->file->report_ptr->last_column + 1, temp_file_name));
00847 report_set_col_field (tab, 0);
00848 gtk_sheet_row_button_add_label (tab->view->report_sheet,
00849 0, _("Group"));
00850 gtk_sheet_row_button_add_label (tab->view->report_sheet,
00851 1, _("Total"));
00852 for (rowx = 2; rowx < 8; rowx++)
00853 gtk_sheet_row_button_add_label (tab->view->report_sheet,
00854 rowx, _("Sample"));
00855 gtk_sheet_set_autoscroll (tab->view->report_sheet, TRUE);
00856 gtk_sheet_set_autoresize (tab->view->report_sheet, FALSE);
00857 gtk_sheet_set_row_titles_width (tab->view->report_sheet, 60);
00858 gtk_container_set_border_width (GTK_CONTAINER (tab->view->report_sheet),
00859 4);
00860
00861
00862 gtk_sheet_show_row_titles (tab->view->report_sheet);
00863 gtk_sheet_show_column_titles (tab->view->report_sheet);
00864 gtk_sheet_columns_set_sensitivity (tab->view->report_sheet, TRUE);
00865 gtk_sheet_rows_set_sensitivity (tab->view->report_sheet, FALSE);
00866 display_all_columns (tab);
00867
00868
00869 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
00870
00871 gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 3);
00872 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
00873 (scrolled_window), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
00874
00875 gtk_container_add (GTK_CONTAINER (scrolled_window),
00876 GTK_WIDGET (tab->view->report_sheet));
00877 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
00878
00879
00880 hbox5 = gtk_hbox_new (FALSE, 5);
00881 footer_label = gtk_label_new (_("Print at bottom of page"));
00882 gtk_box_pack_start (GTK_BOX (hbox5), footer_label, FALSE, FALSE, 0);
00883
00884 tab->view->entry3 = gtk_entry_new ();
00885 gtk_entry_set_max_length (GTK_ENTRY (tab->view->entry3), 80);
00886 gtk_box_pack_start (GTK_BOX (hbox5), tab->view->entry3, TRUE, TRUE, 0);
00887 gtk_box_pack_start (GTK_BOX (vbox), hbox5, FALSE, FALSE, 0);
00888 gtk_entry_set_text (GTK_ENTRY (tab->view->entry3),
00889 tab->file->report_ptr->footer);
00890
00891
00892 hbox6 = gtk_hbox_new (TRUE, 5);
00893 preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
00894 gtk_box_pack_start (GTK_BOX (hbox6), preview_button, TRUE, TRUE, 0);
00895 g_signal_connect (GTK_OBJECT (preview_button), "clicked",
00896 G_CALLBACK (adjust_preview), tab);
00897
00898 edit_list_button = gtk_button_new_from_stock (GTK_STOCK_EDIT);
00899 gtk_box_pack_start (GTK_BOX (hbox6), edit_list_button, TRUE, TRUE, 0);
00900 g_signal_connect (GTK_OBJECT (edit_list_button), "clicked",
00901 G_CALLBACK (pos_list_mode), tab);
00902
00903 delete_button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
00904 gtk_box_pack_start (GTK_BOX (hbox6), delete_button, TRUE, TRUE, 0);
00905 g_signal_connect (GTK_OBJECT (delete_button), "clicked",
00906 G_CALLBACK (pos_delete), tab);
00907
00908 gtk_box_pack_start (GTK_BOX (vbox), hbox6, FALSE, FALSE, 0);
00909
00910 gtk_container_add (GTK_CONTAINER (tab->view->report_win), vbox);
00911 dim_all_menus (tab->qlc);
00912 g_signal_connect (GTK_OBJECT (tab->view->report_win), "delete_event",
00913 G_CALLBACK (pos_list_mode), tab);
00914
00915
00916 g_signal_connect (GTK_OBJECT (tab->view->report_sheet),
00917 "new_column_width", G_CALLBACK (new_report_column_width), tab);
00918 g_signal_connect (GTK_OBJECT (tab->view->report_sheet),
00919 "select_range", G_CALLBACK (select_report_range), tab);
00920 g_signal_connect (GTK_OBJECT (tab->view->report_sheet),
00921 "activate", G_CALLBACK (report_activate), tab);
00922 gtk_widget_show_all (tab->view->report_win);
00923 }
00924
00925
00926 static void
00927 add_ok (GtkWidget G_GNUC_UNUSED * w, gpointer data)
00928 {
00929 gchar *text;
00930 QlTabData * tab;
00931
00932 tab = (QlTabData *)g_object_get_data (G_OBJECT(data), QLTABID);
00933 g_return_if_fail (tab);
00935 if (strcmp(gtk_entry_get_text (GTK_ENTRY (entry1)), "") == 0)
00936 return;
00937 text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry1)));
00938 if (check_entry (tab, text))
00939 {
00940 g_free (text);
00941 return;
00942 }
00943 front_is_changed (tab);
00944 strcpy (tab->file->report_ptr->name, text);
00945 adjust_report (tab);
00946 g_free (text);
00947 gtk_widget_destroy (GTK_WIDGET(data));
00948 }
00949
00950
00951 static G_GNUC_UNUSED void
00952 col_from_clicked (GtkWidget G_GNUC_UNUSED * widget, gint G_GNUC_UNUSED rrow,
00953 gint G_GNUC_UNUSED col, GdkEventButton G_GNUC_UNUSED * event, gpointer G_GNUC_UNUSED data)
00954 {
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987 }
00988
00989
00990 static G_GNUC_UNUSED void
00991 from_clicked (GtkWidget G_GNUC_UNUSED * widget, gint G_GNUC_UNUSED rrow,
00992 gint G_GNUC_UNUSED col, GdkEventButton G_GNUC_UNUSED * event, gpointer G_GNUC_UNUSED data)
00993 {
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010 }
01011
01012 static void
01013 report_dlg_cancel (GtkWidget G_GNUC_UNUSED * w, gpointer data)
01014 {
01015 gtk_widget_destroy (GTK_WIDGET(data));
01016 }
01017
01018 static void
01019 report_add_cancel (GtkWidget G_GNUC_UNUSED * w, gpointer data)
01020 {
01021 QlTabData * tab;
01022
01023 g_return_if_fail (data);
01024 tab = g_object_get_data (G_OBJECT(data), QLTABID);
01025 tab->file->report_ct--;
01026 gtk_widget_destroy (data);
01027 }
01028
01029
01030 void
01031 report_add (GtkAction G_GNUC_UNUSED * w, gpointer data)
01032 {
01033 QlContext * qlc;
01034 QlTabData * tab;
01035 gint colx, fieldx;
01036 guint width;
01037 GtkWidget * report_dlg;
01038 GtkWidget *top_vbox;
01039 GtkWidget *hbox1;
01040 GtkWidget *name_label;
01041 GtkWidget *scrwin_to;
01042 GtkWidget *hbox2;
01043 GtkTreeView * treeview;
01044 GtkTreeModel * model;
01045 GtkTreeStore * treestore;
01046 GtkTreeIter parent_iter, child_iter;
01047 GtkCellRenderer *renderer;
01048 GtkTreeViewColumn *column;
01049 GtkTreeSortable * sort;
01050 GtkTreeSelection * rselect;
01051 GtkWidget *hbox6;
01052 GtkWidget *cancel_button, *ok_button;
01053
01054 qlc = ql_get_context (GTK_WIDGET(data));
01055 tab = ql_get_tabdata (qlc);
01056 g_return_if_fail (tab);
01057 width = 0;
01058 CHECK_CHANGED(tab);
01059 tab->file->report_no = tab->file->report_ct++;
01060 tab->file->report_ptr = &tab->file->reports[tab->file->report_no];
01061
01062 tab->file->report_ptr = g_new0 (QlReportInfo, 1);
01063 tab->file->report_ptr->last_column = -1;
01064 tab->file->report_ptr->sort = -1;
01065 tab->file->report_ptr->filter = -1;
01066
01067 report_dlg = gtk_dialog_new ();
01068 gtk_window_set_modal (GTK_WINDOW (report_dlg), TRUE);
01069 gtk_window_set_position (GTK_WINDOW (report_dlg), GTK_WIN_POS_CENTER);
01070 gtk_window_set_resizable (GTK_WINDOW (report_dlg), TRUE);
01071 gtk_container_set_border_width (GTK_CONTAINER (report_dlg), 5);
01072
01073 gtk_window_set_title (GTK_WINDOW (report_dlg),
01074 _("New report"));
01075 top_vbox = GTK_DIALOG (report_dlg)->vbox;
01076 gtk_box_set_spacing (GTK_BOX (top_vbox), 10);
01077 hbox6 = GTK_DIALOG (report_dlg)->action_area;
01078
01079
01080 hbox1 = gtk_hbox_new (FALSE, 5);
01081 name_label = gtk_label_new (_("Please enter a report name"));
01082 gtk_box_pack_start (GTK_BOX (hbox1), name_label, FALSE, FALSE, 0);
01083
01084 entry1 = gtk_entry_new ();
01085 gtk_box_pack_start (GTK_BOX (hbox1), entry1, TRUE, TRUE, 0);
01086 gtk_box_pack_start (GTK_BOX (top_vbox), hbox1, FALSE, FALSE, 0);
01087
01088
01089
01090 hbox2 = gtk_hbox_new (FALSE, 5);
01091 gtk_box_pack_start (GTK_BOX (top_vbox), hbox2, TRUE, TRUE, 0);
01092
01093 treeview = GTK_TREE_VIEW (gtk_tree_view_new ());
01094 model = gtk_tree_view_get_model (treeview);
01095 treestore = gtk_tree_store_new (SINGLE_COL, G_TYPE_STRING);
01096
01097 sort = GTK_TREE_SORTABLE (treestore);
01098 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
01099 GTK_TREE_MODEL (sort));
01100 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
01101 gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
01102 gtk_tree_store_append (treestore, &parent_iter, NULL);
01103
01104 gtk_tree_store_set (treestore, &parent_iter, REPORT_COL,
01105 _("Available columns"), -1);
01106 renderer = gtk_cell_renderer_text_new ();
01107 column = gtk_tree_view_column_new_with_attributes
01108 (_("Column Name"), renderer, "text", REPORT_COL, NULL);
01109 gtk_tree_view_column_set_sort_column_id (column, REPORT_COL);
01110 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
01111 rselect = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
01112 gtk_tree_selection_set_mode (rselect, GTK_SELECTION_SINGLE);
01113 scrwin_to = gtk_scrolled_window_new (NULL, NULL);
01114 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrwin_to),
01115 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
01116 gtk_container_set_border_width (GTK_CONTAINER (scrwin_to), 5);
01117 gtk_box_pack_start (GTK_BOX (hbox2), scrwin_to, TRUE, TRUE, 0);
01118 gtk_container_add (GTK_CONTAINER (scrwin_to),
01119 GTK_WIDGET(treeview));
01120 g_object_set_data (G_OBJECT(report_dlg), QLTABID, tab);
01121
01122 ok_button = gtk_button_new_from_stock (GTK_STOCK_OK);
01123 gtk_box_pack_start (GTK_BOX (hbox6), ok_button, TRUE, TRUE, 0);
01124 g_signal_connect (GTK_OBJECT (ok_button), "clicked",
01125 G_CALLBACK (add_ok), report_dlg);
01126
01127 cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
01128 gtk_box_pack_start (GTK_BOX (hbox6), cancel_button, TRUE, TRUE, 0);
01129 g_signal_connect (GTK_OBJECT (cancel_button), "clicked",
01130 G_CALLBACK (report_add_cancel), report_dlg);
01131 g_signal_connect (GTK_OBJECT (report_dlg),
01132 "delete_event", G_CALLBACK (report_add_cancel), report_dlg);
01133
01134 newrow[1] = NULL;
01135 for (colx = 0; colx <= tab->file->last_field; colx++)
01136 {
01137 QlFieldInfo * field;
01138 fieldx = tab->file->col_to_field[colx];
01139 field = ql_get_fieldinfo (tab, fieldx);
01140 newrow[0] = field->name;
01141 gtk_tree_store_append (treestore, &child_iter, &parent_iter);
01142 gtk_tree_store_set (treestore, &child_iter, REPORT_COL,
01143 newrow[0], -1);
01144 width = (strlen(newrow[0]) > width) ?
01145 strlen(newrow[0]) : width;
01146 }
01147 gtk_widget_set_size_request (GTK_WIDGET(treeview),
01148 width + 200, 200);
01149 gtk_tree_view_expand_all (GTK_TREE_VIEW(treeview));
01150 gtk_widget_show_all (report_dlg);
01151 }
01152
01153
01154 void
01155 report_col_add (GtkAction G_GNUC_UNUSED * w, gpointer data)
01156 {
01157 gint colx, fieldx;
01158 guint width;
01159 GtkWidget *top_vbox;
01160 GtkWidget *hbox2;
01161 GtkTreeView * treeview;
01162 GtkTreeModel * model;
01163 GtkTreeStore * treestore;
01164 GtkTreeIter parent_iter, child_iter;
01165 GtkCellRenderer *renderer;
01166 GtkTreeViewColumn *column;
01167 GtkTreeSortable * sort;
01168 GtkTreeSelection * rselect;
01169 GtkWidget *hbox6;
01170 GtkWidget *done_button;
01171 GtkWidget * report_dlg;
01172 QlContext * qlc;
01173 QlTabData * tab;
01174
01175 qlc = ql_get_context (GTK_WIDGET(data));
01176 tab = ql_get_tabdata (qlc);
01177 width = 0;
01178 report_dlg = gtk_dialog_new ();
01179 gtk_window_set_modal (GTK_WINDOW (report_dlg), TRUE);
01180 gtk_window_set_position (GTK_WINDOW (report_dlg), GTK_WIN_POS_CENTER);
01181 gtk_window_set_resizable (GTK_WINDOW (report_dlg), TRUE);
01182 gtk_container_set_border_width (GTK_CONTAINER (report_dlg), 5);
01183
01184 gtk_window_set_title (GTK_WINDOW (report_dlg),
01185 _("Add columns to report"));
01186 top_vbox = GTK_DIALOG (report_dlg)->vbox;
01187 gtk_box_set_spacing (GTK_BOX (top_vbox), 10);
01188 hbox6 = GTK_DIALOG (report_dlg)->action_area;
01189
01190
01191
01192 hbox2 = gtk_hbox_new (FALSE, 5);
01193 gtk_box_pack_start (GTK_BOX (top_vbox), hbox2, TRUE, TRUE, 0);
01194
01195
01197 treeview = GTK_TREE_VIEW (gtk_tree_view_new ());
01198 model = gtk_tree_view_get_model (treeview);
01199 treestore = gtk_tree_store_new (SINGLE_COL, G_TYPE_STRING);
01200 sort = GTK_TREE_SORTABLE (treestore);
01201 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
01202 GTK_TREE_MODEL (sort));
01203 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
01204 gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
01205 gtk_tree_store_append (treestore, &parent_iter, NULL);
01206 gtk_tree_store_set (treestore, &parent_iter, FROM_COL,
01207 _("Available columns"), -1);
01208 renderer = gtk_cell_renderer_text_new ();
01209 column = gtk_tree_view_column_new_with_attributes
01210 (_("Column Name"), renderer, "text", FROM_COL, NULL);
01211 gtk_tree_view_column_set_sort_column_id (column, FROM_COL);
01212 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
01213 rselect = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
01214 gtk_tree_selection_set_mode (rselect, GTK_SELECTION_SINGLE);
01215
01216
01217 done_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
01218 gtk_box_pack_start (GTK_BOX (hbox6), done_button, TRUE, TRUE, 0);
01219 g_signal_connect (GTK_OBJECT (done_button), "clicked",
01220 G_CALLBACK (gtk_widget_destroy), report_dlg);
01221
01222 g_signal_connect (GTK_OBJECT (report_dlg),
01223 "delete_event", G_CALLBACK (report_dlg_cancel), report_dlg);
01224
01225 newrow[1] = NULL;
01226 for (colx = 0; colx <= tab->file->last_field; colx++)
01227 {
01228 QlFieldInfo * field;
01230 fieldx = tab->file->col_to_field[colx];
01231 field = ql_get_fieldinfo (tab, fieldx);
01232 newrow[0] = field->name;
01233 gtk_tree_store_append (treestore, &child_iter, &parent_iter);
01234 gtk_tree_store_set (treestore, &child_iter, FROM_COL,
01235 newrow[0], -1);
01236 width = (strlen(newrow[0]) > width) ?
01237 strlen(newrow[0]) : width;
01238 }
01239 gtk_widget_set_size_request (GTK_WIDGET(treeview),
01240 width + 200, 200);
01241 gtk_tree_view_expand_all (GTK_TREE_VIEW(treeview));
01242
01243 gtk_widget_show_all (report_dlg);
01244 }
01245
01246 static void
01247 swap_columns (QlTabData * tab, gint from, gint to)
01248 {
01249 QlReportColumn temp_column;
01250
01251 temp_column = tab->file->report_ptr->column[from];
01252 tab->file->report_ptr->column[from] = tab->file->report_ptr->column[to];
01253 tab->file->report_ptr->column[to] = temp_column;
01254
01255 display_column (tab, from);
01256 display_column (tab, to);
01257 report_set_col_field (tab, to);
01258 gtk_sheet_select_column (tab->view->report_sheet, to);
01259 dim_all_menus (tab->qlc);
01260 }
01261
01262 void
01263 report_col_left (GtkAction G_GNUC_UNUSED * w, gpointer data)
01264 {
01265 QlContext * qlc;
01266 QlTabData * tab;
01267
01268 qlc = ql_get_context (GTK_WIDGET(data));
01269 tab = ql_get_tabdata (qlc);
01270 swap_columns (tab, tab->view->report_sel_col, tab->view->report_sel_col - 1);
01271 }
01272
01273 void
01274 report_col_right (GtkAction G_GNUC_UNUSED * w, gpointer data)
01275 {
01276 QlContext * qlc;
01277 QlTabData * tab;
01278
01279 qlc = ql_get_context (GTK_WIDGET(data));
01280 tab = ql_get_tabdata (qlc);
01281 swap_columns (tab, tab->view->report_sel_col, tab->view->report_sel_col + 1);
01282 }
01283
01284
01285 void
01286 report_go_to (QlTabData * tab, gint row0, gint rowi, gint col0, gint coli)
01287 {
01288 GtkSheetRange range;
01289 range.col0 = col0;
01290 range.coli = coli;
01291 range.row0 = row0;
01292 range.rowi = rowi;
01293 gtk_sheet_select_range (tab->view->report_sheet, &range);
01294 }
01295
01296 void
01297 report_col_del (GtkAction G_GNUC_UNUSED * w, gpointer data)
01298 {
01299 gint colx;
01300 gint this_col;
01301 QlContext * qlc;
01302 QlTabData * tab;
01303
01304 qlc = ql_get_context (GTK_WIDGET(data));
01305 tab = ql_get_tabdata (qlc);
01306 this_col = tab->view->report_sel_col;
01307
01308 gtk_sheet_delete_columns (tab->view->report_sheet,
01309 this_col, 1);
01310
01312
01313 for (colx = this_col; colx < tab->file->report_ptr->last_column; colx++)
01314 tab->file->report_ptr->column[colx] =
01315 tab->file->report_ptr->column[colx + 1];
01316 tab->file->report_ptr->last_column--;
01317 if (this_col > tab->file->report_ptr->last_column)
01318 this_col = tab->file->report_ptr->last_column;
01319 report_go_to (tab, 0, 0, this_col, this_col);
01320 }
01321
01324 static void
01325 select_ok (GtkButton G_GNUC_UNUSED * button, gpointer data)
01326 {
01327 GtkTreeSelection *selection;
01328 GtkTreeIter iter;
01329 GtkTreeModel *model;
01330 gchar * report_name;
01331 gint reportx;
01332 QlTabData * tab;
01333
01334 selection = GTK_TREE_SELECTION(data);
01335 tab = (QlTabData*)g_object_get_data (G_OBJECT(selection), QLTABID);
01336 if (gtk_tree_selection_get_selected (selection, &model, &iter))
01337 {
01338 reportx = -1;
01339 gtk_tree_model_get (model, &iter, REPORT_COL, &report_name, -1);
01340 for (reportx = 0; reportx < tab->file->report_ct; reportx++)
01341 {
01342 if (0 == strcmp (tab->file->reports[reportx].name, report_name))
01343 {
01344 tab->file->report_no = reportx;
01345 }
01346 }
01347 if (tab->file->report_no < 0)
01348 return;
01349 tab->file->report_ptr = &tab->file->reports[tab->file->report_no];
01350 if (tab->file->report_ptr->sort >= 0)
01351 sort_do_it (tab, tab->file->report_ptr->sort);
01352 filter_do_apply (tab, tab->file->report_ptr->filter);
01353 get_window_size_loc (tab->qlc->parent);
01354 html_on_screen (tab);
01355 gtk_widget_destroy (select_dlg);
01356 }
01357 }
01358
01361 void
01362 report_select (GtkAction G_GNUC_UNUSED * w, gpointer data)
01363 {
01364 gint reportx;
01365 guint width;
01366 GtkWidget *top_vbox;
01367 GtkWidget *hbox2;
01368 GtkWidget *scrwin_from;
01369 GtkTreeStore * treestore;
01370 GtkTreeIter parent_iter, child_iter;
01371 GtkCellRenderer *renderer;
01372 GtkTreeViewColumn *column;
01373 GtkTreeView * treeview;
01374 GtkTreeModel * treemodel;
01375 GtkTreeSortable * sort;
01376 GtkTreeSelection * rselect;
01377 GtkWidget *hbox6;
01378 GtkWidget *cancel_button, * ok_button;
01379 QlContext * qlc;
01380 QlTabData * tab;
01381
01382 qlc = ql_get_context (GTK_WIDGET(data));
01383 tab = ql_get_tabdata (qlc);
01384
01385 g_return_if_fail (tab);
01386 CHECK_CHANGED(tab);
01387 select_dlg = gtk_dialog_new ();
01388 gtk_window_set_modal (GTK_WINDOW (select_dlg), TRUE);
01389 gtk_window_set_position (GTK_WINDOW (select_dlg), GTK_WIN_POS_CENTER);
01390 gtk_window_set_resizable (GTK_WINDOW (select_dlg), TRUE);
01391 gtk_container_set_border_width (GTK_CONTAINER (select_dlg), 5);
01392
01393 width = 0;
01394 gtk_window_set_title (GTK_WINDOW (select_dlg), _("Select a report"));
01395 top_vbox = GTK_DIALOG (select_dlg)->vbox;
01396 gtk_box_set_spacing (GTK_BOX (top_vbox), 10);
01397 hbox6 = GTK_DIALOG (select_dlg)->action_area;
01398
01399 treeview = GTK_TREE_VIEW(gtk_tree_view_new ());
01400 treemodel = gtk_tree_view_get_model (treeview);
01401
01402 treestore = gtk_tree_store_new (SINGLE_COL, G_TYPE_STRING);
01403 sort = GTK_TREE_SORTABLE (treestore);
01404 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
01405 GTK_TREE_MODEL (sort));
01406 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
01407 gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
01408 gtk_tree_store_append (treestore, &parent_iter, NULL);
01409 gtk_tree_store_set (treestore, &parent_iter, REPORT_COL,
01410 _("Available reports"), -1);
01411 renderer = gtk_cell_renderer_text_new ();
01412 column = gtk_tree_view_column_new_with_attributes
01413 (_("Report Name"), renderer, "text", REPORT_COL, NULL);
01414 gtk_tree_view_column_set_sort_column_id (column, REPORT_COL);
01415 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
01416
01417 hbox2 = gtk_hbox_new (FALSE, 5);
01418 gtk_box_pack_start (GTK_BOX (top_vbox), hbox2, TRUE, TRUE, 0);
01419
01420
01421 scrwin_from = gtk_scrolled_window_new (NULL, NULL);
01422 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrwin_from),
01423 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
01424 gtk_container_set_border_width (GTK_CONTAINER (scrwin_from), 5);
01425 gtk_box_pack_start (GTK_BOX (hbox2), scrwin_from, TRUE, TRUE, 0);
01426 gtk_container_add (GTK_CONTAINER (scrwin_from),
01427 GTK_WIDGET(treeview));
01428
01429 ok_button = gtk_button_new_from_stock (GTK_STOCK_OK);
01430 rselect = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
01431 gtk_tree_selection_set_mode (rselect, GTK_SELECTION_SINGLE);
01432 g_object_set_data (G_OBJECT(rselect), QLTABID, tab);
01433 g_signal_connect (G_OBJECT (ok_button), "clicked",
01434 G_CALLBACK (select_ok), rselect);
01435 gtk_window_set_resizable (GTK_WINDOW(select_dlg), TRUE);
01436 cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
01437 gtk_box_pack_start (GTK_BOX (hbox6), ok_button, TRUE, TRUE, 0);
01438 gtk_box_pack_start (GTK_BOX (hbox6), cancel_button, TRUE, TRUE, 0);
01439 g_signal_connect (GTK_OBJECT (cancel_button), "clicked",
01440 G_CALLBACK (report_dlg_cancel), select_dlg);
01441 g_signal_connect (GTK_OBJECT (select_dlg), "delete_event",
01442 G_CALLBACK(report_dlg_cancel), select_dlg);
01443
01445 newrow[1] = NULL;
01446 for (reportx = 0; reportx < tab->file->report_ct; reportx++)
01447 {
01448 newrow[0] = tab->file->reports[reportx].name;
01449 gtk_tree_store_append (treestore, &child_iter, &parent_iter);
01450 gtk_tree_store_set (treestore, &child_iter, REPORT_COL,
01451 newrow[0], -1);
01452 width = (strlen(newrow[0]) > width) ?
01453 strlen(newrow[0]) : width;
01454 }
01455 gtk_widget_set_size_request (GTK_WIDGET(treeview),
01456 width + 200, 200);
01457 gtk_tree_view_expand_all (GTK_TREE_VIEW(treeview));
01458 gtk_widget_show_all (select_dlg);
01459 }
01460
01462 void
01463 report_totals_group (GtkAction G_GNUC_UNUSED * w, gpointer data)
01464 {
01465 QlContext * qlc;
01466 QlTabData * tab;
01467
01468 qlc = ql_get_context (GTK_WIDGET(data));
01469 tab = ql_get_tabdata (qlc);
01470 tab->file->report_ptr->column[tab->view->report_sel_col].group =
01471 !tab->file->report_ptr->column[tab->view->report_sel_col].group;
01472 display_column (tab, tab->view->report_sel_col);
01473 }
01474
01476 void
01477 report_totals_total (GtkAction G_GNUC_UNUSED * w, gpointer data)
01478 {
01479 QlContext * qlc;
01480 QlTabData * tab;
01481
01482 qlc = ql_get_context (GTK_WIDGET(data));
01483 tab = ql_get_tabdata (qlc);
01484 tab->file->report_ptr->column[tab->view->report_sel_col].total =
01485 !tab->file->report_ptr->column[tab->view->report_sel_col].total;
01486 display_column (tab, tab->view->report_sel_col);
01487 }
01488
01489
01491 static G_GNUC_UNUSED void
01492 to_clicked (GtkWidget G_GNUC_UNUSED * widget, gint G_GNUC_UNUSED rrow,
01493 gint G_GNUC_UNUSED col, GdkEventButton * event, gpointer G_GNUC_UNUSED data)
01494 {
01495
01496 if (event->type != GDK_2BUTTON_PRESS)
01497 return;
01498
01499
01500
01501
01502
01503 }