static Vector<String> stringListFromResourceId(SInt16 id) { Vector<String> list; Handle handle = Get1Resource('STR#', id); if (!handle) return list; CFStringEncoding encoding = stringEncodingForResource(handle); unsigned char* p = (unsigned char*)*handle; if (!p) return list; SInt16 count = *(SInt16*)p; p += sizeof(SInt16); for (SInt16 i = 0; i < count; ++i) { unsigned char length = *p; WTF::RetainPtr<CFStringRef> str = CFStringCreateWithPascalString(0, p, encoding); list.append(str.get()); p += 1 + length; } return list; }
static CFStringRef BIMCreatePortName( const ProcessSerialNumber *inProcessSerialNumber ) { CFMutableStringRef portName; CFStringRef processSerialNumberStringRef; Str255 processSerialNumberString; Str255 processSerialNumberLowString; // Convert the high and low parts of the process serial number into a string. NumToString( inProcessSerialNumber->highLongOfPSN, processSerialNumberString ); NumToString( inProcessSerialNumber->lowLongOfPSN, processSerialNumberLowString ); BlockMoveData( processSerialNumberLowString + 1, processSerialNumberString + processSerialNumberString [0] + 1, processSerialNumberLowString [0] ); processSerialNumberString [0] += processSerialNumberLowString [0]; // Create a CFString and append the process serial number string onto the end. portName = CFStringCreateMutableCopy( NULL, 255, CFSTR( kBasicServerPortName ) ); processSerialNumberStringRef = CFStringCreateWithPascalString( NULL, processSerialNumberString, CFStringGetSystemEncoding() ); CFStringAppend( portName, processSerialNumberStringRef ); CFRelease( processSerialNumberStringRef ); return portName; }
OSStatus pathtofsref ( bigstring bspath, FSRef *ref ) { /* 2009-08-30 aradke: mac-only helper function for converting from a pascal string (path) to an FSRef */ bigstring bs; CFStringRef csref; char str[256]; copystring(bspath, bs); // convert from colon-delimited to slash-delimited path stringswapall(':', '/', bs); insertstring ( BIGSTRING ( "\x09" "/Volumes/" ), bs ); // convert from Mac Roman to UTF-8 */ csref = CFStringCreateWithPascalString(kCFAllocatorDefault, bs, kCFStringEncodingMacRoman); CFStringGetCString(csref, str, sizeof(str), kCFStringEncodingUTF8); CFRelease(csref); // finally, pass our temporary copy of the string to the underlying system function return FSPathMakeRef((UInt8*) str, ref, NULL); } /*pathtofsref*/
CHXCFString::CHXCFString(ConstStr255Param pPString) { mCFStringRef = CFStringCreateWithPascalString(kCFAllocatorDefault, pPString, CFStringGetSystemEncoding()); check_nonnull(mCFStringRef); UpdateDebugOnlyString(); }
OSStatus OpenFileDialog( OSType applicationSignature, short numTypes, OSType typeList[], NavDialogRef *outDialog ) { OSStatus theErr = noErr; if ( gOpenFileDialog == NULL ) { NavDialogCreationOptions dialogOptions; NavTypeListHandle openList = NULL; NavGetDefaultDialogCreationOptions( &dialogOptions ); dialogOptions.modality = kWindowModalityNone; dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); openList = (NavTypeListHandle)NewOpenHandle( applicationSignature, numTypes, typeList ); theErr = NavCreateGetFileDialog( &dialogOptions, openList, GetPrivateEventUPP(), NULL, NULL, NULL, &gOpenFileDialog ); if ( theErr == noErr ) { theErr = NavDialogRun( gOpenFileDialog ); if ( theErr != noErr ) { NavDialogDispose( gOpenFileDialog ); gOpenFileDialog = NULL; } } if (openList != NULL) { DisposeHandle((Handle)openList); } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } } else { if ( NavDialogGetWindow( gOpenFileDialog ) != NULL ) { SelectWindow( NavDialogGetWindow( gOpenFileDialog )); } } if ( outDialog != NULL ) { *outDialog = gOpenFileDialog; } return NULL; }
void CAComponent::SetCompInfo () const { if (!mCompInfo) { Handle h1 = NewHandle(4); CAComponentDescription desc; OSStatus err = GetComponentInfo (Comp(), &desc, 0, h1, 0); if (err) return; HLock (h1); const_cast<CAComponent*>(this)->mCompInfo = CFStringCreateWithPascalString(NULL, (const unsigned char*)*h1, kCFStringEncodingMacRoman); DisposeHandle (h1); } }
/* Some classcical Mac APIs use the encoding based on WorldScript. for example, Japanese language envrironment use ShiftJIS encoding. So, unicode2NativePascalString, this function converts unicode encoded pascal string to suitable encoding (came from CFStringGetSystemEncoding()). */ void unicode2NativePascalString(ConstStr255Param fromString, StringPtr toString) { if (fromString != NULL) { CFStringRef strRef = CFStringCreateWithPascalString(kCFAllocatorDefault, fromString, gCurrentVMEncoding); if (strRef != NULL) { CFMutableStringRef mStrRef = CFStringCreateMutableCopy(NULL, 0, strRef); if (gCurrentVMEncoding == kCFStringEncodingUTF8) CFStringNormalize(mStrRef, kCFStringNormalizationFormKD); CFStringGetPascalString (mStrRef, toString, 256, CFStringGetSystemEncoding()); CFRelease(mStrRef); CFRelease(strRef); } } }
// SGSettingsDialog with the "Compression" panel removed static OSErr MinimalSGSettingsDialog(SeqGrabComponent seqGrab, SGChannel sgchanVideo, WindowPtr gMonitor) { OSErr err; Component *panelListPtr = NULL; UInt8 numberOfPanels = 0; ComponentDescription cd = { SeqGrabPanelType, VideoMediaType, 0, 0, 0 }; Component c = 0; Component *cPtr = NULL; numberOfPanels = CountComponents(&cd); panelListPtr = (Component *) NewPtr(sizeof(Component) * (numberOfPanels + 1)); cPtr = panelListPtr; numberOfPanels = 0; CFStringRef compressionCFSTR = CFSTR("Compression"); do { ComponentDescription compInfo; c = FindNextComponent(c, &cd); if (c) { Handle hName = NewHandle(0); GetComponentInfo(c, &compInfo, hName, NULL, NULL); CFStringRef nameCFSTR = CFStringCreateWithPascalString(kCFAllocatorDefault, (unsigned char *)(*hName), kCFStringEncodingASCII); if (CFStringCompare (nameCFSTR, compressionCFSTR, kCFCompareCaseInsensitive) != kCFCompareEqualTo) { *cPtr++ = c; numberOfPanels++; } DisposeHandle(hName); } } while (c); if ((err = SGSettingsDialog(seqGrab, sgchanVideo, numberOfPanels, panelListPtr, seqGrabSettingsPreviewOnly, (SGModalFilterUPP) NewSGModalFilterUPP(SeqGrabberModalFilterProc), (long)gMonitor))) { return err; } return 0; }
void CAComponent::SetCompNames () const { if (!mCompName) { Handle h1 = NewHandle(4); CAComponentDescription desc; OSStatus err = GetComponentInfo (Comp(), &desc, h1, 0, 0); if (err) { DisposeHandle(h1); return; } HLock(h1); char* ptr1 = *h1; // Get the manufacturer's name... look for the ':' character convention int len = *ptr1++; char* displayStr = 0; const_cast<CAComponent*>(this)->mCompName = CFStringCreateWithPascalString(NULL, (const unsigned char*)*h1, kCFStringEncodingMacRoman); for (int i = 0; i < len; ++i) { if (ptr1[i] == ':') { // found the name ptr1[i] = 0; displayStr = ptr1; break; } } if (displayStr) { const_cast<CAComponent*>(this)->mManuName = CFStringCreateWithCString(NULL, displayStr, kCFStringEncodingMacRoman); //move displayStr ptr past the manu, to the name // we move the characters down a index, because the handle doesn't have any room // at the end for the \0 int i = strlen(displayStr), j = 0; while (displayStr[++i] == ' ' && i < len) ; while (i < len) displayStr[j++] = displayStr[i++]; displayStr[j] = 0; const_cast<CAComponent*>(this)->mAUName = CFStringCreateWithCString(NULL, displayStr, kCFStringEncodingMacRoman); } DisposeHandle (h1); } }
OSStatus SaveFileDialog( WindowRef parentWindow, CFStringRef documentName, OSType filetype, OSType fileCreator, void *inContextData, NavDialogRef *outDialog ) { NavDialogCreationOptions dialogOptions; OSStatus theErr = noErr; NavGetDefaultDialogCreationOptions( &dialogOptions ); dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); dialogOptions.saveFileName = documentName; dialogOptions.modality = ( parentWindow != NULL ) ? kWindowModalityWindowModal : kWindowModalityAppModal; dialogOptions.parentWindow = parentWindow; theErr = NavCreatePutFileDialog( &dialogOptions, filetype, fileCreator, GetEventUPP(), inContextData, outDialog ); if ( theErr == noErr ) { theErr = NavDialogRun( *outDialog ); if ( theErr != noErr ) { NavDialogDispose( *outDialog ); } if ( theErr != noErr || dialogOptions.modality == kWindowModalityAppModal ) { *outDialog = NULL; // The dialog has already been disposed. } } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } return theErr; }
int dir_Lookup(char *pathString, int pathStringLength, int index, /* outputs: */ char *name, int *nameLength, int *creationDate, int *modificationDate, int *isDirectory, squeakFileOffsetType *sizeIfFile) { /* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int okay; FSSpec spec; long parentDirectory; OSErr err; Str255 longFileName; FSVolumeInfoParam fsVolumeParam; HFSUniStr255 uniStr; FSVolumeInfo volumeInfo; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; if ((pathStringLength == 0)) { /* get volume info */ fsVolumeParam.volumeName = &uniStr; fsVolumeParam.ioVRefNum = kFSInvalidVolumeRefNum; fsVolumeParam.volumeIndex = index; fsVolumeParam.whichInfo = 0; fsVolumeParam.volumeInfo = &volumeInfo; fsVolumeParam.ref = NULL; fsVolumeParam.whichInfo = kFSVolInfoCreateDate + kFSVolInfoModDate; okay = PBGetVolumeInfoSync( &fsVolumeParam) == noErr; /* FSGetVolumeInfo (kFSInvalidVolumeRefNum, index, NULL, ) */ if (okay) { CFStringRef strRef = CFStringCreateWithCharacters( kCFAllocatorDefault, uniStr.unicode, uniStr.length ); CFMutableStringRef mStr = CFStringCreateMutableCopy(NULL, 0, strRef); // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements if (gCurrentVMEncoding == kCFStringEncodingUTF8) CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined Boolean result = CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); // buffer size is to see primitiveDirectoryLookup CFRelease(strRef); CFRelease(mStr); if (result == true) { // strncpy(name, &(uniStr.unicode), uniStr.length); // *nameLength = uniStr.length; *nameLength = strlen(name); { LocalDateTime local; ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->createDate,&local); *creationDate = convertToSqueakTime(local.lowSeconds); } { LocalDateTime local; ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->modifyDate,&local); *modificationDate = convertToSqueakTime(local.lowSeconds); } *isDirectory = true; *sizeIfFile = 0; return ENTRY_FOUND; } else { return NO_MORE_ENTRIES; } } else { return NO_MORE_ENTRIES; } } else { /* get file or directory info */ if (!equalsLastPath(pathString, pathStringLength)) { /* lookup and cache the refNum for this path */ err = lookupPath(pathString, pathStringLength, &spec,false,true); if (err == noErr) recordPath(pathString, pathStringLength, &spec); else return BAD_PATH; } spec = lastSpec; *sizeIfFile = 0; okay = fetchFileInfo(index,&spec,(unsigned char *) name,true, &parentDirectory,isDirectory,creationDate, modificationDate,sizeIfFile,&longFileName); if (okay == noErr) { CFStringRef cfs= CFStringCreateWithPascalString(NULL, longFileName, gCurrentVMEncoding); CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, cfs); CFRelease(cfs); // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements if (gCurrentVMEncoding == kCFStringEncodingUTF8) CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); CFRelease(mStr); *nameLength = strlen(name); *creationDate = convertToSqueakTime(*creationDate); *modificationDate = convertToSqueakTime(*modificationDate); return ENTRY_FOUND; } else return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH; } }
CFStringRef CFStringFromStr255(ConstStr255Param pascalString) { return CFStringCreateWithPascalString( NULL, pascalString, GetApplicationTextEncoding( ) ); }
// ----------------------------------------------------------------------------- // AddCommandToAEDescList // ----------------------------------------------------------------------------- static OSStatus AddCommandToAEDescList( ConstStr255Param inCommandString, TextEncoding inEncoding, DescType inDescType, SInt32 inCommandID, MenuItemAttributes inAttributes, UInt32 inModifiers, AEDescList* ioCommandList) { OSStatus theError = noErr; AERecord theCommandRecord = { typeNull, NULL }; printf( "AddCommandToAEDescList: Trying to add an item.\n" ); // create an apple event record for our command theError = AECreateList( NULL, kAEDescListFactorNone, true, &theCommandRecord ); require_noerr( theError, AddCommandToAEDescList_fail ); // stick the command text into the AERecord if ( inCommandString != NULL ) { if ( inDescType == typeChar ) { theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeChar, &inCommandString[1], StrLength( inCommandString ) ); require_noerr( theError, AddCommandToAEDescList_fail ); } else if ( inDescType == typeStyledText ) { AERecord textRecord; WritingCode writingCode; AEDesc textDesc; theError = AECreateList( NULL, kAEDescListFactorNone, true, &textRecord ); require_noerr( theError, AddCommandToAEDescList_fail ); theError = AEPutKeyPtr( &textRecord, keyAEText, typeChar, &inCommandString[1], StrLength( inCommandString ) ); require_noerr( theError, AddCommandToAEDescList_fail ); RevertTextEncodingToScriptInfo( inEncoding, &writingCode.theScriptCode, &writingCode.theLangCode, NULL ); theError = AEPutKeyPtr( &textRecord, keyAEScriptTag, typeIntlWritingCode, &writingCode, sizeof( writingCode ) ); require_noerr( theError, AddCommandToAEDescList_fail ); theError = AECoerceDesc( &textRecord, typeStyledText, &textDesc ); require_noerr( theError, AddCommandToAEDescList_fail ); theError = AEPutKeyDesc( &theCommandRecord, keyAEName, &textDesc ); require_noerr( theError, AddCommandToAEDescList_fail ); AEDisposeDesc( &textRecord ); } else if ( inDescType == typeIntlText ) { IntlText* intlText; ByteCount size = sizeof( IntlText ) + StrLength( inCommandString ) - 1; // create an IntlText structure with the text and script intlText = (IntlText*) malloc( size ); RevertTextEncodingToScriptInfo( inEncoding, &intlText->theScriptCode, &intlText->theLangCode, NULL ); BlockMoveData( &inCommandString[1], &intlText->theText, StrLength( inCommandString ) ); theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeIntlText, intlText, size ); free( (char*) intlText ); require_noerr( theError, AddCommandToAEDescList_fail ); } else if ( inDescType == typeUnicodeText ) { CFStringRef str = CFStringCreateWithPascalString( NULL, inCommandString, inEncoding ); if ( str != NULL ) { Boolean doFree = false; CFIndex sizeInChars = CFStringGetLength( str ); CFIndex sizeInBytes = sizeInChars * sizeof( UniChar ); const UniChar* unicode = CFStringGetCharactersPtr( str ); if ( unicode == NULL ) { doFree = true; unicode = (UniChar*) malloc( sizeInBytes ); CFStringGetCharacters( str, CFRangeMake( 0, sizeInChars ), (UniChar*) unicode ); } theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeUnicodeText, unicode, sizeInBytes ); CFRelease( str ); if ( doFree ) free( (char*) unicode ); require_noerr( theError, AddCommandToAEDescList_fail ); } } else if ( inDescType == typeCFStringRef ) { CFStringRef str = CFStringCreateWithPascalString( NULL, inCommandString, inEncoding ); if ( str != NULL ) { theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeCFStringRef, &str, sizeof( str ) ); require_noerr( theError, AddCommandToAEDescList_fail ); // do not release the string; the Contextual Menu Manager will release it for us } } } // stick the command ID into the AERecord if ( inCommandID != 0 ) { theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuCommandID, typeLongInteger, &inCommandID, sizeof( inCommandID ) ); require_noerr( theError, AddCommandToAEDescList_fail ); } // stick the attributes into the AERecord if ( inAttributes != 0 ) { theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuAttributes, typeLongInteger, &inAttributes, sizeof( inAttributes ) ); require_noerr( theError, AddCommandToAEDescList_fail ); } // stick the modifiers into the AERecord if ( inModifiers != 0 ) { theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuModifiers, typeLongInteger, &inModifiers, sizeof( inModifiers ) ); require_noerr( theError, AddCommandToAEDescList_fail ); } // stick this record into the list of commands that we are // passing back to the CMM theError = AEPutDesc( ioCommandList, // the list we're putting our command into 0, // stick this command onto the end of our list &theCommandRecord ); // the command I'm putting into the list AddCommandToAEDescList_fail: // clean up after ourself; dispose of the AERecord AEDisposeDesc( &theCommandRecord ); return theError; } // AddCommandToAEDescList
QString qt_mac_from_pascal_string(const Str255 pstr) { return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding())); }
int main(int argc, char *argv[]) { WindowRef window; HIViewRef content; HIViewRef combo; HIViewRef group; HIViewRef check; HIViewRef text; HIViewRef slider; HIViewRef quit; MenuRef menu; HIRect rect; // Window bounds Rect bounds = {0, 0, 436, 590}; // Create window CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowCompositingAttribute, &bounds, &window); // Set the title SetWindowTitleWithCFString(window, CFSTR("Accordion")); // Create an application menu CreateNewMenu(0, 0, &menu); // Set menu title SetMenuTitleWithCFString(menu, CFStringCreateWithPascalString(kCFAllocatorDefault, "\p\024", kCFStringEncodingMacRoman)); // Create an about item InsertMenuItemTextWithCFString(menu, CFSTR("About Accordion"), 0, 0, kHICommandAbout); // Insert the menu InsertMenu(menu, 0); // Create a standard window menu CreateStandardWindowMenu(0, &menu); // Insert the menu InsertMenu(menu, 0); // Show and position the window ShowWindow(window); RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); // Find the window content HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &content); // Set bounds for group box bounds.bottom = 92; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 20); // Bounds of text bounds.bottom = 16; bounds.right = 74; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Instrument:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 18); // Bounds of combo box rect.size.height = 20; rect.size.width = 168; // Create combo box HIComboBoxCreate(&rect, CFSTR(" Accordion"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetCommandID(combo, kCommandInst); // Add the instruments for (int i = 0; i < Length(instruments); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, instruments[i], kCFStringEncodingMacRoman), NULL); // Set the current instrument if (strcmp(instruments[i], " Accordion") == 0) instrument = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 102, 16); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Reverse"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDReverse); HIViewSetCommandID(check, kCommandReverse); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 17); // Bounds of text bounds.bottom = 16; bounds.right = 32; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Key:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 400, 18); // Bounds of combo box rect.size.width = 90; // Create combo box HIComboBoxCreate(&rect, CFSTR(" A/D/G"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetID(combo, kHIViewIDKey); HIViewSetCommandID(combo, kCommandKey); // Add keys for (int i = 0; i < Length(keys); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, keys[i], kCFStringEncodingMacRoman), NULL); // Set current key if (strcmp(keys[i], " A/D/G") == 0) key = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 440, 16); // Bounds of text bounds.bottom = 16; bounds.right = 54; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Volume:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 56); // Bounds of slider bounds.bottom = 16; bounds.right = 168; // Create slider CreateSliderControl(window, &bounds, MAXVOL, 0, MAXVOL, kControlSliderDoesNotPoint, 0, false, NULL, &slider); // Set command ID HIViewSetCommandID(slider, kCommandVolume); // Place in the group box HIViewAddSubview(group, slider); HIViewPlaceInSuperviewAt(slider, 100, 58); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Notes"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDNote); HIViewSetCommandID(check, kCommandNote); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 56); // Bounds of push button bounds.bottom = 20; bounds.right = 90; // Create push button CreatePushButtonControl(window, &bounds, CFSTR("Quit"), &quit); // Set command ID HIViewSetCommandID(quit, kHICommandQuit); // Place in the group box HIViewAddSubview(group, quit); HIViewPlaceInSuperviewAt(quit, 440, 54); // Group box bounds bounds.bottom = 48; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 132); // Font style ControlFontStyleRec style; style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontBigSystemFont; style.just = teCenter; // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Accordion"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 8); // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Play accordion on your keyboard"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 24); // Group box bounds bounds.bottom = 196; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 200); // Button bounds bounds.bottom = SIZE; bounds.right = SIZE; // Create row of bass buttons for (int i = 0; i < Length(bassdisplay); i++) { int x = 15 + 44 * i; int y = 15; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &bassdisplay[i]); // Place in the group box HIViewAddSubview(group, bassdisplay[i]); HIViewPlaceInSuperviewAt(bassdisplay[i], x, y); } // Create three rows of buttons for (int i = 0; i < Length(display); i++) { for (int j = 0; j < ((i == 1)? Length(display[i]): Length(display[i]) - 1); j++) { int x = (i == 1)? 37 + 44 * j: 59 + 44 * j; int y = 59 + 44 * i; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &display[i][j]); // Place in the group box HIViewAddSubview(group, display[i][j]); HIViewPlaceInSuperviewAt(display[i][j], x, y); } } // Create spacebar button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &spacebar); // Place in the group box HIViewAddSubview(group, spacebar); HIViewPlaceInSuperviewAt(spacebar, 16, 147); // Group box bounds, wider than the window to hide rounded corners bounds.bottom = 20; bounds.right = 598; // Create group box for fake status bar CreateGroupBoxControl(window, &bounds, NULL, false, &group); // Place in window at negative offset to hide rounded corners HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, -4, 416); // Text bounds bounds.bottom = 16; bounds.right = 590; // Font style style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontSmallSystemFont; style.just = teCenter; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Press the keyboard keys as accordion buttons " "and the space bar as the bellows. 3rd button start."), &style, &text); // Place in group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 2); // Application events type spec EventTypeSpec applicationEvents[] = {{kEventClassApplication, kEventAppFrontSwitched}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ApplicationHandler), Length(applicationEvents), applicationEvents, NULL, NULL); // Mouse events type spec EventTypeSpec mouseEvents[] = {{kEventClassMouse, kEventMouseDown}}; // Install event handler on the event dispatcher, so that we can // see mouse events before the default handler gets them InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(MouseHandler), Length(mouseEvents), mouseEvents, NULL, NULL); // Window events type spec EventTypeSpec windowEvents[] = {{kEventClassWindow, kEventWindowClose}}; // Install event handler InstallWindowEventHandler(window, NewEventHandlerUPP(WindowHandler), Length(windowEvents), windowEvents, NULL, NULL); // Combo box events type spec EventTypeSpec comboBoxEvents[] = {{kEventClassHIComboBox, kEventComboBoxListItemSelected}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ComboBoxHandler), Length(comboBoxEvents), comboBoxEvents, NULL, NULL); // Command events type spec EventTypeSpec commandEvents[] = {{kEventClassCommand, kEventCommandProcess}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(CommandHandler), Length(commandEvents), commandEvents, NULL, NULL); // Keyboard events type spec EventTypeSpec keyboardEvents[] = {{kEventClassKeyboard, kEventRawKeyDown}, {kEventClassKeyboard, kEventRawKeyUp}, {kEventClassKeyboard, kEventRawKeyModifiersChanged}}; // Install event handler on the event dispatcher InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(KeyboardHandler), Length(keyboardEvents), keyboardEvents, NULL, NULL); // Audio Unit graph AUGraph graph; // Audio Unit synthesizer and output node AUNode synthNode; AUNode outNode; // Component description ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; do { // New AU graph OSStatus status = NewAUGraph(&graph); if (status != noErr) { DisplayAlert(CFSTR("NewAUGraph"), CFSTR("Can't create a new AUGraph"), status); break; } // Synthesizer cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; // New synthesizer node status = AUGraphNewNode(graph, &cd, 0, NULL, &synthNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Output cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; // New output node status = AUGraphNewNode(graph, &cd, 0, NULL, &outNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Open graph status = AUGraphOpen(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphOpen"), CFSTR("Can't open AUGraph"), status); break; } // Connect synthesizer node to output node status = AUGraphConnectNodeInput(graph, synthNode, 0, outNode, 0); if (status != noErr) { DisplayAlert(CFSTR("AUGraphConnectNodeInput"), CFSTR("Can't connect AUGraph input node"), status); break; } // Get a synthesizer unit status = AUGraphGetNodeInfo(graph, synthNode, NULL, 0, NULL, &synthUnit); if (status != noErr) { DisplayAlert(CFSTR("AUGraphGetNodeInfo"), CFSTR("Can't get AUGraph node info"), status); break; } // Initialise status = AUGraphInitialize(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphInitialize"), CFSTR("Can't initialize AUGraph"), status); break; } // Start status = AUGraphStart(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphStart"), CFSTR("Can't start AUGraph"), status); break; } // Show the graph // CAShow(graph); } while (false); // Change instrument ChangeInstrument(instrument); // Run the application event loop RunApplicationEventLoop(); // Stop the graph AUGraphStop(graph); // Dispose of the graph DisposeAUGraph(graph); // Exit return 0; }
static OSStatus UniversalConfirmSaveDialog( WindowRef parentWindow, CFStringRef documentName, Boolean quitting, void* inContextData, NavDialogRef *outDialog, NavUserAction *outUserAction ) { OSStatus theErr = noErr; NavAskSaveChangesAction action = 0; NavDialogRef dialog = NULL; NavUserAction userAction = kNavUserActionNone; NavDialogCreationOptions dialogOptions; NavEventUPP eventUPP; Boolean disposeAfterRun; NavGetDefaultDialogCreationOptions( &dialogOptions ); action = quitting ? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument; dialogOptions.modality = ( parentWindow != NULL ) ? kWindowModalityWindowModal : kWindowModalityAppModal; dialogOptions.parentWindow = parentWindow; dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); if ( documentName != NULL ) { dialogOptions.saveFileName = documentName; } eventUPP = ( inContextData == NULL ) ? GetPrivateEventUPP() : GetEventUPP(); disposeAfterRun = ( dialogOptions.modality == kWindowModalityAppModal && inContextData == NULL ); theErr = NavCreateAskSaveChangesDialog( &dialogOptions, action, eventUPP, inContextData, &dialog ); if ( theErr == noErr ) { theErr = NavDialogRun( dialog ); if ( theErr != noErr || disposeAfterRun ) { userAction = NavDialogGetUserAction( dialog ); NavDialogDispose( dialog ); dialog = NULL; } } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } if ( outDialog != NULL ) { *outDialog = dialog; } if ( outUserAction != NULL ) { *outUserAction = userAction; } return theErr; }
int readJPEG(Image * im, fullPath * sfile) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE *infile; char filename[256]; int scan_lines_to_be_read, scan_lines_read; unsigned int i, scanheight; unsigned char *data; JSAMPARRAY sarray; JOCTET *ptr = NULL; unsigned int size = 0; #ifdef __Mac__ unsigned char the_pcUnixFilePath[256]; // added by Kekus Digital Str255 the_cString; Boolean the_bReturnValue; CFStringRef the_FilePath; CFURLRef the_Url; //till here #endif //PrintError("%s", sfile->name); cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); // Prepare the library for reading the ICC profile, see its source code // for further information jpegICCSetupReadICCProfile(&cinfo); if (GetFullPath(sfile, filename)) return -1; #ifdef __Mac__ CopyCStringToPascal(filename, the_cString); //Added by Kekus Digital the_FilePath = CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString, kCFStringEncodingUTF8); the_Url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath, kCFURLHFSPathStyle, false); the_bReturnValue = CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath, 256); strcpy(filename, the_pcUnixFilePath); //till here #endif if ((infile = fopen(filename, "rb")) == NULL) { PrintError("can't open %s", filename); return -1; } jpeg_stdio_src(&cinfo, infile); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); SetImageDefaults(im); im->width = cinfo.output_width; im->height = cinfo.output_height; if (cinfo.output_components != 3) { PrintError("Image must be rgb"); fclose(infile); return -1; } im->bitsPerPixel = 24; im->bytesPerLine = im->width * 3; im->dataSize = im->width * 4 * im->height; im->data = (unsigned char **) mymalloc((size_t) im->dataSize); if (im->data == NULL) { PrintError("Not enough memory"); fclose(infile); return -1; } scanheight = cinfo.rec_outbuf_height; sarray = (JSAMPARRAY) malloc(scanheight * sizeof(JSAMPROW)); scan_lines_to_be_read = im->height; data = *(im->data); while (scan_lines_to_be_read) { for (i = 0; i < scanheight; i++) { sarray[i] = (JSAMPROW) (data + i * im->bytesPerLine); } scan_lines_read = jpeg_read_scanlines(&cinfo, sarray, scanheight); scan_lines_to_be_read -= scan_lines_read; data += scan_lines_read * im->bytesPerLine; } // read ICC profile if (jpegICCReadProfile(&cinfo, &ptr, &size)) { im->metadata.iccProfile.size = size; im->metadata.iccProfile.data = (char*) ptr; } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); ThreeToFourBPP(im); free(sarray); fclose(infile); return 0; }
// -------------------------------------------------------------------------------------- static void drawIconListCell(ListHandle theList, const Rect *cellRect, IconListCellDataRec *theCellData, Boolean selected) { GrafPtr savedPort; CGrafPtr listPort; ThemeDrawingState savedState; Boolean active; Rect iconRect, textRect; short savedFont, savedSize; Style savedFace; CFStringRef cellName; GetPort(&savedPort); listPort = GetListPort(theList); SetPort((GrafPtr)listPort); GetThemeDrawingState(&savedState); if (selected) // we don't need to change the background { // color if this Cell isn't highlighted Pattern whitePattern; RGBColor highlightColor; GetQDGlobalsWhite(&whitePattern); // set the background pattern so that BackPat(&whitePattern); // the color is properly set as a solid color LMGetHiliteRGB(&highlightColor); RGBBackColor(&highlightColor); // set the background to the highlight color } EraseRect(cellRect); calculateDrawingBounds(cellRect, &iconRect, &textRect); // get the drawing Rects active = GetListActive(theList); // draw the IconRef using Icon Services PlotIconRef(&iconRect, kAlignNone, active ? kTransformNone : kTransformDisabled, kIconServicesNormalUsageFlag, theCellData->icon); #if TARGET_API_MAC_OS8 // draw TextEdit text in Classic #pragma unused (cellName) savedFont = GetPortTextFont(listPort); // Get/SetThemeDrawingState doesn't save or savedFace = GetPortTextFace(listPort); // restore these savedSize = GetPortTextSize(listPort); UseThemeFont(kThemeViewsFont, smCurrentScript); TETextBox(&theCellData->name[1], theCellData->name[0], &textRect, teCenter); TextFont(savedFont); TextFace(savedFace); TextSize(savedSize); #else // draw Appearance text in Carbon #pragma unused (savedFont, savedSize, savedFace) cellName = CFStringCreateWithPascalString(kCFAllocatorDefault, theCellData->name, GetApplicationTextEncoding()); DrawThemeTextBox(cellName, kThemeViewsFont, active ? kThemeStateActive : kThemeStateInactive, true, &textRect, teCenter, NULL); CFRelease(cellName); #endif SetThemeDrawingState(savedState, true); SetPort(savedPort); } // drawIconListCell
int writeJPEG(Image * im, fullPath * sfile, int quality, int progressive) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile; char filename[512]; int scanlines_written; unsigned char *data, *buf; #ifdef __Mac__ unsigned char the_pcUnixFilePath[512]; // added by Kekus Digital Str255 the_cString; Boolean the_bReturnValue; CFStringRef the_FilePath; CFURLRef the_Url; //till here #endif cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); if (GetFullPath(sfile, filename)) return -1; #ifdef __Mac__ CopyCStringToPascal(filename, the_cString); //Added by Kekus Digital the_FilePath = CFStringCreateWithPascalString(kCFAllocatorDefault, the_cString, kCFStringEncodingUTF8); the_Url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, the_FilePath, kCFURLHFSPathStyle, false); the_bReturnValue = CFURLGetFileSystemRepresentation(the_Url, true, the_pcUnixFilePath, 512); strcpy(filename, the_pcUnixFilePath); //till here #endif if ((outfile = fopen(filename, "wb")) == NULL) { PrintError("can't open %s", filename); return -1; } TwoToOneByte(im); jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = im->width; /* image width and height, in pixels */ cinfo.image_height = im->height; cinfo.input_components = 3; /* # of color components per pixel */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ jpeg_set_defaults(&cinfo); if (2 != (progressive & 2)) cinfo.optimize_coding = TRUE; jpeg_set_quality(&cinfo, quality, TRUE); if (1 == (progressive & 1)) jpeg_simple_progression(&cinfo); jpeg_start_compress(&cinfo, TRUE); // Write ICC Profile if it exists if (im->metadata.iccProfile.size > 0) { jpegICCWriteProfile(&cinfo, (JOCTET *)im->metadata.iccProfile.data, im->metadata.iccProfile.size); } scanlines_written = 0; data = *(im->data); buf = (unsigned char *) malloc((size_t) im->bytesPerLine); if (buf == NULL) { PrintError("Not enough memory"); fclose(outfile); return -1; } while (scanlines_written < im->height) { memcpy(buf, data, (size_t) im->bytesPerLine); if (im->bitsPerPixel == 32) // Convert 4->3 samples { int x; unsigned char *c1 = buf, *c2 = buf; for (x = 0; x < im->width; x++) { c2++; *c1++ = *c2++; *c1++ = *c2++; *c1++ = *c2++; } } if (jpeg_write_scanlines(&cinfo, (JSAMPARRAY) & buf, 1)) { scanlines_written++; data += im->bytesPerLine; } } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); fclose(outfile); free(buf); return 0; }