Create a branch for header work.
[reactos.git] / base / applications / charmap / lrgcell.c
1 /*
2 * PROJECT: ReactOS Character Map
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/charmap/lrgcell.c
5 * PURPOSE: large cell window implementation
6 * COPYRIGHT: Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include <precomp.h>
11
12
13 static
14 HFONT
15 SetLrgFont(PMAP infoPtr)
16 {
17 LOGFONTW lf;
18 HFONT hFont = NULL;
19 HDC hdc;
20 HWND hCombo;
21 LPWSTR lpFontName;
22 INT Len;
23
24 hCombo = GetDlgItem(infoPtr->hParent,
25 IDC_FONTCOMBO);
26
27 Len = GetWindowTextLengthW(hCombo);
28
29 if (Len != 0)
30 {
31 lpFontName = HeapAlloc(GetProcessHeap(),
32 0,
33 (Len + 1) * sizeof(WCHAR));
34
35 if (lpFontName)
36 {
37 SendMessageW(hCombo,
38 WM_GETTEXT,
39 31,
40 (LPARAM)lpFontName);
41
42 ZeroMemory(&lf,
43 sizeof(lf));
44
45 hdc = GetDC(infoPtr->hLrgWnd);
46 lf.lfHeight = GetDeviceCaps(hdc,
47 LOGPIXELSY) / 2;
48 ReleaseDC(infoPtr->hLrgWnd,
49 hdc);
50
51 lf.lfCharSet = DEFAULT_CHARSET;
52 wcscpy(lf.lfFaceName,
53 lpFontName);
54
55 hFont = CreateFontIndirectW(&lf);
56
57 HeapFree(GetProcessHeap(),
58 0,
59 lpFontName);
60 }
61 }
62
63 return hFont;
64 }
65
66
67 LRESULT CALLBACK
68 LrgCellWndProc(HWND hwnd,
69 UINT uMsg,
70 WPARAM wParam,
71 LPARAM lParam)
72 {
73 PMAP infoPtr;
74 LRESULT Ret = 0;
75 static INT cxClient, cyClient;
76 static RECT rc;
77 static HFONT hFont = NULL;
78
79 infoPtr = (PMAP)GetWindowLongPtrW(hwnd,
80 GWLP_USERDATA);
81
82 if (infoPtr == NULL && uMsg != WM_CREATE)
83 {
84 goto HandleDefaultMessage;
85 }
86
87 switch (uMsg)
88 {
89 case WM_CREATE:
90 {
91 infoPtr = (PMAP)(((LPCREATESTRUCTW)lParam)->lpCreateParams);
92
93 SetWindowLongPtrW(hwnd,
94 GWLP_USERDATA,
95 (LONG_PTR)infoPtr);
96
97 hFont = SetLrgFont(infoPtr);
98
99 break;
100 }
101
102 case WM_SIZE:
103 {
104 cxClient = LOWORD(lParam);
105 cyClient = HIWORD(lParam);
106
107 rc.left = 0;
108 rc.top = 0;
109 rc.right = cxClient;
110 rc.bottom = cyClient;
111
112 break;
113 }
114
115 case WM_PAINT:
116 {
117 PAINTSTRUCT ps;
118 HDC hdc;
119 HFONT hOldFont;
120
121 hdc = BeginPaint(hwnd,
122 &ps);
123
124 Rectangle(hdc,
125 0,
126 0,
127 cxClient,
128 cyClient);
129
130 hOldFont = SelectObject(hdc, hFont);
131
132 DrawTextW(hdc,
133 &infoPtr->pActiveCell->ch,
134 1,
135 &rc,
136 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
137
138 SelectObject(hdc, hOldFont);
139
140 EndPaint(hwnd,
141 &ps);
142
143 break;
144 }
145
146 case WM_DESTROY:
147 {
148 DeleteObject(hFont);
149
150 break;
151 }
152
153 default:
154 {
155 HandleDefaultMessage:
156 Ret = DefWindowProcW(hwnd,
157 uMsg,
158 wParam,
159 lParam);
160 break;
161 }
162 }
163
164 return Ret;
165 }