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 HMODULE ConsoleLibrary
;
37 WCHAR FontName
[LF_FACESIZE
];
44 DWORD NumberOfHistoryBuffers
;
45 DWORD HistoryBufferSize
;
47 DWORD ScreenBufferSize
;
50 COLORREF ScreenBackground
;
51 COLORREF PopupBackground
;
54 WCHAR szProcessName
[MAX_PATH
];
55 } GUI_CONSOLE_DATA
, *PGUI_CONSOLE_DATA
;
60 #define PM_CREATE_CONSOLE (WM_APP + 1)
61 #define PM_DESTROY_CONSOLE (WM_APP + 2)
63 #define CURSOR_BLINK_TIME 500
64 #define DEFAULT_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
66 static BOOL ConsInitialized
= FALSE
;
67 static HWND NotifyWnd
;
69 typedef struct _GUICONSOLE_MENUITEM
72 const struct _GUICONSOLE_MENUITEM
*SubMenu
;
74 } GUICONSOLE_MENUITEM
, *PGUICONSOLE_MENUITEM
;
76 static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems
[] =
78 { IDS_MARK
, NULL
, ID_SYSTEM_EDIT_MARK
},
79 { IDS_COPY
, NULL
, ID_SYSTEM_EDIT_COPY
},
80 { IDS_PASTE
, NULL
, ID_SYSTEM_EDIT_PASTE
},
81 { IDS_SELECTALL
, NULL
, ID_SYSTEM_EDIT_SELECTALL
},
82 { IDS_SCROLL
, NULL
, ID_SYSTEM_EDIT_SCROLL
},
83 { IDS_FIND
, NULL
, ID_SYSTEM_EDIT_FIND
},
85 { 0, NULL
, 0 } /* End of list */
88 static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems
[] =
90 { (UINT
)-1, NULL
, 0 }, /* Separator */
91 { IDS_EDIT
, GuiConsoleEditMenuItems
, 0 },
92 { IDS_DEFAULTS
, NULL
, ID_SYSTEM_DEFAULTS
},
93 { IDS_PROPERTIES
, NULL
, ID_SYSTEM_PROPERTIES
},
95 { 0, NULL
, 0 } /* End of list */
98 static const COLORREF s_Colors
[] =
118 /* FUNCTIONS *****************************************************************/
121 GuiConsoleAppendMenuItems(HMENU hMenu
,
122 const GUICONSOLE_MENUITEM
*Items
)
125 WCHAR szMenuString
[255];
128 for (i
= 0; Items
[i
].uID
!= 0; i
++)
130 if (Items
[i
].uID
!= (UINT
)-1)
132 if (LoadStringW(Win32CsrDllHandle
,
135 sizeof(szMenuString
) / sizeof(szMenuString
[0])) > 0)
137 if (Items
[i
].SubMenu
!= NULL
)
139 hSubMenu
= CreatePopupMenu();
140 if (hSubMenu
!= NULL
)
142 GuiConsoleAppendMenuItems(hSubMenu
,
145 if (!AppendMenuW(hMenu
,
146 MF_STRING
| MF_POPUP
,
150 DestroyMenu(hSubMenu
);
174 GuiConsoleCreateSysMenu(PCSRSS_CONSOLE Console
)
178 hMenu
= GetSystemMenu(Console
->hWindow
,
182 GuiConsoleAppendMenuItems(hMenu
,
183 GuiConsoleMainMenuItems
);
188 GuiConsoleGetDataPointers(HWND hWnd
, PCSRSS_CONSOLE
*Console
, PGUI_CONSOLE_DATA
*GuiData
)
190 *Console
= (PCSRSS_CONSOLE
) GetWindowLongPtrW(hWnd
, GWL_USERDATA
);
191 *GuiData
= (NULL
== *Console
? NULL
: (*Console
)->PrivateData
);
195 GuiConsoleOpenUserRegistryPathPerProcessId(DWORD ProcessId
, PHANDLE hProcHandle
, PHKEY hResult
, REGSAM samDesired
)
197 HANDLE hProcessToken
= NULL
;
202 UNICODE_STRING SidName
;
206 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
| READ_CONTROL
, FALSE
, ProcessId
);
209 DPRINT("Error: OpenProcess failed(0x%x)\n", GetLastError());
213 if (!OpenProcessToken(hProcess
, TOKEN_QUERY
, &hProcessToken
))
215 DPRINT("Error: OpenProcessToken failed(0x%x)\n", GetLastError());
216 CloseHandle(hProcess
);
220 if (!GetTokenInformation(hProcessToken
, TokenUser
, (PVOID
)Buffer
, sizeof(Buffer
), &Length
))
222 DPRINT("Error: GetTokenInformation failed(0x%x)\n",GetLastError());
223 CloseHandle(hProcess
);
224 CloseHandle(hProcessToken
);
228 TokUser
= ((PTOKEN_USER
)Buffer
)->User
.Sid
;
229 if (!NT_SUCCESS(RtlConvertSidToUnicodeString(&SidName
, TokUser
, TRUE
)))
231 DPRINT("Error: RtlConvertSidToUnicodeString failed(0x%x)\n", GetLastError());
235 res
= RegOpenKeyExW(HKEY_USERS
, SidName
.Buffer
, 0, samDesired
, hResult
);
236 RtlFreeUnicodeString(&SidName
);
238 CloseHandle(hProcessToken
);
240 *hProcHandle
= hProcess
;
242 CloseHandle(hProcess
);
244 if (res
!= ERROR_SUCCESS
)
251 GuiConsoleOpenUserSettings(PGUI_CONSOLE_DATA GuiData
, DWORD ProcessId
, PHKEY hSubKey
, REGSAM samDesired
, BOOL bCreate
)
253 WCHAR szProcessName
[MAX_PATH
];
254 WCHAR szBuffer
[MAX_PATH
];
255 UINT fLength
, wLength
;
256 DWORD dwBitmask
, dwLength
;
257 WCHAR CurDrive
[] = { 'A',':', 0 };
263 * console properties are stored under
266 * There are 3 ways to store console properties
268 * 1. use console title as subkey name
271 * 2. use application name as subkey name
273 * 3. use unexpanded path to console application.
274 * i.e. %SystemRoot%_system32_cmd.exe
277 DPRINT("GuiConsoleOpenUserSettings entered\n");
279 if (!GuiConsoleOpenUserRegistryPathPerProcessId(ProcessId
, &hProcess
, &hKey
, samDesired
))
281 DPRINT("GuiConsoleOpenUserRegistryPathPerProcessId failed\n");
285 /* FIXME we do not getting the process name so no menu will be loading, why ?*/
286 fLength
= GetProcessImageFileNameW(hProcess
, szProcessName
, sizeof(GuiData
->szProcessName
) / sizeof(WCHAR
));
287 CloseHandle(hProcess
);
289 //DPRINT1("szProcessName3 : %S\n",szProcessName);
293 DPRINT("GetProcessImageFileNameW failed(0x%x)ProcessId %d\n", GetLastError(),hProcess
);
297 * try the process name as path
300 ptr
= wcsrchr(szProcessName
, L
'\\');
301 wcscpy(GuiData
->szProcessName
, ptr
);
303 swprintf(szBuffer
, L
"Console%s",ptr
);
304 DPRINT("#1 Path : %S\n", szBuffer
);
308 if (RegCreateKeyW(hKey
, szBuffer
, hSubKey
) == ERROR_SUCCESS
)
317 if (RegOpenKeyExW(hKey
, szBuffer
, 0, samDesired
, hSubKey
) == ERROR_SUCCESS
)
324 * try the "Shortcut to processname" as path
325 * FIXME: detect wheter the process was started as a shortcut
328 swprintf(szBuffer
, L
"Console\\Shortcut to %S", ptr
);
329 DPRINT("#2 Path : %S\n", szBuffer
);
330 if (RegOpenKeyExW(hKey
, szBuffer
, 0, samDesired
, hSubKey
) == ERROR_SUCCESS
)
332 swprintf(GuiData
->szProcessName
, L
"Shortcut to %S", ptr
);
338 * if the path contains \\Device\\HarddiskVolume1\... remove it
341 if (szProcessName
[0] == L
'\\')
343 dwBitmask
= GetLogicalDrives();
348 dwLength
= QueryDosDeviceW(CurDrive
, szBuffer
, MAX_PATH
);
351 if (!memcmp(szBuffer
, szProcessName
, (dwLength
-2)*sizeof(WCHAR
)))
353 wcscpy(szProcessName
, CurDrive
);
354 RtlMoveMemory(&szProcessName
[2], &szProcessName
[dwLength
-1], fLength
- dwLength
-1);
359 dwBitmask
= (dwBitmask
>> 1);
365 * last attempt: check whether the file is under %SystemRoot%
366 * and use path like Console\%SystemRoot%_dir_dir2_file.exe
369 wLength
= GetWindowsDirectoryW(szBuffer
, MAX_PATH
);
372 if (!wcsncmp(szProcessName
, szBuffer
, wLength
))
374 /* replace slashes by underscores */
375 while((ptr
= wcschr(szProcessName
, L
'\\')))
378 swprintf(szBuffer
, L
"Console\\\%SystemRoot\%%S", &szProcessName
[wLength
]);
379 DPRINT("#3 Path : %S\n", szBuffer
);
380 if (RegOpenKeyExW(hKey
, szBuffer
, 0, samDesired
, hSubKey
) == ERROR_SUCCESS
)
382 swprintf(GuiData
->szProcessName
, L
"\%SystemRoot\%%S", &szProcessName
[wLength
]);
393 GuiConsoleWriteUserSettings(PCSRSS_CONSOLE Console
, PGUI_CONSOLE_DATA GuiData
)
396 PCSRSS_PROCESS_DATA ProcessData
;
398 if (Console
->ProcessList
.Flink
== &Console
->ProcessList
)
400 DPRINT("GuiConsoleWriteUserSettings: No Process!!!\n");
403 ProcessData
= CONTAINING_RECORD(Console
->ProcessList
.Flink
, CSRSS_PROCESS_DATA
, ProcessEntry
);
404 if (!GuiConsoleOpenUserSettings(GuiData
, PtrToUlong(ProcessData
->ProcessId
), &hKey
, KEY_READ
| KEY_WRITE
, TRUE
))
409 if (Console
->ActiveBuffer
->CursorInfo
.dwSize
<= 1)
411 RegDeleteKeyW(hKey
, L
"CursorSize");
415 RegSetValueExW(hKey
, L
"CursorSize", 0, REG_DWORD
, (const BYTE
*)&Console
->ActiveBuffer
->CursorInfo
.dwSize
, sizeof(DWORD
));
418 if (GuiData
->NumberOfHistoryBuffers
== 5)
420 RegDeleteKeyW(hKey
, L
"NumberOfHistoryBuffers");
424 RegSetValueExW(hKey
, L
"NumberOfHistoryBuffers", 0, REG_DWORD
, (const BYTE
*)&GuiData
->NumberOfHistoryBuffers
, sizeof(DWORD
));
427 if (GuiData
->HistoryBufferSize
== 50)
429 RegDeleteKeyW(hKey
, L
"HistoryBufferSize");
433 RegSetValueExW(hKey
, L
"HistoryBufferSize", 0, REG_DWORD
, (const BYTE
*)&GuiData
->HistoryBufferSize
, sizeof(DWORD
));
436 if (GuiData
->FullScreen
== FALSE
)
438 RegDeleteKeyW(hKey
, L
"FullScreen");
442 RegSetValueExW(hKey
, L
"FullScreen", 0, REG_DWORD
, (const BYTE
*)&GuiData
->FullScreen
, sizeof(DWORD
));
445 if ( GuiData
->QuickEdit
== FALSE
)
447 RegDeleteKeyW(hKey
, L
"QuickEdit");
451 RegSetValueExW(hKey
, L
"QuickEdit", 0, REG_DWORD
, (const BYTE
*)&GuiData
->QuickEdit
, sizeof(DWORD
));
454 if (GuiData
->InsertMode
== TRUE
)
456 RegDeleteKeyW(hKey
, L
"InsertMode");
460 RegSetValueExW(hKey
, L
"InsertMode", 0, REG_DWORD
, (const BYTE
*)&GuiData
->InsertMode
, sizeof(DWORD
));
463 if (GuiData
->HistoryNoDup
== FALSE
)
465 RegDeleteKeyW(hKey
, L
"HistoryNoDup");
469 RegSetValueExW(hKey
, L
"HistoryNoDup", 0, REG_DWORD
, (const BYTE
*)&GuiData
->HistoryNoDup
, sizeof(DWORD
));
472 if (GuiData
->ScreenText
== RGB(192, 192, 192))
475 * MS uses console attributes instead of real color
477 RegDeleteKeyW(hKey
, L
"ScreenText");
481 RegSetValueExW(hKey
, L
"ScreenText", 0, REG_DWORD
, (const BYTE
*)&GuiData
->ScreenText
, sizeof(COLORREF
));
484 if (GuiData
->ScreenBackground
== RGB(0, 0, 0))
486 RegDeleteKeyW(hKey
, L
"ScreenBackground");
490 RegSetValueExW(hKey
, L
"ScreenBackground", 0, REG_DWORD
, (const BYTE
*)&GuiData
->ScreenBackground
, sizeof(COLORREF
));
497 GuiConsoleReadUserSettings(HKEY hKey
, PCSRSS_CONSOLE Console
, PGUI_CONSOLE_DATA GuiData
, PCSRSS_SCREEN_BUFFER Buffer
)
499 DWORD dwNumSubKeys
= 0;
504 WCHAR szValueName
[MAX_PATH
];
505 WCHAR szValue
[MAX_PATH
];
508 if (RegQueryInfoKey(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &dwNumSubKeys
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
510 DPRINT("GuiConsoleReadUserSettings: RegQueryInfoKey failed\n");
514 DPRINT("GuiConsoleReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys
);
516 for (dwIndex
= 0; dwIndex
< dwNumSubKeys
; dwIndex
++)
518 dwValue
= sizeof(Value
);
519 dwValueName
= MAX_PATH
;
521 if (RegEnumValueW(hKey
, dwIndex
, szValueName
, &dwValueName
, NULL
, &dwType
, (BYTE
*)&Value
, &dwValue
) != ERROR_SUCCESS
)
523 if (dwType
== REG_SZ
)
526 * retry in case of string value
528 dwValue
= sizeof(szValue
);
529 dwValueName
= MAX_PATH
;
530 if (RegEnumValueW(hKey
, dwIndex
, szValueName
, &dwValueName
, NULL
, NULL
, (BYTE
*)szValue
, &dwValue
) != ERROR_SUCCESS
)
536 if (!wcscmp(szValueName
, L
"CursorSize"))
540 Buffer
->CursorInfo
.dwSize
= Value
;
542 else if (Value
== 0x64)
544 Buffer
->CursorInfo
.dwSize
= Value
;
547 else if (!wcscmp(szValueName
, L
"ScreenText"))
549 GuiData
->ScreenText
= Value
;
551 else if (!wcscmp(szValueName
, L
"ScreenBackground"))
553 GuiData
->ScreenBackground
= Value
;
555 else if (!wcscmp(szValueName
, L
"FaceName"))
557 wcscpy(GuiData
->FontName
, szValue
);
559 else if (!wcscmp(szValueName
, L
"FontSize"))
561 GuiData
->FontSize
= Value
;
563 else if (!wcscmp(szValueName
, L
"FontWeight"))
565 GuiData
->FontWeight
= Value
;
567 else if (!wcscmp(szValueName
, L
"HistoryNoDup"))
569 GuiData
->HistoryNoDup
= Value
;
571 else if (!wcscmp(szValueName
, L
"WindowSize"))
573 Console
->Size
.X
= LOWORD(Value
);
574 Console
->Size
.Y
= HIWORD(Value
);
576 else if (!wcscmp(szValueName
, L
"ScreenBufferSize"))
580 Buffer
->MaxX
= LOWORD(Value
);
581 Buffer
->MaxY
= HIWORD(Value
);
584 else if (!wcscmp(szValueName
, L
"FullScreen"))
586 GuiData
->FullScreen
= Value
;
588 else if (!wcscmp(szValueName
, L
"QuickEdit"))
590 GuiData
->QuickEdit
= Value
;
592 else if (!wcscmp(szValueName
, L
"InsertMode"))
594 GuiData
->InsertMode
= Value
;
599 GuiConsoleUseDefaults(PCSRSS_CONSOLE Console
, PGUI_CONSOLE_DATA GuiData
, PCSRSS_SCREEN_BUFFER Buffer
)
602 * init guidata with default properties
605 wcscpy(GuiData
->FontName
, L
"DejaVu Sans Mono");
606 GuiData
->FontSize
= 0x0008000C; // font is 8x12
607 GuiData
->FontWeight
= FW_NORMAL
;
608 GuiData
->HistoryNoDup
= FALSE
;
609 GuiData
->FullScreen
= FALSE
;
610 GuiData
->QuickEdit
= FALSE
;
611 GuiData
->InsertMode
= TRUE
;
612 GuiData
->HistoryBufferSize
= 50;
613 GuiData
->NumberOfHistoryBuffers
= 5;
614 GuiData
->ScreenText
= RGB(192, 192, 192);
615 GuiData
->ScreenBackground
= RGB(0, 0, 0);
616 GuiData
->PopupText
= RGB(128, 0, 128);
617 GuiData
->PopupBackground
= RGB(255, 255, 255);
618 GuiData
->WindowPosition
= UINT_MAX
;
619 GuiData
->ScreenBufferSize
= MAKELONG(80, 300); //FIXME
620 GuiData
->UseRasterFonts
= TRUE
;
621 memcpy(GuiData
->Colors
, s_Colors
, sizeof(s_Colors
));
623 Console
->Size
.X
= 80;
624 Console
->Size
.Y
= 25;
630 Buffer
->CursorInfo
.bVisible
= TRUE
;
631 Buffer
->CursorInfo
.dwSize
= 5;
638 GuiConsoleHandleNcCreate(HWND hWnd
, CREATESTRUCTW
*Create
)
641 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) Create
->lpCreateParams
;
642 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Console
->PrivateData
;
646 PCSRSS_PROCESS_DATA ProcessData
;
649 Console
->hWindow
= hWnd
;
653 DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n");
657 GuiConsoleUseDefaults(Console
, GuiData
, Console
->ActiveBuffer
);
658 if (Console
->ProcessList
.Flink
!= &Console
->ProcessList
)
660 ProcessData
= CONTAINING_RECORD(Console
->ProcessList
.Flink
, CSRSS_PROCESS_DATA
, ProcessEntry
);
661 if (GuiConsoleOpenUserSettings(GuiData
, PtrToUlong(ProcessData
->ProcessId
), &hKey
, KEY_READ
, FALSE
))
663 GuiConsoleReadUserSettings(hKey
, Console
, GuiData
, Console
->ActiveBuffer
);
668 InitializeCriticalSection(&GuiData
->Lock
);
670 GuiData
->LineBuffer
= (PWCHAR
)HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
671 Console
->Size
.X
* sizeof(WCHAR
));
673 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->FontSize
),
674 0, //HIWORD(GuiData->FontSize),
682 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
683 NONANTIALIASED_QUALITY
, FIXED_PITCH
| FF_DONTCARE
,
685 if (NULL
== GuiData
->Font
)
687 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
688 DeleteCriticalSection(&GuiData
->Lock
);
689 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
695 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
696 DeleteObject(GuiData
->Font
);
697 DeleteCriticalSection(&GuiData
->Lock
);
698 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
701 OldFont
= SelectObject(Dc
, GuiData
->Font
);
704 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
706 DeleteObject(GuiData
->Font
);
707 DeleteCriticalSection(&GuiData
->Lock
);
708 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
711 if (! GetTextMetricsW(Dc
, &Metrics
))
713 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
714 SelectObject(Dc
, OldFont
);
716 DeleteObject(GuiData
->Font
);
717 DeleteCriticalSection(&GuiData
->Lock
);
718 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
721 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
722 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
723 SelectObject(Dc
, OldFont
);
726 GuiData
->CursorBlinkOn
= TRUE
;
727 GuiData
->ForceCursorOff
= FALSE
;
729 GuiData
->Selection
.left
= -1;
730 DPRINT("Console %p GuiData %p\n", Console
, GuiData
);
731 Console
->PrivateData
= GuiData
;
732 SetWindowLongPtrW(hWnd
, GWL_USERDATA
, (DWORD_PTR
) Console
);
734 GetWindowRect(hWnd
, &Rect
);
735 Rect
.right
= Rect
.left
+ Console
->Size
.X
* GuiData
->CharWidth
+
736 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
737 Rect
.bottom
= Rect
.top
+ Console
->Size
.Y
* GuiData
->CharHeight
+
738 2 * GetSystemMetrics(SM_CYFIXEDFRAME
) + GetSystemMetrics(SM_CYCAPTION
);
739 MoveWindow(hWnd
, Rect
.left
, Rect
.top
, Rect
.right
- Rect
.left
,
740 Rect
.bottom
- Rect
.top
, FALSE
);
742 SetTimer(hWnd
, 1, CURSOR_BLINK_TIME
, NULL
);
743 GuiConsoleCreateSysMenu(Console
);
744 SetEvent(GuiData
->hGuiInitEvent
);
746 return (BOOL
) DefWindowProcW(hWnd
, WM_NCCREATE
, 0, (LPARAM
) Create
);
749 static COLORREF FASTCALL
750 GuiConsoleRGBFromAttribute(BYTE Attribute
)
752 int Red
= (Attribute
& 0x04 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
753 int Green
= (Attribute
& 0x02 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
754 int Blue
= (Attribute
& 0x01 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
756 return RGB(Red
, Green
, Blue
);
760 GuiConsoleSetTextColors(HDC Dc
, BYTE Attribute
, PCSRSS_SCREEN_BUFFER Buff
, COLORREF TextColor
, COLORREF BkColor
)
762 if (Attribute
!= Buff
->DefaultAttrib
)
764 SetTextColor(Dc
, GuiConsoleRGBFromAttribute(Attribute
& 0x0f));
765 SetBkColor(Dc
, GuiConsoleRGBFromAttribute((Attribute
& 0xf0) >> 4));
769 SetTextColor(Dc
, TextColor
);
770 SetBkColor(Dc
, BkColor
);
775 GuiConsoleGetLogicalCursorPos(PCSRSS_SCREEN_BUFFER Buff
, ULONG
*CursorX
, ULONG
*CursorY
)
777 *CursorX
= Buff
->CurrentX
;
778 if (Buff
->CurrentY
< Buff
->ShowY
)
780 *CursorY
= Buff
->MaxY
- Buff
->ShowY
+ Buff
->CurrentY
;
784 *CursorY
= Buff
->CurrentY
- Buff
->ShowY
;
790 GuiConsoleUpdateSelection(HWND hWnd
, PRECT rc
, PGUI_CONSOLE_DATA GuiData
)
792 RECT oldRect
= GuiData
->Selection
;
796 RECT changeRect
= *rc
;
798 GuiData
->Selection
= *rc
;
800 changeRect
.left
*= GuiData
->CharWidth
;
801 changeRect
.top
*= GuiData
->CharHeight
;
802 changeRect
.right
*= GuiData
->CharWidth
;
803 changeRect
.bottom
*= GuiData
->CharHeight
;
805 if(rc
->left
!= oldRect
.left
||
806 rc
->top
!= oldRect
.top
||
807 rc
->right
!= oldRect
.right
||
808 rc
->bottom
!= oldRect
.bottom
)
810 if(oldRect
.left
!= -1)
814 oldRect
.left
*= GuiData
->CharWidth
;
815 oldRect
.top
*= GuiData
->CharHeight
;
816 oldRect
.right
*= GuiData
->CharWidth
;
817 oldRect
.bottom
*= GuiData
->CharHeight
;
819 /* calculate the region that needs to be updated */
820 if((rgn1
= CreateRectRgnIndirect(&oldRect
)))
822 if((rgn2
= CreateRectRgnIndirect(&changeRect
)))
824 if(CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
826 InvalidateRgn(hWnd
, rgn1
, FALSE
);
836 InvalidateRect(hWnd
, &changeRect
, FALSE
);
840 else if(oldRect
.left
!= -1)
842 /* clear the selection */
843 GuiData
->Selection
.left
= -1;
844 oldRect
.left
*= GuiData
->CharWidth
;
845 oldRect
.top
*= GuiData
->CharHeight
;
846 oldRect
.right
*= GuiData
->CharWidth
;
847 oldRect
.bottom
*= GuiData
->CharHeight
;
848 InvalidateRect(hWnd
, &oldRect
, FALSE
);
854 GuiConsolePaint(PCSRSS_CONSOLE Console
,
855 PGUI_CONSOLE_DATA GuiData
,
859 PCSRSS_SCREEN_BUFFER Buff
;
860 ULONG TopLine
, BottomLine
, LeftChar
, RightChar
;
861 ULONG Line
, Char
, Start
;
864 BYTE LastAttribute
, Attribute
;
865 ULONG CursorX
, CursorY
, CursorHeight
;
866 HBRUSH CursorBrush
, OldBrush
, BackgroundBrush
;
869 Buff
= Console
->ActiveBuffer
;
871 TopLine
= rc
->top
/ GuiData
->CharHeight
;
872 BottomLine
= (rc
->bottom
+ (GuiData
->CharHeight
- 1)) / GuiData
->CharHeight
- 1;
873 LeftChar
= rc
->left
/ GuiData
->CharWidth
;
874 RightChar
= (rc
->right
+ (GuiData
->CharWidth
- 1)) / GuiData
->CharWidth
- 1;
875 LastAttribute
= Buff
->Buffer
[(TopLine
* Buff
->MaxX
+ LeftChar
) * 2 + 1];
877 GuiConsoleSetTextColors(hDC
,
881 GuiData
->ScreenBackground
);
883 EnterCriticalSection(&Buff
->Header
.Lock
);
885 OldFont
= SelectObject(hDC
,
888 BackgroundBrush
= CreateSolidBrush(GuiData
->ScreenBackground
);
889 FillRect(hDC
, rc
, BackgroundBrush
);
890 DeleteObject(BackgroundBrush
);
892 for (Line
= TopLine
; Line
<= BottomLine
; Line
++)
894 if (Line
+ Buff
->ShowY
< Buff
->MaxY
)
896 From
= Buff
->Buffer
+ ((Line
+ Buff
->ShowY
) * Buff
->MaxX
+ LeftChar
) * 2;
900 From
= Buff
->Buffer
+
901 ((Line
- (Buff
->MaxY
- Buff
->ShowY
)) * Buff
->MaxX
+ LeftChar
) * 2;
904 To
= GuiData
->LineBuffer
;
906 for (Char
= LeftChar
; Char
<= RightChar
; Char
++)
908 if (*(From
+ 1) != LastAttribute
)
911 Start
* GuiData
->CharWidth
,
912 Line
* GuiData
->CharHeight
,
916 To
= GuiData
->LineBuffer
;
917 Attribute
= *(From
+ 1);
918 if (Attribute
!= LastAttribute
)
920 GuiConsoleSetTextColors(hDC
,
924 GuiData
->ScreenBackground
);
925 LastAttribute
= Attribute
;
929 MultiByteToWideChar(Console
->OutputCodePage
,
940 Start
* GuiData
->CharWidth
,
941 Line
* GuiData
->CharHeight
,
943 RightChar
- Start
+ 1);
946 if (Buff
->CursorInfo
.bVisible
&& GuiData
->CursorBlinkOn
&&
947 !GuiData
->ForceCursorOff
)
949 GuiConsoleGetLogicalCursorPos(Buff
,
952 if (LeftChar
<= CursorX
&& CursorX
<= RightChar
&&
953 TopLine
<= CursorY
&& CursorY
<= BottomLine
)
955 CursorHeight
= (GuiData
->CharHeight
* Buff
->CursorInfo
.dwSize
) / 100;
956 if (CursorHeight
< 1)
960 From
= Buff
->Buffer
+ (Buff
->CurrentY
* Buff
->MaxX
+ Buff
->CurrentX
) * 2 + 1;
962 if (*From
!= DEFAULT_ATTRIB
)
964 CursorBrush
= CreateSolidBrush(GuiConsoleRGBFromAttribute(*From
));
968 CursorBrush
= CreateSolidBrush(GuiData
->ScreenText
);
971 OldBrush
= SelectObject(hDC
,
974 CursorX
* GuiData
->CharWidth
,
975 CursorY
* GuiData
->CharHeight
+ (GuiData
->CharHeight
- CursorHeight
),
981 DeleteObject(CursorBrush
);
985 LeaveCriticalSection(&Buff
->Header
.Lock
);
992 GuiConsoleHandlePaint(HWND hWnd
, HDC hDCPaint
)
996 PCSRSS_CONSOLE Console
;
997 PGUI_CONSOLE_DATA GuiData
;
999 hDC
= BeginPaint(hWnd
, &ps
);
1001 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
1002 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
1004 GuiConsoleGetDataPointers(hWnd
,
1007 if (Console
!= NULL
&& GuiData
!= NULL
&&
1008 Console
->ActiveBuffer
!= NULL
)
1010 if (Console
->ActiveBuffer
->Buffer
!= NULL
)
1012 EnterCriticalSection(&GuiData
->Lock
);
1014 GuiConsolePaint(Console
,
1019 if (GuiData
->Selection
.left
!= -1)
1021 RECT rc
= GuiData
->Selection
;
1023 rc
.left
*= GuiData
->CharWidth
;
1024 rc
.top
*= GuiData
->CharHeight
;
1025 rc
.right
*= GuiData
->CharWidth
;
1026 rc
.bottom
*= GuiData
->CharHeight
;
1028 /* invert the selection */
1029 if (IntersectRect(&rc
,
1042 LeaveCriticalSection(&GuiData
->Lock
);
1046 EndPaint(hWnd
, &ps
);
1050 static VOID FASTCALL
1051 GuiConsoleHandleKey(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1053 PCSRSS_CONSOLE Console
;
1054 PGUI_CONSOLE_DATA GuiData
;
1057 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1058 Message
.hwnd
= hWnd
;
1059 Message
.message
= msg
;
1060 Message
.wParam
= wParam
;
1061 Message
.lParam
= lParam
;
1063 if(msg
== WM_CHAR
|| msg
== WM_SYSKEYDOWN
)
1065 /* clear the selection */
1066 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
1069 ConioProcessKey(&Message
, Console
, FALSE
);
1072 static VOID FASTCALL
1073 GuiIntDrawRegion(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, RECT
*Region
)
1077 RegionRect
.left
= Region
->left
* GuiData
->CharWidth
;
1078 RegionRect
.top
= Region
->top
* GuiData
->CharHeight
;
1079 RegionRect
.right
= (Region
->right
+ 1) * GuiData
->CharWidth
;
1080 RegionRect
.bottom
= (Region
->bottom
+ 1) * GuiData
->CharHeight
;
1082 InvalidateRect(Wnd
, &RegionRect
, FALSE
);
1086 GuiDrawRegion(PCSRSS_CONSOLE Console
, RECT
*Region
)
1088 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
1090 if (NULL
!= Console
->hWindow
&& NULL
!= GuiData
)
1092 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
1096 static VOID FASTCALL
1097 GuiInvalidateCell(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, UINT x
, UINT y
)
1104 CellRect
.bottom
= y
;
1106 GuiIntDrawRegion(GuiData
, Wnd
, &CellRect
);
1110 GuiWriteStream(PCSRSS_CONSOLE Console
, RECT
*Region
, LONG CursorStartX
, LONG CursorStartY
,
1111 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
)
1113 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
1114 PCSRSS_SCREEN_BUFFER Buff
= Console
->ActiveBuffer
;
1115 LONG CursorEndX
, CursorEndY
;
1118 if (NULL
== Console
->hWindow
|| NULL
== GuiData
)
1123 if (0 != ScrolledLines
)
1125 ScrollRect
.left
= 0;
1127 ScrollRect
.right
= Console
->Size
.X
* GuiData
->CharWidth
;
1128 ScrollRect
.bottom
= Region
->top
* GuiData
->CharHeight
;
1130 if (GuiData
->Selection
.left
!= -1)
1132 /* scroll the selection */
1133 if (GuiData
->Selection
.top
> ScrolledLines
)
1135 GuiData
->Selection
.top
-= ScrolledLines
;
1136 GuiData
->Selection
.bottom
-= ScrolledLines
;
1138 else if (GuiData
->Selection
.bottom
< ScrolledLines
)
1140 GuiData
->Selection
.left
= -1;
1144 GuiData
->Selection
.top
= 0;
1145 GuiData
->Selection
.bottom
-= ScrolledLines
;
1149 ScrollWindowEx(Console
->hWindow
,
1151 -(ScrolledLines
* GuiData
->CharHeight
),
1159 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
1161 if (CursorStartX
< Region
->left
|| Region
->right
< CursorStartX
1162 || CursorStartY
< Region
->top
|| Region
->bottom
< CursorStartY
)
1164 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorStartX
, CursorStartY
);
1167 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
1168 &CursorEndX
, &CursorEndY
);
1169 if ((CursorEndX
< Region
->left
|| Region
->right
< CursorEndX
1170 || CursorEndY
< Region
->top
|| Region
->bottom
< CursorEndY
)
1171 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
1173 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorEndX
, CursorEndY
);
1178 GuiSetCursorInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
)
1182 if (Console
->ActiveBuffer
== Buff
)
1184 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
1185 &UpdateRect
.left
, &UpdateRect
.top
);
1186 UpdateRect
.right
= UpdateRect
.left
;
1187 UpdateRect
.bottom
= UpdateRect
.top
;
1188 ConioDrawRegion(Console
, &UpdateRect
);
1195 GuiSetScreenInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
, UINT OldCursorX
, UINT OldCursorY
)
1199 if (Console
->ActiveBuffer
== Buff
)
1201 /* Redraw char at old position (removes cursor) */
1202 UpdateRect
.left
= OldCursorX
;
1203 UpdateRect
.top
= OldCursorY
;
1204 UpdateRect
.right
= OldCursorX
;
1205 UpdateRect
.bottom
= OldCursorY
;
1206 ConioDrawRegion(Console
, &UpdateRect
);
1207 /* Redraw char at new position (shows cursor) */
1208 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
1209 &(UpdateRect
.left
), &(UpdateRect
.top
));
1210 UpdateRect
.right
= UpdateRect
.left
;
1211 UpdateRect
.bottom
= UpdateRect
.top
;
1212 ConioDrawRegion(Console
, &UpdateRect
);
1218 static VOID FASTCALL
1219 GuiConsoleHandleTimer(HWND hWnd
)
1221 PCSRSS_CONSOLE Console
;
1222 PGUI_CONSOLE_DATA GuiData
;
1224 ULONG CursorX
, CursorY
;
1226 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1227 GuiData
->CursorBlinkOn
= ! GuiData
->CursorBlinkOn
;
1229 GuiConsoleGetLogicalCursorPos(Console
->ActiveBuffer
, &CursorX
, &CursorY
);
1230 CursorRect
.left
= CursorX
;
1231 CursorRect
.top
= CursorY
;
1232 CursorRect
.right
= CursorX
;
1233 CursorRect
.bottom
= CursorY
;
1234 GuiDrawRegion(Console
, &CursorRect
);
1237 static VOID FASTCALL
1238 GuiConsoleHandleClose(HWND hWnd
)
1240 PCSRSS_CONSOLE Console
;
1241 PGUI_CONSOLE_DATA GuiData
;
1242 PLIST_ENTRY current_entry
;
1243 PCSRSS_PROCESS_DATA current
;
1245 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1247 EnterCriticalSection(&Console
->Header
.Lock
);
1249 current_entry
= Console
->ProcessList
.Flink
;
1250 while (current_entry
!= &Console
->ProcessList
)
1252 current
= CONTAINING_RECORD(current_entry
, CSRSS_PROCESS_DATA
, ProcessEntry
);
1253 current_entry
= current_entry
->Flink
;
1255 ConioConsoleCtrlEvent(CTRL_CLOSE_EVENT
, current
);
1258 LeaveCriticalSection(&Console
->Header
.Lock
);
1261 static VOID FASTCALL
1262 GuiConsoleHandleNcDestroy(HWND hWnd
)
1264 PCSRSS_CONSOLE Console
;
1265 PGUI_CONSOLE_DATA GuiData
;
1268 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1270 Console
->PrivateData
= NULL
;
1271 DeleteCriticalSection(&GuiData
->Lock
);
1272 GetSystemMenu(hWnd
, TRUE
);
1273 if (GuiData
->ConsoleLibrary
)
1274 FreeLibrary(GuiData
->ConsoleLibrary
);
1276 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
1279 static VOID FASTCALL
1280 GuiConsoleLeftMouseDown(HWND hWnd
, LPARAM lParam
)
1282 PCSRSS_CONSOLE Console
;
1283 PGUI_CONSOLE_DATA GuiData
;
1287 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1288 if (Console
== NULL
|| GuiData
== NULL
) return;
1290 pt
= MAKEPOINTS(lParam
);
1292 rc
.left
= pt
.x
/ GuiData
->CharWidth
;
1293 rc
.top
= pt
.y
/ GuiData
->CharHeight
;
1294 rc
.right
= rc
.left
+ 1;
1295 rc
.bottom
= rc
.top
+ 1;
1297 GuiData
->SelectionStart
.x
= rc
.left
;
1298 GuiData
->SelectionStart
.y
= rc
.top
;
1302 GuiData
->MouseDown
= TRUE
;
1304 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
1307 static VOID FASTCALL
1308 GuiConsoleLeftMouseUp(HWND hWnd
, LPARAM lParam
)
1310 PCSRSS_CONSOLE Console
;
1311 PGUI_CONSOLE_DATA GuiData
;
1315 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1316 if (Console
== NULL
|| GuiData
== NULL
) return;
1317 if (GuiData
->Selection
.left
== -1 || !GuiData
->MouseDown
) return;
1319 pt
= MAKEPOINTS(lParam
);
1321 rc
.left
= GuiData
->SelectionStart
.x
;
1322 rc
.top
= GuiData
->SelectionStart
.y
;
1323 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
1324 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
1326 /* exchange left/top with right/bottom if required */
1327 if(rc
.left
>= rc
.right
)
1331 rc
.left
= max(rc
.right
- 1, 0);
1334 if(rc
.top
>= rc
.bottom
)
1338 rc
.top
= max(rc
.bottom
- 1, 0);
1339 rc
.bottom
= tmp
+ 1;
1342 GuiData
->MouseDown
= FALSE
;
1344 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
1349 static VOID FASTCALL
1350 GuiConsoleMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1352 PCSRSS_CONSOLE Console
;
1353 PGUI_CONSOLE_DATA GuiData
;
1357 if (!(wParam
& MK_LBUTTON
)) return;
1359 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1360 if (Console
== NULL
|| GuiData
== NULL
|| !GuiData
->MouseDown
) return;
1362 pt
= MAKEPOINTS(lParam
);
1364 rc
.left
= GuiData
->SelectionStart
.x
;
1365 rc
.top
= GuiData
->SelectionStart
.y
;
1366 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
1367 if (Console
->Size
.X
< rc
.right
)
1369 rc
.right
= Console
->Size
.X
;
1371 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
1372 if (Console
->Size
.Y
< rc
.bottom
)
1374 rc
.bottom
= Console
->Size
.Y
;
1377 /* exchange left/top with right/bottom if required */
1378 if(rc
.left
>= rc
.right
)
1382 rc
.left
= max(rc
.right
- 1, 0);
1385 if(rc
.top
>= rc
.bottom
)
1389 rc
.top
= max(rc
.bottom
- 1, 0);
1390 rc
.bottom
= tmp
+ 1;
1393 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
1396 static VOID FASTCALL
1397 GuiConsoleRightMouseDown(HWND hWnd
)
1399 PCSRSS_CONSOLE Console
;
1400 PGUI_CONSOLE_DATA GuiData
;
1402 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1403 if (Console
== NULL
|| GuiData
== NULL
) return;
1405 if (GuiData
->Selection
.left
== -1)
1407 /* FIXME - paste text from clipboard */
1411 /* FIXME - copy selection to clipboard */
1413 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
1420 GuiConsoleShowConsoleProperties(HWND hWnd
, BOOL Defaults
, PGUI_CONSOLE_DATA GuiData
)
1422 PCSRSS_CONSOLE Console
;
1423 APPLET_PROC CPLFunc
;
1424 TCHAR szBuffer
[MAX_PATH
];
1425 ConsoleInfo SharedInfo
;
1427 DPRINT("GuiConsoleShowConsoleProperties entered\n");
1429 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1431 if (GuiData
== NULL
)
1433 DPRINT("GuiConsoleGetDataPointers failed\n");
1437 if (GuiData
->ConsoleLibrary
== NULL
)
1439 GetWindowsDirectory(szBuffer
,MAX_PATH
);
1440 _tcscat(szBuffer
, _T("\\system32\\console.dll"));
1441 GuiData
->ConsoleLibrary
= LoadLibrary(szBuffer
);
1443 if (GuiData
->ConsoleLibrary
== NULL
)
1445 DPRINT1("failed to load console.dll");
1450 CPLFunc
= (APPLET_PROC
) GetProcAddress(GuiData
->ConsoleLibrary
, _T("CPlApplet"));
1453 DPRINT("Error: Console.dll misses CPlApplet export\n");
1458 SharedInfo
.InsertMode
= GuiData
->InsertMode
;
1459 SharedInfo
.HistoryBufferSize
= GuiData
->HistoryBufferSize
;
1460 SharedInfo
.NumberOfHistoryBuffers
= GuiData
->NumberOfHistoryBuffers
;
1461 SharedInfo
.ScreenText
= GuiData
->ScreenText
;
1462 SharedInfo
.ScreenBackground
= GuiData
->ScreenBackground
;
1463 SharedInfo
.PopupText
= GuiData
->PopupText
;
1464 SharedInfo
.PopupBackground
= GuiData
->PopupBackground
;
1465 SharedInfo
.WindowSize
= (DWORD
)MAKELONG(Console
->Size
.X
, Console
->Size
.Y
);
1466 SharedInfo
.WindowPosition
= GuiData
->WindowPosition
;
1467 SharedInfo
.ScreenBuffer
= GuiData
->ScreenBufferSize
;
1468 SharedInfo
.UseRasterFonts
= GuiData
->UseRasterFonts
;
1469 SharedInfo
.FontSize
= (DWORD
)GuiData
->FontSize
;
1470 SharedInfo
.FontWeight
= GuiData
->FontWeight
;
1471 SharedInfo
.CursorSize
= Console
->ActiveBuffer
->CursorInfo
.dwSize
;
1472 SharedInfo
.HistoryNoDup
= GuiData
->HistoryNoDup
;
1473 SharedInfo
.FullScreen
= GuiData
->FullScreen
;
1474 SharedInfo
.QuickEdit
= GuiData
->QuickEdit
;
1475 memcpy(&SharedInfo
.Colors
[0], GuiData
->Colors
, sizeof(s_Colors
));
1477 if (!CPLFunc(hWnd
, CPL_INIT
, 0, 0))
1479 DPRINT("Error: failed to initialize console.dll\n");
1483 if (CPLFunc(hWnd
, CPL_GETCOUNT
, 0, 0) != 1)
1485 DPRINT("Error: console.dll returned unexpected CPL count\n");
1489 CPLFunc(hWnd
, CPL_DBLCLK
, (LPARAM
)&SharedInfo
, Defaults
);
1491 static LRESULT FASTCALL
1492 GuiConsoleHandleSysMenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, PGUI_CONSOLE_DATA GuiData
)
1498 case ID_SYSTEM_EDIT_MARK
:
1499 case ID_SYSTEM_EDIT_COPY
:
1500 case ID_SYSTEM_EDIT_PASTE
:
1501 case ID_SYSTEM_EDIT_SELECTALL
:
1502 case ID_SYSTEM_EDIT_SCROLL
:
1503 case ID_SYSTEM_EDIT_FIND
:
1506 case ID_SYSTEM_DEFAULTS
:
1507 GuiConsoleShowConsoleProperties(hWnd
, TRUE
, GuiData
);
1510 case ID_SYSTEM_PROPERTIES
:
1511 GuiConsoleShowConsoleProperties(hWnd
, FALSE
, GuiData
);
1515 Ret
= DefWindowProcW(hWnd
, WM_SYSCOMMAND
, wParam
, lParam
);
1521 static VOID FASTCALL
1522 GuiConsoleResize(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1524 PCSRSS_CONSOLE Console
;
1525 PGUI_CONSOLE_DATA GuiData
;
1527 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1528 if (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
)
1530 DPRINT1("GuiConsoleResize X %d Y %d\n", LOWORD(lParam
), HIWORD(lParam
));
1535 GuiConsoleCreateScrollBar(PCSRSS_CONSOLE Console
, PGUI_CONSOLE_DATA GuiData
, HWND NewWindow
)
1542 hMenu
= CreatePopupMenu();
1545 DPRINT("CreatePopupMenu failed\n");
1549 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1550 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1551 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1552 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1553 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1554 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1555 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1556 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1557 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1558 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1560 hVScrollBar
= CreateWindowExW(0L,
1563 WS_CHILD
| WS_VSCROLL
,
1570 GetModuleHandleW(NULL
),
1576 /* set scrollbar sizes */
1577 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1578 sInfo
.fMask
= SIF_RANGE
| SIF_POS
;
1580 sInfo
.nMax
= Console
->ActiveBuffer
->MaxY
;
1582 SetScrollInfo(hVScrollBar
, SB_CTL
, &sInfo
, TRUE
);
1583 ShowScrollBar(NewWindow
, SB_CTL
, TRUE
);
1584 GuiData
->hVScrollBar
= hVScrollBar
;
1587 if (Console
->ActiveBuffer
->MaxX
> Console
->Size
.X
)
1589 hHScrollBar
= CreateWindowExW(0L,
1592 WS_CHILD
| WS_HSCROLL
,
1599 GetModuleHandleW(NULL
),
1603 sInfo
.nMax
= Console
->ActiveBuffer
->MaxX
;
1604 SetScrollInfo(hHScrollBar
, SB_CTL
, &sInfo
, TRUE
);
1605 GuiData
->hHScrollBar
= hHScrollBar
;
1610 static VOID FASTCALL
1611 GuiApplyUserSettings(PCSRSS_CONSOLE Console
, PGUI_CONSOLE_DATA GuiData
, PConsoleInfo pConInfo
)
1616 /* apply text / background color */
1617 GuiData
->ScreenText
= pConInfo
->ScreenText
;
1618 GuiData
->ScreenBackground
= pConInfo
->ScreenBackground
;
1620 /* apply cursor size */
1621 Console
->ActiveBuffer
->CursorInfo
.dwSize
= max(min(pConInfo
->CursorSize
, 1), 100);
1623 windx
= LOWORD(pConInfo
->ScreenBuffer
);
1624 windy
= HIWORD(pConInfo
->ScreenBuffer
);
1626 if (windx
!= Console
->ActiveBuffer
->MaxX
|| windy
!= Console
->ActiveBuffer
->MaxY
)
1630 // resize screen buffer
1633 // Console->ActiveBuffer->MaxX = windx;
1634 // Console->ActiveBuffer->MaxY = windy;
1637 windx
= LOWORD(pConInfo
->WindowSize
);
1638 windy
= HIWORD(pConInfo
->WindowSize
);
1640 if (windx
!= Console
->Size
.X
|| windy
!= Console
->Size
.Y
)
1643 Console
->Size
.X
= windx
;
1644 Console
->Size
.Y
= windy
;
1646 GetWindowRect(pConInfo
->hConsoleWindow
, &rect
);
1648 rect
.right
= rect
.left
+ Console
->Size
.X
* GuiData
->CharWidth
+ 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
1649 rect
.bottom
= rect
.top
+ Console
->Size
.Y
* GuiData
->CharHeight
+ 2 * GetSystemMetrics(SM_CYFIXEDFRAME
) + GetSystemMetrics(SM_CYCAPTION
);
1651 MoveWindow(pConInfo
->hConsoleWindow
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, FALSE
);
1653 if (Console
->Size
.X
< Console
->ActiveBuffer
->MaxX
)
1655 /* show scrollbar when window becomes smaller than active screen buffer */
1656 //ShowScrollBar(GuiData->hHScrollBar, SB_CTL, TRUE);
1660 /* hide scrollbar */
1661 //ShowScrollBar(GuiData->hHScrollBar, SB_CTL, FALSE);
1664 /* repaint window */
1665 InvalidateRect(pConInfo
->hConsoleWindow
, NULL
, TRUE
);
1668 static LRESULT CALLBACK
1669 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1672 PGUI_CONSOLE_DATA GuiData
= NULL
;
1673 PCSRSS_CONSOLE Console
= NULL
;
1675 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1680 Result
= (LRESULT
) GuiConsoleHandleNcCreate(hWnd
, (CREATESTRUCTW
*) lParam
);
1683 GuiConsoleHandlePaint(hWnd
, (HDC
)wParam
);
1690 GuiConsoleHandleKey(hWnd
, msg
, wParam
, lParam
);
1693 GuiConsoleHandleTimer(hWnd
);
1696 GuiConsoleHandleClose(hWnd
);
1699 GuiConsoleHandleNcDestroy(hWnd
);
1701 case WM_LBUTTONDOWN
:
1702 GuiConsoleLeftMouseDown(hWnd
, lParam
);
1705 GuiConsoleLeftMouseUp(hWnd
, lParam
);
1707 case WM_RBUTTONDOWN
:
1708 GuiConsoleRightMouseDown(hWnd
);
1711 GuiConsoleMouseMove(hWnd
, wParam
, lParam
);
1714 Result
= GuiConsoleHandleSysMenuCommand(hWnd
, wParam
, lParam
, GuiData
);
1717 GuiConsoleResize(hWnd
, wParam
, lParam
);
1719 case PM_APPLY_CONSOLE_INFO
:
1720 GuiApplyUserSettings(Console
, GuiData
, (PConsoleInfo
)wParam
);
1723 GuiConsoleWriteUserSettings(Console
, GuiData
);
1727 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1734 static LRESULT CALLBACK
1735 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1740 PWCHAR Buffer
, Title
;
1741 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) lParam
;
1748 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
1750 case PM_CREATE_CONSOLE
:
1751 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
1752 Console
->Title
.Length
+ sizeof(WCHAR
));
1755 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
1756 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
1763 NewWindow
= CreateWindowW(L
"ConsoleWindowClass",
1765 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
, //WS_OVERLAPPEDWINDOW
1772 (HINSTANCE
) GetModuleHandleW(NULL
),
1776 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
1778 if (NULL
!= NewWindow
)
1780 // scrollbar support
1781 //GuiConsoleCreateScrollBar(Console, (PGUI_CONSOLE_DATA)Console->PrivateData, NewWindow);
1782 SetWindowLongW(hWnd
, GWL_USERDATA
, GetWindowLongW(hWnd
, GWL_USERDATA
) + 1);
1783 ShowWindow(NewWindow
, SW_SHOW
);
1785 return (LRESULT
) NewWindow
;
1786 case PM_DESTROY_CONSOLE
:
1787 /* Window creation is done using a PostMessage(), so it's possible that the
1788 * window that we want to destroy doesn't exist yet. So first empty the message
1790 while(PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
))
1792 TranslateMessage(&Msg
);
1793 DispatchMessageW(&Msg
);
1795 DestroyWindow(Console
->hWindow
);
1796 Console
->hWindow
= NULL
;
1797 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
1799 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
1800 if (0 == WindowCount
)
1803 DestroyWindow(hWnd
);
1804 PrivateCsrssManualGuiCheck(-1);
1809 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1813 static DWORD STDCALL
1814 GuiConsoleGuiThread(PVOID Data
)
1817 PHANDLE GraphicsStartupEvent
= (PHANDLE
) Data
;
1819 NotifyWnd
= CreateWindowW(L
"Win32CsrCreateNotify",
1821 WS_OVERLAPPEDWINDOW
,
1828 (HINSTANCE
) GetModuleHandleW(NULL
),
1830 if (NULL
== NotifyWnd
)
1832 PrivateCsrssManualGuiCheck(-1);
1833 SetEvent(*GraphicsStartupEvent
);
1837 SetEvent(*GraphicsStartupEvent
);
1839 while(GetMessageW(&msg
, NULL
, 0, 0))
1841 TranslateMessage(&msg
);
1842 DispatchMessageW(&msg
);
1848 static BOOL FASTCALL
1853 if (NULL
== NotifyWnd
)
1855 PrivateCsrssManualGuiCheck(+1);
1858 wc
.cbSize
= sizeof(WNDCLASSEXW
);
1859 wc
.lpszClassName
= L
"Win32CsrCreateNotify";
1860 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
1862 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
1865 wc
.hbrBackground
= NULL
;
1866 wc
.lpszMenuName
= NULL
;
1870 if (RegisterClassExW(&wc
) == 0)
1872 DPRINT1("Failed to register notify wndproc\n");
1876 wc
.cbSize
= sizeof(WNDCLASSEXW
);
1877 wc
.lpszClassName
= L
"ConsoleWindowClass";
1878 wc
.lpfnWndProc
= GuiConsoleWndProc
;
1880 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
1881 wc
.hIcon
= LoadIconW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1));
1882 wc
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
) IDC_ARROW
);
1883 wc
.hbrBackground
= NULL
;
1884 wc
.lpszMenuName
= NULL
;
1887 wc
.hIconSm
= LoadImageW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1), IMAGE_ICON
,
1888 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
1890 if (RegisterClassExW(&wc
) == 0)
1892 DPRINT1("Failed to register console wndproc\n");
1900 GuiInitScreenBuffer(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buffer
)
1902 Buffer
->DefaultAttrib
= DEFAULT_ATTRIB
;
1906 GuiChangeTitle(PCSRSS_CONSOLE Console
)
1908 PWCHAR Buffer
, Title
;
1910 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
1911 Console
->Title
.Length
+ sizeof(WCHAR
));
1914 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
1915 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
1923 SendMessageW(Console
->hWindow
, WM_SETTEXT
, 0, (LPARAM
) Title
);
1927 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
1934 GuiChangeIcon(PCSRSS_CONSOLE Console
)
1936 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)Console
->hWindowIcon
);
1937 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)Console
->hWindowIcon
);
1943 GuiCleanupConsole(PCSRSS_CONSOLE Console
)
1945 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
) Console
);
1948 static CSRSS_CONSOLE_VTBL GuiVtbl
=
1950 GuiInitScreenBuffer
,
1961 GuiInitConsole(PCSRSS_CONSOLE Console
)
1963 HANDLE GraphicsStartupEvent
;
1964 HANDLE ThreadHandle
;
1965 PGUI_CONSOLE_DATA GuiData
;
1967 if (! ConsInitialized
)
1969 ConsInitialized
= TRUE
;
1972 ConsInitialized
= FALSE
;
1973 return STATUS_UNSUCCESSFUL
;
1977 Console
->Vtbl
= &GuiVtbl
;
1978 if (NULL
== NotifyWnd
)
1980 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1981 if (NULL
== GraphicsStartupEvent
)
1983 return STATUS_UNSUCCESSFUL
;
1986 ThreadHandle
= CreateThread(NULL
,
1988 GuiConsoleGuiThread
,
1989 (PVOID
) &GraphicsStartupEvent
,
1992 if (NULL
== ThreadHandle
)
1994 NtClose(GraphicsStartupEvent
);
1995 DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n");
1996 return STATUS_UNSUCCESSFUL
;
1998 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
1999 CloseHandle(ThreadHandle
);
2001 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
2002 CloseHandle(GraphicsStartupEvent
);
2004 if (NULL
== NotifyWnd
)
2006 DPRINT1("Win32Csr: Failed to create notification window.\n");
2007 return STATUS_UNSUCCESSFUL
;
2010 GuiData
= HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
2011 sizeof(GUI_CONSOLE_DATA
));
2014 DPRINT1("Win32Csr: Failed to create GUI_CONSOLE_DATA\n");
2015 return STATUS_UNSUCCESSFUL
;
2018 Console
->PrivateData
= (PVOID
) GuiData
;
2020 * we need to wait untill the GUI has been fully initialized
2021 * to retrieve custom settings i.e. WindowSize etc..
2022 * Ideally we could use SendNotifyMessage for this but its not
2026 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2027 /* create console */
2028 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, 0, (LPARAM
) Console
);
2030 /* wait untill initialization has finished */
2031 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
2032 DPRINT1("received event Console %p GuiData %p X %d Y %d\n", Console
, Console
->PrivateData
, Console
->Size
.X
, Console
->Size
.Y
);
2033 CloseHandle(GuiData
->hGuiInitEvent
);
2034 GuiData
->hGuiInitEvent
= NULL
;
2036 return STATUS_SUCCESS
;