]>
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( wxWindow
*          pParent
, 
  30                              const wxBitmap
&    rBitmap
, 
  34                              const wxValidator
& rValidator
, 
  35                              const wxString
&    rsName 
) 
  37     m_bmpNormal 
= rBitmap
; 
  40     SetValidator(rValidator
); 
  43     pParent
->AddChild(this); 
  45     m_backgroundColour 
= pParent
->GetBackgroundColour() ; 
  46     m_foregroundColour 
= pParent
->GetForegroundColour() ; 
  47     m_windowStyle 
= lStyle
; 
  49     if (lStyle 
& wxBU_AUTODRAW
) 
  51         m_marginX 
= wxDEFAULT_BUTTON_MARGIN
; 
  52         m_marginY 
= wxDEFAULT_BUTTON_MARGIN
; 
  58     int                             nHeight 
= rSize
.y
; 
  61         m_windowId 
= NewControlId(); 
  65     if (nWidth 
== -1 && rBitmap
.Ok()) 
  66         nWidth 
= rBitmap
.GetWidth() + 4 * m_marginX
; 
  68     if (nHeight 
== -1 && rBitmap
.Ok()) 
  69         nHeight 
= rBitmap
.GetHeight() + 4 * m_marginY
; 
  71     ULONG                           ulOS2Style 
= WS_VISIBLE 
| WS_TABSTOP 
| BS_USERBUTTON
; 
  73     if (m_windowStyle 
& wxCLIP_SIBLINGS
) 
  74         ulOS2Style 
|= WS_CLIPSIBLINGS
; 
  76     m_hWnd 
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
) 
  89     //Subclass again for purposes of dialog editing mode 
  92     SetFont(*wxSMALL_FONT
); 
  99 } // end of wxBitmapButton::Create 
 101 bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT
* pItem
) 
 103     PUSERBUTTON                     pUser     
= (PUSERBUTTON
)pItem
; 
 104     bool                            bAutoDraw 
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0; 
 110     bool                            bIsSelected 
= pUser
->fsState 
& BDS_HILITED
; 
 111     wxClientDC                      
vDc(this); 
 113     if (bIsSelected 
&& m_bmpSelected
.Ok()) 
 114         pBitmap 
= &m_bmpSelected
; 
 115     else if ((pUser
->fsState 
& BDS_DEFAULT
) && m_bmpFocus
.Ok()) 
 116         pBitmap 
= &m_bmpFocus
; 
 117     else if ((pUser
->fsState 
& BDS_DISABLED
) && m_bmpDisabled
.Ok()) 
 118         pBitmap 
= &m_bmpDisabled
; 
 120         pBitmap 
= &m_bmpNormal
; 
 127     // Centre the bitmap in the control area 
 132     int                             nWidth     
= vDc
.m_vRclPaint
.xRight 
- vDc
.m_vRclPaint
.xLeft
; 
 133     int                             nHeight    
= vDc
.m_vRclPaint
.xRight 
- vDc
.m_vRclPaint
.xLeft
; 
 134     int                             nBmpWidth  
= pBitmap
->GetWidth(); 
 135     int                             nBmpHeight 
= pBitmap
->GetHeight(); 
 137     nX1 
= nX 
+ (nWidth 
- nBmpWidth
) / 2; 
 138     nY1 
= nX 
+ (nHeight 
- nBmpHeight
) / 2; 
 140     if (bIsSelected 
&& bAutoDraw
) 
 147     // Draw the button face 
 158     vDc
.DrawBitmap( *pBitmap
, nX1
, nY1
, true ); 
 161     // Draw focus / disabled state, if auto-drawing 
 163     if ((pUser
->fsState 
== BDS_DISABLED
) && bAutoDraw
) 
 165         DrawButtonDisable( vDc
 
 169     else if ((pUser
->fsState 
== BDS_DEFAULT
) && bAutoDraw
) 
 171         DrawButtonFocus(vDc
); 
 174 } // end of wxBitmapButton::OS2OnDraw 
 176 void wxBitmapButton::DrawFace (wxClientDC
& rDC
, bool bSel
) 
 179     // Set up drawing colors 
 181     wxPen 
