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