Example #1
0
int gnumeric_move_row(GnumericSheetPtr sheet, int src, int dest) {
  int w, h;
  gnumeric_sheet_get_size(sheet,&w,&h);

  GnmPasteTarget pt;
  pt.sheet = sheet;
  pt.paste_flags = PASTE_CONTENTS | PASTE_COMMENTS | PASTE_NO_RECALC;
  pt.paste_flags = pt.paste_flags | PASTE_FORMATS;

  GnmRange range1, range2;
  GnmCellRegion *rcopy1, *rcopy2 = NULL;
  if (src==dest) return 0;

  // copy src column
  range1.start.col = 0;
  range1.end.col = w-1;
  range1.start.row = src;
  range1.end.row = src;
  rcopy1 = clipboard_copy_range(sheet,&range1);

  // copy src-dest range
  range2.start.col = 0;
  range2.end.col = w-1;
  if (dest<src) {
    range2.start.row = dest;
    range2.end.row = src-1;
  } else {
    range2.start.row = src+1;
    range2.end.row = dest;
  }
  rcopy2 = clipboard_copy_range(sheet,&range2);
  if (dest<src) {
    range2.start.row++;
    range2.end.row++;
  } else {
    range2.start.row--;
    range2.end.row--;
  }
  pt.range = range2;
  clipboard_paste_region(rcopy2, &pt, cc);
  cellregion_unref(rcopy2);

  range1.start.row = dest;
  range1.end.row = dest;
  pt.range = range1;
  clipboard_paste_region(rcopy1, &pt, cc);
  cellregion_unref(rcopy1);
  return 0;
}
Example #2
0
static void
cb_clipboard_copy_range_undo (GnmCellRegion *cr, GnmSheetRange *sr,
			      GOCmdContext *cc)
{
	GnmPasteTarget pt;

	clipboard_paste_region
		(cr,
		 paste_target_init (&pt,
				    sr->sheet,
				    &sr->range,
				    PASTE_CONTENTS | PASTE_FORMATS |
				    PASTE_OBJECTS | PASTE_COMMENTS),
		 cc);
}
Example #3
0
static gboolean
cmd_slicer_refresh_undo (GnmCommand *cmd, WorkbookControl *wbc)
{
	CmdSlicerRefresh *me = CMD_SLICER_REFRESH (cmd);
	GnmRange const *new_size = gnm_sheet_slicer_get_range (me->slicer);
	GnmPasteTarget pt;
	sheet_clear_region (me->cmd.sheet,
		new_size->start.col, new_size->start.row,
		new_size->end.col, new_size->end.row,
		CLEAR_VALUES | CLEAR_FORMATS | CLEAR_MERGES | CLEAR_NOCHECKARRAY | CLEAR_RECALC_DEPS,
		GO_CMD_CONTEXT (wbc));
	clipboard_paste_region (me->orig_content,
		paste_target_init (&pt, me->cmd.sheet, &me->orig_size, PASTE_DEFAULT),
		GO_CMD_CONTEXT (wbc));
	cellregion_unref (me->orig_content);
	me->orig_content = NULL;
	return FALSE;
}
Example #4
0
static void
sort_permute (GnmSortData *data, int const *perm, int length,
	      GOCmdContext *cc)
{
	int i, *rperm;
	GnmPasteTarget pt;

	pt.sheet = data->sheet;
	pt.paste_flags = PASTE_CONTENTS | PASTE_COMMENTS | PASTE_NO_RECALC;
	if (!data->retain_formats)
		pt.paste_flags = pt.paste_flags | PASTE_FORMATS;

#ifdef DEBUG_SORT
	g_printerr ("Permutation:");
	for (i = 0; i < length; i++)
		g_printerr (" %d", perm[i]);
	g_printerr ("\n");
#endif

	rperm = gnm_sort_permute_invert (perm, length);

	for (i = 0; i < length; i++) {
		GnmRange range1, range2;
		GnmCellRegion *rcopy1, *rcopy2 = NULL;
		int i1, i2;

		/* Special case: element is already in place.  */
		if (i == rperm[i]) {
#ifdef DEBUG_SORT
			g_printerr ("  Fixpoint: %d\n", i);
#endif
			continue;
		}

		/* Track a full cycle.  */
		sort_permute_range (data, &range1, i);
		rcopy1 = clipboard_copy_range (data->sheet, &range1);

#ifdef DEBUG_SORT
		g_printerr ("  Cycle:");
#endif
		i1 = i;
		do {
#ifdef DEBUG_SORT
			g_printerr (" %d", i1);
#endif

			i2 = rperm[i1];

			sort_permute_range (data, &range2, i2);
			if (i2 != i) {
				/* Don't copy the start of the loop; we did that above.  */
				rcopy2 = clipboard_copy_range (data->sheet, &range2);
			}

			pt.range = range2;
			clipboard_paste_region (rcopy1, &pt, cc);
			cellregion_unref (rcopy1);

			/* This is one step behind.  */
			rperm[i1] = i1;

			rcopy1 = rcopy2;
			range1 = range2;
			i1 = i2;
		} while (i1 != i);
#ifdef DEBUG_SORT
		g_printerr ("\n");
#endif
	}

	g_free (rperm);
}
Example #5
0
int gnumeric_move_column(GnumericSheetPtr sheet, int src, int dest) {
  int w, h;
  gnumeric_sheet_get_size(sheet,&w,&h);

  /*
    If dest<src:
       copy the src column
       copy from dest to src-1
         paste that offset to right by 1
       paste to dest column

    If dest>src:
       copy the src column
       copy from src+1 to dest
         paste that offset to left by 1
       paste to dest column
   */

  GnmPasteTarget pt;
  pt.sheet = sheet;
  pt.paste_flags = PASTE_CONTENTS | PASTE_COMMENTS | PASTE_NO_RECALC;
  pt.paste_flags = pt.paste_flags | PASTE_FORMATS;

  GnmRange range1, range2;
  GnmCellRegion *rcopy1, *rcopy2 = NULL;
  if (src==dest) return 0;

  // copy src column
  range1.start.row = 0;
  range1.end.row = h-1;
  range1.start.col = src;
  range1.end.col = src;
  rcopy1 = clipboard_copy_range(sheet,&range1);

  // copy src-dest range
  range2.start.row = 0;
  range2.end.row = h-1;
  if (dest<src) {
    range2.start.col = dest;
    range2.end.col = src-1;
  } else {
    range2.start.col = src+1;
    range2.end.col = dest;
  }
  rcopy2 = clipboard_copy_range(sheet,&range2);
  if (dest<src) {
    range2.start.col++;
    range2.end.col++;
  } else {
    range2.start.col--;
    range2.end.col--;
  }
  pt.range = range2;
  clipboard_paste_region(rcopy2, &pt, cc);
  cellregion_unref(rcopy2);

  range1.start.col = dest;
  range1.end.col = dest;
  pt.range = range1;
  clipboard_paste_region(rcopy1, &pt, cc);
  cellregion_unref(rcopy1);
  return 0;
}