]> git.saurik.com Git - wxWidgets.git/blob - src/os2/button.cpp
Renamed XRC project files
[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 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
27
28 // Button
29
30 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 #if wxUSE_VALIDATORS
34 const wxValidator& validator,
35 #endif
36 const wxString& name)
37 {
38 SetName(name);
39 #if wxUSE_VALIDATORS
40 SetValidator(validator);
41 #endif
42 m_windowStyle = style;
43
44 parent->AddChild((wxButton *)this);
45
46 if (id == -1)
47 m_windowId = NewControlId();
48 else
49 m_windowId = id;
50
51 // TODO: create button
52
53 return FALSE;
54 }
55
56 wxButton::~wxButton()
57 {
58 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
59 if ( panel )
60 {
61 if ( panel->GetDefaultItem() == this )
62 {
63 // don't leave the panel with invalid default item
64 panel->SetDefaultItem(NULL);
65 }
66 }
67 }
68
69 // ----------------------------------------------------------------------------
70 // size management including autosizing
71 // ----------------------------------------------------------------------------
72
73 wxSize wxButton::DoGetBestSize() const
74 {
75 wxString label = wxGetWindowText(GetHWND());
76 int wBtn;
77 GetTextExtent(label, &wBtn, NULL);
78
79 int wChar, hChar;
80 wxGetCharSize(GetHWND(), &wChar, &hChar, (wxFont*)&GetFont());
81
82 // add a margin - the button is wider than just its label
83 wBtn += 3*wChar;
84
85 // the button height is proportional to the height of the font used
86 int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
87
88 return wxSize(wBtn, hBtn);
89 }
90
91 /* static */
92 wxSize wxButton::GetDefaultSize()
93 {
94 static wxSize s_sizeBtn;
95
96 if ( s_sizeBtn.x == 0 )
97 {
98 wxScreenDC dc;
99 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
100
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;
111 }
112
113 return s_sizeBtn;
114 }
115
116 void wxButton::Command (wxCommandEvent & event)
117 {
118 ProcessCommand (event);
119 }
120
121 // ----------------------------------------------------------------------------
122 // helpers
123 // ----------------------------------------------------------------------------
124
125 bool wxButton::SendClickEvent()
126 {
127 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
128 event.SetEventObject(this);
129
130 return ProcessCommand(event);
131 }
132
133 void wxButton::SetDefault()
134 {
135 wxWindow *parent = GetParent();
136 wxButton *btnOldDefault = NULL;
137 wxPanel *panel = wxDynamicCast(parent, wxPanel);
138 if (panel)
139 panel->SetDefaultItem(this);
140
141 // TODO: make button the default
142 }
143
144 // ----------------------------------------------------------------------------
145 // event/message handlers
146 // ----------------------------------------------------------------------------
147
148 bool wxButton::OS2Command(WXUINT param, WXWORD id)
149 {
150 bool processed = FALSE;
151 // TODO
152 /*
153 switch ( param )
154 {
155 case 1: // 1 for accelerator
156 case BN_CLICKED:
157 processed = SendClickEvent();
158 break;
159 }
160 */
161 return processed;
162 }
163
164 WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
165 WXHWND pWnd,
166 WXUINT nCtlColor,
167 WXUINT message,
168 WXWPARAM wParam,
169 WXLPARAM lParam)
170 {
171 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
172
173 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
174 }
175
176