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