home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- About Box
-
- Copyright © 1993-1997 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
- #ifndef __WEDEMOAPP__
- #include "WEDemoIntf.h"
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- enum
- {
- kItemScrollPane = 1 ,
- kItemWholePane = 2 ,
- kItemIcon = 3
- } ;
- enum { kScrollStep = 1 } ;
- enum { kScrollDelay = 2 } ;
-
- static pascal void DrawBox ( DialogRef inDialog, SInt16 inItem )
- {
- Rect textRect ;
- SInt16 screenDepth = 1 ;
- WEReference we = ( WEReference ) GetWRefCon ( GetDialogWindow ( inDialog ) ) ;
-
- // get text pane rect
- GetDialogItemRect ( inDialog, inItem, & textRect ) ;
-
- // determine screen depth
- if ( gHasColorQD )
- {
- Rect globalRect = textRect ;
- LocalToGlobal ( ( Point * ) & globalRect ) ;
- LocalToGlobal ( ( Point * ) & globalRect + 1 ) ;
- screenDepth = ( * ( * GetMaxDevice ( & globalRect ) ) -> gdPMap ) -> pixelSize ;
- }
-
- // draw a border around the scrolling pane (only if enough colors are available)
- if ( screenDepth >= 8 )
- {
- RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF } ;
- RGBColor gray = { 0xAAAA, 0xAAAA, 0xAAAA } ;
- RGBColor saveColor ;
- GetForeColor ( & saveColor ) ;
- InsetRect ( & textRect, -3, -3 ) ;
- MoveTo ( textRect . right, textRect . top ) ;
-
- RGBForeColor ( & white ) ;
- Line ( 0, textRect . bottom - textRect . top ) ;
- Line ( textRect . left - textRect . right, 0 ) ;
-
- RGBForeColor ( & gray ) ;
- Line ( 0, textRect . top - textRect . bottom ) ;
- Line ( textRect . right - textRect . left, 0 ) ;
-
- InsetRect ( & textRect, 1, 1 ) ;
-
- MoveTo ( textRect . right, textRect . top ) ;
- RGBForeColor ( & gray ) ;
- Line ( 0, textRect . bottom - textRect . top ) ;
- Line ( textRect . left - textRect . right, 0 ) ;
- RGBForeColor ( & white ) ;
- Line ( 0, textRect . top - textRect . bottom ) ;
- Line ( textRect . right - textRect . left, 0 ) ;
-
- RGBForeColor ( & saveColor ) ;
- }
-
- // redraw the text
- WEUpdate ( GetWindowPort ( GetDialogWindow ( inDialog ) ) -> visRgn, we ) ;
- }
-
- static pascal void DrawBigIcon ( DialogRef inDialog, SInt16 inItem )
- {
- Rect iconRect ;
- GetDialogItemRect ( inDialog, inItem, & iconRect ) ;
- PlotIconID ( & iconRect, kAlignAbsoluteCenter, kTransformNone, 130 ) ;
- }
-
- void DoAboutBox ( SInt16 dialogID )
- {
- DialogRef aboutBox = nil ;
- WEReference we = nil ;
- SInt16 itemHit = 0 ;
- Handle hText, hStyles ;
- GrafPtr savePort ;
- LongRect viewRect, destRect ;
- SInt32 scrollRange, i ;
- UInt32 ticks ;
- Rect r ;
- #ifdef __cplusplus
- static UserItemUPP sBoxDrawer = NewUserItemProc ( DrawBox ) ;
- static UserItemUPP sIconDrawer = NewUserItemProc ( DrawBigIcon ) ;
- #else
- static UserItemUPP sBoxDrawer = nil ;
- static UserItemUPP sIconDrawer = nil ;
- if ( sBoxDrawer == nil )
- {
- sBoxDrawer = NewUserItemProc ( DrawBox ) ;
- sIconDrawer = NewUserItemProc ( DrawBigIcon ) ;
- }
- #endif
-
- // load the dialog
- aboutBox = GetNewDialog ( dialogID, nil, ( WindowRef ) -1L ) ;
- if ( aboutBox == nil )
- {
- goto cleanup ;
- }
-
- // set up the port
- GetPort ( & savePort ) ;
- SetGrafPortOfDialog ( aboutBox ) ;
-
- // get the scrolling pane rect
- GetDialogItemRect ( aboutBox, kItemScrollPane, & r ) ;
-
- // create a WASTE instance for scrolling the text
- WERectToLongRect ( & r, & viewRect ) ;
- if ( WENew ( & viewRect, & viewRect, 0, & we ) != noErr )
- {
- goto cleanup ;
- }
-
- // save reference to the WASTE instance in dialog ref con
- SetWRefCon ( GetDialogWindow ( aboutBox ), ( SInt32 ) we ) ;
-
- // set the alignment style to center
- WESetAlignment ( weCenter, we ) ;
-
- // load the styled text and insert it into the WASTE instance
- hText = GetResource ( kTypeText, dialogID ) ;
- if ( hText == nil )
- {
- goto cleanup ;
- }
- hStyles = GetResource ( kTypeStyles, dialogID ) ;
-
- // insert the styled text
- HLock ( hText ) ;
- WEInsert ( * hText, GetHandleSize ( hText ), ( StScrpHandle ) hStyles, nil, we ) ;
- HUnlock ( hText ) ;
-
- // make the instance read-only
- WEFeatureFlag ( weFReadOnly, weBitSet, we ) ;
-
- // calculate scroll range
- WEGetDestRect ( & destRect, we ) ;
- scrollRange = ( destRect . bottom - destRect . top ) - ( viewRect . bottom - viewRect . top ) ;
-
- // install drawing callbacks
- SetDialogItemProc ( aboutBox, kItemScrollPane, sBoxDrawer ) ;
- SetDialogItemProc ( aboutBox, kItemIcon, sIconDrawer ) ;
-
- // show the dialog
- ShowWindow ( GetDialogWindow ( aboutBox ) ) ;
-
- // wait for a click in the picture
- ModalDialog ( GetMyStandardDialogFilter ( ), & itemHit ) ;
-
- if ( itemHit == kItemScrollPane )
- {
- // start scrolling sequence
- for ( i = 0 ; i < scrollRange ; i += kScrollStep )
- {
- // scroll the text downward
- WEScroll ( 0, - kScrollStep, we ) ;
-
- // wait some ticks
- ticks = TickCount ( ) + kScrollDelay ;
- do
- {
- EventRecord event ;
-
- if ( WaitNextEvent ( mDownMask + keyDownMask, & event, 0, nil ) )
- {
- i = scrollRange ;
- break ;
- }
- } while ( TickCount ( ) < ticks ) ;
- }
- }
-
- cleanup :
- if ( we != nil )
- {
- WEDispose ( we ) ;
- }
- if ( aboutBox != nil )
- {
- DisposeDialog ( aboutBox ) ;
- SetPort ( savePort ) ;
- }
- }
-