]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
wxMSW update for CW, wxMac updated
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/dc.h"
19 #include "wx/dcclient.h"
20 #include "wx/utils.h"
21 #include "wx/app.h"
22 #include "wx/panel.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/frame.h"
30 #include "wx/notebook.h"
31 #include "wx/tabctrl.h"
32 // 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 }
842
843 int wxWindow::GetScrollPos(int orient) const
844 {
845 if ( orient == wxHORIZONTAL )
846 {
847 if ( m_hScrollBar )
848 return m_hScrollBar->GetThumbPosition() ;
849 }
850 else
851 {
852 if ( m_vScrollBar )
853 return m_vScrollBar->GetThumbPosition() ;
854 }
855 return 0;
856 }
857
858 // This now returns the whole range, not just the number
859 // of positions that we can scroll.
860 int wxWindow::GetScrollRange(int orient) const
861 {
862 if ( orient == wxHORIZONTAL )
863 {
864 if ( m_hScrollBar )
865 return m_hScrollBar->GetRange() ;
866 }
867 else
868 {
869 if ( m_vScrollBar )
870 return m_vScrollBar->GetRange() ;
871 }
872 return 0;
873 }
874
875 int wxWindow::GetScrollThumb(int orient) const
876 {
877 if ( orient == wxHORIZONTAL )
878 {
879 if ( m_hScrollBar )
880 return m_hScrollBar->GetThumbSize() ;
881 }
882 else
883 {
884 if ( m_vScrollBar )
885 return m_vScrollBar->GetThumbSize() ;
886 }
887 return 0;
888 }
889
890 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
891 {
892 if ( orient == wxHORIZONTAL )
893 {
894 if ( m_hScrollBar )
895 m_hScrollBar->SetThumbPosition( pos ) ;
896 }
897 else
898 {
899 if ( m_vScrollBar )
900 m_vScrollBar->SetThumbPosition( pos ) ;
901 }
902 }
903
904 // New function that will replace some of the above.
905 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
906 int range, bool refresh)
907 {
908 if ( orient == wxHORIZONTAL )
909 {
910 if ( m_hScrollBar )
911 {
912 if ( range == 0 || thumbVisible >= range )
913 {
914 if ( m_hScrollBar->IsShown() )
915 m_hScrollBar->Show(false) ;
916 }
917 else
918 {
919 if ( !m_hScrollBar->IsShown() )
920 m_hScrollBar->Show(true) ;
921 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
922 }
923 }
924 }
925 else
926 {
927 if ( m_vScrollBar )
928 {
929 if ( range == 0 || thumbVisible >= range )
930 {
931 if ( m_vScrollBar->IsShown() )
932 m_vScrollBar->Show(false) ;
933 }
934 else
935 {
936 if ( !m_vScrollBar->IsShown() )
937 m_vScrollBar->Show(true) ;
938 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
939 }
940 }
941 }
942 MacRepositionScrollBars() ;
943 }
944
945 // Does a physical scroll
946 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
947 {
948 wxMacDrawingClientHelper focus( this ) ;
949 if ( focus.Ok() )
950 {
951 int width , height ;
952 GetClientSize( &width , &height ) ;
953 Rect scrollrect = { 0 , 0 , height , width } ;
954
955 RgnHandle updateRgn = NewRgn() ;
956 ClipRect( &scrollrect ) ;
957 if ( rect )
958 {
959 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
960 SectRect( &scrollrect , &r , &scrollrect ) ;
961 }
962 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
963 InvalRgn( updateRgn ) ;
964 DisposeRgn( updateRgn ) ;
965 }
966 }
967
968 void wxWindow::MacOnScroll(wxScrollEvent &event )
969 {
970 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
971 {
972 wxScrollWinEvent wevent;
973 wevent.SetPosition(event.GetPosition());
974 wevent.SetOrientation(event.GetOrientation());
975 wevent.m_eventObject = this;
976
977 switch ( event.m_eventType )
978 {
979 case wxEVT_SCROLL_TOP:
980 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
981 break;
982
983 case wxEVT_SCROLL_BOTTOM:
984 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
985 break;
986
987 case wxEVT_SCROLL_LINEUP:
988 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
989 break;
990
991 case wxEVT_SCROLL_LINEDOWN:
992 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
993 break;
994
995 case wxEVT_SCROLL_PAGEUP:
996 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
997 break;
998
999 case wxEVT_SCROLL_PAGEDOWN:
1000 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1001 break;
1002
1003 case wxEVT_SCROLL_THUMBTRACK:
1004 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
1005 break;
1006
1007 }
1008
1009 GetEventHandler()->ProcessEvent(wevent);
1010 }
1011 }
1012
1013 bool wxWindow::SetFont(const wxFont& font)
1014 {
1015 if ( !wxWindowBase::SetFont(font) )
1016 {
1017 // nothing to do
1018 return FALSE;
1019 }
1020
1021 return TRUE;
1022 }
1023
1024 // Get the window with the focus
1025 wxWindow *wxWindowBase::FindFocus()
1026 {
1027 return gFocusWindow ;
1028 }
1029
1030 #if WXWIN_COMPATIBILITY
1031 // If nothing defined for this, try the parent.
1032 // E.g. we may be a button loaded from a resource, with no callback function
1033 // defined.
1034 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1035 {
1036 if ( GetEventHandler()->ProcessEvent(event) )
1037 return;
1038 if ( m_parent )
1039 m_parent->GetEventHandler()->OnCommand(win, event);
1040 }
1041 #endif // WXWIN_COMPATIBILITY_2
1042
1043 #if WXWIN_COMPATIBILITY
1044 wxObject* wxWindow::GetChild(int number) const
1045 {
1046 // Return a pointer to the Nth object in the Panel
1047 wxNode *node = GetChildren().First();
1048 int n = number;
1049 while (node && n--)
1050 node = node->Next();
1051 if ( node )
1052 {
1053 wxObject *obj = (wxObject *)node->Data();
1054 return(obj);
1055 }
1056 else
1057 return NULL;
1058 }
1059 #endif // WXWIN_COMPATIBILITY
1060
1061 void wxWindow::Clear()
1062 {
1063 if ( m_macWindowData )
1064 {
1065 wxMacDrawingClientHelper helper ( this ) ;
1066 int w ,h ;
1067 wxPoint origin = GetClientAreaOrigin() ;
1068 GetClientSize( &w , &h ) ;
1069 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1070 Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
1071 EraseRect( &r ) ;
1072 }
1073 else
1074 {
1075 wxClientDC dc(this);
1076 wxBrush brush(GetBackgroundColour(), wxSOLID);
1077 dc.SetBackground(brush);
1078 dc.Clear();
1079 }
1080 }
1081
1082 // Setup background and foreground colours correctly
1083 void wxWindow::SetupColours()
1084 {
1085 if ( GetParent() )
1086 SetBackgroundColour(GetParent()->GetBackgroundColour());
1087 }
1088
1089 void wxWindow::OnIdle(wxIdleEvent& event)
1090 {
1091 /*
1092 // Check if we need to send a LEAVE event
1093 if (m_mouseInWindow)
1094 {
1095 POINT pt;
1096 ::GetCursorPos(&pt);
1097 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1098 {
1099 // Generate a LEAVE event
1100 m_mouseInWindow = FALSE;
1101 MSWOnMouseLeave(pt.x, pt.y, 0);
1102 }
1103 }
1104 */
1105
1106 // This calls the UI-update mechanism (querying windows for
1107 // menu/toolbar/control state information)
1108 UpdateWindowUI();
1109 }
1110
1111 // Raise the window to the top of the Z order
1112 void wxWindow::Raise()
1113 {
1114 // TODO
1115 }
1116
1117 // Lower the window to the bottom of the Z order
1118 void wxWindow::Lower()
1119 {
1120 // TODO
1121 }
1122
1123 void wxWindow::DoSetClientSize(int width, int height)
1124 {
1125 if ( width != -1 || height != -1 )
1126 {
1127
1128 if ( width != -1 && m_vScrollBar )
1129 width += MAC_SCROLLBAR_SIZE ;
1130 if ( height != -1 && m_vScrollBar )
1131 height += MAC_SCROLLBAR_SIZE ;
1132
1133 DoSetSize( -1 , -1 , width , height ) ;
1134 }
1135 }
1136
1137
1138 wxWindow* wxWindow::s_lastMouseWindow = NULL ;
1139
1140 bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWin )
1141 {
1142 if ((point.x < m_x) || (point.y < m_y) ||
1143 (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
1144 return FALSE;
1145
1146 WindowRef window = GetMacRootWindow() ;
1147
1148 wxPoint newPoint( point ) ;
1149
1150 newPoint.x -= m_x;
1151 newPoint.y -= m_y;
1152
1153 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1154 {
1155 wxWindow *child = (wxWindow*)node->Data();
1156 if ( child->GetMacRootWindow() == window )
1157 {
1158 if (child->MacGetWindowFromPointSub(newPoint , outWin ))
1159 return TRUE;
1160 }
1161 }
1162
1163 *outWin = this ;
1164 return TRUE;
1165 }
1166
1167 bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** outWin )
1168 {
1169 WindowRef window ;
1170 Point pt = { screenpoint.y , screenpoint.x } ;
1171 if ( ::FindWindow( pt , &window ) == 3 )
1172 {
1173 wxPoint point( screenpoint ) ;
1174 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1175 win->ScreenToClient( point ) ;
1176 return win->MacGetWindowFromPointSub( point , outWin ) ;
1177 }
1178 return FALSE ;
1179 }
1180
1181 extern int wxBusyCursorCount ;
1182
1183 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event)
1184 {
1185 if ((event.m_x < m_x) || (event.m_y < m_y) ||
1186 (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height)))
1187 return FALSE;
1188
1189 if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
1190 return FALSE ;
1191
1192 WindowRef window = GetMacRootWindow() ;
1193
1194 event.m_x -= m_x;
1195 event.m_y -= m_y;
1196
1197 int x = event.m_x ;
1198 int y = event.m_y ;
1199
1200 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1201 {
1202 wxWindow *child = (wxWindow*)node->Data();
1203 if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
1204 {
1205 if (child->MacDispatchMouseEvent(event))
1206 return TRUE;
1207 }
1208 }
1209
1210 event.m_x = x ;
1211 event.m_y = y ;
1212
1213 if ( wxBusyCursorCount == 0 )
1214 {
1215 m_cursor.MacInstall() ;
1216 }
1217 GetEventHandler()->ProcessEvent( event ) ;
1218 return TRUE;
1219 }
1220
1221 void wxWindow::MacFireMouseEvent( EventRecord *ev )
1222 {
1223 wxMouseEvent event(wxEVT_LEFT_DOWN);
1224 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1225 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1226
1227 event.m_leftDown = isDown && !controlDown;
1228 event.m_middleDown = FALSE;
1229 event.m_rightDown = isDown && controlDown;
1230
1231 if ( ev->what == mouseDown )
1232 {
1233 if ( controlDown )
1234 event.SetEventType(wxEVT_RIGHT_DOWN ) ;
1235 else
1236 event.SetEventType(wxEVT_LEFT_DOWN ) ;
1237 }
1238 else if ( ev->what == mouseUp )
1239 {
1240 if ( controlDown )
1241 event.SetEventType(wxEVT_RIGHT_UP ) ;
1242 else
1243 event.SetEventType(wxEVT_LEFT_UP ) ;
1244 }
1245 else
1246 {
1247 event.SetEventType(wxEVT_MOTION ) ;
1248 }
1249
1250 event.m_shiftDown = ev->modifiers & shiftKey;
1251 event.m_controlDown = ev->modifiers & controlKey;
1252 event.m_altDown = ev->modifiers & optionKey;
1253 event.m_metaDown = ev->modifiers & cmdKey;
1254
1255 Point localwhere = ev->where ;
1256
1257 GrafPtr port ;
1258 ::GetPort( &port ) ;
1259 ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
1260 ::GlobalToLocal( &localwhere ) ;
1261 ::SetPort( port ) ;
1262
1263 event.m_x = localwhere.h;
1264 event.m_y = localwhere.v;
1265 event.m_x += m_x;
1266 event.m_y += m_y;
1267
1268 /*
1269 wxPoint origin = GetClientAreaOrigin() ;
1270
1271 event.m_x += origin.x ;
1272 event.m_y += origin.y ;
1273 */
1274
1275 event.m_timeStamp = ev->when;
1276 event.SetEventObject(this);
1277 if ( wxTheApp->s_captureWindow )
1278 {
1279 int x = event.m_x ;
1280 int y = event.m_y ;
1281 wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;
1282 event.m_x = x ;
1283 event.m_y = y ;
1284 wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
1285 if ( ev->what == mouseUp )
1286 {
1287 wxTheApp->s_captureWindow = NULL ;
1288 if ( wxBusyCursorCount == 0 )
1289 {
1290 m_cursor.MacInstall() ;
1291 }
1292 }
1293 }
1294 else
1295 {
1296 MacDispatchMouseEvent( event ) ;
1297 }
1298 }
1299
1300 void wxWindow::MacMouseDown( EventRecord *ev , short part)
1301 {
1302 MacFireMouseEvent( ev ) ;
1303 }
1304
1305 void wxWindow::MacMouseUp( EventRecord *ev , short part)
1306 {
1307 WindowPtr frontWindow ;
1308 switch (part)
1309 {
1310 case inContent:
1311 {
1312 MacFireMouseEvent( ev ) ;
1313 }
1314 break ;
1315 }
1316 }
1317
1318 void wxWindow::MacMouseMoved( 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 void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
1331 {
1332 wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating);
1333 event.m_timeStamp = ev->when ;
1334 event.SetEventObject(this);
1335
1336 GetEventHandler()->ProcessEvent(event);
1337
1338 UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
1339 }
1340
1341 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
1342 {
1343 // updatergn is always already clipped to our boundaries
1344 WindowRef window = GetMacRootWindow() ;
1345 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1346 {
1347 wxMacDrawingClientHelper focus( this ) ;
1348 if ( focus.Ok() )
1349 {
1350 WindowRef window = GetMacRootWindow() ;
1351 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
1352 {
1353 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
1354 }
1355 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1356 {
1357 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1358 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1359 // either a non gray background color or a non control window
1360
1361
1362 wxWindow* parent = GetParent() ;
1363 while( parent )
1364 {
1365 if ( parent->GetMacRootWindow() != window )
1366 {
1367 // we are in a different window on the mac system
1368 parent = NULL ;
1369 break ;
1370 }
1371
1372 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
1373 {
1374 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
1375 {
1376 // if we have any other colours in the hierarchy
1377 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
1378 break ;
1379 }
1380 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1381 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
1382 {
1383 ApplyThemeBackground (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true);
1384 break ;
1385 }
1386 }
1387 else
1388 {
1389 parent = NULL ;
1390 break ;
1391 }
1392 parent = parent->GetParent() ;
1393 }
1394 if ( !parent )
1395 {
1396 // if there is nothing special -> use default
1397 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
1398 }
1399 }
1400 else
1401 {
1402 RGBBackColor( &m_backgroundColour.GetPixel()) ;
1403 }
1404 SetClip( updatergn ) ;
1405 EraseRgn( updatergn ) ;
1406 }
1407 }
1408
1409
1410 m_updateRegion = updatergn ;
1411 wxPaintEvent event;
1412 event.m_timeStamp = time ;
1413 event.SetEventObject(this);
1414
1415 GetEventHandler()->ProcessEvent(event);
1416
1417 RgnHandle childupdate = NewRgn() ;
1418
1419 for (wxNode *node = GetChildren().First(); node; node = node->Next())
1420 {
1421 wxWindow *child = (wxWindow*)node->Data();
1422 int width ;
1423 int height ;
1424
1425 child->GetClientSize( &width , &height ) ;
1426
1427 SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ;
1428 SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ;
1429 OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
1430 if ( child->GetMacRootWindow() == window && child->IsShown() )
1431 {
1432 // because dialogs may also be children
1433 child->MacRedraw( childupdate , time ) ;
1434 }
1435 }
1436 DisposeRgn( childupdate ) ;
1437 // eventually a draw grow box here
1438 }
1439
1440 void wxWindow::MacUpdateImmediately()
1441 {
1442 WindowRef window = GetMacRootWindow() ;
1443 if ( window )
1444 {
1445 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1446 BeginUpdate( window ) ;
1447 if ( win )
1448 {
1449 #if ! TARGET_CARBON
1450 if ( !EmptyRgn( window->visRgn ) )
1451 #endif
1452 {
1453 win->MacRedraw( window->visRgn , wxTheApp->sm_lastMessageTime ) ;
1454 /*
1455 {
1456 wxMacDrawingHelper help( win ) ;
1457 SetOrigin( 0 , 0 ) ;
1458 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1459 UMAUpdateControls( window , window->visRgn ) ;
1460 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1461 }
1462 */
1463 }
1464 }
1465 EndUpdate( window ) ;
1466 }
1467 }
1468
1469 void wxWindow::MacUpdate( EventRecord *ev )
1470 {
1471 WindowRef window = (WindowRef) ev->message ;
1472 wxWindow * win = wxFindWinFromMacWindow( window ) ;
1473
1474 BeginUpdate( window ) ;
1475 if ( win )
1476 {
1477 // if windowshade gives incompatibility , take the follwing out
1478 #if ! TARGET_CARBON
1479 if ( !EmptyRgn( window->visRgn ) )
1480 #endif
1481 {
1482 MacRedraw( window->visRgn , ev->when ) ;
1483 /*
1484 {
1485 wxMacDrawingHelper help( this ) ;
1486 SetOrigin( 0 , 0 ) ;
1487 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1488 UMAUpdateControls( window , window->visRgn ) ;
1489 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1490 }
1491 */
1492 }
1493 }
1494 EndUpdate( window ) ;
1495 }
1496
1497 WindowRef wxWindow::GetMacRootWindow() const
1498 {
1499 WindowRef window = NULL ;
1500 wxWindow *iter = (wxWindow*)this ;
1501
1502 while( iter )
1503 {
1504 if ( iter->m_macWindowData )
1505 return iter->m_macWindowData->m_macWindow ;
1506
1507 iter = iter->GetParent() ;
1508 }
1509 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1510 return NULL ;
1511 }
1512
1513 void wxWindow::MacCreateScrollBars( long style )
1514 {
1515 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ;
1516 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
1517 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
1518
1519 if ( style & wxVSCROLL )
1520 {
1521 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0),
1522 wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL);
1523 // m_vScrollBar->PushEventHandler( this ) ;
1524 }
1525 if ( style & wxHSCROLL )
1526 {
1527 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ),
1528 wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL);
1529 // m_hScrollBar->PushEventHandler( this ) ;
1530 }
1531
1532 // because the create does not take into account the client area origin
1533 MacRepositionScrollBars() ; // we might have a real position shift
1534 }
1535
1536 void wxWindow::MacRepositionScrollBars()
1537 {
1538 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
1539 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
1540
1541 if ( m_vScrollBar )
1542 {
1543 m_vScrollBar->SetSize( m_width-MAC_SCROLLBAR_SIZE, 0, MAC_SCROLLBAR_SIZE, m_height - adjust , wxSIZE_USE_EXISTING);
1544 }
1545 if ( m_hScrollBar )
1546 {
1547 m_hScrollBar->SetSize( 0 , m_height-MAC_SCROLLBAR_SIZE ,m_width - adjust, MAC_SCROLLBAR_SIZE, wxSIZE_USE_EXISTING);
1548 }
1549 }
1550
1551 void wxWindow::MacKeyDown( EventRecord *ev )
1552 {
1553 }
1554
1555
1556
1557
1558 ControlHandle wxWindow::MacGetContainerForEmbedding()
1559 {
1560 if ( m_macWindowData )
1561 return m_macWindowData->m_macRootControl ;
1562 else
1563 return GetParent()->MacGetContainerForEmbedding() ;
1564 }
1565
1566 void wxWindow::MacSuperChangedPosition()
1567 {
1568 // only window-absolute structures have to be moved i.e. controls
1569
1570 wxNode *node = GetChildren().First();
1571 while ( node )
1572 {
1573 wxWindow *child = (wxWindow *)node->Data();
1574 child->MacSuperChangedPosition() ;
1575 node = node->Next();
1576 }
1577 }
1578
1579 bool wxWindow::MacSetupFocusPort( )
1580 {
1581 Point localOrigin ;
1582 Rect clipRect ;
1583 WindowRef window ;
1584 wxWindow *rootwin ;
1585 GrafPtr port ;
1586
1587 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1588 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1589 }
1590
1591 bool wxWindow::MacSetupFocusClientPort( )
1592 {
1593 Point localOrigin ;
1594 Rect clipRect ;
1595 WindowRef window ;
1596 wxWindow *rootwin ;
1597 GrafPtr port ;
1598
1599 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1600 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1601 }
1602
1603 bool wxWindow::MacSetupDrawingPort( )
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 MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1613 }
1614
1615 bool wxWindow::MacSetupDrawingClientPort( )
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 MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1625 }
1626
1627
1628 bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
1629 {
1630 if ( window == NULL )
1631 return false ;
1632
1633 GrafPtr currPort;
1634 GrafPtr port ;
1635
1636 ::GetPort(&currPort);
1637 port = UMAGetWindowPort( window) ;
1638 if (currPort != port )
1639 ::SetPort(port);
1640
1641 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1642 return true;
1643 }
1644
1645 bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win )
1646 {
1647 if ( window == NULL )
1648 return false ;
1649
1650 GrafPtr currPort;
1651 GrafPtr port ;
1652 ::GetPort(&currPort);
1653 port = UMAGetWindowPort( window) ;
1654 if (currPort != port )
1655 ::SetPort(port);
1656
1657 ::SetOrigin(-localOrigin.h, -localOrigin.v);
1658 ::ClipRect(&clipRect);
1659
1660 ::PenNormal() ;
1661 ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
1662 ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
1663 ::BackPat( &qd.white ) ;
1664 ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1665 return true;
1666 }
1667
1668 void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin)
1669 {
1670 if ( m_macWindowData )
1671 {
1672 localOrigin->h = 0;
1673 localOrigin->v = 0;
1674 clipRect->left = 0;
1675 clipRect->top = 0;
1676 clipRect->right = m_width;
1677 clipRect->bottom = m_height;
1678 *window = m_macWindowData->m_macWindow ;
1679 *rootwin = this ;
1680 }
1681 else
1682 {
1683 wxASSERT( GetParent() != NULL ) ;
1684 GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
1685 localOrigin->h += m_x;
1686 localOrigin->v += m_y;
1687 OffsetRect(clipRect, -m_x, -m_y);
1688
1689 Rect myClip;
1690 myClip.left = 0;
1691 myClip.top = 0;
1692 myClip.right = m_width;
1693 myClip.bottom = m_height;
1694 SectRect(clipRect, &myClip, clipRect);
1695 }
1696 }
1697
1698 void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin )
1699 {
1700 int width , height ;
1701 GetClientSize( &width , &height ) ;
1702
1703 if ( m_macWindowData )
1704 {
1705 localOrigin->h = 0;
1706 localOrigin->v = 0;
1707 clipRect->left = 0;
1708 clipRect->top = 0;
1709 clipRect->right = m_width ;//width;
1710 clipRect->bottom = m_height ;// height;
1711 *window = m_macWindowData->m_macWindow ;
1712 *rootwin = this ;
1713 }
1714 else
1715 {
1716 wxASSERT( GetParent() != NULL ) ;
1717
1718 GetParent()->MacGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
1719
1720 localOrigin->h += m_x;
1721 localOrigin->v += m_y;
1722 OffsetRect(clipRect, -m_x, -m_y);
1723
1724 Rect myClip;
1725 myClip.left = 0;
1726 myClip.top = 0;
1727 myClip.right = width;
1728 myClip.bottom = height;
1729 SectRect(clipRect, &myClip, clipRect);
1730 }
1731 }
1732
1733 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
1734 {
1735 m_ok = false ;
1736 Point localOrigin ;
1737 Rect clipRect ;
1738 WindowRef window ;
1739 wxWindow *rootwin ;
1740 m_currentPort = NULL ;
1741 GetPort( &m_formerPort ) ;
1742 if ( theWindow )
1743 {
1744
1745 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1746 m_currentPort = UMAGetWindowPort( window ) ;
1747 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1748 m_ok = true ;
1749 }
1750 }
1751
1752 wxMacFocusHelper::~wxMacFocusHelper()
1753 {
1754 if ( m_ok )
1755 {
1756 SetOrigin( 0 , 0 ) ;
1757 }
1758 if ( m_formerPort != m_currentPort )
1759 SetPort( m_formerPort ) ;
1760 }
1761
1762 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow )
1763 {
1764 m_ok = false ;
1765 Point localOrigin ;
1766 Rect clipRect ;
1767 WindowRef window ;
1768 wxWindow *rootwin ;
1769 m_currentPort = NULL ;
1770
1771 GetPort( &m_formerPort ) ;
1772 if ( theWindow )
1773 {
1774 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
1775 m_currentPort = UMAGetWindowPort( window ) ;
1776 if ( m_formerPort != m_currentPort )
1777 SetPort( m_currentPort ) ;
1778 GetPenState( &m_savedPenState ) ;
1779 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1780 m_ok = true ;
1781 }
1782 }
1783
1784 wxMacDrawingHelper::~wxMacDrawingHelper()
1785 {
1786 if ( m_ok )
1787 {
1788 SetPenState( &m_savedPenState ) ;
1789 SetOrigin( 0 , 0 ) ;
1790 ClipRect( &m_currentPort->portRect ) ;
1791 }
1792
1793 if ( m_formerPort != m_currentPort )
1794 SetPort( m_formerPort ) ;
1795 }
1796
1797 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
1798 {
1799 m_ok = false ;
1800 Point localOrigin ;
1801 Rect clipRect ;
1802 WindowRef window ;
1803 wxWindow *rootwin ;
1804 m_currentPort = NULL ;
1805
1806 GetPort( &m_formerPort ) ;
1807
1808 if ( theWindow )
1809 {
1810 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1811 m_currentPort = UMAGetWindowPort( window ) ;
1812 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
1813 m_ok = true ;
1814 }
1815 }
1816
1817 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1818 {
1819 if ( m_ok )
1820 {
1821 SetOrigin( 0 , 0 ) ;
1822 }
1823 if ( m_formerPort != m_currentPort )
1824 SetPort( m_formerPort ) ;
1825 }
1826
1827 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow )
1828 {
1829 m_ok = false ;
1830 Point localOrigin ;
1831 Rect clipRect ;
1832 WindowRef window ;
1833 wxWindow *rootwin ;
1834 m_currentPort = NULL ;
1835
1836 GetPort( &m_formerPort ) ;
1837
1838 if ( theWindow )
1839 {
1840 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
1841 m_currentPort = UMAGetWindowPort( window ) ;
1842 if ( m_formerPort != m_currentPort )
1843 SetPort( m_currentPort ) ;
1844 GetPenState( &m_savedPenState ) ;
1845 theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
1846 m_ok = true ;
1847 }
1848 }
1849
1850 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1851 {
1852 if ( m_ok )
1853 {
1854 SetPenState( &m_savedPenState ) ;
1855 SetOrigin( 0 , 0 ) ;
1856 ClipRect( &m_currentPort->portRect ) ;
1857 }
1858
1859 if ( m_formerPort != m_currentPort )
1860 SetPort( m_formerPort ) ;
1861 }