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
= ConSrvGetConsoleLeaderProcess(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));
255 CreateSysMenu(HWND hWnd
)
258 WCHAR szMenuStringBack
[255];
260 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
263 mii
.cbSize
= sizeof(mii
);
264 mii
.fMask
= MIIM_STRING
;
265 mii
.dwTypeData
= szMenuStringBack
;
266 mii
.cch
= sizeof(szMenuStringBack
)/sizeof(WCHAR
);
268 GetMenuItemInfoW(hMenu
, SC_CLOSE
, FALSE
, &mii
);
270 ptrTab
= wcschr(szMenuStringBack
, '\t');
274 mii
.cch
= wcslen(szMenuStringBack
);
276 SetMenuItemInfoW(hMenu
, SC_CLOSE
, FALSE
, &mii
);
279 AppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
285 SendMenuEvent(PCONSOLE Console
, UINT CmdId
)
289 DPRINT1("Menu item ID: %d\n", CmdId
);
291 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
293 er
.EventType
= MENU_EVENT
;
294 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
295 ConioProcessInputEvent(Console
, &er
);
297 LeaveCriticalSection(&Console
->Lock
);
301 Copy(PGUI_CONSOLE_DATA GuiData
);
303 Paste(PGUI_CONSOLE_DATA GuiData
);
305 UpdateSelection(PGUI_CONSOLE_DATA GuiData
,
306 PCOORD SelectionAnchor OPTIONAL
,
310 Mark(PGUI_CONSOLE_DATA GuiData
)
312 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
314 /* Clear the old selection */
315 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
317 /* Restart a new selection */
318 GuiData
->dwSelectionCursor
= ActiveBuffer
->ViewOrigin
;
319 UpdateSelection(GuiData
,
320 &GuiData
->dwSelectionCursor
,
321 &GuiData
->dwSelectionCursor
);
325 SelectAll(PGUI_CONSOLE_DATA GuiData
)
327 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
328 COORD SelectionAnchor
;
330 /* Clear the old selection */
331 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
334 * The selection area extends to the whole screen buffer's width.
336 SelectionAnchor
.X
= SelectionAnchor
.Y
= 0;
337 GuiData
->dwSelectionCursor
.X
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
340 * Determine whether the selection must extend to just some part
341 * (for text-mode screen buffers) or to all of the screen buffer's
342 * height (for graphics ones).
344 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
347 * We select all the characters from the first line
348 * to the line where the cursor is positioned.
350 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->CursorPosition
.Y
;
352 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
355 * We select all the screen buffer area.
357 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
360 /* Restart a new selection */
361 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
;
362 UpdateSelection(GuiData
, &SelectionAnchor
, &GuiData
->dwSelectionCursor
);
366 OnCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
369 PCONSOLE Console
= GuiData
->Console
;
372 * In case the selected menu item belongs to the user-reserved menu id range,
373 * send to him a menu event and return directly. The user must handle those
374 * reserved menu commands...
376 if (GuiData
->CmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->CmdIdHigh
)
378 SendMenuEvent(Console
, (UINT
)wParam
);
382 /* ... otherwise, perform actions. */
385 case ID_SYSTEM_EDIT_MARK
:
389 case ID_SYSTEM_EDIT_COPY
:
393 case ID_SYSTEM_EDIT_PASTE
:
397 case ID_SYSTEM_EDIT_SELECTALL
:
401 case ID_SYSTEM_EDIT_SCROLL
:
402 DPRINT1("Scrolling is not handled yet\n");
405 case ID_SYSTEM_EDIT_FIND
:
406 DPRINT1("Finding is not handled yet\n");
409 case ID_SYSTEM_DEFAULTS
:
410 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
413 case ID_SYSTEM_PROPERTIES
:
414 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
424 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
429 static PGUI_CONSOLE_DATA
430 GuiGetGuiData(HWND hWnd
)
432 /* This function ensures that the console pointer is not NULL */
433 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
434 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
438 ResizeConWnd(PGUI_CONSOLE_DATA GuiData
, DWORD WidthUnit
, DWORD HeightUnit
)
440 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
445 Width
= Buff
->ViewSize
.X
* WidthUnit
+
446 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
447 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
448 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
450 /* Set scrollbar sizes */
451 sInfo
.cbSize
= sizeof(SCROLLINFO
);
452 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
454 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
456 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
457 sInfo
.nPage
= Buff
->ViewSize
.Y
;
458 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
459 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
460 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
461 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
465 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
468 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
470 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
471 sInfo
.nPage
= Buff
->ViewSize
.X
;
472 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
473 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
474 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
475 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
479 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
482 /* Resize the window */
483 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
484 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
485 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
486 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
490 OnNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
492 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
501 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
505 Console
= GuiData
->Console
;
507 GuiData
->hWindow
= hWnd
;
509 GuiData
->Font
= CreateFontW(GuiData
->GuiInfo
.FontSize
.Y
,
510 0, // GuiData->GuiInfo.FontSize.X,
513 GuiData
->GuiInfo
.FontWeight
,
520 NONANTIALIASED_QUALITY
,
521 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
522 GuiData
->GuiInfo
.FaceName
);
524 if (NULL
== GuiData
->Font
)
526 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
527 GuiData
->hWindow
= NULL
;
528 SetEvent(GuiData
->hGuiInitEvent
);
531 hDC
= GetDC(GuiData
->hWindow
);
534 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
535 DeleteObject(GuiData
->Font
);
536 GuiData
->hWindow
= NULL
;
537 SetEvent(GuiData
->hGuiInitEvent
);
540 OldFont
= SelectObject(hDC
, GuiData
->Font
);
543 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
544 ReleaseDC(GuiData
->hWindow
, hDC
);
545 DeleteObject(GuiData
->Font
);
546 GuiData
->hWindow
= NULL
;
547 SetEvent(GuiData
->hGuiInitEvent
);
550 if (!GetTextMetricsW(hDC
, &Metrics
))
552 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
553 SelectObject(hDC
, OldFont
);
554 ReleaseDC(GuiData
->hWindow
, hDC
);
555 DeleteObject(GuiData
->Font
);
556 GuiData
->hWindow
= NULL
;
557 SetEvent(GuiData
->hGuiInitEvent
);
560 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
561 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
563 /* Measure real char width more precisely if possible. */
564 if (GetTextExtentPoint32W(hDC
, L
"R", 1, &CharSize
))
565 GuiData
->CharWidth
= CharSize
.cx
;
567 SelectObject(hDC
, OldFont
);
569 ReleaseDC(GuiData
->hWindow
, hDC
);
571 /* Initialize the terminal framebuffer */
572 GuiData
->hMemDC
= CreateCompatibleDC(NULL
);
573 GuiData
->hBitmap
= NULL
;
574 GuiData
->hSysPalette
= NULL
; /* Original system palette */
576 /* Update the icons of the window */
577 if (GuiData
->hIcon
!= ghDefaultIcon
)
579 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
580 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
583 // FIXME: Keep these instructions here ? ///////////////////////////////////
584 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
585 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
586 ////////////////////////////////////////////////////////////////////////////
588 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
590 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
591 // FIXME: HACK: Potential HACK for CORE-8129; see revision 63595.
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 WORD ActivationState
= LOWORD(wParam
);
615 DPRINT1("WM_ACTIVATE - ActivationState = %d\n");
617 if ( ActivationState
== WA_ACTIVE
||
618 ActivationState
== WA_CLICKACTIVE
)
620 if (GuiData
->GuiInfo
.FullScreen
)
622 EnterFullScreen(GuiData
);
623 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
624 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
627 else // if (ActivationState == WA_INACTIVE)
629 if (GuiData
->GuiInfo
.FullScreen
)
631 SendMessageW(GuiData
->hWindow
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
632 LeaveFullScreen(GuiData
);
633 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
634 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
639 * Ignore the next mouse signal when we are going to be enabled again via
640 * the mouse, in order to prevent, e.g. when we are in Edit mode, erroneous
641 * mouse actions from the user that could spoil text selection or copy/pastes.
643 if (ActivationState
== WA_CLICKACTIVE
)
644 GuiData
->IgnoreNextMouseSignal
= TRUE
;
648 OnFocus(PGUI_CONSOLE_DATA GuiData
, BOOL SetFocus
)
650 PCONSOLE Console
= GuiData
->Console
;
653 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
655 er
.EventType
= FOCUS_EVENT
;
656 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
657 ConioProcessInputEvent(Console
, &er
);
659 LeaveCriticalSection(&Console
->Lock
);
662 DPRINT1("TODO: Create console caret\n");
664 DPRINT1("TODO: Destroy console caret\n");
668 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
670 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
671 UINT WidthUnit
, HeightUnit
;
673 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
675 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
676 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
677 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
678 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
682 GetSelectionBeginEnd(PCOORD Begin
, PCOORD End
,
683 PCOORD SelectionAnchor
,
684 PSMALL_RECT SmallRect
)
686 if (Begin
== NULL
|| End
== NULL
) return;
688 *Begin
= *SelectionAnchor
;
689 End
->X
= (SelectionAnchor
->X
== SmallRect
->Left
) ? SmallRect
->Right
690 /* Case X != Left, must be == Right */ : SmallRect
->Left
;
691 End
->Y
= (SelectionAnchor
->Y
== SmallRect
->Top
) ? SmallRect
->Bottom
692 /* Case Y != Top, must be == Bottom */ : SmallRect
->Top
;
694 /* Exchange Begin / End if Begin > End lexicographically */
695 if (Begin
->Y
> End
->Y
|| (Begin
->Y
== End
->Y
&& Begin
->X
> End
->X
))
697 End
->X
= _InterlockedExchange16(&Begin
->X
, End
->X
);
698 End
->Y
= _InterlockedExchange16(&Begin
->Y
, End
->Y
);
703 CreateSelectionRgn(PGUI_CONSOLE_DATA GuiData
,
705 PCOORD SelectionAnchor
,
706 PSMALL_RECT SmallRect
)
711 SmallRectToRect(GuiData
, &rect
, SmallRect
);
712 return CreateRectRgnIndirect(&rect
);
719 GetSelectionBeginEnd(&Begin
, &End
, SelectionAnchor
, SmallRect
);
721 if (Begin
.Y
== End
.Y
)
731 // Debug thingie to see whether I can put this corner case
732 // together with the previous one.
733 if (SmallRect
->Left
!= sr
.Left
||
734 SmallRect
->Top
!= sr
.Top
||
735 SmallRect
->Right
!= sr
.Right
||
736 SmallRect
->Bottom
!= sr
.Bottom
)
739 "SmallRect = (%d, %d, %d, %d)\n"
740 "sr = (%d, %d, %d, %d)\n"
742 SmallRect
->Left
, SmallRect
->Top
, SmallRect
->Right
, SmallRect
->Bottom
,
743 sr
.Left
, sr
.Top
, sr
.Right
, sr
.Bottom
);
746 SmallRectToRect(GuiData
, &r
, &sr
);
747 SelRgn
= CreateRectRgnIndirect(&r
);
751 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
754 SMALL_RECT sr1
, sr2
, sr3
;
759 sr1
.Right
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
760 sr1
.Bottom
= Begin
.Y
;
763 sr2
.Top
= Begin
.Y
+ 1;
764 sr2
.Right
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
765 sr2
.Bottom
= End
.Y
- 1;
772 SmallRectToRect(GuiData
, &r1
, &sr1
);
773 SmallRectToRect(GuiData
, &r2
, &sr2
);
774 SmallRectToRect(GuiData
, &r3
, &sr3
);
776 rg1
= CreateRectRgnIndirect(&r1
);
777 rg2
= CreateRectRgnIndirect(&r2
);
778 rg3
= CreateRectRgnIndirect(&r3
);
780 CombineRgn(rg1
, rg1
, rg2
, RGN_XOR
);
781 CombineRgn(rg1
, rg1
, rg3
, RGN_XOR
);
793 PaintSelectionRect(PGUI_CONSOLE_DATA GuiData
, PPAINTSTRUCT pps
)
795 HRGN rgnPaint
= CreateRectRgnIndirect(&pps
->rcPaint
);
796 HRGN rgnSel
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
797 &GuiData
->Selection
.dwSelectionAnchor
,
798 &GuiData
->Selection
.srSelection
);
800 /* Invert the selection */
802 int ErrorCode
= CombineRgn(rgnPaint
, rgnPaint
, rgnSel
, RGN_AND
);
803 if (ErrorCode
!= ERROR
&& ErrorCode
!= NULLREGION
)
805 InvertRgn(pps
->hdc
, rgnPaint
);
808 DeleteObject(rgnSel
);
809 DeleteObject(rgnPaint
);
813 UpdateSelection(PGUI_CONSOLE_DATA GuiData
,
814 PCOORD SelectionAnchor OPTIONAL
,
817 PCONSOLE Console
= GuiData
->Console
;
818 HRGN oldRgn
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
819 &GuiData
->Selection
.dwSelectionAnchor
,
820 &GuiData
->Selection
.srSelection
);
822 /* Update the anchor if needed (use the old one if NULL) */
824 GuiData
->Selection
.dwSelectionAnchor
= *SelectionAnchor
;
832 * Pressing the Control key while selecting text, allows us to enter
833 * into line-selection mode, the selection mode of *nix terminals.
835 BOOL OldLineSel
= GuiData
->LineSelection
;
836 GuiData
->LineSelection
= !!(GetKeyState(VK_CONTROL
) & 0x8000);
838 /* Exchange left/top with right/bottom if required */
839 rc
.Left
= min(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
840 rc
.Top
= min(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
841 rc
.Right
= max(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
842 rc
.Bottom
= max(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
844 newRgn
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
845 &GuiData
->Selection
.dwSelectionAnchor
,
848 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
850 if (OldLineSel
!= GuiData
->LineSelection
||
851 memcmp(&rc
, &GuiData
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
853 /* Calculate the region that needs to be updated */
854 if (oldRgn
&& newRgn
&& CombineRgn(newRgn
, newRgn
, oldRgn
, RGN_XOR
) != ERROR
)
856 InvalidateRgn(GuiData
->hWindow
, newRgn
, FALSE
);
862 InvalidateRgn(GuiData
->hWindow
, newRgn
, FALSE
);
865 DeleteObject(newRgn
);
867 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
868 GuiData
->Selection
.srSelection
= rc
;
869 GuiData
->dwSelectionCursor
= *coord
;
871 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
873 LPWSTR SelTypeStr
= NULL
, WindowTitle
= NULL
;
874 SIZE_T SelTypeStrLength
= 0, Length
= 0;
876 /* Clear the old selection */
877 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
879 InvalidateRgn(GuiData
->hWindow
, oldRgn
, FALSE
);
883 * When passing a zero-length buffer size, LoadString(...) returns
884 * a read-only pointer buffer to the program's resource string.
887 LoadStringW(ConSrvDllInstance
,
888 (GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
)
889 ? IDS_SELECT_TITLE
: IDS_MARK_TITLE
,
890 (LPWSTR
)&SelTypeStr
, 0);
893 * Prepend the selection type string to the current console title
894 * if we succeeded in retrieving a valid localized string.
898 // 3 for " - " and 1 for NULL
899 Length
= Console
->Title
.Length
+ (SelTypeStrLength
+ 3 + 1) * sizeof(WCHAR
);
900 WindowTitle
= ConsoleAllocHeap(0, Length
);
902 wcsncpy(WindowTitle
, SelTypeStr
, SelTypeStrLength
);
903 WindowTitle
[SelTypeStrLength
] = L
'\0';
904 wcscat(WindowTitle
, L
" - ");
905 wcscat(WindowTitle
, Console
->Title
.Buffer
);
907 SetWindowText(GuiData
->hWindow
, WindowTitle
);
908 ConsoleFreeHeap(WindowTitle
);
911 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
912 ConioPause(Console
, PAUSED_FROM_SELECTION
);
917 /* Clear the selection */
918 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
920 InvalidateRgn(GuiData
->hWindow
, oldRgn
, FALSE
);
923 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
924 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
926 /* Restore the console title */
927 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
930 DeleteObject(oldRgn
);
935 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
936 PGUI_CONSOLE_DATA GuiData
,
938 PRECT rcFramebuffer
);
940 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
941 PGUI_CONSOLE_DATA GuiData
,
943 PRECT rcFramebuffer
);
946 OnPaint(PGUI_CONSOLE_DATA GuiData
)
948 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
952 BeginPaint(GuiData
->hWindow
, &ps
);
953 if (ps
.hdc
!= NULL
&&
954 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
955 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
957 EnterCriticalSection(&GuiData
->Lock
);
959 /* Compose the current screen-buffer on-memory */
960 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
962 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
963 GuiData
, &ps
.rcPaint
, &rcPaint
);
965 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
967 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
968 GuiData
, &ps
.rcPaint
, &rcPaint
);
971 /* Send it to screen */
975 rcPaint
.right
- rcPaint
.left
,
976 rcPaint
.bottom
- rcPaint
.top
,
982 /* Draw the selection region if needed */
983 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
985 PaintSelectionRect(GuiData
, &ps
);
988 LeaveCriticalSection(&GuiData
->Lock
);
990 EndPaint(GuiData
->hWindow
, &ps
);
996 OnPaletteChanged(PGUI_CONSOLE_DATA GuiData
)
998 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
1000 // See WM_PALETTECHANGED message
1001 // if ((HWND)wParam == hWnd) break;
1003 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
1004 if (ActiveBuffer
->PaletteHandle
)
1006 DPRINT("WM_PALETTECHANGED changing palette\n");
1008 /* Specify the use of the system palette for the framebuffer */
1009 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
1011 /* Realize the (logical) palette */
1012 RealizePalette(GuiData
->hMemDC
);
1017 IsSystemKey(WORD VirtualKeyCode
)
1019 switch (VirtualKeyCode
)
1021 /* From MSDN, "Virtual-Key Codes" */
1040 OnKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1042 PCONSOLE Console
= GuiData
->Console
;
1043 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1045 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1047 ActiveBuffer
= GuiData
->ActiveBuffer
;
1049 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
1051 WORD VirtualKeyCode
= LOWORD(wParam
);
1053 if (msg
!= WM_KEYDOWN
) goto Quit
;
1055 if (VirtualKeyCode
== VK_RETURN
)
1057 /* Copy (and clear) selection if ENTER is pressed */
1061 else if ( VirtualKeyCode
== VK_ESCAPE
||
1062 (VirtualKeyCode
== 'C' && (GetKeyState(VK_CONTROL
) & 0x8000)) )
1064 /* Cancel selection if ESC or Ctrl-C are pressed */
1065 UpdateSelection(GuiData
, NULL
, NULL
);
1069 if ((GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
1071 /* Keyboard selection mode */
1072 BOOL Interpreted
= FALSE
;
1073 BOOL MajPressed
= !!(GetKeyState(VK_SHIFT
) & 0x8000);
1075 switch (VirtualKeyCode
)
1080 if (GuiData
->dwSelectionCursor
.X
> 0)
1081 GuiData
->dwSelectionCursor
.X
--;
1089 if (GuiData
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
1090 GuiData
->dwSelectionCursor
.X
++;
1098 if (GuiData
->dwSelectionCursor
.Y
> 0)
1099 GuiData
->dwSelectionCursor
.Y
--;
1107 if (GuiData
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
1108 GuiData
->dwSelectionCursor
.Y
++;
1116 GuiData
->dwSelectionCursor
.X
= 0;
1117 GuiData
->dwSelectionCursor
.Y
= 0;
1124 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
1131 GuiData
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
1132 if (GuiData
->dwSelectionCursor
.Y
< 0)
1133 GuiData
->dwSelectionCursor
.Y
= 0;
1141 GuiData
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
1142 if (GuiData
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
1143 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
1154 UpdateSelection(GuiData
,
1155 !MajPressed
? &GuiData
->dwSelectionCursor
: NULL
,
1156 &GuiData
->dwSelectionCursor
);
1158 else if (!IsSystemKey(VirtualKeyCode
))
1160 /* Emit an error beep sound */
1161 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
1168 /* Mouse selection mode */
1170 if (!IsSystemKey(VirtualKeyCode
))
1172 /* Clear the selection and send the key into the input buffer */
1173 UpdateSelection(GuiData
, NULL
, NULL
);
1182 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
1186 Message
.hwnd
= GuiData
->hWindow
;
1187 Message
.message
= msg
;
1188 Message
.wParam
= wParam
;
1189 Message
.lParam
= lParam
;
1191 ConioProcessKey(Console
, &Message
);
1195 LeaveCriticalSection(&Console
->Lock
);
1199 // FIXME: Remove after fixing OnTimer
1201 InvalidateCell(PGUI_CONSOLE_DATA GuiData
,
1205 OnTimer(PGUI_CONSOLE_DATA GuiData
)
1207 PCONSOLE Console
= GuiData
->Console
;
1208 PCONSOLE_SCREEN_BUFFER Buff
;
1210 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
1212 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1214 Buff
= GuiData
->ActiveBuffer
;
1216 if (GetType(Buff
) == TEXTMODE_BUFFER
)
1218 InvalidateCell(GuiData
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
1219 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
1221 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) ||
1222 (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
1225 int OldScrollX
= -1, OldScrollY
= -1;
1226 int NewScrollX
= -1, NewScrollY
= -1;
1228 xScroll
.cbSize
= sizeof(SCROLLINFO
);
1229 xScroll
.fMask
= SIF_POS
;
1230 // Capture the original position of the scroll bars and save them.
1231 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
1232 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
1234 // If we successfully got the info for the horizontal scrollbar
1235 if (OldScrollX
>= 0)
1237 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) ||
1238 (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
1240 // Handle the horizontal scroll bar
1241 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
)
1242 NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
1248 NewScrollX
= OldScrollX
;
1251 // If we successfully got the info for the vertical scrollbar
1252 if (OldScrollY
>= 0)
1254 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) ||
1255 (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
1257 // Handle the vertical scroll bar
1258 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
)
1259 NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
1265 NewScrollY
= OldScrollY
;
1269 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1270 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1271 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1272 // and their associated scrollbar is left alone.
1273 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
1275 Buff
->ViewOrigin
.X
= NewScrollX
;
1276 Buff
->ViewOrigin
.Y
= NewScrollY
;
1277 ScrollWindowEx(GuiData
->hWindow
,
1278 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
1279 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1285 if (NewScrollX
>= 0)
1287 xScroll
.nPos
= NewScrollX
;
1288 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1290 if (NewScrollY
>= 0)
1292 xScroll
.nPos
= NewScrollY
;
1293 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1295 UpdateWindow(GuiData
->hWindow
);
1296 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1297 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1298 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1302 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1306 LeaveCriticalSection(&Console
->Lock
);
1310 OnClose(PGUI_CONSOLE_DATA GuiData
)
1312 PCONSOLE Console
= GuiData
->Console
;
1314 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1317 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1320 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1321 * We shouldn't wait here, though, since the console lock is entered.
1322 * A copy of the thread list probably needs to be made.
1324 ConSrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1326 LeaveCriticalSection(&Console
->Lock
);
1331 OnNcDestroy(HWND hWnd
)
1333 PGUI_CONSOLE_DATA GuiData
= GuiGetGuiData(hWnd
);
1335 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1336 GetSystemMenu(hWnd
, TRUE
);
1340 /* Free the terminal framebuffer */
1341 if (GuiData
->hMemDC
) DeleteDC(GuiData
->hMemDC
);
1342 if (GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
1343 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1344 if (GuiData
->Font
) DeleteObject(GuiData
->Font
);
1347 /* Free the GuiData registration */
1348 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1350 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1354 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1356 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1358 UINT WidthUnit
, HeightUnit
;
1360 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1362 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1363 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1365 /* Clip coordinate to ensure it's inside buffer */
1368 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1369 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1373 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1374 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1380 OnMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1383 PCONSOLE Console
= GuiData
->Console
;
1385 // FIXME: It's here that we need to check whether we has focus or not
1386 // and whether we are in edit mode or not, to know if we need to deal
1387 // with the mouse, or not.
1389 if (GuiData
->IgnoreNextMouseSignal
)
1391 if (msg
!= WM_LBUTTONDOWN
&&
1392 msg
!= WM_MBUTTONDOWN
&&
1393 msg
!= WM_RBUTTONDOWN
)
1396 * If this mouse signal is not a button-down action
1397 * then it is the last signal being ignored.
1399 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1404 * This mouse signal is a button-down action.
1405 * Ignore it and perform default action.
1412 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1418 if ( (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1419 (Console
->QuickEdit
) )
1423 case WM_LBUTTONDOWN
:
1425 /* Clear the old selection */
1426 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
1428 /* Restart a new selection */
1429 GuiData
->dwSelectionCursor
= PointToCoord(GuiData
, lParam
);
1430 SetCapture(GuiData
->hWindow
);
1431 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1432 UpdateSelection(GuiData
,
1433 &GuiData
->dwSelectionCursor
,
1434 &GuiData
->dwSelectionCursor
);
1441 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1443 // GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1444 GuiData
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1445 // UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor);
1451 case WM_LBUTTONDBLCLK
:
1453 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1455 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1457 #define IS_WORD_SEP(c) \
1458 ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1460 PTEXTMODE_SCREEN_BUFFER TextBuffer
= (PTEXTMODE_SCREEN_BUFFER
)Buffer
;
1462 PCHAR_INFO ptrL
, ptrR
;
1464 /* Starting point */
1465 cL
= cR
= PointToCoord(GuiData
, lParam
);
1466 ptrL
= ptrR
= ConioCoordToPointer(TextBuffer
, cL
.X
, cL
.Y
);
1468 /* Enlarge the selection by checking for whitespace */
1469 while ((0 < cL
.X
) && !IS_WORD_SEP(ptrL
->Char
.UnicodeChar
)
1470 && !IS_WORD_SEP((ptrL
-1)->Char
.UnicodeChar
))
1475 while ((cR
.X
< TextBuffer
->ScreenBufferSize
.X
- 1) &&
1476 !IS_WORD_SEP(ptrR
->Char
.UnicodeChar
) &&
1477 !IS_WORD_SEP((ptrR
+1)->Char
.UnicodeChar
))
1484 * Update the selection started with the single
1485 * left-click that preceded this double-click.
1487 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1488 UpdateSelection(GuiData
, &cL
, &cR
);
1490 /* Ignore the next mouse move signal */
1491 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1497 case WM_RBUTTONDOWN
:
1498 case WM_RBUTTONDBLCLK
:
1500 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1509 /* Ignore the next mouse move signal */
1510 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1516 if (!(wParam
& MK_LBUTTON
)) break;
1517 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1519 // TODO: Scroll buffer to bring SelectionCursor into view
1520 GuiData
->dwSelectionCursor
= PointToCoord(GuiData
, lParam
);
1521 UpdateSelection(GuiData
, NULL
, &GuiData
->dwSelectionCursor
);
1527 Err
= FALSE
; // TRUE;
1531 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1534 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1535 DWORD dwButtonState
= 0;
1536 DWORD dwControlKeyState
= 0;
1537 DWORD dwEventFlags
= 0;
1541 case WM_LBUTTONDOWN
:
1542 SetCapture(GuiData
->hWindow
);
1543 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1547 case WM_MBUTTONDOWN
:
1548 SetCapture(GuiData
->hWindow
);
1549 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1553 case WM_RBUTTONDOWN
:
1554 SetCapture(GuiData
->hWindow
);
1555 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1577 case WM_LBUTTONDBLCLK
:
1578 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1579 dwEventFlags
= DOUBLE_CLICK
;
1582 case WM_MBUTTONDBLCLK
:
1583 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1584 dwEventFlags
= DOUBLE_CLICK
;
1587 case WM_RBUTTONDBLCLK
:
1588 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1589 dwEventFlags
= DOUBLE_CLICK
;
1594 dwEventFlags
= MOUSE_MOVED
;
1598 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1599 dwEventFlags
= MOUSE_WHEELED
;
1602 case WM_MOUSEHWHEEL
:
1603 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1604 dwEventFlags
= MOUSE_HWHEELED
;
1613 * HACK FOR CORE-8394: Ignore the next mouse move signal
1614 * just after mouse down click actions.
1618 case WM_LBUTTONDOWN
:
1619 case WM_MBUTTONDOWN
:
1620 case WM_RBUTTONDOWN
:
1621 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1628 if (wKeyState
& MK_LBUTTON
)
1629 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1630 if (wKeyState
& MK_MBUTTON
)
1631 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1632 if (wKeyState
& MK_RBUTTON
)
1633 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1635 if (GetKeyState(VK_RMENU
) & 0x8000)
1636 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1637 if (GetKeyState(VK_LMENU
) & 0x8000)
1638 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1639 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1640 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1641 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1642 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1643 if (GetKeyState(VK_SHIFT
) & 0x8000)
1644 dwControlKeyState
|= SHIFT_PRESSED
;
1645 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1646 dwControlKeyState
|= NUMLOCK_ON
;
1647 if (GetKeyState(VK_SCROLL
) & 0x0001)
1648 dwControlKeyState
|= SCROLLLOCK_ON
;
1649 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1650 dwControlKeyState
|= CAPSLOCK_ON
;
1651 /* See WM_CHAR MSDN documentation for instance */
1652 if (lParam
& 0x01000000)
1653 dwControlKeyState
|= ENHANCED_KEY
;
1655 er
.EventType
= MOUSE_EVENT
;
1656 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1657 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1658 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1659 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1661 ConioProcessInputEvent(Console
, &er
);
1669 LeaveCriticalSection(&Console
->Lock
);
1673 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1679 GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1680 PGUI_CONSOLE_DATA GuiData
);
1682 GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1683 PGUI_CONSOLE_DATA GuiData
);
1686 Copy(PGUI_CONSOLE_DATA GuiData
)
1688 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1690 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1692 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1694 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1696 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1698 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1704 /* Clear the selection */
1705 UpdateSelection(GuiData
, NULL
, NULL
);
1709 GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1710 PGUI_CONSOLE_DATA GuiData
);
1712 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1713 PGUI_CONSOLE_DATA GuiData
);
1716 Paste(PGUI_CONSOLE_DATA GuiData
)
1718 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1720 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1722 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1724 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1726 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1728 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1736 OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1738 PCONSOLE Console
= GuiData
->Console
;
1739 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1741 UINT WidthUnit
, HeightUnit
;
1743 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1745 ActiveBuffer
= GuiData
->ActiveBuffer
;
1747 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1749 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1750 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1752 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1753 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1755 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1756 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1758 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1759 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1761 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1762 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1764 LeaveCriticalSection(&Console
->Lock
);
1768 OnSize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1770 PCONSOLE Console
= GuiData
->Console
;
1772 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1774 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1775 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1777 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1778 DWORD windx
, windy
, charx
, chary
;
1779 UINT WidthUnit
, HeightUnit
;
1781 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1783 GuiData
->WindowSizeLock
= TRUE
;
1785 windx
= LOWORD(lParam
);
1786 windy
= HIWORD(lParam
);
1788 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1789 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1790 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1792 charx
= windx
/ (int)WidthUnit
;
1793 chary
= windy
/ (int)HeightUnit
;
1795 // Character alignment (round size up or down)
1796 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1797 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1799 // Compensate for added scroll bars in new window
1800 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1801 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1803 charx
= windx
/ (int)WidthUnit
;
1804 chary
= windy
/ (int)HeightUnit
;
1806 // Character alignment (round size up or down)
1807 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1808 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1811 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1813 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1814 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1817 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
1819 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1820 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1821 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1822 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1824 GuiData
->WindowSizeLock
= FALSE
;
1827 LeaveCriticalSection(&Console
->Lock
);
1831 OnMove(PGUI_CONSOLE_DATA GuiData
)
1835 // TODO: Simplify the code.
1836 // See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
1838 /* Retrieve our real position */
1839 GetWindowRect(GuiData
->hWindow
, &rcWnd
);
1840 GuiData
->GuiInfo
.WindowOrigin
.x
= rcWnd
.left
;
1841 GuiData
->GuiInfo
.WindowOrigin
.y
= rcWnd
.top
;
1845 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1848 GuiConsoleHandleScrollbarMenu(VOID)
1852 hMenu = CreatePopupMenu();
1855 DPRINT("CreatePopupMenu failed\n");
1859 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1860 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1861 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1862 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1863 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1864 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1865 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1866 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1867 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1868 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1873 OnScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1875 PCONSOLE Console
= GuiData
->Console
;
1876 PCONSOLE_SCREEN_BUFFER Buff
;
1879 int old_pos
, Maximum
;
1882 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1884 Buff
= GuiData
->ActiveBuffer
;
1886 if (uMsg
== WM_HSCROLL
)
1889 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1890 pShowXY
= &Buff
->ViewOrigin
.X
;
1895 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1896 pShowXY
= &Buff
->ViewOrigin
.Y
;
1899 /* set scrollbar sizes */
1900 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1901 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1903 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1905 old_pos
= sInfo
.nPos
;
1907 switch (LOWORD(wParam
))
1918 sInfo
.nPos
-= sInfo
.nPage
;
1922 sInfo
.nPos
+= sInfo
.nPage
;
1926 sInfo
.nPos
= sInfo
.nTrackPos
;
1927 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1930 case SB_THUMBPOSITION
:
1931 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1935 sInfo
.nPos
= sInfo
.nMin
;
1939 sInfo
.nPos
= sInfo
.nMax
;
1946 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1947 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1949 if (old_pos
!= sInfo
.nPos
)
1951 USHORT OldX
= Buff
->ViewOrigin
.X
;
1952 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1953 UINT WidthUnit
, HeightUnit
;
1955 *pShowXY
= sInfo
.nPos
;
1957 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1959 ScrollWindowEx(GuiData
->hWindow
,
1960 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1961 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1968 sInfo
.fMask
= SIF_POS
;
1969 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1971 UpdateWindow(GuiData
->hWindow
);
1972 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1976 LeaveCriticalSection(&Console
->Lock
);
1981 static LRESULT CALLBACK
1982 ConWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1985 PGUI_CONSOLE_DATA GuiData
= NULL
;
1986 PCONSOLE Console
= NULL
;
1989 * - If it's the first time we create a window for the terminal,
1990 * just initialize it and return.
1992 * - If we are destroying the window, just do it and return.
1994 if (msg
== WM_NCCREATE
)
1996 return (LRESULT
)OnNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1998 else if (msg
== WM_NCDESTROY
)
2000 return OnNcDestroy(hWnd
);
2004 * Now the terminal window is initialized.
2005 * Get the terminal data via the window's data.
2006 * If there is no data, just go away.
2008 GuiData
= GuiGetGuiData(hWnd
);
2009 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2011 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
2012 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2015 * Just retrieve a pointer to the console in case somebody needs it.
2016 * It is not NULL because it was checked in GuiGetGuiData.
2017 * Each helper function which needs the console has to validate and lock it.
2019 Console
= GuiData
->Console
;
2021 /* We have a console, start message dispatching */
2025 OnActivate(GuiData
, wParam
);
2029 if (OnClose(GuiData
)) goto Default
;
2040 case WM_PALETTECHANGED
:
2042 DPRINT("WM_PALETTECHANGED called\n");
2045 * Protects against infinite loops:
2046 * "... A window that receives this message must not realize
2047 * its palette, unless it determines that wParam does not contain
2048 * its own window handle." (WM_PALETTECHANGED description - MSDN)
2050 * This message is sent to all windows, including the one that
2051 * changed the system palette and caused this message to be sent.
2052 * The wParam of this message contains the handle of the window
2053 * that caused the system palette to change. To avoid an infinite
2054 * loop, care must be taken to check that the wParam of this message
2055 * does not match the window's handle.
2057 if ((HWND
)wParam
== hWnd
) break;
2059 DPRINT("WM_PALETTECHANGED ok\n");
2060 OnPaletteChanged(GuiData
);
2061 DPRINT("WM_PALETTECHANGED quit\n");
2072 case WM_SYSDEADCHAR
:
2074 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
2075 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
2077 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
2078 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
2079 GuiConsoleSwitchFullScreen(GuiData
);
2083 /* Detect Alt-Esc/Space/Tab presses defer to DefWindowProc */
2084 if ( (HIWORD(lParam
) & KF_ALTDOWN
) && (wParam
== VK_ESCAPE
|| wParam
== VK_SPACE
|| wParam
== VK_TAB
))
2086 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2089 OnKey(GuiData
, msg
, wParam
, lParam
);
2096 * The message was sent because we are manually triggering a change.
2097 * Check whether the mouse is indeed present on this console window
2098 * and take appropriate decisions.
2100 if (wParam
== -1 && lParam
== -1)
2105 /* Get the placement of the mouse */
2106 GetCursorPos(&mouseCoords
);
2108 /* On which window is placed the mouse ? */
2109 hWndHit
= WindowFromPoint(mouseCoords
);
2111 /* It's our window. Perform the hit-test to be used later on. */
2112 if (hWndHit
== hWnd
)
2114 wParam
= (WPARAM
)hWnd
;
2115 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
2116 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
2120 /* Set the mouse cursor only when we are in the client area */
2121 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
2123 if (GuiData
->MouseCursorRefCount
>= 0)
2125 /* Show the cursor */
2126 SetCursor(GuiData
->hCursor
);
2130 /* Hide the cursor if the reference count is negative */
2141 case WM_LBUTTONDOWN
:
2142 case WM_MBUTTONDOWN
:
2143 case WM_RBUTTONDOWN
:
2147 case WM_LBUTTONDBLCLK
:
2148 case WM_MBUTTONDBLCLK
:
2149 case WM_RBUTTONDBLCLK
:
2152 case WM_MOUSEHWHEEL
:
2154 Result
= OnMouse(GuiData
, msg
, wParam
, lParam
);
2161 Result
= OnScroll(GuiData
, msg
, wParam
);
2165 case WM_CONTEXTMENU
:
2167 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
2169 HMENU hMenu
= CreatePopupMenu();
2172 AppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
2173 TrackPopupMenuEx(hMenu
,
2175 GET_X_LPARAM(lParam
),
2176 GET_Y_LPARAM(lParam
),
2191 HMENU hMenu
= (HMENU
)wParam
;
2194 /* Enable or disable the Close menu item */
2195 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
2196 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
2198 /* Enable or disable the Copy and Paste items */
2199 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
2200 ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2201 (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
2202 // FIXME: Following whether the active screen buffer is text-mode
2203 // or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
2204 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
2205 (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2206 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
2209 SendMenuEvent(Console
, WM_INITMENU
);
2215 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
2217 SendMenuEvent(Console
, WM_MENUSELECT
);
2225 Result
= OnCommand(GuiData
, wParam
, lParam
);
2231 OnFocus(GuiData
, (msg
== WM_SETFOCUS
));
2234 case WM_GETMINMAXINFO
:
2235 OnGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
2242 #if 0 // This code is here to prepare & control dynamic console SB resizing.
2245 PRECT dragRect
= (PRECT
)lParam
;
2249 DPRINT1("WMSZ_LEFT\n");
2252 DPRINT1("WMSZ_RIGHT\n");
2255 DPRINT1("WMSZ_TOP\n");
2258 DPRINT1("WMSZ_TOPLEFT\n");
2261 DPRINT1("WMSZ_TOPRIGHT\n");
2264 DPRINT1("WMSZ_BOTTOM\n");
2266 case WMSZ_BOTTOMLEFT
:
2267 DPRINT1("WMSZ_BOTTOMLEFT\n");
2269 case WMSZ_BOTTOMRIGHT
:
2270 DPRINT1("WMSZ_BOTTOMRIGHT\n");
2273 DPRINT1("wParam = %d\n", wParam
);
2276 DPRINT1("dragRect = {.left = %d ; .top = %d ; .right = %d ; .bottom = %d}\n",
2277 dragRect
->left
, dragRect
->top
, dragRect
->right
, dragRect
->bottom
);
2283 OnSize(GuiData
, wParam
, lParam
);
2286 case PM_RESIZE_TERMINAL
:
2288 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
2292 DWORD Width
, Height
;
2293 UINT WidthUnit
, HeightUnit
;
2295 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
2297 Width
= Buff
->ScreenBufferSize
.X
* WidthUnit
;
2298 Height
= Buff
->ScreenBufferSize
.Y
* HeightUnit
;
2300 /* Recreate the framebuffer */
2301 hDC
= GetDC(GuiData
->hWindow
);
2302 hnew
= CreateCompatibleBitmap(hDC
, Width
, Height
);
2303 ReleaseDC(GuiData
->hWindow
, hDC
);
2304 hold
= SelectObject(GuiData
->hMemDC
, hnew
);
2305 if (GuiData
->hBitmap
)
2307 if (hold
== GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
2309 GuiData
->hBitmap
= hnew
;
2311 /* Resize the window to the user's values */
2312 GuiData
->WindowSizeLock
= TRUE
;
2313 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
2314 GuiData
->WindowSizeLock
= FALSE
;
2318 case PM_APPLY_CONSOLE_INFO
:
2320 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
2325 * Undocumented message sent by Windows' console.dll for applying console info.
2326 * See http://www.catch22.net/sites/default/source/files/setconsoleinfo.c
2327 * and http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf
2328 * for more information.
2330 case WM_SETCONSOLEINFO
:
2332 DPRINT1("WM_SETCONSOLEINFO message\n");
2333 GuiApplyWindowsConsoleSettings(GuiData
, (HANDLE
)wParam
);
2337 case PM_CONSOLE_BEEP
:
2338 DPRINT1("Beep !!\n");
2342 // case PM_CONSOLE_SET_TITLE:
2343 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
2347 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);