source: trunk/NewView/NavigatePointUnit.pas@ 18

Last change on this file since 18 was 18, checked in by RBRi, 19 years ago

+ newview source

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1Unit 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
7Interface
8
9uses
10 Classes,
11 HelpFile, HelpTopic, HelpWindowDimensions, HelpWindowUnit;
12
13type
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
43Implementation
44
45uses
46 SysUtils,
47 ACLUtility, ACLStringUtility;
48
49procedure SaveWindowList( Var F: TextFile;
50 Windows: TList;
51 Prefix: string );
52var
53 i: integer;
54 Window: TSavedHelpWindow;
55 S: string;
56begin
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;
64end;
65
66procedure LoadWindowList( Var F: TextFile;
67 Windows: TList;
68 HelpFile: THelpFile );
69var
70 i: integer;
71 Window: TSavedHelpWindow;
72 WindowCount: integer;
73 S: string;
74begin
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;
86end;
87
88// --- TNavigatePoint ---------------------------------
89
90constructor TNavigatePoint.Create;
91begin
92 inherited Create;
93 ContentsTopic:= nil;
94 Windows:= TList.Create;
95end;
96
97destructor TNavigatePoint.Destroy;
98begin
99 inherited Destroy;
100 DestroyListObjects( Windows );
101 Windows.Destroy;
102end;
103
104procedure TNavigatePoint.Save( Var F: TextFile );
105begin
106 WriteLn( F, IntToStr( ContentsTopic.Index ) );
107 SaveWindowList( F, Windows, '' );
108end;
109
110constructor TNavigatePoint.Load( Var F: Text;
111 HelpFile: THelpFile );
112Var
113 s: string;
114 ContentsTopicIndex: integer;
115begin
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 );
123end;
124
125// --- TSavedHelpWindow ---------------------------------
126
127constructor TSavedHelpWindow.Create;
128begin
129 inherited Create;
130 ChildWindows:= TList.Create;
131 Rect:= THelpWindowRect.Create;
132end;
133
134destructor TSavedHelpWindow.Destroy;
135begin
136 DestroyListObjects( ChildWindows );
137 ChildWindows.Destroy;
138 Rect.Destroy;
139 inherited Destroy;
140end;
141
142procedure TSavedHelpWindow.Save( Var F: TextFile;
143 Prefix: string );
144begin
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 );
162end;
163
164constructor TSavedHelpWindow.Load( Var F: TextFile );
165var
166 s: string;
167 TopicIndex: integer;
168begin
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 );
185end;
186
187Initialization
188End.
Note: See TracBrowser for help on using the repository browser.