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