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 // this macro tries to adjust the default button height to a reasonable value
52 // using the char height as the base
53 #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
55 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
60 // creation/destruction
61 // ----------------------------------------------------------------------------
63 bool wxButton::Create(wxWindow
*parent
,
65 const wxString
& label
,
69 const wxValidator
& validator
,
72 // Default coordinates based on the knowledgebase recipe "Buttons"
73 wxSize
palmSize(size
.x
==wxDefaultCoord
?36:size
.x
,
74 size
.y
==wxDefaultCoord
?12:size
.y
);
76 // Default placement depends on dialog vs. frame type of parent
78 if((palmPos
.x
==wxDefaultCoord
)||(palmPos
.y
==wxDefaultCoord
))
80 wxSize
parentSize(parent
->GetClientSize());
81 wxWindow
* parentTLW
= parent
;
82 while ( parentTLW
&& !parentTLW
->IsTopLevel() )
84 parentTLW
= parentTLW
->GetParent();
87 if(wxDynamicCast(parentTLW
, wxFrame
)!=NULL
)
89 if(palmPos
.x
==wxDefaultCoord
)
91 if(palmPos
.y
==wxDefaultCoord
)
92 palmPos
.y
= parentSize
.y
-palmSize
.y
;
94 else if(wxDynamicCast(parentTLW
, wxDialog
)!=NULL
)
96 if(palmPos
.x
==wxDefaultCoord
)
98 if(palmPos
.y
==wxDefaultCoord
)
99 palmPos
.y
= parentSize
.y
-palmSize
.y
-5;
103 // something seriously broken
108 // take the stock label
109 wxString palmLabel
= label
;
110 if( palmLabel
.empty() && wxIsStockID(id
) )
111 palmLabel
= wxGetStockLabel(id
, wxSTOCK_NOFLAGS
);
113 if(!wxControl::Create(parent
, id
, palmPos
, palmSize
, style
, validator
, name
))
116 return wxControl::PalmCreateControl(buttonCtl
, palmLabel
, palmPos
, palmSize
);
119 wxButton::~wxButton()
123 // ----------------------------------------------------------------------------
124 // size management including autosizing
125 // ----------------------------------------------------------------------------
127 wxSize
wxButton::DoGetBestSize() const
129 return wxSize(36,12);
133 wxSize
wxButtonBase::GetDefaultSize()
135 return wxSize(36,12);
138 wxWindow
*wxButton::SetDefault()
140 FormType
* form
= (FormType
* )GetParentForm();
144 FrmSetDefaultButtonID(form
,GetId());
145 #endif // __WXPALMOS6__
147 return wxButtonBase::SetDefault();
150 void wxButton::SetTmpDefault()
154 void wxButton::UnsetTmpDefault()
160 wxButton::SetDefaultStyle(wxButton
*btn
, bool on
)
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 bool wxButton::SendClickEvent()
170 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
171 event
.SetEventObject(this);
172 return ProcessCommand(event
);
175 void wxButton::Command(wxCommandEvent
&event
)
177 ProcessCommand(event
);
180 #endif // wxUSE_BUTTON