]> git.saurik.com Git - wxWidgets.git/blame - src/os2/button.cpp
fixed return value of HandleEndSession to return true only if the message was really...
[wxWidgets.git] / src / os2 / button.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose: wxButton
d88de032 4// Author: David Webster
0e320a79 5// Modified by:
d88de032 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
d88de032
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d88de032
DW
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"
0e320a79
DW
22#endif
23
d88de032 24#include "wx/os2/private.h"
0e320a79 25
0e320a79 26IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
0e320a79
DW
27
28// Button
29
30bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
31 const wxPoint& pos,
32 const wxSize& size, long style,
5d4b632b 33#if wxUSE_VALIDATORS
0e320a79 34 const wxValidator& validator,
5d4b632b 35#endif
0e320a79
DW
36 const wxString& name)
37{
38 SetName(name);
5d4b632b 39#if wxUSE_VALIDATORS
0e320a79 40 SetValidator(validator);
5d4b632b 41#endif
0e320a79
DW
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
d88de032 56wxButton::~wxButton()
0e320a79 57{
d88de032
DW
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
e78c4d50 73wxSize wxButton::DoGetBestSize() const
d88de032
DW
74{
75 wxString label = wxGetWindowText(GetHWND());
76 int wBtn;
77 GetTextExtent(label, &wBtn, NULL);
78
79 int wChar, hChar;
e78c4d50 80 wxGetCharSize(GetHWND(), &wChar, &hChar, (wxFont*)&GetFont());
d88de032
DW
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
37f214d5 86 int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
d88de032
DW
87
88 return wxSize(wBtn, hBtn);
89}
90
91/* static */
92wxSize 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
116void wxButton::Command (wxCommandEvent & event)
117{
118 ProcessCommand (event);
119}
120
121// ----------------------------------------------------------------------------
122// helpers
123// ----------------------------------------------------------------------------
124
125bool wxButton::SendClickEvent()
126{
127 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
128 event.SetEventObject(this);
129
130 return ProcessCommand(event);
0e320a79
DW
131}
132
133void wxButton::SetDefault()
134{
63415778
DW
135 wxWindow *parent = GetParent();
136 wxButton *btnOldDefault = NULL;
137 wxPanel *panel = wxDynamicCast(parent, wxPanel);
138 if (panel)
139 panel->SetDefaultItem(this);
0e320a79
DW
140
141 // TODO: make button the default
142}
143
d88de032
DW
144// ----------------------------------------------------------------------------
145// event/message handlers
146// ----------------------------------------------------------------------------
0e320a79 147
d88de032 148bool wxButton::OS2Command(WXUINT param, WXWORD id)
0e320a79 149{
d88de032 150 bool processed = FALSE;
0e320a79 151 // TODO
d88de032
DW
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;
0e320a79
DW
162}
163
d88de032
DW
164WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
165 WXHWND pWnd,
166 WXUINT nCtlColor,
167 WXUINT message,
168 WXWPARAM wParam,
169 WXLPARAM lParam)
0e320a79 170{
d88de032
DW
171 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
172
173 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
0e320a79
DW
174}
175
d88de032 176