[futurebasic] Re: [FB] SetWindowProxy

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sun, 26 Sep 2004 13:14:43 +1200
Robert Covington wrote:

> Any of you guys have a working demo for this puppy?  Is it an HIG 
> normal thing to even have this proxy thing? Or just a luxury widget?

It's expected, not a luxury.  The FB4 editor has it (but subtly wrong: 
you have to click the proxy icon whereas clicking the window title 
should also work).

You should certainly use SetWindowModified to indicate the 'dirty' 
status (unsaved changes) of the document (this is another nicety 
omitted by FB4). The demo below displays the path-selection menu 
regardless of dirtyiness. The proxy icon itself is dimmed when the doc 
is marked as dirty, which is perhaps a better cue to the user than is 
the inconspicuous black dot in the OS X red traffic light.

Robert P.

'--------------
'~'A
'                             Runtime : Rntm Appearance.Incl
'                                 CPU : Carbon
'~'B

/*
Window proxy icon and path-selection menu.
Robert P.     26 Sept 2004
*/

// from Files.h
#define FSCatalogInfoBitmap as UInt32
_kFSCatInfoNone = 0

// contents of FSCatalogInfo not used in FullNameFromFSSpec$
begin record FSCatalogInfo
end record

begin record HFSUniStr255
dim as UInt16  length
dim as UniChar unicode[254] // 255 UniCode characters
end record

toolbox fn FSGetCatalogInfo( const FSRef *ref, FSCatalogInfoBitmap 
whichInfo,¬
     FSCatalogInfo *catalogInfo, HFSUniStr255 *outName, FSSpec *fsSpec,¬
     FSRef *parentRef ) = OSErr

// from CFString.h
toolbox fn CFStringCreateWithCharacters( CFAllocatorRef alloc,¬
     const UniChar *chars, CFIndex numChars ) = CFStringRef

end globals


local mode
local fn FullNameFromFSSpec$( inFSS as ^FSSpec )
'~'1
dim as Str255        name, fullName
dim as FSRef         myFSRef
dim as HFSUniStr255  uniStr255
dim as CFStringRef   cfStr
dim as OSErr         err
dim as Boolean       ok

name[0] = 0 // null string to return if error
// FSSpec -> FSRef
err = fn FSpMakeFSRef( #inFSS, @myFSRef )
long if ( err == _noErr )
// get name as HFSUniStr255
err = fn FSGetCatalogInfo( myFSRef, _kFSCatInfoNone, #0, @uniStr255, 
#0, #0 )
long if ( err == _noErr )
// HFSUniStr255 -> CFString
cfStr = fn CFStringCreateWithCharacters( 0, uniStr255.unicode[0], 
uniStr255.length )
long if ( cfStr )
// CFString -> pascal string
ok = fn CFStringGetPascalString( cfStr, @name, sizeof( name ), 
_kCFStringEncodingMacRoman )
CFRelease( cfStr ) // dump
end if
end if
end if
end fn = name

local mode
local fn DoEvent
'~'1
dim ev as ^EventRecord
dim as WindowRef @ w
dim as SInt32    @ menuResultIgnore
dim as OSStatus    ignore
dim as SInt16      part

ev = event
long if ( ev.what == _mButDwnEvt )
part = fn FindWindow( #ev.where, @w )
long if ( part == _inProxyIcon or part == _inDrag )
long if ( fn IsWindowPathSelectClick( w, #ev ) )
ignore = fn WindowPathSelect( w, 0, @menuResultIgnore )
ev.what = 0 // null out
end if
end if
end if
end fn


// main program
on event fn DoEvent
dim as FSSpec    fs
dim as OSStatus  ignore
long if ( files$( _FSSpecOpen, "", "", fs ) != "" )
window 1, fn FullNameFromFSSpec$( fs )
ignore = fn SetWindowModified( window( _wndRef ), _false )
ignore = fn SetWindowProxyFSSpec( window( _wndRef ), fs )
print "Command-click the window title or proxy icon"
do
HandleEvents
until 0
end if
'--------------