Clipboard operation (Copy/Paste)
This commit is contained in:
parent
49fe505b3d
commit
5ef2c4114f
@ -246,6 +246,7 @@
|
||||
E8F74CF81845C5000085AA54 /* ClientUI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8F74CF61845C5000085AA54 /* ClientUI.cpp */; };
|
||||
E8F74CFB1845C64B0085AA54 /* ClientUIHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8F74CF91845C64B0085AA54 /* ClientUIHelper.cpp */; };
|
||||
E8F74CFD1845D4D00085AA54 /* ClientUIHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8F74CFC1845C8D50085AA54 /* ClientUIHelper.cpp */; };
|
||||
E8F74CFF184C7D7C0085AA54 /* Clipboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8F74CFE184C753F0085AA54 /* Clipboard.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@ -769,6 +770,7 @@
|
||||
E8F74CF91845C64B0085AA54 /* ClientUIHelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClientUIHelper.cpp; sourceTree = "<group>"; };
|
||||
E8F74CFA1845C64B0085AA54 /* ClientUIHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClientUIHelper.h; sourceTree = "<group>"; };
|
||||
E8F74CFC1845C8D50085AA54 /* ClientUIHelper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClientUIHelper.cpp; sourceTree = "<group>"; };
|
||||
E8F74CFE184C753F0085AA54 /* Clipboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Clipboard.cpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -1196,6 +1198,7 @@
|
||||
E8F74CF0183FBB070085AA54 /* MainScreenHelper.cpp */,
|
||||
E8F74CF31840D4CC0085AA54 /* Config.cpp */,
|
||||
E8F74CFC1845C8D50085AA54 /* ClientUIHelper.cpp */,
|
||||
E8F74CFE184C753F0085AA54 /* Clipboard.cpp */,
|
||||
);
|
||||
name = ScriptBindings;
|
||||
path = Sources/ScriptBindings;
|
||||
@ -1788,6 +1791,7 @@
|
||||
E834F55F17950E44004EBE88 /* DeflateStream.cpp in Sources */,
|
||||
E834F56517951B1C004EBE88 /* MemoryStream.cpp in Sources */,
|
||||
E834F56817979F5A004EBE88 /* Quake3Font.cpp in Sources */,
|
||||
E8F74CFF184C7D7C0085AA54 /* Clipboard.cpp in Sources */,
|
||||
E834F56B17979FD7004EBE88 /* IFont.cpp in Sources */,
|
||||
E8F74CEF183FBA9C0085AA54 /* MainScreenHelper.cpp in Sources */,
|
||||
E834F56F1797D934004EBE88 /* ChatWindow.cpp in Sources */,
|
||||
|
@ -406,6 +406,10 @@ namespace spades {
|
||||
if(key == "a") {
|
||||
SelectAll();
|
||||
return;
|
||||
}else if(key == "v") {
|
||||
manager.Paste(PasteClipboardEventHandler(this.Insert));
|
||||
}else if(key == "c") {
|
||||
manager.Copy(this.SelectedText);
|
||||
}
|
||||
}
|
||||
manager.ProcessHotKey(key);
|
||||
|
@ -20,6 +20,9 @@
|
||||
|
||||
namespace spades {
|
||||
namespace ui {
|
||||
|
||||
funcdef void PasteClipboardEventHandler(string text);
|
||||
|
||||
/** Manages all input/output and rendering of the UI framework. */
|
||||
class UIManager {
|
||||
private Renderer@ renderer;
|
||||
@ -36,6 +39,8 @@ namespace spades {
|
||||
private UIElement@ mouseCapturedElement;
|
||||
private UIElement@ mouseHoverElement;
|
||||
|
||||
private PasteClipboardEventHandler@ clipboardEventHandler;
|
||||
|
||||
private Timer@[] timers = {};
|
||||
|
||||
Renderer@ Renderer {
|
||||
@ -218,6 +223,13 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
if(clipboardEventHandler !is null) {
|
||||
if(GotClipboardData()) {
|
||||
clipboardEventHandler(GetClipboardData());
|
||||
@clipboardEventHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
Timer@[]@ timers = this.timers;
|
||||
for(int i = timers.length - 1; i >= 0; i--) {
|
||||
timers[i].RunFrame(dt);
|
||||
@ -236,8 +248,18 @@ namespace spades {
|
||||
c.Render(MouseCursorPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void Copy(string text) {
|
||||
SetClipboardData(text);
|
||||
}
|
||||
|
||||
void Paste(PasteClipboardEventHandler@ handler) {
|
||||
RequestClipboardData();
|
||||
@clipboardEventHandler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
funcdef void TimerTickEventHandler(Timer@);
|
||||
class Timer {
|
||||
private UIManager@ manager;
|
||||
|
108
Sources/ScriptBindings/Clipboard.cpp
Normal file
108
Sources/ScriptBindings/Clipboard.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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.
|
||||
|
||||
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptManager.h"
|
||||
#include <Client/IModel.h>
|
||||
#include <FL/Fl_Widget.H>
|
||||
#include <FL/Fl.H>
|
||||
|
||||
namespace spades{
|
||||
|
||||
class ClipboardReceiver: public Fl_Widget {
|
||||
public:
|
||||
std::string clipboardData;
|
||||
bool hasClipboardData;
|
||||
|
||||
ClipboardReceiver():
|
||||
Fl_Widget(0,0,2,2,NULL),
|
||||
hasClipboardData(false){
|
||||
|
||||
}
|
||||
|
||||
virtual int handle(int event) {
|
||||
if(event == FL_PASTE) {
|
||||
hasClipboardData = true;
|
||||
clipboardData = Fl::event_text();
|
||||
return 1;
|
||||
}
|
||||
return Fl_Widget::handle(event);
|
||||
}
|
||||
virtual void draw(){}
|
||||
};
|
||||
|
||||
static ClipboardReceiver *receiver = NULL;
|
||||
class ClipboardRegistrar: public ScriptObjectRegistrar {
|
||||
static void EnsureReceiver() {
|
||||
if(!receiver) {
|
||||
receiver = new ClipboardReceiver();
|
||||
}
|
||||
}
|
||||
|
||||
static bool GotClipboardData() {
|
||||
EnsureReceiver();
|
||||
return receiver->hasClipboardData;
|
||||
}
|
||||
static std::string GetClipboardData() {
|
||||
EnsureReceiver();
|
||||
std::string s = receiver->clipboardData;
|
||||
receiver->hasClipboardData = false;
|
||||
return s;
|
||||
}
|
||||
|
||||
static void RequestClipboardData() {
|
||||
EnsureReceiver();
|
||||
Fl::paste(*receiver, 1);
|
||||
}
|
||||
|
||||
static void SetClipboardData(const std::string& s) {
|
||||
Fl::copy(s.data(), s.size(), 1);
|
||||
}
|
||||
|
||||
public:
|
||||
ClipboardRegistrar():
|
||||
ScriptObjectRegistrar("Clipboard"){
|
||||
}
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch(phase){
|
||||
case PhaseObjectType:
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterGlobalFunction("bool GotClipboardData()", asFUNCTION(GotClipboardData), asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterGlobalFunction("string GetClipboardData()", asFUNCTION(GetClipboardData), asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterGlobalFunction("void SetClipboardData(const string&in)", asFUNCTION(SetClipboardData), asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterGlobalFunction("void RequestClipboardData()", asFUNCTION(RequestClipboardData), asCALL_CDECL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static ClipboardRegistrar registrar;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user