ReactOS 0.4.16-dev-297-gc569aee
conwnd.c File Reference
#include <consrv.h>
#include <intrin.h>
#include <windowsx.h>
#include <shellapi.h>
#include <debug.h>
#include "concfg/font.h"
#include "guiterm.h"
#include "resource.h"
Include dependency graph for conwnd.c:

Go to the source code of this file.

Classes

struct  _GUICONSOLE_MENUITEM
 

Macros

#define NDEBUG
 
#define CONGUI_MIN_WIDTH   10
 
#define CONGUI_MIN_HEIGHT   10
 
#define CONGUI_UPDATE_TIME   0
 
#define CONGUI_UPDATE_TIMER   1
 
#define CURSOR_BLINK_TIME   500
 
#define GWLP_CONWND_ALLOC   (2 * sizeof(LONG_PTR))
 
#define GWLP_CONSOLE_LEADER_PID   0
 
#define GWLP_CONSOLE_LEADER_TID   4
 
#define IS_WORD_SEP(c)    ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
 

Typedefs

typedef struct _GUICONSOLE_MENUITEM GUICONSOLE_MENUITEM
 
typedef struct _GUICONSOLE_MENUITEMPGUICONSOLE_MENUITEM
 

Functions

VOID SetConWndConsoleLeaderCID (IN PGUI_CONSOLE_DATA GuiData)
 
static LRESULT CALLBACK ConWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
BOOLEAN RegisterConWndClass (IN HINSTANCE hInstance)
 
BOOLEAN UnRegisterConWndClass (HINSTANCE hInstance)
 
static VOID AppendMenuItems (HMENU hMenu, const GUICONSOLE_MENUITEM *Items)
 
VOID CreateSysMenu (HWND hWnd)
 
static VOID SendMenuEvent (PCONSRV_CONSOLE Console, UINT CmdId)
 
static VOID Copy (PGUI_CONSOLE_DATA GuiData)
 
static VOID Paste (PGUI_CONSOLE_DATA GuiData)
 
static VOID UpdateSelection (PGUI_CONSOLE_DATA GuiData, PCOORD SelectionAnchor OPTIONAL, PCOORD coord)
 
static VOID Mark (PGUI_CONSOLE_DATA GuiData)
 
static VOID SelectAll (PGUI_CONSOLE_DATA GuiData)
 
