TransitionWindow allows you to do some mildly interesting visual effects.
OSStatus TransitionWindow ( WindowRef inWindow, WindowTransitionEffect inEffect, WindowTransitionAction inAction, const Rect * inRect );
Of particular interest is the ability to slide a window while resizing or moving it. Let's work out the declaration, then see how to achieve the effects.
The ADC documentation or MacWindows.h tells us that WindowTransitionEffect and WindowTransitionAction are both UInt32. Thus we will declare each parameter as Integer. The possible values for WindowTransitionEffect are as follows.
kWindowZoomTransitionEffect = 1 kWindowSheetTransitionEffect = 2 kWindowSlideTransitionEffect = 3
And here are the possible values for WindowTransitionAction.
kWindowShowTransitionAction = 1 kWindowHideTransitionAction = 2 kWindowMoveTransitionAction = 3 kWindowResizeTransitionAction = 4
The last parameter, inRect, is a pointer to a Rect, so we declare its type to be Ptr. The header file MacWindows.h tells us that TransitionWindow is found in WindowsLib for Mac Classic builds. Here is the REALbasic declaration.
Declare Function TransitionWindow Lib WindowsLib (inWindow as WindowPtr, inEffect as Integer, inAction as Integer, inRect as Ptr) as Integer
The ADC documentation is a little vague as to exactly what the inRect parameter represents, but MacWindows.h is not. The descriptions of the Window Transitions constants for moving and resizing windows says that inRect represents the new structure bounds of the window in global coordinates. Conveniently, there is a function that returns these bounds, GetWindowBounds.
OSStatus GetWindowBounds ( WindowRef window, WindowRegionCode regionCode, Rect * globalBounds );
A look at MacWindows.h tells us that GetWindowBounds is in WindowsLib for Mac classic builds. WindowRegionCode is a UInt16; that is, an unsigned short. So we declare it as UShort.
Declare Function GetWindowBounds Lib WindowsLib (window as WindowPtr, regionCode as UShort, globalBounds as Ptr) as Integer
We call GetWindowBounds to get the old structure bounds, and then modify it to specify the new structure bounds. With that, here is some code for sliding and slide-resizing windows.
Sub Slide(w as Window, newLeft as Integer, newTop as Integer) #if TargetMacOS Declare Function GetWindowBounds Lib WindowsLib (window as WindowPtr, regionCode as UShort, globalBounds as Ptr) as Integer Declare Function TransitionWindow Lib WindowsLib (inWindow as WindowPtr, inEffect as Integer, inAction as Integer, inRect as Ptr) as Integer Const kWindowStructureRgn = 32 Const kWindowSlideTransitionEffect = 3 Const kWindowMoveTransitionAction = 3 Const sizeOfRect = 8 dim bounds as new MemoryBlock(sizeOfRect) dim OSError as Integer = GetWindowBounds(w, kWindowStructureRgn, bounds) If OSError <> 0 then //handle error Return End if bounds.Short(0) = bounds.Short(0) + (newTop- w.Top) bounds.Short(2) = bounds.Short(2) + (newLeft - w.Left) bounds.Short(4) = bounds.Short(4) + (newTop- w.Top) bounds.Short(6) = bounds.Short(6) + (newLeft - w.Left) OSError = TransitionWindow(w, kWindowSlideTransitionEffect, kWindowMoveTransitionAction, bounds) If OSError <> 0 then //handle error End if #endif End Sub
Sub SlideResize(w as Window, newWidth as Integer, newHeight as Integer) #if TargetMacOS Declare Function GetWindowBounds Lib WindowsLib (window as WindowPtr, regionCode as UShort, globalBounds as Ptr) as Integer Declare Function TransitionWindow Lib WindowsLib (inWindow as WindowPtr, inEffect as Integer, inAction as Integer, inRect as Ptr) as Integer Const kWindowStructureRgn = 32 Const kWindowSlideTransitionEffect = 3 Const kWindowResizeTransitionAction = 4 Const sizeOfRect = 8 dim bounds as new MemoryBlock(sizeOfRect) dim OSError as Integer = GetWindowBounds(w, kWindowStructureRgn, bounds) If OSError <> 0 then //handle error Return End if bounds.Short(4) = bounds.Short(4) + (newHeight - w.Height) bounds.Short(6) = bounds.Short(6) + (newWidth - w.Width) OSError = TransitionWindow(w, kWindowSlideTransitionEffect, kWindowResizeTransitionAction, bounds) If OSError <> 0 then //handle error End if #endif End Sub