home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / ColorSync / Sample Code / CSDemo 2.1 / CSDemoSources / winPictDoc.c < prev    next >
Encoding:
Text File  |  1996-07-24  |  70.9 KB  |  2,373 lines  |  [TEXT/CWIE]

  1. // A pict file window
  2. //
  3. // David Hayward and Nick Thompson 
  4. // Developer Technical Support
  5. // AppleLink: DEVSUPPORT
  6. //
  7. // Copyrite 1995, Apple Computer,Inc
  8. //
  9. // This file contains the handlers procs for a pict file window.
  10. // 
  11. // 9/13/94    nick    first cut
  12. // 12/13/94    david    several modifications
  13.  
  14.  
  15. #include <PictUtils.h>
  16. #include <TextUtils.h>
  17. #include <Types.h>
  18. #include <Fonts.h>
  19. #include <Files.h>
  20. #include <QDOffScreen.h>
  21. #include <Resources.h>
  22. #include <StandardFile.h>
  23. #include <Scrap.h>
  24. #include <Drag.h>
  25. #include <GXTypes.h>
  26.  
  27. #include "appGlobals.h"
  28. #include "appMain.h"
  29. #include "appMenus.h"
  30. #include "appErrors.h"
  31. #include "appPrint.h"
  32. #include "appAEvts.h"
  33.  
  34. #include "win.h"
  35. #include "winTables.h"
  36. #include "winPictDoc.h"
  37. #include "winPictDocGetSet.h"
  38. #include "winProfile.h"
  39. #include "winProfileGetSet.h"
  40. #include "winProfID.h"
  41. #include "winProfIDGetSet.h"
  42. #include "winProfList.h"
  43. #include "winProfListGetSet.h"
  44.  
  45. #include "dragUtils.h"
  46. #include "stringUtils.h"
  47. #include "pictUtils.h"
  48. #include "resourceUtils.h"
  49. #include "cursorUtils.h"
  50. #include "colorsyncUtils.h"
  51. #include "faux3DUtils.h"
  52. #include "listsUtils.h"
  53.  
  54.  
  55.  
  56. /**\
  57. |**| ==============================================================================
  58. |**| PRIVATE DEFINES
  59. |**| ==============================================================================
  60. \**/
  61. #define rPictDocWindID            3000                // 'WIND' resource id
  62. #define rPictSrceProfRectID        3001
  63. #define rPictDestProfRectID        3002
  64. #define rPictPrevProfRectID        3003
  65. #define rPictEmbdProfRectID        3004
  66. #define kScrollDelta            16
  67. #define kWindowWidthMin            500
  68. #define kWindowHeightMin        200
  69. #define kHeaderHeightBig        120
  70. #define kHeaderHeightSmall        30
  71. #define kStatusWidth            100
  72. #define kCellHeight                16
  73. #define kMargin                    16
  74. #define kCSyncACursor            150
  75.  
  76.  
  77. /**\
  78. |**| ==============================================================================
  79. |**| PRIVATE GLOBALS
  80. |**| ==============================================================================
  81. \**/
  82. static    RGBColor        white  = {0xFFFF, 0xFFFF, 0xFFFF};
  83. static    RGBColor        ltGray = {0xDDDD, 0xDDDD, 0xDDDD};
  84. static    RGBColor        mdGray = {0x7FFF, 0x7FFF, 0x7FFF};
  85. static    RGBColor        dkGray = {0x3FFF, 0x3FFF, 0x3FFF};
  86. static    Boolean         acceptableDragFlag;
  87. static    Boolean         windowIsHilightedFlag;
  88.  
  89.  
  90. /**\
  91. |**| ==============================================================================
  92. |**| PRIVATE FUNCTION PROTOTYPES
  93. |**| ==============================================================================
  94. \**/
  95. void        DoDrawPictData        ( winHandle win, GrafPtr destPort, Rect *srcRect, Rect *dstRect ) ;
  96. OSErr        DoCreatePalettes    ( winHandle win ) ;
  97. ListHandle    BuildProfList        ( winHandle win ) ;
  98. OSErr        DoCreatePictWindow    ( winHandle win ) ;
  99. OSErr        DoCreateDragZones    ( winHandle win ) ;
  100. pascal void    PictDocActionProc    ( ControlHandle cntl, short part) ;
  101. void        UpdatePane            ( winHandle win, Rect updateRect ) ;
  102. void        ScrollPane            ( winHandle win, ControlHandle cntl, short oldCntlVal ) ;
  103. void        UpdatePict            ( winHandle win, short which ) ;
  104. void        ChangeCSOnOff        ( winHandle win ) ;
  105. void        ChangeCSMode        ( winHandle win ) ;
  106. Boolean        SetWinContentColor    ( WindowRef window, RGBColor theColor ) ;
  107. OSErr        GetProfileFromFront ( CMProfileRef *prof ) ;
  108. OSErr        GetProfIDFromFront    ( CMProfileIdentifierHdl *IDHdl ) ;
  109. void        DoChangeProfile        ( winHandle win, short which, CMProfileRef prof ) ;
  110. void        DoChangeProfileFromFront ( winHandle win, short which ) ;
  111. OSErr        DoAddEmbdProf        ( winHandle win, CMProfileRef prof, unsigned long flags ) ;
  112. OSErr        DoAddEmbdProfID        ( winHandle win, CMProfileIdentifierHdl IDHdl ) ;
  113. void        DoAddEmbdProfFromFront ( winHandle win, unsigned long flags ) ;
  114. void        SaveCmndPictDoc        ( winHandle win ) ;
  115. void        SaveAsCmndPictDoc    ( winHandle win ) ;
  116. void        RevertCmndPictDoc    ( winHandle win ) ;
  117. void        PasteCmndPictDoc    ( winHandle win ) ;
  118. void        DoChangePict        ( winHandle win, PicHandle pict ) ;
  119.  
  120. short            DoDragPict                ( winHandle win, EventRecord *e, Rect hiliteRect ) ;
  121. pascal OSErr    MyDragSendDataProc        ( FlavorType theDragFlavor, void *refCon, ItemReference theItem, DragReference theDrag ) ;
  122. pascal OSErr    MyDragZoneRecvCallback    ( DragZoneHdl theZone, WindowRef theWindow, Point theLocation, Handle dataHdl ) ;
  123. pascal OSErr    MyProfDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow, Point theLocation, Handle dataHdl ) ;
  124.  
  125.  
  126.  
  127. /**\
  128. |**| ==============================================================================
  129. |**| PUBLIC FUNCTIONS
  130. |**| ==============================================================================
  131. \**/
  132.  
  133.  
  134. /*------------------------------------------------------------------------------*\
  135.     winActivatePictDoc
  136.  *------------------------------------------------------------------------------*
  137.         This is a ActivateProcPtr for PictDoc windows.
  138.         Things, such as activating/deactivation controls should go here
  139.         This ProcPtr is envoked by CallWinActivateProc() which is called by:
  140.             DoActivateEvent() which dispaches activate events and
  141.             DoOSEvent() which handles events such as Suspend/Resume.
  142. \*------------------------------------------------------------------------------*/
  143. void winActivatePictDoc ( winHandle win, Boolean activating ) 
  144. {
  145.     Rect        growRect ;
  146.     
  147.     if (activating)
  148.     {
  149.         ShowControl( GetPictDocCntl(win,rPictDocHorzScrollID) ) ;
  150.         ShowControl( GetPictDocCntl(win,rPictDocVertScrollID) ) ;
  151.     }
  152.     else
  153.     {
  154.         HideControl( GetPictDocCntl(win,rPictDocHorzScrollID) ) ;
  155.         HideControl( GetPictDocCntl(win,rPictDocVertScrollID) ) ;
  156.     }
  157.     growRect = GetWinRect( win ) ;                    // check if ok?
  158.     growRect.top = growRect.bottom - kScrollDelta ;
  159.     growRect.left = growRect.right - kScrollDelta ;
  160.     InvalRect( &growRect ) ;
  161. }
  162.  
  163.  
  164. /*------------------------------------------------------------------------------*\
  165.     winUpdatePictDoc
  166.  *------------------------------------------------------------------------------*
  167.         This is a UpdateProcPtr for PictDoc windows.  
  168.         It handles all drawing into the window.
  169.         For PictDoc windows, this means that this routine is responible for
  170.         drawing the scroll bars, grow box, the header area, and the Pict itself.
  171.         The Pict is drawn in the space provided by the current window size and
  172.         in accordance with the scroll bar values.  It is drawn by calling 
  173.         DoDrawPictData() which is also used by the PagePrintProc.
  174.         This ProcPtr is envoked by CallWinUpdateProc() which is called by:
  175.             DoUpdateEvent() which dispaches update events.
  176. \*------------------------------------------------------------------------------*/
  177. void winUpdatePictDoc ( winHandle win, EventRecord *e )
  178. {
  179.     Rect            docRect ;
  180.     Rect            pictRect ;
  181.     Rect            headRect, headUpdateRect ;
  182.     Rect            growRect, growUpdateRect ;
  183.     Rect            statRect, statUpdateRect ;
  184.     WindowRef        window = (WindowRef)e->message;
  185.     Rect             updateRect = ((**(((CGrafPtr)window)->visRgn)).rgnBBox) ;
  186.     GrafPtr            savedPort ;
  187.     
  188.     GetPort( &savedPort ) ;    
  189.     SetPort( (GrafPtr)window ) ;
  190.  
  191.     BeginUpdate( window ) ;
  192.  
  193.  
  194.     docRect  = GetWinRect( win ) ;                    // check if ok?
  195.     pictRect = GetPictDocPictRect( win ) ;            // check if ok?
  196.     
  197. // draw header    
  198.     headRect = docRect ;
  199.     headRect.bottom = kHeaderHeightBig;
  200.     headRect.bottom -= 3;
  201.     if (SectRect(&headRect,&updateRect,&headUpdateRect))
  202.     {
  203.         faux3DFillRect ( &headRect ) ;
  204.         ForeColor(whiteColor) ;
  205.         MoveTo (headRect.left, headRect.bottom+1) ; LineTo (headRect.right, headRect.bottom+1) ;
  206.         ForeColor(blackColor) ;
  207.         MoveTo (headRect.left, headRect.bottom  ) ; LineTo (headRect.right, headRect.bottom  ) ;
  208.         MoveTo (headRect.left, headRect.bottom+2) ; LineTo (headRect.right, headRect.bottom+2) ;
  209.         {
  210.             Rect        embdRect,    srceRect,    destRect,    prevRect ;
  211.             Str255        embdProfStr, srceProfStr, destProfStr, prevProfStr ;
  212.             CMError        cmerr ;
  213.             ListHandle    list ;
  214.  
  215.             // get rects from resources
  216.             srceRect = GetRect( rPictSrceProfRectID ) ;
  217.             destRect = GetRect( rPictDestProfRectID ) ;
  218.             prevRect = GetRect( rPictPrevProfRectID ) ;
  219.             embdRect = GetRect( rPictEmbdProfRectID ) ;
  220.             
  221.             TextSize(9) ;
  222.             TextFace(bold) ;
  223.             TextFont(geneva) ;
  224.             ForeColor(blackColor) ;
  225.             
  226.             GetStringPtr ( rPictSrceProfRectID, srceProfStr ) ;
  227.             GetStringPtr ( rPictDestProfRectID, destProfStr ) ;
  228.             GetStringPtr ( rPictPrevProfRectID, prevProfStr ) ;
  229.             GetStringPtr ( rPictEmbdProfRectID, embdProfStr ) ;
  230.             
  231.             MoveTo( srceRect.left +4, srceRect.top -4) ; DrawString( srceProfStr ) ;
  232.             MoveTo( destRect.left +4, destRect.top -4) ; DrawString( destProfStr ) ;
  233.             MoveTo( prevRect.left +4, prevRect.top -4) ; DrawString( prevProfStr ) ;
  234.             MoveTo( embdRect.left +4, embdRect.top -4) ; DrawString( embdProfStr ) ;
  235.  
  236.             faux3DFillRectIn( &srceRect ) ;
  237.             faux3DFillRectIn( &destRect ) ;
  238.             faux3DFillRectIn( &prevRect ) ;
  239.             faux3DFillRectIn( &embdRect ) ;
  240.             
  241.             TextSize(9) ;
  242.             TextFace(0) ;
  243.             TextFont(geneva) ;
  244.             ForeColor(blackColor) ;
  245.  
  246.             cmerr = GetProfName ( GetPictDocProfile( win, kSrceProf ), srceProfStr ) ;
  247.             cmerr = GetProfName ( GetPictDocProfile( win, kDestProf ), destProfStr ) ;
  248.             cmerr = GetProfName ( GetPictDocProfile( win, kPrevProf ), prevProfStr ) ;
  249.             
  250.             list = GetPictDocProfList( win ) ;
  251.             if (list != nil )
  252.             {
  253.                 LSetDrawingMode( true, list ) ;
  254.                 LUpdate( ((CGrafPtr)window)->visRgn, list) ;        // not sure this is the rgn
  255.             }
  256.             
  257.             TruncString( srceRect.right - srceRect.left - 6 , srceProfStr, smTruncEnd ) ;
  258.             TruncString( destRect.right - destRect.left - 6 , destProfStr, smTruncEnd ) ;
  259.             TruncString( prevRect.right - prevRect.left - 6 , prevProfStr, smTruncEnd ) ;
  260.             
  261.             MoveTo (srceRect.left +6, srceRect.top + 14) ; DrawString( srceProfStr ) ;
  262.             MoveTo (destRect.left +6, destRect.top + 14) ; DrawString( destProfStr ) ;
  263.             MoveTo (prevRect.left +6, prevRect.top + 14) ; DrawString( prevProfStr ) ;
  264.         }
  265.     }
  266.  
  267. // update controls
  268.     TextSize(9) ;
  269.     TextFace(bold) ;
  270.     TextFont(geneva) ;
  271.     SetWinContentColor ( window, ltGray ) ;
  272.     DrawControls( window ) ;
  273.     SetWinContentColor ( window, white ) ;        // should restore previous
  274.     {
  275.     short            val;
  276.     val = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
  277.     SetPictDocCntlValue( win, rPictDocMatchOnOffID, !val ) ;
  278.     SetPictDocCntlValue( win, rPictDocMatchOnOffID,  val ) ;
  279.     }
  280.     
  281. // draw GrowIcon
  282.     growRect = docRect ;
  283.     growRect.top += kHeaderHeightBig ;
  284.     if (SectRect(&growRect,&updateRect,&growUpdateRect))
  285.     {
  286.         RgnHandle saveRgn = NewRgn() ;
  287.         GetClip( saveRgn ) ;
  288.         ClipRect( &growRect ) ;
  289.         DrawGrowIcon( window ) ;
  290.         SetClip( saveRgn ) ;
  291.         DisposeRgn( saveRgn ) ;
  292.     }
  293.     
  294. // startdraw status box    
  295.     statRect = docRect ;
  296.     statRect.top = statRect.bottom +1 - kScrollWidth ;
  297.     statRect.right = kStatusWidth - 1 ;
  298.     if (SectRect(&statRect,&updateRect,&statUpdateRect))
  299.     {
  300.         faux3DFillRect ( &statRect ) ;
  301.         InsetRect( &statRect, -1, -1 ) ;
  302.         ForeColor(blackColor) ;
  303.         FrameRect( &statRect ) ;
  304.     }
  305.  
  306. // draw scrolling pane
  307.     UpdatePane( win, updateRect ) ;
  308.     
  309. // finish drawing status box
  310.     if (SectRect(&statRect,&updateRect,&statUpdateRect))
  311.     {
  312.         Str255        string ;
  313.         Fixed        fix ;
  314.         short        mode, cson ;
  315.         
  316.         ForeColor(blackColor) ;
  317.         TextSize(9) ;
  318.         TextFace(0) ;
  319.         TextFont(geneva) ;
  320.         
  321.         cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
  322.         mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
  323.         if (!cson) mode = kOriginal ;
  324.         
  325.         if ( mode != kDrwMchdPct )
  326.         {
  327.             long        bytes ;
  328.             bytes = GetHandleSize( (Handle)GetPictDocPict(win,mode) ) ;
  329.             fix = (Fixed)(bytes<<6) ;
  330.             FormatFixed( fix, rKBytesFMAT, string) ;
  331.             MoveTo( statRect.left+10, statRect.bottom-4 ) ;
  332.             DrawString( string ) ;
  333.         }
  334.         
  335.         if ( mode != kOriginal )
  336.         {
  337.             long        ticks ;
  338.             ticks = GetPictDocDrawTime(win,mode) ;
  339.             fix = FixRatio( (short)ticks, 60 ) ;
  340.             FormatFixed( fix, rSecsFMAT, string) ;
  341.             MoveTo( statRect.left+50, statRect.bottom-4 ) ;
  342.             DrawString( string ) ;
  343.         }
  344.     }
  345.  
  346. // signal that we finished drawing
  347.     EndUpdate( window ) ;
  348.     SetPort( savedPort ) ;
  349. }
  350.  
  351.  
  352. /*------------------------------------------------------------------------------*\
  353.     winClickPictDoc
  354.  *------------------------------------------------------------------------------*
  355.         This is a ClickProcPtr for PictDoc windows.
  356.         So far, all this contains is a crude handling of the scroll controls
  357.         Other things, such as initiating a drag-and-drop should also go here
  358.         This ProcPtr is envoked by CallWinClickProc() which is called by:
  359.             DoMouseDownEvent() which dispaches mouse down events 
  360. \*------------------------------------------------------------------------------*/
  361. void winClickPictDoc ( winHandle win, EventRecord *e ) 
  362. {
  363.     Point                pt = e->where;
  364.     ControlHandle        hCtl, vCtl, csonCtl, modeCtl ;
  365.     WindowRef            window ;
  366.     Boolean                dblClk = false ;
  367.     Point                cell = {0,0} ;
  368.     ListHandle            list ;
  369.     unsigned long        index ;
  370.     ControlHandle        cntl ;
  371.     short                oldCntlVal ;
  372.     short                cntlPart ;
  373.     ControlActionUPP    caUPP ;
  374.     Boolean                notAtEnd = true ;
  375.     
  376.     window = GetWinWindow( win ) ;
  377.     SetPort ( (GrafPtr)window ) ;
  378.     GlobalToLocal( &pt ) ;
  379.  
  380.     hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
  381.     vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
  382.     csonCtl = GetPictDocCntl( win, rPictDocMatchOnOffID ) ;
  383.     modeCtl = GetPictDocCntl( win, rPictDocMatchPopupID ) ;
  384.     
  385.     list = GetPictDocProfList( win ) ;
  386.     if ( list )
  387.         dblClk = LClick( pt, e->modifiers, list ) ;
  388.     
  389.     if ( dblClk )
  390.     {
  391.         while ( notAtEnd && LGetSelect(true, &cell, list))
  392.         {
  393.             OSErr            err = noErr ;
  394.             CMError            cmerr = noErr ;
  395.             CMProfileRef    prof ;
  396.             CMProfileRef    profCopy ;
  397.             winHandle        profWin ;
  398.             FSSpec            spec ;
  399.             
  400.             index = cell.v +1 ;
  401.  
  402.             cmerr = GetIndexedProfileFromPicHandle( GetPictDocPict(win,kOriginal), index, &prof, nil ) ;
  403.             cmerr = ReOpenProfileRef ( &profCopy, prof ) ;
  404.             CMCloseProfile( prof ) ;
  405.  
  406.             // create a new winHandle of the proper type
  407.             if ( IsPseudoProfile(prof) )
  408.             {
  409.                 CMProfileIdentifierHdl profID;
  410.                 err = NewWinHandle( &profWin, winAllocProfID ) ;
  411.                 WarnIfErr( err ) ;
  412.                 if (err) return ;
  413.                 
  414.                 err = GetPseudoProfileIDHdl( prof, &profID ) ;
  415.                 SetProfIDIDHdl( profWin, profID ) ;
  416.                 SetProfIDIndex( profWin, index ) ;
  417.             }
  418.             else
  419.             {
  420.                 err = NewWinHandle( &profWin, winAllocProfile ) ;
  421.                 WarnIfErr( err ) ;
  422.                 if (err) return ;
  423.                 
  424.                 SetProfileRef( profWin, profCopy ) ;
  425.                 SetProfileIndex( profWin, index ) ;
  426.             }
  427.             spec = GetWinFSSpec(win) ;
  428.             SetWinFSSpec( profWin, &spec ) ;
  429.             SetWinSubtype( profWin, kEmbededSubType ) ;
  430.             err = CallWinOpenProc ( profWin ) ;
  431.         
  432.             if ( err != noErr )            // if an error occured
  433.                 DisposeWinHandle( profWin ) ;
  434.             if ( err == kWasAlreadyOpen )
  435.                 err = noErr;
  436.                 
  437.             notAtEnd = LNextCell( false, true, &cell, list ) ;
  438.         }
  439.     }
  440.  
  441.     cntlPart = FindControl(pt, window, &cntl) ;
  442.     
  443.     if ( cntl==hCtl    || cntl==vCtl )
  444.     {
  445.         switch (cntlPart)
  446.         {
  447.             case kControlUpButtonPart :
  448.             case kControlDownButtonPart :
  449.             case kControlPageUpPart :
  450.             case kControlPageDownPart :
  451.                     caUPP = NewControlActionProc(PictDocActionProc) ;
  452.                     cntlPart = TrackControl( cntl, pt, (ControlActionUPP)caUPP ) ;
  453.                     DisposeRoutineDescriptor( caUPP ) ;
  454.                     break;
  455.             case kControlIndicatorPart :
  456.                     oldCntlVal = GetControlValue( cntl ) ;
  457.                     cntlPart = TrackControl( cntl, pt ,nil) ;
  458.                     if ( cntlPart != 0 )
  459.                         ScrollPane( win, cntl, oldCntlVal ) ;
  460.                     break;
  461.         }
  462.     }
  463.     if ( cntl==csonCtl )
  464.     {
  465.         TextSize(9) ;
  466.         TextFace(bold) ;
  467.         TextFont(geneva) ;
  468.         cntlPart = TrackControl( cntl, pt ,nil) ;
  469.         if ( cntlPart != 0 )
  470.             ChangeCSOnOff( win ) ;
  471.     }
  472.     if ( cntl==modeCtl )
  473.     {
  474.         TextSize(9) ;
  475.         TextFace(bold) ;
  476.         TextFont(geneva) ;
  477.         cntlPart = TrackControl( cntl, pt ,(ControlActionUPP)-1) ;
  478.         if ( cntlPart != 0 )
  479.             ChangeCSMode( win ) ;
  480.     }
  481.     
  482.     // handle drag of pict
  483.     {
  484.         Rect    paneRect = GetPictDocPaneRect( win ) ;
  485.         Rect    pictRect = GetPictDocPictRect( win ) ;
  486.         Rect    dragRect ;
  487.         short    HorzDelta, VertDelta ;
  488.         
  489.         HorzDelta = GetPictDocCntlValue(win,rPictDocHorzScrollID) * kScrollDelta
  490.                     + pictRect.left
  491.                     - kMargin 
  492.                     - paneRect.left ;
  493.                     
  494.         VertDelta = GetPictDocCntlValue(win,rPictDocVertScrollID) * kScrollDelta
  495.                     + pictRect.top 
  496.                     - kMargin 
  497.                     - paneRect.top ;
  498.         
  499.         dragRect = pictRect ;
  500.         OffsetRect( &dragRect, -HorzDelta, -VertDelta ) ;
  501.         SectRect(&dragRect,&paneRect,&dragRect) ;
  502.         
  503.         if ( PtInRect(pt,&dragRect) )
  504.             DoDragPict( win, e, dragRect) ;
  505.     }    
  506.  
  507. }
  508.  
  509.  
  510. /*------------------------------------------------------------------------------*\
  511.     winResizePictDoc
  512.  *------------------------------------------------------------------------------*
  513.         This is a ResizeProcPtr for PictDoc windows.
  514.         This routine is responsible for re-arranging the contents of the window if
  515.         it is resized.  On entry to this routine, the new window size can be found
  516.         in the document's window's portRect.  At the very least, this routine 
  517.         should call SetWinRect() to put the new window size in the winHandle.
  518.         So far, the only other thing this routine does is repostion the scroll controls
  519.         and issue the appropriate update events so everything is re-drawn correctly.
  520.         This ProcPtr is envoked by CallWinResizeProc() which is called by:
  521.             DoMouseDownEvent() which dispaches mouse down events and
  522.             DoCreatePictWindow() which initially creates the window.
  523. \*------------------------------------------------------------------------------*/
  524. void winResizePictDoc ( winHandle win ) 
  525. {
  526.     ControlHandle    hCtl, vCtl ;
  527.     WindowRef        window ;
  528.     Rect            horzInval, vertInval ;
  529.     Rect            oldDocRect, newDocRect, pictRect ;
  530.     Rect            paneRect ;
  531.  
  532.     oldDocRect = GetWinRect( win ) ;
  533.     pictRect = GetPictDocPictRect( win ) ;
  534.  
  535.     window = GetWinWindow ( win ) ;
  536.     newDocRect = ((CGrafPtr)window)->portRect ;
  537.     SetWinRect( win, newDocRect ) ;
  538.  
  539.     horzInval = vertInval = newDocRect ;
  540.     horzInval.top  = MIN( oldDocRect.bottom, newDocRect.bottom) - kScrollWidth;
  541.     vertInval.left = MIN( oldDocRect.right, newDocRect.right)   - kScrollWidth;
  542.     InvalRect( &horzInval ) ;
  543.     InvalRect( &vertInval ) ;
  544.     EraseRect( &horzInval ) ;
  545.     EraseRect( &vertInval ) ;
  546.     
  547.     hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
  548.     vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
  549.  
  550.     paneRect = newDocRect ;
  551.     paneRect.top += kHeaderHeightBig ;
  552.     paneRect.bottom -= kScrollWidth ;
  553.     paneRect.right -= kScrollWidth ;
  554.     SetPictDocPaneRect( win, paneRect ) ;
  555.     
  556.     MoveControl(hCtl, (paneRect.left-1)+kStatusWidth,
  557.                       paneRect.bottom ) ;    
  558.     MoveControl(vCtl, paneRect.right,
  559.                       paneRect.top-1) ;
  560.         
  561.     SizeControl(hCtl, (2+paneRect.right-paneRect.left)-kStatusWidth,
  562.                       kScrollWidth+1) ;    
  563.     SizeControl(vCtl, kScrollWidth+1,
  564.                       2+paneRect.bottom-paneRect.top) ;
  565.  
  566.     {    // position vertical control
  567.         short pV, wV, max, oldCntlVal ;
  568.         
  569.         pV = pictRect.bottom - pictRect.top ;
  570.         pV += kMargin + kMargin ;
  571.         wV = paneRect.bottom - paneRect.top ;
  572.         if (wV>=pV)
  573.             max = 0 ;
  574.         else
  575.             max = ((MAX (0, pV-wV )) / kScrollDelta) +1 ;
  576.         oldCntlVal = GetControlValue(vCtl) ;
  577.         SetControlMinimum(vCtl, 0) ;
  578.         SetControlMaximum(vCtl, max) ;
  579.         SetControlValue  (vCtl, oldCntlVal ) ;
  580.         
  581.         HiliteControl(vCtl, (max==0)?(255):(0) ) ;    
  582.         ScrollPane( win, vCtl, oldCntlVal ) ;
  583.     }
  584.     
  585.     {    // position hoizontal control
  586.         short pH, wH, max, oldCntlVal ;
  587.         
  588.         pH = pictRect.right - pictRect.left ;
  589.         pH += kMargin + kMargin ;
  590.         wH = paneRect.right - paneRect.left ;
  591.         if (wH>=pH)
  592.             max = 0 ;
  593.         else
  594.             max = ((MAX (0, pH-wH )) / kScrollDelta) +1 ;
  595.         oldCntlVal = GetControlValue(hCtl) ;
  596.         SetControlMinimum(hCtl, 0) ;
  597.         SetControlMaximum(hCtl, max) ;
  598.         SetControlValue  (hCtl, oldCntlVal ) ;
  599.         
  600.         HiliteControl(hCtl, (max==0)?(255):(0) ) ;    
  601.         ScrollPane( win, hCtl, oldCntlVal ) ;
  602.     }
  603.     
  604.     {    // position drag&drop zone
  605.         DragZonesHdl    zones ;
  606.         DragZoneHdl        zone ;
  607.         
  608.         zones = GetPictDocDragZones( win ) ;
  609.         if ( zones )
  610.         {
  611.             if ( FindDragZones( zones, 'PICT', 0L, 0, 1, &zone ) == 1 )
  612.                 (**zone).rect = paneRect ;
  613.             if ( FindDragZones( zones, flavorTypeHFS,'PICT', 0, 1, &zone ) == 1 )
  614.                 (**zone).rect = paneRect ;
  615.         }
  616.     }
  617.     
  618.     return ;
  619. }
  620.  
  621.  
  622. /*------------------------------------------------------------------------------*\
  623.     winClosePictDoc
  624.  *------------------------------------------------------------------------------*
  625.         This is a CloseProcPtr for PictDoc windows.
  626.         So far, all this does is call DisposeWinHandle()
  627.         Other things, such as prompting the user to save the file, could go here.
  628.         This ProcPtr is envoked by CallWinCloseProc() which is called by:
  629.             app_aePDOC_handler() which handles PDOC AppleEvents,  
  630.             DoMouseDownEvent() which dispached click events (e.g. close box), and
  631.             MenuProcPtrs which are called whenever menu events occur.
  632. \*------------------------------------------------------------------------------*/
  633. void    winClosePictDoc ( winHandle win ) 
  634. {
  635.     // could do something like ask the user to save if dirty
  636.     
  637.     // if "Save"
  638.     //         SaveCmndPictDoc( win ) ;
  639.     //        DisposeWinHandle( win ) ;
  640.  
  641.     // if "Cancel"
  642.     //        do nothing ?
  643.     
  644.     // if "Don't save"
  645.     //        DisposeWinHandle( win ) ;
  646.     
  647.     DisposeWinHandle( win ) ;
  648. }
  649.  
  650.  
  651. /*------------------------------------------------------------------------------*\
  652.     winMenuPictDoc
  653.  *------------------------------------------------------------------------------*
  654.         This is a MenuProcPtr for PictDoc windows.
  655.         This routine dispatches any menu commands that the window can handle
  656.         to the appropriate function.
  657.         This ProcPtr is envoked by CallWinMenuProc() which is called by:
  658.             HandleMenuCommand() which dispatches all menu events.
  659. \*------------------------------------------------------------------------------*/
  660. void winMenuPictDoc ( winHandle win, long menuResult, Boolean *didit )
  661. {
  662.     short            menuID;
  663.     short            menuItem;
  664.  
  665.     *didit = true ;
  666.     menuID   = HiWrd(menuResult) ;
  667.     menuItem = LoWrd(menuResult) ;
  668.     switch ( menuID )
  669.     {
  670.         case mFile:
  671.             switch ( menuItem )
  672.             {
  673.                 case iSave:                // save this document under the name it was opened
  674.                     SaveCmndPictDoc( win ) ;
  675.                     break ;
  676.                 case iSaveAs:            // save this document under a new name
  677.                     SaveAsCmndPictDoc( win ) ;
  678.                     break ;
  679.                 case iRevert:            // discard all changes made to the document since it was last saved
  680.                     RevertCmndPictDoc( win ) ;
  681.                     break ;
  682.                 default :
  683.                     *didit = false ;
  684.                     break ;
  685.             }
  686.             break ;
  687.  
  688.         case mEdit:
  689.             switch ( menuItem )
  690.             {
  691.                 case iPaste:            // discard all changes made to the document since it was last saved
  692.                     PasteCmndPictDoc( win ) ;
  693.                     break ;
  694.                 default :
  695.                     *didit = false ;
  696.                     break ;
  697.             }
  698.             break ;
  699.             
  700.         case mProfiles:
  701.             switch ( menuItem )
  702.             {
  703.                 case iMakeSrceProf:
  704.                     DoChangeProfileFromFront( win, kSrceProf ) ;
  705.                     break ;
  706.                 case iMakeDestProf:
  707.                     DoChangeProfileFromFront( win, kDestProf ) ;
  708.                     break ;
  709.                 case iMakePrevProf:
  710.                     DoChangeProfileFromFront( win, kPrevProf ) ;
  711.                     break ;
  712.                 case iMakeEmbdProf:
  713.                     DoAddEmbdProfFromFront( win, cmEmbedWholeProfile ) ;
  714.                     break ;
  715.                 case iMakeEmbdProfID:
  716.                     DoAddEmbdProfFromFront( win, cmEmbedProfileIdentifier ) ;
  717.                     break ;
  718.                 default :
  719.                     *didit = false ;
  720.                     break ;
  721.             }
  722.             break ;
  723.  
  724.         default :
  725.             *didit = false ;
  726.             break ;
  727.     }
  728.     HiliteMenu(0) ;        // Unhighlight whatever MenuSelect or MenuKey hilited
  729. }
  730.  
  731.  
  732. /*------------------------------------------------------------------------------*\
  733.     winUpdateMenusPictDoc
  734.  *------------------------------------------------------------------------------*
  735.         This is a UpdateMenusProcPtr for the PictDoc window.
  736.         This routine enables any menu commands that the window can handle.
  737.         For the PictDoc window, the needed items are in the File and Edit menus 
  738.         This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
  739.             DoAppAdjustMenus() which enables menu commands.
  740. \*------------------------------------------------------------------------------*/
  741. void winUpdateMenusPictDoc ( winHandle win ) 
  742. {
  743.     MenuHandle        theMenu ;
  744.     FSSpec            spec ;
  745.     Boolean            dirty ;
  746.     Boolean            hasFile ;
  747.     Boolean            pictOnScrap = true;
  748.     long            scrapOffset ;
  749.     winHandle        frontWin;
  750.     
  751.     frontWin = GetFrontWindowWinHandle() ;
  752.     
  753.     if ( win == frontWin )
  754.     {
  755.         spec = GetWinFSSpec( win ) ;
  756.         dirty = GetWinDirty( win ) ;
  757.         pictOnScrap = (GetScrap(nil,'PICT',&scrapOffset) > 0) ;
  758.         hasFile = ( spec.name[0] > 0 ) ;
  759.         
  760.         // do the file menu
  761.         theMenu = GetMenuHandle ( mFile ) ;
  762.     
  763.             EnableItem ( theMenu, kWholeMenu ) ;
  764.             EnableItem ( theMenu, iClose ) ;
  765.             EnableItem ( theMenu, iSaveAs ) ;
  766. #ifndef PIGS_SHELL_NOPRINT
  767.             EnableItem ( theMenu, iPageSetup ) ;
  768.             EnableItem ( theMenu, iPrint ) ;
  769.             EnableItem ( theMenu, iPrintOne ) ;
  770. #endif
  771.             
  772.             // for the next 2, check to see if the document has been changed
  773.             if ( dirty )
  774.                 EnableItem ( theMenu, iSave ) ;
  775.             if ( dirty && hasFile )
  776.                 EnableItem ( theMenu, iRevert ) ;
  777.     
  778.         // do the edit menu
  779.         theMenu = GetMenuHandle ( mEdit ) ;
  780.     
  781.             if ( pictOnScrap )
  782.             {
  783.                 EnableItem ( theMenu, kWholeMenu ) ;
  784.                 EnableItem ( theMenu, iPaste ) ;
  785.             }
  786.     }
  787.     else
  788.     {
  789.         OSType    frontType, frontSubtype;
  790.         
  791.         // do the profiles menu
  792.         theMenu = GetMenuHandle ( mProfiles ) ;
  793.  
  794.         frontType = GetWinType( frontWin ) ;
  795.         frontSubtype = GetWinSubtype( frontWin ) ;
  796.         
  797.         if (frontType == kProfileType)
  798.         {
  799.             EnableItem ( theMenu, kWholeMenu ) ;
  800.             EnableItem ( theMenu, iMakeSrceProf ) ;
  801.             EnableItem ( theMenu, iMakeDestProf ) ;
  802.             EnableItem ( theMenu, iMakePrevProf ) ;
  803.             if ( frontSubtype!=kSysProfSubType )
  804.             {
  805.                 EnableItem ( theMenu, iMakeEmbdProf ) ;
  806.                 EnableItem ( theMenu, iMakeEmbdProfID ) ;
  807.             }
  808.         }        
  809.         if (frontType == kProfIDType)
  810.         {
  811.             EnableItem ( theMenu, kWholeMenu ) ;
  812.             EnableItem ( theMenu, iMakeEmbdProfID ) ;
  813.         }        
  814.         if (frontType == kProfListType)
  815.         {
  816.             Cell        cell;
  817.             ListHandle    list;
  818.                     
  819.             list = GetProfListList( frontWin ) ;
  820.             if ( GetSingleSelect( &cell, list))            // if we can fine one selected item
  821.             {
  822.                 EnableItem ( theMenu, kWholeMenu ) ;
  823.                 EnableItem ( theMenu, iMakeSrceProf ) ;
  824.                 EnableItem ( theMenu, iMakeDestProf ) ;
  825.                 EnableItem ( theMenu, iMakePrevProf ) ;
  826.                 EnableItem ( theMenu, iMakeEmbdProf ) ;
  827.                 EnableItem ( theMenu, iMakeEmbdProfID ) ;
  828.             }
  829.         }
  830.     }
  831. }
  832.  
  833.  
  834. /*------------------------------------------------------------------------------*\
  835.     winAllocPictDoc
  836.  *------------------------------------------------------------------------------*
  837.         This is a AllocProcPtr for PictDoc windows.
  838.         This routine is responsible for filling in all the needed fields of the
  839.         winHandle structure.  This routine shouldn't be called directly.
  840.         Instead, the code which needs to create a document of this type should
  841.         call NewWinHandle(win,winAllocPictDoc) to envoke this function.
  842.         This ProcPtr is envoked by NewWinHandle() which is called by:
  843.             app_aeODOC_handler() which handles ODOC AppleEvents, and
  844.             app_aePDOC_handler() which handles PDOC AppleEvents.
  845. \*------------------------------------------------------------------------------*/
  846. OSErr winAllocPictDoc ( winHandle win )
  847. {
  848.     OSErr            err = noErr ;
  849.     PictDocDataHdl    data ;
  850.     
  851.     // set the window type
  852.     SetWinType( win, kPictDocType ) ;
  853.     
  854.     // allocate data handle
  855.     data = (PictDocDataHdl)NewHandleClear( sizeof(PictDocDataRec) ) ;
  856.     if ( data == nil ) return MemError() ;
  857.     SetWinData ( win, (Handle)data ) ;
  858.     (**data).PictMatchedNeedsUpdate =
  859.     (**data).PictProofedNeedsUpdate =
  860.     (**data).PictCheckedNeedsUpdate = true ;
  861.     
  862.     // stuff winHandle fields
  863.     SetWinActivateProc        ( win,    (ActivateProcPtr) winActivatePictDoc ) ;
  864.     SetWinUpdateProc        ( win,      (UpdateProcPtr) winUpdatePictDoc ) ;
  865.     SetWinClickProc            ( win,       (ClickProcPtr) winClickPictDoc ) ;
  866.     SetWinMenuProc            ( win,        (MenuProcPtr) winMenuPictDoc ) ;
  867.     SetWinUpdateMenusProc    ( win, (UpdateMenusProcPtr) winUpdateMenusPictDoc ) ;
  868.     SetWinResizeProc        ( win,      (ResizeProcPtr) winResizePictDoc ) ;
  869.     SetWinNewProc            ( win,         (NewProcPtr) winNewPictDoc ) ;
  870.     SetWinOpenProc            ( win,        (OpenProcPtr) winOpenPictDoc ) ;
  871.     SetWinCloseProc            ( win,       (CloseProcPtr) winClosePictDoc ) ;
  872.     SetWinDisposeProc        ( win,     (DisposeProcPtr) winDisposePictDoc ) ;
  873.  
  874. #ifndef PIGS_SHELL_NOPRINT
  875.     SetWinPageCountProc        ( win,   (PageCountProcPtr) winPageCountPictDoc ) ;
  876.     SetWinPagePrintProc        ( win,   (PagePrintProcPtr) winPagePrintPictDoc ) ;
  877. #endif
  878.     
  879.     return err ;    
  880. }
  881.  
  882.  
  883. /*------------------------------------------------------------------------------*\
  884.     winNewPictDoc
  885.  *------------------------------------------------------------------------------*
  886.         This is a NewProcPtr for PictDoc windows.
  887.         This routine is responsible for creating and empty a PictDoc window after all the
  888.         needed fields of the winHandle structure have been filled in by winAllocPictDoc.
  889.         This routine shouldn't be called directly.  Instead, the code which needs
  890.         to create a document of this type should call NewWinHandle(win,winAllocPictDoc)
  891.         and then CallWinNewProc(win) to envoke this function.
  892.         This ProcPtr is envoked by CallWinNewProc() which is called by:
  893.             DoNewCommand() which creates a new PictDoc window. 
  894. \*------------------------------------------------------------------------------*/
  895. OSErr winNewPictDoc ( winHandle win )
  896. {
  897.     OSErr            err = noErr ;
  898.     
  899.     err = DoCreatePictWindow( win ) ;
  900.     if ( err ) return err ;
  901.     
  902. #ifndef PIGS_SHELL_NOPRINT
  903.     err = DoAppGetPrintStrutures( win ) ;
  904.     if ( err ) err = noErr ;            // dont worry, we'll try again if the user prints
  905. #endif
  906.  
  907.     return err ;    
  908. }
  909.  
  910.  
  911. /*------------------------------------------------------------------------------*\
  912.     winOpenPictDoc
  913.  *------------------------------------------------------------------------------*
  914.         This is a OpenProcPtr for PictDoc windows.
  915.         This routine is responsible for opening a PictDoc window after all the
  916.         needed fields of the winHandle structure have been filled in by winAllocPictDoc.
  917.         On entry the DocumentRecord must contain a valid FSSpec.
  918.         If a PictDoc window for the FSSpec is already onen, then this routine 
  919.         will bring it to the front instead of opening a second window.
  920.         This routine shouldn't be called directly.  Instead, the code which needs
  921.         to create a document of this type should call NewWinHandle(win,winAllocPictDoc),
  922.         SetWinFSSpec(win,spec), and then CallWinOpenProc(win) to envoke this function.
  923.         This ProcPtr is envoked by CallWinOpenProc() which is called by:
  924.             app_aeODOC_handler() which handles ODOC AppleEvents, and
  925.             app_aePDOC_handler() which handles PDOC AppleEvents.
  926. \*------------------------------------------------------------------------------*/
  927. OSErr winOpenPictDoc ( winHandle win )
  928. {
  929.     OSErr            err = noErr ;
  930.     PicHandle        pict ;
  931.     Rect            rect ;
  932.     FSSpec            spec ;
  933.     winHandle        existingDoc ;
  934.     
  935.     spec = GetWinFSSpec( win ) ;
  936.  
  937.     // see if we are already open
  938.      if ( FindWinHandle( &spec, kPictDocType, nil, 1, 1, &existingDoc ) == 1 )
  939.     {
  940.         // bring it to the front
  941.         SelectWindow( GetWinWindow(existingDoc) ) ;        
  942.         return kWasAlreadyOpen;
  943.     }
  944.  
  945.     // try to read the pict
  946.     err = DoReadPICT ( spec, &pict ) ;
  947.     if ( err ) return err ;
  948.     
  949.     // set the window's rect
  950.     rect = (**pict).picFrame ;
  951.     SetPictDocPictRect( win, rect ) ;
  952.  
  953.     // set the window's data's pict
  954.     SetPictDocPict( win, kOriginal, pict ) ;
  955.     SetPictDocNeedsUpdate( win, kMatched, true ) ;
  956.     SetPictDocNeedsUpdate( win, kProofed, true ) ;
  957.     SetPictDocNeedsUpdate( win, kChecked, true ) ;
  958.     
  959. //    err = DoCreatePalettes( win ) ;
  960. //    if ( err ) return err ;
  961.  
  962.     err = DoCreatePictWindow( win ) ;
  963.     if ( err ) return err ;
  964.     
  965. #ifndef PIGS_SHELL_NOPRINT
  966.     err = DoAppGetPrintStrutures( win ) ;
  967.     if ( err ) err = noErr ;        // dont worry, we'll try again if the user prints
  968. #endif
  969.     
  970.     return err ;    
  971. }
  972.  
  973.  
  974. /*------------------------------------------------------------------------------*\
  975.     winDisposePictDoc
  976.  *------------------------------------------------------------------------------*
  977.         This is a DisposeProcPtr for PictDoc windows.
  978.         This routine is responsible for disposing of any data that was allocated
  979.         by the document and stored in the its data handle.
  980.         This ProcPtr is envoked by CallWinDisposeProc() which is called by:
  981.             DisposeWinHandle() which disposes of the entire winHandle.
  982. \*------------------------------------------------------------------------------*/
  983. void winDisposePictDoc ( winHandle win )
  984. {
  985.     PictDocDataHdl    data ;
  986.     PicHandle        pict ;
  987.     PaletteHandle    palette ;
  988.     WindowRef        window ;
  989.     DragZonesHdl    zones ;
  990.     ListHandle        list ;
  991.     CMProfileRef    prof ;
  992.     
  993.     data = (PictDocDataHdl) GetWinData ( win ) ;
  994.     if ( data==nil ) return;
  995.     
  996.     // dispose of all the PicHandles we used
  997.     pict = GetPictDocPict( win, kOriginal ) ;
  998.     if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
  999.  
  1000.     pict = GetPictDocPict( win, kProofed ) ;
  1001.     if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
  1002.  
  1003.     pict = GetPictDocPict( win, kMatched ) ;
  1004.     if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
  1005.  
  1006.     pict = GetPictDocPict( win, kChecked ) ;
  1007.     if ( pict != nil ) DisposeHandle( (Handle)pict ) ;
  1008.  
  1009.     // close of all the Profiles we used
  1010.     prof = GetPictDocProfile( win, kSrceProf ) ;
  1011.     if ( prof != nil ) CMCloseProfile( prof ) ;
  1012.     
  1013.     prof = GetPictDocProfile( win, kDestProf ) ;
  1014.     if ( prof != nil ) CMCloseProfile( prof ) ;
  1015.     
  1016.     prof = GetPictDocProfile( win, kPrevProf ) ;
  1017.     if ( prof != nil ) CMCloseProfile( prof ) ;
  1018.  
  1019.     // dispose of the ListHandle we used
  1020.     list = GetPictDocProfList ( win ) ;
  1021.     if ( list != nil ) LDispose(list) ;
  1022.     
  1023.     // dispose of the PictPalette we used
  1024.     palette = GetPictDocPalette( win ) ;
  1025.     if ( palette != nil ) DisposePalette( palette ) ;
  1026.  
  1027.     // dispose of all controls
  1028.     window = GetWinWindow( win ) ;
  1029.     if ( window != nil ) KillControls( window ) ;
  1030.  
  1031.     // dispose of drag&drop zoned structure
  1032.     zones = GetPictDocDragZones( win ) ;
  1033.     if ( window != nil  &&  zones != nil )
  1034.     {
  1035.         RemoveDragZonesHandlers ( zones, window ) ;
  1036.         DisposeHandle( (Handle)zones ) ;
  1037.     }
  1038.  
  1039.     // lastly, dispose of the data handle
  1040.     DisposeHandle( (Handle)data ) ;
  1041. }
  1042.  
  1043.  
  1044. /*------------------------------------------------------------------------------*\
  1045.     winPageCountPictDoc
  1046.  *------------------------------------------------------------------------------*
  1047.         This is a PageCountProcPtr for PictDoc windows.
  1048.         This routine is responsible for the number of pages needed to render the 
  1049.         document's data (whatever it may be) gives the bounds of a page.
  1050.         This ProcPtr is envoked by CallWinPageCountProc() which is called by:
  1051.             DoPrintLoop() which impliments an old-style printing loop, and
  1052.             DoGXPrintLoop() which impliments a GX-style printing loop.
  1053. \*------------------------------------------------------------------------------*/
  1054. OSErr winPageCountPictDoc ( winHandle win, short *pageCount )
  1055. {
  1056.     Rect        pageRect ;
  1057.     Rect        pictRect ;
  1058.     short        horizOffset, 
  1059.                 vertOffset,
  1060.                 pagesWide,         // the number of pages wide the image is
  1061.                 pagesHigh,         // the number pages high for this image
  1062.                 pageWidth, pageHeight,         // dimensions of one page
  1063.                 pictWidth, pictHeight ;        // dimensions of the pict
  1064.     OSErr        err ;
  1065.     
  1066.     pictRect = GetPictDocPictRect( win ) ;
  1067.     err = DoAppGetPageSize( win, &pageRect ) ;
  1068.     if ( err ) return err ;
  1069.     
  1070.     horizOffset = -(pictRect.left) ;
  1071.     vertOffset = -(pictRect.top) ;
  1072.     
  1073.     OffsetRect( &pictRect, horizOffset, vertOffset ) ;    // this should make the origin of the rect (0,0)
  1074.  
  1075.     pageWidth = pageRect.right - pageRect.left ;
  1076.     pageHeight = pageRect.bottom - pageRect.top ;
  1077.     
  1078.     pictWidth  = pictRect.right - pictRect.left ;
  1079.     pictHeight = pictRect.bottom - pictRect.top ;
  1080.     
  1081.     pagesWide = 1+ ( (pictWidth-1)  / pageWidth  ) ;    // round up the number of pages to the nearest
  1082.     pagesHigh = 1+ ( (pictHeight-1) / pageHeight ) ;    // whole page in each direction.
  1083.     
  1084.     *pageCount = pagesWide*pagesHigh ;
  1085.     
  1086.     return noErr ;
  1087. }
  1088.  
  1089.  
  1090. /*------------------------------------------------------------------------------*\
  1091.     winPagePrintPictDoc
  1092.  *------------------------------------------------------------------------------*
  1093.         This is a PagePrintProcPtr for PictDoc windows.
  1094.         This routine is responsible for the printing a given page of document's
  1095.         data into the destination port.
  1096.         This ProcPtr is envoked by CallWinPagePrintProc() which is called by:
  1097.             DoPrintLoop() which impliments an old-style printing loop, and
  1098.             DoGXPrintLoop() which impliments a GX-style printing loop.
  1099. \*------------------------------------------------------------------------------*/
  1100. OSErr winPagePrintPictDoc ( winHandle win, GrafPtr imagingPort, short pageNum )
  1101. {
  1102.     Rect        pageRect ;
  1103.     Rect        pictRect ;
  1104.     Rect        srcRect, dstRect;
  1105.     short        pagesWide,         // the number of pages wide the image is
  1106.                 pagesHigh,         // the number pages high for this image
  1107.                 horozTile,         // used in the loop to denote the H tile to print from the image
  1108.                 vertTile ;         // used in the loop to denote the V tile to print from the image
  1109.     short        thisPage = 1;    // used to find the page they want us to print
  1110.     short        pictHOff,
  1111.                 pictVOff,
  1112.                 pictWidth,         // the width of the win's GWorld
  1113.                 pictHeight ;    // the height of the win's GWorld
  1114.     short        pageWidth,         // the width of one page
  1115.                 pageHeight ;    // the height of one page
  1116.     OSErr        err ;
  1117.     GrafPtr        savedPort ;
  1118.  
  1119.     pictRect = GetPictDocPictRect( win ) ;
  1120.     err = DoAppGetPageSize( win, &pageRect ) ;
  1121.     if ( err ) return err ;
  1122.     
  1123.     GetPort( &savedPort ) ;    
  1124.     SetPort( imagingPort ) ;                        // be sure to do this
  1125.     
  1126.     pictHOff   = -(pictRect.left) ;
  1127.     pictVOff   = -(pictRect.top) ;
  1128.     pictWidth  = pictRect.right - pictRect.left ;
  1129.     pictHeight = pictRect.bottom - pictRect.top ;
  1130.     
  1131. //    OffsetRect( &pictRect, pictHOff, pictVOff ) ;    // this should make the origin of the rect (0,0)
  1132.  
  1133.     pageWidth  = pageRect.right - pageRect.left ;
  1134.     pageHeight = pageRect.bottom - pageRect.top ;
  1135.     
  1136.     pagesWide = 1+ ( (pictWidth-1) /pageWidth  ) ;    // round up the number of pages to the nearest
  1137.     pagesHigh = 1+ ( (pictHeight-1)/pageHeight ) ;    // whole page in each direction.
  1138.     
  1139.     thisPage = 1;
  1140.     for (vertTile=0; vertTile<pagesHigh; vertTile++)
  1141.     {
  1142.         for (horozTile=0; horozTile<pagesWide; horozTile++)
  1143.         {
  1144.             if( thisPage == pageNum )                // is this the page we were called to print
  1145.             {
  1146.                 srcRect = pageRect;
  1147.                 
  1148.                 OffsetRect( &srcRect,
  1149.                             pictRect.left - srcRect.left,
  1150.                             pictRect.top  - srcRect.top ) ;
  1151.     
  1152.                 OffsetRect( &srcRect,
  1153.                             horozTile * pageWidth,
  1154.                             vertTile * pageHeight ) ;
  1155.                 
  1156.                 SectRect( &srcRect, &pictRect, &srcRect) ;
  1157.                 
  1158.                 // finess the rect to print, we'll assume the the top left is always correct.
  1159.                 // this helps with areas of the pict that don't fit entirely on one page
  1160.  
  1161.                 dstRect = srcRect;
  1162.                 
  1163.                 OffsetRect( &dstRect,
  1164.                             pageRect.left - srcRect.left,
  1165.                             pageRect.top  - srcRect.top ) ;
  1166.  
  1167.                 DoDrawPictData( win, imagingPort, &srcRect, &dstRect ) ; 
  1168.  
  1169.             }
  1170.             thisPage++ ;                            // bump the page number
  1171.         }
  1172.     }
  1173.     SetPort( savedPort ) ;                            // put the old port back
  1174.     return noErr ;
  1175. }
  1176.  
  1177.  
  1178. /**\
  1179. |**| ==============================================================================
  1180. |**| PRIVATE FUNCTIONS
  1181. |**| ==============================================================================
  1182. \**/
  1183.  
  1184.  
  1185. /*------------------------------------------------------------------------------*\
  1186.     DoDrawPictData
  1187.  *------------------------------------------------------------------------------*
  1188.         This routine draws the postion of the documents data bounded by srcRect,
  1189.         into the rectangle dstRect of the destPort.
  1190.         data into the destination port.
  1191.         This routine is called by:
  1192.             winUpdatePictDoc() which draws into the scrollable window, and
  1193.             winPagePrintPictDoc() which draws into a printing port.
  1194. \*------------------------------------------------------------------------------*/
  1195. static void DoDrawPictData ( winHandle win, GrafPtr destPort, Rect *srcRect, Rect *dstRect ) 
  1196. {    
  1197.     Rect            rect;
  1198.     PictDocDataHdl    data ;
  1199.     PicHandle        pict ;
  1200.     RgnHandle        savedClipRgn;
  1201.     short            mode, cson ;
  1202.     
  1203.     data = (PictDocDataHdl) GetWinData ( win ) ;
  1204.     if ( data==nil ) return;
  1205.     
  1206.     rect = GetPictDocPictRect( win ) ;
  1207.     if ( ! ( rect.top || rect.bottom || rect.left || rect.right ) )
  1208.         return ;
  1209.  
  1210.     SetGWorld( (CGrafPtr)destPort, nil ) ;    // set the destPort to be the current port
  1211.  
  1212.     MapRect(&rect, srcRect, dstRect) ;
  1213.  
  1214.     savedClipRgn = NewRgn() ;
  1215.     GetClip(savedClipRgn) ;
  1216.     ClipRect(dstRect) ;
  1217.     
  1218.     cson = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
  1219.     mode = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
  1220.     if (!cson) mode = kOriginal ;
  1221.     
  1222.     UpdatePict( win, mode ) ;
  1223.     if (mode==kDrwMchdPct)
  1224.     {
  1225.         pict = GetPictDocPict(win,kOriginal) ;
  1226.         if (pict != nil)
  1227.             NCMDrawMatchedPicture(pict, GetPictDocProfile(win,kPrevProf), &rect) ;
  1228.         else
  1229.             EraseRect( &rect ) ;    
  1230.     }
  1231.     else
  1232.     {
  1233.         pict = GetPictDocPict(win,mode) ;
  1234.         if (pict != nil)
  1235.             DrawPicture( pict, &rect ) ;
  1236.         else
  1237.             EraseRect( &rect ) ;    
  1238.     }
  1239.     
  1240.     SetClip(savedClipRgn) ;
  1241.     DisposeRgn(savedClipRgn) ;
  1242. }
  1243.  
  1244.  
  1245. /*------------------------------------------------------------------------------*\
  1246.     DoCreatePalettes
  1247.  *------------------------------------------------------------------------------*
  1248.         This routine extracts the palette, and colortable from the document's 
  1249.         PictHandle and stores them in the dPictPalette and dPictCTab fields of
  1250.         the PictDocDataHdl. 
  1251.         This routine is called by:
  1252.             winOpenPictDoc() which fills in the winHandle structure
  1253. \*------------------------------------------------------------------------------*/
  1254. static OSErr DoCreatePalettes ( winHandle win )
  1255. {
  1256.     OSErr            err ;
  1257.     PicHandle        pict ;
  1258.     PictInfo        pictInfo ;
  1259.     CTabHandle        ctab ;
  1260.     PaletteHandle    pal ;
  1261.     PictDocDataHdl    data ;
  1262.  
  1263.     data = (PictDocDataHdl) GetWinData ( win ) ;
  1264.     if ( data==nil ) return nilHandleErr ;
  1265.     
  1266.     pict = GetPictDocPict( win, kOriginal ) ;
  1267.         
  1268.     // use the picture utilities to get the palette for the window
  1269.     err = GetPictInfo( pict, &pictInfo, returnColorTable, 256, systemMethod, 0) ;
  1270.  
  1271.     ctab = pictInfo.theColorTable ;
  1272.     pal = NewPalette( (**ctab).ctSize +1, ctab, pmTolerant, 0x1000 ) ;
  1273.  
  1274.     // set up the palette for later use
  1275.     SetPictDocPalette( win, pal ) ;
  1276.  
  1277.     return noErr ;
  1278. }
  1279.  
  1280.  
  1281. /*------------------------------------------------------------------------------*\
  1282.     BuildProfList
  1283.  *------------------------------------------------------------------------------*
  1284. \*------------------------------------------------------------------------------*/
  1285. static ListHandle BuildProfList ( winHandle win )
  1286. {
  1287.     ListHandle            theList = nil ;
  1288.     unsigned long        count ;
  1289.     CMError                cmerr ;
  1290.     PicHandle            pict ;
  1291.  
  1292.     pict = GetPictDocPict( win, kOriginal ) ;
  1293.     if (pict==nil) return nil ;
  1294.     
  1295. //------------- search for all profiles
  1296.     {
  1297.         cmerr = CountProfilesInPicHandle ( pict,  &count ) ;
  1298.         if (cmerr) goto bail ;
  1299.         SetPictDocListCount ( win, count ) ;
  1300.     }
  1301.     
  1302.     
  1303. //------------- build a list
  1304.     {
  1305.         Rect        rView, rDataBnds ;
  1306.         Point        cellSize ;
  1307.         WindowRef    window ;
  1308.  
  1309.         rView = GetRect ( rPictEmbdProfRectID ) ;
  1310.         rView.right -= kScrollWidth;
  1311.         SetPt( &cellSize, rView.right-rView.left, kCellHeight ) ;
  1312.         InsetRect( &rView, 1, 1) ;
  1313.         
  1314.         window = GetWinWindow ( win ) ;
  1315.         SetRect( &rDataBnds, 0,0,1,count ) ;
  1316.         theList = LNew(&rView,
  1317.                         &rDataBnds,
  1318.                         cellSize,
  1319.                         0,                        // proc ID
  1320.                         window,
  1321.                         false,                    // draw now
  1322.                         true,                    // hasGrow
  1323.                         false,                    // scrollHoriz
  1324.                         true ) ;                // scrollVert
  1325.         SetPictDocProfList( win, theList ) ;
  1326.     }
  1327.  
  1328.  
  1329. //------------- add strings to list cells
  1330.     {
  1331.         Point                theCell ;
  1332.         unsigned long        v ;
  1333.         short                dataLen ;
  1334.         Str255                name ;
  1335.         CMProfileRef        prof ;
  1336.  
  1337.         for ( v=0; v<count; v++ )
  1338.         {
  1339.             cmerr = GetIndexedProfileFromPicHandle ( pict, v+1, &prof, nil ) ;
  1340.             cmerr = GetProfName( prof, (StringPtr)name ) ;
  1341.             CMCloseProfile( prof ) ;
  1342.             
  1343.             SetPt(&theCell,0,v) ;
  1344.             dataLen = name[0] ;
  1345.             LSetCell( &(name[1]),  dataLen, theCell, theList ) ;
  1346.         }
  1347.     }
  1348.     
  1349. //-------------
  1350. bail :
  1351.     return theList ;
  1352. }
  1353.  
  1354.  
  1355. /*------------------------------------------------------------------------------*\
  1356.     DoCreatePictWindow
  1357.  *------------------------------------------------------------------------------*
  1358.         This routine actually creates the WindowRef for a winHandle.
  1359.         After creating the window, it:
  1360.             reference the window and the DocumentRecord to each other,
  1361.             makes the window the current port,
  1362.             loads and adds the scroll bar controls,
  1363.             resizes the window according to the Pict (if present),
  1364.             attaches the winHandle's palette to the window,
  1365.             titles it according the the FSSpec (if present), and
  1366.             makes it visible .
  1367.         This routine is called by:
  1368.             winOpenPictDoc() which is called when opening a pict file
  1369.             winNewPictDoc() which is called when creating a new pict window
  1370. \*------------------------------------------------------------------------------*/
  1371. static OSErr DoCreatePictWindow ( winHandle win )
  1372. {
  1373.  
  1374.     Rect            pictRect ;
  1375.     Rect            sizeRect ;
  1376.     OSErr            err = noErr ;
  1377.     WindowRef        window ;
  1378.     FSSpec            spec;
  1379.     PictDocDataHdl    data ;
  1380.     //PaletteHandle    palette ;
  1381.     short            h,v ;
  1382.     ListHandle        profList ;
  1383.     
  1384.     data = (PictDocDataHdl) GetWinData ( win ) ;
  1385.     if ( data==nil ) return nilHandleErr ;
  1386.     
  1387.     // create the window
  1388.     window = GetNewCWindow(rPictDocWindID, nil, (WindowRef)-1 ) ;
  1389.  
  1390.     SetWinWindow( win, window ) ;            // save a reference to the window in the DocumentRecord
  1391.     SetWindowWinHandle( window, win ) ;        // save a reference to the DocumentRecord in the window
  1392.  
  1393.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  1394.  
  1395.     pictRect = GetPictDocPictRect( win ) ;
  1396.         
  1397.     h = pictRect.right - pictRect.left ;
  1398.     v = pictRect.bottom - pictRect.top ;
  1399.     h += kScrollWidth + kMargin + kMargin ;
  1400.     v += kScrollWidth + kMargin + kMargin + kHeaderHeightBig ;
  1401.     h = MAX(h, kWindowWidthMin) ;
  1402.     v = MAX(v, kWindowHeightMin+kHeaderHeightBig) ;
  1403.     
  1404.     SizeWindow(    window, h, v, false) ;        // we'll update everything later
  1405.  
  1406.     SetRect( &sizeRect, kWindowWidthMin,
  1407.                         kWindowHeightMin+kHeaderHeightBig,
  1408.                         h+1,v+1) ;
  1409.     SetWinSizeRect( win, sizeRect ) ;
  1410.  
  1411.     // try to make list of embeded profiles
  1412.     profList = BuildProfList( win ) ;
  1413.     
  1414.     // set up drag&drop zones
  1415.     err = DoCreateDragZones( win ) ;
  1416.     if (err) return err ;                    // we should dispose window before returning
  1417.  
  1418.     // set up scroll bars
  1419.     SetPictDocCntl( win, rPictDocHorzScrollID, GetNewControl(rPictDocHorzScrollID, window ) ) ;
  1420.     SetPictDocCntl( win, rPictDocVertScrollID, GetNewControl(rPictDocVertScrollID, window ) ) ;
  1421.     SetPictDocCntl( win, rPictDocMatchOnOffID, GetNewControl(rPictDocMatchOnOffID, window ) ) ;
  1422.     SetPictDocCntl( win, rPictDocMatchPopupID, GetNewControl(rPictDocMatchPopupID, window ) ) ;
  1423.  
  1424.     // this will adjust the controls and drag&drop zones
  1425.     CallWinResizeProc( win ) ;
  1426.  
  1427.     // and if we set up the palette earlier assign it to the window                
  1428.     //    palette = GetPictDocPalette( win ) ;
  1429.     //    if( palette != nil )
  1430.     //        SetPalette ( window, palette, true ) ;
  1431.     //    ActivatePalette ( window ) ;    
  1432.     
  1433.     // set the name of this document window
  1434.     spec = GetWinFSSpec( win ) ;
  1435.     if ( spec.name[0] )
  1436.         SetWTitle( window, spec.name ) ;
  1437.     
  1438.     // make sure it is visible
  1439.     ShowWindow( window ) ;
  1440.     
  1441.     return err ;
  1442. }
  1443.  
  1444.  
  1445. /*------------------------------------------------------------------------------*\
  1446.     DoCreateDragZones
  1447.  *------------------------------------------------------------------------------*
  1448.         This routine is called by:
  1449. \*------------------------------------------------------------------------------*/
  1450. static OSErr DoCreateDragZones ( winHandle win )
  1451. {
  1452.     OSErr            err = noErr ;
  1453.     Rect            temp = {0,0,500,500} ;
  1454.     DragZonesHdl    zones ;
  1455.     DragZoneRec        zone ;
  1456.     short            which ;
  1457.     
  1458.     zones = NewDragZones() ;
  1459.  
  1460.      zone.rect = temp ;
  1461.     zone.flavor = 'PICT' ;
  1462.     zone.HFSfileType = '????' ;
  1463.     zone.dragRecvUPP = NewDragZoneRecvProc( MyDragZoneRecvCallback ) ;
  1464.     err = AddDragZone ( zones, &zone ) ;
  1465.  
  1466.      zone.rect = temp ;
  1467.     zone.flavor = flavorTypeHFS ;
  1468.     zone.HFSfileType = 'PICT' ;
  1469.     zone.dragRecvUPP = NewDragZoneRecvProc( MyDragZoneRecvCallback ) ;
  1470.     err = AddDragZone ( zones, &zone ) ;
  1471.  
  1472.     // this loop assumes resid's are consecutive
  1473.     for ( which=kSrceProf; which<=kEmbedProfs; which++)
  1474.     {
  1475.         temp = GetRect( rPictDocHorzScrollID + which )  ;
  1476.         InsetRect( &temp, 1, 1 ) ;
  1477.         
  1478.          zone.rect = temp  ;
  1479.         zone.flavor = flavorTypeHFS ;
  1480.         zone.HFSfileType = 'prof' ;
  1481.         zone.dragRecvUPP = NewDragZoneRecvProc( MyProfDragZoneRecvCallback ) ;
  1482.         zone.zoneRefCon = (void*)which ;
  1483.         err = AddDragZone ( zones, &zone ) ;
  1484.     }
  1485.  
  1486.     SetPictDocDragZones( win, zones ) ;
  1487.     err = InstallDragZonesHandlers ( zones, GetWinWindow(win) ) ;
  1488.                                   
  1489.     return err ;
  1490. }
  1491.  
  1492.  
  1493. /*------------------------------------------------------------------------------*\
  1494.     PictDocActionProc
  1495.  *------------------------------------------------------------------------------*
  1496. \*------------------------------------------------------------------------------*/
  1497. static pascal void PictDocActionProc ( ControlHandle cntl, short cntlPart)
  1498. {
  1499.     ControlHandle    hCtl, vCtl ;
  1500.     WindowRef        window ;
  1501.     winHandle        win ;
  1502.     short            oldCntlVal ;
  1503.     
  1504.     // get win from cntl
  1505.     window = (**cntl).contrlOwner ;
  1506.     
  1507.     // get winHandle from window
  1508.     win = GetWindowWinHandle( window ) ;
  1509.     
  1510.     // get controls from winHandle's data
  1511.     hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
  1512.     vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
  1513.  
  1514.     if ( cntl==hCtl    || cntl==vCtl)
  1515.     {
  1516.         oldCntlVal = GetControlValue( cntl ) ;
  1517.         switch (cntlPart)
  1518.         {
  1519.             case kControlUpButtonPart :
  1520.                     if ( oldCntlVal > (**cntl).contrlMin )
  1521.                     SetControlValue( cntl, oldCntlVal - 1 ) ;
  1522.                     break;
  1523.             case kControlDownButtonPart :
  1524.                     if ( oldCntlVal < (**cntl).contrlMax )
  1525.                     SetControlValue( cntl, oldCntlVal + 1 ) ;
  1526.                     break;
  1527.             case kControlPageUpPart :
  1528.                     SetControlValue( cntl, oldCntlVal - 5 ) ;
  1529.                     break;
  1530.             case kControlPageDownPart :
  1531.                     SetControlValue( cntl, oldCntlVal + 5 ) ;
  1532.                     break;
  1533.             case kControlIndicatorPart :
  1534.                     break;
  1535.         }
  1536.         ScrollPane( win, cntl, oldCntlVal ) ;
  1537.     }
  1538. }
  1539.  
  1540.  
  1541. /*------------------------------------------------------------------------------*\
  1542.     UpdatePane
  1543.  *------------------------------------------------------------------------------*
  1544. \*------------------------------------------------------------------------------*/
  1545. static void UpdatePane ( winHandle win, Rect updateRect )
  1546. {
  1547.     PicHandle        pict ;
  1548.     Rect            paneRect,             paneUpdateRect ;
  1549.     Rect            pictRect,             pictUpdateRect ;
  1550.     Rect            pictRelPaneRect,    pictUpdateRelPaneRect ;
  1551.     WindowRef        window ;
  1552.     
  1553.     window = GetWinWindow( win ) ;
  1554.     pict = GetPictDocPict( win, kOriginal ) ;
  1555.     if (!pict) return ;                            // nothing to draw
  1556.  
  1557.     paneRect = GetPictDocPaneRect( win ) ;
  1558.     pictRect = GetPictDocPictRect( win ) ;        // check if ok?
  1559.  
  1560.     if (SectRect(&paneRect,&updateRect,&paneUpdateRect))
  1561.     {
  1562.         short    HorzDelta, VertDelta ;
  1563.  
  1564.         HorzDelta = GetPictDocCntlValue(win,rPictDocHorzScrollID) * kScrollDelta
  1565.                     + pictRect.left 
  1566.                     - kMargin 
  1567.                     - paneRect.left;
  1568.                     
  1569.         VertDelta = GetPictDocCntlValue(win,rPictDocVertScrollID) * kScrollDelta
  1570.                     + pictRect.top 
  1571.                     - kMargin 
  1572.                     - paneRect.top;
  1573.         
  1574.         // pictRelPaneRect = pictRect in the pane's coords            
  1575.         pictRelPaneRect = pictRect ;
  1576.         OffsetRect( &pictRelPaneRect, -HorzDelta, -VertDelta ) ;
  1577.         
  1578.         // erase the pane first
  1579.         BackColor( whiteColor ) ;
  1580.         EraseRect( &paneRect ) ;
  1581.     
  1582.         // Draw the pict into the pane 
  1583.         if (SectRect(&pictRelPaneRect,&paneUpdateRect,&pictUpdateRelPaneRect))
  1584.         {
  1585.             pictUpdateRect = pictUpdateRelPaneRect ;
  1586.             OffsetRect( &pictUpdateRect, HorzDelta, VertDelta ) ;
  1587.             DoDrawPictData( win, (GrafPtr)window, &pictUpdateRect, &pictUpdateRelPaneRect ) ;
  1588.         }
  1589.     
  1590.         // Draw gray crop marks (always)
  1591.         if (true)
  1592.         {
  1593.             Rect            temp ;
  1594.             RgnHandle        saveRgn = NewRgn() ;
  1595.             
  1596.             GetClip( saveRgn ) ;
  1597.             ClipRect( &paneRect ) ;
  1598.             
  1599.             temp = pictRelPaneRect ;
  1600.             temp.top -=1 ;
  1601.             temp.left -=1 ;
  1602.             
  1603.             RGBForeColor( &mdGray ) ;
  1604.             
  1605.             MoveTo( temp.left-8, temp.top   ) ;
  1606.             LineTo( temp.left,   temp.top   ) ;
  1607.             LineTo( temp.left,   temp.top-8 ) ;
  1608.             
  1609.             MoveTo( temp.left-8, temp.bottom   ) ;
  1610.             LineTo( temp.left,   temp.bottom   ) ;
  1611.             LineTo( temp.left,   temp.bottom+8 ) ;
  1612.             
  1613.             MoveTo( temp.right+8, temp.bottom   ) ;
  1614.             LineTo( temp.right,   temp.bottom   ) ;
  1615.             LineTo( temp.right,   temp.bottom+8 ) ;
  1616.             
  1617.             MoveTo( temp.right+8, temp.top   ) ;
  1618.             LineTo( temp.right,   temp.top   ) ;
  1619.             LineTo( temp.right,   temp.top-8 ) ;
  1620.         
  1621.             SetClip( saveRgn ) ;
  1622.             DisposeRgn( saveRgn ) ;
  1623.         }
  1624.     }
  1625. }
  1626.  
  1627.  
  1628. /*------------------------------------------------------------------------------*\
  1629.     ScrollPane
  1630.  *------------------------------------------------------------------------------*
  1631. \*------------------------------------------------------------------------------*/
  1632. static void ScrollPane ( winHandle win, ControlHandle cntl, short oldCntlVal )
  1633. {
  1634.     short            newCntlVal ;
  1635.     short            distHorz=0, distVert=0 ;
  1636.     ControlHandle    hCtl, vCtl ;
  1637.     Rect            paneRect;
  1638.     GrafPtr            savedPort ;
  1639.     WindowRef        window ;
  1640.     
  1641.     newCntlVal = GetControlValue( cntl ) ;
  1642.     if ( newCntlVal != oldCntlVal )
  1643.     {
  1644.         RgnHandle        saveRgn = NewRgn() ;
  1645.         RgnHandle        updateRgn = NewRgn() ;
  1646.  
  1647.         hCtl = GetPictDocCntl( win, rPictDocHorzScrollID ) ;
  1648.         vCtl = GetPictDocCntl( win, rPictDocVertScrollID ) ;
  1649.  
  1650.         paneRect = GetPictDocPaneRect( win ) ;    // determine scrolling rect
  1651.         if (cntl==vCtl)
  1652.             distVert = (oldCntlVal-newCntlVal)*kScrollDelta ;
  1653.         if (cntl==hCtl)
  1654.             distHorz = (oldCntlVal-newCntlVal)*kScrollDelta ;
  1655.         ScrollRect( &paneRect, distHorz, distVert, updateRgn) ;
  1656.     
  1657.         // instead of just calling InvalRgn here, we go through the 
  1658.         // trouble of adjusting the visRgn, calling UpdatePane, and
  1659.         // and restoring the original visRgn.  This way, the update 
  1660.         // is handled immediately instead of waiting for the next 
  1661.         // pass through the main event loop. This way, the app will
  1662.         // update correctly with CDEVs such as "Scrolling" which 
  1663.         // allow live scrolling.
  1664.  
  1665.         window = GetWinWindow( win ) ;
  1666.         GetPort( &savedPort ) ;    
  1667.         SetPort( (GrafPtr)window ) ;
  1668.  
  1669.         CopyRgn( ((CGrafPtr)window)->visRgn, saveRgn ) ;
  1670.         SectRgn( ((CGrafPtr)window)->visRgn, updateRgn,
  1671.                  ((CGrafPtr)window)->visRgn);
  1672.                  
  1673.         UpdatePane( win, (**updateRgn).rgnBBox ) ;
  1674.  
  1675.         CopyRgn( saveRgn, ((CGrafPtr)window)->visRgn ) ;
  1676.         
  1677.         SetPort( savedPort ) ;
  1678.         DisposeRgn( saveRgn ) ;
  1679.         DisposeRgn( updateRgn ) ;
  1680.     }
  1681. }
  1682.  
  1683.  
  1684.  
  1685. static void UpdatePict ( winHandle win, short which )
  1686. {
  1687.     CMError        cmerr ;
  1688.     PicHandle    pictNew ;
  1689.     PicHandle    pictOrig ;
  1690.     long        ticks ;
  1691.     Boolean        needsUpdate ;
  1692.     
  1693.     if (which==kOriginal) return ;
  1694.     if (which>=kDrwMchdPct) return ;
  1695.     
  1696.     needsUpdate = GetPictDocNeedsUpdate( win, which ) ;
  1697.     pictNew = GetPictDocPict( win, which ) ;
  1698.     
  1699.     //if ( (needsUpdate==false) && (pictNew!=nil) ) return;
  1700.     if ( needsUpdate==false ) return;
  1701.  
  1702.     if (pictNew)
  1703.         DisposeHandle( (Handle)pictNew ) ;
  1704.     
  1705.     SetUpCursors( kCSyncACursor ) ;
  1706.     
  1707.     pictOrig = GetPictDocPict(win,kOriginal) ;
  1708.     
  1709.     ticks = TickCount() ;
  1710.  
  1711.     switch (which)
  1712.     {
  1713.         case kMatched :
  1714.             cmerr = MatchPicHandle(
  1715.                         pictOrig, &pictNew,
  1716.                         GetPictDocProfile( win, kSrceProf ),
  1717.                         GetPictDocProfile( win, kPrevProf ) ) ;
  1718.             break;
  1719.         case kProofed :
  1720.             cmerr = ProofPicHandle(
  1721.                         pictOrig, &pictNew,
  1722.                         GetPictDocProfile( win, kSrceProf ),
  1723.                         GetPictDocProfile( win, kDestProf ),
  1724.                         GetPictDocProfile( win, kPrevProf ) ) ;
  1725.             break;
  1726.         case kChecked :
  1727.             cmerr = CheckPicHandle(
  1728.                         pictOrig, &pictNew,
  1729.                         GetPictDocProfile( win, kSrceProf ),
  1730.                         GetPictDocProfile( win, kDestProf ) ) ;
  1731.             break;
  1732.     }
  1733.                             
  1734.     ticks = TickCount() - ticks;                         
  1735.  
  1736.     TearDownCursors( kArrowCursor ) ;
  1737.  
  1738.     if (cmerr)
  1739.     {
  1740.         ticks = 0 ;
  1741.         WarnIfErr( cmerr ) ;
  1742.     }
  1743.     
  1744.     SetPictDocDrawTime( win, which, ticks ) ;
  1745.     SetPictDocPict( win, which, pictNew ) ;
  1746.     SetPictDocNeedsUpdate( win, which, false ) ;
  1747. }
  1748.  
  1749.  
  1750. static void ChangeCSOnOff ( winHandle win )
  1751. {
  1752.     Rect            rect;
  1753.     short            val;
  1754.     
  1755.     val = GetPictDocCntlValue( win, rPictDocMatchOnOffID ) ;
  1756.     SetPictDocCntlValue( win, rPictDocMatchOnOffID, !val ) ;
  1757.     
  1758.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  1759.     rect = GetPictDocPaneRect( win ) ;
  1760.     rect.bottom += kScrollWidth ;            // inval status rect
  1761.     InvalRect( &rect ) ;
  1762. }
  1763.  
  1764.  
  1765. static void ChangeCSMode ( winHandle win )
  1766. {
  1767.     Rect            rect;
  1768.     short            which;
  1769.     
  1770.     which = GetPictDocCntlValue( win, rPictDocMatchPopupID ) ;
  1771.     if ( GetPictDocPict(win,which) == nil )
  1772.         if ( GetPictDocNeedsUpdate(win,which) == false )
  1773.             SetPictDocNeedsUpdate( win, which, true) ;
  1774.             
  1775.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  1776.     rect = GetPictDocPaneRect( win ) ;
  1777.     rect.bottom += kScrollWidth ;            // inval status rect
  1778.     InvalRect( &rect ) ;
  1779. }
  1780.  
  1781.  
  1782. /*------------------------------------------------------------------------------*\
  1783.     SetWinContentColor
  1784.  *------------------------------------------------------------------------------*
  1785. \*------------------------------------------------------------------------------*/
  1786. static Boolean    SetWinContentColor ( WindowRef window, RGBColor theColor ) 
  1787. {
  1788. #if STRICT_WINDOWS
  1789.  
  1790.     return false ;
  1791.     
  1792. #else
  1793.  
  1794.     Boolean            hasAuxWinRec ;
  1795.     CTabHandle        ctab ;
  1796.     short            count ;
  1797.     short            i ;
  1798.     AuxWinHandle    awh ;
  1799.     
  1800.     hasAuxWinRec = GetAuxWin( window, &awh ) ;
  1801.     if (hasAuxWinRec)
  1802.     {
  1803.         ctab = (**awh).awCTable ;
  1804.         count = (**ctab).ctSize ;
  1805.         
  1806.         for (i=0; i<count; i++)
  1807.             if ( (**ctab).ctTable[i].value == 0 )
  1808.                  (**ctab).ctTable[i].rgb = theColor ;
  1809.     }
  1810.     return hasAuxWinRec ;
  1811.     
  1812. #endif
  1813. }
  1814.  
  1815.  
  1816. /*------------------------------------------------------------------------------*\
  1817.     GetProfileFromFront
  1818.  *------------------------------------------------------------------------------*
  1819. \*------------------------------------------------------------------------------*/
  1820. static OSErr GetProfileFromFront ( CMProfileRef *prof )
  1821. {
  1822.     winHandle    frontWin;
  1823.     OSErr        err = noErr ;
  1824.     OSType        type, subtype ;
  1825.     CMProfileRef tempprof ;
  1826.         
  1827.     *prof = nil ;
  1828.     
  1829.     frontWin = GetFrontWindowWinHandle() ;
  1830.     if (!frontWin) return paramErr ;
  1831.     
  1832.     type = GetWinType( frontWin ) ;
  1833.     subtype = GetWinSubtype( frontWin ) ;
  1834.     
  1835.     if ( type==kProfileType )
  1836.     {
  1837.         if ( subtype==kFileSubType || subtype==kEmbededSubType )
  1838.         {
  1839.             tempprof = GetProfileRef(frontWin) ;
  1840.             err = ReOpenProfileRef ( prof, tempprof ) ;
  1841.         } 
  1842.         else if ( subtype==kSysProfSubType )
  1843.             *prof = nil ;
  1844.         else
  1845.             err = paramErr ;
  1846.     }
  1847.     else if ( type==kProfListType )
  1848.     {
  1849.         ListHandle            list ;
  1850.         Cell                cell = {0,0} ;
  1851.         CMProfileSearchRef    search ;
  1852.         
  1853.         list = GetProfListList( frontWin ) ;
  1854.         if ( list && LGetSelect(true, &cell, list))
  1855.         {
  1856.             search = GetProfListSearchResult( frontWin ) ;
  1857.             err = CMSearchGetIndProfile( search, cell.v+1, prof ) ;
  1858.         }
  1859.         else
  1860.             err = paramErr ;
  1861.     }
  1862.     else
  1863.         err = paramErr ;
  1864.     
  1865.     return err; 
  1866. }
  1867.  
  1868.  
  1869. /*------------------------------------------------------------------------------*\
  1870.     GetProfIDFromFront
  1871.  *------------------------------------------------------------------------------*
  1872. \*------------------------------------------------------------------------------*/
  1873. static OSErr GetProfIDFromFront ( CMProfileIdentifierHdl *IDHdl )
  1874. {
  1875.     winHandle    frontWin;
  1876.     OSErr        err = noErr ;
  1877.     OSType        type ;
  1878.         
  1879.     frontWin = GetFrontWindowWinHandle() ;
  1880.     if (!frontWin) return paramErr ;
  1881.     
  1882.     type = GetWinType( frontWin ) ;
  1883.     
  1884.     if ( type==kProfIDType )
  1885.     {
  1886.         *IDHdl = GetProfIDIDHdl( frontWin ) ;
  1887.     }
  1888.     else
  1889.         err = paramErr ;
  1890.     
  1891.     return err; 
  1892. }
  1893.  
  1894.  
  1895.  
  1896. /*------------------------------------------------------------------------------*\
  1897.     DoChangeProfile
  1898.  *------------------------------------------------------------------------------*
  1899. \*------------------------------------------------------------------------------*/
  1900. static void DoChangeProfile ( winHandle win, short which, CMProfileRef prof )
  1901. {    
  1902.     CMError                err ;
  1903.     CMProfileRef        oldProf, newProf ;
  1904.     Rect                rect;
  1905.     
  1906.     oldProf = GetPictDocProfile( win, which ) ;
  1907.     
  1908.     if (oldProf == prof) return ;                // this may not be wize ??
  1909.  
  1910.     // close old profile if !=nil
  1911.     err = CMCloseProfile( oldProf ) ;
  1912.  
  1913.     // reopen profile
  1914.     err = ReOpenProfileRef( &newProf, prof ) ;
  1915.     if ( err ) return ;
  1916.     
  1917.     SetPictDocProfile ( win, which, newProf ) ;
  1918.         
  1919.     // update matched pict and force update
  1920.     if (which != kDestProf)
  1921.         SetPictDocNeedsUpdate( win, kMatched, true ) ;
  1922.     SetPictDocNeedsUpdate( win, kProofed, true ) ;
  1923.     if (which != kPrevProf)
  1924.         SetPictDocNeedsUpdate( win, kChecked, true ) ;
  1925.     
  1926.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  1927.     rect = GetWinRect( win ) ;
  1928.     //if ( GetPictDocCntlValue(win,rPictDocMatchOnOffID) )
  1929.     // rect = header rect
  1930.     InvalRect( &rect ) ;
  1931. }
  1932.  
  1933. static void DoChangeProfileFromFront ( winHandle win, short which )
  1934. {
  1935.     CMProfileRef prof;
  1936.     
  1937.     if ( GetProfileFromFront(&prof)==noErr )
  1938.     {
  1939.         DoChangeProfile( win, which, prof ) ;
  1940.         if (prof) CMCloseProfile(prof);
  1941.     }
  1942. }
  1943.  
  1944.  
  1945. /*------------------------------------------------------------------------------*\
  1946.     DoAddEmbdProf
  1947.  *------------------------------------------------------------------------------*
  1948. \*------------------------------------------------------------------------------*/
  1949. static OSErr DoAddEmbdProf ( winHandle win, CMProfileRef prof, unsigned long flags )
  1950. {
  1951.     PicHandle    pictOld, pictNew ;
  1952.     OSErr        err = noErr ;
  1953.     
  1954.     if (prof==nil) return paramErr ;
  1955.  
  1956.     pictOld = GetPictDocPict( win, kOriginal ) ;
  1957.     err = PrependProfileToPicHandle( pictOld, &pictNew, prof, flags ) ;
  1958.     if (err) return err ;
  1959.  
  1960.     DoChangePict( win, pictNew ) ;
  1961.     return noErr ;
  1962. }
  1963.  
  1964. static OSErr DoAddEmbdProfID ( winHandle win, CMProfileIdentifierHdl IDHdl )
  1965. {
  1966.     PicHandle    pictOld, pictNew ;
  1967.     OSErr        err = noErr ;
  1968.     
  1969.     if (IDHdl==nil) return paramErr ;
  1970.  
  1971.     pictOld = GetPictDocPict( win, kOriginal ) ;
  1972.     HLock( (Handle)IDHdl );
  1973.     err = PrependProfileIdentToPicHandle ( pictOld, &pictNew, *IDHdl ) ;
  1974.     HUnlock( (Handle)IDHdl );
  1975.     if (err) return err ;
  1976.  
  1977.     DoChangePict( win, pictNew ) ;
  1978.     return noErr ;
  1979. }
  1980.  
  1981. static void DoAddEmbdProfFromFront ( winHandle win, unsigned long flags )
  1982. {
  1983.     CMProfileRef prof;
  1984.     CMProfileIdentifierHdl IDHdl;
  1985.  
  1986.     if ( GetProfileFromFront( &prof )==noErr )
  1987.     {
  1988.         (void) DoAddEmbdProf( win, prof, flags ) ;
  1989.         if (prof) CMCloseProfile(prof);
  1990.     }
  1991.     else if ( GetProfIDFromFront(&IDHdl)==noErr && flags==cmEmbedProfileIdentifier )
  1992.         (void) DoAddEmbdProfID( win, IDHdl ) ;
  1993. }
  1994.  
  1995.  
  1996.  
  1997. /*------------------------------------------------------------------------------*\
  1998.     SaveCmndPictDoc
  1999.  *------------------------------------------------------------------------------*
  2000. \*------------------------------------------------------------------------------*/
  2001. static void SaveCmndPictDoc ( winHandle win ) 
  2002. {
  2003.     FSSpec                spec ;
  2004.     Boolean                dirty ;
  2005.     Boolean                hasFile ;
  2006.     OSErr                err ;
  2007.     
  2008.     spec = GetWinFSSpec( win ) ;
  2009.     dirty = GetWinDirty( win ) ;
  2010.     hasFile = ( spec.name[0] > 0 ) ;
  2011.  
  2012.     if ( !dirty ) return;                // no need to save
  2013.     
  2014.     if ( !hasFile )
  2015.         SaveAsCmndPictDoc( win ) ;
  2016.     else
  2017.     {
  2018.         err = DoWritePICT( spec, GetPictDocPict(win,kOriginal), kCreatorType ) ;
  2019.         if (err) return ;                // if err, should do something
  2020.         SetWinDirty( win, false ) ;
  2021.         DoAppAdjustMenus() ;            // undim app items
  2022.     }
  2023. }
  2024.  
  2025.  
  2026. /*------------------------------------------------------------------------------*\
  2027.     SaveAsCmndPictDoc
  2028.  *------------------------------------------------------------------------------*
  2029. \*------------------------------------------------------------------------------*/
  2030. static void SaveAsCmndPictDoc ( winHandle win ) 
  2031. {
  2032.     FSSpec                spec ;
  2033.     Boolean                dirty ;
  2034.     Boolean                hasFile ;
  2035.     StandardFileReply    reply ;
  2036.     OSErr                err ;
  2037.     WindowRef            window ;
  2038.     Str255                title ;
  2039.     
  2040.     spec = GetWinFSSpec( win ) ;
  2041.     dirty = GetWinDirty( win ) ;
  2042.     hasFile = ( spec.name[0] > 0 ) ;
  2043.     window = GetWinWindow( win ) ;
  2044.     
  2045.     if ( hasFile )
  2046.         StringToString( spec.name, title ) ;
  2047.     else
  2048.         GetWTitle( window, title ) ;
  2049.     
  2050.     StandardPutFile( "\pSave PICT as:", title, &reply) ;
  2051.     if ( reply.sfGood )
  2052.     {
  2053.         spec = reply.sfFile ;
  2054.         err = DoWritePICT ( spec, GetPictDocPict(win,kOriginal), kCreatorType ) ;
  2055.         WarnIfErr( err ) ;
  2056.         if ( err ) return ;                    // if err, should do something 
  2057.         SetWinFSSpec( win, &spec ) ;        // win's spec = new spec
  2058.         SetWTitle( window, spec.name ) ;    // win title = new title
  2059.         SetWinDirty( win, false ) ;
  2060.         DoAppAdjustMenus() ;                // undim app items
  2061.     }
  2062. }
  2063.  
  2064.  
  2065. /*------------------------------------------------------------------------------*\
  2066.     RevertCmndPictDoc
  2067.  *------------------------------------------------------------------------------*
  2068. \*------------------------------------------------------------------------------*/
  2069. static void RevertCmndPictDoc ( winHandle win ) 
  2070. {    
  2071.     FSSpec                spec ;
  2072.     Boolean                dirty ;
  2073.     Boolean                hasFile ;
  2074.  
  2075.     spec = GetWinFSSpec( win ) ;
  2076.     dirty = GetWinDirty( win ) ;
  2077.     hasFile = ( spec.name[0] > 0 ) ;
  2078.     
  2079.     if ( !dirty || !hasFile ) return ;
  2080.         
  2081.                                     // ask user if it's ok
  2082.     
  2083.     SetWinDirty( win, false ) ;        // clear dirty so we don't get another dialog
  2084.     CallWinCloseProc( win ) ;        // close the document
  2085.     SendODOC( &spec ) ;                // reopen: send ODOC event to ourselves:
  2086. //    DoAppAdjustMenus() ;            // undim app items
  2087. }
  2088.  
  2089.  
  2090. /*------------------------------------------------------------------------------*\
  2091.     PasteCmndPictDoc
  2092.  *------------------------------------------------------------------------------*
  2093. \*------------------------------------------------------------------------------*/
  2094. static void PasteCmndPictDoc ( winHandle win ) 
  2095. {    
  2096.     Boolean            pictOnScrap ;
  2097.     PicHandle        pict ;
  2098.     long            scrapOffset, length ;
  2099.     
  2100.     length = GetScrap( nil, 'PICT', &scrapOffset ) ;
  2101.     pictOnScrap = ( length > 0 ) ;
  2102.     if ( pictOnScrap == false ) return ;
  2103.     
  2104.     pict = (PicHandle) NewHandle( 0 ) ;        // allocate 0-length data area 
  2105.     length = GetScrap( (Handle)pict, 'PICT', &scrapOffset ) ;
  2106.  
  2107.     if ( length<0 )
  2108.         WarnIfErr( length ) ;
  2109.     else
  2110.         DoChangePict( win, pict ) ; 
  2111. }
  2112.  
  2113.  
  2114. /*------------------------------------------------------------------------------*\
  2115.     DoChangePict
  2116.  *------------------------------------------------------------------------------*
  2117. \*------------------------------------------------------------------------------*/
  2118. static void DoChangePict ( winHandle win, PicHandle pict ) 
  2119. {    
  2120.     PicHandle        oldPict ;
  2121.     Rect            rect, pictRect, sizeRect ;
  2122.     OSErr            err ;
  2123.     short            h,v ;
  2124.     WindowRef        window ;
  2125.     //PaletteHandle    palette ;
  2126.     ListHandle        profList ;
  2127.     
  2128.     oldPict = GetPictDocPict( win, kOriginal ) ;
  2129.     if ( oldPict )        // if there an existing pict
  2130.     {
  2131.         // ask user if it's ok
  2132.     }
  2133.     
  2134.     CallWinDisposeProc( win ) ;
  2135.     CallWinAllocProc( win ) ;
  2136.  
  2137.     // set the window's rect
  2138.     pictRect = (**pict).picFrame ;
  2139.     SetPictDocPictRect( win, pictRect ) ;
  2140.  
  2141.     // set the window's data's pict
  2142.     SetPictDocPict( win, kOriginal, pict ) ;
  2143.     SetPictDocNeedsUpdate( win, kMatched, true ) ;
  2144.     SetPictDocNeedsUpdate( win, kProofed, true ) ;
  2145.     SetPictDocNeedsUpdate( win, kChecked, true ) ;
  2146.     
  2147. //    err = DoCreatePalettes( win ) ;
  2148. //    if ( err ) return ;
  2149.         
  2150.     h = pictRect.right - pictRect.left ;
  2151.     v = pictRect.bottom - pictRect.top ;
  2152.     h += kScrollWidth + kMargin + kMargin ;
  2153.     v += kScrollWidth + kMargin + kMargin + kHeaderHeightBig ;
  2154.     h = MAX(h, kWindowWidthMin) ;
  2155.     v = MAX(v, kWindowHeightMin+kHeaderHeightBig) ;
  2156.  
  2157.     window = GetWinWindow( win ) ;
  2158.     SetPort( (GrafPtr)window ) ;
  2159.     SizeWindow(    window, h, v, false) ;        // we'll update everything later
  2160.  
  2161.     SetRect( &sizeRect, kWindowWidthMin,
  2162.                         kWindowHeightMin+kHeaderHeightBig,
  2163.                         h+1,v+1) ;
  2164.     SetWinSizeRect( win, sizeRect ) ;
  2165.     
  2166.     // try to make list of embeded profiles
  2167.     profList = BuildProfList( win ) ;
  2168.  
  2169.     // set up drag&drop zones
  2170.     err = DoCreateDragZones( win ) ;
  2171.     if (err) return ;//err ;                    // we should dispose window before returning
  2172.  
  2173.     // set up scroll bars
  2174.     SetPictDocCntl( win, rPictDocHorzScrollID, GetNewControl(rPictDocHorzScrollID, window ) ) ;
  2175.     SetPictDocCntl( win, rPictDocVertScrollID, GetNewControl(rPictDocVertScrollID, window ) ) ;
  2176.     SetPictDocCntl( win, rPictDocMatchOnOffID, GetNewControl(rPictDocMatchOnOffID, window ) ) ;
  2177.     SetPictDocCntl( win, rPictDocMatchPopupID, GetNewControl(rPictDocMatchPopupID, window ) ) ;
  2178.     CallWinResizeProc( win ) ;
  2179.  
  2180.     // and if we set up the palette earlier assign it to the window                
  2181.     //    palette = GetPictDocPalette( win ) ;
  2182.     //    if( palette != nil )
  2183.     //        SetPalette ( window, palette, true ) ;
  2184.     //    ActivatePalette ( window ) ;    
  2185.  
  2186.     rect = GetWinRect( win ) ;
  2187.     InvalRect( &rect ) ;                            // force window redraw
  2188.     SetWinDirty( win, true ) ;
  2189.     DoAppAdjustMenus() ;                            // undim app items
  2190. }
  2191.  
  2192.  
  2193. /*------------------------------------------------------------------------------*\
  2194.     DoDragPict
  2195.  *------------------------------------------------------------------------------*
  2196. \*------------------------------------------------------------------------------*/
  2197. static OSErr DoDragPict ( winHandle win, EventRecord *e, Rect hiliteRect )
  2198. {
  2199.     short                result;
  2200.     RgnHandle            dragRegion ;
  2201.     Point                theLoc = {0,0};
  2202.     DragReference        theDrag;
  2203.     AEDesc                dropLocation;
  2204.     DragAttributes        attributes;
  2205.     short                mouseDownModifiers, mouseUpModifiers, copyText;
  2206.     DragSendDataUPP        myDragSendDataUPP ;
  2207.  
  2208.     if ( win == nil )
  2209.         return paramErr ;
  2210.         
  2211.     dragRegion = NewRgn() ;
  2212.     RectRgn(dragRegion,&hiliteRect) ;
  2213.     LocalToGlobal(&theLoc) ;
  2214.     OffsetRgn( dragRegion, theLoc.h, theLoc.v ) ;
  2215.     
  2216.     //    Wait for the mouse to move to the mouse button to be released.
  2217.     //    If the mouse button was released before the mouse moves, return.
  2218.     if (! WaitMouseMoved(e->where)) 
  2219.         return noErr ;            // should return something to indicate no drag occured
  2220.     
  2221.     // create a new reference for a track to pass to track drag
  2222.     NewDrag(&theDrag) ;
  2223.     
  2224.     //    We promise  'PICT'.  If a receiver requests either, the Drag Manager
  2225.     //    will call our MyDragSendDataProc to provide the data at drop time. The MyDragSendDataProc
  2226.     //    is specified by calling SetDragSendProc.
  2227.     AddDragItemFlavor( theDrag, 1, 'PICT', nil, 0L, 0L) ;
  2228.     myDragSendDataUPP = NewDragSendDataProc( MyDragSendDataProc ) ;
  2229.     SetDragSendProc( theDrag, myDragSendDataUPP, (void *)win ) ;
  2230.     
  2231.     //    Set the item's bounding rectangle in global coordinates.
  2232.     SetDragItemBounds(theDrag, 1, &(**dragRegion).rgnBBox) ;
  2233.     
  2234.     //    Prepare the drag region.
  2235.     (void) OutlineRegion( dragRegion ) ;
  2236.     
  2237.     //    Drag the stuff. TrackDrag will return userCanceledErr if the drop zoomed-back for any reason.
  2238.     result = TrackDrag(theDrag, e, dragRegion) ;
  2239.         
  2240.     // get rid of the UPP
  2241.     DisposeRoutineDescriptor( myDragSendDataUPP ) ;
  2242.     
  2243.     if (result != noErr && result != userCanceledErr)
  2244.         return result ;
  2245.     
  2246.     //    Check to see if the drop occurred in the Finder's Trash. If the drop occurred
  2247.     //    in the Finder's Trash and a copy operation wasn't specified, delete the
  2248.     //    source selection. Note that we can continute to get the attributes, drop location
  2249.     //    modifiers, etc. of the drag until we dispose of it using DisposeDrag.
  2250.     GetDragAttributes(theDrag, &attributes) ;
  2251.     if (!(attributes & dragInsideSenderApplication))
  2252.     {
  2253.         GetDropLocation(theDrag, &dropLocation) ;
  2254.         GetDragModifiers(theDrag, 0L, &mouseDownModifiers, &mouseUpModifiers) ;
  2255.         copyText = (mouseDownModifiers | mouseUpModifiers) & optionKey;
  2256.  
  2257.         if ( !copyText && DropLocationIsFinderTrash(theDrag) )
  2258.         {
  2259.         }
  2260.         AEDisposeDesc(&dropLocation) ;
  2261.     }
  2262.  
  2263.     //    Dispose of the drag.
  2264.     DisposeDrag(theDrag) ;
  2265.     DisposeRgn(dragRegion) ;
  2266.     
  2267.     return noErr ;
  2268. }
  2269.  
  2270.  
  2271. /*------------------------------------------------------------------------------*\
  2272.     MyDragSendDataProc
  2273.  *------------------------------------------------------------------------------*
  2274. \*------------------------------------------------------------------------------*/
  2275. static pascal OSErr MyDragSendDataProc ( FlavorType theDragFlavor, void *refCon,
  2276.                             ItemReference theItem, DragReference theDrag)
  2277.  
  2278. {
  2279.     winHandle    win=nil ;
  2280.     Handle        pict=nil ;
  2281.     OSErr        err=noErr ;
  2282.  
  2283.     // so what do they want??
  2284.     if ( theDragFlavor == 'PICT' )
  2285.     {
  2286.             win = (winHandle) refCon ;
  2287.             pict = (Handle)GetPictDocPict( win, kOriginal ) ;
  2288.             HLock(pict) ;
  2289.             SetDragItemFlavorData(    theDrag,
  2290.                                     theItem,
  2291.                                     'PICT',
  2292.                                     (Ptr) *pict,
  2293.                                     GetHandleSize(pict),
  2294.                                     0L ) ;
  2295.     }  
  2296.     else
  2297.         return badDragFlavorErr ;
  2298.     return noErr ;
  2299. }
  2300.  
  2301.  
  2302. /*------------------------------------------------------------------------------*\
  2303.     MyDragZoneRecvCallback
  2304.  *------------------------------------------------------------------------------*
  2305. \*------------------------------------------------------------------------------*/
  2306. static pascal OSErr MyDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow,
  2307.                                 Point theLocation, Handle dataHdl )
  2308. {
  2309.     winHandle    win=nil ;
  2310.     Handle        pict=nil ;
  2311.     OSErr        err=noErr ;
  2312.     FlavorType    theDragFlavor ;
  2313.     
  2314.     win = GetWindowWinHandle( theWindow ) ;
  2315.     theDragFlavor = (**theZone).flavor ;
  2316.     
  2317.     if ( theDragFlavor=='PICT')
  2318.     {
  2319.         pict = dataHdl ;
  2320.         err = HandToHand( &pict ) ;
  2321.     }
  2322.     else if( theDragFlavor==flavorTypeHFS ) // do this on receipt of an HFS flavor (a file from the finder)
  2323.     {
  2324.         HFSFlavor theHFSFlavor ;
  2325.         HLock( dataHdl ) ;
  2326.         theHFSFlavor = *((HFSFlavor *)*dataHdl) ;
  2327.         if ( theHFSFlavor.fileType == 'PICT' ) // get the picture from the file
  2328.             err = DoReadPICT( theHFSFlavor.fileSpec, (PicHandle*)&pict )  ;
  2329.     }
  2330.     if ( win && pict && !err )
  2331.         DoChangePict( win, (PicHandle)pict ) ;
  2332.  
  2333.     return err ;
  2334. }
  2335.  
  2336.  
  2337. /*------------------------------------------------------------------------------*\
  2338.     MyProfDragZoneRecvCallback
  2339.  *------------------------------------------------------------------------------*
  2340. \*------------------------------------------------------------------------------*/
  2341. static pascal OSErr MyProfDragZoneRecvCallback ( DragZoneHdl theZone, WindowRef theWindow,
  2342.                                 Point theLocation, Handle dataHdl )
  2343. {
  2344.     winHandle        win=nil ;
  2345.     OSErr            err=noErr ;
  2346.     FSSpec            spec ;
  2347.     CMProfileRef    prof ;
  2348.     short            which ;
  2349.     
  2350.     win = GetWindowWinHandle( theWindow ) ;
  2351.     spec = ((HFSFlavor *)*dataHdl)->fileSpec ;
  2352.     
  2353.     err = OpenProfileFSSpec( spec, &prof ) ;
  2354.     which = (short)((**theZone).zoneRefCon) ;
  2355.     
  2356.     if ( win && prof && !err )
  2357.     {
  2358.         switch (which)
  2359.         {
  2360.             case kSrceProf :
  2361.             case kDestProf :
  2362.             case kPrevProf :
  2363.                 DoChangeProfile( win, which, prof ) ;
  2364.                 break ;
  2365.             case kEmbedProfs :
  2366.                 err = DoAddEmbdProf( win, prof, cmEmbedWholeProfile ) ;
  2367.                 break ;
  2368.  
  2369.         }
  2370.     }
  2371.     return err ;
  2372. }
  2373.