[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 | tmpFileItems: TStringList;
|
---|
| 60 | tmpFilenames: TStringList;
|
---|
| 61 | tmpFullFilePath: string;
|
---|
| 62 | i: longint;
|
---|
| 63 |
|
---|
| 64 | FileWindow: HWND;
|
---|
| 65 | begin
|
---|
| 66 | result := NULLHANDLE;
|
---|
| 67 |
|
---|
[140] | 68 | if aCmdLineParameters.getFileNames(false) = '' then
|
---|
[61] | 69 | // not loading files; nothing to check
|
---|
| 70 | exit;
|
---|
| 71 |
|
---|
| 72 | tmpFileItems := TStringList.Create;
|
---|
| 73 | tmpFilenames := TStringList.Create;
|
---|
| 74 |
|
---|
[256] | 75 | StrExtractStrings(tmpFileItems, aCmdLineParameters.getFileNames(false), [HELP_FILE_DELIMITER], #0);
|
---|
[61] | 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 |
|
---|
[18] | 120 | Begin
|
---|
[57] | 121 | LogEvent(LogViewStub, 'Starting' );
|
---|
| 122 |
|
---|
[61] | 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
|
---|
[18] | 138 | begin
|
---|
| 139 | // Want a new instance.
|
---|
[61] | 140 | LogEvent(LogViewStub, 'Starting a new NewView instance');
|
---|
[18] | 141 |
|
---|
[57] | 142 | tmpPCharCmdLine := StrAlloc(length(tmpCmdLine) + 1);
|
---|
| 143 | StrPCopy(tmpPCharCmdLine, tmpCmdLine);
|
---|
[18] | 144 |
|
---|
[61] | 145 | LogEvent(LogViewStub, 'CmdLine for NewView exe: ' + tmpCmdLine);
|
---|
[18] | 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,
|
---|
[57] | 164 | tmpPCharCmdLine, // use these rather than Details parameters,
|
---|
[18] | 165 | // cause PM was swallowing /? the other way!!
|
---|
| 166 | nil, // reserved
|
---|
| 167 | 0 );
|
---|
[57] | 168 |
|
---|
| 169 | StrDispose(tmpPCharCmdLine);
|
---|
[61] | 170 | end
|
---|
| 171 | else
|
---|
| 172 | begin
|
---|
| 173 | // the file is already opend in a running instance
|
---|
| 174 | LogEvent(LogViewStub, 'Adequate running NewView instance found');
|
---|
[57] | 175 |
|
---|
[61] | 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
|
---|
[78] | 183 | AND (tmpCmdLineParameters.getSearchText <> '')
|
---|
[61] | 184 | then
|
---|
| 185 | begin
|
---|
| 186 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
| 187 | NHM_SEARCH,
|
---|
[78] | 188 | tmpCmdLineParameters.getSearchText);
|
---|
[61] | 189 | end;
|
---|
| 190 |
|
---|
| 191 | if tmpCmdLineParameters.getGlobalSearchFlag then
|
---|
| 192 | begin
|
---|
| 193 | PostNewViewTextMessage( tmpExistingWindow,
|
---|
| 194 | NHM_GLOBAL_SEARCH,
|
---|
[78] | 195 | tmpCmdLineParameters.getSearchText);
|
---|
[61] | 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 |
|
---|
[18] | 216 | end;
|
---|
[61] | 217 |
|
---|
| 218 | // destroy global list
|
---|
| 219 | GlobalFilelist.Destroy;
|
---|
| 220 |
|
---|
| 221 | tmpCmdLineParameters.Destroy;
|
---|
[57] | 222 | LogEvent(LogViewStub, 'Finished' );
|
---|
[18] | 223 | End.
|
---|