]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/gauge.cpp
Fixed wxRichTextCtrl base class
[wxWidgets.git] / src / os2 / gauge.cpp
index b227ebf692cddc28aea6931882ccfaa98fe88e39..9c95081918e446a3462a6d24cefbaaadb85277dd 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        gauge.cpp
+// Name:        src/os2/gauge.cpp
 // Purpose:     wxGauge class
 // Author:      David Webster
 // Modified by:
 // Purpose:     wxGauge class
 // Author:      David Webster
 // Modified by:
 
 #include "wx/wxprec.h"
 
 
 #include "wx/wxprec.h"
 
+#if wxUSE_GAUGE
+
+#include "wx/gauge.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-#include "wx/defs.h"
-#include "wx/utils.h"
+    #include "wx/utils.h"
+    #include "wx/scrolwin.h"
 #endif
 
 #include "wx/os2/private.h"
 #endif
 
 #include "wx/os2/private.h"
-#include "wx/gauge.h"
 
 static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
 extern void  wxAssociateWinWithHandle( HWND         hWnd
                                       ,wxWindowOS2* pWin
                                      );
 
 
 static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
 extern void  wxAssociateWinWithHandle( HWND         hWnd
                                       ,wxWindowOS2* pWin
                                      );
 
-IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxGaugeBase)
 
 
-MRESULT EXPENTRY wxGaugeWndProc(
-  HWND                              hWnd
-, UINT                              uMessage
-, MPARAM                            wParam
-, MPARAM                            lParam
-)
+MRESULT EXPENTRY wxGaugeWndProc( HWND hWnd,
+                                 UINT uMessage,
+                                 MPARAM wParam,
+                                 MPARAM lParam )
 {
     wxGauge*                        pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
                                                                               ,QWL_USER
                                                                              );
 {
     wxGauge*                        pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
                                                                               ,QWL_USER
                                                                              );
-    wxWindowOS2*                    pWindow = NULL;
-    MRESULT                         rc = (MRESULT)0;
-    bool                            bProcessed = FALSE;
-    HPS                             hPS;
-    RECTL                           vRect;
-    RECTL                           vRect2;
-    double                          dPixelToRange = 0.0;
-    double                          dRange = 0.0;
+    HPS hPS;
+    RECTL vRect;
+    RECTL vRect2;
+    RECTL vRect3;
+    double dPixelToRange = 0.0;
+    double dRange = 0.0;
 
     switch (uMessage )
     {
 
     switch (uMessage )
     {
@@ -69,28 +68,55 @@ MRESULT EXPENTRY wxGaugeWndProc(
                                          ,0L
                                          ,NULL
                                         );
                                          ,0L
                                          ,NULL
                                         );
+                //
+                // Draw the guage box
+                //
+                LONG                lColor = 0x00FFFFFF; // White
+                POINTL              vPoint = {vRect.xLeft + 1, vRect.yBottom + 1};
+
+                ::GpiSetColor(hPS, lColor);
+                ::GpiMove(hPS, &vPoint);
+                vPoint.x = vRect.xRight - 1;
+                ::GpiLine(hPS, &vPoint);
+                vPoint.y = vRect.yTop - 1;
+                ::GpiLine(hPS, &vPoint);
+                lColor = 0x000C0C0C; // Darkish Grey to give depth feel
+                ::GpiSetColor(hPS, lColor);
+                vPoint.x = vRect.xLeft + 1;
+                ::GpiLine(hPS, &vPoint);
+                vPoint.y = vRect.yBottom + 1;
+                ::GpiLine(hPS, &vPoint);
+                vRect3.xLeft   = vRect.xLeft + 2;
+                vRect3.xRight  = vRect.xRight - 2;
+                vRect3.yTop    = vRect.yTop - 2;
+                vRect3.yBottom = vRect.yBottom + 2;
+
                 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
                 {
                 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
                 {
-                    dRange = (double)(vRect.yTop - vRect.yBottom);
+                    dRange = (double)(vRect3.yTop - vRect3.yBottom);
                     dPixelToRange  = dRange/(double)pGauge->GetRange();
                     vRect2.yTop    = (int)(pGauge->GetValue() * dPixelToRange);
                     dPixelToRange  = dRange/(double)pGauge->GetRange();
                     vRect2.yTop    = (int)(pGauge->GetValue() * dPixelToRange);
-                    vRect2.yBottom = vRect.yBottom;
-                    vRect2.xLeft   = vRect.xLeft;
-                    vRect2.xRight  = vRect.xRight;
-                    vRect.yBottom  = vRect2.yTop;
-                    ::WinFillRect(hPS, &vRect,  pGauge->GetBackgroundColour().GetPixel());
+                    vRect2.yBottom = vRect3.yBottom;
+                    vRect2.xLeft   = vRect3.xLeft;
+                    vRect2.xRight  = vRect3.xRight;
+                    vRect3.yBottom  = vRect2.yTop;
+                    if (vRect3.yBottom <= 1)
+                         vRect3.yBottom = 2;
+                    ::WinFillRect(hPS, &vRect3,  pGauge->GetBackgroundColour().GetPixel());
                     ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
                 }
                 else
                 {
                     ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
                 }
                 else
                 {
-                    dRange = (double)(vRect.xRight - vRect.xLeft);
+                    dRange = (double)(vRect3.xRight - vRect3.xLeft);
                     dPixelToRange  = dRange/(double)pGauge->GetRange();
                     dPixelToRange  = dRange/(double)pGauge->GetRange();
-                    vRect2.yTop    = vRect.yTop;
-                    vRect2.yBottom = vRect.yBottom;
-                    vRect2.xLeft   = vRect.xLeft;
+                    vRect2.yTop    = vRect3.yTop;
+                    vRect2.yBottom = vRect3.yBottom;
+                    vRect2.xLeft   = vRect3.xLeft;
                     vRect2.xRight  = (int)(pGauge->GetValue() * dPixelToRange);
                     vRect2.xRight  = (int)(pGauge->GetValue() * dPixelToRange);
-                    vRect.xLeft = vRect2.xRight;
-                    ::WinFillRect(hPS, &vRect,  pGauge->GetBackgroundColour().GetPixel());
+                    vRect3.xLeft = vRect2.xRight;
+                    if (vRect3.xLeft <= 1)
+                        vRect3.xLeft = 2;
+                    ::WinFillRect(hPS, &vRect3,  pGauge->GetBackgroundColour().GetPixel());
                     ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
                 }
                 ::WinEndPaint(hPS);
                     ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
                 }
                 ::WinEndPaint(hPS);
@@ -104,24 +130,21 @@ MRESULT EXPENTRY wxGaugeWndProc(
            );
 } // end of wxGaugeWndProc
 
            );
 } // end of wxGaugeWndProc
 
