📄 tvdemo.pas
字号:
GetPalette := @P[AppPalette];
end;
procedure TTVDemo.HandleEvent(var Event: TEvent);
procedure ChangeDir;
var
D: PChDirDialog;
begin
D := New(PChDirDialog, Init(cdNormal + cdHelpButton, 101));
D^.HelpCtx := hcFCChDirDBox;
ExecuteDialog(D, nil);
end;
procedure Puzzle;
var
P: PPuzzleWindow;
begin
P := New(PPuzzleWindow, Init);
P^.HelpCtx := hcPuzzle;
InsertWindow(P);
end;
procedure Calendar;
var
P: PCalendarWindow;
begin
P := New(PCalendarWindow, Init);
P^.HelpCtx := hcCalendar;
InsertWindow(P);
end;
procedure About;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 40, 11);
D := New(PDialog, Init(R, 'About'));
with D^ do
begin
Options := Options or ofCentered;
R.Grow(-1, -1);
Dec(R.B.Y, 3);
Insert(New(PStaticText, Init(R,
#13 +
^C'Turbo Vision Demo'#13 +
#13 +
^C'Copyright (c) 1992'#13 +
#13 +
^C'Borland International')));
R.Assign(15, 8, 25, 10);
Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
end;
if ValidView(D) <> nil then
begin
Desktop^.ExecView(D);
Dispose(D, Done);
end;
end;
procedure AsciiTab;
var
P: PAsciiChart;
begin
P := New(PAsciiChart, Init);
P^.HelpCtx := hcAsciiTable;
InsertWindow(P);
end;
procedure Calculator;
var
P: PCalculator;
begin
P := New(PCalculator, Init);
P^.HelpCtx := hcCalculator;
InsertWindow(P);
end;
procedure Colors;
var
D: PColorDialog;
begin
D := New(PColorDialog, Init('',
ColorGroup('Desktop', DesktopColorItems(nil),
ColorGroup('Menus', MenuColorItems(nil),
ColorGroup('Dialogs/Calc', DialogColorItems(dpGrayDialog, nil),
ColorGroup('Editor/Puzzle', WindowColorItems(wpBlueWindow, nil),
ColorGroup('Ascii table', WindowColorItems(wpGrayWindow, nil),
ColorGroup('Calendar',
WindowColorItems(wpCyanWindow,
ColorItem('Current day', 22, nil)),
nil))))))));
D^.HelpCtx := hcOCColorsDBox;
if ExecuteDialog(D, Application^.GetPalette) <> cmCancel then
begin
DoneMemory; { Dispose all group buffers }
ReDraw; { Redraw application with new palette }
end;
end;
procedure Mouse;
var
D: PDialog;
begin
D := New(PMouseDialog, Init);
D^.HelpCtx := hcOMMouseDBox;
ExecuteDialog(D, @MouseReverse);
end;
procedure RetrieveDesktop;
var
S: PStream;
Signature: string[SignatureLen];
begin
S := New(PBufStream, Init('TVDEMO.DSK', stOpenRead, 1024));
if LowMemory then OutOfMemory
else if S^.Status <> stOk then
MessageBox('Could not open desktop file', nil, mfOkButton + mfError)
else
begin
Signature[0] := Char(SignatureLen);
S^.Read(Signature[1], SignatureLen);
if Signature = DSKSignature then
begin
LoadDesktop(S^);
LoadIndexes(S^);
LoadHistory(S^);
if S^.Status <> stOk then
MessageBox('Error reading desktop file', nil, mfOkButton + mfError);
end
else
MessageBox('Error: Invalid Desktop file.', nil, mfOkButton + mfError);
end;
Dispose(S, Done);
end;
procedure SaveDesktop;
var
S: PStream;
F: File;
begin
S := New(PBufStream, Init('TVDEMO.DSK', stCreate, 1024));
if not LowMemory and (S^.Status = stOk) then
begin
S^.Write(DSKSignature[1], SignatureLen);
StoreDesktop(S^);
StoreIndexes(S^);
StoreHistory(S^);
if S^.Status <> stOk then
begin
MessageBox('Could not create TVDEMO.DSK.', nil, mfOkButton + mfError);
{$I-}
Dispose(S, Done);
Assign(F, 'TVDEMO.DSK');
Erase(F);
Exit;
end;
end;
Dispose(S, Done);
end;
procedure FileNew;
begin
OpenEditor('', True);
end;
procedure ShowClip;
begin
ClipWindow^.Select;
ClipWindow^.Show;
end;
begin
inherited HandleEvent(Event);
case Event.What of
evCommand:
begin
case Event.Command of
cmOpen: FileOpen('*.*');
cmNew: FileNew;
cmShowClip: ShowClip;
cmChangeDir: ChangeDir;
cmAbout: About;
cmPuzzle: Puzzle;
cmCalendar: Calendar;
cmAsciiTab: AsciiTab;
cmCalculator: Calculator;
cmColors: Colors;
cmMouse: Mouse;
cmSaveDesktop: SaveDesktop;
cmRetrieveDesktop: RetrieveDesktop;
else
Exit;
end;
ClearEvent(Event);
end;
end;
end;
procedure TTVDemo.Idle;
function IsTileable(P: PView): Boolean; far;
begin
IsTileable := (P^.Options and ofTileable <> 0) and
(P^.State and sfVisible <> 0);
end;
begin
inherited Idle;
Clock^.Update;
Heap^.Update;
if Desktop^.FirstThat(@IsTileable) <> nil then
EnableCommands([cmTile, cmCascade])
else
DisableCommands([cmTile, cmCascade]);
end;
procedure TTVDemo.InitMenuBar;
var
R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y+1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~'#240'~', hcSystem, NewMenu(
NewItem('~A~bout', '', kbNoKey, cmAbout, hcSAbout,
NewLine(
NewItem('~P~uzzle', '', kbNoKey, cmPuzzle, hcSPuzzle,
NewItem('Ca~l~endar', '', kbNoKey, cmCalendar, hcSCalendar,
NewItem('Ascii ~t~able', '', kbNoKey, cmAsciiTab, hcSAsciiTable,
NewItem('~C~alculator', '', kbNoKey, cmCalculator, hcCalculator, nil))))))),
NewSubMenu('~F~ile', hcFile, NewMenu(
StdFileMenuItems(nil)),
NewSubMenu('~E~dit', hcEdit, NewMenu(
StdEditMenuItems(
NewLine(
NewItem('~S~how clipboard', '', kbNoKey, cmShowClip, hcShowClip,
nil)))),
NewSubMenu('~S~earch', hcSearch, NewMenu(
NewItem('~F~ind...', '', kbNoKey, cmFind, hcFind,
NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcReplace,
NewItem('~S~earch again', '', kbNoKey, cmSearchAgain, hcSearchAgain,
nil)))),
NewSubMenu('~W~indow', hcWindows, NewMenu(
StdWindowMenuItems(nil)),
NewSubMenu('~O~ptions', hcOptions, NewMenu(
NewItem('~M~ouse...', '', kbNoKey, cmMouse, hcOMouse,
NewItem('~C~olors...', '', kbNoKey, cmColors, hcOColors,
NewLine(
NewItem('~S~ave desktop', '', kbNoKey, cmSaveDesktop, hcOSaveDesktop,
NewItem('~R~etrieve desktop', '', kbNoKey, cmRetrieveDesktop, hcORestoreDesktop, nil)))))),
nil)))))))));
end;
procedure TTVDemo.InitStatusLine;
var
R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F1~ Help', kbF1, cmHelp,
NewStatusKey('~F3~ Open', kbF3, cmOpen,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
NewStatusKey('~F5~ Zoom', kbF5, cmZoom,
NewStatusKey('', kbF10, cmMenu,
NewStatusKey('', kbCtrlF5, cmResize,
nil))))))),
nil)));
end;
procedure TTVDemo.OutOfMemory;
begin
MessageBox('Not enough memory available to complete operation.',
nil, mfError + mfOkButton);
end;
{ Since the safety pool is only large enough to guarantee that allocating
a window will not run out of memory, loading the entire desktop without
checking LowMemory could cause a heap error. This means that each
window should be read individually, instead of using Desktop's Load.
}
procedure TTVDemo.LoadDesktop(var S: TStream);
var
P: PView;
Pal: PString;
procedure CloseView(P: PView); far;
begin
Message(P, evCommand, cmClose, nil);
end;
begin
if Desktop^.Valid(cmClose) then
begin
Desktop^.ForEach(@CloseView); { Clear the desktop }
repeat
P := PView(S.Get);
Desktop^.InsertBefore(ValidView(P), Desktop^.Last);
until P = nil;
Pal := S.ReadStr;
if Pal <> nil then
begin
Application^.GetPalette^ := Pal^;
DoneMemory;
Application^.ReDraw;
DisposeStr(Pal);
end;
end;
end;
procedure TTVDemo.StoreDesktop(var S: TStream);
var
Pal: PString;
procedure WriteView(P: PView); far;
begin
if P <> Desktop^.Last then S.Put(P);
end;
begin
Desktop^.ForEach(@WriteView);
S.Put(nil);
Pal := @Application^.GetPalette^;
S.WriteStr(Pal);
end;
var
Demo: TTVDemo;
begin
Demo.Init;
Demo.Run;
Demo.Done;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -