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/thread.h"
23 #include "wx/dfb/private.h"
24 #include "wx/private/fontmgr.h"
26 //-----------------------------------------------------------------------------
27 // wxApp initialization
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
40 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
42 if ( !wxAppBase::Initialize(argc
, argv
) )
45 // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This
46 // is just a temporary fix to make wxDFB compile in Unicode
47 // build, the real fix is to change Initialize()'s signature
48 // to use char* on Unix.
50 // DirectFBInit() wants UTF-8, not wchar_t, so convert
52 char **argvDFB
= new char *[argc
+ 1];
53 for ( i
= 0; i
< argc
; i
++ )
55 argvDFB
[i
] = strdup(wxConvUTF8
.cWX2MB(argv
[i
]));
62 if ( !wxDfbCheckReturn(DirectFBInit(&argcDFB
, &argvDFB
)) )
65 if ( argcDFB
!= argc
)
67 // we have to drop the parameters which were consumed by DFB+
68 for ( i
= 0; i
< argcDFB
; i
++ )
70 while ( strcmp(wxConvUTF8
.cWX2MB(argv
[i
]), argvDFB
[i
]) != 0 )
72 memmove(argv
+ i
, argv
+ i
+ 1, (argc
- i
)*sizeof(*argv
));
78 //else: DirectFBInit() didn't modify our parameters
81 for ( i
= 0; i
< argcDFB
; i
++ )
90 if ( !wxDfbCheckReturn(DirectFBInit(&argc
, &argv
)) )
93 #endif // Unicode/ANSI
95 // update internal arg[cv] as DFB may have removed processed options:
99 if ( !wxIDirectFB::Get() )
105 void wxApp::CleanUp()
107 wxAppBase::CleanUp();
109 wxFontsManager::CleanUp();
111 wxEventLoop::CleanUp();
112 wxIDirectFB::CleanUp();
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
119 static wxVideoMode
GetCurrentVideoMode()
121 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
123 return wxVideoMode(); // invalid
125 return layer
->GetVideoMode();
128 wxVideoMode
wxApp::GetDisplayMode() const
130 if ( !m_videoMode
.IsOk() )
131 wxConstCast(this, wxApp
)->m_videoMode
= GetCurrentVideoMode();
136 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
138 if ( !wxIDirectFB::Get()->SetVideoMode(mode
.w
, mode
.h
, mode
.bpp
) )
145 //-----------------------------------------------------------------------------
146 // events processing related
147 //-----------------------------------------------------------------------------
149 void wxApp::WakeUpIdle()
152 if (!wxThread::IsMain())
156 wxEventLoopBase
* const loop
= wxEventLoop::GetActive();
161 if (!wxThread::IsMain())
167 bool wxApp::Yield(bool onlyIfNeeded
)
170 if ( !wxThread::IsMain() )
171 return true; // can't process events from other threads
172 #endif // wxUSE_THREADS
174 static bool s_inYield
= false;
180 wxFAIL_MSG( wxT("wxYield called recursively" ) );
193 loop
= static_cast<wxEventLoop
*>(wxEventLoop::GetActive());
197 // it's necessary to call ProcessIdle() to update the frames sizes which
198 // might have been changed (it also will update other things set from
199 // OnUpdateUI() which is a nice (and desired) side effect)
200 while ( ProcessIdle() ) {}