]> git.saurik.com Git - wxWidgets.git/blame - src/os2/button.cpp
debug check for infinite loop in InitializeClasses() added
[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
DW
25
26#if !USE_SHARED_LIBRARY
27IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
28#endif
29
30// Button
31
32bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
33 const wxPoint& pos,
34 const wxSize& size, long style,
5d4b632b 35#if wxUSE_VALIDATORS
0e320a79 36 const wxValidator& validator,
5d4b632b 37#endif
0e320a79
DW
38 const wxString& name)
39{
40 SetName(name);
5d4b632b 41#if wxUSE_VALIDATORS
0e320a79 42 SetValidator(validator);
5d4b632b 43#endif
0e320a79
DW
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
d88de032 58wxButton::~wxButton()
0e320a79 59{
d88de032
DW
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
e78c4d50 75wxSize wxButton::DoGetBestSize() const
d88de032
DW
76{
77 wxString label = wxGetWindowText(GetHWND());
78 int wBtn;
79 GetTextExtent(label, &wBtn, NULL);
80
81 int wChar, hChar;
e78c4d50 82 wxGetCharSize(GetHWND(), &wChar, &hChar, (wxFont*)&GetFont());
d88de032
DW
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
37f214d5 88 int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
d88de032
DW
89
90 return wxSize(wBtn, hBtn);
91}
92
93/* static */
94wxSize 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
118void wxButton::Command (wxCommandEvent & event)
119{
120 ProcessCommand (event);
121}
122
123// ----------------------------------------------------------------------------
124// helpers
125// ----------------------------------------------------------------------------
126
127bool wxButton::SendClickEvent()
128{
129 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
130 event.SetEventObject(this);
131
132 return ProcessCommand(event);
0e320a79
DW
133}
134
135void wxButton::SetDefault()
136{
63415778
DW
137 wxWindow *parent = GetParent();
138 wxButton *btnOldDefault = NULL;
139 wxPanel *panel = wxDynamicCast(parent, wxPanel);
140 if (panel)
141 panel->SetDefaultItem(this);
0e320a79
DW
142
143 // TODO: make button the default
144}
145
d88de032
DW
146// ----------------------------------------------------------------------------
147// event/message handlers
148// ----------------------------------------------------------------------------
0e320a79 149
d88de032 150bool wxButton::OS2Command(WXUINT param, WXWORD id)
0e320a79 151{
d88de032 152 bool processed = FALSE;
0e320a79 153 // TODO
d88de032
DW
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;
0e320a79
DW
164}
165
d88de032
DW
166WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
167 WXHWND pWnd,
168 WXUINT nCtlColor,
169 WXUINT message,
170 WXWPARAM wParam,
171 WXLPARAM lParam)
0e320a79 172{
d88de032
DW
173 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
174
175 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
0e320a79
DW
176}
177
d88de032 178