]>
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"
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 bool wxApp::Initialize()
59 wxBuffer
= new char[1500];
61 wxBuffer
= new char[BUFSIZ
+ 512];
64 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
66 streambuf
* sBuf
= new wxDebugStreamBuf
;
67 ostream
* oStr
= new ostream(sBuf
) ;
68 wxDebugContext::SetStream(oStr
, sBuf
);
72 wxClassInfo::InitializeClasses();
74 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
75 wxTheColourDatabase
->Initialize();
76 wxInitializeStockObjects();
78 #if wxUSE_WX_RESOURCES
79 wxInitializeResourceSystem();
82 // For PostScript printing
84 wxInitializePrintSetupData();
85 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
86 wxThePrintPaperDatabase
->CreateDatabase();
89 wxBitmap::InitStandardHandlers();
91 wxModule::RegisterModules();
92 wxASSERT( wxModule::InitializeModules() == TRUE
);
99 wxModule::CleanUpModules();
101 #if wxUSE_WX_RESOURCES
102 wxCleanUpResourceSystem();
105 wxDeleteStockObjects() ;
107 // Destroy all GDI lists, etc.
109 delete wxTheBrushList
;
110 wxTheBrushList
= NULL
;
115 delete wxTheFontList
;
116 wxTheFontList
= NULL
;
118 delete wxTheBitmapList
;
119 wxTheBitmapList
= NULL
;
121 delete wxTheColourDatabase
;
122 wxTheColourDatabase
= NULL
;
125 wxInitializePrintSetupData(FALSE
);
126 delete wxThePrintPaperDatabase
;
127 wxThePrintPaperDatabase
= NULL
;
130 wxBitmap::CleanUpHandlers();
135 wxClassInfo::CleanUpClasses();
137 // do it as the very last thing because everything else can log messages
138 wxLog::DontCreateOnDemand();
139 // do it as the very last thing because everything else can log messages
140 delete wxLog::SetActiveTarget(NULL
);
143 int wxEntry( int argc
, char *argv
[] )
145 if (!wxApp::Initialize())
149 if (!wxApp::GetInitializerFunction())
151 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
155 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
160 printf( "wxWindows error: wxTheApp == NULL\n" );
164 wxTheApp
->argc
= argc
;
165 wxTheApp
->argv
= argv
;
167 // GUI-specific initialization, such as creating an app context.
168 wxTheApp
->OnInitGui();
170 // Here frames insert themselves automatically
171 // into wxTopLevelWindows by getting created
174 if (!wxTheApp
->OnInit()) return 0;
178 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
180 if (wxTheApp
->GetTopWindow())
182 delete wxTheApp
->GetTopWindow();
183 wxTheApp
->SetTopWindow(NULL
);
186 wxTheApp
->DeletePendingObjects();
195 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
196 // At this point we want to check if there are any memory
197 // blocks that aren't part of the wxDebugContext itself,
198 // as a special case. Then when dumping we need to ignore
199 // wxDebugContext, too.
200 if (wxDebugContext::CountObjectsLeft() > 0)
202 wxTrace("There were memory leaks.\n");
203 wxDebugContext::Dump();
204 wxDebugContext::PrintStatistics();
206 wxDebugContext::SetStream(NULL
, NULL
);
212 // Static member initialization
213 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
220 m_wantDebugOutput
= TRUE
;
225 m_printMode
= wxPRINT_WINDOWS
;
227 m_printMode
= wxPRINT_POSTSCRIPT
;
229 m_exitOnFrameDelete
= TRUE
;
233 bool wxApp::Initialized()
241 int wxApp::MainLoop()
245 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
248 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
258 // Returns TRUE if more time is needed.
259 bool wxApp::ProcessIdle()
262 event
.SetEventObject(this);
265 return event
.MoreRequested();
268 void wxApp::ExitMainLoop()
273 // Is a message/event pending?
274 bool wxApp::Pending()
281 // Dispatch a message.
282 void wxApp::Dispatch()
288 void wxApp::OnIdle(wxIdleEvent
& event
)
290 static bool inOnIdle
= FALSE
;
292 // Avoid recursion (via ProcessEvent default case)
298 // 'Garbage' collection of windows deleted with Close().
299 DeletePendingObjects();
301 // flush the logged messages if any
302 wxLog
*pLog
= wxLog::GetActiveTarget();
303 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
306 // Send OnIdle events to all windows
307 bool needMore
= SendIdleEvents();
310 event
.RequestMore(TRUE
);
315 // Send idle event to all top-level windows
316 bool wxApp::SendIdleEvents()
318 bool needMore
= FALSE
;
319 wxNode
* node
= wxTopLevelWindows
.First();
322 wxWindow
* win
= (wxWindow
*) node
->Data();
323 if (SendIdleEvents(win
))
331 // Send idle event to window and all subwindows
332 bool wxApp::SendIdleEvents(wxWindow
* win
)
334 bool needMore
= FALSE
;
337 event
.SetEventObject(win
);
338 win
->ProcessEvent(event
);
340 if (event
.MoreRequested())
343 wxNode
* node
= win
->GetChildren()->First();
346 wxWindow
* win
= (wxWindow
*) node
->Data();
347 if (SendIdleEvents(win
))
355 void wxApp::DeletePendingObjects()
357 wxNode
*node
= wxPendingDelete
.First();
360 wxObject
*obj
= (wxObject
*)node
->Data();
364 if (wxPendingDelete
.Member(obj
))
367 // Deleting one object may have deleted other pending
368 // objects, so start from beginning of list again.
369 node
= wxPendingDelete
.First();
373 wxLog
* wxApp::CreateLogTarget()
378 wxWindow
* wxApp::GetTopWindow() const
382 else if (wxTopLevelWindows
.Number() > 0)
383 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
392 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
393 * only for emergencies.
397 // Yield to other processes