]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/app.cpp
Fixed remaining int vs. long warnings.
[wxWidgets.git] / src / os2 / app.cpp
index aa1551b0c8fb76e9dcb83407557c4a9821b3be3c..60bb29dcda24de8ae88b9f16f86688eb05e402a7 100644 (file)
@@ -62,12 +62,12 @@ extern wxChar*                      wxBuffer;
 extern wxChar*                      wxOsVersion;
 extern wxList*                      wxWinHandleList;
 extern wxList WXDLLEXPORT           wxPendingDelete;
-extern void wxSetKeyboardHook(bool doIt);
 extern wxCursor*                    g_globalCursor;
 
 HINSTANCE                           wxhInstance = 0;
 QMSG                                svCurrentMsg;
 wxApp*                              wxTheApp = NULL;
+HAB                                 vHabmain = NULL;
 
 // FIXME why not const? and not static?
 
@@ -92,7 +92,11 @@ HICON wxDEFAULT_MDIPARENTFRAME_ICON  = (HICON) NULL;
 
 HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
 
-MRESULT wxWndProc(HWND, UINT, MPARAM, MPARAM);
+MRESULT EXPENTRY wxWndProc( HWND
+                           ,ULONG
+                           ,MPARAM
+                           ,MPARAM
+                          );
 
 // ===========================================================================
 // implementation
@@ -102,7 +106,6 @@ MRESULT wxWndProc(HWND, UINT, MPARAM, MPARAM);
 // wxApp
 // ---------------------------------------------------------------------------
 
-#if !USE_SHARED_LIBRARY
     IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 
     BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
@@ -110,13 +113,22 @@ MRESULT wxWndProc(HWND, UINT, MPARAM, MPARAM);
         EVT_END_SESSION(wxApp::OnEndSession)
         EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
     END_EVENT_TABLE()
