]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
89ebf1c9 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
d8c736e5 GD |
16 | #include "wx/defs.h" |
17 | ||
e9576ca5 | 18 | #include "wx/control.h" |
03e11df5 GD |
19 | #include "wx/panel.h" |
20 | #include "wx/app.h" | |
5fde6fcc | 21 | #include "wx/dc.h" |
456c94e1 | 22 | #include "wx/dcclient.h" |
519cb848 SC |
23 | #include "wx/notebook.h" |
24 | #include "wx/tabctrl.h" | |
2f1ae414 | 25 | #include "wx/radiobox.h" |
519cb848 | 26 | #include "wx/spinbutt.h" |
03e11df5 GD |
27 | #include "wx/scrolbar.h" |
28 | #include "wx/button.h" | |
29 | #include "wx/dialog.h" | |
30 | #include "wx/statbox.h" | |
31 | #include "wx/sizer.h" | |
32 | #include "wx/stattext.h" | |
e9576ca5 | 33 | |
2f1ae414 | 34 | #if !USE_SHARED_LIBRARY |
8208e181 | 35 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) |
e9576ca5 | 36 | |
2f1ae414 | 37 | BEGIN_EVENT_TABLE(wxControl, wxWindow) |
89ebf1c9 | 38 | EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) |
ca453266 | 39 | // EVT_CHAR( wxControl::OnKeyDown ) |
89ebf1c9 | 40 | EVT_PAINT( wxControl::OnPaint ) |
e9576ca5 | 41 | END_EVENT_TABLE() |
2f1ae414 | 42 | #endif |
e9576ca5 | 43 | |
d497dca4 | 44 | #include "wx/mac/uma.h" |
7372fd0a | 45 | #include "wx/mac/private.h" |
519cb848 | 46 | |
e9576ca5 | 47 | // Item members |
519cb848 | 48 | |
17a2c5a1 SC |
49 | |
50 | #if PRAGMA_STRUCT_ALIGN | |
51 | #pragma options align=mac68k | |
52 | #elif PRAGMA_STRUCT_PACKPUSH | |
53 | #pragma pack(push, 2) | |
54 | #elif PRAGMA_STRUCT_PACK | |
55 | #pragma pack(2) | |
56 | #endif | |
57 | ||
58 | typedef struct { | |
59 | unsigned short instruction; | |
60 | void (*function)(); | |
61 | } cdefRec, *cdefPtr, **cdefHandle; | |
62 | ||
63 | #if PRAGMA_STRUCT_ALIGN | |
64 | #pragma options align=reset | |
65 | #elif PRAGMA_STRUCT_PACKPUSH | |
66 | #pragma pack(pop) | |
67 | #elif PRAGMA_STRUCT_PACK | |
68 | #pragma pack() | |
69 | #endif | |
70 | ||
519cb848 | 71 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; |
17a2c5a1 | 72 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ; |
519cb848 | 73 | |
2f1ae414 | 74 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; |
519cb848 SC |
75 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) |
76 | { | |
89ebf1c9 RR |
77 | if ( partCode != 0) |
78 | { | |
79 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
80 | if ( wx ) | |
81 | { | |
82 | wx->MacHandleControlClick( control , partCode ) ; | |
83 | } | |
84 | } | |
519cb848 SC |
85 | } |
86 | ||
692f921a | 87 | ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; |
17a2c5a1 SC |
88 | ControlDefUPP wxMacControlActionUPP = NULL ; |
89 | ||
eb22f2a6 | 90 | pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param) |
17a2c5a1 SC |
91 | { |
92 | ||
93 | wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ; | |
94 | if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) | |
95 | { | |
96 | if( message == drawCntl ) | |
97 | { | |
98 | wxMacWindowClipper clip( wx ) ; | |
99 | return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; | |
100 | } | |
101 | else | |
102 | return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; | |
103 | } | |
104 | return NULL ; | |
105 | } | |
692f921a SC |
106 | |
107 | pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) | |
108 | { | |
109 | OSStatus status = noErr ; | |
110 | switch( iMessage ) | |
111 | { | |
112 | case kControlMsgSetUpBackground : | |
692f921a | 113 | { |
f03c50fa SC |
114 | wxControl* wx = (wxControl*) GetControlReference( iControl ) ; |
115 | if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) | |
116 | { | |
117 | wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ; | |
64820d33 SC |
118 | #if TARGET_CARBON |
119 | // under classic this would lead to partial redraws | |
120 | RgnHandle clip = NewRgn() ; | |
121 | int x = 0 , y = 0; | |
122 | ||
123 | wx->MacWindowToRootWindow( &x,&y ) ; | |
124 | CopyRgn( (RgnHandle) wx->MacGetVisibleRegion(false).GetWXHRGN() , clip ) ; | |
125 | OffsetRgn( clip , x , y ) ; | |
126 | SetClip( clip ) ; | |
127 | DisposeRgn( clip ) ; | |
128 | #endif | |
f03c50fa SC |
129 | } |
130 | else | |
131 | { | |
132 | status = paramErr ; | |
133 | } | |
692f921a SC |
134 | } |
135 | break ; | |
136 | default : | |
137 | status = paramErr ; | |
138 | break ; | |
139 | } | |
140 | return status ; | |
141 | } | |
142 | ||
e9576ca5 SC |
143 | wxControl::wxControl() |
144 | { | |
89ebf1c9 | 145 | m_macControl = NULL ; |
17a2c5a1 | 146 | m_macControlAction = NULL ; |
89ebf1c9 RR |
147 | m_macHorizontalBorder = 0 ; // additional pixels around the real control |
148 | m_macVerticalBorder = 0 ; | |
e9576ca5 SC |
149 | m_backgroundColour = *wxWHITE; |
150 | m_foregroundColour = *wxBLACK; | |
e7549107 SC |
151 | #if WXWIN_COMPATIBILITY |
152 | m_callback = 0; | |
153 | #endif // WXWIN_COMPATIBILITY | |
519cb848 | 154 | |
89ebf1c9 RR |
155 | if ( wxMacLiveScrollbarActionUPP == NULL ) |
156 | { | |
4114d0af | 157 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
158 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); |
159 | #else | |
89ebf1c9 | 160 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; |
03e11df5 | 161 | #endif |
89ebf1c9 | 162 | } |
e9576ca5 SC |
163 | } |
164 | ||
2f1ae414 SC |
165 | bool wxControl::Create(wxWindow *parent, wxWindowID id, |
166 | const wxPoint& pos, | |
167 | const wxSize& size, long style, | |
168 | const wxValidator& validator, | |
169 | const wxString& name) | |
170 | { | |
89ebf1c9 RR |
171 | m_macControl = NULL ; |
172 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
173 | m_macVerticalBorder = 0 ; | |
327788ac | 174 | |
2f1ae414 | 175 | bool rval = wxWindow::Create(parent, id, pos, size, style, name); |
327788ac SC |
176 | if ( parent ) |
177 | { | |
178 | m_backgroundColour = parent->GetBackgroundColour() ; | |
179 | m_foregroundColour = parent->GetForegroundColour() ; | |
180 | } | |
2f1ae414 SC |
181 | if (rval) { |
182 | #if wxUSE_VALIDATORS | |
183 | SetValidator(validator); | |
184 | #endif | |
185 | } | |
186 | return rval; | |
187 | } | |
188 | ||
e9576ca5 SC |
189 | wxControl::~wxControl() |
190 | { | |
e7549107 | 191 | m_isBeingDeleted = TRUE; |
17a2c5a1 | 192 | wxRemoveMacControlAssociation( this ) ; |
e9576ca5 SC |
193 | // If we delete an item, we should initialize the parent panel, |
194 | // because it could now be invalid. | |
9c641c05 SC |
195 | wxWindow *parent = GetParent() ; |
196 | if ( parent ) | |
e9576ca5 | 197 | { |
9c641c05 SC |
198 | if (parent->GetDefaultItem() == (wxButton*) this) |
199 | parent->SetDefaultItem(NULL); | |
e9576ca5 | 200 | } |
76a5e5d2 | 201 | if ( (ControlHandle) m_macControl ) |
519cb848 | 202 | { |
76a5e5d2 | 203 | ::DisposeControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 204 | m_macControl = NULL ; |
519cb848 | 205 | } |
e9576ca5 SC |
206 | } |
207 | ||
e7549107 | 208 | void wxControl::SetLabel(const wxString& title) |
e9576ca5 | 209 | { |
28c98a77 | 210 | m_label = wxStripMenuCodes(title) ; |
89ebf1c9 | 211 | |
76a5e5d2 | 212 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
213 | { |
214 | Str255 maclabel ; | |
215 | wxString label ; | |
216 | ||
217 | if( wxApp::s_macDefaultEncodingIsPC ) | |
28c98a77 | 218 | label = wxMacMakeMacStringFromPC( m_label ) ; |
89ebf1c9 | 219 | else |
28c98a77 | 220 | label = m_label ; |
89ebf1c9 | 221 | |
03e11df5 | 222 | #if TARGET_CARBON |
89ebf1c9 | 223 | c2pstrcpy( (StringPtr) maclabel , label ) ; |
03e11df5 | 224 | #else |
89ebf1c9 RR |
225 | strcpy( (char *) maclabel , label ) ; |
226 | c2pstr( (char *) maclabel ) ; | |
03e11df5 | 227 | #endif |
76a5e5d2 | 228 | ::SetControlTitle( (ControlHandle) m_macControl , maclabel ) ; |
89ebf1c9 RR |
229 | } |
230 | Refresh() ; | |
e9576ca5 SC |
231 | } |
232 | ||
37e2cb08 | 233 | wxSize wxControl::DoGetBestSize() const |
e9576ca5 | 234 | { |
89ebf1c9 RR |
235 | Rect bestsize = { 0 , 0 , 0 , 0 } ; |
236 | short baselineoffset ; | |
237 | int bestWidth, bestHeight ; | |
76a5e5d2 | 238 | ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; |
89ebf1c9 RR |
239 | |
240 | if ( EmptyRect( &bestsize ) ) | |
241 | { | |
242 | baselineoffset = 0; | |
243 | bestsize.left = bestsize.top = 0 ; | |
244 | bestsize.right = 16 ; | |
245 | bestsize.bottom = 16 ; | |
246 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
247 | { | |
248 | bestsize.bottom = 16 ; | |
249 | } | |
250 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
251 | { | |
252 | bestsize.bottom = 24 ; | |
253 | } | |
254 | } | |
255 | ||
256 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
257 | { | |
258 | bestWidth = m_label.Length() * 8 + 12 ; | |
259 | if ( bestWidth < 70 ) | |
260 | bestWidth = 70 ; | |
261 | } | |
262 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
263 | { | |
264 | bestWidth = m_label.Length() * 8 ; | |
265 | } | |
266 | else | |
267 | bestWidth = bestsize.right - bestsize.left ; | |
268 | ||
269 | bestWidth += 2 * m_macHorizontalBorder ; | |
270 | ||
271 | bestHeight = bestsize.bottom - bestsize.top ; | |
272 | if ( bestHeight < 10 ) | |
273 | bestHeight = 13 ; | |
274 | ||
275 | bestHeight += 2 * m_macVerticalBorder; | |
276 | ||
277 | ||
9453cf2b | 278 | return wxSize(bestWidth, bestHeight); |
e9576ca5 SC |
279 | } |
280 | ||
e7549107 | 281 | bool wxControl::ProcessCommand (wxCommandEvent & event) |
e9576ca5 SC |
282 | { |
283 | // Tries: | |
284 | // 1) A callback function (to become obsolete) | |
285 | // 2) OnCommand, starting at this window and working up parent hierarchy | |
286 | // 3) OnCommand then calls ProcessEvent to search the event tables. | |
e7549107 SC |
287 | #if WXWIN_COMPATIBILITY |
288 | if ( m_callback ) | |
e9576ca5 | 289 | { |
e7549107 SC |
290 | (void)(*m_callback)(this, event); |
291 | ||
292 | return TRUE; | |
e9576ca5 SC |
293 | } |
294 | else | |
e7549107 | 295 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 296 | { |
e7549107 | 297 | return GetEventHandler()->ProcessEvent(event); |
e9576ca5 SC |
298 | } |
299 | } | |
300 | ||
519cb848 SC |
301 | // ------------------------ |
302 | wxList *wxWinMacControlList = NULL; | |
303 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) | |
304 | { | |
305 | wxNode *node = wxWinMacControlList->Find((long)inControl); | |
306 | if (!node) | |
307 | return NULL; | |
eb22f2a6 | 308 | return (wxControl *)node->GetData(); |
519cb848 SC |
309 | } |
310 | ||
311 | void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) | |
312 | { | |
313 | // adding NULL WindowRef is (first) surely a result of an error and | |
314 | // (secondly) breaks menu command processing | |
315 | wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" ); | |
316 | ||
317 | if ( !wxWinMacControlList->Find((long)inControl) ) | |
318 | wxWinMacControlList->Append((long)inControl, control); | |
319 | } | |
320 | ||
321 | void wxRemoveMacControlAssociation(wxControl *control) | |
322 | { | |
323 | wxWinMacControlList->DeleteObject(control); | |
324 | } | |
325 | ||
326 | void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , | |
89ebf1c9 RR |
327 | const wxPoint& pos, |
328 | const wxSize& size, long style, | |
329 | const wxValidator& validator, | |
76a5e5d2 | 330 | const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) |
519cb848 | 331 | { |
89ebf1c9 | 332 | m_label = label ; |
519cb848 SC |
333 | SetName(name); |
334 | if ( &validator ) | |
89ebf1c9 | 335 | SetValidator(validator); |
519cb848 SC |
336 | |
337 | m_windowStyle = style; | |
9453cf2b | 338 | parent->AddChild(this); |
519cb848 SC |
339 | |
340 | m_backgroundColour = parent->GetBackgroundColour() ; | |
341 | m_foregroundColour = parent->GetForegroundColour() ; | |
342 | ||
343 | if (id == -1) | |
344 | m_windowId = NewControlId(); | |
345 | else | |
346 | m_windowId = id; | |
347 | ||
9453cf2b SC |
348 | // These sizes will be adjusted in MacPostControlCreate |
349 | ||
89ebf1c9 RR |
350 | m_width = size.x ; |
351 | m_height = size.y ; | |
352 | m_x = pos.x ; | |
353 | m_y = pos.y ; | |
354 | ||
76a5e5d2 SC |
355 | ((Rect*)outBounds)->top = -10; |
356 | ((Rect*)outBounds)->left = -10; | |
357 | ((Rect*)outBounds)->bottom = 0; | |
358 | ((Rect*)outBounds)->right = 0; | |
89ebf1c9 RR |
359 | |
360 | char c_text[255]; | |
361 | strcpy( c_text , label ) ; | |
362 | if( wxApp::s_macDefaultEncodingIsPC ) | |
363 | { | |
364 | wxMacConvertFromPCForControls( c_text ) ; | |
365 | } | |
519cb848 | 366 | |
03e11df5 | 367 | #if TARGET_CARBON |
89ebf1c9 | 368 | c2pstrcpy( (StringPtr) maclabel , c_text ) ; |
03e11df5 | 369 | #else |
89ebf1c9 RR |
370 | strcpy( (char *) maclabel , c_text ) ; |
371 | c2pstr( (char *) maclabel ) ; | |
03e11df5 | 372 | #endif |
519cb848 SC |
373 | } |
374 | ||
375 | void wxControl::MacPostControlCreate() | |
376 | { | |
76a5e5d2 | 377 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ; |
89ebf1c9 RR |
378 | |
379 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
380 | { | |
381 | // no font | |
382 | } | |
2d9d0118 | 383 | else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) ) |
89ebf1c9 RR |
384 | { |
385 | ControlFontStyleRec controlstyle ; | |
386 | controlstyle.flags = kControlUseFontMask ; | |
387 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
388 | ||
76a5e5d2 | 389 | ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; |
89ebf1c9 RR |
390 | } |
391 | else | |
392 | { | |
393 | ControlFontStyleRec controlstyle ; | |
394 | controlstyle.flags = kControlUseFontMask ; | |
395 | controlstyle.font = kControlFontSmallSystemFont ; | |
396 | ||
76a5e5d2 | 397 | ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; |
89ebf1c9 | 398 | } |
76a5e5d2 | 399 | ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; |
89ebf1c9 | 400 | wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; |
76a5e5d2 | 401 | ::EmbedControl( (ControlHandle) m_macControl , container ) ; |
89ebf1c9 RR |
402 | m_macControlIsShown = true ; |
403 | ||
76a5e5d2 | 404 | wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ; |
692f921a SC |
405 | if ( wxMacSetupControlBackgroundUPP == NULL ) |
406 | { | |
407 | wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; | |
408 | } | |
17a2c5a1 SC |
409 | if ( wxMacControlActionUPP == NULL ) |
410 | { | |
eb22f2a6 | 411 | wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ; |
17a2c5a1 | 412 | } |
111c1e2c JS |
413 | // The following block of code is responsible for crashes when switching |
414 | // back to windows, which can be seen in the dialogs sample. | |
415 | // It is disabled until a proper solution can be found. | |
416 | #if 0 | |
17a2c5a1 | 417 | #if TARGET_CARBON |
b6f5f27a SC |
418 | /* |
419 | only working under classic carbon | |
17a2c5a1 SC |
420 | m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; |
421 | (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ; | |
b6f5f27a | 422 | */ |
17a2c5a1 SC |
423 | #else |
424 | m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; | |
425 | ||
426 | cdefHandle cdef ; | |
427 | cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ; | |
428 | if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL ) | |
429 | { | |
430 | (**cdef).instruction = 0x4EF9; /* JMP instruction */ | |
431 | (**cdef).function = (void(*)()) wxMacControlActionUPP; | |
432 | (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ; | |
433 | } | |
111c1e2c | 434 | #endif |
17a2c5a1 | 435 | #endif |
692f921a | 436 | SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ; |
9453cf2b SC |
437 | |
438 | // Adjust the controls size and position | |
439 | wxPoint pos(m_x, m_y); | |
440 | wxSize best_size( DoGetBestSize() ); | |
441 | wxSize new_size( m_width, m_height ); | |
442 | ||
443 | m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control | |
444 | ||
445 | if (new_size.x == -1) { | |
446 | new_size.x = best_size.x; | |
447 | } | |
448 | if (new_size.y == -1) { | |
449 | new_size.y = best_size.y; | |
450 | } | |
451 | ||
452 | SetSize(pos.x, pos.y, new_size.x, new_size.y); | |
453 | ||
76a5e5d2 | 454 | UMAShowControl( (ControlHandle) m_macControl ) ; |
bf4a027d SC |
455 | |
456 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
457 | ||
a5a8ff8a | 458 | Refresh() ; |
519cb848 SC |
459 | } |
460 | ||
461 | void wxControl::MacAdjustControlRect() | |
462 | { | |
76a5e5d2 | 463 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
89ebf1c9 RR |
464 | if ( m_width == -1 || m_height == -1 ) |
465 | { | |
466 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
467 | short baselineoffset ; | |
468 | ||
76a5e5d2 | 469 | ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; |
89ebf1c9 RR |
470 | |
471 | if ( EmptyRect( &bestsize ) ) | |
472 | { | |
473 | baselineoffset = 0; | |
474 | bestsize.left = bestsize.top = 0 ; | |
475 | bestsize.right = 16 ; | |
476 | bestsize.bottom = 16 ; | |
477 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
478 | { | |
479 | bestsize.bottom = 16 ; | |
480 | } | |
481 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
482 | { | |
483 | bestsize.bottom = 24 ; | |
484 | } | |
485 | } | |
486 | ||
487 | if ( m_width == -1 ) | |
488 | { | |
489 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
490 | { | |
491 | m_width = m_label.Length() * 8 + 12 ; | |
492 | if ( m_width < 70 ) | |
493 | m_width = 70 ; | |
494 | } | |
495 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
496 | { | |
497 | m_width = m_label.Length() * 8 ; | |
498 | } | |
499 | else | |
500 | m_width = bestsize.right - bestsize.left ; | |
501 | ||
327788ac | 502 | m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ; |
89ebf1c9 RR |
503 | } |
504 | if ( m_height == -1 ) | |
505 | { | |
506 | m_height = bestsize.bottom - bestsize.top ; | |
507 | if ( m_height < 10 ) | |
508 | m_height = 13 ; | |
509 | ||
327788ac | 510 | m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ; |
89ebf1c9 | 511 | } |
327788ac SC |
512 | MacUpdateDimensions() ; |
513 | // UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; | |
89ebf1c9 | 514 | } |
519cb848 | 515 | } |
76a5e5d2 SC |
516 | |
517 | WXWidget wxControl::MacGetContainerForEmbedding() | |
519cb848 | 518 | { |
89ebf1c9 RR |
519 | if ( m_macControl ) |
520 | return m_macControl ; | |
519cb848 | 521 | |
89ebf1c9 | 522 | return wxWindow::MacGetContainerForEmbedding() ; |
519cb848 SC |
523 | } |
524 | ||
327788ac | 525 | void wxControl::MacUpdateDimensions() |
519cb848 | 526 | { |
327788ac SC |
527 | // actually in the current systems this should never be possible, but later reparenting |
528 | // may become a reality | |
529 | ||
530 | if ( (ControlHandle) m_macControl == NULL ) | |
531 | return ; | |
532 | ||
533 | if ( GetParent() == NULL ) | |
534 | return ; | |
535 | ||
536 | WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; | |
537 | if ( rootwindow == NULL ) | |
538 | return ; | |
539 | ||
540 | Rect oldBounds ; | |
541 | GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; | |
542 | ||
543 | int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ; | |
544 | int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ; | |
545 | int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ; | |
546 | int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ; | |
547 | ||
548 | GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ; | |
549 | bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ; | |
550 | bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ; | |
551 | if ( doMove || doResize ) | |
552 | { | |
553 | InvalWindowRect( rootwindow, &oldBounds ) ; | |
554 | if ( doMove ) | |
555 | { | |
556 | UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ; | |
557 | } | |
558 | if ( doResize ) | |
559 | { | |
560 | UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ; | |
561 | } | |
562 | } | |
563 | } | |
89ebf1c9 | 564 | |
327788ac SC |
565 | void wxControl::MacSuperChangedPosition() |
566 | { | |
567 | MacUpdateDimensions() ; | |
89ebf1c9 | 568 | wxWindow::MacSuperChangedPosition() ; |
519cb848 SC |
569 | } |
570 | ||
571 | void wxControl::MacSuperEnabled( bool enabled ) | |
572 | { | |
1c469f7f | 573 | Refresh(FALSE) ; |
1c310985 | 574 | wxWindow::MacSuperEnabled( enabled ) ; |
519cb848 SC |
575 | } |
576 | ||
577 | void wxControl::MacSuperShown( bool show ) | |
578 | { | |
76a5e5d2 | 579 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
580 | { |
581 | if ( !show ) | |
582 | { | |
583 | if ( m_macControlIsShown ) | |
584 | { | |
76a5e5d2 | 585 | ::UMAHideControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
586 | m_macControlIsShown = false ; |
587 | } | |
588 | } | |
589 | else | |
590 | { | |
591 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
592 | { | |
76a5e5d2 | 593 | ::UMAShowControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
594 | m_macControlIsShown = true ; |
595 | } | |
596 | } | |
597 | } | |
598 | ||
599 | wxWindow::MacSuperShown( show ) ; | |
519cb848 SC |
600 | } |
601 | ||
602 | void wxControl::DoSetSize(int x, int y, | |
603 | int width, int height, | |
604 | int sizeFlags ) | |
605 | { | |
327788ac | 606 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; |
64820d33 SC |
607 | #if 0 |
608 | { | |
609 | Rect meta , control ; | |
610 | GetControlBounds( (ControlHandle) m_macControl , &control ) ; | |
611 | RgnHandle rgn = NewRgn() ; | |
612 | GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ; | |
613 | GetRegionBounds( rgn , &meta ) ; | |
614 | if ( !EmptyRect( &meta ) ) | |
615 | { | |
616 | wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ; | |
617 | wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ; | |
618 | wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ; | |
619 | wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ; | |
620 | } | |
621 | DisposeRgn( rgn ) ; | |
622 | } | |
623 | #endif | |
327788ac SC |
624 | return ; |
625 | /* | |
626 | ||
76a5e5d2 | 627 | if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
628 | { |
629 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
630 | return ; | |
631 | } | |
519cb848 | 632 | |
0cd51b2d | 633 | Rect oldbounds; |
9453cf2b SC |
634 | int new_x, new_y, new_width, new_height; |
635 | int mac_x, mac_y; | |
636 | ||
637 | new_x = m_x; | |
638 | new_y = m_y; | |
639 | new_width = m_width; | |
640 | new_height = m_height; | |
641 | ||
642 | if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) | |
643 | { | |
644 | new_x = x; | |
645 | new_y = y; | |
646 | new_width = width; | |
647 | new_height = height; | |
648 | } | |
649 | else | |
650 | { | |
651 | if (x != -1) new_x = x; | |
652 | if (y != -1) new_y = y; | |
653 | if (width != -1) new_width = width; | |
654 | if (height != -1) new_height = height; | |
655 | } | |
656 | ||
657 | if(sizeFlags & wxSIZE_AUTO) | |
658 | { | |
659 | wxSize size = GetBestSize(); | |
660 | if (sizeFlags & wxSIZE_AUTO_WIDTH) | |
661 | { | |
662 | if (width == -1) new_width = size.x; | |
663 | } | |
664 | if (sizeFlags & wxSIZE_AUTO_HEIGHT) | |
665 | { | |
666 | if (height == -1) new_height = size.y; | |
667 | } | |
668 | } | |
1c310985 | 669 | AdjustForParentClientOrigin(new_x, new_y, sizeFlags); |
9453cf2b SC |
670 | |
671 | mac_x = new_x; | |
672 | mac_y = new_y; | |
673 | if(GetParent()) { | |
1c310985 | 674 | GetParent()->MacWindowToRootWindow(&mac_x, &mac_y); |
9453cf2b | 675 | } |
76a5e5d2 | 676 | GetControlBounds( (ControlHandle) m_macControl, &oldbounds); |
9453cf2b SC |
677 | oldbounds.right = oldbounds.left + m_width; |
678 | oldbounds.bottom = oldbounds.top + m_height; | |
679 | ||
680 | bool doMove = false; | |
681 | bool doResize = false; | |
682 | ||
683 | if ( mac_x != (oldbounds.left - m_macHorizontalBorder) || | |
684 | mac_y != (oldbounds.top - m_macVerticalBorder) ) | |
685 | { | |
686 | doMove = true ; | |
687 | } | |
688 | if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder || | |
689 | new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder) | |
690 | { | |
691 | doResize = true ; | |
692 | } | |
693 | ||
694 | if ( doMove || doResize ) | |
695 | { | |
1c310985 SC |
696 | Refresh() ; |
697 | ||
9453cf2b SC |
698 | // Ensure resize is within constraints |
699 | if ((m_minWidth != -1) && (new_width < m_minWidth)) { | |
700 | new_width = m_minWidth; | |
701 | } | |
702 | if ((m_minHeight != -1) && (new_height < m_minHeight)) { | |
703 | new_height = m_minHeight; | |
704 | } | |
705 | if ((m_maxWidth != -1) && (new_width > m_maxWidth)) { | |
706 | new_width = m_maxWidth; | |
707 | } | |
708 | if ((m_maxHeight != -1) && (new_height > m_maxHeight)) { | |
709 | new_height = m_maxHeight; | |
710 | } | |
711 | ||
712 | if ( doMove ) | |
713 | { | |
714 | m_x = new_x; | |
715 | m_y = new_y; | |
716 | ||
76a5e5d2 | 717 | UMAMoveControl( (ControlHandle) m_macControl, |
9453cf2b | 718 | mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder); |
1c310985 | 719 | |
9453cf2b SC |
720 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); |
721 | event.SetEventObject(this); | |
722 | GetEventHandler()->ProcessEvent(event) ; | |
723 | } | |
724 | if ( doResize ) | |
725 | { | |
726 | m_width = new_width; | |
727 | m_height = new_height; | |
728 | ||
76a5e5d2 | 729 | UMASizeControl( (ControlHandle) m_macControl, |
9453cf2b SC |
730 | m_width - 2 * m_macHorizontalBorder, |
731 | m_height - 2 * m_macVerticalBorder ) ; | |
732 | ||
abfe4a84 | 733 | |
9453cf2b SC |
734 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); |
735 | event.SetEventObject(this); | |
736 | GetEventHandler()->ProcessEvent(event); | |
737 | } | |
738 | ||
1c310985 | 739 | Refresh() ; |
9453cf2b | 740 | } |
327788ac | 741 | */ |
519cb848 SC |
742 | } |
743 | ||
519cb848 SC |
744 | bool wxControl::Show(bool show) |
745 | { | |
89ebf1c9 RR |
746 | if ( !wxWindow::Show( show ) ) |
747 | return FALSE ; | |
748 | ||
76a5e5d2 | 749 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
750 | { |
751 | if ( !show ) | |
752 | { | |
753 | if ( m_macControlIsShown ) | |
754 | { | |
76a5e5d2 | 755 | ::UMAHideControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
756 | m_macControlIsShown = false ; |
757 | } | |
758 | } | |
759 | else | |
760 | { | |
761 | if ( MacIsReallyShown() && !m_macControlIsShown ) | |
762 | { | |
76a5e5d2 | 763 | ::UMAShowControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
764 | m_macControlIsShown = true ; |
765 | } | |
766 | } | |
767 | } | |
768 | return TRUE ; | |
519cb848 SC |
769 | } |
770 | ||
e7549107 | 771 | bool wxControl::Enable(bool enable) |
519cb848 | 772 | { |
e7549107 SC |
773 | if ( !wxWindow::Enable(enable) ) |
774 | return FALSE; | |
519cb848 | 775 | |
76a5e5d2 | 776 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 RR |
777 | { |
778 | if ( enable ) | |
76a5e5d2 | 779 | UMAActivateControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 780 | else |
76a5e5d2 | 781 | UMADeactivateControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
782 | } |
783 | return TRUE ; | |
519cb848 SC |
784 | } |
785 | ||
786 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
787 | { | |
89ebf1c9 | 788 | wxWindow::Refresh( eraseBack , rect ) ; |
519cb848 SC |
789 | } |
790 | ||
2f1ae414 SC |
791 | void wxControl::MacRedrawControl() |
792 | { | |
404dfcae | 793 | if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown ) |
89ebf1c9 | 794 | { |
de043984 SC |
795 | wxClientDC dc(this) ; |
796 | wxMacPortSetter helper(&dc) ; | |
17a2c5a1 | 797 | wxMacWindowClipper clipper(this) ; |
de043984 | 798 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; |
76a5e5d2 | 799 | UMADrawControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 | 800 | } |
2f1ae414 SC |
801 | } |
802 | ||
519cb848 SC |
803 | void wxControl::OnPaint(wxPaintEvent& event) |
804 | { | |
76a5e5d2 | 805 | if ( (ControlHandle) m_macControl ) |
89ebf1c9 | 806 | { |
de043984 SC |
807 | wxPaintDC dc(this) ; |
808 | wxMacPortSetter helper(&dc) ; | |
17a2c5a1 | 809 | wxMacWindowClipper clipper(this) ; |
de043984 | 810 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; |
76a5e5d2 | 811 | UMADrawControl( (ControlHandle) m_macControl ) ; |
89ebf1c9 RR |
812 | } |
813 | else | |
814 | { | |
a5a8ff8a | 815 | event.Skip() ; |
89ebf1c9 | 816 | } |
519cb848 | 817 | } |
51abe921 SC |
818 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
819 | { | |
1c310985 | 820 | wxWindow::OnEraseBackground( event ) ; |
51abe921 SC |
821 | } |
822 | ||
519cb848 SC |
823 | |
824 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
825 | { | |
76a5e5d2 | 826 | if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
827 | return ; |
828 | ||
76a5e5d2 | 829 | EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; |
89ebf1c9 RR |
830 | short keycode ; |
831 | short keychar ; | |
832 | keychar = short(ev->message & charCodeMask); | |
833 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
834 | ||
76a5e5d2 | 835 | ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; |
519cb848 SC |
836 | } |
837 | ||
838 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
839 | { | |
76a5e5d2 | 840 | if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
841 | { |
842 | event.Skip() ; | |
843 | return ; | |
844 | } | |
845 | ||
846 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
847 | { | |
848 | ||
849 | int x = event.m_x ; | |
850 | int y = event.m_y ; | |
851 | ||
852 | MacClientToRootWindow( &x , &y ) ; | |
853 | ||
854 | ControlHandle control ; | |
855 | Point localwhere ; | |
856 | SInt16 controlpart ; | |
89ebf1c9 RR |
857 | |
858 | localwhere.h = x ; | |
859 | localwhere.v = y ; | |
860 | ||
861 | short modifiers = 0; | |
862 | ||
863 | if ( !event.m_leftDown && !event.m_rightDown ) | |
864 | modifiers |= btnState ; | |
865 | ||
866 | if ( event.m_shiftDown ) | |
867 | modifiers |= shiftKey ; | |
868 | ||
869 | if ( event.m_controlDown ) | |
870 | modifiers |= controlKey ; | |
871 | ||
872 | if ( event.m_altDown ) | |
873 | modifiers |= optionKey ; | |
874 | ||
875 | if ( event.m_metaDown ) | |
876 | modifiers |= cmdKey ; | |
89ebf1c9 | 877 | { |
76a5e5d2 | 878 | control = (ControlHandle) m_macControl ; |
89ebf1c9 RR |
879 | if ( control && ::IsControlActive( control ) ) |
880 | { | |
881 | { | |
882 | controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
883 | wxTheApp->s_lastMouseDown = 0 ; | |
884 | if ( control && controlpart != kControlNoPart && | |
885 | ! IsKindOf( CLASSINFO( wxScrollBar ) ) | |
886 | ) // otherwise we will get the event twice for scrollbar | |
887 | { | |
888 | MacHandleControlClick( control , controlpart ) ; | |
889 | } | |
890 | } | |
891 | } | |
892 | } | |
893 | } | |
519cb848 SC |
894 | } |
895 | ||
896 | bool wxControl::MacCanFocus() const | |
897 | { | |
76a5e5d2 | 898 | { if ( (ControlHandle) m_macControl == NULL ) |
89ebf1c9 RR |
899 | return true ; |
900 | else | |
901 | return false ; | |
902 | } | |
519cb848 SC |
903 | } |
904 | ||
76a5e5d2 | 905 | void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) |
519cb848 | 906 | { |
76a5e5d2 | 907 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ; |
519cb848 SC |
908 | } |
909 |