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