ReactOS  0.4.13-dev-247-g0f29b3f
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;
enum _TEXT_TYPE TEXT_TYPE
Definition: console.h:35
Definition: console.h:34

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 
112  SetConsoleInfo = (res != IDCANCEL);
114 
115  if (SetConsoleInfo == FALSE)
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 
130 Done:
131  /* Options have been applied */
133  return;
134 }
#define TRUE
Definition: types.h:120
static INT_PTR CALLBACK ApplyProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: console.c:51
static BOOL SetConsoleInfo
Definition: console.c:25
int32_t INT_PTR
Definition: typedefs.h:62
#define SetWindowLongPtr
Definition: treelist.c:70
#define DWLP_MSGRESULT
Definition: winuser.h:864
unsigned int BOOL
Definition: ntddk_ex.h:94
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
smooth NULL
Definition: ftsmooth.c:416
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4268
HINSTANCE hApplet
Definition: console.c:20
#define PSNRET_NOERROR
Definition: prsht.h:129
static BOOL SaveConsoleInfo
Definition: console.c:26
#define IDD_APPLYOPTIONS
Definition: resource.h:16
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
GLuint res
Definition: glext.h:9613
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
#define IDC_RADIO_APPLY_ALL
Definition: resource.h:34

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
int32_t INT
Definition: typedefs.h:56
#define CB_ERR
Definition: winuser.h:2389
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

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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CB_ERR
Definition: winuser.h:2389
unsigned int UINT
Definition: ndis.h:50

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  hBrush = CreateSolidBrush(nbkColor);
493  if (!hBrush) return;
494 
495  if (FontPreview.hFont == NULL)
496  RefreshFontPreview(&FontPreview, pConInfo);
497 
498  hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
499  //if (hOldFont == NULL)
500  //{
501  // DeleteObject(hBrush);
502  // return;
503  //}
504 
505  FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
506 
507  /* Add a few space between the preview window border and the text sample */
508  InflateRect(&drawItem->rcItem, -2, -2);
509 
510  ptColor = SetTextColor(drawItem->hDC, ntColor);
511  pbkColor = SetBkColor(drawItem->hDC, nbkColor);
512  DrawTextW(drawItem->hDC, szPreviewText, (INT)wcslen(szPreviewText), &drawItem->rcItem, 0);
513  SetTextColor(drawItem->hDC, ptColor);
514  SetBkColor(drawItem->hDC, pbkColor);
515 
516  SelectObject(drawItem->hDC, hOldFont);
517  DeleteObject(hBrush);
518 }
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
int32_t INT
Definition: typedefs.h:56
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
smooth NULL
Definition: ftsmooth.c:416
#define BkgdAttribFromAttrib(Attribute)
Definition: settings.h:73
DWORD COLORREF
Definition: windef.h:285
const WCHAR szPreviewText[]
Definition: layout.c:460
HFONT hFont
Definition: console.h:40
#define TextAttribFromAttrib(Attribute)
Definition: settings.h:72
Definition: console.h:35
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:886
unsigned short USHORT
Definition: pedump.c:61
FONT_PREVIEW FontPreview
Definition: font.c:21
VOID RefreshFontPreview(IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:49
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: console.h:34
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:17

Referenced by ColorsProc(), and FontProc().

◆ RefreshFontPreview()

VOID RefreshFontPreview ( IN FONT_PREVIEW Preview,
IN PCONSOLE_STATE_INFO  pConInfo 
)

Definition at line 49 of file font.c.

52 {
53  if (Preview->hFont) DeleteObject(Preview->hFont);
54  Preview->hFont = CreateConsoleFont(pConInfo);
55  if (Preview->hFont == NULL)
56  DPRINT1("RefreshFontPreview: CreateConsoleFont() failed\n");
57  GetFontCellSize(NULL, Preview->hFont, &Preview->CharHeight, &Preview->CharWidth);
58 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
smooth NULL
Definition: ftsmooth.c:416
BOOL GetFontCellSize(IN HDC hDC OPTIONAL, IN HFONT hFont, OUT PUINT Height, OUT PUINT Width)
Definition: font.c:113
#define DPRINT1
Definition: precomp.h:8
HFONT CreateConsoleFont(IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: font.c:95

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 }
static LRESULT CALLBACK WinPrevProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: layout.c:398
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
HINSTANCE hInstance
Definition: charmap.c:20
smooth NULL
Definition: ftsmooth.c:416
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define IDC_ARROW
Definition: winuser.h:682
#define COLOR_BACKGROUND
Definition: hardware.h:164
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR WndClass[]
Definition: capicon.c:23
#define WIN_PREVIEW_CLASS
Definition: layout.c:17

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)
HINSTANCE hInstance
Definition: charmap.c:20
#define WIN_PREVIEW_CLASS
Definition: layout.c:17

Referenced by InitApplet().

◆ UpdateFontPreview()

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

Definition at line 61 of file font.c.

66 {
67  if (Preview->hFont) DeleteObject(Preview->hFont);
68  Preview->hFont = hFont;
69  Preview->CharWidth = CharWidth;
70  Preview->CharHeight = CharHeight;
71 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HFONT hFont
Definition: main.c:53
static int CharHeight
Definition: carets.c:8
static int CharWidth
Definition: carets.c:7

Referenced by FontSizeChange().

Variable Documentation

◆ ConInfo

◆ FontPreview

FONT_PREVIEW FontPreview

Definition at line 21 of file font.c.

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

◆ hApplet

HINSTANCE hApplet

Definition at line 17 of file access.c.