Better implementation of GetCalendarInfo{A,W}, not perfect.
[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 (!(bitmap = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) return 0;
149   /* Assure that the bitmap device dependent */
150   if(!bitmap->physBitmap && !TTYDRV_DC_CreateBitmap(hbitmap))
151   {
152       GDI_ReleaseObj( hbitmap );
153       return 0;
154   }
155
156   if(bitmap->funcs != dc->funcs) {
157     ERR("Trying to select a non-TTY DDB into a TTY DC\n");
158     GDI_ReleaseObj( hbitmap );
159     return 0;
160   }
161
162   GDI_ReleaseObj( hbitmap );
163   return hbitmap;
164 }
165
166 /***********************************************************************
167  *              TTYDRV_DC_SetBitmapBits
168  */
169 static LONG TTYDRV_DC_SetBitmapBits(BITMAPOBJ *bitmap, void *bits, LONG count)
170 {
171   FIXME("(%p, %p, %ld): semistub\n", bitmap, bits, count);
172
173   return count;
174 }
175
176 /***********************************************************************
177  *              TTYDRV_BITMAP_CreateDIBSection
178  */
179 HBITMAP TTYDRV_BITMAP_CreateDIBSection(
180   TTYDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage,
181   LPVOID *bits, HANDLE section, DWORD offset)
182 {
183   FIXME("(%x, %p, %u, %p, 0x%04x, %ld): stub\n",
184         physDev->hdc, bmi, usage, bits, section, offset);
185
186   return (HBITMAP) NULL;
187 }
188
189 /***********************************************************************
190  *              TTYDRV_DC_SetDIBitsToDevice
191  */
192 INT TTYDRV_DC_SetDIBitsToDevice(TTYDRV_PDEVICE *physDev, INT xDest, INT yDest, DWORD cx,
193                                 DWORD cy, INT xSrc, INT ySrc,
194                                 UINT startscan, UINT lines, LPCVOID bits,
195                                 const BITMAPINFO *info, UINT coloruse)
196 {
197   FIXME("(%x, %d, %d, %ld, %ld, %d, %d, %u, %u, %p, %p, %u): stub\n",
198         physDev->hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse);
199
200   return 0;
201 }