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