#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
#include <string.h>
+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();
}
#endif // __WXDEBUG__
-long wxApp::sm_lastMessageTime = 0;
-
bool wxApp::Initialize()
{
wxClassInfo::InitializeClasses();
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();
void wxApp::CleanUp()
{
- delete wxWidgetHashTable;
- wxWidgetHashTable = NULL;
-
wxModule::CleanUpModules();
-#if wxUSE_WX_RESOURCES
- wxCleanUpResourceSystem();
-#endif
-
wxDeleteStockObjects() ;
// Destroy all GDI lists, etc.
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
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'
#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)
{
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();
wxTheApp->DeletePendingObjects();
- wxTheApp->OnExit();
+ retValue = wxTheApp->OnExit();
- wxApp::CleanUp();
+ wxEntryCleanup();
return retValue;
-};
+}
// Static member initialization
wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
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()
void wxApp::ExitMainLoop()
{
- m_eventLoop->Exit();
+ if( m_eventLoop->IsRunning() )
+ m_eventLoop->Exit();
}
// Is a message/event pending?
wxIdleEvent event;
event.SetEventObject(win);
- win->ProcessEvent(event);
+ win->GetEventHandler()->ProcessEvent(event);
if (event.MoreRequested())
needMore = TRUE;
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";
XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
GetMainColormap(dpy);
- m_maxRequestSize = XMaxRequestSize((Display*) dpy);
wxAddIdleCallback();
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 );
+ 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;
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);