// Textobjekte suchen. 
// Vladimir Samarskiy
// 06/01/97

// Mit diesem Skript kann der Benutzer den nächsten Textblock oder Rahmen in 
// einem verketteten Textabschnitt suchen. Das Skript hält beim letzten Rahmen 
// mit Text an, und arbeitet nicht mit leeren Rahmen.

try getselectlist >> n,..,t,..
try getisframe >> f
if not(n,t=1,1)*not(f)+not(n=1)
	message "Markieren Sie nur einen Textblock."
	return
endif 
getplatform >> platform
if platform=MACINTOSH
	dialogbegin -150,-75,150,85,"Textobjekte suchen"
	pushbutton 42,112,123,140,"OK"
	pushbutton 175,110,260,142,"Abbrechen"
	radiobutton 10,10,290,24,"Erster Textblock des Textabschnitts"
	radiobutton 10,32,290,46,"Voriger Textblock"
	radiobutton 10,54,290,68,"Nächster Textblock",1
	radiobutton 10,76,290,90,"Letzter Textblock des Textabschnitts"
dialogend >>bHit,...,...,first,prev,next,last,...
else
dialogbegin -60,-30,60,50,"Traverse textblocks."
	pushbutton 15,55,50,70,"OK"
	pushbutton 70,55,105,70,"Cancel"
	radiobutton 5,5,115,15,"Erster Textblock des Textabschnitts"
	radiobutton 5,17,115,27,"Voriger Textblock"
	radiobutton 5,29,115,39,"Nächster Textblock",1
	radiobutton 5,41,115,51,"Letzter Textblock des Textabschnitts"
dialogend >>bHit,...,...,first,prev,next,last,...
endif

if not(bHit="OK")
	return
endif

textedit
gettextlocation >> id,...
id0 = id
switch first,prev,next,last
caseof 1,0,0,0
	settextcursor -2,0,0
	gettextlocation >> id,...
	deselect
	try selectid id
	getlasterror >> err
	if err
		message "Gewünschtes Textobjekt kann nicht gesucht werden."
		selectid id0
	endif
break
caseof 0,1,0,0
	textcursor -char,2
	gettextcursor >> tc
	settextcursor tc
	gettextlocation >> id.prev,...
	deselect
	try selectid id.prev
	getlasterror >> err
	if err
		message "Gewünschtes Textobjekt kann nicht gesucht werden."
		selectid id0
	endif
	if id=id.prev
		message "Bereits im ersten Textblock"
	endif
break
caseof 0,0,1,0
	textcursor +textblock
	gettextcursor >> tc0
	textcursor +char,2
	gettextcursor >> tc
	if tc(2)-tc0(2)<2
		message "Bereits im letzten Textblock"
		deselect;selectid id
		break
	endif
	try settextcursor tc
	getlasterror >> err
	if err
		message "Bereits im letzten Textblock"
		deselect;selectid id
		break
	endif
	gettextlocation >> id.next,...
	deselect
	try selectid id.next
	getlasterror >> err
	if err
		message "Gewünschtes Textobjekt kann nicht gesucht werden."
		selectid id0
	endif
	if id=id.next
		message "Bereits im letzten Textblock"
		deselect;selectid id
	endif
break
caseof 0,0,0,1
	textcursor +story
	textcursor -char
	gettextcursor >> tc
	settextcursor tc
	gettextlocation >> id,...
	deselect
	try selectid id
	getlasterror >> err
	if err
		message "Gewünschtes Textobjekt kann nicht gesucht werden."
		selectid id0
	endif
	break
endswitch
// if textblock falls out of the page/spread, show the pasteboard
getpagerect >> pL,pT,pR,pB
getselectinfo >> L, T, R, B
if (L>pR)+(R<pL)+(T>pB)+(B<pT)
	view pasteboard
endif
return


