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