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