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"
25 #include "wx/palette.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
30 #include "wx/module.h"
31 #include "wx/memory.h"
32 #include "wx/tooltip.h"
34 #if wxUSE_WX_RESOURCES
35 #include "wx/resource.h"
50 #include "wx/mac/uma.h"
51 #include "wx/mac/macnotfy.h"
55 #include <OT/OpenTransport.h>
57 #include <OpenTransport.h>
58 #include <OpenTptInternet.h>
62 extern char *wxBuffer
;
63 extern wxList wxPendingDelete
;
64 extern wxList
*wxWinMacWindowList
;
65 extern wxList
*wxWinMacControlList
;
67 wxApp
*wxTheApp
= NULL
;
69 #if !USE_SHARED_LIBRARY
70 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
71 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
72 EVT_IDLE(wxApp::OnIdle
)
73 EVT_END_SESSION(wxApp::OnEndSession
)
74 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
79 const short kMacMinHeap
= (29 * 1024) ;
80 // platform specific static variables
82 const short kwxMacMenuBarResource
= 1 ;
83 const short kwxMacAppleMenuId
= 1 ;
85 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
86 wxWindow
* wxApp::s_captureWindow
= NULL
;
87 int wxApp::s_lastMouseDown
= 0 ;
88 long wxApp::sm_lastMessageTime
= 0;
92 bool wxApp::s_macDefaultEncodingIsPC
= true ;
93 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
94 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
95 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
97 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
99 wxApp
* app
= (wxApp
*) refcon
;
100 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
103 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
105 wxApp
* app
= (wxApp
*) refcon
;
106 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
109 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
111 wxApp
* app
= (wxApp
*) refcon
;
112 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
115 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
117 wxApp
* app
= (wxApp
*) refcon
;
118 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
121 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
123 ProcessSerialNumber PSN
;
124 PSN
.highLongOfPSN
= 0 ;
125 PSN
.lowLongOfPSN
= kCurrentProcess
;
126 SetFrontProcess( &PSN
) ;
130 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
135 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
140 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
142 wxWindow
* win
= GetTopWindow() ;
154 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
155 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
156 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
157 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
158 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
159 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
161 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
162 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
163 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
164 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
165 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
166 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
168 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
173 for( int i
= 0 ; i
< len
; ++ i
)
175 c
= strchr( StringANSI
, *from
) ;
178 *to
= StringMac
[ c
- StringANSI
] ;
186 for( int i
= 0 ; i
< len
; ++ i
)
188 c
= strchr( StringANSI
, *from
) ;
191 *to
= StringMac
[ c
- StringANSI
] ;
203 void wxMacConvertToPC( const char *from
, char *to
, int len
)
208 for( int i
= 0 ; i
< len
; ++ i
)
210 c
= strchr( StringMac
, *from
) ;
213 *to
= StringANSI
[ c
- StringMac
] ;
221 for( int i
= 0 ; i
< len
; ++ i
)
223 c
= strchr( StringMac
, *from
) ;
226 *to
= StringANSI
[ c
- StringMac
] ;
238 void wxMacConvertFromPC( char * p
)
241 int len
= strlen ( p
) ;
243 wxMacConvertFromPC( ptr
, ptr
, len
) ;
246 void wxMacConvertFromPCForControls( char * p
)
249 int len
= strlen ( p
) ;
251 wxMacConvertFromPC( ptr
, ptr
, len
) ;
252 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
254 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
256 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
261 void wxMacConvertFromPC( unsigned char *p
)
263 char *ptr
= (char*) p
+ 1 ;
266 wxMacConvertFromPC( ptr
, ptr
, len
) ;
269 extern char *wxBuffer
;
271 wxString
wxMacMakeMacStringFromPC( const char * p
)
273 const char *ptr
= p
;
274 int len
= strlen ( p
) ;
275 char *buf
= wxBuffer
;
277 if ( len
>= BUFSIZ
+ 512 )
279 buf
= new char [len
+1] ;
282 wxMacConvertFromPC( ptr
, buf
, len
) ;
284 wxString
result( buf
) ;
285 if ( buf
!= wxBuffer
)
291 void wxMacConvertToPC( char * p
)
294 int len
= strlen ( p
) ;
296 wxMacConvertToPC( ptr
, ptr
, len
) ;
299 void wxMacConvertToPC( unsigned char *p
)
301 char *ptr
= (char*) p
+ 1 ;
304 wxMacConvertToPC( ptr
, ptr
, len
) ;
307 wxString
wxMacMakePCStringFromMac( const char * p
)
309 const char *ptr
= p
;
310 int len
= strlen ( p
) ;
311 char *buf
= wxBuffer
;
313 if ( len
>= BUFSIZ
+ 512 )
315 buf
= new char [len
+1] ;
318 wxMacConvertToPC( ptr
, buf
, len
) ;
321 wxString
result( buf
) ;
322 if ( buf
!= wxBuffer
)
329 bool wxApp::Initialize()
335 UMAInitToolbox( 4 ) ;
336 UMAShowWatchCursor() ;
339 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, AEHandleODoc
,
340 (long) wxTheApp
, FALSE
) ;
341 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, AEHandleOApp
,
342 (long) wxTheApp
, FALSE
) ;
343 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, AEHandlePDoc
,
344 (long) wxTheApp
, FALSE
) ;
345 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, AEHandleQuit
,
346 (long) wxTheApp
, FALSE
) ;
348 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
349 (long) wxTheApp
, FALSE
) ;
350 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
351 (long) wxTheApp
, FALSE
) ;
352 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
353 (long) wxTheApp
, FALSE
) ;
354 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
355 (long) wxTheApp
, FALSE
) ;
359 // test the minimal configuration necessary
364 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
366 error
= kMacSTRWrongMachine
;
368 else if (theMachine
< gestaltMacPlus
)
370 error
= kMacSTRWrongMachine
;
372 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
374 error
= kMacSTROldSystem
;
376 else if ( theSystem
< 0x0750 )
378 error
= kMacSTROldSystem
;
381 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
383 error
= kMacSTRSmallSize
;
389 if ( !UMAHasAppearance() )
391 error = kMacSTRNoPre8Yet ;
396 // if we encountered any problems so far, give the error code and exit immediately
403 GetIndString(message
, 128, error
);
404 UMAShowArrowCursor() ;
405 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
406 itemHit
= Alert(128, nil
);
411 #if __option(profile)
412 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
416 // now avoid exceptions thrown for new (bad_alloc)
419 std::__throws_bad_alloc
= FALSE
;
422 s_macCursorRgn
= ::NewRgn() ;
425 wxBuffer
= new char[1500];
427 wxBuffer
= new char[BUFSIZ
+ 512];
430 wxClassInfo::InitializeClasses();
433 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
437 wxPendingEventsLocker
= new wxCriticalSection
;
439 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
440 wxTheColourDatabase
->Initialize();
442 wxInitializeStockLists();
443 wxInitializeStockObjects();
445 #if wxUSE_WX_RESOURCES
446 wxInitializeResourceSystem();
449 wxBitmap::InitStandardHandlers();
451 wxModule::RegisterModules();
452 if (!wxModule::InitializeModules()) {
456 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
457 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
459 wxMacCreateNotifierTable() ;
461 UMAShowArrowCursor() ;
466 void wxApp::CleanUp()
469 // flush the logged messages if any and install a 'safer' log target: the
470 // default one (wxLogGui) can't be used after the resources are freed just
471 // below and the user suppliedo ne might be even more unsafe (using any
472 // wxWindows GUI function is unsafe starting from now)
473 wxLog::DontCreateOnDemand();
475 // this will flush the old messages if any
476 delete wxLog::SetActiveTarget(new wxLogStderr
);
479 // One last chance for pending objects to be cleaned up
480 wxTheApp
->DeletePendingObjects();
482 wxModule::CleanUpModules();
484 #if wxUSE_WX_RESOURCES
485 wxCleanUpResourceSystem();
488 wxDeleteStockObjects() ;
490 // Destroy all GDI lists, etc.
491 wxDeleteStockLists();
493 delete wxTheColourDatabase
;
494 wxTheColourDatabase
= NULL
;
496 wxBitmap::CleanUpHandlers();
501 wxMacDestroyNotifierTable() ;
502 if (wxWinMacWindowList
)
503 delete wxWinMacWindowList
;
505 delete wxPendingEvents
;
507 delete wxPendingEventsLocker
;
508 // If we don't do the following, we get an apparent memory leak.
509 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
512 wxClassInfo::CleanUpClasses();
515 #if __option(profile)
516 ProfilerDump( "\papp.prof" ) ;
524 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
525 // At this point we want to check if there are any memory
526 // blocks that aren't part of the wxDebugContext itself,
527 // as a special case. Then when dumping we need to ignore
528 // wxDebugContext, too.
529 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
531 wxLogDebug(wxT("There were memory leaks."));
532 wxDebugContext::Dump();
533 wxDebugContext::PrintStatistics();
535 // wxDebugContext::SetStream(NULL, NULL);
539 // do it as the very last thing because everything else can log messages
540 delete wxLog::SetActiveTarget(NULL
);
543 UMACleanupToolbox() ;
545 ::DisposeRgn(s_macCursorRgn
);
552 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
555 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
556 // This seems to be necessary since there are 'rogue'
557 // objects present at this point (perhaps global objects?)
558 // Setting a checkpoint will ignore them as far as the
559 // memory checking facility is concerned.
560 // Of course you may argue that memory allocated in globals should be
561 // checked, but this is a reasonable compromise.
562 wxDebugContext::SetCheckpoint();
565 if (!wxApp::Initialize()) {
568 // create the application object or ensure that one already exists
571 // The app may have declared a global application object, but we recommend
572 // the IMPLEMENT_APP macro is used instead, which sets an initializer
573 // function for delayed, dynamic app object construction.
574 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
575 wxT("No initializer - use IMPLEMENT_APP macro.") );
577 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
580 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
583 argc
= 0 ; // currently we don't support files as parameters
586 wxTheApp
->argc
= argc
;
587 wxTheApp
->argv
= argv
;
589 // GUI-specific initialization, such as creating an app context.
590 wxTheApp
->OnInitGui();
592 // we could try to get the open apple events here to adjust argc and argv better
595 // Here frames insert themselves automatically
596 // into wxTopLevelWindows by getting created
601 if ( wxTheApp
->OnInit() )
605 retValue
= wxTheApp
->OnRun();
608 // We want to initialize, but not run or exit immediately.
611 //else: app initialization failed, so we skipped OnRun()
613 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
616 // Forcibly delete the window.
617 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
618 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
620 topWindow
->Close(TRUE
);
621 wxTheApp
->DeletePendingObjects();
626 wxTheApp
->SetTopWindow(NULL
);
637 // Static member initialization
638 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
645 m_wantDebugOutput
= TRUE
;
650 m_printMode
= wxPRINT_WINDOWS
;
651 m_exitOnFrameDelete
= TRUE
;
655 bool wxApp::Initialized()
663 int wxApp::MainLoop()
675 // Returns TRUE if more time is needed.
676 bool wxApp::ProcessIdle()
679 event
.SetEventObject(this);
682 return event
.MoreRequested();
685 void wxApp::ExitMainLoop()
690 // Is a message/event pending?
691 bool wxApp::Pending()
695 return EventAvail( everyEvent
, &event
) ;
698 // Dispatch a message.
699 void wxApp::Dispatch()
704 void wxApp::OnIdle(wxIdleEvent
& event
)
706 static bool s_inOnIdle
= FALSE
;
708 // Avoid recursion (via ProcessEvent default case)
715 // 'Garbage' collection of windows deleted with Close().
716 DeletePendingObjects();
718 // flush the logged messages if any
719 wxLog
*pLog
= wxLog::GetActiveTarget();
720 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
723 // Send OnIdle events to all windows
724 bool needMore
= SendIdleEvents();
727 event
.RequestMore(TRUE
);
729 // If they are pending events, we must process them: pending events are
730 // either events to the threads other than main or events posted with
731 // wxPostEvent() functions
732 wxMacProcessNotifierAndPendingEvents();
742 // Send idle event to all top-level windows
743 bool wxApp::SendIdleEvents()
745 bool needMore
= FALSE
;
746 wxNode
* node
= wxTopLevelWindows
.First();
749 wxWindow
* win
= (wxWindow
*) node
->Data();
750 if (SendIdleEvents(win
))
758 // Send idle event to window and all subwindows
759 bool wxApp::SendIdleEvents(wxWindow
* win
)
761 bool needMore
= FALSE
;
764 event
.SetEventObject(win
);
765 win
->ProcessEvent(event
);
767 if (event
.MoreRequested())
770 wxNode
* node
= win
->GetChildren().First();
773 wxWindow
* win
= (wxWindow
*) node
->Data();
774 if (SendIdleEvents(win
))
782 void wxApp::DeletePendingObjects()
784 wxNode
*node
= wxPendingDelete
.First();
787 wxObject
*obj
= (wxObject
*)node
->Data();
791 if (wxPendingDelete
.Member(obj
))
794 // Deleting one object may have deleted other pending
795 // objects, so start from beginning of list again.
796 node
= wxPendingDelete
.First();
801 wxApp::GetStdIcon(int which
) const
805 case wxICON_INFORMATION
:
806 return wxIcon("wxICON_INFO");
808 case wxICON_QUESTION
:
809 return wxIcon("wxICON_QUESTION");
811 case wxICON_EXCLAMATION
:
812 return wxIcon("wxICON_WARNING");
815 wxFAIL_MSG(wxT("requested non existent standard icon"));
816 // still fall through
819 return wxIcon("wxICON_ERROR");
825 wxLogError(_("Fatal error: exiting"));
831 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
834 GetTopWindow()->Close(TRUE
);
837 // Default behaviour: close the application with prompts. The
838 // user can veto the close, and therefore the end session.
839 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
843 if (!GetTopWindow()->Close(!event
.CanVeto()))
848 extern "C" void wxCYield() ;
854 // Yield to other processes
862 long sleepTime
= 0 ; //::GetCaretTime();
864 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
866 wxTheApp
->MacHandleOneEvent( &event
);
869 wxMacProcessNotifierAndPendingEvents() ;
873 // platform specifics
875 void wxApp::MacSuspend( bool convertClipboard
)
877 // we have to deactive the window manually
879 wxWindow
* window
= GetTopWindow() ;
881 window
->MacActivate( MacGetCurrentEvent() , false ) ;
883 s_lastMouseDown
= 0 ;
884 if( convertClipboard
)
886 MacConvertPrivateToPublicScrap() ;
889 UMAHideFloatingWindows() ;
892 void wxApp::MacResume( bool convertClipboard
)
894 s_lastMouseDown
= 0 ;
895 if( convertClipboard
)
897 MacConvertPublicToPrivateScrap() ;
900 UMAShowFloatingWindows() ;
903 void wxApp::MacConvertPrivateToPublicScrap()
907 void wxApp::MacConvertPublicToPrivateScrap()
911 void wxApp::MacDoOneEvent()
915 long sleepTime
= ::GetCaretTime();
917 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
919 MacHandleOneEvent( &event
);
924 WindowPtr window
= UMAFrontWindow() ;
926 UMAIdleControls( window
) ;
928 wxTheApp
->ProcessIdle() ;
930 if ( event
.what
!= kHighLevelEvent
)
931 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
935 wxMacProcessNotifierAndPendingEvents() ;
938 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
940 m_macCurrentEvent
= ev
;
942 wxApp::sm_lastMessageTime
= ev
->when
;
947 MacHandleMouseDownEvent( ev
) ;
948 if ( ev
->modifiers
& controlKey
)
954 if ( s_lastMouseDown
== 2 )
956 ev
->modifiers
|= controlKey
;
960 ev
->modifiers
&= ~controlKey
;
962 MacHandleMouseUpEvent( ev
) ;
966 MacHandleActivateEvent( ev
) ;
969 MacHandleUpdateEvent( ev
) ;
973 MacHandleKeyDownEvent( ev
) ;
976 MacHandleKeyUpEvent( ev
) ;
979 MacHandleDiskEvent( ev
) ;
982 MacHandleOSEvent( ev
) ;
984 case kHighLevelEvent
:
985 MacHandleHighLevelEvent( ev
) ;
990 wxMacProcessNotifierAndPendingEvents() ;
993 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
995 ::AEProcessAppleEvent( ev
) ;
998 bool s_macIsInModalLoop
= false ;
1000 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1002 wxToolTip::RemoveToolTips() ;
1005 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1006 WindowAttributes frontWindowAttributes
= NULL
;
1008 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1010 short windowPart
= ::FindWindow(ev
->where
, &window
);
1011 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1014 GetQDGlobalsScreenBits( &screenBits
);
1019 if ( s_macIsInModalLoop
)
1025 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1026 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1027 s_lastMouseDown
= 0;
1032 SystemClick( ev
, window
) ;
1033 s_lastMouseDown
= 0;
1037 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1043 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1048 Point pt
= { 0, 0 } ;
1050 SetPort( GetWindowPort(window
) ) ;
1052 SetPort( (window
) ) ;
1054 SetOrigin( 0 , 0 ) ;
1055 LocalToGlobal( &pt
) ;
1057 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1058 -1 , wxSIZE_USE_EXISTING
);
1060 s_lastMouseDown
= 0;
1064 if (TrackGoAway(window
, ev
->where
))
1069 s_lastMouseDown
= 0;
1073 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1074 if (growResult
!= 0)
1076 int newWidth
= LoWord(growResult
);
1077 int newHeight
= HiWord(growResult
);
1078 int oldWidth
, oldHeight
;
1083 win
->GetSize(&oldWidth
, &oldHeight
);
1085 newWidth
= oldWidth
;
1087 newHeight
= oldHeight
;
1088 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1091 s_lastMouseDown
= 0;
1096 if (TrackBox(window
, ev
->where
, windowPart
))
1098 // TODO setup size event
1099 ZoomWindow( window
, windowPart
, false ) ;
1104 GetWindowPortBounds(window
, &tempRect
) ;
1105 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1106 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1109 s_lastMouseDown
= 0;
1111 case inCollapseBox
:
1112 // TODO setup size event
1113 s_lastMouseDown
= 0;
1121 SetPort( GetWindowPort(window
) ) ;
1123 SetPort( (window
) ) ;
1125 SetOrigin( 0 , 0 ) ;
1128 if ( window
!= frontWindow
)
1130 if ( s_macIsInModalLoop
)
1134 else if ( UMAIsWindowFloating( window
) )
1137 win
->MacMouseDown( ev
, windowPart
) ;
1141 UMASelectWindow( window
) ;
1147 win
->MacMouseDown( ev
, windowPart
) ;
1156 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1160 short windowPart
= ::FindWindow(ev
->where
, &window
);
1170 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1172 win
->MacMouseUp( ev
, windowPart
) ;
1178 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1187 retval
= WXK_RETURN
;
1202 retval
= WXK_PAGEUP
;
1205 retval
= WXK_PAGEDOWN
;
1208 retval
= WXK_RETURN
;
1263 retval
= WXK_ESCAPE
;
1269 retval
= WXK_RIGHT
;
1278 retval
= WXK_DELETE
;
1286 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1288 wxToolTip::RemoveToolTips() ;
1290 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1291 if ( HiWord( menuresult
) )
1293 if ( !s_macIsInModalLoop
)
1294 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1300 keychar
= short(ev
->message
& charCodeMask
);
1301 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1303 wxWindow
* focus
= wxWindow::FindFocus() ;
1306 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1308 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1309 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1310 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1311 event
.m_altDown
= ev
->modifiers
& optionKey
;
1312 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1313 event
.m_keyCode
= keyval
;
1314 event
.m_x
= ev
->where
.h
;
1315 event
.m_y
= ev
->where
.v
;
1316 event
.m_timeStamp
= ev
->when
;
1317 event
.SetEventObject(focus
);
1318 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1324 wxWindow
*ancestor
= focus
;
1328 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1331 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1332 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1335 if (ancestor->m_isFrame)
1337 ancestor = ancestor->GetParent();
1341 #endif // wxUSE_ACCEL
1345 wxKeyEvent
event(wxEVT_CHAR
);
1346 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1347 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1348 event
.m_altDown
= ev
->modifiers
& optionKey
;
1349 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1350 event
.m_keyCode
= keyval
;
1351 event
.m_x
= ev
->where
.h
;
1352 event
.m_y
= ev
->where
.v
;
1353 event
.m_timeStamp
= ev
->when
;
1354 event
.SetEventObject(focus
);
1355 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1358 (keyval
== WXK_TAB
) &&
1359 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1360 (focus
->GetParent()) &&
1361 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1363 wxNavigationKeyEvent new_event
;
1364 new_event
.SetEventObject( focus
);
1365 new_event
.SetDirection( !event
.ShiftDown() );
1366 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1367 new_event
.SetWindowChange( event
.ControlDown() );
1368 new_event
.SetCurrentFocus( focus
);
1369 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1371 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1373 (keyval
== '.' && event
.ControlDown() ) )
1375 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1376 new_event
.SetEventObject( focus
);
1377 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1383 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1388 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1390 WindowRef window
= (WindowRef
) ev
->message
;
1393 bool activate
= (ev
->modifiers
& activeFlag
) ;
1394 WindowClass wclass
;
1395 UMAGetWindowClass ( window
, &wclass
) ;
1396 if ( wclass
== kFloatingWindowClass
)
1398 // if it is a floater we activate/deactivate the front non-floating window instead
1399 window
= UMAFrontNonFloatingWindow() ;
1401 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1403 win
->MacActivate( ev
, activate
) ;
1407 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1409 WindowRef window
= (WindowRef
) ev
->message
;
1410 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1413 win
->MacUpdate( ev
) ;
1417 // since there is no way of telling this foreign window to update itself
1418 // we have to invalidate the update region otherwise we keep getting the same
1419 // event over and over again
1420 BeginUpdate( window
) ;
1421 EndUpdate( window
) ;
1425 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1427 if ( HiWord( ev
->message
) != noErr
)
1432 SetPt( &point
, 100 , 100 ) ;
1434 err
= DIBadMount( point
, ev
->message
) ;
1435 wxASSERT( err
== noErr
) ;
1440 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1442 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1444 case suspendResumeMessage
:
1446 bool isResuming
= ev
->message
& resumeFlag
;
1447 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1448 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1451 WindowRef oldFrontWindow
= NULL
;
1452 WindowRef newFrontWindow
= NULL
;
1454 // in case we don't take care of activating ourselves, we have to synchronize
1455 // our idea of the active window with the process manager's - which it already activated
1457 if ( !doesActivate
)
1458 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1460 MacResume( convertClipboard
) ;
1462 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1464 if ( oldFrontWindow
)
1466 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1468 win
->MacActivate( ev
, false ) ;
1470 if ( newFrontWindow
)
1472 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1474 win
->MacActivate( ev
, true ) ;
1479 MacSuspend( convertClipboard
) ;
1481 // in case this suspending did close an active window, another one might
1482 // have surfaced -> lets deactivate that one
1484 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1485 if ( newActiveWindow
)
1487 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1489 win
->MacActivate( ev
, false ) ;
1494 case mouseMovedMessage
:
1498 wxWindow
* currentMouseWindow
= NULL
;
1500 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1501 ¤tMouseWindow
) ;
1503 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1505 wxMouseEvent event
;
1507 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1508 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1510 event
.m_leftDown
= isDown
&& !controlDown
;
1511 event
.m_middleDown
= FALSE
;
1512 event
.m_rightDown
= isDown
&& controlDown
;
1513 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1514 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1515 event
.m_altDown
= ev
->modifiers
& optionKey
;
1516 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1517 event
.m_x
= ev
->where
.h
;
1518 event
.m_y
= ev
->where
.v
;
1519 event
.m_timeStamp
= ev
->when
;
1520 event
.SetEventObject(this);
1522 if ( wxWindow::s_lastMouseWindow
)
1524 wxMouseEvent
eventleave(event
) ;
1525 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1526 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1528 if ( currentMouseWindow
)
1530 wxMouseEvent
evententer(event
) ;
1531 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1532 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1534 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1537 short windowPart
= ::FindWindow(ev
->where
, &window
);
1541 // fixes for setting the cursor back from dominic mazzoni
1543 UMAShowArrowCursor();
1546 UMAShowArrowCursor();
1550 if ( s_lastMouseDown
== 0 )
1551 ev
->modifiers
|= btnState
;
1553 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1555 win
->MacMouseMoved( ev
, windowPart
) ;
1557 UMAShowArrowCursor();
1568 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1571 return; // no menu item selected
1573 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1576 Str255 deskAccessoryName
;
1579 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1580 GetPort(&savedPort
);
1581 OpenDeskAcc(deskAccessoryName
);
1587 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1588 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1589 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1595 long wxApp::MacTranslateKey(char key, int mods)
1599 void wxApp::MacAdjustCursor()
1606 wxApp::macAdjustCursor()
1608 if (ev->what != kHighLevelEvent)
1610 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1613 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1614 ::SetCursor(&(qd.arrow));