make it possible to create wxWindowDC for a hidden window
[wxWidgets.git] / src / dfb / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/utils.cpp
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Vaclav Slavik
5 // Created: 2006-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/utils.h"
19 #include "wx/apptrait.h"
20 #include "wx/unix/execute.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/app.h"
24 #endif
25
26 #include "wx/dfb/private.h"
27 #include <directfb_version.h>
28
29 // ----------------------------------------------------------------------------
30 // toolkit info
31 // ----------------------------------------------------------------------------
32
33 wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
34 {
35 if ( verMaj ) *verMaj = DIRECTFB_MAJOR_VERSION;
36 if ( verMin ) *verMaj = DIRECTFB_MINOR_VERSION;
37
38 return wxPORT_DFB;
39 }
40
41 // ----------------------------------------------------------------------------
42 // display characteristics
43 // ----------------------------------------------------------------------------
44
45 bool wxColourDisplay()
46 {
47 #warning "FIXME: wxColourDisplay"
48 return true;
49 }
50
51 int wxDisplayDepth()
52 {
53 return wxTheApp->GetDisplayMode().bpp;
54 }
55
56 void wxDisplaySize(int *width, int *height)
57 {
58 wxVideoMode mode(wxTheApp->GetDisplayMode());
59 if ( width ) *width = mode.w;
60 if ( height ) *height = mode.h;
61 }
62
63 void wxDisplaySizeMM(int *width, int *height)
64 {
65 // FIXME: there's no way to get physical resolution using the DirectDB
66 // API, we hardcode a commonly used value of 72dpi
67 #define DPI 72.0
68 #define PX_TO_MM(x) (int(((x) / DPI) * inches2mm))
69
70 wxDisplaySize(width, height);
71 if ( width ) *width = PX_TO_MM(*width);
72 if ( height ) *height = PX_TO_MM(*height);
73
74 #undef DPI
75 #undef PX_TO_MM
76 }
77
78 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
79 {
80 // return desktop dimensions minus any panels, menus, trays:
81 if (x) *x = 0;
82 if (y) *y = 0;
83 wxDisplaySize(width, height);
84 }
85
86 //-----------------------------------------------------------------------------
87 // surface manipulation helpers
88 //-----------------------------------------------------------------------------
89
90 wxIDirectFBSurfacePtr wxDfbCreateCompatibleSurface(
91 const wxIDirectFBSurfacePtr& s,
92 const wxSize& size)
93 {
94 if ( !s )
95 return NULL;
96
97 DFBSurfaceDescription desc;
98 desc.flags = (DFBSurfaceDescriptionFlags)(
99 DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
100 s->GetCapabilities(&desc.caps);
101 s->GetPixelFormat(&desc.pixelformat);
102 desc.width = size.x;
103 desc.height = size.y;
104
105 wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
106 if ( !snew )
107 return NULL;
108
109 if ( desc.pixelformat == DSPF_LUT8 )
110 {
111 wxIDirectFBPalettePtr pal(s->GetPalette());
112 if ( s )
113 {
114 if ( !snew->SetPalette(pal) )
115 return NULL;
116 }
117 }
118
119 return snew;
120 }
121
122 wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
123 wxDfbCloneSurfaceMode mode)
124 {
125 if ( !s )
126 return NULL;
127
128 wxSize size;
129 if ( !s->GetSize(&size.x, &size.y) )
130 return NULL;
131
132 wxIDirectFBSurfacePtr snew(wxDfbCreateCompatibleSurface(s, size));
133 if ( !snew )
134 return NULL;
135
136 if ( mode == wxDfbCloneSurface_CopyPixels )
137 {
138 if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
139 return NULL;
140 if ( !snew->Blit(s, NULL, 0, 0) )
141 return NULL;
142 }
143
144 return snew;
145 }
146
147 int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s)
148 {
149 wxCHECK_MSG( s, -1, _T("invalid surface") );
150
151 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
152
153 if ( !s->GetPixelFormat(&format) )
154 return -1;
155
156 return DFB_BITS_PER_PIXEL(format);
157 }
158
159 wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer()
160 {
161 return wxIDirectFB::Get()->GetDisplayLayer(DLID_PRIMARY);
162 }
163
164 wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
165 {
166 wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
167 return layer ? layer->GetSurface() : NULL;
168 }
169
170
171 //-----------------------------------------------------------------------------
172 // mouse
173 //-----------------------------------------------------------------------------
174
175 void wxGetMousePosition(int *x, int *y)
176 {
177 wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
178 if ( layer )
179 layer->GetCursorPosition(x, y);
180 }
181
182 wxPoint wxGetMousePosition()
183 {
184 wxPoint pt;
185 wxGetMousePosition(&pt.x, &pt.y);
186 return pt;
187 }
188
189 //-----------------------------------------------------------------------------
190 // keyboard
191 //-----------------------------------------------------------------------------
192
193 bool wxGetKeyState(wxKeyCode key)
194 {
195 wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != WXK_MBUTTON,
196 _T("can't use wxGetKeyState() for mouse buttons"));
197
198 return false; // FIXME
199 }
200
201 //----------------------------------------------------------------------------
202 // misc.
203 //----------------------------------------------------------------------------
204
205 void wxBell()
206 {
207 }
208
209 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
210 {
211 wxFAIL_MSG( _T("wxAddProcessCallback not implemented") );
212 return 0;
213 }