PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Overview
  • Defining the sources and the targets
  • Declare the events to manage
  • Acting during an event
  • Hovering the target
  • Drop of Drag and Drop
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
HTML 5: Example for managing the programmed Drag and Drop
Overview
To make a WEBDEV site more interactive, you have the ability to implement Drag and Drop in the pages.
The steps for implementing a programmed Drag and Drop are as follows:
  1. Define the sources and targets of Drag and Drop.
  2. Declare the events to manage.
  3. Act during the events.
Remarks:
  • Drag and Drop in HTML 5 is supported by the Chrome and Firefox browsers (at the time this page is written).
  • Caution: Drag and Drop in HTML 5 cannot be used in the sites displayed on a mobile. Indeed, the technology used cannot make the difference between an action of Drag and Drop and a gesture on mobile.
  • This help page is based on the "WW_Drag_n_Drop_HTML5" example supplied with WEBDEV.
Defining the sources and the targets
The first step consists in identifying the controls that will be used in the Drag and Drop operations.
In our example, you will find:
  • 3 "source" controls: these 3 controls display the images of extinguishers. In the initialization code of these controls (server code), DndSource is used to specify that these controls are the source controls for a programmed Drag and Drop.
    // Indique que le champ est source d'un "Drag and Drop"
    MySelf.DndSource = dndProgram
  • 1 "destination" control: it is the image of the plane. DndTarget is used in the initialization code of this control (server code).
    // Indique que le champ est cible d'un "Drag and Drop"
    MySelf.DndTarget = dndProgram
Declare the events to manage
DnDEvent is used to define the events managed during Drag and Drop. This function expects as parameter:
  • the name of the WLanguage procedure that will be run when the event is triggered.
  • the control on which the event must be managed. You have the ability to specify a control or all the page controls.
  • the event to manage. Several events are available: beginning and end of Drag and Drop, entry into and exit from the target control, hover the target control and drop on the target control. These events are identified by constants (dndXXX).
Two events are supported in our example: rollover and drop.
// Active le Drag and Drop sur l'image du plan
DnDEvent(Survol, IMG_PLAN, dndDragOver)
DnDEvent(Lacher, IMG_PLAN, dndDrop)
Acting during an event

Hovering the target

The "Rollover" procedure is called when the target area is hovered by the user during Drag and Drop.
In our case, during the rollover, the cursor is modified to specify to the user that the action is allowed by the Drag and Drop on this target control.
To do so, use DnDCursor associated with the dndMove constant.
PROCÉDURE Survol
// Modifie le curseur
DnDCursor(dndMove)

Drop of Drag and Drop

Several actions are performed during the drop:
  1. The move action is accepted via DnDAccept.
    PROCÉDURE Lacher
    // On accepte le Drag and Drop
    DnDAccept(dndMove)
  2. The cursor position is retrieved via the _DND.MouseXPos and _DND.MouseYPos variables.
    These variables return the cursor position during the drop on the target.
    // Mémorise la position du curseur
    nXImage = _DND.MouseXPos
    nYImage = _DND.MouseYPos
  3. The source control of "Drag and Drop" is also retrieved. According to the source control, the associated color will be stored for the drawing.
    // Récupère le champ source
    sIDExtincteur = _DND.SourceControl
    // La couleur est différente selon l'extincteur sélectionné
    SWITCH sIDExtincteur
    CASE IMG_EXTINCTEUR.Nom
    nCouleur = 255
    CASE IMG_EXTINCTEUR1.Nom
    nCouleur = 3243262
    CASE IMG_EXTINCTEUR2.Nom
    nCouleur = 65535
    OTHER CASE
    nCouleur = 16706050
    END
  4. The entire data (coordinates, color, size) is stored in an array so that it can be re-used when the drawing is performed by the DrawAll procedure.
    // Sauvegarde les coordonnées
    sCoordonnees = sIDExtincteur + TAB + nXImage + TAB + nYImage + TAB + ...
    SAI_POTENTIOMETTRE + TAB + nCouleur
    // Sauvegarde les informations
    gnIndiceCourant++
    gtabListeCoordonnees[gnIndiceCourant] = sCoordonnees
    // Dessine les extincteurs sur le plan
    DessineTout()
Related Examples:
The features of Drag And Drop HTML5 Unit examples (WEBDEV): The features of Drag And Drop HTML5
[ + ] Using the Drag n Drop HTML 5 features in a WEBDEV site.
Minimum version required
  • Version 17
Comments
Click [Add] to post a comment