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