]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/utils.cpp
removed unneeded header
[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 IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s,
91 wxDfbCloneSurfaceMode mode)
92 {
93 if ( !s )
94 return NULL;
95
96 DFBSurfaceDescription desc;
97 desc.flags = (DFBSurfaceDescriptionFlags)(
98 DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
99 s->GetCapabilities(s, &desc.caps);
100 s->GetSize(s, &desc.width, &desc.height);
101 s->GetPixelFormat(s, &desc.pixelformat);
102
103 IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface());
104
105 IDirectFBSurfacePtr snew;
106 if ( !DFB_CALL( dfb->CreateSurface(dfb, &desc, &snew) ) )
107 return NULL;
108
109 IDirectFBPalettePtr pal;
110 if ( s->GetPalette(s, &pal) == DFB_OK )
111 {
112 if ( !DFB_CALL( snew->SetPalette(snew, pal) ) )
113 return NULL;
114 }
115
116 if ( mode == wxDfbCloneSurface_CopyPixels )
117 {
118 if ( !DFB_CALL( snew->SetBlittingFlags(snew, DSBLIT_NOFX) ) )
119 return NULL;
120 if ( !DFB_CALL( snew->Blit(snew, s, NULL, 0, 0) ) )
121 return NULL;
122 }
123
124 return snew;
125 }
126
127 int wxDfbGetSurfaceDepth(const IDirectFBSurfacePtr& s)
128 {
129 wxCHECK_MSG( s, -1, _T("invalid surface") );
130
131 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
132
133 if ( !DFB_CALL( s->GetPixelFormat(s, &format) ) )
134 return -1;
135
136 return DFB_BITS_PER_PIXEL(format);
137 }
138
139 IDirectFBDisplayLayerPtr wxDfbGetDisplayLayer()
140 {
141 IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface());
142
143 IDirectFBDisplayLayerPtr layer;
144 if ( !DFB_CALL( dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer) ) )
145 return NULL;
146
147 return layer;
148 }
149
150 IDirectFBSurfacePtr wxDfbGetPrimarySurface()
151 {
152 IDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
153 IDirectFBSurfacePtr surface;
154 DFB_CALL( layer->GetSurface(layer, &surface) );
155 return surface;
156 }
157
158
159 //-----------------------------------------------------------------------------
160 // mouse
161 //-----------------------------------------------------------------------------
162
163 void wxGetMousePosition(int *x, int *y)
164 {
165 IDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
166 DFB_CALL( layer->GetCursorPosition(layer, x, y) );
167 }
168
169 wxPoint wxGetMousePosition()
170 {
171 wxPoint pt;
172 wxGetMousePosition(&pt.x, &pt.y);
173 return pt;
174 }
175
176 //-----------------------------------------------------------------------------
177 // keyboard
178 //-----------------------------------------------------------------------------
179
180 bool wxGetKeyState(wxKeyCode key)
181 {
182 wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != WXK_MBUTTON,
183 _T("can't use wxGetKeyState() for mouse buttons"));
184
185 return false; // FIXME
186 }
187
188 //----------------------------------------------------------------------------
189 // misc.
190 //----------------------------------------------------------------------------
191
192 void wxBell()
193 {
194 }
195
196 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
197 {
198 wxFAIL_MSG( _T("wxAddProcessCallback not implemented") );
199 return 0;
200 }