1/* 2 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "config.h" 27 28#include "Pasteboard.h" 29#include "DocumentFragment.h" 30#include "Editor.h" 31#include "Frame.h" 32#include "KURL.h" 33#include "markup.h" 34#include "NotImplemented.h" 35#include "PlatformString.h" 36 37#include <wx/defs.h> 38#include <wx/dataobj.h> 39#include <wx/clipbrd.h> 40 41namespace WebCore { 42 43Pasteboard::Pasteboard() 44{ 45} 46 47Pasteboard* Pasteboard::generalPasteboard() 48{ 49 static Pasteboard* pasteboard = new Pasteboard(); 50 return pasteboard; 51} 52 53void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) 54{ 55 if (wxTheClipboard->Open()) { 56 wxTheClipboard->SetData( new wxTextDataObject(frame->editor()->selectedText()) ); 57 wxTheClipboard->Close(); 58 } 59} 60 61void Pasteboard::writePlainText(const String& text) 62{ 63 if (wxTheClipboard->Open()) { 64 wxTheClipboard->SetData( new wxTextDataObject(text) ); 65 wxTheClipboard->Close(); 66 } 67} 68 69bool Pasteboard::canSmartReplace() 70{ 71 notImplemented(); 72 return false; 73} 74 75String Pasteboard::plainText(Frame* frame) 76{ 77 notImplemented(); 78 return String(); 79} 80 81PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, 82 bool allowPlainText, bool& chosePlainText) 83{ 84 RefPtr<DocumentFragment> fragment = 0; 85 if (wxTheClipboard->Open()) { 86 if (allowPlainText && wxTheClipboard->IsSupported( wxDF_TEXT )) { 87 wxTextDataObject data; 88 wxTheClipboard->GetData( data ); 89 chosePlainText = true; 90 fragment = createFragmentFromText(context.get(), data.GetText()); 91 } 92 wxTheClipboard->Close(); 93 } 94 if (fragment) 95 return fragment.release(); 96 97 return 0; 98} 99 100void Pasteboard::writeURL(const KURL& url, const String&, Frame*) 101{ 102 if (wxTheClipboard->Open()) { 103 wxTheClipboard->SetData( new wxTextDataObject( url.string() ) ); 104 wxTheClipboard->Close(); 105 } 106} 107 108void Pasteboard::clear() 109{ 110 wxTheClipboard->Clear(); 111} 112 113void Pasteboard::writeImage(Node*, const KURL&, const String& title) 114{ 115 notImplemented(); 116} 117 118} 119