]>
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 | |
dd49c691 SC |
46 | #include "ToolUtils.h" |
47 | ||
48 | ||
34dc8f91 SC |
49 | #define wxMAC_DEBUG_REDRAW 0 |
50 | #ifndef wxMAC_DEBUG_REDRAW | |
51 | #define wxMAC_DEBUG_REDRAW 0 | |
52 | #endif | |
53 | ||
a15eb0a5 SC |
54 | // ---------------------------------------------------------------------------- |
55 | // globals | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | // list of all frames and modeless dialogs | |
32b5be3d RR |
59 | wxWindowList wxModelessWindows; |
60 | ||
61 | // double click testing | |
62 | static Point gs_lastWhere; | |
63 | static long gs_lastWhen = 0; | |
64 | ||
6a7e6411 | 65 | |
45ff8005 | 66 | #if TARGET_CARBON |
6a7e6411 | 67 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
45ff8005 | 68 | #endif |
6a7e6411 | 69 | |
a15eb0a5 SC |
70 | // ============================================================================ |
71 | // wxTopLevelWindowMac implementation | |
72 | // ============================================================================ | |
73 | ||
851b3a88 SC |
74 | // --------------------------------------------------------------------------- |
75 | // Carbon Events | |
76 | // --------------------------------------------------------------------------- | |
77 | ||
78 | #if TARGET_CARBON | |
79 | ||
80 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
81 | ||
1542ea39 | 82 | static const EventTypeSpec eventList[] = |
851b3a88 SC |
83 | { |
84 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
c5c9378c | 85 | |
e40298d5 | 86 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
87 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
88 | { kEventClassKeyboard, kEventRawKeyUp } , | |
89 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
90 | ||
851b3a88 SC |
91 | { kEventClassWindow , kEventWindowUpdate } , |
92 | { kEventClassWindow , kEventWindowActivated } , | |
93 | { kEventClassWindow , kEventWindowDeactivated } , | |
94 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
95 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
96 | { kEventClassWindow , kEventWindowClose } , | |
97 | ||
98 | { kEventClassMouse , kEventMouseDown } , | |
99 | { kEventClassMouse , kEventMouseUp } , | |
100 | { kEventClassMouse , kEventMouseMoved } , | |
101 | { kEventClassMouse , kEventMouseDragged } , | |
102 | ||
103 | } ; | |
104 | ||
105 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
106 | { | |
107 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 108 | |
c5c9378c | 109 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 110 | char charCode ; |
1542ea39 | 111 | UInt32 keyCode ; |
c5c9378c | 112 | UInt32 modifiers ; |
e40298d5 JS |
113 | Point point ; |
114 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
c5c9378c SC |
115 | |
116 | EventRef rawEvent ; | |
1542ea39 | 117 | |
c5c9378c | 118 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 119 | |
e40298d5 JS |
120 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
121 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
122 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
123 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
124 | sizeof( Point ), NULL, &point ); | |
125 | ||
126 | UInt32 message = (keyCode << 8) + charCode; | |
127 | ||
128 | switch ( GetEventKind( event ) ) | |
129 | { | |
130 | case kEventTextInputUnicodeForKeyEvent : | |
1542ea39 | 131 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
132 | focus , message , modifiers , when , point.h , point.v ) ) |
133 | { | |
134 | result = noErr ; | |
135 | } | |
136 | break ; | |
137 | } | |
c5c9378c SC |
138 | |
139 | return result ; | |
140 | } | |
141 | ||
142 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
143 | { | |
144 | OSStatus result = eventNotHandledErr ; | |
145 | ||
146 | wxWindow* focus = wxWindow::FindFocus() ; | |
e40298d5 | 147 | char charCode ; |
1542ea39 | 148 | UInt32 keyCode ; |
c5c9378c | 149 | UInt32 modifiers ; |
e40298d5 JS |
150 | Point point ; |
151 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
152 | ||
153 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
154 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
155 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
156 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
157 | sizeof( Point ), NULL, &point ); | |
158 | ||
159 | UInt32 message = (keyCode << 8) + charCode; | |
160 | switch( GetEventKind( event ) ) | |
161 | { | |
162 | case kEventRawKeyRepeat : | |
163 | case kEventRawKeyDown : | |
1542ea39 | 164 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
165 | focus , message , modifiers , when , point.h , point.v ) ) |
166 | { | |
167 | result = noErr ; | |
168 | } | |
169 | break ; | |
170 | case kEventRawKeyUp : | |
1542ea39 | 171 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
172 | focus , message , modifiers , when , point.h , point.v ) ) |
173 | { | |
174 | result = noErr ; | |
175 | } | |
176 | break ; | |
177 | case kEventRawKeyModifiersChanged : | |
178 | { | |
179 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
180 | ||
181 | event.m_shiftDown = modifiers & shiftKey; | |
182 | event.m_controlDown = modifiers & controlKey; | |
183 | event.m_altDown = modifiers & optionKey; | |
184 | event.m_metaDown = modifiers & cmdKey; | |
185 | ||
186 | event.m_x = point.h; | |
187 | event.m_y = point.v; | |
188 | event.m_timeStamp = when; | |
189 | wxWindow* focus = wxWindow::FindFocus() ; | |
190 | event.SetEventObject(focus); | |
191 | ||
8d60dc8a | 192 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
193 | { |
194 | event.m_keyCode = WXK_CONTROL ; | |
195 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
196 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
197 | } | |
8d60dc8a | 198 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
199 | { |
200 | event.m_keyCode = WXK_SHIFT ; | |
201 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
202 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
203 | } | |
8d60dc8a | 204 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
205 | { |
206 | event.m_keyCode = WXK_ALT ; | |
207 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
208 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
209 | } | |
210 | wxTheApp->s_lastModifiers = modifiers ; | |
211 | } | |
212 | break ; | |
213 | } | |
851b3a88 SC |
214 | |
215 | return result ; | |
216 | } | |
217 | ||
218 | static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
219 | { | |
220 | OSStatus result = eventNotHandledErr ; | |
221 | ||
e40298d5 JS |
222 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
223 | Point point ; | |
224 | UInt32 modifiers = 0; | |
225 | EventMouseButton button = 0 ; | |
226 | UInt32 click = 0 ; | |
1542ea39 | 227 | |
e40298d5 JS |
228 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, |
229 | sizeof( Point ), NULL, &point ); | |
230 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, | |
231 | sizeof( UInt32 ), NULL, &modifiers ); | |
232 | GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, | |
233 | sizeof( EventMouseButton ), NULL, &button ); | |
234 | GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, | |
235 | sizeof( UInt32 ), NULL, &click ); | |
1542ea39 | 236 | |
e40298d5 JS |
237 | if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) |
238 | modifiers += btnState ; | |
1542ea39 | 239 | |
e40298d5 | 240 | WindowRef window ; |
851b3a88 | 241 | short windowPart = ::FindWindow(point, &window); |
a3195b73 | 242 | |
e40298d5 | 243 | if ( IsWindowActive(window) && windowPart == inContent ) |
851b3a88 | 244 | { |
e40298d5 JS |
245 | switch ( GetEventKind( event ) ) |
246 | { | |
247 | case kEventMouseDown : | |
248 | toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
249 | result = noErr ; | |
250 | break ; | |
251 | case kEventMouseUp : | |
252 | toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
253 | result = noErr ; | |
254 | break ; | |
255 | case kEventMouseMoved : | |
256 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
257 | result = noErr ; | |
258 | break ; | |
259 | case kEventMouseDragged : | |
260 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
261 | result = noErr ; | |
262 | break ; | |
263 | default : | |
264 | break ; | |
265 | } | |
266 | } | |
1542ea39 | 267 | |
e40298d5 | 268 | return result ; |
1542ea39 | 269 | |
851b3a88 SC |
270 | |
271 | } | |
272 | static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
273 | { | |
274 | OSStatus result = eventNotHandledErr ; | |
275 | OSStatus err = noErr ; | |
276 | ||
e40298d5 JS |
277 | UInt32 attributes; |
278 | WindowRef windowRef ; | |
279 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
1542ea39 | 280 | |
e40298d5 JS |
281 | GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, |
282 | sizeof( WindowRef ), NULL, &windowRef ); | |
1542ea39 | 283 | |
e40298d5 JS |
284 | switch( GetEventKind( event ) ) |
285 | { | |
286 | case kEventWindowUpdate : | |
287 | if ( !wxPendingDelete.Member(toplevelWindow) ) | |
288 | toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; | |
289 | result = noErr ; | |
290 | break ; | |
291 | case kEventWindowActivated : | |
292 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; | |
293 | result = noErr ; | |
294 | break ; | |
295 | case kEventWindowDeactivated : | |
296 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; | |
297 | result = noErr ; | |
298 | break ; | |
299 | case kEventWindowClose : | |
300 | toplevelWindow->Close() ; | |
301 | result = noErr ; | |
302 | break ; | |
303 | case kEventWindowBoundsChanged : | |
304 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
305 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
306 | if ( err == noErr ) | |
307 | { | |
308 | Rect newContentRect ; | |
309 | ||
310 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
311 | sizeof( newContentRect ), NULL, &newContentRect ); | |
1542ea39 RD |
312 | |
313 | toplevelWindow->SetSize( newContentRect.left , newContentRect.top , | |
314 | newContentRect.right - newContentRect.left , | |
851b3a88 SC |
315 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); |
316 | ||
e40298d5 JS |
317 | result = noErr; |
318 | } | |
319 | break ; | |
320 | default : | |
321 | break ; | |
322 | } | |
323 | return result ; | |
851b3a88 SC |
324 | } |
325 | ||
326 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
327 | { | |
328 | OSStatus result = eventNotHandledErr ; | |
329 | ||
330 | switch ( GetEventClass( event ) ) | |
331 | { | |
c5c9378c | 332 | case kEventClassKeyboard : |
e40298d5 | 333 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 334 | break ; |
851b3a88 | 335 | case kEventClassTextInput : |
e40298d5 | 336 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
337 | break ; |
338 | case kEventClassWindow : | |
e40298d5 JS |
339 | result = WindowEventHandler( handler, event , data ) ; |
340 | break ; | |
851b3a88 | 341 | case kEventClassMouse : |
e40298d5 JS |
342 | result = MouseEventHandler( handler, event , data ) ; |
343 | break ; | |
851b3a88 SC |
344 | default : |
345 | break ; | |
346 | } | |
347 | return result ; | |
348 | } | |
349 | ||
350 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
351 | ||
352 | #endif | |
353 | ||
5f0b2f22 SC |
354 | // --------------------------------------------------------------------------- |
355 | // wxWindowMac utility functions | |
356 | // --------------------------------------------------------------------------- | |
357 | ||
358 | // Find an item given the Macintosh Window Reference | |
359 | ||
360 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 361 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 SC |
362 | { |
363 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
364 | if (!node) | |
365 | return NULL; | |
eb22f2a6 | 366 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
367 | } |
368 | ||
76a5e5d2 | 369 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
370 | { |
371 | // adding NULL WindowRef is (first) surely a result of an error and | |
372 | // (secondly) breaks menu command processing | |
427ff662 | 373 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 SC |
374 | |
375 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
376 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
377 | } | |
378 | ||
379 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
380 | { | |
381 | wxWinMacWindowList->DeleteObject(win); | |
382 | } | |
383 | ||
384 | ||
a15eb0a5 SC |
385 | // ---------------------------------------------------------------------------- |
386 | // wxTopLevelWindowMac creation | |
387 | // ---------------------------------------------------------------------------- | |
388 | ||
76a5e5d2 | 389 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
5f0b2f22 | 390 | |
a15eb0a5 SC |
391 | void wxTopLevelWindowMac::Init() |
392 | { | |
393 | m_iconized = | |
394 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
395 | m_macNoEraseUpdateRgn = NewRgn() ; |
396 | m_macNeedsErasing = false ; | |
6a17ca35 | 397 | m_macWindow = NULL ; |
851b3a88 | 398 | #if TARGET_CARBON |
7c091673 | 399 | m_macEventHandler = NULL ; |
851b3a88 | 400 | #endif |
a15eb0a5 SC |
401 | } |
402 | ||
118f012e SC |
403 | class wxMacDeferredWindowDeleter : public wxObject |
404 | { | |
405 | public : | |
1542ea39 RD |
406 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
407 | { | |
408 | m_macWindow = windowRef ; | |
118f012e | 409 | } |
1542ea39 RD |
410 | virtual ~wxMacDeferredWindowDeleter() |
411 | { | |
412 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
413 | } |
414 | protected : | |
415 | WindowRef m_macWindow ; | |
416 | } ; | |
417 | ||
a15eb0a5 SC |
418 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
419 | wxWindowID id, | |
420 | const wxString& title, | |
421 | const wxPoint& pos, | |
422 | const wxSize& size, | |
423 | long style, | |
424 | const wxString& name) | |
425 | { | |
426 | // init our fields | |
427 | Init(); | |
428 | ||
429 | m_windowStyle = style; | |
430 | ||
431 | SetName(name); | |
432 | ||
433 | m_windowId = id == -1 ? NewControlId() : id; | |
434 | ||
435 | wxTopLevelWindows.Append(this); | |
436 | ||
437 | if ( parent ) | |
438 | parent->AddChild(this); | |
439 | ||
440 | return TRUE; | |
441 | } | |
442 | ||
443 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
444 | { | |
6a17ca35 SC |
445 | if ( m_macWindow ) |
446 | { | |
447 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 448 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 449 | } |
1542ea39 | 450 | |
f75363ee | 451 | #if TARGET_CARBON |
7c091673 SC |
452 | if ( m_macEventHandler ) |
453 | { | |
454 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
455 | m_macEventHandler = NULL ; | |
456 | } | |
1542ea39 | 457 | #endif |
851b3a88 | 458 | |
5f0b2f22 SC |
459 | wxRemoveMacWindowAssociation( this ) ; |
460 | ||
a15eb0a5 SC |
461 | if ( wxModelessWindows.Find(this) ) |
462 | wxModelessWindows.DeleteObject(this); | |
463 | ||
76a5e5d2 | 464 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
465 | } |
466 | ||
467 | ||
468 | // ---------------------------------------------------------------------------- | |
469 | // wxTopLevelWindowMac maximize/minimize | |
470 | // ---------------------------------------------------------------------------- | |
471 | ||
472 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
473 | { | |
474 | // not available on mac | |
475 | } | |
476 | ||
477 | bool wxTopLevelWindowMac::IsMaximized() const | |
478 | { | |
1542ea39 | 479 | return false ; |
a15eb0a5 SC |
480 | } |
481 | ||
482 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
483 | { | |
484 | // not available on mac | |
485 | } | |
486 | ||
487 | bool wxTopLevelWindowMac::IsIconized() const | |
488 | { | |
ed60b502 | 489 | // mac dialogs cannot be iconized |
a15eb0a5 SC |
490 | return FALSE; |
491 | } | |
492 | ||
493 | void wxTopLevelWindowMac::Restore() | |
494 | { | |
495 | // not available on mac | |
496 | } | |
497 | ||
498 | // ---------------------------------------------------------------------------- | |
499 | // wxTopLevelWindowMac misc | |
500 | // ---------------------------------------------------------------------------- | |
501 | ||
502 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
503 | { | |
504 | // this sets m_icon | |
505 | wxTopLevelWindowBase::SetIcon(icon); | |
506 | } | |
5f0b2f22 SC |
507 | |
508 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, | |
509 | const wxPoint& pos, | |
510 | const wxSize& size, | |
511 | long style, | |
1542ea39 | 512 | const wxString& name ) |
5f0b2f22 | 513 | { |
e40298d5 JS |
514 | SetName(name); |
515 | m_windowStyle = style; | |
516 | m_isShown = FALSE; | |
1542ea39 | 517 | |
e40298d5 | 518 | // create frame. |
1542ea39 | 519 | |
5f0b2f22 | 520 | Rect theBoundsRect; |
1542ea39 | 521 | |
e40298d5 JS |
522 | m_x = (int)pos.x; |
523 | m_y = (int)pos.y; | |
524 | if ( m_y < 50 ) | |
525 | m_y = 50 ; | |
526 | if ( m_x < 20 ) | |
527 | m_x = 20 ; | |
1542ea39 | 528 | |
e40298d5 | 529 | m_width = size.x; |
1542ea39 | 530 | if (m_width == -1) |
5f0b2f22 | 531 | m_width = 20; |
e40298d5 | 532 | m_height = size.y; |
1542ea39 | 533 | if (m_height == -1) |
5f0b2f22 | 534 | m_height = 20; |
1542ea39 | 535 | |
5f0b2f22 | 536 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); |
1542ea39 | 537 | |
5f0b2f22 | 538 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 539 | |
5f0b2f22 SC |
540 | WindowClass wclass = 0; |
541 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 542 | |
f5744893 | 543 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 544 | { |
1542ea39 | 545 | if ( |
f5744893 SC |
546 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
547 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
548 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 549 | ) |
5f0b2f22 | 550 | { |
f5744893 SC |
551 | wclass = kFloatingWindowClass ; |
552 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
553 | { | |
554 | attr |= kWindowSideTitlebarAttribute ; | |
555 | } | |
556 | } | |
557 | else | |
558 | { | |
2b5f62a0 | 559 | #if TARGET_CARBON |
f5744893 | 560 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
561 | #else |
562 | wclass = kFloatingWindowClass ; | |
563 | #endif | |
5f0b2f22 SC |
564 | } |
565 | } | |
566 | else if ( HasFlag( wxCAPTION ) ) | |
567 | { | |
1542ea39 | 568 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
569 | } |
570 | else | |
571 | { | |
f5744893 | 572 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
e40298d5 | 573 | HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
574 | { |
575 | wclass = kDocumentWindowClass ; | |
576 | } | |
577 | else | |
578 | { | |
2b5f62a0 | 579 | #if TARGET_CARBON |
f5744893 | 580 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
581 | #else |
582 | wclass = kModalWindowClass ; | |
583 | #endif | |
f5744893 | 584 | } |
5f0b2f22 | 585 | } |
1542ea39 | 586 | |
5f0b2f22 SC |
587 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) |
588 | { | |
589 | attr |= kWindowFullZoomAttribute ; | |
590 | attr |= kWindowCollapseBoxAttribute ; | |
591 | } | |
592 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
593 | { | |
594 | attr |= kWindowResizableAttribute ; | |
595 | } | |
596 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
597 | { | |
598 | attr |= kWindowCloseBoxAttribute ; | |
599 | } | |
1542ea39 | 600 | |
6a7e6411 RD |
601 | if (HasFlag(wxSTAY_ON_TOP)) |
602 | wclass = kUtilityWindowClass; | |
603 | ||
45ff8005 | 604 | #if TARGET_CARBON |
6a7e6411 RD |
605 | if ( HasFlag(wxFRAME_SHAPED) ) |
606 | { | |
607 | WindowDefSpec customWindowDefSpec; | |
608 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
609 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
610 | ||
611 | ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
612 | attr, &theBoundsRect, | |
613 | (WindowRef*) &m_macWindow); | |
614 | } | |
615 | else | |
45ff8005 | 616 | #endif |
6a7e6411 RD |
617 | { |
618 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
619 | } | |
620 | ||
5f0b2f22 | 621 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
427ff662 | 622 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
76a5e5d2 | 623 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; |
851b3a88 | 624 | #if TARGET_CARBON |
e40298d5 | 625 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
1542ea39 RD |
626 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), |
627 | GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
851b3a88 | 628 | #endif |
5f0b2f22 | 629 | m_macFocus = NULL ; |
6a7e6411 RD |
630 | |
631 | ||
45ff8005 | 632 | #if TARGET_CARBON |
6a7e6411 RD |
633 | if ( HasFlag(wxFRAME_SHAPED) ) |
634 | { | |
635 | // default shape matches the window size | |
636 | wxRegion rgn(0, 0, m_width, m_height); | |
637 | SetShape(rgn); | |
638 | } | |
45ff8005 | 639 | #endif |
5f0b2f22 SC |
640 | } |
641 | ||
1542ea39 | 642 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 643 | { |
76a5e5d2 SC |
644 | ((Point*)localOrigin)->h = 0; |
645 | ((Point*)localOrigin)->v = 0; | |
646 | ((Rect*)clipRect)->left = 0; | |
647 | ((Rect*)clipRect)->top = 0; | |
648 | ((Rect*)clipRect)->right = m_width; | |
649 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
650 | *window = m_macWindow ; |
651 | *rootwin = this ; | |
652 | } | |
653 | ||
654 | void wxTopLevelWindowMac::Clear() | |
655 | { | |
e40298d5 | 656 | wxWindow::Clear() ; |
5f0b2f22 SC |
657 | } |
658 | ||
1542ea39 | 659 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
660 | { |
661 | return m_macRootControl ; | |
662 | } | |
663 | ||
664 | ||
665 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
666 | { | |
66a09d47 | 667 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 | 668 | |
1925be65 SC |
669 | RgnHandle visRgn = NewRgn() ; |
670 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); | |
76a5e5d2 | 671 | BeginUpdate( (WindowRef)m_macWindow ) ; |
5f0b2f22 | 672 | |
1542ea39 | 673 | RgnHandle updateRgn = NewRgn(); |
5f0b2f22 | 674 | RgnHandle diffRgn = NewRgn() ; |
1925be65 | 675 | |
5f0b2f22 SC |
676 | if ( updateRgn && diffRgn ) |
677 | { | |
732b3a75 SC |
678 | #if 1 |
679 | // macos internal control redraws clean up areas we'd like to redraw ourselves | |
680 | // therefore we pick the boundary rect and make sure we can redraw it | |
1925be65 SC |
681 | // this has to be intersected by the visRgn in order to avoid drawing over its own |
682 | // boundaries | |
732b3a75 SC |
683 | RgnHandle trueUpdateRgn = NewRgn() ; |
684 | Rect trueUpdateRgnBoundary ; | |
685 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); | |
686 | GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; | |
1925be65 SC |
687 | RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; |
688 | SectRgn( updateRgn , visRgn , updateRgn ) ; | |
732b3a75 SC |
689 | if ( trueUpdateRgn ) |
690 | DisposeRgn( trueUpdateRgn ) ; | |
691 | SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; | |
692 | #else | |
76a5e5d2 | 693 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
732b3a75 | 694 | #endif |
76a5e5d2 | 695 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
696 | if ( !EmptyRgn( updateRgn ) ) |
697 | { | |
698 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
699 | } | |
700 | } | |
701 | if ( updateRgn ) | |
702 | DisposeRgn( updateRgn ); | |
703 | if ( diffRgn ) | |
704 | DisposeRgn( diffRgn ); | |
1925be65 SC |
705 | if ( visRgn ) |
706 | DisposeRgn( visRgn ) ; | |
707 | ||
76a5e5d2 SC |
708 | EndUpdate( (WindowRef)m_macWindow ) ; |
709 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
710 | m_macNeedsErasing = false ; |
711 | } | |
712 | ||
713 | ||
714 | // Raise the window to the top of the Z order | |
715 | void wxTopLevelWindowMac::Raise() | |
716 | { | |
7f3c339c | 717 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
718 | } |
719 | ||
720 | // Lower the window to the bottom of the Z order | |
721 | void wxTopLevelWindowMac::Lower() | |
722 | { | |
76a5e5d2 | 723 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
724 | } |
725 | ||
1542ea39 | 726 | void wxTopLevelWindowMac::MacFireMouseEvent( |
e40298d5 | 727 | wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) |
5f0b2f22 SC |
728 | { |
729 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
851b3a88 SC |
730 | bool isDown = !(modifiers & btnState) ; // 1 is for up |
731 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
1542ea39 | 732 | |
5f0b2f22 | 733 | event.m_leftDown = isDown && !controlDown; |
1542ea39 | 734 | |
5f0b2f22 SC |
735 | event.m_middleDown = FALSE; |
736 | event.m_rightDown = isDown && controlDown; | |
737 | ||
851b3a88 | 738 | if ( kind == mouseDown ) |
5f0b2f22 SC |
739 | { |
740 | if ( controlDown ) | |
741 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
742 | else | |
743 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
744 | } | |
851b3a88 | 745 | else if ( kind == mouseUp ) |
5f0b2f22 SC |
746 | { |
747 | if ( controlDown ) | |
748 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
749 | else | |
750 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
751 | } | |
752 | else | |
753 | { | |
754 | event.SetEventType(wxEVT_MOTION ) ; | |
755 | } | |
756 | ||
851b3a88 SC |
757 | event.m_shiftDown = modifiers & shiftKey; |
758 | event.m_controlDown = modifiers & controlKey; | |
759 | event.m_altDown = modifiers & optionKey; | |
760 | event.m_metaDown = modifiers & cmdKey; | |
5f0b2f22 | 761 | |
851b3a88 SC |
762 | Point localwhere ; |
763 | localwhere.h = x ; | |
764 | localwhere.v = y ; | |
1542ea39 RD |
765 | |
766 | GrafPtr port ; | |
5f0b2f22 | 767 | ::GetPort( &port ) ; |
76a5e5d2 | 768 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
769 | ::GlobalToLocal( &localwhere ) ; |
770 | ::SetPort( port ) ; | |
771 | ||
851b3a88 | 772 | if ( kind == mouseDown ) |
5f0b2f22 | 773 | { |
851b3a88 | 774 | if ( timestamp - gs_lastWhen <= GetDblTime() ) |
5f0b2f22 | 775 | { |
32b5be3d | 776 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 777 | { |
32b5be3d RR |
778 | // This is not right if the second mouse down |
779 | // event occured in a differen window. We | |
780 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
781 | if ( controlDown ) |
782 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
783 | else | |
784 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
785 | } | |
32b5be3d | 786 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
787 | } |
788 | else | |
789 | { | |
851b3a88 | 790 | gs_lastWhen = timestamp ; |
5f0b2f22 | 791 | } |
32b5be3d | 792 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
793 | } |
794 | ||
795 | event.m_x = localwhere.h; | |
796 | event.m_y = localwhere.v; | |
797 | event.m_x += m_x; | |
798 | event.m_y += m_y; | |
799 | ||
851b3a88 | 800 | event.m_timeStamp = timestamp; |
5f0b2f22 SC |
801 | event.SetEventObject(this); |
802 | if ( wxTheApp->s_captureWindow ) | |
803 | { | |
804 | int x = event.m_x ; | |
805 | int y = event.m_y ; | |
806 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
807 | event.m_x = x ; | |
808 | event.m_y = y ; | |
2e6857fa | 809 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 810 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
1542ea39 | 811 | |
851b3a88 | 812 | if ( kind == mouseUp ) |
5f0b2f22 SC |
813 | { |
814 | wxTheApp->s_captureWindow = NULL ; | |
6b57b49a | 815 | if ( !wxIsBusy() ) |
5f0b2f22 SC |
816 | { |
817 | m_cursor.MacInstall() ; | |
818 | } | |
819 | } | |
820 | } | |
821 | else | |
822 | { | |
823 | MacDispatchMouseEvent( event ) ; | |
824 | } | |
825 | } | |
e40298d5 | 826 | |
851b3a88 | 827 | #if !TARGET_CARBON |
5f0b2f22 | 828 | |
76a5e5d2 | 829 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 | 830 | { |
1542ea39 | 831 | MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 832 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
833 | } |
834 | ||
76a5e5d2 | 835 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
836 | { |
837 | switch (part) | |
838 | { | |
1542ea39 | 839 | case inContent: |
5f0b2f22 | 840 | { |
1542ea39 | 841 | MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 842 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
843 | } |
844 | break ; | |
845 | } | |
846 | } | |
847 | ||
76a5e5d2 | 848 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
849 | { |
850 | switch (part) | |
851 | { | |
1542ea39 | 852 | case inContent: |
5f0b2f22 | 853 | { |
1542ea39 | 854 | MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 855 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
856 | } |
857 | break ; | |
858 | } | |
859 | } | |
851b3a88 SC |
860 | |
861 | #endif | |
862 | ||
863 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
5f0b2f22 SC |
864 | { |
865 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
851b3a88 | 866 | event.m_timeStamp = timestamp ; |
5f0b2f22 | 867 | event.SetEventObject(this); |
1542ea39 | 868 | |
5f0b2f22 | 869 | GetEventHandler()->ProcessEvent(event); |
1542ea39 | 870 | |
76a5e5d2 | 871 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
1542ea39 | 872 | |
a006e78b JS |
873 | // Early versions of MacOS X don't refresh backgrounds properly, |
874 | // so refresh the whole window on activation and deactivation. | |
875 | long osVersion = UMAGetSystemVersion(); | |
1925be65 | 876 | if (osVersion >= 0x1000 && osVersion < 0x1020 ) |
732b3a75 | 877 | { |
a006e78b | 878 | Refresh(TRUE); |
732b3a75 | 879 | } |
a006e78b | 880 | else |
732b3a75 SC |
881 | { |
882 | // for the moment we have to resolve some redrawing issues like this | |
883 | // the OS is stealing some redrawing areas as soon as it draws a control | |
884 | Refresh(TRUE); | |
885 | } | |
5f0b2f22 SC |
886 | } |
887 | ||
851b3a88 SC |
888 | #if !TARGET_CARBON |
889 | ||
1542ea39 | 890 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
891 | { |
892 | } | |
893 | ||
851b3a88 SC |
894 | #endif |
895 | ||
5f0b2f22 SC |
896 | void wxTopLevelWindowMac::SetTitle(const wxString& title) |
897 | { | |
898 | wxWindow::SetTitle( title ) ; | |
427ff662 | 899 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
5f0b2f22 SC |
900 | } |
901 | ||
902 | bool wxTopLevelWindowMac::Show(bool show) | |
903 | { | |
904 | if ( !wxWindow::Show(show) ) | |
905 | return FALSE; | |
906 | ||
907 | if (show) | |
1542ea39 | 908 | { |
1925be65 | 909 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); |
76a5e5d2 | 910 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
911 | // no need to generate events here, they will get them triggered by macos |
912 | // actually they should be , but apparently they are not | |
913 | wxSize size(m_width, m_height); | |
914 | wxSizeEvent event(size, m_windowId); | |
915 | event.SetEventObject(this); | |
916 | GetEventHandler()->ProcessEvent(event); | |
917 | } | |
918 | else | |
919 | { | |
1925be65 | 920 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); |
5f0b2f22 SC |
921 | } |
922 | ||
923 | if ( !show ) | |
924 | { | |
925 | } | |
926 | else | |
927 | { | |
1542ea39 | 928 | Refresh() ; |
5f0b2f22 SC |
929 | } |
930 | ||
931 | return TRUE; | |
932 | } | |
933 | ||
934 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
935 | { | |
936 | int former_x = m_x ; | |
937 | int former_y = m_y ; | |
938 | int former_w = m_width ; | |
939 | int former_h = m_height ; | |
1542ea39 | 940 | |
e40298d5 JS |
941 | int actualWidth = width; |
942 | int actualHeight = height; | |
943 | int actualX = x; | |
944 | int actualY = y; | |
1542ea39 RD |
945 | |
946 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
5f0b2f22 | 947 | actualWidth = m_minWidth; |
1542ea39 | 948 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
5f0b2f22 | 949 | actualHeight = m_minHeight; |
1542ea39 | 950 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
5f0b2f22 | 951 | actualWidth = m_maxWidth; |
1542ea39 | 952 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
5f0b2f22 SC |
953 | actualHeight = m_maxHeight; |
954 | ||
955 | bool doMove = false ; | |
956 | bool doResize = false ; | |
1542ea39 | 957 | |
5f0b2f22 SC |
958 | if ( actualX != former_x || actualY != former_y ) |
959 | { | |
960 | doMove = true ; | |
961 | } | |
962 | if ( actualWidth != former_w || actualHeight != former_h ) | |
963 | { | |
964 | doResize = true ; | |
965 | } | |
966 | ||
967 | if ( doMove || doResize ) | |
968 | { | |
969 | m_x = actualX ; | |
970 | m_y = actualY ; | |
971 | m_width = actualWidth ; | |
972 | m_height = actualHeight ; | |
973 | ||
974 | if ( doMove ) | |
76a5e5d2 | 975 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
1542ea39 | 976 | |
5f0b2f22 | 977 | if ( doResize ) |
1542ea39 RD |
978 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
979 | ||
2b5f62a0 VZ |
980 | // the OS takes care of invalidating and erasing the new area so we only have to |
981 | // take care of refreshing for full repaints | |
982 | ||
983 | if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) | |
984 | Refresh() ; | |
1542ea39 RD |
985 | |
986 | ||
5f0b2f22 SC |
987 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) |
988 | { | |
989 | wxFrame* frame = (wxFrame*) this ; | |
990 | frame->PositionStatusBar(); | |
991 | frame->PositionToolBar(); | |
992 | } | |
993 | if ( doMove ) | |
994 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
995 | ||
996 | MacRepositionScrollBars() ; | |
997 | if ( doMove ) | |
998 | { | |
999 | wxPoint point(m_x, m_y); | |
1000 | wxMoveEvent event(point, m_windowId); | |
1001 | event.SetEventObject(this); | |
1002 | GetEventHandler()->ProcessEvent(event) ; | |
1003 | } | |
1004 | if ( doResize ) | |
1005 | { | |
1006 | MacRepositionScrollBars() ; | |
1007 | wxSize size(m_width, m_height); | |
1008 | wxSizeEvent event(size, m_windowId); | |
1009 | event.SetEventObject(this); | |
1010 | GetEventHandler()->ProcessEvent(event); | |
1011 | } | |
1012 | } | |
1542ea39 | 1013 | |
5f0b2f22 SC |
1014 | } |
1015 | ||
1016 | /* | |
1017 | * Invalidation Mechanism | |
1018 | * | |
1019 | * The update mechanism reflects exactely the windows mechanism | |
1020 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
1021 | * has been true for any part of the update rgn the background is erased in the entire region | |
1022 | * not just in the specified rect. | |
1023 | * | |
1542ea39 | 1024 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have |
5f0b2f22 SC |
1025 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event |
1026 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
1027 | * will get the eraseBackground event first | |
1028 | */ | |
1542ea39 RD |
1029 | |
1030 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) | |
5f0b2f22 | 1031 | { |
e40298d5 JS |
1032 | GrafPtr formerPort ; |
1033 | GetPort( &formerPort ) ; | |
1034 | SetPortWindowPort( (WindowRef)m_macWindow ) ; | |
1542ea39 | 1035 | |
e40298d5 | 1036 | m_macNeedsErasing |= eraseBackground ; |
1542ea39 | 1037 | |
e40298d5 JS |
1038 | // if we already know that we will have to erase, there's no need to track the rest |
1039 | if ( !m_macNeedsErasing) | |
5f0b2f22 | 1040 | { |
e40298d5 JS |
1041 | // we end only here if eraseBackground is false |
1042 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
1043 | // we will have to erase anyway | |
1542ea39 RD |
1044 | |
1045 | RgnHandle updateRgn = NewRgn(); | |
e40298d5 JS |
1046 | RgnHandle diffRgn = NewRgn() ; |
1047 | if ( updateRgn && diffRgn ) | |
1048 | { | |
1049 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); | |
1050 | Point pt = {0,0} ; | |
1051 | LocalToGlobal( &pt ) ; | |
1052 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1053 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
1054 | if ( !EmptyRgn( diffRgn ) ) | |
1055 | { | |
1056 | m_macNeedsErasing = true ; | |
1057 | } | |
1058 | } | |
1059 | if ( updateRgn ) | |
1060 | DisposeRgn( updateRgn ); | |
1061 | if ( diffRgn ) | |
1062 | DisposeRgn( diffRgn ); | |
1542ea39 | 1063 | |
e40298d5 | 1064 | if ( !m_macNeedsErasing ) |
5f0b2f22 | 1065 | { |
e40298d5 JS |
1066 | RgnHandle rectRgn = NewRgn() ; |
1067 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; | |
1068 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
1069 | DisposeRgn( rectRgn ) ; | |
5f0b2f22 SC |
1070 | } |
1071 | } | |
e40298d5 JS |
1072 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
1073 | // turn this on to debug the refreshing cycle | |
34dc8f91 | 1074 | #if wxMAC_DEBUG_REDRAW |
e40298d5 | 1075 | PaintRect( rect ) ; |
5f0b2f22 | 1076 | #endif |
e40298d5 | 1077 | SetPort( formerPort ) ; |
5f0b2f22 | 1078 | } |
a07c1212 | 1079 | |
6a7e6411 | 1080 | |
1542ea39 RD |
1081 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1082 | { | |
6a7e6411 RD |
1083 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1084 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1085 | ||
45ff8005 | 1086 | #if TARGET_CARBON |
6a7e6411 RD |
1087 | // The empty region signifies that the shape should be removed from the |
1088 | // window. | |
1089 | if ( region.IsEmpty() ) | |
1090 | { | |
1091 | wxSize sz = GetClientSize(); | |
1092 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1093 | return SetShape(rgn); | |
1094 | } | |
1095 | ||
1096 | // Make a copy of the region | |
1097 | RgnHandle shapeRegion = NewRgn(); | |
1098 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1099 | ||
1100 | // Dispose of any shape region we may already have | |
1101 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1102 | if ( oldRgn ) | |
1103 | DisposeRgn(oldRgn); | |
1104 | ||
1105 | // Save the region so we can use it later | |
1106 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1107 | ||
1108 | // Tell the window manager that the window has changed shape | |
1109 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1110 | return TRUE; | |
45ff8005 RD |
1111 | #else |
1112 | return FALSE; | |
1113 | #endif | |
6a7e6411 RD |
1114 | } |
1115 | ||
6a7e6411 RD |
1116 | // --------------------------------------------------------------------------- |
1117 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1118 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1119 | // --------------------------------------------------------------------------- | |
1120 | ||
45ff8005 | 1121 | #if TARGET_CARBON |
1925be65 | 1122 | |
6a7e6411 RD |
1123 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1124 | { | |
1125 | GetWindowPortBounds(window, inRect); | |
1126 | Point pt = {inRect->left, inRect->top}; | |
1127 | SetPort((GrafPtr) GetWindowPort(window)); | |
1128 | LocalToGlobal(&pt); | |
1129 | inRect->top = pt.v; | |
1130 | inRect->left = pt.h; | |
1131 | inRect->bottom += pt.v; | |
1132 | inRect->right += pt.h; | |
1133 | } | |
1134 | ||
1135 | ||
1136 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1137 | { | |
1138 | /*------------------------------------------------------ | |
1139 | Define which options your custom window supports. | |
1140 | --------------------------------------------------------*/ | |
1141 | //just enable everything for our demo | |
1142 | *(OptionBits*)param=//kWindowCanGrow| | |
1143 | //kWindowCanZoom| | |
1144 | //kWindowCanCollapse| | |
1145 | //kWindowCanGetWindowRegion| | |
1146 | //kWindowHasTitleBar| | |
1147 | //kWindowSupportsDragHilite| | |
1148 | kWindowCanDrawInCurrentPort| | |
1149 | //kWindowCanMeasureTitle| | |
1150 | kWindowWantsDisposeAtProcessDeath| | |
1151 | kWindowSupportsSetGrowImageRegion| | |
1152 | kWindowDefSupportsColorGrafPort; | |
1153 | return 1; | |
1542ea39 | 1154 | } |
6a7e6411 RD |
1155 | |
1156 | // The content region is left as a rectangle matching the window size, this is | |
1157 | // so the origin in the paint event, and etc. still matches what the | |
1158 | // programmer expects. | |
1159 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1160 | { | |
1161 | SetEmptyRgn(rgn); | |
1162 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1163 | if (win) | |
1164 | { | |
1165 | wxRect r = win->GetRect(); | |
1166 | SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | // The structure region is set to the shape given to the SetShape method. | |
1171 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1172 | { | |
1173 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1174 | ||
1175 | SetEmptyRgn(rgn); | |
1176 | if (cachedRegion) | |
1177 | { | |
1178 | Rect windowRect; | |
1179 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1180 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1181 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1182 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1183 | } | |
1184 | } | |
1185 | ||
1186 | ||
1187 | ||
1188 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1189 | { | |
1190 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1191 | ||
1192 | switch(rgnRec->regionCode) | |
1193 | { | |
1194 | case kWindowStructureRgn: | |
1195 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1196 | break; | |
1197 | case kWindowContentRgn: | |
1198 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1199 | break; | |
1200 | default: | |
1201 | SetEmptyRgn(rgnRec->winRgn); | |
1202 | } //switch | |
1203 | ||
1204 | return noErr; | |
1205 | } | |
1206 | ||
1207 | ||
1208 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1209 | { | |
1210 | /*------------------------------------------------------ | |
1211 | Determine the region of the window which was hit | |
1212 | --------------------------------------------------------*/ | |
1213 | Point hitPoint; | |
1214 | static RgnHandle tempRgn=nil; | |
1215 | ||
1216 | if(!tempRgn) | |
1217 | tempRgn=NewRgn(); | |
1218 | ||
1219 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1220 | ||
1221 | //Mac OS 8.5 or later | |
1222 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1223 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1224 | return wInContent; | |
1225 | ||
1226 | return wNoHit;//no significant area was hit. | |
1227 | } | |
1228 | ||
1229 | ||
1230 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1231 | { | |
1232 | switch(message) | |
1233 | { | |
1234 | case kWindowMsgHitTest: | |
1235 | return wxShapedMacWindowHitTest(window,param); | |
1236 | ||
1237 | case kWindowMsgGetFeatures: | |
1238 | return wxShapedMacWindowGetFeatures(window,param); | |
1239 | ||
1240 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1241 | case kWindowMsgGetRegion: | |
1242 | return wxShapedMacWindowGetRegion(window,param); | |
1243 | } | |
1244 | ||
1245 | return 0; | |
1246 | } | |
1925be65 | 1247 | |
45ff8005 | 1248 | #endif |
6a7e6411 | 1249 | // --------------------------------------------------------------------------- |
1925be65 | 1250 |