00001
00002
00003
00004
00005
00006
00007
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "config.h"
00030
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <glib.h>
00034 #include <gtk/gtk.h>
00035 #include <glib/gi18n.h>
00036 #include <gtkextra/gtksheet.h>
00037 #include <monetary.h>
00038 #include "types.h"
00039 #include "dialog_initial.h"
00040 #include "dim_list_menu.h"
00041 #include "filein.h"
00042 #include "main.h"
00043
00044
00045 static QlFieldInfo * field_db_start;
00046 static QlFieldInfo * field_db_curr;
00047 static GtkWidget *done_button;
00049 static gboolean displaying;
00050 static GtkWidget * text_button;
00051 static GtkWidget * numeric_button;
00052 static GtkWidget * date_button;
00053 static GtkWidget * time_button;
00054 static GtkWidget * left_button;
00055 static GtkWidget * center_button;
00056 static GtkWidget * right_button;
00057 static GtkWidget * column_name_entry;
00058 static GtkWidget * decimal_places_entry;
00059 static GtkWidget * entry_dialogue;
00060
00087 static G_GNUC_UNUSED gchar * num_formats[] = {
00088 "1,234.56",
00089 "1.234,56",
00090 "1234.56",
00091 "1234,56",
00092 "$1,234.56",
00093 "1,234.56%",
00094 "1.234,56%",
00095 NULL
00096 };
00097
00098 static void
00099 cancel_clicked (GtkObject G_GNUC_UNUSED * object, gpointer G_GNUC_UNUSED entry)
00100 {
00101 gtk_widget_destroy (entry_dialogue);
00102 }
00103
00104 static void
00105 done_clicked (GtkObject G_GNUC_UNUSED * object, gpointer data)
00106 {
00107 QlTabData * tab = (QlTabData*)data;
00108 g_return_if_fail (tab);
00109 if (tab->file->last_field < 0)
00110 return;
00111 gtk_widget_destroy (entry_dialogue);
00112 build_basic_list_mode (tab);
00113 tab->view->display_mode = DISPLAY_LIST;
00114 add1row (tab);
00115 dim_all_menus (tab->qlc);
00116 gtk_widget_show_all (tab->qlc->parent);
00117 connect_signals (tab);
00118 }
00119
00120 static void
00121 just_clicked (GtkObject G_GNUC_UNUSED * object, gpointer entry)
00122 {
00123 field_db_curr->justification = GPOINTER_TO_INT (entry);
00124 }
00125
00126 static void
00127 sm_formatting_changed (GtkObject G_GNUC_UNUSED * object,
00128 gpointer G_GNUC_UNUSED entry)
00129 {
00130 field_db_curr->formatting =
00131 gtk_combo_box_get_active (GTK_COMBO_BOX (object));
00132 }
00133
00135 static void
00136 update_field_db (QlTabData * tab)
00137 {
00138 gchar linebuf[20];
00139 const gchar *text;
00140
00141 displaying = TRUE;
00142
00143 text = gtk_entry_get_text (GTK_ENTRY (column_name_entry));
00144 if (text && strlen (text) > 0)
00145 field_db_curr->name = g_strdup(text);
00146 gtk_entry_set_text (GTK_ENTRY (column_name_entry), field_db_curr->name);
00147
00148 if (tab->view->dialog_mode != MODE_EDIT)
00149 gtk_editable_select_region (GTK_EDITABLE (column_name_entry), 0,
00150 strlen (field_db_curr->name));
00151 gtk_widget_hide (GTK_WIDGET (tab->view->sm_numeric_box));
00152 gtk_widget_hide (tab->view->dec_places_label);
00153 gtk_widget_hide (decimal_places_entry);
00154 gtk_widget_hide (GTK_WIDGET (tab->view->sm_date_box));
00155 gtk_widget_hide (GTK_WIDGET (tab->view->sm_time_box));
00156
00157 switch (field_db_curr->type)
00158 {
00159 case FIELD_TYPE_TEXT:
00160 {
00161 gtk_toggle_button_set_active
00162 (GTK_TOGGLE_BUTTON (text_button), TRUE);
00163 break;
00164 }
00165 case FIELD_TYPE_NUMERIC:
00166 {
00167 gtk_toggle_button_set_active
00168 (GTK_TOGGLE_BUTTON (numeric_button), TRUE);
00169 gtk_combo_box_set_active (tab->view->sm_numeric_box,
00170 field_db_curr->formatting);
00171 if (field_db_curr->decimal_places >= 0 &&
00172 field_db_curr->decimal_places < 10)
00173 sprintf (linebuf, "%u", field_db_curr->decimal_places);
00174 else
00175 strcpy (linebuf, "0");
00176
00177 gtk_entry_set_text (GTK_ENTRY (decimal_places_entry), linebuf);
00178 gtk_widget_show (GTK_WIDGET (tab->view->sm_numeric_box));
00179 gtk_widget_show (tab->view->dec_places_label);
00180 gtk_widget_show (decimal_places_entry);
00181 break;
00182 }
00183 case FIELD_TYPE_DATE:
00184 {
00185 gtk_toggle_button_set_active
00186 (GTK_TOGGLE_BUTTON (date_button), TRUE);
00187 gtk_combo_box_set_active (tab->view->sm_date_box,
00188 field_db_curr->formatting);
00189 gtk_widget_show (GTK_WIDGET (tab->view->sm_date_box));
00190 break;
00191 }
00192 case FIELD_TYPE_TIME:
00193 {
00194 gtk_toggle_button_set_active
00195 (GTK_TOGGLE_BUTTON (time_button), TRUE);
00196 gtk_combo_box_set_active (tab->view->sm_time_box,
00197 field_db_curr->formatting);
00198 gtk_widget_show (GTK_WIDGET (tab->view->sm_time_box));
00199 break;
00200 }
00201 }
00202 switch (field_db_curr->justification)
00203 {
00204 case GTK_JUSTIFY_LEFT:
00205 {
00206 gtk_toggle_button_set_active
00207 (GTK_TOGGLE_BUTTON (left_button), TRUE);
00208 break;
00209 }
00210 case GTK_JUSTIFY_CENTER:
00211 {
00212 gtk_toggle_button_set_active
00213 (GTK_TOGGLE_BUTTON (center_button), TRUE);
00214 break;
00215 }
00216 case GTK_JUSTIFY_RIGHT:
00217 {
00218 gtk_toggle_button_set_active
00219 (GTK_TOGGLE_BUTTON (right_button), TRUE);
00220 break;
00221 }
00222 }
00223 if (tab->view->dialog_mode == MODE_NEW && tab->file->last_field >= 0)
00224 gtk_widget_show (done_button);
00225
00226 gtk_widget_grab_focus (GTK_WIDGET (column_name_entry));
00227 displaying = FALSE;
00228 }
00229
00230 static void
00231 type_clicked (GtkObject G_GNUC_UNUSED * object, gpointer data)
00232 {
00233 QlTabData * tab;
00234
00235 if (displaying)
00236 return;
00237
00238 tab = (QlTabData*) g_object_get_data (G_OBJECT(entry_dialogue), QLTABID);
00239 g_return_if_fail (tab);
00240 field_db_curr->type = GPOINTER_TO_INT (data);
00241 field_db_curr->formatting = 0;
00242 if (field_db_curr->type == FIELD_TYPE_TEXT)
00243 field_db_curr->justification = GTK_JUSTIFY_LEFT;
00244 else
00245 field_db_curr->justification = GTK_JUSTIFY_RIGHT;
00246 update_field_db (tab);
00247 }
00248
00249 static gchar *
00250 get_datestamp (const gchar * format)
00251 {
00252 GTimeVal tv;
00253 GDate * gd;
00254 gchar * d;
00255
00256 if (!format)
00257 return NULL;
00258 gd = g_date_new ();
00259 g_get_current_time (&tv);
00260 g_date_set_time_val (gd, &tv);
00261 d = display_date (gd, format);
00262 g_date_free (gd);
00263 return d;
00264 }
00265
00266 static gchar *
00267 get_timestamp (const gchar * format)
00268 {
00269 GTimeVal tv;
00270 gchar * d;
00271
00272 if (!format)
00273 return NULL;
00274 g_get_current_time (&tv);
00275 d = display_time (&tv, format);
00276 return d;
00277 }
00278
00284 static gchar *
00285 display_currency (gdouble number, QlCurrFormat qc)
00286 {
00287 gchar buf[MAX_DATE_BUFFER];
00288 gsize len;
00289 gchar * format;
00290
00291 format = NULL;
00292 switch (qc)
00293 {
00294
00295 case QL_NF_GRP : { format = g_strdup("%!i"); break; }
00296
00297 case QL_NF : { format = g_strdup("%^!i"); break; }
00298
00299 case QL_NF_CURR : { format = g_strdup("%n"); break; }
00300
00301 case QL_NF_PERCENT : { format = g_strdup ("%!i%%"); break; }
00302
00303
00304
00305 default : break;
00306 }
00307 if (!format)
00308 return NULL;
00309 buf[0] = '\1';
00310 len = strfmon (buf, MAX_DATE_BUFFER, format, number);
00311 g_free (format);
00312 if (len <= 0 && buf[0] != '\0')
00313 return NULL;
00314 return g_strdup (buf);
00315 }
00316
00318 static GtkWidget *
00319 sub_menus (QlTabData * tab)
00320 {
00321 GtkWidget *sub_menu_box;
00322 gint subx;
00323
00324
00325
00326 sub_menu_box = gtk_hbox_new (FALSE, 5);
00327 gtk_widget_show (sub_menu_box);
00328
00329
00330 subx = 0;
00331 tab->view->sm_numeric_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
00332 for (subx = 0; subx < QL_NF_LAST; subx++)
00333 {
00334 gchar * nstr = display_currency(1234.56, subx);
00335 if (!nstr)
00336 continue;
00337 gtk_combo_box_insert_text (tab->view->sm_numeric_box, subx, nstr);
00338 }
00339 g_signal_connect (GTK_OBJECT (tab->view->sm_numeric_box), "changed",
00340 G_CALLBACK (sm_formatting_changed), &subx);
00341 gtk_box_pack_start (GTK_BOX (sub_menu_box),
00342 GTK_WIDGET (tab->view->sm_numeric_box), FALSE, FALSE, 0);
00343
00344 decimal_places_entry = gtk_spin_button_new_with_range (0,9,1);
00345 gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON(decimal_places_entry), TRUE);
00346 gtk_box_pack_end (GTK_BOX (sub_menu_box), decimal_places_entry, FALSE, FALSE,
00347 0);
00348 tab->view->dec_places_label = gtk_label_new (_("Decimal places"));
00349 gtk_box_pack_end (GTK_BOX (sub_menu_box), tab->view->dec_places_label,
00350 FALSE, FALSE, 0);
00351
00352
00353 tab->view->sm_date_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
00354 subx = 0;
00355 for (subx = 0; subx < QL_DF_LAST; subx++)
00356 {
00357 gtk_combo_box_insert_text (tab->view->sm_date_box, subx,
00358 get_datestamp(convert_old_df(subx)));
00359 }
00360 g_signal_connect (GTK_OBJECT (tab->view->sm_date_box), "changed",
00361 G_CALLBACK (sm_formatting_changed), NULL);
00362 gtk_box_pack_start (GTK_BOX (sub_menu_box),
00363 GTK_WIDGET (tab->view->sm_date_box), FALSE, FALSE, 0);
00364
00365
00366 tab->view->sm_time_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
00367 subx = 0;
00368 for (subx = 0; subx < QL_TF_LAST; subx++)
00369 {
00370 gtk_combo_box_insert_text (tab->view->sm_time_box, subx,
00371 get_timestamp(convert_old_tf(subx)));
00372 }
00373 g_signal_connect (GTK_OBJECT (tab->view->sm_time_box), "changed",
00374 G_CALLBACK (sm_formatting_changed), NULL);
00375
00376 gtk_box_pack_start (GTK_BOX (sub_menu_box),
00377 GTK_WIDGET (tab->view->sm_time_box), FALSE, FALSE, 0);
00378 return sub_menu_box;
00379 }
00380
00383 static void
00384 new_std_field (QlTabData * tab)
00385 {
00386 gtk_entry_set_text (GTK_ENTRY (column_name_entry), "");
00387
00388 field_db_curr->name = g_strdup_printf (_("Column %u"),
00389 tab->file->last_field + 2);
00390 field_db_curr->sheet_column = tab->file->last_field + 1;
00391 field_db_curr->type = FIELD_TYPE_TEXT;
00392 field_db_curr->formatting = 0;
00393 field_db_curr->decimal_places = 0;
00394 field_db_curr->justification = GTK_JUSTIFY_LEFT;
00395 field_db_curr->width = 10;
00396 }
00397
00398 static void
00399 add_column_cb (gpointer G_GNUC_UNUSED field_index, gpointer field_ptr, gpointer user_data)
00400 {
00401 gint sheet_column;
00402 QlFieldInfo * field = (QlFieldInfo*)field_ptr;
00403 sheet_column = GPOINTER_TO_INT (user_data);
00404 if (field->sheet_column >= sheet_column)
00405 field->sheet_column++;
00406 }
00407
00414 static void
00415 ok_clicked (GtkObject G_GNUC_UNUSED * object, gpointer data)
00416 {
00417 gint fieldx;
00418 gint sheetx;
00419 gint rowx;
00420 const gchar *text;
00421 gchar *tmp;
00422 GtkSheetRange range;
00423 gdouble temp_double;
00424 gchar linebuf[48];
00425 QlTabData * tab;
00426
00427 tab = (QlTabData*)data;
00428 g_return_if_fail (tab);
00429 text = gtk_entry_get_text (GTK_ENTRY (column_name_entry));
00430 tmp = g_strdup (text);
00431 if (check_entry (tab, tmp))
00432 return;
00433 g_free (tmp);
00434 field_db_curr->name = g_strdup(text);
00435
00436 if (field_db_curr->type == FIELD_TYPE_NUMERIC)
00437 {
00438 field_db_curr->decimal_places = gtk_spin_button_get_value_as_int
00439 (GTK_SPIN_BUTTON(decimal_places_entry));
00440 }
00441
00442
00443 if (tab->view->dialog_mode == MODE_ADD)
00444 {
00445 field_db_curr->sheet_column = sheetx = tab->view->sel_range.col0;
00446 ql_fieldinfo_foreach (tab, add_column_cb, GINT_TO_POINTER (sheetx));
00447
00448 fieldx = ++tab->file->last_field;
00449 big_draw_start (tab);
00450 ql_add_fieldinfo (tab, field_db_curr);
00451
00452
00453 gtk_sheet_insert_columns (tab->view->sheet, sheetx, 1);
00454 gtk_sheet_set_column_width (tab->view->sheet, sheetx,
00455 field_db_curr->width * 8);
00456 gtk_sheet_column_button_add_label (tab->view->sheet,
00457 sheetx, field_db_curr->name);
00458 gtk_sheet_column_set_justification (tab->view->sheet,
00459 sheetx, field_db_curr->justification);
00460
00461 reset_col_to_field (tab);
00462 big_draw_end (tab);
00463 front_is_changed (tab);
00464 return;
00465 }
00466
00467
00468 else if (tab->view->dialog_mode == MODE_EDIT)
00469 {
00470 QlFieldInfo * field;
00471 sheetx = tab->view->sel_range.col0;
00472 field = ql_get_fieldinfo (tab, sheetx);
00473 field = field_db_curr;
00474 gtk_sheet_column_button_add_label (tab->view->sheet,
00475 sheetx, field_db_curr->name);
00476 big_draw_start (tab);
00477 if (field_db_curr->justification != field_db_start->justification)
00478 {
00479 gtk_sheet_column_set_justification (tab->view->sheet,
00480 sheetx, field_db_curr->justification);
00481 range.row0 = 0;
00482 range.rowi = tab->file->last_row;
00483 range.col0 = range.coli = sheetx;
00484 gtk_sheet_range_set_justification (tab->view->sheet,
00485 &range, field_db_curr->justification);
00486 }
00487
00488
00489 if (field_db_curr->type == FIELD_TYPE_TEXT ||
00490 !tab->file->last_row)
00491 {
00492 big_draw_end (tab);
00493 front_is_changed (tab);
00494 return;
00495 }
00496 if (field_db_curr->type != FIELD_TYPE_TEXT &&
00497 (field_db_start->type != field_db_curr->type ||
00498 field_db_start->formatting != field_db_curr->formatting ||
00499 field_db_start->decimal_places !=
00500 field_db_curr->decimal_places))
00501 {
00502
00503
00505 if (field_db_start->type == FIELD_TYPE_TEXT)
00506 field_db_start->formatting = field_db_curr->formatting;
00507 for (rowx = 0; rowx < tab->file->last_row; rowx++)
00508 {
00509 text = gtk_sheet_cell_get_text (tab->view->sheet,
00510 rowx, sheetx);
00511 if (text)
00512 {
00513 temp_double = qls2d (text, field_db_curr->type,
00514 field_db_start->formatting);
00515 d2qls (linebuf, temp_double, field_db_curr->type,
00516 field_db_curr->formatting,
00517 field_db_curr->decimal_places);
00518 gtk_sheet_set_cell_text (tab->view->sheet,
00519 rowx, sheetx, linebuf);
00520 }
00521 }
00522 }
00523 big_draw_end (tab);
00524 front_is_changed (tab);
00525 return;
00526 }
00527
00528
00529 fieldx = sheetx = ++tab->file->last_field;
00530 ql_add_fieldinfo (tab, field_db_curr);
00531 reset_col_to_field (tab);
00532 new_std_field (tab);
00533 field_db_start = field_db_curr;
00534 update_field_db (tab);
00535 }
00536
00537 static void
00538 swap_columns (QlTabData * tab, gint tocol, gint from)
00539 {
00540 QlFieldInfo * fieldto, * fieldfrom;
00541 gchar *textfromp;
00542 gchar *texttop;
00543 gchar textfrom[1024];
00544 gint from_justification;
00545 gint to_justification;
00546 gint rowx;
00547 gint to_sheet_col;
00548
00549 big_draw_start (tab);
00550 fieldfrom = ql_get_fieldinfo (tab, from);
00551 fieldto = ql_get_fieldinfo (tab, tocol);
00552 from_justification = fieldfrom->justification;
00553 to_justification = fieldto->justification;
00554 to_sheet_col = fieldto->sheet_column;
00555 fieldto->sheet_column = fieldfrom->sheet_column;
00556 fieldfrom->sheet_column = to_sheet_col;
00557
00558 gtk_sheet_set_column_width (tab->view->sheet, from, fieldto->width * 8);
00559 gtk_sheet_set_column_width (tab->view->sheet, tocol, fieldfrom->width * 8);
00560 gtk_sheet_column_button_add_label (tab->view->sheet, from, fieldto->name);
00561 gtk_sheet_column_button_add_label (tab->view->sheet, tocol,
00562 fieldfrom->name);
00563 gtk_sheet_column_set_justification (tab->view->sheet, from,
00564 fieldto->justification);
00565 gtk_sheet_column_set_justification (tab->view->sheet, tocol,
00566 fieldfrom->justification);
00567
00568 reset_col_to_field (tab);
00569
00570
00571 for (rowx = 0; rowx <= tab->file->last_row; rowx++)
00572 {
00573 textfromp = gtk_sheet_cell_get_text (tab->view->sheet,
00574 rowx, from);
00575 if (textfromp)
00576 strcpy (textfrom, textfromp);
00577
00578
00579 texttop = gtk_sheet_cell_get_text (tab->view->sheet,
00580 rowx, tocol);
00581 if (texttop)
00582 gtk_sheet_set_cell (tab->view->sheet, rowx, from,
00583 to_justification, texttop);
00584 else
00585 gtk_sheet_cell_clear (tab->view->sheet, rowx, from);
00586
00587
00588 if (textfromp)
00589 gtk_sheet_set_cell (tab->view->sheet, rowx, tocol,
00590 from_justification, textfrom);
00591 else
00592 gtk_sheet_cell_clear (tab->view->sheet, rowx, tocol);
00593 }
00594 big_draw_end (tab);
00595 front_is_changed (tab);
00596 gtk_sheet_select_column (tab->view->sheet, tocol);
00597 }
00598
00605 void
00606 build_field_db (QlTabData * tab)
00607 {
00608 GtkWidget *top_box;
00609 GtkWidget *hbox_name;
00610 GtkWidget *hbox_type;
00611 GtkWidget *hbox_just;
00612 GtkWidget *button_box;
00613 GtkWidget *ok_button;
00614 GtkWidget *cancel_button;
00615 GtkWidget *name_label;
00616
00617 entry_dialogue = gtk_dialog_new ();
00618 gtk_window_set_modal (GTK_WINDOW (entry_dialogue), TRUE);
00619 gtk_window_set_position (GTK_WINDOW (entry_dialogue), GTK_WIN_POS_CENTER);
00620 gtk_window_set_resizable (GTK_WINDOW (entry_dialogue), TRUE);
00621 gtk_container_set_border_width (GTK_CONTAINER (entry_dialogue), 5);
00622 displaying = FALSE;
00623 field_db_start = field_db_curr;
00624
00625 g_object_set_data (G_OBJECT(entry_dialogue), QLTABID, tab);
00626 gtk_window_set_title (GTK_WINDOW (entry_dialogue),
00627 _("Edit Column Information"));
00628 top_box = GTK_DIALOG (entry_dialogue)->vbox;
00629 gtk_box_set_spacing (GTK_BOX (top_box), 10);
00630 button_box = GTK_DIALOG (entry_dialogue)->action_area;
00631
00632 hbox_name = gtk_hbox_new (FALSE, 5);
00633 name_label = gtk_label_new (_("Column Name"));
00634 gtk_widget_show (name_label);
00635 gtk_box_pack_start (GTK_BOX (hbox_name), name_label, FALSE, FALSE, 0);
00636
00637 column_name_entry = gtk_entry_new ();
00638 gtk_entry_set_max_length (GTK_ENTRY (column_name_entry), MAX_FIELD_NAME);
00639 gtk_box_pack_start (GTK_BOX (hbox_name), column_name_entry, TRUE, TRUE, 0);
00640 gtk_widget_show (column_name_entry);
00641 gtk_widget_show (hbox_name);
00642 gtk_box_pack_start (GTK_BOX (top_box), hbox_name, FALSE, FALSE, 0);
00643
00644
00645 hbox_type = gtk_hbox_new (FALSE, 3);
00646 text_button = gtk_radio_button_new_with_label (NULL, _("Text"));
00647 g_signal_connect (GTK_OBJECT (text_button), "clicked",
00648 G_CALLBACK (type_clicked), GINT_TO_POINTER (FIELD_TYPE_TEXT));
00649 gtk_box_pack_start (GTK_BOX (hbox_type), text_button, TRUE,
00650 TRUE, 0);
00651 gtk_widget_show (text_button);
00652
00653 numeric_button = gtk_radio_button_new_with_label
00654 (gtk_radio_button_get_group
00655 (GTK_RADIO_BUTTON (text_button)), _("Numeric"));
00656 g_signal_connect (GTK_OBJECT (numeric_button), "clicked",
00657 G_CALLBACK (type_clicked), GINT_TO_POINTER (FIELD_TYPE_NUMERIC));
00658 gtk_box_pack_start (GTK_BOX (hbox_type), numeric_button, TRUE,
00659 TRUE, 0);
00660 gtk_widget_show (numeric_button);
00661
00662 date_button = gtk_radio_button_new_with_label
00663 (gtk_radio_button_get_group
00664 (GTK_RADIO_BUTTON (text_button)), _("Date"));
00665 g_signal_connect (GTK_OBJECT (date_button), "clicked",
00666 G_CALLBACK (type_clicked), GINT_TO_POINTER (FIELD_TYPE_DATE));
00667 gtk_box_pack_start (GTK_BOX (hbox_type), date_button, TRUE,
00668 TRUE, 0);
00669 gtk_widget_show (date_button);
00670
00671 time_button = gtk_radio_button_new_with_label
00672 (gtk_radio_button_get_group
00673 (GTK_RADIO_BUTTON (text_button)), _("Time"));
00674 g_signal_connect (GTK_OBJECT (time_button), "clicked",
00675 G_CALLBACK (type_clicked), GINT_TO_POINTER (FIELD_TYPE_TIME));
00676 gtk_box_pack_start (GTK_BOX (hbox_type), time_button, TRUE,
00677 TRUE, 0);
00678 gtk_widget_show (time_button);
00679 gtk_widget_show (hbox_type);
00680 gtk_box_pack_start (GTK_BOX (top_box), hbox_type, FALSE, FALSE, 0);
00681
00682
00683 hbox_just = gtk_hbox_new (FALSE, 3);
00684 left_button = gtk_radio_button_new_with_label (NULL, _("Left"));
00685 g_signal_connect (GTK_OBJECT (left_button), "clicked",
00686 G_CALLBACK (just_clicked), GINT_TO_POINTER (GTK_JUSTIFY_LEFT));
00687 gtk_box_pack_start (GTK_BOX (hbox_just), left_button, TRUE,
00688 TRUE, 0);
00689 gtk_widget_show (left_button);
00690
00691 center_button = gtk_radio_button_new_with_label
00692 (gtk_radio_button_get_group
00693 (GTK_RADIO_BUTTON (left_button)), _("Center"));
00694 g_signal_connect (GTK_OBJECT (center_button), "clicked",
00695 G_CALLBACK (just_clicked), GINT_TO_POINTER (GTK_JUSTIFY_CENTER));
00696 gtk_box_pack_start (GTK_BOX (hbox_just), center_button, TRUE,
00697 TRUE, 0);
00698 gtk_widget_show (center_button);
00699
00700 right_button = gtk_radio_button_new_with_label
00701 (gtk_radio_button_get_group
00702 (GTK_RADIO_BUTTON (left_button)), _("Right"));
00703 g_signal_connect (GTK_OBJECT (right_button), "clicked",
00704 G_CALLBACK (just_clicked), GINT_TO_POINTER (GTK_JUSTIFY_RIGHT));
00705 gtk_box_pack_start (GTK_BOX (hbox_just), right_button, TRUE,
00706 TRUE, 0);
00707 gtk_widget_show (right_button);
00708 gtk_widget_show (hbox_just);
00709 gtk_box_pack_start (GTK_BOX (top_box), hbox_just, FALSE, FALSE, 0);
00710
00711
00712 gtk_box_pack_start (GTK_BOX (top_box), sub_menus (tab), FALSE, FALSE, 0);
00713
00714
00715 ok_button = gtk_button_new_from_stock (GTK_STOCK_ADD);
00716 gtk_widget_show (ok_button);
00717 gtk_box_pack_start (GTK_BOX (button_box), ok_button, TRUE, TRUE, 0);
00718 g_signal_connect (GTK_OBJECT (ok_button), "clicked",
00719 G_CALLBACK (ok_clicked), tab);
00720
00721 if (tab->view->dialog_mode == MODE_NEW)
00722 {
00723 done_button = gtk_button_new_from_stock (GTK_STOCK_APPLY);
00724
00725 gtk_box_pack_start (GTK_BOX (button_box),
00726 done_button, TRUE, TRUE, 0);
00727 g_signal_connect (GTK_OBJECT (done_button), "clicked",
00728 G_CALLBACK (done_clicked), tab);
00729 }
00730 cancel_button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
00731 gtk_widget_show (cancel_button);
00732 gtk_box_pack_start (GTK_BOX (button_box),
00733 cancel_button, TRUE, TRUE, 0);
00734 g_signal_connect (GTK_OBJECT (cancel_button), "clicked",
00735 G_CALLBACK (cancel_clicked), tab);
00736 g_signal_connect (GTK_OBJECT (entry_dialogue),
00737 "delete_event", G_CALLBACK (cancel_clicked), tab);
00738 gtk_widget_show (entry_dialogue);
00739 }
00740
00741 void
00742 column_add (GtkAction G_GNUC_UNUSED * w, gpointer data)
00743 {
00744 QlContext * qlc;
00745 QlTabData * tab;
00746
00747 qlc = ql_get_context (GTK_WIDGET(data));
00748 tab = ql_get_tabdata (qlc);
00749 CHECK_CHANGED(tab);
00750 tab->view->dialog_mode = MODE_ADD;
00751 build_field_db (tab);
00752 new_std_field (tab);
00753 update_field_db (tab);
00754 }
00755
00756 void
00757 column_edit (GtkAction G_GNUC_UNUSED * w, gpointer data)
00758 {
00759 QlContext * qlc;
00760 QlTabData * tab;
00761 gint this_field, selected;
00762
00764 qlc = ql_get_context (GTK_WIDGET(data));
00765 tab = ql_get_tabdata (qlc);
00766 CHECK_RANGE;
00767 CHECK_CHANGED(tab);
00768 if (tab->view->sel_type != SELECT_COLUMN)
00769 return;
00770 tab->view->dialog_mode = MODE_EDIT;
00771 selected = tab->view->sel_range.col0;
00772 this_field = tab->file->col_to_field[selected];
00773 field_db_curr = ql_get_fieldinfo (tab, this_field);
00774 build_field_db (tab);
00775 update_field_db (tab);
00776 }
00777
00778 void
00779 del_column_cb (gpointer field_index, gpointer field_ptr,
00780 gpointer G_GNUC_UNUSED user_data)
00781 {
00782 QlFieldInfo * field = (QlFieldInfo*)field_ptr;
00783 gint colx = GPOINTER_TO_INT (field_index);
00784 g_return_if_fail (field);
00785 if (field->sheet_column > colx)
00786 field->sheet_column--;
00787 }
00788
00789 void
00790 column_delete (GtkAction G_GNUC_UNUSED * w, gpointer data)
00791 {
00792 gint colx, field_leaving, groupx;
00793 gint linex, reportto, reportfrom, starting_reports;
00794 gint colto, colfrom, starting_cols;
00795 QlReportInfo temp_report;
00796 QlContext * qlc;
00797 QlTabData * tab;
00798
00799 qlc = ql_get_context (GTK_WIDGET(data));
00800 tab = ql_get_tabdata (qlc);
00801
00802
00803 CHECK_RANGE;
00804 CHECK_CHANGED(tab);
00805 front_is_changed (tab);
00806 colx = tab->view->sel_range.col0;
00807 field_leaving = tab->file->col_to_field[colx];
00808 gtk_sheet_delete_columns (tab->view->sheet, colx, 1);
00809
00810
00811
00812
00813 tab->file->last_field--;
00814 ql_remove_fieldinfo (tab, field_leaving);
00815 ql_fieldinfo_foreach (tab, del_column_cb, GINT_TO_POINTER(colx));
00816
00817
00818
00819
00820 reset_col_to_field (tab);
00821
00822
00823 for (groupx = 0; groupx < tab->file->sort_ct; groupx++)
00824 {
00825 for (linex = 0; linex < tab->file->sorts[groupx].line_ct; linex++)
00826 {
00827 if (tab->file->sorts[groupx].line[linex].field == field_leaving)
00828 tab->file->sorts[groupx].line[linex].field = -1;
00829 else if (tab->file->sorts[groupx].line[linex].field >
00830 field_leaving)
00831 tab->file->sorts[groupx].line[linex].field--;
00832 }
00833 }
00834
00835
00836 for (groupx = 0; groupx < tab->file->filter_ct; groupx++)
00837 {
00838 for (linex = 0; linex < tab->file->filters[groupx].line_ct; linex++)
00839 {
00840 if (tab->file->filters[groupx].line[linex].field == field_leaving)
00841 tab->file->filters[groupx].line[linex].field = -1;
00842 else if (tab->file->filters[groupx].line[linex].field >
00843 field_leaving)
00844 tab->file->filters[groupx].line[linex].field--;
00845 }
00846 }
00847
00848
00849 reportto = 0;
00850 starting_reports = tab->file->report_ct;
00851 for (reportfrom = 0; reportfrom < starting_reports; reportfrom++)
00852 {
00853 temp_report = tab->file->reports[reportfrom];
00854 colto = 0;
00855 starting_cols = temp_report.last_column;
00856 for (colfrom = 0; colfrom <= starting_cols; colfrom++)
00857 {
00858 if (temp_report.column[colfrom].field != field_leaving)
00859 {
00860 if (temp_report.column[colfrom].field > field_leaving)
00861 temp_report.column[colfrom].field--;
00862 temp_report.column[colto++] = temp_report.column[colfrom];
00863 }
00864 else
00865 temp_report.last_column--;
00866 }
00867 if (temp_report.last_column >= 0)
00868 tab->file->reports[reportto++] = temp_report;
00869 else
00870 tab->file->report_ct--;
00871 }
00872 }
00873
00874 void
00875 column_left (GtkAction G_GNUC_UNUSED * w, gpointer data)
00876 {
00877 QlContext * qlc;
00878 QlTabData * tab;
00879 gint from, to;
00880
00881 qlc = ql_get_context (GTK_WIDGET(data));
00882 tab = ql_get_tabdata (qlc);
00883 CHECK_RANGE;
00884 CHECK_CHANGED(tab);
00885 from = tab->view->sel_range.col0 - 1;
00886 to = tab->view->sel_range.col0;
00887 swap_columns (tab, to, from);
00888 }
00889
00890 void
00891 column_right (GtkAction G_GNUC_UNUSED * w, gpointer data)
00892 {
00893 QlContext * qlc;
00894 QlTabData * tab;
00895 gint from, to;
00896
00897 qlc = ql_get_context (GTK_WIDGET(data));
00898 tab = ql_get_tabdata (qlc);
00899 CHECK_RANGE;
00900 CHECK_CHANGED(tab);
00901 to = tab->view->sel_range.col0 + 1;
00902 from = tab->view->sel_range.col0;
00903 swap_columns (tab, to, from);
00904 }
00905
00906 void
00907 new_file (GtkAction G_GNUC_UNUSED * w, gpointer data)
00908 {
00909 QlContext * qlc;
00910 QlTabData * tab;
00911
00912 qlc = ql_get_context (GTK_WIDGET(data));
00913 tab = ql_new_tabdata (qlc);
00914 tab->file->last_field = -1;
00915
00916 tab->view->dialog_mode = MODE_NEW;
00917
00918 tab->file->file_path = g_strconcat ("~/", _("Untitled_New_List"), ".qlf", NULL);
00919 tab->file->file_name = g_strconcat (_("Untitled_New_List"), ".qlf", NULL);
00920 field_db_curr = g_new0(QlFieldInfo, 1);
00921 field_db_start = g_new0(QlFieldInfo, 1);
00922 build_field_db (tab);
00923 new_std_field (tab);
00924 update_field_db (tab);
00925 }