]>
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 (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();
72 wxInitializeStockObjects();
74 #if wxUSE_WX_RESOURCES
75 wxInitializeResourceSystem();
78 wxBitmap::InitStandardHandlers();
80 wxModule::RegisterModules();
81 wxASSERT( wxModule::InitializeModules() == TRUE
);
88 wxModule::CleanUpModules();
90 #if wxUSE_WX_RESOURCES
91 wxCleanUpResourceSystem();
94 wxDeleteStockObjects() ;
96 // Destroy all GDI lists, etc.
98 delete wxTheBrushList
;
99 wxTheBrushList
= NULL
;
104 delete wxTheFontList
;
105 wxTheFontList
= NULL
;
107 delete wxTheBitmapList
;
108 wxTheBitmapList
= NULL
;
110 delete wxTheColourDatabase
;
111 wxTheColourDatabase
= NULL
;
113 wxBitmap::CleanUpHandlers();
118 wxClassInfo::CleanUpClasses();
120 // do it as the very last thing because everything else can log messages
121 wxLog::DontCreateOnDemand();
122 // do it as the very last thing because everything else can log messages
123 delete wxLog::SetActiveTarget(NULL
);
126 int wxEntry( int argc
, char *argv
[] )
128 if (!wxApp::Initialize())
132 if (!wxApp::GetInitializerFunction())
134 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
138 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
143 printf( "wxWindows error: wxTheApp == NULL\n" );
147 wxTheApp
->argc
= argc
;
148 wxTheApp
->argv
= argv
;
150 // GUI-specific initialization, such as creating an app context.
151 wxTheApp
->OnInitGui();
153 // Here frames insert themselves automatically
154 // into wxTopLevelWindows by getting created
157 if (!wxTheApp
->OnInit()) return 0;
161 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
163 if (wxTheApp
->GetTopWindow())
165 delete wxTheApp
->GetTopWindow();
166 wxTheApp
->SetTopWindow(NULL
);
169 wxTheApp
->DeletePendingObjects();
178 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
179 // At this point we want to check if there are any memory
180 // blocks that aren't part of the wxDebugContext itself,
181 // as a special case. Then when dumping we need to ignore
182 // wxDebugContext, too.
183 if (wxDebugContext::CountObjectsLeft() > 0)
185 wxTrace("There were memory leaks.\n");
186 wxDebugContext::Dump();
187 wxDebugContext::PrintStatistics();
189 wxDebugContext::SetStream(NULL
, NULL
);
195 // Static member initialization
196 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
203 m_wantDebugOutput
= TRUE
;
208 m_printMode
= wxPRINT_WINDOWS
;
210 m_printMode
= wxPRINT_POSTSCRIPT
;
212 m_exitOnFrameDelete
= TRUE
;
216 bool wxApp::Initialized()
224 int wxApp::MainLoop()
228 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
231 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
241 // Returns TRUE if more time is needed.
242 bool wxApp::ProcessIdle()
245 event
.SetEventObject(this);
248 return event
.MoreRequested();
251 void wxApp::ExitMainLoop()
256 // Is a message/event pending?
257 bool wxApp::Pending()
264 // Dispatch a message.
265 void wxApp::Dispatch()
271 void wxApp::OnIdle(wxIdleEvent
& event
)
273 static bool inOnIdle
= FALSE
;
275 // Avoid recursion (via ProcessEvent default case)
281 // 'Garbage' collection of windows deleted with Close().
282 DeletePendingObjects();
284 // flush the logged messages if any
285 wxLog
*pLog
= wxLog::GetActiveTarget();
286 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
289 // Send OnIdle events to all windows
290 bool needMore
= SendIdleEvents();
293 event
.RequestMore(TRUE
);
298 // Send idle event to all top-level windows
299 bool wxApp::SendIdleEvents()
301 bool needMore
= FALSE
;
302 wxNode
* node
= wxTopLevelWindows
.First();
305 wxWindow
* win
= (wxWindow
*) node
->Data();
306 if (SendIdleEvents(win
))
314 // Send idle event to window and all subwindows
315 bool wxApp::SendIdleEvents(wxWindow
* win
)
317 bool needMore
= FALSE
;
320 event
.SetEventObject(win
);
321 win
->ProcessEvent(event
);
323 if (event
.MoreRequested())
326 wxNode
* node
= win
->GetChildren()->First();
329 wxWindow
* win
= (wxWindow
*) node
->Data();
330 if (SendIdleEvents(win
))
338 void wxApp::DeletePendingObjects()
340 wxNode
*node
= wxPendingDelete
.First();
343 wxObject
*obj
= (wxObject
*)node
->Data();
347 if (wxPendingDelete
.Member(obj
))
350 // Deleting one object may have deleted other pending
351 // objects, so start from beginning of list again.
352 node
= wxPendingDelete
.First();
356 wxLog
* wxApp::CreateLogTarget()
361 wxWindow
* wxApp::GetTopWindow() const
365 else if (wxTopLevelWindows
.Number() > 0)
366 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
375 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
376 * only for emergencies.
380 // Yield to other processes