Implement ResetDC and PHYSICALOFFSET[X|Y] devcaps.
[wine] / dlls / ttydrv / bitmap.c
1 /*
2  * TTY bitmap driver
3  *
4  * Copyright 1999 Patrik Stridvall
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 "config.h"
22
23 #include <string.h>
24
25 #include "bitmap.h"
26 #include "gdi.h"
27 #include "ttydrv.h"
28 #include "winbase.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
32
33 /**********************************************************************/
34
35 extern const DC_FUNCTIONS *TTYDRV_DC_Funcs;  /* hack */
36
37 static LONG TTYDRV_DC_GetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count);
38 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count);
39
40 /***********************************************************************
41  *              TTYDRV_DC_AllocBitmap
42  */
43 TTYDRV_PHYSBITMAP *TTYDRV_DC_AllocBitmap(BITMAPOBJ *bitmap)
44 {
45   TTYDRV_PHYSBITMAP *physBitmap;
46   
47   if(!(physBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(TTYDRV_PHYSBITMAP)))) {
48     ERR("Can't alloc TTYDRV_PHYSBITMAP\n");
49     return NULL;
50   }
51
52   bitmap->physBitmap = physBitmap;
53   bitmap->funcs = TTYDRV_DC_Funcs;
54
55   return physBitmap;
56 }
57
58 /***********************************************************************
59  *           TTYDRV_DC_BitmapBits
60  */
61 LONG TTYDRV_DC_BitmapBits(HBITMAP hbitmap, void *bits, LONG count, WORD flags)
62 {
63   BITMAPOBJ *bitmap;
64   LONG result;
65
66   if(!(bitmap = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC)))
67     return FALSE;
68   
69   if(flags == DDB_GET)
70     result = TTYDRV_DC_GetBitmapBits(bitmap, bits, count);
71   else if(flags == DDB_SET)
72     result = TTYDRV_DC_SetBitmapBits(bitmap, bits, count);
73   else {
74     ERR("Unknown flags value %d\n", flags);
75     result = 0;
76   }
77   
78   GDI_ReleaseObj(hbitmap);
79   return result;
80 }
81
82 /***********************************************************************
83  *              TTYDRV_DC_CreateBitmap
84  */
85 BOOL TTYDRV_DC_CreateBitmap(HBITMAP hbitmap)
86 {
87   TTYDRV_PHYSBITMAP *physBitmap;
88   BITMAPOBJ *bitmap;
89
90   TRACE("(0x%04x)\n", hbitmap);
91
92   if(!(bitmap = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC)))
93     return FALSE;
94   
95   if(!(physBitmap = TTYDRV_DC_AllocBitmap(bitmap))) {
96     GDI_ReleaseObj(hbitmap);
97     return FALSE;
98   }
99  
100   /* Set bitmap bits */
101   if(bitmap->bitmap.bmBits) { 
102     TTYDRV_DC_BitmapBits(hbitmap, bitmap->bitmap.bmBits,
103                          bitmap->bitmap.bmHeight * bitmap->bitmap.bmWidthBytes,
104                          DDB_SET );
105   }
106
107   GDI_ReleaseObj(hbitmap);
108   
109   return TRUE;
110 }
111
112 /***********************************************************************
113  *              TTYDRV_DC_BITMAP_DeleteObject
114  */
115 BOOL TTYDRV_DC_BITMAP_DeleteObject(HBITMAP hbitmap, BITMAPOBJ *bitmap)
116 {
117   TRACE("(0x%04x, %p)\n", hbitmap, bitmap);
118
119   HeapFree(GetProcessHeap(), 0, bitmap->physBitmap);
120   bitmap->physBitmap = NULL;
121   bitmap->funcs = NULL;
122
123   return TRUE;
124 }
125
126 /***********************************************************************
127  *              TTYDRV_DC_GetBitmapBits
128  */
129 static LONG TTYDRV_DC_GetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
130 {
131   FIXME("(%p, %p, %ld): stub\n", bitmap, bits, count);
132
133   memset(bits, 0, count);
134
135   return count;
136 }
137
138 /***********************************************************************
139  *              SelectBitmap   (TTYDRV.@)
140  */
141 HBITMAP TTYDRV_SelectBitmap(TTYDRV_PDEVICE *physDev, HBITMAP hbitmap)
142 {
143   DC *dc = physDev->dc;
144   BITMAPOBJ *bitmap;
145
146   TRACE("(%p, 0x%04x)\n", dc, hbitmap);
147
148   if(!(dc->flags & DC_MEMORY)) 
149     return 0;
150
151   if (!(bitmap = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) return 0;
152   /* Assure that the bitmap device dependent */
153   if(!bitmap->physBitmap && !TTYDRV_DC_CreateBitmap(hbitmap))
154   {
155       GDI_ReleaseObj( hbitmap );
156       return 0;
157   }
158
159   if(bitmap->funcs != dc->funcs) {
160     ERR("Trying to select a non-TTY DDB into a TTY DC\n");
161     GDI_ReleaseObj( hbitmap );
162     return 0;
163   }
164
165   dc->totalExtent.left   = 0;
166   dc->totalExtent.top    = 0;
167   dc->totalExtent.right  = bitmap->bitmap.bmWidth;
168   dc->totalExtent.bottom = bitmap->bitmap.bmHeight;
169
170   /* FIXME: Should be done in the common code instead */
171   if(dc->hVisRgn) {
172     SetRectRgn(dc->hVisRgn, 0, 0,
173                bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
174   } else { 
175     HRGN hrgn;
176
177     if(!(hrgn = CreateRectRgn(0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight)))
178     {
179         GDI_ReleaseObj( hbitmap );
180         return 0;
181     }
182     dc->hVisRgn = hrgn;
183   }
184   GDI_ReleaseObj( hbitmap );
185   return hbitmap;
186 }
187
188 /***********************************************************************
189  *              TTYDRV_DC_SetBitmapBits
190  */
191 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
192 {
193   FIXME("(%p, %p, %ld): semistub\n", bitmap, bits, count);
194
195   return count;
196 }
197
198 /***********************************************************************
199  *              TTYDRV_BITMAP_CreateDIBSection
200  */
201 HBITMAP TTYDRV_BITMAP_CreateDIBSection(
202   TTYDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage,
203   LPVOID *bits, HANDLE section, DWORD offset)
204 {
205   FIXME("(%x, %p, %u, %p, 0x%04x, %ld): stub\n",
206         physDev->hdc, bmi, usage, bits, section, offset);
207
208   return (HBITMAP) NULL;
209 }
210
211 /***********************************************************************
212  *              TTYDRV_DC_SetDIBitsToDevice
213  */
214 INT TTYDRV_DC_SetDIBitsToDevice(TTYDRV_PDEVICE *physDev, INT xDest, INT yDest, DWORD cx,
215                                 DWORD cy, INT xSrc, INT ySrc,
216                                 UINT startscan, UINT lines, LPCVOID bits,
217                                 const BITMAPINFO *info, UINT coloruse)
218 {
219   FIXME("(%x, %d, %d, %ld, %ld, %d, %d, %u, %u, %p, %p, %u): stub\n",
220         physDev->hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse);
221
222   return 0;
223 }