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