⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipper.c

📁 This source code has been tested under OpenWindows 2.0, Sun s X11/NeWS server. For Xlib programs th
💻 C
字号:
/*************************************************************************                                                                    ****  clipper.c                                                         ****                                                                    ****  Text Editor -- Clipboard Interface Module                         ****                                                                    *************************************************************************/#include <stdio.h>#include <Xm/Text.h>#include <Xm/CutPaste.h>#include <X11/Xatom.h>#include "textedit.h"/*************************************************************************                                                                    ****               F O R W A R D   D E F I N I T I O N S                ****                                                                    *************************************************************************/static	char	*GetTextSelection();static	void	RplTextSelection();/*************************************************************************                                                                    ****                    L O C A L   V A R I A B L E S                   ****                                                                    *************************************************************************/static	XmString    prog_name;		/* Name of application	      */static	Display	    *clip_disp;		/* Our display connection     */static	Window	    clip_win;		/* Window associated with cpy */static	char	    *data_type;		/* String for XA_STRING       *//*************************************************************************                                                                    ****  InitClipper()                                                     ****                                                                    ****  This function creates some module-static variables, which hold    ****  identification information needed by all clipboard calls.         ****                                                                    *************************************************************************/void InitClipper(){    prog_name = XmStringCreate( "TextEdit", XmSTRING_DEFAULT_CHARSET );    clip_disp = XtDisplay( appshell );    clip_win  = None;    data_type = XGetAtomName( clip_disp, XA_STRING );}/*************************************************************************                                                                    ****  ClipCut( time )                                                   ****                                                                    ****  Called from the Edit/Cut menu item, this function copies the      ****  current work window selection to the clipboard, then deletes      ****  it. To perform the copy, it calls ClipCopy().                     ****                                                                    ****  The "time" parameter comes from the invoking event, and is used   ****  by the selection mechanism.                                       ****                                                                    *************************************************************************/void ClipCut( time )    Time	time;{    ClipCopy( time );    RplTextSelection( "" );}/*************************************************************************                                                                    ****  ClipCopy( time )                                                  ****                                                                    ****  Called from the Edit/Cut menu item, this function copies the      ****  current work window selection to the clipboard. It is also        ****  called by the function ClipCut, to localize clipboard access.     ****                                                                    ****  The "time" parameter comes from the invoking event, and is used   ****  by the selection mechanism.                                       ****                                                                    *************************************************************************/void ClipCopy( time )    Time	time;{    char	*txtsel;    int		txtlen;    int		clipstat;    long	clip_id;    int		tries;        if (clip_win == None)        clip_win = XtWindow( appshell );    txtsel = GetTextSelection();    txtlen = strlen( txtsel ) + 1;    tries = 0;    do    	clipstat = XmClipboardStartCopy( clip_disp, clip_win, prog_name,                                          time, NULL, NULL, &clip_id );    while ((clipstat != ClipboardSuccess) && (tries++ < 8));    if (tries == 8)	{	/* Display alert here */	XtFree( txtsel );	return;	}    XmClipboardCopy( clip_disp, clip_win, clip_id, data_type, 		     txtsel, txtlen, 0, NULL );    clipstat = XmClipboardEndCopy( clip_disp, clip_win, clip_id );    XtFree( txtsel );}/*************************************************************************                                                                    ****  ClipPaste( time )                                                 ****                                                                    ****  Called from the Edit/Paste menu item, this function copies the    ****  contents of the clipboard into the work window, at the current    ****  insertion point. If there is a current selection, it is replaced  ****  or not, depending on the contents of "pendingDelete".             ****                                                                    ****  The "time" parameter comes from the invoking event, and is used   ****  by the selection mechanism.                                       ****                                                                    *************************************************************************/void ClipPaste( time )    Time	time;{    int		clipstat;    long	data_len;    long	real_len;    char	*databuf;    long	text_pos;    int		tries;        if (clip_win == None)        clip_win = XtWindow( appshell );    tries = 0;    do	clipstat = XmClipboardLock( clip_disp, clip_win );    while ((clipstat == ClipboardLocked) && (tries++ < 8));    if (tries == 8)	{	/* Display alert here */	XmClipboardUnlock( clip_disp, clip_win, TRUE );	return;	}    clipstat = XmClipboardInquireLength( clip_disp, clip_win,                                          data_type, &data_len );    if (clipstat == ClipboardNoData)	return;    databuf = XtMalloc( data_len+1 );    XmClipboardStartRetrieve( clip_disp, clip_win, time );    clipstat = XmClipboardRetrieve( clip_disp, clip_win, data_type, databuf, 				    data_len, &real_len, NULL );    databuf[data_len] = '\0';    RplTextSelection( databuf );    XtFree( databuf );}/*************************************************************************                                                                    ****  GetTextSelection()                                                ****                                                                    ****  This function retrieves the current text selection -- or NULL,    ****  if there is no selection.                                         ****                                                                    *************************************************************************/static char *GetTextSelection(){    return( XmTextGetSelection(textwin) );}/*************************************************************************                                                                    ****  RplTextSelection( newtext )                                       ****                                                                    ****  This function replaces the current text selection with newtext.   ****  If there is no selection, newtext is inserted at the current      ****  insertion point.                                                  ****                                                                    *************************************************************************/static void RplTextSelection( newtext )    char	*newtext;{    Boolean	stest,		pendel;    int		insertion,		sel_start,		sel_end;    XtSetArg( arglist[0], XmNcursorPosition, &insertion );    XtSetArg( arglist[1], XmNpendingDelete, &pendel );    XtGetValues( textwin, arglist, 2 );    stest = XmTextGetSelectionPosition( textwin, &sel_start, &sel_end );    if (!stest || !pendel)        sel_end = sel_start = insertion;    XmTextReplace( textwin, sel_start, sel_end, newtext );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -