void wxMacCarbonPrintData::TransferFrom( wxPrintData* data ) { ValidateOrCreate() ; PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ; PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; // collate cannot be set #if 0 // not yet tested if ( !m_printerName.empty() ) PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ; #endif PMColorMode color ; PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; if ( data->GetColour() ) { if ( color == kPMBlackAndWhite ) PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; } else PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; // PMDuplexMode not yet accessible via API // PMQualityMode not yet accessible via API // todo paperSize }
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data ) { ValidateOrCreate() ; PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ; PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; // collate cannot be set #if 0 // not yet tested if ( m_printerName.Length() > 0 ) PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ; #endif PMColorMode color ; PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; if ( data.GetColour() ) { if ( color == kPMBlackAndWhite ) PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; } else PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; // PMDuplexMode not yet accessible via API // PMQualityMode not yet accessible via API // todo paperSize PMResolution res; PMPrinter printer; PMTag tag = kPMMaxSquareResolution; PMSessionGetCurrentPrinter(m_macPrintSession, &printer); PMPrinterGetPrinterResolution(printer, tag, &res); PMSetResolution((PMPageFormat) m_macPageFormat, &res); return true ; }
static wxString BundleRelativeURLToPath(CFURLRef relativeURL) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL); wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL")); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle); CFRelease(absoluteURL); return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); }
wxSize wxListBox::DoGetBestSize() const { int lbWidth = 100; // some defaults int lbHeight = 110; int wLine; { wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { ::TextFont( m_font.MacGetFontNum() ) ; ::TextSize( m_font.MacGetFontSize() ) ; ::TextFace( m_font.MacGetFontStyle() ) ; } else { ::TextFont( kFontIDMonaco ) ; ::TextSize( 9 ); ::TextFace( 0 ) ; } // Find the widest line for(int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); #if wxUSE_UNICODE Point bounds={0,0} ; SInt16 baseline ; ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); wLine = bounds.h ; #else wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } // Add room for the scrollbar lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); // And just a bit more int cy = 12 ; int cx = ::TextWidth( "X" , 0 , 1 ) ; lbWidth += cx ; // don't make the listbox too tall (limit height to around 10 items) but don't // make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); } return wxSize(lbWidth, lbHeight); }
void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding) { wxString str = wxStripMenuCodes( title ) ; #if TARGET_CARBON SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ; #else Str255 ptitle ; wxMacStringToPascal( str , ptitle ) ; SetMenuItemText( menu , item , ptitle ) ; #endif }
/// Set File to hash in wxTextCtrl void AlcFrame::SetFileToHash() { #ifdef __WXMSW__ wxString browseroot; LPITEMIDLIST pidl; HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl); if (SUCCEEDED(hr)) { if (!SHGetPathFromIDList(pidl, wxStringBuffer(browseroot, MAX_PATH))) { browseroot = wxFileName::GetHomeDir(); } } else { browseroot = wxFileName::GetHomeDir(); } if (pidl) { LPMALLOC pMalloc; SHGetMalloc(&pMalloc); if (pMalloc) { pMalloc->Free(pidl); pMalloc->Release(); } } #elif defined(__WXMAC__) FSRef fsRef; wxString browseroot; if (FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &fsRef) == noErr) { CFURLRef urlRef = CFURLCreateFromFSRef(NULL, &fsRef); CFStringRef cfString = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); CFRelease(urlRef) ; #if wxCHECK_VERSION(2, 9, 0) browseroot = wxCFStringRef(cfString).AsString(wxLocale::GetSystemEncoding()); #else browseroot = wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding()); #endif } else { browseroot = wxFileName::GetHomeDir(); } #else wxString browseroot = wxFileName::GetHomeDir(); #endif const wxString & filename = wxFileSelector (_("Select the file you want to compute the eD2k link"), browseroot, wxEmptyString, wxEmptyString, wxT("*.*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST, this); if (!filename.empty ()) { m_inputFileTextCtrl->SetValue(filename); } }
void wxDataFormat::SetId( const wxChar* zId ) { m_type = wxDF_PRIVATE; m_id = zId; if ( m_format != 0 ) { CFRelease( (CFStringRef) m_format ); m_format = 0; } // since it is private, no need to conform to anything ... m_format = (long) wxMacCFStringHolder(m_id).Detach(); }
void wxFontEnumeratorHelper::DoEnumerate() { MenuHandle menu ; short lines ; menu = NewMenu( 32000 , "\pFont" ) ; AppendResMenu( menu , 'FONT' ) ; lines = CountMenuItems( menu ) ; for ( int i = 1 ; i < lines+1 ; i ++ ) { wxString c_name ; #if TARGET_API_MAC_CARBON CFStringRef menutext ; c_name = wxEmptyString ; if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr ) { c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding()); } #else Str255 p_name; GetMenuItemText( menu , i , p_name ) ; c_name = wxMacMakeStringFromPascal( p_name ); #endif /* if ( m_fixedOnly ) { // check that it's a fixed pitch font (there is *no* error here, the // flag name is misleading!) if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) { // not a fixed pitch font return TRUE; } } if ( m_charset != -1 ) { // check that we have the right encoding if ( lf->lfCharSet != m_charset ) { return TRUE; } } */ m_fontEnum->OnFacename( c_name ) ; } DisposeMenu( menu ) ; }
// returns e.g. "/Applications/appname.app/Contents/Resources" if application is bundled, // or the directory of the binary, e.g. "/usr/local/bin/appname", if it is *not* bundled. static wxString GetResourcesDir() { CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLRef absoluteURL = CFURLCopyAbsoluteURL(resourcesURL); // relative -> absolute CFRelease(resourcesURL); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(3, 0, 0) return wxCFStringRef(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #else return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #endif }
wxSize wxChoice::DoGetBestSize() const { int lbWidth = GetCount() > 0 ? 20 : 100; // some defaults int lbHeight = 20; int wLine; #if TARGET_CARBON long metric ; GetThemeMetric(kThemeMetricPopupButtonHeight , &metric ); lbHeight = metric ; #endif { wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { ::TextFont( m_font.MacGetFontNum() ) ; ::TextSize( m_font.MacGetFontSize() ) ; ::TextFace( m_font.MacGetFontStyle() ) ; } else { ::TextFont( kFontIDMonaco ) ; ::TextSize( 9 ); ::TextFace( 0 ) ; } // Find the widest line for(int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); #if wxUSE_UNICODE Point bounds={0,0} ; SInt16 baseline ; ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); wLine = bounds.h ; #else wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } // Add room for the popup arrow lbWidth += 2 * lbHeight ; // And just a bit more int cx = ::TextWidth( "X" , 0 , 1 ) ; lbWidth += cx ; } return wxSize(lbWidth, lbHeight); }
MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding ) { wxString str = wxStripMenuCodes( title ) ; MenuRef menu ; #if TARGET_CARBON CreateNewMenu( id , 0 , &menu ) ; SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ; #else Str255 ptitle ; wxMacStringToPascal( str , ptitle ) ; menu = ::NewMenu( id , ptitle ) ; #endif return menu ; }
pascal Boolean CrossPlatformFilterCallback ( AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode ) { bool display = true; OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ; if (filterMode == kNavFilteringBrowserList) { NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ; if ( !theInfo->isFolder ) { if (theItem->descriptorType == typeFSS ) { FSSpec spec; memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ; wxString file = wxMacMakeStringFromPascal( spec.name ) ; display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; } #if TARGET_CARBON else if ( theItem->descriptorType == typeFSRef ) { FSRef fsref ; memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ; CFURLRef fullURLRef; fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref); #ifdef __UNIX__ CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; #else CFURLPathStyle pathstyle = kCFURLHFSPathStyle; #endif CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); ::CFRelease( fullURLRef ) ; wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding()); display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; } #endif } } return display; }
void wxDataFormat::SetId( NativeFormat format ) { if ( m_format != 0 ) { CFRelease( (CFStringRef) m_format ); m_format = 0; } m_format = (NativeFormat) CFStringCreateCopy(NULL, (CFStringRef)format); if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.utf16-plain-text") ) ) { m_type = wxDF_UNICODETEXT; } else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.plain-text") ) ) { m_type = wxDF_TEXT; } #if wxMAC_USE_CORE_GRAPHICS else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.tiff") ) ) { m_type = wxDF_BITMAP; } else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("com.adobe.pdf") ) ) { m_type = wxDF_METAFILE; } #else else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("com.apple.pict") ) ) { m_type = wxDF_METAFILE; } #endif else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.file-url") ) ) { m_type = wxDF_FILENAME; } else { m_type = wxDF_PRIVATE; m_id = wxMacCFStringHolder( (CFStringRef) CFRetain((CFStringRef) format )).AsString(); } }
bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir) { wxString dir; m_localTemplate = false; DebugShow(wxT("looking for template: ") + templateName + wxT("\n")); #ifdef __WXMAC__ CFURLRef amuleBundleUrl; OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, // This magic string is the bundle identifier in aMule.app's Info.plist CFSTR("org.amule.aMule"), NULL, NULL, &amuleBundleUrl); if (status == noErr && amuleBundleUrl) { CFBundleRef amuleBundle = CFBundleCreate(NULL, amuleBundleUrl); CFRelease(amuleBundleUrl); if (amuleBundle) { CFURLRef webserverDirUrl = CFBundleCopyResourceURL( amuleBundle, CFSTR("webserver"), NULL, NULL); CFRelease(amuleBundle); if (webserverDirUrl) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(webserverDirUrl); CFRelease(webserverDirUrl); if (absoluteURL) { CFStringRef pathString = CFURLCopyFileSystemPath( absoluteURL, kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(2, 9, 0) dir = wxCFStringRef(pathString). AsString(wxLocale::GetSystemEncoding()); #else dir = wxMacCFStringHolder(pathString). AsString(wxLocale::GetSystemEncoding()); #endif if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } } } } } #endif dir = GetConfigDir(wxT("remote.conf")) + wxT("webserver"); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; m_localTemplate = true; return true; } #ifdef WEBSERVERDIR dir = wxT(WEBSERVERDIR); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } #endif dir = wxStandardPaths::Get().GetResourcesDir(); // Returns 'aMule' when we use 'amule' elsewhere #if !defined(__WXMSW__) && !defined(__WXMAC__) dir = dir.BeforeLast(wxFileName::GetPathSeparator()); dir = JoinPaths(dir, wxT("amule")); #endif dir = JoinPaths(dir, wxT("webserver")); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } // template not found. reverting to default const wxChar* const defaultTemplateName = wxT("default"); if ( templateName == defaultTemplateName ) { return false; } Show(wxT("Template ") + templateName + wxT(" not found, reverting to default\n\n")); return GetTemplateDir(defaultTemplateName, templateDir); }
bool wxSound::DoPlay(unsigned flags) const { Stop(); Movie movie; switch(m_type) { case wxSound_MEMORY: { if (!wxInitQT()) return false; Handle myHandle, dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; myHandle = NewHandleClear((Size)m_waveLength); BlockMove(m_hSnd, *myHandle, m_waveLength); err = PtrToHand(&myHandle, &dataRef, sizeof(Handle)); if (memcmp(&m_hSnd[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&m_hSnd[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&m_hSnd[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(movie, kFullVolume); GoToBeginningOfMovie(movie); DisposeHandle(myHandle); } break; case wxSound_RESOURCE: { SoundComponentData data; unsigned long numframes, offset; ParseSndHeader((SndListHandle)m_hSnd, &data, &numframes, &offset); //m_waveLength = numFrames * data.numChannels; SndChannelPtr pSndChannel; SndNewChannel(&pSndChannel, sampledSynth, initNoInterp + (data.numChannels == 1 ? initMono : initStereo), NULL); if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr) return false; if (flags & wxSOUND_ASYNC) { lastSoundTimer = ((wxSMTimer*&)m_pTimer) = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else SndDisposeChannel(pSndChannel, TRUE); return true; } break; case wxSound_FILE: { if (!wxInitQT()) return false; OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxMacCFStringHolder(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } break; default: return false; }//end switch(m_type) //Start the movie! StartMovie(movie); if (flags & wxSOUND_ASYNC) { //Start timer and play movie asyncronously lastSoundTimer = ((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(movie)) MoviesTask(movie, 1); DisposeMovie(movie); } return true; }
bool wxDataObject::GetFromPasteboard( void * pb ) { PasteboardRef pasteboard = (PasteboardRef) pb; size_t formatcount = GetFormatCount() + 1; wxDataFormat *array = new wxDataFormat[ formatcount ]; array[0] = GetPreferredFormat(); GetAllFormats( &array[1] ); ItemCount itemCount = 0; wxString filenamesPassed; bool transferred = false; // we synchronize here once again, so we don't mind which flags get returned PasteboardSynchronize( pasteboard ); OSStatus err = PasteboardGetItemCount( pasteboard, &itemCount ); if ( err == noErr ) { for (size_t i = 0; !transferred && i < formatcount; i++) { // go through the data in our order of preference wxDataFormat dataFormat = array[ i ]; for( UInt32 itemIndex = 1; itemIndex <= itemCount && transferred == false ; itemIndex++ ) { PasteboardItemID itemID = 0; CFArrayRef flavorTypeArray = NULL; CFIndex flavorCount = 0; err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID ); if ( err != noErr ) continue; err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray ); if ( err != noErr ) continue; flavorCount = CFArrayGetCount( flavorTypeArray ); for( CFIndex flavorIndex = 0; !transferred && flavorIndex < flavorCount ; flavorIndex++ ) { CFStringRef flavorType; CFDataRef flavorData; CFIndex flavorDataSize; flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray, flavorIndex ); // avoid utf8 being treated closer to plain-text than unicode by forcing a conversion if ( UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text") ) ) { flavorType = CFSTR("public.utf16-plain-text"); } wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType ); if ( dataFormat == flavorFormat ) { err = PasteboardCopyItemFlavorData( pasteboard, itemID, flavorType , &flavorData ); if ( err == noErr ) { flavorDataSize = CFDataGetLength( flavorData ); if (dataFormat.GetType() == wxDF_FILENAME ) { // revert the translation and decomposition to arrive at a proper utf8 string again CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL ); CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle ); CFRelease( url ); CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); CFRelease( cfString ); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); wxString path = wxMacCFStringHolder(cfMutableString).AsString(); if (!path.empty()) filenamesPassed += path + wxT("\n"); } else { // because some data implementation expect trailing a trailing NUL, we add some headroom void *buf = malloc( flavorDataSize + 4 ); if ( buf ) { memset( buf, 0, flavorDataSize + 4 ); memcpy( buf, CFDataGetBytePtr( flavorData ), flavorDataSize ); if (dataFormat.GetType() == wxDF_TEXT) wxMacConvertNewlines10To13( (char*) buf ); SetData( flavorFormat, flavorDataSize, buf ); transferred = true; free( buf ); } } CFRelease (flavorData); } } else if ( dataFormat.GetType() == wxDF_UNICODETEXT && flavorFormat.GetType() == wxDF_TEXT ) { err = PasteboardCopyItemFlavorData( pasteboard, itemID, flavorType, &flavorData ); if ( err == noErr ) { flavorDataSize = CFDataGetLength( flavorData ); void *asciibuf = malloc( flavorDataSize + 1 ); if ( asciibuf ) { memset( asciibuf, 0, flavorDataSize + 1 ); memcpy( asciibuf, CFDataGetBytePtr( flavorData ), flavorDataSize ); CFRelease (flavorData); SetData( wxDF_TEXT, flavorDataSize, asciibuf ); transferred = true; free( asciibuf ); } else CFRelease (flavorData); } } } CFRelease( flavorTypeArray ); } if (filenamesPassed.length() > 0) { wxCharBuffer buf = filenamesPassed.fn_str(); SetData( wxDF_FILENAME, strlen( buf ), (const char*)buf ); transferred = true; } } } return transferred; }
bool wxHIDDevice::Create (int nClass, int nType, int nDev) { //Create the mach port wxIOCHECK(IOMasterPort(bootstrap_port, &m_pPort), "Could not create mach port"); //Dictionary that will hold first //the matching dictionary for determining which kind of devices we want, //then later some registry properties from an iterator (see below) // //The call to IOServiceMatching filters down the //the services we want to hid services (and also eats the //dictionary up for us (consumes one reference)) CFMutableDictionaryRef pDictionary = IOServiceMatching(kIOHIDDeviceKey); wxCHECK_MSG( pDictionary, false, _T("IOServiceMatching(kIOHIDDeviceKey) failed") ); wxASSERT( pDictionary ); //Here we'll filter down the services to what we want if (nType != -1) { CFNumberRef pType = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &nType); CFDictionarySetValue(pDictionary, CFSTR(kIOHIDPrimaryUsageKey), pType); CFRelease(pType); } if (nClass != -1) { CFNumberRef pClass = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &nClass); CFDictionarySetValue(pDictionary, CFSTR(kIOHIDPrimaryUsagePageKey), pClass); CFRelease(pClass); } //Now get the maching services io_iterator_t pIterator; wxIOCHECK(IOServiceGetMatchingServices(m_pPort, pDictionary, &pIterator), "No Matching HID Services"); wxASSERT_MSG(pIterator != 0, wxT("No devices found!")); //Now we iterate through them io_object_t pObject; while ( (pObject = IOIteratorNext(pIterator)) != 0) { if(--nDev != 0) continue; if ( IORegistryEntryCreateCFProperties ( pObject, &pDictionary, kCFAllocatorDefault, kNilOptions ) != KERN_SUCCESS ) { wxLogDebug(_T("IORegistryEntryCreateCFProperties failed")); } //Just for sanity :) wxASSERT(CFGetTypeID(CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey))) == CFStringGetTypeID()); /* kIOHIDTransportKey; kIOHIDVendorIDKey; kIOHIDProductIDKey; kIOHIDVersionNumberKey; kIOHIDManufacturerKey; kIOHIDSerialNumberKey; if !kIOHIDLocationIDKey kUSBDevicePropertyLocationID kIOHIDPrimaryUsageKey kIOHIDPrimaryUsagePageKey idProduct idVendor USB Product Name */ //Get [product] name m_szProductName = wxMacCFStringHolder( (CFStringRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey)), false ).AsString(); CFNumberRef nref = (CFNumberRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductIDKey)); if (nref) CFNumberGetValue( nref, kCFNumberIntType, &m_nProductId ); nref = (CFNumberRef) CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDVendorIDKey)); if (nref) CFNumberGetValue( nref, kCFNumberIntType, &m_nManufacturerId ); //Create the interface (good grief - long function names!) SInt32 nScore; IOCFPlugInInterface** ppPlugin; wxIOCHECK(IOCreatePlugInInterfaceForService(pObject, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPlugin, &nScore), ""); //Now, the final thing we can check before we fall back to asserts //(because the dtor only checks if the device is ok, so if anything //fails from now on the dtor will delete the device anyway, so we can't break from this). //Get the HID interface from the plugin to the mach port wxSCHECK((*ppPlugin)->QueryInterface(ppPlugin, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void**) &m_ppDevice), ""); //release the plugin (*ppPlugin)->Release(ppPlugin); //open the HID interface... if ( (*m_ppDevice)->open(m_ppDevice, 0) != S_OK ) wxLogDebug(_T("HID device: open failed")); // //Now the hard part - in order to scan things we need "cookies" - // wxCFArray CookieArray = CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDElementKey)); BuildCookies(CookieArray); //cleanup CFRelease(pDictionary); IOObjectRelease(pObject); break; } //iterator cleanup IOObjectRelease(pIterator); return true; }//end Create()
bool wxApp::Initialize(int& argc, wxChar **argv) { // Mac-specific #if __WXDEBUG__ InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); #endif UMAInitToolbox( 4, sm_isEmbedded ) ; SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; #ifndef __DARWIN__ # if __option(profile) ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ; # endif #endif #ifndef __DARWIN__ // now avoid exceptions thrown for new (bad_alloc) // FIXME CS for some changes outside wxMac does not compile anymore #if 0 std::__throws_bad_alloc = 0 ; #endif #endif s_macCursorRgn = ::NewRgn() ; // Mac OS X passes a process serial number command line argument when // the application is launched from the Finder. This argument must be // removed from the command line arguments before being handled by the // application (otherwise applications would need to handle it) if ( argc > 1 ) { static const wxChar *ARG_PSN = _T("-psn_"); if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 ) { // remove this argument --argc; memmove(argv + 1, argv + 2, argc * sizeof(char *)); } } if ( !wxAppBase::Initialize(argc, argv) ) return false; #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif #if TARGET_API_MAC_OSX // these might be the startup dirs, set them to the 'usual' dir containing the app bundle wxString startupCwd = wxGetCwd() ; if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") ) { CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ; CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ; CFRelease( url ) ; CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ; CFRelease( urlParent ) ; wxString cwd = wxMacCFStringHolder(path).AsString(wxLocale::GetSystemEncoding()); wxSetWorkingDirectory( cwd ) ; } #endif wxMacCreateNotifierTable() ; #ifdef __WXMAC_OSX__ /* connect posted events to common-mode run loop so that wxPostEvent events are handled even while we're in the menu or on a scrollbar */ CFRunLoopSourceContext event_posted_context = {0}; event_posted_context.perform = macPostedEventCallback; m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context); CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); #endif UMAShowArrowCursor() ; return true; }
int wxFileDialog::ShowModal() { #if TARGET_CARBON OSErr err; NavDialogCreationOptions dialogCreateOptions; // set default options ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); // this was always unset in the old code dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; wxMacCFStringHolder message(m_message, m_font.GetEncoding()); dialogCreateOptions.windowTitle = message; wxMacCFStringHolder defaultFileName(m_fileName, m_font.GetEncoding()); dialogCreateOptions.saveFileName = defaultFileName; NavDialogRef dialog; NavObjectFilterUPP navFilterUPP = NULL; CFArrayRef cfArray = NULL; // for popupExtension OpenUserDataRec myData; myData.defaultLocation = m_dir; if (m_dialogStyle & wxSAVE) { dialogCreateOptions.optionFlags |= kNavNoTypePopup; dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; // The extension is important dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; err = ::NavCreatePutFileDialog(&dialogCreateOptions, 'TEXT', 'TEXT', sStandardNavEventFilter, &myData, // for defaultLocation &dialog); } else { MakeUserDataRec(&myData , m_wildCard); size_t numfilters = myData.extensions.GetCount(); if (numfilters > 0) { CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault , numfilters , &kCFTypeArrayCallBacks ) ; dialogCreateOptions.popupExtension = popup ; myData.menuitems = dialogCreateOptions.popupExtension ; for ( size_t i = 0 ; i < numfilters ; ++i ) { CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ; } } navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); err = ::NavCreateGetFileDialog(&dialogCreateOptions, NULL, // NavTypeListHandle sStandardNavEventFilter, NULL, // NavPreviewUPP navFilterUPP, (void *) &myData, // inClientData &dialog); } if (err == noErr) err = ::NavDialogRun(dialog); // clean up filter related data, etc. if (navFilterUPP) ::DisposeNavObjectFilterUPP(navFilterUPP); if (cfArray) ::CFRelease(cfArray); if (err != noErr) return wxID_CANCEL; NavReplyRecord navReply; err = ::NavDialogGetReply(dialog, &navReply); if (err == noErr && navReply.validRecord) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSRef theFSRef; wxString thePath ; long count; ::AECountItems(&navReply.selection , &count); for (long i = 1; i <= count; ++i) { err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType, &theFSRef, sizeof(theFSRef), &actualSize); if (err != noErr) break; CFURLRef fullURLRef; if (m_dialogStyle & wxSAVE) { CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); if (parentURLRef) { fullURLRef = ::CFURLCreateCopyAppendingPathComponent(NULL, parentURLRef, navReply.saveFileName, false); ::CFRelease(parentURLRef); } } else { fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); } #ifdef __UNIX__ CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; #else CFURLPathStyle pathstyle = kCFURLHFSPathStyle; #endif CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding()); if (!thePath) { ::NavDisposeReply(&navReply); return wxID_CANCEL; } m_path = thePath; m_paths.Add(m_path); m_fileName = wxFileNameFromPath(m_path); m_fileNames.Add(m_fileName); } // set these to the first hit m_path = m_paths[0]; m_fileName = wxFileNameFromPath(m_path); m_dir = wxPathOnly(m_path); } ::NavDisposeReply(&navReply); return (err == noErr) ? wxID_OK : wxID_CANCEL; #else // TARGET_CARBON NavDialogOptions mNavOptions; NavObjectFilterUPP mNavFilterUPP = NULL; NavPreviewUPP mNavPreviewUPP = NULL ; NavReplyRecord mNavReply; AEDesc mDefaultLocation ; bool mSelectDefault = false ; OSStatus err = noErr ; // setup dialog mNavFilterUPP = nil; mNavPreviewUPP = nil; mSelectDefault = false; mDefaultLocation.descriptorType = typeNull; mDefaultLocation.dataHandle = nil; NavGetDefaultDialogOptions(&mNavOptions); wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ; wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ; // Set default location, the location // that's displayed when the dialog // first appears FSSpec location ; wxMacFilename2FSSpec( m_dir , &location ) ; err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation ); if ( mDefaultLocation.dataHandle ) { if (mSelectDefault) { mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation; } else { mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation; } } memset( &mNavReply , 0 , sizeof( mNavReply ) ) ; mNavReply.validRecord = false; mNavReply.replacing = false; mNavReply.isStationery = false; mNavReply.translationNeeded = false; mNavReply.selection.descriptorType = typeNull; mNavReply.selection.dataHandle = nil; mNavReply.keyScript = smSystemScript; mNavReply.fileTranslation = nil; mNavReply.version = kNavReplyRecordVersion ; // zero all data m_path = wxEmptyString ; m_fileName = wxEmptyString ; m_paths.Empty(); m_fileNames.Empty(); OpenUserDataRec myData; MakeUserDataRec( &myData , m_wildCard ) ; myData.currentfilter = m_filterIndex ; if ( myData.extensions.GetCount() > 0 ) { mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ; myData.menuitems = mNavOptions.popupExtension ; for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i ) { (*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ; (*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ; // TODO : according to the new docs -1 to 10 are reserved for the OS (*mNavOptions.popupExtension)[i].menuType = i ; wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ; } } if ( m_dialogStyle & wxSAVE ) { myData.saveMode = true ; mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ; mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ; err = ::NavPutFile( &mDefaultLocation, &mNavReply, &mNavOptions, sStandardNavEventFilter , NULL, kNavGenericSignature, &myData); // User Data m_filterIndex = myData.currentfilter ; } else { myData.saveMode = false ; mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ; if ( m_dialogStyle & wxMULTIPLE ) mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ; else mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ; err = ::NavGetFile( &mDefaultLocation, &mNavReply, &mNavOptions, sStandardNavEventFilter , mNavPreviewUPP, mNavFilterUPP, NULL , &myData); m_filterIndex = myData.currentfilter ; } DisposeNavObjectFilterUPP(mNavFilterUPP); if ( mDefaultLocation.dataHandle != nil ) { ::AEDisposeDesc(&mDefaultLocation); } if ( (err != noErr) && (err != userCanceledErr) ) { return wxID_CANCEL ; } if (mNavReply.validRecord) { FSSpec outFileSpec ; AEDesc specDesc ; AEKeyword keyWord ; long count ; ::AECountItems( &mNavReply.selection , &count ) ; for ( long i = 1 ; i <= count ; ++i ) { OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc); if ( err != noErr ) { m_path = wxT("") ; return wxID_CANCEL ; } outFileSpec = **(FSSpec**) specDesc.dataHandle; if (specDesc.dataHandle != nil) { ::AEDisposeDesc(&specDesc); } m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ; m_paths.Add( m_path ) ; m_fileName = wxFileNameFromPath(m_path); m_fileNames.Add(m_fileName); } // set these to the first hit m_path = m_paths[ 0 ] ; m_fileName = wxFileNameFromPath(m_path); m_dir = wxPathOnly(m_path); NavDisposeReply( &mNavReply ) ; return wxID_OK ; } return wxID_CANCEL; #endif // TARGET_CARBON }
int wxFileDialog::ShowModal() { OSErr err; NavDialogCreationOptions dialogCreateOptions; // set default options ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); // this was always unset in the old code dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; wxMacCFStringHolder message(m_message, m_font.GetEncoding()); dialogCreateOptions.windowTitle = message; wxMacCFStringHolder defaultFileName(m_fileName, m_font.GetEncoding()); dialogCreateOptions.saveFileName = defaultFileName; NavDialogRef dialog; NavObjectFilterUPP navFilterUPP = NULL; CFArrayRef cfArray = NULL; // for popupExtension OpenUserDataRec myData; myData.defaultLocation = m_dir; MakeUserDataRec(&myData , m_wildCard); myData.currentfilter = m_filterIndex; size_t numFilters = myData.extensions.GetCount(); if (numFilters) { CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault , numFilters , &kCFTypeArrayCallBacks ) ; dialogCreateOptions.popupExtension = popup ; myData.menuitems = dialogCreateOptions.popupExtension ; for ( size_t i = 0 ; i < numFilters ; ++i ) { CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ; } } if (m_dialogStyle & wxSAVE) { myData.saveMode = true; if (!numFilters) { dialogCreateOptions.optionFlags |= kNavNoTypePopup; } dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; // The extension is important if (numFilters < 2) dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; #if TARGET_API_MAC_OSX if (!(m_dialogStyle & wxOVERWRITE_PROMPT)) { dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement; } #endif err = ::NavCreatePutFileDialog(&dialogCreateOptions, // Suppresses the 'Default' (top) menu item kNavGenericSignature, kNavGenericSignature, sStandardNavEventFilter, &myData, // for defaultLocation &dialog); } else { //let people select bundles/programs in dialogs dialogCreateOptions.optionFlags |= kNavSupportPackages; navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); err = ::NavCreateGetFileDialog(&dialogCreateOptions, NULL, // NavTypeListHandle sStandardNavEventFilter, NULL, // NavPreviewUPP navFilterUPP, (void *) &myData, // inClientData &dialog); } if (err == noErr) err = ::NavDialogRun(dialog); // clean up filter related data, etc. if (navFilterUPP) ::DisposeNavObjectFilterUPP(navFilterUPP); if (cfArray) ::CFRelease(cfArray); if (err != noErr) return wxID_CANCEL; NavReplyRecord navReply; err = ::NavDialogGetReply(dialog, &navReply); if (err == noErr && navReply.validRecord) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSRef theFSRef; wxString thePath ; m_filterIndex = myData.currentfilter ; long count; ::AECountItems(&navReply.selection , &count); for (long i = 1; i <= count; ++i) { err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType, &theFSRef, sizeof(theFSRef), &actualSize); if (err != noErr) break; if (m_dialogStyle & wxSAVE) thePath = wxMacFSRefToPath( &theFSRef , navReply.saveFileName ) ; else thePath = wxMacFSRefToPath( &theFSRef ) ; if (!thePath) { ::NavDisposeReply(&navReply); return wxID_CANCEL; } m_path = thePath; m_paths.Add(m_path); m_fileName = wxFileNameFromPath(m_path); m_fileNames.Add(m_fileName); } // set these to the first hit m_path = m_paths[0]; m_fileName = wxFileNameFromPath(m_path); m_dir = wxPathOnly(m_path); } ::NavDisposeReply(&navReply); return (err == noErr) ? wxID_OK : wxID_CANCEL; }
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data ) { ValidateOrCreate() ; PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ; if ( data.IsOrientationReversed() ) PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? kPMLandscape : kPMPortrait , false ) ; // collate cannot be set #if 0 // not yet tested if ( !m_printerName.empty() ) PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ; #endif #ifndef __LP64__ PMColorMode color ; PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ; if ( data.GetColour() ) { if ( color == kPMBlackAndWhite ) PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ; } else PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ; #endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if ( &PMSetDuplex!=NULL ) { PMDuplexMode mode = 0 ; switch( data.GetDuplex() ) { case wxDUPLEX_HORIZONTAL : mode = kPMDuplexNoTumble ; break ; case wxDUPLEX_VERTICAL : mode = kPMDuplexTumble ; break ; case wxDUPLEX_SIMPLEX : default : mode = kPMDuplexNone ; break ; } PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ; } #endif // PMQualityMode not yet accessible via API // todo paperSize PMResolution res; PMPrinter printer; PMSessionGetCurrentPrinter(m_macPrintSession, &printer); #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 PMPrinterGetOutputResolution( printer, (PMPrintSettings) m_macPrintSettings, &res) ; // TODO transfer ? into page format ? #else PMTag tag = kPMMaxSquareResolution; PMPrinterGetPrinterResolution(printer, tag, &res); PMSetResolution((PMPageFormat) m_macPageFormat, &res); #endif // after setting the new resolution the format has to be updated, otherwise the page rect remains // at the 'old' scaling PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession, (PMPageFormat) m_macPageFormat, kPMDontWantBoolean) ; return true ; }
static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect, Cell cell, short dataOffset, short dataLength, ListHandle listHandle ) { wxListBox* list; list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); if ( list == NULL ) return ; GrafPtr savePort; GrafPtr grafPtr; RgnHandle savedClipRegion; SInt32 savedPenMode; GetPort(&savePort); SetPort((**listHandle).port); grafPtr = (**listHandle).port ; // typecast our refCon // Calculate the cell rect. switch( message ) { case lInitMsg: break; case lCloseMsg: break; case lDrawMsg: { const wxString linetext = list->m_stringArray[cell.v] ; // Save the current clip region, and set the clip region to the area we are about // to draw. savedClipRegion = NewRgn(); GetClip( savedClipRegion ); ClipRect( drawRect ); EraseRect( drawRect ); const wxFont& font = list->GetFont(); if ( font.Ok() ) { ::TextFont( font.GetMacFontNum() ) ; ::TextSize( font.GetMacFontSize() ) ; ::TextFace( font.GetMacFontStyle() ) ; } else { ::TextFont( kFontIDMonaco ) ; ::TextSize( 9 ); ::TextFace( 0 ) ; } #if TARGET_CARBON { Rect frame = { drawRect->top, drawRect->left + 4, drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ; CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext , list->GetFont().GetEncoding()) ) ; ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ; ::DrawThemeTextBox( mString, kThemeCurrentPortFont, kThemeStateActive, false, &frame, teJustLeft, nil ); CFRelease( mString ) ; } #else { wxCharBuffer text = linetext.mb_str( wxConvLocal) ; MoveTo(drawRect->left + 4 , drawRect->top + 10 ); DrawText(text, 0 , strlen(text) ); } #endif // If the cell is hilited, do the hilite now. Paint the cell contents with the // appropriate QuickDraw transform mode. if( isSelected ) { savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr ); SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode ); PaintRect( drawRect ); SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode ); } // Restore the saved clip region. SetClip( savedClipRegion ); DisposeRgn( savedClipRegion ); } break; case lHiliteMsg: // Hilite or unhilite the cell. Paint the cell contents with the // appropriate QuickDraw transform mode. GetPort( &grafPtr ); savedPenMode = GetPortPenMode( (CGrafPtr)grafPtr ); SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode ); PaintRect( drawRect ); SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode ); break; default : break ; } SetPort(savePort); }
void Set(CFStringRef key, const wxString& value) { CFDictionarySetValue(*this, key, wxMacCFStringHolder(value)); }
int FileDialog::ShowModal() { OSErr err; NavDialogCreationOptions dialogCreateOptions; // set default options ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); // this was always unset in the old code dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; wxMacCFStringHolder message(m_message, GetFont().GetEncoding()); dialogCreateOptions.windowTitle = message; wxMacCFStringHolder defaultFileName(m_fileName, GetFont().GetEncoding()); dialogCreateOptions.saveFileName = defaultFileName; NavDialogRef dialog; NavObjectFilterUPP navFilterUPP = NULL; CustomData myData; SetRect(&myData.bounds, 0, 0, 0, 0); myData.me = this; myData.window = NULL; myData.defaultLocation = m_dir; myData.userpane = NULL; myData.choice = NULL; myData.button = NULL; myData.saveMode = false; myData.showing = true; Rect r; SInt16 base; SInt16 margin = 3; SInt16 gap = 0; MakeUserDataRec(&myData , m_wildCard); myData.currentfilter = m_filterIndex; size_t numFilters = myData.extensions.GetCount(); if (numFilters) { CreateNewMenu(0, 0, &myData.menu); for ( size_t i = 0 ; i < numFilters ; ++i ) { ::AppendMenuItemTextWithCFString(myData.menu, wxMacCFStringHolder(myData.name[i], GetFont().GetEncoding()), 4, i, NULL); } SetRect(&r, 0, margin, 0, 0); CreatePopupButtonControl(NULL, &r, CFSTR("Format:"), -12345, true, -1, teJustLeft, normal, &myData.choice); SetControlID(myData.choice, &kChoiceID); SetControlPopupMenuRef(myData.choice, myData.menu); SetControl32BitMinimum(myData.choice, 1); SetControl32BitMaximum(myData.choice, myData.name.GetCount()); SetControl32BitValue(myData.choice, myData.currentfilter + 1); GetBestControlRect(myData.choice, &r, &base); SizeControl(myData.choice, r.right - r.left, r.bottom - r.top); UnionRect(&myData.bounds, &r, &myData.bounds); gap = 15; HIObjectSetAuxiliaryAccessibilityAttribute((HIObjectRef)myData.choice, 0, kAXDescriptionAttribute, CFSTR("Format")); } if (!m_buttonlabel.IsEmpty()) { wxMacCFStringHolder cfString(wxStripMenuCodes(m_buttonlabel).c_str(), wxFONTENCODING_DEFAULT); SetRect(&r, myData.bounds.right + gap, margin, 0, 0); CreatePushButtonControl(NULL, &r, cfString, &myData.button); SetControlID(myData.button, &kButtonID); GetBestControlRect(myData.button, &r, &base); SizeControl(myData.button, r.right - r.left, r.bottom - r.top); UnionRect(&myData.bounds, &r, &myData.bounds); } // Expand bounding rectangle to include a top and bottom margin myData.bounds.top -= margin; myData.bounds.bottom += margin; dialogCreateOptions.optionFlags |= kNavNoTypePopup; if (m_dialogStyle & wxFD_SAVE) { dialogCreateOptions.modality = kWindowModalityWindowModal; dialogCreateOptions.parentWindow = (WindowRef) GetParent()->MacGetTopLevelWindowRef(); myData.saveMode = true; if (!numFilters) { dialogCreateOptions.optionFlags |= kNavNoTypePopup; } dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; // The extension is important if (numFilters < 2) dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; #if TARGET_API_MAC_OSX if (!(m_dialogStyle & wxFD_OVERWRITE_PROMPT)) { dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement; } #endif err = ::NavCreatePutFileDialog(&dialogCreateOptions, // Suppresses the 'Default' (top) menu item kNavGenericSignature, kNavGenericSignature, sStandardNavEventFilter, &myData, // for defaultLocation &dialog); } else { //let people select bundles/programs in dialogs dialogCreateOptions.optionFlags |= kNavSupportPackages; navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); err = ::NavCreateGetFileDialog(&dialogCreateOptions, NULL, // NavTypeListHandle sStandardNavEventFilter, NULL, // NavPreviewUPP navFilterUPP, (void *) &myData, // inClientData &dialog); } if (err == noErr) err = ::NavDialogRun(dialog); if (err == noErr) { myData.window = NavDialogGetWindow(dialog); Rect r; // This creates our "fake" dialog with the same dimensions as the sheet so // that Options dialogs will center properly on the sheet. The "fake" dialog // is never actually seen. GetWindowBounds(myData.window, kWindowStructureRgn, &r); wxDialog::Create(NULL, // no parent...otherwise strange things happen wxID_ANY, wxEmptyString, wxPoint(r.left, r.top), wxSize(r.right - r.left, r.bottom - r.top)); BeginAppModalStateForWindow(myData.window); while (myData.showing) { wxTheApp->MacDoOneEvent(); } EndAppModalStateForWindow(myData.window); } // clean up filter related data, etc. if (navFilterUPP) ::DisposeNavObjectFilterUPP(navFilterUPP); if (err != noErr) return wxID_CANCEL; NavReplyRecord navReply; err = ::NavDialogGetReply(dialog, &navReply); if (err == noErr && navReply.validRecord) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSRef theFSRef; wxString thePath ; m_filterIndex = myData.currentfilter; long count; ::AECountItems(&navReply.selection , &count); for (long i = 1; i <= count; ++i) { err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType, &theFSRef, sizeof(theFSRef), &actualSize); if (err != noErr) break; if (m_dialogStyle & wxFD_SAVE) thePath = wxMacFSRefToPath( &theFSRef , navReply.saveFileName ) ; else thePath = wxMacFSRefToPath( &theFSRef ) ; if (!thePath) { ::NavDisposeReply(&navReply); return wxID_CANCEL; } m_path = ConvertSlashInFileName(thePath); m_paths.Add(m_path); m_fileName = wxFileNameFromPath(m_path); m_fileNames.Add(m_fileName); } // set these to the first hit m_path = m_paths[0]; m_fileName = wxFileNameFromPath(m_path); m_dir = wxPathOnly(m_path); } ::NavDisposeReply(&navReply); return (err == noErr) ? wxID_OK : wxID_CANCEL; }