]> git.saurik.com Git - wxWidgets.git/blobdiff - src/qt/app.cpp
bitmap and image updates
[wxWidgets.git] / src / qt / app.cpp
index 882f4b2b6a917b9ae3cae6a353a2c6cce2c04d5c..f34b677837489612aca29a637b30f66baadfbde2 100644 (file)
@@ -1,10 +1,11 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        app.cpp
-// Purpose:
-// Author:      Robert Roebling
-// Created:     01/02/97
-// Id:
-// Copyright:   (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Purpose:     wxApp
+// Author:      AUTHOR
+// Modified by:
+// Created:     ??/??/98
+// RCS-ID:      $Id$
+// Copyright:   (c) AUTHOR
 // Licence:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #pragma implementation "app.h"
 #endif
 
+#include "wx/frame.h"
 #include "wx/app.h"
-#include "wx/gdicmn.h"
 #include "wx/utils.h"
-#include "wx/postscrp.h"
-#include "wx/intl.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/memory.h"
-
-#include "unistd.h"
+#include "wx/module.h"
 
-//-----------------------------------------------------------------------------
-// global data
-//-----------------------------------------------------------------------------
+#if wxUSE_WX_RESOURCES
+#include "wx/resource.h"
+#endif
 
-wxApp *wxTheApp = NULL;
-wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
+#include <string.h>
 
+#if defined(__WIN95__) && !defined(__GNUWIN32__)
+extern char *wxBuffer;
 extern wxList wxPendingDelete;
 
-//-----------------------------------------------------------------------------
-// local functions
-//-----------------------------------------------------------------------------
-
-extern void wxFlushResources(void);
-
-//-----------------------------------------------------------------------------
-// global functions
-//-----------------------------------------------------------------------------
-
-void wxExit(void)
-{
-};
-
-bool wxYield(void)
-{
-  return TRUE;
-};
-
-//-----------------------------------------------------------------------------
-// wxApp
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
+wxApp *wxTheApp = NULL;
 
+#if !USE_SHARED_LIBRARY
+IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
     EVT_IDLE(wxApp::OnIdle)
 END_EVENT_TABLE()
+#endif
 
-wxApp::wxApp()
-{
-  m_topWindow = NULL;
-  m_exitOnFrameDelete = TRUE;
-};
-
-wxApp::~wxApp(void)
-{
-};
-
-bool wxApp::OnInit(void)
-{
-  return TRUE;
-};
-
-bool wxApp::OnInitGui(void)
-{ 
-  return TRUE; 
-};
-
-int wxApp::OnRun(void) 
-{ 
-  return MainLoop(); 
-};
-
-bool wxApp::ProcessIdle(void)
-{
-  wxIdleEvent event;
-  event.SetEventObject( this );
-  ProcessEvent( event );
-  
-  return event.MoreRequested();
-};
-
-void wxApp::OnIdle( wxIdleEvent &event )
-{
-  static bool inOnIdle = FALSE;
-
-  // Avoid recursion (via ProcessEvent default case)
-  if (inOnIdle)
-    return;
-
-  inOnIdle = TRUE;
-
-  // 'Garbage' collection of windows deleted with Close().
-  DeletePendingObjects();
-
-  // flush the logged messages if any
-  wxLog *pLog = wxLog::GetActiveTarget();
-  if ( pLog != NULL && pLog->HasPendingMessages() )
-    pLog->Flush();
-
-  // Send OnIdle events to all windows
-  bool needMore = SendIdleEvents();
-
-  if (needMore)
-    event.RequestMore(TRUE);
-
-  inOnIdle = FALSE;
-};
-
-bool wxApp::SendIdleEvents(void)
-{
-    bool needMore = FALSE;
-       wxNode* node = wxTopLevelWindows.First();
-       while (node)
-       {
-               wxWindow* win = (wxWindow*) node->Data();
-               if (SendIdleEvents(win))
-            needMore = TRUE;
-
-               node = node->Next();
-       }
-    return needMore;
-};
+long wxApp::sm_lastMessageTime = 0;
 
-bool wxApp::SendIdleEvents( wxWindow* win )
+void wxApp::CommonInit()
 {
-    bool needMore = FALSE;
-
-       wxIdleEvent event;
-       event.SetEventObject(win);
-       win->ProcessEvent(event);
-
-    if (event.MoreRequested())
-        needMore = TRUE;
-
-       wxNode* node = win->GetChildren()->First();
-       while (node)
-       {
-               wxWindow* win = (wxWindow*) node->Data();
-               if (SendIdleEvents(win))
-            needMore = TRUE;
-
-               node = node->Next();
-       }
-    return needMore ;
-};
+#ifdef __WXMSW__
+  wxBuffer = new char[1500];
+#else
+  wxBuffer = new char[BUFSIZ + 512];
+#endif
 
-int wxApp::OnExit(void)
-{
-  return 0;
-};
+  wxClassInfo::InitializeClasses();
 
