📄 sedit.c
字号:
/*
COW : Character Oriented Windows
(COW USER DIALOG)
sedit.c : simple (single-line) edit wnd proc
*/
#define COW
#include <cow.h>
#include <uedit.h>
#include <uevent.h>
#include <udialog.h>
#include <vkey.h>
#include <uwindow.h>
#include <uscreen.h>
#include <uisa.h>
#include <uutil.h>
#include <kinput.h>
#include <kkeyboar.h>
#include "dialog.h"
#include "event.h"
#include "screen.h"
#include "util.h"
#include "overlap.h"
#include "edit.h" /* includes "sedit.h" */
#include "_sedit.h"
#ifndef EDIT_FULLMGR
/* forward */
STATIC VOID DisplayEb(PWND);
STATIC BOOL FAddCh(PWND, char);
STATIC VOID DelCh(PWND, WORD);
STATIC VOID MoveCursorLeft(PWND);
STATIC VOID MoveCursorRight(PWND);
STATIC VOID DelChLeft(PWND);
STATIC VOID DelChRight(PWND);
STATIC VOID MoveCursorBegin(PWND);
STATIC VOID MoveCursorEnd(PWND);
STATIC VOID HiliteEditSel(PWND, BOOL);
STATIC VOID DeleteSelection(PWND, char *);
STATIC VOID PasteSz(PWND, char *);
STATIC VOID CopySelection(PWND, char *);
STATIC VOID
DisplayEb(pwnd)
/*
-- display the text in the edit box
*/
REGISTER PWND pwnd;
{
WORD ichMac = pwnd->ichMacEb;
WORD cch;
RRC rrc;
/* For fixed length edit items:
In order to prevent scrolling to the right due to cursor
or mouse moves, we reset the left edge here */
if (pwnd->cchDialog != pwnd->cchMaxEb) pwnd->ichLeftEb = 0;
GetClientRrc(pwnd,&rrc);
cch = min( (WORD) rrc.rxRight, ichMac - pwnd->ichLeftEb);
#ifdef EDIT_SECRET
/* Secret edit items for password protection */
if (pwnd->style & ES_SECRET)
{
/* Fill edit item with chSecret */
RRC rrcFill;
rrcFill.rxLeft = rrcFill.ryTop = 0;
rrcFill.ryBottom = 1;
rrcFill.rxRight = (RX) cch;
FillRrc(pwnd, &rrcFill, chSecret, pwnd->isaEb);
}
else
#endif /*EDIT_SECRET*/
/*maybe*/TextOut(pwnd, 0, 0, (char *) pwnd->szDialog + pwnd->ichLeftEb,
cch, pwnd->isaEb);
/* fill trailing width with fill character */
rrc.rxLeft = (RX) cch;
FillRrc(pwnd, &rrc, (char) pwnd->chFillDialog, pwnd->isaEb);
}
STATIC BOOL
FAddCh(pwnd, ch)
/*
-- add a character at the cursor position
*/
REGISTER PWND pwnd;
char ch;
{
WORD ichCursor = pwnd->ichCursorEb;
short ichMac = pwnd->ichMacEb;
char *sz = SzEdit(pwnd);
RRC rrc;
RX rx;
if (ichMac >= pwnd->cchDialog)
return(FALSE);
rx = (RX) (ichCursor - pwnd->ichLeftEb);
if (ichMac >= pwnd->cchMaxEb)
{
if (ichCursor < pwnd->cchMaxEb)
{
sz[ichCursor] = ch;
pwnd->ichCursorEb++;
CharOut(pwnd, rx, 0, ch, pwnd->isaEb);
}
else
{
Beep();
}
return(TRUE);
}
GetClientRrc(pwnd,&rrc);
if ((rx >= rrc.rxRight-1)&&(pwnd->cchDialog == pwnd->cchMaxEb))
{
pwnd->ichLeftEb++;
BltRrc(pwnd, 0, 0, rrc.rxRight-1, 1, 1, 0);
rx--;
}
if (ichCursor < ichMac)
{
bltbyte(sz+ichCursor, sz+ichCursor+1, ichMac-ichCursor);
if (rx < rrc.rxRight-1)
BltRrc(pwnd, rx+1, 0, rrc.rxRight-rx-1, 1, rx, 0);
}
sz[ichCursor] = ch;
#ifdef EDIT_SECRET
if (pwnd->style & ES_SECRET)
ch = chSecret;
#else
AssertSz(!(pwnd->style & ES_SECRET), "Secret Edit Items not supported");
#endif /*!EDIT_SECRET*/
CharOut(pwnd, rx, 0, ch, pwnd->isaEb);
pwnd->ichMacEb++;
pwnd->ichCursorEb++;
return(TRUE);
}
STATIC VOID
DelCh(pwnd, ichCur)
/*
-- delete a character at the cursor position
-- called by DelChLeft/DelChRight
*/
REGISTER PWND pwnd;
WORD ichCur;
{
char *sz = SzEdit(pwnd);
WORD ichMac = pwnd->ichMacEb;
pwnd->ichMacEb--;
bltbyte(sz+ichCur+1, sz+ichCur, ichMac-ichCur-1);
/* if room, make it look like we are 1 back from where we are
* (so that we will see an empty item only when it is really empty)
*/
if (ichCur > 0)
ichCur--; /* try to fake it back one */
if (ichCur < pwnd->ichLeftEb)
pwnd->ichLeftEb = ichCur;
DisplayEb(pwnd);
}
STATIC VOID
MoveCursorLeft(pwnd)
/*
-- move the cursor left; scroll if necessary
*/
REGISTER PWND pwnd;
{
short ichNew;
if ((ichNew = pwnd->ichCursorEb-1) < 0)
return;
pwnd->ichCursorEb = ichNew;
if (ichNew < pwnd->ichLeftEb)
{
pwnd->ichLeftEb = ichNew;
DisplayEb(pwnd);
}
}
STATIC VOID
MoveCursorRight(pwnd)
/*
-- move the cursor right; scroll if necessary
*/
REGISTER PWND pwnd;
{
RRC rrc;
WORD ichNew;
WORD ichRight;
GetClientRrc(pwnd,&rrc);
ichRight = pwnd->ichLeftEb + rrc.rxRight;
if ((ichNew = pwnd->ichCursorEb+1) > pwnd->ichMacEb)
return;
pwnd->ichCursorEb = ichNew;
if (ichNew >= ichRight)
{
pwnd->ichLeftEb = ichNew - rrc.rxRight + 1;
DisplayEb(pwnd);
}
}
STATIC VOID
DelChLeft(pwnd)
/*
-- delete the character to the left of the cursor
*/
REGISTER PWND pwnd;
{
if (pwnd->ichCursorEb > 0)
DelCh(pwnd, --pwnd->ichCursorEb);
}
STATIC VOID
DelChRight(pwnd)
/*
-- delete the character at the cursor
*/
REGISTER PWND pwnd;
{
if (pwnd->ichCursorEb < pwnd->ichMacEb)
DelCh(pwnd, pwnd->ichCursorEb);
}
STATIC VOID
MoveCursorBegin(pwnd)
/*
-- move the cursor to the beginning of the edit buffer
-- scroll as needed
*/
REGISTER PWND pwnd;
{
pwnd->ichCursorEb = 0;
if (pwnd->ichLeftEb > 0)
{
pwnd->ichLeftEb = 0;
DisplayEb(pwnd);
}
}
STATIC VOID
MoveCursorEnd(pwnd)
/*
-- move the cursor to the end of the edit buffer
-- scroll as needed
*/
REGISTER PWND pwnd;
{
REGISTER WORD ichCursor = pwnd->ichMacEb;
WORD ichNewLeft;
RRC rrc;
GetClientRrc(pwnd,&rrc);
pwnd->ichCursorEb = ichCursor = pwnd->ichMacEb;
if (ichCursor >= rrc.rxRight &&
(ichNewLeft = ichCursor - rrc.rxRight) >= pwnd->ichLeftEb)
{
pwnd->ichLeftEb = ichNewLeft+1;
DisplayEb(pwnd);
}
}
STATIC VOID
HiliteEditSel(pwnd, fHilite)
/*
-- hilite the current selection
*/
REGISTER PWND pwnd;
BOOL fHilite;
{
int ichCursor = (int) pwnd->ichCursorEb - pwnd->ichLeftEb;
int ichSel = (int) pwnd->ichSelEb - pwnd->ichLeftEb;
RRC rrc;
GetClientRrc(pwnd, &rrc);
rrc.rxLeft = (RX) ((ichSel < 0) ? 0 : ichSel);
rrc.rxLeft = min( rrc.rxLeft, rrc.rxRight);
rrc.rxRight = (RX) ((ichCursor < 0) ? 0 : ichCursor);
if (ichSel >= ichCursor)
{
/* reverse rxLeft & right */
RX rxT = rrc.rxLeft;
rrc.rxLeft = rrc.rxRight;
rrc.rxRight = rxT;
}
FillRrc(pwnd, &rrc, ' ', dmAttrOnly |
(fHilite ? pwnd->isaSelEb : pwnd->isaEb));
}
STATIC VOID
DeleteSelection(pwnd, sz)
/*
-- cut the current selection
-- copying it to sz if it is not NULL
*/
REGISTER PWND pwnd;
char *sz;
{
WORD ichLeft, ichSel = pwnd->ichSelEb;
WORD ichStart, ichEnd, ichMac = pwnd->ichMacEb;
int ichCursor = pwnd->ichCursorEb;
int cch;
char *szStart, *szEnd;
if (ichSel == ichCursor)
return;
else if (ichSel < ichCursor)
{
ichStart = ichSel;
ichEnd = ichCursor-1;
}
else
{
ichStart = ichCursor;
ichEnd = ichSel-1;
}
if (ichEnd >= ichMac)
ichEnd = ichMac-1;
cch = ichEnd - ichStart + 1;
pwnd->ichMacEb -= cch;
szStart = (char *) (pwnd->szDialog + ichStart);
szEnd = (char *) (pwnd->szDialog + ichEnd);
if (sz != NULL)
{
bltbyte(sz, szStart, cch);
sz[cch] = '\0';
}
bltbyte(szEnd+1, szStart, ichMac-ichEnd-1);
if (pwnd->ichLeftEb > ichEnd)
pwnd->ichLeftEb = ichLeft - cch;
else if (pwnd->ichLeftEb > ichStart)
pwnd->ichLeftEb = ichStart;
else if (pwnd->ichLeftEb == ichStart && ichStart != 0)
pwnd->ichLeftEb = ichStart - 1;
pwnd->ichCursorEb = ichStart;
DisplayEb(pwnd);
}
STATIC VOID
PasteSz(pwnd, szPaste)
/*
-- paste the contents of szPaste at the cursor
*/
REGISTER PWND pwnd;
char *szPaste;
{
WORD cch = strlen(szPaste);
WORD ichCursor = pwnd->ichCursorEb;
char *sz = SzEdit(pwnd) + ichCursor;
short cchShift = min(pwnd->cchDialog - ichCursor - cch,
min(pwnd->cchMaxEb - ichCursor - cch,
pwnd->ichMacEb - ichCursor));
RRC rrc;
WORD ichRight;
GetClientRrc(pwnd,&rrc);
ichRight = pwnd->ichLeftEb + rrc.rxRight;
bltbyte(sz, sz+cch, cchShift);
cch = min(cch, min(pwnd->cchDialog - ichCursor,
pwnd->cchMaxEb - ichCursor));
pwnd->ichMacEb += cch;
pwnd->ichCursorEb +=cch;
bltbyte(szPaste, sz, cch);
if (pwnd->ichCursorEb > ichRight)
pwnd->ichLeftEb += cch;
DisplayEb(pwnd);
}
STATIC VOID
CopySelection(pwnd, sz)
/*
-- copy the current selection into the paste buffer (sz)
-- assume buffer to be large enough
*/
REGISTER PWND pwnd;
char *sz;
{
WORD ichSel = pwnd->ichSelEb;
WORD ichStart, ichEnd, ichMac = pwnd->ichMacEb;
WORD cch, ichCursor = pwnd->ichCursorEb;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -