]> git.saurik.com Git - wxWidgets.git/blob - src/common/clipcmn.cpp
applying patch, fixes #10523
[wxWidgets.git] / src / common / clipcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/clipcmn.cpp
3 // Purpose: common (to all ports) wxClipboard functions
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 28.06.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_CLIPBOARD
28
29 #include "wx/clipbrd.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/dataobj.h"
33 #include "wx/module.h"
34 #endif
35
36 // ---------------------------------------------------------
37 // wxClipboardEvent
38 // ---------------------------------------------------------
39
40 IMPLEMENT_DYNAMIC_CLASS(wxClipboardEvent,wxEvent)
41
42 wxDEFINE_EVENT( wxEVT_CLIPBOARD_CHANGED, wxClipboardEvent );
43
44 // notice that ctors are defined here and not inline to avoid having to include
45 // wx/dataobj.h from wx/clipbrd.h
46 wxClipboardEvent::wxClipboardEvent(wxEventType evtType)
47 : wxEvent(0, evtType)
48 {
49 }
50
51 wxClipboardEvent::wxClipboardEvent(const wxClipboardEvent& event)
52 : wxEvent(event),
53 m_formats(event.m_formats)
54 {
55 }
56
57 wxEvent* wxClipboardEvent::Clone() const
58 {
59 return new wxClipboardEvent(*this);
60 }
61
62 bool wxClipboardEvent::SupportsFormat( const wxDataFormat &format ) const
63 {
64 #ifdef __WXGTK20__
65 // GTK has an asynchronous API which reports the supported formats one by
66 // one. We may have to add X11 and Motif later.
67 for (wxVector<wxDataFormat>::size_type n = 0; n < m_formats.size(); n++)
68 {
69 if (m_formats[n] == format)
70 return true;
71 }
72
73 return false;
74 #else
75 // All other ports just query the clipboard directly
76 // from here
77 wxClipboard* clipboard = (wxClipboard*) GetEventObject();
78 return clipboard->IsSupported( format );
79 #endif
80 }
81
82 void wxClipboardEvent::AddFormat(const wxDataFormat& format)
83 {
84 m_formats.push_back( format );
85 }
86
87 // ---------------------------------------------------------
88 // wxClipboardBase
89 // ---------------------------------------------------------
90
91 static wxClipboard *gs_clipboard = NULL;
92
93 /*static*/ wxClipboard *wxClipboardBase::Get()
94 {
95 if ( !gs_clipboard )
96 {
97 gs_clipboard = new wxClipboard;
98 }
99 return gs_clipboard;
100 }
101
102 bool wxClipboardBase::IsSupportedAsync( wxEvtHandler *sink )
103 {
104 // We just imitate an asynchronous API on most platforms.
105 // This method is overridden uner GTK.
106 wxClipboardEvent *event = new wxClipboardEvent(wxEVT_CLIPBOARD_CHANGED);
107 event->SetEventObject( this );
108
109 sink->QueueEvent( event );
110
111 return true;
112 }
113
114
115 // ----------------------------------------------------------------------------
116 // wxClipboardModule: module responsible for destroying the global clipboard
117 // object
118 // ----------------------------------------------------------------------------
119
120 class wxClipboardModule : public wxModule
121 {
122 public:
123 bool OnInit() { return true; }
124 void OnExit() { wxDELETE(gs_clipboard); }
125
126 private:
127 DECLARE_DYNAMIC_CLASS(wxClipboardModule)
128 };
129
130 IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule)
131
132 #endif // wxUSE_CLIPBOARD