1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/module.h"
30 #include "wx/memory.h"
32 #if wxUSE_WX_RESOURCES
33 #include "wx/resource.h"
46 #include <wx/mac/uma.h>
48 extern char *wxBuffer
;
49 extern wxList wxPendingDelete
;
50 extern wxList
*wxWinMacWindowList
;
51 extern wxList
*wxWinMacControlList
;
53 extern wxApp
*wxTheApp
;
55 #if !USE_SHARED_LIBRARY
56 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
57 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
58 EVT_IDLE(wxApp::OnIdle
)
63 const short kMacMinHeap
= (29 * 1024) ;
64 // platform specific static variables
66 const short kwxMacMenuBarResource
= 1 ;
67 const short kwxMacAppleMenuId
= 1 ;
69 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
70 wxWindow
* wxApp::s_captureWindow
= NULL
;
71 int wxApp::s_lastMouseDown
= 0 ;
72 long wxApp::sm_lastMessageTime
= 0;
76 bool wxApp::s_macDefaultEncodingIsPC
= true ;
77 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
78 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
79 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
81 OSErr
AEHandleODoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
83 wxApp
* app
= (wxApp
*) refcon
;
84 return wxTheApp
->MacHandleAEODoc( event
, reply
) ;
87 OSErr
AEHandleOApp( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
89 wxApp
* app
= (wxApp
*) refcon
;
90 return wxTheApp
->MacHandleAEOApp( event
, reply
) ;
93 OSErr
AEHandlePDoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
95 wxApp
* app
= (wxApp
*) refcon
;
96 return wxTheApp
->MacHandleAEPDoc( event
, reply
) ;
99 OSErr
AEHandleQuit( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
101 wxApp
* app
= (wxApp
*) refcon
;
102 return wxTheApp
->MacHandleAEQuit( event
, reply
) ;
105 OSErr
wxApp::MacHandleAEODoc(AppleEvent
*event
, AppleEvent
*reply
)
107 ProcessSerialNumber PSN
;
108 PSN
.highLongOfPSN
= 0 ;
109 PSN
.lowLongOfPSN
= kCurrentProcess
;
110 SetFrontProcess( &PSN
) ;
114 OSErr
wxApp::MacHandleAEPDoc(AppleEvent
*event
, AppleEvent
*reply
)
119 OSErr
wxApp::MacHandleAEOApp(AppleEvent
*event
, AppleEvent
*reply
)
124 OSErr
wxApp::MacHandleAEQuit(AppleEvent
*event
, AppleEvent
*reply
)
126 wxWindow
* win
= GetTopWindow() ;
138 char StringMac
[] = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
139 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
140 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
141 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
142 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
143 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
145 char StringANSI
[] = "\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
146 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
147 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
148 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
149 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
150 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
152 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
157 for( int i
= 0 ; i
< len
; ++ i
)
159 c
= strchr( StringANSI
, *from
) ;
162 *to
= StringMac
[ c
- StringANSI
] ;
170 for( int i
= 0 ; i
< len
; ++ i
)
172 c
= strchr( StringANSI
, *from
) ;
175 *to
= StringMac
[ c
- StringANSI
] ;
187 void wxMacConvertToPC( const char *from
, char *to
, int len
)
192 for( int i
= 0 ; i
< len
; ++ i
)
194 c
= strchr( StringMac
, *from
) ;
197 *to
= StringANSI
[ c
- StringMac
] ;
205 for( int i
= 0 ; i
< len
; ++ i
)
207 c
= strchr( StringMac
, *from
) ;
210 *to
= StringANSI
[ c
- StringMac
] ;
222 void wxMacConvertFromPC( char * p
)
225 int len
= strlen ( p
) ;
227 wxMacConvertFromPC( ptr
, ptr
, len
) ;
230 void wxMacConvertFromPCForControls( char * p
)
233 int len
= strlen ( p
) ;
235 wxMacConvertFromPC( ptr
, ptr
, len
) ;
236 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
238 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
240 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
245 void wxMacConvertFromPC( unsigned char *p
)
247 char *ptr
= (char*) p
+ 1 ;
250 wxMacConvertFromPC( ptr
, ptr
, len
) ;
253 extern char *wxBuffer
;
255 wxString
wxMacMakeMacStringFromPC( const char * p
)
257 const char *ptr
= p
;
258 int len
= strlen ( p
) ;
259 char *buf
= wxBuffer
;
261 if ( len
>= BUFSIZ
+ 512 )
263 buf
= new char [len
+1] ;
266 wxMacConvertFromPC( ptr
, buf
, len
) ;
268 wxString
result( buf
) ;
269 if ( buf
!= wxBuffer
)
275 void wxMacConvertToPC( char * p
)
278 int len
= strlen ( p
) ;
280 wxMacConvertToPC( ptr
, ptr
, len
) ;
283 void wxMacConvertToPC( unsigned char *p
)
285 char *ptr
= (char*) p
+ 1 ;
288 wxMacConvertToPC( ptr
, ptr
, len
) ;
291 wxString
wxMacMakePCStringFromMac( const char * p
)
293 const char *ptr
= p
;
294 int len
= strlen ( p
) ;
295 char *buf
= wxBuffer
;
297 if ( len
>= BUFSIZ
+ 512 )
299 buf
= new char [len
+1] ;
302 wxMacConvertToPC( ptr
, buf
, len
) ;
305 wxString
result( buf
) ;
306 if ( buf
!= wxBuffer
)
313 bool wxApp::Initialize()
319 UMAInitToolbox( 4 ) ;
320 UMAShowWatchCursor() ;
322 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) , (long) wxTheApp
, FALSE
) ;
323 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) , (long) wxTheApp
, FALSE
) ;
324 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) , (long) wxTheApp
, FALSE
) ;
325 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) , (long) wxTheApp
, FALSE
) ;
327 GUSISetup(GUSIwithInternetSockets
);
331 // test the minimal configuration necessary
336 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
338 error
= kMacSTRWrongMachine
;
340 else if (theMachine
< gestaltMacPlus
)
342 error
= kMacSTRWrongMachine
;
344 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
346 error
= kMacSTROldSystem
;
348 else if ( theSystem
< 0x0750 )
350 error
= kMacSTROldSystem
;
353 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
355 error
= kMacSTRSmallSize
;
361 if ( !UMAHasAppearance() )
363 error = kMacSTRNoPre8Yet ;
368 // if we encountered any problems so far, give the error code and exit immediately
375 GetIndString(message
, 128, error
);
376 UMAShowArrowCursor() ;
377 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
378 itemHit
= Alert(128, nil
);
382 #if __option(profile)
383 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 30 ) ;
386 // now avoid exceptions thrown for new (bad_alloc)
388 std::__throws_bad_alloc
= FALSE
;
390 s_macCursorRgn
= ::NewRgn() ;
393 wxBuffer
= new char[1500];
395 wxBuffer
= new char[BUFSIZ
+ 512];
399 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
401 streambuf* sBuf = new wxDebugStreamBuf;
402 ostream* oStr = new ostream(sBuf) ;
403 wxDebugContext::SetStream(oStr, sBuf);
407 wxClassInfo::InitializeClasses();
409 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
410 wxTheColourDatabase
->Initialize();
412 wxInitializeStockLists();
413 wxInitializeStockObjects();
415 #if wxUSE_WX_RESOURCES
416 wxInitializeResourceSystem();
419 wxBitmap::InitStandardHandlers();
421 wxModule::RegisterModules();
422 if (!wxModule::InitializeModules())
425 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
426 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
428 UMAShowArrowCursor() ;
433 void wxApp::CleanUp()
435 wxModule::CleanUpModules();
437 #if wxUSE_WX_RESOURCES
438 wxCleanUpResourceSystem();
441 wxDeleteStockObjects() ;
443 // Destroy all GDI lists, etc.
445 delete wxTheBrushList
;
446 wxTheBrushList
= NULL
;
451 delete wxTheFontList
;
452 wxTheFontList
= NULL
;
454 delete wxTheBitmapList
;
455 wxTheBitmapList
= NULL
;
457 delete wxTheColourDatabase
;
458 wxTheColourDatabase
= NULL
;
460 wxBitmap::CleanUpHandlers();
465 if (wxWinMacWindowList
)
466 delete wxWinMacWindowList
;
468 wxClassInfo::CleanUpClasses();
470 #if __option(profile)
471 ProfilerDump( "\papp.prof" ) ;
478 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
479 // At this point we want to check if there are any memory
480 // blocks that aren't part of the wxDebugContext itself,
481 // as a special case. Then when dumping we need to ignore
482 // wxDebugContext, too.
483 if (wxDebugContext::CountObjectsLeft() > 0)
485 wxTrace("There were memory leaks.\n");
486 wxDebugContext::Dump();
487 wxDebugContext::PrintStatistics();
489 // wxDebugContext::SetStream(NULL, NULL);
492 // do it as the very last thing because everything else can log messages
493 wxLog::DontCreateOnDemand();
494 // do it as the very last thing because everything else can log messages
495 delete wxLog::SetActiveTarget(NULL
);
499 ::DisposeRgn(s_macCursorRgn
);
505 int wxEntry( int argc
, char *argv
[] )
507 if (!wxApp::Initialize())
511 if (!wxApp::GetInitializerFunction())
513 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
517 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
522 printf( "wxWindows error: wxTheApp == NULL\n" );
527 argc
= 1 ; // currently we don't support files as parameters
530 wxTheApp
->argc
= argc
;
531 wxTheApp
->argv
= argv
;
533 // GUI-specific initialization, such as creating an app context.
534 wxTheApp
->OnInitGui();
536 // we could try to get the open apple events here to adjust argc and argv better
539 // Here frames insert themselves automatically
540 // into wxTopLevelWindows by getting created
543 if (!wxTheApp
->OnInit()) return 0;
547 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
549 if (wxTheApp
->GetTopWindow())
551 delete wxTheApp
->GetTopWindow();
552 wxTheApp
->SetTopWindow(NULL
);
555 wxTheApp
->DeletePendingObjects();
564 // Static member initialization
565 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
572 m_wantDebugOutput
= TRUE
;
577 m_printMode
= wxPRINT_WINDOWS
;
579 m_exitOnFrameDelete
= TRUE
;
583 bool wxApp::Initialized()
591 int wxApp::MainLoop()
603 // Returns TRUE if more time is needed.
604 bool wxApp::ProcessIdle()
607 event
.SetEventObject(this);
610 return event
.MoreRequested();
613 void wxApp::ExitMainLoop()
618 // Is a message/event pending?
619 bool wxApp::Pending()
623 return EventAvail( everyEvent
, &event
) ;
626 // Dispatch a message.
627 void wxApp::Dispatch()
632 void wxApp::OnIdle(wxIdleEvent
& event
)
634 static bool inOnIdle
= FALSE
;
636 // Avoid recursion (via ProcessEvent default case)
642 // 'Garbage' collection of windows deleted with Close().
643 DeletePendingObjects();
645 // flush the logged messages if any
646 wxLog
*pLog
= wxLog::GetActiveTarget();
647 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
650 // Send OnIdle events to all windows
651 bool needMore
= SendIdleEvents();
654 event
.RequestMore(TRUE
);
659 // Send idle event to all top-level windows
660 bool wxApp::SendIdleEvents()
662 bool needMore
= FALSE
;
663 wxNode
* node
= wxTopLevelWindows
.First();
666 wxWindow
* win
= (wxWindow
*) node
->Data();
667 if (SendIdleEvents(win
))
675 // Send idle event to window and all subwindows
676 bool wxApp::SendIdleEvents(wxWindow
* win
)
678 bool needMore
= FALSE
;
681 event
.SetEventObject(win
);
682 win
->ProcessEvent(event
);
684 if (event
.MoreRequested())
687 wxNode
* node
= win
->GetChildren().First();
690 wxWindow
* win
= (wxWindow
*) node
->Data();
691 if (SendIdleEvents(win
))
699 void wxApp::DeletePendingObjects()
701 wxNode
*node
= wxPendingDelete
.First();
704 wxObject
*obj
= (wxObject
*)node
->Data();
708 if (wxPendingDelete
.Member(obj
))
711 // Deleting one object may have deleted other pending
712 // objects, so start from beginning of list again.
713 node
= wxPendingDelete
.First();
717 wxLog
* wxApp::CreateLogTarget()
722 wxWindow
* wxApp::GetTopWindow() const
726 else if (wxTopLevelWindows
.Number() > 0)
727 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
738 // Yield to other processes
741 // YieldToAnyThread() ;
746 // platform specifics
748 void wxApp::MacSuspend( bool convertClipboard
)
750 s_lastMouseDown
= 0 ;
751 if( convertClipboard
)
753 MacConvertPrivateToPublicScrap() ;
756 UMAHideFloatingWindows() ;
759 void wxApp::MacResume( bool convertClipboard
)
761 s_lastMouseDown
= 0 ;
762 if( convertClipboard
)
764 MacConvertPublicToPrivateScrap() ;
767 UMAShowFloatingWindows() ;
770 void wxApp::MacConvertPrivateToPublicScrap()
776 void wxApp::MacConvertPublicToPrivateScrap()
781 void wxApp::MacDoOneEvent()
785 long sleepTime
= ::GetCaretTime();
787 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
789 MacHandleOneEvent( &event
);
794 WindowPtr window
= UMAFrontWindow() ;
796 UMAIdleControls( window
) ;
798 wxTheApp
->ProcessIdle() ;
800 if ( event
.what
!= kHighLevelEvent
)
801 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
806 wxMacProcessSocketEvents() ;
810 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
812 m_macCurrentEvent
= ev
;
814 wxApp::sm_lastMessageTime
= ev
->when
;
819 MacHandleMouseDownEvent( ev
) ;
820 if ( ev
->modifiers
& controlKey
)
826 if ( s_lastMouseDown
== 2 )
828 ev
->modifiers
|= controlKey
;
832 ev
->modifiers
&= ~controlKey
;
834 MacHandleMouseUpEvent( ev
) ;
838 MacHandleActivateEvent( ev
) ;
841 MacHandleUpdateEvent( ev
) ;
845 MacHandleKeyDownEvent( ev
) ;
848 MacHandleKeyUpEvent( ev
) ;
851 MacHandleDiskEvent( ev
) ;
854 MacHandleOSEvent( ev
) ;
856 case kHighLevelEvent
:
857 MacHandleHighLevelEvent( ev
) ;
864 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
866 ::AEProcessAppleEvent( ev
) ;
869 bool s_macIsInModalLoop
= false ;
871 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
874 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
875 WindowAttributes frontWindowAttributes
= NULL
;
877 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
879 short windowPart
= ::FindWindow(ev
->where
, &window
);
880 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
885 if ( s_macIsInModalLoop
)
891 UInt32 menuresult
= MenuSelect(ev
->where
) ;
892 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
897 SystemClick( ev
, window
) ;
901 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
907 DragWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
912 Point pt
= { 0, 0 } ;
915 LocalToGlobal( &pt
) ;
917 win
->SetSize( pt
.h
, pt
.v
, -1 ,
918 -1 , wxSIZE_USE_EXISTING
);
924 if (TrackGoAway(window
, ev
->where
))
932 int growResult
= GrowWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
935 int newWidth
= LoWord(growResult
);
936 int newHeight
= HiWord(growResult
);
937 int oldWidth
, oldHeight
;
939 win
->GetSize(&oldWidth
, &oldHeight
);
943 newHeight
= oldHeight
;
946 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
952 if (TrackBox(window
, ev
->where
, windowPart
))
954 // TODO setup size event
955 ZoomWindow( window
, windowPart
, false ) ;
957 win
->SetSize( -1, -1, window
->portRect
.right
-window
->portRect
.left
,
958 window
->portRect
.bottom
-window
->portRect
.top
, wxSIZE_USE_EXISTING
);
963 // TODO setup size event
968 if ( window
!= frontWindow
)
970 if ( s_macIsInModalLoop
)
974 else if ( UMAIsWindowFloating( window
) )
977 win
->MacMouseDown( ev
, windowPart
) ;
981 UMASelectWindow( window
) ;
987 win
->MacMouseDown( ev
, windowPart
) ;
996 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1000 short windowPart
= ::FindWindow(ev
->where
, &window
);
1010 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1012 win
->MacMouseUp( ev
, windowPart
) ;
1018 long wxMacTranslateKey(char key
, char code
)
1123 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1125 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1126 if ( HiWord( menuresult
) )
1127 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1132 keychar
= short(ev
->message
& charCodeMask
);
1133 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1135 wxWindow
* focus
= wxWindow::FindFocus() ;
1138 wxKeyEvent
event(wxEVT_CHAR
);
1139 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1140 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1141 event
.m_altDown
= ev
->modifiers
& optionKey
;
1142 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1143 event
.m_keyCode
= wxMacTranslateKey(keychar
, keycode
);
1144 event
.m_x
= ev
->where
.h
;
1145 event
.m_y
= ev
->where
.v
;
1146 event
.m_timeStamp
= ev
->when
;
1147 event
.SetEventObject(focus
);
1148 focus
->GetEventHandler()->ProcessEvent( event
) ;
1153 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1158 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1160 WindowRef window
= (WindowRef
) ev
->message
;
1163 bool activate
= (ev
->modifiers
& activeFlag
) ;
1164 WindowClass wclass
;
1165 UMAGetWindowClass ( window
, &wclass
) ;
1166 if ( wclass
== kFloatingWindowClass
)
1168 // if it is a floater we activate/deactivate the front non-floating window instead
1169 window
= UMAFrontNonFloatingWindow() ;
1171 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1173 win
->MacActivate( ev
, activate
) ;
1177 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1179 WindowRef window
= (WindowRef
) ev
->message
;
1180 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1183 win
->MacUpdate( ev
) ;
1187 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1189 if ( HiWord( ev
->message
) != noErr
)
1193 SetPt( &point
, 100 , 100 ) ;
1195 err
= DIBadMount( point
, ev
->message
) ;
1196 wxASSERT( err
== noErr
) ;
1200 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1202 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1204 case suspendResumeMessage
:
1206 bool isResuming
= ev
->message
& resumeFlag
;
1207 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1208 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1211 WindowRef oldFrontWindow
= NULL
;
1212 WindowRef newFrontWindow
= NULL
;
1214 // in case we don't take care of activating ourselves, we have to synchronize
1215 // our idea of the active window with the process manager's - which it already activated
1217 if ( !doesActivate
)
1218 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1220 MacResume( convertClipboard
) ;
1222 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1224 if ( oldFrontWindow
)
1226 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1228 win
->MacActivate( ev
, false ) ;
1230 if ( newFrontWindow
)
1232 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1234 win
->MacActivate( ev
, true ) ;
1239 MacSuspend( convertClipboard
) ;
1241 // in case this suspending did close an active window, another one might
1242 // have surfaced -> lets deactivate that one
1244 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1245 if ( newActiveWindow
)
1247 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1249 win
->MacActivate( ev
, false ) ;
1254 case mouseMovedMessage
:
1258 wxWindow
* currentMouseWindow
= NULL
;
1260 MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) , ¤tMouseWindow
) ;
1262 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1264 wxMouseEvent event
;
1266 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1267 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1269 event
.m_leftDown
= isDown
&& !controlDown
;
1270 event
.m_middleDown
= FALSE
;
1271 event
.m_rightDown
= isDown
&& controlDown
;
1272 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1273 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1274 event
.m_altDown
= ev
->modifiers
& optionKey
;
1275 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1276 event
.m_x
= ev
->where
.h
;
1277 event
.m_y
= ev
->where
.v
;
1278 event
.m_timeStamp
= ev
->when
;
1279 event
.SetEventObject(this);
1281 if ( wxWindow::s_lastMouseWindow
)
1283 wxMouseEvent
eventleave(event
) ;
1284 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1285 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1287 if ( currentMouseWindow
)
1289 wxMouseEvent
evententer(event
) ;
1290 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1291 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1293 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1296 short windowPart
= ::FindWindow(ev
->where
, &window
);
1306 if ( s_lastMouseDown
== 0 )
1307 ev
->modifiers
|= btnState
;
1309 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1311 win
->MacMouseMoved( ev
, windowPart
) ;
1321 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1324 return; // no menu item selected
1326 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1329 Str255 deskAccessoryName
;
1332 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1333 GetPort(&savedPort
);
1334 OpenDeskAcc(deskAccessoryName
);
1340 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1341 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1342 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1348 long wxApp::MacTranslateKey(char key, int mods)
1352 void wxApp::MacAdjustCursor()
1359 wxApp::macAdjustCursor()
1361 if (ev->what != kHighLevelEvent)
1363 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1366 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1367 ::SetCursor(&(qd.arrow));