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