home *** CD-ROM | disk | FTP | other *** search
- App TextCopy
- In -
- Out TextCopy
- Type Module
- Ver 1.11b
-
- Define Workspace
- Name DragBox
- Default r9
- Prefix db_
- `left ! left of icon
- `bottom ! bottom of icon
- `right ! right of icon
- `top ! top of icon
- Name workspace
- Default r12
- `filehandle ! handle of file to save to
- `window ! window being dragged to/from
- `icon ! icon being dragged to/from
- `left ! left of icon
- `bottom ! bottom of icon
- `right ! right of icon
- `top ! top of icon
- `flags ! icon flags
- `str ! string pointer
- `valid ! validation pointer
- `length ! length of string
- `eventtype ! Temporary store for event type
- `saveaddr ! Address of text to save out
- `savelen ! Length of text to save out
- `dragbox ^DragBox
- `userblock ! Pointer to users block
- `ptrblock ! Block for pointer information, and x co-ordinate of mouse
- `mousey ! y co-ordinate of mouse
- `mouseb ! button state of mouse
- `mousew ! window mouse is over
- `mousei ! icon mouse is over
- `dragging ! marker showing the current dragging state
- End Workspace
-
- Define Module
- Name TextCopy
- Help Text Copy
- Author Justin Fletcher
- Init InitCode
- Commands
- Name TextCopy
- Help ...
- The TextCopy allows you to drag text files directly on to writable
- icons. This is done by use of filters, so this may clash with
- applications which process text files dragged onto writeable icons.
- If multiple writable icons are present, then the text will span
- these.|M
- Holding down Shift when dragging will copy the filename into the icon.
- |M|MDragging of writable icons is also possible for type 15 icons and
- for all icons if the AllWCD module is present.|M|M
- Holding down Ctrl when dragging will bypass the both patches.
- End Commands
- Workspace `len_workspace
- PostFilter
- Name Text Copy
- Code filtercode
- Task -
- Accept Null
- Accept DragDropped
- Accept MouseClick
- Accept Message
- Accept MessageRec
- Accept MessageAck
- End Filter
- End Module
-
- # REM OFF
- .InitCode
- STMFD (sp)!,{r0,link}
- MOV r0,#0
- STRW r0,`dragging
- LDMFD (sp)!,{r0,pc}
-
- .filtercode
- STMFD (sp)!,{r1-r2,link}
- CMP r0,#0
- BEQ checknullevent
- CMP r0,#6
- BEQ ismouseclick
- CMP r0,#7
- BEQ isdragdone
- CMP r0,#17
- CMPNE r0,#18
- BEQ ismessage
- CMP r0,#19
- BEQ ismessageack
- LDMFD (sp)!,{r1-r2,pc}
-
- .ismessageack
- STRW r0,`eventtype
- REM "%c04%c30Acknowledged"
- LDR r2,[r1,#16]
- CMP r2,#1
- BEQ isNoDataSaveAck ; Nobody loves me, so transfer dies…
- B exitevent
- .ismessage
- STRW r0,`eventtype
- LDR r2,[r1,#16]
- REM "%c04%c30Message %&2"
- CMP r2,#1
- BEQ isDataSave ; Initial message, can I save to you ?
- CMP r2,#3
- BEQ isDataLoad ; Please load this data from me…
- CMP r2,#2
- BEQ isDataSaveAck ; I want your data, give it to me now…
- .exitevent
- LDRW r0,`eventtype
- LDMFD (sp)!,{r1-r2,pc}
-
- .isDataSaveAck
- LDRW r0,`dragging
- CMP r0,#2
- BNE exitevent
- REM "Data save initiated..."
- MOV r0,#10
- ADD r1,r1,#44 ; address in block of filename
- REM "File name to save as %$1"
- LMOV r2,#&FFF ; filetype
- LDRW r4,`saveaddr ; start address
- LDRW r5,`savelen ; length
- ADD r5,r5,r4 ; end address
- REM "Save memory %&4 - %&5"
- SWI "OS_File" ; save file
- SUB r1,r1,#44 ; restore block pointer
- MOV r0,#3 ; acknowledge sending of data
- STR r0,[r1,#16] ; store in block
- LDR r0,[r1,#8] ; get their ref
- STR r0,[r1,#12] ; store in our ref to mark as reply
- LDR r2,[r1,#4] ; task to return to
- MOV r0,#17
- SWI "Wimp_SendMessage" ; tell them...
- MOV r0,#0
- STRW r0,`dragging ; mark as not dragging
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
-
- .isNoDataSaveAck
- LDRW r0,`dragging
- CMP r0,#2
- BNE exitevent
- MOV r0,#0
- STRW r0,`dragging ; mark as not dragging
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
-
- .isDataSave
- ; check for the correct icon
- REM "Check icon"
- BL checkctrl
- BEQ exitevent
- LDR r2,[r1,#40]
- ADD r2,r2,#1
- CMP r2,#&1000
- BNE exitevent
- BL checkshift ; is shift pressed ?
- BEQ exitevent ; if so then exit, 'cos we can't deal with it here
- LDR r3,[r1,#20] ; window
- LDR r4,[r1,#24] ; icon
- BL isdragok
- CMP r0,#0
- BEQ exitevent
- LDMFD (sp),{r1}
- ; end of check
- MVN r2,#NOT -1
- STR r2,[r1,#36] ; data not safe
- MOV r2,#128
- STR r2,[r1,#0] ; length of block
- MOV r2,#2
- STR r2,[r1,#16] ; ok save file message
- LDR r2,[r1,#8]
- STR r2,[r1,#12] ; note message number
- LADR r3,`ourfilename
- ADD r4,r1,#44 ; start of filename
- $DSfilenameloop
- LDRB r2,[r3],#1
- STRB r2,[r4],#1
- CMP r2,#31
- BGT $DSfilenameloop
- MOV r0,#17
- LDR r2,[r1,#4]
- SWI "Wimp_SendMessage"
- MOV r0,#0
- LDMFD (sp)!,{r1-r2,pc}
-
- .isDataLoad
- ; check for the correct icon
- REM "DataLoad"
- BL checkctrl
- BEQ exitevent
- BL checkshift ; is shift pressed ?
- BNE $notshift
- LDREQ r2,[r1,#36] ; if so then is this data safe ?
- CMNEQ r2,#1 ; is it -1 (unsafe ?)
- BEQ exitevent
- B $oktoload
- $notshift
- LDR r2,[r1,#40]
- ADD r2,r2,#1
- CMP r2,#&1000
- BNE exitevent
- $oktoload
- LDR r3,[r1,#20] ; window
- LDR r4,[r1,#24] ; icon
- BL isdragok
- CMP r0,#0
- BEQ exitevent
- ; end of check
- LDMFD (sp),{r1}
- LDRW r3,`str
- LDRW r4,`length
- ADD r1,r1,#44 ; filename
- BL checkshift ; is shift drag ?
- BEQ doshiftdrag ; if so then only copy filename…
- MOV r0,#&40 ; opening file for input
- SWI "OS_Find" ; open file
- STRW r0,`filehandle
- REM "Handle %r0"
- $DLreaddataiconloop
- LDRW r3,`str
- LDRW r4,`length
- $DLreaddataloop
- LDRW r1,`filehandle
- MOV r0,#&7F ; check EOF
- SWI "OS_Byte"
- CMP r1,#0
- BNE $DLeof
- CMP r4,#1 ; is this last char
- BEQ $DLnexticon ; if so, next icon
- LDRW r1,`filehandle
- SWI "XOS_BGet"
- STRB r0,[r3],#1
- CMP r0,#31 ; is this terminator
- BLE $DLnexticon ; if so, next icon
- SUB r4,r4,#1
- B $DLreaddataloop
- $DLnexticon
- BL updateicon
- MOV r0,#0
- STRB r0,[r3],#1
- LDRW r4,`icon
- ADD r4,r4,#1
- STRW r4,`icon ; next icon
- LDRW r3,`window
- BL isdragok
- CMP r0,#0 ; is next icon valid
- BEQ $DLnomore
- B $DLreaddataiconloop
- $DLeof
- LDRW r4,`str
- CMP r4,r3 ; have we stored anything yet ?
- MOVNE r0,#0
- STRNEB r0,[r3],#1
- BLNE updateicon ; and only update if we have changed it...
- $DLnomore
- LDRW r1,`filehandle
- MOV r0,#0 ; r0=0 close file
- SWI "OS_Find"
- ._DLconfirm
- LDMFD (sp),{r1}
- MOV r0,#4
- STR r0,[r1,#16]
- LDR r0,[r1,#8]
- STR r0,[r1,#12]
- LDR r2,[r1,#4]
- MOV r0,#17
- SWI "Wimp_SendMessage"
- MOV r0,#0
- LDMFD (sp)!,{r1-r2,pc}
-
- .doshiftdrag
- ; > r1=filename
- ; r3=store location
- ; r4=length of string
- $loop
- CMP r4,#1 ; how much space left ?
- BLE $exit ; is terminator then exit
- LDRB r0,[r1],#1 ; get byte of filename
- STRB r0,[r3],#1 ; store in block
- CMP r0,#31 ; is this terminator
- BLE $exit ; if so, then exit
- SUB r4,r4,#1
- B $loop
- $exit
- BL updateicon
- B _DLconfirm
-
- .isdragok
- STMFD (sp)!,{r1-r4,link}
- REM "Win = %&3"
- REM "Icon = %&4"
- STRW r3,`window
- STRW r4,`icon
- ADRW r1,`window
- SWI "XWimp_GetIconState"
- BVS $notdragok
- LDRW r2,`flags
- TST r2,#(1<<8) ; is it indirected
- BEQ $notdragok
- AND r3,r2,#(15<<12)
- CMP r3,#(14<<12) ; write/click/drag
- CMPNE r3,#(15<<12) ; writeable
- BNE $notdragok
- MOV r0,#1
- REM "Icon valid"
- LDMFD (sp)!,{r1-r4,pc}
- $notdragok
- MOV r0,#0
- REM "Icon not valid"
- LDMFD (sp)!,{r1-r4,pc}
-
- .updateicon
- STMFD (sp)!,{r0-r5,link} ; Stack registers
- REM CHR$4+"%IUpdating icon"
- ADRW r1,`window
- SWI "Wimp_GetIconState"
- ADD r1,r1,#8 ; remove first two words
- LDMIA r1,{r1-r4} ; read lbrt into r1,r2,r3,r4
- LDRW r0,`window
- SWI "Wimp_ForceRedraw"
- LDMFD (sp)!,{r0-r5,pc} ; Return from call
-
- ; Check if the shift key is pressed
- ; < EQ if pressed
- .checkshift
- STMFD (sp)!,{r0-r2,link}
- MOV r0,#&79 ; Keyboard scan OS_Byte code
- MOV r1,#&80 ; SHIFT key code
- SWI "XOS_Byte" ; Call OS_Byte to read status
- TEQ r1,#&FF ; is it pressed ?
- LDMFD (sp)!,{r0-r2,pc}
- ; Check if the ctrl key is pressed
- ; < EQ if pressed
- .checkctrl
- STMFD (sp)!,{r0-r2,link}
- MOV r0,#&79 ; Keyboard scan OS_Byte code
- MOV r1,#&81 ; CTRL key code
- SWI "XOS_Byte" ; Call OS_Byte to read status
- TEQ r1,#&FF ; is it pressed ?
- LDMFD (sp)!,{r0-r2,pc}
-
- .`ourfilename:EQUS "<Wimp$Scrap>":EQUB 0:ALIGN
-
- .ismouseclick
- STMFD (sp)!,{r3-r9} ; Stack registers
- LDR r0,[r1,#8]
- REM "Button event = %&0"
- BL checkctrl
- LDRNE r0,[r1,#8] ; get buttons if ctrl not pressed…
- TSTNE r0,#&40 ; …is this a select drag ?
- BEQ $exit ; if either then exit
- ; SWI &104
- REM "Checking drag is ok"
- LDR r3,[r1,#12] ; window
- LDR r4,[r1,#16] ; icon
- BL isdragok
- CMP r0,#0
- BEQ $exit
- $isdrag
- LDRW r2,`window
- MVN r3,#NOT -1
- MOV r0,#19
- SWI "XWimp_SendMessage" ; find the task handle
- BVS $exit
- MOV r6,r2 ; r6=task handle
- MOV r8,#0 ; r8=pointer to rma
- MOV r7,#0 ; r7=length of area (0 bytes)
- ADR r2,`textfile ; large text file icon to drag
- BL setdrag
- BL addline
- ; SWI &104
- REM "Is one of our drag requests!!!"
- MOV r0,#1
- STRW r0,`dragging
- STRW r8,`saveaddr
- STRW r7,`savelen
- REM "Data is length %r7, containing %$8"
- B $noaction
- $noaction
- MOV r0,#0
- LDMFD (sp)!,{r3-r9} ; Restore registers
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
- $exit
- MOV r0,#6
- LDMFD (sp)!,{r3-r9} ; Restore registers
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
-
- .`textfile
- EQUS "File_FFF"+CHR$0
- .`smallfile
- EQUS "Small_FFF"+CHR$0
- ALIGN
-
- ; set the drag icon
- .setdrag
- STMFD (sp)!,{r0-r5,link} ; Stack registers
- CMP r8,#0 ; is the current pointer set ?
- SWINE "DragASprite_Stop" ; if not then stop the current drag
- ADRW r1,`dragbox
- SWI "Wimp_GetPointerInfo"
- LDMIA r1,{r0-r1}
- SUB r0,r0,#34 ; x0=x-34 (½ width of box)
- SUB r1,r1,#34 ; y0=y-34 (½ height of box)
- ADD r2,r0,#34*2 ; x1=x0+64 (width of box)
- ADD r3,r1,#34*2 ; y1=y0+64 (height of box)
- ADRW r5,`dragbox
- STMIA r5,{r0-r3} ; store drag box in block in WS
- LDR r2,[sp,#8] ; r2=sprite name
- MOV r0,#%11000101 ; centre, constrain pointer, do shadow
- MOV r1,#1 ; use Wimp sprite area
- MOV r3,r5 ; r3=dragbox pointer
- SWI "DragASprite_Start"
- REM "Starting drag"
- LDMFD (sp)!,{r0-r5,pc} ; Return from call
-
- .wait
- STMFD (sp)!,{r0-r1,link} ; Stack registers
- SWI "OS_ReadMonotonicTime"
- ADD r1,r0,#5 ; r1=time now + delay
- $loop
- SWI "OS_ReadMonotonicTime"
- CMP r0,r1 ; have we exceeded delay ?
- BLT $loop ; if not then keep checking…
- LDMFD (sp)!,{r0-r1,pc} ; Return from call
-
- ; Add a line from the icon pointed to by the block
- .addline
- STMFD (sp)!,{r0-r5,link} ; Stack registers
- LDRW r0,`str ; r0=string
- BL lenctrl ; how long is the string
- REM "Checking length = %r1, current block = %&8"
- ; REM "String located at %&0"
- ; LDMFD (sp)!,{r0-r5,pc} ; Return from call
- ;
- CMP r8,#0 ; is this the first call ?
- MOVEQ r0,#6 ; if so then claim new block
- MOVNE r0,#13 ; otherwise extend it
- MOVNE r2,r8
- MOV r3,r1 ; r3=amount to claim/extend
- ADD r3,r1,#1 ; add extra byte for LF
- SWI "OS_Module" ; claim/extend
- MOV r8,r2 ; r8=new area pointer
- ADD r1,r2,r7 ; r2=end of previous area
- LDRW r0,`str ; r0=pointer to string to copy
- REM "Moving %&0 to %&1"
- BL movectrl ; copy it to the new area
- ADD r7,r7,r3 ; increment amount to copy
- MOV r0,#10 ; LF to add to end of line!
- SUB r1,r7,#1 ; store as last byte
- STRB r0,[r8,r1] ; and store in memory
- LDMFD (sp)!,{r0-r5,pc} ; Return from call
-
- .isdragdone
- STMFD (sp)!,{r3-r9} ; Stack registers
- LDRW r0,`dragging
- CMP r0,#1
- CMPNE r0,#3
- BNE $exit
- REM "%c04Drag done, in state %r0"
- SWI "DragASprite_Stop"
- SWI "Wimp_GetPointerInfo"
- LDMIA r1,{r2,r3,r4,r5,r6}
- REM "%R"
- STR r5,[r1,#20] ; store mx
- STR r6,[r1,#24] ; store my
- STR r2,[r1,#28] ; store mw
- STR r3,[r1,#32] ; store mi
- MOV r2,#56 ; block length
- MOV r3,#0 ; to
- MOV r4,#0 ; ref
- MOV r5,#0 ; ref
- MOV r6,#1 ; message
- STMIA r1,{r2-r6} ; store in block
- ADR r0,`estlen ; address of estimated length
- LDMIA r0,{r2-r6}
- ADD r0,r1,#36
- STMIA r0,{r2-r6} ; copy into block
- MOV r0,#18 ; send recorded delivery…
- LDR r2,[r1,#20] ; get window to send to
- LDR r3,[r1,#24] ; get icon to send to
- REM "Sending to %&2"
- SWI "XWimp_SendMessage"
- MOVVS r0,#0 ; not dragging if error
- MOVVC r0,#2 ; if no error then on to save data message
- STRW r0,`dragging
- REM "Message sent, ok = %r0"
- $noaction
- MOV r0,#0
- LDMFD (sp)!,{r1-r9,pc} ; Return from call
- $exit
- MOV r0,#7
- LDMFD (sp)!,{r1-r9,pc} ; Return from call
-
- .`estlen
- EQUD -1 ; data not safe
- .`texttype
- EQUD &FFF
- .`savename
- EQUS "Icontext"+CHR$0
-
- .checknullevent
- LDRW r2,`dragging
- REM "%c04%c30Current state = %r2"
- CMP r2,#1
- BEQ isnullevent
- CMP r2,#3
- LDMNEFD (sp)!,{r1-r2,pc} ; return if not a small drag
- STMFD (sp)!,{r3-r9} ; Stack registers
- ADRW r1,`ptrblock
- SWI "Wimp_GetPointerInfo"
- LDRW r0,`mouseb
- TST r0,#4
- BEQ $dropped ; if you drop, but still hold adjust
- TST r0,#1 ; adjust ?
- BNE $exit ; if still pressed then exit
- BL wait
- LDRW r8,`saveaddr ; get save address
- ADR r2,`textfile ; swap back to biggy
- BL setdrag
- MOV r0,#1
- STRW r0,`dragging
- MOV r0,#0
- $exit
- LDMFD (sp)!,{r3-r9}
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
- $dropped
- LDMFD (sp)!,{r3-r9}
- MOV r0,#0
- B isdragdone
-
- .isnullevent
- STMFD (sp)!,{r3-r9} ; Stack registers
- STRW r1,`userblock
- ADRW r1,`ptrblock
- SWI "Wimp_GetPointerInfo"
- LDRW r0,`mouseb
- TST r0,#1 ; adjust ?
- BEQ $exit
- LDRW r3,`mousew
- LDRW r4,`mousei
- BL isdragok
- CMP r0,#0 ; is it a valid icon to add ?
- BEQ $exit
- MOV r0,#5 ; read current task handle
- SWI "Wimp_ReadSysInfo"
- MOV r9,r0 ; r9=current task
- ; read task handle we are over
- LDRW r1,`userblock
- MOV r2,r3
- MOV r3,r4
- MOV r0,#19
- SWI "XWimp_SendMessage" ; find the task handle
- REM CHR$4+"%ICurrent = %&9, over = %&2, win = %&3, icon=%&4"
- CMP r2,r9 ; are they the same task ?
- BEQ $gotarea ; if they are then `str is in right place
- MOV r0,r2 ; r0=source (over)
- LDRW r1,`str ; r1=source data (in over)
- MOV r2,r9 ; r2=dest (current)
- LDRW r3,`userblock ; r3=dest data (in current - users block!)
- MOV r4,#256 ; r4=length
- REM "Move from T%&0 to T%&2, from A%&1 to A%&3"
- SWI "Wimp_TransferBlock"
- MOV r0,#0
- STRB r0,[r3,#255] ; add a terminator in case the string is long
- STRW r3,`str ; store in block so that addline can find it
- $gotarea
- LDRW r3,`str
- REM "Is one of ours, is %$3"
- LDRW r7,`savelen
- LDRW r8,`saveaddr
- REM "Currently says %$8"
- BL addline
- STRW r8,`saveaddr
- STRW r7,`savelen
- LADR r2,`smallfile
- BL setdrag
- MOV r0,#3
- STRW r0,`dragging ; mark as currently dragging small
- $exit
- MOV r0,#0
- LDMFD (sp)!,{r3-r9} ; Restore registers
- LDMFD (sp)!,{r1-r2,pc} ; Return from call
-
- #Library "Strings",lenctrl.movectrl
- # POST
- # RUN <CODE>
- # END
-
-