]> git.saurik.com Git - wxWidgets.git/blob - include/wx/clipbrd.h
Sorry, should be a __UNIX__ test
[wxWidgets.git] / include / wx / clipbrd.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/clipbrd.h
3 // Purpose: wxClipboad class and clipboard functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets Team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CLIPBRD_H_BASE_
13 #define _WX_CLIPBRD_H_BASE_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "clipboardbase.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_CLIPBOARD
22
23
24 #include "wx/object.h"
25 #include "wx/wxchar.h"
26
27 class WXDLLEXPORT wxDataFormat;
28 class WXDLLEXPORT wxDataObject;
29 class WXDLLEXPORT wxClipboard;
30
31 // ----------------------------------------------------------------------------
32 // wxClipboard represents the system clipboard. Normally, you should use
33 // wxTheClipboard which is a global pointer to the (unique) clipboard.
34 //
35 // Clipboard can be used to copy data to/paste data from. It works together
36 // with wxDataObject.
37 // ----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxClipboardBase : public wxObject
40 {
41 public:
42 wxClipboardBase() {}
43
44 // open the clipboard before Add/SetData() and GetData()
45 virtual bool Open() = 0;
46
47 // close the clipboard after Add/SetData() and GetData()
48 virtual void Close() = 0;
49
50 // query whether the clipboard is opened
51 virtual bool IsOpened() const = 0;
52
53 // add to the clipboard data
54 //
55 // NB: the clipboard owns the pointer and will delete it, so data must be
56 // allocated on the heap
57 virtual bool AddData( wxDataObject *data ) = 0;
58
59 // set the clipboard data, this is the same as Clear() followed by
60 // AddData()
61 virtual bool SetData( wxDataObject *data ) = 0;
62
63 // ask if data in correct format is available
64 virtual bool IsSupported( const wxDataFormat& format ) = 0;
65
66 // fill data with data on the clipboard (if available)
67 virtual bool GetData( wxDataObject& data ) = 0;
68
69 // clears wxTheClipboard and the system's clipboard if possible
70 virtual void Clear() = 0;
71
72 // flushes the clipboard: this means that the data which is currently on
73 // clipboard will stay available even after the application exits (possibly
74 // eating memory), otherwise the clipboard will be emptied on exit
75 virtual bool Flush() { return false; }
76
77 // X11 has two clipboards which get selected by this call. Empty on MSW.
78 virtual void UsePrimarySelection( bool WXUNUSED(primary) = false ) { }
79
80 // Returns global instance (wxTheClipboard) of the object:
81 static wxClipboard *Get();
82 };
83
84 // ----------------------------------------------------------------------------
85 // globals
86 // ----------------------------------------------------------------------------
87
88 // The global clipboard object - backward compatible access macro:
89 #define wxTheClipboard (wxClipboard::Get())
90
91 // ----------------------------------------------------------------------------
92 // include platform-specific class declaration
93 // ----------------------------------------------------------------------------
94
95 #if defined(__WXMSW__)
96 #include "wx/msw/clipbrd.h"
97 #elif defined(__WXMOTIF__)
98 #include "wx/motif/clipbrd.h"
99 #elif defined(__WXGTK__)
100 #include "wx/gtk/clipbrd.h"
101 #elif defined(__WXX11__)
102 #include "wx/x11/clipbrd.h"
103 #elif defined(__WXMGL__)
104 #include "wx/mgl/clipbrd.h"
105 #elif defined(__WXMAC__)
106 #include "wx/mac/clipbrd.h"
107 #elif defined(__WXCOCOA__)
108 #include "wx/cocoa/clipbrd.h"
109 #elif defined(__WXPM__)
110 #include "wx/os2/clipbrd.h"
111 #endif
112
113 // ----------------------------------------------------------------------------
114 // helpful class for opening the clipboard and automatically closing it
115 // ----------------------------------------------------------------------------
116
117 class WXDLLEXPORT wxClipboardLocker
118 {
119 public:
120 wxClipboardLocker(wxClipboard *clipboard = (wxClipboard *)NULL)
121 {
122 m_clipboard = clipboard ? clipboard : wxTheClipboard;
123 if ( m_clipboard )
124 {
125 m_clipboard->Open();
126 }
127 }
128
129 bool operator!() const { return !m_clipboard->IsOpened(); }
130
131 ~wxClipboardLocker()
132 {
133 if ( m_clipboard )
134 {
135 m_clipboard->Close();
136 }
137 }
138
139 private:
140 wxClipboard *m_clipboard;
141
142 DECLARE_NO_COPY_CLASS(wxClipboardLocker)
143 };
144
145 #endif // wxUSE_CLIPBOARD
146
147 #endif // _WX_CLIPBRD_H_BASE_