]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/button.cpp
Italian translation corrections from Roberto Boriotti.
[wxWidgets.git] / src / palmos / button.cpp
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 // 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)
54
55 // ============================================================================
56 // implementation
57 // ============================================================================
58
59 // ----------------------------------------------------------------------------
60 // creation/destruction
61 // ----------------------------------------------------------------------------
62
63 bool wxButton::Create(wxWindow *parent,
64 wxWindowID id,
65 const wxString& label,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxValidator& validator,
70 const wxString& name)
71 {
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);
75
76 // Default placement depends on dialog vs. frame type of parent
77 wxPoint palmPos(pos);
78 if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
79 {
80 wxSize parentSize(parent->GetClientSize());
81 wxWindow* parentTLW = parent;
82 while ( parentTLW && !parentTLW->IsTopLevel() )
83 {
84 parentTLW = parentTLW->GetParent();
85 }
86
87 if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
88 {
89 if(palmPos.x==wxDefaultCoord)
90 palmPos.x = 0;
91 if(palmPos.y==wxDefaultCoord)
92 palmPos.y = parentSize.y-palmSize.y;
93 }
94 else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
95 {
96 if(palmPos.x==wxDefaultCoord)
97 palmPos.x = 4;
98 if(palmPos.y==wxDefaultCoord)
99 palmPos.y = parentSize.y-palmSize.y-5;
100 }
101 else
102 {
103 // something seriously broken
104 return false;
105 }
106 }
107
108 // take the stock label
109 wxString palmLabel = label;
110 if( palmLabel.empty() && wxIsStockID(id) )
111 palmLabel = wxGetStockLabel(id, wxSTOCK_NOFLAGS);
112
113 if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
114 return false;
115
116 return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize);
117 }
118
119 wxButton::~wxButton()
120 {
121 }
122
123 // ----------------------------------------------------------------------------
124 // size management including autosizing
125 // ----------------------------------------------------------------------------
126
127 wxSize wxButton::DoGetBestSize() const
128 {
129 return wxSize(36,12);
130 }
131
132 /* static */
133 wxSize wxButtonBase::GetDefaultSize()
134 {
135 return wxSize(36,12);
136 }
137
138 wxWindow *wxButton::SetDefault()
139 {
140 FormType* form = (FormType* )GetParentForm();
141 if(form==NULL)
142 return NULL;
143 #ifdef __WXPALMOS6__
144 FrmSetDefaultButtonID(form,GetId());
145 #endif // __WXPALMOS6__
146
147 return wxButtonBase::SetDefault();
148 }
149
150 void wxButton::SetTmpDefault()
151 {
152 }
153
154 void wxButton::UnsetTmpDefault()
155 {
156 }
157
158 /* static */
159 void
160 wxButton::SetDefaultStyle(wxButton *btn, bool on)
161 {
162 }
163
164 // ----------------------------------------------------------------------------
165 // helpers
166 // ----------------------------------------------------------------------------
167
168 bool wxButton::SendClickEvent()
169 {
170 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
171 event.SetEventObject(this);
172 return ProcessCommand(event);
173 }
174
175 void wxButton::Command(wxCommandEvent &event)
176 {
177 ProcessCommand(event);
178 }
179
180 #endif // wxUSE_BUTTON