Skip to content

Commit

Permalink
Merge 98652eb into 1f3762d
Browse files Browse the repository at this point in the history
  • Loading branch information
kengoide authored May 8, 2022
2 parents 1f3762d + 98652eb commit de9e391
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 144 deletions.
46 changes: 27 additions & 19 deletions sakura_core/_os/CClipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool CClipboard::SetText(
if( bColumnSelect ){
UINT uFormat = ::RegisterClipboardFormat( L"MSDEVColumnSelect" );
if( 0 != uFormat ){
hgClipMSDEVColumn = ::GlobalAlloc(
hgClipMSDEVColumn = GlobalAlloc(
GMEM_MOVEABLE | GMEM_DDESHARE,
1
);
Expand All @@ -170,7 +170,7 @@ bool CClipboard::SetText(
if( bLineSelect ){
UINT uFormat = ::RegisterClipboardFormat( L"MSDEVLineSelect" );
if( 0 != uFormat ){
hgClipMSDEVLine = ::GlobalAlloc(
hgClipMSDEVLine = GlobalAlloc(
GMEM_MOVEABLE | GMEM_DDESHARE,
1
);
Expand All @@ -186,7 +186,7 @@ bool CClipboard::SetText(
if( bLineSelect ){
UINT uFormat = ::RegisterClipboardFormat( L"VisualStudioEditorOperationsLineCutCopyClipboardTag" );
if( 0 != uFormat ){
hgClipMSDEVLine2 = ::GlobalAlloc(
hgClipMSDEVLine2 = GlobalAlloc(
GMEM_MOVEABLE | GMEM_DDESHARE,
1
);
Expand Down Expand Up @@ -276,7 +276,7 @@ bool CClipboard::GetText(CNativeW* cmemBuf, bool* pbColumnSelect, bool* pbLineSe
//矩形選択や行選択のデータがあれば取得
if( NULL != pbColumnSelect || NULL != pbLineSelect ){
UINT uFormat = 0;
while( ( uFormat = ::EnumClipboardFormats( uFormat ) ) != 0 ){
while( ( uFormat = EnumClipboardFormats( uFormat ) ) != 0 ){
// Jul. 2, 2005 genta : check return value of GetClipboardFormatName
WCHAR szFormatName[128];
if( ::GetClipboardFormatName( uFormat, szFormatName, _countof(szFormatName) - 1 ) ){
Expand Down Expand Up @@ -425,7 +425,7 @@ static CLIPFORMAT GetClipFormat(const wchar_t* pFormatName)
bool CClipboard::IsIncludeClipboradFormat(const wchar_t* pFormatName)
{
CLIPFORMAT uFormat = GetClipFormat(pFormatName);
if( ::IsClipboardFormatAvailable(uFormat) ){
if( IsClipboardFormatAvailable(uFormat) ){
return true;
}
return false;
Expand Down Expand Up @@ -508,7 +508,7 @@ bool CClipboard::SetClipboradByFormat(const CStringRef& cstr, const wchar_t* pFo
case 0: nulLen = 0; break;
default: nulLen = 0; break;
}
HGLOBAL hgClipText = ::GlobalAlloc(
HGLOBAL hgClipText = GlobalAlloc(
GMEM_MOVEABLE | GMEM_DDESHARE,
nTextByteLen + nulLen
);
Expand All @@ -521,7 +521,7 @@ bool CClipboard::SetClipboradByFormat(const CStringRef& cstr, const wchar_t* pFo
memset( &pszClip[nTextByteLen], 0, nulLen );
}
::GlobalUnlock( hgClipText );
::SetClipboardData( uFormat, hgClipText );
SetClipboardData( uFormat, hgClipText );

return true;
}
Expand Down Expand Up @@ -563,7 +563,7 @@ bool CClipboard::GetClipboradByFormat(CNativeW& mem, const wchar_t* pFormatName,
if( uFormat == (CLIPFORMAT)-1 ){
return false;
}
if( !::IsClipboardFormatAvailable(uFormat) ){
if( !IsClipboardFormatAvailable(uFormat) ){
return false;
}
if( nMode == -2 ){
Expand All @@ -576,10 +576,10 @@ bool CClipboard::GetClipboradByFormat(CNativeW& mem, const wchar_t* pFormatName,
}
return bret;
}
HGLOBAL hClipData = ::GetClipboardData( uFormat );
HGLOBAL hClipData = GetClipboardData( uFormat );
if( hClipData != NULL ){
bool retVal = true;
const BYTE* pData = (BYTE*)::GlobalLock( hClipData );
const BYTE* pData = (BYTE*)GlobalLock( hClipData );
if( pData == NULL ){
return false;
}
Expand Down Expand Up @@ -633,10 +633,6 @@ bool CClipboard::GetClipboradByFormat(CNativeW& mem, const wchar_t* pFormatName,
return false;
}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
// staticインターフェース //
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //

//! クリップボード内に、サクラエディタで扱えるデータがあればtrue
bool CClipboard::HasValidData()
{
Expand All @@ -663,14 +659,14 @@ CLIPFORMAT CClipboard::GetSakuraFormat()
}

//!< クリップボードデータ形式(CF_UNICODETEXT等)の取得
int CClipboard::GetDataType()
int CClipboard::GetDataType() const
{
//扱える形式が1つでもあればtrue
// 2013.06.11 GetTextの取得順に変更
if(::IsClipboardFormatAvailable(GetSakuraFormat()))return GetSakuraFormat();
if(::IsClipboardFormatAvailable(CF_UNICODETEXT))return CF_UNICODETEXT;
if(::IsClipboardFormatAvailable(CF_OEMTEXT))return CF_OEMTEXT;
if(::IsClipboardFormatAvailable(CF_HDROP))return CF_HDROP;
if(IsClipboardFormatAvailable(GetSakuraFormat()))return GetSakuraFormat();
if(IsClipboardFormatAvailable(CF_UNICODETEXT))return CF_UNICODETEXT;
if(IsClipboardFormatAvailable(CF_OEMTEXT))return CF_OEMTEXT;
if(IsClipboardFormatAvailable(CF_HDROP))return CF_HDROP;
return -1;
}

Expand All @@ -689,3 +685,15 @@ BOOL CClipboard::EmptyClipboard() const {
BOOL CClipboard::IsClipboardFormatAvailable(UINT format) const {
return ::IsClipboardFormatAvailable(format);
}

UINT CClipboard::EnumClipboardFormats(UINT format) const {
return ::EnumClipboardFormats(format);
}

HGLOBAL CClipboard::GlobalAlloc(UINT uFlags, SIZE_T dwBytes) const {
return ::GlobalAlloc(uFlags, dwBytes);
}

LPVOID CClipboard::GlobalLock(HGLOBAL hMem) const {
return ::GlobalLock(hMem);
}
6 changes: 5 additions & 1 deletion sakura_core/_os/CClipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class CClipboard{
//演算子
operator bool() const{ return m_bOpenResult!=FALSE; } //!< クリップボードを開けたならtrue

int GetDataType() const; //!< クリップボードデータ形式(CF_UNICODETEXT等)の取得

private:
HWND m_hwnd;
BOOL m_bOpenResult;
Expand All @@ -65,7 +67,6 @@ class CClipboard{
public:
static bool HasValidData(); //!< クリップボード内に、サクラエディタで扱えるデータがあればtrue
static CLIPFORMAT GetSakuraFormat(); //!< サクラエディタ独自のクリップボードデータ形式
static int GetDataType(); //!< クリップボードデータ形式(CF_UNICODETEXT等)の取得

protected:
// 単体テスト用コンストラクタ
Expand All @@ -77,5 +78,8 @@ class CClipboard{
virtual HANDLE GetClipboardData(UINT uFormat) const;
virtual BOOL EmptyClipboard() const;
virtual BOOL IsClipboardFormatAvailable(UINT format) const;
virtual UINT EnumClipboardFormats(UINT format) const;
virtual HGLOBAL GlobalAlloc(UINT uFlags, SIZE_T dwBytes) const;
virtual LPVOID GlobalLock(HGLOBAL hMem) const;
};
#endif /* SAKURA_CCLIPBOARD_4E783022_214C_4E51_A2E0_54EC343500F6_H_ */
Loading

0 comments on commit de9e391

Please sign in to comment.