]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/spinbutt.cpp
Fixed wxMessageBox with only an OK button returning wxCANCEL under MSW.
[wxWidgets.git] / src / os2 / spinbutt.cpp
index 6e58a263223578a3b4dd1eaaf29bb378a657253b..19ea7af58212bfbdfacbd96c12d517ed3a15587c 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        spinbutt.cpp
+// Name:        src/os2/spinbutt.cpp
 // Purpose:     wxSpinButton
 // Author:      David Webster
 // Modified by:
 // Purpose:     wxSpinButton
 // Author:      David Webster
 // Modified by:
@@ -9,11 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-    #pragma implementation "spinbutt.h"
-    #pragma implementation "spinbutbase.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -32,9 +27,6 @@
 extern void  wxAssociateWinWithHandle( HWND         hWnd
                                       ,wxWindowOS2* pWin
                                      );
 extern void  wxAssociateWinWithHandle( HWND         hWnd
                                       ,wxWindowOS2* pWin
                                      );
-static WXFARPROC fnWndProcSpinCtrl = (WXFARPROC)NULL;
-
-IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
 
 #include "wx/os2/private.h"
 
 
 #include "wx/os2/private.h"
 
@@ -46,8 +38,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent)
 // wxWin macros
 // ----------------------------------------------------------------------------
 
 // wxWin macros
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
-
 bool wxSpinButton::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
 bool wxSpinButton::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
@@ -61,6 +51,7 @@ bool wxSpinButton::Create(
     int                             nY      = rPos.y;
     int                             nWidth  = rSize.x;
     int                             nHeight = rSize.y;
     int                             nY      = rPos.y;
     int                             nWidth  = rSize.x;
     int                             nHeight = rSize.y;
+    SWP                             vSwp;
 
     m_min = 0;
     m_max = 100;
 
     m_min = 0;
     m_max = 100;
@@ -68,8 +59,11 @@ bool wxSpinButton::Create(
         m_windowId = NewControlId();
     else
         m_windowId = vId;
         m_windowId = NewControlId();
     else
         m_windowId = vId;
-    m_backgroundColour = pParent->GetBackgroundColour();
-    m_foregroundColour = pParent->GetForegroundColour();
+    if (pParent)
+    {
+        m_backgroundColour = pParent->GetBackgroundColour();
+        m_foregroundColour = pParent->GetForegroundColour();
+    }
     SetName(rsName);
     SetParent(pParent);
     m_windowStyle      = lStyle;
     SetName(rsName);
     SetParent(pParent);
     m_windowStyle      = lStyle;
@@ -101,15 +95,6 @@ bool wxSpinButton::Create(
     if (m_windowStyle & wxCLIP_SIBLINGS )
         lSstyle |= WS_CLIPSIBLINGS;
 
     if (m_windowStyle & wxCLIP_SIBLINGS )
         lSstyle |= WS_CLIPSIBLINGS;
 
-    SPBCDATA                        vCtrlData;
-
-    vCtrlData.cbSize = sizeof(SPBCDATA);
-    vCtrlData.ulTextLimit = 10L;
-    vCtrlData.lLowerLimit = 0L;
-    vCtrlData.lUpperLimit = 100L;
-    vCtrlData.idMasterSpb = vId;
-    vCtrlData.pHWXCtlData = NULL;
-
     m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
                                        ,WC_SPINBUTTON
                                        ,(PSZ)NULL
     m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent)
                                        ,WC_SPINBUTTON
                                        ,(PSZ)NULL
@@ -118,31 +103,42 @@ bool wxSpinButton::Create(
                                        ,GetWinHwnd(pParent)
                                        ,HWND_TOP
                                        ,(HMENU)vId
                                        ,GetWinHwnd(pParent)
                                        ,HWND_TOP
                                        ,(HMENU)vId
-                                       ,(PVOID)&vCtrlData
+                                       ,NULL
                                        ,NULL
                                       );
     if (m_hWnd == 0)
     {
         return FALSE;
     }
                                        ,NULL
                                       );
     if (m_hWnd == 0)
     {
         return FALSE;
     }
+    SetRange(m_min, m_max);
     if(pParent)
         pParent->AddChild((wxSpinButton *)this);
 
     if(pParent)
         pParent->AddChild((wxSpinButton *)this);
 
-    SetFont(pParent->GetFont());
+    ::WinQueryWindowPos(m_hWnd, &vSwp);
+    SetXComp(vSwp.x);
+    SetYComp(vSwp.y-5); // compensate for the associated TextControl border
+
+    SetFont(*wxSMALL_FONT);
     //
     // For OS/2 we want to hide the text portion so we can substitute an
     //
     // For OS/2 we want to hide the text portion so we can substitute an
-    // independent text ctrl in its place.  10 device units does this
+    // independent text ctrl in its place.
+    // Therefore we must override any user given width with our best guess.
     //
     //
-    SetSize( nX
-            ,nY
-            ,10L
+    SetSize( nX - GetXComp()
+            ,nY - GetYComp()
+            ,nWidth
             ,nHeight
            );
     wxAssociateWinWithHandle( m_hWnd
                              ,(wxWindowOS2*)this
                             );
             ,nHeight
            );
     wxAssociateWinWithHandle( m_hWnd
                              ,(wxWindowOS2*)this
                             );
+#if 0
+    // FIXME:
+    // Apparently, this does not work, as it crashes in setvalue/setrange calls
+    // What's it supposed to do anyway?
     ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
     fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
     ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
     fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
+#endif
     return TRUE;
 } // end of wxSpinButton::Create
 
     return TRUE;
 } // end of wxSpinButton::Create
 
