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 | tmpFilenames: TStringList;
|
---|
60 | tmpFullFilePath: string;
|
---|
61 | i: longint;
|
---|
62 | tmpFileWindow: HWND;
|
---|
63 |
|
---|
64 | begin
|
---|
65 | result := NULLHANDLE;
|
---|
66 |
|
---|
67 | if aCmdLineParameters.getFileNames(true) = '' then
|
---|
68 | begin
|
---|
69 | // not loading files; nothing to check
|
---|
70 | exit;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | tmpFilenames := TStringList.Create;
|
---|
74 |
|
---|
75 | ParseAndExpandFileNames(aCmdLineParameters.getFileNames(true), tmpFilenames);
|
---|
76 |
|
---|
77 | for i := 0 to tmpFileNames.Count - 1 do
|
---|
78 | begin
|
---|
79 | LogEvent(LogStartup, 'Search in GlobalFileList for ''' + tmpFilenames[i] + '''');
|
---|
80 |
|
---|
81 | tmpFullFilePath := FindHelpFile( tmpFilenames[i] );
|
---|
82 | if tmpFullFilePath <> '' then
|
---|
83 | begin
|
---|
84 | tmpFileWindow := GlobalFilelist.FindFile(tmpFullFilePath);
|
---|
85 |
|
---|
86 | if tmpFileWindow = NULLHANDLE then
|
---|
87 | begin
|
---|
88 | // not found - stop searching.
|
---|
89 | Result := NULLHANDLE; // no match
|
---|
90 | break;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | // found it
|
---|
94 | LogEvent(LogStartup, 'Found in GlobalFileList for ''' + tmpFullFilePath + '''');
|
---|
95 |
|
---|
96 | // is it the same as any previous match?
|
---|
97 | if Result <> NULLHANDLE then
|
---|
98 | begin
|
---|
99 | if tmpFileWindow <> Result then
|
---|
100 | begin
|
---|
101 | // no, so we don't have a match.
|
---|
102 | // NOTE: We just excluded something: if the same file is
|
---|
103 | // open in multiple windows then we may not check all combinations
|
---|
104 | Result := NULLHANDLE; // no match
|
---|
105 | break;
|
---|
106 | end;
|
---|
107 | end
|
---|
108 | else
|
---|
109 | begin
|
---|
110 | // no match yet - store this one
|
---|
111 | result := tmpFileWindow;
|
---|
112 | end;
|
---|
113 | end;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | tmpFilenames.Destroy;
|
---|
117 | end;
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 | Begin
|
---|
122 | LogEvent(LogViewStub, 'Starting' );
|
---|
123 |
|
---|
124 | // open shared memory
|
---|
125 | SharedMemory := AccessSharedMemory;
|
---|
126 |
|
---|
127 | // get access to the system-global filelist
|
---|
128 | GlobalFilelist := TGlobalFilelist.Create;
|
---|
129 |
|
---|
130 | // parse parameters into Parameters object
|
---|
131 | tmpCmdLine := nativeOS2GetCmdLineParameter;
|
---|
132 |
|
---|
133 | tmpCmdLineParameters := TCmdLineParameters.Create;
|
---|
134 | tmpCmdLineParameters.parseCmdLine(tmpCmdLine);
|
---|
135 |
|
---|
136 | tmpExistingWindow := FindExistingWindow(tmpCmdLineParameters);
|
---|
137 |
|
---|
138 | if tmpExistingWindow = NULLHANDLE then
|
---|
139 | begin
|
---|
140 | // Want a new instance.
|
---|
141 | LogEvent(LogViewStub, 'Starting a new NewView instance');
|
---|
142 |
|
---|
143 | tmpPCharCmdLine := StrAlloc(length(tmpCmdLine) + 1);
|
---|
144 | StrPCopy(tmpPCharCmdLine, tmpCmdLine);
|
---|
145 |
|
---|
146 | LogEvent(LogViewStub, 'CmdLine for NewView exe: ' + tmpCmdLine);
|
---|
147 | // set up details for launching newview
|
---|
148 | With Details do
|
---|
149 | begin
|
---|
150 | Length := Sizeof( Details );
|
---|
151 | progt.progc := PROG_PM;
|
---|
152 | progt.fbVisible := SHE_VISIBLE;
|
---|
153 | pszTitle := 'Help Viewer';
|
---|
154 | pszExecutable := 'newview.exe';
|
---|
155 | pszParameters := nil; // Parameters; // copy our parameters
|
---|
156 | pszStartupDir := ''; // current dir
|
---|
157 | pszIcon := nil; // default
|
---|
158 | pszEnvironment := nil; // default
|
---|
159 | swpInitial.fl := SWP_ACTIVATE;
|
---|
160 | swpInitial.hwndInsertBehind := HWND_TOP;
|
---|
161 | end;
|
---|
162 |
|
---|
163 | _WinStartApp( NULLHANDLE, // no notify window
|
---|
164 | Details,
|
---|
165 | tmpPCharCmdLine, // use these rather than Details parameters,
|
---|
166 | // cause PM was swallowing /? the other way!!
|
---|
167 | nil, // reserved
|
---|
168 | 0 );
|
---|
169 |
|
---|
170 | StrDispose(tmpPCharCmdLine);
|
---|
171 | end
|
---|
172 | else
|
---|
173 | begin
|
---|
174 | // the file is already opend in a running instance
|
---|
175 | LogEvent(LogViewStub, 'Adequate running NewView instance found');
|
---|
176 |
|
---|
177 | WinSetFocus( HWND_DESKTOP, tmpExistingWindow );
|
---|
178 |
|
---|
179 | // search and topic search
|
---|
180 | // topic search is also handled this way
|
---|
181 | // at the moment there is no support for a
|
---|
182 | // seperate window message
|
---|
183 | if not tmpCmdLineParameters.getGlobalSearchFlag
|
---|
184 | AND (tmpCmdLineParameters.getSearchText <> '')
|
---|
185 | then
|
---|
186 | begin
|
---|
187 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
188 | NHM_SEARCH,
|
---|
189 | tmpCmdLineParameters.getSearchText);
|
---|
190 | end;
|
---|
191 |
|
---|
192 | if tmpCmdLineParameters.getGlobalSearchFlag then
|
---|
193 | begin
|
---|
194 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
195 | NHM_GLOBAL_SEARCH,
|
---|
196 | tmpCmdLineParameters.getSearchText);
|
---|
197 | end;
|
---|
198 |
|
---|
199 | if tmpCmdLineParameters.getShowUsageFlag then
|
---|
200 | begin
|
---|
201 | WinPostMsg( tmpExistingWindow,
|
---|
202 | NHM_SHOW_USAGE,
|
---|
203 | 0,
|
---|
204 | 0 );
|
---|
205 | end;
|
---|
206 |
|
---|
207 | if tmpCmdLineParameters.getHelpManagerFlag then
|
---|
208 | begin
|
---|
209 | // tell the new help manager instance to talk to the
|
---|
210 | // other viewer
|
---|
211 | WinPostMsg( tmpCmdLineParameters.getHelpManagerWindow,
|
---|
212 | NHM_VIEWER_READY,
|
---|
213 | tmpExistingWindow,
|
---|
214 | 0 );
|
---|
215 | end;
|
---|
216 |
|
---|
217 | end;
|
---|
218 |
|
---|
219 | // destroy global list
|
---|
220 | GlobalFilelist.Destroy;
|
---|
221 |
|
---|
222 | tmpCmdLineParameters.Destroy;
|
---|
223 | LogEvent(LogViewStub, 'Finished' );
|
---|
224 | End.
|
---|