source: branches/gcc-kmk/src/kernel32/console.cpp@ 21755

Last change on this file since 21755 was 21755, checked in by dmik, 14 years ago

Extern "C".

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