]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
added alpha channel support for mask bitmaps
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindowMac
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 "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/window.h"
19 #include "wx/dc.h"
20 #include "wx/dcclient.h"
21 #include "wx/utils.h"
22 #include "wx/app.h"
23 #include "wx/panel.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/frame.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
38 #include "wx/spinctrl.h"
39 #include "wx/log.h"
40 #include "wx/geometry.h"
41
42 #if wxUSE_CARET
43 #include "wx/caret.h"
44 #endif // wxUSE_CARET
45
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
49
50 #include "wx/mac/uma.h"
51 #ifndef __DARWIN__
52 #include <Windows.h>
53 #include <ToolUtils.h>
54 #endif
55
56 #if wxUSE_DRAG_AND_DROP
57 #include "wx/dnd.h"
58 #endif
59
60 #include <string.h>
61
62 extern wxList wxPendingDelete;
63 wxWindowMac* gFocusWindow = NULL ;
64
65 #ifdef __WXUNIVERSAL__
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
67 #else // __WXMAC__
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
69 #endif // __WXUNIVERSAL__/__WXMAC__
70
71 #if !USE_SHARED_LIBRARY
72
73 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
74 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
75 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
76 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
77 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
78 EVT_IDLE(wxWindowMac::OnIdle)
79 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
80 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
81 END_EVENT_TABLE()
82
83 #endif
84
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
88 #endif
89
90 #define wxMAC_USE_THEME_BORDER 0
91
92
93 // ===========================================================================
94 // implementation
95 // ===========================================================================
96
97
98 // ----------------------------------------------------------------------------
99 // constructors and such
100 // ----------------------------------------------------------------------------
101
102 void wxWindowMac::Init()
103 {
104 // generic
105 InitBase();
106
107 // MSW specific
108 m_doubleClickAllowed = 0;
109 m_winCaptured = FALSE;
110
111 m_isBeingDeleted = FALSE;
112
113 m_useCtl3D = FALSE;
114 m_mouseInWindow = FALSE;
115
116 m_xThumbSize = 0;
117 m_yThumbSize = 0;
118 m_backgroundTransparent = FALSE;
119
120 // as all windows are created with WS_VISIBLE style...
121 m_isShown = TRUE;
122
123 m_x = 0;
124 m_y = 0 ;
125 m_width = 0 ;
126 m_height = 0 ;
127
128 m_hScrollBar = NULL ;
129 m_vScrollBar = NULL ;
130
131 m_label = wxEmptyString;
132 }
133
134 // Destructor
135 wxWindowMac::~wxWindowMac()
136 {
137 SendDestroyEvent();
138
139 // deleting a window while it is shown invalidates the region
140 if ( IsShown() ) {
141 wxWindowMac* iter = this ;
142 while( iter ) {
143 if ( iter->IsTopLevel() )
144 {
145 Refresh() ;
146 break ;
147 }
148 iter = iter->GetParent() ;
149
150 }
151 }
152
153 m_isBeingDeleted = TRUE;
154
155 #ifndef __WXUNIVERSAL__
156 // VS: make sure there's no wxFrame with last focus set to us:
157 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
158 {
159 wxFrame *frame = wxDynamicCast(win, wxFrame);
160 if ( frame )
161 {
162 if ( frame->GetLastFocus() == this )
163 {
164 frame->SetLastFocus((wxWindow*)NULL);
165 }
166 break;
167 }
168 }
169 #endif // __WXUNIVERSAL__
170
171 if ( s_lastMouseWindow == this )
172 {
173 s_lastMouseWindow = NULL ;
174 }
175
176 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
177 if ( frame )
178 {
179 if ( frame->GetLastFocus() == this )
180 frame->SetLastFocus( NULL ) ;
181 }
182
183 if ( gFocusWindow == this )
184 {
185 gFocusWindow = NULL ;
186 }
187
188 // CS: copied from MSW :
189 // VS: destroy children first and _then_ detach *this from its parent.
190 // If we'd do it the other way around, children wouldn't be able
191 // find their parent frame (see above).
192 DestroyChildren();
193
194 if ( m_parent )
195 m_parent->RemoveChild(this);
196
197 // delete our drop target if we've got one
198 #if wxUSE_DRAG_AND_DROP
199 if ( m_dropTarget != NULL )
200 {
201 delete m_dropTarget;
202 m_dropTarget = NULL;
203 }
204 #endif // wxUSE_DRAG_AND_DROP
205 }
206
207 // Constructor
208 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
209 const wxPoint& pos,
210 const wxSize& size,
211 long style,
212 const wxString& name)
213 {
214 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
215
216 #if wxUSE_STATBOX
217 // wxGTK doesn't allow to create controls with static box as the parent so
218 // this will result in a crash when the program is ported to wxGTK - warn
219 // about it
220 //
221 // the correct solution is to create the controls as siblings of the
222 // static box
223 wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox),
224 _T("wxStaticBox can't be used as a window parent!") );
225 #endif // wxUSE_STATBOX
226
227 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
228 return FALSE;
229
230 parent->AddChild(this);
231
232 m_x = (int)pos.x;
233 m_y = (int)pos.y;
234 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
235 m_width = WidthDefault( size.x );
236 m_height = HeightDefault( size.y ) ;
237 #ifndef __WXUNIVERSAL__
238 // Don't give scrollbars to wxControls unless they ask for them
239 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
240 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
241 {
242 MacCreateScrollBars( style ) ;
243 }
244 #endif
245 return TRUE;
246 }
247
248 void wxWindowMac::SetFocus()
249 {
250 if ( gFocusWindow == this )
251 return ;
252
253 if ( AcceptsFocus() )
254 {
255 if (gFocusWindow )
256 {
257 #if wxUSE_CARET
258 // Deal with caret
259 if ( gFocusWindow->m_caret )
260 {
261 gFocusWindow->m_caret->OnKillFocus();
262 }
263 #endif // wxUSE_CARET
264 #ifndef __WXUNIVERSAL__
265 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
266 if ( control && control->GetMacControl() )
267 {
268 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ;
269 control->MacRedrawControl() ;
270 }
271 #endif
272 // Without testing the window id, for some reason
273 // a kill focus event can still be sent to
274 // the control just being focussed.
275 int thisId = this->m_windowId;
276 int gFocusWindowId = gFocusWindow->m_windowId;
277 if (gFocusWindowId != thisId)
278 {
279 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
280 event.SetEventObject(gFocusWindow);
281 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
282 }
283 }
284 gFocusWindow = this ;
285 {
286 #if wxUSE_CARET
287 // Deal with caret
288 if ( m_caret )
289 {
290 m_caret->OnSetFocus();
291 }
292 #endif // wxUSE_CARET
293 // panel wants to track the window which was the last to have focus in it
294 wxChildFocusEvent eventFocus(this);
295 GetEventHandler()->ProcessEvent(eventFocus);
296
297 #ifndef __WXUNIVERSAL__
298 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
299 if ( control && control->GetMacControl() )
300 {
301 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ;
302 }
303 #endif
304 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
305 event.SetEventObject(this);
306 GetEventHandler()->ProcessEvent(event) ;
307 }
308 }
309 }
310
311 bool wxWindowMac::Enable(bool enable)
312 {
313 if ( !wxWindowBase::Enable(enable) )
314 return FALSE;
315
316 MacSuperEnabled( enable ) ;
317
318 return TRUE;
319 }
320
321 void wxWindowMac::DoCaptureMouse()
322 {
323 wxTheApp->s_captureWindow = this ;
324 }
325
326 wxWindow* wxWindowBase::GetCapture()
327 {
328 return wxTheApp->s_captureWindow ;
329 }
330
331 void wxWindowMac::DoReleaseMouse()
332 {
333 wxTheApp->s_captureWindow = NULL ;
334 }
335
336 #if wxUSE_DRAG_AND_DROP
337
338 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
339 {
340 if ( m_dropTarget != 0 ) {
341 delete m_dropTarget;
342 }
343
344 m_dropTarget = pDropTarget;
345 if ( m_dropTarget != 0 )
346 {
347 // TODO
348 }
349 }
350
351 #endif
352
353 // Old style file-manager drag&drop
354 void wxWindowMac::DragAcceptFiles(bool accept)
355 {
356 // TODO
357 }
358
359 // Get total size
360 void wxWindowMac::DoGetSize(int *x, int *y) const
361 {
362 if(x) *x = m_width ;
363 if(y) *y = m_height ;
364 }
365
366 void wxWindowMac::DoGetPosition(int *x, int *y) const
367 {
368 int xx,yy;
369
370 xx = m_x ;
371 yy = m_y ;
372 if ( !IsTopLevel() && GetParent())
373 {
374 wxPoint pt(GetParent()->GetClientAreaOrigin());
375 xx -= pt.x;
376 yy -= pt.y;
377 }
378 if(x) *x = xx;
379 if(y) *y = yy;
380 }
381
382 #if wxUSE_MENUS
383 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
384 {
385 menu->SetInvokingWindow(this);
386 menu->UpdateUI();
387 ClientToScreen( &x , &y ) ;
388
389 wxArrayPtrVoid submenus ;
390 wxMenuItemList::Node *node;
391 wxMenuItem *item;
392 int pos ;
393 for (pos = 0, node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
394 {
395 item = (wxMenuItem *)node->GetData();
396 wxMenu* subMenu = item->GetSubMenu() ;
397 if (subMenu)
398 {
399 submenus.Add(subMenu) ;
400 }
401 }
402
403 ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
404
405 for ( size_t i = 0 ; i < submenus.GetCount() ; ++i )
406 {
407 wxMenu* submenu = (wxMenu*) submenus[i] ;
408 wxMenuItemList::Node *subnode;
409 wxMenuItem *subitem;
410 int subpos ;
411 for ( subpos = 0 , subnode = submenu->GetMenuItems().GetFirst(); subnode; subnode = subnode->GetNext(), subpos++)
412 {
413 subitem = (wxMenuItem *)subnode->GetData();
414 wxMenu* itsSubMenu = subitem->GetSubMenu() ;
415 if (itsSubMenu)
416 {
417 submenus.Add(itsSubMenu) ;
418 }
419 }
420 ::InsertMenu( MAC_WXHMENU(submenu->GetHMenu()) , -1 ) ;
421 }
422
423 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
424 if ( HiWord(menuResult) != 0 )
425 {
426 MenuCommand id ;
427 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
428 wxMenuItem* item = NULL ;
429 wxMenu* realmenu ;
430 item = menu->FindItem(id, &realmenu) ;
431 if (item->IsCheckable())
432 {
433 item->Check( !item->IsChecked() ) ;
434 }
435 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
436 }
437 ::DeleteMenu( menu->MacGetMenuId() ) ;
438 for ( size_t i = 0 ; i < submenus.GetCount() ; ++i )
439 {
440 wxMenu* submenu = (wxMenu*) submenus[i] ;
441 ::DeleteMenu( submenu->MacGetMenuId() ) ;
442 }
443
444 menu->SetInvokingWindow(NULL);
445
446 return TRUE;
447 }
448 #endif
449
450 void wxWindowMac::DoScreenToClient(int *x, int *y) const
451 {
452 WindowRef window = (WindowRef) MacGetRootWindow() ;
453
454 Point localwhere = {0,0} ;
455
456 if(x) localwhere.h = * x ;
457 if(y) localwhere.v = * y ;
458
459 GrafPtr port ;
460 ::GetPort( &port ) ;
461 ::SetPort( UMAGetWindowPort( window ) ) ;
462 ::GlobalToLocal( &localwhere ) ;
463 ::SetPort( port ) ;
464
465 if(x) *x = localwhere.h ;
466 if(y) *y = localwhere.v ;
467
468 MacRootWindowToWindow( x , y ) ;
469 if ( x )
470 *x -= MacGetLeftBorderSize() ;
471 if ( y )
472 *y -= MacGetTopBorderSize() ;
473 }
474
475 void wxWindowMac::DoClientToScreen(int *x, int *y) const
476 {
477 WindowRef window = (WindowRef) MacGetRootWindow() ;
478
479 if ( x )
480 *x += MacGetLeftBorderSize() ;
481 if ( y )
482 *y += MacGetTopBorderSize() ;
483
484 MacWindowToRootWindow( x , y ) ;
485
486 Point localwhere = { 0,0 };
487 if(x) localwhere.h = * x ;
488 if(y) localwhere.v = * y ;
489
490 GrafPtr port ;
491 ::GetPort( &port ) ;
492 ::SetPort( UMAGetWindowPort( window ) ) ;
493
494 ::LocalToGlobal( &localwhere ) ;
495 ::SetPort( port ) ;
496 if(x) *x = localwhere.h ;
497 if(y) *y = localwhere.v ;
498 }
499
500 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
501 {
502 wxPoint origin = GetClientAreaOrigin() ;
503 if(x) *x += origin.x ;
504 if(y) *y += origin.y ;
505
506 MacWindowToRootWindow( x , y ) ;
507 }
508
509 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
510 {
511 wxPoint origin = GetClientAreaOrigin() ;
512 MacRootWindowToWindow( x , y ) ;
513 if(x) *x -= origin.x ;
514 if(y) *y -= origin.y ;
515 }
516
517 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
518 {
519 if ( !IsTopLevel() )
520 {
521 if(x) *x += m_x ;
522 if(y) *y += m_y ;
523 GetParent()->MacWindowToRootWindow( x , y ) ;
524 }
525 }
526
527 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
528 {
529 if ( !IsTopLevel() )
530 {
531 if(x) *x -= m_x ;
532 if(y) *y -= m_y ;
533 GetParent()->MacRootWindowToWindow( x , y ) ;
534 }
535 }
536
537 bool wxWindowMac::SetCursor(const wxCursor& cursor)
538 {
539 if (m_cursor == cursor)
540 return FALSE;
541
542 if (wxNullCursor == cursor)
543 {
544 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
545 return FALSE ;
546 }
547 else
548 {
549 if ( ! wxWindowBase::SetCursor( cursor ) )
550 return FALSE ;
551 }
552
553 wxASSERT_MSG( m_cursor.Ok(),
554 wxT("cursor must be valid after call to the base version"));
555
556 Point pt ;
557 wxWindowMac *mouseWin ;
558 GetMouse( &pt ) ;
559
560 // Change the cursor NOW if we're within the correct window
561
562 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
563 {
564 if ( mouseWin == this && !wxIsBusy() )
565 {
566 m_cursor.MacInstall() ;
567 }
568 }
569
570 return TRUE ;
571 }
572
573
574 // Get size *available for subwindows* i.e. excluding menu bar etc.
575 void wxWindowMac::DoGetClientSize(int *x, int *y) const
576 {
577 int ww, hh;
578 ww = m_width ;
579 hh = m_height ;
580
581 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
582 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
583
584 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
585 {
586 int x1 = 0 ;
587 int y1 = 0 ;
588 int w = m_width ;
589 int h = m_height ;
590
591 MacClientToRootWindow( &x1 , &y1 ) ;
592 MacClientToRootWindow( &w , &h ) ;
593
594 wxWindowMac *iter = (wxWindowMac*)this ;
595
596 int totW = 10000 , totH = 10000;
597 while( iter )
598 {
599 if ( iter->IsTopLevel() )
600 {
601 totW = iter->m_width ;
602 totH = iter->m_height ;
603 break ;
604 }
605
606 iter = iter->GetParent() ;
607 }
608
609 if (m_hScrollBar && m_hScrollBar->IsShown() )
610 {
611 hh -= MAC_SCROLLBAR_SIZE;
612 if ( h-y1 >= totH )
613 {
614 hh += 1 ;
615 }
616 }
617 if (m_vScrollBar && m_vScrollBar->IsShown() )
618 {
619 ww -= MAC_SCROLLBAR_SIZE;
620 if ( w-x1 >= totW )
621 {
622 ww += 1 ;
623 }
624 }
625 }
626 if(x) *x = ww;
627 if(y) *y = hh;
628 }
629
630
631 // ----------------------------------------------------------------------------
632 // tooltips
633 // ----------------------------------------------------------------------------
634
635 #if wxUSE_TOOLTIPS
636
637 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
638 {
639 wxWindowBase::DoSetToolTip(tooltip);
640
641 if ( m_tooltip )
642 m_tooltip->SetWindow(this);
643 }
644
645 #endif // wxUSE_TOOLTIPS
646
647 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
648 {
649 int former_x = m_x ;
650 int former_y = m_y ;
651 int former_w = m_width ;
652 int former_h = m_height ;
653
654 int actualWidth = width;
655 int actualHeight = height;
656 int actualX = x;
657 int actualY = y;
658
659 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
660 actualWidth = m_minWidth;
661 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
662 actualHeight = m_minHeight;
663 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
664 actualWidth = m_maxWidth;
665 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
666 actualHeight = m_maxHeight;
667
668 bool doMove = false ;
669 bool doResize = false ;
670
671 if ( actualX != former_x || actualY != former_y )
672 {
673 doMove = true ;
674 }
675 if ( actualWidth != former_w || actualHeight != former_h )
676 {
677 doResize = true ;
678 }
679
680 if ( doMove || doResize )
681 {
682 // erase former position
683
684 bool partialRepaint = false ;
685
686 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
687 {
688 wxPoint oldPos( m_x , m_y ) ;
689 wxPoint newPos( actualX , actualY ) ;
690 MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ;
691 MacWindowToRootWindow( &newPos.x , &newPos.y ) ;
692 if ( oldPos == newPos )
693 {
694 partialRepaint = true ;
695 RgnHandle oldRgn,newRgn,diffRgn ;
696 oldRgn = NewRgn() ;
697 newRgn = NewRgn() ;
698 diffRgn = NewRgn() ;
699 SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ;
700 SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ;
701 DiffRgn( newRgn , oldRgn , diffRgn ) ;
702 InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ;
703 DiffRgn( oldRgn , newRgn , diffRgn ) ;
704 InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ;
705 DisposeRgn(oldRgn) ;
706 DisposeRgn(newRgn) ;
707 DisposeRgn(diffRgn) ;
708 }
709 }
710
711 if ( !partialRepaint )
712 Refresh() ;
713
714 m_x = actualX ;
715 m_y = actualY ;
716 m_width = actualWidth ;
717 m_height = actualHeight ;
718
719 // update any low-level frame-relative positions
720
721 MacUpdateDimensions() ;
722 // erase new position
723
724 if ( !partialRepaint )
725 Refresh() ;
726 if ( doMove )
727 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
728
729 MacRepositionScrollBars() ;
730 if ( doMove )
731 {
732 wxPoint point(m_x, m_y);
733 wxMoveEvent event(point, m_windowId);
734 event.SetEventObject(this);
735 GetEventHandler()->ProcessEvent(event) ;
736 }
737 if ( doResize )
738 {
739 MacRepositionScrollBars() ;
740 wxSize size(m_width, m_height);
741 wxSizeEvent event(size, m_windowId);
742 event.SetEventObject(this);
743 GetEventHandler()->ProcessEvent(event);
744 }
745 }
746
747 }
748
749 // set the size of the window: if the dimensions are positive, just use them,
750 // but if any of them is equal to -1, it means that we must find the value for
751 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
752 // which case -1 is a valid value for x and y)
753 //
754 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
755 // the width/height to best suit our contents, otherwise we reuse the current
756 // width/height
757 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
758 {
759 // get the current size and position...
760 int currentX, currentY;
761 GetPosition(&currentX, &currentY);
762
763 int currentW,currentH;
764 GetSize(&currentW, &currentH);
765
766 // ... and don't do anything (avoiding flicker) if it's already ok
767 if ( x == currentX && y == currentY &&
768 width == currentW && height == currentH )
769 {
770 MacRepositionScrollBars() ; // we might have a real position shift
771 return;
772 }
773
774 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
775 x = currentX;
776 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
777 y = currentY;
778
779 AdjustForParentClientOrigin(x, y, sizeFlags);
780
781 wxSize size(-1, -1);
782 if ( width == -1 )
783 {
784 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
785 {
786 size = DoGetBestSize();
787 width = size.x;
788 }
789 else
790 {
791 // just take the current one
792 width = currentW;
793 }
794 }
795
796 if ( height == -1 )
797 {
798 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
799 {
800 if ( size.x == -1 )
801 {
802 size = DoGetBestSize();
803 }
804 //else: already called DoGetBestSize() above
805
806 height = size.y;
807 }
808 else
809 {
810 // just take the current one
811 height = currentH;
812 }
813 }
814
815 DoMoveWindow(x, y, width, height);
816
817 }
818 // For implementation purposes - sometimes decorations make the client area
819 // smaller
820
821 wxPoint wxWindowMac::GetClientAreaOrigin() const
822 {
823 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
824 }
825
826 void wxWindowMac::SetTitle(const wxString& title)
827 {
828 m_label = title ;
829 }
830
831 wxString wxWindowMac::GetTitle() const
832 {
833 return m_label ;
834 }
835
836 bool wxWindowMac::Show(bool show)
837 {
838 if ( !wxWindowBase::Show(show) )
839 return FALSE;
840
841 /*
842 WindowRef window = (WindowRef) MacGetRootWindow() ;
843 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
844 if ( win == NULL && win->m_isBeingDeleted )
845 return FALSE ;
846 */
847 MacSuperShown( show ) ;
848 Refresh() ;
849 /*
850 if ( !show )
851 {
852 if ( win && !win->m_isBeingDeleted )
853 Refresh() ;
854 }
855 else
856 {
857 Refresh() ;
858 }
859 */
860 return TRUE;
861 }
862
863 void wxWindowMac::MacSuperShown( bool show )
864 {
865 wxWindowListNode *node = GetChildren().GetFirst();
866 while ( node )
867 {
868 wxWindowMac *child = (wxWindowMac *)node->GetData();
869 if ( child->m_isShown )
870 child->MacSuperShown( show ) ;
871 node = node->GetNext();
872 }
873 }
874
875 void wxWindowMac::MacSuperEnabled( bool enabled )
876 {
877 if ( !IsTopLevel() )
878 {
879 // to be absolutely correct we'd have to invalidate (with eraseBkground
880 // because unter MacOSX the frames are drawn with an addXXX mode)
881 // the borders area
882 }
883 wxWindowListNode *node = GetChildren().GetFirst();
884 while ( node )
885 {
886 wxWindowMac *child = (wxWindowMac *)node->GetData();
887 if ( child->m_isShown )
888 child->MacSuperEnabled( enabled ) ;
889 node = node->GetNext();
890 }
891 }
892
893 bool wxWindowMac::MacIsReallyShown() const
894 {
895 if ( m_isShown && (m_parent != NULL) ) {
896 return m_parent->MacIsReallyShown();
897 }
898 return m_isShown;
899 /*
900 bool status = m_isShown ;
901 wxWindowMac * win = this ;
902 while ( status && win->m_parent != NULL )
903 {
904 win = win->m_parent ;
905 status = win->m_isShown ;
906 }
907 return status ;
908 */
909 }
910
911 int wxWindowMac::GetCharHeight() const
912 {
913 wxClientDC dc ( (wxWindowMac*)this ) ;
914 return dc.GetCharHeight() ;
915 }
916
917 int wxWindowMac::GetCharWidth() const
918 {
919 wxClientDC dc ( (wxWindowMac*)this ) ;
920 return dc.GetCharWidth() ;
921 }
922
923 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
924 int *descent, int *externalLeading, const wxFont *theFont ) const
925 {
926 const wxFont *fontToUse = theFont;
927 if ( !fontToUse )
928 fontToUse = &m_font;
929
930 wxClientDC dc( (wxWindowMac*) this ) ;
931 long lx,ly,ld,le ;
932 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
933 if ( externalLeading )
934 *externalLeading = le ;
935 if ( descent )
936 *descent = ld ;
937 if ( x )
938 *x = lx ;
939 if ( y )
940 *y = ly ;
941 }
942
943 /*
944 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
945 * we always intersect with the entire window, not only with the client area
946 */
947
948 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
949 {
950 if ( MacGetTopLevelWindow() == NULL )
951 return ;
952
953 wxPoint client = GetClientAreaOrigin();
954 int x1 = -client.x;
955 int y1 = -client.y;
956 int x2 = m_width - client.x;
957 int y2 = m_height - client.y;
958
959 if (IsKindOf( CLASSINFO(wxButton)))
960 {
961 // buttons have an "aura"
962 y1 -= 5;
963 x1 -= 5;
964 y2 += 5;
965 x2 += 5;
966 }
967
968 Rect clientrect = { y1, x1, y2, x2 };
969
970 if ( rect )
971 {
972 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
973 SectRect( &clientrect , &r , &clientrect ) ;
974 }
975
976 if ( !EmptyRect( &clientrect ) )
977 {
978 int top = 0 , left = 0 ;
979
980 MacClientToRootWindow( &left , &top ) ;
981 OffsetRect( &clientrect , left , top ) ;
982
983 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
984 }
985 }
986
987 #if wxUSE_CARET && WXWIN_COMPATIBILITY
988 // ---------------------------------------------------------------------------
989 // Caret manipulation
990 // ---------------------------------------------------------------------------
991
992 void wxWindowMac::CreateCaret(int w, int h)
993 {
994 SetCaret(new wxCaret(this, w, h));
995 }
996
997 void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
998 {
999 wxFAIL_MSG("not implemented");
1000 }
1001
1002 void wxWindowMac::ShowCaret(bool show)
1003 {
1004 wxCHECK_RET( m_caret, "no caret to show" );
1005
1006 m_caret->Show(show);
1007 }
1008
1009 void wxWindowMac::DestroyCaret()
1010 {
1011 SetCaret(NULL);
1012 }
1013
1014 void wxWindowMac::SetCaretPos(int x, int y)
1015 {
1016 wxCHECK_RET( m_caret, "no caret to move" );
1017
1018 m_caret->Move(x, y);
1019 }
1020
1021 void wxWindowMac::GetCaretPos(int *x, int *y) const
1022 {
1023 wxCHECK_RET( m_caret, "no caret to get position of" );
1024
1025 m_caret->GetPosition(x, y);
1026 }
1027 #endif // wxUSE_CARET
1028
1029 wxWindowMac *wxGetActiveWindow()
1030 {
1031 // actually this is a windows-only concept
1032 return NULL;
1033 }
1034
1035 // Coordinates relative to the window
1036 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1037 {
1038 // We really don't move the mouse programmatically under Mac.
1039 }
1040
1041 const wxBrush& wxWindowMac::MacGetBackgroundBrush()
1042 {
1043 if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1044 {
1045 m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ;
1046 }
1047 else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
1048 {
1049 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1050 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1051 // either a non gray background color or a non control window
1052
1053 WindowRef window = (WindowRef) MacGetRootWindow() ;
1054
1055 wxWindowMac* parent = GetParent() ;
1056 while( parent )
1057 {
1058 if ( parent->MacGetRootWindow() != window )
1059 {
1060 // we are in a different window on the mac system
1061 parent = NULL ;
1062 break ;
1063 }
1064
1065 {
1066 if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
1067 && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
1068 {
1069 // if we have any other colours in the hierarchy
1070 m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ;
1071 break ;
1072 }
1073 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1074 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1075 {
1076 Rect extent = { 0 , 0 , 0 , 0 } ;
1077 int x , y ;
1078 x = y = 0 ;
1079 wxSize size = parent->GetSize() ;
1080 parent->MacClientToRootWindow( &x , &y ) ;
1081 extent.left = x ;
1082 extent.top = y ;
1083 extent.top-- ;
1084 extent.right = x + size.x ;
1085 extent.bottom = y + size.y ;
1086 m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
1087 break ;
1088 }
1089 }
1090 parent = parent->GetParent() ;
1091 }
1092 if ( !parent )
1093 {
1094 m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive
1095 }
1096 }
1097 else
1098 {
1099 m_macBackgroundBrush.SetColour( m_backgroundColour ) ;
1100 }
1101
1102 return m_macBackgroundBrush ;
1103 }
1104
1105 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1106 {
1107 event.GetDC()->Clear() ;
1108 }
1109
1110 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1111 {
1112 wxWindowDC dc(this) ;
1113 wxMacPortSetter helper(&dc) ;
1114
1115 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1116 }
1117
1118 int wxWindowMac::GetScrollPos(int orient) const
1119 {
1120 if ( orient == wxHORIZONTAL )
1121 {
1122 if ( m_hScrollBar )
1123 return m_hScrollBar->GetThumbPosition() ;
1124 }
1125 else
1126 {
1127 if ( m_vScrollBar )
1128 return m_vScrollBar->GetThumbPosition() ;
1129 }
1130 return 0;
1131 }
1132
1133 // This now returns the whole range, not just the number
1134 // of positions that we can scroll.
1135 int wxWindowMac::GetScrollRange(int orient) const
1136 {
1137 if ( orient == wxHORIZONTAL )
1138 {
1139 if ( m_hScrollBar )
1140 return m_hScrollBar->GetRange() ;
1141 }
1142 else
1143 {
1144 if ( m_vScrollBar )
1145 return m_vScrollBar->GetRange() ;
1146 }
1147 return 0;
1148 }
1149
1150 int wxWindowMac::GetScrollThumb(int orient) const
1151 {
1152 if ( orient == wxHORIZONTAL )
1153 {
1154 if ( m_hScrollBar )
1155 return m_hScrollBar->GetThumbSize() ;
1156 }
1157 else
1158 {
1159 if ( m_vScrollBar )
1160 return m_vScrollBar->GetThumbSize() ;
1161 }
1162 return 0;
1163 }
1164
1165 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1166 {
1167 if ( orient == wxHORIZONTAL )
1168 {
1169 if ( m_hScrollBar )
1170 m_hScrollBar->SetThumbPosition( pos ) ;
1171 }
1172 else
1173 {
1174 if ( m_vScrollBar )
1175 m_vScrollBar->SetThumbPosition( pos ) ;
1176 }
1177 }
1178
1179 void wxWindowMac::MacPaintBorders( int left , int top )
1180 {
1181 if( IsTopLevel() )
1182 return ;
1183
1184 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1185 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1186 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1187 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1188 PenNormal() ;
1189
1190 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1191 {
1192 #if wxMAC_USE_THEME_BORDER
1193 Rect rect = { top , left , m_height + top , m_width + left } ;
1194 SInt32 border = 0 ;
1195 /*
1196 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1197 InsetRect( &rect , border , border );
1198 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1199 */
1200
1201 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1202 #else
1203 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1204 RGBForeColor( &face );
1205 MoveTo( left + 0 , top + m_height - 2 );
1206 LineTo( left + 0 , top + 0 );
1207 LineTo( left + m_width - 2 , top + 0 );
1208
1209 MoveTo( left + 2 , top + m_height - 3 );
1210 LineTo( left + m_width - 3 , top + m_height - 3 );
1211 LineTo( left + m_width - 3 , top + 2 );
1212
1213 RGBForeColor( sunken ? &face : &black );
1214 MoveTo( left + 0 , top + m_height - 1 );
1215 LineTo( left + m_width - 1 , top + m_height - 1 );
1216 LineTo( left + m_width - 1 , top + 0 );
1217
1218 RGBForeColor( sunken ? &shadow : &white );
1219 MoveTo( left + 1 , top + m_height - 3 );
1220 LineTo( left + 1, top + 1 );
1221 LineTo( left + m_width - 3 , top + 1 );
1222
1223 RGBForeColor( sunken ? &white : &shadow );
1224 MoveTo( left + 1 , top + m_height - 2 );
1225 LineTo( left + m_width - 2 , top + m_height - 2 );
1226 LineTo( left + m_width - 2 , top + 1 );
1227
1228 RGBForeColor( sunken ? &black : &face );
1229 MoveTo( left + 2 , top + m_height - 4 );
1230 LineTo( left + 2 , top + 2 );
1231 LineTo( left + m_width - 4 , top + 2 );
1232 #endif
1233 }
1234 else if (HasFlag(wxSIMPLE_BORDER))
1235 {
1236 Rect rect = { top , left , m_height + top , m_width + left } ;
1237 RGBForeColor( &black ) ;
1238 FrameRect( &rect ) ;
1239 }
1240 }
1241
1242 void wxWindowMac::RemoveChild( wxWindowBase *child )
1243 {
1244 if ( child == m_hScrollBar )
1245 m_hScrollBar = NULL ;
1246 if ( child == m_vScrollBar )
1247 m_vScrollBar = NULL ;
1248
1249 wxWindowBase::RemoveChild( child ) ;
1250 }
1251
1252 // New function that will replace some of the above.
1253 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1254 int range, bool refresh)
1255 {
1256 if ( orient == wxHORIZONTAL )
1257 {
1258 if ( m_hScrollBar )
1259 {
1260 if ( range == 0 || thumbVisible >= range )
1261 {
1262 if ( m_hScrollBar->IsShown() )
1263 m_hScrollBar->Show(false) ;
1264 }
1265 else
1266 {
1267 if ( !m_hScrollBar->IsShown() )
1268 m_hScrollBar->Show(true) ;
1269 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1270 }
1271 }
1272 }
1273 else
1274 {
1275 if ( m_vScrollBar )
1276 {
1277 if ( range == 0 || thumbVisible >= range )
1278 {
1279 if ( m_vScrollBar->IsShown() )
1280 m_vScrollBar->Show(false) ;
1281 }
1282 else
1283 {
1284 if ( !m_vScrollBar->IsShown() )
1285 m_vScrollBar->Show(true) ;
1286 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1287 }
1288 }
1289 }
1290 MacRepositionScrollBars() ;
1291 }
1292
1293 // Does a physical scroll
1294 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1295 {
1296 wxClientDC dc(this) ;
1297 wxMacPortSetter helper(&dc) ;
1298
1299 {
1300 int width , height ;
1301 GetClientSize( &width , &height ) ;
1302
1303 Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ;
1304 RgnHandle updateRgn = NewRgn() ;
1305 ClipRect( &scrollrect ) ;
1306 if ( rect )
1307 {
1308 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
1309 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
1310 SectRect( &scrollrect , &r , &scrollrect ) ;
1311 }
1312 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1313 InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ;
1314 DisposeRgn( updateRgn ) ;
1315 }
1316
1317 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1318 {
1319 wxWindowMac *child = (wxWindowMac*)node->GetData();
1320 if (child == m_vScrollBar) continue;
1321 if (child == m_hScrollBar) continue;
1322 if (child->IsTopLevel()) continue;
1323
1324 int x,y;
1325 child->GetPosition( &x, &y );
1326 int w,h;
1327 child->GetSize( &w, &h );
1328 child->SetSize( x+dx, y+dy, w, h );
1329 }
1330
1331 }
1332
1333 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
1334 {
1335 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1336 {
1337 wxScrollWinEvent wevent;
1338 wevent.SetPosition(event.GetPosition());
1339 wevent.SetOrientation(event.GetOrientation());
1340 wevent.m_eventObject = this;
1341
1342 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1343 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1344 } else
1345 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1346 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1347 } else
1348 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1349 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1350 } else
1351 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1352 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1353 } else
1354 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1355 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1356 } else
1357 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1358 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1359 } else
1360 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1361 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1362 }
1363
1364 GetEventHandler()->ProcessEvent(wevent);
1365 }
1366 }
1367
1368 // Get the window with the focus
1369 wxWindowMac *wxWindowBase::FindFocus()
1370 {
1371 return gFocusWindow ;
1372 }
1373
1374 #if WXWIN_COMPATIBILITY
1375 // If nothing defined for this, try the parent.
1376 // E.g. we may be a button loaded from a resource, with no callback function
1377 // defined.
1378 void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
1379 {
1380 if ( GetEventHandler()->ProcessEvent(event) )
1381 return;
1382 if ( m_parent )
1383 m_parent->GetEventHandler()->OnCommand(win, event);
1384 }
1385 #endif // WXWIN_COMPATIBILITY_2
1386
1387 #if WXWIN_COMPATIBILITY
1388 wxObject* wxWindowMac::GetChild(int number) const
1389 {
1390 // Return a pointer to the Nth object in the Panel
1391 wxNode *node = GetChildren().GetFirst();
1392 int n = number;
1393 while (node && n--)
1394 node = node->GetNext();
1395 if ( node )
1396 {
1397 wxObject *obj = (wxObject *)node->GetData();
1398 return(obj);
1399 }
1400 else
1401 return NULL;
1402 }
1403 #endif // WXWIN_COMPATIBILITY
1404
1405 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
1406 {
1407 // panel wants to track the window which was the last to have focus in it,
1408 // so we want to set ourselves as the window which last had focus
1409 //
1410 // notice that it's also important to do it upwards the tree becaus
1411 // otherwise when the top level panel gets focus, it won't set it back to
1412 // us, but to some other sibling
1413
1414 // CS:don't know if this is still needed:
1415 //wxChildFocusEvent eventFocus(this);
1416 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1417
1418 event.Skip();
1419 }
1420
1421 void wxWindowMac::Clear()
1422 {
1423 wxClientDC dc(this);
1424 wxBrush brush(GetBackgroundColour(), wxSOLID);
1425 dc.SetBackground(brush);
1426 dc.Clear();
1427 }
1428
1429 // Setup background and foreground colours correctly
1430 void wxWindowMac::SetupColours()
1431 {
1432 if ( GetParent() )
1433 SetBackgroundColour(GetParent()->GetBackgroundColour());
1434 }
1435
1436 void wxWindowMac::OnIdle(wxIdleEvent& event)
1437 {
1438 /*
1439 // Check if we need to send a LEAVE event
1440 if (m_mouseInWindow)
1441 {
1442 POINT pt;
1443 ::GetCursorPos(&pt);
1444 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1445 {
1446 // Generate a LEAVE event
1447 m_mouseInWindow = FALSE;
1448 MSWOnMouseLeave(pt.x, pt.y, 0);
1449 }
1450 }
1451 */
1452
1453 // This calls the UI-update mechanism (querying windows for
1454 // menu/toolbar/control state information)
1455 UpdateWindowUI();
1456 }
1457
1458 // Raise the window to the top of the Z order
1459 void wxWindowMac::Raise()
1460 {
1461 }
1462
1463 // Lower the window to the bottom of the Z order
1464 void wxWindowMac::Lower()
1465 {
1466 }
1467
1468 void wxWindowMac::DoSetClientSize(int width, int height)
1469 {
1470 if ( width != -1 || height != -1 )
1471 {
1472
1473 if ( width != -1 && m_vScrollBar )
1474 width += MAC_SCROLLBAR_SIZE ;
1475 if ( height != -1 && m_vScrollBar )
1476 height += MAC_SCROLLBAR_SIZE ;
1477
1478 width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1479 height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1480
1481 DoSetSize( -1 , -1 , width , height ) ;
1482 }
1483 }
1484
1485
1486 wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ;
1487
1488 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
1489 {
1490 if ( IsTopLevel() )
1491 {
1492 if ((point.x < 0) || (point.y < 0) ||
1493 (point.x > (m_width)) || (point.y > (m_height)))
1494 return FALSE;
1495 }
1496 else
1497 {
1498 if ((point.x < m_x) || (point.y < m_y) ||
1499 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1500 return FALSE;
1501 }
1502
1503 WindowRef window = (WindowRef) MacGetRootWindow() ;
1504
1505 wxPoint newPoint( point ) ;
1506
1507 if ( !IsTopLevel() )
1508 {
1509 newPoint.x -= m_x;
1510 newPoint.y -= m_y;
1511 }
1512
1513 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1514 {
1515 wxWindowMac *child = (wxWindowMac*)node->GetData();
1516 // added the m_isShown test --dmazzoni
1517 if ( child->MacGetRootWindow() == window && child->m_isShown )
1518 {
1519 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1520 return TRUE;
1521 }
1522 }
1523
1524 *outWin = this ;
1525 return TRUE;
1526 }
1527
1528 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
1529 {
1530 WindowRef window ;
1531
1532 Point pt = { screenpoint.y , screenpoint.x } ;
1533 if ( ::FindWindow( pt , &window ) == 3 )
1534 {
1535
1536 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
1537 if ( win )
1538 {
1539 // No, this yields the CLIENT are, we need the whole frame. RR.
1540 // point = win->ScreenToClient( point ) ;
1541
1542 GrafPtr port;
1543 ::GetPort( &port ) ;
1544 ::SetPort( UMAGetWindowPort( window ) ) ;
1545 ::GlobalToLocal( &pt ) ;
1546 ::SetPort( port ) ;
1547
1548 wxPoint point( pt.h, pt.v ) ;
1549
1550 return win->MacGetWindowFromPointSub( point , outWin ) ;
1551 }
1552 }
1553 return FALSE ;
1554 }
1555
1556 static wxWindow *gs_lastWhich = NULL;
1557
1558 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
1559 {
1560 // first trigger a set cursor event
1561
1562 wxPoint clientorigin = GetClientAreaOrigin() ;
1563 wxSize clientsize = GetClientSize() ;
1564 wxCursor cursor ;
1565 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1566 {
1567 wxSetCursorEvent event( pt.x , pt.y );
1568
1569 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
1570 if ( processedEvtSetCursor && event.HasCursor() )
1571 {
1572 cursor = event.GetCursor() ;
1573 }
1574 else
1575 {
1576
1577 // the test for processedEvtSetCursor is here to prevent using m_cursor
1578 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1579 // it - this is a way to say that our cursor shouldn't be used for this
1580 // point
1581 if ( !processedEvtSetCursor && m_cursor.Ok() )
1582 {
1583 cursor = m_cursor ;
1584 }
1585 if ( wxIsBusy() )
1586 {
1587 }
1588 else
1589 {
1590 if ( !GetParent() )
1591 cursor = *wxSTANDARD_CURSOR ;
1592 }
1593 }
1594 if ( cursor.Ok() )
1595 cursor.MacInstall() ;
1596 }
1597 return cursor.Ok() ;
1598 }
1599
1600 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
1601 {
1602 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1603 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1604 return FALSE;
1605
1606
1607 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1608 return FALSE ;
1609
1610 WindowRef window = (WindowRef) MacGetRootWindow() ;
1611
1612 event.m_x -= m_x;
1613 event.m_y -= m_y;
1614
1615 int x = event.m_x ;
1616 int y = event.m_y ;
1617
1618 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1619 {
1620 wxWindowMac *child = (wxWindowMac*)node->GetData();
1621 if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
1622 {
1623 if (child->MacDispatchMouseEvent(event))
1624 return TRUE;
1625 }
1626 }
1627
1628 wxWindow* cursorTarget = this ;
1629 wxPoint cursorPoint( x , y ) ;
1630
1631 while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
1632 {
1633 cursorTarget = cursorTarget->GetParent() ;
1634 if ( cursorTarget )
1635 cursorPoint += cursorTarget->GetPosition() ;
1636 }
1637 event.m_x = x ;
1638 event.m_y = y ;
1639 event.SetEventObject( this ) ;
1640
1641 if ( event.GetEventType() == wxEVT_LEFT_DOWN )
1642 {
1643 // set focus to this window
1644 if (AcceptsFocus() && FindFocus()!=this)
1645 SetFocus();
1646 }
1647
1648 #if wxUSE_TOOLTIPS
1649 if ( event.GetEventType() == wxEVT_MOTION
1650 || event.GetEventType() == wxEVT_ENTER_WINDOW
1651 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1652 wxToolTip::RelayEvent( this , event);
1653 #endif // wxUSE_TOOLTIPS
1654
1655 if (gs_lastWhich != this)
1656 {
1657 gs_lastWhich = this;
1658
1659 // Double clicks must always occur on the same window
1660 if (event.GetEventType() == wxEVT_LEFT_DCLICK)
1661 event.SetEventType( wxEVT_LEFT_DOWN );
1662 if (event.GetEventType() == wxEVT_RIGHT_DCLICK)
1663 event.SetEventType( wxEVT_RIGHT_DOWN );
1664
1665 // Same for mouse up events
1666 if (event.GetEventType() == wxEVT_LEFT_UP)
1667 return TRUE;
1668 if (event.GetEventType() == wxEVT_RIGHT_UP)
1669 return TRUE;
1670 }
1671
1672 GetEventHandler()->ProcessEvent( event ) ;
1673
1674 return TRUE;
1675 }
1676
1677 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
1678 {
1679 if ( m_tooltip )
1680 {
1681 return m_tooltip->GetTip() ;
1682 }
1683 return "" ;
1684 }
1685
1686 void wxWindowMac::Update()
1687 {
1688 wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
1689 if ( win )
1690 {
1691 win->MacUpdate( 0 ) ;
1692 #if TARGET_API_MAC_CARBON
1693 if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) )
1694 {
1695 QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ;
1696 }
1697 #endif
1698 }
1699 }
1700
1701 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
1702 {
1703 wxTopLevelWindowMac* win = NULL ;
1704 WindowRef window = (WindowRef) MacGetRootWindow() ;
1705 if ( window )
1706 {
1707 win = wxFindWinFromMacWindow( window ) ;
1708 }
1709 return win ;
1710 }
1711
1712 const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings )
1713 {
1714 RgnHandle visRgn = NewRgn() ;
1715 RgnHandle tempRgn = NewRgn() ;
1716 RgnHandle tempStaticBoxRgn = NewRgn() ;
1717
1718 SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
1719
1720 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1721 if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
1722 {
1723 int borderTop = 14 ;
1724 int borderOther = 4 ;
1725
1726 SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
1727 DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ;
1728 }
1729
1730 if ( !IsTopLevel() )
1731 {
1732 wxWindow* parent = GetParent() ;
1733 while( parent )
1734 {
1735 wxSize size = parent->GetSize() ;
1736 int x , y ;
1737 x = y = 0 ;
1738 parent->MacWindowToRootWindow( &x, &y ) ;
1739 MacRootWindowToWindow( &x , &y ) ;
1740
1741 SetRectRgn( tempRgn ,
1742 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
1743 x + size.x - parent->MacGetRightBorderSize(),
1744 y + size.y - parent->MacGetBottomBorderSize()) ;
1745
1746 SectRgn( visRgn , tempRgn , visRgn ) ;
1747 if ( parent->IsTopLevel() )
1748 break ;
1749 parent = parent->GetParent() ;
1750 }
1751 }
1752 if ( respectChildrenAndSiblings )
1753 {
1754 if ( GetWindowStyle() & wxCLIP_CHILDREN )
1755 {
1756 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1757 {
1758 wxWindowMac *child = (wxWindowMac*)node->GetData();
1759
1760 if ( !child->IsTopLevel() && child->IsShown() )
1761 {
1762 SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1763 if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1764 {
1765 int borderTop = 14 ;
1766 int borderOther = 4 ;
1767
1768 SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ;
1769 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1770 }
1771 DiffRgn( visRgn , tempRgn , visRgn ) ;
1772 }
1773 }
1774 }
1775
1776 if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
1777 {
1778 bool thisWindowThrough = false ;
1779 for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext())
1780 {
1781 wxWindowMac *sibling = (wxWindowMac*)node->GetData();
1782 if ( sibling == this )
1783 {
1784 thisWindowThrough = true ;
1785 continue ;
1786 }
1787 if( !thisWindowThrough )
1788 {
1789 continue ;
1790 }
1791
1792 if ( !sibling->IsTopLevel() && sibling->IsShown() )
1793 {
1794 SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ;
1795 if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) )
1796 {
1797 int borderTop = 14 ;
1798 int borderOther = 4 ;
1799
1800 SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ;
1801 DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ;
1802 }
1803 DiffRgn( visRgn , tempRgn , visRgn ) ;
1804 }
1805 }
1806 }
1807 }
1808 m_macVisibleRegion = visRgn ;
1809 DisposeRgn( visRgn ) ;
1810 DisposeRgn( tempRgn ) ;
1811 DisposeRgn( tempStaticBoxRgn ) ;
1812 return m_macVisibleRegion ;
1813 }
1814
1815 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
1816 {
1817 RgnHandle updatergn = (RgnHandle) updatergnr ;
1818 // updatergn is always already clipped to our boundaries
1819 // it is in window coordinates, not in client coordinates
1820
1821 WindowRef window = (WindowRef) MacGetRootWindow() ;
1822
1823 {
1824 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1825 RgnHandle ownUpdateRgn = NewRgn() ;
1826 CopyRgn( updatergn , ownUpdateRgn ) ;
1827
1828 SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
1829
1830 // newupdate is the update region in client coordinates
1831 RgnHandle newupdate = NewRgn() ;
1832 wxSize point = GetClientSize() ;
1833 wxPoint origin = GetClientAreaOrigin() ;
1834 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1835 SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
1836 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1837 m_updateRegion = newupdate ;
1838 DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
1839
1840 if ( erase && !EmptyRgn(ownUpdateRgn) )
1841 {
1842 wxWindowDC dc(this);
1843 if (!EmptyRgn(ownUpdateRgn))
1844 dc.SetClippingRegion(wxRegion(ownUpdateRgn));
1845 wxEraseEvent eevent( GetId(), &dc );
1846 eevent.SetEventObject( this );
1847 GetEventHandler()->ProcessEvent( eevent );
1848
1849 wxNcPaintEvent eventNc( GetId() );
1850 eventNc.SetEventObject( this );
1851 GetEventHandler()->ProcessEvent( eventNc );
1852 }
1853 DisposeRgn( ownUpdateRgn ) ;
1854 if ( !m_updateRegion.Empty() )
1855 {
1856 wxPaintEvent event;
1857 event.m_timeStamp = time ;
1858 event.SetEventObject(this);
1859 GetEventHandler()->ProcessEvent(event);
1860 }
1861 }
1862
1863 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1864
1865 RgnHandle childupdate = NewRgn() ;
1866 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
1867 {
1868 // calculate the update region for the child windows by intersecting the window rectangle with our own
1869 // passed in update region and then offset it to be client-wise window coordinates again
1870 wxWindowMac *child = (wxWindowMac*)node->GetData();
1871 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1872 SectRgn( childupdate , updatergn , childupdate ) ;
1873 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1874 if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
1875 {
1876 // because dialogs may also be children
1877 child->MacRedraw( childupdate , time , erase ) ;
1878 }
1879 }
1880 DisposeRgn( childupdate ) ;
1881 // eventually a draw grow box here
1882
1883 }
1884
1885 WXHWND wxWindowMac::MacGetRootWindow() const
1886 {
1887 wxWindowMac *iter = (wxWindowMac*)this ;
1888
1889 while( iter )
1890 {
1891 if ( iter->IsTopLevel() )
1892 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
1893
1894 iter = iter->GetParent() ;
1895 }
1896 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1897 return NULL ;
1898 }
1899
1900 void wxWindowMac::MacCreateScrollBars( long style )
1901 {
1902 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1903
1904 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1905 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1906 int width, height ;
1907 GetClientSize( &width , &height ) ;
1908
1909 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1910 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1911 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1912 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1913
1914 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1915 vSize , wxVERTICAL);
1916
1917 if ( style & wxVSCROLL )
1918 {
1919
1920 }
1921 else
1922 {
1923 m_vScrollBar->Show(false) ;
1924 }
1925 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1926 hSize , wxHORIZONTAL);
1927 if ( style & wxHSCROLL )
1928 {
1929 }
1930 else
1931 {
1932 m_hScrollBar->Show(false) ;
1933 }
1934
1935 // because the create does not take into account the client area origin
1936 MacRepositionScrollBars() ; // we might have a real position shift
1937 }
1938
1939 void wxWindowMac::MacRepositionScrollBars()
1940 {
1941 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1942 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1943
1944 // get real client area
1945
1946 int width = m_width ;
1947 int height = m_height ;
1948
1949 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
1950 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
1951
1952 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1953 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1954 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1955 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1956
1957 int x = 0 ;
1958 int y = 0 ;
1959 int w = m_width ;
1960 int h = m_height ;
1961
1962 MacClientToRootWindow( &x , &y ) ;
1963 MacClientToRootWindow( &w , &h ) ;
1964
1965 wxWindowMac *iter = (wxWindowMac*)this ;
1966
1967 int totW = 10000 , totH = 10000;
1968 while( iter )
1969 {
1970 if ( iter->IsTopLevel() )
1971 {
1972 totW = iter->m_width ;
1973 totH = iter->m_height ;
1974 break ;
1975 }
1976
1977 iter = iter->GetParent() ;
1978 }
1979
1980 if ( x == 0 )
1981 {
1982 hPoint.x = -1 ;
1983 hSize.x += 1 ;
1984 }
1985 if ( y == 0 )
1986 {
1987 vPoint.y = -1 ;
1988 vSize.y += 1 ;
1989 }
1990
1991 if ( w-x >= totW )
1992 {
1993 hSize.x += 1 ;
1994 vPoint.x += 1 ;
1995 }
1996
1997 if ( h-y >= totH )
1998 {
1999 vSize.y += 1 ;
2000 hPoint.y += 1 ;
2001 }
2002
2003 if ( m_vScrollBar )
2004 {
2005 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2006 }
2007 if ( m_hScrollBar )
2008 {
2009 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2010 }
2011 }
2012
2013 bool wxWindowMac::AcceptsFocus() const
2014 {
2015 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2016 }
2017
2018 WXWidget wxWindowMac::MacGetContainerForEmbedding()
2019 {
2020 return GetParent()->MacGetContainerForEmbedding() ;
2021 }
2022
2023 void wxWindowMac::MacSuperChangedPosition()
2024 {
2025 // only window-absolute structures have to be moved i.e. controls
2026
2027 wxWindowListNode *node = GetChildren().GetFirst();
2028 while ( node )
2029 {
2030 wxWindowMac *child = (wxWindowMac *)node->GetData();
2031 child->MacSuperChangedPosition() ;
2032 node = node->GetNext();
2033 }
2034 }
2035
2036 void wxWindowMac::MacTopLevelWindowChangedPosition()
2037 {
2038 // only screen-absolute structures have to be moved i.e. glcanvas
2039
2040 wxWindowListNode *node = GetChildren().GetFirst();
2041 while ( node )
2042 {
2043 wxWindowMac *child = (wxWindowMac *)node->GetData();
2044 child->MacTopLevelWindowChangedPosition() ;
2045 node = node->GetNext();
2046 }
2047 }
2048 long wxWindowMac::MacGetLeftBorderSize( ) const
2049 {
2050 if( IsTopLevel() )
2051 return 0 ;
2052
2053 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2054 {
2055 SInt32 border = 3 ;
2056 #if wxMAC_USE_THEME_BORDER
2057 #if TARGET_CARBON
2058 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2059 #endif
2060 #endif
2061 return border ;
2062 }
2063 else if ( m_windowStyle &wxDOUBLE_BORDER)
2064 {
2065 SInt32 border = 3 ;
2066 #if wxMAC_USE_THEME_BORDER
2067 #if TARGET_CARBON
2068 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2069 #endif
2070 #endif
2071 return border ;
2072 }
2073 else if (m_windowStyle &wxSIMPLE_BORDER)
2074 {
2075 return 1 ;
2076 }
2077 return 0 ;
2078 }
2079
2080 long wxWindowMac::MacGetRightBorderSize( ) const
2081 {
2082 // they are all symmetric in mac themes
2083 return MacGetLeftBorderSize() ;
2084 }
2085
2086 long wxWindowMac::MacGetTopBorderSize( ) const
2087 {
2088 // they are all symmetric in mac themes
2089 return MacGetLeftBorderSize() ;
2090 }
2091
2092 long wxWindowMac::MacGetBottomBorderSize( ) const
2093 {
2094 // they are all symmetric in mac themes
2095 return MacGetLeftBorderSize() ;
2096 }
2097
2098 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2099 {
2100 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2101 }
2102
2103 // Find the wxWindowMac at the current mouse position, returning the mouse
2104 // position.
2105 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2106 {
2107 pt = wxGetMousePosition();
2108 wxWindowMac* found = wxFindWindowAtPoint(pt);
2109 return found;
2110 }
2111
2112 // Get the current mouse position.
2113 wxPoint wxGetMousePosition()
2114 {
2115 int x, y;
2116 wxGetMousePosition(& x, & y);
2117 return wxPoint(x, y);
2118 }
2119
2120 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2121 {
2122 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2123 {
2124 // copied from wxGTK : CS
2125 // generate a "context menu" event: this is similar to wxEVT_RIGHT_UP
2126 // except that:
2127 //
2128 // (a) it's a command event and so is propagated to the parent
2129 // (b) under MSW it can be generated from kbd too
2130 // (c) it uses screen coords (because of (a))
2131 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2132 this->GetId(),
2133 this->ClientToScreen(event.GetPosition()));
2134 this->GetEventHandler()->ProcessEvent(evtCtx);
2135 }
2136 else
2137 {
2138 event.Skip() ;
2139 }
2140 }
2141