]>
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) | |
e766c8a9 SC |
68 | EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) |
69 | EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) | |
70 | EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) | |
71 | EVT_IDLE(wxWindowMac::OnIdle) | |
72 | EVT_SET_FOCUS(wxWindowMac::OnSetFocus) | |
e9576ca5 SC |
73 | END_EVENT_TABLE() |
74 | ||
2f1ae414 | 75 | #endif |
e9576ca5 SC |
76 | |
77 | ||
e7549107 SC |
78 | |
79 | // =========================================================================== | |
80 | // implementation | |
81 | // =========================================================================== | |
82 | ||
83 | // --------------------------------------------------------------------------- | |
e766c8a9 | 84 | // wxWindowMac utility functions |
e7549107 SC |
85 | // --------------------------------------------------------------------------- |
86 | ||
87 | // Find an item given the Macintosh Window Reference | |
88 | ||
89 | wxList *wxWinMacWindowList = NULL; | |
e766c8a9 | 90 | wxWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) |
e9576ca5 | 91 | { |
e7549107 SC |
92 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); |
93 | if (!node) | |
94 | return NULL; | |
e766c8a9 | 95 | return (wxWindowMac *)node->Data(); |
519cb848 SC |
96 | } |
97 | ||
e766c8a9 | 98 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindowMac *win) |
e7549107 SC |
99 | { |
100 | // adding NULL WindowRef is (first) surely a result of an error and | |
101 | // (secondly) breaks menu command processing | |
102 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); | |
103 | ||
104 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
105 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
106 | } | |
107 | ||
e766c8a9 | 108 | void wxRemoveMacWindowAssociation(wxWindowMac *win) |
e7549107 SC |
109 | { |
110 | wxWinMacWindowList->DeleteObject(win); | |
111 | } | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // constructors and such | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
e766c8a9 | 117 | WindowRef wxWindowMac::s_macWindowInUpdate = NULL; |
9a179dcc | 118 | |
e766c8a9 | 119 | void wxWindowMac::Init() |
519cb848 | 120 | { |
e7549107 SC |
121 | // generic |
122 | InitBase(); | |
123 | ||
0a67a93b SC |
124 | m_macEraseOnRedraw = true ; |
125 | ||
e7549107 SC |
126 | // MSW specific |
127 | m_doubleClickAllowed = 0; | |
128 | m_winCaptured = FALSE; | |
129 | ||
130 | m_isBeingDeleted = FALSE; | |
131 | ||
132 | m_useCtl3D = FALSE; | |
133 | m_mouseInWindow = FALSE; | |
134 | ||
135 | m_xThumbSize = 0; | |
136 | m_yThumbSize = 0; | |
137 | m_backgroundTransparent = FALSE; | |
138 | ||
139 | // as all windows are created with WS_VISIBLE style... | |
140 | m_isShown = TRUE; | |
141 | ||
6264b550 RR |
142 | m_macWindowData = NULL ; |
143 | m_macEraseOnRedraw = true ; | |
e7549107 | 144 | |
6264b550 RR |
145 | m_x = 0; |
146 | m_y = 0 ; | |
147 | m_width = 0 ; | |
148 | m_height = 0 ; | |
e7549107 | 149 | |
6264b550 RR |
150 | m_hScrollBar = NULL ; |
151 | m_vScrollBar = NULL ; | |
e9576ca5 SC |
152 | |
153 | #if wxUSE_DRAG_AND_DROP | |
519cb848 | 154 | m_pDropTarget = NULL; |
e9576ca5 SC |
155 | #endif |
156 | } | |
157 | ||
158 | // Destructor | |
e766c8a9 | 159 | wxWindowMac::~wxWindowMac() |
e9576ca5 | 160 | { |
fdaf613a SC |
161 | // deleting a window while it is shown invalidates the region |
162 | if ( IsShown() ) { | |
e766c8a9 | 163 | wxWindowMac* iter = this ; |
fdaf613a SC |
164 | while( iter ) { |
165 | if ( iter->m_macWindowData ) | |
166 | { | |
167 | Refresh() ; | |
168 | break ; | |
169 | } | |
170 | iter = iter->GetParent() ; | |
171 | ||
172 | } | |
173 | } | |
174 | ||
e7549107 SC |
175 | m_isBeingDeleted = TRUE; |
176 | ||
6264b550 RR |
177 | if ( s_lastMouseWindow == this ) |
178 | { | |
179 | s_lastMouseWindow = NULL ; | |
180 | } | |
e7549107 SC |
181 | |
182 | if ( gFocusWindow == this ) | |
e9576ca5 | 183 | { |
6264b550 | 184 | gFocusWindow = NULL ; |
e9576ca5 | 185 | } |
519cb848 | 186 | |
e7549107 SC |
187 | if ( m_parent ) |
188 | m_parent->RemoveChild(this); | |
e9576ca5 SC |
189 | |
190 | DestroyChildren(); | |
191 | ||
6264b550 RR |
192 | if ( m_macWindowData ) |
193 | { | |
194 | wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ; | |
195 | UMADisposeWindow( m_macWindowData->m_macWindow ) ; | |
196 | delete m_macWindowData ; | |
197 | wxRemoveMacWindowAssociation( this ) ; | |
519cb848 | 198 | } |
e9576ca5 SC |
199 | } |
200 | ||
201 | // Constructor | |
e766c8a9 | 202 | bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, |
e9576ca5 SC |
203 | const wxPoint& pos, |
204 | const wxSize& size, | |
205 | long style, | |
206 | const wxString& name) | |
207 | { | |
e766c8a9 | 208 | wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); |
e9576ca5 | 209 | |
e7549107 | 210 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
e9576ca5 SC |
211 | return FALSE; |
212 | ||
e7549107 | 213 | parent->AddChild(this); |
e9576ca5 | 214 | |
6264b550 RR |
215 | m_x = (int)pos.x; |
216 | m_y = (int)pos.y; | |
217 | AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); | |
218 | m_width = WidthDefault( size.x ); | |
219 | m_height = HeightDefault( size.y ) ; | |
e766c8a9 | 220 | #ifndef __WXUNIVERSAL__ |
6264b550 RR |
221 | if ( ! IsKindOf( CLASSINFO ( wxControl ) ) && ! IsKindOf( CLASSINFO( wxStatusBar ) ) ) |
222 | { | |
223 | MacCreateScrollBars( style ) ; | |
224 | } | |
e766c8a9 | 225 | #endif |
e9576ca5 SC |
226 | return TRUE; |
227 | } | |
228 | ||
e766c8a9 | 229 | void wxWindowMac::SetFocus() |
e9576ca5 | 230 | { |
6264b550 RR |
231 | if ( gFocusWindow == this ) |
232 | return ; | |
233 | ||
234 | if ( AcceptsFocus() ) | |
235 | { | |
236 | if (gFocusWindow ) | |
237 | { | |
238 | #if wxUSE_CARET | |
239 | // Deal with caret | |
240 | if ( gFocusWindow->m_caret ) | |
241 | { | |
242 | gFocusWindow->m_caret->OnKillFocus(); | |
243 | } | |
244 | #endif // wxUSE_CARET | |
e766c8a9 | 245 | #ifndef __WXUNIVERSAL__ |
6264b550 RR |
246 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; |
247 | if ( control && control->GetMacControl() ) | |
248 | { | |
249 | UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; | |
250 | control->MacRedrawControl() ; | |
251 | } | |
252 | #endif | |
253 | wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); | |
254 | event.SetEventObject(gFocusWindow); | |
255 | gFocusWindow->GetEventHandler()->ProcessEvent(event) ; | |
256 | } | |
257 | gFocusWindow = this ; | |
258 | { | |
259 | #if wxUSE_CARET | |
260 | // Deal with caret | |
261 | if ( m_caret ) | |
262 | { | |
263 | m_caret->OnSetFocus(); | |
264 | } | |
265 | #endif // wxUSE_CARET | |
266 | // panel wants to track the window which was the last to have focus in it | |
c1fb8167 SC |
267 | wxChildFocusEvent eventFocus(this); |
268 | (void)GetEventHandler()->ProcessEvent(eventFocus); | |
269 | ||
e766c8a9 | 270 | #ifndef __WXUNIVERSAL__ |
6264b550 RR |
271 | wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; |
272 | if ( control && control->GetMacControl() ) | |
273 | { | |
274 | UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ; | |
275 | } | |
e766c8a9 | 276 | #endif |
6264b550 RR |
277 | wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); |
278 | event.SetEventObject(this); | |
279 | GetEventHandler()->ProcessEvent(event) ; | |
280 | } | |
281 | } | |
e9576ca5 SC |
282 | } |
283 | ||
e766c8a9 | 284 | bool wxWindowMac::Enable(bool enable) |
e9576ca5 | 285 | { |
e7549107 SC |
286 | if ( !wxWindowBase::Enable(enable) ) |
287 | return FALSE; | |
e7549107 SC |
288 | |
289 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
290 | while ( node ) | |
291 | { | |
e766c8a9 | 292 | wxWindowMac *child = node->GetData(); |
e7549107 SC |
293 | child->Enable(enable); |
294 | ||
295 | node = node->GetNext(); | |
296 | } | |
297 | ||
298 | return TRUE; | |
e9576ca5 SC |
299 | } |
300 | ||
e766c8a9 | 301 | void wxWindowMac::CaptureMouse() |
e9576ca5 | 302 | { |
519cb848 | 303 | wxTheApp->s_captureWindow = this ; |
e9576ca5 SC |
304 | } |
305 | ||
90b959ae SC |
306 | wxWindow* wxWindowBase::GetCapture() |
307 | { | |
308 | return wxTheApp->s_captureWindow ; | |
309 | } | |
310 | ||
e766c8a9 | 311 | void wxWindowMac::ReleaseMouse() |
e9576ca5 | 312 | { |
519cb848 | 313 | wxTheApp->s_captureWindow = NULL ; |
e9576ca5 SC |
314 | } |
315 | ||
e9576ca5 SC |
316 | #if wxUSE_DRAG_AND_DROP |
317 | ||
e766c8a9 | 318 | void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) |
e9576ca5 SC |
319 | { |
320 | if ( m_pDropTarget != 0 ) { | |
321 | delete m_pDropTarget; | |
322 | } | |
323 | ||
324 | m_pDropTarget = pDropTarget; | |
325 | if ( m_pDropTarget != 0 ) | |
326 | { | |
327 | // TODO | |
328 | } | |
329 | } | |
330 | ||
331 | #endif | |
332 | ||
333 | // Old style file-manager drag&drop | |
e766c8a9 | 334 | void wxWindowMac::DragAcceptFiles(bool accept) |
e9576ca5 SC |
335 | { |
336 | // TODO | |
337 | } | |
338 | ||
339 | // Get total size | |
e766c8a9 | 340 | void wxWindowMac::DoGetSize(int *x, int *y) const |
e9576ca5 | 341 | { |
9453cf2b SC |
342 | if(x) *x = m_width ; |
343 | if(y) *y = m_height ; | |
e9576ca5 SC |
344 | } |
345 | ||
e766c8a9 | 346 | void wxWindowMac::DoGetPosition(int *x, int *y) const |
e9576ca5 | 347 | { |
9453cf2b SC |
348 | int xx,yy; |
349 | ||
350 | xx = m_x ; | |
351 | yy = m_y ; | |
519cb848 SC |
352 | if (GetParent()) |
353 | { | |
354 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
9453cf2b SC |
355 | xx -= pt.x; |
356 | yy -= pt.y; | |
519cb848 | 357 | } |
9453cf2b SC |
358 | if(x) *x = xx; |
359 | if(y) *y = yy; | |
e9576ca5 SC |
360 | } |
361 | ||
e766c8a9 SC |
362 | #if wxUSE_MENUS |
363 | bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) | |
51abe921 | 364 | { |
6264b550 | 365 | menu->SetInvokingWindow(this); |
51abe921 | 366 | menu->UpdateUI(); |
6264b550 | 367 | ClientToScreen( &x , &y ) ; |
51abe921 | 368 | |
6264b550 RR |
369 | ::InsertMenu( menu->GetHMenu() , -1 ) ; |
370 | long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ; | |
371 | menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; | |
372 | ::DeleteMenu( menu->MacGetMenuId() ) ; | |
373 | menu->SetInvokingWindow(NULL); | |
51abe921 SC |
374 | |
375 | return TRUE; | |
376 | } | |
e766c8a9 | 377 | #endif |
51abe921 | 378 | |
e766c8a9 | 379 | void wxWindowMac::DoScreenToClient(int *x, int *y) const |
e9576ca5 | 380 | { |
6264b550 | 381 | WindowRef window = GetMacRootWindow() ; |
519cb848 | 382 | |
6264b550 | 383 | Point localwhere = {0,0} ; |
9453cf2b SC |
384 | |
385 | if(x) localwhere.h = * x ; | |
386 | if(y) localwhere.v = * y ; | |
519cb848 | 387 | |
6264b550 RR |
388 | GrafPtr port ; |
389 | ::GetPort( &port ) ; | |
390 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
391 | ::GlobalToLocal( &localwhere ) ; | |
392 | ::SetPort( port ) ; | |
519cb848 | 393 | |
9453cf2b SC |
394 | if(x) *x = localwhere.h ; |
395 | if(y) *y = localwhere.v ; | |
6264b550 RR |
396 | |
397 | MacRootWindowToClient( x , y ) ; | |
e9576ca5 SC |
398 | } |
399 | ||
e766c8a9 | 400 | void wxWindowMac::DoClientToScreen(int *x, int *y) const |
e9576ca5 | 401 | { |
6264b550 RR |
402 | WindowRef window = GetMacRootWindow() ; |
403 | ||
404 | MacClientToRootWindow( x , y ) ; | |
405 | ||
406 | Point localwhere = { 0,0 }; | |
9453cf2b SC |
407 | if(x) localwhere.h = * x ; |
408 | if(y) localwhere.v = * y ; | |
6264b550 RR |
409 | |
410 | GrafPtr port ; | |
411 | ::GetPort( &port ) ; | |
412 | ::SetPort( UMAGetWindowPort( window ) ) ; | |
413 | ::SetOrigin( 0 , 0 ) ; | |
414 | ::LocalToGlobal( &localwhere ) ; | |
415 | ::SetPort( port ) ; | |
9453cf2b SC |
416 | if(x) *x = localwhere.h ; |
417 | if(y) *y = localwhere.v ; | |
519cb848 SC |
418 | } |
419 | ||
e766c8a9 | 420 | void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const |
519cb848 | 421 | { |
6264b550 RR |
422 | if ( m_macWindowData == NULL) |
423 | { | |
653b2449 SC |
424 | if(x) *x += m_x + MacGetLeftBorderSize(); |
425 | if(y) *y += m_y + MacGetTopBorderSize(); | |
6264b550 RR |
426 | GetParent()->MacClientToRootWindow( x , y ) ; |
427 | } | |
519cb848 SC |
428 | } |
429 | ||
e766c8a9 | 430 | void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const |
519cb848 | 431 | { |
6264b550 RR |
432 | if ( m_macWindowData == NULL) |
433 | { | |
653b2449 SC |
434 | if(x) *x -= m_x + MacGetLeftBorderSize(); |
435 | if(y) *y -= m_y + MacGetTopBorderSize(); | |
6264b550 RR |
436 | GetParent()->MacRootWindowToClient( x , y ) ; |
437 | } | |
e9576ca5 SC |
438 | } |
439 | ||
e766c8a9 | 440 | bool wxWindowMac::SetCursor(const wxCursor& cursor) |
e9576ca5 | 441 | { |
6618870d | 442 | if (m_cursor == cursor) |
e7549107 | 443 | return FALSE; |
6618870d SC |
444 | |
445 | if (wxNullCursor == cursor) | |
446 | { | |
447 | if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) | |
448 | return FALSE ; | |
449 | } | |
450 | else | |
451 | { | |
452 | if ( ! wxWindowBase::SetCursor( cursor ) ) | |
453 | return FALSE ; | |
454 | } | |
e7549107 SC |
455 | |
456 | wxASSERT_MSG( m_cursor.Ok(), | |
457 | wxT("cursor must be valid after call to the base version")); | |
458 | ||
459 | Point pt ; | |
e766c8a9 | 460 | wxWindowMac *mouseWin ; |
e7549107 SC |
461 | GetMouse( &pt ) ; |
462 | ||
463 | // Change the cursor NOW if we're within the correct window | |
464 | ||
465 | if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) | |
e9576ca5 | 466 | { |
6264b550 RR |
467 | if ( mouseWin == this && !wxIsBusy() ) |
468 | { | |
469 | m_cursor.MacInstall() ; | |
470 | } | |
e9576ca5 | 471 | } |
e7549107 SC |
472 | |
473 | return TRUE ; | |
e9576ca5 SC |
474 | } |
475 | ||
476 | ||
477 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
e766c8a9 | 478 | void wxWindowMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 479 | { |
9453cf2b SC |
480 | int ww, hh; |
481 | ww = m_width ; | |
482 | hh = m_height ; | |
519cb848 | 483 | |
6264b550 RR |
484 | ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
485 | hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); | |
486 | ||
2f1ae414 SC |
487 | if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) |
488 | { | |
6264b550 RR |
489 | int x1 = 0 ; |
490 | int y1 = 0 ; | |
491 | int w = m_width ; | |
492 | int h = m_height ; | |
493 | ||
494 | MacClientToRootWindow( &x1 , &y1 ) ; | |
495 | MacClientToRootWindow( &w , &h ) ; | |
496 | ||
497 | wxWindowMac *iter = (wxWindowMac*)this ; | |
498 | ||
499 | int totW = 10000 , totH = 10000; | |
500 | while( iter ) | |
501 | { | |
502 | if ( iter->m_macWindowData ) | |
503 | { | |
504 | totW = iter->m_width ; | |
505 | totH = iter->m_height ; | |
506 | break ; | |
507 | } | |
508 | ||
509 | iter = iter->GetParent() ; | |
510 | } | |
511 | ||
512 | if (m_hScrollBar && m_hScrollBar->IsShown() ) | |
513 | { | |
514 | hh -= MAC_SCROLLBAR_SIZE; | |
515 | if ( h-y1 >= totH ) | |
516 | { | |
517 | hh += 1 ; | |
518 | } | |
519 | } | |
520 | if (m_vScrollBar && m_vScrollBar->IsShown() ) | |
521 | { | |
522 | ww -= MAC_SCROLLBAR_SIZE; | |
523 | if ( w-x1 >= totW ) | |
524 | { | |
525 | ww += 1 ; | |
526 | } | |
527 | } | |
2f1ae414 | 528 | } |
9453cf2b SC |
529 | if(x) *x = ww; |
530 | if(y) *y = hh; | |
519cb848 SC |
531 | } |
532 | ||
51abe921 SC |
533 | |
534 | // ---------------------------------------------------------------------------- | |
535 | // tooltips | |
536 | // ---------------------------------------------------------------------------- | |
537 | ||
538 | #if wxUSE_TOOLTIPS | |
539 | ||
e766c8a9 | 540 | void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) |
51abe921 SC |
541 | { |
542 | wxWindowBase::DoSetToolTip(tooltip); | |
543 | ||
6264b550 RR |
544 | if ( m_tooltip ) |
545 | m_tooltip->SetWindow(this); | |
51abe921 SC |
546 | } |
547 | ||
548 | #endif // wxUSE_TOOLTIPS | |
549 | ||
e766c8a9 | 550 | void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) |
51abe921 | 551 | { |
6264b550 RR |
552 | int former_x = m_x ; |
553 | int former_y = m_y ; | |
554 | int former_w = m_width ; | |
555 | int former_h = m_height ; | |
556 | ||
519cb848 SC |
557 | int actualWidth = width; |
558 | int actualHeight = height; | |
559 | int actualX = x; | |
560 | int actualY = y; | |
7810c95b | 561 | |
7810c95b | 562 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) |
6264b550 | 563 | actualWidth = m_minWidth; |
7810c95b | 564 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
6264b550 | 565 | actualHeight = m_minHeight; |
7810c95b | 566 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
6264b550 | 567 | actualWidth = m_maxWidth; |
7810c95b | 568 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
6264b550 RR |
569 | actualHeight = m_maxHeight; |
570 | ||
571 | bool doMove = false ; | |
572 | bool doResize = false ; | |
573 | ||
574 | if ( actualX != former_x || actualY != former_y ) | |
575 | { | |
576 | doMove = true ; | |
577 | } | |
578 | if ( actualWidth != former_w || actualHeight != former_h ) | |
579 | { | |
580 | doResize = true ; | |
581 | } | |
582 | ||
583 | if ( doMove || doResize ) | |
584 | { | |
585 | if ( m_macWindowData ) | |
586 | { | |
587 | } | |
588 | else | |
589 | { | |
590 | // erase former position | |
591 | wxMacDrawingHelper focus( this ) ; | |
592 | if ( focus.Ok() ) | |
593 | { | |
594 | Rect clientrect = { 0 , 0 , m_height , m_width } ; | |
595 | // ClipRect( &clientrect ) ; | |
596 | InvalWindowRect( GetMacRootWindow() , &clientrect ) ; | |
597 | } | |
598 | } | |
599 | m_x = actualX ; | |
600 | m_y = actualY ; | |
601 | m_width = actualWidth ; | |
602 | m_height = actualHeight ; | |
603 | if ( m_macWindowData ) | |
604 | { | |
605 | if ( doMove ) | |
606 | ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost | |
607 | ||
608 | if ( doResize ) | |
609 | ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true); | |
610 | ||
611 | // the OS takes care of invalidating and erasing the new area | |
612 | // we have erased the old one | |
613 | ||
614 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) | |
615 | { | |
616 | wxFrame* frame = (wxFrame*) this ; | |
617 | frame->PositionStatusBar(); | |
618 | frame->PositionToolBar(); | |
619 | } | |
620 | if ( doMove ) | |
621 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
622 | } | |
623 | else | |
624 | { | |
625 | // erase new position | |
626 | ||
627 | { | |
628 | wxMacDrawingHelper focus( this ) ; | |
629 | if ( focus.Ok() ) | |
630 | { | |
631 | Rect clientrect = { 0 , 0 , m_height , m_width } ; | |
632 | // ClipRect( &clientrect ) ; | |
633 | InvalWindowRect( GetMacRootWindow() , &clientrect ) ; | |
634 | } | |
635 | } | |
636 | ||
637 | if ( doMove ) | |
638 | wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified | |
639 | } | |
640 | MacRepositionScrollBars() ; | |
641 | if ( doMove ) | |
642 | { | |
643 | wxPoint point(m_x, m_y); | |
644 | wxMoveEvent event(point, m_windowId); | |
645 | event.SetEventObject(this); | |
646 | GetEventHandler()->ProcessEvent(event) ; | |
647 | } | |
648 | if ( doResize ) | |
649 | { | |
650 | MacRepositionScrollBars() ; | |
651 | wxSize size(m_width, m_height); | |
652 | wxSizeEvent event(size, m_windowId); | |
653 | event.SetEventObject(this); | |
654 | GetEventHandler()->ProcessEvent(event); | |
655 | } | |
656 | } | |
657 | ||
954fc50b SC |
658 | } |
659 | ||
660 | // set the size of the window: if the dimensions are positive, just use them, | |
661 | // but if any of them is equal to -1, it means that we must find the value for | |
662 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
663 | // which case -1 is a valid value for x and y) | |
664 | // | |
665 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
666 | // the width/height to best suit our contents, otherwise we reuse the current | |
667 | // width/height | |
668 | void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
669 | { | |
670 | // get the current size and position... | |
671 | int currentX, currentY; | |
672 | GetPosition(¤tX, ¤tY); | |
673 | int currentW,currentH; | |
674 | GetSize(¤tW, ¤tH); | |
675 | ||
676 | // ... and don't do anything (avoiding flicker) if it's already ok | |
677 | if ( x == currentX && y == currentY && | |
678 | width == currentW && height == currentH ) | |
679 | { | |
6264b550 | 680 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
681 | return; |
682 | } | |
683 | ||
684 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
685 | x = currentX; | |
686 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
687 | y = currentY; | |
688 | ||
689 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
690 | ||
691 | wxSize size(-1, -1); | |
692 | if ( width == -1 ) | |
693 | { | |
694 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
695 | { | |
696 | size = DoGetBestSize(); | |
697 | width = size.x; | |
698 | } | |
699 | else | |
700 | { | |
701 | // just take the current one | |
702 | width = currentW; | |
703 | } | |
704 | } | |
705 | ||
706 | if ( height == -1 ) | |
707 | { | |
708 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
709 | { | |
710 | if ( size.x == -1 ) | |
711 | { | |
712 | size = DoGetBestSize(); | |
713 | } | |
714 | //else: already called DoGetBestSize() above | |
715 | ||
716 | height = size.y; | |
717 | } | |
718 | else | |
719 | { | |
720 | // just take the current one | |
721 | height = currentH; | |
722 | } | |
723 | } | |
724 | ||
725 | DoMoveWindow(x, y, width, height); | |
726 | ||
e9576ca5 | 727 | } |
e9576ca5 SC |
728 | // For implementation purposes - sometimes decorations make the client area |
729 | // smaller | |
519cb848 | 730 | |
e766c8a9 | 731 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 732 | { |
5b781a67 | 733 | return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); |
e9576ca5 SC |
734 | } |
735 | ||
736 | // Makes an adjustment to the window position (for example, a frame that has | |
737 | // a toolbar that it manages itself). | |
e766c8a9 | 738 | void wxWindowMac::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) |
e9576ca5 | 739 | { |
6264b550 RR |
740 | if( !m_macWindowData ) |
741 | { | |
e9576ca5 SC |
742 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
743 | { | |
744 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
745 | x += pt.x; y += pt.y; | |
746 | } | |
519cb848 SC |
747 | } |
748 | } | |
749 | ||
e766c8a9 | 750 | void wxWindowMac::SetTitle(const wxString& title) |
519cb848 | 751 | { |
6264b550 RR |
752 | m_label = title ; |
753 | ||
754 | wxString label ; | |
755 | ||
756 | if( wxApp::s_macDefaultEncodingIsPC ) | |
757 | label = wxMacMakeMacStringFromPC( title ) ; | |
758 | else | |
759 | label = title ; | |
519cb848 | 760 | |
6264b550 RR |
761 | if ( m_macWindowData ) |
762 | UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; | |
519cb848 SC |
763 | } |
764 | ||
e766c8a9 | 765 | wxString wxWindowMac::GetTitle() const |
519cb848 | 766 | { |
6264b550 | 767 | return m_label ; |
519cb848 SC |
768 | } |
769 | ||
e766c8a9 | 770 | bool wxWindowMac::Show(bool show) |
e9576ca5 | 771 | { |
e7549107 SC |
772 | if ( !wxWindowBase::Show(show) ) |
773 | return FALSE; | |
774 | ||
6264b550 RR |
775 | if ( m_macWindowData ) |
776 | { | |
777 | if (show) | |
778 | { | |
779 | ::ShowWindow( m_macWindowData->m_macWindow ) ; | |
780 | ::SelectWindow( m_macWindowData->m_macWindow ) ; | |
781 | // no need to generate events here, they will get them triggered by macos | |
782 | // actually they should be , but apparently they are not | |
783 | wxSize size(m_width, m_height); | |
784 | wxSizeEvent event(size, m_windowId); | |
785 | event.SetEventObject(this); | |
786 | GetEventHandler()->ProcessEvent(event); | |
787 | } | |
788 | else | |
789 | { | |
790 | ::HideWindow( m_macWindowData->m_macWindow ) ; | |
791 | } | |
792 | } | |
793 | MacSuperShown( show ) ; | |
794 | if ( !show ) | |
795 | { | |
796 | WindowRef window = GetMacRootWindow() ; | |
797 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
798 | if ( win && !win->m_isBeingDeleted ) | |
799 | Refresh() ; | |
800 | } | |
801 | else | |
802 | { | |
803 | Refresh() ; | |
804 | } | |
fdaf613a | 805 | |
e7549107 | 806 | return TRUE; |
e9576ca5 SC |
807 | } |
808 | ||
e766c8a9 | 809 | void wxWindowMac::MacSuperShown( bool show ) |
8208e181 | 810 | { |
6264b550 RR |
811 | wxNode *node = GetChildren().First(); |
812 | while ( node ) | |
813 | { | |
814 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
815 | if ( child->m_isShown ) | |
816 | child->MacSuperShown( show ) ; | |
817 | node = node->Next(); | |
818 | } | |
8208e181 SC |
819 | } |
820 | ||
e766c8a9 | 821 | bool wxWindowMac::MacIsReallyShown() const |
c809f3be | 822 | { |
6264b550 RR |
823 | if ( m_isShown && (m_parent != NULL) ) { |
824 | return m_parent->MacIsReallyShown(); | |
825 | } | |
826 | return m_isShown; | |
827 | /* | |
828 | bool status = m_isShown ; | |
829 | wxWindowMac * win = this ; | |
830 | while ( status && win->m_parent != NULL ) | |
831 | { | |
832 | win = win->m_parent ; | |
833 | status = win->m_isShown ; | |
834 | } | |
835 | return status ; | |
5fde6fcc | 836 | */ |
c809f3be SC |
837 | } |
838 | ||
e766c8a9 | 839 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 840 | { |
6264b550 RR |
841 | wxClientDC dc ( (wxWindowMac*)this ) ; |
842 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
843 | } |
844 | ||
e766c8a9 | 845 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 846 | { |
6264b550 RR |
847 | wxClientDC dc ( (wxWindowMac*)this ) ; |
848 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
849 | } |
850 | ||
e766c8a9 | 851 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 852 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 853 | { |
e7549107 SC |
854 | const wxFont *fontToUse = theFont; |
855 | if ( !fontToUse ) | |
856 | fontToUse = &m_font; | |
7c74e7fe | 857 | |
e766c8a9 | 858 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 859 | long lx,ly,ld,le ; |
5fde6fcc | 860 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 861 | if ( externalLeading ) |
6264b550 | 862 | *externalLeading = le ; |
2f1ae414 | 863 | if ( descent ) |
6264b550 | 864 | *descent = ld ; |
2f1ae414 | 865 | if ( x ) |
6264b550 | 866 | *x = lx ; |
2f1ae414 | 867 | if ( y ) |
6264b550 | 868 | *y = ly ; |
e9576ca5 SC |
869 | } |
870 | ||
e766c8a9 | 871 | void wxWindowMac::MacEraseBackground( Rect *rect ) |
519cb848 | 872 | { |
0a67a93b | 873 | /* |
6264b550 RR |
874 | WindowRef window = GetMacRootWindow() ; |
875 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
876 | { | |
877 | UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
878 | } | |
879 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
880 | { | |
881 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
882 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
883 | // either a non gray background color or a non control window | |
884 | ||
885 | wxWindowMac* parent = GetParent() ; | |
886 | while( parent ) | |
887 | { | |
888 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
889 | { | |
890 | // if we have any other colours in the hierarchy | |
891 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
892 | break ; | |
893 | } | |
894 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
895 | { | |
896 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
897 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
898 | { | |
899 | UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); | |
900 | break ; | |
901 | } | |
902 | } | |
903 | else | |
904 | { | |
905 | // we have arrived at a non control item | |
906 | parent = NULL ; | |
907 | break ; | |
908 | } | |
909 | parent = parent->GetParent() ; | |
910 | } | |
911 | if ( !parent ) | |
912 | { | |
913 | // if there is nothing special -> use default | |
914 | UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
915 | } | |
916 | } | |
917 | else | |
918 | { | |
919 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
920 | } | |
921 | ||
922 | EraseRect( rect ) ; | |
923 | ||
924 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
925 | { | |
926 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
927 | ||
928 | Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ; | |
929 | SectRect( &clientrect , rect , &clientrect ) ; | |
930 | ||
931 | OffsetRect( &clientrect , -child->m_x , -child->m_y ) ; | |
932 | if ( child->GetMacRootWindow() == window && child->IsShown() ) | |
933 | { | |
934 | wxMacDrawingClientHelper focus( this ) ; | |
935 | if ( focus.Ok() ) | |
936 | { | |
937 | child->MacEraseBackground( &clientrect ) ; | |
938 | } | |
939 | } | |
940 | } | |
0a67a93b | 941 | */ |
519cb848 SC |
942 | } |
943 | ||
e766c8a9 | 944 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 945 | { |
fdaf613a SC |
946 | // if ( !IsShown() ) |
947 | // return ; | |
948 | ||
6264b550 RR |
949 | wxMacDrawingClientHelper focus( this ) ; |
950 | if ( focus.Ok() ) | |
951 | { | |
952 | wxPoint client ; | |
953 | client = GetClientAreaOrigin( ) ; | |
954 | Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ; | |
955 | // ClipRect( &clientrect ) ; | |
956 | ||
957 | if ( rect ) | |
958 | { | |
959 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
960 | SectRect( &clientrect , &r , &clientrect ) ; | |
961 | } | |
962 | InvalWindowRect( GetMacRootWindow() , &clientrect ) ; | |
963 | } | |
964 | if ( !eraseBack ) | |
965 | m_macEraseOnRedraw = false ; | |
966 | else | |
967 | m_macEraseOnRedraw = true ; | |
e9576ca5 SC |
968 | } |
969 | ||
970 | // Responds to colour changes: passes event on to children. | |
e766c8a9 | 971 | void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 SC |
972 | { |
973 | wxNode *node = GetChildren().First(); | |
974 | while ( node ) | |
975 | { | |
976 | // Only propagate to non-top-level windows | |
e766c8a9 | 977 | wxWindowMac *win = (wxWindowMac *)node->Data(); |
e9576ca5 SC |
978 | if ( win->GetParent() ) |
979 | { | |
980 | wxSysColourChangedEvent event2; | |
981 | event.m_eventObject = win; | |
982 | win->GetEventHandler()->ProcessEvent(event2); | |
983 | } | |
984 | ||
985 | node = node->Next(); | |
986 | } | |
987 | } | |
988 | ||
e7549107 SC |
989 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
990 | // --------------------------------------------------------------------------- | |
e9576ca5 | 991 | // Caret manipulation |
e7549107 SC |
992 | // --------------------------------------------------------------------------- |
993 | ||
e766c8a9 | 994 | void wxWindowMac::CreateCaret(int w, int h) |
e9576ca5 | 995 | { |
e7549107 | 996 | SetCaret(new wxCaret(this, w, h)); |
e9576ca5 SC |
997 | } |
998 | ||
e766c8a9 | 999 | void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
e9576ca5 | 1000 | { |
e7549107 | 1001 | wxFAIL_MSG("not implemented"); |
e9576ca5 SC |
1002 | } |
1003 | ||
e766c8a9 | 1004 | void wxWindowMac::ShowCaret(bool show) |
e9576ca5 | 1005 | { |
e7549107 SC |
1006 | wxCHECK_RET( m_caret, "no caret to show" ); |
1007 | ||
1008 | m_caret->Show(show); | |
e9576ca5 SC |
1009 | } |
1010 | ||
e766c8a9 | 1011 | void wxWindowMac::DestroyCaret() |
e9576ca5 | 1012 | { |
e7549107 | 1013 | SetCaret(NULL); |
e9576ca5 SC |
1014 | } |
1015 | ||
e766c8a9 | 1016 | void wxWindowMac::SetCaretPos(int x, int y) |
e9576ca5 | 1017 | { |
e7549107 SC |
1018 | wxCHECK_RET( m_caret, "no caret to move" ); |
1019 | ||
1020 | m_caret->Move(x, y); | |
e9576ca5 SC |
1021 | } |
1022 | ||
e766c8a9 | 1023 | void wxWindowMac::GetCaretPos(int *x, int *y) const |
e9576ca5 | 1024 | { |
e7549107 SC |
1025 | wxCHECK_RET( m_caret, "no caret to get position of" ); |
1026 | ||
1027 | m_caret->GetPosition(x, y); | |
e9576ca5 | 1028 | } |
e7549107 | 1029 | #endif // wxUSE_CARET |
e9576ca5 | 1030 | |
e766c8a9 | 1031 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 1032 | { |
519cb848 | 1033 | // actually this is a windows-only concept |
e9576ca5 SC |
1034 | return NULL; |
1035 | } | |
1036 | ||
e9576ca5 | 1037 | // Coordinates relative to the window |
e766c8a9 | 1038 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 1039 | { |
519cb848 | 1040 | // We really dont move the mouse programmatically under mac |
e9576ca5 SC |
1041 | } |
1042 | ||
e766c8a9 | 1043 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 1044 | { |
519cb848 | 1045 | // TODO : probably we would adopt the EraseEvent structure |
e9576ca5 SC |
1046 | } |
1047 | ||
e766c8a9 | 1048 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 1049 | { |
6264b550 RR |
1050 | if ( orient == wxHORIZONTAL ) |
1051 | { | |
1052 | if ( m_hScrollBar ) | |
1053 | return m_hScrollBar->GetThumbPosition() ; | |
1054 | } | |
1055 | else | |
1056 | { | |
1057 | if ( m_vScrollBar ) | |
1058 | return m_vScrollBar->GetThumbPosition() ; | |
1059 | } | |
e9576ca5 SC |
1060 | return 0; |
1061 | } | |
1062 | ||
1063 | // This now returns the whole range, not just the number | |
1064 | // of positions that we can scroll. | |
e766c8a9 | 1065 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 1066 | { |
6264b550 RR |
1067 | if ( orient == wxHORIZONTAL ) |
1068 | { | |
1069 | if ( m_hScrollBar ) | |
1070 | return m_hScrollBar->GetRange() ; | |
1071 | } | |
1072 | else | |
1073 | { | |
1074 | if ( m_vScrollBar ) | |
1075 | return m_vScrollBar->GetRange() ; | |
1076 | } | |
e9576ca5 SC |
1077 | return 0; |
1078 | } | |
1079 | ||
e766c8a9 | 1080 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 1081 | { |
6264b550 RR |
1082 | if ( orient == wxHORIZONTAL ) |
1083 | { | |
1084 | if ( m_hScrollBar ) | |
1085 | return m_hScrollBar->GetThumbSize() ; | |
1086 | } | |
1087 | else | |
1088 | { | |
1089 | if ( m_vScrollBar ) | |
1090 | return m_vScrollBar->GetThumbSize() ; | |
1091 | } | |
e9576ca5 SC |
1092 | return 0; |
1093 | } | |
1094 | ||
e766c8a9 | 1095 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 1096 | { |
6264b550 RR |
1097 | if ( orient == wxHORIZONTAL ) |
1098 | { | |
1099 | if ( m_hScrollBar ) | |
1100 | m_hScrollBar->SetThumbPosition( pos ) ; | |
1101 | } | |
1102 | else | |
1103 | { | |
1104 | if ( m_vScrollBar ) | |
1105 | m_vScrollBar->SetThumbPosition( pos ) ; | |
1106 | } | |
e9576ca5 SC |
1107 | } |
1108 | ||
e766c8a9 | 1109 | void wxWindowMac::MacCreateRealWindow( const wxString& title, |
2f1ae414 SC |
1110 | const wxPoint& pos, |
1111 | const wxSize& size, | |
1112 | long style, | |
1113 | const wxString& name ) | |
8208e181 | 1114 | { |
2f1ae414 SC |
1115 | SetName(name); |
1116 | m_windowStyle = style; | |
1117 | m_isShown = FALSE; | |
8208e181 | 1118 | |
2f1ae414 | 1119 | // create frame. |
8208e181 | 1120 | |
6264b550 | 1121 | Rect theBoundsRect; |
2f1ae414 SC |
1122 | |
1123 | m_x = (int)pos.x; | |
1124 | m_y = (int)pos.y; | |
1125 | if ( m_y < 50 ) | |
6264b550 | 1126 | m_y = 50 ; |
2f1ae414 | 1127 | if ( m_x < 20 ) |
6264b550 RR |
1128 | m_x = 20 ; |
1129 | ||
2f1ae414 | 1130 | m_width = size.x; |
6264b550 RR |
1131 | if (m_width == -1) |
1132 | m_width = 20; | |
2f1ae414 | 1133 | m_height = size.y; |
6264b550 RR |
1134 | if (m_height == -1) |
1135 | m_height = 20; | |
1136 | ||
1137 | m_macWindowData = new MacWindowData() ; | |
1138 | ||
1139 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); | |
1140 | ||
1141 | // translate the window attributes in the appropriate window class and attributes | |
1142 | ||
1143 | WindowClass wclass = 0; | |
1144 | WindowAttributes attr = kWindowNoAttributes ; | |
1145 | ||
1146 | if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) | |
1147 | { | |
1148 | wclass = kFloatingWindowClass ; | |
1149 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1150 | { | |
1151 | attr |= kWindowSideTitlebarAttribute ; | |
1152 | } | |
1153 | } | |
1154 | else if ( HasFlag( wxCAPTION ) ) | |
1155 | { | |
1156 | if ( HasFlag( wxDIALOG_MODAL ) ) | |
1157 | { | |
1158 | wclass = kMovableModalWindowClass ; | |
1159 | } | |
1160 | else | |
1161 | { | |
1162 | wclass = kDocumentWindowClass ; | |
1163 | } | |
1164 | } | |
1165 | else | |
1166 | { | |
1167 | wclass = kModalWindowClass ; | |
1168 | } | |
1169 | ||
1170 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) | |
1171 | { | |
1172 | attr |= kWindowFullZoomAttribute ; | |
1173 | attr |= kWindowCollapseBoxAttribute ; | |
1174 | } | |
1175 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1176 | { | |
1177 | attr |= kWindowResizableAttribute ; | |
1178 | } | |
1179 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
1180 | { | |
1181 | attr |= kWindowCloseBoxAttribute ; | |
1182 | } | |
1183 | ||
1184 | ::CreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; | |
1185 | wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; | |
1186 | wxString label ; | |
1187 | if( wxApp::s_macDefaultEncodingIsPC ) | |
1188 | label = wxMacMakeMacStringFromPC( title ) ; | |
1189 | else | |
1190 | label = title ; | |
1191 | UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; | |
1192 | ::CreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; | |
1193 | ||
1194 | m_macWindowData->m_macFocus = NULL ; | |
1195 | m_macWindowData->m_macHasReceivedFirstActivate = true ; | |
2f1ae414 SC |
1196 | } |
1197 | ||
e766c8a9 | 1198 | void wxWindowMac::MacPaint( wxPaintEvent &event ) |
2f1ae414 SC |
1199 | { |
1200 | } | |
1201 | ||
e766c8a9 | 1202 | void wxWindowMac::MacPaintBorders( ) |
2f1ae414 | 1203 | { |
6264b550 RR |
1204 | if( m_macWindowData ) |
1205 | return ; | |
1206 | ||
1207 | RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; | |
1208 | RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; | |
1209 | RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; | |
1210 | RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; | |
1211 | PenNormal() ; | |
2f1ae414 SC |
1212 | |
1213 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1214 | { | |
6264b550 | 1215 | bool sunken = HasFlag( wxSUNKEN_BORDER ) ; |
653b2449 SC |
1216 | RGBForeColor( &face ); |
1217 | MoveTo( 0 , m_height - 2 ); | |
1218 | LineTo( 0 , 0 ); | |
1219 | LineTo( m_width - 2 , 0 ); | |
1220 | ||
1221 | MoveTo( 2 , m_height - 3 ); | |
1222 | LineTo( m_width - 3 , m_height - 3 ); | |
1223 | LineTo( m_width - 3 , 2 ); | |
1224 | ||
1225 | RGBForeColor( sunken ? &face : &black ); | |
1226 | MoveTo( 0 , m_height - 1 ); | |
1227 | LineTo( m_width - 1 , m_height - 1 ); | |
1228 | LineTo( m_width - 1 , 0 ); | |
1229 | ||
1230 | RGBForeColor( sunken ? &shadow : &white ); | |
1231 | MoveTo( 1 , m_height - 3 ); | |
1232 | LineTo( 1, 1 ); | |
1233 | LineTo( m_width - 3 , 1 ); | |
1234 | ||
1235 | RGBForeColor( sunken ? &white : &shadow ); | |
1236 | MoveTo( 1 , m_height - 2 ); | |
1237 | LineTo( m_width - 2 , m_height - 2 ); | |
1238 | LineTo( m_width - 2 , 1 ); | |
1239 | ||
1240 | RGBForeColor( sunken ? &black : &face ); | |
1241 | MoveTo( 2 , m_height - 4 ); | |
1242 | LineTo( 2 , 2 ); | |
1243 | LineTo( m_width - 4 , 2 ); | |
8208e181 SC |
1244 | } |
1245 | else if (HasFlag(wxSIMPLE_BORDER)) | |
1246 | { | |
6264b550 RR |
1247 | Rect rect = { 0 , 0 , m_height , m_width } ; |
1248 | RGBForeColor( &black ) ; | |
1249 | FrameRect( &rect ) ; | |
2f1ae414 | 1250 | } |
8208e181 SC |
1251 | } |
1252 | ||
e9576ca5 | 1253 | // New function that will replace some of the above. |
e766c8a9 | 1254 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
1255 | int range, bool refresh) |
1256 | { | |
6264b550 RR |
1257 | if ( orient == wxHORIZONTAL ) |
1258 | { | |
1259 | if ( m_hScrollBar ) | |
1260 | { | |
1261 | if ( range == 0 || thumbVisible >= range ) | |
1262 | { | |
1263 | if ( m_hScrollBar->IsShown() ) | |
1264 | m_hScrollBar->Show(false) ; | |
1265 | } | |
1266 | else | |
1267 | { | |
1268 | if ( !m_hScrollBar->IsShown() ) | |
1269 | m_hScrollBar->Show(true) ; | |
1270 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1271 | } | |
1272 | } | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | if ( m_vScrollBar ) | |
1277 | { | |
1278 | if ( range == 0 || thumbVisible >= range ) | |
1279 | { | |
1280 | if ( m_vScrollBar->IsShown() ) | |
1281 | m_vScrollBar->Show(false) ; | |
1282 | } | |
1283 | else | |
1284 | { | |
1285 | if ( !m_vScrollBar->IsShown() ) | |
1286 | m_vScrollBar->Show(true) ; | |
1287 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1288 | } | |
1289 | } | |
1290 | } | |
1291 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
1292 | } |
1293 | ||
1294 | // Does a physical scroll | |
e766c8a9 | 1295 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 1296 | { |
6264b550 RR |
1297 | wxMacDrawingClientHelper focus( this ) ; |
1298 | if ( focus.Ok() ) | |
1299 | { | |
1300 | int width , height ; | |
1301 | GetClientSize( &width , &height ) ; | |
1302 | ||
1303 | Rect scrollrect = { 0 , 0 , height , width } ; | |
1304 | ||
1305 | RgnHandle updateRgn = NewRgn() ; | |
1306 | ClipRect( &scrollrect ) ; | |
1307 | if ( rect ) | |
1308 | { | |
1309 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
1310 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
1311 | } | |
1312 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
1313 | InvalWindowRgn( GetMacRootWindow() , updateRgn ) ; | |
1314 | DisposeRgn( updateRgn ) ; | |
1315 | } | |
1316 | ||
1317 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1318 | { | |
1319 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1320 | if (child == m_vScrollBar) continue; | |
1321 | if (child == m_hScrollBar) continue; | |
1322 | if (child->IsTopLevel()) continue; | |
1323 | int x,y; | |
1324 | child->GetPosition( &x, &y ); | |
1325 | int w,h; | |
1326 | child->GetSize( &w, &h ); | |
1327 | child->SetSize( x+dx, y+dy, w, h ); | |
1328 | } | |
1329 | ||
e9576ca5 SC |
1330 | } |
1331 | ||
e766c8a9 | 1332 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 1333 | { |
6264b550 RR |
1334 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) |
1335 | { | |
1336 | wxScrollWinEvent wevent; | |
1337 | wevent.SetPosition(event.GetPosition()); | |
1338 | wevent.SetOrientation(event.GetOrientation()); | |
1339 | wevent.m_eventObject = this; | |
1340 | ||
1341 | if (event.m_eventType == wxEVT_SCROLL_TOP) { | |
1342 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
1343 | } else | |
1344 | if (event.m_eventType == wxEVT_SCROLL_BOTTOM) { | |
1345 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1346 | } else | |
1347 | if (event.m_eventType == wxEVT_SCROLL_LINEUP) { | |
1348 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1349 | } else | |
1350 | if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) { | |
1351 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1352 | } else | |
1353 | if (event.m_eventType == wxEVT_SCROLL_PAGEUP) { | |
1354 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1355 | } else | |
1356 | if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) { | |
1357 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1358 | } else | |
1359 | if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) { | |
1360 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1361 | } | |
1362 | ||
1363 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
1364 | } |
1365 | } | |
1366 | ||
e766c8a9 | 1367 | bool wxWindowMac::SetFont(const wxFont& font) |
e9576ca5 | 1368 | { |
e7549107 SC |
1369 | if ( !wxWindowBase::SetFont(font) ) |
1370 | { | |
1371 | // nothing to do | |
1372 | return FALSE; | |
e9576ca5 | 1373 | } |
e9576ca5 | 1374 | |
e7549107 | 1375 | return TRUE; |
e9576ca5 SC |
1376 | } |
1377 | ||
1378 | // Get the window with the focus | |
e766c8a9 | 1379 | wxWindowMac *wxWindowBase::FindFocus() |
e9576ca5 | 1380 | { |
6264b550 | 1381 | return gFocusWindow ; |
519cb848 SC |
1382 | } |
1383 | ||
e7549107 | 1384 | #if WXWIN_COMPATIBILITY |
e9576ca5 SC |
1385 | // If nothing defined for this, try the parent. |
1386 | // E.g. we may be a button loaded from a resource, with no callback function | |
1387 | // defined. | |
e766c8a9 | 1388 | void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event) |
e9576ca5 | 1389 | { |
e7549107 SC |
1390 | if ( GetEventHandler()->ProcessEvent(event) ) |
1391 | return; | |
1392 | if ( m_parent ) | |
1393 | m_parent->GetEventHandler()->OnCommand(win, event); | |
e9576ca5 | 1394 | } |
e7549107 | 1395 | #endif // WXWIN_COMPATIBILITY_2 |
e9576ca5 | 1396 | |
e7549107 | 1397 | #if WXWIN_COMPATIBILITY |
e766c8a9 | 1398 | wxObject* wxWindowMac::GetChild(int number) const |
e9576ca5 | 1399 | { |
e7549107 SC |
1400 | // Return a pointer to the Nth object in the Panel |
1401 | wxNode *node = GetChildren().First(); | |
1402 | int n = number; | |
1403 | while (node && n--) | |
1404 | node = node->Next(); | |
1405 | if ( node ) | |
519cb848 | 1406 | { |
e7549107 SC |
1407 | wxObject *obj = (wxObject *)node->Data(); |
1408 | return(obj); | |
519cb848 SC |
1409 | } |
1410 | else | |
e7549107 | 1411 | return NULL; |
e9576ca5 | 1412 | } |
e7549107 | 1413 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 1414 | |
e766c8a9 | 1415 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
1416 | { |
1417 | // panel wants to track the window which was the last to have focus in it, | |
1418 | // so we want to set ourselves as the window which last had focus | |
1419 | // | |
1420 | // notice that it's also important to do it upwards the tree becaus | |
1421 | // otherwise when the top level panel gets focus, it won't set it back to | |
1422 | // us, but to some other sibling | |
c1fb8167 SC |
1423 | |
1424 | // CS:don't know if this is still needed: | |
1425 | //wxChildFocusEvent eventFocus(this); | |
1426 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b SC |
1427 | |
1428 | event.Skip(); | |
1429 | } | |
1430 | ||
e766c8a9 | 1431 | void wxWindowMac::Clear() |
e9576ca5 | 1432 | { |
6264b550 RR |
1433 | if ( m_macWindowData ) |
1434 | { | |
1435 | wxMacDrawingClientHelper helper ( this ) ; | |
1436 | int w ,h ; | |
1437 | wxPoint origin = GetClientAreaOrigin() ; | |
1438 | GetClientSize( &w , &h ) ; | |
1439 | ::SetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
1440 | Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ; | |
1441 | EraseRect( &r ) ; | |
1442 | } | |
1443 | else | |
1444 | { | |
1445 | wxClientDC dc(this); | |
1446 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1447 | dc.SetBackground(brush); | |
1448 | dc.Clear(); | |
1449 | } | |
e9576ca5 SC |
1450 | } |
1451 | ||
e7549107 | 1452 | // Setup background and foreground colours correctly |
e766c8a9 | 1453 | void wxWindowMac::SetupColours() |
e9576ca5 | 1454 | { |
e7549107 SC |
1455 | if ( GetParent() ) |
1456 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
e9576ca5 SC |
1457 | } |
1458 | ||
e766c8a9 | 1459 | void wxWindowMac::OnIdle(wxIdleEvent& event) |
e9576ca5 | 1460 | { |
519cb848 SC |
1461 | /* |
1462 | // Check if we need to send a LEAVE event | |
1463 | if (m_mouseInWindow) | |
1464 | { | |
1465 | POINT pt; | |
1466 | ::GetCursorPos(&pt); | |
1467 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
1468 | { | |
1469 | // Generate a LEAVE event | |
1470 | m_mouseInWindow = FALSE; | |
1471 | MSWOnMouseLeave(pt.x, pt.y, 0); | |
1472 | } | |
e9576ca5 SC |
1473 | } |
1474 | */ | |
1475 | ||
1476 | // This calls the UI-update mechanism (querying windows for | |
1477 | // menu/toolbar/control state information) | |
6264b550 | 1478 | UpdateWindowUI(); |
e9576ca5 SC |
1479 | } |
1480 | ||
1481 | // Raise the window to the top of the Z order | |
e766c8a9 | 1482 | void wxWindowMac::Raise() |
e9576ca5 | 1483 | { |
f32e5dc5 SC |
1484 | if ( m_macWindowData ) |
1485 | { | |
72055702 | 1486 | ::BringToFront( m_macWindowData->m_macWindow ) ; |
f32e5dc5 | 1487 | } |
e9576ca5 SC |
1488 | } |
1489 | ||
1490 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 1491 | void wxWindowMac::Lower() |
e9576ca5 | 1492 | { |
f32e5dc5 SC |
1493 | if ( m_macWindowData ) |
1494 | { | |
72055702 | 1495 | ::SendBehind( m_macWindowData->m_macWindow , NULL ) ; |
f32e5dc5 | 1496 | } |
e9576ca5 SC |
1497 | } |
1498 | ||
e766c8a9 | 1499 | void wxWindowMac::DoSetClientSize(int width, int height) |
519cb848 | 1500 | { |
6264b550 RR |
1501 | if ( width != -1 || height != -1 ) |
1502 | { | |
1503 | ||
1504 | if ( width != -1 && m_vScrollBar ) | |
1505 | width += MAC_SCROLLBAR_SIZE ; | |
1506 | if ( height != -1 && m_vScrollBar ) | |
1507 | height += MAC_SCROLLBAR_SIZE ; | |
519cb848 | 1508 | |
6264b550 RR |
1509 | width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1510 | height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
2f1ae414 | 1511 | |
6264b550 RR |
1512 | DoSetSize( -1 , -1 , width , height ) ; |
1513 | } | |
519cb848 SC |
1514 | } |
1515 | ||
519cb848 | 1516 | |
e766c8a9 | 1517 | wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; |
519cb848 | 1518 | |
e766c8a9 | 1519 | bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) |
519cb848 | 1520 | { |
6264b550 RR |
1521 | if ((point.x < m_x) || (point.y < m_y) || |
1522 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1523 | return FALSE; | |
1524 | ||
1525 | WindowRef window = GetMacRootWindow() ; | |
519cb848 | 1526 | |
6264b550 | 1527 | wxPoint newPoint( point ) ; |
519cb848 | 1528 | |
6264b550 RR |
1529 | newPoint.x -= m_x; |
1530 | newPoint.y -= m_y; | |
1531 | ||
1532 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1533 | { | |
1534 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1535 | // added the m_isShown test --dmazzoni | |
1536 | if ( child->GetMacRootWindow() == window && child->m_isShown ) | |
1537 | { | |
1538 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1539 | return TRUE; | |
1540 | } | |
1541 | } | |
519cb848 | 1542 | |
6264b550 RR |
1543 | *outWin = this ; |
1544 | return TRUE; | |
519cb848 SC |
1545 | } |
1546 | ||
e766c8a9 | 1547 | bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) |
519cb848 | 1548 | { |
6264b550 RR |
1549 | WindowRef window ; |
1550 | Point pt = { screenpoint.y , screenpoint.x } ; | |
1551 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1552 | { | |
1553 | wxPoint point( screenpoint ) ; | |
1554 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1555 | if ( win ) | |
1556 | { | |
1557 | win->ScreenToClient( point ) ; | |
1558 | return win->MacGetWindowFromPointSub( point , outWin ) ; | |
1559 | } | |
1560 | } | |
1561 | return FALSE ; | |
519cb848 SC |
1562 | } |
1563 | ||
1564 | extern int wxBusyCursorCount ; | |
1565 | ||
e766c8a9 | 1566 | bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) |
519cb848 | 1567 | { |
6264b550 RR |
1568 | if ((event.m_x < m_x) || (event.m_y < m_y) || |
1569 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1570 | return FALSE; | |
1571 | ||
1572 | ||
1573 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) ) | |
1574 | return FALSE ; | |
1575 | ||
1576 | WindowRef window = GetMacRootWindow() ; | |
1577 | ||
1578 | event.m_x -= m_x; | |
1579 | event.m_y -= m_y; | |
1580 | ||
1581 | int x = event.m_x ; | |
1582 | int y = event.m_y ; | |
1583 | ||
1584 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1585 | { | |
1586 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1587 | if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() ) | |
1588 | { | |
1589 | if (child->MacDispatchMouseEvent(event)) | |
1590 | return TRUE; | |
1591 | } | |
7810c95b | 1592 | } |
2f1ae414 | 1593 | |
6264b550 RR |
1594 | event.m_x = x ; |
1595 | event.m_y = y ; | |
1596 | ||
1597 | if ( wxBusyCursorCount == 0 ) | |
1598 | { | |
1599 | m_cursor.MacInstall() ; | |
1600 | } | |
1601 | ||
1602 | if ( event.GetEventType() == wxEVT_LEFT_DOWN ) | |
1603 | { | |
1604 | // set focus to this window | |
1605 | if (AcceptsFocus() && FindFocus()!=this) | |
1606 | SetFocus(); | |
1607 | } | |
1608 | ||
2f1ae414 SC |
1609 | #if wxUSE_TOOLTIPS |
1610 | if ( event.GetEventType() == wxEVT_MOTION | |
6264b550 RR |
1611 | || event.GetEventType() == wxEVT_ENTER_WINDOW |
1612 | || event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
2f1ae414 SC |
1613 | wxToolTip::RelayEvent( this , event); |
1614 | #endif // wxUSE_TOOLTIPS | |
6264b550 RR |
1615 | GetEventHandler()->ProcessEvent( event ) ; |
1616 | return TRUE; | |
519cb848 SC |
1617 | } |
1618 | ||
2f1ae414 SC |
1619 | Point lastWhere ; |
1620 | long lastWhen = 0 ; | |
1621 | ||
e766c8a9 | 1622 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 1623 | { |
6264b550 RR |
1624 | if ( m_tooltip ) |
1625 | { | |
1626 | return m_tooltip->GetTip() ; | |
1627 | } | |
1628 | return "" ; | |
2f1ae414 | 1629 | } |
e766c8a9 | 1630 | void wxWindowMac::MacFireMouseEvent( EventRecord *ev ) |
519cb848 | 1631 | { |
6264b550 RR |
1632 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
1633 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
1634 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
1635 | ||
1636 | event.m_leftDown = isDown && !controlDown; | |
1637 | ||
1638 | event.m_middleDown = FALSE; | |
1639 | event.m_rightDown = isDown && controlDown; | |
1640 | ||
1641 | if ( ev->what == mouseDown ) | |
1642 | { | |
1643 | if ( controlDown ) | |
1644 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
1645 | else | |
1646 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
1647 | } | |
1648 | else if ( ev->what == mouseUp ) | |
1649 | { | |
1650 | if ( controlDown ) | |
1651 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
1652 | else | |
1653 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
1654 | } | |
1655 | else | |
1656 | { | |
1657 | event.SetEventType(wxEVT_MOTION ) ; | |
1658 | } | |
1659 | ||
1660 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1661 | event.m_controlDown = ev->modifiers & controlKey; | |
1662 | event.m_altDown = ev->modifiers & optionKey; | |
1663 | event.m_metaDown = ev->modifiers & cmdKey; | |
1664 | ||
1665 | Point localwhere = ev->where ; | |
1666 | ||
1667 | GrafPtr port ; | |
1668 | ::GetPort( &port ) ; | |
1669 | ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ; | |
1670 | ::GlobalToLocal( &localwhere ) ; | |
1671 | ::SetPort( port ) ; | |
1672 | ||
1673 | if ( ev->what == mouseDown ) | |
1674 | { | |
1675 | if ( ev->when - lastWhen <= GetDblTime() ) | |
1676 | { | |
1677 | if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 ) | |
1678 | { | |
1679 | if ( controlDown ) | |
1680 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
1681 | else | |
1682 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
1683 | } | |
1684 | lastWhen = 0 ; | |
1685 | } | |
1686 | else | |
1687 | { | |
1688 | lastWhen = ev->when ; | |
1689 | } | |
1690 | lastWhere = localwhere ; | |
1691 | } | |
1692 | ||
1693 | event.m_x = localwhere.h; | |
1694 | event.m_y = localwhere.v; | |
1695 | event.m_x += m_x; | |
1696 | event.m_y += m_y; | |
519cb848 SC |
1697 | |
1698 | /* | |
6264b550 | 1699 | wxPoint origin = GetClientAreaOrigin() ; |
519cb848 | 1700 | |
6264b550 RR |
1701 | event.m_x += origin.x ; |
1702 | event.m_y += origin.y ; | |
519cb848 | 1703 | */ |
6264b550 RR |
1704 | |
1705 | event.m_timeStamp = ev->when; | |
1706 | event.SetEventObject(this); | |
1707 | if ( wxTheApp->s_captureWindow ) | |
1708 | { | |
1709 | int x = event.m_x ; | |
1710 | int y = event.m_y ; | |
1711 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
1712 | event.m_x = x ; | |
1713 | event.m_y = y ; | |
1714 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; | |
1715 | if ( ev->what == mouseUp ) | |
1716 | { | |
1717 | wxTheApp->s_captureWindow = NULL ; | |
1718 | if ( wxBusyCursorCount == 0 ) | |
1719 | { | |
1720 | m_cursor.MacInstall() ; | |
1721 | } | |
1722 | } | |
1723 | } | |
1724 | else | |
1725 | { | |
1726 | MacDispatchMouseEvent( event ) ; | |
1727 | } | |
519cb848 SC |
1728 | } |
1729 | ||
e766c8a9 | 1730 | void wxWindowMac::MacMouseDown( EventRecord *ev , short part) |
519cb848 | 1731 | { |
6264b550 | 1732 | MacFireMouseEvent( ev ) ; |
519cb848 SC |
1733 | } |
1734 | ||
e766c8a9 | 1735 | void wxWindowMac::MacMouseUp( EventRecord *ev , short part) |
519cb848 | 1736 | { |
6264b550 RR |
1737 | switch (part) |
1738 | { | |
1739 | case inContent: | |
1740 | { | |
1741 | MacFireMouseEvent( ev ) ; | |
1742 | } | |
1743 | break ; | |
1744 | } | |
519cb848 SC |
1745 | } |
1746 | ||
e766c8a9 | 1747 | void wxWindowMac::MacMouseMoved( EventRecord *ev , short part) |
519cb848 | 1748 | { |
6264b550 RR |
1749 | switch (part) |
1750 | { | |
1751 | case inContent: | |
1752 | { | |
1753 | MacFireMouseEvent( ev ) ; | |
1754 | } | |
1755 | break ; | |
1756 | } | |
519cb848 | 1757 | } |
e766c8a9 | 1758 | void wxWindowMac::MacActivate( EventRecord *ev , bool inIsActivating ) |
519cb848 | 1759 | { |
fdaf613a SC |
1760 | if ( !m_macWindowData->m_macHasReceivedFirstActivate ) |
1761 | m_macWindowData->m_macHasReceivedFirstActivate = true ; | |
1762 | ||
6264b550 RR |
1763 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); |
1764 | event.m_timeStamp = ev->when ; | |
1765 | event.SetEventObject(this); | |
1766 | ||
1767 | GetEventHandler()->ProcessEvent(event); | |
1768 | ||
e42eaa04 | 1769 | Refresh(false) ; |
6264b550 RR |
1770 | UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ; |
1771 | // MacUpdateImmediately() ; | |
519cb848 SC |
1772 | } |
1773 | ||
e766c8a9 | 1774 | void wxWindowMac::MacRedraw( RgnHandle updatergn , long time) |
519cb848 | 1775 | { |
6264b550 RR |
1776 | // updatergn is always already clipped to our boundaries |
1777 | WindowRef window = GetMacRootWindow() ; | |
1778 | // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children | |
1779 | RgnHandle ownUpdateRgn = NewRgn() ; | |
1780 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
1781 | ||
1782 | { | |
1783 | wxMacDrawingHelper focus( this ) ; // was client | |
1784 | if ( focus.Ok() ) | |
1785 | { | |
1786 | WindowRef window = GetMacRootWindow() ; | |
1787 | bool eraseBackground = false ; | |
1788 | if ( m_macWindowData ) | |
1789 | eraseBackground = true ; | |
1790 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
1791 | { | |
1792 | ::SetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
1793 | } | |
1794 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
1795 | { | |
1796 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
1797 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
1798 | // either a non gray background color or a non control window | |
1799 | ||
1800 | ||
1801 | wxWindowMac* parent = GetParent() ; | |
1802 | while( parent ) | |
1803 | { | |
1804 | if ( parent->GetMacRootWindow() != window ) | |
1805 | { | |
1806 | // we are in a different window on the mac system | |
1807 | parent = NULL ; | |
1808 | break ; | |
1809 | } | |
1810 | ||
1811 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
1812 | { | |
1813 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
1814 | { | |
1815 | // if we have any other colours in the hierarchy | |
1816 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
1817 | break ; | |
1818 | } | |
1819 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
1820 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
1821 | { | |
1822 | Rect box ; | |
1823 | GetRegionBounds( updatergn , &box) ; | |
1824 | ::ApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true); | |
1825 | break ; | |
1826 | } | |
1827 | } | |
1828 | else | |
1829 | { | |
1830 | parent = NULL ; | |
1831 | break ; | |
1832 | } | |
1833 | parent = parent->GetParent() ; | |
1834 | } | |
1835 | if ( !parent ) | |
1836 | { | |
1837 | // if there is nothing special -> use default | |
1838 | ::SetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
1839 | } | |
1840 | } | |
1841 | else | |
1842 | { | |
1843 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
1844 | } | |
ca715d88 | 1845 | // subtract all non transparent children from updatergn |
fd2e20ff | 1846 | |
6264b550 RR |
1847 | RgnHandle childarea = NewRgn() ; |
1848 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1849 | { | |
1850 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1851 | // eventually test for transparent windows | |
1852 | if ( child->GetMacRootWindow() == window && child->IsShown() ) | |
1853 | { | |
1854 | if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() ) | |
1855 | { | |
1856 | SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1857 | DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ; | |
1858 | } | |
1859 | } | |
1860 | } | |
1861 | DisposeRgn( childarea ) ; | |
1862 | ||
1863 | if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) | |
1864 | eraseBackground = true ; | |
1865 | SetClip( ownUpdateRgn ) ; | |
1866 | if ( m_macEraseOnRedraw ) { | |
1867 | if ( eraseBackground ) | |
1868 | { | |
1869 | EraseRgn( ownUpdateRgn ) ; | |
1870 | } | |
1871 | } | |
1872 | else { | |
1873 | m_macEraseOnRedraw = true ; | |
1874 | } | |
1875 | } | |
1876 | ||
1877 | { | |
1878 | RgnHandle newupdate = NewRgn() ; | |
1879 | wxSize point = GetClientSize() ; | |
1880 | wxPoint origin = GetClientAreaOrigin() ; | |
1881 | ||
1882 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; | |
1883 | SectRgn( newupdate , ownUpdateRgn , newupdate ) ; | |
1884 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1885 | m_updateRegion = newupdate ; | |
1886 | DisposeRgn( newupdate ) ; | |
1887 | } | |
1888 | ||
1889 | MacPaintBorders() ; | |
1890 | wxPaintEvent event; | |
1891 | event.m_timeStamp = time ; | |
1892 | event.SetEventObject(this); | |
1893 | GetEventHandler()->ProcessEvent(event); | |
1894 | } | |
1895 | ||
1896 | ||
1897 | RgnHandle childupdate = NewRgn() ; | |
1898 | ||
1899 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1900 | { | |
1901 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1902 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1903 | SectRgn( childupdate , updatergn , childupdate ) ; | |
1904 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
1905 | if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) | |
1906 | { | |
1907 | // because dialogs may also be children | |
1908 | child->MacRedraw( childupdate , time ) ; | |
1909 | } | |
1910 | } | |
1911 | DisposeRgn( childupdate ) ; | |
1912 | // eventually a draw grow box here | |
519cb848 SC |
1913 | } |
1914 | ||
e766c8a9 | 1915 | void wxWindowMac::MacUpdateImmediately() |
519cb848 | 1916 | { |
6264b550 RR |
1917 | WindowRef window = GetMacRootWindow() ; |
1918 | if ( window ) | |
1919 | { | |
1920 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1921 | #if TARGET_CARBON | |
1922 | AGAPortHelper help( GetWindowPort(window) ) ; | |
1923 | #else | |
1924 | AGAPortHelper help( (window) ) ; | |
1925 | #endif | |
1926 | SetOrigin( 0 , 0 ) ; | |
1927 | BeginUpdate( window ) ; | |
1928 | if ( win ) | |
1929 | { | |
1930 | RgnHandle region = NewRgn(); | |
1931 | ||
1932 | if ( region ) | |
1933 | { | |
1934 | GetPortVisibleRegion( GetWindowPort( window ), region ); | |
1935 | ||
1936 | // if windowshade gives incompatibility , take the follwing out | |
1937 | if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) | |
1938 | { | |
1939 | win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ; | |
1940 | } | |
1941 | DisposeRgn( region ); | |
1942 | } | |
1943 | } | |
1944 | EndUpdate( window ) ; | |
1945 | } | |
519cb848 SC |
1946 | } |
1947 | ||
e766c8a9 | 1948 | void wxWindowMac::MacUpdate( EventRecord *ev ) |
519cb848 | 1949 | { |
6264b550 RR |
1950 | WindowRef window = (WindowRef) ev->message ; |
1951 | wxWindowMac * win = wxFindWinFromMacWindow( window ) ; | |
1952 | #if TARGET_CARBON | |
1953 | AGAPortHelper help( GetWindowPort(window) ) ; | |
1954 | #else | |
1955 | AGAPortHelper help( (window) ) ; | |
1956 | #endif | |
1957 | SetOrigin( 0 , 0 ) ; | |
1958 | BeginUpdate( window ) ; | |
1959 | if ( win ) | |
1960 | { | |
1961 | RgnHandle region = NewRgn(); | |
1962 | ||
1963 | if ( region ) | |
1964 | { | |
2f1ae414 SC |
1965 | GetPortVisibleRegion( GetWindowPort( window ), region ); |
1966 | ||
6264b550 | 1967 | // if windowshade gives incompatibility , take the follwing out |
fdaf613a | 1968 | if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) |
2f1ae414 | 1969 | { |
6264b550 | 1970 | MacRedraw( region , ev->when ) ; |
2f1ae414 SC |
1971 | } |
1972 | DisposeRgn( region ); | |
1973 | } | |
6264b550 RR |
1974 | } |
1975 | EndUpdate( window ) ; | |
519cb848 SC |
1976 | } |
1977 | ||
e766c8a9 | 1978 | WindowRef wxWindowMac::GetMacRootWindow() const |
519cb848 | 1979 | { |
6264b550 RR |
1980 | wxWindowMac *iter = (wxWindowMac*)this ; |
1981 | ||
1982 | while( iter ) | |
1983 | { | |
1984 | if ( iter->m_macWindowData ) | |
1985 | return iter->m_macWindowData->m_macWindow ; | |
519cb848 | 1986 | |
6264b550 RR |
1987 | iter = iter->GetParent() ; |
1988 | } | |
1989 | wxASSERT_MSG( 1 , "No valid mac root window" ) ; | |
1990 | return NULL ; | |
519cb848 SC |
1991 | } |
1992 | ||
e766c8a9 | 1993 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 1994 | { |
6264b550 RR |
1995 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; |
1996 | ||
1997 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
1998 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
1999 | int width, height ; | |
2000 | GetClientSize( &width , &height ) ; | |
2001 | ||
2002 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
2003 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2004 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2005 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
2006 | ||
2007 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
2008 | vSize , wxVERTICAL); | |
2009 | ||
2010 | if ( style & wxVSCROLL ) | |
2011 | { | |
2012 | ||
2013 | } | |
2014 | else | |
2015 | { | |
2016 | m_vScrollBar->Show(false) ; | |
2017 | } | |
2018 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
2019 | hSize , wxHORIZONTAL); | |
2020 | if ( style & wxHSCROLL ) | |
2021 | { | |
2022 | } | |
2023 | else | |
2024 | { | |
2025 | m_hScrollBar->Show(false) ; | |
2026 | } | |
2027 | ||
2028 | // because the create does not take into account the client area origin | |
2029 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
2030 | } |
2031 | ||
e766c8a9 | 2032 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 2033 | { |
6264b550 RR |
2034 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
2035 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
2036 | ||
2037 | // get real client area | |
2038 | ||
2039 | int width = m_width ; | |
2040 | int height = m_height ; | |
2041 | ||
2042 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2043 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
2044 | ||
2045 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
2046 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2047 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2048 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
2049 | ||
2050 | int x = 0 ; | |
2051 | int y = 0 ; | |
2052 | int w = m_width ; | |
2053 | int h = m_height ; | |
2054 | ||
2055 | MacClientToRootWindow( &x , &y ) ; | |
2056 | MacClientToRootWindow( &w , &h ) ; | |
2057 | ||
2058 | wxWindowMac *iter = (wxWindowMac*)this ; | |
2059 | ||
2060 | int totW = 10000 , totH = 10000; | |
2061 | while( iter ) | |
2062 | { | |
2063 | if ( iter->m_macWindowData ) | |
2064 | { | |
2065 | totW = iter->m_width ; | |
2066 | totH = iter->m_height ; | |
2067 | break ; | |
2068 | } | |
2069 | ||
2070 | iter = iter->GetParent() ; | |
2071 | } | |
2072 | ||
2073 | if ( x == 0 ) | |
2074 | { | |
2075 | hPoint.x = -1 ; | |
2076 | hSize.x += 1 ; | |
2077 | } | |
2078 | if ( y == 0 ) | |
2079 | { | |
2080 | vPoint.y = -1 ; | |
2081 | vSize.y += 1 ; | |
2082 | } | |
2083 | ||
2084 | if ( w-x >= totW ) | |
2085 | { | |
2086 | hSize.x += 1 ; | |
2087 | vPoint.x += 1 ; | |
2088 | } | |
2089 | ||
2090 | if ( h-y >= totH ) | |
2091 | { | |
2092 | vSize.y += 1 ; | |
2093 | hPoint.y += 1 ; | |
2094 | } | |
2095 | ||
2096 | if ( m_vScrollBar ) | |
2097 | { | |
2098 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
2099 | } | |
2100 | if ( m_hScrollBar ) | |
2101 | { | |
2102 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
2103 | } | |
519cb848 SC |
2104 | } |
2105 | ||
e766c8a9 | 2106 | void wxWindowMac::MacKeyDown( EventRecord *ev ) |
519cb848 | 2107 | { |
2f1ae414 | 2108 | |
519cb848 SC |
2109 | } |
2110 | ||
2111 | ||
e766c8a9 | 2112 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
2113 | { |
2114 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
2115 | } | |
519cb848 | 2116 | |
e766c8a9 | 2117 | ControlHandle wxWindowMac::MacGetContainerForEmbedding() |
519cb848 | 2118 | { |
6264b550 RR |
2119 | if ( m_macWindowData ) |
2120 | return m_macWindowData->m_macRootControl ; | |
2121 | else | |
2122 | return GetParent()->MacGetContainerForEmbedding() ; | |
519cb848 SC |
2123 | } |
2124 | ||
e766c8a9 | 2125 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 2126 | { |
6264b550 | 2127 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 2128 | |
6264b550 RR |
2129 | wxNode *node = GetChildren().First(); |
2130 | while ( node ) | |
2131 | { | |
2132 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
2133 | child->MacSuperChangedPosition() ; | |
2134 | node = node->Next(); | |
2135 | } | |
519cb848 | 2136 | } |
519cb848 | 2137 | |
a3bf4a62 SC |
2138 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
2139 | { | |
6264b550 | 2140 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 2141 | |
6264b550 RR |
2142 | wxNode *node = GetChildren().First(); |
2143 | while ( node ) | |
2144 | { | |
2145 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
2146 | child->MacTopLevelWindowChangedPosition() ; | |
2147 | node = node->Next(); | |
2148 | } | |
a3bf4a62 SC |
2149 | } |
2150 | ||
e766c8a9 | 2151 | bool wxWindowMac::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win ) |
519cb848 | 2152 | { |
6264b550 RR |
2153 | if ( window == NULL ) |
2154 | return false ; | |
2155 | ||
2156 | GrafPtr currPort; | |
2157 | GrafPtr port ; | |
519cb848 | 2158 | |
6264b550 RR |
2159 | ::GetPort(&currPort); |
2160 | port = UMAGetWindowPort( window) ; | |
2161 | if (currPort != port ) | |
2162 | ::SetPort(port); | |
2163 | ||
2164 | // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; | |
2165 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2166 | return true; | |
519cb848 SC |
2167 | } |
2168 | ||
e766c8a9 | 2169 | bool wxWindowMac::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win ) |
519cb848 | 2170 | { |
6264b550 RR |
2171 | if ( window == NULL ) |
2172 | return false ; | |
2173 | ||
2174 | GrafPtr currPort; | |
2175 | GrafPtr port ; | |
2176 | ::GetPort(&currPort); | |
2177 | port = UMAGetWindowPort( window) ; | |
2178 | if (currPort != port ) | |
2179 | ::SetPort(port); | |
2180 | // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; | |
2181 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2182 | ::ClipRect(&clipRect); | |
2183 | ||
2184 | ::PenNormal() ; | |
2185 | ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ; | |
2186 | ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ; | |
2187 | Pattern whiteColor ; | |
2188 | ||
2189 | ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ; | |
2190 | ::SetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
2191 | return true; | |
519cb848 SC |
2192 | } |
2193 | ||
e766c8a9 | 2194 | void wxWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin) |
519cb848 | 2195 | { |
6264b550 RR |
2196 | if ( m_macWindowData ) |
2197 | { | |
2198 | localOrigin->h = 0; | |
2199 | localOrigin->v = 0; | |
2200 | clipRect->left = 0; | |
2201 | clipRect->top = 0; | |
2202 | clipRect->right = m_width; | |
2203 | clipRect->bottom = m_height; | |
2204 | *window = m_macWindowData->m_macWindow ; | |
2205 | *rootwin = this ; | |
2206 | } | |
2207 | else | |
2208 | { | |
2209 | wxASSERT( GetParent() != NULL ) ; | |
2210 | GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ; | |
2211 | localOrigin->h += m_x; | |
2212 | localOrigin->v += m_y; | |
2213 | OffsetRect(clipRect, -m_x, -m_y); | |
2214 | ||
2215 | Rect myClip; | |
2216 | myClip.left = 0; | |
2217 | myClip.top = 0; | |
2218 | myClip.right = m_width; | |
2219 | myClip.bottom = m_height; | |
2220 | SectRect(clipRect, &myClip, clipRect); | |
2221 | } | |
519cb848 SC |
2222 | } |
2223 | ||
e766c8a9 | 2224 | void wxWindowMac::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) |
519cb848 | 2225 | { |
6264b550 RR |
2226 | // int width , height ; |
2227 | // GetClientSize( &width , &height ) ; | |
2228 | ||
2229 | if ( m_macWindowData ) | |
2230 | { | |
2231 | localOrigin->h = 0; | |
2232 | localOrigin->v = 0; | |
2233 | clipRect->left = 0; | |
2234 | clipRect->top = 0; | |
2235 | clipRect->right = m_width ;//width; | |
2236 | clipRect->bottom = m_height ;// height; | |
2237 | *window = m_macWindowData->m_macWindow ; | |
2238 | *rootwin = this ; | |
2239 | } | |
2240 | else | |
2241 | { | |
2242 | wxASSERT( GetParent() != NULL ) ; | |
2243 | ||
2244 | GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ; | |
2245 | ||
2246 | localOrigin->h += m_x; | |
2247 | localOrigin->v += m_y; | |
2248 | OffsetRect(clipRect, -m_x, -m_y); | |
2249 | ||
2250 | Rect myClip; | |
2251 | myClip.left = 0; | |
2252 | myClip.top = 0; | |
2253 | myClip.right = m_width ;//width; | |
2254 | myClip.bottom = m_height ;// height; | |
2255 | SectRect(clipRect, &myClip, clipRect); | |
2256 | } | |
519cb848 SC |
2257 | } |
2258 | ||
e766c8a9 | 2259 | void wxWindowMac::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) |
2f1ae414 | 2260 | { |
6264b550 | 2261 | MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ; |
2f1ae414 | 2262 | |
6264b550 RR |
2263 | int width , height ; |
2264 | GetClientSize( &width , &height ) ; | |
2265 | wxPoint client ; | |
2266 | client = GetClientAreaOrigin( ) ; | |
2267 | ||
2268 | localOrigin->h += client.x; | |
2269 | localOrigin->v += client.y; | |
2270 | OffsetRect(clipRect, -client.x, -client.y); | |
2f1ae414 | 2271 | |
6264b550 RR |
2272 | Rect myClip; |
2273 | myClip.left = 0; | |
2274 | myClip.top = 0; | |
2275 | myClip.right = width; | |
2276 | myClip.bottom = height; | |
2277 | SectRect(clipRect, &myClip, clipRect); | |
2f1ae414 SC |
2278 | } |
2279 | ||
e766c8a9 | 2280 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 2281 | { |
6264b550 RR |
2282 | if( m_macWindowData ) |
2283 | return 0 ; | |
2f1ae414 SC |
2284 | |
2285 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2286 | { | |
6264b550 | 2287 | return 3 ; |
2f1ae414 SC |
2288 | } |
2289 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2290 | { | |
6264b550 | 2291 | return 3 ; |
2f1ae414 SC |
2292 | } |
2293 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2294 | { | |
6264b550 | 2295 | return 1 ; |
2f1ae414 | 2296 | } |
6264b550 | 2297 | return 0 ; |
2f1ae414 SC |
2298 | } |
2299 | ||
e766c8a9 | 2300 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 2301 | { |
6264b550 RR |
2302 | if( m_macWindowData ) |
2303 | return 0 ; | |
5b781a67 SC |
2304 | |
2305 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2306 | { | |
6264b550 | 2307 | return 3 ; |
5b781a67 SC |
2308 | } |
2309 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2310 | { | |
6264b550 | 2311 | return 3 ; |
5b781a67 SC |
2312 | } |
2313 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2314 | { | |
6264b550 | 2315 | return 1 ; |
5b781a67 | 2316 | } |
6264b550 | 2317 | return 0 ; |
5b781a67 SC |
2318 | } |
2319 | ||
e766c8a9 | 2320 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 2321 | { |
6264b550 RR |
2322 | if( m_macWindowData ) |
2323 | return 0 ; | |
5b781a67 SC |
2324 | |
2325 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2326 | { | |
6264b550 | 2327 | return 3 ; |
5b781a67 SC |
2328 | } |
2329 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2330 | { | |
6264b550 | 2331 | return 3 ; |
5b781a67 SC |
2332 | } |
2333 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2334 | { | |
6264b550 | 2335 | return 1 ; |
5b781a67 | 2336 | } |
6264b550 | 2337 | return 0 ; |
5b781a67 SC |
2338 | } |
2339 | ||
e766c8a9 | 2340 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 2341 | { |
6264b550 RR |
2342 | if( m_macWindowData ) |
2343 | return 0 ; | |
5b781a67 SC |
2344 | |
2345 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2346 | { | |
6264b550 | 2347 | return 3 ; |
5b781a67 SC |
2348 | } |
2349 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2350 | { | |
6264b550 | 2351 | return 3 ; |
5b781a67 SC |
2352 | } |
2353 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2354 | { | |
6264b550 | 2355 | return 1 ; |
5b781a67 | 2356 | } |
6264b550 | 2357 | return 0 ; |
5b781a67 SC |
2358 | } |
2359 | ||
e766c8a9 | 2360 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 2361 | { |
6264b550 | 2362 | return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; |
2f1ae414 | 2363 | } |
0a67a93b | 2364 | |
b89dac78 | 2365 | |
e766c8a9 | 2366 | wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac * theWindow ) |
519cb848 | 2367 | { |
6264b550 RR |
2368 | m_ok = false ; |
2369 | Point localOrigin ; | |
2370 | Rect clipRect ; | |
2371 | WindowRef window ; | |
2372 | wxWindowMac *rootwin ; | |
2373 | m_currentPort = NULL ; | |
2374 | ||
2375 | GetPort( &m_formerPort ) ; | |
2376 | if ( theWindow ) | |
2377 | { | |
2378 | theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2379 | m_currentPort = UMAGetWindowPort( window ) ; | |
2380 | if ( m_formerPort != m_currentPort ) | |
2381 | SetPort( m_currentPort ) ; | |
2382 | GetPenState( &m_savedPenState ) ; | |
2383 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2384 | m_ok = true ; | |
2385 | } | |
2386 | } | |
2387 | ||
519cb848 SC |
2388 | wxMacDrawingHelper::~wxMacDrawingHelper() |
2389 | { | |
6264b550 RR |
2390 | if ( m_ok ) |
2391 | { | |
2392 | SetPort( m_currentPort ) ; | |
2393 | SetPenState( &m_savedPenState ) ; | |
2394 | SetOrigin( 0 , 0 ) ; | |
2395 | Rect portRect ; | |
2396 | GetPortBounds( m_currentPort , &portRect ) ; | |
2397 | ClipRect( &portRect ) ; | |
2398 | } | |
2399 | ||
2400 | if ( m_formerPort != m_currentPort ) | |
2401 | SetPort( m_formerPort ) ; | |
519cb848 | 2402 | } |
519cb848 | 2403 | |
e766c8a9 | 2404 | wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac * theWindow ) |
519cb848 | 2405 | { |
6264b550 RR |
2406 | m_ok = false ; |
2407 | Point localOrigin ; | |
2408 | Rect clipRect ; | |
2409 | WindowRef window ; | |
2410 | wxWindowMac *rootwin ; | |
2411 | m_currentPort = NULL ; | |
2412 | ||
2413 | GetPort( &m_formerPort ) ; | |
2414 | ||
2415 | if ( theWindow ) | |
2416 | { | |
2417 | theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2418 | m_currentPort = UMAGetWindowPort( window ) ; | |
2419 | if ( m_formerPort != m_currentPort ) | |
2420 | SetPort( m_currentPort ) ; | |
2421 | GetPenState( &m_savedPenState ) ; | |
2422 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2423 | m_ok = true ; | |
2424 | } | |
2425 | } | |
2426 | ||
519cb848 SC |
2427 | wxMacDrawingClientHelper::~wxMacDrawingClientHelper() |
2428 | { | |
6264b550 RR |
2429 | if ( m_ok ) |
2430 | { | |
2431 | SetPort( m_currentPort ) ; | |
2432 | SetPenState( &m_savedPenState ) ; | |
2433 | SetOrigin( 0 , 0 ) ; | |
2434 | Rect portRect ; | |
2435 | GetPortBounds( m_currentPort , &portRect ) ; | |
2436 | ClipRect( &portRect ) ; | |
2437 | } | |
2438 | ||
2439 | if ( m_formerPort != m_currentPort ) | |
2440 | SetPort( m_formerPort ) ; | |
519cb848 | 2441 | } |
3723b7b1 | 2442 | |
e766c8a9 | 2443 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 2444 | // position. |
e766c8a9 | 2445 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 2446 | { |
59a12e90 | 2447 | pt = wxGetMousePosition(); |
e766c8a9 | 2448 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 2449 | return found; |
3723b7b1 JS |
2450 | } |
2451 | ||
2452 | // Get the current mouse position. | |
2453 | wxPoint wxGetMousePosition() | |
2454 | { | |
57591e0e JS |
2455 | int x, y; |
2456 | wxGetMousePosition(& x, & y); | |
2457 | return wxPoint(x, y); | |
3723b7b1 JS |
2458 | } |
2459 |