-int wxApp::MainLoop(void)
-{
-  return 0;
-};
+  wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
+  wxTheColourDatabase->Initialize();
+  wxInitializeStockObjects();
 
-void wxApp::ExitMainLoop(void)
-{
-};
+#if wxUSE_WX_RESOURCES
+  wxInitializeResourceSystem();
+#endif
 
-bool wxApp::Initialized(void)
-{
-  return m_initialized;
-};
+  // For PostScript printing
+#if wxUSE_POSTSCRIPT
+  wxInitializePrintSetupData();
+  wxThePrintPaperDatabase = new wxPrintPaperDatabase;
+  wxThePrintPaperDatabase->CreateDatabase();
+#endif
 
-bool wxApp::Pending(void) 
-{
-  return FALSE;
-};
+  wxBitmap::InitStandardHandlers();
 
-void wxApp::Dispatch(void) 
-{
-};
+  wxModule::RegisterModules();
+  wxASSERT( wxModule::InitializeModules() == TRUE );
+}
 
-void wxApp::DeletePendingObjects(void)
+void wxApp::CommonCleanUp()
 {
-  wxNode *node = wxPendingDelete.First();
-  while (node)
-  {
-    wxObject *obj = (wxObject *)node->Data();
-    
-    delete obj;
+  wxModule::CleanUpModules();
 
-    if (wxPendingDelete.Member(obj))
-      delete node;
+#if wxUSE_WX_RESOURCES
+  wxCleanUpResourceSystem();
+#endif
 
-    node = wxPendingDelete.First();
-  };
-};
+  wxDeleteStockObjects() ;
 
-wxWindow *wxApp::GetTopWindow(void)
-{
-  if (m_topWindow) return m_topWindow;
-  wxNode *node = wxTopLevelWindows.First();
-  if (!node) return NULL;
-  return (wxWindow*)node->Data();
-};
+  // Destroy all GDI lists, etc.
+  delete wxTheBrushList;
+  wxTheBrushList = NULL;
 
-void wxApp::SetTopWindow( wxWindow *win )
-{
-  m_topWindow = win;
-};
+  delete wxThePenList;
+  wxThePenList = NULL;
 
-void wxApp::CommonInit(void)
-{
+  delete wxTheFontList;
+  wxTheFontList = NULL;
 
-/*
-#if USE_RESOURCES
-  (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
-#endif
-*/
+  delete wxTheBitmapList;
+  wxTheBitmapList = NULL;
 
-  wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
-  wxTheColourDatabase->Initialize();
-  wxInitializeStockObjects();
+  delete wxTheColourDatabase;
+  wxTheColourDatabase = NULL;
 
-  // For PostScript printing
-#if USE_POSTSCRIPT
-  wxInitializePrintSetupData();
-  wxThePrintPaperDatabase = new wxPrintPaperDatabase;
-  wxThePrintPaperDatabase->CreateDatabase();
+#if wxUSE_POSTSCRIPT
+  wxInitializePrintSetupData(FALSE);
+  delete wxThePrintPaperDatabase;
+  wxThePrintPaperDatabase = NULL;
 #endif
 
+  wxBitmap::CleanUpHandlers();
 
-/*
-  wxBitmap::InitStandardHandlers();
-
-  g_globalCursor = new wxCursor;
-*/
+  delete[] wxBuffer;
+  wxBuffer = NULL;
 
-  wxInitializeStockObjects();
-};
-
-void wxApp::CommonCleanUp(void)
-{
-  wxDeleteStockObjects();
-  
-  wxFlushResources();
-};
-    
-wxLog *wxApp::CreateLogTarget()
-{
-  return new wxLogGui;
+  // do it as the very last thing because everything else can log messages
+  delete wxLog::SetActiveTarget(NULL);
 }
 
-//-----------------------------------------------------------------------------
-// wxEntry
-//-----------------------------------------------------------------------------
-
 int wxEntry( int argc, char *argv[] )
 {
-  wxBuffer = new char[BUFSIZ + 512];
-
   wxClassInfo::InitializeClasses();
   
-#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
+#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
 
 #if !defined(_WINDLL)
   streambuf* sBuf = new wxDebugStreamBuf;
@@ -288,13 +145,7 @@ int wxEntry( int argc, char *argv[] )
       return 0;
     };
     
-    wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
-    
-    wxObject *test_app = app_ini();
-    
-    wxTheApp = (wxApp*) test_app;
-    
-//    wxTheApp = (wxApp*)( app_ini() );
+       wxTheApp = (* wxApp::GetInitializerFunction()) ();
   };
   
   if (!wxTheApp) 
@@ -303,15 +154,14 @@ int wxEntry( int argc, char *argv[] )
     return 0;
   };
 
-//  printf( "Programmstart.\n" );
-  
   wxTheApp->argc = argc;
   wxTheApp->argv = argv;
 
-// Your init here  !!!!
-    
+  // TODO: your platform-specific initialization.
+
   wxApp::CommonInit();
 
+  // GUI-specific initialization, such as creating an app context.
   wxTheApp->OnInitGui();
 
   // Here frames insert themselves automatically
