home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 July / pcx23_9807.iso / PC-XUSER / PC-XUSER.17 / OOP / PCX_DLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-05-17  |  40.2 KB  |  1,437 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {   PC-X User Dialogs for Turbo Vision                  }
  4. {   Copyright (c) 1997 By PC-X User and Bérczi László   }
  5. {                                                       }
  6. {   Portions Copyright (c) 1990 by Borland Int.         }
  7. {*******************************************************}
  8. {Last Edit: 1997 II 15. 21:00}
  9. {$X+,V-,F+,O-,S+,Q-}
  10.  
  11. {Lásd a file végét a szerzô megállapodás véget ! - Licens agreements.}
  12.  
  13. unit PCX_Dlg;
  14.  
  15. INTERFACE
  16. uses Objects, Dialogs, Drivers, Menus, Views, Editors;
  17.  
  18. const
  19.  
  20.   GFrameCornerLU         = #193;   {┌}                     {Corner=Sarok  }
  21.   GFrameCornerRU         = #194;   {┐}                     {L=Left;R=Right}
  22.   GFrameCornerLD         = #195;   {└}                     {U=Up  ;D=Down }
  23.   GFrameCornerRD         = #197;   {┘}
  24.   GFrameSummitU          = #198;   {─}                     {Summit=Tetô   }
  25.   GFrameSummitD          = #199;   {─}
  26.   GFrameEdgeL            = #200;   {│}                     {Edge=Szél(e)  }
  27.   GFrameEdgeR            = #201;   {│}
  28.  
  29.   CheckBoxCenterN  =  #203; {' '}
  30.   CheckBoxCenterX  =  #204; {'X'}
  31.   CheckBoxLeft     =  #202; {'['}
  32.   CheckBoxRight    =  #181; {']'}
  33.   RadioButtonCenterN = #207; {' '}
  34.   RadioButtonCenterX = #206; { #7}
  35.   RadioButtonLeft    = #205; {'('}
  36.   RadioButtonRight   = #182; {')'}
  37.  
  38.   cmMouseChanged       = 1003;
  39.   cmCheckBoxChanged    = 1004;
  40.   cmRadioButtonChanged = 1005;
  41.   cmViewChanged        = 1006;
  42.   cmMove               = 1007;
  43.   cmRefresh            = 1008;
  44.   cmPCXFrameChanged    = 1009;
  45.  
  46. { Color palettes }
  47.  
  48.   {CPCXDialogs}
  49.   CPCXBlueDialog =
  50.     #64#65#66#67#68#69#70#71#72#73#74#75#76#77#78#79+                {  1- 16}
  51.     #80#81#82#83#84#85#86#87#88#89#90#91#92#92#94#95+                { 17- 32}
  52.     #96#97#98#99#100;                                                { 33- 37}
  53.     {#64-#100}
  54.   CPCXRedDialog  =
  55.     #101#102#103#104#105#106#107#108#109#110#111#112#113#114#115#116+{  1- 16}
  56.     #117#118#119#120#121#122#123#124#125#126#127#128#129#130#131#132+{ 17- 32}
  57.     #133#134#135#136#137;                                            { 33- 37}
  58.     {#101-#137}
  59.   CPCXGrayDialog =
  60.     #138#139#140#141#142#143#144#145#146#147#148#149#150#151#152#153+{  1- 16}
  61.     #154#155#156#157#158#159#160#161#162#163#164#165#166#167#168#169+{ 17- 32}
  62.     #170#171#172#173#174;                                            { 33- 37}
  63.     {#138-#174}
  64.   CPCXDialog     = CGrayDialog+#170#171#172#173#174;
  65.  
  66.   {CPCXWindows}
  67.   CPCXWindow     = CPCXDialog;
  68.   CPCXBlueWindow = CPCXBlueDialog;
  69.   CPCXRedWindow  = CPCXRedDialog;
  70.   CPCXGrayWindow = CPCXGrayDialog;
  71.  
  72.   CPCXIndicator  = #2#37#3#37;
  73.   CPCXFileEditor = #6#4;
  74.  
  75.   CPCXTitleBar      = #175;
  76.   CPCXControlBoxApp = #175;
  77.   CPCXControlBoxDlg = #34;
  78.   CPCXControlBoxWin = #34;
  79.  
  80.   CPCXFrame = #1#33#2#34#36#37#35; {CFrame + DragWindow + DragTitle}
  81.   CPCXScrollBar = #4#5#4#5; {CSrollBar + CMyScroolBox}
  82.  
  83. type
  84.   PString = OBJECTS.PString;
  85.  
  86.   PPCXPoint = ^TPCXPoint;
  87.   TPCXPoint = Object(TPoint)
  88.     procedure Assign(XA, YA: Integer);
  89.   end;
  90.  
  91.   PPCXMenuBox = ^TPCXMenuBox;
  92.   TPCXMenuBox = Object(TMenuBox)
  93.     procedure Draw; virtual;
  94.   end;
  95.  
  96.   PPCXControlBox = ^TPCXControlBox;
  97.   TPCXControlBox = Object(TStaticText)
  98.     constructor Init(P: TPCXPoint);
  99.     procedure HandleEvent(var Event: TEvent); virtual;
  100.     procedure ExecControlMenuBox; virtual;
  101.   private
  102.     ControlMenuBox: PPCXMenuBox;
  103.   end;
  104.  
  105.   PPCXControlBoxApp = ^TPCXControlBoxApp;
  106.   TPCXControlBoxApp = Object(TPCXControlBox)
  107.     function  GetPalette: PPalette; virtual;
  108.     procedure ExecControlMenuBox; virtual;
  109.   end;
  110.  
  111.   PPCXControlBoxDlg = ^TPCXControlBoxDlg;
  112.   TPCXControlBoxDlg = Object(TPCXControlBox)
  113.     function  GetPalette: PPalette; virtual;
  114.     procedure ExecControlMenuBox; virtual;
  115.   end;
  116.  
  117.   PPCXControlBoxWin = ^TPCXControlBoxWin;
  118.   TPCXControlBoxWin = Object(TPCXControlBox)
  119.     function  GetPalette: PPalette; virtual;
  120.     procedure ExecControlMenuBox; virtual;
  121.   end;
  122.  
  123.   PPCXMenuBar = ^TPCXMenuBar;
  124.   TPCXMenuBar = Object(TMenuBar)
  125.     function NewSubView(var Bounds: TRect; AMenu: PMenu;
  126.       AParentMenu: PMenuView): PMenuView; virtual;
  127.   end;
  128.  
  129.   TPCXScrollChars = Array[0..5] of Char;
  130.  
  131.   PPCXScrollBar = ^TPCXScrollBar;
  132.   TPCXScrollBar = Object(TScrollBar)
  133.     constructor Init(var Bounds: TRect);
  134.     procedure Draw; virtual;
  135.     procedure HandleEvent(var Event: TEvent); virtual;
  136.     function  GetPalette: PPalette; virtual;
  137.   private
  138.     Chars: TPCXScrollChars;
  139.     TempB: Byte;
  140.     IsHorizontal: Boolean;
  141.     procedure DrawPos(Pos: Integer);
  142.     function GetPos: Integer;
  143.     function GetSize: Integer;
  144.   end;
  145.  
  146.   PPCXFrame = ^TPCXFrame;
  147.   TPCXFrame = Object(TFrame)
  148.     procedure Draw; virtual;
  149.     function  GetPalette: PPalette; virtual;
  150.   private
  151.     FrameMode: Word;
  152.   end;
  153.  
  154.   PPCXWindow = ^TPCXWindow;
  155.   TPCXWindow = Object(TWindow)
  156.     constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  157.     procedure InitFrame; virtual;
  158.     procedure Draw; virtual;
  159.     function  GetPalette: PPalette; virtual;
  160.     procedure HandleEvent(var Event: TEvent); virtual;
  161.     function  StandardScrollBar(AOptions: Word): PPCXScrollBar;
  162.   private
  163.     ControlBoxWin: PPCXControlBoxWin;
  164.   end;
  165.  
  166.   PPCXBlueWindow = ^TPCXBlueWindow;
  167.   TPCXBlueWindow = Object(TPCXWindow)
  168.     function  GetPalette: PPalette; virtual;
  169.   end;
  170.  
  171.   PPCXRedWindow = ^TPCXRedWindow;
  172.   TPCXRedWindow = Object(TPCXWindow)
  173.     function  GetPalette: PPalette; virtual;
  174.   end;
  175.  
  176.   PPCXGrayWindow = ^TPCXGrayWindow;
  177.   TPCXGrayWindow = Object(TPCXWindow)
  178.     function  GetPalette: PPalette; virtual;
  179.   end;
  180.  
  181.   PPCXDialog = ^TPCXDialog;
  182.   TPCXDialog = Object(TDialog)
  183.     constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  184.     procedure InitFrame; virtual;
  185.     procedure Draw; virtual;
  186.     function  GetPalette: PPalette; virtual;
  187.     procedure HandleEvent(var Event: TEvent); virtual;
  188.   private
  189.     ControlBoxDlg: PPCXControlBoxDlg;
  190.   end;
  191.  
  192.   PPCXBlueDialog = ^TPCXBlueDialog;
  193.   TPCXBlueDialog = Object(TPCXDialog)
  194.     function  GetPalette: PPalette; virtual;
  195.   end;
  196.  
  197.   PPCXRedDialog = ^TPCXRedDialog;
  198.   TPCXRedDialog = Object(TPCXDialog)
  199.     function  GetPalette: PPalette; virtual;
  200.   end;
  201.  
  202.   PPCXGrayDialog = ^TPCXGrayDialog;
  203.   TPCXGrayDialog = Object(TPCXDialog)
  204.     function  GetPalette: PPalette; virtual;
  205.   end;
  206.  
  207.   PPCXIndicator = ^TPCXIndicator;
  208.   TPCXIndicator = Object(TIndicator)
  209.     procedure Draw; virtual;
  210.     function  GetPalette: PPalette; virtual;
  211.   end;
  212.  
  213.   PPCXFileEditor = ^TPCXFileEditor;
  214.   TPCXFileEditor = Object(TFileEditor)
  215.     function  GetPalette: PPalette; virtual;
  216.   end;
  217.  
  218.   PPCXEditWindow = ^TPCXEditWindow;
  219.   TPCXEditWindow = Object(TEditWindow)
  220.     constructor Init(var Bounds: TRect; FileName: FNameStr; ANumber: Integer);
  221.     procedure InitFrame; virtual;
  222.     function  GetPalette: PPalette; virtual;
  223.     procedure HandleEvent(var Event: TEvent); virtual;
  224.   private
  225.     ControlBoxWin: PPCXControlBoxWin;
  226.   end;
  227.  
  228.   PPCXEditBlueWindow = ^TPCXEditBlueWindow;
  229.   TPCXEditBlueWindow = Object(TPCXEditWindow)
  230.     function  GetPalette: PPalette; virtual;
  231.   end;
  232.  
  233.   PPCXStaticText = ^TPCXStaticText;
  234.   TPCXStaticText = Object(TStaticText)
  235.      procedure SetText(AText: String); virtual;
  236.   end;
  237.  
  238.   PPCXButton = ^TPCXButton;
  239.   TPCXButton = Object(TButton)
  240.     procedure Draw; virtual;
  241.     procedure DrawView;
  242.     procedure DrawState(Down: Boolean); virtual;
  243.     procedure HandleEvent(var Event: TEvent); virtual;
  244.   private
  245.     procedure DrawCursor;
  246.     procedure ResetCursor; virtual;
  247.   end;
  248.  
  249.  
  250. const
  251.   IsMagyarul : Boolean = False;
  252.   IsIntensity: Boolean = False;
  253.   ShowMouseOn: Boolean = True;
  254.   IsHomokOra : Boolean = False;
  255.   On  = True;
  256.   Off = False;
  257.   Be  = True;
  258.   Ki  = False;
  259.  
  260.   {Bit flags to determine how to draw the frame icons}
  261.   fmCloseClicked = $0001;
  262.   fmZoomClicked  = $0002;
  263.  
  264.   {PCXScrollBar}
  265.   sbGraphLike = $0004;
  266.   sbTextLike  = $0008;
  267.  
  268. IMPLEMENTATION
  269. uses App, PCX_Util;
  270.  
  271. const
  272.   FrameEmpty: String[80] =  '                                        '+
  273.                             '                                        ';
  274.   FrameFull : String[80] =  '████████████████████████████████████████'+
  275.                             '████████████████████████████████████████';
  276.   GFrameUp  : String[80] =  '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞'+
  277.                             '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞';
  278.   FrameUp   : String[80] =  '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀'+
  279.                             '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀';
  280.   GFrameDown: String[80] =  '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟'+
  281.                             '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟';
  282.   FrameDown : String[80] =  '████████████████████████████████████████'+
  283.                             '████████████████████████████████████████';
  284.  
  285.   WindowSizer: String[2] = #210#14; {'─┘'}
  286.   ControlBox : String[2] = #209#180;{'[■]'}
  287.   UpWin      : String[2] = #214#11;
  288.   RestoreWin : String[2] = #9#10;
  289.   GFrame3DConers: Array[0..1] of Char = #221#222;
  290.   PasswordChar  : Byte = 42; {'*' = #42}
  291.  
  292. {TPCXPoint}
  293. procedure TPCXPoint.Assign(XA, YA: Integer);
  294. begin
  295.   X:=XA; Y:=YA;
  296. end;
  297.  
  298. {TPCXMenuBox}
  299. procedure TPCXMenuBox.Draw;
  300. var
  301.   CNormal, CSelect, CNormDisabled, CSelDisabled, Color: Word;
  302.   Y: Integer;
  303.   P: PMenuItem;
  304.   B: TDrawBuffer;
  305.  
  306. procedure FrameLine(N: Integer);
  307. const
  308.      FrameChars: Array[0..19] of Char = ' ┌─┐  └─┘  │ │  ├─┤ ';
  309.   PCXFrameChars: Array[0..19] of Char =
  310.     GFrameCornerLU+GFrameSummitU+GFrameSummitU+GFrameSummitU+GFrameCornerRU+
  311.     GFrameCornerLD+GFrameSummitD+GFrameSummitD+GFrameSummitD+GFrameCornerRD+
  312.     GFrameEdgeL+#32#32#32+GFrameEdgeR+
  313.     GFrameEdgeL+#32#196#32+GFrameEdgeR; {'┴╞╞╞┬├╟╟╟┼╚   ╔╚ ─ ╔'}
  314. begin
  315.   if IsPCXGraphCharsOn
  316.   then begin
  317.          MoveBuf(B[0], PCXFrameChars[N], Byte(CNormal), 2);
  318.          MoveChar(B[2], PCXFrameChars[N + 2], Byte(Color), Size.X - 4);
  319.          MoveBuf(B[Size.X - 2], PCXFrameChars[N + 3], Byte(CNormal), 2);
  320.        end
  321.   else begin
  322.          MoveBuf(B[0], FrameChars[N], Byte(CNormal), 2);
  323.          MoveChar(B[2], FrameChars[N + 2], Byte(Color), Size.X - 4);
  324.          MoveBuf(B[Size.X - 2], FrameChars[N + 3], Byte(CNormal), 2);
  325.        end;
  326. end;
  327.  
  328. procedure DrawLine;
  329. begin
  330.   WriteBuf(0, Y, Size.X, 1, B);
  331.   Inc(Y);
  332. end;
  333.  
  334. begin
  335.   CNormal := GetColor($0301);
  336.   CSelect := GetColor($0604);
  337.   CNormDisabled := GetColor($0202);
  338.   CSelDisabled := GetColor($0505);
  339.   Y := 0;
  340.   Color := CNormal;
  341.   FrameLine(0);
  342.   DrawLine;
  343.   if Menu <> nil then
  344.   begin
  345.     P := Menu^.Items;
  346.     while P <> nil do
  347.     begin
  348.       Color := CNormal;
  349.       if P^.Name = nil then FrameLine(15) else
  350.       begin
  351.         if P^.Disabled then
  352.           if P = Current then
  353.             Color := CSelDisabled else
  354.             Color := CNormDisabled else
  355.           if P = Current then Color := CSelect;
  356.         FrameLine(10);
  357.         MoveCStr(B[3], P^.Name^, Color);
  358.         if P^.Command = 0 then
  359.           MoveChar(B[Size.X - 4], #16, Byte(Color), 1) else
  360.           if P^.Param <> nil then
  361.             MoveStr(B[Size.X - 3 - Length(P^.Param^)],
  362.               P^.Param^, Byte(Color));
  363.       end;
  364.       DrawLine;
  365.       P := P^.Next;
  366.     end;
  367.   end;
  368.   Color := CNormal;
  369.   FrameLine(5);
  370.   DrawLine;
  371.   Message(Application, evCommand, cmMouseChanged, @Self);
  372. end;
  373.  
  374. {TPCXControlBox}
  375. constructor TPCXControlBox.Init(P: TPCXPoint);
  376. var
  377.   R    : TRect;
  378.   TempS: String;
  379. begin
  380.   ControlMenuBox:=nil;
  381.   R.A.X:=P.X; R.A.Y:=P.Y;
  382.               R.B.Y:=R.A.Y+1;
  383.   if IsPCXGraphCharsOn
  384.   then begin
  385.          R.B.X:=2;
  386.          TempS:=ControlBox;
  387.         end
  388.   else begin
  389.          R.B.X:=3;
  390.          TempS:='[■]';
  391.        end;
  392.   Inherited Init(R, TempS);
  393. end;
  394.  
  395. procedure TPCXControlBox.HandleEvent(var Event: TEvent);
  396. begin
  397.   ExecControlMenuBox;
  398.   Inherited HandleEvent(Event);
  399. end;
  400.  
  401. procedure TPCXControlBox.ExecControlMenuBox;
  402. begin
  403.   Abstract;
  404. end;
  405.  
  406. procedure TPCXControlBoxApp.ExecControlMenuBox;
  407. var
  408.   R    : TRect;
  409.   O    : TPCXPoint;
  410.   C    : Word;
  411.   Event: TEvent;
  412. begin
  413.   O.Assign(0,0);
  414.   MakeGlobal(O, O);
  415.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  416.   if IsMagyarul then
  417.   begin
  418.     Inc(R.A.X, 2);
  419.     Inc(R.B.X, 2);
  420.   end;
  421.   if Not IsMagyarul then
  422.   New(ControlMenuBox, Init(R, NewMenu(
  423.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  424.     NewItem('~Q~uit', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  425.     NewLine(
  426.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  427.     nil))           else
  428.   New(ControlMenuBox, Init(R, NewMenu(
  429.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  430.     NewItem('~K~ilépés', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  431.     NewLine(
  432.     NewItem('~F~rissítés', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  433.     nil));
  434.   C:=Application^.ExecView(ControlMenuBox);
  435.   if C<>cmCancel then
  436.   begin
  437.     case C of cmMove:
  438.               begin
  439.                 {Application^.GetEvent(Event);
  440.                 Event.What:=evKeyboard;
  441.                 Application^.PutEvent(Event);}
  442.                 KeyStrokeToKeyboardBuffer(0, $62);
  443.                 Message(Application, evCommand, cmMouseChanged, @Self);
  444.               end;
  445.               cmRefresh: Application^.ReDraw;
  446.               cmQuit:  {if AreYouSureToQuit then} Message(Application, evCommand, cmQuit, @Self);
  447.     {javit!}
  448.  
  449.  
  450.     end;
  451.   end;
  452. end;
  453.  
  454. function  TPCXControlBoxApp.GetPalette: PPalette;
  455. const P: String[Length(CPCXControlBoxApp)] = CPCXControlBoxApp;
  456. begin
  457.   GetPalette:=@P;
  458. end;
  459.  
  460. procedure TPCXControlBoxDlg.ExecControlMenuBox;
  461. var
  462.   R    : TRect;
  463.   O    : TPCXPoint;
  464.   C    : Word;
  465.   Event: TEvent;
  466. begin
  467.   O.Assign(1,0);
  468.   MakeGlobal(O, O);
  469.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  470.   if IsMagyarul then
  471.   begin
  472.     Inc(R.A.X);
  473.     Inc(R.B.X);
  474.   end;
  475.   if IsMagyarul then
  476.   New(ControlMenuBox, Init(R, NewMenu(
  477.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  478.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  479.     NewLine(
  480.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  481.     nil))           else
  482.   New(ControlMenuBox, Init(R, NewMenu(
  483.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  484.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  485.     NewLine(
  486.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  487.     nil));
  488.   C:=Application^.ExecView(ControlMenuBox);
  489.   Owner^.EnableCommands([cmClose]);
  490.   EnableCommands([cmClose]);
  491.   if C<>cmCancel then
  492.   begin
  493.     case C of cmMove:
  494.               begin
  495.                 {Application^.GetEvent(Event);
  496.                 Event.What:=evKeyboard;
  497.                 Application^.PutEvent(Event);}
  498.                 KeyStrokeToKeyboardBuffer(0, $62);
  499.                 Message(Application, evCommand, cmMouseChanged, @Self);
  500.               end;
  501.               cmRefresh: Application^.ReDraw;
  502.               cmClose:   begin
  503.                            KeyStrokeToKeyboardBuffer(0, $6A);
  504.                            Message(Application, evBroadcast, cmClose, @Self);
  505.                            Message(Application, evCommand, cmMouseChanged, @Self);
  506.                          end;
  507.     end;
  508.   end;
  509. end;
  510.  
  511. function  TPCXControlBoxDlg.GetPalette: PPalette;
  512. const P: String[Length(CPCXControlBoxDlg)] = CPCXControlBoxDlg;
  513. begin
  514.   GetPalette:=@P;
  515. end;
  516.  
  517. procedure TPCXControlBoxWin.ExecControlMenuBox;
  518. var
  519.   R    : TRect;
  520.   O    : TPCXPoint;
  521.   C    : Word;
  522. begin
  523.   O.Assign(1,0);
  524.   MakeGlobal(O, O);
  525.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  526.   Owner^.EnableCommands([cmClose]);
  527.   EnableCommands([cmClose]);
  528.   if IsMagyarul then
  529.   begin
  530.     Inc(R.A.X);
  531.     Inc(R.B.X);
  532.   end;
  533.   if IsMagyarul then
  534.   New(ControlMenuBox, Init(R, NewMenu(
  535.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  536.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  537.     NewLine(
  538.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  539.     nil))           else
  540.   New(ControlMenuBox, Init(R, NewMenu(
  541.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  542.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  543.     NewLine(
  544.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  545.     nil));
  546.   C:=Application^.ExecView(ControlMenuBox);
  547.   if C<>cmCancel then
  548.   begin
  549.     case C of cmMove:
  550.               begin
  551.                  KeyStrokeToKeyboardBuffer(0, $62);
  552.                  Message(Application, evCommand, cmMouseChanged, @Self);
  553.               end;
  554.               cmRefresh: Application^.ReDraw;
  555.               cmClose:
  556.               begin
  557.                  KeyStrokeToKeyboardBuffer(0, $6A);
  558.                  Message(Application, evCommand, cmMouseChanged, @Self);
  559.               end;
  560.  
  561.     end;
  562.   end;
  563. end;
  564.  
  565. function  TPCXControlBoxWin.GetPalette: PPalette;
  566. const P: String[Length(CPCXControlBoxWin)] = CPCXControlBoxWin;
  567. begin
  568.   GetPalette:=@P;
  569. end;
  570.  
  571. {TPCXMenuBar}
  572. function TPCXMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  573.   AParentMenu: PMenuView): PMenuView;
  574. begin
  575.   NewSubView := New(PPCXMenuBox, Init(Bounds, AMenu, AParentMenu));
  576. end;
  577.  
  578. {TPCXScrollBar}
  579. constructor TPCXScrollBar.Init(var Bounds: TRect);
  580. const
  581.   {                           felb  felj   leb   lej  }
  582.   GVChars: TPCXScrollChars = (#212, #183, #213, #184, GFrameEdgeL, GFrameEdgeR);
  583.                               {╘    ╖     ╒     ╕}
  584.   GHChars: TPCXScrollChars = (#217, #21, #218, #185, #215, #215);
  585.                               {┘        ┌     ╣     ╫     ╫}
  586.   VChars : TPCXScrollChars = (#30, #31, #177, #254, #178, #32); {Text, it's  }
  587.   HChars : TPCXScrollChars = (#17, #16, #177, #254, #178, #32); {the original}
  588. begin
  589.   TView.Init(Bounds);
  590.   if IsPCXGraphCharsOn then TempB:=2
  591.                        else TempB:=1;
  592.   Value := 0;
  593.   Min := 0;
  594.   Max := 0;
  595.   PgStep := 1;
  596.   ArStep := 1;
  597.   if Size.X = TempB then
  598.   begin
  599.     GrowMode := gfGrowLoX + gfGrowHiX + gfGrowHiY;
  600.     if IsPCXGraphCharsOn then Chars := GVChars
  601.                          else Chars := VChars;
  602.     IsHorizontal:=False;
  603.   end else
  604.   begin
  605.     GrowMode := gfGrowLoY+ gfGrowHiX + gfGrowHiY;
  606.     if IsPCXGraphCharsOn then Chars := GHChars
  607.                          else Chars := HChars;
  608.     IsHorizontal:=True;
  609.   end;
  610. end;
  611.  
  612. procedure TPCXScrollBar.Draw;
  613. begin
  614.   DrawPos(GetPos);
  615.   Message(Application, evCommand, cmMouseChanged, @Self);
  616.  
  617.   { Include it to evIdle in HandleEvent for make realtime show|hide scrollbars
  618.   if HScrollBar <> nil then
  619.    if HScrollBar^.Min = HScrollBar^.Max 
  620.    then HScrollBar^.Hide
  621.    else HScrollBar^.Show;
  622.   }
  623. end;
  624.  
  625. procedure TPCXScrollBar.DrawPos(Pos: Integer);
  626. var
  627.   S: Integer;
  628.   B: TDrawBuffer;
  629.   i: Word;
  630. begin
  631.   if IsPCXGraphCharsOn then
  632.   begin
  633.     if Not IsHorizontal then
  634.     begin
  635.       S := GetSize - 1;
  636.       MoveCStr(B[0], Chars[0], GetColor(2));
  637.       MoveCStr(B[1], Chars[1], SwapHighAndLowAreaOfByte(GetColor(2)));
  638.       if Max = Min then
  639.       begin
  640.         i:=0;
  641.         while i<(S*2)-1 do
  642.         begin
  643.           Inc(I,2);
  644.           MoveCStr(B[i], ''+Chars[4]+Chars[5]+'', GetColor(1));
  645.         end;
  646.       end
  647.       else
  648.       begin
  649.           i:=0;
  650.           while i<(S*2)-1 do
  651.           begin
  652.             Inc(i,2);
  653.             MoveCStr(B[i], ''+Chars[4]+Chars[5]+'', GetColor(3));
  654.             MoveCStr(B[Pos*2], ''+Chars[4]+Chars[5]+'', GetColor(4));
  655.           end;
  656.       end;
  657.       MoveCStr(B[S*2], Chars[2], GetColor(2));
  658.       MoveCStr(B[(S*2)+1], Chars[3], SwapHighAndLowAreaOfByte(GetColor(2)));
  659.       WriteBuf(0, 0, Size.X, Size.Y, B);      
  660.     end
  661.     else
  662.     begin
  663.       S := GetSize - 1;
  664.       if Pos=1 then Inc(Pos);
  665.       if Pos+1=S then Pos:=S-3;
  666.       MoveCStr(B[0], Chars[0], GetColor(2));
  667.       MoveCStr(B[1], Chars[1], SwapHighAndLowAreaOfByte(GetColor(2)));
  668.       if Max = Min then
  669.         MoveChar(B[2], Chars[4], GetColor(1), S - 2)
  670.       else
  671.       begin
  672.         MoveChar(B[2], Chars[4], GetColor(3), S - 2);
  673.         MoveCStr(B[Pos], Chars[5]+Chars[5], GetColor(4));
  674.       end;
  675.       MoveCStr(B[S-1], Chars[2], GetColor(2));
  676.       MoveCStr(B[S], Chars[3], SwapHighAndLowAreaOfByte(GetColor(2)));
  677.       WriteBuf(0, 0, Size.X, Size.Y, B);
  678.     end;
  679.   end
  680.   else
  681.   begin
  682.     S := GetSize - 1;
  683.     MoveChar(B[0], Chars[0], GetColor(2), 1);
  684.     if Max = Min then
  685.       MoveChar(B[1], Chars[4], GetColor(1), S - 1)
  686.     else
  687.     begin
  688.       MoveChar(B[1], Chars[2], GetColor(1), S - 1);
  689.       MoveChar(B[Pos], Chars[3], GetColor(3), 1);
  690.     end;
  691.     MoveChar(B[S], Chars[1], GetColor(2), 1);
  692.     WriteBuf(0, 0, Size.X, Size.Y, B);
  693.   end;
  694.   Message(Application, evCommand, cmMouseChanged, @Self);
  695. end;
  696.  
  697. procedure TPCXScrollBar.HandleEvent(var Event: TEvent);
  698. var
  699.   Tracking : Boolean;
  700.   I, P,
  701.   S,
  702.   ClickPart: Integer;
  703.   Mouse    : TPoint;
  704.   Extent   : TRect;
  705. function GetPartCode: Integer;
  706. var
  707.   Mark, Part: Integer;
  708. begin
  709.   Part := -1;
  710.   if Extent.Contains(Mouse) then
  711.   begin
  712.     if Size.X = TempB then Mark := Mouse.Y else Mark := Mouse.X;
  713.     if Mark = P then Part := sbIndicator else
  714.     begin
  715.       if Mark < TempB then Part := sbLeftArrow else
  716.         if Mark < P then Part := sbPageLeft else
  717.           if Mark < S then Part := sbPageRight else
  718.             Part := sbRightArrow;
  719.       if Size.X = TempB then Inc(Part, 4);
  720.     end;
  721.   end;
  722.   GetPartCode := Part;
  723. end;
  724.  
  725. procedure Clicked;
  726. begin
  727.   Message(Owner, evCommand, cmViewChanged, @Self);
  728. end;
  729.  
  730. begin
  731.   TView.HandleEvent(Event);
  732.   case Event.What of
  733.     evMouseDown:
  734.       begin
  735.         Clicked;
  736.         MakeLocal(Event.Where, Mouse);
  737.         GetExtent(Extent);
  738.         Extent.Grow(1, 1);
  739.         P := GetPos;
  740.         S := GetSize - 1;
  741.         ClickPart := GetPartCode;
  742.         if ClickPart <> sbIndicator then
  743.         begin
  744.           repeat
  745.             MakeLocal(Event.Where, Mouse);
  746.             if GetPartCode = ClickPart then
  747.               SetValue(Value + ScrollStep(ClickPart));
  748.           until not MouseEvent(Event, evMouseAuto);
  749.         end else
  750.         begin
  751.           repeat
  752.             MakeLocal(Event.Where, Mouse);
  753.             Tracking := Extent.Contains(Mouse);
  754.             if Tracking then
  755.             begin
  756.               if Size.X = TempB then I := Mouse.Y else I := Mouse.X;
  757.               if I <= 0 then I := 1;
  758.               if I >= S then I := S - 1;
  759.             end else I := GetPos;
  760.             if I <> P then
  761.             begin
  762.               DrawPos(I);
  763.               P := I;
  764.             end;
  765.           until not MouseEvent(Event, evMouseMove);
  766.           if Tracking and (S > 2) then
  767.           begin
  768.             Dec(S, 2);
  769.             SetValue(LongDiv(LongMul(P - 1, Max - Min) + S shr 1, S) + Min);
  770.           end;
  771.         end;
  772.         ClearEvent(Event);
  773.       end;
  774.     evKeyDown:
  775.       if State and sfVisible <> 0 then
  776.       begin
  777.         ClickPart := sbIndicator;
  778.         if Size.Y = 1 then
  779.           case CtrlToArrow(Event.KeyCode) of
  780.             kbLeft: ClickPart := sbLeftArrow;
  781.             kbRight: ClickPart := sbRightArrow;
  782.             kbCtrlLeft: ClickPart := sbPageLeft;
  783.             kbCtrlRight: ClickPart := sbPageRight;
  784.             kbHome: I := Min;
  785.             kbEnd: I := Max;
  786.           else
  787.             Exit;
  788.           end
  789.         else
  790.           case CtrlToArrow(Event.KeyCode) of
  791.             kbUp: ClickPart := sbUpArrow;
  792.             kbDown: ClickPart := sbDownArrow;
  793.             kbPgUp: ClickPart := sbPageUp;
  794.             kbPgDn: ClickPart := sbPageDown;
  795.             kbCtrlPgUp: I := Min;
  796.             kbCtrlPgDn: I := Max;
  797.           else
  798.             Exit;
  799.           end;
  800.         Clicked;
  801.         if ClickPart <> sbIndicator then I := Value + ScrollStep(ClickPart);
  802.         SetValue(I);
  803.         ClearEvent(Event);
  804.       end;
  805.   end;
  806. end;
  807.  
  808. function TPCXScrollBar.GetPalette: PPalette;
  809. const P: String[Length(CPCXScrollBar)] = CPCXScrollBar;
  810. begin
  811.   GetPalette:=@P;
  812. end;
  813.  
  814. function TPCXScrollBar.GetPos: Integer;
  815. var
  816.   R: Integer;
  817. begin
  818.   R := Max - Min;
  819.   if R = 0 then
  820.     GetPos := 1 else
  821.     GetPos := LongDiv(LongMul(Value - Min, GetSize - 3) + R shr 1, R) + 1;
  822. end;
  823.  
  824. function TPCXScrollBar.GetSize: Integer;
  825. var
  826.   S: Integer;
  827. begin
  828.   if Size.X = TempB then S := Size.Y else S := Size.X;
  829.   if S < 2+TempB then GetSize := 2+TempB else GetSize := S;
  830. end;
  831.  
  832. {TPCXFrame}
  833. procedure TPCXFrame.Draw;
  834. var
  835.   CFrame, CTitle: Word;
  836.   F, I, L, Width: Integer;
  837.   B: TDrawBuffer;
  838.   Title: TTitleStr;
  839.   Min, Max: TPoint;
  840. begin
  841.   if State and sfDragging <> 0 then
  842.   begin
  843.     CFrame := $0706;
  844.     CTitle := $0007;
  845.     F := 0;
  846.   end else if State and sfActive = 0 then
  847.   begin
  848.     CFrame := $0101;
  849.     CTitle := $0002;
  850.     F := 0;
  851.   end else
  852.   begin
  853.     CFrame := $0503;
  854.     CTitle := $0004;
  855.     F := 9;
  856.   end;
  857.   CFrame := GetColor(CFrame);
  858.   CTitle := GetColor(CTitle);
  859.   Width := Size.X;
  860.   L := Width - 10;
  861.   if PWindow(Owner)^.Flags and (wfClose+wfZoom) <> 0 then Dec(L,6);
  862.   if IsPCXGraphCharsOn then MoveCStr(B, Copy(FrameEmpty, 1, Size.X), CTitle)
  863.                        else MoveCStr(B, Copy(FrameEmpty, 1, Size.X), CTitle);
  864.   if (PWindow(Owner)^.Number <> wnNoNumber) and
  865.      (PWindow(Owner)^.Number < 10) then
  866.   begin
  867.     Dec(L,4);
  868.     if PWindow(Owner)^.Flags and wfZoom <> 0 then I := 7
  869.     else I := 3;
  870.     WordRec(B[Width - I]).Lo := PWindow(Owner)^.Number + $30;
  871.   end;
  872.   if Owner <> nil then Title := PWindow(Owner)^.GetTitle(L)
  873.   else Title := '';
  874.   if Title <> '' then
  875.   begin
  876.     L := Length(Title);
  877.     if L > Width - 10 then L := Width - 10;
  878.     if L < 0 then L := 0;
  879.     I := (Width - L) shr 1;
  880.     MoveChar(B[I - 1], ' ', CTitle, 1);
  881.     MoveBuf(B[I], Title[1], CTitle, L);
  882.     MoveChar(B[I + L], ' ', CTitle, 1);
  883.   end;
  884.   if State and sfActive <> 0 then
  885.   begin
  886.     if PWindow(Owner)^.Flags and wfClose <> 0 then
  887.       if FrameMode and fmCloseClicked = 0 then
  888.         if IsPCXGraphCharsOn then MoveCStr(B[0], '~'+ControlBox+'~', CFrame) {#209#180}
  889.                              else MoveCStr(B[1], '', CFrame) {~[■]~}
  890.       else MoveCStr(B[2], '[~'#15'~]', CFrame);
  891.     if PWindow(Owner)^.Flags and wfZoom <> 0 then
  892.     begin
  893.       if IsPCXGraphCharsOn then MoveCStr(B[Width - 4], '~'+UpWin+'~', CFrame)
  894.                            else MoveCStr(B[Width - 4], '~['#24']~', CFrame);
  895.       Owner^.SizeLimits(Min, Max);
  896.       if FrameMode and fmZoomClicked <> 0 then
  897.         WordRec(B[Width - 4]).Lo := 15
  898.       else if Longint(Owner^.Size) = Longint(Max) then
  899.       begin
  900.         if IsPCXGraphCharsOn then MoveCStr(B[Width - 4], '~'+RestoreWin+'~', CFrame)
  901.                              else MoveCStr(B[Width - 4], '~['#18']~', CFrame);
  902.       end;
  903.     end;
  904.   end;
  905.   WriteLine(0, 0, Size.X, 1, B);
  906.   for I := 1 to Size.Y - 2 do
  907.   begin
  908.     if IsPCXGraphCharsOn then MoveCStr(B, GFrameEdgeL+Copy(FrameEmpty, 1, Size.X-2)+GFrameEdgeR, CFrame)
  909.                          else MoveCStr(B, #221+Copy(FrameEmpty, 1, Size.X-2)+#222, CFrame);
  910.     WriteLine(0, I, Size.X, 1, B);
  911.   end;
  912.   if IsPCXGraphCharsOn then MoveCStr(B, GFrameCornerLD+Copy(GFrameDown, 1, Size.X-2)+GFrameCornerRD, CFrame)
  913.                        else MoveCStr(B, {#221+} Copy(FrameDown{FrameFull}, 1, Size.X) {+#222}, CFrame);
  914.   if State and sfActive <> 0 then
  915.     if PWindow(Owner)^.Flags and wfGrow <> 0 then
  916.       if IsPCXGraphCharsOn then MoveCStr(B[Width - 2], WindowSizer, CFrame) {#210#211}
  917.                            else MoveCStr(B[Width - 2], '~─┘~', CFrame);
  918.   WriteLine(0, Size.Y - 1, Size.X, 1, B);
  919.   Message(Application, evCommand, cmMouseChanged, @Self);
  920.   Message(Application, evCommand, cmPCXFrameChanged, @Self);
  921.   Message(Application, evBroadcast, cmPCXFrameChanged, @Self);
  922. end;
  923.  
  924. function  TPCXFrame.GetPalette: PPalette;
  925. const P: String[Length(CPCXFrame)] = CPCXFrame;
  926. begin
  927.   GetPalette:=@P;
  928. end;
  929.  
  930. {TPCXWindow}
  931. constructor TPCXWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  932. var P: TPCXPoint;
  933. begin
  934.   Inherited Init(Bounds, ATitle, ANumber);
  935.   P.Assign(0, 0);
  936.   New(ControlBoxWin, Init(P));
  937.   Insert(ControlBoxWin);
  938. end;
  939.  
  940. procedure TPCXWindow.InitFrame;
  941. var R: TRect;
  942. begin
  943.   GetExtent(R);
  944.   Frame := New(PPCXFrame, Init(R));
  945. end;
  946.  
  947. procedure TPCXWindow.Draw;
  948. begin
  949.   Inherited Draw;
  950.   Message(Application, evCommand, cmMouseChanged, @Self);  
  951. end;
  952.  
  953. function  TPCXWindow.GetPalette: PPalette;
  954. const P: String[Length(CPCXWindow)] = CPCXWindow;
  955. begin
  956.   GetPalette:=@P;
  957. end;
  958.  
  959. procedure TPCXWindow.HandleEvent(var Event: TEvent);
  960. begin
  961.   if Event.KeyCode=kbAltSpace then
  962.   begin
  963.     ControlBoxWin^.ExecControlMenuBox;
  964.     Event.KeyCode:=Event.KeyCode and Not kbAltSpace;
  965.   end;
  966.   Inherited HandleEvent(Event);
  967. end;
  968.  
  969. function TPCXWindow.StandardScrollBar(AOptions: Word): PPCXScrollBar;
  970. var
  971.   R: TRect;
  972.   S: PPCXScrollBar;
  973. begin
  974.   GetExtent(R);
  975.   if AOptions and sbGraphLike = 0
  976.   then if AOptions and sbVertical = 0 
  977.        then R.Assign(R.A.X + 2, R.B.Y-1, R.B.X-2, R.B.Y) 
  978.        else R.Assign(R.B.X-1,R.A.Y+1,R.B.X,R.B.Y-1)
  979.   else if AOptions and sbVertical = 0 
  980.        then R.Assign(R.A.X + 2, R.B.Y-1, R.B.X-2, R.B.Y) 
  981.        else R.Assign(R.B.X-2,R.A.Y+1,R.B.X,R.B.Y-1);
  982.   S := New(PPCXScrollBar, Init(R));
  983.   Insert(S);
  984.   if AOptions and sbHandleKeyboard <> 0 
  985.   then S^.Options := S^.Options or ofPostProcess;
  986.   StandardScrollBar := S;
  987. end;
  988.  
  989. {TPCXXXXXWindows}
  990. function  TPCXBlueWindow.GetPalette: PPalette;
  991. const P: String[Length(CPCXBlueWindow)] = CPCXBlueWindow;
  992. begin
  993.   GetPalette:=@P;
  994. end;
  995.  
  996. function  TPCXRedWindow.GetPalette: PPalette;
  997. const P: String[Length(CPCXRedWindow)] = CPCXRedWindow;
  998. begin
  999.   GetPalette:=@P;
  1000. end;
  1001.  
  1002. function  TPCXGrayWindow.GetPalette: PPalette;
  1003. const P: String[Length(CPCXGrayWindow)] = CPCXGrayWindow;
  1004. begin
  1005.   GetPalette:=@P;
  1006. end;
  1007.  
  1008. {TPCXDialog}
  1009. constructor TPCXDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  1010. var P: TPCXPoint;
  1011. begin
  1012.   Inherited Init(Bounds, ATitle);
  1013.   P.Assign(0,0);
  1014.   New(ControlBoxDlg, Init(P));
  1015.   Insert(ControlBoxDlg);
  1016. end;
  1017.  
  1018. procedure TPCXDialog.InitFrame;
  1019. var
  1020.   R: TRect;
  1021. begin
  1022.   GetExtent(R);
  1023.   Frame := New(PPCXFrame, Init(R));
  1024. end;
  1025.  
  1026. procedure TPCXDialog.Draw;
  1027. begin
  1028.   Inherited Draw;
  1029.   Message(Application, evCommand, cmMouseChanged, @Self);  
  1030. end;
  1031.  
  1032. function  TPCXDialog.GetPalette: PPalette;
  1033. const P: String[Length(CPCXDialog)] = CPCXDialog;
  1034. begin
  1035.   GetPalette:=@P;
  1036. end;
  1037.  
  1038. procedure TPCXDialog.HandleEvent(var Event: TEvent);
  1039. begin
  1040.   if Event.KeyCode=kbAltSpace then
  1041.   begin
  1042.     ControlBoxDlg^.ExecControlMenuBox;
  1043.     Event.KeyCode:=Event.KeyCode and Not kbAltSpace;
  1044.   end;
  1045.   Inherited HandleEvent(Event);
  1046. end;
  1047.  
  1048. function  TPCXBlueDialog.GetPalette: PPalette;
  1049. const P: String[Length(CPCXBlueDialog)] = CPCXBlueDialog;
  1050. begin
  1051.   GetPalette:=@P;
  1052. end;
  1053.  
  1054. function  TPCXRedDialog.GetPalette: PPalette;
  1055. const P: String[Length(CPCXRedDialog)] = CPCXRedDialog;
  1056. begin
  1057.   GetPalette:=@P;
  1058. end;
  1059.  
  1060. function  TPCXGrayDialog.GetPalette: PPalette;
  1061. const P: String[Length(CPCXGrayDialog)] = CPCXGrayDialog;
  1062. begin
  1063.   GetPalette:=@P;
  1064. end;
  1065.  
  1066. {TPCXIndicator}
  1067. procedure TPCXIndicator.Draw;
  1068. var
  1069.   Color, Color2: Byte;
  1070.   Frame: Char;
  1071.   L: Array[0..1] of Longint;
  1072.   S: String[15];
  1073.   B: TDrawBuffer;
  1074. begin
  1075.   if State and sfDragging = 0 then
  1076.   begin
  1077.     Color := GetColor(1);
  1078.     Color2:= GetColor(3);
  1079.     Frame := GFrameSummitD;
  1080.   end else
  1081.   begin
  1082.     Color := GetColor(2);
  1083.     Color2:= SwapHighAndLowAreaOfByte(GetColor(4));
  1084.     Frame := GFrameSummitD;
  1085.   end;
  1086.   MoveChar(B, Frame, Color, Size.X);
  1087.   if Modified then WordRec(B[0]).Lo := 28;
  1088.   L[0] := Location.Y + 1;
  1089.   L[1] := Location.X + 1;
  1090.   FormatStr(S, ' %d:%d ', L);
  1091.   MoveStr(B[8 - Pos(':', S)], S, Color2);
  1092.   WriteBuf(0, 0, Size.X, 1, B);
  1093.   Message(Application, evCommand, cmMouseChanged, @Self);
  1094. end;
  1095.  
  1096. function  TPCXIndicator.GetPalette: PPalette;
  1097. const P: String[Length(CPCXIndicator)] = CPCXIndicator;
  1098. begin
  1099.   GetPalette:=@P;
  1100. end;
  1101.  
  1102. {TPCXFileEditor}
  1103. function  TPCXFileEditor.GetPalette: PPalette;
  1104. const P: String[Length(CPCXFileEditor)] = CPCXFileEditor;
  1105. begin
  1106.   GetPalette:=@P;
  1107. end;
  1108.  
  1109. {TPCXEditWindow}
  1110. constructor TPCXEditWindow.Init(var Bounds: TRect; FileName: FNameStr; ANumber: Integer);
  1111. var
  1112.   P: TPCXPoint;
  1113.   HScrollBar, VScrollBar: PPCXScrollBar;
  1114.   Indicator: PPCXIndicator;
  1115.   R: TRect;
  1116. begin
  1117.   Inherited Init(Bounds, '', ANumber);
  1118.   Options := Options or ofTileable;
  1119.   R.Assign(18, Size.Y - 1, Size.X - 2, Size.Y);
  1120.   HScrollBar := New(PPCXScrollBar, Init(R));
  1121.   HScrollBar^.Hide;
  1122.   Insert(HScrollBar);
  1123.   R.Assign(Size.X - 2, 1, Size.X, Size.Y - 1);
  1124.   VScrollBar := New(PPCXScrollBar, Init(R));
  1125.   VScrollBar^.Hide;
  1126.   Insert(VScrollBar);
  1127.   R.Assign(2, Size.Y - 1, 16, Size.Y);
  1128.   Indicator := New(PPCXIndicator, Init(R));
  1129.   Indicator^.Hide;
  1130.   Insert(Indicator);
  1131.   GetExtent(R);
  1132.   R.Grow(-2, -1);
  1133.   Editor := New(PPCXFileEditor, Init(R, HScrollBar, VScrollBar, Indicator, FileName));
  1134.   Insert(Editor);
  1135.  
  1136.   P.Assign(0,0);
  1137.   New(ControlBoxWin, Init(P));
  1138.   Insert(ControlBoxWin);
  1139. end;
  1140.  
  1141. procedure TPCXEditWindow.InitFrame;
  1142. var
  1143.   R: TRect;
  1144. begin
  1145.   GetExtent(R);
  1146.   Frame := New(PPCXFrame, Init(R));
  1147. end;
  1148.  
  1149. function  TPCXEditWindow.GetPalette: PPalette;
  1150. const P: String[Length(CPCXWindow)] = CPCXWindow;
  1151. begin
  1152.   GetPalette:=@P;
  1153. end;
  1154.  
  1155. procedure TPCXEditWindow.HandleEvent(var Event: TEvent);
  1156. begin
  1157.   if Event.KeyCode=kbAltSpace then ControlBoxWin^.ExecControlMenuBox;
  1158.   Inherited HandleEvent(Event);
  1159.   if Event.Command = cmNewLine then
  1160.   begin
  1161.     Event.KeyCode:=Event.KeyCode and (Not kbAltSpace);
  1162.     Event.Command:= Event.Command and (Not cmNewLine);
  1163.   end;
  1164. end;
  1165.  
  1166. function  TPCXEditBlueWindow.GetPalette: PPalette;
  1167. const P: String[Length(CPCXBlueWindow)] = CPCXBlueWindow;
  1168. begin
  1169.   GetPalette:=@P;
  1170. end;
  1171.  
  1172. {TPCXStaticText}
  1173. procedure TPCXStaticText.SetText(AText: String);
  1174. begin
  1175.   if Text<>nil then DisposeStr(Text);   {Idea: By Bérczi Gábor, Power INC.}
  1176.   if AText<>'' then Text:=NewStr(AText) {      TOO . . .                  }
  1177.                else Text:=Nil;          {      TOO . . .                  }
  1178.   Draw;
  1179.   Message(Application, evCommand, cmMouseChanged, @Self);
  1180. end;
  1181.  
  1182. {TPCXButton}
  1183. procedure TPCXButton.Draw;
  1184. begin
  1185.   DrawState(False);
  1186.   Message(Application, evCommand, cmMouseChanged, @Self);
  1187. end;
  1188.  
  1189. procedure TPCXButton.DrawState(Down: Boolean);
  1190. var
  1191.   CButton, CShadow: Word;
  1192.   Ch: Char;
  1193.   I, S, Y, T: Integer;
  1194.   B: TDrawBuffer;
  1195.  
  1196. procedure DrawTitle;
  1197. var
  1198.   L, SCOff: Integer;
  1199. begin
  1200.   if Flags and bfLeftJust <> 0 then L := 1 else
  1201.   begin
  1202.     L := (S - CStrLen(Title^) - 1) div 2;
  1203.     if L < 1 then L := 1;
  1204.   end;
  1205.   MoveCStr(B[I + L], Title^, CButton);
  1206.   if ShowMarkers and not Down then
  1207.   begin
  1208.     if State and sfSelected <> 0 then SCOff := 0 else
  1209.       if AmDefault then SCOff := 2 else SCOff := 4;
  1210.     WordRec(B[0]).Lo := Byte(SpecialChars[SCOff]);
  1211.     WordRec(B[S]).Lo := Byte(SpecialChars[SCOff + 1]);
  1212.   end;
  1213. end;
  1214.  
  1215. begin
  1216.   if State and sfDisabled <> 0 then CButton := GetColor($0404) else
  1217.   begin
  1218.     CButton := GetColor($0501);
  1219.     if State and sfActive <> 0 then
  1220.       if State and sfSelected <> 0 then CButton := GetColor($0703) else
  1221.         if AmDefault then CButton := GetColor($0602);
  1222.   end;
  1223.   CShadow := GetColor(8);
  1224.   S := Size.X - 1;
  1225.   T := Size.Y div 2 - 1;
  1226.   for Y := 0 to Size.Y - 2 do
  1227.   begin
  1228.     MoveChar(B, ' ', Byte(CButton), Size.X);
  1229.     WordRec(B[0]).Hi := CShadow;
  1230.     if Down then
  1231.     begin
  1232.       WordRec(B[1]).Hi := CShadow;
  1233.       Ch := ' ';
  1234.       I := 2;
  1235.     end else
  1236.     begin
  1237.       if ShowMarkers then WordRec(B[S]).Hi := Byte(CShadow)
  1238.                      else WordRec(B[S]).Hi := SwapHighAndLowAreaOfByte(Byte(CShadow)); {from PCX_Util}
  1239.       if ShowMarkers then Ch := ' ' else
  1240.       begin
  1241.         if Y = 0 then
  1242.           WordRec(B[S]).Lo := Byte('▀') else {#223 invert = #220}
  1243.           WordRec(B[S]).Lo := Byte('█');
  1244.         Ch := '▀';
  1245.       end;
  1246.       I := 1;
  1247.     end;
  1248.     if (Y = T) and (Title <> nil) then DrawTitle;
  1249.     if ShowMarkers and not Down then
  1250.     begin
  1251.       WordRec(B[1]).Lo := Byte('[');
  1252.       WordRec(B[S - 1]).Lo := Byte(']');
  1253.     end;
  1254.     WriteLine(0, Y, Size.X, 1, B);
  1255.   end;
  1256.   MoveChar(B[0], ' ', Byte(CShadow), 2);
  1257.   MoveChar(B[2], Ch, Byte(CShadow), S - 1);
  1258.   WriteLine(0, Size.Y - 1, Size.X, 1, B);
  1259. end;
  1260.  
  1261. function HotKey(const S: String): Char;
  1262. var
  1263.   P: Word;
  1264. begin
  1265.   P := Pos('~',S);
  1266.   if P <> 0 then HotKey := UpCase(S[P+1])
  1267.   else HotKey := #0;
  1268. end;
  1269.  
  1270. const
  1271.  
  1272. { TButton messages }
  1273.  
  1274.   cmGrabDefault    = 61;
  1275.   cmReleaseDefault = 62;
  1276.  
  1277. procedure TPCXButton.HandleEvent(var Event: TEvent);
  1278. var
  1279.   Down: Boolean;
  1280.   C: Char;
  1281.   Mouse: TPoint;
  1282.   ClickRect: TRect;
  1283. begin
  1284.   GetExtent(ClickRect);
  1285.   Inc(ClickRect.A.X);
  1286.   Dec(ClickRect.B.X);
  1287.   Dec(ClickRect.B.Y);
  1288.   if Event.What = evMouseDown then
  1289.   begin
  1290.     MakeLocal(Event.Where, Mouse);
  1291.     if not ClickRect.Contains(Mouse) then ClearEvent(Event);
  1292.   end;
  1293.   if Flags and bfGrabFocus <> 0 then
  1294.     TView.HandleEvent(Event);
  1295.   case Event.What of
  1296.     evMouseDown:
  1297.       begin
  1298.         if State and sfDisabled = 0 then
  1299.         begin
  1300.           Inc(ClickRect.B.X);
  1301.           Down := False;
  1302.           repeat
  1303.             MakeLocal(Event.Where, Mouse);
  1304.             if Down <> ClickRect.Contains(Mouse) then
  1305.             begin
  1306.               Down := not Down;
  1307.               DrawState(Down);
  1308.             end;
  1309.           until not MouseEvent(Event, evMouseMove);
  1310.           if Down then
  1311.           begin
  1312.             Press;
  1313.             DrawState(False);
  1314.           end;
  1315.         end;
  1316.         ClearEvent(Event);
  1317.       end;
  1318.     evKeyDown:
  1319.       begin
  1320.         C := HotKey(Title^);
  1321.         if (Event.KeyCode = GetAltCode(C)) or
  1322.           (Owner^.Phase = phPostProcess) and (C <> #0) and
  1323.             (Upcase(Event.CharCode) = C) or
  1324.           (State and sfFocused <> 0) and (Event.CharCode = ' ') then
  1325.         begin
  1326.           Press;
  1327.           ClearEvent(Event);
  1328.         end;
  1329.       end;
  1330.     evBroadcast:
  1331.       case Event.Command of
  1332.         cmDefault:
  1333.           if AmDefault then
  1334.           begin
  1335.             Press;
  1336.             ClearEvent(Event);
  1337.           end;
  1338.         cmGrabDefault, cmReleaseDefault:
  1339.           if Flags and bfDefault <> 0 then
  1340.           begin
  1341.             AmDefault := Event.Command = cmReleaseDefault;
  1342.             DrawView;
  1343.           end;
  1344.         cmCommandSetChanged:
  1345.           begin
  1346.             SetState(sfDisabled, not CommandEnabled(Command));
  1347.             DrawView;
  1348.           end;
  1349.       end;
  1350.   end;
  1351. end;
  1352.  
  1353. procedure TPCXButton.ResetCursor; assembler;
  1354. asm
  1355.         LES     DI,Self
  1356.         MOV     AX,ES:[DI].TPCXButton.State
  1357.         NOT     AX
  1358.         TEST    AX,sfVisible+sfCursorVis+sfFocused
  1359.         JNE     @@4
  1360.         MOV     AX,ES:[DI].TView.Cursor.Y
  1361.         MOV     DX,ES:[DI].TView.Cursor.X
  1362. @@1:    OR      AX,AX
  1363.         JL      @@4
  1364.         CMP     AX,ES:[DI].TPCXButton.Size.Y
  1365.         JGE     @@4
  1366.         OR      DX,DX
  1367.         JL      @@4
  1368.         CMP     DX,ES:[DI].TPCXButton.Size.X
  1369.         JGE     @@4
  1370.         ADD     AX,ES:[DI].TPCXButton.Origin.Y
  1371.         ADD     DX,ES:[DI].TPCXButton.Origin.X
  1372.         MOV     CX,DI
  1373.         MOV     BX,ES
  1374.         LES     DI,ES:[DI].TPCXButton.Owner
  1375.         MOV     SI,ES
  1376.         OR      SI,DI
  1377.         JE      @@5
  1378.         TEST    ES:[DI].TPCXButton.State,sfVisible
  1379.         JE      @@4
  1380.         LES     DI,ES:[DI].TGroup.Last
  1381. @@2:    LES     DI,ES:[DI].TPCXButton.Next
  1382.         CMP     CX,DI
  1383.         JNE     @@3
  1384.         MOV     SI,ES
  1385.         CMP     BX,SI
  1386.         JNE     @@3
  1387.         LES     DI,ES:[DI].TPCXButton.Owner
  1388.         JMP     @@1
  1389. @@3:    TEST    ES:[DI].TPCXButton.State,sfVisible
  1390.         JE      @@2
  1391.         MOV     SI,ES:[DI].TPCXButton.Origin.Y
  1392.         CMP     AX,SI
  1393.         JL      @@2
  1394.         ADD     SI,ES:[DI].TPCXButton.Size.Y
  1395.         CMP     AX,SI
  1396.         JGE     @@2
  1397.         MOV     SI,ES:[DI].TPCXButton.Origin.X
  1398.         CMP     DX,SI
  1399.         JL      @@2
  1400.         ADD     SI,ES:[DI].TPCXButton.Size.X
  1401.         CMP     DX,SI
  1402.         JGE     @@2
  1403. @@4:    MOV     CX,2000H
  1404.         JMP     @@6
  1405. @@5:    MOV     DH,AL
  1406.         XOR     BH,BH
  1407.         MOV     AH,2
  1408.         INT     10H
  1409.         MOV     CX,CursorLines
  1410.         LES     DI,Self
  1411.         TEST    ES:[DI].TPCXButton.State,sfCursorIns
  1412.         JE      @@6
  1413.         MOV     CH,0
  1414.         OR      CL,CL
  1415.         JNE     @@6
  1416.         MOV     CL,7
  1417. @@6:    MOV     AH,1
  1418.         INT     10H
  1419. end;
  1420.  
  1421. procedure TPCXButton.DrawCursor;
  1422. begin
  1423.   if State and sfFocused <> 0 then ResetCursor;
  1424. end;
  1425.  
  1426.  
  1427. procedure TPCXButton.DrawView;
  1428. begin
  1429.   if Exposed then
  1430.   begin
  1431.     Draw;
  1432.     DrawCursor;
  1433.   end;
  1434. end;
  1435.  
  1436.  
  1437. END.