2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
5 * PURPOSE: GUI Terminal Front-End
6 * PROGRAMMERS: Gé van Geldorp
9 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
12 /* INCLUDES *******************************************************************/
17 #include "include/conio.h"
18 #include "include/console.h"
19 #include "include/settings.h"
20 #include "conoutput.h"
22 #include "guisettings.h"
33 /* GUI Console Window Class name */
34 #define GUI_CONSOLE_WINDOW_CLASS L"ConsoleWindowClass"
39 #define PM_CREATE_CONSOLE (WM_APP + 1)
40 #define PM_DESTROY_CONSOLE (WM_APP + 2)
41 #define PM_RESIZE_TERMINAL (WM_APP + 3)
42 #define PM_CONSOLE_BEEP (WM_APP + 4)
43 #define PM_CONSOLE_SET_TITLE (WM_APP + 5)
46 /* Not defined in any header file */
47 extern VOID NTAPI
PrivateCsrssManualGuiCheck(LONG Check
);
48 // See winsrv/usersrv/init.c line 234
51 /* GLOBALS ********************************************************************/
53 typedef struct _GUI_INIT_INFO
55 PCONSOLE_INFO ConsoleInfo
;
56 PCONSOLE_START_INFO ConsoleStartInfo
;
58 } GUI_INIT_INFO
, *PGUI_INIT_INFO
;
60 /**************************************************************\
61 \** Define the Console Leader Process for the console window **/
62 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
63 #define GWLP_CONSOLE_LEADER_PID 0
64 #define GWLP_CONSOLE_LEADER_TID 4
66 #define SetConsoleWndConsoleLeaderCID(GuiData) \
68 PCONSOLE_PROCESS_DATA ProcessData; \
69 CLIENT_ID ConsoleLeaderCID; \
70 ProcessData = CONTAINING_RECORD((GuiData)->Console->ProcessList.Blink, \
71 CONSOLE_PROCESS_DATA, \
73 ConsoleLeaderCID = ProcessData->Process->ClientId; \
74 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_PID, \
75 (LONG_PTR)(ConsoleLeaderCID.UniqueProcess)); \
76 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_TID, \
77 (LONG_PTR)(ConsoleLeaderCID.UniqueThread )); \
79 /**************************************************************/
81 static BOOL ConsInitialized
= FALSE
;
82 static HICON ghDefaultIcon
= NULL
;
83 static HICON ghDefaultIconSm
= NULL
;
84 static HCURSOR ghDefaultCursor
= NULL
;
85 static HWND NotifyWnd
= NULL
;
87 typedef struct _GUICONSOLE_MENUITEM
90 const struct _GUICONSOLE_MENUITEM
*SubMenu
;
92 } GUICONSOLE_MENUITEM
, *PGUICONSOLE_MENUITEM
;
94 static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems
[] =
96 { IDS_MARK
, NULL
, ID_SYSTEM_EDIT_MARK
},
97 { IDS_COPY
, NULL
, ID_SYSTEM_EDIT_COPY
},
98 { IDS_PASTE
, NULL
, ID_SYSTEM_EDIT_PASTE
},
99 { IDS_SELECTALL
, NULL
, ID_SYSTEM_EDIT_SELECTALL
},
100 { IDS_SCROLL
, NULL
, ID_SYSTEM_EDIT_SCROLL
},
101 { IDS_FIND
, NULL
, ID_SYSTEM_EDIT_FIND
},
103 { 0, NULL
, 0 } /* End of list */
106 static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems
[] =
108 { IDS_EDIT
, GuiConsoleEditMenuItems
, 0 },
109 { IDS_DEFAULTS
, NULL
, ID_SYSTEM_DEFAULTS
},
110 { IDS_PROPERTIES
, NULL
, ID_SYSTEM_PROPERTIES
},
112 { 0, NULL
, 0 } /* End of list */
116 * Default 16-color palette for foreground and background
117 * (corresponding flags in comments).
119 const COLORREF s_Colors
[16] =
121 RGB(0, 0, 0), // (Black)
122 RGB(0, 0, 128), // BLUE
123 RGB(0, 128, 0), // GREEN
124 RGB(0, 128, 128), // BLUE | GREEN
125 RGB(128, 0, 0), // RED
126 RGB(128, 0, 128), // BLUE | RED
127 RGB(128, 128, 0), // GREEN | RED
128 RGB(192, 192, 192), // BLUE | GREEN | RED
130 RGB(128, 128, 128), // (Grey) INTENSITY
131 RGB(0, 0, 255), // BLUE | INTENSITY
132 RGB(0, 255, 0), // GREEN | INTENSITY
133 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
134 RGB(255, 0, 0), // RED | INTENSITY
135 RGB(255, 0, 255), // BLUE | RED | INTENSITY
136 RGB(255, 255, 0), // GREEN | RED | INTENSITY
137 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
140 /* FUNCTIONS ******************************************************************/
143 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer
,
144 IN PGUI_CONSOLE_DATA GuiData
,
146 OUT PUINT HeightUnit
)
148 if (Buffer
== NULL
|| GuiData
== NULL
||
149 WidthUnit
== NULL
|| HeightUnit
== NULL
)
154 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
156 *WidthUnit
= GuiData
->CharWidth
;
157 *HeightUnit
= GuiData
->CharHeight
;
159 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
169 GuiConsoleAppendMenuItems(HMENU hMenu
,
170 const GUICONSOLE_MENUITEM
*Items
)
173 WCHAR szMenuString
[255];
178 if (Items
[i
].uID
!= (UINT
)-1)
180 if (LoadStringW(ConSrvDllInstance
,
183 sizeof(szMenuString
) / sizeof(szMenuString
[0])) > 0)
185 if (Items
[i
].SubMenu
!= NULL
)
187 hSubMenu
= CreatePopupMenu();
188 if (hSubMenu
!= NULL
)
190 GuiConsoleAppendMenuItems(hSubMenu
,
193 if (!AppendMenuW(hMenu
,
194 MF_STRING
| MF_POPUP
,
198 DestroyMenu(hSubMenu
);
219 } while (!(Items
[i
].uID
== 0 && Items
[i
].SubMenu
== NULL
&& Items
[i
].wCmdID
== 0));
223 GuiConsoleCreateSysMenu(HWND hWnd
)
225 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
228 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
234 GuiSendMenuEvent(PCONSOLE Console
, UINT CmdId
)
238 er
.EventType
= MENU_EVENT
;
239 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
241 ConioProcessInputEvent(Console
, &er
);
245 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
);
247 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
);
249 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
);
251 GuiDrawRegion(IN OUT PFRONTEND This
, SMALL_RECT
* Region
);
253 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
, DWORD WidthUnit
, DWORD HeightUnit
);
257 GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
260 PCONSOLE Console
= GuiData
->Console
;
261 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
263 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
268 ActiveBuffer
= GuiData
->ActiveBuffer
;
271 * In case the selected menu item belongs to the user-reserved menu id range,
272 * send to him a menu event and return directly. The user must handle those
273 * reserved menu commands...
275 if (GuiData
->cmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->cmdIdHigh
)
277 GuiSendMenuEvent(Console
, (UINT
)wParam
);
281 /* ... otherwise, perform actions. */
284 case ID_SYSTEM_EDIT_MARK
:
286 LPWSTR WindowTitle
= NULL
;
289 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ViewOrigin
.X
;
290 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewOrigin
.Y
;
291 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
292 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
293 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
295 Length
= Console
->Title
.Length
+ sizeof(L
"Mark - ")/sizeof(WCHAR
) + 1;
296 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
297 wcscpy(WindowTitle
, L
"Mark - ");
298 wcscat(WindowTitle
, Console
->Title
.Buffer
);
299 SetWindowText(GuiData
->hWindow
, WindowTitle
);
300 ConsoleFreeHeap(WindowTitle
);
305 case ID_SYSTEM_EDIT_COPY
:
306 GuiConsoleCopy(GuiData
);
309 case ID_SYSTEM_EDIT_PASTE
:
310 GuiConsolePaste(GuiData
);
313 case ID_SYSTEM_EDIT_SELECTALL
:
315 LPWSTR WindowTitle
= NULL
;
319 * The selection area extends to the whole screen buffer's width.
321 Console
->Selection
.dwSelectionAnchor
.X
= 0;
322 Console
->Selection
.dwSelectionAnchor
.Y
= 0;
323 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
326 * Determine whether the selection must extend to just some part
327 * (for text-mode screen buffers) or to all of the screen buffer's
328 * height (for graphics ones).
330 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
333 * We select all the characters from the first line
334 * to the line where the cursor is positioned.
336 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->CursorPosition
.Y
;
338 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
341 * We select all the screen buffer area.
343 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
346 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
;
347 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
349 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
350 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
351 wcscpy(WindowTitle
, L
"Selection - ");
352 wcscat(WindowTitle
, Console
->Title
.Buffer
);
353 SetWindowText(GuiData
->hWindow
, WindowTitle
);
354 ConsoleFreeHeap(WindowTitle
);
359 case ID_SYSTEM_EDIT_SCROLL
:
360 DPRINT1("Scrolling is not handled yet\n");
363 case ID_SYSTEM_EDIT_FIND
:
364 DPRINT1("Finding is not handled yet\n");
367 case ID_SYSTEM_DEFAULTS
:
368 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
371 case ID_SYSTEM_PROPERTIES
:
372 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
381 LeaveCriticalSection(&Console
->Lock
);
384 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
389 static PGUI_CONSOLE_DATA
390 GuiGetGuiData(HWND hWnd
)
392 /* This function ensures that the console pointer is not NULL */
393 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
394 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
398 GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData
)
400 /* Move the window if needed (not positioned by the system) */
401 if (!GuiData
->GuiInfo
.AutoPosition
)
403 SetWindowPos(GuiData
->hWindow
,
405 GuiData
->GuiInfo
.WindowOrigin
.x
,
406 GuiData
->GuiInfo
.WindowOrigin
.y
,
409 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
414 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
, DWORD WidthUnit
, DWORD HeightUnit
)
416 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
421 Width
= Buff
->ViewSize
.X
* WidthUnit
+
422 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
423 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
424 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
426 /* Set scrollbar sizes */
427 sInfo
.cbSize
= sizeof(SCROLLINFO
);
428 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
430 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
432 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
433 sInfo
.nPage
= Buff
->ViewSize
.Y
;
434 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
435 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
436 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
437 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
441 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
444 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
446 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
447 sInfo
.nPage
= Buff
->ViewSize
.X
;
448 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
449 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
450 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
451 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
455 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
458 /* Resize the window */
459 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
460 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
461 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
462 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
466 GuiConsoleHandleNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
468 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
475 DPRINT("GuiConsoleHandleNcCreate\n");
479 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
483 Console
= GuiData
->Console
;
485 GuiData
->hWindow
= hWnd
;
487 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->GuiInfo
.FontSize
),
488 0, // HIWORD(GuiData->GuiInfo.FontSize),
491 GuiData
->GuiInfo
.FontWeight
,
498 NONANTIALIASED_QUALITY
,
499 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
500 GuiData
->GuiInfo
.FaceName
);
502 if (NULL
== GuiData
->Font
)
504 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
505 GuiData
->hWindow
= NULL
;
506 SetEvent(GuiData
->hGuiInitEvent
);
509 hDC
= GetDC(GuiData
->hWindow
);
512 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
513 DeleteObject(GuiData
->Font
);
514 GuiData
->hWindow
= NULL
;
515 SetEvent(GuiData
->hGuiInitEvent
);
518 OldFont
= SelectObject(hDC
, GuiData
->Font
);
521 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
522 ReleaseDC(GuiData
->hWindow
, hDC
);
523 DeleteObject(GuiData
->Font
);
524 GuiData
->hWindow
= NULL
;
525 SetEvent(GuiData
->hGuiInitEvent
);
528 if (!GetTextMetricsW(hDC
, &Metrics
))
530 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
531 SelectObject(hDC
, OldFont
);
532 ReleaseDC(GuiData
->hWindow
, hDC
);
533 DeleteObject(GuiData
->Font
);
534 GuiData
->hWindow
= NULL
;
535 SetEvent(GuiData
->hGuiInitEvent
);
538 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
539 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
541 /* Measure real char width more precisely if possible. */
542 if (GetTextExtentPoint32W(hDC
, L
"R", 1, &CharSize
))
543 GuiData
->CharWidth
= CharSize
.cx
;
545 SelectObject(hDC
, OldFont
);
547 ReleaseDC(GuiData
->hWindow
, hDC
);
549 /* Initialize the terminal framebuffer */
550 GuiData
->hMemDC
= CreateCompatibleDC(NULL
);
551 GuiData
->hBitmap
= NULL
;
552 GuiData
->hSysPalette
= NULL
; /* Original system palette */
554 // FIXME: Keep these instructions here ? ///////////////////////////////////
555 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
556 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
557 ////////////////////////////////////////////////////////////////////////////
559 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
561 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
562 GuiConsoleCreateSysMenu(GuiData
->hWindow
);
564 DPRINT("GuiConsoleHandleNcCreate - setting start event\n");
565 SetEvent(GuiData
->hGuiInitEvent
);
567 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
571 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
573 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
574 UINT WidthUnit
, HeightUnit
;
576 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
578 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
579 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
580 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
581 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
585 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
)
587 PGUI_CONSOLE_DATA GuiData
= Console
->TermIFace
.Data
;
588 RECT oldRect
, newRect
;
590 SmallRectToRect(GuiData
, &oldRect
, &Console
->Selection
.srSelection
);
595 /* exchange left/top with right/bottom if required */
596 rc
.Left
= min(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
597 rc
.Top
= min(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
598 rc
.Right
= max(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
599 rc
.Bottom
= max(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
601 SmallRectToRect(GuiData
, &newRect
, &rc
);
603 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
605 if (memcmp(&rc
, &Console
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
609 /* calculate the region that needs to be updated */
610 if ((rgn1
= CreateRectRgnIndirect(&oldRect
)))
612 if ((rgn2
= CreateRectRgnIndirect(&newRect
)))
614 if (CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
616 InvalidateRgn(GuiData
->hWindow
, rgn1
, FALSE
);
626 InvalidateRect(GuiData
->hWindow
, &newRect
, FALSE
);
628 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
629 Console
->Selection
.srSelection
= rc
;
630 Console
->dwSelectionCursor
= *coord
;
631 ConioPause(Console
, PAUSED_FROM_SELECTION
);
635 /* clear the selection */
636 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
638 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
640 Console
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
641 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
647 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
648 PGUI_CONSOLE_DATA GuiData
,
650 PRECT rcFramebuffer
);
652 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
653 PGUI_CONSOLE_DATA GuiData
,
655 PRECT rcFramebuffer
);
658 GuiConsoleHandlePaint(PGUI_CONSOLE_DATA GuiData
)
661 PCONSOLE Console
= GuiData
->Console
;
662 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
666 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
671 ActiveBuffer
= GuiData
->ActiveBuffer
;
673 BeginPaint(GuiData
->hWindow
, &ps
);
674 if (ps
.hdc
!= NULL
&&
675 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
676 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
678 EnterCriticalSection(&GuiData
->Lock
);
680 /* Compose the current screen-buffer on-memory */
681 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
683 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
684 GuiData
, &ps
.rcPaint
, &rcPaint
);
686 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
688 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
689 GuiData
, &ps
.rcPaint
, &rcPaint
);
692 /* Send it to screen */
696 rcPaint
.right
- rcPaint
.left
,
697 rcPaint
.bottom
- rcPaint
.top
,
703 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
705 SmallRectToRect(GuiData
, &rcPaint
, &Console
->Selection
.srSelection
);
707 /* Invert the selection */
708 if (IntersectRect(&rcPaint
, &ps
.rcPaint
, &rcPaint
))
710 InvertRect(ps
.hdc
, &rcPaint
);
714 LeaveCriticalSection(&GuiData
->Lock
);
716 EndPaint(GuiData
->hWindow
, &ps
);
720 LeaveCriticalSection(&Console
->Lock
);
722 DefWindowProcW(GuiData
->hWindow
, WM_PAINT
, 0, 0);
728 IsSystemKey(WORD VirtualKeyCode
)
730 switch (VirtualKeyCode
)
732 /* From MSDN, "Virtual-Key Codes" */
751 GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
753 PCONSOLE Console
= GuiData
->Console
;
754 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
756 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
758 ActiveBuffer
= GuiData
->ActiveBuffer
;
760 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
762 WORD VirtualKeyCode
= LOWORD(wParam
);
764 if (msg
!= WM_KEYDOWN
) goto Quit
;
766 if (VirtualKeyCode
== VK_RETURN
)
768 /* Copy (and clear) selection if ENTER is pressed */
769 GuiConsoleCopy(GuiData
);
772 else if ( VirtualKeyCode
== VK_ESCAPE
||
773 (VirtualKeyCode
== 'C' && GetKeyState(VK_CONTROL
) & 0x8000) )
775 /* Cancel selection if ESC or Ctrl-C are pressed */
776 GuiConsoleUpdateSelection(Console
, NULL
);
777 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
782 if ((Console
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
784 /* Keyboard selection mode */
785 BOOL Interpreted
= FALSE
;
786 BOOL MajPressed
= (GetKeyState(VK_SHIFT
) & 0x8000);
788 switch (VirtualKeyCode
)
793 if (Console
->dwSelectionCursor
.X
> 0)
794 Console
->dwSelectionCursor
.X
--;
802 if (Console
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
803 Console
->dwSelectionCursor
.X
++;
811 if (Console
->dwSelectionCursor
.Y
> 0)
812 Console
->dwSelectionCursor
.Y
--;
820 if (Console
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
821 Console
->dwSelectionCursor
.Y
++;
829 Console
->dwSelectionCursor
.X
= 0;
830 Console
->dwSelectionCursor
.Y
= 0;
837 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
844 Console
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
845 if (Console
->dwSelectionCursor
.Y
< 0)
846 Console
->dwSelectionCursor
.Y
= 0;
854 Console
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
855 if (Console
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
856 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
868 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
870 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
872 else if (!IsSystemKey(VirtualKeyCode
))
874 /* Emit an error beep sound */
875 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
882 /* Mouse selection mode */
884 if (!IsSystemKey(VirtualKeyCode
))
886 /* Clear the selection and send the key into the input buffer */
887 GuiConsoleUpdateSelection(Console
, NULL
);
888 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
897 if ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
901 Message
.hwnd
= GuiData
->hWindow
;
902 Message
.message
= msg
;
903 Message
.wParam
= wParam
;
904 Message
.lParam
= lParam
;
906 ConioProcessKey(Console
, &Message
);
910 LeaveCriticalSection(&Console
->Lock
);
914 GuiInvalidateCell(IN OUT PFRONTEND This
, SHORT x
, SHORT y
)
916 SMALL_RECT CellRect
= { x
, y
, x
, y
};
917 GuiDrawRegion(This
, &CellRect
);
921 GuiConsoleHandleTimer(PGUI_CONSOLE_DATA GuiData
)
923 PCONSOLE Console
= GuiData
->Console
;
924 PCONSOLE_SCREEN_BUFFER Buff
;
926 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
928 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
930 Buff
= GuiData
->ActiveBuffer
;
932 if (GetType(Buff
) == TEXTMODE_BUFFER
)
934 GuiInvalidateCell(&Console
->TermIFace
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
935 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
937 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) ||
938 (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
941 int OldScrollX
= -1, OldScrollY
= -1;
942 int NewScrollX
= -1, NewScrollY
= -1;
944 xScroll
.cbSize
= sizeof(SCROLLINFO
);
945 xScroll
.fMask
= SIF_POS
;
946 // Capture the original position of the scroll bars and save them.
947 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
948 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
950 // If we successfully got the info for the horizontal scrollbar
953 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) ||
954 (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
956 // Handle the horizontal scroll bar
957 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
)
958 NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
964 NewScrollX
= OldScrollX
;
967 // If we successfully got the info for the vertical scrollbar
970 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) ||
971 (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
973 // Handle the vertical scroll bar
974 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
)
975 NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
981 NewScrollY
= OldScrollY
;
985 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
986 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
987 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
988 // and their associated scrollbar is left alone.
989 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
991 Buff
->ViewOrigin
.X
= NewScrollX
;
992 Buff
->ViewOrigin
.Y
= NewScrollY
;
993 ScrollWindowEx(GuiData
->hWindow
,
994 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
995 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1001 if (NewScrollX
>= 0)
1003 xScroll
.nPos
= NewScrollX
;
1004 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1006 if (NewScrollY
>= 0)
1008 xScroll
.nPos
= NewScrollY
;
1009 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1011 UpdateWindow(GuiData
->hWindow
);
1012 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1013 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1014 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1018 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1022 LeaveCriticalSection(&Console
->Lock
);
1026 GuiConsoleHandleClose(PGUI_CONSOLE_DATA GuiData
)
1028 PCONSOLE Console
= GuiData
->Console
;
1030 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1033 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1036 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1037 * We shouldn't wait here, though, since the console lock is entered.
1038 * A copy of the thread list probably needs to be made.
1040 ConDrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1042 LeaveCriticalSection(&Console
->Lock
);
1047 GuiConsoleHandleNcDestroy(HWND hWnd
)
1049 PGUI_CONSOLE_DATA GuiData
= GuiGetGuiData(hWnd
);
1051 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1052 GetSystemMenu(hWnd
, TRUE
);
1056 /* Free the terminal framebuffer */
1057 if (GuiData
->hMemDC
) DeleteDC(GuiData
->hMemDC
);
1058 if (GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
1059 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1060 if (GuiData
->Font
) DeleteObject(GuiData
->Font
);
1063 /* Free the GuiData registration */
1064 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1066 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1070 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1072 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1074 UINT WidthUnit
, HeightUnit
;
1076 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1078 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1079 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1081 /* Clip coordinate to ensure it's inside buffer */
1084 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1085 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1089 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1090 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1096 GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1099 PCONSOLE Console
= GuiData
->Console
;
1101 if (GuiData
->IgnoreNextMouseSignal
)
1103 if (msg
!= WM_LBUTTONDOWN
&&
1104 msg
!= WM_MBUTTONDOWN
&&
1105 msg
!= WM_RBUTTONDOWN
)
1108 * If this mouse signal is not a button-down action,
1109 * then it is the last signal being ignored.
1111 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1116 * This mouse signal is a button-down action.
1117 * Ignore it and perform default action.
1124 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1130 if ( (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1131 (Console
->QuickEdit
) )
1135 case WM_LBUTTONDOWN
:
1137 LPWSTR WindowTitle
= NULL
;
1140 Console
->Selection
.dwSelectionAnchor
= PointToCoord(GuiData
, lParam
);
1141 SetCapture(GuiData
->hWindow
);
1142 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1143 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
1145 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
1146 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
1147 wcscpy(WindowTitle
, L
"Selection - ");
1148 wcscat(WindowTitle
, Console
->Title
.Buffer
);
1149 SetWindowText(GuiData
->hWindow
, WindowTitle
);
1150 ConsoleFreeHeap(WindowTitle
);
1159 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1161 c
= PointToCoord(GuiData
, lParam
);
1162 Console
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1163 GuiConsoleUpdateSelection(Console
, &c
);
1169 case WM_LBUTTONDBLCLK
:
1171 DPRINT1("Handle left-double-click for selecting a word\n");
1175 case WM_RBUTTONDOWN
:
1176 case WM_RBUTTONDBLCLK
:
1178 if (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1180 GuiConsolePaste(GuiData
);
1184 GuiConsoleCopy(GuiData
);
1187 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1195 if (!(wParam
& MK_LBUTTON
)) break;
1196 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1198 c
= PointToCoord(GuiData
, lParam
); /* TODO: Scroll buffer to bring c into view */
1199 GuiConsoleUpdateSelection(Console
, &c
);
1205 Err
= FALSE
; // TRUE;
1209 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1212 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1213 DWORD dwButtonState
= 0;
1214 DWORD dwControlKeyState
= 0;
1215 DWORD dwEventFlags
= 0;
1219 case WM_LBUTTONDOWN
:
1220 SetCapture(GuiData
->hWindow
);
1221 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1225 case WM_MBUTTONDOWN
:
1226 SetCapture(GuiData
->hWindow
);
1227 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1231 case WM_RBUTTONDOWN
:
1232 SetCapture(GuiData
->hWindow
);
1233 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1255 case WM_LBUTTONDBLCLK
:
1256 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1257 dwEventFlags
= DOUBLE_CLICK
;
1260 case WM_MBUTTONDBLCLK
:
1261 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1262 dwEventFlags
= DOUBLE_CLICK
;
1265 case WM_RBUTTONDBLCLK
:
1266 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1267 dwEventFlags
= DOUBLE_CLICK
;
1272 dwEventFlags
= MOUSE_MOVED
;
1276 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1277 dwEventFlags
= MOUSE_WHEELED
;
1280 case WM_MOUSEHWHEEL
:
1281 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1282 dwEventFlags
= MOUSE_HWHEELED
;
1292 if (wKeyState
& MK_LBUTTON
)
1293 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1294 if (wKeyState
& MK_MBUTTON
)
1295 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1296 if (wKeyState
& MK_RBUTTON
)
1297 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1299 if (GetKeyState(VK_RMENU
) & 0x8000)
1300 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1301 if (GetKeyState(VK_LMENU
) & 0x8000)
1302 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1303 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1304 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1305 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1306 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1307 if (GetKeyState(VK_SHIFT
) & 0x8000)
1308 dwControlKeyState
|= SHIFT_PRESSED
;
1309 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1310 dwControlKeyState
|= NUMLOCK_ON
;
1311 if (GetKeyState(VK_SCROLL
) & 0x0001)
1312 dwControlKeyState
|= SCROLLLOCK_ON
;
1313 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1314 dwControlKeyState
|= CAPSLOCK_ON
;
1315 /* See WM_CHAR MSDN documentation for instance */
1316 if (lParam
& 0x01000000)
1317 dwControlKeyState
|= ENHANCED_KEY
;
1319 er
.EventType
= MOUSE_EVENT
;
1320 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1321 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1322 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1323 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1325 ConioProcessInputEvent(Console
, &er
);
1333 LeaveCriticalSection(&Console
->Lock
);
1337 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1342 VOID
GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1343 VOID
GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1346 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
)
1348 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1350 PCONSOLE Console
= GuiData
->Console
;
1351 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1353 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1355 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1357 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1359 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1364 /* Clear the selection */
1365 GuiConsoleUpdateSelection(Console
, NULL
);
1366 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
1370 VOID
GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1371 VOID
GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1374 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
)
1376 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1378 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1380 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1382 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1384 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1386 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1394 GuiConsoleGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1396 PCONSOLE Console
= GuiData
->Console
;
1397 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1399 UINT WidthUnit
, HeightUnit
;
1401 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1403 ActiveBuffer
= GuiData
->ActiveBuffer
;
1405 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1407 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1408 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1410 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1411 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1413 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1414 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1416 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1417 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1419 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1420 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1422 LeaveCriticalSection(&Console
->Lock
);
1426 GuiConsoleResize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1428 PCONSOLE Console
= GuiData
->Console
;
1430 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1432 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1433 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1435 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1436 DWORD windx
, windy
, charx
, chary
;
1437 UINT WidthUnit
, HeightUnit
;
1439 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1441 GuiData
->WindowSizeLock
= TRUE
;
1443 windx
= LOWORD(lParam
);
1444 windy
= HIWORD(lParam
);
1446 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1447 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1448 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1450 charx
= windx
/ (int)WidthUnit
;
1451 chary
= windy
/ (int)HeightUnit
;
1453 // Character alignment (round size up or down)
1454 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1455 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1457 // Compensate for added scroll bars in new window
1458 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1459 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1461 charx
= windx
/ (int)WidthUnit
;
1462 chary
= windy
/ (int)HeightUnit
;
1464 // Character alignment (round size up or down)
1465 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1466 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1469 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1471 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1472 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1475 GuiConsoleResizeWindow(GuiData
, WidthUnit
, HeightUnit
);
1477 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1478 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1479 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1480 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1482 GuiData
->WindowSizeLock
= FALSE
;
1485 LeaveCriticalSection(&Console
->Lock
);
1489 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1493 GuiConsoleHandleScrollbarMenu(VOID)
1497 hMenu = CreatePopupMenu();
1500 DPRINT("CreatePopupMenu failed\n");
1504 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1505 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1506 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1507 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1508 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1509 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1510 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1511 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1512 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1513 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1518 GuiConsoleHandleScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1520 PCONSOLE Console
= GuiData
->Console
;
1521 PCONSOLE_SCREEN_BUFFER Buff
;
1524 int old_pos
, Maximum
;
1527 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1529 Buff
= GuiData
->ActiveBuffer
;
1531 if (uMsg
== WM_HSCROLL
)
1534 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1535 pShowXY
= &Buff
->ViewOrigin
.X
;
1540 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1541 pShowXY
= &Buff
->ViewOrigin
.Y
;
1544 /* set scrollbar sizes */
1545 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1546 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1548 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1550 old_pos
= sInfo
.nPos
;
1552 switch (LOWORD(wParam
))
1563 sInfo
.nPos
-= sInfo
.nPage
;
1567 sInfo
.nPos
+= sInfo
.nPage
;
1571 sInfo
.nPos
= sInfo
.nTrackPos
;
1572 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1575 case SB_THUMBPOSITION
:
1576 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1580 sInfo
.nPos
= sInfo
.nMin
;
1584 sInfo
.nPos
= sInfo
.nMax
;
1591 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1592 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1594 if (old_pos
!= sInfo
.nPos
)
1596 USHORT OldX
= Buff
->ViewOrigin
.X
;
1597 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1598 UINT WidthUnit
, HeightUnit
;
1600 *pShowXY
= sInfo
.nPos
;
1602 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1604 ScrollWindowEx(GuiData
->hWindow
,
1605 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1606 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1613 sInfo
.fMask
= SIF_POS
;
1614 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1616 UpdateWindow(GuiData
->hWindow
);
1617 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1621 LeaveCriticalSection(&Console
->Lock
);
1627 EnterFullScreen(PGUI_CONSOLE_DATA GuiData
);
1629 LeaveFullScreen(PGUI_CONSOLE_DATA GuiData
);
1631 SwitchFullScreen(PGUI_CONSOLE_DATA GuiData
, BOOL FullScreen
);
1633 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
);
1635 static LRESULT CALLBACK
1636 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1639 PGUI_CONSOLE_DATA GuiData
= NULL
;
1640 PCONSOLE Console
= NULL
;
1643 * - If it's the first time we create a window for the terminal,
1644 * just initialize it and return.
1646 * - If we are destroying the window, just do it and return.
1648 if (msg
== WM_NCCREATE
)
1650 return (LRESULT
)GuiConsoleHandleNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1652 else if (msg
== WM_NCDESTROY
)
1654 return GuiConsoleHandleNcDestroy(hWnd
);
1658 * Now the terminal window is initialized.
1659 * Get the terminal data via the window's data.
1660 * If there is no data, just go away.
1662 GuiData
= GuiGetGuiData(hWnd
);
1663 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1665 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
1666 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1669 * Just retrieve a pointer to the console in case somebody needs it.
1670 * It is not NULL because it was checked in GuiGetGuiData.
1671 * Each helper function which needs the console has to validate and lock it.
1673 Console
= GuiData
->Console
;
1675 /* We have a console, start message dispatching */
1680 WORD ActivationState
= LOWORD(wParam
);
1682 DPRINT1("WM_ACTIVATE - ActivationState = %d\n");
1684 if ( ActivationState
== WA_ACTIVE
||
1685 ActivationState
== WA_CLICKACTIVE
)
1687 if (GuiData
->GuiInfo
.FullScreen
)
1689 EnterFullScreen(GuiData
);
1690 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
1691 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
1694 else // if (ActivationState == WA_INACTIVE)
1696 if (GuiData
->GuiInfo
.FullScreen
)
1698 SendMessageW(GuiData
->hWindow
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
1699 LeaveFullScreen(GuiData
);
1700 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
1701 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
1705 if (ActivationState
== WA_CLICKACTIVE
) GuiData
->IgnoreNextMouseSignal
= TRUE
;
1711 if (GuiConsoleHandleClose(GuiData
)) goto Default
;
1715 GuiConsoleHandlePaint(GuiData
);
1718 case WM_PALETTECHANGED
:
1720 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
1722 DPRINT1("WM_PALETTECHANGED called\n");
1725 * Protects against infinite loops:
1726 * "... A window that receives this message must not realize
1727 * its palette, unless it determines that wParam does not contain
1728 * its own window handle." (WM_PALETTECHANGED description - MSDN)
1730 * This message is sent to all windows, including the one that
1731 * changed the system palette and caused this message to be sent.
1732 * The wParam of this message contains the handle of the window
1733 * that caused the system palette to change. To avoid an infinite
1734 * loop, care must be taken to check that the wParam of this message
1735 * does not match the window's handle.
1737 if ((HWND
)wParam
== hWnd
) break;
1739 DPRINT1("WM_PALETTECHANGED ok\n");
1741 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
1742 if (ActiveBuffer
->PaletteHandle
)
1744 DPRINT1("WM_PALETTECHANGED changing palette\n");
1746 /* Specify the use of the system palette for the framebuffer */
1747 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
1749 /* Realize the (logical) palette */
1750 RealizePalette(GuiData
->hMemDC
);
1753 DPRINT1("WM_PALETTECHANGED quit\n");
1765 case WM_SYSDEADCHAR
:
1767 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1768 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1770 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1771 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
1772 GuiConsoleSwitchFullScreen(GuiData
);
1777 GuiConsoleHandleKey(GuiData
, msg
, wParam
, lParam
);
1782 GuiConsoleHandleTimer(GuiData
);
1788 * The message was sent because we are manually triggering a change.
1789 * Check whether the mouse is indeed present on this console window
1790 * and take appropriate decisions.
1792 if (wParam
== -1 && lParam
== -1)
1797 /* Get the placement of the mouse */
1798 GetCursorPos(&mouseCoords
);
1800 /* On which window is placed the mouse ? */
1801 hWndHit
= WindowFromPoint(mouseCoords
);
1803 /* It's our window. Perform the hit-test to be used later on. */
1804 if (hWndHit
== hWnd
)
1806 wParam
= (WPARAM
)hWnd
;
1807 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1808 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1812 /* Set the mouse cursor only when we are in the client area */
1813 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1815 if (GuiData
->MouseCursorRefCount
>= 0)
1817 /* Show the cursor */
1818 SetCursor(GuiData
->hCursor
);
1822 /* Hide the cursor if the reference count is negative */
1833 case WM_LBUTTONDOWN
:
1834 case WM_MBUTTONDOWN
:
1835 case WM_RBUTTONDOWN
:
1839 case WM_LBUTTONDBLCLK
:
1840 case WM_MBUTTONDBLCLK
:
1841 case WM_RBUTTONDBLCLK
:
1844 case WM_MOUSEHWHEEL
:
1846 Result
= GuiConsoleHandleMouse(GuiData
, msg
, wParam
, lParam
);
1853 Result
= GuiConsoleHandleScroll(GuiData
, msg
, wParam
);
1857 case WM_NCRBUTTONDOWN
:
1859 DPRINT1("WM_NCRBUTTONDOWN\n");
1861 * HACK: !! Because, when we deal with WM_RBUTTON* and we do not
1862 * call after that DefWindowProc, on ReactOS, right-clicks on the
1863 * (non-client) application title-bar does not display the system
1864 * menu and does not trigger a WM_NCRBUTTONUP message too.
1865 * See: http://git.reactos.org/?p=reactos.git;a=blob;f=reactos/win32ss/user/user32/windows/defwnd.c;hb=332bc8f482f40fd05ab510f78276576719fbfba8#l1103
1866 * and line 1135 too.
1869 if (DefWindowProcW(hWnd
, WM_NCHITTEST
, 0, lParam
) == HTCAPTION
)
1871 /* Call DefWindowProcW with the WM_CONTEXTMENU message */
1872 msg
= WM_CONTEXTMENU
;
1877 // case WM_NCRBUTTONUP:
1878 // DPRINT1("WM_NCRBUTTONUP\n");
1881 case WM_CONTEXTMENU
:
1883 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
1885 HMENU hMenu
= CreatePopupMenu();
1888 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
1889 TrackPopupMenuEx(hMenu
,
1891 GET_X_LPARAM(lParam
),
1892 GET_Y_LPARAM(lParam
),
1907 HMENU hMenu
= (HMENU
)wParam
;
1910 /* Enable or disable the Close menu item */
1911 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
1912 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
1914 /* Enable or disable the Copy and Paste items */
1915 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
1916 ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1917 (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
1918 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
1919 (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1920 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
1923 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1925 GuiSendMenuEvent(Console
, WM_INITMENU
);
1926 LeaveCriticalSection(&Console
->Lock
);
1933 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
1935 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1937 GuiSendMenuEvent(Console
, WM_MENUSELECT
);
1938 LeaveCriticalSection(&Console
->Lock
);
1947 Result
= GuiConsoleHandleSysMenuCommand(GuiData
, wParam
, lParam
);
1954 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1956 BOOL SetFocus
= (msg
== WM_SETFOCUS
);
1959 er
.EventType
= FOCUS_EVENT
;
1960 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
1961 ConioProcessInputEvent(Console
, &er
);
1964 DPRINT1("TODO: Create console caret\n");
1966 DPRINT1("TODO: Destroy console caret\n");
1968 LeaveCriticalSection(&Console
->Lock
);
1973 case WM_GETMINMAXINFO
:
1974 GuiConsoleGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
1978 GuiConsoleResize(GuiData
, wParam
, lParam
);
1981 case PM_RESIZE_TERMINAL
:
1983 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1987 DWORD Width
, Height
;
1988 UINT WidthUnit
, HeightUnit
;
1990 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1992 Width
= Buff
->ScreenBufferSize
.X
* WidthUnit
;
1993 Height
= Buff
->ScreenBufferSize
.Y
* HeightUnit
;
1995 /* Recreate the framebuffer */
1996 hDC
= GetDC(GuiData
->hWindow
);
1997 hnew
= CreateCompatibleBitmap(hDC
, Width
, Height
);
1998 ReleaseDC(GuiData
->hWindow
, hDC
);
1999 hold
= SelectObject(GuiData
->hMemDC
, hnew
);
2000 if (GuiData
->hBitmap
)
2002 if (hold
== GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
2004 GuiData
->hBitmap
= hnew
;
2006 /* Resize the window to the user's values */
2007 GuiData
->WindowSizeLock
= TRUE
;
2008 GuiConsoleResizeWindow(GuiData
, WidthUnit
, HeightUnit
);
2009 GuiData
->WindowSizeLock
= FALSE
;
2013 case PM_APPLY_CONSOLE_INFO
:
2015 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
2017 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
2018 LeaveCriticalSection(&Console
->Lock
);
2023 case PM_CONSOLE_BEEP
:
2024 DPRINT1("Beep !!\n");
2028 // case PM_CONSOLE_SET_TITLE:
2029 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
2033 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2042 /******************************************************************************
2043 * GUI Terminal Initialization *
2044 ******************************************************************************/
2046 static LRESULT CALLBACK
2047 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2057 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
2061 case PM_CREATE_CONSOLE
:
2063 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2064 PCONSOLE Console
= GuiData
->Console
;
2066 NewWindow
= CreateWindowExW(WS_EX_CLIENTEDGE
,
2067 GUI_CONSOLE_WINDOW_CLASS
,
2068 Console
->Title
.Buffer
,
2069 WS_OVERLAPPEDWINDOW
| WS_HSCROLL
| WS_VSCROLL
,
2078 if (NULL
!= NewWindow
)
2080 ASSERT(NewWindow
== GuiData
->hWindow
);
2082 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2084 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2086 DPRINT("Set icons via PM_CREATE_CONSOLE\n");
2087 if (GuiData
->hIcon
== NULL
)
2089 DPRINT("Not really /o\\...\n");
2090 GuiData
->hIcon
= ghDefaultIcon
;
2091 GuiData
->hIconSm
= ghDefaultIconSm
;
2093 else if (GuiData
->hIcon
!= ghDefaultIcon
)
2095 DPRINT("Yes \\o/\n");
2096 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2097 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2100 /* Move and resize the window to the user's values */
2101 /* CAN WE DEADLOCK ?? */
2102 GuiConsoleMoveWindow(GuiData
);
2103 SendMessageW(GuiData
->hWindow
, PM_RESIZE_TERMINAL
, 0, 0);
2105 /* Switch to full-screen mode if necessary */
2106 if (GuiData
->GuiInfo
.FullScreen
) SwitchFullScreen(GuiData
, TRUE
);
2108 // ShowWindow(NewWindow, (int)wParam);
2109 ShowWindowAsync(NewWindow
, (int)wParam
);
2110 DPRINT("Window showed\n");
2113 return (LRESULT
)NewWindow
;
2116 case PM_DESTROY_CONSOLE
:
2118 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2120 /* Exit the full screen mode if it was already set */
2121 // LeaveFullScreen(GuiData);
2124 * Window creation is done using a PostMessage(), so it's possible
2125 * that the window that we want to destroy doesn't exist yet.
2126 * So first empty the message queue.
2129 while (PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE))
2131 TranslateMessage(&Msg);
2132 DispatchMessageW(&Msg);
2134 while (PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
)) ;
2136 if (GuiData
->hWindow
!= NULL
) /* && DestroyWindow(GuiData->hWindow) */
2138 DestroyWindow(GuiData
->hWindow
);
2140 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2142 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2143 if (0 == WindowCount
)
2146 DestroyWindow(hWnd
);
2147 DPRINT("CONSRV: Going to quit the Gui Thread!!\n");
2156 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2161 GuiConsoleGuiThread(PVOID Data
)
2164 PHANDLE GraphicsStartupEvent
= (PHANDLE
)Data
;
2167 * This thread dispatches all the console notifications to the notify window.
2168 * It is common for all the console windows.
2171 PrivateCsrssManualGuiCheck(+1);
2173 NotifyWnd
= CreateWindowW(L
"ConSrvCreateNotify",
2175 WS_OVERLAPPEDWINDOW
,
2184 if (NULL
== NotifyWnd
)
2186 PrivateCsrssManualGuiCheck(-1);
2187 SetEvent(*GraphicsStartupEvent
);
2191 SetEvent(*GraphicsStartupEvent
);
2193 while (GetMessageW(&msg
, NULL
, 0, 0))
2195 TranslateMessage(&msg
);
2196 DispatchMessageW(&msg
);
2199 DPRINT("CONSRV: Quit the Gui Thread!!\n");
2200 PrivateCsrssManualGuiCheck(-1);
2209 ATOM ConsoleClassAtom
;
2211 /* Exit if we were already initialized */
2212 // if (ConsInitialized) return TRUE;
2215 * Initialize and register the different window classes, if needed.
2217 if (!ConsInitialized
)
2219 /* Initialize the notification window class */
2220 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2221 wc
.lpszClassName
= L
"ConSrvCreateNotify";
2222 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
2224 wc
.hInstance
= ConSrvDllInstance
;
2228 wc
.hbrBackground
= NULL
;
2229 wc
.lpszMenuName
= NULL
;
2232 if (RegisterClassExW(&wc
) == 0)
2234 DPRINT1("Failed to register GUI notify wndproc\n");
2238 /* Initialize the console window class */
2239 ghDefaultIcon
= LoadImageW(ConSrvDllInstance
,
2240 MAKEINTRESOURCEW(IDI_TERMINAL
),
2242 GetSystemMetrics(SM_CXICON
),
2243 GetSystemMetrics(SM_CYICON
),
2245 ghDefaultIconSm
= LoadImageW(ConSrvDllInstance
,
2246 MAKEINTRESOURCEW(IDI_TERMINAL
),
2248 GetSystemMetrics(SM_CXSMICON
),
2249 GetSystemMetrics(SM_CYSMICON
),
2251 ghDefaultCursor
= LoadCursorW(NULL
, IDC_ARROW
);
2252 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2253 wc
.lpszClassName
= GUI_CONSOLE_WINDOW_CLASS
;
2254 wc
.lpfnWndProc
= GuiConsoleWndProc
;
2255 wc
.style
= CS_DBLCLKS
/* | CS_HREDRAW | CS_VREDRAW */;
2256 wc
.hInstance
= ConSrvDllInstance
;
2257 wc
.hIcon
= ghDefaultIcon
;
2258 wc
.hIconSm
= ghDefaultIconSm
;
2259 wc
.hCursor
= ghDefaultCursor
;
2260 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
); // The color of a terminal when it is switch off.
2261 wc
.lpszMenuName
= NULL
;
2263 wc
.cbWndExtra
= GWLP_CONSOLEWND_ALLOC
;
2265 ConsoleClassAtom
= RegisterClassExW(&wc
);
2266 if (ConsoleClassAtom
== 0)
2268 DPRINT1("Failed to register GUI console wndproc\n");
2273 NtUserConsoleControl(GuiConsoleWndClassAtom
, &ConsoleClassAtom
, sizeof(ATOM
));
2276 ConsInitialized
= TRUE
;
2280 * Set-up the notification window
2282 if (NULL
== NotifyWnd
)
2284 HANDLE ThreadHandle
;
2285 HANDLE GraphicsStartupEvent
;
2287 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2288 if (NULL
== GraphicsStartupEvent
) return FALSE
;
2290 ThreadHandle
= CreateThread(NULL
,
2292 GuiConsoleGuiThread
,
2293 (PVOID
)&GraphicsStartupEvent
,
2296 if (NULL
== ThreadHandle
)
2298 CloseHandle(GraphicsStartupEvent
);
2299 DPRINT1("CONSRV: Failed to create graphics console thread. Expect problems\n");
2302 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
2303 CloseHandle(ThreadHandle
);
2305 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
2306 CloseHandle(GraphicsStartupEvent
);
2308 if (NULL
== NotifyWnd
)
2310 DPRINT1("CONSRV: Failed to create notification window.\n");
2315 // ConsInitialized = TRUE;
2322 /******************************************************************************
2323 * GUI Console Driver *
2324 ******************************************************************************/
2327 GuiDeinitFrontEnd(IN OUT PFRONTEND This
);
2330 GuiInitFrontEnd(IN OUT PFRONTEND This
,
2331 IN PCONSOLE Console
)
2333 PGUI_INIT_INFO GuiInitInfo
;
2334 PCONSOLE_INFO ConsoleInfo
;
2335 PCONSOLE_START_INFO ConsoleStartInfo
;
2337 PGUI_CONSOLE_DATA GuiData
;
2338 GUI_CONSOLE_INFO TermInfo
;
2341 LPWSTR IconPath
= NULL
;
2344 if (This
== NULL
|| Console
== NULL
|| This
->OldData
== NULL
)
2345 return STATUS_INVALID_PARAMETER
;
2347 ASSERT(This
->Console
== Console
);
2349 GuiInitInfo
= This
->OldData
;
2351 if (GuiInitInfo
->ConsoleInfo
== NULL
|| GuiInitInfo
->ConsoleStartInfo
== NULL
)
2352 return STATUS_INVALID_PARAMETER
;
2354 ConsoleInfo
= GuiInitInfo
->ConsoleInfo
;
2355 ConsoleStartInfo
= GuiInitInfo
->ConsoleStartInfo
;
2357 IconPath
= ConsoleStartInfo
->IconPath
;
2358 IconIndex
= ConsoleStartInfo
->IconIndex
;
2361 /* Terminal data allocation */
2362 GuiData
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_CONSOLE_DATA
));
2365 DPRINT1("CONSRV: Failed to create GUI_CONSOLE_DATA\n");
2366 return STATUS_UNSUCCESSFUL
;
2368 /* HACK */ Console
->TermIFace
.Data
= (PVOID
)GuiData
; /* HACK */
2369 GuiData
->Console
= Console
;
2370 GuiData
->ActiveBuffer
= Console
->ActiveBuffer
;
2371 GuiData
->hWindow
= NULL
;
2373 /* The console can be resized */
2374 Console
->FixedSize
= FALSE
;
2376 InitializeCriticalSection(&GuiData
->Lock
);
2380 * Load terminal settings
2383 /* 1. Load the default settings */
2384 GuiConsoleGetDefaultSettings(&TermInfo
, GuiInitInfo
->ProcessId
);
2386 /* 3. Load the remaining console settings via the registry. */
2387 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2389 /* Load the terminal infos from the registry. */
2390 GuiConsoleReadUserSettings(&TermInfo
,
2391 ConsoleInfo
->ConsoleTitle
,
2392 GuiInitInfo
->ProcessId
);
2395 * Now, update them with the properties the user might gave to us
2396 * via the STARTUPINFO structure before calling CreateProcess
2397 * (and which was transmitted via the ConsoleStartInfo structure).
2398 * We therefore overwrite the values read in the registry.
2400 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USESHOWWINDOW
)
2402 TermInfo
.ShowWindow
= ConsoleStartInfo
->wShowWindow
;
2404 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USEPOSITION
)
2406 TermInfo
.AutoPosition
= FALSE
;
2407 TermInfo
.WindowOrigin
.x
= ConsoleStartInfo
->dwWindowOrigin
.X
;
2408 TermInfo
.WindowOrigin
.y
= ConsoleStartInfo
->dwWindowOrigin
.Y
;
2410 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_RUNFULLSCREEN
)
2412 TermInfo
.FullScreen
= TRUE
;
2421 Length
= min(wcslen(TermInfo
.FaceName
) + 1, LF_FACESIZE
); // wcsnlen
2422 wcsncpy(GuiData
->GuiInfo
.FaceName
, TermInfo
.FaceName
, LF_FACESIZE
);
2423 GuiData
->GuiInfo
.FaceName
[Length
] = L
'\0';
2424 GuiData
->GuiInfo
.FontFamily
= TermInfo
.FontFamily
;
2425 GuiData
->GuiInfo
.FontSize
= TermInfo
.FontSize
;
2426 GuiData
->GuiInfo
.FontWeight
= TermInfo
.FontWeight
;
2427 GuiData
->GuiInfo
.UseRasterFonts
= TermInfo
.UseRasterFonts
;
2428 GuiData
->GuiInfo
.FullScreen
= TermInfo
.FullScreen
;
2429 GuiData
->GuiInfo
.ShowWindow
= TermInfo
.ShowWindow
;
2430 GuiData
->GuiInfo
.AutoPosition
= TermInfo
.AutoPosition
;
2431 GuiData
->GuiInfo
.WindowOrigin
= TermInfo
.WindowOrigin
;
2433 /* Initialize the icon handles to their default values */
2434 GuiData
->hIcon
= ghDefaultIcon
;
2435 GuiData
->hIconSm
= ghDefaultIconSm
;
2437 /* Get the associated icon, if any */
2438 if (IconPath
== NULL
|| IconPath
[0] == L
'\0')
2440 IconPath
= ConsoleStartInfo
->AppPath
;
2443 DPRINT("IconPath = %S ; IconIndex = %lu\n", (IconPath
? IconPath
: L
"n/a"), IconIndex
);
2444 if (IconPath
&& IconPath
[0] != L
'\0')
2446 HICON hIcon
= NULL
, hIconSm
= NULL
;
2447 PrivateExtractIconExW(IconPath
,
2452 DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon
, hIconSm
);
2455 DPRINT("Effectively set the icons\n");
2456 GuiData
->hIcon
= hIcon
;
2457 GuiData
->hIconSm
= hIconSm
;
2461 /* Mouse is shown by default with its default cursor shape */
2462 GuiData
->hCursor
= ghDefaultCursor
;
2463 GuiData
->MouseCursorRefCount
= 0;
2465 /* A priori don't ignore mouse signals */
2466 GuiData
->IgnoreNextMouseSignal
= FALSE
;
2468 /* Close button and the corresponding system menu item are enabled by default */
2469 GuiData
->IsCloseButtonEnabled
= TRUE
;
2471 /* There is no user-reserved menu id range by default */
2472 GuiData
->cmdIdLow
= GuiData
->cmdIdHigh
= 0;
2475 * We need to wait until the GUI has been fully initialized
2476 * to retrieve custom settings i.e. WindowSize etc...
2477 * Ideally we could use SendNotifyMessage for this but its not
2480 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2482 DPRINT("GUI - Checkpoint\n");
2484 /* Create the terminal window */
2485 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, GuiData
->GuiInfo
.ShowWindow
, (LPARAM
)GuiData
);
2487 /* Wait until initialization has finished */
2488 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
2489 DPRINT("OK we created the console window\n");
2490 CloseHandle(GuiData
->hGuiInitEvent
);
2491 GuiData
->hGuiInitEvent
= NULL
;
2493 /* Check whether we really succeeded in initializing the terminal window */
2494 if (GuiData
->hWindow
== NULL
)
2496 DPRINT("GuiInitConsole - We failed at creating a new terminal window\n");
2497 GuiDeinitFrontEnd(This
);
2498 return STATUS_UNSUCCESSFUL
;
2501 /* Finally, finish to initialize the frontend structure */
2502 This
->Data
= GuiData
;
2503 if (This
->OldData
) ConsoleFreeHeap(This
->OldData
);
2504 This
->OldData
= NULL
;
2506 return STATUS_SUCCESS
;
2510 GuiDeinitFrontEnd(IN OUT PFRONTEND This
)
2512 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2514 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
)GuiData
);
2516 DPRINT("Destroying icons !! - GuiData->hIcon = 0x%p ; ghDefaultIcon = 0x%p ; GuiData->hIconSm = 0x%p ; ghDefaultIconSm = 0x%p\n",
2517 GuiData
->hIcon
, ghDefaultIcon
, GuiData
->hIconSm
, ghDefaultIconSm
);
2518 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2520 DPRINT("Destroy hIcon\n");
2521 DestroyIcon(GuiData
->hIcon
);
2523 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2525 DPRINT("Destroy hIconSm\n");
2526 DestroyIcon(GuiData
->hIconSm
);
2530 DeleteCriticalSection(&GuiData
->Lock
);
2531 ConsoleFreeHeap(GuiData
);
2533 DPRINT("Quit GuiDeinitFrontEnd\n");
2537 GuiDrawRegion(IN OUT PFRONTEND This
,
2540 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2543 SmallRectToRect(GuiData
, &RegionRect
, Region
);
2544 /* Do not erase the background: it speeds up redrawing and reduce flickering */
2545 InvalidateRect(GuiData
->hWindow
, &RegionRect
, FALSE
);
2546 /**UpdateWindow(GuiData->hWindow);**/
2550 GuiWriteStream(IN OUT PFRONTEND This
,
2558 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2559 PCONSOLE_SCREEN_BUFFER Buff
;
2560 SHORT CursorEndX
, CursorEndY
;
2563 if (NULL
== GuiData
|| NULL
== GuiData
->hWindow
) return;
2565 Buff
= GuiData
->ActiveBuffer
;
2566 if (GetType(Buff
) != TEXTMODE_BUFFER
) return;
2568 if (0 != ScrolledLines
)
2570 ScrollRect
.left
= 0;
2572 ScrollRect
.right
= Buff
->ViewSize
.X
* GuiData
->CharWidth
;
2573 ScrollRect
.bottom
= Region
->Top
* GuiData
->CharHeight
;
2575 ScrollWindowEx(GuiData
->hWindow
,
2577 -(int)(ScrolledLines
* GuiData
->CharHeight
),
2585 GuiDrawRegion(This
, Region
);
2587 if (CursorStartX
< Region
->Left
|| Region
->Right
< CursorStartX
2588 || CursorStartY
< Region
->Top
|| Region
->Bottom
< CursorStartY
)
2590 GuiInvalidateCell(This
, CursorStartX
, CursorStartY
);
2593 CursorEndX
= Buff
->CursorPosition
.X
;
2594 CursorEndY
= Buff
->CursorPosition
.Y
;
2595 if ((CursorEndX
< Region
->Left
|| Region
->Right
< CursorEndX
2596 || CursorEndY
< Region
->Top
|| Region
->Bottom
< CursorEndY
)
2597 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
2599 GuiInvalidateCell(This
, CursorEndX
, CursorEndY
);
2602 // Set up the update timer (very short interval) - this is a "hack" for getting the OS to
2603 // repaint the window without having it just freeze up and stay on the screen permanently.
2604 Buff
->CursorBlinkOn
= TRUE
;
2605 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
2609 GuiSetCursorInfo(IN OUT PFRONTEND This
,
2610 PCONSOLE_SCREEN_BUFFER Buff
)
2612 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2614 if (GuiData
->ActiveBuffer
== Buff
)
2616 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2623 GuiSetScreenInfo(IN OUT PFRONTEND This
,
2624 PCONSOLE_SCREEN_BUFFER Buff
,
2628 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2630 if (GuiData
->ActiveBuffer
== Buff
)
2632 /* Redraw char at old position (remove cursor) */
2633 GuiInvalidateCell(This
, OldCursorX
, OldCursorY
);
2634 /* Redraw char at new position (show cursor) */
2635 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2642 GuiResizeTerminal(IN OUT PFRONTEND This
)
2644 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2646 /* Resize the window to the user's values */
2647 PostMessageW(GuiData
->hWindow
, PM_RESIZE_TERMINAL
, 0, 0);
2651 GuiSetActiveScreenBuffer(IN OUT PFRONTEND This
)
2653 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2654 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
2657 EnterCriticalSection(&GuiData
->Lock
);
2658 GuiData
->WindowSizeLock
= TRUE
;
2660 InterlockedExchangePointer(&GuiData
->ActiveBuffer
,
2661 ConDrvGetActiveScreenBuffer(GuiData
->Console
));
2663 GuiData
->WindowSizeLock
= FALSE
;
2664 LeaveCriticalSection(&GuiData
->Lock
);
2666 ActiveBuffer
= GuiData
->ActiveBuffer
;
2668 /* Change the current palette */
2669 if (ActiveBuffer
->PaletteHandle
== NULL
)
2671 hPalette
= GuiData
->hSysPalette
;
2675 hPalette
= ActiveBuffer
->PaletteHandle
;
2678 DPRINT1("GuiSetActiveScreenBuffer using palette 0x%p\n", hPalette
);
2680 /* Set the new palette for the framebuffer */
2681 SelectPalette(GuiData
->hMemDC
, hPalette
, FALSE
);
2683 /* Specify the use of the system palette for the framebuffer */
2684 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
2686 /* Realize the (logical) palette */
2687 RealizePalette(GuiData
->hMemDC
);
2689 GuiResizeTerminal(This
);
2690 // ConioDrawConsole(Console);
2694 GuiReleaseScreenBuffer(IN OUT PFRONTEND This
,
2695 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
)
2697 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2700 * If we were notified to release a screen buffer that is not actually
2701 * ours, then just ignore the notification...
2703 if (ScreenBuffer
!= GuiData
->ActiveBuffer
) return;
2706 * ... else, we must release our active buffer. Two cases are present:
2707 * - If ScreenBuffer (== GuiData->ActiveBuffer) IS NOT the console
2708 * active screen buffer, then we can safely switch to it.
2709 * - If ScreenBuffer IS the console active screen buffer, we must release
2713 /* Release the old active palette and set the default one */
2714 if (GetCurrentObject(GuiData
->hMemDC
, OBJ_PAL
) == ScreenBuffer
->PaletteHandle
)
2716 /* Set the new palette */
2717 SelectPalette(GuiData
->hMemDC
, GuiData
->hSysPalette
, FALSE
);
2720 /* Set the adequate active screen buffer */
2721 if (ScreenBuffer
!= GuiData
->Console
->ActiveBuffer
)
2723 GuiSetActiveScreenBuffer(This
);
2727 EnterCriticalSection(&GuiData
->Lock
);
2728 GuiData
->WindowSizeLock
= TRUE
;
2730 InterlockedExchangePointer(&GuiData
->ActiveBuffer
, NULL
);
2732 GuiData
->WindowSizeLock
= FALSE
;
2733 LeaveCriticalSection(&GuiData
->Lock
);
2738 GuiProcessKeyCallback(IN OUT PFRONTEND This
,
2742 UINT VirtualKeyCode
,
2745 if ((ShiftState
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
) || KeyStateMenu
& 0x80) &&
2746 (VirtualKeyCode
== VK_ESCAPE
|| VirtualKeyCode
== VK_TAB
|| VirtualKeyCode
== VK_SPACE
))
2748 DefWindowProcW(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2756 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2760 GuiRefreshInternalInfo(IN OUT PFRONTEND This
)
2762 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2764 /* Update the console leader information held by the window */
2765 SetConsoleWndConsoleLeaderCID(GuiData
);
2769 * We reset the cursor here so that, when a console app quits, we reset
2770 * the cursor to the default one. It's quite a hack since it doesn't proceed
2771 * per - console process... This must be fixed.
2773 * See GuiInitConsole(...) for more information.
2776 /* Mouse is shown by default with its default cursor shape */
2777 GuiData
->MouseCursorRefCount
= 0; // Reinitialize the reference counter
2778 GuiSetMouseCursor(This
, NULL
);
2782 GuiChangeTitle(IN OUT PFRONTEND This
)
2784 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2785 // PostMessageW(GuiData->hWindow, PM_CONSOLE_SET_TITLE, 0, 0);
2786 SetWindowText(GuiData
->hWindow
, GuiData
->Console
->Title
.Buffer
);
2790 GuiChangeIcon(IN OUT PFRONTEND This
,
2793 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2794 HICON hIcon
, hIconSm
;
2796 if (hWindowIcon
== NULL
)
2798 hIcon
= ghDefaultIcon
;
2799 hIconSm
= ghDefaultIconSm
;
2803 hIcon
= CopyIcon(hWindowIcon
);
2804 hIconSm
= CopyIcon(hWindowIcon
);
2812 if (hIcon
!= GuiData
->hIcon
)
2814 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2816 DestroyIcon(GuiData
->hIcon
);
2818 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2820 DestroyIcon(GuiData
->hIconSm
);
2823 GuiData
->hIcon
= hIcon
;
2824 GuiData
->hIconSm
= hIconSm
;
2826 DPRINT("Set icons in GuiChangeIcon\n");
2827 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2828 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2835 GuiGetConsoleWindowHandle(IN OUT PFRONTEND This
)
2837 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2838 return GuiData
->hWindow
;
2842 GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This
,
2845 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2846 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
2849 UINT WidthUnit
, HeightUnit
;
2853 if (!SystemParametersInfoW(SPI_GETWORKAREA
, 0, &WorkArea
, 0))
2855 DPRINT1("SystemParametersInfoW failed - What to do ??\n");
2859 ActiveBuffer
= GuiData
->ActiveBuffer
;
2862 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
2866 /* Default: text mode */
2867 WidthUnit
= GuiData
->CharWidth
;
2868 HeightUnit
= GuiData
->CharHeight
;
2871 width
= WorkArea
.right
;
2872 height
= WorkArea
.bottom
;
2874 width
-= (2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
)));
2875 height
-= (2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
));
2877 if (width
< 0) width
= 0;
2878 if (height
< 0) height
= 0;
2880 pSize
->X
= (SHORT
)(width
/ (int)WidthUnit
) /* HACK */ + 2;
2881 pSize
->Y
= (SHORT
)(height
/ (int)HeightUnit
) /* HACK */ + 1;
2885 GuiSetPalette(IN OUT PFRONTEND This
,
2886 HPALETTE PaletteHandle
,
2889 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2890 HPALETTE OldPalette
;
2892 // if (GetType(GuiData->ActiveBuffer) != GRAPHICS_BUFFER) return FALSE;
2893 if (PaletteHandle
== NULL
) return FALSE
;
2895 /* Set the new palette for the framebuffer */
2896 OldPalette
= SelectPalette(GuiData
->hMemDC
, PaletteHandle
, FALSE
);
2897 if (OldPalette
== NULL
) return FALSE
;
2899 /* Specify the use of the system palette for the framebuffer */
2900 SetSystemPaletteUse(GuiData
->hMemDC
, PaletteUsage
);
2902 /* Realize the (logical) palette */
2903 RealizePalette(GuiData
->hMemDC
);
2905 /* Save the original system palette handle */
2906 if (GuiData
->hSysPalette
== NULL
) GuiData
->hSysPalette
= OldPalette
;
2912 GuiGetDisplayMode(IN OUT PFRONTEND This
)
2914 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2915 ULONG DisplayMode
= 0;
2917 if (GuiData
->GuiInfo
.FullScreen
)
2918 DisplayMode
|= CONSOLE_FULLSCREEN_HARDWARE
; // CONSOLE_FULLSCREEN
2920 DisplayMode
|= CONSOLE_WINDOWED
;
2926 GuiSetDisplayMode(IN OUT PFRONTEND This
,
2929 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2932 if (NewMode
& ~(CONSOLE_FULLSCREEN_MODE
| CONSOLE_WINDOWED_MODE
))
2935 FullScreen
= ((NewMode
& CONSOLE_FULLSCREEN_MODE
) != 0);
2937 if (FullScreen
!= GuiData
->GuiInfo
.FullScreen
)
2939 SwitchFullScreen(GuiData
, FullScreen
);
2946 GuiShowMouseCursor(IN OUT PFRONTEND This
,
2949 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2951 /* Set the reference count */
2952 if (Show
) ++GuiData
->MouseCursorRefCount
;
2953 else --GuiData
->MouseCursorRefCount
;
2955 /* Effectively show (or hide) the cursor (use special values for (w|l)Param) */
2956 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2958 return GuiData
->MouseCursorRefCount
;
2962 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2965 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2968 * Set the cursor's handle. If the given handle is NULL,
2969 * then restore the default cursor.
2971 GuiData
->hCursor
= (hCursor
? hCursor
: ghDefaultCursor
);
2973 /* Effectively modify the shape of the cursor (use special values for (w|l)Param) */
2974 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2980 GuiMenuControl(IN OUT PFRONTEND This
,
2984 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2986 GuiData
->cmdIdLow
= cmdIdLow
;
2987 GuiData
->cmdIdHigh
= cmdIdHigh
;
2989 return GetSystemMenu(GuiData
->hWindow
, FALSE
);
2993 GuiSetMenuClose(IN OUT PFRONTEND This
,
2997 * NOTE: See http://www.mail-archive.com/harbour@harbour-project.org/msg27509.html
2998 * or http://harbour-devel.1590103.n2.nabble.com/Question-about-hb-gt-win-CtrlHandler-usage-td4670862i20.html
2999 * for more information.
3002 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
3003 HMENU hSysMenu
= GetSystemMenu(GuiData
->hWindow
, FALSE
);
3005 if (hSysMenu
== NULL
) return FALSE
;
3007 GuiData
->IsCloseButtonEnabled
= Enable
;
3008 EnableMenuItem(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| (Enable
? MF_ENABLED
: MF_GRAYED
));
3013 static FRONTEND_VTBL GuiVtbl
=
3022 GuiSetActiveScreenBuffer
,
3023 GuiReleaseScreenBuffer
,
3024 GuiProcessKeyCallback
,
3025 GuiRefreshInternalInfo
,
3028 GuiGetConsoleWindowHandle
,
3029 GuiGetLargestConsoleWindowSize
,
3041 LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo
,
3042 IN OUT PCONSOLE_INFO ConsoleInfo
)
3044 #define PATH_SEPARATOR L'\\'
3046 BOOL RetVal
= FALSE
;
3047 HRESULT hRes
= S_OK
;
3048 LPWSTR LinkName
= NULL
;
3051 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
3054 ConsoleStartInfo
->IconPath
[0] = L
'\0';
3055 ConsoleStartInfo
->IconIndex
= 0;
3057 /* 1- Find the last path separator if any */
3058 LinkName
= wcsrchr(ConsoleStartInfo
->ConsoleTitle
, PATH_SEPARATOR
);
3059 if (LinkName
== NULL
)
3061 LinkName
= ConsoleStartInfo
->ConsoleTitle
;
3065 /* Skip the path separator */
3069 /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
3070 Length
= wcslen(LinkName
);
3071 if ( (Length
<= 4) || (wcsicmp(LinkName
+ (Length
- 4), L
".lnk") != 0) )
3074 /* 3- It may be a link. Try to retrieve some properties */
3075 hRes
= CoInitialize(NULL
);
3076 if (SUCCEEDED(hRes
))
3078 /* Get a pointer to the IShellLink interface */
3079 IShellLinkW
* pshl
= NULL
;
3080 hRes
= CoCreateInstance(&CLSID_ShellLink
,
3082 CLSCTX_INPROC_SERVER
,
3085 if (SUCCEEDED(hRes
))
3087 /* Get a pointer to the IPersistFile interface */
3088 IPersistFile
* ppf
= NULL
;
3089 hRes
= IPersistFile_QueryInterface(pshl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
3090 if (SUCCEEDED(hRes
))
3092 /* Load the shortcut */
3093 hRes
= IPersistFile_Load(ppf
, ConsoleStartInfo
->ConsoleTitle
, STGM_READ
);
3094 if (SUCCEEDED(hRes
))
3097 * Finally we can get the properties !
3098 * Update the old ones if needed.
3103 /* Reset the name of the console with the name of the shortcut */
3104 Length
= min(/*Length*/ Length
- 4, // 4 == len(".lnk")
3105 sizeof(ConsoleInfo
->ConsoleTitle
) / sizeof(ConsoleInfo
->ConsoleTitle
[0]) - 1);
3106 wcsncpy(ConsoleInfo
->ConsoleTitle
, LinkName
, Length
);
3107 ConsoleInfo
->ConsoleTitle
[Length
] = L
'\0';
3109 /* Get the window showing command */
3110 hRes
= IShellLinkW_GetShowCmd(pshl
, &ShowCmd
);
3111 if (SUCCEEDED(hRes
)) ConsoleStartInfo
->wShowWindow
= (WORD
)ShowCmd
;
3113 /* Get the hotkey */
3114 // hRes = pshl->GetHotkey(&ShowCmd);
3115 // if (SUCCEEDED(hRes)) ConsoleStartInfo->HotKey = HotKey;
3117 /* Get the icon location, if any */
3119 hRes
= IShellLinkW_GetIconLocation(pshl
,
3120 ConsoleStartInfo
->IconPath
,
3121 sizeof(ConsoleStartInfo
->IconPath
)/sizeof(ConsoleStartInfo
->IconPath
[0]) - 1, // == MAX_PATH
3122 &ConsoleStartInfo
->IconIndex
);
3123 if (!SUCCEEDED(hRes
))
3125 ConsoleStartInfo
->IconPath
[0] = L
'\0';
3126 ConsoleStartInfo
->IconIndex
= 0;
3129 // FIXME: Since we still don't load console properties from the shortcut,
3130 // return false. When this will be done, we will return true instead.
3133 IPersistFile_Release(ppf
);
3135 IShellLinkW_Release(pshl
);
3144 GuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd
,
3145 IN OUT PCONSOLE_INFO ConsoleInfo
,
3146 IN OUT PVOID ExtraConsoleInfo
,
3149 PCONSOLE_START_INFO ConsoleStartInfo
= ExtraConsoleInfo
;
3150 PGUI_INIT_INFO GuiInitInfo
;
3152 if (FrontEnd
== NULL
|| ConsoleInfo
== NULL
|| ConsoleStartInfo
== NULL
)
3153 return STATUS_INVALID_PARAMETER
;
3155 /* Initialize GUI terminal emulator common functionalities */
3156 if (!GuiInit()) return STATUS_UNSUCCESSFUL
;
3159 * Load per-application terminal settings.
3161 * Check whether the process creating the console was launched via
3162 * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
3163 * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
3165 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
)
3167 if (!LoadShellLinkConsoleInfo(ConsoleStartInfo
, ConsoleInfo
))
3169 ConsoleStartInfo
->dwStartupFlags
&= ~STARTF_TITLEISLINKNAME
;
3174 * Initialize a private initialization info structure for later use.
3175 * It must be freed by a call to GuiUnloadFrontEnd or GuiInitFrontEnd.
3177 GuiInitInfo
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_INIT_INFO
));
3178 if (GuiInitInfo
== NULL
) return STATUS_NO_MEMORY
;
3180 // HACK: We suppose that the pointers will be valid in GuiInitFrontEnd...
3181 GuiInitInfo
->ConsoleInfo
= ConsoleInfo
;
3182 GuiInitInfo
->ConsoleStartInfo
= ConsoleStartInfo
;
3183 GuiInitInfo
->ProcessId
= ProcessId
;
3185 /* Finally, initialize the frontend structure */
3186 FrontEnd
->Vtbl
= &GuiVtbl
;
3187 FrontEnd
->Data
= NULL
;
3188 FrontEnd
->OldData
= GuiInitInfo
;
3190 return STATUS_SUCCESS
;
3194 GuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd
)
3196 if (FrontEnd
== NULL
) return STATUS_INVALID_PARAMETER
;
3198 if (FrontEnd
->Data
) GuiDeinitFrontEnd(FrontEnd
);
3199 if (FrontEnd
->OldData
) ConsoleFreeHeap(FrontEnd
->OldData
);
3201 return STATUS_SUCCESS
;