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