ReactOS 0.4.16-dev-319-g6cf4263
console.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <wingdi.h>
#include <winnls.h>
#include <winreg.h>
#include <winuser.h>
#include <commctrl.h>
#include <cpl.h>
#include <strsafe.h>
#include "resource.h"
#include "concfg.h"
Include dependency graph for console.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _FONT_PREVIEW
 
struct  _LIST_CTL
 

Macros

#define WIN32_NO_STATUS
 
#define EnableDlgItem(hDlg, nID, bEnable)    EnableWindow(GetDlgItem((hDlg), (nID)), (bEnable))
 
#define ResetFontPreview(Preview)    UpdateFontPreview((Preview), NULL, 0, 0)
 

Typedefs

typedef enum _TEXT_TYPE TEXT_TYPE
 
typedef struct _FONT_PREVIEW FONT_PREVIEW
 
typedef INT(* PLIST_GETCOUNT) (IN struct _LIST_CTL *ListCtl)
 
typedef ULONG_PTR(* PLIST_GETDATA) (IN struct _LIST_CTL *ListCtl, IN INT Index)
 
typedef struct _LIST_CTL LIST_CTL
 
typedef struct _LIST_CTLPLIST_CTL
 

Enumerations

enum  _TEXT_TYPE { Screen , Popup }
 

Functions

VOID ApplyConsoleInfo (HWND hwndDlg)
 
