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