| 1 | // Fallback implementation of clipboard access for Nasal. Copy and edit for |
| 2 | // implementing support of other platforms |
| 3 | // |
| 4 | // Copyright (C) 2012 Thomas Geymayer <[email protected]> |
| 5 | // |
| 6 | // This program is free software; you can redistribute it and/or |
| 7 | // modify it under the terms of the GNU General Public License as |
| 8 | // published by the Free Software Foundation; either version 2 of the |
| 9 | // License, or (at your option) any later version. |
| 10 | // |
| 11 | // This program is distributed in the hope that it will be useful, but |
| 12 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | // General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License |
| 17 | // along with this program; if not, write to the Free Software |
| 18 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | |
| 20 | #include "NasalClipboard.hxx" |
| 21 | |
| 22 | #include <simgear/debug/logstream.hxx> |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * Provide a basic clipboard whose contents are only available to FlightGear |
| 27 | * itself |
| 28 | */ |
| 29 | class ClipboardFallback: |
| 30 | public NasalClipboard |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | /** |
| 35 | * Get clipboard contents as text |
| 36 | */ |
| 37 | virtual std::string getText(Type type) |
| 38 | { |
| 39 | return type == CLIPBOARD ? _clipboard : _selection; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Set clipboard contents as text |
| 44 | */ |
| 45 | virtual bool setText(const std::string& text, Type type) |
| 46 | { |
| 47 | if( type == CLIPBOARD ) |
| 48 | _clipboard = text; |
| 49 | else |
| 50 | _selection = text; |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | protected: |
| 55 | |
| 56 | std::string _clipboard, |
| 57 | _selection; |
| 58 | }; |
| 59 | |
| 60 | //------------------------------------------------------------------------------ |
| 61 | NasalClipboard::Ptr NasalClipboard::create() |
| 62 | { |
| 63 | return NasalClipboard::Ptr(new ClipboardFallback); |
| 64 | } |