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