From 456eeaba104219c9e2a6e6f4e2d62653ecbe2455 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 14:01:07 +0200 Subject: [PATCH] Routines for handling clipboard with TOOL_MANAGER. --- common/tool/tool_manager.cpp | 36 ++++++++++++++++++++++++++++++++++++ include/tool/tool_manager.h | 13 +++++++++++++ 2 files changed, 49 insertions(+) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 0f4e3f22e2..e225e05e2b 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -34,6 +34,7 @@ #include #include +#include #include @@ -598,6 +599,41 @@ void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu, } +bool TOOL_MANAGER::SaveClipboard( const std::string& aText ) +{ + if( wxTheClipboard->Open() ) + { + wxTheClipboard->SetData( new wxTextDataObject( aText ) ); + wxTheClipboard->Close(); + + return true; + } + + return false; +} + + +std::string TOOL_MANAGER::GetClipboard() const +{ + std::string result; + + if( wxTheClipboard->Open() ) + { + if( wxTheClipboard->IsSupported( wxDF_TEXT ) ) + { + wxTextDataObject data; + wxTheClipboard->GetData( data ); + + result = data.GetText().mb_str(); + } + + wxTheClipboard->Close(); + } + + return result; +} + + TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName ) { static int currentId; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index fdc17480d6..1935cf1b14 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -257,6 +257,19 @@ public: m_passEvent = true; } + /** + * Stores an information to the system clipboard. + * @param aText is the information to be stored. + * @return False if error occured. + */ + bool SaveClipboard( const std::string& aText ); + + /** + * Returns the information currently stored in the system clipboard. If data stored in the + * clipboard is in non-text format, empty string is returned. + */ + std::string GetClipboard() const; + /** * Returns list of TOOL_ACTIONs. TOOL_ACTIONs add themselves to the list upon their * creation.