VOID RefreshFontPreview (IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
 
VOID UpdateFontPreview (IN FONT_PREVIEW *Preview, IN HFONT hFont, IN UINT CharWidth, IN UINT CharHeight)
 
BOOL RegisterWinPrevClass (IN HINSTANCE hInstance)
 
BOOL UnRegisterWinPrevClass (IN HINSTANCE hInstance)
 
VOID PaintText (IN LPDRAWITEMSTRUCT drawItem, IN PCONSOLE_STATE_INFO pConInfo, IN TEXT_TYPE TextMode)
 
UINT BisectListSortedByValueEx (IN PLIST_CTL ListCtl, IN ULONG_PTR Value, IN UINT itemStart, IN UINT itemEnd, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
 
UINT BisectListSortedByValue (IN PLIST_CTL ListCtl, IN ULONG_PTR Value, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
 

Variables

HINSTANCE hApplet
 
PCONSOLE_STATE_INFO ConInfo
 
FONT_PREVIEW FontPreview
 

Macro Definition Documentation

◆ EnableDlgItem

#define EnableDlgItem (   hDlg,
  nID,
  bEnable 
)     EnableWindow(GetDlgItem((hDlg), (nID)), (bEnable))

Definition at line 26 of file console.h.

◆ ResetFontPreview

#define ResetFontPreview (   Preview)     UpdateFontPreview((Preview), NULL, 0, 0)

Definition at line 65 of file console.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file console.h.

Typedef Documentation

◆ FONT_PREVIEW

◆ LIST_CTL

◆ PLIST_CTL

◆ PLIST_GETCOUNT

typedef INT(* PLIST_GETCOUNT) (IN struct _LIST_CTL *ListCtl)

Definition at line 88 of file console.h.

◆ PLIST_GETDATA

typedef ULONG_PTR(* PLIST_GETDATA) (IN struct _LIST_CTL *ListCtl, IN INT Index)

Definition at line 89 of file console.h.

◆ TEXT_TYPE

Enumeration Type Documentation

◆ _TEXT_TYPE

Enumerator
Screen 
Popup 

Definition at line 32 of file console.h.

33{
34 Screen,
35 Popup
36} TEXT_TYPE;
@ Screen
Definition: console.h:34
@ Popup
Definition: console.h:35
enum _TEXT_TYPE TEXT_TYPE

Function Documentation

◆ ApplyConsoleInfo()

VOID ApplyConsoleInfo ( HWND  hwndDlg)

Definition at line 88 of file console.c.

89{
90 static BOOL ConsoleInfoAlreadySaved = FALSE;
91
92 /*
93 * We already applied all the console properties (and saved if needed).
94 * Nothing more needs to be done.
95 */
96 if (ConsoleInfoAlreadySaved)
97 goto Done;
98
99 /*
100 * If we are setting the default parameters, just save them,
101 * otherwise display the confirmation & apply dialog.
102 */
103 if (ConInfo->hWnd == NULL)
104 {
107 }
108 else
109 {
111
114
115 if (!SetConsoleInfo)
116 {
117 /* Don't destroy when the user presses cancel */
119 return;
120 }
121 }
122
123 /*
124 * We applied all the console properties (and saved if needed).
125 * Set the flag so that if this function is called again, we won't
126 * need to redo everything again.
127 */
128 ConsoleInfoAlreadySaved = TRUE;
129
130Done:
131 /* Options have been applied */
133 return;
134}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
static BOOL SaveConsoleInfo
Definition: console.c:26
static INT_PTR CALLBACK ApplyProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: console.c:51
static BOOL SetConsoleInfo
Definition: console.c:25
HINSTANCE hApplet
Definition: console.c:20
#define IDD_APPLYOPTIONS
Definition: resource.h:16
#define IDC_RADIO_APPLY_ALL
Definition: resource.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
#define PSNRET_NOERROR
Definition: prsht.h:129
#define SetWindowLongPtr
Definition: treelist.c:70
int32_t INT_PTR
Definition: typedefs.h:64
#define IDCANCEL
Definition: winuser.h:834
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4402
#define DWLP_MSGRESULT
Definition: winuser.h:873
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by ColorsProc(), FontProc(), and OptionsProc().

◆ BisectListSortedByValue()

UINT BisectListSortedByValue ( IN PLIST_CTL  ListCtl,
IN ULONG_PTR  Value,
OUT PUINT pValueItem  OPTIONAL,
IN BOOL  BisectRightOrLeft 
)

Definition at line 115 of file utils.c.

120{
121 INT iItemEnd = ListCtl->GetCount(ListCtl);
122 if (iItemEnd == CB_ERR || iItemEnd <= 0)
123 return CB_ERR; // Fail
124
125 return BisectListSortedByValueEx(ListCtl, Value,
126 0, (UINT)(iItemEnd - 1),
127 pValueItem,
128 BisectRightOrLeft);
129}
UINT BisectListSortedByValueEx(IN PLIST_CTL ListCtl, IN ULONG_PTR Value, IN UINT itemStart, IN UINT itemEnd, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
Definition: utils.c:39
unsigned int UINT
Definition: ndis.h:50
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define CB_ERR
Definition: winuser.h:2438

Referenced by AddCodePage(), BuildCodePageList(), EnumFontSizesProc(), and FontSizeList_SelectFontSize().

◆ BisectListSortedByValueEx()

UINT BisectListSortedByValueEx ( IN PLIST_CTL  ListCtl,
IN ULONG_PTR  Value,
IN UINT  itemStart,
IN UINT  itemEnd,
OUT PUINT pValueItem  OPTIONAL,
IN BOOL  BisectRightOrLeft 
)

Definition at line 39 of file utils.c.

46{
47 UINT iItemStart, iItemEnd, iItem;
48 ULONG_PTR itemData;
49
50 /* Sanity checks */
51 if (itemStart > itemEnd)
52 return CB_ERR; // Fail
53
54 /* Initialize */
55 iItemStart = itemStart;
56 iItemEnd = itemEnd;
57 iItem = iItemStart;
58
59 if (pValueItem)
60 *pValueItem = CB_ERR;
61
62 while (iItemStart <= iItemEnd)
63 {
64 /*
65 * Bisect. Note the following:
66 * - if iItemEnd == iItemStart + 1, then iItem == iItemStart;
67 * - if iItemStart == iItemEnd, then iItemStart == iItem == iItemEnd.
68 * In all but the last case, iItemStart <= iItem < iItemEnd.
69 */
70 iItem = (iItemStart + iItemEnd) / 2;
71
72 itemData = ListCtl->GetData(ListCtl, iItem);
73 if (itemData == CB_ERR)
74 return CB_ERR; // Fail
75
76 if (Value == itemData)
77 {
78 /* Found a candidate */
79 if (pValueItem)
80 *pValueItem = iItem;
81
82 /*
83 * Try to find the last element (if BisectRightOrLeft == TRUE)
84 * or the first element (if BisectRightOrLeft == FALSE).
85 */
86 if (BisectRightOrLeft)
87 {
88 iItemStart = iItem + 1; // iItemStart may be > iItemEnd
89 }
90 else
91 {
92 if (iItem <= itemStart) break;
93 iItemEnd = iItem - 1; // iItemEnd may be < iItemStart, i.e. iItemStart may be > iItemEnd
94 }
95 }
96 else if (Value < itemData)
97 {
98 if (iItem <= itemStart) break;
99 /* The value should be before iItem */
100 iItemEnd = iItem - 1; // iItemEnd may be < iItemStart, i.e. iItemStart may be > iItemEnd, if iItem == iItemStart.
101 }
102 else // if (itemData < Value)
103 {
104 /* The value should be after iItem */
105 iItemStart = iItem + 1; // iItemStart may be > iItemEnd, if iItem == iItemEnd.
106 }
107
108 /* Here, iItemStart may be == iItemEnd */
109 }
110
111 return iItemStart;
112}
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by BisectListSortedByValue().

◆ PaintText()

VOID PaintText ( IN LPDRAWITEMSTRUCT  drawItem,
IN PCONSOLE_STATE_INFO  pConInfo,
IN TEXT_TYPE  TextMode 
)

Definition at line 471 of file layout.c.

475{
476 USHORT CurrentAttrib;
477 COLORREF pbkColor, ptColor;
478 COLORREF nbkColor, ntColor;
479 HBRUSH hBrush;
480 HFONT hOldFont;
481
482 if (TextMode == Screen)
483 CurrentAttrib = pConInfo->ScreenAttributes;
484 else if (TextMode == Popup)
485 CurrentAttrib = pConInfo->PopupAttributes;
486 else
487 return;
488
489 nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
490 ntColor = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];
491
492 /* Draw the console background */
493 hBrush = CreateSolidBrush(nbkColor);
494 FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
495 if (hBrush) DeleteObject(hBrush);
496
497 /* Refresh the font preview, getting a new font if necessary */
498 if (FontPreview.hFont == NULL)
500 /* Recheck hFont since RefreshFontPreview() may not have updated it */
501 if (FontPreview.hFont == NULL)
502 return;
503
504 /* Draw the preview text using the current font */
505 hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
506 // if (!hOldFont) return;
507
508 /* Add a few space between the preview window border and the text sample */
509 InflateRect(&drawItem->rcItem, -2, -2);
510
511 ptColor = SetTextColor(drawItem->hDC, ntColor);
512 pbkColor = SetBkColor(drawItem->hDC, nbkColor);
513 DrawTextW(drawItem->hDC, szPreviewText, (INT)wcslen(szPreviewText), &drawItem->rcItem, 0);
514 SetTextColor(drawItem->hDC, ptColor);
515 SetBkColor(drawItem->hDC, pbkColor);
516
517 SelectObject(drawItem->hDC, hOldFont);
518}
FONT_PREVIEW FontPreview
Definition: font.c:21
VOID RefreshFontPreview(IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:52
pKey DeleteObject()
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const WCHAR szPreviewText[]
Definition: layout.c:460
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:16
unsigned short USHORT
Definition: pedump.c:61
HFONT hFont
Definition: console.h:40
#define TextAttribFromAttrib(Attribute)
Definition: settings.h:72
#define BkgdAttribFromAttrib(Attribute)
Definition: settings.h:73
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI GetStockObject(_In_ int)
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:999
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define BLACK_BRUSH
Definition: wingdi.h:896
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)

Referenced by ColorsProc(), and FontProc().

◆ RefreshFontPreview()

VOID RefreshFontPreview ( IN FONT_PREVIEW Preview,
IN PCONSOLE_STATE_INFO  pConInfo 
)

Definition at line 52 of file font.c.

55{
56 HFONT hFont = CreateConsoleFont(pConInfo);
57 if (!hFont)
58 {
59 DPRINT1("RefreshFontPreview: CreateConsoleFont() failed\n");
60 return;
61 }
62
63 if (Preview->hFont) DeleteObject(Preview->hFont);
64 Preview->hFont = hFont;
65 GetFontCellSize(NULL, hFont, &Preview->CharHeight, &Preview->CharWidth);
66}
#define DPRINT1
Definition: precomp.h:8
HFONT hFont
Definition: main.c:53
HFONT CreateConsoleFont(_Inout_ PCONSOLE_STATE_INFO ConsoleInfo)
A wrapper for CreateConsoleFontEx().
Definition: font.c:653

Referenced by InitApplet(), PaintText(), and WinPrev_OnDraw().

◆ RegisterWinPrevClass()

BOOL RegisterWinPrevClass ( IN HINSTANCE  hInstance)

Definition at line 32 of file layout.c.

34{
36
37 WndClass.lpszClassName = WIN_PREVIEW_CLASS;
38 WndClass.lpfnWndProc = WinPrevProc;
39 WndClass.style = 0;
40 WndClass.hInstance = hInstance;
41 WndClass.hIcon = NULL;
43 WndClass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
44 WndClass.lpszMenuName = NULL;
45 WndClass.cbClsExtra = 0;
46 WndClass.cbWndExtra = 0; // sizeof(PWINPREV_DATA);
47
48 return (RegisterClassW(&WndClass) != 0);
49}
WCHAR WndClass[]
Definition: capicon.c:23
HINSTANCE hInstance
Definition: charmap.c:19
#define WIN_PREVIEW_CLASS
Definition: layout.c:17
static LRESULT CALLBACK WinPrevProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: layout.c:398
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define IDC_ARROW
Definition: winuser.h:687
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2157
#define COLOR_BACKGROUND
Definition: winuser.h:916

Referenced by InitApplet().

◆ UnRegisterWinPrevClass()

BOOL UnRegisterWinPrevClass ( IN HINSTANCE  hInstance)

Definition at line 52 of file layout.c.

54{
56}
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)

Referenced by InitApplet().

◆ UpdateFontPreview()

VOID UpdateFontPreview ( IN FONT_PREVIEW Preview,
IN HFONT  hFont,
IN UINT  CharWidth,
IN UINT  CharHeight 
)

Definition at line 69 of file font.c.

74{
75 if (Preview->hFont) DeleteObject(Preview->hFont);
76 Preview->hFont = hFont;
77 Preview->CharWidth = CharWidth;
78 Preview->CharHeight = CharHeight;
79}
static int CharWidth
Definition: carets.c:7
static int CharHeight
Definition: carets.c:8

Referenced by FontSizeChange().

Variable Documentation

◆ ConInfo

◆ FontPreview

FONT_PREVIEW FontPreview
extern

Definition at line 21 of file font.c.

Referenced by FontSizeChange(), InitApplet(), OptionsProc(), PaintText(), and WinPrev_OnDraw().

◆ hApplet

HINSTANCE hApplet
extern

Definition at line 17 of file access.c.