edit.c File Reference


Detailed Description

Functions for edit - cut, copy and paste.

Author:
Copyright 2006-2007 Neil Williams <linux@codehelp.co.uk>

Copyright 1999 Robert Lissner

Definition in file edit.c.

#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gtkextra/gtksheet.h>
#include "types.h"
#include "dim_list_menu.h"
#include "edit.h"
#include "main.h"
#include "dialog_initial.h"

Go to the source code of this file.

Functions

static void dim_sum_menu (QlContext *qlc)
gboolean activate_callback (GtkSheet G_GNUC_UNUSED *sheet, gint row, gint col, gpointer data)
static void actual_paste (QlTabData *tab, gint sheet_row, gint cb_row, gint col)
static void clear_the_range (QlTabData *tab)
void edit_ditto (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_clear (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_fill_down (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_paste (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_select_all (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_insert_rows (GtkAction G_GNUC_UNUSED *w, gpointer data)
void new_column_width (GtkSheet G_GNUC_UNUSED *sheet, gint col, gint width, gpointer data)
static void put_range_on_clipboard (QlTabData *tab)
void edit_cut (GtkAction G_GNUC_UNUSED *w, gpointer data)
void edit_copy (GtkAction G_GNUC_UNUSED *w, gpointer data)
gboolean row_is_visible (QlTabData *tab, gint testrow)
void select_range_callback (GtkSheet G_GNUC_UNUSED *sheet, GtkSheetRange *range, gpointer data)


Function Documentation

static void actual_paste ( QlTabData tab,
gint  sheet_row,
gint  cb_row,
gint  col 
) [static]

Paste one row from clipboard into sheet, at row and col

Definition at line 114 of file edit.c.

00115 {
00116     gchar *linebufp;
00117     gchar *prevbufp;
00118     gint colx;
00119     gint fieldx;
00120     prevbufp = linebufp = tab->view->cb[cb_row];
00121     colx = col;
00122     while (*linebufp != '\0')
00123     {
00124         if (*linebufp != '\t')
00125             linebufp++;
00126         else
00127         {
00128             if (colx > tab->file->last_field)
00129                 return;
00130             *linebufp = '\0';   /* actually change the clipboard */
00131             fieldx = tab->file->col_to_field[colx];
00132             gtk_sheet_set_cell_text (tab->view->sheet, sheet_row,
00133                 colx, prevbufp);
00134             *linebufp = '\t';   /* restore the clipboard */
00135 
00136             prevbufp = ++linebufp;
00137             colx++;
00138         }
00139     }
00140 }   /* end of actual_paste */

void edit_paste ( GtkAction G_GNUC_UNUSED *  w,
gpointer  data 
)

Bug:
last_row shouldn't be changed here

Definition at line 247 of file edit.c.

00248 {
00249     gint rowx;
00250     gint start_row;
00251     gint start_col;
00252     gint cb_row;
00253     gint sheet_row;
00254     QlContext * qlc;
00255     QlTabData * tab;
00256 
00257     qlc = ql_get_context (GTK_WIDGET(data));
00258     tab = ql_get_tabdata (qlc);
00259     CHECK_CHANGED(tab);
00260 /*  if (!paste_is_ok ())
00261         return;*/
00262     start_row = tab->view->sel_range.row0;
00263     start_col = tab->view->sel_range.col0;
00264     big_draw_start (tab);
00265 
00266     /* paste rows */
00267     if (tab->view->cb_sel_type == SELECT_ROW)
00268     {
00269         gtk_sheet_insert_rows (tab->view->sheet,
00270             start_row, tab->view->cb_rows);
00272         tab->file->last_row += tab->view->cb_rows;
00273         for (rowx = 0; rowx < tab->view->cb_rows; rowx++)
00274         {
00275             gtk_sheet_row_button_add_label (tab->view->sheet,
00276                 start_row + rowx, " ");
00277             actual_paste (tab, start_row + rowx, rowx, 0);
00278         }
00279         big_draw_end (tab);
00280         front_is_changed (tab);
00281         return;
00282     }   /* end of type R */
00283 
00284     /* paste the rest */
00285     cb_row = 0;
00286     sheet_row = start_row;
00287     while (cb_row < tab->view->cb_rows)
00288     {
00289         if (sheet_row >= tab->file->last_row)
00290             add1row (tab);
00291         if (row_is_visible (tab, sheet_row))
00292         {
00293             actual_paste (tab, sheet_row, cb_row, start_col);
00294             cb_row++;
00295         }
00296         sheet_row++;
00297     }
00298     big_draw_end (tab);
00299     front_is_changed (tab);
00300 }   /* end of edit_paste */

static void put_range_on_clipboard ( QlTabData tab  )  [static]

Todo:
does QL really need to manage the clipboard itself?

Definition at line 353 of file edit.c.

00354 {
00355     gchar linebuf[4096];
00356     gchar *text;
00357     gchar *linebufp;
00358     gint rowx;
00359     gint16 colx;
00360 
00361     /* get rid of previous contents, if any */
00362     if (tab->view->cb_rows)
00363         for (rowx = 0; rowx < tab->view->cb_rows; rowx++)
00364             g_free (tab->view->cb[rowx]);
00365     tab->view->cb_sel_type = tab->view->sel_type;
00366     tab->view->cb_rows = 0;
00367     tab->view->cb_cols = tab->view->sel_range.coli - tab->view->sel_range.col0 + 1;
00368 
00369     for (rowx = tab->view->sel_range.row0;
00370         rowx <= tab->view->sel_range.rowi; rowx++)
00371     {
00372         if (row_is_visible (tab, rowx))
00373         {
00374             if (tab->view->cb_rows >= MAX_CLIPBOARD - 2)
00375                 level1_error (tab, _("Clipboard is limited to 5,000 rows"));
00376             linebufp = linebuf;
00377             for (colx = tab->view->sel_range.col0;
00378                 colx <= tab->view->sel_range.coli; colx++)
00379             {
00380                 text = gtk_sheet_cell_get_text (tab->view->sheet,
00381                     rowx, colx);
00382                 if (text)
00383                 {
00384                     strcpy (linebufp, text);
00385                     linebufp += strlen (text);
00386                 }
00387                 *linebufp++ = '\t';
00388             }
00389             *linebufp = '\0';
00390             tab->view->cb[tab->view->cb_rows] = g_strdup (linebuf);
00391             tab->view->cb_rows++;
00392         }
00393     }
00394 }


Generated on Mon Jan 28 22:02:10 2008 for quicklist by  doxygen 1.5.4