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 WCHAR szMenuStringBack
[255];
259 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
262 mii
.cbSize
= sizeof(mii
);
263 mii
.fMask
= MIIM_STRING
;
264 mii
.dwTypeData
= szMenuStringBack
;
265 mii
.cch
= sizeof(szMenuStringBack
)/sizeof(WCHAR
);
267 GetMenuItemInfoW(hMenu
, SC_CLOSE
, FALSE
, &mii
);
269 ptrTab
= wcschr(szMenuStringBack
, '\t');
272 mii
.cch
= (int)( ptrTab
- szMenuStringBack
);
273 RtlZeroMemory((PVOID
)ptrTab
, mii
.cch
);
275 mii
.cch
= wcslen(szMenuStringBack
);
277 SetMenuItemInfoW(hMenu
, SC_CLOSE
, FALSE
, &mii
);
280 AppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
286 SendMenuEvent(PCONSOLE Console
, UINT CmdId
)
290 DPRINT1("Menu item ID: %d\n", CmdId
);
292 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
294 er
.EventType
= MENU_EVENT
;
295 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
296 ConioProcessInputEvent(Console
, &er
);
298 LeaveCriticalSection(&Console
->Lock
);
302 Copy(PGUI_CONSOLE_DATA GuiData
);
304 Paste(PGUI_CONSOLE_DATA GuiData
);
306 UpdateSelection(PGUI_CONSOLE_DATA GuiData
, PCOORD coord
);
309 Mark(PGUI_CONSOLE_DATA GuiData
)
311 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
313 /* Clear the old selection */
314 // UpdateSelection(GuiData, NULL);
315 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
317 /* Restart a new selection */
318 GuiData
->dwSelectionCursor
.X
= ActiveBuffer
->ViewOrigin
.X
;
319 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewOrigin
.Y
;
320 GuiData
->Selection
.dwSelectionAnchor
= GuiData
->dwSelectionCursor
;
321 UpdateSelection(GuiData
, &GuiData
->Selection
.dwSelectionAnchor
);
325 SelectAll(PGUI_CONSOLE_DATA GuiData
)
327 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
329 /* Clear the old selection */
330 // UpdateSelection(GuiData, NULL);
331 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
334 * The selection area extends to the whole screen buffer's width.
336 GuiData
->Selection
.dwSelectionAnchor
.X
= 0;
337 GuiData
->Selection
.dwSelectionAnchor
.Y
= 0;
338 GuiData
->dwSelectionCursor
.X
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
341 * Determine whether the selection must extend to just some part
342 * (for text-mode screen buffers) or to all of the screen buffer's
343 * height (for graphics ones).
345 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
348 * We select all the characters from the first line
349 * to the line where the cursor is positioned.
351 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->CursorPosition
.Y
;
353 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
356 * We select all the screen buffer area.
358 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
361 /* Restart a new selection */
362 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
;
363 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
367 OnCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
370 PCONSOLE Console
= GuiData
->Console
;
373 * In case the selected menu item belongs to the user-reserved menu id range,
374 * send to him a menu event and return directly. The user must handle those
375 * reserved menu commands...
377 if (GuiData
->CmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->CmdIdHigh
)
379 SendMenuEvent(Console
, (UINT
)wParam
);
383 /* ... otherwise, perform actions. */
386 case ID_SYSTEM_EDIT_MARK
:
390 case ID_SYSTEM_EDIT_COPY
:
394 case ID_SYSTEM_EDIT_PASTE
:
398 case ID_SYSTEM_EDIT_SELECTALL
:
402 case ID_SYSTEM_EDIT_SCROLL
:
403 DPRINT1("Scrolling is not handled yet\n");
406 case ID_SYSTEM_EDIT_FIND
:
407 DPRINT1("Finding is not handled yet\n");
410 case ID_SYSTEM_DEFAULTS
:
411 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
414 case ID_SYSTEM_PROPERTIES
:
415 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
425 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
430 static PGUI_CONSOLE_DATA
431 GuiGetGuiData(HWND hWnd
)
433 /* This function ensures that the console pointer is not NULL */
434 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
435 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
439 ResizeConWnd(PGUI_CONSOLE_DATA GuiData
, DWORD WidthUnit
, DWORD HeightUnit
)
441 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
446 Width
= Buff
->ViewSize
.X
* WidthUnit
+
447 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
448 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
449 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
451 /* Set scrollbar sizes */
452 sInfo
.cbSize
= sizeof(SCROLLINFO
);
453 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
455 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
457 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
458 sInfo
.nPage
= Buff
->ViewSize
.Y
;
459 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
460 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
461 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
462 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
466 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
469 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
471 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
472 sInfo
.nPage
= Buff
->ViewSize
.X
;
473 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
474 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
475 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
476 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
480 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
483 /* Resize the window */
484 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
485 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
486 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
487 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
491 OnNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
493 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
502 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
506 Console
= GuiData
->Console
;
508 GuiData
->hWindow
= hWnd
;
510 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->GuiInfo
.FontSize
),
511 0, // HIWORD(GuiData->GuiInfo.FontSize),
514 GuiData
->GuiInfo
.FontWeight
,
521 NONANTIALIASED_QUALITY
,
522 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
523 GuiData
->GuiInfo
.FaceName
);
525 if (NULL
== GuiData
->Font
)
527 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
528 GuiData
->hWindow
= NULL
;
529 SetEvent(GuiData
->hGuiInitEvent
);
532 hDC
= GetDC(GuiData
->hWindow
);
535 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
536 DeleteObject(GuiData
->Font
);
537 GuiData
->hWindow
= NULL
;
538 SetEvent(GuiData
->hGuiInitEvent
);
541 OldFont
= SelectObject(hDC
, GuiData
->Font
);
544 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
545 ReleaseDC(GuiData
->hWindow
, hDC
);
546 DeleteObject(GuiData
->Font
);
547 GuiData
->hWindow
= NULL
;
548 SetEvent(GuiData
->hGuiInitEvent
);
551 if (!GetTextMetricsW(hDC
, &Metrics
))
553 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
554 SelectObject(hDC
, OldFont
);
555 ReleaseDC(GuiData
->hWindow
, hDC
);
556 DeleteObject(GuiData
->Font
);
557 GuiData
->hWindow
= NULL
;
558 SetEvent(GuiData
->hGuiInitEvent
);
561 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
562 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
564 /* Measure real char width more precisely if possible. */
565 if (GetTextExtentPoint32W(hDC
, L
"R", 1, &CharSize
))
566 GuiData
->CharWidth
= CharSize
.cx
;
568 SelectObject(hDC
, OldFont
);
570 ReleaseDC(GuiData
->hWindow
, hDC
);
572 /* Initialize the terminal framebuffer */
573 GuiData
->hMemDC
= CreateCompatibleDC(NULL
);
574 GuiData
->hBitmap
= NULL
;
575 GuiData
->hSysPalette
= NULL
; /* Original system palette */
577 /* Update the icons of the window */
578 if (GuiData
->hIcon
!= ghDefaultIcon
)
580 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
581 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
584 // FIXME: Keep these instructions here ? ///////////////////////////////////
585 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
586 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
587 ////////////////////////////////////////////////////////////////////////////
589 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
591 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
592 CreateSysMenu(GuiData
->hWindow
);
594 DPRINT("OnNcCreate - setting start event\n");
595 SetEvent(GuiData
->hGuiInitEvent
);
597 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
602 EnterFullScreen(PGUI_CONSOLE_DATA GuiData
);
604 LeaveFullScreen(PGUI_CONSOLE_DATA GuiData
);
606 SwitchFullScreen(PGUI_CONSOLE_DATA GuiData
, BOOL FullScreen
);
608 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
);
611 OnActivate(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
)
613 PCONSOLE Console
= GuiData
->Console
;
614 WORD ActivationState
= LOWORD(wParam
);
616 DPRINT1("WM_ACTIVATE - ActivationState = %d\n");
618 if ( ActivationState
== WA_ACTIVE
||
619 ActivationState
== WA_CLICKACTIVE
)
621 if (GuiData
->GuiInfo
.FullScreen
)
623 EnterFullScreen(GuiData
);
624 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
625 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
628 else // if (ActivationState == WA_INACTIVE)
630 if (GuiData
->GuiInfo
.FullScreen
)
632 SendMessageW(GuiData
->hWindow
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
633 LeaveFullScreen(GuiData
);
634 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
635 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
640 * When we are in QuickEdit mode, ignore the next mouse signal
641 * when we are going to be enabled again via the mouse, in order
642 * to prevent e.g. an erroneous right-click from the user which
643 * would have as an effect to paste some unwanted text...
645 if (Console
->QuickEdit
&& (ActivationState
== WA_CLICKACTIVE
))
646 GuiData
->IgnoreNextMouseSignal
= TRUE
;
650 OnFocus(PGUI_CONSOLE_DATA GuiData
, BOOL SetFocus
)
652 PCONSOLE Console
= GuiData
->Console
;
655 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
657 er
.EventType
= FOCUS_EVENT
;
658 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
659 ConioProcessInputEvent(Console
, &er
);
661 LeaveCriticalSection(&Console
->Lock
);
664 DPRINT1("TODO: Create console caret\n");
666 DPRINT1("TODO: Destroy console caret\n");
670 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
672 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
673 UINT WidthUnit
, HeightUnit
;
675 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
677 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
678 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
679 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
680 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
684 UpdateSelection(PGUI_CONSOLE_DATA GuiData
, PCOORD coord
)
686 PCONSOLE Console
= GuiData
->Console
;
689 SmallRectToRect(GuiData
, &oldRect
, &GuiData
->Selection
.srSelection
);
696 /* Exchange left/top with right/bottom if required */
697 rc
.Left
= min(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
698 rc
.Top
= min(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
699 rc
.Right
= max(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
700 rc
.Bottom
= max(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
702 SmallRectToRect(GuiData
, &newRect
, &rc
);
704 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
706 if (memcmp(&rc
, &GuiData
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
710 /* Calculate the region that needs to be updated */
711 if ((rgn1
= CreateRectRgnIndirect(&oldRect
)))
713 if ((rgn2
= CreateRectRgnIndirect(&newRect
)))
715 if (CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
717 InvalidateRgn(GuiData
->hWindow
, rgn1
, FALSE
);
727 InvalidateRect(GuiData
->hWindow
, &newRect
, FALSE
);
730 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
731 GuiData
->Selection
.srSelection
= rc
;
732 GuiData
->dwSelectionCursor
= *coord
;
734 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
736 LPWSTR SelectionType
, WindowTitle
= NULL
;
739 /* Clear the old selection */
740 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
742 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
745 if (GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
)
747 SelectionType
= L
"Selection - ";
751 SelectionType
= L
"Mark - ";
754 Length
= Console
->Title
.Length
+ wcslen(SelectionType
) + 1;
755 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
756 wcscpy(WindowTitle
, SelectionType
);
757 wcscat(WindowTitle
, Console
->Title
.Buffer
);
758 SetWindowText(GuiData
->hWindow
, WindowTitle
);
759 ConsoleFreeHeap(WindowTitle
);
761 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
762 ConioPause(Console
, PAUSED_FROM_SELECTION
);
767 /* Clear the selection */
768 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
770 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
773 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
774 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
776 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
782 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
783 PGUI_CONSOLE_DATA GuiData
,
785 PRECT rcFramebuffer
);
787 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
788 PGUI_CONSOLE_DATA GuiData
,
790 PRECT rcFramebuffer
);
793 OnPaint(PGUI_CONSOLE_DATA GuiData
)
795 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
799 ActiveBuffer
= GuiData
->ActiveBuffer
;
801 BeginPaint(GuiData
->hWindow
, &ps
);
802 if (ps
.hdc
!= NULL
&&
803 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
804 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
806 EnterCriticalSection(&GuiData
->Lock
);
808 /* Compose the current screen-buffer on-memory */
809 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
811 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
812 GuiData
, &ps
.rcPaint
, &rcPaint
);
814 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
816 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
817 GuiData
, &ps
.rcPaint
, &rcPaint
);
820 /* Send it to screen */
824 rcPaint
.right
- rcPaint
.left
,
825 rcPaint
.bottom
- rcPaint
.top
,
831 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
833 SmallRectToRect(GuiData
, &rcPaint
, &GuiData
->Selection
.srSelection
);
835 /* Invert the selection */
836 if (IntersectRect(&rcPaint
, &ps
.rcPaint
, &rcPaint
))
838 InvertRect(ps
.hdc
, &rcPaint
);
842 LeaveCriticalSection(&GuiData
->Lock
);
844 EndPaint(GuiData
->hWindow
, &ps
);
850 OnPaletteChanged(PGUI_CONSOLE_DATA GuiData
)
852 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
854 // See WM_PALETTECHANGED message
855 // if ((HWND)wParam == hWnd) break;
857 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
858 if (ActiveBuffer
->PaletteHandle
)
860 DPRINT("WM_PALETTECHANGED changing palette\n");
862 /* Specify the use of the system palette for the framebuffer */
863 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
865 /* Realize the (logical) palette */
866 RealizePalette(GuiData
->hMemDC
);
871 IsSystemKey(WORD VirtualKeyCode
)
873 switch (VirtualKeyCode
)
875 /* From MSDN, "Virtual-Key Codes" */
894 OnKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
896 PCONSOLE Console
= GuiData
->Console
;
897 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
899 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
901 ActiveBuffer
= GuiData
->ActiveBuffer
;
903 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
905 WORD VirtualKeyCode
= LOWORD(wParam
);
907 if (msg
!= WM_KEYDOWN
) goto Quit
;
909 if (VirtualKeyCode
== VK_RETURN
)
911 /* Copy (and clear) selection if ENTER is pressed */
915 else if ( VirtualKeyCode
== VK_ESCAPE
||
916 (VirtualKeyCode
== 'C' && GetKeyState(VK_CONTROL
) & 0x8000) )
918 /* Cancel selection if ESC or Ctrl-C are pressed */
919 UpdateSelection(GuiData
, NULL
);
923 if ((GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
925 /* Keyboard selection mode */
926 BOOL Interpreted
= FALSE
;
927 BOOL MajPressed
= (GetKeyState(VK_SHIFT
) & 0x8000);
929 switch (VirtualKeyCode
)
934 if (GuiData
->dwSelectionCursor
.X
> 0)
935 GuiData
->dwSelectionCursor
.X
--;
943 if (GuiData
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
944 GuiData
->dwSelectionCursor
.X
++;
952 if (GuiData
->dwSelectionCursor
.Y
> 0)
953 GuiData
->dwSelectionCursor
.Y
--;
961 if (GuiData
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
962 GuiData
->dwSelectionCursor
.Y
++;
970 GuiData
->dwSelectionCursor
.X
= 0;
971 GuiData
->dwSelectionCursor
.Y
= 0;
978 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
985 GuiData
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
986 if (GuiData
->dwSelectionCursor
.Y
< 0)
987 GuiData
->dwSelectionCursor
.Y
= 0;
995 GuiData
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
996 if (GuiData
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
997 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
1009 GuiData
->Selection
.dwSelectionAnchor
= GuiData
->dwSelectionCursor
;
1011 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
1013 else if (!IsSystemKey(VirtualKeyCode
))
1015 /* Emit an error beep sound */
1016 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
1023 /* Mouse selection mode */
1025 if (!IsSystemKey(VirtualKeyCode
))
1027 /* Clear the selection and send the key into the input buffer */
1028 UpdateSelection(GuiData
, NULL
);
1037 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
1041 Message
.hwnd
= GuiData
->hWindow
;
1042 Message
.message
= msg
;
1043 Message
.wParam
= wParam
;
1044 Message
.lParam
= lParam
;
1046 ConioProcessKey(Console
, &Message
);
1050 LeaveCriticalSection(&Console
->Lock
);
1054 // FIXME: Remove after fixing OnTimer
1056 InvalidateCell(PGUI_CONSOLE_DATA GuiData
,
1060 OnTimer(PGUI_CONSOLE_DATA GuiData
)
1062 PCONSOLE Console
= GuiData
->Console
;
1063 PCONSOLE_SCREEN_BUFFER Buff
;
1065 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
1067 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1069 Buff
= GuiData
->ActiveBuffer
;
1071 if (GetType(Buff
) == TEXTMODE_BUFFER
)
1073 InvalidateCell(GuiData
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
1074 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
1076 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) ||
1077 (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
1080 int OldScrollX
= -1, OldScrollY
= -1;
1081 int NewScrollX
= -1, NewScrollY
= -1;
1083 xScroll
.cbSize
= sizeof(SCROLLINFO
);
1084 xScroll
.fMask
= SIF_POS
;
1085 // Capture the original position of the scroll bars and save them.
1086 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
1087 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
1089 // If we successfully got the info for the horizontal scrollbar
1090 if (OldScrollX
>= 0)
1092 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) ||
1093 (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
1095 // Handle the horizontal scroll bar
1096 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
)
1097 NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
1103 NewScrollX
= OldScrollX
;
1106 // If we successfully got the info for the vertical scrollbar
1107 if (OldScrollY
>= 0)
1109 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) ||
1110 (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
1112 // Handle the vertical scroll bar
1113 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
)
1114 NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
1120 NewScrollY
= OldScrollY
;
1124 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1125 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1126 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1127 // and their associated scrollbar is left alone.
1128 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
1130 Buff
->ViewOrigin
.X
= NewScrollX
;
1131 Buff
->ViewOrigin
.Y
= NewScrollY
;
1132 ScrollWindowEx(GuiData
->hWindow
,
1133 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
1134 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1140 if (NewScrollX
>= 0)
1142 xScroll
.nPos
= NewScrollX
;
1143 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1145 if (NewScrollY
>= 0)
1147 xScroll
.nPos
= NewScrollY
;
1148 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1150 UpdateWindow(GuiData
->hWindow
);
1151 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1152 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1153 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1157 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1161 LeaveCriticalSection(&Console
->Lock
);
1165 OnClose(PGUI_CONSOLE_DATA GuiData
)
1167 PCONSOLE Console
= GuiData
->Console
;
1169 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1172 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1175 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1176 * We shouldn't wait here, though, since the console lock is entered.
1177 * A copy of the thread list probably needs to be made.
1179 ConDrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1181 LeaveCriticalSection(&Console
->Lock
);
1186 OnNcDestroy(HWND hWnd
)
1188 PGUI_CONSOLE_DATA GuiData
= GuiGetGuiData(hWnd
);
1190 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1191 GetSystemMenu(hWnd
, TRUE
);
1195 /* Free the terminal framebuffer */
1196 if (GuiData
->hMemDC
) DeleteDC(GuiData
->hMemDC
);
1197 if (GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
1198 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1199 if (GuiData
->Font
) DeleteObject(GuiData
->Font
);
1202 /* Free the GuiData registration */
1203 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1205 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1209 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1211 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1213 UINT WidthUnit
, HeightUnit
;
1215 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1217 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1218 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1220 /* Clip coordinate to ensure it's inside buffer */
1223 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1224 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1228 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1229 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1235 OnMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1238 PCONSOLE Console
= GuiData
->Console
;
1240 if (GuiData
->IgnoreNextMouseSignal
)
1242 if (msg
!= WM_LBUTTONDOWN
&&
1243 msg
!= WM_MBUTTONDOWN
&&
1244 msg
!= WM_RBUTTONDOWN
&&
1245 msg
!= WM_MOUSEMOVE
)
1248 * If this mouse signal is not a button-down action or a move,
1249 * then it is the last signal being ignored.
1251 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1256 * This mouse signal is a button-down action or a move.
1257 * Ignore it and perform default action.
1264 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1270 if ( (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1271 (Console
->QuickEdit
) )
1275 case WM_LBUTTONDOWN
:
1277 /* Clear the old selection */
1278 // UpdateSelection(GuiData, NULL);
1279 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
1281 /* Restart a new selection */
1282 GuiData
->Selection
.dwSelectionAnchor
= PointToCoord(GuiData
, lParam
);
1283 SetCapture(GuiData
->hWindow
);
1284 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1285 UpdateSelection(GuiData
, &GuiData
->Selection
.dwSelectionAnchor
);
1294 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1296 // c = PointToCoord(GuiData, lParam);
1297 GuiData
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1298 // UpdateSelection(GuiData, &c);
1304 case WM_LBUTTONDBLCLK
:
1306 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1308 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1310 #ifdef IS_WHITESPACE
1311 #undef IS_WHITESPACE
1313 #define IS_WHITESPACE(c) \
1314 ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1316 PTEXTMODE_SCREEN_BUFFER TextBuffer
= (PTEXTMODE_SCREEN_BUFFER
)Buffer
;
1318 PCHAR_INFO ptrL
, ptrR
;
1320 /* Starting point */
1321 cL
= cR
= PointToCoord(GuiData
, lParam
);
1322 ptrL
= ptrR
= ConioCoordToPointer(TextBuffer
, cL
.X
, cL
.Y
);
1324 /* Enlarge the selection by checking for whitespace */
1325 while ((0 < cL
.X
) && !IS_WHITESPACE(ptrL
->Char
.UnicodeChar
)
1326 && !IS_WHITESPACE((ptrL
-1)->Char
.UnicodeChar
))
1331 while ((cR
.X
< TextBuffer
->ScreenBufferSize
.X
- 1) &&
1332 !IS_WHITESPACE(ptrR
->Char
.UnicodeChar
) &&
1333 !IS_WHITESPACE((ptrR
+1)->Char
.UnicodeChar
))
1340 * Update the selection started with the single
1341 * left-click that preceded this double-click.
1343 GuiData
->Selection
.dwSelectionAnchor
= cL
;
1344 GuiData
->dwSelectionCursor
= cR
;
1346 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1347 UpdateSelection(GuiData
, &GuiData
->dwSelectionCursor
);
1349 /* Ignore the next mouse move signal */
1350 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1356 case WM_RBUTTONDOWN
:
1357 case WM_RBUTTONDBLCLK
:
1359 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1368 /* Ignore the next mouse move signal */
1369 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1377 if (!(wParam
& MK_LBUTTON
)) break;
1378 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1380 c
= PointToCoord(GuiData
, lParam
); /* TODO: Scroll buffer to bring c into view */
1381 UpdateSelection(GuiData
, &c
);
1387 Err
= FALSE
; // TRUE;
1391 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1394 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1395 DWORD dwButtonState
= 0;
1396 DWORD dwControlKeyState
= 0;
1397 DWORD dwEventFlags
= 0;
1401 case WM_LBUTTONDOWN
:
1402 SetCapture(GuiData
->hWindow
);
1403 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1407 case WM_MBUTTONDOWN
:
1408 SetCapture(GuiData
->hWindow
);
1409 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1413 case WM_RBUTTONDOWN
:
1414 SetCapture(GuiData
->hWindow
);
1415 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1437 case WM_LBUTTONDBLCLK
:
1438 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1439 dwEventFlags
= DOUBLE_CLICK
;
1442 case WM_MBUTTONDBLCLK
:
1443 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1444 dwEventFlags
= DOUBLE_CLICK
;
1447 case WM_RBUTTONDBLCLK
:
1448 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1449 dwEventFlags
= DOUBLE_CLICK
;
1454 dwEventFlags
= MOUSE_MOVED
;
1458 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1459 dwEventFlags
= MOUSE_WHEELED
;
1462 case WM_MOUSEHWHEEL
:
1463 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1464 dwEventFlags
= MOUSE_HWHEELED
;
1474 if (wKeyState
& MK_LBUTTON
)
1475 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1476 if (wKeyState
& MK_MBUTTON
)
1477 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1478 if (wKeyState
& MK_RBUTTON
)
1479 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1481 if (GetKeyState(VK_RMENU
) & 0x8000)
1482 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1483 if (GetKeyState(VK_LMENU
) & 0x8000)
1484 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1485 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1486 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1487 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1488 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1489 if (GetKeyState(VK_SHIFT
) & 0x8000)
1490 dwControlKeyState
|= SHIFT_PRESSED
;
1491 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1492 dwControlKeyState
|= NUMLOCK_ON
;
1493 if (GetKeyState(VK_SCROLL
) & 0x0001)
1494 dwControlKeyState
|= SCROLLLOCK_ON
;
1495 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1496 dwControlKeyState
|= CAPSLOCK_ON
;
1497 /* See WM_CHAR MSDN documentation for instance */
1498 if (lParam
& 0x01000000)
1499 dwControlKeyState
|= ENHANCED_KEY
;
1501 er
.EventType
= MOUSE_EVENT
;
1502 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1503 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1504 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1505 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1507 ConioProcessInputEvent(Console
, &er
);
1515 LeaveCriticalSection(&Console
->Lock
);
1519 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1525 GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1526 PGUI_CONSOLE_DATA GuiData
);
1528 GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1529 PGUI_CONSOLE_DATA GuiData
);
1532 Copy(PGUI_CONSOLE_DATA GuiData
)
1534 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1536 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1538 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1540 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1542 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1544 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1550 /* Clear the selection */
1551 UpdateSelection(GuiData
, NULL
);
1555 GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1556 PGUI_CONSOLE_DATA GuiData
);
1558 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1559 PGUI_CONSOLE_DATA GuiData
);
1562 Paste(PGUI_CONSOLE_DATA GuiData
)
1564 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1566 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1568 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1570 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1572 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1574 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1582 OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1584 PCONSOLE Console
= GuiData
->Console
;
1585 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1587 UINT WidthUnit
, HeightUnit
;
1589 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1591 ActiveBuffer
= GuiData
->ActiveBuffer
;
1593 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1595 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1596 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1598 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1599 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1601 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1602 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1604 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1605 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1607 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1608 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1610 LeaveCriticalSection(&Console
->Lock
);
1614 OnSize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1616 PCONSOLE Console
= GuiData
->Console
;
1618 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1620 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1621 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1623 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1624 DWORD windx
, windy
, charx
, chary
;
1625 UINT WidthUnit
, HeightUnit
;
1627 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1629 GuiData
->WindowSizeLock
= TRUE
;
1631 windx
= LOWORD(lParam
);
1632 windy
= HIWORD(lParam
);
1634 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1635 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1636 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1638 charx
= windx
/ (int)WidthUnit
;
1639 chary
= windy
/ (int)HeightUnit
;
1641 // Character alignment (round size up or down)
1642 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1643 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1645 // Compensate for added scroll bars in new window
1646 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1647 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1649 charx
= windx
/ (int)WidthUnit
;
1650 chary
= windy
/ (int)HeightUnit
;
1652 // Character alignment (round size up or down)
1653 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1654 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1657 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1659 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1660 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1663 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
1665 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1666 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1667 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1668 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1670 GuiData
->WindowSizeLock
= FALSE
;
1673 LeaveCriticalSection(&Console
->Lock
);
1677 OnMove(PGUI_CONSOLE_DATA GuiData
)
1681 // TODO: Simplify the code.
1682 // See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
1684 /* Retrieve our real position */
1685 GetWindowRect(GuiData
->hWindow
, &rcWnd
);
1686 GuiData
->GuiInfo
.WindowOrigin
.x
= rcWnd
.left
;
1687 GuiData
->GuiInfo
.WindowOrigin
.y
= rcWnd
.top
;
1691 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1695 GuiConsoleHandleScrollbarMenu(VOID)
1699 hMenu = CreatePopupMenu();
1702 DPRINT("CreatePopupMenu failed\n");
1706 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1707 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1708 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1709 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1710 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1711 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1712 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1713 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1714 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1715 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1720 OnScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1722 PCONSOLE Console
= GuiData
->Console
;
1723 PCONSOLE_SCREEN_BUFFER Buff
;
1726 int old_pos
, Maximum
;
1729 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1731 Buff
= GuiData
->ActiveBuffer
;
1733 if (uMsg
== WM_HSCROLL
)
1736 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1737 pShowXY
= &Buff
->ViewOrigin
.X
;
1742 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1743 pShowXY
= &Buff
->ViewOrigin
.Y
;
1746 /* set scrollbar sizes */
1747 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1748 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1750 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1752 old_pos
= sInfo
.nPos
;
1754 switch (LOWORD(wParam
))
1765 sInfo
.nPos
-= sInfo
.nPage
;
1769 sInfo
.nPos
+= sInfo
.nPage
;
1773 sInfo
.nPos
= sInfo
.nTrackPos
;
1774 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1777 case SB_THUMBPOSITION
:
1778 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1782 sInfo
.nPos
= sInfo
.nMin
;
1786 sInfo
.nPos
= sInfo
.nMax
;
1793 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1794 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1796 if (old_pos
!= sInfo
.nPos
)
1798 USHORT OldX
= Buff
->ViewOrigin
.X
;
1799 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1800 UINT WidthUnit
, HeightUnit
;
1802 *pShowXY
= sInfo
.nPos
;
1804 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1806 ScrollWindowEx(GuiData
->hWindow
,
1807 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1808 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1815 sInfo
.fMask
= SIF_POS
;
1816 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1818 UpdateWindow(GuiData
->hWindow
);
1819 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1823 LeaveCriticalSection(&Console
->Lock
);
1828 static LRESULT CALLBACK
1829 ConWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1832 PGUI_CONSOLE_DATA GuiData
= NULL
;
1833 PCONSOLE Console
= NULL
;
1836 * - If it's the first time we create a window for the terminal,
1837 * just initialize it and return.
1839 * - If we are destroying the window, just do it and return.
1841 if (msg
== WM_NCCREATE
)
1843 return (LRESULT
)OnNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1845 else if (msg
== WM_NCDESTROY
)
1847 return OnNcDestroy(hWnd
);
1851 * Now the terminal window is initialized.
1852 * Get the terminal data via the window's data.
1853 * If there is no data, just go away.
1855 GuiData
= GuiGetGuiData(hWnd
);
1856 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1858 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
1859 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1862 * Just retrieve a pointer to the console in case somebody needs it.
1863 * It is not NULL because it was checked in GuiGetGuiData.
1864 * Each helper function which needs the console has to validate and lock it.
1866 Console
= GuiData
->Console
;
1868 /* We have a console, start message dispatching */
1872 OnActivate(GuiData
, wParam
);
1876 if (OnClose(GuiData
)) goto Default
;
1887 case WM_PALETTECHANGED
:
1889 DPRINT("WM_PALETTECHANGED called\n");
1892 * Protects against infinite loops:
1893 * "... A window that receives this message must not realize
1894 * its palette, unless it determines that wParam does not contain
1895 * its own window handle." (WM_PALETTECHANGED description - MSDN)
1897 * This message is sent to all windows, including the one that
1898 * changed the system palette and caused this message to be sent.
1899 * The wParam of this message contains the handle of the window
1900 * that caused the system palette to change. To avoid an infinite
1901 * loop, care must be taken to check that the wParam of this message
1902 * does not match the window's handle.
1904 if ((HWND
)wParam
== hWnd
) break;
1906 DPRINT("WM_PALETTECHANGED ok\n");
1907 OnPaletteChanged(GuiData
);
1908 DPRINT("WM_PALETTECHANGED quit\n");
1919 case WM_SYSDEADCHAR
:
1921 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1922 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1924 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1925 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
1926 GuiConsoleSwitchFullScreen(GuiData
);
1931 OnKey(GuiData
, msg
, wParam
, lParam
);
1938 * The message was sent because we are manually triggering a change.
1939 * Check whether the mouse is indeed present on this console window
1940 * and take appropriate decisions.
1942 if (wParam
== -1 && lParam
== -1)
1947 /* Get the placement of the mouse */
1948 GetCursorPos(&mouseCoords
);
1950 /* On which window is placed the mouse ? */
1951 hWndHit
= WindowFromPoint(mouseCoords
);
1953 /* It's our window. Perform the hit-test to be used later on. */
1954 if (hWndHit
== hWnd
)
1956 wParam
= (WPARAM
)hWnd
;
1957 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1958 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1962 /* Set the mouse cursor only when we are in the client area */
1963 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1965 if (GuiData
->MouseCursorRefCount
>= 0)
1967 /* Show the cursor */
1968 SetCursor(GuiData
->hCursor
);
1972 /* Hide the cursor if the reference count is negative */
1983 case WM_LBUTTONDOWN
:
1984 case WM_MBUTTONDOWN
:
1985 case WM_RBUTTONDOWN
:
1989 case WM_LBUTTONDBLCLK
:
1990 case WM_MBUTTONDBLCLK
:
1991 case WM_RBUTTONDBLCLK
:
1994 case WM_MOUSEHWHEEL
:
1996 Result
= OnMouse(GuiData
, msg
, wParam
, lParam
);
2003 Result
= OnScroll(GuiData
, msg
, wParam
);
2007 case WM_CONTEXTMENU
:
2009 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
2011 HMENU hMenu
= CreatePopupMenu();
2014 AppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
2015 TrackPopupMenuEx(hMenu
,
2017 GET_X_LPARAM(lParam
),
2018 GET_Y_LPARAM(lParam
),
2033 HMENU hMenu
= (HMENU
)wParam
;
2036 /* Enable or disable the Close menu item */
2037 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
2038 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
2040 /* Enable or disable the Copy and Paste items */
2041 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
2042 ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2043 (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
2044 // FIXME: Following whether the active screen buffer is text-mode
2045 // or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
2046 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
2047 (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2048 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
2051 SendMenuEvent(Console
, WM_INITMENU
);
2057 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
2059 SendMenuEvent(Console
, WM_MENUSELECT
);
2067 Result
= OnCommand(GuiData
, wParam
, lParam
);
2073 OnFocus(GuiData
, (msg
== WM_SETFOCUS
));
2076 case WM_GETMINMAXINFO
:
2077 OnGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
2084 #if 0 // This code is here to prepare & control dynamic console SB resizing.
2087 PRECT dragRect
= (PRECT
)lParam
;
2091 DPRINT1("WMSZ_LEFT\n");
2094 DPRINT1("WMSZ_RIGHT\n");
2097 DPRINT1("WMSZ_TOP\n");
2100 DPRINT1("WMSZ_TOPLEFT\n");
2103 DPRINT1("WMSZ_TOPRIGHT\n");
2106 DPRINT1("WMSZ_BOTTOM\n");
2108 case WMSZ_BOTTOMLEFT
:
2109 DPRINT1("WMSZ_BOTTOMLEFT\n");
2111 case WMSZ_BOTTOMRIGHT
:
2112 DPRINT1("WMSZ_BOTTOMRIGHT\n");
2115 DPRINT1("wParam = %d\n", wParam
);
2118 DPRINT1("dragRect = {.left = %d ; .top = %d ; .right = %d ; .bottom = %d}\n",
2119 dragRect
->left
, dragRect
->top
, dragRect
->right
, dragRect
->bottom
);
2125 OnSize(GuiData
, wParam
, lParam
);
2128 case PM_RESIZE_TERMINAL
:
2130 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
2134 DWORD Width
, Height
;
2135 UINT WidthUnit
, HeightUnit
;
2137 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
2139 Width
= Buff
->ScreenBufferSize
.X
* WidthUnit
;
2140 Height
= Buff
->ScreenBufferSize
.Y
* HeightUnit
;
2142 /* Recreate the framebuffer */
2143 hDC
= GetDC(GuiData
->hWindow
);
2144 hnew
= CreateCompatibleBitmap(hDC
, Width
, Height
);
2145 ReleaseDC(GuiData
->hWindow
, hDC
);
2146 hold
= SelectObject(GuiData
->hMemDC
, hnew
);
2147 if (GuiData
->hBitmap
)
2149 if (hold
== GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
2151 GuiData
->hBitmap
= hnew
;
2153 /* Resize the window to the user's values */
2154 GuiData
->WindowSizeLock
= TRUE
;
2155 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
2156 GuiData
->WindowSizeLock
= FALSE
;
2160 case PM_APPLY_CONSOLE_INFO
:
2162 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
2166 case PM_CONSOLE_BEEP
:
2167 DPRINT1("Beep !!\n");
2171 // case PM_CONSOLE_SET_TITLE:
2172 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
2176 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);