]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/bmpbuttn.cpp 
   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" 
  17 #include "wx/bmpbuttn.h" 
  22 #include "wx/os2/dcclient.h" 
  23 #include "wx/os2/private.h" 
  26 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
) 
  28 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1) 
  30 bool wxBitmapButton::Create( wxWindow
*          pParent
, 
  32                              const wxBitmap
&    rBitmap
, 
  36                              const wxValidator
& rValidator
, 
  37                              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 
== wxDefaultCoord 
&& rBitmap
.Ok()) 
  68         nWidth 
= rBitmap
.GetWidth() + 4 * m_marginX
; 
  70     if (nHeight 
== wxDefaultCoord 
&& 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( WXDRAWITEMSTRUCT
* pItem
) 
 105     PUSERBUTTON  pUser     
= (PUSERBUTTON
)pItem
; 
 106     bool         bAutoDraw 
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0; 
 112     bool       bIsSelected 
= pUser
->fsState 
& BDS_HILITED
; 
 113     wxClientDC 
vDc(this); 
 115     if (bIsSelected 
&& m_bmpSelected
.Ok()) 
 116         pBitmap 
= &m_bmpSelected
; 
 117     else if ((pUser
->fsState 
& BDS_DEFAULT
) && m_bmpFocus
.Ok()) 
 118         pBitmap 
= &m_bmpFocus
; 
 119     else if ((pUser
->fsState 
& BDS_DISABLED
) && m_bmpDisabled
.Ok()) 
 120         pBitmap 
= &m_bmpDisabled
; 
 122         pBitmap 
= &m_bmpNormal
; 
 129     // Centre the bitmap in the control area 
 133     wxPMDCImpl                      
*impl 
= (wxPMDCImpl
*) vDc
.GetImpl(); 
 134     int                             nWidth     
= impl
->m_vRclPaint
.xRight 
- impl
->m_vRclPaint
.xLeft
; 
 135     int                             nHeight    
= impl
->m_vRclPaint
.yTop 
- impl
->m_vRclPaint
.yBottom
; 
 136     int                             nBmpWidth  
= pBitmap
->GetWidth(); 
 137     int                             nBmpHeight 
= pBitmap
->GetHeight(); 
 139     nX1 
= (nWidth 
- nBmpWidth
) / 2; 
 140     nY1 
= (nHeight 
- nBmpHeight
) / 2; 
 142     if (bIsSelected 
&& bAutoDraw
) 
 149     // Draw the button face 
 151     DrawFace( vDc
, bIsSelected 
); 
 156     vDc
.DrawBitmap( *pBitmap
, nX1
, nY1
, true ); 
 159     // Draw focus / disabled state, if auto-drawing 
 161     if ((pUser
->fsState 
== BDS_DISABLED
) && bAutoDraw
) 
 163         DrawButtonDisable( vDc
, *pBitmap 
); 
 165     else if ((pUser
->fsState 
== BDS_DEFAULT
) && bAutoDraw
) 
 167         DrawButtonFocus(vDc
); 
 170 } // end of wxBitmapButton::OS2OnDraw 
 172 void wxBitmapButton::DrawFace (wxClientDC
& rDC
, bool bSel
) 
 175     // Set up drawing colors 
 177     wxPen 
vHiLitePen(*wxWHITE
, 2, wxSOLID
); // White 
 178     wxColour 
gray85(85, 85, 85); 
 179     wxPen 
vDarkShadowPen(gray85
, 2, wxSOLID
); 
 180     wxColour 
vFaceColor(204, 204, 204); // Light Grey 
 183     // Draw the main button face 
 185     // This triggers a redraw and destroys the bottom & left focus border and 
 186     // doesn't seem to do anything useful. 
 187     //    ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel()); 
 191     // Note: DrawLine expects wxWidgets coordinate system so swap 
 193     rDC
.SetPen(bSel 
? vDarkShadowPen 
: vHiLitePen
); 
 194     wxPMDCImpl                      
*impl 
= (wxPMDCImpl
*) rDC
.GetImpl(); 
 196     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft 
+ 1 
 197                  ,impl
->m_vRclPaint
.yBottom 
+ 1 
 198                  ,impl
->m_vRclPaint
.xRight 
- 1 
 199                  ,impl
