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