PtInitDrag

PtInitDrag --  starts a drag operation.

Syntax

PtInitDrag (widget, container, flags)

		

Arguments

widget

The widget on which the dragging events are to be enabled.

container

The container within which the dragging events are to be confined.

flags

Determiners for the drag operation. For details see PhInitDrag in the Photon documentation.

Returns

nil on success.

Example

This example, ex_PtInitDrag.g, is included in the gamma_ph_#_examples_1_QNX4.tgz file available on the Cogent Web Site.

#!/usr/cogent/bin/phgamma

/*
This example puts a small window on the screen with a text label that
can be dragged.
*/

require_lisp("PhotonWidgets");

PtInit(nil);

win = new(PtWindow);
win.SetDim(200,200);
PtRealizeWidget(win);

lab = new(PtLabel);
lab.text_string = "Drag Me";
PtRealizeWidget(lab);

DraggedWidget := nil;

method PtWidget.StartDrag ()
{
   DraggedWidget = self;
   PtInitDrag (self, nil, Ph_TRACK_DRAG | Ph_DRAG_TRACK);
}

function handle_drag ()
{
   local   event = cbinfo.event, rect;

   if (event.type == Ph_EV_DRAG)
   {
      if (event.subtype == Ph_EV_DRAG_COMPLETE ||
            event.subtype == Ph_EV_DRAG_MOVE)
      {
         if (DraggedWidget)
         {
            rect = TranslateRect (event_data.drag_event.rect,
              event.translation);
            DraggedWidget.SetPos (rect.ul.x, rect.ul.y);
         }
         if (event.subtype == Ph_EV_DRAG_COMPLETE)
            DraggedWidget = nil;
      }
   }
}

PtAttachCallback(win,Pt_CB_RAW,#handle_drag(),Ph_EV_DRAG);
PtAttachCallback(lab,Pt_CB_RAW,#widget.StartDrag(),Ph_EV_BUT_PRESS);

PtMainLoop();
		

See Also

In Photon documentation: PhInitDrag.

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.