static LRESULT OnCommand (PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
 
static PGUI_CONSOLE_DATA GuiGetGuiData (HWND hWnd)
 
static VOID ResizeConWnd (PGUI_CONSOLE_DATA GuiData, DWORD WidthUnit, DWORD HeightUnit)
 
VOID DeleteFonts (PGUI_CONSOLE_DATA GuiData)
 
static HFONT CreateDerivedFont (HFONT OrgFont, ULONG FontWeight, BOOLEAN bUnderline, BOOLEAN bStrikeOut)
 
BOOL InitFonts (_Inout_ PGUI_CONSOLE_DATA GuiData, _In_reads_or_z_(LF_FACESIZE) PCWSTR FaceName, _In_ ULONG FontWeight, _In_ ULONG FontFamily, _In_ COORD FontSize, _In_opt_ UINT CodePage, _In_ BOOL UseDefaultFallback)
 
static BOOL OnNcCreate (HWND hWnd, LPCREATESTRUCTW Create)
 
static VOID OnActivate (PGUI_CONSOLE_DATA GuiData, WPARAM wParam)
 
static VOID OnFocus (PGUI_CONSOLE_DATA GuiData, BOOL SetFocus)
 
VOID GetSelectionBeginEnd (PCOORD Begin, PCOORD End, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
 
static HRGN CreateSelectionRgn (PGUI_CONSOLE_DATA GuiData, BOOL LineSelection, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
 
static VOID PaintSelectionRect (PGUI_CONSOLE_DATA GuiData, PPAINTSTRUCT pps)
 
static VOID OnPaint (PGUI_CONSOLE_DATA GuiData)
 
static VOID OnPaletteChanged (PGUI_CONSOLE_DATA GuiData)
 
static BOOL IsSystemKey (WORD VirtualKeyCode)
 
static VOID OnKey (PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
 
VOID InvalidateCell (PGUI_CONSOLE_DATA GuiData, SHORT x, SHORT y)
 
static VOID OnTimer (PGUI_CONSOLE_DATA GuiData)
 
static BOOL OnClose (PGUI_CONSOLE_DATA GuiData)
 
static LRESULT OnNcDestroy (HWND hWnd)
 
static VOID OnScroll (PGUI_CONSOLE_DATA GuiData, INT nBar, WORD sbCode)
 
static COORD PointToCoord (PGUI_CONSOLE_DATA GuiData, LPARAM lParam)
 
static LRESULT OnMouse (PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
 
static VOID OnGetMinMaxInfo (PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
 
static VOID OnSize (PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
 
static VOID OnMove (PGUI_CONSOLE_DATA GuiData)
 
static VOID OnDropFiles (PCONSRV_CONSOLE Console, HDROP hDrop)
 
HBITMAP CreateFrameBufferBitmap (HDC hDC, int width, int height)
 

Variables

HICON ghDefaultIcon = NULL
 
HICON ghDefaultIconSm = NULL
 
HCURSOR ghDefaultCursor = NULL
 
static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems []
 
static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems []
 
const COLORREF s_Colors [16]
 

Macro Definition Documentation

◆ CONGUI_MIN_HEIGHT

#define CONGUI_MIN_HEIGHT   10

Definition at line 34 of file conwnd.c.

◆ CONGUI_MIN_WIDTH

#define CONGUI_MIN_WIDTH   10

Definition at line 33 of file conwnd.c.

◆ CONGUI_UPDATE_TIME

#define CONGUI_UPDATE_TIME   0

Definition at line 35 of file conwnd.c.

◆ CONGUI_UPDATE_TIMER

#define CONGUI_UPDATE_TIMER   1

Definition at line 36 of file conwnd.c.

◆ CURSOR_BLINK_TIME

#define CURSOR_BLINK_TIME   500

Definition at line 38 of file conwnd.c.

◆ GWLP_CONSOLE_LEADER_PID

#define GWLP_CONSOLE_LEADER_PID   0

Definition at line 44 of file conwnd.c.

◆ GWLP_CONSOLE_LEADER_TID

#define GWLP_CONSOLE_LEADER_TID   4

Definition at line 45 of file conwnd.c.

◆ GWLP_CONWND_ALLOC

#define GWLP_CONWND_ALLOC   (2 * sizeof(LONG_PTR))

Definition at line 43 of file conwnd.c.

◆ IS_WORD_SEP

#define IS_WORD_SEP (   c)     ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')

◆ NDEBUG

#define NDEBUG

Definition at line 20 of file conwnd.c.

Typedef Documentation

◆ GUICONSOLE_MENUITEM

◆ PGUICONSOLE_MENUITEM

Function Documentation

◆ AppendMenuItems()

static VOID AppendMenuItems ( HMENU  hMenu,
const GUICONSOLE_MENUITEM Items 
)
static

Definition at line 188 of file conwnd.c.

190{
191 UINT i = 0;
192 WCHAR szMenuString[255];
193 HMENU hSubMenu;
194
195 do
196 {
197 if (Items[i].uID != (UINT)-1)
198 {
200 Items[i].uID,
201 szMenuString,
202 ARRAYSIZE(szMenuString)) > 0)
203 {
204 if (Items[i].SubMenu != NULL)
205 {
206 hSubMenu = CreatePopupMenu();
207 if (hSubMenu != NULL)
208 {
209 AppendMenuItems(hSubMenu, Items[i].SubMenu);
210
211 if (!AppendMenuW(hMenu,
213 (UINT_PTR)hSubMenu,
214 szMenuString))
215 {
216 DestroyMenu(hSubMenu);
217 }
218 }
219 }
220 else
221 {
222 AppendMenuW(hMenu,
223 MF_STRING,
224 Items[i].wCmdID,
225 szMenuString);
226 }
227 }
228 }
229 else
230 {
231 AppendMenuW(hMenu,
233 0,
234 NULL);
235 }
236 i++;
237 } while (!(Items[i].uID == 0 && Items[i].SubMenu == NULL && Items[i].wCmdID == 0));
238}
HINSTANCE ConSrvDllInstance
Definition: init.c:21
static VOID AppendMenuItems(HMENU hMenu, const GUICONSOLE_MENUITEM *Items)
Definition: conwnd.c:188
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MF_STRING
Definition: winuser.h:138
#define MF_POPUP
Definition: winuser.h:136
#define MF_SEPARATOR
Definition: winuser.h:137
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AppendMenuItems(), ConWndProc(), and CreateSysMenu().

◆ ConWndProc()

static LRESULT CALLBACK ConWndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 2278 of file conwnd.c.

2279{
2280 LRESULT Result = 0;
2281 PGUI_CONSOLE_DATA GuiData = NULL;
2283
2284 /*
2285 * - If it's the first time we create a window for the terminal,
2286 * just initialize it and return.
2287 *
2288 * - If we are destroying the window, just do it and return.
2289 */
2290 if (msg == WM_NCCREATE)
2291 {
2293 }
2294 else if (msg == WM_NCDESTROY)
2295 {
2296 return OnNcDestroy(hWnd);
2297 }
2298
2299 /*
2300 * Now the terminal window is initialized.
2301 * Get the terminal data via the window's data.
2302 * If there is no data, just go away.
2303 */
2304 GuiData = GuiGetGuiData(hWnd);
2305 if (GuiData == NULL) return DefWindowProcW(hWnd, msg, wParam, lParam);
2306
2307 // TEMPORARY HACK until all of the functions can deal with a NULL GuiData->ActiveBuffer ...
2308 if (GuiData->ActiveBuffer == NULL) return DefWindowProcW(hWnd, msg, wParam, lParam);
2309
2310 /*
2311 * Just retrieve a pointer to the console in case somebody needs it.
2312 * It is not NULL because it was checked in GuiGetGuiData.
2313 * Each helper function which needs the console has to validate and lock it.
2314 */
2315 Console = GuiData->Console;
2316
2317 /* We have a console, start message dispatching */
2318 switch (msg)
2319 {
2320 case WM_ACTIVATE:
2321 OnActivate(GuiData, wParam);
2322 break;
2323
2324 case WM_CLOSE:
2325 if (OnClose(GuiData)) goto Default;
2326 break;
2327
2328 case WM_ERASEBKGND:
2329 return TRUE;
2330
2331 case WM_PAINT:
2332 OnPaint(GuiData);
2333 break;
2334
2335 case WM_TIMER:
2336 OnTimer(GuiData);
2337 break;
2338
2339 case WM_PALETTECHANGED:
2340 {
2341 DPRINT("WM_PALETTECHANGED called\n");
2342
2343 /*
2344 * Protects against infinite loops:
2345 * "... A window that receives this message must not realize
2346 * its palette, unless it determines that wParam does not contain
2347 * its own window handle." (WM_PALETTECHANGED description - MSDN)
2348 *
2349 * This message is sent to all windows, including the one that
2350 * changed the system palette and caused this message to be sent.
2351 * The wParam of this message contains the handle of the window
2352 * that caused the system palette to change. To avoid an infinite
2353 * loop, care must be taken to check that the wParam of this message
2354 * does not match the window's handle.
2355 */
2356 if ((HWND)wParam == hWnd) break;
2357
2358 DPRINT("WM_PALETTECHANGED ok\n");
2359 OnPaletteChanged(GuiData);
2360 DPRINT("WM_PALETTECHANGED quit\n");
2361 break;
2362 }
2363
2364 case WM_KEYDOWN:
2365 case WM_KEYUP:
2366 case WM_CHAR:
2367 case WM_DEADCHAR:
2368 case WM_SYSKEYDOWN:
2369 case WM_SYSKEYUP:
2370 case WM_SYSCHAR:
2371 case WM_SYSDEADCHAR:
2372 {
2373 /* Detect Alt-Enter presses and switch back and forth to fullscreen mode */
2375 {
2376 /* Switch only at first Alt-Enter press, and ignore subsequent key repetitions */
2377 if ((HIWORD(lParam) & (KF_UP | KF_REPEAT)) != KF_REPEAT)
2379
2380 break;
2381 }
2382 /* Detect Alt-Esc/Space/Tab presses defer to DefWindowProc */
2383 if ( (HIWORD(lParam) & KF_ALTDOWN) && (wParam == VK_ESCAPE || wParam == VK_SPACE || wParam == VK_TAB))
2384 {
2385 return DefWindowProcW(hWnd, msg, wParam, lParam);
2386 }
2387 /* Detect Alt+Shift */
2388 if (wParam == VK_SHIFT && (msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP))
2389 {
2390 return DefWindowProcW(hWnd, msg, wParam, lParam);
2391 }
2392
2393 OnKey(GuiData, msg, wParam, lParam);
2394 break;
2395 }
2396
2397 case WM_SETCURSOR:
2398 {
2399 /* Do nothing if the window is hidden */
2400 if (!GuiData->IsWindowVisible) goto Default;
2401
2402 /*
2403 * The message was sent because we are manually triggering a change.
2404 * Check whether the mouse is indeed present on this console window
2405 * and take appropriate decisions.
2406 */
2407 if (wParam == -1 && lParam == -1)
2408 {
2409 POINT mouseCoords;
2410 HWND hWndHit;
2411
2412 /* Get the placement of the mouse */
2413 GetCursorPos(&mouseCoords);
2414
2415 /* On which window is placed the mouse ? */
2416 hWndHit = WindowFromPoint(mouseCoords);
2417
2418 /* It's our window. Perform the hit-test to be used later on. */
2419 if (hWndHit == hWnd)
2420 {
2421 wParam = (WPARAM)hWnd;
2422 lParam = DefWindowProcW(hWndHit, WM_NCHITTEST, 0,
2423 MAKELPARAM(mouseCoords.x, mouseCoords.y));
2424 }
2425 }
2426
2427 /* Set the mouse cursor only when we are in the client area */
2428 if ((HWND)wParam == hWnd && LOWORD(lParam) == HTCLIENT)
2429 {
2430 if (GuiData->MouseCursorRefCount >= 0)
2431 {
2432 /* Show the cursor */
2433 SetCursor(GuiData->hCursor);
2434 }
2435 else
2436 {
2437 /* Hide the cursor if the reference count is negative */
2438 SetCursor(NULL);
2439 }
2440 return TRUE;
2441 }
2442 else
2443 {
2444 goto Default;
2445 }
2446 }
2447
2448 case WM_LBUTTONDOWN:
2449 case WM_MBUTTONDOWN:
2450 case WM_RBUTTONDOWN:
2451 case WM_XBUTTONDOWN:
2452 case WM_LBUTTONUP:
2453 case WM_MBUTTONUP:
2454 case WM_RBUTTONUP:
2455 case WM_XBUTTONUP:
2456 case WM_LBUTTONDBLCLK:
2457 case WM_MBUTTONDBLCLK:
2458 case WM_RBUTTONDBLCLK:
2459 case WM_XBUTTONDBLCLK:
2460 case WM_MOUSEMOVE:
2461 case WM_MOUSEWHEEL:
2462 case WM_MOUSEHWHEEL:
2463 {
2464 Result = OnMouse(GuiData, msg, wParam, lParam);
2465 break;
2466 }
2467
2468 case WM_HSCROLL:
2469 OnScroll(GuiData, SB_HORZ, LOWORD(wParam));
2470 break;
2471
2472 case WM_VSCROLL:
2473 OnScroll(GuiData, SB_VERT, LOWORD(wParam));
2474 break;
2475
2476 case WM_CONTEXTMENU:
2477 {
2478 /* Do nothing if the window is hidden */
2479 if (!GuiData->IsWindowVisible) break;
2480
2481 if (DefWindowProcW(hWnd /*GuiData->hWindow*/, WM_NCHITTEST, 0, lParam) == HTCLIENT)
2482 {
2483 HMENU hMenu = CreatePopupMenu();
2484 if (hMenu != NULL)
2485 {
2487 TrackPopupMenuEx(hMenu,
2491 hWnd,
2492 NULL);
2493 DestroyMenu(hMenu);
2494 }
2495 break;
2496 }
2497 else
2498 {
2499 goto Default;
2500 }
2501 }
2502
2503 case WM_INITMENU:
2504 {
2505 HMENU hMenu = (HMENU)wParam;
2506 if (hMenu != NULL)
2507 {
2508 /* Enable or disable the Close menu item */
2511
2512 /* Enable or disable the Copy and Paste items */
2516 // FIXME: Following whether the active screen buffer is text-mode
2517 // or graphics-mode, search for CF_UNICODETEXT or CF_BITMAP formats.
2521 }
2522
2524 break;
2525 }
2526
2527 case WM_MENUSELECT:
2528 {
2529 if (HIWORD(wParam) == 0xFFFF) // Allow all the menu flags
2530 {
2532 }
2533 break;
2534 }
2535
2536 case WM_COMMAND:
2537 case WM_SYSCOMMAND:
2538 {
2539 Result = OnCommand(GuiData, wParam, lParam);
2540 break;
2541 }
2542
2543 case WM_DROPFILES:
2544 OnDropFiles(Console, (HDROP)wParam);
2545 break;
2546
2547 case WM_SETFOCUS:
2548 case WM_KILLFOCUS:
2549 OnFocus(GuiData, (msg == WM_SETFOCUS));
2550 break;
2551
2552 case WM_GETMINMAXINFO:
2554 break;
2555
2556 case WM_MOVE:
2557 OnMove(GuiData);
2558 break;
2559
2560#if 0 // This code is here to prepare & control dynamic console SB resizing.
2561 case WM_SIZING:
2562 {
2563 PRECT dragRect = (PRECT)lParam;
2564 switch (wParam)
2565 {
2566 case WMSZ_LEFT:
2567 DPRINT1("WMSZ_LEFT\n");
2568 break;
2569 case WMSZ_RIGHT:
2570 DPRINT1("WMSZ_RIGHT\n");
2571 break;
2572 case WMSZ_TOP:
2573 DPRINT1("WMSZ_TOP\n");
2574 break;
2575 case WMSZ_TOPLEFT:
2576 DPRINT1("WMSZ_TOPLEFT\n");
2577 break;
2578 case WMSZ_TOPRIGHT:
2579 DPRINT1("WMSZ_TOPRIGHT\n");
2580 break;
2581 case WMSZ_BOTTOM:
2582 DPRINT1("WMSZ_BOTTOM\n");
2583 break;
2584 case WMSZ_BOTTOMLEFT:
2585 DPRINT1("WMSZ_BOTTOMLEFT\n");
2586 break;
2587 case WMSZ_BOTTOMRIGHT:
2588 DPRINT1("WMSZ_BOTTOMRIGHT\n");
2589 break;
2590 default:
2591 DPRINT1("wParam = %d\n", wParam);
2592 break;
2593 }
2594 DPRINT1("dragRect = {.left = %d ; .top = %d ; .right = %d ; .bottom = %d}\n",
2595 dragRect->left, dragRect->top, dragRect->right, dragRect->bottom);
2596 break;
2597 }
2598#endif
2599
2600 case WM_SIZE:
2601 OnSize(GuiData, wParam, lParam);
2602 break;
2603
2604 case PM_RESIZE_TERMINAL:
2605 {
2606 PCONSOLE_SCREEN_BUFFER Buff = GuiData->ActiveBuffer;
2607 HDC hDC;
2608 HBITMAP hnew, hold;
2609
2611 UINT WidthUnit, HeightUnit;
2612
2613 /* Do nothing if the window is hidden */
2614 if (!GuiData->IsWindowVisible) break;
2615
2616 GetScreenBufferSizeUnits(Buff, GuiData, &WidthUnit, &HeightUnit);
2617
2618 Width = Buff->ScreenBufferSize.X * WidthUnit ;
2619 Height = Buff->ScreenBufferSize.Y * HeightUnit;
2620
2621 /* Recreate the framebuffer */
2622 hDC = GetDC(GuiData->hWindow);
2624 ReleaseDC(GuiData->hWindow, hDC);
2625 hold = SelectObject(GuiData->hMemDC, hnew);
2626 if (GuiData->hBitmap)
2627 {
2628 if (hold == GuiData->hBitmap) DeleteObject(GuiData->hBitmap);
2629 }
2630 GuiData->hBitmap = hnew;
2631
2632 /* Resize the window to the user's values */
2633 GuiData->WindowSizeLock = TRUE;
2634 ResizeConWnd(GuiData, WidthUnit, HeightUnit);
2635 GuiData->WindowSizeLock = FALSE;
2636 break;
2637 }
2638
2639 /*
2640 * Undocumented message sent by Windows' console.dll for applying console info.
2641 * See http://www.catch22.net/sites/default/source/files/setconsoleinfo.c
2642 * and http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf
2643 * for more information.
2644 */
2645 case WM_SETCONSOLEINFO:
2646 {
2648 break;
2649 }
2650
2651 case PM_CONSOLE_BEEP:
2652 DPRINT1("Beep\n");
2653 Beep(800, 200);
2654 break;
2655
2657 SetWindowTextW(GuiData->hWindow, GuiData->Console->Title.Buffer);
2658 break;
2659
2660 default: Default:
2662 break;
2663 }
2664
2665 return Result;
2666}
static HDC hDC
Definition: 3dtext.c:33
CConsole Console
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
#define CF_UNICODETEXT
Definition: constants.h:408
#define DPRINT1
Definition: precomp.h:8
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static BOOL OnNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
Definition: conwnd.c:630
static VOID OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
Definition: conwnd.c:2100
static VOID OnFocus(PGUI_CONSOLE_DATA GuiData, BOOL SetFocus)
Definition: conwnd.c:762
static LRESULT OnNcDestroy(HWND hWnd)
Definition: conwnd.c:1446
static VOID OnMove(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:2198
static VOID OnPaint(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:1046
HBITMAP CreateFrameBufferBitmap(HDC hDC, int width, int height)
Definition: conwnd.c:2264
static const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems[]
Definition: conwnd.c:84
static VOID OnTimer(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:1313
static VOID OnScroll(PGUI_CONSOLE_DATA GuiData, INT nBar, WORD sbCode)
Definition: conwnd.c:1472
static BOOL OnClose(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:1425
static LRESULT OnMouse(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: conwnd.c:1606
static PGUI_CONSOLE_DATA GuiGetGuiData(HWND hWnd)
Definition: conwnd.c:420
static VOID SendMenuEvent(PCONSRV_CONSOLE Console, UINT CmdId)
Definition: conwnd.c:274
static VOID OnPaletteChanged(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:1101
static VOID OnSize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
Definition: conwnd.c:2132
static LRESULT OnCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
Definition: conwnd.c:356
static VOID ResizeConWnd(PGUI_CONSOLE_DATA GuiData, DWORD WidthUnit, DWORD HeightUnit)
Definition: conwnd.c:428
static VOID OnKey(PGUI_CONSOLE_DATA GuiData, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: conwnd.c:1148
static VOID OnActivate(PGUI_CONSOLE_DATA GuiData, WPARAM wParam)
Definition: conwnd.c:723
static VOID OnDropFiles(PCONSRV_CONSOLE Console, HDROP hDrop)
Definition: conwnd.c:2212
#define PM_RESIZE_TERMINAL
Definition: conwnd.h:20
#define PM_CONSOLE_SET_TITLE
Definition: conwnd.h:22
#define PM_CONSOLE_BEEP
Definition: conwnd.h:21
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID GuiConsoleSwitchFullScreen(PGUI_CONSOLE_DATA GuiData)
Definition: fullscreen.c:175
pKey DeleteObject()
VOID GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData, HANDLE hClientSection)
Definition: guisettings.c:258
FORCEINLINE VOID GetScreenBufferSizeUnits(IN PCONSOLE_SCREEN_BUFFER Buffer, IN PGUI_CONSOLE_DATA GuiData, OUT PUINT WidthUnit, OUT PUINT HeightUnit)
Definition: guiterm.h:22
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
@ Default
Definition: stdole2.idl:392
#define LOWORD(l)
Definition: pedump.c:82
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define DPRINT
Definition: sndvol32.h:73
COORD ScreenBufferSize
Definition: conio.h:62
UNICODE_STRING Title
Definition: conio_winsrv.h:178
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
PCONSOLE_SCREEN_BUFFER ActiveBuffer
Definition: conwnd.h:92
CONSOLE_SELECTION_INFO Selection
Definition: conwnd.h:93
BOOLEAN IsWindowVisible
Definition: conwnd.h:52
BOOL IsCloseButtonEnabled
Definition: conwnd.h:78
BOOL WindowSizeLock
Definition: conwnd.h:43
PCONSRV_CONSOLE Console
Definition: conwnd.h:91
HCURSOR hCursor
Definition: conwnd.h:71
HBITMAP hBitmap
Definition: conwnd.h:64
INT MouseCursorRefCount
Definition: conwnd.h:72
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define WM_MOUSEWHEEL
Definition: treelist.c:96
#define HIWORD(l)
Definition: typedefs.h:247
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
#define PRECT
Definition: precomp.h:27
#define WM_SETCONSOLEINFO
Definition: settings.h:21
#define ID_SYSTEM_EDIT_COPY
Definition: resource.h:13
#define ID_SYSTEM_EDIT_PASTE
Definition: resource.h:14
#define CONSOLE_SELECTION_IN_PROGRESS
Definition: wincon.h:103
#define CONSOLE_SELECTION_NOT_EMPTY
Definition: wincon.h:104
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define WM_PAINT
Definition: winuser.h:1623
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_ERASEBKGND
Definition: winuser.h:1628
#define WM_CLOSE
Definition: winuser.h:1624
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_SYSCOMMAND
Definition: winuser.h:1744
#define VK_TAB
Definition: winuser.h:2202
#define WM_HSCROLL
Definition: winuser.h:1746
#define MAKELPARAM(l, h)
Definition: winuser.h:4011
#define WM_KEYUP
Definition: winuser.h:1719
#define WMSZ_BOTTOMRIGHT
Definition: winuser.h:2474
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WMSZ_BOTTOMLEFT
Definition: winuser.h:2473
#define WM_VSCROLL
Definition: winuser.h:1747
#define TPM_RIGHTBUTTON
Definition: winuser.h:2383
#define VK_SPACE
Definition: winuser.h:2222
#define WM_SIZE
Definition: winuser.h:1614
#define SB_VERT
Definition: winuser.h:553
#define WM_DROPFILES
Definition: winuser.h:1828
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1781
#define WM_PALETTECHANGED
Definition: winuser.h:1880
#define WM_COMMAND
Definition: winuser.h:1743
#define KF_ALTDOWN
Definition: winuser.h:2452
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2722
#define WM_NCHITTEST
Definition: winuser.h:1689
#define WM_RBUTTONUP
Definition: winuser.h:1783
#define WMSZ_TOP
Definition: winuser.h:2469
#define WM_RBUTTONDBLCLK
Definition: winuser.h:1784
#define WM_SETFOCUS
Definition: winuser.h:1616
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define WM_MOUSEMOVE
Definition: winuser.h:1778
#define WM_INITMENU
Definition: winuser.h:1748
#define WM_LBUTTONDOWN
Definition: winuser.h:1779
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
#define WMSZ_LEFT
Definition: winuser.h:2467
#define WM_NCCREATE
Definition: winuser.h:1686
#define WM_ACTIVATE
Definition: winuser.h:1615
#define WM_RBUTTONDOWN
Definition: winuser.h:1782
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define WMSZ_TOPLEFT
Definition: winuser.h:2470
#define KF_UP
Definition: winuser.h:2454
#define WM_SYSCHAR
Definition: winuser.h:1724
#define VK_RETURN
Definition: winuser.h:2204
#define WM_SYSDEADCHAR
Definition: winuser.h:1725
#define WM_GETMINMAXINFO
Definition: winuser.h:1643
#define MF_ENABLED
Definition: winuser.h:128
#define WM_TIMER
Definition: winuser.h:1745
#define WMSZ_TOPRIGHT
Definition: winuser.h:2471
#define HTCLIENT
Definition: winuser.h:2478
#define WM_MBUTTONDBLCLK
Definition: winuser.h:1787
#define WM_SYSKEYUP
Definition: winuser.h:1723
HDC WINAPI GetDC(_In_opt_ HWND)
#define SC_CLOSE
Definition: winuser.h:2595
#define WM_LBUTTONUP
Definition: winuser.h:1780
#define WM_CHAR
Definition: winuser.h:1720
#define WM_MOVE
Definition: winuser.h:1613
#define WMSZ_BOTTOM
Definition: winuser.h:2472
#define WM_SIZING
Definition: winuser.h:1810
#define WM_NCDESTROY
Definition: winuser.h:1687
HWND WINAPI WindowFromPoint(_In_ POINT)
#define WMSZ_RIGHT
Definition: winuser.h:2468
#define WM_SETCURSOR
Definition: winuser.h:1639
#define KF_REPEAT
Definition: winuser.h:2453
#define VK_SHIFT
Definition: winuser.h:2205
#define WM_KEYDOWN
Definition: winuser.h:1718
#define WM_MBUTTONUP
Definition: winuser.h:1786
#define WM_MENUSELECT
Definition: winuser.h:1750
#define VK_ESCAPE
Definition: winuser.h:2217
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define WM_DEADCHAR
Definition: winuser.h:1721
#define WM_KILLFOCUS
Definition: winuser.h:1617
#define WM_SYSKEYDOWN
Definition: winuser.h:1722
BOOL WINAPI IsClipboardFormatAvailable(_In_ UINT)
#define WM_MBUTTONDOWN
Definition: winuser.h:1785
#define SB_HORZ
Definition: winuser.h:552
#define MF_GRAYED
Definition: winuser.h:129
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by RegisterConWndClass().

◆ Copy()

static VOID Copy ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 2057 of file conwnd.c.

2058{
2059 if (OpenClipboard(GuiData->hWindow))
2060 {
2062
2064 {
2066 }
2067 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
2068 {
2070 }
2071
2073 }
2074
2075 /* Clear the selection */
2076 UpdateSelection(GuiData, NULL, NULL);
2077}
Definition: bufpool.h:45
static VOID UpdateSelection(PGUI_CONSOLE_DATA GuiData, PCOORD SelectionAnchor OPTIONAL, PCOORD coord)
Definition: conwnd.c:923
VOID GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
Definition: text.c:306
#define TEXTMODE_BUFFER
Definition: pccons.c:21
VOID GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
Definition: graphics.c:21
#define GetType(This)
Definition: conio.h:54
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
BOOL WINAPI OpenClipboard(_In_opt_ HWND)

Referenced by OnCommand(), OnKey(), and OnMouse().

◆ CreateDerivedFont()

static HFONT CreateDerivedFont ( HFONT  OrgFont,
ULONG  FontWeight,
BOOLEAN  bUnderline,
BOOLEAN  bStrikeOut 
)
static

Definition at line 492 of file conwnd.c.

498{
499 LOGFONTW lf;
500
501 /* Initialize the LOGFONT structure */
502 RtlZeroMemory(&lf, sizeof(lf));
503
504 /* Retrieve the details of the current font */
505 if (GetObjectW(OrgFont, sizeof(lf), &lf) == 0)
506 return NULL;
507
508 /* Change the font attributes */
509 // lf.lfHeight = FontSize.Y;
510 // lf.lfWidth = FontSize.X;
511 lf.lfWeight = FontWeight;
512 // lf.lfItalic = bItalic;
513 lf.lfUnderline = bUnderline;
514 lf.lfStrikeOut = bStrikeOut;
515
516 /* Build a new font */
517 return CreateFontIndirectW(&lf);
518}
BYTE lfStrikeOut
Definition: dimm.idl:66
LONG lfWeight
Definition: dimm.idl:63
BYTE lfUnderline
Definition: dimm.idl:65
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)

Referenced by InitFonts().

◆ CreateFrameBufferBitmap()

HBITMAP CreateFrameBufferBitmap ( HDC  hDC,
int  width,
int  height 
)

Definition at line 2264 of file conwnd.c.

2265{
2266 BITMAPINFO bmi;
2267 ZeroMemory(&bmi, sizeof(BITMAPINFO));
2268 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2269 bmi.bmiHeader.biWidth = width;
2271 bmi.bmiHeader.biPlanes = 1;
2274 return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
2275}
#define BI_RGB
Definition: precomp.h:56
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#define ZeroMemory
Definition: winbase.h:1737
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define BITSPIXEL
Definition: wingdi.h:720

Referenced by ConWndProc().

◆ CreateSelectionRgn()

static HRGN CreateSelectionRgn ( PGUI_CONSOLE_DATA  GuiData,
BOOL  LineSelection,
PCOORD  SelectionAnchor,
PSMALL_RECT  SmallRect 
)
static

Definition at line 813 of file conwnd.c.

817{
818 if (!LineSelection)
819 {
820 RECT rect;
821 SmallRectToRect(GuiData, &rect, SmallRect);
823 }
824 else
825 {
826 HRGN SelRgn;
827 COORD Begin, End;
828
829 GetSelectionBeginEnd(&Begin, &End, SelectionAnchor, SmallRect);
830
831 if (Begin.Y == End.Y)
832 {
833 SMALL_RECT sr;
834 RECT r ;
835
836 sr.Left = Begin.X;
837 sr.Top = Begin.Y;
838 sr.Right = End.X;
839 sr.Bottom = End.Y;
840
841 // Debug thingie to see whether I can put this corner case
842 // together with the previous one.
843 if (SmallRect->Left != sr.Left ||
844 SmallRect->Top != sr.Top ||
845 SmallRect->Right != sr.Right ||
846 SmallRect->Bottom != sr.Bottom)
847 {
848 DPRINT1("\n"
849 "SmallRect = (%d, %d, %d, %d)\n"
850 "sr = (%d, %d, %d, %d)\n"
851 "\n",
852 SmallRect->Left, SmallRect->Top, SmallRect->Right, SmallRect->Bottom,
853 sr.Left, sr.Top, sr.Right, sr.Bottom);
854 }
855
856 SmallRectToRect(GuiData, &r, &sr);
857 SelRgn = CreateRectRgnIndirect(&r);
858 }
859 else
860 {
861 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
862
863 HRGN rg1, rg2, rg3;
864 SMALL_RECT sr1, sr2, sr3;
865 RECT r1 , r2 , r3 ;
866
867 sr1.Left = Begin.X;
868 sr1.Top = Begin.Y;
869 sr1.Right = ActiveBuffer->ScreenBufferSize.X - 1;
870 sr1.Bottom = Begin.Y;
871
872 sr2.Left = 0;
873 sr2.Top = Begin.Y + 1;
874 sr2.Right = ActiveBuffer->ScreenBufferSize.X - 1;
875 sr2.Bottom = End.Y - 1;
876
877 sr3.Left = 0;
878 sr3.Top = End.Y;
879 sr3.Right = End.X;
880 sr3.Bottom = End.Y;
881
882 SmallRectToRect(GuiData, &r1, &sr1);
883 SmallRectToRect(GuiData, &r2, &sr2);
884 SmallRectToRect(GuiData, &r3, &sr3);
885
889
890 CombineRgn(rg1, rg1, rg2, RGN_XOR);
891 CombineRgn(rg1, rg1, rg3, RGN_XOR);
892 DeleteObject(rg3);
893 DeleteObject(rg2);
894
895 SelRgn = rg1;
896 }
897
898 return SelRgn;
899 }
900}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 const char BOOLEAN Begin
Definition: acpixf.h:1301
VOID GetSelectionBeginEnd(PCOORD Begin, PCOORD End, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
Definition: conwnd.c:792
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
FORCEINLINE VOID SmallRectToRect(PGUI_CONSOLE_DATA GuiData, PRECT Rect, PSMALL_RECT SmallRect)
Definition: guiterm.h:43
static DNS_RECORDW r3
Definition: record.c:39
static DNS_RECORDW r1
Definition: record.c:37
static DNS_RECORDW r2
Definition: record.c:38
& rect
Definition: startmenu.cpp:1413
Definition: bl.h:1338
SHORT Top
Definition: tui.c:25
SHORT Right
Definition: tui.c:26
SHORT Left
Definition: tui.c:24
SHORT Bottom
Definition: tui.c:27
int WINAPI CombineRgn(_In_opt_ HRGN hrgnDest, _In_opt_ HRGN hrgnSrc1, _In_opt_ HRGN hrgnSrc2, _In_ int fnCombineMode)
#define RGN_XOR
Definition: wingdi.h:360
HRGN WINAPI CreateRectRgnIndirect(_In_ LPCRECT)

Referenced by PaintSelectionRect(), and UpdateSelection().

◆ CreateSysMenu()

VOID CreateSysMenu ( HWND  hWnd)

Definition at line 242 of file conwnd.c.

243{
244 MENUITEMINFOW mii;
245 HMENU hMenu;
246 PWCHAR ptrTab;
247 WCHAR szMenuStringBack[255];
248
249 hMenu = GetSystemMenu(hWnd, FALSE);
250 if (hMenu == NULL)
251 return;
252
253 mii.cbSize = sizeof(mii);
254 mii.fMask = MIIM_STRING;
255 mii.dwTypeData = szMenuStringBack;
256 mii.cch = ARRAYSIZE(szMenuStringBack);
257
258 GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
259
260 ptrTab = wcschr(szMenuStringBack, L'\t');
261 if (ptrTab)
262 {
263 *ptrTab = L'\0';
264 mii.cch = (UINT)wcslen(szMenuStringBack);
265
266 SetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii);
267 }
268
271}
static const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems[]
Definition: conwnd.c:96
#define wcschr
Definition: compat.h:17
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define L(x)
Definition: ntvdm.h:50
LPWSTR dwTypeData
Definition: winuser.h:3272
uint16_t * PWCHAR
Definition: typedefs.h:56
#define MIIM_STRING
Definition: winuser.h:730
BOOL WINAPI SetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
BOOL WINAPI DrawMenuBar(_In_ HWND)
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)

Referenced by GuiConsoleInputThread().

◆ DeleteFonts()

VOID DeleteFonts ( PGUI_CONSOLE_DATA  GuiData)

Definition at line 481 of file conwnd.c.

482{
483 ULONG i;
484 for (i = 0; i < ARRAYSIZE(GuiData->Font); ++i)
485 {
486 if (GuiData->Font[i] != NULL) DeleteObject(GuiData->Font[i]);
487 GuiData->Font[i] = NULL;
488 }
489}
HFONT Font[FONT_MAXNO]
Definition: conwnd.h:86
uint32_t ULONG
Definition: typedefs.h:59

Referenced by InitFonts(), and OnNcDestroy().

◆ GetSelectionBeginEnd()

VOID GetSelectionBeginEnd ( PCOORD  Begin,
PCOORD  End,
PCOORD  SelectionAnchor,
PSMALL_RECT  SmallRect 
)

Definition at line 792 of file conwnd.c.

795{
796 if (Begin == NULL || End == NULL) return;
797
798 *Begin = *SelectionAnchor;
799 End->X = (SelectionAnchor->X == SmallRect->Left) ? SmallRect->Right
800 /* Case X != Left, must be == Right */ : SmallRect->Left;
801 End->Y = (SelectionAnchor->Y == SmallRect->Top ) ? SmallRect->Bottom
802 /* Case Y != Top, must be == Bottom */ : SmallRect->Top;
803
804 /* Exchange Begin / End if Begin > End lexicographically */
805 if (Begin->Y > End->Y || (Begin->Y == End->Y && Begin->X > End->X))
806 {
807 End->X = _InterlockedExchange16(&Begin->X, End->X);
808 End->Y = _InterlockedExchange16(&Begin->Y, End->Y);
809 }
810}
short _InterlockedExchange16(_Interlocked_operand_ short volatile *_Target, short _Value)

Referenced by CreateSelectionRgn(), and GuiCopyFromTextModeBuffer().

◆ GuiGetGuiData()

static PGUI_CONSOLE_DATA GuiGetGuiData ( HWND  hWnd)
static

Definition at line 420 of file conwnd.c.

421{
422 /* This function ensures that the console pointer is not NULL */
424 return ( ((GuiData == NULL) || (GuiData->hWindow == hWnd && GuiData->Console != NULL)) ? GuiData : NULL );
425}
struct _GUI_CONSOLE_DATA * PGUI_CONSOLE_DATA
#define GWLP_USERDATA
Definition: treelist.c:63
#define GetWindowLongPtrW
Definition: winuser.h:4832

Referenced by ConWndProc(), and OnNcDestroy().

◆ InitFonts()

BOOL InitFonts ( _Inout_ PGUI_CONSOLE_DATA  GuiData,
_In_reads_or_z_(LF_FACESIZE) PCWSTR  FaceName,
_In_ ULONG  FontWeight,
_In_ ULONG  FontFamily,
_In_ COORD  FontSize,
_In_opt_ UINT  CodePage,
_In_ BOOL  UseDefaultFallback 
)

Definition at line 521 of file conwnd.c.

530{
531 HDC hDC;
532 HFONT hFont;
533 FONT_DATA FontData;
534 UINT OldCharWidth = GuiData->CharWidth;
535 UINT OldCharHeight = GuiData->CharHeight;
536 COORD OldFontSize = GuiData->GuiInfo.FontSize;
537 WCHAR NewFaceName[LF_FACESIZE];
538
539 /* Default to current code page if none has been provided */
540 if (!CodePage)
541 CodePage = GuiData->Console->OutputCodePage;
542
543 /*
544 * Initialize a new NORMAL font.
545 */
546
547 /* Copy the requested face name into the local buffer.
548 * It will be modified in output by CreateConsoleFontEx()
549 * to hold a possible fallback font face name. */
550 StringCchCopyNW(NewFaceName, ARRAYSIZE(NewFaceName),
551 FaceName, LF_FACESIZE);
552
553 /* NOTE: FontSize is always in cell height/width units (pixels) */
554 hFont = CreateConsoleFontEx((LONG)(ULONG)FontSize.Y,
555 (LONG)(ULONG)FontSize.X,
556 NewFaceName,
557 FontWeight,
559 CodePage,
560 UseDefaultFallback,
561 &FontData);
562 if (!hFont)
563 {
564 DPRINT1("InitFonts: CreateConsoleFontEx('%S') failed\n", NewFaceName);
565 return FALSE;
566 }
567
568 /* Retrieve its character cell size */
569 hDC = GetDC(GuiData->hWindow);
570 if (!GetFontCellSize(hDC, hFont, &GuiData->CharHeight, &GuiData->CharWidth))
571 {
572 DPRINT1("InitFonts: GetFontCellSize failed\n");
573 ReleaseDC(GuiData->hWindow, hDC);
575 return FALSE;
576 }
577 ReleaseDC(GuiData->hWindow, hDC);
578
579 /*
580 * Initialization succeeded.
581 */
582 // Delete all the old fonts first.
583 DeleteFonts(GuiData);
584 GuiData->Font[FONT_NORMAL] = hFont;
585
586 /*
587 * Now build the optional fonts (bold, underlined, mixed).
588 * Do not error in case they fail to be created.
589 */
590 GuiData->Font[FONT_BOLD] =
591 CreateDerivedFont(GuiData->Font[FONT_NORMAL],
592 max(FW_BOLD, FontData.Weight),
593 FALSE,
594 FALSE);
595 GuiData->Font[FONT_UNDERLINE] =
596 CreateDerivedFont(GuiData->Font[FONT_NORMAL],
597 FontData.Weight,
598 TRUE,
599 FALSE);
600 GuiData->Font[FONT_BOLD | FONT_UNDERLINE] =
601 CreateDerivedFont(GuiData->Font[FONT_NORMAL],
602 max(FW_BOLD, FontData.Weight),
603 TRUE,
604 FALSE);
605
606 /*
607 * Save the new font characteristics.
608 */
609 StringCchCopyNW(GuiData->GuiInfo.FaceName,
610 ARRAYSIZE(GuiData->GuiInfo.FaceName),
611 NewFaceName, ARRAYSIZE(NewFaceName));
612 GuiData->GuiInfo.FontWeight = FontData.Weight;
613 GuiData->GuiInfo.FontFamily = FontData.Family;
614 GuiData->GuiInfo.FontSize = FontData.Size;
615
616 /* Resize the terminal, in case the new font has a different size */
617 if ((OldCharWidth != GuiData->CharWidth) ||
618 (OldCharHeight != GuiData->CharHeight) ||
619 (OldFontSize.X != FontData.Size.X ||
620 OldFontSize.Y != FontData.Size.Y))
621 {
622 TermResizeTerminal(GuiData->Console);
623 }
624
625 return TRUE;
626}
HFONT hFont
Definition: main.c:53
static HFONT CreateDerivedFont(HFONT OrgFont, ULONG FontWeight, BOOLEAN bUnderline, BOOLEAN bStrikeOut)
Definition: conwnd.c:492
VOID DeleteFonts(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:481
#define FONT_NORMAL
Definition: conwnd.h:35
#define FONT_BOLD
Definition: conwnd.h:36
#define FONT_UNDERLINE
Definition: conwnd.h:37
#define LF_FACESIZE
Definition: dimm.idl:39
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
long LONG
Definition: pedump.c:60
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
COORD Size
Definition: font.h:57
ULONG Family
Definition: font.h:56
ULONG Weight
Definition: font.h:55
#define max(a, b)
Definition: svc.c:63
#define TermResizeTerminal(Console)
Definition: term.h:28
HFONT CreateConsoleFontEx(_In_ LONG Height, _In_opt_ LONG Width, _Inout_updates_z_(LF_FACESIZE) PWSTR FaceName, _In_ ULONG FontWeight, _In_ ULONG FontFamily, _In_ UINT CodePage, _In_ BOOL UseDefaultFallback, _Out_ PFONT_DATA FontData)
Validates and creates a suitable console font based on the font characteristics given in input.
Definition: font.c:505
#define FW_BOLD
Definition: wingdi.h:378

Referenced by GuiApplyUserSettings(), GuiSetCodePage(), and OnNcCreate().

◆ InvalidateCell()

VOID InvalidateCell ( PGUI_CONSOLE_DATA  GuiData,
SHORT  x,
SHORT  y 
)

Definition at line 88 of file guiterm.c.

90{
91 SMALL_RECT CellRect = { x, y, x, y };
92 DrawRegion(GuiData, &CellRect);
93}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static VOID DrawRegion(PGUI_CONSOLE_DATA GuiData, SMALL_RECT *Region)
Definition: guiterm.c:76

Referenced by GuiSetCursorInfo(), GuiSetScreenInfo(), GuiWriteStream(), and OnTimer().

◆ IsSystemKey()

static BOOL IsSystemKey ( WORD  VirtualKeyCode)
static

Definition at line 1125 of file conwnd.c.

1126{
1127 switch (VirtualKeyCode)
1128 {
1129 /* From MSDN, "Virtual-Key Codes" */
1130 case VK_RETURN:
1131 case VK_SHIFT:
1132 case VK_CONTROL:
1133 case VK_MENU:
1134 case VK_PAUSE:
1135 case VK_CAPITAL:
1136 case VK_ESCAPE:
1137 case VK_LWIN:
1138 case VK_RWIN:
1139 case VK_NUMLOCK:
1140 case VK_SCROLL:
1141 return TRUE;
1142 default:
1143 return FALSE;
1144 }
1145}
#define VK_CAPITAL
Definition: winuser.h:2209
#define VK_SCROLL
Definition: winuser.h:2283
#define VK_CONTROL
Definition: winuser.h:2206
#define VK_PAUSE
Definition: winuser.h:2208
#define VK_LWIN
Definition: winuser.h:2238
#define VK_NUMLOCK
Definition: winuser.h:2282
#define VK_RWIN
Definition: winuser.h:2239
#define VK_MENU
Definition: winuser.h:2207

Referenced by OnKey().

◆ Mark()

static VOID Mark ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 300 of file conwnd.c.

301{
302 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
303
304 /* Clear the old selection */
306
307 /* Restart a new selection */
308 GuiData->dwSelectionCursor = ActiveBuffer->ViewOrigin;
309 UpdateSelection(GuiData,
310 &GuiData->dwSelectionCursor,
311 &GuiData->dwSelectionCursor);
312}
COORD dwSelectionCursor
Definition: conwnd.h:94
#define CONSOLE_NO_SELECTION
Definition: wincon.h:102

Referenced by EmbeddedPointerMarshall(), EmbeddedPointerMemorySize(), EmbeddedPointerUnmarshall(), OnCommand(), and WmipIoControl().

◆ OnActivate()

static VOID OnActivate ( PGUI_CONSOLE_DATA  GuiData,
WPARAM  wParam 
)
static

Definition at line 723 of file conwnd.c.

724{
725 WORD ActivationState = LOWORD(wParam);
726
727 DPRINT("WM_ACTIVATE - ActivationState = %d\n", ActivationState);
728
729 GuiData->IsWindowActive = (ActivationState != WA_INACTIVE);
730
731 if ( ActivationState == WA_ACTIVE ||
732 ActivationState == WA_CLICKACTIVE )
733 {
734 if (GuiData->GuiInfo.FullScreen)
735 {
736 EnterFullScreen(GuiData);
737 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
738 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_RESTORE, 0);
739 }
740 }
741 else // if (ActivationState == WA_INACTIVE)
742 {
743 if (GuiData->GuiInfo.FullScreen)
744 {
746 LeaveFullScreen(GuiData);
747 // // PostMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
748 // SendMessageW(GuiData->hWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
749 }
750 }
751
752 /*
753 * Ignore the next mouse event when we are going to be enabled again via
754 * the mouse, in order to prevent, e.g. when we are in Edit mode, erroneous
755 * mouse actions from the user that could spoil text selection or copy/pastes.
756 */
757 if (ActivationState == WA_CLICKACTIVE)
758 GuiData->IgnoreNextMouseEvent = TRUE;
759}
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL EnterFullScreen(PGUI_CONSOLE_DATA GuiData)
Definition: fullscreen.c:21
VOID LeaveFullScreen(PGUI_CONSOLE_DATA GuiData)
Definition: fullscreen.c:39
BOOLEAN IsWindowActive
Definition: conwnd.h:53
BOOL IgnoreNextMouseEvent
Definition: conwnd.h:73
GUI_CONSOLE_INFO GuiInfo
Definition: conwnd.h:97
#define WA_INACTIVE
Definition: winuser.h:2625
#define SC_MINIMIZE
Definition: winuser.h:2589
#define WA_ACTIVE
Definition: winuser.h:2626
#define WA_CLICKACTIVE
Definition: winuser.h:2627
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by ConWndProc().

◆ OnClose()

static BOOL OnClose ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 1425 of file conwnd.c.

1426{
1427 PCONSRV_CONSOLE Console = GuiData->Console;
1428
1430 return TRUE;
1431
1432 // TODO: Prompt for termination ? (Warn the user about possible apps running in this console)
1433
1434 /*
1435 * FIXME: Windows will wait up to 5 seconds for the thread to exit.
1436 * We shouldn't wait here, though, since the console lock is entered.
1437 * A copy of the thread list probably needs to be made.
1438 */
1440
1442 return FALSE;
1443}
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:36
NTSTATUS NTAPI ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console, IN ULONG ProcessGroupId, IN ULONG CtrlEvent)
Definition: console.c:1402
@ CONSOLE_RUNNING
Definition: conio.h:283
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define CTRL_CLOSE_EVENT
Definition: wincon.h:70

Referenced by ConWndProc().

◆ OnCommand()

static LRESULT OnCommand ( PGUI_CONSOLE_DATA  GuiData,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 356 of file conwnd.c.

357{
358 LRESULT Ret = TRUE;
360
361 /*
362 * In case the selected menu item belongs to the user-reserved menu id range,
363 * send to him a menu event and return directly. The user must handle those
364 * reserved menu commands...
365 */
366 if (GuiData->CmdIdLow <= (UINT)wParam && (UINT)wParam <= GuiData->CmdIdHigh)
367 {
369 goto Quit;
370 }
371
372 /* ... otherwise, perform actions. */
373 switch (wParam)
374 {
376 Mark(GuiData);
377 break;
378
380 Copy(GuiData);
381 break;
382
384 Paste(GuiData);
385 break;
386
388 SelectAll(GuiData);
389 break;
390
392 DPRINT1("Scrolling is not handled yet\n");
393 break;
394
396 DPRINT1("Finding is not handled yet\n");
397 break;
398
401 break;
402
405 break;
406
407 default:
408 Ret = FALSE;
409 break;
410 }
411
412Quit:
413 if (!Ret)
415
416 return Ret;
417}
static VOID SelectAll(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:315
static VOID Copy(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:2057
static VOID Mark(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:300
static VOID Paste(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:2080
VOID GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData, BOOL Defaults)
Definition: guisettings.c:44
#define ID_SYSTEM_DEFAULTS
Definition: resource.h:18
#define ID_SYSTEM_EDIT_SCROLL
Definition: resource.h:16
#define ID_SYSTEM_EDIT_SELECTALL
Definition: resource.h:15
#define ID_SYSTEM_EDIT_FIND
Definition: resource.h:17
#define ID_SYSTEM_EDIT_MARK
Definition: resource.h:12
#define ID_SYSTEM_PROPERTIES
Definition: resource.h:19

Referenced by ConWndProc().

◆ OnDropFiles()

static VOID OnDropFiles ( PCONSRV_CONSOLE  Console,
HDROP  hDrop 
)
static

Definition at line 2212 of file conwnd.c.

2213{
2214 LPWSTR pszPath;
2215 WCHAR szPath[MAX_PATH + 2];
2216
2217 szPath[0] = L'"';
2218
2219 DragQueryFileW(hDrop, 0, &szPath[1], ARRAYSIZE(szPath) - 1);
2220 DragFinish(hDrop);
2221
2222 if (wcschr(&szPath[1], L' ') != NULL)
2223 {
2225 pszPath = szPath;
2226 }
2227 else
2228 {
2229 pszPath = &szPath[1];
2230 }
2231
2232 PasteText(Console, pszPath, wcslen(pszPath));
2233}
#define MAX_PATH
Definition: compat.h:34
void WINAPI DragFinish(HDROP h)
Definition: shellole.c:538
UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength)
Definition: shellole.c:622
VOID PasteText(IN PCONSRV_CONSOLE Console, IN PWCHAR Buffer, IN SIZE_T cchSize)
Definition: text.c:238
LPCWSTR szPath
Definition: env.c:37
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by ConWndProc().

◆ OnFocus()

static VOID OnFocus ( PGUI_CONSOLE_DATA  GuiData,
BOOL  SetFocus 
)
static

Definition at line 762 of file conwnd.c.

763{
765 INPUT_RECORD er;
766
768
769 /* Set console focus state */
770 Console->HasFocus = SetFocus;
771
772 /*
773 * Set the priority of the processes of this console
774 * in accordance with the console focus state.
775 */
777
778 /* Send a focus event */
782
784
785 if (SetFocus)
786 DPRINT("TODO: Create console caret\n");
787 else
788 DPRINT("TODO: Destroy console caret\n");
789}
NTSTATUS ConioProcessInputEvent(PCONSRV_CONSOLE Console, PINPUT_RECORD InputEvent)
Definition: coninput.c:201
FOCUS_EVENT_RECORD FocusEvent
Definition: wincon.h:279
union _INPUT_RECORD::@3285 Event
WORD EventType
Definition: wincon.h:273
NTSTATUS NTAPI ConSrvSetConsoleProcessFocus(IN PCONSRV_CONSOLE Console, IN BOOLEAN SetForeground)
Definition: console.c:1453
#define FOCUS_EVENT
Definition: wincon.h:132
HWND WINAPI SetFocus(_In_opt_ HWND)

Referenced by ConWndProc().

◆ OnGetMinMaxInfo()

static VOID OnGetMinMaxInfo ( PGUI_CONSOLE_DATA  GuiData,
PMINMAXINFO  minMaxInfo 
)
static

Definition at line 2100 of file conwnd.c.

2101{
2102 PCONSRV_CONSOLE Console = GuiData->Console;
2103 PCONSOLE_SCREEN_BUFFER ActiveBuffer;
2104 DWORD windx, windy;
2105 UINT WidthUnit, HeightUnit;
2106
2108
2109 ActiveBuffer = GuiData->ActiveBuffer;
2110
2111 GetScreenBufferSizeUnits(ActiveBuffer, GuiData, &WidthUnit, &HeightUnit);
2112
2115
2116 minMaxInfo->ptMinTrackSize.x = windx;
2117 minMaxInfo->ptMinTrackSize.y = windy;
2118
2119 windx = (ActiveBuffer->ScreenBufferSize.X) * WidthUnit + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
2120 windy = (ActiveBuffer->ScreenBufferSize.Y) * HeightUnit + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
2121
2122 if (ActiveBuffer->ViewSize.X < ActiveBuffer->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // Window currently has a horizontal scrollbar
2123 if (ActiveBuffer->ViewSize.Y < ActiveBuffer->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // Window currently has a vertical scrollbar
2124
2125 minMaxInfo->ptMaxTrackSize.x = windx;
2126 minMaxInfo->ptMaxTrackSize.y = windy;
2127
2129}
#define CONGUI_MIN_WIDTH
Definition: conwnd.c:33
#define CONGUI_MIN_HEIGHT
Definition: conwnd.c:34
POINT ptMinTrackSize
Definition: winuser.h:3633
POINT ptMaxTrackSize
Definition: winuser.h:3634
#define SM_CYEDGE
Definition: winuser.h:1012
#define SM_CXEDGE
Definition: winuser.h:1011
#define SM_CXVSCROLL
Definition: winuser.h:964
#define SM_CXFRAME
Definition: winuser.h:997
#define SM_CYFRAME
Definition: winuser.h:999
#define SM_CYHSCROLL
Definition: winuser.h:965
#define SM_CYCAPTION
Definition: winuser.h:966
int WINAPI GetSystemMetrics(_In_ int)

Referenced by ConWndProc().

◆ OnKey()

static VOID OnKey ( PGUI_CONSOLE_DATA  GuiData,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1148 of file conwnd.c.

1149{
1150 PCONSRV_CONSOLE Console = GuiData->Console;
1151 PCONSOLE_SCREEN_BUFFER ActiveBuffer;
1152
1154
1155 ActiveBuffer = GuiData->ActiveBuffer;
1156
1158 {
1159 WORD VirtualKeyCode = LOWORD(wParam);
1160
1161 if (msg != WM_KEYDOWN) goto Quit;
1162
1163 if (VirtualKeyCode == VK_RETURN)
1164 {
1165 /* Copy (and clear) selection if ENTER is pressed */
1166 Copy(GuiData);
1167 goto Quit;
1168 }
1169 else if ( VirtualKeyCode == VK_ESCAPE ||
1170 (VirtualKeyCode == 'C' && (GetKeyState(VK_CONTROL) & KEY_PRESSED)) )
1171 {
1172 /* Cancel selection if ESC or Ctrl-C are pressed */
1173 UpdateSelection(GuiData, NULL, NULL);
1174 goto Quit;
1175 }
1176
1177 if ((GuiData->Selection.dwFlags & CONSOLE_MOUSE_SELECTION) == 0)
1178 {
1179 /* Keyboard selection mode */
1180 BOOL Interpreted = FALSE;
1181 BOOL MajPressed = !!(GetKeyState(VK_SHIFT) & KEY_PRESSED);
1182
1183 switch (VirtualKeyCode)
1184 {
1185 case VK_LEFT:
1186 {
1187 Interpreted = TRUE;
1188 if (GuiData->dwSelectionCursor.X > 0)
1189 GuiData->dwSelectionCursor.X--;
1190
1191 break;
1192 }
1193
1194 case VK_RIGHT:
1195 {
1196 Interpreted = TRUE;
1197 if (GuiData->dwSelectionCursor.X < ActiveBuffer->ScreenBufferSize.X - 1)
1198 GuiData->dwSelectionCursor.X++;
1199
1200 break;
1201 }
1202
1203 case VK_UP:
1204 {
1205 Interpreted = TRUE;
1206 if (GuiData->dwSelectionCursor.Y > 0)
1207 GuiData->dwSelectionCursor.Y--;
1208
1209 break;
1210 }
1211
1212 case VK_DOWN:
1213 {
1214 Interpreted = TRUE;
1215 if (GuiData->dwSelectionCursor.Y < ActiveBuffer->ScreenBufferSize.Y - 1)
1216 GuiData->dwSelectionCursor.Y++;
1217
1218 break;
1219 }
1220
1221 case VK_HOME:
1222 {
1223 Interpreted = TRUE;
1224 GuiData->dwSelectionCursor.X = 0;
1225 GuiData->dwSelectionCursor.Y = 0;
1226 break;
1227 }
1228
1229 case VK_END:
1230 {
1231 Interpreted = TRUE;
1232 GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
1233 break;
1234 }
1235
1236 case VK_PRIOR:
1237 {
1238 Interpreted = TRUE;
1239 GuiData->dwSelectionCursor.Y -= ActiveBuffer->ViewSize.Y;
1240 if (GuiData->dwSelectionCursor.Y < 0)
1241 GuiData->dwSelectionCursor.Y = 0;
1242
1243 break;
1244 }
1245
1246 case VK_NEXT:
1247 {
1248 Interpreted = TRUE;
1249 GuiData->dwSelectionCursor.Y += ActiveBuffer->ViewSize.Y;
1250 if (GuiData->dwSelectionCursor.Y >= ActiveBuffer->ScreenBufferSize.Y)
1251 GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
1252
1253 break;
1254 }
1255
1256 default:
1257 break;
1258 }
1259
1260 if (Interpreted)
1261 {
1262 UpdateSelection(GuiData,
1263 !MajPressed ? &GuiData->dwSelectionCursor : NULL,
1264 &GuiData->dwSelectionCursor);
1265 }
1266 else if (!IsSystemKey(VirtualKeyCode))
1267 {
1268 /* Emit an error beep sound */
1269 SendNotifyMessage(GuiData->hWindow, PM_CONSOLE_BEEP, 0, 0);
1270 }
1271
1272 goto Quit;
1273 }
1274 else
1275 {
1276 /* Mouse selection mode */
1277
1278 if (!IsSystemKey(VirtualKeyCode))
1279 {
1280 /* Clear the selection and send the key into the input buffer */
1281 UpdateSelection(GuiData, NULL, NULL);
1282 }
1283 else
1284 {
1285 goto Quit;
1286 }
1287 }
1288 }
1289
1290 if ((GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
1291 {
1292 MSG Message;
1293
1294 Message.hwnd = GuiData->hWindow;
1295 Message.message = msg;
1296 Message.wParam = wParam;
1297 Message.lParam = lParam;
1298
1300 }
1301
1302Quit:
1304}
static BOOL IsSystemKey(WORD VirtualKeyCode)
Definition: conwnd.c:1125
#define KEY_PRESSED
Definition: conwnd.h:26
static const WCHAR Message[]
Definition: register.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
VOID NTAPI ConioProcessKey(PCONSRV_CONSOLE Console, MSG *msg)
Definition: input.c:60
#define CONSOLE_MOUSE_SELECTION
Definition: wincon.h:105
#define VK_UP
Definition: winuser.h:2228
#define VK_NEXT
Definition: winuser.h:2224
#define VK_END
Definition: winuser.h:2225
#define VK_HOME
Definition: winuser.h:2226
#define VK_LEFT
Definition: winuser.h:2227
#define VK_RIGHT
Definition: winuser.h:2229
#define VK_DOWN
Definition: winuser.h:2230
#define VK_PRIOR
Definition: winuser.h:2223
#define SendNotifyMessage
Definition: winuser.h:5858
SHORT WINAPI GetKeyState(_In_ int)

Referenced by ConWndProc().

◆ OnMouse()

static LRESULT OnMouse ( PGUI_CONSOLE_DATA  GuiData,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1606 of file conwnd.c.

1607{
1608 BOOL DoDefault = FALSE;
1609 PCONSRV_CONSOLE Console = GuiData->Console;
1610
1611 /*
1612 * HACK FOR CORE-8394 (Part 2):
1613 *
1614 * Check whether we should ignore the next mouse move event.
1615 * In either case we reset the HACK flag.
1616 *
1617 * See Part 1 of this hack below.
1618 */
1619 if (GuiData->HackCORE8394IgnoreNextMove && msg == WM_MOUSEMOVE)
1620 {
1622 goto Quit;
1623 }
1625
1626 // FIXME: It's here that we need to check whether we have focus or not
1627 // and whether we are or not in edit mode, in order to know if we need
1628 // to deal with the mouse.
1629
1630 if (GuiData->IgnoreNextMouseEvent)
1631 {
1632 if (msg != WM_LBUTTONDOWN &&
1633 msg != WM_MBUTTONDOWN &&
1634 msg != WM_RBUTTONDOWN &&
1635 msg != WM_XBUTTONDOWN)
1636 {
1637 /*
1638 * If this mouse event is not a button-down action
1639 * then this is the last one being ignored.
1640 */
1641 GuiData->IgnoreNextMouseEvent = FALSE;
1642 }
1643 else
1644 {
1645 /*
1646 * This mouse event is a button-down action.
1647 * Ignore it and perform default action.
1648 */
1649 DoDefault = TRUE;
1650 }
1651 goto Quit;
1652 }
1653
1655 {
1656 DoDefault = TRUE;
1657 goto Quit;
1658 }
1659
1661 (Console->QuickEdit) )
1662 {
1663 switch (msg)
1664 {
1665 case WM_LBUTTONDOWN:
1666 {
1667 /* Check for selection state */
1671 {
1672 /*
1673 * A mouse selection is currently in progress and the user
1674 * has pressed the SHIFT key and clicked somewhere, update
1675 * the selection.
1676 */
1677 GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1678 UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor);
1679 }
1680 else
1681 {
1682 /* Clear the old selection */
1684
1685 /* Restart a new selection */
1686 GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1687 SetCapture(GuiData->hWindow);
1689 UpdateSelection(GuiData,
1690 &GuiData->dwSelectionCursor,
1691 &GuiData->dwSelectionCursor);
1692 }
1693
1694 break;
1695 }
1696
1697 case WM_LBUTTONUP:
1698 {
1699 if (!(GuiData->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
1700
1701 // GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1702 GuiData->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN;
1703 // UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor);
1705
1706 break;
1707 }
1708
1709 case WM_LBUTTONDBLCLK:
1710 {
1712
1714 {
1715#define IS_WORD_SEP(c) \
1716 ((c) == L'\0' || (c) == L' ' || (c) == L'\t' || (c) == L'\r' || (c) == L'\n')
1717
1719 COORD cL, cR;
1720 PCHAR_INFO ptrL, ptrR;
1721
1722 /* Starting point */
1723 cL = cR = PointToCoord(GuiData, lParam);
1724 ptrL = ptrR = ConioCoordToPointer(TextBuffer, cL.X, cL.Y);
1725
1726 /* Enlarge the selection by checking for whitespace */
1727 while ((0 < cL.X) && !IS_WORD_SEP(ptrL->Char.UnicodeChar)
1728 && !IS_WORD_SEP((ptrL-1)->Char.UnicodeChar))
1729 {
1730 --cL.X;
1731 --ptrL;
1732 }
1733 while ((cR.X < TextBuffer->ScreenBufferSize.X - 1) &&
1734 !IS_WORD_SEP(ptrR->Char.UnicodeChar) &&
1735 !IS_WORD_SEP((ptrR+1)->Char.UnicodeChar))
1736 {
1737 ++cR.X;
1738 ++ptrR;
1739 }
1740
1741 /*
1742 * Update the selection started with the single
1743 * left-click that preceded this double-click.
1744 */
1746 UpdateSelection(GuiData, &cL, &cR);
1747
1748 /* Ignore the next mouse move event */
1749 GuiData->IgnoreNextMouseEvent = TRUE;
1750#undef IS_WORD_SEP
1751 }
1752
1753 break;
1754 }
1755
1756 case WM_RBUTTONDOWN:
1757 case WM_RBUTTONDBLCLK:
1758 {
1760 {
1761 Paste(GuiData);
1762 }
1763 else
1764 {
1765 Copy(GuiData);
1766 }
1767
1768 /* Ignore the next mouse move event */
1769 GuiData->IgnoreNextMouseEvent = TRUE;
1770 break;
1771 }
1772
1773 case WM_MOUSEMOVE:
1774 {
1775 if (!(GET_KEYSTATE_WPARAM(wParam) & MK_LBUTTON)) break;
1776 if (!(GuiData->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) break;
1777
1778 GuiData->dwSelectionCursor = PointToCoord(GuiData, lParam);
1779 UpdateSelection(GuiData, NULL, &GuiData->dwSelectionCursor);
1780 break;
1781 }
1782
1783 default:
1784 DoDefault = TRUE; // FALSE;
1785 break;
1786 }
1787
1788 /*
1789 * HACK FOR CORE-8394 (Part 1):
1790 *
1791 * It appears that when running ReactOS on VBox with Mouse Integration
1792 * enabled, the next mouse event coming after a button-down action is
1793 * a mouse-move. However it is NOT always a rule, so that we cannot use
1794 * the IgnoreNextMouseEvent flag to just "ignore" the next mouse event,
1795 * thinking it would always be a mouse-move event.
1796 *
1797 * To work around this problem (that should really be fixed in Win32k),
1798 * we use a second flag to ignore this possible next mouse move event.
1799 */
1800 switch (msg)
1801 {
1802 case WM_LBUTTONDOWN:
1803 case WM_MBUTTONDOWN:
1804 case WM_RBUTTONDOWN:
1805 case WM_XBUTTONDOWN:
1807 default:
1808 break;
1809 }
1810 }
1812 {
1813 INPUT_RECORD er;
1814 WORD wKeyState = GET_KEYSTATE_WPARAM(wParam);
1815 DWORD dwButtonState = 0;
1816 DWORD dwControlKeyState = 0;
1817 DWORD dwEventFlags = 0;
1818
1819 switch (msg)
1820 {
1821 case WM_LBUTTONDOWN:
1822 SetCapture(GuiData->hWindow);
1823 dwButtonState = FROM_LEFT_1ST_BUTTON_PRESSED;
1824 dwEventFlags = 0;
1825 break;
1826
1827 case WM_MBUTTONDOWN:
1828 SetCapture(GuiData->hWindow);
1829 dwButtonState = FROM_LEFT_2ND_BUTTON_PRESSED;
1830 dwEventFlags = 0;
1831 break;
1832
1833 case WM_RBUTTONDOWN:
1834 SetCapture(GuiData->hWindow);
1835 dwButtonState = RIGHTMOST_BUTTON_PRESSED;
1836 dwEventFlags = 0;
1837 break;
1838
1839 case WM_XBUTTONDOWN:
1840 {
1841 /* Get which X-button was pressed */
1842 WORD wButton = GET_XBUTTON_WPARAM(wParam);
1843
1844 /* Check for X-button validity */
1845 if (wButton & ~(XBUTTON1 | XBUTTON2))
1846 {
1847 DPRINT1("X-button 0x%04x invalid\n", wButton);
1848 DoDefault = TRUE;
1849 break;
1850 }
1851
1852 SetCapture(GuiData->hWindow);
1853 dwButtonState = (wButton == XBUTTON1 ? FROM_LEFT_3RD_BUTTON_PRESSED
1855 dwEventFlags = 0;
1856 break;
1857 }
1858
1859 case WM_LBUTTONUP:
1861 dwButtonState = 0;
1862 dwEventFlags = 0;
1863 break;
1864
1865 case WM_MBUTTONUP:
1867 dwButtonState = 0;
1868 dwEventFlags = 0;
1869 break;
1870
1871 case WM_RBUTTONUP:
1873 dwButtonState = 0;
1874 dwEventFlags = 0;
1875 break;
1876
1877 case WM_XBUTTONUP:
1878 {
1879 /* Get which X-button was released */
1880 WORD wButton = GET_XBUTTON_WPARAM(wParam);
1881
1882 /* Check for X-button validity */
1883 if (wButton & ~(XBUTTON1 | XBUTTON2))
1884 {
1885 DPRINT1("X-button 0x%04x invalid\n", wButton);
1886 /* Ok, just release the button anyway... */
1887 }
1888
1890 dwButtonState = 0;
1891 dwEventFlags = 0;
1892 break;
1893 }
1894
1895 case WM_LBUTTONDBLCLK:
1896 dwButtonState = FROM_LEFT_1ST_BUTTON_PRESSED;
1897 dwEventFlags = DOUBLE_CLICK;
1898 break;
1899
1900 case WM_MBUTTONDBLCLK:
1901 dwButtonState = FROM_LEFT_2ND_BUTTON_PRESSED;
1902 dwEventFlags = DOUBLE_CLICK;
1903 break;
1904
1905 case WM_RBUTTONDBLCLK:
1906 dwButtonState = RIGHTMOST_BUTTON_PRESSED;
1907 dwEventFlags = DOUBLE_CLICK;
1908 break;
1909
1910 case WM_XBUTTONDBLCLK:
1911 {
1912 /* Get which X-button was double-clicked */
1913 WORD wButton = GET_XBUTTON_WPARAM(wParam);
1914
1915 /* Check for X-button validity */
1916 if (wButton & ~(XBUTTON1 | XBUTTON2))
1917 {
1918 DPRINT1("X-button 0x%04x invalid\n", wButton);
1919 DoDefault = TRUE;
1920 break;
1921 }
1922
1923 dwButtonState = (wButton == XBUTTON1 ? FROM_LEFT_3RD_BUTTON_PRESSED
1925 dwEventFlags = DOUBLE_CLICK;
1926 break;
1927 }
1928
1929 case WM_MOUSEMOVE:
1930 dwButtonState = 0;
1931 dwEventFlags = MOUSE_MOVED;
1932 break;
1933
1934 case WM_MOUSEWHEEL:
1935 dwButtonState = GET_WHEEL_DELTA_WPARAM(wParam) << 16;
1936 dwEventFlags = MOUSE_WHEELED;
1937 break;
1938
1939 case WM_MOUSEHWHEEL:
1940 dwButtonState = GET_WHEEL_DELTA_WPARAM(wParam) << 16;
1941 dwEventFlags = MOUSE_HWHEELED;
1942 break;
1943
1944 default:
1945 DoDefault = TRUE;
1946 break;
1947 }
1948
1949 /*
1950 * HACK FOR CORE-8394 (Part 1):
1951 *
1952 * It appears that when running ReactOS on VBox with Mouse Integration
1953 * enabled, the next mouse event coming after a button-down action is
1954 * a mouse-move. However it is NOT always a rule, so that we cannot use
1955 * the IgnoreNextMouseEvent flag to just "ignore" the next mouse event,
1956 * thinking it would always be a mouse-move event.
1957 *
1958 * To work around this problem (that should really be fixed in Win32k),
1959 * we use a second flag to ignore this possible next mouse move event.
1960 */
1961 switch (msg)
1962 {
1963 case WM_LBUTTONDOWN:
1964 case WM_MBUTTONDOWN:
1965 case WM_RBUTTONDOWN:
1966 case WM_XBUTTONDOWN:
1968 default:
1969 break;
1970 }
1971
1972 if (!DoDefault)
1973 {
1974 if (wKeyState & MK_LBUTTON)
1975 dwButtonState |= FROM_LEFT_1ST_BUTTON_PRESSED;
1976 if (wKeyState & MK_MBUTTON)
1977 dwButtonState |= FROM_LEFT_2ND_BUTTON_PRESSED;
1978 if (wKeyState & MK_RBUTTON)
1979 dwButtonState |= RIGHTMOST_BUTTON_PRESSED;
1980 if (wKeyState & MK_XBUTTON1)
1981 dwButtonState |= FROM_LEFT_3RD_BUTTON_PRESSED;
1982 if (wKeyState & MK_XBUTTON2)
1983 dwButtonState |= FROM_LEFT_4TH_BUTTON_PRESSED;
1984
1986 dwControlKeyState |= RIGHT_ALT_PRESSED;
1988 dwControlKeyState |= LEFT_ALT_PRESSED;
1990 dwControlKeyState |= RIGHT_CTRL_PRESSED;
1992 dwControlKeyState |= LEFT_CTRL_PRESSED;
1994 dwControlKeyState |= SHIFT_PRESSED;
1996 dwControlKeyState |= NUMLOCK_ON;
1998 dwControlKeyState |= SCROLLLOCK_ON;
2000 dwControlKeyState |= CAPSLOCK_ON;
2001 /* See WM_CHAR MSDN documentation for instance */
2002 if (HIWORD(lParam) & KF_EXTENDED)
2003 dwControlKeyState |= ENHANCED_KEY;
2004
2005 /* Send a mouse event */
2008 er.Event.MouseEvent.dwButtonState = dwButtonState;
2009 er.Event.MouseEvent.dwControlKeyState = dwControlKeyState;
2010 er.Event.MouseEvent.dwEventFlags = dwEventFlags;
2011
2013 }
2014 }
2015 else
2016 {
2017 DoDefault = TRUE;
2018 }
2019
2021
2022Quit:
2023 if (!DoDefault)
2024 return 0;
2025
2026 if (msg == WM_MOUSEWHEEL || msg == WM_MOUSEHWHEEL)
2027 {
2028 INT nBar;
2029 WORD sbCode;
2030 // WORD wKeyState = GET_KEYSTATE_WPARAM(wParam);
2031 SHORT wDelta = GET_WHEEL_DELTA_WPARAM(wParam);
2032
2033 if (msg == WM_MOUSEWHEEL)
2034 nBar = SB_VERT;
2035 else // if (msg == WM_MOUSEHWHEEL)
2036 nBar = SB_HORZ;
2037
2038 // NOTE: We currently do not support zooming...
2039 // if (wKeyState & MK_CONTROL)
2040
2041 // FIXME: For some reason our win32k does not set the key states
2042 // when sending WM_MOUSEWHEEL or WM_MOUSEHWHEEL ...
2043 // if (wKeyState & MK_SHIFT)
2045 sbCode = (wDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN);
2046 else
2047 sbCode = (wDelta >= 0 ? SB_LINEUP : SB_LINEDOWN);
2048
2049 OnScroll(GuiData, nBar, sbCode);
2050 }
2051
2052 return DefWindowProcW(GuiData->hWindow, msg, wParam, lParam);
2053}
char TextBuffer[BUFFERLEN]
Definition: combotst.c:45
static COORD PointToCoord(PGUI_CONSOLE_DATA GuiData, LPARAM lParam)
Definition: conwnd.c:1580
#define IS_WORD_SEP(c)
#define KEY_TOGGLED
Definition: conwnd.h:25
short SHORT
Definition: pedump.c:59
union _CHAR_INFO::@3283 Char
WCHAR UnicodeChar
Definition: wincon.h:184
BOOL HackCORE8394IgnoreNextMove
Definition: conwnd.h:75
MOUSE_EVENT_RECORD MouseEvent
Definition: wincon.h:276
DWORD dwControlKeyState
Definition: wincon.h:256
DWORD dwEventFlags
Definition: wincon.h:257
DWORD dwButtonState
Definition: wincon.h:255
COORD dwMousePosition
Definition: wincon.h:254
int32_t INT
Definition: typedefs.h:58
PCHAR_INFO ConioCoordToPointer(PTEXTMODE_SCREEN_BUFFER Buff, ULONG X, ULONG Y)
Definition: text.c:143
#define GetConsoleInputBufferMode(Console)
Definition: conio.h:320
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER
#define CAPSLOCK_ON
Definition: wincon.h:144
#define DOUBLE_CLICK
Definition: wincon.h:169
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define SHIFT_PRESSED
Definition: wincon.h:141
#define CONSOLE_MOUSE_DOWN
Definition: wincon.h:106
#define ENABLE_MOUSE_INPUT
Definition: wincon.h:82
#define FROM_LEFT_4TH_BUTTON_PRESSED
Definition: wincon.h:163
#define NUMLOCK_ON
Definition: wincon.h:142
#define MOUSE_EVENT
Definition: wincon.h:129
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define MOUSE_MOVED
Definition: wincon.h:168
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define FROM_LEFT_2ND_BUTTON_PRESSED
Definition: wincon.h:161
#define ENHANCED_KEY
Definition: wincon.h:145
#define FROM_LEFT_3RD_BUTTON_PRESSED
Definition: wincon.h:162
#define SCROLLLOCK_ON
Definition: wincon.h:143
#define MOUSE_HWHEELED
Definition: wincon.h:172
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
#define FROM_LEFT_1ST_BUTTON_PRESSED
Definition: wincon.h:159
#define RIGHTMOST_BUTTON_PRESSED
Definition: wincon.h:160
#define MOUSE_WHEELED
Definition: wincon.h:170
HWND WINAPI SetCapture(_In_ HWND hWnd)
#define MK_RBUTTON
Definition: winuser.h:2371
#define SB_LINEUP
Definition: winuser.h:564
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
#define KF_EXTENDED
Definition: winuser.h:2449
#define VK_LCONTROL
Definition: winuser.h:2287
#define VK_RCONTROL
Definition: winuser.h:2288
#define MK_MBUTTON
Definition: winuser.h:2374
#define VK_RMENU
Definition: winuser.h:2290
#define SB_PAGEDOWN
Definition: winuser.h:569
#define SB_LINEDOWN
Definition: winuser.h:565
#define MK_LBUTTON
Definition: winuser.h:2370
#define SB_PAGEUP
Definition: winuser.h:568
#define VK_LMENU
Definition: winuser.h:2289

Referenced by ConWndProc().

◆ OnMove()

static VOID OnMove ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 2198 of file conwnd.c.

2199{
2200 RECT rcWnd;
2201
2202 // TODO: Simplify the code.
2203 // See: GuiConsoleNotifyWndProc() PM_CREATE_CONSOLE.
2204
2205 /* Retrieve our real position */
2206 GetWindowRect(GuiData->hWindow, &rcWnd);
2207 GuiData->GuiInfo.WindowOrigin.x = rcWnd.left;
2208 GuiData->GuiInfo.WindowOrigin.y = rcWnd.top;
2209}
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)

Referenced by ConWndProc().

◆ OnNcCreate()

static BOOL OnNcCreate ( HWND  hWnd,
LPCREATESTRUCTW  Create 
)
static

Definition at line 630 of file conwnd.c.

631{
632 PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Create->lpCreateParams;
634
635 if (GuiData == NULL)
636 {
637 DPRINT1("GuiConsoleNcCreate: No GUI data\n");
638 return FALSE;
639 }
640
641 Console = GuiData->Console;
642
643 GuiData->hWindow = hWnd;
644 GuiData->hSysMenu = GetSystemMenu(hWnd, FALSE);
645 GuiData->IsWindowActive = FALSE;
646
647 /* Initialize the fonts */
648 if (!InitFonts(GuiData,
649 GuiData->GuiInfo.FaceName,
650 GuiData->GuiInfo.FontWeight,
651 GuiData->GuiInfo.FontFamily,
652 GuiData->GuiInfo.FontSize,
653 0, FALSE))
654 {
655 /* Reset only the output code page if we don't have a suitable
656 * font for it, possibly falling back to "United States (OEM)". */
657 UINT AltCodePage = GetOEMCP();
658
659 if (AltCodePage == Console->OutputCodePage)
660 AltCodePage = CP_USA;
661
662 DPRINT1("Could not initialize font '%S' for code page %d - Resetting CP to %d\n",
663 GuiData->GuiInfo.FaceName, Console->OutputCodePage, AltCodePage);
664
665 CON_SET_OUTPUT_CP(Console, AltCodePage);
666
667 /* We will use a fallback font if we cannot find
668 * anything for this replacement code page. */
669 if (!InitFonts(GuiData,
670 GuiData->GuiInfo.FaceName,
671 GuiData->GuiInfo.FontWeight,
672 GuiData->GuiInfo.FontFamily,
673 GuiData->GuiInfo.FontSize,
674 0, TRUE))
675 {
676 DPRINT1("Failed to initialize font '%S' for code page %d\n",
677 GuiData->GuiInfo.FaceName, Console->OutputCodePage);
678
679 DPRINT1("GuiConsoleNcCreate: InitFonts failed\n");
680 GuiData->hWindow = NULL;
681 NtSetEvent(GuiData->hGuiInitEvent, NULL);
682 return FALSE;
683 }
684 }
685
686 /* Initialize the terminal framebuffer */
687 GuiData->hMemDC = CreateCompatibleDC(NULL);
688 GuiData->hBitmap = NULL;
689 GuiData->hSysPalette = NULL; /* Original system palette */
690
691 /* Update the icons of the window */
692 if (GuiData->hIcon != ghDefaultIcon)
693 {
694 DefWindowProcW(GuiData->hWindow, WM_SETICON, ICON_BIG , (LPARAM)GuiData->hIcon );
695 DefWindowProcW(GuiData->hWindow, WM_SETICON, ICON_SMALL, (LPARAM)GuiData->hIconSm);
696 }
697
698 // FIXME: Keep these instructions here ? ///////////////////////////////////
699 Console->ActiveBuffer->CursorBlinkOn = TRUE;
700 Console->ActiveBuffer->ForceCursorOff = FALSE;
702
704
705 if (GuiData->IsWindowVisible)
706 {
708 }
709
710 // FIXME: HACK: Potential HACK for CORE-8129; see revision 63595.
711 //CreateSysMenu(GuiData->hWindow);
712
713 DPRINT("OnNcCreate - setting start event\n");
714 NtSetEvent(GuiData->hGuiInitEvent, NULL);
715
716 /* We accept dropped files */
717 DragAcceptFiles(GuiData->hWindow, TRUE);
718
719 return (BOOL)DefWindowProcW(GuiData->hWindow, WM_NCCREATE, 0, (LPARAM)Create);
720}
@ Create
Definition: registry.c:563
#define CONGUI_UPDATE_TIME
Definition: conwnd.c:35
HICON ghDefaultIcon
Definition: conwnd.c:73
BOOL InitFonts(_Inout_ PGUI_CONSOLE_DATA GuiData, _In_reads_or_z_(LF_FACESIZE) PCWSTR FaceName, _In_ ULONG FontWeight, _In_ ULONG FontFamily, _In_ COORD FontSize, _In_opt_ UINT CodePage, _In_ BOOL UseDefaultFallback)
Definition: conwnd.c:521
#define CONGUI_UPDATE_TIMER
Definition: conwnd.c:36
UINT WINAPI GetOEMCP(void)
Definition: locale.c:2060
void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
Definition: shellole.c:522
if(dx< 0)
Definition: linetemp.h:194
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
HMENU hSysMenu
Definition: conwnd.h:77
HANDLE hGuiInitEvent
Definition: conwnd.h:44
HICON hIconSm
Definition: conwnd.h:68
HPALETTE hSysPalette
Definition: conwnd.h:65
WCHAR FaceName[LF_FACESIZE]
Definition: guisettings.h:18
#define ICON_BIG
Definition: tnclass.cpp:51
#define ICON_SMALL
Definition: tnclass.cpp:48
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define CP_USA
Definition: font.h:19
#define CON_SET_OUTPUT_CP(Console, CodePage)
Definition: conio.h:323
LONG_PTR LPARAM
Definition: windef.h:208
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define SetWindowLongPtrW
Definition: winuser.h:5358

Referenced by ConWndProc().

◆ OnNcDestroy()

static LRESULT OnNcDestroy ( HWND  hWnd)
static

Definition at line 1446 of file conwnd.c.

1447{
1449
1450 /* Free the GuiData registration */
1452
1453 /* Reset the system menu back to default and destroy the previous menu */
1455
1456 if (GuiData)
1457 {
1458 if (GuiData->IsWindowVisible)
1460
1461 /* Free the terminal framebuffer */
1462 if (GuiData->hMemDC ) DeleteDC(GuiData->hMemDC);
1463 if (GuiData->hBitmap) DeleteObject(GuiData->hBitmap);
1464 // if (GuiData->hSysPalette) DeleteObject(GuiData->hSysPalette);
1465 DeleteFonts(GuiData);
1466 }
1467
1468 return DefWindowProcW(hWnd, WM_NCDESTROY, 0, 0);
1469}
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)

Referenced by ConWndProc().

◆ OnPaint()

static VOID OnPaint ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 1046 of file conwnd.c.

1047{
1048 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
1049 PAINTSTRUCT ps;
1050 RECT rcPaint;
1051
1052 /* Do nothing if the window is hidden */
1053 if (!GuiData->IsWindowVisible) return;
1054
1055 BeginPaint(GuiData->hWindow, &ps);
1056 if (ps.hdc != NULL &&
1057 ps.rcPaint.left < ps.rcPaint.right &&
1058 ps.rcPaint.top < ps.rcPaint.bottom)
1059 {
1060 EnterCriticalSection(&GuiData->Lock);
1061
1062 /* Compose the current screen-buffer on-memory */
1063 if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
1064 {
1066 GuiData, &ps.rcPaint, &rcPaint);
1067 }
1068 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
1069 {
1071 GuiData, &ps.rcPaint, &rcPaint);
1072 }
1073
1074 /* Send it to screen */
1075 BitBlt(ps.hdc,
1076 ps.rcPaint.left,
1077 ps.rcPaint.top,
1078 rcPaint.right - rcPaint.left,
1079 rcPaint.bottom - rcPaint.top,
1080 GuiData->hMemDC,
1081 rcPaint.left,
1082 rcPaint.top,
1083 SRCCOPY);
1084
1085 /* Draw the selection region if needed */
1087 {
1088 PaintSelectionRect(GuiData, &ps);
1089 }
1090
1091 // TODO: Move cursor display here!
1092
1093 LeaveCriticalSection(&GuiData->Lock);
1094 }
1095 EndPaint(GuiData->hWindow, &ps);
1096
1097 return;
1098}
static VOID PaintSelectionRect(PGUI_CONSOLE_DATA GuiData, PPAINTSTRUCT pps)
Definition: conwnd.c:903
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
VOID GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData, PRECT rcView, PRECT rcFramebuffer)
Definition: text.c:433
CRITICAL_SECTION Lock
Definition: conwnd.h:42
VOID GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData, PRECT rcView, PRECT rcFramebuffer)
Definition: graphics.c:124
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define SRCCOPY
Definition: wingdi.h:333
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)

Referenced by ConWndProc().

◆ OnPaletteChanged()

static VOID OnPaletteChanged ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 1101 of file conwnd.c.

1102{
1103 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
1104
1105 /* Do nothing if the window is hidden */
1106 if (!GuiData->IsWindowVisible) return;
1107
1108 // See WM_PALETTECHANGED message
1109 // if ((HWND)wParam == hWnd) break;
1110
1111 // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
1112 if (ActiveBuffer->PaletteHandle)
1113 {
1114 DPRINT("WM_PALETTECHANGED changing palette\n");
1115
1116 /* Specify the use of the system palette for the framebuffer */
1117 SetSystemPaletteUse(GuiData->hMemDC, ActiveBuffer->PaletteUsage);
1118
1119 /* Realize the (logical) palette */
1120 RealizePalette(GuiData->hMemDC);
1121 }
1122}
HPALETTE PaletteHandle
Definition: conio.h:78
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
UINT WINAPI SetSystemPaletteUse(_In_ HDC, _In_ UINT)

Referenced by ConWndProc().

◆ OnScroll()

static VOID OnScroll ( PGUI_CONSOLE_DATA  GuiData,
INT  nBar,
WORD  sbCode 
)
static

Definition at line 1472 of file conwnd.c.

1473{
1474 PCONSRV_CONSOLE Console = GuiData->Console;
1476 SCROLLINFO sInfo;
1477 INT oldPos, Maximum;
1478 PSHORT pOriginXY;
1479
1480 ASSERT(nBar == SB_HORZ || nBar == SB_VERT);
1481
1483
1484 Buff = GuiData->ActiveBuffer;
1485
1486 if (nBar == SB_HORZ)
1487 {
1488 Maximum = Buff->ScreenBufferSize.X - Buff->ViewSize.X;
1489 pOriginXY = &Buff->ViewOrigin.X;
1490 }
1491 else // if (nBar == SB_VERT)
1492 {
1493 Maximum = Buff->ScreenBufferSize.Y - Buff->ViewSize.Y;
1494 pOriginXY = &Buff->ViewOrigin.Y;
1495 }
1496
1497 /* Set scrollbar sizes */
1498 sInfo.cbSize = sizeof(sInfo);
1500
1501 if (!GetScrollInfo(GuiData->hWindow, nBar, &sInfo)) goto Quit;
1502
1503 oldPos = sInfo.nPos;
1504
1505 switch (sbCode)
1506 {
1507 case SB_LINEUP: // SB_LINELEFT:
1508 sInfo.nPos--;
1509 break;
1510
1511 case SB_LINEDOWN: // SB_LINERIGHT:
1512 sInfo.nPos++;
1513 break;
1514
1515 case SB_PAGEUP: // SB_PAGELEFT:
1516 sInfo.nPos -= sInfo.nPage;
1517 break;
1518
1519 case SB_PAGEDOWN: // SB_PAGERIGHT:
1520 sInfo.nPos += sInfo.nPage;
1521 break;
1522
1523 case SB_THUMBTRACK:
1524 sInfo.nPos = sInfo.nTrackPos;
1526 break;
1527
1528 case SB_THUMBPOSITION:
1529 sInfo.nPos = sInfo.nTrackPos;
1531 break;
1532
1533 case SB_TOP: // SB_LEFT:
1534 sInfo.nPos = sInfo.nMin;
1535 break;
1536
1537 case SB_BOTTOM: // SB_RIGHT:
1538 sInfo.nPos = sInfo.nMax;
1539 break;
1540
1541 default:
1542 break;
1543 }
1544
1545 sInfo.nPos = min(max(sInfo.nPos, 0), Maximum);
1546
1547 if (oldPos != sInfo.nPos)
1548 {
1549 USHORT OldX = Buff->ViewOrigin.X;
1550 USHORT OldY = Buff->ViewOrigin.Y;
1551 UINT WidthUnit, HeightUnit;
1552
1553 /* We now modify Buff->ViewOrigin */
1554 *pOriginXY = sInfo.nPos;
1555
1556 GetScreenBufferSizeUnits(Buff, GuiData, &WidthUnit, &HeightUnit);
1557
1558 ScrollWindowEx(GuiData->hWindow,
1559 (OldX - Buff->ViewOrigin.X) * WidthUnit ,
1560 (OldY - Buff->ViewOrigin.Y) * HeightUnit,
1561 NULL,
1562 NULL,
1563 NULL,
1564 NULL,
1566
1567 sInfo.fMask = SIF_POS;
1568 SetScrollInfo(GuiData->hWindow, nBar, &sInfo, TRUE);
1569
1570 UpdateWindow(GuiData->hWindow);
1571 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1572 }
1573
1574Quit:
1576 return;
1577}
#define PAUSED_FROM_SCROLLBAR
Definition: conio_winsrv.h:110
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
unsigned short USHORT
Definition: pedump.c:61
int16_t * PSHORT
Definition: typedefs.h:55
VOID ConioUnpause(PCONSRV_CONSOLE Console, UCHAR Flags)
Definition: console.c:866
VOID ConioPause(PCONSRV_CONSOLE Console, UCHAR Flags)
Definition: console.c:859
#define SB_THUMBTRACK
Definition: winuser.h:573
#define SIF_RANGE
Definition: winuser.h:1238
#define SB_BOTTOM
Definition: winuser.h:577
#define SW_INVALIDATE
Definition: winuser.h:2582
#define SIF_PAGE
Definition: winuser.h:1236
#define SIF_TRACKPOS
Definition: winuser.h:1240
BOOL WINAPI UpdateWindow(_In_ HWND)
#define SB_TOP
Definition: winuser.h:578
#define SIF_POS
Definition: winuser.h:1237
int WINAPI SetScrollInfo(_In_ HWND, _In_ int, _In_ LPCSCROLLINFO, _In_ BOOL)
BOOL WINAPI GetScrollInfo(_In_ HWND, _In_ int, _Inout_ LPSCROLLINFO)
int WINAPI ScrollWindowEx(_In_ HWND, _In_ int, _In_ int, _In_opt_ LPCRECT, _In_opt_ LPCRECT, _In_opt_ HRGN, _Out_opt_ LPRECT, _In_ UINT)
#define SB_THUMBPOSITION
Definition: winuser.h:572

Referenced by ConWndProc(), and OnMouse().

◆ OnSize()

static VOID OnSize ( PGUI_CONSOLE_DATA  GuiData,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 2132 of file conwnd.c.

2133{
2134 PCONSRV_CONSOLE Console = GuiData->Console;
2135
2136 /* Do nothing if the window is hidden */
2137 if (!GuiData->IsWindowVisible || IsIconic(GuiData->hWindow)) return;
2138
2140
2141 if (!GuiData->WindowSizeLock &&
2143 {
2144 PCONSOLE_SCREEN_BUFFER Buff = GuiData->ActiveBuffer;
2145 DWORD windx, windy, charx, chary;
2146 UINT WidthUnit, HeightUnit;
2147
2148 GetScreenBufferSizeUnits(Buff, GuiData, &WidthUnit, &HeightUnit);
2149
2150 GuiData->WindowSizeLock = TRUE;
2151
2152 windx = LOWORD(lParam);
2153 windy = HIWORD(lParam);
2154
2155 /* Compensate for existing scroll bars (because lParam values do not accommodate scroll bar) */
2156 if (Buff->ViewSize.X < Buff->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // Window currently has a horizontal scrollbar
2157 if (Buff->ViewSize.Y < Buff->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // Window currently has a vertical scrollbar
2158
2159 charx = windx / (int)WidthUnit ;
2160 chary = windy / (int)HeightUnit;
2161
2162 /* Character alignment (round size up or down) */
2163 if ((windx % WidthUnit ) >= (WidthUnit / 2)) ++charx;
2164 if ((windy % HeightUnit) >= (HeightUnit / 2)) ++chary;
2165
2166 /* Compensate for added scroll bars in window */
2167 if (Buff->ViewSize.X < Buff->ScreenBufferSize.X) windy -= GetSystemMetrics(SM_CYHSCROLL); // Window will have a horizontal scroll bar
2168 if (Buff->ViewSize.Y < Buff->ScreenBufferSize.Y) windx -= GetSystemMetrics(SM_CXVSCROLL); // Window will have a vertical scroll bar
2169
2170 charx = windx / (int)WidthUnit ;
2171 chary = windy / (int)HeightUnit;
2172
2173 /* Character alignment (round size up or down) */
2174 if ((windx % WidthUnit ) >= (WidthUnit / 2)) ++charx;
2175 if ((windy % HeightUnit) >= (HeightUnit / 2)) ++chary;
2176
2177 /* Resize window */
2178 if ((charx != Buff->ViewSize.X) || (chary != Buff->ViewSize.Y))
2179 {
2180 Buff->ViewSize.X = (charx <= (DWORD)Buff->ScreenBufferSize.X) ? charx : Buff->ScreenBufferSize.X;
2181 Buff->ViewSize.Y = (chary <= (DWORD)Buff->ScreenBufferSize.Y) ? chary : Buff->ScreenBufferSize.Y;
2182 }
2183
2184 ResizeConWnd(GuiData, WidthUnit, HeightUnit);
2185
2186 /* Adjust the start of the visible area if we are attempting to show nonexistent areas */
2187 if ((Buff->ScreenBufferSize.X - Buff->ViewOrigin.X) < Buff->ViewSize.X) Buff->ViewOrigin.X = Buff->ScreenBufferSize.X - Buff->ViewSize.X;
2188 if ((Buff->ScreenBufferSize.Y - Buff->ViewOrigin.Y) < Buff->ViewSize.Y) Buff->ViewOrigin.Y = Buff->ScreenBufferSize.Y - Buff->ViewSize.Y;
2189 InvalidateRect(GuiData->hWindow, NULL, TRUE);
2190
2191 GuiData->WindowSizeLock = FALSE;
2192 }
2193
2195}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define DWORD
Definition: nt_native.h:44
#define SIZE_MINIMIZED
Definition: winuser.h:2509
BOOL WINAPI IsIconic(_In_ HWND)
#define SIZE_MAXIMIZED
Definition: winuser.h:2510
#define SIZE_RESTORED
Definition: winuser.h:2508
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)

Referenced by ConWndProc().

◆ OnTimer()

static VOID OnTimer ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 1313 of file conwnd.c.

1314{
1315 PCONSRV_CONSOLE Console = GuiData->Console;
1317
1318 /* Do nothing if the window is hidden */
1319 if (!GuiData->IsWindowVisible) return;
1320
1322
1324
1325 Buff = GuiData->ActiveBuffer;
1326
1327 if (GetType(Buff) == TEXTMODE_BUFFER)
1328 {
1329 /* Repaint the caret */
1330 if (GuiData->IsWindowActive || Buff->CursorBlinkOn)
1331 {
1332 InvalidateCell(GuiData, Buff->CursorPosition.X, Buff->CursorPosition.Y);
1333 Buff->CursorBlinkOn = !Buff->CursorBlinkOn;
1334 }
1335
1336 if ((GuiData->OldCursor.x != Buff->CursorPosition.X) ||
1337 (GuiData->OldCursor.y != Buff->CursorPosition.Y))
1338 {
1339 SCROLLINFO sInfo;
1340 int OldScrollX = -1, OldScrollY = -1;
1341 int NewScrollX = -1, NewScrollY = -1;
1342
1343 sInfo.cbSize = sizeof(sInfo);
1344 sInfo.fMask = SIF_POS;
1345 // Capture the original position of the scroll bars and save them.
1346 if (GetScrollInfo(GuiData->hWindow, SB_HORZ, &sInfo)) OldScrollX = sInfo.nPos;
1347 if (GetScrollInfo(GuiData->hWindow, SB_VERT, &sInfo)) OldScrollY = sInfo.nPos;
1348
1349 // If we successfully got the info for the horizontal scrollbar
1350 if (OldScrollX >= 0)
1351 {
1352 if ((Buff->CursorPosition.X < Buff->ViewOrigin.X) ||
1353 (Buff->CursorPosition.X >= (Buff->ViewOrigin.X + Buff->ViewSize.X)))
1354 {
1355 // Handle the horizontal scroll bar
1356 if (Buff->CursorPosition.X >= Buff->ViewSize.X)
1357 NewScrollX = Buff->CursorPosition.X - Buff->ViewSize.X + 1;
1358 else
1359 NewScrollX = 0;
1360 }
1361 else
1362 {
1363 NewScrollX = OldScrollX;
1364 }
1365 }
1366 // If we successfully got the info for the vertical scrollbar
1367 if (OldScrollY >= 0)
1368 {
1369 if ((Buff->CursorPosition.Y < Buff->ViewOrigin.Y) ||
1370 (Buff->CursorPosition.Y >= (Buff->ViewOrigin.Y + Buff->ViewSize.Y)))
1371 {
1372 // Handle the vertical scroll bar
1373 if (Buff->CursorPosition.Y >= Buff->ViewSize.Y)
1374 NewScrollY = Buff->CursorPosition.Y - Buff->ViewSize.Y + 1;
1375 else
1376 NewScrollY = 0;
1377 }
1378 else
1379 {
1380 NewScrollY = OldScrollY;
1381 }
1382 }
1383
1384 // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area
1385 // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar
1386 // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling)
1387 // and their associated scrollbar is left alone.
1388 if ((OldScrollX != NewScrollX) || (OldScrollY != NewScrollY))
1389 {
1390 Buff->ViewOrigin.X = NewScrollX;
1391 Buff->ViewOrigin.Y = NewScrollY;
1392 ScrollWindowEx(GuiData->hWindow,
1393 (OldScrollX - NewScrollX) * GuiData->CharWidth,
1394 (OldScrollY - NewScrollY) * GuiData->CharHeight,
1395 NULL,
1396 NULL,
1397 NULL,
1398 NULL,
1400 if (NewScrollX >= 0)
1401 {
1402 sInfo.nPos = NewScrollX;
1403 SetScrollInfo(GuiData->hWindow, SB_HORZ, &sInfo, TRUE);
1404 }
1405 if (NewScrollY >= 0)
1406 {
1407 sInfo.nPos = NewScrollY;
1408 SetScrollInfo(GuiData->hWindow, SB_VERT, &sInfo, TRUE);
1409 }
1410 UpdateWindow(GuiData->hWindow);
1411 // InvalidateRect(GuiData->hWindow, NULL, FALSE);
1412 GuiData->OldCursor.x = Buff->CursorPosition.X;
1413 GuiData->OldCursor.y = Buff->CursorPosition.Y;
1414 }
1415 }
1416 }
1417 else /* if (GetType(Buff) == GRAPHICS_BUFFER) */
1418 {
1419 }
1420
1422}
VOID InvalidateCell(PGUI_CONSOLE_DATA GuiData, SHORT x, SHORT y)
Definition: guiterm.c:88
#define CURSOR_BLINK_TIME
Definition: conwnd.c:38
COORD CursorPosition
Definition: conio.h:71
BOOLEAN CursorBlinkOn
Definition: conio.h:72
UINT CharWidth
Definition: conwnd.h:87
POINT OldCursor
Definition: conwnd.h:55
UINT CharHeight
Definition: conwnd.h:88

Referenced by ConWndProc().

◆ PaintSelectionRect()

static VOID PaintSelectionRect ( PGUI_CONSOLE_DATA  GuiData,
PPAINTSTRUCT  pps 
)
static

Definition at line 903 of file conwnd.c.

904{
905 HRGN rgnPaint = CreateRectRgnIndirect(&pps->rcPaint);
906 HRGN rgnSel = CreateSelectionRgn(GuiData, GuiData->LineSelection,
908 &GuiData->Selection.srSelection);
909
910 /* Invert the selection */
911
912 int ErrorCode = CombineRgn(rgnPaint, rgnPaint, rgnSel, RGN_AND);
913 if (ErrorCode != ERROR && ErrorCode != NULLREGION)
914 {
915 InvertRgn(pps->hdc, rgnPaint);
916 }
917
918 DeleteObject(rgnSel);
919 DeleteObject(rgnPaint);
920}
static HRGN CreateSelectionRgn(PGUI_CONSOLE_DATA GuiData, BOOL LineSelection, PCOORD SelectionAnchor, PSMALL_RECT SmallRect)
Definition: conwnd.c:813
#define ERROR(name)
Definition: error_private.h:53
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
SMALL_RECT srSelection
Definition: wincon.h:210
BOOL LineSelection
Definition: conwnd.h:95
#define NULLREGION
Definition: wingdi.h:361
BOOL WINAPI InvertRgn(_In_ HDC, _In_ HRGN)
Definition: painting.c:229
#define RGN_AND
Definition: wingdi.h:356

Referenced by OnPaint().

◆ Paste()

static VOID Paste ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 2080 of file conwnd.c.

2081{
2082 if (OpenClipboard(GuiData->hWindow))
2083 {
2085
2087 {
2089 }
2090 else /* if (GetType(Buffer) == GRAPHICS_BUFFER) */
2091 {
2093 }
2094
2096 }
2097}
VOID GuiPasteToTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
Definition: text.c:339
VOID GuiPasteToGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer, PGUI_CONSOLE_DATA GuiData)
Definition: graphics.c:111

Referenced by DECLARE_INTERFACE_(), OnCommand(), OnMouse(), and CConsole::ReadLine().

◆ PointToCoord()

static COORD PointToCoord ( PGUI_CONSOLE_DATA  GuiData,
LPARAM  lParam 
)
static

Definition at line 1580 of file conwnd.c.

1581{
1583 COORD Coord;
1584 UINT WidthUnit, HeightUnit;
1585
1586 GetScreenBufferSizeUnits(Buffer, GuiData, &WidthUnit, &HeightUnit);
1587
1588 Coord.X = Buffer->ViewOrigin.X + ((SHORT)LOWORD(lParam) / (int)WidthUnit );
1589 Coord.Y = Buffer->ViewOrigin.Y + ((SHORT)HIWORD(lParam) / (int)HeightUnit);
1590
1591 /* Clip coordinate to ensure it's inside buffer */
1592 if (Coord.X < 0)
1593 Coord.X = 0;
1594 else if (Coord.X >= Buffer->ScreenBufferSize.X)
1595 Coord.X = Buffer->ScreenBufferSize.X - 1;
1596
1597 if (Coord.Y < 0)
1598 Coord.Y = 0;
1599 else if (Coord.Y >= Buffer->ScreenBufferSize.Y)
1600 Coord.Y = Buffer->ScreenBufferSize.Y - 1;
1601
1602 return Coord;
1603}

Referenced by OnMouse().

◆ RegisterConWndClass()

BOOLEAN RegisterConWndClass ( IN HINSTANCE  hInstance)

Definition at line 136 of file conwnd.c.

137{
139 ATOM WndClassAtom;
140
146 LR_SHARED);
152 LR_SHARED);
154
155 WndClass.cbSize = sizeof(WNDCLASSEXW);
156 WndClass.lpszClassName = GUI_CONWND_CLASS;
157 WndClass.lpfnWndProc = ConWndProc;
158 WndClass.style = CS_DBLCLKS /* | CS_HREDRAW | CS_VREDRAW */;
159 WndClass.hInstance = hInstance;
160 WndClass.hIcon = ghDefaultIcon;
161 WndClass.hIconSm = ghDefaultIconSm;
162 WndClass.hCursor = ghDefaultCursor;
163 WndClass.hbrBackground = NULL;
164 WndClass.lpszMenuName = NULL;
165 WndClass.cbClsExtra = 0;
166 WndClass.cbWndExtra = GWLP_CONWND_ALLOC;
167
168 WndClassAtom = RegisterClassExW(&WndClass);
169 if (WndClassAtom == 0)
170 {
171 DPRINT1("Failed to register GUI console class\n");
172 }
173 else
174 {
175 NtUserConsoleControl(GuiConsoleWndClassAtom, &WndClassAtom, sizeof(ATOM));
176 }
177
178 return (WndClassAtom != 0);
179}
#define IDI_TERMINAL
Definition: resource.h:44
WCHAR WndClass[]
Definition: capicon.c:23
HINSTANCE hInstance
Definition: charmap.c:19
HCURSOR ghDefaultCursor
Definition: conwnd.c:75
static LRESULT CALLBACK ConWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: conwnd.c:2278
#define GWLP_CONWND_ALLOC
Definition: conwnd.c:43
HICON ghDefaultIconSm
Definition: conwnd.c:74
#define GUI_CONWND_CLASS
Definition: conwnd.h:15
WORD ATOM
Definition: dimm.idl:113
@ GuiConsoleWndClassAtom
Definition: ntuser.h:1799
NTSTATUS APIENTRY NtUserConsoleControl(IN CONSOLECONTROL ConsoleCtrl, IN PVOID ConsoleCtrlInfo, IN ULONG ConsoleCtrlInfoLength)
Definition: console.c:14
#define IMAGE_ICON
Definition: winuser.h:212
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2255
#define IDC_ARROW
Definition: winuser.h:687
#define SM_CYSMICON
Definition: winuser.h:1016
#define CS_DBLCLKS
Definition: winuser.h:651
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2157
#define SM_CXSMICON
Definition: winuser.h:1015
#define SM_CYICON
Definition: winuser.h:976
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
#define LR_SHARED
Definition: winuser.h:1103
struct _WNDCLASSEXW WNDCLASSEXW
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define SM_CXICON
Definition: winuser.h:975

Referenced by GuiInit().

◆ ResizeConWnd()

static VOID ResizeConWnd ( PGUI_CONSOLE_DATA  GuiData,
DWORD  WidthUnit,
DWORD  HeightUnit 
)
static

Definition at line 428 of file conwnd.c.

429{
430 PCONSOLE_SCREEN_BUFFER Buff = GuiData->ActiveBuffer;
431 SCROLLINFO sInfo;
432
434
435 Width = Buff->ViewSize.X * WidthUnit +
437 Height = Buff->ViewSize.Y * HeightUnit +
439
440 /* Set scrollbar sizes */
441 sInfo.cbSize = sizeof(sInfo);
442 sInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
443 sInfo.nMin = 0;
444 if (Buff->ScreenBufferSize.Y > Buff->ViewSize.Y)
445 {
446 sInfo.nMax = Buff->ScreenBufferSize.Y - 1;
447 sInfo.nPage = Buff->ViewSize.Y;
448 sInfo.nPos = Buff->ViewOrigin.Y;
449 SetScrollInfo(GuiData->hWindow, SB_VERT, &sInfo, TRUE);
451 ShowScrollBar(GuiData->hWindow, SB_VERT, TRUE);
452 }
453 else
454 {
456 }
457
458 if (Buff->ScreenBufferSize.X > Buff->ViewSize.X)
459 {
460 sInfo.nMax = Buff->ScreenBufferSize.X - 1;
461 sInfo.nPage = Buff->ViewSize.X;
462 sInfo.nPos = Buff->ViewOrigin.X;
463 SetScrollInfo(GuiData->hWindow, SB_HORZ, &sInfo, TRUE);
465 ShowScrollBar(GuiData->hWindow, SB_HORZ, TRUE);
466 }
467 else
468 {
470 }
471
472 /* Resize the window */
473 SetWindowPos(GuiData->hWindow, NULL, 0, 0, Width, Height,
475 // NOTE: The SWP_NOCOPYBITS flag can be replaced by a subsequent call
476 // to: InvalidateRect(GuiData->hWindow, NULL, TRUE);
477}
#define SWP_NOACTIVATE
Definition: winuser.h:1245
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOMOVE
Definition: winuser.h:1247
#define SWP_NOCOPYBITS
Definition: winuser.h:1246
BOOL WINAPI ShowScrollBar(_In_ HWND, _In_ int, _In_ BOOL)
#define SWP_NOZORDER
Definition: winuser.h:1250

Referenced by ConWndProc(), and OnSize().

◆ SelectAll()

static VOID SelectAll ( PGUI_CONSOLE_DATA  GuiData)
static

Definition at line 315 of file conwnd.c.

316{
317 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
318 COORD SelectionAnchor;
319
320 /* Clear the old selection */
322
323 /*
324 * The selection area extends to the whole screen buffer's width.
325 */
326 SelectionAnchor.X = SelectionAnchor.Y = 0;
327 GuiData->dwSelectionCursor.X = ActiveBuffer->ScreenBufferSize.X - 1;
328
329 /*
330 * Determine whether the selection must extend to just some part
331 * (for text-mode screen buffers) or to all of the screen buffer's
332 * height (for graphics ones).
333 */
334 if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
335 {
336 /*
337 * We select all the characters from the first line
338 * to the line where the cursor is positioned.
339 */
340 GuiData->dwSelectionCursor.Y = ActiveBuffer->CursorPosition.Y;
341 }
342 else /* if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) */
343 {
344 /*
345 * We select all the screen buffer area.
346 */
347 GuiData->dwSelectionCursor.Y = ActiveBuffer->ScreenBufferSize.Y - 1;
348 }
349
350 /* Restart a new selection */
352 UpdateSelection(GuiData, &SelectionAnchor, &GuiData->dwSelectionCursor);
353}

Referenced by OnCommand().

◆ SendMenuEvent()

static VOID SendMenuEvent ( PCONSRV_CONSOLE  Console,
UINT  CmdId 
)
static

Definition at line 274 of file conwnd.c.

275{
276 INPUT_RECORD er;
277
278 DPRINT("Menu item ID: %d\n", CmdId);
279
281
282 /* Send a menu event */
284 er.Event.MenuEvent.dwCommandId = CmdId;
286
288}
MENU_EVENT_RECORD MenuEvent
Definition: wincon.h:278
#define MENU_EVENT
Definition: wincon.h:131

Referenced by ConWndProc(), and OnCommand().

◆ SetConWndConsoleLeaderCID()

VOID SetConWndConsoleLeaderCID ( IN PGUI_CONSOLE_DATA  GuiData)

Definition at line 48 of file conwnd.c.

49{
50 PCONSOLE_PROCESS_DATA ProcessData;
51
52 ProcessData = ConSrvGetConsoleLeaderProcess(GuiData->Console);
53
54 ASSERT(ProcessData != NULL);
55 DPRINT("ProcessData: %p, ProcessData->Process %p.\n", ProcessData, ProcessData->Process);
56
57 if (ProcessData->Process)
58 {
59 CLIENT_ID ConsoleLeaderCID = ProcessData->Process->ClientId;
61 (LONG_PTR)(ConsoleLeaderCID.UniqueProcess));
63 (LONG_PTR)(ConsoleLeaderCID.UniqueThread));
64 }
65 else
66 {
67 SetWindowLongPtrW(GuiData->hWindow, GWLP_CONSOLE_LEADER_PID, 0);
68 SetWindowLongPtrW(GuiData->hWindow, GWLP_CONSOLE_LEADER_TID, 0);
69 }
70}
#define GWLP_CONSOLE_LEADER_PID
Definition: conwnd.c:44
#define GWLP_CONSOLE_LEADER_TID
Definition: conwnd.c:45
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
PCSR_PROCESS Process
Definition: consrv.h:43
CLIENT_ID ClientId
Definition: csrsrv.h:38
PCONSOLE_PROCESS_DATA NTAPI ConSrvGetConsoleLeaderProcess(IN PCONSRV_CONSOLE Console)
Definition: console.c:1363

Referenced by GuiRefreshInternalInfo().

◆ UnRegisterConWndClass()

BOOLEAN UnRegisterConWndClass ( HINSTANCE  hInstance)

Definition at line 182 of file conwnd.c.

183{
185}
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)

◆ UpdateSelection()

static VOID UpdateSelection ( PGUI_CONSOLE_DATA  GuiData,
PCOORD SelectionAnchor  OPTIONAL,
PCOORD  coord 
)
static

Definition at line 923 of file conwnd.c.

926{
928 HRGN oldRgn = CreateSelectionRgn(GuiData, GuiData->LineSelection,
930 &GuiData->Selection.srSelection);
931
932 /* Update the anchor if needed (use the old one if NULL) */
933 if (SelectionAnchor)
934 GuiData->Selection.dwSelectionAnchor = *SelectionAnchor;
935
936 // TODO: Scroll buffer to bring 'coord' into view
937
938 if (coord != NULL)
939 {
940 SMALL_RECT rc;
941 HRGN newRgn;
942
943 /*
944 * Pressing the Control key while selecting text, allows us to enter
945 * into line-selection mode, the selection mode of *nix terminals.
946 */
947 BOOL OldLineSel = GuiData->LineSelection;
949
950 /* Exchange left/top with right/bottom if required */
951 rc.Left = min(GuiData->Selection.dwSelectionAnchor.X, coord->X);
952 rc.Top = min(GuiData->Selection.dwSelectionAnchor.Y, coord->Y);
953 rc.Right = max(GuiData->Selection.dwSelectionAnchor.X, coord->X);
954 rc.Bottom = max(GuiData->Selection.dwSelectionAnchor.Y, coord->Y);
955
956 newRgn = CreateSelectionRgn(GuiData, GuiData->LineSelection,
958 &rc);
959
961 {
962 if (OldLineSel != GuiData->LineSelection ||
963 memcmp(&rc, &GuiData->Selection.srSelection, sizeof(SMALL_RECT)) != 0)
964 {
965 /* Calculate the region that needs to be updated */
966 if (oldRgn && newRgn && CombineRgn(newRgn, newRgn, oldRgn, RGN_XOR) != ERROR)
967 {
968 InvalidateRgn(GuiData->hWindow, newRgn, FALSE);
969 }
970 }
971 }
972 else
973 {
974 InvalidateRgn(GuiData->hWindow, newRgn, FALSE);
975 }
976
977 DeleteObject(newRgn);
978
980 GuiData->Selection.srSelection = rc;
981 GuiData->dwSelectionCursor = *coord;
982
983 if ((GuiData->Selection.dwFlags & CONSOLE_SELECTION_IN_PROGRESS) == 0)
984 {
985 LPWSTR SelTypeStr = NULL , WindowTitle = NULL;
986 SIZE_T SelTypeStrLength = 0, Length = 0;
987
988 /* Clear the old selection */
990 {
991 InvalidateRgn(GuiData->hWindow, oldRgn, FALSE);
992 }
993
994 /*
995 * When passing a zero-length buffer size, LoadString(...) returns
996 * a read-only pointer buffer to the program's resource string.
997 */
998 SelTypeStrLength =
1002 (LPWSTR)&SelTypeStr, 0);
1003
1004 /*
1005 * Prepend the selection type string to the current console title
1006 * if we succeeded in retrieving a valid localized string.
1007 */
1008 if (SelTypeStr)
1009 {
1010 // 3 for " - " and 1 for NULL
1011 Length = Console->Title.Length + (SelTypeStrLength + 3 + 1) * sizeof(WCHAR);
1012 WindowTitle = ConsoleAllocHeap(0, Length);
1013
1014 wcsncpy(WindowTitle, SelTypeStr, SelTypeStrLength);
1015 WindowTitle[SelTypeStrLength] = UNICODE_NULL;
1016 wcscat(WindowTitle, L" - ");
1017 wcscat(WindowTitle, Console->Title.Buffer);
1018
1019 SetWindowTextW(GuiData->hWindow, WindowTitle);
1020 ConsoleFreeHeap(WindowTitle);
1021 }
1022
1025 }
1026 }
1027 else
1028 {
1029 /* Clear the selection */
1031 {
1032 InvalidateRgn(GuiData->hWindow, oldRgn, FALSE);
1033 }
1034
1037
1038 /* Restore the console title */
1039 SetWindowTextW(GuiData->hWindow, Console->Title.Buffer);
1040 }
1041
1042 DeleteObject(oldRgn);
1043}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define PAUSED_FROM_SELECTION
Definition: conio_winsrv.h:111
GLuint coord
Definition: glext.h:9511
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IDS_SELECT_TITLE
Definition: resource.h:32
#define IDS_MARK_TITLE
Definition: resource.h:31
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
BOOL WINAPI InvalidateRgn(_In_ HWND, _In_opt_ HRGN, _In_ BOOL)

Referenced by Copy(), Mark(), OnKey(), OnMouse(), and SelectAll().

Variable Documentation

◆ ghDefaultCursor

HCURSOR ghDefaultCursor = NULL

Definition at line 75 of file conwnd.c.

Referenced by GuiInitFrontEnd(), GuiSetMouseCursor(), and RegisterConWndClass().

◆ ghDefaultIcon

HICON ghDefaultIcon = NULL

◆ ghDefaultIconSm

HICON ghDefaultIconSm = NULL

Definition at line 74 of file conwnd.c.

Referenced by GuiChangeIcon(), GuiDeinitFrontEnd(), GuiInitFrontEnd(), and RegisterConWndClass().

◆ GuiConsoleEditMenuItems

const GUICONSOLE_MENUITEM GuiConsoleEditMenuItems[]
static
Initial value:
=
{
{ 0, NULL, 0 }
}
#define IDS_COPY
Definition: resource.h:131
#define IDS_PASTE
Definition: shresdef.h:231
#define IDS_MARK
Definition: resource.h:22
#define IDS_FIND
Definition: resource.h:27
#define IDS_SCROLL
Definition: resource.h:26
#define IDS_SELECTALL
Definition: resource.h:25

Definition at line 84 of file conwnd.c.

Referenced by ConWndProc().

◆ GuiConsoleMainMenuItems

const GUICONSOLE_MENUITEM GuiConsoleMainMenuItems[]
static
Initial value:
=
{
{ 0, NULL, 0 }
}
#define IDS_PROPERTIES
Definition: resource.h:102
#define IDS_EDIT
Definition: resource.h:21
#define IDS_DEFAULTS
Definition: resource.h:28

Definition at line 96 of file conwnd.c.

Referenced by CreateSysMenu().

◆ s_Colors

const COLORREF s_Colors[16]
Initial value:
=
{
RGB(0, 0, 0),
RGB(0, 0, 128),
RGB(0, 128, 0),
RGB(0, 128, 128),
RGB(128, 0, 0),
RGB(128, 0, 128),
RGB(128, 128, 0),
RGB(192, 192, 192),
RGB(128, 128, 128),
RGB(0, 0, 255),
RGB(0, 255, 0),
RGB(0, 255, 255),
RGB(255, 0, 0),
RGB(255, 0, 255),
RGB(255, 255, 0),
}
#define RGB(r, g, b)
Definition: precomp.h:71

Definition at line 109 of file conwnd.c.