Browse Source

Merge pull request #168 from boq/clipboard

Basic clipboard functionality
Adam Johnson 13 years ago
parent
commit
a753532f77
  1. 1
      Sources/Plasma/Apps/plClient/CMakeLists.txt
  2. 8
      Sources/Plasma/CoreLib/plString.cpp
  3. 36
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp
  4. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h
  5. 45
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp
  6. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h
  7. 1
      Sources/Plasma/PubUtilLib/CMakeLists.txt
  8. 17
      Sources/Plasma/PubUtilLib/plClipboard/CMakeLists.txt
  9. 115
      Sources/Plasma/PubUtilLib/plClipboard/plClipboard.cpp
  10. 64
      Sources/Plasma/PubUtilLib/plClipboard/plClipboard.h
  11. 12
      Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp
  12. 2
      Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h

1
Sources/Plasma/Apps/plClient/CMakeLists.txt

@ -97,6 +97,7 @@ target_link_libraries(plClient plAudio)
target_link_libraries(plClient plAudioCore) target_link_libraries(plClient plAudioCore)
target_link_libraries(plClient plAvatar) target_link_libraries(plClient plAvatar)
target_link_libraries(plClient plClientResMgr) target_link_libraries(plClient plClientResMgr)
target_link_libraries(plClient plClipboard)
#target_link_libraries(plClient plClientKey) #target_link_libraries(plClient plClientKey)
target_link_libraries(plClient plCompression) target_link_libraries(plClient plCompression)
target_link_libraries(plClient plContainer) target_link_libraries(plClient plContainer)

8
Sources/Plasma/CoreLib/plString.cpp

@ -162,11 +162,11 @@ void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size)
*dp++ = 0x80 | ((unichar >> 6) & 0x3F); *dp++ = 0x80 | ((unichar >> 6) & 0x3F);
*dp++ = 0x80 | ((unichar ) & 0x3F); *dp++ = 0x80 | ((unichar ) & 0x3F);
} else if (*sp > 0x7FF) { } else if (*sp > 0x7FF) {
*dp++ = 0xF0 | ((*sp >> 12) & 0x0F); *dp++ = 0xE0 | ((*sp >> 12) & 0x0F);
*dp++ = 0x80 | ((*sp >> 6) & 0x3F); *dp++ = 0x80 | ((*sp >> 6) & 0x3F);
*dp++ = 0x80 | ((*sp ) & 0x3F); *dp++ = 0x80 | ((*sp ) & 0x3F);
} else if (*sp > 0x7F) { } else if (*sp > 0x7F) {
*dp++ = 0xF0 | ((*sp >> 6) & 0x1F); *dp++ = 0xC0 | ((*sp >> 6) & 0x1F);
*dp++ = 0x80 | ((*sp ) & 0x3F); *dp++ = 0x80 | ((*sp ) & 0x3F);
} else { } else {
*dp++ = (char)(*sp); *dp++ = (char)(*sp);
@ -227,11 +227,11 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
*dp++ = 0x80 | ((*sp >> 6) & 0x3F); *dp++ = 0x80 | ((*sp >> 6) & 0x3F);
*dp++ = 0x80 | ((*sp ) & 0x3F); *dp++ = 0x80 | ((*sp ) & 0x3F);
} else if (*sp > 0x7FF) { } else if (*sp > 0x7FF) {
*dp++ = 0xF0 | ((*sp >> 12) & 0x0F); *dp++ = 0xE0 | ((*sp >> 12) & 0x0F);
*dp++ = 0x80 | ((*sp >> 6) & 0x3F); *dp++ = 0x80 | ((*sp >> 6) & 0x3F);
*dp++ = 0x80 | ((*sp ) & 0x3F); *dp++ = 0x80 | ((*sp ) & 0x3F);
} else if (*sp > 0x7F) { } else if (*sp > 0x7F) {
*dp++ = 0xF0 | ((*sp >> 6) & 0x1F); *dp++ = 0xC0 | ((*sp >> 6) & 0x1F);
*dp++ = 0x80 | ((*sp ) & 0x3F); *dp++ = 0x80 | ((*sp ) & 0x3F);
} else { } else {
*dp++ = (char)(*sp); *dp++ = (char)(*sp);

36
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp

@ -61,6 +61,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plgDispatch.h" #include "plgDispatch.h"
#include "hsResMgr.h" #include "hsResMgr.h"
#include "pnInputCore/plKeyMap.h" #include "pnInputCore/plKeyMap.h"
#include "plClipboard/plClipboard.h"
#include <locale> #include <locale>
@ -71,7 +72,6 @@ pfGUIEditBoxMod::pfGUIEditBoxMod()
{ {
SetFlag( kWantsInterest ); SetFlag( kWantsInterest );
SetFlag( kTakesSpecialKeys ); SetFlag( kTakesSpecialKeys );
fIgnoreNextKey = false;
fEscapedFlag = false; fEscapedFlag = false;
fFirstHalfExitKeyPushed = false; fFirstHalfExitKeyPushed = false;
fSpecialCaptureKeyEventMode = false; fSpecialCaptureKeyEventMode = false;
@ -240,13 +240,6 @@ hsBool pfGUIEditBoxMod::HandleKeyPress( wchar_t key, uint8_t modifiers )
if( fBuffer == nil ) if( fBuffer == nil )
return false; return false;
if( fIgnoreNextKey )
{
// So we don't process keys that already got handled by HandleKeyEvent()
fIgnoreNextKey = false;
return true;
}
int i = wcslen( fBuffer ); int i = wcslen( fBuffer );
// Insert character at the current cursor position, then inc the cursor by one // Insert character at the current cursor position, then inc the cursor by one
@ -329,7 +322,6 @@ hsBool pfGUIEditBoxMod::HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef
// done capturing... tell the handler // done capturing... tell the handler
DoSomething(); DoSomething();
} }
fIgnoreNextKey = true;
fFirstHalfExitKeyPushed = false; fFirstHalfExitKeyPushed = false;
return true; return true;
} }
@ -387,13 +379,31 @@ hsBool pfGUIEditBoxMod::HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef
DoSomething(); // Query WasEscaped() to see if it was escape vs enter DoSomething(); // Query WasEscaped() to see if it was escape vs enter
return true; return true;
} }
else else if (modifiers & pfGameGUIMgr::kCtrlDown)
{ {
fIgnoreNextKey = false; if (key == KEY_C)
return true; {
plClipboard::GetInstance().SetClipboardText(_TEMP_CONVERT_FROM_WCHAR_T(fBuffer));
}
else if (key == KEY_V)
{
plString contents = plClipboard::GetInstance().GetClipboardText();
plStringBuffer<wchar_t> tmp = contents.ToWchar();
size_t len = tmp.GetSize();
if (len > 0) {
--len; //skip \0 on end
wchar_t* insertTarget = fBuffer + fCursorPos;
size_t bufferTailLen = wcslen(insertTarget);
if (fCursorPos + len + bufferTailLen < fBufferSize) {
memmove(insertTarget + len, insertTarget, bufferTailLen * sizeof(wchar_t));
memcpy(insertTarget, tmp.GetData(), len * sizeof(wchar_t));
fCursorPos += len;
HandleExtendedEvent( kValueChanging );
}
}
}
} }
fIgnoreNextKey = true;
IUpdate(); IUpdate();
return true; return true;
} }

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h

