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"
31 #include "wx/tooltip.h"
32 #if wxUSE_WX_RESOURCES
33 #include "wx/resource.h"
46 #include <wx/mac/uma.h>
47 #include <wx/mac/macnotfy.h>
50 #include <OpenTransport.h>
51 #include <OpenTptInternet.h>
54 extern char *wxBuffer
;
55 extern wxList wxPendingDelete
;
56 extern wxList
*wxWinMacWindowList
;
57 extern wxList
*wxWinMacControlList
;
59 wxApp
*wxTheApp
= NULL
;
61 #if !USE_SHARED_LIBRARY
62 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
63 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
64 EVT_IDLE(wxApp::OnIdle
)
65 EVT_END_SESSION(wxApp::OnEndSession
)
66 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
71 const short kMacMinHeap
= (29 * 1024) ;
72 // platform specific static variables
74 const short kwxMacMenuBarResource
= 1 ;
75 const short kwxMacAppleMenuId
= 1 ;
77 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
78 wxWindow
* wxApp::s_captureWindow
= NULL
;
79 int wxApp::s_lastMouseDown
= 0 ;
80 long wxApp::sm_lastMessageTime
= 0;
84 bool wxApp::s_macDefaultEncodingIsPC
= true ;
85 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
86 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
87 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
89 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
91 wxApp
* app
= (wxApp
*) refcon
;
92 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
95 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
97 wxApp
* app
= (wxApp
*) refcon
;
98 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
101 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
103 wxApp
* app
= (wxApp
*) refcon
;
104 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
107 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
109 wxApp
* app
= (wxApp
*) refcon
;
110 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
113 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
115 ProcessSerialNumber PSN
;
116 PSN
.highLongOfPSN
= 0 ;
117 PSN
.lowLongOfPSN
= kCurrentProcess
;
118 SetFrontProcess( &PSN
) ;
122 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
127 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
132 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
134 wxWindow
* win
= GetTopWindow() ;
146 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
147 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
148 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
149 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
150 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
151 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
153 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
154 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
155 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
156 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
157 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
158 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
160 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
165 for( int i
= 0 ; i
< len
; ++ i
)
167 c
= strchr( StringANSI
, *from
) ;
170 *to
= StringMac
[ c
- StringANSI
] ;
178 for( int i
= 0 ; i
< len
; ++ i
)
180 c
= strchr( StringANSI
, *from
) ;
183 *to
= StringMac
[ c
- StringANSI
] ;
195 void wxMacConvertToPC( const char *from
, char *to
, int len
)
200 for( int i
= 0 ; i
< len
; ++ i
)
202 c
= strchr( StringMac
, *from
) ;
205 *to
= StringANSI
[ c
- StringMac
] ;
213 for( int i
= 0 ; i
< len
; ++ i
)
215 c
= strchr( StringMac
, *from
) ;
218 *to
= StringANSI
[ c
- StringMac
] ;
230 void wxMacConvertFromPC( char * p
)
233 int len
= strlen ( p
) ;
235 wxMacConvertFromPC( ptr
, ptr
, len
) ;
238 void wxMacConvertFromPCForControls( char * p
)
241 int len
= strlen ( p
) ;
243 wxMacConvertFromPC( ptr
, ptr
, len
) ;
244 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
246 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
248 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
253 void wxMacConvertFromPC( unsigned char *p
)
255 char *ptr
= (char*) p
+ 1 ;
258 wxMacConvertFromPC( ptr
, ptr
, len
) ;
261 extern char *wxBuffer
;
263 wxString
wxMacMakeMacStringFromPC( const char * p
)
265 const char *ptr
= p
;
266 int len
= strlen ( p
) ;
267 char *buf
= wxBuffer
;
269 if ( len
>= BUFSIZ
+ 512 )
271 buf
= new char [len
+1] ;
274 wxMacConvertFromPC( ptr
, buf
, len
) ;
276 wxString
result( buf
) ;
277 if ( buf
!= wxBuffer
)
283 void wxMacConvertToPC( char * p
)
286 int len
= strlen ( p
) ;
288 wxMacConvertToPC( ptr
, ptr
, len
) ;
291 void wxMacConvertToPC( unsigned char *p
)
293 char *ptr
= (char*) p
+ 1 ;
296 wxMacConvertToPC( ptr
, ptr
, len
) ;
299 wxString
wxMacMakePCStringFromMac( const char * p
)
301 const char *ptr
= p
;
302 int len
= strlen ( p
) ;
303 char *buf
= wxBuffer
;
305 if ( len
>= BUFSIZ
+ 512 )
307 buf
= new char [len
+1] ;
310 wxMacConvertToPC( ptr
, buf
, len
) ;
313 wxString
result( buf
) ;
314 if ( buf
!= wxBuffer
)
321 bool wxApp::Initialize()
327 UMAInitToolbox( 4 ) ;
328 UMAShowWatchCursor() ;
330 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) , (long) wxTheApp
, FALSE
) ;
331 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) , (long) wxTheApp
, FALSE
) ;
332 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) , (long) wxTheApp
, FALSE
) ;
333 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) , (long) wxTheApp
, FALSE
) ;
336 // test the minimal configuration necessary
341 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
343 error
= kMacSTRWrongMachine
;
345 else if (theMachine
< gestaltMacPlus
)
347 error
= kMacSTRWrongMachine
;
349 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
351 error
= kMacSTROldSystem
;
353 else if ( theSystem
< 0x0750 )
355 error
= kMacSTROldSystem
;
358 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
360 error
= kMacSTRSmallSize
;
366 if ( !UMAHasAppearance() )
368 error = kMacSTRNoPre8Yet ;
373 // if we encountered any problems so far, give the error code and exit immediately
380 GetIndString(message
, 128, error
);
381 UMAShowArrowCursor() ;
382 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
383 itemHit
= Alert(128, nil
);
387 #if __option(profile)
388 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
391 // now avoid exceptions thrown for new (bad_alloc)
393 std::__throws_bad_alloc
= FALSE
;
395 s_macCursorRgn
= ::NewRgn() ;
398 wxBuffer
= new char[1500];
400 wxBuffer
= new char[BUFSIZ
+ 512];
403 wxClassInfo::InitializeClasses();
406 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
410 wxPendingEventsLocker
= new wxCriticalSection
;
412 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
413 wxTheColourDatabase
->Initialize();
415 wxInitializeStockLists();
416 wxInitializeStockObjects();
418 #if wxUSE_WX_RESOURCES
419 wxInitializeResourceSystem();
422 wxBitmap::InitStandardHandlers();
424 wxModule::RegisterModules();
425 if (!wxModule::InitializeModules())
428 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
429 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
431 wxMacCreateNotifierTable() ;
433 UMAShowArrowCursor() ;
438 void wxApp::CleanUp()
441 // flush the logged messages if any and install a 'safer' log target: the
442 // default one (wxLogGui) can't be used after the resources are freed just
443 // below and the user suppliedo ne might be even more unsafe (using any
444 // wxWindows GUI function is unsafe starting from now)
445 wxLog::DontCreateOnDemand();
447 // this will flush the old messages if any
448 delete wxLog::SetActiveTarget(new wxLogStderr
);
451 // One last chance for pending objects to be cleaned up
452 wxTheApp
->DeletePendingObjects();
454 wxModule::CleanUpModules();
456 #if wxUSE_WX_RESOURCES
457 wxCleanUpResourceSystem();
460 wxDeleteStockObjects() ;
462 // Destroy all GDI lists, etc.
463 wxDeleteStockLists();
465 delete wxTheColourDatabase
;
466 wxTheColourDatabase
= NULL
;
468 wxBitmap::CleanUpHandlers();
473 wxMacDestroyNotifierTable() ;
474 if (wxWinMacWindowList
)
475 delete wxWinMacWindowList
;
477 delete wxPendingEvents
;
479 delete wxPendingEventsLocker
;
480 // If we don't do the following, we get an apparent memory leak.
481 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
484 wxClassInfo::CleanUpClasses();
486 #if __option(profile)
487 ProfilerDump( "\papp.prof" ) ;
494 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
495 // At this point we want to check if there are any memory
496 // blocks that aren't part of the wxDebugContext itself,
497 // as a special case. Then when dumping we need to ignore
498 // wxDebugContext, too.
499 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
501 wxLogDebug(wxT("There were memory leaks."));
502 wxDebugContext::Dump();
503 wxDebugContext::PrintStatistics();
505 // wxDebugContext::SetStream(NULL, NULL);
509 // do it as the very last thing because everything else can log messages
510 delete wxLog::SetActiveTarget(NULL
);
513 UMACleanupToolbox() ;
515 ::DisposeRgn(s_macCursorRgn
);
522 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
525 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
526 // This seems to be necessary since there are 'rogue'
527 // objects present at this point (perhaps global objects?)
528 // Setting a checkpoint will ignore them as far as the
529 // memory checking facility is concerned.
530 // Of course you may argue that memory allocated in globals should be
531 // checked, but this is a reasonable compromise.
532 wxDebugContext::SetCheckpoint();
535 if (!wxApp::Initialize())
537 // create the application object or ensure that one already exists
540 // The app may have declared a global application object, but we recommend
541 // the IMPLEMENT_APP macro is used instead, which sets an initializer
542 // function for delayed, dynamic app object construction.
543 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
544 wxT("No initializer - use IMPLEMENT_APP macro.") );
546 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
549 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
552 argc
= 0 ; // currently we don't support files as parameters
555 wxTheApp
->argc
= argc
;
556 wxTheApp
->argv
= argv
;
558 // GUI-specific initialization, such as creating an app context.
559 wxTheApp
->OnInitGui();
561 // we could try to get the open apple events here to adjust argc and argv better
564 // Here frames insert themselves automatically
565 // into wxTopLevelWindows by getting created
570 if ( wxTheApp
->OnInit() )
574 retValue
= wxTheApp
->OnRun();
577 // We want to initialize, but not run or exit immediately.
580 //else: app initialization failed, so we skipped OnRun()
582 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
585 // Forcibly delete the window.
586 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
587 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
589 topWindow
->Close(TRUE
);
590 wxTheApp
->DeletePendingObjects();
595 wxTheApp
->SetTopWindow(NULL
);
606 // Static member initialization
607 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
614 m_wantDebugOutput
= TRUE
;
619 m_printMode
= wxPRINT_WINDOWS
;
620 m_exitOnFrameDelete
= TRUE
;
624 bool wxApp::Initialized()
632 int wxApp::MainLoop()
644 // Returns TRUE if more time is needed.
645 bool wxApp::ProcessIdle()
648 event
.SetEventObject(this);
651 return event
.MoreRequested();
654 void wxApp::ExitMainLoop()
659 // Is a message/event pending?
660 bool wxApp::Pending()
664 return EventAvail( everyEvent
, &event
) ;
667 // Dispatch a message.
668 void wxApp::Dispatch()
673 void wxApp::OnIdle(wxIdleEvent
& event
)
675 static bool s_inOnIdle
= FALSE
;
677 // Avoid recursion (via ProcessEvent default case)
684 // 'Garbage' collection of windows deleted with Close().
685 DeletePendingObjects();
687 // flush the logged messages if any
688 wxLog
*pLog
= wxLog::GetActiveTarget();
689 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
692 // Send OnIdle events to all windows
693 bool needMore
= SendIdleEvents();
696 event
.RequestMore(TRUE
);
698 // If they are pending events, we must process them: pending events are
699 // either events to the threads other than main or events posted with
700 // wxPostEvent() functions
701 wxMacProcessNotifierAndPendingEvents();
711 // Send idle event to all top-level windows
712 bool wxApp::SendIdleEvents()
714 bool needMore
= FALSE
;
715 wxNode
* node
= wxTopLevelWindows
.First();
718 wxWindow
* win
= (wxWindow
*) node
->Data();
719 if (SendIdleEvents(win
))
727 // Send idle event to window and all subwindows
728 bool wxApp::SendIdleEvents(wxWindow
* win
)
730 bool needMore
= FALSE
;
733 event
.SetEventObject(win
);
734 win
->ProcessEvent(event
);
736 if (event
.MoreRequested())
739 wxNode
* node
= win
->GetChildren().First();
742 wxWindow
* win
= (wxWindow
*) node
->Data();
743 if (SendIdleEvents(win
))
751 void wxApp::DeletePendingObjects()
753 wxNode
*node
= wxPendingDelete
.First();
756 wxObject
*obj
= (wxObject
*)node
->Data();
760 if (wxPendingDelete
.Member(obj
))
763 // Deleting one object may have deleted other pending
764 // objects, so start from beginning of list again.
765 node
= wxPendingDelete
.First();
770 wxApp::GetStdIcon(int which
) const
774 case wxICON_INFORMATION
:
775 return wxIcon("wxICON_INFO");
777 case wxICON_QUESTION
:
778 return wxIcon("wxICON_QUESTION");
780 case wxICON_EXCLAMATION
:
781 return wxIcon("wxICON_WARNING");
784 wxFAIL_MSG(wxT("requested non existent standard icon"));
785 // still fall through
788 return wxIcon("wxICON_ERROR");
794 wxLogError(_("Fatal error: exiting"));
800 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
803 GetTopWindow()->Close(TRUE
);
806 // Default behaviour: close the application with prompts. The
807 // user can veto the close, and therefore the end session.
808 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
812 if (!GetTopWindow()->Close(!event
.CanVeto()))
817 extern "C" void wxCYield() ;
823 // Yield to other processes
831 long sleepTime
= 0 ; //::GetCaretTime();
833 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
835 wxTheApp
->MacHandleOneEvent( &event
);
838 wxMacProcessNotifierAndPendingEvents() ;
842 // platform specifics
844 void wxApp::MacSuspend( bool convertClipboard
)
846 // we have to deactive the window manually
848 wxWindow
* window
= GetTopWindow() ;
850 window
->MacActivate( MacGetCurrentEvent() , false ) ;
852 s_lastMouseDown
= 0 ;
853 if( convertClipboard
)
855 MacConvertPrivateToPublicScrap() ;
858 UMAHideFloatingWindows() ;
861 void wxApp::MacResume( bool convertClipboard
)
863 s_lastMouseDown
= 0 ;
864 if( convertClipboard
)
866 MacConvertPublicToPrivateScrap() ;
869 UMAShowFloatingWindows() ;
872 void wxApp::MacConvertPrivateToPublicScrap()
876 void wxApp::MacConvertPublicToPrivateScrap()
880 void wxApp::MacDoOneEvent()
884 long sleepTime
= ::GetCaretTime();
886 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
888 MacHandleOneEvent( &event
);
893 WindowPtr window
= UMAFrontWindow() ;
895 UMAIdleControls( window
) ;
897 wxTheApp
->ProcessIdle() ;
899 if ( event
.what
!= kHighLevelEvent
)
900 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
904 wxMacProcessNotifierAndPendingEvents() ;
907 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
909 m_macCurrentEvent
= ev
;
911 wxApp::sm_lastMessageTime
= ev
->when
;
916 MacHandleMouseDownEvent( ev
) ;
917 if ( ev
->modifiers
& controlKey
)
923 if ( s_lastMouseDown
== 2 )
925 ev
->modifiers
|= controlKey
;
929 ev
->modifiers
&= ~controlKey
;
931 MacHandleMouseUpEvent( ev
) ;
935 MacHandleActivateEvent( ev
) ;
938 MacHandleUpdateEvent( ev
) ;
942 MacHandleKeyDownEvent( ev
) ;
945 MacHandleKeyUpEvent( ev
) ;
948 MacHandleDiskEvent( ev
) ;
951 MacHandleOSEvent( ev
) ;
953 case kHighLevelEvent
:
954 MacHandleHighLevelEvent( ev
) ;
959 wxMacProcessNotifierAndPendingEvents() ;
962 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
964 ::AEProcessAppleEvent( ev
) ;
967 bool s_macIsInModalLoop
= false ;
969 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
971 wxToolTip::RemoveToolTips() ;
974 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
975 WindowAttributes frontWindowAttributes
= NULL
;
977 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
979 short windowPart
= ::FindWindow(ev
->where
, &window
);
980 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
983 GetQDGlobalsScreenBits( &screenBits
);
988 if ( s_macIsInModalLoop
)
994 UInt32 menuresult
= MenuSelect(ev
->where
) ;
995 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1001 SystemClick( ev
, window
) ;
1002 s_lastMouseDown
= 0;
1006 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1012 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1017 Point pt
= { 0, 0 } ;
1019 SetPort( GetWindowPort(window
) ) ;
1021 SetPort( (window
) ) ;
1023 SetOrigin( 0 , 0 ) ;
1024 LocalToGlobal( &pt
) ;
1026 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1027 -1 , wxSIZE_USE_EXISTING
);
1029 s_lastMouseDown
= 0;
1033 if (TrackGoAway(window
, ev
->where
))
1038 s_lastMouseDown
= 0;
1041 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1042 if (growResult
!= 0)
1044 int newWidth
= LoWord(growResult
);
1045 int newHeight
= HiWord(growResult
);
1046 int oldWidth
, oldHeight
;
1051 win
->GetSize(&oldWidth
, &oldHeight
);
1053 newWidth
= oldWidth
;
1055 newHeight
= oldHeight
;
1056 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1059 s_lastMouseDown
= 0;
1063 if (TrackBox(window
, ev
->where
, windowPart
))
1065 // TODO setup size event
1066 ZoomWindow( window
, windowPart
, false ) ;
1071 GetWindowPortBounds(window
, &tempRect
) ;
1072 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1073 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1076 s_lastMouseDown
= 0;
1078 case inCollapseBox
:
1079 // TODO setup size event
1080 s_lastMouseDown
= 0;
1088 SetPort( GetWindowPort(window
) ) ;
1090 SetPort( (window
) ) ;
1092 SetOrigin( 0 , 0 ) ;
1095 if ( window
!= frontWindow
)
1097 if ( s_macIsInModalLoop
)
1101 else if ( UMAIsWindowFloating( window
) )
1104 win
->MacMouseDown( ev
, windowPart
) ;
1108 UMASelectWindow( window
) ;
1114 win
->MacMouseDown( ev
, windowPart
) ;
1123 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1127 short windowPart
= ::FindWindow(ev
->where
, &window
);
1137 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1139 win
->MacMouseUp( ev
, windowPart
) ;
1145 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1154 retval
= WXK_RETURN
;
1169 retval
= WXK_PAGEUP
;
1172 retval
= WXK_PAGEDOWN
;
1175 retval
= WXK_RETURN
;
1230 retval
= WXK_ESCAPE
;
1236 retval
= WXK_RIGHT
;
1245 retval
= WXK_DELETE
;
1253 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1255 wxToolTip::RemoveToolTips() ;
1257 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1258 if ( HiWord( menuresult
) )
1260 if ( !s_macIsInModalLoop
)
1261 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1267 keychar
= short(ev
->message
& charCodeMask
);
1268 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1270 wxWindow
* focus
= wxWindow::FindFocus() ;
1273 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1275 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1276 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1277 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1278 event
.m_altDown
= ev
->modifiers
& optionKey
;
1279 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1280 event
.m_keyCode
= keyval
;
1281 event
.m_x
= ev
->where
.h
;
1282 event
.m_y
= ev
->where
.v
;
1283 event
.m_timeStamp
= ev
->when
;
1284 event
.SetEventObject(focus
);
1285 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1291 wxWindow
*ancestor
= focus
;
1295 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1298 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1299 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1302 if (ancestor->m_isFrame)
1304 ancestor = ancestor->GetParent();
1308 #endif // wxUSE_ACCEL
1312 wxKeyEvent
event(wxEVT_CHAR
);
1313 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1314 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1315 event
.m_altDown
= ev
->modifiers
& optionKey
;
1316 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1317 event
.m_keyCode
= keyval
;
1318 event
.m_x
= ev
->where
.h
;
1319 event
.m_y
= ev
->where
.v
;
1320 event
.m_timeStamp
= ev
->when
;
1321 event
.SetEventObject(focus
);
1322 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1325 (keyval
== WXK_TAB
) &&
1326 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1327 (focus
->GetParent()) &&
1328 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1330 wxNavigationKeyEvent new_event
;
1331 new_event
.SetEventObject( focus
);
1332 new_event
.SetDirection( !event
.ShiftDown() );
1333 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1334 new_event
.SetWindowChange( event
.ControlDown() );
1335 new_event
.SetCurrentFocus( focus
);
1336 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1338 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1340 (keyval
== '.' && event
.ControlDown() ) )
1342 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1343 new_event
.SetEventObject( focus
);
1344 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1350 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1355 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1357 WindowRef window
= (WindowRef
) ev
->message
;
1360 bool activate
= (ev
->modifiers
& activeFlag
) ;
1361 WindowClass wclass
;
1362 UMAGetWindowClass ( window
, &wclass
) ;
1363 if ( wclass
== kFloatingWindowClass
)
1365 // if it is a floater we activate/deactivate the front non-floating window instead
1366 window
= UMAFrontNonFloatingWindow() ;
1368 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1370 win
->MacActivate( ev
, activate
) ;
1374 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1376 WindowRef window
= (WindowRef
) ev
->message
;
1377 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1380 win
->MacUpdate( ev
) ;
1384 // since there is no way of telling this foreign window to update itself
1385 // we have to invalidate the update region otherwise we keep getting the same
1386 // event over and over again
1387 BeginUpdate( window
) ;
1388 EndUpdate( window
) ;
1392 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1394 if ( HiWord( ev
->message
) != noErr
)
1399 SetPt( &point
, 100 , 100 ) ;
1401 err
= DIBadMount( point
, ev
->message
) ;
1402 wxASSERT( err
== noErr
) ;
1407 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1409 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1411 case suspendResumeMessage
:
1413 bool isResuming
= ev
->message
& resumeFlag
;
1414 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1415 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1418 WindowRef oldFrontWindow
= NULL
;
1419 WindowRef newFrontWindow
= NULL
;
1421 // in case we don't take care of activating ourselves, we have to synchronize
1422 // our idea of the active window with the process manager's - which it already activated
1424 if ( !doesActivate
)
1425 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1427 MacResume( convertClipboard
) ;
1429 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1431 if ( oldFrontWindow
)
1433 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1435 win
->MacActivate( ev
, false ) ;
1437 if ( newFrontWindow
)
1439 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1441 win
->MacActivate( ev
, true ) ;
1446 MacSuspend( convertClipboard
) ;
1448 // in case this suspending did close an active window, another one might
1449 // have surfaced -> lets deactivate that one
1451 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1452 if ( newActiveWindow
)
1454 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1456 win
->MacActivate( ev
, false ) ;
1461 case mouseMovedMessage
:
1465 wxWindow
* currentMouseWindow
= NULL
;
1467 MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) , ¤tMouseWindow
) ;
1469 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1471 wxMouseEvent event
;
1473 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1474 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1476 event
.m_leftDown
= isDown
&& !controlDown
;
1477 event
.m_middleDown
= FALSE
;
1478 event
.m_rightDown
= isDown
&& controlDown
;
1479 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1480 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1481 event
.m_altDown
= ev
->modifiers
& optionKey
;
1482 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1483 event
.m_x
= ev
->where
.h
;
1484 event
.m_y
= ev
->where
.v
;
1485 event
.m_timeStamp
= ev
->when
;
1486 event
.SetEventObject(this);
1488 if ( wxWindow::s_lastMouseWindow
)
1490 wxMouseEvent
eventleave(event
) ;
1491 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1492 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1494 if ( currentMouseWindow
)
1496 wxMouseEvent
evententer(event
) ;
1497 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1498 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1500 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1503 short windowPart
= ::FindWindow(ev
->where
, &window
);
1507 // fixes for setting the cursor back from dominic mazzoni
1509 UMAShowArrowCursor();
1512 UMAShowArrowCursor();
1516 if ( s_lastMouseDown
== 0 )
1517 ev
->modifiers
|= btnState
;
1519 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1521 win
->MacMouseMoved( ev
, windowPart
) ;
1523 UMAShowArrowCursor();
1534 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1537 return; // no menu item selected
1539 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1542 Str255 deskAccessoryName
;
1545 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1546 GetPort(&savedPort
);
1547 OpenDeskAcc(deskAccessoryName
);
1553 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1554 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1555 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1561 long wxApp::MacTranslateKey(char key, int mods)
1565 void wxApp::MacAdjustCursor()
1572 wxApp::macAdjustCursor()
1574 if (ev->what != kHighLevelEvent)
1576 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1579 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1580 ::SetCursor(&(qd.arrow));