->m_vRclPaint
.yBottom 
+ 1 
 202     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft 
+ 1 
 203                  ,impl
->m_vRclPaint
.yBottom 
+ 1 
 204                  ,impl
->m_vRclPaint
.xLeft 
+ 1 
 205                  ,impl
->m_vRclPaint
.yTop 
- 1 
 208     rDC
.SetPen(bSel 
? vHiLitePen 
: vDarkShadowPen
); 
 210     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft 
+ 1 
 211                  ,impl
->m_vRclPaint
.yTop 
- 1 
 212                  ,impl
->m_vRclPaint
.xRight 
- 1 
 213                  ,impl
->m_vRclPaint
.yTop 
- 1 
 216     rDC
.DrawLine( impl
->m_vRclPaint
.xRight 
- 1 
 217                  ,impl
->m_vRclPaint
.yBottom 
+ 1 
 218                  ,impl
->m_vRclPaint
.xRight 
- 1 
 219                  ,impl
->m_vRclPaint
.yTop 
- 1 
 222 } // end of wxBitmapButton::DrawFace 
 224 void wxBitmapButton::DrawButtonFocus ( 
 228     wxPen 
vBlackPen(*wxBLACK
, 2, wxSOLID
); 
 231     // Draw a thick black line around the outside of the button 
 232     // Note: DrawLine expects wxWidgets coordinate system so swap 
 234     rDC
.SetPen(vBlackPen
); 
 235     wxPMDCImpl                      
*impl 
= (wxPMDCImpl
*) rDC
.GetImpl(); 
 237     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
 
 238                  ,impl
->m_vRclPaint
.yBottom
 
 239                  ,impl
->m_vRclPaint
.xRight
 
 240                  ,impl
->m_vRclPaint
.yBottom
 
 243     rDC
.DrawLine( impl
->m_vRclPaint
.xRight
 
 244                  ,impl
->m_vRclPaint
.yBottom
 
 245                  ,impl
->m_vRclPaint
.xRight
 
 246                  ,impl
->m_vRclPaint
.yTop
 
 249     rDC
.DrawLine( impl
->m_vRclPaint
.xRight
 
 250                  ,impl
->m_vRclPaint
.yTop
 
 251                  ,impl
->m_vRclPaint
.xLeft
 
 252                  ,impl
->m_vRclPaint
.yTop
 
 255     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
 
 256                  ,impl
->m_vRclPaint
.yTop
 
 257                  ,impl
->m_vRclPaint
.xLeft
 
 258                  ,impl
->m_vRclPaint
.yBottom
 
 260 } // end of wxBitmapButton::DrawButtonFocus 
 262 void wxBitmapButton::DrawButtonDisable( wxClientDC
& rDC
, 
 265     wxPen 
vGreyPen(wxT("GREY"), 2, wxSOLID
); 
 268     // Draw a thick black line around the outside of the button 
 269     // Note: DrawLine expects wxWidgets coordinate system so swap 
 271     rDC
.SetPen(vGreyPen
); 
 272     wxPMDCImpl                      
*impl 
= (wxPMDCImpl
*) rDC
.GetImpl(); 
 274     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
 
 275                  ,impl
->m_vRclPaint
.yBottom
 
 276                  ,impl
->m_vRclPaint
.xRight
 
 277                  ,impl
->m_vRclPaint
.yBottom
 
 280     rDC
.DrawLine( impl
->m_vRclPaint
.xRight
 
 281                  ,impl
->m_vRclPaint
.yBottom
 
 282                  ,impl
->m_vRclPaint
.xRight
 
 283                  ,impl
->m_vRclPaint
.yTop
 
 286     rDC
.DrawLine( impl
->m_vRclPaint
.xRight
 
 287                  ,impl
->m_vRclPaint
.yTop
 
 288                  ,impl
->m_vRclPaint
.xLeft
 
 289                  ,impl
->m_vRclPaint
.yTop
 
 292     rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
 
 293                  ,impl
->m_vRclPaint
.yTop
 
 294                  ,impl
->m_vRclPaint
.xLeft
 
 295                  ,impl
->m_vRclPaint
.yBottom
 
 297     wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel()); 
 298 } // end of wxBitmapButton::DrawButtonDisable 
 300 #endif // ndef for wxUSE_BMPBUTTON