OSStatus TextViewSetFontStyleOfThisRange( HIViewRef textView, UInt32 setStyle, TXNOffset startRng, TXNOffset endRng ) { TXNTypeAttributes typeAttr[] = {{kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize, {0}}}; typeAttr[0].data.dataValue = setStyle; return TXNSetTypeAttributes( HITextViewGetTXNObject(textView), 1, typeAttr, startRng, endRng ); }
OSStatus TextViewDemoActionGroup( HIViewRef textView ) { const char* sampleText = "bigger...\n"; static const CFStringRef taskCFStr = CFSTR("TaskActionGroup"); static const CFStringRef actionLabel = CFSTR("Example Action Group"); TXNObject txnObj = HITextViewGetTXNObject(textView); TXNTypeAttributes typeAttr[] = {{kTXNQDFontSizeAttribute, kTXNQDFontSizeAttributeSize, {0}}}; typeAttr[0].data.dataValue = (24 << 16); TXNBeginActionGroup( txnObj, actionLabel); TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNStartOffset, kTXNEndOffset ); TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNStartOffset, kTXNEndOffset ); typeAttr[0].data.dataValue = (36 << 16); TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset ); TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset ); typeAttr[0].data.dataValue = (48 << 16); TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset ); TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset ); typeAttr[0].data.dataValue = (72 << 16); TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset ); TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset ); typeAttr[0].data.dataValue = (96 << 16); TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset ); TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ) - 1 /*don't set last line return*/, kTXNEndOffset, kTXNEndOffset ); TXNEndActionGroup( txnObj ); SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr ); return noErr; }
/* initialize the status window (used to show console messages in the graphic environment */ void CARBON_GUI::setupStatusWindow() { OSStatus err=CreateWindowFromNib(nibRef,CFSTR("StatusWindow"),&statusWindow); if(err!=noErr) msg->error("Can't create status window (%d)!!",err); //SetDrawerParent(statusWindow,window); //SetDrawerPreferredEdge(statusWindow,kWindowEdgeBottom); //SetDrawerOffsets(statusWindow,20,20); /* install an eventHandler to intercept close requests */ err = InstallWindowEventHandler (statusWindow, NewEventHandlerUPP (StatusWindowEventHandler), GetEventTypeCount(statusEvents), statusEvents, this, NULL); if(err != noErr) msg->error("Can't install status window eventHandler"); /* and then install a command handler (to handle "clear" requests) */ err=InstallWindowEventHandler(statusWindow,NewEventHandlerUPP(StatusWindowCommandHandler), GetEventTypeCount(commands),commands,this,NULL); /* obtain an HIViewRef for the status text box ... we have to use it * to setup various properties and to obain a TXNObject needed to manage its content */ const ControlID txtid={ CARBON_GUI_APP_SIGNATURE, STATUS_TEXT_ID }; err= HIViewFindByID(HIViewGetRoot(statusWindow), txtid, &statusTextView); if(err!=noErr) return;// msg->warning("Can't get textView for status window (%d)!!",err); statusText = HITextViewGetTXNObject(statusTextView); if(!statusText) { msg->error("Can't get statusText object from status window!!"); } // TXNControlTag iControlTags[1] = { kTXNAutoScrollBehaviorTag }; // TXNControlData iControlData[1] = { kTXNAutoScrollNever }; //kTXNAutoScrollWhenInsertionVisible }; // err = TXNSetTXNObjectControls(statusText,false,1,iControlTags,iControlData); //TextViewSetObjectControlData //TextViewSetObjectControlData(statusText,kTXNAutoScrollBehaviorTag,kUn kTXNAutoScrollWhenInsertionVisible) /* setup status text font size and color */ // Create type attribute data structure UInt32 fontSize = 10 << 16; // needs to be in Fixed format TXNAttributeData fsData,fcData; fsData.dataValue=fontSize; fcData.dataPtr=(void *)&black; TXNTypeAttributes attributes[] = { //{ kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize, bold }, { kTXNQDFontColorAttribute, kTXNQDFontColorAttributeSize,fcData}, //&lgrey }, { kTXNQDFontSizeAttribute, kTXNFontSizeAttributeSize,fsData } }; err= TXNSetTypeAttributes( statusText, 2, attributes, kTXNStartOffset,kTXNEndOffset ); /* block user input in the statusText box */ TXNControlTag tags[] = { kTXNNoUserIOTag }; TXNControlData vals[] = { kTXNReadOnly }; err=TXNSetTXNObjectControls(statusText,false,1,tags,vals); if(err!=noErr) msg->error("Can't set statusText properties (%d)!!",err); // TXNSetScrollbarState(statusText,kScrollBarsAlwaysActive); //struct TXNBackground bg = { kTXNBackgroundTypeRGB, black }; //TXNSetBackground(statusText,&bg); }
OSStatus TextViewIncrementFontSizeOfThisRange( HIViewRef textView, TXNOffset startRng, TXNOffset endRng, Boolean incrementUp, UInt32 count = 1 /*unused*/ ) { SInt32 direction = incrementUp?kTXNIncrementTypeSize:kTXNDecrementTypeSize; TXNTypeAttributes typeAttr[] = {{kTXNQDFontSizeAttribute, kTXNQDFontSizeAttributeSize, {0}}}; typeAttr[0].data.dataValue = direction; return TXNSetTypeAttributes( HITextViewGetTXNObject(textView), 1, typeAttr, startRng, endRng ); }
void IGraphicsCarbon::CreateTextEntry(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam) { if (!pControl || mTextEntryView || !mIsComposited) return; // Only composited carbon supports text entry WindowRef window = mWindow; TXNFrameOptions txnFrameOptions = kTXNMonostyledTextMask | kTXNDisableDragAndDropMask | kTXNSingleLineOnlyMask; TXNObject txnObject = 0; TXNFrameID frameID = 0; TXNObjectRefcon txnObjectRefCon = 0; HIRect rct; HIViewGetFrame(this->mView, &rct); HIViewRef contentView; HIViewFindByID (HIViewGetRoot(this->mWindow), kHIViewWindowContentID, &contentView); HIViewConvertRect(&rct, HIViewGetSuperview((HIViewRef)this->mView), contentView); Rect rect = { rct.origin.y + pTextRect->T, rct.origin.x + pTextRect->L, rct.origin.y + pTextRect->B + 1, rct.origin.x + pTextRect->R + 1 }; if (TXNNewObject(NULL, window, &rect, txnFrameOptions, kTXNTextEditStyleFrameType, kTXNSingleStylePerTextDocumentResType, kTXNMacOSEncoding, &txnObject, &frameID, txnObjectRefCon) == noErr) { TXNSetFrameBounds(txnObject, rect.top, rect.left, rect.bottom, rect.right, frameID); mTextEntryView = txnObject; // Set the text to display by defualt TXNSetData(mTextEntryView, kTXNTextData, pString, strlen(pString)/*+1*/, kTXNStartOffset, kTXNEndOffset); // center aligned text has problems with uneven string lengths RGBColor tc; tc.red = pText->mTextEntryFGColor.R * 257; tc.green = pText->mTextEntryFGColor.G * 257; tc.blue = pText->mTextEntryFGColor.B * 257; TXNBackground bg; bg.bgType = kTXNBackgroundTypeRGB; bg.bg.color.red = pText->mTextEntryBGColor.R * 257; bg.bg.color.green = pText->mTextEntryBGColor.G * 257; bg.bg.color.blue = pText->mTextEntryBGColor.B * 257; TXNSetBackground(mTextEntryView, &bg); // Set justification SInt16 justification; Fract flushness; switch ( pText->mAlign ) { case IText::kAlignCenter: justification = kTXNCenter; // seems to be buggy wrt dragging and alignement with uneven string lengths flushness = kATSUCenterAlignment; break; case IText::kAlignFar: justification = kTXNFlushRight; flushness = kATSUEndAlignment; break; case IText::kAlignNear: default: justification = kTXNFlushLeft; flushness = kATSUStartAlignment; break; } TXNControlTag controlTag[1]; TXNControlData controlData[1]; controlTag[0] = kTXNJustificationTag; controlData[0].sValue = justification; TXNSetTXNObjectControls(mTextEntryView, false, 1, controlTag, controlData); ATSUFontID fontid = kATSUInvalidFontID; if (pText->mFont && pText->mFont[0]) { ATSUFindFontFromName(pText->mFont, strlen(pText->mFont), kFontFullName /* kFontFamilyName? */ , (FontPlatformCode)kFontNoPlatform, kFontNoScriptCode, kFontNoLanguageCode, &fontid); } // font (NOT working) TXNTypeAttributes attributes[3]; attributes[0].tag = kATSUFontTag; attributes[0].size = sizeof(ATSUFontID); attributes[0].data.dataPtr = &fontid; // size attributes[1].tag = kTXNQDFontSizeAttribute; attributes[1].size = kTXNFontSizeAttributeSize; attributes[1].data.dataValue = pText->mSize << 16; // color attributes[2].tag = kTXNQDFontColorAttribute; attributes[2].size = kTXNQDFontColorAttributeSize; attributes[2].data.dataPtr = &tc; // Finally set the attributes TXNSetTypeAttributes(mTextEntryView, 3, attributes, kTXNStartOffset, kTXNEndOffset); // Ensure focus remains consistent SetUserFocusWindow(window); AdvanceKeyboardFocus(window); // Set the focus to the edit window TXNFocus(txnObject, true); TXNSelectAll(mTextEntryView); TXNShowSelection(mTextEntryView, true); // The event types const static EventTypeSpec eventTypes[] = { { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseWheelMoved }, { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowFocusRelinquish }, { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyRepeat } }; // Install the event handler InstallWindowEventHandler(window, TextEntryHandler, GetEventTypeCount(eventTypes), eventTypes, this, &mTextEntryHandler); mEdControl = pControl; mEdParam = pParam; mTextEntryRect = *pTextRect; } }