void AUControlGroup::CreateLabelledSliderAndEditText( AUCarbonViewBase * auView, const CAAUParameter & auvp, const Rect & area, Point labelSize, Point editTextSize, const ControlFontStyleRec & inFontStyle) { #if !__LP64__ ControlFontStyleRec fontStyle = inFontStyle; Rect sliderArea, textArea; ControlRef newControl; int width = area.right - area.left, height = area.bottom - area.top; bool horizontal = (width > height); sliderArea = area; textArea = area; if (horizontal) { textArea.left = area.right - editTextSize.h; // provide a large text box if param is generic and its values have strings... if (auvp.ValuesHaveStrings() && (auvp.ParamInfo().unit == kAudioUnitParameterUnit_Generic)) { textArea.right += 30; } sliderArea.right = textArea.left - kLabelAndSliderSpacing; textArea.top = area.top + (height - editTextSize.v) / 2; textArea.bottom = textArea.top + editTextSize.v; } else { textArea.top = area.bottom - editTextSize.v; sliderArea.bottom = textArea.top - kLabelAndSliderSpacing; textArea.left = area.left + (width - editTextSize.h) / 2; textArea.right = textArea.left + editTextSize.h; } CreateLabelledSlider(auView, auvp, sliderArea, labelSize, fontStyle); verify_noerr(CreateEditUnicodeTextControl(auView->GetCarbonWindow(), &textArea, CFSTR(""), false, &fontStyle, &newControl)); auView->AddCarbonControl(AUCarbonViewControl::kTypeText, auvp, newControl); #endif }
void IGraphicsCarbon::CreateTextEntry(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam) { ControlRef control = 0; if (!pControl || mTextEntryView || !mIsComposited) return; Rect r = { pTextRect->T, pTextRect->L, pTextRect->B, pTextRect->R }; // these adjustments should make it the same as the cocoa one, i.e. the same size as the pTextRect, but with the extra blue rim often this is too small //Rect r = { pTextRect->T+4, pTextRect->L+3, pTextRect->B-3, pTextRect->R -3 }; if (CreateEditUnicodeTextControl(NULL, &r, NULL, false, NULL, &control) != noErr) return; HIViewAddSubview(mView, control); const EventTypeSpec events[] = { { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyRepeat } }; InstallControlEventHandler(control, TextEntryHandler, GetEventTypeCount(events), events, this, &mTextEntryHandler); mTextEntryView = control; if (pString[0] != '\0') { CFStringRef str = CFStringCreateWithCString(NULL, pString, kCFStringEncodingUTF8); if (str) { SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextCFStringTag, sizeof(str), &str); CFRelease(str); } ControlEditTextSelectionRec sel; sel.selStart = 0; sel.selEnd = strlen(pString); SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSelectionTag, sizeof(sel), &sel); } int just = 0; switch ( pText->mAlign ) { case IText::kAlignNear: just = teJustLeft; break; case IText::kAlignCenter: just = teCenter; break; case IText::kAlignFar: just = teJustRight; break; default: just = teCenter; break; } ControlFontStyleRec font = { kControlUseJustMask | kControlUseSizeMask | kControlUseFontMask, 0, pText->mSize, 0, 0, just, 0, 0 }; CFStringRef str = CFStringCreateWithCString(NULL, pText->mFont, kCFStringEncodingUTF8); font.font = ATSFontFamilyFindFromName(str, kATSOptionFlagsDefault); SetControlData(mTextEntryView, kControlEditTextPart, kControlFontStyleTag, sizeof(font), &font); CFRelease(str); Boolean singleLineStyle = true; SetControlData(mTextEntryView, kControlEditTextPart, kControlEditTextSingleLineTag, sizeof (Boolean), &singleLineStyle); HIViewSetVisible(mTextEntryView, true); HIViewAdvanceFocus(mTextEntryView, 0); SetKeyboardFocus(mWindow, mTextEntryView, kControlEditTextPart); SetUserFocusWindow(mWindow); mEdControl = pControl; mEdParam = pParam; }