@@ -157,10 +153,12 @@ wxSpinButton::~wxSpinButton()
 wxSize wxSpinButton::DoGetBestSize() const
 {
     //
 wxSize wxSpinButton::DoGetBestSize() const
 {
     //
-    // OS/2 PM does not really have system metrics so we'll just set our best guess
-    // Also we have no horizontal spin buttons.
+    // OS/2 PM does not really have system metrics so we'll just set it to
+    // a square based on its height.
     //
     //
-    return (wxSize(10,20));
+    RECTL   vRect;
+    ::WinQueryWindowRect(GetHwnd(),&vRect);
+    return wxSize(vRect.yTop,vRect.yTop);
 } // end of wxSpinButton::DoGetBestSize
 
 // ----------------------------------------------------------------------------
 } // end of wxSpinButton::DoGetBestSize
 
 // ----------------------------------------------------------------------------
@@ -169,7 +167,6 @@ wxSize wxSpinButton::DoGetBestSize() const
 
 int wxSpinButton::GetValue() const
 {
 
 int wxSpinButton::GetValue() const
 {
-    int                             nVal = 0;
     long                            lVal = 0L;
     char                            zVal[10];
 
     long                            lVal = 0L;
     char                            zVal[10];
 
@@ -184,31 +181,25 @@ int wxSpinButton::GetValue() const
     return ((int)lVal);
 } // end of wxSpinButton::GetValue
 
     return ((int)lVal);
 } // end of wxSpinButton::GetValue
 
-bool wxSpinButton::OS2OnScroll(
-  int                               nOrientation
-, WXWORD                            wParam
-, WXWORD                            wPos
-, WXHWND                            hControl
-)
+bool wxSpinButton::OS2OnScroll( int    WXUNUSED(nOrientation),
+                                WXWORD WXUNUSED(wParam),
+                                WXWORD wPos,
+                                WXHWND hControl )
 {
 {
-    wxCHECK_MSG(hControl, FALSE, wxT("scrolling what?") )
+    wxCHECK_MSG(hControl, false, wxT("scrolling what?") );
 
 
-    wxSpinEvent                     vEvent( wxEVT_SCROLL_THUMBTRACK
-                                           ,m_windowId
-                                          );
-    int                             nVal = (int)wPos;    // cast is important for negative values!
+    wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
+    int nVal = (int)wPos;    // cast is important for negative values!
 
     vEvent.SetPosition(nVal);
     vEvent.SetEventObject(this);
 
     vEvent.SetPosition(nVal);
     vEvent.SetEventObject(this);
-    return(GetEventHandler()->ProcessEvent(vEvent));
+    return(HandleWindowEvent(vEvent));
 } // end of wxSpinButton::OS2OnScroll
 
 } // end of wxSpinButton::OS2OnScroll
 
-bool wxSpinButton::OS2Command(
-  WXUINT                            uCmd
-, WXWORD                            wId
-)
+bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
+                               WXWORD WXUNUSED(wId) )
 {
 {
-    return FALSE;
+    return false;
 } // end of wxSpinButton::OS2Command
 
 void wxSpinButton::SetRange(
 } // end of wxSpinButton::OS2Command
 
 void wxSpinButton::SetRange(