Added regedit unit test, a couple minor changes to regedit.
[wine] / dlls / gdi / win16drv / graphics.c
1 /*
2  * Windows 16 bit device driver graphics functions
3  *
4  * Copyright 1997 John Harvey
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdio.h>
22
23 #include "win16drv/win16drv.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
27
28 /***********************************************************************
29  *           WIN16DRV_LineTo
30  */
31 BOOL
32 WIN16DRV_LineTo( PHYSDEV dev, INT x, INT y )
33 {
34     BOOL bRet ;
35     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
36     DC *dc = physDev->dc;
37     POINT16 points[2];
38
39     points[0].x = physDev->org.x + XLPTODP( dc, dc->CursPosX );
40     points[0].y = physDev->org.y + YLPTODP( dc, dc->CursPosY );
41     points[1].x = physDev->org.x + XLPTODP( dc, x );
42     points[1].y = physDev->org.y + YLPTODP( dc, y );
43     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
44                          OS_POLYLINE, 2, points,
45                          physDev->PenInfo,
46                          NULL,
47                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
48
49     dc->CursPosX = x;
50     dc->CursPosY = y;
51     return TRUE;
52 }
53
54
55 /***********************************************************************
56  *           WIN16DRV_Rectangle
57  */
58 BOOL
59 WIN16DRV_Rectangle(PHYSDEV dev, INT left, INT top, INT right, INT bottom)
60 {
61     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
62     DC *dc = physDev->dc;
63     BOOL bRet = 0;
64     POINT16 points[2];
65
66     TRACE("In WIN16DRV_Rectangle, x %d y %d DCOrgX %ld y %ld\n",
67            left, top, physDev->org.x, physDev->org.y);
68     TRACE("In WIN16DRV_Rectangle, VPortOrgX %d y %d\n",
69            dc->vportOrgX, dc->vportOrgY);
70     points[0].x = XLPTODP(dc, left);
71     points[0].y = YLPTODP(dc, top);
72
73     points[1].x = XLPTODP(dc, right);
74     points[1].y = YLPTODP(dc, bottom);
75     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
76                            OS_RECTANGLE, 2, points,
77                            physDev->PenInfo,
78                            physDev->BrushInfo,
79                            win16drv_SegPtr_DrawMode, dc->hClipRgn);
80     return bRet;
81 }
82
83
84
85
86 /***********************************************************************
87  *           WIN16DRV_Polygon
88  */
89 BOOL
90 WIN16DRV_Polygon(PHYSDEV dev, const POINT* pt, INT count )
91 {
92     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
93     DC *dc = physDev->dc;
94     BOOL bRet = 0;
95     LPPOINT16 points;
96     int i;
97
98     if(count < 2) return TRUE;
99     if(pt[0].x != pt[count-1].x || pt[0].y != pt[count-1].y)
100         count++; /* Ensure polygon is closed */
101
102     points = HeapAlloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
103     if(points == NULL) return FALSE;
104
105     for (i = 0; i < count - 1; i++)
106     {
107       points[i].x = XLPTODP( dc, pt[i].x );
108       points[i].y = YLPTODP( dc, pt[i].y );
109     }
110     points[count-1].x = points[0].x;
111     points[count-1].y = points[0].y;
112     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
113                          OS_WINDPOLYGON, count, points,
114                          physDev->PenInfo,
115                          physDev->BrushInfo,
116                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
117     HeapFree( GetProcessHeap(), 0, points );
118     return bRet;
119 }
120
121
122 /***********************************************************************
123  *           WIN16DRV_Polyline
124  */
125 BOOL
126 WIN16DRV_Polyline(PHYSDEV dev, const POINT* pt, INT count )
127 {
128     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
129     DC *dc = physDev->dc;
130     BOOL bRet = 0;
131     LPPOINT16 points;
132     int i;
133
134     if(count < 2) return TRUE;
135
136     points = HeapAlloc( GetProcessHeap(), 0, count * sizeof(POINT16) );
137     if(points == NULL) return FALSE;
138
139     for (i = 0; i < count; i++)
140     {
141       points[i].x = XLPTODP( dc, pt[i].x );
142       points[i].y = YLPTODP( dc, pt[i].y );
143     }
144     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
145                          OS_POLYLINE, count, points,
146                          physDev->PenInfo,
147                          NULL,
148                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
149     HeapFree( GetProcessHeap(), 0, points );
150     return bRet;
151 }
152
153
154
155 /***********************************************************************
156  *           WIN16DRV_Ellipse
157  */
158 BOOL
159 WIN16DRV_Ellipse(PHYSDEV dev, INT left, INT top, INT right, INT bottom)
160 {
161     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
162     DC *dc = physDev->dc;
163     BOOL bRet = 0;
164     POINT16 points[2];
165
166     TRACE("In WIN16DRV_Ellipse, x %d y %d DCOrgX %ld y %ld\n",
167           left, top, physDev->org.x, physDev->org.y);
168     TRACE("In WIN16DRV_Ellipse, VPortOrgX %d y %d\n", dc->vportOrgX, dc->vportOrgY);
169     points[0].x = XLPTODP(dc, left);
170     points[0].y = YLPTODP(dc, top);
171
172     points[1].x = XLPTODP(dc, right);
173     points[1].y = YLPTODP(dc, bottom);
174
175     bRet = PRTDRV_Output(physDev->segptrPDEVICE,
176                          OS_ELLIPSE, 2, points,
177                          physDev->PenInfo,
178                          physDev->BrushInfo,
179                          win16drv_SegPtr_DrawMode, dc->hClipRgn);
180     return bRet;
181 }