]>
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];
60 wxClassInfo::InitializeClasses();
62 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
63 wxTheColourDatabase
->Initialize();
65 wxInitializeStockLists();
66 wxInitializeStockObjects();
68 #if wxUSE_WX_RESOURCES
69 wxInitializeResourceSystem();
72 wxBitmap::InitStandardHandlers();
74 wxModule::RegisterModules();
75 wxASSERT( wxModule::InitializeModules() == TRUE
);
82 wxModule::CleanUpModules();
84 #if wxUSE_WX_RESOURCES
85 wxCleanUpResourceSystem();
88 wxDeleteStockObjects() ;
90 // Destroy all GDI lists, etc.
92 delete wxTheBrushList
;
93 wxTheBrushList
= NULL
;
101 delete wxTheBitmapList
;
102 wxTheBitmapList
= NULL
;
104 delete wxTheColourDatabase
;
105 wxTheColourDatabase
= NULL
;
107 wxBitmap::CleanUpHandlers();
112 wxClassInfo::CleanUpClasses();
117 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
118 // At this point we want to check if there are any memory
119 // blocks that aren't part of the wxDebugContext itself,
120 // as a special case. Then when dumping we need to ignore
121 // wxDebugContext, too.
122 if (wxDebugContext::CountObjectsLeft() > 0)
124 wxTrace("There were memory leaks.\n");
125 wxDebugContext::Dump();
126 wxDebugContext::PrintStatistics();
128 // wxDebugContext::SetStream(NULL, NULL);
131 // do it as the very last thing because everything else can log messages
132 wxLog::DontCreateOnDemand();
133 // do it as the very last thing because everything else can log messages
134 delete wxLog::SetActiveTarget(NULL
);
137 int wxEntry( int argc
, char *argv
[] )
139 if (!wxApp::Initialize())
143 if (!wxApp::GetInitializerFunction())
145 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
149 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
154 printf( "wxWindows error: wxTheApp == NULL\n" );
158 wxTheApp
->argc
= argc
;
159 wxTheApp
->argv
= argv
;
161 // GUI-specific initialization, such as creating an app context.
162 wxTheApp
->OnInitGui();
164 // Here frames insert themselves automatically
165 // into wxTopLevelWindows by getting created
168 if (!wxTheApp
->OnInit()) return 0;
172 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
174 if (wxTheApp
->GetTopWindow())
176 delete wxTheApp
->GetTopWindow();
177 wxTheApp
->SetTopWindow(NULL
);
180 wxTheApp
->DeletePendingObjects();
189 // Static member initialization
190 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
197 m_wantDebugOutput
= TRUE
;
202 m_printMode
= wxPRINT_WINDOWS
;
204 m_printMode
= wxPRINT_POSTSCRIPT
;
206 m_exitOnFrameDelete
= TRUE
;
210 bool wxApp::Initialized()
218 int wxApp::MainLoop()
222 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
225 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
235 // Returns TRUE if more time is needed.
236 bool wxApp::ProcessIdle()
239 event
.SetEventObject(this);
242 return event
.MoreRequested();
245 void wxApp::ExitMainLoop()
250 // Is a message/event pending?
251 bool wxApp::Pending()
258 // Dispatch a message.
259 void wxApp::Dispatch()
265 void wxApp::OnIdle(wxIdleEvent
& event
)
267 static bool inOnIdle
= FALSE
;
269 // Avoid recursion (via ProcessEvent default case)
275 // 'Garbage' collection of windows deleted with Close().
276 DeletePendingObjects();
278 // flush the logged messages if any
279 wxLog
*pLog
= wxLog::GetActiveTarget();
280 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
283 // Send OnIdle events to all windows
284 bool needMore
= SendIdleEvents();
287 event
.RequestMore(TRUE
);
292 // Send idle event to all top-level windows
293 bool wxApp::SendIdleEvents()
295 bool needMore
= FALSE
;
296 wxNode
* node
= wxTopLevelWindows
.First();
299 wxWindow
* win
= (wxWindow
*) node
->Data();
300 if (SendIdleEvents(win
))
308 // Send idle event to window and all subwindows
309 bool wxApp::SendIdleEvents(wxWindow
* win
)
311 bool needMore
= FALSE
;
314 event
.SetEventObject(win
);
315 win
->ProcessEvent(event
);
317 if (event
.MoreRequested())
320 wxNode
* node
= win
->GetChildren().First();
323 wxWindow
* win
= (wxWindow
*) node
->Data();
324 if (SendIdleEvents(win
))
332 void wxApp::DeletePendingObjects()
334 wxNode
*node
= wxPendingDelete
.First();
337 wxObject
*obj
= (wxObject
*)node
->Data();
341 if (wxPendingDelete
.Member(obj
))
344 // Deleting one object may have deleted other pending
345 // objects, so start from beginning of list again.
346 node
= wxPendingDelete
.First();
350 wxLog
* wxApp::CreateLogTarget()
355 wxWindow
* wxApp::GetTopWindow() const
359 else if (wxTopLevelWindows
.Number() > 0)
360 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
369 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
370 * only for emergencies.
374 // Yield to other processes