-bool wxGauge::Create(
-  wxWindowOS2*                      pParent
-, wxWindowID                        vId
-, int                               nRange
-, const wxPoint&                    rPos
-, const wxSize&                     rSize
-, long                              lStyle
-#if wxUSE_VALIDATORS
-, const wxValidator&                rValidator
-#endif
-, const wxString&                   rsName
-)
+bool wxGauge::Create( wxWindowOS2* pParent,
+                      wxWindowID vId,
+                      int nRange,
+                      const wxPoint& rPos,
+                      const wxSize& rSize,
+                      long lStyle,
+                      const wxValidator& rValidator,
+                      const wxString& rsName )
 {
 {
-    int                             nX       = rPos.x;
-    int                             nY       = rPos.y;
-    int                             nWidth   = rSize.x;
-    int                             nHeight  = rSize.y;
-    long                            lMsStyle = 0L;
+    int nX       = rPos.x;
+    int nY       = rPos.y;
+    int nWidth   = rSize.x;
+    int nHeight  = rSize.y;
+    long lMsStyle = 0L;
+    SWP vSwp;
 
     SetName(rsName);
 #if wxUSE_VALIDATORS
 
     SetName(rsName);
 #if wxUSE_VALIDATORS
@@ -129,14 +152,14 @@ bool wxGauge::Create(
 #endif
     if (pParent)
         pParent->AddChild(this);
 #endif
     if (pParent)
         pParent->AddChild(this);
-    SetBackgroundColour(pParent->GetBackgroundColour()) ;
-    SetForegroundColour(pParent->GetForegroundColour()) ;
+    m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
+    m_foregroundColour.Set(wxString(wxT("NAVY")));
 
     m_nRangeMax   = nRange;
     m_nGaugePos   = 0;
     m_windowStyle = lStyle;
 
 
     m_nRangeMax   = nRange;
     m_nGaugePos   = 0;
     m_windowStyle = lStyle;
 
-    if (vId == -1)
+    if (vId == wxID_ANY)
         m_windowId = (int)NewControlId();
     else
         m_windowId = vId;
         m_windowId = (int)NewControlId();
     else
         m_windowId = vId;
@@ -154,8 +177,6 @@ bool wxGauge::Create(
     if (m_windowStyle & wxCLIP_SIBLINGS)
         lMsStyle |= WS_CLIPSIBLINGS;
 
     if (m_windowStyle & wxCLIP_SIBLINGS)
         lMsStyle |= WS_CLIPSIBLINGS;
 
-
-
     m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
                                        ,WC_ENTRYFIELD            // Window class
                                        ,(PSZ)NULL                // Initial Text
     m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
                                        ,WC_ENTRYFIELD            // Window class
                                        ,(PSZ)NULL                // Initial Text
@@ -173,7 +194,15 @@ bool wxGauge::Create(
                             );
     ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
     fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
                             );
     ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
     fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
-    SetFont(pParent->GetFont());
+    ::WinQueryWindowPos(m_hWnd, &vSwp);
+    SetXComp(vSwp.x);
+    SetYComp(vSwp.y);
+    wxFont*                          pTextFont = new wxFont( 10
+                                                            ,wxMODERN
+                                                            ,wxNORMAL
+                                                            ,wxNORMAL
+                                                           );
+    SetFont(*pTextFont);
     if (nWidth == -1L)
         nWidth = 50L;
     if (nHeight == -1L)
     if (nWidth == -1L)
         nWidth = 50L;
     if (nHeight == -1L)
@@ -183,8 +212,11 @@ bool wxGauge::Create(
             ,nWidth
             ,nHeight
            );
             ,nWidth
             ,nHeight
            );
+    m_nWidth  = nWidth;     // Save for GetBestSize
+    m_nHeight = nHeight;
     ::WinShowWindow((HWND)GetHWND(), TRUE);
     ::WinShowWindow((HWND)GetHWND(), TRUE);
-    return TRUE;
+    delete pTextFont;
+    return true;
 } // end of wxGauge::Create
 
 int wxGauge::GetBezelFace() const
 } // end of wxGauge::Create
 
 int wxGauge::GetBezelFace() const
