]>
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"
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.
98 delete wxTheBrushList
;
99 wxTheBrushList
= NULL
;
104 delete wxTheFontList
;
105 wxTheFontList
= NULL
;
107 delete wxTheBitmapList
;
108 wxTheBitmapList
= NULL
;
110 delete wxTheColourDatabase
;
111 wxTheColourDatabase
= NULL
;
114 wxInitializePrintSetupData(FALSE
);
115 delete wxThePrintPaperDatabase
;
116 wxThePrintPaperDatabase
= NULL
;
119 wxBitmap::CleanUpHandlers();
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 wxClassInfo::InitializeClasses();
132 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
134 #if !defined(_WINDLL)
135 streambuf
* sBuf
= new wxDebugStreamBuf
;
137 streambuf
* sBuf
= NULL
;
139 ostream
* oStr
= new ostream(sBuf
) ;
140 wxDebugContext::SetStream(oStr
, sBuf
);
146 if (!wxApp::GetInitializerFunction())
148 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
152 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
157 printf( "wxWindows error: wxTheApp == NULL\n" );
161 wxTheApp
->argc
= argc
;
162 wxTheApp
->argv
= argv
;
164 // TODO: your platform-specific initialization.
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 wxTheApp
->DeletePendingObjects();
185 wxApp::CommonCleanUp();
187 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
188 // At this point we want to check if there are any memory
189 // blocks that aren't part of the wxDebugContext itself,
190 // as a special case. Then when dumping we need to ignore
191 // wxDebugContext, too.
192 if (wxDebugContext::CountObjectsLeft() > 0)
194 wxTrace("There were memory leaks.\n");
195 wxDebugContext::Dump();
196 wxDebugContext::PrintStatistics();
198 wxDebugContext::SetStream(NULL
, NULL
);
204 // Static member initialization
205 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
212 m_wantDebugOutput
= TRUE
;
217 m_printMode
= wxPRINT_WINDOWS
;
219 m_printMode
= wxPRINT_POSTSCRIPT
;
221 m_exitOnFrameDelete
= TRUE
;
225 bool wxApp::Initialized()
233 int wxApp::MainLoop()
237 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
240 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
250 // Returns TRUE if more time is needed.
251 bool wxApp::ProcessIdle()
254 event
.SetEventObject(this);
257 return event
.MoreRequested();
260 void wxApp::ExitMainLoop()
265 // Is a message/event pending?
266 bool wxApp::Pending()
273 // Dispatch a message.
274 void wxApp::Dispatch()
280 void wxApp::OnIdle(wxIdleEvent
& event
)
282 static bool inOnIdle
= FALSE
;
284 // Avoid recursion (via ProcessEvent default case)
290 // 'Garbage' collection of windows deleted with Close().
291 DeletePendingObjects();
293 // flush the logged messages if any
294 wxLog
*pLog
= wxLog::GetActiveTarget();
295 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
298 // Send OnIdle events to all windows
299 bool needMore
= SendIdleEvents();
302 event
.RequestMore(TRUE
);
307 // Send idle event to all top-level windows
308 bool wxApp::SendIdleEvents()
310 bool needMore
= FALSE
;
311 wxNode
* node
= wxTopLevelWindows
.First();
314 wxWindow
* win
= (wxWindow
*) node
->Data();
315 if (SendIdleEvents(win
))
323 // Send idle event to window and all subwindows
324 bool wxApp::SendIdleEvents(wxWindow
* win
)
326 bool needMore
= FALSE
;
329 event
.SetEventObject(win
);
330 win
->ProcessEvent(event
);
332 if (event
.MoreRequested())
335 wxNode
* node
= win
->GetChildren()->First();
338 wxWindow
* win
= (wxWindow
*) node
->Data();
339 if (SendIdleEvents(win
))
347 void wxApp::DeletePendingObjects()
349 wxNode
*node
= wxPendingDelete
.First();
352 wxObject
*obj
= (wxObject
*)node
->Data();
356 if (wxPendingDelete
.Member(obj
))
359 // Deleting one object may have deleted other pending
360 // objects, so start from beginning of list again.
361 node
= wxPendingDelete
.First();
365 wxLog
* wxApp::CreateLogTarget()
370 wxWindow
* wxApp::GetTopWindow() const
374 else if (wxTopLevelWindows
.Number() > 0)
375 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
382 wxApp::CommonCleanUp();
384 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
385 * only for emergencies.
389 // Yield to other processes