]>
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 | ||
baf52e1c SC |
697 | /* |
698 | WindowRef window = (WindowRef) MacGetRootWindow() ; | |
699 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
700 | if ( win == NULL && win->m_isBeingDeleted ) | |
701 | return FALSE ; | |
702 | */ | |
6264b550 | 703 | MacSuperShown( show ) ; |
baf52e1c SC |
704 | Refresh() ; |
705 | /* | |
6264b550 RR |
706 | if ( !show ) |
707 | { | |
6264b550 RR |
708 | if ( win && !win->m_isBeingDeleted ) |
709 | Refresh() ; | |
710 | } | |
711 | else | |
712 | { | |
713 | Refresh() ; | |
714 | } | |
baf52e1c | 715 | */ |
e7549107 | 716 | return TRUE; |
e9576ca5 SC |
717 | } |
718 | ||
e766c8a9 | 719 | void wxWindowMac::MacSuperShown( bool show ) |
8208e181 | 720 | { |
6264b550 RR |
721 | wxNode *node = GetChildren().First(); |
722 | while ( node ) | |
723 | { | |
724 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
725 | if ( child->m_isShown ) | |
726 | child->MacSuperShown( show ) ; | |
727 | node = node->Next(); | |
728 | } | |
8208e181 SC |
729 | } |
730 | ||
1c310985 SC |
731 | void wxWindowMac::MacSuperEnabled( bool enabled ) |
732 | { | |
1c469f7f SC |
733 | if ( !IsTopLevel() ) |
734 | { | |
735 | // to be absolutely correct we'd have to invalidate (with eraseBkground | |
736 | // because unter MacOSX the frames are drawn with an addXXX mode) | |
737 | // the borders area | |
738 | } | |
1c310985 SC |
739 | wxNode *node = GetChildren().First(); |
740 | while ( node ) | |
741 | { | |
742 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
743 | if ( child->m_isShown ) | |
744 | child->MacSuperEnabled( enabled ) ; | |
745 | node = node->Next(); | |
746 | } | |
747 | } | |
748 | ||
e766c8a9 | 749 | bool wxWindowMac::MacIsReallyShown() const |
c809f3be | 750 | { |
6264b550 RR |
751 | if ( m_isShown && (m_parent != NULL) ) { |
752 | return m_parent->MacIsReallyShown(); | |
753 | } | |
754 | return m_isShown; | |
755 | /* | |
756 | bool status = m_isShown ; | |
757 | wxWindowMac * win = this ; | |
758 | while ( status && win->m_parent != NULL ) | |
759 | { | |
760 | win = win->m_parent ; | |
761 | status = win->m_isShown ; | |
762 | } | |
763 | return status ; | |
5fde6fcc | 764 | */ |
c809f3be SC |
765 | } |
766 | ||
e766c8a9 | 767 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 768 | { |
6264b550 RR |
769 | wxClientDC dc ( (wxWindowMac*)this ) ; |
770 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
771 | } |
772 | ||
e766c8a9 | 773 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 774 | { |
6264b550 RR |
775 | wxClientDC dc ( (wxWindowMac*)this ) ; |
776 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
777 | } |
778 | ||
e766c8a9 | 779 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 780 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 781 | { |
e7549107 SC |
782 | const wxFont *fontToUse = theFont; |
783 | if ( !fontToUse ) | |
784 | fontToUse = &m_font; | |
7c74e7fe | 785 | |
e766c8a9 | 786 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 787 | long lx,ly,ld,le ; |
5fde6fcc | 788 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 789 | if ( externalLeading ) |
6264b550 | 790 | *externalLeading = le ; |
2f1ae414 | 791 | if ( descent ) |
6264b550 | 792 | *descent = ld ; |
2f1ae414 | 793 | if ( x ) |
6264b550 | 794 | *x = lx ; |
2f1ae414 | 795 | if ( y ) |
6264b550 | 796 | *y = ly ; |
e9576ca5 SC |
797 | } |
798 | ||
0a67a93b | 799 | /* |
1c310985 SC |
800 | * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect |
801 | * we always intersect with the entire window, not only with the client area | |
802 | */ | |
803 | ||
e766c8a9 | 804 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 805 | { |
94abc21f SC |
806 | if ( MacGetTopLevelWindow() == NULL ) |
807 | return ; | |
808 | ||
1c310985 SC |
809 | wxPoint client ; |
810 | client = GetClientAreaOrigin( ) ; | |
811 | Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ; | |
812 | if ( rect ) | |
6264b550 | 813 | { |
1c310985 SC |
814 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; |
815 | SectRect( &clientrect , &r , &clientrect ) ; | |
6264b550 | 816 | } |
1c310985 | 817 | if ( !EmptyRect( &clientrect ) ) |
e9576ca5 | 818 | { |
1c310985 SC |
819 | int top = 0 , left = 0 ; |
820 | ||
821 | MacClientToRootWindow( &left , &top ) ; | |
822 | OffsetRect( &clientrect , left , top ) ; | |
823 | ||
824 | MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; | |
e9576ca5 SC |
825 | } |
826 | } | |
827 | ||
e7549107 SC |
828 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
829 | // --------------------------------------------------------------------------- | |
e9576ca5 | 830 | // Caret manipulation |
e7549107 SC |
831 | // --------------------------------------------------------------------------- |
832 | ||
e766c8a9 | 833 | void wxWindowMac::CreateCaret(int w, int h) |
e9576ca5 | 834 | { |
e7549107 | 835 | SetCaret(new wxCaret(this, w, h)); |
e9576ca5 SC |
836 | } |
837 | ||
e766c8a9 | 838 | void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
e9576ca5 | 839 | { |
e7549107 | 840 | wxFAIL_MSG("not implemented"); |
e9576ca5 SC |
841 | } |
842 | ||
e766c8a9 | 843 | void wxWindowMac::ShowCaret(bool show) |
e9576ca5 | 844 | { |
e7549107 SC |
845 | wxCHECK_RET( m_caret, "no caret to show" ); |
846 | ||
847 | m_caret->Show(show); | |
e9576ca5 SC |
848 | } |
849 | ||
e766c8a9 | 850 | void wxWindowMac::DestroyCaret() |
e9576ca5 | 851 | { |
e7549107 | 852 | SetCaret(NULL); |
e9576ca5 SC |
853 | } |
854 | ||
e766c8a9 | 855 | void wxWindowMac::SetCaretPos(int x, int y) |
e9576ca5 | 856 | { |
e7549107 SC |
857 | wxCHECK_RET( m_caret, "no caret to move" ); |
858 | ||
859 | m_caret->Move(x, y); | |
e9576ca5 SC |
860 | } |
861 | ||
e766c8a9 | 862 | void wxWindowMac::GetCaretPos(int *x, int *y) const |
e9576ca5 | 863 | { |
e7549107 SC |
864 | wxCHECK_RET( m_caret, "no caret to get position of" ); |
865 | ||
866 | m_caret->GetPosition(x, y); | |
e9576ca5 | 867 | } |
e7549107 | 868 | #endif // wxUSE_CARET |
e9576ca5 | 869 | |
e766c8a9 | 870 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 871 | { |
519cb848 | 872 | // actually this is a windows-only concept |
e9576ca5 SC |
873 | return NULL; |
874 | } | |
875 | ||
e9576ca5 | 876 | // Coordinates relative to the window |
e766c8a9 | 877 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 878 | { |
519cb848 | 879 | // We really dont move the mouse programmatically under mac |
e9576ca5 SC |
880 | } |
881 | ||
94abc21f | 882 | const wxBrush& wxWindowMac::MacGetBackgroundBrush() |
e9576ca5 | 883 | { |
a756f210 | 884 | if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) |
1c310985 | 885 | { |
94abc21f | 886 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ; |
1c310985 | 887 | } |
a756f210 | 888 | else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) |
94abc21f SC |
889 | { |
890 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
891 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
892 | // either a non gray background color or a non control window | |
893 | ||
76a5e5d2 | 894 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
94abc21f SC |
895 | |
896 | wxWindowMac* parent = GetParent() ; | |
897 | while( parent ) | |
898 | { | |
899 | if ( parent->MacGetRootWindow() != window ) | |
900 | { | |
901 | // we are in a different window on the mac system | |
902 | parent = NULL ; | |
903 | break ; | |
904 | } | |
905 | ||
906 | { | |
a756f210 VS |
907 | if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) |
908 | && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
94abc21f SC |
909 | { |
910 | // if we have any other colours in the hierarchy | |
911 | m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ; | |
912 | break ; | |
913 | } | |
914 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
915 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
916 | { | |
7d9d1fd7 SC |
917 | Rect extent = { 0 , 0 , 0 , 0 } ; |
918 | int x , y ; | |
919 | x = y = 0 ; | |
baf52e1c | 920 | wxSize size = parent->GetSize() ; |
7d9d1fd7 SC |
921 | parent->MacClientToRootWindow( &x , &y ) ; |
922 | extent.left = x ; | |
923 | extent.top = y ; | |
924 | extent.top-- ; | |
925 | extent.right = x + size.x ; | |
926 | extent.bottom = y + size.y ; | |
76a5e5d2 | 927 | m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive |
94abc21f SC |
928 | break ; |
929 | } | |
930 | } | |
931 | parent = parent->GetParent() ; | |
932 | } | |
933 | if ( !parent ) | |
934 | { | |
935 | m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive | |
936 | } | |
937 | } | |
938 | else | |
939 | { | |
940 | m_macBackgroundBrush.SetColour( m_backgroundColour ) ; | |
941 | } | |
942 | ||
943 | return m_macBackgroundBrush ; | |
1c310985 | 944 | |
94abc21f SC |
945 | } |
946 | ||
947 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) | |
948 | { | |
949 | event.GetDC()->Clear() ; | |
1c310985 SC |
950 | } |
951 | ||
952 | void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) | |
953 | { | |
de043984 SC |
954 | wxWindowDC dc(this) ; |
955 | wxMacPortSetter helper(&dc) ; | |
956 | ||
76a5e5d2 | 957 | MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ; |
e9576ca5 SC |
958 | } |
959 | ||
e766c8a9 | 960 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 961 | { |
1c310985 SC |
962 | if ( orient == wxHORIZONTAL ) |
963 | { | |
964 | if ( m_hScrollBar ) | |
965 | return m_hScrollBar->GetThumbPosition() ; | |
966 | } | |
967 | else | |
968 | { | |
969 | if ( m_vScrollBar ) | |
970 | return m_vScrollBar->GetThumbPosition() ; | |
971 | } | |
e9576ca5 SC |
972 | return 0; |
973 | } | |
974 | ||
975 | // This now returns the whole range, not just the number | |
976 | // of positions that we can scroll. | |
e766c8a9 | 977 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 978 | { |
1c310985 SC |
979 | if ( orient == wxHORIZONTAL ) |
980 | { | |
981 | if ( m_hScrollBar ) | |
982 | return m_hScrollBar->GetRange() ; | |
983 | } | |
984 | else | |
985 | { | |
986 | if ( m_vScrollBar ) | |
987 | return m_vScrollBar->GetRange() ; | |
988 | } | |
e9576ca5 SC |
989 | return 0; |
990 | } | |
991 | ||
e766c8a9 | 992 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 993 | { |
1c310985 SC |
994 | if ( orient == wxHORIZONTAL ) |
995 | { | |
996 | if ( m_hScrollBar ) | |
997 | return m_hScrollBar->GetThumbSize() ; | |
998 | } | |
999 | else | |
1000 | { | |
1001 | if ( m_vScrollBar ) | |
1002 | return m_vScrollBar->GetThumbSize() ; | |
1003 | } | |
e9576ca5 SC |
1004 | return 0; |
1005 | } | |
1006 | ||
e766c8a9 | 1007 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 1008 | { |
1c310985 | 1009 | if ( orient == wxHORIZONTAL ) |
6264b550 | 1010 | { |
1c310985 SC |
1011 | if ( m_hScrollBar ) |
1012 | m_hScrollBar->SetThumbPosition( pos ) ; | |
6264b550 RR |
1013 | } |
1014 | else | |
1015 | { | |
1c310985 SC |
1016 | if ( m_vScrollBar ) |
1017 | m_vScrollBar->SetThumbPosition( pos ) ; | |
6264b550 | 1018 | } |
2f1ae414 SC |
1019 | } |
1020 | ||
7d9d1fd7 | 1021 | void wxWindowMac::MacPaintBorders( int left , int top ) |
2f1ae414 | 1022 | { |
1c310985 | 1023 | if( IsTopLevel() ) |
6264b550 RR |
1024 | return ; |
1025 | ||
1026 | RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; | |
1027 | RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; | |
1028 | RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; | |
1029 | RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; | |
1030 | PenNormal() ; | |
2f1ae414 SC |
1031 | |
1032 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1033 | { | |
1c310985 | 1034 | #if wxMAC_USE_THEME_BORDER |
ed60b502 RR |
1035 | Rect rect = { top , left , m_height + top , m_width + left } ; |
1036 | SInt32 border = 0 ; | |
1037 | /* | |
1038 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1039 | InsetRect( &rect , border , border ); | |
1c310985 SC |
1040 | DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; |
1041 | */ | |
1042 | ||
1043 | DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
1044 | #else | |
ed60b502 | 1045 | bool sunken = HasFlag( wxSUNKEN_BORDER ) ; |
653b2449 | 1046 | RGBForeColor( &face ); |
7d9d1fd7 SC |
1047 | MoveTo( left + 0 , top + m_height - 2 ); |
1048 | LineTo( left + 0 , top + 0 ); | |
1049 | LineTo( left + m_width - 2 , top + 0 ); | |
653b2449 | 1050 | |
7d9d1fd7 SC |
1051 | MoveTo( left + 2 , top + m_height - 3 ); |
1052 | LineTo( left + m_width - 3 , top + m_height - 3 ); | |
1053 | LineTo( left + m_width - 3 , top + 2 ); | |
653b2449 SC |
1054 | |
1055 | RGBForeColor( sunken ? &face : &black ); | |
7d9d1fd7 SC |
1056 | MoveTo( left + 0 , top + m_height - 1 ); |
1057 | LineTo( left + m_width - 1 , top + m_height - 1 ); | |
1058 | LineTo( left + m_width - 1 , top + 0 ); | |
653b2449 SC |
1059 | |
1060 | RGBForeColor( sunken ? &shadow : &white ); | |
7d9d1fd7 SC |
1061 | MoveTo( left + 1 , top + m_height - 3 ); |
1062 | LineTo( left + 1, top + 1 ); | |
1063 | LineTo( left + m_width - 3 , top + 1 ); | |
653b2449 SC |
1064 | |
1065 | RGBForeColor( sunken ? &white : &shadow ); | |
7d9d1fd7 SC |
1066 | MoveTo( left + 1 , top + m_height - 2 ); |
1067 | LineTo( left + m_width - 2 , top + m_height - 2 ); | |
1068 | LineTo( left + m_width - 2 , top + 1 ); | |
653b2449 SC |
1069 | |
1070 | RGBForeColor( sunken ? &black : &face ); | |
7d9d1fd7 SC |
1071 | MoveTo( left + 2 , top + m_height - 4 ); |
1072 | LineTo( left + 2 , top + 2 ); | |
1073 | LineTo( left + m_width - 4 , top + 2 ); | |
1c310985 | 1074 | #endif |
8208e181 SC |
1075 | } |
1076 | else if (HasFlag(wxSIMPLE_BORDER)) | |
1077 | { | |
ed60b502 | 1078 | Rect rect = { top , left , m_height + top , m_width + left } ; |
6264b550 RR |
1079 | RGBForeColor( &black ) ; |
1080 | FrameRect( &rect ) ; | |
2f1ae414 | 1081 | } |
8208e181 SC |
1082 | } |
1083 | ||
abda5788 SC |
1084 | void wxWindowMac::RemoveChild( wxWindowBase *child ) |
1085 | { | |
1086 | if ( child == m_hScrollBar ) | |
1087 | m_hScrollBar = NULL ; | |
1088 | if ( child == m_vScrollBar ) | |
1089 | m_vScrollBar = NULL ; | |
1090 | ||
1091 | wxWindowBase::RemoveChild( child ) ; | |
1092 | } | |
1093 | ||
e9576ca5 | 1094 | // New function that will replace some of the above. |
e766c8a9 | 1095 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
1096 | int range, bool refresh) |
1097 | { | |
6264b550 RR |
1098 | if ( orient == wxHORIZONTAL ) |
1099 | { | |
1100 | if ( m_hScrollBar ) | |
1101 | { | |
1102 | if ( range == 0 || thumbVisible >= range ) | |
1103 | { | |
1104 | if ( m_hScrollBar->IsShown() ) | |
1105 | m_hScrollBar->Show(false) ; | |
1106 | } | |
1107 | else | |
1108 | { | |
1109 | if ( !m_hScrollBar->IsShown() ) | |
1110 | m_hScrollBar->Show(true) ; | |
1111 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1112 | } | |
1113 | } | |
1114 | } | |
1115 | else | |
1116 | { | |
1117 | if ( m_vScrollBar ) | |
1118 | { | |
1119 | if ( range == 0 || thumbVisible >= range ) | |
1120 | { | |
1121 | if ( m_vScrollBar->IsShown() ) | |
1122 | m_vScrollBar->Show(false) ; | |
1123 | } | |
1124 | else | |
1125 | { | |
1126 | if ( !m_vScrollBar->IsShown() ) | |
1127 | m_vScrollBar->Show(true) ; | |
1128 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1129 | } | |
1130 | } | |
1131 | } | |
1132 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
1133 | } |
1134 | ||
1135 | // Does a physical scroll | |
e766c8a9 | 1136 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 1137 | { |
de043984 SC |
1138 | wxClientDC dc(this) ; |
1139 | wxMacPortSetter helper(&dc) ; | |
1140 | ||
6264b550 RR |
1141 | { |
1142 | int width , height ; | |
1143 | GetClientSize( &width , &height ) ; | |
1144 | ||
de043984 | 1145 | Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ; |
6264b550 RR |
1146 | RgnHandle updateRgn = NewRgn() ; |
1147 | ClipRect( &scrollrect ) ; | |
1148 | if ( rect ) | |
1149 | { | |
de043984 SC |
1150 | Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , |
1151 | dc.XLOG2DEVMAC(rect->x + rect->width) } ; | |
6264b550 RR |
1152 | SectRect( &scrollrect , &r , &scrollrect ) ; |
1153 | } | |
1154 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
76a5e5d2 | 1155 | InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ; |
6264b550 RR |
1156 | DisposeRgn( updateRgn ) ; |
1157 | } | |
1158 | ||
1159 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1160 | { | |
1161 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1162 | if (child == m_vScrollBar) continue; | |
1163 | if (child == m_hScrollBar) continue; | |
1164 | if (child->IsTopLevel()) continue; | |
1165 | int x,y; | |
1166 | child->GetPosition( &x, &y ); | |
1167 | int w,h; | |
1168 | child->GetSize( &w, &h ); | |
1169 | child->SetSize( x+dx, y+dy, w, h ); | |
1170 | } | |
1171 | ||
e9576ca5 SC |
1172 | } |
1173 | ||
e766c8a9 | 1174 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 1175 | { |
6264b550 RR |
1176 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) |
1177 | { | |
1178 | wxScrollWinEvent wevent; | |
1179 | wevent.SetPosition(event.GetPosition()); | |
1180 | wevent.SetOrientation(event.GetOrientation()); | |
1181 | wevent.m_eventObject = this; | |
1182 | ||
1183 | if (event.m_eventType == wxEVT_SCROLL_TOP) { | |
1184 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
1185 | } else | |
1186 | if (event.m_eventType == wxEVT_SCROLL_BOTTOM) { | |
1187 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1188 | } else | |
1189 | if (event.m_eventType == wxEVT_SCROLL_LINEUP) { | |
1190 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1191 | } else | |
1192 | if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) { | |
1193 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1194 | } else | |
1195 | if (event.m_eventType == wxEVT_SCROLL_PAGEUP) { | |
1196 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1197 | } else | |
1198 | if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) { | |
1199 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1200 | } else | |
1201 | if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) { | |
1202 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1203 | } | |
1204 | ||
1205 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
1206 | } |
1207 | } | |
1208 | ||
e9576ca5 | 1209 | // Get the window with the focus |
e766c8a9 | 1210 | wxWindowMac *wxWindowBase::FindFocus() |
e9576ca5 | 1211 | { |
6264b550 | 1212 | return gFocusWindow ; |
519cb848 SC |
1213 | } |
1214 | ||
e7549107 | 1215 | #if WXWIN_COMPATIBILITY |
e9576ca5 SC |
1216 | // If nothing defined for this, try the parent. |
1217 | // E.g. we may be a button loaded from a resource, with no callback function | |
1218 | // defined. | |
e766c8a9 | 1219 | void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event) |
e9576ca5 | 1220 | { |
e7549107 SC |
1221 | if ( GetEventHandler()->ProcessEvent(event) ) |
1222 | return; | |
1223 | if ( m_parent ) | |
1224 | m_parent->GetEventHandler()->OnCommand(win, event); | |
e9576ca5 | 1225 | } |
e7549107 | 1226 | #endif // WXWIN_COMPATIBILITY_2 |
e9576ca5 | 1227 | |
e7549107 | 1228 | #if WXWIN_COMPATIBILITY |
e766c8a9 | 1229 | wxObject* wxWindowMac::GetChild(int number) const |
e9576ca5 | 1230 | { |
e7549107 SC |
1231 | // Return a pointer to the Nth object in the Panel |
1232 | wxNode *node = GetChildren().First(); | |
1233 | int n = number; | |
1234 | while (node && n--) | |
1235 | node = node->Next(); | |
1236 | if ( node ) | |
519cb848 | 1237 | { |
e7549107 SC |
1238 | wxObject *obj = (wxObject *)node->Data(); |
1239 | return(obj); | |
519cb848 SC |
1240 | } |
1241 | else | |
e7549107 | 1242 | return NULL; |
e9576ca5 | 1243 | } |
e7549107 | 1244 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 1245 | |
e766c8a9 | 1246 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
1247 | { |
1248 | // panel wants to track the window which was the last to have focus in it, | |
1249 | // so we want to set ourselves as the window which last had focus | |
1250 | // | |
1251 | // notice that it's also important to do it upwards the tree becaus | |
1252 | // otherwise when the top level panel gets focus, it won't set it back to | |
1253 | // us, but to some other sibling | |
c1fb8167 SC |
1254 | |
1255 | // CS:don't know if this is still needed: | |
1256 | //wxChildFocusEvent eventFocus(this); | |
1257 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b SC |
1258 | |
1259 | event.Skip(); | |
1260 | } | |
1261 | ||
e766c8a9 | 1262 | void wxWindowMac::Clear() |
e9576ca5 | 1263 | { |
1c310985 SC |
1264 | wxClientDC dc(this); |
1265 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1266 | dc.SetBackground(brush); | |
1267 | dc.Clear(); | |
e9576ca5 SC |
1268 | } |
1269 | ||
e7549107 | 1270 | // Setup background and foreground colours correctly |
e766c8a9 | 1271 | void wxWindowMac::SetupColours() |
e9576ca5 | 1272 | { |
e7549107 SC |
1273 | if ( GetParent() ) |
1274 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
e9576ca5 SC |
1275 | } |
1276 | ||
e766c8a9 | 1277 | void wxWindowMac::OnIdle(wxIdleEvent& event) |
e9576ca5 | 1278 | { |
519cb848 SC |
1279 | /* |
1280 | // Check if we need to send a LEAVE event | |
1281 | if (m_mouseInWindow) | |
1282 | { | |
1283 | POINT pt; | |
1284 | ::GetCursorPos(&pt); | |
1285 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
1286 | { | |
1287 | // Generate a LEAVE event | |
1288 | m_mouseInWindow = FALSE; | |
1289 | MSWOnMouseLeave(pt.x, pt.y, 0); | |
1290 | } | |
e9576ca5 SC |
1291 | } |
1292 | */ | |
1293 | ||
1294 | // This calls the UI-update mechanism (querying windows for | |
1295 | // menu/toolbar/control state information) | |
6264b550 | 1296 | UpdateWindowUI(); |
e9576ca5 SC |
1297 | } |
1298 | ||
1299 | // Raise the window to the top of the Z order | |
e766c8a9 | 1300 | void wxWindowMac::Raise() |
e9576ca5 | 1301 | { |
e9576ca5 SC |
1302 | } |
1303 | ||
1304 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 1305 | void wxWindowMac::Lower() |
e9576ca5 | 1306 | { |
e9576ca5 SC |
1307 | } |
1308 | ||
e766c8a9 | 1309 | void wxWindowMac::DoSetClientSize(int width, int height) |
519cb848 | 1310 | { |
6264b550 RR |
1311 | if ( width != -1 || height != -1 ) |
1312 | { | |
1313 | ||
1314 | if ( width != -1 && m_vScrollBar ) | |
1315 | width += MAC_SCROLLBAR_SIZE ; | |
1316 | if ( height != -1 && m_vScrollBar ) | |
1317 | height += MAC_SCROLLBAR_SIZE ; | |
519cb848 | 1318 | |
6264b550 RR |
1319 | width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1320 | height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
2f1ae414 | 1321 | |
6264b550 RR |
1322 | DoSetSize( -1 , -1 , width , height ) ; |
1323 | } | |
519cb848 SC |
1324 | } |
1325 | ||
519cb848 | 1326 | |
e766c8a9 | 1327 | wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; |
519cb848 | 1328 | |
e766c8a9 | 1329 | bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) |
519cb848 | 1330 | { |
a07c1212 SC |
1331 | if ( IsTopLevel() ) |
1332 | { | |
1333 | if ((point.x < 0) || (point.y < 0) || | |
1334 | (point.x > (m_width)) || (point.y > (m_height))) | |
1335 | return FALSE; | |
1336 | } | |
1337 | else | |
1338 | { | |
1339 | if ((point.x < m_x) || (point.y < m_y) || | |
1340 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1341 | return FALSE; | |
1342 | } | |
6264b550 | 1343 | |
76a5e5d2 | 1344 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
519cb848 | 1345 | |
6264b550 | 1346 | wxPoint newPoint( point ) ; |
519cb848 | 1347 | |
a07c1212 SC |
1348 | if ( !IsTopLevel() ) |
1349 | { | |
1350 | newPoint.x -= m_x; | |
1351 | newPoint.y -= m_y; | |
1352 | } | |
6264b550 RR |
1353 | |
1354 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1355 | { | |
1356 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1357 | // added the m_isShown test --dmazzoni | |
1c310985 | 1358 | if ( child->MacGetRootWindow() == window && child->m_isShown ) |
6264b550 RR |
1359 | { |
1360 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1361 | return TRUE; | |
1362 | } | |
1363 | } | |
519cb848 | 1364 | |
6264b550 RR |
1365 | *outWin = this ; |
1366 | return TRUE; | |
519cb848 SC |
1367 | } |
1368 | ||
e766c8a9 | 1369 | bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) |
519cb848 | 1370 | { |
6264b550 | 1371 | WindowRef window ; |
ed60b502 | 1372 | |
6264b550 RR |
1373 | Point pt = { screenpoint.y , screenpoint.x } ; |
1374 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1375 | { | |
ed60b502 | 1376 | |
a07c1212 SC |
1377 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; |
1378 | if ( win ) | |
1379 | { | |
ed60b502 RR |
1380 | // No, this yields the CLIENT are, we need the whole frame. RR. |
1381 | // point = win->ScreenToClient( point ) ; | |
1382 | ||
1383 | GrafPtr port; | |
1384 | ::GetPort( &port ) ; | |
1385 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
1386 | ::GlobalToLocal( &pt ) ; | |
1387 | ::SetPort( port ) ; | |
1388 | ||
1389 | wxPoint point( pt.h, pt.v ) ; | |
1390 | ||
6264b550 | 1391 | return win->MacGetWindowFromPointSub( point , outWin ) ; |
a07c1212 | 1392 | } |
6264b550 RR |
1393 | } |
1394 | return FALSE ; | |
519cb848 SC |
1395 | } |
1396 | ||
1397 | extern int wxBusyCursorCount ; | |
32b5be3d | 1398 | static wxWindow *gs_lastWhich = NULL; |
519cb848 | 1399 | |
e766c8a9 | 1400 | bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) |
519cb848 | 1401 | { |
6264b550 RR |
1402 | if ((event.m_x < m_x) || (event.m_y < m_y) || |
1403 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1404 | return FALSE; | |
1405 | ||
1406 | ||
4ac219f6 | 1407 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxSpinCtrl ) )) |
6264b550 RR |
1408 | return FALSE ; |
1409 | ||
76a5e5d2 | 1410 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
6264b550 RR |
1411 | |
1412 | event.m_x -= m_x; | |
1413 | event.m_y -= m_y; | |
1414 | ||
1415 | int x = event.m_x ; | |
1416 | int y = event.m_y ; | |
1417 | ||
1418 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1419 | { | |
1420 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1c310985 | 1421 | if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() ) |
6264b550 RR |
1422 | { |
1423 | if (child->MacDispatchMouseEvent(event)) | |
1424 | return TRUE; | |
1425 | } | |
7810c95b | 1426 | } |
2f1ae414 | 1427 | |
6264b550 RR |
1428 | event.m_x = x ; |
1429 | event.m_y = y ; | |
2e6857fa | 1430 | event.SetEventObject( this ) ; |
6264b550 RR |
1431 | |
1432 | if ( wxBusyCursorCount == 0 ) | |
1433 | { | |
1434 | m_cursor.MacInstall() ; | |
1435 | } | |
1436 | ||
1437 | if ( event.GetEventType() == wxEVT_LEFT_DOWN ) | |
1438 | { | |
1439 | // set focus to this window | |
1440 | if (AcceptsFocus() && FindFocus()!=this) | |
1441 | SetFocus(); | |
1442 | } | |
1443 | ||
2f1ae414 SC |
1444 | #if wxUSE_TOOLTIPS |
1445 | if ( event.GetEventType() == wxEVT_MOTION | |
6264b550 RR |
1446 | || event.GetEventType() == wxEVT_ENTER_WINDOW |
1447 | || event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
2f1ae414 SC |
1448 | wxToolTip::RelayEvent( this , event); |
1449 | #endif // wxUSE_TOOLTIPS | |
ed60b502 | 1450 | |
32b5be3d RR |
1451 | if (gs_lastWhich != this) |
1452 | { | |
1453 | gs_lastWhich = this; | |
1454 | ||
1455 | // Double clicks must always occur on the same window | |
1456 | if (event.GetEventType() == wxEVT_LEFT_DCLICK) | |
1457 | event.SetEventType( wxEVT_LEFT_DOWN ); | |
1458 | if (event.GetEventType() == wxEVT_RIGHT_DCLICK) | |
1459 | event.SetEventType( wxEVT_RIGHT_DOWN ); | |
1460 | ||
1461 | // Same for mouse up events | |
1462 | if (event.GetEventType() == wxEVT_LEFT_UP) | |
1463 | return TRUE; | |
1464 | if (event.GetEventType() == wxEVT_RIGHT_UP) | |
1465 | return TRUE; | |
1466 | } | |
1467 | ||
6264b550 | 1468 | GetEventHandler()->ProcessEvent( event ) ; |
ed60b502 | 1469 | |
6264b550 | 1470 | return TRUE; |
519cb848 SC |
1471 | } |
1472 | ||
e766c8a9 | 1473 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 1474 | { |
6264b550 RR |
1475 | if ( m_tooltip ) |
1476 | { | |
1477 | return m_tooltip->GetTip() ; | |
1478 | } | |
1479 | return "" ; | |
2f1ae414 | 1480 | } |
6264b550 | 1481 | |
1c310985 | 1482 | void wxWindowMac::Update() |
519cb848 | 1483 | { |
1c310985 SC |
1484 | wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ; |
1485 | if ( win ) | |
f1759123 | 1486 | { |
1c310985 | 1487 | win->MacUpdate( 0 ) ; |
bec721ec | 1488 | #if TARGET_API_MAC_CARBON |
ed60b502 RR |
1489 | if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) |
1490 | { | |
1491 | QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; | |
1492 | } | |
bec721ec | 1493 | #endif |
ed60b502 | 1494 | } |
519cb848 SC |
1495 | } |
1496 | ||
1c310985 | 1497 | wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const |
519cb848 | 1498 | { |
1c310985 | 1499 | wxTopLevelWindowMac* win = NULL ; |
76a5e5d2 | 1500 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
1c310985 | 1501 | if ( window ) |
6264b550 | 1502 | { |
1c310985 SC |
1503 | win = wxFindWinFromMacWindow( window ) ; |
1504 | } | |
1505 | return win ; | |
519cb848 SC |
1506 | } |
1507 | ||
94abc21f SC |
1508 | const wxRegion& wxWindowMac::MacGetVisibleRegion() |
1509 | { | |
1510 | RgnHandle visRgn = NewRgn() ; | |
de043984 | 1511 | RgnHandle tempRgn = NewRgn() ; |
94abc21f SC |
1512 | |
1513 | SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; | |
1514 | ||
de043984 SC |
1515 | //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox |
1516 | if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) | |
94abc21f | 1517 | { |
de043984 SC |
1518 | int borderTop = 14 ; |
1519 | int borderOther = 4 ; | |
1520 | ||
1521 | SetRectRgn( tempRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; | |
1522 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
1523 | } | |
94abc21f | 1524 | |
a07c1212 | 1525 | if ( !IsTopLevel() ) |
de043984 | 1526 | { |
a07c1212 SC |
1527 | wxWindow* parent = GetParent() ; |
1528 | while( parent ) | |
1529 | { | |
1530 | wxSize size = parent->GetSize() ; | |
1531 | int x , y ; | |
1532 | x = y = 0 ; | |
1533 | parent->MacWindowToRootWindow( &x, &y ) ; | |
1534 | MacRootWindowToWindow( &x , &y ) ; | |
1535 | SetRectRgn( tempRgn , x , y , x + size.x , y + size.y ) ; | |
1536 | SectRgn( visRgn , tempRgn , visRgn ) ; | |
1537 | if ( parent->IsTopLevel() ) | |
1538 | break ; | |
1539 | parent = parent->GetParent() ; | |
1540 | } | |
de043984 SC |
1541 | } |
1542 | if ( GetWindowStyle() & wxCLIP_CHILDREN ) | |
1543 | { | |
94abc21f SC |
1544 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) |
1545 | { | |
1546 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1547 | ||
1548 | if ( !child->IsTopLevel() && child->IsShown() ) | |
1549 | { | |
de043984 SC |
1550 | SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; |
1551 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
94abc21f SC |
1552 | } |
1553 | } | |
94abc21f SC |
1554 | } |
1555 | ||
1556 | if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) | |
1557 | { | |
94abc21f SC |
1558 | bool thisWindowThrough = false ; |
1559 | for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next()) | |
1560 | { | |
1561 | wxWindowMac *sibling = (wxWindowMac*)node->Data(); | |
1562 | if ( sibling == this ) | |
1563 | { | |
1564 | thisWindowThrough = true ; | |
1565 | continue ; | |
1566 | } | |
1567 | if( !thisWindowThrough ) | |
1568 | { | |
1569 | continue ; | |
1570 | } | |
1571 | ||
1572 | if ( !sibling->IsTopLevel() && sibling->IsShown() ) | |
1573 | { | |
de043984 SC |
1574 | 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 ) ; |
1575 | DiffRgn( visRgn , tempRgn , visRgn ) ; | |
94abc21f SC |
1576 | } |
1577 | } | |
94abc21f SC |
1578 | } |
1579 | m_macVisibleRegion = visRgn ; | |
1580 | DisposeRgn( visRgn ) ; | |
de043984 | 1581 | DisposeRgn( tempRgn ) ; |
94abc21f SC |
1582 | return m_macVisibleRegion ; |
1583 | } | |
1584 | ||
76a5e5d2 | 1585 | void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) |
519cb848 | 1586 | { |
76a5e5d2 | 1587 | RgnHandle updatergn = (RgnHandle) updatergnr ; |
6264b550 | 1588 | // updatergn is always already clipped to our boundaries |
94abc21f | 1589 | // it is in window coordinates, not in client coordinates |
1c310985 | 1590 | |
76a5e5d2 | 1591 | WindowRef window = (WindowRef) MacGetRootWindow() ; |
6264b550 RR |
1592 | |
1593 | { | |
94abc21f | 1594 | // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates |
1c310985 SC |
1595 | RgnHandle ownUpdateRgn = NewRgn() ; |
1596 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
94abc21f | 1597 | |
76a5e5d2 | 1598 | SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ; |
6264b550 | 1599 | |
94abc21f | 1600 | // newupdate is the update region in client coordinates |
1c310985 SC |
1601 | RgnHandle newupdate = NewRgn() ; |
1602 | wxSize point = GetClientSize() ; | |
1603 | wxPoint origin = GetClientAreaOrigin() ; | |
1c310985 SC |
1604 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; |
1605 | SectRgn( newupdate , ownUpdateRgn , newupdate ) ; | |
1606 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1607 | m_updateRegion = newupdate ; | |
1608 | DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion | |
94abc21f | 1609 | |
e8788ed0 | 1610 | if ( erase && !EmptyRgn(ownUpdateRgn) ) |
1c310985 SC |
1611 | { |
1612 | wxWindowDC dc(this); | |
e8788ed0 | 1613 | dc.SetClippingRegion(wxRegion(ownUpdateRgn)); |
1c310985 SC |
1614 | wxEraseEvent eevent( GetId(), &dc ); |
1615 | eevent.SetEventObject( this ); | |
1616 | GetEventHandler()->ProcessEvent( eevent ); | |
1617 | ||
1618 | wxNcPaintEvent eventNc( GetId() ); | |
1619 | eventNc.SetEventObject( this ); | |
1620 | GetEventHandler()->ProcessEvent( eventNc ); | |
6264b550 | 1621 | } |
1c310985 | 1622 | DisposeRgn( ownUpdateRgn ) ; |
1c310985 | 1623 | if ( !m_updateRegion.Empty() ) |
6264b550 | 1624 | { |
1c310985 SC |
1625 | wxPaintEvent event; |
1626 | event.m_timeStamp = time ; | |
1627 | event.SetEventObject(this); | |
1628 | GetEventHandler()->ProcessEvent(event); | |
1629 | } | |
6264b550 RR |
1630 | } |
1631 | ||
1c310985 | 1632 | // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively |
6264b550 | 1633 | |
1c310985 | 1634 | RgnHandle childupdate = NewRgn() ; |
6264b550 RR |
1635 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) |
1636 | { | |
94abc21f SC |
1637 | // calculate the update region for the child windows by intersecting the window rectangle with our own |
1638 | // passed in update region and then offset it to be client-wise window coordinates again | |
6264b550 RR |
1639 | wxWindowMac *child = (wxWindowMac*)node->Data(); |
1640 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1641 | SectRgn( childupdate , updatergn , childupdate ) ; | |
1642 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
1c310985 | 1643 | if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) |
6264b550 RR |
1644 | { |
1645 | // because dialogs may also be children | |
1c310985 | 1646 | child->MacRedraw( childupdate , time , erase ) ; |
6264b550 RR |
1647 | } |
1648 | } | |
1649 | DisposeRgn( childupdate ) ; | |
1650 | // eventually a draw grow box here | |
1c310985 | 1651 | |
519cb848 SC |
1652 | } |
1653 | ||
76a5e5d2 | 1654 | WXHWND wxWindowMac::MacGetRootWindow() const |
519cb848 | 1655 | { |
6264b550 RR |
1656 | wxWindowMac *iter = (wxWindowMac*)this ; |
1657 | ||
1658 | while( iter ) | |
1659 | { | |
1c310985 SC |
1660 | if ( iter->IsTopLevel() ) |
1661 | return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ; | |
519cb848 | 1662 | |
6264b550 RR |
1663 | iter = iter->GetParent() ; |
1664 | } | |
1665 | wxASSERT_MSG( 1 , "No valid mac root window" ) ; | |
1666 | return NULL ; | |
519cb848 SC |
1667 | } |
1668 | ||
e766c8a9 | 1669 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 1670 | { |
6264b550 RR |
1671 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; |
1672 | ||
1673 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
1674 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
1675 | int width, height ; | |
1676 | GetClientSize( &width , &height ) ; | |
1677 | ||
1678 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
1679 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1680 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1681 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
1682 | ||
1683 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
1684 | vSize , wxVERTICAL); | |
1685 | ||
1686 | if ( style & wxVSCROLL ) | |
1687 | { | |
1688 | ||
1689 | } | |
1690 | else | |
1691 | { | |
1692 | m_vScrollBar->Show(false) ; | |
1693 | } | |
1694 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
1695 | hSize , wxHORIZONTAL); | |
1696 | if ( style & wxHSCROLL ) | |
1697 | { | |
1698 | } | |
1699 | else | |
1700 | { | |
1701 | m_hScrollBar->Show(false) ; | |
1702 | } | |
1703 | ||
1704 | // because the create does not take into account the client area origin | |
1705 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
1706 | } |
1707 | ||
e766c8a9 | 1708 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 1709 | { |
6264b550 RR |
1710 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
1711 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
1712 | ||
1713 | // get real client area | |
1714 | ||
1715 | int width = m_width ; | |
1716 | int height = m_height ; | |
1717 | ||
1718 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
1719 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
1720 | ||
1721 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
1722 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
1723 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
1724 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
1725 | ||
1726 | int x = 0 ; | |
1727 | int y = 0 ; | |
1728 | int w = m_width ; | |
1729 | int h = m_height ; | |
1730 | ||
1731 | MacClientToRootWindow( &x , &y ) ; | |
1732 | MacClientToRootWindow( &w , &h ) ; | |
1733 | ||
1734 | wxWindowMac *iter = (wxWindowMac*)this ; | |
1735 | ||
1736 | int totW = 10000 , totH = 10000; | |
1737 | while( iter ) | |
1738 | { | |
1c310985 | 1739 | if ( iter->IsTopLevel() ) |
6264b550 RR |
1740 | { |
1741 | totW = iter->m_width ; | |
1742 | totH = iter->m_height ; | |
1743 | break ; | |
1744 | } | |
1745 | ||
1746 | iter = iter->GetParent() ; | |
1747 | } | |
1748 | ||
1749 | if ( x == 0 ) | |
1750 | { | |
1751 | hPoint.x = -1 ; | |
1752 | hSize.x += 1 ; | |
1753 | } | |
1754 | if ( y == 0 ) | |
1755 | { | |
1756 | vPoint.y = -1 ; | |
1757 | vSize.y += 1 ; | |
1758 | } | |
1759 | ||
1760 | if ( w-x >= totW ) | |
1761 | { | |
1762 | hSize.x += 1 ; | |
1763 | vPoint.x += 1 ; | |
1764 | } | |
1765 | ||
1766 | if ( h-y >= totH ) | |
1767 | { | |
1768 | vSize.y += 1 ; | |
1769 | hPoint.y += 1 ; | |
1770 | } | |
1771 | ||
1772 | if ( m_vScrollBar ) | |
1773 | { | |
1774 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
1775 | } | |
1776 | if ( m_hScrollBar ) | |
1777 | { | |
1778 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
1779 | } | |
519cb848 SC |
1780 | } |
1781 | ||
e766c8a9 | 1782 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
1783 | { |
1784 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
1785 | } | |
519cb848 | 1786 | |
76a5e5d2 | 1787 | WXWidget wxWindowMac::MacGetContainerForEmbedding() |
519cb848 | 1788 | { |
1c310985 | 1789 | return GetParent()->MacGetContainerForEmbedding() ; |
519cb848 SC |
1790 | } |
1791 | ||
e766c8a9 | 1792 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 1793 | { |
6264b550 | 1794 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 1795 | |
6264b550 RR |
1796 | wxNode *node = GetChildren().First(); |
1797 | while ( node ) | |
1798 | { | |
1799 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
1800 | child->MacSuperChangedPosition() ; | |
1801 | node = node->Next(); | |
1802 | } | |
519cb848 | 1803 | } |
519cb848 | 1804 | |
a3bf4a62 SC |
1805 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
1806 | { | |
6264b550 | 1807 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 1808 | |
6264b550 RR |
1809 | wxNode *node = GetChildren().First(); |
1810 | while ( node ) | |
1811 | { | |
1812 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
1813 | child->MacTopLevelWindowChangedPosition() ; | |
1814 | node = node->Next(); | |
1815 | } | |
a3bf4a62 | 1816 | } |
e766c8a9 | 1817 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 1818 | { |
1c310985 | 1819 | if( IsTopLevel() ) |
6264b550 | 1820 | return 0 ; |
2f1ae414 SC |
1821 | |
1822 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
1823 | { | |
ed60b502 | 1824 | SInt32 border = 3 ; |
1c310985 | 1825 | #if wxMAC_USE_THEME_BORDER |
ed60b502 RR |
1826 | #if TARGET_CARBON |
1827 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1c310985 SC |
1828 | #endif |
1829 | #endif | |
ed60b502 | 1830 | return border ; |
2f1ae414 SC |
1831 | } |
1832 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
1833 | { | |
ed60b502 | 1834 | SInt32 border = 3 ; |
1c310985 | 1835 | #if wxMAC_USE_THEME_BORDER |
ed60b502 RR |
1836 | #if TARGET_CARBON |
1837 | GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; | |
1c310985 SC |
1838 | #endif |
1839 | #endif | |
ed60b502 | 1840 | return border ; |
2f1ae414 SC |
1841 | } |
1842 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
1843 | { | |
6264b550 | 1844 | return 1 ; |
2f1ae414 | 1845 | } |
6264b550 | 1846 | return 0 ; |
2f1ae414 SC |
1847 | } |
1848 | ||
e766c8a9 | 1849 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 1850 | { |
1c310985 SC |
1851 | // they are all symmetric in mac themes |
1852 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
1853 | } |
1854 | ||
e766c8a9 | 1855 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 1856 | { |
1c310985 SC |
1857 | // they are all symmetric in mac themes |
1858 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
1859 | } |
1860 | ||
e766c8a9 | 1861 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 1862 | { |
1c310985 SC |
1863 | // they are all symmetric in mac themes |
1864 | return MacGetLeftBorderSize() ; | |
5b781a67 SC |
1865 | } |
1866 | ||
e766c8a9 | 1867 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 1868 | { |
6264b550 | 1869 | return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; |
2f1ae414 | 1870 | } |
0a67a93b | 1871 | |
e766c8a9 | 1872 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 1873 | // position. |
e766c8a9 | 1874 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 1875 | { |
59a12e90 | 1876 | pt = wxGetMousePosition(); |
e766c8a9 | 1877 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 1878 | return found; |
3723b7b1 JS |
1879 | } |
1880 | ||
1881 | // Get the current mouse position. | |
1882 | wxPoint wxGetMousePosition() | |
1883 | { | |
57591e0e JS |
1884 | int x, y; |
1885 | wxGetMousePosition(& x, & y); | |
1886 | return wxPoint(x, y); | |
3723b7b1 JS |
1887 | } |
1888 |