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