home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
drgfil.zip
/
drgfiles.doc
< prev
next >
Wrap
Text File
|
1993-07-31
|
8KB
|
147 lines
DRGFILES.EXE is a sample program for OS/2 Drag/Drop facilities (aka Direct
Manipulation). It implements the DrgDragFiles and DrgAcceptDroppedFiles API's
which together provide the simplest way to implement Drag and Drop. Of course
with simplicity comes limitations. The following are the limitations of using
these API's to implement Drag and Drop:
1. Only filenames can be dragged/dropped. Therefore anything you drag must
be able to be represented by a file name.
2. Source printing of dragged files is not supported. When you drag a file
to the printer using DrgDragFiles, the printer is in full control of the
printing of the file. Therefore the filename that is being dragged must
be in a format that can be printed native by the printer objects. When the
user drops the icon on the printer, the printer will ask the user what
type of file it is, etc. if that information is not embedded in the drag
info or attached to the file's EA's. Under normal Drag/Drop, your window
can choose to do the printing itself. With DrgDragFiles your window
doesn't have that option.
3. Source shredding of dragged files is not supported. Again, the shredder
will try and delete your file. There is no way for your program to take
part in the delete. This is important because your program's window will
not be able to remove the bitmap representing the file since it doesn't
know that the object was dropped on the shredder.
4. Only 1 image is allowed under the mouse pointer during the drag. Usually
on a multiple-item drag the user expects more than one icon to be under
the mouse pointer during the drag. You can't do that using DrgDragFiles.
This API allows only one icon handle.
5. There are currenty many bugs in this API pair that cause PMDRAG.DLL to
trap (as of 2.1GA in September 1993) if more than 1 file is dropped or
rendering is done. Therefore I've only been able to get it to work
reliably by dragging one file at a time and not rendering. These are of
course major limitations but they are bugs and will hopefully be fixed.
The most obvious advantage to using these API's is their simplicity.
A MAJOR advantage to using these simple API's is that you are excused from
the duties of freeing the drag/drop structures when the drag/drop is done. So
if your app can live with the above limitations, you should seriously consider
using these API's.
DRGFILES creates 2 frame windows. One of the windows plays the role of a 'drag'
window, the other plays the role of a 'drop' window. Their roles are not
interchangeable. The 'Drag' frame window has a container control as its client
window and that container has 5 icons that can be dragged to the 'drop' window.
The 'Drop' frame window has a normal client window. The client window has a
container control as a child and the container takes up the right half of the
client window. The left half is where you will drop the icons from the drag
container. When the icon is dropped on the client area, it is added to the
'Drop' container. If it was a 'move' operation, it is removed from the 'drag'
container.
There are currently 2 major OS/2 bugs that impact this sample program:
1. When dropping more than one icon on the 'drop' window's client area,
PMDRAG.DLL traps when processing the second file. Therefore the 'drag'
container was implemented with CCS_SINGLESEL, meaning only one item can
be selected at any given time. DRGFILES.C has a global variable named
flSelType that is currently set to CCS_SINGLESEL. You can change it to
CCS_EXTENDSEL if you want to see the trap or if you want to test it after a
new release of OS/2 comes out. All the code is in the program to allow more
than one item to be dragged. The only thing stopping it is that CCS_ flag.
2. When rendering is enabled, PMDRAG.DLL traps when the source sends the
target a DM_FILERENDERED message after doing the rendering. Therefore
rendering is disabled, yet all the code remains if you choose to re-enable
it. To enable rendering, set the fRender global variable in drgfiles.c to
TRUE. It is currently set to FALSE.
The reason that containers are used is not to make the program more complex. On
the contrary, containers make Drag/Drop easier to program because the app does
not have to draw representations of things that can be dragged and dropped. The
container provides simple facilities to place draggable icons into its window.
To run this sample program, type DRGFILES on the command line. The 2 windows
will appear on the bottom of your display. The left-hand container is the 'drag'
container, the right one is the 'drop' container. Drag one or more icons from
the 'drag' container to the 'drop' window and drop on the part of the 'drop'
window that says 'DROP IT HERE'. When you do, the icon will appear
in the 'drop' window's container. The default is to 'copy' the file. If you
press the Shift key while dragging, the default will change to be a 'move'. In
that case, the icon will be removed from the source container at drop time.
When the target window first comes up it calls DrgAcceptDroppedFiles to
'register' with PMDRAG.DLL so that PMDRAG can do all the low-level Drag/Drop
stuff. When the source window's container gets a WM_BEGINDRAG message, it sends
a WM_CONTROL/CN_INITDRAG message to its owner, the frame window. At that time
the frame calls DrgDragFiles and they're off and running.
Here is the message flow:
SOURCE TARGET
────── ──────
call DrgAcceptDroppedFiles
CN_INITDRAG...call DrgDragFiles.........
..................( user drops files )... DM_DRAGFILECOMPLETE
DM_DRAGFILECOMPLETE......................
There is one DM_DRAGFILECOMPLETE message for each file that was dropped.
Very simple, no?
If rendering is enabled there is just slightly more to it:
SOURCE TARGET
────── ──────
call DrgAcceptDroppedFiles
CN_INITDRAG...call DrgDragFiles.........
..........( user drops files )..........
DM_RENDERFILE.. (source renders file)...
source sends DM_FILERENDERED to target.. DM_FILERENDERED
DM_DRAGFILECOMPLETE (from PMDRAG)
DM_DRAGFILECOMPLETE (from PMDRAG).......
DM_RENDERFILE happens for each file, as does DM_FILERENDERED and
DM_DRAGFILECOMPLETE.
This is basically it. PMDRAG knows that filenames are being dragged so it can
do all the move/copy/delete file operations for you. If you use rendering,
you do those operations. If an error happens during a file operation, the
appropriate window gets a DM_DRAGERROR message.
DRGFILES.EXE is built from 3 source modules:
DRGFILES.C - base code that has the message queue and supporting functions.
SRCWIN.C - creates the source window and handles the Drag/Drop for it.
TRGWIN.C - creates the target window and handles the Drag/Drop for it.
Hope this sample program helps someone.
===============================================================================
GLOBAL HISTORY
7-31-93 - Completed coding.
===============================================================================
Rick Fishman
Code Blazers, Inc.
4113 Apricot
Irvine, CA 92720
CIS ID: 72251,750