f8f18e4d9a9487828d21b5ad81bc1ef1c88cdb65
[reactos.git] / reactos / lib / gdi32 / objects / dc.c
1 #include "precomp.h"
2
3 #define NDEBUG
4 #include <debug.h>
5
6
7 /*
8 * @implemented
9 */
10 HDC
11 STDCALL
12 CreateDCA (
13 LPCSTR lpszDriver,
14 LPCSTR lpszDevice,
15 LPCSTR lpszOutput,
16 CONST DEVMODEA * lpInitData
17 )
18 {
19 ANSI_STRING DriverA, DeviceA, OutputA;
20 UNICODE_STRING DriverU, DeviceU, OutputU;
21 HDC hDC;
22 DEVMODEW *lpInitDataW;
23
24 /*
25 * If needed, convert to Unicode
26 * any string parameter.
27 */
28
29 if (NULL != lpszDriver)
30 {
31 RtlInitAnsiString(&DriverA, (LPSTR)lpszDriver);
32 RtlAnsiStringToUnicodeString(&DriverU, &DriverA, TRUE);
33 } else
34 DriverU.Buffer = NULL;
35 if (NULL != lpszDevice)
36 {
37 RtlInitAnsiString(&DeviceA, (LPSTR)lpszDevice);
38 RtlAnsiStringToUnicodeString(&DeviceU, &DeviceA, TRUE);
39 } else
40 DeviceU.Buffer = NULL;
41 if (NULL != lpszOutput)
42 {
43 RtlInitAnsiString(&OutputA, (LPSTR)lpszOutput);
44 RtlAnsiStringToUnicodeString(&OutputU, &OutputA, TRUE);
45 } else
46 OutputU.Buffer = NULL;
47
48 if (NULL != lpInitData)
49 {
50 // lpInitDataW = HeapAllocMem(
51 } else
52 lpInitDataW = NULL;
53
54 /*
55 * Call the Unicode version
56 * of CreateDC.
57 */
58
59 hDC = CreateDCW (
60 DriverU.Buffer,
61 DeviceU.Buffer,
62 OutputU.Buffer,
63 NULL);
64 // lpInitDataW);
65 /*
66 * Free Unicode parameters.
67 */
68 RtlFreeUnicodeString(&DriverU);
69 RtlFreeUnicodeString(&DeviceU);
70 RtlFreeUnicodeString(&OutputU);
71
72 /*
73 * Return the possible DC handle.
74 */
75
76 return hDC;
77 }
78
79
80 /*
81 * @implemented
82 */
83 HDC
84 STDCALL
85 CreateDCW (
86 LPCWSTR lpwszDriver,
87 LPCWSTR lpwszDevice,
88 LPCWSTR lpwszOutput,
89 CONST DEVMODEW * lpInitData
90 )
91 {
92 UNICODE_STRING Driver, Device, Output;
93
94 if(lpwszDriver)
95 RtlInitUnicodeString(&Driver, lpwszDriver);
96 if(lpwszDevice)
97 RtlInitUnicodeString(&Driver, lpwszDevice);
98 if(lpwszOutput)
99 RtlInitUnicodeString(&Driver, lpwszOutput);
100
101 return NtGdiCreateDC((lpwszDriver ? &Driver : NULL),
102 (lpwszDevice ? &Device : NULL),
103 (lpwszOutput ? &Output : NULL),
104 (PDEVMODEW)lpInitData);
105 }
106
107
108 /*
109 * @implemented
110 */
111 HDC
112 STDCALL
113 CreateICW(
114 LPCWSTR lpszDriver,
115 LPCWSTR lpszDevice,
116 LPCWSTR lpszOutput,
117 CONST DEVMODEW * lpdvmInit
118 )
119 {
120 UNICODE_STRING Driver, Device, Output;
121
122 if(lpszDriver)
123 RtlInitUnicodeString(&Driver, lpszDriver);
124 if(lpszDevice)
125 RtlInitUnicodeString(&Device, lpszDevice);
126 if(lpszOutput)
127 RtlInitUnicodeString(&Output, lpszOutput);
128 return NtGdiCreateIC ((lpszDriver ? &Driver : NULL),
129 (lpszDevice ? &Device : NULL),
130 (lpszOutput ? &Output : NULL),
131 (CONST PDEVMODEW)lpdvmInit );
132 }
133
134
135 /*
136 * @implemented
137 */
138 HDC
139 STDCALL
140 CreateICA(
141 LPCSTR lpszDriver,
142 LPCSTR lpszDevice,
143 LPCSTR lpszOutput,
144 CONST DEVMODEA * lpdvmInit
145 )
146 {
147 NTSTATUS Status;
148 LPWSTR lpszDriverW, lpszDeviceW, lpszOutputW;
149 UNICODE_STRING Driver, Device, Output;
150 LPDEVMODEW dvmInitW = NULL;
151 HDC rc = 0;
152
153 Status = HEAP_strdupA2W ( &lpszDriverW, lpszDriver );
154 if (!NT_SUCCESS (Status))
155 SetLastError (RtlNtStatusToDosError(Status));
156 else
157 {
158 Status = HEAP_strdupA2W ( &lpszDeviceW, lpszDevice );
159 if (!NT_SUCCESS (Status))
160 SetLastError (RtlNtStatusToDosError(Status));
161 else
162 {
163 Status = HEAP_strdupA2W ( &lpszOutputW, lpszOutput );
164 if (!NT_SUCCESS (Status))
165 SetLastError (RtlNtStatusToDosError(Status));
166 else
167 {
168 if ( lpdvmInit )
169 dvmInitW = GdiConvertToDevmodeW((LPDEVMODEA)lpdvmInit);
170
171 RtlInitUnicodeString(&Driver, lpszDriverW);
172 RtlInitUnicodeString(&Device, lpszDeviceW);
173 RtlInitUnicodeString(&Output, lpszOutputW);
174 rc = NtGdiCreateIC ( &Driver,
175 &Device,
176 &Output,
177 lpdvmInit ? dvmInitW : NULL );
178 HEAP_free (dvmInitW);
179 HEAP_free ( lpszOutputW );
180 }
181 HEAP_free ( lpszDeviceW );
182 }
183 HEAP_free ( lpszDriverW );
184 }
185 return rc;
186 }
187
188
189 /*
190 * @implemented
191 */
192 BOOL
193 STDCALL
194 DeleteObject(HGDIOBJ hObject)
195 {
196 if (0 != ((DWORD) hObject & GDI_HANDLE_STOCK_MASK))
197 {
198 DPRINT1("Trying to delete system object 0x%x\n", hObject);
199 return TRUE;
200 }
201
202 /* deleting a handle that doesn't belong to the caller should be rather rarely
203 so for the sake of speed just try to delete it without checking validity */
204 return NtGdiDeleteObject(hObject);
205 }
206
207
208 /*
209 * @implemented
210 */
211 DWORD
212 STDCALL
213 GetRelAbs(
214 HDC hdc,
215 DWORD dwIgnore
216 )
217 {
218 return NtGdiGetRelAbs(hdc);
219 }
220
221 /*
222 * @implemented
223 */
224 LONG
225 STDCALL
226 GetDCOrg(
227 HDC hdc
228 )
229 {
230 // Officially obsolete by Microsoft
231 POINT Pt;
232 if (!NtGdiGetDCOrgEx(hdc, &Pt))
233 return 0;
234 return(MAKELONG(Pt.x, Pt.y));
235 }
236
237
238 /*
239 * @unimplemented
240 */
241 int
242 STDCALL
243 GetObjectA(HGDIOBJ Handle, int Size, LPVOID Buffer)
244 {
245 LOGFONTW LogFontW;
246 DWORD Type;
247 int Result;
248
249 Type = NtGdiGetObjectType(Handle);
250 if (0 == Type)
251 {
252 return 0;
253 }
254
255 if (OBJ_FONT == Type)
256 {
257 if (Size < sizeof(LOGFONTA))
258 {
259 SetLastError(ERROR_BUFFER_OVERFLOW);
260 return 0;
261 }
262 Result = NtGdiGetObject(Handle, sizeof(LOGFONTW), &LogFontW);
263 if (0 == Result)
264 {
265 return 0;
266 }
267 LogFontW2A((LPLOGFONTA) Buffer, &LogFontW);
268 Result = sizeof(LOGFONTA);
269 }
270 else
271 {
272 Result = NtGdiGetObject(Handle, Size, Buffer);
273 }
274
275 return Result;
276 }
277
278
279 /*
280 * @unimplemented
281 */
282 int
283 STDCALL
284 GetObjectW(HGDIOBJ Handle, int Size, LPVOID Buffer)
285 {
286 return NtGdiGetObject(Handle, Size, Buffer);
287 }
288
289
290 /*
291 * @implemented
292 */
293 COLORREF
294 STDCALL
295 GetDCBrushColor(
296 HDC hdc
297 )
298 {
299 return NtUserGetDCBrushColor(hdc);
300 }
301
302 /*
303 * @implemented
304 */
305 COLORREF
306 STDCALL
307 GetDCPenColor(
308 HDC hdc
309 )
310 {
311 return NtUserGetDCPenColor(hdc);
312 }
313
314 /*
315 * @implemented
316 */
317 COLORREF
318 STDCALL
319 SetDCBrushColor(
320 HDC hdc,
321 COLORREF crColor
322 )
323 {
324 return NtUserSetDCBrushColor(hdc, crColor);
325 }
326
327 /*
328 * @implemented
329 */
330 COLORREF
331 STDCALL
332 SetDCPenColor(
333 HDC hdc,
334 COLORREF crColor
335 )
336 {
337 return NtUserSetDCPenColor(hdc, crColor);
338 }
339
340
341 /*
342 * @implemented
343 */
344 HDC
345 STDCALL
346 ResetDCW(
347 HDC hdc,
348 CONST DEVMODEW *lpInitData
349 )
350 {
351 return NtGdiResetDC ( hdc, lpInitData );
352 }
353
354
355 /*
356 * @implemented
357 */
358 HDC
359 STDCALL
360 ResetDCA(
361 HDC hdc,
362 CONST DEVMODEA *lpInitData
363 )
364 {
365 LPDEVMODEW InitDataW;
366 HDC hDc;
367
368 InitDataW = GdiConvertToDevmodeW((LPDEVMODEA)lpInitData);
369
370 hDc = NtGdiResetDC ( hdc, InitDataW );
371 HEAP_free(InitDataW);
372 return hDc;
373 }
374
375
376 /*
377 * @implemented
378 */
379 int
380 STDCALL
381 StartDocW(
382 HDC hdc,
383 CONST DOCINFOW *a1
384 )
385 {
386 return NtGdiStartDoc ( hdc, (DOCINFOW *)a1 );
387 }
388
389
390 /*
391 * @implemented
392 */
393 DWORD
394 STDCALL
395 GetObjectType(
396 HGDIOBJ h
397 )
398 {
399 DWORD Ret = 0;
400
401 if(GdiIsHandleValid(h))
402 {
403 LONG Type = GDI_HANDLE_GET_TYPE(h);
404 switch(Type)
405 {
406 case GDI_OBJECT_TYPE_PEN:
407 Ret = OBJ_PEN;
408 break;
409 case GDI_OBJECT_TYPE_BRUSH:
410 Ret = OBJ_BRUSH;
411 break;
412 case GDI_OBJECT_TYPE_BITMAP:
413 Ret = OBJ_BITMAP;
414 break;
415 case GDI_OBJECT_TYPE_FONT:
416 Ret = OBJ_FONT;
417 break;
418 case GDI_OBJECT_TYPE_PALETTE:
419 Ret = OBJ_PAL;
420 break;
421 case GDI_OBJECT_TYPE_REGION:
422 Ret = OBJ_REGION;
423 break;
424 case GDI_OBJECT_TYPE_DC:
425 Ret = OBJ_DC;
426 break;
427 case GDI_OBJECT_TYPE_METADC:
428 Ret = OBJ_METADC;
429 break;
430 case GDI_OBJECT_TYPE_METAFILE:
431 Ret = OBJ_METAFILE;
432 break;
433 case GDI_OBJECT_TYPE_ENHMETAFILE:
434 Ret = OBJ_ENHMETAFILE;
435 break;
436 case GDI_OBJECT_TYPE_ENHMETADC:
437 Ret = OBJ_ENHMETADC;
438 break;
439 case GDI_OBJECT_TYPE_EXTPEN:
440 Ret = OBJ_EXTPEN;
441 break;
442 case GDI_OBJECT_TYPE_MEMDC:
443 Ret = OBJ_MEMDC;
444 break;
445
446 default:
447 DPRINT1("GetObjectType: Magic 0x%08x not implemented\n", Type);
448 break;
449 }
450 }
451
452 return Ret;
453 }