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