1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
16 #include "wx/window.h"
20 #include "wx/gdicmn.h"
23 #include "wx/cursor.h"
26 #include "wx/palette.h"
28 #include "wx/dialog.h"
29 #include "wx/msgdlg.h"
31 #include "wx/module.h"
32 #include "wx/memory.h"
33 #include "wx/tooltip.h"
34 #include "wx/textctrl.h"
36 #if wxUSE_WX_RESOURCES
37 #include "wx/resource.h"
52 #include "wx/mac/uma.h"
53 #include "wx/mac/macnotfy.h"
57 #include <CoreServices/CoreServices.h>
59 #include <OpenTransport.h>
60 #include <OpenTptInternet.h>
64 extern char *wxBuffer
;
65 extern wxList wxPendingDelete
;
66 extern wxList
*wxWinMacWindowList
;
67 extern wxList
*wxWinMacControlList
;
69 wxApp
*wxTheApp
= NULL
;
71 #if !USE_SHARED_LIBRARY
72 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
73 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
74 EVT_IDLE(wxApp::OnIdle
)
75 EVT_END_SESSION(wxApp::OnEndSession
)
76 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
81 const short kMacMinHeap
= (29 * 1024) ;
82 // platform specific static variables
84 const short kwxMacMenuBarResource
= 1 ;
85 const short kwxMacAppleMenuId
= 1 ;
87 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
88 wxWindow
* wxApp::s_captureWindow
= NULL
;
89 int wxApp::s_lastMouseDown
= 0 ;
90 long wxApp::sm_lastMessageTime
= 0;
94 bool wxApp::s_macDefaultEncodingIsPC
= true ;
95 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
96 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
97 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
99 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
100 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
102 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
105 wxApp
* app
= (wxApp
*) refcon
;
106 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
109 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
110 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
112 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
115 wxApp
* app
= (wxApp
*) refcon
;
116 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
119 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
120 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
122 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
125 wxApp
* app
= (wxApp
*) refcon
;
126 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
129 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
130 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
132 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
135 wxApp
* app
= (wxApp
*) refcon
;
136 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
139 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
142 ProcessSerialNumber PSN
;
143 PSN
.highLongOfPSN
= 0 ;
144 PSN
.lowLongOfPSN
= kCurrentProcess
;
145 SetFrontProcess( &PSN
) ;
149 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
154 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
159 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
161 wxWindow
* win
= GetTopWindow() ;
173 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
174 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
175 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
176 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
177 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
178 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
180 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
181 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
182 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
183 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
184 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
185 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
187 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
192 for( int i
= 0 ; i
< len
; ++ i
)
194 c
= strchr( StringANSI
, *from
) ;
197 *to
= StringMac
[ c
- StringANSI
] ;
205 for( int i
= 0 ; i
< len
; ++ i
)
207 c
= strchr( StringANSI
, *from
) ;
210 *to
= StringMac
[ c
- StringANSI
] ;
222 void wxMacConvertToPC( const char *from
, char *to
, int len
)
227 for( int i
= 0 ; i
< len
; ++ i
)
229 c
= strchr( StringMac
, *from
) ;
232 *to
= StringANSI
[ c
- StringMac
] ;
240 for( int i
= 0 ; i
< len
; ++ i
)
242 c
= strchr( StringMac
, *from
) ;
245 *to
= StringANSI
[ c
- StringMac
] ;
257 void wxMacConvertFromPC( char * p
)
260 int len
= strlen ( p
) ;
262 wxMacConvertFromPC( ptr
, ptr
, len
) ;
265 void wxMacConvertFromPCForControls( char * p
)
268 int len
= strlen ( p
) ;
270 wxMacConvertFromPC( ptr
, ptr
, len
) ;
271 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
273 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
275 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
280 void wxMacConvertFromPC( unsigned char *p
)
282 char *ptr
= (char*) p
+ 1 ;
285 wxMacConvertFromPC( ptr
, ptr
, len
) ;
288 extern char *wxBuffer
;
290 wxString
wxMacMakeMacStringFromPC( const char * p
)
292 const char *ptr
= p
;
293 int len
= strlen ( p
) ;
294 char *buf
= wxBuffer
;
296 if ( len
>= BUFSIZ
+ 512 )
298 buf
= new char [len
+1] ;
301 wxMacConvertFromPC( ptr
, buf
, len
) ;
303 wxString
result( buf
) ;
304 if ( buf
!= wxBuffer
)
310 void wxMacConvertToPC( char * p
)
313 int len
= strlen ( p
) ;
315 wxMacConvertToPC( ptr
, ptr
, len
) ;
318 void wxMacConvertToPC( unsigned char *p
)
320 char *ptr
= (char*) p
+ 1 ;
323 wxMacConvertToPC( ptr
, ptr
, len
) ;
326 wxString
wxMacMakePCStringFromMac( const char * p
)
328 const char *ptr
= p
;
329 int len
= strlen ( p
) ;
330 char *buf
= wxBuffer
;
332 if ( len
>= BUFSIZ
+ 512 )
334 buf
= new char [len
+1] ;
337 wxMacConvertToPC( ptr
, buf
, len
) ;
340 wxString
result( buf
) ;
341 if ( buf
!= wxBuffer
)
348 bool wxApp::Initialize()
354 UMAInitToolbox( 4 ) ;
355 SetEventMask( everyEvent
) ;
356 UMAShowWatchCursor() ;
358 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
359 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerUPP(AEHandleODoc
) ,
360 (long) wxTheApp
, FALSE
) ;
361 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerUPP(AEHandleOApp
) ,
362 (long) wxTheApp
, FALSE
) ;
363 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerUPP(AEHandlePDoc
) ,
364 (long) wxTheApp
, FALSE
) ;
365 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerUPP(AEHandleQuit
) ,
366 (long) wxTheApp
, FALSE
) ;
368 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
369 (long) wxTheApp
, FALSE
) ;
370 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
371 (long) wxTheApp
, FALSE
) ;
372 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
373 (long) wxTheApp
, FALSE
) ;
374 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
375 (long) wxTheApp
, FALSE
) ;
380 // test the minimal configuration necessary
386 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
388 error
= kMacSTRWrongMachine
;
390 else if (theMachine
< gestaltMacPlus
)
392 error
= kMacSTRWrongMachine
;
394 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
396 error
= kMacSTROldSystem
;
398 else if ( theSystem
< 0x0750 )
400 error
= kMacSTROldSystem
;
402 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
404 error
= kMacSTRSmallSize
;
410 if ( !UMAHasAppearance() )
412 error = kMacSTRNoPre8Yet ;
418 // if we encountered any problems so far, give the error code and exit immediately
425 GetIndString(message
, 128, error
);
426 UMAShowArrowCursor() ;
427 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
428 itemHit
= Alert(128, nil
);
433 #if __option(profile)
434 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
438 // now avoid exceptions thrown for new (bad_alloc)
441 std::__throws_bad_alloc
= FALSE
;
444 s_macCursorRgn
= ::NewRgn() ;
447 wxBuffer
= new char[1500];
449 wxBuffer
= new char[BUFSIZ
+ 512];
452 wxClassInfo::InitializeClasses();
455 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
459 wxPendingEventsLocker
= new wxCriticalSection
;
461 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
462 wxTheColourDatabase
->Initialize();
466 // flush the logged messages if any and install a 'safer' log target: the
467 // default one (wxLogGui) can't be used after the resources are freed just
468 // below and the user suppliedo ne might be even more unsafe (using any
469 // wxWindows GUI function is unsafe starting from now)
470 wxLog::DontCreateOnDemand();
472 // this will flush the old messages if any
473 delete wxLog::SetActiveTarget(new wxLogStderr
);
477 wxInitializeStockLists();
478 wxInitializeStockObjects();
480 #if wxUSE_WX_RESOURCES
481 wxInitializeResourceSystem();
484 wxBitmap::InitStandardHandlers();
486 wxModule::RegisterModules();
487 if (!wxModule::InitializeModules()) {
491 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
492 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
494 wxMacCreateNotifierTable() ;
496 UMAShowArrowCursor() ;
501 void wxApp::CleanUp()
504 // flush the logged messages if any and install a 'safer' log target: the
505 // default one (wxLogGui) can't be used after the resources are freed just
506 // below and the user suppliedo ne might be even more unsafe (using any
507 // wxWindows GUI function is unsafe starting from now)
508 wxLog::DontCreateOnDemand();
510 // this will flush the old messages if any
511 delete wxLog::SetActiveTarget(new wxLogStderr
);
514 // One last chance for pending objects to be cleaned up
515 wxTheApp
->DeletePendingObjects();
517 wxModule::CleanUpModules();
519 #if wxUSE_WX_RESOURCES
520 wxCleanUpResourceSystem();
523 wxDeleteStockObjects() ;
525 // Destroy all GDI lists, etc.
526 wxDeleteStockLists();
528 delete wxTheColourDatabase
;
529 wxTheColourDatabase
= NULL
;
531 wxBitmap::CleanUpHandlers();
536 wxMacDestroyNotifierTable() ;
537 if (wxWinMacWindowList
)
538 delete wxWinMacWindowList
;
540 delete wxPendingEvents
;
542 delete wxPendingEventsLocker
;
543 // If we don't do the following, we get an apparent memory leak.
544 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
547 wxClassInfo::CleanUpClasses();
550 #if __option(profile)
551 ProfilerDump( "\papp.prof" ) ;
559 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
560 // At this point we want to check if there are any memory
561 // blocks that aren't part of the wxDebugContext itself,
562 // as a special case. Then when dumping we need to ignore
563 // wxDebugContext, too.
564 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
566 wxLogDebug(wxT("There were memory leaks."));
567 wxDebugContext::Dump();
568 wxDebugContext::PrintStatistics();
570 // wxDebugContext::SetStream(NULL, NULL);
574 // do it as the very last thing because everything else can log messages
575 delete wxLog::SetActiveTarget(NULL
);
578 UMACleanupToolbox() ;
580 ::DisposeRgn(s_macCursorRgn
);
587 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
590 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
591 // This seems to be necessary since there are 'rogue'
592 // objects present at this point (perhaps global objects?)
593 // Setting a checkpoint will ignore them as far as the
594 // memory checking facility is concerned.
595 // Of course you may argue that memory allocated in globals should be
596 // checked, but this is a reasonable compromise.
597 wxDebugContext::SetCheckpoint();
600 if (!wxApp::Initialize()) {
603 // create the application object or ensure that one already exists
606 // The app may have declared a global application object, but we recommend
607 // the IMPLEMENT_APP macro is used instead, which sets an initializer
608 // function for delayed, dynamic app object construction.
609 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
610 wxT("No initializer - use IMPLEMENT_APP macro.") );
612 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
615 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
618 argc
= 0 ; // currently we don't support files as parameters
621 wxTheApp
->argc
= argc
;
622 wxTheApp
->argv
= argv
;
624 // GUI-specific initialization, such as creating an app context.
625 wxTheApp
->OnInitGui();
627 // we could try to get the open apple events here to adjust argc and argv better
630 // Here frames insert themselves automatically
631 // into wxTopLevelWindows by getting created
636 if ( wxTheApp
->OnInit() )
640 retValue
= wxTheApp
->OnRun();
643 // We want to initialize, but not run or exit immediately.
646 //else: app initialization failed, so we skipped OnRun()
648 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
651 // Forcibly delete the window.
652 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
653 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
655 topWindow
->Close(TRUE
);
656 wxTheApp
->DeletePendingObjects();
661 wxTheApp
->SetTopWindow(NULL
);
672 // Static member initialization
673 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
680 m_wantDebugOutput
= TRUE
;
685 m_printMode
= wxPRINT_WINDOWS
;
686 m_exitOnFrameDelete
= TRUE
;
690 bool wxApp::Initialized()
698 int wxApp::MainLoop()
710 // Returns TRUE if more time is needed.
711 bool wxApp::ProcessIdle()
714 event
.SetEventObject(this);
717 return event
.MoreRequested();
720 void wxApp::ExitMainLoop()
725 // Is a message/event pending?
726 bool wxApp::Pending()
730 return EventAvail( everyEvent
, &event
) ;
733 // Dispatch a message.
734 void wxApp::Dispatch()
739 void wxApp::OnIdle(wxIdleEvent
& event
)
741 static bool s_inOnIdle
= FALSE
;
743 // Avoid recursion (via ProcessEvent default case)
750 // 'Garbage' collection of windows deleted with Close().
751 DeletePendingObjects();
753 // flush the logged messages if any
754 wxLog
*pLog
= wxLog::GetActiveTarget();
755 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
758 // Send OnIdle events to all windows
759 bool needMore
= SendIdleEvents();
762 event
.RequestMore(TRUE
);
764 // If they are pending events, we must process them: pending events are
765 // either events to the threads other than main or events posted with
766 // wxPostEvent() functions
767 wxMacProcessNotifierAndPendingEvents();
777 // Send idle event to all top-level windows
778 bool wxApp::SendIdleEvents()
780 bool needMore
= FALSE
;
781 wxNode
* node
= wxTopLevelWindows
.First();
784 wxWindow
* win
= (wxWindow
*) node
->Data();
785 if (SendIdleEvents(win
))
793 // Send idle event to window and all subwindows
794 bool wxApp::SendIdleEvents(wxWindow
* win
)
796 bool needMore
= FALSE
;
799 event
.SetEventObject(win
);
800 win
->ProcessEvent(event
);
802 if (event
.MoreRequested())
805 wxNode
* node
= win
->GetChildren().First();
808 wxWindow
* win
= (wxWindow
*) node
->Data();
809 if (SendIdleEvents(win
))
817 void wxApp::DeletePendingObjects()
819 wxNode
*node
= wxPendingDelete
.First();
822 wxObject
*obj
= (wxObject
*)node
->Data();
826 if (wxPendingDelete
.Member(obj
))
829 // Deleting one object may have deleted other pending
830 // objects, so start from beginning of list again.
831 node
= wxPendingDelete
.First();
836 wxApp::GetStdIcon(int which
) const
840 case wxICON_INFORMATION
:
841 return wxIcon("wxICON_INFO");
843 case wxICON_QUESTION
:
844 return wxIcon("wxICON_QUESTION");
846 case wxICON_EXCLAMATION
:
847 return wxIcon("wxICON_WARNING");
850 wxFAIL_MSG(wxT("requested non existent standard icon"));
851 // still fall through
854 return wxIcon("wxICON_ERROR");
860 wxLogError(_("Fatal error: exiting"));
866 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
869 GetTopWindow()->Close(TRUE
);
872 // Default behaviour: close the application with prompts. The
873 // user can veto the close, and therefore the end session.
874 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
878 if (!GetTopWindow()->Close(!event
.CanVeto()))
883 extern "C" void wxCYield() ;
889 // Yield to other processes
891 static bool gs_inYield
= FALSE
;
897 wxFAIL_MSG( wxT("wxYield called recursively" ) );
907 long sleepTime
= 1 ; //::GetCaretTime();
909 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
911 wxTheApp
->MacHandleOneEvent( &event
);
912 if ( event
.what
!= kHighLevelEvent
)
913 SetRectRgn( wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
916 wxMacProcessNotifierAndPendingEvents() ;
923 // Yield to incoming messages; but fail silently if recursion is detected.
924 bool wxYieldIfNeeded()
932 // platform specifics
934 void wxApp::MacSuspend( bool convertClipboard
)
936 // we have to deactive the window manually
938 wxWindow
* window
= GetTopWindow() ;
940 window
->MacActivate( MacGetCurrentEvent() , false ) ;
942 s_lastMouseDown
= 0 ;
943 if( convertClipboard
)
945 MacConvertPrivateToPublicScrap() ;
948 UMAHideFloatingWindows() ;
951 void wxApp::MacResume( bool convertClipboard
)
953 s_lastMouseDown
= 0 ;
954 if( convertClipboard
)
956 MacConvertPublicToPrivateScrap() ;
959 UMAShowFloatingWindows() ;
962 void wxApp::MacConvertPrivateToPublicScrap()
966 void wxApp::MacConvertPublicToPrivateScrap()
970 void wxApp::MacDoOneEvent()
974 long sleepTime
= 1 ; // GetCaretTime() / 4 ;
976 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
978 MacHandleOneEvent( &event
);
983 WindowPtr window
= UMAFrontWindow() ;
985 UMAIdleControls( window
) ;
987 wxTheApp
->ProcessIdle() ;
989 if ( event
.what
!= kHighLevelEvent
)
990 SetRectRgn( s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
994 DeletePendingObjects() ;
995 wxMacProcessNotifierAndPendingEvents() ;
998 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
1000 m_macCurrentEvent
= ev
;
1002 wxApp::sm_lastMessageTime
= ev
->when
;
1007 MacHandleMouseDownEvent( ev
) ;
1008 if ( ev
->modifiers
& controlKey
)
1009 s_lastMouseDown
= 2;
1011 s_lastMouseDown
= 1;
1014 if ( s_lastMouseDown
== 2 )
1016 ev
->modifiers
|= controlKey
;
1020 ev
->modifiers
&= ~controlKey
;
1022 MacHandleMouseUpEvent( ev
) ;
1023 s_lastMouseDown
= 0;
1026 MacHandleActivateEvent( ev
) ;
1029 MacHandleUpdateEvent( ev
) ;
1033 MacHandleKeyDownEvent( ev
) ;
1036 MacHandleKeyUpEvent( ev
) ;
1039 MacHandleDiskEvent( ev
) ;
1042 MacHandleOSEvent( ev
) ;
1044 case kHighLevelEvent
:
1045 MacHandleHighLevelEvent( ev
) ;
1050 wxMacProcessNotifierAndPendingEvents() ;
1053 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1055 ::AEProcessAppleEvent( ev
) ;
1058 bool s_macIsInModalLoop
= false ;
1060 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1062 wxToolTip::RemoveToolTips() ;
1065 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1066 WindowAttributes frontWindowAttributes
= NULL
;
1068 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1070 short windowPart
= ::FindWindow(ev
->where
, &window
);
1071 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1072 if ( wxPendingDelete
.Member(win
) )
1076 GetQDGlobalsScreenBits( &screenBits
);
1081 if ( s_macIsInModalLoop
)
1087 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1088 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1089 s_lastMouseDown
= 0;
1094 SystemClick( ev
, window
) ;
1095 s_lastMouseDown
= 0;
1099 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1105 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1110 Point pt
= { 0, 0 } ;
1112 SetPort( GetWindowPort(window
) ) ;
1114 SetPort( (window
) ) ;
1116 SetOrigin( 0 , 0 ) ;
1117 LocalToGlobal( &pt
) ;
1119 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1120 -1 , wxSIZE_USE_EXISTING
);
1122 s_lastMouseDown
= 0;
1126 if (TrackGoAway(window
, ev
->where
))
1131 s_lastMouseDown
= 0;
1135 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1136 if (growResult
!= 0)
1138 int newWidth
= LoWord(growResult
);
1139 int newHeight
= HiWord(growResult
);
1140 int oldWidth
, oldHeight
;
1145 win
->GetSize(&oldWidth
, &oldHeight
);
1147 newWidth
= oldWidth
;
1149 newHeight
= oldHeight
;
1150 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1153 s_lastMouseDown
= 0;
1158 if (TrackBox(window
, ev
->where
, windowPart
))
1160 // TODO setup size event
1161 ZoomWindow( window
, windowPart
, false ) ;
1166 GetWindowPortBounds(window
, &tempRect
) ;
1167 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1168 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1171 s_lastMouseDown
= 0;
1173 case inCollapseBox
:
1174 // TODO setup size event
1175 s_lastMouseDown
= 0;
1183 SetPort( GetWindowPort(window
) ) ;
1185 SetPort( (window
) ) ;
1187 SetOrigin( 0 , 0 ) ;
1190 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1192 if ( s_macIsInModalLoop
)
1196 else if ( UMAIsWindowFloating( window
) )
1199 win
->MacMouseDown( ev
, windowPart
) ;
1204 win
->MacMouseDown( ev
, windowPart
) ;
1205 UMASelectWindow( window
) ;
1211 win
->MacMouseDown( ev
, windowPart
) ;
1220 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1224 short windowPart
= ::FindWindow(ev
->where
, &window
);
1234 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1236 win
->MacMouseUp( ev
, windowPart
) ;
1242 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1251 retval
= WXK_RETURN
;
1266 retval
= WXK_PAGEUP
;
1269 retval
= WXK_PAGEDOWN
;
1272 retval
= WXK_RETURN
;
1327 retval
= WXK_ESCAPE
;
1333 retval
= WXK_RIGHT
;
1342 retval
= WXK_DELETE
;
1350 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1352 wxToolTip::RemoveToolTips() ;
1354 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1355 if ( HiWord( menuresult
) )
1357 if ( !s_macIsInModalLoop
)
1358 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1364 keychar
= short(ev
->message
& charCodeMask
);
1365 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1367 wxWindow
* focus
= wxWindow::FindFocus() ;
1370 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1372 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1373 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1374 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1375 event
.m_altDown
= ev
->modifiers
& optionKey
;
1376 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1377 event
.m_keyCode
= keyval
;
1378 event
.m_x
= ev
->where
.h
;
1379 event
.m_y
= ev
->where
.v
;
1380 event
.m_timeStamp
= ev
->when
;
1381 event
.SetEventObject(focus
);
1382 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1388 wxWindow
*ancestor
= focus
;
1392 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1395 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1396 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1399 if (ancestor->m_isFrame)
1401 ancestor = ancestor->GetParent();
1405 #endif // wxUSE_ACCEL
1409 wxKeyEvent
event(wxEVT_CHAR
);
1410 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1411 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1412 event
.m_altDown
= ev
->modifiers
& optionKey
;
1413 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1414 event
.m_keyCode
= keyval
;
1415 event
.m_x
= ev
->where
.h
;
1416 event
.m_y
= ev
->where
.v
;
1417 event
.m_timeStamp
= ev
->when
;
1418 event
.SetEventObject(focus
);
1419 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1422 (keyval
== WXK_TAB
) &&
1423 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1424 (focus
->GetParent()) &&
1425 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1427 wxNavigationKeyEvent new_event
;
1428 new_event
.SetEventObject( focus
);
1429 new_event
.SetDirection( !event
.ShiftDown() );
1430 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1431 new_event
.SetWindowChange( event
.ControlDown() );
1432 new_event
.SetCurrentFocus( focus
);
1433 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1435 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1437 (keyval
== '.' && event
.ControlDown() ) )
1439 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1440 new_event
.SetEventObject( focus
);
1441 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1447 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1449 wxToolTip::RemoveToolTips() ;
1451 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1452 if ( HiWord( menuresult
) )
1459 keychar
= short(ev
->message
& charCodeMask
);
1460 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1462 wxWindow
* focus
= wxWindow::FindFocus() ;
1465 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1467 wxKeyEvent
event(wxEVT_KEY_UP
);
1468 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1469 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1470 event
.m_altDown
= ev
->modifiers
& optionKey
;
1471 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1472 event
.m_keyCode
= keyval
;
1473 event
.m_x
= ev
->where
.h
;
1474 event
.m_y
= ev
->where
.v
;
1475 event
.m_timeStamp
= ev
->when
;
1476 event
.SetEventObject(focus
);
1477 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1482 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1484 WindowRef window
= (WindowRef
) ev
->message
;
1487 bool activate
= (ev
->modifiers
& activeFlag
) ;
1488 WindowClass wclass
;
1489 UMAGetWindowClass ( window
, &wclass
) ;
1490 if ( wclass
== kFloatingWindowClass
)
1492 // if it is a floater we activate/deactivate the front non-floating window instead
1493 window
= UMAFrontNonFloatingWindow() ;
1495 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1497 win
->MacActivate( ev
, activate
) ;
1501 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1503 WindowRef window
= (WindowRef
) ev
->message
;
1504 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1507 if ( !wxPendingDelete
.Member(win
) )
1508 win
->MacUpdate( ev
) ;
1512 // since there is no way of telling this foreign window to update itself
1513 // we have to invalidate the update region otherwise we keep getting the same
1514 // event over and over again
1515 BeginUpdate( window
) ;
1516 EndUpdate( window
) ;
1520 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1522 if ( HiWord( ev
->message
) != noErr
)
1527 SetPt( &point
, 100 , 100 ) ;
1529 err
= DIBadMount( point
, ev
->message
) ;
1530 wxASSERT( err
== noErr
) ;
1535 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1537 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1539 case suspendResumeMessage
:
1541 bool isResuming
= ev
->message
& resumeFlag
;
1543 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1545 bool convertClipboard
= false;
1547 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1550 WindowRef oldFrontWindow
= NULL
;
1551 WindowRef newFrontWindow
= NULL
;
1553 // in case we don't take care of activating ourselves, we have to synchronize
1554 // our idea of the active window with the process manager's - which it already activated
1556 if ( !doesActivate
)
1557 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1559 MacResume( convertClipboard
) ;
1561 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1563 if ( oldFrontWindow
)
1565 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1567 win
->MacActivate( ev
, false ) ;
1569 if ( newFrontWindow
)
1571 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1573 win
->MacActivate( ev
, true ) ;
1578 MacSuspend( convertClipboard
) ;
1580 // in case this suspending did close an active window, another one might
1581 // have surfaced -> lets deactivate that one
1583 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1584 if ( newActiveWindow
)
1586 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1588 win
->MacActivate( ev
, false ) ;
1593 case mouseMovedMessage
:
1597 wxWindow
* currentMouseWindow
= NULL
;
1599 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1600 ¤tMouseWindow
) ;
1602 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1604 wxMouseEvent event
;
1606 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1607 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1609 event
.m_leftDown
= isDown
&& !controlDown
;
1610 event
.m_middleDown
= FALSE
;
1611 event
.m_rightDown
= isDown
&& controlDown
;
1612 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1613 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1614 event
.m_altDown
= ev
->modifiers
& optionKey
;
1615 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1616 event
.m_x
= ev
->where
.h
;
1617 event
.m_y
= ev
->where
.v
;
1618 event
.m_timeStamp
= ev
->when
;
1619 event
.SetEventObject(this);
1621 if ( wxWindow::s_lastMouseWindow
)
1623 wxMouseEvent
eventleave(event
) ;
1624 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1625 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1627 if ( currentMouseWindow
)
1629 wxMouseEvent
evententer(event
) ;
1630 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1631 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1633 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1636 short windowPart
= ::FindWindow(ev
->where
, &window
);
1640 // fixes for setting the cursor back from dominic mazzoni
1642 UMAShowArrowCursor();
1645 UMAShowArrowCursor();
1649 if ( s_lastMouseDown
== 0 )
1650 ev
->modifiers
|= btnState
;
1652 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1654 win
->MacMouseMoved( ev
, windowPart
) ;
1656 UMAShowArrowCursor();
1667 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1670 return; // no menu item selected
1672 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1675 Str255 deskAccessoryName
;
1678 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1679 GetPort(&savedPort
);
1680 OpenDeskAcc(deskAccessoryName
);
1686 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1687 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1688 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1694 long wxApp::MacTranslateKey(char key, int mods)
1698 void wxApp::MacAdjustCursor()
1705 wxApp::macAdjustCursor()
1707 if (ev->what != kHighLevelEvent)
1709 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1712 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1713 ::SetCursor(&(qd.arrow));