home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 July / pcx23_9807.iso / PC-XUSER / PC-XUSER.18 / OOP / PCX_DLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-06-14  |  57.6 KB  |  2,071 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, StdDlg, DOS;
  17.  
  18.  
  19. const
  20.  
  21.   GFrameCornerLU         = #193;   {┌}                     {Corner=Sarok  }
  22.   GFrameCornerRU         = #194;   {┐}                     {L=Left;R=Right}
  23.   GFrameCornerLD         = #195;   {└}                     {U=Up  ;D=Down }
  24.   GFrameCornerRD         = #197;   {┘}
  25.   GFrameSummitU          = #198;   {─}                     {Summit=Tetô   }
  26.   GFrameSummitD          = #199;   {─}
  27.   GFrameEdgeL            = #200;   {│}                     {Edge=Szél(e)  }
  28.   GFrameEdgeR            = #201;   {│}
  29.  
  30.   CheckBoxCenterN  =  #203; {' '}
  31.   CheckBoxCenterX  =  #204; {'X'}
  32.   CheckBoxLeft     =  #202; {'['}
  33.   CheckBoxRight    =  #181; {']'}
  34.   RadioButtonCenterN = #207; {' '}
  35.   RadioButtonCenterX = #206; { #7}
  36.   RadioButtonLeft    = #205; {'('}
  37.   RadioButtonRight   = #182; {')'}
  38.  
  39.   cmMouseChanged       = 1003;
  40.   cmCheckBoxChanged    = 1004;
  41.   cmRadioButtonChanged = 1005;
  42.   cmViewChanged        = 1006;
  43.   cmMove               = 1007;
  44.   cmRefresh            = 1008;
  45.   cmPCXFrameChanged    = 1009;
  46.  
  47. { Color palettes }
  48.  
  49.   {CPCXDialogs}
  50.   CPCXBlueDialog =
  51.     #64#65#66#67#68#69#70#71#72#73#74#75#76#77#78#79+                {  1- 16}
  52.     #80#81#82#83#84#85#86#87#88#89#90#91#92#92#94#95+                { 17- 32}
  53.     #96#97#98#99#100;                                                { 33- 37}
  54.     {#64-#100}
  55.   CPCXRedDialog  =
  56.     #101#102#103#104#105#106#107#108#109#110#111#112#113#114#115#116+{  1- 16}
  57.     #117#118#119#120#121#122#123#124#125#126#127#128#129#130#131#132+{ 17- 32}
  58.     #133#134#135#136#137;                                            { 33- 37}
  59.     {#101-#137}
  60.   CPCXGrayDialog =
  61.     #138#139#140#141#142#143#144#145#146#147#148#149#150#151#152#153+{  1- 16}
  62.     #154#155#156#157#158#159#160#161#162#163#164#165#166#167#168#169+{ 17- 32}
  63.     #170#171#172#173#174;                                            { 33- 37}
  64.     {#138-#174}
  65.   CPCXDialog     = CGrayDialog+#170#171#172#173#174;
  66.  
  67.   {CPCXWindows}
  68.   CPCXWindow     = CPCXDialog;
  69.   CPCXBlueWindow = CPCXBlueDialog;
  70.   CPCXRedWindow  = CPCXRedDialog;
  71.   CPCXGrayWindow = CPCXGrayDialog;
  72.  
  73.   CPCXIndicator  = #2#37#3#37;
  74.   CPCXFileEditor = #6#4;
  75.  
  76.   CPCXTitleBar      = #175;
  77.   CPCXControlBoxApp = #175;
  78.   CPCXControlBoxDlg = #34;
  79.   CPCXControlBoxWin = #34;
  80.  
  81.   CPCXFrame = #1#33#2#34#36#37#35; {CFrame + DragWindow + DragTitle}
  82.   CPCXFrame3D = #15#8; {CFrame3D + CFrame3DTitle}
  83.   CPCXScrollBar = #4#5#4#5; {CSrollBar + CMyScroolBox}
  84.  
  85.   CPCXCheckBoxes   = #8#9#9#9;
  86.   CPCXRadioButtons = #8#9#9#9;
  87.  
  88. {FrameType}
  89.   AllGraphFrame  = 1;
  90.   HalfGraphFrame = 2;
  91.   TextFrame      = 3;
  92. {FrameColor}
  93.   FrameBlack     = 1;
  94.   FrameWhite     = 2;
  95.  
  96. type
  97.   PString = OBJECTS.PString;
  98.  
  99.   PPCXPoint = ^TPCXPoint;
  100.   TPCXPoint = Object(TPoint)
  101.     procedure Assign(XA, YA: Integer);
  102.   end;
  103.  
  104.   PPCXMenuBox = ^TPCXMenuBox;
  105.   TPCXMenuBox = Object(TMenuBox)
  106.     procedure Draw; virtual;
  107.   end;
  108.  
  109.   PPCXControlBox = ^TPCXControlBox;
  110.   TPCXControlBox = Object(TStaticText)
  111.     constructor Init(P: TPCXPoint);
  112.     procedure HandleEvent(var Event: TEvent); virtual;
  113.     procedure ExecControlMenuBox; virtual;
  114.   private
  115.     ControlMenuBox: PPCXMenuBox;
  116.   end;
  117.  
  118.   PPCXControlBoxApp = ^TPCXControlBoxApp;
  119.   TPCXControlBoxApp = Object(TPCXControlBox)
  120.     function  GetPalette: PPalette; virtual;
  121.     procedure ExecControlMenuBox; virtual;
  122.   end;
  123.  
  124.   PPCXControlBoxDlg = ^TPCXControlBoxDlg;
  125.   TPCXControlBoxDlg = Object(TPCXControlBox)
  126.     function  GetPalette: PPalette; virtual;
  127.     procedure ExecControlMenuBox; virtual;
  128.   end;
  129.  
  130.   PPCXControlBoxWin = ^TPCXControlBoxWin;
  131.   TPCXControlBoxWin = Object(TPCXControlBox)
  132.     function  GetPalette: PPalette; virtual;
  133.     procedure ExecControlMenuBox; virtual;
  134.   end;
  135.  
  136.   PPCXMenuBar = ^TPCXMenuBar;
  137.   TPCXMenuBar = Object(TMenuBar)
  138.     function NewSubView(var Bounds: TRect; AMenu: PMenu;
  139.       AParentMenu: PMenuView): PMenuView; virtual;
  140.   end;
  141.  
  142.   TPCXScrollChars = Array[0..5] of Char;
  143.  
  144.   PPCXScrollBar = ^TPCXScrollBar;
  145.   TPCXScrollBar = Object(TScrollBar)
  146.     constructor Init(var Bounds: TRect);
  147.     procedure Draw; virtual;
  148.     procedure HandleEvent(var Event: TEvent); virtual;
  149.     function  GetPalette: PPalette; virtual;
  150.   private
  151.     Chars: TPCXScrollChars;
  152.     TempB: Byte;
  153.     IsHorizontal: Boolean;
  154.     procedure DrawPos(Pos: Integer);
  155.     function GetPos: Integer;
  156.     function GetSize: Integer;
  157.   end;
  158.  
  159.   PPCXFrame = ^TPCXFrame;
  160.   TPCXFrame = Object(TFrame)
  161.     procedure Draw; virtual;
  162.     function  GetPalette: PPalette; virtual;
  163.   private
  164.     FrameMode: Word;
  165.   end;
  166.  
  167.   PPCXWindow = ^TPCXWindow;
  168.   TPCXWindow = Object(TWindow)
  169.     constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  170.     procedure InitFrame; virtual;
  171.     procedure Draw; virtual;
  172.     function  GetPalette: PPalette; virtual;
  173.     procedure HandleEvent(var Event: TEvent); virtual;
  174.     function  StandardScrollBar(AOptions: Word): PPCXScrollBar;
  175.   private
  176.     ControlBoxWin: PPCXControlBoxWin;
  177.   end;
  178.  
  179.   PPCXBlueWindow = ^TPCXBlueWindow;
  180.   TPCXBlueWindow = Object(TPCXWindow)
  181.     function  GetPalette: PPalette; virtual;
  182.   end;
  183.  
  184.   PPCXRedWindow = ^TPCXRedWindow;
  185.   TPCXRedWindow = Object(TPCXWindow)
  186.     function  GetPalette: PPalette; virtual;
  187.   end;
  188.  
  189.   PPCXGrayWindow = ^TPCXGrayWindow;
  190.   TPCXGrayWindow = Object(TPCXWindow)
  191.     function  GetPalette: PPalette; virtual;
  192.   end;
  193.  
  194.   PPCXDialog = ^TPCXDialog;
  195.   TPCXDialog = Object(TDialog)
  196.     constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  197.     procedure InitFrame; virtual;
  198.     procedure Draw; virtual;
  199.     function  GetPalette: PPalette; virtual;
  200.     procedure HandleEvent(var Event: TEvent); virtual;
  201.   private
  202.     ControlBoxDlg: PPCXControlBoxDlg;
  203.   end;
  204.  
  205.   PPCXBlueDialog = ^TPCXBlueDialog;
  206.   TPCXBlueDialog = Object(TPCXDialog)
  207.     function  GetPalette: PPalette; virtual;
  208.   end;
  209.  
  210.   PPCXRedDialog = ^TPCXRedDialog;
  211.   TPCXRedDialog = Object(TPCXDialog)
  212.     function  GetPalette: PPalette; virtual;
  213.   end;
  214.  
  215.   PPCXGrayDialog = ^TPCXGrayDialog;
  216.   TPCXGrayDialog = Object(TPCXDialog)
  217.     function  GetPalette: PPalette; virtual;
  218.   end;
  219.  
  220.   PPCXIndicator = ^TPCXIndicator;
  221.   TPCXIndicator = Object(TIndicator)
  222.     procedure Draw; virtual;
  223.     function  GetPalette: PPalette; virtual;
  224.   end;
  225.  
  226.   PPCXFileEditor = ^TPCXFileEditor;
  227.   TPCXFileEditor = Object(TFileEditor)
  228.     function  GetPalette: PPalette; virtual;
  229.   end;
  230.  
  231.   PPCXEditWindow = ^TPCXEditWindow;
  232.   TPCXEditWindow = Object(TEditWindow)
  233.     constructor Init(var Bounds: TRect; FileName: FNameStr; ANumber: Integer);
  234.     procedure InitFrame; virtual;
  235.     function  GetPalette: PPalette; virtual;
  236.     procedure HandleEvent(var Event: TEvent); virtual;
  237.   private
  238.     ControlBoxWin: PPCXControlBoxWin;
  239.   end;
  240.  
  241.   PPCXEditBlueWindow = ^TPCXEditBlueWindow;
  242.   TPCXEditBlueWindow = Object(TPCXEditWindow)
  243.     function  GetPalette: PPalette; virtual;
  244.   end;
  245.  
  246.   PPCXStaticText = ^TPCXStaticText;
  247.   TPCXStaticText = Object(TStaticText)
  248.      procedure SetText(AText: String); virtual;
  249.   end;
  250.  
  251.   PPCXButton = ^TPCXButton;
  252.   TPCXButton = Object(TButton)
  253.     procedure Draw; virtual;
  254.     procedure DrawView;
  255.     procedure DrawState(Down: Boolean); virtual;
  256.     procedure HandleEvent(var Event: TEvent); virtual;
  257.   private
  258.     procedure DrawCursor;
  259.     procedure ResetCursor; virtual;
  260.   end;
  261.  
  262.   PPCXFrame3D = ^TPCXFrame3D;
  263.   TPCXFrame3D = Object(TView)
  264.     Title    : String;
  265.     Frametype,
  266.     Color    : Byte;
  267.     constructor Init(var Bounds: TRect; ATitle: String; AFrameType, AColor: Byte);
  268.     procedure Draw; virtual;
  269.     function  GetPalette: PPalette; virtual;
  270.   end;
  271.  
  272.   PPCXFileDialog = ^TPCXFileDialog;
  273.   TPCXFileDialog = Object(TFileDialog)
  274.     constructor Init(AWildCard: TWildStr; const ATitle,
  275.       InputName: String; AOptions: Word; HistoryId: Byte);
  276.     function  GetPalette: PPalette; virtual;
  277.     procedure InitFrame; virtual;
  278.   private
  279.     procedure ReadDirectory;
  280.   end;
  281.  
  282.   PPCXCheckBoxes = ^TPCXCheckBoxes;
  283.   TPCXCheckBoxes = Object(TCheckBoxes)
  284.     constructor Init(var Bounds: TRect; AStrings: PSItem; IsRightOn: Boolean);
  285.     procedure DrawMultiBox(const Icon, Marker: String);
  286.     procedure Draw; virtual;
  287.     function  GetPalette: PPalette; virtual;
  288.     procedure Press(Item: Integer); virtual;
  289.   private
  290.     IsRight: Boolean;
  291.     function Column(Item: Integer): Integer;
  292.     function FindSel(P: TPoint): Integer;
  293.     function Row(Item: Integer): Integer;
  294.   end;
  295.  
  296.   PPCXRadioButtons = ^TPCXRadioButtons;
  297.   TPCXRadioButtons = Object(TRadioButtons)
  298.     constructor Init(var Bounds: TRect; AStrings: PSItem; IsRightOn: Boolean);
  299.     procedure DrawMultiBox(const Icon, Marker: String);
  300.     procedure Draw; virtual;
  301.     function  GetPalette: PPalette; virtual;
  302.     procedure Press(Item: Integer); virtual;
  303.   private
  304.     IsRight: Boolean;
  305.     function Column(Item: Integer): Integer;
  306.     function FindSel(P: TPoint): Integer;
  307.     function Row(Item: Integer): Integer;
  308.   end;
  309.  
  310.  
  311. function  PCXMsgBox(const Msg: String; Params: Pointer; AOptions: Word): Word;
  312. function  PCXMsgBoxRect(var R: TRect; const Msg: String; Params: Pointer; AOptions: Word): Word;
  313.  
  314. const
  315.   IsMagyarul : Boolean = False;
  316.   IsIntensity: Boolean = False;
  317.   ShowMouseOn: Boolean = True;
  318.   IsHomokOra : Boolean = False;
  319.   On  = True;
  320.   Off = False;
  321.   Be  = True;
  322.   Ki  = False;
  323.  
  324.   {Bit flags to determine how to draw the frame icons}
  325.   fmCloseClicked = $0001;
  326.   fmZoomClicked  = $0002;
  327.  
  328.   {PCXScrollBar}
  329.   sbGraphLike = $0004;
  330.   sbTextLike  = $0008;
  331.  
  332. IMPLEMENTATION
  333. uses App, PCX_Util, MsgBox;
  334.  
  335. const
  336.   FrameEmpty: String[80] =  '                                        '+
  337.                             '                                        ';
  338.   FrameFull : String[80] =  '████████████████████████████████████████'+
  339.                             '████████████████████████████████████████';
  340.   GFrameUp  : String[80] =  '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞'+
  341.                             '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞';
  342.   FrameUp   : String[80] =  '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀'+
  343.                             '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀';
  344.   GFrameDown: String[80] =  '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟'+
  345.                             '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟';
  346.   FrameDown : String[80] =  '████████████████████████████████████████'+
  347.                             '████████████████████████████████████████';
  348.  
  349.   WindowSizer: String[2] = #210#14; {'─┘'}
  350.   ControlBox : String[2] = #209#180;{'[■]'}
  351.   UpWin      : String[2] = #214#11;
  352.   RestoreWin : String[2] = #9#10;
  353.   GFrame3DConers: Array[0..1] of Char = #221#222;
  354.   PasswordChar  : Byte = 42; {'*' = #42}
  355.  
  356. {TPCXPoint}
  357. procedure TPCXPoint.Assign(XA, YA: Integer);
  358. begin
  359.   X:=XA; Y:=YA;
  360. end;
  361.  
  362. {TPCXMenuBox}
  363. procedure TPCXMenuBox.Draw;
  364. var
  365.   CNormal, CSelect, CNormDisabled, CSelDisabled, Color: Word;
  366.   Y: Integer;
  367.   P: PMenuItem;
  368.   B: TDrawBuffer;
  369.  
  370. procedure FrameLine(N: Integer);
  371. const
  372.      FrameChars: Array[0..19] of Char = ' ┌─┐  └─┘  │ │  ├─┤ ';
  373.   PCXFrameChars: Array[0..19] of Char =
  374.     GFrameCornerLU+GFrameSummitU+GFrameSummitU+GFrameSummitU+GFrameCornerRU+
  375.     GFrameCornerLD+GFrameSummitD+GFrameSummitD+GFrameSummitD+GFrameCornerRD+
  376.     GFrameEdgeL+#32#32#32+GFrameEdgeR+
  377.     GFrameEdgeL+#32#196#32+GFrameEdgeR; {'┴╞╞╞┬├╟╟╟┼╚   ╔╚ ─ ╔'}
  378. begin
  379.   if IsPCXGraphCharsOn
  380.   then begin
  381.          MoveBuf(B[0], PCXFrameChars[N], Byte(CNormal), 2);
  382.          MoveChar(B[2], PCXFrameChars[N + 2], Byte(Color), Size.X - 4);
  383.          MoveBuf(B[Size.X - 2], PCXFrameChars[N + 3], Byte(CNormal), 2);
  384.        end
  385.   else begin
  386.          MoveBuf(B[0], FrameChars[N], Byte(CNormal), 2);
  387.          MoveChar(B[2], FrameChars[N + 2], Byte(Color), Size.X - 4);
  388.          MoveBuf(B[Size.X - 2], FrameChars[N + 3], Byte(CNormal), 2);
  389.        end;
  390. end;
  391.  
  392. procedure DrawLine;
  393. begin
  394.   WriteBuf(0, Y, Size.X, 1, B);
  395.   Inc(Y);
  396. end;
  397.  
  398. begin
  399.   CNormal := GetColor($0301);
  400.   CSelect := GetColor($0604);
  401.   CNormDisabled := GetColor($0202);
  402.   CSelDisabled := GetColor($0505);
  403.   Y := 0;
  404.   Color := CNormal;
  405.   FrameLine(0);
  406.   DrawLine;
  407.   if Menu <> nil then
  408.   begin
  409.     P := Menu^.Items;
  410.     while P <> nil do
  411.     begin
  412.       Color := CNormal;
  413.       if P^.Name = nil then FrameLine(15) else
  414.       begin
  415.         if P^.Disabled then
  416.           if P = Current then
  417.             Color := CSelDisabled else
  418.             Color := CNormDisabled else
  419.           if P = Current then Color := CSelect;
  420.         FrameLine(10);
  421.         MoveCStr(B[3], P^.Name^, Color);
  422.         if P^.Command = 0 then
  423.           MoveChar(B[Size.X - 4], #16, Byte(Color), 1) else
  424.           if P^.Param <> nil then
  425.             MoveStr(B[Size.X - 3 - Length(P^.Param^)],
  426.               P^.Param^, Byte(Color));
  427.       end;
  428.       DrawLine;
  429.       P := P^.Next;
  430.     end;
  431.   end;
  432.   Color := CNormal;
  433.   FrameLine(5);
  434.   DrawLine;
  435.   Message(Application, evCommand, cmMouseChanged, @Self);
  436. end;
  437.  
  438. {TPCXControlBox}
  439. constructor TPCXControlBox.Init(P: TPCXPoint);
  440. var
  441.   R    : TRect;
  442.   TempS: String;
  443. begin
  444.   ControlMenuBox:=nil;
  445.   R.A.X:=P.X; R.A.Y:=P.Y;
  446.               R.B.Y:=R.A.Y+1;
  447.   if IsPCXGraphCharsOn
  448.   then begin
  449.          R.B.X:=2;
  450.          TempS:=ControlBox;
  451.         end
  452.   else begin
  453.          R.B.X:=3;
  454.          TempS:='[■]';
  455.        end;
  456.   Inherited Init(R, TempS);
  457. end;
  458.  
  459. procedure TPCXControlBox.HandleEvent(var Event: TEvent);
  460. begin
  461.   ExecControlMenuBox;
  462.   Inherited HandleEvent(Event);
  463. end;
  464.  
  465. procedure TPCXControlBox.ExecControlMenuBox;
  466. begin
  467.   Abstract;
  468. end;
  469.  
  470. procedure TPCXControlBoxApp.ExecControlMenuBox;
  471. var
  472.   R    : TRect;
  473.   O    : TPCXPoint;
  474.   C    : Word;
  475.   Event: TEvent;
  476. begin
  477.   O.Assign(0,0);
  478.   MakeGlobal(O, O);
  479.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  480.   if IsMagyarul then
  481.   begin
  482.     Inc(R.A.X, 2);
  483.     Inc(R.B.X, 2);
  484.   end;
  485.   if Not IsMagyarul then
  486.   New(ControlMenuBox, Init(R, NewMenu(
  487.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  488.     NewItem('~Q~uit', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  489.     NewLine(
  490.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  491.     nil))           else
  492.   New(ControlMenuBox, Init(R, NewMenu(
  493.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  494.     NewItem('~K~ilépés', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  495.     NewLine(
  496.     NewItem('~F~rissítés', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  497.     nil));
  498.   C:=Application^.ExecView(ControlMenuBox);
  499.   if C<>cmCancel then
  500.   begin
  501.     case C of cmMove:
  502.               begin
  503.                 {Application^.GetEvent(Event);
  504.                 Event.What:=evKeyboard;
  505.                 Application^.PutEvent(Event);}
  506.                 KeyStrokeToKeyboardBuffer(0, $62);
  507.                 Message(Application, evCommand, cmMouseChanged, @Self);
  508.               end;
  509.               cmRefresh: Application^.ReDraw;
  510.               cmQuit:  {if AreYouSureToQuit then} Message(Application, evCommand, cmQuit, @Self);
  511.     {javit!}
  512.  
  513.  
  514.     end;
  515.   end;
  516. end;
  517.  
  518. function  TPCXControlBoxApp.GetPalette: PPalette;
  519. const P: String[Length(CPCXControlBoxApp)] = CPCXControlBoxApp;
  520. begin
  521.   GetPalette:=@P;
  522. end;
  523.  
  524. procedure TPCXControlBoxDlg.ExecControlMenuBox;
  525. var
  526.   R    : TRect;
  527.   O    : TPCXPoint;
  528.   C    : Word;
  529.   Event: TEvent;
  530. begin
  531.   O.Assign(1,0);
  532.   MakeGlobal(O, O);
  533.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  534.   if IsMagyarul then
  535.   begin
  536.     Inc(R.A.X);
  537.     Inc(R.B.X);
  538.   end;
  539.   if IsMagyarul then
  540.   New(ControlMenuBox, Init(R, NewMenu(
  541.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  542.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  543.     NewLine(
  544.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  545.     nil))           else
  546.   New(ControlMenuBox, Init(R, NewMenu(
  547.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  548.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  549.     NewLine(
  550.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  551.     nil));
  552.   C:=Application^.ExecView(ControlMenuBox);
  553.   Owner^.EnableCommands([cmClose]);
  554.   EnableCommands([cmClose]);
  555.   if C<>cmCancel then
  556.   begin
  557.     case C of cmMove:
  558.               begin
  559.                 {Application^.GetEvent(Event);
  560.                 Event.What:=evKeyboard;
  561.                 Application^.PutEvent(Event);}
  562.                 KeyStrokeToKeyboardBuffer(0, $62);
  563.                 Message(Application, evCommand, cmMouseChanged, @Self);
  564.               end;
  565.               cmRefresh: Application^.ReDraw;
  566.               cmClose:   begin
  567.                            KeyStrokeToKeyboardBuffer(0, $6A);
  568.                            Message(Application, evBroadcast, cmClose, @Self);
  569.                            Message(Application, evCommand, cmMouseChanged, @Self);
  570.                          end;
  571.     end;
  572.   end;
  573. end;
  574.  
  575. function  TPCXControlBoxDlg.GetPalette: PPalette;
  576. const P: String[Length(CPCXControlBoxDlg)] = CPCXControlBoxDlg;
  577. begin
  578.   GetPalette:=@P;
  579. end;
  580.  
  581. procedure TPCXControlBoxWin.ExecControlMenuBox;
  582. var
  583.   R    : TRect;
  584.   O    : TPCXPoint;
  585.   C    : Word;
  586. begin
  587.   O.Assign(1,0);
  588.   MakeGlobal(O, O);
  589.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  590.   Owner^.EnableCommands([cmClose]);
  591.   EnableCommands([cmClose]);
  592.   if IsMagyarul then
  593.   begin
  594.     Inc(R.A.X);
  595.     Inc(R.B.X);
  596.   end;
  597.   if IsMagyarul then
  598.   New(ControlMenuBox, Init(R, NewMenu(
  599.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  600.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  601.     NewLine(
  602.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  603.     nil))           else
  604.   New(ControlMenuBox, Init(R, NewMenu(
  605.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  606.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  607.     NewLine(
  608.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  609.     nil));
  610.   C:=Application^.ExecView(ControlMenuBox);
  611.   if C<>cmCancel then
  612.   begin
  613.     case C of cmMove:
  614.               begin
  615.                  KeyStrokeToKeyboardBuffer(0, $62);
  616.                  Message(Application, evCommand, cmMouseChanged, @Self);
  617.               end;
  618.               cmRefresh: Application^.ReDraw;
  619.               cmClose:
  620.               begin
  621.                  KeyStrokeToKeyboardBuffer(0, $6A);
  622.                  Message(Application, evCommand, cmMouseChanged, @Self);
  623.               end;
  624.  
  625.     end;
  626.   end;
  627. end;
  628.  
  629. function  TPCXControlBoxWin.GetPalette: PPalette;
  630. const P: String[Length(CPCXControlBoxWin)] = CPCXControlBoxWin;
  631. begin
  632.   GetPalette:=@P;
  633. end;
  634.  
  635. {TPCXMenuBar}
  636. function TPCXMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  637.   AParentMenu: PMenuView): PMenuView;
  638. begin
  639.   NewSubView := New(PPCXMenuBox, Init(Bounds, AMenu, AParentMenu));
  640. end;
  641.  
  642. {TPCXScrollBar}
  643. constructor TPCXScrollBar.Init(var Bounds: TRect);
  644. const
  645.   {                           felb  felj   leb   lej  }
  646.   GVChars: TPCXScrollChars = (#212, #183, #213, #184, GFrameEdgeL, GFrameEdgeR);
  647.                               {╘    ╖     ╒     ╕}
  648.   GHChars: TPCXScrollChars = (#217, #21, #218, #185, #215, #215);
  649.                               {┘        ┌     ╣     ╫     ╫}
  650.   VChars : TPCXScrollChars = (#30, #31, #177, #254, #178, #32); {Text, it's  }
  651.   HChars : TPCXScrollChars = (#17, #16, #177, #254, #178, #32); {the original}
  652. begin
  653.   TView.Init(Bounds);
  654.   if IsPCXGraphCharsOn then TempB:=2
  655.                        else TempB:=1;
  656.   Value := 0;
  657.   Min := 0;
  658.   Max := 0;
  659.   PgStep := 1;
  660.   ArStep := 1;
  661.   if Size.X = TempB then
  662.   begin
  663.     GrowMode := gfGrowLoX + gfGrowHiX + gfGrowHiY;
  664.     if IsPCXGraphCharsOn then Chars := GVChars
  665.                          else Chars := VChars;
  666.     IsHorizontal:=False;
  667.   end else
  668.   begin
  669.     GrowMode := gfGrowLoY+ gfGrowHiX + gfGrowHiY;
  670.     if IsPCXGraphCharsOn then Chars := GHChars
  671.                          else Chars := HChars;
  672.     IsHorizontal:=True;
  673.   end;
  674. end;
  675.  
  676. procedure TPCXScrollBar.Draw;
  677. begin
  678.   DrawPos(GetPos);
  679.   Message(Application, evCommand, cmMouseChanged, @Self);
  680.  
  681.   { Include it to evIdle in HandleEvent for make realtime show|hide scrollbars
  682.   if HScrollBar <> nil then
  683.    if HScrollBar^.Min = HScrollBar^.Max 
  684.    then HScrollBar^.Hide
  685.    else HScrollBar^.Show;
  686.   }
  687. end;
  688.  
  689. procedure TPCXScrollBar.DrawPos(Pos: Integer);
  690. var
  691.   S: Integer;
  692.   B: TDrawBuffer;
  693.   i: Word;
  694. begin
  695.   if IsPCXGraphCharsOn then
  696.   begin
  697.     if Not IsHorizontal then
  698.     begin
  699.       S := GetSize - 1;
  700.       MoveCStr(B[0], Chars[0], GetColor(2));
  701.       MoveCStr(B[1], Chars[1], SwapHighAndLowAreaOfByte(GetColor(2)));
  702.       if Max = Min then
  703.       begin
  704.         i:=0;
  705.         while i<(S*2)-1 do
  706.         begin
  707.           Inc(I,2);
  708.           MoveCStr(B[i], ''+Chars[4]+Chars[5]+'', GetColor(1));
  709.         end;
  710.       end
  711.       else
  712.       begin
  713.           i:=0;
  714.           while i<(S*2)-1 do
  715.           begin
  716.             Inc(i,2);
  717.             MoveCStr(B[i], ''+Chars[4]+Chars[5]+'', GetColor(3));
  718.             MoveCStr(B[Pos*2], ''+Chars[4]+Chars[5]+'', GetColor(4));
  719.           end;
  720.       end;
  721.       MoveCStr(B[S*2], Chars[2], GetColor(2));
  722.       MoveCStr(B[(S*2)+1], Chars[3], SwapHighAndLowAreaOfByte(GetColor(2)));
  723.       WriteBuf(0, 0, Size.X, Size.Y, B);      
  724.     end
  725.     else
  726.     begin
  727.       S := GetSize - 1;
  728.       if Pos=1 then Inc(Pos);
  729.       if Pos+1=S then Pos:=S-3;
  730.       MoveCStr(B[0], Chars[0], GetColor(2));
  731.       MoveCStr(B[1], Chars[1], SwapHighAndLowAreaOfByte(GetColor(2)));
  732.       if Max = Min then
  733.         MoveChar(B[2], Chars[4], GetColor(1), S - 2)
  734.       else
  735.       begin
  736.         MoveChar(B[2], Chars[4], GetColor(3), S - 2);
  737.         MoveCStr(B[Pos], Chars[5]+Chars[5], GetColor(4));
  738.       end;
  739.       MoveCStr(B[S-1], Chars[2], GetColor(2));
  740.       MoveCStr(B[S], Chars[3], SwapHighAndLowAreaOfByte(GetColor(2)));
  741.       WriteBuf(0, 0, Size.X, Size.Y, B);
  742.     end;
  743.   end
  744.   else
  745.   begin
  746.     S := GetSize - 1;
  747.     MoveChar(B[0], Chars[0], GetColor(2), 1);
  748.     if Max = Min then
  749.       MoveChar(B[1], Chars[4], GetColor(1), S - 1)
  750.     else
  751.     begin
  752.       MoveChar(B[1], Chars[2], GetColor(1), S - 1);
  753.       MoveChar(B[Pos], Chars[3], GetColor(3), 1);
  754.     end;
  755.     MoveChar(B[S], Chars[1], GetColor(2), 1);
  756.     WriteBuf(0, 0, Size.X, Size.Y, B);
  757.   end;
  758.   Message(Application, evCommand, cmMouseChanged, @Self);
  759. end;
  760.  
  761. procedure TPCXScrollBar.HandleEvent(var Event: TEvent);
  762. var
  763.   Tracking : Boolean;
  764.   I, P,
  765.   S,
  766.   ClickPart: Integer;
  767.   Mouse    : TPoint;
  768.   Extent   : TRect;
  769. function GetPartCode: Integer;
  770. var
  771.   Mark, Part: Integer;
  772. begin
  773.   Part := -1;
  774.   if Extent.Contains(Mouse) then
  775.   begin
  776.     if Size.X = TempB then Mark := Mouse.Y else Mark := Mouse.X;
  777.     if Mark = P then Part := sbIndicator else
  778.     begin
  779.       if Mark < TempB then Part := sbLeftArrow else
  780.         if Mark < P then Part := sbPageLeft else
  781.           if Mark < S then Part := sbPageRight else
  782.             Part := sbRightArrow;
  783.       if Size.X = TempB then Inc(Part, 4);
  784.     end;
  785.   end;
  786.   GetPartCode := Part;
  787. end;
  788.  
  789. procedure Clicked;
  790. begin
  791.   Message(Owner, evCommand, cmViewChanged, @Self);
  792. end;
  793.  
  794. begin
  795.   TView.HandleEvent(Event);
  796.   case Event.What of
  797.     evMouseDown:
  798.       begin
  799.         Clicked;
  800.         MakeLocal(Event.Where, Mouse);
  801.         GetExtent(Extent);
  802.         Extent.Grow(1, 1);
  803.         P := GetPos;
  804.         S := GetSize - 1;
  805.         ClickPart := GetPartCode;
  806.         if ClickPart <> sbIndicator then
  807.         begin
  808.           repeat
  809.             MakeLocal(Event.Where, Mouse);
  810.             if GetPartCode = ClickPart then
  811.               SetValue(Value + ScrollStep(ClickPart));
  812.           until not MouseEvent(Event, evMouseAuto);
  813.         end else
  814.         begin
  815.           repeat
  816.             MakeLocal(Event.Where, Mouse);
  817.             Tracking := Extent.Contains(Mouse);
  818.             if Tracking then
  819.             begin
  820.               if Size.X = TempB then I := Mouse.Y else I := Mouse.X;
  821.               if I <= 0 then I := 1;
  822.               if I >= S then I := S - 1;
  823.             end else I := GetPos;
  824.             if I <> P then
  825.             begin
  826.               DrawPos(I);
  827.               P := I;
  828.             end;
  829.           until not MouseEvent(Event, evMouseMove);
  830.           if Tracking and (S > 2) then
  831.           begin
  832.             Dec(S, 2);
  833.             SetValue(LongDiv(LongMul(P - 1, Max - Min) + S shr 1, S) + Min);
  834.           end;
  835.         end;
  836.         ClearEvent(Event);
  837.       end;
  838.     evKeyDown:
  839.       if State and sfVisible <> 0 then
  840.       begin
  841.         ClickPart := sbIndicator;
  842.         if Size.Y = 1 then
  843.           case CtrlToArrow(Event.KeyCode) of
  844.             kbLeft: ClickPart := sbLeftArrow;
  845.             kbRight: ClickPart := sbRightArrow;
  846.             kbCtrlLeft: ClickPart := sbPageLeft;
  847.             kbCtrlRight: ClickPart := sbPageRight;
  848.             kbHome: I := Min;
  849.             kbEnd: I := Max;
  850.           else
  851.             Exit;
  852.           end
  853.         else
  854.           case CtrlToArrow(Event.KeyCode) of
  855.             kbUp: ClickPart := sbUpArrow;
  856.             kbDown: ClickPart := sbDownArrow;
  857.             kbPgUp: ClickPart := sbPageUp;
  858.             kbPgDn: ClickPart := sbPageDown;
  859.             kbCtrlPgUp: I := Min;
  860.             kbCtrlPgDn: I := Max;
  861.           else
  862.             Exit;
  863.           end;
  864.         Clicked;
  865.         if ClickPart <> sbIndicator then I := Value + ScrollStep(ClickPart);
  866.         SetValue(I);
  867.         ClearEvent(Event);
  868.       end;
  869.   end;
  870. end;
  871.  
  872. function TPCXScrollBar.GetPalette: PPalette;
  873. const P: String[Length(CPCXScrollBar)] = CPCXScrollBar;
  874. begin
  875.   GetPalette:=@P;
  876. end;
  877.  
  878. function TPCXScrollBar.GetPos: Integer;
  879. var
  880.   R: Integer;
  881. begin
  882.   R := Max - Min;
  883.   if R = 0 then
  884.     GetPos := 1 else
  885.     GetPos := LongDiv(LongMul(Value - Min, GetSize - 3) + R shr 1, R) + 1;
  886. end;
  887.  
  888. function TPCXScrollBar.GetSize: Integer;
  889. var
  890.   S: Integer;
  891. begin
  892.   if Size.X = TempB then S := Size.Y else S := Size.X;
  893.   if S < 2+TempB then GetSize := 2+TempB else GetSize := S;
  894. end;
  895.  
  896. {TPCXFrame}
  897. procedure TPCXFrame.Draw;
  898. var
  899.   CFrame, CTitle: Word;
  900.   F, I, L, Width: Integer;
  901.   B: TDrawBuffer;
  902.   Title: TTitleStr;
  903.   Min, Max: TPoint;
  904. begin
  905.   if State and sfDragging <> 0 then
  906.   begin
  907.     CFrame := $0706;
  908.     CTitle := $0007;
  909.     F := 0;
  910.   end else if State and sfActive = 0 then
  911.   begin
  912.     CFrame := $0101;
  913.     CTitle := $0002;
  914.     F := 0;
  915.   end else
  916.   begin
  917.     CFrame := $0503;
  918.     CTitle := $0004;
  919.     F := 9;
  920.   end;
  921.   CFrame := GetColor(CFrame);
  922.   CTitle := GetColor(CTitle);
  923.   Width := Size.X;
  924.   L := Width - 10;
  925.   if PWindow(Owner)^.Flags and (wfClose+wfZoom) <> 0 then Dec(L,6);
  926.   if IsPCXGraphCharsOn then MoveCStr(B, Copy(FrameEmpty, 1, Size.X), CTitle)
  927.                        else MoveCStr(B, Copy(FrameEmpty, 1, Size.X), CTitle);
  928.   if (PWindow(Owner)^.Number <> wnNoNumber) and
  929.      (PWindow(Owner)^.Number < 10) then
  930.   begin
  931.     Dec(L,4);
  932.     if PWindow(Owner)^.Flags and wfZoom <> 0 then I := 7
  933.     else I := 3;
  934.     WordRec(B[Width - I]).Lo := PWindow(Owner)^.Number + $30;
  935.   end;
  936.   if Owner <> nil then Title := PWindow(Owner)^.GetTitle(L)
  937.   else Title := '';
  938.   if Title <> '' then
  939.   begin
  940.     L := Length(Title);
  941.     if L > Width - 10 then L := Width - 10;
  942.     if L < 0 then L := 0;
  943.     I := (Width - L) shr 1;
  944.     MoveChar(B[I - 1], ' ', CTitle, 1);
  945.     MoveBuf(B[I], Title[1], CTitle, L);
  946.     MoveChar(B[I + L], ' ', CTitle, 1);
  947.   end;
  948.   if State and sfActive <> 0 then
  949.   begin
  950.     if PWindow(Owner)^.Flags and wfClose <> 0 then
  951.       if FrameMode and fmCloseClicked = 0 then
  952.         if IsPCXGraphCharsOn then MoveCStr(B[0], '~'+ControlBox+'~', CFrame) {#209#180}
  953.                              else MoveCStr(B[1], '', CFrame) {~[■]~}
  954.       else MoveCStr(B[2], '[~'#15'~]', CFrame);
  955.     if PWindow(Owner)^.Flags and wfZoom <> 0 then
  956.     begin
  957.       if IsPCXGraphCharsOn then MoveCStr(B[Width - 4], '~'+UpWin+'~', CFrame)
  958.                            else MoveCStr(B[Width - 4], '~['#24']~', CFrame);
  959.       Owner^.SizeLimits(Min, Max);
  960.       if FrameMode and fmZoomClicked <> 0 then
  961.         WordRec(B[Width - 4]).Lo := 15
  962.       else if Longint(Owner^.Size) = Longint(Max) then
  963.       begin
  964.         if IsPCXGraphCharsOn then MoveCStr(B[Width - 4], '~'+RestoreWin+'~', CFrame)
  965.                              else MoveCStr(B[Width - 4], '~['#18']~', CFrame);
  966.       end;
  967.     end;
  968.   end;
  969.   WriteLine(0, 0, Size.X, 1, B);
  970.   for I := 1 to Size.Y - 2 do
  971.   begin
  972.     if IsPCXGraphCharsOn then MoveCStr(B, GFrameEdgeL+Copy(FrameEmpty, 1, Size.X-2)+GFrameEdgeR, CFrame)
  973.                          else MoveCStr(B, #221+Copy(FrameEmpty, 1, Size.X-2)+#222, CFrame);
  974.     WriteLine(0, I, Size.X, 1, B);
  975.   end;
  976.   if IsPCXGraphCharsOn then MoveCStr(B, GFrameCornerLD+Copy(GFrameDown, 1, Size.X-2)+GFrameCornerRD, CFrame)
  977.                        else MoveCStr(B, {#221+} Copy(FrameDown{FrameFull}, 1, Size.X) {+#222}, CFrame);
  978.   if State and sfActive <> 0 then
  979.     if PWindow(Owner)^.Flags and wfGrow <> 0 then
  980.       if IsPCXGraphCharsOn then MoveCStr(B[Width - 2], WindowSizer, CFrame) {#210#211}
  981.                            else MoveCStr(B[Width - 2], '~─┘~', CFrame);
  982.   WriteLine(0, Size.Y - 1, Size.X, 1, B);
  983.   Message(Application, evCommand, cmMouseChanged, @Self);
  984.   Message(Application, evCommand, cmPCXFrameChanged, @Self);
  985.   Message(Application, evBroadcast, cmPCXFrameChanged, @Self);
  986. end;
  987.  
  988. function  TPCXFrame.GetPalette: PPalette;
  989. const P: String[Length(CPCXFrame)] = CPCXFrame;
  990. begin
  991.   GetPalette:=@P;
  992. end;
  993.  
  994. {TPCXWindow}
  995. constructor TPCXWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  996. var P: TPCXPoint;
  997. begin
  998.   Inherited Init(Bounds, ATitle, ANumber);
  999.   P.Assign(0, 0);
  1000.   New(ControlBoxWin, Init(P));
  1001.   Insert(ControlBoxWin);
  1002. end;
  1003.  
  1004. procedure TPCXWindow.InitFrame;
  1005. var R: TRect;
  1006. begin
  1007.   GetExtent(R);
  1008.   Frame := New(PPCXFrame, Init(R));
  1009. end;
  1010.  
  1011. procedure TPCXWindow.Draw;
  1012. begin
  1013.   Inherited Draw;
  1014.   Message(Application, evCommand, cmMouseChanged, @Self);  
  1015. end;
  1016.  
  1017. function  TPCXWindow.GetPalette: PPalette;
  1018. const P: String[Length(CPCXWindow)] = CPCXWindow;
  1019. begin
  1020.   GetPalette:=@P;
  1021. end;
  1022.  
  1023. procedure TPCXWindow.HandleEvent(var Event: TEvent);
  1024. begin
  1025.   if Event.KeyCode=kbAltSpace then
  1026.   begin
  1027.     ControlBoxWin^.ExecControlMenuBox;
  1028.     Event.KeyCode:=Event.KeyCode and Not kbAltSpace;
  1029.   end;
  1030.   Inherited HandleEvent(Event);
  1031. end;
  1032.  
  1033. function TPCXWindow.StandardScrollBar(AOptions: Word): PPCXScrollBar;
  1034. var
  1035.   R: TRect;
  1036.   S: PPCXScrollBar;
  1037. begin
  1038.   GetExtent(R);
  1039.   if AOptions and sbGraphLike = 0
  1040.   then if AOptions and sbVertical = 0 
  1041.        then R.Assign(R.A.X + 2, R.B.Y-1, R.B.X-2, R.B.Y) 
  1042.        else R.Assign(R.B.X-1,R.A.Y+1,R.B.X,R.B.Y-1)
  1043.   else if AOptions and sbVertical = 0 
  1044.        then R.Assign(R.A.X + 2, R.B.Y-1, R.B.X-2, R.B.Y) 
  1045.        else R.Assign(R.B.X-2,R.A.Y+1,R.B.X,R.B.Y-1);
  1046.   S := New(PPCXScrollBar, Init(R));
  1047.   Insert(S);
  1048.   if AOptions and sbHandleKeyboard <> 0 
  1049.   then S^.Options := S^.Options or ofPostProcess;
  1050.   StandardScrollBar := S;
  1051. end;
  1052.  
  1053. {TPCXXXXXWindows}
  1054. function  TPCXBlueWindow.GetPalette: PPalette;
  1055. const P: String[Length(CPCXBlueWindow)] = CPCXBlueWindow;
  1056. begin
  1057.   GetPalette:=@P;
  1058. end;
  1059.  
  1060. function  TPCXRedWindow.GetPalette: PPalette;
  1061. const P: String[Length(CPCXRedWindow)] = CPCXRedWindow;
  1062. begin
  1063.   GetPalette:=@P;
  1064. end;
  1065.  
  1066. function  TPCXGrayWindow.GetPalette: PPalette;
  1067. const P: String[Length(CPCXGrayWindow)] = CPCXGrayWindow;
  1068. begin
  1069.   GetPalette:=@P;
  1070. end;
  1071.  
  1072. {TPCXDialog}
  1073. constructor TPCXDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  1074. var P: TPCXPoint;
  1075. begin
  1076.   Inherited Init(Bounds, ATitle);
  1077.   P.Assign(0,0);
  1078.   New(ControlBoxDlg, Init(P));
  1079.   Insert(ControlBoxDlg);
  1080. end;
  1081.  
  1082. procedure TPCXDialog.InitFrame;
  1083. var
  1084.   R: TRect;
  1085. begin
  1086.   GetExtent(R);
  1087.   Frame := New(PPCXFrame, Init(R));
  1088. end;
  1089.  
  1090. procedure TPCXDialog.Draw;
  1091. begin
  1092.   Inherited Draw;
  1093.   Message(Application, evCommand, cmMouseChanged, @Self);  
  1094. end;
  1095.  
  1096. function  TPCXDialog.GetPalette: PPalette;
  1097. const P: String[Length(CPCXDialog)] = CPCXDialog;
  1098. begin
  1099.   GetPalette:=@P;
  1100. end;
  1101.  
  1102. procedure TPCXDialog.HandleEvent(var Event: TEvent);
  1103. begin
  1104.   if Event.KeyCode=kbAltSpace then
  1105.   begin
  1106.     ControlBoxDlg^.ExecControlMenuBox;
  1107.     Event.KeyCode:=Event.KeyCode and Not kbAltSpace;
  1108.   end;
  1109.   Inherited HandleEvent(Event);
  1110. end;
  1111.  
  1112. function  TPCXBlueDialog.GetPalette: PPalette;
  1113. const P: String[Length(CPCXBlueDialog)] = CPCXBlueDialog;
  1114. begin
  1115.   GetPalette:=@P;
  1116. end;
  1117.  
  1118. function  TPCXRedDialog.GetPalette: PPalette;
  1119. const P: String[Length(CPCXRedDialog)] = CPCXRedDialog;
  1120. begin
  1121.   GetPalette:=@P;
  1122. end;
  1123.  
  1124. function  TPCXGrayDialog.GetPalette: PPalette;
  1125. const P: String[Length(CPCXGrayDialog)] = CPCXGrayDialog;
  1126. begin
  1127.   GetPalette:=@P;
  1128. end;
  1129.  
  1130. {TPCXIndicator}
  1131. procedure TPCXIndicator.Draw;
  1132. var
  1133.   Color, Color2: Byte;
  1134.   Frame: Char;
  1135.   L: Array[0..1] of Longint;
  1136.   S: String[15];
  1137.   B: TDrawBuffer;
  1138. begin
  1139.   if State and sfDragging = 0 then
  1140.   begin
  1141.     Color := GetColor(1);
  1142.     Color2:= GetColor(3);
  1143.     if IsPCXGraphCharsOn
  1144.     then Frame := GFrameSummitD
  1145.     else Frame := #219;
  1146.   end else
  1147.   begin
  1148.     Color := GetColor(2);
  1149.     Color2:= SwapHighAndLowAreaOfByte(GetColor(4));
  1150.     if IsPCXGraphCharsOn
  1151.     then Frame := GFrameSummitD
  1152.     else Frame := #219;
  1153.   end;
  1154.   MoveChar(B, Frame, Color, Size.X);
  1155.   if Modified
  1156.   then if IsPCXGraphCharsOn
  1157.        then WordRec(B[0]).Lo := 210
  1158.        else WordRec(B[0]).Lo := 220;
  1159.   L[0] := Location.Y + 1;
  1160.   L[1] := Location.X + 1;
  1161.   FormatStr(S, ' %d:%d ', L);
  1162.   MoveStr(B[8 - Pos(':', S)], S, Color2);
  1163.   WriteBuf(0, 0, Size.X, 1, B);
  1164.   Message(Application, evCommand, cmMouseChanged, @Self);
  1165. end;
  1166.  
  1167. function  TPCXIndicator.GetPalette: PPalette;
  1168. const P: String[Length(CPCXIndicator)] = CPCXIndicator;
  1169. begin
  1170.   GetPalette:=@P;
  1171. end;
  1172.  
  1173. {TPCXFileEditor}
  1174. function  TPCXFileEditor.GetPalette: PPalette;
  1175. const P: String[Length(CPCXFileEditor)] = CPCXFileEditor;
  1176. begin
  1177.   GetPalette:=@P;
  1178. end;
  1179.  
  1180. {TPCXEditWindow}
  1181. constructor TPCXEditWindow.Init(var Bounds: TRect; FileName: FNameStr; ANumber: Integer);
  1182. var
  1183.   P: TPCXPoint;
  1184.   HScrollBar, VScrollBar: PPCXScrollBar;
  1185.   Indicator: PPCXIndicator;
  1186.   R: TRect;
  1187. begin
  1188.   Inherited Init(Bounds, '', ANumber);
  1189.   Options := Options or ofTileable;
  1190.   R.Assign(18, Size.Y - 1, Size.X - 2, Size.Y);
  1191.   HScrollBar := New(PPCXScrollBar, Init(R));
  1192.   HScrollBar^.Hide;
  1193.   Insert(HScrollBar);
  1194.   if IsPCXGraphCharsOn
  1195.   then R.Assign(Size.X - 2, 1, Size.X, Size.Y - 1)
  1196.   else R.Assign(Size.X - 1, 1, Size.X, Size.Y - 1);
  1197.   VScrollBar := New(PPCXScrollBar, Init(R));
  1198.   VScrollBar^.Hide;
  1199.   Insert(VScrollBar);
  1200.   R.Assign(2, Size.Y - 1, 16, Size.Y);
  1201.   Indicator := New(PPCXIndicator, Init(R));
  1202.   Indicator^.Hide;
  1203.   Insert(Indicator);
  1204.   GetExtent(R);
  1205.   R.Grow(-2, -1);
  1206.   Editor := New(PPCXFileEditor, Init(R, HScrollBar, VScrollBar, Indicator, FileName));
  1207.   Insert(Editor);
  1208.  
  1209.   P.Assign(0,0);
  1210.   New(ControlBoxWin, Init(P));
  1211.   Insert(ControlBoxWin);
  1212. end;
  1213.  
  1214. procedure TPCXEditWindow.InitFrame;
  1215. var
  1216.   R: TRect;
  1217. begin
  1218.   GetExtent(R);
  1219.   Frame := New(PPCXFrame, Init(R));
  1220. end;
  1221.  
  1222. function  TPCXEditWindow.GetPalette: PPalette;
  1223. const P: String[Length(CPCXWindow)] = CPCXWindow;
  1224. begin
  1225.   GetPalette:=@P;
  1226. end;
  1227.  
  1228. procedure TPCXEditWindow.HandleEvent(var Event: TEvent);
  1229. begin
  1230.   if Event.KeyCode=kbAltSpace then ControlBoxWin^.ExecControlMenuBox;
  1231.   Inherited HandleEvent(Event);
  1232.   if Event.Command = cmNewLine then
  1233.   begin
  1234.     Event.KeyCode:=Event.KeyCode and (Not kbAltSpace);
  1235.     Event.Command:= Event.Command and (Not cmNewLine);
  1236.   end;
  1237. end;
  1238.  
  1239. function  TPCXEditBlueWindow.GetPalette: PPalette;
  1240. const P: String[Length(CPCXBlueWindow)] = CPCXBlueWindow;
  1241. begin
  1242.   GetPalette:=@P;
  1243. end;
  1244.  
  1245. {TPCXStaticText}
  1246. procedure TPCXStaticText.SetText(AText: String);
  1247. begin
  1248.   if Text<>nil then DisposeStr(Text);   {Idea: By Bérczi Gábor, Power INC.}
  1249.   if AText<>'' then Text:=NewStr(AText) {      TOO . . .                  }
  1250.                else Text:=Nil;          {      TOO . . .                  }
  1251.   Draw;
  1252.   Message(Application, evCommand, cmMouseChanged, @Self);
  1253. end;
  1254.  
  1255. {TPCXButton}
  1256. procedure TPCXButton.Draw;
  1257. begin
  1258.   DrawState(False);
  1259.   Message(Application, evCommand, cmMouseChanged, @Self);
  1260. end;
  1261.  
  1262. procedure TPCXButton.DrawState(Down: Boolean);
  1263. var
  1264.   CButton, CShadow: Word;
  1265.   Ch: Char;
  1266.   I, S, Y, T: Integer;
  1267.   B: TDrawBuffer;
  1268.  
  1269. procedure DrawTitle;
  1270. var
  1271.   L, SCOff: Integer;
  1272. begin
  1273.   if Flags and bfLeftJust <> 0 then L := 1 else
  1274.   begin
  1275.     L := (S - CStrLen(Title^) - 1) div 2;
  1276.     if L < 1 then L := 1;
  1277.   end;
  1278.   MoveCStr(B[I + L], Title^, CButton);
  1279.   if ShowMarkers and not Down then
  1280.   begin
  1281.     if State and sfSelected <> 0 then SCOff := 0 else
  1282.       if AmDefault then SCOff := 2 else SCOff := 4;
  1283.     WordRec(B[0]).Lo := Byte(SpecialChars[SCOff]);
  1284.     WordRec(B[S]).Lo := Byte(SpecialChars[SCOff + 1]);
  1285.   end;
  1286. end;
  1287.  
  1288. begin
  1289.   if State and sfDisabled <> 0 then CButton := GetColor($0404) else
  1290.   begin
  1291.     CButton := GetColor($0501);
  1292.     if State and sfActive <> 0 then
  1293.       if State and sfSelected <> 0 then CButton := GetColor($0703) else
  1294.         if AmDefault then CButton := GetColor($0602);
  1295.   end;
  1296.   CShadow := GetColor(8);
  1297.   S := Size.X - 1;
  1298.   T := Size.Y div 2 - 1;
  1299.   for Y := 0 to Size.Y - 2 do
  1300.   begin
  1301.     MoveChar(B, ' ', Byte(CButton), Size.X);
  1302.     WordRec(B[0]).Hi := CShadow;
  1303.     if Down then
  1304.     begin
  1305.       WordRec(B[1]).Hi := CShadow;
  1306.       Ch := ' ';
  1307.       I := 2;
  1308.     end else
  1309.     begin
  1310.       if ShowMarkers then WordRec(B[S]).Hi := Byte(CShadow)
  1311.                      else WordRec(B[S]).Hi := SwapHighAndLowAreaOfByte(Byte(CShadow)); {from PCX_Util}
  1312.       if ShowMarkers then Ch := ' ' else
  1313.       begin
  1314.         if Y = 0 then
  1315.           WordRec(B[S]).Lo := Byte('▀') else {#223 invert = #220}
  1316.           WordRec(B[S]).Lo := Byte('█');
  1317.         Ch := '▀';
  1318.       end;
  1319.       I := 1;
  1320.     end;
  1321.     if (Y = T) and (Title <> nil) then DrawTitle;
  1322.     if ShowMarkers and not Down then
  1323.     begin
  1324.       WordRec(B[1]).Lo := Byte('[');
  1325.       WordRec(B[S - 1]).Lo := Byte(']');
  1326.     end;
  1327.     WriteLine(0, Y, Size.X, 1, B);
  1328.   end;
  1329.   MoveChar(B[0], ' ', Byte(CShadow), 2);
  1330.   MoveChar(B[2], Ch, Byte(CShadow), S - 1);
  1331.   WriteLine(0, Size.Y - 1, Size.X, 1, B);
  1332. end;
  1333.  
  1334. function HotKey(const S: String): Char;
  1335. var
  1336.   P: Word;
  1337. begin
  1338.   P := Pos('~',S);
  1339.   if P <> 0 then HotKey := UpCase(S[P+1])
  1340.   else HotKey := #0;
  1341. end;
  1342.  
  1343. const
  1344.  
  1345. { TButton messages }
  1346.  
  1347.   cmGrabDefault    = 61;
  1348.   cmReleaseDefault = 62;
  1349.  
  1350. procedure TPCXButton.HandleEvent(var Event: TEvent);
  1351. var
  1352.   Down: Boolean;
  1353.   C: Char;
  1354.   Mouse: TPoint;
  1355.   ClickRect: TRect;
  1356. begin
  1357.   GetExtent(ClickRect);
  1358.   Inc(ClickRect.A.X);
  1359.   Dec(ClickRect.B.X);
  1360.   Dec(ClickRect.B.Y);
  1361.   if Event.What = evMouseDown then
  1362.   begin
  1363.     MakeLocal(Event.Where, Mouse);
  1364.     if not ClickRect.Contains(Mouse) then ClearEvent(Event);
  1365.   end;
  1366.   if Flags and bfGrabFocus <> 0 then
  1367.     TView.HandleEvent(Event);
  1368.   case Event.What of
  1369.     evMouseDown:
  1370.       begin
  1371.         if State and sfDisabled = 0 then
  1372.         begin
  1373.           Inc(ClickRect.B.X);
  1374.           Down := False;
  1375.           repeat
  1376.             MakeLocal(Event.Where, Mouse);
  1377.             if Down <> ClickRect.Contains(Mouse) then
  1378.             begin
  1379.               Down := not Down;
  1380.               DrawState(Down);
  1381.             end;
  1382.           until not MouseEvent(Event, evMouseMove);
  1383.           if Down then
  1384.           begin
  1385.             Press;
  1386.             DrawState(False);
  1387.           end;
  1388.         end;
  1389.         ClearEvent(Event);
  1390.       end;
  1391.     evKeyDown:
  1392.       begin
  1393.         C := HotKey(Title^);
  1394.         if (Event.KeyCode = GetAltCode(C)) or
  1395.           (Owner^.Phase = phPostProcess) and (C <> #0) and
  1396.             (Upcase(Event.CharCode) = C) or
  1397.           (State and sfFocused <> 0) and (Event.CharCode = ' ') then
  1398.         begin
  1399.           Press;
  1400.           ClearEvent(Event);
  1401.         end;
  1402.       end;
  1403.     evBroadcast:
  1404.       case Event.Command of
  1405.         cmDefault:
  1406.           if AmDefault then
  1407.           begin
  1408.             Press;
  1409.             ClearEvent(Event);
  1410.           end;
  1411.         cmGrabDefault, cmReleaseDefault:
  1412.           if Flags and bfDefault <> 0 then
  1413.           begin
  1414.             AmDefault := Event.Command = cmReleaseDefault;
  1415.             DrawView;
  1416.           end;
  1417.         cmCommandSetChanged:
  1418.           begin
  1419.             SetState(sfDisabled, not CommandEnabled(Command));
  1420.             DrawView;
  1421.           end;
  1422.       end;
  1423.   end;
  1424. end;
  1425.  
  1426. procedure TPCXButton.ResetCursor; assembler;
  1427. asm
  1428.         LES     DI,Self
  1429.         MOV     AX,ES:[DI].TPCXButton.State
  1430.         NOT     AX
  1431.         TEST    AX,sfVisible+sfCursorVis+sfFocused
  1432.         JNE     @@4
  1433.         MOV     AX,ES:[DI].TView.Cursor.Y
  1434.         MOV     DX,ES:[DI].TView.Cursor.X
  1435. @@1:    OR      AX,AX
  1436.         JL      @@4
  1437.         CMP     AX,ES:[DI].TPCXButton.Size.Y
  1438.         JGE     @@4
  1439.         OR      DX,DX
  1440.         JL      @@4
  1441.         CMP     DX,ES:[DI].TPCXButton.Size.X
  1442.         JGE     @@4
  1443.         ADD     AX,ES:[DI].TPCXButton.Origin.Y
  1444.         ADD     DX,ES:[DI].TPCXButton.Origin.X
  1445.         MOV     CX,DI
  1446.         MOV     BX,ES
  1447.         LES     DI,ES:[DI].TPCXButton.Owner
  1448.         MOV     SI,ES
  1449.         OR      SI,DI
  1450.         JE      @@5
  1451.         TEST    ES:[DI].TPCXButton.State,sfVisible
  1452.         JE      @@4
  1453.         LES     DI,ES:[DI].TGroup.Last
  1454. @@2:    LES     DI,ES:[DI].TPCXButton.Next
  1455.         CMP     CX,DI
  1456.         JNE     @@3
  1457.         MOV     SI,ES
  1458.         CMP     BX,SI
  1459.         JNE     @@3
  1460.         LES     DI,ES:[DI].TPCXButton.Owner
  1461.         JMP     @@1
  1462. @@3:    TEST    ES:[DI].TPCXButton.State,sfVisible
  1463.         JE      @@2
  1464.         MOV     SI,ES:[DI].TPCXButton.Origin.Y
  1465.         CMP     AX,SI
  1466.         JL      @@2
  1467.         ADD     SI,ES:[DI].TPCXButton.Size.Y
  1468.         CMP     AX,SI
  1469.         JGE     @@2
  1470.         MOV     SI,ES:[DI].TPCXButton.Origin.X
  1471.         CMP     DX,SI
  1472.         JL      @@2
  1473.         ADD     SI,ES:[DI].TPCXButton.Size.X
  1474.         CMP     DX,SI
  1475.         JGE     @@2
  1476. @@4:    MOV     CX,2000H
  1477.         JMP     @@6
  1478. @@5:    MOV     DH,AL
  1479.         XOR     BH,BH
  1480.         MOV     AH,2
  1481.         INT     10H
  1482.         MOV     CX,CursorLines
  1483.         LES     DI,Self
  1484.         TEST    ES:[DI].TPCXButton.State,sfCursorIns
  1485.         JE      @@6
  1486.         MOV     CH,0
  1487.         OR      CL,CL
  1488.         JNE     @@6
  1489.         MOV     CL,7
  1490. @@6:    MOV     AH,1
  1491.         INT     10H
  1492. end;
  1493.  
  1494. procedure TPCXButton.DrawCursor;
  1495. begin
  1496.   if State and sfFocused <> 0 then ResetCursor;
  1497. end;
  1498.  
  1499.  
  1500. procedure TPCXButton.DrawView;
  1501. begin
  1502.   if Exposed then
  1503.   begin
  1504.     Draw;
  1505.     DrawCursor;
  1506.   end;
  1507. end;
  1508.  
  1509. {TPCXFrame3D}
  1510. constructor TPCXFrame3D.Init(var Bounds: TRect; ATitle: String; AFrametype, AColor: Byte);
  1511. begin
  1512.   Inherited Init(Bounds);
  1513.   Title:=ATitle;
  1514.   Frametype:=AFrametype;
  1515.   Color:=AColor;
  1516. end;
  1517.  
  1518. procedure TPCXFrame3D.Draw;
  1519. var
  1520.   B: TDrawBuffer;
  1521.   i: Word;
  1522.   S: String;
  1523.   C: Word;
  1524. begin
  1525.   if Color = FrameWhite then C:=GetColor(2)
  1526.                         else C:=GetColor(1);
  1527.   case Frametype of
  1528.   2:
  1529.   begin
  1530.  
  1531.   end;
  1532.   end;
  1533.   if IsPCXGraphCharsOn then
  1534.   begin
  1535.     FillChar(S, Size.X-1, #196);
  1536.     S[0]:=Chr(Size.X-2);
  1537.     if Title<>'' then MoveCStr(B, GFrame3DConers[0]+S+GFrame3DConers[1], C)
  1538.                  else MoveChar(B, GFrameSummitD, C, Size.X);
  1539.     WriteLine(0,0,Size.X,Size.Y, B);
  1540.     {for i:=1 to Size.Y-2 do
  1541.     begin}
  1542.       MoveCStr(B, GFrameEdgeL+Copy(FrameEmpty, 1, Size.X-2)+GFrameEdgeR, C);
  1543.       WriteLine(0,1,Size.X,Size.Y, B);
  1544.     {end;}
  1545.     MoveChar(B, GFrameSummitU, C, Size.X);
  1546.     WriteLine(0,Size.Y-1,Size.X,Size.Y, B);
  1547.   end
  1548.   else
  1549.   begin
  1550.     FillChar(S, Size.X-1, #196);
  1551.     S[0]:=Chr(Size.X-2);
  1552.     MoveCStr(B, #218+S+#191, C);
  1553.     WriteLine(0,0,Size.X,Size.Y, B);
  1554.     {for i:=1 to Size.Y-2 do
  1555.     begin}
  1556.       MoveCStr(B, #179+Copy(FrameEmpty, 1, Size.X-2)+#179, C);
  1557.       WriteLine(0,1,Size.X,Size.Y, B);
  1558.     {end;}
  1559.     FillChar(S, Size.X-1, #196);
  1560.     S[0]:=Chr(Size.X-2);
  1561.     MoveCStr(B, #192+S+#217, C);
  1562.     WriteLine(0,Size.Y-1,Size.X,Size.Y, B);
  1563.   end;
  1564.   {end;}
  1565.   if Title<>'' then
  1566.   begin
  1567.     if Title[1]<>#3
  1568.     then begin
  1569.            MoveCStr(B, #32+Title+#32, GetColor(2));
  1570.            WriteLine(1, 0, Length(Title)+2, 1, B);
  1571.          end
  1572.     else begin
  1573.            Delete(Title, 1, 1);
  1574.            MoveCStr(B, #32+Title+#32, GetColor(2));
  1575.            WriteLine(1+((Size.X-Length(Title)-2) div 2), 0, Length(Title)+2, 1, B);
  1576.          end;
  1577.   end;
  1578.   Message(Application, evCommand, cmMouseChanged, @Self);
  1579. end;
  1580.  
  1581. function  TPCXFrame3D.GetPalette: PPalette;
  1582. const P: String[Length(CPCXFrame3D)] = CPCXFrame3D;
  1583. begin
  1584.   GetPalette:=@P;
  1585. end;
  1586.  
  1587. {TPCXFileDialog}
  1588. constructor TPCXFileDialog.Init(AWildCard: TWildStr; const ATitle,
  1589.   InputName: String; AOptions: Word; HistoryId: Byte);
  1590. var
  1591.   Control: PView;
  1592.   R: TRect;
  1593.   Opt: Word;
  1594. begin
  1595.   R.Assign(15,1,64,20);
  1596.   TDialog.Init(R, ATitle);
  1597.   Options := Options or ofCentered;
  1598.   WildCard := AWildCard;
  1599.  
  1600.   R.Assign(3,3,34,4);
  1601.   FileName := New(PFileInputLine, Init(R, 79));
  1602.   FileName^.Data^ := WildCard;
  1603.   Insert(FileName);
  1604.   R.Assign(2,2,3+CStrLen(InputName),3);
  1605.   Control := New(PLabel, Init(R, InputName, FileName));
  1606.   Insert(Control);
  1607. (*  R.Assign(31,3,34,4);
  1608.   Control := New(PHistory, Init(R, FileName, HistoryId));
  1609.   Insert(Control);*)
  1610.  
  1611.   R.Assign(2,5,35,16);
  1612.   Insert(New(PPCXFrame3D, Init(R, ' ', AllGraphFrame, FrameBlack)));
  1613.   R.Assign(2,14,35,15);
  1614.   Control := New(PPCXScrollBar, Init(R));
  1615.   Insert(Control);
  1616.   R.Assign(3,6,34,14);
  1617.   FileList := New(PFileList, Init(R, PPCXScrollBar(Control)));
  1618.   Insert(FileList);
  1619.   R.Assign(3,5,10,6);
  1620.   Control := New(PLabel, Init(R, '~F~iles ', FileList));
  1621.   Insert(Control);
  1622.  
  1623.   R.Assign(35,3,46,5);
  1624.   Opt := bfDefault;
  1625.   if AOptions and fdOpenButton <> 0 then
  1626.   begin
  1627.     Insert(New(PPCXButton, Init(R, '~O~pen', cmFileOpen, Opt)));
  1628.     Opt := bfNormal;
  1629.     Inc(R.A.Y,3); Inc(R.B.Y,3);
  1630.   end;
  1631.   if AOptions and fdOkButton <> 0 then
  1632.   begin
  1633.     Insert(New(PPCXButton, Init(R, 'O~K~', cmFileOpen, Opt)));
  1634.     Opt := bfNormal;
  1635.     Inc(R.A.Y,3); Inc(R.B.Y,3);
  1636.   end;
  1637.   if AOptions and fdReplaceButton <> 0 then
  1638.   begin
  1639.     Insert(New(PPCXButton, Init(R, '~R~eplace',cmFileReplace, Opt)));
  1640.     Opt := bfNormal;
  1641.     Inc(R.A.Y,3); Inc(R.B.Y,3);
  1642.   end;
  1643.   if AOptions and fdClearButton <> 0 then
  1644.   begin
  1645.     Insert(New(PPCXButton, Init(R, '~C~lear',cmFileClear, Opt)));
  1646.     Opt := bfNormal;
  1647.     Inc(R.A.Y,3); Inc(R.B.Y,3);
  1648.   end;
  1649.   Insert(New(PPCXButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  1650.   Inc(R.A.Y,3); Inc(R.B.Y,3);
  1651.   if AOptions and fdHelpButton <> 0 then
  1652.   begin
  1653.     Insert(New(PPCXButton, Init(R, 'Help',cmHelp, bfNormal)));
  1654.     Inc(R.A.Y,3); Inc(R.B.Y,3);
  1655.   end;
  1656.  
  1657.   R.Assign(1,16,48,18);
  1658.   Control := New(PFileInfoPane, Init(R));
  1659.   Insert(Control);
  1660.  
  1661.   SelectNext(False);
  1662.  
  1663.   if AOptions and fdNoLoadDir = 0 then ReadDirectory;
  1664. end;
  1665.  
  1666. function TPCXFileDialog.GetPalette: PPalette;
  1667. const P: String[Length(CPCXBlueDialog)] = CPCXBlueDialog;
  1668. begin
  1669.   GetPalette:=@P;
  1670. end;
  1671.  
  1672. procedure TPCXFileDialog.InitFrame;
  1673. var R: TRect;
  1674. begin
  1675.   GetExtent(R);
  1676.   Frame:=New(PPCXFrame, Init(R));
  1677. end;
  1678.  
  1679. function GetCurDir: DirStr;
  1680. var
  1681.   CurDir: DirStr;
  1682. begin
  1683.   GetDir(0, CurDir);
  1684.   if Length(CurDir) > 3 then
  1685.   begin
  1686.     Inc(CurDir[0]);
  1687.     CurDir[Length(CurDir)] := '\';
  1688.   end;
  1689.   GetCurDir := CurDir;
  1690. end;
  1691.  
  1692. procedure TPCXFileDialog.ReadDirectory;
  1693. begin
  1694.   FileList^.ReadDirectory(WildCard);
  1695.   Directory := NewStr(GetCurDir);
  1696. end;
  1697.  
  1698. {TPCXCheckBoxes}
  1699. constructor TPCXCheckBoxes.Init(var Bounds: TRect; AStrings: PSItem; IsRightOn: Boolean);
  1700. begin
  1701.   inherited Init(Bounds, AStrings);
  1702.   IsRight:=IsRightOn;
  1703. end;
  1704.  
  1705. procedure TPCXCheckBoxes.DrawMultiBox(const Icon, Marker: String);
  1706. var
  1707.   I,J,Cur,Col: Integer;
  1708.   CNorm, CSel, CDis, Color: Word;
  1709.   B: TDrawBuffer;
  1710.   SCOff: Byte;
  1711. begin
  1712.   CNorm := GetColor($0301);
  1713.   CSel := GetColor($0402);
  1714.   CDis := GetColor($0505);
  1715.   for I := 0 to Size.Y do
  1716.   begin
  1717.     MoveChar(B, ' ', Byte(CNorm), Size.X);
  1718.     for J := 0 to (Strings.Count - 1) div Size.Y + 1 do
  1719.     begin
  1720.       Cur := J*Size.Y + I;
  1721.       if Cur < Strings.Count then
  1722.       begin
  1723.         Col := Column(Cur);
  1724.         if (Col + CStrLen(PString(Strings.At(Cur))^) + 5 <
  1725.           Sizeof(TDrawBuffer) div SizeOf(Word)) and (Col < Size.X) then
  1726.         begin
  1727.           if not ButtonState(Cur) then
  1728.             Color := CDis
  1729.           else if (Cur = Sel) and (State and sfFocused <> 0) then
  1730.             Color := CSel
  1731.           else
  1732.             Color := CNorm;
  1733.           if not IsRight then
  1734.           begin
  1735.             MoveChar(B[Col], ' ', Byte(Color), Size.X - Col);
  1736.             MoveStr(B[Col], Icon, Byte(Color));
  1737.             WordRec(B[Col+2]).Lo := Byte(Marker[MultiMark(Cur) + 1]);
  1738.             MoveCStr(B[Col+5], PString(Strings.At(Cur))^, Color);
  1739.           end
  1740.           else
  1741.           begin
  1742.             MoveChar(B[Col], ' ', Byte(Color), Size.X - Col);
  1743.             MoveStr(B[Size.X-4], Icon, Byte(Color));
  1744.             WordRec(B[Size.X-2]).Lo := Byte(Marker[MultiMark(Cur) + 1]);
  1745.             MoveCStr(B[Col+2], PString(Strings.At(Cur))^, Color);
  1746.           end;
  1747.           if ShowMarkers and (State and sfFocused <> 0) and (Cur = Sel) then
  1748.           begin
  1749.             WordRec(B[Col]).Lo := Byte(SpecialChars[0]);
  1750.             WordRec(B[Column(Cur+Size.Y)-1]).Lo := Byte(SpecialChars[1]);
  1751.           end;
  1752.         end;
  1753.       end;
  1754.     end;
  1755.     WriteBuf(0, I, Size.X, 1, B);
  1756.   end;
  1757.   if IsRight then SetCursor(Column(Sel)+Size.X-2,Row(Sel))
  1758.              else SetCursor(Column(Sel)+2,Row(Sel));
  1759.   Message(Application, evCommand, cmMouseChanged, @Self);
  1760. end;
  1761.  
  1762. function TPCXCheckBoxes.Column(Item: Integer): Integer;
  1763. var
  1764.   I, Col, Width, L: Integer;
  1765. begin
  1766.   if Item < Size.Y then Column := 0
  1767.   else
  1768.   begin
  1769.     Width := 0;
  1770.     Col := -6;
  1771.     for I := 0 to Item do
  1772.     begin
  1773.       if I mod Size.Y = 0 then
  1774.       begin
  1775.         Inc(Col, Width + 6);
  1776.         Width := 0;
  1777.       end;
  1778.       if I < Strings.Count then
  1779.         L := CStrLen(PString(Strings.At(I))^);
  1780.       if L > Width then Width := L;
  1781.     end;
  1782.     Column := Col;
  1783.   end;
  1784. end;
  1785.  
  1786. function TPCXCheckBoxes.FindSel(P: TPoint): Integer;
  1787. var
  1788.   I, S: Integer;
  1789.   R: TRect;
  1790. begin
  1791.   GetExtent(R);
  1792.   if not R.Contains(P) then FindSel := -1
  1793.   else
  1794.   begin
  1795.     I := 0;
  1796.     while P.X >= Column(I+Size.Y) do
  1797.       Inc(I, Size.Y);
  1798.     S := I + P.Y;
  1799.     if S >= Strings.Count then
  1800.       FindSel := -1 else
  1801.       FindSel := S;
  1802.   end;
  1803. end;
  1804.  
  1805. function TPCXCheckBoxes.Row(Item: Integer): Integer;
  1806. begin
  1807.   Row := Item mod Size.Y;
  1808. end;
  1809.  
  1810. procedure TPCXCheckBoxes.Draw;
  1811. const
  1812.   GraphButton = #32+CheckBoxLeft+#32+CheckBoxRight+#32; {' [ ] '}
  1813.   TextButton  = ' [ ] ';
  1814. begin
  1815.   if IsPCXGraphCharsOn
  1816.   then DrawMultiBox(GraphButton, CheckBoxCenterN+CheckBoxCenterX) {' X'}
  1817.   else DrawMultiBox(TextButton, ' X');
  1818. end;
  1819.  
  1820. function  TPCXCheckBoxes.GetPalette: PPalette;
  1821. const P: String[Length(CPCXCheckBoxes)] = CPCXCheckBoxes;
  1822. begin
  1823.   GetPalette:=@P;
  1824. end;
  1825.  
  1826. procedure TPCXCheckBoxes.Press(Item: Integer);
  1827. begin
  1828.   Inherited Press(Item);
  1829.   Message(Owner, evCommand, cmCheckBoxChanged, @Self);
  1830. end;
  1831.  
  1832. {TPCXRadioButtons}
  1833. constructor TPCXRadioButtons.Init(var Bounds: TRect; AStrings: PSItem; IsRightOn: Boolean);
  1834. begin
  1835.  inherited Init(Bounds, AStrings);
  1836.  IsRight:=IsRightOn;
  1837. end;
  1838.  
  1839. procedure TPCXRadioButtons.DrawMultiBox(const Icon, Marker: String);
  1840. var
  1841.   I,J,Cur,Col: Integer;
  1842.   CNorm, CSel, CDis, Color: Word;
  1843.   B: TDrawBuffer;
  1844.   SCOff: Byte;
  1845. begin
  1846.   CNorm := GetColor($0301);
  1847.   CSel := GetColor($0402);
  1848.   CDis := GetColor($0505);
  1849.   for I := 0 to Size.Y do
  1850.   begin
  1851.     MoveChar(B, ' ', Byte(CNorm), Size.X);
  1852.     for J := 0 to (Strings.Count - 1) div Size.Y + 1 do
  1853.     begin
  1854.       Cur := J*Size.Y + I;
  1855.       if Cur < Strings.Count then
  1856.       begin
  1857.         Col := Column(Cur);
  1858.         if (Col + CStrLen(PString(Strings.At(Cur))^) + 5 <
  1859.           Sizeof(TDrawBuffer) div SizeOf(Word)) and (Col < Size.X) then
  1860.         begin
  1861.           if not ButtonState(Cur) then
  1862.             Color := CDis
  1863.           else if (Cur = Sel) and (State and sfFocused <> 0) then
  1864.             Color := CSel
  1865.           else
  1866.             Color := CNorm;
  1867.           if not IsRight then
  1868.           begin
  1869.             MoveChar(B[Col], ' ', Byte(Color), Size.X - Col);
  1870.             MoveStr(B[Col], Icon, Byte(Color));
  1871.             WordRec(B[Col+2]).Lo := Byte(Marker[MultiMark(Cur) + 1]);
  1872.             MoveCStr(B[Col+5], PString(Strings.At(Cur))^, Color);
  1873.           end
  1874.           else
  1875.           begin
  1876.             MoveChar(B[Col], ' ', Byte(Color), Size.X - Col);
  1877.             MoveStr(B[Size.X-4], Icon, Byte(Color));
  1878.             WordRec(B[Size.X-2]).Lo := Byte(Marker[MultiMark(Cur) + 1]);
  1879.             MoveCStr(B[Col+2], PString(Strings.At(Cur))^, Color);
  1880.           end;
  1881.           if ShowMarkers and (State and sfFocused <> 0) and (Cur = Sel) then
  1882.           begin
  1883.             WordRec(B[Col]).Lo := Byte(SpecialChars[0]);
  1884.             WordRec(B[Column(Cur+Size.Y)-1]).Lo := Byte(SpecialChars[1]);
  1885.           end;
  1886.         end;
  1887.       end;
  1888.     end;
  1889.     WriteBuf(0, I, Size.X, 1, B);
  1890.   end;
  1891.   if IsRight then SetCursor(Column(Sel)+Size.X-2,Row(Sel))
  1892.              else SetCursor(Column(Sel)+2,Row(Sel));
  1893.   Message(Application, evCommand, cmMouseChanged, @Self);
  1894. end;
  1895.  
  1896. function TPCXRadioButtons.Column(Item: Integer): Integer;
  1897. var
  1898.   I, Col, Width, L: Integer;
  1899. begin
  1900.   if Item < Size.Y then Column := 0
  1901.   else
  1902.   begin
  1903.     Width := 0;
  1904.     Col := -6;
  1905.     for I := 0 to Item do
  1906.     begin
  1907.       if I mod Size.Y = 0 then
  1908.       begin
  1909.         Inc(Col, Width + 6);
  1910.         Width := 0;
  1911.       end;
  1912.       if I < Strings.Count then
  1913.         L := CStrLen(PString(Strings.At(I))^);
  1914.       if L > Width then Width := L;
  1915.     end;
  1916.     Column := Col;
  1917.   end;
  1918. end;
  1919.  
  1920. function TPCXRadioButtons.FindSel(P: TPoint): Integer;
  1921. var
  1922.   I, S: Integer;
  1923.   R: TRect;
  1924. begin
  1925.   GetExtent(R);
  1926.   if not R.Contains(P) then FindSel := -1
  1927.   else
  1928.   begin
  1929.     I := 0;
  1930.     while P.X >= Column(I+Size.Y) do
  1931.       Inc(I, Size.Y);
  1932.     S := I + P.Y;
  1933.     if S >= Strings.Count then
  1934.       FindSel := -1 else
  1935.       FindSel := S;
  1936.   end;
  1937. end;
  1938.  
  1939. function TPCXRadioButtons.Row(Item: Integer): Integer;
  1940. begin
  1941.   Row := Item mod Size.Y;
  1942. end;
  1943.  
  1944. procedure TPCXRadioButtons.Draw;
  1945. const
  1946.   GraphButton = #32+RadioButtonLeft+#32+RadioButtonRight+#32; {' ( ) '}
  1947.   TextButton  = ' ( ) ';
  1948. begin
  1949.   if IsPCXGraphCharsOn
  1950.   then DrawMultiBox(GraphButton, RadioButtonCenterN+RadioButtonCenterX) {#32#7}
  1951.   else DrawMultiBox(TextButton, #32#7);
  1952. end;
  1953.  
  1954. function TPCXRadioButtons.GetPalette: PPalette;
  1955. const P: String[Length(CPCXRadioButtons)] = CPCXRadioButtons;
  1956. begin
  1957.   GetPalette:=@P;
  1958. end;
  1959.  
  1960. procedure TPCXRadioButtons.Press(Item: Integer);
  1961. begin
  1962.   Inherited Press(Item);
  1963.   Message(Owner, evCommand, cmRadioButtonChanged, @Self);
  1964. end;
  1965.  
  1966.  
  1967. {PCXMsgBox}
  1968. function PCXMsgBoxRect(var R: TRect; const Msg: String; Params: Pointer;
  1969.   AOptions: Word): Word;
  1970. {const
  1971.   ButtonName: Array[0..3] of String[6] =
  1972.     ('~Y~es', '~N~o', 'O~K~', 'Cancel');
  1973.   Commands: Array[0..3] of word =
  1974.     (cmYes, cmNo, cmOK, cmCancel);
  1975.   Titles: Array[0..3] of String[11] =
  1976.     ('Warning','Error','Information','Confirm');}
  1977. var
  1978.   I, X, ButtonCount: Integer;
  1979.   Dialog: PDialog;
  1980.   Control: PView;
  1981.   ButtonList: Array[0..4] of PView;
  1982.   S: String;
  1983.   ButtonName: Array[0..3] of String[6];
  1984.   Commands: Array[0..3] of word;
  1985.   Titles: Array[0..3] of String[11];
  1986. begin
  1987.   if Not IsMagyarul then
  1988.   begin
  1989.    ButtonName[0]:='~Y~es';
  1990.    ButtonName[1]:='~N~o';
  1991.    ButtonName[2]:='O~K~';
  1992.    ButtonName[3]:='Cancel';
  1993.  
  1994.    Commands[0]:=cmYes;
  1995.    Commands[1]:=cmNo;
  1996.    Commands[2]:=cmOK;
  1997.    Commands[3]:=cmCancel;
  1998.  
  1999.    Titles[0]:='Warning';
  2000.    Titles[1]:='Error';
  2001.    Titles[2]:='Information';
  2002.    Titles[3]:='Confirm';
  2003.   end
  2004.   else
  2005.   begin
  2006.    ButtonName[0]:='~I~gen';
  2007.    ButtonName[1]:='~N~em';
  2008.    ButtonName[2]:='O~K~';
  2009.    ButtonName[3]:='Mégsem';
  2010.  
  2011.    Commands[0]:=cmYes;
  2012.    Commands[1]:=cmNo;
  2013.    Commands[2]:=cmOK;
  2014.    Commands[3]:=cmCancel;
  2015.  
  2016.    Titles[0]:='Vigyázat';
  2017.    Titles[1]:='Hiba';
  2018.    Titles[2]:='Információ';
  2019.    Titles[3]:='Konfirmáció';
  2020.   end;
  2021.   {Special Thanks o Bérczi Gábor for: if mfError or mfWarning then RedDialog}
  2022.   if ((AOptions and 3)<>mfError) and ((AOptions and 3)<>mfWarning)
  2023.      then Dialog := New(PPCXBlueDialog,Init(R, Titles[AOptions and $3]))
  2024.      else Dialog := New(PPCXRedDialog,Init(R, Titles[AOptions and $3]));
  2025.   {End Thanks}
  2026.   with Dialog^ do
  2027.   begin
  2028.     R.Assign(3, 2, Size.X - 2, Size.Y - 3);
  2029.     FormatStr(S, Msg, Params^);
  2030.     Control := New(PStaticText, Init(R, S));
  2031.     Insert(Control);
  2032.     X := -2;
  2033.     ButtonCount := 0;
  2034.     for I := 0 to 3 do
  2035.       if AOptions and ($0100 shl I) <> 0 then
  2036.       begin
  2037.         R.Assign(0, 0, 10, 2);
  2038.         Control := New(PPCXButton, Init(R, ButtonName[I], Commands[i],
  2039.           bfNormal));
  2040.         Inc(X, Control^.Size.X + 2);
  2041.         ButtonList[ButtonCount] := Control;
  2042.         Inc(ButtonCount);
  2043.       end;
  2044.     X := (Size.X - X) shr 1;
  2045.     for I := 0 to ButtonCount - 1 do
  2046.     begin
  2047.       Control := ButtonList[I];
  2048.       Insert(Control);
  2049.       Control^.MoveTo(X, Size.Y - 3);
  2050.       Inc(X, Control^.Size.X + 2);
  2051.     end;
  2052.     SelectNext(False);
  2053.   end;
  2054.   if AOptions and mfInsertInApp = 0 then
  2055.     PCXMsgBoxRect := DeskTop^.ExecView(Dialog)
  2056.   else PCXMsgBoxRect := Application^.ExecView(Dialog);
  2057.   Dispose(Dialog, Done);
  2058. end;
  2059.  
  2060. function PCXMsgBox(const Msg: String; Params: Pointer; AOptions: Word): Word;
  2061. var
  2062.   R: TRect;
  2063. begin
  2064.   R.Assign(0, 0, 40, 9);
  2065.   if AOptions and mfInsertInApp = 0 then
  2066.     R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2)
  2067.   else R.Move((Application^.Size.X - R.B.X) div 2, (Application^.Size.Y - R.B.Y) div 2);
  2068.   PCXMsgBox := PCXMsgBoxRect(R, Msg, Params, AOptions);
  2069. end;
  2070.  
  2071. END.