source: branches/2.19_branch/NewView/NavigatePointUnit.pas@ 292

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

%more stringutils refactoring

  • Property svn:eol-style set to native
File size: 4.4 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,
12 HelpTopic,
13 HelpWindowDimensions;
14
15type
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
45Implementation
46
47uses
48 SysUtils,
49 ACLUtility,
50 StringUtilsUnit,
51 DebugUnit;
52
53procedure SaveWindowList( Var F: TextFile;
54 Windows: TList;
55 Prefix: string );
56var
57 i: integer;
58 Window: TSavedHelpWindow;
59 S: string;
60begin
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;
68end;
69
70procedure LoadWindowList( Var F: TextFile;
71 Windows: TList;
72 HelpFile: THelpFile );
73var
74 i: integer;
75 Window: TSavedHelpWindow;
76 WindowCount: integer;
77 S: string;
78begin
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;
90end;
91
92// --- TNavigatePoint ---------------------------------
93
94constructor TNavigatePoint.Create;
95begin
96 inherited Create;
97 ContentsTopic:= nil;
98 Windows:= TList.Create;
99end;
100
101destructor TNavigatePoint.Destroy;
102begin
103 inherited Destroy;
104 DestroyListObjects( Windows );
105 Windows.Destroy;
106end;
107
108procedure TNavigatePoint.Save( Var F: TextFile );
109begin
110 WriteLn( F, IntToStr( ContentsTopic.Index ) );
111 SaveWindowList( F, Windows, '' );
112end;
113
114constructor TNavigatePoint.Load( Var F: Text;
115 HelpFile: THelpFile );
116Var
117 s: string;
118 ContentsTopicIndex: integer;
119begin
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 );
127end;
128
129// --- TSavedHelpWindow ---------------------------------
130
131constructor TSavedHelpWindow.Create;
132begin
133 inherited Create;
134 ChildWindows:= TList.Create;
135 Rect:= THelpWindowRect.Create;
136end;
137
138destructor TSavedHelpWindow.Destroy;
139begin
140 DestroyListObjects( ChildWindows );
141 ChildWindows.Destroy;
142 Rect.Destroy;
143 inherited Destroy;
144end;
145
146procedure TSavedHelpWindow.Save( Var F: TextFile;
147 Prefix: string );
148begin
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 );
166end;
167
168constructor TSavedHelpWindow.Load( Var F: TextFile );
169var
170 tmpString : string;
171 TopicIndex: integer;
172 tmpParts : TStringList;
173begin
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 );
194end;
195
196Initialization
197End.
Note: See TracBrowser for help on using the repository browser.