+static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData,
+ XtPointer ptr)
+{
+ if( wxTheApp )
+ wxTheApp->SetTopLevelWidget( (WXDisplay*)XtDisplay(w),
+ (WXWidget)NULL );
+}
+
+WXWidget wxCreateTopLevelWidget( WXDisplay* display )
+{
+ Widget tlw = XtAppCreateShell( (String)NULL,
+ wxTheApp->GetClassName().c_str(),
+ applicationShellWidgetClass,
+ (Display*)display,
+ NULL, 0 );
+
+ XtAddCallback( tlw, XmNdestroyCallback,
+ (XtCallbackProc)wxTLWidgetDestroyCallback,
+ (XtPointer)NULL );
+
+ return (WXWidget)tlw;
+}
+
+WXWidget wxApp::GetTopLevelWidget()
+{
+ WXDisplay* display = wxGetDisplay();
+ wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display );
+
+ if( it != m_perDisplayData->end() && it->second.m_topLevelWidget )
+ return (WXWidget)it->second.m_topLevelWidget;
+
+ WXWidget tlw = wxCreateTopLevelWidget( display );
+ SetTopLevelWidget( display, tlw );
+
+ return tlw;
+}
+
+void wxApp::SetTopLevelWidget(WXDisplay* display, WXWidget widget)
+{
+ (*m_perDisplayData)[display].m_topLevelWidget = (Widget)widget;
+}
+