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