// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "app.h"
#endif
-#include "wx/defs.h"
+#include "wx/wxprec.h"
#include "wx/window.h"
#include "wx/frame.h"
# if defined(WXMAKINGDLL_CORE)
# include <mach-o/dyld.h>
# endif
+// include hid keyboard
+# include "wx/mac/carbon/private/hid.h"
#else
# include <Sound.h>
# include <Threads.h>
long wxApp::s_macExitMenuItemId = wxID_EXIT ;
wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
+#ifdef __DARWIN__
+ wxHIDKeyboard* wxApp::s_macHIDKeyboard = NULL;
+#endif
+
// Normally we're not a plugin
bool wxApp::sm_isEmbedded = false;
//----------------------------------------------------------------------
DescType returnedType;
Size actualSize;
long itemsInList;
- FSSpec theSpec;
OSErr err;
short i;
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
PSN.lowLongOfPSN = kCurrentProcess ;
SetFrontProcess( &PSN ) ;
- for (i = 1; i <= itemsInList; i++) {
- AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
- (Ptr) & theSpec, sizeof(theSpec), &actualSize);
- wxString fName = wxMacFSSpec2MacFilename(&theSpec);
+ for (i = 1; i <= itemsInList; i++)
+ {
+ wxString fName ;
+
+ FSRef theRef ;
+ AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
+ (Ptr) & theRef, sizeof(theRef), &actualSize);
+ fName = wxMacFSRefToPath( &theRef ) ;
+
MacOpenFile(fName);
}
return noErr;
DescType returnedType;
Size actualSize;
long itemsInList;
- FSSpec theSpec;
OSErr err;
short i;
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
SetFrontProcess( &PSN ) ;
for (i = 1; i <= itemsInList; i++) {
- AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
- (Ptr) & theSpec, sizeof(theSpec), &actualSize);
- wxString fName = wxMacFSSpec2MacFilename(&theSpec);
+ wxString fName ;
+
+ FSRef theRef ;
+ AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
+ (Ptr) & theRef, sizeof(theRef), &actualSize);
+ fName = wxMacFSRefToPath( &theRef ) ;
+
MacPrintFile(fName);
}
return noErr;
static pascal OSStatus
wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
-{
- EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
- EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
- wxTheApp->MacSetCurrentEvent( event , handler ) ;
-
+{
wxMacCarbonEvent cEvent( event ) ;
MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
if ( type )
{
- wxMenuEvent wxevent(type, cmd);
+ wxMenuEvent wxevent(type, cmd, menu);
wxevent.SetEventObject(menu);
wxEvtHandler* handler = menu->GetEventHandler();
}
}
- wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
-
return eventNotHandledErr;
}
pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
+ EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
+ EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
+ wxTheApp->MacSetCurrentEvent( event , handler ) ;
+
OSStatus result = eventNotHandledErr ;
switch( GetEventClass( event ) )
{
result = wxMacAppMenuEventHandler( handler , event , data ) ;
break ;
case kEventClassMouse :
- result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
+ {
+ wxMacCarbonEvent cEvent( event ) ;
+
+ WindowRef window ;
+ Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
+ ::FindWindow(screenMouseLocation, &window);
+ // only send this event in case it had not already been sent to a tlw, as we get
+ // double events otherwise (in case event.skip) was called
+ if ( window == NULL )
+ result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
+ }
break ;
case kEventClassAppleEvent :
{
break ;
}
+ wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
+
return result ;
}
WXIMPORT char std::__throws_bad_alloc ;
#endif
+#if __WXDEBUG__
+
pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,
const char *assertionString, const char *exceptionLabelString,
const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg)
#endif
}
+#endif //__WXDEBUG__
+
bool wxApp::Initialize(int& argc, wxChar **argv)
{
// Mac-specific
SetEventMask( everyEvent ) ;
UMAShowWatchCursor() ;
-#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
- // open shared library resources from here since we don't have
- // __wxinitialize in Mach-O shared libraries
- wxStAppResource::OpenSharedLibraryResource(NULL);
-#endif
-
#ifndef __DARWIN__
# if __option(profile)
ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;
# endif
#endif
-#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
- // close shared library resources from here since we don't have
- // __wxterminate in Mach-O shared libraries
- wxStAppResource::CloseSharedLibraryResource();
+#ifdef __DARWIN__
+ // clean up HID Keyboard
+ if (s_macHIDKeyboard)
+ delete s_macHIDKeyboard;
#endif
UMACleanupToolbox() ;
// misc initialization stuff
//----------------------------------------------------------------------
-// extern variable for shared library resource id
-// need to be able to find it with NSLookupAndBindSymbol
-short gSharedLibraryResource = kResFileNotOpened ;
-
-#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
-CFBundleRef gSharedLibraryBundle = NULL;
-#endif /* WXMAKINGDLL_CORE && __DARWIN__ */
-
-wxStAppResource::wxStAppResource()
-{
- m_currentRefNum = CurResFile() ;
- if ( gSharedLibraryResource != kResFileNotOpened )
- {
- UseResFile( gSharedLibraryResource ) ;
- }
-}
-
-wxStAppResource::~wxStAppResource()
-{
- if ( m_currentRefNum != kResFileNotOpened )
- {
- UseResFile( m_currentRefNum ) ;
- }
-}
-
-void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
-{
- gSharedLibraryResource = kResFileNotOpened;
-
-#ifdef WXMAKINGDLL_CORE
- if ( initBlock != NULL ) {
- const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
- FSSpec *fileSpec = NULL;
-
- if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
- fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
- }
- else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
- fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
- }
-
- if (fileSpec != NULL) {
- gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
- }
- }
- else {
-#ifdef __DARWIN__
- // Open the shared library resource file if it is not yet open
- NSSymbol theSymbol;
- NSModule theModule;
- const char *theLibPath;
-
- gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
- if (gSharedLibraryBundle != NULL) {
- // wxWidgets has been bundled into a framework
- // load the framework resources
-
- gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
- }
- else {
- // wxWidgets is a simple dynamic shared library
- // load the resources from the data fork of a separate resource file
- wxString theResPath;
- wxString theName;
- FSRef theResRef;
- OSErr theErr = noErr;
-
- // get the library path
- theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
- theModule = NSModuleForSymbol(theSymbol);
- theLibPath = NSLibraryNameForModule(theModule);
-
- // if we call wxLogDebug from here then, as wxTheApp hasn't been
- // created yet when we're called from wxApp::Initialize(), wxLog
- // is going to create a default stderr-based log target instead of
- // the expected normal GUI one -- don't do it, if we really want
- // to see this message just use fprintf() here
-#if 0
- wxLogDebug( wxT("wxMac library installation name is '%s'"),
- theLibPath );
-#endif
-
- // allocate copy to replace .dylib.* extension with .rsrc
- if (theLibPath != NULL) {
-#if wxUSE_UNICODE
- theResPath = wxString(theLibPath, wxConvLocal);
-#else
- theResPath = wxString(theLibPath);
-#endif
- // replace '_core' with '' in case of multi-lib build
- theResPath.Replace(wxT("_core"), wxEmptyString);
- // replace ".dylib" shared library extension with ".rsrc"
- theResPath.Replace(wxT(".dylib"), wxT(".rsrc"));
- // Find the begining of the filename
- theName = theResPath.AfterLast('/');
-
-#if 0
- wxLogDebug( wxT("wxMac resources file name is '%s'"),
- theResPath.mb_str() );
-#endif
-
- theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false);
- if (theErr != noErr) {
- // try in current directory (using name only)
- theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false);
- }
-
- // open the resource file
- if (theErr == noErr) {
- theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
- &gSharedLibraryResource);
- }
- if (theErr != noErr) {
-#ifdef __WXDEBUG__
- wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
- theResPath.mb_str() );
-#endif // __WXDEBUG__
- }
-
- }
- }
-#endif /* __DARWIN__ */
- }
-#endif /* WXMAKINGDLL_CORE */
-}
-
-void wxStAppResource::CloseSharedLibraryResource()
-{
-#ifdef WXMAKINGDLL_CORE
- // Close the shared library resource file
- if (gSharedLibraryResource != kResFileNotOpened) {
-#ifdef __DARWIN__
- if (gSharedLibraryBundle != NULL) {
- CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
- gSharedLibraryResource);
- gSharedLibraryBundle = NULL;
- }
- else
-#endif /* __DARWIN__ */
- {
- CloseResFile(gSharedLibraryResource);
- }
- gSharedLibraryResource = kResFileNotOpened;
- }
-#endif /* WXMAKINGDLL_CORE */
-}
-
#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
// for shared libraries we have to manually get the correct resource
pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
{
- wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
return __initialize( theInitBlock ) ;
}
pascal void __wxterminate(void)
{
- wxStAppResource::CloseSharedLibraryResource() ;
__terminate() ;
}
bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
{
-//#ifdef __DARWIN__
-// wxHIDKeyboard keyboard;
-// return keyboard.IsActive(key);
-//#else
-// TODO: Have it use HID Manager on OSX...
+#ifdef __DARWIN__
+ // Startup HID keyboard for getting key codes on DARWIN
+ if (!wxApp::s_macHIDKeyboard)
+ {
+ wxApp::s_macHIDKeyboard = new wxHIDKeyboard();
+ wxApp::s_macHIDKeyboard->Create();
+ }
+
+ return wxApp::s_macHIDKeyboard->IsActive(key);
+#else
//if OS X > 10.2 (i.e. 10.2.x)
//a known apple bug prevents the system from determining led
//states with GetKeys... can only determine caps lock led
// KeyMapByteArray keymap;
// GetKeys((BigEndianLong*)keymap);
// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
-//#endif
+#endif
}
event.m_x = wherex;
event.m_y = wherey;
- event.m_timeStamp = when;
+ event.SetTimestamp(when);
event.SetEventObject(focus);
handled = focus->GetEventHandler()->ProcessEvent( event ) ;
if ( handled && event.GetSkipped() )
event.m_x = wherex;
event.m_y = wherey;
- event.m_timeStamp = when;
+ event.SetTimestamp(when);
event.SetEventObject(focus);
handled = focus->GetEventHandler()->ProcessEvent( event ) ;