| [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 | {$R ViewStub}
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | var
 | 
|---|
 | 25 |   Details: PROGDETAILS;
 | 
|---|
 | 26 |   Parameters: pchar;
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | Const
 | 
|---|
| [64] | 29 |   Vendor = 'Aaron Lawrence, Ronald Brill';
 | 
|---|
 | 30 |   BldLevelVersion = '1.1.2';
 | 
|---|
| [18] | 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 | 
 | 
|---|
| [57] | 50 | var
 | 
|---|
| [61] | 51 |   tmpCmdLine : String;
 | 
|---|
 | 52 |   tmpPCharCmdLine : PChar;
 | 
|---|
 | 53 |   tmpCmdLineParameters: TCmdLineParameters;
 | 
|---|
 | 54 |   tmpExistingWindow: HWND;
 | 
|---|
| [57] | 55 | 
 | 
|---|
| [61] | 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 | 
 | 
|---|
| [140] | 70 |     if aCmdLineParameters.getFileNames(false) = '' then
 | 
|---|
| [61] | 71 |       // not loading files; nothing to check
 | 
|---|
 | 72 |       exit;
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 |     tmpFileItems := TStringList.Create;
 | 
|---|
 | 75 |     tmpFilenames := TStringList.Create;
 | 
|---|
 | 76 | 
 | 
|---|
| [140] | 77 |     StrExtractStrings(tmpFileItems, aCmdLineParameters.getFileNames(false), ['+'], #0);
 | 
|---|
| [61] | 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 | 
 | 
|---|
| [18] | 122 | Begin
 | 
|---|
| [57] | 123 |   LogEvent(LogViewStub, 'Starting' );
 | 
|---|
 | 124 | 
 | 
|---|
| [61] | 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
 | 
|---|
| [18] | 140 |   begin
 | 
|---|
 | 141 |     // Want a new instance.
 | 
|---|
| [61] | 142 |     LogEvent(LogViewStub, 'Starting a new NewView instance');
 | 
|---|
| [18] | 143 | 
 | 
|---|
| [57] | 144 |     tmpPCharCmdLine := StrAlloc(length(tmpCmdLine) + 1);
 | 
|---|
 | 145 |     StrPCopy(tmpPCharCmdLine, tmpCmdLine);
 | 
|---|
| [18] | 146 | 
 | 
|---|
| [61] | 147 |     LogEvent(LogViewStub, 'CmdLine for NewView exe: ' + tmpCmdLine);
 | 
|---|
| [18] | 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,
 | 
|---|
| [57] | 166 |                   tmpPCharCmdLine, // use these rather than Details parameters,
 | 
|---|
| [18] | 167 |                               // cause PM was swallowing /? the other way!!
 | 
|---|
 | 168 |                   nil, // reserved
 | 
|---|
 | 169 |                   0 );
 | 
|---|
| [57] | 170 | 
 | 
|---|
 | 171 |     StrDispose(tmpPCharCmdLine);
 | 
|---|
| [61] | 172 |   end
 | 
|---|
 | 173 |   else
 | 
|---|
 | 174 |   begin
 | 
|---|
 | 175 |     // the file is already opend in a running instance
 | 
|---|
 | 176 |     LogEvent(LogViewStub, 'Adequate running NewView instance found');
 | 
|---|
| [57] | 177 | 
 | 
|---|
| [61] | 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
 | 
|---|
| [78] | 185 |        AND (tmpCmdLineParameters.getSearchText <> '')
 | 
|---|
| [61] | 186 |     then
 | 
|---|
 | 187 |     begin
 | 
|---|
 | 188 |       PostNewViewTextMessage( tmpExistingWindow,
 | 
|---|
 | 189 |                               NHM_SEARCH,
 | 
|---|
| [78] | 190 |                               tmpCmdLineParameters.getSearchText);
 | 
|---|
| [61] | 191 |     end;
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 |     if tmpCmdLineParameters.getGlobalSearchFlag then
 | 
|---|
 | 194 |     begin
 | 
|---|
 | 195 |       PostNewViewTextMessage( tmpExistingWindow,
 | 
|---|
 | 196 |                               NHM_GLOBAL_SEARCH,
 | 
|---|
| [78] | 197 |                               tmpCmdLineParameters.getSearchText);
 | 
|---|
| [61] | 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 | 
 | 
|---|
| [18] | 218 |   end;
 | 
|---|
| [61] | 219 | 
 | 
|---|
 | 220 |   // destroy global list
 | 
|---|
 | 221 |   GlobalFilelist.Destroy;
 | 
|---|
 | 222 | 
 | 
|---|
 | 223 |   tmpCmdLineParameters.Destroy;
 | 
|---|
| [57] | 224 |   LogEvent(LogViewStub, 'Finished' );
 | 
|---|
| [18] | 225 | End.
 | 
|---|