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

Last change on this file since 22050 was 22050, checked in by dmik, 13 years ago

kernel32: All console modes are on by default except ENABLE_WINDOW_INPUT.

This is according to MSDN.

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