]>
Commit | Line | Data |
---|---|---|
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 | ||
f1e01716 WS |
29 | #include "wx/button.h" |
30 | ||
ffecfa5a JS |
31 | #ifndef WX_PRECOMP |
32 | #include "wx/app.h" | |
ffecfa5a JS |
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" | |
808e3bce WS |
38 | #include "wx/frame.h" |
39 | #include "wx/dialog.h" | |
ffecfa5a JS |
40 | #endif |
41 | ||
634629fa WS |
42 | #include "wx/stockitem.h" |
43 | ||
20bc5ad8 WS |
44 | #include <Control.h> |
45 | #include <Form.h> | |
46 | ||
ffecfa5a JS |
47 | // ---------------------------------------------------------------------------- |
48 | // macros | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
ffecfa5a JS |
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 | { | |
808e3bce WS |
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 | { | |
be4e4e27 | 80 | wxSize parentSize(parent->GetClientSize()); |
808e3bce WS |
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) | |
be4e4e27 | 90 | palmPos.x = 0; |
808e3bce WS |
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) | |
be4e4e27 | 97 | palmPos.x = 4; |
808e3bce WS |
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) ) | |
ee0a94cf | 111 | palmLabel = wxGetStockLabel(id, wxSTOCK_NOFLAGS); |
808e3bce | 112 | |
a152561c WS |
113 | if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name)) |
114 | return false; | |
115 | ||
116 | return wxControl::PalmCreateControl(buttonCtl, palmLabel, palmPos, palmSize); | |
ffecfa5a JS |
117 | } |
118 | ||
119 | wxButton::~wxButton() | |
120 | { | |
121 | } | |
122 | ||
ffecfa5a JS |
123 | // ---------------------------------------------------------------------------- |
124 | // size management including autosizing | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
127 | wxSize wxButton::DoGetBestSize() const | |
128 | { | |
808e3bce | 129 | return wxSize(36,12); |
ffecfa5a JS |
130 | } |
131 | ||
132 | /* static */ | |
133 | wxSize wxButtonBase::GetDefaultSize() | |
134 | { | |
808e3bce | 135 | return wxSize(36,12); |
ffecfa5a JS |
136 | } |
137 | ||
94aff5ff | 138 | wxWindow *wxButton::SetDefault() |
ffecfa5a | 139 | { |
20bc5ad8 | 140 | FormType* form = (FormType* )GetParentForm(); |
ba889513 | 141 | if(form==NULL) |
e2fc40b4 | 142 | return NULL; |
6afc1b46 | 143 | #ifdef __WXPALMOS6__ |
ba889513 | 144 | FrmSetDefaultButtonID(form,GetId()); |
6afc1b46 | 145 | #endif // __WXPALMOS6__ |
94aff5ff VZ |
146 | |
147 | return wxButtonBase::SetDefault(); | |
ffecfa5a JS |
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 | { | |
a152561c WS |
170 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); |
171 | event.SetEventObject(this); | |
172 | return ProcessCommand(event); | |
ffecfa5a JS |
173 | } |
174 | ||
808e3bce | 175 | void wxButton::Command(wxCommandEvent &event) |
ffecfa5a | 176 | { |
a152561c | 177 | ProcessCommand(event); |
ffecfa5a JS |
178 | } |
179 | ||
ffecfa5a | 180 | #endif // wxUSE_BUTTON |