#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 "../util/DialogF.h"
#include "../util/xdnd.h"
#include "window.h"
#include "preferences.h"
#include "../util/nedit_malloc.h"
#include "help.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <ctype.h>
#include <sys/param.h>
#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
#ifndef XK_Control_L
#include <X11/keysym.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
#define SELECT_THRESHOLD 5
#define VERTICAL_SCROLL_DELAY 50
static 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 hscrollEH(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 cancelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
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 zoomInAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
static void zoomOutAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
#ifndef DISABLE_MULTICURSOR
static void addCursorUpAP(Widget w, XEvent *event, String *args,
Cardinal *nArgs);
static void addCursorDownAP(Widget w, XEvent *event, String *args,
Cardinal *nArgs);
#endif
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 void ringIfNecessary(Boolean silent, Widget w);
static XftColor defaultAnsiColors[
16];
static char defaultTranslations[] =
"~Shift ~Ctrl Alt<Key>osfBeginLine: last_document()\n"
"<KeyPress>osfCancel: cancel()\n"
"Alt<KeyPress>osfCancel: cancel()\n"
":<Key>KP_7: self_insert()\n"
":<Key>KP_8: self_insert()\n"
":<Key>KP_9: self_insert()\n"
":<Key>KP_4: self_insert()\n"
":<Key>KP_6: self_insert()\n"
":<Key>KP_1: self_insert()\n"
":<Key>KP_2: self_insert()\n"
":<Key>KP_3: self_insert()\n"
":<Key>KP_0: self_insert()\n"
":<Key>KP_Separator: self_insert()\n"
"Ctrl<KeyPress>osfBackSpace: delete_previous_word()\n"
"<KeyPress>osfBackSpace: delete_previous_character()\n"
"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"
"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: set_overtype_mode()\n"
"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"
"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"
"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"
"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"
"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"
#ifndef DISABLE_MULTICURSOR
"Ctrl Super<KeyPress>osfUp: add_cursor_up()\n"
#endif
"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<KeyPress>osfUp: backward_paragraph()\n"
"Shift<KeyPress>osfUp: process_shift_up()\n"
"~Alt~Shift~Ctrl~Meta<KeyPress>osfUp: process_up()\n"
#ifndef DISABLE_MULTICURSOR
"Ctrl Super<KeyPress>osfDown: add_cursor_down()\n"
#endif
"Alt Shift Ctrl<KeyPress>osfDown: forward_paragraph(\"extend\", \"rect\")\n"
"Meta Shift Ctrl<KeyPress>osfDown: forward_paragraph(\"extend\", \"rect\")\n"
"Alt Shift<KeyPress>osfDown: process_shift_down(\"rect\")\n"
"Meta Shift<KeyPress>osfDown: process_shift_down(\"rect\")\n"
"Shift Ctrl<KeyPress>osfDown: forward_paragraph(\"extend\")\n"
"Ctrl<KeyPress>osfDown: forward_paragraph()\n"
"Shift<KeyPress>osfDown: process_shift_down()\n"
"~Alt~Shift~Ctrl~Meta<KeyPress>osfDown: process_down()\n"
"Alt Shift Ctrl<KeyPress>osfPageUp: page_left(\"extend\", \"rect\")\n"
"Meta Shift Ctrl<KeyPress>osfPageUp: page_left(\"extend\", \"rect\")\n"
"Alt Shift<KeyPress>osfPageUp: previous_page(\"extend\", \"rect\")\n"
"Meta Shift<KeyPress>osfPageUp: previous_page(\"extend\", \"rect\")\n"
"Shift Ctrl<KeyPress>osfPageUp: page_left(\"extend\")\n"
"Ctrl<KeyPress>osfPageUp: previous_document()\n"
"Shift<KeyPress>osfPageUp: previous_page(\"extend\")\n"
"~Alt ~Shift ~Ctrl ~Meta<KeyPress>osfPageUp: previous_page()\n"
"Alt Shift Ctrl<KeyPress>osfPageDown: page_right(\"extend\", \"rect\")\n"
"Meta Shift Ctrl<KeyPress>osfPageDown: page_right(\"extend\", \"rect\")\n"
"Alt Shift<KeyPress>osfPageDown: next_page(\"extend\", \"rect\")\n"
"Meta Shift<KeyPress>osfPageDown: next_page(\"extend\", \"rect\")\n"
"Shift Ctrl<KeyPress>osfPageDown: page_right(\"extend\")\n"
"Ctrl<KeyPress>osfPageDown: next_document()\n"
"Shift<KeyPress>osfPageDown: next_page(\"extend\")\n"
"~Alt ~Shift ~Ctrl ~Meta<KeyPress>osfPageDown: next_page()\n"
"Alt Shift<KeyPress>osfPageLeft: page_left(\"extend\", \"rect\")\n"
"Meta Shift<KeyPress>osfPageLeft: page_left(\"extend\", \"rect\")\n"
"Shift<KeyPress>osfPageLeft: page_left(\"extend\")\n"
"~Alt ~Shift ~Ctrl ~Meta<KeyPress>osfPageLeft: page_left()\n"
"Alt Shift<KeyPress>osfPageRight: page_right(\"extend\", \"rect\")\n"
"Meta Shift<KeyPress>osfPageRight: page_right(\"extend\", \"rect\")\n"
"Shift<KeyPress>osfPageRight: page_right(\"extend\")\n"
"~Alt ~Shift ~Ctrl ~Meta<KeyPress>osfPageRight: page_right()\n"
"Ctrl <Key>+: zoom_in()\n"
"Ctrl <Key>-: zoom_out()\n"
"Ctrl <Key>KP_Add: zoom_in()\n"
"Ctrl <Key>KP_Subtract: zoom_out()\n"
"Shift<KeyPress>osfSelect: key_select()\n"
"<KeyPress>osfCancel: process_cancel()\n"
"Ctrl~Alt~Meta<KeyPress>v: paste_clipboard()\n"
"Ctrl~Alt~Meta<KeyPress>c: copy_clipboard()\n"
"Ctrl~Alt~Meta<KeyPress>x: cut_clipboard()\n"
"Ctrl~Alt~Meta<KeyPress>u: delete_to_start_of_line()\n"
"Ctrl<KeyPress>Return: newline_and_indent()\n"
"Shift<KeyPress>Return: newline_no_indent()\n"
"<KeyPress>Return: newline()\n"
"Shift<KeyPress>osfActivate: newline_no_indent()\n"
"<KeyPress>osfActivate: newline()\n"
"Ctrl<KeyPress>Tab: self_insert()\n"
"<KeyPress>Tab: process_tab()\n"
"Alt Shift Ctrl<KeyPress>space: key_select(\"rect\")\n"
"Meta Shift Ctrl<KeyPress>space: key_select(\"rect\")\n"
"Shift Ctrl~Meta~Alt<KeyPress>space: key_select()\n"
"Ctrl~Meta~Alt<KeyPress>slash: select_all()\n"
"Ctrl~Meta~Alt<KeyPress>backslash: deselect_all()\n"
"<KeyPress>: self_insert()\n"
"Alt Ctrl<Btn1Down>: move_destination()\n"
"Meta Ctrl<Btn1Down>: move_destination()\n"
"Shift Ctrl<Btn1Down>: extend_start(\"rect\")\n"
"Shift<Btn1Down>: extend_start()\n"
#ifndef DISABLE_MULTICURSOR
"Ctrl<Btn1Down>: grab_focus(\"mc\")\n"
#endif
"<Btn1Down>: grab_focus()\n"
"Button1 Ctrl<MotionNotify>: extend_adjust(\"rect\")\n"
"Button1~Ctrl<MotionNotify>: extend_adjust()\n"
"<Btn1Up>: extend_end()\n"
"<Btn2Down>: secondary_or_drag_start()\n"
"Shift Ctrl Button2<MotionNotify>: secondary_or_drag_adjust(\"rect\", \"copy\", \"overlay\")\n"
"Shift Button2<MotionNotify>: secondary_or_drag_adjust(\"copy\")\n"
"Ctrl Button2<MotionNotify>: secondary_or_drag_adjust(\"rect\", \"overlay\")\n"
"Button2<MotionNotify>: secondary_or_drag_adjust()\n"
"Shift Ctrl<Btn2Up>: move_to_or_end_drag(\"copy\", \"overlay\")\n"
"Shift <Btn2Up>: move_to_or_end_drag(\"copy\")\n"
"Alt<Btn2Up>: exchange()\n"
"Meta<Btn2Up>: exchange()\n"
"Ctrl<Btn2Up>: copy_to_or_end_drag(\"overlay\")\n"
"<Btn2Up>: copy_to_or_end_drag()\n"
"Ctrl~Meta~Alt<Btn3Down>: mouse_pan()\n"
"Ctrl~Meta~Alt Button3<MotionNotify>: mouse_pan()\n"
"<Btn3Up>: end_drag()\n"
"<FocusIn>: focusIn()\n"
"<FocusOut>: focusOut()\n"
"Shift<Btn4Down>,<Btn4Up>: scroll_up(1)\n"
"Shift<Btn5Down>,<Btn5Up>: scroll_down(1)\n"
"Ctrl<Btn4Down>,<Btn4Up>: scroll_up(1, pages)\n"
"Ctrl<Btn5Down>,<Btn5Up>: scroll_down(1, pages)\n"
"<Btn4Down>,<Btn4Up>,<MotionNotify>(1+): extend_adjust()\n"
"<Btn5Down>,<Btn5Up>,<MotionNotify>(1+): extend_adjust()\n"
"<Btn4Down>,<Btn4Up>: scroll_up(5)\n"
"<Btn5Down>,<Btn5Up>: scroll_down(5)\n";