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