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