unit AEOther; { This module is adds some AppleEvent support to Image Written and partly debugged by Rob Douglas University of British Columbia douglas@org.ecc.ubc.ca McKellar Designs rdouglas@mckellar.com } interface uses Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils,Resources, Errors, Palettes, LowMem, AppleEvents,AEObjects, AERegistry, Errors, globals, Utilities,Analysis,Text,File1,Graphics,Math,LUT,Edit, msc,AEUtility,AEWindow; function ResultsEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; function ResultsGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; function ResultsPutData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; function TextWindowEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; function PasteEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; function LUTEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; function HistogramEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; function HistogramGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; implementation { *************************************************************************************** Handles AppleEvents specific to the results window. *************************************************************************************** } function ResultsEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; VAR theError:OSErr; theName:str255; begin if ResultsWindow <> nil then begin if theCommand = 'clos' then theError := CloseAWindow(ResultsWindow) else if theCommand = 'save' then begin theError := GetAEStr255(inAppleEvent, 'name', theName); Export(theName, 0); end else if theCommand = 'Upda' then UpdateResultsWindow else if theCommand = 'copy' then CopyResults else if inToken^.containerWindow = ResultsWindow then theError := WindowEvents(inAppleEvent, reply,inToken,theCommand); end else begin if (theCommand = 'slct') or (theCommand = 'Show') or (theCommand = 'open') then begin ShowResults; UpdateList; SelectWindow(ResultsWindow); end else if theCommand = 'copy' then CopyResults; end; ResultsEvents := noErr; end; function ResultsPutData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; VAR theError:OSErr; theIndex:LongInt; begin theError := errAEDescNotFound; with inToken^ do begin if name = 'mCtr' then mCount := GetShortProperty(inAppleEvent,1,MaxMeasurements) else if containerWindow = ResultsWindow then theError := WindowPutData(inAppleEvent, reply, inToken); end; ResultsPutData := errAEEventNotHandled; end; function ResultsGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; VAR theError:OSErr; theIndex:LongInt; i:integer; theList:AEDescList; xValue:extended; begin theError := errAEDescNotFound; with inToken^ do begin if (name = 'cAre') or (name = 'cMea') or (name = 'cMin') or (name = 'cMax') or (name = 'cSD ') or (name = 'nPix') or (name = 'cLen') or (name = 'nPix') or (name = 'xCtr') or (name = 'yCtr') or (name = 'majX') or (name = 'minX') or (name = 'cOri') or (name = 'rUs1') or (name = 'rUs2') then begin theIndex := index; if theindex = -1 then theIndex := mCount; CheckIndex(theIndex, 1, MaxMeasurements); if thru > 0 then begin theError := AECreateList(nil, 0,false,theList); CheckIndex(thru,1,MaxMeasurements); for i := index to thru do begin if name = 'cAre' then xValue := mArea^[theIndex] else if name = 'cMea' then xValue := mean^[theIndex] else if name = 'cMin' then xValue := mMin^[theIndex] else if name = 'cMax' then xValue := mMax^[theIndex] else if name = 'cSD ' then xValue := sd^[theIndex] else if name = 'nPix' then xValue := PixelCount^[theIndex] else if name = 'cLen' then xValue := pLength^[theIndex] else if name = 'nPix' then xValue := sd^[theIndex] else if name = 'xCtr' then xValue := xcenter^[theIndex] else if name = 'yCtr' then xValue := ycenter^[theIndex] else if name = 'majX' then xValue := MajorAxis^[theIndex] else if name = 'minX' then xValue := MinorAxis^[theIndex] else if name = 'cOri' then xValue := orientation^[theIndex] else if name = 'rUs1' then xValue := User1^[Index] else if name = 'rUs2' then xValue := User2^[Index]; theError := AEPutPtr( theList, 0, typeExtended, Ptr(@xValue), sizeof(extended) ); end; theError := AEPutParamDesc( reply, keyDirectObject, theList ); end else begin if name = 'cAre' then theError := ReturnExtendedProperty(reply, mArea^[theIndex]) else if name = 'cMea' then theError := ReturnExtendedProperty(reply, mean^[theIndex]) else if name = 'cMin' then theError := ReturnExtendedProperty(reply, mMin^[theIndex]) else if name = 'cMax' then theError := ReturnExtendedProperty(reply, mMax^[theIndex]) else if name = 'cSD ' then theError := ReturnExtendedProperty(reply, sd^[theIndex]) else if name = 'nPix' then theError := ReturnExtendedProperty(reply, PixelCount^[theIndex]) else if name = 'cLen' then theError := ReturnExtendedProperty(reply, pLength^[theIndex]) else if name = 'nPix' then theError := ReturnExtendedProperty(reply, sd^[theIndex]) else if name = 'xCtr' then theError := ReturnExtendedProperty(reply, xcenter^[theIndex]) else if name = 'yCtr' then theError := ReturnExtendedProperty(reply, ycenter^[theIndex]) else if name = 'majX' then theError := ReturnExtendedProperty(reply, MajorAxis^[theIndex]) else if name = 'minX' then theError := ReturnExtendedProperty(reply, MinorAxis^[theIndex]) else if name = 'cOri' then theError := ReturnExtendedProperty(reply, orientation^[theIndex]) else if name = 'rUs1' then theError := ReturnExtendedProperty(reply, User1^[Index]) else if name = 'rUs2' then theError := ReturnExtendedProperty(reply, User2^[Index]) end; end else if name = 'mCtr' then theError := ReturnShortProperty(reply, mCount) else if containerWindow = ResultsWindow then theError := WindowGetData(inAppleEvent, reply, inToken); end; ResultsGetData := theError; end; function HistogramEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; VAR theWindow:WindowPtr; begin HistogramEvents := noErr; theWindow := inToken^.containerWindow; if (theCommand = 'slct') or (theCommand = 'Show') or (theCommand = 'open') then begin { ShowHistogram} DoHistogram; DrawHistogram; end else if theWindow <> nil then begin if theCommand = 'clos' then HistogramEvents := CloseAWindow(theWindow) else if theWindow <> nil then HistogramEvents := WindowEvents(inAppleEvent, reply,inToken,theCommand) else HistogramEvents := errAEEventNotHandled; end else HistogramEvents := errAEEventNotHandled; end; function HistogramGetData(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr):OSerr; VAR theError:OSErr; i:integer; theList:AEDescList; xValue:extended; begin theError := errAEDescNotFound; with inToken^ do begin if (name = 'BinH') then begin CheckIndex(index, 1, 256); if thru > 0 then begin theError := AECreateList(nil, 0,false,theList); CheckIndex(thru,1,256); for i := index to thru do theError := AEPutPtr( theList, 0, typeLongInteger, Ptr(@histogram[i]), sizeof(LongInt) ); theError := AEPutParamDesc( reply, keyDirectObject, theList ); end else theError := ReturnLongProperty(reply,histogram[index]); end else theError := WindowGetData(inAppleEvent, reply, inToken); end; HistogramGetData := theError; end; function LUTEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; VAR theWindow:WindowPtr; begin LUTEvents := noErr; theWindow := inToken^.containerWindow; if theWindow <> nil then begin if theCommand = 'invt' then begin InvertPalette; UpdateLUT; end else if theCommand = 'Upda' then UpdateLUT { DoUpdateLUT } else LUTEvents := WindowEvents(inAppleEvent, reply,inToken,theCommand) end else LUTEvents := errAEEventNotHandled; end; { *************************************************************************************** Handles AppleEvents specific to the Text Windows. *************************************************************************************** } function TextWindowEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; VAR theWindow:WindowPtr; ignoreErr:OSErr; theEnum:DescType; begin TextWindowEvents := noErr; theWindow := inToken^.containerWindow; if theCommand = 'clos' then TextWindowEvents := CloseAWindow(theWindow) else if theCommand = 'save' then SaveText else if theCommand = 'sAll' then SelectAllText else TextWindowEvents := WindowEvents(inAppleEvent, reply,inToken,theCommand); end; { *************************************************************************************** Handles AppleEvents specific to the Paste Control window. *************************************************************************************** } function PasteEvents(var inAppleEvent, reply:AppleEvent; inToken: TokenPtr; theCommand: OSType):OSerr; VAR theError:OSErr; theName:str255; begin PasteEvents := noErr; if PasteControl <> nil then begin if theCommand = 'clos' then theError := CloseAWindow(PasteControl) else if (theCommand = 'slct') or (theCommand = 'show') or (theCommand = 'open') then begin ShowPasteControl; end else if inToken^.containerWindow = PasteControl then theError := WindowEvents(inAppleEvent, reply,inToken,theCommand); end else if (theCommand = 'slct') or (theCommand = 'show') or (theCommand = 'open') then ShowPasteControl; PasteEvents := noErr; end; end.