Contents page

DragGadgets




    Drag Gadgets

    Unfortunately, it is not possible to "drag" standard Intuition gadgets.

    An example of a gadget that you can drag would be the disk and file icons in Workbench. You can click on these and drag them to a new position, even in another window.

    Proportional gadgets give you something, but movement is limited to within a window and the bounding boxes the gadgets move within can not overlap.

    The routine DragGadget, coupled with the DragInfo data structure give you the ability to drag Intuition gadgets that are defined with an Image. These gadgets can move across window boundaries (which is very useful for some user interfaces) and the bounding boxes can overlap, the only possible conflict being when the icons themselves overlap.

    The DragInfo Structure

    Because additional information is needed for dragging gadgets, such as the , bounding box, this data structure is used:

        struct DragInfo {
          struct Gadget *Gadget;        /* Gadget to drag */
    
          SHORT LeftEdge,TopEdge,       /* Bounding box. */
                RightEdge, BottomEdge;
    
          USHORT Flags;                 /* Command flags. */
    
          SHORT XPos, YPos;             /* Current position. */
    
          void (*UpdateRoutine)();      /* User supplied routine. */
    
          LONG DD;                      /* Leave this alone. */
        };
        
    A description of each field and how you use it:

    Gadget This is the gadget to drag.
    LeftEdge There is a bounding box you define that the gadget can move within. This defines the left edge of that, relative to the left hand edge of the window. If you wish the left edge of the bounding box to be unlimited, specify a large negative number, like -1000.
    TopEdge This defines the top edge of that bounding box, relative to the top of the window. If you wish the top edge of the bounding box to be unlimited, specify a large negative number, like1000.
    RightEdge This defines the right edge of the bounding box, relative to the left edge of the window. If you wish the right edge of the bounding box to be unlimited, specify a large number, like 1000.
    BottomEdge This defines the bottom edge of the bounding box, relative to w the top of the window. If you wish the bottom of the bounding box to be unlimited, specify a large number, like .... you guess.
    Flags There are several flags you can set that govern the behavior of the drag gadget.
    • DRAG_INWINDOW
      This indicates that the gadget can only be drawn within the RastPort of the window. If clear, it will be drawn directly into the screen's bitmap, so it will travel over other windows, including overlapping ones. A WorkBench file gadget would have this flag cleared so it could drag anywhere in the screen.
    • DRAG_MOVEGADGET
      If you want the gadget to stay in its new position, set this flag. The gadget's LeftEdge and TopEdge value will be adjusted at the end of the drag. Otherwise, it springs back to the original position and you are left with the knowledge of where the icon was dragged to.
    • DRAG_OUTLINE
      If this flag is set, all parts of the gadget image that are color pen 0 are transparent. So, rather than a , rectangular box moving over the picture, you have an outlined shape.
    XPos,YPos This is the current window coordinate of the gadget. You can read this after a move to find out where the user dragged the gadget. And, your UpdateRoutine (see below) can use this.
    UpdateRoutine You can provide a routine that is called every time the gadget moves a pixel. For example, you might wish to dynamically display the coordinates of the gadget as it travels in your window title bar. This routine is passed two parameters:
    • Window
      A pointer to your window.
    • Draglnfo
      A pointer to the DragInfo structure. From this, you can get the current coordinates, the gadget, and any other important information.





    Using Drag Gadgets

    Set up your Intuition gadget as a BOOLGADGET type and give it a gadget render Image. You can also give it a select render Image, which will be the one dragged in that case.

    Set up your DragInfo structure.

    When you receive a GADGETDOWN event for this gadget, call DragGadget(Window,DragInfo). When the gadget has finished being dragged, it will return. You can then read the new coordinates from the DragInfo structure.

    If you are using Drag Gadgets to move icons from one window to another, you need to know which wsndow the gadget was dragged to. Use the routine WhichWindow. WhichWindow is passed a pointer to the window the Drag Gadget belongs to and the final X and Y positions of the gadget (in the originating window's coordinate system.) It returns a pointer to the topmost window that is under the coordinates, if such a window exists.