@ -66,7 +66,7 @@ class pfGUIEditBoxMod : public pfGUIControlMod
wchar_t *fBuffer; wchar_t *fBuffer;
uint32_t fBufferSize, fCursorPos; uint32_t fBufferSize, fCursorPos;
int32_t fScrollPos; int32_t fScrollPos;
hsBool fIgnoreNextKey, fEscapedFlag; hsBool fEscapedFlag;
hsBool fFirstHalfExitKeyPushed; hsBool fFirstHalfExitKeyPushed;
hsBool fSpecialCaptureKeyEventMode; hsBool fSpecialCaptureKeyEventMode;

45
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp

@ -60,7 +60,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plGImage/plDynamicTextMap.h" #include "plGImage/plDynamicTextMap.h"
#include "plgDispatch.h" #include "plgDispatch.h"
#include "hsResMgr.h" #include "hsResMgr.h"
#include "plClipboard/plClipboard.h"
#include "plString.h"
//// Tiny Helper Class /////////////////////////////////////////////////////// //// Tiny Helper Class ///////////////////////////////////////////////////////
@ -150,7 +151,6 @@ pfGUIMultiLineEditCtrl::pfGUIMultiLineEditCtrl()
fLastCursorLine = 0; fLastCursorLine = 0;
fBuffer.Append( 0L ); fBuffer.Append( 0L );
fBufferLimit = -1; fBufferLimit = -1;
fIgnoreNextKey = false;
fScrollControl = nil; fScrollControl = nil;
fScrollProc = nil; fScrollProc = nil;
fScrollPos = 0; fScrollPos = 0;
@ -1035,16 +1035,6 @@ hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( wchar_t key, uint8_t modifiers )
if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine())) if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine()))
return true; // we're ignoring if we can't actually edit our visible frame (and we're linked) return true; // we're ignoring if we can't actually edit our visible frame (and we're linked)
if (modifiers & pfGameGUIMgr::kCtrlDown)
return true; // we're ignoring ctrl key events
if( fIgnoreNextKey )
{
// So we don't process keys that already got handled by HandleKeyEvent()
fIgnoreNextKey = false;
return true;
}
// Store info for the event we're about to send out // Store info for the event we're about to send out
fLastKeyModifiers = modifiers; fLastKeyModifiers = modifiers;
fLastKeyPressed = key; fLastKeyPressed = key;
@ -1070,9 +1060,6 @@ hsBool pfGUIMultiLineEditCtrl::HandleKeyEvent( pfGameGUIMgr::EventType event, p
if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine())) if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine()))
return true; // we're ignoring if we can't actually edit our visible frame (and we're linked) return true; // we're ignoring if we can't actually edit our visible frame (and we're linked)
if (modifiers & pfGameGUIMgr::kCtrlDown)
return true; // we're ignoring ctrl key events
if( event == pfGameGUIMgr::kKeyDown || event == pfGameGUIMgr::kKeyRepeat ) if( event == pfGameGUIMgr::kKeyDown || event == pfGameGUIMgr::kKeyRepeat )
{ {
// Use arrow keys to do our dirty work // Use arrow keys to do our dirty work
@ -1112,18 +1099,34 @@ hsBool pfGUIMultiLineEditCtrl::HandleKeyEvent( pfGameGUIMgr::EventType event, p
DeleteChar(); DeleteChar();
} }
else if( key == KEY_ENTER )
{
if( IsLocked() )
return true;
InsertChar('\n');
}
else if (modifiers & pfGameGUIMgr::kCtrlDown)
{
// Not exactly safe way to do it, since there are control codes inside buffer.
// But what's the worst thing that can happen? Horribly colorful ki-mails?
// Too lazy to worry about that...
if (key == KEY_C)
{
plClipboard::GetInstance().SetClipboardText(_TEMP_CONVERT_FROM_WCHAR_T(fBuffer.AcquireArray()));
}
else if (key == KEY_V)
{
plString contents = plClipboard::GetInstance().GetClipboardText();
InsertString(contents.ToWchar().GetData());
}
}
else if( key == KEY_ESCAPE ) else if( key == KEY_ESCAPE )
{ {
// fEscapedFlag = true; // fEscapedFlag = true;
DoSomething(); // Query WasEscaped() to see if it was escape vs enter DoSomething(); // Query WasEscaped() to see if it was escape vs enter
} }
else
{
fIgnoreNextKey = false;
return true;
}
fIgnoreNextKey = true;
return true; return true;
} }
else else

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h

