home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 March / pcx19_9803.iso / PC-XUSER / PC-XUSER.14 / OOP / PCX_DLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-09  |  13.5 KB  |  449 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;
  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.   {CPCXDialogs}
  48.   CPCXBlueDialog =
  49.     #64#65#66#67#68#69#70#71#72#73#74#75#76#77#78#79+                {  1- 16}
  50.     #80#81#82#83#84#85#86#87#88#89#90#91#92#92#94#95+                { 17- 32}
  51.     #96#97#98#99#100;                                                { 33- 37}
  52.     {#64-#100}
  53.   CPCXRedDialog  =
  54.     #101#102#103#104#105#106#107#108#109#110#111#112#113#114#115#116+{  1- 16}
  55.     #117#118#119#120#121#122#123#124#125#126#127#128#129#130#131#132+{ 17- 32}
  56.     #133#134#135#136#137;                                            { 33- 37}
  57.     {#101-#137}
  58.   CPCXGrayDialog =
  59.     #138#139#140#141#142#143#144#145#146#147#148#149#150#151#152#153+{  1- 16}
  60.     #154#155#156#157#158#159#160#161#162#163#164#165#166#167#168#169+{ 17- 32}
  61.     #170#171#172#173#174;                                            { 33- 37}
  62.     {#138-#174}
  63.   CPCXDialog     = CGrayDialog+#170#171#172#173#174;
  64.  
  65.   {CPCXWindows}
  66.   CPCXWindow     = CPCXDialog;
  67.   CPCXBlueWindow = CPCXBlueDialog;
  68.   CPCXRedWindow  = CPCXRedDialog;
  69.   CPCXGrayWindow = CPCXGrayDialog;
  70.  
  71.   CPCXIndicator = #2#37#3#37;
  72.   CPCXFileEditor = #6#4;
  73.  
  74.   CPCXTitleBar = #175;
  75.   CPCXControlBoxApp = #175;
  76.   CPCXControlBoxDlg = #34;
  77.   CPCXControlBoxWin = #34;
  78.  
  79.   CPCXFrame = #1#33#2#34#36#37#35; {CFrame + DragWindow + DragTitle}
  80.  
  81. type
  82.   PString = OBJECTS.PString;
  83.  
  84.   PPCXPoint = ^TPCXPoint;
  85.   TPCXPoint = Object(TPoint)
  86.     procedure Assign(XA, YA: Integer);
  87.   end;
  88.  
  89.   PPCXMenuBox = ^TPCXMenuBox;
  90.   TPCXMenuBox = Object(TMenuBox)
  91.     procedure Draw; virtual;
  92.   end;
  93.  
  94.   PPCXControlBox = ^TPCXControlBox;
  95.   TPCXControlBox = Object(TStaticText)
  96.     constructor Init(P: TPCXPoint);
  97.     procedure HandleEvent(var Event: TEvent); virtual;
  98.     procedure ExecControlMenuBox; virtual;
  99.   private
  100.     ControlMenuBox: PPCXMenuBox;
  101.   end;
  102.  
  103.   PPCXControlBoxApp = ^TPCXControlBoxApp;
  104.   TPCXControlBoxApp = Object(TPCXControlBox)
  105.     function  GetPalette: PPalette; virtual;
  106.     procedure ExecControlMenuBox; virtual;
  107.   end;
  108.  
  109.   PPCXControlBoxDlg = ^TPCXControlBoxDlg;
  110.   TPCXControlBoxDlg = Object(TPCXControlBox)
  111.     function  GetPalette: PPalette; virtual;
  112.     procedure ExecControlMenuBox; virtual;
  113.   end;
  114.  
  115.   PPCXControlBoxWin = ^TPCXControlBoxWin;
  116.   TPCXControlBoxWin = Object(TPCXControlBox)
  117.     function  GetPalette: PPalette; virtual;
  118.     procedure ExecControlMenuBox; virtual;
  119.   end;
  120.  
  121.   PPCXMenuBar = ^TPCXMenuBar;
  122.   TPCXMenuBar = Object(TMenuBar)
  123.     function NewSubView(var Bounds: TRect; AMenu: PMenu;
  124.       AParentMenu: PMenuView): PMenuView; virtual;
  125.   end;
  126.  
  127.  
  128. const
  129.   IsMagyarul       : Boolean = False;
  130.   IsIntensity      : Boolean = False;
  131.   ShowMouseOn      : Boolean = True;
  132.   IsHomokOra       : Boolean = False;
  133.   On  = True;
  134.   Off = False;
  135.   Be  = True;
  136.   Ki  = False;
  137.  
  138. IMPLEMENTATION
  139. uses App, PCX_Util;
  140.  
  141. const
  142.   FrameEmpty: String[80] =  '                                        '+
  143.                             '                                        ';
  144.   FrameFull : String[80] =  '████████████████████████████████████████'+
  145.                             '████████████████████████████████████████';
  146.   GFrameUp  : String[80] =  '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞'+
  147.                             '╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞╞';
  148.   FrameUp   : String[80] =  '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀'+
  149.                             '▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀';
  150.   GFrameDown: String[80] =  '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟'+
  151.                             '╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟╟';
  152.   FrameDown : String[80] =  '████████████████████████████████████████'+
  153.                             '████████████████████████████████████████';
  154.  
  155.   WindowSizer: String[2] = #210#14; {'─┘'}
  156.   ControlBox : String[2] = #209#180;{'[■]'}
  157.   UpWin      : String[2] = #214#11;
  158.   RestoreWin : String[2] = #9#10;
  159.   GFrame3DConers: Array[0..1] of Char = #221#222;
  160.   PasswordChar  : Byte = 42; {'*' = #42}
  161.  
  162. {TPCXPoint}
  163. procedure TPCXPoint.Assign(XA, YA: Integer);
  164. begin
  165.   X:=XA; Y:=YA;
  166. end;
  167.  
  168. {TPCXMenuBox}
  169. procedure TPCXMenuBox.Draw;
  170. var
  171.   CNormal, CSelect, CNormDisabled, CSelDisabled, Color: Word;
  172.   Y: Integer;
  173.   P: PMenuItem;
  174.   B: TDrawBuffer;
  175.  
  176. procedure FrameLine(N: Integer);
  177. const
  178.      FrameChars: Array[0..19] of Char = ' ┌─┐  └─┘  │ │  ├─┤ ';
  179.   PCXFrameChars: Array[0..19] of Char =
  180.     GFrameCornerLU+GFrameSummitU+GFrameSummitU+GFrameSummitU+GFrameCornerRU+
  181.     GFrameCornerLD+GFrameSummitD+GFrameSummitD+GFrameSummitD+GFrameCornerRD+
  182.     GFrameEdgeL+#32#32#32+GFrameEdgeR+
  183.     GFrameEdgeL+#32#196#32+GFrameEdgeR; {'┴╞╞╞┬├╟╟╟┼╚   ╔╚ ─ ╔'}
  184. begin
  185.   if IsPCXGraphCharsOn
  186.   then begin
  187.          MoveBuf(B[0], PCXFrameChars[N], Byte(CNormal), 2);
  188.          MoveChar(B[2], PCXFrameChars[N + 2], Byte(Color), Size.X - 4);
  189.          MoveBuf(B[Size.X - 2], PCXFrameChars[N + 3], Byte(CNormal), 2);
  190.        end
  191.   else begin
  192.          MoveBuf(B[0], FrameChars[N], Byte(CNormal), 2);
  193.          MoveChar(B[2], FrameChars[N + 2], Byte(Color), Size.X - 4);
  194.          MoveBuf(B[Size.X - 2], FrameChars[N + 3], Byte(CNormal), 2);
  195.        end;
  196. end;
  197.  
  198. procedure DrawLine;
  199. begin
  200.   WriteBuf(0, Y, Size.X, 1, B);
  201.   Inc(Y);
  202. end;
  203.  
  204. begin
  205.   CNormal := GetColor($0301);
  206.   CSelect := GetColor($0604);
  207.   CNormDisabled := GetColor($0202);
  208.   CSelDisabled := GetColor($0505);
  209.   Y := 0;
  210.   Color := CNormal;
  211.   FrameLine(0);
  212.   DrawLine;
  213.   if Menu <> nil then
  214.   begin
  215.     P := Menu^.Items;
  216.     while P <> nil do
  217.     begin
  218.       Color := CNormal;
  219.       if P^.Name = nil then FrameLine(15) else
  220.       begin
  221.         if P^.Disabled then
  222.           if P = Current then
  223.             Color := CSelDisabled else
  224.             Color := CNormDisabled else
  225.           if P = Current then Color := CSelect;
  226.         FrameLine(10);
  227.         MoveCStr(B[3], P^.Name^, Color);
  228.         if P^.Command = 0 then
  229.           MoveChar(B[Size.X - 4], #16, Byte(Color), 1) else
  230.           if P^.Param <> nil then
  231.             MoveStr(B[Size.X - 3 - Length(P^.Param^)],
  232.               P^.Param^, Byte(Color));
  233.       end;
  234.       DrawLine;
  235.       P := P^.Next;
  236.     end;
  237.   end;
  238.   Color := CNormal;
  239.   FrameLine(5);
  240.   DrawLine;
  241.   Message(Application, evCommand, cmMouseChanged, @Self);
  242. end;
  243.  
  244. {TPCXControlBox}
  245. constructor TPCXControlBox.Init(P: TPCXPoint);
  246. var
  247.   R    : TRect;
  248.   TempS: String;
  249. begin
  250.   ControlMenuBox:=nil;
  251.   R.A.X:=P.X; R.A.Y:=P.Y;
  252.               R.B.Y:=R.A.Y+1;
  253.   if IsPCXGraphCharsOn
  254.   then begin
  255.          R.B.X:=2;
  256.          TempS:=ControlBox;
  257.         end
  258.   else begin
  259.          R.B.X:=3;
  260.          TempS:='[■]';
  261.        end;
  262.   Inherited Init(R, TempS);
  263. end;
  264.  
  265. procedure TPCXControlBox.HandleEvent(var Event: TEvent);
  266. begin
  267.   ExecControlMenuBox;
  268.   Inherited HandleEvent(Event);
  269. end;
  270.  
  271. procedure TPCXControlBox.ExecControlMenuBox;
  272. begin
  273.   Abstract;
  274. end;
  275.  
  276. procedure TPCXControlBoxApp.ExecControlMenuBox;
  277. var
  278.   R    : TRect;
  279.   O    : TPCXPoint;
  280.   C    : Word;
  281.   Event: TEvent;
  282. begin
  283.   O.Assign(0,0);
  284.   MakeGlobal(O, O);
  285.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  286.   if IsMagyarul then
  287.   begin
  288.     Inc(R.A.X, 2);
  289.     Inc(R.B.X, 2);
  290.   end;
  291.   if Not IsMagyarul then
  292.   New(ControlMenuBox, Init(R, NewMenu(
  293.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  294.     NewItem('~Q~uit', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  295.     NewLine(
  296.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  297.     nil))           else
  298.   New(ControlMenuBox, Init(R, NewMenu(
  299.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  300.     NewItem('~K~ilépés', 'Alt- X', kbAltQ, cmQuit, hcNoContext,
  301.     NewLine(
  302.     NewItem('~F~rissítés', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  303.     nil));
  304.   C:=Application^.ExecView(ControlMenuBox);
  305.   if C<>cmCancel then
  306.   begin
  307.     case C of cmMove:
  308.               begin
  309.                 {Application^.GetEvent(Event);
  310.                 Event.What:=evKeyboard;
  311.                 Application^.PutEvent(Event);}
  312.                 KeyStrokeToKeyboardBuffer(0, $62);
  313.                 Message(Application, evCommand, cmMouseChanged, @Self);
  314.               end;
  315.               cmRefresh: Application^.ReDraw;
  316.               cmQuit:  {if AreYouSureToQuit then} Message(Application, evCommand, cmQuit, @Self);
  317.     {javit!}
  318.  
  319.  
  320.     end;
  321.   end;
  322. end;
  323.  
  324. function  TPCXControlBoxApp.GetPalette: PPalette;
  325. const P: String[Length(CPCXControlBoxApp)] = CPCXControlBoxApp;
  326. begin
  327.   GetPalette:=@P;
  328. end;
  329.  
  330. procedure TPCXControlBoxDlg.ExecControlMenuBox;
  331. var
  332.   R    : TRect;
  333.   O    : TPCXPoint;
  334.   C    : Word;
  335.   Event: TEvent;
  336. begin
  337.   O.Assign(1,0);
  338.   MakeGlobal(O, O);
  339.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  340.   if IsMagyarul then
  341.   begin
  342.     Inc(R.A.X);
  343.     Inc(R.B.X);
  344.   end;
  345.   if IsMagyarul then
  346.   New(ControlMenuBox, Init(R, NewMenu(
  347.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  348.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  349.     NewLine(
  350.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  351.     nil))           else
  352.   New(ControlMenuBox, Init(R, NewMenu(
  353.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  354.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  355.     NewLine(
  356.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  357.     nil));
  358.   C:=Application^.ExecView(ControlMenuBox);
  359.   Owner^.EnableCommands([cmClose]);
  360.   EnableCommands([cmClose]);
  361.   if C<>cmCancel then
  362.   begin
  363.     case C of cmMove:
  364.               begin
  365.                 {Application^.GetEvent(Event);
  366.                 Event.What:=evKeyboard;
  367.                 Application^.PutEvent(Event);}
  368.                 KeyStrokeToKeyboardBuffer(0, $62);
  369.                 Message(Application, evCommand, cmMouseChanged, @Self);
  370.               end;
  371.               cmRefresh: Application^.ReDraw;
  372.               cmClose:   begin
  373.                            KeyStrokeToKeyboardBuffer(0, $6A);
  374.                            Message(Application, evBroadcast, cmClose, @Self);
  375.                            Message(Application, evCommand, cmMouseChanged, @Self);
  376.                          end;
  377.     end;
  378.   end;
  379. end;
  380.  
  381. function  TPCXControlBoxDlg.GetPalette: PPalette;
  382. const P: String[Length(CPCXControlBoxDlg)] = CPCXControlBoxDlg;
  383. begin
  384.   GetPalette:=@P;
  385. end;
  386.  
  387. procedure TPCXControlBoxWin.ExecControlMenuBox;
  388. var
  389.   R    : TRect;
  390.   O    : TPCXPoint;
  391.   C    : Word;
  392. begin
  393.   O.Assign(1,0);
  394.   MakeGlobal(O, O);
  395.   R.Assign(O.X,O.Y+1,O.X+18,O.Y+7);
  396.   Owner^.EnableCommands([cmClose]);
  397.   EnableCommands([cmClose]);
  398.   if IsMagyarul then
  399.   begin
  400.     Inc(R.A.X);
  401.     Inc(R.B.X);
  402.   end;
  403.   if IsMagyarul then
  404.   New(ControlMenuBox, Init(R, NewMenu(
  405.     NewItem('~M~ozgat', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  406.     NewItem('~B~ezár', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  407.     NewLine(
  408.     NewItem('~F~rissít', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  409.     nil))           else
  410.   New(ControlMenuBox, Init(R, NewMenu(
  411.     NewItem('~M~ove', 'Crt-F5', kbCtrlF5, cmMove, hcNoContext,
  412.     NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
  413.     NewLine(
  414.     NewItem('~R~efresh', '', kbNoKey, cmRefresh, hcNoContext, nil))))),
  415.     nil));
  416.   C:=Application^.ExecView(ControlMenuBox);
  417.   if C<>cmCancel then
  418.   begin
  419.     case C of cmMove:
  420.               begin
  421.                  KeyStrokeToKeyboardBuffer(0, $62);
  422.                  Message(Application, evCommand, cmMouseChanged, @Self);
  423.               end;
  424.               cmRefresh: Application^.ReDraw;
  425.               cmClose:
  426.               begin
  427.                  KeyStrokeToKeyboardBuffer(0, $6A);
  428.                  Message(Application, evCommand, cmMouseChanged, @Self);
  429.               end;
  430.  
  431.     end;
  432.   end;
  433. end;
  434.  
  435. function  TPCXControlBoxWin.GetPalette: PPalette;
  436. const P: String[Length(CPCXControlBoxWin)] = CPCXControlBoxWin;
  437. begin
  438.   GetPalette:=@P;
  439. end;
  440.  
  441. {TPCXMenuBar}
  442. function TPCXMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  443.   AParentMenu: PMenuView): PMenuView;
  444. begin
  445.   NewSubView := New(PPCXMenuBox, Init(Bounds, AMenu, AParentMenu));
  446. end;
  447.  
  448.  
  449. END.