-#endif
 
 //// Initialize
 bool wxApp::Initialize(
   HAB                               vHab
 )
 {
+    //
+    // OS2 has to have an anchorblock
+    //
+    vHab = WinInitialize(0);
+
+    if (!vHab)
+        return FALSE;
+    else
+        vHabmain = vHab;
+
     // Some people may wish to use this, but
     // probably it shouldn't be here by default.
 #ifdef __WXDEBUG__
@@ -161,12 +173,12 @@ bool wxApp::Initialize(
 
     // This is to foil optimizations in Visual C++ that throw out dummy.obj.
     // PLEASE DO NOT ALTER THIS.
-#if !defined(WXMAKINGDLL)
+#if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
     extern char wxDummyChar;
     if (wxDummyChar) wxDummyChar++;
 #endif
 
-    wxSetKeyboardHook(TRUE);
+    // wxSetKeyboardHook(TRUE);
 
     wxModule::RegisterModules();
     if (!wxModule::InitializeModules())
@@ -185,100 +197,111 @@ bool wxApp::RegisterWindowClasses(
   HAB                               vHab
 )
 {
+    APIRET                          rc;
+    ERRORID                         vError = 0L;
+    wxString                        sError;
 
     if (!::WinRegisterClass( vHab
                             ,wxFrameClassName
                             ,(PFNWP)wxWndProc
-                            ,CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST | CS_CLIPCHILDREN | CS_FRAME
+                            ,CS_SIZEREDRAW | CS_SYNCPAINT
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(frame)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxFrameClassNameNoRedraw
                             ,(PFNWP)wxWndProc
-                            ,CS_HITTEST | CS_CLIPCHILDREN | CS_FRAME
+                            ,0
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(no redraw frame)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxMDIFrameClassName
                             ,(PFNWP)wxWndProc
-                            ,CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST | CS_CLIPCHILDREN | CS_FRAME
+                            ,CS_SIZEREDRAW | CS_SYNCPAINT
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(MDI parent)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxMDIFrameClassNameNoRedraw
                             ,(PFNWP)wxWndProc
-                            ,CS_HITTEST | CS_CLIPCHILDREN | CS_FRAME
+                            ,0
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(no redraw MDI parent)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxMDIChildFrameClassName
                             ,(PFNWP)wxWndProc
-                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST | CS_CLIPSIBLINGS | CS_FRAME
+                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(MDI child)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxMDIChildFrameClassNameNoRedraw
                             ,(PFNWP)wxWndProc
-                            ,CS_HITTEST | CS_CLIPSIBLINGS | CS_FRAME
+                            ,CS_HITTEST
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(no redraw MDI child)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxPanelClassName
                             ,(PFNWP)wxWndProc
-                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_CLIPSIBLINGS | CS_SAVEBITS | CS_SYNCPAINT
+                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(Panel)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
 
     if (!::WinRegisterClass( vHab
                             ,wxCanvasClassName
                             ,(PFNWP)wxWndProc
-                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_CLIPSIBLINGS | CS_SAVEBITS | CS_SYNCPAINT
+                            ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT
                             ,0
                            ))
     {
-        wxLogLastError("RegisterClass(Canvas)");
-
+        vError = ::WinGetLastError(vHab);
+        sError = wxPMErrorToStr(vError);
+        wxLogLastError(sError);
         return FALSE;
     }
     return TRUE;
@@ -298,13 +321,19 @@ void wxApp::CleanUp()
     wxLog::DontCreateOnDemand();
 
     // this will flush the old messages if any
+#if (!(defined(__VISAGECPP__) && __IBMCPP__ < 400))
+    // another VA 3.0 memory problem here
     delete wxLog::SetActiveTarget(new wxLogStderr);
+#endif
 #endif // wxUSE_LOG
 
     // One last chance for pending objects to be cleaned up
     wxTheApp->DeletePendingObjects();
 
+#if (!(defined(__VISAGECPP__) && __IBMCPP__ < 400))
+    // another VA 3.0 memory problem here
     wxModule::CleanUpModules();
+#endif
 
 #if wxUSE_WX_RESOURCES
     wxCleanUpResourceSystem();
@@ -316,7 +345,10 @@ void wxApp::CleanUp()
     // by deleting the bitmap list before g_globalCursor goes out of scope
     // (double deletion of the cursor).
     wxSetCursor(wxNullCursor);
+#if (!(defined(__VISAGECPP__) && __IBMCPP__ < 400))
+    // another VA 3.0 memory problem here
     delete g_globalCursor;
+#endif
     g_globalCursor = NULL;
 
     wxDeleteStockObjects();
@@ -334,7 +366,7 @@ void wxApp::CleanUp()
 
     //// WINDOWS-SPECIFIC CLEANUP
 
-    wxSetKeyboardHook(FALSE);
+    // wxSetKeyboardHook(FALSE);
 
     if (wxSTD_FRAME_ICON)
         ::WinFreeFileIcon(wxSTD_FRAME_ICON);
@@ -397,7 +429,7 @@ int wxEntry(
 , char*                             argv[]
 )
 {
-    HAB                             vHab;
+    HAB                             vHab = 0;
 
     if (!wxApp::Initialize(vHab))
         return 0;
@@ -407,17 +439,14 @@ int wxEntry(
     //
     if (!wxTheApp)
     {
-        wxCHECK_MSG( wxApp::GetInitializerFunction()
-                    ,-1
-                    ,wxT("wxWindows error: No initializer - use IMPLEMENT_APP macro.\n")
-                   );
-
-        wxAppInitializerFunction    fnAppIni = wxApp::GetInitializerFunction();
-        wxObject*                   pTest_app = fnAppIni();
-
-        wxTheApp = (wxApp*)pTest_app;
+        // The app may have declared a global application object, but we recommend
+        // the IMPLEMENT_APP macro is used instead, which sets an initializer
+        // function for delayed, dynamic app object construction.
+        wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
+                     wxT("No initializer - use IMPLEMENT_APP macro.") );
+        wxTheApp = (*wxApp::GetInitializerFunction()) ();
     }
-    wxCHECK_MSG( wxTheApp, -1, wxT("wxWindows error: no application object") );
+    wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
     wxTheApp->argc = argc;
 
 #if wxUSE_UNICODE
@@ -449,28 +478,26 @@ int wxEntry(
     {
         if (wxTheApp->OnInit())
         {
-            nRetValue = -1;
+            nRetValue = wxTheApp->OnRun();
+//          nRetValue = -1;
         }
     }
 
-    if (nRetValue == 0)
-    {
-        wxWindow*                   pTopWindow = wxTheApp->GetTopWindow();
+    wxWindow*                       pTopWindow = wxTheApp->GetTopWindow();
 
-        if (pTopWindow)
+    if (pTopWindow)
+    {
+        // Forcibly delete the window.
+        if (pTopWindow->IsKindOf(CLASSINFO(wxFrame)) ||
+            pTopWindow->IsKindOf(CLASSINFO(wxDialog)) )
         {
-            // Forcibly delete the window.
-            if (pTopWindow->IsKindOf(CLASSINFO(wxFrame)) ||
-                pTopWindow->IsKindOf(CLASSINFO(wxDialog)) )
-            {
-                pTopWindow->Close(TRUE);
-                wxTheApp->DeletePendingObjects();
-            }
-            else
-            {
-                delete pTopWindow;
-                wxTheApp->SetTopWindow(NULL);
-            }
+            pTopWindow->Close(TRUE);
+            wxTheApp->DeletePendingObjects();
+        }
+        else
+        {
+            delete pTopWindow;
+            wxTheApp->SetTopWindow(NULL);
         }
     }
     wxTheApp->OnExit();
@@ -480,9 +507,17 @@ int wxEntry(
 
 bool wxApp::OnInitGui()
 {
-    m_vHab = WinInitialize(0);
-    m_hMq  = WinCreateMsgQueue(m_vHab, 0);
+    ERRORID                         vError;
+    wxString                        sError;
 
+    m_hMq = ::WinCreateMsgQueue(vHabmain, 0);
+    if (!m_hMq)
+    {
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogDebug(sError);
+        return FALSE;
+    }
     return TRUE;
 }
 
@@ -506,6 +541,7 @@ wxApp::wxApp()
 
 wxApp::~wxApp()
 {
+#if wxUSE_UNICODE
     // Delete command-line args
     int i;
     for (i = 0; i < argc; i++)
@@ -513,6 +549,7 @@ wxApp::~wxApp()
         delete[] argv[i];
     }
     delete[] argv;
+#endif
 }
 
 bool wxApp::Initialized()
@@ -529,7 +566,7 @@ bool wxApp::Initialized()
 //
 bool wxApp::DoMessage()
 {
-    BOOL                            bRc = ::WinGetMsg(m_vHab, &m_vMsg, HWND(NULL), 0, 0);
+    BOOL                            bRc = ::WinGetMsg(vHabmain, &m_vMsg, HWND(NULL), 0, 0);
 
     if (bRc == 0)
     {
@@ -591,7 +628,7 @@ bool wxApp::DoMessage()
 
                     if ( !ProcessMessage((WXMSG *)&vMsg) )
                     {
-                        ::WinDispatchMsg(m_vHab, &vMsg);
+                        ::WinDispatchMsg(vHabmain, &vMsg);
                     }
                 }
                 svSavedMessages.Empty();
@@ -602,7 +639,7 @@ bool wxApp::DoMessage()
         // Process the message
         if (!ProcessMessage((WXMSG *)&svCurrentMsg) )
         {
-            ::WinDispatchMsg(m_vHab, (PQMSG)&svCurrentMsg);
+            ::WinDispatchMsg(vHabmain, (PQMSG)&svCurrentMsg);
         }
     }
     return TRUE;
@@ -632,7 +669,7 @@ int wxApp::MainLoop()
 #if wxUSE_THREADS
         wxMutexGuiLeaveOrEnter();
 #endif // wxUSE_THREADS
-        while (!::WinPeekMsg(m_vHab, &svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) &&
+        while (!::WinPeekMsg(vHabmain, &svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) &&
                 ProcessIdle() )
         {
         }
@@ -677,7 +714,7 @@ void wxApp::ExitMainLoop()
 
 bool wxApp::Pending()
 {
-    return (::WinPeekMsg(m_vHab, (PQMSG)&svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) != 0);
+    return (::WinPeekMsg(vHabmain, (PQMSG)&svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) != 0);
 }
 
 void wxApp::Dispatch()
@@ -872,7 +909,7 @@ void wxExit()
 // Yield to incoming messages
 bool wxYield()
 {
-    HAB                             vHab;
+    HAB                             vHab = 0;
     QMSG                            vMsg;
     // We want to go back to the main message loop
     // if we see a WM_QUIT. (?)
@@ -923,4 +960,3 @@ void wxSetInstance(HINSTANCE hInst)
     wxhInstance = hInst;
 }
 
-