home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1999 March / PCShareware-3-99.iso / IMPLE / DJGPP.RAR / DJGPP2 / XLIB-SR0.ZIP / SRC / XLIBEMU / SELECTIO.C < prev    next >
C/C++ Source or Header  |  1994-01-14  |  3KB  |  135 lines

  1. /* $Id: selectio.c 1.2 1994/01/15 02:18:38 ulrich Exp $ */
  2. /*
  3.  * selection.c
  4.  *
  5.  * X library functions for selections.
  6.  */
  7. #include "Xlibemu.h"
  8.  
  9. extern Time _WCurrentTime();
  10.  
  11.  
  12. typedef struct {
  13.   Atom selection;
  14.   Window owner;
  15.   Time last_change;
  16. } _WSelection;
  17.  
  18. typedef struct {
  19.   int next;
  20.   int size;
  21.   _WSelection *selections;
  22. } _WSelectionList;
  23.  
  24. _WSelectionList _SelList = { 0 };
  25.  
  26.  
  27.  
  28. XSetSelectionOwner(dpy, selection, owner, time)
  29.      register Display *dpy;
  30.      Atom selection;
  31.      Window owner;
  32.      Time time;
  33. {
  34.   int i;
  35.   _WSelection *sp;
  36.   XEvent xe;
  37.  
  38.   for (i = _SelList.next; --i >= 0; ) {
  39.     if (_SelList.selections[i].selection == selection)
  40.       break;
  41.   }
  42.   if (i < 0) {
  43.     if (_SelList.next >= _SelList.size) {
  44.       _SelList.size += _SelList.size/2 + 1;
  45.       _SelList.selections = (_WSelection *)
  46.     Xrealloc (_SelList.selections,
  47.           _SelList.size * sizeof(_WSelection));
  48.     }
  49.     i = _SelList.next++;
  50.     _SelList.selections[i].selection = selection;
  51.     _SelList.selections[i].owner = None;
  52.     _SelList.selections[i].last_change = 0;
  53.   }
  54.   sp = &_SelList.selections[i];
  55.   if (time == CurrentTime)
  56.     time = _WCurrentTime();
  57.   if (time < sp->last_change || time > _WCurrentTime()) {
  58.     return 0;
  59.   }
  60.   sp->last_change = time;
  61.   if (sp->owner != None && sp->owner != owner) {
  62.     xe.xselectionclear.type = SelectionClear;
  63.     xe.xselectionclear.send_event = False;
  64.     xe.xselectionclear.display = dpy;
  65.     xe.xselectionclear.window = sp->owner;
  66.     xe.xselectionclear.selection = selection;
  67.     xe.xselectionclear.time = sp->last_change;
  68.     _XEnq (dpy, &xe);
  69.   }
  70.   sp->owner = owner;
  71.   return 1;
  72. }
  73.  
  74.  
  75. Window XGetSelectionOwner(dpy, selection)
  76. register Display *dpy;
  77. Atom selection;
  78. {
  79.   int i;
  80.  
  81.   for (i = _SelList.next; --i >= 0; ) {
  82.     if (_SelList.selections[i].selection == selection)
  83.       break;
  84.   }
  85.   if (i < 0) {
  86.     return None;
  87.   }
  88.   return _SelList.selections[i].owner;
  89. }
  90.  
  91. XConvertSelection(dpy, selection, target, property, requestor, time)
  92. register Display *dpy;
  93. Atom selection, target;
  94. Atom property;
  95. Window requestor;
  96. Time time;
  97. {
  98.   int i;
  99.   XEvent xe;
  100.  
  101.   for (i = _SelList.next; --i >= 0; ) {
  102.     if (_SelList.selections[i].selection == selection)
  103.       break;
  104.   }
  105.   if (i < 0) {
  106.     _WError (dpy, (XID) requestor, BadAtom, X_ConvertSelection);
  107.     return 0;
  108.   }
  109.   if (_SelList.selections[i].owner != None) {
  110.     xe.xselectionrequest.type = SelectionRequest;
  111.     xe.xselectionrequest.send_event = False;
  112.     xe.xselectionrequest.display = dpy;
  113.     xe.xselectionrequest.owner = _SelList.selections[i].owner;
  114.     xe.xselectionrequest.requestor = requestor;
  115.     xe.xselectionrequest.selection = _SelList.selections[i].selection;
  116.     xe.xselectionrequest.target = target;
  117.     xe.xselectionrequest.property = property;
  118.     xe.xselectionrequest.time = (time == CurrentTime) ? _WCurrentTime() : time;
  119.     _XEnq (dpy, &xe);
  120.     return 1;
  121.   }
  122.   else {
  123.     xe.xselection.type = SelectionNotify;
  124.     xe.xselection.send_event = False;
  125.     xe.xselection.display = dpy;
  126.     xe.xselection.requestor = requestor;
  127.     xe.xselection.selection = _SelList.selections[i].selection;
  128.     xe.xselection.target = target;
  129.     xe.xselection.property = None;
  130.     xe.xselection.time = (time == CurrentTime) ? _WCurrentTime() : time;
  131.     _XEnq (dpy, &xe);
  132.     return 1;
  133.   }
  134. }
  135.