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
)
31 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
32 EVT_IDLE(wxAppBase::OnIdle
)
43 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
45 if ( !wxAppBase::Initialize(argc
, argv
) )
48 // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This
49 // is just a temporary fix to make wxDFB compile in Unicode
50 // build, the real fix is to change Initialize()'s signature
51 // to use char* on Unix.
53 // DirectFBInit() wants UTF-8, not wchar_t, so convert
55 char **argvDFB
= new char *[argc
+ 1];
56 for ( i
= 0; i
< argc
; i
++ )
58 argvDFB
[i
] = strdup(wxConvUTF8
.cWX2MB(argv
[i
]));
65 if ( !wxDfbCheckReturn(DirectFBInit(&argcDFB
, &argvDFB
)) )
68 if ( argcDFB
!= argc
)
70 // we have to drop the parameters which were consumed by DFB+
71 for ( i
= 0; i
< argcDFB
; i
++ )
73 while ( strcmp(wxConvUTF8
.cWX2MB(argv
[i
]), argvDFB
[i
]) != 0 )
75 memmove(argv
+ i
, argv
+ i
+ 1, (argc
- i
)*sizeof(*argv
));
81 //else: DirectFBInit() didn't modify our parameters
84 for ( i
= 0; i
< argcDFB
; i
++ )
93 if ( !wxDfbCheckReturn(DirectFBInit(&argc
, &argv
)) )
96 #endif // Unicode/ANSI
98 // update internal arg[cv] as DFB may have removed processed options:
102 if ( !wxIDirectFB::Get() )
108 void wxApp::CleanUp()
110 wxAppBase::CleanUp();
112 wxFontsManager::CleanUp();
114 wxEventLoop::CleanUp();
115 wxIDirectFB::CleanUp();
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
122 static wxVideoMode
GetCurrentVideoMode()
124 wxIDirectFBDisplayLayerPtr
layer(wxIDirectFB::Get()->GetDisplayLayer());
126 return wxVideoMode(); // invalid
128 return layer
->GetVideoMode();
131 wxVideoMode
wxApp::GetDisplayMode() const
133 if ( !m_videoMode
.IsOk() )
134 wxConstCast(this, wxApp
)->m_videoMode
= GetCurrentVideoMode();
139 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
141 if ( !wxIDirectFB::Get()->SetVideoMode(mode
.w
, mode
.h
, mode
.bpp
) )
148 //-----------------------------------------------------------------------------
149 // events processing related
150 //-----------------------------------------------------------------------------
152 void wxApp::WakeUpIdle()
155 if (!wxThread::IsMain())
159 wxEventLoopBase
* const loop
= wxEventLoop::GetActive();
164 if (!wxThread::IsMain())
170 bool wxApp::Yield(bool onlyIfNeeded
)
173 if ( !wxThread::IsMain() )
174 return true; // can't process events from other threads
175 #endif // wxUSE_THREADS
177 static bool s_inYield
= false;
183 wxFAIL_MSG( wxT("wxYield called recursively" ) );
194 loop
= wx_static_cast(wxEventLoop
*, wxEventLoop::GetActive());
198 // it's necessary to call ProcessIdle() to update the frames sizes which
199 // might have been changed (it also will update other things set from
200 // OnUpdateUI() which is a nice (and desired) side effect)
201 while ( ProcessIdle() ) {}