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