]>
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 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
44 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
45 EVT_IDLE(wxApp::OnIdle
)
48 long wxApp::sm_lastMessageTime
= 0;
50 bool wxApp::Initialize()
53 wxBuffer
= new char[1500];
55 wxBuffer
= new char[BUFSIZ
+ 512];
59 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
61 streambuf* sBuf = new wxDebugStreamBuf;
62 ostream* oStr = new ostream(sBuf) ;
63 wxDebugContext::SetStream(oStr, sBuf);
67 wxClassInfo::InitializeClasses();
69 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
70 wxTheColourDatabase
->Initialize();
72 wxInitializeStockLists();
73 wxInitializeStockObjects();
75 #if wxUSE_WX_RESOURCES
76 wxInitializeResourceSystem();
79 wxBitmap::InitStandardHandlers();
81 wxModule::RegisterModules();
82 wxASSERT( wxModule::InitializeModules() == TRUE
);
89 wxModule::CleanUpModules();
91 #if wxUSE_WX_RESOURCES
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
;
114 wxBitmap::CleanUpHandlers();
119 wxClassInfo::CleanUpClasses();
124 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
125 // At this point we want to check if there are any memory
126 // blocks that aren't part of the wxDebugContext itself,
127 // as a special case. Then when dumping we need to ignore
128 // wxDebugContext, too.
129 if (wxDebugContext::CountObjectsLeft() > 0)
131 wxTrace("There were memory leaks.\n");
132 wxDebugContext::Dump();
133 wxDebugContext::PrintStatistics();
135 // wxDebugContext::SetStream(NULL, NULL);
138 // do it as the very last thing because everything else can log messages
139 wxLog::DontCreateOnDemand();
140 // do it as the very last thing because everything else can log messages
141 delete wxLog::SetActiveTarget(NULL
);
144 int wxEntry( int argc
, char *argv
[] )
146 if (!wxApp::Initialize())
150 if (!wxApp::GetInitializerFunction())
152 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
156 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
161 printf( "wxWindows error: wxTheApp == NULL\n" );
165 wxTheApp
->argc
= argc
;
166 wxTheApp
->argv
= argv
;
168 // GUI-specific initialization, such as creating an app context.
169 wxTheApp
->OnInitGui();
171 // Here frames insert themselves automatically
172 // into wxTopLevelWindows by getting created
175 if (!wxTheApp
->OnInit()) return 0;
179 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
181 if (wxTheApp
->GetTopWindow())
183 delete wxTheApp
->GetTopWindow();
184 wxTheApp
->SetTopWindow(NULL
);
187 wxTheApp
->DeletePendingObjects();
196 // Static member initialization
197 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
204 m_wantDebugOutput
= TRUE
;
209 m_printMode
= wxPRINT_WINDOWS
;
211 m_printMode
= wxPRINT_POSTSCRIPT
;
213 m_exitOnFrameDelete
= TRUE
;
217 bool wxApp::Initialized()
225 int wxApp::MainLoop()
229 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
232 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
242 // Returns TRUE if more time is needed.
243 bool wxApp::ProcessIdle()
246 event
.SetEventObject(this);
249 return event
.MoreRequested();
252 void wxApp::ExitMainLoop()
257 // Is a message/event pending?
258 bool wxApp::Pending()
265 // Dispatch a message.
266 void wxApp::Dispatch()
272 void wxApp::OnIdle(wxIdleEvent
& event
)
274 static bool inOnIdle
= FALSE
;
276 // Avoid recursion (via ProcessEvent default case)
282 // 'Garbage' collection of windows deleted with Close().
283 DeletePendingObjects();
285 // flush the logged messages if any
286 wxLog
*pLog
= wxLog::GetActiveTarget();
287 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
290 // Send OnIdle events to all windows
291 bool needMore
= SendIdleEvents();
294 event
.RequestMore(TRUE
);
299 // Send idle event to all top-level windows
300 bool wxApp::SendIdleEvents()
302 bool needMore
= FALSE
;
303 wxNode
* node
= wxTopLevelWindows
.First();
306 wxWindow
* win
= (wxWindow
*) node
->Data();
307 if (SendIdleEvents(win
))
315 // Send idle event to window and all subwindows
316 bool wxApp::SendIdleEvents(wxWindow
* win
)
318 bool needMore
= FALSE
;
321 event
.SetEventObject(win
);
322 win
->ProcessEvent(event
);
324 if (event
.MoreRequested())
327 wxNode
* node
= win
->GetChildren().First();
330 wxWindow
* win
= (wxWindow
*) node
->Data();
331 if (SendIdleEvents(win
))
339 void wxApp::DeletePendingObjects()
341 wxNode
*node
= wxPendingDelete
.First();
344 wxObject
*obj
= (wxObject
*)node
->Data();
348 if (wxPendingDelete
.Member(obj
))
351 // Deleting one object may have deleted other pending
352 // objects, so start from beginning of list again.
353 node
= wxPendingDelete
.First();
357 wxLog
* wxApp::CreateLogTarget()
362 wxWindow
* wxApp::GetTopWindow() const
366 else if (wxTopLevelWindows
.Number() > 0)
367 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
376 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
377 * only for emergencies.
381 // Yield to other processes