@ -100,7 +100,7 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod
hsTArray<int32_t> fLineStarts; hsTArray<int32_t> fLineStarts;
uint16_t fLineHeight, fCurrCursorX, fCurrCursorY; uint16_t fLineHeight, fCurrCursorX, fCurrCursorY;
int32_t fCursorPos, fLastCursorLine; int32_t fCursorPos, fLastCursorLine;
hsBool fIgnoreNextKey, fReadyToRender; hsBool fReadyToRender;
hsBounds3Ext fLastP2PArea; hsBounds3Ext fLastP2PArea;
int8_t fLockCount; int8_t fLockCount;
uint8_t fCalcedFontSize; // The font size that we calced our line height at uint8_t fCalcedFontSize; // The font size that we calced our line height at

1
Sources/Plasma/PubUtilLib/CMakeLists.txt

@ -7,6 +7,7 @@ add_subdirectory(plAudio)
add_subdirectory(plAudioCore) add_subdirectory(plAudioCore)
add_subdirectory(plAvatar) add_subdirectory(plAvatar)
add_subdirectory(plClientResMgr) add_subdirectory(plClientResMgr)
add_subdirectory(plClipboard)
add_subdirectory(plCompression) add_subdirectory(plCompression)
add_subdirectory(plContainer) add_subdirectory(plContainer)
#add_subdirectory(plDeviceSelector) # Not being used by any current slns #add_subdirectory(plDeviceSelector) # Not being used by any current slns

17
Sources/Plasma/PubUtilLib/plClipboard/CMakeLists.txt

@ -0,0 +1,17 @@
include_directories("../../CoreLib")
include_directories("../../NucleusLib/inc")
include_directories("../../NucleusLib")
include_directories("../../PubUtilLib")
set(plClipboard_SOURCES
plClipboard.cpp
)
set(plClipboard_HEADERS
plClipboard.h
)
add_library(plClipboard STATIC ${plClipboard_SOURCES} ${plClipboard_HEADERS})
source_group("Source Files" FILES ${plClipboard_SOURCES})
source_group("Header Files" FILES ${plClipboard_HEADERS})

115
Sources/Plasma/PubUtilLib/plClipboard/plClipboard.cpp

