src/solaris/classes/sun/awt/X11/XMSelection.java

Print this page




 111     }
 112 
 113 
 114     public int getNumberOfScreens() {
 115         return numScreens;
 116     }
 117 
 118     void select(long extra_mask) {
 119         eventMask = extra_mask;
 120         for (int screen = 0; screen < numScreens ; screen ++) {
 121             selectPerScreen(screen,extra_mask);
 122         }
 123     }
 124 
 125     void resetOwner(long owner, final int screen) {
 126         XToolkit.awtLock();
 127         try {
 128             long display = XToolkit.getDisplay();
 129             synchronized(this) {
 130                 setOwner(owner, screen);
 131                 if (log.isLoggable(PlatformLogger.FINE)) log.fine("New Selection Owner for screen " + screen + " = " + owner );


 132                 XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | eventMask);
 133                 XToolkit.addEventDispatcher(owner,
 134                         new XEventDispatcher() {
 135                             public void dispatchEvent(XEvent ev) {
 136                                 dispatchSelectionEvent(ev, screen);
 137                             }
 138                         });
 139 
 140             }
 141         } finally {
 142             XToolkit.awtUnlock();
 143         }
 144     }
 145 
 146     void selectPerScreen(final int screen, long extra_mask) {
 147         XToolkit.awtLock();
 148         try {
 149             try {
 150                 long display = XToolkit.getDisplay();
 151                 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Grabbing XServer");


 152                 XlibWrapper.XGrabServer(display);
 153 
 154                 synchronized(this) {
 155                     String selection_name = getName()+"_S"+screen;
 156                     if (log.isLoggable(PlatformLogger.FINE)) log.fine("Screen = " + screen + " selection name = " + selection_name);


 157                     XAtom atom = XAtom.get(selection_name);
 158                     selectionMap.put(Long.valueOf(atom.getAtom()),this); // add mapping from atom to the instance of XMSelection
 159                     setAtom(atom,screen);
 160                     long owner = XlibWrapper.XGetSelectionOwner(display, atom.getAtom());
 161                     if (owner != 0) {
 162                         setOwner(owner, screen);
 163                         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Selection Owner for screen " + screen + " = " + owner );


 164                         XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | extra_mask);
 165                         XToolkit.addEventDispatcher(owner,
 166                                 new XEventDispatcher() {
 167                                         public void dispatchEvent(XEvent ev) {
 168                                             dispatchSelectionEvent(ev, screen);
 169                                         }
 170                                     });
 171                     }
 172                 }
 173             }
 174             catch (Exception e) {
 175                 e.printStackTrace();
 176             }
 177             finally {
 178                 if (log.isLoggable(PlatformLogger.FINE)) log.fine("UnGrabbing XServer");


 179                 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
 180             }
 181         } finally {
 182             XToolkit.awtUnlock();
 183         }
 184     }
 185 
 186 
 187     static boolean processClientMessage(XEvent xev, int screen) {
 188         XClientMessageEvent xce = xev.get_xclient();
 189         if (xce.get_message_type() == XA_MANAGER.getAtom()) {
 190             if (log.isLoggable(PlatformLogger.FINE)) log.fine("client messags = " + xce);


 191             long timestamp = xce.get_data(0);
 192             long atom = xce.get_data(1);
 193             long owner = xce.get_data(2);
 194             long data = xce.get_data(3);
 195 
 196             XMSelection sel = getInstance(atom);
 197             if (sel != null) {
 198                 sel.resetOwner(owner,screen);
 199                 sel.dispatchOwnerChangedEvent(xev,screen,owner,data, timestamp);
 200             }
 201         }
 202         return false;
 203     }
 204 
 205     static  boolean processRootEvent(XEvent xev, int screen) {
 206         switch (xev.get_type()) {
 207             case XConstants.ClientMessage: {
 208                 return processClientMessage(xev, screen);
 209             }
 210         }


 277 
 278     synchronized long getOwner(int screen) {
 279         if (owners != null) {
 280             return owners[screen];
 281         }
 282         return 0;
 283     }
 284 
 285     synchronized void setOwner(long owner, int screen) {
 286         if (owners != null) {
 287             owners[screen] = owner;
 288         }
 289     }
 290 
 291     synchronized String getName() {
 292         return selectionName;
 293     }
 294 
 295 
 296     synchronized void dispatchSelectionChanged( XPropertyEvent ev, int screen) {
 297         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Selection Changed : Screen = " + screen + "Event =" + ev);


 298         if (listeners != null) {
 299             Iterator iter = listeners.iterator();
 300             while (iter.hasNext()) {
 301                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 302                 disp.selectionChanged(screen, this, ev.get_window(), ev);
 303             }
 304         }
 305     }
 306 
 307     synchronized void dispatchOwnerDeath(XDestroyWindowEvent de, int screen) {
 308         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Owner dead : Screen = " + screen + "Event =" + de);


 309         if (listeners != null) {
 310             Iterator iter = listeners.iterator();
 311             while (iter.hasNext()) {
 312                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 313                 disp.ownerDeath(screen, this, de.get_window());
 314 
 315             }
 316         }
 317     }
 318 
 319     void dispatchSelectionEvent(XEvent xev, int screen) {
 320         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Event =" + xev);


 321         if (xev.get_type() == XConstants.DestroyNotify) {
 322             XDestroyWindowEvent de = xev.get_xdestroywindow();
 323             dispatchOwnerDeath( de, screen);
 324         }
 325         else if (xev.get_type() == XConstants.PropertyNotify)  {
 326             XPropertyEvent xpe = xev.get_xproperty();
 327             dispatchSelectionChanged( xpe, screen);
 328         }
 329     }
 330 
 331 
 332     synchronized void dispatchOwnerChangedEvent(XEvent ev, int screen, long owner, long data, long timestamp) {
 333         if (listeners != null) {
 334             Iterator iter = listeners.iterator();
 335             while (iter.hasNext()) {
 336                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 337                 disp.ownerChanged(screen,this, owner, data, timestamp);
 338             }
 339         }
 340     }


 111     }
 112 
 113 
 114     public int getNumberOfScreens() {
 115         return numScreens;
 116     }
 117 
 118     void select(long extra_mask) {
 119         eventMask = extra_mask;
 120         for (int screen = 0; screen < numScreens ; screen ++) {
 121             selectPerScreen(screen,extra_mask);
 122         }
 123     }
 124 
 125     void resetOwner(long owner, final int screen) {
 126         XToolkit.awtLock();
 127         try {
 128             long display = XToolkit.getDisplay();
 129             synchronized(this) {
 130                 setOwner(owner, screen);
 131                 if (log.isLoggable(PlatformLogger.FINE)) {
 132                     log.fine("New Selection Owner for screen " + screen + " = " + owner );
 133                 }
 134                 XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | eventMask);
 135                 XToolkit.addEventDispatcher(owner,
 136                         new XEventDispatcher() {
 137                             public void dispatchEvent(XEvent ev) {
 138                                 dispatchSelectionEvent(ev, screen);
 139                             }
 140                         });
 141 
 142             }
 143         } finally {
 144             XToolkit.awtUnlock();
 145         }
 146     }
 147 
 148     void selectPerScreen(final int screen, long extra_mask) {
 149         XToolkit.awtLock();
 150         try {
 151             try {
 152                 long display = XToolkit.getDisplay();
 153                 if (log.isLoggable(PlatformLogger.FINE)) {
 154                     log.fine("Grabbing XServer");
 155                 }
 156                 XlibWrapper.XGrabServer(display);
 157 
 158                 synchronized(this) {
 159                     String selection_name = getName()+"_S"+screen;
 160                     if (log.isLoggable(PlatformLogger.FINE)) {
 161                         log.fine("Screen = " + screen + " selection name = " + selection_name);
 162                     }
 163                     XAtom atom = XAtom.get(selection_name);
 164                     selectionMap.put(Long.valueOf(atom.getAtom()),this); // add mapping from atom to the instance of XMSelection
 165                     setAtom(atom,screen);
 166                     long owner = XlibWrapper.XGetSelectionOwner(display, atom.getAtom());
 167                     if (owner != 0) {
 168                         setOwner(owner, screen);
 169                         if (log.isLoggable(PlatformLogger.FINE)) {
 170                             log.fine("Selection Owner for screen " + screen + " = " + owner );
 171                         }
 172                         XlibWrapper.XSelectInput(display, owner, XConstants.StructureNotifyMask | extra_mask);
 173                         XToolkit.addEventDispatcher(owner,
 174                                 new XEventDispatcher() {
 175                                         public void dispatchEvent(XEvent ev) {
 176                                             dispatchSelectionEvent(ev, screen);
 177                                         }
 178                                     });
 179                     }
 180                 }
 181             }
 182             catch (Exception e) {
 183                 e.printStackTrace();
 184             }
 185             finally {
 186                 if (log.isLoggable(PlatformLogger.FINE)) {
 187                     log.fine("UnGrabbing XServer");
 188                 }
 189                 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
 190             }
 191         } finally {
 192             XToolkit.awtUnlock();
 193         }
 194     }
 195 
 196 
 197     static boolean processClientMessage(XEvent xev, int screen) {
 198         XClientMessageEvent xce = xev.get_xclient();
 199         if (xce.get_message_type() == XA_MANAGER.getAtom()) {
 200             if (log.isLoggable(PlatformLogger.FINE)) {
 201                 log.fine("client messags = " + xce);
 202             }
 203             long timestamp = xce.get_data(0);
 204             long atom = xce.get_data(1);
 205             long owner = xce.get_data(2);
 206             long data = xce.get_data(3);
 207 
 208             XMSelection sel = getInstance(atom);
 209             if (sel != null) {
 210                 sel.resetOwner(owner,screen);
 211                 sel.dispatchOwnerChangedEvent(xev,screen,owner,data, timestamp);
 212             }
 213         }
 214         return false;
 215     }
 216 
 217     static  boolean processRootEvent(XEvent xev, int screen) {
 218         switch (xev.get_type()) {
 219             case XConstants.ClientMessage: {
 220                 return processClientMessage(xev, screen);
 221             }
 222         }


 289 
 290     synchronized long getOwner(int screen) {
 291         if (owners != null) {
 292             return owners[screen];
 293         }
 294         return 0;
 295     }
 296 
 297     synchronized void setOwner(long owner, int screen) {
 298         if (owners != null) {
 299             owners[screen] = owner;
 300         }
 301     }
 302 
 303     synchronized String getName() {
 304         return selectionName;
 305     }
 306 
 307 
 308     synchronized void dispatchSelectionChanged( XPropertyEvent ev, int screen) {
 309         if (log.isLoggable(PlatformLogger.FINE)) {
 310             log.fine("Selection Changed : Screen = " + screen + "Event =" + ev);
 311         }
 312         if (listeners != null) {
 313             Iterator iter = listeners.iterator();
 314             while (iter.hasNext()) {
 315                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 316                 disp.selectionChanged(screen, this, ev.get_window(), ev);
 317             }
 318         }
 319     }
 320 
 321     synchronized void dispatchOwnerDeath(XDestroyWindowEvent de, int screen) {
 322         if (log.isLoggable(PlatformLogger.FINE)) {
 323             log.fine("Owner dead : Screen = " + screen + "Event =" + de);
 324         }
 325         if (listeners != null) {
 326             Iterator iter = listeners.iterator();
 327             while (iter.hasNext()) {
 328                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 329                 disp.ownerDeath(screen, this, de.get_window());
 330 
 331             }
 332         }
 333     }
 334 
 335     void dispatchSelectionEvent(XEvent xev, int screen) {
 336         if (log.isLoggable(PlatformLogger.FINE)) {
 337             log.fine("Event =" + xev);
 338         }
 339         if (xev.get_type() == XConstants.DestroyNotify) {
 340             XDestroyWindowEvent de = xev.get_xdestroywindow();
 341             dispatchOwnerDeath( de, screen);
 342         }
 343         else if (xev.get_type() == XConstants.PropertyNotify)  {
 344             XPropertyEvent xpe = xev.get_xproperty();
 345             dispatchSelectionChanged( xpe, screen);
 346         }
 347     }
 348 
 349 
 350     synchronized void dispatchOwnerChangedEvent(XEvent ev, int screen, long owner, long data, long timestamp) {
 351         if (listeners != null) {
 352             Iterator iter = listeners.iterator();
 353             while (iter.hasNext()) {
 354                 XMSelectionListener disp = (XMSelectionListener) iter.next();
 355                 disp.ownerChanged(screen,this, owner, data, timestamp);
 356             }
 357         }
 358     }