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