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