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