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

Last change on this file since 21426 was 21426, checked in by dmik, 15 years ago

Attempted to make Odin work in LIBPATHSTRICT=T mode by replacing DosQueryModuleHandle() with the custom made DosQueryModuleHandleStrict().

File size: 131.5 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
2310
2311/*****************************************************************************
2312 * Name : BOOL WIN32API AllocConsole
2313 * Purpose : The AllocConsole function allocates a new console
2314 * for the calling process
2315 * Parameters: VOID
2316 * Variables :
2317 * Result : BOOL: TRUE - function succeeded
2318 * FALSE - function failed. Extended error information
2319 * obtainable via GetLastError
2320 * Remark :
2321 * Status : REWRITTEN UNTESTED
2322 *
2323 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2324 *****************************************************************************/
2325
2326BOOL WIN32API AllocConsole(VOID)
2327{
2328 APIRET rc; /* API returncode */
2329
2330 dprintf(("KERNEL32/CONSOLE: OS2AllocConsole() called"));
2331
2332 rc = iConsoleInit(flVioConsole); /* initialize subsystem if required */
2333 if (rc != NO_ERROR) /* check for errors */
2334 {
2335 SetLastError(rc); /* pass thru the error code */
2336 return FALSE; /* signal failure */
2337 }
2338 else
2339 return TRUE; /* Fine ! :) */
2340}
2341
2342
2343/*****************************************************************************
2344 * Name : HANDLE WIN32API CreateConsoleScreenBuffer
2345 * Purpose : The CreateConsoleScreenBuffer function creates a console
2346 * screen buffer and returns a handle of it.
2347 * Parameters: DWORD dwDesiredAccess - access flag
2348 * DWORD dwShareMode - buffer share more
2349 * PVOID pIgnored - LPSECURITY_ATTRIBUTES -> NT
2350 * DWORD dwFlags - type of buffer to create
2351 * LPVOID lpScreenBufferData - reserved
2352 * Variables :
2353 * Result :
2354 * Remark : a console buffer is a kernel heap object equipped with
2355 * share modes, access rights, etc.
2356 * we can't really map this to OS/2 unless we build a
2357 * console device driver for it ... maybe this turns out to
2358 * be necessary since we've got to handle CONIN$ and CONOUT$, too.
2359 * Status :
2360 *
2361 * Author : Patrick Haller [Tue, 1998/02/10 03:55]
2362 *****************************************************************************/
2363
2364HANDLE WIN32API CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
2365 DWORD dwShareMode,
2366 LPVOID lpSecurityAttributes,
2367 DWORD dwFlags,
2368 LPVOID lpScreenBufferData)
2369{
2370 HANDLE hResult;
2371
2372 hResult = HMCreateFile("CONBUFFER$", /* create a new buffer handle */
2373 dwDesiredAccess,
2374 dwShareMode,
2375 (LPSECURITY_ATTRIBUTES)lpSecurityAttributes,
2376 0,
2377 dwFlags,
2378 INVALID_HANDLE_VALUE);
2379
2380 return hResult;
2381}
2382
2383
2384/*****************************************************************************
2385 * Name :
2386 * Purpose :
2387 * Parameters:
2388 * Variables :
2389 * Result :
2390 * Remark :
2391 * Status :
2392 *
2393 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2394 *****************************************************************************/
2395
2396BOOL WIN32API FillConsoleOutputAttribute(HANDLE hConsoleOutput,
2397 WORD wAttribute,
2398 DWORD nLength,
2399 COORD dwWriteCoord,
2400 LPDWORD lpNumberOfAttrsWritten)
2401{
2402 BOOL fResult;
2403
2404 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2405 DRQ_FILLCONSOLEOUTPUTATTRIBUTE,
2406 (ULONG)wAttribute,
2407 (ULONG)nLength,
2408 COORD2ULONG(dwWriteCoord),
2409 (ULONG)lpNumberOfAttrsWritten);
2410
2411 return fResult;
2412}
2413
2414
2415/*****************************************************************************
2416 * Name :
2417 * Purpose :
2418 * Parameters:
2419 * Variables :
2420 * Result :
2421 * Remark :
2422 * Status :
2423 *
2424 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2425 *****************************************************************************/
2426
2427BOOL WIN32API FillConsoleOutputCharacterA(HANDLE hConsoleOutput,
2428 UCHAR cCharacter,
2429 DWORD nLength,
2430 COORD dwWriteCoord,
2431 LPDWORD lpNumberOfCharsWritten )
2432{
2433 BOOL fResult;
2434
2435 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2436 DRQ_FILLCONSOLEOUTPUTCHARACTERA,
2437 (ULONG)cCharacter,
2438 (ULONG)nLength,
2439 COORD2ULONG(dwWriteCoord),
2440 (ULONG)lpNumberOfCharsWritten);
2441
2442 return fResult;
2443}
2444
2445
2446/*****************************************************************************
2447 * Name :
2448 * Purpose :
2449 * Parameters:
2450 * Variables :
2451 * Result :
2452 * Remark :
2453 * Status :
2454 *
2455 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2456 *****************************************************************************/
2457
2458BOOL WIN32API FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
2459 WCHAR cCharacter,
2460 DWORD nLength,
2461 COORD dwWriteCoord,
2462 LPDWORD lpNumberOfCharsWritten )
2463{
2464 BOOL fResult;
2465
2466 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2467 DRQ_FILLCONSOLEOUTPUTCHARACTERW,
2468 (ULONG)cCharacter,
2469 (ULONG)nLength,
2470 COORD2ULONG(dwWriteCoord),
2471 (ULONG)lpNumberOfCharsWritten);
2472
2473 return fResult;
2474}
2475
2476
2477/*****************************************************************************
2478 * Name :
2479 * Purpose :
2480 * Parameters:
2481 * Variables :
2482 * Result :
2483 * Remark :
2484 * Status :
2485 *
2486 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2487 *****************************************************************************/
2488
2489BOOL WIN32API FlushConsoleInputBuffer( HANDLE hConsoleInput )
2490{
2491 BOOL fResult;
2492
2493 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2494 DRQ_FLUSHCONSOLEINPUTBUFFER,
2495 0,
2496 0,
2497 0,
2498 0);
2499
2500 return fResult;
2501}
2502
2503
2504/*****************************************************************************
2505 * Name : BOOL WIN32API FreeConsole
2506 * Purpose : The FreeConsole function detaches the calling process
2507 * from its console.
2508 * Parameters: VOID
2509 * Variables :
2510 * Result : BOOL: TRUE - function succeeded
2511 * FALSE - function failed. Extended error information
2512 * obtainable via GetLastError
2513 * Remark :
2514 * Status : REWRITTEN UNTESTED
2515 *
2516 * Author : Patrick Haller [Tue, 1998/02/10 03:35]
2517 *****************************************************************************/
2518
2519BOOL WIN32API FreeConsole( VOID )
2520{
2521 APIRET rc; /* API returncode */
2522
2523 rc = iConsoleTerminate(); /* terminate subsystem if required */
2524 if (rc != NO_ERROR) /* check for errors */
2525 {
2526 SetLastError(rc); /* pass thru the error code */
2527 return FALSE; /* signal failure */
2528 }
2529 else
2530 return TRUE; /* Fine ! :) */
2531
2532 return TRUE;
2533}
2534
2535
2536/*****************************************************************************
2537 * Name :
2538 * Purpose :
2539 * Parameters:
2540 * Variables :
2541 * Result :
2542 * Remark :
2543 * Status :
2544 *
2545 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2546 *****************************************************************************/
2547
2548UINT WIN32API GetConsoleCP(VOID)
2549{
2550 dprintf(("KERNEL32/CONSOLE: GetConsoleCP not implemented"));
2551
2552 return 1;
2553}
2554
2555
2556/*****************************************************************************
2557 * Name :
2558 * Purpose :
2559 * Parameters:
2560 * Variables :
2561 * Result :
2562 * Remark :
2563 * Status :
2564 *
2565 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2566 *****************************************************************************/
2567
2568BOOL WIN32API GetConsoleCursorInfo(HANDLE hConsoleOutput,
2569 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
2570{
2571 BOOL fResult;
2572
2573 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2574 DRQ_GETCONSOLECURSORINFO,
2575 (ULONG)lpConsoleCursorInfo,
2576 0,
2577 0,
2578 0);
2579
2580 return fResult;
2581}
2582
2583
2584/*****************************************************************************
2585 * Name :
2586 * Purpose :
2587 * Parameters:
2588 * Variables :
2589 * Result :
2590 * Remark :
2591 * Status :
2592 *
2593 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2594 *****************************************************************************/
2595
2596BOOL WIN32API GetConsoleMode(HANDLE hConsole,
2597 LPDWORD lpMode)
2598{
2599 BOOL fResult;
2600
2601 fResult = (BOOL)HMDeviceRequest(hConsole,
2602 DRQ_GETCONSOLEMODE,
2603 (ULONG) lpMode,
2604 0,
2605 0,
2606 0);
2607
2608 return fResult;
2609}
2610
2611
2612/*****************************************************************************
2613 * Name :
2614 * Purpose :
2615 * Parameters:
2616 * Variables :
2617 * Result :
2618 * Remark :
2619 * Status :
2620 *
2621 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2622 *****************************************************************************/
2623
2624UINT WIN32API GetConsoleOutputCP(VOID)
2625{
2626 dprintf(("KERNEL32/CONSOLE: GetConsoleOutputCP not implemented"));
2627
2628 return 1;
2629}
2630
2631
2632/*****************************************************************************
2633 * Name :
2634 * Purpose :
2635 * Parameters:
2636 * Variables :
2637 * Result :
2638 * Remark :
2639 * Status :
2640 *
2641 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2642 *****************************************************************************/
2643
2644BOOL WIN32API GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,
2645 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
2646{
2647 BOOL fResult;
2648
2649 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
2650 DRQ_GETCONSOLESCREENBUFFERINFO,
2651 (ULONG)lpConsoleScreenBufferInfo,
2652 0,
2653 0,
2654 0);
2655
2656 return fResult;
2657}
2658
2659
2660/*****************************************************************************
2661 * Name : DWORD WIN32API GetConsoleTitle
2662 * Purpose : Query the current console window title
2663 * Parameters: LPTSTR lpConsoleTitle
2664 * DWORD nSize
2665 * Variables :
2666 * Result : number of copied bytes
2667 * Remark :
2668 * Status : REWRITTEN UNTESTED
2669 *
2670 * Author : Patrick Haller [Thu, 1998/02/12 23:31]
2671 *****************************************************************************/
2672
2673DWORD WIN32API GetConsoleTitleA(LPTSTR lpConsoleTitle,
2674 DWORD nSize)
2675{
2676 ULONG ulLength; /* length of text */
2677
2678 if (ConsoleGlobals.pszWindowTitle == NULL) /* is there a window title ? */
2679 return 0; /* abort immediately */
2680
2681 ulLength = strlen(ConsoleGlobals.pszWindowTitle); /* length of text */
2682
2683 strncpy(lpConsoleTitle,
2684 ConsoleGlobals.pszWindowTitle,
2685 nSize);
2686 lpConsoleTitle[nSize-1] = 0;
2687
2688 return (nSize < ulLength) ? nSize : ulLength;
2689}
2690
2691
2692/*****************************************************************************
2693 * Name : DWORD WIN32API GetConsoleTitle
2694 * Purpose : Query the current console window title
2695 * Parameters: LPTSTR lpConsoleTitle
2696 * DWORD nSize
2697 * Variables :
2698 * Result : number of copied bytes
2699 * Remark :
2700 * Status : REWRITTEN UNTESTED
2701 *
2702 * Author : Patrick Haller [Thu, 1998/02/12 23:31]
2703 *****************************************************************************/
2704
2705
2706DWORD WIN32API GetConsoleTitleW(LPWSTR lpConsoleTitle,
2707 DWORD nSize)
2708{
2709 if (ConsoleGlobals.pszWindowTitle == NULL) /* is there a window title ? */
2710 return 0; /* abort immediately */
2711
2712 MultiByteToWideChar( GetConsoleCP(), 0, ConsoleGlobals.pszWindowTitle, -1,
2713 lpConsoleTitle, nSize );
2714 lpConsoleTitle[ nSize - 1 ] = 0;
2715
2716 return lstrlenW( lpConsoleTitle );
2717}
2718
2719
2720/*****************************************************************************
2721 * Name : COORD WIN32API GetLargestConsoleWindowSize
2722 * Purpose : Determine maximum AVIO size
2723 * Parameters:
2724 * Variables :
2725 * Result :
2726 * Remark :
2727 * Status :
2728 *
2729 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2730 *****************************************************************************/
2731
2732COORD WIN32API GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
2733{
2734 DWORD dwResult;
2735 COORD coordResult;
2736
2737 dwResult = HMDeviceRequest(hConsoleOutput,
2738 DRQ_GETLARGESTCONSOLEWINDOWSIZE,
2739 0,
2740 0,
2741 0,
2742 0);
2743
2744 ULONG2COORD(coordResult,dwResult)
2745 return ( coordResult );
2746}
2747
2748
2749/*****************************************************************************
2750 * Name :
2751 * Purpose :
2752 * Parameters:
2753 * Variables :
2754 * Result :
2755 * Remark :
2756 * Status :
2757 *
2758 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2759 *****************************************************************************/
2760
2761BOOL WIN32API GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
2762 LPDWORD lpNumberOfEvents)
2763{
2764 BOOL fResult;
2765
2766 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2767 DRQ_GETNUMBEROFCONSOLEINPUTEVENTS,
2768 (ULONG)lpNumberOfEvents,
2769 0,
2770 0,
2771 0);
2772
2773 return fResult;
2774}
2775
2776
2777/*****************************************************************************
2778 * Name :
2779 * Purpose :
2780 * Parameters:
2781 * Variables :
2782 * Result :
2783 * Remark :
2784 * Status :
2785 *
2786 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2787 *****************************************************************************/
2788
2789BOOL WIN32API GetNumberOfConsoleMouseButtons(LPDWORD lpcNumberOfMouseButtons)
2790{
2791 LONG lMouseButtons;
2792
2793 lMouseButtons = WinQuerySysValue(HWND_DESKTOP, /* query PM for that */
2794 SV_CMOUSEBUTTONS);
2795
2796 *lpcNumberOfMouseButtons = (DWORD)lMouseButtons;
2797
2798 return TRUE;
2799}
2800
2801
2802/*****************************************************************************
2803 * Name :
2804 * Purpose :
2805 * Parameters:
2806 * Variables :
2807 * Result :
2808 * Remark :
2809 * Status :
2810 *
2811 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2812 *****************************************************************************/
2813
2814BOOL WIN32API PeekConsoleInputW(HANDLE hConsoleInput,
2815 PINPUT_RECORD pirBuffer,
2816 DWORD cInRecords,
2817 LPDWORD lpcRead)
2818{
2819 BOOL fResult;
2820
2821 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2822 DRQ_PEEKCONSOLEINPUTW,
2823 (ULONG)pirBuffer,
2824 (ULONG)cInRecords,
2825 (ULONG)lpcRead,
2826 0);
2827
2828 return fResult;
2829}
2830
2831
2832/*****************************************************************************
2833 * Name :
2834 * Purpose :
2835 * Parameters:
2836 * Variables :
2837 * Result :
2838 * Remark :
2839 * Status :
2840 *
2841 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2842 *****************************************************************************/
2843
2844BOOL WIN32API PeekConsoleInputA(HANDLE hConsoleInput,
2845 PINPUT_RECORD pirBuffer,
2846 DWORD cInRecords,
2847 LPDWORD lpcRead)
2848{
2849 BOOL fResult;
2850
2851 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2852 DRQ_PEEKCONSOLEINPUTA,
2853 (ULONG)pirBuffer,
2854 (ULONG)cInRecords,
2855 (ULONG)lpcRead,
2856 0);
2857
2858 return fResult;
2859}
2860
2861
2862/*****************************************************************************
2863 * Name :
2864 * Purpose :
2865 * Parameters:
2866 * Variables :
2867 * Result :
2868 * Remark :
2869 * Status :
2870 *
2871 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2872 *****************************************************************************/
2873
2874BOOL WIN32API ReadConsoleA(HANDLE hConsoleInput,
2875 LPVOID lpvBuffer,
2876 DWORD cchToRead,
2877 LPDWORD lpcchRead,
2878 LPVOID lpvReserved)
2879{
2880 BOOL fResult;
2881
2882 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2883 DRQ_READCONSOLEA,
2884 (ULONG)lpvBuffer,
2885 (ULONG)cchToRead,
2886 (ULONG)lpcchRead,
2887 (ULONG)lpvReserved);
2888
2889 return fResult;
2890}
2891
2892
2893/*****************************************************************************
2894 * Name :
2895 * Purpose :
2896 * Parameters:
2897 * Variables :
2898 * Result :
2899 * Remark :
2900 * Status :
2901 *
2902 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2903 *****************************************************************************/
2904
2905BOOL WIN32API ReadConsoleW(HANDLE hConsoleInput,
2906 LPVOID lpvBuffer,
2907 DWORD cchToRead,
2908 LPDWORD lpcchRead,
2909 LPVOID lpvReserved)
2910{
2911 BOOL fResult;
2912
2913 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2914 DRQ_READCONSOLEW,
2915 (ULONG)lpvBuffer,
2916 (ULONG)cchToRead,
2917 (ULONG)lpcchRead,
2918 (ULONG)lpvReserved);
2919
2920 return fResult;
2921}
2922
2923
2924/*****************************************************************************
2925 * Name :
2926 * Purpose :
2927 * Parameters:
2928 * Variables :
2929 * Result :
2930 * Remark :
2931 * Status :
2932 *
2933 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2934 *****************************************************************************/
2935
2936BOOL WIN32API ReadConsoleInputA(HANDLE hConsoleInput,
2937 PINPUT_RECORD pirBuffer,
2938 DWORD cInRecords,
2939 LPDWORD lpcRead)
2940{
2941 BOOL fResult;
2942
2943 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2944 DRQ_READCONSOLEINPUTA,
2945 (ULONG)pirBuffer,
2946 (ULONG)cInRecords,
2947 (ULONG)lpcRead,
2948 0);
2949
2950 return fResult;
2951}
2952
2953
2954/*****************************************************************************
2955 * Name :
2956 * Purpose :
2957 * Parameters:
2958 * Variables :
2959 * Result :
2960 * Remark :
2961 * Status :
2962 *
2963 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2964 *****************************************************************************/
2965
2966BOOL WIN32API ReadConsoleInputW(HANDLE hConsoleInput,
2967 PINPUT_RECORD pirBuffer,
2968 DWORD cInRecords,
2969 LPDWORD lpcRead)
2970{
2971 BOOL fResult;
2972
2973 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
2974 DRQ_READCONSOLEINPUTW,
2975 (ULONG)pirBuffer,
2976 (ULONG)cInRecords,
2977 (ULONG)lpcRead,
2978 0);
2979
2980 return fResult;
2981}
2982
2983
2984/*****************************************************************************
2985 * Name :
2986 * Purpose :
2987 * Parameters:
2988 * Variables :
2989 * Result :
2990 * Remark :
2991 * Status :
2992 *
2993 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
2994 *****************************************************************************/
2995
2996BOOL WIN32API ReadConsoleOutputA(HANDLE hConsoleOutput,
2997 PCHAR_INFO pchiDestBuffer,
2998 COORD coordDestBufferSize,
2999 COORD coordDestBufferCoord,
3000 PSMALL_RECT psrctSourceRect)
3001{
3002 BOOL fResult;
3003
3004 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3005 DRQ_READCONSOLEOUTPUTA,
3006 (ULONG)pchiDestBuffer,
3007 COORD2ULONG(coordDestBufferSize),
3008 COORD2ULONG(coordDestBufferCoord),
3009 (ULONG)psrctSourceRect);
3010
3011 return fResult;
3012}
3013
3014
3015/*****************************************************************************
3016 * Name :
3017 * Purpose :
3018 * Parameters:
3019 * Variables :
3020 * Result :
3021 * Remark :
3022 * Status :
3023 *
3024 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3025 *****************************************************************************/
3026
3027BOOL WIN32API ReadConsoleOutputW(HANDLE hConsoleOutput,
3028 PCHAR_INFO pchiDestBuffer,
3029 COORD coordDestBufferSize,
3030 COORD coordDestBufferCoord,
3031 PSMALL_RECT psrctSourceRect)
3032{
3033 BOOL fResult;
3034
3035 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3036 DRQ_READCONSOLEOUTPUTW,
3037 (ULONG)pchiDestBuffer,
3038 COORD2ULONG(coordDestBufferSize),
3039 COORD2ULONG(coordDestBufferCoord),
3040 (ULONG)psrctSourceRect);
3041
3042 return fResult;
3043}
3044
3045
3046/*****************************************************************************
3047 * Name :
3048 * Purpose :
3049 * Parameters:
3050 * Variables :
3051 * Result :
3052 * Remark :
3053 * Status :
3054 *
3055 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3056 *****************************************************************************/
3057
3058BOOL WIN32API ReadConsoleOutputAttribute(HANDLE hConsoleOutput,
3059 LPWORD lpwAttribute,
3060 DWORD cReadCells,
3061 COORD coordReadCoord,
3062 LPDWORD lpcNumberRead)
3063{
3064 BOOL fResult;
3065
3066 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3067 DRQ_READCONSOLEOUTPUTATTRIBUTE,
3068 (ULONG)lpwAttribute,
3069 (ULONG)cReadCells,
3070 COORD2ULONG(coordReadCoord),
3071 (ULONG)lpcNumberRead);
3072
3073 return fResult;
3074}
3075
3076
3077/*****************************************************************************
3078 * Name :
3079 * Purpose :
3080 * Parameters:
3081 * Variables :
3082 * Result :
3083 * Remark :
3084 * Status :
3085 *
3086 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3087 *****************************************************************************/
3088
3089BOOL WIN32API ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
3090 LPTSTR lpReadBuffer,
3091 DWORD cchRead,
3092 COORD coordReadCoord,
3093 LPDWORD lpcNumberRead)
3094{
3095 BOOL fResult;
3096
3097 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3098 DRQ_READCONSOLEOUTPUTCHARACTERA,
3099 (ULONG)lpReadBuffer,
3100 (ULONG)cchRead,
3101 COORD2ULONG(coordReadCoord),
3102 (ULONG)lpcNumberRead);
3103
3104 return fResult;
3105}
3106
3107
3108/*****************************************************************************
3109 * Name :
3110 * Purpose :
3111 * Parameters:
3112 * Variables :
3113 * Result :
3114 * Remark :
3115 * Status :
3116 *
3117 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3118 *****************************************************************************/
3119
3120BOOL WIN32API ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
3121 LPTSTR lpReadBuffer,
3122 DWORD cchRead,
3123 COORD coordReadCoord,
3124 LPDWORD lpcNumberRead)
3125{
3126 BOOL fResult;
3127
3128 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3129 DRQ_READCONSOLEOUTPUTCHARACTERW,
3130 (ULONG)lpReadBuffer,
3131 (ULONG)cchRead,
3132 COORD2ULONG(coordReadCoord),
3133 (ULONG)lpcNumberRead);
3134
3135 return fResult;
3136}
3137
3138
3139/*****************************************************************************
3140 * Name :
3141 * Purpose :
3142 * Parameters:
3143 * Variables :
3144 * Result :
3145 * Remark :
3146 * Status :
3147 *
3148 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3149 *****************************************************************************/
3150
3151BOOL WIN32API ScrollConsoleScreenBufferA(HANDLE hConsoleOutput,
3152 PSMALL_RECT psrctSourceRect,
3153 PSMALL_RECT psrctClipRect,
3154 COORD coordDestOrigin,
3155 PCHAR_INFO pchiFill)
3156{
3157 BOOL fResult;
3158
3159 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3160 DRQ_SCROLLCONSOLESCREENBUFFERA,
3161 (ULONG)psrctSourceRect,
3162 (ULONG)psrctClipRect,
3163 COORD2ULONG(coordDestOrigin),
3164 (ULONG)pchiFill);
3165
3166 return fResult;
3167}
3168
3169
3170/*****************************************************************************
3171 * Name :
3172 * Purpose :
3173 * Parameters:
3174 * Variables :
3175 * Result :
3176 * Remark :
3177 * Status :
3178 *
3179 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3180 *****************************************************************************/
3181
3182BOOL WIN32API ScrollConsoleScreenBufferW(HANDLE hConsoleOutput,
3183 PSMALL_RECT psrctSourceRect,
3184 PSMALL_RECT psrctClipRect,
3185 COORD coordDestOrigin,
3186 PCHAR_INFO pchiFill)
3187{
3188 BOOL fResult;
3189
3190 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3191 DRQ_SCROLLCONSOLESCREENBUFFERW,
3192 (ULONG)psrctSourceRect,
3193 (ULONG)psrctClipRect,
3194 COORD2ULONG(coordDestOrigin),
3195 (ULONG)pchiFill);
3196
3197 return fResult;
3198}
3199
3200/*****************************************************************************
3201 * Name :
3202 * Purpose :
3203 * Parameters:
3204 * Variables :
3205 * Result :
3206 * Remark :
3207 * Status :
3208 *
3209 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3210 *****************************************************************************/
3211
3212BOOL WIN32API SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
3213{
3214 BOOL fResult;
3215
3216 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3217 DRQ_SETCONSOLEACTIVESCREENBUFFER,
3218 0,
3219 0,
3220 0,
3221 0);
3222
3223 return fResult;
3224}
3225
3226
3227/*****************************************************************************
3228 * Name :
3229 * Purpose :
3230 * Parameters:
3231 * Variables :
3232 * Result :
3233 * Remark :
3234 * Status :
3235 *
3236 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3237 *****************************************************************************/
3238
3239BOOL WIN32API SetConsoleCP(UINT IDCodePage)
3240{
3241 dprintf(("KERNEL32/CONSOLE: SetConsoleCP(%08x) not implemented.\n",
3242 IDCodePage));
3243
3244 return TRUE;
3245}
3246
3247
3248/*****************************************************************************
3249 * Name :
3250 * Purpose :
3251 * Parameters:
3252 * Variables :
3253 * Result :
3254 * Remark :
3255 * Status :
3256 *
3257 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3258 *****************************************************************************/
3259
3260BOOL WIN32API SetConsoleCursorInfo(HANDLE hConsoleOutput,
3261 PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
3262{
3263 BOOL fResult;
3264
3265 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3266 DRQ_SETCONSOLECURSORINFO,
3267 (ULONG)lpConsoleCursorInfo,
3268 0,
3269 0,
3270 0);
3271
3272 return fResult;
3273}
3274
3275
3276/*****************************************************************************
3277 * Name :
3278 * Purpose :
3279 * Parameters:
3280 * Variables :
3281 * Result :
3282 * Remark :
3283 * Status :
3284 *
3285 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3286
3287 *****************************************************************************/
3288
3289BOOL WIN32API SetConsoleCursorPosition(HANDLE hConsoleOutput,
3290 COORD coordCursor)
3291{
3292 BOOL fResult;
3293
3294 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3295 DRQ_SETCONSOLECURSORPOSITION,
3296 COORD2ULONG(coordCursor),
3297 0,
3298 0,
3299 0);
3300
3301 return fResult;
3302}
3303
3304
3305/*****************************************************************************
3306 * Name :
3307 * Purpose :
3308 * Parameters:
3309 * Variables :
3310 * Result :
3311 * Remark :
3312 * Status :
3313 *
3314 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3315 *****************************************************************************/
3316
3317BOOL WIN32API SetConsoleMode(HANDLE hConsole,
3318 DWORD fdwMode)
3319{
3320 BOOL fResult;
3321
3322 fResult = (BOOL)HMDeviceRequest(hConsole,
3323 DRQ_SETCONSOLEMODE,
3324 (ULONG)fdwMode,
3325 0,
3326 0,
3327 0);
3328
3329 return fResult;
3330}
3331
3332
3333/*****************************************************************************
3334 * Name :
3335 * Purpose :
3336 * Parameters:
3337 * Variables :
3338 * Result :
3339 * Remark :
3340 * Status :
3341 *
3342 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3343 *****************************************************************************/
3344
3345BOOL WIN32API SetConsoleOutputCP(UINT IDCodePage)
3346{
3347 dprintf(("KERNEL32/CONSOLE: OS2SetConsoleOutputCP(%08x) not implemented.\n",
3348 IDCodePage));
3349
3350 return TRUE;
3351}
3352
3353
3354/*****************************************************************************
3355 * Name :
3356 * Purpose :
3357 * Parameters:
3358 * Variables :
3359 * Result :
3360 * Remark :
3361 * Status :
3362 *
3363 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3364 *****************************************************************************/
3365
3366BOOL WIN32API SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
3367 COORD coordSize)
3368{
3369 BOOL fResult;
3370
3371 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3372 DRQ_SETCONSOLESCREENBUFFERSIZE,
3373 COORD2ULONG(coordSize),
3374 0,
3375 0,
3376 0);
3377
3378 return fResult;
3379}
3380
3381
3382/*****************************************************************************
3383 * Name :
3384 * Purpose :
3385 * Parameters:
3386 * Variables :
3387 * Result :
3388 * Remark :
3389 * Status :
3390 *
3391 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3392 *****************************************************************************/
3393
3394BOOL WIN32API SetConsoleTextAttribute(HANDLE hConsoleOutput,
3395 WORD wAttr)
3396{
3397 BOOL fResult;
3398
3399 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3400 DRQ_SETCONSOLETEXTATTRIBUTE,
3401 (ULONG)wAttr,
3402 0,
3403 0,
3404 0);
3405
3406 return fResult;
3407}
3408
3409
3410/*****************************************************************************
3411 * Name : BOOL WIN32API SetConsoleTitleA
3412 * Purpose : Set new title text for the console window
3413 * Parameters: LPTSTR lpszTitle
3414 * Variables :
3415 * Result :
3416 * Remark :
3417 * Status : REWRITTEN UNTESTED
3418 *
3419 * Author : Patrick Haller [Tue, 1998/02/12 23:28]
3420 *****************************************************************************/
3421
3422BOOL WIN32API SetConsoleTitleA(LPTSTR lpszTitle)
3423{
3424 if (ConsoleGlobals.pszWindowTitle != NULL) /* previously set name */
3425 free (ConsoleGlobals.pszWindowTitle); /* then free it */
3426
3427 ConsoleGlobals.pszWindowTitle = strdup(lpszTitle); /* copy the new name */
3428
3429 WinSetWindowText(ConsoleGlobals.hwndFrame, /* set new title text */
3430 ConsoleGlobals.pszWindowTitle);
3431
3432 return TRUE;
3433}
3434
3435
3436/*****************************************************************************
3437 * Name : BOOL WIN32API SetConsoleTitleW
3438 * Purpose : Set new title text for the console window
3439 * Parameters: LPTSTR lpszTitle
3440 * Variables :
3441 * Result :
3442 * Remark :
3443 * Status : REWRITTEN UNTESTED
3444 *
3445 * Author : Patrick Haller [Tue, 1998/02/12 23:28]
3446 *****************************************************************************/
3447
3448BOOL WIN32API SetConsoleTitleW(LPWSTR lpszTitle)
3449{
3450 int alen;
3451
3452 if (lpszTitle == NULL) /* check parameters */
3453 return FALSE;
3454
3455 if (ConsoleGlobals.pszWindowTitle != NULL) /* previously set name */
3456 free (ConsoleGlobals.pszWindowTitle); /* then free it */
3457
3458 alen = WideCharToMultiByte( GetConsoleCP(), 0, lpszTitle, -1, 0, 0, 0, 0 );
3459 /* create an ascii copy of the lpszTitle */
3460 ConsoleGlobals.pszWindowTitle = (PSZ)malloc( alen );
3461 WideCharToMultiByte( GetConsoleCP(), 0, lpszTitle, -1,
3462 ConsoleGlobals.pszWindowTitle, alen, 0, 0 );
3463
3464 WinSetWindowText(ConsoleGlobals.hwndFrame, /* set new title text */
3465 ConsoleGlobals.pszWindowTitle);
3466
3467 return TRUE;
3468}
3469
3470
3471/*****************************************************************************
3472 * Name :
3473 * Purpose :
3474 * Parameters:
3475 * Variables :
3476 * Result :
3477 * Remark :
3478 * Status :
3479 *
3480 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3481 *****************************************************************************/
3482
3483BOOL WIN32API SetConsoleWindowInfo(HANDLE hConsoleOutput,
3484 BOOL fAbsolute,
3485 PSMALL_RECT psrctWindowRect)
3486{
3487 BOOL fResult;
3488
3489 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3490 DRQ_SETCONSOLEWINDOWINFO,
3491 (ULONG)fAbsolute,
3492 (ULONG)psrctWindowRect,
3493 0,
3494 0);
3495
3496 return fResult;
3497}
3498
3499
3500/*****************************************************************************
3501 * Name :
3502 * Purpose :
3503 * Parameters:
3504 * Variables :
3505 * Result :
3506 * Remark :
3507 * Status :
3508 *
3509 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3510 *****************************************************************************/
3511
3512BOOL WIN32API WriteConsoleA(HANDLE hConsoleOutput,
3513 CONST VOID* lpvBuffer,
3514 DWORD cchToWrite,
3515 LPDWORD lpcchWritten,
3516 LPVOID lpvReserved)
3517{
3518 BOOL fResult;
3519
3520 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3521 DRQ_WRITECONSOLEA,
3522 (ULONG)lpvBuffer,
3523 (ULONG)cchToWrite,
3524 (ULONG)lpcchWritten,
3525 (ULONG)lpvReserved);
3526
3527 return fResult;
3528}
3529
3530
3531/*****************************************************************************
3532 * Name :
3533 * Purpose :
3534 * Parameters:
3535 * Variables :
3536 * Result :
3537 * Remark :
3538 * Status :
3539 *
3540 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3541 *****************************************************************************/
3542
3543BOOL WIN32API WriteConsoleW(HANDLE hConsoleOutput,
3544 CONST VOID* lpvBuffer,
3545 DWORD cchToWrite,
3546 LPDWORD lpcchWritten,
3547 LPVOID lpvReserved)
3548{
3549 BOOL fResult;
3550
3551 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3552 DRQ_WRITECONSOLEW,
3553 (ULONG)lpvBuffer,
3554 (ULONG)cchToWrite,
3555 (ULONG)lpcchWritten,
3556 (ULONG)lpvReserved);
3557
3558 return fResult;
3559}
3560
3561
3562/*****************************************************************************
3563 * Name :
3564 * Purpose :
3565 * Parameters:
3566 * Variables :
3567 * Result :
3568 * Remark :
3569 * Status :
3570 *
3571 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3572 *****************************************************************************/
3573
3574BOOL WIN32API WriteConsoleInputA(HANDLE hConsoleInput,
3575 PINPUT_RECORD pirBuffer,
3576 DWORD cInRecords,
3577 LPDWORD lpcWritten)
3578{
3579 BOOL fResult;
3580
3581 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3582 DRQ_WRITECONSOLEINPUTA,
3583 (ULONG)pirBuffer,
3584 (ULONG)cInRecords,
3585 (ULONG)lpcWritten,
3586 0);
3587
3588 return fResult;
3589}
3590
3591
3592/*****************************************************************************
3593 * Name :
3594 * Purpose :
3595 * Parameters:
3596 * Variables :
3597 * Result :
3598 * Remark :
3599 * Status :
3600 *
3601 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3602 *****************************************************************************/
3603
3604BOOL WIN32API WriteConsoleInputW(HANDLE hConsoleInput,
3605 PINPUT_RECORD pirBuffer,
3606 DWORD cInRecords,
3607 LPDWORD lpcWritten)
3608{
3609 BOOL fResult;
3610
3611 fResult = (BOOL)HMDeviceRequest(hConsoleInput,
3612 DRQ_WRITECONSOLEINPUTW,
3613 (ULONG)pirBuffer,
3614 (ULONG)cInRecords,
3615 (ULONG)lpcWritten,
3616 0);
3617
3618 return fResult;
3619}
3620
3621
3622/*****************************************************************************
3623 * Name :
3624 * Purpose :
3625 * Parameters:
3626 * Variables :
3627 * Result :
3628 * Remark :
3629 * Status :
3630 *
3631 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3632 *****************************************************************************/
3633
3634BOOL WIN32API WriteConsoleOutputA(HANDLE hConsoleOutput,
3635 PCHAR_INFO pchiSrcBuffer,
3636 COORD coordSrcBufferSize,
3637 COORD coordSrcBufferCoord,
3638 PSMALL_RECT psrctDestRect)
3639{
3640 BOOL fResult;
3641
3642 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3643 DRQ_WRITECONSOLEOUTPUTA,
3644 (ULONG)pchiSrcBuffer,
3645 COORD2ULONG(coordSrcBufferSize),
3646 COORD2ULONG(coordSrcBufferCoord),
3647 (ULONG)psrctDestRect);
3648
3649 return fResult;
3650}
3651
3652
3653/*****************************************************************************
3654 * Name :
3655 * Purpose :
3656 * Parameters:
3657 * Variables :
3658 * Result :
3659 * Remark :
3660 * Status :
3661 *
3662 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3663 *****************************************************************************/
3664
3665BOOL WIN32API WriteConsoleOutputW(HANDLE hConsoleOutput,
3666 PCHAR_INFO pchiSrcBuffer,
3667 COORD coordSrcBufferSize,
3668 COORD coordSrcBufferCoord,
3669 PSMALL_RECT psrctDestRect)
3670{
3671 BOOL fResult;
3672
3673 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3674 DRQ_WRITECONSOLEOUTPUTW,
3675 (ULONG)pchiSrcBuffer,
3676 COORD2ULONG(coordSrcBufferSize),
3677 COORD2ULONG(coordSrcBufferCoord),
3678 (ULONG)psrctDestRect);
3679
3680 return fResult;
3681}
3682
3683/*****************************************************************************
3684 * Name :
3685 * Purpose :
3686 * Parameters:
3687 * Variables :
3688 * Result :
3689 * Remark :
3690 * Status :
3691 *
3692 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3693 *****************************************************************************/
3694
3695BOOL WIN32API WriteConsoleOutputAttribute(HANDLE hConsoleOutput,
3696 LPWORD lpwAttribute,
3697 DWORD cWriteCells,
3698 COORD coordWriteCoord,
3699 LPDWORD lpcNumberWritten)
3700{
3701 BOOL fResult;
3702
3703 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3704 DRQ_WRITECONSOLEOUTPUTATTRIBUTE,
3705 (ULONG)lpwAttribute,
3706 (ULONG)cWriteCells,
3707 COORD2ULONG(coordWriteCoord),
3708 (ULONG)lpcNumberWritten);
3709
3710 return fResult;
3711}
3712
3713
3714/*****************************************************************************
3715 * Name :
3716 * Purpose :
3717 * Parameters:
3718 * Variables :
3719 * Result :
3720 * Remark :
3721 * Status :
3722 *
3723 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3724 *****************************************************************************/
3725
3726BOOL WIN32API WriteConsoleOutputCharacterA(HANDLE hConsoleOutput,
3727 LPTSTR lpWriteBuffer,
3728 DWORD cchWrite,
3729 COORD coordWriteCoord,
3730 LPDWORD lpcWritten)
3731{
3732 BOOL fResult;
3733
3734 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3735 DRQ_WRITECONSOLEOUTPUTCHARACTERA,
3736 (ULONG)lpWriteBuffer,
3737 (ULONG)cchWrite,
3738 COORD2ULONG(coordWriteCoord),
3739 (ULONG)lpcWritten);
3740
3741 return fResult;
3742}
3743
3744
3745/*****************************************************************************
3746 * Name :
3747 * Purpose :
3748 * Parameters:
3749 * Variables :
3750 * Result :
3751 * Remark :
3752 * Status :
3753 *
3754 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
3755 *****************************************************************************/
3756
3757BOOL WIN32API WriteConsoleOutputCharacterW(HANDLE hConsoleOutput,
3758 LPTSTR lpWriteBuffer,
3759 DWORD cchWrite,
3760 COORD coordWriteCoord,
3761 LPDWORD lpcWritten)
3762{
3763 BOOL fResult;
3764
3765 fResult = (BOOL)HMDeviceRequest(hConsoleOutput,
3766 DRQ_WRITECONSOLEOUTPUTCHARACTERW,
3767 (ULONG)lpWriteBuffer,
3768 (ULONG)cchWrite,
3769 COORD2ULONG(coordWriteCoord),
3770 (ULONG)lpcWritten);
3771
3772 return fResult;
3773}
Note: See TracBrowser for help on using the repository browser.