]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/palmos/button.cpp
mac paths updated
[wxWidgets.git] / src / palmos / button.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/palmos/button.cpp
3// Purpose: wxButton
4// Author: William Osborne - minimal working wxPalmOS port
5// Modified by: Wlodzimierz ABX Skiba - native wxButton implementation
6// Created: 10/13/04
7// RCS-ID: $Id$
8// Copyright: (c) William Osborne, Wlodzimierz Skiba
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_BUTTON
28
29#include "wx/button.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/brush.h"
34 #include "wx/panel.h"
35 #include "wx/bmpbuttn.h"
36 #include "wx/settings.h"
37 #include "wx/dcscreen.h"
38 #include "wx/frame.h"
39 #include "wx/dialog.h"
40#endif
41
42#include "wx/stockitem.h"
43
44#include <Control.h>
45#include <Form.h>
46
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)
64
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{
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 {
141 wxSize parentSize(parent->GetClientSize());
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)
151 palmPos.x = 0;
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)
158 palmPos.x = 4;
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) )
172 palmLabel = wxGetStockLabel(id, wxSTOCK_NOFLAGS);
173
174 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
175 return false;
176
177 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
178}
179
180wxButton::~wxButton()
181{
182}
183
184// ----------------------------------------------------------------------------
185// size management including autosizing
186// ----------------------------------------------------------------------------
187
188wxSize wxButton::DoGetBestSize() const
189{
190 return wxSize(36,12);
191}
192
193/* static */
194wxSize wxButtonBase::GetDefaultSize()
195{
196 return wxSize(36,12);
197}
198
199wxWindow *wxButton::SetDefault()
200{
201 FormType* form = (FormType* )GetParentForm();
202 if(form==NULL)
203 return NULL;
204#ifdef __WXPALMOS6__
205 FrmSetDefaultButtonID(form,GetId());
206#endif // __WXPALMOS6__
207
208 return wxButtonBase::SetDefault();
209}
210
211void wxButton::SetTmpDefault()
212{
213}
214
215void wxButton::UnsetTmpDefault()
216{
217}
218
219/* static */
220void
221wxButton::SetDefaultStyle(wxButton *btn, bool on)
222{
223}
224
225// ----------------------------------------------------------------------------
226// helpers
227// ----------------------------------------------------------------------------
228
229bool wxButton::SendClickEvent()
230{
231 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
232 event.SetEventObject(this);
233 return ProcessCommand(event);
234}
235
236void wxButton::Command(wxCommandEvent &event)
237{
238 ProcessCommand(event);
239}
240
241#endif // wxUSE_BUTTON