]>
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) | |
9 | // License: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "toplevel.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
38 | #endif //WX_PRECOMP | |
39 | ||
5f0b2f22 | 40 | #include "wx/mac/uma.h" |
422644a3 | 41 | #include "wx/mac/aga.h" |
7c091673 | 42 | #include "wx/app.h" |
5f0b2f22 | 43 | #include "wx/tooltip.h" |
a07c1212 | 44 | #include "wx/dnd.h" |
5f0b2f22 | 45 | |
34dc8f91 SC |
46 | #define wxMAC_DEBUG_REDRAW 0 |
47 | #ifndef wxMAC_DEBUG_REDRAW | |
48 | #define wxMAC_DEBUG_REDRAW 0 | |
49 | #endif | |
50 | ||
a15eb0a5 SC |
51 | // ---------------------------------------------------------------------------- |
52 | // globals | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | // list of all frames and modeless dialogs | |
32b5be3d RR |
56 | wxWindowList wxModelessWindows; |
57 | ||
58 | // double click testing | |
59 | static Point gs_lastWhere; | |
60 | static long gs_lastWhen = 0; | |
61 | ||
62 | // cursor stuff | |
63 | extern int wxBusyCursorCount; | |
64 | ||
a15eb0a5 SC |
65 | |
66 | // ============================================================================ | |
67 | // wxTopLevelWindowMac implementation | |
68 | // ============================================================================ | |
69 | ||
5f0b2f22 SC |
70 | // --------------------------------------------------------------------------- |
71 | // wxWindowMac utility functions | |
72 | // --------------------------------------------------------------------------- | |
73 | ||
74 | // Find an item given the Macintosh Window Reference | |
75 | ||
76 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 77 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 SC |
78 | { |
79 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
80 | if (!node) | |
81 | return NULL; | |
82 | return (wxTopLevelWindowMac *)node->Data(); | |
83 | } | |
84 | ||
76a5e5d2 | 85 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
86 | { |
87 | // adding NULL WindowRef is (first) surely a result of an error and | |
88 | // (secondly) breaks menu command processing | |
89 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" ); | |
90 | ||
91 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
92 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
93 | } | |
94 | ||
95 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
96 | { | |
97 | wxWinMacWindowList->DeleteObject(win); | |
98 | } | |
99 | ||
100 | ||
a15eb0a5 SC |
101 | // ---------------------------------------------------------------------------- |
102 | // wxTopLevelWindowMac creation | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
76a5e5d2 | 105 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
5f0b2f22 | 106 | |
a15eb0a5 SC |
107 | void wxTopLevelWindowMac::Init() |
108 | { | |
109 | m_iconized = | |
110 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
111 | m_macNoEraseUpdateRgn = NewRgn() ; |
112 | m_macNeedsErasing = false ; | |
6a17ca35 | 113 | m_macWindow = NULL ; |
7c091673 | 114 | m_macEventHandler = NULL ; |
a15eb0a5 SC |
115 | } |
116 | ||
118f012e SC |
117 | class wxMacDeferredWindowDeleter : public wxObject |
118 | { | |
119 | public : | |
120 | wxMacDeferredWindowDeleter( WindowRef windowRef ) | |
121 | { | |
122 | m_macWindow = windowRef ; | |
123 | } | |
124 | virtual ~wxMacDeferredWindowDeleter() | |
125 | { | |
126 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
127 | } | |
128 | protected : | |
129 | WindowRef m_macWindow ; | |
130 | } ; | |
131 | ||
a15eb0a5 SC |
132 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
133 | wxWindowID id, | |
134 | const wxString& title, | |
135 | const wxPoint& pos, | |
136 | const wxSize& size, | |
137 | long style, | |
138 | const wxString& name) | |
139 | { | |
140 | // init our fields | |
141 | Init(); | |
142 | ||
143 | m_windowStyle = style; | |
144 | ||
145 | SetName(name); | |
146 | ||
147 | m_windowId = id == -1 ? NewControlId() : id; | |
148 | ||
149 | wxTopLevelWindows.Append(this); | |
150 | ||
151 | if ( parent ) | |
152 | parent->AddChild(this); | |
153 | ||
154 | return TRUE; | |
155 | } | |
156 | ||
157 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
158 | { | |
6a17ca35 SC |
159 | if ( m_macWindow ) |
160 | { | |
161 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 162 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 163 | } |
7c091673 | 164 | |
f75363ee | 165 | #if TARGET_CARBON |
7c091673 SC |
166 | if ( m_macEventHandler ) |
167 | { | |
168 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
169 | m_macEventHandler = NULL ; | |
170 | } | |
171 | #endif | |
5f0b2f22 SC |
172 | wxRemoveMacWindowAssociation( this ) ; |
173 | ||
a15eb0a5 SC |
174 | if ( wxModelessWindows.Find(this) ) |
175 | wxModelessWindows.DeleteObject(this); | |
176 | ||
76a5e5d2 | 177 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
178 | } |
179 | ||
180 | ||
181 | // ---------------------------------------------------------------------------- | |
182 | // wxTopLevelWindowMac maximize/minimize | |
183 | // ---------------------------------------------------------------------------- | |
184 | ||
185 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
186 | { | |
187 | // not available on mac | |
188 | } | |
189 | ||
190 | bool wxTopLevelWindowMac::IsMaximized() const | |
191 | { | |
192 | return false ; | |
193 | } | |
194 | ||
195 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
196 | { | |
197 | // not available on mac | |
198 | } | |
199 | ||
200 | bool wxTopLevelWindowMac::IsIconized() const | |
201 | { | |
ed60b502 | 202 | // mac dialogs cannot be iconized |
a15eb0a5 SC |
203 | return FALSE; |
204 | } | |
205 | ||
206 | void wxTopLevelWindowMac::Restore() | |
207 | { | |
208 | // not available on mac | |
209 | } | |
210 | ||
211 | // ---------------------------------------------------------------------------- | |
212 | // wxTopLevelWindowMac misc | |
213 | // ---------------------------------------------------------------------------- | |
214 | ||
215 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
216 | { | |
217 | // this sets m_icon | |
218 | wxTopLevelWindowBase::SetIcon(icon); | |
219 | } | |
5f0b2f22 | 220 | |
7c091673 SC |
221 | #if TARGET_CARBON |
222 | ||
223 | EventHandlerUPP wxMacWindowEventHandlerUPP = NULL ; | |
224 | ||
ac2d1ca6 SC |
225 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
226 | ||
7c091673 SC |
227 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
228 | { | |
229 | OSStatus result = eventNotHandledErr ; | |
230 | EventRecord rec ; | |
231 | switch ( GetEventClass( event ) ) | |
232 | { | |
233 | case kEventClassTextInput : | |
234 | if ( wxMacConvertEventToRecord( event , &rec ) ) | |
235 | { | |
ac2d1ca6 | 236 | wxWindow* focus = wxWindow::FindFocus() ; |
4ccc303a | 237 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) ) |
ac2d1ca6 SC |
238 | { |
239 | // was handled internally | |
240 | result = noErr ; | |
241 | } | |
7c091673 SC |
242 | } |
243 | break ; | |
244 | default : | |
245 | break ; | |
246 | } | |
247 | return result ; | |
248 | } | |
249 | ||
250 | #endif | |
251 | ||
252 | void wxTopLevelWindowMac::MacInstallEventHandler() | |
253 | { | |
254 | #if TARGET_CARBON | |
255 | if ( wxMacWindowEventHandlerUPP == NULL ) | |
256 | { | |
257 | wxMacWindowEventHandlerUPP = NewEventHandlerUPP( wxMacWindowEventHandler ) ; | |
258 | } | |
259 | ||
260 | static const EventTypeSpec eventList[] = | |
261 | { | |
262 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } | |
263 | } ; | |
264 | if ( m_macEventHandler ) | |
265 | { | |
266 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
267 | m_macEventHandler = NULL ; | |
268 | } | |
269 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), wxMacWindowEventHandlerUPP, WXSIZEOF(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
270 | #endif | |
271 | } | |
272 | ||
5f0b2f22 SC |
273 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
274 | const wxPoint& pos, | |
275 | const wxSize& size, | |
276 | long style, | |
277 | const wxString& name ) | |
278 | { | |
279 | SetName(name); | |
280 | m_windowStyle = style; | |
281 | m_isShown = FALSE; | |
282 | ||
283 | // create frame. | |
284 | ||
285 | Rect theBoundsRect; | |
286 | ||
287 | m_x = (int)pos.x; | |
288 | m_y = (int)pos.y; | |
289 | if ( m_y < 50 ) | |
290 | m_y = 50 ; | |
291 | if ( m_x < 20 ) | |
292 | m_x = 20 ; | |
293 | ||
294 | m_width = size.x; | |
295 | if (m_width == -1) | |
296 | m_width = 20; | |
297 | m_height = size.y; | |
298 | if (m_height == -1) | |
299 | m_height = 20; | |
300 | ||
301 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); | |
302 | ||
303 | // translate the window attributes in the appropriate window class and attributes | |
304 | ||
305 | WindowClass wclass = 0; | |
306 | WindowAttributes attr = kWindowNoAttributes ; | |
307 | ||
f5744893 | 308 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 309 | { |
f5744893 SC |
310 | if ( |
311 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
312 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
313 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
314 | ) | |
5f0b2f22 | 315 | { |
f5744893 SC |
316 | wclass = kFloatingWindowClass ; |
317 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
318 | { | |
319 | attr |= kWindowSideTitlebarAttribute ; | |
320 | } | |
321 | } | |
322 | else | |
323 | { | |
324 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
325 | } |
326 | } | |
327 | else if ( HasFlag( wxCAPTION ) ) | |
328 | { | |
329 | if ( HasFlag( wxDIALOG_MODAL ) ) | |
330 | { | |
60fcb584 | 331 | wclass = kDocumentWindowClass ; // kMovableModalWindowClass ; |
5f0b2f22 SC |
332 | } |
333 | else | |
334 | { | |
335 | wclass = kDocumentWindowClass ; | |
336 | } | |
337 | } | |
338 | else | |
339 | { | |
f5744893 SC |
340 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
341 | HasFlag( wxSYSTEM_MENU ) ) | |
342 | { | |
343 | wclass = kDocumentWindowClass ; | |
344 | } | |
345 | else | |
346 | { | |
347 | wclass = kPlainWindowClass ; | |
348 | } | |
5f0b2f22 SC |
349 | } |
350 | ||
351 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) | |
352 | { | |
353 | attr |= kWindowFullZoomAttribute ; | |
354 | attr |= kWindowCollapseBoxAttribute ; | |
355 | } | |
356 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
357 | { | |
358 | attr |= kWindowResizableAttribute ; | |
359 | } | |
360 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
361 | { | |
362 | attr |= kWindowCloseBoxAttribute ; | |
363 | } | |
364 | ||
76a5e5d2 | 365 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
5f0b2f22 SC |
366 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
367 | wxString label ; | |
368 | if( wxApp::s_macDefaultEncodingIsPC ) | |
369 | label = wxMacMakeMacStringFromPC( title ) ; | |
370 | else | |
371 | label = title ; | |
76a5e5d2 SC |
372 | UMASetWTitleC( (WindowRef)m_macWindow , label ) ; |
373 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; | |
7c091673 | 374 | MacInstallEventHandler() ; |
5f0b2f22 SC |
375 | |
376 | m_macFocus = NULL ; | |
377 | } | |
378 | ||
76a5e5d2 | 379 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 380 | { |
76a5e5d2 SC |
381 | ((Point*)localOrigin)->h = 0; |
382 | ((Point*)localOrigin)->v = 0; | |
383 | ((Rect*)clipRect)->left = 0; | |
384 | ((Rect*)clipRect)->top = 0; | |
385 | ((Rect*)clipRect)->right = m_width; | |
386 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
387 | *window = m_macWindow ; |
388 | *rootwin = this ; | |
389 | } | |
390 | ||
391 | void wxTopLevelWindowMac::Clear() | |
392 | { | |
7d9d1fd7 | 393 | wxWindow::Clear() ; |
5f0b2f22 SC |
394 | } |
395 | ||
76a5e5d2 | 396 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
397 | { |
398 | return m_macRootControl ; | |
399 | } | |
400 | ||
401 | ||
402 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
403 | { | |
76a5e5d2 | 404 | |
66a09d47 | 405 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 SC |
406 | |
407 | BeginUpdate( (WindowRef)m_macWindow ) ; | |
5f0b2f22 SC |
408 | |
409 | RgnHandle updateRgn = NewRgn(); | |
410 | RgnHandle diffRgn = NewRgn() ; | |
411 | if ( updateRgn && diffRgn ) | |
412 | { | |
76a5e5d2 SC |
413 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
414 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
5f0b2f22 SC |
415 | if ( !EmptyRgn( updateRgn ) ) |
416 | { | |
417 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
418 | } | |
419 | } | |
420 | if ( updateRgn ) | |
421 | DisposeRgn( updateRgn ); | |
422 | if ( diffRgn ) | |
423 | DisposeRgn( diffRgn ); | |
76a5e5d2 SC |
424 | EndUpdate( (WindowRef)m_macWindow ) ; |
425 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
426 | m_macNeedsErasing = false ; |
427 | } | |
428 | ||
429 | ||
430 | // Raise the window to the top of the Z order | |
431 | void wxTopLevelWindowMac::Raise() | |
432 | { | |
76a5e5d2 | 433 | ::BringToFront( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
434 | } |
435 | ||
436 | // Lower the window to the bottom of the Z order | |
437 | void wxTopLevelWindowMac::Lower() | |
438 | { | |
76a5e5d2 | 439 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
440 | } |
441 | ||
76a5e5d2 | 442 | void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) |
5f0b2f22 | 443 | { |
76a5e5d2 | 444 | EventRecord *ev = (EventRecord*) evr ; |
5f0b2f22 SC |
445 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
446 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
447 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
448 | ||
449 | event.m_leftDown = isDown && !controlDown; | |
450 | ||
451 | event.m_middleDown = FALSE; | |
452 | event.m_rightDown = isDown && controlDown; | |
453 | ||
454 | if ( ev->what == mouseDown ) | |
455 | { | |
456 | if ( controlDown ) | |
457 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
458 | else | |
459 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
460 | } | |
461 | else if ( ev->what == mouseUp ) | |
462 | { | |
463 | if ( controlDown ) | |
464 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
465 | else | |
466 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
467 | } | |
468 | else | |
469 | { | |
470 | event.SetEventType(wxEVT_MOTION ) ; | |
471 | } | |
472 | ||
473 | event.m_shiftDown = ev->modifiers & shiftKey; | |
474 | event.m_controlDown = ev->modifiers & controlKey; | |
475 | event.m_altDown = ev->modifiers & optionKey; | |
476 | event.m_metaDown = ev->modifiers & cmdKey; | |
477 | ||
478 | Point localwhere = ev->where ; | |
479 | ||
480 | GrafPtr port ; | |
481 | ::GetPort( &port ) ; | |
76a5e5d2 | 482 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
483 | ::GlobalToLocal( &localwhere ) ; |
484 | ::SetPort( port ) ; | |
485 | ||
486 | if ( ev->what == mouseDown ) | |
487 | { | |
32b5be3d | 488 | if ( ev->when - gs_lastWhen <= GetDblTime() ) |
5f0b2f22 | 489 | { |
32b5be3d | 490 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 491 | { |
32b5be3d RR |
492 | // This is not right if the second mouse down |
493 | // event occured in a differen window. We | |
494 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
495 | if ( controlDown ) |
496 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
497 | else | |
498 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
499 | } | |
32b5be3d | 500 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
501 | } |
502 | else | |
503 | { | |
32b5be3d | 504 | gs_lastWhen = ev->when ; |
5f0b2f22 | 505 | } |
32b5be3d | 506 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
507 | } |
508 | ||
509 | event.m_x = localwhere.h; | |
510 | event.m_y = localwhere.v; | |
511 | event.m_x += m_x; | |
512 | event.m_y += m_y; | |
513 | ||
5f0b2f22 SC |
514 | event.m_timeStamp = ev->when; |
515 | event.SetEventObject(this); | |
516 | if ( wxTheApp->s_captureWindow ) | |
517 | { | |
518 | int x = event.m_x ; | |
519 | int y = event.m_y ; | |
520 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
521 | event.m_x = x ; | |
522 | event.m_y = y ; | |
2e6857fa | 523 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 524 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
ed60b502 | 525 | |
5f0b2f22 SC |
526 | if ( ev->what == mouseUp ) |
527 | { | |
528 | wxTheApp->s_captureWindow = NULL ; | |
529 | if ( wxBusyCursorCount == 0 ) | |
530 | { | |
531 | m_cursor.MacInstall() ; | |
532 | } | |
533 | } | |
534 | } | |
535 | else | |
536 | { | |
537 | MacDispatchMouseEvent( event ) ; | |
538 | } | |
539 | } | |
540 | ||
76a5e5d2 | 541 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 SC |
542 | { |
543 | MacFireMouseEvent( ev ) ; | |
544 | } | |
545 | ||
76a5e5d2 | 546 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
547 | { |
548 | switch (part) | |
549 | { | |
550 | case inContent: | |
551 | { | |
552 | MacFireMouseEvent( ev ) ; | |
553 | } | |
554 | break ; | |
555 | } | |
556 | } | |
557 | ||
76a5e5d2 | 558 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
559 | { |
560 | switch (part) | |
561 | { | |
562 | case inContent: | |
563 | { | |
564 | MacFireMouseEvent( ev ) ; | |
565 | } | |
566 | break ; | |
567 | } | |
568 | } | |
76a5e5d2 | 569 | void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating ) |
5f0b2f22 SC |
570 | { |
571 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
76a5e5d2 | 572 | event.m_timeStamp = ((EventRecord*)ev)->when ; |
5f0b2f22 SC |
573 | event.SetEventObject(this); |
574 | ||
575 | GetEventHandler()->ProcessEvent(event); | |
576 | ||
76a5e5d2 | 577 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
5f0b2f22 | 578 | |
1c469f7f | 579 | MacSuperEnabled( inIsActivating ) ; |
5f0b2f22 SC |
580 | } |
581 | ||
76a5e5d2 | 582 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
583 | { |
584 | } | |
585 | ||
586 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
587 | { | |
588 | wxWindow::SetTitle( title ) ; | |
589 | ||
590 | wxString label ; | |
591 | ||
592 | if( wxApp::s_macDefaultEncodingIsPC ) | |
593 | label = wxMacMakeMacStringFromPC( m_label ) ; | |
594 | else | |
595 | label = m_label ; | |
596 | ||
76a5e5d2 | 597 | UMASetWTitleC( (WindowRef)m_macWindow , label ) ; |
5f0b2f22 SC |
598 | } |
599 | ||
600 | bool wxTopLevelWindowMac::Show(bool show) | |
601 | { | |
602 | if ( !wxWindow::Show(show) ) | |
603 | return FALSE; | |
604 | ||
605 | if (show) | |
606 | { | |
76a5e5d2 SC |
607 | ::ShowWindow( (WindowRef)m_macWindow ) ; |
608 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
5f0b2f22 SC |
609 | // no need to generate events here, they will get them triggered by macos |
610 | // actually they should be , but apparently they are not | |
611 | wxSize size(m_width, m_height); | |
612 | wxSizeEvent event(size, m_windowId); | |
613 | event.SetEventObject(this); | |
614 | GetEventHandler()->ProcessEvent(event); | |
615 | } | |
616 | else | |
617 | { | |
76a5e5d2 | 618 | ::HideWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
619 | } |
620 | ||
621 | if ( !show ) | |
622 | { | |
623 | } | |
624 | else | |
625 | { | |
626 | Refresh() ; | |
627 | } | |
628 | ||
629 | return TRUE; | |
630 | } | |
631 | ||
632 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
633 | { | |
634 | int former_x = m_x ; | |
635 | int former_y = m_y ; | |
636 | int former_w = m_width ; | |
637 | int former_h = m_height ; | |
638 | ||
639 | int actualWidth = width; | |
640 | int actualHeight = height; | |
641 | int actualX = x; | |
642 | int actualY = y; | |
643 | ||
644 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
645 | actualWidth = m_minWidth; | |
646 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
647 | actualHeight = m_minHeight; | |
648 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
649 | actualWidth = m_maxWidth; | |
650 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
651 | actualHeight = m_maxHeight; | |
652 | ||
653 | bool doMove = false ; | |
654 | bool doResize = false ; | |
655 | ||
656 | if ( actualX != former_x || actualY != former_y ) | |
657 | { | |
658 | doMove = true ; | |
659 | } | |
660 | if ( actualWidth != former_w || actualHeight != former_h ) | |
661 | { | |
662 | doResize = true ; | |
663 | } | |
664 | ||
665 | if ( doMove || doResize ) | |
666 | { | |
667 | m_x = actualX ; | |
668 | m_y = actualY ; | |
669 | m_width = actualWidth ; | |
670 | m_height = actualHeight ; | |
671 | ||
672 | if ( doMove ) | |
76a5e5d2 | 673 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
5f0b2f22 SC |
674 | |
675 | if ( doResize ) | |
76a5e5d2 | 676 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
5f0b2f22 SC |
677 | |
678 | // the OS takes care of invalidating and erasing the new area | |
679 | // we have erased the old one | |
680 | ||
681 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) | |
682 | { | |
683 | wxFrame* frame = (wxFrame*) this ; | |
684 | frame->PositionStatusBar(); | |
685 | frame->PositionToolBar(); | |
686 | } | |
687 | if ( doMove ) | |
688 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
689 | ||
690 | MacRepositionScrollBars() ; | |
691 | if ( doMove ) | |
692 | { | |
693 | wxPoint point(m_x, m_y); | |
694 | wxMoveEvent event(point, m_windowId); | |
695 | event.SetEventObject(this); | |
696 | GetEventHandler()->ProcessEvent(event) ; | |
697 | } | |
698 | if ( doResize ) | |
699 | { | |
700 | MacRepositionScrollBars() ; | |
701 | wxSize size(m_width, m_height); | |
702 | wxSizeEvent event(size, m_windowId); | |
703 | event.SetEventObject(this); | |
704 | GetEventHandler()->ProcessEvent(event); | |
705 | } | |
706 | } | |
707 | ||
708 | } | |
709 | ||
710 | /* | |
711 | * Invalidation Mechanism | |
712 | * | |
713 | * The update mechanism reflects exactely the windows mechanism | |
714 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
715 | * has been true for any part of the update rgn the background is erased in the entire region | |
716 | * not just in the specified rect. | |
717 | * | |
718 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have | |
719 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event | |
720 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
721 | * will get the eraseBackground event first | |
722 | */ | |
723 | ||
76a5e5d2 | 724 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) |
5f0b2f22 SC |
725 | { |
726 | GrafPtr formerPort ; | |
727 | GetPort( &formerPort ) ; | |
76a5e5d2 | 728 | SetPortWindowPort( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
729 | |
730 | m_macNeedsErasing |= eraseBackground ; | |
731 | ||
732 | // if we already know that we will have to erase, there's no need to track the rest | |
733 | if ( !m_macNeedsErasing) | |
734 | { | |
735 | // we end only here if eraseBackground is false | |
736 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
737 | // we will have to erase anyway | |
738 | ||
739 | RgnHandle updateRgn = NewRgn(); | |
740 | RgnHandle diffRgn = NewRgn() ; | |
741 | if ( updateRgn && diffRgn ) | |
742 | { | |
76a5e5d2 | 743 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); |
5f0b2f22 SC |
744 | Point pt = {0,0} ; |
745 | LocalToGlobal( &pt ) ; | |
746 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
76a5e5d2 | 747 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
748 | if ( !EmptyRgn( diffRgn ) ) |
749 | { | |
750 | m_macNeedsErasing = true ; | |
751 | } | |
752 | } | |
753 | if ( updateRgn ) | |
754 | DisposeRgn( updateRgn ); | |
755 | if ( diffRgn ) | |
756 | DisposeRgn( diffRgn ); | |
757 | ||
758 | if ( !m_macNeedsErasing ) | |
759 | { | |
760 | RgnHandle rectRgn = NewRgn() ; | |
76a5e5d2 SC |
761 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; |
762 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
763 | DisposeRgn( rectRgn ) ; |
764 | } | |
765 | } | |
76a5e5d2 | 766 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
5f0b2f22 | 767 | // turn this on to debug the refreshing cycle |
34dc8f91 | 768 | #if wxMAC_DEBUG_REDRAW |
5f0b2f22 SC |
769 | PaintRect( rect ) ; |
770 | #endif | |
771 | SetPort( formerPort ) ; | |
772 | } | |
a07c1212 | 773 |