]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/osx/window_osx.cpp | |
3 | // Purpose: wxWindowMac | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/window.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/log.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/utils.h" | |
20 | #include "wx/panel.h" | |
21 | #include "wx/frame.h" | |
22 | #include "wx/dc.h" | |
23 | #include "wx/dcclient.h" | |
24 | #include "wx/button.h" | |
25 | #include "wx/menu.h" | |
26 | #include "wx/dialog.h" | |
27 | #include "wx/settings.h" | |
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/scrolbar.h" | |
30 | #include "wx/statbox.h" | |
31 | #include "wx/textctrl.h" | |
32 | #include "wx/toolbar.h" | |
33 | #include "wx/layout.h" | |
34 | #include "wx/statusbr.h" | |
35 | #include "wx/menuitem.h" | |
36 | #include "wx/treectrl.h" | |
37 | #include "wx/listctrl.h" | |
38 | #endif | |
39 | ||
40 | #include "wx/tooltip.h" | |
41 | #include "wx/spinctrl.h" | |
42 | #include "wx/geometry.h" | |
43 | ||
44 | #if wxUSE_LISTCTRL | |
45 | #include "wx/listctrl.h" | |
46 | #endif | |
47 | ||
48 | #if wxUSE_TREECTRL | |
49 | #include "wx/treectrl.h" | |
50 | #endif | |
51 | ||
52 | #if wxUSE_CARET | |
53 | #include "wx/caret.h" | |
54 | #endif | |
55 | ||
56 | #if wxUSE_POPUPWIN | |
57 | #include "wx/popupwin.h" | |
58 | #endif | |
59 | ||
60 | #if wxUSE_DRAG_AND_DROP | |
61 | #include "wx/dnd.h" | |
62 | #endif | |
63 | ||
64 | #include "wx/graphics.h" | |
65 | ||
66 | #if wxOSX_USE_CARBON | |
67 | #include "wx/osx/uma.h" | |
68 | #else | |
69 | #include "wx/osx/private.h" | |
70 | #endif | |
71 | ||
72 | #define MAC_SCROLLBAR_SIZE 15 | |
73 | #define MAC_SMALL_SCROLLBAR_SIZE 11 | |
74 | ||
75 | #include <string.h> | |
76 | ||
77 | #ifdef __WXUNIVERSAL__ | |
78 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
79 | #endif | |
80 | ||
81 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
82 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) | |
83 | END_EVENT_TABLE() | |
84 | ||
85 | #define wxMAC_DEBUG_REDRAW 0 | |
86 | #ifndef wxMAC_DEBUG_REDRAW | |
87 | #define wxMAC_DEBUG_REDRAW 0 | |
88 | #endif | |
89 | ||
90 | wxWidgetImplType* kOSXNoWidgetImpl = (wxWidgetImplType*) -1L; | |
91 | ||
92 | // =========================================================================== | |
93 | // implementation | |
94 | // =========================================================================== | |
95 | ||
96 | // the grow box has to be implemented as an inactive window, so that nothing can direct | |
97 | // the focus to it | |
98 | ||
99 | class WXDLLIMPEXP_CORE wxBlindPlateWindow : public wxWindow | |
100 | { | |
101 | public: | |
102 | wxBlindPlateWindow() { Init(); } | |
103 | ||
104 | // Old-style constructor (no default values for coordinates to avoid | |
105 | // ambiguity with the new one) | |
106 | wxBlindPlateWindow(wxWindow *parent, | |
107 | int x, int y, int width, int height, | |
108 | long style = wxTAB_TRAVERSAL | wxNO_BORDER, | |
109 | const wxString& name = wxPanelNameStr) | |
110 | { | |
111 | Init(); | |
112 | ||
113 | Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), style, name); | |
114 | } | |
115 | ||
116 | // Constructor | |
117 | wxBlindPlateWindow(wxWindow *parent, | |
118 | wxWindowID winid = wxID_ANY, | |
119 | const wxPoint& pos = wxDefaultPosition, | |
120 | const wxSize& size = wxDefaultSize, | |
121 | long style = wxTAB_TRAVERSAL | wxNO_BORDER, | |
122 | const wxString& name = wxPanelNameStr) | |
123 | { | |
124 | Init(); | |
125 | ||
126 | Create(parent, winid, pos, size, style, name); | |
127 | } | |
128 | ||
129 | // Pseudo ctor | |
130 | bool Create(wxWindow *parent, | |
131 | wxWindowID winid = wxID_ANY, | |
132 | const wxPoint& pos = wxDefaultPosition, | |
133 | const wxSize& size = wxDefaultSize, | |
134 | long style = wxTAB_TRAVERSAL | wxNO_BORDER, | |
135 | const wxString& name = wxPanelNameStr) | |
136 | { | |
137 | if ( !wxWindow::Create(parent, winid, pos, size, style, name) ) | |
138 | return false; | |
139 | ||
140 | // so that non-solid background renders correctly under GTK+: | |
141 | SetThemeEnabled(true); | |
142 | return true; | |
143 | } | |
144 | ||
145 | virtual ~wxBlindPlateWindow(); | |
146 | ||
147 | virtual bool AcceptsFocus() const | |
148 | { | |
149 | return false; | |
150 | } | |
151 | ||
152 | protected: | |
153 | // common part of all ctors | |
154 | void Init() | |
155 | { | |
156 | } | |
157 | ||
158 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow) | |
159 | DECLARE_EVENT_TABLE() | |
160 | }; | |
161 | ||
162 | wxBlindPlateWindow::~wxBlindPlateWindow() | |
163 | { | |
164 | } | |
165 | ||
166 | IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow, wxWindow) | |
167 | ||
168 | BEGIN_EVENT_TABLE(wxBlindPlateWindow, wxWindow) | |
169 | END_EVENT_TABLE() | |
170 | ||
171 | ||
172 | // ---------------------------------------------------------------------------- | |
173 | // constructors and such | |
174 | // ---------------------------------------------------------------------------- | |
175 | ||
176 | wxWindowMac::wxWindowMac() | |
177 | { | |
178 | Init(); | |
179 | } | |
180 | ||
181 | wxWindowMac::wxWindowMac(wxWindowMac *parent, | |
182 | wxWindowID id, | |
183 | const wxPoint& pos , | |
184 | const wxSize& size , | |
185 | long style , | |
186 | const wxString& name ) | |
187 | { | |
188 | Init(); | |
189 | Create(parent, id, pos, size, style, name); | |
190 | } | |
191 | ||
192 | void wxWindowMac::Init() | |
193 | { | |
194 | m_peer = NULL ; | |
195 | m_macAlpha = 255 ; | |
196 | m_cgContextRef = NULL ; | |
197 | ||
198 | // as all windows are created with WS_VISIBLE style... | |
199 | m_isShown = true; | |
200 | ||
201 | m_hScrollBar = NULL ; | |
202 | m_vScrollBar = NULL ; | |
203 | m_hScrollBarAlwaysShown = false; | |
204 | m_vScrollBarAlwaysShown = false; | |
205 | m_growBox = NULL ; | |
206 | ||
207 | m_clipChildren = false ; | |
208 | m_cachedClippedRectValid = false ; | |
209 | m_isNativeWindowWrapper = false; | |
210 | } | |
211 | ||
212 | wxWindowMac::~wxWindowMac() | |
213 | { | |
214 | SendDestroyEvent(); | |
215 | ||
216 | MacInvalidateBorders() ; | |
217 | ||
218 | #ifndef __WXUNIVERSAL__ | |
219 | // VS: make sure there's no wxFrame with last focus set to us: | |
220 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
221 | { | |
222 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
223 | if ( frame ) | |
224 | { | |
225 | if ( frame->GetLastFocus() == this ) | |
226 | frame->SetLastFocus(NULL); | |
227 | break; | |
228 | } | |
229 | } | |
230 | #endif | |
231 | ||
232 | // destroy children before destroying this window itself | |
233 | DestroyChildren(); | |
234 | ||
235 | // wxRemoveMacControlAssociation( this ) ; | |
236 | // If we delete an item, we should initialize the parent panel, | |
237 | // because it could now be invalid. | |
238 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); | |
239 | if ( tlw ) | |
240 | { | |
241 | if ( tlw->GetDefaultItem() == (wxButton*) this) | |
242 | tlw->SetDefaultItem(NULL); | |
243 | } | |
244 | ||
245 | if ( g_MacLastWindow == this ) | |
246 | g_MacLastWindow = NULL ; | |
247 | ||
248 | #ifndef __WXUNIVERSAL__ | |
249 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ; | |
250 | if ( frame ) | |
251 | { | |
252 | if ( frame->GetLastFocus() == this ) | |
253 | frame->SetLastFocus( NULL ) ; | |
254 | } | |
255 | #endif | |
256 | ||
257 | // delete our drop target if we've got one | |
258 | #if wxUSE_DRAG_AND_DROP | |
259 | wxDELETE(m_dropTarget); | |
260 | #endif | |
261 | ||
262 | delete GetPeer() ; | |
263 | } | |
264 | ||
265 | WXWidget wxWindowMac::GetHandle() const | |
266 | { | |
267 | if ( GetPeer() ) | |
268 | return (WXWidget) GetPeer()->GetWXWidget() ; | |
269 | return NULL; | |
270 | } | |
271 | ||
272 | wxOSXWidgetImpl* wxWindowMac::GetPeer() const | |
273 | { | |
274 | return m_peer == kOSXNoWidgetImpl ? NULL : m_peer ; | |
275 | } | |
276 | ||
277 | void wxWindowMac::DontCreatePeer() | |
278 | { | |
279 | m_peer = kOSXNoWidgetImpl; | |
280 | } | |
281 | ||
282 | void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl* wrapper) | |
283 | { | |
284 | wxOSXWidgetImpl* inner = GetPeer(); | |
285 | wxASSERT_MSG( inner != NULL && inner->IsOk(), "missing or incomplete inner peer" ); | |
286 | wxASSERT_MSG( wrapper != NULL && wrapper->IsOk(), "missing or incomplete wrapper" ); | |
287 | ||
288 | if ( !(inner != NULL && inner->IsOk() && wrapper != NULL && wrapper->IsOk()) ) | |
289 | return; | |
290 | ||
291 | inner->RemoveFromParent(); | |
292 | wrapper->InstallEventHandler(); | |
293 | wrapper->Embed(inner); | |
294 | m_peer = wrapper; | |
295 | } | |
296 | ||
297 | void wxWindowMac::SetPeer(wxOSXWidgetImpl* peer) | |
298 | { | |
299 | if ( GetPeer() ) | |
300 | { | |
301 | if ( !GetPeer()->IsRootControl() ) | |
302 | GetPeer()->RemoveFromParent(); | |
303 | wxDELETE(m_peer); | |
304 | } | |
305 | ||
306 | m_peer = peer; | |
307 | ||
308 | if ( GetPeer() && !GetPeer()->IsRootControl()) | |
309 | { | |
310 | wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ; | |
311 | ||
312 | if (!GetParent()->GetChildren().Find((wxWindow*)this)) | |
313 | GetParent()->AddChild( this ); | |
314 | ||
315 | GetPeer()->InstallEventHandler(); | |
316 | GetPeer()->Embed(GetParent()->GetPeer()); | |
317 | ||
318 | GetParent()->MacChildAdded() ; | |
319 | ||
320 | // adjust font, controlsize etc | |
321 | DoSetWindowVariant( m_windowVariant ) ; | |
322 | ||
323 | GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; | |
324 | ||
325 | // for controls we want to use best size for wxDefaultSize params ) | |
326 | if ( !GetPeer()->IsUserPane() ) | |
327 | SetInitialSize(GetMinSize()); | |
328 | ||
329 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
330 | } | |
331 | } | |
332 | ||
333 | #if WXWIN_COMPATIBILITY_2_8 | |
334 | ||
335 | bool wxWindowMac::MacIsUserPane() | |
336 | { | |
337 | return GetPeer() == NULL || GetPeer()->IsUserPane(); | |
338 | } | |
339 | ||
340 | #endif | |
341 | ||
342 | bool wxWindowMac::MacIsUserPane() const | |
343 | { | |
344 | return GetPeer() == NULL || GetPeer()->IsUserPane(); | |
345 | } | |
346 | ||
347 | // --------------------------------------------------------------------------- | |
348 | // Utility Routines to move between different coordinate systems | |
349 | // --------------------------------------------------------------------------- | |
350 | ||
351 | /* | |
352 | * Right now we have the following setup : | |
353 | * a border that is not part of the native control is always outside the | |
354 | * control's border (otherwise we loose all native intelligence, future ways | |
355 | * may be to have a second embedding control responsible for drawing borders | |
356 | * and backgrounds eventually) | |
357 | * so all this border calculations have to be taken into account when calling | |
358 | * native methods or getting native oriented data | |
359 | * so we have three coordinate systems here | |
360 | * wx client coordinates | |
361 | * wx window coordinates (including window frames) | |
362 | * native coordinates | |
363 | */ | |
364 | ||
365 | // | |
366 | // | |
367 | ||
368 | // Constructor | |
369 | bool wxWindowMac::Create(wxWindowMac *parent, | |
370 | wxWindowID id, | |
371 | const wxPoint& pos, | |
372 | const wxSize& size, | |
373 | long style, | |
374 | const wxString& name) | |
375 | { | |
376 | wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); | |
377 | ||
378 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
379 | return false; | |
380 | ||
381 | m_windowVariant = parent->GetWindowVariant() ; | |
382 | ||
383 | if ( m_peer != kOSXNoWidgetImpl ) | |
384 | { | |
385 | SetPeer(wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() )); | |
386 | MacPostControlCreate(pos, size) ; | |
387 | } | |
388 | ||
389 | #ifndef __WXUNIVERSAL__ | |
390 | // Don't give scrollbars to wxControls unless they ask for them | |
391 | if ( (! IsKindOf(CLASSINFO(wxControl)) | |
392 | #if wxUSE_STATUSBAR | |
393 | && ! IsKindOf(CLASSINFO(wxStatusBar)) | |
394 | #endif | |
395 | ) | |
396 | || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) | |
397 | { | |
398 | MacCreateScrollBars( style ) ; | |
399 | } | |
400 | #endif | |
401 | ||
402 | wxWindowCreateEvent event((wxWindow*)this); | |
403 | GetEventHandler()->AddPendingEvent(event); | |
404 | ||
405 | return true; | |
406 | } | |
407 | ||
408 | void wxWindowMac::MacChildAdded() | |
409 | { | |
410 | #if wxUSE_SCROLLBAR | |
411 | if ( m_vScrollBar ) | |
412 | m_vScrollBar->Raise() ; | |
413 | if ( m_hScrollBar ) | |
414 | m_hScrollBar->Raise() ; | |
415 | if ( m_growBox ) | |
416 | m_growBox->Raise() ; | |
417 | #endif | |
418 | } | |
419 | ||
420 | void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) | |
421 | { | |
422 | // todo remove if refactoring works correctly | |
423 | #if 0 | |
424 | wxASSERT_MSG( GetPeer() != NULL && GetPeer()->IsOk() , wxT("No valid mac control") ) ; | |
425 | ||
426 | if (!GetParent()->GetChildren().Find((wxWindow*)this)) | |
427 | GetParent()->AddChild( this ); | |
428 | ||
429 | GetPeer()->InstallEventHandler(); | |
430 | GetPeer()->Embed(GetParent()->GetPeer()); | |
431 | ||
432 | GetParent()->MacChildAdded() ; | |
433 | ||
434 | // adjust font, controlsize etc | |
435 | DoSetWindowVariant( m_windowVariant ) ; | |
436 | ||
437 | GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; | |
438 | ||
439 | // for controls we want to use best size for wxDefaultSize params ) | |
440 | if ( !GetPeer()->IsUserPane() ) | |
441 | SetInitialSize(size); | |
442 | ||
443 | SetCursor( *wxSTANDARD_CURSOR ) ; | |
444 | #endif | |
445 | } | |
446 | ||
447 | void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) | |
448 | { | |
449 | // Don't assert, in case we set the window variant before | |
450 | // the window is created | |
451 | // wxASSERT( GetPeer()->Ok() ) ; | |
452 | ||
453 | m_windowVariant = variant ; | |
454 | ||
455 | if (GetPeer() == NULL || !GetPeer()->IsOk()) | |
456 | return; | |
457 | ||
458 | GetPeer()->SetControlSize( variant ); | |
459 | #if wxOSX_USE_CARBON | |
460 | ControlSize size ; | |
461 | ||
462 | // we will get that from the settings later | |
463 | // and make this NORMAL later, but first | |
464 | // we have a few calculations that we must fix | |
465 | ||
466 | switch ( variant ) | |
467 | { | |
468 | case wxWINDOW_VARIANT_NORMAL : | |
469 | size = kControlSizeNormal; | |
470 | break ; | |
471 | ||
472 | case wxWINDOW_VARIANT_SMALL : | |
473 | size = kControlSizeSmall; | |
474 | break ; | |
475 | ||
476 | case wxWINDOW_VARIANT_MINI : | |
477 | // not always defined in the headers | |
478 | size = 3 ; | |
479 | break ; | |
480 | ||
481 | case wxWINDOW_VARIANT_LARGE : | |
482 | size = kControlSizeLarge; | |
483 | break ; | |
484 | ||
485 | default: | |
486 | wxFAIL_MSG(wxT("unexpected window variant")); | |
487 | break ; | |
488 | } | |
489 | GetPeer()->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ; | |
490 | #endif | |
491 | ||
492 | ||
493 | switch ( variant ) | |
494 | { | |
495 | case wxWINDOW_VARIANT_NORMAL : | |
496 | static wxFont sysNormal(wxOSX_SYSTEM_FONT_NORMAL); | |
497 | SetFont(sysNormal) ; | |
498 | break ; | |
499 | ||
500 | case wxWINDOW_VARIANT_SMALL : | |
501 | static wxFont sysSmall(wxOSX_SYSTEM_FONT_SMALL); | |
502 | SetFont(sysSmall) ; | |
503 | break ; | |
504 | ||
505 | case wxWINDOW_VARIANT_MINI : | |
506 | static wxFont sysMini(wxOSX_SYSTEM_FONT_MINI); | |
507 | SetFont(sysMini) ; | |
508 | break ; | |
509 | ||
510 | case wxWINDOW_VARIANT_LARGE : | |
511 | static wxFont sysLarge(wxOSX_SYSTEM_FONT_NORMAL); | |
512 | SetFont(sysLarge) ; | |
513 | break ; | |
514 | ||
515 | default: | |
516 | wxFAIL_MSG(wxT("unexpected window variant")); | |
517 | break ; | |
518 | } | |
519 | } | |
520 | ||
521 | void wxWindowMac::MacUpdateControlFont() | |
522 | { | |
523 | if ( GetPeer() ) | |
524 | GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; | |
525 | ||
526 | // do not trigger refreshes upon invisible and possible partly created objects | |
527 | if ( IsShownOnScreen() ) | |
528 | Refresh() ; | |
529 | } | |
530 | ||
531 | bool wxWindowMac::SetFont(const wxFont& font) | |
532 | { | |
533 | bool retval = wxWindowBase::SetFont( font ); | |
534 | ||
535 | MacUpdateControlFont() ; | |
536 | ||
537 | return retval; | |
538 | } | |
539 | ||
540 | bool wxWindowMac::SetForegroundColour(const wxColour& col ) | |
541 | { | |
542 | bool retval = wxWindowBase::SetForegroundColour( col ); | |
543 | ||
544 | if (retval) | |
545 | MacUpdateControlFont(); | |
546 | ||
547 | return retval; | |
548 | } | |
549 | ||
550 | bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style) | |
551 | { | |
552 | if ( !wxWindowBase::SetBackgroundStyle(style) ) | |
553 | return false; | |
554 | ||
555 | if ( GetPeer() ) | |
556 | GetPeer()->SetBackgroundStyle(style); | |
557 | return true; | |
558 | } | |
559 | ||
560 | bool wxWindowMac::SetBackgroundColour(const wxColour& col ) | |
561 | { | |
562 | if (m_growBox) | |
563 | { | |
564 | if ( m_backgroundColour.Ok() ) | |
565 | m_growBox->SetBackgroundColour(m_backgroundColour); | |
566 | else | |
567 | m_growBox->SetBackgroundColour(*wxWHITE); | |
568 | } | |
569 | ||
570 | if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) | |
571 | return false ; | |
572 | ||
573 | if ( GetPeer() ) | |
574 | GetPeer()->SetBackgroundColour( col ) ; | |
575 | ||
576 | return true ; | |
577 | } | |
578 | ||
579 | static bool wxIsWindowOrParentDisabled(wxWindow* w) | |
580 | { | |
581 | while (w && !w->IsTopLevel()) | |
582 | { | |
583 | if (!w->IsEnabled()) | |
584 | return true; | |
585 | w = w->GetParent(); | |
586 | } | |
587 | return false; | |
588 | } | |
589 | ||
590 | void wxWindowMac::SetFocus() | |
591 | { | |
592 | if ( !AcceptsFocus() ) | |
593 | return ; | |
594 | ||
595 | if (wxIsWindowOrParentDisabled((wxWindow*) this)) | |
596 | return; | |
597 | ||
598 | wxWindow* former = FindFocus() ; | |
599 | if ( former == this ) | |
600 | return ; | |
601 | ||
602 | GetPeer()->SetFocus() ; | |
603 | } | |
604 | ||
605 | void wxWindowMac::DoCaptureMouse() | |
606 | { | |
607 | wxApp::s_captureWindow = (wxWindow*) this ; | |
608 | GetPeer()->CaptureMouse() ; | |
609 | } | |
610 | ||
611 | wxWindow * wxWindowBase::GetCapture() | |
612 | { | |
613 | return wxApp::s_captureWindow ; | |
614 | } | |
615 | ||
616 | void wxWindowMac::DoReleaseMouse() | |
617 | { | |
618 | wxApp::s_captureWindow = NULL ; | |
619 | ||
620 | GetPeer()->ReleaseMouse() ; | |
621 | } | |
622 | ||
623 | #if wxUSE_DRAG_AND_DROP | |
624 | ||
625 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) | |
626 | { | |
627 | delete m_dropTarget; | |
628 | ||
629 | m_dropTarget = pDropTarget; | |
630 | if ( m_dropTarget != NULL ) | |
631 | { | |
632 | // TODO: | |
633 | } | |
634 | } | |
635 | ||
636 | #endif | |
637 | ||
638 | // Old-style File Manager Drag & Drop | |
639 | void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept)) | |
640 | { | |
641 | // TODO: | |
642 | } | |
643 | ||
644 | // From a wx position / size calculate the appropriate size of the native control | |
645 | ||
646 | bool wxWindowMac::MacGetBoundsForControl( | |
647 | const wxPoint& pos, | |
648 | const wxSize& size, | |
649 | int& x, int& y, | |
650 | int& w, int& h , bool adjustOrigin ) const | |
651 | { | |
652 | // the desired size, minus the border pixels gives the correct size of the control | |
653 | x = (int)pos.x; | |
654 | y = (int)pos.y; | |
655 | ||
656 | w = WidthDefault( size.x ); | |
657 | h = HeightDefault( size.y ); | |
658 | ||
659 | x += MacGetLeftBorderSize() ; | |
660 | y += MacGetTopBorderSize() ; | |
661 | w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
662 | h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
663 | ||
664 | if ( adjustOrigin ) | |
665 | AdjustForParentClientOrigin( x , y ) ; | |
666 | ||
667 | // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border | |
668 | if ( GetParent() && !GetParent()->IsTopLevel() ) | |
669 | { | |
670 | x -= GetParent()->MacGetLeftBorderSize() ; | |
671 | y -= GetParent()->MacGetTopBorderSize() ; | |
672 | } | |
673 | ||
674 | return true ; | |
675 | } | |
676 | ||
677 | // Get window size (not client size) | |
678 | void wxWindowMac::DoGetSize(int *x, int *y) const | |
679 | { | |
680 | int width, height; | |
681 | GetPeer()->GetSize( width, height ); | |
682 | ||
683 | if (x) | |
684 | *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
685 | if (y) | |
686 | *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
687 | } | |
688 | ||
689 | // get the position of the bounds of this window in client coordinates of its parent | |
690 | void wxWindowMac::DoGetPosition(int *x, int *y) const | |
691 | { | |
692 | int x1, y1; | |
693 | ||
694 | GetPeer()->GetPosition( x1, y1 ) ; | |
695 | ||
696 | // get the wx window position from the native one | |
697 | x1 -= MacGetLeftBorderSize() ; | |
698 | y1 -= MacGetTopBorderSize() ; | |
699 | ||
700 | if ( !IsTopLevel() ) | |
701 | { | |
702 | wxWindow *parent = GetParent(); | |
703 | if ( parent ) | |
704 | { | |
705 | // we must first adjust it to be in window coordinates of the parent, | |
706 | // as otherwise it gets lost by the ClientAreaOrigin fix | |
707 | x1 += parent->MacGetLeftBorderSize() ; | |
708 | y1 += parent->MacGetTopBorderSize() ; | |
709 | ||
710 | // and now to client coordinates | |
711 | wxPoint pt(parent->GetClientAreaOrigin()); | |
712 | x1 -= pt.x ; | |
713 | y1 -= pt.y ; | |
714 | } | |
715 | } | |
716 | ||
717 | if (x) | |
718 | *x = x1 ; | |
719 | if (y) | |
720 | *y = y1 ; | |
721 | } | |
722 | ||
723 | void wxWindowMac::DoScreenToClient(int *x, int *y) const | |
724 | { | |
725 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; | |
726 | wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ; | |
727 | tlw->GetNonOwnedPeer()->ScreenToWindow( x, y); | |
728 | MacRootWindowToWindow( x , y ) ; | |
729 | ||
730 | wxPoint origin = GetClientAreaOrigin() ; | |
731 | if (x) | |
732 | *x -= origin.x ; | |
733 | if (y) | |
734 | *y -= origin.y ; | |
735 | } | |
736 | ||
737 | void wxWindowMac::DoClientToScreen(int *x, int *y) const | |
738 | { | |
739 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; | |
740 | wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ; | |
741 | ||
742 | wxPoint origin = GetClientAreaOrigin() ; | |
743 | if (x) | |
744 | *x += origin.x ; | |
745 | if (y) | |
746 | *y += origin.y ; | |
747 | ||
748 | MacWindowToRootWindow( x , y ) ; | |
749 | tlw->GetNonOwnedPeer()->WindowToScreen( x , y ); | |
750 | } | |
751 | ||
752 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const | |
753 | { | |
754 | wxPoint origin = GetClientAreaOrigin() ; | |
755 | if (x) | |
756 | *x += origin.x ; | |
757 | if (y) | |
758 | *y += origin.y ; | |
759 | ||
760 | MacWindowToRootWindow( x , y ) ; | |
761 | } | |
762 | ||
763 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
764 | { | |
765 | wxPoint pt ; | |
766 | ||
767 | if (x) | |
768 | pt.x = *x ; | |
769 | if (y) | |
770 | pt.y = *y ; | |
771 | ||
772 | if ( !IsTopLevel() ) | |
773 | { | |
774 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
775 | if (top) | |
776 | { | |
777 | pt.x -= MacGetLeftBorderSize() ; | |
778 | pt.y -= MacGetTopBorderSize() ; | |
779 | wxWidgetImpl::Convert( &pt , GetPeer() , top->GetPeer() ) ; | |
780 | } | |
781 | } | |
782 | ||
783 | if (x) | |
784 | *x = (int) pt.x ; | |
785 | if (y) | |
786 | *y = (int) pt.y ; | |
787 | } | |
788 | ||
789 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const | |
790 | { | |
791 | wxPoint pt ; | |
792 | ||
793 | if (x) | |
794 | pt.x = *x ; | |
795 | if (y) | |
796 | pt.y = *y ; | |
797 | ||
798 | if ( !IsTopLevel() ) | |
799 | { | |
800 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
801 | if (top) | |
802 | { | |
803 | wxWidgetImpl::Convert( &pt , top->GetPeer() , GetPeer() ) ; | |
804 | pt.x += MacGetLeftBorderSize() ; | |
805 | pt.y += MacGetTopBorderSize() ; | |
806 | } | |
807 | } | |
808 | ||
809 | if (x) | |
810 | *x = (int) pt.x ; | |
811 | if (y) | |
812 | *y = (int) pt.y ; | |
813 | } | |
814 | ||
815 | wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const | |
816 | { | |
817 | wxSize sizeTotal = size; | |
818 | ||
819 | int innerwidth, innerheight; | |
820 | int left, top; | |
821 | int outerwidth, outerheight; | |
822 | ||
823 | GetPeer()->GetContentArea( left, top, innerwidth, innerheight ); | |
824 | GetPeer()->GetSize( outerwidth, outerheight ); | |
825 | ||
826 | sizeTotal.x += outerwidth-innerwidth; | |
827 | sizeTotal.y += outerheight-innerheight; | |
828 | ||
829 | sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; | |
830 | sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; | |
831 | ||
832 | return sizeTotal; | |
833 | } | |
834 | ||
835 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
836 | void wxWindowMac::DoGetClientSize( int *x, int *y ) const | |
837 | { | |
838 | int ww, hh; | |
839 | ||
840 | int left, top; | |
841 | ||
842 | GetPeer()->GetContentArea( left, top, ww, hh ); | |
843 | #if wxUSE_SCROLLBAR | |
844 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
845 | hh -= m_hScrollBar->GetSize().y ; | |
846 | ||
847 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
848 | ww -= m_vScrollBar->GetSize().x ; | |
849 | ||
850 | #endif | |
851 | if (x) | |
852 | *x = ww; | |
853 | if (y) | |
854 | *y = hh; | |
855 | } | |
856 | ||
857 | bool wxWindowMac::SetCursor(const wxCursor& cursor) | |
858 | { | |
859 | if (m_cursor.IsSameAs(cursor)) | |
860 | return false; | |
861 | ||
862 | if (!cursor.IsOk()) | |
863 | { | |
864 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
865 | return false ; | |
866 | } | |
867 | else | |
868 | { | |
869 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
870 | return false ; | |
871 | } | |
872 | ||
873 | wxASSERT_MSG( m_cursor.Ok(), | |
874 | wxT("cursor must be valid after call to the base version")); | |
875 | ||
876 | if ( GetPeer() != NULL ) | |
877 | GetPeer()->SetCursor( m_cursor ); | |
878 | ||
879 | return true ; | |
880 | } | |
881 | ||
882 | #if wxUSE_MENUS | |
883 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
884 | { | |
885 | #ifndef __WXUNIVERSAL__ | |
886 | menu->UpdateUI(); | |
887 | ||
888 | if ( x == wxDefaultCoord && y == wxDefaultCoord ) | |
889 | { | |
890 | wxPoint mouse = wxGetMousePosition(); | |
891 | x = mouse.x; | |
892 | y = mouse.y; | |
893 | } | |
894 | else | |
895 | { | |
896 | ClientToScreen( &x , &y ) ; | |
897 | } | |
898 | menu->GetPeer()->PopUp(this, x, y); | |
899 | return true; | |
900 | #else | |
901 | // actually this shouldn't be called, because universal is having its own implementation | |
902 | return false; | |
903 | #endif | |
904 | } | |
905 | #endif | |
906 | ||
907 | // ---------------------------------------------------------------------------- | |
908 | // tooltips | |
909 | // ---------------------------------------------------------------------------- | |
910 | ||
911 | #if wxUSE_TOOLTIPS | |
912 | ||
913 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) | |
914 | { | |
915 | wxWindowBase::DoSetToolTip(tooltip); | |
916 | ||
917 | if ( m_tooltip ) | |
918 | m_tooltip->SetWindow(this); | |
919 | ||
920 | if (GetPeer()) | |
921 | GetPeer()->SetToolTip(tooltip); | |
922 | } | |
923 | ||
924 | #endif | |
925 | ||
926 | void wxWindowMac::MacInvalidateBorders() | |
927 | { | |
928 | if ( GetPeer() == NULL ) | |
929 | return ; | |
930 | ||
931 | bool vis = IsShownOnScreen() ; | |
932 | if ( !vis ) | |
933 | return ; | |
934 | ||
935 | int outerBorder = MacGetLeftBorderSize() ; | |
936 | ||
937 | if ( GetPeer()->NeedsFocusRect() ) | |
938 | outerBorder += 4 ; | |
939 | ||
940 | if ( outerBorder == 0 ) | |
941 | return ; | |
942 | ||
943 | // now we know that we have something to do at all | |
944 | ||
945 | int tx,ty,tw,th; | |
946 | ||
947 | GetPeer()->GetSize( tw, th ); | |
948 | GetPeer()->GetPosition( tx, ty ); | |
949 | ||
950 | wxRect leftupdate( tx-outerBorder,ty,outerBorder,th ); | |
951 | wxRect rightupdate( tx+tw, ty, outerBorder, th ); | |
952 | wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder ); | |
953 | wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder ); | |
954 | ||
955 | if (GetParent()) { | |
956 | GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate); | |
957 | GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate); | |
958 | GetParent()->GetPeer()->SetNeedsDisplay(&topupdate); | |
959 | GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate); | |
960 | } | |
961 | } | |
962 | ||
963 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
964 | { | |
965 | // this is never called for a toplevel window, so we know we have a parent | |
966 | int former_x , former_y , former_w, former_h ; | |
967 | ||
968 | // Get true coordinates of former position | |
969 | DoGetPosition( &former_x , &former_y ) ; | |
970 | DoGetSize( &former_w , &former_h ) ; | |
971 | ||
972 | wxWindow *parent = GetParent(); | |
973 | if ( parent ) | |
974 | { | |
975 | wxPoint pt(parent->GetClientAreaOrigin()); | |
976 | former_x += pt.x ; | |
977 | former_y += pt.y ; | |
978 | } | |
979 | ||
980 | int actualWidth = width ; | |
981 | int actualHeight = height ; | |
982 | int actualX = x; | |
983 | int actualY = y; | |
984 | ||
985 | #if 0 | |
986 | // min and max sizes are only for sizers, not for explicit size setting | |
987 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
988 | actualWidth = m_minWidth; | |
989 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
990 | actualHeight = m_minHeight; | |
991 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
992 | actualWidth = m_maxWidth; | |
993 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
994 | actualHeight = m_maxHeight; | |
995 | #endif | |
996 | ||
997 | bool doMove = false, doResize = false ; | |
998 | ||
999 | if ( actualX != former_x || actualY != former_y ) | |
1000 | doMove = true ; | |
1001 | ||
1002 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1003 | doResize = true ; | |
1004 | ||
1005 | if ( doMove || doResize ) | |
1006 | { | |
1007 | // as the borders are drawn outside the native control, we adjust now | |
1008 | ||
1009 | wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ), | |
1010 | wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) , | |
1011 | actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ; | |
1012 | ||
1013 | if ( parent && !parent->IsTopLevel() ) | |
1014 | { | |
1015 | bounds.Offset( -parent->MacGetLeftBorderSize(), -parent->MacGetTopBorderSize() ); | |
1016 | } | |
1017 | ||
1018 | MacInvalidateBorders() ; | |
1019 | ||
1020 | m_cachedClippedRectValid = false ; | |
1021 | ||
1022 | GetPeer()->Move( bounds.x, bounds.y, bounds.width, bounds.height); | |
1023 | ||
1024 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
1025 | ||
1026 | MacInvalidateBorders() ; | |
1027 | ||
1028 | MacRepositionScrollBars() ; | |
1029 | if ( doMove ) | |
1030 | { | |
1031 | wxPoint point(actualX, actualY); | |
1032 | wxMoveEvent event(point, m_windowId); | |
1033 | event.SetEventObject(this); | |
1034 | HandleWindowEvent(event) ; | |
1035 | } | |
1036 | ||
1037 | if ( doResize ) | |
1038 | { | |
1039 | MacRepositionScrollBars() ; | |
1040 | wxSize size(actualWidth, actualHeight); | |
1041 | wxSizeEvent event(size, m_windowId); | |
1042 | event.SetEventObject(this); | |
1043 | HandleWindowEvent(event); | |
1044 | } | |
1045 | } | |
1046 | } | |
1047 | ||
1048 | wxSize wxWindowMac::DoGetBestSize() const | |
1049 | { | |
1050 | if ( GetPeer() == NULL || GetPeer()->IsUserPane() || IsTopLevel() ) | |
1051 | { | |
1052 | return wxWindowBase::DoGetBestSize() ; | |
1053 | } | |
1054 | else | |
1055 | { | |
1056 | wxRect r ; | |
1057 | ||
1058 | GetPeer()->GetBestRect(&r); | |
1059 | ||
1060 | if ( r.GetWidth() == 0 && r.GetHeight() == 0 ) | |
1061 | { | |
1062 | r.x = | |
1063 | r.y = 0 ; | |
1064 | r.width = | |
1065 | r.height = 16 ; | |
1066 | ||
1067 | #if wxUSE_SCROLLBAR | |
1068 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
1069 | { | |
1070 | r.height = 16 ; | |
1071 | } | |
1072 | else | |
1073 | #endif | |
1074 | #if wxUSE_SPINBTN | |
1075 | if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
1076 | { | |
1077 | r.height = 24 ; | |
1078 | } | |
1079 | else | |
1080 | #endif | |
1081 | { | |
1082 | // return wxWindowBase::DoGetBestSize() ; | |
1083 | } | |
1084 | } | |
1085 | ||
1086 | int bestWidth = r.width + MacGetLeftBorderSize() + | |
1087 | MacGetRightBorderSize(); | |
1088 | int bestHeight = r.height + MacGetTopBorderSize() + | |
1089 | MacGetBottomBorderSize(); | |
1090 | if ( bestHeight < 10 ) | |
1091 | bestHeight = 13 ; | |
1092 | ||
1093 | return wxSize(bestWidth, bestHeight); | |
1094 | } | |
1095 | } | |
1096 | ||
1097 | // set the size of the window: if the dimensions are positive, just use them, | |
1098 | // but if any of them is equal to -1, it means that we must find the value for | |
1099 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
1100 | // which case -1 is a valid value for x and y) | |
1101 | // | |
1102 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
1103 | // the width/height to best suit our contents, otherwise we reuse the current | |
1104 | // width/height | |
1105 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
1106 | { | |
1107 | // get the current size and position... | |
1108 | int currentX, currentY; | |
1109 | int currentW, currentH; | |
1110 | ||
1111 | GetPosition(¤tX, ¤tY); | |
1112 | GetSize(¤tW, ¤tH); | |
1113 | ||
1114 | // ... and don't do anything (avoiding flicker) if it's already ok | |
1115 | if ( x == currentX && y == currentY && | |
1116 | width == currentW && height == currentH && ( height != -1 && width != -1 ) ) | |
1117 | { | |
1118 | // TODO: REMOVE | |
1119 | MacRepositionScrollBars() ; // we might have a real position shift | |
1120 | ||
1121 | if (sizeFlags & wxSIZE_FORCE_EVENT) | |
1122 | { | |
1123 | wxSizeEvent event( wxSize(width,height), GetId() ); | |
1124 | event.SetEventObject( this ); | |
1125 | HandleWindowEvent( event ); | |
1126 | } | |
1127 | ||
1128 | return; | |
1129 | } | |
1130 | ||
1131 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1132 | { | |
1133 | if ( x == wxDefaultCoord ) | |
1134 | x = currentX; | |
1135 | if ( y == wxDefaultCoord ) | |
1136 | y = currentY; | |
1137 | } | |
1138 | ||
1139 | AdjustForParentClientOrigin( x, y, sizeFlags ); | |
1140 | ||
1141 | wxSize size = wxDefaultSize; | |
1142 | if ( width == wxDefaultCoord ) | |
1143 | { | |
1144 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1145 | { | |
1146 | size = DoGetBestSize(); | |
1147 | width = size.x; | |
1148 | } | |
1149 | else | |
1150 | { | |
1151 | // just take the current one | |
1152 | width = currentW; | |
1153 | } | |
1154 | } | |
1155 | ||
1156 | if ( height == wxDefaultCoord ) | |
1157 | { | |
1158 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1159 | { | |
1160 | if ( size.x == wxDefaultCoord ) | |
1161 | size = DoGetBestSize(); | |
1162 | // else: already called DoGetBestSize() above | |
1163 | ||
1164 | height = size.y; | |
1165 | } | |
1166 | else | |
1167 | { | |
1168 | // just take the current one | |
1169 | height = currentH; | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | DoMoveWindow( x, y, width, height ); | |
1174 | } | |
1175 | ||
1176 | wxPoint wxWindowMac::GetClientAreaOrigin() const | |
1177 | { | |
1178 | int left,top,width,height; | |
1179 | GetPeer()->GetContentArea( left , top , width , height); | |
1180 | return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() ); | |
1181 | } | |
1182 | ||
1183 | void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) | |
1184 | { | |
1185 | if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord ) | |
1186 | { | |
1187 | int currentclientwidth , currentclientheight ; | |
1188 | int currentwidth , currentheight ; | |
1189 | ||
1190 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
1191 | GetSize( ¤twidth , ¤theight ) ; | |
1192 | ||
1193 | DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth , | |
1194 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | float wxWindowMac::GetContentScaleFactor() const | |
1199 | { | |
1200 | return GetPeer()->GetContentScaleFactor(); | |
1201 | } | |
1202 | ||
1203 | void wxWindowMac::SetLabel(const wxString& title) | |
1204 | { | |
1205 | if ( title == m_label ) | |
1206 | return; | |
1207 | ||
1208 | m_label = title ; | |
1209 | ||
1210 | InvalidateBestSize(); | |
1211 | ||
1212 | if ( GetPeer() && GetPeer()->IsOk() ) | |
1213 | GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; | |
1214 | ||
1215 | // do not trigger refreshes upon invisible and possible partly created objects | |
1216 | if ( IsShownOnScreen() ) | |
1217 | Refresh() ; | |
1218 | } | |
1219 | ||
1220 | wxString wxWindowMac::GetLabel() const | |
1221 | { | |
1222 | return m_label ; | |
1223 | } | |
1224 | ||
1225 | bool wxWindowMac::Show(bool show) | |
1226 | { | |
1227 | if ( !wxWindowBase::Show(show) ) | |
1228 | return false; | |
1229 | ||
1230 | if ( GetPeer() ) | |
1231 | GetPeer()->SetVisibility( show ) ; | |
1232 | ||
1233 | #ifdef __WXOSX_IPHONE__ | |
1234 | // only when there's no native event support | |
1235 | if ( !IsTopLevel() ) | |
1236 | #endif | |
1237 | { | |
1238 | wxShowEvent eventShow(GetId(), show); | |
1239 | eventShow.SetEventObject(this); | |
1240 | ||
1241 | HandleWindowEvent(eventShow); | |
1242 | } | |
1243 | ||
1244 | return true; | |
1245 | } | |
1246 | ||
1247 | bool wxWindowMac::OSXShowWithEffect(bool show, | |
1248 | wxShowEffect effect, | |
1249 | unsigned timeout) | |
1250 | { | |
1251 | if ( effect == wxSHOW_EFFECT_NONE || | |
1252 | !GetPeer() || !GetPeer()->ShowWithEffect(show, effect, timeout) ) | |
1253 | return Show(show); | |
1254 | ||
1255 | return true; | |
1256 | } | |
1257 | ||
1258 | void wxWindowMac::DoEnable(bool enable) | |
1259 | { | |
1260 | GetPeer()->Enable( enable ) ; | |
1261 | MacInvalidateBorders(); | |
1262 | } | |
1263 | ||
1264 | // | |
1265 | // status change notifications | |
1266 | // | |
1267 | ||
1268 | void wxWindowMac::MacVisibilityChanged() | |
1269 | { | |
1270 | } | |
1271 | ||
1272 | void wxWindowMac::MacHiliteChanged() | |
1273 | { | |
1274 | } | |
1275 | ||
1276 | void wxWindowMac::MacEnabledStateChanged() | |
1277 | { | |
1278 | OnEnabled( GetPeer()->IsEnabled() ); | |
1279 | } | |
1280 | ||
1281 | // | |
1282 | // status queries on the inherited window's state | |
1283 | // | |
1284 | ||
1285 | bool wxWindowMac::MacIsReallyEnabled() | |
1286 | { | |
1287 | return GetPeer()->IsEnabled() ; | |
1288 | } | |
1289 | ||
1290 | bool wxWindowMac::MacIsReallyHilited() | |
1291 | { | |
1292 | #if wxOSX_USE_CARBON | |
1293 | return GetPeer()->IsActive(); | |
1294 | #else | |
1295 | return true; // TODO | |
1296 | #endif | |
1297 | } | |
1298 | ||
1299 | int wxWindowMac::GetCharHeight() const | |
1300 | { | |
1301 | wxCoord height; | |
1302 | GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ); | |
1303 | ||
1304 | return height; | |
1305 | } | |
1306 | ||
1307 | int wxWindowMac::GetCharWidth() const | |
1308 | { | |
1309 | wxCoord width; | |
1310 | GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ); | |
1311 | ||
1312 | return width; | |
1313 | } | |
1314 | ||
1315 | void wxWindowMac::DoGetTextExtent(const wxString& str, | |
1316 | int *x, int *y, | |
1317 | int *descent, | |
1318 | int *externalLeading, | |
1319 | const wxFont *theFont) const | |
1320 | { | |
1321 | const wxFont *fontToUse = theFont; | |
1322 | wxFont tempFont; | |
1323 | if ( !fontToUse ) | |
1324 | { | |
1325 | tempFont = GetFont(); | |
1326 | fontToUse = &tempFont; | |
1327 | } | |
1328 | ||
1329 | wxGraphicsContext* ctx = wxGraphicsContext::Create(); | |
1330 | ctx->SetFont( *fontToUse, *wxBLACK ); | |
1331 | ||
1332 | wxDouble h , d , e , w; | |
1333 | ctx->GetTextExtent( str, &w, &h, &d, &e ); | |
1334 | ||
1335 | delete ctx; | |
1336 | ||
1337 | if ( externalLeading ) | |
1338 | *externalLeading = (wxCoord)(e+0.5); | |
1339 | if ( descent ) | |
1340 | *descent = (wxCoord)(d+0.5); | |
1341 | if ( x ) | |
1342 | *x = (wxCoord)(w+0.5); | |
1343 | if ( y ) | |
1344 | *y = (wxCoord)(h+0.5); | |
1345 | } | |
1346 | ||
1347 | /* | |
1348 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect | |
1349 | * we always intersect with the entire window, not only with the client area | |
1350 | */ | |
1351 | ||
1352 | void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) | |
1353 | { | |
1354 | if ( GetPeer() == NULL ) | |
1355 | return ; | |
1356 | ||
1357 | if ( !IsShownOnScreen() ) | |
1358 | return ; | |
1359 | ||
1360 | GetPeer()->SetNeedsDisplay( rect ) ; | |
1361 | } | |
1362 | ||
1363 | void wxWindowMac::DoFreeze() | |
1364 | { | |
1365 | #if wxOSX_USE_CARBON | |
1366 | if ( GetPeer() && GetPeer()->IsOk() ) | |
1367 | GetPeer()->SetDrawingEnabled( false ) ; | |
1368 | #endif | |
1369 | } | |
1370 | ||
1371 | void wxWindowMac::DoThaw() | |
1372 | { | |
1373 | #if wxOSX_USE_CARBON | |
1374 | if ( GetPeer() && GetPeer()->IsOk() ) | |
1375 | { | |
1376 | GetPeer()->SetDrawingEnabled( true ) ; | |
1377 | GetPeer()->InvalidateWithChildren() ; | |
1378 | } | |
1379 | #endif | |
1380 | } | |
1381 | ||
1382 | wxWindow *wxGetActiveWindow() | |
1383 | { | |
1384 | // actually this is a windows-only concept | |
1385 | return NULL; | |
1386 | } | |
1387 | ||
1388 | // Coordinates relative to the window | |
1389 | void wxWindowMac::WarpPointer(int x_pos, int y_pos) | |
1390 | { | |
1391 | #if wxOSX_USE_COCOA_OR_CARBON | |
1392 | int x = x_pos; | |
1393 | int y = y_pos; | |
1394 | DoClientToScreen(&x, &y); | |
1395 | CGPoint cgpoint = CGPointMake( x, y ); | |
1396 | CGWarpMouseCursorPosition( cgpoint ); | |
1397 | ||
1398 | // At least GTK sends a mouse moved event after WarpMouse | |
1399 | wxMouseEvent event(wxEVT_MOTION); | |
1400 | event.m_x = x_pos; | |
1401 | event.m_y = y_pos; | |
1402 | wxMouseState mState = ::wxGetMouseState(); | |
1403 | ||
1404 | event.m_altDown = mState.AltDown(); | |
1405 | event.m_controlDown = mState.ControlDown(); | |
1406 | event.m_leftDown = mState.LeftIsDown(); | |
1407 | event.m_middleDown = mState.MiddleIsDown(); | |
1408 | event.m_rightDown = mState.RightIsDown(); | |
1409 | event.m_metaDown = mState.MetaDown(); | |
1410 | event.m_shiftDown = mState.ShiftDown(); | |
1411 | event.SetId(GetId()); | |
1412 | event.SetEventObject(this); | |
1413 | GetEventHandler()->ProcessEvent(event); | |
1414 | #endif | |
1415 | } | |
1416 | ||
1417 | int wxWindowMac::GetScrollPos(int orient) const | |
1418 | { | |
1419 | #if wxUSE_SCROLLBAR | |
1420 | if ( orient == wxHORIZONTAL ) | |
1421 | { | |
1422 | if ( m_hScrollBar ) | |
1423 | return m_hScrollBar->GetThumbPosition() ; | |
1424 | } | |
1425 | else | |
1426 | { | |
1427 | if ( m_vScrollBar ) | |
1428 | return m_vScrollBar->GetThumbPosition() ; | |
1429 | } | |
1430 | #endif | |
1431 | return 0; | |
1432 | } | |
1433 | ||
1434 | // This now returns the whole range, not just the number | |
1435 | // of positions that we can scroll. | |
1436 | int wxWindowMac::GetScrollRange(int orient) const | |
1437 | { | |
1438 | #if wxUSE_SCROLLBAR | |
1439 | if ( orient == wxHORIZONTAL ) | |
1440 | { | |
1441 | if ( m_hScrollBar ) | |
1442 | return m_hScrollBar->GetRange() ; | |
1443 | } | |
1444 | else | |
1445 | { | |
1446 | if ( m_vScrollBar ) | |
1447 | return m_vScrollBar->GetRange() ; | |
1448 | } | |
1449 | #endif | |
1450 | return 0; | |
1451 | } | |
1452 | ||
1453 | int wxWindowMac::GetScrollThumb(int orient) const | |
1454 | { | |
1455 | #if wxUSE_SCROLLBAR | |
1456 | if ( orient == wxHORIZONTAL ) | |
1457 | { | |
1458 | if ( m_hScrollBar ) | |
1459 | return m_hScrollBar->GetThumbSize() ; | |
1460 | } | |
1461 | else | |
1462 | { | |
1463 | if ( m_vScrollBar ) | |
1464 | return m_vScrollBar->GetThumbSize() ; | |
1465 | } | |
1466 | #endif | |
1467 | return 0; | |
1468 | } | |
1469 | ||
1470 | void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) | |
1471 | { | |
1472 | #if wxUSE_SCROLLBAR | |
1473 | if ( orient == wxHORIZONTAL ) | |
1474 | { | |
1475 | if ( m_hScrollBar ) | |
1476 | m_hScrollBar->SetThumbPosition( pos ) ; | |
1477 | } | |
1478 | else | |
1479 | { | |
1480 | if ( m_vScrollBar ) | |
1481 | m_vScrollBar->SetThumbPosition( pos ) ; | |
1482 | } | |
1483 | #endif | |
1484 | } | |
1485 | ||
1486 | void | |
1487 | wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag) | |
1488 | { | |
1489 | bool needVisibilityUpdate = false; | |
1490 | ||
1491 | if ( m_hScrollBarAlwaysShown != hflag ) | |
1492 | { | |
1493 | m_hScrollBarAlwaysShown = hflag; | |
1494 | needVisibilityUpdate = true; | |
1495 | } | |
1496 | ||
1497 | if ( m_vScrollBarAlwaysShown != vflag ) | |
1498 | { | |
1499 | m_vScrollBarAlwaysShown = vflag; | |
1500 | needVisibilityUpdate = true; | |
1501 | } | |
1502 | ||
1503 | if ( needVisibilityUpdate ) | |
1504 | DoUpdateScrollbarVisibility(); | |
1505 | } | |
1506 | ||
1507 | // | |
1508 | // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef | |
1509 | // our own window origin is at leftOrigin/rightOrigin | |
1510 | // | |
1511 | ||
1512 | void wxWindowMac::MacPaintGrowBox() | |
1513 | { | |
1514 | if ( IsTopLevel() ) | |
1515 | return ; | |
1516 | ||
1517 | #if wxUSE_SCROLLBAR | |
1518 | if ( MacHasScrollBarCorner() ) | |
1519 | { | |
1520 | #if 0 | |
1521 | CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; | |
1522 | wxASSERT( cgContext ) ; | |
1523 | ||
1524 | int tx,ty,tw,th; | |
1525 | ||
1526 | GetPeer()->GetSize( tw, th ); | |
1527 | GetPeer()->GetPosition( tx, ty ); | |
1528 | ||
1529 | Rect rect = { ty,tx, ty+th, tx+tw }; | |
1530 | ||
1531 | ||
1532 | int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
1533 | CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; | |
1534 | CGContextSaveGState( cgContext ); | |
1535 | ||
1536 | if ( m_backgroundColour.Ok() ) | |
1537 | { | |
1538 | CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); | |
1539 | } | |
1540 | else | |
1541 | { | |
1542 | CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 ); | |
1543 | } | |
1544 | CGContextFillRect( cgContext, cgrect ); | |
1545 | CGContextRestoreGState( cgContext ); | |
1546 | #else | |
1547 | if (m_growBox) | |
1548 | { | |
1549 | if ( m_backgroundColour.Ok() ) | |
1550 | m_growBox->SetBackgroundColour(m_backgroundColour); | |
1551 | else | |
1552 | m_growBox->SetBackgroundColour(*wxWHITE); | |
1553 | } | |
1554 | #endif | |
1555 | } | |
1556 | ||
1557 | #endif | |
1558 | } | |
1559 | ||
1560 | void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) | |
1561 | { | |
1562 | if ( IsTopLevel() ) | |
1563 | return ; | |
1564 | ||
1565 | bool hasFocus = GetPeer()->NeedsFocusRect() && HasFocus(); | |
1566 | ||
1567 | // back to the surrounding frame rectangle | |
1568 | int tx,ty,tw,th; | |
1569 | ||
1570 | GetPeer()->GetSize( tw, th ); | |
1571 | GetPeer()->GetPosition( tx, ty ); | |
1572 | ||
1573 | Rect rect = { ty,tx, ty+th, tx+tw }; | |
1574 | ||
1575 | #if wxOSX_USE_COCOA_OR_CARBON | |
1576 | ||
1577 | InsetRect( &rect, -1 , -1 ) ; | |
1578 | ||
1579 | { | |
1580 | CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , | |
1581 | rect.bottom - rect.top ) ; | |
1582 | ||
1583 | CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; | |
1584 | wxASSERT( cgContext ) ; | |
1585 | ||
1586 | if ( GetPeer()->NeedsFrame() ) | |
1587 | { | |
1588 | HIThemeFrameDrawInfo info ; | |
1589 | memset( &info, 0 , sizeof(info) ) ; | |
1590 | ||
1591 | info.version = 0 ; | |
1592 | info.kind = 0 ; | |
1593 | info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; | |
1594 | info.isFocused = hasFocus ; | |
1595 | ||
1596 | if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1597 | { | |
1598 | info.kind = kHIThemeFrameTextFieldSquare ; | |
1599 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
1600 | } | |
1601 | else if ( HasFlag(wxSIMPLE_BORDER) ) | |
1602 | { | |
1603 | info.kind = kHIThemeFrameListBox ; | |
1604 | HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; | |
1605 | } | |
1606 | } | |
1607 | ||
1608 | if ( hasFocus ) | |
1609 | { | |
1610 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; | |
1611 | } | |
1612 | } | |
1613 | #endif // wxOSX_USE_COCOA_OR_CARBON | |
1614 | } | |
1615 | ||
1616 | void wxWindowMac::RemoveChild( wxWindowBase *child ) | |
1617 | { | |
1618 | #if wxUSE_SCROLLBAR | |
1619 | if ( child == m_hScrollBar ) | |
1620 | m_hScrollBar = NULL ; | |
1621 | if ( child == m_vScrollBar ) | |
1622 | m_vScrollBar = NULL ; | |
1623 | if ( child == m_growBox ) | |
1624 | m_growBox = NULL ; | |
1625 | #endif | |
1626 | wxWindowBase::RemoveChild( child ) ; | |
1627 | } | |
1628 | ||
1629 | void wxWindowMac::DoUpdateScrollbarVisibility() | |
1630 | { | |
1631 | #if wxUSE_SCROLLBAR | |
1632 | bool triggerSizeEvent = false; | |
1633 | ||
1634 | if ( m_hScrollBar ) | |
1635 | { | |
1636 | bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded(); | |
1637 | ||
1638 | if ( m_hScrollBar->IsShown() != showHScrollBar ) | |
1639 | { | |
1640 | m_hScrollBar->Show( showHScrollBar ); | |
1641 | triggerSizeEvent = true; | |
1642 | } | |
1643 | } | |
1644 | ||
1645 | if ( m_vScrollBar) | |
1646 | { | |
1647 | bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded(); | |
1648 | ||
1649 | if ( m_vScrollBar->IsShown() != showVScrollBar ) | |
1650 | { | |
1651 | m_vScrollBar->Show( showVScrollBar ) ; | |
1652 | triggerSizeEvent = true; | |
1653 | } | |
1654 | } | |
1655 | ||
1656 | MacRepositionScrollBars() ; | |
1657 | if ( triggerSizeEvent ) | |
1658 | { | |
1659 | wxSizeEvent event(GetSize(), m_windowId); | |
1660 | event.SetEventObject(this); | |
1661 | HandleWindowEvent(event); | |
1662 | } | |
1663 | #endif | |
1664 | } | |
1665 | ||
1666 | // New function that will replace some of the above. | |
1667 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, | |
1668 | int range, bool refresh) | |
1669 | { | |
1670 | #if wxUSE_SCROLLBAR | |
1671 | // Updating scrollbars when window is being deleted is useless and | |
1672 | // currently results in asserts in client-to-screen coordinates conversion | |
1673 | // code which is used by DoUpdateScrollbarVisibility() so just skip it. | |
1674 | if ( m_isBeingDeleted ) | |
1675 | return; | |
1676 | ||
1677 | if ( orient == wxHORIZONTAL && m_hScrollBar ) | |
1678 | m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
1679 | else if ( orient == wxVERTICAL && m_vScrollBar ) | |
1680 | m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); | |
1681 | ||
1682 | DoUpdateScrollbarVisibility(); | |
1683 | #endif | |
1684 | } | |
1685 | ||
1686 | // Does a physical scroll | |
1687 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) | |
1688 | { | |
1689 | if ( dx == 0 && dy == 0 ) | |
1690 | return ; | |
1691 | ||
1692 | int width , height ; | |
1693 | GetClientSize( &width , &height ) ; | |
1694 | ||
1695 | { | |
1696 | wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ; | |
1697 | if ( rect ) | |
1698 | scrollrect.Intersect( *rect ) ; | |
1699 | // as the native control might be not a 0/0 wx window coordinates, we have to offset | |
1700 | scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ; | |
1701 | ||
1702 | GetPeer()->ScrollRect( &scrollrect, dx, dy ); | |
1703 | } | |
1704 | ||
1705 | wxWindowMac *child; | |
1706 | int x, y, w, h; | |
1707 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
1708 | { | |
1709 | child = node->GetData(); | |
1710 | if (child == NULL) | |
1711 | continue; | |
1712 | ||
1713 | if (child->IsTopLevel()) | |
1714 | continue; | |
1715 | ||
1716 | if ( !IsClientAreaChild(child) ) | |
1717 | continue; | |
1718 | ||
1719 | child->GetPosition( &x, &y ); | |
1720 | child->GetSize( &w, &h ); | |
1721 | if (rect) | |
1722 | { | |
1723 | wxRect rc( x, y, w, h ); | |
1724 | if (rect->Intersects( rc )) | |
1725 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); | |
1726 | } | |
1727 | else | |
1728 | { | |
1729 | child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE ); | |
1730 | } | |
1731 | } | |
1732 | } | |
1733 | ||
1734 | void wxWindowMac::MacOnScroll( wxScrollEvent &event ) | |
1735 | { | |
1736 | #if wxUSE_SCROLLBAR | |
1737 | if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) | |
1738 | { | |
1739 | wxScrollWinEvent wevent; | |
1740 | wevent.SetPosition(event.GetPosition()); | |
1741 | wevent.SetOrientation(event.GetOrientation()); | |
1742 | wevent.SetEventObject(this); | |
1743 | ||
1744 | if (event.GetEventType() == wxEVT_SCROLL_TOP) | |
1745 | wevent.SetEventType( wxEVT_SCROLLWIN_TOP ); | |
1746 | else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM) | |
1747 | wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM ); | |
1748 | else if (event.GetEventType() == wxEVT_SCROLL_LINEUP) | |
1749 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP ); | |
1750 | else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN) | |
1751 | wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN ); | |
1752 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP) | |
1753 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP ); | |
1754 | else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN) | |
1755 | wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN ); | |
1756 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK) | |
1757 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK ); | |
1758 | else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) | |
1759 | wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); | |
1760 | ||
1761 | HandleWindowEvent(wevent); | |
1762 | } | |
1763 | #endif | |
1764 | } | |
1765 | ||
1766 | wxWindow *wxWindowBase::DoFindFocus() | |
1767 | { | |
1768 | return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus()); | |
1769 | } | |
1770 | ||
1771 | // Raise the window to the top of the Z order | |
1772 | void wxWindowMac::Raise() | |
1773 | { | |
1774 | GetPeer()->Raise(); | |
1775 | } | |
1776 | ||
1777 | // Lower the window to the bottom of the Z order | |
1778 | void wxWindowMac::Lower() | |
1779 | { | |
1780 | GetPeer()->Lower(); | |
1781 | } | |
1782 | ||
1783 | // static wxWindow *gs_lastWhich = NULL; | |
1784 | ||
1785 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt ) | |
1786 | { | |
1787 | // first trigger a set cursor event | |
1788 | ||
1789 | wxPoint clientorigin = GetClientAreaOrigin() ; | |
1790 | wxSize clientsize = GetClientSize() ; | |
1791 | wxCursor cursor ; | |
1792 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
1793 | { | |
1794 | wxSetCursorEvent event( pt.x , pt.y ); | |
1795 | ||
1796 | bool processedEvtSetCursor = HandleWindowEvent(event); | |
1797 | if ( processedEvtSetCursor && event.HasCursor() ) | |
1798 | { | |
1799 | cursor = event.GetCursor() ; | |
1800 | } | |
1801 | else | |
1802 | { | |
1803 | // the test for processedEvtSetCursor is here to prevent using m_cursor | |
1804 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
1805 | // it - this is a way to say that our cursor shouldn't be used for this | |
1806 | // point | |
1807 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
1808 | cursor = m_cursor ; | |
1809 | ||
1810 | if ( !wxIsBusy() && !GetParent() ) | |
1811 | cursor = *wxSTANDARD_CURSOR ; | |
1812 | } | |
1813 | ||
1814 | if ( cursor.Ok() ) | |
1815 | cursor.MacInstall() ; | |
1816 | } | |
1817 | ||
1818 | return cursor.Ok() ; | |
1819 | } | |
1820 | ||
1821 | wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) ) | |
1822 | { | |
1823 | #if wxUSE_TOOLTIPS | |
1824 | if ( m_tooltip ) | |
1825 | return m_tooltip->GetTip() ; | |
1826 | #endif | |
1827 | ||
1828 | return wxEmptyString ; | |
1829 | } | |
1830 | ||
1831 | void wxWindowMac::ClearBackground() | |
1832 | { | |
1833 | Refresh() ; | |
1834 | Update() ; | |
1835 | } | |
1836 | ||
1837 | void wxWindowMac::Update() | |
1838 | { | |
1839 | wxNonOwnedWindow* top = MacGetTopLevelWindow(); | |
1840 | if (top) | |
1841 | top->Update() ; | |
1842 | } | |
1843 | ||
1844 | wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const | |
1845 | { | |
1846 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1847 | ||
1848 | while ( iter ) | |
1849 | { | |
1850 | if ( iter->IsTopLevel() ) | |
1851 | { | |
1852 | wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow); | |
1853 | if ( toplevel ) | |
1854 | return toplevel; | |
1855 | #if wxUSE_POPUPWIN | |
1856 | wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow); | |
1857 | if ( popupwin ) | |
1858 | return popupwin; | |
1859 | #endif | |
1860 | } | |
1861 | iter = iter->GetParent() ; | |
1862 | } | |
1863 | ||
1864 | return NULL ; | |
1865 | } | |
1866 | ||
1867 | const wxRect& wxWindowMac::MacGetClippedClientRect() const | |
1868 | { | |
1869 | MacUpdateClippedRects() ; | |
1870 | ||
1871 | return m_cachedClippedClientRect ; | |
1872 | } | |
1873 | ||
1874 | const wxRect& wxWindowMac::MacGetClippedRect() const | |
1875 | { | |
1876 | MacUpdateClippedRects() ; | |
1877 | ||
1878 | return m_cachedClippedRect ; | |
1879 | } | |
1880 | ||
1881 | const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const | |
1882 | { | |
1883 | MacUpdateClippedRects() ; | |
1884 | ||
1885 | return m_cachedClippedRectWithOuterStructure ; | |
1886 | } | |
1887 | ||
1888 | const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) | |
1889 | { | |
1890 | static wxRegion emptyrgn ; | |
1891 | ||
1892 | if ( !m_isBeingDeleted && IsShownOnScreen() ) | |
1893 | { | |
1894 | MacUpdateClippedRects() ; | |
1895 | if ( includeOuterStructures ) | |
1896 | return m_cachedClippedRegionWithOuterStructure ; | |
1897 | else | |
1898 | return m_cachedClippedRegion ; | |
1899 | } | |
1900 | else | |
1901 | { | |
1902 | return emptyrgn ; | |
1903 | } | |
1904 | } | |
1905 | ||
1906 | void wxWindowMac::MacUpdateClippedRects() const | |
1907 | { | |
1908 | #if wxOSX_USE_CARBON | |
1909 | if ( m_cachedClippedRectValid ) | |
1910 | return ; | |
1911 | ||
1912 | // includeOuterStructures is true if we try to draw somthing like a focus ring etc. | |
1913 | // also a window dc uses this, in this case we only clip in the hierarchy for hard | |
1914 | // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having | |
1915 | // to add focus borders everywhere | |
1916 | ||
1917 | Rect rIncludingOuterStructures ; | |
1918 | ||
1919 | int tx,ty,tw,th; | |
1920 | ||
1921 | GetPeer()->GetSize( tw, th ); | |
1922 | GetPeer()->GetPosition( tx, ty ); | |
1923 | ||
1924 | Rect r = { ty,tx, ty+th, tx+tw }; | |
1925 | ||
1926 | r.left -= MacGetLeftBorderSize() ; | |
1927 | r.top -= MacGetTopBorderSize() ; | |
1928 | r.bottom += MacGetBottomBorderSize() ; | |
1929 | r.right += MacGetRightBorderSize() ; | |
1930 | ||
1931 | r.right -= r.left ; | |
1932 | r.bottom -= r.top ; | |
1933 | r.left = 0 ; | |
1934 | r.top = 0 ; | |
1935 | ||
1936 | rIncludingOuterStructures = r ; | |
1937 | InsetRect( &rIncludingOuterStructures , -4 , -4 ) ; | |
1938 | ||
1939 | wxRect cl = GetClientRect() ; | |
1940 | Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ; | |
1941 | ||
1942 | int x , y ; | |
1943 | wxSize size ; | |
1944 | const wxWindow* child = (wxWindow*) this ; | |
1945 | const wxWindow* parent = NULL ; | |
1946 | ||
1947 | while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL ) | |
1948 | { | |
1949 | if ( parent->MacIsChildOfClientArea(child) ) | |
1950 | { | |
1951 | size = parent->GetClientSize() ; | |
1952 | wxPoint origin = parent->GetClientAreaOrigin() ; | |
1953 | x = origin.x ; | |
1954 | y = origin.y ; | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | // this will be true for scrollbars, toolbars etc. | |
1959 | size = parent->GetSize() ; | |
1960 | y = parent->MacGetTopBorderSize() ; | |
1961 | x = parent->MacGetLeftBorderSize() ; | |
1962 | size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ; | |
1963 | size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ; | |
1964 | } | |
1965 | ||
1966 | parent->MacWindowToRootWindow( &x, &y ) ; | |
1967 | MacRootWindowToWindow( &x , &y ) ; | |
1968 | ||
1969 | Rect rparent = { y , x , y + size.y , x + size.x } ; | |
1970 | ||
1971 | // the wxwindow and client rects will always be clipped | |
1972 | SectRect( &r , &rparent , &r ) ; | |
1973 | SectRect( &rClient , &rparent , &rClient ) ; | |
1974 | ||
1975 | // the structure only at 'hard' borders | |
1976 | if ( parent->MacClipChildren() || | |
1977 | ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) ) | |
1978 | { | |
1979 | SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ; | |
1980 | } | |
1981 | ||
1982 | child = parent ; | |
1983 | } | |
1984 | ||
1985 | m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ; | |
1986 | m_cachedClippedClientRect = wxRect( rClient.left , rClient.top , | |
1987 | rClient.right - rClient.left , rClient.bottom - rClient.top ) ; | |
1988 | m_cachedClippedRectWithOuterStructure = wxRect( | |
1989 | rIncludingOuterStructures.left , rIncludingOuterStructures.top , | |
1990 | rIncludingOuterStructures.right - rIncludingOuterStructures.left , | |
1991 | rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ; | |
1992 | ||
1993 | m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ; | |
1994 | m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ; | |
1995 | m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ; | |
1996 | ||
1997 | m_cachedClippedRectValid = true ; | |
1998 | #endif | |
1999 | } | |
2000 | ||
2001 | /* | |
2002 | This function must not change the updatergn ! | |
2003 | */ | |
2004 | bool wxWindowMac::MacDoRedraw( long time ) | |
2005 | { | |
2006 | bool handled = false ; | |
2007 | ||
2008 | wxRegion formerUpdateRgn = m_updateRegion; | |
2009 | wxRegion clientUpdateRgn = formerUpdateRgn; | |
2010 | ||
2011 | const wxRect clientRect = GetClientRect(); | |
2012 | ||
2013 | clientUpdateRgn.Intersect(clientRect); | |
2014 | ||
2015 | // first send an erase event to the entire update area | |
2016 | const wxBackgroundStyle bgStyle = GetBackgroundStyle(); | |
2017 | switch ( bgStyle ) | |
2018 | { | |
2019 | case wxBG_STYLE_ERASE: | |
2020 | case wxBG_STYLE_SYSTEM: | |
2021 | case wxBG_STYLE_COLOUR: | |
2022 | { | |
2023 | // for the toplevel window this really is the entire area for | |
2024 | // all the others only their client area, otherwise they might | |
2025 | // be drawing with full alpha and eg put blue into the grow-box | |
2026 | // area of a scrolled window (scroll sample) | |
2027 | wxWindowDC dc(this); | |
2028 | if ( IsTopLevel() ) | |
2029 | dc.SetDeviceClippingRegion(formerUpdateRgn); | |
2030 | else | |
2031 | dc.SetDeviceClippingRegion(clientUpdateRgn); | |
2032 | ||
2033 | if ( bgStyle == wxBG_STYLE_ERASE ) | |
2034 | { | |
2035 | wxEraseEvent eevent( GetId(), &dc ); | |
2036 | eevent.SetEventObject( this ); | |
2037 | if ( ProcessWindowEvent( eevent ) ) | |
2038 | break; | |
2039 | } | |
2040 | ||
2041 | if ( UseBgCol() ) | |
2042 | { | |
2043 | dc.SetBackground(GetBackgroundColour()); | |
2044 | dc.Clear(); | |
2045 | } | |
2046 | } | |
2047 | break; | |
2048 | ||
2049 | case wxBG_STYLE_PAINT: | |
2050 | case wxBG_STYLE_TRANSPARENT: | |
2051 | // nothing to do, user-defined EVT_PAINT handler will overwrite the | |
2052 | // entire window client area | |
2053 | break; | |
2054 | ||
2055 | default: | |
2056 | wxFAIL_MSG( "unsupported background style" ); | |
2057 | } | |
2058 | ||
2059 | // as this is a full window, shouldn't be necessary anymore | |
2060 | // MacPaintGrowBox(); | |
2061 | ||
2062 | // calculate a client-origin version of the update rgn and set | |
2063 | // m_updateRegion to that | |
2064 | clientUpdateRgn.Offset(-clientRect.GetPosition()); | |
2065 | m_updateRegion = clientUpdateRgn ; | |
2066 | ||
2067 | if ( !m_updateRegion.Empty() ) | |
2068 | { | |
2069 | // paint the window itself | |
2070 | ||
2071 | wxPaintEvent event(GetId()); | |
2072 | event.SetTimestamp(time); | |
2073 | event.SetEventObject(this); | |
2074 | handled = HandleWindowEvent(event); | |
2075 | } | |
2076 | ||
2077 | m_updateRegion = formerUpdateRgn; | |
2078 | return handled; | |
2079 | } | |
2080 | ||
2081 | void wxWindowMac::MacPaintChildrenBorders() | |
2082 | { | |
2083 | // now we cannot rely on having its borders drawn by a window itself, as it does not | |
2084 | // get the updateRgn wide enough to always do so, so we do it from the parent | |
2085 | // this would also be the place to draw any custom backgrounds for native controls | |
2086 | // in Composited windowing | |
2087 | wxPoint clientOrigin = GetClientAreaOrigin() ; | |
2088 | ||
2089 | wxWindowMac *child; | |
2090 | int x, y, w, h; | |
2091 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
2092 | { | |
2093 | child = node->GetData(); | |
2094 | if (child == NULL) | |
2095 | continue; | |
2096 | #if wxUSE_SCROLLBAR | |
2097 | if (child == m_vScrollBar) | |
2098 | continue; | |
2099 | if (child == m_hScrollBar) | |
2100 | continue; | |
2101 | if (child == m_growBox) | |
2102 | continue; | |
2103 | #endif | |
2104 | if (child->IsTopLevel()) | |
2105 | continue; | |
2106 | if (!child->IsShown()) | |
2107 | continue; | |
2108 | ||
2109 | // only draw those in the update region (add a safety margin of 10 pixels for shadow effects | |
2110 | ||
2111 | child->GetPosition( &x, &y ); | |
2112 | child->GetSize( &w, &h ); | |
2113 | ||
2114 | if ( m_updateRegion.Contains(clientOrigin.x+x-10, clientOrigin.y+y-10, w+20, h+20) ) | |
2115 | { | |
2116 | // paint custom borders | |
2117 | wxNcPaintEvent eventNc( child->GetId() ); | |
2118 | eventNc.SetEventObject( child ); | |
2119 | if ( !child->HandleWindowEvent( eventNc ) ) | |
2120 | { | |
2121 | child->MacPaintBorders(0, 0) ; | |
2122 | } | |
2123 | } | |
2124 | } | |
2125 | } | |
2126 | ||
2127 | ||
2128 | WXWindow wxWindowMac::MacGetTopLevelWindowRef() const | |
2129 | { | |
2130 | wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); | |
2131 | return tlw ? tlw->GetWXWindow() : NULL ; | |
2132 | } | |
2133 | ||
2134 | bool wxWindowMac::MacHasScrollBarCorner() const | |
2135 | { | |
2136 | #if wxUSE_SCROLLBAR | |
2137 | /* Returns whether the scroll bars in a wxScrolledWindow should be | |
2138 | * shortened. Scroll bars should be shortened if either: | |
2139 | * | |
2140 | * - both scroll bars are visible, or | |
2141 | * | |
2142 | * - there is a resize box in the parent frame's corner and this | |
2143 | * window shares the bottom and right edge with the parent | |
2144 | * frame. | |
2145 | */ | |
2146 | ||
2147 | if ( m_hScrollBar == NULL && m_vScrollBar == NULL ) | |
2148 | return false; | |
2149 | ||
2150 | if ( ( m_hScrollBar && m_hScrollBar->IsShown() ) | |
2151 | && ( m_vScrollBar && m_vScrollBar->IsShown() ) ) | |
2152 | { | |
2153 | // Both scroll bars visible | |
2154 | return true; | |
2155 | } | |
2156 | else | |
2157 | { | |
2158 | wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight(); | |
2159 | ||
2160 | for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() ) | |
2161 | { | |
2162 | const wxFrame *frame = wxDynamicCast( win, wxFrame ) ; | |
2163 | if ( frame ) | |
2164 | { | |
2165 | if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER ) | |
2166 | { | |
2167 | // Parent frame has resize handle | |
2168 | wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight(); | |
2169 | ||
2170 | // Note: allow for some wiggle room here as wxMac's | |
2171 | // window rect calculations seem to be imprecise | |
2172 | if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2 | |
2173 | && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 ) | |
2174 | { | |
2175 | // Parent frame has resize handle and shares | |
2176 | // right bottom corner | |
2177 | return true ; | |
2178 | } | |
2179 | else | |
2180 | { | |
2181 | // Parent frame has resize handle but doesn't | |
2182 | // share right bottom corner | |
2183 | return false ; | |
2184 | } | |
2185 | } | |
2186 | else | |
2187 | { | |
2188 | // Parent frame doesn't have resize handle | |
2189 | return false ; | |
2190 | } | |
2191 | } | |
2192 | } | |
2193 | ||
2194 | // No parent frame found | |
2195 | return false ; | |
2196 | } | |
2197 | #else | |
2198 | return false; | |
2199 | #endif | |
2200 | } | |
2201 | ||
2202 | void wxWindowMac::MacCreateScrollBars( long style ) | |
2203 | { | |
2204 | #if wxUSE_SCROLLBAR | |
2205 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; | |
2206 | ||
2207 | if ( style & ( wxVSCROLL | wxHSCROLL ) ) | |
2208 | { | |
2209 | int scrlsize = MAC_SCROLLBAR_SIZE ; | |
2210 | if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI ) | |
2211 | { | |
2212 | scrlsize = MAC_SMALL_SCROLLBAR_SIZE ; | |
2213 | } | |
2214 | ||
2215 | int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ; | |
2216 | int width, height ; | |
2217 | GetClientSize( &width , &height ) ; | |
2218 | ||
2219 | wxPoint vPoint(width - scrlsize, 0) ; | |
2220 | wxSize vSize(scrlsize, height - adjust) ; | |
2221 | wxPoint hPoint(0, height - scrlsize) ; | |
2222 | wxSize hSize(width - adjust, scrlsize) ; | |
2223 | ||
2224 | // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize) | |
2225 | if ( style & wxVSCROLL ) | |
2226 | { | |
2227 | m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL); | |
2228 | m_vScrollBar->SetMinSize( wxDefaultSize ); | |
2229 | } | |
2230 | ||
2231 | if ( style & wxHSCROLL ) | |
2232 | { | |
2233 | m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL); | |
2234 | m_hScrollBar->SetMinSize( wxDefaultSize ); | |
2235 | } | |
2236 | ||
2237 | wxPoint gPoint(width - scrlsize, height - scrlsize); | |
2238 | wxSize gSize(scrlsize, scrlsize); | |
2239 | m_growBox = new wxBlindPlateWindow((wxWindow *)this, wxID_ANY, gPoint, gSize, 0); | |
2240 | } | |
2241 | ||
2242 | // because the create does not take into account the client area origin | |
2243 | // we might have a real position shift | |
2244 | MacRepositionScrollBars() ; | |
2245 | #endif | |
2246 | } | |
2247 | ||
2248 | bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const | |
2249 | { | |
2250 | bool result = ((child == NULL) | |
2251 | #if wxUSE_SCROLLBAR | |
2252 | || ((child != m_hScrollBar) && (child != m_vScrollBar) && (child != m_growBox)) | |
2253 | #endif | |
2254 | ); | |
2255 | ||
2256 | return result ; | |
2257 | } | |
2258 | ||
2259 | void wxWindowMac::MacRepositionScrollBars() | |
2260 | { | |
2261 | #if wxUSE_SCROLLBAR | |
2262 | if ( !m_hScrollBar && !m_vScrollBar ) | |
2263 | return ; | |
2264 | ||
2265 | int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; | |
2266 | int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ; | |
2267 | ||
2268 | // get real client area | |
2269 | int width, height ; | |
2270 | GetSize( &width , &height ); | |
2271 | ||
2272 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2273 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
2274 | ||
2275 | wxPoint vPoint( width - scrlsize, 0 ) ; | |
2276 | wxSize vSize( scrlsize, height - adjust ) ; | |
2277 | wxPoint hPoint( 0 , height - scrlsize ) ; | |
2278 | wxSize hSize( width - adjust, scrlsize ) ; | |
2279 | ||
2280 | if ( m_vScrollBar ) | |
2281 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE ); | |
2282 | if ( m_hScrollBar ) | |
2283 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE ); | |
2284 | if ( m_growBox ) | |
2285 | { | |
2286 | if ( MacHasScrollBarCorner() ) | |
2287 | { | |
2288 | m_growBox->SetSize( width - scrlsize, height - scrlsize, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING ); | |
2289 | if ( !m_growBox->IsShown() ) | |
2290 | m_growBox->Show(); | |
2291 | } | |
2292 | else | |
2293 | { | |
2294 | if ( m_growBox->IsShown() ) | |
2295 | m_growBox->Hide(); | |
2296 | } | |
2297 | } | |
2298 | #endif | |
2299 | } | |
2300 | ||
2301 | bool wxWindowMac::AcceptsFocus() const | |
2302 | { | |
2303 | if ( GetPeer() == NULL || GetPeer()->IsUserPane() ) | |
2304 | return wxWindowBase::AcceptsFocus(); | |
2305 | else | |
2306 | return GetPeer()->CanFocus(); | |
2307 | } | |
2308 | ||
2309 | void wxWindowMac::MacSuperChangedPosition() | |
2310 | { | |
2311 | // only window-absolute structures have to be moved i.e. controls | |
2312 | ||
2313 | m_cachedClippedRectValid = false ; | |
2314 | ||
2315 | wxWindowMac *child; | |
2316 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2317 | while ( node ) | |
2318 | { | |
2319 | child = node->GetData(); | |
2320 | child->MacSuperChangedPosition() ; | |
2321 | ||
2322 | node = node->GetNext(); | |
2323 | } | |
2324 | } | |
2325 | ||
2326 | void wxWindowMac::MacTopLevelWindowChangedPosition() | |
2327 | { | |
2328 | // only screen-absolute structures have to be moved i.e. glcanvas | |
2329 | ||
2330 | wxWindowMac *child; | |
2331 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
2332 | while ( node ) | |
2333 | { | |
2334 | child = node->GetData(); | |
2335 | child->MacTopLevelWindowChangedPosition() ; | |
2336 | ||
2337 | node = node->GetNext(); | |
2338 | } | |
2339 | } | |
2340 | ||
2341 | long wxWindowMac::MacGetWXBorderSize() const | |
2342 | { | |
2343 | if ( IsTopLevel() ) | |
2344 | return 0 ; | |
2345 | ||
2346 | SInt32 border = 0 ; | |
2347 | ||
2348 | if ( GetPeer() && GetPeer()->NeedsFrame() ) | |
2349 | { | |
2350 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) | |
2351 | { | |
2352 | #if wxOSX_USE_COCOA_OR_CARBON | |
2353 | // this metric is only the 'outset' outside the simple frame rect | |
2354 | GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; | |
2355 | border += 1; | |
2356 | #else | |
2357 | border += 2; | |
2358 | #endif | |
2359 | } | |
2360 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2361 | { | |
2362 | #if wxOSX_USE_COCOA_OR_CARBON | |
2363 | // this metric is only the 'outset' outside the simple frame rect | |
2364 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
2365 | border += 1; | |
2366 | #else | |
2367 | border += 1; | |
2368 | #endif | |
2369 | } | |
2370 | } | |
2371 | ||
2372 | return border ; | |
2373 | } | |
2374 | ||
2375 | long wxWindowMac::MacGetLeftBorderSize() const | |
2376 | { | |
2377 | // the wx borders are all symmetric in mac themes | |
2378 | long border = MacGetWXBorderSize() ; | |
2379 | ||
2380 | if ( GetPeer() ) | |
2381 | { | |
2382 | int left, top, right, bottom; | |
2383 | GetPeer()->GetLayoutInset( left, top, right, bottom ); | |
2384 | border -= left; | |
2385 | } | |
2386 | ||
2387 | return border; | |
2388 | } | |
2389 | ||
2390 | ||
2391 | long wxWindowMac::MacGetRightBorderSize() const | |
2392 | { | |
2393 | // the wx borders are all symmetric in mac themes | |
2394 | long border = MacGetWXBorderSize() ; | |
2395 | ||
2396 | if ( GetPeer() ) | |
2397 | { | |
2398 | int left, top, right, bottom; | |
2399 | GetPeer()->GetLayoutInset( left, top, right, bottom ); | |
2400 | border -= right; | |
2401 | } | |
2402 | ||
2403 | return border; | |
2404 | } | |
2405 | ||
2406 | long wxWindowMac::MacGetTopBorderSize() const | |
2407 | { | |
2408 | // the wx borders are all symmetric in mac themes | |
2409 | long border = MacGetWXBorderSize() ; | |
2410 | ||
2411 | if ( GetPeer() ) | |
2412 | { | |
2413 | int left, top, right, bottom; | |
2414 | GetPeer()->GetLayoutInset( left, top, right, bottom ); | |
2415 | border -= top; | |
2416 | } | |
2417 | ||
2418 | return border; | |
2419 | } | |
2420 | ||
2421 | long wxWindowMac::MacGetBottomBorderSize() const | |
2422 | { | |
2423 | // the wx borders are all symmetric in mac themes | |
2424 | long border = MacGetWXBorderSize() ; | |
2425 | ||
2426 | if ( GetPeer() ) | |
2427 | { | |
2428 | int left, top, right, bottom; | |
2429 | GetPeer()->GetLayoutInset( left, top, right, bottom ); | |
2430 | border -= bottom; | |
2431 | } | |
2432 | ||
2433 | return border; | |
2434 | } | |
2435 | ||
2436 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) | |
2437 | { | |
2438 | return style & ~wxBORDER_MASK ; | |
2439 | } | |
2440 | ||
2441 | // Find the wxWindowMac at the current mouse position, returning the mouse | |
2442 | // position. | |
2443 | wxWindow * wxFindWindowAtPointer( wxPoint& pt ) | |
2444 | { | |
2445 | pt = wxGetMousePosition(); | |
2446 | wxWindowMac* found = wxFindWindowAtPoint(pt); | |
2447 | ||
2448 | return (wxWindow*) found; | |
2449 | } | |
2450 | ||
2451 | // Get the current mouse position. | |
2452 | wxPoint wxGetMousePosition() | |
2453 | { | |
2454 | int x, y; | |
2455 | ||
2456 | wxGetMousePosition( &x, &y ); | |
2457 | ||
2458 | return wxPoint(x, y); | |
2459 | } | |
2460 | ||
2461 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) | |
2462 | { | |
2463 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
2464 | { | |
2465 | // copied from wxGTK : CS | |
2466 | // VZ: shouldn't we move this to base class then? | |
2467 | ||
2468 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN | |
2469 | // except that: | |
2470 | // | |
2471 | // (a) it's a command event and so is propagated to the parent | |
2472 | // (b) under MSW it can be generated from kbd too | |
2473 | // (c) it uses screen coords (because of (a)) | |
2474 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
2475 | this->GetId(), | |
2476 | this->ClientToScreen(event.GetPosition())); | |
2477 | evtCtx.SetEventObject(this); | |
2478 | if ( ! HandleWindowEvent(evtCtx) ) | |
2479 | event.Skip() ; | |
2480 | } | |
2481 | else | |
2482 | { | |
2483 | event.Skip() ; | |
2484 | } | |
2485 | } | |
2486 | ||
2487 | void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) ) | |
2488 | { | |
2489 | } | |
2490 | ||
2491 | Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) | |
2492 | { | |
2493 | int x, y, w, h ; | |
2494 | ||
2495 | window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ; | |
2496 | Rect bounds = { y, x, y + h, x + w }; | |
2497 | ||
2498 | return bounds ; | |
2499 | } | |
2500 | ||
2501 | bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec) ) | |
2502 | { | |
2503 | return false; | |
2504 | } | |
2505 | ||
2506 | wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event ) | |
2507 | { | |
2508 | #if wxOSX_USE_COCOA_OR_CARBON | |
2509 | if ( OSXHandleClicked( GetEventTime((EventRef)event) ) ) | |
2510 | return noErr; | |
2511 | ||
2512 | return eventNotHandledErr ; | |
2513 | #else | |
2514 | return 0; | |
2515 | #endif | |
2516 | } | |
2517 | ||
2518 | bool wxWindowMac::Reparent(wxWindowBase *newParentBase) | |
2519 | { | |
2520 | wxWindowMac *newParent = (wxWindowMac *)newParentBase; | |
2521 | if ( !wxWindowBase::Reparent(newParent) ) | |
2522 | return false; | |
2523 | ||
2524 | GetPeer()->RemoveFromParent(); | |
2525 | GetPeer()->Embed( GetParent()->GetPeer() ); | |
2526 | ||
2527 | MacChildAdded(); | |
2528 | return true; | |
2529 | } | |
2530 | ||
2531 | bool wxWindowMac::SetTransparent(wxByte alpha) | |
2532 | { | |
2533 | SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); | |
2534 | ||
2535 | if ( alpha != m_macAlpha ) | |
2536 | { | |
2537 | m_macAlpha = alpha ; | |
2538 | Refresh() ; | |
2539 | } | |
2540 | return true ; | |
2541 | } | |
2542 | ||
2543 | ||
2544 | bool wxWindowMac::CanSetTransparent() | |
2545 | { | |
2546 | return true ; | |
2547 | } | |
2548 | ||
2549 | wxByte wxWindowMac::GetTransparent() const | |
2550 | { | |
2551 | return m_macAlpha ; | |
2552 | } | |
2553 | ||
2554 | bool wxWindowMac::IsShownOnScreen() const | |
2555 | { | |
2556 | if ( GetPeer() && GetPeer()->IsOk() ) | |
2557 | { | |
2558 | bool peerVis = GetPeer()->IsVisible(); | |
2559 | bool wxVis = wxWindowBase::IsShownOnScreen(); | |
2560 | if( peerVis != wxVis ) | |
2561 | { | |
2562 | // CS : put a breakpoint here to investigate differences | |
2563 | // between native an wx visibilities | |
2564 | // the only place where I've encountered them until now | |
2565 | // are the hiding/showing sequences where the vis-changed event is | |
2566 | // first sent to the innermost control, while wx does things | |
2567 | // from the outmost control | |
2568 | wxVis = wxWindowBase::IsShownOnScreen(); | |
2569 | return wxVis; | |
2570 | } | |
2571 | ||
2572 | return GetPeer()->IsVisible(); | |
2573 | } | |
2574 | return wxWindowBase::IsShownOnScreen(); | |
2575 | } | |
2576 | ||
2577 | bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) | |
2578 | { | |
2579 | bool handled = false; | |
2580 | ||
2581 | // moved the ordinary key event sending AFTER the accel evaluation | |
2582 | ||
2583 | #if wxUSE_ACCEL | |
2584 | if ( !handled && event.GetEventType() == wxEVT_KEY_DOWN) | |
2585 | { | |
2586 | wxWindow *ancestor = this; | |
2587 | while (ancestor) | |
2588 | { | |
2589 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
2590 | if (command != -1) | |
2591 | { | |
2592 | wxEvtHandler * const handler = ancestor->GetEventHandler(); | |
2593 | ||
2594 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
2595 | handled = handler->ProcessEvent( command_event ); | |
2596 | ||
2597 | if ( !handled ) | |
2598 | { | |
2599 | // accelerators can also be used with buttons, try them too | |
2600 | command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED); | |
2601 | handled = handler->ProcessEvent( command_event ); | |
2602 | } | |
2603 | ||
2604 | break; | |
2605 | } | |
2606 | ||
2607 | if (ancestor->IsTopLevel()) | |
2608 | break; | |
2609 | ||
2610 | ancestor = ancestor->GetParent(); | |
2611 | } | |
2612 | } | |
2613 | #endif // wxUSE_ACCEL | |
2614 | ||
2615 | if ( !handled ) | |
2616 | { | |
2617 | handled = HandleWindowEvent( event ) ; | |
2618 | if ( handled && event.GetSkipped() ) | |
2619 | handled = false ; | |
2620 | } | |
2621 | ||
2622 | return handled ; | |
2623 | } | |
2624 | ||
2625 | // | |
2626 | // wxWidgetImpl | |
2627 | // | |
2628 | ||
2629 | WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap); | |
2630 | ||
2631 | static MacControlMap wxWinMacControlList; | |
2632 | ||
2633 | wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl ) | |
2634 | { | |
2635 | wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl ); | |
2636 | if ( impl ) | |
2637 | return impl->GetWXPeer(); | |
2638 | ||
2639 | return NULL; | |
2640 | } | |
2641 | ||
2642 | wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl ) | |
2643 | { | |
2644 | MacControlMap::iterator node = wxWinMacControlList.find(inControl); | |
2645 | ||
2646 | return (node == wxWinMacControlList.end()) ? NULL : node->second; | |
2647 | } | |
2648 | ||
2649 | void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl) | |
2650 | { | |
2651 | // adding NULL ControlRef is (first) surely a result of an error and | |
2652 | // (secondly) breaks native event processing | |
2653 | wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") ); | |
2654 | ||
2655 | wxWinMacControlList[inControl] = impl; | |
2656 | } | |
2657 | ||
2658 | void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl) | |
2659 | { | |
2660 | // iterate over all the elements in the class | |
2661 | // is the iterator stable ? as we might have two associations pointing to the same wxWindow | |
2662 | // we should go on... | |
2663 | ||
2664 | bool found = true ; | |
2665 | while ( found ) | |
2666 | { | |
2667 | found = false ; | |
2668 | MacControlMap::iterator it; | |
2669 | for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it ) | |
2670 | { | |
2671 | if ( it->second == impl ) | |
2672 | { | |
2673 | wxWinMacControlList.erase(it); | |
2674 | found = true ; | |
2675 | break; | |
2676 | } | |
2677 | } | |
2678 | } | |
2679 | } | |
2680 | ||
2681 | IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject ) | |
2682 | ||
2683 | wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane ) | |
2684 | { | |
2685 | Init(); | |
2686 | m_isRootControl = isRootControl; | |
2687 | m_isUserPane = isUserPane; | |
2688 | m_wxPeer = peer; | |
2689 | m_shouldSendEvents = true; | |
2690 | } | |
2691 | ||
2692 | wxWidgetImpl::wxWidgetImpl() | |
2693 | { | |
2694 | Init(); | |
2695 | } | |
2696 | ||
2697 | wxWidgetImpl::~wxWidgetImpl() | |
2698 | { | |
2699 | } | |
2700 | ||
2701 | void wxWidgetImpl::Init() | |
2702 | { | |
2703 | m_isRootControl = false; | |
2704 | m_wxPeer = NULL; | |
2705 | m_needsFocusRect = false; | |
2706 | m_needsFrame = true; | |
2707 | } | |
2708 | ||
2709 | void wxWidgetImpl::SetNeedsFocusRect( bool needs ) | |
2710 | { | |
2711 | m_needsFocusRect = needs; | |
2712 | } | |
2713 | ||
2714 | bool wxWidgetImpl::NeedsFocusRect() const | |
2715 | { | |
2716 | return m_needsFocusRect; | |
2717 | } | |
2718 | ||
2719 | void wxWidgetImpl::SetNeedsFrame( bool needs ) | |
2720 | { | |
2721 | m_needsFrame = needs; | |
2722 | } | |
2723 | ||
2724 | bool wxWidgetImpl::NeedsFrame() const | |
2725 | { | |
2726 | return m_needsFrame; | |
2727 | } |