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

Last change on this file since 9544 was 9544, checked in by sandervl, 23 years ago

removed hardcoded writelog calls

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