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