Added LGPL standard comment, and copyright notices where necessary.
[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  *              TTYDRV_DC_BITMAP_SelectObject
140  */
141 HBITMAP TTYDRV_DC_BITMAP_SelectObject(DC *dc, HBITMAP hbitmap, BITMAPOBJ *bitmap)
142 {
143   HBITMAP hPreviousBitmap;
144
145   TRACE("(%p, 0x%04x, %p)\n", dc, hbitmap, bitmap);
146
147   if(!(dc->flags & DC_MEMORY)) 
148     return 0;
149
150   /* Assure that the bitmap device dependent */
151   if(!bitmap->physBitmap && !TTYDRV_DC_CreateBitmap(hbitmap))
152     return 0;
153
154   if(bitmap->funcs != dc->funcs) {
155     ERR("Trying to select a non-TTY DDB into a TTY DC\n");
156     return 0;
157   }
158
159   dc->totalExtent.left   = 0;
160   dc->totalExtent.top    = 0;
161   dc->totalExtent.right  = bitmap->bitmap.bmWidth;
162   dc->totalExtent.bottom = bitmap->bitmap.bmHeight;
163
164   /* FIXME: Should be done in the common code instead */
165   if(dc->hVisRgn) {
166     SetRectRgn(dc->hVisRgn, 0, 0,
167                bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
168   } else { 
169     HRGN hrgn;
170
171     if(!(hrgn = CreateRectRgn(0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight)))
172       return 0;
173
174     dc->hVisRgn = hrgn;
175   }
176
177   hPreviousBitmap = dc->hBitmap;
178   dc->hBitmap = hbitmap;
179
180   return hPreviousBitmap;
181 }
182
183 /***********************************************************************
184  *              TTYDRV_DC_SetBitmapBits
185  */
186 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
187 {
188   FIXME("(%p, %p, %ld): semistub\n", bitmap, bits, count);
189
190   return count;
191 }
192
193 /***********************************************************************
194  *              TTYDRV_BITMAP_CreateDIBSection
195  */
196 HBITMAP TTYDRV_BITMAP_CreateDIBSection(
197   DC *dc, BITMAPINFO *bmi, UINT usage,
198   LPVOID *bits, HANDLE section, DWORD offset)
199 {
200   FIXME("(%p, %p, %u, %p, 0x%04x, %ld): stub\n",
201         dc, bmi, usage, bits, section, offset);
202
203   return (HBITMAP) NULL;
204 }
205
206 /***********************************************************************
207  *              TTYDRV_BITMAP_DeleteDIBSection
208  */
209 void TTYDRV_BITMAP_DeleteDIBSection(BITMAPOBJ *bmp)
210 {
211   FIXME("(%p): stub\n", bmp);
212 }
213
214 /***********************************************************************
215  *              TTYDRV_BITMAP_SetDIBColorTable
216  */
217 UINT TTYDRV_BITMAP_SetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, const RGBQUAD *colors)
218 {
219   FIXME("(%p): stub\n", bmp);
220   return 0;
221 }
222
223 /***********************************************************************
224  *              TTYDRV_BITMAP_GetDIBColorTable
225  */
226 UINT TTYDRV_BITMAP_GetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, RGBQUAD *colors)
227 {
228   FIXME("(%p): stub\n", bmp);
229   return 0;
230 }
231
232 /***********************************************************************
233  *              TTYDRV_BITMAP_Lock
234  */
235 INT TTYDRV_BITMAP_Lock(BITMAPOBJ *bmp, INT req, BOOL lossy)
236 {
237   FIXME("(%p): stub\n", bmp);
238   return DIB_Status_None;
239 }
240
241 /***********************************************************************
242  *              TTYDRV_BITMAP_Unlock
243  */
244 void TTYDRV_BITMAP_Unlock(BITMAPOBJ *bmp, BOOL commit)
245 {
246   FIXME("(%p): stub\n", bmp);
247 }
248
249 /***********************************************************************
250  *              TTYDRV_BITMAP_GetDIBits
251  */
252 INT TTYDRV_BITMAP_GetDIBits(
253   BITMAPOBJ *bmp, DC *dc, UINT startscan, UINT lines, 
254   LPVOID bits, BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap)
255 {
256   FIXME("(%p, %p, %u, %u, %p, %p, %u, 0x%04x): stub\n",
257         bmp, dc, startscan, lines, bits, info, coloruse, hbitmap);
258
259   return 0;
260 }
261
262
263 /***********************************************************************
264  *              TTYDRV_BITMAP_SetDIBits
265  */
266 INT TTYDRV_BITMAP_SetDIBits(
267   BITMAPOBJ *bmp, DC *dc, UINT startscan, UINT lines, 
268   LPCVOID bits, const BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap)
269 {
270   FIXME("(%p, %p, %u, %u, %p, %p, %u, 0x%04x): stub\n",
271         bmp, dc, startscan, lines, bits, info, coloruse, hbitmap);
272
273   return 0;
274 }
275
276 /***********************************************************************
277  *              TTYDRV_DC_SetDIBitsToDevice
278  */
279 INT TTYDRV_DC_SetDIBitsToDevice(DC *dc, INT xDest, INT yDest, DWORD cx,
280                                 DWORD cy, INT xSrc, INT ySrc,
281                                 UINT startscan, UINT lines, LPCVOID bits,
282                                 const BITMAPINFO *info, UINT coloruse)
283 {
284   FIXME("(%p, %d, %d, %ld, %ld, %d, %d, %u, %u, %p, %p, %u): stub\n",
285         dc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse);
286
287   return 0;
288 }