home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 33.6 KB | 1,167 lines | [TEXT/CWIE] |
- // A profile window
- //
- // David Hayward
- // Developer Technical Support
- // AppleLink: DEVSUPPORT
- //
- // Copyrite 1995, Apple Computer,Inc
- //
- // This file contains the menus routines for a profile window.
- //
- // 12/13/94 david first cut
-
-
- #include <QuickDraw.h>
- #include <Icons.h>
- #include <Fonts.h>
- #include <LowMem.h>
- #include <Files.h>
- #include <TextUtils.h>
- #include <QDOffScreen.h>
- #include <Resources.h>
- #include <StandardFile.h>
-
- #include "appGlobals.h"
- #include "appMain.h"
- #include "appMenus.h"
- #include "appErrors.h"
- #include "appAEvts.h"
-
- #include "win.h"
- #include "winTables.h"
- #include "winProfile.h"
- #include "winProfileGetSet.h"
- #include "winProfID.h"
- #include "winProfIDGetSet.h"
- #include "winProfList.h"
- #include "winProfListGetSet.h"
-
- #include "stringUtils.h"
- #include "colorsyncUtils.h"
- #include "resourceUtils.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE TYPEDEFS
- |**| ==============================================================================
- \**/
- typedef struct FlagList
- {
- short count ; // 1-based count of structs to follow
- struct
- {
- short shift ; // bits to shift over
- short mask ; // bits to then mask over
- short value ; // resulting value
- Str27 string ;
- } entry[];
- } FlagList, *FlagListPtr, **FlagListHdl ;
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE DEFINES
- |**| ==============================================================================
- \**/
- #define rProfileWindID 1000 // 'WIND' resource id
- #define rProfileLabelsStringID 1000 // 'STR ' resource id
- #define rProfileVarsStringID 1001 // 'STR ' resource id
- #define rProfileWhereVarStringID 1002 // 'STR ' resource id
- #define rProfileIconID 1003 // icon family resource id
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- void DoDrawProfData ( winHandle win ) ;
- void MungeProfileHeader1 ( CMProfileRef prof, Handle text ) ;
- void MungeProfileHeader2 ( CMProfileRef prof, Handle text ) ;
- OSErr RendIntent2String ( unsigned long intent, StringPtr dest ) ;
- OSErr ColorSpace2String ( OSType spaceType, StringPtr dest ) ;
- OSErr ProfileClass2String ( OSType classType, StringPtr dest ) ;
- OSErr DoCreateProfWindow ( winHandle win ) ;
- void ProfMakeSysProfileCmnd ( winHandle win ) ;
- void ProfCreateProfIDCmnd ( winHandle win ) ;
- void SaveCmndProfile ( winHandle win ) ;
- void SaveAsCmndProfile ( winHandle win ) ;
- void RevertCmndProfile ( winHandle win ) ;
- long PopUpMenuSelectFont ( MenuHandle theMenu, short top, short left,
- short popUpItem, short font, short size) ;
- OSErr GetFlagListStringPtr ( short id, unsigned long flags, StringPtr dest ) ;
- OSErr BuildFlagListMenu ( short id, unsigned long flags, MenuHandle menu ) ;
- OSErr SetFlagFromMenuItem ( short id, unsigned long *flags, short mitem ) ;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateProfile
- *------------------------------------------------------------------------------*
- This is a UpdateProcPtr for Profile windows.
- It handles all drawing into the window.
- For ProfList windows, this means that this routine is responible for
- drawing the the basic CS1 and CS2 profile info into the window.
- This ProcPtr is envoked by CallWinUpdateProc() which is called by:
- DoUpdateEvent() which dispaches update events.
- \*------------------------------------------------------------------------------*/
- void winUpdateProfile ( winHandle win, EventRecord *e )
- {
- WindowRef window = (WindowRef)e->message;
- GrafPtr savedPort ;
-
- GetPort(&savedPort ) ;
- SetPort( (GrafPtr)window ) ;
-
- BeginUpdate( window ) ;
-
- DoDrawProfData( win ) ;
-
- // signal that we finished drawing
- EndUpdate( window ) ;
- SetPort( savedPort ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winClickProfile
- *------------------------------------------------------------------------------*
- This is a ClickProcPtr for Profile windows.
- So far, all this contains is a crude handling of the popup menus
- Other things, such as initiating a drag-and-drop should also go here
- This ProcPtr is envoked by CallWinClickProc() which is called by:
- DoMouseDownEvent() which dispaches mouse down events
- \*------------------------------------------------------------------------------*/
- void winClickProfile ( winHandle win, EventRecord *e )
- {
- CMError cmerr ;
- CMProfileRef prof;
- CMAppleProfileHeader head ;
- unsigned long vers ;
- unsigned long *flagPtr ;
- Point where ;
- Rect varsRect ;
-
- varsRect = GetRect ( rProfileVarsStringID ) ;
-
- // if in correct region
- where = e->where;
- GlobalToLocal(&where);
-
- if ( (where.h >= varsRect.left) && (where.h <= varsRect.left+8) )
- {
- short row, resID, mitem;
- long mresult;
- MenuHandle menu;
- Point mOrigin ;
-
- row = (where.v - varsRect.top) /12;
-
- if ( row>=14 && row<=17 )
- {
- prof = GetProfileRef( win );
-
- cmerr = CMGetProfileHeader(prof, &head) ;
- if (cmerr) return ;
-
- vers = head.cm2.profileVersion ;
-
- menu = NewMenu(5000,"\ppopup");
- InsertMenu(menu,-1);
-
- mOrigin.h = varsRect.left;
- mOrigin.v = varsRect.top + 12*row;
- LocalToGlobal(&mOrigin);
-
- flagPtr = nil;
-
- if (row==15 && vers>=cmCS2ProfileVersion) // CS2 Atrb1
- { flagPtr = &(head.cm2.deviceAttributes[1]) ;
- resID = 1001;
- }
- if (row==16 && vers>=cmCS2ProfileVersion) // CS2 Flags
- { flagPtr = &(head.cm2.flags) ;
- resID = 1002;
- }
- if (row==16 && vers<cmCS2ProfileVersion) // CS1 Flags
- { flagPtr = (unsigned long *)&(head.cm1.flags) ;
- resID = 1003;
- }
- if (row==17) // CS Intent
- { flagPtr = &(head.cm2.renderingIntent) ;
- resID = 1000;
- }
-
- if (flagPtr) cmerr = BuildFlagListMenu( resID, *flagPtr, menu ) ;
-
- if (flagPtr && !cmerr)
- {
- mresult = PopUpMenuSelectFont(menu,mOrigin.v,mOrigin.h,0, 3, 9);
- DeleteMenu((**menu).menuID);
- mitem = LoWord(mresult);
-
- cmerr = SetFlagFromMenuItem( resID, flagPtr, mitem ) ;
-
- if (!cmerr)
- {
- cmerr = CMSetProfileHeader(prof, &head) ;
- SetWinDirty( win, true ) ;
- InvalRect( &varsRect ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
- DisposeMenu(menu);
- }
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winCloseProfile
- *------------------------------------------------------------------------------*
- This is a CloseProcPtr for Profile windows.
- So far, all this does is call DisposeWinHandle()
- This win type doesn't need to be saved so ther is no reason to prompt the
- user to save the file here.
- This ProcPtr is envoked by CallWinCloseProc() which is called by:
- DoMouseDownEvent() which dispached click events (e.g. close box), and
- MenuProcPtrs which are called whenever menu events occur.
- \*------------------------------------------------------------------------------*/
- void winCloseProfile ( winHandle win )
- {
- DisposeWinHandle( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winMenuProfile
- *------------------------------------------------------------------------------*
- This is a MenuProcPtr for Profile windows.
- This routine dispatches any menu commands that the window can handle
- to the appropriate function.
- This ProcPtr is envoked by CallWinMenuProc() which is called by:
- HandleMenuCommand() which dispatches all menu events.
- \*------------------------------------------------------------------------------*/
- void winMenuProfile ( winHandle win, long menuResult, Boolean *didit )
- {
- short menuID;
- short menuItem;
-
- *didit = true ;
- menuID = HiWrd(menuResult) ;
- menuItem = LoWrd(menuResult) ;
- switch ( menuID )
- {
- case mFile:
- switch ( menuItem )
- {
- case iSave: // save this document under the name it was opened
- SaveCmndProfile( win ) ;
- break ;
- case iSaveAs: // save this document under a new name
- SaveAsCmndProfile( win ) ;
- break ;
- case iRevert: // discard all changes made to the document since it was last saved
- RevertCmndProfile( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- case mProfiles:
- switch ( menuItem )
- {
- case iSetDefaultProf:
- ProfMakeSysProfileCmnd( win ) ;
- break ;
- case iCreateProfID:
- ProfCreateProfIDCmnd( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- default :
- *didit = false ;
- break ;
- }
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- }
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateMenusProfile
- *------------------------------------------------------------------------------*
- This is a UpdateMenuProcPtr for Profile windows.
- This routine enables any menu commands that the window can handle.
- This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
- DoAppAdjustMenus() which dispatches all menu events.
- \*------------------------------------------------------------------------------*/
- void winUpdateMenusProfile ( winHandle win )
- {
- MenuHandle theMenu ;
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- OSType subtype ;
- winHandle frontWin;
-
- frontWin = GetFrontWindowWinHandle() ;
-
- if ( win == frontWin )
- {
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- subtype = GetWinSubtype( win ) ;
-
- // do the file menu
- theMenu = GetMenuHandle ( mFile ) ;
-
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iClose ) ;
- EnableItem ( theMenu, iSaveAs ) ;
-
- // for the next 2, check to see if the document has been changed
- if ( dirty && subtype==kFileSubType)
- EnableItem ( theMenu, iSave ) ;
- if ( dirty && subtype==kFileSubType && hasFile )
- EnableItem ( theMenu, iRevert ) ;
-
- // do the profiles menu
- theMenu = GetMenuHandle ( mProfiles ) ;
-
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iCreateProfID ) ;
- if ( subtype==kFileSubType )
- EnableItem ( theMenu, iSetDefaultProf ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winAllocProfile
- *------------------------------------------------------------------------------*
- This is a AllocProcPtr for Profile windows.
- This routine is responsible for filling in all the needed fields of the
- winHandle structure. This routine shouldn't be called directly.
- Instead, the code which needs to create a document of this type should
- call NewWinHandle(win,winAllocProfile) to envoke this function.
- This ProcPtr is envoked by NewWinHandle() which is called by:
- app_aeODOC_handler() which handles ODOC AppleEvents, and
- app_aePDOC_handler() which handles PDOC AppleEvents.
- \*------------------------------------------------------------------------------*/
- OSErr winAllocProfile ( winHandle win )
- {
- OSErr err = noErr ;
- ProfileDataHdl data ;
-
- // we need ColorSync 2.
- if (!CS2_available())
- return eWarnCantOpenFileNoColorSync2 ;
-
- // set the window type
- SetWinType( win, kProfileType ) ;
-
- // stuff winHandle fields
- SetWinUpdateProc ( win, (UpdateProcPtr) winUpdateProfile ) ;
- SetWinClickProc ( win, (ClickProcPtr) winClickProfile ) ;
- SetWinMenuProc ( win, (MenuProcPtr) winMenuProfile ) ;
- SetWinUpdateMenusProc ( win, (UpdateMenusProcPtr) winUpdateMenusProfile ) ;
- SetWinOpenProc ( win, (OpenProcPtr) winOpenProfile ) ;
- SetWinCloseProc ( win, (CloseProcPtr) winCloseProfile ) ;
- SetWinDisposeProc ( win, (DisposeProcPtr) winDisposeProfile ) ;
-
- // allocate data handle
- data = (ProfileDataHdl)NewHandleClear( sizeof(ProfileDataRec) ) ;
- if( data == nil ) return MemError() ;
- SetWinData( win, (Handle)data ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winOpenProfile
- *------------------------------------------------------------------------------*
- This is a OpenProcPtr for Profile windows.
- This routine is responsible for opening a Profile window after all the
- needed fields of the winHandle structure have been filled in by winAllocProfile.
- On entry the DocumentRecord must contain a valid FSSpec.
- If a Profile window for the FSSpec is already onen, then this routine
- will bring it to the front instead of opening a second window.
- This routine shouldn't be called directly. Instead, the code which needs
- to create a document of this type should call NewWinHandle(win,winAllocProfile),
- SetWinFSSpec (win,spec), and then CallWinOpenProc(win) to envoke this function.
- This ProcPtr is envoked by CallWinOpenProc() which is called by:
- app_aeODOC_handler() which handles ODOC AppleEvents, and
- app_aePDOC_handler() which handles PDOC AppleEvents.
- \*------------------------------------------------------------------------------*/
- OSErr winOpenProfile ( winHandle win )
- {
- OSErr err = noErr ;
- winHandle existingWin ;
- FSSpec spec ;
- CMProfileRef prof ;
- CMProfileLocation profLoc ;
- OSType subtype ; // this is the subtype of window ('file' 'embd' or 'sysp')
- unsigned long index ; // if embeded subtype then this tells us which one
- Boolean alreadyOpen = false;
- short count, i ;
-
- spec = GetWinFSSpec( win ) ;
- subtype = GetWinSubtype( win ) ;
- index = GetProfileIndex( win ) ;
-
- // see if already open
- switch (subtype)
- {
- case kFileSubType :
- if ( FindWinHandle( &spec, kProfileType, subtype, 1, 1, &existingWin ) == 1 )
- alreadyOpen = true ;
- break ;
-
- case kEmbededSubType :
- count = FindWinHandle( &spec, kProfileType, subtype, 0, 0, nil ) ;
- for (i=1; i<=count && !alreadyOpen; i++)
- {
- if ( FindWinHandle( &spec, kProfileType, subtype, i, 1, &existingWin ) == 1 )
- if ( GetProfileIndex(existingWin) == index )
- alreadyOpen = true ;
- }
- break ;
-
- case kSysProfSubType :
- if ( FindWinHandle( nil, kProfileType, subtype, 1, 1, &existingWin ) == 1 )
- alreadyOpen = true ;
- break ;
- }
-
- if (alreadyOpen)
- {
- // bring it to the front
- SelectWindow( GetWinWindow(existingWin) ) ;
- return kWasAlreadyOpen ;
- }
-
- switch (subtype)
- {
- case kFileSubType :
- err = OpenProfileFSSpec( spec, &prof ) ;
- if ( err ) return err;
- SetProfileRef( win, prof ) ; // set the window's data's profile ref
- break ;
-
- case kEmbededSubType :
- //? the prof is valid
- //? the spec is the spec of the pict file
- break ;
-
- case kSysProfSubType :
- err = CMGetSystemProfile( &prof ) ;
- err = CMGetProfileLocation( prof, &profLoc) ;
- if ( err ) return err ;
- if ( profLoc.locType != cmFileBasedProfile )
- return fnfErr ; //? should also close prof
- spec = profLoc.u.fileLoc.spec ;
- SetWinFSSpec( win, &spec ) ;
- SetProfileRef( win, prof ) ; // this should be nil already
- break ;
- }
-
- err = DoCreateProfWindow( win ) ;
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winDisposeProfile
- *------------------------------------------------------------------------------*
- This is a DisposeProcPtr for Profile windows.
- This routine is responsible for disposing of any data that was allocated
- by the document and stored in the its data handle.
- This ProcPtr is envoked by CallWinDisposeProc() which is called by:
- DisposeWinHandle() which disposes of the entire winHandle.
- \*------------------------------------------------------------------------------*/
- void winDisposeProfile ( winHandle win )
- {
- ProfileDataHdl data ;
- CMProfileRef prof ;
-
- data = (ProfileDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return;
-
- prof = GetProfileRef( win ) ;
- if ( prof != nil )
- CMCloseProfile( prof ) ;
-
- #if TryGettingAnEditableProfileName
- TEHandle teh = GetProfileNameTEH( win ) ;
- if ( teh != nil )
- TEDispose( teh ) ;
- #endif
-
- // lastly, dispose of the data handle
- DisposeHandle( (Handle)data ) ;
- }
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- static void DoDrawProfData ( winHandle win )
- {
- long length ;
- Rect labelRect, varsRect, whereRect, iconRect ; // = {7,53,39,85} ;
- Handle labelText, varText, whereText ;
- CMProfileRef prof ;
- CMError cmerr ;
- OSType subtype ;
- unsigned long vers ;
- Str255 name, path ;
- FSSpec spec ;
-
- // get rects from resources
- labelRect = GetRect ( rProfileLabelsStringID ) ;
- varsRect = GetRect ( rProfileVarsStringID ) ;
- whereRect = GetRect ( rProfileWhereVarStringID ) ;
- iconRect = GetRect ( rProfileIconID ) ;
-
- // draw icon
- PlotIconID( &iconRect, atNone, ttNone, rProfileIconID ) ;
-
- // draw labels
- TextSize(9) ;
- TextFace(bold) ;
- TextFont(applFont) ;
-
- labelText = GetResource( 'TEXT', rProfileLabelsStringID ) ;
-
- HLock( labelText ) ;
- length = GetHandleSize( labelText ) ;
- TETextBox( *labelText, length, &labelRect, teFlushRight) ;
- HUnlock( labelText ) ;
- ReleaseResource( labelText ) ;
-
- TextSize(9) ;
- TextFace(0) ;
- TextFont(applFont) ;
-
- // get the profile's vital stats
- subtype = GetWinSubtype( win ) ;
- prof = GetProfileRef( win ) ;
- spec = GetWinFSSpec( win ) ;
-
- // get the profile's name element
- cmerr = GetProfName ( prof, (StringPtr)&name ) ;
- if (cmerr) return ;
-
- // draw the profile's name
- MoveTo (varsRect.left,varsRect.top-19) ;
- if ( IsPseudoProfile(prof) )
- TextFace(italic) ;
- DrawString( name ) ;
- TextFace(0) ;
-
- #if TryGettingAnEditableProfileName
- {
- TEHandle hTE;
- Rect rUpdate;
- hTE = GetProfileNameTEH( win );
- rUpdate = (**hTE).destRect;
- TEUpdate(&rUpdate,hTE);
- }
- #endif
-
- // get profile version
- cmerr = GetProfVersion ( prof, &vers) ;
- if (cmerr) return ;
-
- // set up the profile info text
- varText = GetResource( 'TEXT', rProfileVarsStringID ) ;
- if (vers == cmCS1ProfileVersion)
- MungeProfileHeader1( prof, varText ) ;
- else if (vers >= cmCS2ProfileVersion)
- MungeProfileHeader2( prof, varText ) ;
- else return ; // need a better error code here
-
- // set up the "where" info text
- whereText = GetResource( 'TEXT', rProfileWhereVarStringID ) ;
- FSSpecToString( GetWinFSSpec(win), path, (subtype==kEmbededSubType) ) ;
- MyReplaceText ( whereText, path, "\p«Where»" ) ;
- MyReplaceText ( whereText, "\p:\0", "\p:" ) ;
-
- // draw the profile info
- HLock( varText ) ;
- length = GetHandleSize( varText ) ;
- TETextBox( *varText, length, &varsRect, teFlushLeft) ;
- HUnlock( varText ) ;
- ReleaseResource( varText ) ;
-
- // draw the "where" information
- HLock( whereText ) ;
- length = GetHandleSize( whereText ) ;
- TETextBox( *whereText, length, &whereRect, teFlushLeft) ;
- HUnlock( whereText ) ;
- ReleaseResource( whereText ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- \*------------------------------------------------------------------------------*/
- static void MungeProfileHeader1 ( CMProfileRef prof, Handle text )
- {
- CMAppleProfileHeader head ;
- CMHeader cm1 ;
- Str255 myStr ;
- CMError cmerr ;
-
- // get the profile's header
- cmerr = CMGetProfileHeader(prof, &head) ;
- if (cmerr) return ;
- cm1 = head.cm1 ;
-
- // Vers
- MyReplaceText( text, "\p1.0", "\p«Vers»" ) ;
- // Embed
- // Size
- FormatLong( cm1.size, rBytesFMAT, myStr) ;
- MyReplaceText( text, myStr, "\p«Size»" ) ;
- // ColorSpace
- ColorSpace2String ( cm1.dataType, myStr ) ;
- MyReplaceText( text, myStr, "\p«ColorSpace»" ) ;
- // InterchangeSpace
- ColorSpace2String ( 'XYZ ', myStr ) ;
- MyReplaceText( text, myStr, "\p«XchngSpace»" ) ;
- // CMM
- OSTypeToString( cm1.CMMType, myStr) ;
- MyReplaceText( text, myStr, "\p«CMM»" ) ;
- // Class
- ProfileClass2String ( cm1.deviceType, myStr ) ;
- MyReplaceText( text, myStr, "\p«Class»" ) ;
- // Manufacturer
- OSTypeToString( cm1.deviceManufacturer, myStr) ;
- MyReplaceText( text, myStr, "\p«Manufacturer»" ) ;
- // DeviceModel
- LongHexToString ( cm1.deviceModel, myStr) ;
- MyReplaceText( text, myStr, "\p«DeviceModel»" ) ;
- // Attributes
- LongHexToString ( cm1.deviceAttributes[0], myStr) ;
- MyReplaceText( text, myStr, "\p«Attributes0»" ) ;
- LongHexToString ( cm1.deviceAttributes[1], myStr) ;
- MyReplaceText( text, myStr, "\p«Attributes1»" ) ;
- // Flags
- LongHexToString ( cm1.flags, myStr) ;
- MyReplaceText( text, myStr, "\p«Flags»" ) ;
- // Intent
- RendIntent2String ( cm1.options, myStr ) ;
- MyReplaceText( text, myStr, "\p«Intent»" ) ;
- // White
- MyReplaceText( text, "\p«X», «Y», «Z»", "\p«White»" ) ;
- FormatSmallFract( cm1.white.X, rDotThreeFMAT, myStr ) ;
- MyReplaceText( text, myStr, "\p«X»" ) ;
- FormatSmallFract( cm1.white.Y, rDotThreeFMAT, myStr ) ;
- MyReplaceText( text, myStr, "\p«Y»" ) ;
- FormatSmallFract( cm1.white.Z, rDotThreeFMAT, myStr ) ;
- MyReplaceText( text, myStr, "\p«Z»" ) ;
- // Created
- MyReplaceText( text, "\p--", "\p«Created»" ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- \*------------------------------------------------------------------------------*/
- static void MungeProfileHeader2 ( CMProfileRef prof, Handle text )
- {
- CMAppleProfileHeader head ;
- CM2Header cm2 ;
- Str255 myStr ;
- CMError cmerr ;
- unsigned long rawSecs ;
-
- // get the profile's header
- cmerr = CMGetProfileHeader(prof, &head) ;
- if (cmerr) return ;
- cm2 = head.cm2 ;
-
- // Vers
- VersionToString( cm2.profileVersion, myStr) ;
- MyReplaceText( text, myStr, "\p«Vers»" ) ;
- // Embed
- // Size
- FormatLong( cm2.size, rBytesFMAT, myStr) ;
- MyReplaceText( text, myStr, "\p«Size»" ) ;
- // ColorSpace
- ColorSpace2String ( cm2.dataColorSpace, myStr ) ;
- MyReplaceText( text, myStr, "\p«ColorSpace»" ) ;
- // InterchangeSpace
- ColorSpace2String ( cm2.profileConnectionSpace, myStr ) ;
- MyReplaceText( text, myStr, "\p«XchngSpace»" ) ;
- // CMM
- OSTypeToString( cm2.CMMType, myStr) ;
- MyReplaceText( text, myStr, "\p«CMM»" ) ;
- // Class
- OSTypeToString( cm2.profileClass, myStr) ;
- ProfileClass2String ( cm2.profileClass, myStr ) ;
- MyReplaceText( text, myStr, "\p«Class»" ) ;
- // Manufacturer
- OSTypeToString( cm2.deviceManufacturer, myStr) ;
- MyReplaceText( text, myStr, "\p«Manufacturer»" ) ;
- // DeviceModel
- LongHexToString ( cm2.deviceModel, myStr) ;
- MyReplaceText( text, myStr, "\p«DeviceModel»" ) ;
- // Attributes
- LongHexToString ( cm2.deviceAttributes[0], myStr) ;
- MyReplaceText( text, myStr, "\p«Attributes0»" ) ;
- LongHexToString ( cm2.deviceAttributes[1], myStr) ;
- MyReplaceText( text, myStr, "\p«Attributes1»" ) ;
- // Flags
- LongHexToString ( cm2.flags, myStr) ;
- MyReplaceText( text, myStr, "\p«Flags»" ) ;
- // Intent
- RendIntent2String ( cm2.renderingIntent, myStr ) ;
- MyReplaceText( text, myStr, "\p«Intent»" ) ;
- // White
- MyReplaceText( text, "\p«X», «Y», «Z»", "\p«White»" ) ;
- FormatFixed( cm2.white.X, rDotThreeFMAT, myStr) ;
- MyReplaceText( text, myStr, "\p«X»" ) ;
- FormatFixed( cm2.white.Y, rDotThreeFMAT, myStr) ;
- MyReplaceText( text, myStr, "\p«Y»" ) ;
- FormatFixed( cm2.white.Z, rDotThreeFMAT, myStr) ;
- MyReplaceText( text, myStr, "\p«Z»" ) ;
- // Created
- MyReplaceText( text, "\p«Date», «Time»", "\p«Created»" ) ;
- DateToSeconds( (DateTimeRec*)&(cm2.dateTime), &rawSecs) ;
- IUDateString( rawSecs, abbrevDate, myStr) ;
- MyReplaceText( text, myStr, "\p«Date»" ) ;
- IUTimeString( rawSecs, false, myStr) ;
- MyReplaceText( text, myStr, "\p«Time»" ) ;
- }
-
-
- static OSErr RendIntent2String ( unsigned long intent, StringPtr dest )
- {
- return GetFlagListStringPtr( 1000, intent, dest ) ;
- }
-
- static OSErr ColorSpace2String ( OSType spaceType, StringPtr dest )
- {
- return GetOSTypeListStringPtr( 129, spaceType, dest ) ;
- }
-
- static OSErr ProfileClass2String ( OSType classType, StringPtr dest )
- {
- return GetOSTypeListStringPtr( 128, classType, dest ) ;
- }
-
-
-
-
-
- /*------------------------------------------------------------------------------*\
- DoCreateProfWindow
- *------------------------------------------------------------------------------*
- This routine actually creates the WindowRef for a winHandle.
- After creating the window, it:
- reference the window and the DocumentRecord to each other,
- makes the window the current port,
- resizes the window according to the WIND resource,
- titles it according the the FSSpec, and
- makes it visible .
- This routine is called by:
- winOpenProfList() which fills in the winHandle structure
- \*------------------------------------------------------------------------------*/
- static OSErr DoCreateProfWindow ( winHandle win )
- {
- OSErr err = noErr ;
- WindowRef window ;
- FSSpec spec ;
- CMProfileRef prof ;
- OSType subtype ;
- Str255 winTitle="\p" ;
-
- // create the window
- window = GetNewCWindow(rProfileWindID, nil, (WindowRef)-1 ) ;
-
- SetWinWindow( win, window ) ; // save a reference to the window in the winRecord
- SetWindowWinHandle ( window, win ) ; // save a reference to the winRecord in the window
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
-
- SetWinRect( win, ((CGrafPtr)window)->portRect ) ;
-
- spec = GetWinFSSpec( win ) ;
- prof = GetProfileRef( win ) ;
- subtype = GetWinSubtype( win ) ;
-
- // set the name of this document window
- switch (subtype)
- {
- case kFileSubType :
- SetWTitle( window, spec.name ) ;
- break ;
-
- case kEmbededSubType :
- NumToString( GetProfileIndex(win), winTitle ) ;
- pStrIns( winTitle, "\p:", 255 ) ;
- pStrIns( winTitle, spec.name, 255 ) ;
- SetWTitle( window, winTitle ) ;
- break ;
-
- case kSysProfSubType :
- err = GetProfName( nil, winTitle ) ;
- SetWTitle( window, winTitle ) ;
- break ;
- }
-
- #if TryGettingAnEditableProfileName
- {
- Rect varsRect;
- Rect destRect;
- Rect viewRect;
- TEHandle hTE;
-
- varsRect = GetRect ( rProfileVarsStringID ) ;
- varsRect.top -= 19;
- varsRect.bottom = varsRect.top + 16*2;
-
- destRect = viewRect = varsRect;
-
- hTE = TENew(&destRect,&viewRect);
- (**hTE).txSize = 9;
- (**hTE).lineHeight = 16;
- (**hTE).fontAscent = 9;
- TESetText(" ",1,hTE);
- // TESetText("this is a test",14,hTE);
- TEActivate(hTE);
-
- SetProfileNameTEH( win, hTE );
- }
- #endif
-
- // make sure it is visible
- ShowWindow( window ) ;
-
- return err ;
- }
-
-
- static void ProfMakeSysProfileCmnd ( winHandle win )
- {
- OSType subtype ;
- OSErr err ;
- FSSpec spec ;
-
- subtype = GetWinSubtype( win ) ;
- if ( subtype==kFileSubType )
- {
- spec = GetWinFSSpec( win ) ;
- err = CMSetSystemProfile( &spec ) ;
- }
- }
-
- static void ProfCreateProfIDCmnd ( winHandle win )
- {
- OSErr err ;
- CMProfileRef prof ;
- unsigned long size ;
- CMProfileIdentifierHdl ident ;
- winHandle newwin ;
-
- prof = GetProfileRef( win ) ;
-
- err = CMCreateProfileIdentifierCompat( prof, nil, &size) ;
- if (err) return ;
- ident = (CMProfileIdentifierHdl) NewHandle( size );
- if (!ident) return ;
- HLock( (Handle)ident );
- err = CMCreateProfileIdentifierCompat( prof, *ident, &size) ;
- HUnlock( (Handle)ident );
-
-
- // create a new winHandle of the proper type
- err = NewWinHandle( &newwin, winAllocProfID ) ;
- WarnIfErr( err ) ;
- if (err) return ;
-
- // set the subtype of the winHandle so that the correct search is done
- SetProfIDIDHdl( newwin, ident ) ;
- SetWinSubtype( newwin, kHandleSubType ) ; // set subtype
-
- err = CallWinOpenProc( newwin ) ;
- if ( err != noErr )
- DisposeWinHandle( newwin ) ;
-
- if ( err == kWasAlreadyOpen )
- err = noErr;
- }
-
-
- /*------------------------------------------------------------------------------*\
- SaveCmndProfile
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveCmndProfile ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- OSErr err ;
- OSType subtype ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- subtype = GetWinSubtype( win ) ;
- GetProfileRef( win ) ;
-
- if ( !dirty ) return; // no need to save
- if ( subtype!=kFileSubType) return; // can't save
-
- if ( !hasFile )
- SaveAsCmndProfile( win ) ;
- else
- {
- err = CMUpdateProfile(GetProfileRef(win));
- if (err) return ; // if err, should do something
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- SaveAsCmndProfile
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveAsCmndProfile ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- StandardFileReply reply ;
- OSErr err ;
- WindowRef window ;
- Str255 title ;
- OSType subtype ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- subtype = GetWinSubtype( win ) ;
- window = GetWinWindow( win ) ;
-
- if ( hasFile )
- StringToString( spec.name, title ) ;
- else
- GetWTitle( window, title ) ;
-
- StandardPutFile( "\pSave profile as:", title, &reply) ;
- if ( reply.sfGood )
- {
- CMProfileRef newProf, prof;
- CMProfileLocation profLoc ;
-
- profLoc.locType = cmFileBasedProfile;
- profLoc.u.fileLoc.spec = reply.sfFile;
-
- prof = GetProfileRef(win);
- err = CMCopyProfile( &newProf, &profLoc, prof) ;
- WarnIfErr( err ) ;
- if ( err ) return ; // if err, should do something
- SetWinFSSpec( win, &spec ) ; // win's spec = new spec
- SetWTitle( window, spec.name ) ; // win title = new title
- SetProfileRef(win, newProf);
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- RevertCmndProfile
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void RevertCmndProfile ( winHandle win )
- {
- FSSpec spec ;
- Boolean dirty ;
- Boolean hasFile ;
- OSType subtype ;
-
- spec = GetWinFSSpec( win ) ;
- dirty = GetWinDirty( win ) ;
- hasFile = ( spec.name[0] > 0 ) ;
- subtype = GetWinSubtype( win ) ;
-
- if ( !dirty || !hasFile ) return ;
- if ( subtype!=kFileSubType) return; // can't revert
-
- // ask user if it's ok
-
- SetWinDirty( win, false ) ; // clear dirty so we don't get another dialog
- CallWinCloseProc( win ) ; // close the document
- SendODOC( &spec ) ; // reopen: send ODOC event to ourselves:
- // DoAppAdjustMenus() ; // undim app items
- }
-
-
- #define LMGetWMgrCPort() (* (GrafPtr *) 0x0D2C)
-
- static long PopUpMenuSelectFont (MenuHandle theMenu,
- short top, short left,
- short popUpItem,
- short font, short size)
- {
- long result;
- /*
- short SaveSysFontFam;
- GrafPtr wmPtr,wmCPtr;
- short SaveWPortFont;
- short SaveWPortSize;
-
- wmPtr = LMGetWMgrPort();
- wmCPtr = LMGetWMgrCPort();
- SaveWPortFont = wmPtr->txFont;
- SaveWPortSize = wmPtr->txSize;
-
- SaveSysFontFam = LMGetSysFontFam();
- LMSetSysFontFam(font);
- wmCPtr->txFont = font;
- wmCPtr->txSize = size;
- wmPtr->txFont = font;
- wmPtr->txSize = size;
- */
- result = PopUpMenuSelect(theMenu,top,left,popUpItem);
- /*
- LMSetSysFontFam(SaveSysFontFam);
- wmCPtr->txFont = SaveWPortFont;
- wmCPtr->txSize = SaveWPortSize;
- wmPtr->txFont = SaveWPortFont;
- wmPtr->txSize = SaveWPortSize;
- */
- return result;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetFlagListStringPtr
- *------------------------------------------------------------------------------*
- This routine loads a 'BTS#' resource and loops through it looking
- for the string that coresponds to the type parameter.
- \*------------------------------------------------------------------------------*/
-
- static OSErr GetFlagListStringPtr( short id, unsigned long flags, StringPtr dest )
- {
- short i, count;
- short shift ;
- long maskShift, valueShift ;
- FlagListHdl list ;
-
- list = (FlagListHdl) GetResource('BTS#', id) ;
- if (list==nil) return ResError() ;
-
- count = (**list).count ;
- dest[0] = 0 ;
-
- for (i=0; i<count; i++ )
- {
- shift = (**list).entry[i].shift ;
- maskShift = ((unsigned long)((**list).entry[i].mask)) << shift ;
- valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
-
- if ( (flags & maskShift) == valueShift )
- {
- if (dest[0]) pStrCat( dest, "\p, ", 255 );
- pStrCat( dest, (StringPtr)&((**list).entry[i].string), 255 );
- }
- }
- ReleaseResource( (Handle)list ) ;
- return noErr ;
- }
-
- static OSErr BuildFlagListMenu ( short id, unsigned long flags, MenuHandle menu )
- {
- short j, i, count;
- short shift, lastshift ;
- long maskShift, valueShift ;
- FlagListHdl list ;
-
- list = (FlagListHdl) GetResource('BTS#', id) ;
- if (list==nil) return ResError() ;
-
- count = (**list).count ;
-
- for (j=i=0; i<count; i++, j++ )
- {
- shift = (**list).entry[i].shift ;
- maskShift = ((unsigned long)((**list).entry[i].mask)) << shift ;
- valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
-
- if ( (i!=0) && (lastshift!=shift) )
- {
- AppendMenu( menu, "\p-" );
- j++;
- }
-
- AppendMenu(menu, (StringPtr)&((**list).entry[i].string) );
- if ( (flags & maskShift) == valueShift )
- SetItemMark(menu,j+1,0xC3);
-
- lastshift = shift ;
- }
- ReleaseResource( (Handle)list ) ;
- return noErr ;
- }
-
- static OSErr SetFlagFromMenuItem ( short id, unsigned long *flags, short mitem )
- {
- short j, i, count;
- short shift, lastshift ;
- long maskShift, valueShift ;
- FlagListHdl list ;
- unsigned long flagsBefore ;
-
- flagsBefore = *flags ;
-
- list = (FlagListHdl) GetResource('BTS#', id) ;
- if (list==nil) return ResError() ;
-
- count = (**list).count ;
-
- for (j=i=0; i<count; i++, j++ )
- {
- shift = (**list).entry[i].shift ;
- maskShift = ((unsigned long)((**list).entry[i].mask)) << shift ;
- valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
-
- if ( (i!=0) && (lastshift!=shift) )
- j++;
-
- if (mitem == j+1)
- *flags = ((*flags) & (~maskShift)) | (valueShift);
-
- lastshift = shift ;
- }
- ReleaseResource( (Handle)list ) ;
-
- return (flagsBefore == *flags) ; // return something if there was no change
- }
-
-
-