@@ -207,12 +239,10 @@ int wxGauge::GetValue() const
     return m_nGaugePos;
 } // end of wxGauge::GetValue
 
     return m_nGaugePos;
 } // end of wxGauge::GetValue
 
-bool wxGauge::SetBackgroundColour(
-  const wxColour&                   rColour
-)
+bool wxGauge::SetBackgroundColour( const wxColour& rColour )
 {
     if (!wxControl::SetBackgroundColour(rColour))
 {
     if (!wxControl::SetBackgroundColour(rColour))
-        return FALSE;
+        return false;
 
     LONG                            lColor = (LONG)rColour.GetPixel();
 
 
     LONG                            lColor = (LONG)rColour.GetPixel();
 
@@ -221,23 +251,19 @@ bool wxGauge::SetBackgroundColour(
                       ,sizeof(LONG)
                       ,(PVOID)&lColor
                      );
                       ,sizeof(LONG)
                       ,(PVOID)&lColor
                      );
-    return TRUE;
+    return true;
 } // end of wxGauge::SetBackgroundColour
 
 } // end of wxGauge::SetBackgroundColour
 
-void wxGauge::SetBezelFace(
-  int                               WXUNUSED(nWidth)
-)
+void wxGauge::SetBezelFace( int WXUNUSED(nWidth) )
 {
 } // end of wxGauge::SetBezelFace
 
 {
 } // end of wxGauge::SetBezelFace
 
-bool wxGauge::SetForegroundColour(
-  const wxColour&                   rColour
-)
+bool wxGauge::SetForegroundColour( const wxColour& rColour )
 {
     if (!wxControl::SetForegroundColour(rColour))
 {
     if (!wxControl::SetForegroundColour(rColour))
-        return FALSE;
+        return false;
 
 
-    LONG                            lColor = (LONG)rColour.GetPixel();
+    LONG lColor = (LONG)rColour.GetPixel();
 
     ::WinSetPresParam( GetHwnd()
                       ,PP_FOREGROUNDCOLOR
 
     ::WinSetPresParam( GetHwnd()
                       ,PP_FOREGROUNDCOLOR
@@ -245,31 +271,30 @@ bool wxGauge::SetForegroundColour(
                       ,(PVOID)&lColor
                      );
 
                       ,(PVOID)&lColor
                      );
 
-    return TRUE;
+    return true;
 } // end of wxGauge::SetForegroundColour
 
 } // end of wxGauge::SetForegroundColour
 
-void wxGauge::SetRange(
-  int                               nRange
-)
+void wxGauge::SetRange( int nRange )
 {
     m_nRangeMax = nRange;
 } // end of wxGauge::SetRange
 
 {
     m_nRangeMax = nRange;
 } // end of wxGauge::SetRange
 
-void wxGauge::SetShadowWidth(
-  int                               WXUNUSED(nWidth)
-)
+void wxGauge::SetShadowWidth( int WXUNUSED(nWidth) )
 {
 } // end of wxGauge::SetShadowWidth
 
 {
 } // end of wxGauge::SetShadowWidth
 
-void wxGauge::SetValue(
-  int                               nPos
-)
+void wxGauge::SetValue( int nPos )
 {
 {
-    RECT                            vRect;
+    RECT vRect;
 
     m_nGaugePos = nPos;
     ::WinQueryWindowRect(GetHwnd(), &vRect);
     ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
 } // end of wxGauge::SetValue
 
 
     m_nGaugePos = nPos;
     ::WinQueryWindowRect(GetHwnd(), &vRect);
     ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
 } // end of wxGauge::SetValue
 
+wxSize wxGauge::DoGetBestSize() const
+{
+    return wxSize(m_nWidth,m_nHeight);
+}
 
 
+#endif // wxUSE_GAUGE