]>
Commit | Line | Data |
---|---|---|
a15eb0a5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/toplevel.cpp | |
3 | // Purpose: implements wxTopLevelWindow for MSW | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) | |
6aa89a22 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "toplevel.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
38 | #endif //WX_PRECOMP | |
39 | ||
5f0b2f22 | 40 | #include "wx/mac/uma.h" |
422644a3 | 41 | #include "wx/mac/aga.h" |
7c091673 | 42 | #include "wx/app.h" |
5f0b2f22 | 43 | #include "wx/tooltip.h" |
a07c1212 | 44 | #include "wx/dnd.h" |
5f0b2f22 | 45 | |
34dc8f91 SC |
46 | #define wxMAC_DEBUG_REDRAW 0 |
47 | #ifndef wxMAC_DEBUG_REDRAW | |
48 | #define wxMAC_DEBUG_REDRAW 0 | |
49 | #endif | |
50 | ||
a15eb0a5 SC |
51 | // ---------------------------------------------------------------------------- |
52 | // globals | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | // list of all frames and modeless dialogs | |
32b5be3d RR |
56 | wxWindowList wxModelessWindows; |
57 | ||
58 | // double click testing | |
59 | static Point gs_lastWhere; | |
60 | static long gs_lastWhen = 0; | |
61 | ||
a15eb0a5 SC |
62 | // ============================================================================ |
63 | // wxTopLevelWindowMac implementation | |
64 | // ============================================================================ | |
65 | ||
851b3a88 SC |
66 | // --------------------------------------------------------------------------- |
67 | // Carbon Events | |
68 | // --------------------------------------------------------------------------- | |
69 | ||
70 | #if TARGET_CARBON | |
71 | ||
72 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
73 | ||
1542ea39 | 74 | static const EventTypeSpec eventList[] = |
851b3a88 SC |
75 | { |
76 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
c5c9378c | 77 | |
e40298d5 | 78 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
79 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
80 | { kEventClassKeyboard, kEventRawKeyUp } , | |
81 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
82 | ||
851b3a88 SC |
83 | { kEventClassWindow , kEventWindowUpdate } , |
84 | { kEventClassWindow , kEventWindowActivated } , | |
85 | { kEventClassWindow , kEventWindowDeactivated } , | |
86 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
87 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
88 | { kEventClassWindow , kEventWindowClose } , | |
89 | ||
90 | { kEventClassMouse , kEventMouseDown } , | |
91 | { kEventClassMouse , kEventMouseUp } , | |
92 | { kEventClassMouse , kEventMouseMoved } , | |
93 | { kEventClassMouse , kEventMouseDragged } , | |
94 | ||
95 | } ; | |
96 | ||
97 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
98 | { | |
99 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 100 | |
c5c9378c | 101 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 102 | char charCode ; |
1542ea39 | 103 | UInt32 keyCode ; |
c5c9378c | 104 | UInt32 modifiers ; |
e40298d5 JS |
105 | Point point ; |
106 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
c5c9378c SC |
107 | |
108 | EventRef rawEvent ; | |
1542ea39 | 109 | |
c5c9378c | 110 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 111 | |
e40298d5 JS |
112 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
113 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
114 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
115 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
116 | sizeof( Point ), NULL, &point ); | |
117 | ||
118 | UInt32 message = (keyCode << 8) + charCode; | |
119 | ||
120 | switch ( GetEventKind( event ) ) | |
121 | { | |
122 | case kEventTextInputUnicodeForKeyEvent : | |
1542ea39 | 123 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
124 | focus , message , modifiers , when , point.h , point.v ) ) |
125 | { | |
126 | result = noErr ; | |
127 | } | |
128 | break ; | |
129 | } | |
c5c9378c SC |
130 | |
131 | return result ; | |
132 | } | |
133 | ||
134 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
135 | { | |
136 | OSStatus result = eventNotHandledErr ; | |
137 | ||
138 | wxWindow* focus = wxWindow::FindFocus() ; | |
e40298d5 | 139 | char charCode ; |
1542ea39 | 140 | UInt32 keyCode ; |
c5c9378c | 141 | UInt32 modifiers ; |
e40298d5 JS |
142 | Point point ; |
143 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
144 | ||
145 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
146 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
147 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
148 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
149 | sizeof( Point ), NULL, &point ); | |
150 | ||
151 | UInt32 message = (keyCode << 8) + charCode; | |
152 | switch( GetEventKind( event ) ) | |
153 | { | |
154 | case kEventRawKeyRepeat : | |
155 | case kEventRawKeyDown : | |
1542ea39 | 156 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
157 | focus , message , modifiers , when , point.h , point.v ) ) |
158 | { | |
159 | result = noErr ; | |
160 | } | |
161 | break ; | |
162 | case kEventRawKeyUp : | |
1542ea39 | 163 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
164 | focus , message , modifiers , when , point.h , point.v ) ) |
165 | { | |
166 | result = noErr ; | |
167 | } | |
168 | break ; | |
169 | case kEventRawKeyModifiersChanged : | |
170 | { | |
171 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
172 | ||
173 | event.m_shiftDown = modifiers & shiftKey; | |
174 | event.m_controlDown = modifiers & controlKey; | |
175 | event.m_altDown = modifiers & optionKey; | |
176 | event.m_metaDown = modifiers & cmdKey; | |
177 | ||
178 | event.m_x = point.h; | |
179 | event.m_y = point.v; | |
180 | event.m_timeStamp = when; | |
181 | wxWindow* focus = wxWindow::FindFocus() ; | |
182 | event.SetEventObject(focus); | |
183 | ||
8d60dc8a | 184 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
185 | { |
186 | event.m_keyCode = WXK_CONTROL ; | |
187 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
188 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
189 | } | |
8d60dc8a | 190 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
191 | { |
192 | event.m_keyCode = WXK_SHIFT ; | |
193 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
194 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
195 | } | |
8d60dc8a | 196 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
197 | { |
198 | event.m_keyCode = WXK_ALT ; | |
199 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
200 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
201 | } | |
202 | wxTheApp->s_lastModifiers = modifiers ; | |
203 | } | |
204 | break ; | |
205 | } | |
851b3a88 SC |
206 | |
207 | return result ; | |
208 | } | |
209 | ||
210 | static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
211 | { | |
212 | OSStatus result = eventNotHandledErr ; | |
213 | ||
e40298d5 JS |
214 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
215 | Point point ; | |
216 | UInt32 modifiers = 0; | |
217 | EventMouseButton button = 0 ; | |
218 | UInt32 click = 0 ; | |
1542ea39 | 219 | |
e40298d5 JS |
220 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, |
221 | sizeof( Point ), NULL, &point ); | |
222 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, | |
223 | sizeof( UInt32 ), NULL, &modifiers ); | |
224 | GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, | |
225 | sizeof( EventMouseButton ), NULL, &button ); | |
226 | GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, | |
227 | sizeof( UInt32 ), NULL, &click ); | |
1542ea39 | 228 | |
e40298d5 JS |
229 | if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) |
230 | modifiers += btnState ; | |
1542ea39 | 231 | |
e40298d5 | 232 | WindowRef window ; |
851b3a88 | 233 | short windowPart = ::FindWindow(point, &window); |
a3195b73 | 234 | |
e40298d5 | 235 | if ( IsWindowActive(window) && windowPart == inContent ) |
851b3a88 | 236 | { |
e40298d5 JS |
237 | switch ( GetEventKind( event ) ) |
238 | { | |
239 | case kEventMouseDown : | |
240 | toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
241 | result = noErr ; | |
242 | break ; | |
243 | case kEventMouseUp : | |
244 | toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
245 | result = noErr ; | |
246 | break ; | |
247 | case kEventMouseMoved : | |
248 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
249 | result = noErr ; | |
250 | break ; | |
251 | case kEventMouseDragged : | |
252 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
253 | result = noErr ; | |
254 | break ; | |
255 | default : | |
256 | break ; | |
257 | } | |
258 | } | |
1542ea39 | 259 | |
e40298d5 | 260 | return result ; |
1542ea39 | 261 | |
851b3a88 SC |
262 | |
263 | } | |
264 | static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
265 | { | |
266 | OSStatus result = eventNotHandledErr ; | |
267 | OSStatus err = noErr ; | |
268 | ||
e40298d5 JS |
269 | UInt32 attributes; |
270 | WindowRef windowRef ; | |
271 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
1542ea39 | 272 | |
e40298d5 JS |
273 | GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, |
274 | sizeof( WindowRef ), NULL, &windowRef ); | |
1542ea39 | 275 | |
e40298d5 JS |
276 | switch( GetEventKind( event ) ) |
277 | { | |
278 | case kEventWindowUpdate : | |
279 | if ( !wxPendingDelete.Member(toplevelWindow) ) | |
280 | toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; | |
281 | result = noErr ; | |
282 | break ; | |
283 | case kEventWindowActivated : | |
284 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; | |
285 | result = noErr ; | |
286 | break ; | |
287 | case kEventWindowDeactivated : | |
288 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; | |
289 | result = noErr ; | |
290 | break ; | |
291 | case kEventWindowClose : | |
292 | toplevelWindow->Close() ; | |
293 | result = noErr ; | |
294 | break ; | |
295 | case kEventWindowBoundsChanged : | |
296 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
297 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
298 | if ( err == noErr ) | |
299 | { | |
300 | Rect newContentRect ; | |
301 | ||
302 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
303 | sizeof( newContentRect ), NULL, &newContentRect ); | |
1542ea39 RD |
304 | |
305 | toplevelWindow->SetSize( newContentRect.left , newContentRect.top , | |
306 | newContentRect.right - newContentRect.left , | |
851b3a88 SC |
307 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); |
308 | ||
e40298d5 JS |
309 | result = noErr; |
310 | } | |
311 | break ; | |
312 | default : | |
313 | break ; | |
314 | } | |
315 | return result ; | |
851b3a88 SC |
316 | } |
317 | ||
318 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
319 | { | |
320 | OSStatus result = eventNotHandledErr ; | |
321 | ||
322 | switch ( GetEventClass( event ) ) | |
323 | { | |
c5c9378c | 324 | case kEventClassKeyboard : |
e40298d5 | 325 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 326 | break ; |
851b3a88 | 327 | case kEventClassTextInput : |
e40298d5 | 328 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
329 | break ; |
330 | case kEventClassWindow : | |
e40298d5 JS |
331 | result = WindowEventHandler( handler, event , data ) ; |
332 | break ; | |
851b3a88 | 333 | case kEventClassMouse : |
e40298d5 JS |
334 | result = MouseEventHandler( handler, event , data ) ; |
335 | break ; | |
851b3a88 SC |
336 | default : |
337 | break ; | |
338 | } | |
339 | return result ; | |
340 | } | |
341 | ||
342 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
343 | ||
344 | #endif | |
345 | ||
5f0b2f22 SC |
346 | // --------------------------------------------------------------------------- |
347 | // wxWindowMac utility functions | |
348 | // --------------------------------------------------------------------------- | |
349 | ||
350 | // Find an item given the Macintosh Window Reference | |
351 | ||
352 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 353 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 SC |
354 | { |
355 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
356 | if (!node) | |
357 | return NULL; | |
eb22f2a6 | 358 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
359 | } |
360 | ||
76a5e5d2 | 361 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
362 | { |
363 | // adding NULL WindowRef is (first) surely a result of an error and | |
364 | // (secondly) breaks menu command processing | |
427ff662 | 365 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 SC |
366 | |
367 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
368 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
369 | } | |
370 | ||
371 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
372 | { | |
373 | wxWinMacWindowList->DeleteObject(win); | |
374 | } | |
375 | ||
376 | ||
a15eb0a5 SC |
377 | // ---------------------------------------------------------------------------- |
378 | // wxTopLevelWindowMac creation | |
379 | // ---------------------------------------------------------------------------- | |
380 | ||
76a5e5d2 | 381 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
5f0b2f22 | 382 | |
a15eb0a5 SC |
383 | void wxTopLevelWindowMac::Init() |
384 | { | |
385 | m_iconized = | |
386 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
387 | m_macNoEraseUpdateRgn = NewRgn() ; |
388 | m_macNeedsErasing = false ; | |
6a17ca35 | 389 | m_macWindow = NULL ; |
851b3a88 | 390 | #if TARGET_CARBON |
7c091673 | 391 | m_macEventHandler = NULL ; |
851b3a88 | 392 | #endif |
a15eb0a5 SC |
393 | } |
394 | ||
118f012e SC |
395 | class wxMacDeferredWindowDeleter : public wxObject |
396 | { | |
397 | public : | |
1542ea39 RD |
398 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
399 | { | |
400 | m_macWindow = windowRef ; | |
118f012e | 401 | } |
1542ea39 RD |
402 | virtual ~wxMacDeferredWindowDeleter() |
403 | { | |
404 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
405 | } |
406 | protected : | |
407 | WindowRef m_macWindow ; | |
408 | } ; | |
409 | ||
a15eb0a5 SC |
410 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
411 | wxWindowID id, | |
412 | const wxString& title, | |
413 | const wxPoint& pos, | |
414 | const wxSize& size, | |
415 | long style, | |
416 | const wxString& name) | |
417 | { | |
418 | // init our fields | |
419 | Init(); | |
420 | ||
421 | m_windowStyle = style; | |
422 | ||
423 | SetName(name); | |
424 | ||
425 | m_windowId = id == -1 ? NewControlId() : id; | |
426 | ||
427 | wxTopLevelWindows.Append(this); | |
428 | ||
429 | if ( parent ) | |
430 | parent->AddChild(this); | |
431 | ||
432 | return TRUE; | |
433 | } | |
434 | ||
435 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
436 | { | |
6a17ca35 SC |
437 | if ( m_macWindow ) |
438 | { | |
439 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 440 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 441 | } |
1542ea39 | 442 | |
f75363ee | 443 | #if TARGET_CARBON |
7c091673 SC |
444 | if ( m_macEventHandler ) |
445 | { | |
446 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
447 | m_macEventHandler = NULL ; | |
448 | } | |
1542ea39 | 449 | #endif |
851b3a88 | 450 | |
5f0b2f22 SC |
451 | wxRemoveMacWindowAssociation( this ) ; |
452 | ||
a15eb0a5 SC |
453 | if ( wxModelessWindows.Find(this) ) |
454 | wxModelessWindows.DeleteObject(this); | |
455 | ||
76a5e5d2 | 456 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
457 | } |
458 | ||
459 | ||
460 | // ---------------------------------------------------------------------------- | |
461 | // wxTopLevelWindowMac maximize/minimize | |
462 | // ---------------------------------------------------------------------------- | |
463 | ||
464 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
465 | { | |
466 | // not available on mac | |
467 | } | |
468 | ||
469 | bool wxTopLevelWindowMac::IsMaximized() const | |
470 | { | |
1542ea39 | 471 | return false ; |
a15eb0a5 SC |
472 | } |
473 | ||
474 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
475 | { | |
476 | // not available on mac | |
477 | } | |
478 | ||
479 | bool wxTopLevelWindowMac::IsIconized() const | |
480 | { | |
ed60b502 | 481 | // mac dialogs cannot be iconized |
a15eb0a5 SC |
482 | return FALSE; |
483 | } | |
484 | ||
485 | void wxTopLevelWindowMac::Restore() | |
486 | { | |
487 | // not available on mac | |
488 | } | |
489 | ||
490 | // ---------------------------------------------------------------------------- | |
491 | // wxTopLevelWindowMac misc | |
492 | // ---------------------------------------------------------------------------- | |
493 | ||
494 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
495 | { | |
496 | // this sets m_icon | |
497 | wxTopLevelWindowBase::SetIcon(icon); | |
498 | } | |
5f0b2f22 SC |
499 | |
500 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, | |
501 | const wxPoint& pos, | |
502 | const wxSize& size, | |
503 | long style, | |
1542ea39 | 504 | const wxString& name ) |
5f0b2f22 | 505 | { |
e40298d5 JS |
506 | SetName(name); |
507 | m_windowStyle = style; | |
508 | m_isShown = FALSE; | |
1542ea39 | 509 | |
e40298d5 | 510 | // create frame. |
1542ea39 | 511 | |
5f0b2f22 | 512 | Rect theBoundsRect; |
1542ea39 | 513 | |
e40298d5 JS |
514 | m_x = (int)pos.x; |
515 | m_y = (int)pos.y; | |
516 | if ( m_y < 50 ) | |
517 | m_y = 50 ; | |
518 | if ( m_x < 20 ) | |
519 | m_x = 20 ; | |
1542ea39 | 520 | |
e40298d5 | 521 | m_width = size.x; |
1542ea39 | 522 | if (m_width == -1) |
5f0b2f22 | 523 | m_width = 20; |
e40298d5 | 524 | m_height = size.y; |
1542ea39 | 525 | if (m_height == -1) |
5f0b2f22 | 526 | m_height = 20; |
1542ea39 | 527 | |
5f0b2f22 | 528 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); |
1542ea39 | 529 | |
5f0b2f22 | 530 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 531 | |
5f0b2f22 SC |
532 | WindowClass wclass = 0; |
533 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 534 | |
f5744893 | 535 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 536 | { |
1542ea39 | 537 | if ( |
f5744893 SC |
538 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
539 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
540 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 541 | ) |
5f0b2f22 | 542 | { |
f5744893 SC |
543 | wclass = kFloatingWindowClass ; |
544 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
545 | { | |
546 | attr |= kWindowSideTitlebarAttribute ; | |
547 | } | |
548 | } | |
549 | else | |
550 | { | |
2b5f62a0 | 551 | #if TARGET_CARBON |
f5744893 | 552 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
553 | #else |
554 | wclass = kFloatingWindowClass ; | |
555 | #endif | |
5f0b2f22 SC |
556 | } |
557 | } | |
558 | else if ( HasFlag( wxCAPTION ) ) | |
559 | { | |
1542ea39 | 560 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
561 | } |
562 | else | |
563 | { | |
f5744893 | 564 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
e40298d5 | 565 | HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
566 | { |
567 | wclass = kDocumentWindowClass ; | |
568 | } | |
569 | else | |
570 | { | |
2b5f62a0 | 571 | #if TARGET_CARBON |
f5744893 | 572 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
573 | #else |
574 | wclass = kModalWindowClass ; | |
575 | #endif | |
f5744893 | 576 | } |
5f0b2f22 | 577 | } |
1542ea39 | 578 | |
5f0b2f22 SC |
579 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) |
580 | { | |
581 | attr |= kWindowFullZoomAttribute ; | |
582 | attr |= kWindowCollapseBoxAttribute ; | |
583 | } | |
584 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
585 | { | |
586 | attr |= kWindowResizableAttribute ; | |
587 | } | |
588 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
589 | { | |
590 | attr |= kWindowCloseBoxAttribute ; | |
591 | } | |
1542ea39 | 592 | |
76a5e5d2 | 593 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
5f0b2f22 | 594 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
427ff662 | 595 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
76a5e5d2 | 596 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; |
851b3a88 | 597 | #if TARGET_CARBON |
e40298d5 | 598 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
1542ea39 RD |
599 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), |
600 | GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
851b3a88 | 601 | #endif |
5f0b2f22 SC |
602 | m_macFocus = NULL ; |
603 | } | |
604 | ||
1542ea39 | 605 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 606 | { |
76a5e5d2 SC |
607 | ((Point*)localOrigin)->h = 0; |
608 | ((Point*)localOrigin)->v = 0; | |
609 | ((Rect*)clipRect)->left = 0; | |
610 | ((Rect*)clipRect)->top = 0; | |
611 | ((Rect*)clipRect)->right = m_width; | |
612 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
613 | *window = m_macWindow ; |
614 | *rootwin = this ; | |
615 | } | |
616 | ||
617 | void wxTopLevelWindowMac::Clear() | |
618 | { | |
e40298d5 | 619 | wxWindow::Clear() ; |
5f0b2f22 SC |
620 | } |
621 | ||
1542ea39 | 622 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
623 | { |
624 | return m_macRootControl ; | |
625 | } | |
626 | ||
627 | ||
628 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
629 | { | |
66a09d47 | 630 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 SC |
631 | |
632 | BeginUpdate( (WindowRef)m_macWindow ) ; | |
5f0b2f22 | 633 | |
1542ea39 | 634 | RgnHandle updateRgn = NewRgn(); |
5f0b2f22 SC |
635 | RgnHandle diffRgn = NewRgn() ; |
636 | if ( updateRgn && diffRgn ) | |
637 | { | |
732b3a75 SC |
638 | #if 1 |
639 | // macos internal control redraws clean up areas we'd like to redraw ourselves | |
640 | // therefore we pick the boundary rect and make sure we can redraw it | |
641 | RgnHandle trueUpdateRgn = NewRgn() ; | |
642 | Rect trueUpdateRgnBoundary ; | |
643 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); | |
644 | GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; | |
645 | RectRgn( (RgnHandle) updateRgn , &trueUpdateRgnBoundary ) ; | |
646 | if ( trueUpdateRgn ) | |
647 | DisposeRgn( trueUpdateRgn ) ; | |
648 | SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; | |
649 | #else | |
76a5e5d2 | 650 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
732b3a75 | 651 | #endif |
76a5e5d2 | 652 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
653 | if ( !EmptyRgn( updateRgn ) ) |
654 | { | |
655 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
656 | } | |
657 | } | |
658 | if ( updateRgn ) | |
659 | DisposeRgn( updateRgn ); | |
660 | if ( diffRgn ) | |
661 | DisposeRgn( diffRgn ); | |
76a5e5d2 SC |
662 | EndUpdate( (WindowRef)m_macWindow ) ; |
663 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
664 | m_macNeedsErasing = false ; |
665 | } | |
666 | ||
667 | ||
668 | // Raise the window to the top of the Z order | |
669 | void wxTopLevelWindowMac::Raise() | |
670 | { | |
7f3c339c | 671 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
672 | } |
673 | ||
674 | // Lower the window to the bottom of the Z order | |
675 | void wxTopLevelWindowMac::Lower() | |
676 | { | |
76a5e5d2 | 677 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
678 | } |
679 | ||
1542ea39 | 680 | void wxTopLevelWindowMac::MacFireMouseEvent( |
e40298d5 | 681 | wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) |
5f0b2f22 SC |
682 | { |
683 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
851b3a88 SC |
684 | bool isDown = !(modifiers & btnState) ; // 1 is for up |
685 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
1542ea39 | 686 | |
5f0b2f22 | 687 | event.m_leftDown = isDown && !controlDown; |
1542ea39 | 688 | |
5f0b2f22 SC |
689 | event.m_middleDown = FALSE; |
690 | event.m_rightDown = isDown && controlDown; | |
691 | ||
851b3a88 | 692 | if ( kind == mouseDown ) |
5f0b2f22 SC |
693 | { |
694 | if ( controlDown ) | |
695 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
696 | else | |
697 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
698 | } | |
851b3a88 | 699 | else if ( kind == mouseUp ) |
5f0b2f22 SC |
700 | { |
701 | if ( controlDown ) | |
702 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
703 | else | |
704 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
705 | } | |
706 | else | |
707 | { | |
708 | event.SetEventType(wxEVT_MOTION ) ; | |
709 | } | |
710 | ||
851b3a88 SC |
711 | event.m_shiftDown = modifiers & shiftKey; |
712 | event.m_controlDown = modifiers & controlKey; | |
713 | event.m_altDown = modifiers & optionKey; | |
714 | event.m_metaDown = modifiers & cmdKey; | |
5f0b2f22 | 715 | |
851b3a88 SC |
716 | Point localwhere ; |
717 | localwhere.h = x ; | |
718 | localwhere.v = y ; | |
1542ea39 RD |
719 | |
720 | GrafPtr port ; | |
5f0b2f22 | 721 | ::GetPort( &port ) ; |
76a5e5d2 | 722 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
723 | ::GlobalToLocal( &localwhere ) ; |
724 | ::SetPort( port ) ; | |
725 | ||
851b3a88 | 726 | if ( kind == mouseDown ) |
5f0b2f22 | 727 | { |
851b3a88 | 728 | if ( timestamp - gs_lastWhen <= GetDblTime() ) |
5f0b2f22 | 729 | { |
32b5be3d | 730 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 731 | { |
32b5be3d RR |
732 | // This is not right if the second mouse down |
733 | // event occured in a differen window. We | |
734 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
735 | if ( controlDown ) |
736 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
737 | else | |
738 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
739 | } | |
32b5be3d | 740 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
741 | } |
742 | else | |
743 | { | |
851b3a88 | 744 | gs_lastWhen = timestamp ; |
5f0b2f22 | 745 | } |
32b5be3d | 746 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
747 | } |
748 | ||
749 | event.m_x = localwhere.h; | |
750 | event.m_y = localwhere.v; | |
751 | event.m_x += m_x; | |
752 | event.m_y += m_y; | |
753 | ||
851b3a88 | 754 | event.m_timeStamp = timestamp; |
5f0b2f22 SC |
755 | event.SetEventObject(this); |
756 | if ( wxTheApp->s_captureWindow ) | |
757 | { | |
758 | int x = event.m_x ; | |
759 | int y = event.m_y ; | |
760 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
761 | event.m_x = x ; | |
762 | event.m_y = y ; | |
2e6857fa | 763 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 764 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
1542ea39 | 765 | |
851b3a88 | 766 | if ( kind == mouseUp ) |
5f0b2f22 SC |
767 | { |
768 | wxTheApp->s_captureWindow = NULL ; | |
6b57b49a | 769 | if ( !wxIsBusy() ) |
5f0b2f22 SC |
770 | { |
771 | m_cursor.MacInstall() ; | |
772 | } | |
773 | } | |
774 | } | |
775 | else | |
776 | { | |
777 | MacDispatchMouseEvent( event ) ; | |
778 | } | |
779 | } | |
e40298d5 | 780 | |
851b3a88 | 781 | #if !TARGET_CARBON |
5f0b2f22 | 782 | |
76a5e5d2 | 783 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 | 784 | { |
1542ea39 | 785 | MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 786 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
787 | } |
788 | ||
76a5e5d2 | 789 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
790 | { |
791 | switch (part) | |
792 | { | |
1542ea39 | 793 | case inContent: |
5f0b2f22 | 794 | { |
1542ea39 | 795 | MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 796 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
797 | } |
798 | break ; | |
799 | } | |
800 | } | |
801 | ||
76a5e5d2 | 802 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
803 | { |
804 | switch (part) | |
805 | { | |
1542ea39 | 806 | case inContent: |
5f0b2f22 | 807 | { |
1542ea39 | 808 | MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 809 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
810 | } |
811 | break ; | |
812 | } | |
813 | } | |
851b3a88 SC |
814 | |
815 | #endif | |
816 | ||
817 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
5f0b2f22 SC |
818 | { |
819 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
851b3a88 | 820 | event.m_timeStamp = timestamp ; |
5f0b2f22 | 821 | event.SetEventObject(this); |
1542ea39 | 822 | |
5f0b2f22 | 823 | GetEventHandler()->ProcessEvent(event); |
1542ea39 | 824 | |
76a5e5d2 | 825 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
1542ea39 | 826 | |
a006e78b JS |
827 | // Early versions of MacOS X don't refresh backgrounds properly, |
828 | // so refresh the whole window on activation and deactivation. | |
829 | long osVersion = UMAGetSystemVersion(); | |
830 | if (osVersion >= 0x1000 && osVersion < 0x1020) | |
732b3a75 | 831 | { |
a006e78b | 832 | Refresh(TRUE); |
732b3a75 | 833 | } |
a006e78b | 834 | else |
732b3a75 SC |
835 | { |
836 | // for the moment we have to resolve some redrawing issues like this | |
837 | // the OS is stealing some redrawing areas as soon as it draws a control | |
838 | Refresh(TRUE); | |
839 | } | |
5f0b2f22 SC |
840 | } |
841 | ||
851b3a88 SC |
842 | #if !TARGET_CARBON |
843 | ||
1542ea39 | 844 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
845 | { |
846 | } | |
847 | ||
851b3a88 SC |
848 | #endif |
849 | ||
5f0b2f22 SC |
850 | void wxTopLevelWindowMac::SetTitle(const wxString& title) |
851 | { | |
852 | wxWindow::SetTitle( title ) ; | |
427ff662 | 853 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
5f0b2f22 SC |
854 | } |
855 | ||
856 | bool wxTopLevelWindowMac::Show(bool show) | |
857 | { | |
858 | if ( !wxWindow::Show(show) ) | |
859 | return FALSE; | |
860 | ||
861 | if (show) | |
1542ea39 | 862 | { |
2b5f62a0 | 863 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); |
76a5e5d2 | 864 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
865 | // no need to generate events here, they will get them triggered by macos |
866 | // actually they should be , but apparently they are not | |
867 | wxSize size(m_width, m_height); | |
868 | wxSizeEvent event(size, m_windowId); | |
869 | event.SetEventObject(this); | |
870 | GetEventHandler()->ProcessEvent(event); | |
871 | } | |
872 | else | |
873 | { | |
2b5f62a0 | 874 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); |
5f0b2f22 SC |
875 | } |
876 | ||
877 | if ( !show ) | |
878 | { | |
879 | } | |
880 | else | |
881 | { | |
1542ea39 | 882 | Refresh() ; |
5f0b2f22 SC |
883 | } |
884 | ||
885 | return TRUE; | |
886 | } | |
887 | ||
888 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
889 | { | |
890 | int former_x = m_x ; | |
891 | int former_y = m_y ; | |
892 | int former_w = m_width ; | |
893 | int former_h = m_height ; | |
1542ea39 | 894 | |
e40298d5 JS |
895 | int actualWidth = width; |
896 | int actualHeight = height; | |
897 | int actualX = x; | |
898 | int actualY = y; | |
1542ea39 RD |
899 | |
900 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
5f0b2f22 | 901 | actualWidth = m_minWidth; |
1542ea39 | 902 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
5f0b2f22 | 903 | actualHeight = m_minHeight; |
1542ea39 | 904 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
5f0b2f22 | 905 | actualWidth = m_maxWidth; |
1542ea39 | 906 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
5f0b2f22 SC |
907 | actualHeight = m_maxHeight; |
908 | ||
909 | bool doMove = false ; | |
910 | bool doResize = false ; | |
1542ea39 | 911 | |
5f0b2f22 SC |
912 | if ( actualX != former_x || actualY != former_y ) |
913 | { | |
914 | doMove = true ; | |
915 | } | |
916 | if ( actualWidth != former_w || actualHeight != former_h ) | |
917 | { | |
918 | doResize = true ; | |
919 | } | |
920 | ||
921 | if ( doMove || doResize ) | |
922 | { | |
923 | m_x = actualX ; | |
924 | m_y = actualY ; | |
925 | m_width = actualWidth ; | |
926 | m_height = actualHeight ; | |
927 | ||
928 | if ( doMove ) | |
76a5e5d2 | 929 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
1542ea39 | 930 | |
5f0b2f22 | 931 | if ( doResize ) |
1542ea39 RD |
932 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
933 | ||
2b5f62a0 VZ |
934 | // the OS takes care of invalidating and erasing the new area so we only have to |
935 | // take care of refreshing for full repaints | |
936 | ||
937 | if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) | |
938 | Refresh() ; | |
1542ea39 RD |
939 | |
940 | ||
5f0b2f22 SC |
941 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) |
942 | { | |
943 | wxFrame* frame = (wxFrame*) this ; | |
944 | frame->PositionStatusBar(); | |
945 | frame->PositionToolBar(); | |
946 | } | |
947 | if ( doMove ) | |
948 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
949 | ||
950 | MacRepositionScrollBars() ; | |
951 | if ( doMove ) | |
952 | { | |
953 | wxPoint point(m_x, m_y); | |
954 | wxMoveEvent event(point, m_windowId); | |
955 | event.SetEventObject(this); | |
956 | GetEventHandler()->ProcessEvent(event) ; | |
957 | } | |
958 | if ( doResize ) | |
959 | { | |
960 | MacRepositionScrollBars() ; | |
961 | wxSize size(m_width, m_height); | |
962 | wxSizeEvent event(size, m_windowId); | |
963 | event.SetEventObject(this); | |
964 | GetEventHandler()->ProcessEvent(event); | |
965 | } | |
966 | } | |
1542ea39 | 967 | |
5f0b2f22 SC |
968 | } |
969 | ||
970 | /* | |
971 | * Invalidation Mechanism | |
972 | * | |
973 | * The update mechanism reflects exactely the windows mechanism | |
974 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
975 | * has been true for any part of the update rgn the background is erased in the entire region | |
976 | * not just in the specified rect. | |
977 | * | |
1542ea39 | 978 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have |
5f0b2f22 SC |
979 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event |
980 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
981 | * will get the eraseBackground event first | |
982 | */ | |
1542ea39 RD |
983 | |
984 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) | |
5f0b2f22 | 985 | { |
e40298d5 JS |
986 | GrafPtr formerPort ; |
987 | GetPort( &formerPort ) ; | |
988 | SetPortWindowPort( (WindowRef)m_macWindow ) ; | |
1542ea39 | 989 | |
e40298d5 | 990 | m_macNeedsErasing |= eraseBackground ; |
1542ea39 | 991 | |
e40298d5 JS |
992 | // if we already know that we will have to erase, there's no need to track the rest |
993 | if ( !m_macNeedsErasing) | |
5f0b2f22 | 994 | { |
e40298d5 JS |
995 | // we end only here if eraseBackground is false |
996 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
997 | // we will have to erase anyway | |
1542ea39 RD |
998 | |
999 | RgnHandle updateRgn = NewRgn(); | |
e40298d5 JS |
1000 | RgnHandle diffRgn = NewRgn() ; |
1001 | if ( updateRgn && diffRgn ) | |
1002 | { | |
1003 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); | |
1004 | Point pt = {0,0} ; | |
1005 | LocalToGlobal( &pt ) ; | |
1006 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1007 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
1008 | if ( !EmptyRgn( diffRgn ) ) | |
1009 | { | |
1010 | m_macNeedsErasing = true ; | |
1011 | } | |
1012 | } | |
1013 | if ( updateRgn ) | |
1014 | DisposeRgn( updateRgn ); | |
1015 | if ( diffRgn ) | |
1016 | DisposeRgn( diffRgn ); | |
1542ea39 | 1017 | |
e40298d5 | 1018 | if ( !m_macNeedsErasing ) |
5f0b2f22 | 1019 | { |
e40298d5 JS |
1020 | RgnHandle rectRgn = NewRgn() ; |
1021 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; | |
1022 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
1023 | DisposeRgn( rectRgn ) ; | |
5f0b2f22 SC |
1024 | } |
1025 | } | |
e40298d5 JS |
1026 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
1027 | // turn this on to debug the refreshing cycle | |
34dc8f91 | 1028 | #if wxMAC_DEBUG_REDRAW |
e40298d5 | 1029 | PaintRect( rect ) ; |
5f0b2f22 | 1030 | #endif |
e40298d5 | 1031 | SetPort( formerPort ) ; |
5f0b2f22 | 1032 | } |
a07c1212 | 1033 | |
1542ea39 RD |
1034 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1035 | { | |
1036 | return FALSE; | |
1037 | } |