| 1 | Unit NavigatePointUnit;
 | 
|---|
| 2 | 
 | 
|---|
| 3 | // NewView - a new OS/2 Help Viewer
 | 
|---|
| 4 | // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
 | 
|---|
| 5 | // This software is released under the Gnu Public License - see readme.txt
 | 
|---|
| 6 | 
 | 
|---|
| 7 | Interface
 | 
|---|
| 8 | 
 | 
|---|
| 9 | uses
 | 
|---|
| 10 |   Classes,
 | 
|---|
| 11 |   HelpFile, HelpTopic, HelpWindowDimensions, HelpWindowUnit;
 | 
|---|
| 12 | 
 | 
|---|
| 13 | type
 | 
|---|
| 14 |   // Navigate point: a saved history position specifiying
 | 
|---|
| 15 |   // a set of windows that were displayed.
 | 
|---|
| 16 |   TNavigatePoint = class
 | 
|---|
| 17 |     ContentsTopic: TTopic;
 | 
|---|
| 18 |     Windows: TList;
 | 
|---|
| 19 |     constructor Create;
 | 
|---|
| 20 |     destructor Destroy; Override;
 | 
|---|
| 21 |     procedure Save( Var F: TextFile );
 | 
|---|
| 22 |     constructor Load( Var F: TextFile; HelpFile: THelpFile );
 | 
|---|
| 23 |   end;
 | 
|---|
| 24 | 
 | 
|---|
| 25 |   // A help window definition as saved in a navigate point
 | 
|---|
| 26 |   TSavedHelpWindow = class
 | 
|---|
| 27 |     Topic: TTopic;
 | 
|---|
| 28 |     Group: longint;
 | 
|---|
| 29 | 
 | 
|---|
| 30 |     ChildWindows: TList;
 | 
|---|
| 31 |     Parent: TSavedHelpWindow;
 | 
|---|
| 32 | 
 | 
|---|
| 33 |     Rect: THelpWindowRect;
 | 
|---|
| 34 | 
 | 
|---|
| 35 |     TopCharIndex: longint; // used when saving for navigation
 | 
|---|
| 36 | 
 | 
|---|
| 37 |     constructor Create;
 | 
|---|
| 38 |     destructor Destroy; override;
 | 
|---|
| 39 |     procedure Save( Var F: TextFile; Prefix: string; );
 | 
|---|
| 40 |     constructor Load( Var F: TextFile; HelpFile: THelpFile );
 | 
|---|
| 41 |   end;
 | 
|---|
| 42 | 
 | 
|---|
| 43 | Implementation
 | 
|---|
| 44 | 
 | 
|---|
| 45 | uses
 | 
|---|
| 46 |   SysUtils,
 | 
|---|
| 47 |   ACLUtility, ACLStringUtility;
 | 
|---|
| 48 | 
 | 
|---|
| 49 | procedure SaveWindowList( Var F: TextFile;
 | 
|---|
| 50 |                           Windows: TList;
 | 
|---|
| 51 |                           Prefix: string );
 | 
|---|
| 52 | var
 | 
|---|
| 53 |   i: integer;
 | 
|---|
| 54 |   Window: TSavedHelpWindow;
 | 
|---|
| 55 |   S: string;
 | 
|---|
| 56 | begin
 | 
|---|
| 57 |   S := Prefix + IntToStr( Windows.Count );
 | 
|---|
| 58 |   WriteLn( F, S );
 | 
|---|
| 59 |   for i := 0 to Windows.Count - 1 do
 | 
|---|
| 60 |   begin
 | 
|---|
| 61 |     Window := Windows[ i ];
 | 
|---|
| 62 |     Window.Save( F, Prefix + ' ' );
 | 
|---|
| 63 |   end;
 | 
|---|
| 64 | end;
 | 
|---|
| 65 | 
 | 
|---|
| 66 | procedure LoadWindowList( Var F: TextFile;
 | 
|---|
| 67 |                           Windows: TList;
 | 
|---|
| 68 |                           HelpFile: THelpFile );
 | 
|---|
| 69 | var
 | 
|---|
| 70 |   i: integer;
 | 
|---|
| 71 |   Window: TSavedHelpWindow;
 | 
|---|
| 72 |   WindowCount: integer;
 | 
|---|
| 73 |   S: string;
 | 
|---|
| 74 | begin
 | 
|---|
| 75 |   ReadLn( F, S );
 | 
|---|
| 76 |   try
 | 
|---|
| 77 |     WindowCount := StrToInt( S );
 | 
|---|
| 78 |   except
 | 
|---|
| 79 |     WindowCount := 0;
 | 
|---|
| 80 |   end;
 | 
|---|
| 81 |   for i := 0 to WindowCount - 1 do
 | 
|---|
| 82 |   begin
 | 
|---|
| 83 |     Window := TSavedHelpWindow.Load( F, HelpFile );
 | 
|---|
| 84 |     Windows.Add( Window );
 | 
|---|
| 85 |   end;
 | 
|---|
| 86 | end;
 | 
|---|
| 87 | 
 | 
|---|
| 88 | // --- TNavigatePoint ---------------------------------
 | 
|---|
| 89 | 
 | 
|---|
| 90 | constructor TNavigatePoint.Create;
 | 
|---|
| 91 | begin
 | 
|---|
| 92 |   inherited Create;
 | 
|---|
| 93 |   ContentsTopic:= nil;
 | 
|---|
| 94 |   Windows:= TList.Create;
 | 
