]>
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 ; | |
574bf507 | 352 | if (!m_macWindowData && GetParent()) |
519cb848 SC |
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); | |
574bf507 | 673 | |
954fc50b SC |
674 | int currentW,currentH; |
675 | GetSize(¤tW, ¤tH); | |
676 | ||
677 | // ... and don't do anything (avoiding flicker) if it's already ok | |
678 | if ( x == currentX && y == currentY && | |
679 | width == currentW && height == currentH ) | |
680 | { | |
6264b550 | 681 | MacRepositionScrollBars() ; // we might have a real position shift |
954fc50b SC |
682 | return; |
683 | } | |
684 | ||
685 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
686 | x = currentX; | |
687 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
688 | y = currentY; | |
689 | ||
690 | AdjustForParentClientOrigin(x, y, sizeFlags); | |
691 | ||
692 | wxSize size(-1, -1); | |
693 | if ( width == -1 ) | |
694 | { | |
695 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
696 | { | |
697 | size = DoGetBestSize(); | |
698 | width = size.x; | |
699 | } | |
700 | else | |
701 | { | |
702 | // just take the current one | |
703 | width = currentW; | |
704 | } | |
705 | } | |
706 | ||
707 | if ( height == -1 ) | |
708 | { | |
709 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
710 | { | |
711 | if ( size.x == -1 ) | |
712 | { | |
713 | size = DoGetBestSize(); | |
714 | } | |
715 | //else: already called DoGetBestSize() above | |
716 | ||
717 | height = size.y; | |
718 | } | |
719 | else | |
720 | { | |
721 | // just take the current one | |
722 | height = currentH; | |
723 | } | |
724 | } | |
725 | ||
726 | DoMoveWindow(x, y, width, height); | |
727 | ||
e9576ca5 | 728 | } |
e9576ca5 SC |
729 | // For implementation purposes - sometimes decorations make the client area |
730 | // smaller | |
519cb848 | 731 | |
e766c8a9 | 732 | wxPoint wxWindowMac::GetClientAreaOrigin() const |
e9576ca5 | 733 | { |
5b781a67 | 734 | return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); |
e9576ca5 SC |
735 | } |
736 | ||
737 | // Makes an adjustment to the window position (for example, a frame that has | |
738 | // a toolbar that it manages itself). | |
e766c8a9 | 739 | void wxWindowMac::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) |
e9576ca5 | 740 | { |
6264b550 RR |
741 | if( !m_macWindowData ) |
742 | { | |
e9576ca5 SC |
743 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
744 | { | |
745 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
746 | x += pt.x; y += pt.y; | |
747 | } | |
519cb848 SC |
748 | } |
749 | } | |
750 | ||
e766c8a9 | 751 | void wxWindowMac::SetTitle(const wxString& title) |
519cb848 | 752 | { |
6264b550 RR |
753 | m_label = title ; |
754 | ||
755 | wxString label ; | |
756 | ||
757 | if( wxApp::s_macDefaultEncodingIsPC ) | |
758 | label = wxMacMakeMacStringFromPC( title ) ; | |
759 | else | |
760 | label = title ; | |
519cb848 | 761 | |
6264b550 RR |
762 | if ( m_macWindowData ) |
763 | UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; | |
519cb848 SC |
764 | } |
765 | ||
e766c8a9 | 766 | wxString wxWindowMac::GetTitle() const |
519cb848 | 767 | { |
6264b550 | 768 | return m_label ; |
519cb848 SC |
769 | } |
770 | ||
e766c8a9 | 771 | bool wxWindowMac::Show(bool show) |
e9576ca5 | 772 | { |
e7549107 SC |
773 | if ( !wxWindowBase::Show(show) ) |
774 | return FALSE; | |
775 | ||
6264b550 RR |
776 | if ( m_macWindowData ) |
777 | { | |
778 | if (show) | |
779 | { | |
780 | ::ShowWindow( m_macWindowData->m_macWindow ) ; | |
781 | ::SelectWindow( m_macWindowData->m_macWindow ) ; | |
782 | // no need to generate events here, they will get them triggered by macos | |
783 | // actually they should be , but apparently they are not | |
784 | wxSize size(m_width, m_height); | |
785 | wxSizeEvent event(size, m_windowId); | |
786 | event.SetEventObject(this); | |
787 | GetEventHandler()->ProcessEvent(event); | |
788 | } | |
789 | else | |
790 | { | |
791 | ::HideWindow( m_macWindowData->m_macWindow ) ; | |
792 | } | |
793 | } | |
794 | MacSuperShown( show ) ; | |
795 | if ( !show ) | |
796 | { | |
797 | WindowRef window = GetMacRootWindow() ; | |
798 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
799 | if ( win && !win->m_isBeingDeleted ) | |
800 | Refresh() ; | |
801 | } | |
802 | else | |
803 | { | |
804 | Refresh() ; | |
805 | } | |
fdaf613a | 806 | |
e7549107 | 807 | return TRUE; |
e9576ca5 SC |
808 | } |
809 | ||
e766c8a9 | 810 | void wxWindowMac::MacSuperShown( bool show ) |
8208e181 | 811 | { |
6264b550 RR |
812 | wxNode *node = GetChildren().First(); |
813 | while ( node ) | |
814 | { | |
815 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
816 | if ( child->m_isShown ) | |
817 | child->MacSuperShown( show ) ; | |
818 | node = node->Next(); | |
819 | } | |
8208e181 SC |
820 | } |
821 | ||
e766c8a9 | 822 | bool wxWindowMac::MacIsReallyShown() const |
c809f3be | 823 | { |
6264b550 RR |
824 | if ( m_isShown && (m_parent != NULL) ) { |
825 | return m_parent->MacIsReallyShown(); | |
826 | } | |
827 | return m_isShown; | |
828 | /* | |
829 | bool status = m_isShown ; | |
830 | wxWindowMac * win = this ; | |
831 | while ( status && win->m_parent != NULL ) | |
832 | { | |
833 | win = win->m_parent ; | |
834 | status = win->m_isShown ; | |
835 | } | |
836 | return status ; | |
5fde6fcc | 837 | */ |
c809f3be SC |
838 | } |
839 | ||
e766c8a9 | 840 | int wxWindowMac::GetCharHeight() const |
e9576ca5 | 841 | { |
6264b550 RR |
842 | wxClientDC dc ( (wxWindowMac*)this ) ; |
843 | return dc.GetCharHeight() ; | |
e9576ca5 SC |
844 | } |
845 | ||
e766c8a9 | 846 | int wxWindowMac::GetCharWidth() const |
e9576ca5 | 847 | { |
6264b550 RR |
848 | wxClientDC dc ( (wxWindowMac*)this ) ; |
849 | return dc.GetCharWidth() ; | |
e9576ca5 SC |
850 | } |
851 | ||
e766c8a9 | 852 | void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, |
e7549107 | 853 | int *descent, int *externalLeading, const wxFont *theFont ) const |
e9576ca5 | 854 | { |
e7549107 SC |
855 | const wxFont *fontToUse = theFont; |
856 | if ( !fontToUse ) | |
857 | fontToUse = &m_font; | |
7c74e7fe | 858 | |
e766c8a9 | 859 | wxClientDC dc( (wxWindowMac*) this ) ; |
7c74e7fe | 860 | long lx,ly,ld,le ; |
5fde6fcc | 861 | dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; |
2f1ae414 | 862 | if ( externalLeading ) |
6264b550 | 863 | *externalLeading = le ; |
2f1ae414 | 864 | if ( descent ) |
6264b550 | 865 | *descent = ld ; |
2f1ae414 | 866 | if ( x ) |
6264b550 | 867 | *x = lx ; |
2f1ae414 | 868 | if ( y ) |
6264b550 | 869 | *y = ly ; |
e9576ca5 SC |
870 | } |
871 | ||
e766c8a9 | 872 | void wxWindowMac::MacEraseBackground( Rect *rect ) |
519cb848 | 873 | { |
0a67a93b | 874 | /* |
6264b550 RR |
875 | WindowRef window = GetMacRootWindow() ; |
876 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
877 | { | |
878 | UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
879 | } | |
880 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
881 | { | |
882 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
883 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
884 | // either a non gray background color or a non control window | |
885 | ||
886 | wxWindowMac* parent = GetParent() ; | |
887 | while( parent ) | |
888 | { | |
889 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
890 | { | |
891 | // if we have any other colours in the hierarchy | |
892 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
893 | break ; | |
894 | } | |
895 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
896 | { | |
897 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
898 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
899 | { | |
900 | UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); | |
901 | break ; | |
902 | } | |
903 | } | |
904 | else | |
905 | { | |
906 | // we have arrived at a non control item | |
907 | parent = NULL ; | |
908 | break ; | |
909 | } | |
910 | parent = parent->GetParent() ; | |
911 | } | |
912 | if ( !parent ) | |
913 | { | |
914 | // if there is nothing special -> use default | |
915 | UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
916 | } | |
917 | } | |
918 | else | |
919 | { | |
920 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
921 | } | |
922 | ||
923 | EraseRect( rect ) ; | |
924 | ||
925 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
926 | { | |
927 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
928 | ||
929 | Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ; | |
930 | SectRect( &clientrect , rect , &clientrect ) ; | |
931 | ||
932 | OffsetRect( &clientrect , -child->m_x , -child->m_y ) ; | |
933 | if ( child->GetMacRootWindow() == window && child->IsShown() ) | |
934 | { | |
935 | wxMacDrawingClientHelper focus( this ) ; | |
936 | if ( focus.Ok() ) | |
937 | { | |
938 | child->MacEraseBackground( &clientrect ) ; | |
939 | } | |
940 | } | |
941 | } | |
0a67a93b | 942 | */ |
519cb848 SC |
943 | } |
944 | ||
e766c8a9 | 945 | void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) |
e9576ca5 | 946 | { |
fdaf613a SC |
947 | // if ( !IsShown() ) |
948 | // return ; | |
949 | ||
6264b550 RR |
950 | wxMacDrawingClientHelper focus( this ) ; |
951 | if ( focus.Ok() ) | |
952 | { | |
953 | wxPoint client ; | |
954 | client = GetClientAreaOrigin( ) ; | |
955 | Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ; | |
956 | // ClipRect( &clientrect ) ; | |
957 | ||
958 | if ( rect ) | |
959 | { | |
960 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
961 | SectRect( &clientrect , &r , &clientrect ) ; | |
962 | } | |
963 | InvalWindowRect( GetMacRootWindow() , &clientrect ) ; | |
964 | } | |
965 | if ( !eraseBack ) | |
966 | m_macEraseOnRedraw = false ; | |
967 | else | |
968 | m_macEraseOnRedraw = true ; | |
e9576ca5 SC |
969 | } |
970 | ||
971 | // Responds to colour changes: passes event on to children. | |
e766c8a9 | 972 | void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 SC |
973 | { |
974 | wxNode *node = GetChildren().First(); | |
975 | while ( node ) | |
976 | { | |
977 | // Only propagate to non-top-level windows | |
e766c8a9 | 978 | wxWindowMac *win = (wxWindowMac *)node->Data(); |
e9576ca5 SC |
979 | if ( win->GetParent() ) |
980 | { | |
981 | wxSysColourChangedEvent event2; | |
982 | event.m_eventObject = win; | |
983 | win->GetEventHandler()->ProcessEvent(event2); | |
984 | } | |
985 | ||
986 | node = node->Next(); | |
987 | } | |
988 | } | |
989 | ||
e7549107 SC |
990 | #if wxUSE_CARET && WXWIN_COMPATIBILITY |
991 | // --------------------------------------------------------------------------- | |
e9576ca5 | 992 | // Caret manipulation |
e7549107 SC |
993 | // --------------------------------------------------------------------------- |
994 | ||
e766c8a9 | 995 | void wxWindowMac::CreateCaret(int w, int h) |
e9576ca5 | 996 | { |
e7549107 | 997 | SetCaret(new wxCaret(this, w, h)); |
e9576ca5 SC |
998 | } |
999 | ||
e766c8a9 | 1000 | void wxWindowMac::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
e9576ca5 | 1001 | { |
e7549107 | 1002 | wxFAIL_MSG("not implemented"); |
e9576ca5 SC |
1003 | } |
1004 | ||
e766c8a9 | 1005 | void wxWindowMac::ShowCaret(bool show) |
e9576ca5 | 1006 | { |
e7549107 SC |
1007 | wxCHECK_RET( m_caret, "no caret to show" ); |
1008 | ||
1009 | m_caret->Show(show); | |
e9576ca5 SC |
1010 | } |
1011 | ||
e766c8a9 | 1012 | void wxWindowMac::DestroyCaret() |
e9576ca5 | 1013 | { |
e7549107 | 1014 | SetCaret(NULL); |
e9576ca5 SC |
1015 | } |
1016 | ||
e766c8a9 | 1017 | void wxWindowMac::SetCaretPos(int x, int y) |
e9576ca5 | 1018 | { |
e7549107 SC |
1019 | wxCHECK_RET( m_caret, "no caret to move" ); |
1020 | ||
1021 | m_caret->Move(x, y); | |
e9576ca5 SC |
1022 | } |
1023 | ||
e766c8a9 | 1024 | void wxWindowMac::GetCaretPos(int *x, int *y) const |
e9576ca5 | 1025 | { |
e7549107 SC |
1026 | wxCHECK_RET( m_caret, "no caret to get position of" ); |
1027 | ||
1028 | m_caret->GetPosition(x, y); | |
e9576ca5 | 1029 | } |
e7549107 | 1030 | #endif // wxUSE_CARET |
e9576ca5 | 1031 | |
e766c8a9 | 1032 | wxWindowMac *wxGetActiveWindow() |
e9576ca5 | 1033 | { |
519cb848 | 1034 | // actually this is a windows-only concept |
e9576ca5 SC |
1035 | return NULL; |
1036 | } | |
1037 | ||
e9576ca5 | 1038 | // Coordinates relative to the window |
e766c8a9 | 1039 | void wxWindowMac::WarpPointer (int x_pos, int y_pos) |
e9576ca5 | 1040 | { |
519cb848 | 1041 | // We really dont move the mouse programmatically under mac |
e9576ca5 SC |
1042 | } |
1043 | ||
e766c8a9 | 1044 | void wxWindowMac::OnEraseBackground(wxEraseEvent& event) |
e9576ca5 | 1045 | { |
519cb848 | 1046 | // TODO : probably we would adopt the EraseEvent structure |
e9576ca5 SC |
1047 | } |
1048 | ||
e766c8a9 | 1049 | int wxWindowMac::GetScrollPos(int orient) const |
e9576ca5 | 1050 | { |
6264b550 RR |
1051 | if ( orient == wxHORIZONTAL ) |
1052 | { | |
1053 | if ( m_hScrollBar ) | |
1054 | return m_hScrollBar->GetThumbPosition() ; | |
1055 | } | |
1056 | else | |
1057 | { | |
1058 | if ( m_vScrollBar ) | |
1059 | return m_vScrollBar->GetThumbPosition() ; | |
1060 | } | |
e9576ca5 SC |
1061 | return 0; |
1062 | } | |
1063 | ||
1064 | // This now returns the whole range, not just the number | |
1065 | // of positions that we can scroll. | |
e766c8a9 | 1066 | int wxWindowMac::GetScrollRange(int orient) const |
e9576ca5 | 1067 | { |
6264b550 RR |
1068 | if ( orient == wxHORIZONTAL ) |
1069 | { | |
1070 | if ( m_hScrollBar ) | |
1071 | return m_hScrollBar->GetRange() ; | |
1072 | } | |
1073 | else | |
1074 | { | |
1075 | if ( m_vScrollBar ) | |
1076 | return m_vScrollBar->GetRange() ; | |
1077 | } | |
e9576ca5 SC |
1078 | return 0; |
1079 | } | |
1080 | ||
e766c8a9 | 1081 | int wxWindowMac::GetScrollThumb(int orient) const |
e9576ca5 | 1082 | { |
6264b550 RR |
1083 | if ( orient == wxHORIZONTAL ) |
1084 | { | |
1085 | if ( m_hScrollBar ) | |
1086 | return m_hScrollBar->GetThumbSize() ; | |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | if ( m_vScrollBar ) | |
1091 | return m_vScrollBar->GetThumbSize() ; | |
1092 | } | |
e9576ca5 SC |
1093 | return 0; |
1094 | } | |
1095 | ||
e766c8a9 | 1096 | void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh) |
e9576ca5 | 1097 | { |
6264b550 RR |
1098 | if ( orient == wxHORIZONTAL ) |
1099 | { | |
1100 | if ( m_hScrollBar ) | |
1101 | m_hScrollBar->SetThumbPosition( pos ) ; | |
1102 | } | |
1103 | else | |
1104 | { | |
1105 | if ( m_vScrollBar ) | |
1106 | m_vScrollBar->SetThumbPosition( pos ) ; | |
1107 | } | |
e9576ca5 SC |
1108 | } |
1109 | ||
e766c8a9 | 1110 | void wxWindowMac::MacCreateRealWindow( const wxString& title, |
2f1ae414 SC |
1111 | const wxPoint& pos, |
1112 | const wxSize& size, | |
1113 | long style, | |
1114 | const wxString& name ) | |
8208e181 | 1115 | { |
2f1ae414 SC |
1116 | SetName(name); |
1117 | m_windowStyle = style; | |
1118 | m_isShown = FALSE; | |
8208e181 | 1119 | |
2f1ae414 | 1120 | // create frame. |
8208e181 | 1121 | |
6264b550 | 1122 | Rect theBoundsRect; |
2f1ae414 SC |
1123 | |
1124 | m_x = (int)pos.x; | |
1125 | m_y = (int)pos.y; | |
1126 | if ( m_y < 50 ) | |
6264b550 | 1127 | m_y = 50 ; |
2f1ae414 | 1128 | if ( m_x < 20 ) |
6264b550 RR |
1129 | m_x = 20 ; |
1130 | ||
2f1ae414 | 1131 | m_width = size.x; |
6264b550 RR |
1132 | if (m_width == -1) |
1133 | m_width = 20; | |
2f1ae414 | 1134 | m_height = size.y; |
6264b550 RR |
1135 | if (m_height == -1) |
1136 | m_height = 20; | |
1137 | ||
1138 | m_macWindowData = new MacWindowData() ; | |
1139 | ||
1140 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); | |
1141 | ||
1142 | // translate the window attributes in the appropriate window class and attributes | |
1143 | ||
1144 | WindowClass wclass = 0; | |
1145 | WindowAttributes attr = kWindowNoAttributes ; | |
1146 | ||
1147 | if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) | |
1148 | { | |
1149 | wclass = kFloatingWindowClass ; | |
1150 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1151 | { | |
1152 | attr |= kWindowSideTitlebarAttribute ; | |
1153 | } | |
1154 | } | |
1155 | else if ( HasFlag( wxCAPTION ) ) | |
1156 | { | |
1157 | if ( HasFlag( wxDIALOG_MODAL ) ) | |
1158 | { | |
1159 | wclass = kMovableModalWindowClass ; | |
1160 | } | |
1161 | else | |
1162 | { | |
1163 | wclass = kDocumentWindowClass ; | |
1164 | } | |
1165 | } | |
1166 | else | |
1167 | { | |
1168 | wclass = kModalWindowClass ; | |
1169 | } | |
1170 | ||
1171 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) | |
1172 | { | |
1173 | attr |= kWindowFullZoomAttribute ; | |
1174 | attr |= kWindowCollapseBoxAttribute ; | |
1175 | } | |
1176 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
1177 | { | |
1178 | attr |= kWindowResizableAttribute ; | |
1179 | } | |
1180 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
1181 | { | |
1182 | attr |= kWindowCloseBoxAttribute ; | |
1183 | } | |
1184 | ||
1185 | ::CreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; | |
1186 | wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; | |
1187 | wxString label ; | |
1188 | if( wxApp::s_macDefaultEncodingIsPC ) | |
1189 | label = wxMacMakeMacStringFromPC( title ) ; | |
1190 | else | |
1191 | label = title ; | |
1192 | UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; | |
1193 | ::CreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; | |
1194 | ||
1195 | m_macWindowData->m_macFocus = NULL ; | |
1196 | m_macWindowData->m_macHasReceivedFirstActivate = true ; | |
2f1ae414 SC |
1197 | } |
1198 | ||
e766c8a9 | 1199 | void wxWindowMac::MacPaint( wxPaintEvent &event ) |
2f1ae414 SC |
1200 | { |
1201 | } | |
1202 | ||
e766c8a9 | 1203 | void wxWindowMac::MacPaintBorders( ) |
2f1ae414 | 1204 | { |
6264b550 RR |
1205 | if( m_macWindowData ) |
1206 | return ; | |
1207 | ||
1208 | RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; | |
1209 | RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; | |
1210 | RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; | |
1211 | RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; | |
1212 | PenNormal() ; | |
2f1ae414 SC |
1213 | |
1214 | if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) | |
1215 | { | |
6264b550 | 1216 | bool sunken = HasFlag( wxSUNKEN_BORDER ) ; |
653b2449 SC |
1217 | RGBForeColor( &face ); |
1218 | MoveTo( 0 , m_height - 2 ); | |
1219 | LineTo( 0 , 0 ); | |
1220 | LineTo( m_width - 2 , 0 ); | |
1221 | ||
1222 | MoveTo( 2 , m_height - 3 ); | |
1223 | LineTo( m_width - 3 , m_height - 3 ); | |
1224 | LineTo( m_width - 3 , 2 ); | |
1225 | ||
1226 | RGBForeColor( sunken ? &face : &black ); | |
1227 | MoveTo( 0 , m_height - 1 ); | |
1228 | LineTo( m_width - 1 , m_height - 1 ); | |
1229 | LineTo( m_width - 1 , 0 ); | |
1230 | ||
1231 | RGBForeColor( sunken ? &shadow : &white ); | |
1232 | MoveTo( 1 , m_height - 3 ); | |
1233 | LineTo( 1, 1 ); | |
1234 | LineTo( m_width - 3 , 1 ); | |
1235 | ||
1236 | RGBForeColor( sunken ? &white : &shadow ); | |
1237 | MoveTo( 1 , m_height - 2 ); | |
1238 | LineTo( m_width - 2 , m_height - 2 ); | |
1239 | LineTo( m_width - 2 , 1 ); | |
1240 | ||
1241 | RGBForeColor( sunken ? &black : &face ); | |
1242 | MoveTo( 2 , m_height - 4 ); | |
1243 | LineTo( 2 , 2 ); | |
1244 | LineTo( m_width - 4 , 2 ); | |
8208e181 SC |
1245 | } |
1246 | else if (HasFlag(wxSIMPLE_BORDER)) | |
1247 | { | |
6264b550 RR |
1248 | Rect rect = { 0 , 0 , m_height , m_width } ; |
1249 | RGBForeColor( &black ) ; | |
1250 | FrameRect( &rect ) ; | |
2f1ae414 | 1251 | } |
8208e181 SC |
1252 | } |
1253 | ||
e9576ca5 | 1254 | // New function that will replace some of the above. |
e766c8a9 | 1255 | void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, |
e9576ca5 SC |
1256 | int range, bool refresh) |
1257 | { | |
6264b550 RR |
1258 | if ( orient == wxHORIZONTAL ) |
1259 | { | |
1260 | if ( m_hScrollBar ) | |
1261 | { | |
1262 | if ( range == 0 || thumbVisible >= range ) | |
1263 | { | |
1264 | if ( m_hScrollBar->IsShown() ) | |
1265 | m_hScrollBar->Show(false) ; | |
1266 | } | |
1267 | else | |
1268 | { | |
1269 | if ( !m_hScrollBar->IsShown() ) | |
1270 | m_hScrollBar->Show(true) ; | |
1271 | m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1272 | } | |
1273 | } | |
1274 | } | |
1275 | else | |
1276 | { | |
1277 | if ( m_vScrollBar ) | |
1278 | { | |
1279 | if ( range == 0 || thumbVisible >= range ) | |
1280 | { | |
1281 | if ( m_vScrollBar->IsShown() ) | |
1282 | m_vScrollBar->Show(false) ; | |
1283 | } | |
1284 | else | |
1285 | { | |
1286 | if ( !m_vScrollBar->IsShown() ) | |
1287 | m_vScrollBar->Show(true) ; | |
1288 | m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; | |
1289 | } | |
1290 | } | |
1291 | } | |
1292 | MacRepositionScrollBars() ; | |
e9576ca5 SC |
1293 | } |
1294 | ||
1295 | // Does a physical scroll | |
e766c8a9 | 1296 | void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) |
e9576ca5 | 1297 | { |
6264b550 RR |
1298 | wxMacDrawingClientHelper focus( this ) ; |
1299 | if ( focus.Ok() ) | |
1300 | { | |
1301 | int width , height ; | |
1302 | GetClientSize( &width , &height ) ; | |
1303 | ||
1304 | Rect scrollrect = { 0 , 0 , height , width } ; | |
1305 | ||
1306 | RgnHandle updateRgn = NewRgn() ; | |
1307 | ClipRect( &scrollrect ) ; | |
1308 | if ( rect ) | |
1309 | { | |
1310 | Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; | |
1311 | SectRect( &scrollrect , &r , &scrollrect ) ; | |
1312 | } | |
1313 | ScrollRect( &scrollrect , dx , dy , updateRgn ) ; | |
1314 | InvalWindowRgn( GetMacRootWindow() , updateRgn ) ; | |
1315 | DisposeRgn( updateRgn ) ; | |
1316 | } | |
1317 | ||
1318 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1319 | { | |
1320 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1321 | if (child == m_vScrollBar) continue; | |
1322 | if (child == m_hScrollBar) continue; | |
1323 | if (child->IsTopLevel()) continue; | |
1324 | int x,y; | |
1325 | child->GetPosition( &x, &y ); | |
1326 | int w,h; | |
1327 | child->GetSize( &w, &h ); | |
1328 | child->SetSize( x+dx, y+dy, w, h ); | |
1329 | } | |
1330 | ||
e9576ca5 SC |
1331 | } |
1332 | ||
e766c8a9 | 1333 | void wxWindowMac::MacOnScroll(wxScrollEvent &event ) |
7c74e7fe | 1334 | { |
6264b550 RR |
1335 | if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar ) |
1336 | { | |
1337 | wxScrollWinEvent wevent; | |
1338 | wevent.SetPosition(event.GetPosition()); | |
1339 | wevent.SetOrientation(event.GetOrientation()); | |
1340 | wevent.m_eventObject = this; | |
1341 | ||
1342 | if (event.m_eventType == wxEVT_SCROLL_TOP) { | |
1343 | wevent.m_eventType = wxEVT_SCROLLWIN_TOP; | |
1344 | } else | |
1345 | if (event.m_eventType == wxEVT_SCROLL_BOTTOM) { | |
1346 | wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1347 | } else | |
1348 | if (event.m_eventType == wxEVT_SCROLL_LINEUP) { | |
1349 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1350 | } else | |
1351 | if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) { | |
1352 | wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1353 | } else | |
1354 | if (event.m_eventType == wxEVT_SCROLL_PAGEUP) { | |
1355 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1356 | } else | |
1357 | if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) { | |
1358 | wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1359 | } else | |
1360 | if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) { | |
1361 | wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1362 | } | |
1363 | ||
1364 | GetEventHandler()->ProcessEvent(wevent); | |
7c74e7fe SC |
1365 | } |
1366 | } | |
1367 | ||
e766c8a9 | 1368 | bool wxWindowMac::SetFont(const wxFont& font) |
e9576ca5 | 1369 | { |
e7549107 SC |
1370 | if ( !wxWindowBase::SetFont(font) ) |
1371 | { | |
1372 | // nothing to do | |
1373 | return FALSE; | |
e9576ca5 | 1374 | } |
e9576ca5 | 1375 | |
e7549107 | 1376 | return TRUE; |
e9576ca5 SC |
1377 | } |
1378 | ||
1379 | // Get the window with the focus | |
e766c8a9 | 1380 | wxWindowMac *wxWindowBase::FindFocus() |
e9576ca5 | 1381 | { |
6264b550 | 1382 | return gFocusWindow ; |
519cb848 SC |
1383 | } |
1384 | ||
e7549107 | 1385 | #if WXWIN_COMPATIBILITY |
e9576ca5 SC |
1386 | // If nothing defined for this, try the parent. |
1387 | // E.g. we may be a button loaded from a resource, with no callback function | |
1388 | // defined. | |
e766c8a9 | 1389 | void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event) |
e9576ca5 | 1390 | { |
e7549107 SC |
1391 | if ( GetEventHandler()->ProcessEvent(event) ) |
1392 | return; | |
1393 | if ( m_parent ) | |
1394 | m_parent->GetEventHandler()->OnCommand(win, event); | |
e9576ca5 | 1395 | } |
e7549107 | 1396 | #endif // WXWIN_COMPATIBILITY_2 |
e9576ca5 | 1397 | |
e7549107 | 1398 | #if WXWIN_COMPATIBILITY |
e766c8a9 | 1399 | wxObject* wxWindowMac::GetChild(int number) const |
e9576ca5 | 1400 | { |
e7549107 SC |
1401 | // Return a pointer to the Nth object in the Panel |
1402 | wxNode *node = GetChildren().First(); | |
1403 | int n = number; | |
1404 | while (node && n--) | |
1405 | node = node->Next(); | |
1406 | if ( node ) | |
519cb848 | 1407 | { |
e7549107 SC |
1408 | wxObject *obj = (wxObject *)node->Data(); |
1409 | return(obj); | |
519cb848 SC |
1410 | } |
1411 | else | |
e7549107 | 1412 | return NULL; |
e9576ca5 | 1413 | } |
e7549107 | 1414 | #endif // WXWIN_COMPATIBILITY |
e9576ca5 | 1415 | |
e766c8a9 | 1416 | void wxWindowMac::OnSetFocus(wxFocusEvent& event) |
7810c95b SC |
1417 | { |
1418 | // panel wants to track the window which was the last to have focus in it, | |
1419 | // so we want to set ourselves as the window which last had focus | |
1420 | // | |
1421 | // notice that it's also important to do it upwards the tree becaus | |
1422 | // otherwise when the top level panel gets focus, it won't set it back to | |
1423 | // us, but to some other sibling | |
c1fb8167 SC |
1424 | |
1425 | // CS:don't know if this is still needed: | |
1426 | //wxChildFocusEvent eventFocus(this); | |
1427 | //(void)GetEventHandler()->ProcessEvent(eventFocus); | |
7810c95b SC |
1428 | |
1429 | event.Skip(); | |
1430 | } | |
1431 | ||
e766c8a9 | 1432 | void wxWindowMac::Clear() |
e9576ca5 | 1433 | { |
6264b550 RR |
1434 | if ( m_macWindowData ) |
1435 | { | |
1436 | wxMacDrawingClientHelper helper ( this ) ; | |
1437 | int w ,h ; | |
1438 | wxPoint origin = GetClientAreaOrigin() ; | |
1439 | GetClientSize( &w , &h ) ; | |
1440 | ::SetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
1441 | Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ; | |
1442 | EraseRect( &r ) ; | |
1443 | } | |
1444 | else | |
1445 | { | |
1446 | wxClientDC dc(this); | |
1447 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1448 | dc.SetBackground(brush); | |
1449 | dc.Clear(); | |
1450 | } | |
e9576ca5 SC |
1451 | } |
1452 | ||
e7549107 | 1453 | // Setup background and foreground colours correctly |
e766c8a9 | 1454 | void wxWindowMac::SetupColours() |
e9576ca5 | 1455 | { |
e7549107 SC |
1456 | if ( GetParent() ) |
1457 | SetBackgroundColour(GetParent()->GetBackgroundColour()); | |
e9576ca5 SC |
1458 | } |
1459 | ||
e766c8a9 | 1460 | void wxWindowMac::OnIdle(wxIdleEvent& event) |
e9576ca5 | 1461 | { |
519cb848 SC |
1462 | /* |
1463 | // Check if we need to send a LEAVE event | |
1464 | if (m_mouseInWindow) | |
1465 | { | |
1466 | POINT pt; | |
1467 | ::GetCursorPos(&pt); | |
1468 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
1469 | { | |
1470 | // Generate a LEAVE event | |
1471 | m_mouseInWindow = FALSE; | |
1472 | MSWOnMouseLeave(pt.x, pt.y, 0); | |
1473 | } | |
e9576ca5 SC |
1474 | } |
1475 | */ | |
1476 | ||
1477 | // This calls the UI-update mechanism (querying windows for | |
1478 | // menu/toolbar/control state information) | |
6264b550 | 1479 | UpdateWindowUI(); |
e9576ca5 SC |
1480 | } |
1481 | ||
1482 | // Raise the window to the top of the Z order | |
e766c8a9 | 1483 | void wxWindowMac::Raise() |
e9576ca5 | 1484 | { |
f32e5dc5 SC |
1485 | if ( m_macWindowData ) |
1486 | { | |
72055702 | 1487 | ::BringToFront( m_macWindowData->m_macWindow ) ; |
f32e5dc5 | 1488 | } |
e9576ca5 SC |
1489 | } |
1490 | ||
1491 | // Lower the window to the bottom of the Z order | |
e766c8a9 | 1492 | void wxWindowMac::Lower() |
e9576ca5 | 1493 | { |
f32e5dc5 SC |
1494 | if ( m_macWindowData ) |
1495 | { | |
72055702 | 1496 | ::SendBehind( m_macWindowData->m_macWindow , NULL ) ; |
f32e5dc5 | 1497 | } |
e9576ca5 SC |
1498 | } |
1499 | ||
e766c8a9 | 1500 | void wxWindowMac::DoSetClientSize(int width, int height) |
519cb848 | 1501 | { |
6264b550 RR |
1502 | if ( width != -1 || height != -1 ) |
1503 | { | |
1504 | ||
1505 | if ( width != -1 && m_vScrollBar ) | |
1506 | width += MAC_SCROLLBAR_SIZE ; | |
1507 | if ( height != -1 && m_vScrollBar ) | |
1508 | height += MAC_SCROLLBAR_SIZE ; | |
519cb848 | 1509 | |
6264b550 RR |
1510 | width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; |
1511 | height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; | |
2f1ae414 | 1512 | |
6264b550 RR |
1513 | DoSetSize( -1 , -1 , width , height ) ; |
1514 | } | |
519cb848 SC |
1515 | } |
1516 | ||
519cb848 | 1517 | |
e766c8a9 | 1518 | wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; |
519cb848 | 1519 | |
e766c8a9 | 1520 | bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) |
519cb848 | 1521 | { |
6264b550 RR |
1522 | if ((point.x < m_x) || (point.y < m_y) || |
1523 | (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) | |
1524 | return FALSE; | |
1525 | ||
1526 | WindowRef window = GetMacRootWindow() ; | |
519cb848 | 1527 | |
6264b550 | 1528 | wxPoint newPoint( point ) ; |
519cb848 | 1529 | |
6264b550 RR |
1530 | newPoint.x -= m_x; |
1531 | newPoint.y -= m_y; | |
1532 | ||
1533 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1534 | { | |
1535 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1536 | // added the m_isShown test --dmazzoni | |
1537 | if ( child->GetMacRootWindow() == window && child->m_isShown ) | |
1538 | { | |
1539 | if (child->MacGetWindowFromPointSub(newPoint , outWin )) | |
1540 | return TRUE; | |
1541 | } | |
1542 | } | |
519cb848 | 1543 | |
6264b550 RR |
1544 | *outWin = this ; |
1545 | return TRUE; | |
519cb848 SC |
1546 | } |
1547 | ||
e766c8a9 | 1548 | bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) |
519cb848 | 1549 | { |
6264b550 RR |
1550 | WindowRef window ; |
1551 | Point pt = { screenpoint.y , screenpoint.x } ; | |
1552 | if ( ::FindWindow( pt , &window ) == 3 ) | |
1553 | { | |
1554 | wxPoint point( screenpoint ) ; | |
1555 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1556 | if ( win ) | |
1557 | { | |
1558 | win->ScreenToClient( point ) ; | |
1559 | return win->MacGetWindowFromPointSub( point , outWin ) ; | |
1560 | } | |
1561 | } | |
1562 | return FALSE ; | |
519cb848 SC |
1563 | } |
1564 | ||
1565 | extern int wxBusyCursorCount ; | |
1566 | ||
e766c8a9 | 1567 | bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) |
519cb848 | 1568 | { |
6264b550 RR |
1569 | if ((event.m_x < m_x) || (event.m_y < m_y) || |
1570 | (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) | |
1571 | return FALSE; | |
1572 | ||
1573 | ||
1574 | if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) ) | |
1575 | return FALSE ; | |
1576 | ||
1577 | WindowRef window = GetMacRootWindow() ; | |
1578 | ||
1579 | event.m_x -= m_x; | |
1580 | event.m_y -= m_y; | |
1581 | ||
1582 | int x = event.m_x ; | |
1583 | int y = event.m_y ; | |
1584 | ||
1585 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1586 | { | |
1587 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1588 | if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() ) | |
1589 | { | |
1590 | if (child->MacDispatchMouseEvent(event)) | |
1591 | return TRUE; | |
1592 | } | |
7810c95b | 1593 | } |
2f1ae414 | 1594 | |
6264b550 RR |
1595 | event.m_x = x ; |
1596 | event.m_y = y ; | |
1597 | ||
1598 | if ( wxBusyCursorCount == 0 ) | |
1599 | { | |
1600 | m_cursor.MacInstall() ; | |
1601 | } | |
1602 | ||
1603 | if ( event.GetEventType() == wxEVT_LEFT_DOWN ) | |
1604 | { | |
1605 | // set focus to this window | |
1606 | if (AcceptsFocus() && FindFocus()!=this) | |
1607 | SetFocus(); | |
1608 | } | |
1609 | ||
2f1ae414 SC |
1610 | #if wxUSE_TOOLTIPS |
1611 | if ( event.GetEventType() == wxEVT_MOTION | |
6264b550 RR |
1612 | || event.GetEventType() == wxEVT_ENTER_WINDOW |
1613 | || event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
2f1ae414 SC |
1614 | wxToolTip::RelayEvent( this , event); |
1615 | #endif // wxUSE_TOOLTIPS | |
6264b550 RR |
1616 | GetEventHandler()->ProcessEvent( event ) ; |
1617 | return TRUE; | |
519cb848 SC |
1618 | } |
1619 | ||
2f1ae414 SC |
1620 | Point lastWhere ; |
1621 | long lastWhen = 0 ; | |
1622 | ||
e766c8a9 | 1623 | wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) |
2f1ae414 | 1624 | { |
6264b550 RR |
1625 | if ( m_tooltip ) |
1626 | { | |
1627 | return m_tooltip->GetTip() ; | |
1628 | } | |
1629 | return "" ; | |
2f1ae414 | 1630 | } |
e766c8a9 | 1631 | void wxWindowMac::MacFireMouseEvent( EventRecord *ev ) |
519cb848 | 1632 | { |
6264b550 RR |
1633 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
1634 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
1635 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
1636 | ||
1637 | event.m_leftDown = isDown && !controlDown; | |
1638 | ||
1639 | event.m_middleDown = FALSE; | |
1640 | event.m_rightDown = isDown && controlDown; | |
1641 | ||
1642 | if ( ev->what == mouseDown ) | |
1643 | { | |
1644 | if ( controlDown ) | |
1645 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
1646 | else | |
1647 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
1648 | } | |
1649 | else if ( ev->what == mouseUp ) | |
1650 | { | |
1651 | if ( controlDown ) | |
1652 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
1653 | else | |
1654 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
1655 | } | |
1656 | else | |
1657 | { | |
1658 | event.SetEventType(wxEVT_MOTION ) ; | |
1659 | } | |
1660 | ||
1661 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1662 | event.m_controlDown = ev->modifiers & controlKey; | |
1663 | event.m_altDown = ev->modifiers & optionKey; | |
1664 | event.m_metaDown = ev->modifiers & cmdKey; | |
1665 | ||
1666 | Point localwhere = ev->where ; | |
1667 | ||
1668 | GrafPtr port ; | |
1669 | ::GetPort( &port ) ; | |
1670 | ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ; | |
1671 | ::GlobalToLocal( &localwhere ) ; | |
1672 | ::SetPort( port ) ; | |
1673 | ||
1674 | if ( ev->what == mouseDown ) | |
1675 | { | |
1676 | if ( ev->when - lastWhen <= GetDblTime() ) | |
1677 | { | |
1678 | if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 ) | |
1679 | { | |
1680 | if ( controlDown ) | |
1681 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
1682 | else | |
1683 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
1684 | } | |
1685 | lastWhen = 0 ; | |
1686 | } | |
1687 | else | |
1688 | { | |
1689 | lastWhen = ev->when ; | |
1690 | } | |
1691 | lastWhere = localwhere ; | |
1692 | } | |
1693 | ||
1694 | event.m_x = localwhere.h; | |
1695 | event.m_y = localwhere.v; | |
1696 | event.m_x += m_x; | |
1697 | event.m_y += m_y; | |
519cb848 SC |
1698 | |
1699 | /* | |
6264b550 | 1700 | wxPoint origin = GetClientAreaOrigin() ; |
519cb848 | 1701 | |
6264b550 RR |
1702 | event.m_x += origin.x ; |
1703 | event.m_y += origin.y ; | |
519cb848 | 1704 | */ |
6264b550 RR |
1705 | |
1706 | event.m_timeStamp = ev->when; | |
1707 | event.SetEventObject(this); | |
1708 | if ( wxTheApp->s_captureWindow ) | |
1709 | { | |
1710 | int x = event.m_x ; | |
1711 | int y = event.m_y ; | |
1712 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
1713 | event.m_x = x ; | |
1714 | event.m_y = y ; | |
1715 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; | |
1716 | if ( ev->what == mouseUp ) | |
1717 | { | |
1718 | wxTheApp->s_captureWindow = NULL ; | |
1719 | if ( wxBusyCursorCount == 0 ) | |
1720 | { | |
1721 | m_cursor.MacInstall() ; | |
1722 | } | |
1723 | } | |
1724 | } | |
1725 | else | |
1726 | { | |
1727 | MacDispatchMouseEvent( event ) ; | |
1728 | } | |
519cb848 SC |
1729 | } |
1730 | ||
e766c8a9 | 1731 | void wxWindowMac::MacMouseDown( EventRecord *ev , short part) |
519cb848 | 1732 | { |
6264b550 | 1733 | MacFireMouseEvent( ev ) ; |
519cb848 SC |
1734 | } |
1735 | ||
e766c8a9 | 1736 | void wxWindowMac::MacMouseUp( EventRecord *ev , short part) |
519cb848 | 1737 | { |
6264b550 RR |
1738 | switch (part) |
1739 | { | |
1740 | case inContent: | |
1741 | { | |
1742 | MacFireMouseEvent( ev ) ; | |
1743 | } | |
1744 | break ; | |
1745 | } | |
519cb848 SC |
1746 | } |
1747 | ||
e766c8a9 | 1748 | void wxWindowMac::MacMouseMoved( EventRecord *ev , short part) |
519cb848 | 1749 | { |
6264b550 RR |
1750 | switch (part) |
1751 | { | |
1752 | case inContent: | |
1753 | { | |
1754 | MacFireMouseEvent( ev ) ; | |
1755 | } | |
1756 | break ; | |
1757 | } | |
519cb848 | 1758 | } |
e766c8a9 | 1759 | void wxWindowMac::MacActivate( EventRecord *ev , bool inIsActivating ) |
519cb848 | 1760 | { |
fdaf613a SC |
1761 | if ( !m_macWindowData->m_macHasReceivedFirstActivate ) |
1762 | m_macWindowData->m_macHasReceivedFirstActivate = true ; | |
1763 | ||
6264b550 RR |
1764 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); |
1765 | event.m_timeStamp = ev->when ; | |
1766 | event.SetEventObject(this); | |
1767 | ||
1768 | GetEventHandler()->ProcessEvent(event); | |
1769 | ||
e42eaa04 | 1770 | Refresh(false) ; |
6264b550 RR |
1771 | UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ; |
1772 | // MacUpdateImmediately() ; | |
519cb848 SC |
1773 | } |
1774 | ||
e766c8a9 | 1775 | void wxWindowMac::MacRedraw( RgnHandle updatergn , long time) |
519cb848 | 1776 | { |
6264b550 RR |
1777 | // updatergn is always already clipped to our boundaries |
1778 | WindowRef window = GetMacRootWindow() ; | |
1779 | // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children | |
1780 | RgnHandle ownUpdateRgn = NewRgn() ; | |
1781 | CopyRgn( updatergn , ownUpdateRgn ) ; | |
1782 | ||
1783 | { | |
1784 | wxMacDrawingHelper focus( this ) ; // was client | |
1785 | if ( focus.Ok() ) | |
1786 | { | |
1787 | WindowRef window = GetMacRootWindow() ; | |
1788 | bool eraseBackground = false ; | |
1789 | if ( m_macWindowData ) | |
1790 | eraseBackground = true ; | |
1791 | if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) | |
1792 | { | |
1793 | ::SetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; | |
1794 | } | |
1795 | else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
1796 | { | |
1797 | // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether | |
1798 | // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have | |
1799 | // either a non gray background color or a non control window | |
1800 | ||
1801 | ||
1802 | wxWindowMac* parent = GetParent() ; | |
1803 | while( parent ) | |
1804 | { | |
1805 | if ( parent->GetMacRootWindow() != window ) | |
1806 | { | |
1807 | // we are in a different window on the mac system | |
1808 | parent = NULL ; | |
1809 | break ; | |
1810 | } | |
1811 | ||
1812 | if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() ) | |
1813 | { | |
1814 | if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) | |
1815 | { | |
1816 | // if we have any other colours in the hierarchy | |
1817 | RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; | |
1818 | break ; | |
1819 | } | |
1820 | // if we have the normal colours in the hierarchy but another control etc. -> use it's background | |
1821 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
1822 | { | |
1823 | Rect box ; | |
1824 | GetRegionBounds( updatergn , &box) ; | |
1825 | ::ApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true); | |
1826 | break ; | |
1827 | } | |
1828 | } | |
1829 | else | |
1830 | { | |
1831 | parent = NULL ; | |
1832 | break ; | |
1833 | } | |
1834 | parent = parent->GetParent() ; | |
1835 | } | |
1836 | if ( !parent ) | |
1837 | { | |
1838 | // if there is nothing special -> use default | |
1839 | ::SetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ; | |
1840 | } | |
1841 | } | |
1842 | else | |
1843 | { | |
1844 | RGBBackColor( &m_backgroundColour.GetPixel()) ; | |
1845 | } | |
ca715d88 | 1846 | // subtract all non transparent children from updatergn |
fd2e20ff | 1847 | |
6264b550 RR |
1848 | RgnHandle childarea = NewRgn() ; |
1849 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1850 | { | |
1851 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1852 | // eventually test for transparent windows | |
1853 | if ( child->GetMacRootWindow() == window && child->IsShown() ) | |
1854 | { | |
1855 | if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() ) | |
1856 | { | |
1857 | SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1858 | DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ; | |
1859 | } | |
1860 | } | |
1861 | } | |
1862 | DisposeRgn( childarea ) ; | |
1863 | ||
1864 | if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) | |
1865 | eraseBackground = true ; | |
1866 | SetClip( ownUpdateRgn ) ; | |
1867 | if ( m_macEraseOnRedraw ) { | |
1868 | if ( eraseBackground ) | |
1869 | { | |
1870 | EraseRgn( ownUpdateRgn ) ; | |
1871 | } | |
1872 | } | |
1873 | else { | |
1874 | m_macEraseOnRedraw = true ; | |
1875 | } | |
1876 | } | |
1877 | ||
1878 | { | |
1879 | RgnHandle newupdate = NewRgn() ; | |
1880 | wxSize point = GetClientSize() ; | |
1881 | wxPoint origin = GetClientAreaOrigin() ; | |
1882 | ||
1883 | SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; | |
1884 | SectRgn( newupdate , ownUpdateRgn , newupdate ) ; | |
1885 | OffsetRgn( newupdate , -origin.x , -origin.y ) ; | |
1886 | m_updateRegion = newupdate ; | |
1887 | DisposeRgn( newupdate ) ; | |
1888 | } | |
1889 | ||
1890 | MacPaintBorders() ; | |
1891 | wxPaintEvent event; | |
1892 | event.m_timeStamp = time ; | |
1893 | event.SetEventObject(this); | |
1894 | GetEventHandler()->ProcessEvent(event); | |
1895 | } | |
1896 | ||
1897 | ||
1898 | RgnHandle childupdate = NewRgn() ; | |
1899 | ||
1900 | for (wxNode *node = GetChildren().First(); node; node = node->Next()) | |
1901 | { | |
1902 | wxWindowMac *child = (wxWindowMac*)node->Data(); | |
1903 | SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; | |
1904 | SectRgn( childupdate , updatergn , childupdate ) ; | |
1905 | OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; | |
1906 | if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) | |
1907 | { | |
1908 | // because dialogs may also be children | |
1909 | child->MacRedraw( childupdate , time ) ; | |
1910 | } | |
1911 | } | |
1912 | DisposeRgn( childupdate ) ; | |
1913 | // eventually a draw grow box here | |
519cb848 SC |
1914 | } |
1915 | ||
e766c8a9 | 1916 | void wxWindowMac::MacUpdateImmediately() |
519cb848 | 1917 | { |
6264b550 RR |
1918 | WindowRef window = GetMacRootWindow() ; |
1919 | if ( window ) | |
1920 | { | |
1921 | wxWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1922 | #if TARGET_CARBON | |
1923 | AGAPortHelper help( GetWindowPort(window) ) ; | |
1924 | #else | |
1925 | AGAPortHelper help( (window) ) ; | |
1926 | #endif | |
1927 | SetOrigin( 0 , 0 ) ; | |
1928 | BeginUpdate( window ) ; | |
1929 | if ( win ) | |
1930 | { | |
1931 | RgnHandle region = NewRgn(); | |
1932 | ||
1933 | if ( region ) | |
1934 | { | |
1935 | GetPortVisibleRegion( GetWindowPort( window ), region ); | |
1936 | ||
1937 | // if windowshade gives incompatibility , take the follwing out | |
1938 | if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) | |
1939 | { | |
1940 | win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ; | |
1941 | } | |
1942 | DisposeRgn( region ); | |
1943 | } | |
1944 | } | |
1945 | EndUpdate( window ) ; | |
1946 | } | |
519cb848 SC |
1947 | } |
1948 | ||
e766c8a9 | 1949 | void wxWindowMac::MacUpdate( EventRecord *ev ) |
519cb848 | 1950 | { |
6264b550 RR |
1951 | WindowRef window = (WindowRef) ev->message ; |
1952 | wxWindowMac * win = wxFindWinFromMacWindow( window ) ; | |
1953 | #if TARGET_CARBON | |
1954 | AGAPortHelper help( GetWindowPort(window) ) ; | |
1955 | #else | |
1956 | AGAPortHelper help( (window) ) ; | |
1957 | #endif | |
1958 | SetOrigin( 0 , 0 ) ; | |
1959 | BeginUpdate( window ) ; | |
1960 | if ( win ) | |
1961 | { | |
1962 | RgnHandle region = NewRgn(); | |
1963 | ||
1964 | if ( region ) | |
1965 | { | |
2f1ae414 SC |
1966 | GetPortVisibleRegion( GetWindowPort( window ), region ); |
1967 | ||
6264b550 | 1968 | // if windowshade gives incompatibility , take the follwing out |
fdaf613a | 1969 | if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate ) |
2f1ae414 | 1970 | { |
6264b550 | 1971 | MacRedraw( region , ev->when ) ; |
2f1ae414 SC |
1972 | } |
1973 | DisposeRgn( region ); | |
1974 | } | |
6264b550 RR |
1975 | } |
1976 | EndUpdate( window ) ; | |
519cb848 SC |
1977 | } |
1978 | ||
e766c8a9 | 1979 | WindowRef wxWindowMac::GetMacRootWindow() const |
519cb848 | 1980 | { |
6264b550 RR |
1981 | wxWindowMac *iter = (wxWindowMac*)this ; |
1982 | ||
1983 | while( iter ) | |
1984 | { | |
1985 | if ( iter->m_macWindowData ) | |
1986 | return iter->m_macWindowData->m_macWindow ; | |
519cb848 | 1987 | |
6264b550 RR |
1988 | iter = iter->GetParent() ; |
1989 | } | |
1990 | wxASSERT_MSG( 1 , "No valid mac root window" ) ; | |
1991 | return NULL ; | |
519cb848 SC |
1992 | } |
1993 | ||
e766c8a9 | 1994 | void wxWindowMac::MacCreateScrollBars( long style ) |
519cb848 | 1995 | { |
6264b550 RR |
1996 | wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; |
1997 | ||
1998 | bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; | |
1999 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; | |
2000 | int width, height ; | |
2001 | GetClientSize( &width , &height ) ; | |
2002 | ||
2003 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
2004 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2005 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2006 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
2007 | ||
2008 | m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, | |
2009 | vSize , wxVERTICAL); | |
2010 | ||
2011 | if ( style & wxVSCROLL ) | |
2012 | { | |
2013 | ||
2014 | } | |
2015 | else | |
2016 | { | |
2017 | m_vScrollBar->Show(false) ; | |
2018 | } | |
2019 | m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, | |
2020 | hSize , wxHORIZONTAL); | |
2021 | if ( style & wxHSCROLL ) | |
2022 | { | |
2023 | } | |
2024 | else | |
2025 | { | |
2026 | m_hScrollBar->Show(false) ; | |
2027 | } | |
2028 | ||
2029 | // because the create does not take into account the client area origin | |
2030 | MacRepositionScrollBars() ; // we might have a real position shift | |
519cb848 SC |
2031 | } |
2032 | ||
e766c8a9 | 2033 | void wxWindowMac::MacRepositionScrollBars() |
519cb848 | 2034 | { |
6264b550 RR |
2035 | bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; |
2036 | int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; | |
2037 | ||
2038 | // get real client area | |
2039 | ||
2040 | int width = m_width ; | |
2041 | int height = m_height ; | |
2042 | ||
2043 | width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); | |
2044 | height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); | |
2045 | ||
2046 | wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; | |
2047 | wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; | |
2048 | wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; | |
2049 | wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; | |
2050 | ||
2051 | int x = 0 ; | |
2052 | int y = 0 ; | |
2053 | int w = m_width ; | |
2054 | int h = m_height ; | |
2055 | ||
2056 | MacClientToRootWindow( &x , &y ) ; | |
2057 | MacClientToRootWindow( &w , &h ) ; | |
2058 | ||
2059 | wxWindowMac *iter = (wxWindowMac*)this ; | |
2060 | ||
2061 | int totW = 10000 , totH = 10000; | |
2062 | while( iter ) | |
2063 | { | |
2064 | if ( iter->m_macWindowData ) | |
2065 | { | |
2066 | totW = iter->m_width ; | |
2067 | totH = iter->m_height ; | |
2068 | break ; | |
2069 | } | |
2070 | ||
2071 | iter = iter->GetParent() ; | |
2072 | } | |
2073 | ||
2074 | if ( x == 0 ) | |
2075 | { | |
2076 | hPoint.x = -1 ; | |
2077 | hSize.x += 1 ; | |
2078 | } | |
2079 | if ( y == 0 ) | |
2080 | { | |
2081 | vPoint.y = -1 ; | |
2082 | vSize.y += 1 ; | |
2083 | } | |
2084 | ||
2085 | if ( w-x >= totW ) | |
2086 | { | |
2087 | hSize.x += 1 ; | |
2088 | vPoint.x += 1 ; | |
2089 | } | |
2090 | ||
2091 | if ( h-y >= totH ) | |
2092 | { | |
2093 | vSize.y += 1 ; | |
2094 | hPoint.y += 1 ; | |
2095 | } | |
2096 | ||
2097 | if ( m_vScrollBar ) | |
2098 | { | |
2099 | m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); | |
2100 | } | |
2101 | if ( m_hScrollBar ) | |
2102 | { | |
2103 | m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); | |
2104 | } | |
519cb848 SC |
2105 | } |
2106 | ||
e766c8a9 | 2107 | void wxWindowMac::MacKeyDown( EventRecord *ev ) |
519cb848 | 2108 | { |
2f1ae414 | 2109 | |
519cb848 SC |
2110 | } |
2111 | ||
2112 | ||
e766c8a9 | 2113 | bool wxWindowMac::AcceptsFocus() const |
7c551d95 SC |
2114 | { |
2115 | return MacCanFocus() && wxWindowBase::AcceptsFocus(); | |
2116 | } | |
519cb848 | 2117 | |
e766c8a9 | 2118 | ControlHandle wxWindowMac::MacGetContainerForEmbedding() |
519cb848 | 2119 | { |
6264b550 RR |
2120 | if ( m_macWindowData ) |
2121 | return m_macWindowData->m_macRootControl ; | |
2122 | else | |
2123 | return GetParent()->MacGetContainerForEmbedding() ; | |
519cb848 SC |
2124 | } |
2125 | ||
e766c8a9 | 2126 | void wxWindowMac::MacSuperChangedPosition() |
519cb848 | 2127 | { |
6264b550 | 2128 | // only window-absolute structures have to be moved i.e. controls |
519cb848 | 2129 | |
6264b550 RR |
2130 | wxNode *node = GetChildren().First(); |
2131 | while ( node ) | |
2132 | { | |
2133 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
2134 | child->MacSuperChangedPosition() ; | |
2135 | node = node->Next(); | |
2136 | } | |
519cb848 | 2137 | } |
519cb848 | 2138 | |
a3bf4a62 SC |
2139 | void wxWindowMac::MacTopLevelWindowChangedPosition() |
2140 | { | |
6264b550 | 2141 | // only screen-absolute structures have to be moved i.e. glcanvas |
a3bf4a62 | 2142 | |
6264b550 RR |
2143 | wxNode *node = GetChildren().First(); |
2144 | while ( node ) | |
2145 | { | |
2146 | wxWindowMac *child = (wxWindowMac *)node->Data(); | |
2147 | child->MacTopLevelWindowChangedPosition() ; | |
2148 | node = node->Next(); | |
2149 | } | |
a3bf4a62 SC |
2150 | } |
2151 | ||
e766c8a9 | 2152 | bool wxWindowMac::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win ) |
519cb848 | 2153 | { |
6264b550 RR |
2154 | if ( window == NULL ) |
2155 | return false ; | |
2156 | ||
2157 | GrafPtr currPort; | |
2158 | GrafPtr port ; | |
519cb848 | 2159 | |
6264b550 RR |
2160 | ::GetPort(&currPort); |
2161 | port = UMAGetWindowPort( window) ; | |
2162 | if (currPort != port ) | |
2163 | ::SetPort(port); | |
2164 | ||
2165 | // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; | |
2166 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2167 | return true; | |
519cb848 SC |
2168 | } |
2169 | ||
e766c8a9 | 2170 | bool wxWindowMac::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win ) |
519cb848 | 2171 | { |
6264b550 RR |
2172 | if ( window == NULL ) |
2173 | return false ; | |
2174 | ||
2175 | GrafPtr currPort; | |
2176 | GrafPtr port ; | |
2177 | ::GetPort(&currPort); | |
2178 | port = UMAGetWindowPort( window) ; | |
2179 | if (currPort != port ) | |
2180 | ::SetPort(port); | |
2181 | // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; | |
2182 | ::SetOrigin(-localOrigin.h, -localOrigin.v); | |
2183 | ::ClipRect(&clipRect); | |
2184 | ||
2185 | ::PenNormal() ; | |
2186 | ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ; | |
2187 | ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ; | |
2188 | Pattern whiteColor ; | |
2189 | ||
2190 | ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ; | |
2191 | ::SetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; | |
2192 | return true; | |
519cb848 SC |
2193 | } |
2194 | ||
e766c8a9 | 2195 | void wxWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin) |
519cb848 | 2196 | { |
6264b550 RR |
2197 | if ( m_macWindowData ) |
2198 | { | |
2199 | localOrigin->h = 0; | |
2200 | localOrigin->v = 0; | |
2201 | clipRect->left = 0; | |
2202 | clipRect->top = 0; | |
2203 | clipRect->right = m_width; | |
2204 | clipRect->bottom = m_height; | |
2205 | *window = m_macWindowData->m_macWindow ; | |
2206 | *rootwin = this ; | |
2207 | } | |
2208 | else | |
2209 | { | |
2210 | wxASSERT( GetParent() != NULL ) ; | |
2211 | GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ; | |
2212 | localOrigin->h += m_x; | |
2213 | localOrigin->v += m_y; | |
2214 | OffsetRect(clipRect, -m_x, -m_y); | |
2215 | ||
2216 | Rect myClip; | |
2217 | myClip.left = 0; | |
2218 | myClip.top = 0; | |
2219 | myClip.right = m_width; | |
2220 | myClip.bottom = m_height; | |
2221 | SectRect(clipRect, &myClip, clipRect); | |
2222 | } | |
519cb848 SC |
2223 | } |
2224 | ||
e766c8a9 | 2225 | void wxWindowMac::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) |
519cb848 | 2226 | { |
6264b550 RR |
2227 | // int width , height ; |
2228 | // GetClientSize( &width , &height ) ; | |
2229 | ||
2230 | if ( m_macWindowData ) | |
2231 | { | |
2232 | localOrigin->h = 0; | |
2233 | localOrigin->v = 0; | |
2234 | clipRect->left = 0; | |
2235 | clipRect->top = 0; | |
2236 | clipRect->right = m_width ;//width; | |
2237 | clipRect->bottom = m_height ;// height; | |
2238 | *window = m_macWindowData->m_macWindow ; | |
2239 | *rootwin = this ; | |
2240 | } | |
2241 | else | |
2242 | { | |
2243 | wxASSERT( GetParent() != NULL ) ; | |
2244 | ||
2245 | GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ; | |
2246 | ||
2247 | localOrigin->h += m_x; | |
2248 | localOrigin->v += m_y; | |
2249 | OffsetRect(clipRect, -m_x, -m_y); | |
2250 | ||
2251 | Rect myClip; | |
2252 | myClip.left = 0; | |
2253 | myClip.top = 0; | |
2254 | myClip.right = m_width ;//width; | |
2255 | myClip.bottom = m_height ;// height; | |
2256 | SectRect(clipRect, &myClip, clipRect); | |
2257 | } | |
519cb848 SC |
2258 | } |
2259 | ||
e766c8a9 | 2260 | void wxWindowMac::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin ) |
2f1ae414 | 2261 | { |
6264b550 | 2262 | MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ; |
2f1ae414 | 2263 | |
6264b550 RR |
2264 | int width , height ; |
2265 | GetClientSize( &width , &height ) ; | |
2266 | wxPoint client ; | |
2267 | client = GetClientAreaOrigin( ) ; | |
2268 | ||
2269 | localOrigin->h += client.x; | |
2270 | localOrigin->v += client.y; | |
2271 | OffsetRect(clipRect, -client.x, -client.y); | |
2f1ae414 | 2272 | |
6264b550 RR |
2273 | Rect myClip; |
2274 | myClip.left = 0; | |
2275 | myClip.top = 0; | |
2276 | myClip.right = width; | |
2277 | myClip.bottom = height; | |
2278 | SectRect(clipRect, &myClip, clipRect); | |
2f1ae414 SC |
2279 | } |
2280 | ||
e766c8a9 | 2281 | long wxWindowMac::MacGetLeftBorderSize( ) const |
2f1ae414 | 2282 | { |
6264b550 RR |
2283 | if( m_macWindowData ) |
2284 | return 0 ; | |
2f1ae414 SC |
2285 | |
2286 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2287 | { | |
6264b550 | 2288 | return 3 ; |
2f1ae414 SC |
2289 | } |
2290 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2291 | { | |
6264b550 | 2292 | return 3 ; |
2f1ae414 SC |
2293 | } |
2294 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2295 | { | |
6264b550 | 2296 | return 1 ; |
2f1ae414 | 2297 | } |
6264b550 | 2298 | return 0 ; |
2f1ae414 SC |
2299 | } |
2300 | ||
e766c8a9 | 2301 | long wxWindowMac::MacGetRightBorderSize( ) const |
5b781a67 | 2302 | { |
6264b550 RR |
2303 | if( m_macWindowData ) |
2304 | return 0 ; | |
5b781a67 SC |
2305 | |
2306 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2307 | { | |
6264b550 | 2308 | return 3 ; |
5b781a67 SC |
2309 | } |
2310 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2311 | { | |
6264b550 | 2312 | return 3 ; |
5b781a67 SC |
2313 | } |
2314 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2315 | { | |
6264b550 | 2316 | return 1 ; |
5b781a67 | 2317 | } |
6264b550 | 2318 | return 0 ; |
5b781a67 SC |
2319 | } |
2320 | ||
e766c8a9 | 2321 | long wxWindowMac::MacGetTopBorderSize( ) const |
5b781a67 | 2322 | { |
6264b550 RR |
2323 | if( m_macWindowData ) |
2324 | return 0 ; | |
5b781a67 SC |
2325 | |
2326 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2327 | { | |
6264b550 | 2328 | return 3 ; |
5b781a67 SC |
2329 | } |
2330 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2331 | { | |
6264b550 | 2332 | return 3 ; |
5b781a67 SC |
2333 | } |
2334 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2335 | { | |
6264b550 | 2336 | return 1 ; |
5b781a67 | 2337 | } |
6264b550 | 2338 | return 0 ; |
5b781a67 SC |
2339 | } |
2340 | ||
e766c8a9 | 2341 | long wxWindowMac::MacGetBottomBorderSize( ) const |
5b781a67 | 2342 | { |
6264b550 RR |
2343 | if( m_macWindowData ) |
2344 | return 0 ; | |
5b781a67 SC |
2345 | |
2346 | if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) | |
2347 | { | |
6264b550 | 2348 | return 3 ; |
5b781a67 SC |
2349 | } |
2350 | else if ( m_windowStyle &wxDOUBLE_BORDER) | |
2351 | { | |
6264b550 | 2352 | return 3 ; |
5b781a67 SC |
2353 | } |
2354 | else if (m_windowStyle &wxSIMPLE_BORDER) | |
2355 | { | |
6264b550 | 2356 | return 1 ; |
5b781a67 | 2357 | } |
6264b550 | 2358 | return 0 ; |
5b781a67 SC |
2359 | } |
2360 | ||
e766c8a9 | 2361 | long wxWindowMac::MacRemoveBordersFromStyle( long style ) |
2f1ae414 | 2362 | { |
6264b550 | 2363 | return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; |
2f1ae414 | 2364 | } |
0a67a93b | 2365 | |
b89dac78 | 2366 | |
e766c8a9 | 2367 | wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac * theWindow ) |
519cb848 | 2368 | { |
6264b550 RR |
2369 | m_ok = false ; |
2370 | Point localOrigin ; | |
2371 | Rect clipRect ; | |
2372 | WindowRef window ; | |
2373 | wxWindowMac *rootwin ; | |
2374 | m_currentPort = NULL ; | |
2375 | ||
2376 | GetPort( &m_formerPort ) ; | |
2377 | if ( theWindow ) | |
2378 | { | |
2379 | theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2380 | m_currentPort = UMAGetWindowPort( window ) ; | |
2381 | if ( m_formerPort != m_currentPort ) | |
2382 | SetPort( m_currentPort ) ; | |
2383 | GetPenState( &m_savedPenState ) ; | |
2384 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2385 | m_ok = true ; | |
2386 | } | |
2387 | } | |
2388 | ||
519cb848 SC |
2389 | wxMacDrawingHelper::~wxMacDrawingHelper() |
2390 | { | |
6264b550 RR |
2391 | if ( m_ok ) |
2392 | { | |
2393 | SetPort( m_currentPort ) ; | |
2394 | SetPenState( &m_savedPenState ) ; | |
2395 | SetOrigin( 0 , 0 ) ; | |
2396 | Rect portRect ; | |
2397 | GetPortBounds( m_currentPort , &portRect ) ; | |
2398 | ClipRect( &portRect ) ; | |
2399 | } | |
2400 | ||
2401 | if ( m_formerPort != m_currentPort ) | |
2402 | SetPort( m_formerPort ) ; | |
519cb848 | 2403 | } |
519cb848 | 2404 | |
e766c8a9 | 2405 | wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac * theWindow ) |
519cb848 | 2406 | { |
6264b550 RR |
2407 | m_ok = false ; |
2408 | Point localOrigin ; | |
2409 | Rect clipRect ; | |
2410 | WindowRef window ; | |
2411 | wxWindowMac *rootwin ; | |
2412 | m_currentPort = NULL ; | |
2413 | ||
2414 | GetPort( &m_formerPort ) ; | |
2415 | ||
2416 | if ( theWindow ) | |
2417 | { | |
2418 | theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; | |
2419 | m_currentPort = UMAGetWindowPort( window ) ; | |
2420 | if ( m_formerPort != m_currentPort ) | |
2421 | SetPort( m_currentPort ) ; | |
2422 | GetPenState( &m_savedPenState ) ; | |
2423 | theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; | |
2424 | m_ok = true ; | |
2425 | } | |
2426 | } | |
2427 | ||
519cb848 SC |
2428 | wxMacDrawingClientHelper::~wxMacDrawingClientHelper() |
2429 | { | |
6264b550 RR |
2430 | if ( m_ok ) |
2431 | { | |
2432 | SetPort( m_currentPort ) ; | |
2433 | SetPenState( &m_savedPenState ) ; | |
2434 | SetOrigin( 0 , 0 ) ; | |
2435 | Rect portRect ; | |
2436 | GetPortBounds( m_currentPort , &portRect ) ; | |
2437 | ClipRect( &portRect ) ; | |
2438 | } | |
2439 | ||
2440 | if ( m_formerPort != m_currentPort ) | |
2441 | SetPort( m_formerPort ) ; | |
519cb848 | 2442 | } |
3723b7b1 | 2443 | |
e766c8a9 | 2444 | // Find the wxWindowMac at the current mouse position, returning the mouse |
3723b7b1 | 2445 | // position. |
e766c8a9 | 2446 | wxWindowMac* wxFindWindowAtPointer(wxPoint& pt) |
3723b7b1 | 2447 | { |
59a12e90 | 2448 | pt = wxGetMousePosition(); |
e766c8a9 | 2449 | wxWindowMac* found = wxFindWindowAtPoint(pt); |
59a12e90 | 2450 | return found; |
3723b7b1 JS |
2451 | } |
2452 | ||
2453 | // Get the current mouse position. | |
2454 | wxPoint wxGetMousePosition() | |
2455 | { | |
57591e0e JS |
2456 | int x, y; |
2457 | wxGetMousePosition(& x, & y); | |
2458 | return wxPoint(x, y); | |
3723b7b1 JS |
2459 | } |
2460 |