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