📄 clipboard.c
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: clipboard.c,v 1.15 2001/03/20 22:19:33 ttabner Exp $ * * Copyright (C) 1999-2000 Bynari Inc. * Copyright (C) 2001 Project TradeClient * * LGPL * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library * General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "clipboard.h"#ifdef DMALLOC#include <dmalloc.h>#endif#define CLIPBOARDGtkWidget *focus_widget = NULL;char *clipboard = NULL;GtkWidget *popup = NULL;GList *undo_list = NULL;GList *undo_widgets = NULL;guint undo_level = 100;int ignore_next = FALSE;gboolean find_by_widget (UndoNode * node1, GtkWidget * widget){ if (node1->relative == widget) return FALSE; return TRUE;}GList *g_list_find_custom_filo (GList * list, gpointer data, GCompareFunc func){ GList *last; if (!func) return list; for (last = g_list_last (list); last; last = g_list_previous (last)) { if (!func (last->data, data)) return last; } return NULL;}voidclip_focus_in_event (GtkWidget * widget){ focus_widget = widget;}int selection_start = -1;int selection_end = -1;voidclip_button_press_event (GtkWidget * widget, GdkEventButton * button){ if (button->button == 3) { if (GTK_IS_EDITABLE (widget)) { focus_widget = widget; gtk_widget_grab_focus (widget); selection_start = GTK_EDITABLE (widget)->selection_start_pos; selection_end = GTK_EDITABLE (widget)->selection_end_pos; } else { selection_start = -1; selection_end = -1; } if (GTK_IS_WIDGET (popup)) { gtk_widget_destroy (popup); } popup = clip_create_menu (NULL, NULL); gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL, 3, 0); }}voidclip_button_press_event_after (GtkWidget * widget, GdkEventButton * button){ if (selection_start != -1 && selection_end != -1) { gtk_editable_select_region (GTK_EDITABLE (widget), selection_start, selection_end); selection_start = -1; selection_end = -1; }}voidclip_cut (GtkWidget * widget){ if (focus_widget) { if (GTK_WIDGET_HAS_FOCUS (focus_widget) && GTK_IS_EDITABLE (focus_widget)) { GtkEditable *edit = GTK_EDITABLE (focus_widget); if (clipboard) free (clipboard); clipboard = gtk_editable_get_chars (edit, edit->selection_start_pos, edit->selection_end_pos); gtk_editable_delete_selection (edit); } } return;}voidclip_copy (GtkWidget * widget){ if (!focus_widget) return; if (GTK_WIDGET_HAS_FOCUS (focus_widget) && GTK_IS_EDITABLE (focus_widget)) { GtkEditable *edit = GTK_EDITABLE (focus_widget); if (clipboard) free (clipboard); clipboard = gtk_editable_get_chars (edit, edit->selection_start_pos, edit->selection_end_pos); gtk_editable_copy_clipboard (GTK_EDITABLE (focus_widget)); }}voidclip_paste (GtkWidget * widget){ if (!focus_widget) return; if (GTK_WIDGET_HAS_FOCUS (focus_widget) && GTK_IS_EDITABLE (focus_widget)) { GtkEditable *edit = GTK_EDITABLE (focus_widget); int pos = edit->current_pos; if (clipboard) gtk_editable_insert_text (edit, clipboard, strlen (clipboard), &pos); }}voidclip_clear (GtkWidget * widget){ if (!focus_widget) return; if (GTK_WIDGET_HAS_FOCUS (focus_widget) && GTK_IS_EDITABLE (focus_widget)) { gtk_editable_delete_selection (GTK_EDITABLE (focus_widget)); }}voidclip_select_all (GtkWidget * widget){ if (!focus_widget) return; if (GTK_WIDGET_HAS_FOCUS (focus_widget) && GTK_IS_EDITABLE (focus_widget)) { gtk_editable_select_region (GTK_EDITABLE (focus_widget), 0, -1); }}voidclip_undo (GtkWidget * widget){ undo_undo ();}voidclear_undo_list (){ GList *seek = NULL; UndoNode *node; for (seek = undo_list; seek; seek = g_list_next (seek)) { node = seek->data; undo_list = g_list_remove (undo_list, seek->data); if (node) free (node); } undo_list = NULL; undo_undo ();}voidundo_destroy_notify (GtkWidget * widget, GdkEventAny * event){ GList *seek, *tmp = NULL; for (seek = undo_list; seek; seek = seek->next) { UndoNode *node = seek->data; if (node->relative == widget) tmp = g_list_append (tmp, node); } for (seek = tmp; seek; seek = seek->next) { UndoNode *node = seek->data;#if 0 if (node->last) free (node->last);#endif undo_list = g_list_remove (undo_list, seek->data); free (node); }}voidadd_node (UndoNode * node){ g_return_if_fail (node != NULL); if (g_list_length (undo_list) > undo_level) { GList *seek; GtkWidget *widget; UndoNode *undonode; widget = node->relative; seek = g_list_find_custom (undo_list, widget, (GCompareFunc) find_by_widget); if (seek) { seek = g_list_last (seek); undonode = seek->data; if (undonode->last) free (undonode->last); undonode->last = NULL; if (undonode->charecter) free (undonode->charecter); undo_list = g_list_remove (undo_list, undonode); free (undonode); } } undo_list = g_list_prepend (undo_list, node);}gintfind_offset (char *text1, char *text2){ guint len1 = strlen (text1); guint len2 = strlen (text2); guint count = 0; if (!text1) return -1; if (!text2) return -1; if (strcmp (text1, text2) == 0) return -1; while (count < len1 && count < len2 && text1[count] == text2[count]) count++; return count;}voidundo_undo (){ UndoNode *node; UndoNode *last; time_t timestamp; if (undo_list) { GList *gtmp; GtkEditable *edit; gint position; int dum = 0; int cont = TRUE; node = undo_list->data; timestamp = node->timestamp; while (cont && undo_list) { node = undo_list->data; if (!node) return; if (node->timestamp != timestamp) break; gtmp = g_list_find_custom (undo_list->next, node->relative,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -