]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/app.cpp
67271c4c3b0f4d19c2334674253c3f24d146fe9a
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"
33 #include "wx/resource.h"
37 #include "wx/postscrp.h"
42 extern char *wxBuffer
;
43 extern wxList wxPendingDelete
;
45 wxApp
*wxTheApp
= NULL
;
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
49 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
50 EVT_IDLE(wxApp::OnIdle
)
54 long wxApp::sm_lastMessageTime
= 0;
56 void wxApp::CommonInit()
59 wxBuffer
= new char[1500];
61 wxBuffer
= new char[BUFSIZ
+ 512];
64 wxClassInfo::InitializeClasses();
66 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
67 wxTheColourDatabase
->Initialize();
68 wxInitializeStockObjects();
71 wxInitializeResourceSystem();
74 // For PostScript printing
76 wxInitializePrintSetupData();
77 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
78 wxThePrintPaperDatabase
->CreateDatabase();
81 wxBitmap::InitStandardHandlers();
83 wxModule::RegisterModules();
84 wxASSERT( wxModule::InitializeModules() == TRUE
);
87 void wxApp::CommonCleanUp()
89 wxModule::CleanUpModules();
92 wxCleanUpResourceSystem();
95 wxDeleteStockObjects() ;
97 // Destroy all GDI lists, etc.
99 delete wxTheBrushList
;
100 wxTheBrushList
= NULL
;
105 delete wxTheFontList
;
106 wxTheFontList
= NULL
;
108 delete wxTheBitmapList
;
109 wxTheBitmapList
= NULL
;
111 delete wxTheColourDatabase
;
112 wxTheColourDatabase
= NULL
;
115 wxInitializePrintSetupData(FALSE
);
116 delete wxThePrintPaperDatabase
;
117 wxThePrintPaperDatabase
= NULL
;
120 wxBitmap::CleanUpHandlers();
125 wxClassInfo::CleanUpClasses();
127 // do it as the very last thing because everything else can log messages
128 wxLog::DontCreateOnDemand();
129 // do it as the very last thing because everything else can log messages
130 delete wxLog::SetActiveTarget(NULL
);
133 int wxEntry( int argc
, char *argv
[] )
135 wxClassInfo::InitializeClasses();
137 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
139 #if !defined(_WINDLL)
140 streambuf
* sBuf
= new wxDebugStreamBuf
;
142 streambuf
* sBuf
= NULL
;
144 ostream
* oStr
= new ostream(sBuf
) ;
145 wxDebugContext::SetStream(oStr
, sBuf
);
151 if (!wxApp::GetInitializerFunction())
153 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
157 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
162 printf( "wxWindows error: wxTheApp == NULL\n" );
166 wxTheApp
->argc
= argc
;
167 wxTheApp
->argv
= argv
;
169 // TODO: your platform-specific initialization.
173 // GUI-specific initialization, such as creating an app context.
174 wxTheApp
->OnInitGui();
176 // Here frames insert themselves automatically
177 // into wxTopLevelWindows by getting created
180 if (!wxTheApp
->OnInit()) return 0;
184 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
186 if (wxTheApp
->GetTopWindow())
188 delete wxTheApp
->GetTopWindow();
189 wxTheApp
->SetTopWindow(NULL
);
192 wxTheApp
->DeletePendingObjects();
196 wxApp::CommonCleanUp();
201 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
202 // At this point we want to check if there are any memory
203 // blocks that aren't part of the wxDebugContext itself,
204 // as a special case. Then when dumping we need to ignore
205 // wxDebugContext, too.
206 if (wxDebugContext::CountObjectsLeft() > 0)
208 wxTrace("There were memory leaks.\n");
209 wxDebugContext::Dump();
210 wxDebugContext::PrintStatistics();
212 wxDebugContext::SetStream(NULL
, NULL
);
218 // Static member initialization
219 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
226 m_wantDebugOutput
= TRUE
;
231 m_printMode
= wxPRINT_WINDOWS
;
233 m_printMode
= wxPRINT_POSTSCRIPT
;
235 m_exitOnFrameDelete
= TRUE
;
239 bool wxApp::Initialized()
247 int wxApp::MainLoop()
251 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
254 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
264 // Returns TRUE if more time is needed.
265 bool wxApp::ProcessIdle()
268 event
.SetEventObject(this);
271 return event
.MoreRequested();
274 void wxApp::ExitMainLoop()
279 // Is a message/event pending?
280 bool wxApp::Pending()
287 // Dispatch a message.
288 void wxApp::Dispatch()
294 void wxApp::OnIdle(wxIdleEvent
& event
)
296 static bool inOnIdle
= FALSE
;
298 // Avoid recursion (via ProcessEvent default case)
304 // 'Garbage' collection of windows deleted with Close().
305 DeletePendingObjects();
307 // flush the logged messages if any
308 wxLog
*pLog
= wxLog::GetActiveTarget();
309 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
312 // Send OnIdle events to all windows
313 bool needMore
= SendIdleEvents();
316 event
.RequestMore(TRUE
);
321 // Send idle event to all top-level windows
322 bool wxApp::SendIdleEvents()
324 bool needMore
= FALSE
;
325 wxNode
* node
= wxTopLevelWindows
.First();
328 wxWindow
* win
= (wxWindow
*) node
->Data();
329 if (SendIdleEvents(win
))
337 // Send idle event to window and all subwindows
338 bool wxApp::SendIdleEvents(wxWindow
* win
)
340 bool needMore
= FALSE
;
343 event
.SetEventObject(win
);
344 win
->ProcessEvent(event
);
346 if (event
.MoreRequested())
349 wxNode
* node
= win
->GetChildren()->First();
352 wxWindow
* win
= (wxWindow
*) node
->Data();
353 if (SendIdleEvents(win
))
361 void wxApp::DeletePendingObjects()
363 wxNode
*node
= wxPendingDelete
.First();
366 wxObject
*obj
= (wxObject
*)node
->Data();
370 if (wxPendingDelete
.Member(obj
))
373 // Deleting one object may have deleted other pending
374 // objects, so start from beginning of list again.
375 node
= wxPendingDelete
.First();
379 wxLog
* wxApp::CreateLogTarget()
384 wxWindow
* wxApp::GetTopWindow() const
388 else if (wxTopLevelWindows
.Number() > 0)
389 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
396 wxApp::CommonCleanUp();
398 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
399 * only for emergencies.
403 // Yield to other processes