gWidgets-dnd {gWidgets} | R Documentation

## Functions to add drag and drop ability to widgets

### Description

These functions allow drag and drop between widgets. The basic idea is that one creates drop sources from which one defines values which may be dragged and drop target where values may be dropped. These values can be text, or widgets.

### Usage

    adddropsource (obj, targetType = "text", handler = NULL, action = NULL,
        ...)
    adddropmotion (obj, handler = NULL, action = NULL, ...)
    adddroptarget (obj, targetType = "text", handler = NULL, action = NULL,
        ...)

### Arguments

`obj` | Object to put drop handler on
`targetType` | What type of drop target: either "text" or "pixmap" or "entry".
`handler` | Handler called for the drop motion
`action` | action passed to handler
`...` | Not documented, currently has no role.

### Details

To specify if one can drag values from a widget use `adddropsource` called on the object. The argument `targetType` can be set to `"object"` when the drop value is to be a widget, and not a string. The arguments `handler` and `action` can be used to describe what gets dropped. The default is to drop the widget's contents as returned by `svalue`.

To specify if an object is a drop target the `adddroptarget` method is called on the object. The argument `handler` (but no `action`) is used to handle the drop.

The handler's first argument is a list with named components. The `obj` component refers to the object that has the target placed on it. The component `dropdata` is set by the `adddropsource` method. The dropdata is typically a string, but a mechanism is in place to drop widgets. The default handler for `adddroptarget` is to replace the widget's value with the dropped data.

To add an action to a motion event, use the `adddropmotion` method. The `adddroptarget` must first have been added to the object.

### Value

These functions return an ID returned when registering a handler. The function `removehandler` uses this information to remove a drag and drop handler.

### Author(s)

Implementation of Simon Urbanek's iwidgets API was done by Michael Lawrence and John Verzani

### See Also

gWidgets-methods

### Examples

    ## Not run:
    ## simple dnd
    lab  = glabel("drag me",container=gwindow())
    ed = gedit("drop here",container = gwindow())
    adddropsource(lab)
    adddroptarget(ed)
    adddropmotion(ed,handler=function(h,...) print("bombs away"))

    ## more complicated
    ## this shows that rows of editable data frame can be dropped.
    ## by assigning to the changed signal, the graphs can be dynamic.
    ## THat is, drop a column, then edit it. The graph will update. The key
    ## is referring to the "value" stored in gd. This refers to the column
    ## in the editable data frame.
    ## By using svalue() and id(), the dropped value can also be a
    ## character string referring to a variable in the workspace.
    adf = gdf(mtcars, container = gwindow())
    gd = ggraphics(container = gwindow())
    plotData = function() {
      dropvalue = tag(gd,"value")
      theValues = svalue(dropvalue)
      theName = id(dropvalue)
      hist(theValues, xlab=theName, main="")
    }

    ids = adddroptarget(gd,targetType="object", handler = function(h,...) {
        tag(gd, "value") <- h$dropdata
        plotData()

        if(is.gdataframecolumn(h$dropdata)) {
          view.col = h$dropdata
          id = addhandlerchanged(view.col, handler=function(h,...) plotData())
        }
    })

    ## End(Not run)

[Package gWidgets version 0.0-54.2 Index]