/* 
    FinalWriter: Objekt-Duplizieren - 8.4.94 - von Gunther Lemm
*/

if ~show('L',"rexxreqtools.library") then addlib('rexxreqtools.library',0,-30,0)

titel="ARexx-Macro: Objekt duplizieren"
Address='FinalW'
Options results

STATUS PORTNAME
address = result

trans=0 ; r='0a'x ; tags="rtgs_flags=gsreqf_centertext"

CURRENTOBJECT
if result=0 then do ; void=rtezrequest("    Kein Objekt ausgewählt!    ",,titel) ; exit ; end
mainid=result

GETDOCITEMPREFS DECIMAL
if result="Comma" then trans=1

oldinp=getclip("GFX-DUP")
if oldinp="" then oldinp="1 0,5 0,5"

t1= "Objekt Duplizieren..."||r
t2="Die drei Parameter bitte jeweils durch"||r
t3="ein Leerzeichen voneinander trennen."||r||r
t4="<Anzahl> <X-Verschiebung> <Y-Verschiebung>"

nochmal:
back=rtgetstring(oldinp,t1||t2||t3||t4,titel,"Duplizieren|ABBRUCH",tags)
if back="" then exit
void=setclip("GFX-DUP",back)
back=translate(back,"..",",.")
parse var back num xoff yoff

if (datatype(num,"W")=0 | datatype(xoff,"N")=0 | datatype(yoff,"N")=0) then
 do
  back=rtezrequest("Falsches Zahlenformat","Nochmal|ABBRUCH",titel)
  if back=0 then exit
  else call nochmal
 end

if num>99 then back=rtezrequest(num||" Kopien? - Ist das nicht ein bißchen viel?","Kopier mir das!|Lieber nicht!",titel)
if back=0 then call nochmal

COPY

GETPAGESETUP WIDTH HEIGHT
result=translate(result,"..",",.")
parse var result pw ph .

GETOBJECTCOORDS mainid
result=translate(result,"..",",.")
parse var result p x y w h .

GETOBJECTTYPE
if (result=2 | result=3) then line=1
else line=0

nonstop=0
do n=1 to num
 x=x+xoff
 y=y+yoff
 if line=1 then
  do
   w=w+xoff
   h=h+yoff
  end

  if line=1 then do ; xx=w ; yy=h ; end 
  else do ; xx=w+x ; yy=h+y ; end

 if (x<0 | xx>pw | y<0 | yy>ph) & nonstop=0 then
  do
   back=rtezrequest("Objekt außerhalb der Seite!","Weiter!|Noch'ne Kopie!|ABBRUCH",titel)
   if back=0 then
    do
     CURRENTOBJECT
     DELETEOBJECT result
     exit
    end
   if back=1 then nonstop=1
   else nonstop=0
  end

 PASTE
 CURRENTOBJECT
 if trans=1 then tr=translate(x||" "||y||" "||w||" "||h,",,",".,")
 else tr=x||" "||y||" "||w||" "||h

 parse var tr xt yt wt ht
 id=result
 SETOBJECTCOORDS id p xt yt wt ht
end

REDRAW
exit
