]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/app.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/module.h"
30 #include "wx/memory.h"
32 #if wxUSE_WX_RESOURCES
33 #include "wx/resource.h"
38 extern char *wxBuffer
;
39 extern wxList wxPendingDelete
;
41 wxApp
*wxTheApp
= NULL
;
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
45 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
46 EVT_IDLE(wxApp::OnIdle
)
50 long wxApp::sm_lastMessageTime
= 0;
52 bool wxApp::Initialize()
55 wxBuffer
= new char[1500];
57 wxBuffer
= new char[BUFSIZ
+ 512];
60 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
62 streambuf
* sBuf
= new wxDebugStreamBuf
;
63 ostream
* oStr
= new ostream(sBuf
) ;
64 wxDebugContext::SetStream(oStr
, sBuf
);
68 wxClassInfo::InitializeClasses();
70 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
71 wxTheColourDatabase
->Initialize();
73 wxInitializeStockLists();
74 wxInitializeStockObjects();
76 #if wxUSE_WX_RESOURCES
77 wxInitializeResourceSystem();
80 wxBitmap::InitStandardHandlers();
82 wxModule::RegisterModules();
83 wxASSERT( wxModule::InitializeModules() == TRUE
);
90 wxModule::CleanUpModules();
92 #if wxUSE_WX_RESOURCES
93 wxCleanUpResourceSystem();
96 wxDeleteStockObjects() ;
98 // Destroy all GDI lists, etc.
100 delete wxTheBrushList
;
101 wxTheBrushList
= NULL
;
106 delete wxTheFontList
;
107 wxTheFontList
= NULL
;
109 delete wxTheBitmapList
;
110 wxTheBitmapList
= NULL
;
112 delete wxTheColourDatabase
;
113 wxTheColourDatabase
= NULL
;
115 wxBitmap::CleanUpHandlers();
120 wxClassInfo::CleanUpClasses();
122 // do it as the very last thing because everything else can log messages
123 wxLog::DontCreateOnDemand();
124 // do it as the very last thing because everything else can log messages
125 delete wxLog::SetActiveTarget(NULL
);
128 int wxEntry( int argc
, char *argv
[] )
130 if (!wxApp::Initialize())
134 if (!wxApp::GetInitializerFunction())
136 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
140 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
145 printf( "wxWindows error: wxTheApp == NULL\n" );
149 wxTheApp
->argc
= argc
;
150 wxTheApp
->argv
= argv
;
152 // GUI-specific initialization, such as creating an app context.
153 wxTheApp
->OnInitGui();
155 // Here frames insert themselves automatically
156 // into wxTopLevelWindows by getting created
159 if (!wxTheApp
->OnInit()) return 0;
163 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
165 if (wxTheApp
->GetTopWindow())
167 delete wxTheApp
->GetTopWindow();
168 wxTheApp
->SetTopWindow(NULL
);
171 wxTheApp
->DeletePendingObjects();
180 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
181 // At this point we want to check if there are any memory
182 // blocks that aren't part of the wxDebugContext itself,
183 // as a special case. Then when dumping we need to ignore
184 // wxDebugContext, too.
185 if (wxDebugContext::CountObjectsLeft() > 0)
187 wxTrace("There were memory leaks.\n");
188 wxDebugContext::Dump();
189 wxDebugContext::PrintStatistics();
191 wxDebugContext::SetStream(NULL
, NULL
);
197 // Static member initialization
198 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
205 m_wantDebugOutput
= TRUE
;
210 m_printMode
= wxPRINT_WINDOWS
;
212 m_printMode
= wxPRINT_POSTSCRIPT
;
214 m_exitOnFrameDelete
= TRUE
;
218 bool wxApp::Initialized()
226 int wxApp::MainLoop()
230 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
233 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
243 // Returns TRUE if more time is needed.
244 bool wxApp::ProcessIdle()
247 event
.SetEventObject(this);
250 return event
.MoreRequested();
253 void wxApp::ExitMainLoop()
258 // Is a message/event pending?
259 bool wxApp::Pending()
266 // Dispatch a message.
267 void wxApp::Dispatch()
273 void wxApp::OnIdle(wxIdleEvent
& event
)
275 static bool inOnIdle
= FALSE
;
277 // Avoid recursion (via ProcessEvent default case)
283 // 'Garbage' collection of windows deleted with Close().
284 DeletePendingObjects();
286 // flush the logged messages if any
287 wxLog
*pLog
= wxLog::GetActiveTarget();
288 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
291 // Send OnIdle events to all windows
292 bool needMore
= SendIdleEvents();
295 event
.RequestMore(TRUE
);
300 // Send idle event to all top-level windows
301 bool wxApp::SendIdleEvents()
303 bool needMore
= FALSE
;
304 wxNode
* node
= wxTopLevelWindows
.First();
307 wxWindow
* win
= (wxWindow
*) node
->Data();
308 if (SendIdleEvents(win
))
316 // Send idle event to window and all subwindows
317 bool wxApp::SendIdleEvents(wxWindow
* win
)
319 bool needMore
= FALSE
;
322 event
.SetEventObject(win
);
323 win
->ProcessEvent(event
);
325 if (event
.MoreRequested())
328 wxNode
* node
= win
->GetChildren()->First();
331 wxWindow
* win
= (wxWindow
*) node
->Data();
332 if (SendIdleEvents(win
))
340 void wxApp::DeletePendingObjects()
342 wxNode
*node
= wxPendingDelete
.First();
345 wxObject
*obj
= (wxObject
*)node
->Data();
349 if (wxPendingDelete
.Member(obj
))
352 // Deleting one object may have deleted other pending
353 // objects, so start from beginning of list again.
354 node
= wxPendingDelete
.First();
358 wxLog
* wxApp::CreateLogTarget()
363 wxWindow
* wxApp::GetTopWindow() const
367 else if (wxTopLevelWindows
.Number() > 0)
368 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
377 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
378 * only for emergencies.
382 // Yield to other processes