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