home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / WASTE 1.3a5 / Demo / Source / WEDemoAbout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-11  |  4.9 KB  |  203 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     About Box
  4.  
  5.     Copyright © 1993-1997 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. #ifndef __WEDEMOAPP__
  12. #include "WEDemoIntf.h"
  13. #endif
  14.  
  15. #ifndef __ICONS__
  16. #include <Icons.h>
  17. #endif
  18.  
  19. enum
  20. {
  21.     kItemScrollPane = 1 ,
  22.     kItemWholePane = 2 ,
  23.     kItemIcon = 3
  24. } ;
  25. enum { kScrollStep = 1 } ;
  26. enum { kScrollDelay = 2 } ;
  27.  
  28. static pascal void DrawBox ( DialogRef inDialog, SInt16 inItem )
  29. {
  30.     Rect textRect ;
  31.     SInt16 screenDepth = 1 ;
  32.     WEReference we = ( WEReference ) GetWRefCon ( GetDialogWindow ( inDialog ) ) ;
  33.  
  34.     //    get text pane rect
  35.     GetDialogItemRect ( inDialog, inItem, & textRect ) ;
  36.     
  37.     //    determine screen depth
  38.     if ( gHasColorQD )
  39.     {
  40.         Rect globalRect = textRect ;
  41.         LocalToGlobal ( ( Point * ) & globalRect ) ;
  42.         LocalToGlobal ( ( Point * ) & globalRect + 1 ) ;
  43.         screenDepth = ( * ( * GetMaxDevice ( & globalRect ) ) -> gdPMap ) -> pixelSize ;
  44.     }
  45.  
  46.     //    draw a border around the scrolling pane (only if enough colors are available)
  47.     if ( screenDepth >= 8 )
  48.     {
  49.         RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF } ;
  50.         RGBColor gray = { 0xAAAA, 0xAAAA, 0xAAAA } ;
  51.         RGBColor saveColor ;
  52.         GetForeColor ( & saveColor ) ;
  53.         InsetRect ( & textRect, -3, -3 ) ;
  54.         MoveTo ( textRect . right, textRect . top ) ;
  55.  
  56.         RGBForeColor ( & white ) ;
  57.         Line ( 0, textRect . bottom - textRect . top ) ;
  58.         Line ( textRect . left - textRect . right, 0 ) ;
  59.  
  60.         RGBForeColor ( & gray ) ;
  61.         Line ( 0, textRect . top - textRect . bottom ) ;
  62.         Line ( textRect . right - textRect . left, 0 ) ;
  63.  
  64.         InsetRect ( & textRect, 1, 1 ) ;
  65.         
  66.         MoveTo ( textRect . right, textRect . top ) ;
  67.         RGBForeColor ( & gray ) ;
  68.         Line ( 0, textRect . bottom - textRect . top ) ;
  69.         Line ( textRect . left - textRect . right, 0 ) ;
  70.         RGBForeColor ( & white ) ;
  71.         Line ( 0, textRect . top - textRect . bottom ) ;
  72.         Line ( textRect . right - textRect . left, 0 ) ;
  73.         
  74.         RGBForeColor ( & saveColor ) ;
  75.     }
  76.     
  77.     //    redraw the text
  78.     WEUpdate ( GetWindowPort ( GetDialogWindow ( inDialog ) ) -> visRgn, we ) ;
  79. }
  80.  
  81. static pascal void DrawBigIcon ( DialogRef inDialog, SInt16 inItem )
  82. {
  83.     Rect iconRect ;    
  84.     GetDialogItemRect ( inDialog, inItem, & iconRect ) ;
  85.     PlotIconID ( & iconRect, kAlignAbsoluteCenter, kTransformNone, 130 ) ;
  86. }
  87.  
  88. void DoAboutBox ( SInt16 dialogID )
  89. {
  90.     DialogRef aboutBox = nil ;
  91.     WEReference we = nil ;
  92.     SInt16 itemHit = 0 ;
  93.     Handle hText, hStyles ;
  94.     GrafPtr savePort ;
  95.     LongRect viewRect, destRect ;
  96.     SInt32 scrollRange, i ;
  97.     UInt32 ticks ;
  98.     Rect r ;
  99. #ifdef __cplusplus
  100.     static UserItemUPP sBoxDrawer = NewUserItemProc ( DrawBox ) ;
  101.     static UserItemUPP sIconDrawer = NewUserItemProc ( DrawBigIcon ) ;
  102. #else
  103.     static UserItemUPP sBoxDrawer = nil ;
  104.     static UserItemUPP sIconDrawer = nil ;
  105.     if ( sBoxDrawer == nil )
  106.     {
  107.         sBoxDrawer = NewUserItemProc ( DrawBox ) ;
  108.         sIconDrawer = NewUserItemProc ( DrawBigIcon ) ;
  109.     }
  110. #endif
  111.  
  112.     //    load the dialog
  113.     aboutBox = GetNewDialog ( dialogID, nil, ( WindowRef ) -1L ) ;
  114.     if ( aboutBox == nil )
  115.     {
  116.         goto cleanup ;
  117.     }
  118.  
  119.     //    set up the port
  120.     GetPort ( & savePort ) ;
  121.     SetGrafPortOfDialog ( aboutBox ) ;
  122.  
  123.     //    get the scrolling pane rect
  124.     GetDialogItemRect ( aboutBox, kItemScrollPane, & r ) ;
  125.     
  126.     //    create a WASTE instance for scrolling the text
  127.     WERectToLongRect ( & r, & viewRect ) ;
  128.     if ( WENew ( & viewRect, & viewRect, 0, & we ) != noErr )
  129.     {
  130.         goto cleanup ;
  131.     }
  132.     
  133.     //    save reference to the WASTE instance in dialog ref con
  134.     SetWRefCon ( GetDialogWindow ( aboutBox ), ( SInt32 ) we ) ;
  135.     
  136.     //    set the alignment style to center
  137.     WESetAlignment ( weCenter, we ) ;
  138.     
  139.     //    load the styled text and insert it into the WASTE instance
  140.     hText = GetResource ( kTypeText, dialogID ) ;
  141.     if ( hText == nil )
  142.     {
  143.         goto cleanup ;
  144.     }
  145.     hStyles = GetResource ( kTypeStyles, dialogID ) ;
  146.  
  147.     //    insert the styled text
  148.     HLock ( hText ) ;
  149.     WEInsert ( * hText, GetHandleSize ( hText ), ( StScrpHandle ) hStyles, nil, we ) ;
  150.     HUnlock ( hText ) ;
  151.  
  152.     //    make the instance read-only
  153.     WEFeatureFlag ( weFReadOnly, weBitSet, we ) ;
  154.     
  155.     //    calculate scroll range
  156.     WEGetDestRect ( & destRect, we ) ;
  157.     scrollRange = ( destRect . bottom - destRect . top ) - ( viewRect . bottom - viewRect . top ) ;
  158.     
  159.     //    install drawing callbacks
  160.     SetDialogItemProc ( aboutBox, kItemScrollPane, sBoxDrawer ) ;
  161.     SetDialogItemProc ( aboutBox, kItemIcon, sIconDrawer ) ;
  162.  
  163.     //    show the dialog
  164.     ShowWindow ( GetDialogWindow ( aboutBox ) ) ;
  165.     
  166.     //    wait for a click in the picture
  167.     ModalDialog ( GetMyStandardDialogFilter ( ), & itemHit ) ;
  168.     
  169.     if ( itemHit == kItemScrollPane )
  170.     {
  171.         //    start scrolling sequence
  172.         for ( i = 0 ; i < scrollRange ; i += kScrollStep )
  173.         {
  174.             //    scroll the text downward
  175.             WEScroll ( 0, - kScrollStep, we ) ;
  176.             
  177.             //    wait some ticks
  178.             ticks = TickCount ( ) + kScrollDelay ;
  179.             do
  180.             {
  181.                 EventRecord event ;
  182.  
  183.                 if ( WaitNextEvent ( mDownMask + keyDownMask, & event, 0, nil ) )
  184.                 {
  185.                     i = scrollRange ;
  186.                     break ;
  187.                 }
  188.             } while ( TickCount ( ) < ticks ) ;
  189.         }
  190.     }
  191.  
  192. cleanup :
  193.     if ( we != nil )
  194.     {
  195.         WEDispose ( we ) ;
  196.     }
  197.     if ( aboutBox != nil )
  198.     {
  199.         DisposeDialog ( aboutBox ) ;
  200.         SetPort ( savePort ) ;
  201.     }
  202. }
  203.