]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/button.cpp
reSWIGged
[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
ffecfa5a
JS
47// ----------------------------------------------------------------------------
48// macros
49// ----------------------------------------------------------------------------
50
51#if wxUSE_EXTENDED_RTTI
52
53WX_DEFINE_FLAGS( wxButtonStyle )
54
55wxBEGIN_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)
4055ed82 64
ffecfa5a
JS
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)
72
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)
82
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)
88wxEND_FLAGS( wxButtonStyle )
89
90IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl,"wx/button.h")
91
92wxBEGIN_PROPERTIES_TABLE(wxButton)
93 wxEVENT_PROPERTY( Click , wxEVT_COMMAND_BUTTON_CLICKED , wxCommandEvent)
94
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") )
97
98 wxPROPERTY_FLAGS( WindowStyle , wxButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
99
100wxEND_PROPERTIES_TABLE()
101
102wxBEGIN_HANDLERS_TABLE(wxButton)
103wxEND_HANDLERS_TABLE()
104
105wxCONSTRUCTOR_6( wxButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
106
107
108#else
109IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
110#endif
111
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)
115
116// ============================================================================
117// implementation
118// ============================================================================
119
120// ----------------------------------------------------------------------------
121// creation/destruction
122// ----------------------------------------------------------------------------
123
124bool wxButton::Create(wxWindow *parent,
125 wxWindowID id,
126 const wxString& label,
127 const wxPoint& pos,
128 const wxSize& size,
129 long style,
130 const wxValidator& validator,
131 const wxString& name)
132{
808e3bce
WS
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);
136
137 // Default placement depends on dialog vs. frame type of parent
138 wxPoint palmPos(pos);
139 if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
140 {
be4e4e27 141 wxSize parentSize(parent->GetClientSize());
808e3bce
WS
142 wxWindow* parentTLW = parent;
143 while ( parentTLW && !parentTLW->IsTopLevel() )
144 {
145 parentTLW = parentTLW->GetParent();
146 }
147
148 if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
149 {
150 if(palmPos.x==wxDefaultCoord)
be4e4e27 151 palmPos.x = 0;
808e3bce
WS
152 if(palmPos.y==wxDefaultCoord)
153 palmPos.y = parentSize.y-palmSize.y;
154 }
155 else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
156 {
157 if(palmPos.x==wxDefaultCoord)
be4e4e27 158 palmPos.x = 4;
808e3bce
WS
159 if(palmPos.y==wxDefaultCoord)
160 palmPos.y = parentSize.y-palmSize.y-5;
161 }
162 else
163 {
164 // something seriously broken
165 return false;
166 }
167 }
168
169 // take the stock label
170 wxString palmLabel = label;
171 if( palmLabel.empty() && wxIsStockID(id) )
634629fa 172 palmLabel = wxGetStockLabel(id, false);
808e3bce 173
a152561c
WS
174 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
175 return false;
176
177 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
ffecfa5a
JS
178}
179
180wxButton::~wxButton()
181{
182}
183
ffecfa5a
JS
184// ----------------------------------------------------------------------------
185// size management including autosizing
186// ----------------------------------------------------------------------------
187
188wxSize wxButton::DoGetBestSize() const
189{
808e3bce 190 return wxSize(36,12);
ffecfa5a
JS
191}
192
193/* static */
194wxSize wxButtonBase::GetDefaultSize()
195{
808e3bce 196 return wxSize(36,12);
ffecfa5a
JS
197}
198
199void wxButton::SetDefault()
200{
ba889513
WS
201 FormType* form = GetParentForm();
202 if(form==NULL)
203 return;
204 FrmSetDefaultButtonID(form,GetId());
ffecfa5a
JS
205}
206
207void wxButton::SetTmpDefault()
208{
209}
210
211void wxButton::UnsetTmpDefault()
212{
213}
214
215/* static */
216void
217wxButton::SetDefaultStyle(wxButton *btn, bool on)
218{
219}
220
221// ----------------------------------------------------------------------------
222// helpers
223// ----------------------------------------------------------------------------
224
225bool wxButton::SendClickEvent()
226{
a152561c
WS
227 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
228 event.SetEventObject(this);
229 return ProcessCommand(event);
ffecfa5a
JS
230}
231
808e3bce 232void wxButton::Command(wxCommandEvent &event)
ffecfa5a 233{
a152561c 234 ProcessCommand(event);
ffecfa5a
JS
235}
236
ffecfa5a
JS
237#endif // wxUSE_BUTTON
238