2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: frontends/gui/conwnd.c
5 * PURPOSE: GUI Console Window Class
6 * PROGRAMMERS: Gé van Geldorp
9 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
12 /* INCLUDES *******************************************************************/
25 /* GLOBALS ********************************************************************/
27 // #define PM_CREATE_CONSOLE (WM_APP + 1)
28 // #define PM_DESTROY_CONSOLE (WM_APP + 2)
31 #define CONGUI_MIN_WIDTH 10
32 #define CONGUI_MIN_HEIGHT 10
33 #define CONGUI_UPDATE_TIME 0
34 #define CONGUI_UPDATE_TIMER 1
36 #define CURSOR_BLINK_TIME 500
39 /**************************************************************\
40 \** Define the Console Leader Process for the console window **/
41 #define GWLP_CONWND_ALLOC (2 * sizeof(LONG_PTR))
42 #define GWLP_CONSOLE_LEADER_PID 0
43 #define GWLP_CONSOLE_LEADER_TID 4
46 SetConWndConsoleLeaderCID(IN PGUI_CONSOLE_DATA GuiData
)
48 PCONSOLE_PROCESS_DATA ProcessData
;
49 CLIENT_ID ConsoleLeaderCID
;
51 ProcessData
= ConDrvGetConsoleLeaderProcess(GuiData
->Console
);
52 ConsoleLeaderCID
= ProcessData
->Process
->ClientId
;
53 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_CONSOLE_LEADER_PID
,
54 (LONG_PTR
)(ConsoleLeaderCID
.UniqueProcess
));
55 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_CONSOLE_LEADER_TID
,
56 (LONG_PTR
)(ConsoleLeaderCID
.UniqueThread
));
58 /**************************************************************/
60 HICON ghDefaultIcon
= NULL
;
61 HICON ghDefaultIconSm
= NULL
;
62 HCURSOR ghDefaultCursor
= NULL
;
64 typedef struct _GUICONSOLE_MENUITEM
67 const struct _GUICONSOLE_MENUITEM
*SubMenu
;
69 } GUICONSOLE_MENUITEM
, *PGUICONSOLE_MENUITEM
;
71 static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems
[] =
73 { IDS_MARK
, NULL
, ID_SYSTEM_EDIT_MARK
},
74 { IDS_COPY
, NULL
, ID_SYSTEM_EDIT_COPY
},
75 { IDS_PASTE
, NULL
, ID_SYSTEM_EDIT_PASTE
},
76 { IDS_SELECTALL
, NULL
, ID_SYSTEM_EDIT_SELECTALL
},
77 { IDS_SCROLL
, NULL
, ID_SYSTEM_EDIT_SCROLL
},
78 { IDS_FIND
, NULL
, ID_SYSTEM_EDIT_FIND
},
80 { 0, NULL
, 0 } /* End of list */
83 static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems
[] =
85 { IDS_EDIT
, GuiConsoleEditMenuItems
, 0 },
86 { IDS_DEFAULTS
, NULL
, ID_SYSTEM_DEFAULTS
},
87 { IDS_PROPERTIES
, NULL
, ID_SYSTEM_PROPERTIES
},
89 { 0, NULL
, 0 } /* End of list */
93 * Default 16-color palette for foreground and background
94 * (corresponding flags in comments).
96 const COLORREF s_Colors
[16] =
98 RGB(0, 0, 0), // (Black)
99 RGB(0, 0, 128), // BLUE
100 RGB(0, 128, 0), // GREEN
101 RGB(0, 128, 128), // BLUE | GREEN
102 RGB(128, 0, 0), // RED
103 RGB(128, 0, 128), // BLUE | RED
104 RGB(128, 128, 0), // GREEN | RED
105 RGB(192, 192, 192), // BLUE | GREEN | RED
107 RGB(128, 128, 128), // (Grey) INTENSITY
108 RGB(0, 0, 255), // BLUE | INTENSITY
109 RGB(0, 255, 0), // GREEN | INTENSITY
110 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
111 RGB(255, 0, 0), // RED | INTENSITY
112 RGB(255, 0, 255), // BLUE | RED | INTENSITY
113 RGB(255, 255, 0), // GREEN | RED | INTENSITY
114 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
117 /* FUNCTIONS ******************************************************************/
119 static LRESULT CALLBACK
120 ConWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
123 RegisterConWndClass(IN HINSTANCE hInstance
)
125 WNDCLASSEXW WndClass
;
128 ghDefaultIcon
= LoadImageW(hInstance
,
129 MAKEINTRESOURCEW(IDI_TERMINAL
),
131 GetSystemMetrics(SM_CXICON
),
132 GetSystemMetrics(SM_CYICON
),
134 ghDefaultIconSm
= LoadImageW(hInstance
,
135 MAKEINTRESOURCEW(IDI_TERMINAL
),
137 GetSystemMetrics(SM_CXSMICON
),
138 GetSystemMetrics(SM_CYSMICON
),
140 ghDefaultCursor
= LoadCursorW(NULL
, IDC_ARROW
);
142 WndClass
.cbSize
= sizeof(WNDCLASSEXW
);
143 WndClass
.lpszClassName
= GUI_CONWND_CLASS
;
144 WndClass
.lpfnWndProc
= ConWndProc
;
145 WndClass
.style
= CS_DBLCLKS
/* | CS_HREDRAW | CS_VREDRAW */;
146 WndClass
.hInstance
= hInstance
;
147 WndClass
.hIcon
= ghDefaultIcon
;
148 WndClass
.hIconSm
= ghDefaultIconSm
;
149 WndClass
.hCursor
= ghDefaultCursor
;
150 WndClass
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
); // The color of a terminal when it is switched off.
151 WndClass
.lpszMenuName
= NULL
;
152 WndClass
.cbClsExtra
= 0;
153 WndClass
.cbWndExtra
= GWLP_CONWND_ALLOC
;
155 WndClassAtom
= RegisterClassExW(&WndClass
);
156 if (WndClassAtom
== 0)
158 DPRINT1("Failed to register GUI console class\n");
162 NtUserConsoleControl(GuiConsoleWndClassAtom
, &WndClassAtom
, sizeof(ATOM
));
165 return (WndClassAtom
!= 0);
169 UnRegisterConWndClass(HINSTANCE hInstance
)
171 return !!UnregisterClassW(GUI_CONWND_CLASS
, hInstance
);
177 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer
,
178 IN PGUI_CONSOLE_DATA GuiData
,
180 OUT PUINT HeightUnit
)
182 if (Buffer
== NULL
|| GuiData
== NULL
||
183 WidthUnit
== NULL
|| HeightUnit
== NULL
)
188 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
190 *WidthUnit
= GuiData
->CharWidth
;
191 *HeightUnit
= GuiData
->CharHeight
;
193 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
201 AppendMenuItems(HMENU hMenu
,
202 const GUICONSOLE_MENUITEM
*Items
)
205 WCHAR szMenuString
[255];
210 if (Items
[i
].uID
!= (UINT
)-1)
212 if (LoadStringW(ConSrvDllInstance
,
215 sizeof(szMenuString
) / sizeof(szMenuString
[0])) > 0)
217 if (Items
[i
].SubMenu
!= NULL
)
219 hSubMenu
= CreatePopupMenu();
220 if (hSubMenu
!= NULL
)
222 AppendMenuItems(hSubMenu
, Items
[i
].SubMenu
);
224 if (!AppendMenuW(hMenu
,
225 MF_STRING
| MF_POPUP
,
229 DestroyMenu(hSubMenu
);
250 } while (!(Items
[i
].uID
== 0 && Items
[i
].SubMenu
== NULL
&& Items
[i
].wCmdID
== 0));
254 CreateSysMenu(HWND hWnd
)
257 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
260 mii
.cbSize
= sizeof(mii
);
261 mii
.fMask
= MIIM_STRING
;
262 mii
.dwTypeData
= L
"&Close";
263 SetMenuItemInfoW(hMenu
, SC_CLOSE
, FALSE
, &mii
);
265 AppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
271 SendMenuEvent(PCONSOLE Console
, UINT CmdId
)
275 DPRINT1("Menu item ID: %d\n", CmdId
);
277 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
279 er
.EventType
= MENU_EVENT
;
280 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
281 ConioProcessInputEvent(Console
, &er
);
283 LeaveCriticalSection(&Console
->Lock
);
287 Copy(PGUI_CONSOLE_DATA GuiData
);
289 Paste(PGUI_CONSOLE_DATA GuiData
);
291 UpdateSelection(PGUI_CONSOLE_DATA GuiData
, PCOORD coord
);
294 Mark(PGUI_CONSOLE_DATA GuiData
)
296 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
298 /* Clear the old selection */
299 // UpdateSelection(GuiData, NULL);
300 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
302 /* Restart a new selection */
303 GuiData
->dwSelectionCursor
.X
= ActiveBuffer
->ViewOrigin
.X
;
304 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewOrigin
.Y
;
305 GuiData
->Selection
.dwSelectionAnchor
= GuiData
->dwSelectionCursor
;
306 UpdateSelection(GuiData
, &GuiData
->Selection
.dwSelectionAnchor
);
310 SelectAll(PGUI_CONSOLE_DATA GuiData
)
312 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
314 /* Clear the old selection */
315 // UpdateSelection(GuiData, NULL);
316 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
319 * The selection area extends to the whole screen buffer's width.
321 GuiData
->Selection
.dwSelectionAnchor
.X
= 0;
322 GuiData
->Selection
.dwSelectionAnchor
.Y
= 0;
323 GuiData
->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 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->CursorPosition
.Y
;
338 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
341 * We select all the screen buffer area.
343 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
346 /* Restart a new selection */
347 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
;
348 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
352 OnCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
355 PCONSOLE Console
= GuiData
->Console
;
358 * In case the selected menu item belongs to the user-reserved menu id range,
359 * send to him a menu event and return directly. The user must handle those
360 * reserved menu commands...
362 if (GuiData
->CmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->CmdIdHigh
)
364 SendMenuEvent(Console
, (UINT
)wParam
);
368 /* ... otherwise, perform actions. */
371 case ID_SYSTEM_EDIT_MARK
:
375 case ID_SYSTEM_EDIT_COPY
:
379 case ID_SYSTEM_EDIT_PASTE
:
383 case ID_SYSTEM_EDIT_SELECTALL
:
387 case ID_SYSTEM_EDIT_SCROLL
:
388 DPRINT1("Scrolling is not handled yet\n");
391 case ID_SYSTEM_EDIT_FIND
:
392 DPRINT1("Finding is not handled yet\n");
395 case ID_SYSTEM_DEFAULTS
:
396 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
399 case ID_SYSTEM_PROPERTIES
:
400 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
410 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
415 static PGUI_CONSOLE_DATA
416 GuiGetGuiData(HWND hWnd
)
418 /* This function ensures that the console pointer is not NULL */
419 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
420 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
424 ResizeConWnd(PGUI_CONSOLE_DATA GuiData
, DWORD WidthUnit
, DWORD HeightUnit
)
426 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
431 Width
= Buff
->ViewSize
.X
* WidthUnit
+
432 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
433 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
434 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
436 /* Set scrollbar sizes */
437 sInfo
.cbSize
= sizeof(SCROLLINFO
);
438 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
440 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
442 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
443 sInfo
.nPage
= Buff
->ViewSize
.Y
;
444 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
445 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
446 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
447 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
451 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
454 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
456 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
457 sInfo
.nPage
= Buff
->ViewSize
.X
;
458 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
459 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
460 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
461 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
465 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
468 /* Resize the window */
469 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
470 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
471 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
472 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
476 OnNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
478 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
487 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
491 Console
= GuiData
->Console
;
493 GuiData
->hWindow
= hWnd
;
495 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->GuiInfo
.FontSize
),
496 0, // HIWORD(GuiData->GuiInfo.FontSize),
499 GuiData
->GuiInfo
.FontWeight
,
506 NONANTIALIASED_QUALITY
,
507 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
508 GuiData
->GuiInfo
.FaceName
);
510 if (NULL
== GuiData
->Font
)
512 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
513 GuiData
->hWindow
= NULL
;
514 SetEvent(GuiData
->hGuiInitEvent
);
517 hDC
= GetDC(GuiData
->hWindow
);
520 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
521 DeleteObject(GuiData
->Font
);
522 GuiData
->hWindow
= NULL
;
523 SetEvent(GuiData
->hGuiInitEvent
);
526 OldFont
= SelectObject(hDC
, GuiData
->Font
);
529 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
530 ReleaseDC(GuiData
->hWindow
, hDC
);
531 DeleteObject(GuiData
->Font
);
532 GuiData
->hWindow
= NULL
;
533 SetEvent(GuiData
->hGuiInitEvent
);
536 if (!GetTextMetricsW(hDC
, &Metrics
))
538 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
539 SelectObject(hDC
, OldFont
);
540 ReleaseDC(GuiData
->hWindow
, hDC
);
541 DeleteObject(GuiData
->Font
);
542 GuiData
->hWindow
= NULL
;
543 SetEvent(GuiData
->hGuiInitEvent
);
546 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
547 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
549 /* Measure real char width more precisely if possible. */
550 if (GetTextExtentPoint32W(hDC
, L
"R", 1, &CharSize
))
551 GuiData
->CharWidth
= CharSize
.cx
;
553 SelectObject(hDC
, OldFont
);
555 ReleaseDC(GuiData
->hWindow
, hDC
);
557 /* Initialize the terminal framebuffer */
558 GuiData
->hMemDC
= CreateCompatibleDC(NULL
);
559 GuiData
->hBitmap
= NULL
;
560 GuiData
->hSysPalette
= NULL
; /* Original system palette */
562 /* Update the icons of the window */
563 if (GuiData
->hIcon
!= ghDefaultIcon
)
565 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
566 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
569 // FIXME: Keep these instructions here ? ///////////////////////////////////
570 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
571 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
572 ////////////////////////////////////////////////////////////////////////////
574 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
576 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
577 CreateSysMenu(GuiData
->hWindow
);
579 DPRINT("OnNcCreate - setting start event\n");
580 SetEvent(GuiData
->hGuiInitEvent
);
582 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
587 EnterFullScreen(PGUI_CONSOLE_DATA GuiData
);
589 LeaveFullScreen(PGUI_CONSOLE_DATA GuiData
);
591 SwitchFullScreen(PGUI_CONSOLE_DATA GuiData
, BOOL FullScreen
);
593 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
);
596 OnActivate(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
)
598 PCONSOLE Console
= GuiData
->Console
;
599 WORD ActivationState
= LOWORD(wParam
);
601 DPRINT1("WM_ACTIVATE - ActivationState = %d\n");
603 if ( ActivationState
== WA_ACTIVE
||
604 ActivationState
== WA_CLICKACTIVE
)
606 if (GuiData
->GuiInfo
.FullScreen
)
608 EnterFullScreen(GuiData
);
609 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
610 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
613 else // if (ActivationState == WA_INACTIVE)
615 if (GuiData
->GuiInfo
.FullScreen
)
617 SendMessageW(GuiData
->hWindow
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
618 LeaveFullScreen(GuiData
);
619 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
620 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
625 * When we are in QuickEdit mode, ignore the next mouse signal
626 * when we are going to be enabled again via the mouse, in order
627 * to prevent e.g. an erroneous right-click from the user which
628 * would have as an effect to paste some unwanted text...
630 if (Console
->QuickEdit
&& (ActivationState
== WA_CLICKACTIVE
))
631 GuiData
->IgnoreNextMouseSignal
= TRUE
;
635 OnFocus(PGUI_CONSOLE_DATA GuiData
, BOOL SetFocus
)
637 PCONSOLE Console
= GuiData
->Console
;
640 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
642 er
.EventType
= FOCUS_EVENT
;
643 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
644 ConioProcessInputEvent(Console
, &er
);
646 LeaveCriticalSection(&Console
->Lock
);
649 DPRINT1("TODO: Create console caret\n");
651 DPRINT1("TODO: Destroy console caret\n");
655 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
657 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
658 UINT WidthUnit
, HeightUnit
;
660 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
662 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
663 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
664 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
665 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
669 UpdateSelection(PGUI_CONSOLE_DATA GuiData
, PCOORD coord
)
671 PCONSOLE Console
= GuiData
->Console
;
674 SmallRectToRect(GuiData
, &oldRect
, &GuiData
->Selection
.srSelection
);
681 /* Exchange left/top with right/bottom if required */
682 rc
.Left
= min(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
683 rc
.Top
= min(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
684 rc
.Right
= max(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
685 rc
.Bottom
= max(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
687 SmallRectToRect(GuiData
, &newRect
, &rc
);
689 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
691 if (memcmp(&rc
, &GuiData
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
695 /* Calculate the region that needs to be updated */
696 if ((rgn1
= CreateRectRgnIndirect(&oldRect
)))
698 if ((rgn2
= CreateRectRgnIndirect(&newRect
)))
700 if (CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
702 InvalidateRgn(GuiData
->hWindow
, rgn1
, FALSE
);
712 InvalidateRect(GuiData
->hWindow
, &newRect
, FALSE
);
715 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
716 GuiData
->Selection
.srSelection
= rc
;
717 GuiData
->dwSelectionCursor
= *coord
;
719 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
721 LPWSTR SelectionType
, WindowTitle
= NULL
;
724 /* Clear the old selection */
725 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
727 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
730 if (GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
)
732 SelectionType
= L
"Selection - ";
736 SelectionType
= L
"Mark - ";
739 Length
= Console
->Title
.Length
+ wcslen(SelectionType
) + 1;
740 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
741 wcscpy(WindowTitle
, SelectionType
);
742 wcscat(WindowTitle
, Console
->Title
.Buffer
);
743 SetWindowText(GuiData
->hWindow
, WindowTitle
);
744 ConsoleFreeHeap(WindowTitle
);
746 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
747 ConioPause(Console
, PAUSED_FROM_SELECTION
);
752 /* Clear the selection */
753 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
755 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
758 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
759 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
761 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
767 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
768 PGUI_CONSOLE_DATA GuiData
,
770 PRECT rcFramebuffer
);
772 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
773 PGUI_CONSOLE_DATA GuiData
,
775 PRECT rcFramebuffer
);
778 OnPaint(PGUI_CONSOLE_DATA GuiData
)
780 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
784 ActiveBuffer
= GuiData
->ActiveBuffer
;
786 BeginPaint(GuiData
->hWindow
, &ps
);
787 if (ps
.hdc
!= NULL
&&
788 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
789 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
791 EnterCriticalSection(&GuiData
->Lock
);
793 /* Compose the current screen-buffer on-memory */
794 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
796 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
797 GuiData
, &ps
.rcPaint
, &rcPaint
);
799 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
801 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
802 GuiData
, &ps
.rcPaint
, &rcPaint
);
805 /* Send it to screen */
809 rcPaint
.right
- rcPaint
.left
,
810 rcPaint
.bottom
- rcPaint
.top
,
816 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
818 SmallRectToRect(GuiData
, &rcPaint
, &GuiData
->Selection
.srSelection
);
820 /* Invert the selection */
821 if (IntersectRect(&rcPaint
, &ps
.rcPaint
, &rcPaint
))
823 InvertRect(ps
.hdc
, &rcPaint
);
827 LeaveCriticalSection(&GuiData
->Lock
);
829 EndPaint(GuiData
->hWindow
, &ps
);
835 OnPaletteChanged(PGUI_CONSOLE_DATA GuiData
)
837 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
839 // See WM_PALETTECHANGED message
840 // if ((HWND)wParam == hWnd) break;
842 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
843 if (ActiveBuffer
->PaletteHandle
)
845 DPRINT("WM_PALETTECHANGED changing palette\n");
847 /* Specify the use of the system palette for the framebuffer */
848 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
850 /* Realize the (logical) palette */
851 RealizePalette(GuiData
->hMemDC
);
856 IsSystemKey(WORD VirtualKeyCode
)
858 switch (VirtualKeyCode
)
860 /* From MSDN, "Virtual-Key Codes" */
879 OnKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
881 PCONSOLE Console
= GuiData
->Console
;
882 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
884 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
886 ActiveBuffer
= GuiData
->ActiveBuffer
;
888 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
890 WORD VirtualKeyCode
= LOWORD(wParam
);
892 if (msg
!= WM_KEYDOWN
) goto Quit
;
894 if (VirtualKeyCode
== VK_RETURN
)
896 /* Copy (and clear) selection if ENTER is pressed */
900 else if ( VirtualKeyCode
== VK_ESCAPE
||
901 (VirtualKeyCode
== 'C' && GetKeyState(VK_CONTROL
) & 0x8000) )
903 /* Cancel selection if ESC or Ctrl-C are pressed */
904 UpdateSelection(GuiData
, NULL
);
908 if ((GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
910 /* Keyboard selection mode */
911 BOOL Interpreted
= FALSE
;
912 BOOL MajPressed
= (GetKeyState(VK_SHIFT
) & 0x8000);
914 switch (VirtualKeyCode
)
919 if (GuiData
->dwSelectionCursor
.X
> 0)
920 GuiData
->dwSelectionCursor
.X
--;
928 if (GuiData
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
929 GuiData
->dwSelectionCursor
.X
++;
937 if (GuiData
->dwSelectionCursor
.Y
> 0)
938 GuiData
->dwSelectionCursor
.Y
--;
946 if (GuiData
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
947 GuiData
->dwSelectionCursor
.Y
++;
955 GuiData
->dwSelectionCursor
.X
= 0;
956 GuiData
->dwSelectionCursor
.Y
= 0;
963 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
970 GuiData
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
971 if (GuiData
->dwSelectionCursor
.Y
< 0)
972 GuiData
->dwSelectionCursor
.Y
= 0;
980 GuiData
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
981 if (GuiData
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
982 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
994 GuiData
->Selection
.dwSelectionAnchor
= GuiData
->dwSelectionCursor
;
996 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
998 else if (!IsSystemKey(VirtualKeyCode
))
1000 /* Emit an error beep sound */
1001 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
1008 /* Mouse selection mode */
1010 if (!IsSystemKey(VirtualKeyCode
))
1012 /* Clear the selection and send the key into the input buffer */
1013 UpdateSelection(GuiData
, NULL
);
1022 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
1026 Message
.hwnd
= GuiData
->hWindow
;
1027 Message
.message
= msg
;
1028 Message
.wParam
= wParam
;
1029 Message
.lParam
= lParam
;
1031 ConioProcessKey(Console
, &Message
);
1035 LeaveCriticalSection(&Console
->Lock
);
1039 // FIXME: Remove after fixing OnTimer
1041 InvalidateCell(PGUI_CONSOLE_DATA GuiData
,
1045 OnTimer(PGUI_CONSOLE_DATA GuiData
)
1047 PCONSOLE Console
= GuiData
->Console
;
1048 PCONSOLE_SCREEN_BUFFER Buff
;
1050 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
1052 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1054 Buff
= GuiData
->ActiveBuffer
;
1056 if (GetType(Buff
) == TEXTMODE_BUFFER
)
1058 InvalidateCell(GuiData
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
1059 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
1061 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) ||
1062 (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
1065 int OldScrollX
= -1, OldScrollY
= -1;
1066 int NewScrollX
= -1, NewScrollY
= -1;
1068 xScroll
.cbSize
= sizeof(SCROLLINFO
);
1069 xScroll
.fMask
= SIF_POS
;
1070 // Capture the original position of the scroll bars and save them.
1071 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
1072 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
1074 // If we successfully got the info for the horizontal scrollbar
1075 if (OldScrollX
>= 0)
1077 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) ||
1078 (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
1080 // Handle the horizontal scroll bar
1081 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
)
1082 NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
1088 NewScrollX
= OldScrollX
;
1091 // If we successfully got the info for the vertical scrollbar
1092 if (OldScrollY
>= 0)
1094 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) ||
1095 (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
1097 // Handle the vertical scroll bar
1098 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
)
1099 NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
1105 NewScrollY
= OldScrollY
;
1109 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1110 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1111 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1112 // and their associated scrollbar is left alone.
1113 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
1115 Buff
->ViewOrigin
.X
= NewScrollX
;
1116 Buff
->ViewOrigin
.Y
= NewScrollY
;
1117 ScrollWindowEx(GuiData
->hWindow
,
1118 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
1119 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1125 if (NewScrollX
>= 0)
1127 xScroll
.nPos
= NewScrollX
;
1128 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1130 if (NewScrollY
>= 0)
1132 xScroll
.nPos
= NewScrollY
;
1133 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1135 UpdateWindow(GuiData
->hWindow
);
1136 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1137 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1138 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1142 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1146 LeaveCriticalSection(&Console
->Lock
);
1150 OnClose(PGUI_CONSOLE_DATA GuiData
)
1152 PCONSOLE Console
= GuiData
->Console
;
1154 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1157 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1160 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1161 * We shouldn't wait here, though, since the console lock is entered.
1162 * A copy of the thread list probably needs to be made.
1164 ConDrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1166 LeaveCriticalSection(&Console
->Lock
);
1171 OnNcDestroy(HWND hWnd
)
1173 PGUI_CONSOLE_DATA GuiData
= GuiGetGuiData(hWnd
);
1175 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1176 GetSystemMenu(hWnd
, TRUE
);
1180 /* Free the terminal framebuffer */
1181 if (GuiData
->hMemDC
) DeleteDC(GuiData
->hMemDC
);
1182 if (GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
1183 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1184 if (GuiData
->Font
) DeleteObject(GuiData
->Font
);
1187 /* Free the GuiData registration */
1188 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1190 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1194 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1196 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1198 UINT WidthUnit
, HeightUnit
;
1200 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1202 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1203 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1205 /* Clip coordinate to ensure it's inside buffer */
1208 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1209 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1213 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1214 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1220 OnMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1223 PCONSOLE Console
= GuiData
->Console
;
1225 if (GuiData
->IgnoreNextMouseSignal
)
1227 if (msg
!= WM_LBUTTONDOWN
&&
1228 msg
!= WM_MBUTTONDOWN
&&
1229 msg
!= WM_RBUTTONDOWN
&&
1230 msg
!= WM_MOUSEMOVE
)
1233 * If this mouse signal is not a button-down action or a move,
1234 * then it is the last signal being ignored.
1236 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1241 * This mouse signal is a button-down action or a move.
1242 * Ignore it and perform default action.
1249 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1255 if ( (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1256 (Console
->QuickEdit
) )
1260 case WM_LBUTTONDOWN
:
1262 /* Clear the old selection */
1263 // UpdateSelection(GuiData, NULL);
1264 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
1266 /* Restart a new selection */
1267 GuiData
->Selection
.dwSelectionAnchor
= PointToCoord(GuiData
, lParam
);
1268 SetCapture(GuiData
->hWindow
);
1269 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1270 UpdateSelection(GuiData
, &GuiData
->Selection
.dwSelectionAnchor
);
1279 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1281 // c = PointToCoord(GuiData, lParam);
1282 GuiData
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1283 // UpdateSelection(GuiData, &c);
1289 case WM_LBUTTONDBLCLK
:
1291 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1293 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1295 #ifdef IS_WHITESPACE
1296 #undef IS_WHITESPACE
1298 #define IS_WHITESPACE(c) \
1299 ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1301 PTEXTMODE_SCREEN_BUFFER TextBuffer
= (PTEXTMODE_SCREEN_BUFFER
)Buffer
;
1303 PCHAR_INFO ptrL
, ptrR
;
1305 /* Starting point */
1306 cL
= cR
= PointToCoord(GuiData
, lParam
);
1307 ptrL
= ptrR
= ConioCoordToPointer(TextBuffer
, cL
.X
, cL
.Y
);
1309 /* Enlarge the selection by checking for whitespace */
1310 while ((0 < cL
.X
) && !IS_WHITESPACE(ptrL
->Char
.UnicodeChar
)
1311 && !IS_WHITESPACE((ptrL
-1)->Char
.UnicodeChar
))
1316 while ((cR
.X
< TextBuffer
->ScreenBufferSize
.X
- 1) &&
1317 !IS_WHITESPACE(ptrR
->Char
.UnicodeChar
) &&
1318 !IS_WHITESPACE((ptrR
+1)->Char
.UnicodeChar
))
1325 * Update the selection started with the single
1326 * left-click that preceded this double-click.
1328 GuiData
->Selection
.dwSelectionAnchor
= cL
;
1329 GuiData
->dwSelectionCursor
= cR
;
1331 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1332 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
1334 /* Ignore the next mouse move signal */
1335 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1341 case WM_RBUTTONDOWN
:
1342 case WM_RBUTTONDBLCLK
:
1344 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1353 /* Ignore the next mouse move signal */
1354 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1362 if (!(wParam
& MK_LBUTTON
)) break;
1363 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1365 c
= PointToCoord(GuiData
, lParam
); /* TODO: Scroll buffer to bring c into view */
1366 UpdateSelection(GuiData
, &c
);
1372 Err
= FALSE
; // TRUE;
1376 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1379 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1380 DWORD dwButtonState
= 0;
1381 DWORD dwControlKeyState
= 0;
1382 DWORD dwEventFlags
= 0;
1386 case WM_LBUTTONDOWN
:
1387 SetCapture(GuiData
->hWindow
);
1388 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1392 case WM_MBUTTONDOWN
:
1393 SetCapture(GuiData
->hWindow
);
1394 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1398 case WM_RBUTTONDOWN
:
1399 SetCapture(GuiData
->hWindow
);
1400 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1422 case WM_LBUTTONDBLCLK
:
1423 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1424 dwEventFlags
= DOUBLE_CLICK
;
1427 case WM_MBUTTONDBLCLK
:
1428 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1429 dwEventFlags
= DOUBLE_CLICK
;
1432 case WM_RBUTTONDBLCLK
:
1433 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1434 dwEventFlags
= DOUBLE_CLICK
;
1439 dwEventFlags
= MOUSE_MOVED
;
1443 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1444 dwEventFlags
= MOUSE_WHEELED
;
1447 case WM_MOUSEHWHEEL
:
1448 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1449 dwEventFlags
= MOUSE_HWHEELED
;
1459 if (wKeyState
& MK_LBUTTON
)
1460 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1461 if (wKeyState
& MK_MBUTTON
)
1462 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1463 if (wKeyState
& MK_RBUTTON
)
1464 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1466 if (GetKeyState(VK_RMENU
) & 0x8000)
1467 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1468 if (GetKeyState(VK_LMENU
) & 0x8000)
1469 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1470 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1471 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1472 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1473 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1474 if (GetKeyState(VK_SHIFT
) & 0x8000)
1475 dwControlKeyState
|= SHIFT_PRESSED
;
1476 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1477 dwControlKeyState
|= NUMLOCK_ON
;
1478 if (GetKeyState(VK_SCROLL
) & 0x0001)
1479 dwControlKeyState
|= SCROLLLOCK_ON
;
1480 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1481 dwControlKeyState
|= CAPSLOCK_ON
;
1482 /* See WM_CHAR MSDN documentation for instance */
1483 if (lParam
& 0x01000000)
1484 dwControlKeyState
|= ENHANCED_KEY
;
1486 er
.EventType
= MOUSE_EVENT
;
1487 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1488 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1489 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1490 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1492 ConioProcessInputEvent(Console
, &er
);
1500 LeaveCriticalSection(&Console
->Lock
);
1504 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1510 GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1511 PGUI_CONSOLE_DATA GuiData
);
1513 GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1514 PGUI_CONSOLE_DATA GuiData
);
1517 Copy(PGUI_CONSOLE_DATA GuiData
)
1519 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1521 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1523 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1525 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1527 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1529 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1535 /* Clear the selection */
1536 UpdateSelection(GuiData
, NULL
);
1540 GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1541 PGUI_CONSOLE_DATA GuiData
);
1543 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1544 PGUI_CONSOLE_DATA GuiData
);
1547 Paste(PGUI_CONSOLE_DATA GuiData
)
1549 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1551 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1553 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1555 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1557 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1559 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1567 OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1569 PCONSOLE Console
= GuiData
->Console
;
1570 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1572 UINT WidthUnit
, HeightUnit
;
1574 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1576 ActiveBuffer
= GuiData
->ActiveBuffer
;
1578 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1580 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1581 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1583 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1584 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1586 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1587 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1589 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1590 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1592 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1593 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1595 LeaveCriticalSection(&Console
->Lock
);
1599 OnSize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1601 PCONSOLE Console
= GuiData
->Console
;
1603 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1605 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1606 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1608 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1609 DWORD windx
, windy
, charx
, chary
;
1610 UINT WidthUnit
, HeightUnit
;
1612 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1614 GuiData
->WindowSizeLock
= TRUE
;
1616 windx
= LOWORD(lParam
);
1617 windy
= HIWORD(lParam
);
1619 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1620 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1621 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1623 charx
= windx
/ (int)WidthUnit
;
1624 chary
= windy
/ (int)HeightUnit
;
1626 // Character alignment (round size up or down)
1627 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1628 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1630 // Compensate for added scroll bars in new window
1631 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1632 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1634 charx
= windx
/ (int)WidthUnit
;
1635 chary
= windy
/ (int)HeightUnit
;
1637 // Character alignment (round size up or down)
1638 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1639 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1642 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1644 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1645 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1648 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
1650 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1651 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1652 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1653 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1655 GuiData
->WindowSizeLock
= FALSE
;
1658 LeaveCriticalSection(&Console
->Lock
);
1662 OnMove(PGUI_CONSOLE_DATA GuiData
)
1666 // TODO: Simplify the code.
1667 // See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
1669 /* Retrieve our real position */
1670 GetWindowRect(GuiData
->hWindow
, &rcWnd
);
1671 GuiData
->GuiInfo
.WindowOrigin
.x
= rcWnd
.left
;
1672 GuiData
->GuiInfo
.WindowOrigin
.y
= rcWnd
.top
;
1676 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1680 GuiConsoleHandleScrollbarMenu(VOID)
1684 hMenu = CreatePopupMenu();
1687 DPRINT("CreatePopupMenu failed\n");
1691 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1692 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1693 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1694 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1695 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1696 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1697 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1698 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1699 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1700 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1705 OnScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1707 PCONSOLE Console
= GuiData
->Console
;
1708 PCONSOLE_SCREEN_BUFFER Buff
;
1711 int old_pos
, Maximum
;
1714 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1716 Buff
= GuiData
->ActiveBuffer
;
1718 if (uMsg
== WM_HSCROLL
)
1721 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1722 pShowXY
= &Buff
->ViewOrigin
.X
;
1727 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1728 pShowXY
= &Buff
->ViewOrigin
.Y
;
1731 /* set scrollbar sizes */
1732 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1733 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1735 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1737 old_pos
= sInfo
.nPos
;
1739 switch (LOWORD(wParam
))
1750 sInfo
.nPos
-= sInfo
.nPage
;
1754 sInfo
.nPos
+= sInfo
.nPage
;
1758 sInfo
.nPos
= sInfo
.nTrackPos
;
1759 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1762 case SB_THUMBPOSITION
:
1763 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1767 sInfo
.nPos
= sInfo
.nMin
;
1771 sInfo
.nPos
= sInfo
.nMax
;
1778 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1779 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1781 if (old_pos
!= sInfo
.nPos
)
1783 USHORT OldX
= Buff
->ViewOrigin
.X
;
1784 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1785 UINT WidthUnit
, HeightUnit
;
1787 *pShowXY
= sInfo
.nPos
;
1789 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1791 ScrollWindowEx(GuiData
->hWindow
,
1792 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1793 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1800 sInfo
.fMask
= SIF_POS
;
1801 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1803 UpdateWindow(GuiData
->hWindow
);
1804 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1808 LeaveCriticalSection(&Console
->Lock
);
1813 static LRESULT CALLBACK
1814 ConWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1817 PGUI_CONSOLE_DATA GuiData
= NULL
;
1818 PCONSOLE Console
= NULL
;
1821 * - If it's the first time we create a window for the terminal,
1822 * just initialize it and return.
1824 * - If we are destroying the window, just do it and return.
1826 if (msg
== WM_NCCREATE
)
1828 return (LRESULT
)OnNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1830 else if (msg
== WM_NCDESTROY
)
1832 return OnNcDestroy(hWnd
);
1836 * Now the terminal window is initialized.
1837 * Get the terminal data via the window's data.
1838 * If there is no data, just go away.
1840 GuiData
= GuiGetGuiData(hWnd
);
1841 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1843 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
1844 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1847 * Just retrieve a pointer to the console in case somebody needs it.
1848 * It is not NULL because it was checked in GuiGetGuiData.
1849 * Each helper function which needs the console has to validate and lock it.
1851 Console
= GuiData
->Console
;
1853 /* We have a console, start message dispatching */
1857 OnActivate(GuiData
, wParam
);
1861 if (OnClose(GuiData
)) goto Default
;
1872 case WM_PALETTECHANGED
:
1874 DPRINT("WM_PALETTECHANGED called\n");
1877 * Protects against infinite loops:
1878 * "... A window that receives this message must not realize
1879 * its palette, unless it determines that wParam does not contain
1880 * its own window handle." (WM_PALETTECHANGED description - MSDN)
1882 * This message is sent to all windows, including the one that
1883 * changed the system palette and caused this message to be sent.
1884 * The wParam of this message contains the handle of the window
1885 * that caused the system palette to change. To avoid an infinite
1886 * loop, care must be taken to check that the wParam of this message
1887 * does not match the window's handle.
1889 if ((HWND
)wParam
== hWnd
) break;
1891 DPRINT("WM_PALETTECHANGED ok\n");
1892 OnPaletteChanged(GuiData
);
1893 DPRINT("WM_PALETTECHANGED quit\n");
1904 case WM_SYSDEADCHAR
:
1906 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1907 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1909 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1910 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
1911 GuiConsoleSwitchFullScreen(GuiData
);
1916 OnKey(GuiData
, msg
, wParam
, lParam
);
1923 * The message was sent because we are manually triggering a change.
1924 * Check whether the mouse is indeed present on this console window
1925 * and take appropriate decisions.
1927 if (wParam
== -1 && lParam
== -1)
1932 /* Get the placement of the mouse */
1933 GetCursorPos(&mouseCoords
);
1935 /* On which window is placed the mouse ? */
1936 hWndHit
= WindowFromPoint(mouseCoords
);
1938 /* It's our window. Perform the hit-test to be used later on. */
1939 if (hWndHit
== hWnd
)
1941 wParam
= (WPARAM
)hWnd
;
1942 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1943 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1947 /* Set the mouse cursor only when we are in the client area */
1948 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1950 if (GuiData
->MouseCursorRefCount
>= 0)
1952 /* Show the cursor */
1953 SetCursor(GuiData
->hCursor
);
1957 /* Hide the cursor if the reference count is negative */
1968 case WM_LBUTTONDOWN
:
1969 case WM_MBUTTONDOWN
:
1970 case WM_RBUTTONDOWN
:
1974 case WM_LBUTTONDBLCLK
:
1975 case WM_MBUTTONDBLCLK
:
1976 case WM_RBUTTONDBLCLK
:
1979 case WM_MOUSEHWHEEL
:
1981 Result
= OnMouse(GuiData
, msg
, wParam
, lParam
);
1988 Result
= OnScroll(GuiData
, msg
, wParam
);
1992 case WM_CONTEXTMENU
:
1994 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
1996 HMENU hMenu
= CreatePopupMenu();
1999 AppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
2000 TrackPopupMenuEx(hMenu
,
2002 GET_X_LPARAM(lParam
),
2003 GET_Y_LPARAM(lParam
),
2018 HMENU hMenu
= (HMENU
)wParam
;
2021 /* Enable or disable the Close menu item */
2022 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
2023 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
2025 /* Enable or disable the Copy and Paste items */
2026 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
2027 ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2028 (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
2029 // FIXME: Following whether the active screen buffer is text-mode
2030 // or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
2031 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
2032 (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2033 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
2036 SendMenuEvent(Console
, WM_INITMENU
);
2042 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
2044 SendMenuEvent(Console
, WM_MENUSELECT
);
2052 Result
= OnCommand(GuiData
, wParam
, lParam
);
2058 OnFocus(GuiData
, (msg
== WM_SETFOCUS
));
2061 case WM_GETMINMAXINFO
:
2062 OnGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
2069 #if 0 // This code is here to prepare & control dynamic console SB resizing.
2072 PRECT dragRect
= (PRECT
)lParam
;
2076 DPRINT1("WMSZ_LEFT\n");
2079 DPRINT1("WMSZ_RIGHT\n");
2082 DPRINT1("WMSZ_TOP\n");
2085 DPRINT1("WMSZ_TOPLEFT\n");
2088 DPRINT1("WMSZ_TOPRIGHT\n");
2091 DPRINT1("WMSZ_BOTTOM\n");
2093 case WMSZ_BOTTOMLEFT
:
2094 DPRINT1("WMSZ_BOTTOMLEFT\n");
2096 case WMSZ_BOTTOMRIGHT
:
2097 DPRINT1("WMSZ_BOTTOMRIGHT\n");
2100 DPRINT1("wParam = %d\n", wParam
);
2103 DPRINT1("dragRect = {.left = %d ; .top = %d ; .right = %d ; .bottom = %d}\n",
2104 dragRect
->left
, dragRect
->top
, dragRect
->right
, dragRect
->bottom
);
2110 OnSize(GuiData
, wParam
, lParam
);
2113 case PM_RESIZE_TERMINAL
:
2115 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
2119 DWORD Width
, Height
;
2120 UINT WidthUnit
, HeightUnit
;
2122 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
2124 Width
= Buff
->ScreenBufferSize
.X
* WidthUnit
;
2125 Height
= Buff
->ScreenBufferSize
.Y
* HeightUnit
;
2127 /* Recreate the framebuffer */
2128 hDC
= GetDC(GuiData
->hWindow
);
2129 hnew
= CreateCompatibleBitmap(hDC
, Width
, Height
);
2130 ReleaseDC(GuiData
->hWindow
, hDC
);
2131 hold
= SelectObject(GuiData
->hMemDC
, hnew
);
2132 if (GuiData
->hBitmap
)
2134 if (hold
== GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
2136 GuiData
->hBitmap
= hnew
;
2138 /* Resize the window to the user's values */
2139 GuiData
->WindowSizeLock
= TRUE
;
2140 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
2141 GuiData
->WindowSizeLock
= FALSE
;
2145 case PM_APPLY_CONSOLE_INFO
:
2147 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
2151 case PM_CONSOLE_BEEP
:
2152 DPRINT1("Beep !!\n");
2156 // case PM_CONSOLE_SET_TITLE:
2157 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
2161 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);