gWidgets-dnd            package:gWidgets            R Documentation

_F_u_n_c_t_i_o_n_s _t_o _a_d_d _d_r_a_g _a_n_d _d_r_o_p _a_b_i_l_i_t_y _t_o _w_i_d_g_e_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

     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

     ...: 

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

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

_A_u_t_h_o_r(_s):

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

_S_e_e _A_l_s_o:

     gWidgets-methods

_E_x_a_m_p_l_e_s:

     ## 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, cont = TRUE)
     gd = ggraphics(cont = TRUE)
     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)

