--##########################################
--This AppleScript is used by GrabbyWindow for simulating the drag to Quark Xpress 3.32 - 5.0b
--You can change the parameters for cascading, the bounds and position of the new box, 
--and the accepted filetypes, if you use Xtensions for additional ones
--You should not change the return values 
--and you should not change anything at all, if you dont know what you are doing!!
--End If Software 2002
--
--Release 15  -  11.03.2002
--##########################################
--top position for the first box

set err to "7"
property X : 10
property Y : 10
--x+y for the first box
property W : 100
property H : 100
--cascading
property Zunahme : 5

--list of paths
global PfadListe
--list of filetypes of this files
global texttypelist

set PfadListe to "$$PfadListe$$"
set DateiformatListe to "$$DateiformatListe$$"
set Anzahl to 7777

global texttypelist
global imagetypelist


--texttypes accepted from Quark
set texttypelist to {"CWWP", "AWWP", "WDBN", "TEXT", "ttro", "WPD4", "WPD3", "WPD2", ".WP4", ".WP5", ".WP6", ".txt", ".rtf" }
--imagetypes accepted from Quark
set imagetypelist to {"TIFF", "JPEG", "EPSF", "BMP ", "GIFF", ".GIF", ".TIF", "PICT", ".JPG", ".PSD", ".TIFF"}
set err to "5"

try
	--timeout, if quark is busy
	with timeout of 5 seconds
		tell application "$$QuarkXPress Passport$$"
			set err to "9"
			--if no doc is open, create a new one
			set dnum to number of documents
			if dnum < 1 then
				try
					make document at beginning
				on error errtext
					return errtext
				end try
			end if
			
			if texttypelist contains paragraph 1 of DateiformatListe then
				--text
				try
					tell current box of document 1
						set story 1 to (paragraph 1 of PfadListe as alias)
					end tell
				on error
					tell current page of document 1
						try
							make text box at beginning with properties {bounds:{(Y as string) & " mm", (X as string) & " mm", (H as string) & " mm", (W as string) & " mm"}}
							tell text box 1
								set story 1 to (paragraph 1 of PfadListe as alias)
							end tell
						on error errtext
							return errtext
						end try
					end tell
					
				end try
			else if imagetypelist contains paragraph 1 of DateiformatListe then
				try
					tell current box of document 1
						set image 1 to (paragraph 1 of PfadListe as alias)
					end tell
				on error
					tell current page of document 1
						try
							make picture box at beginning with properties {bounds:{(Y as string) & " mm", (X as string) & " mm", (H as string) & " mm", (W as string) & " mm"}}
							tell picture box 1
								set image 1 to (paragraph 1 of PfadListe as alias)
							end tell
						on error errtext
							return errtext
						end try
					end tell
					
				end try
			else
				return "-10"
			end if
			if Anzahl > 1 then
				set i to 1
				--more images in loop
				try
					repeat with i from 2 to Anzahl
					
						set X to X + Zunahme
						set Y to Y + Zunahme
						set W to W + Zunahme
						set H to H + Zunahme
						tell current page of document 1
							try
								if texttypelist contains paragraph i of DateiformatListe then
									make text box at beginning with properties {bounds:{(Y as string) & " mm", (X as string) & " mm", (H as string) & " mm", (W as string) & " mm"}}
									tell text box 1
										set story 1 to (paragraph i of PfadListe as alias)
									end tell
								else if imagetypelist contains paragraph i of DateiformatListe then
									make picture box at beginning with properties {bounds:{(Y as string) & " mm", (X as string) & " mm", (H as string) & " mm", (W as string) & " mm"}}
									tell picture box 1
										set image 1 to (paragraph i of PfadListe as alias)
									end tell
								else
									return "-10"
								end if
							on error errtext
								return errtext
							end try
						end tell
					end repeat
				on error errtext
					return errtext
				end try
			end if
			do updates
		end tell
	end timeout
on error errtext
	return errtext
end try
return err
