1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
21 #include "wx/dialog.h"
23 #include "wx/module.h"
24 #include "wx/memory.h"
27 #include "wx/evtloop.h"
29 #include "wx/filename.h"
32 #include "wx/univ/theme.h"
33 #include "wx/univ/renderer.h"
35 #define ABS(a) (((a) < 0) ? -(a) : (a))
38 #include "wx/thread.h"
41 #if wxUSE_WX_RESOURCES
42 #include "wx/resource.h"
45 #include "wx/x11/private.h"
49 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
53 extern wxList wxPendingDelete
;
55 wxHashTable
*wxWidgetHashTable
= NULL
;
56 wxHashTable
*wxClientWidgetHashTable
= NULL
;
58 wxApp
*wxTheApp
= NULL
;
60 // This is set within wxEntryStart -- too early on
61 // to put these in wxTheApp
62 static bool g_showIconic
= FALSE
;
63 static wxSize g_initialSize
= wxDefaultSize
;
65 // This is required for wxFocusEvent::SetWindow(). It will only
66 // work for focus events which we provoke ourselves (by calling
67 // SetFocus()). It will not work for those events, which X11
69 static wxWindow
*g_nextFocus
= NULL
;
70 static wxWindow
*g_prevFocus
= NULL
;
72 //------------------------------------------------------------------------
74 //------------------------------------------------------------------------
77 typedef int (*XErrorHandlerFunc
)(Display
*, XErrorEvent
*);
79 XErrorHandlerFunc gs_pfnXErrorHandler
= 0;
81 static int wxXErrorHandler(Display
*dpy
, XErrorEvent
*xevent
)
83 // just forward to the default handler for now
84 if (gs_pfnXErrorHandler
)
85 return gs_pfnXErrorHandler(dpy
, xevent
);
91 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
95 long wxApp::sm_lastMessageTime
= 0;
96 WXDisplay
*wxApp::ms_display
= NULL
;
98 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
100 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
101 EVT_IDLE(wxApp::OnIdle
)
104 bool wxApp::Initialize()
106 wxClassInfo::InitializeClasses();
109 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
112 // GL: I'm annoyed ... I don't know where to put this and I don't want to
113 // create a module for that as it's part of the core.
115 wxPendingEventsLocker
= new wxCriticalSection();
118 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
119 wxTheColourDatabase
->Initialize();
121 wxInitializeStockLists();
122 wxInitializeStockObjects();
124 #if wxUSE_WX_RESOURCES
125 wxInitializeResourceSystem();
128 wxWidgetHashTable
= new wxHashTable(wxKEY_INTEGER
);
129 wxClientWidgetHashTable
= new wxHashTable(wxKEY_INTEGER
);
131 wxModule::RegisterModules();
132 if (!wxModule::InitializeModules()) return FALSE
;
137 void wxApp::CleanUp()
139 delete wxWidgetHashTable
;
140 wxWidgetHashTable
= NULL
;
141 delete wxClientWidgetHashTable
;
142 wxClientWidgetHashTable
= NULL
;
144 wxModule::CleanUpModules();
146 #if wxUSE_WX_RESOURCES
147 wxCleanUpResourceSystem();
150 delete wxTheColourDatabase
;
151 wxTheColourDatabase
= NULL
;
153 wxDeleteStockObjects();
155 wxDeleteStockLists();
160 wxClassInfo::CleanUpClasses();
163 delete wxPendingEvents
;
164 delete wxPendingEventsLocker
;
167 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
168 // At this point we want to check if there are any memory
169 // blocks that aren't part of the wxDebugContext itself,
170 // as a special case. Then when dumping we need to ignore
171 // wxDebugContext, too.
172 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
174 wxLogDebug("There were memory leaks.");
175 wxDebugContext::Dump();
176 wxDebugContext::PrintStatistics();
180 // do it as the very last thing because everything else can log messages
181 wxLog::DontCreateOnDemand();
182 // do it as the very last thing because everything else can log messages
183 delete wxLog::SetActiveTarget(NULL
);
186 // NB: argc and argv may be changed here, pass by reference!
187 int wxEntryStart( int& argc
, char *argv
[] )
191 // install the X error handler
192 gs_pfnXErrorHandler
= XSetErrorHandler( wxXErrorHandler
);
194 #endif // __WXDEBUG__
196 char *displayName
= NULL
;
197 bool syncDisplay
= FALSE
;
200 for (i
= 0; i
< argc
; i
++)
202 if (strcmp( argv
[i
], "-display") == 0)
207 displayName
= argv
[i
];
211 else if (strcmp( argv
[i
], "-geometry") == 0)
217 if (sscanf(argv
[i
], "%dx%d", &w
, &h
) != 2)
219 wxLogError( _("Invalid geometry specification '%s'"), wxString::FromAscii(argv
[i
]).c_str() );
223 g_initialSize
= wxSize(w
, h
);
228 else if (strcmp( argv
[i
], "-sync") == 0)
233 else if (strcmp( argv
[i
], "-iconic") == 0)
243 Display
* xdisplay
= XOpenDisplay( displayName
);
246 wxLogError( _("wxWindows could not open display. Exiting.") );
251 XSynchronize(xdisplay
, True
);
253 wxApp::ms_display
= (WXDisplay
*) xdisplay
;
255 XSelectInput( xdisplay
, XDefaultRootWindow(xdisplay
), PropertyChangeMask
);
258 wxSetDetectableAutoRepeat( TRUE
);
261 // Glib's type system required by Pango
265 if (!wxApp::Initialize())
275 if ( !wxTheApp
->OnInitGui() )
282 int wxEntry( int argc
, char *argv
[] )
284 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
285 // This seems to be necessary since there are 'rogue'
286 // objects present at this point (perhaps global objects?)
287 // Setting a checkpoint will ignore them as far as the
288 // memory checking facility is concerned.
289 // Of course you may argue that memory allocated in globals should be
290 // checked, but this is a reasonable compromise.
291 wxDebugContext::SetCheckpoint();
293 int err
= wxEntryStart(argc
, argv
);
299 if (!wxApp::GetInitializerFunction())
301 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
305 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
310 printf( "wxWindows error: wxTheApp == NULL\n" );
314 // Command line argument stuff
315 wxTheApp
->argc
= argc
;
317 wxTheApp
->argv
= new wxChar
*[argc
+1];
319 while (mb_argc
< argc
)
321 wxString tmp
= wxString::FromAscii( argv
[mb_argc
] );
322 wxTheApp
->argv
[mb_argc
] = wxStrdup( tmp
.c_str() );
325 wxTheApp
->argv
[mb_argc
] = (wxChar
*)NULL
;
327 wxTheApp
->argv
= argv
;
330 if (wxTheApp
->argc
> 0)
332 wxFileName
fname( wxTheApp
->argv
[0] );
333 wxTheApp
->SetAppName( fname
.GetName() );
336 wxTheApp
->m_showIconic
= g_showIconic
;
337 wxTheApp
->m_initialSize
= g_initialSize
;
340 retValue
= wxEntryInitGui();
342 // Here frames insert themselves automatically into wxTopLevelWindows by
343 // getting created in OnInit().
346 if ( !wxTheApp
->OnInit() )
352 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
355 // flush the logged messages if any
356 wxLog
*pLog
= wxLog::GetActiveTarget();
357 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
360 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
361 // for further messages
363 if (wxTheApp
->GetTopWindow())
365 delete wxTheApp
->GetTopWindow();
366 wxTheApp
->SetTopWindow(NULL
);
369 wxTheApp
->DeletePendingObjects();
378 // Static member initialization
379 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
383 // TODO: parse the command line
387 m_mainColormap
= (WXColormap
) NULL
;
388 m_topLevelWidget
= (WXWindow
) NULL
;
389 m_maxRequestSize
= 0;
391 m_showIconic
= FALSE
;
392 m_initialSize
= wxDefaultSize
;
395 m_visualColormap
= NULL
;
406 if (m_visualColormap
)
407 delete [] (XColor
*)m_visualColormap
;
411 bool wxApp::Initialized()
419 int wxApp::MainLoop()
422 m_mainLoop
= new wxEventLoop
;
424 rt
= m_mainLoop
->Run();
432 //-----------------------------------------------------------------------
433 // X11 predicate function for exposure compression
434 //-----------------------------------------------------------------------
439 Bool found_non_matching
;
442 static Bool
expose_predicate (Display
*display
, XEvent
*xevent
, XPointer arg
)
444 wxExposeInfo
*info
= (wxExposeInfo
*) arg
;
446 if (info
->found_non_matching
)
449 if (xevent
->xany
.type
!= Expose
)
451 info
->found_non_matching
= TRUE
;
455 if (xevent
->xexpose
.window
!= info
->window
)
457 info
->found_non_matching
= TRUE
;
466 //-----------------------------------------------------------------------
467 // Processes an X event, returning TRUE if the event was processed.
468 //-----------------------------------------------------------------------
470 bool wxApp::ProcessXEvent(WXEvent
* _event
)
472 XEvent
* event
= (XEvent
*) _event
;
474 wxWindow
* win
= NULL
;
475 Window window
= XEventGetWindow(event
);
477 Window actualWindow
= window
;
480 // Find the first wxWindow that corresponds to this event window
481 // Because we're receiving events after a window
482 // has been destroyed, assume a 1:1 match between
483 // Window and wxWindow, so if it's not in the table,
484 // it must have been destroyed.
486 win
= wxGetWindowFromTable(window
);
489 #if wxUSE_TWO_WINDOWS
490 win
= wxGetClientWindowFromTable(window
);
497 wxString windowClass
= win
->GetClassInfo()->GetClassName();
504 #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX
505 if (event
->xexpose
.window
!= (Window
)win
->GetClientAreaWindow())
509 info
.window
= event
->xexpose
.window
;
510 info
.found_non_matching
= FALSE
;
511 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event
, expose_predicate
, (XPointer
) &info
))
513 // Don't worry about optimizing redrawing the border etc.
515 win
->NeedUpdateNcAreaInIdle();
520 win
->GetUpdateRegion().Union( XExposeEventGetX(event
), XExposeEventGetY(event
),
521 XExposeEventGetWidth(event
), XExposeEventGetHeight(event
));
522 win
->GetClearRegion().Union( XExposeEventGetX(event
), XExposeEventGetY(event
),
523 XExposeEventGetWidth(event
), XExposeEventGetHeight(event
));
528 info
.window
= event
->xexpose
.window
;
529 info
.found_non_matching
= FALSE
;
530 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event
, expose_predicate
, (XPointer
) &info
))
532 win
->GetUpdateRegion().Union( tmp_event
.xexpose
.x
, tmp_event
.xexpose
.y
,
533 tmp_event
.xexpose
.width
, tmp_event
.xexpose
.height
);
535 win
->GetClearRegion().Union( tmp_event
.xexpose
.x
, tmp_event
.xexpose
.y
,
536 tmp_event
.xexpose
.width
, tmp_event
.xexpose
.height
);
540 // This simplifies the expose and clear areas to simple
542 win
->GetUpdateRegion() = win
->GetUpdateRegion().GetBox();
543 win
->GetClearRegion() = win
->GetClearRegion().GetBox();
545 // If we only have one X11 window, always indicate
546 // that borders might have to be redrawn.
547 if (win
->GetMainWindow() == win
->GetClientAreaWindow())
548 win
->NeedUpdateNcAreaInIdle();
550 // Only erase background, paint in idle time.
551 win
->SendEraseEvents();
561 printf( "GraphicExpose event\n" );
563 wxLogTrace( _T("expose"), _T("GraphicsExpose from %s"), win
->GetName().c_str());
565 win
->GetUpdateRegion().Union( event
->xgraphicsexpose
.x
, event
->xgraphicsexpose
.y
,
566 event
->xgraphicsexpose
.width
, event
->xgraphicsexpose
.height
);
568 win
->GetClearRegion().Union( event
->xgraphicsexpose
.x
, event
->xgraphicsexpose
.y
,
569 event
->xgraphicsexpose
.width
, event
->xgraphicsexpose
.height
);
571 if (event
->xgraphicsexpose
.count
== 0)
573 // Only erase background, paint in idle time.
574 win
->SendEraseEvents();
584 if (!win
->IsEnabled())
587 wxKeyEvent
keyEvent(wxEVT_KEY_DOWN
);
588 wxTranslateKeyEvent(keyEvent
, win
, window
, event
);
590 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
592 // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
593 if (win
->GetEventHandler()->ProcessEvent( keyEvent
))
596 keyEvent
.SetEventType(wxEVT_CHAR
);
597 // Do the translation again, retaining the ASCII
599 wxTranslateKeyEvent(keyEvent
, win
, window
, event
, TRUE
);
600 if (win
->GetEventHandler()->ProcessEvent( keyEvent
))
603 if ( (keyEvent
.m_keyCode
== WXK_TAB
) &&
604 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
606 wxNavigationKeyEvent new_event
;
607 new_event
.SetEventObject( win
->GetParent() );
608 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
609 new_event
.SetDirection( (keyEvent
.m_keyCode
== WXK_TAB
) );
610 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
611 new_event
.SetWindowChange( keyEvent
.ControlDown() );
612 new_event
.SetCurrentFocus( win
);
613 return win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
620 if (!win
->IsEnabled())
623 wxKeyEvent
keyEvent(wxEVT_KEY_UP
);
624 wxTranslateKeyEvent(keyEvent
, win
, window
, event
);
626 return win
->GetEventHandler()->ProcessEvent( keyEvent
);
628 case ConfigureNotify
:
631 if (event
->update
.utype
== GR_UPDATE_SIZE
)
634 if (win
->IsTopLevel())
636 wxTopLevelWindow
*tlw
= (wxTopLevelWindow
*) win
;
637 tlw
->SetConfigureGeometry( XConfigureEventGetX(event
), XConfigureEventGetY(event
),
638 XConfigureEventGetWidth(event
), XConfigureEventGetHeight(event
) );
641 if (win
->IsTopLevel() && win
->IsShown())
643 wxTopLevelWindowX11
*tlw
= (wxTopLevelWindowX11
*) win
;
644 tlw
->SetNeedResizeInIdle();
648 wxSizeEvent
sizeEvent( wxSize(XConfigureEventGetWidth(event
), XConfigureEventGetHeight(event
)), win
->GetId() );
649 sizeEvent
.SetEventObject( win
);
651 return win
->GetEventHandler()->ProcessEvent( sizeEvent
);
660 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
661 return HandlePropertyChange(_event
);
665 if (!win
->IsEnabled())
668 Atom wm_delete_window
= XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True
);
669 Atom wm_protocols
= XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True
);
671 if (event
->xclient
.message_type
== wm_protocols
)
673 if ((Atom
) (event
->xclient
.data
.l
[0]) == wm_delete_window
)
684 printf( "destroy from %s\n", win
->GetName().c_str() );
689 printf( "create from %s\n", win
->GetName().c_str() );
694 printf( "map request from %s\n", win
->GetName().c_str() );
699 printf( "resize request from %s\n", win
->GetName().c_str() );
701 Display
*disp
= (Display
*) wxGetDisplay();
706 while( XCheckTypedWindowEvent (disp
, actualWindow
, ResizeRequest
, &report
));
708 wxSize sz
= win
->GetSize();
709 wxSizeEvent
sizeEvent(sz
, win
->GetId());
710 sizeEvent
.SetEventObject(win
);
712 return win
->GetEventHandler()->ProcessEvent( sizeEvent
);
717 case GR_EVENT_TYPE_CLOSE_REQ
:
734 if (!win
->IsEnabled())
737 // Here we check if the top level window is
738 // disabled, which is one aspect of modality.
740 while (tlw
&& !tlw
->IsTopLevel())
741 tlw
= tlw
->GetParent();
742 if (tlw
&& !tlw
->IsEnabled())
745 if (event
->type
== ButtonPress
)
747 if ((win
!= wxWindow::FindFocus()) && win
->AcceptsFocus())
749 // This might actually be done in wxWindow::SetFocus()
750 // and not here. TODO.
751 g_prevFocus
= wxWindow::FindFocus();
754 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win
->GetName().c_str(), win
->GetClassInfo()->GetClassName() );
756 // Record the fact that this window is
757 // getting the focus, because we'll need to
758 // check if its parent is getting a bogus
759 // focus and duly ignore it.
760 // TODO: may need to have this code in SetFocus, too.
761 extern wxWindow
* g_GettingFocus
;
762 g_GettingFocus
= win
;
768 if (event
->type
== LeaveNotify
|| event
->type
== EnterNotify
)
770 // Throw out NotifyGrab and NotifyUngrab
771 if (event
->xcrossing
.mode
!= NotifyNormal
)
775 wxMouseEvent wxevent
;
776 wxTranslateMouseEvent(wxevent
, win
, window
, event
);
777 return win
->GetEventHandler()->ProcessEvent( wxevent
);
782 if ((event
->xfocus
.detail
!= NotifyPointer
) &&
783 (event
->xfocus
.mode
== NotifyNormal
))
786 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win
->GetName().c_str(), win
->GetClassInfo()->GetClassName() );
788 extern wxWindow
* g_GettingFocus
;
789 if (g_GettingFocus
&& g_GettingFocus
->GetParent() == win
)
791 // Ignore this, this can be a spurious FocusIn
792 // caused by a child having its focus set.
793 g_GettingFocus
= NULL
;
794 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win
->GetName().c_str(), win
->GetClassInfo()->GetClassName() );
799 wxFocusEvent
focusEvent(wxEVT_SET_FOCUS
, win
->GetId());
800 focusEvent
.SetEventObject(win
);
801 focusEvent
.SetWindow( g_prevFocus
);
804 return win
->GetEventHandler()->ProcessEvent(focusEvent
);
813 if ((event
->xfocus
.detail
!= NotifyPointer
) &&
814 (event
->xfocus
.mode
== NotifyNormal
))
817 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win
->GetName().c_str(), win
->GetClassInfo()->GetClassName() );
819 wxFocusEvent
focusEvent(wxEVT_KILL_FOCUS
, win
->GetId());
820 focusEvent
.SetEventObject(win
);
821 focusEvent
.SetWindow( g_nextFocus
);
823 return win
->GetEventHandler()->ProcessEvent(focusEvent
);
831 //wxString eventName = wxGetXEventName(XEvent& event);
832 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
841 // Returns TRUE if more time is needed.
842 // Note that this duplicates wxEventLoopImpl::SendIdleEvent
843 // but ProcessIdle may be needed by apps, so is kept.
844 bool wxApp::ProcessIdle()
847 event
.SetEventObject(this);
850 return event
.MoreRequested();
853 void wxApp::ExitMainLoop()
859 // Is a message/event pending?
860 bool wxApp::Pending()
862 return wxEventLoop::GetActive()->Pending();
865 // Dispatch a message.
866 void wxApp::Dispatch()
868 wxEventLoop::GetActive()->Dispatch();
871 // This should be redefined in a derived class for
872 // handling property change events for XAtom IPC.
873 bool wxApp::HandlePropertyChange(WXEvent
*event
)
875 // by default do nothing special
876 // TODO: what to do for X11
877 // XtDispatchEvent((XEvent*) event);
881 void wxApp::OnIdle(wxIdleEvent
& event
)
883 static bool s_inOnIdle
= FALSE
;
885 // Avoid recursion (via ProcessEvent default case)
891 // Resend in the main thread events which have been prepared in other
893 ProcessPendingEvents();
895 // 'Garbage' collection of windows deleted with Close()
896 DeletePendingObjects();
898 // Send OnIdle events to all windows
899 bool needMore
= SendIdleEvents();
902 event
.RequestMore(TRUE
);
909 // **** please implement me! ****
910 // Wake up the idle handler processor, even if it is in another thread...
914 // Send idle event to all top-level windows
915 bool wxApp::SendIdleEvents()
917 bool needMore
= FALSE
;
919 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
922 wxWindow
* win
= node
->GetData();
923 if (SendIdleEvents(win
))
925 node
= node
->GetNext();
931 // Send idle event to window and all subwindows
932 bool wxApp::SendIdleEvents(wxWindow
* win
)
934 bool needMore
= FALSE
;
937 event
.SetEventObject(win
);
939 win
->GetEventHandler()->ProcessEvent(event
);
941 if (event
.MoreRequested())
944 wxNode
* node
= win
->GetChildren().First();
947 wxWindow
* win
= (wxWindow
*) node
->Data();
948 if (SendIdleEvents(win
))
954 win
->OnInternalIdle();
959 void wxApp::DeletePendingObjects()
961 wxNode
*node
= wxPendingDelete
.First();
964 wxObject
*obj
= (wxObject
*)node
->Data();
968 if (wxPendingDelete
.Member(obj
))
971 // Deleting one object may have deleted other pending
972 // objects, so start from beginning of list again.
973 node
= wxPendingDelete
.First();
977 static void wxCalcPrecAndShift( unsigned long mask
, int *shift
, int *prec
)
982 while (!(mask
& 0x1))
995 // Create display, and other initialization
996 bool wxApp::OnInitGui()
998 // Eventually this line will be removed, but for
999 // now we don't want to try popping up a dialog
1000 // for error messages.
1001 delete wxLog::SetActiveTarget(new wxLogStderr
);
1003 if (!wxAppBase::OnInitGui())
1006 GetMainColormap( wxApp::GetDisplay() );
1008 m_maxRequestSize
= XMaxRequestSize( (Display
*) wxApp::GetDisplay() );
1011 // Get info about the current visual. It is enough
1012 // to do this once here unless we support different
1013 // visuals, displays and screens. Given that wxX11
1014 // mostly for embedded things, that is no real
1016 Display
*xdisplay
= (Display
*) wxApp::GetDisplay();
1017 int xscreen
= DefaultScreen(xdisplay
);
1018 Visual
* xvisual
= DefaultVisual(xdisplay
,xscreen
);
1019 int xdepth
= DefaultDepth(xdisplay
, xscreen
);
1021 XVisualInfo vinfo_template
;
1022 vinfo_template
.visual
= xvisual
;
1023 vinfo_template
.visualid
= XVisualIDFromVisual( xvisual
);
1024 vinfo_template
.depth
= xdepth
;
1027 XVisualInfo
*vi
= XGetVisualInfo( xdisplay
, VisualIDMask
|VisualDepthMask
, &vinfo_template
, &nitem
);
1028 wxASSERT_MSG( vi
, wxT("No visual info") );
1030 m_visualType
= vi
->visual
->c_class
;
1031 m_visualScreen
= vi
->screen
;
1033 m_visualRedMask
= vi
->red_mask
;
1034 m_visualGreenMask
= vi
->green_mask
;
1035 m_visualBlueMask
= vi
->blue_mask
;
1037 if (m_visualType
!= GrayScale
&& m_visualType
!= PseudoColor
)
1039 wxCalcPrecAndShift( m_visualRedMask
, &m_visualRedShift
, &m_visualRedPrec
);
1040 wxCalcPrecAndShift( m_visualGreenMask
, &m_visualGreenShift
, &m_visualGreenPrec
);
1041 wxCalcPrecAndShift( m_visualBlueMask
, &m_visualBlueShift
, &m_visualBluePrec
);
1044 m_visualDepth
= xdepth
;
1046 xdepth
= m_visualRedPrec
+ m_visualGreenPrec
+ m_visualBluePrec
;
1048 m_visualColormapSize
= vi
->colormap_size
;
1052 if (m_visualDepth
> 8)
1055 m_visualColormap
= new XColor
[m_visualColormapSize
];
1056 XColor
* colors
= (XColor
*) m_visualColormap
;
1058 for (int i
= 0; i
< m_visualColormapSize
; i
++)
1059 colors
[i
].pixel
= i
;
1061 XQueryColors( xdisplay
, DefaultColormap(xdisplay
,xscreen
), colors
, m_visualColormapSize
);
1063 m_colorCube
= (unsigned char*)malloc(32 * 32 * 32);
1065 for (int r
= 0; r
< 32; r
++)
1067 for (int g
= 0; g
< 32; g
++)
1069 for (int b
= 0; b
< 32; b
++)
1071 int rr
= (r
<< 3) | (r
>> 2);
1072 int gg
= (g
<< 3) | (g
>> 2);
1073 int bb
= (b
<< 3) | (b
>> 2);
1079 int max
= 3 * 65536;
1081 for (int i
= 0; i
< m_visualColormapSize
; i
++)
1083 int rdiff
= ((rr
<< 8) - colors
[i
].red
);
1084 int gdiff
= ((gg
<< 8) - colors
[i
].green
);
1085 int bdiff
= ((bb
<< 8) - colors
[i
].blue
);
1086 int sum
= ABS (rdiff
) + ABS (gdiff
) + ABS (bdiff
);
1089 index
= i
; max
= sum
;
1095 // assume 8-bit true or static colors. this really exists
1096 index
= (r
>> (5 - m_visualRedPrec
)) << m_visualRedShift
;
1097 index
|= (g
>> (5 - m_visualGreenPrec
)) << m_visualGreenShift
;
1098 index
|= (b
>> (5 - m_visualBluePrec
)) << m_visualBlueShift
;
1100 m_colorCube
[ (r
*1024) + (g
*32) + b
] = index
;
1111 #include <pango/pango.h>
1112 #include <pango/pangox.h>
1113 #include <pango/pangoxft.h>
1115 PangoContext
* wxApp::GetPangoContext()
1117 static PangoContext
*ret
= NULL
;
1121 Display
*xdisplay
= (Display
*) wxApp::GetDisplay();
1124 int xscreen
= DefaultScreen(xdisplay
);
1125 static int use_xft
= -1;
1128 wxString val
= wxGetenv( L
"GDK_USE_XFT" );
1129 use_xft
= (val
== L
"1");
1133 ret
= pango_xft_get_context( xdisplay
, xscreen
);
1136 ret
= pango_x_get_context( xdisplay
);
1138 if (!PANGO_IS_CONTEXT(ret
))
1139 wxLogError( wxT("No pango context.") );
1145 WXColormap
wxApp::GetMainColormap(WXDisplay
* display
)
1147 if (!display
) /* Must be called first with non-NULL display */
1148 return m_mainColormap
;
1150 int defaultScreen
= DefaultScreen((Display
*) display
);
1151 Screen
* screen
= XScreenOfDisplay((Display
*) display
, defaultScreen
);
1153 Colormap c
= DefaultColormapOfScreen(screen
);
1155 if (!m_mainColormap
)
1156 m_mainColormap
= (WXColormap
) c
;
1158 return (WXColormap
) c
;
1161 Window
wxGetWindowParent(Window window
)
1163 wxASSERT_MSG( window
, "invalid window" );
1167 Window parent
, root
= 0;
1171 unsigned int noChildren
= 0;
1173 Window
* children
= NULL
;
1175 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
1180 XQueryTree((Display
*) wxGetDisplay(), window
, & root
, & parent
,
1181 & children
, & noChildren
);
1194 retValue
= wxTheApp
->OnExit();
1198 * Exit in some platform-specific way. Not recommended that the app calls this:
1199 * only for emergencies.
1204 // Yield to other processes
1206 bool wxApp::Yield(bool onlyIfNeeded
)
1208 // Sometimes only 2 yields seem
1209 // to do the trick, e.g. in the
1212 for (i
= 0; i
< 2; i
++)
1214 bool s_inYield
= FALSE
;
1218 if ( !onlyIfNeeded
)
1220 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1228 // Make sure we have an event loop object,
1229 // or Pending/Dispatch will fail
1230 wxEventLoop
* eventLoop
= wxEventLoop::GetActive();
1231 wxEventLoop
* newEventLoop
= NULL
;
1234 newEventLoop
= new wxEventLoop
;
1235 wxEventLoop::SetActive(newEventLoop
);
1238 // Call dispatch at least once so that sockets
1240 wxTheApp
->Dispatch();
1242 while (wxTheApp
&& wxTheApp
->Pending())
1243 wxTheApp
->Dispatch();
1246 wxTimer::NotifyTimers();
1252 wxEventLoop::SetActive(NULL
);
1253 delete newEventLoop
;
1264 void wxApp::OnAssert(const wxChar
*file
, int line
, const wxChar
* cond
, const wxChar
*msg
)
1266 // While the GUI isn't working that well, just print out the
1269 wxAppBase::OnAssert(file
, line
, cond
, msg
);
1272 msg2
.Printf("At file %s:%d: %s", file
, line
, msg
);
1277 #endif // __WXDEBUG__