source: trunk/src/kernel32/console.cpp@ 3894

Last change on this file since 3894 was 3894, checked in by sandervl, 25 years ago

added support for auto exit of console apps

File size: 137.7 KB
Line 
1/* $Id: console.cpp,v 1.20 2000-07-25 18:22:47 sandervl Exp $ */
2
3/*
4 * Win32 Console API Translation for OS/2
5 *
6 * 1998/02/10 Patrick Haller (haller@zebra.fh-weingarten.de)
7 *
8 * @(#) console.cpp 1.0.0 1998/02/10 PH Start from scratch
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13
14
15#ifdef DEBUG
16#define DEBUG_LOCAL
17#define DEBUG_LOCAL2
18#endif
19
20//#undef DEBUG_LOCAL
21//#undef DEBUG_LOCAL2
22
23
24/*****************************************************************************
25 * Remark *
26 *****************************************************************************
27
28 - DWORD HandlerRoutine (DWORD dwCtrlType)
29 basically an exception handler routine. handles a few signals / excpts.
30 should be somewhere near the exception handling code ... :)
31
32 Hmm, however as PM applications don't really get a ctrl-c signal,
33 I'll have to do this on my own ...
34
35 - supply unicode<->ascii conversions for all the _A and _W function pairs.
36
37 - problem: we can't prevent thread1 from blocking the message queue ?
38 what will happen if a WinTerminate() is issued there ?
39 will the message queue be closed and provide smooth tasking ?
40 how will open32 react on this ?
41
42 - ECHO_LINE_INPUT / ReadFile blocks till CR
43
44 - scrollbars
45 * do some flowchart to exactly determine WHEN to use WHICH setting
46 and perform WHAT action
47
48 - clipboard support
49*/
50
51
52/*****************************************************************************
53 * Includes *
54 *****************************************************************************/
55
56#include <builtin.h>
57#include <stdlib.h>
58#include <string.h>
59
60#define INCL_WIN
61#define INCL_DOSMEMMGR
62#define INCL_DOSSEMAPHORES
63#define INCL_DOSERRORS
64#define INCL_DOSPROCESS
65#define INCL_DOSMODULEMGR
66#define INCL_VIO
67#define INCL_AVIO
68#include <os2wrap.h> //Odin32 OS/2 api wrappers
69
70#include <win32type.h>
71#include <misc.h>
72
73#include "conwin.h" // Windows Header for console only
74#include "HandleManager.h"
75#include "HMDevice.h"
76
77#include "console.h"
78#include "console2.h"
79#include "conin.h"
80#include "conout.h"
81#include "conbuffer.h"
82
83#include "conprop.h"
84#include "unicode.h"
85#include "heapstring.h"
86
87#define DBG_LOCALLOG DBG_console
88#include "dbglocal.h"
89
90
91/***********************************
92 * PH: fixups for missing os2win.h *
93 ***********************************/
94
95#include <os2sel.h>
96
97extern "C"
98{
99 void _System _O32_SetLastError(DWORD dwError);
100 DWORD _System _O32_GetLastError(void);
101 LPSTR _System _O32_GetCommandLine(void);
102 void _System _O32_ExitProcess(UINT exitcode);
103 HANDLE _System _O32_GetStdHandle(DWORD dwDevice);
104 DWORD _System _O32_GetFileType(HANDLE hFile);
105
106inline void SetLastError(DWORD a)
107{
108 USHORT sel = GetFS();
109
110 _O32_SetLastError(a);
111 SetFS(sel);
112}
113
114inline DWORD GetLastError()
115{
116 DWORD yyrc;
117 USHORT sel = GetFS();
118
119 yyrc = _O32_GetLastError();
120 SetFS(sel);
121
122 return yyrc;
123}
124
125inline LPSTR GetCommandLine()
126{
127 LPSTR yyrc;
128 USHORT sel = GetFS();
129
130 yyrc = _O32_GetCommandLine();
131 SetFS(sel);
132
133 return yyrc;
134}
135
136inline void ExitProcess(UINT a)
137{
138 USHORT sel = GetFS();
139
140 _O32_ExitProcess(a);
141 SetFS(sel);
142}
143
144inline HANDLE GetStdHandle(DWORD a)
145{
146 HANDLE yyrc;
147 USHORT sel = GetFS();
148
149 yyrc = _O32_GetStdHandle(a);
150 SetFS(sel);
151
152 return yyrc;
153}
154
155inline DWORD GetFileType(HANDLE a)
156{
157 DWORD yyrc;
158 USHORT sel = GetFS();
159
160 yyrc = _O32_GetFileType(a);
161 SetFS(sel);
162
163 return yyrc;
164}
165
166}
167
168/*****************************************************************************
169 * Defines *
170 *****************************************************************************/
171
172/*****************************************************************************
173 * Structures *
174 *****************************************************************************/
175
176
177/*****************************************************************************
178 * Process Global Structures *
179 *****************************************************************************/
180
181static ICONSOLEGLOBALS ConsoleGlobals;
182static ICONSOLEINPUT ConsoleInput;
183
184
185/*****************************************************************************
186 * Prototypes *
187 *****************************************************************************/
188
189
190/*****************************************************************************
191 * Name : iConsoleInputQueueLock
192 * Purpose : lock the input queue to ensure correct event sequence
193 * Parameters:
194 * Variables :
195 * Result :
196 * Remark :
197 * Status :
198 *
199 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
200 *****************************************************************************/
201
202void static iConsoleInputQueueLock()
203{
204 APIRET rc;
205
206 rc = DosRequestMutexSem(ConsoleInput.hmtxInputQueue,
207 SEM_INDEFINITE_WAIT);
208 if (rc != NO_ERROR)
209 dprintf(("KERNEL32: Console:iConsoleInputQueueLock error %08xh\n",
210 rc));
211}
212
213
214/*****************************************************************************
215 * Name : iConsoleInputQueueUnlock
216 * Purpose : unlock the input queue
217 * Parameters:
218 * Variables :
219 * Result :
220 * Remark :
221 * Status :
222 *
223 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
224 *****************************************************************************/
225
226void static iConsoleInputQueueUnlock()
227{
228 APIRET rc;
229
230 rc = DosReleaseMutexSem(ConsoleInput.hmtxInputQueue);
231 if (rc != NO_ERROR)
232 dprintf(("KERNEL32: Console:iConsoleInputQueueUnlock error %08xh\n",
233 rc));
234}
235
236
237/*****************************************************************************
238 * Name :
239 * Purpose :
240 * Parameters:
241 * Variables :
242 * Result :
243 * Remark :
244 * Status :
245 *
246 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
247 *****************************************************************************/
248
249APIRET iConsoleInit(void) /* creation of the console subsystem */
250{
251 APIRET rc; /* API return code */
252 ULONG ulPostCount; /* semaphore post counter */
253
254
255
256 if (ConsoleGlobals.hevConsole != NULLHANDLE) /* we're already initialized ?*/
257 return (NO_ERROR); /* then abort immediately */
258
259 /* create console synchronization semaphore */
260 rc = DosCreateEventSem (NULL,
261 &ConsoleGlobals.hevConsole,
262 0L, /* semaphore is private */
263 FALSE); /* reset state */
264 if (rc != NO_ERROR) /* other error ? */
265 return (rc); /* raise error condition */
266
267
268 /* create console input queue semaphore */
269 rc = DosCreateEventSem (NULL,
270 &ConsoleInput.hevInputQueue,
271 0L, /* semaphore is private */
272 FALSE); /* reset state */
273 if (rc != NO_ERROR) /* other error ? */
274 {
275 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */
276 return (rc); /* raise error condition */
277 }
278
279
280 rc = DosCreateMutexSem(NULL,
281 &ConsoleInput.hmtxInputQueue,
282 0L,
283 FALSE);
284 if (rc != NO_ERROR) /* other error ? */
285 {
286 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */
287 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
288 return (rc); /* raise error condition */
289 }
290
291 /***************************************************************************
292 * Create pseudo-devices and initialize ConsoleGlobals *
293 ***************************************************************************/
294
295 rc = iConsoleDevicesRegister(); /* ensure devices are there */
296 if (rc != NO_ERROR) /* check for errors */
297 {
298 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */
299 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
300 return (rc); /* raise error condition */
301 }
302
303
304 /***************************************************************************
305 * Presentation Manager Initialization phase *
306 ***************************************************************************/
307
308 /* OK, we're about to initialize the console subsystem for this process. */
309 /* start message thread for console object window */
310 ConsoleGlobals.tidConsole = _beginthread(iConsoleMsgThread,
311 NULL,
312 12288,
313 NULL);
314 /* has the thread been created properly ? */
315 if (ConsoleGlobals.tidConsole == -1)
316 {
317 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
318 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */
319 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */
320 return (rc); /* raise error condition */
321 }
322 else
323 DosSetPriority(PRTYS_THREAD, /* set priority */
324 ConsoleGlobals.Options.ulConsoleThreadPriorityClass,
325 ConsoleGlobals.Options.ulConsoleThreadPriorityDelta,
326 ConsoleGlobals.tidConsole);
327
328
329 /* wait for the child thread to do it's initialization */
330 /* timeout isn't really useful */
331 rc = DosWaitEventSem(ConsoleGlobals.hevConsole,
332 SEM_INDEFINITE_WAIT);
333 if (rc != NO_ERROR) /* check for errors */
334 {
335 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
336 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */
337 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */
338 return (rc); /* raise error condition */
339 }
340
341 DosResetEventSem(ConsoleGlobals.hevConsole, /* reset event semaphore */
342 &ulPostCount);
343
344 rc = ConsoleGlobals.rcConsole; /* pass thru console thread's return code */
345
346 return (rc); /* OK */
347}
348
349
350/*****************************************************************************
351 * Name : ConsoleDevicesRegister
352 * Purpose : creates and registers console devices if the standard handles
353 * are not redirected to a file
354 * Parameters:
355 * Variables :
356 * Result :
357 * Remark :
358 * Status :
359 *
360 * Author : Patrick Haller [Tue, 1998/03/17 01:55]
361 *****************************************************************************/
362
363APIRET iConsoleDevicesRegister(void)
364{
365 DWORD dwType; /* device handle type */
366 HANDLE hStandardIn; /* stdin handle to CONIN$ */
367 HANDLE hStandardOut; /* stdout handle to CONOUT$ */
368 HANDLE hStandardError; /* stderr handle to CONOUT$ */
369
370 HMDeviceConsoleInClass *pHMDeviceConsoleIn;
371 HMDeviceConsoleOutClass *pHMDeviceConsoleOut;
372 HMDeviceConsoleBufferClass *pHMDeviceConsoleBuffer;
373
374 DWORD rc;
375
376 static fDevicesInitialized; /* have we been initialized already ? */
377
378 if (fDevicesInitialized == TRUE) /* OK, we're already done */
379 return (NO_ERROR);
380 else
381 fDevicesInitialized = TRUE;
382
383 dprintf(("KERNEL32:ConsoleDevicesRegister\n"));
384
385
386 /*************************************
387 * Initialize Console Window Options *
388 *************************************/
389
390 // load defaults
391 ConsolePropertyDefault(&ConsoleGlobals.Options);
392
393 ConsoleGlobals.ulTimerFrequency = 10; /* cursor + blitter timer frequency */
394
395 ConsoleGlobals.coordWindowSize.X = ConsoleGlobals.Options.coordDefaultSize.X;
396 ConsoleGlobals.coordWindowSize.Y = ConsoleGlobals.Options.coordDefaultSize.Y;
397 ConsoleGlobals.coordWindowPos.X = 0;
398 ConsoleGlobals.coordWindowPos.Y = 0;
399
400
401 ConsoleGlobals.flFrameFlags = FCF_SIZEBORDER | /* frame creation flags */
402 FCF_TITLEBAR |
403 FCF_SHELLPOSITION|
404 FCF_SYSMENU |
405 FCF_TASKLIST |
406 FCF_AUTOICON |
407 FCF_HORZSCROLL |
408 FCF_VERTSCROLL |
409 FCF_MINMAX;
410
411 /* generate copy of title */
412 ConsoleGlobals.pszWindowTitle = strdup(GetCommandLine());
413
414 /* obtain module handle to our resources */
415 rc = DosQueryModuleHandle("KERNEL32",
416 &ConsoleGlobals.hmodResource);
417 if (rc != NO_ERROR)
418 WriteLog("KERNEL32/CONSOLE: Can't get handle to KERNEL32 (%u).\n",
419 rc);
420
421 /* standard console input modes */
422 ConsoleInput.dwConsoleMode = ENABLE_LINE_INPUT |
423 ENABLE_PROCESSED_INPUT;
424 /* @@@PH ENABLE_ECHO_INPUT || ENABLE_MOUSE_INPUT; */
425
426 ConsoleGlobals.hConsoleBufferDefault = INVALID_HANDLE_VALUE;
427 ConsoleGlobals.hConsoleBuffer = INVALID_HANDLE_VALUE;
428
429
430 // defaults are effective, try to read and apply stored properties
431 if (ConsolePropertyLoad(&ConsoleGlobals.Options) == NO_ERROR)
432 ConsolePropertyApply(&ConsoleGlobals.Options);
433
434
435 /***************************************************************************
436 * Standard handles Initialization phase *
437 ***************************************************************************/
438
439 /* create devices and register devices with handlemanager */
440
441 pHMDeviceConsoleIn = new HMDeviceConsoleInClass("CONIN$",
442 &ConsoleInput,
443 &ConsoleGlobals);
444 rc = HMDeviceRegister ("CONIN$",
445 pHMDeviceConsoleIn);
446 if (rc != NO_ERROR) /* check for errors */
447 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONIN$ failed with %u.\n",
448 rc));
449
450
451 pHMDeviceConsoleOut = new HMDeviceConsoleOutClass("CONOUT$",
452 &ConsoleInput,
453 &ConsoleGlobals);
454 rc = HMDeviceRegister ("CONOUT$",
455 pHMDeviceConsoleOut);
456 if (rc != NO_ERROR) /* check for errors */
457 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONOUT$ failed with %u.\n",
458 rc));
459
460
461 pHMDeviceConsoleBuffer = new HMDeviceConsoleBufferClass("CONBUFFER$",
462 &ConsoleInput,
463 &ConsoleGlobals);
464 rc = HMDeviceRegister ("CONBUFFER$",
465 pHMDeviceConsoleBuffer);
466 if (rc != NO_ERROR) /* check for errors */
467 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONBUFFER$ failed with %u.\n",
468 rc));
469
470
471 /***********************************************************************
472 * initialize stdin handle *
473 ***********************************************************************/
474 hStandardIn = GetStdHandle(STD_INPUT_HANDLE);
475 dwType = GetFileType(hStandardIn);
476 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */
477 hStandardIn = HMCreateFile("CONIN$",
478 GENERIC_READ | GENERIC_WRITE,
479 FILE_SHARE_READ | FILE_SHARE_WRITE,
480 NULL,
481 0,
482 CONSOLE_TEXTMODE_BUFFER,
483 0);
484
485 HMSetStdHandle(STD_INPUT_HANDLE,
486 hStandardIn);
487
488 /***********************************************************************
489 * initialize stdout handle *
490 ***********************************************************************/
491 hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE);
492 dwType = GetFileType(hStandardOut);
493 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */
494 hStandardOut = HMCreateFile("CONOUT$",
495 GENERIC_READ | GENERIC_WRITE,
496 FILE_SHARE_READ | FILE_SHARE_WRITE,
497 NULL,
498 0,
499 CONSOLE_TEXTMODE_BUFFER,
500 0);
501
502 HMSetStdHandle(STD_OUTPUT_HANDLE,
503 hStandardOut);
504
505
506 /***********************************************************************
507 * initialize stderr handle *
508 ***********************************************************************/
509 hStandardError = GetStdHandle(STD_ERROR_HANDLE);
510 dwType = GetFileType(hStandardError);
511 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */
512 hStandardError = HMCreateFile("CONOUT$",
513 GENERIC_READ | GENERIC_WRITE,
514 FILE_SHARE_READ | FILE_SHARE_WRITE,
515 NULL,
516 0,
517 CONSOLE_TEXTMODE_BUFFER,
518 0);
519
520 HMSetStdHandle(STD_ERROR_HANDLE,
521 hStandardError);
522
523 return (NO_ERROR); /* OK */
524}
525
526
527/*****************************************************************************
528 * Name : static APIRET ConsoleTerminate
529 * Purpose : Shuts the OS/2 console subsystem down
530 * Parameters: VOID
531 * Variables :
532 * Result : OS/2 API return code
533 * Remark : That consolebuffer handle that became allocated as default
534 * screen buffer is lost here. This would be a serious memory
535 * leak if an application keeps opening and closing the console
536 * frequently.
537 * Status :
538 *
539 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
540 *****************************************************************************/
541
542ULONG iConsoleTerminate(VOID)
543{
544 APIRET rc;
545
546 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */
547 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
548 DosCloseMutexSem(ConsoleInput.hmtxInputQueue); /* close semaphore */
549
550
551 WinPostMsg (ConsoleGlobals.hwndFrame, /* force thread to terminate */
552 WM_CLOSE,
553 (MPARAM)NULL,
554 (MPARAM)NULL);
555
556 rc = DosWaitThread(&ConsoleGlobals.tidConsole,/* wait until thd terminates */
557 DCWW_WAIT);
558
559 /* close the consolebuffer handle */
560 HMCloseHandle(ConsoleGlobals.hConsoleBufferDefault);
561 free(ConsoleGlobals.pszWindowTitle); /* free previously allocated memory */
562
563 return (rc); /* OK */
564}
565
566
567/*****************************************************************************
568 * Name : static void ConsoleWaitClose
569 * Purpose : Wait for the user to close console window
570 * Parameters: VOID
571 * Variables :
572 * Result :
573 * Remark :
574 * Status :
575 *
576 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
577 *****************************************************************************/
578
579void iConsoleWaitClose(void)
580{
581 CHAR szBuffer[128]; /* buffer for the title */
582 BOOL fResult; /* result from subsequent calls to Win32 APIs */
583
584 /* check if there is a console window at all */
585 if (iConsoleIsActive() == FALSE)
586 return; /* nope */
587
588 strcpy (szBuffer, /* indicate console process has terminated */
589 "Completed: ");
590
591 fResult = GetConsoleTitleA(szBuffer + 11,/* 11 is length of Completed:_ */
592 sizeof(szBuffer) - 11);
593
594
595 /* Set new title: Win32 Console - Terminated */
596 fResult = SetConsoleTitleA(szBuffer);
597
598 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */
599 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
600 DosCloseMutexSem(ConsoleInput.hmtxInputQueue); /* close semaphore */
601
602
603 /* terminate console immediately ? */
604 if (ConsoleGlobals.Options.fTerminateAutomatically == FALSE) {
605 if(getenv("ODIN_AUTOEXITCONSOLE") == NULL) {
606 DosWaitThread(&ConsoleGlobals.tidConsole, /* wait until thd terminates */
607 DCWW_WAIT);
608 }
609 }
610}
611
612
613/*****************************************************************************
614 * Name : static BOOL ConsoleIsActive
615 * Purpose : Check if Console window is opened
616 * Parameters: VOID
617 * Variables :
618 * Result :
619 * Remark :
620 * Status :
621 *
622 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
623 *****************************************************************************/
624
625BOOL iConsoleIsActive(void)
626{
627 return (NULLHANDLE != ConsoleGlobals.hevConsole);
628}
629
630
631/*****************************************************************************
632 * Name : static VOID ConsoleMsgThread
633 * Purpose : Message handler thread for the console object window
634 * Parameters: PVOID pDummy
635 * Variables :
636 * Result : is placed in Globals.rcConsole
637 * Remark : the main thread has to wait for this thread
638 * Status :
639 *
640 * Author : Patrick Haller [Tue, 1998/02/10 02:49]
641 *****************************************************************************/
642
643VOID iConsoleMsgThread(PVOID pParameters)
644{
645 APIRET rc; /* API return code */
646
647
648 ConsoleGlobals.rcConsole = NO_ERROR; /* initialization */
649
650 ConsoleGlobals.hab = WinInitialize(0); /* enable thread for PM */
651 if (ConsoleGlobals.hab == NULLHANDLE) /* if anchor block allocation failed */
652 ConsoleGlobals.rcConsole = ERROR_NOT_ENOUGH_MEMORY;
653 else
654 {
655 /* create message queue */
656 ConsoleGlobals.hmq = WinCreateMsgQueue(ConsoleGlobals.hab,
657 0);
658 if (ConsoleGlobals.hmq == NULLHANDLE) /* if msg queue allocation failed */
659 {
660 WinTerminate(ConsoleGlobals.hab); /* stop thread from accessing PM */
661 ConsoleGlobals.rcConsole = ERROR_NOT_ENOUGH_MEMORY;
662 }
663 else
664 {
665 if (WinRegisterClass(ConsoleGlobals.hab, /* register our class with PM */
666 SZ_CONSOLE_CLASS,
667 iConsoleWindowProc,
668 CS_SIZEREDRAW,
669 0)
670 == FALSE)
671 {
672 WinDestroyMsgQueue(ConsoleGlobals.hmq); /* destroy message queue */
673 WinTerminate(ConsoleGlobals.hab); /* stop thread from accessing PM */
674 ConsoleGlobals.rcConsole = ERROR_NOT_ENOUGH_MEMORY;
675 }
676 else
677 {
678 ConsoleGlobals.hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
679 WS_VISIBLE,
680 &ConsoleGlobals.flFrameFlags,
681 SZ_CONSOLE_CLASS,
682 ConsoleGlobals.pszWindowTitle,
683 0,
684 ConsoleGlobals.hmodResource,
685 ID_CONSOLE_MAIN,
686 &ConsoleGlobals.hwndClient);
687 if (ConsoleGlobals.hwndFrame == NULLHANDLE) /* check window creation */
688 {
689 WinDestroyMsgQueue(ConsoleGlobals.hmq); /* destroy message queue */
690 WinTerminate(ConsoleGlobals.hab); /* stop thread from accessing PM */
691 ConsoleGlobals.rcConsole = ERROR_NOT_ENOUGH_MEMORY;
692 } /* WinCreateStdWindow */
693 } /* WinRegisterClass */
694 } /* WinCreateMsgQueue */
695 } /* WinInitialize */
696
697
698 DosPostEventSem(ConsoleGlobals.hevConsole); /* signal the main thread */
699
700
701 if (ConsoleGlobals.rcConsole != NO_ERROR) /* if we ran into a problem */
702 {
703 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
704 DosCloseEventSem(ConsoleGlobals.hevConsole); /* subsystem not running .. */
705 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */
706 return; /* abort the message queue thread immediately */
707 }
708
709
710 while( WinGetMsg(ConsoleGlobals.hab, /* message loop */
711 &ConsoleGlobals.qmsg,
712 NULLHANDLE,
713 0,
714 0) )
715 WinDispatchMsg(ConsoleGlobals.hab, /* dispatch the message */
716 &ConsoleGlobals.qmsg);
717
718 /* do the cleanup, destroy window, queue */
719 /* and stop thread from using PM */
720 WinDestroyWindow (ConsoleGlobals.hwndFrame);
721 WinDestroyMsgQueue(ConsoleGlobals.hmq);
722 WinTerminate (ConsoleGlobals.hab);
723
724 /* destruction of semaphore indicates console is shutdown */
725 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */
726 DosCloseEventSem(ConsoleGlobals.hevConsole);
727 DosCloseMutexSem(ConsoleInput.hmtxInputQueue); /* close semaphore */
728
729 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */
730 ConsoleInput.hevInputQueue = NULLHANDLE;
731 ConsoleInput.hmtxInputQueue = NULLHANDLE;
732
733 /* @@@PH we've got to exit the process here ! */
734 ExitProcess(1);
735}
736
737
738/*****************************************************************************
739 * Name : static MRESULT EXPENTRY ConsoleWindowProc
740 * Purpose : Window Procedure for OUR console window
741 * Parameters: HWND hwnd - window handle
742 * ULONG msg - message identifier
743 * MPARAM mp1 - message parameter 1
744 * MPARAM mp2 - message parameter 2
745 * Variables :
746 * Result : MRESULT for PM
747 * Remark :
748 * Status :
749 *
750 * Author : Patrick Haller [Tue, 1998/02/10 03:24]
751 *****************************************************************************/
752
753MRESULT EXPENTRY iConsoleWindowProc(HWND hwnd,
754 ULONG msg,
755 MPARAM mp1,
756 MPARAM mp2)
757{
758 static RECTL rcl; /* window rectangle */
759 static HPS hps;
760
761 switch(msg)
762 {
763 /*************************************************************************
764 * WM_CREATE window creation *
765 *************************************************************************/
766
767 case WM_CREATE:
768 WinPostMsg(hwnd, /* deferred initialization */
769 UM_CONSOLE_CREATE,
770 (MPARAM)NULL,
771 (MPARAM)NULL);
772 break;
773
774
775 case UM_CONSOLE_CREATE:
776 {
777 APIRET rc; /* API return code */
778 HWND hwndFrame; /* frame window handle */
779
780 /* subclass the frame window */
781 hwndFrame = ConsoleGlobals.hwndFrame;
782 ConsoleGlobals.pfnwpFrameOriginal = WinSubclassWindow(hwndFrame,
783 iConsoleFrameWindowProc);
784
785 ConsoleGlobals.hwndMenuConsole
786 = WinLoadMenu (hwnd, /* load context menue */
787 ConsoleGlobals.hmodResource,
788 ID_CONSOLE_MAIN);
789
790 /* set an icon for the dialog */
791 ConsoleGlobals.hPtrConsole = WinLoadPointer(HWND_DESKTOP,
792 ConsoleGlobals.hmodResource,
793 ID_CONSOLE_MAIN );
794 WinSendMsg(ConsoleGlobals.hwndFrame,
795 WM_SETICON,
796 (MPARAM)ConsoleGlobals.hPtrConsole,
797 0L );
798
799 /* determine handles of the horizontal / vertical scroll bars */
800 ConsoleGlobals.hwndVertScroll = WinWindowFromID(ConsoleGlobals.hwndFrame,
801 FID_VERTSCROLL);
802
803 ConsoleGlobals.hwndHorzScroll = WinWindowFromID(ConsoleGlobals.hwndFrame,
804 FID_HORZSCROLL);
805
806 /* the initial state of the controls is DETACHED */
807 WinSetParent(ConsoleGlobals.hwndHorzScroll, /* detach control */
808 HWND_OBJECT,
809 FALSE);
810
811 WinSetParent(ConsoleGlobals.hwndVertScroll, /* detach control */
812 HWND_OBJECT,
813 FALSE);
814
815
816 /* create AVIO presentation space */
817 rc = VioCreatePS(&ConsoleGlobals.hvpsConsole,
818 ConsoleGlobals.coordWindowSize.Y,
819 ConsoleGlobals.coordWindowSize.X,
820 0, /* format, must be 0 */
821 FORMAT_CGA,
822 0); /* template hvps, must be 0 */
823 if (rc != NO_ERROR) /* check errors */
824 WriteLog("KERNEL32/CONSOLE:VioCreatePS=%u\n",
825 rc);
826
827 /* PH 1998/02/12 this seems to be an OS/2 PM bug:
828 when doing a WinOpenWindowDC here, PM hangs. Seems it never gets back into
829 the message loop. To investigate and report to IBM
830 */
831
832 /* get a device context for the client window */
833 ConsoleGlobals.hdcConsole = WinOpenWindowDC(hwnd);
834 /* associate AVIO PS with the HDC */
835 rc = VioAssociate(ConsoleGlobals.hdcConsole,
836 ConsoleGlobals.hvpsConsole);
837 if (rc != NO_ERROR) /* check errors */
838 WriteLog("KERNEL32/CONSOLE:VioAssociate=%u\n",
839 rc);
840
841 iConsoleFontQuery(); /* query current cell sizes */
842
843 /* adjust window size and position */
844 HMDeviceRequest(ConsoleGlobals.hConsoleBuffer,
845 DRQ_INTERNAL_CONSOLEADJUSTWINDOW,
846 0,
847 0,
848 0,
849 0);
850
851 /* @@@PH if console is maximized - now switched on per default ! */
852 WinSetWindowPos (ConsoleGlobals.hwndFrame,
853 HWND_DESKTOP,
854 0,
855 0,
856 ConsoleGlobals.Options.coordDefaultPosition.X *
857 ConsoleGlobals.sCellCX +
858 2 * WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER),
859 ConsoleGlobals.Options.coordDefaultPosition.Y *
860 ConsoleGlobals.sCellCY +
861 WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) +
862 2 * WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER),
863 SWP_SIZE);
864
865 /* do we have to set the window position also ? */
866 if (ConsoleGlobals.Options.fSetWindowPosition == TRUE)
867 WinSetWindowPos (ConsoleGlobals.hwndFrame,
868 HWND_DESKTOP,
869 ConsoleGlobals.Options.coordDefaultPosition.X,
870 ConsoleGlobals.Options.coordDefaultPosition.Y,
871 0,
872 0,
873 SWP_MOVE);
874
875 /* start timer service for blitting and cursor blinking */
876 ConsoleGlobals.idTimer = WinStartTimer (ConsoleGlobals.hab,
877 hwnd,
878 CONSOLE_TIMER_ID, /* timer id */
879 ConsoleGlobals.ulTimerFrequency);
880
881 WinPostMsg (hwnd, /* send myself a start message so we get the first */
882 WM_TIMER, /* frame immediately */
883 (MPARAM)NULL,
884 (MPARAM)NULL);
885 }
886 break;
887
888
889 /*************************************************************************
890 * WM_DESTROY window destruction *
891 *************************************************************************/
892
893 case WM_DESTROY:
894 WinStopTimer (ConsoleGlobals.hab, /* anchor block */
895 hwnd,
896 ConsoleGlobals.idTimer); /* timer ID */
897
898 VioAssociate(NULL,
899 ConsoleGlobals.hvpsConsole); /* disassociates the AVIO PS */
900 VioDestroyPS(ConsoleGlobals.hvpsConsole); /* destroys the AVIO PS */
901
902 WinDestroyWindow(ConsoleGlobals.hwndMenuConsole);
903 WinDestroyPointer(ConsoleGlobals.hPtrConsole);
904 break;
905
906
907 /*************************************************************************
908 * WM_TIMER display cursor and update AVIO PS if required *
909 *************************************************************************/
910
911 case WM_TIMER:
912 /* check if console has to be updated */
913 if (ConsoleGlobals.fUpdateRequired == TRUE)
914 {
915 ConsoleGlobals.fUpdateRequired = FALSE; /* as soon as possible ! */
916
917 /* as device to map itself to the VIO buffer */
918 HMDeviceRequest(ConsoleGlobals.hConsoleBuffer,
919 DRQ_INTERNAL_CONSOLEBUFFERMAP,
920 0,
921 0,
922 0,
923 0);
924
925 { /* DEBUG */
926 APIRET rc;
927 /* and now bring it to the screen */
928 rc = VioShowPS(ConsoleGlobals.coordWindowSize.Y,
929 ConsoleGlobals.coordWindowSize.X,
930 0,
931 ConsoleGlobals.hvpsConsole);
932
933 dprintf(("KERNEL32::Console::1 VioShowPS(%u,%u,%u)=%u\n",
934 ConsoleGlobals.coordWindowSize.Y,
935 ConsoleGlobals.coordWindowSize.X,
936 ConsoleGlobals.hvpsConsole,
937 rc));
938 }
939
940 /* cursor is overwritten here ! */
941 HMDeviceRequest(ConsoleGlobals.hConsoleBuffer,
942 DRQ_INTERNAL_CONSOLECURSORSHOW,
943 CONSOLECURSOR_OVERWRITTEN,
944 0,
945 0,
946 0);
947 }
948 else
949 {
950 ConsoleGlobals.ulTimerCursor++; /* increase counter */
951 if (ConsoleGlobals.ulTimerCursor > ConsoleGlobals.Options.ucCursorDivisor)
952 {
953 ConsoleGlobals.ulTimerCursor = 0; /* reset counter */
954 /* let our cursor blink */
955 HMDeviceRequest(ConsoleGlobals.hConsoleBuffer,
956 DRQ_INTERNAL_CONSOLECURSORSHOW,
957 CONSOLECURSOR_BLINK,
958 0,
959 0,
960 0);
961 }
962 }
963 break;
964
965
966 /*************************************************************************
967 * WM_MINMAXFRAME handle window repaint in case of iconized window *
968 *************************************************************************/
969
970 case WM_MINMAXFRAME :
971 {
972 BOOL fShow = ! (((PSWP) mp1)->fl & SWP_MINIMIZE);
973 HENUM henum;
974 HWND hwndChild;
975
976 WinEnableWindowUpdate ( hwnd, FALSE );
977
978 for (henum=WinBeginEnumWindows(hwnd);
979 (hwndChild = WinGetNextWindow (henum)) != 0; )
980 WinShowWindow ( hwndChild, fShow );
981
982 WinEndEnumWindows ( henum );
983 WinEnableWindowUpdate ( hwnd, TRUE );
984 }
985 break;
986
987
988 /*************************************************************************
989 * WM_PAINT repaint the window *
990 *************************************************************************/
991 case WM_PAINT:
992 hps = WinBeginPaint(hwnd,
993 (HPS)NULL,
994 &rcl);
995 /* blit the whole AVIO presentation space */
996 { /* DEBUG */
997 APIRET rc;
998 /* and now bring it to the screen */
999 rc = VioShowPS(ConsoleGlobals.coordWindowSize.Y,
1000 ConsoleGlobals.coordWindowSize.X,
1001 0,
1002 ConsoleGlobals.hvpsConsole);
1003
1004 dprintf(("KERNEL32::Console::2 VioShowPS(%u,%u,%u)=%u\n",
1005 ConsoleGlobals.coordWindowSize.Y,
1006 ConsoleGlobals.coordWindowSize.X,
1007 ConsoleGlobals.hvpsConsole,
1008 rc));
1009 }
1010
1011 WinEndPaint(hps);
1012 break;
1013
1014
1015 /*************************************************************************
1016 * WM_SIZE resize the window *
1017 *************************************************************************/
1018 case WM_SIZE:
1019 {
1020 /* calculate scrollbars if neccessary */
1021 HMDeviceRequest(ConsoleGlobals.hConsoleBuffer,
1022 DRQ_INTERNAL_CONSOLEADJUSTWINDOW,
1023 0,
1024 0,
1025 0,
1026 0);
1027
1028 return WinDefAVioWindowProc(hwnd,
1029 (USHORT)msg,
1030 (ULONG)mp1,
1031 (ULONG)mp2);
1032 }
1033
1034
1035 /*************************************************************************
1036 * context menue *
1037 *************************************************************************/
1038 case WM_CONTEXTMENU:
1039 {
1040 WinPopupMenu (hwnd,
1041 hwnd,
1042 ConsoleGlobals.hwndMenuConsole,
1043 SHORT1FROMMP(mp1),
1044 SHORT2FROMMP(mp1),
1045 CM_CONSOLE_PROPERTIES, /* item id */
1046 PU_HCONSTRAIN |
1047 PU_VCONSTRAIN |
1048 PU_KEYBOARD |
1049 PU_MOUSEBUTTON1 |
1050 PU_MOUSEBUTTON2 |
1051 PU_POSITIONONITEM);
1052 }
1053 return (MPARAM)FALSE;
1054
1055
1056 /*************************************************************************
1057 * WM_COMMAND command processing *
1058 *************************************************************************/
1059 case WM_COMMAND:
1060 {
1061 switch(SHORT1FROMMP(mp1)) /* select appropriate identifier */
1062 {
1063 /* close console window, however we can't call ConsoleTerminate here!*/
1064 case CM_CONSOLE_EXIT:
1065 WinPostMsg (ConsoleGlobals.hwndFrame,
1066 WM_CLOSE,
1067 (MPARAM)NULL,
1068 (MPARAM)NULL);
1069
1070 return (MPARAM)FALSE;
1071
1072
1073 case CM_CONSOLE_REPAINT:
1074 WinInvalidateRect(ConsoleGlobals.hwndClient,/* redraw frame window */
1075 NULL,
1076 TRUE);
1077 return (MPARAM)FALSE;
1078
1079 /* open the properties dialog */
1080 case CM_CONSOLE_PROPERTIES:
1081 {
1082 ULONG ulResult; /* response from user */
1083
1084 ConsoleGlobals.Options.hmodResources = /* save module handle */
1085 ConsoleGlobals.hmodResource;
1086
1087 ulResult = WinDlgBox(HWND_DESKTOP,
1088 ConsoleGlobals.hwndClient,
1089 &ConsolePropertyDlgProc,
1090 ConsoleGlobals.hmodResource,
1091 DLG_CONSOLE_PROPERTIES,
1092 (PVOID)&ConsoleGlobals.Options);
1093 switch (ulResult)
1094 {
1095 case ID_BTN_SAVE:
1096 ConsolePropertySave(&ConsoleGlobals.Options);
1097 ConsolePropertyApply(&ConsoleGlobals.Options);
1098 break;
1099
1100 case ID_BTN_APPLY:
1101 ConsolePropertyApply(&ConsoleGlobals.Options);
1102 break;
1103
1104 default: break;
1105 }
1106
1107 return (MPARAM) FALSE;
1108 }
1109 }
1110 }
1111 break;
1112
1113
1114 /*************************************************************************
1115 * WM_CHAR keyboard char processing *
1116 *************************************************************************/
1117
1118 case WM_CHAR:
1119 iConsoleInputEventPushKey(mp1, /* push event into queue */
1120 mp2);
1121 break; /* enable further processing ! */
1122
1123
1124 /*************************************************************************
1125 * WM_SETFOCUS focus changing processing *
1126 *************************************************************************/
1127
1128 case WM_SETFOCUS:
1129 iConsoleInputEventPushFocus((BOOL)mp2); /* push event into queue */
1130 break; /* enable further processing ! */
1131
1132
1133 /*************************************************************************
1134 * WM_MOUSEMOVE mouse event processing *
1135 *************************************************************************/
1136
1137 case WM_MOUSEMOVE:
1138 case WM_BUTTON1UP:
1139 case WM_BUTTON1DOWN:
1140 case WM_BUTTON2UP:
1141 case WM_BUTTON2DOWN:
1142 case WM_BUTTON3UP:
1143 case WM_BUTTON3DOWN:
1144 case WM_BUTTON1DBLCLK:
1145 case WM_BUTTON2DBLCLK:
1146 case WM_BUTTON3DBLCLK:
1147 iConsoleInputEventPushMouse(msg,
1148 mp1, /* push event into queue */
1149 mp2);
1150 break; /* enable further processing ! */
1151 }
1152
1153 return WinDefWindowProc(hwnd, /* to default processing */
1154 msg,
1155 mp1,
1156 mp2);
1157}
1158
1159
1160/*****************************************************************************
1161 * Name : static MRESULT EXPENTRY ConsoleFrameWindowProc
1162 * Purpose : Window Procedure for OUR console frame window
1163 * Parameters: HWND hwnd - window handle
1164 * ULONG msg - message identifier
1165 * MPARAM mp1 - message parameter 1
1166 * MPARAM mp2 - message parameter 2
1167 * Variables :
1168 * Result : MRESULT for PM
1169 * Remark :
1170 * Status :
1171 *
1172 * Author : Patrick Haller [Tue, 1998/02/10 03:24]
1173 *****************************************************************************/
1174
1175MRESULT EXPENTRY iConsoleFrameWindowProc(HWND hwnd,
1176 ULONG msg,
1177 MPARAM mp1,
1178 MPARAM mp2)
1179{
1180 switch(msg)
1181 {
1182 /*************************************************************************
1183 * WM_QUERYTRACKINFO handling *
1184 *************************************************************************/
1185 case WM_QUERYTRACKINFO:
1186 {
1187 MRESULT mr; /* message result */
1188 PTRACKINFO pTrackInfo; /* frame window tracking information */
1189
1190 /* let the original code do the hard work first */
1191 mr = ConsoleGlobals.pfnwpFrameOriginal(hwnd,
1192 msg,
1193 mp1,
1194 mp2);
1195
1196 pTrackInfo = (PTRACKINFO)mp2; /* get track information */
1197
1198 /* @@@PH */
1199 pTrackInfo->ptlMinTrackSize.x = max(pTrackInfo->ptlMinTrackSize.x, 200);
1200 pTrackInfo->ptlMinTrackSize.y = max(pTrackInfo->ptlMinTrackSize.y, 100);
1201 pTrackInfo->ptlMaxTrackSize.x = min(pTrackInfo->ptlMaxTrackSize.x, ConsoleGlobals.coordMaxWindowPels.X);
1202 pTrackInfo->ptlMaxTrackSize.y = min(pTrackInfo->ptlMaxTrackSize.y, ConsoleGlobals.coordMaxWindowPels.Y);
1203
1204 return (mr); /* deliver result */
1205 }
1206 }
1207
1208 /* call original frame window procedure code */
1209 return (ConsoleGlobals.pfnwpFrameOriginal(hwnd,
1210 msg,
1211 mp1,
1212 mp2));
1213}
1214
1215
1216/*****************************************************************************
1217 * Name : static void ConsoleBufferMap
1218 * Purpose : draw a whole consolebuffer into the VIO space
1219 * Parameters: PCONSOLEBUFFER pConsoleBuffer
1220 * Variables :
1221 * Result : none
1222 * Remark :
1223 * Status :
1224 *
1225 * Author : Patrick Haller [Tue, 1998/02/17 12:57]
1226 *****************************************************************************/
1227
1228void iConsoleBufferMap(PCONSOLEBUFFER pConsoleBuffer)
1229{
1230 ULONG ulLine;
1231
1232 ULONG ulSizeX; /* blitting length and height */
1233 ULONG ulSizeY;
1234
1235 ulSizeX = 2 * min(ConsoleGlobals.coordWindowSize.X,
1236 pConsoleBuffer->coordBufferSize.X -
1237 ConsoleGlobals.coordWindowPos.X);
1238
1239 ulSizeY = min(ConsoleGlobals.coordWindowSize.Y,
1240 pConsoleBuffer->coordBufferSize.Y -
1241 ConsoleGlobals.coordWindowPos.Y);
1242
1243 /* check if we're called with non-existing line buffer */
1244 if (pConsoleBuffer->ppszLine == NULL)
1245 return;
1246
1247 for (ulLine = ConsoleGlobals.coordWindowPos.Y;
1248 ulLine < ulSizeY;
1249 ulLine++)
1250 VioWrtCellStr(pConsoleBuffer->ppszLine[ulLine] +
1251 ConsoleGlobals.coordWindowPos.X,
1252 ulSizeX,
1253 ulLine,
1254 0,
1255 ConsoleGlobals.hvpsConsole);
1256}
1257
1258
1259/*****************************************************************************
1260 * Name : static void ConsoleBufferFillLine
1261 * Purpose : fills a line with a certain output pattern
1262 * Parameters: ULONG ulPattern, PUSHORT pusTarget, ULONG ulSize
1263 * Variables :
1264 * Result : none
1265 * Remark :
1266 * Status :
1267 *
1268 * Author : Patrick Haller [Tue, 1998/02/17 12:57]
1269 *****************************************************************************/
1270
1271void iConsoleBufferFillLine(ULONG ulPattern,
1272 PUSHORT pusTarget,
1273 ULONG ulSize)
1274{
1275 ULONG ulCounter;
1276
1277 for (ulCounter = 0;
1278 ulCounter < (ulSize >> 1);
1279 ulCounter++,
1280 pusTarget+=2)
1281 *(PULONG)pusTarget = ulPattern;
1282
1283 if (ulSize & 0x00000001)
1284 *pusTarget = (USHORT)ulPattern;
1285}
1286
1287
1288/*****************************************************************************
1289 * Name : static void ConsoleBufferScrollUp
1290 * Purpose : scroll whole buffer n lines up,
1291 * fill new lines with default attribute
1292 * Parameters: PCONSOLEBUFFER pConsoleBuffer
1293 * ULONG ulLines
1294 * Variables :
1295 * Result : none
1296 * Remark :
1297 * Status :
1298 *
1299 * Author : Patrick Haller [Tue, 1998/02/17 12:57]
1300 *****************************************************************************/
1301
1302void iConsoleBufferScrollUp(PCONSOLEBUFFER pConsoleBuffer,
1303 ULONG ulLines)
1304{
1305 ULONG ulLine;
1306 ULONG ulPosition;
1307 ULONG ulScrollLine;
1308
1309 static ULONG ulUpdateCounter; /* counter for jump-scrolling */
1310
1311 /* calculate new line offset to the first line */
1312 pConsoleBuffer->ulScrollLineOffset += ulLines;
1313 pConsoleBuffer->ulScrollLineOffset %= pConsoleBuffer->coordBufferSize.Y;
1314
1315 /* do we have to scroll ? */
1316 if (ulLines < pConsoleBuffer->coordBufferSize.Y)
1317 {
1318 for (ulLine = 0; /* do the scrolling */
1319 ulLine < ConsoleGlobals.coordWindowSize.Y;
1320 ulLine++)
1321 {
1322 ulScrollLine = (ulLine + pConsoleBuffer->ulScrollLineOffset)
1323 % pConsoleBuffer->coordBufferSize.Y;
1324
1325 ulPosition = (ULONG)pConsoleBuffer->ppszLine
1326 + (pConsoleBuffer->coordBufferSize.Y * sizeof (PSZ) )
1327 + (pConsoleBuffer->coordBufferSize.X * 2 * ulScrollLine);
1328
1329 pConsoleBuffer->ppszLine[ulLine] = (PSZ)ulPosition;
1330 }
1331 }
1332
1333 /* enforce the upper limit */
1334 if (ulLines > pConsoleBuffer->coordBufferSize.Y)
1335 ulLines = pConsoleBuffer->coordBufferSize.Y;
1336
1337 ulPosition = ( ((ULONG)(pConsoleBuffer->ucDefaultAttribute) << 8) +
1338 ((ULONG)' ') +
1339 ((ULONG)(pConsoleBuffer->ucDefaultAttribute) << 24) +
1340 ((ULONG)' ' << 16) );
1341
1342 /* scroll the line index */
1343 for (ulLine = pConsoleBuffer->coordBufferSize.Y - ulLines;
1344 ulLine < pConsoleBuffer->coordBufferSize.Y;
1345 ulLine++)
1346 iConsoleBufferFillLine(ulPosition,
1347 (PUSHORT)(pConsoleBuffer->ppszLine[ulLine]),
1348 pConsoleBuffer->coordBufferSize.X);
1349
1350 /* this code ensures frequent screen updating, even if the timer prooves */
1351 /* to be to slow */
1352 ulUpdateCounter++;
1353 if (ulUpdateCounter > ConsoleGlobals.Options.ulUpdateLimit)
1354 {
1355 ulUpdateCounter = 0; /* reset the counter */
1356 iConsoleBufferMap(pConsoleBuffer);
1357 VioShowPS(ConsoleGlobals.coordWindowSize.Y,
1358 ConsoleGlobals.coordWindowSize.X,
1359 0,
1360 ConsoleGlobals.hvpsConsole);
1361
1362 ConsoleGlobals.fUpdateRequired = FALSE; /* no more required ... */
1363 }
1364}
1365
1366
1367/*****************************************************************************
1368 * Name : static APIRET ConsoleInputEventPush
1369 * Purpose : add an element to the console input queue
1370 * Parameters: PINPUT_RECORD pInputRecord
1371 * Variables :
1372 * Result : API returncode
1373 * Remark :
1374 * Status :
1375 *
1376 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1377 *****************************************************************************/
1378
1379APIRET iConsoleInputEventPush(PINPUT_RECORD pInputRecord)
1380{
1381 PINPUT_RECORD pirFree; /* pointer to free record */
1382 APIRET rc; /* API-returncode */
1383
1384#ifdef DEBUG_LOCAL2
1385 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPush(%08x).\n",
1386 pInputRecord));
1387#endif
1388
1389 iConsoleInputQueueLock();
1390 /* get free event */
1391 pirFree = &ConsoleInput.arrInputRecord[ConsoleInput.ulIndexFree];
1392 if (pirFree->EventType != 0x0000)
1393 {
1394 iConsoleInputQueueUnlock();
1395 return (ERROR_QUE_NO_MEMORY); /* queue is full ! */
1396 }
1397 /* put event in queue */
1398
1399 ConsoleInput.ulIndexFree++; /* update index counter */
1400 if (ConsoleInput.ulIndexFree >= CONSOLE_INPUTQUEUESIZE)
1401 ConsoleInput.ulIndexFree = 0;
1402
1403 ConsoleInput.ulEvents++; /* increate queue event counter */
1404
1405 iConsoleInputQueueUnlock();
1406
1407 memcpy(pirFree, /* copy data */
1408 pInputRecord,
1409 sizeof (INPUT_RECORD) );
1410 /* unblock reading threads */
1411 rc = DosPostEventSem(ConsoleInput.hevInputQueue);
1412 return (rc); /* OK */
1413}
1414
1415
1416/*****************************************************************************
1417 * Name : static APIRET ConsoleInputEventPop
1418 * Purpose : read first element from the console input queue
1419 * Parameters: PINPUT_RECORD pInputRecord
1420 * Variables :
1421 * Result : API returncode
1422 * Remark :
1423 * Status :
1424 *
1425 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1426 *****************************************************************************/
1427
1428APIRET iConsoleInputEventPop(PINPUT_RECORD pInputRecord)
1429{
1430 PINPUT_RECORD pirEvent; /* pointer to event record */
1431 APIRET rc; /* API-returncode */
1432
1433#ifdef DEBUG_LOCAL2
1434 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPop(%08x).\n",
1435 pInputRecord));
1436#endif
1437
1438 if (ConsoleInput.ulEvents == 0) /* empty console ? */
1439 return (ERROR_QUE_EMPTY); /* queue is empty ! */
1440
1441 iConsoleInputQueueLock();
1442 /* get first event */
1443 pirEvent = &ConsoleInput.arrInputRecord[ConsoleInput.ulIndexEvent];
1444 if (pirEvent->EventType == 0x0000)
1445 {
1446 iConsoleInputQueueUnlock();
1447 return (ERROR_QUE_EMPTY); /* queue is empty ! */
1448 }
1449
1450 if (ConsoleInput.ulEvents >= 0) /* decrease number of console events */
1451 ConsoleInput.ulEvents--;
1452
1453 ConsoleInput.ulIndexEvent++; /* update index counter */
1454 if (ConsoleInput.ulIndexEvent >= CONSOLE_INPUTQUEUESIZE)
1455 ConsoleInput.ulIndexEvent = 0;
1456
1457 /* put event in queue */
1458 memcpy(pInputRecord, /* copy data */
1459 pirEvent,
1460 sizeof (INPUT_RECORD) );
1461
1462 pirEvent->EventType = 0x0000; /* mark event as read = free */
1463
1464 iConsoleInputQueueUnlock();
1465
1466 return (NO_ERROR); /* OK */
1467}
1468
1469
1470/*****************************************************************************
1471 * Name : static APIRET ConsoleInputEventPushKey
1472 * Purpose : push key event into the queue
1473 * Parameters: MPARAM mp1, MPARAM mp2 from WM_CHAR processing
1474 * Variables :
1475 * Result : API returncode
1476 * Remark : @@@PH: 2nd table that learns codes automatically from "down"
1477 * messages from PM. With Alt-a, etc. it is 0 for "up" ?
1478 * Status :
1479 *
1480 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1481 *****************************************************************************/
1482
1483char tabVirtualKeyCodes[TABVIRTUALKEYCODES] =
1484{
1485/* --- PM key -- NT key --- */
1486 /* 0x00 */ 0,
1487 /* VK_BUTTON1 0x01 */ 0x01, /* WIN_VK_LBUTTON ??? */
1488 /* VK_BUTTON2 0x02 */ 0x02, /* WIN_VK_RBUTTON ??? */
1489 /* VK_BUTTON3 0x03 */ 0x04, /* WIN_VK_MBUTTON ??? */
1490 /* VK_BREAK 0x04 */ 0x03, /* WIN_VK_CANCEL ??? */
1491 /* VK_BACKSPACE 0x05 */ 0x08, /* WIN_VK_BACK */
1492 /* VK_TAB 0x06 */ 0x09, /* WIN_VK_TAB */
1493 /* VK_BACKTAB 0x07 */ 0,
1494 /* VK_NEWLINE 0x08 */ 0,
1495 /* VK_SHIFT 0x09 */ 0x10, /* WIN_VK_SHIFT */
1496 /* VK_CTRL 0x0A */ 0x11, /* WIN_VK_CONTROL */
1497 /* VK_ALT 0x0B */ 0x12, /* WIN_VK_MENU */
1498 /* VK_ALTGRAF 0x0C */ 0,
1499 /* VK_PAUSE 0x0D */ 0x13, /* WIN_VK_PAUSE */
1500 /* VK_CAPSLOCK 0x0E */ 0x14, /* WIN_VK_CAPITAL ??? */
1501 /* VK_ESC 0x0F */ 0x1b, /* WIN_VK_ESCAPE */
1502 /* VK_SPACE 0x10 */ 0x20, /* WIN_VK_SPACE */
1503 /* VK_PAGEUP 0x11 */ 0x21, /* WIN_VK_PRIOR ??? */
1504 /* VK_PAGEDOWN 0x12 */ 0x22, /* WIN_VK_NEXT ??? */
1505 /* VK_END 0x13 */ 0x23, /* WIN_VK_END */
1506 /* VK_HOME 0x14 */ 0x24, /* WIN_VK_HOME */
1507 /* VK_LEFT 0x15 */ 0x25, /* WIN_VK_LEFT */
1508 /* VK_UP 0x16 */ 0x26, /* WIN_VK_UP */
1509 /* VK_RIGHT 0x17 */ 0x27, /* WIN_VK_RIGHT */
1510 /* VK_DOWN 0x18 */ 0x28, /* WIN_VK_DOWN */
1511 /* VK_PRINTSCRN 0x19 */ 0x2A, /* WIN_VK_PRINT */
1512 /* VK_INSERT 0x1A */ 0x2D, /* WIN_VK_INSERT */
1513 /* VK_DELETE 0x1B */ 0x2E, /* WIN_VK_DELETE */
1514 /* VK_SCRLLOCK 0x1C */ 0x91, /* WIN_VK_SCROLL */
1515 /* VK_NUMLOCK 0x1D */ 0x90, /* WIN_VK_NUMLOCK */
1516 /* VK_ENTER 0x1E */ 0x0D, /* WIN_VK_RETURN */
1517 /* VK_SYSRQ 0x1F */ 0,
1518 /* VK_F1 0x20 */ 0x70, /* WIN_VK_F1 */
1519 /* VK_F2 0x21 */ 0x71, /* WIN_VK_F2 */
1520 /* VK_F3 0x22 */ 0x72, /* WIN_VK_F3 */
1521 /* VK_F4 0x23 */ 0x73, /* WIN_VK_F4 */
1522 /* VK_F5 0x24 */ 0x74, /* WIN_VK_F5 */
1523 /* VK_F6 0x25 */ 0x75, /* WIN_VK_F6 */
1524 /* VK_F7 0x26 */ 0x76, /* WIN_VK_F7 */
1525 /* VK_F8 0x27 */ 0x77, /* WIN_VK_F8 */
1526 /* VK_F9 0x28 */ 0x78, /* WIN_VK_F9 */
1527 /* VK_F10 0x29 */ 0x79, /* WIN_VK_F10 */
1528 /* VK_F11 0x2A */ 0x7A, /* WIN_VK_F11 */
1529 /* VK_F12 0x2B */ 0x7B, /* WIN_VK_F12 */
1530 /* VK_F13 0x2C */ 0x7C, /* WIN_VK_F13 */
1531 /* VK_F14 0x2D */ 0x7D, /* WIN_VK_F14 */
1532 /* VK_F15 0x2E */ 0x7E, /* WIN_VK_F15 */
1533 /* VK_F16 0x2F */ 0x7F, /* WIN_VK_F16 */
1534 /* VK_F17 0x30 */ 0x80, /* WIN_VK_F17 */
1535 /* VK_F18 0x31 */ 0x81, /* WIN_VK_F18 */
1536 /* VK_F19 0x32 */ 0x82, /* WIN_VK_F19 */
1537 /* VK_F20 0x33 */ 0x83, /* WIN_VK_F20 */
1538 /* VK_F21 0x34 */ 0x84, /* WIN_VK_F21 */
1539 /* VK_F22 0x35 */ 0x85, /* WIN_VK_F22 */
1540 /* VK_F23 0x36 */ 0x86, /* WIN_VK_F23 */
1541 /* VK_F24 0x37 */ 0x87, /* WIN_VK_F24 */
1542 /* VK_ENDDRAG 0x38 */ 0,
1543 /* VK_CLEAR 0x39 */ 0x0C, /* WIN_VK_CLEAR */
1544 /* VK_EREOF 0x3A */ 0xF9, /* WIN_VK_EREOF */
1545 /* VK_PA1 0x3B */ 0xFD, /* WIN_VK_PA1 */
1546 /* VK_ATTN 0x3C */ 0xF6, /* WIN_VK_ATTN */
1547 /* VK_CRSEL 0x3D */ 0xF7, /* WIN_VK_CRSEL */
1548 /* VK_EXSEL 0x3E */ 0xF8, /* WIN_VK_EXSEL */
1549 /* VK_COPY 0x3F */ 0,
1550 /* VK_BLK1 0x40 */ 0,
1551 /* VK_BLK2 0x41 */ 0,
1552 /* 0x42 */ 0,
1553 /* 0x43 */ 0,
1554 /* 0x44 */ 0,
1555 /* 0x45 */ 0,
1556 /* 0x46 */ 0,
1557 /* 0x47 */ 0,
1558 /* 0x48 */ 0,
1559 /* 0x49 */ 0,
1560 /* 0x4A */ 0,
1561 /* 0x4B */ 0,
1562 /* 0x4C */ 0,
1563 /* 0x4D */ 0,
1564 /* 0x4E */ 0,
1565 /* 0x4F */ 0,
1566 /* from UNIKBD.H: */
1567 /* VK_PA2 0x0050 */ 0,
1568 /* VK_PA3 0x0051 */ 0,
1569 /* VK_GROUP 0x0052 */ 0,
1570 /* VK_GROUPLOCK 0x0053 */ 0,
1571 /* VK_APPL 0x0054 */ 0x5D, /* WIN_VK_APPS ??? */
1572 /* VK_WINLEFT 0x0055 */ 0x5B, /* WIN_VK_LWIN */
1573 /* VK_WINRIGHT 0x0056 */ 0x5C, /* WIN_VK_RWIN */
1574 /* 0x0057 */ 0,
1575 /* 0x0058 */ 0,
1576 /* 0x0059 */ 0,
1577 /* 0x005A */ 0,
1578 /* 0x005B */ 0,
1579 /* 0x005C */ 0,
1580 /* 0x005D */ 0,
1581 /* 0x005E */ 0,
1582 /* 0x005F */ 0,
1583 /* 0x0060 */ 0,
1584 /* VK_M_DOWNLEFT 0x0061 */ 0,
1585 /* VK_M_DOWN 0x0062 */ 0,
1586 /* VK_M_DOWNRIGHT 0x0063 */ 0,
1587 /* VK_M_LEFT 0x0064 */ 0,
1588 /* VK_M_CENTER 0x0065 */ 0,
1589 /* VK_M_RIGHT 0x0066 */ 0,
1590 /* VK_M_UPLEFT 0x0067 */ 0,
1591 /* VK_M_UP 0x0068 */ 0,
1592 /* VK_M_UPRIGHT 0x0069 */ 0,
1593 /* VK_M_BUTTONLOCK 0x006A */ 0,
1594 /* VK_M_BUTTONRELEASE 0x006B */ 0,
1595 /* VK_M_DOUBLECLICK 0x006C */ 0,
1596
1597#if 0
15980xA4, /* WIN_VK_LMENU ??? */
15990xA5, /* WIN_VK_RMENU ??? */
1600#define VK_SELECT 0x29
1601#define VK_EXECUTE 0x2B
1602#define VK_SNAPSHOT 0x2C
1603#define VK_HELP 0x2F
1604#define VK_NUMPAD0 0x60
1605#define VK_NUMPAD1 0x61
1606#define VK_NUMPAD2 0x62
1607#define VK_NUMPAD3 0x63
1608#define VK_NUMPAD4 0x64
1609#define VK_NUMPAD5 0x65
1610#define VK_NUMPAD6 0x66
1611#define VK_NUMPAD7 0x67
1612#define VK_NUMPAD8 0x68
1613#define VK_NUMPAD9 0x69
1614#define VK_MULTIPLY 0x6A
1615#define VK_ADD 0x6B
1616#define VK_SEPARATOR 0x6C
1617#define VK_SUBTRACT 0x6D
1618#define VK_DECIMAL 0x6E
1619#define VK_DIVIDE 0x6F
1620#define VK_LSHIFT 0xA0
1621#define VK_RSHIFT 0xA1
1622#define VK_LCONTROL 0xA2
1623#define VK_RCONTROL 0xA3
1624#define VK_PROCESSKEY 0xE5
1625#define VK_PLAY 0xFA
1626#define VK_ZOOM 0xFB
1627#define VK_NONAME 0xFC
1628#define VK_OEM_CLEAR 0xFE
1629#endif
1630
1631};
1632
1633
1634APIRET iConsoleInputEventPushKey(MPARAM mp1,
1635 MPARAM mp2)
1636{
1637 INPUT_RECORD InputRecord; /* the input record structure */
1638 APIRET rc; /* API-returncode */
1639 USHORT fsFlags = ((ULONG)mp1 & 0x0000ffff); /* get key flags */
1640 UCHAR ucRepeat = ((ULONG)mp1 & 0x00ff0000) >> 16;
1641 UCHAR ucScanCode = ((ULONG)mp1 & 0xff000000) >> 24;
1642 UCHAR usCh = ((ULONG)mp2 & 0x0000ffff);
1643 USHORT usVk = ((ULONG)mp2 & 0xffff0000) >> 16;
1644 UCHAR ucChar = usCh & 0x00ff;
1645
1646#ifdef DEBUG_LOCAL2
1647 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPushKey(%08x,%08x).\n",
1648 mp1,
1649 mp2));
1650#endif
1651
1652
1653 InputRecord.EventType = KEY_EVENT; /* fill event structure */
1654 InputRecord.Event.KeyEvent.dwControlKeyState = 0;
1655
1656 if (fsFlags & KC_SHIFT) InputRecord.Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
1657 if (fsFlags & KC_ALT) InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
1658 if (fsFlags & KC_CTRL) InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
1659
1660 /* @@@PH no support for RIGHT_ALT_PRESSED,
1661 RIGHT_CTRL_PRESSED,
1662 NUMLOCK_ON,
1663 SCROLLLOCK_ON,
1664 CAPSLOCK_ON,
1665 ENHANCED_KEY
1666 */
1667
1668 InputRecord.Event.KeyEvent.bKeyDown = !(fsFlags & KC_KEYUP);
1669 InputRecord.Event.KeyEvent.wRepeatCount = ucRepeat;
1670 InputRecord.Event.KeyEvent.wVirtualKeyCode = usVk;
1671 InputRecord.Event.KeyEvent.wVirtualScanCode = ucScanCode;
1672
1673 /* check if ascii is valid, if so then wVirtualKeyCode = ascii, */
1674 /* else go through the table */
1675 if (fsFlags & KC_CHAR) /* usCh valid ? */
1676 {
1677 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
1678 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
1679 if ( ( (usCh >= 'a') && (usCh <= 'z') ) || /* lowercase ? */
1680 ( (usCh >= '0') && (usCh <= '9') )
1681 )
1682 InputRecord.Event.KeyEvent.wVirtualKeyCode = usCh & 0xDF;
1683 else
1684 InputRecord.Event.KeyEvent.wVirtualKeyCode = usCh;
1685 }
1686 else
1687 if (fsFlags & KC_VIRTUALKEY) /* translate OS/2 virtual key code */
1688 {
1689 if (usVk < TABVIRTUALKEYCODES) /* limit to table size */
1690 InputRecord.Event.KeyEvent.wVirtualKeyCode =
1691 tabVirtualKeyCodes[usVk]; /* translate keycode */
1692 }
1693
1694 /* this is a workaround for empty / invalid wVirtualKeyCodes */
1695 if (InputRecord.Event.KeyEvent.wVirtualKeyCode == 0x0000)
1696 {
1697 if ( ( (usCh >= 'a') && (usCh <= 'z') ) || /* lowercase ? */
1698 ( (usCh >= '0') && (usCh <= '9') )
1699 )
1700 InputRecord.Event.KeyEvent.wVirtualKeyCode = usCh & 0xDF;
1701 else
1702 InputRecord.Event.KeyEvent.wVirtualKeyCode = usCh;
1703 }
1704
1705
1706 /* @@@PH handle special keys */
1707 if ( (ucChar != 0xe0) && (ucChar != 0x00) )
1708 InputRecord.Event.KeyEvent.uChar.AsciiChar = ucChar;
1709 else
1710 {
1711 /* extended key ! */
1712 InputRecord.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY;
1713 InputRecord.Event.KeyEvent.uChar.AsciiChar = (ucChar >> 8);
1714 }
1715
1716 /* further processing according the current input console mode */
1717 if (ConsoleInput.dwConsoleMode & ENABLE_PROCESSED_INPUT)
1718 {
1719 /* filter ctrl-c, etc. */
1720 }
1721
1722#if 0
1723 /* DEBUG */
1724 dprintf(("DEBUG: mp1=%08x mp2=%08x\n",
1725 mp1,
1726 mp2));
1727 dprintf(("DEBUG: fsFlags = %04x repeat=%u hwscan=%2x",
1728 fsFlags,
1729 ucRepeat,
1730 ucScanCode ));
1731 dprintf((" uscc=%04x usvk=%04x\n",
1732 SHORT1FROMMP(mp2),
1733 SHORT2FROMMP(mp2)));
1734
1735 dprintf(("DEBUG: ascii=[%c] (%02x)",
1736 InputRecord.Event.KeyEvent.uChar.AsciiChar,
1737 InputRecord.Event.KeyEvent.uChar.AsciiChar));
1738#endif
1739
1740 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */
1741 return (rc); /* OK */
1742}
1743
1744
1745/*****************************************************************************
1746 * Name : static APIRET ConsoleInputEventPushMouse
1747 * Purpose : push mouse event into the queue
1748 * Parameters: MPARAM mp1, MPARAM mp2 from WM_MOUSEMOVE processing
1749 * Variables :
1750 * Result : API returncode
1751 * Remark :
1752 * Status :
1753 *
1754 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1755 *****************************************************************************/
1756
1757APIRET iConsoleInputEventPushMouse(ULONG ulMessage,
1758 MPARAM mp1,
1759 MPARAM mp2)
1760{
1761 INPUT_RECORD InputRecord; /* the input record structure */
1762 APIRET rc; /* API-returncode */
1763 USHORT fsFlags = SHORT2FROMMP(mp2); /* get key flags */
1764 static USHORT usButtonState; /* keeps track of mouse button state */
1765
1766 /* do we have to process mouse input ? */
1767 if ( !(ConsoleInput.dwConsoleMode & ENABLE_MOUSE_INPUT))
1768 return (NO_ERROR); /* return immediately */
1769
1770 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPushMouse(%08x,%08x,%08x).\n",
1771 ulMessage,
1772 mp1,
1773 mp2));
1774
1775 memset(&InputRecord, /* zero the structure */
1776 0,
1777 sizeof (INPUT_RECORD) );
1778
1779 InputRecord.EventType = MOUSE_EVENT; /* fill event structure */
1780
1781 switch (ulMessage)
1782 {
1783 case WM_MOUSEMOVE:
1784 InputRecord.Event.MouseEvent.dwEventFlags = MOUSE_MOVED;
1785 InputRecord.Event.MouseEvent.dwMousePosition.X = SHORT1FROMMP(mp1);
1786 InputRecord.Event.MouseEvent.dwMousePosition.Y = SHORT2FROMMP(mp1);
1787
1788 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1789
1790 if (fsFlags & KC_SHIFT) InputRecord.Event.MouseEvent.dwControlKeyState |= SHIFT_PRESSED;
1791 if (fsFlags & KC_ALT) InputRecord.Event.MouseEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
1792 if (fsFlags & KC_CTRL) InputRecord.Event.MouseEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
1793
1794 /* @@@PH no support for RIGHT_ALT_PRESSED,
1795 RIGHT_CTRL_PRESSED,
1796 NUMLOCK_ON,
1797 SCROLLLOCK_ON,
1798 CAPSLOCK_ON,
1799 ENHANCED_KEY
1800 */
1801 break;
1802
1803 case WM_BUTTON1UP:
1804 usButtonState &= ~FROM_LEFT_1ST_BUTTON_PRESSED;
1805 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1806 break;
1807
1808 case WM_BUTTON1DOWN:
1809 usButtonState |= FROM_LEFT_1ST_BUTTON_PRESSED;
1810 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1811 break;
1812
1813 case WM_BUTTON2UP:
1814 usButtonState &= ~FROM_LEFT_2ND_BUTTON_PRESSED;
1815 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1816 break;
1817
1818 case WM_BUTTON2DOWN:
1819 usButtonState |= FROM_LEFT_2ND_BUTTON_PRESSED;
1820 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1821 break;
1822
1823 case WM_BUTTON3UP:
1824 usButtonState &= ~FROM_LEFT_3RD_BUTTON_PRESSED;
1825 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1826 break;
1827
1828 case WM_BUTTON3DOWN:
1829 usButtonState |= FROM_LEFT_3RD_BUTTON_PRESSED;
1830 InputRecord.Event.MouseEvent.dwButtonState = usButtonState;
1831 break;
1832
1833 case WM_BUTTON1DBLCLK:
1834 InputRecord.Event.MouseEvent.dwEventFlags = DOUBLE_CLICK;
1835 InputRecord.Event.MouseEvent.dwButtonState = FROM_LEFT_1ST_BUTTON_PRESSED;
1836 usButtonState &= ~FROM_LEFT_1ST_BUTTON_PRESSED;
1837 break;
1838
1839 case WM_BUTTON2DBLCLK:
1840 InputRecord.Event.MouseEvent.dwEventFlags = DOUBLE_CLICK;
1841 InputRecord.Event.MouseEvent.dwButtonState = FROM_LEFT_2ND_BUTTON_PRESSED;
1842 usButtonState &= ~FROM_LEFT_2ND_BUTTON_PRESSED;
1843 break;
1844
1845 case WM_BUTTON3DBLCLK:
1846 InputRecord.Event.MouseEvent.dwEventFlags = DOUBLE_CLICK;
1847 InputRecord.Event.MouseEvent.dwButtonState = FROM_LEFT_3RD_BUTTON_PRESSED;
1848 usButtonState &= ~FROM_LEFT_3RD_BUTTON_PRESSED;
1849 break;
1850 }
1851
1852 /* @@@PH pseudo-support for RIGHTMOST_BUTTON_PRESSED */
1853 if (InputRecord.Event.MouseEvent.dwButtonState & FROM_LEFT_3RD_BUTTON_PRESSED)
1854 InputRecord.Event.MouseEvent.dwButtonState |= RIGHTMOST_BUTTON_PRESSED;
1855
1856 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */
1857 return (rc); /* OK */
1858}
1859
1860
1861/*****************************************************************************
1862 * Name : static APIRET ConsoleInputEventPushWindow
1863 * Purpose : push menu event into the queue
1864 * Parameters: DWORD dwCommandId
1865 * Variables :
1866 * Result : API returncode
1867 * Remark :
1868 * Status :
1869 *
1870 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1871 *****************************************************************************/
1872
1873APIRET iConsoleInputEventPushWindow(COORD coordWindowSize)
1874{
1875 INPUT_RECORD InputRecord; /* the input record structure */
1876 APIRET rc; /* API-returncode */
1877
1878 /* do we have to process window input ? */
1879 if ( !(ConsoleInput.dwConsoleMode & ENABLE_WINDOW_INPUT))
1880 return (NO_ERROR); /* return immediately */
1881
1882 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPushWindow(x = %u, y = %u).\n",
1883 coordWindowSize.X,
1884 coordWindowSize.Y));
1885
1886 InputRecord.EventType = WINDOW_BUFFER_SIZE_EVENT; /* fill event structure */
1887
1888 InputRecord.Event.WindowBufferSizeEvent.dwSize = coordWindowSize;
1889
1890 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */
1891 return (rc); /* OK */
1892}
1893
1894
1895/*****************************************************************************
1896 * Name : static APIRET ConsoleInputEventPushMenu
1897 * Purpose : push window event into the queue
1898 * Parameters: COORD coordWindowSize
1899 * Variables :
1900 * Result : API returncode
1901 * Remark :
1902 * Status :
1903 *
1904 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1905 *****************************************************************************/
1906
1907APIRET iConsoleInputEventPushMenu(DWORD dwCommandId)
1908{
1909 INPUT_RECORD InputRecord; /* the input record structure */
1910 APIRET rc; /* API-returncode */
1911
1912 /* @@@PH this is unknown to me - there's no separate bit for menu events ? */
1913 /* do we have to process window input ? */
1914 if ( !(ConsoleInput.dwConsoleMode & ENABLE_WINDOW_INPUT))
1915 return (NO_ERROR); /* return immediately */
1916
1917 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPushMenu(%08x).\n",
1918 dwCommandId));
1919
1920 InputRecord.EventType = MENU_EVENT; /* fill event structure */
1921
1922 InputRecord.Event.MenuEvent.dwCommandId = dwCommandId;
1923
1924 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */
1925 return (rc); /* OK */
1926}
1927
1928
1929/*****************************************************************************
1930 * Name : static APIRET ConsoleInputEventPushFocus
1931 * Purpose : push focus event into the queue
1932 * Parameters: BOOL bSetFocus
1933 * Variables :
1934 * Result : API returncode
1935 * Remark :
1936 * Status :
1937 *
1938 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1939 *****************************************************************************/
1940
1941APIRET iConsoleInputEventPushFocus(BOOL bSetFocus)
1942{
1943 INPUT_RECORD InputRecord; /* the input record structure */
1944 APIRET rc; /* API-returncode */
1945
1946 /* @@@PH this is unknown to me - there's no separate bit for menu events ? */
1947 /* do we have to process window input ? */
1948 if ( !(ConsoleInput.dwConsoleMode & ENABLE_WINDOW_INPUT))
1949 return (NO_ERROR); /* return immediately */
1950
1951 dprintf(("KERNEL32/CONSOLE:ConsoleInputEventPushFocus(%08x).\n",
1952 bSetFocus));
1953
1954 InputRecord.EventType = FOCUS_EVENT; /* fill event structure */
1955
1956 InputRecord.Event.FocusEvent.bSetFocus = bSetFocus;
1957
1958 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */
1959 return (rc); /* OK */
1960}
1961
1962
1963/*****************************************************************************
1964 * Name : static ULONG ConsoleInputQueueEvents
1965 * Purpose : query number of events in the queue
1966 * Parameters:
1967 * Variables :
1968 * Result : number of events
1969 * Remark :
1970 * Status :
1971 *
1972 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1973 *****************************************************************************/
1974
1975ULONG iConsoleInputQueryEvents (void)
1976{
1977 return (ConsoleInput.ulEvents); /* return number of events in queue */
1978}
1979
1980
1981/*****************************************************************************
1982 * Name : static void ConsoleCursorShow
1983 * Purpose : query number of events in the queue
1984 * Parameters:
1985 * Variables :
1986 * Result : number of events
1987 * Remark :
1988 * Status :
1989 *
1990 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
1991 *****************************************************************************/
1992
1993void iConsoleCursorShow (PCONSOLEBUFFER pConsoleBuffer,
1994 ULONG ulCursorMode)
1995{
1996 HPS hps; /* presentation space handle */
1997 RECTL rclCursor; /* the cursor rectangle */
1998 static BOOL fState; /* current cursor state */
1999 RECTL rclWindow; /* current window size */
2000
2001#ifdef DEBUG_LOCAL2
2002 dprintf(("KERNEL32:Console:ConsoleCursorShow(%u)\n",
2003 ulCursorMode));
2004#endif
2005
2006 if (pConsoleBuffer->CursorInfo.bVisible == FALSE)/* cursor is switched off */
2007 return; /* return immediately */
2008
2009 switch (ulCursorMode)
2010 {
2011 case CONSOLECURSOR_HIDE:
2012 if (fState == FALSE) /* cursor currently shown ? */
2013 return; /* no, abort immediately */
2014 else
2015 fState = FALSE; /* set to invisible and invert our cursor rect */
2016 break;
2017
2018 case CONSOLECURSOR_SHOW:
2019 if (fState == TRUE) /* cursor currently shown ? */
2020 return; /* yes,abort immediately */
2021 else
2022 fState = TRUE; /* set to visible and invert our cursor rect */
2023 break;
2024
2025 case CONSOLECURSOR_BLINK:
2026 fState = !fState; /* let there be on off on off on off on off ... */
2027 break;
2028
2029 case CONSOLECURSOR_OVERWRITTEN: /* our cursor has been overwritten */
2030 fState = TRUE; /* so show the cursor immediately */
2031 break;
2032 }
2033
2034
2035 /* query current window's size */
2036 WinQueryWindowRect(ConsoleGlobals.hwndClient,
2037 &rclWindow);
2038
2039 /* calculate coordinates of the cursor */
2040 rclCursor.xLeft = ConsoleGlobals.sCellCX * pConsoleBuffer->coordCursorPosition.X;
2041 rclCursor.xRight = rclCursor.xLeft + ConsoleGlobals.sCellCX;
2042
2043 //@@@PH top calculation is wrong!
2044 rclCursor.yBottom = rclWindow.yTop
2045 - ConsoleGlobals.sCellCY * (pConsoleBuffer->coordCursorPosition.Y + 1);
2046 rclCursor.yTop = rclCursor.yBottom + /* cursor height in percent */
2047 (ConsoleGlobals.sCellCY *
2048 pConsoleBuffer->CursorInfo.dwSize /
2049 100);
2050
2051 hps = WinGetPS(ConsoleGlobals.hwndClient); /* get HPS */
2052
2053 /* @@@PH invert coordinates here ... */
2054 WinInvertRect(hps, /* our cursor is an inverted rectangle */
2055 &rclCursor);
2056
2057 WinReleasePS(hps); /* release the hps again */
2058}
2059
2060
2061/*****************************************************************************
2062 * Name : static APIRET ConsoleFontQuery
2063 * Purpose : queries the current font cell sizes
2064 * Parameters:
2065 * Variables :
2066 * Result : API returncode
2067 * Remark :
2068 * Status :
2069 *
2070 * Author : Patrick Haller [Tue, 1998/03/07 16:55]
2071 *****************************************************************************/
2072
2073APIRET iConsoleFontQuery (void)
2074{
2075 return(VioGetDeviceCellSize(&ConsoleGlobals.sCellCY, /* query VIO manager */
2076 &ConsoleGlobals.sCellCX,
2077 ConsoleGlobals.hvpsConsole));
2078}
2079
2080
2081/*****************************************************************************
2082 * Name : static void ConsoleCursorShow
2083 * Purpose : query number of events in the queue
2084 * Parameters:
2085 * Variables :
2086 * Result : number of events
2087 * Remark : called during INIT, FONTCHANGE, RESIZE, BUFFERCHANGE
2088 * Status :
2089 *
2090 * Author : Patrick Haller [Wed, 1998/04/29 16:55]
2091 *****************************************************************************/
2092
2093void iConsoleAdjustWindow (PCONSOLEBUFFER pConsoleBuffer)
2094{
2095 LONG lX, lY; /* temporary long values */
2096 RECTL rcl;
2097 PRECTL pRcl = &rcl;
2098 ULONG flStyle; /* window frame control style */
2099
2100 BOOL fNeedVertScroll; /* indicates need of scrollbars */
2101 BOOL fNeedHorzScroll;
2102
2103 LONG lScrollX; /* width and height of scrollbars */
2104 LONG lScrollY;
2105
2106 /* now calculate actual window size */
2107 lX = ConsoleGlobals.sCellCX * ConsoleGlobals.coordWindowSize.X;
2108 lY = ConsoleGlobals.sCellCY * ConsoleGlobals.coordWindowSize.Y;
2109
2110 if ( (ConsoleGlobals.sCellCX == 0) || /* prevent division by zero */
2111 (ConsoleGlobals.sCellCY == 0) )
2112 return;
2113
2114 /* calculate maximum console window size in pixels for the tracking */
2115 ConsoleGlobals.coordMaxWindowPels.X = ConsoleGlobals.sCellCX * pConsoleBuffer->coordWindowSize.X
2116 + WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) * 2;
2117
2118 ConsoleGlobals.coordMaxWindowPels.Y = ConsoleGlobals.sCellCY * pConsoleBuffer->coordWindowSize.Y
2119 + WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER) * 2
2120 + WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
2121
2122 /***************************/
2123 /* @@@PH broken code below */
2124 /***************************/
2125 return;
2126
2127 /* add the window border height and width, etc. */
2128 WinQueryWindowRect (ConsoleGlobals.hwndClient,
2129 pRcl);
2130
2131 /* calculate visible area */
2132 /* calculate real client window rectangle and take care of the scrollbars */
2133 lScrollX = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
2134 lScrollY = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
2135 if (ConsoleGlobals.fHasHorzScroll)
2136 {
2137 lY += lScrollY;
2138 ConsoleGlobals.coordMaxWindowPels.Y += lScrollY;
2139 }
2140
2141 if (ConsoleGlobals.fHasVertScroll)
2142 {
2143 lX += lScrollX;
2144 ConsoleGlobals.coordMaxWindowPels.X += lScrollX;
2145 }
2146
2147 /* @@@PH might NOT exceed maximum VioPS size ! */
2148 ConsoleGlobals.coordWindowSize.X = (pRcl->xRight - pRcl->xLeft)
2149 / ConsoleGlobals.sCellCX;
2150
2151 ConsoleGlobals.coordWindowSize.Y = (pRcl->yTop - pRcl->yBottom)
2152 / ConsoleGlobals.sCellCY;
2153
2154 /* do we have to enable the scrollbars ? */
2155 fNeedHorzScroll = lX < pConsoleBuffer->coordWindowSize.X * ConsoleGlobals.sCellCX;
2156 fNeedVertScroll = lY < pConsoleBuffer->coordWindowSize.Y * ConsoleGlobals.sCellCY;
2157
2158
2159 if ( (ConsoleGlobals.fHasVertScroll != fNeedVertScroll) ||
2160 (ConsoleGlobals.fHasHorzScroll != fNeedHorzScroll) )
2161 {
2162 flStyle = WinQueryWindowULong(ConsoleGlobals.hwndFrame,
2163 QWL_STYLE);
2164
2165 /* now set or remove the controls */
2166 if (ConsoleGlobals.fHasHorzScroll != fNeedHorzScroll)
2167 if (fNeedHorzScroll)
2168 {
2169 flStyle |= FCF_HORZSCROLL;
2170 WinSetParent(ConsoleGlobals.hwndHorzScroll, /* attach control */
2171 ConsoleGlobals.hwndFrame,
2172 FALSE);
2173 }
2174 else
2175 {
2176 flStyle &= ~FCF_HORZSCROLL;
2177 WinSetParent(ConsoleGlobals.hwndHorzScroll, /* detach control */
2178 HWND_OBJECT,
2179 FALSE);
2180 ConsoleGlobals.coordWindowPos.X = 0; /* we can see the whole buffer */
2181 }
2182
2183 if (ConsoleGlobals.fHasVertScroll != fNeedVertScroll)
2184 if (fNeedVertScroll)
2185 {
2186 flStyle |= FCF_VERTSCROLL;
2187 WinSetParent(ConsoleGlobals.hwndVertScroll, /* attach control */
2188 ConsoleGlobals.hwndFrame,
2189 FALSE);
2190 }
2191 else
2192 {
2193 flStyle &= ~FCF_VERTSCROLL;
2194 WinSetParent(ConsoleGlobals.hwndVertScroll, /* detach control */
2195 HWND_OBJECT,
2196 FALSE);
2197 ConsoleGlobals.coordWindowPos.Y = 0; /* we can see the whole buffer */
2198 }
2199
2200
2201 WinSendMsg(ConsoleGlobals.hwndFrame, /* update frame */
2202 WM_UPDATEFRAME,
2203 MPFROMLONG(flStyle),
2204 MPVOID);
2205
2206 WinInvalidateRect(ConsoleGlobals.hwndFrame, /* redraw frame window */
2207 NULL,
2208 TRUE);
2209
2210 ConsoleGlobals.fHasVertScroll = fNeedVertScroll; /* update globals */
2211 ConsoleGlobals.fHasHorzScroll = fNeedHorzScroll; /* update globals */
2212 }
2213
2214
2215 /* setup the scrollbars and scrollranges */
2216 if (ConsoleGlobals.fHasVertScroll)
2217 {
2218 /* setup vertical scrollbar */
2219 }
2220
2221
2222 if (ConsoleGlobals.fHasHorzScroll)
2223 {
2224 /* setup horizonal scrollbar */
2225 }
2226
2227
2228 WinCalcFrameRect(ConsoleGlobals.hwndFrame, /* calculate frame rectangle */
2229 pRcl,
2230 FALSE);
2231
2232 /* @@@PH client may not overlap frame ! */
2233 /* @@@PH write values to TRACKINFO */
2234
2235#if 0
2236 /* @@@PH this results in recursion */
2237 WinSetWindowPos (ConsoleGlobals.hwndClient, /* adjust client window size */
2238 ConsoleGlobals.hwndFrame,
2239 0,
2240 0,
2241 lX,
2242 lY,
2243 SWP_SIZE);
2244
2245 WinSetWindowPos (ConsoleGlobals.hwndFrame, /* adjust client window size */
2246 HWND_DESKTOP,
2247 pRcl->xLeft,
2248 pRcl->yBottom,
2249 pRcl->xRight,
2250 pRcl->yTop,
2251 SWP_SIZE);
2252#endif
2253}
2254
2255
2256/*****************************************************************************
2257 * Name : BOOL WIN32API AllocConsole
2258 * Purpose : The AllocConsole function allocates a new console
2259 * for the calling process
2260 * Parameters: VOID
2261 * Variables :
2262 * Result : BOOL: TRUE - function succeeded
2263 * FALSE - function failed. Extended error information
2264 * obtainable via GetLastError
2265 * Remark :
2266 * Status : REWRITTEN UNTESTED
2267 *
2268 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2269 *****************************************************************************/
2270
2271BOOL WIN32API AllocConsole(VOID)
2272{
2273 APIRET rc; /* API returncode */
2274
2275#ifdef DEBUG_LOCAL2
2276 WriteLog("KERNEL32/CONSOLE: OS2AllocConsole() called.\n");
2277#endif
2278
2279 rc = iConsoleInit(); /* initialize subsystem if required */
2280 if (rc != NO_ERROR) /* check for errors */
2281 {
2282 SetLastError(rc); /* pass thru the error code */
2283 return FALSE; /* signal failure */
2284 }
2285 else
2286 return TRUE; /* Fine ! :) */
2287}
2288
2289
2290/*****************************************************************************
2291 * Name : HANDLE WIN32API CreateConsoleScreenBuffer
2292 * Purpose : The CreateConsoleScreenBuffer function creates a console
2293 * screen buffer and returns a handle of it.
2294 * Parameters: DWORD dwDesiredAccess - access flag
2295 * DWORD dwShareMode - buffer share more
2296 * PVOID pIgnored - LPSECURITY_ATTRIBUTES -> NT
2297 * DWORD dwFlags - type of buffer to create
2298 * LPVOID lpScreenBufferData - reserved
2299 * Variables :
2300 * Result :
2301 * Remark : a console buffer is a kernel heap object equipped with
2302 * share modes, access rights, etc.
2303 * we can't really map this to OS/2 unless we build a
2304 * console device driver for it ... maybe this turns out to
2305 * be necessary since we've got to handle CONIN$ and CONOUT$, too.
2306 * Status :
2307 *
2308 * Author : Patrick Haller [Tue, 1998/02/10 03:55]
2309 *****************************************************************************/
2310
2311HANDLE WIN32API CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
2312 DWORD dwShareMode,
2313 LPVOID lpSecurityAttributes,
2314 DWORD dwFlags,
2315 LPVOID lpScreenBufferData)
2316{
2317 HANDLE hResult;
2318
2319#ifdef DEBUG_LOCAL2
2320 WriteLog("KERNEL32/CONSOLE:OS2CreateConsoleScreenBuffer(%08x,%08x,%08x,%08x,%08x).\n",
2321 dwDesiredAccess,
2322 dwShareMode,
2323 lpSecurityAttributes,
2324 dwFlags,
2325 lpScreenBufferData);
2326#endif
2327
2328 hResult = HMCreateFile("CONBUFFER$", /* create a new buffer handle */
2329 dwDesiredAccess,
2330 dwShareMode,
2331 (LPSECURITY_ATTRIBUTES)lpSecurityAttributes,
2332 0,
2333 dwFlags,
2334 INVALID_HANDLE_VALUE);
2335
2336 return hResult;
2337}
2338
2339
2340/*****************************************************************************
2341 * Name :
2342 * Purpose :
2343 * Parameters:
2344 * Variables :
2345 * Result :
2346 * Remark :
2347 * Status :
2348 *
2349 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2350 *****************************************************************************/
2351
2352BOOL WIN32API FillConsoleOutputAttribute(HANDLE hConsoleOutput,
2353 WORD wAttribute,
2354 DWORD nLength,
2355 COORD dwWriteCoord,
2356 LPDWORD lpNumberOfAttrsWritten)
2357{
2358 BOOL fResult;
2359
2360#ifdef DEBUG_LOCAL2
2361 WriteLog("KERNEL32/CONSOLE: OS2FillConsoleOutputAttribute(%08x,%04x,%08x,%08x,%08x).\n",
2362 hConsoleOutput,
2363 wAttribute,
2364 nLength,
2365 dwWriteCoord,
2366 lpNumberOfAttrsWritten);
2367#endif
2368
2369 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2370 DRQ_FILLCONSOLEOUTPUTATTRIBUTE,
2371 (ULONG)wAttribute,
2372 (ULONG)nLength,
2373 COORD2ULONG(dwWriteCoord),
2374 (ULONG)lpNumberOfAttrsWritten);
2375
2376 return fResult;
2377}
2378
2379
2380/*****************************************************************************
2381 * Name :
2382 * Purpose :
2383 * Parameters:
2384 * Variables :
2385 * Result :
2386 * Remark :
2387 * Status :
2388 *
2389 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2390 *****************************************************************************/
2391
2392BOOL WIN32API FillConsoleOutputCharacterA(HANDLE hConsoleOutput,
2393 UCHAR cCharacter,
2394 DWORD nLength,
2395 COORD dwWriteCoord,
2396 LPDWORD lpNumberOfCharsWritten )
2397{
2398 BOOL fResult;
2399
2400#ifdef DEBUG_LOCAL2
2401 WriteLog("KERNEL32/CONSOLE: OS2FillConsoleOutputCharacterA(%08x,%c,%08x,%08x,%08x).\n",
2402 hConsoleOutput,
2403 cCharacter,
2404 nLength,
2405 dwWriteCoord,
2406 lpNumberOfCharsWritten);
2407#endif
2408
2409 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2410 DRQ_FILLCONSOLEOUTPUTCHARACTERA,
2411 (ULONG)cCharacter,
2412 (ULONG)nLength,
2413 COORD2ULONG(dwWriteCoord),
2414 (ULONG)lpNumberOfCharsWritten);
2415
2416 return fResult;
2417}
2418
2419
2420/*****************************************************************************
2421 * Name :
2422 * Purpose :
2423 * Parameters:
2424 * Variables :
2425 * Result :
2426 * Remark :
2427 * Status :
2428 *
2429 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2430 *****************************************************************************/
2431
2432BOOL WIN32API FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
2433 WCHAR cCharacter,
2434 DWORD nLength,
2435 COORD dwWriteCoord,
2436 LPDWORD lpNumberOfCharsWritten )
2437{
2438 BOOL fResult;
2439
2440#ifdef DEBUG_LOCAL2
2441 WriteLog("KERNEL32/CONSOLE: OS2FillConsoleOutputCharacterW(%08x,%c,%08x,%08x,%08x) .\n",
2442 hConsoleOutput,
2443 cCharacter,
2444 nLength,
2445 dwWriteCoord,
2446 lpNumberOfCharsWritten);
2447#endif
2448
2449 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2450 DRQ_FILLCONSOLEOUTPUTCHARACTERW,
2451 (ULONG)cCharacter,
2452 (ULONG)nLength,
2453 COORD2ULONG(dwWriteCoord),
2454 (ULONG)lpNumberOfCharsWritten);
2455
2456 return fResult;
2457}
2458
2459
2460/*****************************************************************************
2461 * Name :
2462 * Purpose :
2463 * Parameters:
2464 * Variables :
2465 * Result :
2466 * Remark :
2467 * Status :
2468 *
2469 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2470 *****************************************************************************/
2471
2472BOOL WIN32API FlushConsoleInputBuffer( HANDLE hConsoleInput )
2473{
2474 BOOL fResult;
2475
2476#ifdef DEBUG_LOCAL2
2477 WriteLog("KERNEL32/CONSOLE: OS2FlushConsoleInputBuffer(%08x).\n",
2478 hConsoleInput);
2479#endif
2480
2481 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2482 DRQ_FLUSHCONSOLEINPUTBUFFER,
2483 0,
2484 0,
2485 0,
2486 0);
2487
2488 return fResult;
2489}
2490
2491
2492/*****************************************************************************
2493 * Name : BOOL WIN32API FreeConsole
2494 * Purpose : The FreeConsole function detaches the calling process
2495 * from its console.
2496 * Parameters: VOID
2497 * Variables :
2498 * Result : BOOL: TRUE - function succeeded
2499 * FALSE - function failed. Extended error information
2500 * obtainable via GetLastError
2501 * Remark :
2502 * Status : REWRITTEN UNTESTED
2503 *
2504 * Author : Patrick Haller [Tue, 1998/02/10 03:35]
2505 *****************************************************************************/
2506
2507BOOL WIN32API FreeConsole( VOID )
2508{
2509 APIRET rc; /* API returncode */
2510
2511#ifdef DEBUG_LOCAL2
2512 WriteLog("KERNEL32/CONSOLE: OS2FreeConsole() called.\n");
2513#endif
2514
2515 rc = iConsoleTerminate(); /* terminate subsystem if required */
2516 if (rc != NO_ERROR) /* check for errors */
2517 {
2518 SetLastError(rc); /* pass thru the error code */
2519 return FALSE; /* signal failure */
2520 }
2521 else
2522 return TRUE; /* Fine ! :) */
2523
2524 return TRUE;
2525}
2526
2527
2528/*****************************************************************************
2529 * Name :
2530 * Purpose :
2531 * Parameters:
2532 * Variables :
2533 * Result :
2534 * Remark :
2535 * Status :
2536 *
2537 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2538 *****************************************************************************/
2539
2540BOOL WIN32API GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
2541 DWORD dwProcessGroupId)
2542{
2543#ifdef DEBUG_LOCAL2
2544 WriteLog("KERNEL32/CONSOLE: OS2GenerateConsoleCtrlEvent(%08x,%08x) not implemented.\n",
2545 dwCtrlEvent,
2546 dwProcessGroupId);
2547#endif
2548
2549 return TRUE;
2550}
2551
2552
2553/*****************************************************************************
2554 * Name :
2555 * Purpose :
2556 * Parameters:
2557 * Variables :
2558 * Result :
2559 * Remark :
2560 * Status :
2561 *
2562 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2563 *****************************************************************************/
2564
2565UINT WIN32API GetConsoleCP(VOID)
2566{
2567#ifdef DEBUG_LOCAL2
2568 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleCP not implemented.\n");
2569#endif
2570
2571 return 1;
2572}
2573
2574
2575/*****************************************************************************
2576 * Name :
2577 * Purpose :
2578 * Parameters:
2579 * Variables :
2580 * Result :
2581 * Remark :
2582 * Status :
2583 *
2584 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2585 *****************************************************************************/
2586
2587BOOL WIN32API GetConsoleCursorInfo(HANDLE hConsoleOutput,
2588 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
2589{
2590 BOOL fResult;
2591
2592#ifdef DEBUG_LOCAL2
2593 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleCursorInfo(%08x,%08x).\n",
2594 hConsoleOutput,
2595 lpConsoleCursorInfo);
2596#endif
2597
2598 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2599 DRQ_GETCONSOLECURSORINFO,
2600 (ULONG)lpConsoleCursorInfo,
2601 0,
2602 0,
2603 0);
2604
2605 return fResult;
2606}
2607
2608
2609/*****************************************************************************
2610 * Name :
2611 * Purpose :
2612 * Parameters:
2613 * Variables :
2614 * Result :
2615 * Remark :
2616 * Status :
2617 *
2618 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2619 *****************************************************************************/
2620
2621BOOL WIN32API GetConsoleMode(HANDLE hConsole,
2622 LPDWORD lpMode)
2623{
2624 BOOL fResult;
2625
2626#ifdef DEBUG_LOCAL2
2627 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleMode(%08x,%08x).\n",
2628 hConsole,
2629 lpMode);
2630#endif
2631
2632 fResult = (BOOL)HMDeviceRequest(hConsole,
2633 DRQ_GETCONSOLEMODE,
2634 (ULONG) lpMode,
2635 0,
2636 0,
2637 0);
2638
2639 return fResult;
2640}
2641
2642
2643/*****************************************************************************
2644 * Name :
2645 * Purpose :
2646 * Parameters:
2647 * Variables :
2648 * Result :
2649 * Remark :
2650 * Status :
2651 *
2652 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2653 *****************************************************************************/
2654
2655UINT WIN32API GetConsoleOutputCP(VOID)
2656{
2657#ifdef DEBUG_LOCAL2
2658 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleOutputCP not implemented.\n");
2659#endif
2660
2661 return 1;
2662}
2663
2664
2665/*****************************************************************************
2666 * Name :
2667 * Purpose :
2668 * Parameters:
2669 * Variables :
2670 * Result :
2671 * Remark :
2672 * Status :
2673 *
2674 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2675 *****************************************************************************/
2676
2677BOOL WIN32API GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,
2678 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
2679{
2680 BOOL fResult;
2681
2682#ifdef DEBUG_LOCAL2
2683 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleScreenBufferInfo(%08x,%08x).\n",
2684 hConsoleOutput,
2685 lpConsoleScreenBufferInfo);
2686#endif
2687
2688 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2689 DRQ_GETCONSOLESCREENBUFFERINFO,
2690 (ULONG)lpConsoleScreenBufferInfo,
2691 0,
2692 0,
2693 0);
2694
2695 return fResult;
2696}
2697
2698
2699/*****************************************************************************
2700 * Name : DWORD WIN32API GetConsoleTitle
2701 * Purpose : Query the current console window title
2702 * Parameters: LPTSTR lpConsoleTitle
2703 * DWORD nSize
2704 * Variables :
2705 * Result : number of copied bytes
2706 * Remark :
2707 * Status : REWRITTEN UNTESTED
2708 *
2709 * Author : Patrick Haller [Thu, 1998/02/12 23:31]
2710 *****************************************************************************/
2711
2712DWORD WIN32API GetConsoleTitleA(LPTSTR lpConsoleTitle,
2713 DWORD nSize)
2714{
2715 ULONG ulLength; /* length of text */
2716
2717#ifdef DEBUG_LOCAL2
2718 WriteLog("KERNEL32/CONSOLE: OS2GetConsoleTitleA(%08x,%08x).\n",
2719 lpConsoleTitle,
2720 nSize);
2721#endif
2722
2723 if (ConsoleGlobals.pszWindowTitle == NULL) /* is there a window title ? */
2724 return 0; /* abort immediately */
2725
2726 ulLength = strlen(ConsoleGlobals.pszWindowTitle); /* length of text */
2727
2728 strncpy(lpConsoleTitle,
2729 ConsoleGlobals.pszWindowTitle,
2730 nSize);
2731 lpConsoleTitle[nSize-1] = 0;
2732
2733 return (nSize < ulLength) ? nSize : ulLength;
2734}
2735
2736
2737/*****************************************************************************
2738 * Name : DWORD WIN32API GetConsoleTitle
2739 * Purpose : Query the current console window title
2740 * Parameters: LPTSTR lpConsoleTitle
2741 * DWORD nSize
2742 * Variables :
2743 * Result : number of copied bytes
2744 * Remark :
2745 * Status : REWRITTEN UNTESTED
2746 *
2747 * Author : Patrick Haller [Thu, 1998/02/12 23:31]
2748 *****************************************************************************/
2749
2750DWORD WIN32API GetConsoleTitleW(LPWSTR lpConsoleTitle,
2751 DWORD nSize)
2752{
2753 ULONG ulLength; /* length of text */
2754
2755#ifdef DEBUG_LOCAL2
2756 WriteLog("KERNEL32/CONSOLE: GetConsoleTitleW(%08x,%08x)",
2757 lpConsoleTitle,
2758 nSize);
2759#endif
2760
2761 if (ConsoleGlobals.pszWindowTitle == NULL) /* is there a window title ? */
2762 return 0; /* abort immediately */
2763
2764 ulLength = strlen(ConsoleGlobals.pszWindowTitle); /* length of text */
2765
2766 lstrcpynAtoW(lpConsoleTitle,
2767 ConsoleGlobals.pszWindowTitle,
2768 nSize);
2769
2770 /* @@@PH Ascii2Unicode */
2771
2772 return (nSize < ulLength) ? nSize : ulLength;
2773}
2774
2775
2776/*****************************************************************************
2777 * Name : COORD WIN32API GetLargestConsoleWindowSize
2778 * Purpose : Determine maximum AVIO size
2779 * Parameters:
2780 * Variables :
2781 * Result :
2782 * Remark :
2783 * Status :
2784 *
2785 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2786 *****************************************************************************/
2787
2788COORD WIN32API GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
2789{
2790 DWORD dwResult;
2791 COORD coordResult;
2792
2793#ifdef DEBUG_LOCAL2
2794 WriteLog("KERNEL32/CONSOLE: OS2GetLargestConsoleWindowSize(%08x).\n",
2795 hConsoleOutput);
2796#endif
2797
2798 dwResult = HMDeviceRequest(hConsoleOutput,
2799 DRQ_GETLARGESTCONSOLEWINDOWSIZE,
2800 0,
2801 0,
2802 0,
2803 0);
2804
2805 ULONG2COORD(coordResult,dwResult)
2806 return ( coordResult );
2807}
2808
2809
2810/*****************************************************************************
2811 * Name :
2812 * Purpose :
2813 * Parameters:
2814 * Variables :
2815 * Result :
2816 * Remark :
2817 * Status :
2818 *
2819 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2820 *****************************************************************************/
2821
2822BOOL WIN32API GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
2823 LPDWORD lpNumberOfEvents)
2824{
2825 BOOL fResult;
2826
2827#ifdef DEBUG_LOCAL2
2828 WriteLog("KERNEL32/CONSOLE: OS2GetNumberOfConsoleInputEvents(%08x,%08x).\n",
2829 hConsoleInput,
2830 lpNumberOfEvents);
2831#endif
2832
2833 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2834 DRQ_GETNUMBEROFCONSOLEINPUTEVENTS,
2835 (ULONG)lpNumberOfEvents,
2836 0,
2837 0,
2838 0);
2839
2840 return fResult;
2841}
2842
2843
2844/*****************************************************************************
2845 * Name :
2846 * Purpose :
2847 * Parameters:
2848 * Variables :
2849 * Result :
2850 * Remark :
2851 * Status :
2852 *
2853 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2854 *****************************************************************************/
2855
2856BOOL WIN32API GetNumberOfConsoleMouseButtons(LPDWORD lpcNumberOfMouseButtons)
2857{
2858 LONG lMouseButtons;
2859
2860#ifdef DEBUG_LOCAL2
2861 WriteLog("KERNEL32/CONSOLE: OS2GetNumberOfConsoleMouseButtons(%08x).\n",
2862 lpcNumberOfMouseButtons);
2863#endif
2864
2865 lMouseButtons = WinQuerySysValue(HWND_DESKTOP, /* query PM for that */
2866 SV_CMOUSEBUTTONS);
2867
2868 *lpcNumberOfMouseButtons = (DWORD)lMouseButtons;
2869
2870 return TRUE;
2871}
2872
2873
2874/*****************************************************************************
2875 * Name :
2876 * Purpose :
2877 * Parameters:
2878 * Variables :
2879 * Result :
2880 * Remark :
2881 * Status :
2882 *
2883 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2884 *****************************************************************************/
2885
2886BOOL WIN32API PeekConsoleInputW(HANDLE hConsoleInput,
2887 PINPUT_RECORD pirBuffer,
2888 DWORD cInRecords,
2889 LPDWORD lpcRead)
2890{
2891 BOOL fResult;
2892
2893#ifdef DEBUG_LOCAL2
2894 WriteLog("KERNEL32/CONSOLE: OS2PeekConsoleInputW(%08x,%08x,%08x,%08x).\n",
2895 hConsoleInput,
2896 pirBuffer,
2897 cInRecords,
2898 lpcRead);
2899#endif
2900
2901 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2902 DRQ_PEEKCONSOLEINPUTW,
2903 (ULONG)pirBuffer,
2904 (ULONG)cInRecords,
2905 (ULONG)lpcRead,
2906 0);
2907
2908 return fResult;
2909}
2910
2911
2912/*****************************************************************************
2913 * Name :
2914 * Purpose :
2915 * Parameters:
2916 * Variables :
2917 * Result :
2918 * Remark :
2919 * Status :
2920 *
2921 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2922 *****************************************************************************/
2923
2924BOOL WIN32API PeekConsoleInputA(HANDLE hConsoleInput,
2925 PINPUT_RECORD pirBuffer,
2926 DWORD cInRecords,
2927 LPDWORD lpcRead)
2928{
2929 BOOL fResult;
2930
2931#ifdef DEBUG_LOCAL2
2932 WriteLog("KERNEL32/CONSOLE: OS2PeekConsoleInputA(%08x,%08x,%08x,%08x).\n",
2933 hConsoleInput,
2934 pirBuffer,
2935 cInRecords,
2936 lpcRead);
2937#endif
2938
2939 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2940 DRQ_PEEKCONSOLEINPUTA,
2941 (ULONG)pirBuffer,
2942 (ULONG)cInRecords,
2943 (ULONG)lpcRead,
2944 0);
2945
2946 return fResult;
2947}
2948
2949
2950/*****************************************************************************
2951 * Name :
2952 * Purpose :
2953 * Parameters:
2954 * Variables :
2955 * Result :
2956 * Remark :
2957 * Status :
2958 *
2959 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2960 *****************************************************************************/
2961
2962BOOL WIN32API ReadConsoleA(HANDLE hConsoleInput,
2963 LPVOID lpvBuffer,
2964 DWORD cchToRead,
2965 LPDWORD lpcchRead,
2966 LPVOID lpvReserved)
2967{
2968 BOOL fResult;
2969
2970#ifdef DEBUG_LOCAL2
2971 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleA(%08x,%08x,%08x,%08x,%08x).\n",
2972 hConsoleInput,
2973 lpvBuffer,
2974 cchToRead,
2975 lpcchRead,
2976 lpvReserved);
2977#endif
2978
2979 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2980 DRQ_READCONSOLEA,
2981 (ULONG)lpvBuffer,
2982 (ULONG)cchToRead,
2983 (ULONG)lpcchRead,
2984 (ULONG)lpvReserved);
2985
2986 return fResult;
2987}
2988
2989
2990/*****************************************************************************
2991 * Name :
2992 * Purpose :
2993 * Parameters:
2994 * Variables :
2995 * Result :
2996 * Remark :
2997 * Status :
2998 *
2999 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3000 *****************************************************************************/
3001
3002BOOL WIN32API ReadConsoleW(HANDLE hConsoleInput,
3003 LPVOID lpvBuffer,
3004 DWORD cchToRead,
3005 LPDWORD lpcchRead,
3006 LPVOID lpvReserved)
3007{
3008 BOOL fResult;
3009
3010#ifdef DEBUG_LOCAL2
3011 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleW(%08x,%08x,%08x,%08x,%08x).\n",
3012 hConsoleInput,
3013 lpvBuffer,
3014 cchToRead,
3015 lpcchRead,
3016 lpvReserved);
3017#endif
3018
3019 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3020 DRQ_READCONSOLEW,
3021 (ULONG)lpvBuffer,
3022 (ULONG)cchToRead,
3023 (ULONG)lpcchRead,
3024 (ULONG)lpvReserved);
3025
3026 return fResult;
3027}
3028
3029
3030/*****************************************************************************
3031 * Name :
3032 * Purpose :
3033 * Parameters:
3034 * Variables :
3035 * Result :
3036 * Remark :
3037 * Status :
3038 *
3039 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3040 *****************************************************************************/
3041
3042BOOL WIN32API ReadConsoleInputA(HANDLE hConsoleInput,
3043 PINPUT_RECORD pirBuffer,
3044 DWORD cInRecords,
3045 LPDWORD lpcRead)
3046{
3047 BOOL fResult;
3048
3049#ifdef DEBUG_LOCAL2
3050 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleInputA(%08x,%08x,%08x,%08x).\n",
3051 hConsoleInput,
3052 pirBuffer,
3053 cInRecords,
3054 lpcRead);
3055#endif
3056
3057 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3058 DRQ_READCONSOLEINPUTA,
3059 (ULONG)pirBuffer,
3060 (ULONG)cInRecords,
3061 (ULONG)lpcRead,
3062 0);
3063
3064 return fResult;
3065}
3066
3067
3068/*****************************************************************************
3069 * Name :
3070 * Purpose :
3071 * Parameters:
3072 * Variables :
3073 * Result :
3074 * Remark :
3075 * Status :
3076 *
3077 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3078 *****************************************************************************/
3079
3080BOOL WIN32API ReadConsoleInputW(HANDLE hConsoleInput,
3081 PINPUT_RECORD pirBuffer,
3082 DWORD cInRecords,
3083 LPDWORD lpcRead)
3084{
3085 BOOL fResult;
3086
3087#ifdef DEBUG_LOCAL2
3088 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleInputW(%08x,%08x,%08x,%08x).\n",
3089 hConsoleInput,
3090 pirBuffer,
3091 cInRecords,
3092 lpcRead);
3093#endif
3094
3095 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3096 DRQ_READCONSOLEINPUTW,
3097 (ULONG)pirBuffer,
3098 (ULONG)cInRecords,
3099 (ULONG)lpcRead,
3100 0);
3101
3102 return fResult;
3103}
3104
3105
3106/*****************************************************************************
3107 * Name :
3108 * Purpose :
3109 * Parameters:
3110 * Variables :
3111 * Result :
3112 * Remark :
3113 * Status :
3114 *
3115 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3116 *****************************************************************************/
3117
3118BOOL WIN32API ReadConsoleOutputA(HANDLE hConsoleOutput,
3119 PCHAR_INFO pchiDestBuffer,
3120 COORD coordDestBufferSize,
3121 COORD coordDestBufferCoord,
3122 PSMALL_RECT psrctSourceRect)
3123{
3124 BOOL fResult;
3125
3126#ifdef DEBUG_LOCAL2
3127 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleOutputA(%08x,%08x,%08x,%08x,%08x).\n",
3128 hConsoleOutput,
3129 pchiDestBuffer,
3130 coordDestBufferSize,
3131 coordDestBufferCoord,
3132 psrctSourceRect);
3133#endif
3134
3135 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3136 DRQ_READCONSOLEOUTPUTA,
3137 (ULONG)pchiDestBuffer,
3138 COORD2ULONG(coordDestBufferSize),
3139 COORD2ULONG(coordDestBufferCoord),
3140 (ULONG)psrctSourceRect);
3141
3142 return fResult;
3143}
3144
3145
3146/*****************************************************************************
3147 * Name :
3148 * Purpose :
3149 * Parameters:
3150 * Variables :
3151 * Result :
3152 * Remark :
3153 * Status :
3154 *
3155 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3156 *****************************************************************************/
3157
3158BOOL WIN32API ReadConsoleOutputW(HANDLE hConsoleOutput,
3159 PCHAR_INFO pchiDestBuffer,
3160 COORD coordDestBufferSize,
3161 COORD coordDestBufferCoord,
3162 PSMALL_RECT psrctSourceRect)
3163{
3164 BOOL fResult;
3165
3166#ifdef DEBUG_LOCAL2
3167 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleOutputW(%08x,%08x,%08x,%08x,%08x).\n",
3168 hConsoleOutput,
3169 pchiDestBuffer,
3170 coordDestBufferSize,
3171 coordDestBufferCoord,
3172 psrctSourceRect);
3173#endif
3174
3175 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3176 DRQ_READCONSOLEOUTPUTW,
3177 (ULONG)pchiDestBuffer,
3178 COORD2ULONG(coordDestBufferSize),
3179 COORD2ULONG(coordDestBufferCoord),
3180 (ULONG)psrctSourceRect);
3181
3182 return fResult;
3183}
3184
3185
3186/*****************************************************************************
3187 * Name :
3188 * Purpose :
3189 * Parameters:
3190 * Variables :
3191 * Result :
3192 * Remark :
3193 * Status :
3194 *
3195 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3196 *****************************************************************************/
3197
3198BOOL WIN32API ReadConsoleOutputAttribute(HANDLE hConsoleOutput,
3199 LPWORD lpwAttribute,
3200 DWORD cReadCells,
3201 COORD coordReadCoord,
3202 LPDWORD lpcNumberRead)
3203{
3204 BOOL fResult;
3205
3206#ifdef DEBUG_LOCAL2
3207 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleOutputAttribute(%08x,%08x,%08x,%08x,%08x).\n",
3208 hConsoleOutput,
3209 lpwAttribute,
3210 cReadCells,
3211 coordReadCoord,
3212 lpcNumberRead);
3213#endif
3214
3215 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3216 DRQ_READCONSOLEOUTPUTATTRIBUTE,
3217 (ULONG)lpwAttribute,
3218 (ULONG)cReadCells,
3219 COORD2ULONG(coordReadCoord),
3220 (ULONG)lpcNumberRead);
3221
3222 return fResult;
3223}
3224
3225
3226/*****************************************************************************
3227 * Name :
3228 * Purpose :
3229 * Parameters:
3230 * Variables :
3231 * Result :
3232 * Remark :
3233 * Status :
3234 *
3235 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3236 *****************************************************************************/
3237
3238BOOL WIN32API ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
3239 LPTSTR lpReadBuffer,
3240 DWORD cchRead,
3241 COORD coordReadCoord,
3242 LPDWORD lpcNumberRead)
3243{
3244 BOOL fResult;
3245
3246#ifdef DEBUG_LOCAL2
3247 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleOutputCharacterA(%08x,%08x,%08x,%08x,%08x).\n",
3248 hConsoleOutput,
3249 lpReadBuffer,
3250 cchRead,
3251 coordReadCoord,
3252 lpcNumberRead);
3253#endif
3254
3255 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3256 DRQ_READCONSOLEOUTPUTCHARACTERA,
3257 (ULONG)lpReadBuffer,
3258 (ULONG)cchRead,
3259 COORD2ULONG(coordReadCoord),
3260 (ULONG)lpcNumberRead);
3261
3262 return fResult;
3263}
3264
3265
3266/*****************************************************************************
3267 * Name :
3268 * Purpose :
3269 * Parameters:
3270 * Variables :
3271 * Result :
3272 * Remark :
3273 * Status :
3274 *
3275 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3276 *****************************************************************************/
3277
3278BOOL WIN32API ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
3279 LPTSTR lpReadBuffer,
3280 DWORD cchRead,
3281 COORD coordReadCoord,
3282 LPDWORD lpcNumberRead)
3283{
3284 BOOL fResult;
3285
3286#ifdef DEBUG_LOCAL2
3287 WriteLog("KERNEL32/CONSOLE: OS2ReadConsoleOutputCharacterW(%08x,%08x,%08x,%08x,%08x).\n",
3288 hConsoleOutput,
3289 lpReadBuffer,
3290 cchRead,
3291 coordReadCoord,
3292 lpcNumberRead);
3293#endif
3294
3295 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3296 DRQ_READCONSOLEOUTPUTCHARACTERW,
3297 (ULONG)lpReadBuffer,
3298 (ULONG)cchRead,
3299 COORD2ULONG(coordReadCoord),
3300 (ULONG)lpcNumberRead);
3301
3302 return fResult;
3303}
3304
3305
3306/*****************************************************************************
3307 * Name :
3308 * Purpose :
3309 * Parameters:
3310 * Variables :
3311 * Result :
3312 * Remark :
3313 * Status :
3314 *
3315 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3316 *****************************************************************************/
3317
3318BOOL WIN32API ScrollConsoleScreenBufferA(HANDLE hConsoleOutput,
3319 PSMALL_RECT psrctSourceRect,
3320 PSMALL_RECT psrctClipRect,
3321 COORD coordDestOrigin,
3322 PCHAR_INFO pchiFill)
3323{
3324 BOOL fResult;
3325
3326#ifdef DEBUG_LOCAL2
3327 WriteLog("KERNEL32/CONSOLE: OS2ScrollConsoleScreenBufferA(%08x,%08x,%08x,%08x,%08x).\n",
3328 hConsoleOutput,
3329 psrctSourceRect,
3330 psrctClipRect,
3331 coordDestOrigin,
3332 pchiFill);
3333#endif
3334
3335 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3336 DRQ_SCROLLCONSOLESCREENBUFFERA,
3337 (ULONG)psrctSourceRect,
3338 (ULONG)psrctClipRect,
3339 COORD2ULONG(coordDestOrigin),
3340 (ULONG)pchiFill);
3341
3342 return fResult;
3343}
3344
3345
3346/*****************************************************************************
3347 * Name :
3348 * Purpose :
3349 * Parameters:
3350 * Variables :
3351 * Result :
3352 * Remark :
3353 * Status :
3354 *
3355 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3356 *****************************************************************************/
3357
3358BOOL WIN32API ScrollConsoleScreenBufferW(HANDLE hConsoleOutput,
3359 PSMALL_RECT psrctSourceRect,
3360 PSMALL_RECT psrctClipRect,
3361 COORD coordDestOrigin,
3362 PCHAR_INFO pchiFill)
3363{
3364 BOOL fResult;
3365
3366#ifdef DEBUG_LOCAL2
3367 WriteLog("KERNEL32/CONSOLE: OS2ScrollConsoleScreenBufferW(%08x,%08x,%08x,%08x,%08x).\n",
3368 hConsoleOutput,
3369 psrctSourceRect,
3370 psrctClipRect,
3371 coordDestOrigin,
3372 pchiFill);
3373#endif
3374
3375 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3376 DRQ_SCROLLCONSOLESCREENBUFFERW,
3377 (ULONG)psrctSourceRect,
3378 (ULONG)psrctClipRect,
3379 COORD2ULONG(coordDestOrigin),
3380 (ULONG)pchiFill);
3381
3382 return fResult;
3383}
3384
3385/*****************************************************************************
3386 * Name :
3387 * Purpose :
3388 * Parameters:
3389 * Variables :
3390 * Result :
3391 * Remark :
3392 * Status :
3393 *
3394 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3395 *****************************************************************************/
3396
3397BOOL WIN32API SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
3398{
3399 BOOL fResult;
3400
3401#ifdef DEBUG_LOCAL2
3402 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleActiveScreenBuffer(%08x).\n",
3403 hConsoleOutput);
3404#endif
3405
3406 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3407 DRQ_SETCONSOLEACTIVESCREENBUFFER,
3408 0,
3409 0,
3410 0,
3411 0);
3412
3413 return fResult;
3414}
3415
3416
3417/*****************************************************************************
3418 * Name :
3419 * Purpose :
3420 * Parameters:
3421 * Variables :
3422 * Result :
3423 * Remark :
3424 * Status :
3425 *
3426 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3427 *****************************************************************************/
3428
3429BOOL WIN32API SetConsoleCP(UINT IDCodePage)
3430{
3431#ifdef DEBUG_LOCAL2
3432 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleCP(%08x) not implemented.\n",
3433 IDCodePage);
3434#endif
3435
3436 return TRUE;
3437}
3438
3439
3440/*****************************************************************************
3441 * Name :
3442 * Purpose :
3443 * Parameters:
3444 * Variables :
3445 * Result :
3446 * Remark :
3447 * Status :
3448 *
3449 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3450 *****************************************************************************/
3451
3452BOOL WIN32API SetConsoleCtrlHandler(PHANDLER_ROUTINE pHandlerRoutine,
3453 BOOL fAdd)
3454{
3455#ifdef DEBUG_LOCAL2
3456 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleCtrlHandler(%08x,%08x) not implemented.\n",
3457 pHandlerRoutine,
3458 fAdd);
3459#endif
3460
3461 return TRUE;
3462}
3463
3464
3465/*****************************************************************************
3466 * Name :
3467 * Purpose :
3468 * Parameters:
3469 * Variables :
3470 * Result :
3471 * Remark :
3472 * Status :
3473 *
3474 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3475 *****************************************************************************/
3476
3477BOOL WIN32API SetConsoleCursorInfo(HANDLE hConsoleOutput,
3478 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
3479{
3480 BOOL fResult;
3481
3482#ifdef DEBUG_LOCAL2
3483 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleCursorInfo(%08x,%08x).\n",
3484 hConsoleOutput,
3485 lpConsoleCursorInfo);
3486#endif
3487
3488 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3489 DRQ_SETCONSOLECURSORINFO,
3490 (ULONG)lpConsoleCursorInfo,
3491 0,
3492 0,
3493 0);
3494
3495 return fResult;
3496}
3497
3498
3499/*****************************************************************************
3500 * Name :
3501 * Purpose :
3502 * Parameters:
3503 * Variables :
3504 * Result :
3505 * Remark :
3506 * Status :
3507 *
3508 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3509
3510 *****************************************************************************/
3511
3512BOOL WIN32API SetConsoleCursorPosition(HANDLE hConsoleOutput,
3513 COORD coordCursor)
3514{
3515 BOOL fResult;
3516
3517#ifdef DEBUG_LOCAL2
3518 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleCursorPosition(%08x,%08x).\n",
3519 hConsoleOutput,
3520 coordCursor);
3521#endif
3522
3523 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3524 DRQ_SETCONSOLECURSORPOSITION,
3525 COORD2ULONG(coordCursor),
3526 0,
3527 0,
3528 0);
3529
3530 return fResult;
3531}
3532
3533
3534/*****************************************************************************
3535 * Name :
3536 * Purpose :
3537 * Parameters:
3538 * Variables :
3539 * Result :
3540 * Remark :
3541 * Status :
3542 *
3543 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3544 *****************************************************************************/
3545
3546BOOL WIN32API SetConsoleMode(HANDLE hConsole,
3547 DWORD fdwMode)
3548{
3549 BOOL fResult;
3550
3551#ifdef DEBUG_LOCAL2
3552 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleMode(%08x,%08x).\n",
3553 hConsole,
3554 fdwMode);
3555#endif
3556
3557 fResult = (BOOL)HMDeviceRequest(hConsole,
3558 DRQ_SETCONSOLEMODE,
3559 (ULONG)fdwMode,
3560 0,
3561 0,
3562 0);
3563
3564 return fResult;
3565}
3566
3567
3568/*****************************************************************************
3569 * Name :
3570 * Purpose :
3571 * Parameters:
3572 * Variables :
3573 * Result :
3574 * Remark :
3575 * Status :
3576 *
3577 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3578 *****************************************************************************/
3579
3580BOOL WIN32API SetConsoleOutputCP(UINT IDCodePage)
3581{
3582#ifdef DEBUG_LOCAL2
3583 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleOutputCP(%08x) not implemented.\n",
3584 IDCodePage);
3585#endif
3586
3587 return TRUE;
3588}
3589
3590
3591/*****************************************************************************
3592 * Name :
3593 * Purpose :
3594 * Parameters:
3595 * Variables :
3596 * Result :
3597 * Remark :
3598 * Status :
3599 *
3600 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3601 *****************************************************************************/
3602
3603BOOL WIN32API SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
3604 COORD coordSize)
3605{
3606 BOOL fResult;
3607
3608#ifdef DEBUG_LOCAL2
3609 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleScreenBufferSize(%08x,%08x).\n",
3610 hConsoleOutput,
3611 coordSize);
3612#endif
3613
3614 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3615 DRQ_SETCONSOLESCREENBUFFERSIZE,
3616 COORD2ULONG(coordSize),
3617 0,
3618 0,
3619 0);
3620
3621 return fResult;
3622}
3623
3624
3625/*****************************************************************************
3626 * Name :
3627 * Purpose :
3628 * Parameters:
3629 * Variables :
3630 * Result :
3631 * Remark :
3632 * Status :
3633 *
3634 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3635 *****************************************************************************/
3636
3637BOOL WIN32API SetConsoleTextAttribute(HANDLE hConsoleOutput,
3638 WORD wAttr)
3639{
3640 BOOL fResult;
3641
3642#ifdef DEBUG_LOCAL2
3643 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleTextAttribute(%08x,%04x).\n",
3644 hConsoleOutput,
3645 wAttr);
3646#endif
3647
3648 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3649 DRQ_SETCONSOLETEXTATTRIBUTE,
3650 (ULONG)wAttr,
3651 0,
3652 0,
3653 0);
3654
3655 return fResult;
3656}
3657
3658
3659/*****************************************************************************
3660 * Name : BOOL WIN32API SetConsoleTitleA
3661 * Purpose : Set new title text for the console window
3662 * Parameters: LPTSTR lpszTitle
3663 * Variables :
3664 * Result :
3665 * Remark :
3666 * Status : REWRITTEN UNTESTED
3667 *
3668 * Author : Patrick Haller [Tue, 1998/02/12 23:28]
3669 *****************************************************************************/
3670
3671BOOL WIN32API SetConsoleTitleA(LPTSTR lpszTitle)
3672{
3673#ifdef DEBUG_LOCAL2
3674 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleTitleA(%s).\n",
3675 lpszTitle);
3676#endif
3677
3678 if (ConsoleGlobals.pszWindowTitle != NULL) /* previously set name */
3679 free (ConsoleGlobals.pszWindowTitle); /* then free it */
3680
3681 ConsoleGlobals.pszWindowTitle = strdup(lpszTitle); /* copy the new name */
3682
3683 WinSetWindowText(ConsoleGlobals.hwndFrame, /* set new title text */
3684 ConsoleGlobals.pszWindowTitle);
3685
3686 return TRUE;
3687}
3688
3689
3690/*****************************************************************************
3691 * Name : BOOL WIN32API SetConsoleTitleW
3692 * Purpose : Set new title text for the console window
3693 * Parameters: LPTSTR lpszTitle
3694 * Variables :
3695 * Result :
3696 * Remark :
3697 * Status : REWRITTEN UNTESTED
3698 *
3699 * Author : Patrick Haller [Tue, 1998/02/12 23:28]
3700 *****************************************************************************/
3701
3702BOOL WIN32API SetConsoleTitleW(LPTSTR lpszTitle)
3703{
3704#ifdef DEBUG_LOCAL2
3705 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleTitleW(%s) not implemented.\n",
3706 lpszTitle);
3707#endif
3708
3709 /* @@@PH Unicode2Ascii */
3710
3711 if (ConsoleGlobals.pszWindowTitle != NULL) /* previously set name */
3712 free (ConsoleGlobals.pszWindowTitle); /* then free it */
3713
3714 ConsoleGlobals.pszWindowTitle = strdup(lpszTitle); /* copy the new name */
3715
3716 WinSetWindowText(ConsoleGlobals.hwndFrame, /* set new title text */
3717 ConsoleGlobals.pszWindowTitle);
3718
3719 return TRUE;
3720}
3721
3722
3723/*****************************************************************************
3724 * Name :
3725 * Purpose :
3726 * Parameters:
3727 * Variables :
3728 * Result :
3729 * Remark :
3730 * Status :
3731 *
3732 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3733 *****************************************************************************/
3734
3735BOOL WIN32API SetConsoleWindowInfo(HANDLE hConsoleOutput,
3736 BOOL fAbsolute,
3737 PSMALL_RECT psrctWindowRect)
3738{
3739 BOOL fResult;
3740
3741#ifdef DEBUG_LOCAL2
3742 WriteLog("KERNEL32/CONSOLE: OS2SetConsoleWindowInfo(%08x,%08x,%08x).\n",
3743 hConsoleOutput,
3744 fAbsolute,
3745 psrctWindowRect);
3746#endif
3747
3748 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3749 DRQ_SETCONSOLEWINDOWINFO,
3750 (ULONG)fAbsolute,
3751 (ULONG)psrctWindowRect,
3752 0,
3753 0);
3754
3755 return fResult;
3756}
3757
3758
3759/*****************************************************************************
3760 * Name :
3761 * Purpose :
3762 * Parameters:
3763 * Variables :
3764 * Result :
3765 * Remark :
3766 * Status :
3767 *
3768 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3769 *****************************************************************************/
3770
3771BOOL WIN32API WriteConsoleA(HANDLE hConsoleOutput,
3772 CONST VOID* lpvBuffer,
3773 DWORD cchToWrite,
3774 LPDWORD lpcchWritten,
3775 LPVOID lpvReserved)
3776{
3777 BOOL fResult;
3778
3779#ifdef DEBUG_LOCAL2
3780 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleA(%08x,%08x,%08x,%08x,%08x).\n",
3781 hConsoleOutput,
3782 lpvBuffer,
3783 cchToWrite,
3784 lpcchWritten,
3785 lpvReserved);
3786#endif
3787
3788 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3789 DRQ_WRITECONSOLEA,
3790 (ULONG)lpvBuffer,
3791 (ULONG)cchToWrite,
3792 (ULONG)lpcchWritten,
3793 (ULONG)lpvReserved);
3794
3795 return fResult;
3796}
3797
3798
3799/*****************************************************************************
3800 * Name :
3801 * Purpose :
3802 * Parameters:
3803 * Variables :
3804 * Result :
3805 * Remark :
3806 * Status :
3807 *
3808 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3809 *****************************************************************************/
3810
3811BOOL WIN32API WriteConsoleW(HANDLE hConsoleOutput,
3812 CONST VOID* lpvBuffer,
3813 DWORD cchToWrite,
3814 LPDWORD lpcchWritten,
3815 LPVOID lpvReserved)
3816{
3817 BOOL fResult;
3818
3819#ifdef DEBUG_LOCAL2
3820 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleW(%08x,%08x,%08x,%08x,%08x).\n",
3821 hConsoleOutput,
3822 lpvBuffer,
3823 cchToWrite,
3824 lpcchWritten,
3825 lpvReserved);
3826#endif
3827
3828 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3829 DRQ_WRITECONSOLEW,
3830 (ULONG)lpvBuffer,
3831 (ULONG)cchToWrite,
3832 (ULONG)lpcchWritten,
3833 (ULONG)lpvReserved);
3834
3835 return fResult;
3836}
3837
3838
3839/*****************************************************************************
3840 * Name :
3841 * Purpose :
3842 * Parameters:
3843 * Variables :
3844 * Result :
3845 * Remark :
3846 * Status :
3847 *
3848 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3849 *****************************************************************************/
3850
3851BOOL WIN32API WriteConsoleInputA(HANDLE hConsoleInput,
3852 PINPUT_RECORD pirBuffer,
3853 DWORD cInRecords,
3854 LPDWORD lpcWritten)
3855{
3856 BOOL fResult;
3857
3858#ifdef DEBUG_LOCAL2
3859 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleInputA(%08x,%08x,%08x,%08x).\n",
3860 hConsoleInput,
3861 pirBuffer,
3862 cInRecords,
3863 lpcWritten);
3864#endif
3865
3866 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3867 DRQ_WRITECONSOLEINPUTA,
3868 (ULONG)pirBuffer,
3869 (ULONG)cInRecords,
3870 (ULONG)lpcWritten,
3871 0);
3872
3873 return fResult;
3874}
3875
3876
3877/*****************************************************************************
3878 * Name :
3879 * Purpose :
3880 * Parameters:
3881 * Variables :
3882 * Result :
3883 * Remark :
3884 * Status :
3885 *
3886 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3887 *****************************************************************************/
3888
3889BOOL WIN32API WriteConsoleInputW(HANDLE hConsoleInput,
3890 PINPUT_RECORD pirBuffer,
3891 DWORD cInRecords,
3892 LPDWORD lpcWritten)
3893{
3894 BOOL fResult;
3895
3896#ifdef DEBUG_LOCAL2
3897 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleInputW(%08x,%08x,%08x,%08x).\n",
3898 hConsoleInput,
3899 pirBuffer,
3900 cInRecords,
3901 lpcWritten);
3902#endif
3903
3904 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3905 DRQ_WRITECONSOLEINPUTW,
3906 (ULONG)pirBuffer,
3907 (ULONG)cInRecords,
3908 (ULONG)lpcWritten,
3909 0);
3910
3911 return fResult;
3912}
3913
3914
3915/*****************************************************************************
3916 * Name :
3917 * Purpose :
3918 * Parameters:
3919 * Variables :
3920 * Result :
3921 * Remark :
3922 * Status :
3923 *
3924 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3925 *****************************************************************************/
3926
3927BOOL WIN32API WriteConsoleOutputA(HANDLE hConsoleOutput,
3928 PCHAR_INFO pchiSrcBuffer,
3929 COORD coordSrcBufferSize,
3930 COORD coordSrcBufferCoord,
3931 PSMALL_RECT psrctDestRect)
3932{
3933 BOOL fResult;
3934
3935#ifdef DEBUG_LOCAL2
3936 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleOutputA(%08x,%08x,%08x,%08x,%08x).\n",
3937 hConsoleOutput,
3938 pchiSrcBuffer,
3939 coordSrcBufferSize,
3940 coordSrcBufferCoord,
3941 psrctDestRect);
3942#endif
3943
3944 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3945 DRQ_WRITECONSOLEOUTPUTA,
3946 (ULONG)pchiSrcBuffer,
3947 COORD2ULONG(coordSrcBufferSize),
3948 COORD2ULONG(coordSrcBufferCoord),
3949 (ULONG)psrctDestRect);
3950
3951 return fResult;
3952}
3953
3954
3955/*****************************************************************************
3956 * Name :
3957 * Purpose :
3958 * Parameters:
3959 * Variables :
3960 * Result :
3961 * Remark :
3962 * Status :
3963 *
3964 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3965 *****************************************************************************/
3966
3967BOOL WIN32API WriteConsoleOutputW(HANDLE hConsoleOutput,
3968 PCHAR_INFO pchiSrcBuffer,
3969 COORD coordSrcBufferSize,
3970 COORD coordSrcBufferCoord,
3971 PSMALL_RECT psrctDestRect)
3972{
3973 BOOL fResult;
3974
3975#ifdef DEBUG_LOCAL2
3976 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleOutputW(%08x,%08x,%08x,%08x,%08x).\n",
3977 hConsoleOutput,
3978 pchiSrcBuffer,
3979 coordSrcBufferSize,
3980 coordSrcBufferCoord,
3981 psrctDestRect);
3982#endif
3983
3984 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3985 DRQ_WRITECONSOLEOUTPUTW,
3986 (ULONG)pchiSrcBuffer,
3987 COORD2ULONG(coordSrcBufferSize),
3988 COORD2ULONG(coordSrcBufferCoord),
3989 (ULONG)psrctDestRect);
3990
3991 return fResult;
3992}
3993
3994/*****************************************************************************
3995 * Name :
3996 * Purpose :
3997 * Parameters:
3998 * Variables :
3999 * Result :
4000 * Remark :
4001 * Status :
4002 *
4003 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
4004 *****************************************************************************/
4005
4006BOOL WIN32API WriteConsoleOutputAttribute(HANDLE hConsoleOutput,
4007 LPWORD lpwAttribute,
4008 DWORD cWriteCells,
4009 COORD coordWriteCoord,
4010 LPDWORD lpcNumberWritten)
4011{
4012 BOOL fResult;
4013
4014#ifdef DEBUG_LOCAL2
4015 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleOutputAttribute(%08x,%08x,%08x,%08x,%08x).\n",
4016 hConsoleOutput,
4017 lpwAttribute,
4018 cWriteCells,
4019 coordWriteCoord,
4020 lpcNumberWritten);
4021#endif
4022
4023 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
4024 DRQ_WRITECONSOLEOUTPUTATTRIBUTE,
4025 (ULONG)lpwAttribute,
4026 (ULONG)cWriteCells,
4027 COORD2ULONG(coordWriteCoord),
4028 (ULONG)lpcNumberWritten);
4029
4030 return fResult;
4031}
4032
4033
4034/*****************************************************************************
4035 * Name :
4036 * Purpose :
4037 * Parameters:
4038 * Variables :
4039 * Result :
4040 * Remark :
4041 * Status :
4042 *
4043 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
4044 *****************************************************************************/
4045
4046BOOL WIN32API WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,
4047 LPTSTR lpWriteBuffer,
4048 DWORD cchWrite,
4049 COORD coordWriteCoord,
4050 LPDWORD lpcWritten)
4051{
4052 BOOL fResult;
4053
4054#ifdef DEBUG_LOCAL2
4055 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleOutputCharacterA(%08x,%08x,%08x,%08x,%08x).\n",
4056 hConsoleOutput,
4057 lpWriteBuffer,
4058 cchWrite,
4059 coordWriteCoord,
4060 lpcWritten);
4061#endif
4062
4063 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
4064 DRQ_WRITECONSOLEOUTPUTCHARACTERA,
4065 (ULONG)lpWriteBuffer,
4066 (ULONG)cchWrite,
4067 COORD2ULONG(coordWriteCoord),
4068 (ULONG)lpcWritten);
4069
4070 return fResult;
4071}
4072
4073
4074/*****************************************************************************
4075 * Name :
4076 * Purpose :
4077 * Parameters:
4078 * Variables :
4079 * Result :
4080 * Remark :
4081 * Status :
4082 *
4083 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
4084 *****************************************************************************/
4085
4086BOOL WIN32API WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,
4087 LPTSTR lpWriteBuffer,
4088 DWORD cchWrite,
4089 COORD coordWriteCoord,
4090 LPDWORD lpcWritten)
4091{
4092 BOOL fResult;
4093
4094#ifdef DEBUG_LOCAL2
4095 WriteLog("KERNEL32/CONSOLE: OS2WriteConsoleOutputCharacterW(%08x,%08x,%08x,%08x,%08x).\n",
4096 hConsoleOutput,
4097 lpWriteBuffer,
4098 cchWrite,
4099 coordWriteCoord,
4100 lpcWritten);
4101#endif
4102
4103 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
4104 DRQ_WRITECONSOLEOUTPUTCHARACTERW,
4105 (ULONG)lpWriteBuffer,
4106 (ULONG)cchWrite,
4107 COORD2ULONG(coordWriteCoord),
4108 (ULONG)lpcWritten);
4109
4110 return fResult;
4111}
Note: See TracBrowser for help on using the repository browser.