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