vHiLitePen(*wxWHITE
, 2, wxSOLID
); // White 
 182     wxColour 
gray85(85, 85, 85); 
 183     wxPen 
vDarkShadowPen(gray85
, 2, wxSOLID
); 
 184     wxColour 
vFaceColor(204, 204, 204); // Light Grey 
 187     // Draw the main button face 
 189     ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel()); 
 194     rDC
.SetPen(bSel 
? vDarkShadowPen 
: vHiLitePen
); 
 195     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 196                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 197                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 198                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 200     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 201                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 202                  ,rDC
.m_vRclPaint
.xLeft 
+ 1 
 203                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 206     rDC
.SetPen(bSel 
? vHiLitePen 
: vDarkShadowPen
); 
 207     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft 
+ 1 
 208                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 209                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 210                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 212     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight 
- 1 
 213                  ,rDC
.m_vRclPaint
.yTop 
- 1 
 214                  ,rDC
.m_vRclPaint
.xRight 
- 1 
 215                  ,rDC
.m_vRclPaint
.yBottom 
+ 1 
 218 } // end of wxBitmapButton::DrawFace 
 220 void wxBitmapButton::DrawButtonFocus ( 
 224     wxPen 
vBlackPen(*wxBLACK
, 2, wxSOLID
); 
 227     // Draw a thick black line around the outside of the button 
 229     rDC
.SetPen(vBlackPen
); 
 230     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 231                  ,rDC
.m_vRclPaint
.yTop
 
 232                  ,rDC
.m_vRclPaint
.xRight
 
 233                  ,rDC
.m_vRclPaint
.yTop
 
 235     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 236                  ,rDC
.m_vRclPaint
.yTop
 
 237                  ,rDC
.m_vRclPaint
.xRight
 
 238                  ,rDC
.m_vRclPaint
.yBottom
 
 240     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 241                  ,rDC
.m_vRclPaint
.yBottom
 
 242                  ,rDC
.m_vRclPaint
.xLeft
 
 243                  ,rDC
.m_vRclPaint
.yBottom
 
 245     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 246                  ,rDC
.m_vRclPaint
.yBottom
 
 247                  ,rDC
.m_vRclPaint
.xLeft
 
 248                  ,rDC
.m_vRclPaint
.yTop
 
 250 } // end of wxBitmapButton::DrawButtonFocus 
 252 void wxBitmapButton::DrawButtonDisable( wxClientDC
& rDC
, 
 255     wxPen 
vGreyPen(wxT("GREY"), 2, wxSOLID
); 
 258     // Draw a thick black line around the outside of the button 
 260     rDC
.SetPen(vGreyPen
); 
 261     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 262                  ,rDC
.m_vRclPaint
.yTop
 
 263                  ,rDC
.m_vRclPaint
.xRight
 
 264                  ,rDC
.m_vRclPaint
.yTop
 
 266     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 267                  ,rDC
.m_vRclPaint
.yTop
 
 268                  ,rDC
.m_vRclPaint
.xRight
 
 269                  ,rDC
.m_vRclPaint
.yBottom
 
 271     rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
 
 272                  ,rDC
.m_vRclPaint
.yBottom
 
 273                  ,rDC
.m_vRclPaint
.xLeft
 
 274                  ,rDC
.m_vRclPaint
.yBottom
 
 276     rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
 
 277                  ,rDC
.m_vRclPaint
.yBottom
 
 278                  ,rDC
.m_vRclPaint
.xLeft
 
 279                  ,rDC
.m_vRclPaint
.yTop
 
 281     wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel()); 
 282 } // end of wxBitmapButton::DrawButtonDisable 
 284 void wxBitmapButton::SetDefault() 
 286     wxButton::SetDefault(); 
 289 #endif // ndef for wxUSE_BMPBUTTON