Ejemplo n.º 1
0
static GODataCache *
build_cache(void) 
{
	Workbook *wb;
	Sheet *sheet;
	GODataCache *cache;
	GnmRange *range;
	int row, col, numRows = 60, numCols = 5;
	
	wb = workbook_new();
	sheet = workbook_sheet_add (wb, -1, 1024, 1024);
	
	for (row = 0; row < numRows; row++) {
		for (col = 0; col < numCols; col++) {
			GnmCell * tempCell = sheet_cell_create(sheet, col, row);
			GnmValue * tempVal;
			if (col == 0) {
				if (row%4 == 0) {
					tempVal = value_new_string_nocopy((char *)"A");
				} else if (row%4 == 1) {
					tempVal = value_new_string_nocopy((char *)"B");
				} else if (row%4 == 2) {
					tempVal = value_new_string_nocopy((char *)"C");
				} else {
					tempVal = value_new_string_nocopy((char *)"D");
				}
			} else if (col == 1) {
				tempVal = value_new_int(row);
			} else if (col == 2) {
				if (row%5 == 0) {
					tempVal = value_new_float(14.4);
				} else if (row%5 == 1) {
					tempVal = value_new_float(18.8);
				} else if (row%5 == 2) {
					tempVal = value_new_float(7.6);
				} else if (row%5 == 3) {
					tempVal = value_new_float(3.3);
				} else {
					tempVal = value_new_float(11.6);
				}
			} else if (col == 3) {
				tempVal = value_new_int(row % 10);
			} else if (col == 4) {
				if (row == 0) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_DIV0(pos);
				} else if (row == 1) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_NA(pos);
				} else if (row == 2) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_REF(pos);
				} else if (row == 3) {
					tempVal = value_new_bool(TRUE);
				} else if (row == 4) {
					tempVal = value_new_bool(FALSE);
				} else if (row == 5) {
					tempVal = value_new_empty();
				} else {
					if (row%5 == 1) {
						tempVal = value_new_string_nocopy((char *)"a");
					} else if (row%5 == 2) {
						tempVal = value_new_string_nocopy((char *)"b");
					} else if (row%5 == 3) {
						tempVal = value_new_string_nocopy((char *)"c");
					} else if (row%5 == 4) {
						tempVal = value_new_string_nocopy((char *)"d");
					} else {
						tempVal = value_new_string_nocopy((char *)"e");
					}
				}
			}
			sheet_cell_set_value(tempCell, tempVal);
		}
	}
	
	cache = g_object_new(GO_DATA_CACHE_TYPE, NULL);
	range = g_new(GnmRange, 1);
	range = range_init(range, 0, 0, numCols - 1, numRows - 1);
	
	go_data_cache_build_cache(cache, sheet, range);
	
	g_object_unref (wb);
	
	return cache;
}
Ejemplo n.º 2
0
static void
item_grid_draw_merged_range (cairo_t *cr, GnmItemGrid *ig,
			     int start_x, int start_y,
			     GnmRange const *view, GnmRange const *range,
			     gboolean draw_selection, GtkStyleContext *ctxt)
{
	int l, r, t, b, last;
	SheetView const *sv = scg_view (ig->scg);
	WorkbookView *wbv = sv_wbv (sv);
	gboolean show_function_cell_markers = wbv->show_function_cell_markers;
	gboolean show_extension_markers = wbv->show_extension_markers;
	Sheet const *sheet  = sv->sheet;
	GnmCell const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
	int const dir = sheet->text_is_rtl ? -1 : 1;

	/* load style from corner which may not be visible */
	GnmStyle const *style = sheet_style_get (sheet, range->start.col, range->start.row);
	gboolean const is_selected = draw_selection &&
		(sv->edit_pos.col != range->start.col ||
		 sv->edit_pos.row != range->start.row) &&
		sv_is_full_range_selected (sv, range);

	/* Get the coordinates of the visible region */
	l = r = start_x;
	if (view->start.col < range->start.col)
		l += dir * scg_colrow_distance_get (ig->scg, TRUE,
			view->start.col, range->start.col);
	if (range->end.col <= (last = view->end.col))
		last = range->end.col;
	r += dir * scg_colrow_distance_get (ig->scg, TRUE, view->start.col, last+1);

	t = b = start_y;
	if (view->start.row < range->start.row)
		t += scg_colrow_distance_get (ig->scg, FALSE,
			view->start.row, range->start.row);
	if (range->end.row <= (last = view->end.row))
		last = range->end.row;
	b += scg_colrow_distance_get (ig->scg, FALSE, view->start.row, last+1);

	if (l == r || t == b)
		return;

	if (style->conditions) {
		GnmEvalPos ep;
		int res;
		eval_pos_init (&ep, (Sheet *)sheet, range->start.col, range->start.row);
		if ((res = gnm_style_conditions_eval (style->conditions, &ep)) >= 0)
			style = g_ptr_array_index (style->cond_styles, res);
	}

	/* Check for background THEN selection */
	if (gnumeric_background_set (style, cr, is_selected, ctxt) ||
	    is_selected) {
		/* Remember X excludes the far pixels */
		if (dir > 0)
			cairo_rectangle (cr, l, t, r-l+1, b-t+1);
		else
			cairo_rectangle (cr, r, t, l-r+1, b-t+1);
		cairo_fill (cr);
	}

	/* Expand the coords to include non-visible areas too.  The clipped
	 * region is only necessary when drawing the background */
	if (range->start.col < view->start.col)
		l -= dir * scg_colrow_distance_get (ig->scg, TRUE,
			range->start.col, view->start.col);
	if (view->end.col < range->end.col)
		r += dir * scg_colrow_distance_get (ig->scg, TRUE,
			view->end.col+1, range->end.col+1);
	if (range->start.row < view->start.row)
		t -= scg_colrow_distance_get (ig->scg, FALSE,
			range->start.row, view->start.row);
	if (view->end.row < range->end.row)
		b += scg_colrow_distance_get (ig->scg, FALSE,
			view->end.row+1, range->end.row+1);

	if (cell != NULL) {
		ColRowInfo *ri = sheet_row_get (sheet, range->start.row);

		if (ri->needs_respan)
			row_calc_spans (ri, cell->pos.row, sheet);

		if (dir > 0) {
			if (show_function_cell_markers)
				draw_function_marker (ig, cell, cr, l, t,
						      r - l, b - t, dir);
			cell_draw (cell, cr,
				   l, t, r - l, b - t, -1,
				   show_extension_markers);
		} else {
			if (show_function_cell_markers)
				draw_function_marker (ig, cell, cr, r, t,
						      l - r, b - t, dir);
			cell_draw (cell, cr,
				   r, t, l - r, b - t, -1,
				   show_extension_markers);
		}
	}
	if (dir > 0)
		gnm_style_border_draw_diag (style, cr, l, t, r, b);
	else
		gnm_style_border_draw_diag (style, cr, r, t, l, b);
}