]> git.saurik.com Git - wxWidgets.git/blob - src/mac/control.cpp
bug fix & carbon support
[wxWidgets.git] / src / mac / control.cpp
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
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_CHAR( wxControl::OnKeyDown )
40 EVT_PAINT( wxControl::OnPaint )
41 END_EVENT_TABLE()
42 #endif
43
44 #include "wx/mac/uma.h"
45 #include "wx/mac/private.h"
46
47 // Item members
48
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
71 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
72 wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ;
73
74 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
75 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
76 {
77 if ( partCode != 0)
78 {
79 wxControl* wx = (wxControl*) GetControlReference( control ) ;
80 if ( wx )
81 {
82 wx->MacHandleControlClick( control , partCode ) ;
83 }
84 }
85 }
86
87 ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
88 ControlDefUPP wxMacControlActionUPP = NULL ;
89
90 pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param)
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 }
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 :
113 {
114 wxControl* wx = (wxControl*) GetControlReference( iControl ) ;
115 if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
116 {
117 wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ;
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
129 }
130 else
131 {
132 status = paramErr ;
133 }
134 }
135 break ;
136 default :
137 status = paramErr ;
138 break ;
139 }
140 return status ;
141 }
142
143 wxControl::wxControl()
144 {
145 m_macControl = NULL ;
146 m_macControlAction = NULL ;
147 m_macHorizontalBorder = 0 ; // additional pixels around the real control
148 m_macVerticalBorder = 0 ;
149 m_backgroundColour = *wxWHITE;
150 m_foregroundColour = *wxBLACK;
151 #if WXWIN_COMPATIBILITY
152 m_callback = 0;
153 #endif // WXWIN_COMPATIBILITY
154
155 if ( wxMacLiveScrollbarActionUPP == NULL )
156 {
157 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
158 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
159 #else
160 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
161 #endif
162 }
163 }
164
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 {
171 m_macControl = NULL ;
172 m_macHorizontalBorder = 0 ; // additional pixels around the real control
173 m_macVerticalBorder = 0 ;
174
175 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
176 if ( parent )
177 {
178 m_backgroundColour = parent->GetBackgroundColour() ;
179 m_foregroundColour = parent->GetForegroundColour() ;
180 }
181 if (rval) {
182 #if wxUSE_VALIDATORS
183 SetValidator(validator);
184 #endif
185 }
186 return rval;
187 }
188
189 wxControl::~wxControl()
190 {
191 m_isBeingDeleted = TRUE;
192 wxRemoveMacControlAssociation( this ) ;
193 // If we delete an item, we should initialize the parent panel,
194 // because it could now be invalid.
195 wxWindow *parent = GetParent() ;
196 if ( parent )
197 {
198 if (parent->GetDefaultItem() == (wxButton*) this)
199 parent->SetDefaultItem(NULL);
200 }
201 if ( (ControlHandle) m_macControl )
202 {
203 ::DisposeControl( (ControlHandle) m_macControl ) ;
204 m_macControl = NULL ;
205 }
206 }
207
208 void wxControl::SetLabel(const wxString& title)
209 {
210 m_label = wxStripMenuCodes(title) ;
211
212 if ( (ControlHandle) m_macControl )
213 {
214 Str255 maclabel ;
215 wxString label ;
216
217 if( wxApp::s_macDefaultEncodingIsPC )
218 label = wxMacMakeMacStringFromPC( m_label ) ;
219 else
220 label = m_label ;
221
222 #if TARGET_CARBON
223 c2pstrcpy( (StringPtr) maclabel , label ) ;
224 #else
225 strcpy( (char *) maclabel , label ) ;
226 c2pstr( (char *) maclabel ) ;
227 #endif
228 ::SetControlTitle( (ControlHandle) m_macControl , maclabel ) ;
229 }
230 Refresh() ;
231 }
232
233 wxSize wxControl::DoGetBestSize() const
234 {
235 Rect bestsize = { 0 , 0 , 0 , 0 } ;
236 short baselineoffset ;
237 int bestWidth, bestHeight ;
238 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
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
278 return wxSize(bestWidth, bestHeight);
279 }
280
281 bool wxControl::ProcessCommand (wxCommandEvent & event)
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.
287 #if WXWIN_COMPATIBILITY
288 if ( m_callback )
289 {
290 (void)(*m_callback)(this, event);
291
292 return TRUE;
293 }
294 else
295 #endif // WXWIN_COMPATIBILITY
296 {
297 return GetEventHandler()->ProcessEvent(event);
298 }
299 }
300
301 // ------------------------
302 wxList *wxWinMacControlList = NULL;
303 wxControl *wxFindControlFromMacControl(ControlHandle inControl )
304 {
305 wxNode *node = wxWinMacControlList->Find((long)inControl);
306 if (!node)
307 return NULL;
308 return (wxControl *)node->GetData();
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 ,
327 const wxPoint& pos,
328 const wxSize& size, long style,
329 const wxValidator& validator,
330 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
331 {
332 m_label = label ;
333 SetName(name);
334 if ( &validator )
335 SetValidator(validator);
336
337 m_windowStyle = style;
338 parent->AddChild(this);
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
348 // These sizes will be adjusted in MacPostControlCreate
349
350 m_width = size.x ;
351 m_height = size.y ;
352 m_x = pos.x ;
353 m_y = pos.y ;
354
355 ((Rect*)outBounds)->top = -10;
356 ((Rect*)outBounds)->left = -10;
357 ((Rect*)outBounds)->bottom = 0;
358 ((Rect*)outBounds)->right = 0;
359
360 char c_text[255];
361 strcpy( c_text , label ) ;
362 if( wxApp::s_macDefaultEncodingIsPC )
363 {
364 wxMacConvertFromPCForControls( c_text ) ;
365 }
366
367 #if TARGET_CARBON
368 c2pstrcpy( (StringPtr) maclabel , c_text ) ;
369 #else
370 strcpy( (char *) maclabel , c_text ) ;
371 c2pstr( (char *) maclabel ) ;
372 #endif
373 }
374
375 void wxControl::MacPostControlCreate()
376 {
377 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
378
379 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
380 {
381 // no font
382 }
383 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
384 {
385 ControlFontStyleRec controlstyle ;
386 controlstyle.flags = kControlUseFontMask ;
387 controlstyle.font = kControlFontSmallBoldSystemFont ;
388
389 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
390 }
391 else
392 {
393 ControlFontStyleRec controlstyle ;
394 controlstyle.flags = kControlUseFontMask ;
395 controlstyle.font = kControlFontSmallSystemFont ;
396
397 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
398 }
399 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
400 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
401 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
402 m_macControlIsShown = true ;
403
404 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
405 if ( wxMacSetupControlBackgroundUPP == NULL )
406 {
407 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
408 }
409 if ( wxMacControlActionUPP == NULL )
410 {
411 wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
412 }
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
417 #if TARGET_CARBON
418 /*
419 only working under classic carbon
420 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
421 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
422 */
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 }
434 #endif
435 #endif
436 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
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
454 UMAShowControl( (ControlHandle) m_macControl ) ;
455
456 SetCursor( *wxSTANDARD_CURSOR ) ;
457
458 Refresh() ;
459 }
460
461 void wxControl::MacAdjustControlRect()
462 {
463 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
464 if ( m_width == -1 || m_height == -1 )
465 {
466 Rect bestsize = { 0 , 0 , 0 , 0 } ;
467 short baselineoffset ;
468
469 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
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
502 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
503 }
504 if ( m_height == -1 )
505 {
506 m_height = bestsize.bottom - bestsize.top ;
507 if ( m_height < 10 )
508 m_height = 13 ;
509
510 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
511 }
512 MacUpdateDimensions() ;
513 // UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
514 }
515 }
516
517 WXWidget wxControl::MacGetContainerForEmbedding()
518 {
519 if ( m_macControl )
520 return m_macControl ;
521
522 return wxWindow::MacGetContainerForEmbedding() ;
523 }
524
525 void wxControl::MacUpdateDimensions()
526 {
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 }
564
565 void wxControl::MacSuperChangedPosition()
566 {
567 MacUpdateDimensions() ;
568 wxWindow::MacSuperChangedPosition() ;
569 }
570
571 void wxControl::MacSuperEnabled( bool enabled )
572 {
573 Refresh(FALSE) ;
574 wxWindow::MacSuperEnabled( enabled ) ;
575 }
576
577 void wxControl::MacSuperShown( bool show )
578 {
579 if ( (ControlHandle) m_macControl )
580 {
581 if ( !show )
582 {
583 if ( m_macControlIsShown )
584 {
585 ::UMAHideControl( (ControlHandle) m_macControl ) ;
586 m_macControlIsShown = false ;
587 }
588 }
589 else
590 {
591 if ( MacIsReallyShown() && !m_macControlIsShown )
592 {
593 ::UMAShowControl( (ControlHandle) m_macControl ) ;
594 m_macControlIsShown = true ;
595 }
596 }
597 }
598
599 wxWindow::MacSuperShown( show ) ;
600 }
601
602 void wxControl::DoSetSize(int x, int y,
603 int width, int height,
604 int sizeFlags )
605 {
606 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
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
624 return ;
625 /*
626
627 if ( (ControlHandle) m_macControl == NULL )
628 {
629 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
630 return ;
631 }
632
633 Rect oldbounds;
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 }
669 AdjustForParentClientOrigin(new_x, new_y, sizeFlags);
670
671 mac_x = new_x;
672 mac_y = new_y;
673 if(GetParent()) {
674 GetParent()->MacWindowToRootWindow(&mac_x, &mac_y);
675 }
676 GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
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 {
696 Refresh() ;
697
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
717 UMAMoveControl( (ControlHandle) m_macControl,
718 mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder);
719
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
729 UMASizeControl( (ControlHandle) m_macControl,
730 m_width - 2 * m_macHorizontalBorder,
731 m_height - 2 * m_macVerticalBorder ) ;
732
733
734 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
735 event.SetEventObject(this);
736 GetEventHandler()->ProcessEvent(event);
737 }
738
739 Refresh() ;
740 }
741 */
742 }
743
744 bool wxControl::Show(bool show)
745 {
746 if ( !wxWindow::Show( show ) )
747 return FALSE ;
748
749 if ( (ControlHandle) m_macControl )
750 {
751 if ( !show )
752 {
753 if ( m_macControlIsShown )
754 {
755 ::UMAHideControl( (ControlHandle) m_macControl ) ;
756 m_macControlIsShown = false ;
757 }
758 }
759 else
760 {
761 if ( MacIsReallyShown() && !m_macControlIsShown )
762 {
763 ::UMAShowControl( (ControlHandle) m_macControl ) ;
764 m_macControlIsShown = true ;
765 }
766 }
767 }
768 return TRUE ;
769 }
770
771 bool wxControl::Enable(bool enable)
772 {
773 if ( !wxWindow::Enable(enable) )
774 return FALSE;
775
776 if ( (ControlHandle) m_macControl )
777 {
778 if ( enable )
779 UMAActivateControl( (ControlHandle) m_macControl ) ;
780 else
781 UMADeactivateControl( (ControlHandle) m_macControl ) ;
782 }
783 return TRUE ;
784 }
785
786 void wxControl::Refresh(bool eraseBack, const wxRect *rect)
787 {
788 wxWindow::Refresh( eraseBack , rect ) ;
789 }
790
791 void wxControl::MacRedrawControl()
792 {
793 if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
794 {
795 wxClientDC dc(this) ;
796 wxMacPortSetter helper(&dc) ;
797 wxMacWindowClipper clipper(this) ;
798 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
799 UMADrawControl( (ControlHandle) m_macControl ) ;
800 }
801 }
802
803 void wxControl::OnPaint(wxPaintEvent& event)
804 {
805 if ( (ControlHandle) m_macControl )
806 {
807 wxPaintDC dc(this) ;
808 wxMacPortSetter helper(&dc) ;
809 wxMacWindowClipper clipper(this) ;
810 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
811 UMADrawControl( (ControlHandle) m_macControl ) ;
812 }
813 else
814 {
815 event.Skip() ;
816 }
817 }
818 void wxControl::OnEraseBackground(wxEraseEvent& event)
819 {
820 wxWindow::OnEraseBackground( event ) ;
821 }
822
823
824 void wxControl::OnKeyDown( wxKeyEvent &event )
825 {
826 if ( (ControlHandle) m_macControl == NULL )
827 return ;
828
829 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
830 short keycode ;
831 short keychar ;
832 keychar = short(ev->message & charCodeMask);
833 keycode = short(ev->message & keyCodeMask) >> 8 ;
834
835 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
836 }
837
838 void wxControl::OnMouseEvent( wxMouseEvent &event )
839 {
840 if ( (ControlHandle) m_macControl == NULL )
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 ;
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 ;
877 {
878 control = (ControlHandle) m_macControl ;
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 }
894 }
895
896 bool wxControl::MacCanFocus() const
897 {
898 { if ( (ControlHandle) m_macControl == NULL )
899 return true ;
900 else
901 return false ;
902 }
903 }
904
905 void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
906 {
907 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
908 }
909