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

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    DMXFORMS  --Form Editing Unit            }
  5. {    tvDMX     --data editing project (ver 2.1)    }
  6. {                            }
  7. {    Copyright (c) 1993  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Unit DMXFORMS;
  15.  
  16. {$B-,D+,O+,R-,V-,X+ }
  17.  
  18. interface
  19.  
  20. uses Objects, Drivers, Memory, Views, Dialogs, Menus, App,
  21.      RSet, DmxGizma, tvDMX;
  22.  
  23. const
  24.     CDmxDlgForm        = #26#12#10#10#01#02;
  25.              {  |  |  |  |  |  |  }
  26.   {  1 normal fields -------+  |  |  |  |  |  }
  27.   {  2 normal selected field --+  |  |  |  |  }
  28.   {  3 read-only selected field --+  |  |  |  }
  29.   {  4 locked field -----------------+  |  |  }
  30.   {  5 delimiter -----------------------+  |  }
  31.   {  6 border -----------------------------+  }
  32.  
  33. type
  34.     PFldPtrArray    = ^TFldPtrArray;
  35.     TFldPtrArray    =  array [0..8195] of pDMXfieldrec;
  36.  
  37.  
  38.     PDmxForm        = ^TDmxForm;
  39.     TDmxForm        =  OBJECT (TDmxEditor)
  40.     InScrl        : boolean;
  41.     NumRows        : integer;
  42.     DMXfields    : PFldPtrArray;
  43.       constructor Init (ATemplates : PSItem;  AInScroll : boolean;
  44.             var AData;  var Bounds : TRect;  ALabels,ARecInd : PDmxLink;
  45.             AHScrollBar,AVScrollBar : PScrollBar);
  46.       function  DataAt (RecNum : integer) : pointer;  VIRTUAL;
  47.       procedure DoneStruct;   VIRTUAL;
  48.       procedure Draw;         VIRTUAL;
  49.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  50.       procedure InitStruct (var ATemplate );  VIRTUAL;
  51.       procedure LoadStruct (var S : TStream);  VIRTUAL;
  52.       procedure SetupField;   VIRTUAL;
  53.       procedure SetupRecord;  VIRTUAL;
  54.       procedure StoreStruct (var S : TStream);  VIRTUAL;
  55.       private
  56.     FirstDataRow    : integer;
  57.     PrevRec        : integer;
  58.     end;
  59.  
  60.  
  61.     PDmxDlgForm        = ^TDmxDlgForm;
  62.     TDmxDlgForm        =  OBJECT (TDmxForm)
  63.       constructor Init (ATemplates : PSItem;
  64.             var Bounds : TRect;
  65.             AHScrollBar,AVScrollBar : PScrollBar);
  66.       function  DataSize : word;  VIRTUAL;
  67.       procedure DoneData;  VIRTUAL;
  68.       procedure GetData (var Rec );  VIRTUAL;
  69.       function  GetPalette : PPalette;  VIRTUAL;
  70.       procedure InitData (var AData );  VIRTUAL;
  71.       procedure SetData (var Rec );  VIRTUAL;
  72.     end;
  73.  
  74.  
  75.   procedure RegisterDMXFORMS;
  76.  
  77.  
  78. const
  79.     RDmxForm    :  TStreamRec = (
  80.     ObjType:  rnDmxForm;
  81.     VmtLink:  ofs (TypeOf (TDmxForm)^);
  82.     Load:     @TDmxForm.Load;
  83.     Store:    @TDmxForm.Store
  84.       );
  85.  
  86.     RDmxDlgForm    :  TStreamRec = (
  87.     ObjType:  rnDmxDlgForm;
  88.     VmtLink:  ofs (TypeOf (TDmxDlgForm)^);
  89.     Load:     @TDmxDlgForm.Load;
  90.     Store:    @TDmxDlgForm.Store
  91.       );
  92.  
  93.  
  94. implementation
  95.  
  96.   { ══ TDmxForm ══════════════════════════════════════════════════════════ }
  97.  
  98.  
  99. constructor TDmxForm.Init (ATemplates : PSItem;  AInScroll : boolean;
  100.             var AData;  var Bounds : TRect;  ALabels,ARecInd : PDmxLink;
  101.             AHScrollBar,AVScrollBar : PScrollBar);
  102. var  S : string [sizeof (PSItem) + 1];
  103. begin
  104.   Move (ATemplates, S [1], sizeof (PSItem));
  105.   S [0] := #4;
  106.   TDmxEditor.Init (S, AData, 0, Bounds, ALabels, ARecInd, AHScrollBar, AVScrollBar);
  107.   InScrl := AInScroll;
  108. end;
  109.  
  110.  
  111. procedure TDmxForm.LoadStruct (var S : TStream);
  112. var  i : integer;
  113. begin
  114.   S.Read (InScrl,  sizeof (InScrl));
  115.   S.Read (NumRows, sizeof (NumRows));
  116.   S.Read (FirstDataRow, sizeof (FirstDataRow));
  117.   If (NumRows > 0) then
  118.     begin
  119.     GetMem (DMXfields, (NumRows * 4) + 200);
  120.     For i := 0 to pred (NumRows) do
  121.       begin
  122.       TDmxEditor.LoadStruct (S);
  123.       DMXfields^ [i] := DMXfield1;
  124.       end;
  125.     end;
  126.   PrevRec := -1;
  127. end;
  128.  
  129.  
  130. function  TDmxForm.DataAt (RecNum : integer) : pointer;
  131. begin
  132.   DMXfield1 := DMXfields^ [RecNum];
  133.   DataAt := WorkingData;
  134. end;
  135.  
  136.  
  137. procedure TDmxForm.DoneStruct;
  138. var  Items,P : PSItem;
  139.      i,Lim   : integer;
  140. begin
  141.   If (DMXfields = nil) then Exit;
  142.   i := NumRows;
  143.   While (i > 0) do
  144.     begin
  145.     DMXfield1 := DMXfields^ [pred (i)];
  146.     If (DMXfield1 <> nil) then TDmxEditor.DoneStruct;
  147.     Dec (i);
  148.     end;
  149.   FreeMem (DMXfields, (NumRows * 4) + 200);
  150.   NumRows := 0;
  151.   Limit.X := 0;
  152.   DataBlockSize := 0;
  153.   RecordSize := 0;
  154. end;
  155.  
  156.  
  157. procedure TDmxForm.Draw;
  158. begin
  159.   TDmxScroller.Draw;
  160.   DMXfield1 := DMXfields^ [CurrentRecord];
  161.   If FieldSelected and (showanyway in ShowFmt) and (CurrentField <> nil) then
  162.     DrawField (CurrentField);
  163. end;
  164.  
  165.  
  166. procedure TDmxForm.HandleEvent (var Event : TEvent);
  167. var  i,j    : word;
  168.      RS,FS    : boolean;
  169.      MousePlace    : TPoint;
  170.      PrevFld    : pDMXfieldrec;
  171. begin
  172.   With Event do
  173.     If (Event.What = evMouseDown) and GetState (sfFocused) and
  174.        (MouseInView (Where)) then
  175.       begin
  176.       RS := RecordSelected;
  177.       FS := FieldSelected;
  178.       If FS then EvaluateField;
  179.       If RS then EvaluateRecord;
  180.       MakeLocal (Where, MousePlace);
  181.       MousePlace.X := MousePlace.X + Delta.X;
  182.       MousePlace.Y := MousePlace.Y + Delta.Y;
  183.       i := cmDMX_goto;
  184.       DMXfield1 := DMXfields^ [MousePlace.Y];
  185.       PrevFld    := CurrentField;
  186.       CurrentField := DMXfield1;
  187.       If (MousePlace.Y < Limit.Y) then
  188.     ProcessCommand (i, MousePlace)
  189.        else
  190.     DoubleValid := FALSE;
  191.       If not DoubleValid then
  192.     begin
  193.     WrongKeypressed (Event);
  194.     CurrentField := PrevFld;
  195.     end;
  196.       ClearEvent (Event);
  197.       If RS then SetupRecord;
  198.       If FS then SetupField;
  199.       end
  200.      else
  201.       begin
  202.       Case What of
  203.     evCommand,evBroadcast:
  204.       begin
  205.       If (Command = cmDMX_Draw) or (Command = cmDMX_DrawData) then
  206.         begin
  207.         DrawView;
  208.         If (What = evCommand) then ClearEvent (Event);
  209.         end;
  210.       end;
  211.     evKeyboard:
  212.       begin
  213.       If ((KeyCode = kbPgUp) or (KeyCode = kbUp)) and (CurrentRecord = 0) then
  214.         KeyCode := kbShiftTab;
  215.       If ((KeyCode = kbPgDn) or (KeyCode = kbDown))
  216.         and (succ (CurrentRecord) = Limit.Y)
  217.        then
  218.         KeyCode := kbTab;
  219.       end;
  220.     end;
  221.       TDmxEditor.HandleEvent (Event);
  222.       end;
  223. end;
  224.  
  225.  
  226. procedure TDmxForm.InitStruct (var ATemplate );
  227. var  Items    : PSItem;
  228.      i,Lim    : integer;
  229.      AllZ    : boolean;
  230.      S        : string;
  231. begin
  232.   Move (string (ATemplate) [1], Items, sizeof (Items));
  233.   If (Items = nil) then Exit;
  234.   FirstDataRow := -1;
  235.   AllZ := (Items^.Value <> nil) and (Items^.Value^[1] = ^A);
  236.   Repeat
  237.     Inc (NumRows);
  238.     Items := Items^.Next;
  239.   Until (Items = nil);
  240.   Move (string (ATemplate) [1], Items, sizeof (Items));
  241.   GetMem (DMXfields, (NumRows * 4) + 200);
  242.   i := 0;
  243.   Lim := 0;
  244.   While (Items <> nil) and (not LowMemory) do
  245.     begin
  246.     Limit.X := 0;
  247.     DMXfield1 := nil;
  248.     If (Items^.Value = nil) or (Items^.Value^ = '') or (Items^.Value^ = ^A) then
  249.       S := ' '
  250.      else
  251.       S := Items^.Value^;
  252.     If AllZ and (length (S) < pred (sizeof (S))) then Insert (^A, S, 1);
  253.     TDmxEditor.InitStruct (S);
  254.     If (FirstDataRow < 0) and (RecordSize > 0) then
  255.       begin
  256.       CurrentField := DMXfield1;
  257.       While (CurrentField <> nil) and ((CurrentField^.fieldsize = 0)
  258.      or (CurrentField^.access and (accHidden or accSkip) <> 0)) do
  259.     CurrentField := CurrentField^.Next;
  260.       If (CurrentField <> nil) then FirstDataRow := i;
  261.       end;
  262.     If (Lim < Limit.X) then Lim := Limit.X;
  263.     DMXfields^ [i] := DMXfield1;
  264.     Inc (i);
  265.     Items := Items^.Next;
  266.     end;
  267.   Limit.X := Lim;
  268.   DataBlockSize := RecordSize;
  269.   DataBlockSize := DataBlockSize * NumRows;
  270.   If (FirstDataRow >= 0) then CurrentRecord := FirstDataRow;
  271.   DMXfield1 := DMXfields^[CurrentRecord];
  272.   PrevRec := -1;
  273. end;
  274.  
  275.  
  276. procedure TDmxForm.SetUpField;
  277. begin
  278.   TDmxEditor.SetUpField;
  279.   If InScrl and (CurrentField <> nil) and
  280.      (upcase (CurrentField^.typecode) in [fldSTR, fldSTRNUM, fldCHAR, fldCHARNUM])
  281.    then
  282.     FirstKey := FALSE;
  283. end;
  284.  
  285.  
  286. procedure TDmxForm.SetupRecord;
  287. var  i,n : integer;
  288.      cmd : word;
  289.      cf,was : pDMXfieldrec;
  290. begin
  291.   was := CurrentField;
  292.   If (CurrentField = nil) then n := 0 else n := CurrentField^.screentab;
  293.   DMXfield1 := DMXfields^ [CurrentRecord];
  294.   CurrentField := DMXfield1;
  295.   If (DMXfield1 <> nil) then
  296.     begin
  297.     While (CurrentField <> nil) and ((CurrentField^.fieldsize = 0) or
  298.       (CurrentField^.access and (accHidden or accSkip) <> 0)) do
  299.       CurrentField := CurrentField^.Next;
  300.     If (CurrentField = nil) then
  301.       begin
  302.       If (CurrentRecord = 0) then PrevRec := -1;
  303.       If (CurrentRecord = pred (Limit.Y)) then PrevRec := Limit.Y;
  304.       If (PrevRec > CurrentRecord) then cmd := cmDMX_Up else cmd := cmDMX_Down;
  305.       CurrentField := was;
  306.       Message (@Self, evCommand, cmd, @Self);
  307.       TDmxForm.SetupRecord;
  308.       Exit;
  309.       end
  310.      else
  311.       begin
  312.       cf := CurrentField;
  313.       While (cf <> nil) and (cf^.screentab <= n) do
  314.     begin
  315.     If (cf^.fieldsize > 0) and (cf^.access and (accHidden or accSkip) = 0)
  316.      then CurrentField := cf;
  317.     cf := cf^.Next;
  318.     end;
  319.       n := Delta.X;
  320.       If (n + CurrentField^.screentab + CurrentField^.shownwid > Size.X) then
  321.     n := CurrentField^.screentab + CurrentField^.shownwid - Size.X;
  322.       If (n > CurrentField^.screentab) then n := CurrentField^.screentab;
  323.       If (n <> Delta.X) then ScrollTo (n, Delta.Y);
  324.       end;
  325.     end;
  326.   TDmxEditor.SetupRecord;
  327.   PrevRec := CurrentRecord;
  328. end;
  329.  
  330.  
  331. procedure TDmxForm.StoreStruct (var S : TStream);
  332. var  i : integer;
  333. begin
  334.   S.Write (InScrl,  sizeof (InScrl));
  335.   S.Write (NumRows, sizeof (NumRows));
  336.   S.Write (FirstDataRow, sizeof (FirstDataRow));
  337.   If (NumRows > 0) then
  338.     For i := 0 to pred (NumRows) do
  339.       begin
  340.       DMXfield1 := DMXfields^ [i];
  341.       TDmxEditor.StoreStruct (S);
  342.       end;
  343.   PrevRec := -1;
  344. end;
  345.  
  346.  
  347.   { ══ TDmxDlgForm ═══════════════════════════════════════════════════════ }
  348.  
  349.  
  350. constructor TDmxDlgForm.Init (ATemplates : PSItem;
  351.             var Bounds : TRect;
  352.             AHScrollBar,AVScrollBar : PScrollBar);
  353. begin
  354.   TDmxForm.Init (ATemplates, TRUE, Mem [0:0], Bounds, nil,nil, AHScrollBar, AVScrollBar);
  355. end;
  356.  
  357.  
  358. function  TDmxDlgForm.DataSize : word;
  359. begin
  360.   DataSize := RecordSize;
  361. end;
  362.  
  363.  
  364. procedure TDmxDlgForm.DoneData;
  365. begin
  366.   If (WorkingData <> nil) and (RecordSize > 0) then
  367.     FreeMem (WorkingData, RecordSize);
  368. end;
  369.  
  370.  
  371. procedure TDmxDlgForm.GetData (var Rec );
  372. begin
  373.   Move (WorkingData^, Rec, DataSize);
  374. end;
  375.  
  376.  
  377. function  TDmxDlgForm.GetPalette : PPalette;
  378. const  P : string [length (CDmxDlgForm)] = CDmxDlgForm;
  379. begin
  380.   GetPalette := @P
  381. end;
  382.  
  383.  
  384. procedure TDmxDlgForm.InitData (var AData );
  385. begin
  386.   If not LowMemory and (RecordSize > 0) then
  387.     begin
  388.     GetMem (WorkingData, RecordSize);
  389.     FillChar (WorkingData^, RecordSize, 0);
  390.     end;
  391. end;
  392.  
  393.  
  394. procedure TDmxDlgForm.SetData (var Rec );
  395. begin
  396.   Move (Rec, WorkingData^, DataSize);
  397. end;
  398.  
  399.  
  400.   { ══════════════════════════════════════════════════════════════════════ }
  401.  
  402.  
  403. procedure RegisterDMXFORMS;
  404. begin
  405.   RegisterType (RDmxForm);
  406.   RegisterType (RDmxDlgForm);
  407. end;
  408.  
  409.  
  410.   { ══════════════════════════════════════════════════════════════════════ }
  411.  
  412.  
  413. End.
  414.