2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/gui/guiterm.c
5 * PURPOSE: GUI Terminal Front-End
6 * PROGRAMMERS: Gé van Geldorp
9 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
12 /* INCLUDES *******************************************************************/
15 #define NONAMELESSUNION
18 #include "include/conio.h"
19 #include "include/console.h"
20 #include "include/settings.h"
21 #include "conoutput.h"
23 #include "guisettings.h"
34 /* GUI Console Window Class name */
35 #define GUI_CONSOLE_WINDOW_CLASS L"ConsoleWindowClass"
40 #define PM_CREATE_CONSOLE (WM_APP + 1)
41 #define PM_DESTROY_CONSOLE (WM_APP + 2)
42 #define PM_RESIZE_TERMINAL (WM_APP + 3)
43 #define PM_CONSOLE_BEEP (WM_APP + 4)
44 #define PM_CONSOLE_SET_TITLE (WM_APP + 5)
47 /* Not defined in any header file */
48 extern VOID WINAPI
PrivateCsrssManualGuiCheck(LONG Check
);
49 // See winsrv/usersrv/init.c line 234
52 /* GLOBALS ********************************************************************/
54 typedef struct _GUI_INIT_INFO
56 PCONSOLE_INFO ConsoleInfo
;
57 PCONSOLE_START_INFO ConsoleStartInfo
;
59 } GUI_INIT_INFO
, *PGUI_INIT_INFO
;
61 /**************************************************************\
62 \** Define the Console Leader Process for the console window **/
63 #define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
64 #define GWLP_CONSOLE_LEADER_PID 0
65 #define GWLP_CONSOLE_LEADER_TID 4
67 #define SetConsoleWndConsoleLeaderCID(GuiData) \
69 PCONSOLE_PROCESS_DATA ProcessData; \
70 CLIENT_ID ConsoleLeaderCID; \
71 ProcessData = CONTAINING_RECORD((GuiData)->Console->ProcessList.Blink, \
72 CONSOLE_PROCESS_DATA, \
74 ConsoleLeaderCID = ProcessData->Process->ClientId; \
75 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_PID, \
76 (LONG_PTR)(ConsoleLeaderCID.UniqueProcess)); \
77 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_TID, \
78 (LONG_PTR)(ConsoleLeaderCID.UniqueThread )); \
80 /**************************************************************/
82 static BOOL ConsInitialized
= FALSE
;
83 static HICON ghDefaultIcon
= NULL
;
84 static HICON ghDefaultIconSm
= NULL
;
85 static HCURSOR ghDefaultCursor
= NULL
;
86 static HWND NotifyWnd
= NULL
;
88 typedef struct _GUICONSOLE_MENUITEM
91 const struct _GUICONSOLE_MENUITEM
*SubMenu
;
93 } GUICONSOLE_MENUITEM
, *PGUICONSOLE_MENUITEM
;
95 static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems
[] =
97 { IDS_MARK
, NULL
, ID_SYSTEM_EDIT_MARK
},
98 { IDS_COPY
, NULL
, ID_SYSTEM_EDIT_COPY
},
99 { IDS_PASTE
, NULL
, ID_SYSTEM_EDIT_PASTE
},
100 { IDS_SELECTALL
, NULL
, ID_SYSTEM_EDIT_SELECTALL
},
101 { IDS_SCROLL
, NULL
, ID_SYSTEM_EDIT_SCROLL
},
102 { IDS_FIND
, NULL
, ID_SYSTEM_EDIT_FIND
},
104 { 0, NULL
, 0 } /* End of list */
107 static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems
[] =
109 { IDS_EDIT
, GuiConsoleEditMenuItems
, 0 },
110 { IDS_DEFAULTS
, NULL
, ID_SYSTEM_DEFAULTS
},
111 { IDS_PROPERTIES
, NULL
, ID_SYSTEM_PROPERTIES
},
113 { 0, NULL
, 0 } /* End of list */
117 * Default 16-color palette for foreground and background
118 * (corresponding flags in comments).
120 const COLORREF s_Colors
[16] =
122 RGB(0, 0, 0), // (Black)
123 RGB(0, 0, 128), // BLUE
124 RGB(0, 128, 0), // GREEN
125 RGB(0, 128, 128), // BLUE | GREEN
126 RGB(128, 0, 0), // RED
127 RGB(128, 0, 128), // BLUE | RED
128 RGB(128, 128, 0), // GREEN | RED
129 RGB(192, 192, 192), // BLUE | GREEN | RED
131 RGB(128, 128, 128), // (Grey) INTENSITY
132 RGB(0, 0, 255), // BLUE | INTENSITY
133 RGB(0, 255, 0), // GREEN | INTENSITY
134 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
135 RGB(255, 0, 0), // RED | INTENSITY
136 RGB(255, 0, 255), // BLUE | RED | INTENSITY
137 RGB(255, 255, 0), // GREEN | RED | INTENSITY
138 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
141 /* FUNCTIONS ******************************************************************/
144 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer
,
145 IN PGUI_CONSOLE_DATA GuiData
,
147 OUT PUINT HeightUnit
)
149 if (Buffer
== NULL
|| GuiData
== NULL
||
150 WidthUnit
== NULL
|| HeightUnit
== NULL
)
155 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
157 *WidthUnit
= GuiData
->CharWidth
;
158 *HeightUnit
= GuiData
->CharHeight
;
160 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
170 GuiConsoleAppendMenuItems(HMENU hMenu
,
171 const GUICONSOLE_MENUITEM
*Items
)
174 WCHAR szMenuString
[255];
179 if (Items
[i
].uID
!= (UINT
)-1)
181 if (LoadStringW(ConSrvDllInstance
,
184 sizeof(szMenuString
) / sizeof(szMenuString
[0])) > 0)
186 if (Items
[i
].SubMenu
!= NULL
)
188 hSubMenu
= CreatePopupMenu();
189 if (hSubMenu
!= NULL
)
191 GuiConsoleAppendMenuItems(hSubMenu
,
194 if (!AppendMenuW(hMenu
,
195 MF_STRING
| MF_POPUP
,
199 DestroyMenu(hSubMenu
);
220 } while (!(Items
[i
].uID
== 0 && Items
[i
].SubMenu
== NULL
&& Items
[i
].wCmdID
== 0));
224 GuiConsoleCreateSysMenu(HWND hWnd
)
226 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
229 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
235 GuiSendMenuEvent(PCONSOLE Console
, UINT CmdId
)
239 er
.EventType
= MENU_EVENT
;
240 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
242 ConioProcessInputEvent(Console
, &er
);
246 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
);
248 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
);
250 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
);
252 GuiDrawRegion(IN OUT PFRONTEND This
, SMALL_RECT
* Region
);
254 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
);
258 GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
261 PCONSOLE Console
= GuiData
->Console
;
262 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
264 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
269 // ActiveBuffer = ConDrvGetActiveScreenBuffer(Console);
270 ActiveBuffer
= GuiData
->ActiveBuffer
;
273 * In case the selected menu item belongs to the user-reserved menu id range,
274 * send to him a menu event and return directly. The user must handle those
275 * reserved menu commands...
277 if (GuiData
->cmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->cmdIdHigh
)
279 GuiSendMenuEvent(Console
, (UINT
)wParam
);
283 /* ... otherwise, perform actions. */
286 case ID_SYSTEM_EDIT_MARK
:
288 LPWSTR WindowTitle
= NULL
;
291 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ViewOrigin
.X
;
292 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewOrigin
.Y
;
293 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
294 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
295 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
297 Length
= Console
->Title
.Length
+ sizeof(L
"Mark - ")/sizeof(WCHAR
) + 1;
298 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
299 wcscpy(WindowTitle
, L
"Mark - ");
300 wcscat(WindowTitle
, Console
->Title
.Buffer
);
301 SetWindowText(GuiData
->hWindow
, WindowTitle
);
302 ConsoleFreeHeap(WindowTitle
);
307 case ID_SYSTEM_EDIT_COPY
:
308 GuiConsoleCopy(GuiData
);
311 case ID_SYSTEM_EDIT_PASTE
:
312 GuiConsolePaste(GuiData
);
315 case ID_SYSTEM_EDIT_SELECTALL
:
317 LPWSTR WindowTitle
= NULL
;
321 * The selection area extends to the whole screen buffer's width.
323 Console
->Selection
.dwSelectionAnchor
.X
= 0;
324 Console
->Selection
.dwSelectionAnchor
.Y
= 0;
325 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ScreenBufferSize
.X
- 1;
328 * Determine whether the selection must extend to just some part
329 * (for text-mode screen buffers) or to all of the screen buffer's
330 * height (for graphics ones).
332 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
335 * We select all the characters from the first line
336 * to the line where the cursor is positioned.
338 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->CursorPosition
.Y
;
340 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
343 * We select all the screen buffer area.
345 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
348 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
;
349 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
351 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
352 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
353 wcscpy(WindowTitle
, L
"Selection - ");
354 wcscat(WindowTitle
, Console
->Title
.Buffer
);
355 SetWindowText(GuiData
->hWindow
, WindowTitle
);
356 ConsoleFreeHeap(WindowTitle
);
361 case ID_SYSTEM_EDIT_SCROLL
:
362 DPRINT1("Scrolling is not handled yet\n");
365 case ID_SYSTEM_EDIT_FIND
:
366 DPRINT1("Finding is not handled yet\n");
369 case ID_SYSTEM_DEFAULTS
:
370 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
373 case ID_SYSTEM_PROPERTIES
:
374 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
383 LeaveCriticalSection(&Console
->Lock
);
386 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
391 static PGUI_CONSOLE_DATA
392 GuiGetGuiData(HWND hWnd
)
394 /* This function ensures that the console pointer is not NULL */
395 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
396 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
400 GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData
)
402 /* Move the window if needed (not positioned by the system) */
403 if (!GuiData
->GuiInfo
.AutoPosition
)
405 SetWindowPos(GuiData
->hWindow
,
407 GuiData
->GuiInfo
.WindowOrigin
.x
,
408 GuiData
->GuiInfo
.WindowOrigin
.y
,
411 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
416 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
)
418 // PCONSOLE Console = GuiData->Console;
419 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
423 UINT WidthUnit
, HeightUnit
;
425 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
427 Width
= Buff
->ViewSize
.X
* WidthUnit
+
428 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
429 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
430 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
432 /* Set scrollbar sizes */
433 sInfo
.cbSize
= sizeof(SCROLLINFO
);
434 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
436 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
438 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
439 sInfo
.nPage
= Buff
->ViewSize
.Y
;
440 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
441 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
442 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
443 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
447 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
450 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
452 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
453 sInfo
.nPage
= Buff
->ViewSize
.X
;
454 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
455 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
456 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
457 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
461 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
464 /* Resize the window */
465 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
466 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
467 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
468 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
472 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
)
474 PCONSOLE Console
= GuiData
->Console
;
475 // DEVMODE dmScreenSettings;
477 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
479 /* Switch to full-screen or to windowed mode */
480 GuiData
->GuiInfo
.FullScreen
= !GuiData
->GuiInfo
.FullScreen
;
481 DPRINT1("GuiConsoleSwitchFullScreen - Switch to %s ...\n",
482 (GuiData
->GuiInfo
.FullScreen
? "full-screen" : "windowed mode"));
484 // TODO: Change window appearance.
486 // http://stackoverflow.com/questions/2382464/win32-full-screen-and-hiding-taskbar
487 // http://stackoverflow.com/questions/3549148/fullscreen-management-with-winapi
488 // http://blogs.msdn.com/b/oldnewthing/archive/2010/04/12/9994016.aspx
489 // http://stackoverflow.com/questions/1400654/how-do-i-put-my-opengl-app-into-fullscreen-mode
490 // http://nehe.gamedev.net/tutorial/creating_an_opengl_window_win32/13001/
492 if (GuiData
->GuiInfo
.FullScreen
)
494 memset(&dmScreenSettings
, 0, sizeof(dmScreenSettings
));
495 dmScreenSettings
.dmSize
= sizeof(dmScreenSettings
);
496 dmScreenSettings
.dmDisplayFixedOutput
= DMDFO_CENTER
; // DMDFO_STRETCH // DMDFO_DEFAULT
497 dmScreenSettings
.dmPelsWidth
= 640; // GuiData->ActiveBuffer->ViewSize.X * GuiData->CharWidth;
498 dmScreenSettings
.dmPelsHeight
= 480; // GuiData->ActiveBuffer->ViewSize.Y * GuiData->CharHeight;
499 dmScreenSettings
.dmBitsPerPel
= 32;
500 dmScreenSettings
.dmFields
= DM_BITSPERPEL
| DM_PELSWIDTH
| DM_PELSHEIGHT
;
501 ChangeDisplaySettings(&dmScreenSettings
, CDS_FULLSCREEN
);
508 LeaveCriticalSection(&Console
->Lock
);
512 GuiConsoleHandleNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
514 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
521 DPRINT("GuiConsoleHandleNcCreate\n");
525 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
529 Console
= GuiData
->Console
;
531 GuiData
->hWindow
= hWnd
;
533 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->GuiInfo
.FontSize
),
534 0, // HIWORD(GuiData->GuiInfo.FontSize),
537 GuiData
->GuiInfo
.FontWeight
,
544 NONANTIALIASED_QUALITY
,
545 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
546 GuiData
->GuiInfo
.FaceName
);
548 if (NULL
== GuiData
->Font
)
550 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
551 GuiData
->hWindow
= NULL
;
552 SetEvent(GuiData
->hGuiInitEvent
);
555 Dc
= GetDC(GuiData
->hWindow
);
558 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
559 DeleteObject(GuiData
->Font
);
560 GuiData
->hWindow
= NULL
;
561 SetEvent(GuiData
->hGuiInitEvent
);
564 OldFont
= SelectObject(Dc
, GuiData
->Font
);
567 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
568 ReleaseDC(GuiData
->hWindow
, Dc
);
569 DeleteObject(GuiData
->Font
);
570 GuiData
->hWindow
= NULL
;
571 SetEvent(GuiData
->hGuiInitEvent
);
574 if (!GetTextMetricsW(Dc
, &Metrics
))
576 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
577 SelectObject(Dc
, OldFont
);
578 ReleaseDC(GuiData
->hWindow
, Dc
);
579 DeleteObject(GuiData
->Font
);
580 GuiData
->hWindow
= NULL
;
581 SetEvent(GuiData
->hGuiInitEvent
);
584 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
585 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
587 /* Measure real char width more precisely if possible. */
588 if (GetTextExtentPoint32W(Dc
, L
"R", 1, &CharSize
))
589 GuiData
->CharWidth
= CharSize
.cx
;
591 SelectObject(Dc
, OldFont
);
593 ReleaseDC(GuiData
->hWindow
, Dc
);
595 // FIXME: Keep these instructions here ? ///////////////////////////////////
596 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
597 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
598 ////////////////////////////////////////////////////////////////////////////
600 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
602 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
603 GuiConsoleCreateSysMenu(GuiData
->hWindow
);
605 DPRINT("GuiConsoleHandleNcCreate - setting start event\n");
606 SetEvent(GuiData
->hGuiInitEvent
);
608 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
612 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
614 // PCONSOLE Console = GuiData->Console;
615 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
616 UINT WidthUnit
, HeightUnit
;
618 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
620 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
621 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
622 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
623 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
627 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
)
629 PGUI_CONSOLE_DATA GuiData
= Console
->TermIFace
.Data
;
630 RECT oldRect
, newRect
;
632 SmallRectToRect(GuiData
, &oldRect
, &Console
->Selection
.srSelection
);
637 /* exchange left/top with right/bottom if required */
638 rc
.Left
= min(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
639 rc
.Top
= min(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
640 rc
.Right
= max(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
641 rc
.Bottom
= max(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
643 SmallRectToRect(GuiData
, &newRect
, &rc
);
645 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
647 if (memcmp(&rc
, &Console
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
651 /* calculate the region that needs to be updated */
652 if ((rgn1
= CreateRectRgnIndirect(&oldRect
)))
654 if ((rgn2
= CreateRectRgnIndirect(&newRect
)))
656 if (CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
658 InvalidateRgn(GuiData
->hWindow
, rgn1
, FALSE
);
668 InvalidateRect(GuiData
->hWindow
, &newRect
, FALSE
);
670 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
671 Console
->Selection
.srSelection
= rc
;
672 Console
->dwSelectionCursor
= *coord
;
673 ConioPause(Console
, PAUSED_FROM_SELECTION
);
677 /* clear the selection */
678 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
680 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
682 Console
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
683 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
689 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
690 PGUI_CONSOLE_DATA GuiData
,
694 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
695 PGUI_CONSOLE_DATA GuiData
,
700 GuiConsoleHandlePaint(PGUI_CONSOLE_DATA GuiData
)
703 PCONSOLE Console
= GuiData
->Console
;
704 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
708 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
713 // ActiveBuffer = ConDrvGetActiveScreenBuffer(Console);
714 ActiveBuffer
= GuiData
->ActiveBuffer
;
716 hDC
= BeginPaint(GuiData
->hWindow
, &ps
);
718 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
719 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
721 EnterCriticalSection(&GuiData
->Lock
);
723 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
725 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
726 GuiData
, hDC
, &ps
.rcPaint
);
728 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
730 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
731 GuiData
, hDC
, &ps
.rcPaint
);
734 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
737 SmallRectToRect(GuiData
, &rc
, &Console
->Selection
.srSelection
);
739 /* invert the selection */
740 if (IntersectRect(&rc
, &ps
.rcPaint
, &rc
))
751 LeaveCriticalSection(&GuiData
->Lock
);
753 EndPaint(GuiData
->hWindow
, &ps
);
757 LeaveCriticalSection(&Console
->Lock
);
759 DefWindowProcW(GuiData
->hWindow
, WM_PAINT
, 0, 0);
765 IsSystemKey(WORD VirtualKeyCode
)
767 switch (VirtualKeyCode
)
769 /* From MSDN, "Virtual-Key Codes" */
788 GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
790 PCONSOLE Console
= GuiData
->Console
;
791 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
793 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
795 // ActiveBuffer = ConDrvGetActiveScreenBuffer(Console);
796 ActiveBuffer
= GuiData
->ActiveBuffer
;
798 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
800 WORD VirtualKeyCode
= LOWORD(wParam
);
802 if (msg
!= WM_KEYDOWN
) goto Quit
;
804 if (VirtualKeyCode
== VK_RETURN
)
806 /* Copy (and clear) selection if ENTER is pressed */
807 GuiConsoleCopy(GuiData
);
810 else if ( VirtualKeyCode
== VK_ESCAPE
||
811 (VirtualKeyCode
== 'C' && GetKeyState(VK_CONTROL
) & 0x8000) )
813 /* Cancel selection if ESC or Ctrl-C are pressed */
814 GuiConsoleUpdateSelection(Console
, NULL
);
815 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
820 if ((Console
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
822 /* Keyboard selection mode */
823 BOOL Interpreted
= FALSE
;
824 BOOL MajPressed
= (GetKeyState(VK_SHIFT
) & 0x8000);
826 switch (VirtualKeyCode
)
831 if (Console
->dwSelectionCursor
.X
> 0)
832 Console
->dwSelectionCursor
.X
--;
840 if (Console
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
841 Console
->dwSelectionCursor
.X
++;
849 if (Console
->dwSelectionCursor
.Y
> 0)
850 Console
->dwSelectionCursor
.Y
--;
858 if (Console
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
859 Console
->dwSelectionCursor
.Y
++;
867 Console
->dwSelectionCursor
.X
= 0;
868 Console
->dwSelectionCursor
.Y
= 0;
875 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
882 Console
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
883 if (Console
->dwSelectionCursor
.Y
< 0)
884 Console
->dwSelectionCursor
.Y
= 0;
892 Console
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
893 if (Console
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
894 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
906 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
908 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
910 else if (!IsSystemKey(VirtualKeyCode
))
912 /* Emit an error beep sound */
913 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
920 /* Mouse selection mode */
922 if (!IsSystemKey(VirtualKeyCode
))
924 /* Clear the selection and send the key into the input buffer */
925 GuiConsoleUpdateSelection(Console
, NULL
);
926 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
935 if ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
939 Message
.hwnd
= GuiData
->hWindow
;
940 Message
.message
= msg
;
941 Message
.wParam
= wParam
;
942 Message
.lParam
= lParam
;
944 ConioProcessKey(Console
, &Message
);
948 LeaveCriticalSection(&Console
->Lock
);
952 GuiInvalidateCell(IN OUT PFRONTEND This
, SHORT x
, SHORT y
)
954 SMALL_RECT CellRect
= { x
, y
, x
, y
};
955 GuiDrawRegion(This
, &CellRect
);
959 GuiConsoleHandleTimer(PGUI_CONSOLE_DATA GuiData
)
961 PCONSOLE Console
= GuiData
->Console
;
962 PCONSOLE_SCREEN_BUFFER Buff
;
964 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
966 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
968 Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
970 if (GetType(Buff
) == TEXTMODE_BUFFER
)
972 GuiInvalidateCell(&Console
->TermIFace
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
973 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
975 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) || (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
978 int OldScrollX
= -1, OldScrollY
= -1;
979 int NewScrollX
= -1, NewScrollY
= -1;
981 xScroll
.cbSize
= sizeof(SCROLLINFO
);
982 xScroll
.fMask
= SIF_POS
;
983 // Capture the original position of the scroll bars and save them.
984 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
985 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
987 // If we successfully got the info for the horizontal scrollbar
990 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) || (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
992 // Handle the horizontal scroll bar
993 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
) NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
998 NewScrollX
= OldScrollX
;
1001 // If we successfully got the info for the vertical scrollbar
1002 if (OldScrollY
>= 0)
1004 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) || (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
1006 // Handle the vertical scroll bar
1007 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
) NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
1008 else NewScrollY
= 0;
1012 NewScrollY
= OldScrollY
;
1016 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1017 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1018 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1019 // and their associated scrollbar is left alone.
1020 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
1022 Buff
->ViewOrigin
.X
= NewScrollX
;
1023 Buff
->ViewOrigin
.Y
= NewScrollY
;
1024 ScrollWindowEx(GuiData
->hWindow
,
1025 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
1026 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1032 if (NewScrollX
>= 0)
1034 xScroll
.nPos
= NewScrollX
;
1035 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1037 if (NewScrollY
>= 0)
1039 xScroll
.nPos
= NewScrollY
;
1040 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1042 UpdateWindow(GuiData
->hWindow
);
1043 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1044 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1048 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1052 LeaveCriticalSection(&Console
->Lock
);
1056 GuiConsoleHandleClose(PGUI_CONSOLE_DATA GuiData
)
1058 PCONSOLE Console
= GuiData
->Console
;
1060 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1063 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1066 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1067 * We shouldn't wait here, though, since the console lock is entered.
1068 * A copy of the thread list probably needs to be made.
1070 ConDrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1072 LeaveCriticalSection(&Console
->Lock
);
1077 GuiConsoleHandleNcDestroy(HWND hWnd
)
1079 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1080 GetSystemMenu(hWnd
, TRUE
);
1082 /* Free the GuiData registration */
1083 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1085 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1089 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1091 // PCONSOLE Console = GuiData->Console;
1092 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
1094 UINT WidthUnit
, HeightUnit
;
1096 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1098 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1099 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1101 /* Clip coordinate to ensure it's inside buffer */
1104 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1105 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1109 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1110 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1116 GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1119 PCONSOLE Console
= GuiData
->Console
;
1121 if (GuiData
->IgnoreNextMouseSignal
)
1123 if (msg
!= WM_LBUTTONDOWN
&&
1124 msg
!= WM_MBUTTONDOWN
&&
1125 msg
!= WM_RBUTTONDOWN
)
1128 * If this mouse signal is not a button-down action,
1129 * then it is the last signal being ignored.
1131 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1136 * This mouse signal is a button-down action.
1137 * Ignore it and perform default action.
1144 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1150 if ( (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1151 (Console
->QuickEdit
) )
1155 case WM_LBUTTONDOWN
:
1157 LPWSTR WindowTitle
= NULL
;
1160 Console
->Selection
.dwSelectionAnchor
= PointToCoord(GuiData
, lParam
);
1161 SetCapture(GuiData
->hWindow
);
1162 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1163 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
1165 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
1166 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
1167 wcscpy(WindowTitle
, L
"Selection - ");
1168 wcscat(WindowTitle
, Console
->Title
.Buffer
);
1169 SetWindowText(GuiData
->hWindow
, WindowTitle
);
1170 ConsoleFreeHeap(WindowTitle
);
1179 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1181 c
= PointToCoord(GuiData
, lParam
);
1182 Console
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1183 GuiConsoleUpdateSelection(Console
, &c
);
1189 case WM_LBUTTONDBLCLK
:
1191 DPRINT1("Handle left-double-click for selecting a word\n");
1195 case WM_RBUTTONDOWN
:
1196 case WM_RBUTTONDBLCLK
:
1198 if (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1200 GuiConsolePaste(GuiData
);
1204 GuiConsoleCopy(GuiData
);
1207 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1215 if (!(wParam
& MK_LBUTTON
)) break;
1216 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1218 c
= PointToCoord(GuiData
, lParam
); /* TODO: Scroll buffer to bring c into view */
1219 GuiConsoleUpdateSelection(Console
, &c
);
1225 Err
= FALSE
; // TRUE;
1229 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1232 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1233 DWORD dwButtonState
= 0;
1234 DWORD dwControlKeyState
= 0;
1235 DWORD dwEventFlags
= 0;
1239 case WM_LBUTTONDOWN
:
1240 SetCapture(GuiData
->hWindow
);
1241 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1245 case WM_MBUTTONDOWN
:
1246 SetCapture(GuiData
->hWindow
);
1247 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1251 case WM_RBUTTONDOWN
:
1252 SetCapture(GuiData
->hWindow
);
1253 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1275 case WM_LBUTTONDBLCLK
:
1276 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1277 dwEventFlags
= DOUBLE_CLICK
;
1280 case WM_MBUTTONDBLCLK
:
1281 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1282 dwEventFlags
= DOUBLE_CLICK
;
1285 case WM_RBUTTONDBLCLK
:
1286 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1287 dwEventFlags
= DOUBLE_CLICK
;
1292 dwEventFlags
= MOUSE_MOVED
;
1296 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1297 dwEventFlags
= MOUSE_WHEELED
;
1300 case WM_MOUSEHWHEEL
:
1301 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1302 dwEventFlags
= MOUSE_HWHEELED
;
1312 if (wKeyState
& MK_LBUTTON
)
1313 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1314 if (wKeyState
& MK_MBUTTON
)
1315 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1316 if (wKeyState
& MK_RBUTTON
)
1317 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1319 if (GetKeyState(VK_RMENU
) & 0x8000)
1320 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1321 if (GetKeyState(VK_LMENU
) & 0x8000)
1322 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1323 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1324 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1325 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1326 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1327 if (GetKeyState(VK_SHIFT
) & 0x8000)
1328 dwControlKeyState
|= SHIFT_PRESSED
;
1329 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1330 dwControlKeyState
|= NUMLOCK_ON
;
1331 if (GetKeyState(VK_SCROLL
) & 0x0001)
1332 dwControlKeyState
|= SCROLLLOCK_ON
;
1333 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1334 dwControlKeyState
|= CAPSLOCK_ON
;
1335 /* See WM_CHAR MSDN documentation for instance */
1336 if (lParam
& 0x01000000)
1337 dwControlKeyState
|= ENHANCED_KEY
;
1339 er
.EventType
= MOUSE_EVENT
;
1340 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1341 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1342 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1343 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1345 ConioProcessInputEvent(Console
, &er
);
1353 LeaveCriticalSection(&Console
->Lock
);
1357 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1362 VOID
GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1363 VOID
GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1366 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
)
1368 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1370 PCONSOLE Console
= GuiData
->Console
;
1371 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
1373 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1375 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1377 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1379 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1384 /* Clear the selection */
1385 GuiConsoleUpdateSelection(Console
, NULL
);
1386 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
1390 VOID
GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1391 VOID
GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1394 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
)
1396 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1398 // PCONSOLE Console = GuiData->Console;
1399 PCONSOLE_SCREEN_BUFFER Buffer
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
1401 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1403 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1405 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1407 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1415 GuiConsoleGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1417 PCONSOLE Console
= GuiData
->Console
;
1418 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1420 UINT WidthUnit
, HeightUnit
;
1422 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1424 // ActiveBuffer = ConDrvGetActiveScreenBuffer(Console);
1425 ActiveBuffer
= GuiData
->ActiveBuffer
;
1427 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1429 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1430 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1432 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1433 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1435 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1436 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1438 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1439 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1441 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1442 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1444 LeaveCriticalSection(&Console
->Lock
);
1448 GuiConsoleResize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1450 PCONSOLE Console
= GuiData
->Console
;
1452 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1454 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1455 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1457 PCONSOLE_SCREEN_BUFFER Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
1458 DWORD windx
, windy
, charx
, chary
;
1459 UINT WidthUnit
, HeightUnit
;
1461 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1463 GuiData
->WindowSizeLock
= TRUE
;
1465 windx
= LOWORD(lParam
);
1466 windy
= HIWORD(lParam
);
1468 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1469 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1470 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1472 charx
= windx
/ (int)WidthUnit
;
1473 chary
= windy
/ (int)HeightUnit
;
1475 // Character alignment (round size up or down)
1476 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1477 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1479 // Compensate for added scroll bars in new window
1480 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1481 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1483 charx
= windx
/ (int)WidthUnit
;
1484 chary
= windy
/ (int)HeightUnit
;
1486 // Character alignment (round size up or down)
1487 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1488 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1491 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1493 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1494 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1497 GuiConsoleResizeWindow(GuiData
);
1499 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1500 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1501 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1502 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1504 GuiData
->WindowSizeLock
= FALSE
;
1507 LeaveCriticalSection(&Console
->Lock
);
1511 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1515 GuiConsoleHandleScrollbarMenu(VOID)
1519 hMenu = CreatePopupMenu();
1522 DPRINT("CreatePopupMenu failed\n");
1526 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1527 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1528 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1529 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1530 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1531 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1532 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1533 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1534 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1535 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1540 GuiConsoleHandleScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1542 PCONSOLE Console
= GuiData
->Console
;
1543 PCONSOLE_SCREEN_BUFFER Buff
;
1546 int old_pos
, Maximum
;
1549 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1551 Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(Console);
1553 if (uMsg
== WM_HSCROLL
)
1556 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1557 pShowXY
= &Buff
->ViewOrigin
.X
;
1562 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1563 pShowXY
= &Buff
->ViewOrigin
.Y
;
1566 /* set scrollbar sizes */
1567 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1568 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1570 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1572 old_pos
= sInfo
.nPos
;
1574 switch (LOWORD(wParam
))
1585 sInfo
.nPos
-= sInfo
.nPage
;
1589 sInfo
.nPos
+= sInfo
.nPage
;
1593 sInfo
.nPos
= sInfo
.nTrackPos
;
1594 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1597 case SB_THUMBPOSITION
:
1598 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1602 sInfo
.nPos
= sInfo
.nMin
;
1606 sInfo
.nPos
= sInfo
.nMax
;
1613 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1614 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1616 if (old_pos
!= sInfo
.nPos
)
1618 USHORT OldX
= Buff
->ViewOrigin
.X
;
1619 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1620 UINT WidthUnit
, HeightUnit
;
1622 *pShowXY
= sInfo
.nPos
;
1624 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1626 ScrollWindowEx(GuiData
->hWindow
,
1627 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1628 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1635 sInfo
.fMask
= SIF_POS
;
1636 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1638 UpdateWindow(GuiData
->hWindow
);
1642 LeaveCriticalSection(&Console
->Lock
);
1646 static LRESULT CALLBACK
1647 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1650 PGUI_CONSOLE_DATA GuiData
= NULL
;
1651 PCONSOLE Console
= NULL
;
1654 * - If it's the first time we create a window for the terminal,
1655 * just initialize it and return.
1657 * - If we are destroying the window, just do it and return.
1659 if (msg
== WM_NCCREATE
)
1661 return (LRESULT
)GuiConsoleHandleNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1663 else if (msg
== WM_NCDESTROY
)
1665 return GuiConsoleHandleNcDestroy(hWnd
);
1669 * Now the terminal window is initialized.
1670 * Get the terminal data via the window's data.
1671 * If there is no data, just go away.
1673 GuiData
= GuiGetGuiData(hWnd
);
1674 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1676 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
1677 if (GuiData
->ActiveBuffer
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1680 * Just retrieve a pointer to the console in case somebody needs it.
1681 * It is not NULL because it was checked in GuiGetGuiData.
1682 * Each helper function which needs the console has to validate and lock it.
1684 Console
= GuiData
->Console
;
1686 /* We have a console, start message dispatching */
1691 if (LOWORD(wParam
) == WA_CLICKACTIVE
) GuiData
->IgnoreNextMouseSignal
= TRUE
;
1696 if (GuiConsoleHandleClose(GuiData
)) goto Default
;
1700 GuiConsoleHandlePaint(GuiData
);
1710 case WM_SYSDEADCHAR
:
1712 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1713 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1715 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1716 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
) GuiConsoleSwitchFullScreen(GuiData
);
1720 GuiConsoleHandleKey(GuiData
, msg
, wParam
, lParam
);
1725 GuiConsoleHandleTimer(GuiData
);
1731 * The message was sent because we are manually triggering a change.
1732 * Check whether the mouse is indeed present on this console window
1733 * and take appropriate decisions.
1735 if (wParam
== -1 && lParam
== -1)
1740 /* Get the placement of the mouse */
1741 GetCursorPos(&mouseCoords
);
1743 /* On which window is placed the mouse ? */
1744 hWndHit
= WindowFromPoint(mouseCoords
);
1746 /* It's our window. Perform the hit-test to be used later on. */
1747 if (hWndHit
== hWnd
)
1749 wParam
= (WPARAM
)hWnd
;
1750 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1751 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1755 /* Set the mouse cursor only when we are in the client area */
1756 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1758 if (GuiData
->MouseCursorRefCount
>= 0)
1760 /* Show the cursor */
1761 SetCursor(GuiData
->hCursor
);
1765 /* Hide the cursor if the reference count is negative */
1776 case WM_LBUTTONDOWN
:
1777 case WM_MBUTTONDOWN
:
1778 case WM_RBUTTONDOWN
:
1782 case WM_LBUTTONDBLCLK
:
1783 case WM_MBUTTONDBLCLK
:
1784 case WM_RBUTTONDBLCLK
:
1787 case WM_MOUSEHWHEEL
:
1789 Result
= GuiConsoleHandleMouse(GuiData
, msg
, wParam
, lParam
);
1796 Result
= GuiConsoleHandleScroll(GuiData
, msg
, wParam
);
1800 case WM_NCRBUTTONDOWN
:
1802 DPRINT1("WM_NCRBUTTONDOWN\n");
1804 * HACK: !! Because, when we deal with WM_RBUTTON* and we do not
1805 * call after that DefWindowProc, on ReactOS, right-clicks on the
1806 * (non-client) application title-bar does not display the system
1807 * menu and does not trigger a WM_NCRBUTTONUP message too.
1808 * See: http://git.reactos.org/?p=reactos.git;a=blob;f=reactos/win32ss/user/user32/windows/defwnd.c;hb=HEAD#l1103
1809 * and line 1135 too.
1811 if (DefWindowProcW(hWnd
, WM_NCHITTEST
, 0, lParam
) == HTCAPTION
)
1813 /* Call DefWindowProcW with the WM_CONTEXTMENU message */
1814 msg
= WM_CONTEXTMENU
;
1818 // case WM_NCRBUTTONUP:
1819 // DPRINT1("WM_NCRBUTTONUP\n");
1822 case WM_CONTEXTMENU
:
1824 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
1826 HMENU hMenu
= CreatePopupMenu();
1829 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
1830 TrackPopupMenuEx(hMenu
,
1832 GET_X_LPARAM(lParam
),
1833 GET_Y_LPARAM(lParam
),
1848 HMENU hMenu
= (HMENU
)wParam
;
1851 /* Enable or disable the Close menu item */
1852 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
1853 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
1855 /* Enable or disable the Copy and Paste items */
1856 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
1857 ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1858 (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
1859 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
1860 (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1861 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
1864 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1866 GuiSendMenuEvent(Console
, WM_INITMENU
);
1867 LeaveCriticalSection(&Console
->Lock
);
1874 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
1876 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1878 GuiSendMenuEvent(Console
, WM_MENUSELECT
);
1879 LeaveCriticalSection(&Console
->Lock
);
1888 Result
= GuiConsoleHandleSysMenuCommand(GuiData
, wParam
, lParam
);
1895 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1897 BOOL SetFocus
= (msg
== WM_SETFOCUS
);
1900 er
.EventType
= FOCUS_EVENT
;
1901 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
1902 ConioProcessInputEvent(Console
, &er
);
1905 DPRINT1("TODO: Create console caret\n");
1907 DPRINT1("TODO: Destroy console caret\n");
1909 LeaveCriticalSection(&Console
->Lock
);
1914 case WM_GETMINMAXINFO
:
1915 GuiConsoleGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
1919 GuiConsoleResize(GuiData
, wParam
, lParam
);
1922 case PM_RESIZE_TERMINAL
:
1924 /* Resize the window to the user's values */
1925 GuiData
->WindowSizeLock
= TRUE
;
1926 GuiConsoleResizeWindow(GuiData
);
1927 GuiData
->WindowSizeLock
= FALSE
;
1931 case PM_APPLY_CONSOLE_INFO
:
1933 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1935 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
1936 LeaveCriticalSection(&Console
->Lock
);
1941 case PM_CONSOLE_BEEP
:
1942 DPRINT1("Beep !!\n");
1946 // case PM_CONSOLE_SET_TITLE:
1947 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
1951 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1960 /******************************************************************************
1961 * GUI Terminal Initialization *
1962 ******************************************************************************/
1964 static LRESULT CALLBACK
1965 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1975 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
1979 case PM_CREATE_CONSOLE
:
1981 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
1982 PCONSOLE Console
= GuiData
->Console
;
1984 NewWindow
= CreateWindowExW(WS_EX_CLIENTEDGE
,
1985 GUI_CONSOLE_WINDOW_CLASS
,
1986 Console
->Title
.Buffer
,
1987 WS_OVERLAPPEDWINDOW
| WS_HSCROLL
| WS_VSCROLL
,
1996 if (NULL
!= NewWindow
)
1998 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2000 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2002 DPRINT("Set icons via PM_CREATE_CONSOLE\n");
2003 if (GuiData
->hIcon
== NULL
)
2005 DPRINT("Not really /o\\...\n");
2006 GuiData
->hIcon
= ghDefaultIcon
;
2007 GuiData
->hIconSm
= ghDefaultIconSm
;
2009 else if (GuiData
->hIcon
!= ghDefaultIcon
)
2011 DPRINT("Yes \\o/\n");
2012 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2013 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2016 /* Move and resize the window to the user's values */
2017 /* CAN WE DEADLOCK ?? */
2018 GuiConsoleMoveWindow(GuiData
);
2019 GuiData
->WindowSizeLock
= TRUE
;
2020 GuiConsoleResizeWindow(GuiData
);
2021 GuiData
->WindowSizeLock
= FALSE
;
2023 // ShowWindow(NewWindow, (int)wParam);
2024 ShowWindowAsync(NewWindow
, (int)wParam
);
2025 DPRINT("Window showed\n");
2028 return (LRESULT
)NewWindow
;
2031 case PM_DESTROY_CONSOLE
:
2033 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2036 * Window creation is done using a PostMessage(), so it's possible
2037 * that the window that we want to destroy doesn't exist yet.
2038 * So first empty the message queue.
2041 while (PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE))
2043 TranslateMessage(&Msg);
2044 DispatchMessageW(&Msg);
2046 while (PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
)) ;
2048 if (GuiData
->hWindow
!= NULL
) /* && DestroyWindow(GuiData->hWindow) */
2050 DestroyWindow(GuiData
->hWindow
);
2052 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2054 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2055 if (0 == WindowCount
)
2058 DestroyWindow(hWnd
);
2059 DPRINT("CONSRV: Going to quit the Gui Thread!!\n");
2068 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2073 GuiConsoleGuiThread(PVOID Data
)
2076 PHANDLE GraphicsStartupEvent
= (PHANDLE
)Data
;
2079 * This thread dispatches all the console notifications to the notify window.
2080 * It is common for all the console windows.
2083 PrivateCsrssManualGuiCheck(+1);
2085 NotifyWnd
= CreateWindowW(L
"ConSrvCreateNotify",
2087 WS_OVERLAPPEDWINDOW
,
2096 if (NULL
== NotifyWnd
)
2098 PrivateCsrssManualGuiCheck(-1);
2099 SetEvent(*GraphicsStartupEvent
);
2103 SetEvent(*GraphicsStartupEvent
);
2105 while (GetMessageW(&msg
, NULL
, 0, 0))
2107 TranslateMessage(&msg
);
2108 DispatchMessageW(&msg
);
2111 DPRINT("CONSRV: Quit the Gui Thread!!\n");
2112 PrivateCsrssManualGuiCheck(-1);
2121 ATOM ConsoleClassAtom
;
2123 /* Exit if we were already initialized */
2124 // if (ConsInitialized) return TRUE;
2127 * Initialize and register the different window classes, if needed.
2129 if (!ConsInitialized
)
2131 /* Initialize the notification window class */
2132 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2133 wc
.lpszClassName
= L
"ConSrvCreateNotify";
2134 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
2136 wc
.hInstance
= ConSrvDllInstance
;
2140 wc
.hbrBackground
= NULL
;
2141 wc
.lpszMenuName
= NULL
;
2144 if (RegisterClassExW(&wc
) == 0)
2146 DPRINT1("Failed to register GUI notify wndproc\n");
2150 /* Initialize the console window class */
2151 ghDefaultIcon
= LoadImageW(ConSrvDllInstance
,
2152 MAKEINTRESOURCEW(IDI_TERMINAL
),
2154 GetSystemMetrics(SM_CXICON
),
2155 GetSystemMetrics(SM_CYICON
),
2157 ghDefaultIconSm
= LoadImageW(ConSrvDllInstance
,
2158 MAKEINTRESOURCEW(IDI_TERMINAL
),
2160 GetSystemMetrics(SM_CXSMICON
),
2161 GetSystemMetrics(SM_CYSMICON
),
2163 ghDefaultCursor
= LoadCursorW(NULL
, IDC_ARROW
);
2164 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2165 wc
.lpszClassName
= GUI_CONSOLE_WINDOW_CLASS
;
2166 wc
.lpfnWndProc
= GuiConsoleWndProc
;
2167 wc
.style
= CS_DBLCLKS
/* | CS_HREDRAW | CS_VREDRAW */;
2168 wc
.hInstance
= ConSrvDllInstance
;
2169 wc
.hIcon
= ghDefaultIcon
;
2170 wc
.hIconSm
= ghDefaultIconSm
;
2171 wc
.hCursor
= ghDefaultCursor
;
2172 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
); // The color of a terminal when it is switch off.
2173 wc
.lpszMenuName
= NULL
;
2175 wc
.cbWndExtra
= GWLP_CONSOLEWND_ALLOC
;
2177 ConsoleClassAtom
= RegisterClassExW(&wc
);
2178 if (ConsoleClassAtom
== 0)
2180 DPRINT1("Failed to register GUI console wndproc\n");
2185 NtUserConsoleControl(GuiConsoleWndClassAtom
, &ConsoleClassAtom
, sizeof(ATOM
));
2188 ConsInitialized
= TRUE
;
2192 * Set-up the notification window
2194 if (NULL
== NotifyWnd
)
2196 HANDLE ThreadHandle
;
2197 HANDLE GraphicsStartupEvent
;
2199 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2200 if (NULL
== GraphicsStartupEvent
) return FALSE
;
2202 ThreadHandle
= CreateThread(NULL
,
2204 GuiConsoleGuiThread
,
2205 (PVOID
)&GraphicsStartupEvent
,
2208 if (NULL
== ThreadHandle
)
2210 CloseHandle(GraphicsStartupEvent
);
2211 DPRINT1("CONSRV: Failed to create graphics console thread. Expect problems\n");
2214 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
2215 CloseHandle(ThreadHandle
);
2217 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
2218 CloseHandle(GraphicsStartupEvent
);
2220 if (NULL
== NotifyWnd
)
2222 DPRINT1("CONSRV: Failed to create notification window.\n");
2227 // ConsInitialized = TRUE;
2234 /******************************************************************************
2235 * GUI Console Driver *
2236 ******************************************************************************/
2239 GuiDeinitFrontEnd(IN OUT PFRONTEND This
);
2242 GuiInitFrontEnd(IN OUT PFRONTEND This
,
2243 IN PCONSOLE Console
)
2245 PGUI_INIT_INFO GuiInitInfo
;
2246 PCONSOLE_INFO ConsoleInfo
;
2247 PCONSOLE_START_INFO ConsoleStartInfo
;
2249 PGUI_CONSOLE_DATA GuiData
;
2250 GUI_CONSOLE_INFO TermInfo
;
2253 LPWSTR IconPath
= NULL
;
2256 if (This
== NULL
|| Console
== NULL
|| This
->OldData
== NULL
)
2257 return STATUS_INVALID_PARAMETER
;
2259 ASSERT(This
->Console
== Console
);
2261 GuiInitInfo
= This
->OldData
;
2263 if (GuiInitInfo
->ConsoleInfo
== NULL
|| GuiInitInfo
->ConsoleStartInfo
== NULL
)
2264 return STATUS_INVALID_PARAMETER
;
2266 ConsoleInfo
= GuiInitInfo
->ConsoleInfo
;
2267 ConsoleStartInfo
= GuiInitInfo
->ConsoleStartInfo
;
2269 IconPath
= ConsoleStartInfo
->IconPath
;
2270 IconIndex
= ConsoleStartInfo
->IconIndex
;
2273 /* Terminal data allocation */
2274 GuiData
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_CONSOLE_DATA
));
2277 DPRINT1("CONSRV: Failed to create GUI_CONSOLE_DATA\n");
2278 return STATUS_UNSUCCESSFUL
;
2280 /* HACK */ Console
->TermIFace
.Data
= (PVOID
)GuiData
; /* HACK */
2281 GuiData
->Console
= Console
;
2282 GuiData
->ActiveBuffer
= Console
->ActiveBuffer
;
2283 GuiData
->hWindow
= NULL
;
2285 /* The console can be resized */
2286 Console
->FixedSize
= FALSE
;
2288 InitializeCriticalSection(&GuiData
->Lock
);
2292 * Load terminal settings
2295 /* 1. Load the default settings */
2296 GuiConsoleGetDefaultSettings(&TermInfo
, GuiInitInfo
->ProcessId
);
2298 /* 3. Load the remaining console settings via the registry. */
2299 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2301 /* Load the terminal infos from the registry. */
2302 GuiConsoleReadUserSettings(&TermInfo
,
2303 ConsoleInfo
->ConsoleTitle
,
2304 GuiInitInfo
->ProcessId
);
2307 * Now, update them with the properties the user might gave to us
2308 * via the STARTUPINFO structure before calling CreateProcess
2309 * (and which was transmitted via the ConsoleStartInfo structure).
2310 * We therefore overwrite the values read in the registry.
2312 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USESHOWWINDOW
)
2314 TermInfo
.ShowWindow
= ConsoleStartInfo
->wShowWindow
;
2316 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USEPOSITION
)
2318 TermInfo
.AutoPosition
= FALSE
;
2319 TermInfo
.WindowOrigin
.x
= ConsoleStartInfo
->dwWindowOrigin
.X
;
2320 TermInfo
.WindowOrigin
.y
= ConsoleStartInfo
->dwWindowOrigin
.Y
;
2322 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_RUNFULLSCREEN
)
2324 TermInfo
.FullScreen
= TRUE
;
2333 Length
= min(wcslen(TermInfo
.FaceName
) + 1, LF_FACESIZE
); // wcsnlen
2334 wcsncpy(GuiData
->GuiInfo
.FaceName
, TermInfo
.FaceName
, LF_FACESIZE
);
2335 GuiData
->GuiInfo
.FaceName
[Length
] = L
'\0';
2336 GuiData
->GuiInfo
.FontFamily
= TermInfo
.FontFamily
;
2337 GuiData
->GuiInfo
.FontSize
= TermInfo
.FontSize
;
2338 GuiData
->GuiInfo
.FontWeight
= TermInfo
.FontWeight
;
2339 GuiData
->GuiInfo
.UseRasterFonts
= TermInfo
.UseRasterFonts
;
2340 GuiData
->GuiInfo
.FullScreen
= TermInfo
.FullScreen
;
2341 GuiData
->GuiInfo
.ShowWindow
= TermInfo
.ShowWindow
;
2342 GuiData
->GuiInfo
.AutoPosition
= TermInfo
.AutoPosition
;
2343 GuiData
->GuiInfo
.WindowOrigin
= TermInfo
.WindowOrigin
;
2345 /* Initialize the icon handles to their default values */
2346 GuiData
->hIcon
= ghDefaultIcon
;
2347 GuiData
->hIconSm
= ghDefaultIconSm
;
2349 /* Get the associated icon, if any */
2350 if (IconPath
== NULL
|| IconPath
[0] == L
'\0')
2352 IconPath
= ConsoleStartInfo
->AppPath
;
2355 DPRINT("IconPath = %S ; IconIndex = %lu\n", (IconPath
? IconPath
: L
"n/a"), IconIndex
);
2356 if (IconPath
&& IconPath
[0] != L
'\0')
2358 HICON hIcon
= NULL
, hIconSm
= NULL
;
2359 PrivateExtractIconExW(IconPath
,
2364 DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon
, hIconSm
);
2367 DPRINT("Effectively set the icons\n");
2368 GuiData
->hIcon
= hIcon
;
2369 GuiData
->hIconSm
= hIconSm
;
2373 /* Mouse is shown by default with its default cursor shape */
2374 GuiData
->hCursor
= ghDefaultCursor
;
2375 GuiData
->MouseCursorRefCount
= 0;
2377 /* A priori don't ignore mouse signals */
2378 GuiData
->IgnoreNextMouseSignal
= FALSE
;
2380 /* Close button and the corresponding system menu item are enabled by default */
2381 GuiData
->IsCloseButtonEnabled
= TRUE
;
2383 /* There is no user-reserved menu id range by default */
2384 GuiData
->cmdIdLow
= GuiData
->cmdIdHigh
= 0;
2387 * We need to wait until the GUI has been fully initialized
2388 * to retrieve custom settings i.e. WindowSize etc...
2389 * Ideally we could use SendNotifyMessage for this but its not
2392 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2394 DPRINT("GUI - Checkpoint\n");
2396 /* Create the terminal window */
2397 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, GuiData
->GuiInfo
.ShowWindow
, (LPARAM
)GuiData
);
2399 /* Wait until initialization has finished */
2400 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
2401 DPRINT("OK we created the console window\n");
2402 CloseHandle(GuiData
->hGuiInitEvent
);
2403 GuiData
->hGuiInitEvent
= NULL
;
2405 /* Check whether we really succeeded in initializing the terminal window */
2406 if (GuiData
->hWindow
== NULL
)
2408 DPRINT("GuiInitConsole - We failed at creating a new terminal window\n");
2409 GuiDeinitFrontEnd(This
);
2410 return STATUS_UNSUCCESSFUL
;
2413 /* Finally, finish to initialize the frontend structure */
2414 This
->Data
= GuiData
;
2415 if (This
->OldData
) ConsoleFreeHeap(This
->OldData
);
2416 This
->OldData
= NULL
;
2418 return STATUS_SUCCESS
;
2422 GuiDeinitFrontEnd(IN OUT PFRONTEND This
)
2424 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2426 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
)GuiData
);
2428 DPRINT("Destroying icons !! - GuiData->hIcon = 0x%p ; ghDefaultIcon = 0x%p ; GuiData->hIconSm = 0x%p ; ghDefaultIconSm = 0x%p\n",
2429 GuiData
->hIcon
, ghDefaultIcon
, GuiData
->hIconSm
, ghDefaultIconSm
);
2430 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2432 DPRINT("Destroy hIcon\n");
2433 DestroyIcon(GuiData
->hIcon
);
2435 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2437 DPRINT("Destroy hIconSm\n");
2438 DestroyIcon(GuiData
->hIconSm
);
2442 DeleteCriticalSection(&GuiData
->Lock
);
2443 ConsoleFreeHeap(GuiData
);
2445 DPRINT("Quit GuiDeinitFrontEnd\n");
2449 GuiDrawRegion(IN OUT PFRONTEND This
,
2452 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2455 SmallRectToRect(GuiData
, &RegionRect
, Region
);
2456 /* Do not erase the background: it speeds up redrawing and reduce flickering */
2457 InvalidateRect(GuiData
->hWindow
, &RegionRect
, FALSE
);
2461 GuiWriteStream(IN OUT PFRONTEND This
,
2469 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2470 PCONSOLE_SCREEN_BUFFER Buff
;
2471 SHORT CursorEndX
, CursorEndY
;
2474 if (NULL
== GuiData
|| NULL
== GuiData
->hWindow
) return;
2476 Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(GuiData->Console);
2477 if (GetType(Buff
) != TEXTMODE_BUFFER
) return;
2479 if (0 != ScrolledLines
)
2481 ScrollRect
.left
= 0;
2483 ScrollRect
.right
= Buff
->ViewSize
.X
* GuiData
->CharWidth
;
2484 ScrollRect
.bottom
= Region
->Top
* GuiData
->CharHeight
;
2486 ScrollWindowEx(GuiData
->hWindow
,
2488 -(int)(ScrolledLines
* GuiData
->CharHeight
),
2496 GuiDrawRegion(This
, Region
);
2498 if (CursorStartX
< Region
->Left
|| Region
->Right
< CursorStartX
2499 || CursorStartY
< Region
->Top
|| Region
->Bottom
< CursorStartY
)
2501 GuiInvalidateCell(This
, CursorStartX
, CursorStartY
);
2504 CursorEndX
= Buff
->CursorPosition
.X
;
2505 CursorEndY
= Buff
->CursorPosition
.Y
;
2506 if ((CursorEndX
< Region
->Left
|| Region
->Right
< CursorEndX
2507 || CursorEndY
< Region
->Top
|| Region
->Bottom
< CursorEndY
)
2508 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
2510 GuiInvalidateCell(This
, CursorEndX
, CursorEndY
);
2513 // Set up the update timer (very short interval) - this is a "hack" for getting the OS to
2514 // repaint the window without having it just freeze up and stay on the screen permanently.
2515 Buff
->CursorBlinkOn
= TRUE
;
2516 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
2520 GuiSetCursorInfo(IN OUT PFRONTEND This
,
2521 PCONSOLE_SCREEN_BUFFER Buff
)
2523 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2525 if (/*ConDrvGetActiveScreenBuffer(GuiData->Console)*/GuiData
->ActiveBuffer
== Buff
)
2527 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2534 GuiSetScreenInfo(IN OUT PFRONTEND This
,
2535 PCONSOLE_SCREEN_BUFFER Buff
,
2539 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2541 if (/*ConDrvGetActiveScreenBuffer(GuiData->Console)*/GuiData
->ActiveBuffer
== Buff
)
2543 /* Redraw char at old position (remove cursor) */
2544 GuiInvalidateCell(This
, OldCursorX
, OldCursorY
);
2545 /* Redraw char at new position (show cursor) */
2546 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2553 GuiResizeTerminal(IN OUT PFRONTEND This
)
2555 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2557 /* Resize the window to the user's values */
2558 // GuiData->WindowSizeLock = TRUE;
2559 // GuiConsoleResizeWindow(GuiData);
2560 // GuiData->WindowSizeLock = FALSE;
2561 // NOTE: This code ^^ causes deadlocks...
2563 PostMessageW(GuiData
->hWindow
, PM_RESIZE_TERMINAL
, 0, 0);
2567 GuiSetActiveScreenBuffer(IN OUT PFRONTEND This
)
2569 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2571 EnterCriticalSection(&GuiData
->Lock
);
2572 GuiData
->WindowSizeLock
= TRUE
;
2574 InterlockedExchangePointer(&GuiData
->ActiveBuffer
,
2575 GuiData
->Console
->ActiveBuffer
);
2577 GuiData
->WindowSizeLock
= FALSE
;
2578 LeaveCriticalSection(&GuiData
->Lock
);
2580 GuiResizeTerminal(This
);
2581 // ConioDrawConsole(Console);
2583 // FIXME: Change the palette.
2587 GuiReleaseScreenBuffer(IN OUT PFRONTEND This
,
2588 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
)
2590 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2593 * If we were notified to release a screen buffer that is not actually
2594 * ours, then just ignore the notification...
2596 if (ScreenBuffer
!= GuiData
->ActiveBuffer
) return;
2599 * ... else, we must release our active buffer. Two cases are present:
2600 * - If ScreenBuffer (== GuiData->ActiveBuffer) IS NOT the console
2601 * active screen buffer, then we can safely switch to it.
2602 * - If ScreenBuffer IS the console active screen buffer, we must release
2606 if (ScreenBuffer
!= GuiData
->Console
->ActiveBuffer
)
2608 GuiSetActiveScreenBuffer(This
);
2612 EnterCriticalSection(&GuiData
->Lock
);
2613 GuiData
->WindowSizeLock
= TRUE
;
2615 InterlockedExchangePointer(&GuiData
->ActiveBuffer
, NULL
);
2617 GuiData
->WindowSizeLock
= FALSE
;
2618 LeaveCriticalSection(&GuiData
->Lock
);
2623 GuiProcessKeyCallback(IN OUT PFRONTEND This
,
2627 UINT VirtualKeyCode
,
2630 if ((ShiftState
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
) || KeyStateMenu
& 0x80) &&
2631 (VirtualKeyCode
== VK_ESCAPE
|| VirtualKeyCode
== VK_TAB
|| VirtualKeyCode
== VK_SPACE
))
2633 DefWindowProcW(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2641 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2645 GuiRefreshInternalInfo(IN OUT PFRONTEND This
)
2647 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2649 /* Update the console leader information held by the window */
2650 SetConsoleWndConsoleLeaderCID(GuiData
);
2654 * We reset the cursor here so that, when a console app quits, we reset
2655 * the cursor to the default one. It's quite a hack since it doesn't proceed
2656 * per - console process... This must be fixed.
2658 * See GuiInitConsole(...) for more information.
2661 /* Mouse is shown by default with its default cursor shape */
2662 GuiData
->MouseCursorRefCount
= 0; // Reinitialize the reference counter
2663 GuiSetMouseCursor(This
, NULL
);
2667 GuiChangeTitle(IN OUT PFRONTEND This
)
2669 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2670 // PostMessageW(GuiData->hWindow, PM_CONSOLE_SET_TITLE, 0, 0);
2671 SetWindowText(GuiData
->hWindow
, GuiData
->Console
->Title
.Buffer
);
2675 GuiChangeIcon(IN OUT PFRONTEND This
,
2678 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2679 HICON hIcon
, hIconSm
;
2681 if (hWindowIcon
== NULL
)
2683 hIcon
= ghDefaultIcon
;
2684 hIconSm
= ghDefaultIconSm
;
2688 hIcon
= CopyIcon(hWindowIcon
);
2689 hIconSm
= CopyIcon(hWindowIcon
);
2697 if (hIcon
!= GuiData
->hIcon
)
2699 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2701 DestroyIcon(GuiData
->hIcon
);
2703 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2705 DestroyIcon(GuiData
->hIconSm
);
2708 GuiData
->hIcon
= hIcon
;
2709 GuiData
->hIconSm
= hIconSm
;
2711 DPRINT("Set icons in GuiChangeIcon\n");
2712 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2713 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2720 GuiGetConsoleWindowHandle(IN OUT PFRONTEND This
)
2722 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2723 return GuiData
->hWindow
;
2727 GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This
,
2730 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2731 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
2734 UINT WidthUnit
, HeightUnit
;
2738 if (!SystemParametersInfoW(SPI_GETWORKAREA
, 0, &WorkArea
, 0))
2740 DPRINT1("SystemParametersInfoW failed - What to do ??\n");
2744 // ActiveBuffer = ConDrvGetActiveScreenBuffer(GuiData->Console);
2745 ActiveBuffer
= GuiData
->ActiveBuffer
;
2748 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
2752 /* Default: text mode */
2753 WidthUnit
= GuiData
->CharWidth
;
2754 HeightUnit
= GuiData
->CharHeight
;
2757 width
= WorkArea
.right
;
2758 height
= WorkArea
.bottom
;
2760 width
-= (2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
)));
2761 height
-= (2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
));
2763 if (width
< 0) width
= 0;
2764 if (height
< 0) height
= 0;
2766 pSize
->X
= (SHORT
)(width
/ (int)WidthUnit
) /* HACK */ + 2;
2767 pSize
->Y
= (SHORT
)(height
/ (int)HeightUnit
) /* HACK */ + 1;
2771 GuiGetDisplayMode(IN OUT PFRONTEND This
)
2773 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2774 ULONG DisplayMode
= 0;
2776 if (GuiData
->GuiInfo
.FullScreen
)
2777 DisplayMode
|= CONSOLE_FULLSCREEN_HARDWARE
; // CONSOLE_FULLSCREEN
2779 DisplayMode
|= CONSOLE_WINDOWED
;
2785 GuiSetDisplayMode(IN OUT PFRONTEND This
,
2788 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2790 if (NewMode
& ~(CONSOLE_FULLSCREEN_MODE
| CONSOLE_WINDOWED_MODE
))
2793 GuiData
->GuiInfo
.FullScreen
= (NewMode
& CONSOLE_FULLSCREEN_MODE
);
2794 // TODO: Change the display mode
2799 GuiShowMouseCursor(IN OUT PFRONTEND This
,
2802 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2804 /* Set the reference count */
2805 if (Show
) ++GuiData
->MouseCursorRefCount
;
2806 else --GuiData
->MouseCursorRefCount
;
2808 /* Effectively show (or hide) the cursor (use special values for (w|l)Param) */
2809 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2811 return GuiData
->MouseCursorRefCount
;
2815 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2818 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2821 * Set the cursor's handle. If the given handle is NULL,
2822 * then restore the default cursor.
2824 GuiData
->hCursor
= (hCursor
? hCursor
: ghDefaultCursor
);
2826 /* Effectively modify the shape of the cursor (use special values for (w|l)Param) */
2827 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2833 GuiMenuControl(IN OUT PFRONTEND This
,
2837 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2839 GuiData
->cmdIdLow
= cmdIdLow
;
2840 GuiData
->cmdIdHigh
= cmdIdHigh
;
2842 return GetSystemMenu(GuiData
->hWindow
, FALSE
);
2846 GuiSetMenuClose(IN OUT PFRONTEND This
,
2850 * NOTE: See http://www.mail-archive.com/harbour@harbour-project.org/msg27509.html
2851 * or http://harbour-devel.1590103.n2.nabble.com/Question-about-hb-gt-win-CtrlHandler-usage-td4670862i20.html
2852 * for more information.
2855 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2856 HMENU hSysMenu
= GetSystemMenu(GuiData
->hWindow
, FALSE
);
2858 if (hSysMenu
== NULL
) return FALSE
;
2860 GuiData
->IsCloseButtonEnabled
= Enable
;
2861 EnableMenuItem(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| (Enable
? MF_ENABLED
: MF_GRAYED
));
2866 static FRONTEND_VTBL GuiVtbl
=
2875 GuiSetActiveScreenBuffer
,
2876 GuiReleaseScreenBuffer
,
2877 GuiProcessKeyCallback
,
2878 GuiRefreshInternalInfo
,
2881 GuiGetConsoleWindowHandle
,
2882 GuiGetLargestConsoleWindowSize
,
2893 LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo
,
2894 IN OUT PCONSOLE_INFO ConsoleInfo
)
2896 #define PATH_SEPARATOR L'\\'
2898 BOOL RetVal
= FALSE
;
2899 HRESULT hRes
= S_OK
;
2900 LPWSTR LinkName
= NULL
;
2903 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2906 ConsoleStartInfo
->IconPath
[0] = L
'\0';
2907 ConsoleStartInfo
->IconIndex
= 0;
2909 /* 1- Find the last path separator if any */
2910 LinkName
= wcsrchr(ConsoleStartInfo
->ConsoleTitle
, PATH_SEPARATOR
);
2911 if (LinkName
== NULL
)
2913 LinkName
= ConsoleStartInfo
->ConsoleTitle
;
2917 /* Skip the path separator */
2921 /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
2922 Length
= wcslen(LinkName
);
2923 if ( (Length
<= 4) || (wcsicmp(LinkName
+ (Length
- 4), L
".lnk") != 0) )
2926 /* 3- It may be a link. Try to retrieve some properties */
2927 hRes
= CoInitialize(NULL
);
2928 if (SUCCEEDED(hRes
))
2930 /* Get a pointer to the IShellLink interface */
2931 IShellLinkW
* pshl
= NULL
;
2932 hRes
= CoCreateInstance(&CLSID_ShellLink
,
2934 CLSCTX_INPROC_SERVER
,
2937 if (SUCCEEDED(hRes
))
2939 /* Get a pointer to the IPersistFile interface */
2940 IPersistFile
* ppf
= NULL
;
2941 hRes
= IPersistFile_QueryInterface(pshl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
2942 if (SUCCEEDED(hRes
))
2944 /* Load the shortcut */
2945 hRes
= IPersistFile_Load(ppf
, ConsoleStartInfo
->ConsoleTitle
, STGM_READ
);
2946 if (SUCCEEDED(hRes
))
2949 * Finally we can get the properties !
2950 * Update the old ones if needed.
2955 /* Reset the name of the console with the name of the shortcut */
2956 Length
= min(/*Length*/ Length
- 4, // 4 == len(".lnk")
2957 sizeof(ConsoleInfo
->ConsoleTitle
) / sizeof(ConsoleInfo
->ConsoleTitle
[0]) - 1);
2958 wcsncpy(ConsoleInfo
->ConsoleTitle
, LinkName
, Length
);
2959 ConsoleInfo
->ConsoleTitle
[Length
] = L
'\0';
2961 /* Get the window showing command */
2962 hRes
= IShellLinkW_GetShowCmd(pshl
, &ShowCmd
);
2963 if (SUCCEEDED(hRes
)) ConsoleStartInfo
->wShowWindow
= (WORD
)ShowCmd
;
2965 /* Get the hotkey */
2966 // hRes = pshl->GetHotkey(&ShowCmd);
2967 // if (SUCCEEDED(hRes)) ConsoleStartInfo->HotKey = HotKey;
2969 /* Get the icon location, if any */
2971 hRes
= IShellLinkW_GetIconLocation(pshl
,
2972 ConsoleStartInfo
->IconPath
,
2973 sizeof(ConsoleStartInfo
->IconPath
)/sizeof(ConsoleStartInfo
->IconPath
[0]) - 1, // == MAX_PATH
2974 &ConsoleStartInfo
->IconIndex
);
2975 if (!SUCCEEDED(hRes
))
2977 ConsoleStartInfo
->IconPath
[0] = L
'\0';
2978 ConsoleStartInfo
->IconIndex
= 0;
2981 // FIXME: Since we still don't load console properties from the shortcut,
2982 // return false. When this will be done, we will return true instead.
2985 IPersistFile_Release(ppf
);
2987 IShellLinkW_Release(pshl
);
2996 GuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd
,
2997 IN OUT PCONSOLE_INFO ConsoleInfo
,
2998 IN OUT PVOID ExtraConsoleInfo
,
3001 PCONSOLE_START_INFO ConsoleStartInfo
= ExtraConsoleInfo
;
3002 PGUI_INIT_INFO GuiInitInfo
;
3004 if (FrontEnd
== NULL
|| ConsoleInfo
== NULL
|| ConsoleStartInfo
== NULL
)
3005 return STATUS_INVALID_PARAMETER
;
3007 /* Initialize GUI terminal emulator common functionalities */
3008 if (!GuiInit()) return STATUS_UNSUCCESSFUL
;
3011 * Load per-application terminal settings.
3013 * Check whether the process creating the console was launched via
3014 * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
3015 * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
3017 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
)
3019 if (!LoadShellLinkConsoleInfo(ConsoleStartInfo
, ConsoleInfo
))
3021 ConsoleStartInfo
->dwStartupFlags
&= ~STARTF_TITLEISLINKNAME
;
3026 * Initialize a private initialization info structure for later use.
3027 * It must be freed by a call to GuiUnloadFrontEnd or GuiInitFrontEnd.
3029 GuiInitInfo
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_INIT_INFO
));
3030 if (GuiInitInfo
== NULL
) return STATUS_NO_MEMORY
;
3032 // HACK: We suppose that the pointers will be valid in GuiInitFrontEnd...
3033 GuiInitInfo
->ConsoleInfo
= ConsoleInfo
;
3034 GuiInitInfo
->ConsoleStartInfo
= ConsoleStartInfo
;
3035 GuiInitInfo
->ProcessId
= ProcessId
;
3037 /* Finally, initialize the frontend structure */
3038 FrontEnd
->Vtbl
= &GuiVtbl
;
3039 FrontEnd
->Data
= NULL
;
3040 FrontEnd
->OldData
= GuiInitInfo
;
3042 return STATUS_SUCCESS
;
3046 GuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd
)
3048 if (FrontEnd
== NULL
) return STATUS_INVALID_PARAMETER
;
3050 if (FrontEnd
->Data
) GuiDeinitFrontEnd(FrontEnd
);
3051 if (FrontEnd
->OldData
) ConsoleFreeHeap(FrontEnd
->OldData
);
3053 return STATUS_SUCCESS
;