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

📄 text.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
static const char CVSID[] = "$Id: text.c,v 1.43.2.2 2003/08/13 16:22:15 edg Exp $";/********************************************************************************									       ** text.c - Display text from a text buffer				       **									       ** Copyright (C) 1999 Mark Edel						       **									       ** This is free software; you can redistribute it and/or modify it under the    ** terms of the GNU General Public License as published by the Free Software    ** Foundation; either version 2 of the License, or (at your option) any later   ** version.							               ** 									       ** This software 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 General Public License        ** for more details.							       ** 									       ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple     ** Place, Suite 330, Boston, MA  02111-1307 USA		                       **									       ** Nirvana Text Editor	    						       ** June 15, 1995								       **									       ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "text.h"#include "textP.h"#include "textBuf.h"#include "textDisp.h"#include "textSel.h"#include "textDrag.h"#include "nedit.h"#include "calltips.h"#include <stdio.h>#include <stdlib.h>#include <limits.h>#include <string.h>#include <ctype.h>#ifdef VMS#include "../util/VMSparam.h"#else#ifndef __MVS__#include <sys/param.h>#endif#endif /*VMS*/#include <limits.h>#include <X11/Intrinsic.h>#include <X11/IntrinsicP.h>#include <X11/StringDefs.h>#include <X11/cursorfont.h>#include <Xm/Xm.h>#include <Xm/XmP.h>#if XmVersion >= 1002#include <Xm/PrimitiveP.h>#endif#ifdef HAVE_DEBUG_H#include "../debug.h"#endif#ifdef UNICOS#define XtOffset(p_type,field) ((size_t)__INTADDR__(&(((p_type)0)->field)))#endif/* Number of pixels of motion from the initial (grab-focus) button press   required to begin recognizing a mouse drag for the purpose of making a   selection */#define SELECT_THRESHOLD 5/* Length of delay in milliseconds for vertical autoscrolling */#define VERTICAL_SCROLL_DELAY 50static void initialize(TextWidget request, TextWidget new);static void handleHidePointer(Widget w, XtPointer unused,         XEvent *event, Boolean *continue_to_dispatch);static void handleShowPointer(Widget w, XtPointer unused,         XEvent *event, Boolean *continue_to_dispatch);static void redisplay(TextWidget w, XEvent *event, Region region);static void redisplayGE(TextWidget w, XtPointer client_data,                    XEvent *event, Boolean *continue_to_dispatch_return);static void destroy(TextWidget w);static void resize(TextWidget w);static Boolean setValues(TextWidget current, TextWidget request,	TextWidget new);static void realize(Widget w, XtValueMask *valueMask,	XSetWindowAttributes *attributes);static XtGeometryResult queryGeometry(Widget w, XtWidgetGeometry *proposed,	XtWidgetGeometry *answer);static void grabFocusAP(Widget w, XEvent *event, String *args,	Cardinal *n_args);static void moveDestinationAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void extendAdjustAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void extendStartAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void extendEndAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void processCancelAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void secondaryStartAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void secondaryOrDragStartAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void secondaryAdjustAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void secondaryOrDragAdjustAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void copyToAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void copyToOrEndDragAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void copyPrimaryAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void cutPrimaryAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void moveToAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void moveToOrEndDragAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void endDragAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void exchangeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void mousePanAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void pasteClipboardAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void copyClipboardAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void cutClipboardAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void insertStringAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void selfInsertAP(Widget w, XEvent *event, String *args,	Cardinal *n_args);static void newlineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void newlineAndIndentAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void newlineNoIndentAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void processTabAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void endOfLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void beginningOfLineAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deleteSelectionAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deletePreviousCharacterAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deleteNextCharacterAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deletePreviousWordAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deleteNextWordAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deleteToStartOfLineAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deleteToEndOfLineAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void forwardCharacterAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void backwardCharacterAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void forwardWordAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void backwardWordAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void forwardParagraphAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void backwardParagraphAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void keySelectAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void processUpAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void processShiftUpAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void processDownAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void processShiftDownAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void beginningOfFileAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void endOfFileAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void nextPageAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void previousPageAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void pageLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void pageRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);static void toggleOverstrikeAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void scrollUpAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void scrollDownAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void scrollLeftAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void scrollRightAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void scrollToLineAP(Widget w, XEvent *event, String *args,    	Cardinal *nArgs);static void selectAllAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void deselectAllAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void focusInAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void focusOutAP(Widget w, XEvent *event, String *args,	Cardinal *nArgs);static void checkMoveSelectionChange(Widget w, XEvent *event, int startPos,	String *args, Cardinal *nArgs);static void keyMoveExtendSelection(Widget w, XEvent *event, int startPos,	int rectangular);static void checkAutoShowInsertPos(Widget w);static int checkReadOnly(Widget w);static void simpleInsertAtCursor(Widget w, char *chars, XEvent *event,    	int allowPendingDelete);static int pendingSelection(Widget w);static int deletePendingSelection(Widget w, XEvent *event);static int deleteEmulatedTab(Widget w, XEvent *event);static void selectWord(Widget w, int pointerX);static int spanForward(textBuffer *buf, int startPos, char *searchChars,	int ignoreSpace, int *foundPos);static int spanBackward(textBuffer *buf, int startPos, char *searchChars, int    	ignoreSpace, int *foundPos);static void selectLine(Widget w);static int startOfWord(TextWidget w, int pos);static int endOfWord(TextWidget w, int pos);static void checkAutoScroll(TextWidget w, int x, int y);static void endDrag(Widget w);static void cancelDrag(Widget w);static void callCursorMovementCBs(Widget w, XEvent *event);static void adjustSelection(TextWidget tw, int x, int y);static void adjustSecondarySelection(TextWidget tw, int x, int y);static void autoScrollTimerProc(XtPointer clientData, XtIntervalId *id);static char *wrapText(TextWidget tw, char *startLine, char *text, int bufOffset,    	int wrapMargin, int *breakBefore);static int wrapLine(TextWidget tw, textBuffer *buf, int bufOffset,    	int lineStartPos, int lineEndPos, int limitPos, int *breakAt,	int *charsAdded);static char *createIndentString(TextWidget tw, textBuffer *buf, int bufOffset,    	int lineStartPos, int lineEndPos, int *length, int *column);static void cursorBlinkTimerProc(XtPointer clientData, XtIntervalId *id);static int hasKey(const char *key, const String *args, const Cardinal *nArgs);static int max(int i1, int i2);static int min(int i1, int i2);static int strCaseCmp(const char *str1, const char *str2);static void ringIfNecessary(Boolean silent, Widget w);static char defaultTranslations[] =     /* Backspace */    "Ctrl<KeyPress>osfBackSpace: delete_previous_word()\n"    "<KeyPress>osfBackSpace: delete_previous_character()\n"    /* Delete */    "Alt Shift Ctrl<KeyPress>osfDelete: cut_primary(\"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfDelete: cut_primary(\"rect\")\n"    "Shift Ctrl<KeyPress>osfDelete: cut_primary()\n"    "Ctrl<KeyPress>osfDelete: delete_to_end_of_line()\n"    "Shift<KeyPress>osfDelete: cut_clipboard()\n"    "<KeyPress>osfDelete: delete_next_character()\n"    /* Insert */    "Alt Shift Ctrl<KeyPress>osfInsert: copy_primary(\"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfInsert: copy_primary(\"rect\")\n"    "Shift Ctrl<KeyPress>osfInsert: copy_primary()\n"    "Shift<KeyPress>osfInsert: paste_clipboard()\n"    "Ctrl<KeyPress>osfInsert: copy_clipboard()\n"    "~Shift ~Ctrl<KeyPress>osfInsert: toggle_overstrike()\n"    /* Cut/Copy/Paste */    "Shift Ctrl<KeyPress>osfCut: cut_primary()\n"    "<KeyPress>osfCut: cut_clipboard()\n"    "<KeyPress>osfCopy: copy_clipboard()\n"    "<KeyPress>osfPaste: paste_clipboard()\n"    "<KeyPress>osfPrimaryPaste: copy_primary()\n"    /* BeginLine */    "Alt Shift Ctrl<KeyPress>osfBeginLine: beginning_of_file(\"extend\", \"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfBeginLine: beginning_of_file(\"extend\" \"rect\")\n"    "Alt Shift<KeyPress>osfBeginLine: beginning_of_line(\"extend\", \"rect\")\n"    "Meta Shift<KeyPress>osfBeginLine: beginning_of_line(\"extend\", \"rect\")\n"    "Shift Ctrl<KeyPress>osfBeginLine: beginning_of_file(\"extend\")\n"    "Ctrl<KeyPress>osfBeginLine: beginning_of_file()\n"    "Shift<KeyPress>osfBeginLine: beginning_of_line(\"extend\")\n"    "~Alt~Shift~Ctrl~Meta<KeyPress>osfBeginLine: beginning_of_line()\n"    /* EndLine */    "Alt Shift Ctrl<KeyPress>osfEndLine: end_of_file(\"extend\", \"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfEndLine: end_of_file(\"extend\", \"rect\")\n"    "Alt Shift<KeyPress>osfEndLine: end_of_line(\"extend\", \"rect\")\n"    "Meta Shift<KeyPress>osfEndLine: end_of_line(\"extend\", \"rect\")\n"    "Shift Ctrl<KeyPress>osfEndLine: end_of_file(\"extend\")\n"    "Ctrl<KeyPress>osfEndLine: end_of_file()\n"    "Shift<KeyPress>osfEndLine: end_of_line(\"extend\")\n"    "~Alt~Shift~Ctrl~Meta<KeyPress>osfEndLine: end_of_line()\n"    /* Left */    "Alt Shift Ctrl<KeyPress>osfLeft: backward_word(\"extend\", \"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfLeft: backward_word(\"extend\", \"rect\")\n"    "Alt Shift<KeyPress>osfLeft: key_select(\"left\", \"rect\")\n"    "Meta Shift<KeyPress>osfLeft: key_select(\"left\", \"rect\")\n"    "Shift Ctrl<KeyPress>osfLeft: backward_word(\"extend\")\n"    "Ctrl<KeyPress>osfLeft: backward_word()\n"    "Shift<KeyPress>osfLeft: key_select(\"left\")\n"    "~Alt~Shift~Ctrl~Meta<KeyPress>osfLeft: backward_character()\n"    /* Right */    "Alt Shift Ctrl<KeyPress>osfRight: forward_word(\"extend\", \"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfRight: forward_word(\"extend\", \"rect\")\n"    "Alt Shift<KeyPress>osfRight: key_select(\"right\", \"rect\")\n"    "Meta Shift<KeyPress>osfRight: key_select(\"right\", \"rect\")\n"    "Shift Ctrl<KeyPress>osfRight: forward_word(\"extend\")\n"    "Ctrl<KeyPress>osfRight: forward_word()\n"    "Shift<KeyPress>osfRight: key_select(\"right\")\n"    "~Alt~Shift~Ctrl~Meta<KeyPress>osfRight: forward_character()\n"    /* Up */    "Alt Shift Ctrl<KeyPress>osfUp: backward_paragraph(\"extend\", \"rect\")\n"    "Meta Shift Ctrl<KeyPress>osfUp: backward_paragraph(\"extend\", \"rect\")\n"    "Alt Shift<KeyPress>osfUp: process_shift_up(\"rect\")\n"    "Meta Shift<KeyPress>osfUp: process_shift_up(\"rect\")\n"    "Shift Ctrl<KeyPress>osfUp: backward_paragraph(\"extend\")\n"

⌨️ 快捷键说明

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