[futurebasic] Re: [FB] fn CreateNewWindow(...) v Appearance Window- MinWindow

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2005 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sun, 24 Apr 2005 00:13:04 +1200
Bernie wrote:

> Windows created using FB's appearance window statement allow the user 
> to resize down to 64 x 64. However, windows created using fn 
> CreateNewWindow(...) can only be resized down to 128 x 128. I've 
> searched the window manager docs and the dev site but can't find a way 
> to override the this size.


There seem to be two method to constrain the resize limits of a window 
that has the standard window event handler (i.e. was created with 
_kWindowStandardHandlerAttribute).
You can either
(1) install a handler for {_kEventClassWindow, 
_kEventWindowGetMinimumSize}, {_kEventClassWindow, 
_kEventWindowGetMaximumSize} or both, and thereby override the default 
system-supplied limits during the resize,
or
(2) call SetWindowResizeLimits before the resize.


'--------------------
'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'~'B
/*
Demo of constraining the minimum size of a window by two methods.
The windows here are created with _kWindowStandardHandlerAttribute,
with the effect that resizing them does not involve the FB runtime
and generates no FB events.
Robert P.     April 2005
*/

include "Tlbx CarbonEvents.incl"

toolbox fn SetWindowResizeLimits( WindowRef inWindow, const HISize 
*inMinLimits,¬
    const HISize *inMaxLimits) = OSStatus


// Install handler for {_kEventClassWindow, _kEventWindowGetMinimumSize}
// and put size as userData for later reference
local fn InstallWindowEventHandler( w as WindowRef, size as Point )
'~'1
dim as EventTypeSpec   evnt
begin globals
dim as proc            sWindowEventHandlerUPP // 'static' var
end globals

long if ( sWindowEventHandlerUPP == _nil ) // initialize
sWindowEventHandlerUPP = fn NewEventHandlerUPP( ¬
   [proc "WindowEventHandler" + _FBprocToProcPtrOffset] )
end if
evnt.eventClass = _kEventClassWindow
evnt.eventKind  = _kEventWindowGetMinimumSize
end fn = fn InstallEventHandler( fn GetWindowEventTarget( w ),¬
          sWindowEventHandlerUPP, 1, @evnt, #size, #0 )


long if 0
"WindowEventHandler"
enterproc fn WindowEventHandler( ¬
     nextHandler as EventHandlerCallRef,¬
     theEvent as EventRef, userData as Ptr ) = OSStatus
'~'1
dim as OSStatus      result
dim as Point      @  size

size  = userData // retrieve preset min size from the event
result = fn SetEventParameter( theEvent, _kEventParamDimensions,¬
     _typeQDPoint, sizeof( Point ), @size )
exitproc = result
end if



// main program
dim as WindowAttributes  wa
dim as Point             size

wa  = _kWindowStandardDocumentAttributes
wa += _kWindowLiveResizeAttribute
wa += _kWindowStandardHandlerAttribute

// window event handler method
appearance window 1, "Min size 273x47",, _kDocumentWindowClass, wa
size.h% = 273
size.v% = 47
fn InstallWindowEventHandler( window( _wndRef ), size )

// SetWindowResizeLimits method
dim as OSStatus       ignore
dim as HISize         minLimit
minLimit.width  = 120.0
minLimit.height = 250.0
appearance window 2, "Min size 120x250",, _kDocumentWindowClass, wa
ignore = fn SetWindowResizeLimits( window( _wndRef ), @minLimit, #0 )

do
HandleEvents
until 0
'--------------------

Robert P.