]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/clipbrd.h
decouple primary selection handling from clipboard and further simplifications/refact...
[wxWidgets.git] / include / wx / gtk / clipbrd.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/clipboard.h
3 // Purpose: wxClipboard for wxGTK
4 // Author: Robert Roebling, Vadim Zeitlin
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // (c) 2007 Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GTK_CLIPBOARD_H_
12 #define _WX_GTK_CLIPBOARD_H_
13
14 // ----------------------------------------------------------------------------
15 // wxClipboard
16 // ----------------------------------------------------------------------------
17
18 class WXDLLIMPEXP_CORE wxClipboard : public wxClipboardBase
19 {
20 public:
21 // there are several clipboards in X11 (and in GDK)
22 enum Kind
23 {
24 Primary,
25 Clipboard
26 };
27
28 wxClipboard();
29 virtual ~wxClipboard();
30
31 // open the clipboard before SetData() and GetData()
32 virtual bool Open();
33
34 // close the clipboard after SetData() and GetData()
35 virtual void Close();
36
37 // query whether the clipboard is opened
38 virtual bool IsOpened() const;
39
40 // set the clipboard data. all other formats will be deleted.
41 virtual bool SetData( wxDataObject *data );
42
43 // add to the clipboard data.
44 virtual bool AddData( wxDataObject *data );
45
46 // ask if data in correct format is available
47 virtual bool IsSupported( const wxDataFormat& format );
48
49 // fill data with data on the clipboard (if available)
50 virtual bool GetData( wxDataObject& data );
51
52 // clears wxTheClipboard and the system's clipboard if possible
53 virtual void Clear();
54
55 // If primary == TRUE, use primary selection in all further ops,
56 // primary == FALSE resets it.
57 virtual void UsePrimarySelection(bool primary = TRUE)
58 { m_usePrimary = primary; }
59
60
61 // implementation from now on
62 // --------------------------
63
64 // get our clipboard item (depending on m_usePrimary value)
65 GdkAtom GTKGetClipboardAtom() const;
66
67 // get the data object currently being used
68 wxDataObject *GTKGetDataObject() { return Data(); }
69
70 // clear the data for the given clipboard kind
71 void GTKClearData(Kind kind);
72
73 // called when selection data is received
74 void GTKOnSelectionReceived(const GtkSelectionData& sel);
75
76 // called when available target information is received
77 bool GTKOnTargetReceived(const wxDataFormat& format);
78
79 private:
80 // the data object we're currently using
81 wxDataObject *& Data()
82 {
83 return m_usePrimary ? m_dataPrimary : m_dataClipboard;
84 }
85
86 // set or unset selection ownership
87 bool SetSelectionOwner(bool set = true);
88
89 // add atom to the list of supported targets
90 void AddSupportedTarget(GdkAtom atom);
91
92 // check if the given format is supported
93 bool DoIsSupported(const wxDataFormat& format);
94
95
96 // both of these pointers can be non-NULL simultaneously but we only use
97 // one of them at any moment depending on m_usePrimary value, use Data()
98 // (from inside) or GTKGetDataObject() (from outside) accessors
99 wxDataObject *m_dataPrimary,
100 *m_dataClipboard;
101
102 // this is used to temporarily hold the object passed to our GetData() so
103 // that GTK callbacks could access it
104 wxDataObject *m_receivedData;
105
106 // used to pass information about the format we need from DoIsSupported()
107 // to GTKOnTargetReceived()
108 GdkAtom m_targetRequested;
109
110 GtkWidget *m_clipboardWidget; // for getting and offering data
111 GtkWidget *m_targetsWidget; // for getting list of supported formats
112
113 bool m_open;
114 bool m_usePrimary;
115 bool m_formatSupported;
116
117
118 DECLARE_DYNAMIC_CLASS(wxClipboard)
119 };
120
121 #endif // _WX_GTK_CLIPBOARD_H_