]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxBitmapButton 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  18 #include "wx/bmpbuttn.h" 
  21 #include "wx/os2/private.h" 
  24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
) 
  26 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1) 
  28 bool wxBitmapButton::Create( 
  31 , const wxBitmap
&                   rBitmap
 
  35 , const wxValidator
&                rValidator
 
  36 , const wxString
&                   rsName
 
  39     m_bmpNormal 
= rBitmap
; 
  42     SetValidator(rValidator
); 
  45     pParent
->AddChild(this); 
  47     m_backgroundColour 
= pParent
->GetBackgroundColour() ; 
  48     m_foregroundColour 
= pParent
->GetForegroundColour() ; 
  49     m_windowStyle 
= lStyle
; 
  51     if (lStyle 
& wxBU_AUTODRAW
) 
  53         m_marginX 
= wxDEFAULT_BUTTON_MARGIN
; 
  54         m_marginY 
= wxDEFAULT_BUTTON_MARGIN
; 
  60     int                             nHeight 
= rSize
.y
; 
  63         m_windowId 
= NewControlId(); 
  67     if (nWidth 
== -1 && rBitmap
.Ok()) 
  68         nWidth 
= rBitmap
.GetWidth() + 4 * m_marginX
; 
  70     if (nHeight 
== -1 && rBitmap
.Ok()) 
  71         nHeight 
= rBitmap
.GetHeight() + 4 * m_marginY
; 
  73     ULONG                           ulOS2Style 
= WS_VISIBLE 
| WS_TABSTOP 
| BS_USERBUTTON
; 
  75     if (m_windowStyle 
& wxCLIP_SIBLINGS
) 
  76         ulOS2Style 
|= WS_CLIPSIBLINGS
; 
  78     m_hWnd 
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
) 
  91     //Subclass again for purposes of dialog editing mode 
  94     SetFont(*wxSMALL_FONT
); 
 101 } // end of wxBitmapButton::Create 
 103 bool wxBitmapButton::OS2OnDraw( 
 104   WXDRAWITEMSTRUCT
*                 pItem
 
 107     PUSERBUTTON                     pUser     
= (PUSERBUTTON
)pItem
; 
 108     bool                            bAutoDraw 
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0; 
 115     bool                            bIsSelected 
= pUser
->fsState 
& BDS_HILITED
; 
 116     wxClientDC                      
vDc(this); 
 118     if (bIsSelected 
&& m_bmpSelected
.Ok()) 
 119         pBitmap 
= &m_bmpSelected
; 
 120     else if ((pUser
->fsState 
& BDS_DEFAULT
) && m_bmpFocus
.Ok()) 
 121         pBitmap 
= &m_bmpFocus
; 
 122     else if ((pUser
->fsState 
& BDS_DISABLED
) && m_bmpDisabled
.Ok()) 
 123         pBitmap 
= &m_bmpDisabled
; 
 125         pBitmap 
= &m_bmpNormal
; 
 132     // Centre the bitmap in the control area 
 138     int                             nWidth     
= vDc
.m_vRclPaint
.xRight 
- vDc
.m_vRclPaint
.xLeft
; 
 139     int                             nHeight    
= vDc
.m_vRclPaint
.xRight 
- vDc
.m_vRclPaint
.xLeft
; 
 140     int                             nBmpWidth  
= pBitmap
->GetWidth(); 
 141     int                             nBmpHeight 
= pBitmap
->GetHeight(); 
 143     nX1 
= nX 
+ (nWidth 
- nBmpWidth
) / 2; 
 144     nY1 
= nX 
+ (nHeight 
- nBmpHeight
) / 2; 
 146     if (bIsSelected 
&& bAutoDraw
) 
 153     // Draw the button face 
 164     vDc
.DrawBitmap( *pBitmap
 
 171     // Draw focus / disabled state, if auto-drawing 
 173     if ((pUser
->fsState 
== BDS_DISABLED
) && bAutoDraw
) 
 175         DrawButtonDisable( vDc
 
 179     else if ((pUser
->fsState 
== BDS_DEFAULT
) && bAutoDraw
) 
 181         DrawButtonFocus(vDc
); 
 184 } // end of wxBitmapButton::OS2OnDraw 
 186 void wxBitmapButton::DrawFace ( 
 192     // Set up drawing colors 
 194     wxPen                           
vHiLitePen(wxColour(255, 255, 255), 2, wxSOLID
); // White 
 195     wxPen                           
vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID
); 
 196     wxColour                        
vFaceColor(wxColour(204, 204, 204)); // Light Grey 
 199     // Draw the main button face 
 201     ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel()); 
 206     rDC
.SetPen(bSel 
? vDarkShadowPen 
: vHiLitePen
); 
 207     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 208                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 209                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 210                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 212     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 213                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 214                  ,rDC
.m_vRclPaint
.xLeft 
+ 1 
 215                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 218     rDC
.SetPen(bSel 
? vHiLitePen 
: vDarkShadowPen
); 
 219     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 220                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 221                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 222                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 224     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight 
- 1 
 225                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 226                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 227                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 230 } // end of wxBitmapButton::DrawFace 
 232 void wxBitmapButton::DrawButtonFocus ( 
 236     wxPen                           
vBlackPen(wxColour(0, 0, 0), 2, wxSOLID
); 
 239     // Draw a thick black line around the outside of the button 
 241     rDC
.SetPen(vBlackPen
); 
 242     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 243                  ,rDC
.m_vRclPaint
.yTop
 
 244                  ,rDC
.m_vRclPaint
.xRight
 
 245                  ,rDC
.m_vRclPaint
.yTop
 
 247     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 248                  ,rDC
.m_vRclPaint
.yTop
 
 249                  ,rDC
.m_vRclPaint
.xRight
 
 250                  ,rDC
.m_vRclPaint
.yBottom
 
 252     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 253                  ,rDC
.m_vRclPaint
.yBottom
 
 254                  ,rDC
.m_vRclPaint
.xLeft
 
 255                  ,rDC
.m_vRclPaint
.yBottom
 
 257     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 258                  ,rDC
.m_vRclPaint
.yBottom
 
 259                  ,rDC
.m_vRclPaint
.xLeft
 
 260                  ,rDC
.m_vRclPaint
.yTop
 
 262 } // end of wxBitmapButton::DrawButtonFocus 
 264 void wxBitmapButton::DrawButtonDisable( 
 269     wxPen                           
vGreyPen(wxColour(128, 128, 128), 2, wxSOLID
); 
 272     // Draw a thick black line around the outside of the button 
 274     rDC
.SetPen(vGreyPen
); 
 275     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 276                  ,rDC
.m_vRclPaint
.yTop
 
 277                  ,rDC
.m_vRclPaint
.xRight
 
 278                  ,rDC
.m_vRclPaint
.yTop
 
 280     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 281                  ,rDC
.m_vRclPaint
.yTop
 
 282                  ,rDC
.m_vRclPaint
.xRight
 
 283                  ,rDC
.m_vRclPaint
.yBottom
 
 285     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 286                  ,rDC
.m_vRclPaint
.yBottom
 
 287                  ,rDC
.m_vRclPaint
.xLeft
 
 288                  ,rDC
.m_vRclPaint
.yBottom
 
 290     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 291                  ,rDC
.m_vRclPaint
.yBottom
 
 292                  ,rDC
.m_vRclPaint
.xLeft
 
 293                  ,rDC
.m_vRclPaint
.yTop
 
 295     wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel()); 
 296 } // end of wxBitmapButton::DrawButtonDisable 
 298 void wxBitmapButton::SetDefault() 
 300     wxButton::SetDefault(); 
 303 #endif // ndef for wxUSE_BMPBUTTON