]>
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 | ||
5706de1c JS |
352 | // Patch 531199 defined a window event handler, as follows. |
353 | // TODO: merge the moving/sizing event handling with the event | |
354 | // handler above. | |
355 | #if 0 | |
356 | static pascal OSStatus | |
357 | WindowHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* userData ) | |
358 | { | |
359 | Rect bounds; | |
360 | SInt16 height, width; | |
361 | UInt32 attributes; | |
362 | OSStatus result = eventNotHandledErr; | |
363 | ||
364 | GetEventParameter( inEvent, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); | |
365 | ||
366 | if ((attributes & (kWindowBoundsChangeSizeChanged | kWindowBoundsChangeOriginChanged)) != 0) | |
367 | { | |
368 | // Extract the current bounds. This is the paramter you get to modify to | |
369 | // alter the window position or size during a window resizing. | |
370 | GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( bounds ), NULL, &bounds ); | |
371 | ||
372 | wxRect rect; | |
373 | rect.SetLeft(bounds.left); | |
374 | rect.SetTop(bounds.top); | |
375 | rect.SetRight(bounds.right); | |
376 | rect.SetBottom(bounds.bottom); | |
377 | ||
378 | bool rc; | |
379 | wxWindowMac *pWindow = (wxWindowMac*)userData; | |
380 | if ((attributes & kWindowBoundsChangeSizeChanged) != 0) { | |
381 | wxSizeEvent event(rect, pWindow->GetId()); | |
382 | event.SetEventObject(pWindow); | |
383 | rc = pWindow->GetEventHandler()->ProcessEvent(event); | |
384 | rect = event.GetRect(); | |
385 | } | |
386 | else { | |
387 | wxMoveEvent event(rect, pWindow->GetId()); | |
388 | event.SetEventObject(pWindow); | |
389 | rc = pWindow->GetEventHandler()->ProcessEvent(event); | |
390 | rect = event.GetRect(); | |
391 | } | |
392 | ||
393 | if (rc) { | |
394 | bounds.left = rect.GetLeft(); | |
395 | bounds.top = rect.GetTop(); | |
396 | bounds.right = rect.GetRight(); | |
397 | bounds.bottom = rect.GetBottom(); | |
398 | } | |
399 | ||
400 | // Set the current bounds parameter to our adjusted bounds. Return | |
401 | // noErr to indicate we handled this event. | |
402 | SetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, sizeof( bounds ), &bounds ); | |
403 | result = noErr; | |
404 | } | |
405 | return result; | |
406 | } | |
407 | #endif | |
408 | // WindowHandler | |
409 | ||
851b3a88 SC |
410 | #endif |
411 | ||
5f0b2f22 SC |
412 | // --------------------------------------------------------------------------- |
413 | // wxWindowMac utility functions | |
414 | // --------------------------------------------------------------------------- | |
415 | ||
416 | // Find an item given the Macintosh Window Reference | |
417 | ||
418 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 419 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 SC |
420 | { |
421 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
422 | if (!node) | |
423 | return NULL; | |
eb22f2a6 | 424 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
425 | } |
426 | ||
76a5e5d2 | 427 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
428 | { |
429 | // adding NULL WindowRef is (first) surely a result of an error and | |
430 | // (secondly) breaks menu command processing | |
427ff662 | 431 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 SC |
432 | |
433 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
434 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
435 | } | |
436 | ||
437 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
438 | { | |
439 | wxWinMacWindowList->DeleteObject(win); | |
440 | } | |
441 | ||
442 | ||
a15eb0a5 SC |
443 | // ---------------------------------------------------------------------------- |
444 | // wxTopLevelWindowMac creation | |
445 | // ---------------------------------------------------------------------------- | |
446 | ||
76a5e5d2 | 447 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
5f0b2f22 | 448 | |
a15eb0a5 SC |
449 | void wxTopLevelWindowMac::Init() |
450 | { | |
451 | m_iconized = | |
452 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
453 | m_macNoEraseUpdateRgn = NewRgn() ; |
454 | m_macNeedsErasing = false ; | |
6a17ca35 | 455 | m_macWindow = NULL ; |
851b3a88 | 456 | #if TARGET_CARBON |
7c091673 | 457 | m_macEventHandler = NULL ; |
851b3a88 | 458 | #endif |
a15eb0a5 SC |
459 | } |
460 | ||
118f012e SC |
461 | class wxMacDeferredWindowDeleter : public wxObject |
462 | { | |
463 | public : | |
1542ea39 RD |
464 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
465 | { | |
466 | m_macWindow = windowRef ; | |
118f012e | 467 | } |
1542ea39 RD |
468 | virtual ~wxMacDeferredWindowDeleter() |
469 | { | |
470 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
471 | } |
472 | protected : | |
473 | WindowRef m_macWindow ; | |
474 | } ; | |
475 | ||
a15eb0a5 SC |
476 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
477 | wxWindowID id, | |
478 | const wxString& title, | |
479 | const wxPoint& pos, | |
480 | const wxSize& size, | |
481 | long style, | |
482 | const wxString& name) | |
483 | { | |
484 | // init our fields | |
485 | Init(); | |
486 | ||
487 | m_windowStyle = style; | |
488 | ||
489 | SetName(name); | |
490 | ||
491 | m_windowId = id == -1 ? NewControlId() : id; | |
492 | ||
493 | wxTopLevelWindows.Append(this); | |
494 | ||
495 | if ( parent ) | |
496 | parent->AddChild(this); | |
497 | ||
498 | return TRUE; | |
499 | } | |
500 | ||
501 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
502 | { | |
6a17ca35 SC |
503 | if ( m_macWindow ) |
504 | { | |
505 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 506 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 507 | } |
1542ea39 | 508 | |
f75363ee | 509 | #if TARGET_CARBON |
7c091673 SC |
510 | if ( m_macEventHandler ) |
511 | { | |
512 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
513 | m_macEventHandler = NULL ; | |
514 | } | |
1542ea39 | 515 | #endif |
851b3a88 | 516 | |
5f0b2f22 SC |
517 | wxRemoveMacWindowAssociation( this ) ; |
518 | ||
a15eb0a5 SC |
519 | if ( wxModelessWindows.Find(this) ) |
520 | wxModelessWindows.DeleteObject(this); | |
521 | ||
76a5e5d2 | 522 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
523 | } |
524 | ||
525 | ||
526 | // ---------------------------------------------------------------------------- | |
527 | // wxTopLevelWindowMac maximize/minimize | |
528 | // ---------------------------------------------------------------------------- | |
529 | ||
530 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
531 | { | |
532 | // not available on mac | |
533 | } | |
534 | ||
535 | bool wxTopLevelWindowMac::IsMaximized() const | |
536 | { | |
1542ea39 | 537 | return false ; |
a15eb0a5 SC |
538 | } |
539 | ||
540 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
541 | { | |
542 | // not available on mac | |
543 | } | |
544 | ||
545 | bool wxTopLevelWindowMac::IsIconized() const | |
546 | { | |
ed60b502 | 547 | // mac dialogs cannot be iconized |
a15eb0a5 SC |
548 | return FALSE; |
549 | } | |
550 | ||
551 | void wxTopLevelWindowMac::Restore() | |
552 | { | |
553 | // not available on mac | |
554 | } | |
555 | ||
556 | // ---------------------------------------------------------------------------- | |
557 | // wxTopLevelWindowMac misc | |
558 | // ---------------------------------------------------------------------------- | |
559 | ||
560 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
561 | { | |
562 | // this sets m_icon | |
563 | wxTopLevelWindowBase::SetIcon(icon); | |
564 | } | |
5f0b2f22 SC |
565 | |
566 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, | |
567 | const wxPoint& pos, | |
568 | const wxSize& size, | |
569 | long style, | |
1542ea39 | 570 | const wxString& name ) |
5f0b2f22 | 571 | { |
e40298d5 JS |
572 | SetName(name); |
573 | m_windowStyle = style; | |
574 | m_isShown = FALSE; | |
1542ea39 | 575 | |
e40298d5 | 576 | // create frame. |
1542ea39 | 577 | |
5f0b2f22 | 578 | Rect theBoundsRect; |
1542ea39 | 579 | |
e40298d5 JS |
580 | m_x = (int)pos.x; |
581 | m_y = (int)pos.y; | |
582 | if ( m_y < 50 ) | |
583 | m_y = 50 ; | |
584 | if ( m_x < 20 ) | |
585 | m_x = 20 ; | |
1542ea39 | 586 | |
e40298d5 | 587 | m_width = size.x; |
1542ea39 | 588 | if (m_width == -1) |
5f0b2f22 | 589 | m_width = 20; |
e40298d5 | 590 | m_height = size.y; |
1542ea39 | 591 | if (m_height == -1) |
5f0b2f22 | 592 | m_height = 20; |
1542ea39 | 593 | |
5f0b2f22 | 594 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); |
1542ea39 | 595 | |
5f0b2f22 | 596 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 597 | |
5f0b2f22 SC |
598 | WindowClass wclass = 0; |
599 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 600 | |
f5744893 | 601 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 602 | { |
1542ea39 | 603 | if ( |
f5744893 SC |
604 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
605 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
606 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 607 | ) |
5f0b2f22 | 608 | { |
f5744893 SC |
609 | wclass = kFloatingWindowClass ; |
610 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
611 | { | |
612 | attr |= kWindowSideTitlebarAttribute ; | |
613 | } | |
614 | } | |
615 | else | |
616 | { | |
2b5f62a0 | 617 | #if TARGET_CARBON |
f5744893 | 618 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
619 | #else |
620 | wclass = kFloatingWindowClass ; | |
621 | #endif | |
5f0b2f22 SC |
622 | } |
623 | } | |
624 | else if ( HasFlag( wxCAPTION ) ) | |
625 | { | |
1542ea39 | 626 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
627 | } |
628 | else | |
629 | { | |
f5744893 | 630 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
e40298d5 | 631 | HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
632 | { |
633 | wclass = kDocumentWindowClass ; | |
634 | } | |
635 | else | |
636 | { | |
2b5f62a0 | 637 | #if TARGET_CARBON |
f5744893 | 638 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
639 | #else |
640 | wclass = kModalWindowClass ; | |
641 | #endif | |
f5744893 | 642 | } |
5f0b2f22 | 643 | } |
1542ea39 | 644 | |
5f0b2f22 SC |
645 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) |
646 | { | |
647 | attr |= kWindowFullZoomAttribute ; | |
648 | attr |= kWindowCollapseBoxAttribute ; | |
649 | } | |
650 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
651 | { | |
652 | attr |= kWindowResizableAttribute ; | |
653 | } | |
654 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
655 | { | |
656 | attr |= kWindowCloseBoxAttribute ; | |
657 | } | |
1542ea39 | 658 | |
b9c10231 SC |
659 | #if TARGET_CARBON |
660 | #if 0 // having problems right now with that | |
6a7e6411 RD |
661 | if (HasFlag(wxSTAY_ON_TOP)) |
662 | wclass = kUtilityWindowClass; | |
b9c10231 SC |
663 | #endif |
664 | #endif | |
6a7e6411 | 665 | |
45ff8005 | 666 | #if TARGET_CARBON |
6a7e6411 RD |
667 | if ( HasFlag(wxFRAME_SHAPED) ) |
668 | { | |
669 | WindowDefSpec customWindowDefSpec; | |
670 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
671 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
672 | ||
673 | ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
674 | attr, &theBoundsRect, | |
675 | (WindowRef*) &m_macWindow); | |
676 | } | |
677 | else | |
45ff8005 | 678 | #endif |
6a7e6411 RD |
679 | { |
680 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
681 | } | |
682 | ||
5f0b2f22 | 683 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
427ff662 | 684 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
76a5e5d2 | 685 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; |
851b3a88 | 686 | #if TARGET_CARBON |
e40298d5 | 687 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
1542ea39 RD |
688 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), |
689 | GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
5706de1c JS |
690 | |
691 | // Patch 531199 also defined a window event handler, as follows: | |
692 | #if 0 | |
693 | // install a window event handler to send wxEVT_MOVING and wxEVT_SIZING events | |
694 | EventTypeSpec events[] = { { kEventClassWindow, kEventWindowBoundsChanging } }; | |
695 | EventHandlerUPP handlerProc = NewEventHandlerUPP( WindowHandler ); | |
696 | EventHandlerRef eventHandlerRef; | |
697 | InstallWindowEventHandler( m_macWindowData->m_macWindow, handlerProc, GetEventTypeCount(events), | |
698 | events, (void*)this, &eventHandlerRef); | |
699 | #endif | |
700 | ||
851b3a88 | 701 | #endif |
5f0b2f22 | 702 | m_macFocus = NULL ; |
6a7e6411 RD |
703 | |
704 | ||
45ff8005 | 705 | #if TARGET_CARBON |
6a7e6411 RD |
706 | if ( HasFlag(wxFRAME_SHAPED) ) |
707 | { | |
708 | // default shape matches the window size | |
709 | wxRegion rgn(0, 0, m_width, m_height); | |
710 | SetShape(rgn); | |
711 | } | |
45ff8005 | 712 | #endif |
5f0b2f22 SC |
713 | } |
714 | ||
1542ea39 | 715 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 716 | { |
76a5e5d2 SC |
717 | ((Point*)localOrigin)->h = 0; |
718 | ((Point*)localOrigin)->v = 0; | |
719 | ((Rect*)clipRect)->left = 0; | |
720 | ((Rect*)clipRect)->top = 0; | |
721 | ((Rect*)clipRect)->right = m_width; | |
722 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
723 | *window = m_macWindow ; |
724 | *rootwin = this ; | |
725 | } | |
726 | ||
727 | void wxTopLevelWindowMac::Clear() | |
728 | { | |
e40298d5 | 729 | wxWindow::Clear() ; |
5f0b2f22 SC |
730 | } |
731 | ||
1542ea39 | 732 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
733 | { |
734 | return m_macRootControl ; | |
735 | } | |
736 | ||
737 | ||
738 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
739 | { | |
66a09d47 | 740 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 | 741 | |
1925be65 SC |
742 | RgnHandle visRgn = NewRgn() ; |
743 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); | |
76a5e5d2 | 744 | BeginUpdate( (WindowRef)m_macWindow ) ; |
5f0b2f22 | 745 | |
1542ea39 | 746 | RgnHandle updateRgn = NewRgn(); |
5f0b2f22 | 747 | RgnHandle diffRgn = NewRgn() ; |
1925be65 | 748 | |
5f0b2f22 SC |
749 | if ( updateRgn && diffRgn ) |
750 | { | |
732b3a75 SC |
751 | #if 1 |
752 | // macos internal control redraws clean up areas we'd like to redraw ourselves | |
753 | // therefore we pick the boundary rect and make sure we can redraw it | |
1925be65 SC |
754 | // this has to be intersected by the visRgn in order to avoid drawing over its own |
755 | // boundaries | |
732b3a75 SC |
756 | RgnHandle trueUpdateRgn = NewRgn() ; |
757 | Rect trueUpdateRgnBoundary ; | |
758 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); | |
759 | GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; | |
1925be65 SC |
760 | RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; |
761 | SectRgn( updateRgn , visRgn , updateRgn ) ; | |
732b3a75 SC |
762 | if ( trueUpdateRgn ) |
763 | DisposeRgn( trueUpdateRgn ) ; | |
764 | SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; | |
765 | #else | |
76a5e5d2 | 766 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
732b3a75 | 767 | #endif |
76a5e5d2 | 768 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
769 | if ( !EmptyRgn( updateRgn ) ) |
770 | { | |
771 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
772 | } | |
773 | } | |
774 | if ( updateRgn ) | |
775 | DisposeRgn( updateRgn ); | |
776 | if ( diffRgn ) | |
777 | DisposeRgn( diffRgn ); | |
1925be65 SC |
778 | if ( visRgn ) |
779 | DisposeRgn( visRgn ) ; | |
780 | ||
76a5e5d2 SC |
781 | EndUpdate( (WindowRef)m_macWindow ) ; |
782 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
783 | m_macNeedsErasing = false ; |
784 | } | |
785 | ||
786 | ||
787 | // Raise the window to the top of the Z order | |
788 | void wxTopLevelWindowMac::Raise() | |
789 | { | |
7f3c339c | 790 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
791 | } |
792 | ||
793 | // Lower the window to the bottom of the Z order | |
794 | void wxTopLevelWindowMac::Lower() | |
795 | { | |
76a5e5d2 | 796 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
797 | } |
798 | ||
1542ea39 | 799 | void wxTopLevelWindowMac::MacFireMouseEvent( |
e40298d5 | 800 | wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) |
5f0b2f22 SC |
801 | { |
802 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
851b3a88 SC |
803 | bool isDown = !(modifiers & btnState) ; // 1 is for up |
804 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
1542ea39 | 805 | |
5f0b2f22 | 806 | event.m_leftDown = isDown && !controlDown; |
1542ea39 | 807 | |
5f0b2f22 SC |
808 | event.m_middleDown = FALSE; |
809 | event.m_rightDown = isDown && controlDown; | |
810 | ||
851b3a88 | 811 | if ( kind == mouseDown ) |
5f0b2f22 SC |
812 | { |
813 | if ( controlDown ) | |
814 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
815 | else | |
816 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
817 | } | |
851b3a88 | 818 | else if ( kind == mouseUp ) |
5f0b2f22 SC |
819 | { |
820 | if ( controlDown ) | |
821 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
822 | else | |
823 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
824 | } | |
825 | else | |
826 | { | |
827 | event.SetEventType(wxEVT_MOTION ) ; | |
828 | } | |
829 | ||
851b3a88 SC |
830 | event.m_shiftDown = modifiers & shiftKey; |
831 | event.m_controlDown = modifiers & controlKey; | |
832 | event.m_altDown = modifiers & optionKey; | |
833 | event.m_metaDown = modifiers & cmdKey; | |
5f0b2f22 | 834 | |
851b3a88 SC |
835 | Point localwhere ; |
836 | localwhere.h = x ; | |
837 | localwhere.v = y ; | |
1542ea39 RD |
838 | |
839 | GrafPtr port ; | |
5f0b2f22 | 840 | ::GetPort( &port ) ; |
76a5e5d2 | 841 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
842 | ::GlobalToLocal( &localwhere ) ; |
843 | ::SetPort( port ) ; | |
844 | ||
851b3a88 | 845 | if ( kind == mouseDown ) |
5f0b2f22 | 846 | { |
5be55d56 | 847 | if ( timestamp - gs_lastWhen <= (long) GetDblTime() ) |
5f0b2f22 | 848 | { |
32b5be3d | 849 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 850 | { |
32b5be3d RR |
851 | // This is not right if the second mouse down |
852 | // event occured in a differen window. We | |
853 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
854 | if ( controlDown ) |
855 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
856 | else | |
857 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
858 | } | |
32b5be3d | 859 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
860 | } |
861 | else | |
862 | { | |
851b3a88 | 863 | gs_lastWhen = timestamp ; |
5f0b2f22 | 864 | } |
32b5be3d | 865 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
866 | } |
867 | ||
868 | event.m_x = localwhere.h; | |
869 | event.m_y = localwhere.v; | |
870 | event.m_x += m_x; | |
871 | event.m_y += m_y; | |
872 | ||
851b3a88 | 873 | event.m_timeStamp = timestamp; |
5f0b2f22 SC |
874 | event.SetEventObject(this); |
875 | if ( wxTheApp->s_captureWindow ) | |
876 | { | |
877 | int x = event.m_x ; | |
878 | int y = event.m_y ; | |
879 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
880 | event.m_x = x ; | |
881 | event.m_y = y ; | |
2e6857fa | 882 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 883 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
1542ea39 | 884 | |
851b3a88 | 885 | if ( kind == mouseUp ) |
5f0b2f22 SC |
886 | { |
887 | wxTheApp->s_captureWindow = NULL ; | |
6b57b49a | 888 | if ( !wxIsBusy() ) |
5f0b2f22 SC |
889 | { |
890 | m_cursor.MacInstall() ; | |
891 | } | |
892 | } | |
893 | } | |
894 | else | |
895 | { | |
896 | MacDispatchMouseEvent( event ) ; | |
897 | } | |
898 | } | |
e40298d5 | 899 | |
851b3a88 | 900 | #if !TARGET_CARBON |
5f0b2f22 | 901 | |
76a5e5d2 | 902 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 | 903 | { |
1542ea39 | 904 | MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 905 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
906 | } |
907 | ||
76a5e5d2 | 908 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
909 | { |
910 | switch (part) | |
911 | { | |
1542ea39 | 912 | case inContent: |
5f0b2f22 | 913 | { |
1542ea39 | 914 | MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 915 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
916 | } |
917 | break ; | |
918 | } | |
919 | } | |
920 | ||
76a5e5d2 | 921 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
922 | { |
923 | switch (part) | |
924 | { | |
1542ea39 | 925 | case inContent: |
5f0b2f22 | 926 | { |
1542ea39 | 927 | MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 928 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
929 | } |
930 | break ; | |
931 | } | |
932 | } | |
851b3a88 SC |
933 | |
934 | #endif | |
935 | ||
936 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
5f0b2f22 SC |
937 | { |
938 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
851b3a88 | 939 | event.m_timeStamp = timestamp ; |
5f0b2f22 | 940 | event.SetEventObject(this); |
1542ea39 | 941 | |
5f0b2f22 | 942 | GetEventHandler()->ProcessEvent(event); |
1542ea39 | 943 | |
76a5e5d2 | 944 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
1542ea39 | 945 | |
a006e78b JS |
946 | // Early versions of MacOS X don't refresh backgrounds properly, |
947 | // so refresh the whole window on activation and deactivation. | |
948 | long osVersion = UMAGetSystemVersion(); | |
1925be65 | 949 | if (osVersion >= 0x1000 && osVersion < 0x1020 ) |
732b3a75 | 950 | { |
a006e78b | 951 | Refresh(TRUE); |
732b3a75 | 952 | } |
a006e78b | 953 | else |
732b3a75 SC |
954 | { |
955 | // for the moment we have to resolve some redrawing issues like this | |
956 | // the OS is stealing some redrawing areas as soon as it draws a control | |
957 | Refresh(TRUE); | |
958 | } | |
5f0b2f22 SC |
959 | } |
960 | ||
851b3a88 SC |
961 | #if !TARGET_CARBON |
962 | ||
1542ea39 | 963 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
964 | { |
965 | } | |
966 | ||
851b3a88 SC |
967 | #endif |
968 | ||
5f0b2f22 SC |
969 | void wxTopLevelWindowMac::SetTitle(const wxString& title) |
970 | { | |
971 | wxWindow::SetTitle( title ) ; | |
427ff662 | 972 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
5f0b2f22 SC |
973 | } |
974 | ||
975 | bool wxTopLevelWindowMac::Show(bool show) | |
976 | { | |
977 | if ( !wxWindow::Show(show) ) | |
978 | return FALSE; | |
979 | ||
980 | if (show) | |
1542ea39 | 981 | { |
1925be65 | 982 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); |
76a5e5d2 | 983 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
984 | // no need to generate events here, they will get them triggered by macos |
985 | // actually they should be , but apparently they are not | |
986 | wxSize size(m_width, m_height); | |
987 | wxSizeEvent event(size, m_windowId); | |
988 | event.SetEventObject(this); | |
989 | GetEventHandler()->ProcessEvent(event); | |
990 | } | |
991 | else | |
992 | { | |
1925be65 | 993 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); |
5f0b2f22 SC |
994 | } |
995 | ||
996 | if ( !show ) | |
997 | { | |
998 | } | |
999 | else | |
1000 | { | |
1542ea39 | 1001 | Refresh() ; |
5f0b2f22 SC |
1002 | } |
1003 | ||
1004 | return TRUE; | |
1005 | } | |
1006 | ||
1007 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1008 | { | |
1009 | int former_x = m_x ; | |
1010 | int former_y = m_y ; | |
1011 | int former_w = m_width ; | |
1012 | int former_h = m_height ; | |
1542ea39 | 1013 | |
e40298d5 JS |
1014 | int actualWidth = width; |
1015 | int actualHeight = height; | |
1016 | int actualX = x; | |
1017 | int actualY = y; | |
1542ea39 RD |
1018 | |
1019 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
5f0b2f22 | 1020 | actualWidth = m_minWidth; |
1542ea39 | 1021 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
5f0b2f22 | 1022 | actualHeight = m_minHeight; |
1542ea39 | 1023 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
5f0b2f22 | 1024 | actualWidth = m_maxWidth; |
1542ea39 | 1025 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
5f0b2f22 SC |
1026 | actualHeight = m_maxHeight; |
1027 | ||
1028 | bool doMove = false ; | |
1029 | bool doResize = false ; | |
1542ea39 | 1030 | |
5f0b2f22 SC |
1031 | if ( actualX != former_x || actualY != former_y ) |
1032 | { | |
1033 | doMove = true ; | |
1034 | } | |
1035 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1036 | { | |
1037 | doResize = true ; | |
1038 | } | |
1039 | ||
1040 | if ( doMove || doResize ) | |
1041 | { | |
1042 | m_x = actualX ; | |
1043 | m_y = actualY ; | |
1044 | m_width = actualWidth ; | |
1045 | m_height = actualHeight ; | |
1046 | ||
1047 | if ( doMove ) | |
76a5e5d2 | 1048 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
1542ea39 | 1049 | |
5f0b2f22 | 1050 | if ( doResize ) |
1542ea39 RD |
1051 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
1052 | ||
2b5f62a0 VZ |
1053 | // the OS takes care of invalidating and erasing the new area so we only have to |
1054 | // take care of refreshing for full repaints | |
1055 | ||
1056 | if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) | |
1057 | Refresh() ; | |
1542ea39 RD |
1058 | |
1059 | ||
5f0b2f22 SC |
1060 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) |
1061 | { | |
1062 | wxFrame* frame = (wxFrame*) this ; | |
1063 | frame->PositionStatusBar(); | |
1064 | frame->PositionToolBar(); | |
1065 | } | |
1066 | if ( doMove ) | |
1067 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
1068 | ||
1069 | MacRepositionScrollBars() ; | |
1070 | if ( doMove ) | |
1071 | { | |
1072 | wxPoint point(m_x, m_y); | |
1073 | wxMoveEvent event(point, m_windowId); | |
1074 | event.SetEventObject(this); | |
1075 | GetEventHandler()->ProcessEvent(event) ; | |
1076 | } | |
1077 | if ( doResize ) | |
1078 | { | |
1079 | MacRepositionScrollBars() ; | |
1080 | wxSize size(m_width, m_height); | |
1081 | wxSizeEvent event(size, m_windowId); | |
1082 | event.SetEventObject(this); | |
1083 | GetEventHandler()->ProcessEvent(event); | |
1084 | } | |
1085 | } | |
1542ea39 | 1086 | |
5f0b2f22 SC |
1087 | } |
1088 | ||
1089 | /* | |
1090 | * Invalidation Mechanism | |
1091 | * | |
1092 | * The update mechanism reflects exactely the windows mechanism | |
1093 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
1094 | * has been true for any part of the update rgn the background is erased in the entire region | |
1095 | * not just in the specified rect. | |
1096 | * | |
1542ea39 | 1097 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have |
5f0b2f22 SC |
1098 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event |
1099 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
1100 | * will get the eraseBackground event first | |
1101 | */ | |
1542ea39 RD |
1102 | |
1103 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) | |
5f0b2f22 | 1104 | { |
e40298d5 JS |
1105 | GrafPtr formerPort ; |
1106 | GetPort( &formerPort ) ; | |
1107 | SetPortWindowPort( (WindowRef)m_macWindow ) ; | |
1542ea39 | 1108 | |
e40298d5 | 1109 | m_macNeedsErasing |= eraseBackground ; |
1542ea39 | 1110 | |
e40298d5 JS |
1111 | // if we already know that we will have to erase, there's no need to track the rest |
1112 | if ( !m_macNeedsErasing) | |
5f0b2f22 | 1113 | { |
e40298d5 JS |
1114 | // we end only here if eraseBackground is false |
1115 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
1116 | // we will have to erase anyway | |
1542ea39 RD |
1117 | |
1118 | RgnHandle updateRgn = NewRgn(); | |
e40298d5 JS |
1119 | RgnHandle diffRgn = NewRgn() ; |
1120 | if ( updateRgn && diffRgn ) | |
1121 | { | |
1122 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); | |
1123 | Point pt = {0,0} ; | |
1124 | LocalToGlobal( &pt ) ; | |
1125 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1126 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
1127 | if ( !EmptyRgn( diffRgn ) ) | |
1128 | { | |
1129 | m_macNeedsErasing = true ; | |
1130 | } | |
1131 | } | |
1132 | if ( updateRgn ) | |
1133 | DisposeRgn( updateRgn ); | |
1134 | if ( diffRgn ) | |
1135 | DisposeRgn( diffRgn ); | |
1542ea39 | 1136 | |
e40298d5 | 1137 | if ( !m_macNeedsErasing ) |
5f0b2f22 | 1138 | { |
e40298d5 JS |
1139 | RgnHandle rectRgn = NewRgn() ; |
1140 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; | |
1141 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
1142 | DisposeRgn( rectRgn ) ; | |
5f0b2f22 SC |
1143 | } |
1144 | } | |
e40298d5 JS |
1145 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
1146 | // turn this on to debug the refreshing cycle | |
34dc8f91 | 1147 | #if wxMAC_DEBUG_REDRAW |
e40298d5 | 1148 | PaintRect( rect ) ; |
5f0b2f22 | 1149 | #endif |
e40298d5 | 1150 | SetPort( formerPort ) ; |
5f0b2f22 | 1151 | } |
a07c1212 | 1152 | |
6a7e6411 | 1153 | |
1542ea39 RD |
1154 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1155 | { | |
6a7e6411 RD |
1156 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1157 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1158 | ||
45ff8005 | 1159 | #if TARGET_CARBON |
6a7e6411 RD |
1160 | // The empty region signifies that the shape should be removed from the |
1161 | // window. | |
1162 | if ( region.IsEmpty() ) | |
1163 | { | |
1164 | wxSize sz = GetClientSize(); | |
1165 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1166 | return SetShape(rgn); | |
1167 | } | |
1168 | ||
1169 | // Make a copy of the region | |
1170 | RgnHandle shapeRegion = NewRgn(); | |
1171 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1172 | ||
1173 | // Dispose of any shape region we may already have | |
1174 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1175 | if ( oldRgn ) | |
1176 | DisposeRgn(oldRgn); | |
1177 | ||
1178 | // Save the region so we can use it later | |
1179 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1180 | ||
1181 | // Tell the window manager that the window has changed shape | |
1182 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1183 | return TRUE; | |
45ff8005 RD |
1184 | #else |
1185 | return FALSE; | |
1186 | #endif | |
6a7e6411 RD |
1187 | } |
1188 | ||
6a7e6411 RD |
1189 | // --------------------------------------------------------------------------- |
1190 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1191 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1192 | // --------------------------------------------------------------------------- | |
1193 | ||
45ff8005 | 1194 | #if TARGET_CARBON |
1925be65 | 1195 | |
6a7e6411 RD |
1196 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1197 | { | |
1198 | GetWindowPortBounds(window, inRect); | |
1199 | Point pt = {inRect->left, inRect->top}; | |
1200 | SetPort((GrafPtr) GetWindowPort(window)); | |
1201 | LocalToGlobal(&pt); | |
1202 | inRect->top = pt.v; | |
1203 | inRect->left = pt.h; | |
1204 | inRect->bottom += pt.v; | |
1205 | inRect->right += pt.h; | |
1206 | } | |
1207 | ||
1208 | ||
1209 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1210 | { | |
1211 | /*------------------------------------------------------ | |
1212 | Define which options your custom window supports. | |
1213 | --------------------------------------------------------*/ | |
1214 | //just enable everything for our demo | |
1215 | *(OptionBits*)param=//kWindowCanGrow| | |
1216 | //kWindowCanZoom| | |
1217 | //kWindowCanCollapse| | |
1218 | //kWindowCanGetWindowRegion| | |
1219 | //kWindowHasTitleBar| | |
1220 | //kWindowSupportsDragHilite| | |
1221 | kWindowCanDrawInCurrentPort| | |
1222 | //kWindowCanMeasureTitle| | |
1223 | kWindowWantsDisposeAtProcessDeath| | |
1224 | kWindowSupportsSetGrowImageRegion| | |
1225 | kWindowDefSupportsColorGrafPort; | |
1226 | return 1; | |
1542ea39 | 1227 | } |
6a7e6411 RD |
1228 | |
1229 | // The content region is left as a rectangle matching the window size, this is | |
1230 | // so the origin in the paint event, and etc. still matches what the | |
1231 | // programmer expects. | |
1232 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1233 | { | |
1234 | SetEmptyRgn(rgn); | |
1235 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1236 | if (win) | |
1237 | { | |
1238 | wxRect r = win->GetRect(); | |
1239 | SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
1240 | } | |
1241 | } | |
1242 | ||
1243 | // The structure region is set to the shape given to the SetShape method. | |
1244 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1245 | { | |
1246 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1247 | ||
1248 | SetEmptyRgn(rgn); | |
1249 | if (cachedRegion) | |
1250 | { | |
1251 | Rect windowRect; | |
1252 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1253 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1254 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1255 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1256 | } | |
1257 | } | |
1258 | ||
1259 | ||
1260 | ||
1261 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1262 | { | |
1263 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1264 | ||
1265 | switch(rgnRec->regionCode) | |
1266 | { | |
1267 | case kWindowStructureRgn: | |
1268 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1269 | break; | |
1270 | case kWindowContentRgn: | |
1271 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1272 | break; | |
1273 | default: | |
1274 | SetEmptyRgn(rgnRec->winRgn); | |
1275 | } //switch | |
1276 | ||
1277 | return noErr; | |
1278 | } | |
1279 | ||
1280 | ||
1281 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1282 | { | |
1283 | /*------------------------------------------------------ | |
1284 | Determine the region of the window which was hit | |
1285 | --------------------------------------------------------*/ | |
1286 | Point hitPoint; | |
1287 | static RgnHandle tempRgn=nil; | |
1288 | ||
1289 | if(!tempRgn) | |
1290 | tempRgn=NewRgn(); | |
1291 | ||
1292 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1293 | ||
1294 | //Mac OS 8.5 or later | |
1295 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1296 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1297 | return wInContent; | |
1298 | ||
1299 | return wNoHit;//no significant area was hit. | |
1300 | } | |
1301 | ||
1302 | ||
1303 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1304 | { | |
1305 | switch(message) | |
1306 | { | |
1307 | case kWindowMsgHitTest: | |
1308 | return wxShapedMacWindowHitTest(window,param); | |
1309 | ||
1310 | case kWindowMsgGetFeatures: | |
1311 | return wxShapedMacWindowGetFeatures(window,param); | |
1312 | ||
1313 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1314 | case kWindowMsgGetRegion: | |
1315 | return wxShapedMacWindowGetRegion(window,param); | |
1316 | } | |
1317 | ||
1318 | return 0; | |
1319 | } | |
1925be65 | 1320 | |
45ff8005 | 1321 | #endif |
6a7e6411 | 1322 | // --------------------------------------------------------------------------- |
1925be65 | 1323 |