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