[futurebasic] [FB] How to activate an HITextView programmatically

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2012 : Group Archive : Group : All Groups

From: Domokos Vekas <domika@...>
Date: Thu, 15 Mar 2012 22:29:46 +0100
I would like to ask how to activate an HITextView (embedded into an
HIScrollView à la SVV) programmatically. I hope it is not too
complicated, even if I haven't find any helpful information in the
examples.

If I populate a window with old fashioned edit fields and HITextViews,
the most recently created edit field is active (and will receive
keyboard input), even if the HITextViews are created later in the
source code, as in the small demo below. I can use the edit field
statement to activate an edit field (or deactivate all edit fields),
but how can I activate/deactivate an HITextView?

Thanks in advance for your help,
Domokos

'----- demo ------
include "Tlbx MacTextEditor.incl"

local fn SetHIViewTextString( txtView as HIViewRef, s as Str255 )
'~'1
end fn = fn TXNSetData( fn HITextViewGetTXNObject( txtView ),
_kTXNTextData, @s[1], ¬
s[0], _kTXNStartOffset, _kTXNEndOffset )

local fn HIViewCreateScrollHITextView( wRef as WindowRef, x as short,
y as short, ¬
w as short, h as short ) as HIViewRef
'~'1
dim as HIViewRef  textView
dim as HIRect  myViewRect
dim as HIViewRef  contentView, scrollView
dim as TXNFrameOptions txtOptions
dim as OptionBits  scrlOptions
dim as OSStatus err

// Get content view
err = fn HIViewFindByID( fn HIViewGetRoot( wRef ),
kHIViewWindowContentID, @contentView )

scrlOptions = _kHIScrollViewOptionsVertScroll
err = fn HIScrollViewCreate( scrlOptions, @scrollView )
err = fn HIViewSetVisible( scrollView, _true )
err = fn HIViewAddSubview( contentView, scrollView )

// Controls location and size of HITextView
myViewRect.origin.x = x
myViewRect.origin.y = y
myViewRect.size.width = w
myViewRect.size.height = h
err = fn HIViewSetFrame( scrollView, myViewRect )

txtOptions = _kOutputTextInUnicodeEncodingMask
txtOptions +=_kTXNAlwaysWrapAtViewEdgeMask
txtOptions += _kTXNWantVScrollBarMask
err = fn HITextViewCreate( myViewRect, 0, txtOptions, @textView )
err = fn HIViewAddSubview( scrollView, textView )
err = fn HIViewSetVisible( textView, _true )
end fn = textView

local fn BuildWindow
'~'1
dim as HIViewRef  txtView, txtView2
dim as WindowAttributes  attr

attr  = _kWindowStandardDocumentAttributes
attr += _kWindowStandardHandlerAttribute
attr += _kWindowCompositingAttribute
attr += _kWindowMetalAttribute
appearance window 1, "How to activate an HITextView?",,
_kDocumentWindowClass, attr

edit field 1, "old fashioned edit field 1", (20, 50)-(150, 150)
edit field 2, "old fashioned edit field 2", (20, 200)-(150, 300)
edit field 1//activate field 1

txtView = fn HIViewCreateScrollHITextView( window( _wndRef ), 200, 50,
150, 100 )
fn SetHIViewTextString( txtView, "HITextView 1" )

txtView2 = fn HIViewCreateScrollHITextView( window( _wndRef ), 200,
200, 150, 100 )
fn SetHIViewTextString( txtView2, "HITextView 2" )

// is this I need? It does not seem to work:
fn HIViewSetActivated( txtView, _true )//( HIViewRef inView, Boolean
inSetActivated)

end fn

edit menu 2
fn BuildWindow
HandleEvents
'-----------