]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/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"
31 #if wxUSE_WX_RESOURCES
32 #include "wx/resource.h"
37 #if defined(__WIN95__) && !defined(__GNUWIN32__)
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 void wxApp::CommonInit()
53 wxBuffer
= new char[1500];
55 wxBuffer
= new char[BUFSIZ
+ 512];
58 wxClassInfo::InitializeClasses();
60 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
61 wxTheColourDatabase
->Initialize();
62 wxInitializeStockObjects();
64 #if wxUSE_WX_RESOURCES
65 wxInitializeResourceSystem();
68 // For PostScript printing
70 wxInitializePrintSetupData();
71 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
72 wxThePrintPaperDatabase
->CreateDatabase();
75 wxBitmap::InitStandardHandlers();
77 wxModule::RegisterModules();
78 wxASSERT( wxModule::InitializeModules() == TRUE
);
81 void wxApp::CommonCleanUp()
83 wxModule::CleanUpModules();
85 #if wxUSE_WX_RESOURCES
86 wxCleanUpResourceSystem();
89 wxDeleteStockObjects() ;
91 // Destroy all GDI lists, etc.
92 delete wxTheBrushList
;
93 wxTheBrushList
= NULL
;
101 delete wxTheBitmapList
;
102 wxTheBitmapList
= NULL
;
104 delete wxTheColourDatabase
;
105 wxTheColourDatabase
= NULL
;
108 wxInitializePrintSetupData(FALSE
);
109 delete wxThePrintPaperDatabase
;
110 wxThePrintPaperDatabase
= NULL
;
113 wxBitmap::CleanUpHandlers();
118 // do it as the very last thing because everything else can log messages
119 delete wxLog::SetActiveTarget(NULL
);
122 int wxEntry( int argc
, char *argv
[] )
124 wxClassInfo::InitializeClasses();
126 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
128 #if !defined(_WINDLL)
129 streambuf
* sBuf
= new wxDebugStreamBuf
;
131 streambuf
* sBuf
= NULL
;
133 ostream
* oStr
= new ostream(sBuf
) ;
134 wxDebugContext::SetStream(oStr
, sBuf
);
140 if (!wxApp::GetInitializerFunction())
142 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
146 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
151 printf( "wxWindows error: wxTheApp == NULL\n" );
155 wxTheApp
->argc
= argc
;
156 wxTheApp
->argv
= argv
;
158 // TODO: your platform-specific initialization.
162 // GUI-specific initialization, such as creating an app context.
163 wxTheApp
->OnInitGui();
165 // Here frames insert themselves automatically
166 // into wxTopLevelWindows by getting created
169 if (!wxTheApp
->OnInit()) return 0;
171 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
175 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
177 wxTheApp
->DeletePendingObjects();
181 wxApp::CommonCleanUp();
183 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
184 // At this point we want to check if there are any memory
185 // blocks that aren't part of the wxDebugContext itself,
186 // as a special case. Then when dumping we need to ignore
187 // wxDebugContext, too.
188 if (wxDebugContext::CountObjectsLeft() > 0)
190 wxTrace("There were memory leaks.\n");
191 wxDebugContext::Dump();
192 wxDebugContext::PrintStatistics();
194 wxDebugContext::SetStream(NULL
, NULL
);
200 // Static member initialization
201 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
208 m_wantDebugOutput
= TRUE
;
213 m_printMode
= wxPRINT_WINDOWS
;
215 m_printMode
= wxPRINT_POSTSCRIPT
;
217 m_exitOnFrameDelete
= TRUE
;
221 bool wxApp::Initialized()
229 int wxApp::MainLoop()
233 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
236 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
246 // Returns TRUE if more time is needed.
247 bool wxApp::ProcessIdle()
250 event
.SetEventObject(this);
253 return event
.MoreRequested();
256 void wxApp::ExitMainLoop()
261 // Is a message/event pending?
262 bool wxApp::Pending()
269 // Dispatch a message.
270 void wxApp::Dispatch()
276 void wxApp::OnIdle(wxIdleEvent
& event
)
278 static bool inOnIdle
= FALSE
;
280 // Avoid recursion (via ProcessEvent default case)
286 // 'Garbage' collection of windows deleted with Close().
287 DeletePendingObjects();
289 // flush the logged messages if any
290 wxLog
*pLog
= wxLog::GetActiveTarget();
291 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
294 // Send OnIdle events to all windows
295 bool needMore
= SendIdleEvents();
298 event
.RequestMore(TRUE
);
303 // Send idle event to all top-level windows
304 bool wxApp::SendIdleEvents()
306 bool needMore
= FALSE
;
307 wxNode
* node
= wxTopLevelWindows
.First();
310 wxWindow
* win
= (wxWindow
*) node
->Data();
311 if (SendIdleEvents(win
))
319 // Send idle event to window and all subwindows
320 bool wxApp::SendIdleEvents(wxWindow
* win
)
322 bool needMore
= FALSE
;
325 event
.SetEventObject(win
);
326 win
->ProcessEvent(event
);
328 if (event
.MoreRequested())
331 wxNode
* node
= win
->GetChildren()->First();
334 wxWindow
* win
= (wxWindow
*) node
->Data();
335 if (SendIdleEvents(win
))
343 void wxApp::DeletePendingObjects()
345 wxNode
*node
= wxPendingDelete
.First();
348 wxObject
*obj
= (wxObject
*)node
->Data();
352 if (wxPendingDelete
.Member(obj
))
355 // Deleting one object may have deleted other pending
356 // objects, so start from beginning of list again.
357 node
= wxPendingDelete
.First();
361 wxLog
* wxApp::CreateLogTarget()
366 wxWindow
* wxApp::GetTopWindow() const
370 else if (wxTopLevelWindows
.Number() > 0)
371 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
378 wxApp::CommonCleanUp();
380 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
381 * only for emergencies.
385 // Yield to other processes