source: branches/2.20_branch/hlpmgr/viewer.c@ 443

Last change on this file since 443 was 361, checked in by RBRi, 16 years ago

formating

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4
5#define INCL_PM
6#include <os2.h>
7
8#include "Viewer.h"
9#include "log.h"
10
11char* pszViewerFilename = "view.exe";
12char* OWN_HELP_MARKER = "[NVHELP]";
13
14BOOL StartViewer( char* pszParameters,
15 HWND hTerminateNotify,
16 HWND hAppWindow,
17 HAB hab )
18{
19 PROGDETAILS Details;
20 char pszMessageCaption[ 1024 ];
21 HAPP hApplication;
22 BOOL result;
23
24 Details.Length = sizeof(PROGDETAILS);
25 Details.progt.progc = PROG_PM;
26 Details.progt.fbVisible = SHE_VISIBLE;
27 Details.pszTitle = "Help Viewer";
28 Details.pszExecutable = pszViewerFilename;
29 Details.pszParameters = pszParameters;
30 Details.pszStartupDir = "";
31 Details.pszIcon = NULL; // default app icon
32 Details.pszEnvironment = NULL;
33 Details.swpInitial.fl = SWP_ACTIVATE;
34 Details.swpInitial.cy = 0;
35 Details.swpInitial.cx = 0;
36 Details.swpInitial.y = 0;
37 Details.swpInitial.x = 0;
38 Details.swpInitial.hwndInsertBehind = HWND_TOP;
39 Details.swpInitial.hwnd = hAppWindow;
40 Details.swpInitial.ulReserved1 = 0;
41 Details.swpInitial.ulReserved2 = 0;
42
43
44 LogEvent( "Launching: %s %s", Details.pszExecutable, pszParameters );
45
46 hApplication =
47 WinStartApp( hTerminateNotify, // window to be notified of termination
48 & Details, // details
49 NULL, // parameters - used Details
50 NULL, // reserved
51 SAF_INSTALLEDCMDLINE ); // options
52
53 if ( hApplication == NULL )
54 {
55 LogEvent( " Failed to launch viewer, rc=%8X", WinGetLastError( hab ) );
56 sprintf( pszMessageCaption, "Unable to start help viewer %s", pszViewerFilename );
57 WinMessageBox( HWND_DESKTOP, // parent
58 hAppWindow, // owner
59 pszMessageCaption,
60 "Help Error", // title
61 0, // ID
62 MB_OK | MB_WARNING | MB_MOVEABLE );
63 result = FALSE;
64 }
65 else
66 {
67 result = TRUE;
68 }
69
70 free( pszParameters );
71 return result;
72}
73
74
75// appends the given filenames to the output string,
76// replace spaces between filenames with a +
77// and stripping redundant spaces.
78void ModifyFilenames( char* Filenames, char* Output )
79{
80 BOOL First;
81 BOOL InQuote;
82 char QuoteChar;
83
84 First = TRUE;
85 InQuote = FALSE;
86 while ( *Filenames != 0 )
87 {
88 // skip spaces
89 while ( *Filenames != 0
90 && *Filenames == ' ' )
91 Filenames ++;
92
93 // add a plus sign (+), after first word
94 if ( ! First
95 && *Filenames != 0 )
96 {
97 * Output = '+';
98 Output ++;
99 }
100
101 First = FALSE;
102 // copy non-space characters
103 // or all characters if in quotes
104 while ( *Filenames != 0
105 && ( *Filenames != ' ' || InQuote ) )
106 {
107 * Output = *Filenames;
108 if ( ! InQuote )
109 {
110 if ( *Filenames == '\''
111 || *Filenames == '\"' )
112 {
113 InQuote = TRUE;
114 QuoteChar = *Filenames;
115 * Output = '\"'; // change singles to doubles
116 }
117 }
118 else
119 {
120 if ( *Filenames == QuoteChar )
121 {
122 InQuote = FALSE;
123 * Output = '\"'; // change singles to doubles
124 }
125 }
126
127 Output ++;
128 Filenames ++;
129 }
130 }
131
132 // null terminate
133 *Output = 0;
134}
135
136
137BOOL ViewHelpFile( char* pszHelpFileName,
138 char* pszWindowTitle,
139 HWND hHelpWindow,
140 HWND hAppWindow,
141 HAB hab )
142{
143 char* pszParameters;
144
145 // set up viewer parameters:
146 // <helpfilename> /hm:<helpwindow>
147 // currently not used: /owner:<ownerwindow>
148
149 pszParameters = (char*) malloc( strlen( pszHelpFileName )
150 + strlen( pszWindowTitle )
151 + 512 );
152
153 sprintf( pszParameters, "/hm:%u ", hHelpWindow );
154
155 if ( pszHelpFileName != NULL )
156 {
157 // add (modified) filenames to parameters
158 ModifyFilenames( pszHelpFileName,
159 pszParameters + strlen( pszParameters ) );
160 }
161
162 if ( pszWindowTitle != NULL )
163 {
164 // add window title parameter
165 strcat( pszParameters, " \"/title:" );
166 strcat( pszParameters, pszWindowTitle );
167 strcat( pszParameters, "\"" );
168 }
169
170 return StartViewer( pszParameters,
171 hHelpWindow,
172 hAppWindow,
173 hab );
174}
175
176
177void ViewHelpOnHelp( HAB hab )
178{
179 StartViewer( OWN_HELP_MARKER,
180 NULL,
181 NULL,
182 hab );
183}
184
Note: See TracBrowser for help on using the repository browser.