]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/gauge.cpp 
   3 // Purpose:     wxGauge class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  16     #include "wx/scrolwin.h" 
  19 #include "wx/os2/private.h" 
  22 static WXFARPROC fnWndProcGauge 
= (WXFARPROC
)NULL
; 
  23 extern void  wxAssociateWinWithHandle( HWND         hWnd
 
  27 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
) 
  29 MRESULT EXPENTRY 
wxGaugeWndProc( 
  36     wxGauge
*                        pGauge 
= (wxGauge 
*)::WinQueryWindowULong( hWnd
 
  43     double                          dPixelToRange 
= 0.0; 
  49             hPS 
= ::WinBeginPaint( hWnd
 
  55                 ::WinQueryWindowRect(hWnd
, &vRect
); 
  56                 ::GpiCreateLogColorTable( hPS
 
  60                                          ,(LONG
)wxTheColourDatabase
->m_nSize
 
  61                                          ,(PLONG
)wxTheColourDatabase
->m_palTable
 
  63                 ::GpiCreateLogColorTable( hPS
 
  73                 LONG                lColor 
= 0x00FFFFFF; // White 
  74                 POINTL              vPoint 
= {vRect
.xLeft 
+ 1, vRect
.yBottom 
+ 1}; 
  76                 ::GpiSetColor(hPS
, lColor
); 
  77                 ::GpiMove(hPS
, &vPoint
); 
  78                 vPoint
.x 
= vRect
.xRight 
- 1; 
  79                 ::GpiLine(hPS
, &vPoint
); 
  80                 vPoint
.y 
= vRect
.yTop 
- 1; 
  81                 ::GpiLine(hPS
, &vPoint
); 
  82                 lColor 
= 0x000C0C0C; // Darkish Grey to give depth feel 
  83                 ::GpiSetColor(hPS
, lColor
); 
  84                 vPoint
.x 
= vRect
.xLeft 
+ 1; 
  85                 ::GpiLine(hPS
, &vPoint
); 
  86                 vPoint
.y 
= vRect
.yBottom 
+ 1; 
  87                 ::GpiLine(hPS
, &vPoint
); 
  88                 vRect3
.xLeft   
= vRect
.xLeft 
+ 2; 
  89                 vRect3
.xRight  
= vRect
.xRight 
- 2; 
  90                 vRect3
.yTop    
= vRect
.yTop 
- 2; 
  91                 vRect3
.yBottom 
= vRect
.yBottom 
+ 2; 
  93                 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
) 
  95                     dRange 
= (double)(vRect3
.yTop 
- vRect3
.yBottom
); 
  96                     dPixelToRange  
= dRange
/(double)pGauge
->GetRange(); 
  97                     vRect2
.yTop    
= (int)(pGauge
->GetValue() * dPixelToRange
); 
  98                     vRect2
.yBottom 
= vRect3
.yBottom
; 
  99                     vRect2
.xLeft   
= vRect3
.xLeft
; 
 100                     vRect2
.xRight  
= vRect3
.xRight
; 
 101                     vRect3
.yBottom  
= vRect2
.yTop
; 
 102                     if (vRect3
.yBottom 
<= 1) 
 104                     ::WinFillRect(hPS
, &vRect3
,  pGauge
->GetBackgroundColour().GetPixel()); 
 105                     ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel()); 
 109                     dRange 
= (double)(vRect3
.xRight 
- vRect3
.xLeft
); 
 110                     dPixelToRange  
= dRange
/(double)pGauge
->GetRange(); 
 111                     vRect2
.yTop    
= vRect3
.yTop
; 
 112                     vRect2
.yBottom 
= vRect3
.yBottom
; 
 113                     vRect2
.xLeft   
= vRect3
.xLeft
; 
 114                     vRect2
.xRight  
= (int)(pGauge
->GetValue() * dPixelToRange
); 
 115                     vRect3
.xLeft 
= vRect2
.xRight
; 
 116                     if (vRect3
.xLeft 
<= 1) 
 118                     ::WinFillRect(hPS
, &vRect3
,  pGauge
->GetBackgroundColour().GetPixel()); 
 119                     ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel()); 
 124     return (fnWndProcGauge( hWnd
 
 130 } // end of wxGaugeWndProc 
 132 bool wxGauge::Create( 
 136 , const wxPoint
&                    rPos
 
 137 , const wxSize
&                     rSize
 
 139 , const wxValidator
&                rValidator
 
 140 , const wxString
&                   rsName
 
 145     int                             nWidth   
= rSize
.x
; 
 146     int                             nHeight  
= rSize
.y
; 
 152     SetValidator(rValidator
); 
 155         pParent
->AddChild(this); 
 156     m_backgroundColour
.Set(wxString(wxT("LIGHT GREY"))); 
 157     m_foregroundColour
.Set(wxString(wxT("NAVY"))); 
 159     m_nRangeMax   
= nRange
; 
 161     m_windowStyle 
= lStyle
; 
 164         m_windowId 
= (int)NewControlId(); 
 168     if (m_windowStyle 
& wxCLIP_SIBLINGS 
) 
 169         lMsStyle 
|= WS_CLIPSIBLINGS
; 
 172     // OS/2 will use an edit control for this, since there is not a native gauge 
 173     // Other choices include using an armless slider but they are more difficult 
 174     // to control and manipulate 
 177     lMsStyle 
= WS_VISIBLE 
| ES_MARGIN 
| ES_LEFT 
| ES_READONLY
; 
 178     if (m_windowStyle 
& wxCLIP_SIBLINGS
) 
 179         lMsStyle 
|= WS_CLIPSIBLINGS
; 
 181     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
 182                                        ,WC_ENTRYFIELD            
// Window class 
 183                                        ,(PSZ
)NULL                
// Initial Text 
 184                                        ,(ULONG
)lMsStyle          
// Style flags 
 185                                        ,0L, 0L, 0L, 0L           // Origin -- 0 size 
 186                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
 187                                        ,HWND_TOP                 
// initial z position 
 188                                        ,(HMENU
)m_windowId        
// Window identifier 
 189                                        ,NULL                     
// Slider control data 
 190                                        ,NULL                     
// no Presentation parameters 
 193     wxAssociateWinWithHandle( m_hWnd
 
 196     ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this); 
 197     fnWndProcGauge 
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
); 
 198     ::WinQueryWindowPos(m_hWnd
, &vSwp
); 
 201     wxFont
*                          pTextFont 
= new wxFont( 10 
 216     m_nWidth  
= nWidth
;     // Save for GetBestSize 
 218     ::WinShowWindow((HWND
)GetHWND(), TRUE
); 
 221 } // end of wxGauge::Create 
 223 int wxGauge::GetBezelFace() const 
 226 } // end of wxGauge::GetBezelFace 
 228 int wxGauge::GetRange() const 
 231 } // end of wxGauge::GetRange 
 233 int wxGauge::GetShadowWidth() const 
 236 } // end of wxGauge::GetShadowWidth 
 238 int wxGauge::GetValue() const 
 241 } // end of wxGauge::GetValue 
 243 bool wxGauge::SetBackgroundColour( const wxColour
& rColour 
) 
 245     if (!wxControl::SetBackgroundColour(rColour
)) 
 248     LONG                            lColor 
= (LONG
)rColour
.GetPixel(); 
 250     ::WinSetPresParam( GetHwnd() 
 256 } // end of wxGauge::SetBackgroundColour 
 258 void wxGauge::SetBezelFace( 
 262 } // end of wxGauge::SetBezelFace 
 264 bool wxGauge::SetForegroundColour( const wxColour
& rColour 
) 
 266     if (!wxControl::SetForegroundColour(rColour
)) 
 269     LONG lColor 
= (LONG
)rColour
.GetPixel(); 
 271     ::WinSetPresParam( GetHwnd() 
 278 } // end of wxGauge::SetForegroundColour 
 280 void wxGauge::SetRange( 
 284     m_nRangeMax 
= nRange
; 
 285 } // end of wxGauge::SetRange 
 287 void wxGauge::SetShadowWidth( 
 291 } // end of wxGauge::SetShadowWidth 
 293 void wxGauge::SetValue( 
 300     ::WinQueryWindowRect(GetHwnd(), &vRect
); 
 301     ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
); 
 302 } // end of wxGauge::SetValue 
 304 wxSize 
wxGauge::DoGetBestSize() const 
 306     return wxSize(m_nWidth
,m_nHeight
);