1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxClipboad class and clipboard functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets Team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CLIPBRD_H_BASE_
13 #define _WX_CLIPBRD_H_BASE_
20 #include "wx/object.h"
21 #include "wx/wxchar.h"
23 class WXDLLEXPORT wxDataFormat
;
24 class WXDLLEXPORT wxDataObject
;
25 class WXDLLEXPORT wxClipboard
;
27 // ----------------------------------------------------------------------------
28 // wxClipboard represents the system clipboard. Normally, you should use
29 // wxTheClipboard which is a global pointer to the (unique) clipboard.
31 // Clipboard can be used to copy data to/paste data from. It works together
33 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxClipboardBase
: public wxObject
40 // open the clipboard before Add/SetData() and GetData()
41 virtual bool Open() = 0;
43 // close the clipboard after Add/SetData() and GetData()
44 virtual void Close() = 0;
46 // query whether the clipboard is opened
47 virtual bool IsOpened() const = 0;
49 // add to the clipboard data
51 // NB: the clipboard owns the pointer and will delete it, so data must be
52 // allocated on the heap
53 virtual bool AddData( wxDataObject
*data
) = 0;
55 // set the clipboard data, this is the same as Clear() followed by
57 virtual bool SetData( wxDataObject
*data
) = 0;
59 // ask if data in correct format is available
60 virtual bool IsSupported( const wxDataFormat
& format
) = 0;
62 // fill data with data on the clipboard (if available)
63 virtual bool GetData( wxDataObject
& data
) = 0;
65 // clears wxTheClipboard and the system's clipboard if possible
66 virtual void Clear() = 0;
68 // flushes the clipboard: this means that the data which is currently on
69 // clipboard will stay available even after the application exits (possibly
70 // eating memory), otherwise the clipboard will be emptied on exit
71 virtual bool Flush() { return false; }
73 // X11 has two clipboards which get selected by this call. Empty on MSW.
74 virtual void UsePrimarySelection( bool WXUNUSED(primary
) = false ) { }
76 // Returns global instance (wxTheClipboard) of the object:
77 static wxClipboard
*Get();
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // The global clipboard object - backward compatible access macro:
85 #define wxTheClipboard (wxClipboard::Get())
87 // ----------------------------------------------------------------------------
88 // include platform-specific class declaration
89 // ----------------------------------------------------------------------------
91 #if defined(__WXMSW__)
92 #include "wx/msw/clipbrd.h"
93 #elif defined(__WXMOTIF__)
94 #include "wx/motif/clipbrd.h"
95 #elif defined(__WXGTK20__)
96 #include "wx/gtk/clipbrd.h"
97 #elif defined(__WXGTK__)
98 #include "wx/gtk1/clipbrd.h"
99 #elif defined(__WXX11__)
100 #include "wx/x11/clipbrd.h"
101 #elif defined(__WXMGL__)
102 #include "wx/mgl/clipbrd.h"
103 #elif defined(__WXMAC__)
104 #include "wx/mac/clipbrd.h"
105 #elif defined(__WXCOCOA__)
106 #include "wx/cocoa/clipbrd.h"
107 #elif defined(__WXPM__)
108 #include "wx/os2/clipbrd.h"
111 // ----------------------------------------------------------------------------
112 // helpful class for opening the clipboard and automatically closing it
113 // ----------------------------------------------------------------------------
115 class WXDLLEXPORT wxClipboardLocker
118 wxClipboardLocker(wxClipboard
*clipboard
= (wxClipboard
*)NULL
)
120 m_clipboard
= clipboard
? clipboard
: wxTheClipboard
;
127 bool operator!() const { return !m_clipboard
->IsOpened(); }
133 m_clipboard
->Close();
138 wxClipboard
*m_clipboard
;
140 DECLARE_NO_COPY_CLASS(wxClipboardLocker
)
143 #endif // wxUSE_CLIPBOARD
145 #endif // _WX_CLIPBRD_H_BASE_