pascal OSStatus OpenEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { NavDialogRef fileDialog; NavDialogCreationOptions fo; NavGetDefaultDialogCreationOptions(&fo); fo.optionFlags=0; fo.parentWindow=win; NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog); // if someone wants to somehow get the file selector to filter like in the Windows example, that'd be nice ;) if (!NavDialogRun(fileDialog)) { NavReplyRecord r; if (!NavDialogGetReply(fileDialog,&r)) { AEKeyword k; FSRef fr; if (!AEGetNthPtr(&r.selection,1,typeFSRef,&k,NULL,&fr,sizeof(fr),NULL)) { char file[256]; FSRefMakePath(&fr,(BYTE*)file,sizeof(file)); BASS_StreamFree(chan); // free old stream before opening new if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FLOAT))) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file...")); { ControlRef cref=GetControl(11); SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,0,""); DrawOneControl(cref); } SetControl32BitMaximum(GetControl(12),0); Error("Can't play the file"); } else { CFStringRef cs=CFStringCreateWithCString(0,file,kCFStringEncodingUTF8); SetControlTitleWithCFString(inUserData,cs); CFRelease(cs); { // display the file type and length QWORD bytes=BASS_ChannelGetLength(chan,BASS_POS_BYTE); DWORD time=BASS_ChannelBytes2Seconds(chan,bytes); BASS_CHANNELINFO info; BASS_ChannelGetInfo(chan,&info); sprintf(file,"channel type = %x (%s)\nlength = %llu (%u:%02u)", info.ctype,GetCTypeString(info.ctype,info.plugin),bytes,time/60,time%60); { ControlRef cref=GetControl(11); SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,strlen(file),file); DrawOneControl(cref); } SetControl32BitMaximum(GetControl(12),time); // update scroller range } BASS_ChannelPlay(chan,FALSE); } } NavDisposeReply(&r); } } NavDialogDispose(fileDialog); return noErr; }
static void window_adjust_scrollbars(WindowRef windowRef) { IMAGE *img; Rect portRect; img = (IMAGE*)GetWRefCon(windowRef); GetWindowPortBounds(windowRef,&portRect); /* Move the crollbars to the edges of the window */ HideControl(img->scrollbarVertRef); HideControl(img->scrollbarHorizRef); MoveControl(img->scrollbarVertRef,portRect.right - kScrollBarWidth, portRect.top - 1); MoveControl(img->scrollbarHorizRef,portRect.left - 1, portRect.bottom - kScrollBarWidth); SizeControl(img->scrollbarVertRef,kScrollBarWidth + 1, portRect.bottom - portRect.top - kScrollBarWidth + 1); SizeControl(img->scrollbarHorizRef, portRect.right - portRect.left - kScrollBarWidth + 1, kScrollBarWidth + 1); /* Adjust the scroll position showing */ if (img->pixmapHdl) { PixMap *pixmap = *(img->pixmapHdl); int visibleHeight = portRect.bottom - portRect.top - kScrollBarWidth; int visibleWidth = portRect.right - portRect.left - kScrollBarWidth; if (pixmap->bounds.bottom > visibleHeight) { SetControl32BitMaximum(img->scrollbarVertRef, pixmap->bounds.bottom - visibleHeight); SetControlViewSize(img->scrollbarVertRef,visibleHeight); } else SetControlMaximum(img->scrollbarVertRef, 0); if (pixmap->bounds.right > visibleWidth) { SetControl32BitMaximum(img->scrollbarHorizRef, pixmap->bounds.right - visibleWidth); SetControlViewSize(img->scrollbarHorizRef, visibleWidth); } else SetControlMaximum(img->scrollbarHorizRef, 0); } ShowControl(img->scrollbarVertRef); ShowControl(img->scrollbarHorizRef); }
void wxSpinButton::SetRange(int minVal, int maxVal) { m_min = minVal; m_max = maxVal; SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ; SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ; }
// Tell a control to update its value & maximum. OSStatus ControlUpdateValues( ControlRef scrollBar, SInt32 value, SInt32 max ) { require( IsValidControlHandle( scrollBar ), BadControl ); SetControl32BitValue( scrollBar, value ); SetControl32BitMaximum( scrollBar, max ); return noErr; BadControl: return paramErr; }
void wxSlider::SetRange(int minValue, int maxValue) { wxString value; m_rangeMin = minValue; m_rangeMax = maxValue; SetControl32BitMinimum( (ControlHandle) m_macControl, m_rangeMin); SetControl32BitMaximum( (ControlHandle) m_macControl, m_rangeMax); if(m_macMinimumStatic) { value.Printf(wxT("%d"), m_rangeMin); m_macMinimumStatic->SetLabel(value); } if(m_macMaximumStatic) { value.Printf(wxT("%d"), m_rangeMax); m_macMaximumStatic->SetLabel(value); } SetValue(m_rangeMin); }
void AUControlGroup::CreatePopupMenu (AUCarbonViewBase * auView, const CAAUParameter & auvp, const Rect & area, const ControlFontStyleRec & inFontStyle, const bool inSizeToFit) { #if !__LP64__ ControlRef thePopUp; verify_noerr(CreatePopupButtonControl (auView->GetCarbonWindow(), &area, NULL, -12345, // DON'T GET MENU FROM RESOURCE mMenuID FALSE, // variableWidth, 0, // titleWidth, 0, // titleJustification, 0, // titleStyle, &thePopUp)); ControlSize small = kControlSizeSmall; SetControlData(thePopUp, kControlEntireControl, kControlSizeTag, sizeof(ControlSize), &small); MenuRef menuRef; verify_noerr(CreateNewMenu( 1, 0, &menuRef)); for (int i = 0; i < auvp.GetNumIndexedParams(); ++i) { verify_noerr(AppendMenuItemTextWithCFString (menuRef, auvp.GetParamName(i), kMenuItemAttrIgnoreMeta, 0, 0)); } verify_noerr(SetControlData(thePopUp, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef)); SetControl32BitMaximum(thePopUp, auvp.GetNumIndexedParams()); verify_noerr (SetControlFontStyle (thePopUp, &inFontStyle)); if (inSizeToFit) { AUCarbonViewControl::SizeControlToFit(thePopUp); } auView->AddCarbonControl(AUCarbonViewControl::kTypeDiscrete, auvp, thePopUp); #endif }
void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, bool refresh) { m_pageSize = pageSize; m_viewSize = thumbSize; m_objectSize = range; int range1 = wxMax((m_objectSize - m_viewSize), 0) ; SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ; SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ; SetControl32BitValue( (ControlHandle) m_macControl , position ) ; if ( UMAGetAppearanceVersion() >= 0x0110 ) { if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress ) { SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ; } } if ( refresh ) MacRedrawControl() ; }
// Associate a tracking procedure UPP with each of a scroll control. OSStatus ControlRegisterActionProc( WindowRef window, ControlRef scrollControl, TXNScrollBarOrientation orientation ) { OSStatus status = noErr; SInt32 max = 200; require( IsValidControlHandle( scrollControl ), BadControl ); // Create the callback if( gControlActionUPP == NULL ) gControlActionUPP = NewControlActionUPP( MyTrackActionProcedure ); require( gControlActionUPP != NULL, NullControlActionUPP ); // Associate the callback with the control SetControlAction( scrollControl, gControlActionUPP ); // set the max value of the control based on the height of the text // in the text view if( orientation = kTXNVertical ) { SInt32 height = (SInt32)TextViewGetTextHeight( window, kMyMLTEDataStructProperty ); max = ( height <= kMyINT32_MAX ? height : kMyINT32_MAX ); } else { SInt32 width = (SInt32)TextViewGetTextWidth( window, kMyMLTEDataStructProperty ); max = ( width <= kMyINT32_MAX ? width : kMyINT32_MAX ); } SetControl32BitMaximum( scrollControl, max ); BadControl: NullControlActionUPP: return status; }
static DialogRef DrawDialogTheMacOS8or9Way(void) { short i; ControlRef theControl; DialogRef theDialog = GetNewDialog(257, NULL, (WindowRef)-1L); if (theDialog == NULL) return(NULL); // Let's get a pulsing blue default button! GetDialogItemAsControl(theDialog, 1, &theControl); SetWindowDefaultButton(GetDialogWindow(theDialog), theControl); // Setting the check box GetDialogItemAsControl(theDialog, 2, &theControl); SetControl32BitValue(theControl, 1); // We need to autoembed our radio buttons in the radio group // so that they work automatically for (i = 4; i <= 8; i++) { GetDialogItemAsControl(theDialog, i, &theControl); AutoEmbedControl(theControl, GetDialogWindow(theDialog)); } // we assign a key filter on our edit text box so that only digits can be entered ControlRef theTextControl; ControlKeyFilterUPP keyFilter = MyEditKeyFilter; GetDialogItemAsControl(theDialog, 9, &theTextControl); SetKeyboardFocus(GetDialogWindow(theDialog), theTextControl, kControlFocusNextPart); SetControlData(theTextControl, kControlEntireControl, kControlEditTextKeyFilterTag, sizeof(keyFilter), &keyFilter); // Setting the action proc for the scroll bar so that the PageUp/PageDown/Up/Down buttons work // We also associate the previous edit text box with the scroll bar so it gets updated GetDialogItemAsControl(theDialog, 14, &theControl); SetControlAction(theControl, ScrollBar32BitActionProc); SetControl32BitMaximum(theControl, 0x7fffffff); SetControlReference(theControl, (SInt32)theTextControl); // The static text control is created as a resource but we could only set its title and // not its content. We set the content now! GetDialogItemAsControl(theDialog, 15, &theControl); Str255 theTitle; GetControlTitle(theControl, theTitle); SetControlData(theControl, kControlEntireControl, kControlStaticTextTextTag, theTitle[0], &theTitle[1]); // We set up our User Pane Control with the draw, hit test, and track (actually action) procs GetDialogItemAsControl(theDialog, 13, &theControl); Rect bounds; GetControlBounds(theControl, &bounds); gUserH = (bounds.left + bounds.right) / 2; gUserV = (bounds.top + bounds.bottom) / 2; ControlUserPaneDrawUPP userPaneDraw = MyUserPaneDrawProc; SetControlData(theControl, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(userPaneDraw), &userPaneDraw); ControlUserPaneHitTestUPP userPaneHitTest = MyUserPaneHitTestProc; SetControlData(theControl, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(userPaneHitTest), &userPaneHitTest); SetControlAction(theControl, MoveSpotActionProc); ShowWindow(GetDialogWindow(theDialog)); return(theDialog); }
void TkpDisplayScale( ClientData clientData) /* Widget record for scale. */ { TkScale *scalePtr = (TkScale *) clientData; Tk_Window tkwin = scalePtr->tkwin; Tcl_Interp *interp = scalePtr->interp; int result; char string[TCL_DOUBLE_SPACE]; MacScale *macScalePtr = (MacScale *) clientData; Rect r; WindowRef windowRef; CGrafPtr destPort, savePort; Boolean portChanged; MacDrawable *macDraw; SInt32 initialValue, minValue, maxValue; UInt16 numTicks; #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("TkpDisplayScale"); #endif scalePtr->flags &= ~REDRAW_PENDING; if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) { goto done; } /* * Invoke the scale's command if needed. */ Tcl_Preserve((ClientData) scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { Tcl_Preserve((ClientData) interp); sprintf(string, scalePtr->format, scalePtr->value); result = Tcl_VarEval(interp, scalePtr->command, " ", string, NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundError(interp); } Tcl_Release((ClientData) interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { Tcl_Release((ClientData) scalePtr); return; } Tcl_Release((ClientData) scalePtr); /* * Now handle the part of redisplay that is the same for * horizontal and vertical scales: border and traversal * highlight. */ if (scalePtr->highlightWidth != 0) { GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin)); Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, Tk_WindowId(tkwin)); } Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scalePtr->bgBorder, scalePtr->highlightWidth, scalePtr->highlightWidth, Tk_Width(tkwin) - 2*scalePtr->highlightWidth, Tk_Height(tkwin) - 2*scalePtr->highlightWidth, scalePtr->borderWidth, scalePtr->relief); /* * Set up port for drawing Macintosh control. */ macDraw = (MacDrawable *) Tk_WindowId(tkwin); destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin)); portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); /* * Create Macintosh control. */ #define MAC_OSX_SCROLL_WIDTH 10 if (scalePtr->orient == ORIENT_HORIZONTAL) { int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + scalePtr->inset; r.top = macDraw->yOff + offset; r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset; r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2; } else { int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + offset; r.top = macDraw->yOff + scalePtr->inset; r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2; r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset; } if (macScalePtr->scaleHandle == NULL) { #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("Initialising scale"); #endif initialValue = scalePtr->value; if (scalePtr->orient == ORIENT_HORIZONTAL) { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } else { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } if (scalePtr->tickInterval == 0) { numTicks = 0; } else { numTicks = (maxValue - minValue)/scalePtr->tickInterval; } CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue, kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc, &(macScalePtr->scaleHandle)); SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr); if (IsWindowActive(windowRef)) { macScalePtr->flags |= ACTIVE; } } else { SetControlBounds(macScalePtr->scaleHandle, &r); SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value); SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue); SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue); } /* * Finally draw the control. */ SetControlVisibility(macScalePtr->scaleHandle,true,true); HiliteControl(macScalePtr->scaleHandle,0); Draw1Control(macScalePtr->scaleHandle); if (portChanged) { QDSwapPort(savePort, NULL); } done: scalePtr->flags &= ~REDRAW_ALL; }
void XControl::SetMenuHandle(MenuHandle menu) { SetControlData(mControl, 0, kControlPopupButtonMenuHandleTag, sizeof(MenuHandle), &menu); SetControl32BitMaximum(mControl, CountMenuItems(menu)); }
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; }
pascal OSStatus OpenEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { DWORD p; NavDialogRef fileDialog; NavDialogCreationOptions fo; NavGetDefaultDialogCreationOptions(&fo); fo.optionFlags=0; fo.parentWindow=win; NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog); if (!NavDialogRun(fileDialog)) { NavReplyRecord r; if (!NavDialogGetReply(fileDialog,&r)) { AEKeyword k; FSRef fr; if (!AEGetNthPtr(&r.selection,1,typeFSRef,&k,NULL,&fr,sizeof(fr),NULL)) { char file[256]; FSRefMakePath(&fr,(BYTE*)file,sizeof(file)); BASS_StreamFree(chan); // free old streams before opening new // create decode channel chan = BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE|BASS_STREAM_PRESCAN); // check for MOD if (!chan) chan = BASS_MusicLoad(FALSE, file, 0, 0, BASS_SAMPLE_FLOAT|BASS_MUSIC_RAMP|BASS_STREAM_DECODE|BASS_MUSIC_PRESCAN,0); if (!chan) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Selected file couldn't be loaded!"); } else { // create new stream - decoded & reversed // 2 seconds decoding block as a decoding channel if (!(chan=BASS_FX_ReverseCreate(chan, 2, BASS_STREAM_DECODE|BASS_FX_FREESOURCE))) { SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Couldn't create a reversed stream!"); BASS_StreamFree(chan); BASS_MusicFree(chan); } else { // create a new stream - decoded & resampled :) if (!(chan=BASS_FX_TempoCreate(chan, BASS_SAMPLE_LOOP|BASS_FX_FREESOURCE))){ SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file && play it...")); Error("Couldn't create a resampled stream!"); BASS_StreamFree(chan); BASS_MusicFree(chan); } else { // update the Button to show the loaded file c2pstrcpy((BYTE*)file,file); SetControlTitle(inUserData,(BYTE*)file); // update the position slider p = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE)); SetControl32BitMaximum(GetControl(15),p); SetControl32BitValue(GetControl(15),p); // set Volume p = GetControl32BitValue(GetControl(11)); BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, (float)p/100.0f); // update tempo slider SetControl32BitValue(GetControl(13),0); SetStaticText(12,"Tempo = 0%"); // play new created stream BASS_ChannelPlay(chan,FALSE); } } } } NavDisposeReply(&r); } } NavDialogDispose(fileDialog); return noErr; }
/***************************************************** * * Do_NewWindow() * * Purpose: called to create a new window that has been constructed with Interface Builder * * Inputs: none * * Returns: OSStatus - error code (0 == no error) */ OSStatus Do_NewWindow(void) { OSStatus status; static IBNibRef gIBNibRef = NULL; WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; CFMutableStringRef theNewTitle = NULL; if (gIBNibRef == NULL) { // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. status = CreateNibReference(CFSTR("main"), &gIBNibRef); require_noerr(status, CantGetNibRef); } require(gIBNibRef != NULL, CantGetNibRef); // Create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. status = CreateWindowFromNib(gIBNibRef, CFSTR("MainWindow"), &aWindowRef); require_noerr(status, CantCreateWindow); require(NULL != aWindowRef, CantCreateWindow); // Grab the title of the window and add the window count to it status = CopyWindowTitleAsCFString(aWindowRef, &theTitle); require_noerr(status, CantGetSetTitle); theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle); require(NULL != theNewTitle, CantGetSetTitle); CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount); status = SetWindowTitleWithCFString(aWindowRef, theNewTitle); require_noerr(status, CantGetSetTitle); // Create the custom view to be tested and embed it in our group box control HIViewRef groupBox; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kGroupBoxID, &groupBox); require_noerr(status, CantFindGroupBox); require(groupBox != NULL, CantFindGroupBox); HIViewRef customView; status = HICreateCustomView(NULL, &customView); require_noerr(status, CantCreateCustom); require(customView != NULL, CantCreateCustom); HIRect groupBoxBounds; HIViewGetBounds(groupBox, &groupBoxBounds); groupBoxBounds.origin.x += 20; groupBoxBounds.origin.y += 34; groupBoxBounds.size.width -= 40; groupBoxBounds.size.height -= 54; HIViewSetFrame(customView, &groupBoxBounds); HIViewSetLayoutInfo(customView, &kBindToParentLayout); status = HIViewAddSubview(groupBox, customView); require_noerr(status, CantAddSubview); HIViewSetVisible(customView, true); // Let's react to User's commands. EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // Let's update our static text field whenever the value or hilite of our tested custom view changes EventTypeSpec eventTypeCVFC[] = { {kEventClassControl, kEventControlValueFieldChanged}, {kEventClassControl, kEventControlHiliteChanged} }; status = InstallControlEventHandler(customView, Handle_ControlValueFieldOrHiliteChanged, 2, eventTypeCVFC, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // We accept only numbers in our Edit text control HIViewRef editText; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText); #ifdef MAC_OS_X_VERSION_10_4 // in Tiger, only 1 event handler is necessary for the key filtering EventTypeSpec eventTypeTSCIR = {kEventClassTextField, kEventTextShouldChangeInRange}; status = InstallControlEventHandler(editText, Handle_TextShouldChangeInRange, 1, &eventTypeTSCIR, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #else // pre-Tiger, we need a different event handler and a validation proc to handle pastes and drops. ControlEditTextValidationUPP textValidation = MyValidationProc; SetControlData(editText, kControlEntireControl, kControlEditTextValidationProcTag, sizeof(textValidation), &textValidation); EventTypeSpec eventTypeTIUFKE = {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}; status = InstallControlEventHandler(editText, Handle_TextInputEvent, 1, &eventTypeTIUFKE, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #endif // Finishing the custom view setup SetControl32BitMinimum(customView, 0); SetControl32BitMaximum(customView, 36); SetControl32BitValue(customView, 2); // We want window and thus our custom view to be able to respond to drops status = SetAutomaticControlDragTrackingEnabledForWindow(aWindowRef, true); require_noerr(status, SetAutomaticControlDragTrackingEnabledForWindow); ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); SetAutomaticControlDragTrackingEnabledForWindow: SetControlDragTrackingEnabled: CantAddSubview: CantCreateCustom: CantFindGroupBox: CantInstallEventHandler: CantGetSetTitle: CantAllocateWindowData: CantCreateWindow: CantGetNibRef: if (theTitle != NULL) CFRelease(theTitle); if (theNewTitle != NULL) CFRelease(theNewTitle); return status; } // Do_NewWindow
AUVPresets::AUVPresets (AUCarbonViewBase* inParentView, CFArrayRef& inPresets, Point inLocation, int nameWidth, int controlWidth, ControlFontStyleRec & inFontStyle) : AUPropertyControl (inParentView), mPresets (inPresets), mView (inParentView) { #if !__LP64__ Rect r; // ok we now have an array of factory presets // get their strings and display them r.top = inLocation.v; r.bottom = r.top; r.left = inLocation.h; r.right = r.left; // localize as necessary if (!sAUVPresetLocalized) { CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(kLocalizedStringBundle_AUView); if (mainBundle) { kStringFactoryPreset = CFCopyLocalizedStringFromTableInBundle( kAUViewLocalizedStringKey_FactoryPreset, kLocalizedStringTable_AUView, mainBundle, CFSTR("FactoryPreset title string")); sAUVPresetLocalized = true; } } // create localized title string CFMutableStringRef factoryPresetsTitle = CFStringCreateMutable(NULL, 0); CFStringAppend(factoryPresetsTitle, kStringFactoryPreset); CFStringAppend(factoryPresetsTitle, kAUViewUnlocalizedString_TitleSeparator); ControlRef theControl; verify_noerr(CreateStaticTextControl(mView->GetCarbonWindow(), &r, factoryPresetsTitle, &inFontStyle, &theControl)); SInt16 width = 0; AUCarbonViewControl::SizeControlToFit(theControl, &width, &mHeight); CFRelease(factoryPresetsTitle); EmbedControl(theControl); r.top -= 2; r.left += width + 10; r.right = r.left; r.bottom = r.top; verify_noerr(CreatePopupButtonControl ( mView->GetCarbonWindow(), &r, NULL, -12345, // DON'T GET MENU FROM RESOURCE mMenuID,!!! FALSE, // variableWidth, 0, // titleWidth, 0, // titleJustification, 0, // titleStyle, &mControl)); MenuRef menuRef; verify_noerr(CreateNewMenu(1, 0, &menuRef)); int numPresets = CFArrayGetCount(mPresets); for (int i = 0; i < numPresets; ++i) { AUPreset* preset = (AUPreset*) CFArrayGetValueAtIndex (mPresets, i); verify_noerr(AppendMenuItemTextWithCFString (menuRef, preset->presetName, 0, 0, 0)); } verify_noerr(SetControlData(mControl, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef)); verify_noerr (SetControlFontStyle (mControl, &inFontStyle)); SetControl32BitMaximum (mControl, numPresets); // size popup SInt16 height = 0; AUCarbonViewControl::SizeControlToFit(mControl, &width, &height); if (height > mHeight) mHeight = height; if (mHeight < 0) mHeight = 0; // find which menu item is the Default preset UInt32 propertySize = sizeof(AUPreset); AUPreset defaultPreset; OSStatus result = AudioUnitGetProperty (mView->GetEditAudioUnit(), kAudioUnitProperty_PresentPreset, kAudioUnitScope_Global, 0, &defaultPreset, &propertySize); mPropertyID = kAudioUnitProperty_PresentPreset; #endif #ifndef __LP64__ if (result != noErr) { // if the PresentPreset property is not implemented, fall back to the CurrentPreset property OSStatus result = AudioUnitGetProperty (mView->GetEditAudioUnit(), kAudioUnitProperty_CurrentPreset, kAudioUnitScope_Global, 0, &defaultPreset, &propertySize); mPropertyID = kAudioUnitProperty_CurrentPreset; if (result == noErr) CFRetain (defaultPreset.presetName); } #endif #if !__LP64__ EmbedControl (mControl); HandlePropertyChange(defaultPreset); RegisterEvents(); #endif }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // AURenderQualityPopup::AURenderQualityPopup // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AURenderQualityPopup::AURenderQualityPopup (AUCarbonViewBase *inBase, Point inLocation, int inRightEdge, ControlFontStyleRec & inFontStyle) : AUPropertyControl (inBase) { Rect r; r.top = inLocation.v; r.bottom = r.top + 17; r.left = inLocation.h; r.right = r.left + inRightEdge; ControlFontStyleRec fontStyle = inFontStyle; inFontStyle.just = teFlushRight; ControlRef ref; CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.audio.units.Components")); if (mainBundle != NULL) { CFMutableStringRef renderTitle = CFStringCreateMutable(NULL, 0); CFStringAppend(renderTitle, CFCopyLocalizedStringFromTableInBundle( CFSTR("Render Quality"), CFSTR("CustomUI"), mainBundle, CFSTR("The Render Quality Popup menu title"))); CFStringAppend(renderTitle, CFSTR(":")); OSErr theErr = CreateStaticTextControl (GetCarbonWindow(), &r, renderTitle, &inFontStyle, &ref); if (theErr == noErr) EmbedControl(ref); r.left = r.right + 8; r.right = r.left + 100; short bundleRef = CFBundleOpenBundleResourceMap (mainBundle); theErr = CreatePopupButtonControl (mView->GetCarbonWindow(), &r, NULL, /*kQualityMenuID*/ -12345, false, -1, 0, 0, &mControl); MenuRef menuRef; verify_noerr(CreateNewMenu(kQualityMenuID, 0, &menuRef)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Maximum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("High"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Medium"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Low"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Minimum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(SetControlData(mControl, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef)); verify_noerr(SetControlFontStyle (mControl, &inFontStyle)); SetControl32BitMaximum(mControl, 5); UInt32 renderQuality; UInt32 size = sizeof(UInt32); AudioUnitGetProperty (mView->GetEditAudioUnit(), kAudioUnitProperty_RenderQuality, kAudioUnitScope_Global, 0, &renderQuality, &size); HandlePropertyChange(renderQuality); EmbedControl(mControl); theErr = AudioUnitAddPropertyListener(mView->GetEditAudioUnit(), kAudioUnitProperty_RenderQuality, RenderQualityListener, this); CFBundleCloseBundleResourceMap (mainBundle, bundleRef); CFRelease(renderTitle); } RegisterEvents(); }