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, (LONG_PTR)(ConsoleLeaderCID.UniqueProcess)); \
76 SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)(ConsoleLeaderCID.UniqueThread )); \
78 /**************************************************************/
80 static BOOL ConsInitialized
= FALSE
;
81 static HICON ghDefaultIcon
= NULL
;
82 static HICON ghDefaultIconSm
= NULL
;
83 static HCURSOR ghDefaultCursor
= NULL
;
84 static HWND NotifyWnd
= NULL
;
86 typedef struct _GUICONSOLE_MENUITEM
89 const struct _GUICONSOLE_MENUITEM
*SubMenu
;
91 } GUICONSOLE_MENUITEM
, *PGUICONSOLE_MENUITEM
;
93 static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems
[] =
95 { IDS_MARK
, NULL
, ID_SYSTEM_EDIT_MARK
},
96 { IDS_COPY
, NULL
, ID_SYSTEM_EDIT_COPY
},
97 { IDS_PASTE
, NULL
, ID_SYSTEM_EDIT_PASTE
},
98 { IDS_SELECTALL
, NULL
, ID_SYSTEM_EDIT_SELECTALL
},
99 { IDS_SCROLL
, NULL
, ID_SYSTEM_EDIT_SCROLL
},
100 { IDS_FIND
, NULL
, ID_SYSTEM_EDIT_FIND
},
102 { 0, NULL
, 0 } /* End of list */
105 static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems
[] =
107 { IDS_EDIT
, GuiConsoleEditMenuItems
, 0 },
108 { IDS_DEFAULTS
, NULL
, ID_SYSTEM_DEFAULTS
},
109 { IDS_PROPERTIES
, NULL
, ID_SYSTEM_PROPERTIES
},
111 { 0, NULL
, 0 } /* End of list */
115 * Default 16-color palette for foreground and background
116 * (corresponding flags in comments).
118 const COLORREF s_Colors
[16] =
120 RGB(0, 0, 0), // (Black)
121 RGB(0, 0, 128), // BLUE
122 RGB(0, 128, 0), // GREEN
123 RGB(0, 128, 128), // BLUE | GREEN
124 RGB(128, 0, 0), // RED
125 RGB(128, 0, 128), // BLUE | RED
126 RGB(128, 128, 0), // GREEN | RED
127 RGB(192, 192, 192), // BLUE | GREEN | RED
129 RGB(128, 128, 128), // (Grey) INTENSITY
130 RGB(0, 0, 255), // BLUE | INTENSITY
131 RGB(0, 255, 0), // GREEN | INTENSITY
132 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
133 RGB(255, 0, 0), // RED | INTENSITY
134 RGB(255, 0, 255), // BLUE | RED | INTENSITY
135 RGB(255, 255, 0), // GREEN | RED | INTENSITY
136 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
139 /* FUNCTIONS ******************************************************************/
142 GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer
,
143 IN PGUI_CONSOLE_DATA GuiData
,
145 OUT PUINT HeightUnit
)
147 if (Buffer
== NULL
|| GuiData
== NULL
||
148 WidthUnit
== NULL
|| HeightUnit
== NULL
)
153 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
155 *WidthUnit
= GuiData
->CharWidth
;
156 *HeightUnit
= GuiData
->CharHeight
;
158 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
168 GuiConsoleAppendMenuItems(HMENU hMenu
,
169 const GUICONSOLE_MENUITEM
*Items
)
172 WCHAR szMenuString
[255];
177 if (Items
[i
].uID
!= (UINT
)-1)
179 if (LoadStringW(ConSrvDllInstance
,
182 sizeof(szMenuString
) / sizeof(szMenuString
[0])) > 0)
184 if (Items
[i
].SubMenu
!= NULL
)
186 hSubMenu
= CreatePopupMenu();
187 if (hSubMenu
!= NULL
)
189 GuiConsoleAppendMenuItems(hSubMenu
,
192 if (!AppendMenuW(hMenu
,
193 MF_STRING
| MF_POPUP
,
197 DestroyMenu(hSubMenu
);
218 } while (!(Items
[i
].uID
== 0 && Items
[i
].SubMenu
== NULL
&& Items
[i
].wCmdID
== 0));
222 GuiConsoleCreateSysMenu(HWND hWnd
)
224 HMENU hMenu
= GetSystemMenu(hWnd
, FALSE
);
227 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleMainMenuItems
);
233 GuiSendMenuEvent(PCONSOLE Console
, UINT CmdId
)
237 er
.EventType
= MENU_EVENT
;
238 er
.Event
.MenuEvent
.dwCommandId
= CmdId
;
240 ConioProcessInputEvent(Console
, &er
);
244 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
);
246 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
);
248 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
);
250 GuiDrawRegion(IN OUT PFRONTEND This
, SMALL_RECT
* Region
);
252 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
);
256 GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
259 PCONSOLE Console
= GuiData
->Console
;
260 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
262 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
267 ActiveBuffer
= ConDrvGetActiveScreenBuffer(Console
);
270 * In case the selected menu item belongs to the user-reserved menu id range,
271 * send to him a menu event and return directly. The user must handle those
272 * reserved menu commands...
274 if (GuiData
->cmdIdLow
<= (UINT
)wParam
&& (UINT
)wParam
<= GuiData
->cmdIdHigh
)
276 GuiSendMenuEvent(Console
, (UINT
)wParam
);
280 /* ... otherwise, perform actions. */
283 case ID_SYSTEM_EDIT_MARK
:
285 LPWSTR WindowTitle
= NULL
;
288 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ViewOrigin
.X
;
289 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewOrigin
.Y
;
290 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
291 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
;
292 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
294 Length
= Console
->Title
.Length
+ sizeof(L
"Mark - ")/sizeof(WCHAR
) + 1;
295 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
296 wcscpy(WindowTitle
, L
"Mark - ");
297 wcscat(WindowTitle
, Console
->Title
.Buffer
);
298 SetWindowText(GuiData
->hWindow
, WindowTitle
);
299 ConsoleFreeHeap(WindowTitle
);
304 case ID_SYSTEM_EDIT_COPY
:
305 GuiConsoleCopy(GuiData
);
308 case ID_SYSTEM_EDIT_PASTE
:
309 GuiConsolePaste(GuiData
);
312 case ID_SYSTEM_EDIT_SELECTALL
:
314 LPWSTR WindowTitle
= NULL
;
317 Console
->Selection
.dwSelectionAnchor
.X
= 0;
318 Console
->Selection
.dwSelectionAnchor
.Y
= 0;
319 Console
->dwSelectionCursor
.X
= ActiveBuffer
->ViewSize
.X
- 1;
320 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ViewSize
.Y
- 1;
321 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
;
322 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
324 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
325 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
326 wcscpy(WindowTitle
, L
"Selection - ");
327 wcscat(WindowTitle
, Console
->Title
.Buffer
);
328 SetWindowText(GuiData
->hWindow
, WindowTitle
);
329 ConsoleFreeHeap(WindowTitle
);
334 case ID_SYSTEM_EDIT_SCROLL
:
335 DPRINT1("Scrolling is not handled yet\n");
338 case ID_SYSTEM_EDIT_FIND
:
339 DPRINT1("Finding is not handled yet\n");
342 case ID_SYSTEM_DEFAULTS
:
343 GuiConsoleShowConsoleProperties(GuiData
, TRUE
);
346 case ID_SYSTEM_PROPERTIES
:
347 GuiConsoleShowConsoleProperties(GuiData
, FALSE
);
356 LeaveCriticalSection(&Console
->Lock
);
359 Ret
= DefWindowProcW(GuiData
->hWindow
, WM_SYSCOMMAND
, wParam
, lParam
);
364 static PGUI_CONSOLE_DATA
365 GuiGetGuiData(HWND hWnd
)
367 /* This function ensures that the console pointer is not NULL */
368 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
369 return ( ((GuiData
== NULL
) || (GuiData
->hWindow
== hWnd
&& GuiData
->Console
!= NULL
)) ? GuiData
: NULL
);
373 GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData
)
375 /* Move the window if needed (not positioned by the system) */
376 if (!GuiData
->GuiInfo
.AutoPosition
)
378 SetWindowPos(GuiData
->hWindow
,
380 GuiData
->GuiInfo
.WindowOrigin
.x
,
381 GuiData
->GuiInfo
.WindowOrigin
.y
,
384 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
);
389 GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData
)
391 PCONSOLE Console
= GuiData
->Console
;
392 PCONSOLE_SCREEN_BUFFER Buff
= ConDrvGetActiveScreenBuffer(Console
);
396 UINT WidthUnit
, HeightUnit
;
398 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
400 Width
= Buff
->ViewSize
.X
* WidthUnit
+
401 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
402 Height
= Buff
->ViewSize
.Y
* HeightUnit
+
403 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
405 /* Set scrollbar sizes */
406 sInfo
.cbSize
= sizeof(SCROLLINFO
);
407 sInfo
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
409 if (Buff
->ScreenBufferSize
.Y
> Buff
->ViewSize
.Y
)
411 sInfo
.nMax
= Buff
->ScreenBufferSize
.Y
- 1;
412 sInfo
.nPage
= Buff
->ViewSize
.Y
;
413 sInfo
.nPos
= Buff
->ViewOrigin
.Y
;
414 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &sInfo
, TRUE
);
415 Width
+= GetSystemMetrics(SM_CXVSCROLL
);
416 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, TRUE
);
420 ShowScrollBar(GuiData
->hWindow
, SB_VERT
, FALSE
);
423 if (Buff
->ScreenBufferSize
.X
> Buff
->ViewSize
.X
)
425 sInfo
.nMax
= Buff
->ScreenBufferSize
.X
- 1;
426 sInfo
.nPage
= Buff
->ViewSize
.X
;
427 sInfo
.nPos
= Buff
->ViewOrigin
.X
;
428 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &sInfo
, TRUE
);
429 Height
+= GetSystemMetrics(SM_CYHSCROLL
);
430 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, TRUE
);
434 ShowScrollBar(GuiData
->hWindow
, SB_HORZ
, FALSE
);
437 /* Resize the window */
438 SetWindowPos(GuiData
->hWindow
, NULL
, 0, 0, Width
, Height
,
439 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
);
440 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
441 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
445 GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData
)
447 PCONSOLE Console
= GuiData
->Console
;
448 // DEVMODE dmScreenSettings;
450 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
452 /* Switch to full-screen or to windowed mode */
453 GuiData
->GuiInfo
.FullScreen
= !GuiData
->GuiInfo
.FullScreen
;
454 DPRINT1("GuiConsoleSwitchFullScreen - Switch to %s ...\n",
455 (GuiData
->GuiInfo
.FullScreen
? "full-screen" : "windowed mode"));
457 // TODO: Change window appearance.
459 // http://stackoverflow.com/questions/2382464/win32-full-screen-and-hiding-taskbar
460 // http://stackoverflow.com/questions/3549148/fullscreen-management-with-winapi
461 // http://blogs.msdn.com/b/oldnewthing/archive/2010/04/12/9994016.aspx
462 // http://stackoverflow.com/questions/1400654/how-do-i-put-my-opengl-app-into-fullscreen-mode
463 // http://nehe.gamedev.net/tutorial/creating_an_opengl_window_win32/13001/
465 if (GuiData
->GuiInfo
.FullScreen
)
467 memset(&dmScreenSettings
, 0, sizeof(dmScreenSettings
));
468 dmScreenSettings
.dmSize
= sizeof(dmScreenSettings
);
469 dmScreenSettings
.dmDisplayFixedOutput
= DMDFO_CENTER
; // DMDFO_STRETCH // DMDFO_DEFAULT
470 dmScreenSettings
.dmPelsWidth
= 640; // Console->ActiveBuffer->ViewSize.X * GuiData->CharWidth;
471 dmScreenSettings
.dmPelsHeight
= 480; // Console->ActiveBuffer->ViewSize.Y * GuiData->CharHeight;
472 dmScreenSettings
.dmBitsPerPel
= 32;
473 dmScreenSettings
.dmFields
= DM_BITSPERPEL
| DM_PELSWIDTH
| DM_PELSHEIGHT
;
474 ChangeDisplaySettings(&dmScreenSettings
, CDS_FULLSCREEN
);
481 LeaveCriticalSection(&Console
->Lock
);
485 GuiConsoleHandleNcCreate(HWND hWnd
, LPCREATESTRUCTW Create
)
487 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Create
->lpCreateParams
;
494 DPRINT("GuiConsoleHandleNcCreate\n");
498 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
502 Console
= GuiData
->Console
;
504 GuiData
->hWindow
= hWnd
;
506 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->GuiInfo
.FontSize
),
507 0, // HIWORD(GuiData->GuiInfo.FontSize),
510 GuiData
->GuiInfo
.FontWeight
,
517 NONANTIALIASED_QUALITY
,
518 FIXED_PITCH
| GuiData
->GuiInfo
.FontFamily
/* FF_DONTCARE */,
519 GuiData
->GuiInfo
.FaceName
);
521 if (NULL
== GuiData
->Font
)
523 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
524 GuiData
->hWindow
= NULL
;
525 SetEvent(GuiData
->hGuiInitEvent
);
528 Dc
= GetDC(GuiData
->hWindow
);
531 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
532 DeleteObject(GuiData
->Font
);
533 GuiData
->hWindow
= NULL
;
534 SetEvent(GuiData
->hGuiInitEvent
);
537 OldFont
= SelectObject(Dc
, GuiData
->Font
);
540 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
541 ReleaseDC(GuiData
->hWindow
, Dc
);
542 DeleteObject(GuiData
->Font
);
543 GuiData
->hWindow
= NULL
;
544 SetEvent(GuiData
->hGuiInitEvent
);
547 if (!GetTextMetricsW(Dc
, &Metrics
))
549 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
550 SelectObject(Dc
, OldFont
);
551 ReleaseDC(GuiData
->hWindow
, Dc
);
552 DeleteObject(GuiData
->Font
);
553 GuiData
->hWindow
= NULL
;
554 SetEvent(GuiData
->hGuiInitEvent
);
557 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
558 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
560 /* Measure real char width more precisely if possible. */
561 if (GetTextExtentPoint32W(Dc
, L
"R", 1, &CharSize
))
562 GuiData
->CharWidth
= CharSize
.cx
;
564 SelectObject(Dc
, OldFont
);
566 ReleaseDC(GuiData
->hWindow
, Dc
);
568 // FIXME: Keep these instructions here ? ///////////////////////////////////
569 Console
->ActiveBuffer
->CursorBlinkOn
= TRUE
;
570 Console
->ActiveBuffer
->ForceCursorOff
= FALSE
;
571 ////////////////////////////////////////////////////////////////////////////
573 SetWindowLongPtrW(GuiData
->hWindow
, GWLP_USERDATA
, (DWORD_PTR
)GuiData
);
575 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
576 GuiConsoleCreateSysMenu(GuiData
->hWindow
);
578 DPRINT("GuiConsoleHandleNcCreate - setting start event\n");
579 SetEvent(GuiData
->hGuiInitEvent
);
581 return (BOOL
)DefWindowProcW(GuiData
->hWindow
, WM_NCCREATE
, 0, (LPARAM
)Create
);
585 SmallRectToRect(PGUI_CONSOLE_DATA GuiData
, PRECT Rect
, PSMALL_RECT SmallRect
)
587 PCONSOLE Console
= GuiData
->Console
;
588 PCONSOLE_SCREEN_BUFFER Buffer
= ConDrvGetActiveScreenBuffer(Console
);
589 UINT WidthUnit
, HeightUnit
;
591 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
593 Rect
->left
= (SmallRect
->Left
- Buffer
->ViewOrigin
.X
) * WidthUnit
;
594 Rect
->top
= (SmallRect
->Top
- Buffer
->ViewOrigin
.Y
) * HeightUnit
;
595 Rect
->right
= (SmallRect
->Right
+ 1 - Buffer
->ViewOrigin
.X
) * WidthUnit
;
596 Rect
->bottom
= (SmallRect
->Bottom
+ 1 - Buffer
->ViewOrigin
.Y
) * HeightUnit
;
600 GuiConsoleUpdateSelection(PCONSOLE Console
, PCOORD coord
)
602 PGUI_CONSOLE_DATA GuiData
= Console
->TermIFace
.Data
;
603 RECT oldRect
, newRect
;
605 SmallRectToRect(GuiData
, &oldRect
, &Console
->Selection
.srSelection
);
610 /* exchange left/top with right/bottom if required */
611 rc
.Left
= min(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
612 rc
.Top
= min(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
613 rc
.Right
= max(Console
->Selection
.dwSelectionAnchor
.X
, coord
->X
);
614 rc
.Bottom
= max(Console
->Selection
.dwSelectionAnchor
.Y
, coord
->Y
);
616 SmallRectToRect(GuiData
, &newRect
, &rc
);
618 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
620 if (memcmp(&rc
, &Console
->Selection
.srSelection
, sizeof(SMALL_RECT
)) != 0)
624 /* calculate the region that needs to be updated */
625 if ((rgn1
= CreateRectRgnIndirect(&oldRect
)))
627 if ((rgn2
= CreateRectRgnIndirect(&newRect
)))
629 if (CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
631 InvalidateRgn(GuiData
->hWindow
, rgn1
, FALSE
);
641 InvalidateRect(GuiData
->hWindow
, &newRect
, FALSE
);
643 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_NOT_EMPTY
;
644 Console
->Selection
.srSelection
= rc
;
645 Console
->dwSelectionCursor
= *coord
;
646 ConioPause(Console
, PAUSED_FROM_SELECTION
);
650 /* clear the selection */
651 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
653 InvalidateRect(GuiData
->hWindow
, &oldRect
, FALSE
);
655 Console
->Selection
.dwFlags
= CONSOLE_NO_SELECTION
;
656 ConioUnpause(Console
, PAUSED_FROM_SELECTION
);
662 GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
,
663 PGUI_CONSOLE_DATA GuiData
,
667 GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
,
668 PGUI_CONSOLE_DATA GuiData
,
673 GuiConsoleHandlePaint(PGUI_CONSOLE_DATA GuiData
)
676 PCONSOLE Console
= GuiData
->Console
;
677 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
681 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
686 ActiveBuffer
= ConDrvGetActiveScreenBuffer(Console
);
688 hDC
= BeginPaint(GuiData
->hWindow
, &ps
);
690 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
691 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
693 EnterCriticalSection(&GuiData
->Lock
);
695 if (GetType(ActiveBuffer
) == TEXTMODE_BUFFER
)
697 GuiPaintTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)ActiveBuffer
,
698 GuiData
, hDC
, &ps
.rcPaint
);
700 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
702 GuiPaintGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)ActiveBuffer
,
703 GuiData
, hDC
, &ps
.rcPaint
);
706 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
)
709 SmallRectToRect(GuiData
, &rc
, &Console
->Selection
.srSelection
);
711 /* invert the selection */
712 if (IntersectRect(&rc
, &ps
.rcPaint
, &rc
))
723 LeaveCriticalSection(&GuiData
->Lock
);
725 EndPaint(GuiData
->hWindow
, &ps
);
729 LeaveCriticalSection(&Console
->Lock
);
731 DefWindowProcW(GuiData
->hWindow
, WM_PAINT
, 0, 0);
737 IsSystemKey(WORD VirtualKeyCode
)
739 switch (VirtualKeyCode
)
741 /* From MSDN, "Virtual-Key Codes" */
760 GuiConsoleHandleKey(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
762 PCONSOLE Console
= GuiData
->Console
;
763 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
765 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
767 ActiveBuffer
= ConDrvGetActiveScreenBuffer(Console
);
769 if (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
)
771 WORD VirtualKeyCode
= LOWORD(wParam
);
773 if (msg
!= WM_KEYDOWN
) goto Quit
;
775 if (VirtualKeyCode
== VK_RETURN
)
777 /* Copy (and clear) selection if ENTER is pressed */
778 GuiConsoleCopy(GuiData
);
781 else if ( VirtualKeyCode
== VK_ESCAPE
||
782 (VirtualKeyCode
== 'C' && GetKeyState(VK_CONTROL
) & 0x8000) )
784 /* Cancel selection if ESC or Ctrl-C are pressed */
785 GuiConsoleUpdateSelection(Console
, NULL
);
786 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
791 if ((Console
->Selection
.dwFlags
& CONSOLE_MOUSE_SELECTION
) == 0)
793 /* Keyboard selection mode */
794 BOOL Interpreted
= FALSE
;
795 BOOL MajPressed
= (GetKeyState(VK_SHIFT
) & 0x8000);
797 switch (VirtualKeyCode
)
802 if (Console
->dwSelectionCursor
.X
> 0)
803 Console
->dwSelectionCursor
.X
--;
811 if (Console
->dwSelectionCursor
.X
< ActiveBuffer
->ScreenBufferSize
.X
- 1)
812 Console
->dwSelectionCursor
.X
++;
820 if (Console
->dwSelectionCursor
.Y
> 0)
821 Console
->dwSelectionCursor
.Y
--;
829 if (Console
->dwSelectionCursor
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
- 1)
830 Console
->dwSelectionCursor
.Y
++;
838 Console
->dwSelectionCursor
.X
= 0;
839 Console
->dwSelectionCursor
.Y
= 0;
846 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
853 Console
->dwSelectionCursor
.Y
-= ActiveBuffer
->ViewSize
.Y
;
854 if (Console
->dwSelectionCursor
.Y
< 0)
855 Console
->dwSelectionCursor
.Y
= 0;
863 Console
->dwSelectionCursor
.Y
+= ActiveBuffer
->ViewSize
.Y
;
864 if (Console
->dwSelectionCursor
.Y
>= ActiveBuffer
->ScreenBufferSize
.Y
)
865 Console
->dwSelectionCursor
.Y
= ActiveBuffer
->ScreenBufferSize
.Y
- 1;
877 Console
->Selection
.dwSelectionAnchor
= Console
->dwSelectionCursor
;
879 GuiConsoleUpdateSelection(Console
, &Console
->dwSelectionCursor
);
881 else if (!IsSystemKey(VirtualKeyCode
))
883 /* Emit an error beep sound */
884 SendNotifyMessage(GuiData
->hWindow
, PM_CONSOLE_BEEP
, 0, 0);
891 /* Mouse selection mode */
893 if (!IsSystemKey(VirtualKeyCode
))
895 /* Clear the selection and send the key into the input buffer */
896 GuiConsoleUpdateSelection(Console
, NULL
);
897 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
906 if ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) == 0)
910 Message
.hwnd
= GuiData
->hWindow
;
911 Message
.message
= msg
;
912 Message
.wParam
= wParam
;
913 Message
.lParam
= lParam
;
915 ConioProcessKey(Console
, &Message
);
919 LeaveCriticalSection(&Console
->Lock
);
923 GuiInvalidateCell(IN OUT PFRONTEND This
, SHORT x
, SHORT y
)
925 SMALL_RECT CellRect
= { x
, y
, x
, y
};
926 GuiDrawRegion(This
, &CellRect
);
930 GuiConsoleHandleTimer(PGUI_CONSOLE_DATA GuiData
)
932 PCONSOLE Console
= GuiData
->Console
;
933 PCONSOLE_SCREEN_BUFFER Buff
;
935 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CURSOR_BLINK_TIME
, NULL
);
937 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
939 Buff
= ConDrvGetActiveScreenBuffer(Console
);
941 if (GetType(Buff
) == TEXTMODE_BUFFER
)
943 GuiInvalidateCell(&Console
->TermIFace
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
944 Buff
->CursorBlinkOn
= !Buff
->CursorBlinkOn
;
946 if ((GuiData
->OldCursor
.x
!= Buff
->CursorPosition
.X
) || (GuiData
->OldCursor
.y
!= Buff
->CursorPosition
.Y
))
949 int OldScrollX
= -1, OldScrollY
= -1;
950 int NewScrollX
= -1, NewScrollY
= -1;
952 xScroll
.cbSize
= sizeof(SCROLLINFO
);
953 xScroll
.fMask
= SIF_POS
;
954 // Capture the original position of the scroll bars and save them.
955 if (GetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
)) OldScrollX
= xScroll
.nPos
;
956 if (GetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
)) OldScrollY
= xScroll
.nPos
;
958 // If we successfully got the info for the horizontal scrollbar
961 if ((Buff
->CursorPosition
.X
< Buff
->ViewOrigin
.X
) || (Buff
->CursorPosition
.X
>= (Buff
->ViewOrigin
.X
+ Buff
->ViewSize
.X
)))
963 // Handle the horizontal scroll bar
964 if (Buff
->CursorPosition
.X
>= Buff
->ViewSize
.X
) NewScrollX
= Buff
->CursorPosition
.X
- Buff
->ViewSize
.X
+ 1;
969 NewScrollX
= OldScrollX
;
972 // If we successfully got the info for the vertical scrollbar
975 if ((Buff
->CursorPosition
.Y
< Buff
->ViewOrigin
.Y
) || (Buff
->CursorPosition
.Y
>= (Buff
->ViewOrigin
.Y
+ Buff
->ViewSize
.Y
)))
977 // Handle the vertical scroll bar
978 if (Buff
->CursorPosition
.Y
>= Buff
->ViewSize
.Y
) NewScrollY
= Buff
->CursorPosition
.Y
- Buff
->ViewSize
.Y
+ 1;
983 NewScrollY
= OldScrollY
;
987 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
988 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
989 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
990 // and their associated scrollbar is left alone.
991 if ((OldScrollX
!= NewScrollX
) || (OldScrollY
!= NewScrollY
))
993 Buff
->ViewOrigin
.X
= NewScrollX
;
994 Buff
->ViewOrigin
.Y
= NewScrollY
;
995 ScrollWindowEx(GuiData
->hWindow
,
996 (OldScrollX
- NewScrollX
) * GuiData
->CharWidth
,
997 (OldScrollY
- NewScrollY
) * GuiData
->CharHeight
,
1003 if (NewScrollX
>= 0)
1005 xScroll
.nPos
= NewScrollX
;
1006 SetScrollInfo(GuiData
->hWindow
, SB_HORZ
, &xScroll
, TRUE
);
1008 if (NewScrollY
>= 0)
1010 xScroll
.nPos
= NewScrollY
;
1011 SetScrollInfo(GuiData
->hWindow
, SB_VERT
, &xScroll
, TRUE
);
1013 UpdateWindow(GuiData
->hWindow
);
1014 GuiData
->OldCursor
.x
= Buff
->CursorPosition
.X
;
1015 GuiData
->OldCursor
.y
= Buff
->CursorPosition
.Y
;
1019 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1023 LeaveCriticalSection(&Console
->Lock
);
1027 GuiConsoleHandleClose(PGUI_CONSOLE_DATA GuiData
)
1029 PCONSOLE Console
= GuiData
->Console
;
1031 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1034 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1037 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1038 * We shouldn't wait here, though, since the console lock is entered.
1039 * A copy of the thread list probably needs to be made.
1041 ConDrvConsoleProcessCtrlEvent(Console
, 0, CTRL_CLOSE_EVENT
);
1043 LeaveCriticalSection(&Console
->Lock
);
1048 GuiConsoleHandleNcDestroy(HWND hWnd
)
1050 KillTimer(hWnd
, CONGUI_UPDATE_TIMER
);
1051 GetSystemMenu(hWnd
, TRUE
);
1053 /* Free the GuiData registration */
1054 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (DWORD_PTR
)NULL
);
1056 return DefWindowProcW(hWnd
, WM_NCDESTROY
, 0, 0);
1060 PointToCoord(PGUI_CONSOLE_DATA GuiData
, LPARAM lParam
)
1062 PCONSOLE Console
= GuiData
->Console
;
1063 PCONSOLE_SCREEN_BUFFER Buffer
= ConDrvGetActiveScreenBuffer(Console
);
1065 UINT WidthUnit
, HeightUnit
;
1067 GetScreenBufferSizeUnits(Buffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1069 Coord
.X
= Buffer
->ViewOrigin
.X
+ ((SHORT
)LOWORD(lParam
) / (int)WidthUnit
);
1070 Coord
.Y
= Buffer
->ViewOrigin
.Y
+ ((SHORT
)HIWORD(lParam
) / (int)HeightUnit
);
1072 /* Clip coordinate to ensure it's inside buffer */
1075 else if (Coord
.X
>= Buffer
->ScreenBufferSize
.X
)
1076 Coord
.X
= Buffer
->ScreenBufferSize
.X
- 1;
1080 else if (Coord
.Y
>= Buffer
->ScreenBufferSize
.Y
)
1081 Coord
.Y
= Buffer
->ScreenBufferSize
.Y
- 1;
1087 GuiConsoleHandleMouse(PGUI_CONSOLE_DATA GuiData
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1090 PCONSOLE Console
= GuiData
->Console
;
1092 if (GuiData
->IgnoreNextMouseSignal
)
1094 if (msg
!= WM_LBUTTONDOWN
&&
1095 msg
!= WM_MBUTTONDOWN
&&
1096 msg
!= WM_RBUTTONDOWN
)
1099 * If this mouse signal is not a button-down action,
1100 * then it is the last signal being ignored.
1102 GuiData
->IgnoreNextMouseSignal
= FALSE
;
1107 * This mouse signal is a button-down action.
1108 * Ignore it and perform default action.
1115 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1121 if ( (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) ||
1122 (Console
->QuickEdit
) )
1126 case WM_LBUTTONDOWN
:
1128 LPWSTR WindowTitle
= NULL
;
1131 Console
->Selection
.dwSelectionAnchor
= PointToCoord(GuiData
, lParam
);
1132 SetCapture(GuiData
->hWindow
);
1133 Console
->Selection
.dwFlags
|= CONSOLE_SELECTION_IN_PROGRESS
| CONSOLE_MOUSE_SELECTION
| CONSOLE_MOUSE_DOWN
;
1134 GuiConsoleUpdateSelection(Console
, &Console
->Selection
.dwSelectionAnchor
);
1136 Length
= Console
->Title
.Length
+ sizeof(L
"Selection - ")/sizeof(WCHAR
) + 1;
1137 WindowTitle
= ConsoleAllocHeap(0, Length
* sizeof(WCHAR
));
1138 wcscpy(WindowTitle
, L
"Selection - ");
1139 wcscat(WindowTitle
, Console
->Title
.Buffer
);
1140 SetWindowText(GuiData
->hWindow
, WindowTitle
);
1141 ConsoleFreeHeap(WindowTitle
);
1150 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1152 c
= PointToCoord(GuiData
, lParam
);
1153 Console
->Selection
.dwFlags
&= ~CONSOLE_MOUSE_DOWN
;
1154 GuiConsoleUpdateSelection(Console
, &c
);
1160 case WM_LBUTTONDBLCLK
:
1162 DPRINT1("Handle left-double-click for selecting a word\n");
1166 case WM_RBUTTONDOWN
:
1167 case WM_RBUTTONDBLCLK
:
1169 if (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
))
1171 GuiConsolePaste(GuiData
);
1175 GuiConsoleCopy(GuiData
);
1178 GuiData
->IgnoreNextMouseSignal
= TRUE
;
1186 if (!(wParam
& MK_LBUTTON
)) break;
1187 if (!(Console
->Selection
.dwFlags
& CONSOLE_MOUSE_DOWN
)) break;
1189 c
= PointToCoord(GuiData
, lParam
); /* TODO: Scroll buffer to bring c into view */
1190 GuiConsoleUpdateSelection(Console
, &c
);
1196 Err
= FALSE
; // TRUE;
1200 else if (Console
->InputBuffer
.Mode
& ENABLE_MOUSE_INPUT
)
1203 WORD wKeyState
= GET_KEYSTATE_WPARAM(wParam
);
1204 DWORD dwButtonState
= 0;
1205 DWORD dwControlKeyState
= 0;
1206 DWORD dwEventFlags
= 0;
1210 case WM_LBUTTONDOWN
:
1211 SetCapture(GuiData
->hWindow
);
1212 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1216 case WM_MBUTTONDOWN
:
1217 SetCapture(GuiData
->hWindow
);
1218 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1222 case WM_RBUTTONDOWN
:
1223 SetCapture(GuiData
->hWindow
);
1224 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1246 case WM_LBUTTONDBLCLK
:
1247 dwButtonState
= FROM_LEFT_1ST_BUTTON_PRESSED
;
1248 dwEventFlags
= DOUBLE_CLICK
;
1251 case WM_MBUTTONDBLCLK
:
1252 dwButtonState
= FROM_LEFT_2ND_BUTTON_PRESSED
;
1253 dwEventFlags
= DOUBLE_CLICK
;
1256 case WM_RBUTTONDBLCLK
:
1257 dwButtonState
= RIGHTMOST_BUTTON_PRESSED
;
1258 dwEventFlags
= DOUBLE_CLICK
;
1263 dwEventFlags
= MOUSE_MOVED
;
1267 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1268 dwEventFlags
= MOUSE_WHEELED
;
1271 case WM_MOUSEHWHEEL
:
1272 dwButtonState
= GET_WHEEL_DELTA_WPARAM(wParam
) << 16;
1273 dwEventFlags
= MOUSE_HWHEELED
;
1283 if (wKeyState
& MK_LBUTTON
)
1284 dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1285 if (wKeyState
& MK_MBUTTON
)
1286 dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1287 if (wKeyState
& MK_RBUTTON
)
1288 dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1290 if (GetKeyState(VK_RMENU
) & 0x8000)
1291 dwControlKeyState
|= RIGHT_ALT_PRESSED
;
1292 if (GetKeyState(VK_LMENU
) & 0x8000)
1293 dwControlKeyState
|= LEFT_ALT_PRESSED
;
1294 if (GetKeyState(VK_RCONTROL
) & 0x8000)
1295 dwControlKeyState
|= RIGHT_CTRL_PRESSED
;
1296 if (GetKeyState(VK_LCONTROL
) & 0x8000)
1297 dwControlKeyState
|= LEFT_CTRL_PRESSED
;
1298 if (GetKeyState(VK_SHIFT
) & 0x8000)
1299 dwControlKeyState
|= SHIFT_PRESSED
;
1300 if (GetKeyState(VK_NUMLOCK
) & 0x0001)
1301 dwControlKeyState
|= NUMLOCK_ON
;
1302 if (GetKeyState(VK_SCROLL
) & 0x0001)
1303 dwControlKeyState
|= SCROLLLOCK_ON
;
1304 if (GetKeyState(VK_CAPITAL
) & 0x0001)
1305 dwControlKeyState
|= CAPSLOCK_ON
;
1306 /* See WM_CHAR MSDN documentation for instance */
1307 if (lParam
& 0x01000000)
1308 dwControlKeyState
|= ENHANCED_KEY
;
1310 er
.EventType
= MOUSE_EVENT
;
1311 er
.Event
.MouseEvent
.dwMousePosition
= PointToCoord(GuiData
, lParam
);
1312 er
.Event
.MouseEvent
.dwButtonState
= dwButtonState
;
1313 er
.Event
.MouseEvent
.dwControlKeyState
= dwControlKeyState
;
1314 er
.Event
.MouseEvent
.dwEventFlags
= dwEventFlags
;
1316 ConioProcessInputEvent(Console
, &er
);
1324 LeaveCriticalSection(&Console
->Lock
);
1328 return DefWindowProcW(GuiData
->hWindow
, msg
, wParam
, lParam
);
1333 VOID
GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1334 VOID
GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1337 GuiConsoleCopy(PGUI_CONSOLE_DATA GuiData
)
1339 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1341 PCONSOLE Console
= GuiData
->Console
;
1342 PCONSOLE_SCREEN_BUFFER Buffer
= ConDrvGetActiveScreenBuffer(Console
);
1344 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1346 GuiCopyFromTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1348 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1350 GuiCopyFromGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1355 /* Clear the selection */
1356 GuiConsoleUpdateSelection(Console
, NULL
);
1357 SetWindowText(GuiData
->hWindow
, Console
->Title
.Buffer
);
1361 VOID
GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer
);
1362 VOID
GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer
);
1365 GuiConsolePaste(PGUI_CONSOLE_DATA GuiData
)
1367 if (OpenClipboard(GuiData
->hWindow
) == TRUE
)
1369 PCONSOLE Console
= GuiData
->Console
;
1370 PCONSOLE_SCREEN_BUFFER Buffer
= ConDrvGetActiveScreenBuffer(Console
);
1372 if (GetType(Buffer
) == TEXTMODE_BUFFER
)
1374 GuiPasteToTextModeBuffer((PTEXTMODE_SCREEN_BUFFER
)Buffer
);
1376 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
1378 GuiPasteToGraphicsBuffer((PGRAPHICS_SCREEN_BUFFER
)Buffer
);
1386 GuiConsoleGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData
, PMINMAXINFO minMaxInfo
)
1388 PCONSOLE Console
= GuiData
->Console
;
1389 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
1391 UINT WidthUnit
, HeightUnit
;
1393 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1395 ActiveBuffer
= ConDrvGetActiveScreenBuffer(Console
);
1397 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
1399 windx
= CONGUI_MIN_WIDTH
* WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1400 windy
= CONGUI_MIN_HEIGHT
* HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1402 minMaxInfo
->ptMinTrackSize
.x
= windx
;
1403 minMaxInfo
->ptMinTrackSize
.y
= windy
;
1405 windx
= (ActiveBuffer
->ScreenBufferSize
.X
) * WidthUnit
+ 2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
));
1406 windy
= (ActiveBuffer
->ScreenBufferSize
.Y
) * HeightUnit
+ 2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
);
1408 if (ActiveBuffer
->ViewSize
.X
< ActiveBuffer
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1409 if (ActiveBuffer
->ViewSize
.Y
< ActiveBuffer
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1411 minMaxInfo
->ptMaxTrackSize
.x
= windx
;
1412 minMaxInfo
->ptMaxTrackSize
.y
= windy
;
1414 LeaveCriticalSection(&Console
->Lock
);
1418 GuiConsoleResize(PGUI_CONSOLE_DATA GuiData
, WPARAM wParam
, LPARAM lParam
)
1420 PCONSOLE Console
= GuiData
->Console
;
1422 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return;
1424 if ((GuiData
->WindowSizeLock
== FALSE
) &&
1425 (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
|| wParam
== SIZE_MINIMIZED
))
1427 PCONSOLE_SCREEN_BUFFER Buff
= ConDrvGetActiveScreenBuffer(Console
);
1428 DWORD windx
, windy
, charx
, chary
;
1429 UINT WidthUnit
, HeightUnit
;
1431 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1433 GuiData
->WindowSizeLock
= TRUE
;
1435 windx
= LOWORD(lParam
);
1436 windy
= HIWORD(lParam
);
1438 // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
1439 if (Buff
->ViewSize
.X
< Buff
->ScreenBufferSize
.X
) windy
+= GetSystemMetrics(SM_CYHSCROLL
); // window currently has a horizontal scrollbar
1440 if (Buff
->ViewSize
.Y
< Buff
->ScreenBufferSize
.Y
) windx
+= GetSystemMetrics(SM_CXVSCROLL
); // window currently has a vertical scrollbar
1442 charx
= windx
/ (int)WidthUnit
;
1443 chary
= windy
/ (int)HeightUnit
;
1445 // Character alignment (round size up or down)
1446 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1447 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1449 // Compensate for added scroll bars in new window
1450 if (charx
< Buff
->ScreenBufferSize
.X
) windy
-= GetSystemMetrics(SM_CYHSCROLL
); // new window will have a horizontal scroll bar
1451 if (chary
< Buff
->ScreenBufferSize
.Y
) windx
-= GetSystemMetrics(SM_CXVSCROLL
); // new window will have a vertical scroll bar
1453 charx
= windx
/ (int)WidthUnit
;
1454 chary
= windy
/ (int)HeightUnit
;
1456 // Character alignment (round size up or down)
1457 if ((windx
% WidthUnit
) >= (WidthUnit
/ 2)) ++charx
;
1458 if ((windy
% HeightUnit
) >= (HeightUnit
/ 2)) ++chary
;
1461 if ((charx
!= Buff
->ViewSize
.X
) || (chary
!= Buff
->ViewSize
.Y
))
1463 Buff
->ViewSize
.X
= (charx
<= Buff
->ScreenBufferSize
.X
) ? charx
: Buff
->ScreenBufferSize
.X
;
1464 Buff
->ViewSize
.Y
= (chary
<= Buff
->ScreenBufferSize
.Y
) ? chary
: Buff
->ScreenBufferSize
.Y
;
1467 GuiConsoleResizeWindow(GuiData
);
1469 // Adjust the start of the visible area if we are attempting to show nonexistent areas
1470 if ((Buff
->ScreenBufferSize
.X
- Buff
->ViewOrigin
.X
) < Buff
->ViewSize
.X
) Buff
->ViewOrigin
.X
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1471 if ((Buff
->ScreenBufferSize
.Y
- Buff
->ViewOrigin
.Y
) < Buff
->ViewSize
.Y
) Buff
->ViewOrigin
.Y
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1472 InvalidateRect(GuiData
->hWindow
, NULL
, TRUE
);
1474 GuiData
->WindowSizeLock
= FALSE
;
1477 LeaveCriticalSection(&Console
->Lock
);
1481 // HACK: This functionality is standard for general scrollbars. Don't add it by hand.
1485 GuiConsoleHandleScrollbarMenu(VOID)
1489 hMenu = CreatePopupMenu();
1492 DPRINT("CreatePopupMenu failed\n");
1496 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE);
1497 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1498 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP);
1499 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM);
1500 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1501 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP);
1502 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN);
1503 //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1);
1504 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP);
1505 //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN);
1510 GuiConsoleHandleScroll(PGUI_CONSOLE_DATA GuiData
, UINT uMsg
, WPARAM wParam
)
1512 PCONSOLE Console
= GuiData
->Console
;
1513 PCONSOLE_SCREEN_BUFFER Buff
;
1516 int old_pos
, Maximum
;
1519 if (!ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
)) return 0;
1521 Buff
= ConDrvGetActiveScreenBuffer(Console
);
1523 if (uMsg
== WM_HSCROLL
)
1526 Maximum
= Buff
->ScreenBufferSize
.X
- Buff
->ViewSize
.X
;
1527 pShowXY
= &Buff
->ViewOrigin
.X
;
1532 Maximum
= Buff
->ScreenBufferSize
.Y
- Buff
->ViewSize
.Y
;
1533 pShowXY
= &Buff
->ViewOrigin
.Y
;
1536 /* set scrollbar sizes */
1537 sInfo
.cbSize
= sizeof(SCROLLINFO
);
1538 sInfo
.fMask
= SIF_RANGE
| SIF_POS
| SIF_PAGE
| SIF_TRACKPOS
;
1540 if (!GetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
)) goto Quit
;
1542 old_pos
= sInfo
.nPos
;
1544 switch (LOWORD(wParam
))
1555 sInfo
.nPos
-= sInfo
.nPage
;
1559 sInfo
.nPos
+= sInfo
.nPage
;
1563 sInfo
.nPos
= sInfo
.nTrackPos
;
1564 ConioPause(Console
, PAUSED_FROM_SCROLLBAR
);
1567 case SB_THUMBPOSITION
:
1568 ConioUnpause(Console
, PAUSED_FROM_SCROLLBAR
);
1572 sInfo
.nPos
= sInfo
.nMin
;
1576 sInfo
.nPos
= sInfo
.nMax
;
1583 sInfo
.nPos
= max(sInfo
.nPos
, 0);
1584 sInfo
.nPos
= min(sInfo
.nPos
, Maximum
);
1586 if (old_pos
!= sInfo
.nPos
)
1588 USHORT OldX
= Buff
->ViewOrigin
.X
;
1589 USHORT OldY
= Buff
->ViewOrigin
.Y
;
1590 UINT WidthUnit
, HeightUnit
;
1592 *pShowXY
= sInfo
.nPos
;
1594 GetScreenBufferSizeUnits(Buff
, GuiData
, &WidthUnit
, &HeightUnit
);
1596 ScrollWindowEx(GuiData
->hWindow
,
1597 (OldX
- Buff
->ViewOrigin
.X
) * WidthUnit
,
1598 (OldY
- Buff
->ViewOrigin
.Y
) * HeightUnit
,
1605 sInfo
.fMask
= SIF_POS
;
1606 SetScrollInfo(GuiData
->hWindow
, fnBar
, &sInfo
, TRUE
);
1608 UpdateWindow(GuiData
->hWindow
);
1612 LeaveCriticalSection(&Console
->Lock
);
1616 static LRESULT CALLBACK
1617 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1620 PGUI_CONSOLE_DATA GuiData
= NULL
;
1621 PCONSOLE Console
= NULL
;
1624 * - If it's the first time we create a window for the terminal,
1625 * just initialize it and return.
1627 * - If we are destroying the window, just do it and return.
1629 if (msg
== WM_NCCREATE
)
1631 return (LRESULT
)GuiConsoleHandleNcCreate(hWnd
, (LPCREATESTRUCTW
)lParam
);
1633 else if (msg
== WM_NCDESTROY
)
1635 return GuiConsoleHandleNcDestroy(hWnd
);
1639 * Now the terminal window is initialized.
1640 * Get the terminal data via the window's data.
1641 * If there is no data, just go away.
1643 GuiData
= GuiGetGuiData(hWnd
);
1644 if (GuiData
== NULL
) return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1647 * Just retrieve a pointer to the console in case somebody needs it.
1648 * It is not NULL because it was checked in GuiGetGuiData.
1649 * Each helper function which needs the console has to validate and lock it.
1651 Console
= GuiData
->Console
;
1653 /* We have a console, start message dispatching */
1658 if (LOWORD(wParam
) == WA_CLICKACTIVE
) GuiData
->IgnoreNextMouseSignal
= TRUE
;
1663 if (GuiConsoleHandleClose(GuiData
)) goto Default
;
1667 GuiConsoleHandlePaint(GuiData
);
1677 case WM_SYSDEADCHAR
:
1679 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1680 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1682 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1683 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
) GuiConsoleSwitchFullScreen(GuiData
);
1687 GuiConsoleHandleKey(GuiData
, msg
, wParam
, lParam
);
1692 GuiConsoleHandleTimer(GuiData
);
1698 * The message was sent because we are manually triggering a change.
1699 * Check whether the mouse is indeed present on this console window
1700 * and take appropriate decisions.
1702 if (wParam
== -1 && lParam
== -1)
1707 /* Get the placement of the mouse */
1708 GetCursorPos(&mouseCoords
);
1710 /* On which window is placed the mouse ? */
1711 hWndHit
= WindowFromPoint(mouseCoords
);
1713 /* It's our window. Perform the hit-test to be used later on. */
1714 if (hWndHit
== hWnd
)
1716 wParam
= (WPARAM
)hWnd
;
1717 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1718 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1722 /* Set the mouse cursor only when we are in the client area */
1723 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1725 if (GuiData
->MouseCursorRefCount
>= 0)
1727 /* Show the cursor */
1728 SetCursor(GuiData
->hCursor
);
1732 /* Hide the cursor if the reference count is negative */
1743 case WM_LBUTTONDOWN
:
1744 case WM_MBUTTONDOWN
:
1745 case WM_RBUTTONDOWN
:
1749 case WM_LBUTTONDBLCLK
:
1750 case WM_MBUTTONDBLCLK
:
1751 case WM_RBUTTONDBLCLK
:
1754 case WM_MOUSEHWHEEL
:
1756 Result
= GuiConsoleHandleMouse(GuiData
, msg
, wParam
, lParam
);
1763 Result
= GuiConsoleHandleScroll(GuiData
, msg
, wParam
);
1767 case WM_NCRBUTTONDOWN
:
1769 DPRINT1("WM_NCRBUTTONDOWN\n");
1771 * HACK: !! Because, when we deal with WM_RBUTTON* and we do not
1772 * call after that DefWindowProc, on ReactOS, right-clicks on the
1773 * (non-client) application title-bar does not display the system
1774 * menu and does not trigger a WM_NCRBUTTONUP message too.
1775 * See: http://git.reactos.org/?p=reactos.git;a=blob;f=reactos/win32ss/user/user32/windows/defwnd.c;hb=HEAD#l1103
1776 * and line 1135 too.
1778 if (DefWindowProcW(hWnd
, WM_NCHITTEST
, 0, lParam
) == HTCAPTION
)
1780 /* Call DefWindowProcW with the WM_CONTEXTMENU message */
1781 msg
= WM_CONTEXTMENU
;
1785 // case WM_NCRBUTTONUP:
1786 // DPRINT1("WM_NCRBUTTONUP\n");
1789 case WM_CONTEXTMENU
:
1791 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
1793 HMENU hMenu
= CreatePopupMenu();
1796 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
1797 TrackPopupMenuEx(hMenu
,
1799 GET_X_LPARAM(lParam
),
1800 GET_Y_LPARAM(lParam
),
1815 HMENU hMenu
= (HMENU
)wParam
;
1818 /* Enable or disable the Close menu item */
1819 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
1820 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
1822 /* Enable or disable the Copy and Paste items */
1823 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
1824 ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1825 (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
1826 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
1827 (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1828 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
1831 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1833 GuiSendMenuEvent(Console
, WM_INITMENU
);
1834 LeaveCriticalSection(&Console
->Lock
);
1841 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
1843 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1845 GuiSendMenuEvent(Console
, WM_MENUSELECT
);
1846 LeaveCriticalSection(&Console
->Lock
);
1855 Result
= GuiConsoleHandleSysMenuCommand(GuiData
, wParam
, lParam
);
1862 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1865 er
.EventType
= FOCUS_EVENT
;
1866 er
.Event
.FocusEvent
.bSetFocus
= (msg
== WM_SETFOCUS
);
1867 ConioProcessInputEvent(Console
, &er
);
1869 if (msg
== WM_SETFOCUS
)
1870 DPRINT1("TODO: Create console caret\n");
1871 else // if (msg == WM_KILLFOCUS)
1872 DPRINT1("TODO: Destroy console caret\n");
1874 LeaveCriticalSection(&Console
->Lock
);
1879 case WM_GETMINMAXINFO
:
1880 GuiConsoleGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
1884 GuiConsoleResize(GuiData
, wParam
, lParam
);
1887 case PM_RESIZE_TERMINAL
:
1889 /* Resize the window to the user's values */
1890 GuiData
->WindowSizeLock
= TRUE
;
1891 GuiConsoleResizeWindow(GuiData
);
1892 GuiData
->WindowSizeLock
= FALSE
;
1896 case PM_APPLY_CONSOLE_INFO
:
1898 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1900 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
1901 LeaveCriticalSection(&Console
->Lock
);
1906 case PM_CONSOLE_BEEP
:
1907 DPRINT1("Beep !!\n");
1911 // case PM_CONSOLE_SET_TITLE:
1912 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
1916 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1925 /******************************************************************************
1926 * GUI Terminal Initialization *
1927 ******************************************************************************/
1929 static LRESULT CALLBACK
1930 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1940 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
1944 case PM_CREATE_CONSOLE
:
1946 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
1947 PCONSOLE Console
= GuiData
->Console
;
1949 NewWindow
= CreateWindowExW(WS_EX_CLIENTEDGE
,
1950 GUI_CONSOLE_WINDOW_CLASS
,
1951 Console
->Title
.Buffer
,
1952 WS_OVERLAPPEDWINDOW
| WS_HSCROLL
| WS_VSCROLL
,
1961 if (NULL
!= NewWindow
)
1963 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
1965 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
1967 DPRINT("Set icons via PM_CREATE_CONSOLE\n");
1968 if (GuiData
->hIcon
== NULL
)
1970 DPRINT("Not really /o\\...\n");
1971 GuiData
->hIcon
= ghDefaultIcon
;
1972 GuiData
->hIconSm
= ghDefaultIconSm
;
1974 else if (GuiData
->hIcon
!= ghDefaultIcon
)
1976 DPRINT("Yes \\o/\n");
1977 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
1978 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
1981 /* Move and resize the window to the user's values */
1982 /* CAN WE DEADLOCK ?? */
1983 GuiConsoleMoveWindow(GuiData
);
1984 GuiData
->WindowSizeLock
= TRUE
;
1985 GuiConsoleResizeWindow(GuiData
);
1986 GuiData
->WindowSizeLock
= FALSE
;
1988 // ShowWindow(NewWindow, (int)wParam);
1989 ShowWindowAsync(NewWindow
, (int)wParam
);
1990 DPRINT("Window showed\n");
1993 return (LRESULT
)NewWindow
;
1996 case PM_DESTROY_CONSOLE
:
1998 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2001 * Window creation is done using a PostMessage(), so it's possible
2002 * that the window that we want to destroy doesn't exist yet.
2003 * So first empty the message queue.
2006 while (PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE))
2008 TranslateMessage(&Msg);
2009 DispatchMessageW(&Msg);
2011 while (PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
)) ;
2013 if (GuiData
->hWindow
!= NULL
) /* && DestroyWindow(GuiData->hWindow) */
2015 DestroyWindow(GuiData
->hWindow
);
2017 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2019 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2020 if (0 == WindowCount
)
2023 DestroyWindow(hWnd
);
2024 DPRINT("CONSRV: Going to quit the Gui Thread!!\n");
2033 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2038 GuiConsoleGuiThread(PVOID Data
)
2041 PHANDLE GraphicsStartupEvent
= (PHANDLE
)Data
;
2044 * This thread dispatches all the console notifications to the notify window.
2045 * It is common for all the console windows.
2048 PrivateCsrssManualGuiCheck(+1);
2050 NotifyWnd
= CreateWindowW(L
"ConSrvCreateNotify",
2052 WS_OVERLAPPEDWINDOW
,
2061 if (NULL
== NotifyWnd
)
2063 PrivateCsrssManualGuiCheck(-1);
2064 SetEvent(*GraphicsStartupEvent
);
2068 SetEvent(*GraphicsStartupEvent
);
2070 while (GetMessageW(&msg
, NULL
, 0, 0))
2072 TranslateMessage(&msg
);
2073 DispatchMessageW(&msg
);
2076 DPRINT("CONSRV: Quit the Gui Thread!!\n");
2077 PrivateCsrssManualGuiCheck(-1);
2086 ATOM ConsoleClassAtom
;
2088 /* Exit if we were already initialized */
2089 // if (ConsInitialized) return TRUE;
2092 * Initialize and register the different window classes, if needed.
2094 if (!ConsInitialized
)
2096 /* Initialize the notification window class */
2097 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2098 wc
.lpszClassName
= L
"ConSrvCreateNotify";
2099 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
2101 wc
.hInstance
= ConSrvDllInstance
;
2105 wc
.hbrBackground
= NULL
;
2106 wc
.lpszMenuName
= NULL
;
2109 if (RegisterClassExW(&wc
) == 0)
2111 DPRINT1("Failed to register GUI notify wndproc\n");
2115 /* Initialize the console window class */
2116 ghDefaultIcon
= LoadImageW(ConSrvDllInstance
,
2117 MAKEINTRESOURCEW(IDI_TERMINAL
),
2119 GetSystemMetrics(SM_CXICON
),
2120 GetSystemMetrics(SM_CYICON
),
2122 ghDefaultIconSm
= LoadImageW(ConSrvDllInstance
,
2123 MAKEINTRESOURCEW(IDI_TERMINAL
),
2125 GetSystemMetrics(SM_CXSMICON
),
2126 GetSystemMetrics(SM_CYSMICON
),
2128 ghDefaultCursor
= LoadCursorW(NULL
, IDC_ARROW
);
2129 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2130 wc
.lpszClassName
= GUI_CONSOLE_WINDOW_CLASS
;
2131 wc
.lpfnWndProc
= GuiConsoleWndProc
;
2132 wc
.style
= CS_DBLCLKS
/* | CS_HREDRAW | CS_VREDRAW */;
2133 wc
.hInstance
= ConSrvDllInstance
;
2134 wc
.hIcon
= ghDefaultIcon
;
2135 wc
.hIconSm
= ghDefaultIconSm
;
2136 wc
.hCursor
= ghDefaultCursor
;
2137 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
); // The color of a terminal when it is switch off.
2138 wc
.lpszMenuName
= NULL
;
2140 wc
.cbWndExtra
= GWLP_CONSOLEWND_ALLOC
;
2142 ConsoleClassAtom
= RegisterClassExW(&wc
);
2143 if (ConsoleClassAtom
== 0)
2145 DPRINT1("Failed to register GUI console wndproc\n");
2150 NtUserConsoleControl(GuiConsoleWndClassAtom
, &ConsoleClassAtom
, sizeof(ATOM
));
2153 ConsInitialized
= TRUE
;
2157 * Set-up the notification window
2159 if (NULL
== NotifyWnd
)
2161 HANDLE ThreadHandle
;
2162 HANDLE GraphicsStartupEvent
;
2164 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2165 if (NULL
== GraphicsStartupEvent
) return FALSE
;
2167 ThreadHandle
= CreateThread(NULL
,
2169 GuiConsoleGuiThread
,
2170 (PVOID
)&GraphicsStartupEvent
,
2173 if (NULL
== ThreadHandle
)
2175 CloseHandle(GraphicsStartupEvent
);
2176 DPRINT1("CONSRV: Failed to create graphics console thread. Expect problems\n");
2179 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
2180 CloseHandle(ThreadHandle
);
2182 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
2183 CloseHandle(GraphicsStartupEvent
);
2185 if (NULL
== NotifyWnd
)
2187 DPRINT1("CONSRV: Failed to create notification window.\n");
2192 // ConsInitialized = TRUE;
2199 /******************************************************************************
2200 * GUI Console Driver *
2201 ******************************************************************************/
2204 GuiDeinitFrontEnd(IN OUT PFRONTEND This
);
2207 GuiInitFrontEnd(IN OUT PFRONTEND This
,
2208 IN PCONSOLE Console
)
2210 PGUI_INIT_INFO GuiInitInfo
;
2211 PCONSOLE_INFO ConsoleInfo
;
2212 PCONSOLE_START_INFO ConsoleStartInfo
;
2214 PGUI_CONSOLE_DATA GuiData
;
2215 GUI_CONSOLE_INFO TermInfo
;
2218 LPWSTR IconPath
= NULL
;
2221 if (This
== NULL
|| Console
== NULL
|| This
->OldData
== NULL
)
2222 return STATUS_INVALID_PARAMETER
;
2224 ASSERT(This
->Console
== Console
);
2226 GuiInitInfo
= This
->OldData
;
2228 if (GuiInitInfo
->ConsoleInfo
== NULL
|| GuiInitInfo
->ConsoleStartInfo
== NULL
)
2229 return STATUS_INVALID_PARAMETER
;
2231 ConsoleInfo
= GuiInitInfo
->ConsoleInfo
;
2232 ConsoleStartInfo
= GuiInitInfo
->ConsoleStartInfo
;
2234 IconPath
= ConsoleStartInfo
->IconPath
;
2235 IconIndex
= ConsoleStartInfo
->IconIndex
;
2238 /* Terminal data allocation */
2239 GuiData
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_CONSOLE_DATA
));
2242 DPRINT1("CONSRV: Failed to create GUI_CONSOLE_DATA\n");
2243 return STATUS_UNSUCCESSFUL
;
2245 /* HACK */ Console
->TermIFace
.Data
= (PVOID
)GuiData
; /* HACK */
2246 GuiData
->Console
= Console
;
2247 GuiData
->hWindow
= NULL
;
2249 /* The console can be resized */
2250 Console
->FixedSize
= FALSE
;
2252 InitializeCriticalSection(&GuiData
->Lock
);
2256 * Load terminal settings
2259 /* 1. Load the default settings */
2260 GuiConsoleGetDefaultSettings(&TermInfo
, GuiInitInfo
->ProcessId
);
2262 /* 3. Load the remaining console settings via the registry. */
2263 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2265 /* Load the terminal infos from the registry. */
2266 GuiConsoleReadUserSettings(&TermInfo
,
2267 ConsoleInfo
->ConsoleTitle
,
2268 GuiInitInfo
->ProcessId
);
2271 * Now, update them with the properties the user might gave to us
2272 * via the STARTUPINFO structure before calling CreateProcess
2273 * (and which was transmitted via the ConsoleStartInfo structure).
2274 * We therefore overwrite the values read in the registry.
2276 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USESHOWWINDOW
)
2278 TermInfo
.ShowWindow
= ConsoleStartInfo
->ShowWindow
;
2280 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USEPOSITION
)
2282 TermInfo
.AutoPosition
= FALSE
;
2283 TermInfo
.WindowOrigin
= ConsoleStartInfo
->ConsoleWindowOrigin
;
2285 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_RUNFULLSCREEN
)
2287 TermInfo
.FullScreen
= TRUE
;
2296 Length
= min(wcslen(TermInfo
.FaceName
) + 1, LF_FACESIZE
); // wcsnlen
2297 wcsncpy(GuiData
->GuiInfo
.FaceName
, TermInfo
.FaceName
, LF_FACESIZE
);
2298 GuiData
->GuiInfo
.FaceName
[Length
] = L
'\0';
2299 GuiData
->GuiInfo
.FontFamily
= TermInfo
.FontFamily
;
2300 GuiData
->GuiInfo
.FontSize
= TermInfo
.FontSize
;
2301 GuiData
->GuiInfo
.FontWeight
= TermInfo
.FontWeight
;
2302 GuiData
->GuiInfo
.UseRasterFonts
= TermInfo
.UseRasterFonts
;
2303 GuiData
->GuiInfo
.FullScreen
= TermInfo
.FullScreen
;
2304 GuiData
->GuiInfo
.ShowWindow
= TermInfo
.ShowWindow
;
2305 GuiData
->GuiInfo
.AutoPosition
= TermInfo
.AutoPosition
;
2306 GuiData
->GuiInfo
.WindowOrigin
= TermInfo
.WindowOrigin
;
2308 /* Initialize the icon handles to their default values */
2309 GuiData
->hIcon
= ghDefaultIcon
;
2310 GuiData
->hIconSm
= ghDefaultIconSm
;
2312 /* Get the associated icon, if any */
2313 if (IconPath
== NULL
|| IconPath
[0] == L
'\0')
2315 IconPath
= ConsoleStartInfo
->AppPath
;
2318 DPRINT("IconPath = %S ; IconIndex = %lu\n", (IconPath
? IconPath
: L
"n/a"), IconIndex
);
2319 if (IconPath
&& IconPath
[0] != L
'\0')
2321 HICON hIcon
= NULL
, hIconSm
= NULL
;
2322 PrivateExtractIconExW(IconPath
,
2327 DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon
, hIconSm
);
2330 DPRINT("Effectively set the icons\n");
2331 GuiData
->hIcon
= hIcon
;
2332 GuiData
->hIconSm
= hIconSm
;
2336 /* Mouse is shown by default with its default cursor shape */
2337 GuiData
->hCursor
= ghDefaultCursor
;
2338 GuiData
->MouseCursorRefCount
= 0;
2340 /* A priori don't ignore mouse signals */
2341 GuiData
->IgnoreNextMouseSignal
= FALSE
;
2343 /* Close button and the corresponding system menu item are enabled by default */
2344 GuiData
->IsCloseButtonEnabled
= TRUE
;
2346 /* There is no user-reserved menu id range by default */
2347 GuiData
->cmdIdLow
= GuiData
->cmdIdHigh
= 0;
2350 * We need to wait until the GUI has been fully initialized
2351 * to retrieve custom settings i.e. WindowSize etc...
2352 * Ideally we could use SendNotifyMessage for this but its not
2355 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2357 DPRINT("GUI - Checkpoint\n");
2359 /* Create the terminal window */
2360 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, GuiData
->GuiInfo
.ShowWindow
, (LPARAM
)GuiData
);
2362 /* Wait until initialization has finished */
2363 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
2364 DPRINT("OK we created the console window\n");
2365 CloseHandle(GuiData
->hGuiInitEvent
);
2366 GuiData
->hGuiInitEvent
= NULL
;
2368 /* Check whether we really succeeded in initializing the terminal window */
2369 if (GuiData
->hWindow
== NULL
)
2371 DPRINT("GuiInitConsole - We failed at creating a new terminal window\n");
2372 GuiDeinitFrontEnd(This
);
2373 return STATUS_UNSUCCESSFUL
;
2376 /* Finally, finish to initialize the frontend structure */
2377 This
->Data
= GuiData
;
2378 if (This
->OldData
) ConsoleFreeHeap(This
->OldData
);
2379 This
->OldData
= NULL
;
2381 return STATUS_SUCCESS
;
2385 GuiDeinitFrontEnd(IN OUT PFRONTEND This
)
2387 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2389 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
)GuiData
);
2391 DPRINT("Destroying icons !! - GuiData->hIcon = 0x%p ; ghDefaultIcon = 0x%p ; GuiData->hIconSm = 0x%p ; ghDefaultIconSm = 0x%p\n",
2392 GuiData
->hIcon
, ghDefaultIcon
, GuiData
->hIconSm
, ghDefaultIconSm
);
2393 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2395 DPRINT("Destroy hIcon\n");
2396 DestroyIcon(GuiData
->hIcon
);
2398 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2400 DPRINT("Destroy hIconSm\n");
2401 DestroyIcon(GuiData
->hIconSm
);
2405 DeleteCriticalSection(&GuiData
->Lock
);
2406 ConsoleFreeHeap(GuiData
);
2408 DPRINT("Quit GuiDeinitFrontEnd\n");
2412 GuiDrawRegion(IN OUT PFRONTEND This
,
2415 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2418 SmallRectToRect(GuiData
, &RegionRect
, Region
);
2419 /* Do not erase the background: it speeds up redrawing and reduce flickering */
2420 InvalidateRect(GuiData
->hWindow
, &RegionRect
, FALSE
);
2424 GuiWriteStream(IN OUT PFRONTEND This
,
2432 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2433 PCONSOLE_SCREEN_BUFFER Buff
;
2434 SHORT CursorEndX
, CursorEndY
;
2437 if (NULL
== GuiData
|| NULL
== GuiData
->hWindow
) return;
2439 Buff
= ConDrvGetActiveScreenBuffer(GuiData
->Console
);
2440 if (GetType(Buff
) != TEXTMODE_BUFFER
) return;
2442 if (0 != ScrolledLines
)
2444 ScrollRect
.left
= 0;
2446 ScrollRect
.right
= Buff
->ViewSize
.X
* GuiData
->CharWidth
;
2447 ScrollRect
.bottom
= Region
->Top
* GuiData
->CharHeight
;
2449 ScrollWindowEx(GuiData
->hWindow
,
2451 -(int)(ScrolledLines
* GuiData
->CharHeight
),
2459 GuiDrawRegion(This
, Region
);
2461 if (CursorStartX
< Region
->Left
|| Region
->Right
< CursorStartX
2462 || CursorStartY
< Region
->Top
|| Region
->Bottom
< CursorStartY
)
2464 GuiInvalidateCell(This
, CursorStartX
, CursorStartY
);
2467 CursorEndX
= Buff
->CursorPosition
.X
;
2468 CursorEndY
= Buff
->CursorPosition
.Y
;
2469 if ((CursorEndX
< Region
->Left
|| Region
->Right
< CursorEndX
2470 || CursorEndY
< Region
->Top
|| Region
->Bottom
< CursorEndY
)
2471 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
2473 GuiInvalidateCell(This
, CursorEndX
, CursorEndY
);
2476 // Set up the update timer (very short interval) - this is a "hack" for getting the OS to
2477 // repaint the window without having it just freeze up and stay on the screen permanently.
2478 Buff
->CursorBlinkOn
= TRUE
;
2479 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
2483 GuiSetCursorInfo(IN OUT PFRONTEND This
,
2484 PCONSOLE_SCREEN_BUFFER Buff
)
2486 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2488 if (ConDrvGetActiveScreenBuffer(GuiData
->Console
) == Buff
)
2490 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2497 GuiSetScreenInfo(IN OUT PFRONTEND This
,
2498 PCONSOLE_SCREEN_BUFFER Buff
,
2502 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2504 if (ConDrvGetActiveScreenBuffer(GuiData
->Console
) == Buff
)
2506 /* Redraw char at old position (remove cursor) */
2507 GuiInvalidateCell(This
, OldCursorX
, OldCursorY
);
2508 /* Redraw char at new position (show cursor) */
2509 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2516 GuiResizeTerminal(IN OUT PFRONTEND This
)
2518 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2520 /* Resize the window to the user's values */
2521 // GuiData->WindowSizeLock = TRUE;
2522 // GuiConsoleResizeWindow(GuiData);
2523 // GuiData->WindowSizeLock = FALSE;
2524 // NOTE: This code ^^ causes deadlocks...
2526 PostMessageW(GuiData
->hWindow
, PM_RESIZE_TERMINAL
, 0, 0);
2530 GuiProcessKeyCallback(IN OUT PFRONTEND This
,
2534 UINT VirtualKeyCode
,
2537 if ((ShiftState
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
) || KeyStateMenu
& 0x80) &&
2538 (VirtualKeyCode
== VK_ESCAPE
|| VirtualKeyCode
== VK_TAB
|| VirtualKeyCode
== VK_SPACE
))
2540 DefWindowProcW(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2548 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2552 GuiRefreshInternalInfo(IN OUT PFRONTEND This
)
2554 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2556 /* Update the console leader information held by the window */
2557 SetConsoleWndConsoleLeaderCID(GuiData
);
2561 * We reset the cursor here so that, when a console app quits, we reset
2562 * the cursor to the default one. It's quite a hack since it doesn't proceed
2563 * per - console process... This must be fixed.
2565 * See GuiInitConsole(...) for more information.
2568 /* Mouse is shown by default with its default cursor shape */
2569 GuiData
->MouseCursorRefCount
= 0; // Reinitialize the reference counter
2570 GuiSetMouseCursor(This
, NULL
);
2574 GuiChangeTitle(IN OUT PFRONTEND This
)
2576 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2577 // PostMessageW(GuiData->hWindow, PM_CONSOLE_SET_TITLE, 0, 0);
2578 SetWindowText(GuiData
->hWindow
, GuiData
->Console
->Title
.Buffer
);
2582 GuiChangeIcon(IN OUT PFRONTEND This
,
2585 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2586 HICON hIcon
, hIconSm
;
2588 if (hWindowIcon
== NULL
)
2590 hIcon
= ghDefaultIcon
;
2591 hIconSm
= ghDefaultIconSm
;
2595 hIcon
= CopyIcon(hWindowIcon
);
2596 hIconSm
= CopyIcon(hWindowIcon
);
2604 if (hIcon
!= GuiData
->hIcon
)
2606 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2608 DestroyIcon(GuiData
->hIcon
);
2610 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2612 DestroyIcon(GuiData
->hIconSm
);
2615 GuiData
->hIcon
= hIcon
;
2616 GuiData
->hIconSm
= hIconSm
;
2618 DPRINT("Set icons in GuiChangeIcon\n");
2619 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2620 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2627 GuiGetConsoleWindowHandle(IN OUT PFRONTEND This
)
2629 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2630 return GuiData
->hWindow
;
2634 GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This
,
2637 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2638 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
2641 UINT WidthUnit
, HeightUnit
;
2645 if (!SystemParametersInfoW(SPI_GETWORKAREA
, 0, &WorkArea
, 0))
2647 DPRINT1("SystemParametersInfoW failed - What to do ??\n");
2651 ActiveBuffer
= ConDrvGetActiveScreenBuffer(GuiData
->Console
);
2654 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
2658 /* Default: text mode */
2659 WidthUnit
= GuiData
->CharWidth
;
2660 HeightUnit
= GuiData
->CharHeight
;
2663 width
= WorkArea
.right
;
2664 height
= WorkArea
.bottom
;
2666 width
-= (2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
)));
2667 height
-= (2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
));
2669 if (width
< 0) width
= 0;
2670 if (height
< 0) height
= 0;
2672 pSize
->X
= (SHORT
)(width
/ (int)WidthUnit
) /* HACK */ + 2;
2673 pSize
->Y
= (SHORT
)(height
/ (int)HeightUnit
) /* HACK */ + 1;
2677 GuiGetDisplayMode(IN OUT PFRONTEND This
)
2679 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2680 ULONG DisplayMode
= 0;
2682 if (GuiData
->GuiInfo
.FullScreen
)
2683 DisplayMode
|= CONSOLE_FULLSCREEN_HARDWARE
; // CONSOLE_FULLSCREEN
2685 DisplayMode
|= CONSOLE_WINDOWED
;
2691 GuiSetDisplayMode(IN OUT PFRONTEND This
,
2694 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2696 if (NewMode
& ~(CONSOLE_FULLSCREEN_MODE
| CONSOLE_WINDOWED_MODE
))
2699 GuiData
->GuiInfo
.FullScreen
= (NewMode
& CONSOLE_FULLSCREEN_MODE
);
2700 // TODO: Change the display mode
2705 GuiShowMouseCursor(IN OUT PFRONTEND This
,
2708 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2710 /* Set the reference count */
2711 if (Show
) ++GuiData
->MouseCursorRefCount
;
2712 else --GuiData
->MouseCursorRefCount
;
2714 /* Effectively show (or hide) the cursor (use special values for (w|l)Param) */
2715 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2717 return GuiData
->MouseCursorRefCount
;
2721 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2724 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2727 * Set the cursor's handle. If the given handle is NULL,
2728 * then restore the default cursor.
2730 GuiData
->hCursor
= (hCursor
? hCursor
: ghDefaultCursor
);
2732 /* Effectively modify the shape of the cursor (use special values for (w|l)Param) */
2733 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2739 GuiMenuControl(IN OUT PFRONTEND This
,
2743 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2745 GuiData
->cmdIdLow
= cmdIdLow
;
2746 GuiData
->cmdIdHigh
= cmdIdHigh
;
2748 return GetSystemMenu(GuiData
->hWindow
, FALSE
);
2752 GuiSetMenuClose(IN OUT PFRONTEND This
,
2756 * NOTE: See http://www.mail-archive.com/harbour@harbour-project.org/msg27509.html
2757 * or http://harbour-devel.1590103.n2.nabble.com/Question-about-hb-gt-win-CtrlHandler-usage-td4670862i20.html
2758 * for more information.
2761 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2762 HMENU hSysMenu
= GetSystemMenu(GuiData
->hWindow
, FALSE
);
2764 if (hSysMenu
== NULL
) return FALSE
;
2766 GuiData
->IsCloseButtonEnabled
= Enable
;
2767 EnableMenuItem(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| (Enable
? MF_ENABLED
: MF_GRAYED
));
2772 static FRONTEND_VTBL GuiVtbl
=
2781 GuiProcessKeyCallback
,
2782 GuiRefreshInternalInfo
,
2785 GuiGetConsoleWindowHandle
,
2786 GuiGetLargestConsoleWindowSize
,
2797 LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo
,
2798 IN OUT PCONSOLE_INFO ConsoleInfo
)
2800 #define PATH_SEPARATOR L'\\'
2802 BOOL RetVal
= FALSE
;
2803 HRESULT hRes
= S_OK
;
2804 LPWSTR LinkName
= NULL
;
2807 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2810 ConsoleStartInfo
->IconPath
[0] = L
'\0';
2811 ConsoleStartInfo
->IconIndex
= 0;
2813 /* 1- Find the last path separator if any */
2814 LinkName
= wcsrchr(ConsoleStartInfo
->ConsoleTitle
, PATH_SEPARATOR
);
2815 if (LinkName
== NULL
)
2817 LinkName
= ConsoleStartInfo
->ConsoleTitle
;
2821 /* Skip the path separator */
2825 /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
2826 Length
= wcslen(LinkName
);
2827 if ( (Length
<= 4) || (wcsicmp(LinkName
+ (Length
- 4), L
".lnk") != 0) )
2830 /* 3- It may be a link. Try to retrieve some properties */
2831 hRes
= CoInitialize(NULL
);
2832 if (SUCCEEDED(hRes
))
2834 /* Get a pointer to the IShellLink interface */
2835 IShellLinkW
* pshl
= NULL
;
2836 hRes
= CoCreateInstance(&CLSID_ShellLink
,
2838 CLSCTX_INPROC_SERVER
,
2841 if (SUCCEEDED(hRes
))
2843 /* Get a pointer to the IPersistFile interface */
2844 IPersistFile
* ppf
= NULL
;
2845 hRes
= IPersistFile_QueryInterface(pshl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
2846 if (SUCCEEDED(hRes
))
2848 /* Load the shortcut */
2849 hRes
= IPersistFile_Load(ppf
, ConsoleStartInfo
->ConsoleTitle
, STGM_READ
);
2850 if (SUCCEEDED(hRes
))
2853 * Finally we can get the properties !
2854 * Update the old ones if needed.
2859 /* Reset the name of the console with the name of the shortcut */
2860 Length
= min(/*Length*/ Length
- 4, // 4 == len(".lnk")
2861 sizeof(ConsoleInfo
->ConsoleTitle
) / sizeof(ConsoleInfo
->ConsoleTitle
[0]) - 1);
2862 wcsncpy(ConsoleInfo
->ConsoleTitle
, LinkName
, Length
);
2863 ConsoleInfo
->ConsoleTitle
[Length
] = L
'\0';
2865 /* Get the window showing command */
2866 hRes
= IShellLinkW_GetShowCmd(pshl
, &ShowCmd
);
2867 if (SUCCEEDED(hRes
)) ConsoleStartInfo
->ShowWindow
= (WORD
)ShowCmd
;
2869 /* Get the hotkey */
2870 // hRes = pshl->GetHotkey(&ShowCmd);
2871 // if (SUCCEEDED(hRes)) ConsoleStartInfo->HotKey = HotKey;
2873 /* Get the icon location, if any */
2875 hRes
= IShellLinkW_GetIconLocation(pshl
,
2876 ConsoleStartInfo
->IconPath
,
2877 sizeof(ConsoleStartInfo
->IconPath
)/sizeof(ConsoleStartInfo
->IconPath
[0]) - 1, // == MAX_PATH
2878 &ConsoleStartInfo
->IconIndex
);
2879 if (!SUCCEEDED(hRes
))
2881 ConsoleStartInfo
->IconPath
[0] = L
'\0';
2882 ConsoleStartInfo
->IconIndex
= 0;
2885 // FIXME: Since we still don't load console properties from the shortcut,
2886 // return false. When this will be done, we will return true instead.
2889 IPersistFile_Release(ppf
);
2891 IShellLinkW_Release(pshl
);
2900 GuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd
,
2901 IN OUT PCONSOLE_INFO ConsoleInfo
,
2902 IN OUT PVOID ExtraConsoleInfo
,
2905 PCONSOLE_START_INFO ConsoleStartInfo
= ExtraConsoleInfo
;
2906 PGUI_INIT_INFO GuiInitInfo
;
2908 if (FrontEnd
== NULL
|| ConsoleInfo
== NULL
|| ConsoleStartInfo
== NULL
)
2909 return STATUS_INVALID_PARAMETER
;
2911 /* Initialize GUI terminal emulator common functionalities */
2912 if (!GuiInit()) return STATUS_UNSUCCESSFUL
;
2915 * Load per-application terminal settings.
2917 * Check whether the process creating the console was launched via
2918 * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
2919 * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
2921 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
)
2923 if (!LoadShellLinkConsoleInfo(ConsoleStartInfo
, ConsoleInfo
))
2925 ConsoleStartInfo
->dwStartupFlags
&= ~STARTF_TITLEISLINKNAME
;
2930 * Initialize a private initialization info structure for later use.
2931 * It must be freed by a call to GuiUnloadFrontEnd or GuiInitFrontEnd.
2933 GuiInitInfo
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_INIT_INFO
));
2934 if (GuiInitInfo
== NULL
) return STATUS_NO_MEMORY
;
2936 // HACK: We suppose that the pointers will be valid in GuiInitFrontEnd...
2937 GuiInitInfo
->ConsoleInfo
= ConsoleInfo
;
2938 GuiInitInfo
->ConsoleStartInfo
= ConsoleStartInfo
;
2939 GuiInitInfo
->ProcessId
= ProcessId
;
2941 /* Finally, initialize the frontend structure */
2942 FrontEnd
->Vtbl
= &GuiVtbl
;
2943 FrontEnd
->Data
= NULL
;
2944 FrontEnd
->OldData
= GuiInitInfo
;
2946 return STATUS_SUCCESS
;
2950 GuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd
)
2952 if (FrontEnd
== NULL
) return STATUS_INVALID_PARAMETER
;
2954 if (FrontEnd
->Data
) GuiDeinitFrontEnd(FrontEnd
);
2955 if (FrontEnd
->OldData
) ConsoleFreeHeap(FrontEnd
->OldData
);
2957 return STATUS_SUCCESS
;