Dr Wimp p19

Dragging/double-clicking directory objects

The start of Section 2.10 of the Dr Wimp Manual contains a very important message but, when you are new to Dr Wimp, perhaps its importance isn't always clear. The text is:

"Whenever a file (or directory or application) is 'dragged and dropped' onto a window belonging to your application (or, indeed, just double-clicked on), then FNuser_loaddata is called."

If you then read further, you will find that the return from this user-function needs to be 1 if you actually load any data from the dragged/double-clicked item, or 0 if you don't.

What this last sentence means is that you must be very careful to ensure that a 1 is returned only when you mean it. In practice, this usually means that very specific 'filtering' is needed.

For instance, look at this extreme example:

DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
=1

i.e. just change the return value (from the default of 0) to 1.

If you run a Dr Wimp application with this change you will find that your desktop will just not operate correctly, e.g. it will try to open a directory displayed in a filer window. Nothing will happen!

If you re-read the earlier points, hopefully the penny will drop. You've just double-clicked on a directory; this has caused FNuser_loaddata to be called, and you have made it return a 1. The result is tantamount to telling the Wimp, "Thanks very much for telling me a double-click has taken place on that directory. It is one that I'm interested in and I'll deal with it." So, the Wimp takes you at your word and doesn't pass things on to the filer.

That extreme example helps us take simple steps to prevent this sort of problem in more practical cases, by setting up some 'filtering'. For instance:

DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
return%=0
CASE ftype$ OF
  WHEN "FFF"
  PROCloadtextfile
  return%=1
ENDCASE
=return%

This is a simple filter based on the filetype. The result is that 0 is returned in all cases except when the drag/double-click is with a textfile - in which case some loading action occurs and 1 is duly returned.

You might want to be even more specific and check some feature of the textfile before you decide whether you want to load it:

DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
return%=0
CASE ftype$ OF
  WHEN "FFF"
  check%=FNcheckfile
  IF check%=TRUE THEN
    PROCloadtextfile
    return%=1
  ENDIF
ENDCASE
=return%

Or you might want to insist on dragging a text file rather than also allowing a double-click:

DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
return%=0
IF window%=0 AND icon%=-1 THEN
  CASE ftype$ OF
    WHEN "FFF"
    PROCloadtextfile
    return%=1
  ENDCASE
ENDIF
=return%

These are just a few of the practical filters you can incorporate.

The important thing is to be very careful to control the circumstances that give a return of 1.


Source: Archive 14.07
Publication: Archive Magazine
Contributor: Ray Favre