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