ReactOS  0.4.13-dev-482-ge57f103
editglyphdlg.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS VGA Font Editor
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Dialog for editing a glyph
5  * COPYRIGHT: Copyright 2008 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 static VOID
11 AddToolboxButton(IN HWND hToolbar, IN INT iBitmap, IN INT idCommand, IN BYTE fsState)
12 {
13  TBBUTTON tbb = {0,};
14 
15  tbb.fsState = fsState;
17  tbb.iBitmap = iBitmap;
18  tbb.idCommand = idCommand;
19 
20  SendMessageW( hToolbar, TB_ADDBUTTONSW, 1, (LPARAM)&tbb );
21 }
22 
23 static VOID
25 {
26  HWND hToolbar;
27  INT iBitmap;
28  TBADDBITMAP tbab;
29 
30  hToolbar = GetDlgItem(Info->hSelf, IDC_EDIT_GLYPH_TOOLBOX);
31 
32  // Identify the used Common Controls version
33  SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
34 
35  // Set the button size to 24x24
36  SendMessageW( hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(24, 24) );
37  SendMessageW( hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24) );
38 
39  // Add the Toolbox bitmaps
40  tbab.hInst = hInstance;
42  iBitmap = (INT)SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbab);
43 
45 }
46 
47 static VOID
49 {
50  BitRect->left = uColumn * Info->lEditSpacing + 1;
51  BitRect->top = uRow * Info->lEditSpacing + 1;
52  BitRect->right = BitRect->left + Info->lEditSpacing - 1;
53  BitRect->bottom = BitRect->top + Info->lEditSpacing - 1;
54 }
55 
56 static VOID
58 {
59  // Set the bit in the bitfield
60  if(uBit)
61  Info->CharacterBits[uRow] |= 1 << (7 - uColumn);
62  else
63  Info->CharacterBits[uRow] &= ~( 1 << (7 - uColumn) );
64 
65  // Redraw everything
66  InvalidateRect(Info->hEdit, NULL, FALSE);
67  InvalidateRect(Info->hPreview, NULL, FALSE);
68 }
69 
70 static BOOL
72 {
73  switch(idCommand)
74  {
75  case IDOK:
76  {
77  RECT rect;
78  UINT uColumn;
79  UINT uRow;
80 
81  RtlCopyMemory( Info->FontWndInfo->Font->Bits + Info->uCharacter * 8, Info->CharacterBits, sizeof(Info->CharacterBits) );
82 
83  GetCharacterPosition(Info->uCharacter, &uRow, &uColumn);
84  GetCharacterRect(uRow, uColumn, &rect);
85  InvalidateRect(Info->FontWndInfo->hFontBoxesWnd, &rect, FALSE);
86 
87  Info->FontWndInfo->OpenInfo->bModified = TRUE;
88 
89  // Fall through
90  }
91 
92  // This is the equivalent of WM_DESTROY for dialogs
93  case IDCANCEL:
94  EndDialog(Info->hSelf, 0);
95 
96  // Remove the window from the linked list
97  if(Info->PrevEditGlyphWnd)
98  Info->PrevEditGlyphWnd->NextEditGlyphWnd = Info->NextEditGlyphWnd;
99  else
100  Info->FontWndInfo->FirstEditGlyphWnd = Info->NextEditGlyphWnd;
101 
102  if(Info->NextEditGlyphWnd)
103  Info->NextEditGlyphWnd->PrevEditGlyphWnd = Info->PrevEditGlyphWnd;
104  else
105  Info->FontWndInfo->LastEditGlyphWnd = Info->PrevEditGlyphWnd;
106 
109  SetWindowLongPtrW(Info->hPreview, GWLP_USERDATA, 0 );
110 
112  return TRUE;
113  }
114 
115  return FALSE;
116 }
117 
120 {
122 
124 
125  if(Info || uMsg == WM_INITDIALOG)
126  {
127  switch(uMsg)
128  {
129  case WM_COMMAND:
130  return EditGlyphCommand( LOWORD(wParam), Info );
131 
132  case WM_INITDIALOG:
134  Info->hSelf = hwnd;
137 
141 
142  InitToolbox(Info);
143 
144  return TRUE;
145  }
146  }
147 
148  return FALSE;
149 }
150 
151 static LRESULT CALLBACK
153 {
155 
157 
158  if(Info)
159  {
160  switch(uMsg)
161  {
162  case WM_CREATE:
163  return 0;
164 
165  case WM_LBUTTONDOWN:
166  SetPixelBit(Info, GET_Y_LPARAM(lParam) / Info->lEditSpacing, GET_X_LPARAM(lParam) / Info->lEditSpacing, 1);
167  return 0;
168 
169  case WM_RBUTTONDOWN:
170  SetPixelBit(Info, GET_Y_LPARAM(lParam) / Info->lEditSpacing, GET_X_LPARAM(lParam) / Info->lEditSpacing, 0);
171  return 0;
172 
173  case WM_PAINT:
174  {
175  BOOL bBit;
176  HPEN hOldPen;
177  HPEN hPen;
178  PAINTSTRUCT ps;
179  RECT rect;
180  UINT i;
181  UINT j;
182 
183  BeginPaint(hwnd, &ps);
184 
185  // Draw the grid
187  Info->lEditSpacing = rect.right / 8;
188 
189  hPen = CreatePen( PS_SOLID, 1, RGB(128, 128, 128) );
190  hOldPen = SelectObject(ps.hdc, hPen);
191 
192  for(i = 1; i < 8; i++)
193  {
194  MoveToEx(ps.hdc, i * Info->lEditSpacing, 0, NULL);
195  LineTo (ps.hdc, i * Info->lEditSpacing, rect.right);
196 
197  MoveToEx(ps.hdc, 0, i * Info->lEditSpacing, NULL);
198  LineTo (ps.hdc, rect.right, i * Info->lEditSpacing);
199  }
200 
201  SelectObject(ps.hdc, hOldPen);
202  DeleteObject(hPen);
203 
204  // Draw all bits
205  for(i = 0; i < 8; i++)
206  {
207  for(j = 0; j < 8; j++)
208  {
209  bBit = (BOOL) (Info->CharacterBits[i] << j & 0x80);
210 
211  GetBitRect(Info, i, j, &rect);
212  FillRect( ps.hdc, &rect, (HBRUSH) GetStockObject(bBit ? BLACK_BRUSH : WHITE_BRUSH) );
213  }
214  }
215 
216  // Draw the bounding rectangle
218  Rectangle(ps.hdc, 0, 0, rect.right, rect.right);
219 
220  EndPaint(hwnd, &ps);
221  return 0;
222  }
223  }
224  }
225 
226  return DefWindowProcW(hwnd, uMsg, wParam, lParam);
227 }
228 
229 static LRESULT CALLBACK
231 {
233 
235 
236  if(Info)
237  {
238  switch(uMsg)
239  {
240  case WM_CREATE:
241  return 0;
242 
243  case WM_PAINT:
244  {
245  BOOL bBit;
246  INT iLeft;
247  INT iTop;
248  PAINTSTRUCT ps;
249  RECT rect;
250  UINT i;
251  UINT j;
252 
253  BeginPaint(hwnd, &ps);
254 
255  // Draw the bounding rectangle
257  Rectangle(ps.hdc, 0, 0, rect.right, rect.bottom);
258 
259  // Draw all bits
260  iLeft = rect.right / 2 - 8 / 2;
261  iTop = rect.bottom / 2 - 8 / 2;
262 
263  for(i = 0; i < 8; i++)
264  {
265  for(j = 0; j < 8; j++)
266  {
267  bBit = (BOOL) (Info->CharacterBits[i] << j & 0x80);
268  SetPixel( ps.hdc, j + iLeft, i + iTop, (bBit ? 0 : 0xFFFFFF) );
269  }
270  }
271 
272  EndPaint(hwnd, &ps);
273 
274  return 0;
275  }
276  }
277  }
278 
279  return DefWindowProcW(hwnd, uMsg, wParam, lParam);
280 }
281 
282 BOOL
284 {
285  WNDCLASSW wc = {0,};
286 
288  wc.hInstance = hInstance;
289  wc.hCursor = LoadCursor( NULL, IDC_ARROW );
291 
292  if( !RegisterClassW(&wc) )
293  return FALSE;
294 
297 
298  return RegisterClassW(&wc) != 0;
299 }
300 
301 VOID
303 {
306 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IN
Definition: typedefs.h:38
#define TB_SETBUTTONSIZE
Definition: commctrl.h:1107
#define TB_BUTTONSTRUCTSIZE
Definition: commctrl.h:1106
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define IDOK
Definition: winuser.h:824
#define WM_LBUTTONDOWN
Definition: winuser.h:1752
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
struct _EDIT_GLYPH_INFO * PEDIT_GLYPH_INFO
Definition: precomp.h:37
__inline VOID GetCharacterPosition(IN UINT uCharacter, OUT PUINT uFontRow, OUT PUINT uFontColumn)
Definition: fontboxeswnd.c:34
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define ID_TOOLBOX_PEN
Definition: resource.h:56
#define NULL_BRUSH
Definition: wingdi.h:900
#define INT
Definition: polytest.cpp:20
#define CALLBACK
Definition: compat.h:27
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
INT_PTR CALLBACK EditGlyphDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: editglyphdlg.c:119
#define WHITE_BRUSH
Definition: wingdi.h:901
static LRESULT CALLBACK EditGlyphEditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: editglyphdlg.c:152
UINT_PTR WPARAM
Definition: windef.h:207
HINSTANCE hInst
Definition: commctrl.h:1031
#define GetWindowLongPtrW
Definition: winuser.h:4698
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
int32_t INT_PTR
Definition: typedefs.h:62
BYTE fsStyle
Definition: commctrl.h:924
VOID UnInitEditGlyphWndClasses(VOID)
Definition: editglyphdlg.c:302
#define BOOL
Definition: nt_native.h:43
int32_t INT
Definition: typedefs.h:56
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
struct TraceInfo Info
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define PS_SOLID
Definition: wingdi.h:585
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
HINSTANCE hInstance
Definition: charmap.c:20
static VOID GetBitRect(IN PEDIT_GLYPH_INFO Info, IN UINT uRow, IN UINT uColumn, OUT LPRECT BitRect)
Definition: editglyphdlg.c:48
#define BTNS_CHECKGROUP
Definition: commctrl.h:974
unsigned int BOOL
Definition: ntddk_ex.h:94
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
WNDPROC lpfnWndProc
Definition: winuser.h:3130
#define GWLP_USERDATA
Definition: treelist.c:63
#define MAKELONG(a, b)
Definition: typedefs.h:248
smooth NULL
Definition: ftsmooth.c:416
LPCWSTR lpszClassName
Definition: winuser.h:3138
LONG_PTR LPARAM
Definition: windef.h:208
int iBitmap
Definition: commctrl.h:921
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 GLint GLint j
Definition: glfuncs.h:250
#define WM_RBUTTONDOWN
Definition: winuser.h:1755
#define BLACK_BRUSH
Definition: wingdi.h:895
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:99
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define RGB(r, g, b)
Definition: wingdi.h:2918
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define TB_ADDBITMAP
Definition: commctrl.h:1028
#define WM_PAINT
Definition: winuser.h:1602
VOID GetCharacterRect(IN UINT uFontRow, IN UINT uFontColumn, OUT LPRECT CharacterRect)
Definition: fontboxeswnd.c:25
int idCommand
Definition: commctrl.h:922
#define TB_ADDBUTTONSW
Definition: commctrl.h:1238
#define TB_SETBITMAPSIZE
Definition: commctrl.h:1108
unsigned char BYTE
Definition: mem.h:68
#define WM_COMMAND
Definition: winuser.h:1716
#define IDC_EDIT_GLYPH_TOOLBOX
Definition: resource.h:32
#define LoadCursor
Definition: winuser.h:5678
#define EDIT_GLYPH_EDIT_CLASSW
HCURSOR hCursor
Definition: winuser.h:3135
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define IDC_EDIT_GLYPH_EDIT
Definition: resource.h:33
#define TBSTATE_CHECKED
Definition: commctrl.h:944
static BOOL EditGlyphCommand(IN INT idCommand, IN PEDIT_GLYPH_INFO Info)
Definition: editglyphdlg.c:71
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
static VOID InitToolbox(IN PEDIT_GLYPH_INFO Info)
Definition: editglyphdlg.c:24
HINSTANCE hInstance
Definition: winuser.h:3133
static VOID SetPixelBit(IN PEDIT_GLYPH_INFO Info, IN UINT uRow, IN UINT uColumn, IN BOOL uBit)
Definition: editglyphdlg.c:57
#define IDC_ARROW
Definition: winuser.h:682
#define IDC_EDIT_GLYPH_PREVIEW
Definition: resource.h:34
#define OUT
Definition: typedefs.h:39
#define TBSTATE_ENABLED
Definition: commctrl.h:946
#define WM_CREATE
Definition: winuser.h:1590
#define EDIT_GLYPH_PREVIEW_CLASSW
static VOID AddToolboxButton(IN HWND hToolbar, IN INT iBitmap, IN INT idCommand, IN BYTE fsState)
Definition: editglyphdlg.c:11
#define TOOLBOX_PEN
Definition: precomp.h:119
BOOL InitEditGlyphWndClasses(VOID)
Definition: editglyphdlg.c:283
#define SetWindowLongPtrW
Definition: winuser.h:5215
#define IDB_EDIT_GLYPH_TOOLBOX
Definition: resource.h:25
BYTE fsState
Definition: commctrl.h:923
#define IDCANCEL
Definition: winuser.h:825
LONG_PTR LRESULT
Definition: windef.h:209
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
static LRESULT CALLBACK EditGlyphPreviewWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: editglyphdlg.c:230
HANDLE hProcessHeap
Definition: kbswitch.c:25
UINT_PTR nID
Definition: commctrl.h:1032