@ -0,0 +1,115 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "HeadSpin.h"
#include "plClipboard.h"
plClipboard& plClipboard::GetInstance()
{
static plClipboard theInstance;
return theInstance;
}
bool plClipboard::IsTextInClipboard()
{
#ifdef HS_BUILD_FOR_WIN32
return ::IsClipboardFormatAvailable(CF_UNICODETEXT);
#else
return false;
#endif
}
plString plClipboard::GetClipboardText()
{
if (!IsTextInClipboard())
return plString::Null;
#ifdef HS_BUILD_FOR_WIN32
if (!::OpenClipboard(NULL))
return plString::Null;
HANDLE clipboardData = ::GetClipboardData(CF_UNICODETEXT);
size_t size = ::GlobalSize(clipboardData) / sizeof(wchar_t);
wchar_t* clipboardDataPtr = (wchar_t*)::GlobalLock(clipboardData);
plString result = plString::FromWchar(clipboardDataPtr, size);
::GlobalUnlock(clipboardData);
::CloseClipboard();
return result;
#else
return plString::Null;
#endif
}
void plClipboard::SetClipboardText(const plString& text)
{
if (text.IsEmpty())
return;
#ifdef HS_BUILD_FOR_WIN32
plStringBuffer<wchar_t> buf = text.ToWchar();
size_t len = buf.GetSize();
if (len == 0)
return;
HGLOBAL copy = ::GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t));
if (copy == NULL)
return;
if (!::OpenClipboard(NULL))
return;
::EmptyClipboard();
wchar_t* target = (wchar_t*)::GlobalLock(copy);
memcpy(target, buf.GetData(), (len + 1) * sizeof(wchar_t));
target[len] = '\0';
::GlobalUnlock(copy);
// Place the handle on the clipboard.
::SetClipboardData(CF_UNICODETEXT, target);
::CloseClipboard();
#endif
}

64
Sources/Plasma/PubUtilLib/plClipboard/plClipboard.h

@ -0,0 +1,64 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef _plClipboard_h
#define _plClipboard_h
#include "plString.h"
//// Class Definition /////////////////////////////////////////////////////////
class plClipboard
{
private:
plClipboard() {}
plClipboard(const plClipboard& rhs) {}
public:
bool IsTextInClipboard();
plString GetClipboardText();
void SetClipboardText(const plString& text);
static plClipboard& GetInstance( void );
};
#endif // _Clipboard_h

12
Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp

@ -119,7 +119,8 @@ plInputManager* plInputManager::fInstance = nil;
plInputManager::plInputManager( hsWindowHndl hWnd ) : plInputManager::plInputManager( hsWindowHndl hWnd ) :
fDInputMgr(nil), fDInputMgr(nil),
fInterfaceMgr(nil) fInterfaceMgr(nil),
localeC("C")
{ {
fhWnd = hWnd; fhWnd = hWnd;
fInstance = this; fInstance = this;
@ -289,9 +290,11 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM
break; break;
case CHAR_MSG: case CHAR_MSG:
{ {
wchar_t ch = (wchar_t)Wparam;
// These are handled by KEYUP/KEYDOWN and should not be sent // These are handled by KEYUP/KEYDOWN and should not be sent
// We don't like garbage getting in string fields // We don't like garbage getting in string fields
if (Wparam == KEY_BACKSPACE || Wparam == KEY_ESCAPE) if (std::iscntrl(ch, localeC))
break; break;
BYTE scan = (BYTE)(Lparam >> 16); BYTE scan = (BYTE)(Lparam >> 16);
@ -300,10 +303,7 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM
bExtended = Lparam >> 24 & 1; bExtended = Lparam >> 24 & 1;
hsBool bRepeat = ((Lparam >> 29) & 0xf) != 0; hsBool bRepeat = ((Lparam >> 29) & 0xf) != 0;
bool down = !(Lparam >> 31); bool down = !(Lparam >> 31);
wchar_t ch = (wchar_t)Wparam;
// for the return key, Windows sends CR, but multiline text input fields want LF (CR is rendered as a wide horizontal space)
if (ch == 0x0D)
ch = 0x0A;
for (int i=0; i<fInputDevices.Count(); i++) for (int i=0; i<fInputDevices.Count(); i++)
fInputDevices[i]->HandleKeyEvent( CHAR_MSG, (plKeyDef)vkey, down, bRepeat, ch ); fInputDevices[i]->HandleKeyEvent( CHAR_MSG, (plKeyDef)vkey, down, bRepeat, ch );
} }

2
Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTemplates.h" #include "hsTemplates.h"
#include "pnKeyedObject/hsKeyedObject.h" #include "pnKeyedObject/hsKeyedObject.h"
#include "pnInputCore/plInputMap.h" #include "pnInputCore/plInputMap.h"
#include <locale>
class plDInputMgr; class plDInputMgr;
class plInputDevice; class plInputDevice;
@ -99,6 +100,7 @@ protected:
float fMouseScale; float fMouseScale;
static uint8_t bRecenterMouse; static uint8_t bRecenterMouse;
static hsWindowHndl fhWnd; static hsWindowHndl fhWnd;
std::locale localeC;
public: public:
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32

Loading…
Cancel
Save