Beispiel #1
0
static void motListDragStart(Widget w, XButtonEvent* evt, String* params, Cardinal* num_params)
{
  Atom atomListItem = XInternAtom(iupmot_display, "LIST_ITEM", False);
  Atom exportList[1];
  Widget drop_context;
  int idDrag, num_args = 0;
  Arg args[40];
  Ihandle *ih = NULL;

  XtVaGetValues(w, XmNuserData, &ih, NULL);
  if(!ih->handle)
    return;

  exportList[0] = atomListItem;
  idDrag = motListConvertXYToPos(ih, evt->x, evt->y);  /* starts at 1 */

  /* specify resources for DragContext for the transfer */
  num_args = 0;
  iupMOT_SETARG(args, num_args, XmNexportTargets, exportList);
  iupMOT_SETARG(args, num_args, XmNnumExportTargets, 1);
  iupMOT_SETARG(args, num_args, XmNdragOperations, XmDROP_MOVE|XmDROP_COPY);
  iupMOT_SETARG(args, num_args, XmNconvertProc, motListConvertProc);
  iupMOT_SETARG(args, num_args, XmNclientData, idDrag);

  /* start the drag and register a callback to clean up when done */
  drop_context = XmDragStart(w, (XEvent*)evt, args, num_args);

  XtAddCallback(drop_context, XmNdragDropFinishCallback, (XtCallbackProc)motListDragDropFinishCallback, NULL);
  XtAddCallback(drop_context, XmNdragMotionCallback, (XtCallbackProc)motListDragMotionCallback, (XtPointer)ih);

  iupAttribSet(ih, "_IUPLIST_DROPITEM", NULL);

  (void)params;
  (void)num_params;
}
static void motDragStart(Widget dragSource, XButtonEvent* evt, String* params, Cardinal* num_params)
{
  Widget dragContext;
  Arg args[20];
  int num_args = 0;
  Atom *dragTypesList;
  Cardinal dragTypesListCount;
  Ihandle* ih = NULL;

  XtVaGetValues(dragSource, XmNuserData, &ih, NULL);

  dragTypesList = (Atom*)iupAttribGet(ih, "_IUPMOT_DRAG_TARGETLIST");
  dragTypesListCount =  (Cardinal)iupAttribGetInt(ih, "_IUPMOT_DRAG_TARGETLIST_COUNT");
  if (!dragTypesList)
    return;

  /* specify resources for DragContext for the transfer */
  num_args = 0;
  iupMOT_SETARG(args, num_args, XmNexportTargets, dragTypesList);
  iupMOT_SETARG(args, num_args, XmNnumExportTargets, dragTypesListCount);
  iupMOT_SETARG(args, num_args, XmNdragOperations, iupAttribGetBoolean(ih, "DRAGSOURCEMOVE")? XmDROP_MOVE|XmDROP_COPY: XmDROP_COPY);
  iupMOT_SETARG(args, num_args, XmNconvertProc, motDragConvertProc);
  iupMOT_SETARG(args, num_args, XmNinvalidCursorForeground, iupmotColorGetPixel(255, 0, 0));
  iupMOT_SETARG(args, num_args, XmNclientData, ih);

  /* creates a XmDragContext */
  dragContext = XmDragStart(dragSource, (XEvent*)evt, args, num_args);

  if(dragContext)
  {
    IFnii cbDragBegin;

    XtAddCallback(dragContext, XmNdropFinishCallback, (XtCallbackProc)motDropFinishCallback, (XtPointer)ih);

    cbDragBegin = (IFnii)IupGetCallback(ih, "DRAGBEGIN_CB");
    if(cbDragBegin)
    {
      if (cbDragBegin(ih, evt->x, evt->y) == IUP_IGNORE)
        XmDragCancel(dragContext);
    }
  }

  (void)params;
  (void)num_params;
}
Beispiel #3
0
void StartDrag(Widget searchWidget, XEvent *event)
{
  Arg             args[8];
  Cardinal        n;
  Atom            exportList[1];
  Widget          sourceIcon;
  UpdateTask    * pt;
  int             textWidth, maxWidth, maxHeight, fontHeight, ascent;
  unsigned long   fg, bg;
  XButtonEvent  * xbutton;
  XGCValues       gcValues;
  unsigned long   gcValueMask;
  DisplayInfo   * displayInfo;

  static char *channelNames[MAX(MAX_PENS,MAX_TRACES)][2];

  Pixmap sourcePixmap = (Pixmap)NULL;
  static GC gc = NULL;

/* a nice sized font */
#define FONT_TABLE_INDEX 6
/* move the text over... */
#define X_SHIFT 8
#define MARGIN  2

  
  /* (MDA) since widget doing drag could be toggleButton or optionMenu button
   *   (which has more than just flat, single parent),
   *   find the widget that has a parent that is the drawing area and
   *   search based on that *   (since that is what is rooted in the display)
   * - NB if drawing areas as children of the main drawing area are allowed
   *   as parents of controllers/monitors, this logic must change...
   */

  if (XtClass(searchWidget) == xmDrawingAreaWidgetClass
      && 
      strcmp(XtName(searchWidget),stripChartWidgetName) !=0 ) 
  {
    /* starting search from a DrawingArea which is not a StripChart 
     *  (i.e., DL_Display) therefore lookup "graphic" (non-widget) elements ;
     *  get UpdateTask data from position knowledge
     */
    displayInfo = dmGetDisplayInfoFromWidget(searchWidget);
    xbutton = (XButtonEvent *)event;

    pt = getUpdateTaskFromPosition(displayInfo, xbutton->x,xbutton->y);
  } 
  else {
    WidgetUserData * userData;

   /* get UpdateTask data from widget's userData resource
    */
    while (XtClass(XtParent(searchWidget)) != xmDrawingAreaWidgetClass)
      searchWidget = XtParent(searchWidget);
    
    XtVaGetValues (searchWidget, XmNuserData, &userData, NULL);

    if (userData)
      pt = userData->updateTask;
    else {
      pt = getUpdateTaskFromWidget(searchWidget); 
      INFORM_INTERNAL_ERROR();
    }

  }

#define MAX_COL 4

  if (pt) 
  {
    char  * name[MAX_PENS*MAX_COL];
    short   severity[MAX_PENS*MAX_COL];
    int     count = 1;
    int     column;
    int     row;

    if (pt->name == NULL) 
      return;
    else
      (*pt->name)(pt->clientData, name, severity, &count);

    /* T. Straumann: copy the names to the clipboard
     *
     * NOTE: we must copy the name strings, because we
     *		 cannot be 100% sure the updateTask still
     *		 exists at the time the PRIMARY selection 
     *		 is requested.
     */
    if ( count > 0 ) {
       int i;
       
       clipbdStart();
       clipbdAdd(name[0]);
       /* count > 100 means count/100 columns (see dm2kCartesianPlot.c !?!) */
       for ( i=1; i < (count%100); i++) {
	  clipbdAdd("\n");
	  clipbdAdd(name[i]);
       }
       clipbdHold();
    }

    column = count / 100;
    if (column == 0) column = 1;
    if (column > MAX_COL) column = MAX_COL;
    count = count % 100;
    row = 0;

    bg = BlackPixel(display,screenNum);
    fg = WhitePixel(display,screenNum);

    ascent = fontTable[FONT_TABLE_INDEX]->ascent;
    fontHeight = ascent + fontTable[FONT_TABLE_INDEX]->descent;

    if (count == 0) {
      channelName = NULL;
      return;
    } else {
      int i, j;
      int x, y;

      i = 0; j = 0;
      textWidth = 0;
      while (i < count) {
        if (name[i]) {
	  register int tmp = 
	    XTextWidth(fontTable[FONT_TABLE_INDEX],name[i],STRLEN(name[i]));
 	  textWidth = MAX(textWidth,tmp);
        }
        j++;
        if (j >= column) {
          j = 0;
          row++;
        }
        i++;
      }
      maxWidth = X_SHIFT + (textWidth + MARGIN) * column;
      maxHeight = row*fontHeight + 2*MARGIN;
      sourcePixmap = XCreatePixmap(display,
				   RootWindow(display, screenNum),
				   maxWidth,maxHeight,
				   DefaultDepth(display,screenNum));
      if (gc == NULL) 
	gc = XCreateGC(display,sourcePixmap,0,NULL);

      gcValueMask = GCForeground|GCBackground|GCFunction|GCFont;

      gcValues.foreground = bg;
      gcValues.background = bg;
      gcValues.function   = GXcopy;
      gcValues.font       = fontTable[FONT_TABLE_INDEX]->fid;

      XChangeGC(display,gc,gcValueMask,&gcValues);

      XFillRectangle(display,sourcePixmap,gc,0,0,maxWidth,maxHeight);

      i = j = 0;
      x = X_SHIFT;
      y = ascent + MARGIN;

      while (i < count) {
        if (name[i]) {
          XSetForeground(display,gc,alarmColorPixel[severity[i]]);
          XDrawString(display,sourcePixmap,gc,x,y,name[i],STRLEN(name[i]));
          channelName = name[i];
        }

        j++;

        if (j < column) {
          x += textWidth + MARGIN;
        } else {
          j = 0;
          x = X_SHIFT;
          y += fontHeight;
        }

        i++;
      }
    } 
  }

  if (sourcePixmap != (Pixmap)NULL) 
  {
    /* use source widget as parent - can inherit visual attributes that way 
     */
    n = 0;
    XtSetArg(args[n],XmNpixmap,sourcePixmap); n++;
    XtSetArg(args[n],XmNwidth,maxWidth); n++;
    XtSetArg(args[n],XmNheight,maxHeight); n++;
    XtSetArg(args[n],XmNdepth,DefaultDepth(display,screenNum)); n++;
    sourceIcon = XmCreateDragIcon(XtParent(searchWidget),"sourceIcon",args,n);

    /* establish list of valid target types 
     */
    exportList[0] = COMPOUND_TEXT;

    n = 0;
    XtSetArg(args[n],XmNexportTargets,          exportList); n++;
    XtSetArg(args[n],XmNnumExportTargets,       1); n++;
    XtSetArg(args[n],XmNdragOperations,         XmDROP_COPY); n++;
    XtSetArg(args[n],XmNconvertProc,            DragConvertProc); n++;
    XtSetArg(args[n],XmNsourcePixmapIcon,       sourceIcon); n++;
    XtSetArg(args[n],XmNcursorForeground,       fg); n++;
    XtSetArg(args[n],XmNcursorBackground,       bg); n++;
    XtSetArg(args[n],XmNdragDropFinishCallback, dragDropFinishCB); n++;
    XmDragStart(searchWidget,event,args,n);
  }
}
Beispiel #4
0
int
main(int argc, char **argv)
{
  XtAppContext theApp;
  Widget label;
  Pixel fg,bg;
  XmFontList fontlist;

  toplevel = XtVaAppInitialize(&theApp, "drawingArea", NULL, 0,
			       &argc, argv, Fallback, NULL);

  fontlist = XmFontListAppendEntry(NULL,
			   XmFontListEntryCreate("MY_FONT",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));

  fontlist = XmFontListAppendEntry(fontlist,
			   XmFontListEntryCreate("MY_FONT1",
						 XmFONT_IS_FONT,
						 XLoadQueryFont(XtDisplay(toplevel), 
 	                                         "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1")));

#if 0
  label= XtVaCreateManagedWidget("Button1", xmLabelWidgetClass, toplevel, XmNfontList, fontlist,
				NULL);
#else
  label= XtVaCreateManagedWidget("Button1", xmLabelWidgetClass, toplevel,
				NULL);
#endif
  XtRealizeWidget(toplevel);

  theDisplay = XtDisplay(toplevel);
  theRootWindow = XDefaultRootWindow(theDisplay);

  fg = XBlackPixelOfScreen(DefaultScreenOfDisplay(theDisplay));
  bg = XWhitePixelOfScreen(DefaultScreenOfDisplay(theDisplay));

  Pix = XmGetPixmap(DefaultScreenOfDisplay(theDisplay),
                    "xlogo64",
                    fg, bg);
  if (Pix == XmUNSPECIFIED_PIXMAP) {
	printf("NO PIXMAP!\n");
	exit(0);
  }

  XtVaSetValues(label,
	        XmNlabelPixmap,Pix, 
                XmNlabelType,XmPIXMAP,
                NULL);

  printf("%p\n", XmDragStart(label, NULL, NULL, 0));
  
{
    static XtWidgetGeometry Expected[] = {
   CWWidth | CWHeight            ,   57,   73,   46,   17, 0,0,0, /* Button1 */ 
    };
    PrintDetails(  toplevel ,Expected);
};
   LessTifTestMainLoop(  toplevel );

  exit(0);
}