]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/button.cpp
Fix after removal of PRIOR/NEXT in common headers (duplicates change in GTK2 sources).
[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
ffecfa5a
JS
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#ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/button.h"
32 #include "wx/brush.h"
33 #include "wx/panel.h"
34 #include "wx/bmpbuttn.h"
35 #include "wx/settings.h"
36 #include "wx/dcscreen.h"
808e3bce
WS
37 #include "wx/frame.h"
38 #include "wx/dialog.h"
ffecfa5a
JS
39#endif
40
634629fa
WS
41#include "wx/stockitem.h"
42
20bc5ad8
WS
43#include <Control.h>
44#include <Form.h>
45
ffecfa5a
JS
46// ----------------------------------------------------------------------------
47// macros
48// ----------------------------------------------------------------------------
49
50#if wxUSE_EXTENDED_RTTI
51
52WX_DEFINE_FLAGS( wxButtonStyle )
53
54wxBEGIN_FLAGS( wxButtonStyle )
55 // new style border flags, we put them first to
56 // use them for streaming out
57 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
58 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
59 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
60 wxFLAGS_MEMBER(wxBORDER_RAISED)
61 wxFLAGS_MEMBER(wxBORDER_STATIC)
62 wxFLAGS_MEMBER(wxBORDER_NONE)
4055ed82 63
ffecfa5a
JS
64 // old style border flags
65 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
66 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
67 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
68 wxFLAGS_MEMBER(wxRAISED_BORDER)
69 wxFLAGS_MEMBER(wxSTATIC_BORDER)
70 wxFLAGS_MEMBER(wxBORDER)
71
72 // standard window styles
73 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
74 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
75 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
76 wxFLAGS_MEMBER(wxWANTS_CHARS)
77 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
78 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
79 wxFLAGS_MEMBER(wxVSCROLL)
80 wxFLAGS_MEMBER(wxHSCROLL)
81
82 wxFLAGS_MEMBER(wxBU_LEFT)
83 wxFLAGS_MEMBER(wxBU_RIGHT)
84 wxFLAGS_MEMBER(wxBU_TOP)
85 wxFLAGS_MEMBER(wxBU_BOTTOM)
86 wxFLAGS_MEMBER(wxBU_EXACTFIT)
87wxEND_FLAGS( wxButtonStyle )
88
89IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl,"wx/button.h")
90
91wxBEGIN_PROPERTIES_TABLE(wxButton)
92 wxEVENT_PROPERTY( Click , wxEVT_COMMAND_BUTTON_CLICKED , wxCommandEvent)
93
94 wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
95 wxPROPERTY( Label, wxString , SetLabel, GetLabel, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
96
97 wxPROPERTY_FLAGS( WindowStyle , wxButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
98
99wxEND_PROPERTIES_TABLE()
100
101wxBEGIN_HANDLERS_TABLE(wxButton)
102wxEND_HANDLERS_TABLE()
103
104wxCONSTRUCTOR_6( wxButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
105
106
107#else
108IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
109#endif
110
111// this macro tries to adjust the default button height to a reasonable value
112// using the char height as the base
113#define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
114
115// ============================================================================
116// implementation
117// ============================================================================
118
119// ----------------------------------------------------------------------------
120// creation/destruction
121// ----------------------------------------------------------------------------
122
123bool wxButton::Create(wxWindow *parent,
124 wxWindowID id,
125 const wxString& label,
126 const wxPoint& pos,
127 const wxSize& size,
128 long style,
129 const wxValidator& validator,
130 const wxString& name)
131{
808e3bce
WS
132 // Default coordinates based on the knowledgebase recipe "Buttons"
133 wxSize palmSize(size.x==wxDefaultCoord?36:size.x,
134 size.y==wxDefaultCoord?12:size.y);
135
136 // Default placement depends on dialog vs. frame type of parent
137 wxPoint palmPos(pos);
138 if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
139 {
be4e4e27 140 wxSize parentSize(parent->GetClientSize());
808e3bce
WS
141 wxWindow* parentTLW = parent;
142 while ( parentTLW && !parentTLW->IsTopLevel() )
143 {
144 parentTLW = parentTLW->GetParent();
145 }
146
147 if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
148 {
149 if(palmPos.x==wxDefaultCoord)
be4e4e27 150 palmPos.x = 0;
808e3bce
WS
151 if(palmPos.y==wxDefaultCoord)
152 palmPos.y = parentSize.y-palmSize.y;
153 }
154 else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
155 {
156 if(palmPos.x==wxDefaultCoord)
be4e4e27 157 palmPos.x = 4;
808e3bce
WS
158 if(palmPos.y==wxDefaultCoord)
159 palmPos.y = parentSize.y-palmSize.y-5;
160 }
161 else
162 {
163 // something seriously broken
164 return false;
165 }
166 }
167
168 // take the stock label
169 wxString palmLabel = label;
170 if( palmLabel.empty() && wxIsStockID(id) )
634629fa 171 palmLabel = wxGetStockLabel(id, false);
808e3bce 172
a152561c
WS
173 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
174 return false;
175
176 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
ffecfa5a
JS
177}
178
179wxButton::~wxButton()
180{
181}
182
ffecfa5a
JS
183// ----------------------------------------------------------------------------
184// size management including autosizing
185// ----------------------------------------------------------------------------
186
187wxSize wxButton::DoGetBestSize() const
188{
808e3bce 189 return wxSize(36,12);
ffecfa5a
JS
190}
191
192/* static */
193wxSize wxButtonBase::GetDefaultSize()
194{
808e3bce 195 return wxSize(36,12);
ffecfa5a
JS
196}
197
198void wxButton::SetDefault()
199{
20bc5ad8 200 FormType* form = (FormType* )GetParentForm();
ba889513
WS
201 if(form==NULL)
202 return;
203 FrmSetDefaultButtonID(form,GetId());
ffecfa5a
JS
204}
205
206void wxButton::SetTmpDefault()
207{
208}
209
210void wxButton::UnsetTmpDefault()
211{
212}
213
214/* static */
215void
216wxButton::SetDefaultStyle(wxButton *btn, bool on)
217{
218}
219
220// ----------------------------------------------------------------------------
221// helpers
222// ----------------------------------------------------------------------------
223
224bool wxButton::SendClickEvent()
225{
a152561c
WS
226 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
227 event.SetEventObject(this);
228 return ProcessCommand(event);
ffecfa5a
JS
229}
230
808e3bce 231void wxButton::Command(wxCommandEvent &event)
ffecfa5a 232{
a152561c 233 ProcessCommand(event);
ffecfa5a
JS
234}
235
ffecfa5a
JS
236#endif // wxUSE_BUTTON
237