-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "WAS_ClipboardHandler.hpp" | ||
#include "NE_Debug.hpp" | ||
#include "NUIE_VersionInfo.hpp" | ||
|
||
namespace WAS | ||
{ | ||
|
||
ClipboardHandler::ClipboardHandler () : | ||
NUIE::ClipboardHandler (), | ||
formatId (0) | ||
{ | ||
formatId = RegisterClipboardFormat (VSE_APP_NAME); | ||
} | ||
|
||
ClipboardHandler::~ClipboardHandler () | ||
{ | ||
|
||
} | ||
|
||
NUIE::Version ClipboardHandler::GetCurrentVersion () const | ||
{ | ||
return NUIE::GetCurrentVersion (); | ||
} | ||
|
||
bool ClipboardHandler::IsCompatibleVersion (const NUIE::Version& version) const | ||
{ | ||
return NUIE::IsCompatibleVersion (version); | ||
} | ||
|
||
bool ClipboardHandler::HasClipboardContent () const | ||
{ | ||
if (DBGERROR (!OpenClipboard (NULL))) { | ||
return false; | ||
} | ||
|
||
HGLOBAL clipboardHandle = GetClipboardData (formatId); | ||
bool hasClipboardContent = (clipboardHandle != NULL); | ||
CloseClipboard (); | ||
|
||
return hasClipboardContent; | ||
} | ||
|
||
bool ClipboardHandler::GetClipboardContent (std::vector<char>& content) const | ||
{ | ||
if (DBGERROR (!OpenClipboard (NULL))) { | ||
return false; | ||
} | ||
HGLOBAL clipboardHandle = GetClipboardData (formatId); | ||
if (clipboardHandle == NULL) { | ||
CloseClipboard (); | ||
return false; | ||
} | ||
|
||
SIZE_T handleSize = GlobalSize (clipboardHandle); | ||
if (handleSize == 0) { | ||
return false; | ||
} | ||
|
||
char* pointer = (char*) GlobalLock (clipboardHandle); | ||
content.assign (pointer, pointer + handleSize); | ||
GlobalUnlock (clipboardHandle); | ||
CloseClipboard (); | ||
|
||
return true; | ||
} | ||
|
||
bool ClipboardHandler::SetClipboardContent (const std::vector<char>& content) | ||
{ | ||
if (DBGERROR (content.empty ())) { | ||
return false; | ||
} | ||
|
||
if (DBGERROR (!OpenClipboard (NULL))) { | ||
return false; | ||
} | ||
|
||
EmptyClipboard (); | ||
|
||
HGLOBAL clipboardHandle = GlobalAlloc (GMEM_MOVEABLE, content.size ()); | ||
LPVOID pointer = GlobalLock (clipboardHandle); | ||
memcpy (pointer, &content[0], content.size ()); | ||
GlobalUnlock (clipboardHandle); | ||
|
||
HANDLE resultData = SetClipboardData (formatId, clipboardHandle); | ||
if (DBGERROR (resultData == NULL)) { | ||
CloseClipboard (); | ||
return false; | ||
} | ||
|
||
CloseClipboard (); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef WAS_CLIPBOARDHANDLER_HPP | ||
#define WAS_CLIPBOARDHANDLER_HPP | ||
|
||
#include "WAS_IncludeWindowsHeaders.hpp" | ||
#include "NUIE_ClipboardHandler.hpp" | ||
|
||
namespace WAS | ||
{ | ||
|
||
class ClipboardHandler : public NUIE::ClipboardHandler | ||
{ | ||
public: | ||
ClipboardHandler (); | ||
virtual ~ClipboardHandler (); | ||
|
||
virtual NUIE::Version GetCurrentVersion () const override; | ||
virtual bool IsCompatibleVersion (const NUIE::Version& version) const override; | ||
|
||
virtual bool HasClipboardContent () const override; | ||
virtual bool GetClipboardContent (std::vector<char>& content) const override; | ||
virtual bool SetClipboardContent (const std::vector<char>& content) override; | ||
|
||
private: | ||
UINT formatId; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters