X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c9955d147ed92cdd79d795ed94d6e03fca06a52..55826fcf4fd863d48ac28789d99bbb5c8a8d4c7e:/src/motif/app.cpp diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 096845166f..0185173142 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,11 +48,24 @@ #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(); -wxApp *wxTheApp = NULL; - wxHashTable *wxWidgetHashTable = NULL; IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) @@ -83,41 +86,14 @@ END_EVENT_TABLE() } #endif // __WXDEBUG__ -long wxApp::sm_lastMessageTime = 0; - -bool wxApp::Initialize() +bool wxApp::Initialize(int& argc, wxChar **argv) { - wxClassInfo::InitializeClasses(); - - // 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 - wxPendingEventsLocker = new wxCriticalSection(); -#endif - - wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); - wxTheColourDatabase->Initialize(); - - wxInitializeStockLists(); - wxInitializeStockObjects(); - - // For PostScript printing -#if wxUSE_POSTSCRIPT - /* Done using wxModule now - wxInitializePrintSetupData(); - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - */ -#endif - - wxBitmap::InitStandardHandlers(); + if ( !wxAppBase::Initialize(argc, argv) ) + return false; wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); - wxModule::RegisterModules(); - if (!wxModule::InitializeModules()) return FALSE; - - return TRUE; + return true; } void wxApp::CleanUp() @@ -125,133 +101,19 @@ void wxApp::CleanUp() delete wxWidgetHashTable; wxWidgetHashTable = NULL; - wxModule::CleanUpModules(); - - wxDeleteStockObjects() ; - - // Destroy all GDI lists, etc. - - wxDeleteStockLists(); - - 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; - - // 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; - delete wxPendingEventsLocker; -#endif - -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // At this point we want to check if there are any memory - // blocks that aren't part of the wxDebugContext itself, - // as a special case. Then when dumping we need to ignore - // wxDebugContext, too. - if (wxDebugContext::CountObjectsLeft(TRUE) > 0) - { - wxLogDebug("There were memory leaks.\n"); - wxDebugContext::Dump(); - wxDebugContext::PrintStatistics(); - } -#endif - - // do it as the very last thing because everything else can log messages - wxLog::DontCreateOnDemand(); - // do it as the very last thing because everything else can log messages - delete wxLog::SetActiveTarget(NULL); + wxAppBase::CleanUp(); } -int wxEntry( int argc, char *argv[] ) +void wxApp::Exit() { -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // This seems to be necessary since there are 'rogue' - // objects present at this point (perhaps global objects?) - // Setting a checkpoint will ignore them as far as the - // memory checking facility is concerned. - // Of course you may argue that memory allocated in globals should be - // checked, but this is a reasonable compromise. - wxDebugContext::SetCheckpoint(); -#endif - - if (!wxApp::Initialize()) - return FALSE; - - if (!wxTheApp) - { - if (!wxApp::GetInitializerFunction()) - { - printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" ); - return 0; - }; - - wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) (); - }; - - if (!wxTheApp) - { - printf( "wxWindows error: wxTheApp == NULL\n" ); - return 0; - }; - - wxTheApp->SetClassName(wxFileNameFromPath(argv[0])); - wxTheApp->SetAppName(wxFileNameFromPath(argv[0])); - - wxTheApp->argc = argc; - wxTheApp->argv = argv; - - // GUI-specific initialization, such as creating an app context. - wxTheApp->OnInitGui(); - - // Here frames insert themselves automatically into wxTopLevelWindows by - // getting created in OnInit(). - - int retValue = 0; - if (wxTheApp->OnInit()) - { - if (wxTheApp->Initialized()) retValue = 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(); - wxTheApp->SetTopWindow(NULL); - } - - wxTheApp->DeletePendingObjects(); - - wxTheApp->OnExit(); - wxApp::CleanUp(); - return retValue; -}; + wxAppConsole::Exit(); +} -// Static member initialization -wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; +// ============================================================================ +// wxApp +// ============================================================================ wxApp::wxApp() { @@ -261,14 +123,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 +181,8 @@ bool wxApp::ProcessIdle() void wxApp::ExitMainLoop() { - m_eventLoop->Exit(); + if( m_eventLoop->IsRunning() ) + m_eventLoop->Exit(); } // Is a message/event pending? @@ -401,7 +275,7 @@ bool wxApp::SendIdleEvents(wxWindow* win) wxIdleEvent event; event.SetEventObject(win); - win->ProcessEvent(event); + win->GetEventHandler()->ProcessEvent(event); if (event.MoreRequested()) needMore = TRUE; @@ -418,24 +292,6 @@ bool wxApp::SendIdleEvents(wxWindow* win) return needMore ; } -void wxApp::DeletePendingObjects() -{ - wxList::Node *node = wxPendingDelete.GetFirst(); - while (node) - { - wxObject *obj = node->GetData(); - - delete obj; - - if (wxPendingDelete.Member(obj)) - delete node; - - // Deleting one object may have deleted other pending - // objects, so start from beginning of list again. - node = wxPendingDelete.GetFirst(); - } -} - static char *fallbackResources[] = { "*menuBar.marginHeight: 0", "*menuBar.shadowThickness: 1", @@ -478,12 +334,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 +341,6 @@ bool wxApp::OnInitGui() XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1); GetMainColormap(dpy); - m_maxRequestSize = XMaxRequestSize((Display*) dpy); wxAddIdleCallback(); @@ -514,18 +363,63 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display) return (WXColormap) c; } -void wxExit() +wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display ) { - int retValue = 0; - if (wxTheApp) - retValue = wxTheApp->OnExit(); + wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display ); - wxApp::CleanUp(); - /* - * Exit in some platform-specific way. Not recommended that the app calls this: - * only for emergencies. - */ - exit(retValue); + 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; } // Yield to other processes