1 | /*
|
---|
2 | * This file is (C) Chris Wohlgemuth 1999-2004
|
---|
3 | */
|
---|
4 | /*
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
8 | * any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; see the file COPYING. If not, write to
|
---|
17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #define INCL_WIN
|
---|
21 | #define INCL_DOS
|
---|
22 | #define INCL_REXXSAA
|
---|
23 |
|
---|
24 | #include <os2.h>
|
---|
25 | #include <rexxsaa.h> /* needed for RexxStart() */
|
---|
26 | #include "except.h"
|
---|
27 | #include <sys/types.h>
|
---|
28 | #include <sys/stat.h>
|
---|
29 | #include <stdio.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <stdarg.h>
|
---|
32 |
|
---|
33 | #include "sys_funcs.h"
|
---|
34 |
|
---|
35 | #ifndef BS_NOTEBOOKBUTTON
|
---|
36 | #define BS_NOTEBOOKBUTTON 8L /* Warp 4 notebook style */
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | extern char chrInstallDir[];
|
---|
40 |
|
---|
41 |
|
---|
42 | /* Mutex semaphores to protect filename generation */
|
---|
43 | ULONG cwCreateMutex(HMTX * hmtxBMP) {
|
---|
44 |
|
---|
45 | return DosCreateMutexSem( NULL, hmtxBMP, 0, FALSE);
|
---|
46 | }
|
---|
47 |
|
---|
48 | ULONG cwCloseMutex(HMTX hmtxBMP) {
|
---|
49 |
|
---|
50 | return DosCloseMutexSem( hmtxBMP );
|
---|
51 | }
|
---|
52 |
|
---|
53 | ULONG cwRequestMutex(HMTX hmtxBMP, ULONG ulTimeOut) {
|
---|
54 |
|
---|
55 | return DosRequestMutexSem( hmtxBMP, ulTimeOut );
|
---|
56 | }
|
---|
57 |
|
---|
58 | ULONG cwReleaseMutex(HMTX hmtxBMP) {
|
---|
59 |
|
---|
60 | return DosReleaseMutexSem( hmtxBMP );
|
---|
61 | }
|
---|
62 |
|
---|
63 | /****************************************************
|
---|
64 | * *
|
---|
65 | * This function moves the default buttons off *
|
---|
66 | * notebook pages on Warp 4. *
|
---|
67 | * usDelta specifies the units all controls have *
|
---|
68 | * to be moved down. usID is the ID of the last *
|
---|
69 | * button that has to be moved on the main frame *
|
---|
70 | * of the notebook. This value is a threshold. *
|
---|
71 | * *
|
---|
72 | ****************************************************/
|
---|
73 | BOOL cwMoveNotebookButtonsWarp4(HWND hwndDlg, USHORT usID, USHORT usDelta)
|
---|
74 | {
|
---|
75 | if (SysQueryOSRelease()>=40) {
|
---|
76 | HENUM henum;
|
---|
77 | HWND hwnd;
|
---|
78 |
|
---|
79 | /* Move the default notebook buttons */
|
---|
80 | if((henum=WinBeginEnumWindows(hwndDlg))!=NULLHANDLE) {
|
---|
81 | while((hwnd=WinGetNextWindow(henum))!=NULLHANDLE) {
|
---|
82 | if(WinQueryWindowUShort(hwnd,QWS_ID)<=usID)
|
---|
83 | WinSetWindowBits(hwnd, QWL_STYLE,
|
---|
84 | BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
|
---|
85 | else {
|
---|
86 | SWP swp;
|
---|
87 | POINTL ptl= {0};
|
---|
88 | ptl.y=usDelta;
|
---|
89 |
|
---|
90 | WinMapDlgPoints(hwndDlg, &ptl, 1, TRUE);
|
---|
91 | /* Move all other controls */
|
---|
92 | if(WinQueryWindowPos(hwnd, &swp))
|
---|
93 | WinSetWindowPos(hwnd, NULLHANDLE, swp.x, swp.y-ptl.y,0,0, SWP_MOVE);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | WinEndEnumWindows(henum);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | return TRUE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | BOOL launchRexx(PSZ rexxFile)
|
---|
103 | {
|
---|
104 | char text[1024];
|
---|
105 |
|
---|
106 | RXSTRING arg[1]; /* argument string for REXX */
|
---|
107 | RXSTRING rexxretval; /* return value from REXX */
|
---|
108 | APIRET rc; /* return code from REXX */
|
---|
109 | SHORT rexxrc = 0; /* return code from function */
|
---|
110 | char theScript[CCHMAXPATH];
|
---|
111 | /* By setting the strlength of the output RXSTRING to zero, we */
|
---|
112 | /* force the interpreter to allocate memory and return it to us. */
|
---|
113 | /* We could provide a buffer for the interpreter to use instead. */
|
---|
114 | rexxretval.strlength = 0L; /* initialize return to empty*/
|
---|
115 |
|
---|
116 | // MAKERXSTRING(arg[0], chrRexxEnv, strlen(chrRexxEnv));/* create input argument */
|
---|
117 | // MAKERXSTRING(arg[1], chrThis, strlen(chrThis));/* create input argument */
|
---|
118 | // MAKERXSTRING(arg[2], chrHwnd, strlen(chrHwnd));/* create input argument */
|
---|
119 |
|
---|
120 | sprintf(theScript, "%s\\bin\\%s", chrInstallDir, rexxFile);
|
---|
121 |
|
---|
122 | TRY_LOUD(RX_START) {
|
---|
123 | /* Here we call the interpreter. We don't really need to use */
|
---|
124 | /* all the casts in this call; they just help illustrate */
|
---|
125 | /* the data types used. */
|
---|
126 | rc=RexxStart((LONG) 0, /* number of arguments */
|
---|
127 | (PRXSTRING) &arg, /* array of arguments */
|
---|
128 | (PSZ) theScript,/* name of REXX file */
|
---|
129 | (PRXSTRING) 0, /* No INSTORE used */
|
---|
130 | (PSZ) "CWRXX", /* Command env. name */
|
---|
131 | (LONG) RXSUBROUTINE, /* Code for how invoked */
|
---|
132 | (PRXSYSEXIT) 0, /* No EXITs on this call */
|
---|
133 | (PSHORT) &rexxrc, /* Rexx program output */
|
---|
134 | (PRXSTRING) &rexxretval ); /* Rexx program output */
|
---|
135 | #if 0
|
---|
136 | if(rc) {
|
---|
137 | sprintf(text,"Error in the Rexx skript %s\n\n Get more information with 'help REX%04d'.\n",
|
---|
138 | tPt->rexxSkript, rc*-1);
|
---|
139 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE|MB_ERROR);
|
---|
140 | }
|
---|
141 | #endif
|
---|
142 | DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */
|
---|
143 | }
|
---|
144 | CATCH(RX_START)
|
---|
145 | {}END_CATCH;
|
---|
146 | return TRUE;
|
---|
147 | }
|
---|
148 |
|
---|
149 | #if 0
|
---|
150 | ULONG launchRexx( PSZ pszTitle, PSZ rexxFile, PSZ parameters)
|
---|
151 | {
|
---|
152 | STARTDATA startData={0};
|
---|
153 | APIRET rc;
|
---|
154 | PID pid;
|
---|
155 | ULONG ulSessionID=0;
|
---|
156 | char chrLoadError[CCHMAXPATH];
|
---|
157 | char startParams[CCHMAXPATH*4];
|
---|
158 | char tempText[CCHMAXPATH]= {0};
|
---|
159 | char *charPtr;
|
---|
160 | char trackname[CCHMAXPATH];
|
---|
161 |
|
---|
162 | memset(&startData,0,sizeof(startData));
|
---|
163 | startData.Length=sizeof(startData);
|
---|
164 | startData.Related=SSF_RELATED_INDEPENDENT;
|
---|
165 | startData.FgBg=SSF_FGBG_BACK;
|
---|
166 | startData.TraceOpt=SSF_TRACEOPT_NONE;
|
---|
167 | startData.PgmTitle=pszTitle;
|
---|
168 |
|
---|
169 | startData.PgmName="cmd.exe";
|
---|
170 | startData.InheritOpt=SSF_INHERTOPT_SHELL;
|
---|
171 | startData.SessionType=SSF_TYPE_WINDOWABLEVIO;
|
---|
172 | startData.PgmControl|=SSF_CONTROL_INVISIBLE;//|SSF_CONTROL_MAXIMIZE|SSF_CONTROL_NOAUTOCLOSE;
|
---|
173 | startData.InitXPos=30;
|
---|
174 | startData.InitYPos=30;
|
---|
175 | startData.InitXSize=500;
|
---|
176 | startData.InitYSize=400;
|
---|
177 | startData.ObjectBuffer=chrLoadError;
|
---|
178 | startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
|
---|
179 |
|
---|
180 | sprintf(startParams," /C \"%s\\bin\\%s\"", chrInstallDir, rexxFile);
|
---|
181 | startData.PgmInputs=startParams;
|
---|
182 |
|
---|
183 | rc=DosStartSession(&startData,&ulSessionID,&pid);
|
---|
184 | return rc;
|
---|
185 | }
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | /* This function launches the wrapper <wrapperExe> */
|
---|
189 | /* with the params given as a PM-session */
|
---|
190 | /* in PSZ parameter. PSZ folderPath is the path to put the */
|
---|
191 | /* write.log. HWND hwnd is the window waiting for the */
|
---|
192 | /* WM_APPTERMINATE message */
|
---|
193 | ULONG launchPMWrapper(PSZ pszTitle, PSZ wrapperExe, PSZ parameters)
|
---|
194 | {
|
---|
195 | STARTDATA startData={0};
|
---|
196 | APIRET rc;
|
---|
197 | PID pid;
|
---|
198 | ULONG ulSessionID=0;
|
---|
199 | char chrLoadError[CCHMAXPATH];
|
---|
200 |
|
---|
201 | memset(&startData,0,sizeof(startData));
|
---|
202 | startData.Length=sizeof(startData);
|
---|
203 | startData.Related=SSF_RELATED_INDEPENDENT;
|
---|
204 | startData.FgBg=SSF_FGBG_FORE;
|
---|
205 | startData.TraceOpt=SSF_TRACEOPT_NONE;
|
---|
206 | startData.PgmTitle=pszTitle;
|
---|
207 |
|
---|
208 | startData.PgmName=wrapperExe;
|
---|
209 | startData.InheritOpt=SSF_INHERTOPT_SHELL;
|
---|
210 | startData.SessionType=SSF_TYPE_PM;
|
---|
211 | startData.PgmControl=0;
|
---|
212 | startData.InitXPos=30;
|
---|
213 | startData.InitYPos=30;
|
---|
214 | startData.InitXSize=500;
|
---|
215 | startData.InitYSize=400;
|
---|
216 | startData.ObjectBuffer=chrLoadError;
|
---|
217 | startData.ObjectBuffLen=(ULONG)sizeof(chrLoadError);
|
---|
218 |
|
---|
219 | startData.PgmInputs=parameters;
|
---|
220 |
|
---|
221 | rc=DosStartSession(&startData,&ulSessionID,&pid);
|
---|
222 | return 0;
|
---|
223 | }
|
---|
224 |
|
---|