]> git.saurik.com Git - wxWidgets.git/blame - include/wx/clipbrd.h
using Run of base class
[wxWidgets.git] / include / wx / clipbrd.h
CommitLineData
e1ee679c
VZ
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
77ffb593 7// Copyright: (c) wxWidgets Team
65571936 8// Licence: wxWindows licence
e1ee679c
VZ
9/////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_CLIPBRD_H_BASE_
12#define _WX_CLIPBRD_H_BASE_
c801d85f 13
e1ee679c
VZ
14#include "wx/defs.h"
15
16#if wxUSE_CLIPBOARD
17
b068c4e8 18
01fc4932 19#include "wx/event.h"
e3f6cbd9 20#include "wx/chartype.h"
81f0d3ca 21#include "wx/dataobj.h" // for wxDataFormat
c220de0b 22#include "wx/vector.h"
e1ee679c 23
b5dbe15d 24class WXDLLIMPEXP_FWD_CORE wxClipboard;
e1ee679c
VZ
25
26// ----------------------------------------------------------------------------
27// wxClipboard represents the system clipboard. Normally, you should use
28// wxTheClipboard which is a global pointer to the (unique) clipboard.
29//
30// Clipboard can be used to copy data to/paste data from. It works together
31// with wxDataObject.
32// ----------------------------------------------------------------------------
33
53a2db12 34class WXDLLIMPEXP_CORE wxClipboardBase : public wxObject
e1ee679c
VZ
35{
36public:
9005f2ed 37 wxClipboardBase() { m_usePrimary = false; }
b068c4e8 38
e1ee679c 39 // open the clipboard before Add/SetData() and GetData()
b068c4e8 40 virtual bool Open() = 0;
e1ee679c
VZ
41
42 // close the clipboard after Add/SetData() and GetData()
b068c4e8 43 virtual void Close() = 0;
e1ee679c 44
f536e0f2
VZ
45 // query whether the clipboard is opened
46 virtual bool IsOpened() const = 0;
47
e1ee679c
VZ
48 // add to the clipboard data
49 //
50 // NB: the clipboard owns the pointer and will delete it, so data must be
51 // allocated on the heap
b068c4e8 52 virtual bool AddData( wxDataObject *data ) = 0;
e1ee679c
VZ
53
54 // set the clipboard data, this is the same as Clear() followed by
55 // AddData()
b068c4e8 56 virtual bool SetData( wxDataObject *data ) = 0;
e1ee679c
VZ
57
58 // ask if data in correct format is available
b068c4e8 59 virtual bool IsSupported( const wxDataFormat& format ) = 0;
e1ee679c 60
311c1be9
RR
61 // ask if data in correct format is available
62 virtual bool IsSupportedAsync( wxEvtHandler *sink );
8946ede1 63
e1ee679c 64 // fill data with data on the clipboard (if available)
b068c4e8 65 virtual bool GetData( wxDataObject& data ) = 0;
68379eaf 66
e1ee679c 67 // clears wxTheClipboard and the system's clipboard if possible
b068c4e8 68 virtual void Clear() = 0;
e1ee679c
VZ
69
70 // flushes the clipboard: this means that the data which is currently on
71 // clipboard will stay available even after the application exits (possibly
72 // eating memory), otherwise the clipboard will be emptied on exit
68379eaf 73 virtual bool Flush() { return false; }
e1ee679c 74
9005f2ed
VZ
75 // this allows to choose whether we work with CLIPBOARD (default) or
76 // PRIMARY selection on X11-based systems
77 //
78 // on the other ones, working with primary selection does nothing: this
79 // allows to write code which sets the primary selection when something is
80 // selected without any ill effects (i.e. without overwriting the
81 // clipboard which would be wrong on the platforms without X11 PRIMARY)
82 virtual void UsePrimarySelection(bool usePrimary = false)
83 {
84 m_usePrimary = usePrimary;
85 }
86
87 // return true if we're using primary selection
88 bool IsUsingPrimarySelection() const { return m_usePrimary; }
e1ee679c 89
5dc43d1f
VS
90 // Returns global instance (wxTheClipboard) of the object:
91 static wxClipboard *Get();
9005f2ed
VZ
92
93
94 // don't use this directly, it is public for compatibility with some ports
95 // (wxX11, wxMotif, ...) only
96 bool m_usePrimary;
e1ee679c
VZ
97};
98
c220de0b
RR
99// ----------------------------------------------------------------------------
100// asynchronous clipboard event
101// ----------------------------------------------------------------------------
102
103class WXDLLIMPEXP_CORE wxClipboardEvent : public wxEvent
104{
105public:
81f0d3ca
VZ
106 wxClipboardEvent(wxEventType evtType = wxEVT_NULL)
107 : wxEvent(0, evtType)
108 {
109 }
110
111 wxClipboardEvent(const wxClipboardEvent& event)
112 : wxEvent(event),
113 m_formats(event.m_formats)
114 {
115 }
c220de0b 116
8946ede1
VZ
117 bool SupportsFormat(const wxDataFormat& format) const;
118 void AddFormat(const wxDataFormat& format);
c220de0b 119
81f0d3ca
VZ
120 virtual wxEvent *Clone() const
121 {
122 return new wxClipboardEvent(*this);
123 }
124
c220de0b
RR
125
126protected:
127 wxVector<wxDataFormat> m_formats;
128
c220de0b
RR
129 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent)
130};
131
9b11752c 132wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_CLIPBOARD_CHANGED, wxClipboardEvent );
c220de0b
RR
133
134typedef void (wxEvtHandler::*wxClipboardEventFunction)(wxClipboardEvent&);
135
136#define wxClipboardEventHandler(func) \
3c778901 137 wxEVENT_HANDLER_CAST(wxClipboardEventFunction, func)
c220de0b
RR
138
139#define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func))
140
5dc43d1f
VS
141// ----------------------------------------------------------------------------
142// globals
143// ----------------------------------------------------------------------------
144
145// The global clipboard object - backward compatible access macro:
146#define wxTheClipboard (wxClipboard::Get())
147
e1ee679c
VZ
148// ----------------------------------------------------------------------------
149// include platform-specific class declaration
150// ----------------------------------------------------------------------------
151
2049ba38 152#if defined(__WXMSW__)
e1ee679c 153 #include "wx/msw/clipbrd.h"
2049ba38 154#elif defined(__WXMOTIF__)
e1ee679c 155 #include "wx/motif/clipbrd.h"
1be7a35c 156#elif defined(__WXGTK20__)
e1ee679c 157 #include "wx/gtk/clipbrd.h"
1be7a35c
MR
158#elif defined(__WXGTK__)
159 #include "wx/gtk1/clipbrd.h"
83df96d6
JS
160#elif defined(__WXX11__)
161 #include "wx/x11/clipbrd.h"
34138703 162#elif defined(__WXMAC__)
ef0e9220 163 #include "wx/osx/clipbrd.h"
aa3d0277
DE
164#elif defined(__WXCOCOA__)
165 #include "wx/cocoa/clipbrd.h"
1777b9bb 166#elif defined(__WXPM__)
e1ee679c 167 #include "wx/os2/clipbrd.h"
c801d85f
KB
168#endif
169
f536e0f2
VZ
170// ----------------------------------------------------------------------------
171// helpful class for opening the clipboard and automatically closing it
172// ----------------------------------------------------------------------------
173
53a2db12 174class WXDLLIMPEXP_CORE wxClipboardLocker
f536e0f2
VZ
175{
176public:
d3b9f782 177 wxClipboardLocker(wxClipboard *clipboard = NULL)
f536e0f2
VZ
178 {
179 m_clipboard = clipboard ? clipboard : wxTheClipboard;
180 if ( m_clipboard )
181 {
182 m_clipboard->Open();
183 }
184 }
185
ffd56fbc 186 bool operator!() const { return !m_clipboard->IsOpened(); }
f536e0f2
VZ
187
188 ~wxClipboardLocker()
189 {
190 if ( m_clipboard )
191 {
192 m_clipboard->Close();
193 }
194 }
195
196private:
197 wxClipboard *m_clipboard;
22f3361e 198
c0c133e1 199 wxDECLARE_NO_COPY_CLASS(wxClipboardLocker);
f536e0f2
VZ
200};
201
e1ee679c
VZ
202#endif // wxUSE_CLIPBOARD
203
204#endif // _WX_CLIPBRD_H_BASE_