]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/app.cpp
Applied patch [ 730686 ] wxImage::Scale speed improvements
[wxWidgets.git] / src / motif / app.cpp
index 330ba91007c4832e081619f1eb5a84c50e43bd55..1dce3f1186a84fd6decda4f2e2684442f4bb6cb1 100644 (file)
 #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"
 #endif
 
-#if wxUSE_WX_RESOURCES
-    #include "wx/resource.h"
-#endif
-
 #ifdef __VMS__
 #pragma message disable nosimpint
 #endif
@@ -61,6 +48,8 @@
 
 #include <string.h>
 
+WX_DECLARE_VOIDPTR_HASH_MAP( wxXVisualInfo*, wxXVisualInfoMap );
+
 extern wxList wxPendingDelete;
 extern bool wxAddIdleCallback();
 
@@ -104,21 +93,6 @@ bool wxApp::Initialize()
     wxInitializeStockLists();
     wxInitializeStockObjects();
 
-#if wxUSE_WX_RESOURCES
-    wxInitializeResourceSystem();
-#endif
-
-    // 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();
@@ -129,15 +103,8 @@ bool wxApp::Initialize()
 
 void wxApp::CleanUp()
 {
-    delete wxWidgetHashTable;
-    wxWidgetHashTable = NULL;
-
     wxModule::CleanUpModules();
 
-#if wxUSE_WX_RESOURCES
-    wxCleanUpResourceSystem();
-#endif
-
     wxDeleteStockObjects() ;
 
     // Destroy all GDI lists, etc.
@@ -147,21 +114,14 @@ 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
@@ -188,7 +148,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'
@@ -201,7 +165,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)
     {
@@ -227,25 +225,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();
@@ -254,12 +245,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;
@@ -275,11 +266,21 @@ wxApp::wxApp()
     m_topLevelWidget = (WXWidget) NULL;
     m_maxRequestSize = 0;
     m_initialDisplay = (WXDisplay*) 0;
+    m_visualInfoMap = new wxXVisualInfoMap;
 }
 
 wxApp::~wxApp()
 {
     delete m_eventLoop;
+
+    for( wxXVisualInfoMap::iterator it  = m_visualInfoMap->begin(),
+                                    end = m_visualInfoMap->end();
+         it != end; ++it )
+    {
+        delete it->second;
+    }
+
+    delete m_visualInfoMap;
 }
 
 bool wxApp::Initialized()
@@ -319,17 +320,21 @@ bool wxApp::ProcessIdle()
 
 void wxApp::ExitMainLoop()
 {
-    m_eventLoop->Exit();
+    if( m_eventLoop->IsRunning() )
+        m_eventLoop->Exit();
 }
 
 // Is a message/event pending?
 bool wxApp::Pending()
 {
+    return m_eventLoop->Pending();
+#if 0
     XFlush(XtDisplay( (Widget) wxTheApp->GetTopLevelWidget() ));
 
     // Fix by Doug from STI, to prevent a stall if non-X event
     // is found.
     return ((XtAppPending( (XtAppContext) GetAppContext() ) & XtIMXEvent) != 0) ;
+#endif
 }
 
 // Dispatch a message.
@@ -463,7 +468,7 @@ bool wxApp::OnInitGui()
     XtAppSetFallbackResources((XtAppContext) wxTheApp->m_appContext, fallbackResources);
 
     Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL,
-        (const char*) wxTheApp->GetClassName(), NULL, 0,
+        wxTheApp->GetClassName().c_str(), NULL, 0,
 # if XtSpecificationRelease < 5
         (Cardinal*) &argc,
 # else
@@ -476,7 +481,7 @@ bool wxApp::OnInitGui()
         delete wxLog::SetActiveTarget(new wxLogStderr);
         wxString className(wxTheApp->GetClassName());
         wxLogError(_("wxWindows could not open display for '%s': exiting."),
-                   (const char*) className);
+                   className.c_str());
         exit(-1);
     }
     m_initialDisplay = (WXDisplay*) dpy;
@@ -486,9 +491,11 @@ bool wxApp::OnInitGui()
     gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);
 #endif // __WXDEBUG__
 
-    wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(),
-        applicationShellWidgetClass,dpy,
-        NULL,0) ;
+    wxTheApp->m_topLevelWidget =
+        (WXWidget) XtAppCreateShell((String)NULL,
+                                    wxTheApp->GetClassName().c_str(),
+                                    applicationShellWidgetClass,dpy,
+                                    NULL,0) ;
 
     // Add general resize proc
     XtActionsRec rec;
@@ -520,6 +527,20 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
     return (WXColormap) c;
 }
 
+wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display )
+{
+    wxXVisualInfoMap::iterator it = m_visualInfoMap->find( display );
+
+    if( it != m_visualInfoMap->end() ) return it->second;
+
+    wxXVisualInfo* vi = new wxXVisualInfo;
+    wxFillXVisualInfo( vi, (Display*)display );
+
+    (*m_visualInfoMap)[display] = vi;
+
+    return vi;
+}
+
 void wxExit()
 {
     int retValue = 0;
@@ -528,7 +549,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);