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