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