| 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 | StringUtilsUnit, | 
|---|
| 51 | DebugUnit; | 
|---|
| 52 |  | 
|---|
| 53 | procedure SaveWindowList( Var F: TextFile; | 
|---|
| 54 | Windows: TList; | 
|---|
| 55 | Prefix: string ); | 
|---|
| 56 | var | 
|---|
| 57 | i: integer; | 
|---|
| 58 | Window: TSavedHelpWindow; | 
|---|
| 59 | S: string; | 
|---|
| 60 | begin | 
|---|
| 61 | S := Prefix + IntToStr( Windows.Count ); | 
|---|
| 62 | WriteLn( F, S ); | 
|---|
| 63 | for i := 0 to Windows.Count - 1 do | 
|---|
| 64 | begin | 
|---|
| 65 | Window := Windows[ i ]; | 
|---|
| 66 | Window.Save( F, Prefix + ' ' ); | 
|---|
| 67 | end; | 
|---|
| 68 | end; | 
|---|
| 69 |  | 
|---|
| 70 | procedure LoadWindowList( Var F: TextFile; | 
|---|
| 71 | Windows: TList; | 
|---|
| 72 | HelpFile: THelpFile ); | 
|---|
| 73 | var | 
|---|
| 74 | i: integer; | 
|---|
| 75 | Window: TSavedHelpWindow; | 
|---|
| 76 | WindowCount: integer; | 
|---|
| 77 | S: string; | 
|---|
| 78 | begin | 
|---|
| 79 | ReadLn( F, S ); | 
|---|
| 80 | try | 
|---|
| 81 | WindowCount := StrToInt( S ); | 
|---|
| 82 | except | 
|---|
| 83 | WindowCount := 0; | 
|---|
| 84 | end; | 
|---|
| 85 | for i := 0 to WindowCount - 1 do | 
|---|
| 86 | begin | 
|---|
| 87 | Window := TSavedHelpWindow.Load( F, HelpFile ); | 
|---|
| 88 | Windows.Add( Window ); | 
|---|
| 89 | end; | 
|---|
| 90 | end; | 
|---|
| 91 |  | 
|---|
| 92 | // --- TNavigatePoint --------------------------------- | 
|---|
| 93 |  | 
|---|
| 94 | constructor TNavigatePoint.Create; | 
|---|
| 95 | begin | 
|---|
| 96 | inherited Create; | 
|---|
| 97 | ContentsTopic:= nil; | 
|---|
| 98 | Windows:= TList.Create; | 
|---|
| 99 | end; | 
|---|
| 100 |  | 
|---|
| 101 | destructor TNavigatePoint.Destroy; | 
|---|
| 102 | begin | 
|---|
| 103 | inherited Destroy; | 
|---|
| 104 | DestroyListObjects( Windows ); | 
|---|
| 105 | Windows.Destroy; | 
|---|
| 106 | end; | 
|---|
| 107 |  | 
|---|
| 108 | procedure TNavigatePoint.Save( Var F: TextFile ); | 
|---|
| 109 | begin | 
|---|
| 110 | WriteLn( F, IntToStr( ContentsTopic.Index ) ); | 
|---|
| 111 | SaveWindowList( F, Windows, '' ); | 
|---|
| 112 | end; | 
|---|
| 113 |  | 
|---|
| 114 | constructor TNavigatePoint.Load( Var F: Text; | 
|---|
| 115 | HelpFile: THelpFile ); | 
|---|
| 116 | Var | 
|---|
| 117 | s: string; | 
|---|
| 118 | ContentsTopicIndex: integer; | 
|---|
| 119 | begin | 
|---|
| 120 | inherited Create; | 
|---|
| 121 | ReadLn( F, S ); | 
|---|
| 122 | ContentsTopicIndex := StrToInt( S ); | 
|---|
| 123 | ContentsTopic:= HelpFile.Topics[ ContentsTopicIndex ]; | 
|---|
| 124 |  | 
|---|
| 125 | Windows:= TList.Create; | 
|---|
| 126 | LoadWindowList( F, Windows, HelpFile ); | 
|---|
| 127 | end; | 
|---|
| 128 |  | 
|---|
| 129 | // --- TSavedHelpWindow --------------------------------- | 
|---|
| 130 |  | 
|---|
| 131 | constructor TSavedHelpWindow.Create; | 
|---|
| 132 | begin | 
|---|
| 133 | inherited Create; | 
|---|
| 134 | ChildWindows:= TList.Create; | 
|---|
| 135 | Rect:= THelpWindowRect.Create; | 
|---|
| 136 | end; | 
|---|
| 137 |  | 
|---|
| 138 | destructor TSavedHelpWindow.Destroy; | 
|---|
| 139 | begin | 
|---|
| 140 | DestroyListObjects( ChildWindows ); | 
|---|
| 141 | ChildWindows.Destroy; | 
|---|
| 142 | Rect.Destroy; | 
|---|
| 143 | inherited Destroy; | 
|---|
| 144 | end; | 
|---|
| 145 |  | 
|---|
| 146 | procedure TSavedHelpWindow.Save( Var F: TextFile; | 
|---|
| 147 | Prefix: string ); | 
|---|
| 148 | begin | 
|---|
| 149 | WriteLn( F, | 
|---|
| 150 | Prefix | 
|---|
| 151 | + IntToStr( Topic.Index ) | 
|---|
| 152 | + ', ' | 
|---|
| 153 | + IntToStr( Group ) | 
|---|
| 154 | + ', ' | 
|---|
| 155 | + IntToStr( Rect.Left ) | 
|---|
| 156 | + ', ' | 
|---|
| 157 | + IntToStr( Rect.Bottom ) | 
|---|
| 158 | + ', ' | 
|---|
| 159 | + IntToStr( Rect.Width ) | 
|---|
| 160 | + ', ' | 
|---|
| 161 | + IntToStr( Rect.Height ) | 
|---|
| 162 | + ', ' | 
|---|
| 163 | + IntToStr( TopCharIndex ) | 
|---|
| 164 | ); | 
|---|
| 165 | SaveWindowList( F, ChildWindows, Prefix ); | 
|---|
| 166 | end; | 
|---|
| 167 |  | 
|---|
| 168 | constructor TSavedHelpWindow.Load( Var F: TextFile ); | 
|---|
| 169 | var | 
|---|
| 170 | tmpString : string; | 
|---|
| 171 | TopicIndex: integer; | 
|---|
| 172 | tmpParts : TStringList; | 
|---|
| 173 | begin | 
|---|
| 174 | inherited Create; | 
|---|
| 175 | ChildWindows:= TList.Create; | 
|---|
| 176 | Rect:= THelpWindowRect.Create; | 
|---|
| 177 |  | 
|---|
| 178 | ReadLn( F, tmpString); | 
|---|
| 179 | tmpParts := TStringList.Create; | 
|---|
| 180 | StrExtractStrings(tmpParts, tmpString, [','], #0); | 
|---|
| 181 |  | 
|---|
| 182 | TopicIndex   := StrToInt(tmpParts[0]); | 
|---|
| 183 | Topic := HelpFile.Topics[ TopicIndex ]; | 
|---|
| 184 | Group        := StrToInt(tmpParts[1]); | 
|---|
| 185 | Rect.Left    := StrToInt(tmpParts[2]); | 
|---|
| 186 | Rect.Bottom  := StrToInt(tmpParts[3]); | 
|---|
| 187 | Rect.Width   := StrToInt(tmpParts[4]); | 
|---|
| 188 | Rect.Height  := StrToInt(tmpParts[5]); | 
|---|
| 189 | TopCharIndex := StrToInt(tmpParts[6]); | 
|---|
| 190 |  | 
|---|
| 191 | tmpParts.Destroy; | 
|---|
| 192 |  | 
|---|
| 193 | LoadWindowList( F, ChildWindows, HelpFile ); | 
|---|
| 194 | end; | 
|---|
| 195 |  | 
|---|
| 196 | Initialization | 
|---|
| 197 | End. | 
|---|