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