1 | Program ViewStub;
|
---|
2 |
|
---|
3 | // Small stub program that uses the GlobalFilelist to decide
|
---|
4 | // whether to launch a new instance of newview.exe, or activate
|
---|
5 | // an existing one.
|
---|
6 |
|
---|
7 | // Becomes view.exe.
|
---|
8 |
|
---|
9 | Uses
|
---|
10 | OS2def,
|
---|
11 | PMShl,
|
---|
12 | PmWin,
|
---|
13 | SysUtils,
|
---|
14 | Classes,
|
---|
15 | DebugUnit,
|
---|
16 | GlobalFilelistUnit,
|
---|
17 | CmdLineParameterUnit,
|
---|
18 | HelpManagerUnit,
|
---|
19 | StringUtilsUnit,
|
---|
20 | StartupUnit;
|
---|
21 |
|
---|
22 | var
|
---|
23 | Details: PROGDETAILS;
|
---|
24 | Parameters: pchar;
|
---|
25 |
|
---|
26 | Const
|
---|
27 | Vendor = 'Aaron Lawrence, Ronald Brill';
|
---|
28 | BldLevelVersion = '1.1.2';
|
---|
29 | Description = 'NewView Stub';
|
---|
30 |
|
---|
31 | // BLDLevel - compatible - mostly
|
---|
32 | EmbeddedVersion: string =
|
---|
33 | '@#'
|
---|
34 | + Vendor
|
---|
35 | + ':'
|
---|
36 | + BldLevelVersion
|
---|
37 | + '#@'
|
---|
38 | + Description
|
---|
39 | + #0;
|
---|
40 |
|
---|
41 | imports
|
---|
42 | // Alternative declaration of WinStartApp with a more useful type for pszParams
|
---|
43 | FUNCTION _WinStartApp(hwndNotify:HWND;VAR pDetails:PROGDETAILS;pszParams:pchar;
|
---|
44 | Reserved:POINTER;fbOptions:ULONG):HAPP;
|
---|
45 | APIENTRY; 'PMSHAPI' index 119;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | var
|
---|
49 | tmpCmdLine : String;
|
---|
50 | tmpPCharCmdLine : PChar;
|
---|
51 | tmpCmdLineParameters: TCmdLineParameters;
|
---|
52 | tmpExistingWindow: HWND;
|
---|
53 |
|
---|
54 |
|
---|
55 | // If another instance already has the files open
|
---|
56 | // activate it and return true.
|
---|
57 | Function FindExistingWindow(aCmdLineParameters : TCmdLineParameters) : HWND;
|
---|
58 | var
|
---|
59 | tmpFileItems: TStringList;
|
---|
60 | tmpFilenames: TStringList;
|
---|
61 | tmpFullFilePath: string;
|
---|
62 | i: longint;
|
---|
63 |
|
---|
64 | FileWindow: HWND;
|
---|
65 | begin
|
---|
66 | result := NULLHANDLE;
|
---|
67 |
|
---|
68 | if aCmdLineParameters.getFileNames(false) = '' then
|
---|
69 | // not loading files; nothing to check
|
---|
70 | exit;
|
---|
71 |
|
---|
72 | tmpFileItems := TStringList.Create;
|
---|
73 | tmpFilenames := TStringList.Create;
|
---|
74 |
|
---|
75 | StrExtractStrings(tmpFileItems, aCmdLineParameters.getFileNames(false), [HELP_FILE_DELIMITER], #0);
|
---|
76 | TranslateIPFEnvironmentVars(tmpFileItems, tmpFileNames );
|
---|
77 |
|
---|
78 | for i := 0 to tmpFileNames.Count - 1 do
|
---|
79 | begin
|
---|
80 | tmpFullFilePath := FindHelpFile( tmpFilenames[ i ] );
|
---|
81 | if tmpFullFilePath <> '' then
|
---|
82 | begin
|
---|
83 | FileWindow := GlobalFilelist.FindFile(tmpFullFilePath);
|
---|
84 |
|
---|
85 | if FileWindow = NULLHANDLE then
|
---|
86 | begin
|
---|
87 | // not found - stop searching.
|
---|
88 | Result := NULLHANDLE; // no match
|
---|
89 | break;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | // found it
|
---|
93 |
|
---|
94 | // is it the same as any previous match?
|
---|
95 | if Result <> NULLHANDLE then
|
---|
96 | begin
|
---|
97 | if FileWindow <> Result then
|
---|
98 | begin
|
---|
99 | // no, so we don't have a match.
|
---|
100 | // NOTE: We just excluded something: if the same file is
|
---|
101 | // open in multiple windows then we may not check all combinations
|
---|
102 | Result := NULLHANDLE; // no match
|
---|
103 | break;
|
---|
104 | end;
|
---|
105 | end
|
---|
106 | else
|
---|
107 | begin
|
---|
108 | // no match yet - store this one
|
---|
109 | result := FileWindow;
|
---|
110 | end;
|
---|
111 | end;
|
---|
112 | end;
|
---|
113 |
|
---|
114 | tmpFilenames.Destroy;
|
---|
115 | tmpFileItems.Destroy;
|
---|
116 | end;
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | Begin
|
---|
121 | LogEvent(LogViewStub, 'Starting' );
|
---|
122 |
|
---|
123 | // open shared memory
|
---|
124 | SharedMemory := AccessSharedMemory;
|
---|
125 |
|
---|
126 | // get access to the system-global filelist
|
---|
127 | GlobalFilelist := TGlobalFilelist.Create;
|
---|
128 |
|
---|
129 | // parse parameters into Parameters object
|
---|
130 | tmpCmdLine := nativeOS2GetCmdLineParameter;
|
---|
131 |
|
---|
132 | tmpCmdLineParameters := TCmdLineParameters.Create;
|
---|
133 | tmpCmdLineParameters.parseCmdLine(tmpCmdLine);
|
---|
134 |
|
---|
135 | tmpExistingWindow := FindExistingWindow(tmpCmdLineParameters);
|
---|
136 |
|
---|
137 | if tmpExistingWindow = NULLHANDLE then
|
---|
138 | begin
|
---|
139 | // Want a new instance.
|
---|
140 | LogEvent(LogViewStub, 'Starting a new NewView instance');
|
---|
141 |
|
---|
142 | tmpPCharCmdLine := StrAlloc(length(tmpCmdLine) + 1);
|
---|
143 | StrPCopy(tmpPCharCmdLine, tmpCmdLine);
|
---|
144 |
|
---|
145 | LogEvent(LogViewStub, 'CmdLine for NewView exe: ' + tmpCmdLine);
|
---|
146 | // set up details for launching newview
|
---|
147 | With Details do
|
---|
148 | begin
|
---|
149 | Length := Sizeof( Details );
|
---|
150 | progt.progc := PROG_PM;
|
---|
151 | progt.fbVisible := SHE_VISIBLE;
|
---|
152 | pszTitle := 'Help Viewer';
|
---|
153 | pszExecutable := 'newview.exe';
|
---|
154 | pszParameters := nil; // Parameters; // copy our parameters
|
---|
155 | pszStartupDir := ''; // current dir
|
---|
156 | pszIcon := nil; // default
|
---|
157 | pszEnvironment := nil; // default
|
---|
158 | swpInitial.fl := SWP_ACTIVATE;
|
---|
159 | swpInitial.hwndInsertBehind := HWND_TOP;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | _WinStartApp( NULLHANDLE, // no notify window
|
---|
163 | Details,
|
---|
164 | tmpPCharCmdLine, // use these rather than Details parameters,
|
---|
165 | // cause PM was swallowing /? the other way!!
|
---|
166 | nil, // reserved
|
---|
167 | 0 );
|
---|
168 |
|
---|
169 | StrDispose(tmpPCharCmdLine);
|
---|
170 | end
|
---|
171 | else
|
---|
172 | begin
|
---|
173 | // the file is already opend in a running instance
|
---|
174 | LogEvent(LogViewStub, 'Adequate running NewView instance found');
|
---|
175 |
|
---|
176 | WinSetFocus( HWND_DESKTOP, tmpExistingWindow );
|
---|
177 |
|
---|
178 | // search and topic search
|
---|
179 | // topic search is also handled this way
|
---|
180 | // at the moment there is no support for a
|
---|
181 | // seperate window message
|
---|
182 | if not tmpCmdLineParameters.getGlobalSearchFlag
|
---|
183 | AND (tmpCmdLineParameters.getSearchText <> '')
|
---|
184 | then
|
---|
185 | begin
|
---|
186 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
187 | NHM_SEARCH,
|
---|
188 | tmpCmdLineParameters.getSearchText);
|
---|
189 | end;
|
---|
190 |
|
---|
191 | if tmpCmdLineParameters.getGlobalSearchFlag then
|
---|
192 | begin
|
---|
193 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
194 | NHM_GLOBAL_SEARCH,
|
---|
195 | tmpCmdLineParameters.getSearchText);
|
---|
196 | end;
|
---|
197 |
|
---|
198 | if tmpCmdLineParameters.getShowUsageFlag then
|
---|
199 | begin
|
---|
200 | WinPostMsg( tmpExistingWindow,
|
---|
201 | NHM_SHOW_USAGE,
|
---|
202 | 0,
|
---|
203 | 0 );
|
---|
204 | end;
|
---|
205 |
|
---|
206 | if tmpCmdLineParameters.getHelpManagerFlag then
|
---|
207 | begin
|
---|
208 | // tell the new help manager instance to talk to the
|
---|
209 | // other viewer
|
---|
210 | WinPostMsg( tmpCmdLineParameters.getHelpManagerWindow,
|
---|
211 | NHM_VIEWER_READY,
|
---|
212 | tmpExistingWindow,
|
---|
213 | 0 );
|
---|
214 | end;
|
---|
215 |
|
---|
216 | end;
|
---|
217 |
|
---|
218 | // destroy global list
|
---|
219 | GlobalFilelist.Destroy;
|
---|
220 |
|
---|
221 | tmpCmdLineParameters.Destroy;
|
---|
222 | LogEvent(LogViewStub, 'Finished' );
|
---|
223 | End.
|
---|