home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Pascal / TVDMX.ZIP / STDDMX.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-04-01  |  12.4 KB  |  467 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    StdDMX   --Standard tvDMX Interface Unit    }
  5. {    tvDMX    --data editing project (ver 2.x)    }
  6. {                            }
  7. {    Copyright (c) 1992,93   Randolph Beck        }
  8. {                P.O. Box  56-0487    }
  9. {                Orlando, FL 32856    }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Unit StdDMX;
  15.  
  16. {$B-,D-,O+,R-,X+,V- }
  17.  
  18. interface
  19.  
  20. uses  crt, Objects, Drivers, Views, Dialogs, App, RSet, tvGizma, DmxGizma, tvDMX;
  21.  
  22. const    CDmxEditDlg    = #19#20#06#06#01#02; { similar to CInputLine }
  23.              {  |  |  |  |  |  | }
  24.   {  1 normal fields -------+  |  |  |  |  | }
  25.   {  2 normal selected field --+  |  |  |  | }
  26.   {  3 read-only selected field --+  |  |  | }
  27.   {  4 locked field -----------------+  |  | }
  28.   {  5 delimiter -----------------------+  | }
  29.   {  6 border -----------------------------+ }
  30.  
  31. type
  32.     PDmxEditDlg     = ^TDmxEditDlg;  { tvDMX editor for dialog boxes }
  33.     PInputFields = ^TInputFields; { line-editor for dialog boxes }
  34.     PDmxViewer     = ^TDmxViewer;   { tvDMX data scroller window }
  35.     PDmxWindow     = ^TDmxWindow;   { tvDMX data editor window  }
  36.  
  37.  
  38.     TDmxEditDlg     =  OBJECT (TDmxEditor)
  39.       function  GetPalette  : PPalette;  VIRTUAL;
  40.     end;
  41.  
  42.  
  43.     TInputFields =  OBJECT (TDmxEditDlg)
  44.     StdEnter    : boolean;
  45.       constructor Init (InfoStr : string; var Bounds : TRect);
  46.       procedure InitData (var AData );  VIRTUAL;
  47.       procedure DoneData;  VIRTUAL;
  48.       procedure LoadData (var S : TStream);  VIRTUAL;
  49.       procedure StoreData (var S : TStream);  VIRTUAL;
  50.       function  DataSize  : word;  VIRTUAL;
  51.       procedure GetData (var Rec );  VIRTUAL;
  52.       procedure SetData (var Rec );  VIRTUAL;
  53.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  54.       procedure SetState (AState : word; Enable : boolean);  VIRTUAL;
  55.       procedure SetUpField;  VIRTUAL;
  56.     end;
  57.  
  58.  
  59.     TDmxViewer     =  OBJECT (TLtdWindow)
  60.     DMX    : PDmxEditor;
  61.       constructor Init (var Bounds : TRect;  ATitle : TTitleStr;  ANumber : integer;
  62.             ATemplate : string;  var AData;  BSize : longint;
  63.             var ALabels  : string);
  64.       constructor Load (var S : TStream);
  65.       procedure InitDMX (ATemplate : string;  var AData;
  66.             ALabels, ARecInd  : PDmxLink;
  67.             BSize  : longint);  VIRTUAL;
  68.       function  NewDmxLabels (var ALabels ) : PDmxLink;  VIRTUAL;
  69.       procedure Store (var S : TStream);
  70.       function  Valid (Command : word) : boolean;  VIRTUAL;
  71.     end;
  72.  
  73.  
  74.     TDmxWindow     =  OBJECT (TDmxViewer)
  75.       constructor Init (var Bounds : TRect;  ATitle : TTitleStr;  ANumber : integer;
  76.             ATemplate : string;  var AData;  BSize : longint;
  77.             var ALabels  : string;  IndLen  : integer);
  78.       procedure InitDMX (ATemplate : string;  var AData;
  79.             ALabels, ARecInd  : PDmxLink;
  80.             BSize  : longint);  VIRTUAL;
  81.       function  NewRecInd (Len : integer) : PDmxLink;  VIRTUAL;
  82.     end;
  83.  
  84.  
  85.  
  86.   procedure GetBlob (Num : integer; var Blob : pointer; var Len : integer);
  87.  
  88.  
  89.   function  InsertField (Dialog : PDialog;  Col,Row : integer;
  90.              Fmt : boolean;  ALabel,ATemplate : string) : PView;
  91.  
  92.   procedure RegisterStdDMX;
  93.  
  94.  
  95. const
  96.     RDmxEditDlg    :  TStreamRec = (
  97.     ObjType:  rnDmxEditDlg;
  98.     VmtLink:  ofs (TypeOf (TDmxEditDlg)^);
  99.     Load:     @TDmxEditDlg.Load;
  100.     Store:    @TDmxEditDlg.Store
  101.       );
  102.  
  103.     RInputFields :  TStreamRec = (
  104.     ObjType:  rnInputFields;
  105.     VmtLink:  ofs (TypeOf (TInputFields)^);
  106.     Load:     @TInputFields.Load;
  107.     Store:    @TInputFields.Store
  108.       );
  109.  
  110.     RDmxViewer    :  TStreamRec = (
  111.     ObjType:  rnDmxViewer;
  112.     VmtLink:  ofs (TypeOf (TDmxViewer)^);
  113.     Load:     @TDmxViewer.Load;
  114.     Store:    @TDmxViewer.Store
  115.       );
  116.  
  117.     RDmxWindow    :  TStreamRec = (
  118.     ObjType:  rnDmxWindow;
  119.     VmtLink:  ofs (TypeOf (TDmxWindow)^);
  120.     Load:     @TDmxWindow.Load;
  121.     Store:    @TDmxWindow.Store
  122.       );
  123.  
  124.  
  125. implementation
  126.  
  127.   { ══════════════════════════════════════════════════════════════════════ }
  128.  
  129.  
  130. procedure GetBlob (Num : integer; var Blob : pointer; var Len : integer);
  131. var  P : PDmxEditor;
  132. begin
  133.   Blob := nil;
  134.   Len  := 0;
  135.   P := Message (DeskTop, evCommand, cmDMX_RollCall, nil);
  136.   If (P <> nil) then P^.GetBlob (Num, Blob, Len);
  137. end;
  138.  
  139.  
  140.   { ══════════════════════════════════════════════════════════════════════ }
  141.  
  142.  
  143. function  InsertField (Dialog : PDialog;  Col,Row : integer;
  144.                Fmt : boolean;  ALabel,ATemplate : string)  : PView;
  145. var  i  : integer;
  146.      R  : TRect;
  147.      B  : PView;
  148. begin
  149.   With Dialog^ do
  150.     begin
  151.     i  := succ (CStrLen (ALabel));
  152.     R.Assign (Col, Row, Col + DmxStrLen (ATemplate), succ (Row));
  153.     If (ALabel <> '') then
  154.       begin
  155.       If Fmt then R.Move (1, 1) else R.Move (i, 0);
  156.       end;
  157.     B  := New (PInputFields, Init (ATemplate, R));
  158.     Insert (B);
  159.     If (ALabel <> '') then
  160.       begin
  161.       R.Assign (Col, Row, Col + i, succ (Row));
  162.       Insert (New (PLabel, Init (R, ALabel, B)));
  163.       end;
  164.     end;
  165.   InsertField := B;
  166. end;
  167.  
  168.  
  169.   { ══ TDmxEditDlg ══════════════════════════════════════════════════════ }
  170.  
  171.  
  172. function  TDmxEditDlg.GetPalette  : PPalette;
  173. const  A : string [length (CDmxEditDlg)] = CDmxEditDlg;
  174. begin
  175.   GetPalette := @A
  176. end;
  177.  
  178.  
  179.   { ══ TInputFields ══════════════════════════════════════════════════════ }
  180.  
  181.  
  182. constructor TInputFields.Init (InfoStr : string;  var Bounds : TRect);
  183. var  S      : string;
  184.      void : integer;
  185. begin
  186.     { init with no data }
  187.   S := ^A + InfoStr;
  188.   TDmxEditDlg.Init (S, void, 0, Bounds, nil,nil, nil,nil);
  189.   GrowMode := gfGrowHiX;
  190.   Options := Options or ofFirstClick;
  191.   StdEnter := TRUE;
  192. end;
  193.  
  194.  
  195. procedure TInputFields.InitData (var AData );
  196. { allocates memory for the data }
  197. begin
  198.   DataBlockSize := Size.Y * RecordSize;  { correct improper size }
  199.   GetMem (WorkingData, DataBlockSize);
  200.   fillchar (WorkingData^, DataBlockSize, 0);
  201.   TDmxEditDlg.InitData (WorkingData^);
  202. end;
  203.  
  204.  
  205. procedure TInputFields.DoneData;
  206. begin
  207.   TDmxEditDlg.DoneData;
  208.   FreeMem (WorkingData, DataBlockSize);
  209. end;
  210.  
  211.  
  212. procedure TInputFields.LoadData (var S : TStream);
  213. begin
  214.   S.Read (StdEnter, sizeof (StdEnter));
  215.   S.Read (DataBlockSize, sizeof (DataBlockSize));
  216.   GetMem (WorkingData,  DataBlockSize);
  217.   S.Read (WorkingData^, DataBlockSize);
  218. end;
  219.  
  220.  
  221. procedure TInputFields.StoreData (var S : TStream);
  222. begin
  223.   S.Write (StdEnter, sizeof (StdEnter));
  224.   S.Write (DataBlockSize, sizeof (DataBlockSize));
  225.   S.Write (WorkingData^, DataBlockSize);
  226. end;
  227.  
  228.  
  229. function  TInputFields.DataSize  : word;
  230. begin
  231.   DataSize := LongRec (DataBlockSize).Lo
  232. end;
  233.  
  234.  
  235. procedure TInputFields.GetData (var Rec );
  236. var  Len : word;
  237. begin
  238.   Len  := DataSize;
  239.   If (Len > 0) and (WorkingData <> nil) then Move (WorkingData^, Rec, Len);
  240. end;
  241.  
  242.  
  243. procedure TInputFields.SetData (var Rec );
  244. var  Len : word;
  245. begin
  246.   Len  := DataSize;
  247.   If (Len > 0) and (WorkingData <> nil) then Move (Rec, WorkingData^, Len);
  248.   DrawView;
  249. end;
  250.  
  251.  
  252. const  Initing : boolean = FALSE;
  253.  
  254.  
  255. procedure TInputFields.HandleEvent (var Event : TEvent);
  256.     function  AtEndField : boolean;
  257.     var  F : pDMXfieldrec;
  258.     begin
  259.       F := CurrentField;
  260.       Repeat
  261.     F := F^.Next;
  262.       Until (F = nil) or ((F^.fieldsize > 0) and (F^.access and accSkip = 0));
  263.       AtEndField := (F = nil);
  264.     end;
  265. begin
  266.   With Event do
  267.     If (What = evKeyboard) then
  268.       begin
  269.       If (KeyCode = kbEnter) and StdEnter and AtEndField then
  270.     begin
  271.     TScroller.HandleEvent (Event);
  272.     Exit;
  273.     end
  274.        else
  275.     begin
  276.     If ((KeyCode = kbPgUp) or (KeyCode = kbUp)) and (CurrentRecord = 0) then
  277.       KeyCode := kbShiftTab;
  278.     If ((KeyCode = kbPgDn) or (KeyCode = kbDown)
  279.       or ((KeyCode = kbEnter) and AtEndField))
  280.       and (succ (CurrentRecord) = Limit.Y)
  281.      then
  282.       KeyCode := kbTab;
  283.     end;
  284.       end
  285.     else
  286.     If (What = evBroadcast) and (Command = cmDMX_RollCall) and Initing and
  287.        (InfoPtr <> @Self) then
  288.       begin
  289.       StdEnter := FALSE;
  290.       end;
  291.   TDmxEditDlg.HandleEvent (Event);
  292. end;
  293.  
  294.  
  295. procedure TInputFields.SetState (AState : word; Enable : boolean);
  296. var  cmd    : word;
  297.      voidXY : TPoint;
  298. begin
  299.   If (AState and sfFocused <> 0) and not Enable then JustAltered := FALSE;
  300.   TDmxEditDlg.SetState (AState, Enable);
  301.   If Enable and (AState and sfFocused <> 0) then
  302.     begin
  303.     cmd  := cmDMX_Home;
  304.     ProcessCommand (cmd, voidXY);
  305.     end
  306.   else
  307.   If Enable and (AState and sfExposed <> 0) then
  308.     begin
  309.     If (Owner <> nil) then
  310.       begin
  311.       Initing := TRUE;
  312.       Message (Owner, evBroadcast, cmDMX_RollCall, @Self);
  313.       Initing := FALSE;
  314.       end;
  315.     end;
  316. end;
  317.  
  318.  
  319. procedure TInputFields.SetUpField;
  320. begin
  321.   TDmxEditDlg.SetUpField;
  322.   If (CurrentField <> nil) and
  323.      (upcase (CurrentField^.typecode) in [fldSTR, fldSTRNUM, fldCHAR, fldCHARNUM])
  324.    then
  325.     FirstKey := FALSE;
  326. end;
  327.  
  328.  
  329.   { ══ TDmxViewer ════════════════════════════════════════════════════════ }
  330.  
  331.  
  332. constructor TDmxViewer.Init (var Bounds     : TRect;
  333.                  ATitle     : TTitleStr;
  334.                  ANumber    : integer;
  335.                  ATemplate  : string;
  336.                  var AData;
  337.                  BSize      : longint;
  338.                  var ALabels    : string);
  339. const  NilWin    : array [0..1] of Longint = (0,0);
  340. begin
  341.   TLtdWindow.Init (Bounds, TRect (NilWin), ATitle, ANumber);
  342.   InitDMX (ATemplate, AData, NewDmxLabels (ALabels), nil, BSize);
  343.   Options := Options or ofTileable;
  344. end;
  345.  
  346.  
  347. constructor TDmxViewer.Load (var S : TStream);
  348. begin
  349.   TLtdWindow.Load (S);
  350.   GetSubViewPtr (S, DMX);
  351. end;
  352.  
  353.  
  354. procedure TDmxViewer.InitDMX (ATemplate     : string;
  355.                   var AData;
  356.                   ALabels,ARecInd  : PDmxLink;
  357.                   BSize  : longint);
  358. var  R    : TRect;
  359. begin
  360.   GetExtent (R);
  361.   R.Grow (-1,-1);
  362.   If (ALabels <> nil) then Inc (R.A.Y, ALabels^.Size.Y);
  363.   Insert (New (PDmxScroller, Init (ATemplate, AData, BSize, R, ALabels,
  364.                    StandardScrollBar (sbHorizontal+ sbHandleKeyboard),
  365.                    StandardScrollBar (sbVertical  + sbHandleKeyboard))));
  366. end;
  367.  
  368.  
  369. function  TDmxViewer.NewDmxLabels (var ALabels ) : PDmxLink;
  370. begin
  371.   If (@ALabels = nil) or (string (ALabels) = '') then
  372.     NewDmxLabels := nil
  373.    else
  374.     NewDmxLabels := New (PDmxLabels, InitInsert (@Self, @ALabels));
  375. end;
  376.  
  377.  
  378. procedure TDmxViewer.Store (var S : TStream);
  379. begin
  380.   TLtdWindow.Store (S);
  381.   PutSubViewPtr (S, DMX);
  382. end;
  383.  
  384.  
  385. function  TDmxViewer.Valid (Command : word) : boolean;
  386. var  Len : integer;
  387.      V     : boolean;
  388. begin
  389.   V := TLtdWindow.Valid (Command);
  390.   If V and (Command = cmValid) then
  391.     begin
  392.     If (DMX = nil) then DMX := Message (@Self, evCommand, cmDMX_RollCall, nil);
  393.     If (DMX <> nil) and (DMX^.Labels <> nil) then
  394.       begin
  395.       If (Limit.A.Y > 0) then Limit.A.Y := succ (Size.Y - DMX^.Size.Y);
  396.       Limit.B.X    := PDmxLabels (DMX^.Labels)^.Len + (Size.X - DMX^.Size.X);
  397.       Len    := length (GetTitle (MaxViewWidth)) + 12;
  398.       If (Len > ScreenWidth) then Len := ScreenWidth;
  399.       If (Len > Limit.B.X) then Limit.B.X := Len;
  400.       If (Limit.B.X < MinWinSize.X) then Limit.B.X := MinWinSize.X;
  401.       end;
  402.     end;
  403.   Valid := V;
  404. end;
  405.  
  406.  
  407.   { ══ TDmxWindow ════════════════════════════════════════════════════════ }
  408.  
  409.  
  410. constructor TDmxWindow.Init (var Bounds     : TRect;
  411.                  ATitle     : TTitleStr;
  412.                  ANumber    : integer;
  413.                  ATemplate  : string;
  414.                  var AData;
  415.                  BSize        : longint;
  416.                  var ALabels    : string;
  417.                  IndLen     : integer);
  418. const  NilWin    : array [0..1] of Longint = (0,0);
  419. begin
  420.   TLtdWindow.Init (Bounds, TRect (NilWin), ATitle, ANumber);
  421.   InitDMX (ATemplate, AData, NewDmxLabels (ALabels), NewRecInd (IndLen), BSize);
  422.   Options := Options or ofTileable;
  423. end;
  424.  
  425.  
  426. procedure TDmxWindow.InitDMX (ATemplate : string;  var AData;
  427.                   ALabels, ARecInd : PDmxLink;
  428.                   BSize  : longint);
  429. var  R  : TRect;
  430. begin
  431.   GetExtent (R);
  432.   R.Grow (-1,-1);
  433.   If (ALabels <> nil) then Inc (R.A.Y, ALabels^.Size.Y);
  434.   Insert (New (PDmxEditor, Init (ATemplate, AData, BSize, R,
  435.                  ALabels, ARecInd,
  436.                  StandardScrollBar (sbHorizontal + sbHandleKeyboard),
  437.                  StandardScrollBar (sbVertical   + sbHandleKeyboard))));
  438. end;
  439.  
  440.  
  441. function  TDmxWindow.NewRecInd (Len : integer) : PDmxLink;
  442. begin
  443.   If (Len <= 0) then
  444.     NewRecInd := nil
  445.    else
  446.     NewRecInd := New (PDmxRecInd, InitInsert (@Self, Len));
  447. end;
  448.  
  449.  
  450.   { ══════════════════════════════════════════════════════════════════════ }
  451.  
  452.  
  453. procedure RegisterStdDMX;
  454. begin
  455.   RegisterType (RDmxEditDlg);
  456.   RegisterType (RInputFields);
  457.   RegisterType (RDmxViewer);
  458.   RegisterType (RDmxWindow);
  459. end;
  460.  
  461.  
  462.   { ══════════════════════════════════════════════════════════════════════ }
  463.  
  464.  
  465.  
  466. End.
  467.