]>
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 | { | |
4dcf0afe | 236 | wxTheApp->m_macCurrentEvent = &rec ; |
ac2d1ca6 | 237 | wxWindow* focus = wxWindow::FindFocus() ; |
4ccc303a | 238 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) ) |
ac2d1ca6 SC |
239 | { |
240 | // was handled internally | |
241 | result = noErr ; | |
242 | } | |
7c091673 SC |
243 | } |
244 | break ; | |
245 | default : | |
246 | break ; | |
247 | } | |
248 | return result ; | |
249 | } | |
250 | ||
251 | #endif | |
252 | ||
253 | void wxTopLevelWindowMac::MacInstallEventHandler() | |
254 | { | |
255 | #if TARGET_CARBON | |
256 | if ( wxMacWindowEventHandlerUPP == NULL ) | |
257 | { | |
258 | wxMacWindowEventHandlerUPP = NewEventHandlerUPP( wxMacWindowEventHandler ) ; | |
259 | } | |
260 | ||
261 | static const EventTypeSpec eventList[] = | |
262 | { | |
263 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } | |
264 | } ; | |
265 | if ( m_macEventHandler ) | |
266 | { | |
267 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
268 | m_macEventHandler = NULL ; | |
269 | } | |
270 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), wxMacWindowEventHandlerUPP, WXSIZEOF(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
271 | #endif | |
272 | } | |
273 | ||
5f0b2f22 SC |
274 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
275 | const wxPoint& pos, | |
276 | const wxSize& size, | |
277 | long style, | |
278 | const wxString& name ) | |
279 | { | |
280 | SetName(name); | |
281 | m_windowStyle = style; | |
282 | m_isShown = FALSE; | |
283 | ||
284 | // create frame. | |
285 | ||
286 | Rect theBoundsRect; | |
287 | ||
288 | m_x = (int)pos.x; | |
289 | m_y = (int)pos.y; | |
290 | if ( m_y < 50 ) | |
291 | m_y = 50 ; | |
292 | if ( m_x < 20 ) | |
293 | m_x = 20 ; | |
294 | ||
295 | m_width = size.x; | |
296 | if (m_width == -1) | |
297 | m_width = 20; | |
298 | m_height = size.y; | |
299 | if (m_height == -1) | |
300 | m_height = 20; | |
301 | ||
302 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); | |
303 | ||
304 | // translate the window attributes in the appropriate window class and attributes | |
305 | ||
306 | WindowClass wclass = 0; | |
307 | WindowAttributes attr = kWindowNoAttributes ; | |
308 | ||
f5744893 | 309 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 310 | { |
f5744893 SC |
311 | if ( |
312 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || | |
313 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
314 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
315 | ) | |
5f0b2f22 | 316 | { |
f5744893 SC |
317 | wclass = kFloatingWindowClass ; |
318 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
319 | { | |
320 | attr |= kWindowSideTitlebarAttribute ; | |
321 | } | |
322 | } | |
323 | else | |
324 | { | |
325 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
326 | } |
327 | } | |
328 | else if ( HasFlag( wxCAPTION ) ) | |
329 | { | |
330 | if ( HasFlag( wxDIALOG_MODAL ) ) | |
331 | { | |
60fcb584 | 332 | wclass = kDocumentWindowClass ; // kMovableModalWindowClass ; |
5f0b2f22 SC |
333 | } |
334 | else | |
335 | { | |
336 | wclass = kDocumentWindowClass ; | |
337 | } | |
338 | } | |
339 | else | |
340 | { | |
f5744893 SC |
341 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
342 | HasFlag( wxSYSTEM_MENU ) ) | |
343 | { | |
344 | wclass = kDocumentWindowClass ; | |
345 | } | |
346 | else | |
347 | { | |
348 | wclass = kPlainWindowClass ; | |
349 | } | |
5f0b2f22 SC |
350 | } |
351 | ||
352 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) | |
353 | { | |
354 | attr |= kWindowFullZoomAttribute ; | |
355 | attr |= kWindowCollapseBoxAttribute ; | |
356 | } | |
357 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
358 | { | |
359 | attr |= kWindowResizableAttribute ; | |
360 | } | |
361 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
362 | { | |
363 | attr |= kWindowCloseBoxAttribute ; | |
364 | } | |
365 | ||
76a5e5d2 | 366 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
5f0b2f22 SC |
367 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
368 | wxString label ; | |
369 | if( wxApp::s_macDefaultEncodingIsPC ) | |
370 | label = wxMacMakeMacStringFromPC( title ) ; | |
371 | else | |
372 | label = title ; | |
76a5e5d2 SC |
373 | UMASetWTitleC( (WindowRef)m_macWindow , label ) ; |
374 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; | |
7c091673 | 375 | MacInstallEventHandler() ; |
5f0b2f22 SC |
376 | |
377 | m_macFocus = NULL ; | |
378 | } | |
379 | ||
76a5e5d2 | 380 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 381 | { |
76a5e5d2 SC |
382 | ((Point*)localOrigin)->h = 0; |
383 | ((Point*)localOrigin)->v = 0; | |
384 | ((Rect*)clipRect)->left = 0; | |
385 | ((Rect*)clipRect)->top = 0; | |
386 | ((Rect*)clipRect)->right = m_width; | |
387 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
388 | *window = m_macWindow ; |
389 | *rootwin = this ; | |
390 | } | |
391 | ||
392 | void wxTopLevelWindowMac::Clear() | |
393 | { | |
7d9d1fd7 | 394 | wxWindow::Clear() ; |
5f0b2f22 SC |
395 | } |
396 | ||
76a5e5d2 | 397 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
398 | { |
399 | return m_macRootControl ; | |
400 | } | |
401 | ||
402 | ||
403 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
404 | { | |
76a5e5d2 | 405 | |
66a09d47 | 406 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 SC |
407 | |
408 | BeginUpdate( (WindowRef)m_macWindow ) ; | |
5f0b2f22 SC |
409 | |
410 | RgnHandle updateRgn = NewRgn(); | |
411 | RgnHandle diffRgn = NewRgn() ; | |
412 | if ( updateRgn && diffRgn ) | |
413 | { | |
76a5e5d2 SC |
414 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
415 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
5f0b2f22 SC |
416 | if ( !EmptyRgn( updateRgn ) ) |
417 | { | |
418 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
419 | } | |
420 | } | |
421 | if ( updateRgn ) | |
422 | DisposeRgn( updateRgn ); | |
423 | if ( diffRgn ) | |
424 | DisposeRgn( diffRgn ); | |
76a5e5d2 SC |
425 | EndUpdate( (WindowRef)m_macWindow ) ; |
426 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
427 | m_macNeedsErasing = false ; |
428 | } | |
429 | ||
430 | ||
431 | // Raise the window to the top of the Z order | |
432 | void wxTopLevelWindowMac::Raise() | |
433 | { | |
76a5e5d2 | 434 | ::BringToFront( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
435 | } |
436 | ||
437 | // Lower the window to the bottom of the Z order | |
438 | void wxTopLevelWindowMac::Lower() | |
439 | { | |
76a5e5d2 | 440 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
441 | } |
442 | ||
76a5e5d2 | 443 | void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) |
5f0b2f22 | 444 | { |
76a5e5d2 | 445 | EventRecord *ev = (EventRecord*) evr ; |
5f0b2f22 SC |
446 | wxMouseEvent event(wxEVT_LEFT_DOWN); |
447 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
448 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
449 | ||
450 | event.m_leftDown = isDown && !controlDown; | |
451 | ||
452 | event.m_middleDown = FALSE; | |
453 | event.m_rightDown = isDown && controlDown; | |
454 | ||
455 | if ( ev->what == mouseDown ) | |
456 | { | |
457 | if ( controlDown ) | |
458 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
459 | else | |
460 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
461 | } | |
462 | else if ( ev->what == mouseUp ) | |
463 | { | |
464 | if ( controlDown ) | |
465 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
466 | else | |
467 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
468 | } | |
469 | else | |
470 | { | |
471 | event.SetEventType(wxEVT_MOTION ) ; | |
472 | } | |
473 | ||
474 | event.m_shiftDown = ev->modifiers & shiftKey; | |
475 | event.m_controlDown = ev->modifiers & controlKey; | |
476 | event.m_altDown = ev->modifiers & optionKey; | |
477 | event.m_metaDown = ev->modifiers & cmdKey; | |
478 | ||
479 | Point localwhere = ev->where ; | |
480 | ||
481 | GrafPtr port ; | |
482 | ::GetPort( &port ) ; | |
76a5e5d2 | 483 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
484 | ::GlobalToLocal( &localwhere ) ; |
485 | ::SetPort( port ) ; | |
486 | ||
487 | if ( ev->what == mouseDown ) | |
488 | { | |
32b5be3d | 489 | if ( ev->when - gs_lastWhen <= GetDblTime() ) |
5f0b2f22 | 490 | { |
32b5be3d | 491 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 492 | { |
32b5be3d RR |
493 | // This is not right if the second mouse down |
494 | // event occured in a differen window. We | |
495 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
496 | if ( controlDown ) |
497 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
498 | else | |
499 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
500 | } | |
32b5be3d | 501 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
502 | } |
503 | else | |
504 | { | |
32b5be3d | 505 | gs_lastWhen = ev->when ; |
5f0b2f22 | 506 | } |
32b5be3d | 507 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
508 | } |
509 | ||
510 | event.m_x = localwhere.h; | |
511 | event.m_y = localwhere.v; | |
512 | event.m_x += m_x; | |
513 | event.m_y += m_y; | |
514 | ||
5f0b2f22 SC |
515 | event.m_timeStamp = ev->when; |
516 | event.SetEventObject(this); | |
517 | if ( wxTheApp->s_captureWindow ) | |
518 | { | |
519 | int x = event.m_x ; | |
520 | int y = event.m_y ; | |
521 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
522 | event.m_x = x ; | |
523 | event.m_y = y ; | |
2e6857fa | 524 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 525 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
ed60b502 | 526 | |
5f0b2f22 SC |
527 | if ( ev->what == mouseUp ) |
528 | { | |
529 | wxTheApp->s_captureWindow = NULL ; | |
530 | if ( wxBusyCursorCount == 0 ) | |
531 | { | |
532 | m_cursor.MacInstall() ; | |
533 | } | |
534 | } | |
535 | } | |
536 | else | |
537 | { | |
538 | MacDispatchMouseEvent( event ) ; | |
539 | } | |
540 | } | |
541 | ||
76a5e5d2 | 542 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 SC |
543 | { |
544 | MacFireMouseEvent( ev ) ; | |
545 | } | |
546 | ||
76a5e5d2 | 547 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
548 | { |
549 | switch (part) | |
550 | { | |
551 | case inContent: | |
552 | { | |
553 | MacFireMouseEvent( ev ) ; | |
554 | } | |
555 | break ; | |
556 | } | |
557 | } | |
558 | ||
76a5e5d2 | 559 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
560 | { |
561 | switch (part) | |
562 | { | |
563 | case inContent: | |
564 | { | |
565 | MacFireMouseEvent( ev ) ; | |
566 | } | |
567 | break ; | |
568 | } | |
569 | } | |
76a5e5d2 | 570 | void wxTopLevelWindowMac::MacActivate( WXEVENTREF ev , bool inIsActivating ) |
5f0b2f22 SC |
571 | { |
572 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
76a5e5d2 | 573 | event.m_timeStamp = ((EventRecord*)ev)->when ; |
5f0b2f22 SC |
574 | event.SetEventObject(this); |
575 | ||
576 | GetEventHandler()->ProcessEvent(event); | |
577 | ||
76a5e5d2 | 578 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
5f0b2f22 | 579 | |
1c469f7f | 580 | MacSuperEnabled( inIsActivating ) ; |
5f0b2f22 SC |
581 | } |
582 | ||
76a5e5d2 | 583 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
584 | { |
585 | } | |
586 | ||
587 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
588 | { | |
589 | wxWindow::SetTitle( title ) ; | |
590 | ||
591 | wxString label ; | |
592 | ||
593 | if( wxApp::s_macDefaultEncodingIsPC ) | |
594 | label = wxMacMakeMacStringFromPC( m_label ) ; | |
595 | else | |
596 | label = m_label ; | |
597 | ||
76a5e5d2 | 598 | UMASetWTitleC( (WindowRef)m_macWindow , label ) ; |
5f0b2f22 SC |
599 | } |
600 | ||
601 | bool wxTopLevelWindowMac::Show(bool show) | |
602 | { | |
603 | if ( !wxWindow::Show(show) ) | |
604 | return FALSE; | |
605 | ||
606 | if (show) | |
607 | { | |
76a5e5d2 SC |
608 | ::ShowWindow( (WindowRef)m_macWindow ) ; |
609 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
5f0b2f22 SC |
610 | // no need to generate events here, they will get them triggered by macos |
611 | // actually they should be , but apparently they are not | |
612 | wxSize size(m_width, m_height); | |
613 | wxSizeEvent event(size, m_windowId); | |
614 | event.SetEventObject(this); | |
615 | GetEventHandler()->ProcessEvent(event); | |
616 | } | |
617 | else | |
618 | { | |
76a5e5d2 | 619 | ::HideWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
620 | } |
621 | ||
622 | if ( !show ) | |
623 | { | |
624 | } | |
625 | else | |
626 | { | |
627 | Refresh() ; | |
628 | } | |
629 | ||
630 | return TRUE; | |
631 | } | |
632 | ||
633 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
634 | { | |
635 | int former_x = m_x ; | |
636 | int former_y = m_y ; | |
637 | int former_w = m_width ; | |
638 | int former_h = m_height ; | |
639 | ||
640 | int actualWidth = width; | |
641 | int actualHeight = height; | |
642 | int actualX = x; | |
643 | int actualY = y; | |
644 | ||
645 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
646 | actualWidth = m_minWidth; | |
647 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) | |
648 | actualHeight = m_minHeight; | |
649 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) | |
650 | actualWidth = m_maxWidth; | |
651 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) | |
652 | actualHeight = m_maxHeight; | |
653 | ||
654 | bool doMove = false ; | |
655 | bool doResize = false ; | |
656 | ||
657 | if ( actualX != former_x || actualY != former_y ) | |
658 | { | |
659 | doMove = true ; | |
660 | } | |
661 | if ( actualWidth != former_w || actualHeight != former_h ) | |
662 | { | |
663 | doResize = true ; | |
664 | } | |
665 | ||
666 | if ( doMove || doResize ) | |
667 | { | |
668 | m_x = actualX ; | |
669 | m_y = actualY ; | |
670 | m_width = actualWidth ; | |
671 | m_height = actualHeight ; | |
672 | ||
673 | if ( doMove ) | |
76a5e5d2 | 674 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
5f0b2f22 SC |
675 | |
676 | if ( doResize ) | |
76a5e5d2 | 677 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
5f0b2f22 SC |
678 | |
679 | // the OS takes care of invalidating and erasing the new area | |
680 | // we have erased the old one | |
681 | ||
682 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) | |
683 | { | |
684 | wxFrame* frame = (wxFrame*) this ; | |
685 | frame->PositionStatusBar(); | |
686 | frame->PositionToolBar(); | |
687 | } | |
688 | if ( doMove ) | |
689 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
690 | ||
691 | MacRepositionScrollBars() ; | |
692 | if ( doMove ) | |
693 | { | |
694 | wxPoint point(m_x, m_y); | |
695 | wxMoveEvent event(point, m_windowId); | |
696 | event.SetEventObject(this); | |
697 | GetEventHandler()->ProcessEvent(event) ; | |
698 | } | |
699 | if ( doResize ) | |
700 | { | |
701 | MacRepositionScrollBars() ; | |
702 | wxSize size(m_width, m_height); | |
703 | wxSizeEvent event(size, m_windowId); | |
704 | event.SetEventObject(this); | |
705 | GetEventHandler()->ProcessEvent(event); | |
706 | } | |
707 | } | |
708 | ||
709 | } | |
710 | ||
711 | /* | |
712 | * Invalidation Mechanism | |
713 | * | |
714 | * The update mechanism reflects exactely the windows mechanism | |
715 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
716 | * has been true for any part of the update rgn the background is erased in the entire region | |
717 | * not just in the specified rect. | |
718 | * | |
719 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have | |
720 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event | |
721 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
722 | * will get the eraseBackground event first | |
723 | */ | |
724 | ||
76a5e5d2 | 725 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) |
5f0b2f22 SC |
726 | { |
727 | GrafPtr formerPort ; | |
728 | GetPort( &formerPort ) ; | |
76a5e5d2 | 729 | SetPortWindowPort( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
730 | |
731 | m_macNeedsErasing |= eraseBackground ; | |
732 | ||
733 | // if we already know that we will have to erase, there's no need to track the rest | |
734 | if ( !m_macNeedsErasing) | |
735 | { | |
736 | // we end only here if eraseBackground is false | |
737 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
738 | // we will have to erase anyway | |
739 | ||
740 | RgnHandle updateRgn = NewRgn(); | |
741 | RgnHandle diffRgn = NewRgn() ; | |
742 | if ( updateRgn && diffRgn ) | |
743 | { | |
76a5e5d2 | 744 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); |
5f0b2f22 SC |
745 | Point pt = {0,0} ; |
746 | LocalToGlobal( &pt ) ; | |
747 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
76a5e5d2 | 748 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
749 | if ( !EmptyRgn( diffRgn ) ) |
750 | { | |
751 | m_macNeedsErasing = true ; | |
752 | } | |
753 | } | |
754 | if ( updateRgn ) | |
755 | DisposeRgn( updateRgn ); | |
756 | if ( diffRgn ) | |
757 | DisposeRgn( diffRgn ); | |
758 | ||
759 | if ( !m_macNeedsErasing ) | |
760 | { | |
761 | RgnHandle rectRgn = NewRgn() ; | |
76a5e5d2 SC |
762 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; |
763 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
764 | DisposeRgn( rectRgn ) ; |
765 | } | |
766 | } | |
76a5e5d2 | 767 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
5f0b2f22 | 768 | // turn this on to debug the refreshing cycle |
34dc8f91 | 769 | #if wxMAC_DEBUG_REDRAW |
5f0b2f22 SC |
770 | PaintRect( rect ) ; |
771 | #endif | |
772 | SetPort( formerPort ) ; | |
773 | } | |
a07c1212 | 774 |