]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/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];
61 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
63 streambuf* sBuf = new wxDebugStreamBuf;
64 ostream* oStr = new ostream(sBuf) ;
65 wxDebugContext::SetStream(oStr, sBuf);
69 wxClassInfo::InitializeClasses();
71 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
72 wxTheColourDatabase
->Initialize();
74 wxInitializeStockLists();
75 wxInitializeStockObjects();
77 #if wxUSE_WX_RESOURCES
78 wxInitializeResourceSystem();
81 wxBitmap::InitStandardHandlers();
83 wxModule::RegisterModules();
84 wxASSERT( wxModule::InitializeModules() == TRUE
);
91 wxModule::CleanUpModules();
93 #if wxUSE_WX_RESOURCES
94 wxCleanUpResourceSystem();
97 wxDeleteStockObjects() ;
99 // Destroy all GDI lists, etc.
101 delete wxTheBrushList
;
102 wxTheBrushList
= NULL
;
107 delete wxTheFontList
;
108 wxTheFontList
= NULL
;
110 delete wxTheBitmapList
;
111 wxTheBitmapList
= NULL
;
113 delete wxTheColourDatabase
;
114 wxTheColourDatabase
= NULL
;
116 wxBitmap::CleanUpHandlers();
121 wxClassInfo::CleanUpClasses();
126 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
127 // At this point we want to check if there are any memory
128 // blocks that aren't part of the wxDebugContext itself,
129 // as a special case. Then when dumping we need to ignore
130 // wxDebugContext, too.
131 if (wxDebugContext::CountObjectsLeft() > 0)
133 wxTrace("There were memory leaks.\n");
134 wxDebugContext::Dump();
135 wxDebugContext::PrintStatistics();
137 // wxDebugContext::SetStream(NULL, NULL);
140 // do it as the very last thing because everything else can log messages
141 wxLog::DontCreateOnDemand();
142 // do it as the very last thing because everything else can log messages
143 delete wxLog::SetActiveTarget(NULL
);
146 int wxEntry( int argc
, char *argv
[] )
148 if (!wxApp::Initialize())
152 if (!wxApp::GetInitializerFunction())
154 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
158 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
163 printf( "wxWindows error: wxTheApp == NULL\n" );
167 wxTheApp
->argc
= argc
;
168 wxTheApp
->argv
= argv
;
170 // GUI-specific initialization, such as creating an app context.
171 wxTheApp
->OnInitGui();
173 // Here frames insert themselves automatically
174 // into wxTopLevelWindows by getting created
177 if (!wxTheApp
->OnInit()) return 0;
181 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
183 if (wxTheApp
->GetTopWindow())
185 delete wxTheApp
->GetTopWindow();
186 wxTheApp
->SetTopWindow(NULL
);
189 wxTheApp
->DeletePendingObjects();
198 // Static member initialization
199 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
206 m_wantDebugOutput
= TRUE
;
211 m_printMode
= wxPRINT_WINDOWS
;
213 m_printMode
= wxPRINT_POSTSCRIPT
;
215 m_exitOnFrameDelete
= TRUE
;
219 bool wxApp::Initialized()
227 int wxApp::MainLoop()
231 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
234 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
244 // Returns TRUE if more time is needed.
245 bool wxApp::ProcessIdle()
248 event
.SetEventObject(this);
251 return event
.MoreRequested();
254 void wxApp::ExitMainLoop()
259 // Is a message/event pending?
260 bool wxApp::Pending()
267 // Dispatch a message.
268 void wxApp::Dispatch()
274 void wxApp::OnIdle(wxIdleEvent
& event
)
276 static bool inOnIdle
= FALSE
;
278 // Avoid recursion (via ProcessEvent default case)
284 // 'Garbage' collection of windows deleted with Close().
285 DeletePendingObjects();
287 // flush the logged messages if any
288 wxLog
*pLog
= wxLog::GetActiveTarget();
289 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
292 // Send OnIdle events to all windows
293 bool needMore
= SendIdleEvents();
296 event
.RequestMore(TRUE
);
301 // Send idle event to all top-level windows
302 bool wxApp::SendIdleEvents()
304 bool needMore
= FALSE
;
305 wxNode
* node
= wxTopLevelWindows
.First();
308 wxWindow
* win
= (wxWindow
*) node
->Data();
309 if (SendIdleEvents(win
))
317 // Send idle event to window and all subwindows
318 bool wxApp::SendIdleEvents(wxWindow
* win
)
320 bool needMore
= FALSE
;
323 event
.SetEventObject(win
);
324 win
->ProcessEvent(event
);
326 if (event
.MoreRequested())
329 wxNode
* node
= win
->GetChildren().First();
332 wxWindow
* win
= (wxWindow
*) node
->Data();
333 if (SendIdleEvents(win
))
341 void wxApp::DeletePendingObjects()
343 wxNode
*node
= wxPendingDelete
.First();
346 wxObject
*obj
= (wxObject
*)node
->Data();
350 if (wxPendingDelete
.Member(obj
))
353 // Deleting one object may have deleted other pending
354 // objects, so start from beginning of list again.
355 node
= wxPendingDelete
.First();
359 wxLog
* wxApp::CreateLogTarget()
364 wxWindow
* wxApp::GetTopWindow() const
368 else if (wxTopLevelWindows
.Number() > 0)
369 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
378 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
379 * only for emergencies.
383 // Yield to other processes