source: trunk/essentials/dev-lang/perl/os2/OS2/Process/Process.xs@ 3609

Last change on this file since 3609 was 3204, checked in by bird, 19 years ago

_libc_32to16

  • Property svn:eol-style set to native
File size: 42.5 KB
Line 
1#include <process.h>
2#define INCL_DOS
3#define INCL_DOSERRORS
4#define INCL_DOSNLS
5#define INCL_WINSWITCHLIST
6#define INCL_WINWINDOWMGR
7#define INCL_WININPUT
8#define INCL_VIO
9#define INCL_KBD
10#define INCL_WINCLIPBOARD
11#define INCL_WINATOM
12#include <os2.h>
13
14#include "EXTERN.h"
15#include "perl.h"
16#include "XSUB.h"
17
18static unsigned long
19constant(char *name, int arg)
20{
21 errno = 0;
22 if (name[0] == 'P' && name[1] == '_') {
23 if (strEQ(name, "P_BACKGROUND"))
24#ifdef P_BACKGROUND
25 return P_BACKGROUND;
26#else
27 goto not_there;
28#endif
29 if (strEQ(name, "P_DEBUG"))
30#ifdef P_DEBUG
31 return P_DEBUG;
32#else
33 goto not_there;
34#endif
35 if (strEQ(name, "P_DEFAULT"))
36#ifdef P_DEFAULT
37 return P_DEFAULT;
38#else
39 goto not_there;
40#endif
41 if (strEQ(name, "P_DETACH"))
42#ifdef P_DETACH
43 return P_DETACH;
44#else
45 goto not_there;
46#endif
47 if (strEQ(name, "P_FOREGROUND"))
48#ifdef P_FOREGROUND
49 return P_FOREGROUND;
50#else
51 goto not_there;
52#endif
53 if (strEQ(name, "P_FULLSCREEN"))
54#ifdef P_FULLSCREEN
55 return P_FULLSCREEN;
56#else
57 goto not_there;
58#endif
59 if (strEQ(name, "P_MAXIMIZE"))
60#ifdef P_MAXIMIZE
61 return P_MAXIMIZE;
62#else
63 goto not_there;
64#endif
65 if (strEQ(name, "P_MINIMIZE"))
66#ifdef P_MINIMIZE
67 return P_MINIMIZE;
68#else
69 goto not_there;
70#endif
71 if (strEQ(name, "P_NOCLOSE"))
72#ifdef P_NOCLOSE
73 return P_NOCLOSE;
74#else
75 goto not_there;
76#endif
77 if (strEQ(name, "P_NOSESSION"))
78#ifdef P_NOSESSION
79 return P_NOSESSION;
80#else
81 goto not_there;
82#endif
83 if (strEQ(name, "P_NOWAIT"))
84#ifdef P_NOWAIT
85 return P_NOWAIT;
86#else
87 goto not_there;
88#endif
89 if (strEQ(name, "P_OVERLAY"))
90#ifdef P_OVERLAY
91 return P_OVERLAY;
92#else
93 goto not_there;
94#endif
95 if (strEQ(name, "P_PM"))
96#ifdef P_PM
97 return P_PM;
98#else
99 goto not_there;
100#endif
101 if (strEQ(name, "P_QUOTE"))
102#ifdef P_QUOTE
103 return P_QUOTE;
104#else
105 goto not_there;
106#endif
107 if (strEQ(name, "P_SESSION"))
108#ifdef P_SESSION
109 return P_SESSION;
110#else
111 goto not_there;
112#endif
113 if (strEQ(name, "P_TILDE"))
114#ifdef P_TILDE
115 return P_TILDE;
116#else
117 goto not_there;
118#endif
119 if (strEQ(name, "P_UNRELATED"))
120#ifdef P_UNRELATED
121 return P_UNRELATED;
122#else
123 goto not_there;
124#endif
125 if (strEQ(name, "P_WAIT"))
126#ifdef P_WAIT
127 return P_WAIT;
128#else
129 goto not_there;
130#endif
131 if (strEQ(name, "P_WINDOWED"))
132#ifdef P_WINDOWED
133 return P_WINDOWED;
134#else
135 goto not_there;
136#endif
137 } else if (name[0] == 'T' && name[1] == '_') {
138 if (strEQ(name, "FAPPTYP_NOTSPEC"))
139#ifdef FAPPTYP_NOTSPEC
140 return FAPPTYP_NOTSPEC;
141#else
142 goto not_there;
143#endif
144 if (strEQ(name, "T_NOTWINDOWCOMPAT"))
145#ifdef FAPPTYP_NOTWINDOWCOMPAT
146 return FAPPTYP_NOTWINDOWCOMPAT;
147#else
148 goto not_there;
149#endif
150 if (strEQ(name, "T_WINDOWCOMPAT"))
151#ifdef FAPPTYP_WINDOWCOMPAT
152 return FAPPTYP_WINDOWCOMPAT;
153#else
154 goto not_there;
155#endif
156 if (strEQ(name, "T_WINDOWAPI"))
157#ifdef FAPPTYP_WINDOWAPI
158 return FAPPTYP_WINDOWAPI;
159#else
160 goto not_there;
161#endif
162 if (strEQ(name, "T_BOUND"))
163#ifdef FAPPTYP_BOUND
164 return FAPPTYP_BOUND;
165#else
166 goto not_there;
167#endif
168 if (strEQ(name, "T_DLL"))
169#ifdef FAPPTYP_DLL
170 return FAPPTYP_DLL;
171#else
172 goto not_there;
173#endif
174 if (strEQ(name, "T_DOS"))
175#ifdef FAPPTYP_DOS
176 return FAPPTYP_DOS;
177#else
178 goto not_there;
179#endif
180 if (strEQ(name, "T_PHYSDRV"))
181#ifdef FAPPTYP_PHYSDRV
182 return FAPPTYP_PHYSDRV;
183#else
184 goto not_there;
185#endif
186 if (strEQ(name, "T_VIRTDRV"))
187#ifdef FAPPTYP_VIRTDRV
188 return FAPPTYP_VIRTDRV;
189#else
190 goto not_there;
191#endif
192 if (strEQ(name, "T_PROTDLL"))
193#ifdef FAPPTYP_PROTDLL
194 return FAPPTYP_PROTDLL;
195#else
196 goto not_there;
197#endif
198 if (strEQ(name, "T_32BIT"))
199#ifdef FAPPTYP_32BIT
200 return FAPPTYP_32BIT;
201#else
202 goto not_there;
203#endif
204 }
205
206 errno = EINVAL;
207 return 0;
208
209not_there:
210 errno = ENOENT;
211 return 0;
212}
213
214const char* const ptypes[] = { "FS", "DOS", "VIO", "PM", "DETACH" };
215
216static char *
217my_type()
218{
219 int rc;
220 TIB *tib;
221 PIB *pib;
222
223#ifndef __KLIBC__
224 if (!(_emx_env & 0x200)) return (char*)ptypes[1]; /* not OS/2. */
225#endif
226 if (CheckOSError(DosGetInfoBlocks(&tib, &pib)))
227 return NULL;
228
229 return (pib->pib_ultype <= 4 ? (char*)ptypes[pib->pib_ultype] : "UNKNOWN");
230}
231
232static ULONG
233file_type(char *path)
234{
235 int rc;
236 ULONG apptype;
237
238#ifndef __KLIBC__
239 if (!(_emx_env & 0x200))
240 croak("file_type not implemented on DOS"); /* not OS/2. */
241#endif
242 if (CheckOSError(DosQueryAppType(path, &apptype))) {
243#if 0
244 if (rc == ERROR_INVALID_EXE_SIGNATURE)
245 croak("Invalid EXE signature");
246 else if (rc == ERROR_EXE_MARKED_INVALID) {
247 croak("EXE marked invalid");
248 }
249#endif
250 croak_with_os2error("DosQueryAppType");
251 }
252
253 return apptype;
254}
255
256/* These use different type of wrapper. Good to check wrappers. ;-) */
257/* XXXX This assumes DOS type return type, without SEVERITY?! */
258DeclFuncByORD(HSWITCH, myWinQuerySwitchHandle, ORD_WinQuerySwitchHandle,
259 (HWND hwnd, PID pid), (hwnd, pid))
260DeclFuncByORD(ULONG, myWinQuerySwitchEntry, ORD_WinQuerySwitchEntry,
261 (HSWITCH hsw, PSWCNTRL pswctl), (hsw, pswctl))
262DeclFuncByORD(ULONG, myWinSetWindowText, ORD_WinSetWindowText,
263 (HWND hwnd, char* text), (hwnd, text))
264DeclFuncByORD(BOOL, myWinQueryWindowProcess, ORD_WinQueryWindowProcess,
265 (HWND hwnd, PPID ppid, PTID ptid), (hwnd, ppid, ptid))
266DeclFuncByORD(ULONG, XmyWinSwitchToProgram, ORD_WinSwitchToProgram,
267 (HSWITCH hsw), (hsw))
268#define myWinSwitchToProgram(hsw) (!CheckOSError(XmyWinSwitchToProgram(hsw)))
269
270
271/* These function croak if the return value is 0. */
272DeclWinFunc_CACHE(HWND, QueryWindow, (HWND hwnd, LONG cmd), (hwnd, cmd))
273DeclWinFunc_CACHE(BOOL, QueryWindowPos, (HWND hwnd, PSWP pswp),
274 (hwnd, pswp))
275DeclWinFunc_CACHE(LONG, QueryWindowText,
276 (HWND hwnd, LONG cchBufferMax, PCH pchBuffer),
277 (hwnd, cchBufferMax, pchBuffer))
278DeclWinFunc_CACHE(LONG, QueryClassName, (HWND hwnd, LONG cchMax, PCH pch),
279 (hwnd, cchMax, pch))
280DeclWinFunc_CACHE(HWND, QueryFocus, (HWND hwndDesktop), (hwndDesktop))
281DeclWinFunc_CACHE(BOOL, SetFocus, (HWND hwndDesktop, HWND hwndFocus),
282 (hwndDesktop, hwndFocus))
283DeclWinFunc_CACHE(BOOL, ShowWindow, (HWND hwnd, BOOL fShow), (hwnd, fShow))
284DeclWinFunc_CACHE(BOOL, EnableWindow, (HWND hwnd, BOOL fEnable),
285 (hwnd, fEnable))
286DeclWinFunc_CACHE(BOOL, SetWindowPos,
287 (HWND hwnd, HWND hwndInsertBehind, LONG x, LONG y,
288 LONG cx, LONG cy, ULONG fl),
289 (hwnd, hwndInsertBehind, x, y, cx, cy, fl))
290DeclWinFunc_CACHE(HENUM, BeginEnumWindows, (HWND hwnd), (hwnd))
291DeclWinFunc_CACHE(BOOL, EndEnumWindows, (HENUM henum), (henum))
292DeclWinFunc_CACHE(BOOL, EnableWindowUpdate, (HWND hwnd, BOOL fEnable),
293 (hwnd, fEnable))
294DeclWinFunc_CACHE(BOOL, SetWindowBits,
295 (HWND hwnd, LONG index, ULONG flData, ULONG flMask),
296 (hwnd, index, flData, flMask))
297DeclWinFunc_CACHE(BOOL, SetWindowPtr, (HWND hwnd, LONG index, PVOID p),
298 (hwnd, index, p))
299DeclWinFunc_CACHE(BOOL, SetWindowULong, (HWND hwnd, LONG index, ULONG ul),
300 (hwnd, index, ul))
301DeclWinFunc_CACHE(BOOL, SetWindowUShort, (HWND hwnd, LONG index, USHORT us),
302 (hwnd, index, us))
303DeclWinFunc_CACHE(HWND, IsChild, (HWND hwnd, HWND hwndParent),
304 (hwnd, hwndParent))
305DeclWinFunc_CACHE(HWND, WindowFromId, (HWND hwnd, ULONG id), (hwnd, id))
306DeclWinFunc_CACHE(HWND, EnumDlgItem, (HWND hwndDlg, HWND hwnd, ULONG code),
307 (hwndDlg, hwnd, code))
308DeclWinFunc_CACHE(HWND, QueryDesktopWindow, (HAB hab, HDC hdc), (hab, hdc));
309DeclWinFunc_CACHE(BOOL, SetActiveWindow, (HWND hwndDesktop, HWND hwnd),
310 (hwndDesktop, hwnd));
311DeclWinFunc_CACHE(BOOL, QueryActiveDesktopPathname, (PSZ pszPathName, ULONG ulSize),
312 (pszPathName, ulSize));
313DeclWinFunc_CACHE(BOOL, InvalidateRect,
314 (HWND hwnd, /*RECTL*/ char *prcl, BOOL fIncludeChildren),
315 (hwnd, prcl, fIncludeChildren));
316DeclWinFunc_CACHE(BOOL, CreateFrameControls,
317 (HWND hwndFrame, /*PFRAMECDATA*/ char* pfcdata, PCSZ pszTitle),
318 (hwndFrame, pfcdata, pszTitle));
319DeclWinFunc_CACHE(BOOL, OpenClipbrd, (HAB hab), (hab));
320DeclWinFunc_CACHE(BOOL, EmptyClipbrd, (HAB hab), (hab));
321DeclWinFunc_CACHE(BOOL, CloseClipbrd, (HAB hab), (hab));
322DeclWinFunc_CACHE(HWND, QueryClipbrdViewer, (HAB hab), (hab));
323DeclWinFunc_CACHE(HWND, QueryClipbrdOwner, (HAB hab), (hab));
324DeclWinFunc_CACHE(BOOL, QueryClipbrdFmtInfo, (HAB hab, ULONG fmt, PULONG prgfFmtInfo), (hab, fmt, prgfFmtInfo));
325DeclWinFunc_CACHE(ULONG, QueryClipbrdData, (HAB hab, ULONG fmt), (hab, fmt));
326DeclWinFunc_CACHE(HWND, SetClipbrdViewer, (HAB hab, HWND hwnd), (hab, hwnd));
327DeclWinFunc_CACHE(HWND, SetClipbrdOwner, (HAB hab, HWND hwnd), (hab, hwnd));
328DeclWinFunc_CACHE(ULONG, EnumClipbrdFmts, (HAB hab, ULONG fmt), (hab, fmt));
329DeclWinFunc_CACHE(ATOM, AddAtom, (HATOMTBL hAtomTbl, PCSZ pszAtomName),
330 (hAtomTbl, pszAtomName));
331DeclWinFunc_CACHE(ATOM, FindAtom, (HATOMTBL hAtomTbl, PCSZ pszAtomName),
332 (hAtomTbl, pszAtomName));
333DeclWinFunc_CACHE(ATOM, DeleteAtom, (HATOMTBL hAtomTbl, PCSZ pszAtomName),
334 (hAtomTbl, pszAtomName));
335DeclWinFunc_CACHE(ULONG, QueryAtomUsage, (HATOMTBL hAtomTbl, ATOM atom),
336 (hAtomTbl, atom));
337DeclWinFunc_CACHE(ULONG, QueryAtomLength, (HATOMTBL hAtomTbl, ATOM atom),
338 (hAtomTbl, atom));
339DeclWinFunc_CACHE(ULONG, QueryAtomName,
340 (HATOMTBL hAtomTbl, ATOM atom, PSZ pchBuffer, ULONG cchBufferMax),
341 (hAtomTbl, atom, pchBuffer, cchBufferMax));
342DeclWinFunc_CACHE(HATOMTBL, QuerySystemAtomTable, (VOID), ());
343DeclWinFunc_CACHE(HATOMTBL, CreateAtomTable, (ULONG initial, ULONG buckets),
344 (initial, buckets));
345DeclWinFunc_CACHE(HATOMTBL, DestroyAtomTable, (HATOMTBL hAtomTbl), (hAtomTbl));
346DeclWinFunc_CACHE(ULONG, MessageBox, (HWND hwndParent, HWND hwndOwner, PCSZ pszText, PCSZ pszCaption, ULONG idWindow, ULONG flStyle), (hwndParent, hwndOwner, pszText, pszCaption, idWindow, flStyle));
347DeclWinFunc_CACHE(ULONG, MessageBox2,
348 (HWND hwndParent, HWND hwndOwner, PCSZ pszText,
349 PCSZ pszCaption, ULONG idWindow, PMB2INFO pmb2info),
350 (hwndParent, hwndOwner, pszText, pszCaption, idWindow, pmb2info));
351DeclWinFunc_CACHE(HPOINTER, LoadPointer,
352 (HWND hwndDesktop, HMODULE hmod, ULONG idres),
353 (hwndDesktop, hmod, idres));
354DeclWinFunc_CACHE(HPOINTER, QuerySysPointer,
355 (HWND hwndDesktop, LONG lId, BOOL fCopy),
356 (hwndDesktop, lId, fCopy));
357DeclWinFunc_CACHE(BOOL, Alarm, (HWND hwndDesktop, ULONG rgfType), (hwndDesktop, rgfType));
358DeclWinFunc_CACHE(BOOL, FlashWindow, (HWND hwndFrame, BOOL fFlash), (hwndFrame, fFlash));
359
360
361/* These functions do not croak on error */
362DeclWinFunc_CACHE_survive(BOOL, SetClipbrdData,
363 (HAB hab, ULONG ulData, ULONG fmt, ULONG rgfFmtInfo),
364 (hab, ulData, fmt, rgfFmtInfo));
365
366#define get_InvalidateRect InvalidateRect
367#define get_CreateFrameControls CreateFrameControls
368
369/* These functions may return 0 on success; check $^E/Perl_rc on res==0: */
370DeclWinFunc_CACHE_resetError(PVOID, QueryWindowPtr, (HWND hwnd, LONG index),
371 (hwnd, index))
372DeclWinFunc_CACHE_resetError(ULONG, QueryWindowULong, (HWND hwnd, LONG index),
373 (hwnd, index))
374DeclWinFunc_CACHE_resetError(SHORT, QueryWindowUShort, (HWND hwnd, LONG index),
375 (hwnd, index))
376DeclWinFunc_CACHE_resetError(LONG, QueryWindowTextLength, (HWND hwnd), (hwnd))
377DeclWinFunc_CACHE_resetError(HWND, QueryActiveWindow, (HWND hwnd), (hwnd))
378DeclWinFunc_CACHE_resetError(BOOL, PostMsg,
379 (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2),
380 (hwnd, msg, mp1, mp2))
381DeclWinFunc_CACHE_resetError(HWND, GetNextWindow, (HENUM henum), (henum))
382DeclWinFunc_CACHE_resetError(BOOL, IsWindowEnabled, (HWND hwnd), (hwnd))
383DeclWinFunc_CACHE_resetError(BOOL, IsWindowVisible, (HWND hwnd), (hwnd))
384DeclWinFunc_CACHE_resetError(BOOL, IsWindowShowing, (HWND hwnd), (hwnd))
385
386/* No die()ing on error */
387DeclWinFunc_CACHE_survive(BOOL, IsWindow, (HAB hab, HWND hwnd), (hab, hwnd))
388
389/* These functions are called frow complicated wrappers: */
390ULONG (*pWinQuerySwitchList) (HAB hab, PSWBLOCK pswblk, ULONG usDataLength);
391ULONG (*pWinChangeSwitchEntry) (HSWITCH hsw, __const__ SWCNTRL *pswctl);
392HWND (*pWinWindowFromPoint)(HWND hwnd, __const__ POINTL *pptl, BOOL fChildren);
393
394
395/* These functions have different names/signatures than what is
396 declared above */
397#define QueryFocusWindow QueryFocus
398#define FocusWindow_set(hwndFocus, hwndDesktop) SetFocus(hwndDesktop, hwndFocus)
399#define WindowPos_set(hwnd, x, y, fl, cx, cy, hwndInsertBehind) \
400 SetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl)
401#define myWinQueryWindowPtr(hwnd, i) ((ULONG)QueryWindowPtr(hwnd, i))
402#define _ClipbrdData_set SetClipbrdData
403#define ClipbrdOwner_set SetClipbrdOwner
404#define ClipbrdViewer_set SetClipbrdViewer
405
406int
407WindowText_set(HWND hwnd, char* text)
408{
409 return !CheckWinError(myWinSetWindowText(hwnd, text));
410}
411
412SV *
413myQueryWindowText(HWND hwnd)
414{
415 LONG l = QueryWindowTextLength(hwnd), len;
416 SV *sv;
417 STRLEN n_a;
418
419 if (l == 0) {
420 if (Perl_rc) /* Last error */
421 return &PL_sv_undef;
422 return &PL_sv_no;
423 }
424 sv = newSVpvn("", 0);
425 SvGROW(sv, l + 1);
426 len = QueryWindowText(hwnd, l + 1, SvPV_force(sv, n_a));
427 if (len != l) {
428 Safefree(sv);
429 croak("WinQueryWindowText() uncompatible with WinQueryWindowTextLength()");
430 }
431 SvCUR_set(sv, l);
432 return sv;
433}
434
435SWP
436QueryWindowSWP_(HWND hwnd)
437{
438 SWP swp;
439
440 if (!QueryWindowPos(hwnd, &swp))
441 croak("WinQueryWindowPos() error");
442 return swp;
443}
444
445SV *
446QueryWindowSWP(HWND hwnd)
447{
448 SWP swp = QueryWindowSWP_(hwnd);
449
450 return newSVpvn((char*)&swp, sizeof(swp));
451}
452
453SV *
454myQueryClassName(HWND hwnd)
455{
456 SV *sv = newSVpvn("",0);
457 STRLEN l = 46, len = 0, n_a;
458
459 while (l + 1 >= len) {
460 if (len)
461 len = 2*len + 10; /* Grow quick */
462 else
463 len = l + 2;
464 SvGROW(sv, len);
465 l = QueryClassName(hwnd, len, SvPV_force(sv, n_a));
466 }
467 SvCUR_set(sv, l);
468 return sv;
469}
470
471HWND
472WindowFromPoint(long x, long y, HWND hwnd, BOOL fChildren)
473{
474 POINTL ppl;
475
476 ppl.x = x; ppl.y = y;
477 if (!pWinWindowFromPoint)
478 AssignFuncPByORD(pWinWindowFromPoint, ORD_WinWindowFromPoint);
479 return SaveWinError(pWinWindowFromPoint(hwnd, &ppl, fChildren));
480}
481
482static HSWITCH
483switch_of(HWND hwnd, PID pid)
484{
485 HSWITCH hSwitch;
486
487#ifndef __KLIBC__
488 if (!(_emx_env & 0x200))
489 croak("switch_entry not implemented on DOS"); /* not OS/2. */
490#endif
491 if (CheckWinError(hSwitch =
492 myWinQuerySwitchHandle(hwnd, pid)))
493 croak_with_os2error("WinQuerySwitchHandle");
494 return hSwitch;
495}
496
497
498static void
499fill_swentry(SWENTRY *swentryp, HWND hwnd, PID pid)
500{
501 int rc;
502 HSWITCH hSwitch = switch_of(hwnd, pid);
503
504 swentryp->hswitch = hSwitch;
505 if (CheckOSError(myWinQuerySwitchEntry(hSwitch, &swentryp->swctl)))
506 croak_with_os2error("WinQuerySwitchEntry");
507}
508
509static void
510fill_swentry_default(SWENTRY *swentryp)
511{
512 fill_swentry(swentryp, NULLHANDLE, getpid());
513}
514
515static SV*
516myWinQueryActiveDesktopPathname()
517{
518 SV *buf = newSVpv("",0);
519 STRLEN n_a;
520
521 SvGROW(buf, MAXPATHLEN);
522 QueryActiveDesktopPathname(SvPV(buf,n_a), MAXPATHLEN);
523 SvCUR_set(buf, strlen(SvPV(buf, n_a)));
524 return buf;
525}
526
527SV *
528myWinQueryAtomName(ATOM atom, HATOMTBL hAtomTbl)
529{
530 ULONG len = QueryAtomLength(hAtomTbl, atom);
531 SV *sv = newSVpvn("",0);
532 STRLEN n_a;
533
534 SvGROW(sv, len + 1);
535 QueryAtomName(hAtomTbl, atom, SvPV(sv, n_a), len);
536 SvCUR_set(sv, len);
537 *SvEND(sv) = 0;
538 return sv;
539}
540
541#define myWinQueryClipbrdFmtInfo QueryClipbrdFmtInfo
542
543/* Put data into shared memory, then call SetClipbrdData */
544void
545ClipbrdData_set(SV *sv, int convert_nl, unsigned long fmt, unsigned long rgfFmtInfo, HAB hab)
546{
547 STRLEN len;
548 char *buf = SvPV_force(sv, len);
549 char *pByte = 0, *s = buf, c;
550 ULONG nls = 0, rc;
551
552 if (convert_nl) {
553 while ((c = *s++)) {
554 if (c == '\r' && *s == '\n')
555 s++;
556 else if (c == '\n')
557 nls++;
558 }
559 }
560
561 if (CheckOSError(DosAllocSharedMem((PPVOID)&pByte, 0, len + nls + 1,
562 PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE | OBJ_GETTABLE)))
563 croak_with_os2error("ClipbrdData_set: DosAllocSharedMem error");
564
565 if (!nls)
566 memcpy(pByte, buf, len + 1);
567 else {
568 char *t = pByte, *e = buf + len;
569
570 while (buf < e) {
571 c = *t++ = *buf++;
572 if (c == '\n' && (t == pByte + 1 || t[-2] != '\r'))
573 t[-1] = '\r', *t++ = '\n';
574 }
575 }
576
577 if (!SetClipbrdData(hab, (ULONG)pByte, fmt, rgfFmtInfo)) {
578 DosFreeMem((PPVOID)&pByte);
579 croak_with_os2error("ClipbrdData_set: WinSetClipbrdData error");
580 }
581}
582
583#if 0
584
585ULONG
586myWinMessageBox(HWND hwndParent, HWND hwndOwner, PCSZ pszText, PCSZ pszCaption, ULONG idWindow, ULONG flStyle)
587{
588 ULONG rc = MessageBox(hwndParent, hwndOwner, pszText, pszCaption,
589 idWindow, flStyle);
590
591 if (rc == MBID_ERROR)
592 rc = 0;
593 if (CheckWinError(rc))
594 croak_with_os2error("MessageBox");
595 return rc;
596}
597
598ULONG
599myWinMessageBox2(HWND hwndParent, HWND hwndOwner, PCSZ pszText,
600 PCSZ pszCaption, ULONG idWindow, PMB2INFO pmb2info)
601{
602 ULONG rc = MessageBox2(hwndParent, hwndOwner, pszText, pszCaption, idWindow, pmb2info);
603
604 if (rc == MBID_ERROR)
605 rc = 0;
606 if (CheckWinError(rc))
607 croak_with_os2error("MessageBox2");
608 return rc;
609}
610#endif
611
612/* static ULONG (* APIENTRY16 pDosSmSetTitle)(ULONG, PSZ); */
613ULONG _THUNK_FUNCTION(DosSmSetTitle)(ULONG, PSZ);
614
615#if 0 /* Does not work. */
616static ULONG (*pDosSmSetTitle)(ULONG, PSZ);
617
618static void
619sesmgr_title_set(char *s)
620{
621 SWENTRY swentry;
622 static HMODULE hdosc = 0;
623 BYTE buf[20];
624 long rc;
625
626 fill_swentry_default(&swentry);
627 if (!pDosSmSetTitle || !hdosc) {
628 if (CheckOSError(DosLoadModule(buf, sizeof buf, "sesmgr", &hdosc)))
629 croak("Cannot load SESMGR: no `%s'", buf);
630 if (CheckOSError(DosQueryProcAddr(hdosc, 0, "DOSSMSETTITLE",
631 (PFN*)&pDosSmSetTitle)))
632 croak("Cannot load SESMGR.DOSSMSETTITLE, err=%ld", rc);
633 }
634/* (pDosSmSetTitle)(swcntrl.idSession,s); */
635 rc = ((USHORT)
636 (_THUNK_PROLOG (2+4);
637 _THUNK_SHORT (swcntrl.idSession);
638 _THUNK_FLAT (s);
639 _THUNK_CALLI (*pDosSmSetTitle)));
640 if (CheckOSError(rc))
641 warn("*DOSSMSETTITLE: err=%ld, ses=%ld, addr=%x, *paddr=%x",
642 rc, swcntrl.idSession, &_THUNK_FUNCTION(DosSmSetTitle),
643 pDosSmSetTitle);
644}
645
646#else /* !0 */
647
648static bool
649sesmgr_title_set(char *s)
650{
651 SWENTRY swentry;
652 long rc;
653
654 fill_swentry_default(&swentry);
655 rc = ((USHORT)
656 (_THUNK_PROLOG (2+4);
657 _THUNK_SHORT (swentry.swctl.idSession);
658 _THUNK_FLAT (s);
659 _THUNK_CALL (DosSmSetTitle)));
660#if 0
661 if (CheckOSError(rc))
662 warn("DOSSMSETTITLE: err=%ld, ses=%ld, addr=%x",
663 rc, swcntrl.idSession, _THUNK_FUNCTION(DosSmSetTitle));
664#endif
665 return !CheckOSError(rc);
666}
667#endif /* !0 */
668
669#if 0 /* Does not work. */
670USHORT _THUNK_FUNCTION(Win16SetTitle) ();
671
672static void
673set_title2(char *s)
674{
675 long rc;
676
677 rc = ((USHORT)
678 (_THUNK_PROLOG (4);
679 _THUNK_FLAT (s);
680 _THUNK_CALL (Win16SetTitle)));
681 if (CheckWinError(rc))
682 warn("Win16SetTitle: err=%ld", rc);
683}
684#endif
685
686SV *
687process_swentry(unsigned long pid, HWND hwnd)
688{
689 SWENTRY swentry;
690
691#ifndef __KLIBC__
692 if (!(_emx_env & 0x200))
693 croak("process_swentry not implemented on DOS"); /* not OS/2. */
694#endif
695
696 fill_swentry(&swentry, hwnd, pid);
697 return newSVpvn((char*)&swentry, sizeof(swentry));
698}
699
700SV *
701swentries_list()
702{
703 int num, n = 0;
704 STRLEN n_a;
705 PSWBLOCK pswblk;
706 SV *sv = newSVpvn("",0);
707
708#ifndef __KLIBC__
709 if (!(_emx_env & 0x200))
710 croak("swentries_list not implemented on DOS"); /* not OS/2. */
711#endif
712 if (!pWinQuerySwitchList)
713 AssignFuncPByORD(pWinQuerySwitchList, ORD_WinQuerySwitchList);
714 num = pWinQuerySwitchList(0, NULL, 0); /* HAB is not required */
715 if (!num)
716 croak("(Unknown) error during WinQuerySwitchList()");
717 /* Allow one extra entry to allow overflow detection (may happen
718 if the list has been changed). */
719 while (num > n) {
720 if (n == 0)
721 n = num + 1;
722 else
723 n = 2*num + 10; /* Enlarge quickly */
724 SvGROW(sv, sizeof(ULONG) + sizeof(SWENTRY) * n + 1);
725 pswblk = (PSWBLOCK) SvPV_force(sv, n_a);
726 num = pWinQuerySwitchList(0, pswblk, SvLEN(sv));
727 }
728 SvCUR_set(sv, sizeof(ULONG) + sizeof(SWENTRY) * num);
729 *SvEND(sv) = 0;
730 return sv;
731}
732
733SWENTRY
734swentry( char *title, HWND sw_hwnd, HWND icon_hwnd, HPROGRAM owner_phandle,
735 PID owner_pid, ULONG owner_sid, ULONG visible, ULONG nonswitchable,
736 ULONG jumpable, ULONG ptype, HSWITCH sw_entry)
737{
738 SWENTRY e;
739
740 strncpy(e.swctl.szSwtitle, title, MAXNAMEL);
741 e.swctl.szSwtitle[60] = 0;
742 e.swctl.hwnd = sw_hwnd;
743 e.swctl.hwndIcon = icon_hwnd;
744 e.swctl.hprog = owner_phandle;
745 e.swctl.idProcess = owner_pid;
746 e.swctl.idSession = owner_sid;
747 e.swctl.uchVisibility = ((visible ? SWL_VISIBLE : SWL_INVISIBLE)
748 | (nonswitchable ? SWL_GRAYED : 0));
749 e.swctl.fbJump = (jumpable ? SWL_JUMPABLE : 0);
750 e.swctl.bProgType = ptype;
751 e.hswitch = sw_entry;
752 return e;
753}
754
755SV *
756create_swentry( char *title, HWND owner_hwnd, HWND icon_hwnd, HPROGRAM owner_phandle,
757 PID owner_pid, ULONG owner_sid, ULONG visible, ULONG nonswitchable,
758 ULONG jumpable, ULONG ptype, HSWITCH sw_entry)
759{
760 SWENTRY e = swentry(title, owner_hwnd, icon_hwnd, owner_phandle, owner_pid,
761 owner_sid, visible, nonswitchable, jumpable, ptype,
762 sw_entry);
763
764 return newSVpvn((char*)&e, sizeof(e));
765}
766
767int
768change_swentrysw(SWENTRY *sw)
769{
770 ULONG rc; /* For CheckOSError */
771
772#ifndef __KLIBC__
773 if (!(_emx_env & 0x200))
774 croak("change_entry() not implemented on DOS"); /* not OS/2. */
775#endif
776 if (!pWinChangeSwitchEntry)
777 AssignFuncPByORD(pWinChangeSwitchEntry, ORD_WinChangeSwitchEntry);
778 return !CheckOSError(pWinChangeSwitchEntry(sw->hswitch, &sw->swctl));
779}
780
781int
782change_swentry(SV *sv)
783{
784 STRLEN l;
785 PSWENTRY pswentry = (PSWENTRY)SvPV(sv, l);
786
787 if (l != sizeof(SWENTRY))
788 croak("Wrong structure size %ld!=%ld in change_swentry()", (long)l, (long)sizeof(SWENTRY));
789 return change_swentrysw(pswentry);
790}
791
792
793#define swentry_size() (sizeof(SWENTRY))
794
795void
796getscrsize(int *wp, int *hp)
797{
798 int i[2];
799
800 _scrsize(i);
801 *wp = i[0];
802 *hp = i[1];
803}
804
805/* Force vio to not cross 64K-boundary: */
806#define VIO_FROM_VIOB \
807 vio = viob; \
808 if (!_THUNK_PTR_STRUCT_OK(vio)) \
809 vio++
810
811bool
812scrsize_set(int w, int h)
813{
814 VIOMODEINFO viob[2], *vio;
815 ULONG rc;
816
817 VIO_FROM_VIOB;
818
819 if (h == -9999)
820 h = w, w = 0;
821 vio->cb = sizeof(*vio);
822 if (CheckOSError(VioGetMode( vio, 0 )))
823 return 0;
824
825 if( w > 0 )
826 vio->col = (USHORT)w;
827
828 if( h > 0 )
829 vio->row = (USHORT)h;
830
831 vio->cb = 8;
832 if (CheckOSError(VioSetMode( vio, 0 )))
833 return 0;
834 return 1;
835}
836
837void
838cursor(int *sp, int *ep, int *wp, int *ap)
839{
840 VIOCURSORINFO viob[2], *vio;
841 ULONG rc;
842
843 VIO_FROM_VIOB;
844
845 if (CheckOSError(VioGetCurType( vio, 0 )))
846 croak_with_os2error("VioGetCurType() error");
847
848 *sp = vio->yStart;
849 *ep = vio->cEnd;
850 *wp = vio->cx;
851 *ep = vio->attr;
852}
853
854bool
855cursor__(int is_a)
856{
857 int s,e,w,a;
858
859 cursor(&s, &e, &w, &a);
860 if (is_a)
861 return a;
862 else
863 return w;
864}
865
866bool
867cursor_set(int s, int e, int w, int a)
868{
869 VIOCURSORINFO viob[2], *vio;
870 ULONG rc;
871
872 VIO_FROM_VIOB;
873
874 vio->yStart = s;
875 vio->cEnd = e;
876 vio->cx = w;
877 vio->attr = a;
878 return !CheckOSError(VioSetCurType( vio, 0 ));
879}
880
881static int
882bufsize(void)
883{
884#if 1
885 VIOMODEINFO viob[2], *vio;
886 ULONG rc;
887
888 VIO_FROM_VIOB;
889
890 vio->cb = sizeof(*vio);
891 if (CheckOSError(VioGetMode( vio, 0 )))
892 croak_with_os2error("Can't get size of buffer for screen");
893#if 0 /* buf=323552247, full=1118455, partial=0 */
894 croak("Lengths: buf=%d, full=%d, partial=%d",vio->buf_length,vio->full_length,vio->partial_length);
895 return newSVpvn((char*)vio->buf_addr, vio->full_length);
896#endif
897 return vio->col * vio->row * 2; /* How to get bytes/cell? 2 or 4? */
898#else /* 0 */
899 int i[2];
900
901 _scrsize(i);
902 return i[0]*i[1]*2;
903#endif /* 0 */
904}
905
906SV*
907_kbdChar(unsigned int nowait, int handle)
908{
909 KBDKEYINFO viob[2], *vio;
910 ULONG rc;
911
912 VIO_FROM_VIOB;
913
914 if (nowait > 2)
915 croak("unexpected nowait");
916 if (CheckOSError(nowait == 2
917 ? KbdPeek( vio, handle )
918 : KbdCharIn( vio, nowait == 1, handle )))
919 croak_with_os2error("Can't _kbdChar");
920 return newSVpvn((char*)vio, sizeof(*vio));
921}
922
923SV*
924_kbdStatus(int handle)
925{
926 KBDINFO viob[2], *vio;
927 ULONG rc;
928
929 VIO_FROM_VIOB;
930
931 vio->cb = sizeof(*vio);
932 if (CheckOSError(KbdGetStatus( vio, handle )))
933 croak_with_os2error("Can't _kbdStatus");
934 return newSVpvn((char*)vio, sizeof(*vio));
935}
936
937void
938_kbdStatus_set(SV* sv, int handle)
939{
940 KBDINFO viob[2], *vio;
941 ULONG rc;
942 STRLEN l;
943 char *s = SvPV(sv, l);
944
945 VIO_FROM_VIOB;
946
947 if (l != sizeof(*vio))
948 croak("unexpected datasize");
949 Copy((KBDINFO*)s, vio, 1, KBDINFO);
950 if (vio->cb != sizeof(*vio))
951 croak("unexpected datasize");
952 if (CheckOSError(KbdSetStatus( vio, handle )))
953 croak_with_os2error("Can't kbdStatus_set()");
954}
955
956SV*
957_vioConfig(int which, int handle)
958{
959 struct {VIOCONFIGINFO i; short a[20];} viob[2], *vio;
960 ULONG rc;
961
962 VIO_FROM_VIOB;
963
964 vio->i.cb = 2;
965 if (CheckOSError(VioGetConfig( which, &vio->i, handle )))
966 croak_with_os2error("Can't get VIO config size");
967 if (vio->i.cb > sizeof(*vio))
968 vio->i.cb = sizeof(*vio);
969 if (CheckOSError(VioGetConfig( which, &vio->i, handle )))
970 croak_with_os2error("Can't get VIO config");
971 return newSVpvn((char*)vio, vio->i.cb);
972}
973
974SV*
975_vioMode(void)
976{
977 VIOMODEINFO viob[2], *vio;
978 ULONG rc;
979
980 VIO_FROM_VIOB;
981
982 vio->cb = sizeof(*vio);
983 if (CheckOSError(VioGetMode( vio, 0 )))
984 croak_with_os2error("Can't get VIO mode");
985 return newSVpvn((char*)vio, sizeof(*vio));
986}
987
988void
989_vioMode_set(SV* sv)
990{
991 VIOMODEINFO viob[2], *vio;
992 ULONG rc;
993 STRLEN l;
994 char *s = SvPV(sv, l);
995
996 VIO_FROM_VIOB;
997
998 Copy((VIOMODEINFO*)s, vio, 1, VIOMODEINFO);
999 if (vio->cb != sizeof(*vio) || l != vio->cb)
1000 croak("unexpected datasize");
1001 if (CheckOSError(VioSetMode( vio, 0 )))
1002 croak_with_os2error("Can't set VIO mode");
1003}
1004
1005SV*
1006vioFont(int type, int *w, int *h) /* 0 for actual RAM font, 1 for ROM font */
1007{
1008 VIOFONTINFO viob[2], *vio;
1009 ULONG rc;
1010 UCHAR b[1<<17];
1011 UCHAR *buf = b;
1012 SV *sv;
1013
1014 VIO_FROM_VIOB;
1015
1016 /* Should not cross 64K boundaries too: */
1017 if (((ULONG)buf) & 0xFFFF)
1018 buf += 0x10000 - (((ULONG)buf) & 0xFFFF);
1019
1020 vio->cb = sizeof(*vio);
1021 vio->type = type; /* BIOS or the loaded font. */
1022 vio->cbData = 0xFFFF; /* How large is my buffer? */
1023 vio->pbData = _libc_32to16(buf); /* Wants an 16:16 pointer */
1024 if (CheckOSError(VioGetFont( vio, 0 )))
1025 croak_with_os2error("Can't get VIO font");
1026 *w = vio->cxCell;
1027 *h = vio->cyCell;
1028 return newSVpvn(buf,vio->cbData);
1029}
1030
1031void
1032vioFont_set(SV *sv, int cellwidth, int cellheight, int type)
1033{
1034 VIOFONTINFO viob[2], *vio;
1035 ULONG rc;
1036 UCHAR b[1<<17];
1037 UCHAR *buf = b;
1038 STRLEN l;
1039 char *s = SvPV(sv, l);
1040
1041 VIO_FROM_VIOB;
1042
1043 /* Should not cross 64K boundaries too: */
1044 if (((ULONG)buf) & 0xFFFF)
1045 buf += 0x10000 - (((ULONG)buf) & 0xFFFF);
1046
1047 if (l > 0xFFFF)
1048 croak("length overflow of VIO font");
1049 if (l != (cellwidth + 7)/8 * cellheight * 256)
1050 warn("unexpected length of VIO font");
1051 vio->cb = sizeof(*vio);
1052 vio->type = type; /* BIOS or the loaded font. */
1053 vio->cbData = l; /* How large is my buffer? */
1054 vio->pbData = _libc_32to16(buf); /* Wants an 16:16 pointer */
1055 vio->cxCell = cellwidth;
1056 vio->cyCell = cellheight;
1057 Copy(s, buf, l, char);
1058
1059 if (CheckOSError(VioSetFont( vio, 0 )))
1060 croak_with_os2error("Can't set VIO font");
1061}
1062
1063/*
1064 uses use32,os2def,os2base,crt,defs;
1065 var Plt :Plt256;
1066 const Pal :VioPalState=(Cb:sizeof(VioPalState);rType:0;iFirst:0;
1067 Acolor:($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF));
1068 CReg:VioColorReg=(Cb:sizeof(VioColorReg);rType:3;FirstColorReg:0;
1069 NumColorRegs:256; ColorRegAddr:@Plt);
1070 var ii:Pointer;
1071 begin
1072 VioGetState(Pal,0);
1073 Pal.Acolor[09]:=$0F;
1074 Pal.Acolor[10]:=$A;
1075 Pal.Acolor[13]:=$2F;
1076 VioSetState(Pal,0); // ce smena EGA registrov
1077 asm
1078 lea eax,Plt
1079 call DosFlatToSel
1080 mov ii,eax
1081 end;
1082 CReg.ColorRegAddr:=ii;
1083 VioGetState(CReg,0);
1084 Plt[10,0]:=$00;
1085 Plt[10,1]:=$32;
1086 Plt[10,2]:=$2A;
1087 VioSetState(CReg,0); // a ce - VGA registrov
1088 end.
1089*/
1090
1091typedef union {
1092 VIOPALSTATE pal;
1093 struct { VIOPALSTATE pal; USHORT a[15]; } pal_padded;
1094 VIOOVERSCAN overscan;
1095 VIOINTENSITY intensity;
1096 VIOCOLORREG colorreg;
1097 struct { VIOCOLORREG reg; char rgb[3*256]; } colorreg_padded;
1098 VIOSETULINELOC lineloc;
1099 VIOSETTARGET target;
1100} my_VIOSTATE;
1101
1102int
1103vio_state_size(int what)
1104{
1105 static const char sizes[] = {
1106 sizeof(VIOPALSTATE),
1107 sizeof(VIOOVERSCAN),
1108 sizeof(VIOINTENSITY),
1109 sizeof(VIOCOLORREG),
1110 6, /* Random number: Reserved entry */
1111 sizeof(VIOSETULINELOC),
1112 sizeof(VIOSETTARGET)
1113 };
1114 if (what < 0 || what >= sizeof(sizes))
1115 croak("Unexpected VIO state type");
1116 return sizes[what];
1117}
1118
1119SV*
1120_vioState(int what, int first, int count)
1121{
1122 my_VIOSTATE viob[2], *vio;
1123 ULONG rc, size = vio_state_size(what);
1124
1125 VIO_FROM_VIOB;
1126
1127 vio->pal.cb = size;
1128 vio->pal.type = what;
1129 if (what == 0) {
1130 vio->pal.iFirst = first;
1131 if (first < 0 || first >= 16)
1132 croak("unexpected palette start value");
1133 if (count < 0 || count > 16)
1134 croak("unexpected palette count");
1135 vio->pal.cb = (size += (count - 1) * sizeof(short));
1136 } else if (what == 3) {
1137 /* Wants an 16:16 pointer */
1138 if (count < 0 || count > 256)
1139 croak("unexpected palette count");
1140 vio->colorreg.colorregaddr = (PCH)_libc_32to16(vio->colorreg_padded.rgb);
1141 vio->colorreg.numcolorregs = count; /* 256 is max */
1142 vio->colorreg.firstcolorreg = first;
1143 size += 3 * count;
1144 }
1145 if (CheckOSError(VioGetState( (void*)vio, 0 )))
1146 croak_with_os2error("Can't get VIO state");
1147 return newSVpvn((char*)vio, size);
1148}
1149
1150void
1151_vioState_set(SV *sv)
1152{
1153 my_VIOSTATE viob[2], *ovio = (my_VIOSTATE*)SvPV_nolen(sv), *vio = ovio;
1154 int what = ovio->pal.type, cb = ovio->pal.cb;
1155 ULONG rc, size = vio_state_size(what);
1156 STRLEN l;
1157 char *s = SvPV(sv, l);
1158
1159 VIO_FROM_VIOB;
1160
1161 switch (what) {
1162 case 0:
1163 if ( cb < size || cb > size + 15*sizeof(SHORT) || l != cb)
1164 croak("unexpected datasize");
1165 size = l;
1166 break;
1167 case 3:
1168 if (l != cb + 3 * ovio->colorreg.numcolorregs || cb != size)
1169 croak("unexpected datasize");
1170 size = l;
1171 break;
1172 default:
1173 if (l != cb || l != size )
1174 croak("unexpected datasize");
1175 break;
1176 }
1177 Copy(s, (char*)vio, size, char);
1178 if (what == 3) /* We expect colors put after VIOCOLORREG */
1179 vio->colorreg.colorregaddr = (PCH)_libc_32to16(vio->colorreg_padded.rgb);
1180
1181 if (CheckOSError(VioSetState( (void*)vio, 0 )))
1182 croak_with_os2error("Can't set VIO state");
1183}
1184
1185SV *
1186screen(void)
1187{
1188 ULONG rc;
1189 USHORT bufl = bufsize();
1190 char b[(1<<16) * 3]; /* This/3 is enough for 16-bit calls, we need
1191 2x overhead due to 2 vs 4 issue, and extra
1192 64K due to alignment logic */
1193 char *buf = b;
1194
1195 if (((ULONG)buf) & 0xFFFF)
1196 buf += 0x10000 - (((ULONG)buf) & 0xFFFF);
1197 if ((sizeof(b) - (buf - b)) < 2*bufl)
1198 croak("panic: VIO buffer allocation");
1199 if (CheckOSError(VioReadCellStr( buf, &bufl, 0, 0, 0 )))
1200 return &PL_sv_undef;
1201 return newSVpvn(buf,bufl);
1202}
1203
1204bool
1205screen_set(SV *sv)
1206{
1207 ULONG rc;
1208 STRLEN l = SvCUR(sv), bufl = bufsize();
1209 char b[(1<<16) * 2]; /* This/2 is enough for 16-bit calls, we need
1210 extra 64K due to alignment logic */
1211 char *buf = b;
1212
1213 if (((ULONG)buf) & 0xFFFF)
1214 buf += 0x10000 - (((ULONG)buf) & 0xFFFF);
1215 if (!SvPOK(sv) || ((l != bufl) && (l != 2*bufl)))
1216 croak("Wrong size %d of saved screen data", SvCUR(sv));
1217 if ((sizeof(b) - (buf - b)) < l)
1218 croak("panic: VIO buffer allocation");
1219 Copy(SvPV(sv,l), buf, bufl, char);
1220 if (CheckOSError(VioWrtCellStr( buf, bufl, 0, 0, 0 )))
1221 return 0;
1222 return 1;
1223}
1224
1225int
1226process_codepages()
1227{
1228 ULONG cps[4], cp, rc;
1229
1230 if (CheckOSError(DosQueryCp( sizeof(cps), cps, &cp )))
1231 croak_with_os2error("DosQueryCp()");
1232 return cp;
1233}
1234
1235int
1236out_codepage()
1237{
1238 USHORT cp, rc;
1239
1240 if (CheckOSError(VioGetCp( 0, &cp, 0 )))
1241 croak_with_os2error("VioGetCp()");
1242 return cp;
1243}
1244
1245bool
1246out_codepage_set(int cp)
1247{
1248 USHORT rc;
1249
1250 return !(CheckOSError(VioSetCp( 0, cp, 0 )));
1251}
1252
1253int
1254in_codepage()
1255{
1256 USHORT cp, rc;
1257
1258 if (CheckOSError(KbdGetCp( 0, &cp, 0 )))
1259 croak_with_os2error("KbdGetCp()");
1260 return cp;
1261}
1262
1263bool
1264in_codepage_set(int cp)
1265{
1266 USHORT rc;
1267
1268 return !(CheckOSError(KbdSetCp( 0, cp, 0 )));
1269}
1270
1271bool
1272process_codepage_set(int cp)
1273{
1274 USHORT rc;
1275
1276 return !(CheckOSError(DosSetProcessCp( cp )));
1277}
1278
1279int
1280ppidOf(int pid)
1281{
1282 PQTOPLEVEL psi;
1283 int ppid;
1284
1285 if (!pid)
1286 return -1;
1287 psi = get_sysinfo(pid, QSS_PROCESS);
1288 if (!psi)
1289 return -1;
1290 ppid = psi->procdata->ppid;
1291 Safefree(psi);
1292 return ppid;
1293}
1294
1295int
1296sidOf(int pid)
1297{
1298 PQTOPLEVEL psi;
1299 int sid;
1300
1301 if (!pid)
1302 return -1;
1303 psi = get_sysinfo(pid, QSS_PROCESS);
1304 if (!psi)
1305 return -1;
1306 sid = psi->procdata->sessid;
1307 Safefree(psi);
1308 return sid;
1309}
1310
1311#define ulMPFROMSHORT(i) ((unsigned long)MPFROMSHORT(i))
1312#define ulMPVOID() ((unsigned long)MPVOID)
1313#define ulMPFROMCHAR(i) ((unsigned long)MPFROMCHAR(i))
1314#define ulMPFROM2SHORT(x1,x2) ((unsigned long)MPFROM2SHORT(x1,x2))
1315#define ulMPFROMSH2CH(s, c1, c2) ((unsigned long)MPFROMSH2CH(s, c1, c2))
1316#define ulMPFROMLONG(x) ((unsigned long)MPFROMLONG(x))
1317
1318#define _MessageBox MessageBox
1319#define _MessageBox2 MessageBox2
1320
1321MODULE = OS2::Process PACKAGE = OS2::Process
1322
1323PROTOTYPES: ENABLE
1324
1325unsigned long
1326constant(name,arg)
1327 char * name
1328 int arg
1329
1330char *
1331my_type()
1332
1333U32
1334file_type(path)
1335 char *path
1336
1337SV *
1338swentry_expand( SV *sv )
1339 PPCODE:
1340 {
1341 STRLEN l;
1342 PSWENTRY pswentry = (PSWENTRY)SvPV(sv, l);
1343
1344 if (l != sizeof(SWENTRY))
1345 croak("Wrong structure size %ld!=%ld in swentry_expand()", (long)l, (long)sizeof(SWENTRY));
1346 EXTEND(sp,11);
1347 PUSHs(sv_2mortal(newSVpv(pswentry->swctl.szSwtitle, 0)));
1348 PUSHs(sv_2mortal(newSVnv(pswentry->swctl.hwnd)));
1349 PUSHs(sv_2mortal(newSVnv(pswentry->swctl.hwndIcon)));
1350 PUSHs(sv_2mortal(newSViv(pswentry->swctl.hprog)));
1351 PUSHs(sv_2mortal(newSViv(pswentry->swctl.idProcess)));
1352 PUSHs(sv_2mortal(newSViv(pswentry->swctl.idSession)));
1353 PUSHs(sv_2mortal(newSViv(pswentry->swctl.uchVisibility & SWL_VISIBLE)));
1354 PUSHs(sv_2mortal(newSViv(pswentry->swctl.uchVisibility & SWL_GRAYED)));
1355 PUSHs(sv_2mortal(newSViv(pswentry->swctl.fbJump == SWL_JUMPABLE)));
1356 PUSHs(sv_2mortal(newSViv(pswentry->swctl.bProgType)));
1357 PUSHs(sv_2mortal(newSViv(pswentry->hswitch)));
1358 }
1359
1360SV *
1361create_swentry( char *title, unsigned long sw_hwnd, unsigned long icon_hwnd, unsigned long owner_phandle, unsigned long owner_pid, unsigned long owner_sid, unsigned long visible, unsigned long switchable, unsigned long jumpable, unsigned long ptype, unsigned long sw_entry)
1362PROTOTYPE: DISABLE
1363
1364int
1365change_swentry( SV *sv )
1366
1367bool
1368sesmgr_title_set(s)
1369 char *s
1370
1371SV *
1372process_swentry(unsigned long pid = getpid(), HWND hwnd = NULLHANDLE);
1373 PROTOTYPE: DISABLE
1374
1375int
1376swentry_size()
1377
1378SV *
1379swentries_list()
1380
1381void
1382ResetWinError()
1383
1384int
1385WindowText_set(HWND hwndFrame, char *title)
1386
1387bool
1388FocusWindow_set(HWND hwndFocus, HWND hwndDesktop = HWND_DESKTOP)
1389
1390bool
1391ShowWindow(HWND hwnd, bool fShow = TRUE)
1392
1393bool
1394EnableWindow(HWND hwnd, bool fEnable = TRUE)
1395
1396bool
1397PostMsg(HWND hwnd, unsigned long msg, unsigned long mp1 = 0, unsigned long mp2 = 0)
1398 C_ARGS: hwnd, msg, (MPARAM)mp1, (MPARAM)mp2
1399
1400bool
1401WindowPos_set(HWND hwnd, long x, long y, unsigned long fl = SWP_MOVE, long cx = 0, long cy = 0, HWND hwndInsertBehind = HWND_TOP)
1402 PROTOTYPE: DISABLE
1403
1404unsigned long
1405BeginEnumWindows(HWND hwnd)
1406
1407bool
1408EndEnumWindows(unsigned long henum)
1409
1410unsigned long
1411GetNextWindow(unsigned long henum)
1412
1413bool
1414IsWindowVisible(HWND hwnd)
1415
1416bool
1417IsWindowEnabled(HWND hwnd)
1418
1419bool
1420IsWindowShowing(HWND hwnd)
1421
1422unsigned long
1423QueryWindow(HWND hwnd, long cmd)
1424
1425unsigned long
1426IsChild(HWND hwnd, HWND hwndParent)
1427
1428unsigned long
1429WindowFromId(HWND hwndParent, unsigned long id)
1430
1431unsigned long
1432WindowFromPoint(long x, long y, HWND hwnd = HWND_DESKTOP, bool fChildren = TRUE)
1433PROTOTYPE: DISABLE
1434
1435unsigned long
1436EnumDlgItem(HWND hwndDlg, unsigned long code, HWND hwnd = NULLHANDLE)
1437 C_ARGS: hwndDlg, hwnd, code
1438
1439bool
1440EnableWindowUpdate(HWND hwnd, bool fEnable = TRUE)
1441
1442bool
1443SetWindowBits(HWND hwnd, long index, unsigned long flData, unsigned long flMask)
1444
1445bool
1446SetWindowPtr(HWND hwnd, long index, unsigned long p)
1447 C_ARGS: hwnd, index, (PVOID)p
1448
1449bool
1450SetWindowULong(HWND hwnd, long index, unsigned long i)
1451
1452bool
1453SetWindowUShort(HWND hwnd, long index, unsigned short i)
1454
1455bool
1456IsWindow(HWND hwnd, HAB hab = Acquire_hab())
1457 C_ARGS: hab, hwnd
1458
1459BOOL
1460ActiveWindow_set(HWND hwnd, HWND hwndDesktop = HWND_DESKTOP)
1461 CODE:
1462 RETVAL = SetActiveWindow(hwndDesktop, hwnd);
1463
1464unsigned long
1465LoadPointer(unsigned long idres, unsigned long hmod = 0, HWND hwndDesktop = HWND_DESKTOP)
1466 C_ARGS: hwndDesktop, hmod, idres
1467
1468int
1469out_codepage()
1470
1471bool
1472out_codepage_set(int cp)
1473
1474int
1475in_codepage()
1476
1477bool
1478in_codepage_set(int cp)
1479
1480SV *
1481screen()
1482
1483bool
1484screen_set(SV *sv)
1485
1486SV *
1487process_codepages()
1488 PPCODE:
1489 {
1490 ULONG cps[4], c, i = 0, rc;
1491
1492 if (CheckOSError(DosQueryCp( sizeof(cps), cps, &c )))
1493 c = 0;
1494 c /= sizeof(ULONG);
1495 if (c >= 3)
1496 EXTEND(sp, c);
1497 while (i < c)
1498 PUSHs(sv_2mortal(newSViv(cps[i++])));
1499 }
1500
1501bool
1502process_codepage_set(int cp)
1503
1504void
1505cursor(OUTLIST int stp, OUTLIST int ep, OUTLIST int wp, OUTLIST int ap)
1506 PROTOTYPE:
1507
1508bool
1509cursor_set(int s, int e, int w = cursor__(0), int a = cursor__(1))
1510
1511SV*
1512_kbdChar(int nowait = 0, int handle = 0)
1513
1514SV*
1515_kbdStatus(int handle = 0)
1516
1517void
1518_kbdStatus_set(SV *sv, int handle = 0)
1519
1520SV*
1521_vioConfig(int which = 0, int handle = 0)
1522
1523SV*
1524_vioMode()
1525
1526void
1527_vioMode_set(SV *buffer)
1528
1529SV*
1530_vioState(int what, int first = -1, int count = -1)
1531
1532void
1533_vioState_set(SV *buffer)
1534
1535SV*
1536vioFont( int type = 0, OUTLIST int w, OUTLIST int h)
1537
1538void
1539vioFont_set(SV *buffer, int cellwidth, int cellheight, int type = 0)
1540
1541NO_OUTPUT bool
1542_ClipbrdData_set(unsigned long ulData, unsigned long fmt = CF_TEXT, unsigned long rgfFmtInfo = ((fmt == CF_TEXT || fmt == CF_DSPTEXT) ? CFI_POINTER : CFI_HANDLE), HAB hab = perl_hab_GET())
1543 PROTOTYPE: DISABLE
1544 C_ARGS: hab, ulData, fmt, rgfFmtInfo
1545 POSTCALL:
1546 if (CheckWinError(RETVAL))
1547 croak_with_os2error("_ClipbrdData_set() error");
1548
1549void
1550ClipbrdData_set(SV *text, int convert_nl = 1, unsigned long fmt = CF_TEXT, unsigned long rgfFmtInfo = ((fmt == CF_TEXT || fmt == CF_DSPTEXT) ? CFI_POINTER : CFI_HANDLE), HAB hab = perl_hab_GET())
1551 PROTOTYPE: DISABLE
1552
1553void
1554ClipbrdOwner_set(HWND hwnd, HAB hab = perl_hab_GET())
1555 C_ARGS: hab, hwnd
1556
1557void
1558ClipbrdViewer_set(HWND hwnd, HAB hab = perl_hab_GET())
1559 C_ARGS: hab, hwnd
1560
1561unsigned long
1562EnumClipbrdFmts(unsigned long fmt = 0, HAB hab = perl_hab_GET())
1563 C_ARGS: hab, fmt
1564
1565unsigned long
1566AddAtom(char *pszAtomName, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1567 C_ARGS: hAtomTbl, pszAtomName
1568
1569unsigned long
1570FindAtom(char *pszAtomName, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1571 C_ARGS: hAtomTbl, pszAtomName
1572
1573unsigned long
1574DeleteAtom(char *pszAtomName, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1575 C_ARGS: hAtomTbl, pszAtomName
1576
1577void
1578Alarm(unsigned long rgfType = WA_ERROR, HWND hwndDesktop = HWND_DESKTOP)
1579 C_ARGS: hwndDesktop, rgfType
1580
1581void
1582FlashWindow(HWND hwndFrame, bool fFlash)
1583
1584MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = myQuery
1585
1586SV *
1587myQueryWindowText(HWND hwnd)
1588
1589SV *
1590myQueryClassName(HWND hwnd)
1591
1592MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = Query
1593
1594unsigned long
1595QueryFocusWindow(HWND hwndDesktop = HWND_DESKTOP)
1596
1597long
1598QueryWindowTextLength(HWND hwnd)
1599
1600SV *
1601QueryWindowSWP(HWND hwnd)
1602
1603unsigned long
1604QueryWindowULong(HWND hwnd, long index)
1605
1606unsigned short
1607QueryWindowUShort(HWND hwnd, long index)
1608
1609unsigned long
1610QueryActiveWindow(HWND hwnd = HWND_DESKTOP)
1611
1612unsigned long
1613QueryDesktopWindow(HAB hab = Acquire_hab(), unsigned long hdc = NULLHANDLE)
1614
1615unsigned long
1616QueryClipbrdData(unsigned long fmt = CF_TEXT, HAB hab = perl_hab_GET())
1617 C_ARGS: hab, fmt
1618 PROTOTYPE: DISABLE
1619
1620unsigned long
1621QueryClipbrdViewer(HAB hab = perl_hab_GET())
1622
1623unsigned long
1624QueryClipbrdOwner(HAB hab = perl_hab_GET())
1625
1626void
1627CloseClipbrd(HAB hab = perl_hab_GET())
1628
1629void
1630EmptyClipbrd(HAB hab = perl_hab_GET())
1631
1632bool
1633OpenClipbrd(HAB hab = perl_hab_GET())
1634
1635unsigned long
1636QueryAtomUsage(ATOM atom, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1637 C_ARGS: hAtomTbl, atom
1638
1639unsigned long
1640QueryAtomLength(ATOM atom, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1641 C_ARGS: hAtomTbl, atom
1642
1643unsigned long
1644QuerySystemAtomTable()
1645
1646unsigned long
1647QuerySysPointer(long lId, bool fCopy = 1, HWND hwndDesktop = HWND_DESKTOP)
1648 C_ARGS: hwndDesktop, lId, fCopy
1649
1650unsigned long
1651CreateAtomTable(unsigned long initial = 0, unsigned long buckets = 0)
1652
1653unsigned long
1654DestroyAtomTable(HATOMTBL hAtomTbl)
1655
1656
1657MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = myWinQuery
1658
1659unsigned long
1660myWinQueryWindowPtr(HWND hwnd, long index)
1661
1662NO_OUTPUT BOOL
1663myWinQueryWindowProcess(HWND hwnd, OUTLIST unsigned long pid, OUTLIST unsigned long tid)
1664 PROTOTYPE: $
1665 POSTCALL:
1666 if (CheckWinError(RETVAL))
1667 croak_with_os2error("WindowProcess() error");
1668
1669SV *
1670myWinQueryActiveDesktopPathname()
1671
1672void
1673myWinQueryClipbrdFmtInfo(OUTLIST unsigned long prgfFmtInfo, unsigned long fmt = CF_TEXT, HAB hab = perl_hab_GET())
1674 C_ARGS: hab, fmt, &prgfFmtInfo
1675
1676SV *
1677myWinQueryAtomName(ATOM atom, HATOMTBL hAtomTbl = QuerySystemAtomTable())
1678
1679MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = myWin
1680
1681int
1682myWinSwitchToProgram(HSWITCH hsw = switch_of(NULLHANDLE, getpid()))
1683 PREINIT:
1684 ULONG rc;
1685
1686#if 0
1687
1688unsigned long
1689myWinMessageBox(unsigned long pszText, char* pszCaption = "Perl script error", unsigned long flStyle = MB_CANCEL | MB_ICONHAND, HWND hwndParent = HWND_DESKTOP, HWND hwndOwner = HWND_DESKTOP, unsigned long idWindow = 0)
1690 C_ARGS: hwndParent, hwndOwner, pszText, pszCaption, idWindow, flStyle
1691
1692#endif
1693
1694unsigned long
1695_MessageBox(char* pszText, char* pszCaption = "Perl script error", unsigned long flStyle = MB_CANCEL | MB_INFORMATION | MB_MOVEABLE, HWND hwndParent = HWND_DESKTOP, HWND hwndOwner = NULLHANDLE, unsigned long idWindow = 0)
1696 C_ARGS: hwndParent, hwndOwner, pszText, pszCaption, idWindow, flStyle
1697 POSTCALL:
1698 if (RETVAL == MBID_ERROR)
1699 RETVAL = 0;
1700
1701unsigned long
1702_MessageBox2(char *pszText, char* pmb2info, char *pszCaption, HWND hwndParent = HWND_DESKTOP, HWND hwndOwner = NULLHANDLE, unsigned long idWindow = 0)
1703 C_ARGS: hwndParent, hwndOwner, pszText, pszCaption, idWindow, (PMB2INFO)pmb2info
1704 POSTCALL:
1705 if (RETVAL == MBID_ERROR)
1706 RETVAL = 0;
1707
1708MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = myWinQuery
1709
1710MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = get
1711
1712int
1713getppid()
1714
1715int
1716ppidOf(int pid = getpid())
1717
1718int
1719sidOf(int pid = getpid())
1720
1721void
1722getscrsize(OUTLIST int wp, OUTLIST int hp)
1723 PROTOTYPE:
1724
1725bool
1726scrsize_set(int w_or_h, int h = -9999)
1727
1728void
1729get_InvalidateRect(HWND hwnd, char *prcl, bool fIncludeChildren)
1730
1731void
1732get_CreateFrameControls(HWND hwndFrame, char *pfcdata, char* pszTitle)
1733
1734MODULE = OS2::Process PACKAGE = OS2::Process PREFIX = ul
1735
1736unsigned long
1737ulMPFROMSHORT(unsigned short i)
1738
1739unsigned long
1740ulMPVOID()
1741
1742unsigned long
1743ulMPFROMCHAR(unsigned char i)
1744
1745unsigned long
1746ulMPFROM2SHORT(unsigned short x1, unsigned short x2)
1747 PROTOTYPE: DISABLE
1748
1749unsigned long
1750ulMPFROMSH2CH(unsigned short s, unsigned char c1, unsigned char c2)
1751 PROTOTYPE: DISABLE
1752
1753unsigned long
1754ulMPFROMLONG(unsigned long x)
1755
Note: See TracBrowser for help on using the repository browser.