]>
Commit | Line | Data |
---|---|---|
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 | |
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, | |
5d4b632b DW |
35 | #if wxUSE_VALIDATORS |
36 | # if defined(__VISAGECPP__) | |
37 | const wxValidator* validator, | |
38 | # else | |
0e320a79 | 39 | const wxValidator& validator, |
5d4b632b DW |
40 | # endif |
41 | #endif | |
0e320a79 DW |
42 | const wxString& name) |
43 | { | |
44 | SetName(name); | |
5d4b632b | 45 | #if wxUSE_VALIDATORS |
0e320a79 | 46 | SetValidator(validator); |
5d4b632b | 47 | #endif |
0e320a79 DW |
48 | m_windowStyle = style; |
49 | ||
50 | parent->AddChild((wxButton *)this); | |
51 | ||
52 | if (id == -1) | |
53 | m_windowId = NewControlId(); | |
54 | else | |
55 | m_windowId = id; | |
56 | ||
57 | // TODO: create button | |
58 | ||
59 | return FALSE; | |
60 | } | |
61 | ||
d88de032 | 62 | wxButton::~wxButton() |
0e320a79 | 63 | { |
d88de032 DW |
64 | wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); |
65 | if ( panel ) | |
66 | { | |
67 | if ( panel->GetDefaultItem() == this ) | |
68 | { | |
69 | // don't leave the panel with invalid default item | |
70 | panel->SetDefaultItem(NULL); | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | // ---------------------------------------------------------------------------- | |
76 | // size management including autosizing | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | wxSize wxButton::DoGetBestSize() | |
80 | { | |
81 | wxString label = wxGetWindowText(GetHWND()); | |
82 | int wBtn; | |
83 | GetTextExtent(label, &wBtn, NULL); | |
84 | ||
85 | int wChar, hChar; | |
86 | wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont()); | |
87 | ||
88 | // add a margin - the button is wider than just its label | |
89 | wBtn += 3*wChar; | |
90 | ||
91 | // the button height is proportional to the height of the font used | |
37f214d5 | 92 | int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); |
d88de032 DW |
93 | |
94 | return wxSize(wBtn, hBtn); | |
95 | } | |
96 | ||
97 | /* static */ | |
98 | wxSize wxButton::GetDefaultSize() | |
99 | { | |
100 | static wxSize s_sizeBtn; | |
101 | ||
102 | if ( s_sizeBtn.x == 0 ) | |
103 | { | |
104 | wxScreenDC dc; | |
105 | dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
106 | ||
107 | // the size of a standard button in the dialog units is 50x14, | |
108 | // translate this to pixels | |
109 | // NB1: the multipliers come from the Windows convention | |
110 | // NB2: the extra +1/+2 were needed to get the size be the same as the | |
111 | // size of the buttons in the standard dialog - I don't know how | |
112 | // this happens, but on my system this size is 75x23 in pixels and | |
113 | // 23*8 isn't even divisible by 14... Would be nice to understand | |
114 | // why these constants are needed though! | |
115 | s_sizeBtn.x = (50 * (dc.GetCharWidth() + 1))/4; | |
116 | s_sizeBtn.y = ((14 * dc.GetCharHeight()) + 2)/8; | |
117 | } | |
118 | ||
119 | return s_sizeBtn; | |
120 | } | |
121 | ||
122 | void wxButton::Command (wxCommandEvent & event) | |
123 | { | |
124 | ProcessCommand (event); | |
125 | } | |
126 | ||
127 | // ---------------------------------------------------------------------------- | |
128 | // helpers | |
129 | // ---------------------------------------------------------------------------- | |
130 | ||
131 | bool wxButton::SendClickEvent() | |
132 | { | |
133 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); | |
134 | event.SetEventObject(this); | |
135 | ||
136 | return ProcessCommand(event); | |
0e320a79 DW |
137 | } |
138 | ||
139 | void wxButton::SetDefault() | |
140 | { | |
63415778 DW |
141 | wxWindow *parent = GetParent(); |
142 | wxButton *btnOldDefault = NULL; | |
143 | wxPanel *panel = wxDynamicCast(parent, wxPanel); | |
144 | if (panel) | |
145 | panel->SetDefaultItem(this); | |
0e320a79 DW |
146 | |
147 | // TODO: make button the default | |
148 | } | |
149 | ||
d88de032 DW |
150 | // ---------------------------------------------------------------------------- |
151 | // event/message handlers | |
152 | // ---------------------------------------------------------------------------- | |
0e320a79 | 153 | |
d88de032 | 154 | bool wxButton::OS2Command(WXUINT param, WXWORD id) |
0e320a79 | 155 | { |
d88de032 | 156 | bool processed = FALSE; |
0e320a79 | 157 | // TODO |
d88de032 DW |
158 | /* |
159 | switch ( param ) | |
160 | { | |
161 | case 1: // 1 for accelerator | |
162 | case BN_CLICKED: | |
163 | processed = SendClickEvent(); | |
164 | break; | |
165 | } | |
166 | */ | |
167 | return processed; | |
0e320a79 DW |
168 | } |
169 | ||
d88de032 DW |
170 | WXHBRUSH wxButton::OnCtlColor(WXHDC pDC, |
171 | WXHWND pWnd, | |
172 | WXUINT nCtlColor, | |
173 | WXUINT message, | |
174 | WXWPARAM wParam, | |
175 | WXLPARAM lParam) | |
0e320a79 | 176 | { |
d88de032 DW |
177 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); |
178 | ||
179 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
0e320a79 DW |
180 | } |
181 | ||
d88de032 | 182 |