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