]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: app.cpp | |
3 | // Purpose: wxApp | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
afb74891 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
ee31c392 | 13 | #pragma implementation "app.h" |
4bb6408c JS |
14 | #endif |
15 | ||
bcd055ae JJ |
16 | #ifdef __VMS |
17 | #define XtParent XTPARENT | |
18 | #define XtDisplay XTDISPLAY | |
19 | #endif | |
20 | ||
4bb6408c JS |
21 | #include "wx/app.h" |
22 | #include "wx/utils.h" | |
4bb6408c JS |
23 | #include "wx/module.h" |
24 | #include "wx/memory.h" | |
8bedcdce RR |
25 | #include "wx/log.h" |
26 | #include "wx/intl.h" | |
7e1bcfa8 | 27 | #include "wx/evtloop.h" |
ed39ff57 | 28 | #include "wx/hash.h" |
9ce8d6a2 | 29 | #include "wx/hashmap.h" |
b412f9be | 30 | |
7bcb11d3 | 31 | #if wxUSE_THREADS |
dfe1eee3 | 32 | #include "wx/thread.h" |
7bcb11d3 | 33 | #endif |
4bb6408c | 34 | |
338dd992 JJ |
35 | #ifdef __VMS__ |
36 | #pragma message disable nosimpint | |
37 | #endif | |
4bb6408c JS |
38 | #include <Xm/Xm.h> |
39 | #include <X11/Xlib.h> | |
40 | #include <X11/Xutil.h> | |
41 | #include <X11/Xresource.h> | |
42 | #include <X11/Xatom.h> | |
338dd992 JJ |
43 | #ifdef __VMS__ |
44 | #pragma message enable nosimpint | |
45 | #endif | |
4bb6408c JS |
46 | |
47 | #include "wx/motif/private.h" | |
48 | ||
49 | #include <string.h> | |
50 | ||
eb6fa4b4 MB |
51 | struct wxPerDisplayData |
52 | { | |
53 | wxPerDisplayData() | |
54 | { m_visualInfo = NULL; m_topLevelWidget = NULL; } | |
55 | ||
56 | wxXVisualInfo* m_visualInfo; | |
57 | Widget m_topLevelWidget; | |
58 | }; | |
59 | ||
60 | WX_DECLARE_VOIDPTR_HASH_MAP( wxPerDisplayData, wxPerDisplayDataMap ); | |
61 | ||
62 | static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData, | |
63 | XtPointer ptr); | |
64 | static WXWidget wxCreateTopLevelWidget( WXDisplay* display ); | |
9ce8d6a2 | 65 | |
4bb6408c | 66 | extern wxList wxPendingDelete; |
7e1bcfa8 | 67 | extern bool wxAddIdleCallback(); |
7491d644 | 68 | |
4bb6408c JS |
69 | wxApp *wxTheApp = NULL; |
70 | ||
71 | wxHashTable *wxWidgetHashTable = NULL; | |
72 | ||
4bb6408c | 73 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) |
9c6e1335 | 74 | |
4bb6408c | 75 | BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) |
9c6e1335 | 76 | EVT_IDLE(wxApp::OnIdle) |
4bb6408c | 77 | END_EVENT_TABLE() |
4bb6408c | 78 | |
e838cc14 VZ |
79 | #ifdef __WXDEBUG__ |
80 | typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *); | |
81 | ||
82 | XErrorHandlerFunc gs_pfnXErrorHandler = 0; | |
83 | ||
84 | static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent) | |
85 | { | |
86 | // just forward to the default handler for now | |
87 | return gs_pfnXErrorHandler(dpy, xevent); | |
88 | } | |
89 | #endif // __WXDEBUG__ | |
90 | ||
4bb6408c JS |
91 | bool wxApp::Initialize() |
92 | { | |
4bb6408c | 93 | wxClassInfo::InitializeClasses(); |
afb74891 | 94 | |
ee31c392 | 95 | // GL: I'm annoyed ... I don't know where to put this and I don't want to |
4d3a259a GL |
96 | // create a module for that as it's part of the core. |
97 | #if wxUSE_THREADS | |
4d3a259a GL |
98 | wxPendingEventsLocker = new wxCriticalSection(); |
99 | #endif | |
100 | ||
4bb6408c JS |
101 | wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); |
102 | wxTheColourDatabase->Initialize(); | |
afb74891 | 103 | |
4b5f3fe6 | 104 | wxInitializeStockLists(); |
4bb6408c | 105 | wxInitializeStockObjects(); |
afb74891 | 106 | |
4bb6408c | 107 | wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); |
afb74891 | 108 | |
4bb6408c | 109 | wxModule::RegisterModules(); |
aaa38880 | 110 | if (!wxModule::InitializeModules()) return FALSE; |
afb74891 | 111 | |
4bb6408c JS |
112 | return TRUE; |
113 | } | |
114 | ||
115 | void wxApp::CleanUp() | |
116 | { | |
4bb6408c | 117 | wxModule::CleanUpModules(); |
afb74891 | 118 | |
4bb6408c | 119 | wxDeleteStockObjects() ; |
afb74891 | 120 | |
4bb6408c | 121 | // Destroy all GDI lists, etc. |
afb74891 | 122 | |
7ecb8b06 | 123 | wxDeleteStockLists(); |
afb74891 | 124 | |
4bb6408c JS |
125 | delete wxTheColourDatabase; |
126 | wxTheColourDatabase = NULL; | |
afb74891 | 127 | |
4bb6408c | 128 | wxClassInfo::CleanUpClasses(); |
afb74891 | 129 | |
184b5d99 JS |
130 | delete wxTheApp; |
131 | wxTheApp = NULL; | |
afb74891 | 132 | |
e6be3e7c MB |
133 | delete wxWidgetHashTable; |
134 | wxWidgetHashTable = NULL; | |
135 | ||
4d3a259a GL |
136 | // GL: I'm annoyed ... I don't know where to put this and I don't want to |
137 | // create a module for that as it's part of the core. | |
138 | #if wxUSE_THREADS | |
139 | delete wxPendingEvents; | |
b0feedc5 | 140 | wxPendingEvents = NULL; |
4d3a259a | 141 | delete wxPendingEventsLocker; |
b0feedc5 | 142 | wxPendingEventsLocker = NULL; |
4d3a259a GL |
143 | #endif |
144 | ||
184b5d99 JS |
145 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT |
146 | // At this point we want to check if there are any memory | |
147 | // blocks that aren't part of the wxDebugContext itself, | |
148 | // as a special case. Then when dumping we need to ignore | |
149 | // wxDebugContext, too. | |
4fabb575 | 150 | if (wxDebugContext::CountObjectsLeft(TRUE) > 0) |
184b5d99 | 151 | { |
2d120f83 JS |
152 | wxLogDebug("There were memory leaks.\n"); |
153 | wxDebugContext::Dump(); | |
154 | wxDebugContext::PrintStatistics(); | |
184b5d99 | 155 | } |
184b5d99 | 156 | #endif |
afb74891 | 157 | |
4bb6408c JS |
158 | // do it as the very last thing because everything else can log messages |
159 | wxLog::DontCreateOnDemand(); | |
160 | // do it as the very last thing because everything else can log messages | |
161 | delete wxLog::SetActiveTarget(NULL); | |
162 | } | |
163 | ||
e6be3e7c MB |
164 | // ============================================================================ |
165 | // wxEntry* | |
166 | // ============================================================================ | |
167 | ||
168 | int wxEntryStart( int argc, char* argv[] ) | |
4bb6408c | 169 | { |
4fabb575 JS |
170 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT |
171 | // This seems to be necessary since there are 'rogue' | |
172 | // objects present at this point (perhaps global objects?) | |
173 | // Setting a checkpoint will ignore them as far as the | |
174 | // memory checking facility is concerned. | |
175 | // Of course you may argue that memory allocated in globals should be | |
176 | // checked, but this is a reasonable compromise. | |
177 | wxDebugContext::SetCheckpoint(); | |
178 | #endif | |
afb74891 | 179 | |
4bb6408c | 180 | if (!wxApp::Initialize()) |
e6be3e7c MB |
181 | return -1; |
182 | ||
183 | return 0; | |
184 | } | |
185 | ||
186 | int wxEntryInitGui() | |
187 | { | |
188 | int retValue = 0; | |
189 | ||
190 | // GUI-specific initialization, such as creating an app context. | |
191 | if (!wxTheApp->OnInitGui()) | |
192 | retValue = -1; | |
193 | ||
194 | return retValue; | |
195 | } | |
196 | ||
197 | void wxEntryCleanup() | |
198 | { | |
199 | // So dialog boxes aren't used for further messages | |
200 | delete wxLog::SetActiveTarget(new wxLogStderr); | |
201 | ||
202 | // flush the logged messages if any | |
203 | wxLog *pLog = wxLog::GetActiveTarget(); | |
204 | if ( pLog != NULL && pLog->HasPendingMessages() ) | |
205 | pLog->Flush(); | |
206 | ||
207 | wxApp::CleanUp(); | |
208 | } | |
209 | ||
210 | int wxEntry( int argc, char *argv[] ) | |
211 | { | |
212 | int retValue = 0; | |
213 | ||
214 | retValue = wxEntryStart( argc, argv ); | |
215 | if (retValue) return retValue; | |
afb74891 | 216 | |
4bb6408c JS |
217 | if (!wxTheApp) |
218 | { | |
2d120f83 JS |
219 | if (!wxApp::GetInitializerFunction()) |
220 | { | |
221 | printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" ); | |
222 | return 0; | |
223 | }; | |
afb74891 | 224 | |
2d120f83 | 225 | wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) (); |
4bb6408c | 226 | }; |
afb74891 | 227 | |
4bb6408c JS |
228 | if (!wxTheApp) |
229 | { | |
2d120f83 JS |
230 | printf( "wxWindows error: wxTheApp == NULL\n" ); |
231 | return 0; | |
4bb6408c | 232 | }; |
afb74891 | 233 | |
4bb6408c JS |
234 | wxTheApp->SetClassName(wxFileNameFromPath(argv[0])); |
235 | wxTheApp->SetAppName(wxFileNameFromPath(argv[0])); | |
afb74891 | 236 | |
4bb6408c JS |
237 | wxTheApp->argc = argc; |
238 | wxTheApp->argv = argv; | |
afb74891 | 239 | |
4bb6408c | 240 | // GUI-specific initialization, such as creating an app context. |
e6be3e7c MB |
241 | retValue = wxEntryInitGui(); |
242 | if (retValue) return retValue; | |
afb74891 | 243 | |
e146b8c8 VZ |
244 | // Here frames insert themselves automatically into wxTopLevelWindows by |
245 | // getting created in OnInit(). | |
afb74891 | 246 | |
4fabb575 JS |
247 | if (wxTheApp->OnInit()) |
248 | { | |
e6be3e7c MB |
249 | if (wxTheApp->Initialized()) |
250 | wxTheApp->OnRun(); | |
4fabb575 | 251 | } |
afb74891 | 252 | |
4bb6408c JS |
253 | if (wxTheApp->GetTopWindow()) |
254 | { | |
2d120f83 JS |
255 | delete wxTheApp->GetTopWindow(); |
256 | wxTheApp->SetTopWindow(NULL); | |
4bb6408c | 257 | } |
afb74891 | 258 | |
4bb6408c | 259 | wxTheApp->DeletePendingObjects(); |
afb74891 | 260 | |
e6be3e7c | 261 | retValue = wxTheApp->OnExit(); |
afb74891 | 262 | |
e6be3e7c | 263 | wxEntryCleanup(); |
afb74891 | 264 | |
4bb6408c | 265 | return retValue; |
e6be3e7c | 266 | } |
4bb6408c JS |
267 | |
268 | // Static member initialization | |
ee31c392 | 269 | wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; |
4bb6408c JS |
270 | |
271 | wxApp::wxApp() | |
272 | { | |
4bb6408c JS |
273 | argc = 0; |
274 | argv = NULL; | |
afb74891 | 275 | |
7e1bcfa8 | 276 | m_eventLoop = new wxEventLoop; |
4bb6408c JS |
277 | m_mainColormap = (WXColormap) NULL; |
278 | m_appContext = (WXAppContext) NULL; | |
47bc1060 | 279 | m_initialDisplay = (WXDisplay*) 0; |
eb6fa4b4 | 280 | m_perDisplayData = new wxPerDisplayDataMap; |
4bb6408c JS |
281 | } |
282 | ||
7e1bcfa8 MB |
283 | wxApp::~wxApp() |
284 | { | |
285 | delete m_eventLoop; | |
9ce8d6a2 | 286 | |
eb6fa4b4 MB |
287 | for( wxPerDisplayDataMap::iterator it = m_perDisplayData->begin(), |
288 | end = m_perDisplayData->end(); | |
9ce8d6a2 MB |
289 | it != end; ++it ) |
290 | { | |
eb6fa4b4 MB |
291 | delete it->second.m_visualInfo; |
292 | XtDestroyWidget( it->second.m_topLevelWidget ); | |
9ce8d6a2 MB |
293 | } |
294 | ||
eb6fa4b4 MB |
295 | delete m_perDisplayData; |
296 | ||
297 | wxTheApp = NULL; | |
7e1bcfa8 MB |
298 | } |
299 | ||
4bb6408c JS |
300 | bool wxApp::Initialized() |
301 | { | |
302 | if (GetTopWindow()) | |
2d120f83 | 303 | return TRUE; |
4bb6408c | 304 | else |
2d120f83 | 305 | return FALSE; |
4bb6408c JS |
306 | } |
307 | ||
308 | int wxApp::MainLoop() | |
309 | { | |
2d120f83 | 310 | /* |
4bb6408c JS |
311 | * Sit around forever waiting to process X-events. Property Change |
312 | * event are handled special, because they have to refer to | |
313 | * the root window rather than to a widget. therefore we can't | |
314 | * use an Xt-eventhandler. | |
315 | */ | |
afb74891 | 316 | |
4bb6408c | 317 | XSelectInput(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), |
2d120f83 JS |
318 | XDefaultRootWindow(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())), |
319 | PropertyChangeMask); | |
afb74891 | 320 | |
7e1bcfa8 | 321 | m_eventLoop->Run(); |
afb74891 | 322 | |
8aa04e8b JS |
323 | return 0; |
324 | } | |
325 | ||
7e1bcfa8 | 326 | // Processes an idle event. |
4bb6408c JS |
327 | // Returns TRUE if more time is needed. |
328 | bool wxApp::ProcessIdle() | |
329 | { | |
330 | wxIdleEvent event; | |
afb74891 | 331 | |
7e1bcfa8 | 332 | return ProcessEvent(event) && event.MoreRequested(); |
4bb6408c JS |
333 | } |
334 | ||
335 | void wxApp::ExitMainLoop() | |
336 | { | |
e6be3e7c MB |
337 | if( m_eventLoop->IsRunning() ) |
338 | m_eventLoop->Exit(); | |
4bb6408c JS |
339 | } |
340 | ||
341 | // Is a message/event pending? | |
342 | bool wxApp::Pending() | |
343 | { | |
ba2fcb07 MB |
344 | return m_eventLoop->Pending(); |
345 | #if 0 | |
4bb6408c | 346 | XFlush(XtDisplay( (Widget) wxTheApp->GetTopLevelWidget() )); |
afb74891 | 347 | |
8aa04e8b JS |
348 | // Fix by Doug from STI, to prevent a stall if non-X event |
349 | // is found. | |
350 | return ((XtAppPending( (XtAppContext) GetAppContext() ) & XtIMXEvent) != 0) ; | |
ba2fcb07 | 351 | #endif |
4bb6408c JS |
352 | } |
353 | ||
354 | // Dispatch a message. | |
355 | void wxApp::Dispatch() | |
356 | { | |
7e1bcfa8 | 357 | m_eventLoop->Dispatch(); |
4bb6408c JS |
358 | } |
359 | ||
360 | // This should be redefined in a derived class for | |
361 | // handling property change events for XAtom IPC. | |
362 | void wxApp::HandlePropertyChange(WXEvent *event) | |
363 | { | |
364 | // by default do nothing special | |
365 | XtDispatchEvent((XEvent*) event); /* let Motif do the work */ | |
366 | } | |
367 | ||
368 | void wxApp::OnIdle(wxIdleEvent& event) | |
369 | { | |
370 | static bool inOnIdle = FALSE; | |
afb74891 | 371 | |
4bb6408c JS |
372 | // Avoid recursion (via ProcessEvent default case) |
373 | if (inOnIdle) | |
2d120f83 | 374 | return; |
afb74891 | 375 | |
4bb6408c | 376 | inOnIdle = TRUE; |
afb74891 | 377 | |
0ca580f6 GRG |
378 | // If there are pending events, we must process them: pending events |
379 | // are either events to the threads other than main or events posted | |
380 | // with wxPostEvent() functions | |
381 | // GRG: I have moved this here so that all pending events are processed | |
382 | // before starting to delete any objects. This behaves better (in | |
383 | // particular, wrt wxPostEvent) and is coherent with wxGTK's current | |
384 | // behaviour. Also removed the '#if wxUSE_THREADS' around it. | |
385 | // Changed Mar/2000 before 2.1.14 | |
afb74891 | 386 | |
7214297d GL |
387 | // Flush pending events. |
388 | ProcessPendingEvents(); | |
0ca580f6 GRG |
389 | |
390 | // 'Garbage' collection of windows deleted with Close(). | |
391 | DeletePendingObjects(); | |
7214297d | 392 | |
4bb6408c JS |
393 | // flush the logged messages if any |
394 | wxLog *pLog = wxLog::GetActiveTarget(); | |
395 | if ( pLog != NULL && pLog->HasPendingMessages() ) | |
2d120f83 | 396 | pLog->Flush(); |
afb74891 | 397 | |
4bb6408c JS |
398 | // Send OnIdle events to all windows |
399 | bool needMore = SendIdleEvents(); | |
afb74891 | 400 | |
4bb6408c | 401 | if (needMore) |
2d120f83 | 402 | event.RequestMore(TRUE); |
afb74891 | 403 | |
4bb6408c JS |
404 | inOnIdle = FALSE; |
405 | } | |
406 | ||
407 | // Send idle event to all top-level windows | |
408 | bool wxApp::SendIdleEvents() | |
409 | { | |
410 | bool needMore = FALSE; | |
e146b8c8 VZ |
411 | |
412 | wxWindowList::Node* node = wxTopLevelWindows.GetFirst(); | |
2d120f83 JS |
413 | while (node) |
414 | { | |
e146b8c8 | 415 | wxWindow* win = node->GetData(); |
2d120f83 | 416 | if (SendIdleEvents(win)) |
4bb6408c | 417 | needMore = TRUE; |
e146b8c8 | 418 | node = node->GetNext(); |
2d120f83 | 419 | } |
e146b8c8 | 420 | |
4bb6408c JS |
421 | return needMore; |
422 | } | |
423 | ||
424 | // Send idle event to window and all subwindows | |
425 | bool wxApp::SendIdleEvents(wxWindow* win) | |
426 | { | |
427 | bool needMore = FALSE; | |
afb74891 | 428 | |
2d120f83 JS |
429 | wxIdleEvent event; |
430 | event.SetEventObject(win); | |
44f5b995 | 431 | win->GetEventHandler()->ProcessEvent(event); |
afb74891 | 432 | |
4bb6408c JS |
433 | if (event.MoreRequested()) |
434 | needMore = TRUE; | |
afb74891 | 435 | |
fd304d98 | 436 | wxWindowList::Node* node = win->GetChildren().GetFirst(); |
2d120f83 JS |
437 | while (node) |
438 | { | |
fd304d98 | 439 | wxWindow* win = node->GetData(); |
2d120f83 | 440 | if (SendIdleEvents(win)) |
4bb6408c | 441 | needMore = TRUE; |
afb74891 | 442 | |
fd304d98 | 443 | node = node->GetNext(); |
2d120f83 | 444 | } |
4bb6408c JS |
445 | return needMore ; |
446 | } | |
447 | ||
448 | void wxApp::DeletePendingObjects() | |
449 | { | |
7e1bcfa8 | 450 | wxList::Node *node = wxPendingDelete.GetFirst(); |
4bb6408c JS |
451 | while (node) |
452 | { | |
fd304d98 | 453 | wxObject *obj = node->GetData(); |
afb74891 | 454 | |
2d120f83 | 455 | delete obj; |
afb74891 | 456 | |
2d120f83 JS |
457 | if (wxPendingDelete.Member(obj)) |
458 | delete node; | |
afb74891 | 459 | |
2d120f83 JS |
460 | // Deleting one object may have deleted other pending |
461 | // objects, so start from beginning of list again. | |
fd304d98 | 462 | node = wxPendingDelete.GetFirst(); |
4bb6408c JS |
463 | } |
464 | } | |
465 | ||
edc1cd8b JS |
466 | static char *fallbackResources[] = { |
467 | "*menuBar.marginHeight: 0", | |
468 | "*menuBar.shadowThickness: 1", | |
469 | "*background: #c0c0c0", | |
470 | "*foreground: black", | |
471 | NULL | |
472 | }; | |
473 | ||
4bb6408c JS |
474 | // Create an application context |
475 | bool wxApp::OnInitGui() | |
476 | { | |
fd304d98 MB |
477 | if( !wxAppBase::OnInitGui() ) |
478 | return FALSE; | |
479 | ||
4bb6408c | 480 | XtToolkitInitialize() ; |
edc1cd8b JS |
481 | wxTheApp->m_appContext = (WXAppContext) XtCreateApplicationContext(); |
482 | XtAppSetFallbackResources((XtAppContext) wxTheApp->m_appContext, fallbackResources); | |
483 | ||
4bb6408c | 484 | Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL, |
d3a80c92 | 485 | wxTheApp->GetClassName().c_str(), NULL, 0, |
4bb6408c | 486 | # if XtSpecificationRelease < 5 |
9c6e1335 | 487 | (Cardinal*) &argc, |
4bb6408c | 488 | # else |
9c6e1335 | 489 | &argc, |
4bb6408c | 490 | # endif |
9c6e1335 VZ |
491 | argv); |
492 | ||
4bb6408c | 493 | if (!dpy) { |
c88b736c MB |
494 | // if you don't log to stderr, nothing will be shown... |
495 | delete wxLog::SetActiveTarget(new wxLogStderr); | |
7bcb11d3 | 496 | wxString className(wxTheApp->GetClassName()); |
9c6e1335 | 497 | wxLogError(_("wxWindows could not open display for '%s': exiting."), |
d3a80c92 | 498 | className.c_str()); |
2d120f83 | 499 | exit(-1); |
4bb6408c | 500 | } |
47bc1060 | 501 | m_initialDisplay = (WXDisplay*) dpy; |
afb74891 | 502 | |
e838cc14 VZ |
503 | #ifdef __WXDEBUG__ |
504 | // install the X error handler | |
505 | gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); | |
506 | #endif // __WXDEBUG__ | |
507 | ||
4bb6408c JS |
508 | // Add general resize proc |
509 | XtActionsRec rec; | |
510 | rec.string = "resize"; | |
511 | rec.proc = (XtActionProc)wxWidgetResizeProc; | |
512 | XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1); | |
afb74891 | 513 | |
4bb6408c | 514 | GetMainColormap(dpy); |
afb74891 | 515 | |
7e1bcfa8 MB |
516 | wxAddIdleCallback(); |
517 | ||
4bb6408c JS |
518 | return TRUE; |
519 | } | |
520 | ||
521 | WXColormap wxApp::GetMainColormap(WXDisplay* display) | |
522 | { | |
523 | if (!display) /* Must be called first with non-NULL display */ | |
2d120f83 | 524 | return m_mainColormap; |
a91b47e8 JS |
525 | |
526 | int defaultScreen = DefaultScreen((Display*) display); | |
527 | Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen); | |
afb74891 | 528 | |
a91b47e8 | 529 | Colormap c = DefaultColormapOfScreen(screen); |
afb74891 | 530 | |
4bb6408c | 531 | if (!m_mainColormap) |
2d120f83 | 532 | m_mainColormap = (WXColormap) c; |
afb74891 | 533 | |
4bb6408c JS |
534 | return (WXColormap) c; |
535 | } | |
536 | ||
9ce8d6a2 MB |
537 | wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display ) |
538 | { | |
eb6fa4b4 | 539 | wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display ); |
9ce8d6a2 | 540 | |
eb6fa4b4 MB |
541 | if( it != m_perDisplayData->end() && it->second.m_visualInfo ) |
542 | return it->second.m_visualInfo; | |
9ce8d6a2 MB |
543 | |
544 | wxXVisualInfo* vi = new wxXVisualInfo; | |
545 | wxFillXVisualInfo( vi, (Display*)display ); | |
546 | ||
eb6fa4b4 | 547 | (*m_perDisplayData)[display].m_visualInfo = vi; |
9ce8d6a2 MB |
548 | |
549 | return vi; | |
550 | } | |
551 | ||
eb6fa4b4 MB |
552 | static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData, |
553 | XtPointer ptr) | |
554 | { | |
555 | if( wxTheApp ) | |
556 | wxTheApp->SetTopLevelWidget( (WXDisplay*)XtDisplay(w), | |
557 | (WXWidget)NULL ); | |
558 | } | |
559 | ||
560 | WXWidget wxCreateTopLevelWidget( WXDisplay* display ) | |
561 | { | |
562 | Widget tlw = XtAppCreateShell( (String)NULL, | |
563 | wxTheApp->GetClassName().c_str(), | |
564 | applicationShellWidgetClass, | |
565 | (Display*)display, | |
566 | NULL, 0 ); | |
732c0bfd | 567 | XtSetMappedWhenManaged( tlw, False ); |
dd38c875 | 568 | XtRealizeWidget( tlw ); |
eb6fa4b4 MB |
569 | |
570 | XtAddCallback( tlw, XmNdestroyCallback, | |
571 | (XtCallbackProc)wxTLWidgetDestroyCallback, | |
572 | (XtPointer)NULL ); | |
573 | ||
574 | return (WXWidget)tlw; | |
575 | } | |
576 | ||
577 | WXWidget wxApp::GetTopLevelWidget() | |
578 | { | |
579 | WXDisplay* display = wxGetDisplay(); | |
580 | wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display ); | |
581 | ||
582 | if( it != m_perDisplayData->end() && it->second.m_topLevelWidget ) | |
583 | return (WXWidget)it->second.m_topLevelWidget; | |
584 | ||
585 | WXWidget tlw = wxCreateTopLevelWidget( display ); | |
586 | SetTopLevelWidget( display, tlw ); | |
587 | ||
588 | return tlw; | |
589 | } | |
590 | ||
591 | void wxApp::SetTopLevelWidget(WXDisplay* display, WXWidget widget) | |
592 | { | |
593 | (*m_perDisplayData)[display].m_topLevelWidget = (Widget)widget; | |
594 | } | |
595 | ||
4bb6408c JS |
596 | void wxExit() |
597 | { | |
598 | int retValue = 0; | |
599 | if (wxTheApp) | |
2d120f83 | 600 | retValue = wxTheApp->OnExit(); |
afb74891 | 601 | |
4bb6408c JS |
602 | wxApp::CleanUp(); |
603 | /* | |
d03bb63c MB |
604 | * Exit in some platform-specific way. |
605 | * Not recommended that the app calls this: | |
2d120f83 JS |
606 | * only for emergencies. |
607 | */ | |
4bb6408c JS |
608 | exit(retValue); |
609 | } | |
610 | ||
611 | // Yield to other processes | |
cb2713bf | 612 | |
8461e4c2 | 613 | bool wxApp::Yield(bool onlyIfNeeded) |
4bb6408c | 614 | { |
8461e4c2 VZ |
615 | bool s_inYield = FALSE; |
616 | ||
617 | if ( s_inYield ) | |
618 | { | |
619 | if ( !onlyIfNeeded ) | |
620 | { | |
621 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
622 | } | |
623 | ||
624 | return FALSE; | |
625 | } | |
626 | ||
627 | s_inYield = TRUE; | |
cb2713bf | 628 | |
4bb6408c | 629 | while (wxTheApp && wxTheApp->Pending()) |
2d120f83 | 630 | wxTheApp->Dispatch(); |
518b5d2f | 631 | |
8461e4c2 | 632 | s_inYield = FALSE; |
cb2713bf | 633 | |
4bb6408c JS |
634 | return TRUE; |
635 | } | |
636 | ||
d391a345 VZ |
637 | // ---------------------------------------------------------------------------- |
638 | // accessors for C modules | |
639 | // ---------------------------------------------------------------------------- | |
640 | ||
641 | extern "C" XtAppContext wxGetAppContext() | |
642 | { | |
643 | return (XtAppContext)wxTheApp->GetAppContext(); | |
644 | } |