Changed the GDI driver interface to pass an opaque PHYSDEV pointer
[wine] / dlls / ttydrv / dc.c
1 /*
2  * TTY DC 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 "gdi.h"
24 #include "bitmap.h"
25 #include "palette.h"
26 #include "ttydrv.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(ttydrv);
31
32 /**********************************************************************/
33
34 PALETTE_DRIVER TTYDRV_PALETTE_Driver = 
35 {
36   TTYDRV_PALETTE_SetMapping,
37   TTYDRV_PALETTE_UpdateMapping,
38   TTYDRV_PALETTE_IsDark
39 };
40
41 const DC_FUNCTIONS *TTYDRV_DC_Funcs = NULL;  /* hack */
42
43 /**********************************************************************
44  *           TTYDRV_GDI_Initialize
45  */
46 BOOL TTYDRV_GDI_Initialize(void)
47 {
48   PALETTE_Driver = &TTYDRV_PALETTE_Driver;
49
50   return TTYDRV_PALETTE_Initialize();
51 }
52
53 /***********************************************************************
54  *           TTYDRV_DC_CreateDC
55  */
56 BOOL TTYDRV_DC_CreateDC(DC *dc, LPCSTR driver, LPCSTR device,
57                         LPCSTR output, const DEVMODEA *initData)
58 {
59   TTYDRV_PDEVICE *physDev;
60   BITMAPOBJ *bmp;
61
62   TRACE("(%p, %s, %s, %s, %p)\n",
63     dc, debugstr_a(driver), debugstr_a(device), 
64     debugstr_a(output), initData);
65
66   if (!TTYDRV_DC_Funcs) TTYDRV_DC_Funcs = dc->funcs;  /* hack */
67
68   dc->physDev = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
69                           sizeof(TTYDRV_PDEVICE));  
70   if(!dc->physDev) {
71     ERR("Can't allocate physDev\n");
72     return FALSE;
73   }
74   physDev = (TTYDRV_PDEVICE *) dc->physDev;
75   physDev->hdc = dc->hSelf;
76   physDev->dc = dc;
77
78   if(dc->flags & DC_MEMORY){
79     physDev->window = NULL;
80     physDev->cellWidth = 1;
81     physDev->cellHeight = 1;
82
83     TTYDRV_DC_CreateBitmap(dc->hBitmap);
84     bmp = (BITMAPOBJ *) GDI_GetObjPtr(dc->hBitmap, BITMAP_MAGIC);
85                                    
86     dc->bitsPerPixel = bmp->bitmap.bmBitsPixel;
87     
88     dc->totalExtent.left   = 0;
89     dc->totalExtent.top    = 0;
90     dc->totalExtent.right  = bmp->bitmap.bmWidth;
91     dc->totalExtent.bottom = bmp->bitmap.bmHeight;
92     dc->hVisRgn            = CreateRectRgnIndirect( &dc->totalExtent );
93     
94     GDI_ReleaseObj( dc->hBitmap );
95   } else {
96     physDev->window = root_window;
97     physDev->cellWidth = cell_width;
98     physDev->cellHeight = cell_height;
99     
100     dc->bitsPerPixel       = 1;
101     dc->totalExtent.left   = 0;
102     dc->totalExtent.top    = 0;
103     dc->totalExtent.right  = cell_width * screen_cols;
104     dc->totalExtent.bottom = cell_height * screen_rows;
105     dc->hVisRgn            = CreateRectRgnIndirect( &dc->totalExtent );    
106   }
107
108   return TRUE;
109 }
110
111 /***********************************************************************
112  *           TTYDRV_DC_DeleteDC
113  */
114 BOOL TTYDRV_DC_DeleteDC(TTYDRV_PDEVICE *physDev)
115 {
116     TRACE("(%x)\n", physDev->hdc);
117
118     physDev->dc->physDev = NULL;
119     HeapFree( GetProcessHeap(), 0, physDev );
120     return TRUE;
121 }
122
123
124 /***********************************************************************
125  *           GetDeviceCaps    (TTYDRV.@)
126  */
127 INT TTYDRV_GetDeviceCaps( TTYDRV_PDEVICE *physDev, INT cap )
128 {
129     switch(cap)
130     {
131     case DRIVERVERSION:
132         return 0x300;
133     case TECHNOLOGY:
134         return DT_RASDISPLAY;
135     case HORZSIZE:
136         return 0;    /* FIXME: Screen width in mm */
137     case VERTSIZE:
138         return 0;    /* FIXME: Screen height in mm */
139     case HORZRES:
140         return 640;  /* FIXME: Screen width in pixel */
141     case VERTRES:
142         return 480;  /* FIXME: Screen height in pixel */
143     case BITSPIXEL:
144         return 1;    /* FIXME */
145     case PLANES:
146         return 1;
147     case NUMBRUSHES:
148         return 16 + 6;
149     case NUMPENS:
150         return 16;
151     case NUMMARKERS:
152         return 0;
153     case NUMFONTS:
154         return 0;
155     case NUMCOLORS:
156         return 100;
157     case PDEVICESIZE:
158         return sizeof(TTYDRV_PDEVICE);
159     case CURVECAPS:
160         return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
161                 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
162     case LINECAPS:
163         return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
164                 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
165     case POLYGONALCAPS:
166         return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
167                 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
168     case TEXTCAPS:
169         return 0;
170     case CLIPCAPS:
171         return CP_REGION;
172     case RASTERCAPS:
173         return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
174                 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS);
175     case ASPECTX:
176     case ASPECTY:
177         return 36;
178     case ASPECTXY:
179         return 51;
180     case LOGPIXELSX:
181     case LOGPIXELSY:
182         return 72;  /* FIXME */
183     case SIZEPALETTE:
184         return 256;  /* FIXME */
185     case NUMRESERVED:
186         return 0;
187     case COLORRES:
188         return 0;
189     case PHYSICALWIDTH:
190     case PHYSICALHEIGHT:
191     case PHYSICALOFFSETX:
192     case PHYSICALOFFSETY:
193     case SCALINGFACTORX:
194     case SCALINGFACTORY:
195     case VREFRESH:
196     case DESKTOPVERTRES:
197     case DESKTOPHORZRES:
198     case BTLALIGNMENT:
199         return 0;
200     default:
201         FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
202         return 0;
203     }
204 }
205
206
207 /***********************************************************************
208  *              TTYDRV_DC_SetDeviceClipping
209  */
210 void TTYDRV_DC_SetDeviceClipping(TTYDRV_PDEVICE *physDev)
211 {
212     TRACE("(%x)\n", physDev->hdc);
213 }