home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 29.2 KB | 1,004 lines | [TEXT/CWIE] |
- // A profID 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 "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 rProfIDIconID 5003 // icon family resource id
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- void DoDrawProfData ( winHandle win ) ;
- void MungeProfileHeader2 ( CMAppleProfileHeader head, 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 ProfIDSearchListCmnd ( winHandle win ) ;
- void SaveCmndProfID ( winHandle win ) ;
- void SaveAsCmndProfID ( winHandle win ) ;
- void RevertCmndProfID ( 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
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateProfID
- *------------------------------------------------------------------------------*
- This is a UpdateProcPtr for ProfID windows.
- It handles all drawing into the window.
- For ProfList windows, this means that this routine is responible for
- drawing the the basic profID info into the window.
- This ProcPtr is envoked by CallWinUpdateProc() which is called by:
- DoUpdateEvent() which dispaches update events.
- \*------------------------------------------------------------------------------*/
- void winUpdateProfID ( 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 ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winClickProfID
- *------------------------------------------------------------------------------*
- This is a ClickProcPtr for ProfID 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 winClickProfID ( winHandle win, EventRecord *e )
- {
- CMError cmerr ;
- CMProfileIdentifierHdl id;
- 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 )
- {
- id = GetProfIDIDHdl( win ) ;
- head.cm2 = ((**id).profileHeader) ;
-
- 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)
- {
- SetWinDirty( win, true ) ;
- InvalRect( &varsRect ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
- DisposeMenu(menu);
- }
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winCloseProfID
- *------------------------------------------------------------------------------*
- This is a CloseProcPtr for ProfID windows.
- So far, all this does is call DisposeWinHandle()
- This win type doesn't need to be saved so there 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 winCloseProfID ( winHandle win )
- {
- DisposeWinHandle( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winMenuProfID
- *------------------------------------------------------------------------------*
- This is a MenuProcPtr for ProfID 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 winMenuProfID ( 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
- SaveCmndProfID( win ) ;
- break ;
- case iSaveAs: // save this document under a new name
- SaveAsCmndProfID( win ) ;
- break ;
- case iRevert: // discard all changes made to the document since it was last saved
- RevertCmndProfID( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- case mProfileLists:
- switch ( menuItem )
- {
- case iCSFolderUqid:
- ProfIDSearchListCmnd( win ) ;
- break ;
- default :
- *didit = false ;
- break ;
- }
- break ;
-
- default :
- *didit = false ;
- break ;
- }
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- }
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateMenusProfID
- *------------------------------------------------------------------------------*
- This is a UpdateMenuProcPtr for ProfID 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 winUpdateMenusProfID ( 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 list submenu
- theMenu = GetMenuHandle ( mProfileLists ) ;
-
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iCSFolderUqid ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winAllocProfID
- *------------------------------------------------------------------------------*
- This is a AllocProcPtr for ProfID 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,winAllocProfID) 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 winAllocProfID ( winHandle win )
- {
- OSErr err = noErr ;
- ProfIDDataHdl data ;
-
- // we need ColorSync 2.
- if (!CS2_available())
- return eWarnCantOpenFileNoColorSync2 ;
-
- // set the window type
- SetWinType( win, kProfIDType ) ;
-
- // stuff winHandle fields
- SetWinUpdateProc ( win, (UpdateProcPtr) winUpdateProfID ) ;
- SetWinClickProc ( win, (ClickProcPtr) winClickProfID ) ;
- SetWinMenuProc ( win, (MenuProcPtr) winMenuProfID ) ;
- SetWinUpdateMenusProc ( win, (UpdateMenusProcPtr) winUpdateMenusProfID ) ;
- SetWinOpenProc ( win, (OpenProcPtr) winOpenProfID ) ;
- SetWinCloseProc ( win, (CloseProcPtr) winCloseProfID ) ;
- SetWinDisposeProc ( win, (DisposeProcPtr) winDisposeProfID ) ;
-
- // allocate data handle
- data = (ProfIDDataHdl)NewHandleClear( sizeof(ProfIDDataRec) ) ;
- if( data == nil ) return MemError() ;
- SetWinData( win, (Handle)data ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winOpenProfID
- *------------------------------------------------------------------------------*
- This is a OpenProcPtr for ProfID windows.
- This routine is responsible for opening a ProfID window after all the
- needed fields of the winHandle structure have been filled in by winAllocProfID.
- On entry the DocumentRecord must contain a valid FSSpec.
- If a ProfID 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,winAllocProfID),
- 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 winOpenProfID ( winHandle win )
- {
- OSErr err = noErr ;
- winHandle existingWin ;
- FSSpec spec ;
- CMProfileIdentifierHdl id ;
- 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 = GetProfIDIndex( win ) ;
-
- // see if already open
- switch (subtype)
- {
- case kHandleSubType :
- break ;
-
- case kFileSubType :
- if ( FindWinHandle( &spec, kProfIDType, subtype, 1, 1, &existingWin ) == 1 )
- alreadyOpen = true ;
- break ;
-
- case kEmbededSubType :
- count = FindWinHandle( &spec, kProfIDType, subtype, 0, 0, nil ) ;
- for (i=1; i<=count && !alreadyOpen; i++)
- {
- if ( FindWinHandle( &spec, kProfIDType, subtype, i, 1, &existingWin ) == 1 )
- if ( GetProfIDIndex(existingWin) == index )
- alreadyOpen = true ;
- }
- break ;
- }
-
- if (alreadyOpen)
- {
- // bring it to the front
- SelectWindow( GetWinWindow(existingWin) ) ;
- return kWasAlreadyOpen ;
- }
-
- switch (subtype)
- {
- case kHandleSubType :
- break ;
-
- case kFileSubType :
- err = ReadProfileIdentifier( spec, &id ) ;
- if ( err ) return err;
- SetProfIDIDHdl( win, id ) ; // 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 ;
- }
-
- err = DoCreateProfWindow( win ) ;
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winDisposeProfID
- *------------------------------------------------------------------------------*
- This is a DisposeProcPtr for ProfID 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 winDisposeProfID ( winHandle win )
- {
- ProfIDDataHdl data ;
- CMProfileIdentifierHdl id ;
-
- data = (ProfIDDataHdl) GetWinData ( win ) ;
- if ( data==nil ) return;
-
- id = GetProfIDIDHdl( win ) ;
- if ( id != nil )
- DisposeHandle( (Handle)id ) ;
-
- // 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 ;
- CMProfileIdentifierHdl id;
- CMAppleProfileHeader head ;
- 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 ( rProfIDIconID ) ;
-
- // draw icon
- PlotIconID( &iconRect, atNone, ttNone, rProfIDIconID ) ;
-
- // 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 ProfID's vital stats
- subtype = GetWinSubtype( win ) ;
- spec = GetWinFSSpec( win ) ;
- id = GetProfIDIDHdl( win ) ;
- HLock ( (Handle)id ) ;
- head.cm2 = ((**id).profileHeader) ;
- (void) GetProfileIdentifierSize( *id, &(head.cm2.size) ) ;
-
- // get the ProfID's name element
- cmerr = GetProfileIdentName( *id, (StringPtr)&name ) ;
- HUnlock ( (Handle)id ) ;
- if (cmerr) return ;
-
- // draw the ProfID's name
- MoveTo (varsRect.left,varsRect.top-19) ;
- TextFace(italic) ;
- DrawString( name ) ;
- TextFace(0) ;
-
- // get ProfID version
- vers = head.cm2.profileVersion ;
-
- // set up the ProfID info text
- varText = GetResource( 'TEXT', rProfileVarsStringID ) ;
- if (vers >= cmCS2ProfileVersion)
- MungeProfileHeader2( head, 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 MungeProfileHeader2 ( CMAppleProfileHeader head, Handle text )
- {
- CM2Header cm2 ;
- Str255 myStr ;
- unsigned long rawSecs ;
-
- // get the profile's header
- 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 ;
- 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 ) ;
- subtype = GetWinSubtype( win ) ;
-
- // set the name of this document window
- switch (subtype)
- {
- case kHandleSubType :
- break ;
-
- case kFileSubType :
- SetWTitle( window, spec.name ) ;
- break ;
-
- case kEmbededSubType :
- NumToString( GetProfIDIndex(win), winTitle ) ;
- pStrIns( winTitle, "\p:", 255 ) ;
- pStrIns( winTitle, spec.name, 255 ) ;
- SetWTitle( window, winTitle ) ;
- break ;
- }
-
- // make sure it is visible
- ShowWindow( window ) ;
-
- return err ;
- }
-
-
- static void ProfIDSearchListCmnd ( winHandle win )
- {
- OSErr err = noErr ;
- CMProfileIdentifierHdl profIDHdl ;
- winHandle newWin ;
-
- // create a a new handle copied from the win's ProfileIdentifier handle
- profIDHdl = GetProfIDIDHdl( win ) ;
- err = HandToHand( (Handle*)&profIDHdl );
- WarnIfErr( err ) ;
- if (err) return ;
-
- // create a new winHandle of the proper type
- err = NewWinHandle( &newWin, winAllocProfList ) ;
- WarnIfErr( err ) ;
- if (err) return ;
-
- // set the subtype of the winHandle so that the correct search is done
- SetWinSubtype( newWin, kProfIDListSubtype ) ; // set subtype
- SetProfListIdentHdl( newWin, profIDHdl ) ;
-
- err = CallWinNewProc( newWin ) ;
- if ( err != noErr )
- DisposeWinHandle( newWin ) ;
-
- if ( err == kWasAlreadyOpen )
- err = noErr;
- }
-
- /*------------------------------------------------------------------------------*\
- SaveCmndProfile
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveCmndProfID ( 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 ) ;
-
- if ( !dirty ) return; // no need to save
- if ( subtype!=kFileSubType) return; // can't save
-
- if ( !hasFile )
- SaveAsCmndProfID( win ) ;
- else
- {
- err = WriteProfileIdentifier( spec, GetProfIDIDHdl(win), kCreatorType ) ;
- if (err) return ; // if err, should do something
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- SaveAsCmndProfID
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void SaveAsCmndProfID ( 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 ProfID as:", title, &reply) ;
- if ( reply.sfGood )
- {
- spec = reply.sfFile ;
- err = WriteProfileIdentifier( spec, GetProfIDIDHdl(win), kCreatorType ) ;
- 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
- SetWinSubtype( win, kFileSubType ) ;
- SetWinDirty( win, false ) ;
- DoAppAdjustMenus() ; // undim app items
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- RevertCmndProfID
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- static void RevertCmndProfID ( 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
- }
-
-
-