1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/button.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - native wxButton implementation
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/button.h"
34 #include "wx/bmpbuttn.h"
35 #include "wx/settings.h"
36 #include "wx/dcscreen.h"
38 #include "wx/dialog.h"
41 #include "wx/stockitem.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 #if wxUSE_EXTENDED_RTTI
52 WX_DEFINE_FLAGS( wxButtonStyle
)
54 wxBEGIN_FLAGS( wxButtonStyle
)
55 // new style border flags, we put them first to
56 // use them for streaming out
57 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
58 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
59 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
60 wxFLAGS_MEMBER(wxBORDER_RAISED
)
61 wxFLAGS_MEMBER(wxBORDER_STATIC
)
62 wxFLAGS_MEMBER(wxBORDER_NONE
)
64 // old style border flags
65 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
66 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
67 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
68 wxFLAGS_MEMBER(wxRAISED_BORDER
)
69 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
70 wxFLAGS_MEMBER(wxBORDER
)
72 // standard window styles
73 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
74 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
75 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
76 wxFLAGS_MEMBER(wxWANTS_CHARS
)
77 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
78 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
79 wxFLAGS_MEMBER(wxVSCROLL
)
80 wxFLAGS_MEMBER(wxHSCROLL
)
82 wxFLAGS_MEMBER(wxBU_LEFT
)
83 wxFLAGS_MEMBER(wxBU_RIGHT
)
84 wxFLAGS_MEMBER(wxBU_TOP
)
85 wxFLAGS_MEMBER(wxBU_BOTTOM
)
86 wxFLAGS_MEMBER(wxBU_EXACTFIT
)
87 wxEND_FLAGS( wxButtonStyle
)
89 IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton
, wxControl
,"wx/button.h")
91 wxBEGIN_PROPERTIES_TABLE(wxButton
)
92 wxEVENT_PROPERTY( Click
, wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
)
94 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
95 wxPROPERTY( Label
, wxString
, SetLabel
, GetLabel
, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
97 wxPROPERTY_FLAGS( WindowStyle
, wxButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99 wxEND_PROPERTIES_TABLE()
101 wxBEGIN_HANDLERS_TABLE(wxButton
)
102 wxEND_HANDLERS_TABLE()
104 wxCONSTRUCTOR_6( wxButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
108 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
111 // this macro tries to adjust the default button height to a reasonable value
112 // using the char height as the base
113 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
115 // ============================================================================
117 // ============================================================================
119 // ----------------------------------------------------------------------------
120 // creation/destruction
121 // ----------------------------------------------------------------------------
123 bool wxButton::Create(wxWindow
*parent
,
125 const wxString
& label
,
129 const wxValidator
& validator
,
130 const wxString
& name
)
132 // Default coordinates based on the knowledgebase recipe "Buttons"
133 wxSize
palmSize(size
.x
==wxDefaultCoord
?36:size
.x
,
134 size
.y
==wxDefaultCoord
?12:size
.y
);
136 // Default placement depends on dialog vs. frame type of parent
137 wxPoint
palmPos(pos
);
138 if((palmPos
.x
==wxDefaultCoord
)||(palmPos
.y
==wxDefaultCoord
))
140 wxSize
parentSize(parent
->GetClientSize());
141 wxWindow
* parentTLW
= parent
;
142 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
144 parentTLW
= parentTLW
->GetParent();
147 if(wxDynamicCast(parentTLW
, wxFrame
)!=NULL
)
149 if(palmPos
.x
==wxDefaultCoord
)
151 if(palmPos
.y
==wxDefaultCoord
)
152 palmPos
.y
= parentSize
.y
-palmSize
.y
;
154 else if(wxDynamicCast(parentTLW
, wxDialog
)!=NULL
)
156 if(palmPos
.x
==wxDefaultCoord
)
158 if(palmPos
.y
==wxDefaultCoord
)
159 palmPos
.y
= parentSize
.y
-palmSize
.y
-5;
163 // something seriously broken
168 // take the stock label
169 wxString palmLabel
= label
;
170 if( palmLabel
.empty() && wxIsStockID(id
) )
171 palmLabel
= wxGetStockLabel(id
, false);
173 if(!wxControl::Create(parent
, id
, palmPos
, palmSize
, style
, validator
, name
))
176 return wxControl::PalmCreateControl(buttonCtl
, palmLabel
, palmPos
, palmSize
);
179 wxButton::~wxButton()
183 // ----------------------------------------------------------------------------
184 // size management including autosizing
185 // ----------------------------------------------------------------------------
187 wxSize
wxButton::DoGetBestSize() const
189 return wxSize(36,12);
193 wxSize
wxButtonBase::GetDefaultSize()
195 return wxSize(36,12);
198 void wxButton::SetDefault()
200 FormType
* form
= (FormType
* )GetParentForm();
203 FrmSetDefaultButtonID(form
,GetId());
206 void wxButton::SetTmpDefault()
210 void wxButton::UnsetTmpDefault()
216 wxButton::SetDefaultStyle(wxButton
*btn
, bool on
)
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
224 bool wxButton::SendClickEvent()
226 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
227 event
.SetEventObject(this);
228 return ProcessCommand(event
);
231 void wxButton::Command(wxCommandEvent
&event
)
233 ProcessCommand(event
);
236 #endif // wxUSE_BUTTON