]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/button.cpp
wxOS2/OW warning and build fixes.
[wxWidgets.git] / src / palmos / button.cpp
CommitLineData
ffecfa5a 1/////////////////////////////////////////////////////////////////////////////
e2731512 2// Name: src/palmos/button.cpp
ffecfa5a 3// Purpose: wxButton
e2731512 4// Author: William Osborne - minimal working wxPalmOS port
db101bd3 5// Modified by: Wlodzimierz ABX Skiba - native wxButton implementation
ffecfa5a 6// Created: 10/13/04
e2731512 7// RCS-ID: $Id$
db101bd3 8// Copyright: (c) William Osborne, Wlodzimierz Skiba
ffecfa5a
JS
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "button.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#if wxUSE_BUTTON
32
33#ifndef WX_PRECOMP
34 #include "wx/app.h"
35 #include "wx/button.h"
36 #include "wx/brush.h"
37 #include "wx/panel.h"
38 #include "wx/bmpbuttn.h"
39 #include "wx/settings.h"
40 #include "wx/dcscreen.h"
808e3bce
WS
41 #include "wx/frame.h"
42 #include "wx/dialog.h"
ffecfa5a
JS
43#endif
44
634629fa
WS
45#include "wx/stockitem.h"
46
20bc5ad8
WS
47#include <Control.h>
48#include <Form.h>
49
ffecfa5a
JS
50// ----------------------------------------------------------------------------
51// macros
52// ----------------------------------------------------------------------------
53
54#if wxUSE_EXTENDED_RTTI
55
56WX_DEFINE_FLAGS( wxButtonStyle )
57
58wxBEGIN_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)
4055ed82 67
ffecfa5a
JS
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)
75
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)
85
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)
91wxEND_FLAGS( wxButtonStyle )
92
93IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl,"wx/button.h")
94
95wxBEGIN_PROPERTIES_TABLE(wxButton)
96 wxEVENT_PROPERTY( Click , wxEVT_COMMAND_BUTTON_CLICKED , wxCommandEvent)
97
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") )
100
101 wxPROPERTY_FLAGS( WindowStyle , wxButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
102
103wxEND_PROPERTIES_TABLE()
104
105wxBEGIN_HANDLERS_TABLE(wxButton)
106wxEND_HANDLERS_TABLE()
107
108wxCONSTRUCTOR_6( wxButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
109
110
111#else
112IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
113#endif
114
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)
118
119// ============================================================================
120// implementation
121// ============================================================================
122
123// ----------------------------------------------------------------------------
124// creation/destruction
125// ----------------------------------------------------------------------------
126
127bool wxButton::Create(wxWindow *parent,
128 wxWindowID id,
129 const wxString& label,
130 const wxPoint& pos,
131 const wxSize& size,
132 long style,
133 const wxValidator& validator,
134 const wxString& name)
135{
808e3bce
WS
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);
139
140 // Default placement depends on dialog vs. frame type of parent
141 wxPoint palmPos(pos);
142 if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
143 {
be4e4e27 144 wxSize parentSize(parent->GetClientSize());
808e3bce
WS
145 wxWindow* parentTLW = parent;
146 while ( parentTLW && !parentTLW->IsTopLevel() )
147 {
148 parentTLW = parentTLW->GetParent();
149 }
150
151 if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
152 {
153 if(palmPos.x==wxDefaultCoord)
be4e4e27 154 palmPos.x = 0;
808e3bce
WS
155 if(palmPos.y==wxDefaultCoord)
156 palmPos.y = parentSize.y-palmSize.y;
157 }
158 else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
159 {
160 if(palmPos.x==wxDefaultCoord)
be4e4e27 161 palmPos.x = 4;
808e3bce
WS
162 if(palmPos.y==wxDefaultCoord)
163 palmPos.y = parentSize.y-palmSize.y-5;
164 }
165 else
166 {
167 // something seriously broken
168 return false;
169 }
170 }
171
172 // take the stock label
173 wxString palmLabel = label;
174 if( palmLabel.empty() && wxIsStockID(id) )
634629fa 175 palmLabel = wxGetStockLabel(id, false);
808e3bce 176
a152561c
WS
177 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
178 return false;
179
180 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
ffecfa5a
JS
181}
182
183wxButton::~wxButton()
184{
185}
186
ffecfa5a
JS
187// ----------------------------------------------------------------------------
188// size management including autosizing
189// ----------------------------------------------------------------------------
190
191wxSize wxButton::DoGetBestSize() const
192{
808e3bce 193 return wxSize(36,12);
ffecfa5a
JS
194}
195
196/* static */
197wxSize wxButtonBase::GetDefaultSize()
198{
808e3bce 199 return wxSize(36,12);
ffecfa5a
JS
200}
201
202void wxButton::SetDefault()
203{
20bc5ad8 204 FormType* form = (FormType* )GetParentForm();
ba889513
WS
205 if(form==NULL)
206 return;
207 FrmSetDefaultButtonID(form,GetId());
ffecfa5a
JS
208}
209
210void wxButton::SetTmpDefault()
211{
212}
213
214void wxButton::UnsetTmpDefault()
215{
216}
217
218/* static */
219void
220wxButton::SetDefaultStyle(wxButton *btn, bool on)
221{
222}
223
224// ----------------------------------------------------------------------------
225// helpers
226// ----------------------------------------------------------------------------
227
228bool wxButton::SendClickEvent()
229{
a152561c
WS
230 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
231 event.SetEventObject(this);
232 return ProcessCommand(event);
ffecfa5a
JS
233}
234
808e3bce 235void wxButton::Command(wxCommandEvent &event)
ffecfa5a 236{
a152561c 237 ProcessCommand(event);
ffecfa5a
JS
238}
239
ffecfa5a
JS
240#endif // wxUSE_BUTTON
241