Prevent deletion of system-owned objects like brushes returned by
[reactos.git] / reactos / lib / gdi32 / objects / dc.c
1 #ifdef UNICODE
2 #undef UNICODE
3 #endif
4
5 #undef WIN32_LEAN_AND_MEAN
6 #include <windows.h>
7 #include <ddk/ntddk.h>
8 #include <win32k/kapi.h>
9 #include <rosrtl/logfont.h>
10
11 #define NDEBUG
12 #include <debug.h>
13
14 /*
15 * @implemented
16 */
17 DWORD
18 STDCALL
19 GetObjectType(
20 HGDIOBJ a0
21 )
22 {
23 return NtGdiGetObjectType(a0);
24 }
25
26
27
28 /*
29 * @implemented
30 */
31 BOOL
32 STDCALL
33 DPtoLP(
34 HDC a0,
35 LPPOINT a1,
36 int a2
37 )
38 {
39 return NtGdiDPtoLP(a0, a1, a2);
40 }
41
42
43 /*
44 * @implemented
45 */
46 COLORREF
47 STDCALL
48 SetBkColor(
49 HDC a0,
50 COLORREF a1
51 )
52 {
53 return NtGdiSetBkColor(a0, a1);
54 }
55
56
57 /*
58 * @implemented
59 */
60 int
61 STDCALL
62 GetGraphicsMode(
63 HDC a0
64 )
65 {
66 return NtGdiGetGraphicsMode(a0);
67 }
68
69
70 /*
71 * @implemented
72 */
73 int
74 STDCALL
75 SetGraphicsMode(
76 HDC hdc,
77 int iMode
78 )
79 {
80 return NtGdiSetGraphicsMode(hdc, iMode);
81 }
82
83
84 /*
85 * @implemented
86 */
87 int
88 STDCALL
89 GetMapMode(
90 HDC a0
91 )
92 {
93 return NtGdiGetMapMode(a0);
94 }
95
96 /*
97 * @implemented
98 */
99 BOOL
100 STDCALL
101 GetCurrentPositionEx(
102 HDC a0,
103 LPPOINT a1
104 )
105 {
106 return NtGdiGetCurrentPositionEx(a0, a1);
107 }
108
109
110 /*
111 * @implemented
112 */
113 COLORREF
114 STDCALL
115 GetBkColor(
116 HDC a0
117 )
118 {
119 return NtGdiGetBkColor(a0);
120 }
121
122
123 /*
124 * @implemented
125 */
126 int
127 STDCALL
128 GetBkMode(
129 HDC a0
130 )
131 {
132 return NtGdiGetBkMode(a0);
133 }
134
135 /*
136 * @implemented
137 */
138 BOOL
139 STDCALL
140 GetBrushOrgEx(
141 HDC a0,
142 LPPOINT a1
143 )
144 {
145 return NtGdiGetBrushOrgEx(a0, a1);
146 }
147
148
149 /*
150 * @implemented
151 */
152 int
153 STDCALL
154 GetROP2(
155 HDC a0
156 )
157 {
158 return NtGdiGetROP2(a0);
159
160 }
161
162
163 /*
164 * @implemented
165 */
166 int
167 STDCALL
168 GetStretchBltMode(
169 HDC a0
170 )
171 {
172 return NtGdiGetStretchBltMode(a0);
173
174 }
175
176
177
178 /*
179 * @implemented
180 */
181 UINT
182 STDCALL
183 GetTextAlign(
184 HDC hDc
185 )
186 {
187 return NtGdiGetTextAlign(hDc);
188
189 }
190
191
192 /*
193 * @implemented
194 */
195 COLORREF
196 STDCALL
197 GetTextColor(
198 HDC hDc
199 )
200 {
201 return NtGdiGetTextColor(hDc);
202
203 }
204
205
206 /*
207 * @implemented
208 */
209 BOOL
210 STDCALL
211 GetViewportExtEx(
212 HDC hDc,
213 LPSIZE lpSize
214 )
215 {
216 return NtGdiGetViewportExtEx(hDc, lpSize);
217
218 }
219
220
221 /*
222 * @implemented
223 */
224 BOOL
225 STDCALL
226 GetViewportOrgEx(
227 HDC hDc,
228 LPPOINT lpPoint
229 )
230 {
231 return NtGdiGetViewportOrgEx(hDc, lpPoint);
232
233 }
234
235
236 /*
237 * @implemented
238 */
239 BOOL
240 STDCALL
241 GetWindowExtEx(
242 HDC hDc,
243 LPSIZE lpSize
244 )
245 {
246 return NtGdiGetWindowExtEx(hDc, lpSize);
247 }
248
249
250 /*
251 * @implemented
252 */
253 BOOL
254 STDCALL
255 GetWindowOrgEx(
256 HDC hDc,
257 LPPOINT lpPoint
258 )
259 {
260 return NtGdiGetWindowOrgEx(hDc, lpPoint);
261 }
262
263
264 /*
265 * @implemented
266 */
267 int
268 STDCALL
269 SetBkMode(
270 HDC a0,
271 int a1
272 )
273 {
274 return NtGdiSetBkMode(a0, a1);
275
276 }
277
278
279 /*
280 * @implemented
281 */
282 int
283 STDCALL
284 SetROP2(
285 HDC a0,
286 int a1
287 )
288 {
289 return NtGdiSetROP2(a0, a1);
290 }
291
292
293 /*
294 * @implemented
295 */
296 int
297 STDCALL
298 SetStretchBltMode(
299 HDC a0,
300 int a1
301 )
302 {
303 return NtGdiSetStretchBltMode(a0, a1);
304
305 }
306
307
308 /*
309 * @implemented
310 */
311 DWORD
312 STDCALL
313 GetRelAbs(
314 HDC a0,
315 DWORD a1
316 )
317 {
318 return NtGdiGetRelAbs(a0);
319
320 }
321
322
323 /*
324 * @implemented
325 */
326 HGDIOBJ STDCALL
327 GetStockObject(int Index)
328 {
329 return(NtGdiGetStockObject(Index));
330 }
331
332
333 /*
334 * @implemented
335 */
336 int STDCALL
337 GetClipBox(HDC hDc, LPRECT Rect)
338 {
339 return(NtGdiGetClipBox(hDc, Rect));
340 }
341
342
343 /*
344 * @implemented
345 */
346 int
347 STDCALL
348 GetPolyFillMode(
349 HDC a0
350 )
351 {
352 return NtGdiGetPolyFillMode(a0);
353 }
354
355
356 /*
357 * @implemented
358 */
359 HDC
360 STDCALL
361 CreateDCA (
362 LPCSTR lpszDriver,
363 LPCSTR lpszDevice,
364 LPCSTR lpszOutput,
365 CONST DEVMODEA * lpInitData
366 )
367 {
368 ANSI_STRING DriverA, DeviceA, OutputA;
369 UNICODE_STRING DriverU, DeviceU, OutputU;
370 HDC hDC;
371 DEVMODEW *lpInitDataW;
372
373 /*
374 * If needed, convert to Unicode
375 * any string parameter.
376 */
377
378 if (NULL != lpszDriver)
379 {
380 RtlInitAnsiString(&DriverA, (LPSTR)lpszDriver);
381 RtlAnsiStringToUnicodeString(&DriverU, &DriverA, TRUE);
382 } else
383 DriverU.Buffer = NULL;
384 if (NULL != lpszDevice)
385 {
386 RtlInitAnsiString(&DeviceA, (LPSTR)lpszDevice);
387 RtlAnsiStringToUnicodeString(&DeviceU, &DeviceA, TRUE);
388 } else
389 DeviceU.Buffer = NULL;
390 if (NULL != lpszOutput)
391 {
392 RtlInitAnsiString(&OutputA, (LPSTR)lpszOutput);
393 RtlAnsiStringToUnicodeString(&OutputU, &OutputA, TRUE);
394 } else
395 OutputU.Buffer = NULL;
396
397 if (NULL != lpInitData)
398 {
399 // lpInitDataW = HeapAllocMem(
400 } else
401 lpInitDataW = NULL;
402
403 /*
404 * Call the Unicode version
405 * of CreateDC.
406 */
407
408 hDC = CreateDCW (
409 DriverU.Buffer,
410 DeviceU.Buffer,
411 OutputU.Buffer,
412 NULL);
413 // lpInitDataW);
414 /*
415 * Free Unicode parameters.
416 */
417 RtlFreeUnicodeString(&DriverU);
418 RtlFreeUnicodeString(&DeviceU);
419 RtlFreeUnicodeString(&OutputU);
420
421 /*
422 * Return the possible DC handle.
423 */
424
425 return hDC;
426 }
427
428
429 /*
430 * @implemented
431 */
432 HDC
433 STDCALL
434 CreateDCW (
435 LPCWSTR lpwszDriver,
436 LPCWSTR lpwszDevice,
437 LPCWSTR lpwszOutput,
438 CONST DEVMODEW * lpInitData
439 )
440 {
441 UNICODE_STRING Driver, Device, Output;
442
443 if(lpwszDriver)
444 RtlInitUnicodeString(&Driver, lpwszDriver);
445 if(lpwszDevice)
446 RtlInitUnicodeString(&Driver, lpwszDevice);
447 if(lpwszOutput)
448 RtlInitUnicodeString(&Driver, lpwszOutput);
449
450 return NtGdiCreateDC((lpwszDriver ? &Driver : NULL),
451 (lpwszDevice ? &Device : NULL),
452 (lpwszOutput ? &Output : NULL),
453 (PDEVMODEW)lpInitData);
454 }
455
456
457 /*
458 * @implemented
459 */
460 BOOL STDCALL DeleteDC( HDC hDC )
461 {
462 return NtGdiDeleteDC( hDC );
463 }
464
465
466 /*
467 * @implemented
468 */
469 HDC
470 STDCALL
471 CreateCompatibleDC(
472 HDC hDC
473 )
474 {
475 return NtGdiCreateCompatableDC(hDC);
476 }
477
478
479 /*
480 * @implemented
481 */
482 HGDIOBJ
483 STDCALL
484 SelectObject(
485 HDC hDC,
486 HGDIOBJ hGDIObj
487 )
488 {
489 return NtGdiSelectObject(hDC, hGDIObj);
490 }
491
492
493 /*
494 * @implemented
495 */
496 int
497 STDCALL
498 SetMapMode(
499 HDC a0,
500 int a1
501 )
502 {
503 return NtGdiSetMapMode( a0, a1 );
504 }
505
506
507 /*
508 * @implemented
509 */
510 BOOL
511 STDCALL
512 SetViewportOrgEx(
513 HDC a0,
514 int a1,
515 int a2,
516 LPPOINT a3
517 )
518 {
519 return NtGdiSetViewportOrgEx( a0, a1, a2, a3 );
520 }
521
522
523 /*
524 * @implemented
525 */
526 BOOL
527 STDCALL
528 OffsetViewportOrgEx(
529 HDC DC,
530 int XOffset,
531 int YOffset,
532 LPPOINT Point
533 )
534 {
535 return NtGdiOffsetViewportOrgEx(DC, XOffset, YOffset, Point);
536 }
537
538
539 /*
540 * @implemented
541 */
542 BOOL
543 STDCALL
544 SetWindowOrgEx(
545 HDC a0,
546 int a1,
547 int a2,
548 LPPOINT a3
549 )
550 {
551 return NtGdiSetWindowOrgEx( a0, a1, a2, a3 );
552 }
553
554
555 /*
556 * @implemented
557 */
558 BOOL
559 STDCALL
560 DeleteObject(HGDIOBJ Obj)
561 {
562 if (0 != ((DWORD) Obj & 0x00800000))
563 {
564 DPRINT1("Trying to delete system object 0x%x\n", Obj);
565 return FALSE;
566 }
567
568 return NtGdiDeleteObject(Obj);
569 }
570
571
572 /*
573 * @implemented
574 */
575 HPALETTE
576 STDCALL
577 SelectPalette(
578 HDC a0,
579 HPALETTE a1,
580 BOOL a2
581 )
582 {
583 return NtGdiSelectPalette( a0, a1,a2 );
584 }
585
586
587 /*
588 * @implemented
589 */
590 UINT
591 STDCALL
592 RealizePalette(
593 HDC a0
594 )
595 {
596 return NtGdiRealizePalette( a0 );
597 }
598
599
600 /*
601 * @implemented
602 */
603 BOOL
604 STDCALL
605 LPtoDP(
606 HDC a0,
607 LPPOINT a1,
608 int a2
609 )
610 {
611 return NtGdiLPtoDP(a0, a1, a2);
612 }
613
614
615 /*
616 * @implemented
617 */
618 int
619 STDCALL
620 SetPolyFillMode(
621 HDC a0,
622 int a1
623 )
624 {
625 return NtGdiSetPolyFillMode(a0, a1);
626 }
627
628
629 /*
630 * @implemented
631 */
632 int
633 STDCALL
634 GetDeviceCaps(
635 HDC DC,
636 int Index
637 )
638 {
639 return NtGdiGetDeviceCaps(DC, Index);
640 }
641
642 /*
643 * @implemented
644 */
645 HPALETTE
646 STDCALL
647 CreatePalette(
648 CONST LOGPALETTE *a0
649 )
650 {
651 return NtGdiCreatePalette((CONST PLOGPALETTE)a0);
652 }
653
654 /*
655 * @implemented
656 */
657 COLORREF
658 STDCALL
659 GetNearestColor(
660 HDC a0,
661 COLORREF a1
662 )
663 {
664 return NtGdiGetNearestColor(a0,a1);
665 }
666
667 /*
668 * @implemented
669 */
670 UINT
671 STDCALL
672 GetNearestPaletteIndex(
673 HPALETTE a0,
674 COLORREF a1
675 )
676 {
677 return NtGdiGetNearestPaletteIndex(a0,a1);
678 }
679
680 /*
681 * @implemented
682 */
683 UINT
684 STDCALL
685 GetPaletteEntries(
686 HPALETTE a0,
687 UINT a1,
688 UINT a2,
689 LPPALETTEENTRY a3
690 )
691 {
692 return NtGdiGetPaletteEntries(a0,a1,a2,a3);
693 }
694
695 /*
696 * @implemented
697 */
698 UINT
699 STDCALL
700 GetSystemPaletteEntries(
701 HDC a0,
702 UINT a1,
703 UINT a2,
704 LPPALETTEENTRY a3
705 )
706 {
707 return NtGdiGetSystemPaletteEntries(a0,a1,a2,a3);
708 }
709
710 /*
711 * @implemented
712 */
713 BOOL
714 STDCALL
715 RestoreDC(
716 HDC a0,
717 int a1
718 )
719 {
720 return NtGdiRestoreDC(a0,a1);
721 }
722
723
724 /*
725 * @implemented
726 */
727 int
728 STDCALL
729 SaveDC(
730 HDC a0
731 )
732 {
733 return NtGdiSaveDC(a0);
734 }
735
736 /*
737 * @implemented
738 */
739 UINT
740 STDCALL
741 SetPaletteEntries(
742 HPALETTE a0,
743 UINT a1,
744 UINT a2,
745 CONST PALETTEENTRY *a3
746 )
747 {
748 return NtGdiSetPaletteEntries(a0,a1,a2,(CONST PPALETTEENTRY)a3);
749 }
750
751 /*
752 * @implemented
753 */
754 BOOL
755 STDCALL
756 GetWorldTransform(
757 HDC hdc,
758 LPXFORM a1
759 )
760 {
761 return NtGdiGetWorldTransform(hdc,a1);
762 }
763
764 /*
765 * @implemented
766 */
767 BOOL
768 STDCALL
769 SetWorldTransform(
770 HDC a0,
771 CONST XFORM *a1
772 )
773 {
774 return NtGdiSetWorldTransform(a0,(CONST PXFORM)a1);
775 }
776
777 /*
778 * @implemented
779 */
780 BOOL
781 STDCALL
782 ModifyWorldTransform(
783 HDC a0,
784 CONST XFORM *a1,
785 DWORD a2
786 )
787 {
788 return NtGdiModifyWorldTransform(a0,(CONST PXFORM)a1,a2);
789 }
790
791 /*
792 * @implemented
793 */
794 BOOL
795 STDCALL
796 CombineTransform(
797 LPXFORM a0,
798 CONST XFORM *a1,
799 CONST XFORM *a2
800 )
801 {
802 return NtGdiCombineTransform(a0,(CONST PXFORM)a1,(CONST PXFORM)a2);
803 }
804
805 /*
806 * @implemented
807 */
808 UINT
809 STDCALL
810 SetDIBColorTable(
811 HDC hdc,
812 UINT a1,
813 UINT a2,
814 CONST RGBQUAD *a3
815 )
816 {
817 return NtGdiSetDIBColorTable(hdc,a1,a2,(CONST PRGBQUAD)a3);
818 }
819
820 /*
821 * @implemented
822 */
823 HPALETTE
824 STDCALL
825 CreateHalftonePalette(
826 HDC hdc
827 )
828 {
829 return NtGdiCreateHalftonePalette(hdc);
830 }
831
832 /*
833 * @implemented
834 */
835 BOOL
836 STDCALL
837 SetViewportExtEx(
838 HDC a0,
839 int a1,
840 int a2,
841 LPSIZE a3
842 )
843 {
844 return NtGdiSetViewportExtEx(a0,a1,a2,a3);
845 }
846
847 /*
848 * @implemented
849 */
850 BOOL
851 STDCALL
852 SetWindowExtEx(
853 HDC a0,
854 int a1,
855 int a2,
856 LPSIZE a3
857 )
858 {
859 return NtGdiSetWindowExtEx(a0,a1,a2,a3);
860 }
861
862 /*
863 * @implemented
864 */
865 BOOL
866 STDCALL
867 OffsetWindowOrgEx(
868 HDC a0,
869 int a1,
870 int a2,
871 LPPOINT a3
872 )
873 {
874 return NtGdiOffsetWindowOrgEx(a0,a1,a2,a3);
875 }
876
877 /*
878 * @implemented
879 */
880 BOOL
881 STDCALL
882 SetBitmapDimensionEx(
883 HBITMAP a0,
884 int a1,
885 int a2,
886 LPSIZE a3
887 )
888 {
889 return NtGdiSetBitmapDimensionEx(a0,a1,a2,a3);
890 }
891
892 /*
893 * @implemented
894 */
895 BOOL
896 STDCALL
897 GetDCOrgEx(
898 HDC a0,
899 LPPOINT a1
900 )
901 {
902 return NtGdiGetDCOrgEx(a0,a1);
903 }
904
905 /*
906 * @implemented
907 */
908 LONG
909 STDCALL
910 GetDCOrg(
911 HDC a0
912 )
913 {
914 // Officially obsolete by Microsoft
915 POINT Pt;
916 if (!NtGdiGetDCOrgEx(a0,&Pt))
917 return 0;
918 return(MAKELONG(Pt.x, Pt.y));
919 }
920
921 /*
922 * @implemented
923 */
924 BOOL
925 STDCALL
926 RectVisible(
927 HDC a0,
928 CONST RECT *a1
929 )
930 {
931 return NtGdiRectVisible(a0,(RECT *)a1);
932 }
933
934 /*
935 * @implemented
936 */
937 int
938 STDCALL
939 ExtEscape(
940 HDC a0,
941 int a1,
942 int a2,
943 LPCSTR a3,
944 int a4,
945 LPSTR a5
946 )
947 {
948 return NtGdiExtEscape(a0, a1, a2, a3, a4, a5);
949 }
950
951
952 /*
953 * @unimplemented
954 */
955 int
956 STDCALL
957 GetObjectA(HGDIOBJ Handle, int Size, LPVOID Buffer)
958 {
959 LOGFONTW LogFontW;
960 DWORD Type;
961 int Result;
962
963 Type = GetObjectType(Handle);
964 if (0 == Type)
965 {
966 return 0;
967 }
968
969 if (OBJ_FONT == Type)
970 {
971 if (Size < sizeof(LOGFONTA))
972 {
973 SetLastError(ERROR_BUFFER_OVERFLOW);
974 return 0;
975 }
976 Result = NtGdiGetObject(Handle, sizeof(LOGFONTW), &LogFontW);
977 if (0 == Result)
978 {
979 return 0;
980 }
981 RosRtlLogFontW2A((LPLOGFONTA) Buffer, &LogFontW);
982 Result = sizeof(LOGFONTA);
983 }
984 else
985 {
986 Result = NtGdiGetObject(Handle, Size, Buffer);
987 }
988
989 return Result;
990 }
991
992
993 /*
994 * @unimplemented
995 */
996 int
997 STDCALL
998 GetObjectW(HGDIOBJ Handle, int Size, LPVOID Buffer)
999 {
1000 return NtGdiGetObject(Handle, Size, Buffer);
1001 }