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

📄 text.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
      XtOffset(TextWidget, text.pendingDelete), XmRString, "True"},    {textNautoWrap, textCAutoWrap, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.autoWrap), XmRString, "True"},    {textNcontinuousWrap, textCContinuousWrap, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.continuousWrap), XmRString, "True"},    {textNautoIndent, textCAutoIndent, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.autoIndent), XmRString, "True"},    {textNsmartIndent, textCSmartIndent, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.smartIndent), XmRString, "False"},    {textNoverstrike, textCOverstrike, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.overstrike), XmRString, "False"},    {textNheavyCursor, textCHeavyCursor, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.heavyCursor), XmRString, "False"},    {textNreadOnly, textCReadOnly, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.readOnly), XmRString, "False"},    {textNhidePointer, textCHidePointer, XmRBoolean, sizeof(Boolean),      XtOffset(TextWidget, text.hidePointer), XmRString, "False"},    {textNwrapMargin, textCWrapMargin, XmRInt, sizeof(int),      XtOffset(TextWidget, text.wrapMargin), XmRString, "0"},    {textNhScrollBar, textCHScrollBar, XmRWidget, sizeof(Widget),      XtOffset(TextWidget, text.hScrollBar), XmRString, ""},    {textNvScrollBar, textCVScrollBar, XmRWidget, sizeof(Widget),      XtOffset(TextWidget, text.vScrollBar), XmRString, ""},    {textNlineNumCols, textCLineNumCols, XmRInt, sizeof(int),      XtOffset(TextWidget, text.lineNumCols), XmRString, "0"},    {textNautoShowInsertPos, textCAutoShowInsertPos, XmRBoolean,      sizeof(Boolean), XtOffset(TextWidget, text.autoShowInsertPos),      XmRString, "True"},    {textNautoWrapPastedText, textCAutoWrapPastedText, XmRBoolean,      sizeof(Boolean), XtOffset(TextWidget, text.autoWrapPastedText),      XmRString, "False"},    {textNwordDelimiters, textCWordDelimiters, XmRString, sizeof(char *),      XtOffset(TextWidget, text.delimiters), XmRString,      ".,/\\`'!@#%^&*()-=+{}[]\":;<>?"},    {textNblinkRate, textCBlinkRate, XmRInt, sizeof(int),      XtOffset(TextWidget, text.cursorBlinkRate), XmRString, "500"},    {textNemulateTabs, textCEmulateTabs, XmRInt, sizeof(int),      XtOffset(TextWidget, text.emulateTabs), XmRString, "0"},    {textNfocusCallback, textCFocusCallback, XmRCallback, sizeof(caddr_t),      XtOffset(TextWidget, text.focusInCB), XtRCallback, NULL},    {textNlosingFocusCallback, textCLosingFocusCallback, XmRCallback,      sizeof(caddr_t), XtOffset(TextWidget, text.focusOutCB), XtRCallback,NULL},    {textNcursorMovementCallback, textCCursorMovementCallback, XmRCallback,      sizeof(caddr_t), XtOffset(TextWidget, text.cursorCB), XtRCallback, NULL},    {textNdragStartCallback, textCDragStartCallback, XmRCallback,      sizeof(caddr_t), XtOffset(TextWidget, text.dragStartCB), XtRCallback,      NULL},    {textNdragEndCallback, textCDragEndCallback, XmRCallback,      sizeof(caddr_t), XtOffset(TextWidget, text.dragEndCB), XtRCallback, NULL},    {textNsmartIndentCallback, textCSmartIndentCallback, XmRCallback,      sizeof(caddr_t), XtOffset(TextWidget, text.smartIndentCB), XtRCallback,      NULL},    {textNcursorVPadding, textCCursorVPadding, XtRCardinal, sizeof(Cardinal),      XtOffset(TextWidget, text.cursorVPadding), XmRString, "0"}};static TextClassRec textClassRec = {     /* CoreClassPart */  {    (WidgetClass) &xmPrimitiveClassRec,  /* superclass       */    "Text",                         /* class_name            */    sizeof(TextRec),                /* widget_size           */    NULL,                           /* class_initialize      */    NULL,                           /* class_part_initialize */    FALSE,                          /* class_inited          */    (XtInitProc)initialize,         /* initialize            */    NULL,                           /* initialize_hook       */    realize,   		            /* realize               */    actionsList,                    /* actions               */    XtNumber(actionsList),          /* num_actions           */    resources,                      /* resources             */    XtNumber(resources),            /* num_resources         */    NULLQUARK,                      /* xrm_class             */    TRUE,                           /* compress_motion       */    TRUE,                           /* compress_exposure     */    TRUE,                           /* compress_enterleave   */    FALSE,                          /* visible_interest      */    (XtWidgetProc)destroy,          /* destroy               */    (XtWidgetProc)resize,           /* resize                */    (XtExposeProc)redisplay,        /* expose                */    (XtSetValuesFunc)setValues,     /* set_values            */    NULL,                           /* set_values_hook       */    XtInheritSetValuesAlmost,       /* set_values_almost     */    NULL,                           /* get_values_hook       */    NULL,                           /* accept_focus          */    XtVersion,                      /* version               */    NULL,                           /* callback private      */    defaultTranslations,            /* tm_table              */    queryGeometry,                  /* query_geometry        */    NULL,                           /* display_accelerator   */    NULL,                           /* extension             */  },  /* Motif primitive class fields */  {     (XtWidgetProc)_XtInherit,   	/* Primitive border_highlight   */     (XtWidgetProc)_XtInherit,   	/* Primitive border_unhighlight */     NULL, /*XtInheritTranslations,*/	/* translations                 */     NULL,				/* arm_and_activate             */     NULL,				/* get resources      		*/     0,					/* num get_resources  		*/     NULL,         			/* extension                    */  },  /* Text class part */  {    0,                              	/* ignored	                */  }};WidgetClass textWidgetClass = (WidgetClass)&textClassRec;#define NEDIT_HIDE_CURSOR_MASK (KeyPressMask)#define NEDIT_SHOW_CURSOR_MASK (FocusChangeMask | PointerMotionMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask)static char empty_bits[] = {0x00, 0x00, 0x00, 0x00};static Cursor empty_cursor = 0;/*** Widget initialize method*/static void initialize(TextWidget request, TextWidget new){    XFontStruct *fs = new->text.fontStruct;    char *delimiters;    textBuffer *buf;    Pixel white, black;    int textLeft;    int charWidth = fs->max_bounds.width;    int marginWidth = new->text.marginWidth;    int lineNumCols = new->text.lineNumCols;        /* Set the initial window size based on the rows and columns resources */    if (request->core.width == 0)    	new->core.width = charWidth * new->text.columns + marginWidth*2 +	       (lineNumCols == 0 ? 0 : marginWidth + charWidth * lineNumCols);    if (request->core.height == 0)   	new->core.height = (fs->ascent + fs->descent) * new->text.rows +   		new->text.marginHeight * 2;        /* The default colors work for B&W as well as color, except for       selectFGPixel and selectBGPixel, where color highlighting looks       much better without reverse video, so if we get here, and the       selection is totally unreadable because of the bad default colors,       swap the colors and make the selection reverse video */    white = WhitePixelOfScreen(XtScreen((Widget)new));    black = BlackPixelOfScreen(XtScreen((Widget)new));    if (    new->text.selectBGPixel == white &&    	    new->core.background_pixel == white &&    	    new->text.selectFGPixel == black &&    	    new->primitive.foreground == black) {    	new->text.selectBGPixel = black;    	new->text.selectFGPixel = white;    }        /* Create the initial text buffer for the widget to display (which can       be replaced later with TextSetBuffer) */    buf = BufCreate();        /* Create and initialize the text-display part of the widget */    textLeft = new->text.marginWidth +	    (lineNumCols == 0 ? 0 : marginWidth + charWidth * lineNumCols);    new->text.textD = TextDCreate((Widget)new, new->text.hScrollBar,	    new->text.vScrollBar, textLeft, new->text.marginHeight,	    new->core.width - marginWidth - textLeft,	    new->core.height - new->text.marginHeight * 2,	    lineNumCols == 0 ? 0 : marginWidth,	    lineNumCols == 0 ? 0 : lineNumCols * charWidth,	    buf, new->text.fontStruct, new->core.background_pixel,	    new->primitive.foreground, new->text.selectFGPixel,	    new->text.selectBGPixel, new->text.highlightFGPixel,	    new->text.highlightBGPixel, new->text.cursorFGPixel,	    new->text.lineNumFGPixel,          new->text.continuousWrap, new->text.wrapMargin,          new->text.backlightCharTypes, new->text.calltipFGPixel,          new->text.calltipBGPixel);    /* Add mandatory delimiters blank, tab, and newline to the list of       delimiters.  The memory use scheme here is that new values are       always copied, and can therefore be safely freed on subsequent       set-values calls or destroy */    delimiters = XtMalloc(strlen(new->text.delimiters) + 4);    sprintf(delimiters, "%s%s", " \t\n", new->text.delimiters);    new->text.delimiters = delimiters;    /* Start with the cursor blanked (widgets don't have focus on creation,       the initial FocusIn event will unblank it and get blinking started) */    new->text.textD->cursorOn = False;        /* Initialize the widget variables */    new->text.autoScrollProcID = 0;    new->text.cursorBlinkProcID = 0;    new->text.dragState = NOT_CLICKED;    new->text.multiClickState = NO_CLICKS;    new->text.lastBtnDown = 0;    new->text.selectionOwner = False;    new->text.motifDestOwner = False;    new->text.emTabsBeforeCursor = 0;#ifndef NO_XMIM    /* Register the widget to the input manager */    XmImRegister((Widget)new, 0);    /* In case some Resources for the IC need to be set, add them below */    XmImVaSetValues((Widget)new, NULL);#endif    XtAddEventHandler((Widget)new, GraphicsExpose, True,            (XtEventHandler)redisplayGE, (Opaque)NULL);    if (new->text.hidePointer) {        Display *theDisplay;        Pixmap empty_pixmap;        XColor black_color;        /* Set up the empty Cursor */        if (empty_cursor == 0) {            theDisplay = XtDisplay((Widget)new);            empty_pixmap = XCreateBitmapFromData(theDisplay,                    RootWindowOfScreen(XtScreen((Widget)new)), empty_bits, 1, 1);            XParseColor(theDisplay, DefaultColormapOfScreen(XtScreen((Widget)new)),                     "black", &black_color);            empty_cursor = XCreatePixmapCursor(theDisplay, empty_pixmap,                     empty_pixmap, &black_color, &black_color, 0, 0);        }        /* Add event handler to hide the pointer on keypresses */        XtAddEventHandler((Widget)new, NEDIT_HIDE_CURSOR_MASK, False,                 handleHidePointer, (Opaque)NULL);    }}/* Hide the pointer while the user is typing */static void handleHidePointer(Widget w, XtPointer unused,         XEvent *event, Boolean *continue_to_dispatch) {    TextWidget tw = (TextWidget) w;    ShowHidePointer(tw, True);}/* Restore the pointer if the mouse moves or focus changes */static void handleShowPointer(Widget w, XtPointer unused,         XEvent *event, Boolean *continue_to_dispatch) {    TextWidget tw = (TextWidget) w;    ShowHidePointer(tw, False);}void ShowHidePointer(TextWidget w, Boolean hidePointer){    if (w->text.hidePointer) {        if (hidePointer != w->text.textD->pointerHidden) {            if (hidePointer) {                /* Don't listen for keypresses any more */                XtRemoveEventHandler((Widget)w, NEDIT_HIDE_CURSOR_MASK, False,                         handleHidePointer, (Opaque)NULL);                /* Switch to empty cursor */                XDefineCursor(XtDisplay(w), XtWindow(w), empty_cursor);                w->text.textD->pointerHidden = True;                /* Listen to mouse movement, focus change, and button presses */                XtAddEventHandler((Widget)w, NEDIT_SHOW_CURSOR_MASK,                        False, handleShowPointer, (Opaque)NULL);            }            else {                /* Don't listen to mouse/focus events any more */                XtRemoveEventHandler((Widget)w, NEDIT_SHOW_CURSOR_MASK,                        False, handleShowPointer, (Opaque)NULL);                /* Switch to regular cursor */                XUndefineCursor(XtDisplay(w), XtWindow(w));                w->text.textD->pointerHidden = False;                /* Listen for keypresses now */                XtAddEventHandler((Widget)w, NEDIT_HIDE_CURSOR_MASK, False,                         handleHidePointer, (Opaque)NULL);            }        }    }}/*** Widget destroy method*/static void destroy(TextWidget w){    textBuffer *buf;        /* Free the text display and possibly the attached buffer.  The buffer       is freed only if after removing all of the modify procs (by calling       StopHandlingXSelections and TextDFree) there are no modify procs       left */    StopHandlingXSelections((Widget)w);    buf = w->text.textD->buffer;    TextDFree(w->text.textD);    if (buf->nModifyProcs == 0)    	BufFree(buf);    if (w->text.cursorBlinkProcID != 0)    	XtRemoveTimeOut(w->text.cursorBlinkProcID);    XtFree(w->text.delimiters);    XtRemoveAllCallbacks((Widget)w, textNfocusCallback);    XtRemoveAllCallbacks((Widget)w, textNlosingFocusCallback);    XtRemoveAllCallbacks((Widget)w, textNcursorMovementCallback);    XtRemoveAllCallbacks((Widget)w, textNdragStartCallback);    XtRemoveAllCallbacks((Widget)w, textNdragEndCallback);#ifndef NO_XMIM    /* Unregister the widget from the input manager */    XmImUnregister((Widget)w);#endif}/*** Widget resize method.  Called when the size of the widget changes*/static void resize(TextWidget w){    XFontStruct *fs = w->text.fontStruct;    int height = w->core.height, width = w->core.width;    int marginWidth = w->text.marginWidth, marginHeight = w->text.marginHeight;    int lineNumAreaWidth = w->text.lineNumCols == 0 ? 0 : w->text.marginWidth +		fs->max_bounds.width * w->text.lineNumCols;    w->text.columns = (width - marginWidth*2 - lineNumAreaWidth) /    	    fs->max_bounds.width;    w->text.rows = (height - marginHeight*2) / (fs->ascent + fs->descent);        /* Reject widths and heights less than a character, which the text       display can't tolerate.  This is not strictly legal, but I've seen       it done in other widgets and it seems to do no serious harm.  NEdit       prevents panes from getting smaller than one line, but sometimes

⌨️ 快捷键说明

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