]> git.saurik.com Git - wxWidgets.git/blob - src/mac/window.cpp
18ab38338affebb05e738ede0f61c16741bcfddd
[wxWidgets.git] / src / mac / 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 // TODO remove the line below, just for lookup-up convenience CS
33 #include "wx/mac/window.h"
34
35 #include "wx/menuitem.h"
36 #include "wx/log.h"
37
38 #define wxWINDOW_HSCROLL 5998
39 #define wxWINDOW_VSCROLL 5997
40 #define MAC_SCROLLBAR_SIZE 16
41
42 #include <wx/mac/uma.h>
43
44 #if wxUSE_DRAG_AND_DROP
45 #include "wx/dnd.h"
46 #endif
47
48 #include <string.h>
49
50 extern wxList wxPendingDelete;
51 wxWindow* gFocusWindow = NULL ;
52
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
55
56 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
57 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
58 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
59 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
60 EVT_IDLE(wxWindow::OnIdle)
61 END_EVENT_TABLE()
62
63 #endif
64
65
66
67 // ===========================================================================
68 // implementation
69 // ===========================================================================
70
71 // ---------------------------------------------------------------------------
72 // wxWindow utility functions
73 // ---------------------------------------------------------------------------
74
75 // Find an item given the Macintosh Window Reference
76
77 wxList *wxWinMacWindowList = NULL;
78 wxWindow *wxFindWinFromMacWindow(WindowRef inWindowRef)
79 {
80 wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
81 if (!node)
82 return NULL;
83 return (wxWindow *)node->Data();
84 }
85
86 void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindow *win)
87 {
88 // adding NULL WindowRef is (first) surely a result of an error and
89 // (secondly) breaks menu command processing
90 wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
91
92 if ( !wxWinMacWindowList->Find((long)inWindowRef) )
93 wxWinMacWindowList->Append((long)inWindowRef, win);
94 }
95
96 void wxRemoveMacWindowAssociation(wxWindow *win)
97 {
98 wxWinMacWindowList->DeleteObject(win);
99 }
100
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
104
105 void wxWindow::Init()
106 {
107 // generic
108 InitBase();
109
110 // MSW specific
111 m_doubleClickAllowed = 0;
112 m_winCaptured = FALSE;
113
114 m_isBeingDeleted = FALSE;
115
116 m_useCtl3D = FALSE;
117 m_mouseInWindow = FALSE;
118
119 m_xThumbSize = 0;
120 m_yThumbSize = 0;
121 m_backgroundTransparent = FALSE;
122
123 // as all windows are created with WS_VISIBLE style...
124 m_isShown = TRUE;
125
126 m_macWindowData = NULL ;
127
128 m_x = 0;
129 m_y = 0 ;
130 m_width = 0 ;
131 m_height = 0 ;
132
133 m_hScrollBar = NULL ;
134 m_vScrollBar = NULL ;
135
136 #if wxUSE_DRAG_AND_DROP
137 m_pDropTarget = NULL;
138 #endif
139 }
140
141 // Destructor
142 wxWindow::~wxWindow()
143 {
144 m_isBeingDeleted = TRUE;
145
146 if ( s_lastMouseWindow == this )
147 {
148 s_lastMouseWindow = NULL ;
149 }
150
151 if ( gFocusWindow == this )
152 {
153 gFocusWindow = NULL ;
154 }
155
156 if ( m_parent )
157 m_parent->RemoveChild(this);
158
159 DestroyChildren();
160
161 if ( m_macWindowData )
162 {
163 UMADisposeWindow( m_macWindowData->m_macWindow ) ;
164 delete m_macWindowData ;
165 wxRemoveMacWindowAssociation( this ) ;
166 }
167 }
168
169 // Constructor
170 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
171 const wxPoint& pos,
172 const wxSize& size,
173 long style,
174 const wxString& name)
175 {
176 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
177
178 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
179 return FALSE;
180
181 parent->AddChild(this);
182
183 m_x = (int)pos.x;
184 m_y = (int)pos.y;
185 AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING);
186 m_width = WidthDefault( size.x );
187 m_height = HeightDefault( size.y ) ;
188
189 MacCreateScrollBars( style ) ;
190
191 return TRUE;
192 }
193
194 void wxWindow::SetFocus()
195 {
196 if ( AcceptsFocus() )
197 {
198 if (gFocusWindow )
199 {
200 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
201 if ( control && control->GetMacControl() )
202 {
203 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
204 }
205 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
206 event.SetEventObject(gFocusWindow);
207 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
208 }
209 gFocusWindow = this ;
210 {
211 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
212 if ( control && control->GetMacControl() )
213 {
214 UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
215 }
216
217 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
218 event.SetEventObject(this);
219 GetEventHandler()->ProcessEvent(event) ;
220 }
221 }
222 }
223
224 bool wxWindow::Enable(bool enable)
225 {
226 if ( !wxWindowBase::Enable(enable) )
227 return FALSE;
228 /*
229 HWND hWnd = GetHwnd();
230 if ( hWnd )
231 ::EnableWindow(hWnd, (BOOL)enable);
232 */
233
234 wxWindowList::Node *node = GetChildren().GetFirst();
235 while ( node )
236 {
237 wxWindow *child = node->GetData();
238 child->Enable(enable);
239
240 node = node->GetNext();
241 }
242
243 return TRUE;
244 }
245
246 void wxWindow::CaptureMouse()
247 {
248 wxTheApp->s_captureWindow = this ;
249 }
250
251 void wxWindow::ReleaseMouse()
252 {
253 wxTheApp->s_captureWindow = NULL ;
254 }
255
256 #if wxUSE_DRAG_AND_DROP
257
258 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
259 {
260 if ( m_pDropTarget != 0 ) {
261 delete m_pDropTarget;
262 }
263
264 m_pDropTarget = pDropTarget;
265 if ( m_pDropTarget != 0 )
266 {
267 // TODO
268 }
269 }
270
271 #endif
272
273 // Old style file-manager drag&drop
274 void wxWindow::DragAcceptFiles(bool accept)
275 {
276 // TODO
277 }
278
279 // Get total size
280 void wxWindow::DoGetSize(int *x, int *y) const
281 {
282 *x = m_width ;
283 *y = m_height ;
284 }
285
286 void wxWindow::DoGetPosition(int *x, int *y) const
287 {
288 *x = m_x ;
289 *y = m_y ;
290 if (GetParent())
291 {
292 wxPoint pt(GetParent()->GetClientAreaOrigin());
293 *x -= pt.x;
294 *y -= pt.y;
295 }
296 }
297
298 void wxWindow::DoScreenToClient(int *x, int *y) const
299 {
300 WindowRef window = GetMacRootWindow() ;
301
302 Point localwhere ;
303 localwhere.h = * x ;
304 localwhere.v = * y ;
305
306 GrafPtr port ;
307 ::GetPort( &port ) ;
308 ::SetPort( UMAGetWindowPort( window ) ) ;
309 ::GlobalToLocal( &localwhere ) ;
310 ::SetPort( port ) ;
311
312 *x = localwhere.h ;
313 *y = localwhere.v ;
314
315 MacRootWindowToClient( x , y ) ;
316 }
317
318 void wxWindow::DoClientToScreen(int *x, int *y) const
319 {
320 WindowRef window = GetMacRootWindow() ;
321
322 MacClientToRootWindow( x , y ) ;
323
324 Point localwhere ;
325 localwhere.h = * x ;
326 localwhere.v = * y ;
327
328 GrafPtr port ;
329 ::GetPort( &port ) ;
330 ::SetPort( UMAGetWindowPort( window ) ) ;
331 ::LocalToGlobal( &localwhere ) ;
332 ::SetPort( port ) ;
333 *x = localwhere.h ;
334 *y = localwhere.v ;
335 }
336
337 void wxWindow::MacClientToRootWindow( int *x , int *y ) const
338 {
339 if ( m_macWindowData )
340 {
341 }
342 else
343 {
344 *x += m_x ;
345 *y += m_y ;
346 GetParent()->MacClientToRootWindow( x , y ) ;
347 }
348 }
349
350 void wxWindow::MacRootWindowToClient( int *x , int *y ) const
351 {
352 if ( m_macWindowData )
353 {
354 }
355 else
356 {
357 *x -= m_x ;
358 *y -= m_y ;
359 GetParent()->MacRootWindowToClient( x , y ) ;
360 }
361 }
362
363 bool wxWindow::SetCursor(const wxCursor& cursor)
364 {
365 if ( !wxWindowBase::SetCursor(cursor) )
366 {
367 // no change
368 return FALSE;
369 }
370
371 wxASSERT_MSG( m_cursor.Ok(),
372 wxT("cursor must be valid after call to the base version"));
373
374 Point pt ;
375 wxWindow *mouseWin ;
376 GetMouse( &pt ) ;
377
378 // Change the cursor NOW if we're within the correct window
379
380 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
381 {
382 if ( mouseWin == this && !wxIsBusy() )
383 {
384 cursor.MacInstall() ;
385 }
386 }
387
388 return TRUE ;
389 }
390
391
392 // Get size *available for subwindows* i.e. excluding menu bar etc.
393 void wxWindow::DoGetClientSize(int *x, int *y) const
394 {
395 *x = m_width ;
396 *y = m_height ;
397
398 if (m_vScrollBar && m_vScrollBar->IsShown() )
399 (*x) -= MAC_SCROLLBAR_SIZE;
400 if (m_hScrollBar && m_hScrollBar->IsShown() )
401 (*y) -= MAC_SCROLLBAR_SIZE;
402 }
403
404 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
405 {
406 int former_x = m_x ;
407 int former_y = m_y ;
408 int former_w = m_width ;
409 int former_h = m_height ;
410
411 int currentX, currentY;
412 GetPosition(&currentX, &currentY);
413 int currentW,currentH;
414 GetSize(&currentW, &currentH);
415
416 int actualWidth = width;
417 int actualHeight = height;
418 int actualX = x;
419 int actualY = y;
420 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
421 actualX = currentX;
422 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
423 actualY = currentY;
424 if (width == -1)
425 actualWidth = currentW ;
426 if (height == -1)
427 actualHeight = currentH ;
428
429 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
430 {
431 MacRepositionScrollBars() ; // we might have a real position shift
432 return ;
433 }
434
435 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
436
437
438 bool doMove = false ;
439 bool doResize = false ;
440
441 if ( actualX != former_x || actualY != former_y )
442 {
443 doMove = true ;
444 }
445 if ( actualWidth != former_w || actualHeight != former_h )
446 {
447 doResize = true ;
448 }
449
450 if ( doMove || doResize )
451 {
452 if ( m_macWindowData )
453 {
454 }
455 else
456 {
457 // erase former position
458 {
459 wxMacDrawingClientHelper focus( this ) ;
460 if ( focus.Ok() )
461 {
462 Rect clientrect = { 0 , 0 , m_height , m_width } ;
463 InvalRect( &clientrect ) ;
464 }
465 }
466 }
467 m_x = actualX ;
468 m_y = actualY ;
469 m_width = actualWidth ;
470 m_height = actualHeight ;
471 if ( m_macWindowData )
472 {
473 if ( doMove )
474 ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y, false); // don't make frontmost
475
476 if ( doResize )
477 ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height, true);
478
479 // the OS takes care of invalidating and erasing
480
481 if ( IsKindOf( CLASSINFO( wxFrame ) ) )
482 {
483 wxFrame* frame = (wxFrame*) this ;
484 frame->PositionStatusBar();
485 frame->PositionToolBar();
486 }
487 }
488 else
489 {
490 // erase new position
491 {
492 wxMacDrawingClientHelper focus( this ) ;
493 if ( focus.Ok() )
494 {
495 Rect clientrect = { 0 , 0 , m_height , m_width } ;
496 InvalRect( &clientrect ) ;
497 }
498 }
499 if ( doMove )
500 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
501 }
502 MacRepositionScrollBars() ;
503 if ( doMove )
504 {
505 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
506 event.SetEventObject(this);
507 GetEventHandler()->ProcessEvent(event) ;
508 }
509 if ( doResize )
510 {
511 MacRepositionScrollBars() ;
512 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
513 event.SetEventObject(this);
514 GetEventHandler()->ProcessEvent(event);
515 }
516 }
517 }
518 // For implementation purposes - sometimes decorations make the client area
519 // smaller
520
521 wxPoint wxWindow::GetClientAreaOrigin() const
522 {
523 return wxPoint(0, 0);
524 }
525
526 // Makes an adjustment to the window position (for example, a frame that has
527 // a toolbar that it manages itself).
528 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
529 {
530 if( !m_macWindowData )
531 {
532 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
533 {
534 wxPoint pt(GetParent()->GetClientAreaOrigin());
535 x += pt.x; y += pt.y;
536 }
537 }
538 }
539
540 void wxWindow::SetTitle(const wxString& title)
541 {
542 m_label = title ;
543
544 wxString label ;
545
546 if( wxApp::s_macDefaultEncodingIsPC )
547 label = wxMacMakeMacStringFromPC( title ) ;
548 else
549 label = title ;
550
551 if ( m_macWindowData )
552 UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
553 }
554
555 wxString wxWindow::GetTitle() const
556 {
557 return m_label ;
558 }
559
560 bool wxWindow::Show(bool show)
561 {
562 if ( !wxWindowBase::Show(show) )
563 return FALSE;
564
565 if ( m_macWindowData )
566 {
567 if (show)
568 {
569 UMAShowWindow( m_macWindowData->m_macWindow ) ;
570 UMASelectWindow( m_macWindowData->m_macWindow ) ;
571 // no need to generate events here, they will get them triggered by macos
572 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
573 event.SetEventObject(this);
574 GetEventHandler()->ProcessEvent(event);
575 }
576 else
577 {
578 UMAHideWindow( m_macWindowData->m_macWindow ) ;
579 }
580 }
581 Refresh() ;
582
583 return TRUE;
584 }
585
586 int wxWindow::GetCharHeight() const
587 {
588 wxClientDC dc ( (wxWindow*)this ) ;
589 return dc.GetCharHeight() ;
590 }
591
592 int wxWindow::GetCharWidth() const
593 {
594 wxClientDC dc ( (wxWindow*)this ) ;
595 return dc.GetCharWidth() ;
596 }
597
598 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
599 int *descent, int *externalLeading, const wxFont *theFont ) const
600 {
601 const wxFont *fontToUse = theFont;
602 if ( !fontToUse )
603 fontToUse = &m_font;
604 /*
605 if ( x )
606 *x = sizeRect.cx;
607 if ( y )
608 *y = sizeRect.cy;
609 if ( descent )
610 *descent = tm.tmDescent;
611 if ( externalLeading )
612 *externalLeading = tm.tmExternalLeading;
613 */
614
615 }
616
617 void wxWindow::MacEraseBackground( Rect *rect )
618 {
619 WindowRef window = GetMacRootWindow() ;
620 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
621 {
622 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
623 }
624 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
625 {
626 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
627 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
628 // either a non gray background color or a non control window
629
630 wxWindow* parent = GetParent() ;
631 while( parent )
632 {
633 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
634 {
635 // if we have any other colours in the hierarchy
636 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
637 break ;
638 }
639 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
640 {
641 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
642 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
643 {
644 ApplyThemeBackground (kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
645 break ;
646 }
647 }
648 else
649 {
650 // we have arrived at a non control item
651 parent = NULL ;
652 break ;
653 }
654 parent = parent->GetParent() ;
655 }
656 if ( !parent )
657 {
658 // if there is nothing special -> use default
659 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
660 }
661 }
662 else
663 {
664 RGBBackColor( &m_backgroundColour.GetPixel()) ;
665 }
666
667 EraseRect( rect ) ;
668
669 for (wxNode *node = GetChildren().First(); node; node = node->Next())
670 {
671 wxWindow *child = (wxWindow*)node->Data();
672 // int width ;
673 // int height ;
674
675 // child->GetClientSize( &width , &height ) ;
676
677 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
678 SectRect( &clientrect , rect , &clientrect ) ;
679
680 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
681 if ( child->GetMacRootWindow() == window && child->IsShown() )
682 {
683 wxMacDrawingClientHelper focus( this ) ;
684 if ( focus.Ok() )
685 {
686 child->MacEraseBackground( &clientrect ) ;
687 }
688 }
689 }
690 }
691
692 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
693 {
694 wxMacDrawingClientHelper focus( this ) ;
695 if ( focus.Ok() )
696 {
697 int width , height ;
698 GetClientSize( &width , &height ) ;
699 Rect clientrect = { 0 , 0 , height , width } ;
700 ClipRect( &clientrect ) ;
701
702 if ( rect )
703 {
704 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
705 SectRect( &clientrect , &r , &clientrect ) ;
706 }
707 InvalRect( &clientrect ) ;
708 /*
709 if ( eraseBack )
710 {
711 MacEraseBackground( &clientrect ) ;
712 }
713 */
714 }
715 }
716
717 // Responds to colour changes: passes event on to children.
718 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
719 {
720 wxNode *node = GetChildren().First();
721 while ( node )
722 {
723 // Only propagate to non-top-level windows
724 wxWindow *win = (wxWindow *)node->Data();
725 if ( win->GetParent() )
726 {
727 wxSysColourChangedEvent event2;
728 event.m_eventObject = win;
729 win->GetEventHandler()->ProcessEvent(event2);
730 }
731
732 node = node->Next();
733 }
734 }
735
736 #if wxUSE_CARET && WXWIN_COMPATIBILITY
737 // ---------------------------------------------------------------------------
738 // Caret manipulation
739 // ---------------------------------------------------------------------------
740
741 void wxWindow::CreateCaret(int w, int h)
742 {
743 SetCaret(new wxCaret(this, w, h));
744 }
745
746 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
747 {
748 wxFAIL_MSG("not implemented");
749 }
750
751 void wxWindow::ShowCaret(bool show)
752 {
753 wxCHECK_RET( m_caret, "no caret to show" );
754
755 m_caret->Show(show);
756 }
757
758 void wxWindow::DestroyCaret()
759 {
760 SetCaret(NULL);
761 }
762
763 void wxWindow::SetCaretPos(int x, int y)
764 {
765 wxCHECK_RET( m_caret, "no caret to move" );
766
767 m_caret->Move(x, y);
768 }
769
770 void wxWindow::GetCaretPos(int *x, int *y) const
771 {
772 wxCHECK_RET( m_caret, "no caret to get position of" );
773
774 m_caret->GetPosition(x, y);
775 }
776 #endif // wxUSE_CARET
777
778 wxWindow *wxGetActiveWindow()
779 {
780 // actually this is a windows-only concept
781 return NULL;
782 }
783
784 // Coordinates relative to the window
785 void wxWindow::WarpPointer (int x_pos, int y_pos)
786 {
787 // We really dont move the mouse programmatically under mac
788 }
789
790 void wxWindow::OnEraseBackground(wxEraseEvent& event)
791 {
792 // TODO : probably we would adopt the EraseEvent structure
793 Default();
794 }
795
796 int wxWindow::GetScrollPos(int orient) const
797 {
798 if ( orient == wxHORIZONTAL )
799 {
800 if ( m_hScrollBar )
801 return m_hScrollBar->GetThumbPosition() ;
802 }
803 else
804 {
805 if ( m_vScrollBar )
806 return m_vScrollBar->GetThumbPosition() ;
807 }
808 return 0;
809 }
810
811 // This now returns the whole range, not just the number
812 // of positions that we can scroll.
813 int wxWindow::GetScrollRange(int orient) const
814 {
815 if ( orient == wxHORIZONTAL )
816 {
817 if ( m_hScrollBar )
818 return m_hScrollBar->GetRange() ;
819 }
820 else
821 {
822 if ( m_vScrollBar )
823 return m_vScrollBar->GetRange() ;
824 }
825 return 0;
826 }
827
828 int wxWindow::GetScrollThumb(int orient) const
829 {
830 if ( orient == wxHORIZONTAL )
831 {
832 if ( m_hScrollBar )
833 return m_hScrollBar->GetThumbSize() ;
834 }
835 else
836 {
837 if ( m_vScrollBar )
838 return m_vScrollBar->GetThumbSize() ;
839 }
840 return 0;
841 }
842
843 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
844 {
845 if ( orient == wxHORIZONTAL )
846 {
847 if ( m_hScrollBar )
848 m_hScrollBar->SetThumbPosition( pos ) ;
849 }
850 else
851 {
852 if ( m_vScrollBar )
853 m_vScrollBar->SetThumbPosition( pos ) ;
854 }
855 }
856
857 // New function that will replace some of the above.
858 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
859 int range, bool refresh)
860 {
861 if ( orient == wxHORIZONTAL )
862 {
863 if ( m_hScrollBar )
864 {
865 if ( range == 0 || thumbVisible >= range )
866 {
867 if ( m_hScrollBar->IsShown() )
868 m_hScrollBar->Show(false) ;
869 }
870 else
871 {
872 if ( !m_hScrollBar->IsShown() )
873 m_hScrollBar->Show(true) ;
874 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
875 }
876 }
877 }
878 else
879 {
880 if ( m_vScrollBar )
881 {
882 if ( range == 0 || thumbVisible >= range )
883 {
884 if ( m_vScrollBar->IsShown() )
885 m_vScrollBar->Show(false) ;
886 }
887 else
888 {
889 if ( !m_vScrollBar->IsShown() )
890 m_vScrollBar->Show(true) ;
891 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
892 }
893 }
894 }
895 MacRepositionScrollBars() ;
896 }
897
898 // Does a physical scroll
899 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
900 {
901 wxMacDrawingClientHelper focus( this ) ;
902 if ( focus.Ok() )
903 {
904 int width , height ;
905 GetClientSize( &width , &height ) ;
906 Rect scrollrect = { 0 , 0 , height , width } ;
907
908 RgnHandle updateRgn = NewRgn() ;
909 ClipRect( &scrollrect ) ;
910 if ( rect )
911 {
912 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
913 SectRect( &scrollrect , &r , &scrollrect ) ;
914 }
915 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
916 InvalRgn( updateRgn ) ;
917 DisposeRgn( updateRgn ) ;
918 }
919 }
920
921 bool wxWindow::SetFont(const wxFont& font)
922 {
923 if ( !wxWindowBase::SetFont(font) )
924 {
925 // nothing to do
926 return FALSE;
927 }
928
929 return TRUE;
930 }
931
932 // Get the window with the focus
933 wxWindow *wxWindowBase::FindFocus()
934 {
935 return gFocusWindow ;
936 }
937
938 #if WXWIN_COMPATIBILITY
939 // If nothing defined for this, try the parent.
940 // E.g. we may be a button loaded from a resource, with no callback function
941 // defined.
942 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
943 {
944 if ( GetEventHandler()->ProcessEvent(event) )
945 return;
946 if ( m_parent )
947 m_parent->GetEventHandler()->OnCommand(win, event);
948 }
949 #endif // WXWIN_COMPATIBILITY_2
950
951 #if WXWIN_COMPATIBILITY
952 wxObject* wxWindow::GetChild(int number) const
953 {
954 // Return a pointer to the Nth object in the Panel
955 wxNode *node = GetChildren().First();
956 int n = number;
957 while (node && n--)
958 node = node->Next();
959 if ( node )
960 {
961 wxObject *obj = (wxObject *)node->Data();
962 return(obj);
963 }
964 else
965 return NULL;
966 }
967 #endif // WXWIN_COMPATIBILITY
968
969 void wxWindow::Clear()
970 {
971 if ( m_macWindowData )
972 {
973 wxMacDrawingClientHelper helper ( this ) ;
974 int w ,h ;
975 wxPoint origin = GetClientAreaOrigin() ;
976 GetClientSize( &w , &h ) ;
977 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
978 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
979 EraseRect( &r ) ;
980 }
981 else
982 {
983 wxClientDC dc(this);
984 wxBrush brush(GetBackgroundColour(), wxSOLID);
985 dc.SetBackground(brush);
986 dc.Clear();
987 }
988 }
989
990 // Setup background and foreground colours correctly
991 void wxWindow::SetupColours()
992 {
993 if ( GetParent() )
994 SetBackgroundColour(GetParent()->GetBackgroundColour());
995 }
996
997 void wxWindow::OnIdle(wxIdleEvent& event)
998 {
999 /*
1000 // Check if we need to send a LEAVE event
1001 if (m_mouseInWindow)
1002 {
1003 POINT pt;
1004 ::GetCursorPos(&pt);
1005 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1006 {
1007 // Generate a LEAVE event
1008 m_mouseInWindow = FALSE;
1009 MSWOnMouseLeave(pt.x, pt.y, 0);
1010 }
1011 }
1012 */
1013
1014 // This calls the UI-update mechanism (querying windows for
1015 // menu/toolbar/control state information)
1016 UpdateWindowUI();
1017 }
1018
1019 // Raise the window to the top of the Z order
1020 void wxWindow::Raise()
1021 {
1022 // TODO
1023 }
1024
1025 // Lower the window to the bottom of the Z order
1026 void wxWindow::Lower()
1027 {
1028 // TODO
1029 }
1030
1031 void wxWindow::DoSetClientSize(int width, int height)
1032 {
1033 if ( width != -1 || height != -1 )
1034 {
1035
1036 if ( width != -1 && m_vScrollBar )
1037 width += MAC_SCROLLBAR_SIZE ;
1038 if ( height != -1 && m_vScrollBar )
1039 height += MAC_SCROLLBAR_SIZE ;
1040
1041 DoSetSize( -1 , -1 , width , height ) ;
1042 }
1043 }
1044
1045
1046 wxWindow* wxWindow::s_lastMouseWindow = NULL ;
1047
1048 bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin )
1049 {
1050 if ((point.x < m_x) || (point.y < m_y) ||
1051 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1052 return FALSE;
1053
1054 WindowRef window = GetMacRootWindow() ;
1055
1056 wxPoint newPoint( point ) ;
1057
1058 newPoint.x -= m_x;
1059 newPoint.y -= m_y;
1060
1061 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1062 {
1063 wxWindow *child = (wxWindow*)node->Data();
1064 if ( child->GetMacRootWindow() == window )
1065 {
1066 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1067 return TRUE;
1068 }
1069 }
1070
1071 *outWin = this ;
1072 return TRUE;
1073 }
1074
1075 bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin )
1076 {
1077 WindowRef window ;
1078 Point pt = { screenpoint.y , screenpoint.x } ;
1079 if ( ::FindWindow( pt , &window ) == 3 )
1080 {
1081 wxPoint point( screenpoint ) ;
1082 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1083 win->ScreenToClient( point ) ;
1084 return win->MacGetWindowFromPointSub( point , outWin ) ;
1085 }
1086 return FALSE ;
1087 }
1088
1089 extern int wxBusyCursorCount ;
1090
1091 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
1092 {
1093 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1094 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1095 return FALSE;
1096
1097 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1098 return FALSE ;
1099
1100 WindowRef window = GetMacRootWindow() ;
1101
1102 event.m_x -= m_x;
1103 event.m_y -= m_y;
1104
1105 int x = event.m_x ;
1106 int y = event.m_y ;
1107
1108 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1109 {
1110 wxWindow *child = (wxWindow*)node->Data();
1111 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
1112 {
1113 if (child->MacDispatchMouseEvent(event))
1114 return TRUE;
1115 }
1116 }
1117
1118 event.m_x = x ;
1119 event.m_y = y ;
1120
1121 if ( wxBusyCursorCount == 0 )
1122 {
1123 m_cursor.MacInstall() ;
1124 }
1125 GetEventHandler()->ProcessEvent( event ) ;
1126 return TRUE;
1127 }
1128
1129 void wxWindow::MacFireMouseEvent( EventRecord *ev )
1130 {
1131 wxMouseEvent event(wxEVT_LEFT_DOWN);
1132 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1133 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1134
1135 event.m_leftDown = isDown && !controlDown;
1136 event.m_middleDown = FALSE;
1137 event.m_rightDown = isDown && controlDown;
1138
1139 if ( ev->what == mouseDown )
1140 {
1141 if ( controlDown )
1142 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1143 else
1144 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1145 }
1146 else if ( ev->what == mouseUp )
1147 {
1148 if ( controlDown )
1149 event.SetEventType(wxEVT_RIGHT_UP ) ;
1150 else
1151 event.SetEventType(wxEVT_LEFT_UP ) ;
1152 }
1153 else
1154 {
1155 event.SetEventType(wxEVT_MOTION ) ;
1156 }
1157
1158 event.m_shiftDown = ev->modifiers & shiftKey;
1159 event.m_controlDown = ev->modifiers & controlKey;
1160 event.m_altDown = ev->modifiers & optionKey;
1161 event.m_metaDown = ev->modifiers & cmdKey;
1162
1163 Point localwhere = ev->where ;
1164
1165 GrafPtr port ;
1166 ::GetPort( &port ) ;
1167 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1168 ::GlobalToLocal( &localwhere ) ;
1169 ::SetPort( port ) ;
1170
1171 event.m_x = localwhere.h;
1172 event.m_y = localwhere.v;
1173 event.m_x += m_x;
1174 event.m_y += m_y;
1175
1176 /*
1177 wxPoint origin = GetClientAreaOrigin() ;
1178
1179 event.m_x += origin.x ;
1180 event.m_y += origin.y ;
1181 */
1182
1183 event.m_timeStamp = ev->when;
1184 event.SetEventObject(this);
1185 if ( wxTheApp->s_captureWindow )
1186 {
1187 int x = event.m_x ;
1188 int y = event.m_y ;
1189 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1190 event.m_x = x ;
1191 event.m_y = y ;
1192 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1193 if ( ev->what == mouseUp )
1194 {
1195 wxTheApp->s_captureWindow = NULL ;
1196 if ( wxBusyCursorCount == 0 )
1197 {
1198 m_cursor.MacInstall() ;
1199 }
1200 }
1201 }
1202 else
1203 {
1204 MacDispatchMouseEvent( event ) ;
1205 }
1206 }
1207
1208 void wxWindow::MacMouseDown( EventRecord *ev , short part)
1209 {
1210 MacFireMouseEvent( ev ) ;
1211 }
1212
1213 void wxWindow::MacMouseUp( EventRecord *ev , short part)
1214 {
1215 WindowPtr frontWindow ;
1216 switch (part)
1217 {
1218 case inContent:
1219 {
1220 MacFireMouseEvent( ev ) ;
1221 }
1222 break ;
1223 }
1224 }
1225
1226 void wxWindow::MacMouseMoved( EventRecord *ev , short part)
1227 {
1228 WindowPtr frontWindow ;
1229 switch (part)
1230 {
1231 case inContent:
1232 {
1233 MacFireMouseEvent( ev ) ;
1234 }
1235 break ;
1236 }
1237 }
1238 void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
1239 {
1240 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating);
1241 event.m_timeStamp = ev->when ;
1242 event.SetEventObject(this);
1243
1244 GetEventHandler()->ProcessEvent(event);
1245
1246 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
1247 }
1248
1249 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
1250 {
1251 // updatergn is always already clipped to our boundaries
1252 WindowRef window = GetMacRootWindow() ;
1253 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1254 {
1255 wxMacDrawingClientHelper focus( this ) ;
1256 if ( focus.Ok() )
1257 {
1258 WindowRef window = GetMacRootWindow() ;
1259 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1260 {
1261 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1262 }
1263 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1264 {
1265 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1266 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1267 // either a non gray background color or a non control window
1268
1269
1270 wxWindow* parent = GetParent() ;
1271 while( parent )
1272 {
1273 if ( parent->GetMacRootWindow() != window )
1274 {
1275 // we are in a different window on the mac system
1276 parent = NULL ;
1277 break ;
1278 }
1279
1280 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1281 {
1282 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1283 {
1284 // if we have any other colours in the hierarchy
1285 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1286 break ;
1287 }
1288 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1289 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1290 {
1291 ApplyThemeBackground (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true);
1292 break ;
1293 }
1294 }
1295 else
1296 {
1297 parent = NULL ;
1298 break ;
1299 }
1300 parent = parent->GetParent() ;
1301 }
1302 if ( !parent )
1303 {
1304 // if there is nothing special -> use default
1305 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1306 }
1307 }
1308 else
1309 {
1310 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1311 }
1312 SetClip( updatergn ) ;
1313 EraseRgn( updatergn ) ;
1314 }
1315 }
1316
1317
1318 m_updateRegion = updatergn ;
1319 wxPaintEvent event;
1320 event.m_timeStamp = time ;
1321 event.SetEventObject(this);
1322
1323 GetEventHandler()->ProcessEvent(event);
1324
1325 RgnHandle childupdate = NewRgn() ;
1326
1327 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1328 {
1329 wxWindow *child = (wxWindow*)node->Data();
1330 int width ;
1331 int height ;
1332
1333 child->GetClientSize( &width , &height ) ;
1334
1335 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ;
1336 SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ;
1337 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1338 if ( child->GetMacRootWindow() == window && child->IsShown() )
1339 {
1340 // because dialogs may also be children
1341 child->MacRedraw( childupdate , time ) ;
1342 }
1343 }
1344 DisposeRgn( childupdate ) ;
1345 // eventually a draw grow box here
1346 }
1347
1348 void wxWindow::MacUpdateImmediately()
1349 {
1350 WindowRef window = GetMacRootWindow() ;
1351 if ( window )
1352 {
1353 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1354 BeginUpdate( window ) ;
1355 if ( win )
1356 {
1357 #if ! TARGET_CARBON
1358 if ( !EmptyRgn( window->visRgn ) )
1359 #endif
1360 {
1361 win->MacRedraw( window->visRgn , wxTheApp->sm_lastMessageTime ) ;
1362 /*
1363 {
1364 wxMacDrawingHelper help( win ) ;
1365 SetOrigin( 0 , 0 ) ;
1366 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1367 UMAUpdateControls( window , window->visRgn ) ;
1368 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1369 }
1370 */
1371 }
1372 }
1373 EndUpdate( window ) ;
1374 }
1375 }
1376
1377 void wxWindow::MacUpdate( EventRecord *ev )
1378 {
1379 WindowRef window = (WindowRef) ev->message ;
1380 wxWindow * win = wxFindWinFromMacWindow( window ) ;
1381
1382 BeginUpdate( window ) ;
1383 if ( win )
1384 {
1385 // if windowshade gives incompatibility , take the follwing out
1386 #if ! TARGET_CARBON
1387 if ( !EmptyRgn( window->visRgn ) )
1388 #endif
1389 {
1390 MacRedraw( window->visRgn , ev->when ) ;
1391 /*
1392 {
1393 wxMacDrawingHelper help( this ) ;
1394 SetOrigin( 0 , 0 ) ;
1395 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1396 UMAUpdateControls( window , window->visRgn ) ;
1397 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1398 }
1399 */
1400 }
1401 }
1402 EndUpdate( window ) ;
1403 }
1404
1405 WindowRef wxWindow::GetMacRootWindow() const
1406 {
1407 WindowRef window = NULL ;
1408 wxWindow *iter = (wxWindow*)this ;
1409
1410 while( iter )
1411 {
1412 if ( iter->m_macWindowData )
1413 return iter->m_macWindowData->m_macWindow ;
1414
1415 iter = iter->GetParent() ;
1416 }
1417 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1418 return NULL ;
1419 }
1420
1421 void wxWindow::MacCreateScrollBars( long style )
1422 {
1423 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1424 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1425 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1426
1427 if ( style & wxVSCROLL )
1428 {
1429 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0),
1430 wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL);
1431 }
1432 if ( style & wxHSCROLL )
1433 {
1434 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ),
1435 wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL);
1436 }
1437 // because the create does not take into account the client area origin
1438 MacRepositionScrollBars() ; // we might have a real position shift
1439 }
1440
1441 void wxWindow::MacRepositionScrollBars()
1442 {
1443 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1444 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1445
1446 if ( m_vScrollBar )
1447 {
1448 m_vScrollBar->SetSize( m_width-MAC_SCROLLBAR_SIZE, 0, MAC_SCROLLBAR_SIZE, m_height - adjust , wxSIZE_USE_EXISTING);
1449 }
1450 if ( m_hScrollBar )
1451 {
1452 m_hScrollBar->SetSize( 0 , m_height-MAC_SCROLLBAR_SIZE ,m_width - adjust, MAC_SCROLLBAR_SIZE, wxSIZE_USE_EXISTING);
1453 }
1454 }
1455
1456 void wxWindow::MacKeyDown( EventRecord *ev )
1457 {
1458 }
1459
1460
1461
1462
1463 ControlHandle wxWindow::MacGetContainerForEmbedding()
1464 {
1465 if ( m_macWindowData )
1466 return m_macWindowData->m_macRootControl ;
1467 else
1468 return GetParent()->MacGetContainerForEmbedding() ;
1469 }
1470
1471 void wxWindow::MacSuperChangedPosition()
1472 {
1473 // only window-absolute structures have to be moved i.e. controls
1474
1475 wxNode *node = GetChildren().First();
1476 while ( node )
1477 {
1478 wxWindow *child = (wxWindow *)node->Data();
1479 child->MacSuperChangedPosition() ;
1480 node = node->Next();
1481 }
1482 }
1483
1484 bool wxWindow::MacSetupFocusPort( )
1485 {
1486 Point localOrigin ;
1487 Rect clipRect ;
1488 WindowRef window ;
1489 wxWindow *rootwin ;
1490 GrafPtr port ;
1491
1492 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1493 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1494 }
1495
1496 bool wxWindow::MacSetupFocusClientPort( )
1497 {
1498 Point localOrigin ;
1499 Rect clipRect ;
1500 WindowRef window ;
1501 wxWindow *rootwin ;
1502 GrafPtr port ;
1503
1504 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1505 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1506 }
1507
1508 bool wxWindow::MacSetupDrawingPort( )
1509 {
1510 Point localOrigin ;
1511 Rect clipRect ;
1512 WindowRef window ;
1513 wxWindow *rootwin ;
1514 GrafPtr port ;
1515
1516 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1517 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1518 }
1519
1520 bool wxWindow::MacSetupDrawingClientPort( )
1521 {
1522 Point localOrigin ;
1523 Rect clipRect ;
1524 WindowRef window ;
1525 wxWindow *rootwin ;
1526 GrafPtr port ;
1527
1528 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1529 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1530 }
1531
1532
1533 bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
1534 {
1535 if ( window == NULL )
1536 return false ;
1537
1538 GrafPtr currPort;
1539 GrafPtr port ;
1540
1541 ::GetPort(&currPort);
1542 port = UMAGetWindowPort( window) ;
1543 if (currPort != port )
1544 ::SetPort(port);
1545
1546 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1547 return true;
1548 }
1549
1550 bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
1551 {
1552 if ( window == NULL )
1553 return false ;
1554
1555 GrafPtr currPort;
1556 GrafPtr port ;
1557 ::GetPort(&currPort);
1558 port = UMAGetWindowPort( window) ;
1559 if (currPort != port )
1560 ::SetPort(port);
1561
1562 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1563 ::ClipRect(&clipRect);
1564
1565 ::PenNormal() ;
1566 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
1567 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
1568 ::BackPat( &qd.white ) ;
1569 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1570 return true;
1571 }
1572
1573 void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin)
1574 {
1575 if ( m_macWindowData )
1576 {
1577 localOrigin->h = 0;
1578 localOrigin->v = 0;
1579 clipRect->left = 0;
1580 clipRect->top = 0;
1581 clipRect->right = m_width;
1582 clipRect->bottom = m_height;
1583 *window = m_macWindowData->m_macWindow ;
1584 *rootwin = this ;
1585 }
1586 else
1587 {
1588 wxASSERT( GetParent() != NULL ) ;
1589 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
1590 localOrigin->h += m_x;
1591 localOrigin->v += m_y;
1592 OffsetRect(clipRect, -m_x, -m_y);
1593
1594 Rect myClip;
1595 myClip.left = 0;
1596 myClip.top = 0;
1597 myClip.right = m_width;
1598 myClip.bottom = m_height;
1599 SectRect(clipRect, &myClip, clipRect);
1600 }
1601 }
1602
1603 void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
1604 {
1605 int width , height ;
1606 GetClientSize( &width , &height ) ;
1607
1608 if ( m_macWindowData )
1609 {
1610 localOrigin->h = 0;
1611 localOrigin->v = 0;
1612 clipRect->left = 0;
1613 clipRect->top = 0;
1614 clipRect->right = m_width ;//width;
1615 clipRect->bottom = m_height ;// height;
1616 *window = m_macWindowData->m_macWindow ;
1617 *rootwin = this ;
1618 }
1619 else
1620 {
1621 wxASSERT( GetParent() != NULL ) ;
1622
1623 GetParent()->MacGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
1624
1625 localOrigin->h += m_x;
1626 localOrigin->v += m_y;
1627 OffsetRect(clipRect, -m_x, -m_y);
1628
1629 Rect myClip;
1630 myClip.left = 0;
1631 myClip.top = 0;
1632 myClip.right = width;
1633 myClip.bottom = height;
1634 SectRect(clipRect, &myClip, clipRect);
1635 }
1636 }
1637
1638 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
1639 {
1640 m_ok = false ;
1641 Point localOrigin ;
1642 Rect clipRect ;
1643 WindowRef window ;
1644 wxWindow *rootwin ;
1645 m_currentPort = NULL ;
1646 GetPort( &m_formerPort ) ;
1647 if ( theWindow )
1648 {
1649
1650 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1651 m_currentPort = UMAGetWindowPort( window ) ;
1652 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1653 m_ok = true ;
1654 }
1655 }
1656
1657 wxMacFocusHelper::~wxMacFocusHelper()
1658 {
1659 if ( m_ok )
1660 {
1661 SetOrigin( 0 , 0 ) ;
1662 }
1663 if ( m_formerPort != m_currentPort )
1664 SetPort( m_formerPort ) ;
1665 }
1666
1667 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow )
1668 {
1669 m_ok = false ;
1670 Point localOrigin ;
1671 Rect clipRect ;
1672 WindowRef window ;
1673 wxWindow *rootwin ;
1674 m_currentPort = NULL ;
1675
1676 GetPort( &m_formerPort ) ;
1677 if ( theWindow )
1678 {
1679 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1680 m_currentPort = UMAGetWindowPort( window ) ;
1681 if ( m_formerPort != m_currentPort )
1682 SetPort( m_currentPort ) ;
1683 GetPenState( &m_savedPenState ) ;
1684 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1685 m_ok = true ;
1686 }
1687 }
1688
1689 wxMacDrawingHelper::~wxMacDrawingHelper()
1690 {
1691 if ( m_ok )
1692 {
1693 SetPenState( &m_savedPenState ) ;
1694 SetOrigin( 0 , 0 ) ;
1695 ClipRect( &m_currentPort->portRect ) ;
1696 }
1697
1698 if ( m_formerPort != m_currentPort )
1699 SetPort( m_formerPort ) ;
1700 }
1701
1702 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
1703 {
1704 m_ok = false ;
1705 Point localOrigin ;
1706 Rect clipRect ;
1707 WindowRef window ;
1708 wxWindow *rootwin ;
1709 m_currentPort = NULL ;
1710
1711 GetPort( &m_formerPort ) ;
1712
1713 if ( theWindow )
1714 {
1715 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1716 m_currentPort = UMAGetWindowPort( window ) ;
1717 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1718 m_ok = true ;
1719 }
1720 }
1721
1722 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1723 {
1724 if ( m_ok )
1725 {
1726 SetOrigin( 0 , 0 ) ;
1727 }
1728 if ( m_formerPort != m_currentPort )
1729 SetPort( m_formerPort ) ;
1730 }
1731
1732 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow )
1733 {
1734 m_ok = false ;
1735 Point localOrigin ;
1736 Rect clipRect ;
1737 WindowRef window ;
1738 wxWindow *rootwin ;
1739 m_currentPort = NULL ;
1740
1741 GetPort( &m_formerPort ) ;
1742
1743 if ( theWindow )
1744 {
1745 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1746 m_currentPort = UMAGetWindowPort( window ) ;
1747 if ( m_formerPort != m_currentPort )
1748 SetPort( m_currentPort ) ;
1749 GetPenState( &m_savedPenState ) ;
1750 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1751 m_ok = true ;
1752 }
1753 }
1754
1755 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1756 {
1757 if ( m_ok )
1758 {
1759 SetPenState( &m_savedPenState ) ;
1760 SetOrigin( 0 , 0 ) ;
1761 ClipRect( &m_currentPort->portRect ) ;
1762 }
1763
1764 if ( m_formerPort != m_currentPort )
1765 SetPort( m_formerPort ) ;
1766 }
1767
1768 // ----------------------------------------------------------------------------
1769 // list classes implementation
1770 // ----------------------------------------------------------------------------
1771
1772 void wxWindowListNode::DeleteData()
1773 {
1774 delete (wxWindow *)GetData();
1775 }
1776