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