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 hDC
= GetDC(GuiData
->hWindow
);
558 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
559 DeleteObject(GuiData
->Font
);
560 GuiData
->hWindow
= NULL
;
561 SetEvent(GuiData
->hGuiInitEvent
);
564 OldFont
= SelectObject(hDC
, GuiData
->Font
);
567 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
568 ReleaseDC(GuiData
->hWindow
, hDC
);
569 DeleteObject(GuiData
->Font
);
570 GuiData
->hWindow
= NULL
;
571 SetEvent(GuiData
->hGuiInitEvent
);
574 if (!GetTextMetricsW(hDC
, &Metrics
))
576 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
577 SelectObject(hDC
, OldFont
);
578 ReleaseDC(GuiData
->hWindow
, hDC
);
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(hDC
, L
"R", 1, &CharSize
))
589 GuiData
->CharWidth
= CharSize
.cx
;
591 SelectObject(hDC
, OldFont
);
593 ReleaseDC(GuiData
->hWindow
, hDC
);
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
);
1703 case WM_PALETTECHANGED
:
1705 PCONSOLE_SCREEN_BUFFER ActiveBuffer
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(GuiData->Console);
1707 DPRINT1("WM_PALETTECHANGED called\n");
1710 * Protects against infinite loops:
1711 * "... A window that receives this message must not realize
1712 * its palette, unless it determines that wParam does not contain
1713 * its own window handle." (WM_PALETTECHANGED description - MSDN)
1715 * This message is sent to all windows, including the one that
1716 * changed the system palette and caused this message to be sent.
1717 * The wParam of this message contains the handle of the window
1718 * that caused the system palette to change. To avoid an infinite
1719 * loop, care must be taken to check that the wParam of this message
1720 * does not match the window's handle.
1722 if ((HWND
)wParam
== hWnd
) break;
1724 DPRINT1("WM_PALETTECHANGED ok\n");
1726 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
1727 if (ActiveBuffer
->PaletteHandle
)
1729 /* Get the Device Context of the console window */
1730 HDC hDC
= GetDC(GuiData
->hWindow
);
1732 DPRINT1("WM_PALETTECHANGED changing palette\n");
1734 /* Specify the use of the system palette */
1735 SetSystemPaletteUse(hDC
, ActiveBuffer
->PaletteUsage
);
1737 /* Realize the (logical) palette */
1738 RealizePalette(hDC
);
1740 /* Release the Device Context and return */
1741 ReleaseDC(GuiData
->hWindow
, hDC
);
1744 DPRINT1("WM_PALETTECHANGED quit\n");
1756 case WM_SYSDEADCHAR
:
1758 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
1759 if (msg
== WM_SYSKEYDOWN
&& (HIWORD(lParam
) & KF_ALTDOWN
) && wParam
== VK_RETURN
)
1761 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
1762 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
) GuiConsoleSwitchFullScreen(GuiData
);
1766 GuiConsoleHandleKey(GuiData
, msg
, wParam
, lParam
);
1771 GuiConsoleHandleTimer(GuiData
);
1777 * The message was sent because we are manually triggering a change.
1778 * Check whether the mouse is indeed present on this console window
1779 * and take appropriate decisions.
1781 if (wParam
== -1 && lParam
== -1)
1786 /* Get the placement of the mouse */
1787 GetCursorPos(&mouseCoords
);
1789 /* On which window is placed the mouse ? */
1790 hWndHit
= WindowFromPoint(mouseCoords
);
1792 /* It's our window. Perform the hit-test to be used later on. */
1793 if (hWndHit
== hWnd
)
1795 wParam
= (WPARAM
)hWnd
;
1796 lParam
= DefWindowProcW(hWndHit
, WM_NCHITTEST
, 0,
1797 MAKELPARAM(mouseCoords
.x
, mouseCoords
.y
));
1801 /* Set the mouse cursor only when we are in the client area */
1802 if ((HWND
)wParam
== hWnd
&& LOWORD(lParam
) == HTCLIENT
)
1804 if (GuiData
->MouseCursorRefCount
>= 0)
1806 /* Show the cursor */
1807 SetCursor(GuiData
->hCursor
);
1811 /* Hide the cursor if the reference count is negative */
1822 case WM_LBUTTONDOWN
:
1823 case WM_MBUTTONDOWN
:
1824 case WM_RBUTTONDOWN
:
1828 case WM_LBUTTONDBLCLK
:
1829 case WM_MBUTTONDBLCLK
:
1830 case WM_RBUTTONDBLCLK
:
1833 case WM_MOUSEHWHEEL
:
1835 Result
= GuiConsoleHandleMouse(GuiData
, msg
, wParam
, lParam
);
1842 Result
= GuiConsoleHandleScroll(GuiData
, msg
, wParam
);
1846 case WM_NCRBUTTONDOWN
:
1848 DPRINT1("WM_NCRBUTTONDOWN\n");
1850 * HACK: !! Because, when we deal with WM_RBUTTON* and we do not
1851 * call after that DefWindowProc, on ReactOS, right-clicks on the
1852 * (non-client) application title-bar does not display the system
1853 * menu and does not trigger a WM_NCRBUTTONUP message too.
1854 * See: http://git.reactos.org/?p=reactos.git;a=blob;f=reactos/win32ss/user/user32/windows/defwnd.c;hb=332bc8f482f40fd05ab510f78276576719fbfba8#l1103
1855 * and line 1135 too.
1858 if (DefWindowProcW(hWnd
, WM_NCHITTEST
, 0, lParam
) == HTCAPTION
)
1860 /* Call DefWindowProcW with the WM_CONTEXTMENU message */
1861 msg
= WM_CONTEXTMENU
;
1866 // case WM_NCRBUTTONUP:
1867 // DPRINT1("WM_NCRBUTTONUP\n");
1870 case WM_CONTEXTMENU
:
1872 if (DefWindowProcW(hWnd
/*GuiData->hWindow*/, WM_NCHITTEST
, 0, lParam
) == HTCLIENT
)
1874 HMENU hMenu
= CreatePopupMenu();
1877 GuiConsoleAppendMenuItems(hMenu
, GuiConsoleEditMenuItems
);
1878 TrackPopupMenuEx(hMenu
,
1880 GET_X_LPARAM(lParam
),
1881 GET_Y_LPARAM(lParam
),
1896 HMENU hMenu
= (HMENU
)wParam
;
1899 /* Enable or disable the Close menu item */
1900 EnableMenuItem(hMenu
, SC_CLOSE
, MF_BYCOMMAND
|
1901 (GuiData
->IsCloseButtonEnabled
? MF_ENABLED
: MF_GRAYED
));
1903 /* Enable or disable the Copy and Paste items */
1904 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_COPY
, MF_BYCOMMAND
|
1905 ((Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1906 (Console
->Selection
.dwFlags
& CONSOLE_SELECTION_NOT_EMPTY
) ? MF_ENABLED
: MF_GRAYED
));
1907 EnableMenuItem(hMenu
, ID_SYSTEM_EDIT_PASTE
, MF_BYCOMMAND
|
1908 (!(Console
->Selection
.dwFlags
& CONSOLE_SELECTION_IN_PROGRESS
) &&
1909 IsClipboardFormatAvailable(CF_UNICODETEXT
) ? MF_ENABLED
: MF_GRAYED
));
1912 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1914 GuiSendMenuEvent(Console
, WM_INITMENU
);
1915 LeaveCriticalSection(&Console
->Lock
);
1922 if (HIWORD(wParam
) == 0xFFFF) // Allow all the menu flags
1924 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1926 GuiSendMenuEvent(Console
, WM_MENUSELECT
);
1927 LeaveCriticalSection(&Console
->Lock
);
1936 Result
= GuiConsoleHandleSysMenuCommand(GuiData
, wParam
, lParam
);
1943 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1945 BOOL SetFocus
= (msg
== WM_SETFOCUS
);
1948 er
.EventType
= FOCUS_EVENT
;
1949 er
.Event
.FocusEvent
.bSetFocus
= SetFocus
;
1950 ConioProcessInputEvent(Console
, &er
);
1953 DPRINT1("TODO: Create console caret\n");
1955 DPRINT1("TODO: Destroy console caret\n");
1957 LeaveCriticalSection(&Console
->Lock
);
1962 case WM_GETMINMAXINFO
:
1963 GuiConsoleGetMinMaxInfo(GuiData
, (PMINMAXINFO
)lParam
);
1967 GuiConsoleResize(GuiData
, wParam
, lParam
);
1970 case PM_RESIZE_TERMINAL
:
1972 /* Resize the window to the user's values */
1973 GuiData
->WindowSizeLock
= TRUE
;
1974 GuiConsoleResizeWindow(GuiData
);
1975 GuiData
->WindowSizeLock
= FALSE
;
1979 case PM_APPLY_CONSOLE_INFO
:
1981 if (ConDrvValidateConsoleUnsafe(Console
, CONSOLE_RUNNING
, TRUE
))
1983 GuiApplyUserSettings(GuiData
, (HANDLE
)wParam
, (BOOL
)lParam
);
1984 LeaveCriticalSection(&Console
->Lock
);
1989 case PM_CONSOLE_BEEP
:
1990 DPRINT1("Beep !!\n");
1994 // case PM_CONSOLE_SET_TITLE:
1995 // SetWindowText(GuiData->hWindow, GuiData->Console->Title.Buffer);
1999 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2008 /******************************************************************************
2009 * GUI Terminal Initialization *
2010 ******************************************************************************/
2012 static LRESULT CALLBACK
2013 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2023 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
2027 case PM_CREATE_CONSOLE
:
2029 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2030 PCONSOLE Console
= GuiData
->Console
;
2032 NewWindow
= CreateWindowExW(WS_EX_CLIENTEDGE
,
2033 GUI_CONSOLE_WINDOW_CLASS
,
2034 Console
->Title
.Buffer
,
2035 WS_OVERLAPPEDWINDOW
| WS_HSCROLL
| WS_VSCROLL
,
2044 if (NULL
!= NewWindow
)
2046 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2048 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2050 DPRINT("Set icons via PM_CREATE_CONSOLE\n");
2051 if (GuiData
->hIcon
== NULL
)
2053 DPRINT("Not really /o\\...\n");
2054 GuiData
->hIcon
= ghDefaultIcon
;
2055 GuiData
->hIconSm
= ghDefaultIconSm
;
2057 else if (GuiData
->hIcon
!= ghDefaultIcon
)
2059 DPRINT("Yes \\o/\n");
2060 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2061 SendMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2064 /* Move and resize the window to the user's values */
2065 /* CAN WE DEADLOCK ?? */
2066 GuiConsoleMoveWindow(GuiData
);
2067 GuiData
->WindowSizeLock
= TRUE
;
2068 GuiConsoleResizeWindow(GuiData
);
2069 GuiData
->WindowSizeLock
= FALSE
;
2071 // ShowWindow(NewWindow, (int)wParam);
2072 ShowWindowAsync(NewWindow
, (int)wParam
);
2073 DPRINT("Window showed\n");
2076 return (LRESULT
)NewWindow
;
2079 case PM_DESTROY_CONSOLE
:
2081 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)lParam
;
2084 * Window creation is done using a PostMessage(), so it's possible
2085 * that the window that we want to destroy doesn't exist yet.
2086 * So first empty the message queue.
2089 while (PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE))
2091 TranslateMessage(&Msg);
2092 DispatchMessageW(&Msg);
2094 while (PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
)) ;
2096 if (GuiData
->hWindow
!= NULL
) /* && DestroyWindow(GuiData->hWindow) */
2098 DestroyWindow(GuiData
->hWindow
);
2100 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
2102 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
2103 if (0 == WindowCount
)
2106 DestroyWindow(hWnd
);
2107 DPRINT("CONSRV: Going to quit the Gui Thread!!\n");
2116 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2121 GuiConsoleGuiThread(PVOID Data
)
2124 PHANDLE GraphicsStartupEvent
= (PHANDLE
)Data
;
2127 * This thread dispatches all the console notifications to the notify window.
2128 * It is common for all the console windows.
2131 PrivateCsrssManualGuiCheck(+1);
2133 NotifyWnd
= CreateWindowW(L
"ConSrvCreateNotify",
2135 WS_OVERLAPPEDWINDOW
,
2144 if (NULL
== NotifyWnd
)
2146 PrivateCsrssManualGuiCheck(-1);
2147 SetEvent(*GraphicsStartupEvent
);
2151 SetEvent(*GraphicsStartupEvent
);
2153 while (GetMessageW(&msg
, NULL
, 0, 0))
2155 TranslateMessage(&msg
);
2156 DispatchMessageW(&msg
);
2159 DPRINT("CONSRV: Quit the Gui Thread!!\n");
2160 PrivateCsrssManualGuiCheck(-1);
2169 ATOM ConsoleClassAtom
;
2171 /* Exit if we were already initialized */
2172 // if (ConsInitialized) return TRUE;
2175 * Initialize and register the different window classes, if needed.
2177 if (!ConsInitialized
)
2179 /* Initialize the notification window class */
2180 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2181 wc
.lpszClassName
= L
"ConSrvCreateNotify";
2182 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
2184 wc
.hInstance
= ConSrvDllInstance
;
2188 wc
.hbrBackground
= NULL
;
2189 wc
.lpszMenuName
= NULL
;
2192 if (RegisterClassExW(&wc
) == 0)
2194 DPRINT1("Failed to register GUI notify wndproc\n");
2198 /* Initialize the console window class */
2199 ghDefaultIcon
= LoadImageW(ConSrvDllInstance
,
2200 MAKEINTRESOURCEW(IDI_TERMINAL
),
2202 GetSystemMetrics(SM_CXICON
),
2203 GetSystemMetrics(SM_CYICON
),
2205 ghDefaultIconSm
= LoadImageW(ConSrvDllInstance
,
2206 MAKEINTRESOURCEW(IDI_TERMINAL
),
2208 GetSystemMetrics(SM_CXSMICON
),
2209 GetSystemMetrics(SM_CYSMICON
),
2211 ghDefaultCursor
= LoadCursorW(NULL
, IDC_ARROW
);
2212 wc
.cbSize
= sizeof(WNDCLASSEXW
);
2213 wc
.lpszClassName
= GUI_CONSOLE_WINDOW_CLASS
;
2214 wc
.lpfnWndProc
= GuiConsoleWndProc
;
2215 wc
.style
= CS_DBLCLKS
/* | CS_HREDRAW | CS_VREDRAW */;
2216 wc
.hInstance
= ConSrvDllInstance
;
2217 wc
.hIcon
= ghDefaultIcon
;
2218 wc
.hIconSm
= ghDefaultIconSm
;
2219 wc
.hCursor
= ghDefaultCursor
;
2220 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
); // The color of a terminal when it is switch off.
2221 wc
.lpszMenuName
= NULL
;
2223 wc
.cbWndExtra
= GWLP_CONSOLEWND_ALLOC
;
2225 ConsoleClassAtom
= RegisterClassExW(&wc
);
2226 if (ConsoleClassAtom
== 0)
2228 DPRINT1("Failed to register GUI console wndproc\n");
2233 NtUserConsoleControl(GuiConsoleWndClassAtom
, &ConsoleClassAtom
, sizeof(ATOM
));
2236 ConsInitialized
= TRUE
;
2240 * Set-up the notification window
2242 if (NULL
== NotifyWnd
)
2244 HANDLE ThreadHandle
;
2245 HANDLE GraphicsStartupEvent
;
2247 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2248 if (NULL
== GraphicsStartupEvent
) return FALSE
;
2250 ThreadHandle
= CreateThread(NULL
,
2252 GuiConsoleGuiThread
,
2253 (PVOID
)&GraphicsStartupEvent
,
2256 if (NULL
== ThreadHandle
)
2258 CloseHandle(GraphicsStartupEvent
);
2259 DPRINT1("CONSRV: Failed to create graphics console thread. Expect problems\n");
2262 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
2263 CloseHandle(ThreadHandle
);
2265 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
2266 CloseHandle(GraphicsStartupEvent
);
2268 if (NULL
== NotifyWnd
)
2270 DPRINT1("CONSRV: Failed to create notification window.\n");
2275 // ConsInitialized = TRUE;
2282 /******************************************************************************
2283 * GUI Console Driver *
2284 ******************************************************************************/
2287 GuiDeinitFrontEnd(IN OUT PFRONTEND This
);
2290 GuiInitFrontEnd(IN OUT PFRONTEND This
,
2291 IN PCONSOLE Console
)
2293 PGUI_INIT_INFO GuiInitInfo
;
2294 PCONSOLE_INFO ConsoleInfo
;
2295 PCONSOLE_START_INFO ConsoleStartInfo
;
2297 PGUI_CONSOLE_DATA GuiData
;
2298 GUI_CONSOLE_INFO TermInfo
;
2301 LPWSTR IconPath
= NULL
;
2304 if (This
== NULL
|| Console
== NULL
|| This
->OldData
== NULL
)
2305 return STATUS_INVALID_PARAMETER
;
2307 ASSERT(This
->Console
== Console
);
2309 GuiInitInfo
= This
->OldData
;
2311 if (GuiInitInfo
->ConsoleInfo
== NULL
|| GuiInitInfo
->ConsoleStartInfo
== NULL
)
2312 return STATUS_INVALID_PARAMETER
;
2314 ConsoleInfo
= GuiInitInfo
->ConsoleInfo
;
2315 ConsoleStartInfo
= GuiInitInfo
->ConsoleStartInfo
;
2317 IconPath
= ConsoleStartInfo
->IconPath
;
2318 IconIndex
= ConsoleStartInfo
->IconIndex
;
2321 /* Terminal data allocation */
2322 GuiData
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_CONSOLE_DATA
));
2325 DPRINT1("CONSRV: Failed to create GUI_CONSOLE_DATA\n");
2326 return STATUS_UNSUCCESSFUL
;
2328 /* HACK */ Console
->TermIFace
.Data
= (PVOID
)GuiData
; /* HACK */
2329 GuiData
->Console
= Console
;
2330 GuiData
->ActiveBuffer
= Console
->ActiveBuffer
;
2331 GuiData
->hWindow
= NULL
;
2333 /* The console can be resized */
2334 Console
->FixedSize
= FALSE
;
2336 InitializeCriticalSection(&GuiData
->Lock
);
2340 * Load terminal settings
2343 /* 1. Load the default settings */
2344 GuiConsoleGetDefaultSettings(&TermInfo
, GuiInitInfo
->ProcessId
);
2346 /* 3. Load the remaining console settings via the registry. */
2347 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
2349 /* Load the terminal infos from the registry. */
2350 GuiConsoleReadUserSettings(&TermInfo
,
2351 ConsoleInfo
->ConsoleTitle
,
2352 GuiInitInfo
->ProcessId
);
2355 * Now, update them with the properties the user might gave to us
2356 * via the STARTUPINFO structure before calling CreateProcess
2357 * (and which was transmitted via the ConsoleStartInfo structure).
2358 * We therefore overwrite the values read in the registry.
2360 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USESHOWWINDOW
)
2362 TermInfo
.ShowWindow
= ConsoleStartInfo
->wShowWindow
;
2364 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_USEPOSITION
)
2366 TermInfo
.AutoPosition
= FALSE
;
2367 TermInfo
.WindowOrigin
.x
= ConsoleStartInfo
->dwWindowOrigin
.X
;
2368 TermInfo
.WindowOrigin
.y
= ConsoleStartInfo
->dwWindowOrigin
.Y
;
2370 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_RUNFULLSCREEN
)
2372 TermInfo
.FullScreen
= TRUE
;
2381 Length
= min(wcslen(TermInfo
.FaceName
) + 1, LF_FACESIZE
); // wcsnlen
2382 wcsncpy(GuiData
->GuiInfo
.FaceName
, TermInfo
.FaceName
, LF_FACESIZE
);
2383 GuiData
->GuiInfo
.FaceName
[Length
] = L
'\0';
2384 GuiData
->GuiInfo
.FontFamily
= TermInfo
.FontFamily
;
2385 GuiData
->GuiInfo
.FontSize
= TermInfo
.FontSize
;
2386 GuiData
->GuiInfo
.FontWeight
= TermInfo
.FontWeight
;
2387 GuiData
->GuiInfo
.UseRasterFonts
= TermInfo
.UseRasterFonts
;
2388 GuiData
->GuiInfo
.FullScreen
= TermInfo
.FullScreen
;
2389 GuiData
->GuiInfo
.ShowWindow
= TermInfo
.ShowWindow
;
2390 GuiData
->GuiInfo
.AutoPosition
= TermInfo
.AutoPosition
;
2391 GuiData
->GuiInfo
.WindowOrigin
= TermInfo
.WindowOrigin
;
2393 /* Initialize the icon handles to their default values */
2394 GuiData
->hIcon
= ghDefaultIcon
;
2395 GuiData
->hIconSm
= ghDefaultIconSm
;
2397 /* Get the associated icon, if any */
2398 if (IconPath
== NULL
|| IconPath
[0] == L
'\0')
2400 IconPath
= ConsoleStartInfo
->AppPath
;
2403 DPRINT("IconPath = %S ; IconIndex = %lu\n", (IconPath
? IconPath
: L
"n/a"), IconIndex
);
2404 if (IconPath
&& IconPath
[0] != L
'\0')
2406 HICON hIcon
= NULL
, hIconSm
= NULL
;
2407 PrivateExtractIconExW(IconPath
,
2412 DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon
, hIconSm
);
2415 DPRINT("Effectively set the icons\n");
2416 GuiData
->hIcon
= hIcon
;
2417 GuiData
->hIconSm
= hIconSm
;
2421 /* Original system palette */
2422 GuiData
->hSysPalette
= NULL
;
2424 /* Mouse is shown by default with its default cursor shape */
2425 GuiData
->hCursor
= ghDefaultCursor
;
2426 GuiData
->MouseCursorRefCount
= 0;
2428 /* A priori don't ignore mouse signals */
2429 GuiData
->IgnoreNextMouseSignal
= FALSE
;
2431 /* Close button and the corresponding system menu item are enabled by default */
2432 GuiData
->IsCloseButtonEnabled
= TRUE
;
2434 /* There is no user-reserved menu id range by default */
2435 GuiData
->cmdIdLow
= GuiData
->cmdIdHigh
= 0;
2438 * We need to wait until the GUI has been fully initialized
2439 * to retrieve custom settings i.e. WindowSize etc...
2440 * Ideally we could use SendNotifyMessage for this but its not
2443 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2445 DPRINT("GUI - Checkpoint\n");
2447 /* Create the terminal window */
2448 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, GuiData
->GuiInfo
.ShowWindow
, (LPARAM
)GuiData
);
2450 /* Wait until initialization has finished */
2451 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
2452 DPRINT("OK we created the console window\n");
2453 CloseHandle(GuiData
->hGuiInitEvent
);
2454 GuiData
->hGuiInitEvent
= NULL
;
2456 /* Check whether we really succeeded in initializing the terminal window */
2457 if (GuiData
->hWindow
== NULL
)
2459 DPRINT("GuiInitConsole - We failed at creating a new terminal window\n");
2460 GuiDeinitFrontEnd(This
);
2461 return STATUS_UNSUCCESSFUL
;
2464 /* Finally, finish to initialize the frontend structure */
2465 This
->Data
= GuiData
;
2466 if (This
->OldData
) ConsoleFreeHeap(This
->OldData
);
2467 This
->OldData
= NULL
;
2469 return STATUS_SUCCESS
;
2473 GuiDeinitFrontEnd(IN OUT PFRONTEND This
)
2475 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2477 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
)GuiData
);
2479 DPRINT("Destroying icons !! - GuiData->hIcon = 0x%p ; ghDefaultIcon = 0x%p ; GuiData->hIconSm = 0x%p ; ghDefaultIconSm = 0x%p\n",
2480 GuiData
->hIcon
, ghDefaultIcon
, GuiData
->hIconSm
, ghDefaultIconSm
);
2481 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2483 DPRINT("Destroy hIcon\n");
2484 DestroyIcon(GuiData
->hIcon
);
2486 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2488 DPRINT("Destroy hIconSm\n");
2489 DestroyIcon(GuiData
->hIconSm
);
2493 DeleteCriticalSection(&GuiData
->Lock
);
2494 ConsoleFreeHeap(GuiData
);
2496 DPRINT("Quit GuiDeinitFrontEnd\n");
2500 GuiDrawRegion(IN OUT PFRONTEND This
,
2503 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2506 SmallRectToRect(GuiData
, &RegionRect
, Region
);
2507 /* Do not erase the background: it speeds up redrawing and reduce flickering */
2508 InvalidateRect(GuiData
->hWindow
, &RegionRect
, FALSE
);
2512 GuiWriteStream(IN OUT PFRONTEND This
,
2520 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2521 PCONSOLE_SCREEN_BUFFER Buff
;
2522 SHORT CursorEndX
, CursorEndY
;
2525 if (NULL
== GuiData
|| NULL
== GuiData
->hWindow
) return;
2527 Buff
= GuiData
->ActiveBuffer
; // ConDrvGetActiveScreenBuffer(GuiData->Console);
2528 if (GetType(Buff
) != TEXTMODE_BUFFER
) return;
2530 if (0 != ScrolledLines
)
2532 ScrollRect
.left
= 0;
2534 ScrollRect
.right
= Buff
->ViewSize
.X
* GuiData
->CharWidth
;
2535 ScrollRect
.bottom
= Region
->Top
* GuiData
->CharHeight
;
2537 ScrollWindowEx(GuiData
->hWindow
,
2539 -(int)(ScrolledLines
* GuiData
->CharHeight
),
2547 GuiDrawRegion(This
, Region
);
2549 if (CursorStartX
< Region
->Left
|| Region
->Right
< CursorStartX
2550 || CursorStartY
< Region
->Top
|| Region
->Bottom
< CursorStartY
)
2552 GuiInvalidateCell(This
, CursorStartX
, CursorStartY
);
2555 CursorEndX
= Buff
->CursorPosition
.X
;
2556 CursorEndY
= Buff
->CursorPosition
.Y
;
2557 if ((CursorEndX
< Region
->Left
|| Region
->Right
< CursorEndX
2558 || CursorEndY
< Region
->Top
|| Region
->Bottom
< CursorEndY
)
2559 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
2561 GuiInvalidateCell(This
, CursorEndX
, CursorEndY
);
2564 // Set up the update timer (very short interval) - this is a "hack" for getting the OS to
2565 // repaint the window without having it just freeze up and stay on the screen permanently.
2566 Buff
->CursorBlinkOn
= TRUE
;
2567 SetTimer(GuiData
->hWindow
, CONGUI_UPDATE_TIMER
, CONGUI_UPDATE_TIME
, NULL
);
2571 GuiSetCursorInfo(IN OUT PFRONTEND This
,
2572 PCONSOLE_SCREEN_BUFFER Buff
)
2574 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2576 if (/*ConDrvGetActiveScreenBuffer(GuiData->Console)*/GuiData
->ActiveBuffer
== Buff
)
2578 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2585 GuiSetScreenInfo(IN OUT PFRONTEND This
,
2586 PCONSOLE_SCREEN_BUFFER Buff
,
2590 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2592 if (/*ConDrvGetActiveScreenBuffer(GuiData->Console)*/GuiData
->ActiveBuffer
== Buff
)
2594 /* Redraw char at old position (remove cursor) */
2595 GuiInvalidateCell(This
, OldCursorX
, OldCursorY
);
2596 /* Redraw char at new position (show cursor) */
2597 GuiInvalidateCell(This
, Buff
->CursorPosition
.X
, Buff
->CursorPosition
.Y
);
2604 GuiResizeTerminal(IN OUT PFRONTEND This
)
2606 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2608 /* Resize the window to the user's values */
2609 // GuiData->WindowSizeLock = TRUE;
2610 // GuiConsoleResizeWindow(GuiData);
2611 // GuiData->WindowSizeLock = FALSE;
2612 // NOTE: This code ^^ causes deadlocks...
2614 PostMessageW(GuiData
->hWindow
, PM_RESIZE_TERMINAL
, 0, 0);
2618 GuiSetActiveScreenBuffer(IN OUT PFRONTEND This
)
2620 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2621 PCONSOLE_SCREEN_BUFFER ActiveBuffer
; // = GuiData->ActiveBuffer; // ConDrvGetActiveScreenBuffer(GuiData->Console);
2625 EnterCriticalSection(&GuiData
->Lock
);
2626 GuiData
->WindowSizeLock
= TRUE
;
2628 InterlockedExchangePointer(&GuiData
->ActiveBuffer
,
2629 GuiData
->Console
->ActiveBuffer
);
2631 GuiData
->WindowSizeLock
= FALSE
;
2632 LeaveCriticalSection(&GuiData
->Lock
);
2634 ActiveBuffer
= GuiData
->ActiveBuffer
;
2636 /* Change the current palette */
2637 if (ActiveBuffer
->PaletteHandle
== NULL
)
2639 hPalette
= GuiData
->hSysPalette
;
2643 hPalette
= ActiveBuffer
->PaletteHandle
;
2646 DPRINT1("GuiSetActiveScreenBuffer using palette 0x%p\n", hPalette
);
2648 /* Get the Device Context of the console window */
2649 hDC
= GetDC(GuiData
->hWindow
);
2651 /* Set the new palette */
2652 SelectPalette(hDC
, hPalette
, FALSE
);
2654 /* Specify the use of the system palette */
2655 SetSystemPaletteUse(hDC
, ActiveBuffer
->PaletteUsage
);
2657 /* Realize the (logical) palette */
2658 RealizePalette(hDC
);
2660 /* Release the Device Context */
2661 ReleaseDC(GuiData
->hWindow
, hDC
);
2663 GuiResizeTerminal(This
);
2664 // ConioDrawConsole(Console);
2668 GuiReleaseScreenBuffer(IN OUT PFRONTEND This
,
2669 IN PCONSOLE_SCREEN_BUFFER ScreenBuffer
)
2671 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2675 * If we were notified to release a screen buffer that is not actually
2676 * ours, then just ignore the notification...
2678 if (ScreenBuffer
!= GuiData
->ActiveBuffer
) return;
2681 * ... else, we must release our active buffer. Two cases are present:
2682 * - If ScreenBuffer (== GuiData->ActiveBuffer) IS NOT the console
2683 * active screen buffer, then we can safely switch to it.
2684 * - If ScreenBuffer IS the console active screen buffer, we must release
2688 /* Get the Device Context of the console window */
2689 hDC
= GetDC(GuiData
->hWindow
);
2691 /* Release the old active palette and set the default one */
2692 if (GetCurrentObject(hDC
, OBJ_PAL
) == ScreenBuffer
->PaletteHandle
)
2694 /* Set the new palette */
2695 SelectPalette(hDC
, GuiData
->hSysPalette
, FALSE
);
2698 /* Release the Device Context */
2699 ReleaseDC(GuiData
->hWindow
, hDC
);
2701 /* Set the adequate active screen buffer */
2702 if (ScreenBuffer
!= GuiData
->Console
->ActiveBuffer
)
2704 GuiSetActiveScreenBuffer(This
);
2708 EnterCriticalSection(&GuiData
->Lock
);
2709 GuiData
->WindowSizeLock
= TRUE
;
2711 InterlockedExchangePointer(&GuiData
->ActiveBuffer
, NULL
);
2713 GuiData
->WindowSizeLock
= FALSE
;
2714 LeaveCriticalSection(&GuiData
->Lock
);
2719 GuiProcessKeyCallback(IN OUT PFRONTEND This
,
2723 UINT VirtualKeyCode
,
2726 if ((ShiftState
& (RIGHT_ALT_PRESSED
| LEFT_ALT_PRESSED
) || KeyStateMenu
& 0x80) &&
2727 (VirtualKeyCode
== VK_ESCAPE
|| VirtualKeyCode
== VK_TAB
|| VirtualKeyCode
== VK_SPACE
))
2729 DefWindowProcW(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2737 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2741 GuiRefreshInternalInfo(IN OUT PFRONTEND This
)
2743 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2745 /* Update the console leader information held by the window */
2746 SetConsoleWndConsoleLeaderCID(GuiData
);
2750 * We reset the cursor here so that, when a console app quits, we reset
2751 * the cursor to the default one. It's quite a hack since it doesn't proceed
2752 * per - console process... This must be fixed.
2754 * See GuiInitConsole(...) for more information.
2757 /* Mouse is shown by default with its default cursor shape */
2758 GuiData
->MouseCursorRefCount
= 0; // Reinitialize the reference counter
2759 GuiSetMouseCursor(This
, NULL
);
2763 GuiChangeTitle(IN OUT PFRONTEND This
)
2765 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2766 // PostMessageW(GuiData->hWindow, PM_CONSOLE_SET_TITLE, 0, 0);
2767 SetWindowText(GuiData
->hWindow
, GuiData
->Console
->Title
.Buffer
);
2771 GuiChangeIcon(IN OUT PFRONTEND This
,
2774 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2775 HICON hIcon
, hIconSm
;
2777 if (hWindowIcon
== NULL
)
2779 hIcon
= ghDefaultIcon
;
2780 hIconSm
= ghDefaultIconSm
;
2784 hIcon
= CopyIcon(hWindowIcon
);
2785 hIconSm
= CopyIcon(hWindowIcon
);
2793 if (hIcon
!= GuiData
->hIcon
)
2795 if (GuiData
->hIcon
!= NULL
&& GuiData
->hIcon
!= ghDefaultIcon
)
2797 DestroyIcon(GuiData
->hIcon
);
2799 if (GuiData
->hIconSm
!= NULL
&& GuiData
->hIconSm
!= ghDefaultIconSm
)
2801 DestroyIcon(GuiData
->hIconSm
);
2804 GuiData
->hIcon
= hIcon
;
2805 GuiData
->hIconSm
= hIconSm
;
2807 DPRINT("Set icons in GuiChangeIcon\n");
2808 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)GuiData
->hIcon
);
2809 PostMessageW(GuiData
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)GuiData
->hIconSm
);
2816 GuiGetConsoleWindowHandle(IN OUT PFRONTEND This
)
2818 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2819 return GuiData
->hWindow
;
2823 GuiGetLargestConsoleWindowSize(IN OUT PFRONTEND This
,
2826 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2827 PCONSOLE_SCREEN_BUFFER ActiveBuffer
;
2830 UINT WidthUnit
, HeightUnit
;
2834 if (!SystemParametersInfoW(SPI_GETWORKAREA
, 0, &WorkArea
, 0))
2836 DPRINT1("SystemParametersInfoW failed - What to do ??\n");
2840 // ActiveBuffer = ConDrvGetActiveScreenBuffer(GuiData->Console);
2841 ActiveBuffer
= GuiData
->ActiveBuffer
;
2844 GetScreenBufferSizeUnits(ActiveBuffer
, GuiData
, &WidthUnit
, &HeightUnit
);
2848 /* Default: text mode */
2849 WidthUnit
= GuiData
->CharWidth
;
2850 HeightUnit
= GuiData
->CharHeight
;
2853 width
= WorkArea
.right
;
2854 height
= WorkArea
.bottom
;
2856 width
-= (2 * (GetSystemMetrics(SM_CXFRAME
) + GetSystemMetrics(SM_CXEDGE
)));
2857 height
-= (2 * (GetSystemMetrics(SM_CYFRAME
) + GetSystemMetrics(SM_CYEDGE
)) + GetSystemMetrics(SM_CYCAPTION
));
2859 if (width
< 0) width
= 0;
2860 if (height
< 0) height
= 0;
2862 pSize
->X
= (SHORT
)(width
/ (int)WidthUnit
) /* HACK */ + 2;
2863 pSize
->Y
= (SHORT
)(height
/ (int)HeightUnit
) /* HACK */ + 1;
2867 GuiSetPalette(IN OUT PFRONTEND This
,
2868 HPALETTE PaletteHandle
,
2871 BOOL Success
= TRUE
;
2872 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2873 // PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer; // ConDrvGetActiveScreenBuffer(GuiData->Console);
2875 HPALETTE OldPalette
;
2877 DPRINT1("GuiSetPalette checkpt 0\n");
2879 // if (GetType(ActiveBuffer) != GRAPHICS_BUFFER) return FALSE;
2880 if (PaletteHandle
== NULL
) return FALSE
;
2882 DPRINT1("GuiSetPalette checkpt 1\n");
2884 /* Get the Device Context of the console window */
2885 hDC
= GetDC(GuiData
->hWindow
);
2887 DPRINT1("GuiSetPalette calling SelectPalette(0x%p, 0x%p, FALSE)\n", hDC
, PaletteHandle
);
2889 /* Set the new palette */
2890 OldPalette
= SelectPalette(hDC
, PaletteHandle
, FALSE
);
2891 DPRINT1("OldPalette = 0x%p\n", OldPalette
);
2892 if (OldPalette
== NULL
)
2894 DPRINT1("SelectPalette failed\n");
2899 DPRINT1("GuiSetPalette checkpt 2\n");
2901 /* Specify the use of the system palette */
2902 SetSystemPaletteUse(hDC
, PaletteUsage
);
2904 /* Realize the (logical) palette */
2905 RealizePalette(hDC
);
2907 DPRINT1("GuiData->hSysPalette before == 0x%p\n", GuiData
->hSysPalette
);
2909 /* Save the original system palette handle */
2910 if (GuiData
->hSysPalette
== NULL
) GuiData
->hSysPalette
= OldPalette
;
2912 DPRINT1("GuiData->hSysPalette after == 0x%p\n", GuiData
->hSysPalette
);
2915 DPRINT1("GuiSetPalette Quit\n");
2916 /* Release the Device Context and return */
2917 ReleaseDC(GuiData
->hWindow
, hDC
);
2922 GuiGetDisplayMode(IN OUT PFRONTEND This
)
2924 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2925 ULONG DisplayMode
= 0;
2927 if (GuiData
->GuiInfo
.FullScreen
)
2928 DisplayMode
|= CONSOLE_FULLSCREEN_HARDWARE
; // CONSOLE_FULLSCREEN
2930 DisplayMode
|= CONSOLE_WINDOWED
;
2936 GuiSetDisplayMode(IN OUT PFRONTEND This
,
2939 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2941 if (NewMode
& ~(CONSOLE_FULLSCREEN_MODE
| CONSOLE_WINDOWED_MODE
))
2944 GuiData
->GuiInfo
.FullScreen
= (NewMode
& CONSOLE_FULLSCREEN_MODE
);
2945 // TODO: Change the display mode
2950 GuiShowMouseCursor(IN OUT PFRONTEND This
,
2953 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2955 /* Set the reference count */
2956 if (Show
) ++GuiData
->MouseCursorRefCount
;
2957 else --GuiData
->MouseCursorRefCount
;
2959 /* Effectively show (or hide) the cursor (use special values for (w|l)Param) */
2960 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2962 return GuiData
->MouseCursorRefCount
;
2966 GuiSetMouseCursor(IN OUT PFRONTEND This
,
2969 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2972 * Set the cursor's handle. If the given handle is NULL,
2973 * then restore the default cursor.
2975 GuiData
->hCursor
= (hCursor
? hCursor
: ghDefaultCursor
);
2977 /* Effectively modify the shape of the cursor (use special values for (w|l)Param) */
2978 PostMessageW(GuiData
->hWindow
, WM_SETCURSOR
, -1, -1);
2984 GuiMenuControl(IN OUT PFRONTEND This
,
2988 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
2990 GuiData
->cmdIdLow
= cmdIdLow
;
2991 GuiData
->cmdIdHigh
= cmdIdHigh
;
2993 return GetSystemMenu(GuiData
->hWindow
, FALSE
);
2997 GuiSetMenuClose(IN OUT PFRONTEND This
,
3001 * NOTE: See http://www.mail-archive.com/harbour@harbour-project.org/msg27509.html
3002 * or http://harbour-devel.1590103.n2.nabble.com/Question-about-hb-gt-win-CtrlHandler-usage-td4670862i20.html
3003 * for more information.
3006 PGUI_CONSOLE_DATA GuiData
= This
->Data
;
3007 HMENU hSysMenu
= GetSystemMenu(GuiData
->hWindow
, FALSE
);
3009 if (hSysMenu
== NULL
) return FALSE
;
3011 GuiData
->IsCloseButtonEnabled
= Enable
;
3012 EnableMenuItem(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
| (Enable
? MF_ENABLED
: MF_GRAYED
));
3017 static FRONTEND_VTBL GuiVtbl
=
3026 GuiSetActiveScreenBuffer
,
3027 GuiReleaseScreenBuffer
,
3028 GuiProcessKeyCallback
,
3029 GuiRefreshInternalInfo
,
3032 GuiGetConsoleWindowHandle
,
3033 GuiGetLargestConsoleWindowSize
,
3045 LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo
,
3046 IN OUT PCONSOLE_INFO ConsoleInfo
)
3048 #define PATH_SEPARATOR L'\\'
3050 BOOL RetVal
= FALSE
;
3051 HRESULT hRes
= S_OK
;
3052 LPWSTR LinkName
= NULL
;
3055 if ((ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
) == 0)
3058 ConsoleStartInfo
->IconPath
[0] = L
'\0';
3059 ConsoleStartInfo
->IconIndex
= 0;
3061 /* 1- Find the last path separator if any */
3062 LinkName
= wcsrchr(ConsoleStartInfo
->ConsoleTitle
, PATH_SEPARATOR
);
3063 if (LinkName
== NULL
)
3065 LinkName
= ConsoleStartInfo
->ConsoleTitle
;
3069 /* Skip the path separator */
3073 /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
3074 Length
= wcslen(LinkName
);
3075 if ( (Length
<= 4) || (wcsicmp(LinkName
+ (Length
- 4), L
".lnk") != 0) )
3078 /* 3- It may be a link. Try to retrieve some properties */
3079 hRes
= CoInitialize(NULL
);
3080 if (SUCCEEDED(hRes
))
3082 /* Get a pointer to the IShellLink interface */
3083 IShellLinkW
* pshl
= NULL
;
3084 hRes
= CoCreateInstance(&CLSID_ShellLink
,
3086 CLSCTX_INPROC_SERVER
,
3089 if (SUCCEEDED(hRes
))
3091 /* Get a pointer to the IPersistFile interface */
3092 IPersistFile
* ppf
= NULL
;
3093 hRes
= IPersistFile_QueryInterface(pshl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
3094 if (SUCCEEDED(hRes
))
3096 /* Load the shortcut */
3097 hRes
= IPersistFile_Load(ppf
, ConsoleStartInfo
->ConsoleTitle
, STGM_READ
);
3098 if (SUCCEEDED(hRes
))
3101 * Finally we can get the properties !
3102 * Update the old ones if needed.
3107 /* Reset the name of the console with the name of the shortcut */
3108 Length
= min(/*Length*/ Length
- 4, // 4 == len(".lnk")
3109 sizeof(ConsoleInfo
->ConsoleTitle
) / sizeof(ConsoleInfo
->ConsoleTitle
[0]) - 1);
3110 wcsncpy(ConsoleInfo
->ConsoleTitle
, LinkName
, Length
);
3111 ConsoleInfo
->ConsoleTitle
[Length
] = L
'\0';
3113 /* Get the window showing command */
3114 hRes
= IShellLinkW_GetShowCmd(pshl
, &ShowCmd
);
3115 if (SUCCEEDED(hRes
)) ConsoleStartInfo
->wShowWindow
= (WORD
)ShowCmd
;
3117 /* Get the hotkey */
3118 // hRes = pshl->GetHotkey(&ShowCmd);
3119 // if (SUCCEEDED(hRes)) ConsoleStartInfo->HotKey = HotKey;
3121 /* Get the icon location, if any */
3123 hRes
= IShellLinkW_GetIconLocation(pshl
,
3124 ConsoleStartInfo
->IconPath
,
3125 sizeof(ConsoleStartInfo
->IconPath
)/sizeof(ConsoleStartInfo
->IconPath
[0]) - 1, // == MAX_PATH
3126 &ConsoleStartInfo
->IconIndex
);
3127 if (!SUCCEEDED(hRes
))
3129 ConsoleStartInfo
->IconPath
[0] = L
'\0';
3130 ConsoleStartInfo
->IconIndex
= 0;
3133 // FIXME: Since we still don't load console properties from the shortcut,
3134 // return false. When this will be done, we will return true instead.
3137 IPersistFile_Release(ppf
);
3139 IShellLinkW_Release(pshl
);
3148 GuiLoadFrontEnd(IN OUT PFRONTEND FrontEnd
,
3149 IN OUT PCONSOLE_INFO ConsoleInfo
,
3150 IN OUT PVOID ExtraConsoleInfo
,
3153 PCONSOLE_START_INFO ConsoleStartInfo
= ExtraConsoleInfo
;
3154 PGUI_INIT_INFO GuiInitInfo
;
3156 if (FrontEnd
== NULL
|| ConsoleInfo
== NULL
|| ConsoleStartInfo
== NULL
)
3157 return STATUS_INVALID_PARAMETER
;
3159 /* Initialize GUI terminal emulator common functionalities */
3160 if (!GuiInit()) return STATUS_UNSUCCESSFUL
;
3163 * Load per-application terminal settings.
3165 * Check whether the process creating the console was launched via
3166 * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
3167 * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
3169 if (ConsoleStartInfo
->dwStartupFlags
& STARTF_TITLEISLINKNAME
)
3171 if (!LoadShellLinkConsoleInfo(ConsoleStartInfo
, ConsoleInfo
))
3173 ConsoleStartInfo
->dwStartupFlags
&= ~STARTF_TITLEISLINKNAME
;
3178 * Initialize a private initialization info structure for later use.
3179 * It must be freed by a call to GuiUnloadFrontEnd or GuiInitFrontEnd.
3181 GuiInitInfo
= ConsoleAllocHeap(HEAP_ZERO_MEMORY
, sizeof(GUI_INIT_INFO
));
3182 if (GuiInitInfo
== NULL
) return STATUS_NO_MEMORY
;
3184 // HACK: We suppose that the pointers will be valid in GuiInitFrontEnd...
3185 GuiInitInfo
->ConsoleInfo
= ConsoleInfo
;
3186 GuiInitInfo
->ConsoleStartInfo
= ConsoleStartInfo
;
3187 GuiInitInfo
->ProcessId
= ProcessId
;
3189 /* Finally, initialize the frontend structure */
3190 FrontEnd
->Vtbl
= &GuiVtbl
;
3191 FrontEnd
->Data
= NULL
;
3192 FrontEnd
->OldData
= GuiInitInfo
;
3194 return STATUS_SUCCESS
;
3198 GuiUnloadFrontEnd(IN OUT PFRONTEND FrontEnd
)
3200 if (FrontEnd
== NULL
) return STATUS_INVALID_PARAMETER
;
3202 if (FrontEnd
->Data
) GuiDeinitFrontEnd(FrontEnd
);
3203 if (FrontEnd
->OldData
) ConsoleFreeHeap(FrontEnd
->OldData
);
3205 return STATUS_SUCCESS
;