1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/app.cpp
3 // Purpose: wxApp implementation
4 // Author: Vaclav Slavik
5 // based on MGL implementation
8 // Copyright: (c) 2006 REA Elektronik GmbH
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/evtloop.h"
22 #include "wx/dfb/private.h"
23 #include "wx/private/fontmgr.h"
25 //-----------------------------------------------------------------------------
26 // wxApp initialization
27 //-----------------------------------------------------------------------------
29 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
39 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
41 if ( !wxAppBase::Initialize(argc
, argv
) )
44 // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This
45 // is just a temporary fix to make wxDFB compile in Unicode
46 // build, the real fix is to change Initialize()'s signature
47 // to use char* on Unix.
49 // DirectFBInit() wants UTF-8, not wchar_t, so convert
51 char **argvDFB
= new char *[argc
+ 1];
52 for ( i
= 0; i
< argc
; i
++ )
54 argvDFB
[i
] = strdup(wxConvUTF8
.cWX2MB(argv
[i
]));
61 if ( !wxDfbCheckReturn(DirectFBInit(&argcDFB
, &argvDFB
)) )
64 if ( argcDFB
!= argc
)
66 // we have to drop the parameters which were consumed by DFB+
67 for ( i
= 0; i
< argcDFB
; i
++ )
69 while ( strcmp(wxConvUTF8
.cWX2MB(argv
[i
]), argvDFB
[i
]) != 0 )
71 memmove(argv
+ i
, argv
+ i
+ 1, (argc
- i
)*sizeof(*argv
));
77 //else: DirectFBInit() didn't modify our parameters
80 for ( i
= 0; i
< argcDFB
; i
++ )
89 if ( !wxDfbCheckReturn(DirectFBInit(&argc
, &argv
)) )
92 #endif // Unicode/ANSI
94 // update internal arg[cv] as DFB may have removed processed options:
98 if ( !wxIDirectFB::Get() )
104 void wxApp::CleanUp()
106 wxAppBase::CleanUp();
108 wxFontsManager::CleanUp();
110 wxEventLoop::CleanUp();
111 wxIDirectFB::CleanUp();
114 //-----------------------------------------------------------------------------
116 //-----------------------------------------------------------------------------
118 static wxVideoMode
GetCurrentVideoMode()
120 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
122 return wxVideoMode(); // invalid
124 return layer
->GetVideoMode();
127 wxVideoMode
wxApp::GetDisplayMode() const
129 if ( !m_videoMode
.IsOk() )
130 wxConstCast(this, wxApp
)->m_videoMode
= GetCurrentVideoMode();
135 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
137 if ( !wxIDirectFB::Get()->SetVideoMode(mode
.w
, mode
.h
, mode
.bpp
) )
144 //-----------------------------------------------------------------------------
145 // events processing related
146 //-----------------------------------------------------------------------------
148 void wxApp::WakeUpIdle()
151 if (!wxThread::IsMain())
155 wxEventLoopBase
* const loop
= wxEventLoop::GetActive();
160 if (!wxThread::IsMain())
166 bool wxApp::Yield(bool onlyIfNeeded
)
169 if ( !wxThread::IsMain() )
170 return true; // can't process events from other threads
171 #endif // wxUSE_THREADS
173 static bool s_inYield
= false;
179 wxFAIL_MSG( wxT("wxYield called recursively" ) );
190 loop
= wx_static_cast(wxEventLoop
*, wxEventLoop::GetActive());
194 // it's necessary to call ProcessIdle() to update the frames sizes which
195 // might have been changed (it also will update other things set from
196 // OnUpdateUI() which is a nice (and desired) side effect)
197 while ( ProcessIdle() ) {}