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(PCONSRV_CONSOLE 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 PCONSRV_CONSOLE 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);
491 DeleteFonts(PGUI_CONSOLE_DATA GuiData
)
494 for (i
= 0; i
< sizeof(GuiData
->Font
) / sizeof(GuiData
->Font
[0]); ++i
)
496 if (GuiData
->Font
[i
] != NULL
) DeleteObject(GuiData
->Font
[i
]);
497 GuiData
->Font
[i
] = NULL
;
502 CreateDerivedFont(HFONT OrgFont
,
511 /* Initialize the LOGFONT structure */
512 RtlZeroMemory(&lf
, sizeof(lf
));
514 /* Retrieve the details of the current font */
515 if (GetObject(OrgFont
, sizeof(lf
), &lf
) == 0)
518 /* Change the font attributes */
519 // lf.lfHeight = FontSize.Y;
520 // lf.lfWidth = FontSize.X;
521 lf
.lfWeight
= FontWeight
;
522 // lf.lfItalic = bItalic;
523 lf
.lfUnderline
= bUnderline
;
524 lf
.lfStrikeOut
= bStrikeOut
;
526 /* Build a new font */
527 return CreateFontIndirect(&lf
);
531 InitFonts(PGUI_CONSOLE_DATA GuiData
,
532 LPWSTR FaceName
, // Points to a WCHAR array of LF_FACESIZE elements.
538 HFONT OldFont
, NewFont
;
542 hDC
= GetDC(GuiData
->hWindow
);
545 * Initialize a new NORMAL font and get its metrics.
548 FontSize
.Y
= FontSize
.Y
> 0 ? -MulDiv(FontSize
.Y
, GetDeviceCaps(hDC
, LOGPIXELSY
), 72)
551 NewFont
= CreateFontW(FontSize
.Y
,
563 FIXED_PITCH
| FontFamily
,
567 DPRINT1("InitFonts: CreateFontW failed\n");
568 ReleaseDC(GuiData
->hWindow
, hDC
);
572 OldFont
= SelectObject(hDC
, NewFont
);
575 DPRINT1("InitFonts: SelectObject failed\n");
576 ReleaseDC(GuiData
->hWindow
, hDC
);
577 DeleteObject(NewFont
);
581 if (!GetTextMetricsW(hDC
, &Metrics
))
583 DPRINT1("InitFonts: GetTextMetrics failed\n");
584 SelectObject(hDC
, OldFont
);
585 ReleaseDC(GuiData
->hWindow
, hDC
);
586 DeleteObject(NewFont
);
589 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
590 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
592 /* Measure real char width more precisely if possible */
593 if (GetTextExtentPoint32W(hDC
, L
"R", 1, &CharSize
))
594 GuiData
->CharWidth
= CharSize
.cx
;
596 SelectObject(hDC
, OldFont
);
597 ReleaseDC(GuiData
->hWindow
, hDC
);
600 * Initialization succeeded.
602 // Delete all the old fonts first.
603 DeleteFonts(GuiData
);
604 GuiData
->Font
[FONT_NORMAL
] = NewFont
;
607 * Now build the other fonts (bold, underlined, mixed).
609 GuiData
->Font
[FONT_BOLD
] =
610 CreateDerivedFont(GuiData
->Font
[FONT_NORMAL
],
611 FontWeight
< FW_BOLD
? FW_BOLD
: FontWeight
,
614 GuiData
->Font
[FONT_UNDERLINE
] =
615 CreateDerivedFont(GuiData
->Font
[FONT_NORMAL
],
619 GuiData
->Font
[FONT_BOLD
| FONT_UNDERLINE
] =
620 CreateDerivedFont(GuiData
->Font
[FONT_NORMAL
],
621 FontWeight
< FW_BOLD
? FW_BOLD
: FontWeight
,
628 if (FaceName
!= GuiData
->GuiInfo
.FaceName
)
630 wcsncpy(GuiData
->GuiInfo
.FaceName
, FaceName
, LF_FACESIZE
);
631 GuiData
->GuiInfo
.FaceName
[LF_FACESIZE
- 1] = UNICODE_NULL
;
633 GuiData
->GuiInfo
.FontFamily
= FontFamily
;
634 GuiData
->GuiInfo
.FontSize
= FontSize
;
635 GuiData
->GuiInfo
.FontWeight
= FontWeight
;
642 OnNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
644 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
645 PCONSRV_CONSOLE Console
;
649 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
653 Console
= GuiData
->Console
;
655 GuiData
->hWindow
= hWnd
;
657 /* Initialize the fonts */
658 if (!InitFonts(GuiData
,
659 GuiData
->GuiInfo
.FaceName
,
660 GuiData
->GuiInfo
.FontFamily
,
661 GuiData
->GuiInfo
.FontSize
,
662 GuiData
->GuiInfo
.FontWeight
))
664 DPRINT1("GuiConsoleNcCreate: InitFonts failed\n");
665 GuiData
->hWindow
= NULL
;
666 SetEvent(GuiData
->hGuiInitEvent
);
670 /* Initialize the terminal framebuffer */
671 GuiData
->hMemDC
= CreateCompatibleDC(NULL
);
672 GuiData
->hBitmap
= NULL
;
673 GuiData
->hSysPalette
= NULL
; /* Original system palette */
675 /* Update the icons of the window */
676 if (GuiData
->hIcon
!= ghDefaultIcon
)
678 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
679 DefWindowProcW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
682 // FIXME: Keep these instructions here ? ///////////////////////////////////
683 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
684 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
685 ////////////////////////////////////////////////////////////////////////////
687 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
689 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
690 // FIXME: HACK: Potential HACK for CORE-8129; see revision 63595.
691 //CreateSysMenu(GuiData->hWindow);
693 DPRINT("OnNcCreate - setting start event\n");
694 SetEvent(GuiData
->hGuiInitEvent
);
696 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
701 EnterFullScreen(PGUI_CONSOLE_DATA GuiData
);
703 LeaveFullScreen(PGUI_CONSOLE_DATA GuiData
);
705 SwitchFullScreen(PGUI_CONSOLE_DATA GuiData
, BOOL FullScreen
);
707 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
);
710 OnActivate(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
)
712 WORD ActivationState
= LOWORD(wParam
);
714 DPRINT1("WM_ACTIVATE - ActivationState = %d\n");
716 if ( ActivationState
== WA_ACTIVE
||
717 ActivationState
== WA_CLICKACTIVE
)
719 if (GuiData
->GuiInfo
.FullScreen
)
721 EnterFullScreen(GuiData
);
722 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
723 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
726 else // if (ActivationState == WA_INACTIVE)
728 if (GuiData
->GuiInfo
.FullScreen
)
730 SendMessageW(GuiData
->hWindow
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
731 LeaveFullScreen(GuiData
);
732 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
733 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
738 * Ignore the next mouse signal when we are going to be enabled again via
739 * the mouse, in order to prevent, e.g. when we are in Edit mode, erroneous
740 * mouse actions from the user that could spoil text selection or copy/pastes.
742 if (ActivationState
== WA_CLICKACTIVE
)
743 GuiData
->IgnoreNextMouseSignal
= TRUE
;
747 OnFocus(PGUI_CONSOLE_DATA GuiData
, BOOL SetFocus
)
749 PCONSRV_CONSOLE Console
= GuiData
->Console
;
752 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
754 er
.EventType
= FOCUS_EVENT
;
755 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
756 ConioProcessInputEvent(Console
, &er
);
758 LeaveCriticalSection(&Console
->Lock
);
761 DPRINT1("TODO: Create console caret\n");
763 DPRINT1("TODO: Destroy console caret\n");
767 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
769 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
770 UINT WidthUnit
, HeightUnit
;
772 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
774 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
775 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
776 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
777 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
781 GetSelectionBeginEnd(PCOORD Begin
, PCOORD End
,
782 PCOORD SelectionAnchor
,
783 PSMALL_RECT SmallRect
)
785 if (Begin
== NULL
|| End
== NULL
) return;
787 *Begin
= *SelectionAnchor
;
788 End
->X
= (SelectionAnchor
->X
== SmallRect
->Left
) ? SmallRect
->Right
789 /* Case X != Left, must be == Right */ : SmallRect
->Left
;
790 End
->Y
= (SelectionAnchor
->Y
== SmallRect
->Top
) ? SmallRect
->Bottom
791 /* Case Y != Top, must be == Bottom */ : SmallRect
->Top
;
793 /* Exchange Begin / End if Begin > End lexicographically */
794 if (Begin
->Y
> End
->Y
|| (Begin
->Y
== End
->Y
&& Begin
->X
> End
->X
))
796 End
->X
= _InterlockedExchange16(&Begin
->X
, End
->X
);
797 End
->Y
= _InterlockedExchange16(&Begin
->Y
, End
->Y
);
802 CreateSelectionRgn(PGUI_CONSOLE_DATA GuiData
,
804 PCOORD SelectionAnchor
,
805 PSMALL_RECT SmallRect
)
810 SmallRectToRect(GuiData
, &rect
, SmallRect
);
811 return CreateRectRgnIndirect(&rect
);
818 GetSelectionBeginEnd(&Begin
, &End
, SelectionAnchor
, SmallRect
);
820 if (Begin
.Y
== End
.Y
)
830 // Debug thingie to see whether I can put this corner case
831 // together with the previous one.
832 if (SmallRect
->Left
!= sr
.Left
||
833 SmallRect
->Top
!= sr
.Top
||
834 SmallRect
->Right
!= sr
.Right
||
835 SmallRect
->Bottom
!= sr
.Bottom
)
838 "SmallRect = (%d, %d, %d, %d)\n"
839 "sr = (%d, %d, %d, %d)\n"
841 SmallRect
->Left
, SmallRect
->Top
, SmallRect
->Right
, SmallRect
->Bottom
,
842 sr
.Left
, sr
.Top
, sr
.Right
, sr
.Bottom
);
845 SmallRectToRect(GuiData
, &r
, &sr
);
846 SelRgn
= CreateRectRgnIndirect(&r
);
850 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
853 SMALL_RECT sr1
, sr2
, sr3
;
858 sr1
.Right
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
859 sr1
.Bottom
= Begin
.Y
;
862 sr2
.Top
= Begin
.Y
+ 1;
863 sr2
.Right
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
864 sr2
.Bottom
= End
.Y
- 1;
871 SmallRectToRect(GuiData
, &r1
, &sr1
);
872 SmallRectToRect(GuiData
, &r2
, &sr2
);
873 SmallRectToRect(GuiData
, &r3
, &sr3
);
875 rg1
= CreateRectRgnIndirect(&r1
);
876 rg2
= CreateRectRgnIndirect(&r2
);
877 rg3
= CreateRectRgnIndirect(&r3
);
879 CombineRgn(rg1
, rg1
, rg2
, RGN_XOR
);
880 CombineRgn(rg1
, rg1
, rg3
, RGN_XOR
);
892 PaintSelectionRect(PGUI_CONSOLE_DATA GuiData
, PPAINTSTRUCT pps
)
894 HRGN rgnPaint
= CreateRectRgnIndirect(&pps
->rcPaint
);
895 HRGN rgnSel
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
896 &GuiData
->Selection
.dwSelectionAnchor
,
897 &GuiData
->Selection
.srSelection
);
899 /* Invert the selection */
901 int ErrorCode
= CombineRgn(rgnPaint
, rgnPaint
, rgnSel
, RGN_AND
);
902 if (ErrorCode
!= ERROR
&& ErrorCode
!= NULLREGION
)
904 InvertRgn(pps
->hdc
, rgnPaint
);
907 DeleteObject(rgnSel
);
908 DeleteObject(rgnPaint
);
912 UpdateSelection(PGUI_CONSOLE_DATA GuiData
,
913 PCOORD SelectionAnchor OPTIONAL
,
916 PCONSRV_CONSOLE Console
= GuiData
->Console
;
917 HRGN oldRgn
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
918 &GuiData
->Selection
.dwSelectionAnchor
,
919 &GuiData
->Selection
.srSelection
);
921 /* Update the anchor if needed (use the old one if NULL) */
923 GuiData
->Selection
.dwSelectionAnchor
= *SelectionAnchor
;
931 * Pressing the Control key while selecting text, allows us to enter
932 * into line-selection mode, the selection mode of *nix terminals.
934 BOOL OldLineSel
= GuiData
->LineSelection
;
935 GuiData
->LineSelection
= !!(GetKeyState(VK_CONTROL
) & 0x8000);
937 /* Exchange left/top with right/bottom if required */
938 rc
.Left
= min(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
939 rc
.Top
= min(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
940 rc
.Right
= max(GuiData
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
941 rc
.Bottom
= max(GuiData
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
943 newRgn
= CreateSelectionRgn(GuiData
, GuiData
->LineSelection
,
944 &GuiData
->Selection
.dwSelectionAnchor
,
947 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
949 if (OldLineSel
!= GuiData
->LineSelection
||
950 memcmp(&rc
, &GuiData
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
952 /* Calculate the region that needs to be updated */
953 if (oldRgn
&& newRgn
&& CombineRgn(newRgn
, newRgn
, oldRgn
, RGN_XOR
) != ERROR
)
955 InvalidateRgn(GuiData
->hWindow
, newRgn
, FALSE
);
961 InvalidateRgn(GuiData
->hWindow
, newRgn
, FALSE
);
964 DeleteObject(newRgn
);
966 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
967 GuiData
->Selection
.srSelection
= rc
;
968 GuiData
->dwSelectionCursor
= *coord
;
970 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
972 LPWSTR SelTypeStr
= NULL
, WindowTitle
= NULL
;
973 SIZE_T SelTypeStrLength
= 0, Length
= 0;
975 /* Clear the old selection */
976 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
978 InvalidateRgn(GuiData
->hWindow
, oldRgn
, FALSE
);
982 * When passing a zero-length buffer size, LoadString(...) returns
983 * a read-only pointer buffer to the program's resource string.
986 LoadStringW(ConSrvDllInstance
,
987 (GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
)
988 ? IDS_SELECT_TITLE
: IDS_MARK_TITLE
,
989 (LPWSTR
)&SelTypeStr
, 0);
992 * Prepend the selection type string to the current console title
993 * if we succeeded in retrieving a valid localized string.
997 // 3 for " - " and 1 for NULL
998 Length
= Console
->Title
.Length
+ (SelTypeStrLength
+ 3 + 1) * sizeof(WCHAR
);
999 WindowTitle
= ConsoleAllocHeap(0, Length
);
1001 wcsncpy(WindowTitle
, SelTypeStr
, SelTypeStrLength
);
1002 WindowTitle
[SelTypeStrLength
] = L
'\0';
1003 wcscat(WindowTitle
, L
" - ");
1004 wcscat(WindowTitle
, Console
->Title
.Buffer
);
1006 SetWindowText(GuiData
->hWindow
, WindowTitle
);
1007 ConsoleFreeHeap(WindowTitle
);
1010 GuiData
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
1011 ConioPause(Console
, PAUSED_FROM_SELECTION
);
1016 /* Clear the selection */
1017 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
1019 InvalidateRgn(GuiData
->hWindow
, oldRgn
, FALSE
);
1022 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
1023 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
1025 /* Restore the console title */
1026 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
1029 DeleteObject(oldRgn
);
1034 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1035 PGUI_CONSOLE_DATA GuiData
,
1037 PRECT rcFramebuffer
);
1039 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1040 PGUI_CONSOLE_DATA GuiData
,
1042 PRECT rcFramebuffer
);
1045 OnPaint(PGUI_CONSOLE_DATA GuiData
)
1047 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
1051 BeginPaint(GuiData
->hWindow
, &ps
);
1052 if (ps
.hdc
!= NULL
&&
1053 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
1054 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
1056 EnterCriticalSection(&GuiData
->Lock
);
1058 /* Compose the current screen-buffer on-memory */
1059 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
1061 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
1062 GuiData
, &ps
.rcPaint
, &rcPaint
);
1064 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
1066 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
1067 GuiData
, &ps
.rcPaint
, &rcPaint
);
1070 /* Send it to screen */
1074 rcPaint
.right
- rcPaint
.left
,
1075 rcPaint
.bottom
- rcPaint
.top
,
1081 /* Draw the selection region if needed */
1082 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
1084 PaintSelectionRect(GuiData
, &ps
);
1087 LeaveCriticalSection(&GuiData
->Lock
);
1089 EndPaint(GuiData
->hWindow
, &ps
);
1095 OnPaletteChanged(PGUI_CONSOLE_DATA GuiData
)
1097 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
;
1099 // See WM_PALETTECHANGED message
1100 // if ((HWND)wParam == hWnd) break;
1102 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
1103 if (ActiveBuffer
->PaletteHandle
)
1105 DPRINT("WM_PALETTECHANGED changing palette\n");
1107 /* Specify the use of the system palette for the framebuffer */
1108 SetSystemPaletteUse(GuiData
->hMemDC
, ActiveBuffer
->PaletteUsage
);
1110 /* Realize the (logical) palette */
1111 RealizePalette(GuiData
->hMemDC
);
1116 IsSystemKey(WORD VirtualKeyCode
)
1118 switch (VirtualKeyCode
)
1120 /* From MSDN, "Virtual-Key Codes" */
1139 OnKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1141 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1142 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1144 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1146 ActiveBuffer
= GuiData
->ActiveBuffer
;
1148 if (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
1150 WORD VirtualKeyCode
= LOWORD(wParam
);
1152 if (msg
!= WM_KEYDOWN
) goto Quit
;
1154 if (VirtualKeyCode
== VK_RETURN
)
1156 /* Copy (and clear) selection if ENTER is pressed */
1160 else if ( VirtualKeyCode
== VK_ESCAPE
||
1161 (VirtualKeyCode
== 'C' && (GetKeyState(VK_CONTROL
) & 0x8000)) )
1163 /* Cancel selection if ESC or Ctrl-C are pressed */
1164 UpdateSelection(GuiData
, NULL
, NULL
);
1168 if ((GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
1170 /* Keyboard selection mode */
1171 BOOL Interpreted
= FALSE
;
1172 BOOL MajPressed
= !!(GetKeyState(VK_SHIFT
) & 0x8000);
1174 switch (VirtualKeyCode
)
1179 if (GuiData
->dwSelectionCursor
.X
> 0)
1180 GuiData
->dwSelectionCursor
.X
--;
1188 if (GuiData
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
1189 GuiData
->dwSelectionCursor
.X
++;
1197 if (GuiData
->dwSelectionCursor
.Y
> 0)
1198 GuiData
->dwSelectionCursor
.Y
--;
1206 if (GuiData
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
1207 GuiData
->dwSelectionCursor
.Y
++;
1215 GuiData
->dwSelectionCursor
.X
= 0;
1216 GuiData
->dwSelectionCursor
.Y
= 0;
1223 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
1230 GuiData
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
1231 if (GuiData
->dwSelectionCursor
.Y
< 0)
1232 GuiData
->dwSelectionCursor
.Y
= 0;
1240 GuiData
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
1241 if (GuiData
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
1242 GuiData
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
1253 UpdateSelection(GuiData
,
1254 !MajPressed
? &GuiData
->dwSelectionCursor
: NULL
,
1255 &GuiData
->dwSelectionCursor
);
1257 else if (!IsSystemKey(VirtualKeyCode
))
1259 /* Emit an error beep sound */
1260 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
1267 /* Mouse selection mode */
1269 if (!IsSystemKey(VirtualKeyCode
))
1271 /* Clear the selection and send the key into the input buffer */
1272 UpdateSelection(GuiData
, NULL
, NULL
);
1281 if ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
1285 Message
.hwnd
= GuiData
->hWindow
;
1286 Message
.message
= msg
;
1287 Message
.wParam
= wParam
;
1288 Message
.lParam
= lParam
;
1290 ConioProcessKey(Console
, &Message
);
1294 LeaveCriticalSection(&Console
->Lock
);
1298 // FIXME: Remove after fixing OnTimer
1300 InvalidateCell(PGUI_CONSOLE_DATA GuiData
,
1304 OnTimer(PGUI_CONSOLE_DATA GuiData
)
1306 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1307 PCONSOLE_SCREEN_BUFFER Buff
;
1309 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
1311 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1313 Buff
= GuiData
->ActiveBuffer
;
1315 if (GetType(Buff
) == TEXTMODE_BUFFER
)
1317 InvalidateCell(GuiData
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
1318 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
1320 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) ||
1321 (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
1324 int OldScrollX
= -1, OldScrollY
= -1;
1325 int NewScrollX
= -1, NewScrollY
= -1;
1327 xScroll
.cbSize
= sizeof(SCROLLINFO
);
1328 xScroll
.fMask
= SIF_POS
;
1329 // Capture the original position of the scroll bars and save them.
1330 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
1331 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
1333 // If we successfully got the info for the horizontal scrollbar
1334 if (OldScrollX
>= 0)
1336 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) ||
1337 (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
1339 // Handle the horizontal scroll bar
1340 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
)
1341 NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
1347 NewScrollX
= OldScrollX
;
1350 // If we successfully got the info for the vertical scrollbar
1351 if (OldScrollY
>= 0)
1353 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) ||
1354 (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
1356 // Handle the vertical scroll bar
1357 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
)
1358 NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
1364 NewScrollY
= OldScrollY
;
1368 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1369 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1370 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1371 // and their associated scrollbar is left alone.
1372 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
1374 Buff
->ViewOrigin
.X
= NewScrollX
;
1375 Buff
->ViewOrigin
.Y
= NewScrollY
;
1376 ScrollWindowEx(GuiData
->hWindow
,
1377 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
1378 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1384 if (NewScrollX
>= 0)
1386 xScroll
.nPos
= NewScrollX
;
1387 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1389 if (NewScrollY
>= 0)
1391 xScroll
.nPos
= NewScrollY
;
1392 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1394 UpdateWindow(GuiData
->hWindow
);
1395 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1396 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1397 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1401 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1405 LeaveCriticalSection(&Console
->Lock
);
1409 OnClose(PGUI_CONSOLE_DATA GuiData
)
1411 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1413 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1416 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1419 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1420 * We shouldn't wait here, though, since the console lock is entered.
1421 * A copy of the thread list probably needs to be made.
1423 ConSrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1425 LeaveCriticalSection(&Console
->Lock
);
1430 OnNcDestroy(HWND hWnd
)
1432 PGUI_CONSOLE_DATA GuiData
= GuiGetGuiData(hWnd
);
1434 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1435 GetSystemMenu(hWnd
, TRUE
);
1439 /* Free the terminal framebuffer */
1440 if (GuiData
->hMemDC
) DeleteDC(GuiData
->hMemDC
);
1441 if (GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
1442 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1443 DeleteFonts(GuiData
);
1446 /* Free the GuiData registration */
1447 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1449 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1453 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1455 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1457 UINT WidthUnit
, HeightUnit
;
1459 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1461 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1462 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1464 /* Clip coordinate to ensure it's inside buffer */
1467 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1468 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1472 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1473 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1479 OnMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1482 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1484 // FIXME: It's here that we need to check whether we has focus or not
1485 // and whether we are in edit mode or not, to know if we need to deal
1486 // with the mouse, or not.
1488 if (GuiData
->IgnoreNextMouseSignal
)
1490 if (msg
!= WM_LBUTTONDOWN
&&
1491 msg
!= WM_MBUTTONDOWN
&&
1492 msg
!= WM_RBUTTONDOWN
)
1495 * If this mouse signal is not a button-down action
1496 * then it is the last signal being ignored.
1498 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1503 * This mouse signal is a button-down action.
1504 * Ignore it and perform default action.
1511 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1517 if ( (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1518 (Console
->QuickEdit
) )
1522 case WM_LBUTTONDOWN
:
1524 /* Clear the old selection */
1525 GuiData
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
1527 /* Restart a new selection */
1528 GuiData
->dwSelectionCursor
= PointToCoord(GuiData
, lParam
);
1529 SetCapture(GuiData
->hWindow
);
1530 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1531 UpdateSelection(GuiData
,
1532 &GuiData
->dwSelectionCursor
,
1533 &GuiData
->dwSelectionCursor
);
1540 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1542 // GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1543 GuiData
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1544 // UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor);
1550 case WM_LBUTTONDBLCLK
:
1552 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1554 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1556 #define IS_WORD_SEP(c) \
1557 ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1559 PTEXTMODE_SCREEN_BUFFER TextBuffer
= (PTEXTMODE_SCREEN_BUFFER
)Buffer
;
1561 PCHAR_INFO ptrL
, ptrR
;
1563 /* Starting point */
1564 cL
= cR
= PointToCoord(GuiData
, lParam
);
1565 ptrL
= ptrR
= ConioCoordToPointer(TextBuffer
, cL
.X
, cL
.Y
);
1567 /* Enlarge the selection by checking for whitespace */
1568 while ((0 < cL
.X
) && !IS_WORD_SEP(ptrL
->Char
.UnicodeChar
)
1569 && !IS_WORD_SEP((ptrL
-1)->Char
.UnicodeChar
))
1574 while ((cR
.X
< TextBuffer
->ScreenBufferSize
.X
- 1) &&
1575 !IS_WORD_SEP(ptrR
->Char
.UnicodeChar
) &&
1576 !IS_WORD_SEP((ptrR
+1)->Char
.UnicodeChar
))
1583 * Update the selection started with the single
1584 * left-click that preceded this double-click.
1586 GuiData
->Selection
.dwFlags
|= CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1587 UpdateSelection(GuiData
, &cL
, &cR
);
1589 /* Ignore the next mouse move signal */
1590 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1596 case WM_RBUTTONDOWN
:
1597 case WM_RBUTTONDBLCLK
:
1599 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1608 /* Ignore the next mouse move signal */
1609 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1615 if (!(wParam
& MK_LBUTTON
)) break;
1616 if (!(GuiData
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1618 // TODO: Scroll buffer to bring SelectionCursor into view
1619 GuiData
->dwSelectionCursor
= PointToCoord(GuiData
, lParam
);
1620 UpdateSelection(GuiData
, NULL
, &GuiData
->dwSelectionCursor
);
1626 Err
= FALSE
; // TRUE;
1630 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1633 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1634 DWORD dwButtonState
= 0;
1635 DWORD dwControlKeyState
= 0;
1636 DWORD dwEventFlags
= 0;
1640 case WM_LBUTTONDOWN
:
1641 SetCapture(GuiData
->hWindow
);
1642 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1646 case WM_MBUTTONDOWN
:
1647 SetCapture(GuiData
->hWindow
);
1648 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1652 case WM_RBUTTONDOWN
:
1653 SetCapture(GuiData
->hWindow
);
1654 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1676 case WM_LBUTTONDBLCLK
:
1677 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1678 dwEventFlags
= DOUBLE_CLICK
;
1681 case WM_MBUTTONDBLCLK
:
1682 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1683 dwEventFlags
= DOUBLE_CLICK
;
1686 case WM_RBUTTONDBLCLK
:
1687 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1688 dwEventFlags
= DOUBLE_CLICK
;
1693 dwEventFlags
= MOUSE_MOVED
;
1697 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1698 dwEventFlags
= MOUSE_WHEELED
;
1701 case WM_MOUSEHWHEEL
:
1702 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1703 dwEventFlags
= MOUSE_HWHEELED
;
1712 * HACK FOR CORE-8394: Ignore the next mouse move signal
1713 * just after mouse down click actions.
1717 case WM_LBUTTONDOWN
:
1718 case WM_MBUTTONDOWN
:
1719 case WM_RBUTTONDOWN
:
1720 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1727 if (wKeyState
& MK_LBUTTON
)
1728 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1729 if (wKeyState
& MK_MBUTTON
)
1730 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1731 if (wKeyState
& MK_RBUTTON
)
1732 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1734 if (GetKeyState(VK_RMENU
) & 0x8000)
1735 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1736 if (GetKeyState(VK_LMENU
) & 0x8000)
1737 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1738 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1739 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1740 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1741 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1742 if (GetKeyState(VK_SHIFT
) & 0x8000)
1743 dwControlKeyState
|= SHIFT_PRESSED
;
1744 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1745 dwControlKeyState
|= NUMLOCK_ON
;
1746 if (GetKeyState(VK_SCROLL
) & 0x0001)
1747 dwControlKeyState
|= SCROLLLOCK_ON
;
1748 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1749 dwControlKeyState
|= CAPSLOCK_ON
;
1750 /* See WM_CHAR MSDN documentation for instance */
1751 if (lParam
& 0x01000000)
1752 dwControlKeyState
|= ENHANCED_KEY
;
1754 er
.EventType
= MOUSE_EVENT
;
1755 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1756 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1757 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1758 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1760 ConioProcessInputEvent(Console
, &er
);
1768 LeaveCriticalSection(&Console
->Lock
);
1772 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1778 GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1779 PGUI_CONSOLE_DATA GuiData
);
1781 GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1782 PGUI_CONSOLE_DATA GuiData
);
1785 Copy(PGUI_CONSOLE_DATA GuiData
)
1787 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1789 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1791 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1793 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1795 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1797 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1803 /* Clear the selection */
1804 UpdateSelection(GuiData
, NULL
, NULL
);
1808 GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
1809 PGUI_CONSOLE_DATA GuiData
);
1811 GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
1812 PGUI_CONSOLE_DATA GuiData
);
1815 Paste(PGUI_CONSOLE_DATA GuiData
)
1817 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1819 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
;
1821 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1823 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
, GuiData
);
1825 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1827 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
, GuiData
);
1835 OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1837 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1838 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1840 UINT WidthUnit
, HeightUnit
;
1842 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1844 ActiveBuffer
= GuiData
->ActiveBuffer
;
1846 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1848 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1849 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1851 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1852 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1854 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1855 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1857 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1858 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1860 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1861 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1863 LeaveCriticalSection(&Console
->Lock
);
1867 OnSize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1869 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1871 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1873 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1874 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1876 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
1877 DWORD windx
, windy
, charx
, chary
;
1878 UINT WidthUnit
, HeightUnit
;
1880 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1882 GuiData
->WindowSizeLock
= TRUE
;
1884 windx
= LOWORD(lParam
);
1885 windy
= HIWORD(lParam
);
1887 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1888 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1889 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1891 charx
= windx
/ (int)WidthUnit
;
1892 chary
= windy
/ (int)HeightUnit
;
1894 // Character alignment (round size up or down)
1895 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1896 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1898 // Compensate for added scroll bars in new window
1899 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1900 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1902 charx
= windx
/ (int)WidthUnit
;
1903 chary
= windy
/ (int)HeightUnit
;
1905 // Character alignment (round size up or down)
1906 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1907 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1910 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1912 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1913 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1916 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
1918 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1919 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1920 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1921 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1923 GuiData
->WindowSizeLock
= FALSE
;
1926 LeaveCriticalSection(&Console
->Lock
);
1930 OnMove(PGUI_CONSOLE_DATA GuiData
)
1934 // TODO: Simplify the code.
1935 // See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
1937 /* Retrieve our real position */
1938 GetWindowRect(GuiData
->hWindow
, &rcWnd
);
1939 GuiData
->GuiInfo
.WindowOrigin
.x
= rcWnd
.left
;
1940 GuiData
->GuiInfo
.WindowOrigin
.y
= rcWnd
.top
;
1944 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1947 GuiConsoleHandleScrollbarMenu(VOID)
1951 hMenu = CreatePopupMenu();
1954 DPRINT("CreatePopupMenu failed\n");
1958 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1959 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1960 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1961 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1962 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1963 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1964 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1965 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1966 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1967 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1972 OnScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1974 PCONSRV_CONSOLE Console
= GuiData
->Console
;
1975 PCONSOLE_SCREEN_BUFFER Buff
;
1978 int old_pos
, Maximum
;
1981 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1983 Buff
= GuiData
->ActiveBuffer
;
1985 if (uMsg
== WM_HSCROLL
)
1988 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1989 pShowXY
= &Buff
->ViewOrigin
.X
;
1994 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1995 pShowXY
= &Buff
->ViewOrigin
.Y
;
1998 /* set scrollbar sizes */
1999 sInfo
.cbSize
= sizeof(SCROLLINFO
);
2000 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
2002 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
2004 old_pos
= sInfo
.nPos
;
2006 switch (LOWORD(wParam
))
2017 sInfo
.nPos
-= sInfo
.nPage
;
2021 sInfo
.nPos
+= sInfo
.nPage
;
2025 sInfo
.nPos
= sInfo
.nTrackPos
;
2026 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
2029 case SB_THUMBPOSITION
:
2030 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
2034 sInfo
.nPos
= sInfo
.nMin
;
2038 sInfo
.nPos
= sInfo
.nMax
;
2045 sInfo
.nPos
= max(sInfo
.nPos
, 0);
2046 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
2048 if (old_pos
!= sInfo
.nPos
)
2050 USHORT OldX
= Buff
->ViewOrigin
.X
;
2051 USHORT OldY
= Buff
->ViewOrigin
.Y
;
2052 UINT WidthUnit
, HeightUnit
;
2054 *pShowXY
= sInfo
.nPos
;
2056 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
2058 ScrollWindowEx(GuiData
->hWindow
,
2059 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
2060 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
2067 sInfo
.fMask
= SIF_POS
;
2068 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
2070 UpdateWindow(GuiData
->hWindow
);
2071 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
2075 LeaveCriticalSection(&Console
->Lock
);
2080 static LRESULT CALLBACK
2081 ConWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2084 PGUI_CONSOLE_DATA GuiData
= NULL
;
2085 PCONSRV_CONSOLE Console
= NULL
;
2088 * - If it's the first time we create a window for the terminal,
2089 * just initialize it and return.
2091 * - If we are destroying the window, just do it and return.
2093 if (msg
== WM_NCCREATE
)
2095 return (LRESULT
)OnNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
2097 else if (msg
== WM_NCDESTROY
)
2099 return OnNcDestroy(hWnd
);
2103 * Now the terminal window is initialized.
2104 * Get the terminal data via the window's data.
2105 * If there is no data, just go away.
2107 GuiData
= GuiGetGuiData(hWnd
);
2108 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2110 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
2111 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2114 * Just retrieve a pointer to the console in case somebody needs it.
2115 * It is not NULL because it was checked in GuiGetGuiData.
2116 * Each helper function which needs the console has to validate and lock it.
2118 Console
= GuiData
->Console
;
2120 /* We have a console, start message dispatching */
2124 OnActivate(GuiData
, wParam
);
2128 if (OnClose(GuiData
)) goto Default
;
2139 case WM_PALETTECHANGED
:
2141 DPRINT("WM_PALETTECHANGED called\n");
2144 * Protects against infinite loops:
2145 * "... A window that receives this message must not realize
2146 * its palette, unless it determines that wParam does not contain
2147 * its own window handle." (WM_PALETTECHANGED description - MSDN)
2149 * This message is sent to all windows, including the one that
2150 * changed the system palette and caused this message to be sent.
2151 * The wParam of this message contains the handle of the window
2152 * that caused the system palette to change. To avoid an infinite
2153 * loop, care must be taken to check that the wParam of this message
2154 * does not match the window's handle.
2156 if ((HWND
)wParam
== hWnd
) break;
2158 DPRINT("WM_PALETTECHANGED ok\n");
2159 OnPaletteChanged(GuiData
);
2160 DPRINT("WM_PALETTECHANGED quit\n");
2171 case WM_SYSDEADCHAR
:
2173 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
2174 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
2176 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
2177 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
2178 GuiConsoleSwitchFullScreen(GuiData
);
2182 /* Detect Alt-Esc/Space/Tab presses defer to DefWindowProc */
2183 if ( (HIWORD(lParam
) & KF_ALTDOWN
) && (wParam
== VK_ESCAPE
|| wParam
== VK_SPACE
|| wParam
== VK_TAB
))
2185 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2188 OnKey(GuiData
, msg
, wParam
, lParam
);
2195 * The message was sent because we are manually triggering a change.
2196 * Check whether the mouse is indeed present on this console window
2197 * and take appropriate decisions.
2199 if (wParam
== -1 && lParam
== -1)
2204 /* Get the placement of the mouse */
2205 GetCursorPos(&mouseCoords
);
2207 /* On which window is placed the mouse ? */
2208 hWndHit
= WindowFromPoint(mouseCoords
);
2210 /* It's our window. Perform the hit-test to be used later on. */
2211 if (hWndHit
== hWnd
)
2213 wParam
= (WPARAM
)hWnd
;
2214 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
2215 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
2219 /* Set the mouse cursor only when we are in the client area */
2220 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
2222 if (GuiData
->MouseCursorRefCount
>= 0)
2224 /* Show the cursor */
2225 SetCursor(GuiData
->hCursor
);
2229 /* Hide the cursor if the reference count is negative */
2240 case WM_LBUTTONDOWN
:
2241 case WM_MBUTTONDOWN
:
2242 case WM_RBUTTONDOWN
:
2246 case WM_LBUTTONDBLCLK
:
2247 case WM_MBUTTONDBLCLK
:
2248 case WM_RBUTTONDBLCLK
:
2251 case WM_MOUSEHWHEEL
:
2253 Result
= OnMouse(GuiData
, msg
, wParam
, lParam
);
2260 Result
= OnScroll(GuiData
, msg
, wParam
);
2264 case WM_CONTEXTMENU
:
2266 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
2268 HMENU hMenu
= CreatePopupMenu();
2271 AppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
2272 TrackPopupMenuEx(hMenu
,
2274 GET_X_LPARAM(lParam
),
2275 GET_Y_LPARAM(lParam
),
2290 HMENU hMenu
= (HMENU
)wParam
;
2293 /* Enable or disable the Close menu item */
2294 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
2295 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
2297 /* Enable or disable the Copy and Paste items */
2298 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
2299 ((GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2300 (GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
2301 // FIXME: Following whether the active screen buffer is text-mode
2302 // or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
2303 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
2304 (!(GuiData
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
2305 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
2308 SendMenuEvent(Console
, WM_INITMENU
);
2314 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
2316 SendMenuEvent(Console
, WM_MENUSELECT
);
2324 Result
= OnCommand(GuiData
, wParam
, lParam
);
2330 OnFocus(GuiData
, (msg
== WM_SETFOCUS
));
2333 case WM_GETMINMAXINFO
:
2334 OnGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
2341 #if 0 // This code is here to prepare & control dynamic console SB resizing.
2344 PRECT dragRect
= (PRECT
)lParam
;
2348 DPRINT1("WMSZ_LEFT\n");
2351 DPRINT1("WMSZ_RIGHT\n");
2354 DPRINT1("WMSZ_TOP\n");
2357 DPRINT1("WMSZ_TOPLEFT\n");
2360 DPRINT1("WMSZ_TOPRIGHT\n");
2363 DPRINT1("WMSZ_BOTTOM\n");
2365 case WMSZ_BOTTOMLEFT
:
2366 DPRINT1("WMSZ_BOTTOMLEFT\n");
2368 case WMSZ_BOTTOMRIGHT
:
2369 DPRINT1("WMSZ_BOTTOMRIGHT\n");
2372 DPRINT1("wParam = %d\n", wParam
);
2375 DPRINT1("dragRect = {.left = %d ; .top = %d ; .right = %d ; .bottom = %d}\n",
2376 dragRect
->left
, dragRect
->top
, dragRect
->right
, dragRect
->bottom
);
2382 OnSize(GuiData
, wParam
, lParam
);
2385 case PM_RESIZE_TERMINAL
:
2387 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
;
2391 DWORD Width
, Height
;
2392 UINT WidthUnit
, HeightUnit
;
2394 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
2396 Width
= Buff
->ScreenBufferSize
.X
* WidthUnit
;
2397 Height
= Buff
->ScreenBufferSize
.Y
* HeightUnit
;
2399 /* Recreate the framebuffer */
2400 hDC
= GetDC(GuiData
->hWindow
);
2401 hnew
= CreateCompatibleBitmap(hDC
, Width
, Height
);
2402 ReleaseDC(GuiData
->hWindow
, hDC
);
2403 hold
= SelectObject(GuiData
->hMemDC
, hnew
);
2404 if (GuiData
->hBitmap
)
2406 if (hold
== GuiData
->hBitmap
) DeleteObject(GuiData
->hBitmap
);
2408 GuiData
->hBitmap
= hnew
;
2410 /* Resize the window to the user's values */
2411 GuiData
->WindowSizeLock
= TRUE
;
2412 ResizeConWnd(GuiData
, WidthUnit
, HeightUnit
);
2413 GuiData
->WindowSizeLock
= FALSE
;
2417 case PM_APPLY_CONSOLE_INFO
:
2419 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
2424 * Undocumented message sent by Windows' console.dll for applying console info.
2425 * See http://www.catch22.net/sites/default/source/files/setconsoleinfo.c
2426 * and http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf
2427 * for more information.
2429 case WM_SETCONSOLEINFO
:
2431 DPRINT1("WM_SETCONSOLEINFO message\n");
2432 GuiApplyWindowsConsoleSettings(GuiData
, (HANDLE
)wParam
);
2436 case PM_CONSOLE_BEEP
:
2441 // case PM_CONSOLE_SET_TITLE:
2442 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
2446 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);