]>
Commit | Line | Data |
---|---|---|
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 | # if defined(__VISAGECPP__) | |
37 | const wxValidator* validator, | |
38 | # else | |
39 | const wxValidator& validator, | |
40 | # endif | |
41 | #endif | |
42 | const wxString& name) | |
43 | { | |
44 | SetName(name); | |
45 | #if wxUSE_VALIDATORS | |
46 | SetValidator(validator); | |
47 | #endif | |
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 | ||
62 | wxButton::~wxButton() | |
63 | { | |
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 | |
92 | int hBtn = 0;// TODO: BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); | |
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); | |
137 | } | |
138 | ||
139 | void wxButton::SetDefault() | |
140 | { | |
141 | wxWindow *parent = GetParent(); | |
142 | wxButton *btnOldDefault = NULL; | |
143 | wxPanel *panel = wxDynamicCast(parent, wxPanel); | |
144 | if (panel) | |
145 | panel->SetDefaultItem(this); | |
146 | ||
147 | // TODO: make button the default | |
148 | } | |
149 | ||
150 | // ---------------------------------------------------------------------------- | |
151 | // event/message handlers | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | bool wxButton::OS2Command(WXUINT param, WXWORD id) | |
155 | { | |
156 | bool processed = FALSE; | |
157 | // TODO | |
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; | |
168 | } | |
169 | ||
170 | WXHBRUSH wxButton::OnCtlColor(WXHDC pDC, | |
171 | WXHWND pWnd, | |
172 | WXUINT nCtlColor, | |
173 | WXUINT message, | |
174 | WXWPARAM wParam, | |
175 | WXLPARAM lParam) | |
176 | { | |
177 | wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); | |
178 | ||
179 | return (WXHBRUSH) backgroundBrush->GetResourceHandle(); | |
180 | } | |
181 | ||
182 |