2c6b40b7e9be4a86abcb958c084b72cb91bd5383
[reactos.git] / rosapps / smartpdf / baseutils / ms_ui_helper.h
1 /*++
2
3 Copyright (c) 2003 Microsoft Corporation
4
5 Module Name:
6
7 uihelper.h
8
9 Abstract:
10
11 Include file for HIDPI / orientation / font change helper functions.
12
13 --*/
14
15 #ifndef __UIHELPER_H__
16 #define __UIHELPER_H__
17
18 #include <windows.h>
19 #include <commctrl.h>
20 #include "ms_ui_shguim.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 ////////////////////////////////////////////////////////////////////////////////
27 // HIDPI functions and constants.
28 ////////////////////////////////////////////////////////////////////////////////
29
30 #ifndef ILC_COLORMASK
31 #define ILC_COLORMASK 0x00FE
32 #endif
33
34 //
35 // The two macros HIDPISIGN and HIDPIABS are there to ensure correct rounding
36 // for negative numbers passed into HIDPIMulDiv as x (we want -1.5 to round
37 // to -1, 2.5 to round to 2, etc). So we use the absolute value of x, and then
38 // multiply the result by the sign of x. Y and z should never be negative, as
39 // y is the dpi of the device (presumably 192 or 96), and z is always 96, as
40 // that is our original dpi we developed on.
41 //
42
43 #define HIDPISIGN(x) (((x)<0)?-1:1)
44 #define HIDPIABS(x) (((x)<0)?-(x):x)
45 #define HIDPIMulDiv(x,y,z) ((((HIDPIABS(x)*(y))+((z)>>1))/(z))*HIDPISIGN(x))
46
47 //
48 // Cached values of GetDeviceCaps(LOGPIXELSX/Y) for the screen DC.
49 //
50 EXTERN_C int g_HIDPI_LogPixelsX;
51 EXTERN_C int g_HIDPI_LogPixelsY;
52
53 //
54 // You need to define these somewhere in your .c files only if you make use of
55 // the scaling macros. (Defined in UIHelper.cpp).
56 //
57 #define HIDPI_ENABLE \
58 int g_HIDPI_LogPixelsX; \
59 int g_HIDPI_LogPixelsY;
60
61 //
62 // Scaling macros.
63 //
64 #define SCALEX(argX) (HIDPIMulDiv(argX,g_HIDPI_LogPixelsX,96))
65 #define SCALEY(argY) (HIDPIMulDiv(argY,g_HIDPI_LogPixelsY,96))
66
67 #define UNSCALEX(argX) (HIDPIMulDiv(argX,96,g_HIDPI_LogPixelsX))
68 #define UNSCALEY(argY) (HIDPIMulDiv(argY,96,g_HIDPI_LogPixelsY))
69
70 #define SCALERECT(rc) { rc.left = SCALEX(rc.left); rc.right = SCALEX(rc.right); rc.top = SCALEY(rc.top); rc.bottom = SCALEY(rc.bottom);}
71 #define SCALEPT(pt) { pt.x = SCALEX(pt.x); pt.y = SCALEY(pt.y);}
72
73 //////////////////////////////////////////////////////////////////////////////
74 // FUNCTION: HIDPI_InitScaling
75 //
76 // PURPOSE: Initializes g_HIDPI_LogPixelsX and g_HIDPI_LogPixelsY. This
77 // should be called once at the beginning of any HIDPI-aware application.
78 //
79 __inline void HIDPI_InitScaling()
80 {
81 HDC screen;
82
83 if( g_HIDPI_LogPixelsX )
84 return;
85
86 screen = GetDC(NULL);
87 g_HIDPI_LogPixelsX = GetDeviceCaps(screen, LOGPIXELSX);
88 g_HIDPI_LogPixelsY = GetDeviceCaps(screen, LOGPIXELSY);
89 ReleaseDC(NULL, screen);
90 }
91
92 //////////////////////////////////////////////////////////////////////////////
93 // FUNCTION: HIDPI_StretchBitmap
94 //
95 // PURPOSE: Stretches a bitmap containing a grid of images. There are
96 // cImagesX images per row and cImagesY rows per bitmap. Each image is
97 // scaled individually, so that there are no artifacts with non-integral
98 // scaling factors. If the bitmap contains only one image, set cImagesX
99 // and cImagesY to 1.
100 //
101 // ON ENTRY:
102 // HBITMAP* phbm: a pointer to the bitmap to be scaled.
103 // INT cxDstImg: the width of each image after scaling.
104 // INT cyDstImg: the height of each image after scaling.
105 // INT cImagesX: the number of images per row. This value should
106 // evenly divide the width of the bitmap.
107 // INT cImagesY: the number of rows in the bitmap. This value should
108 // evenly divide the height of the bitmap.
109 //
110 // ON EXIT:
111 // Returns TRUE on success, FALSE on failure.
112 //
113 // If any scaling has occured, the bitmap pointed to by phbm is deleted
114 // and is replaced by a new bitmap handle.
115 //
116 BOOL HIDPI_StretchBitmap(
117 HBITMAP* phbm,
118 int cxDstImg,
119 int cyDstImg,
120 int cImagesX,
121 int cImagesY
122 );
123
124 //////////////////////////////////////////////////////////////////////////////
125 // FUNCTION: HIDPI_GetBitmapLogPixels
126 //
127 // PURPOSE: retrieves the DPI fields of the specified bitmap.
128 //
129 // ON ENTRY:
130 // HINSTANCE hinst: the HINSTANCE of the bitmap resource.
131 // LPCTSTR lpbmp: the ID of the bitmap resource. The MAKEINTRESOURCE
132 // macro can be used for integer IDs.
133 // INT* pnLogPixelsX: the returned value for the horizontal DPI field of
134 // the bitmap. This value is never less than 96.
135 // INT* pnLogPixelsY: the returned value for the vertical DPI field of
136 // the bitmap. This value is never less than 96.
137 //
138 // ON EXIT:
139 // Returns TRUE on success, FALSE on failure.
140 //
141 BOOL HIDPI_GetBitmapLogPixels(
142 HINSTANCE hinst,
143 LPCTSTR lpbmp,
144 int* pnLogPixelsX,
145 int* pnLogPixelsY
146 );
147
148 //////////////////////////////////////////////////////////////////////////////
149 // FUNCTION: HIDPI_StretchIcon
150 //
151 // PURPOSE: stretches an icon to the specified size on 4.21 devices and later.
152 // On 4.20 and previous revisions of the OS, this is a no-op.
153 //
154 // ON ENTRY:
155 // HICON* phic: the icon to stretch.
156 // INT cxIcon: the desired width of the icon.
157 // INT cyIcon: the desired height of the icon.
158 //
159 // ON EXIT:
160 // Returns TRUE on success, FALSE on failure.
161 //
162 // If any stretching occurred, the icon pointed to by phic is deleted and
163 // is replaced by a new icon handle.
164 //
165 BOOL HIDPI_StretchIcon(
166 HICON* phic,
167 int cxIcon,
168 int cyIcon
169 );
170
171 //////////////////////////////////////////////////////////////////////////////
172 // FUNCTION: HIDPI_ImageList_LoadImage
173 //
174 // PURPOSE: This function operates identically to ImageList_LoadImage, except
175 // that it first checks the DPI fields of the bitmap (using
176 // HIDPI_GetBitmapLogPixels); compares it to the DPI of the screen
177 // (using g_HIDPI_LogPixelsX and g_HIDPI_LogPixelsY), and performs scaling
178 // (using HIDPI_StretchBitmap) if the values are different.
179 //
180 // ON ENTRY:
181 // See the MSDN documentation for ImageList_LoadImage.
182 //
183 // ON EXIT:
184 // See the MSDN documentation for ImageList_LoadImage.
185 //
186 HIMAGELIST HIDPI_ImageList_LoadImage(
187 HINSTANCE hinst,
188 LPCTSTR lpbmp,
189 int cx,
190 int cGrow,
191 COLORREF crMask,
192 UINT uType,
193 UINT uFlags
194 );
195
196 //////////////////////////////////////////////////////////////////////////////
197 // FUNCTION: HIDPI_ImageList_ReplaceIcon
198 //
199 // PURPOSE: Replaces an icon in an ImageList, scaling it from its original size
200 // to the size of the images in the ImageList.
201 //
202 // ON ENTRY:
203 // See the MSDN documentation for ImageList_ReplaceIcon.
204 //
205 // ON EXIT:
206 // See the MSDN documentation for ImageList_ReplaceIcon.
207 //
208 int HIDPI_ImageList_ReplaceIcon(
209 HIMAGELIST himl,
210 int i,
211 HICON hicon
212 );
213
214 //////////////////////////////////////////////////////////////////////////////
215 // FUNCTION: HIDPI_ImageList_AddIcon
216 //
217 // PURPOSE: Adds an icon to an ImageList, scaling it from its original size
218 // to the size of the images in the ImageList.
219 //
220 // ON ENTRY:
221 // See the MSDN documentation for ImageList_AddIcon.
222 //
223 // ON EXIT:
224 // See the MSDN documentation for ImageList_AddIcon.
225 //
226 #define HIDPI_ImageList_AddIcon(himl, hicon) HIDPI_ImageList_ReplaceIcon(himl, -1, hicon)
227
228 //////////////////////////////////////////////////////////////////////////////
229 // FUNCTION: HIDPI_Rectangle
230 //
231 // PURPOSE: Draws a rectangle using the currently selected pen. Drawing occurs
232 // completely within the drawing rectangle (the rectangle has an "inside
233 // frame" drawing style).
234 //
235 // ON ENTRY:
236 // HDC hdc: the display context of the drawing surface.
237 // INT nLeft: left bound of rectangle
238 // INT nTop: top bound of rectangle
239 // INT nRight: right bound of rectangle plus one.
240 // INT nBottom: bottom bound of rectangle plus one.
241 //
242 // ON EXIT:
243 // Returns TRUE on success, FALSE on failure.
244 //
245 BOOL HIDPI_Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom);
246
247 //////////////////////////////////////////////////////////////////////////////
248 // FUNCTION: HIDPI_BorderRectangle
249 //
250 // PURPOSE: Draws a rectangle with the system border pen. Drawing occurs
251 // completely within the drawing rectangle (the rectangle has an "inside
252 // frame" drawing style).
253 //
254 // ON ENTRY:
255 // HDC hdc: the display context of the drawing surface.
256 // INT nLeft: left bound of rectangle
257 // INT nTop: top bound of rectangle
258 // INT nRight: right bound of rectangle plus one.
259 // INT nBottom: bottom bound of rectangle plus one.
260 //
261 // ON EXIT:
262 // Returns TRUE on success, FALSE on failure.
263 //
264 BOOL HIDPI_BorderRectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom);
265
266 //////////////////////////////////////////////////////////////////////////////
267 // FUNCTION: HIDPI_Polyline
268 //
269 // PURPOSE: Draws a polyline using the currently selected pen. In addition,
270 // this function provides control over how the line will be drawn.
271 //
272 // ON ENTRY:
273 // HDC hdc: the display context of the drawing surface.
274 // const POINT* lppt: array of POINTS that specify line to draw.
275 // INT cPoints: number of points in array.
276 // INT nStyle: the style the pen should be drawn in. This may be an
277 // existing pen style, such as PS_SOLID, or one of the following styles:
278 //
279 // PS_LEFTBIAS PS_UPBIAS PS_UPLEFT
280 // PS_RIGHTBIAS PS_DOWNBIAS PS_DOWNRIGHT
281 //
282 // These styles indicate how the pen should "hang" from each line
283 // segment. By default, the pen is centered along the line, but with
284 // these line styles the developer can draw lines above, below, to the
285 // left or to the right of the line segment.
286 //
287 // ON EXIT:
288 // Returns TRUE on success, FALSE on failure.
289 //
290
291 #define PS_RIGHTBIAS 0x10
292 #define PS_LEFTBIAS 0x20
293 #define PS_DOWNBIAS 0x40
294 #define PS_UPBIAS 0x80
295 #define PS_DOWNRIGHT (PS_DOWNBIAS | PS_RIGHTBIAS)
296 #define PS_UPLEFT (PS_UPBIAS | PS_LEFTBIAS)
297 #define PS_BIAS_MASK (PS_RIGHTBIAS | PS_LEFTBIAS | PS_DOWNBIAS | PS_UPBIAS)
298
299 BOOL HIDPI_Polyline(HDC hdc, const POINT *lppt, int cPoints, int nStyle);
300
301 //////////////////////////////////////////////////////////////////////////////
302 // FUNCTION: HIDPI_BorderPolyline
303 //
304 // PURPOSE: Draws a polyline, but with the system border pen. In addition,
305 // this function provides control over how the line will be drawn.
306 //
307 // ON ENTRY:
308 // HDC hdc: the display context of the drawing surface.
309 // const POINT* lppt: array of POINTS that specify line to draw.
310 // INT cPoints: number of points in array.
311 // INT nStyle: the style the pen should be drawn in. See HIDPI_Polyline
312 // for more details.
313 //
314 // ON EXIT:
315 // Returns TRUE on success, FALSE on failure.
316 //
317 BOOL HIDPI_BorderPolyline(HDC hdc, const POINT *lppt, int cPoints, int nStyle);
318
319 ////////////////////////////////////////////////////////////////////////////////
320 // Orientation functions.
321 ////////////////////////////////////////////////////////////////////////////////
322
323 //////////////////////////////////////////////////////////////////////////////
324 // FUNCTION: RelayoutDialog
325 //
326 // PURPOSE: Re-lays out a dialog based on a dialog template. This function
327 // iterates through all the child window controls and does a SetWindowPos
328 // for each. It also does a SetWindowText for each static text control
329 // and updates the selected bitmap or icon in a static image control.
330 // This assumes that the current dialog and the new template have all the
331 // same controls, with the same IDCs.
332 //
333 // ON ENTRY:
334 // HINSTANCE hInst: the hInstance of the current module.
335 // HWND hDlg: the dialog to layout.
336 // LPCWSTR iddTemplate: the new template for the dialog (can use
337 // the MAKEINTRESOURCE macro).
338 //
339 // ON EXIT: TRUE if success; FALSE if failure (either the iddTemplate is
340 // invalid, or there are two or more IDC_STATICs in the template).
341 //
342 BOOL RelayoutDialog(HINSTANCE hInst, HWND hDlg, LPCWSTR iddTemplate);
343
344 #ifdef __cplusplus
345 }
346 #endif
347
348 #endif // __UIHELPER_H__