home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kmanagerselection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  8.8 KB  |  230 lines

  1. /****************************************************************************
  2.  
  3.  Copyright (C) 2003 Lubos Lunak        <l.lunak@kde.org>
  4.  
  5. Permission is hereby granted, free of charge, to any person obtaining a
  6. copy of this software and associated documentation files (the "Software"),
  7. to deal in the Software without restriction, including without limitation
  8. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. and/or sell copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following conditions:
  11.  
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14.  
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE.
  22.  
  23. ****************************************************************************/
  24.  
  25. #ifndef __KMANAGERSELECTION_H
  26. #define __KMANAGERSELECTION_H
  27.  
  28. #include <qobject.h>
  29. #include <kdelibs_export.h>
  30.  
  31. #ifdef Q_WS_X11 // FIXME(E)
  32.  
  33. #include <X11/Xlib.h>
  34.  
  35. class KSelectionOwnerPrivate;
  36.  
  37. /**
  38.  This class implements claiming and owning manager selections, as described
  39.  in the ICCCM, section 2.8. The selection atom is passed to the constructor,
  40.  claim() attemps to claim ownership of the selection, release() gives up
  41.  the selection ownership. Signal lostOwnership() is emitted when the selection
  42.  is claimed by another owner.
  43.  @since 3.2
  44.  @short ICCCM manager selection owner
  45. */
  46. class KDECORE_EXPORT KSelectionOwner
  47.     : public QObject
  48.     {
  49.     Q_OBJECT
  50.     public:
  51.         /**
  52.          * This constructor initializes the object, but doesn't perform any
  53.          * operation on the selection.
  54.          *
  55.          * @param selection atom representing the manager selection
  56.          * @param screen X screen, or -1 for default
  57.          * @param parent parent object, or NULL if there is none
  58.          */
  59.         KSelectionOwner( Atom selection, int screen = -1, QObject* parent = NULL );
  60.         /**
  61.          * @overload
  62.          * This constructor accepts the selection name and creates the appropriate atom
  63.          * for it automatically.
  64.          *
  65.          * @param selection name of the manager selection
  66.          * @param screen X screen, or -1 for default
  67.          * @param parent parent object, or NULL if there is none
  68.          */
  69.         KSelectionOwner( const char* selection, int screen = -1, QObject* parent = NULL );
  70.         /**
  71.          * Destructor. Calls release().
  72.          */
  73.     virtual ~KSelectionOwner();
  74.         /**
  75.          * This function attemps to claim ownership of the manager selection, using
  76.          * the current X timestamp. If @p force is false, and the selection is already
  77.          * owned, the selection is not claimed, and false is returned. If claiming
  78.          * is forced and the selection is owned by another client, it is waited for up to 1 second
  79.          * for the previous owner to disown the selection, if @p force_kill is true,
  80.          * and the previous owner fails to disown the selection in time,
  81.          * it will be forcibly killed. True is returned after successfully claiming
  82.          * ownership of the selection.
  83.          */
  84.         bool claim( bool force, bool force_kill = true );
  85.         /**
  86.          * If the selection is owned, the ownership is given up.
  87.          */
  88.         void release();
  89.         /**
  90.          * If the selection is owned, returns the window used internally
  91.          * for owning the selection.
  92.          */
  93.         Window ownerWindow() const; // None if not owning the selection
  94.         /**
  95.          * @internal
  96.          */
  97.     bool filterEvent( XEvent* ev_P ); // internal
  98.     signals:
  99.         /**
  100.          * This signal is emitted if the selection was owned and the ownership
  101.          * has been lost due to another client claiming it, this signal is emitted.
  102.          * IMPORTANT: It's not safe to delete the instance in a slot connected
  103.          * to this signal.
  104.          */
  105.         void lostOwnership();
  106.     protected:
  107.         /**
  108.          * Called for every X event received on the window used for owning
  109.          * the selection. If true is returned, the event is filtered out.
  110.          */
  111.         virtual bool handleMessage( XEvent* ev );
  112.         /**
  113.          * Called when a SelectionRequest event is received. A reply should
  114.          * be sent using the selection handling mechanism described in the ICCCM
  115.          * section 2.
  116.          *
  117.          * @param target requested target type
  118.          * @param property property to use for the reply data
  119.          * @param requestor requestor window
  120.          */
  121.         virtual bool genericReply( Atom target, Atom property, Window requestor );
  122.         /**
  123.          * Called to announce the supported targets, as described in the ICCCM
  124.          * section 2.6. The default implementation announces the required targets
  125.          * MULTIPLE, TIMESTAMP and TARGETS.
  126.          */
  127.         virtual void replyTargets( Atom property, Window requestor );
  128.         /**
  129.          * Called to create atoms needed for claiming the selection and
  130.          * communication using the selection handling mechanism. The default
  131.          * implementation must be called if reimplemented. This method
  132.          * may be called repeatedly.
  133.          */
  134.         virtual void getAtoms();
  135.         /**
  136.          * Sets extra data to be sent in the message sent to root window
  137.          * after successfully claiming a selection. These extra data
  138.          * are in data.l[3] and data.l[4] fields of the XClientMessage.
  139.          */
  140.         void setData( long extra1, long extra2 );
  141.     private:
  142.         void filter_selection_request( XSelectionRequestEvent& ev_P );
  143.         bool handle_selection( Atom target_P, Atom property_P, Window requestor_P );
  144.         const Atom selection;
  145.         const int screen;
  146.         Window window;
  147.         Time timestamp;
  148.         long extra1, extra2;
  149.         static Atom manager_atom;
  150.         static Atom xa_multiple;
  151.         static Atom xa_targets;
  152.         static Atom xa_timestamp;
  153.     protected:
  154.         virtual void virtual_hook( int id, void* data );
  155.     private:
  156.         KSelectionOwnerPrivate* d;
  157.     };
  158.  
  159. class KSelectionWatcherPrivate;
  160.  
  161. /**
  162.  This class implements watching manager selections, as described in the ICCCM
  163.  section 2.8. It emits signal newOwner() when a new owner claim the selection,
  164.  and emits lostOwner() when the selection ownership is given up. To find
  165.  out current owner of the selection, owner() can be used.
  166.  @since 3.2
  167.  @short ICCCM manager selection watching
  168. */
  169. class KDECORE_EXPORT KSelectionWatcher
  170.     : public QObject
  171.     {
  172.     Q_OBJECT
  173.     public:
  174.         /**
  175.          * This constructor initializes the object, but doesn't perform any
  176.          * operation on the selection.
  177.          *
  178.          * @param selection atom representing the manager selection
  179.          * @param screen X screen, or -1 for default
  180.          * @param parent parent object, or NULL if there is none
  181.          */
  182.         KSelectionWatcher( Atom selection, int screen = -1, QObject* parent = NULL );
  183.         /**
  184.          * @overload
  185.          * This constructor accepts the selection name and creates the appropriate atom
  186.          * for it automatically.
  187.          *
  188.          * @param selection name of the manager selection
  189.          * @param screen X screen, or -1 for default
  190.          * @param parent parent object, or NULL if there is none
  191.          */
  192.         KSelectionWatcher( const char* selection, int screen = -1, QObject* parent = NULL );
  193.     virtual ~KSelectionWatcher();
  194.         /**
  195.          * Return the current owner of the manager selection, if any.
  196.          */
  197.         Window owner();
  198.         /**
  199.          * @internal
  200.          */
  201.         void filterEvent( XEvent* ev_P ); // internal
  202.     signals:
  203.         /**
  204.          * This signal is emitted when the selection is successfully claimed by a new
  205.          * owner.
  206.          * @param owner the new owner of the selection
  207.          */
  208.         void newOwner( Window owner );
  209.         /**
  210.          * This signal is emitted when the selection is given up, i.e. there's no
  211.          * owner. Note that the selection may be immediatelly claimed again,
  212.          * so the newOwner() signal may be emitted right after this one.
  213.          * It's safe to delete the instance in a slot connected to this signal.
  214.          */
  215.         void lostOwner();
  216.     private:
  217.         void init();
  218.         const Atom selection;
  219.         const int screen;
  220.         Window selection_owner;
  221.         static Atom manager_atom;
  222.     protected:
  223.         virtual void virtual_hook( int id, void* data );
  224.     private:
  225.         KSelectionWatcherPrivate* d;
  226.     };
  227.  
  228. #endif
  229. #endif
  230.