]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
changed argument types (replaced long with wxCoord)
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
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 "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/dc.h"
19 #include "wx/dcclient.h"
20 #include "wx/utils.h"
21 #include "wx/app.h"
22 #include "wx/panel.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/frame.h"
30 #include "wx/notebook.h"
31 #include "wx/tabctrl.h"
32 #include "wx/tooltip.h"
33 // TODO remove the line below, just for lookup-up convenience CS
34 #include "wx/mac/window.h"
35
36 #include "wx/menuitem.h"
37 #include "wx/log.h"
38
39 #if wxUSE_CARET
40 #include "wx/caret.h"
41 #endif // wxUSE_CARET
42
43 #define wxWINDOW_HSCROLL 5998
44 #define wxWINDOW_VSCROLL 5997
45 #define MAC_SCROLLBAR_SIZE 16
46
47 #include <wx/mac/uma.h>
48
49 #if wxUSE_DRAG_AND_DROP
50 #include "wx/dnd.h"
51 #endif
52
53 #include <string.h>
54
55 extern wxList wxPendingDelete;
56 wxWindow* gFocusWindow = NULL ;
57
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
60 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
61 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
62 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
63 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
64 EVT_IDLE(wxWindow::OnIdle)
65 // EVT_SCROLL(wxWindow::OnScroll)
66 END_EVENT_TABLE()
67
68 #endif
69
70
71
72 // ===========================================================================
73 // implementation
74 // ===========================================================================
75
76 // ---------------------------------------------------------------------------
77 // wxWindow utility functions
78 // ---------------------------------------------------------------------------
79
80 // Find an item given the Macintosh Window Reference
81
82 wxList *wxWinMacWindowList = NULL;
83 wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef)
84 {
85 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
86 if (!node)
87 return NULL;
88 return (wxWindow *)node->Data();
89 }
90
91 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win)
92 {
93 // adding NULL WindowRef is (first) surely a result of an error and
94 // (secondly) breaks menu command processing
95 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
96
97 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
98 wxWinMacWindowList->Append((long)inWindowRef, win);
99 }
100
101 void wxRemoveMacWindowAssociation(wxWindow *win)
102 {
103 wxWinMacWindowList->DeleteObject(win);
104 }
105
106 // ----------------------------------------------------------------------------
107 // constructors and such
108 // ----------------------------------------------------------------------------
109
110 void wxWindow::Init()
111 {
112 // generic
113 InitBase();
114
115 // MSW specific
116 m_doubleClickAllowed = 0;
117 m_winCaptured = FALSE;
118
119 m_isBeingDeleted = FALSE;
120
121 m_useCtl3D = FALSE;
122 m_mouseInWindow = FALSE;
123
124 m_xThumbSize = 0;
125 m_yThumbSize = 0;
126 m_backgroundTransparent = FALSE;
127
128 // as all windows are created with WS_VISIBLE style...
129 m_isShown = TRUE;
130
131 m_macWindowData = NULL ;
132
133 m_x = 0;
134 m_y = 0 ;
135 m_width = 0 ;
136 m_height = 0 ;
137
138 m_hScrollBar = NULL ;
139 m_vScrollBar = NULL ;
140
141 #if wxUSE_DRAG_AND_DROP
142 m_pDropTarget = NULL;
143 #endif
144 }
145
146 // Destructor
147 wxWindow::~wxWindow()
148 {
149 m_isBeingDeleted = TRUE;
150
151 if ( s_lastMouseWindow == this )
152 {
153 s_lastMouseWindow = NULL ;
154 }
155
156 if ( gFocusWindow == this )
157 {
158 gFocusWindow = NULL ;
159 }
160
161 if ( m_parent )
162 m_parent->RemoveChild(this);
163
164 DestroyChildren();
165
166 if ( m_macWindowData )
167 {
168 wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ;
169 UMADisposeWindow( m_macWindowData->m_macWindow ) ;
170 delete m_macWindowData ;
171 wxRemoveMacWindowAssociation( this ) ;
172 }
173 }
174
175 // Constructor
176 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
177 const wxPoint& pos,
178 const wxSize& size,
179 long style,
180 const wxString& name)
181 {
182 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
183
184 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
185 return FALSE;
186
187 parent->AddChild(this);
188
189 m_x = (int)pos.x;
190 m_y = (int)pos.y;
191 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
192 m_width = WidthDefault( size.x );
193 m_height = HeightDefault( size.y ) ;
194
195 if ( ! IsKindOf( CLASSINFO ( wxControl ) ) )
196 {
197 MacCreateScrollBars( style ) ;
198 }
199
200 return TRUE;
201 }
202
203 void wxWindow::SetFocus()
204 {
205 if ( AcceptsFocus() )
206 {
207 if (gFocusWindow )
208 {
209 #if wxUSE_CARET
210 // Deal with caret
211 if ( gFocusWindow->m_caret )
212 {
213 gFocusWindow->m_caret->OnKillFocus();
214 }
215 #endif // wxUSE_CARET
216 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
217 if ( control && control->GetMacControl() )
218 {
219 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
220 control->MacRedrawControl() ;
221 }
222 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
223 event.SetEventObject(gFocusWindow);
224 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
225 }
226 gFocusWindow = this ;
227 {
228 #if wxUSE_CARET
229 // Deal with caret
230 if ( m_caret )
231 {
232 m_caret->OnSetFocus();
233 }
234 #endif // wxUSE_CARET
235 // panel wants to track the window which was the last to have focus in it
236 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
237 if ( panel )
238 {
239 panel->SetLastFocus(this);
240 }
241 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
242 if ( control && control->GetMacControl() )
243 {
244 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
245 }
246
247 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
248 event.SetEventObject(this);
249 GetEventHandler()->ProcessEvent(event) ;
250 }
251 }
252 }
253
254 bool wxWindow::Enable(bool enable)
255 {
256 if ( !wxWindowBase::Enable(enable) )
257 return FALSE;
258
259 wxWindowList::Node *node = GetChildren().GetFirst();
260 while ( node )
261 {
262 wxWindow *child = node->GetData();
263 child->Enable(enable);
264
265 node = node->GetNext();
266 }
267
268 return TRUE;
269 }
270
271 void wxWindow::CaptureMouse()
272 {
273 wxTheApp->s_captureWindow = this ;
274 }
275
276 void wxWindow::ReleaseMouse()
277 {
278 wxTheApp->s_captureWindow = NULL ;
279 }
280
281 #if wxUSE_DRAG_AND_DROP
282
283 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
284 {
285 if ( m_pDropTarget != 0 ) {
286 delete m_pDropTarget;
287 }
288
289 m_pDropTarget = pDropTarget;
290 if ( m_pDropTarget != 0 )
291 {
292 // TODO
293 }
294 }
295
296 #endif
297
298 // Old style file-manager drag&drop
299 void wxWindow::DragAcceptFiles(bool accept)
300 {
301 // TODO
302 }
303
304 // Get total size
305 void wxWindow::DoGetSize(int *x, int *y) const
306 {
307 *x = m_width ;
308 *y = m_height ;
309 }
310
311 void wxWindow::DoGetPosition(int *x, int *y) const
312 {
313 *x = m_x ;
314 *y = m_y ;
315 if (GetParent())
316 {
317 wxPoint pt(GetParent()->GetClientAreaOrigin());
318 *x -= pt.x;
319 *y -= pt.y;
320 }
321 }
322
323
324 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
325 {
326 menu->SetInvokingWindow(this);
327 menu->UpdateUI();
328 ClientToScreen( &x , &y ) ;
329
330 ::InsertMenu( menu->GetHMenu() , -1 ) ;
331 long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
332 menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
333 ::DeleteMenu( menu->MacGetMenuId() ) ;
334 menu->SetInvokingWindow(NULL);
335
336 return TRUE;
337 }
338
339 void wxWindow::DoScreenToClient(int *x, int *y) const
340 {
341 WindowRef window = GetMacRootWindow() ;
342
343 Point localwhere ;
344 localwhere.h = * x ;
345 localwhere.v = * y ;
346
347 GrafPtr port ;
348 ::GetPort( &port ) ;
349 ::SetPort( UMAGetWindowPort( window ) ) ;
350 ::GlobalToLocal( &localwhere ) ;
351 ::SetPort( port ) ;
352
353 *x = localwhere.h ;
354 *y = localwhere.v ;
355
356 MacRootWindowToClient( x , y ) ;
357 }
358
359 void wxWindow::DoClientToScreen(int *x, int *y) const
360 {
361 WindowRef window = GetMacRootWindow() ;
362
363 MacClientToRootWindow( x , y ) ;
364
365 Point localwhere ;
366 localwhere.h = * x ;
367 localwhere.v = * y ;
368
369 GrafPtr port ;
370 ::GetPort( &port ) ;
371 ::SetPort( UMAGetWindowPort( window ) ) ;
372 ::SetOrigin( 0 , 0 ) ;
373 ::LocalToGlobal( &localwhere ) ;
374 ::SetPort( port ) ;
375 *x = localwhere.h ;
376 *y = localwhere.v ;
377 }
378
379 void wxWindow::MacClientToRootWindow( int *x , int *y ) const
380 {
381 if ( m_macWindowData )
382 {
383 }
384 else
385 {
386 *x += m_x ;
387 *y += m_y ;
388 GetParent()->MacClientToRootWindow( x , y ) ;
389 }
390 }
391
392 void wxWindow::MacRootWindowToClient( int *x , int *y ) const
393 {
394 if ( m_macWindowData )
395 {
396 }
397 else
398 {
399 *x -= m_x ;
400 *y -= m_y ;
401 GetParent()->MacRootWindowToClient( x , y ) ;
402 }
403 }
404
405 bool wxWindow::SetCursor(const wxCursor& cursor)
406 {
407 if ( !wxWindowBase::SetCursor(cursor) )
408 {
409 // no change
410 return FALSE;
411 }
412
413 wxASSERT_MSG( m_cursor.Ok(),
414 wxT("cursor must be valid after call to the base version"));
415
416 Point pt ;
417 wxWindow *mouseWin ;
418 GetMouse( &pt ) ;
419
420 // Change the cursor NOW if we're within the correct window
421
422 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
423 {
424 if ( mouseWin == this && !wxIsBusy() )
425 {
426 cursor.MacInstall() ;
427 }
428 }
429
430 return TRUE ;
431 }
432
433
434 // Get size *available for subwindows* i.e. excluding menu bar etc.
435 void wxWindow::DoGetClientSize(int *x, int *y) const
436 {
437 *x = m_width ;
438 *y = m_height ;
439
440 *x -= 2 * MacGetBorderSize( ) ;
441 *y -= 2 * MacGetBorderSize( ) ;
442
443 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
444 {
445 int x1 = 0 ;
446 int y1 = 0 ;
447 int w = m_width ;
448 int h = m_height ;
449
450 MacClientToRootWindow( &x1 , &y1 ) ;
451 MacClientToRootWindow( &w , &h ) ;
452
453 WindowRef window = NULL ;
454 wxWindow *iter = (wxWindow*)this ;
455
456 int totW = 10000 , totH = 10000;
457 while( iter )
458 {
459 if ( iter->m_macWindowData )
460 {
461 totW = iter->m_width ;
462 totH = iter->m_height ;
463 break ;
464 }
465
466 iter = iter->GetParent() ;
467 }
468
469 if (m_hScrollBar && m_hScrollBar->IsShown() )
470 {
471 (*y) -= MAC_SCROLLBAR_SIZE;
472 if ( h-y1 >= totH )
473 {
474 (*y)+= 1 ;
475 }
476 }
477 if (m_vScrollBar && m_vScrollBar->IsShown() )
478 {
479 (*x) -= MAC_SCROLLBAR_SIZE;
480 if ( w-x1 >= totW )
481 {
482 (*x) += 1 ;
483 }
484 }
485 }
486 }
487
488
489 // ----------------------------------------------------------------------------
490 // tooltips
491 // ----------------------------------------------------------------------------
492
493 #if wxUSE_TOOLTIPS
494
495 void wxWindow::DoSetToolTip(wxToolTip *tooltip)
496 {
497 wxWindowBase::DoSetToolTip(tooltip);
498
499 if ( m_tooltip )
500 m_tooltip->SetWindow(this);
501 }
502
503 #endif // wxUSE_TOOLTIPS
504
505 void wxWindow::DoMoveWindow(int x, int y, int width, int height)
506 {
507 DoSetSize( x,y, width, height ) ;
508 }
509
510 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
511 {
512
513 int former_x = m_x ;
514 int former_y = m_y ;
515 int former_w = m_width ;
516 int former_h = m_height ;
517
518 int currentX, currentY;
519 GetPosition(&currentX, &currentY);
520 int currentW,currentH;
521 GetSize(&currentW, &currentH);
522
523 int actualWidth = width;
524 int actualHeight = height;
525 int actualX = x;
526 int actualY = y;
527 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
528 actualX = currentX;
529 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
530 actualY = currentY;
531 if (width == -1)
532 actualWidth = currentW ;
533 if (height == -1)
534 actualHeight = currentH ;
535
536 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
537 {
538 MacRepositionScrollBars() ; // we might have a real position shift
539 return ;
540 }
541
542 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
543
544
545 bool doMove = false ;
546 bool doResize = false ;
547
548 if ( actualX != former_x || actualY != former_y )
549 {
550 doMove = true ;
551 }
552 if ( actualWidth != former_w || actualHeight != former_h )
553 {
554 doResize = true ;
555 }
556
557 if ( doMove || doResize )
558 {
559 if ( m_macWindowData )
560 {
561 }
562 else
563 {
564 // erase former position
565 {
566 wxMacDrawingClientHelper focus( this ) ;
567 if ( focus.Ok() )
568 {
569 Rect clientrect = { 0 , 0 , m_height , m_width } ;
570 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
571 }
572 }
573 }
574 m_x = actualX ;
575 m_y = actualY ;
576 m_width = actualWidth ;
577 m_height = actualHeight ;
578 if ( m_macWindowData )
579 {
580 if ( doMove )
581 ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost
582
583 if ( doResize )
584 ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true);
585
586 // the OS takes care of invalidating and erasing
587
588 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
589 {
590 wxFrame* frame = (wxFrame*) this ;
591 frame->PositionStatusBar();
592 frame->PositionToolBar();
593 }
594 }
595 else
596 {
597 // erase new position
598 {
599 wxMacDrawingClientHelper focus( this ) ;
600 if ( focus.Ok() )
601 {
602 Rect clientrect = { 0 , 0 , m_height , m_width } ;
603 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
604 }
605 }
606 if ( doMove )
607 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
608 }
609 MacRepositionScrollBars() ;
610 if ( doMove )
611 {
612 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
613 event.SetEventObject(this);
614 GetEventHandler()->ProcessEvent(event) ;
615 }
616 if ( doResize )
617 {
618 MacRepositionScrollBars() ;
619 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
620 event.SetEventObject(this);
621 GetEventHandler()->ProcessEvent(event);
622 }
623 }
624 }
625 // For implementation purposes - sometimes decorations make the client area
626 // smaller
627
628 wxPoint wxWindow::GetClientAreaOrigin() const
629 {
630 return wxPoint(MacGetBorderSize( ) , MacGetBorderSize( ) );
631 }
632
633 // Makes an adjustment to the window position (for example, a frame that has
634 // a toolbar that it manages itself).
635 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
636 {
637 if( !m_macWindowData )
638 {
639 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
640 {
641 wxPoint pt(GetParent()->GetClientAreaOrigin());
642 x += pt.x; y += pt.y;
643 }
644 }
645 }
646
647 void wxWindow::SetTitle(const wxString& title)
648 {
649 m_label = title ;
650
651 wxString label ;
652
653 if( wxApp::s_macDefaultEncodingIsPC )
654 label = wxMacMakeMacStringFromPC( title ) ;
655 else
656 label = title ;
657
658 if ( m_macWindowData )
659 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
660 }
661
662 wxString wxWindow::GetTitle() const
663 {
664 return m_label ;
665 }
666
667 bool wxWindow::Show(bool show)
668 {
669 if ( !wxWindowBase::Show(show) )
670 return FALSE;
671
672 if ( m_macWindowData )
673 {
674 if (show)
675 {
676 UMAShowWindow( m_macWindowData->m_macWindow ) ;
677 UMASelectWindow( m_macWindowData->m_macWindow ) ;
678 // no need to generate events here, they will get them triggered by macos
679 // actually they should be , but apparently they are not
680 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
681 event.SetEventObject(this);
682 GetEventHandler()->ProcessEvent(event);
683 }
684 else
685 {
686 UMAHideWindow( m_macWindowData->m_macWindow ) ;
687 }
688 }
689 MacSuperShown( show ) ;
690 Refresh() ;
691 if(m_macWindowData)
692 MacUpdateImmediately() ;
693
694 return TRUE;
695 }
696
697 void wxWindow::MacSuperShown( bool show )
698 {
699 wxNode *node = GetChildren().First();
700 while ( node )
701 {
702 wxWindow *child = (wxWindow *)node->Data();
703 if ( child->m_isShown )
704 child->MacSuperShown( show ) ;
705 node = node->Next();
706 }
707 }
708
709 int wxWindow::GetCharHeight() const
710 {
711 wxClientDC dc ( (wxWindow*)this ) ;
712 return dc.GetCharHeight() ;
713 }
714
715 int wxWindow::GetCharWidth() const
716 {
717 wxClientDC dc ( (wxWindow*)this ) ;
718 return dc.GetCharWidth() ;
719 }
720
721 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
722 int *descent, int *externalLeading, const wxFont *theFont ) const
723 {
724 const wxFont *fontToUse = theFont;
725 if ( !fontToUse )
726 fontToUse = &m_font;
727
728 wxClientDC dc( this ) ;
729 long lx,ly,ld,le ;
730 dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ;
731 if ( externalLeading )
732 *externalLeading = le ;
733 if ( descent )
734 *descent = ld ;
735 if ( x )
736 *x = lx ;
737 if ( y )
738 *y = ly ;
739 }
740
741 void wxWindow::MacEraseBackground( Rect *rect )
742 {
743 WindowRef window = GetMacRootWindow() ;
744 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
745 {
746 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
747 }
748 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
749 {
750 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
751 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
752 // either a non gray background color or a non control window
753
754 wxWindow* parent = GetParent() ;
755 while( parent )
756 {
757 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
758 {
759 // if we have any other colours in the hierarchy
760 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
761 break ;
762 }
763 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
764 {
765 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
766 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
767 {
768 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
769 break ;
770 }
771 }
772 else
773 {
774 // we have arrived at a non control item
775 parent = NULL ;
776 break ;
777 }
778 parent = parent->GetParent() ;
779 }
780 if ( !parent )
781 {
782 // if there is nothing special -> use default
783 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
784 }
785 }
786 else
787 {
788 RGBBackColor( &m_backgroundColour.GetPixel()) ;
789 }
790
791 EraseRect( rect ) ;
792
793 for (wxNode *node = GetChildren().First(); node; node = node->Next())
794 {
795 wxWindow *child = (wxWindow*)node->Data();
796
797 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
798 SectRect( &clientrect , rect , &clientrect ) ;
799
800 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
801 if ( child->GetMacRootWindow() == window && child->IsShown() )
802 {
803 wxMacDrawingClientHelper focus( this ) ;
804 if ( focus.Ok() )
805 {
806 child->MacEraseBackground( &clientrect ) ;
807 }
808 }
809 }
810 }
811
812 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
813 {
814 wxMacDrawingHelper focus( this ) ;
815 if ( focus.Ok() )
816 {
817 Rect clientrect = { 0 , 0 , m_height , m_width } ;
818 ClipRect( &clientrect ) ;
819
820 if ( rect )
821 {
822 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
823 SectRect( &clientrect , &r , &clientrect ) ;
824 }
825 InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
826 }
827 }
828
829 // Responds to colour changes: passes event on to children.
830 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
831 {
832 wxNode *node = GetChildren().First();
833 while ( node )
834 {
835 // Only propagate to non-top-level windows
836 wxWindow *win = (wxWindow *)node->Data();
837 if ( win->GetParent() )
838 {
839 wxSysColourChangedEvent event2;
840 event.m_eventObject = win;
841 win->GetEventHandler()->ProcessEvent(event2);
842 }
843
844 node = node->Next();
845 }
846 }
847
848 #if wxUSE_CARET && WXWIN_COMPATIBILITY
849 // ---------------------------------------------------------------------------
850 // Caret manipulation
851 // ---------------------------------------------------------------------------
852
853 void wxWindow::CreateCaret(int w, int h)
854 {
855 SetCaret(new wxCaret(this, w, h));
856 }
857
858 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
859 {
860 wxFAIL_MSG("not implemented");
861 }
862
863 void wxWindow::ShowCaret(bool show)
864 {
865 wxCHECK_RET( m_caret, "no caret to show" );
866
867 m_caret->Show(show);
868 }
869
870 void wxWindow::DestroyCaret()
871 {
872 SetCaret(NULL);
873 }
874
875 void wxWindow::SetCaretPos(int x, int y)
876 {
877 wxCHECK_RET( m_caret, "no caret to move" );
878
879 m_caret->Move(x, y);
880 }
881
882 void wxWindow::GetCaretPos(int *x, int *y) const
883 {
884 wxCHECK_RET( m_caret, "no caret to get position of" );
885
886 m_caret->GetPosition(x, y);
887 }
888 #endif // wxUSE_CARET
889
890 wxWindow *wxGetActiveWindow()
891 {
892 // actually this is a windows-only concept
893 return NULL;
894 }
895
896 // Coordinates relative to the window
897 void wxWindow::WarpPointer (int x_pos, int y_pos)
898 {
899 // We really dont move the mouse programmatically under mac
900 }
901
902 void wxWindow::OnEraseBackground(wxEraseEvent& event)
903 {
904 // TODO : probably we would adopt the EraseEvent structure
905 }
906
907 int wxWindow::GetScrollPos(int orient) const
908 {
909 if ( orient == wxHORIZONTAL )
910 {
911 if ( m_hScrollBar )
912 return m_hScrollBar->GetThumbPosition() ;
913 }
914 else
915 {
916 if ( m_vScrollBar )
917 return m_vScrollBar->GetThumbPosition() ;
918 }
919 return 0;
920 }
921
922 // This now returns the whole range, not just the number
923 // of positions that we can scroll.
924 int wxWindow::GetScrollRange(int orient) const
925 {
926 if ( orient == wxHORIZONTAL )
927 {
928 if ( m_hScrollBar )
929 return m_hScrollBar->GetRange() ;
930 }
931 else
932 {
933 if ( m_vScrollBar )
934 return m_vScrollBar->GetRange() ;
935 }
936 return 0;
937 }
938
939 int wxWindow::GetScrollThumb(int orient) const
940 {
941 if ( orient == wxHORIZONTAL )
942 {
943 if ( m_hScrollBar )
944 return m_hScrollBar->GetThumbSize() ;
945 }
946 else
947 {
948 if ( m_vScrollBar )
949 return m_vScrollBar->GetThumbSize() ;
950 }
951 return 0;
952 }
953
954 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
955 {
956 if ( orient == wxHORIZONTAL )
957 {
958 if ( m_hScrollBar )
959 m_hScrollBar->SetThumbPosition( pos ) ;
960 }
961 else
962 {
963 if ( m_vScrollBar )
964 m_vScrollBar->SetThumbPosition( pos ) ;
965 }
966 }
967
968 void wxWindow::MacCreateRealWindow( const wxString& title,
969 const wxPoint& pos,
970 const wxSize& size,
971 long style,
972 const wxString& name )
973 {
974 SetName(name);
975 m_windowStyle = style;
976 m_isShown = FALSE;
977
978 // create frame.
979
980 Rect theBoundsRect;
981
982 m_x = (int)pos.x;
983 m_y = (int)pos.y;
984 if ( m_y < 50 )
985 m_y = 50 ;
986 if ( m_x < 20 )
987 m_x = 20 ;
988
989 m_width = size.x;
990 if (m_width == -1)
991 m_width = 20;
992 m_height = size.y;
993 if (m_height == -1)
994 m_height = 20;
995
996 m_macWindowData = new MacWindowData() ;
997
998 ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
999
1000 // translate the window attributes in the appropriate window class and attributes
1001
1002 WindowClass wclass ;
1003 WindowAttributes attr ;
1004
1005 if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) )
1006 {
1007 wclass = kFloatingWindowClass ;
1008 if ( HasFlag(wxTINY_CAPTION_VERT) )
1009 {
1010 attr |= kWindowSideTitlebarAttribute ;
1011 }
1012 }
1013 else if ( HasFlag( wxTHICK_FRAME ) )
1014 {
1015 if ( HasFlag( wxDIALOG_MODAL ) )
1016 {
1017 wclass = kMovableModalWindowClass ;
1018 }
1019 else if ( HasFlag( wxDIALOG_MODELESS ) )
1020 {
1021 wclass = kDocumentWindowClass ;
1022 }
1023 else
1024 {
1025 if ( HasFlag( wxCAPTION ) )
1026 {
1027 wclass = kDocumentWindowClass ;
1028 }
1029 else
1030 {
1031 wclass = kModalWindowClass ;
1032 }
1033 }
1034 }
1035 else
1036 {
1037 wclass = kModalWindowClass ;
1038 }
1039
1040 attr = kWindowNoAttributes ;
1041
1042 if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
1043 {
1044 attr |= kWindowFullZoomAttribute ;
1045 attr |= kWindowCollapseBoxAttribute ;
1046 }
1047 if ( HasFlag( wxRESIZE_BORDER ) )
1048 {
1049 attr |= kWindowResizableAttribute ;
1050 }
1051 if ( HasFlag( wxSYSTEM_MENU ) )
1052 {
1053 attr |= kWindowCloseBoxAttribute ;
1054 }
1055
1056 UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ;
1057 wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ;
1058 wxString label ;
1059 if( wxApp::s_macDefaultEncodingIsPC )
1060 label = wxMacMakeMacStringFromPC( title ) ;
1061 else
1062 label = title ;
1063 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
1064 UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
1065
1066 m_macWindowData->m_macFocus = NULL ;
1067 }
1068
1069 void wxWindow::MacPaint( wxPaintEvent &event )
1070 {
1071 }
1072
1073 void wxWindow::MacPaintBorders( )
1074 {
1075 if( m_macWindowData )
1076 return ;
1077
1078 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1079 RGBColor black = { 0x0000, 0x0000 , 0x0000 } ;
1080 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1081 RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ;
1082 PenNormal() ;
1083
1084 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1085 {
1086 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1087 RGBColor pen1 = sunken ? white : black ;
1088 RGBColor pen2 = sunken ? shadow : face ;
1089 RGBColor pen3 = sunken ? face : shadow ;
1090 RGBColor pen4 = sunken ? black : white ;
1091
1092 RGBForeColor( &pen1 ) ;
1093 {
1094 Rect rect = { 0 , 0 , m_height , m_width } ;
1095 FrameRect( &rect ) ;
1096 }
1097 RGBForeColor( &pen2 ) ;
1098 {
1099 Rect rect = { 1 , 1 , m_height -1 , m_width -1} ;
1100 FrameRect( &rect ) ;
1101 }
1102 RGBForeColor( &pen3 ) ;
1103 {
1104 Rect rect = { 0 , 0 , m_height -2 , m_width -2} ;
1105 FrameRect( &rect ) ;
1106 }
1107 RGBForeColor( &pen4 ) ;
1108 {
1109 MoveTo( 0 , 0 ) ;
1110 LineTo( m_width - 3 , 0 ) ;
1111 MoveTo( 0 , 0 ) ;
1112 LineTo( 0 , m_height - 3 ) ;
1113 }
1114 }
1115 else if (HasFlag(wxSIMPLE_BORDER))
1116 {
1117 Rect rect = { 0 , 0 , m_height , m_width } ;
1118 RGBForeColor( &black ) ;
1119 FrameRect( &rect ) ;
1120 }
1121 /*
1122 if ( this->GetParent() )
1123 {
1124 wxPaintDC dc(GetParent());
1125 GetParent()->PrepareDC(dc);
1126
1127 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1128 {
1129 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1130
1131 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1132 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1133
1134 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1135 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1136 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1137 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1138
1139 dc.SetPen(wxPen1);
1140 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1141
1142 dc.SetPen(wxPen2);
1143 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1144
1145 dc.SetPen(wxPen3);
1146 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1147
1148 dc.SetPen(wxPen4);
1149 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1150 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1151 }
1152 else if (HasFlag(wxDOUBLE_BORDER))
1153 {
1154 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1155
1156 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1157 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1158
1159 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1160 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1161 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1162 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1163
1164 dc.SetPen(wxPen1);
1165 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1166
1167 dc.SetPen(wxPen2);
1168 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1169
1170 dc.SetPen(wxPen3);
1171 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1172
1173 dc.SetPen(wxPen4);
1174 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1175 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1176 }
1177 else if (HasFlag(wxSIMPLE_BORDER))
1178 {
1179 dc.SetPen(*wxBLACK_PEN);
1180 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1181 }
1182 }
1183 */
1184 }
1185
1186 // New function that will replace some of the above.
1187 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
1188 int range, bool refresh)
1189 {
1190 if ( orient == wxHORIZONTAL )
1191 {
1192 if ( m_hScrollBar )
1193 {
1194 if ( range == 0 || thumbVisible >= range )
1195 {
1196 if ( m_hScrollBar->IsShown() )
1197 m_hScrollBar->Show(false) ;
1198 }
1199 else
1200 {
1201 if ( !m_hScrollBar->IsShown() )
1202 m_hScrollBar->Show(true) ;
1203 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
1204 }
1205 }
1206 }
1207 else
1208 {
1209 if ( m_vScrollBar )
1210 {
1211 if ( range == 0 || thumbVisible >= range )
1212 {
1213 if ( m_vScrollBar->IsShown() )
1214 m_vScrollBar->Show(false) ;
1215 }
1216 else
1217 {
1218 if ( !m_vScrollBar->IsShown() )
1219 m_vScrollBar->Show(true) ;
1220 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
1221 }
1222 }
1223 }
1224 MacRepositionScrollBars() ;
1225 }
1226
1227 // Does a physical scroll
1228 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1229 {
1230 wxMacDrawingClientHelper focus( this ) ;
1231 if ( focus.Ok() )
1232 {
1233 int width , height ;
1234 GetClientSize( &width , &height ) ;
1235
1236 Rect scrollrect = { 0 , 0 , height , width } ;
1237
1238 RgnHandle updateRgn = NewRgn() ;
1239 ClipRect( &scrollrect ) ;
1240 if ( rect )
1241 {
1242 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1243 SectRect( &scrollrect , &r , &scrollrect ) ;
1244 }
1245 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
1246 InvalWindowRgn( GetMacRootWindow() , updateRgn ) ;
1247 DisposeRgn( updateRgn ) ;
1248 }
1249
1250 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1251 {
1252 wxWindow *child = (wxWindow*)node->Data();
1253 if (child == m_vScrollBar) continue;
1254 if (child == m_hScrollBar) continue;
1255 if (child->IsTopLevel()) continue;
1256 int x,y;
1257 child->GetPosition( &x, &y );
1258 int w,h;
1259 child->GetSize( &w, &h );
1260 child->SetSize( x+dx, y+dy, w, h );
1261 }
1262
1263 }
1264
1265 void wxWindow::MacOnScroll(wxScrollEvent &event )
1266 {
1267 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
1268 {
1269 wxScrollWinEvent wevent;
1270 wevent.SetPosition(event.GetPosition());
1271 wevent.SetOrientation(event.GetOrientation());
1272 wevent.m_eventObject = this;
1273
1274 if (event.m_eventType == wxEVT_SCROLL_TOP) {
1275 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
1276 } else
1277 if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
1278 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
1279 } else
1280 if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
1281 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1282 } else
1283 if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
1284 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
1285 } else
1286 if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
1287 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1288 } else
1289 if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
1290 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1291 } else
1292 if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
1293 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1294 }
1295
1296 GetEventHandler()->ProcessEvent(wevent);
1297 }
1298 }
1299
1300 bool wxWindow::SetFont(const wxFont& font)
1301 {
1302 if ( !wxWindowBase::SetFont(font) )
1303 {
1304 // nothing to do
1305 return FALSE;
1306 }
1307
1308 return TRUE;
1309 }
1310
1311 // Get the window with the focus
1312 wxWindow *wxWindowBase::FindFocus()
1313 {
1314 return gFocusWindow ;
1315 }
1316
1317 #if WXWIN_COMPATIBILITY
1318 // If nothing defined for this, try the parent.
1319 // E.g. we may be a button loaded from a resource, with no callback function
1320 // defined.
1321 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1322 {
1323 if ( GetEventHandler()->ProcessEvent(event) )
1324 return;
1325 if ( m_parent )
1326 m_parent->GetEventHandler()->OnCommand(win, event);
1327 }
1328 #endif // WXWIN_COMPATIBILITY_2
1329
1330 #if WXWIN_COMPATIBILITY
1331 wxObject* wxWindow::GetChild(int number) const
1332 {
1333 // Return a pointer to the Nth object in the Panel
1334 wxNode *node = GetChildren().First();
1335 int n = number;
1336 while (node && n--)
1337 node = node->Next();
1338 if ( node )
1339 {
1340 wxObject *obj = (wxObject *)node->Data();
1341 return(obj);
1342 }
1343 else
1344 return NULL;
1345 }
1346 #endif // WXWIN_COMPATIBILITY
1347
1348 void wxWindow::Clear()
1349 {
1350 if ( m_macWindowData )
1351 {
1352 wxMacDrawingClientHelper helper ( this ) ;
1353 int w ,h ;
1354 wxPoint origin = GetClientAreaOrigin() ;
1355 GetClientSize( &w , &h ) ;
1356 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1357 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
1358 EraseRect( &r ) ;
1359 }
1360 else
1361 {
1362 wxClientDC dc(this);
1363 wxBrush brush(GetBackgroundColour(), wxSOLID);
1364 dc.SetBackground(brush);
1365 dc.Clear();
1366 }
1367 }
1368
1369 // Setup background and foreground colours correctly
1370 void wxWindow::SetupColours()
1371 {
1372 if ( GetParent() )
1373 SetBackgroundColour(GetParent()->GetBackgroundColour());
1374 }
1375
1376 void wxWindow::OnIdle(wxIdleEvent& event)
1377 {
1378 /*
1379 // Check if we need to send a LEAVE event
1380 if (m_mouseInWindow)
1381 {
1382 POINT pt;
1383 ::GetCursorPos(&pt);
1384 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1385 {
1386 // Generate a LEAVE event
1387 m_mouseInWindow = FALSE;
1388 MSWOnMouseLeave(pt.x, pt.y, 0);
1389 }
1390 }
1391 */
1392
1393 // This calls the UI-update mechanism (querying windows for
1394 // menu/toolbar/control state information)
1395 UpdateWindowUI();
1396 }
1397
1398 // Raise the window to the top of the Z order
1399 void wxWindow::Raise()
1400 {
1401 // TODO
1402 }
1403
1404 // Lower the window to the bottom of the Z order
1405 void wxWindow::Lower()
1406 {
1407 // TODO
1408 }
1409
1410 void wxWindow::DoSetClientSize(int width, int height)
1411 {
1412 if ( width != -1 || height != -1 )
1413 {
1414
1415 if ( width != -1 && m_vScrollBar )
1416 width += MAC_SCROLLBAR_SIZE ;
1417 if ( height != -1 && m_vScrollBar )
1418 height += MAC_SCROLLBAR_SIZE ;
1419
1420 width += 2 * MacGetBorderSize( ) ;
1421 height += 2 * MacGetBorderSize( ) ;
1422
1423 DoSetSize( -1 , -1 , width , height ) ;
1424 }
1425 }
1426
1427
1428 wxWindow* wxWindow::s_lastMouseWindow = NULL ;
1429
1430 bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin )
1431 {
1432 if ((point.x < m_x) || (point.y < m_y) ||
1433 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1434 return FALSE;
1435
1436 WindowRef window = GetMacRootWindow() ;
1437
1438 wxPoint newPoint( point ) ;
1439
1440 newPoint.x -= m_x;
1441 newPoint.y -= m_y;
1442
1443 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1444 {
1445 wxWindow *child = (wxWindow*)node->Data();
1446 if ( child->GetMacRootWindow() == window )
1447 {
1448 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1449 return TRUE;
1450 }
1451 }
1452
1453 *outWin = this ;
1454 return TRUE;
1455 }
1456
1457 bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin )
1458 {
1459 WindowRef window ;
1460 Point pt = { screenpoint.y , screenpoint.x } ;
1461 if ( ::FindWindow( pt , &window ) == 3 )
1462 {
1463 wxPoint point( screenpoint ) ;
1464 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1465 win->ScreenToClient( point ) ;
1466 return win->MacGetWindowFromPointSub( point , outWin ) ;
1467 }
1468 return FALSE ;
1469 }
1470
1471 extern int wxBusyCursorCount ;
1472
1473 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
1474 {
1475 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1476 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1477 return FALSE;
1478
1479
1480 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1481 return FALSE ;
1482
1483 WindowRef window = GetMacRootWindow() ;
1484
1485 event.m_x -= m_x;
1486 event.m_y -= m_y;
1487
1488 int x = event.m_x ;
1489 int y = event.m_y ;
1490
1491 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1492 {
1493 wxWindow *child = (wxWindow*)node->Data();
1494 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
1495 {
1496 if (child->MacDispatchMouseEvent(event))
1497 return TRUE;
1498 }
1499 }
1500
1501 event.m_x = x ;
1502 event.m_y = y ;
1503
1504 if ( wxBusyCursorCount == 0 )
1505 {
1506 m_cursor.MacInstall() ;
1507 }
1508
1509 #if wxUSE_TOOLTIPS
1510 if ( event.GetEventType() == wxEVT_MOTION
1511 || event.GetEventType() == wxEVT_ENTER_WINDOW
1512 || event.GetEventType() == wxEVT_LEAVE_WINDOW )
1513 wxToolTip::RelayEvent( this , event);
1514 #endif // wxUSE_TOOLTIPS
1515 GetEventHandler()->ProcessEvent( event ) ;
1516 return TRUE;
1517 }
1518
1519 Point lastWhere ;
1520 long lastWhen = 0 ;
1521
1522 wxString wxWindow::MacGetToolTipString( wxPoint &pt )
1523 {
1524 if ( m_tooltip )
1525 {
1526 return m_tooltip->GetTip() ;
1527 }
1528 return "" ;
1529 }
1530 void wxWindow::MacFireMouseEvent( EventRecord *ev )
1531 {
1532 wxMouseEvent event(wxEVT_LEFT_DOWN);
1533 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1534 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1535
1536 event.m_leftDown = isDown && !controlDown;
1537 event.m_middleDown = FALSE;
1538 event.m_rightDown = isDown && controlDown;
1539
1540 if ( ev->what == mouseDown )
1541 {
1542 if ( controlDown )
1543 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1544 else
1545 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1546 }
1547 else if ( ev->what == mouseUp )
1548 {
1549 if ( controlDown )
1550 event.SetEventType(wxEVT_RIGHT_UP ) ;
1551 else
1552 event.SetEventType(wxEVT_LEFT_UP ) ;
1553 }
1554 else
1555 {
1556 event.SetEventType(wxEVT_MOTION ) ;
1557 }
1558
1559 event.m_shiftDown = ev->modifiers & shiftKey;
1560 event.m_controlDown = ev->modifiers & controlKey;
1561 event.m_altDown = ev->modifiers & optionKey;
1562 event.m_metaDown = ev->modifiers & cmdKey;
1563
1564 Point localwhere = ev->where ;
1565
1566 GrafPtr port ;
1567 ::GetPort( &port ) ;
1568 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1569 ::GlobalToLocal( &localwhere ) ;
1570 ::SetPort( port ) ;
1571
1572 if ( ev->what == mouseDown )
1573 {
1574 if ( ev->when - lastWhen <= GetDblTime() )
1575 {
1576 if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
1577 {
1578 if ( controlDown )
1579 event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
1580 else
1581 event.SetEventType(wxEVT_LEFT_DCLICK ) ;
1582 }
1583 }
1584 lastWhen = ev->when ;
1585 lastWhere = localwhere ;
1586 }
1587
1588 event.m_x = localwhere.h;
1589 event.m_y = localwhere.v;
1590 event.m_x += m_x;
1591 event.m_y += m_y;
1592
1593 /*
1594 wxPoint origin = GetClientAreaOrigin() ;
1595
1596 event.m_x += origin.x ;
1597 event.m_y += origin.y ;
1598 */
1599
1600 event.m_timeStamp = ev->when;
1601 event.SetEventObject(this);
1602 if ( wxTheApp->s_captureWindow )
1603 {
1604 int x = event.m_x ;
1605 int y = event.m_y ;
1606 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1607 event.m_x = x ;
1608 event.m_y = y ;
1609 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1610 if ( ev->what == mouseUp )
1611 {
1612 wxTheApp->s_captureWindow = NULL ;
1613 if ( wxBusyCursorCount == 0 )
1614 {
1615 m_cursor.MacInstall() ;
1616 }
1617 }
1618 }
1619 else
1620 {
1621 MacDispatchMouseEvent( event ) ;
1622 }
1623 }
1624
1625 void wxWindow::MacMouseDown( EventRecord *ev , short part)
1626 {
1627 MacFireMouseEvent( ev ) ;
1628 }
1629
1630 void wxWindow::MacMouseUp( EventRecord *ev , short part)
1631 {
1632 WindowPtr frontWindow ;
1633 switch (part)
1634 {
1635 case inContent:
1636 {
1637 MacFireMouseEvent( ev ) ;
1638 }
1639 break ;
1640 }
1641 }
1642
1643 void wxWindow::MacMouseMoved( EventRecord *ev , short part)
1644 {
1645 WindowPtr frontWindow ;
1646 switch (part)
1647 {
1648 case inContent:
1649 {
1650 MacFireMouseEvent( ev ) ;
1651 }
1652 break ;
1653 }
1654 }
1655 void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
1656 {
1657 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating);
1658 event.m_timeStamp = ev->when ;
1659 event.SetEventObject(this);
1660
1661 GetEventHandler()->ProcessEvent(event);
1662
1663 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
1664 }
1665
1666 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
1667 {
1668 // updatergn is always already clipped to our boundaries
1669 WindowRef window = GetMacRootWindow() ;
1670 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1671 {
1672 wxMacDrawingHelper focus( this ) ; // was client
1673 if ( focus.Ok() )
1674 {
1675 WindowRef window = GetMacRootWindow() ;
1676 bool eraseBackground = false ;
1677 if ( m_macWindowData )
1678 eraseBackground = true ;
1679 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1680 {
1681 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1682 }
1683 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1684 {
1685 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1686 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1687 // either a non gray background color or a non control window
1688
1689
1690 wxWindow* parent = GetParent() ;
1691 while( parent )
1692 {
1693 if ( parent->GetMacRootWindow() != window )
1694 {
1695 // we are in a different window on the mac system
1696 parent = NULL ;
1697 break ;
1698 }
1699
1700 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1701 {
1702 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1703 {
1704 // if we have any other colours in the hierarchy
1705 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1706 break ;
1707 }
1708 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1709 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1710 {
1711 Rect box ;
1712 GetRegionBounds( updatergn , &box) ;
1713 UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
1714 break ;
1715 }
1716 }
1717 else
1718 {
1719 parent = NULL ;
1720 break ;
1721 }
1722 parent = parent->GetParent() ;
1723 }
1724 if ( !parent )
1725 {
1726 // if there is nothing special -> use default
1727 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1728 }
1729 }
1730 else
1731 {
1732 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1733 }
1734 if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
1735 eraseBackground = true ;
1736 SetClip( updatergn ) ;
1737 if ( eraseBackground )
1738 {
1739 EraseRgn( updatergn ) ;
1740 }
1741 }
1742
1743 m_macUpdateRgn = updatergn ;
1744 {
1745 RgnHandle newupdate = NewRgn() ;
1746 wxSize point = GetClientSize() ;
1747 wxPoint origin = GetClientAreaOrigin() ;
1748
1749 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
1750 SectRgn( newupdate , m_macUpdateRgn , newupdate ) ;
1751 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
1752 m_updateRegion = newupdate ;
1753 DisposeRgn( newupdate ) ;
1754 }
1755
1756 MacPaintBorders() ;
1757 wxPaintEvent event;
1758 event.m_timeStamp = time ;
1759 event.SetEventObject(this);
1760 GetEventHandler()->ProcessEvent(event);
1761 }
1762
1763
1764 RgnHandle childupdate = NewRgn() ;
1765
1766 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1767 {
1768 wxWindow *child = (wxWindow*)node->Data();
1769 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
1770 SectRgn( childupdate , m_macUpdateRgn , childupdate ) ;
1771 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1772 if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
1773 {
1774 // because dialogs may also be children
1775 child->MacRedraw( childupdate , time ) ;
1776 }
1777 }
1778 DisposeRgn( childupdate ) ;
1779 // eventually a draw grow box here
1780 }
1781
1782 void wxWindow::MacUpdateImmediately()
1783 {
1784 WindowRef window = GetMacRootWindow() ;
1785 if ( window )
1786 {
1787 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1788 #if TARGET_CARBON
1789 AGAPortHelper help( GetWindowPort(window) ) ;
1790 #else
1791 AGAPortHelper help( (window) ) ;
1792 #endif
1793 SetOrigin( 0 , 0 ) ;
1794 BeginUpdate( window ) ;
1795 if ( win )
1796 {
1797 RgnHandle region = NewRgn();
1798
1799 if ( region )
1800 {
1801 GetPortVisibleRegion( GetWindowPort( window ), region );
1802
1803 // if windowshade gives incompatibility , take the follwing out
1804 if ( !EmptyRgn( region ) )
1805 {
1806 win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
1807 }
1808 DisposeRgn( region );
1809 }
1810 }
1811 EndUpdate( window ) ;
1812 }
1813 }
1814
1815 void wxWindow::MacUpdate( EventRecord *ev )
1816 {
1817 WindowRef window = (WindowRef) ev->message ;
1818 wxWindow * win = wxFindWinFromMacWindow( window ) ;
1819 #if TARGET_CARBON
1820 AGAPortHelper help( GetWindowPort(window) ) ;
1821 #else
1822 AGAPortHelper help( (window) ) ;
1823 #endif
1824 SetOrigin( 0 , 0 ) ;
1825 BeginUpdate( window ) ;
1826 if ( win )
1827 {
1828 RgnHandle region = NewRgn();
1829
1830 if ( region )
1831 {
1832 GetPortVisibleRegion( GetWindowPort( window ), region );
1833
1834 // if windowshade gives incompatibility , take the follwing out
1835 if ( !EmptyRgn( region ) )
1836 {
1837 MacRedraw( region , ev->when ) ;
1838 }
1839 DisposeRgn( region );
1840 }
1841 }
1842 EndUpdate( window ) ;
1843 }
1844
1845 WindowRef wxWindow::GetMacRootWindow() const
1846 {
1847 WindowRef window = NULL ;
1848 wxWindow *iter = (wxWindow*)this ;
1849
1850 while( iter )
1851 {
1852 if ( iter->m_macWindowData )
1853 return iter->m_macWindowData->m_macWindow ;
1854
1855 iter = iter->GetParent() ;
1856 }
1857 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1858 return NULL ;
1859 }
1860
1861 void wxWindow::MacCreateScrollBars( long style )
1862 {
1863 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1864
1865 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1866 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1867 int width, height ;
1868 GetClientSize( &width , &height ) ;
1869
1870 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1871 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1872 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1873 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1874
1875 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
1876 vSize , wxVERTICAL);
1877
1878 if ( style & wxVSCROLL )
1879 {
1880
1881 }
1882 else
1883 {
1884 m_vScrollBar->Show(false) ;
1885 }
1886 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
1887 hSize , wxHORIZONTAL);
1888 if ( style & wxHSCROLL )
1889 {
1890 }
1891 else
1892 {
1893 m_hScrollBar->Show(false) ;
1894 }
1895
1896 // because the create does not take into account the client area origin
1897 MacRepositionScrollBars() ; // we might have a real position shift
1898 }
1899
1900 void wxWindow::MacRepositionScrollBars()
1901 {
1902 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1903 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1904
1905 // get real client area
1906
1907 int width = m_width ;
1908 int height = m_height ;
1909
1910 width -= 2 * MacGetBorderSize() ;
1911 height -= 2 * MacGetBorderSize() ;
1912
1913 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
1914 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
1915 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
1916 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
1917
1918 int x = 0 ;
1919 int y = 0 ;
1920 int w = m_width ;
1921 int h = m_height ;
1922
1923 MacClientToRootWindow( &x , &y ) ;
1924 MacClientToRootWindow( &w , &h ) ;
1925
1926 WindowRef window = NULL ;
1927 wxWindow *iter = (wxWindow*)this ;
1928
1929 int totW = 10000 , totH = 10000;
1930 while( iter )
1931 {
1932 if ( iter->m_macWindowData )
1933 {
1934 totW = iter->m_width ;
1935 totH = iter->m_height ;
1936 break ;
1937 }
1938
1939 iter = iter->GetParent() ;
1940 }
1941
1942 if ( x == 0 )
1943 {
1944 hPoint.x = -1 ;
1945 hSize.x += 1 ;
1946 }
1947 if ( y == 0 )
1948 {
1949 vPoint.y = -1 ;
1950 vSize.y += 1 ;
1951 }
1952
1953 if ( w-x >= totW )
1954 {
1955 hSize.x += 1 ;
1956 vPoint.x += 1 ;
1957 }
1958
1959 if ( h-y >= totH )
1960 {
1961 vSize.y += 1 ;
1962 hPoint.y += 1 ;
1963 }
1964
1965 if ( m_vScrollBar )
1966 {
1967 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
1968 }
1969 if ( m_hScrollBar )
1970 {
1971 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
1972 }
1973 }
1974
1975 void wxWindow::MacKeyDown( EventRecord *ev )
1976 {
1977
1978 }
1979
1980
1981 bool wxWindow::AcceptsFocus() const
1982 {
1983 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1984 }
1985
1986 ControlHandle wxWindow::MacGetContainerForEmbedding()
1987 {
1988 if ( m_macWindowData )
1989 return m_macWindowData->m_macRootControl ;
1990 else
1991 return GetParent()->MacGetContainerForEmbedding() ;
1992 }
1993
1994 void wxWindow::MacSuperChangedPosition()
1995 {
1996 // only window-absolute structures have to be moved i.e. controls
1997
1998 wxNode *node = GetChildren().First();
1999 while ( node )
2000 {
2001 wxWindow *child = (wxWindow *)node->Data();
2002 child->MacSuperChangedPosition() ;
2003 node = node->Next();
2004 }
2005 }
2006 /*
2007
2008 bool wxWindow::MacSetupFocusPort( )
2009 {
2010 Point localOrigin ;
2011 Rect clipRect ;
2012 WindowRef window ;
2013 wxWindow *rootwin ;
2014 GrafPtr port ;
2015
2016 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2017 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2018 }
2019
2020 bool wxWindow::MacSetupFocusClientPort( )
2021 {
2022 Point localOrigin ;
2023 Rect clipRect ;
2024 WindowRef window ;
2025 wxWindow *rootwin ;
2026 GrafPtr port ;
2027
2028 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2029 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2030 }
2031
2032 bool wxWindow::MacSetupDrawingPort( )
2033 {
2034 Point localOrigin ;
2035 Rect clipRect ;
2036 WindowRef window ;
2037 wxWindow *rootwin ;
2038 GrafPtr port ;
2039
2040 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2041 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2042 }
2043
2044 bool wxWindow::MacSetupDrawingClientPort( )
2045 {
2046 Point localOrigin ;
2047 Rect clipRect ;
2048 WindowRef window ;
2049 wxWindow *rootwin ;
2050 GrafPtr port ;
2051
2052 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2053 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2054 }
2055 */
2056
2057 bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2058 {
2059 if ( window == NULL )
2060 return false ;
2061
2062 GrafPtr currPort;
2063 GrafPtr port ;
2064
2065 ::GetPort(&currPort);
2066 port = UMAGetWindowPort( window) ;
2067 if (currPort != port )
2068 ::SetPort(port);
2069
2070 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2071 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2072 return true;
2073 }
2074
2075 bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
2076 {
2077 if ( window == NULL )
2078 return false ;
2079
2080 GrafPtr currPort;
2081 GrafPtr port ;
2082 ::GetPort(&currPort);
2083 port = UMAGetWindowPort( window) ;
2084 if (currPort != port )
2085 ::SetPort(port);
2086 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2087 ::SetOrigin(-localOrigin.h, -localOrigin.v);
2088 ::ClipRect(&clipRect);
2089
2090 ::PenNormal() ;
2091 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
2092 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
2093 Pattern whiteColor ;
2094
2095 ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
2096 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2097 return true;
2098 }
2099
2100 void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin)
2101 {
2102 if ( m_macWindowData )
2103 {
2104 localOrigin->h = 0;
2105 localOrigin->v = 0;
2106 clipRect->left = 0;
2107 clipRect->top = 0;
2108 clipRect->right = m_width;
2109 clipRect->bottom = m_height;
2110 *window = m_macWindowData->m_macWindow ;
2111 *rootwin = this ;
2112 }
2113 else
2114 {
2115 wxASSERT( GetParent() != NULL ) ;
2116 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
2117 localOrigin->h += m_x;
2118 localOrigin->v += m_y;
2119 OffsetRect(clipRect, -m_x, -m_y);
2120
2121 Rect myClip;
2122 myClip.left = 0;
2123 myClip.top = 0;
2124 myClip.right = m_width;
2125 myClip.bottom = m_height;
2126 SectRect(clipRect, &myClip, clipRect);
2127 }
2128 }
2129
2130 void wxWindow::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
2131 {
2132 // int width , height ;
2133 // GetClientSize( &width , &height ) ;
2134
2135 if ( m_macWindowData )
2136 {
2137 localOrigin->h = 0;
2138 localOrigin->v = 0;
2139 clipRect->left = 0;
2140 clipRect->top = 0;
2141 clipRect->right = m_width ;//width;
2142 clipRect->bottom = m_height ;// height;
2143 *window = m_macWindowData->m_macWindow ;
2144 *rootwin = this ;
2145 }
2146 else
2147 {
2148 wxASSERT( GetParent() != NULL ) ;
2149
2150 GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
2151
2152 localOrigin->h += m_x;
2153 localOrigin->v += m_y;
2154 OffsetRect(clipRect, -m_x, -m_y);
2155
2156 Rect myClip;
2157 myClip.left = 0;
2158 myClip.top = 0;
2159 myClip.right = m_width ;//width;
2160 myClip.bottom = m_height ;// height;
2161 SectRect(clipRect, &myClip, clipRect);
2162 }
2163 }
2164
2165 void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
2166 {
2167 MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
2168
2169 int width , height ;
2170 GetClientSize( &width , &height ) ;
2171 wxPoint client ;
2172 client = GetClientAreaOrigin( ) ;
2173
2174 localOrigin->h += client.x;
2175 localOrigin->v += client.y;
2176 OffsetRect(clipRect, -client.x, -client.y);
2177
2178 Rect myClip;
2179 myClip.left = 0;
2180 myClip.top = 0;
2181 myClip.right = width;
2182 myClip.bottom = height;
2183 SectRect(clipRect, &myClip, clipRect);
2184 }
2185
2186 long wxWindow::MacGetBorderSize( ) const
2187 {
2188 if( m_macWindowData )
2189 return 0 ;
2190
2191 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2192 {
2193 return 2 ;
2194 }
2195 else if ( m_windowStyle &wxDOUBLE_BORDER)
2196 {
2197 return 2 ;
2198 }
2199 else if (m_windowStyle &wxSIMPLE_BORDER)
2200 {
2201 return 1 ;
2202 }
2203 return 0 ;
2204 }
2205
2206 long wxWindow::MacRemoveBordersFromStyle( long style )
2207 {
2208 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2209 }
2210 /*
2211 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
2212 {
2213 m_ok = false ;
2214 Point localOrigin ;
2215 Rect clipRect ;
2216 WindowRef window ;
2217 wxWindow *rootwin ;
2218 m_currentPort = NULL ;
2219 GetPort( &m_formerPort ) ;
2220 if ( theWindow )
2221 {
2222
2223 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2224 m_currentPort = UMAGetWindowPort( window ) ;
2225 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2226 m_ok = true ;
2227 }
2228 }
2229
2230 wxMacFocusHelper::~wxMacFocusHelper()
2231 {
2232 if ( m_ok )
2233 {
2234 SetPort( m_currentPort ) ;
2235 SetOrigin( 0 , 0 ) ;
2236 }
2237 if ( m_formerPort != m_currentPort )
2238 SetPort( m_formerPort ) ;
2239 }
2240 */
2241 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow )
2242 {
2243 m_ok = false ;
2244 Point localOrigin ;
2245 Rect clipRect ;
2246 WindowRef window ;
2247 wxWindow *rootwin ;
2248 m_currentPort = NULL ;
2249
2250 GetPort( &m_formerPort ) ;
2251 if ( theWindow )
2252 {
2253 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2254 m_currentPort = UMAGetWindowPort( window ) ;
2255 if ( m_formerPort != m_currentPort )
2256 SetPort( m_currentPort ) ;
2257 GetPenState( &m_savedPenState ) ;
2258 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2259 m_ok = true ;
2260 }
2261 }
2262
2263 wxMacDrawingHelper::~wxMacDrawingHelper()
2264 {
2265 if ( m_ok )
2266 {
2267 SetPort( m_currentPort ) ;
2268 SetPenState( &m_savedPenState ) ;
2269 SetOrigin( 0 , 0 ) ;
2270 Rect portRect ;
2271 GetPortBounds( m_currentPort , &portRect ) ;
2272 ClipRect( &portRect ) ;
2273 }
2274
2275 if ( m_formerPort != m_currentPort )
2276 SetPort( m_formerPort ) ;
2277 }
2278 /*
2279 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
2280 {
2281 m_ok = false ;
2282 Point localOrigin ;
2283 Rect clipRect ;
2284 WindowRef window ;
2285 wxWindow *rootwin ;
2286 m_currentPort = NULL ;
2287
2288 GetPort( &m_formerPort ) ;
2289
2290 if ( theWindow )
2291 {
2292 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2293 m_currentPort = UMAGetWindowPort( window ) ;
2294 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2295 m_ok = true ;
2296 }
2297 }
2298
2299 wxMacFocusClientHelper::~wxMacFocusClientHelper()
2300 {
2301 if ( m_ok )
2302 {
2303 SetPort( m_currentPort ) ;
2304 SetOrigin( 0 , 0 ) ;
2305 }
2306 if ( m_formerPort != m_currentPort )
2307 SetPort( m_formerPort ) ;
2308 }
2309 */
2310
2311 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow )
2312 {
2313 m_ok = false ;
2314 Point localOrigin ;
2315 Rect clipRect ;
2316 WindowRef window ;
2317 wxWindow *rootwin ;
2318 m_currentPort = NULL ;
2319
2320 GetPort( &m_formerPort ) ;
2321
2322 if ( theWindow )
2323 {
2324 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2325 m_currentPort = UMAGetWindowPort( window ) ;
2326 if ( m_formerPort != m_currentPort )
2327 SetPort( m_currentPort ) ;
2328 GetPenState( &m_savedPenState ) ;
2329 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2330 m_ok = true ;
2331 }
2332 }
2333
2334 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2335 {
2336 if ( m_ok )
2337 {
2338 SetPort( m_currentPort ) ;
2339 SetPenState( &m_savedPenState ) ;
2340 SetOrigin( 0 , 0 ) ;
2341 Rect portRect ;
2342 GetPortBounds( m_currentPort , &portRect ) ;
2343 ClipRect( &portRect ) ;
2344 }
2345
2346 if ( m_formerPort != m_currentPort )
2347 SetPort( m_formerPort ) ;
2348 }
2349
2350 // Find the wxWindow at the current mouse position, returning the mouse
2351 // position.
2352 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
2353 {
2354 pt = wxGetMousePosition();
2355 wxWindow* found = wxFindWindowAtPoint(pt);
2356 return found;
2357 }
2358
2359 // Get the current mouse position.
2360 wxPoint wxGetMousePosition()
2361 {
2362 int x, y;
2363 wxGetMousePosition(& x, & y);
2364 return wxPoint(x, y);
2365 }
2366