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