]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
e766c8a9 | 3 | // Purpose: wxWindowMac |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
6264b550 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/menu.h" | |
5fde6fcc | 18 | #include "wx/window.h" |
e9576ca5 SC |
19 | #include "wx/dc.h" |
20 | #include "wx/dcclient.h" | |
14c9cbdb | 21 | #include "wx/utils.h" |
e9576ca5 SC |
22 | #include "wx/app.h" |
23 | #include "wx/panel.h" | |
24 | #include "wx/layout.h" | |
25 | #include "wx/dialog.h" | |
26 | #include "wx/listbox.h" | |
03e11df5 GD |
27 | #include "wx/scrolbar.h" |
28 | #include "wx/statbox.h" | |
e9576ca5 SC |
29 | #include "wx/button.h" |
30 | #include "wx/settings.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/frame.h" | |
519cb848 SC |
33 | #include "wx/notebook.h" |
34 | #include "wx/tabctrl.h" | |
2f1ae414 | 35 | #include "wx/tooltip.h" |
c809f3be | 36 | #include "wx/statusbr.h" |
e9576ca5 | 37 | #include "wx/menuitem.h" |
4ac219f6 | 38 | #include "wx/spinctrl.h" |
e9576ca5 | 39 | #include "wx/log.h" |
467e3168 | 40 | #include "wx/geometry.h" |
e9576ca5 | 41 | |
7c551d95 SC |
42 | #if wxUSE_CARET |
43 | #include "wx/caret.h" | |
44 | #endif // wxUSE_CARET | |
45 | ||
519cb848 SC |
46 | #define wxWINDOW_HSCROLL 5998 |
47 | #define wxWINDOW_VSCROLL 5997 | |
48 | #define MAC_SCROLLBAR_SIZE 16 | |
49 | ||
d497dca4 | 50 | #include "wx/mac/uma.h" |
66a09d47 SC |
51 | #ifndef __DARWIN__ |
52 | #include <Windows.h> | |
53 | #include <ToolUtils.h> | |
54 | #endif | |
519cb848 | 55 | |
e9576ca5 SC |
56 | #if wxUSE_DRAG_AND_DROP |
57 | #include "wx/dnd.h" | |
58 | #endif | |
59 | ||
60 | #include <string.h> | |
61 | ||
62 | extern wxList wxPendingDelete; | |
e766c8a9 | 63 | wxWindowMac* gFocusWindow = NULL ; |
e9576ca5 | 64 | |
fc0daf84 SC |
65 | #ifdef __WXUNIVERSAL__ |
66 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) | |
67 | #else // __WXMAC__ | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
69 | #endif // __WXUNIVERSAL__/__WXMAC__ | |
70 | ||
2f1ae414 | 71 | #if !USE_SHARED_LIBRARY |
fc0daf84 SC |
72 | |
73 | BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) | |
1c310985 | 74 | EVT_NC_PAINT(wxWindowMac::OnNcPaint) |
e766c8a9 SC |
75 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) |
76 | EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) | |
77 | EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) | |
78 | EVT_IDLE(wxWindowMac::OnIdle) | |
79 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) | |
8950f7cc | 80 | EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) |
e9576ca5 SC |
81 | END_EVENT_TABLE() |
82 | ||
2f1ae414 | 83 | #endif |
e9576ca5 | 84 | |
94abc21f SC |
85 | #define wxMAC_DEBUG_REDRAW 0 |
86 | #ifndef wxMAC_DEBUG_REDRAW | |
87 | #define wxMAC_DEBUG_REDRAW 0 | |
88 | #endif | |
89 | ||
1c310985 | 90 | #define wxMAC_USE_THEME_BORDER 0 |
e9576ca5 | 91 | |
e7549107 SC |
92 | |
93 | // =========================================================================== | |
94 | // implementation | |
95 | // =========================================================================== | |
96 | ||
e7549107 SC |
97 | |
98 | // ---------------------------------------------------------------------------- | |
99 | // constructors and such | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
e766c8a9 | 102 | void wxWindowMac::Init() |
519cb848 | 103 | { |
e7549107 SC |
104 | // generic |
105 | InitBase(); | |
106 | ||
e7549107 SC |
107 | m_backgroundTransparent = FALSE; |
108 | ||
109 | // as all windows are created with WS_VISIBLE style... | |
110 | m_isShown = TRUE; | |
111 | ||
6264b550 | 112 | m_x = 0; |
14c9cbdb | 113 | m_y = 0 ; |
6264b550 RR |
114 | m_width = 0 ; |
115 | m_height = 0 ; | |
e7549107 | 116 | |
6264b550 RR |
117 | m_hScrollBar = NULL ; |
118 | m_vScrollBar = NULL ; | |
d84afea9 GD |
119 | |
120 | m_label = wxEmptyString; | |
e9576ca5 SC |
121 | } |
122 | ||
123 | // Destructor | |
e766c8a9 | 124 | wxWindowMac::~wxWindowMac() |
e9576ca5 | 125 | { |
7de59551 RD |
126 | SendDestroyEvent(); |
127 | ||
fdaf613a SC |
128 | // deleting a window while it is shown invalidates the region |
129 | if ( IsShown() ) { | |
e766c8a9 | 130 | wxWindowMac* iter = this ; |
fdaf613a | 131 | while( iter ) { |
1c310985 | 132 | if ( iter->IsTopLevel() ) |
fdaf613a SC |
133 | { |
134 | Refresh() ; | |
135 | break ; | |
136 | } | |
137 | iter = iter->GetParent() ; | |
14c9cbdb | 138 | |
fdaf613a SC |
139 | } |
140 | } | |
14c9cbdb | 141 | |
d4380aaf SC |
142 | #ifndef __WXUNIVERSAL__ |
143 | // VS: make sure there's no wxFrame with last focus set to us: | |
144 | for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) | |
145 | { | |
146 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
147 | if ( frame ) | |
148 | { | |
149 | if ( frame->GetLastFocus() == this ) | |
150 | { | |
151 | frame->SetLastFocus((wxWindow*)NULL); | |
152 | } | |
153 | break; | |
154 | } | |
155 | } | |
156 | #endif // __WXUNIVERSAL__ | |
157 | ||
6264b550 RR |
158 | if ( s_lastMouseWindow == this ) |
159 | { | |
160 | s_lastMouseWindow = NULL ; | |
161 | } | |
7de59551 | 162 | |
fd76aa8d SC |
163 | wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; |
164 | if ( frame ) | |
165 | { | |
e40298d5 JS |
166 | if ( frame->GetLastFocus() == this ) |
167 | frame->SetLastFocus( NULL ) ; | |
fd76aa8d | 168 | } |
e7549107 SC |
169 | |
170 | if ( gFocusWindow == this ) | |
e9576ca5 | 171 | { |
6264b550 | 172 | gFocusWindow = NULL ; |
e9576ca5 | 173 | } |
519cb848 | 174 | |
42683dfb SC |
175 | // CS: copied from MSW : |
176 | // VS: destroy children first and _then_ detach *this from its parent. | |
177 | // If we'd do it the other way around, children wouldn't be able | |
178 | // find their parent frame (see above). | |
179 | DestroyChildren(); | |
180 | ||
e7549107 SC |
181 | if ( m_parent ) |
182 | m_parent->RemoveChild(this); | |
e9576ca5 | 183 | |
42683dfb SC |
184 | // delete our drop target if we've got one |
185 | #if wxUSE_DRAG_AND_DROP | |
186 | if ( m_dropTarget != NULL ) | |
187 | { | |
188 | delete m_dropTarget; | |
189 | m_dropTarget = NULL; | |
190 | } | |
191 | #endif // wxUSE_DRAG_AND_DROP | |
e9576ca5 SC |
192 | } |
193 | ||
194 | // Constructor | |
e766c8a9 | 195 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, |
e9576ca5 SC |
196 | const wxPoint& pos, |
197 | const wxSize& size, | |
198 | long style, | |
199 | const wxString& name) | |
200 | { | |
e766c8a9 | 201 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 202 | |
01fbf5d7 SC |
203 | #if wxUSE_STATBOX |
204 | // wxGTK doesn't allow to create controls with static box as the parent so | |
205 | // this will result in a crash when the program is ported to wxGTK - warn | |
206 | // about it | |
207 | // | |
208 | // the correct solution is to create the controls as siblings of the | |
209 | // static box | |
210 | wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox), | |
211 | _T("wxStaticBox can't be used as a window parent!") ); | |
212 | #endif // wxUSE_STATBOX | |
213 | ||
e7549107 | 214 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
e9576ca5 SC |
215 | return FALSE; |
216 | ||
e7549107 | 217 | parent->AddChild(this); |
e9576ca5 | 218 | |
6264b550 RR |
219 | m_x = (int)pos.x; |
220 | m_y = (int)pos.y; | |
221 | AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); | |
222 | m_width = WidthDefault( size.x ); | |
223 | m_height = HeightDefault( size.y ) ; | |
e766c8a9 | 224 | #ifndef __WXUNIVERSAL__ |
14c9cbdb RD |
225 | // Don't give scrollbars to wxControls unless they ask for them |
226 | if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || | |
227 | (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL))) | |
6264b550 RR |
228 | { |
229 | MacCreateScrollBars( style ) ; | |
230 | } | |
e766c8a9 | 231 | #endif |
e9576ca5 SC |
232 | return TRUE; |
233 | } | |
234 | ||
e766c8a9 | 235 | void wxWindowMac::SetFocus() |
e9576ca5 | 236 | { |
6264b550 RR |
237 | if ( gFocusWindow == this ) |
238 | return ; | |
14c9cbdb | 239 | |
6264b550 RR |
240 | if ( AcceptsFocus() ) |
241 | { | |
242 | if (gFocusWindow ) | |
243 | { | |
eed1be65 | 244 | #if wxUSE_CARET |
6264b550 RR |
245 | // Deal with caret |
246 | if ( gFocusWindow->m_caret ) | |
247 | { | |
248 | gFocusWindow->m_caret->OnKillFocus(); | |
249 | } | |
eed1be65 JS |
250 | #endif // wxUSE_CARET |
251 | #ifndef __WXUNIVERSAL__ | |
6264b550 RR |
252 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; |
253 | if ( control && control->GetMacControl() ) | |
254 | { | |
76a5e5d2 | 255 | UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ; |
6264b550 RR |
256 | control->MacRedrawControl() ; |
257 | } | |
eed1be65 JS |
258 | #endif |
259 | // Without testing the window id, for some reason | |
260 | // a kill focus event can still be sent to | |
261 | // the control just being focussed. | |
262 | int thisId = this->m_windowId; | |
263 | int gFocusWindowId = gFocusWindow->m_windowId; | |
264 | if (gFocusWindowId != thisId) | |
265 | { | |
266 | wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); | |
267 | event.SetEventObject(gFocusWindow); | |
268 | gFocusWindow->GetEventHandler()->ProcessEvent(event) ; | |
269 | } | |
6264b550 RR |
270 | } |
271 | gFocusWindow = this ; | |
272 | { | |
273 | #if wxUSE_CARET | |
274 | // Deal with caret | |
275 | if ( m_caret ) | |
276 | { | |
277 | m_caret->OnSetFocus(); | |
278 | } | |
279 | #endif // wxUSE_CARET | |
280 | // panel wants to track the window which was the last to have focus in it | |
c1fb8167 | 281 | wxChildFocusEvent eventFocus(this); |
1c310985 | 282 | GetEventHandler()->ProcessEvent(eventFocus); |
c1fb8167 | 283 | |
e766c8a9 | 284 | #ifndef __WXUNIVERSAL__ |
6264b550 RR |
285 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; |
286 | if ( control && control->GetMacControl() ) | |
287 | { | |
f6c29ee0 | 288 | UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ; |
6264b550 | 289 | } |
e766c8a9 | 290 | #endif |
6264b550 RR |
291 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
292 | event.SetEventObject(this); | |
293 | GetEventHandler()->ProcessEvent(event) ; | |
294 | } | |
295 | } | |
e9576ca5 SC |
296 | } |
297 | ||
e766c8a9 | 298 | bool wxWindowMac::Enable(bool enable) |
e9576ca5 | 299 | { |
e7549107 SC |
300 | if ( !wxWindowBase::Enable(enable) ) |
301 | return FALSE; | |
e7549107 | 302 | |
1c310985 | 303 | MacSuperEnabled( enable ) ; |
e7549107 SC |
304 | |
305 | return TRUE; | |
e9576ca5 SC |
306 | } |
307 | ||
4116c221 | 308 | void wxWindowMac::DoCaptureMouse() |
e9576ca5 | 309 | { |
519cb848 | 310 | wxTheApp->s_captureWindow = this ; |
e9576ca5 SC |
311 | } |
312 | ||
90b959ae SC |
313 | wxWindow* wxWindowBase::GetCapture() |
314 | { | |
315 | return wxTheApp->s_captureWindow ; | |
316 | } | |
317 | ||
4116c221 | 318 | void wxWindowMac::DoReleaseMouse() |
e9576ca5 | 319 | { |
519cb848 | 320 | wxTheApp->s_captureWindow = NULL ; |
e9576ca5 SC |
321 | } |
322 | ||
e9576ca5 SC |
323 | #if wxUSE_DRAG_AND_DROP |
324 | ||
e766c8a9 | 325 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 | 326 | { |
e40298d5 JS |
327 | if ( m_dropTarget != 0 ) { |
328 | delete m_dropTarget; | |
329 | } | |
330 | ||
331 | m_dropTarget = pDropTarget; | |
332 | if ( m_dropTarget != 0 ) | |
333 | { | |
334 | // TODO | |
335 | } | |
e9576ca5 SC |
336 | } |
337 | ||
338 | #endif | |
339 | ||
340 | // Old style file-manager drag&drop | |
e766c8a9 | 341 | void wxWindowMac::DragAcceptFiles(bool accept) |
e9576ca5 SC |
342 | { |
343 | // TODO | |
344 | } | |
345 | ||
346 | // Get total size | |
e766c8a9 | 347 | void wxWindowMac::DoGetSize(int *x, int *y) const |
e9576ca5 | 348 | { |
9453cf2b SC |
349 | if(x) *x = m_width ; |
350 | if(y) *y = m_height ; | |
e9576ca5 SC |
351 | } |
352 | ||
e766c8a9 | 353 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
e9576ca5 | 354 | { |
9453cf2b | 355 | int xx,yy; |
14c9cbdb | 356 | |
9453cf2b SC |
357 | xx = m_x ; |
358 | yy = m_y ; | |
1c310985 | 359 | if ( !IsTopLevel() && GetParent()) |
519cb848 SC |
360 | { |
361 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
9453cf2b SC |
362 | xx -= pt.x; |
363 | yy -= pt.y; | |
519cb848 | 364 | } |
9453cf2b SC |
365 | if(x) *x = xx; |
366 | if(y) *y = yy; | |
e9576ca5 SC |
367 | } |
368 | ||
e766c8a9 SC |
369 | #if wxUSE_MENUS |
370 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
51abe921 | 371 | { |
6264b550 | 372 | menu->SetInvokingWindow(this); |
51abe921 | 373 | menu->UpdateUI(); |
6264b550 | 374 | ClientToScreen( &x , &y ) ; |
51abe921 | 375 | |
d46342af | 376 | menu->MacBeforeDisplay( true ) ; |
76a5e5d2 | 377 | long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; |
2b5f62a0 VZ |
378 | if ( HiWord(menuResult) != 0 ) |
379 | { | |
380 | MenuCommand id ; | |
381 | GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; | |
8950f7cc SC |
382 | wxMenuItem* item = NULL ; |
383 | wxMenu* realmenu ; | |
384 | item = menu->FindItem(id, &realmenu) ; | |
385 | if (item->IsCheckable()) | |
386 | { | |
387 | item->Check( !item->IsChecked() ) ; | |
388 | } | |
389 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
2b5f62a0 | 390 | } |
d46342af | 391 | menu->MacAfterDisplay( true ) ; |
8950f7cc | 392 | |
6264b550 | 393 | menu->SetInvokingWindow(NULL); |
51abe921 SC |
394 | |
395 | return TRUE; | |
396 | } | |
e766c8a9 | 397 | #endif |
51abe921 | 398 | |
e766c8a9 | 399 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 400 | { |
76a5e5d2 | 401 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
519cb848 | 402 | |
6264b550 | 403 | Point localwhere = {0,0} ; |
9453cf2b SC |
404 | |
405 | if(x) localwhere.h = * x ; | |
406 | if(y) localwhere.v = * y ; | |
519cb848 | 407 | |
14c9cbdb | 408 | GrafPtr port ; |
6264b550 RR |
409 | ::GetPort( &port ) ; |
410 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
411 | ::GlobalToLocal( &localwhere ) ; | |
412 | ::SetPort( port ) ; | |
519cb848 | 413 | |
9453cf2b SC |
414 | if(x) *x = localwhere.h ; |
415 | if(y) *y = localwhere.v ; | |
e40298d5 | 416 | |
2078220e SC |
417 | MacRootWindowToWindow( x , y ) ; |
418 | if ( x ) | |
e40298d5 | 419 | *x -= MacGetLeftBorderSize() ; |
2078220e | 420 | if ( y ) |
e40298d5 | 421 | *y -= MacGetTopBorderSize() ; |
e9576ca5 SC |
422 | } |
423 | ||
e766c8a9 | 424 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 425 | { |
76a5e5d2 | 426 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
14c9cbdb | 427 | |
2078220e | 428 | if ( x ) |
e40298d5 | 429 | *x += MacGetLeftBorderSize() ; |
2078220e | 430 | if ( y ) |
e40298d5 | 431 | *y += MacGetTopBorderSize() ; |
14c9cbdb | 432 | |
2078220e | 433 | MacWindowToRootWindow( x , y ) ; |
14c9cbdb | 434 | |
6264b550 | 435 | Point localwhere = { 0,0 }; |
9453cf2b SC |
436 | if(x) localwhere.h = * x ; |
437 | if(y) localwhere.v = * y ; | |
14c9cbdb RD |
438 | |
439 | GrafPtr port ; | |
6264b550 RR |
440 | ::GetPort( &port ) ; |
441 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
7d9d1fd7 | 442 | |
6264b550 RR |
443 | ::LocalToGlobal( &localwhere ) ; |
444 | ::SetPort( port ) ; | |
9453cf2b SC |
445 | if(x) *x = localwhere.h ; |
446 | if(y) *y = localwhere.v ; | |
519cb848 SC |
447 | } |
448 | ||
e766c8a9 | 449 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 450 | { |
1c310985 SC |
451 | wxPoint origin = GetClientAreaOrigin() ; |
452 | if(x) *x += origin.x ; | |
453 | if(y) *y += origin.y ; | |
14c9cbdb | 454 | |
1c310985 SC |
455 | MacWindowToRootWindow( x , y ) ; |
456 | } | |
457 | ||
458 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const | |
459 | { | |
460 | wxPoint origin = GetClientAreaOrigin() ; | |
461 | MacRootWindowToWindow( x , y ) ; | |
462 | if(x) *x -= origin.x ; | |
463 | if(y) *y -= origin.y ; | |
464 | } | |
465 | ||
466 | void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const | |
467 | { | |
468 | if ( !IsTopLevel() ) | |
6264b550 | 469 | { |
1c310985 SC |
470 | if(x) *x += m_x ; |
471 | if(y) *y += m_y ; | |
472 | GetParent()->MacWindowToRootWindow( x , y ) ; | |
6264b550 | 473 | } |
519cb848 SC |
474 | } |
475 | ||
1c310985 | 476 | void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const |
519cb848 | 477 | { |
1c310985 | 478 | if ( !IsTopLevel() ) |
6264b550 | 479 | { |
1c310985 SC |
480 | if(x) *x -= m_x ; |
481 | if(y) *y -= m_y ; | |
482 | GetParent()->MacRootWindowToWindow( x , y ) ; | |
6264b550 | 483 | } |
e9576ca5 SC |
484 | } |
485 | ||
e766c8a9 | 486 | bool wxWindowMac::SetCursor(const wxCursor& cursor) |
e9576ca5 | 487 | { |
6618870d | 488 | if (m_cursor == cursor) |
e40298d5 JS |
489 | return FALSE; |
490 | ||
6618870d SC |
491 | if (wxNullCursor == cursor) |
492 | { | |
e40298d5 JS |
493 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) |
494 | return FALSE ; | |
6618870d SC |
495 | } |
496 | else | |
497 | { | |
e40298d5 JS |
498 | if ( ! wxWindowBase::SetCursor( cursor ) ) |
499 | return FALSE ; | |
500 | } | |
501 | ||
502 | wxASSERT_MSG( m_cursor.Ok(), | |
503 | wxT("cursor must be valid after call to the base version")); | |
504 | ||
505 | Point pt ; | |
506 | wxWindowMac *mouseWin ; | |
507 | GetMouse( &pt ) ; | |
508 | ||
509 | // Change the cursor NOW if we're within the correct window | |
510 | ||
511 | if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) | |
512 | { | |
513 | if ( mouseWin == this && !wxIsBusy() ) | |
514 | { | |
515 | m_cursor.MacInstall() ; | |
516 | } | |
6264b550 | 517 | } |
e40298d5 JS |
518 | |
519 | return TRUE ; | |
e9576ca5 SC |
520 | } |
521 | ||
522 | ||
523 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
e766c8a9 | 524 | void wxWindowMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 525 | { |
9453cf2b SC |
526 | int ww, hh; |
527 | ww = m_width ; | |
528 | hh = m_height ; | |
e40298d5 | 529 | |
6264b550 RR |
530 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
531 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
e40298d5 JS |
532 | |
533 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) | |
534 | { | |
535 | int x1 = 0 ; | |
536 | int y1 = 0 ; | |
537 | int w = m_width ; | |
538 | int h = m_height ; | |
539 | ||
540 | MacClientToRootWindow( &x1 , &y1 ) ; | |
541 | MacClientToRootWindow( &w , &h ) ; | |
542 | ||
543 | wxWindowMac *iter = (wxWindowMac*)this ; | |
544 | ||
545 | int totW = 10000 , totH = 10000; | |
546 | while( iter ) | |
6264b550 | 547 | { |
e40298d5 JS |
548 | if ( iter->IsTopLevel() ) |
549 | { | |
550 | totW = iter->m_width ; | |
551 | totH = iter->m_height ; | |
552 | break ; | |
553 | } | |
554 | ||
555 | iter = iter->GetParent() ; | |
6264b550 | 556 | } |
e40298d5 JS |
557 | |
558 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
6264b550 | 559 | { |
e40298d5 JS |
560 | hh -= MAC_SCROLLBAR_SIZE; |
561 | if ( h-y1 >= totH ) | |
562 | { | |
563 | hh += 1 ; | |
564 | } | |
6264b550 | 565 | } |
e40298d5 | 566 | if (m_vScrollBar && m_vScrollBar->IsShown() ) |
6264b550 | 567 | { |
e40298d5 JS |
568 | ww -= MAC_SCROLLBAR_SIZE; |
569 | if ( w-x1 >= totW ) | |
570 | { | |
571 | ww += 1 ; | |
572 | } | |
6264b550 RR |
573 | } |
574 | } | |
e40298d5 JS |
575 | if(x) *x = ww; |
576 | if(y) *y = hh; | |
519cb848 SC |
577 | } |
578 | ||
51abe921 SC |
579 | |
580 | // ---------------------------------------------------------------------------- | |
581 | // tooltips | |
582 | // ---------------------------------------------------------------------------- | |
583 | ||
584 | #if wxUSE_TOOLTIPS | |
585 | ||
e766c8a9 | 586 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
587 | { |
588 | wxWindowBase::DoSetToolTip(tooltip); | |
e40298d5 | 589 | |
6264b550 RR |
590 | if ( m_tooltip ) |
591 | m_tooltip->SetWindow(this); | |
51abe921 SC |
592 | } |
593 | ||
594 | #endif // wxUSE_TOOLTIPS | |
595 | ||
e766c8a9 | 596 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 597 | { |
6264b550 RR |
598 | int former_x = m_x ; |
599 | int former_y = m_y ; | |
600 | int former_w = m_width ; | |
601 | int former_h = m_height ; | |
e40298d5 JS |
602 | |
603 | int actualWidth = width; | |
604 | int actualHeight = height; | |
605 | int actualX = x; | |
606 | int actualY = y; | |
607 | ||
14c9cbdb | 608 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 609 | actualWidth = m_minWidth; |
14c9cbdb | 610 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 611 | actualHeight = m_minHeight; |
14c9cbdb | 612 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 613 | actualWidth = m_maxWidth; |
14c9cbdb | 614 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
6264b550 | 615 | actualHeight = m_maxHeight; |
e40298d5 | 616 | |
6264b550 RR |
617 | bool doMove = false ; |
618 | bool doResize = false ; | |
e40298d5 | 619 | |
6264b550 RR |
620 | if ( actualX != former_x || actualY != former_y ) |
621 | { | |
622 | doMove = true ; | |
623 | } | |
624 | if ( actualWidth != former_w || actualHeight != former_h ) | |
625 | { | |
626 | doResize = true ; | |
627 | } | |
e40298d5 | 628 | |
6264b550 RR |
629 | if ( doMove || doResize ) |
630 | { | |
1c310985 | 631 | // erase former position |
e40298d5 | 632 | |
2b5f62a0 | 633 | bool partialRepaint = false ; |
e40298d5 | 634 | |
2b5f62a0 VZ |
635 | if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) |
636 | { | |
7de59551 | 637 | wxPoint oldPos( m_x , m_y ) ; |
2b5f62a0 VZ |
638 | wxPoint newPos( actualX , actualY ) ; |
639 | MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ; | |
640 | MacWindowToRootWindow( &newPos.x , &newPos.y ) ; | |
641 | if ( oldPos == newPos ) | |
642 | { | |
643 | partialRepaint = true ; | |
644 | RgnHandle oldRgn,newRgn,diffRgn ; | |
645 | oldRgn = NewRgn() ; | |
646 | newRgn = NewRgn() ; | |
647 | diffRgn = NewRgn() ; | |
648 | SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ; | |
649 | SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ; | |
650 | DiffRgn( newRgn , oldRgn , diffRgn ) ; | |
651 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; | |
652 | DiffRgn( oldRgn , newRgn , diffRgn ) ; | |
653 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; | |
654 | DisposeRgn(oldRgn) ; | |
655 | DisposeRgn(newRgn) ; | |
656 | DisposeRgn(diffRgn) ; | |
657 | } | |
658 | } | |
e40298d5 | 659 | |
2b5f62a0 VZ |
660 | if ( !partialRepaint ) |
661 | Refresh() ; | |
e40298d5 | 662 | |
6264b550 RR |
663 | m_x = actualX ; |
664 | m_y = actualY ; | |
665 | m_width = actualWidth ; | |
666 | m_height = actualHeight ; | |
e40298d5 JS |
667 | |
668 | // update any low-level frame-relative positions | |
669 | ||
670 | MacUpdateDimensions() ; | |
1c310985 | 671 | // erase new position |
e40298d5 | 672 | |
2b5f62a0 VZ |
673 | if ( !partialRepaint ) |
674 | Refresh() ; | |
1c310985 SC |
675 | if ( doMove ) |
676 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
e40298d5 | 677 | |
6264b550 RR |
678 | MacRepositionScrollBars() ; |
679 | if ( doMove ) | |
680 | { | |
681 | wxPoint point(m_x, m_y); | |
682 | wxMoveEvent event(point, m_windowId); | |
683 | event.SetEventObject(this); | |
684 | GetEventHandler()->ProcessEvent(event) ; | |
685 | } | |
686 | if ( doResize ) | |
687 | { | |
e40298d5 JS |
688 | MacRepositionScrollBars() ; |
689 | wxSize size(m_width, m_height); | |
690 | wxSizeEvent event(size, m_windowId); | |
691 | event.SetEventObject(this); | |
692 | GetEventHandler()->ProcessEvent(event); | |
6264b550 RR |
693 | } |
694 | } | |
e40298d5 | 695 | |
954fc50b SC |
696 | } |
697 | ||
698 | // set the size of the window: if the dimensions are positive, just use them, | |
699 | // but if any of them is equal to -1, it means that we must find the value for | |
700 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
701 | // which case -1 is a valid value for x and y) | |
702 | // | |
703 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
704 | // the width/height to best suit our contents, otherwise we reuse the current | |
705 | // width/height | |
706 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
707 | { | |
708 | // get the current size and position... | |
709 | int currentX, currentY; | |
710 | GetPosition(¤tX, ¤tY); | |
e40298d5 | 711 | |
954fc50b SC |
712 | int currentW,currentH; |
713 | GetSize(¤tW, ¤tH); | |
e40298d5 | 714 | |
954fc50b SC |
715 | // ... and don't do anything (avoiding flicker) if it's already ok |
716 | if ( x == currentX && y == currentY && | |
e40298d5 | 717 | width == currentW && height == currentH ) |
954fc50b | 718 | { |
6264b550 | 719 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
720 | return; |
721 | } | |
e40298d5 | 722 | |
954fc50b SC |
723 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
724 | x = currentX; | |
725 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
726 | y = currentY; | |
e40298d5 | 727 | |
954fc50b | 728 | AdjustForParentClientOrigin(x, y, sizeFlags); |
e40298d5 | 729 | |
954fc50b SC |
730 | wxSize size(-1, -1); |
731 | if ( width == -1 ) | |
732 | { | |
733 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
734 | { | |
735 | size = DoGetBestSize(); | |
736 | width = size.x; | |
737 | } | |
738 | else | |
739 | { | |
740 | // just take the current one | |
741 | width = currentW; | |
742 | } | |
743 | } | |
e40298d5 | 744 | |
954fc50b SC |
745 | if ( height == -1 ) |
746 | { | |
747 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
748 | { | |
749 | if ( size.x == -1 ) | |
750 | { | |
751 | size = DoGetBestSize(); | |
752 | } | |
753 | //else: already called DoGetBestSize() above | |
e40298d5 | 754 | |
954fc50b SC |
755 | height = size.y; |
756 | } | |
757 | else | |
758 | { | |
759 | // just take the current one | |
760 | height = currentH; | |
761 | } | |
762 | } | |
e40298d5 | 763 | |
954fc50b | 764 | DoMoveWindow(x, y, width, height); |
e40298d5 | 765 | |
e9576ca5 | 766 | } |
e9576ca5 SC |
767 | // For implementation purposes - sometimes decorations make the client area |
768 | // smaller | |
519cb848 | 769 | |
e766c8a9 | 770 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 771 | { |
5b781a67 | 772 | return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); |
e9576ca5 SC |
773 | } |
774 | ||
d84afea9 | 775 | void wxWindowMac::SetTitle(const wxString& title) |
e9576ca5 | 776 | { |
ed60b502 | 777 | m_label = title ; |
519cb848 SC |
778 | } |
779 | ||
d84afea9 | 780 | wxString wxWindowMac::GetTitle() const |
519cb848 | 781 | { |
ed60b502 | 782 | return m_label ; |
519cb848 SC |
783 | } |
784 | ||
e766c8a9 | 785 | bool wxWindowMac::Show(bool show) |
e9576ca5 | 786 | { |
e7549107 SC |
787 | if ( !wxWindowBase::Show(show) ) |
788 | return FALSE; | |
789 | ||
6264b550 | 790 | MacSuperShown( show ) ; |
14c9cbdb | 791 | Refresh() ; |
4241baae | 792 | |
e7549107 | 793 | return TRUE; |
e9576ca5 SC |
794 | } |
795 | ||
14c9cbdb | 796 | void wxWindowMac::MacSuperShown( bool show ) |
8208e181 | 797 | { |
eb22f2a6 | 798 | wxWindowListNode *node = GetChildren().GetFirst(); |
6264b550 RR |
799 | while ( node ) |
800 | { | |
9bd1404d | 801 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
802 | if ( child->m_isShown ) |
803 | child->MacSuperShown( show ) ; | |
eb22f2a6 | 804 | node = node->GetNext(); |
6264b550 | 805 | } |
8208e181 SC |
806 | } |
807 | ||
14c9cbdb | 808 | void wxWindowMac::MacSuperEnabled( bool enabled ) |
1c310985 | 809 | { |
1c469f7f SC |
810 | if ( !IsTopLevel() ) |
811 | { | |
14c9cbdb | 812 | // to be absolutely correct we'd have to invalidate (with eraseBkground |
1c469f7f SC |
813 | // because unter MacOSX the frames are drawn with an addXXX mode) |
814 | // the borders area | |
815 | } | |
eb22f2a6 | 816 | wxWindowListNode *node = GetChildren().GetFirst(); |
1c310985 SC |
817 | while ( node ) |
818 | { | |
eb22f2a6 | 819 | wxWindowMac *child = (wxWindowMac *)node->GetData(); |
1c310985 SC |
820 | if ( child->m_isShown ) |
821 | child->MacSuperEnabled( enabled ) ; | |
eb22f2a6 | 822 | node = node->GetNext(); |
1c310985 SC |
823 | } |
824 | } | |
825 | ||
14c9cbdb | 826 | bool wxWindowMac::MacIsReallyShown() const |
c809f3be | 827 | { |
6264b550 RR |
828 | if ( m_isShown && (m_parent != NULL) ) { |
829 | return m_parent->MacIsReallyShown(); | |
830 | } | |
831 | return m_isShown; | |
14c9cbdb | 832 | /* |
6264b550 RR |
833 | bool status = m_isShown ; |
834 | wxWindowMac * win = this ; | |
835 | while ( status && win->m_parent != NULL ) | |
836 | { | |
837 | win = win->m_parent ; | |
838 | status = win->m_isShown ; | |
839 | } | |
840 | return status ; | |
5fde6fcc | 841 | */ |
c809f3be SC |
842 | } |
843 | ||
e766c8a9 | 844 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 845 | { |
6264b550 RR |
846 | wxClientDC dc ( (wxWindowMac*)this ) ; |
847 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
848 | } |
849 | ||
e766c8a9 | 850 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 851 | { |
6264b550 RR |
852 | wxClientDC dc ( (wxWindowMac*)this ) ; |
853 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
854 | } |
855 | ||
e766c8a9 | 856 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 857 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 858 | { |
e7549107 SC |
859 | const wxFont *fontToUse = theFont; |
860 | if ( !fontToUse ) | |
861 | fontToUse = &m_font; | |
14c9cbdb | 862 | |
e766c8a9 | 863 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 864 | long lx,ly,ld,le ; |
5fde6fcc | 865 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 866 | if ( externalLeading ) |
6264b550 | 867 | *externalLeading = le ; |
2f1ae414 | 868 | if ( descent ) |
6264b550 | 869 | *descent = ld ; |
2f1ae414 | 870 | if ( x ) |
6264b550 | 871 | *x = lx ; |
2f1ae414 | 872 | if ( y ) |
6264b550 | 873 | *y = ly ; |
e9576ca5 SC |
874 | } |
875 | ||
0a67a93b | 876 | /* |
14c9cbdb | 877 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
1c310985 SC |
878 | * we always intersect with the entire window, not only with the client area |
879 | */ | |
14c9cbdb | 880 | |
e766c8a9 | 881 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 882 | { |
94abc21f | 883 | if ( MacGetTopLevelWindow() == NULL ) |
9a456218 | 884 | return ; |
14c9cbdb | 885 | |
9a456218 RR |
886 | wxPoint client = GetClientAreaOrigin(); |
887 | int x1 = -client.x; | |
888 | int y1 = -client.y; | |
889 | int x2 = m_width - client.x; | |
890 | int y2 = m_height - client.y; | |
891 | ||
892 | if (IsKindOf( CLASSINFO(wxButton))) | |
893 | { | |
894 | // buttons have an "aura" | |
895 | y1 -= 5; | |
896 | x1 -= 5; | |
897 | y2 += 5; | |
898 | x2 += 5; | |
899 | } | |
900 | ||
901 | Rect clientrect = { y1, x1, y2, x2 }; | |
14c9cbdb | 902 | |
1c310985 | 903 | if ( rect ) |
6264b550 | 904 | { |
1c310985 | 905 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; |
14c9cbdb | 906 | SectRect( &clientrect , &r , &clientrect ) ; |
6264b550 | 907 | } |
14c9cbdb | 908 | |
1c310985 | 909 | if ( !EmptyRect( &clientrect ) ) |
e9576ca5 | 910 | { |
1c310985 | 911 | int top = 0 , left = 0 ; |
14c9cbdb | 912 | |
1c310985 SC |
913 | MacClientToRootWindow( &left , &top ) ; |
914 | OffsetRect( &clientrect , left , top ) ; | |
14c9cbdb | 915 | |
1c310985 | 916 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; |
e9576ca5 SC |
917 | } |
918 | } | |
919 | ||
e7549107 SC |
920 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
921 | // --------------------------------------------------------------------------- | |
e9576ca5 | 922 | // Caret manipulation |
e7549107 SC |
923 | // --------------------------------------------------------------------------- |
924 | ||
e766c8a9 | 925 | void wxWindowMac::CreateCaret(int w, int h) |
e9576ca5 | 926 | { |
e7549107 | 927 | SetCaret(new wxCaret(this, w, h)); |
e9576ca5 SC |
928 | } |
929 | ||
e766c8a9 | 930 | void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
e9576ca5 | 931 | { |
e7549107 | 932 | wxFAIL_MSG("not implemented"); |
e9576ca5 SC |
933 | } |
934 | ||
e766c8a9 | 935 | void wxWindowMac::ShowCaret(bool show) |
e9576ca5 | 936 | { |
e7549107 SC |
937 | wxCHECK_RET( m_caret, "no caret to show" ); |
938 | ||
939 | m_caret->Show(show); | |
e9576ca5 SC |
940 | } |
941 | ||
e766c8a9 | 942 | void wxWindowMac::DestroyCaret() |
e9576ca5 | 943 | { |
e7549107 | 944 | SetCaret(NULL); |
e9576ca5 SC |
945 | } |
946 | ||
e766c8a9 | 947 | void wxWindowMac::SetCaretPos(int x, int y) |
e9576ca5 | 948 | { |
e7549107 SC |
949 | wxCHECK_RET( m_caret, "no caret to move" ); |
950 | ||
951 | m_caret->Move(x, y); | |
e9576ca5 SC |
952 | } |
953 | ||
e766c8a9 | 954 | void wxWindowMac::GetCaretPos(int *x, int *y) const |
e9576ca5 | 955 | { |
e7549107 SC |
956 | wxCHECK_RET( m_caret, "no caret to get position of" ); |
957 | ||
958 | m_caret->GetPosition(x, y); | |
e9576ca5 | 959 | } |
e7549107 | 960 | #endif // wxUSE_CARET |
e9576ca5 | 961 | |
e766c8a9 | 962 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 963 | { |
519cb848 | 964 | // actually this is a windows-only concept |
e9576ca5 SC |
965 | return NULL; |
966 | } | |
967 | ||
e9576ca5 | 968 | // Coordinates relative to the window |
e766c8a9 | 969 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 970 | { |
e40298d5 | 971 | // We really don't move the mouse programmatically under Mac. |
e9576ca5 SC |
972 | } |
973 | ||
14c9cbdb | 974 | const wxBrush& wxWindowMac::MacGetBackgroundBrush() |
e9576ca5 | 975 | { |
a756f210 | 976 | if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) |
1c310985 | 977 | { |
94abc21f | 978 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ; |
1c310985 | 979 | } |
a756f210 | 980 | else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) |
94abc21f SC |
981 | { |
982 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
983 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
984 | // either a non gray background color or a non control window | |
e40298d5 JS |
985 | |
986 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
987 | ||
988 | wxWindowMac* parent = GetParent() ; | |
989 | while( parent ) | |
990 | { | |
991 | if ( parent->MacGetRootWindow() != window ) | |
992 | { | |
993 | // we are in a different window on the mac system | |
994 | parent = NULL ; | |
995 | break ; | |
996 | } | |
997 | ||
94abc21f | 998 | { |
e40298d5 JS |
999 | if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) |
1000 | && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
94abc21f | 1001 | { |
e40298d5 JS |
1002 | // if we have any other colours in the hierarchy |
1003 | m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ; | |
94abc21f SC |
1004 | break ; |
1005 | } | |
e40298d5 JS |
1006 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background |
1007 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
94abc21f | 1008 | { |
e40298d5 JS |
1009 | Rect extent = { 0 , 0 , 0 , 0 } ; |
1010 | int x , y ; | |
1011 | x = y = 0 ; | |
1012 | wxSize size = parent->GetSize() ; | |
1013 | parent->MacClientToRootWindow( &x , &y ) ; | |
1014 | extent.left = x ; | |
1015 | extent.top = y ; | |
1016 | extent.top-- ; | |
1017 | extent.right = x + size.x ; | |
1018 | extent.bottom = y + size.y ; | |
1019 | m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive | |
1020 | break ; | |
94abc21f | 1021 | } |
94abc21f | 1022 | } |
e40298d5 JS |
1023 | parent = parent->GetParent() ; |
1024 | } | |
1025 | if ( !parent ) | |
1026 | { | |
1027 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive | |
1028 | } | |
94abc21f SC |
1029 | } |
1030 | else | |
1031 | { | |
1032 | m_macBackgroundBrush.SetColour( m_backgroundColour ) ; | |
1033 | } | |
e40298d5 JS |
1034 | |
1035 | return m_macBackgroundBrush ; | |
94abc21f SC |
1036 | } |
1037 | ||
1038 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
1039 | { | |
1040 | event.GetDC()->Clear() ; | |
1c310985 SC |
1041 | } |
1042 | ||
1043 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
1044 | { | |
de043984 SC |
1045 | wxWindowDC dc(this) ; |
1046 | wxMacPortSetter helper(&dc) ; | |
14c9cbdb | 1047 | |
76a5e5d2 | 1048 | MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ; |
e9576ca5 SC |
1049 | } |
1050 | ||
e766c8a9 | 1051 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 1052 | { |
1c310985 SC |
1053 | if ( orient == wxHORIZONTAL ) |
1054 | { | |
1055 | if ( m_hScrollBar ) | |
1056 | return m_hScrollBar->GetThumbPosition() ; | |
1057 | } | |
1058 | else | |
1059 | { | |
1060 | if ( m_vScrollBar ) | |
1061 | return m_vScrollBar->GetThumbPosition() ; | |
1062 | } | |
e9576ca5 SC |
1063 | return 0; |
1064 | } | |
1065 | ||
1066 | // This now returns the whole range, not just the number | |
1067 | // of positions that we can scroll. | |
e766c8a9 | 1068 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 1069 | { |
1c310985 SC |
1070 | if ( orient == wxHORIZONTAL ) |
1071 | { | |
1072 | if ( m_hScrollBar ) | |
1073 | return m_hScrollBar->GetRange() ; | |
1074 | } | |
1075 | else | |
1076 | { | |
1077 | if ( m_vScrollBar ) | |
1078 | return m_vScrollBar->GetRange() ; | |
1079 | } | |
e9576ca5 SC |
1080 | return 0; |
1081 | } | |
1082 | ||
e766c8a9 | 1083 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 1084 | { |
1c310985 SC |
1085 | if ( orient == wxHORIZONTAL ) |
1086 | { | |
1087 | if ( m_hScrollBar ) | |
1088 | return m_hScrollBar->GetThumbSize() ; | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | if ( m_vScrollBar ) | |
1093 | return m_vScrollBar->GetThumbSize() ; | |
1094 | } | |
e9576ca5 SC |
1095 | return 0; |
1096 | } | |
1097 | ||
e766c8a9 | 1098 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 1099 | { |
1c310985 | 1100 | if ( orient == wxHORIZONTAL ) |
6264b550 | 1101 | { |
1c310985 SC |
1102 | if ( m_hScrollBar ) |
1103 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
1104 | } |
1105 | else | |
1106 | { | |
1c310985 SC |
1107 | if ( m_vScrollBar ) |
1108 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 1109 | } |
2f1ae414 SC |
1110 | } |
1111 | ||
14c9cbdb | 1112 | void wxWindowMac::MacPaintBorders( int left , int top ) |
2f1ae414 | 1113 | { |
1c310985 | 1114 | if( IsTopLevel() ) |
6264b550 | 1115 | return ; |
14c9cbdb | 1116 | |
6264b550 RR |
1117 | RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; |
1118 | RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; | |
1119 | RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; | |
1120 | RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; | |
1121 | PenNormal() ; | |
2f1ae414 SC |
1122 | |
1123 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1124 | { | |
1c310985 | 1125 | #if wxMAC_USE_THEME_BORDER |
ed60b502 RR |
1126 | Rect rect = { top , left , m_height + top , m_width + left } ; |
1127 | SInt32 border = 0 ; | |
1128 | /* | |
1129 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1130 | InsetRect( &rect , border , border ); | |
1c310985 SC |
1131 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
1132 | */ | |
14c9cbdb | 1133 | |
1c310985 SC |
1134 | DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
1135 | #else | |
ed60b502 | 1136 | bool sunken = HasFlag( wxSUNKEN_BORDER ) ; |
653b2449 | 1137 | RGBForeColor( &face ); |
7d9d1fd7 SC |
1138 | MoveTo( left + 0 , top + m_height - 2 ); |
1139 | LineTo( left + 0 , top + 0 ); | |
1140 | LineTo( left + m_width - 2 , top + 0 ); | |
653b2449 | 1141 | |
7d9d1fd7 SC |
1142 | MoveTo( left + 2 , top + m_height - 3 ); |
1143 | LineTo( left + m_width - 3 , top + m_height - 3 ); | |
1144 | LineTo( left + m_width - 3 , top + 2 ); | |
653b2449 SC |
1145 | |
1146 | RGBForeColor( sunken ? &face : &black ); | |
7d9d1fd7 SC |
1147 | MoveTo( left + 0 , top + m_height - 1 ); |
1148 | LineTo( left + m_width - 1 , top + m_height - 1 ); | |
1149 | LineTo( left + m_width - 1 , top + 0 ); | |
653b2449 SC |
1150 | |
1151 | RGBForeColor( sunken ? &shadow : &white ); | |
7d9d1fd7 SC |
1152 | MoveTo( left + 1 , top + m_height - 3 ); |
1153 | LineTo( left + 1, top + 1 ); | |
1154 | LineTo( left + m_width - 3 , top + 1 ); | |
653b2449 SC |
1155 | |
1156 | RGBForeColor( sunken ? &white : &shadow ); | |
7d9d1fd7 SC |
1157 | MoveTo( left + 1 , top + m_height - 2 ); |
1158 | LineTo( left + m_width - 2 , top + m_height - 2 ); | |
1159 | LineTo( left + m_width - 2 , top + 1 ); | |
653b2449 SC |
1160 | |
1161 | RGBForeColor( sunken ? &black : &face ); | |
7d9d1fd7 SC |
1162 | MoveTo( left + 2 , top + m_height - 4 ); |
1163 | LineTo( left + 2 , top + 2 ); | |
1164 | LineTo( left + m_width - 4 , top + 2 ); | |
1c310985 | 1165 | #endif |
8208e181 SC |
1166 | } |
1167 | else if (HasFlag(wxSIMPLE_BORDER)) | |
1168 | { | |
ed60b502 | 1169 | Rect rect = { top , left , m_height + top , m_width + left } ; |
6264b550 RR |
1170 | RGBForeColor( &black ) ; |
1171 | FrameRect( &rect ) ; | |
2f1ae414 | 1172 | } |
8208e181 SC |
1173 | } |
1174 | ||
abda5788 SC |
1175 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
1176 | { | |
1177 | if ( child == m_hScrollBar ) | |
1178 | m_hScrollBar = NULL ; | |
1179 | if ( child == m_vScrollBar ) | |
1180 | m_vScrollBar = NULL ; | |
14c9cbdb | 1181 | |
abda5788 SC |
1182 | wxWindowBase::RemoveChild( child ) ; |
1183 | } | |
1184 | ||
e9576ca5 | 1185 | // New function that will replace some of the above. |
e766c8a9 | 1186 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
1187 | int range, bool refresh) |
1188 | { | |
e40298d5 JS |
1189 | if ( orient == wxHORIZONTAL ) |
1190 | { | |
1191 | if ( m_hScrollBar ) | |
6264b550 | 1192 | { |
e40298d5 | 1193 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 1194 | { |
e40298d5 JS |
1195 | if ( m_hScrollBar->IsShown() ) |
1196 | m_hScrollBar->Show(false) ; | |
1197 | } | |
1198 | else | |
1199 | { | |
1200 | if ( !m_hScrollBar->IsShown() ) | |
1201 | m_hScrollBar->Show(true) ; | |
1202 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
6264b550 RR |
1203 | } |
1204 | } | |
e40298d5 JS |
1205 | } |
1206 | else | |
1207 | { | |
1208 | if ( m_vScrollBar ) | |
6264b550 | 1209 | { |
e40298d5 | 1210 | if ( range == 0 || thumbVisible >= range ) |
6264b550 | 1211 | { |
e40298d5 JS |
1212 | if ( m_vScrollBar->IsShown() ) |
1213 | m_vScrollBar->Show(false) ; | |
1214 | } | |
1215 | else | |
1216 | { | |
1217 | if ( !m_vScrollBar->IsShown() ) | |
1218 | m_vScrollBar->Show(true) ; | |
1219 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
6264b550 RR |
1220 | } |
1221 | } | |
e40298d5 JS |
1222 | } |
1223 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
1224 | } |
1225 | ||
1226 | // Does a physical scroll | |
e766c8a9 | 1227 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 1228 | { |
de043984 SC |
1229 | wxClientDC dc(this) ; |
1230 | wxMacPortSetter helper(&dc) ; | |
e40298d5 | 1231 | |
6264b550 RR |
1232 | { |
1233 | int width , height ; | |
1234 | GetClientSize( &width , &height ) ; | |
e40298d5 | 1235 | |
de043984 | 1236 | Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ; |
6264b550 RR |
1237 | RgnHandle updateRgn = NewRgn() ; |
1238 | ClipRect( &scrollrect ) ; | |
1239 | if ( rect ) | |
1240 | { | |
14c9cbdb | 1241 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , |
e40298d5 | 1242 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; |
14c9cbdb | 1243 | SectRect( &scrollrect , &r , &scrollrect ) ; |
6264b550 RR |
1244 | } |
1245 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
76a5e5d2 | 1246 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ; |
6264b550 RR |
1247 | DisposeRgn( updateRgn ) ; |
1248 | } | |
e40298d5 | 1249 | |
eb22f2a6 | 1250 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 1251 | { |
9bd1404d | 1252 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
1253 | if (child == m_vScrollBar) continue; |
1254 | if (child == m_hScrollBar) continue; | |
1255 | if (child->IsTopLevel()) continue; | |
e40298d5 | 1256 | |
6264b550 RR |
1257 | int x,y; |
1258 | child->GetPosition( &x, &y ); | |
1259 | int w,h; | |
1260 | child->GetSize( &w, &h ); | |
1261 | child->SetSize( x+dx, y+dy, w, h ); | |
1262 | } | |
e40298d5 | 1263 | |
e9576ca5 SC |
1264 | } |
1265 | ||
e766c8a9 | 1266 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 1267 | { |
6264b550 RR |
1268 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) |
1269 | { | |
1270 | wxScrollWinEvent wevent; | |
1271 | wevent.SetPosition(event.GetPosition()); | |
1272 | wevent.SetOrientation(event.GetOrientation()); | |
1273 | wevent.m_eventObject = this; | |
e40298d5 | 1274 | |
6264b550 RR |
1275 | if (event.m_eventType == wxEVT_SCROLL_TOP) { |
1276 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
1277 | } else | |
e40298d5 JS |
1278 | if (event.m_eventType == wxEVT_SCROLL_BOTTOM) { |
1279 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1280 | } else | |
1281 | if (event.m_eventType == wxEVT_SCROLL_LINEUP) { | |
1282 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1283 | } else | |
1284 | if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) { | |
1285 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1286 | } else | |
1287 | if (event.m_eventType == wxEVT_SCROLL_PAGEUP) { | |
1288 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1289 | } else | |
1290 | if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) { | |
1291 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1292 | } else | |
1293 | if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) { | |
1294 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1295 | } | |
1296 | ||
1297 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
1298 | } |
1299 | } | |
1300 | ||
e9576ca5 | 1301 | // Get the window with the focus |
e766c8a9 | 1302 | wxWindowMac *wxWindowBase::FindFocus() |
e9576ca5 | 1303 | { |
6264b550 | 1304 | return gFocusWindow ; |
519cb848 SC |
1305 | } |
1306 | ||
e7549107 | 1307 | #if WXWIN_COMPATIBILITY |
e9576ca5 SC |
1308 | // If nothing defined for this, try the parent. |
1309 | // E.g. we may be a button loaded from a resource, with no callback function | |
1310 | // defined. | |
e766c8a9 | 1311 | void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event) |
e9576ca5 | 1312 | { |
e7549107 SC |
1313 | if ( GetEventHandler()->ProcessEvent(event) ) |
1314 | return; | |
1315 | if ( m_parent ) | |
1316 | m_parent->GetEventHandler()->OnCommand(win, event); | |
e9576ca5 | 1317 | } |
e7549107 | 1318 | #endif // WXWIN_COMPATIBILITY_2 |
e9576ca5 | 1319 | |
e7549107 | 1320 | #if WXWIN_COMPATIBILITY |
e766c8a9 | 1321 | wxObject* wxWindowMac::GetChild(int number) const |
e9576ca5 | 1322 | { |
e7549107 | 1323 | // Return a pointer to the Nth object in the Panel |
eb22f2a6 | 1324 | wxNode *node = GetChildren().GetFirst(); |
e7549107 SC |
1325 | int n = number; |
1326 | while (node && n--) | |
eb22f2a6 | 1327 | node = node->GetNext(); |
e7549107 | 1328 | if ( node ) |
519cb848 | 1329 | { |
eb22f2a6 | 1330 | wxObject *obj = (wxObject *)node->GetData(); |
e7549107 | 1331 | return(obj); |
519cb848 SC |
1332 | } |
1333 | else | |
e7549107 | 1334 | return NULL; |
e9576ca5 | 1335 | } |
e7549107 | 1336 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 1337 | |
e766c8a9 | 1338 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
1339 | { |
1340 | // panel wants to track the window which was the last to have focus in it, | |
1341 | // so we want to set ourselves as the window which last had focus | |
1342 | // | |
1343 | // notice that it's also important to do it upwards the tree becaus | |
1344 | // otherwise when the top level panel gets focus, it won't set it back to | |
1345 | // us, but to some other sibling | |
e40298d5 | 1346 | |
c1fb8167 SC |
1347 | // CS:don't know if this is still needed: |
1348 | //wxChildFocusEvent eventFocus(this); | |
1349 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b SC |
1350 | |
1351 | event.Skip(); | |
1352 | } | |
1353 | ||
e766c8a9 | 1354 | void wxWindowMac::Clear() |
e9576ca5 | 1355 | { |
1c310985 SC |
1356 | wxClientDC dc(this); |
1357 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1358 | dc.SetBackground(brush); | |
1359 | dc.Clear(); | |
e9576ca5 SC |
1360 | } |
1361 | ||
e7549107 | 1362 | // Setup background and foreground colours correctly |
e766c8a9 | 1363 | void wxWindowMac::SetupColours() |
e9576ca5 | 1364 | { |
e7549107 SC |
1365 | if ( GetParent() ) |
1366 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
e9576ca5 SC |
1367 | } |
1368 | ||
e766c8a9 | 1369 | void wxWindowMac::OnIdle(wxIdleEvent& event) |
e9576ca5 | 1370 | { |
e9576ca5 SC |
1371 | // This calls the UI-update mechanism (querying windows for |
1372 | // menu/toolbar/control state information) | |
6264b550 | 1373 | UpdateWindowUI(); |
e9576ca5 SC |
1374 | } |
1375 | ||
1376 | // Raise the window to the top of the Z order | |
e766c8a9 | 1377 | void wxWindowMac::Raise() |
e9576ca5 | 1378 | { |
e9576ca5 SC |
1379 | } |
1380 | ||
1381 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 1382 | void wxWindowMac::Lower() |
e9576ca5 | 1383 | { |
e9576ca5 SC |
1384 | } |
1385 | ||
e766c8a9 | 1386 | void wxWindowMac::DoSetClientSize(int width, int height) |
519cb848 | 1387 | { |
6264b550 RR |
1388 | if ( width != -1 || height != -1 ) |
1389 | { | |
14c9cbdb | 1390 | |
6264b550 RR |
1391 | if ( width != -1 && m_vScrollBar ) |
1392 | width += MAC_SCROLLBAR_SIZE ; | |
1393 | if ( height != -1 && m_vScrollBar ) | |
1394 | height += MAC_SCROLLBAR_SIZE ; | |
519cb848 | 1395 | |
6264b550 RR |
1396 | width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1397 | height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
2f1ae414 | 1398 | |
6264b550 RR |
1399 | DoSetSize( -1 , -1 , width , height ) ; |
1400 | } | |
519cb848 SC |
1401 | } |
1402 | ||
519cb848 | 1403 | |
e766c8a9 | 1404 | wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; |
519cb848 | 1405 | |
14c9cbdb | 1406 | bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) |
519cb848 | 1407 | { |
a07c1212 SC |
1408 | if ( IsTopLevel() ) |
1409 | { | |
e40298d5 JS |
1410 | if ((point.x < 0) || (point.y < 0) || |
1411 | (point.x > (m_width)) || (point.y > (m_height))) | |
1412 | return FALSE; | |
a07c1212 SC |
1413 | } |
1414 | else | |
1415 | { | |
e40298d5 JS |
1416 | if ((point.x < m_x) || (point.y < m_y) || |
1417 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1418 | return FALSE; | |
a07c1212 | 1419 | } |
e40298d5 | 1420 | |
76a5e5d2 | 1421 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
e40298d5 | 1422 | |
6264b550 | 1423 | wxPoint newPoint( point ) ; |
e40298d5 | 1424 | |
a07c1212 SC |
1425 | if ( !IsTopLevel() ) |
1426 | { | |
e40298d5 JS |
1427 | newPoint.x -= m_x; |
1428 | newPoint.y -= m_y; | |
a07c1212 | 1429 | } |
e40298d5 | 1430 | |
eb22f2a6 | 1431 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 1432 | { |
9bd1404d | 1433 | wxWindowMac *child = node->GetData(); |
6264b550 | 1434 | // added the m_isShown test --dmazzoni |
1c310985 | 1435 | if ( child->MacGetRootWindow() == window && child->m_isShown ) |
6264b550 RR |
1436 | { |
1437 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1438 | return TRUE; | |
1439 | } | |
1440 | } | |
e40298d5 | 1441 | |
6264b550 RR |
1442 | *outWin = this ; |
1443 | return TRUE; | |
519cb848 SC |
1444 | } |
1445 | ||
14c9cbdb | 1446 | bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) |
519cb848 | 1447 | { |
6264b550 | 1448 | WindowRef window ; |
e40298d5 | 1449 | |
6264b550 RR |
1450 | Point pt = { screenpoint.y , screenpoint.x } ; |
1451 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1452 | { | |
e40298d5 | 1453 | |
a07c1212 SC |
1454 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; |
1455 | if ( win ) | |
1456 | { | |
ed60b502 RR |
1457 | // No, this yields the CLIENT are, we need the whole frame. RR. |
1458 | // point = win->ScreenToClient( point ) ; | |
e40298d5 | 1459 | |
14c9cbdb | 1460 | GrafPtr port; |
ed60b502 RR |
1461 | ::GetPort( &port ) ; |
1462 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
1463 | ::GlobalToLocal( &pt ) ; | |
1464 | ::SetPort( port ) ; | |
e40298d5 | 1465 | |
ed60b502 | 1466 | wxPoint point( pt.h, pt.v ) ; |
e40298d5 | 1467 | |
6264b550 | 1468 | return win->MacGetWindowFromPointSub( point , outWin ) ; |
a07c1212 | 1469 | } |
6264b550 RR |
1470 | } |
1471 | return FALSE ; | |
519cb848 SC |
1472 | } |
1473 | ||
32b5be3d | 1474 | static wxWindow *gs_lastWhich = NULL; |
519cb848 | 1475 | |
7de59551 | 1476 | bool wxWindowMac::MacSetupCursor( const wxPoint& pt) |
467e3168 SC |
1477 | { |
1478 | // first trigger a set cursor event | |
e40298d5 | 1479 | |
467e3168 SC |
1480 | wxPoint clientorigin = GetClientAreaOrigin() ; |
1481 | wxSize clientsize = GetClientSize() ; | |
1482 | wxCursor cursor ; | |
1483 | if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) ) | |
7de59551 | 1484 | { |
467e3168 | 1485 | wxSetCursorEvent event( pt.x , pt.y ); |
e40298d5 | 1486 | |
467e3168 SC |
1487 | bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); |
1488 | if ( processedEvtSetCursor && event.HasCursor() ) | |
1489 | { | |
e40298d5 | 1490 | cursor = event.GetCursor() ; |
467e3168 SC |
1491 | } |
1492 | else | |
1493 | { | |
e40298d5 | 1494 | |
467e3168 SC |
1495 | // the test for processedEvtSetCursor is here to prevent using m_cursor |
1496 | // if the user code caught EVT_SET_CURSOR() and returned nothing from | |
1497 | // it - this is a way to say that our cursor shouldn't be used for this | |
1498 | // point | |
1499 | if ( !processedEvtSetCursor && m_cursor.Ok() ) | |
1500 | { | |
1501 | cursor = m_cursor ; | |
1502 | } | |
1503 | if ( wxIsBusy() ) | |
1504 | { | |
1505 | } | |
1506 | else | |
1507 | { | |
1508 | if ( !GetParent() ) | |
1509 | cursor = *wxSTANDARD_CURSOR ; | |
1510 | } | |
1511 | } | |
1512 | if ( cursor.Ok() ) | |
1513 | cursor.MacInstall() ; | |
1514 | } | |
1515 | return cursor.Ok() ; | |
1516 | } | |
1517 | ||
e766c8a9 | 1518 | bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) |
519cb848 | 1519 | { |
6264b550 RR |
1520 | if ((event.m_x < m_x) || (event.m_y < m_y) || |
1521 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1522 | return FALSE; | |
e40298d5 JS |
1523 | |
1524 | ||
327788ac | 1525 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) |
14c9cbdb | 1526 | return FALSE ; |
e40298d5 | 1527 | |
76a5e5d2 | 1528 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
e40298d5 | 1529 | |
6264b550 RR |
1530 | event.m_x -= m_x; |
1531 | event.m_y -= m_y; | |
e40298d5 | 1532 | |
6264b550 RR |
1533 | int x = event.m_x ; |
1534 | int y = event.m_y ; | |
e40298d5 | 1535 | |
eb22f2a6 | 1536 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 1537 | { |
9bd1404d | 1538 | wxWindowMac *child = node->GetData(); |
1c310985 | 1539 | if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() ) |
6264b550 RR |
1540 | { |
1541 | if (child->MacDispatchMouseEvent(event)) | |
1542 | return TRUE; | |
1543 | } | |
7810c95b | 1544 | } |
e40298d5 | 1545 | |
467e3168 SC |
1546 | wxWindow* cursorTarget = this ; |
1547 | wxPoint cursorPoint( x , y ) ; | |
e40298d5 | 1548 | |
467e3168 | 1549 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) |
6264b550 | 1550 | { |
467e3168 SC |
1551 | cursorTarget = cursorTarget->GetParent() ; |
1552 | if ( cursorTarget ) | |
1553 | cursorPoint += cursorTarget->GetPosition() ; | |
6264b550 | 1554 | } |
467e3168 SC |
1555 | event.m_x = x ; |
1556 | event.m_y = y ; | |
1557 | event.SetEventObject( this ) ; | |
e40298d5 | 1558 | |
6264b550 RR |
1559 | if ( event.GetEventType() == wxEVT_LEFT_DOWN ) |
1560 | { | |
1561 | // set focus to this window | |
1562 | if (AcceptsFocus() && FindFocus()!=this) | |
1563 | SetFocus(); | |
1564 | } | |
e40298d5 | 1565 | |
2f1ae414 | 1566 | #if wxUSE_TOOLTIPS |
14c9cbdb | 1567 | if ( event.GetEventType() == wxEVT_MOTION |
e40298d5 JS |
1568 | || event.GetEventType() == wxEVT_ENTER_WINDOW |
1569 | || event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
2f1ae414 SC |
1570 | wxToolTip::RelayEvent( this , event); |
1571 | #endif // wxUSE_TOOLTIPS | |
e40298d5 | 1572 | |
32b5be3d RR |
1573 | if (gs_lastWhich != this) |
1574 | { | |
1575 | gs_lastWhich = this; | |
e40298d5 | 1576 | |
32b5be3d RR |
1577 | // Double clicks must always occur on the same window |
1578 | if (event.GetEventType() == wxEVT_LEFT_DCLICK) | |
1579 | event.SetEventType( wxEVT_LEFT_DOWN ); | |
1580 | if (event.GetEventType() == wxEVT_RIGHT_DCLICK) | |
1581 | event.SetEventType( wxEVT_RIGHT_DOWN ); | |
e40298d5 | 1582 | |
32b5be3d RR |
1583 | // Same for mouse up events |
1584 | if (event.GetEventType() == wxEVT_LEFT_UP) | |
1585 | return TRUE; | |
1586 | if (event.GetEventType() == wxEVT_RIGHT_UP) | |
1587 | return TRUE; | |
1588 | } | |
e40298d5 | 1589 | |
6264b550 | 1590 | GetEventHandler()->ProcessEvent( event ) ; |
e40298d5 | 1591 | |
6264b550 | 1592 | return TRUE; |
519cb848 SC |
1593 | } |
1594 | ||
e766c8a9 | 1595 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 1596 | { |
6264b550 RR |
1597 | if ( m_tooltip ) |
1598 | { | |
1599 | return m_tooltip->GetTip() ; | |
1600 | } | |
427ff662 | 1601 | return wxEmptyString ; |
2f1ae414 | 1602 | } |
6264b550 | 1603 | |
1c310985 | 1604 | void wxWindowMac::Update() |
519cb848 | 1605 | { |
1c310985 SC |
1606 | wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ; |
1607 | if ( win ) | |
f1759123 | 1608 | { |
1c310985 | 1609 | win->MacUpdate( 0 ) ; |
bec721ec | 1610 | #if TARGET_API_MAC_CARBON |
ed60b502 RR |
1611 | if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) |
1612 | { | |
1613 | QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; | |
1614 | } | |
bec721ec | 1615 | #endif |
ed60b502 | 1616 | } |
519cb848 SC |
1617 | } |
1618 | ||
14c9cbdb | 1619 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const |
519cb848 | 1620 | { |
1c310985 | 1621 | wxTopLevelWindowMac* win = NULL ; |
76a5e5d2 | 1622 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
1c310985 | 1623 | if ( window ) |
6264b550 | 1624 | { |
1c310985 | 1625 | win = wxFindWinFromMacWindow( window ) ; |
14c9cbdb | 1626 | } |
1c310985 | 1627 | return win ; |
519cb848 SC |
1628 | } |
1629 | ||
7372fd0a | 1630 | const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings ) |
94abc21f | 1631 | { |
e40298d5 JS |
1632 | RgnHandle visRgn = NewRgn() ; |
1633 | RgnHandle tempRgn = NewRgn() ; | |
1634 | RgnHandle tempStaticBoxRgn = NewRgn() ; | |
1635 | ||
1636 | SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; | |
1637 | ||
1638 | //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox | |
1639 | if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1640 | { | |
1641 | int borderTop = 14 ; | |
1642 | int borderOther = 4 ; | |
1643 | ||
1644 | SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; | |
1645 | DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; | |
1646 | } | |
1647 | ||
1648 | if ( !IsTopLevel() ) | |
1649 | { | |
1650 | wxWindow* parent = GetParent() ; | |
1651 | while( parent ) | |
94abc21f | 1652 | { |
e40298d5 JS |
1653 | wxSize size = parent->GetSize() ; |
1654 | int x , y ; | |
1655 | x = y = 0 ; | |
1656 | parent->MacWindowToRootWindow( &x, &y ) ; | |
1657 | MacRootWindowToWindow( &x , &y ) ; | |
1658 | ||
1659 | SetRectRgn( tempRgn , | |
1660 | x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , | |
1661 | x + size.x - parent->MacGetRightBorderSize(), | |
1662 | y + size.y - parent->MacGetBottomBorderSize()) ; | |
1663 | ||
1664 | SectRgn( visRgn , tempRgn , visRgn ) ; | |
1665 | if ( parent->IsTopLevel() ) | |
1666 | break ; | |
1667 | parent = parent->GetParent() ; | |
1668 | } | |
1669 | } | |
1670 | if ( respectChildrenAndSiblings ) | |
1671 | { | |
1672 | if ( GetWindowStyle() & wxCLIP_CHILDREN ) | |
1673 | { | |
1674 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) | |
7372fd0a | 1675 | { |
9bd1404d | 1676 | wxWindowMac *child = node->GetData(); |
e40298d5 JS |
1677 | |
1678 | if ( !child->IsTopLevel() && child->IsShown() ) | |
be0b002a | 1679 | { |
e40298d5 JS |
1680 | SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; |
1681 | if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1682 | { | |
1683 | int borderTop = 14 ; | |
1684 | int borderOther = 4 ; | |
1685 | ||
1686 | SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; | |
1687 | DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; | |
1688 | } | |
1689 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
be0b002a | 1690 | } |
7372fd0a | 1691 | } |
94abc21f | 1692 | } |
e40298d5 JS |
1693 | |
1694 | if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) | |
94abc21f | 1695 | { |
e40298d5 JS |
1696 | bool thisWindowThrough = false ; |
1697 | for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) | |
7372fd0a | 1698 | { |
9bd1404d | 1699 | wxWindowMac *sibling = node->GetData(); |
e40298d5 | 1700 | if ( sibling == this ) |
be0b002a | 1701 | { |
e40298d5 JS |
1702 | thisWindowThrough = true ; |
1703 | continue ; | |
1704 | } | |
1705 | if( !thisWindowThrough ) | |
1706 | { | |
1707 | continue ; | |
1708 | } | |
1709 | ||
1710 | if ( !sibling->IsTopLevel() && sibling->IsShown() ) | |
1711 | { | |
1712 | SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; | |
1713 | if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
1714 | { | |
1715 | int borderTop = 14 ; | |
1716 | int borderOther = 4 ; | |
1717 | ||
1718 | SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; | |
1719 | DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; | |
1720 | } | |
1721 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
be0b002a | 1722 | } |
7372fd0a | 1723 | } |
94abc21f | 1724 | } |
e40298d5 JS |
1725 | } |
1726 | m_macVisibleRegion = visRgn ; | |
1727 | DisposeRgn( visRgn ) ; | |
1728 | DisposeRgn( tempRgn ) ; | |
1729 | DisposeRgn( tempStaticBoxRgn ) ; | |
1730 | return m_macVisibleRegion ; | |
94abc21f SC |
1731 | } |
1732 | ||
76a5e5d2 | 1733 | void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) |
519cb848 | 1734 | { |
76a5e5d2 | 1735 | RgnHandle updatergn = (RgnHandle) updatergnr ; |
6264b550 | 1736 | // updatergn is always already clipped to our boundaries |
94abc21f | 1737 | // it is in window coordinates, not in client coordinates |
e40298d5 | 1738 | |
76a5e5d2 | 1739 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
e40298d5 | 1740 | |
6264b550 | 1741 | { |
94abc21f | 1742 | // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates |
1c310985 SC |
1743 | RgnHandle ownUpdateRgn = NewRgn() ; |
1744 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
e40298d5 | 1745 | |
76a5e5d2 | 1746 | SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ; |
e40298d5 | 1747 | |
94abc21f | 1748 | // newupdate is the update region in client coordinates |
1c310985 SC |
1749 | RgnHandle newupdate = NewRgn() ; |
1750 | wxSize point = GetClientSize() ; | |
1751 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 SC |
1752 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; |
1753 | SectRgn( newupdate , ownUpdateRgn , newupdate ) ; | |
1754 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1755 | m_updateRegion = newupdate ; | |
1756 | DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion | |
e40298d5 | 1757 | |
e8788ed0 | 1758 | if ( erase && !EmptyRgn(ownUpdateRgn) ) |
14c9cbdb | 1759 | { |
e40298d5 JS |
1760 | wxWindowDC dc(this); |
1761 | if (!EmptyRgn(ownUpdateRgn)) | |
1762 | dc.SetClippingRegion(wxRegion(ownUpdateRgn)); | |
1763 | wxEraseEvent eevent( GetId(), &dc ); | |
1764 | eevent.SetEventObject( this ); | |
1765 | GetEventHandler()->ProcessEvent( eevent ); | |
1766 | ||
1767 | wxNcPaintEvent eventNc( GetId() ); | |
1768 | eventNc.SetEventObject( this ); | |
1769 | GetEventHandler()->ProcessEvent( eventNc ); | |
6264b550 | 1770 | } |
14c9cbdb | 1771 | DisposeRgn( ownUpdateRgn ) ; |
1c310985 | 1772 | if ( !m_updateRegion.Empty() ) |
6264b550 | 1773 | { |
e40298d5 JS |
1774 | wxPaintEvent event; |
1775 | event.m_timeStamp = time ; | |
1776 | event.SetEventObject(this); | |
1777 | GetEventHandler()->ProcessEvent(event); | |
14c9cbdb | 1778 | } |
6264b550 | 1779 | } |
e40298d5 | 1780 | |
1c310985 | 1781 | // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively |
e40298d5 | 1782 | |
14c9cbdb | 1783 | RgnHandle childupdate = NewRgn() ; |
eb22f2a6 | 1784 | for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) |
6264b550 | 1785 | { |
94abc21f SC |
1786 | // calculate the update region for the child windows by intersecting the window rectangle with our own |
1787 | // passed in update region and then offset it to be client-wise window coordinates again | |
9bd1404d | 1788 | wxWindowMac *child = node->GetData(); |
6264b550 RR |
1789 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; |
1790 | SectRgn( childupdate , updatergn , childupdate ) ; | |
1791 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
1c310985 | 1792 | if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) |
6264b550 RR |
1793 | { |
1794 | // because dialogs may also be children | |
1c310985 | 1795 | child->MacRedraw( childupdate , time , erase ) ; |
6264b550 RR |
1796 | } |
1797 | } | |
1798 | DisposeRgn( childupdate ) ; | |
1799 | // eventually a draw grow box here | |
e40298d5 | 1800 | |
519cb848 SC |
1801 | } |
1802 | ||
76a5e5d2 | 1803 | WXHWND wxWindowMac::MacGetRootWindow() const |
519cb848 | 1804 | { |
6264b550 | 1805 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 1806 | |
6264b550 RR |
1807 | while( iter ) |
1808 | { | |
1c310985 SC |
1809 | if ( iter->IsTopLevel() ) |
1810 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
519cb848 | 1811 | |
6264b550 | 1812 | iter = iter->GetParent() ; |
14c9cbdb | 1813 | } |
427ff662 | 1814 | wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ; |
6264b550 | 1815 | return NULL ; |
519cb848 SC |
1816 | } |
1817 | ||
14c9cbdb | 1818 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 1819 | { |
427ff662 | 1820 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; |
14c9cbdb | 1821 | |
6264b550 RR |
1822 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; |
1823 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
1824 | int width, height ; | |
1825 | GetClientSize( &width , &height ) ; | |
14c9cbdb | 1826 | |
6264b550 RR |
1827 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; |
1828 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1829 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1830 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
14c9cbdb RD |
1831 | |
1832 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
6264b550 RR |
1833 | vSize , wxVERTICAL); |
1834 | ||
1835 | if ( style & wxVSCROLL ) | |
1836 | { | |
14c9cbdb | 1837 | |
6264b550 RR |
1838 | } |
1839 | else | |
1840 | { | |
1841 | m_vScrollBar->Show(false) ; | |
1842 | } | |
14c9cbdb | 1843 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, |
6264b550 RR |
1844 | hSize , wxHORIZONTAL); |
1845 | if ( style & wxHSCROLL ) | |
1846 | { | |
1847 | } | |
1848 | else | |
1849 | { | |
1850 | m_hScrollBar->Show(false) ; | |
1851 | } | |
14c9cbdb | 1852 | |
6264b550 RR |
1853 | // because the create does not take into account the client area origin |
1854 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
1855 | } |
1856 | ||
e766c8a9 | 1857 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 1858 | { |
6264b550 RR |
1859 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
1860 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
14c9cbdb | 1861 | |
6264b550 | 1862 | // get real client area |
14c9cbdb RD |
1863 | |
1864 | int width = m_width ; | |
6264b550 RR |
1865 | int height = m_height ; |
1866 | ||
1867 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
1868 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
14c9cbdb | 1869 | |
6264b550 RR |
1870 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; |
1871 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1872 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1873 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
14c9cbdb RD |
1874 | |
1875 | int x = 0 ; | |
6264b550 RR |
1876 | int y = 0 ; |
1877 | int w = m_width ; | |
1878 | int h = m_height ; | |
14c9cbdb | 1879 | |
6264b550 RR |
1880 | MacClientToRootWindow( &x , &y ) ; |
1881 | MacClientToRootWindow( &w , &h ) ; | |
14c9cbdb | 1882 | |
6264b550 | 1883 | wxWindowMac *iter = (wxWindowMac*)this ; |
14c9cbdb | 1884 | |
6264b550 RR |
1885 | int totW = 10000 , totH = 10000; |
1886 | while( iter ) | |
1887 | { | |
1c310985 | 1888 | if ( iter->IsTopLevel() ) |
6264b550 RR |
1889 | { |
1890 | totW = iter->m_width ; | |
1891 | totH = iter->m_height ; | |
1892 | break ; | |
1893 | } | |
1894 | ||
1895 | iter = iter->GetParent() ; | |
14c9cbdb RD |
1896 | } |
1897 | ||
6264b550 RR |
1898 | if ( x == 0 ) |
1899 | { | |
1900 | hPoint.x = -1 ; | |
1901 | hSize.x += 1 ; | |
1902 | } | |
1903 | if ( y == 0 ) | |
1904 | { | |
1905 | vPoint.y = -1 ; | |
1906 | vSize.y += 1 ; | |
1907 | } | |
14c9cbdb | 1908 | |
6264b550 RR |
1909 | if ( w-x >= totW ) |
1910 | { | |
1911 | hSize.x += 1 ; | |
1912 | vPoint.x += 1 ; | |
1913 | } | |
14c9cbdb | 1914 | |
6264b550 RR |
1915 | if ( h-y >= totH ) |
1916 | { | |
1917 | vSize.y += 1 ; | |
1918 | hPoint.y += 1 ; | |
1919 | } | |
1920 | ||
1921 | if ( m_vScrollBar ) | |
1922 | { | |
1923 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
1924 | } | |
1925 | if ( m_hScrollBar ) | |
1926 | { | |
1927 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
1928 | } | |
519cb848 SC |
1929 | } |
1930 | ||
e766c8a9 | 1931 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
1932 | { |
1933 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
1934 | } | |
519cb848 | 1935 | |
14c9cbdb | 1936 | WXWidget wxWindowMac::MacGetContainerForEmbedding() |
519cb848 | 1937 | { |
1c310985 | 1938 | return GetParent()->MacGetContainerForEmbedding() ; |
519cb848 SC |
1939 | } |
1940 | ||
14c9cbdb | 1941 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 1942 | { |
6264b550 | 1943 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 1944 | |
eb22f2a6 | 1945 | wxWindowListNode *node = GetChildren().GetFirst(); |
6264b550 RR |
1946 | while ( node ) |
1947 | { | |
9bd1404d | 1948 | wxWindowMac *child = node->GetData(); |
6264b550 | 1949 | child->MacSuperChangedPosition() ; |
eb22f2a6 | 1950 | node = node->GetNext(); |
6264b550 | 1951 | } |
519cb848 | 1952 | } |
519cb848 | 1953 | |
14c9cbdb | 1954 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
a3bf4a62 | 1955 | { |
6264b550 | 1956 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 1957 | |
eb22f2a6 | 1958 | wxWindowListNode *node = GetChildren().GetFirst(); |
6264b550 RR |
1959 | while ( node ) |
1960 | { | |
9bd1404d | 1961 | wxWindowMac *child = node->GetData(); |
6264b550 | 1962 | child->MacTopLevelWindowChangedPosition() ; |
eb22f2a6 | 1963 | node = node->GetNext(); |
6264b550 | 1964 | } |
a3bf4a62 | 1965 | } |
e766c8a9 | 1966 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 1967 | { |
1c310985 | 1968 | if( IsTopLevel() ) |
6264b550 | 1969 | return 0 ; |
2f1ae414 SC |
1970 | |
1971 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
1972 | { | |
ed60b502 | 1973 | SInt32 border = 3 ; |
1c310985 | 1974 | #if wxMAC_USE_THEME_BORDER |
14c9cbdb | 1975 | #if TARGET_CARBON |
ed60b502 | 1976 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; |
1c310985 SC |
1977 | #endif |
1978 | #endif | |
ed60b502 | 1979 | return border ; |
2f1ae414 SC |
1980 | } |
1981 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
1982 | { | |
ed60b502 | 1983 | SInt32 border = 3 ; |
1c310985 | 1984 | #if wxMAC_USE_THEME_BORDER |
14c9cbdb | 1985 | #if TARGET_CARBON |
ed60b502 | 1986 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; |
1c310985 SC |
1987 | #endif |
1988 | #endif | |
ed60b502 | 1989 | return border ; |
2f1ae414 SC |
1990 | } |
1991 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
1992 | { | |
6264b550 | 1993 | return 1 ; |
2f1ae414 | 1994 | } |
6264b550 | 1995 | return 0 ; |
2f1ae414 SC |
1996 | } |
1997 | ||
e766c8a9 | 1998 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 1999 | { |
1c310985 SC |
2000 | // they are all symmetric in mac themes |
2001 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
2002 | } |
2003 | ||
e766c8a9 | 2004 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 2005 | { |
1c310985 SC |
2006 | // they are all symmetric in mac themes |
2007 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
2008 | } |
2009 | ||
e766c8a9 | 2010 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 2011 | { |
1c310985 SC |
2012 | // they are all symmetric in mac themes |
2013 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
2014 | } |
2015 | ||
14c9cbdb | 2016 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 2017 | { |
6264b550 | 2018 | return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; |
2f1ae414 | 2019 | } |
0a67a93b | 2020 | |
e766c8a9 | 2021 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 2022 | // position. |
e766c8a9 | 2023 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 2024 | { |
59a12e90 | 2025 | pt = wxGetMousePosition(); |
e766c8a9 | 2026 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 2027 | return found; |
3723b7b1 JS |
2028 | } |
2029 | ||
2030 | // Get the current mouse position. | |
2031 | wxPoint wxGetMousePosition() | |
2032 | { | |
57591e0e JS |
2033 | int x, y; |
2034 | wxGetMousePosition(& x, & y); | |
2035 | return wxPoint(x, y); | |
3723b7b1 JS |
2036 | } |
2037 | ||
8950f7cc SC |
2038 | void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) |
2039 | { | |
2040 | if ( event.GetEventType() == wxEVT_RIGHT_DOWN ) | |
2041 | { | |
2042 | // copied from wxGTK : CS | |
249aad30 | 2043 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN |
8950f7cc SC |
2044 | // except that: |
2045 | // | |
2046 | // (a) it's a command event and so is propagated to the parent | |
2047 | // (b) under MSW it can be generated from kbd too | |
2048 | // (c) it uses screen coords (because of (a)) | |
2049 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
2050 | this->GetId(), | |
2051 | this->ClientToScreen(event.GetPosition())); | |
249aad30 SC |
2052 | if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) |
2053 | event.Skip() ; | |
8950f7cc SC |
2054 | } |
2055 | else | |
2056 | { | |
2057 | event.Skip() ; | |
2058 | } | |
2059 | } | |
2060 |