home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1074 / hftp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-01-31  |  14.4 KB  |  479 lines

  1. {************************************************************}
  2. {************************************************************}
  3. {**                                                        **}
  4. {**  Turbo Vision Demo                                     **}
  5. {**  Portions Copyright (c) 1992 by Borland International  **}
  6. {**  Portions Coypright (c) 1993 by KAP Holger Lembke      **}
  7. {**                                                        **}
  8. {************************************************************}
  9. {************************************************************}
  10.  
  11. {
  12. dt.
  13. KAP - Ergänzungen
  14. 14.01.94
  15.   ■ Farbumsetztablle "CConverter" eingebaut
  16. 10.01.93
  17.   ■ Einige Geschwindigkeitsoptimierungen
  18.     Hauptsächlich wiederholtes Dereferenzieren beseitigt,
  19.     ca. 8% schneller, Kleinvieh macht auch Mist.
  20. 06.01.93
  21.   ■ Farbcodegeschichten gestrafft und vereinheitlicht
  22.   ■ Farbcodes, die VOR dem sichtbaren Teil der Seite liegen, wurden
  23.     nicht berücksichtigt
  24.      zweite "for i:=1 to delta.y" Schleife
  25.   ■ Fehler in Farbdarstellung bei direkt aufeinanderfolgenden Farbcodes
  26.      Farbcodeumsetzer modifiziert
  27.          k:=1;
  28.          m:=0;
  29.          cc:=0;
  30.          while (k<=length(line)) do begin
  31. **         while (line[k]='#') and (k<length(line)) do begin
  32. war        if (line[k]='#') then begin
  33. 30.12.93
  34.   ■ THelpWindow
  35.      InitHelpViewer eingebaut, um auch Nachfahren von THelpViewer einfach
  36.      einfügen zu können.
  37.      Dazu auch eine Änderung in der DONE-Methode von THelpViewer
  38. 22.12.93
  39.   ■ Seltener Fehler beim Zurücksteppen, wenn kein Link auf Seite
  40.       procedure MakeSelectVisible;
  41.       var D: TPoint;
  42.       begin
  43. **      if (selected=0) or (topic^.crossrefs=nil) then exit;
  44.  
  45.         if (locarray=nil) kap
  46.           then Topic^.GetCrossRef(Selected, KeyPoint, KeyLength, KeyRef)
  47. 18.09.93
  48.   ■ SELECTED im TStackRec (von Byte) auf Word geändert
  49.   ■ MAKEFOCUSVISIBLE Bereichsüberschreitung beim Suchen des Hotkeys
  50.     (while (p<>nil) !!and (count<=topic^.numrefs)!! do begin
  51. 16.09.93
  52.   ■ LASTPARAGRAPH:=NIL; in constructor THelpTopic.Load (Quelle: H.C.F.)
  53.     (Komisch, daß das nicht schon früher gestört hat....)
  54. 19.08.93
  55.   ■ Kontrolle der Streamregistrierung eingebaut. Wenn Hilfsstreams nicht
  56.     registriert, dann reagieren wichtige Objekte im Constructor mit FAIL.
  57. 10.08.93
  58.   ■ Kontrolle der Änderungen vom 8.-9.8.
  59.   ■ Topic link-Jumping eingebaut (MakefocusVisible)
  60. 09.08.93
  61.   ■ Markierung von Schaltflächen dramatisch beschleunigt (Handleevent)
  62.     (alles im Zuge des Deppen-Aufräumens)
  63. 08.08.93
  64.   ■ DRAW-Methode bei vielen Links dramatisch beschleunigt
  65.     (vorher muss ein Depp drangewesen sein...)
  66. 04.08.93
  67.   ■ compressor/decompressor optimiert
  68. 01.08.93
  69.   ■ compressor/decompressor
  70. 22.07.93
  71.   ■ modales Fenster ergänzt um "resizable dialog"
  72. 11.07.93
  73.   ■ Fehler in der thelpviewer.draw methode, wenn farbumschaltung
  74.     ausserhalb des sichtbereiches liegt. es wurde dann übersehen.
  75.     Folge: text war falsch befarbt...
  76. 03.07.93
  77.   ■ Speichern der letzten Menüposition umgestellt
  78. 02.06.93
  79.   ■ Verändertes Mono-Handling
  80. 19.05.93
  81.   ■ Bugfix: Topic-Markierung und Farben in einer Zeile
  82.     Bugfix: Farbmarkierungen und horizontales Scrollen
  83. 11.05.93
  84.   ■ Bugfix: thelpviewer.draw und mehrzeiliger Umbruch farbiger texte
  85. 25.04.93
  86.   ■ Optimisierung bei "countcs" in THelpTopic.WrapText
  87.     (Die Darstellung bei vielen Topics ist immer noch recht träge.)
  88. 21.04.93
  89.   ■ Bugfix: Zeilenumbruch bei langen Paragraphen
  90. 20.04.93
  91.   ■ nicht-modale Hilfe merkt sich die Größe
  92.   ■ geänderte Farbe auch über Zeilenumbrüche hinweg
  93. 19.04.93
  94.   ■ Umbau der THelpViewer.Draw-Methode
  95.     (incl. Änderungen in THelpTopic.WrapText)
  96.     - lock/unlock zur Darstellungsberuhigung
  97.     - zeichenweises Ablegen wg. Farbänderungen
  98.       methode: #n als Code, es ändert sich =nur= der Vordergrund
  99.                ## für #
  100.                #! für Rücksetzen auf Dialogfarbe
  101. 16.04.93
  102.   ■ Alt-F1 focusiert letztes focusiertes topic
  103. 15.04.93
  104.   ■ modales Fenster wird in anderem Farbset dargestellt als nicht-modales
  105.   ■ Alt-F1 für Help-History
  106.   ■ Shift-F1 für Hilfe über Hilfe
  107. 14.04.93
  108.   ■ Unterscheidung zwischen modaler und nicht-modaler Hilfe
  109.  
  110.  
  111. eng.
  112. 22.12.93
  113.   ■ rare error with "last help", if last page has no link
  114.       procedure MakeSelectVisible;
  115.       var D: TPoint;
  116.       begin
  117. **      if (selected=0) or (topic^.crossrefs=nil) then exit;
  118.  
  119.         if (locarray=nil) kap
  120.           then Topic^.GetCrossRef(Selected, KeyPoint, KeyLength, KeyRef)
  121.  
  122. 18.09.93
  123.   ■ SELECTED at TStackRec (from Byte) changed to Word
  124.   ■ MAKEFOCUSVISIBLE range-error when searching the hotkey
  125.     (while (p<>nil) !!and (count<=topic^.numrefs)!! do begin
  126. 16.09.93
  127.   ■ LASTPARAGRAPH:=NIL; at constructor THelpTopic.Load (Quelle: H.C.F.)
  128.     (funny, that this hadn't disturbed earlyer....)
  129. 19.08.93
  130.   ■ check of stream-registration inserted. if stream is not registered,
  131.     importend constructors will FAIL.
  132. 10.08.93
  133.   ■ check of changes from 8.-9.8.
  134.   ■ Topic link-Jumping einserted (MakefocusVisible)
  135. 09.08.93
  136.   ■ dramaticly increase of link-selection (Handleevent)
  137.     (again: tiding up after the fool)
  138. 08.08.93
  139.   ■ DRAW-methode inceased when lot of links are shown
  140.     (must been programed by a fool.....)
  141. 04.08.93
  142.   ■ compressor/decompressor optimized
  143. 01.08.93
  144.   ■ compressor/decompressor
  145. 22.07.93
  146.   ■ added "resizable dialog" to modalar view
  147. 11.07.93
  148.   ■ fixed error inside thelpviewer.draw methode, if colorchange is outside
  149.     the visible range, it was missed then.
  150.     result: text has wrong color...
  151. 03.07.93
  152.   ■ change: storing the last menueposition
  153. 02.06.93
  154.   ■ change: mono-handling
  155. 19.05.93
  156.   ■ Bugfix: link-color and color of a line of text
  157.     Bugfix: color and horizontal scrolling
  158. 11.05.93
  159.   ■ Bugfix: thelpviewer.draw and wrap with more lines
  160. 25.04.93
  161.   ■ optimization: at "countcs" in THelpTopic.WrapText
  162.     (displaying lot of links is ugly slow.)
  163. 21.04.93
  164.   ■ Bugfix: linewrap with long paragraphs
  165. 20.04.93
  166.   ■ non-modal helpview will store its size
  167.   ■ changed color with wrapped lines
  168. 19.04.93
  169.   ■ redesign of THelpViewer.Draw-methode
  170.     (incl. changes in THelpTopic.WrapText)
  171.     - lock/unlock
  172.     - changed to piut-by-char because coloring
  173.       methode: #n for colorcode, only foreground!
  174.                ## für #
  175.                #! für reset to "standardcolor"
  176. 16.04.93
  177.   ■ Alt-F1 for switching back to last topic
  178. 15.04.93
  179.   ■ modale view gets a different color set than non-modal view
  180.   ■ Alt-F1 for help-history
  181.   ■ Shift-F1 for help about help
  182. 14.04.93
  183.   ■ nodal view <-> non-modal view
  184. }
  185.  
  186. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X+,Y-}
  187.  
  188. {$Q-,I-,O- }
  189.  
  190.  
  191. unit HelpFile;
  192.  
  193. interface
  194.  
  195. uses Objects, Drivers, Views;
  196.  
  197. const
  198.   CHelpColor      = {8} #$37#$3F#$3A#$13#$13#$30#$3E#$1E;
  199.   CHelpBlackWhite = {8} #$07#$0F#$07#$70#$70#$07#$0F#$70;
  200.   CHelpMonochrome = {8} #$07#$0F#$07#$70#$70#$07#$0F#$70;
  201.   CHelpViewer     = {3} #6#7#8;
  202.   Chelpwindow     = {8} #16#17#18#19#20#57#21#13;
  203.  
  204.   Cdialogwindow   = {8} #32#33#34#35#36#38#40#13; { die farbe der dialoge }
  205.  
  206. {KAP}
  207.   {
  208.   chelpwindow-felder
  209.    1 ????
  210.    2 rahmen
  211.    3 rahmensymbole [■]
  212.    4 scroller
  213.    5 background, scrollersymbole
  214.    6 textinhalt
  215.    7 nicht focusierter topic
  216.    8 linked topics/reaktionstopic für ENTER
  217.   }
  218.  
  219. (*
  220.   CHelpWindow     = #128#129#130#131#132#133#134#135;
  221. *)
  222.  
  223. {KAP}
  224.   maxhelpback           = 50;
  225.  
  226.   indexpagenumber       : word = 100;
  227.   helpabouthelp         : word = 99;
  228.  
  229.   cmhelplast            = 65001;
  230.   cmhelpindex           = 65002;
  231.  
  232.   lastpos               : trect = (a:(x:-1;y:0);b:(x:50;y:18));
  233.  
  234.   MagicHeader           = $46484246; {'FBHF'}
  235.  
  236. { wenn auch tp60-hf geöffnet werden können sollen ... }
  237. { if it should be possible to old tp60-hf }
  238.   openanyway            : boolean = false;
  239.  
  240. { erlaubt den Hilfsfenster (trotz Dialog-Aussehen) die Größe zu ändern }
  241. { a non-modal help will be resizable, if set to true }
  242.   resizeabledialog      : boolean = false;
  243.  
  244.   ct_store              = $01;
  245.   ct_nibble             = $02;
  246.   ct_lastnibble         = $03;
  247.  
  248.   nc_rawchar            = $0f;
  249.   nc_repchar            = $0e;
  250.  
  251.   comparraysize         = 13;
  252.  
  253.   createcompressedhelp  : boolean = false;
  254.  
  255.   helpversion           = $20;  { helpfile - version 2.0 }
  256.  
  257. Type string80 = string[80];
  258.  
  259. Const
  260.  
  261.   helpdialogtitle       : string80 = 'Help-Dialog';
  262.   helpwindowtitle       : string80 = 'Help';
  263.   nohelpInvalidStr      : string80 = #13' No help for this topic link.';
  264.   emptyhelpInvalidStr   : string80 = #13' This helppage is empty.';
  265.  
  266.   CCConverter           : array[0..15] of byte
  267.                         = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
  268.  
  269.  
  270. type
  271.       pbytearray = ^tbytearray;
  272.       tbytearray = array[0..63*1024] of byte;
  273.  
  274.       pchararray = ^tchararray;
  275.       tchararray = array[0..63*1024] of char;
  276.  
  277. { TParagraph }
  278.  
  279.   PPParagraph = ^pparagraph;
  280.   PParagraph = ^TParagraph;
  281.   TParagraph = record
  282.     Next: PParagraph;
  283.     Wrap: Boolean;
  284.     Size: Word;
  285.     Text: record end;
  286.   end;
  287.  
  288. { THelpTopic }
  289.  
  290.   TCrossRef = record
  291.     Ref: Word;
  292.     Offset: Integer;
  293.     Length: Byte;
  294.   end;
  295.  
  296.   tCompressinfo = record
  297.     comptype  : byte;                 {                           }
  298.     orgsize   : word;                 { orginalgroesse            }
  299.                                       { original size             }
  300.     chartable : array[0..comparraysize] of byte;
  301.                                       { die comparraysize+1 häufigsten codes   }
  302.                                       { the comparraysize+1 most used codes}
  303.   end;
  304.  
  305.  
  306.   plocarray  = ^tlocarray;
  307.   tlocarray  = array[1..1000] of tpoint;
  308.  
  309.   PCrossRefs = ^TCrossRefs;
  310.   TCrossRefs = array[1..10000] of TCrossRef;
  311.   TCrossRefHandler = procedure (var S: TStream; XRefValue: Integer);
  312.  
  313.   PHelpTopic = ^THelpTopic;
  314.   THelpTopic = object(TObject)
  315. { private}
  316.     Paragraphs    : PParagraph;
  317.     NumRefs       : Integer;
  318.     CrossRefs     : PCrossRefs;
  319.     Width         : Integer;
  320.     LastOffset    : Integer;
  321.     LastLine      : Integer;
  322.     LastParagraph : PParagraph;
  323. { public }
  324.     constructor   Init;
  325.     constructor   Load(var S: TStream);
  326.     destructor    Done; virtual;
  327.  
  328.     procedure     initstatistic    (var compheader : tcompressinfo;     p : pParagraph);
  329.     function      Paragraphcompress(var compheader : tcompressinfo;     p : PPParagraph):word;
  330.     procedure     Paragraphexpand  (var compheader : tcompressinfo; var p : ppparagraph);
  331.  
  332.     procedure     AddCrossRef(Ref: TCrossRef);
  333.     procedure     AddParagraph(P: PParagraph);
  334.  
  335.     procedure     GetCrossRef(I: Integer; var Loc: TPoint; var Length: Byte; var Ref: Word);
  336.     procedure     GetallCrossRef(locarray : plocarray; maxline : integer);
  337.  
  338.     function      GetLine(Line: Integer): String;
  339.     function      GetNumCrossRefs: Integer;
  340.     function      NumLines: Integer;
  341.     procedure     SetCrossRef(I: Integer; var Ref: TCrossRef);
  342.     procedure     SetNumCrossRefs(I: Integer);
  343.     procedure     SetWidth(AWidth: Integer);
  344.     procedure     Store(var S: TStream);
  345. { private }
  346.     function WrapText(var Text; Size: Integer; var Offset: Integer;
  347.       Wrap: Boolean): String;
  348.   end;
  349.  
  350. { THelpIndex }
  351.  
  352.   PIndexArray = ^TIndexArray;
  353.   TIndexArray = array[0..16380] of LongInt;
  354.  
  355.   PContextArray = ^TContextArray;
  356.   TContextArray = array[0..16380] of Word;
  357.  
  358.   PHelpIndex = ^THelpIndex;
  359.   THelpIndex = object(TObject)
  360.     Contexts  : PContextArray;
  361.     Index     : PIndexArray;
  362. { private }
  363.     Size      : Word;
  364.     Used      : Word;
  365. { public }
  366.     constructor Init;
  367.     constructor Load(var S: TStream);
  368.     destructor  Done; virtual;
  369.     function    Position(I: Word): Longint;
  370.     procedure   Add(I: Word; Val: Longint);
  371.     procedure   Store(var S: TStream);
  372. { private }
  373.     function    Find(I: Word):longint;
  374.   end;
  375.  
  376. { THelpFile }
  377.  
  378.   PHelpFile = ^THelpFile;
  379.   THelpFile = object(TObject)
  380.     Stream     : PStream;
  381.     Modified   : Boolean;
  382. {KAP}
  383.     invaltopic : boolean;
  384. { private}
  385.     Index      : PHelpIndex;
  386.     IndexPos   : LongInt;
  387. { public }
  388.     constructor Init(S: PStream);
  389.     destructor  Done; virtual;
  390.     function    GetTopic(I: Word): PHelpTopic;
  391.     function    InvalidTopic: PHelpTopic;
  392.     function    emptyTopic: PHelpTopic;
  393.     procedure   RecordPositionInIndex(I: word);
  394.     procedure   PutTopic(Topic: PHelpTopic);
  395.   end;
  396.  
  397. {KAP}
  398.   TStackrec = record
  399.     helpctx  : word;
  400.     selected : word;
  401.   end;
  402.  
  403.   pstackarray = ^tstackarray;
  404.   tstackarray = array[1..maxhelpback] of TStackrec;
  405.  
  406. { THelpViewer }
  407.   PHelpViewer = ^THelpViewer;
  408.   THelpViewer = object(TScroller)
  409.     HFile         : PHelpFile;
  410.     Topic         : PHelpTopic;
  411.     stack         : pstackarray;
  412.     Selected      : Integer;
  413.  
  414.     oldsize       : byte;
  415.     locarray      : plocarray;
  416.     locarraysize  : word;
  417.     keyfocus      : pstring;
  418.     constructor Init(var Bounds       : TRect;
  419.                          AHScrollBar,
  420.                          AVScrollBar  : PScrollBar;
  421.                          AHelpFile    : PHelpFile;
  422.                          Context      : Word);
  423.     destructor Done; virtual;
  424.     procedure  ChangeBounds(var Bounds: TRect); virtual;
  425.     procedure  Draw; virtual;
  426.     function   GetPalette: PPalette; virtual;
  427.     procedure  HandleEvent(var Event: TEvent); virtual;
  428.     procedure  SwitchToTopic(KeyRef: word);
  429.  
  430.     procedure  invalidatelocarray;
  431.  
  432.     procedure  Popstack(var keyword : word);
  433.     procedure  Pushstack(keyword : word);
  434.     procedure  SwitchTooldTopic(Var keyref : word);
  435.   end;
  436.  
  437. { THelpWindow }
  438.   PHelpWindow = ^THelpWindow;
  439.   THelpWindow = object(TWindow)
  440.     phv      : phelpviewer;
  441.     ismodal  : boolean;
  442.     constructor Init(HFile: PHelpFile; Context: Word; aismodal : boolean);
  443.     function    GetPalette: PPalette; virtual;
  444.     procedure   InitHelpviewer(HFile: PHelpFile; Context: Word);
  445.     destructor  done; virtual;
  446.   end;
  447.  
  448. Var
  449.   originalsize, compresssize  : longint;
  450.  
  451.  
  452. const
  453.   RHelpTopic: TStreamRec = (
  454.      ObjType: 10000;
  455.      VmtLink: Ofs(TypeOf(THelpTopic)^);
  456.      Load:    @THelpTopic.Load;
  457.      Store:   @THelpTopic.Store
  458.   );
  459.  
  460. const
  461.   RHelpIndex: TStreamRec = (
  462.      ObjType: 10001;
  463.      VmtLink: Ofs(TypeOf(THelpIndex)^);
  464.      Load:    @THelpIndex.Load;
  465.      Store:   @THelpIndex.Store
  466.   );
  467.  
  468. procedure RegisterHelpFile;
  469.  
  470. procedure NotAssigned(var S: TStream; Value: Integer);
  471.  
  472. const     CrossRefHandler: TCrossRefHandler = NotAssigned;
  473.  
  474. implementation
  475.  
  476. {............................................................}
  477.  
  478. end.
  479.