[18] | 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
|
---|
[33] | 10 | OS2def,
|
---|
| 11 | PMShl,
|
---|
| 12 | PmWin,
|
---|
[57] | 13 | SysUtils,
|
---|
[61] | 14 | Classes,
|
---|
[57] | 15 | DebugUnit,
|
---|
[61] | 16 | GlobalFilelistUnit,
|
---|
[57] | 17 | CmdLineParameterUnit,
|
---|
[61] | 18 | HelpManagerUnit,
|
---|
| 19 | StringUtilsUnit,
|
---|
[18] | 20 | StartupUnit;
|
---|
| 21 |
|
---|
| 22 | var
|
---|
| 23 | Details: PROGDETAILS;
|
---|
| 24 | Parameters: pchar;
|
---|
| 25 |
|
---|
| 26 | Const
|
---|
[64] | 27 | Vendor = 'Aaron Lawrence, Ronald Brill';
|
---|
| 28 | BldLevelVersion = '1.1.2';
|
---|
[18] | 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 |
|
---|
[57] | 48 | var
|
---|
[61] | 49 | tmpCmdLine : String;
|
---|
| 50 | tmpPCharCmdLine : PChar;
|
---|
| 51 | tmpCmdLineParameters: TCmdLineParameters;
|
---|
| 52 | tmpExistingWindow: HWND;
|
---|
[57] | 53 |
|
---|
[61] | 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;
|
---|
[353] | 62 | tmpFileWindow: HWND;
|
---|
[61] | 63 |
|
---|
| 64 | begin
|
---|
| 65 | result := NULLHANDLE;
|
---|
| 66 |
|
---|
[353] | 67 | if aCmdLineParameters.getFileNames(true) = '' then
|
---|
| 68 | begin
|
---|
[61] | 69 | // not loading files; nothing to check
|
---|
| 70 | exit;
|
---|
[353] | 71 | end;
|
---|
[61] | 72 |
|
---|
| 73 | tmpFilenames := TStringList.Create;
|
---|
| 74 |
|
---|
[353] | 75 | ParseAndExpandFileNames(aCmdLineParameters.getFileNames(true), tmpFilenames);
|
---|
[61] | 76 |
|
---|
| 77 | for i := 0 to tmpFileNames.Count - 1 do
|
---|
| 78 | begin
|
---|
[353] | 79 | LogEvent(LogStartup, 'Search in GlobalFileList for ''' + tmpFilenames[i] + '''');
|
---|
| 80 |
|
---|
| 81 | tmpFullFilePath := FindHelpFile( tmpFilenames[i] );
|
---|
[61] | 82 | if tmpFullFilePath <> '' then
|
---|
| 83 | begin
|
---|
[353] | 84 | tmpFileWindow := GlobalFilelist.FindFile(tmpFullFilePath);
|
---|
[61] | 85 |
|
---|
[353] | 86 | if tmpFileWindow = NULLHANDLE then
|
---|
[61] | 87 | begin
|
---|
| 88 | // not found - stop searching.
|
---|
| 89 | Result := NULLHANDLE; // no match
|
---|
| 90 | break;
|
---|
| 91 | end;
|
---|
| 92 |
|
---|
| 93 | // found it
|
---|
[353] | 94 | LogEvent(LogStartup, 'Found in GlobalFileList for ''' + tmpFullFilePath + '''');
|
---|
[61] | 95 |
|
---|
| 96 | // is it the same as any previous match?
|
---|
| 97 | if Result <> NULLHANDLE then
|
---|
| 98 | begin
|
---|
[353] | 99 | if tmpFileWindow <> Result then
|
---|
[61] | 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
|
---|
[353] | 111 | result := tmpFileWindow;
|
---|
[61] | 112 | end;
|
---|
| 113 | end;
|
---|
| 114 | end;
|
---|
| 115 |
|
---|
| 116 | tmpFilenames.Destroy;
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
[18] | 121 | Begin
|
---|
[57] | 122 | LogEvent(LogViewStub, 'Starting' );
|
---|
| 123 |
|
---|
[61] | 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
|
---|
[18] | 139 | begin
|
---|
| 140 | // Want a new instance.
|
---|
[61] | 141 | LogEvent(LogViewStub, 'Starting a new NewView instance');
|
---|
[18] | 142 |
|
---|
[57] | 143 | tmpPCharCmdLine := StrAlloc(length(tmpCmdLine) + 1);
|
---|
| 144 | StrPCopy(tmpPCharCmdLine, tmpCmdLine);
|
---|
[18] | 145 |
|
---|
[61] | 146 | LogEvent(LogViewStub, 'CmdLine for NewView exe: ' + tmpCmdLine);
|
---|
[18] | 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,
|
---|
[57] | 165 | tmpPCharCmdLine, // use these rather than Details parameters,
|
---|
[18] | 166 | // cause PM was swallowing /? the other way!!
|
---|
| 167 | nil, // reserved
|
---|
| 168 | 0 );
|
---|
[57] | 169 |
|
---|
| 170 | StrDispose(tmpPCharCmdLine);
|
---|
[61] | 171 | end
|
---|
| 172 | else
|
---|
| 173 | begin
|
---|
| 174 | // the file is already opend in a running instance
|
---|
| 175 | LogEvent(LogViewStub, 'Adequate running NewView instance found');
|
---|
[57] | 176 |
|
---|
[61] | 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
|
---|
[78] | 184 | AND (tmpCmdLineParameters.getSearchText <> '')
|
---|
[61] | 185 | then
|
---|
| 186 | begin
|
---|
| 187 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
| 188 | NHM_SEARCH,
|
---|
[78] | 189 | tmpCmdLineParameters.getSearchText);
|
---|
[61] | 190 | end;
|
---|
| 191 |
|
---|
| 192 | if tmpCmdLineParameters.getGlobalSearchFlag then
|
---|
| 193 | begin
|
---|
| 194 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
| 195 | NHM_GLOBAL_SEARCH,
|
---|
[78] | 196 | tmpCmdLineParameters.getSearchText);
|
---|
[61] | 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 |
|
---|
[18] | 217 | end;
|
---|
[61] | 218 |
|
---|
| 219 | // destroy global list
|
---|
| 220 | GlobalFilelist.Destroy;
|
---|
| 221 |
|
---|
| 222 | tmpCmdLineParameters.Destroy;
|
---|
[57] | 223 | LogEvent(LogViewStub, 'Finished' );
|
---|
[18] | 224 | End.
|
---|