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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "button.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/button.h"
38 #include "wx/bmpbuttn.h"
39 #include "wx/settings.h"
40 #include "wx/dcscreen.h"
42 #include "wx/dialog.h"
45 #include "wx/stockitem.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #if wxUSE_EXTENDED_RTTI
56 WX_DEFINE_FLAGS( wxButtonStyle
)
58 wxBEGIN_FLAGS( wxButtonStyle
)
59 // new style border flags, we put them first to
60 // use them for streaming out
61 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
62 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
63 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
64 wxFLAGS_MEMBER(wxBORDER_RAISED
)
65 wxFLAGS_MEMBER(wxBORDER_STATIC
)
66 wxFLAGS_MEMBER(wxBORDER_NONE
)
68 // old style border flags
69 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
70 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
71 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
72 wxFLAGS_MEMBER(wxRAISED_BORDER
)
73 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
74 wxFLAGS_MEMBER(wxBORDER
)
76 // standard window styles
77 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
78 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
79 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
80 wxFLAGS_MEMBER(wxWANTS_CHARS
)
81 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
82 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
83 wxFLAGS_MEMBER(wxVSCROLL
)
84 wxFLAGS_MEMBER(wxHSCROLL
)
86 wxFLAGS_MEMBER(wxBU_LEFT
)
87 wxFLAGS_MEMBER(wxBU_RIGHT
)
88 wxFLAGS_MEMBER(wxBU_TOP
)
89 wxFLAGS_MEMBER(wxBU_BOTTOM
)
90 wxFLAGS_MEMBER(wxBU_EXACTFIT
)
91 wxEND_FLAGS( wxButtonStyle
)
93 IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton
, wxControl
,"wx/button.h")
95 wxBEGIN_PROPERTIES_TABLE(wxButton
)
96 wxEVENT_PROPERTY( Click
, wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
)
98 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
99 wxPROPERTY( Label
, wxString
, SetLabel
, GetLabel
, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
101 wxPROPERTY_FLAGS( WindowStyle
, wxButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
103 wxEND_PROPERTIES_TABLE()
105 wxBEGIN_HANDLERS_TABLE(wxButton
)
106 wxEND_HANDLERS_TABLE()
108 wxCONSTRUCTOR_6( wxButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
112 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
115 // this macro tries to adjust the default button height to a reasonable value
116 // using the char height as the base
117 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
119 // ============================================================================
121 // ============================================================================
123 // ----------------------------------------------------------------------------
124 // creation/destruction
125 // ----------------------------------------------------------------------------
127 bool wxButton::Create(wxWindow
*parent
,
129 const wxString
& label
,
133 const wxValidator
& validator
,
134 const wxString
& name
)
136 // Default coordinates based on the knowledgebase recipe "Buttons"
137 wxSize
palmSize(size
.x
==wxDefaultCoord
?36:size
.x
,
138 size
.y
==wxDefaultCoord
?12:size
.y
);
140 // Default placement depends on dialog vs. frame type of parent
141 wxPoint
palmPos(pos
);
142 if((palmPos
.x
==wxDefaultCoord
)||(palmPos
.y
==wxDefaultCoord
))
144 wxSize
parentSize(parent
->GetClientSize());
145 wxWindow
* parentTLW
= parent
;
146 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
148 parentTLW
= parentTLW
->GetParent();
151 if(wxDynamicCast(parentTLW
, wxFrame
)!=NULL
)
153 if(palmPos
.x
==wxDefaultCoord
)
155 if(palmPos
.y
==wxDefaultCoord
)
156 palmPos
.y
= parentSize
.y
-palmSize
.y
;
158 else if(wxDynamicCast(parentTLW
, wxDialog
)!=NULL
)
160 if(palmPos
.x
==wxDefaultCoord
)
162 if(palmPos
.y
==wxDefaultCoord
)
163 palmPos
.y
= parentSize
.y
-palmSize
.y
-5;
167 // something seriously broken
172 // take the stock label
173 wxString palmLabel
= label
;
174 if( palmLabel
.empty() && wxIsStockID(id
) )
175 palmLabel
= wxGetStockLabel(id
, false);
177 if(!wxControl::Create(parent
, id
, palmPos
, palmSize
, style
, validator
, name
))
180 return wxControl::PalmCreateControl(buttonCtl
, palmLabel
, palmPos
, palmSize
);
183 wxButton::~wxButton()
187 // ----------------------------------------------------------------------------
188 // size management including autosizing
189 // ----------------------------------------------------------------------------
191 wxSize
wxButton::DoGetBestSize() const
193 return wxSize(36,12);
197 wxSize
wxButtonBase::GetDefaultSize()
199 return wxSize(36,12);
202 void wxButton::SetDefault()
204 FormType
* form
= (FormType
* )GetParentForm();
207 FrmSetDefaultButtonID(form
,GetId());
210 void wxButton::SetTmpDefault()
214 void wxButton::UnsetTmpDefault()
220 wxButton::SetDefaultStyle(wxButton
*btn
, bool on
)
224 // ----------------------------------------------------------------------------
226 // ----------------------------------------------------------------------------
228 bool wxButton::SendClickEvent()
230 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
231 event
.SetEventObject(this);
232 return ProcessCommand(event
);
235 void wxButton::Command(wxCommandEvent
&event
)
237 ProcessCommand(event
);
240 #endif // wxUSE_BUTTON