void workbook_style_test (Workbook *wb) { GSList *sheets; g_return_if_fail (wb != NULL); sheets = workbook_sheets (wb); while (sheets) { Sheet *sheet = sheets->data; fprintf (stderr, "Style lookups on '%s'\n", sheet->name_unquoted); sheet_styles_dump (sheet); #ifdef RUN_THRASH_SCROLL zero_stats (); thrash_scroll (sheet); dump_stats ("Scroll"); #endif zero_stats (); thrash_insert (sheet); dump_stats ("Insert"); sheets = g_slist_remove (sheets, sheet); sheet_flag_recompute_spans (sheet); } workbook_recalc (wb); workbook_calc_spans (wb, GNM_SPANCALC_RENDER); }
static void add_worksheet(Workbook *wb, psiconv_sheet_worksheet psi_worksheet,int nr, psiconv_formula_list psi_formulas) { Sheet *sheet; char *sheet_name; GnmStyle *default_style; psiconv_sheet_grid_section grid; sheet_name = g_strdup_printf (_("Sheet%d"),nr); sheet = sheet_new (wb, sheet_name, 256, 65536); g_free (sheet_name); if (!sheet) return; /* Default layout */ default_style = gnm_style_new_default(); if (!default_style) { g_object_unref (sheet); return; } set_layout(default_style,psi_worksheet->default_layout); /* TODO: Add show_zeros */ grid = psi_worksheet->grid; if (grid) { sheet_row_set_default_size_pts (sheet, cm2pts (grid->default_row_height)); sheet_col_set_default_size_pts (sheet, cm2pts (grid->default_column_width)); if (grid->row_heights) set_row_heights (sheet, grid->row_heights); if (grid->column_heights) set_col_widths (sheet, grid->column_heights); } add_cells(sheet,psi_worksheet->cells,psi_formulas,default_style); /* TODO: What about the NULL? */ sheet_flag_recompute_spans(sheet); workbook_sheet_attach (wb, sheet); gnm_style_unref (default_style); }
void colrow_set_states (Sheet *sheet, gboolean is_cols, int first, ColRowStateList *states) { GSList *l; int i, max_outline, offset = first; ColRowCollection *infos; double scale; g_return_if_fail (IS_SHEET (sheet)); infos = is_cols ? &(sheet->cols) : &(sheet->rows); max_outline = infos->max_outline_level; scale = colrow_compute_pixel_scale (sheet, is_cols); for (l = states; l != NULL; l = l->next) { ColRowRLEState const *rles = l->data; ColRowState const *state = &rles->state; if (max_outline < state->outline_level) max_outline = state->outline_level; for (i = offset; i < offset + rles->length; i++) { if (state->is_default) { ColRowSegment *segment = COLROW_GET_SEGMENT(infos, i); if (segment != NULL) { int const sub = COLROW_SUB_INDEX (i); ColRowInfo *cri = segment->info[sub]; if (cri != NULL) { segment->info[sub] = NULL; colrow_free (cri); } } } else { ColRowInfo *cri = sheet_colrow_fetch (sheet, i, is_cols); cri->hard_size = state->hard_size; cri->size_pts = state->size_pts; colrow_compute_pixels_from_pts (cri, sheet, is_cols, scale); colrow_set_outline (cri, state->outline_level, state->is_collapsed); } } offset += rles->length; } /* Notify sheet of pending update */ sheet->priv->recompute_visibility = TRUE; if (is_cols) { sheet_flag_recompute_spans (sheet); /* In order to properly reposition cell * comments in merged cells that cross the * boundary we need to do everything. Revert * this when comments are handled properly */ #if 0 if (sheet->priv->reposition_objects.col > first) sheet->priv->reposition_objects.col = first; #else sheet->priv->reposition_objects.col = 0; #endif } else { if (sheet->priv->reposition_objects.row > first) sheet->priv->reposition_objects.row = first; } sheet_colrow_gutter (sheet, is_cols, max_outline); }
G_MODULE_EXPORT void paradox_file_open (GOFileOpener const *fo, GOIOContext *io_context, WorkbookView *wb_view, GsfInput *input) { Workbook *wb; pxdoc_t *pxdoc; pxhead_t *pxh; pxfield_t *pxf; char *data; char *name; Sheet *sheet; GnmCell *cell; GnmValue *val = NULL; GOErrorInfo *open_error = NULL; guint row, i, j, offset; #ifdef PX_MEMORY_DEBUGGING PX_mp_init (); #endif #ifdef PX_MEMORY_DEBUGGING pxdoc = PX_new2 (gn_errorhandler, PX_mp_malloc, PX_mp_realloc, PX_mp_free); #else pxdoc = PX_new2 (gn_errorhandler, gn_malloc, gn_realloc, gn_free); #endif if (PX_open_gsf (pxdoc, input) < 0) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } pxh = pxdoc->px_head; PX_set_targetencoding (pxdoc, "UTF-8"); wb = wb_view_get_workbook (wb_view); name = workbook_sheet_get_free_name (wb, pxh->px_tablename, FALSE, TRUE); sheet = sheet_new (wb, name, 256, 65536); g_free (name); workbook_sheet_attach (wb, sheet); pxf = pxh->px_fields; for (i = 0 ; i < (guint) pxh->px_numfields; i++) { char str[30], *str2; char ctypes[26] = {'?', 'A', 'D', 'S', 'I', '$', 'N', '?', '?', 'L', '?', '?', 'M', 'B', 'F', 'O', 'G', '?', '?', '?', 'T', '@', '+', '#', 'Y', }; cell = sheet_cell_fetch (sheet, i, 0); if (pxf->px_ftype == pxfBCD) snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_fdc); else snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_flen); #if PXLIB_MAJOR_VERSION == 0 && (PXLIB_MINOR_VERION < 3 || (PXLIB_MAJOR_VERSION == 3 && PXLIB_MICRO_VERSION == 0)) /* Convert the field names to utf-8. This is actually in pxlib * responsibility, but hasn't been implemented yet. For the mean time * we *misuse* PX_get_data_alpha() */ PX_get_data_alpha (pxdoc, str, strlen (str), &str2); gnm_cell_set_text (cell, str2); pxdoc->free (pxdoc, str2); #else gnm_cell_set_text (cell, str); #endif pxf++; } { GnmRange r; GnmStyle *bold = gnm_style_new (); gnm_style_set_font_bold (bold, TRUE); sheet_style_apply_range (sheet, range_init (&r, 0, 0, pxh->px_numfields-1, 0), bold); } if ((data = (char *) pxdoc->malloc (pxdoc, pxh->px_recordsize, _("Could not allocate memory for record."))) == NULL) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } row = 1; for (j = 0; j < (guint)pxh->px_numrecords; j++) { pxdatablockinfo_t pxdbinfo; int isdeleted = 0; if (NULL != PX_get_record2 (pxdoc, j, data, &isdeleted, &pxdbinfo)) { offset = 0; pxf = pxh->px_fields; for (i = 0; i < (guint) pxh->px_numfields ; i++) { cell = sheet_cell_fetch (sheet, i, row); val = NULL; switch (pxf->px_ftype) { case pxfAlpha: { char *value; if (0 < PX_get_data_alpha (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_string_nocopy (value); /* value_set_fmt (val, field->fmt); */ } break; } case pxfShort: { short int value; if (0 < PX_get_data_short (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfAutoInc: case pxfLong: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfCurrency: case pxfNumber: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value); if (pxf->px_ftype == pxfCurrency) value_set_fmt (val, go_format_default_money ()); } break; } case pxfTimestamp: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { value = value / 86400000.0; /* 693594 = number of days up to 31.12.1899 */ value -= 693594; val = value_new_float (value); value_set_fmt (val, go_format_default_date_time ()); } break; } case pxfLogical: { char value; if (0 < PX_get_data_byte (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_bool (value ? TRUE : FALSE); } break; } case pxfDate: { long value; int year, month, day; GDate *date; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { PX_SdnToGregorian (value+1721425, &year, &month, &day); date = g_date_new_dmy (day, month, year); val = value_new_int (go_date_g_to_serial (date, NULL)); value_set_fmt (val, go_format_default_date ()); g_date_free (date); } break; } case pxfTime: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value/86400000.0); value_set_fmt (val, go_format_default_time ()); } break; } case pxfBCD: { char *value; if (0 < PX_get_data_bcd (pxdoc, &data[offset], pxf->px_fdc, &value)) { val = value_new_string_nocopy (value); } break; } case pxfMemoBLOb: { char *value; int size, mod_nr; if (0 < PX_get_data_blob (pxdoc, &data[offset], pxf->px_flen, &mod_nr, &size, &value)) { val = value_new_string_nocopy (value); } break; } default: val = value_new_string_nocopy ( g_strdup_printf (_("Field type %d is not supported."), pxf->px_ftype)); } if (val) gnm_cell_set_value (cell, val); offset += pxf->px_flen; pxf++; } if (pxh->px_filetype == pxfFileTypPrimIndex) { short int value; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } cell = sheet_cell_fetch (sheet, i++, row); val = value_new_int (pxdbinfo.number); gnm_cell_set_value (cell, val); } } row++; } pxdoc->free (pxdoc, data); PX_close (pxdoc); PX_delete (pxdoc); sheet_flag_recompute_spans (sheet); }
/** * colrow_set_visibility: * @sheet: the sheet * @is_cols: Are we dealing with rows or columns. * @visible: Make things visible or invisible. * @first: The index of the first row/col (inclusive) * @last: The index of the last row/col (inclusive) * * Change the visibility of the selected range of contiguous cols/rows. * NOTE : only changes the collapsed state for the LAST+1 element. */ void colrow_set_visibility (Sheet *sheet, gboolean is_cols, gboolean visible, int first, int last) { int i, step, prev_outline = 0; gboolean changed = FALSE; GnmRange * const bound = &sheet->priv->unhidden_region; gboolean const fwd = is_cols ? sheet->outline_symbols_right : sheet->outline_symbols_below; g_return_if_fail (IS_SHEET (sheet)); g_return_if_fail (first <= last); if (visible) { /* expand to include newly visible regions */ if (is_cols) { if (bound->start.col > first) bound->start.col = first; if (bound->end.col < last) bound->end.col = last; } else { if (bound->start.row > first) bound->start.row = first; if (bound->end.row < last) bound->end.row = last; } } else { /* contract to exclude newly hidden regions */ if (is_cols) { if (bound->start.col >= first && bound->start.col <= last) bound->start.col = last+1; if (bound->end.col <= last && bound->end.col >= first) bound->end.col = first-1; } else { if (bound->start.row >= first && bound->start.row <= last) bound->start.row = last+1; if (bound->end.row <= last && bound->end.row >= first) bound->end.row = first-1; } } if (fwd) { i = first; step = 1; } else { i = last; step = -1; } for (; fwd ? (i <= last) : (i >= first) ; i += step) { ColRowInfo * const cri = sheet_colrow_fetch (sheet, i, is_cols); if (changed && prev_outline > cri->outline_level && !visible) cri->is_collapsed = FALSE; changed = (visible == 0) != (cri->visible == 0); if (changed) { cri->visible = visible; prev_outline = cri->outline_level; sheet->priv->recompute_visibility = TRUE; if (is_cols) { sheet_flag_recompute_spans (sheet); /* In order to properly reposition cell * comments in merged cells that cross the * boundary we need to do everything. Revert * this when comments are handled properly */ #if 0 if (sheet->priv->reposition_objects.col > i) sheet->priv->reposition_objects.col = i; #else sheet->priv->reposition_objects.col = 0; #endif } else { if (sheet->priv->reposition_objects.row > i) sheet->priv->reposition_objects.row = i; } } } if (changed && 0 <= i && i < colrow_max (is_cols, sheet)) { ColRowInfo *cri = sheet_colrow_get (sheet, i, is_cols); if (!cri && !visible && prev_outline > 0) cri = sheet_colrow_fetch (sheet, i, is_cols); if (cri && prev_outline > cri->outline_level) cri->is_collapsed = !visible; } }