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( event
, reply
) ;
95 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
97 wxApp
* app
= (wxApp
*) refcon
;
98 return wxTheApp
->MacHandleAEOApp( event
, reply
) ;
101 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
103 wxApp
* app
= (wxApp
*) refcon
;
104 return wxTheApp
->MacHandleAEPDoc( event
, reply
) ;
107 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
109 wxApp
* app
= (wxApp
*) refcon
;
110 return wxTheApp
->MacHandleAEQuit( event
, reply
) ;
113 OSErr
wxApp::MacHandleAEODoc(AppleEvent
*event
, AppleEvent
*reply
)
115 ProcessSerialNumber PSN
;
116 PSN
.highLongOfPSN
= 0 ;
117 PSN
.lowLongOfPSN
= kCurrentProcess
;
118 SetFrontProcess( &PSN
) ;
122 OSErr
wxApp::MacHandleAEPDoc(AppleEvent
*event
, AppleEvent
*reply
)
127 OSErr
wxApp::MacHandleAEOApp(AppleEvent
*event
, AppleEvent
*reply
)
132 OSErr
wxApp::MacHandleAEQuit(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
);
514 ::DisposeRgn(s_macCursorRgn
);
521 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
524 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
525 // This seems to be necessary since there are 'rogue'
526 // objects present at this point (perhaps global objects?)
527 // Setting a checkpoint will ignore them as far as the
528 // memory checking facility is concerned.
529 // Of course you may argue that memory allocated in globals should be
530 // checked, but this is a reasonable compromise.
531 wxDebugContext::SetCheckpoint();
534 if (!wxApp::Initialize())
536 // create the application object or ensure that one already exists
539 // The app may have declared a global application object, but we recommend
540 // the IMPLEMENT_APP macro is used instead, which sets an initializer
541 // function for delayed, dynamic app object construction.
542 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
543 wxT("No initializer - use IMPLEMENT_APP macro.") );
545 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
548 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
551 argc
= 0 ; // currently we don't support files as parameters
554 wxTheApp
->argc
= argc
;
555 wxTheApp
->argv
= argv
;
557 // GUI-specific initialization, such as creating an app context.
558 wxTheApp
->OnInitGui();
560 // we could try to get the open apple events here to adjust argc and argv better
563 // Here frames insert themselves automatically
564 // into wxTopLevelWindows by getting created
569 if ( wxTheApp
->OnInit() )
573 retValue
= wxTheApp
->OnRun();
576 // We want to initialize, but not run or exit immediately.
579 //else: app initialization failed, so we skipped OnRun()
581 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
584 // Forcibly delete the window.
585 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
586 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
588 topWindow
->Close(TRUE
);
589 wxTheApp
->DeletePendingObjects();
594 wxTheApp
->SetTopWindow(NULL
);
605 // Static member initialization
606 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
613 m_wantDebugOutput
= TRUE
;
618 m_printMode
= wxPRINT_WINDOWS
;
619 m_exitOnFrameDelete
= TRUE
;
623 bool wxApp::Initialized()
631 int wxApp::MainLoop()
643 // Returns TRUE if more time is needed.
644 bool wxApp::ProcessIdle()
647 event
.SetEventObject(this);
650 return event
.MoreRequested();
653 void wxApp::ExitMainLoop()
658 // Is a message/event pending?
659 bool wxApp::Pending()
663 return EventAvail( everyEvent
, &event
) ;
666 // Dispatch a message.
667 void wxApp::Dispatch()
672 void wxApp::OnIdle(wxIdleEvent
& event
)
674 static bool s_inOnIdle
= FALSE
;
676 // Avoid recursion (via ProcessEvent default case)
683 // 'Garbage' collection of windows deleted with Close().
684 DeletePendingObjects();
686 // flush the logged messages if any
687 wxLog
*pLog
= wxLog::GetActiveTarget();
688 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
691 // Send OnIdle events to all windows
692 bool needMore
= SendIdleEvents();
695 event
.RequestMore(TRUE
);
697 // If they are pending events, we must process them: pending events are
698 // either events to the threads other than main or events posted with
699 // wxPostEvent() functions
700 wxMacProcessNotifierAndPendingEvents();
710 // Send idle event to all top-level windows
711 bool wxApp::SendIdleEvents()
713 bool needMore
= FALSE
;
714 wxNode
* node
= wxTopLevelWindows
.First();
717 wxWindow
* win
= (wxWindow
*) node
->Data();
718 if (SendIdleEvents(win
))
726 // Send idle event to window and all subwindows
727 bool wxApp::SendIdleEvents(wxWindow
* win
)
729 bool needMore
= FALSE
;
732 event
.SetEventObject(win
);
733 win
->ProcessEvent(event
);
735 if (event
.MoreRequested())
738 wxNode
* node
= win
->GetChildren().First();
741 wxWindow
* win
= (wxWindow
*) node
->Data();
742 if (SendIdleEvents(win
))
750 void wxApp::DeletePendingObjects()
752 wxNode
*node
= wxPendingDelete
.First();
755 wxObject
*obj
= (wxObject
*)node
->Data();
759 if (wxPendingDelete
.Member(obj
))
762 // Deleting one object may have deleted other pending
763 // objects, so start from beginning of list again.
764 node
= wxPendingDelete
.First();
769 wxApp::GetStdIcon(int which
) const
773 case wxICON_INFORMATION
:
774 return wxIcon("wxICON_INFO");
776 case wxICON_QUESTION
:
777 return wxIcon("wxICON_QUESTION");
779 case wxICON_EXCLAMATION
:
780 return wxIcon("wxICON_WARNING");
783 wxFAIL_MSG(wxT("requested non existent standard icon"));
784 // still fall through
787 return wxIcon("wxICON_ERROR");
793 wxLogError(_("Fatal error: exiting"));
799 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
802 GetTopWindow()->Close(TRUE
);
805 // Default behaviour: close the application with prompts. The
806 // user can veto the close, and therefore the end session.
807 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
811 if (!GetTopWindow()->Close(!event
.CanVeto()))
816 extern "C" void wxCYield() ;
822 // Yield to other processes
830 long sleepTime
= 0 ; //::GetCaretTime();
832 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
834 wxTheApp
->MacHandleOneEvent( &event
);
837 wxMacProcessNotifierAndPendingEvents() ;
841 // platform specifics
843 void wxApp::MacSuspend( bool convertClipboard
)
845 // we have to deactive the window manually
847 wxWindow
* window
= GetTopWindow() ;
849 window
->MacActivate( MacGetCurrentEvent() , false ) ;
851 s_lastMouseDown
= 0 ;
852 if( convertClipboard
)
854 MacConvertPrivateToPublicScrap() ;
857 UMAHideFloatingWindows() ;
860 void wxApp::MacResume( bool convertClipboard
)
862 s_lastMouseDown
= 0 ;
863 if( convertClipboard
)
865 MacConvertPublicToPrivateScrap() ;
868 UMAShowFloatingWindows() ;
871 void wxApp::MacConvertPrivateToPublicScrap()
875 void wxApp::MacConvertPublicToPrivateScrap()
879 void wxApp::MacDoOneEvent()
883 long sleepTime
= ::GetCaretTime();
885 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
887 MacHandleOneEvent( &event
);
892 WindowPtr window
= UMAFrontWindow() ;
894 UMAIdleControls( window
) ;
896 wxTheApp
->ProcessIdle() ;
898 if ( event
.what
!= kHighLevelEvent
)
899 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
903 wxMacProcessNotifierAndPendingEvents() ;
906 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
908 m_macCurrentEvent
= ev
;
910 wxApp::sm_lastMessageTime
= ev
->when
;
915 MacHandleMouseDownEvent( ev
) ;
916 if ( ev
->modifiers
& controlKey
)
922 if ( s_lastMouseDown
== 2 )
924 ev
->modifiers
|= controlKey
;
928 ev
->modifiers
&= ~controlKey
;
930 MacHandleMouseUpEvent( ev
) ;
934 MacHandleActivateEvent( ev
) ;
937 MacHandleUpdateEvent( ev
) ;
941 MacHandleKeyDownEvent( ev
) ;
944 MacHandleKeyUpEvent( ev
) ;
947 MacHandleDiskEvent( ev
) ;
950 MacHandleOSEvent( ev
) ;
952 case kHighLevelEvent
:
953 MacHandleHighLevelEvent( ev
) ;
958 wxMacProcessNotifierAndPendingEvents() ;
961 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
963 ::AEProcessAppleEvent( ev
) ;
966 bool s_macIsInModalLoop
= false ;
968 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
970 wxToolTip::RemoveToolTips() ;
973 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
974 WindowAttributes frontWindowAttributes
= NULL
;
976 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
978 short windowPart
= ::FindWindow(ev
->where
, &window
);
979 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
982 GetQDGlobalsScreenBits( &screenBits
);
987 if ( s_macIsInModalLoop
)
993 UInt32 menuresult
= MenuSelect(ev
->where
) ;
994 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1000 SystemClick( ev
, window
) ;
1001 s_lastMouseDown
= 0;
1005 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1011 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1016 Point pt
= { 0, 0 } ;
1018 SetPort( GetWindowPort(window
) ) ;
1020 SetPort( (window
) ) ;
1022 SetOrigin( 0 , 0 ) ;
1023 LocalToGlobal( &pt
) ;
1025 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1026 -1 , wxSIZE_USE_EXISTING
);
1028 s_lastMouseDown
= 0;
1032 if (TrackGoAway(window
, ev
->where
))
1037 s_lastMouseDown
= 0;
1040 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1041 if (growResult
!= 0)
1043 int newWidth
= LoWord(growResult
);
1044 int newHeight
= HiWord(growResult
);
1045 int oldWidth
, oldHeight
;
1047 win
->GetSize(&oldWidth
, &oldHeight
);
1049 newWidth
= oldWidth
;
1051 newHeight
= oldHeight
;
1054 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1056 s_lastMouseDown
= 0;
1060 if (TrackBox(window
, ev
->where
, windowPart
))
1062 // TODO setup size event
1063 ZoomWindow( window
, windowPart
, false ) ;
1068 GetWindowPortBounds(window
, &tempRect
) ;
1069 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1070 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1073 s_lastMouseDown
= 0;
1075 case inCollapseBox
:
1076 // TODO setup size event
1077 s_lastMouseDown
= 0;
1085 SetPort( GetWindowPort(window
) ) ;
1087 SetPort( (window
) ) ;
1089 SetOrigin( 0 , 0 ) ;
1092 if ( window
!= frontWindow
)
1094 if ( s_macIsInModalLoop
)
1098 else if ( UMAIsWindowFloating( window
) )
1101 win
->MacMouseDown( ev
, windowPart
) ;
1105 UMASelectWindow( window
) ;
1111 win
->MacMouseDown( ev
, windowPart
) ;
1120 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1124 short windowPart
= ::FindWindow(ev
->where
, &window
);
1134 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1136 win
->MacMouseUp( ev
, windowPart
) ;
1142 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1151 retval
= WXK_RETURN
;
1166 retval
= WXK_PAGEUP
;
1169 retval
= WXK_PAGEDOWN
;
1172 retval
= WXK_RETURN
;
1227 retval
= WXK_ESCAPE
;
1233 retval
= WXK_RIGHT
;
1242 retval
= WXK_DELETE
;
1250 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1252 wxToolTip::RemoveToolTips() ;
1254 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1255 if ( HiWord( menuresult
) )
1256 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1261 keychar
= short(ev
->message
& charCodeMask
);
1262 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1264 wxWindow
* focus
= wxWindow::FindFocus() ;
1267 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1269 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1270 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1271 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1272 event
.m_altDown
= ev
->modifiers
& optionKey
;
1273 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1274 event
.m_keyCode
= keyval
;
1275 event
.m_x
= ev
->where
.h
;
1276 event
.m_y
= ev
->where
.v
;
1277 event
.m_timeStamp
= ev
->when
;
1278 event
.SetEventObject(focus
);
1279 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1285 wxWindow
*ancestor
= focus
;
1289 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1292 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1293 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1296 if (ancestor->m_isFrame)
1298 ancestor = ancestor->GetParent();
1302 #endif // wxUSE_ACCEL
1306 wxKeyEvent
event(wxEVT_CHAR
);
1307 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1308 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1309 event
.m_altDown
= ev
->modifiers
& optionKey
;
1310 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1311 event
.m_keyCode
= keyval
;
1312 event
.m_x
= ev
->where
.h
;
1313 event
.m_y
= ev
->where
.v
;
1314 event
.m_timeStamp
= ev
->when
;
1315 event
.SetEventObject(focus
);
1316 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1319 (keyval
== WXK_TAB
) &&
1320 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1321 (focus
->GetParent()) &&
1322 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1324 wxNavigationKeyEvent new_event
;
1325 new_event
.SetEventObject( focus
);
1326 new_event
.SetDirection( !event
.ShiftDown() );
1327 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1328 new_event
.SetWindowChange( event
.ControlDown() );
1329 new_event
.SetCurrentFocus( focus
);
1330 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1332 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1334 (keyval
== '.' && event
.ControlDown() ) )
1336 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1337 new_event
.SetEventObject( focus
);
1338 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1344 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1349 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1351 WindowRef window
= (WindowRef
) ev
->message
;
1354 bool activate
= (ev
->modifiers
& activeFlag
) ;
1355 WindowClass wclass
;
1356 UMAGetWindowClass ( window
, &wclass
) ;
1357 if ( wclass
== kFloatingWindowClass
)
1359 // if it is a floater we activate/deactivate the front non-floating window instead
1360 window
= UMAFrontNonFloatingWindow() ;
1362 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1364 win
->MacActivate( ev
, activate
) ;
1368 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1370 WindowRef window
= (WindowRef
) ev
->message
;
1371 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1374 win
->MacUpdate( ev
) ;
1378 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1380 if ( HiWord( ev
->message
) != noErr
)
1385 SetPt( &point
, 100 , 100 ) ;
1387 err
= DIBadMount( point
, ev
->message
) ;
1388 wxASSERT( err
== noErr
) ;
1393 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1395 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1397 case suspendResumeMessage
:
1399 bool isResuming
= ev
->message
& resumeFlag
;
1400 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1401 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1404 WindowRef oldFrontWindow
= NULL
;
1405 WindowRef newFrontWindow
= NULL
;
1407 // in case we don't take care of activating ourselves, we have to synchronize
1408 // our idea of the active window with the process manager's - which it already activated
1410 if ( !doesActivate
)
1411 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1413 MacResume( convertClipboard
) ;
1415 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1417 if ( oldFrontWindow
)
1419 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1421 win
->MacActivate( ev
, false ) ;
1423 if ( newFrontWindow
)
1425 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1427 win
->MacActivate( ev
, true ) ;
1432 MacSuspend( convertClipboard
) ;
1434 // in case this suspending did close an active window, another one might
1435 // have surfaced -> lets deactivate that one
1437 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1438 if ( newActiveWindow
)
1440 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1442 win
->MacActivate( ev
, false ) ;
1447 case mouseMovedMessage
:
1451 wxWindow
* currentMouseWindow
= NULL
;
1453 MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) , ¤tMouseWindow
) ;
1455 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1457 wxMouseEvent event
;
1459 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1460 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1462 event
.m_leftDown
= isDown
&& !controlDown
;
1463 event
.m_middleDown
= FALSE
;
1464 event
.m_rightDown
= isDown
&& controlDown
;
1465 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1466 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1467 event
.m_altDown
= ev
->modifiers
& optionKey
;
1468 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1469 event
.m_x
= ev
->where
.h
;
1470 event
.m_y
= ev
->where
.v
;
1471 event
.m_timeStamp
= ev
->when
;
1472 event
.SetEventObject(this);
1474 if ( wxWindow::s_lastMouseWindow
)
1476 wxMouseEvent
eventleave(event
) ;
1477 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1478 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1480 if ( currentMouseWindow
)
1482 wxMouseEvent
evententer(event
) ;
1483 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1484 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1486 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1489 short windowPart
= ::FindWindow(ev
->where
, &window
);
1499 if ( s_lastMouseDown
== 0 )
1500 ev
->modifiers
|= btnState
;
1502 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1504 win
->MacMouseMoved( ev
, windowPart
) ;
1514 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1517 return; // no menu item selected
1519 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1522 Str255 deskAccessoryName
;
1525 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1526 GetPort(&savedPort
);
1527 OpenDeskAcc(deskAccessoryName
);
1533 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1534 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1535 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1541 long wxApp::MacTranslateKey(char key, int mods)
1545 void wxApp::MacAdjustCursor()
1552 wxApp::macAdjustCursor()
1554 if (ev->what != kHighLevelEvent)
1556 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1559 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1560 ::SetCursor(&(qd.arrow));