]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindowMac | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
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/window.h" | |
19 | #include "wx/dc.h" | |
20 | #include "wx/dcclient.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/app.h" | |
23 | #include "wx/panel.h" | |
24 | #include "wx/layout.h" | |
25 | #include "wx/dialog.h" | |
26 | #include "wx/listbox.h" | |
27 | #include "wx/scrolbar.h" | |
28 | #include "wx/statbox.h" | |
29 | #include "wx/button.h" | |
30 | #include "wx/settings.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/frame.h" | |
33 | #include "wx/notebook.h" | |
34 | #include "wx/tabctrl.h" | |
35 | #include "wx/tooltip.h" | |
36 | #include "wx/statusbr.h" | |
37 | #include "wx/menuitem.h" | |
38 | #include "wx/spinctrl.h" | |
39 | #include "wx/log.h" | |
40 | #include "wx/geometry.h" | |
41 | ||
42 | #if wxUSE_CARET | |
43 | #include "wx/caret.h" | |
44 | #endif // wxUSE_CARET | |
45 | ||
46 | #define wxWINDOW_HSCROLL 5998 | |
47 | #define wxWINDOW_VSCROLL 5997 | |
48 | #define MAC_SCROLLBAR_SIZE 16 | |
49 | ||
50 | #include "wx/mac/uma.h" | |
51 | #ifndef __DARWIN__ | |
52 | #include <Windows.h> | |
53 | #include <ToolUtils.h> | |
54 | #endif | |
55 | ||
56 | #if wxUSE_DRAG_AND_DROP | |
57 | #include "wx/dnd.h" | |
58 | #endif | |
59 | ||
60 | #include <string.h> | |
61 | ||
62 | extern wxList wxPendingDelete; | |
63 | wxWindowMac* gFocusWindow = NULL ; | |
64 | ||
65 | #ifdef __WXUNIVERSAL__ | |
66 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
67 | #else // __WXMAC__ | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
69 | #endif // __WXUNIVERSAL__/__WXMAC__ | |
70 | ||
71 | #if !USE_SHARED_LIBRARY | |
72 | ||
73 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
74 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) | |
75 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) | |
76 | EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) | |
77 | EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) | |
78 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) | |
79 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) | |
80 | END_EVENT_TABLE() | |
81 | ||
82 | #endif | |
83 | ||
84 | #define wxMAC_DEBUG_REDRAW 0 | |
85 | #ifndef wxMAC_DEBUG_REDRAW | |
86 | #define wxMAC_DEBUG_REDRAW 0 | |
87 | #endif | |
88 | ||
89 | #define wxMAC_USE_THEME_BORDER 0 | |
90 | ||
91 | ||
92 | // =========================================================================== | |
93 | // implementation | |
94 | // =========================================================================== | |
95 | ||
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // constructors and such | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | void wxWindowMac::Init() | |
102 | { | |
103 | m_backgroundTransparent = FALSE; | |
104 | ||
105 | // as all windows are created with WS_VISIBLE style... | |
106 | m_isShown = TRUE; | |
107 | ||
108 | m_x = 0; | |
109 | m_y = 0 ; | |
110 | m_width = 0 ; | |
111 | m_height = 0 ; | |
112 | ||
113 | m_hScrollBar = NULL ; | |
114 | m_vScrollBar = NULL ; | |
115 | } | |
116 | ||
117 | // Destructor | |
118 | wxWindowMac::~wxWindowMac() | |
119 | { | |
120 | SendDestroyEvent(); | |
121 | ||
122 | // deleting a window while it is shown invalidates the region | |
123 | if ( IsShown() ) { | |
124 | wxWindowMac* iter = this ; | |
125 | while( iter ) { | |
126 | if ( iter->IsTopLevel() ) | |
127 | { | |
128 | Refresh() ; | |
129 | break ; | |
130 | } | |
131 | iter = iter->GetParent() ; | |
132 | ||
133 | } | |
134 | } | |
135 | ||
136 | m_isBeingDeleted = TRUE; | |
137 | ||
138 | #ifndef __WXUNIVERSAL__ | |
139 | // VS: make sure there's no wxFrame with last focus set to us: | |
140 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
141 | { | |
142 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
143 | if ( frame ) | |
144 | { | |
145 | if ( frame->GetLastFocus() == this ) | |
146 | { | |
147 | frame->SetLastFocus((wxWindow*)NULL); | |
148 | } | |
149 | break; | |
150 | } | |
151 | } | |
152 | #endif // __WXUNIVERSAL__ | |
153 | ||
154 | if ( s_lastMouseWindow == this ) | |
155 | { | |
156 | s_lastMouseWindow = NULL ; | |
157 | } | |
158 | ||
159 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; | |
160 | if ( frame ) | |
161 | { | |
162 | if ( frame->GetLastFocus() == this ) | |
163 | frame->SetLastFocus( NULL ) ; | |
164 | } | |
165 | ||
166 | if ( gFocusWindow == this ) | |
167 | { | |
168 | gFocusWindow = NULL ; | |
169 | } | |
170 | ||
171 | DestroyChildren(); | |
172 | ||
173 | // delete our drop target if we've got one | |
174 | #if wxUSE_DRAG_AND_DROP | |
175 | if ( m_dropTarget != NULL ) | |
176 | { | |
177 | delete m_dropTarget; | |
178 | m_dropTarget = NULL; | |
179 | } | |
180 | #endif // wxUSE_DRAG_AND_DROP | |
181 | } | |
182 | ||
183 | // Constructor | |
184 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, | |
185 | const wxPoint& pos, | |
186 | const wxSize& size, | |
187 | long style, | |
188 | const wxString& name) | |
189 | { | |
190 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); | |
191 | ||
192 | #if wxUSE_STATBOX | |
193 | // wxGTK doesn't allow to create controls with static box as the parent so | |
194 | // this will result in a crash when the program is ported to wxGTK - warn | |
195 | // about it | |
196 | // | |
197 | // the correct solution is to create the controls as siblings of the | |
198 | // static box | |
199 | wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox), | |
200 | _T("wxStaticBox can't be used as a window parent!") ); | |
201 | #endif // wxUSE_STATBOX | |
202 | ||
203 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
204 | return FALSE; | |
205 | ||
206 | parent->AddChild(this); | |
207 | ||
208 | m_x = (int)pos.x; | |
209 | m_y = (int)pos.y; | |
210 | AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); | |
211 | m_width = WidthDefault( size.x ); | |
212 | m_height = HeightDefault( size.y ) ; | |
213 | #ifndef __WXUNIVERSAL__ | |
214 | // Don't give scrollbars to wxControls unless they ask for them | |
215 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
216 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
217 | { | |
218 | MacCreateScrollBars( style ) ; | |
219 | } | |
220 | #endif | |
221 | ||
222 | wxWindowCreateEvent event(this); | |
223 | GetEventHandler()->ProcessEvent(event); | |
224 | ||
225 | return TRUE; | |
226 | } | |
227 | ||
228 | void wxWindowMac::SetFocus() | |
229 | { | |
230 | if ( gFocusWindow == this ) | |
231 | return ; | |
232 | ||
233 | if ( AcceptsFocus() ) | |
234 | { | |
235 | if (gFocusWindow ) | |
236 | { | |
237 | #if wxUSE_CARET | |
238 | // Deal with caret | |
239 | if ( gFocusWindow->m_caret ) | |
240 | { | |
241 | gFocusWindow->m_caret->OnKillFocus(); | |
242 | } | |
243 | #endif // wxUSE_CARET | |
244 | #ifndef __WXUNIVERSAL__ | |
245 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; | |
246 | if ( control && control->GetMacControl() ) | |
247 | { | |
248 | UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ; | |
249 | control->MacRedrawControl() ; | |
250 | } | |
251 | #endif | |
252 | // Without testing the window id, for some reason | |
253 | // a kill focus event can still be sent to | |
254 | // the control just being focussed. | |
255 | int thisId = this->m_windowId; | |
256 | int gFocusWindowId = gFocusWindow->m_windowId; | |
257 | if (gFocusWindowId != thisId) | |
258 | { | |
259 | wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); | |
260 | event.SetEventObject(gFocusWindow); | |
261 | gFocusWindow->GetEventHandler()->ProcessEvent(event) ; | |
262 | } | |
263 | } | |
264 | gFocusWindow = this ; | |
265 | { | |
266 | #if wxUSE_CARET | |
267 | // Deal with caret | |
268 | if ( m_caret ) | |
269 | { | |
270 | m_caret->OnSetFocus(); | |
271 | } | |
272 | #endif // wxUSE_CARET | |
273 | // panel wants to track the window which was the last to have focus in it | |
274 | wxChildFocusEvent eventFocus(this); | |
275 | GetEventHandler()->ProcessEvent(eventFocus); | |
276 | ||
277 | #ifndef __WXUNIVERSAL__ | |
278 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; | |
279 | if ( control && control->GetMacControl() ) | |
280 | { | |
281 | UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ; | |
282 | } | |
283 | #endif | |
284 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); | |
285 | event.SetEventObject(this); | |
286 | GetEventHandler()->ProcessEvent(event) ; | |
287 | } | |
288 | } | |
289 | } | |
290 | ||
291 | bool wxWindowMac::Enable(bool enable) | |
292 | { | |
293 | if ( !wxWindowBase::Enable(enable) ) | |
294 | return FALSE; | |
295 | ||
296 | MacSuperEnabled( enable ) ; | |
297 | ||
298 | return TRUE; | |
299 | } | |
300 | ||
301 | void wxWindowMac::DoCaptureMouse() | |
302 | { | |
303 | wxTheApp->s_captureWindow = this ; | |
304 | } | |
305 | ||
306 | wxWindow* wxWindowBase::GetCapture() | |
307 | { | |
308 | return wxTheApp->s_captureWindow ; | |
309 | } | |
310 | ||
311 | void wxWindowMac::DoReleaseMouse() | |
312 | { | |
313 | wxTheApp->s_captureWindow = NULL ; | |
314 | } | |
315 | ||
316 | #if wxUSE_DRAG_AND_DROP | |
317 | ||
318 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) | |
319 | { | |
320 | if ( m_dropTarget != 0 ) { | |
321 | delete m_dropTarget; | |
322 | } | |
323 | ||
324 | m_dropTarget = pDropTarget; | |
325 | if ( m_dropTarget != 0 ) | |
326 | { | |
327 | // TODO | |
328 | } | |
329 | } | |
330 | ||
331 | #endif | |
332 | ||
333 | // Old style file-manager drag&drop | |
334 | void wxWindowMac::DragAcceptFiles(bool accept) | |
335 | { | |
336 | // TODO | |
337 | } | |
338 | ||
339 | // Get total size | |
340 | void wxWindowMac::DoGetSize(int *x, int *y) const | |
341 | { | |
342 | if(x) *x = m_width ; | |
343 | if(y) *y = m_height ; | |
344 | } | |
345 | ||
346 | void wxWindowMac::DoGetPosition(int *x, int *y) const | |
347 | { | |
348 | int xx,yy; | |
349 | ||
350 | xx = m_x ; | |
351 | yy = m_y ; | |
352 | if ( !IsTopLevel() && GetParent()) | |
353 | { | |
354 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
355 | xx -= pt.x; | |
356 | yy -= pt.y; | |
357 | } | |
358 | if(x) *x = xx; | |
359 | if(y) *y = yy; | |
360 | } | |
361 | ||
362 | #if wxUSE_MENUS | |
363 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
364 | { | |
365 | menu->SetInvokingWindow(this); | |
366 | menu->UpdateUI(); | |
367 | ClientToScreen( &x , &y ) ; | |
368 | ||
369 | menu->MacBeforeDisplay( true ) ; | |
370 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; | |
371 | if ( HiWord(menuResult) != 0 ) | |
372 | { | |
373 | MenuCommand id ; | |
374 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
375 | wxMenuItem* item = NULL ; | |
376 | wxMenu* realmenu ; | |
377 | item = menu->FindItem(id, &realmenu) ; | |
378 | if (item->IsCheckable()) | |
379 | { | |
380 | item->Check( !item->IsChecked() ) ; | |
381 | } | |
382 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
383 | } | |
384 | menu->MacAfterDisplay( true ) ; | |
385 | ||
386 | menu->SetInvokingWindow(NULL); | |
387 | ||
388 | return TRUE; | |
389 | } | |
390 | #endif | |
391 | ||
392 | void wxWindowMac::DoScreenToClient(int *x, int *y) const | |
393 | { | |
394 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
395 | ||
396 | Point localwhere = {0,0} ; | |
397 | ||
398 | if(x) localwhere.h = * x ; | |
399 | if(y) localwhere.v = * y ; | |
400 | ||
401 | GrafPtr port ; | |
402 | ::GetPort( &port ) ; | |
403 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
404 | ::GlobalToLocal( &localwhere ) ; | |
405 | ::SetPort( port ) ; | |
406 | ||
407 | if(x) *x = localwhere.h ; | |
408 | if(y) *y = localwhere.v ; | |
409 | ||
410 | MacRootWindowToWindow( x , y ) ; | |
411 | if ( x ) | |
412 | *x -= MacGetLeftBorderSize() ; | |
413 | if ( y ) | |
414 | *y -= MacGetTopBorderSize() ; | |
415 | } | |
416 | ||
417 | void wxWindowMac::DoClientToScreen(int *x, int *y) const | |
418 | { | |
419 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
420 | ||
421 | if ( x ) | |
422 | *x += MacGetLeftBorderSize() ; | |
423 | if ( y ) | |
424 | *y += MacGetTopBorderSize() ; | |
425 | ||
426 | MacWindowToRootWindow( x , y ) ; | |
427 | ||
428 | Point localwhere = { 0,0 }; | |
429 | if(x) localwhere.h = * x ; | |
430 | if(y) localwhere.v = * y ; | |
431 | ||
432 | GrafPtr port ; | |
433 | ::GetPort( &port ) ; | |
434 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
435 | ||
436 | ::LocalToGlobal( &localwhere ) ; | |
437 | ::SetPort( port ) ; | |
438 | if(x) *x = localwhere.h ; | |
439 | if(y) *y = localwhere.v ; | |
440 | } | |
441 | ||
442 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const | |
443 | { | |
444 | wxPoint origin = GetClientAreaOrigin() ; | |
445 | if(x) *x += origin.x ; | |
446 | if(y) *y += origin.y ; | |
447 | ||
448 | MacWindowToRootWindow( x , y ) ; | |
449 | } | |
450 | ||
451 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
452 | { | |
453 | wxPoint origin = GetClientAreaOrigin() ; | |
454 | MacRootWindowToWindow( x , y ) ; | |
455 | if(x) *x -= origin.x ; | |
456 | if(y) *y -= origin.y ; | |
457 | } | |
458 | ||
459 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
460 | { | |
461 | if ( !IsTopLevel() ) | |
462 | { | |
463 | if(x) *x += m_x ; | |
464 | if(y) *y += m_y ; | |
465 | GetParent()->MacWindowToRootWindow( x , y ) ; | |
466 | } | |
467 | } | |
468 | ||
469 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const | |
470 | { | |
471 | if ( !IsTopLevel() ) | |
472 | { | |
473 | if(x) *x -= m_x ; | |
474 | if(y) *y -= m_y ; | |
475 | GetParent()->MacRootWindowToWindow( x , y ) ; | |
476 | } | |
477 | } | |
478 | ||
479 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
480 | { | |
481 | if (m_cursor == cursor) | |
482 | return FALSE; | |
483 | ||
484 | if (wxNullCursor == cursor) | |
485 | { | |
486 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
487 | return FALSE ; | |
488 | } | |
489 | else | |
490 | { | |
491 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
492 | return FALSE ; | |
493 | } | |
494 | ||
495 | wxASSERT_MSG( m_cursor.Ok(), | |
496 | wxT("cursor must be valid after call to the base version")); | |
497 | ||
498 | Point pt ; | |
499 | wxWindowMac *mouseWin ; | |
500 | GetMouse( &pt ) ; | |
501 | ||
502 | // Change the cursor NOW if we're within the correct window | |
503 | ||
504 | if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) | |
505 | { | |
506 | if ( mouseWin == this && !wxIsBusy() ) | |
507 | { | |
508 | m_cursor.MacInstall() ; | |
509 | } | |
510 | } | |
511 | ||
512 | return TRUE ; | |
513 | } | |
514 | ||
515 | ||
516 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
517 | void wxWindowMac::DoGetClientSize(int *x, int *y) const | |
518 | { | |
519 | int ww, hh; | |
520 | ww = m_width ; | |
521 | hh = m_height ; | |
522 | ||
523 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; | |
524 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
525 | ||
526 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) | |
527 | { | |
528 | int x1 = 0 ; | |
529 | int y1 = 0 ; | |
530 | int w = m_width ; | |
531 | int h = m_height ; | |
532 | ||
533 | MacClientToRootWindow( &x1 , &y1 ) ; | |
534 | MacClientToRootWindow( &w , &h ) ; | |
535 | ||
536 | wxWindowMac *iter = (wxWindowMac*)this ; | |
537 | ||
538 | int totW = 10000 , totH = 10000; | |
539 | while( iter ) | |
540 | { | |
541 | if ( iter->IsTopLevel() ) | |
542 | { | |
543 | totW = iter->m_width ; | |
544 | totH = iter->m_height ; | |
545 | break ; | |
546 | } | |
547 | ||
548 | iter = iter->GetParent() ; | |
549 | } | |
550 | ||
551 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
552 | { | |
553 | hh -= MAC_SCROLLBAR_SIZE; | |
554 | if ( h-y1 >= totH ) | |
555 | { | |
556 | hh += 1 ; | |
557 | } | |
558 | } | |
559 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
560 | { | |
561 | ww -= MAC_SCROLLBAR_SIZE; | |
562 | if ( w-x1 >= totW ) | |
563 | { | |
564 | ww += 1 ; | |
565 | } | |
566 | } | |
567 | } | |
568 | if(x) *x = ww; | |
569 | if(y) *y = hh; | |
570 | } | |
571 | ||
572 | ||
573 | // ---------------------------------------------------------------------------- | |
574 | // tooltips | |
575 | // ---------------------------------------------------------------------------- | |
576 | ||
577 | #if wxUSE_TOOLTIPS | |
578 | ||
579 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) | |
580 | { | |
581 | wxWindowBase::DoSetToolTip(tooltip); | |
582 | ||
583 | if ( m_tooltip ) | |
584 | m_tooltip->SetWindow(this); | |
585 | } | |
586 | ||
587 | #endif // wxUSE_TOOLTIPS | |
588 | ||
589 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
590 | { | |
591 | int former_x = m_x ; | |
592 | int former_y = m_y ; | |
593 | int former_w = m_width ; | |
594 | int former_h = m_height ; | |
595 | ||
596 | int actualWidth = width; | |
597 | int actualHeight = height; | |
598 | int actualX = x; | |
599 | int actualY = y; | |
600 | ||
601 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
602 | actualWidth = m_minWidth; | |
603 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
604 | actualHeight = m_minHeight; | |
605 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
606 | actualWidth = m_maxWidth; | |
607 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
608 | actualHeight = m_maxHeight; | |
609 | ||
610 | bool doMove = false ; | |
611 | bool doResize = false ; | |
612 | ||
613 | if ( actualX != former_x || actualY != former_y ) | |
614 | { | |
615 | doMove = true ; | |
616 | } | |
617 | if ( actualWidth != former_w || actualHeight != former_h ) | |
618 | { | |
619 | doResize = true ; | |
620 | } | |
621 | ||
622 | if ( doMove || doResize ) | |
623 | { | |
624 | // erase former position | |
625 | ||
626 | bool partialRepaint = false ; | |
627 | ||
628 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) | |
629 | { | |
630 | wxPoint oldPos( m_x , m_y ) ; | |
631 | wxPoint newPos( actualX , actualY ) ; | |
632 | MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ; | |
633 | MacWindowToRootWindow( &newPos.x , &newPos.y ) ; | |
634 | if ( oldPos == newPos ) | |
635 | { | |
636 | partialRepaint = true ; | |
637 | RgnHandle oldRgn,newRgn,diffRgn ; | |
638 | oldRgn = NewRgn() ; | |
639 | newRgn = NewRgn() ; | |
640 | diffRgn = NewRgn() ; | |
641 | SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ; | |
642 | SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ; | |
643 | DiffRgn( newRgn , oldRgn , diffRgn ) ; | |
644 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; | |
645 | DiffRgn( oldRgn , newRgn , diffRgn ) ; | |
646 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; | |
647 | DisposeRgn(oldRgn) ; | |
648 | DisposeRgn(newRgn) ; | |
649 | DisposeRgn(diffRgn) ; | |
650 | } | |
651 | } | |
652 | ||
653 | if ( !partialRepaint ) | |
654 | Refresh() ; | |
655 | ||
656 | m_x = actualX ; | |
657 | m_y = actualY ; | |
658 | m_width = actualWidth ; | |
659 | m_height = actualHeight ; | |
660 | ||
661 | // update any low-level frame-relative positions | |
662 | ||
663 | MacUpdateDimensions() ; | |
664 | // erase new position | |
665 | ||
666 | if ( !partialRepaint ) | |
667 | Refresh() ; | |
668 | if ( doMove ) | |
669 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
670 | ||
671 | MacRepositionScrollBars() ; | |
672 | if ( doMove ) | |
673 | { | |
674 | wxPoint point(m_x, m_y); | |
675 | wxMoveEvent event(point, m_windowId); | |
676 | event.SetEventObject(this); | |
677 | GetEventHandler()->ProcessEvent(event) ; | |
678 | } | |
679 | if ( doResize ) | |
680 | { | |
681 | MacRepositionScrollBars() ; | |
682 | wxSize size(m_width, m_height); | |
683 | wxSizeEvent event(size, m_windowId); | |
684 | event.SetEventObject(this); | |
685 | GetEventHandler()->ProcessEvent(event); | |
686 | } | |
687 | } | |
688 | ||
689 | } | |
690 | ||
691 | // set the size of the window: if the dimensions are positive, just use them, | |
692 | // but if any of them is equal to -1, it means that we must find the value for | |
693 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
694 | // which case -1 is a valid value for x and y) | |
695 | // | |
696 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
697 | // the width/height to best suit our contents, otherwise we reuse the current | |
698 | // width/height | |
699 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
700 | { | |
701 | // get the current size and position... | |
702 | int currentX, currentY; | |
703 | GetPosition(¤tX, ¤tY); | |
704 | ||
705 | int currentW,currentH; | |
706 | GetSize(¤tW, ¤tH); | |
707 | ||
708 | // ... and don't do anything (avoiding flicker) if it's already ok | |
709 | if ( x == currentX && y == currentY && | |
710 | width == currentW && height == currentH ) | |
711 | { | |
712 | MacRepositionScrollBars() ; // we might have a real position shift | |
713 | return; | |
714 | } | |
715 | ||
716 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
717 | x = currentX; | |
718 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
719 | y = currentY; | |
720 | ||
721 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
722 | ||
723 | wxSize size(-1, -1); | |
724 | if ( width == -1 ) | |
725 | { | |
726 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
727 | { | |
728 | size = DoGetBestSize(); | |
729 | width = size.x; | |
730 | } | |
731 | else | |
732 | { | |
733 | // just take the current one | |
734 | width = currentW; | |
735 | } | |
736 | } | |
737 | ||
738 | if ( height == -1 ) | |
739 | { | |
740 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
741 | { | |
742 | if ( size.x == -1 ) | |
743 | { | |
744 | size = DoGetBestSize(); | |
745 | } | |
746 | //else: already called DoGetBestSize() above | |
747 | ||
748 | height = size.y; | |
749 | } | |
750 | else | |
751 | { | |
752 | // just take the current one | |
753 | height = currentH; | |
754 | } | |
755 | } | |
756 | ||
757 | DoMoveWindow(x, y, width, height); | |
758 | ||
759 | } | |
760 | // For implementation purposes - sometimes decorations make the client area | |
761 | // smaller | |
762 | ||
763 | wxPoint wxWindowMac::GetClientAreaOrigin() const | |
764 | { | |
765 | return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); | |
766 | } | |
767 | ||
768 | void wxWindowMac::SetTitle(const wxString& title) | |
769 | { | |
770 | m_label = title ; | |
771 | } | |
772 | ||
773 | wxString wxWindowMac::GetTitle() const | |
774 | { | |
775 | return m_label ; | |
776 | } | |
777 | ||
778 | bool wxWindowMac::Show(bool show) | |
779 | { | |
780 | if ( !wxWindowBase::Show(show) ) | |
781 | return FALSE; | |
782 | ||
783 | MacSuperShown( show ) ; | |
784 | Refresh() ; | |
785 | ||
786 | return TRUE; | |
787 | } | |
788 | ||
789 | void wxWindowMac::MacSuperShown( bool show ) | |
790 | { | |
791 | wxWindowListNode *node = GetChildren().GetFirst(); | |
792 | while ( node ) | |
793 | { | |
794 | wxWindowMac *child = node->GetData(); | |
795 | if ( child->m_isShown ) | |
796 | child->MacSuperShown( show ) ; | |
797 | node = node->GetNext(); | |
798 | } | |
799 | } | |
800 | ||
801 | void wxWindowMac::MacSuperEnabled( bool enabled ) | |
802 | { | |
803 | if ( !IsTopLevel() ) | |
804 | { | |
805 | // to be absolutely correct we'd have to invalidate (with eraseBkground | |
806 | // because unter MacOSX the frames are drawn with an addXXX mode) | |
807 | // the borders area | |
808 | } | |
809 | wxWindowListNode *node = GetChildren().GetFirst(); | |
810 | while ( node ) | |
811 | { | |
812 | wxWindowMac *child = (wxWindowMac *)node->GetData(); | |
813 | if ( child->m_isShown ) | |
814 | child->MacSuperEnabled( enabled ) ; | |
815 | node = node->GetNext(); | |
816 | } | |
817 | } | |
818 | ||
819 | bool wxWindowMac::MacIsReallyShown() const | |
820 | { | |
821 | if ( m_isShown && (m_parent != NULL) ) { | |
822 | return m_parent->MacIsReallyShown(); | |
823 | } | |
824 | return m_isShown; | |
825 | /* | |
826 | bool status = m_isShown ; | |
827 | wxWindowMac * win = this ; | |
828 | while ( status && win->m_parent != NULL ) | |
829 | { | |
830 | win = win->m_parent ; | |
831 | status = win->m_isShown ; | |
832 | } | |
833 | return status ; | |
834 | */ | |
835 | } | |
836 | ||
837 | int wxWindowMac::GetCharHeight() const | |
838 | { | |
839 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
840 | return dc.GetCharHeight() ; | |
841 | } | |
842 | ||
843 | int wxWindowMac::GetCharWidth() const | |
844 | { | |
845 | wxClientDC dc ( (wxWindowMac*)this ) ; | |
846 | return dc.GetCharWidth() ; | |
847 | } | |
848 | ||
849 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, | |
850 | int *descent, int *externalLeading, const wxFont *theFont ) const | |
851 | { | |
852 | const wxFont *fontToUse = theFont; | |
853 | if ( !fontToUse ) | |
854 | fontToUse = &m_font; | |
855 | ||
856 | wxClientDC dc( (wxWindowMac*) this ) ; | |
857 | long lx,ly,ld,le ; | |
858 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; | |
859 | if ( externalLeading ) | |
860 | *externalLeading = le ; | |
861 | if ( descent ) | |
862 | *descent = ld ; | |
863 | if ( x ) | |
864 | *x = lx ; | |
865 | if ( y ) | |
866 | *y = ly ; | |
867 | } | |
868 | ||
869 | /* | |
870 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect | |
871 | * we always intersect with the entire window, not only with the client area | |
872 | */ | |
873 | ||
874 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) | |
875 | { | |
876 | if ( MacGetTopLevelWindow() == NULL ) | |
877 | return ; | |
878 | ||
879 | if ( !MacIsReallyShown() ) | |
880 | return ; | |
881 | ||
882 | wxPoint client = GetClientAreaOrigin(); | |
883 | int x1 = -client.x; | |
884 | int y1 = -client.y; | |
885 | int x2 = m_width - client.x; | |
886 | int y2 = m_height - client.y; | |
887 | ||
888 | if (IsKindOf( CLASSINFO(wxButton))) | |
889 | { | |
890 | // buttons have an "aura" | |
891 | y1 -= 5; | |
892 | x1 -= 5; | |
893 | y2 += 5; | |
894 | x2 += 5; | |
895 | } | |
896 | ||
897 | Rect clientrect = { y1, x1, y2, x2 }; | |
898 | ||
899 | if ( rect ) | |
900 | { | |
901 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
902 | SectRect( &clientrect , &r , &clientrect ) ; | |
903 | } | |
904 | ||
905 | if ( !EmptyRect( &clientrect ) ) | |
906 | { | |
907 | int top = 0 , left = 0 ; | |
908 | ||
909 | MacClientToRootWindow( &left , &top ) ; | |
910 | OffsetRect( &clientrect , left , top ) ; | |
911 | ||
912 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; | |
913 | } | |
914 | } | |
915 | ||
916 | wxWindowMac *wxGetActiveWindow() | |
917 | { | |
918 | // actually this is a windows-only concept | |
919 | return NULL; | |
920 | } | |
921 | ||
922 | // Coordinates relative to the window | |
923 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) | |
924 | { | |
925 | // We really don't move the mouse programmatically under Mac. | |
926 | } | |
927 | ||
928 | const wxBrush& wxWindowMac::MacGetBackgroundBrush() | |
929 | { | |
930 | if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
931 | { | |
932 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ; | |
933 | } | |
934 | else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
935 | { | |
936 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
937 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
938 | // either a non gray background color or a non control window | |
939 | ||
940 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
941 | ||
942 | wxWindowMac* parent = GetParent() ; | |
943 | while( parent ) | |
944 | { | |
945 | if ( parent->MacGetRootWindow() != window ) | |
946 | { | |
947 | // we are in a different window on the mac system | |
948 | parent = NULL ; | |
949 | break ; | |
950 | } | |
951 | ||
952 | { | |
953 | if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) | |
954 | && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
955 | { | |
956 | // if we have any other colours in the hierarchy | |
957 | m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ; | |
958 | break ; | |
959 | } | |
960 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
961 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
962 | { | |
963 | Rect extent = { 0 , 0 , 0 , 0 } ; | |
964 | int x , y ; | |
965 | x = y = 0 ; | |
966 | wxSize size = parent->GetSize() ; | |
967 | parent->MacClientToRootWindow( &x , &y ) ; | |
968 | extent.left = x ; | |
969 | extent.top = y ; | |
970 | extent.top-- ; | |
971 | extent.right = x + size.x ; | |
972 | extent.bottom = y + size.y ; | |
973 | m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive | |
974 | break ; | |
975 | } | |
976 | } | |
977 | parent = parent->GetParent() ; | |
978 | } | |
979 | if ( !parent ) | |
980 | { | |
981 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive | |
982 | } | |
983 | } | |
984 | else | |
985 | { | |
986 | m_macBackgroundBrush.SetColour( m_backgroundColour ) ; | |
987 | } | |
988 | ||
989 | return m_macBackgroundBrush ; | |
990 | } | |
991 | ||
992 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
993 | { | |
994 | event.GetDC()->Clear() ; | |
995 | } | |
996 | ||
997 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
998 | { | |
999 | wxWindowDC dc(this) ; | |
1000 | wxMacPortSetter helper(&dc) ; | |
1001 | ||
1002 | MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ; | |
1003 | } | |
1004 | ||
1005 | int wxWindowMac::GetScrollPos(int orient) const | |
1006 | { | |
1007 | if ( orient == wxHORIZONTAL ) | |
1008 | { | |
1009 | if ( m_hScrollBar ) | |
1010 | return m_hScrollBar->GetThumbPosition() ; | |
1011 | } | |
1012 | else | |
1013 | { | |
1014 | if ( m_vScrollBar ) | |
1015 | return m_vScrollBar->GetThumbPosition() ; | |
1016 | } | |
1017 | return 0; | |
1018 | } | |
1019 | ||
1020 | // This now returns the whole range, not just the number | |
1021 | // of positions that we can scroll. | |
1022 | int wxWindowMac::GetScrollRange(int orient) const | |
1023 | { | |
1024 | if ( orient == wxHORIZONTAL ) | |
1025 | { | |
1026 | if ( m_hScrollBar ) | |
1027 | return m_hScrollBar->GetRange() ; | |
1028 | } | |
1029 | else | |
1030 | { | |
1031 | if ( m_vScrollBar ) | |
1032 | return m_vScrollBar->GetRange() ; | |
1033 | } | |
1034 | return 0; | |
1035 | } | |
1036 | ||
1037 | int wxWindowMac::GetScrollThumb(int orient) const | |
1038 | { | |
1039 | if ( orient == wxHORIZONTAL ) | |
1040 | { | |
1041 | if ( m_hScrollBar ) | |
1042 | return m_hScrollBar->GetThumbSize() ; | |
1043 | } | |
1044 | else | |
1045 | { | |
1046 | if ( m_vScrollBar ) | |
1047 | return m_vScrollBar->GetThumbSize() ; | |
1048 | } | |
1049 | return 0; | |
1050 | } | |
1051 | ||
1052 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) | |
1053 | { | |
1054 | if ( orient == wxHORIZONTAL ) | |
1055 | { | |
1056 | if ( m_hScrollBar ) | |
1057 | m_hScrollBar->SetThumbPosition( pos ) ; | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | if ( m_vScrollBar ) | |
1062 | m_vScrollBar->SetThumbPosition( pos ) ; | |
1063 | } | |
1064 | } | |
1065 | ||
1066 | void wxWindowMac::MacPaintBorders( int left , int top ) | |
1067 | { | |
1068 | if( IsTopLevel() ) | |
1069 | return ; | |
1070 | ||
1071 | int major,minor; | |
1072 | wxGetOsVersion( &major, &minor ); | |
1073 | ||
1074 | RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; | |
1075 | RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; | |
1076 | ||
1077 | RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ; | |
1078 | RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ; | |
1079 | // OS X has lighter border edges than classic: | |
1080 | if (major >= 10) | |
1081 | { | |
1082 | darkShadow.red = 0x8E8E; | |
1083 | darkShadow.green = 0x8E8E; | |
1084 | darkShadow.blue = 0x8E8E; | |
1085 | lightShadow.red = 0xBDBD; | |
1086 | lightShadow.green = 0xBDBD; | |
1087 | lightShadow.blue = 0xBDBD; | |
1088 | } | |
1089 | ||
1090 | PenNormal() ; | |
1091 | ||
1092 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1093 | { | |
1094 | #if wxMAC_USE_THEME_BORDER | |
1095 | Rect rect = { top , left , m_height + top , m_width + left } ; | |
1096 | SInt32 border = 0 ; | |
1097 | /* | |
1098 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1099 | InsetRect( &rect , border , border ); | |
1100 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
1101 | */ | |
1102 | ||
1103 | DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
1104 | #else | |
1105 | bool sunken = HasFlag( wxSUNKEN_BORDER ) ; | |
1106 | RGBForeColor( &face ); | |
1107 | MoveTo( left + 0 , top + m_height - 2 ); | |
1108 | LineTo( left + 0 , top + 0 ); | |
1109 | LineTo( left + m_width - 2 , top + 0 ); | |
1110 | ||
1111 | MoveTo( left + 2 , top + m_height - 3 ); | |
1112 | LineTo( left + m_width - 3 , top + m_height - 3 ); | |
1113 | LineTo( left + m_width - 3 , top + 2 ); | |
1114 | ||
1115 | RGBForeColor( sunken ? &face : &darkShadow ); | |
1116 | MoveTo( left + 0 , top + m_height - 1 ); | |
1117 | LineTo( left + m_width - 1 , top + m_height - 1 ); | |
1118 | LineTo( left + m_width - 1 , top + 0 ); | |
1119 | ||
1120 | RGBForeColor( sunken ? &lightShadow : &white ); | |
1121 | MoveTo( left + 1 , top + m_height - 3 ); | |
1122 | LineTo( left + 1, top + 1 ); | |
1123 | LineTo( left + m_width - 3 , top + 1 ); | |
1124 | ||
1125 | RGBForeColor( sunken ? &white : &lightShadow ); | |
1126 | MoveTo( left + 1 , top + m_height - 2 ); | |
1127 | LineTo( left + m_width - 2 , top + m_height - 2 ); | |
1128 | LineTo( left + m_width - 2 , top + 1 ); | |
1129 | ||
1130 | RGBForeColor( sunken ? &darkShadow : &face ); | |
1131 | MoveTo( left + 2 , top + m_height - 4 ); | |
1132 | LineTo( left + 2 , top + 2 ); | |
1133 | LineTo( left + m_width - 4 , top + 2 ); | |
1134 | #endif | |
1135 | } | |
1136 | else if (HasFlag(wxSIMPLE_BORDER)) | |
1137 | { | |
1138 | Rect rect = { top , left , m_height + top , m_width + left } ; | |
1139 | RGBForeColor( &darkShadow ) ; | |
1140 | FrameRect( &rect ) ; | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | void wxWindowMac::RemoveChild( wxWindowBase *child ) | |
1145 | { | |
1146 | if ( child == m_hScrollBar ) | |
1147 | m_hScrollBar = NULL ; | |
1148 | if ( child == m_vScrollBar ) | |
1149 | m_vScrollBar = NULL ; | |
1150 | ||
1151 | wxWindowBase::RemoveChild( child ) ; | |
1152 | } | |
1153 | ||
1154 | // New function that will replace some of the above. | |
1155 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, | |
1156 | int range, bool refresh) | |
1157 | { | |
1158 | if ( orient == wxHORIZONTAL ) | |
1159 | { | |
1160 | if ( m_hScrollBar ) | |
1161 | { | |
1162 | if ( range == 0 || thumbVisible >= range ) | |
1163 | { | |
1164 | if ( m_hScrollBar->IsShown() ) | |
1165 | m_hScrollBar->Show(false) ; | |
1166 | } | |
1167 | else | |
1168 | { | |
1169 | if ( !m_hScrollBar->IsShown() ) | |
1170 | m_hScrollBar->Show(true) ; | |
1171 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1172 | } | |
1173 | } | |
1174 | } | |
1175 | else | |
1176 | { | |
1177 | if ( m_vScrollBar ) | |
1178 | { | |
1179 | if ( range == 0 || thumbVisible >= range ) | |
1180 | { | |
1181 | if ( m_vScrollBar->IsShown() ) | |
1182 | m_vScrollBar->Show(false) ; | |
1183 | } | |
1184 | else | |
1185 | { | |
1186 | if ( !m_vScrollBar->IsShown() ) | |
1187 | m_vScrollBar->Show(true) ; | |
1188 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1189 | } | |
1190 | } | |
1191 | } | |
1192 | MacRepositionScrollBars() ; | |
1193 | } | |
1194 | ||
1195 | // Does a physical scroll | |
1196 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) | |
1197 | { | |
1198 | if( dx == 0 && dy ==0 ) | |
1199 | return ; | |
1200 | ||
1201 | ||
1202 | { | |
1203 | wxClientDC dc(this) ; | |
1204 | wxMacPortSetter helper(&dc) ; | |
1205 | ||
1206 | int width , height ; | |
1207 | GetClientSize( &width , &height ) ; | |
1208 | ||
1209 | Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ; | |
1210 | RgnHandle updateRgn = NewRgn() ; | |
1211 | ClipRect( &scrollrect ) ; | |
1212 | if ( rect ) | |
1213 | { | |
1214 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , | |
1215 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
1216 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
1217 | } | |
1218 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
1219 | // we also have to scroll the update rgn in this rectangle | |
1220 | // in order not to loose updates | |
1221 | WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; | |
1222 | RgnHandle formerUpdateRgn = NewRgn() ; | |
1223 | RgnHandle scrollRgn = NewRgn() ; | |
1224 | RectRgn( scrollRgn , &scrollrect ) ; | |
1225 | GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ; | |
1226 | Point pt = {0,0} ; | |
1227 | LocalToGlobal( &pt ) ; | |
1228 | OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ; | |
1229 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
1230 | if ( !EmptyRgn( formerUpdateRgn ) ) | |
1231 | { | |
1232 | MacOffsetRgn( formerUpdateRgn , dx , dy ) ; | |
1233 | SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ; | |
1234 | InvalWindowRgn(rootWindow , formerUpdateRgn ) ; | |
1235 | } | |
1236 | InvalWindowRgn(rootWindow , updateRgn ) ; | |
1237 | DisposeRgn( updateRgn ) ; | |
1238 | DisposeRgn( formerUpdateRgn ) ; | |
1239 | DisposeRgn( scrollRgn ) ; | |
1240 | } | |
1241 | ||
1242 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1243 | { | |
1244 | wxWindowMac *child = node->GetData(); | |
1245 | if (child == m_vScrollBar) continue; | |
1246 | if (child == m_hScrollBar) continue; | |
1247 | if (child->IsTopLevel()) continue; | |
1248 | ||
1249 | int x,y; | |
1250 | child->GetPosition( &x, &y ); | |
1251 | int w,h; | |
1252 | child->GetSize( &w, &h ); | |
1253 | child->SetSize( x+dx, y+dy, w, h ); | |
1254 | } | |
1255 | ||
1256 | Update() ; | |
1257 | ||
1258 | } | |
1259 | ||
1260 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) | |
1261 | { | |
1262 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) | |
1263 | { | |
1264 | wxScrollWinEvent wevent; | |
1265 | wevent.SetPosition(event.GetPosition()); | |
1266 | wevent.SetOrientation(event.GetOrientation()); | |
1267 | wevent.m_eventObject = this; | |
1268 | ||
1269 | if (event.m_eventType == wxEVT_SCROLL_TOP) | |
1270 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
1271 | else if (event.m_eventType == wxEVT_SCROLL_BOTTOM) | |
1272 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1273 | else if (event.m_eventType == wxEVT_SCROLL_LINEUP) | |
1274 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1275 | else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) | |
1276 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1277 | else if (event.m_eventType == wxEVT_SCROLL_PAGEUP) | |
1278 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1279 | else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) | |
1280 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1281 | else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) | |
1282 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1283 | else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE) | |
1284 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE; | |
1285 | ||
1286 | GetEventHandler()->ProcessEvent(wevent); | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | // Get the window with the focus | |
1291 | wxWindowMac *wxWindowBase::FindFocus() | |
1292 | { | |
1293 | return gFocusWindow ; | |
1294 | } | |
1295 | ||
1296 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) | |
1297 | { | |
1298 | // panel wants to track the window which was the last to have focus in it, | |
1299 | // so we want to set ourselves as the window which last had focus | |
1300 | // | |
1301 | // notice that it's also important to do it upwards the tree becaus | |
1302 | // otherwise when the top level panel gets focus, it won't set it back to | |
1303 | // us, but to some other sibling | |
1304 | ||
1305 | // CS:don't know if this is still needed: | |
1306 | //wxChildFocusEvent eventFocus(this); | |
1307 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
1308 | ||
1309 | event.Skip(); | |
1310 | } | |
1311 | ||
1312 | // Setup background and foreground colours correctly | |
1313 | void wxWindowMac::SetupColours() | |
1314 | { | |
1315 | if ( GetParent() ) | |
1316 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
1317 | } | |
1318 | ||
1319 | void wxWindowMac::OnInternalIdle() | |
1320 | { | |
1321 | // This calls the UI-update mechanism (querying windows for | |
1322 | // menu/toolbar/control state information) | |
1323 | if (wxUpdateUIEvent::CanUpdate(this)) | |
1324 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
1325 | } | |
1326 | ||
1327 | // Raise the window to the top of the Z order | |
1328 | void wxWindowMac::Raise() | |
1329 | { | |
1330 | } | |
1331 | ||
1332 | // Lower the window to the bottom of the Z order | |
1333 | void wxWindowMac::Lower() | |
1334 | { | |
1335 | } | |
1336 | ||
1337 | void wxWindowMac::DoSetClientSize(int width, int height) | |
1338 | { | |
1339 | if ( width != -1 || height != -1 ) | |
1340 | { | |
1341 | ||
1342 | if ( width != -1 && m_vScrollBar ) | |
1343 | width += MAC_SCROLLBAR_SIZE ; | |
1344 | if ( height != -1 && m_vScrollBar ) | |
1345 | height += MAC_SCROLLBAR_SIZE ; | |
1346 | ||
1347 | width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; | |
1348 | height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
1349 | ||
1350 | DoSetSize( -1 , -1 , width , height ) ; | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | ||
1355 | wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; | |
1356 | ||
1357 | bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) | |
1358 | { | |
1359 | if ( IsTopLevel() ) | |
1360 | { | |
1361 | if ((point.x < 0) || (point.y < 0) || | |
1362 | (point.x > (m_width)) || (point.y > (m_height))) | |
1363 | return FALSE; | |
1364 | } | |
1365 | else | |
1366 | { | |
1367 | if ((point.x < m_x) || (point.y < m_y) || | |
1368 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1369 | return FALSE; | |
1370 | } | |
1371 | ||
1372 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
1373 | ||
1374 | wxPoint newPoint( point ) ; | |
1375 | ||
1376 | if ( !IsTopLevel() ) | |
1377 | { | |
1378 | newPoint.x -= m_x; | |
1379 | newPoint.y -= m_y; | |
1380 | } | |
1381 | ||
1382 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1383 | { | |
1384 | wxWindowMac *child = node->GetData(); | |
1385 | // added the m_isShown test --dmazzoni | |
1386 | if ( child->MacGetRootWindow() == window && child->m_isShown ) | |
1387 | { | |
1388 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1389 | return TRUE; | |
1390 | } | |
1391 | } | |
1392 | ||
1393 | *outWin = this ; | |
1394 | return TRUE; | |
1395 | } | |
1396 | ||
1397 | bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) | |
1398 | { | |
1399 | WindowRef window ; | |
1400 | ||
1401 | Point pt = { screenpoint.y , screenpoint.x } ; | |
1402 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1403 | { | |
1404 | ||
1405 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1406 | if ( win ) | |
1407 | { | |
1408 | // No, this yields the CLIENT are, we need the whole frame. RR. | |
1409 | // point = win->ScreenToClient( point ) ; | |
1410 | ||
1411 | GrafPtr port; | |
1412 | ::GetPort( &port ) ; | |
1413 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
1414 | ::GlobalToLocal( &pt ) ; | |
1415 | ::SetPort( port ) ; | |
1416 | ||
1417 | wxPoint point( pt.h, pt.v ) ; | |
1418 | ||
1419 | return win->MacGetWindowFromPointSub( point , outWin ) ; | |
1420 | } | |
1421 | } | |
1422 | return FALSE ; | |
1423 | } | |
1424 | ||
1425 | static wxWindow *gs_lastWhich = NULL; | |
1426 | ||
1427 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) | |
1428 | { | |
1429 | // first trigger a set cursor event | |
1430 | ||
1431 | wxPoint clientorigin = GetClientAreaOrigin() ; | |
1432 | wxSize clientsize = GetClientSize() ; | |
1433 | wxCursor cursor ; | |
1434 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
1435 | { | |
1436 | wxSetCursorEvent event( pt.x , pt.y ); | |
1437 | ||
1438 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); | |
1439 | if ( processedEvtSetCursor && event.HasCursor() ) | |
1440 | { | |
1441 | cursor = event.GetCursor() ; | |
1442 | } | |
1443 | else | |
1444 | { | |
1445 | ||
1446 | // the test for processedEvtSetCursor is here to prevent using m_cursor | |
1447 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
1448 | // it - this is a way to say that our cursor shouldn't be used for this | |
1449 | // point | |
1450 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
1451 | { | |
1452 | cursor = m_cursor ; | |
1453 | } | |
1454 | if ( wxIsBusy() ) | |
1455 | { | |
1456 | } | |
1457 | else | |
1458 | { | |
1459 | if ( !GetParent() ) | |
1460 | cursor = *wxSTANDARD_CURSOR ; | |
1461 | } | |
1462 | } | |
1463 | if ( cursor.Ok() ) | |
1464 | cursor.MacInstall() ; | |
1465 | } | |
1466 | return cursor.Ok() ; | |
1467 | } | |
1468 | ||
1469 | bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) | |
1470 | { | |
1471 | //In case a third-party component changed the port... | |
1472 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) MacGetRootWindow()) ) ; | |
1473 | wxMacWindowClipper clip (this); | |
1474 | ||
1475 | if ((event.m_x < m_x) || (event.m_y < m_y) || | |
1476 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1477 | return FALSE; | |
1478 | ||
1479 | ||
1480 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) | |
1481 | return FALSE ; | |
1482 | ||
1483 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
1484 | ||
1485 | event.m_x -= m_x; | |
1486 | event.m_y -= m_y; | |
1487 | ||
1488 | int x = event.m_x ; | |
1489 | int y = event.m_y ; | |
1490 | ||
1491 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1492 | { | |
1493 | wxWindowMac *child = node->GetData(); | |
1494 | if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() ) | |
1495 | { | |
1496 | if (child->MacDispatchMouseEvent(event)) | |
1497 | return TRUE; | |
1498 | } | |
1499 | } | |
1500 | ||
1501 | wxWindow* cursorTarget = this ; | |
1502 | wxPoint cursorPoint( x , y ) ; | |
1503 | ||
1504 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
1505 | { | |
1506 | cursorTarget = cursorTarget->GetParent() ; | |
1507 | if ( cursorTarget ) | |
1508 | cursorPoint += cursorTarget->GetPosition() ; | |
1509 | } | |
1510 | event.m_x = x ; | |
1511 | event.m_y = y ; | |
1512 | event.SetEventObject( this ) ; | |
1513 | ||
1514 | if ( event.GetEventType() == wxEVT_LEFT_DOWN ) | |
1515 | { | |
1516 | // set focus to this window | |
1517 | if (AcceptsFocus() && FindFocus()!=this) | |
1518 | SetFocus(); | |
1519 | } | |
1520 | ||
1521 | #if wxUSE_TOOLTIPS | |
1522 | if ( event.GetEventType() == wxEVT_MOTION | |
1523 | || event.GetEventType() == wxEVT_ENTER_WINDOW | |
1524 | || event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
1525 | wxToolTip::RelayEvent( this , event); | |
1526 | #endif // wxUSE_TOOLTIPS | |
1527 | ||
1528 | if (gs_lastWhich != this) | |
1529 | { | |
1530 | gs_lastWhich = this; | |
1531 | ||
1532 | // Double clicks must always occur on the same window | |
1533 | if (event.GetEventType() == wxEVT_LEFT_DCLICK) | |
1534 | event.SetEventType( wxEVT_LEFT_DOWN ); | |
1535 | if (event.GetEventType() == wxEVT_RIGHT_DCLICK) | |
1536 | event.SetEventType( wxEVT_RIGHT_DOWN ); | |
1537 | ||
1538 | // Same for mouse up events | |
1539 | if (event.GetEventType() == wxEVT_LEFT_UP) | |
1540 | return TRUE; | |
1541 | if (event.GetEventType() == wxEVT_RIGHT_UP) | |
1542 | return TRUE; | |
1543 | } | |
1544 | ||
1545 | GetEventHandler()->ProcessEvent( event ) ; | |
1546 | ||
1547 | return TRUE; | |
1548 | } | |
1549 | ||
1550 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) | |
1551 | { | |
1552 | if ( m_tooltip ) | |
1553 | { | |
1554 | return m_tooltip->GetTip() ; | |
1555 | } | |
1556 | return wxEmptyString ; | |
1557 | } | |
1558 | ||
1559 | void wxWindowMac::Update() | |
1560 | { | |
1561 | wxRegion visRgn = MacGetVisibleRegion( false ) ; | |
1562 | int top = 0 , left = 0 ; | |
1563 | MacWindowToRootWindow( &left , &top ) ; | |
1564 | WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; | |
1565 | RgnHandle updateRgn = NewRgn() ; | |
1566 | // getting the update region in macos local coordinates | |
1567 | GetWindowUpdateRgn( rootWindow , updateRgn ) ; | |
1568 | GrafPtr port ; | |
1569 | ::GetPort( &port ) ; | |
1570 | ::SetPort( UMAGetWindowPort( rootWindow ) ) ; | |
1571 | Point pt = {0,0} ; | |
1572 | LocalToGlobal( &pt ) ; | |
1573 | ::SetPort( port ) ; | |
1574 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1575 | // translate to window local coordinates | |
1576 | OffsetRgn( updateRgn , -left , -top ) ; | |
1577 | SectRgn( updateRgn , (RgnHandle) visRgn.GetWXHRGN() , updateRgn ) ; | |
1578 | MacRedraw( updateRgn , 0 , true ) ; | |
1579 | // for flushing and validating we need macos-local coordinates again | |
1580 | OffsetRgn( updateRgn , left , top ) ; | |
1581 | #if TARGET_API_MAC_CARBON | |
1582 | if ( QDIsPortBuffered( GetWindowPort( rootWindow ) ) ) | |
1583 | { | |
1584 | QDFlushPortBuffer( GetWindowPort( rootWindow ) , updateRgn ) ; | |
1585 | } | |
1586 | #endif | |
1587 | ValidWindowRgn( rootWindow , updateRgn ) ; | |
1588 | DisposeRgn( updateRgn ) ; | |
1589 | } | |
1590 | ||
1591 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const | |
1592 | { | |
1593 | wxTopLevelWindowMac* win = NULL ; | |
1594 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
1595 | if ( window ) | |
1596 | { | |
1597 | win = wxFindWinFromMacWindow( window ) ; | |
1598 | } | |
1599 | return win ; | |
1600 | } | |
1601 | ||
1602 | const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings ) | |
1603 | { | |
1604 | RgnHandle visRgn = NewRgn() ; | |
1605 | RgnHandle tempRgn = NewRgn() ; | |
1606 | RgnHandle tempStaticBoxRgn = NewRgn() ; | |
1607 | ||
1608 | SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; | |
1609 | ||
1610 | //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox | |
1611 | if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1612 | { | |
1613 | int borderTop = 14 ; | |
1614 | int borderOther = 4 ; | |
1615 | ||
1616 | SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; | |
1617 | DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; | |
1618 | } | |
1619 | ||
1620 | if ( !IsTopLevel() ) | |
1621 | { | |
1622 | wxWindow* parent = GetParent() ; | |
1623 | while( parent ) | |
1624 | { | |
1625 | wxSize size = parent->GetSize() ; | |
1626 | int x , y ; | |
1627 | x = y = 0 ; | |
1628 | parent->MacWindowToRootWindow( &x, &y ) ; | |
1629 | MacRootWindowToWindow( &x , &y ) ; | |
1630 | ||
1631 | SetRectRgn( tempRgn , | |
1632 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
1633 | x + size.x - parent->MacGetRightBorderSize(), | |
1634 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
1635 | ||
1636 | SectRgn( visRgn , tempRgn , visRgn ) ; | |
1637 | if ( parent->IsTopLevel() ) | |
1638 | break ; | |
1639 | parent = parent->GetParent() ; | |
1640 | } | |
1641 | } | |
1642 | if ( respectChildrenAndSiblings ) | |
1643 | { | |
1644 | if ( GetWindowStyle() & wxCLIP_CHILDREN ) | |
1645 | { | |
1646 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1647 | { | |
1648 | wxWindowMac *child = node->GetData(); | |
1649 | ||
1650 | if ( !child->IsTopLevel() && child->IsShown() ) | |
1651 | { | |
1652 | SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1653 | if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1654 | { | |
1655 | int borderTop = 14 ; | |
1656 | int borderOther = 4 ; | |
1657 | ||
1658 | SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; | |
1659 | DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; | |
1660 | } | |
1661 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
1662 | } | |
1663 | } | |
1664 | } | |
1665 | ||
1666 | if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) | |
1667 | { | |
1668 | bool thisWindowThrough = false ; | |
1669 | for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) | |
1670 | { | |
1671 | wxWindowMac *sibling = node->GetData(); | |
1672 | if ( sibling == this ) | |
1673 | { | |
1674 | thisWindowThrough = true ; | |
1675 | continue ; | |
1676 | } | |
1677 | if( !thisWindowThrough ) | |
1678 | { | |
1679 | continue ; | |
1680 | } | |
1681 | ||
1682 | if ( !sibling->IsTopLevel() && sibling->IsShown() ) | |
1683 | { | |
1684 | SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; | |
1685 | if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1686 | { | |
1687 | int borderTop = 14 ; | |
1688 | int borderOther = 4 ; | |
1689 | ||
1690 | SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; | |
1691 | DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; | |
1692 | } | |
1693 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
1694 | } | |
1695 | } | |
1696 | } | |
1697 | } | |
1698 | m_macVisibleRegion = visRgn ; | |
1699 | DisposeRgn( visRgn ) ; | |
1700 | DisposeRgn( tempRgn ) ; | |
1701 | DisposeRgn( tempStaticBoxRgn ) ; | |
1702 | return m_macVisibleRegion ; | |
1703 | } | |
1704 | ||
1705 | void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) | |
1706 | { | |
1707 | RgnHandle updatergn = (RgnHandle) updatergnr ; | |
1708 | // updatergn is always already clipped to our boundaries | |
1709 | // it is in window coordinates, not in client coordinates | |
1710 | ||
1711 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
1712 | ||
1713 | { | |
1714 | // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates | |
1715 | RgnHandle ownUpdateRgn = NewRgn() ; | |
1716 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
1717 | ||
1718 | SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ; | |
1719 | ||
1720 | // newupdate is the update region in client coordinates | |
1721 | RgnHandle newupdate = NewRgn() ; | |
1722 | wxSize point = GetClientSize() ; | |
1723 | wxPoint origin = GetClientAreaOrigin() ; | |
1724 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; | |
1725 | SectRgn( newupdate , ownUpdateRgn , newupdate ) ; | |
1726 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1727 | m_updateRegion = newupdate ; | |
1728 | DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion | |
1729 | ||
1730 | if ( erase && !EmptyRgn(ownUpdateRgn) ) | |
1731 | { | |
1732 | wxWindowDC dc(this); | |
1733 | if (!EmptyRgn(ownUpdateRgn)) | |
1734 | dc.SetClippingRegion(wxRegion(ownUpdateRgn)); | |
1735 | wxEraseEvent eevent( GetId(), &dc ); | |
1736 | eevent.SetEventObject( this ); | |
1737 | GetEventHandler()->ProcessEvent( eevent ); | |
1738 | ||
1739 | wxNcPaintEvent eventNc( GetId() ); | |
1740 | eventNc.SetEventObject( this ); | |
1741 | GetEventHandler()->ProcessEvent( eventNc ); | |
1742 | } | |
1743 | DisposeRgn( ownUpdateRgn ) ; | |
1744 | if ( !m_updateRegion.Empty() ) | |
1745 | { | |
1746 | wxWindowList hiddenWindows ; | |
1747 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1748 | { | |
1749 | wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; | |
1750 | ||
1751 | if ( child && child->MacGetRootWindow() == window && child->IsShown() && child->GetMacControl() ) | |
1752 | { | |
1753 | SetControlVisibility( (ControlHandle) child->GetMacControl() , false , false ) ; | |
1754 | hiddenWindows.Append( child ) ; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | wxPaintEvent event; | |
1759 | event.m_timeStamp = time ; | |
1760 | event.SetEventObject(this); | |
1761 | GetEventHandler()->ProcessEvent(event); | |
1762 | ||
1763 | for (wxWindowListNode *node = hiddenWindows.GetFirst(); node; node = node->GetNext()) | |
1764 | { | |
1765 | wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; | |
1766 | ||
1767 | if ( child && child->GetMacControl() ) | |
1768 | { | |
1769 | SetControlVisibility( (ControlHandle) child->GetMacControl() , true , false ) ; | |
1770 | } | |
1771 | } | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively | |
1776 | ||
1777 | RgnHandle childupdate = NewRgn() ; | |
1778 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1779 | { | |
1780 | // calculate the update region for the child windows by intersecting the window rectangle with our own | |
1781 | // passed in update region and then offset it to be client-wise window coordinates again | |
1782 | wxWindowMac *child = node->GetData(); | |
1783 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1784 | SectRgn( childupdate , updatergn , childupdate ) ; | |
1785 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
1786 | if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) | |
1787 | { | |
1788 | // because dialogs may also be children | |
1789 | child->MacRedraw( childupdate , time , erase ) ; | |
1790 | } | |
1791 | } | |
1792 | DisposeRgn( childupdate ) ; | |
1793 | // eventually a draw grow box here | |
1794 | ||
1795 | } | |
1796 | ||
1797 | WXHWND wxWindowMac::MacGetRootWindow() const | |
1798 | { | |
1799 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1800 | ||
1801 | while( iter ) | |
1802 | { | |
1803 | if ( iter->IsTopLevel() ) | |
1804 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
1805 | ||
1806 | iter = iter->GetParent() ; | |
1807 | } | |
1808 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; | |
1809 | return NULL ; | |
1810 | } | |
1811 | ||
1812 | void wxWindowMac::MacCreateScrollBars( long style ) | |
1813 | { | |
1814 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; | |
1815 | ||
1816 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
1817 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
1818 | int width, height ; | |
1819 | GetClientSize( &width , &height ) ; | |
1820 | ||
1821 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
1822 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1823 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1824 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
1825 | ||
1826 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
1827 | vSize , wxVERTICAL); | |
1828 | ||
1829 | if ( style & wxVSCROLL ) | |
1830 | { | |
1831 | ||
1832 | } | |
1833 | else | |
1834 | { | |
1835 | m_vScrollBar->Show(false) ; | |
1836 | } | |
1837 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
1838 | hSize , wxHORIZONTAL); | |
1839 | if ( style & wxHSCROLL ) | |
1840 | { | |
1841 | } | |
1842 | else | |
1843 | { | |
1844 | m_hScrollBar->Show(false) ; | |
1845 | } | |
1846 | ||
1847 | // because the create does not take into account the client area origin | |
1848 | MacRepositionScrollBars() ; // we might have a real position shift | |
1849 | } | |
1850 | ||
1851 | void wxWindowMac::MacRepositionScrollBars() | |
1852 | { | |
1853 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; | |
1854 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
1855 | ||
1856 | // get real client area | |
1857 | ||
1858 | int width = m_width ; | |
1859 | int height = m_height ; | |
1860 | ||
1861 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
1862 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
1863 | ||
1864 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
1865 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1866 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1867 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
1868 | ||
1869 | int x = 0 ; | |
1870 | int y = 0 ; | |
1871 | int w = m_width ; | |
1872 | int h = m_height ; | |
1873 | ||
1874 | MacClientToRootWindow( &x , &y ) ; | |
1875 | MacClientToRootWindow( &w , &h ) ; | |
1876 | ||
1877 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1878 | ||
1879 | int totW = 10000 , totH = 10000; | |
1880 | while( iter ) | |
1881 | { | |
1882 | if ( iter->IsTopLevel() ) | |
1883 | { | |
1884 | totW = iter->m_width ; | |
1885 | totH = iter->m_height ; | |
1886 | break ; | |
1887 | } | |
1888 | ||
1889 | iter = iter->GetParent() ; | |
1890 | } | |
1891 | ||
1892 | if ( x == 0 ) | |
1893 | { | |
1894 | hPoint.x = -1 ; | |
1895 | hSize.x += 1 ; | |
1896 | } | |
1897 | if ( y == 0 ) | |
1898 | { | |
1899 | vPoint.y = -1 ; | |
1900 | vSize.y += 1 ; | |
1901 | } | |
1902 | ||
1903 | if ( w-x >= totW ) | |
1904 | { | |
1905 | hSize.x += 1 ; | |
1906 | vPoint.x += 1 ; | |
1907 | } | |
1908 | ||
1909 | if ( h-y >= totH ) | |
1910 | { | |
1911 | vSize.y += 1 ; | |
1912 | hPoint.y += 1 ; | |
1913 | } | |
1914 | ||
1915 | if ( m_vScrollBar ) | |
1916 | { | |
1917 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
1918 | } | |
1919 | if ( m_hScrollBar ) | |
1920 | { | |
1921 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
1922 | } | |
1923 | } | |
1924 | ||
1925 | bool wxWindowMac::AcceptsFocus() const | |
1926 | { | |
1927 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
1928 | } | |
1929 | ||
1930 | WXWidget wxWindowMac::MacGetContainerForEmbedding() | |
1931 | { | |
1932 | return GetParent()->MacGetContainerForEmbedding() ; | |
1933 | } | |
1934 | ||
1935 | void wxWindowMac::MacSuperChangedPosition() | |
1936 | { | |
1937 | // only window-absolute structures have to be moved i.e. controls | |
1938 | ||
1939 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1940 | while ( node ) | |
1941 | { | |
1942 | wxWindowMac *child = node->GetData(); | |
1943 | child->MacSuperChangedPosition() ; | |
1944 | node = node->GetNext(); | |
1945 | } | |
1946 | } | |
1947 | ||
1948 | void wxWindowMac::MacTopLevelWindowChangedPosition() | |
1949 | { | |
1950 | // only screen-absolute structures have to be moved i.e. glcanvas | |
1951 | ||
1952 | wxWindowListNode *node = GetChildren().GetFirst(); | |
1953 | while ( node ) | |
1954 | { | |
1955 | wxWindowMac *child = node->GetData(); | |
1956 | child->MacTopLevelWindowChangedPosition() ; | |
1957 | node = node->GetNext(); | |
1958 | } | |
1959 | } | |
1960 | long wxWindowMac::MacGetLeftBorderSize( ) const | |
1961 | { | |
1962 | if( IsTopLevel() ) | |
1963 | return 0 ; | |
1964 | ||
1965 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
1966 | { | |
1967 | SInt32 border = 3 ; | |
1968 | #if wxMAC_USE_THEME_BORDER | |
1969 | #if TARGET_CARBON | |
1970 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1971 | #endif | |
1972 | #endif | |
1973 | return border ; | |
1974 | } | |
1975 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
1976 | { | |
1977 | SInt32 border = 3 ; | |
1978 | #if wxMAC_USE_THEME_BORDER | |
1979 | #if TARGET_CARBON | |
1980 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1981 | #endif | |
1982 | #endif | |
1983 | return border ; | |
1984 | } | |
1985 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
1986 | { | |
1987 | return 1 ; | |
1988 | } | |
1989 | return 0 ; | |
1990 | } | |
1991 | ||
1992 | long wxWindowMac::MacGetRightBorderSize( ) const | |
1993 | { | |
1994 | // they are all symmetric in mac themes | |
1995 | return MacGetLeftBorderSize() ; | |
1996 | } | |
1997 | ||
1998 | long wxWindowMac::MacGetTopBorderSize( ) const | |
1999 | { | |
2000 | // they are all symmetric in mac themes | |
2001 | return MacGetLeftBorderSize() ; | |
2002 | } | |
2003 | ||
2004 | long wxWindowMac::MacGetBottomBorderSize( ) const | |
2005 | { | |
2006 | // they are all symmetric in mac themes | |
2007 | return MacGetLeftBorderSize() ; | |
2008 | } | |
2009 | ||
2010 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) | |
2011 | { | |
2012 | return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; | |
2013 | } | |
2014 | ||
2015 | // Find the wxWindowMac at the current mouse position, returning the mouse | |
2016 | // position. | |
2017 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) | |
2018 | { | |
2019 | pt = wxGetMousePosition(); | |
2020 | wxWindowMac* found = wxFindWindowAtPoint(pt); | |
2021 | return found; | |
2022 | } | |
2023 | ||
2024 | // Get the current mouse position. | |
2025 | wxPoint wxGetMousePosition() | |
2026 | { | |
2027 | int x, y; | |
2028 | wxGetMousePosition(& x, & y); | |
2029 | return wxPoint(x, y); | |
2030 | } | |
2031 | ||
2032 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) | |
2033 | { | |
2034 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
2035 | { | |
2036 | // copied from wxGTK : CS | |
2037 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN | |
2038 | // except that: | |
2039 | // | |
2040 | // (a) it's a command event and so is propagated to the parent | |
2041 | // (b) under MSW it can be generated from kbd too | |
2042 | // (c) it uses screen coords (because of (a)) | |
2043 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
2044 | this->GetId(), | |
2045 | this->ClientToScreen(event.GetPosition())); | |
2046 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) | |
2047 | event.Skip() ; | |
2048 | } | |
2049 | else | |
2050 | { | |
2051 | event.Skip() ; | |
2052 | } | |
2053 | } | |
2054 |