X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c9955d147ed92cdd79d795ed94d6e03fca06a52..550e6c014ca85140969ab48c22c684755b4e9dce:/src/motif/app.cpp diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 096845166f..6dffbd1e12 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -18,25 +18,15 @@ #define XtDisplay XTDISPLAY #endif -#include "wx/frame.h" #include "wx/app.h" #include "wx/utils.h" -#include "wx/gdicmn.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/cursor.h" -#include "wx/icon.h" -#include "wx/palette.h" -#include "wx/dc.h" -#include "wx/dialog.h" -#include "wx/msgdlg.h" -#include "wx/log.h" #include "wx/module.h" #include "wx/memory.h" #include "wx/log.h" #include "wx/intl.h" #include "wx/evtloop.h" #include "wx/hash.h" +#include "wx/hashmap.h" #if wxUSE_THREADS #include "wx/thread.h" @@ -58,6 +48,21 @@ #include +struct wxPerDisplayData +{ + wxPerDisplayData() + { m_visualInfo = NULL; m_topLevelWidget = NULL; } + + wxXVisualInfo* m_visualInfo; + Widget m_topLevelWidget; +}; + +WX_DECLARE_VOIDPTR_HASH_MAP( wxPerDisplayData, wxPerDisplayDataMap ); + +static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData, + XtPointer ptr); +static WXWidget wxCreateTopLevelWidget( WXDisplay* display ); + extern wxList wxPendingDelete; extern bool wxAddIdleCallback(); @@ -83,8 +88,6 @@ END_EVENT_TABLE() } #endif // __WXDEBUG__ -long wxApp::sm_lastMessageTime = 0; - bool wxApp::Initialize() { wxClassInfo::InitializeClasses(); @@ -101,17 +104,6 @@ bool wxApp::Initialize() wxInitializeStockLists(); wxInitializeStockObjects(); - // For PostScript printing -#if wxUSE_POSTSCRIPT - /* Done using wxModule now - wxInitializePrintSetupData(); - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - */ -#endif - - wxBitmap::InitStandardHandlers(); - wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); wxModule::RegisterModules(); @@ -122,9 +114,6 @@ bool wxApp::Initialize() void wxApp::CleanUp() { - delete wxWidgetHashTable; - wxWidgetHashTable = NULL; - wxModule::CleanUpModules(); wxDeleteStockObjects() ; @@ -136,26 +125,21 @@ void wxApp::CleanUp() delete wxTheColourDatabase; wxTheColourDatabase = NULL; -#if wxUSE_POSTSCRIPT - /* Done using wxModule now - wxInitializePrintSetupData(FALSE); - delete wxThePrintPaperDatabase; - wxThePrintPaperDatabase = NULL; - */ -#endif - - wxBitmap::CleanUpHandlers(); - wxClassInfo::CleanUpClasses(); delete wxTheApp; wxTheApp = NULL; + delete wxWidgetHashTable; + wxWidgetHashTable = NULL; + // GL: I'm annoyed ... I don't know where to put this and I don't want to // create a module for that as it's part of the core. #if wxUSE_THREADS delete wxPendingEvents; + wxPendingEvents = NULL; delete wxPendingEventsLocker; + wxPendingEventsLocker = NULL; #endif #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT @@ -177,7 +161,11 @@ void wxApp::CleanUp() delete wxLog::SetActiveTarget(NULL); } -int wxEntry( int argc, char *argv[] ) +// ============================================================================ +// wxEntry* +// ============================================================================ + +int wxEntryStart( int argc, char* argv[] ) { #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT // This seems to be necessary since there are 'rogue' @@ -190,7 +178,41 @@ int wxEntry( int argc, char *argv[] ) #endif if (!wxApp::Initialize()) - return FALSE; + return -1; + + return 0; +} + +int wxEntryInitGui() +{ + int retValue = 0; + + // GUI-specific initialization, such as creating an app context. + if (!wxTheApp->OnInitGui()) + retValue = -1; + + return retValue; +} + +void wxEntryCleanup() +{ + // So dialog boxes aren't used for further messages + delete wxLog::SetActiveTarget(new wxLogStderr); + + // flush the logged messages if any + wxLog *pLog = wxLog::GetActiveTarget(); + if ( pLog != NULL && pLog->HasPendingMessages() ) + pLog->Flush(); + + wxApp::CleanUp(); +} + +int wxEntry( int argc, char *argv[] ) +{ + int retValue = 0; + + retValue = wxEntryStart( argc, argv ); + if (retValue) return retValue; if (!wxTheApp) { @@ -216,25 +238,18 @@ int wxEntry( int argc, char *argv[] ) wxTheApp->argv = argv; // GUI-specific initialization, such as creating an app context. - wxTheApp->OnInitGui(); + retValue = wxEntryInitGui(); + if (retValue) return retValue; // Here frames insert themselves automatically into wxTopLevelWindows by // getting created in OnInit(). - int retValue = 0; if (wxTheApp->OnInit()) { - if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun(); + if (wxTheApp->Initialized()) + wxTheApp->OnRun(); } - // flush the logged messages if any - wxLog *pLog = wxLog::GetActiveTarget(); - if ( pLog != NULL && pLog->HasPendingMessages() ) - pLog->Flush(); - - delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used - // for further messages - if (wxTheApp->GetTopWindow()) { delete wxTheApp->GetTopWindow(); @@ -243,12 +258,12 @@ int wxEntry( int argc, char *argv[] ) wxTheApp->DeletePendingObjects(); - wxTheApp->OnExit(); + retValue = wxTheApp->OnExit(); - wxApp::CleanUp(); + wxEntryCleanup(); return retValue; -}; +} // Static member initialization wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; @@ -261,14 +276,25 @@ wxApp::wxApp() m_eventLoop = new wxEventLoop; m_mainColormap = (WXColormap) NULL; m_appContext = (WXAppContext) NULL; - m_topLevelWidget = (WXWidget) NULL; - m_maxRequestSize = 0; m_initialDisplay = (WXDisplay*) 0; + m_perDisplayData = new wxPerDisplayDataMap; } wxApp::~wxApp() { delete m_eventLoop; + + for( wxPerDisplayDataMap::iterator it = m_perDisplayData->begin(), + end = m_perDisplayData->end(); + it != end; ++it ) + { + delete it->second.m_visualInfo; + XtDestroyWidget( it->second.m_topLevelWidget ); + } + + delete m_perDisplayData; + + wxTheApp = NULL; } bool wxApp::Initialized() @@ -308,7 +334,8 @@ bool wxApp::ProcessIdle() void wxApp::ExitMainLoop() { - m_eventLoop->Exit(); + if( m_eventLoop->IsRunning() ) + m_eventLoop->Exit(); } // Is a message/event pending? @@ -401,7 +428,7 @@ bool wxApp::SendIdleEvents(wxWindow* win) wxIdleEvent event; event.SetEventObject(win); - win->ProcessEvent(event); + win->GetEventHandler()->ProcessEvent(event); if (event.MoreRequested()) needMore = TRUE; @@ -478,12 +505,6 @@ bool wxApp::OnInitGui() gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); #endif // __WXDEBUG__ - wxTheApp->m_topLevelWidget = - (WXWidget) XtAppCreateShell((String)NULL, - wxTheApp->GetClassName().c_str(), - applicationShellWidgetClass,dpy, - NULL,0) ; - // Add general resize proc XtActionsRec rec; rec.string = "resize"; @@ -491,7 +512,6 @@ bool wxApp::OnInitGui() XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1); GetMainColormap(dpy); - m_maxRequestSize = XMaxRequestSize((Display*) dpy); wxAddIdleCallback(); @@ -514,6 +534,65 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display) return (WXColormap) c; } +wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display ) +{ + wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display ); + + if( it != m_perDisplayData->end() && it->second.m_visualInfo ) + return it->second.m_visualInfo; + + wxXVisualInfo* vi = new wxXVisualInfo; + wxFillXVisualInfo( vi, (Display*)display ); + + (*m_perDisplayData)[display].m_visualInfo = vi; + + return vi; +} + +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 ); + XtSetMappedWhenManaged( tlw, False ); + XtRealizeWidget( tlw ); + + 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; +} + void wxExit() { int retValue = 0; @@ -522,7 +601,8 @@ void wxExit() wxApp::CleanUp(); /* - * Exit in some platform-specific way. Not recommended that the app calls this: + * Exit in some platform-specific way. + * Not recommended that the app calls this: * only for emergencies. */ exit(retValue);