@@ -332,7 +182,7 @@ int wxEntry( int argc, char *argv[] )
   
   wxApp::CommonCleanUp();
   
-#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
+#if (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
@@ -349,18 +199,197 @@ int wxEntry( int argc, char *argv[] )
   return retValue;
 };
 
-//-----------------------------------------------------------------------------
-// main()
-//-----------------------------------------------------------------------------
+// Static member initialization
+wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
 
-#if defined(AIX) || defined(AIX4) || defined(____HPUX__)
+wxApp::wxApp()
+{
+  m_topWindow = NULL;
+  wxTheApp = this;
+  m_className = "";
+  m_wantDebugOutput = TRUE ;
+  m_appName = "";
+  argc = 0;
+  argv = NULL;
+#ifdef __WXMSW__
+  m_printMode = wxPRINT_WINDOWS;
+#else
+  m_printMode = wxPRINT_POSTSCRIPT;
+#endif
+  m_exitOnFrameDelete = TRUE;
+  m_auto3D = TRUE;
+}
 
- // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
+bool wxApp::Initialized()
+{
+  if (GetTopWindow())
+    return TRUE;
+  else
+    return FALSE;
+}
 
-#else
+int wxApp::MainLoop()
+{
+  m_keepGoing = TRUE;
 
-  int main(int argc, char *argv[]) { return wxEntry(argc, argv); }
+/* TODO: implement your main loop here, calling ProcessIdle in idle time.
+  while (m_keepGoing)
+  {
+    while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
+           ProcessIdle()) {}
+    if (!DoMessage())
+      m_keepGoing = FALSE;
+  }
+*/
 
-#endif
+  return 0;
+}
+
+// Returns TRUE if more time is needed.
+bool wxApp::ProcessIdle()
+{
+    wxIdleEvent event;
+    event.SetEventObject(this);
+    ProcessEvent(event);
+
+    return event.MoreRequested();
+}
+
+void wxApp::ExitMainLoop()
+{
+  m_keepGoing = FALSE;
+}
+
+// Is a message/event pending?
+bool wxApp::Pending()
+{
+/* TODO.
+ */
+  return FALSE;
+}
+
+// Dispatch a message.
+void wxApp::Dispatch()
+{
+/* TODO.
+ */
+}
+
+void wxApp::OnIdle(wxIdleEvent& event)
+{
+  static bool inOnIdle = FALSE;
+
+  // Avoid recursion (via ProcessEvent default case)
+  if (inOnIdle)
+    return;
+
+  inOnIdle = TRUE;
+
+  // 'Garbage' collection of windows deleted with Close().
+  DeletePendingObjects();
+
+  // flush the logged messages if any
+  wxLog *pLog = wxLog::GetActiveTarget();
+  if ( pLog != NULL && pLog->HasPendingMessages() )
+    pLog->Flush();
+
+  // Send OnIdle events to all windows
+  bool needMore = SendIdleEvents();
+
+  if (needMore)
+    event.RequestMore(TRUE);
+
+  inOnIdle = FALSE;
+}
+
+// Send idle event to all top-level windows
+bool wxApp::SendIdleEvents()
+{
+    bool needMore = FALSE;
+       wxNode* node = wxTopLevelWindows.First();
+       while (node)
+       {
+               wxWindow* win = (wxWindow*) node->Data();
+               if (SendIdleEvents(win))
+            needMore = TRUE;
 
+               node = node->Next();
+       }
+    return needMore;
+}
+
+// Send idle event to window and all subwindows
+bool wxApp::SendIdleEvents(wxWindow* win)
+{
+    bool needMore = FALSE;
+
+       wxIdleEvent event;
+       event.SetEventObject(win);
+       win->ProcessEvent(event);
+
+    if (event.MoreRequested())
+        needMore = TRUE;
+
+       wxNode* node = win->GetChildren()->First();
+       while (node)
+       {
+               wxWindow* win = (wxWindow*) node->Data();
+               if (SendIdleEvents(win))
+            needMore = TRUE;
+
+               node = node->Next();
+       }
+    return needMore ;
+}
+
+void wxApp::DeletePendingObjects()
+{
+  wxNode *node = wxPendingDelete.First();
+  while (node)
+  {
+    wxObject *obj = (wxObject *)node->Data();
+    
+    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.First();
+  }
+}
+
+wxLog* wxApp::CreateLogTarget()
+{
+    return new wxLogGui;
+}
+
+wxWindow* wxApp::GetTopWindow() const
+{
+    if (m_topWindow)
+        return m_topWindow;
+    else if (wxTopLevelWindows.Number() > 0)
+        return (wxWindow*) wxTopLevelWindows.First()->Data();
+    else
+        return NULL;
+}
+
+void wxExit()
+{
+  wxApp::CommonCleanUp();
+/*
+ * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
+ * only for emergencies.
+ */
+}
+
+// Yield to other processes
+bool wxYield()
+{
+  /*
+   * TODO
+   */
+  return TRUE;
+}