1 ///////////////////////////////////////////////////////////////////////////// 
   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" 
  16     #include "wx/button.h" 
  19     #include "wx/bmpbuttn.h" 
  20     #include "wx/settings.h" 
  21     #include "wx/dcscreen.h" 
  24 #include "wx/os2/private.h" 
  26 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
) 
  30 bool wxButton::Create(wxWindow 
*parent
, wxWindowID id
, const wxString
& label
, 
  32            const wxSize
& size
, long style
, 
  34            const wxValidator
& validator
, 
  40     SetValidator(validator
); 
  42     m_windowStyle 
= style
; 
  44     parent
->AddChild((wxButton 
*)this); 
  47         m_windowId 
= NewControlId(); 
  51     // TODO: create button 
  58     wxPanel 
*panel 
= wxDynamicCast(GetParent(), wxPanel
); 
  61         if ( panel
->GetDefaultItem() == this ) 
  63             // don't leave the panel with invalid default item 
  64             panel
->SetDefaultItem(NULL
); 
  69 // ---------------------------------------------------------------------------- 
  70 // size management including autosizing 
  71 // ---------------------------------------------------------------------------- 
  73 wxSize 
wxButton::DoGetBestSize() const 
  75     wxString label 
= wxGetWindowText(GetHWND()); 
  77     GetTextExtent(label
, &wBtn
, NULL
); 
  80     wxGetCharSize(GetHWND(), &wChar
, &hChar
, (wxFont
*)&GetFont()); 
  82     // add a margin - the button is wider than just its label 
  85     // the button height is proportional to the height of the font used 
  86     int hBtn 
= 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); 
  88     return wxSize(wBtn
, hBtn
); 
  92 wxSize 
wxButton::GetDefaultSize() 
  94     static wxSize s_sizeBtn
; 
  96     if ( s_sizeBtn
.x 
== 0 ) 
  99         dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
)); 
 101         // the size of a standard button in the dialog units is 50x14, 
 102         // translate this to pixels 
 103         // NB1: the multipliers come from the Windows convention 
 104         // NB2: the extra +1/+2 were needed to get the size be the same as the 
 105         //      size of the buttons in the standard dialog - I don't know how 
 106         //      this happens, but on my system this size is 75x23 in pixels and 
 107         //      23*8 isn't even divisible by 14... Would be nice to understand 
 108         //      why these constants are needed though! 
 109         s_sizeBtn
.x 
= (50 * (dc
.GetCharWidth() + 1))/4; 
 110         s_sizeBtn
.y 
= ((14 * dc
.GetCharHeight()) + 2)/8; 
 116 void wxButton::Command (wxCommandEvent 
& event
) 
 118     ProcessCommand (event
); 
 121 // ---------------------------------------------------------------------------- 
 123 // ---------------------------------------------------------------------------- 
 125 bool wxButton::SendClickEvent() 
 127     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId()); 
 128     event
.SetEventObject(this); 
 130     return ProcessCommand(event
); 
 133 void wxButton::SetDefault() 
 135     wxWindow 
*parent 
= GetParent(); 
 136     wxButton 
*btnOldDefault 
= NULL
; 
 137     wxPanel 
*panel 
= wxDynamicCast(parent
, wxPanel
); 
 139         panel
->SetDefaultItem(this); 
 141     // TODO: make button the default 
 144 // ---------------------------------------------------------------------------- 
 145 // event/message handlers 
 146 // ---------------------------------------------------------------------------- 
 148 bool wxButton::OS2Command(WXUINT param
, WXWORD id
) 
 150     bool processed 
= FALSE
; 
 155         case 1:                                             // 1 for accelerator 
 157             processed = SendClickEvent(); 
 164 WXHBRUSH 
wxButton::OnCtlColor(WXHDC pDC
, 
 171   wxBrush 
*backgroundBrush 
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
); 
 173   return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();