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"
29 #include "wx/button.h"
35 #include "wx/bmpbuttn.h"
36 #include "wx/settings.h"
37 #include "wx/dcscreen.h"
39 #include "wx/dialog.h"
42 #include "wx/stockitem.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 #if wxUSE_EXTENDED_RTTI
53 WX_DEFINE_FLAGS( wxButtonStyle
)
55 wxBEGIN_FLAGS( wxButtonStyle
)
56 // new style border flags, we put them first to
57 // use them for streaming out
58 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
59 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
60 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
61 wxFLAGS_MEMBER(wxBORDER_RAISED
)
62 wxFLAGS_MEMBER(wxBORDER_STATIC
)
63 wxFLAGS_MEMBER(wxBORDER_NONE
)
65 // old style border flags
66 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
67 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
68 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
69 wxFLAGS_MEMBER(wxRAISED_BORDER
)
70 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
71 wxFLAGS_MEMBER(wxBORDER
)
73 // standard window styles
74 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
75 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
76 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
77 wxFLAGS_MEMBER(wxWANTS_CHARS
)
78 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
79 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
80 wxFLAGS_MEMBER(wxVSCROLL
)
81 wxFLAGS_MEMBER(wxHSCROLL
)
83 wxFLAGS_MEMBER(wxBU_LEFT
)
84 wxFLAGS_MEMBER(wxBU_RIGHT
)
85 wxFLAGS_MEMBER(wxBU_TOP
)
86 wxFLAGS_MEMBER(wxBU_BOTTOM
)
87 wxFLAGS_MEMBER(wxBU_EXACTFIT
)
88 wxEND_FLAGS( wxButtonStyle
)
90 IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton
, wxControl
,"wx/button.h")
92 wxBEGIN_PROPERTIES_TABLE(wxButton
)
93 wxEVENT_PROPERTY( Click
, wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
)
95 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
96 wxPROPERTY( Label
, wxString
, SetLabel
, GetLabel
, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
98 wxPROPERTY_FLAGS( WindowStyle
, wxButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
100 wxEND_PROPERTIES_TABLE()
102 wxBEGIN_HANDLERS_TABLE(wxButton
)
103 wxEND_HANDLERS_TABLE()
105 wxCONSTRUCTOR_6( wxButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
109 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
112 // this macro tries to adjust the default button height to a reasonable value
113 // using the char height as the base
114 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
116 // ============================================================================
118 // ============================================================================
120 // ----------------------------------------------------------------------------
121 // creation/destruction
122 // ----------------------------------------------------------------------------
124 bool wxButton::Create(wxWindow
*parent
,
126 const wxString
& label
,
130 const wxValidator
& validator
,
131 const wxString
& name
)
133 // Default coordinates based on the knowledgebase recipe "Buttons"
134 wxSize
palmSize(size
.x
==wxDefaultCoord
?36:size
.x
,
135 size
.y
==wxDefaultCoord
?12:size
.y
);
137 // Default placement depends on dialog vs. frame type of parent
138 wxPoint
palmPos(pos
);
139 if((palmPos
.x
==wxDefaultCoord
)||(palmPos
.y
==wxDefaultCoord
))
141 wxSize
parentSize(parent
->GetClientSize());
142 wxWindow
* parentTLW
= parent
;
143 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
145 parentTLW
= parentTLW
->GetParent();
148 if(wxDynamicCast(parentTLW
, wxFrame
)!=NULL
)
150 if(palmPos
.x
==wxDefaultCoord
)
152 if(palmPos
.y
==wxDefaultCoord
)
153 palmPos
.y
= parentSize
.y
-palmSize
.y
;
155 else if(wxDynamicCast(parentTLW
, wxDialog
)!=NULL
)
157 if(palmPos
.x
==wxDefaultCoord
)
159 if(palmPos
.y
==wxDefaultCoord
)
160 palmPos
.y
= parentSize
.y
-palmSize
.y
-5;
164 // something seriously broken
169 // take the stock label
170 wxString palmLabel
= label
;
171 if( palmLabel
.empty() && wxIsStockID(id
) )
172 palmLabel
= wxGetStockLabel(id
, false);
174 if(!wxControl::Create(parent
, id
, palmPos
, palmSize
, style
, validator
, name
))
177 return wxControl::PalmCreateControl(buttonCtl
, palmLabel
, palmPos
, palmSize
);
180 wxButton::~wxButton()
184 // ----------------------------------------------------------------------------
185 // size management including autosizing
186 // ----------------------------------------------------------------------------
188 wxSize
wxButton::DoGetBestSize() const
190 return wxSize(36,12);
194 wxSize
wxButtonBase::GetDefaultSize()
196 return wxSize(36,12);
199 void wxButton::SetDefault()
201 FormType
* form
= (FormType
* )GetParentForm();
204 FrmSetDefaultButtonID(form
,GetId());
207 void wxButton::SetTmpDefault()
211 void wxButton::UnsetTmpDefault()
217 wxButton::SetDefaultStyle(wxButton
*btn
, bool on
)
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
225 bool wxButton::SendClickEvent()
227 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
228 event
.SetEventObject(this);
229 return ProcessCommand(event
);
232 void wxButton::Command(wxCommandEvent
&event
)
234 ProcessCommand(event
);
237 #endif // wxUSE_BUTTON