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