]> git.saurik.com Git - wxWidgets.git/blob - src/os2/button.cpp
[gtk] fixed bug that caused segfaults in wxYield when wxToolBar has non-button contr...
[wxWidgets.git] / src / os2 / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/button.h"
17 #include "wx/brush.h"
18 #include "wx/panel.h"
19 #include "wx/bmpbuttn.h"
20 #include "wx/settings.h"
21 #include "wx/dcscreen.h"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
28 #endif
29
30 // Button
31
32 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
33 const wxPoint& pos,
34 const wxSize& size, long style,
35 #if wxUSE_VALIDATORS
36 const wxValidator& validator,
37 #endif
38 const wxString& name)
39 {
40 SetName(name);
41 #if wxUSE_VALIDATORS
42 SetValidator(validator);
43 #endif
44 m_windowStyle = style;
45
46 parent->AddChild((wxButton *)this);
47
48 if (id == -1)
49 m_windowId = NewControlId();
50 else
51 m_windowId = id;
52
53 // TODO: create button
54
55 return FALSE;
56 }
57
58 wxButton::~wxButton()
59 {
60 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
61 if ( panel )
62 {
63 if ( panel->GetDefaultItem() == this )
64 {
65 // don't leave the panel with invalid default item
66 panel->SetDefaultItem(NULL);
67 }
68 }
69 }
70
71 // ----------------------------------------------------------------------------
72 // size management including autosizing
73 // ----------------------------------------------------------------------------
74
75 wxSize wxButton::DoGetBestSize() const
76 {
77 wxString label = wxGetWindowText(GetHWND());
78 int wBtn;
79 GetTextExtent(label, &wBtn, NULL);
80
81 int wChar, hChar;
82 wxGetCharSize(GetHWND(), &wChar, &hChar, (wxFont*)&GetFont());
83
84 // add a margin - the button is wider than just its label
85 wBtn += 3*wChar;
86
87 // the button height is proportional to the height of the font used
88 int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
89
90 return wxSize(wBtn, hBtn);
91 }
92
93 /* static */
94 wxSize wxButton::GetDefaultSize()
95 {
96 static wxSize s_sizeBtn;
97
98 if ( s_sizeBtn.x == 0 )
99 {
100 wxScreenDC dc;
101 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
102
103 // the size of a standard button in the dialog units is 50x14,
104 // translate this to pixels
105 // NB1: the multipliers come from the Windows convention
106 // NB2: the extra +1/+2 were needed to get the size be the same as the
107 // size of the buttons in the standard dialog - I don't know how
108 // this happens, but on my system this size is 75x23 in pixels and
109 // 23*8 isn't even divisible by 14... Would be nice to understand
110 // why these constants are needed though!
111 s_sizeBtn.x = (50 * (dc.GetCharWidth() + 1))/4;
112 s_sizeBtn.y = ((14 * dc.GetCharHeight()) + 2)/8;
113 }
114
115 return s_sizeBtn;
116 }
117
118 void wxButton::Command (wxCommandEvent & event)
119 {
120 ProcessCommand (event);
121 }
122
123 // ----------------------------------------------------------------------------
124 // helpers
125 // ----------------------------------------------------------------------------
126
127 bool wxButton::SendClickEvent()
128 {
129 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
130 event.SetEventObject(this);
131
132 return ProcessCommand(event);
133 }
134
135 void wxButton::SetDefault()
136 {
137 wxWindow *parent = GetParent();
138 wxButton *btnOldDefault = NULL;
139 wxPanel *panel = wxDynamicCast(parent, wxPanel);
140 if (panel)
141 panel->SetDefaultItem(this);
142
143 // TODO: make button the default
144 }
145
146 // ----------------------------------------------------------------------------
147 // event/message handlers
148 // ----------------------------------------------------------------------------
149
150 bool wxButton::OS2Command(WXUINT param, WXWORD id)
151 {
152 bool processed = FALSE;
153 // TODO
154 /*
155 switch ( param )
156 {
157 case 1: // 1 for accelerator
158 case BN_CLICKED:
159 processed = SendClickEvent();
160 break;
161 }
162 */
163 return processed;
164 }
165
166 WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
167 WXHWND pWnd,
168 WXUINT nCtlColor,
169 WXUINT message,
170 WXWPARAM wParam,
171 WXLPARAM lParam)
172 {
173 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
174
175 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
176 }
177
178