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