📄 awterm.pas
字号:
(***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower Async Professional
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1991-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* AWTERM.PAS 4.06 *}
{*********************************************************}
{* Deprecated terminal emulator support *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
{Options required for this unit}
{$X+,B+,F-,I-,Q-}
{$IFDEF Win32}
{$J+}
{$ENDIF}
unit AwTerm;
{-Terminal window}
interface
uses
WinTypes,
WinProcs,
Messages,
SysUtils,
OoMisc,
AwUser,
AwEmu;
{$DEFINE IncludeTerm}
type
{Windows message record}
{$IFDEF Win32}
wMsg = record
hWindow : TApdHwnd;
Message : UINT;
case Integer of
0: (wParam : WPARAM; lParam : LPARAM);
1: (wParamLo, wParamHi : Word; lParamLo, lParamHi : Word);
end;
{$ELSE}
wMsg = record
hWindow : TApdHwnd;
Message : Word;
case Integer of
0: (wParam : Word; lParam : LongInt);
1: (wParamLo, wParamHi : Byte; lParamLo, lParamHi : Word);
end;
{$ENDIF}
{.$I AWTERM.PA0} {Interfaced routines}
type
{For holding/changing the ANSI color map}
TAnsiColorMap = array[emBlack..emWhiteBold] of TColorRef;
const
{Maximum number of columns for terminal window}
MaxCols = 133;
{Map ANSI color constants into RGB values}
ColorValues : TAnsiColorMap = (
$00000000, {black, emBlack}
$00000080, {red, emRed}
$00008000, {green, emGreen}
$00008080, {yellow, emYellow}
$00800000, {blue, emBlue}
$00800080, {magenta, emMagenta}
$00808000, {cyan, emCyan}
$00C0C0C0, {gray, emWhite}
$00808080, {dark gray, emBlackBold}
$000000FF, {dark red, emRedBold}
$0000FF00, {dark green, emGreenBold}
$0000FFFF, {brown, emYellowBold}
$00FF0000, {dark blue, emBlueBold}
$00FF00FF, {pink, emMagentaBold}
$00FFFF00, {dark mag, emCyanBold}
$00FFFFFF); {white, emWhiteBold}
{For getting/setting color maps}
gscSetMap = 0;
gscGetMap = 1;
gscGetColors = 2;
type
{Screen buffer}
PScreenBuffer = ^TScreenBuffer;
TScreenBuffer = array[0..65520] of Char;
{Screen attribute buffer}
PAttrBuffer = ^TAttrBuffer;
TAttrBuffer = array[0..65520] of Byte;
{Temporary Screen Attribute buffer for entended attributes}
PAttrBufferB = ^TAttrBufferB;
TAttrBufferB = array[0..65520] of Byte;
{Extended screen attribute buffer}
PExtAttrBuffer = ^TExtAttrBuffer;
TExtAttrBuffer = array[0..65520] of Byte;
{Terminal window tab stop settings}
PHorizontalTabStop = ^THorizontalTabStop;
THorizontalTabStop = array[1..25] of Byte;
PVerticalTabStop = ^TVerticalTabStop;
TVerticalTabStop = array[1..12] of Byte;
{Capture buffer}
PCharBuffer = ^TCharBuffer;
TCharBuffer = array[1..65521] of Char;
{$IFDEF IncludeTerm}
type
{For storing the default proc}
TWndProc = function (Wnd: TApdHwnd; Msg, wParam: Word; lParam: LongInt): LongInt;
TBuffer = class
{Buffer information}
bScreenBuffer: PScreenBuffer; {Pointer to screen data}
bAttrBuffer : PAttrBuffer; {Pointer to attribute data}
bAttrBufferB : PAttrBufferB; {Pointer to attribute data}
bExtAttrBuffer:PExtAttrBuffer;{Pointer to extended attribute data}
bHorizTabStop: PHorizontalTabStop;{Pointer to horizontal tab data}
bVertiTabStop: PVerticalTabStop;{Pointer to vertical tab data}
bHeight : Word; {Buffer height}
bWidth : Word; {Buffer width}
bCharHeight : Word; {Height of one character of current font}
bCharWidth : Word; {Width of one character of current font}
bScrollback : Bool; {True when in scrollback mode}
bJunk1 : Bool; {Keep word alignment}
bPageHeight : Word; {Height of page}
bBufferSize : Word; {Total buffer size}
bBufferLimit : Word; {Number of characters -1 line}
bX : Word; {Current buffer location of caret}
bY : Word; {Current buffer location of caret}
bMaxY : Word; {Y highwater}
bXPos : Integer; {X coord of upper left of client}
bYPos : Integer; {Y coord of upper left of client}
bCom : TApdBaseDispatcher; {Copy of TTerminal's TComHandle}
bInMargins : Bool; {Caret in margin area}
{Save/restore client/buffer info when in scrollback}
bSaveX : Word; {Saved X}
bSaveY : Word; {Saved Y}
bSaveXPos : Integer; {Saved XPos}
bSaveYPos : Integer; {Saved YPos}
bWasFull : Boolean; {Saved fullscreen flag}
{Color information, current and original}
bfColor : Byte; {Current foreground color}
bbColor : Byte; {Current background color}
bfColorOrg : Byte; {Original foreground color}
bbColorOrg : Byte; {Original background color}
bColors : TAnsiColorMap; {ANSI color map}
bExtAttr : Byte; {Extended ANSI attribute byte}
bBlinkReset : Bool; {blinking reset state}
{Client area information (visible portion of Buffer)}
cHeight : Word; {Char height of client area}
cWidth : Word; {Char width of client area}
cSizeX : Word; {Pixel width of client area}
cSizeY : Word; {Pixel height of client area}
cSaveX : Word; {Pixel width before scrollback}
cSaveY : Word; {Pixel height before scrollback}
cCheckX : Word; {width at start of scrollback}
cCheckY : Word; {height at start of scrollback}
cLastHeight : Word; {Previous height, checked during wmSize}
cLastWidth : Word; {Previous width, check during wmSize}
cMarginTop : Word; {Top margin of page/client}
cMarginBottom: Word; {Bottom margin of page/client}
{Emulator}
bEmulator : Pointer; {Emulator pointer}
bEmuProc : TProcessCharProcLo; {Callback to emulator}
bEC : TEmuCommandLo; {Results of last emulator call}
bSaveXLoc : Word; {X from last eSaveCursorPosition}
bSaveYLoc : Word; {Y from last eSaveCursorPosition}
bSaveFlag : Bool; {Are we currently in a previos save state}
bSaveAttr : Byte; {attribute form last eSaveCursorPosition}
bSaveAttrEx : Byte; {extended attribute form last eSaveCursorPosition}
{Painting information}
bWnd : hWnd; {Window handle of owning Terminal}
bNeedVScroll : Integer; {Pending vertical scroll value}
bNeedHScroll : Integer; {Pending horizontal scroll value}
bRedrawRect : TRect; {Union of all invalid rectangles}
bFocused : Bool; {The current window has focus}
{Marking information}
bMarking : Bool; {In the process of marking}
bMarked : Bool; {A marked block exists}
bOffScreen : Bool; {True if doing offscreen scrolling}
bMarkAnchorX : Word; {Anchor for current block}
bMarkAnchorY : Word; {Anchor for current block}
bMarkStartX : Word; {Start column of marked block}
bMarkStartY : Word; {Start row of marked block}
bMarkEndX : Word; {End column of marked block}
bMarkEndY : Word; {End row of marked block}
bScrollTimer : Word; {Timer used for off-screen scrolling}
bMarkColorB : Byte; {Highlight background color}
bMarkColorF : Byte; {Highlight foreground color}
{Capturing}
bCapIndex : Word; {Index into capture buffer}
bCapBuffer : PCharBuffer; {Capture buffer}
bCaptureName : array[0..255] of Char; {Name of capture file}
bCaptureFile : File; {File of captured data}
bCapture : Bool; {True if capturing}
{Semaphore for save structure}
bFinal : Word; {Notes end of data for copying}
constructor Create(AWnd : TApdHwnd; Height, Width : Word);
destructor Destroy; override;
procedure bDeallocBuffers;
function bNewBuffer(Rows, Cols, PageHeight : Word) : Integer;
procedure bSetColors(FC, BC : Word);
procedure bSetHighlightColors(FC, BC : Word);
procedure bFlushCapture;
procedure bAddToCapture(C : Char);
function bSetCapture(Enable, Append : Bool; FName : PChar) : Integer;
procedure bSetScrollMode(Scrollback : Bool);
procedure bInvalidateChar(X, Y : Word);
procedure bPostStatusMsg;
procedure bUpdateFont(Height, Width : Word);
procedure bUpdateBuffer;
procedure bWriteChar(C : Char);
procedure bClearScreen;
procedure bProcessChar(C : Char);
procedure bMoveCaret;
function bCurLineLength : Word;
function bNeedPaint : Bool;
procedure bForcePaint;
procedure bUpdateScrollThumb(Vert : Bool);
procedure bScroll(X, Y : Integer);
procedure bGotoTop(Vert : Boolean);
procedure bGotoBottom(Vert : Boolean);
function bConvertToRow(I : Integer) : Word;
function bConvertToCol(I : Integer) : Word;
procedure bFixMarking(NewX, NewY : Word);
procedure bResetMarking;
procedure bUpdateMarks(RawX, RawY : Integer);
procedure bSortTabBuffer(var TabBuffer; Size : Byte);
function bGetNextTabStop(CurrentPos, Count : Byte;
var TabBuffer; Size : Byte): Byte;
function bGetPrevTabStop(CurrentPos, Count : Byte;
var TabBuffer; Size : Byte): Byte;
procedure bSetHorizontalTabStop(Column : Byte);
procedure bClearHorizontalTabStop(Column : Byte);
procedure bSetVerticalTabStop(Row : Byte);
procedure bClearVerticalTabStop(Row : Byte);
end;
TTerminal = class
tWnd : hWnd; {Window handle for terminal window}
aBuffer : TBuffer; {Buffer object, screen contents}
tFont : THandle; {Handle to selected font}
tCom : TApdBaseDispatcher; {Handle to com port}
tCharHeight : Word; {Height of current font}
tCharWidth : Word; {Width of current font}
tScrollBack : Bool; {True when in tScrollBack mode}
tDataReady : Bool; {True if data arrived during tScrollBack}
tHasVScroll : Bool; {True if vertical scrollbar present}
tHasHScroll : Bool; {True if horizontal scrollbar present}
tFocused : Bool; {True when window has the focus}
tMinimized : Bool; {True when window is minimized}
tPersistentMarking : Bool; {True if persistant marking in on}
tHalfDuplex : Bool; {True when in full duplex mode}
tDefWndProc : TFarProc; {The default window proc}
tFinal : Word; {Notes end of data for copying}
HadVScroll : Bool; {Preserve VScroll state through scroll-back}
vMin,vMax : Integer; {Saved VScroll ranges}
TriggerHandlerInstalled : Boolean;
{Keyboard Emulator}
tKeyEmuPtr : Pointer; {Emulator pointer}
tKeyEmuProc : TProcessKeyProcLo; {Callback to emulator}
tKC : TKeyEmuCommandLo; {Results of last keyboard emulator call}
constructor Create(AWnd : TApdHwnd);
destructor Destroy; override;
procedure tBlink;
procedure tSetInitialSizes;
function tGetWindowStyle : LongInt;
function tWantTab : Bool;
function tIntHeight : Bool;
function tIntWidth : Bool;
function tAutoVScroll : Bool;
function tAutoHScroll : Bool;
procedure tMakeCaret;
procedure tCalcClientRowCol;
procedure tAdjustIntSize;
procedure tAdjustMaxSize;
procedure tAdjustClient;
function tFullWidth : Bool;
function tFullHeight : Bool;
procedure tCheckVScroll;
procedure tCheckHScroll;
procedure tResizeClientRect;
procedure tGetMousePos(var X, Y : Integer);
procedure tStartTerminal(var Msg : wMsg);
procedure tStopTerminal(var Msg : wMsg);
procedure tSetEmulatorPtr(var Msg : wMsg);
procedure tSetEmulatorProc(var Msg : wMsg);
procedure tSetKeyEmulatorPtr(var Msg : wMsg);
procedure tSetKeyEmulatorProc(var Msg : wMsg);
procedure tSetComHandle(var Msg : wMsg);
procedure tReleaseComHandle(var Msg : wMsg);
procedure tHandleData(var Msg : wMsg);
procedure tClearWindow(var Msg : wMsg);
procedure tClearBuffer(var Msg : wMsg);
procedure tToggleScrollback(var Msg : wMsg);
procedure tStuffData(var Msg : wMsg);
procedure tForcePaint(var Msg : wMsg);
procedure tSetWndProc(wParam : Word; lParam : Longint);
function tSaveRestore(var Msg : wMsg) : Longint;
function tGetSetColorMap(var Msg : wMsg) : LongInt;
procedure tForceSize(var Msg : wMsg);
function tGetFontSize(var Msg : wMsg) : Longint;
procedure tBlinkTimeChange(var Msg : wMsg);
procedure tPersistentMarkChange(var Msg : wMsg);
procedure tSetHalfDuplex(var Msg: wMsg);
procedure tGetBuffPtr(var Msg: wMsg);
function tGetFirstClientLine(var Msg: wMsg): Longint;
procedure tTextOutColor(DC : HDC; X, Y : Word;
Line : PChar; Attr : PChar;
Len : Word; MarkStart : Word; MarkEnd : Word);
procedure tPaint(PaintDC: HDC; var PaintInfo: TPaintStruct);
procedure wmPaint(var Msg : wMsg);
procedure wmKeydown(var Msg : wMsg);
procedure wmMouseActivate(var Msg : wMsg);
procedure wmSize(var Msg : wMsg);
procedure wmGetMinMaxInfo(var Msg : wMsg);
function wmSetFont(Font : THandle) : LongInt;
procedure wmChar(var Msg : wMsg);
procedure wmSetFocus(var Msg : wMsg);
procedure wmKillFocus(var Msg : wMsg);
function wmGetDlgCode(var Msg : wMsg) : LongInt;
procedure wmVScroll(var Msg : wMsg);
procedure wmHScroll(var Msg : wMsg);
procedure wmEraseBkGnd(var Msg : wMsg);
procedure wmLButtonDown(var Msg : wMsg);
procedure wmLButtonUp(var Msg : wMsg);
procedure wmMouseMove(var Msg : wMsg);
procedure wmTimer(var Msg : wMsg);
procedure wmCopy(var Msg : wMsg);
end;
{For saving/restoring terminal data}
PTermSave = ^TTermSave;
TTermSave = record
ScreenBuffer : Pointer;
AttrBuffer : Pointer;
RestBuffer : Pointer;
TermBuffer : Pointer;
AttrBufferB : Pointer;
ExtAttrBuffer: Pointer;
HorizTabStop : Pointer;
VertiTabStop : Pointer;
end;
{$ENDIF}
{$UNDEF IncludeTerm}
PTermBuff = ^TTermBuff;
TTermBuff = record
Data : PScreenBuffer;
Attr : PAttrBuffer;
XAttr: PExtAttrBuffer;
end;
procedure RegisterTerminalWindowClass(Designing : Boolean);
implementation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -