]>
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" 
  20     #include "wx/scrolwin.h" 
  23 #include "wx/os2/private.h" 
  25 static WXFARPROC fnWndProcGauge 
= (WXFARPROC
)NULL
; 
  26 extern void  wxAssociateWinWithHandle( HWND         hWnd
 
  30 MRESULT EXPENTRY 
wxGaugeWndProc( HWND hWnd
, 
  35     wxGauge
*                        pGauge 
= (wxGauge 
*)::WinQueryWindowULong( hWnd
 
  42     double dPixelToRange 
= 0.0; 
  48             hPS 
= ::WinBeginPaint( hWnd
 
  54                 ::WinQueryWindowRect(hWnd
, &vRect
); 
  55                 ::GpiCreateLogColorTable( hPS
 
  59                                          ,(LONG
)wxTheColourDatabase
->m_nSize
 
  60                                          ,(PLONG
)wxTheColourDatabase
->m_palTable
 
  62                 ::GpiCreateLogColorTable( hPS
 
  72                 LONG                lColor 
= 0x00FFFFFF; // White 
  73                 POINTL              vPoint 
= {vRect
.xLeft 
+ 1, vRect
.yBottom 
+ 1}; 
  75                 ::GpiSetColor(hPS
, lColor
); 
  76                 ::GpiMove(hPS
, &vPoint
); 
  77                 vPoint
.x 
= vRect
.xRight 
- 1; 
  78                 ::GpiLine(hPS
, &vPoint
); 
  79                 vPoint
.y 
= vRect
.yTop 
- 1; 
  80                 ::GpiLine(hPS
, &vPoint
); 
  81                 lColor 
= 0x000C0C0C; // Darkish Grey to give depth feel 
  82                 ::GpiSetColor(hPS
, lColor
); 
  83                 vPoint
.x 
= vRect
.xLeft 
+ 1; 
  84                 ::GpiLine(hPS
, &vPoint
); 
  85                 vPoint
.y 
= vRect
.yBottom 
+ 1; 
  86                 ::GpiLine(hPS
, &vPoint
); 
  87                 vRect3
.xLeft   
= vRect
.xLeft 
+ 2; 
  88                 vRect3
.xRight  
= vRect
.xRight 
- 2; 
  89                 vRect3
.yTop    
= vRect
.yTop 
- 2; 
  90                 vRect3
.yBottom 
= vRect
.yBottom 
+ 2; 
  92                 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
) 
  94                     dRange 
= (double)(vRect3
.yTop 
- vRect3
.yBottom
); 
  95                     dPixelToRange  
= dRange
/(double)pGauge
->GetRange(); 
  96                     vRect2
.yTop    
= (int)(pGauge
->GetValue() * dPixelToRange
); 
  97                     vRect2
.yBottom 
= vRect3
.yBottom
; 
  98                     vRect2
.xLeft   
= vRect3
.xLeft
; 
  99                     vRect2
.xRight  
= vRect3
.xRight
; 
 100                     vRect3
.yBottom  
= vRect2
.yTop
; 
 101                     if (vRect3
.yBottom 
<= 1) 
 103                     ::WinFillRect(hPS
, &vRect3
,  pGauge
->GetBackgroundColour().GetPixel()); 
 104                     ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel()); 
 108                     dRange 
= (double)(vRect3
.xRight 
- vRect3
.xLeft
); 
 109                     dPixelToRange  
= dRange
/(double)pGauge
->GetRange(); 
 110                     vRect2
.yTop    
= vRect3
.yTop
; 
 111                     vRect2
.yBottom 
= vRect3
.yBottom
; 
 112                     vRect2
.xLeft   
= vRect3
.xLeft
; 
 113                     vRect2
.xRight  
= (int)(pGauge
->GetValue() * dPixelToRange
); 
 114                     vRect3
.xLeft 
= vRect2
.xRight
; 
 115                     if (vRect3
.xLeft 
<= 1) 
 117                     ::WinFillRect(hPS
, &vRect3
,  pGauge
->GetBackgroundColour().GetPixel()); 
 118                     ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel()); 
 123     return (fnWndProcGauge( hWnd
 
 129 } // end of wxGaugeWndProc 
 131 bool wxGauge::Create( wxWindowOS2
* pParent
, 
 137                       const wxValidator
& rValidator
, 
 138                       const wxString
& rsName 
) 
 142     int nWidth   
= rSize
.x
; 
 143     int nHeight  
= rSize
.y
; 
 149     SetValidator(rValidator
); 
 152         pParent
->AddChild(this); 
 153     m_backgroundColour
.Set(wxString(wxT("LIGHT GREY"))); 
 154     m_foregroundColour
.Set(wxString(wxT("NAVY"))); 
 156     m_nRangeMax   
= nRange
; 
 158     m_windowStyle 
= lStyle
; 
 161         m_windowId 
= (int)NewControlId(); 
 165     if (m_windowStyle 
& wxCLIP_SIBLINGS 
) 
 166         lMsStyle 
|= WS_CLIPSIBLINGS
; 
 169     // OS/2 will use an edit control for this, since there is not a native gauge 
 170     // Other choices include using an armless slider but they are more difficult 
 171     // to control and manipulate 
 174     lMsStyle 
= WS_VISIBLE 
| ES_MARGIN 
| ES_LEFT 
| ES_READONLY
; 
 175     if (m_windowStyle 
& wxCLIP_SIBLINGS
) 
 176         lMsStyle 
|= WS_CLIPSIBLINGS
; 
 178     m_hWnd 
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle 
 179                                        ,WC_ENTRYFIELD            
// Window class 
 180                                        ,(PSZ
)NULL                
// Initial Text 
 181                                        ,(ULONG
)lMsStyle          
// Style flags 
 182                                        ,0L, 0L, 0L, 0L           // Origin -- 0 size 
 183                                        ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent 
 184                                        ,HWND_TOP                 
// initial z position 
 185                                        ,(HMENU
)m_windowId        
// Window identifier 
 186                                        ,NULL                     
// Slider control data 
 187                                        ,NULL                     
// no Presentation parameters 
 190     wxAssociateWinWithHandle( m_hWnd
 
 193     ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this); 
 194     fnWndProcGauge 
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
); 
 195     ::WinQueryWindowPos(m_hWnd
, &vSwp
); 
 198     wxFont
*                          pTextFont 
= new wxFont( 10 
 213     m_nWidth  
= nWidth
;     // Save for GetBestSize 
 215     ::WinShowWindow((HWND
)GetHWND(), TRUE
); 
 218 } // end of wxGauge::Create 
 220 int wxGauge::GetBezelFace() const 
 223 } // end of wxGauge::GetBezelFace 
 225 int wxGauge::GetRange() const 
 228 } // end of wxGauge::GetRange 
 230 int wxGauge::GetShadowWidth() const 
 233 } // end of wxGauge::GetShadowWidth 
 235 int wxGauge::GetValue() const 
 238 } // end of wxGauge::GetValue 
 240 bool wxGauge::SetBackgroundColour( const wxColour
& rColour 
) 
 242     if (!wxControl::SetBackgroundColour(rColour
)) 
 245     LONG                            lColor 
= (LONG
)rColour
.GetPixel(); 
 247     ::WinSetPresParam( GetHwnd() 
 253 } // end of wxGauge::SetBackgroundColour 
 255 void wxGauge::SetBezelFace( int WXUNUSED(nWidth
) ) 
 257 } // end of wxGauge::SetBezelFace 
 259 bool wxGauge::SetForegroundColour( const wxColour
& rColour 
) 
 261     if (!wxControl::SetForegroundColour(rColour
)) 
 264     LONG lColor 
= (LONG
)rColour
.GetPixel(); 
 266     ::WinSetPresParam( GetHwnd() 
 273 } // end of wxGauge::SetForegroundColour 
 275 void wxGauge::SetRange( int nRange 
) 
 277     m_nRangeMax 
= nRange
; 
 278 } // end of wxGauge::SetRange 
 280 void wxGauge::SetShadowWidth( int WXUNUSED(nWidth
) ) 
 282 } // end of wxGauge::SetShadowWidth 
 284 void wxGauge::SetValue( int nPos 
) 
 289     ::WinQueryWindowRect(GetHwnd(), &vRect
); 
 290     ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
); 
 291 } // end of wxGauge::SetValue 
 293 wxSize 
wxGauge::DoGetBestSize() const 
 295     return wxSize(m_nWidth
,m_nHeight
); 
 298 #endif // wxUSE_GAUGE