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_ 
  21 #include "wx/chartype.h" 
  22 #include "wx/dataobj.h"     // for wxDataFormat 
  23 #include "wx/vector.h" 
  25 class WXDLLIMPEXP_FWD_CORE 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 WXDLLIMPEXP_CORE wxClipboardBase 
: public wxObject
 
  38     wxClipboardBase() { m_usePrimary 
= false; } 
  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     // ask if data in correct format is available 
  63     virtual bool IsSupportedAsync( wxEvtHandler 
*sink 
); 
  65     // fill data with data on the clipboard (if available) 
  66     virtual bool GetData( wxDataObject
& data 
) = 0; 
  68     // clears wxTheClipboard and the system's clipboard if possible 
  69     virtual void Clear() = 0; 
  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 
  74     virtual bool Flush() { return false; } 
  76     // this allows to choose whether we work with CLIPBOARD (default) or 
  77     // PRIMARY selection on X11-based systems 
  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) 
  85         m_usePrimary 
= usePrimary
; 
  88     // return true if we're using primary selection 
  89     bool IsUsingPrimarySelection() const { return m_usePrimary
; } 
  91     // Returns global instance (wxTheClipboard) of the object: 
  92     static wxClipboard 
*Get(); 
  95     // don't use this directly, it is public for compatibility with some ports 
  96     // (wxX11, wxMotif, ...) only 
 100 // ---------------------------------------------------------------------------- 
 101 // asynchronous clipboard event 
 102 // ---------------------------------------------------------------------------- 
 104 class WXDLLIMPEXP_CORE wxClipboardEvent 
: public wxEvent
 
 107     wxClipboardEvent(wxEventType evtType 
= wxEVT_NULL
) 
 108         : wxEvent(0, evtType
) 
 112     wxClipboardEvent(const wxClipboardEvent
& event
) 
 114           m_formats(event
.m_formats
) 
 118     bool SupportsFormat(const wxDataFormat
& format
) const; 
 119     void AddFormat(const wxDataFormat
& format
); 
 121     virtual wxEvent 
*Clone() const 
 123         return new wxClipboardEvent(*this); 
 128     wxVector
<wxDataFormat
> m_formats
; 
 130     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardEvent
) 
 133 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_CLIPBOARD_CHANGED
, wxClipboardEvent 
); 
 135 typedef void (wxEvtHandler::*wxClipboardEventFunction
)(wxClipboardEvent
&); 
 137 #define wxClipboardEventHandler(func) \ 
 138     wxEVENT_HANDLER_CAST(wxClipboardEventFunction, func) 
 140 #define EVT_CLIPBOARD_CHANGED(func) wx__DECLARE_EVT0(wxEVT_CLIPBOARD_CHANGED, wxClipboardEventHandler(func)) 
 142 // ---------------------------------------------------------------------------- 
 144 // ---------------------------------------------------------------------------- 
 146 // The global clipboard object - backward compatible access macro: 
 147 #define wxTheClipboard   (wxClipboard::Get()) 
 149 // ---------------------------------------------------------------------------- 
 150 // include platform-specific class declaration 
 151 // ---------------------------------------------------------------------------- 
 153 #if defined(__WXMSW__) 
 154     #include "wx/msw/clipbrd.h" 
 155 #elif defined(__WXMOTIF__) 
 156     #include "wx/motif/clipbrd.h" 
 157 #elif defined(__WXGTK20__) 
 158     #include "wx/gtk/clipbrd.h" 
 159 #elif defined(__WXGTK__) 
 160     #include "wx/gtk1/clipbrd.h" 
 161 #elif defined(__WXX11__) 
 162     #include "wx/x11/clipbrd.h" 
 163 #elif defined(__WXMAC__) 
 164     #include "wx/osx/clipbrd.h" 
 165 #elif defined(__WXCOCOA__) 
 166     #include "wx/cocoa/clipbrd.h" 
 167 #elif defined(__WXPM__) 
 168     #include "wx/os2/clipbrd.h" 
 171 // ---------------------------------------------------------------------------- 
 172 // helpful class for opening the clipboard and automatically closing it 
 173 // ---------------------------------------------------------------------------- 
 175 class WXDLLIMPEXP_CORE wxClipboardLocker
 
 178     wxClipboardLocker(wxClipboard 
*clipboard 
= NULL
) 
 180         m_clipboard 
= clipboard 
? clipboard 
: wxTheClipboard
; 
 187     bool operator!() const { return !m_clipboard
->IsOpened(); } 
 193             m_clipboard
->Close(); 
 198     wxClipboard 
*m_clipboard
; 
 200     wxDECLARE_NO_COPY_CLASS(wxClipboardLocker
); 
 203 #endif // wxUSE_CLIPBOARD 
 205 #endif // _WX_CLIPBRD_H_BASE_