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