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
/**
 * gnm_app_clipboard_cut_copy:
 * @wbc: the workbook control that requested the operation.
 * @is_cut: is this a cut or a copy.
 * @sv: The source sheet for the copy.
 * @area: A single rectangular range to be copied.
 * @animate_range: Do we want ot add an animated cursor around things.
 *
 * When Cutting we
 *   Clear and free the contents of the clipboard and save the sheet and area
 *   to be cut.  DO NOT ACTUALLY CUT!  Paste will move the region if this was a
 *   cut operation.
 *
 * When Copying we
 *   Clear and free the contents of the clipboard and COPY the designated region
 *   into the clipboard.
 *
 * we need to pass @wbc as a control rather than a simple command-context so
 * that the control can claim the selection.
 **/
void
gnm_app_clipboard_cut_copy (WorkbookControl *wbc, gboolean is_cut,
			    SheetView *sv, GnmRange const *area,
			    gboolean animate_cursor)
{
	Sheet *sheet;

	g_return_if_fail (IS_SHEET_VIEW (sv));
	g_return_if_fail (area != NULL);
	g_return_if_fail (app != NULL);

	gnm_app_clipboard_clear (FALSE);
	sheet = sv_sheet (sv);
	g_free (app->clipboard_cut_range);
	app->clipboard_cut_range = gnm_range_dup (area);
	sv_weak_ref (sv, &(app->clipboard_sheet_view));

	if (!is_cut)
		app->clipboard_copied_contents =
			clipboard_copy_range (sheet, area);
	if (animate_cursor) {
		GList *l = g_list_append (NULL, (gpointer)area);
		sv_ant (sv, l);
		g_list_free (l);
	}

	if (wb_control_claim_selection (wbc)) {
		g_signal_emit (G_OBJECT (app), signals[CLIPBOARD_MODIFIED], 0);
	} else {
		gnm_app_clipboard_clear (FALSE);
		g_warning ("Unable to set selection ?");
	}
}
Example #3
0
/**
 * clipboard_copy_range_undo:
 * @sheet: #Sheet
 * @r: #GnmRange
 *
 * Returns: (transfer full): A #GOUndo object that will restore the contents
 * of the given range.
 **/
GOUndo *
clipboard_copy_range_undo (Sheet *sheet, GnmRange const *r)
{
	GnmCellRegion *cr = clipboard_copy_range (sheet, r);
	g_return_val_if_fail (cr != NULL, NULL);
	return go_undo_binary_new (cr, gnm_sheet_range_new (sheet, r),
				   (GOUndoBinaryFunc)cb_clipboard_copy_range_undo,
				   (GFreeFunc)cellregion_unref,
				   (GFreeFunc)g_free);
}
Example #4
0
static gboolean
cmd_slicer_refresh_redo (GnmCommand *cmd, WorkbookControl *wbc)
{
	CmdSlicerRefresh *me = CMD_SLICER_REFRESH (cmd);
	GnmRange const *new_size = gnm_sheet_slicer_get_range (me->slicer);

	me->orig_size	 = *gnm_sheet_slicer_get_range (me->slicer);
	me->orig_content = clipboard_copy_range (me->cmd.sheet, &me->orig_size);

	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));

	gnm_sheet_slicer_regenerate (me->slicer);

	return FALSE;
}
Example #5
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 #6
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;
}