3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: subsys/csrss/win32csr/guiconsole.c
6 * PURPOSE: Implementation of gui-mode consoles
9 /* INCLUDES ******************************************************************/
16 /* Not defined in any header file */
17 extern VOID STDCALL
PrivateCsrssManualGuiCheck(LONG Check
);
19 /* GLOBALS *******************************************************************/
21 typedef struct GUI_CONSOLE_DATA_TAG
29 CRITICAL_SECTION Lock
;
33 } GUI_CONSOLE_DATA
, *PGUI_CONSOLE_DATA
;
38 #define PM_CREATE_CONSOLE (WM_APP + 1)
39 #define PM_DESTROY_CONSOLE (WM_APP + 2)
41 #define CURSOR_BLINK_TIME 500
43 static BOOL ConsInitialized
= FALSE
;
44 static HWND NotifyWnd
;
46 /* FUNCTIONS *****************************************************************/
49 GuiConsoleGetDataPointers(HWND hWnd
, PCSRSS_CONSOLE
*Console
, PGUI_CONSOLE_DATA
*GuiData
)
51 *Console
= (PCSRSS_CONSOLE
) GetWindowLongPtrW(hWnd
, GWL_USERDATA
);
52 *GuiData
= (NULL
== *Console
? NULL
: (*Console
)->PrivateData
);
56 GuiConsoleHandleNcCreate(HWND hWnd
, CREATESTRUCTW
*Create
)
59 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) Create
->lpCreateParams
;
60 PGUI_CONSOLE_DATA GuiData
;
65 GuiData
= HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
66 sizeof(GUI_CONSOLE_DATA
) +
67 (Console
->Size
.X
+ 1) * sizeof(WCHAR
));
70 DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n");
74 InitializeCriticalSection(&GuiData
->Lock
);
76 GuiData
->LineBuffer
= (PWCHAR
)(GuiData
+ 1);
78 GuiData
->Font
= CreateFontW(12, 0, 0, TA_BASELINE
, FW_NORMAL
,
79 FALSE
, FALSE
, FALSE
, OEM_CHARSET
,
80 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
81 NONANTIALIASED_QUALITY
, FIXED_PITCH
| FF_DONTCARE
,
82 L
"Bitstream Vera Sans Mono");
83 if (NULL
== GuiData
->Font
)
85 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
86 DeleteCriticalSection(&GuiData
->Lock
);
87 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
93 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
94 DeleteObject(GuiData
->Font
);
95 DeleteCriticalSection(&GuiData
->Lock
);
96 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
99 OldFont
= SelectObject(Dc
, GuiData
->Font
);
102 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
104 DeleteObject(GuiData
->Font
);
105 DeleteCriticalSection(&GuiData
->Lock
);
106 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
109 if (! GetTextMetricsW(Dc
, &Metrics
))
111 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
112 SelectObject(Dc
, OldFont
);
114 DeleteObject(GuiData
->Font
);
115 DeleteCriticalSection(&GuiData
->Lock
);
116 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
119 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
120 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
121 SelectObject(Dc
, OldFont
);
124 GuiData
->CursorBlinkOn
= TRUE
;
125 GuiData
->ForceCursorOff
= FALSE
;
127 GuiData
->Selection
.left
= -1;
129 Console
->PrivateData
= GuiData
;
130 SetWindowLongPtrW(hWnd
, GWL_USERDATA
, (DWORD_PTR
) Console
);
132 GetWindowRect(hWnd
, &Rect
);
133 Rect
.right
= Rect
.left
+ Console
->Size
.X
* GuiData
->CharWidth
+
134 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
135 Rect
.bottom
= Rect
.top
+ Console
->Size
.Y
* GuiData
->CharHeight
+
136 2 * GetSystemMetrics(SM_CYFIXEDFRAME
) + GetSystemMetrics(SM_CYCAPTION
);
137 MoveWindow(hWnd
, Rect
.left
, Rect
.top
, Rect
.right
- Rect
.left
,
138 Rect
.bottom
- Rect
.top
, FALSE
);
140 SetTimer(hWnd
, 1, CURSOR_BLINK_TIME
, NULL
);
142 return (BOOL
) DefWindowProcW(hWnd
, WM_NCCREATE
, 0, (LPARAM
) Create
);
145 static COLORREF FASTCALL
146 GuiConsoleRGBFromAttribute(BYTE Attribute
)
148 int Red
= (Attribute
& 0x04 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
149 int Green
= (Attribute
& 0x02 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
150 int Blue
= (Attribute
& 0x01 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
152 return RGB(Red
, Green
, Blue
);
156 GuiConsoleSetTextColors(HDC Dc
, BYTE Attribute
)
158 SetTextColor(Dc
, GuiConsoleRGBFromAttribute(Attribute
& 0x0f));
159 SetBkColor(Dc
, GuiConsoleRGBFromAttribute((Attribute
& 0xf0) >> 4));
163 GuiConsoleGetLogicalCursorPos(PCSRSS_SCREEN_BUFFER Buff
, ULONG
*CursorX
, ULONG
*CursorY
)
165 *CursorX
= Buff
->CurrentX
;
166 if (Buff
->CurrentY
< Buff
->ShowY
)
168 *CursorY
= Buff
->MaxY
- Buff
->ShowY
+ Buff
->CurrentY
;
172 *CursorY
= Buff
->CurrentY
- Buff
->ShowY
;
178 GuiConsoleUpdateSelection(HWND hWnd
, PRECT rc
, PGUI_CONSOLE_DATA GuiData
)
180 RECT oldRect
= GuiData
->Selection
;
184 RECT changeRect
= *rc
;
186 GuiData
->Selection
= *rc
;
188 changeRect
.left
*= GuiData
->CharWidth
;
189 changeRect
.top
*= GuiData
->CharHeight
;
190 changeRect
.right
*= GuiData
->CharWidth
;
191 changeRect
.bottom
*= GuiData
->CharHeight
;
193 if(rc
->left
!= oldRect
.left
||
194 rc
->top
!= oldRect
.top
||
195 rc
->right
!= oldRect
.right
||
196 rc
->bottom
!= oldRect
.bottom
)
198 if(oldRect
.left
!= -1)
202 oldRect
.left
*= GuiData
->CharWidth
;
203 oldRect
.top
*= GuiData
->CharHeight
;
204 oldRect
.right
*= GuiData
->CharWidth
;
205 oldRect
.bottom
*= GuiData
->CharHeight
;
207 /* calculate the region that needs to be updated */
208 if((rgn1
= CreateRectRgnIndirect(&oldRect
)))
210 if((rgn2
= CreateRectRgnIndirect(&changeRect
)))
212 if(CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
214 InvalidateRgn(hWnd
, rgn1
, FALSE
);
224 InvalidateRect(hWnd
, &changeRect
, FALSE
);
228 else if(oldRect
.left
!= -1)
230 /* clear the selection */
231 GuiData
->Selection
.left
= -1;
232 oldRect
.left
*= GuiData
->CharWidth
;
233 oldRect
.top
*= GuiData
->CharHeight
;
234 oldRect
.right
*= GuiData
->CharWidth
;
235 oldRect
.bottom
*= GuiData
->CharHeight
;
236 InvalidateRect(hWnd
, &oldRect
, FALSE
);
242 GuiConsolePaint(PCSRSS_CONSOLE Console
,
243 PGUI_CONSOLE_DATA GuiData
,
247 PCSRSS_SCREEN_BUFFER Buff
;
248 ULONG TopLine
, BottomLine
, LeftChar
, RightChar
;
249 ULONG Line
, Char
, Start
;
252 BYTE LastAttribute
, Attribute
;
253 ULONG CursorX
, CursorY
, CursorHeight
;
254 HBRUSH CursorBrush
, OldBrush
;
257 Buff
= Console
->ActiveBuffer
;
259 TopLine
= rc
->top
/ GuiData
->CharHeight
;
260 BottomLine
= (rc
->bottom
+ (GuiData
->CharHeight
- 1)) / GuiData
->CharHeight
- 1;
261 LeftChar
= rc
->left
/ GuiData
->CharWidth
;
262 RightChar
= (rc
->right
+ (GuiData
->CharWidth
- 1)) / GuiData
->CharWidth
- 1;
263 LastAttribute
= Buff
->Buffer
[(TopLine
* Buff
->MaxX
+ LeftChar
) * 2 + 1];
265 GuiConsoleSetTextColors(hDC
,
268 EnterCriticalSection(&Buff
->Header
.Lock
);
270 OldFont
= SelectObject(hDC
,
273 for (Line
= TopLine
; Line
<= BottomLine
; Line
++)
275 if (Line
+ Buff
->ShowY
< Buff
->MaxY
)
277 From
= Buff
->Buffer
+ ((Line
+ Buff
->ShowY
) * Buff
->MaxX
+ LeftChar
) * 2;
281 From
= Buff
->Buffer
+
282 ((Line
- (Buff
->MaxY
- Buff
->ShowY
)) * Buff
->MaxX
+ LeftChar
) * 2;
285 To
= GuiData
->LineBuffer
;
287 for (Char
= LeftChar
; Char
<= RightChar
; Char
++)
289 if (*(From
+ 1) != LastAttribute
)
292 Start
* GuiData
->CharWidth
,
293 Line
* GuiData
->CharHeight
,
297 To
= GuiData
->LineBuffer
;
298 Attribute
= *(From
+ 1);
299 if (Attribute
!= LastAttribute
)
301 GuiConsoleSetTextColors(hDC
,
303 LastAttribute
= Attribute
;
307 MultiByteToWideChar(Console
->OutputCodePage
,
318 Start
* GuiData
->CharWidth
,
319 Line
* GuiData
->CharHeight
,
321 RightChar
- Start
+ 1);
324 if (Buff
->CursorInfo
.bVisible
&& GuiData
->CursorBlinkOn
&&
325 !GuiData
->ForceCursorOff
)
327 GuiConsoleGetLogicalCursorPos(Buff
,
330 if (LeftChar
<= CursorX
&& CursorX
<= RightChar
&&
331 TopLine
<= CursorY
&& CursorY
<= BottomLine
)
333 CursorHeight
= (GuiData
->CharHeight
* Buff
->CursorInfo
.dwSize
) / 100;
334 if (CursorHeight
< 1)
338 From
= Buff
->Buffer
+ (Buff
->CurrentY
* Buff
->MaxX
+ Buff
->CurrentX
) * 2 + 1;
339 CursorBrush
= CreateSolidBrush(GuiConsoleRGBFromAttribute(*From
));
340 OldBrush
= SelectObject(hDC
,
343 CursorX
* GuiData
->CharWidth
,
344 CursorY
* GuiData
->CharHeight
+ (GuiData
->CharHeight
- CursorHeight
),
350 DeleteObject(CursorBrush
);
354 LeaveCriticalSection(&Buff
->Header
.Lock
);
361 GuiConsoleHandlePaint(HWND hWnd
, HDC hDCPaint
)
366 PCSRSS_CONSOLE Console
;
367 PGUI_CONSOLE_DATA GuiData
;
369 if (GetUpdateRect(hWnd
,
373 hDC
= (hDCPaint
!= NULL
? hDCPaint
: BeginPaint(hWnd
,
377 GuiConsoleGetDataPointers(hWnd
,
380 if (Console
!= NULL
&& GuiData
!= NULL
&&
381 Console
->ActiveBuffer
!= NULL
)
383 EnterCriticalSection(&GuiData
->Lock
);
385 GuiConsolePaint(Console
,
390 if (GuiData
->Selection
.left
!= -1)
392 RECT rc
= GuiData
->Selection
;
394 rc
.left
*= GuiData
->CharWidth
;
395 rc
.top
*= GuiData
->CharHeight
;
396 rc
.right
*= GuiData
->CharWidth
;
397 rc
.bottom
*= GuiData
->CharHeight
;
399 /* invert the selection */
400 if (IntersectRect(&rc
,
413 LeaveCriticalSection(&GuiData
->Lock
);
416 if (hDCPaint
== NULL
)
426 GuiConsoleHandleKey(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
428 PCSRSS_CONSOLE Console
;
429 PGUI_CONSOLE_DATA GuiData
;
432 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
434 Message
.message
= msg
;
435 Message
.wParam
= wParam
;
436 Message
.lParam
= lParam
;
438 if(msg
== WM_CHAR
|| msg
== WM_SYSKEYDOWN
)
440 /* clear the selection */
441 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
444 ConioProcessKey(&Message
, Console
, FALSE
);
448 GuiIntDrawRegion(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, RECT
*Region
)
452 RegionRect
.left
= Region
->left
* GuiData
->CharWidth
;
453 RegionRect
.top
= Region
->top
* GuiData
->CharHeight
;
454 RegionRect
.right
= (Region
->right
+ 1) * GuiData
->CharWidth
;
455 RegionRect
.bottom
= (Region
->bottom
+ 1) * GuiData
->CharHeight
;
457 InvalidateRect(Wnd
, &RegionRect
, FALSE
);
461 GuiDrawRegion(PCSRSS_CONSOLE Console
, RECT
*Region
)
463 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
465 if (NULL
!= Console
->hWindow
&& NULL
!= GuiData
)
467 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
472 GuiInvalidateCell(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, UINT x
, UINT y
)
481 GuiIntDrawRegion(GuiData
, Wnd
, &CellRect
);
485 GuiWriteStream(PCSRSS_CONSOLE Console
, RECT
*Region
, LONG CursorStartX
, LONG CursorStartY
,
486 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
)
488 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
489 PCSRSS_SCREEN_BUFFER Buff
= Console
->ActiveBuffer
;
490 LONG CursorEndX
, CursorEndY
;
491 RECT Source
, ScrollRect
;
493 if (NULL
== Console
->hWindow
|| NULL
== GuiData
)
498 if (0 != ScrolledLines
)
501 Source
.top
= ScrolledLines
;
502 Source
.right
= Console
->Size
.X
- 1;
503 Source
.bottom
= ScrolledLines
+ Region
->top
- 1;
506 ScrollRect
.right
= Console
->Size
.X
* GuiData
->CharWidth
;
507 ScrollRect
.bottom
= Region
->top
* GuiData
->CharHeight
;
509 InvalidateRect(Console
->hWindow
, &ScrollRect
, FALSE
);
512 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
514 if (CursorStartX
< Region
->left
|| Region
->right
< CursorStartX
515 || CursorStartY
< Region
->top
|| Region
->bottom
< CursorStartY
)
517 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorStartX
, CursorStartY
);
520 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
521 &CursorEndX
, &CursorEndY
);
522 if ((CursorEndX
< Region
->left
|| Region
->right
< CursorEndX
523 || CursorEndY
< Region
->top
|| Region
->bottom
< CursorEndY
)
524 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
526 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorEndX
, CursorEndY
);
531 GuiSetCursorInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
)
535 if (Console
->ActiveBuffer
== Buff
)
537 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
538 &UpdateRect
.left
, &UpdateRect
.top
);
539 UpdateRect
.right
= UpdateRect
.left
;
540 UpdateRect
.bottom
= UpdateRect
.top
;
541 ConioDrawRegion(Console
, &UpdateRect
);
548 GuiSetScreenInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
, UINT OldCursorX
, UINT OldCursorY
)
552 if (Console
->ActiveBuffer
== Buff
)
554 /* Redraw char at old position (removes cursor) */
555 UpdateRect
.left
= OldCursorX
;
556 UpdateRect
.top
= OldCursorY
;
557 UpdateRect
.right
= OldCursorX
;
558 UpdateRect
.bottom
= OldCursorY
;
559 ConioDrawRegion(Console
, &UpdateRect
);
560 /* Redraw char at new position (shows cursor) */
561 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
562 &(UpdateRect
.left
), &(UpdateRect
.top
));
563 UpdateRect
.right
= UpdateRect
.left
;
564 UpdateRect
.bottom
= UpdateRect
.top
;
565 ConioDrawRegion(Console
, &UpdateRect
);
572 GuiConsoleHandleTimer(HWND hWnd
)
574 PCSRSS_CONSOLE Console
;
575 PGUI_CONSOLE_DATA GuiData
;
577 ULONG CursorX
, CursorY
;
579 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
580 GuiData
->CursorBlinkOn
= ! GuiData
->CursorBlinkOn
;
582 GuiConsoleGetLogicalCursorPos(Console
->ActiveBuffer
, &CursorX
, &CursorY
);
583 CursorRect
.left
= CursorX
;
584 CursorRect
.top
= CursorY
;
585 CursorRect
.right
= CursorX
;
586 CursorRect
.bottom
= CursorY
;
587 GuiDrawRegion(Console
, &CursorRect
);
591 GuiConsoleHandleClose(HWND hWnd
)
593 PCSRSS_CONSOLE Console
;
594 PGUI_CONSOLE_DATA GuiData
;
595 PLIST_ENTRY current_entry
;
596 PCSRSS_PROCESS_DATA current
;
598 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
600 EnterCriticalSection(&Console
->Header
.Lock
);
602 current_entry
= Console
->ProcessList
.Flink
;
603 while (current_entry
!= &Console
->ProcessList
)
605 current
= CONTAINING_RECORD(current_entry
, CSRSS_PROCESS_DATA
, ProcessEntry
);
606 current_entry
= current_entry
->Flink
;
608 ConioConsoleCtrlEvent(CTRL_CLOSE_EVENT
, current
);
611 LeaveCriticalSection(&Console
->Header
.Lock
);
615 GuiConsoleHandleNcDestroy(HWND hWnd
)
617 PCSRSS_CONSOLE Console
;
618 PGUI_CONSOLE_DATA GuiData
;
620 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
622 Console
->PrivateData
= NULL
;
623 DeleteCriticalSection(&GuiData
->Lock
);
624 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
628 GuiConsoleLeftMouseDown(HWND hWnd
, LPARAM lParam
)
630 PCSRSS_CONSOLE Console
;
631 PGUI_CONSOLE_DATA GuiData
;
635 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
636 if (Console
== NULL
|| GuiData
== NULL
) return;
638 pt
= MAKEPOINTS(lParam
);
640 rc
.left
= pt
.x
/ GuiData
->CharWidth
;
641 rc
.top
= pt
.y
/ GuiData
->CharHeight
;
642 rc
.right
= rc
.left
+ 1;
643 rc
.bottom
= rc
.top
+ 1;
645 GuiData
->SelectionStart
.x
= rc
.left
;
646 GuiData
->SelectionStart
.y
= rc
.top
;
650 GuiData
->MouseDown
= TRUE
;
652 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
656 GuiConsoleLeftMouseUp(HWND hWnd
, LPARAM lParam
)
658 PCSRSS_CONSOLE Console
;
659 PGUI_CONSOLE_DATA GuiData
;
663 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
664 if (Console
== NULL
|| GuiData
== NULL
) return;
665 if (GuiData
->Selection
.left
== -1 || !GuiData
->MouseDown
) return;
667 pt
= MAKEPOINTS(lParam
);
669 rc
.left
= GuiData
->SelectionStart
.x
;
670 rc
.top
= GuiData
->SelectionStart
.y
;
671 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
672 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
674 /* exchange left/top with right/bottom if required */
675 if(rc
.left
>= rc
.right
)
679 rc
.left
= max(rc
.right
- 1, 0);
682 if(rc
.top
>= rc
.bottom
)
686 rc
.top
= max(rc
.bottom
- 1, 0);
690 GuiData
->MouseDown
= FALSE
;
692 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
698 GuiConsoleMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
700 PCSRSS_CONSOLE Console
;
701 PGUI_CONSOLE_DATA GuiData
;
705 if (!(wParam
& MK_LBUTTON
)) return;
707 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
708 if (Console
== NULL
|| GuiData
== NULL
|| !GuiData
->MouseDown
) return;
710 pt
= MAKEPOINTS(lParam
);
712 rc
.left
= GuiData
->SelectionStart
.x
;
713 rc
.top
= GuiData
->SelectionStart
.y
;
714 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
715 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
717 /* exchange left/top with right/bottom if required */
718 if(rc
.left
>= rc
.right
)
722 rc
.left
= max(rc
.right
- 1, 0);
725 if(rc
.top
>= rc
.bottom
)
729 rc
.top
= max(rc
.bottom
- 1, 0);
733 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
737 GuiConsoleRightMouseDown(HWND hWnd
)
739 PCSRSS_CONSOLE Console
;
740 PGUI_CONSOLE_DATA GuiData
;
742 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
743 if (Console
== NULL
|| GuiData
== NULL
) return;
745 if (GuiData
->Selection
.left
== -1)
747 /* FIXME - paste text from clipboard */
751 /* FIXME - copy selection to clipboard */
753 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
758 static LRESULT CALLBACK
759 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
766 Result
= (LRESULT
) GuiConsoleHandleNcCreate(hWnd
, (CREATESTRUCTW
*) lParam
);
769 GuiConsoleHandlePaint(hWnd
, (HDC
)wParam
);
776 GuiConsoleHandleKey(hWnd
, msg
, wParam
, lParam
);
779 GuiConsoleHandleTimer(hWnd
);
782 GuiConsoleHandleClose(hWnd
);
785 GuiConsoleHandleNcDestroy(hWnd
);
788 GuiConsoleLeftMouseDown(hWnd
, lParam
);
791 GuiConsoleLeftMouseUp(hWnd
, lParam
);
794 GuiConsoleRightMouseDown(hWnd
);
797 GuiConsoleMouseMove(hWnd
, wParam
, lParam
);
800 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
807 static LRESULT CALLBACK
808 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
813 PWCHAR Buffer
, Title
;
814 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) lParam
;
819 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
821 case PM_CREATE_CONSOLE
:
822 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
823 Console
->Title
.Length
+ sizeof(WCHAR
));
826 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
827 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
834 NewWindow
= CreateWindowW(L
"ConsoleWindowClass",
836 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
843 (HINSTANCE
) GetModuleHandleW(NULL
),
847 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
849 Console
->hWindow
= NewWindow
;
850 if (NULL
!= NewWindow
)
852 SetWindowLongW(hWnd
, GWL_USERDATA
, GetWindowLongW(hWnd
, GWL_USERDATA
) + 1);
853 ShowWindow(NewWindow
, SW_SHOW
);
855 return (LRESULT
) NewWindow
;
856 case PM_DESTROY_CONSOLE
:
857 /* Window creation is done using a PostMessage(), so it's possible that the
858 * window that we want to destroy doesn't exist yet. So first empty the message
860 while(PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
))
862 TranslateMessage(&Msg
);
863 DispatchMessageW(&Msg
);
865 DestroyWindow(Console
->hWindow
);
866 Console
->hWindow
= NULL
;
867 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
869 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
870 if (0 == WindowCount
)
874 PrivateCsrssManualGuiCheck(-1);
879 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
884 GuiConsoleGuiThread(PVOID Data
)
887 PHANDLE GraphicsStartupEvent
= (PHANDLE
) Data
;
889 NotifyWnd
= CreateWindowW(L
"Win32CsrCreateNotify",
898 (HINSTANCE
) GetModuleHandleW(NULL
),
900 if (NULL
== NotifyWnd
)
902 PrivateCsrssManualGuiCheck(-1);
903 SetEvent(*GraphicsStartupEvent
);
907 SetEvent(*GraphicsStartupEvent
);
909 while(GetMessageW(&msg
, NULL
, 0, 0))
911 TranslateMessage(&msg
);
912 DispatchMessageW(&msg
);
923 if (NULL
== NotifyWnd
)
925 PrivateCsrssManualGuiCheck(+1);
928 wc
.cbSize
= sizeof(WNDCLASSEXW
);
929 wc
.lpszClassName
= L
"Win32CsrCreateNotify";
930 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
932 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
935 wc
.hbrBackground
= NULL
;
936 wc
.lpszMenuName
= NULL
;
940 if (RegisterClassExW(&wc
) == 0)
942 DPRINT1("Failed to register notify wndproc\n");
946 wc
.cbSize
= sizeof(WNDCLASSEXW
);
947 wc
.lpszClassName
= L
"ConsoleWindowClass";
948 wc
.lpfnWndProc
= GuiConsoleWndProc
;
950 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
951 wc
.hIcon
= LoadIconW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1));
952 wc
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_ARROW
));
953 wc
.hbrBackground
= NULL
;
954 wc
.lpszMenuName
= NULL
;
957 wc
.hIconSm
= LoadImageW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1), IMAGE_ICON
,
958 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
960 if (RegisterClassExW(&wc
) == 0)
962 DPRINT1("Failed to register console wndproc\n");
970 GuiInitScreenBuffer(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buffer
)
972 Buffer
->DefaultAttrib
= 0x0f;
976 GuiChangeTitle(PCSRSS_CONSOLE Console
)
978 PWCHAR Buffer
, Title
;
980 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
981 Console
->Title
.Length
+ sizeof(WCHAR
));
984 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
985 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
992 SendMessageW(Console
->hWindow
, WM_SETTEXT
, 0, (LPARAM
) Title
);
995 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
1002 GuiChangeIcon(PCSRSS_CONSOLE Console
)
1004 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)Console
->hWindowIcon
);
1005 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)Console
->hWindowIcon
);
1011 GuiCleanupConsole(PCSRSS_CONSOLE Console
)
1013 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
) Console
);
1016 static CSRSS_CONSOLE_VTBL GuiVtbl
=
1018 GuiInitScreenBuffer
,
1029 GuiInitConsole(PCSRSS_CONSOLE Console
)
1031 HANDLE GraphicsStartupEvent
;
1032 HANDLE ThreadHandle
;
1034 if (! ConsInitialized
)
1036 ConsInitialized
= TRUE
;
1039 ConsInitialized
= FALSE
;
1040 return STATUS_UNSUCCESSFUL
;
1044 Console
->Vtbl
= &GuiVtbl
;
1045 Console
->Size
.X
= 80;
1046 Console
->Size
.Y
= 25;
1047 if (NULL
== NotifyWnd
)
1049 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1050 if (NULL
== GraphicsStartupEvent
)
1052 return STATUS_UNSUCCESSFUL
;
1055 ThreadHandle
= CreateThread(NULL
,
1057 GuiConsoleGuiThread
,
1058 (PVOID
) &GraphicsStartupEvent
,
1061 if (NULL
== ThreadHandle
)
1063 NtClose(GraphicsStartupEvent
);
1064 DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n");
1065 return STATUS_UNSUCCESSFUL
;
1067 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
1068 CloseHandle(ThreadHandle
);
1070 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
1071 CloseHandle(GraphicsStartupEvent
);
1073 if (NULL
== NotifyWnd
)
1075 DPRINT1("Win32Csr: Failed to create notification window.\n");
1076 return STATUS_UNSUCCESSFUL
;
1080 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, 0, (LPARAM
) Console
);
1082 return STATUS_SUCCESS
;