[futurebasic] Re: [FB] evaluating bits

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2007 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Wed, 9 May 2007 09:23:59 +0200
George asked:

> Is there a way to see those little suckers?

Run the following and paste text into the edit field. Opt-spaces will  
be visible  ;-)

Bernie


'----------
if ( system(_sysVers) < 1040 ) then shutdown "Requires OS X 10.4 or  
later"

include "Tlbx HIView.incl"

local fn CoreFoundationBundle
'~'1
begin globals
dim as CFBundleRef sCoreFoundationBundle// static
end globals
if ( sCoreFoundationBundle == 0 ) then sCoreFoundationBundle = ¬
fn CreateBundleForFramework( "CoreFoundation.framework" )
end fn = sCoreFoundationBundle


begin globals
dim as pointer gCFStringFindAndReplace
end globals

gCFStringFindAndReplace = fn GetMachFunctionFromBundle( ¬
fn CoreFoundationBundle(), "CFStringFindAndReplace" )
local fn CFStringFindAndReplace( theString as CFMutableStringRef, ¬
stringToFind as CFStringRef, replacementString as CFStringRef, ¬
rangeToSearchLocation as CFIndex, rangeToSearchLength as CFIndex, ¬
compareOptions as CFOptionFlags )
beginassem
   lwz r12,^gCFStringFindAndReplace
   mtspr ctr,r12
   mr r31,r2
   bctrl
   mr r2,r31
endassem
end fn// returns CFIndex


local mode
local fn HILayoutBindAll( c as HIViewRef )
'~'1
dim as HILayoutInfo layoutInfo

layoutInfo.version = _kHILayoutInfoVersionZero
call HIViewGetLayoutInfo( c, @layoutInfo )
layoutInfo.binding.left.toView = 0
layoutInfo.binding.left.kind = _kHILayoutBindLeft
layoutInfo.binding.top.toView = 0
layoutInfo.binding.top.kind = _kHILayoutBindTop
layoutInfo.binding.right.toView = 0
layoutInfo.binding.right.kind = _kHILayoutBindRight
layoutInfo.binding.bottom.toView = 0
layoutInfo.binding.bottom.kind = _kHILayoutBindBottom
call HIViewSetLayoutInfo( c, @layoutInfo )
end fn


local mode
local fn StringReplaceCharacter( string as CFStringRef, ¬
searchChar as CFStringRef, replaceStr as CFStringRef )
'~'1
dim as CFMutableStringRef replacement
dim as CFIndex count

replacement = fn CFStringCreateMutableCopy( 0, 0, string )
long if ( replacement )
count = fn CFStringFindAndReplace( replacement, searchChar, ¬
replaceStr, 0, fn CFStringGetLength( replacement ), 0 )
end if
end fn = replacement


local fn InstallTextChangeHandler( c as HIViewRef )
'~'1
dim as EventTypeSpec theEvent

begin globals
dim as proc sTextChangeEventUPP
end globals

long if ( sTextChangeEventUPP == 0 )
sTextChangeEventUPP = fn NewEventHandlerUPP( ¬
[proc "MyTextChangeHandler" + _FBprocToProcPtrOffset] )
end if

theEvent.eventClass = _kEventClassTextField
theEvent.eventKind = _kEventTextShouldChangeInRange
end fn = fn InstallEventHandler( fn GetControlEventTarget( c ), ¬
sTextChangeEventUPP, 1, @theEvent, #0, #0 )


long if 0
"MyTextChangeHandler"
enterproc fn MyTextChangedHandler( nextHandler as EventHandlerCallRef, ¬
theEvent as EventRef, userData as pointer ) = OSStatus
'~'1
dim as CFMutableStringRef @ replacement
dim as CFStringRef @ candidate
dim as OSStatus result : result = _eventNotHandledErr

call GetEventParameter( theEvent, _kEventParamCandidateText, ¬
_typeCFStringRef, #0, sizeof( CFStringRef ), #0, candidate )
long if ( candidate )
replacement = fn StringReplaceCharacter( candidate, ¬
fn CFSTR( " " ), fn CFSTR( "<LittleSucker>" ) )
long if ( replacement )
call SetEventParameter( theEvent, _kEventParamReplacementText, ¬
_typeCFStringRef, sizeof( CFStringRef ), replacement )
CFRelease( replacement )
result = _noErr
end if
end if
exitproc = result
end if


local mode
local fn BuildUI
'~'1
dim as Rect r
dim as WindowAttributes wa
dim as UInt16 item
dim as OSErr err

wa = _kWindowFullZoomAttribute ¬
_kWindowResizableAttribute ¬
_kWindowLiveResizeAttribute ¬
_kWindowStandardHandlerAttribute ¬
_kWindowCompositingAttribute

SetRect( r, 9, 49, 489, 409 )
appearance window 1, "Little Sucker Detector", @r, ¬
_kDocumentWindowClass, wa

SetRect( r, 23, 23, 457, 337 )
appearance button 1,,,,,, @r, _kControlEditUnicodeTextProc
fn InstallTextChangeHandler( button&(1) )
fn HILayoutBindAll( button&(1) )

def SetButtonFocus( 1 )
end fn


fn BuildUI

RunApplicationEventLoop()
'----------