|---|
| 95 | end;
 | 
|---|
| 96 | 
 | 
|---|
| 97 | destructor TNavigatePoint.Destroy;
 | 
|---|
| 98 | begin
 | 
|---|
| 99 |   inherited Destroy;
 | 
|---|
| 100 |   DestroyListObjects( Windows );
 | 
|---|
| 101 |   Windows.Destroy;
 | 
|---|
| 102 | end;
 | 
|---|
| 103 | 
 | 
|---|
| 104 | procedure TNavigatePoint.Save( Var F: TextFile );
 | 
|---|
| 105 | begin
 | 
|---|
| 106 |   WriteLn( F, IntToStr( ContentsTopic.Index ) );
 | 
|---|
| 107 |   SaveWindowList( F, Windows, '' );
 | 
|---|
| 108 | end;
 | 
|---|
| 109 | 
 | 
|---|
| 110 | constructor TNavigatePoint.Load( Var F: Text;
 | 
|---|
| 111 |                                  HelpFile: THelpFile );
 | 
|---|
| 112 | Var
 | 
|---|
| 113 |   s: string;
 | 
|---|
| 114 |   ContentsTopicIndex: integer;
 | 
|---|
| 115 | begin
 | 
|---|
| 116 |   inherited Create;
 | 
|---|
| 117 |   ReadLn( F, S );
 | 
|---|
| 118 |   ContentsTopicIndex := StrToInt( S );
 | 
|---|
| 119 |   ContentsTopic:= HelpFile.Topics[ ContentsTopicIndex ];
 | 
|---|
| 120 | 
 | 
|---|
| 121 |   Windows:= TList.Create;
 | 
|---|
| 122 |   LoadWindowList( F, Windows, HelpFile );
 | 
|---|
| 123 | end;
 | 
|---|
| 124 | 
 | 
|---|
| 125 | // --- TSavedHelpWindow ---------------------------------
 | 
|---|
| 126 | 
 | 
|---|
| 127 | constructor TSavedHelpWindow.Create;
 | 
|---|
| 128 | begin
 | 
|---|
| 129 |   inherited Create;
 | 
|---|
| 130 |   ChildWindows:= TList.Create;
 | 
|---|
| 131 |   Rect:= THelpWindowRect.Create;
 | 
|---|
| 132 | end;
 | 
|---|
| 133 | 
 | 
|---|
| 134 | destructor TSavedHelpWindow.Destroy;
 | 
|---|
| 135 | begin
 | 
|---|
| 136 |   DestroyListObjects( ChildWindows );
 | 
|---|
| 137 |   ChildWindows.Destroy;
 | 
|---|
| 138 |   Rect.Destroy;
 | 
|---|
| 139 |   inherited Destroy;
 | 
|---|
| 140 | end;
 | 
|---|
| 141 | 
 | 
|---|
| 142 | procedure TSavedHelpWindow.Save( Var F: TextFile;
 | 
|---|
| 143 |                                  Prefix: string );
 | 
|---|
| 144 | begin
 | 
|---|
| 145 |   WriteLn( F,
 | 
|---|
| 146 |            Prefix
 | 
|---|
| 147 |            + IntToStr( Topic.Index )
 | 
|---|
| 148 |            + ', '
 | 
|---|
| 149 |            + IntToStr( Group )
 | 
|---|
| 150 |            + ', '
 | 
|---|
| 151 |            + IntToStr( Rect.Left )
 | 
|---|
| 152 |            + ', '
 | 
|---|
| 153 |            + IntToStr( Rect.Bottom )
 | 
|---|
| 154 |            + ', '
 | 
|---|
| 155 |            + IntToStr( Rect.Width )
 | 
|---|
| 156 |            + ', '
 | 
|---|
| 157 |            + IntToStr( Rect.Height )
 | 
|---|
| 158 |            + ', '
 | 
|---|
| 159 |            + IntToStr( TopCharIndex )
 | 
|---|
| 160 |          );
 | 
|---|
| 161 |   SaveWindowList( F, ChildWindows, Prefix );
 | 
|---|
| 162 | end;
 | 
|---|
| 163 | 
 | 
|---|
| 164 | constructor TSavedHelpWindow.Load( Var F: TextFile );
 | 
|---|
| 165 | var
 | 
|---|
| 166 |   s: string;
 | 
|---|
| 167 |   TopicIndex: integer;
 | 
|---|
| 168 | begin
 | 
|---|
| 169 |   inherited Create;
 | 
|---|
| 170 |   ChildWindows:= TList.Create;
 | 
|---|
| 171 |   Rect:= THelpWindowRect.Create;
 | 
|---|
| 172 | 
 | 
|---|
| 173 |   ReadLn( F, S );
 | 
|---|
| 174 | 
 | 
|---|
| 175 |   TopicIndex   := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 176 |   Topic := HelpFile.Topics[ TopicIndex ];
 | 
|---|
| 177 |   Group        := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 178 |   Rect.Left    := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 179 |   Rect.Bottom  := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 180 |   Rect.Width   := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 181 |   Rect.Height  := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 182 |   TopCharIndex := StrToInt( ExtractNextValue( S, ',' ) );
 | 
|---|
| 183 | 
 | 
|---|
| 184 |   LoadWindowList( F, ChildWindows, HelpFile );
 | 
|---|
| 185 | end;
 | 
|---|
| 186 | 
 | 
|---|
| 187 | Initialization
 | 
|---|
| 188 | End.
 | 
|---|