GRAPHICS: MACGUI: implement getTextFromClipboard and setTextInClipboard for mactext
This commit is contained in:
parent
f68b3736a3
commit
a5e6f59533
2 changed files with 68 additions and 52 deletions
|
@ -1307,6 +1307,54 @@ Common::U32String MacText::cutSelection() {
|
||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is refer to how we deal U32String in splitString
|
||||||
|
// maybe we can optimize this specifically
|
||||||
|
Common::U32String stripFormat(const Common::U32String &str) {
|
||||||
|
Common::U32String res;
|
||||||
|
// calc the size of str
|
||||||
|
const Common::U32String::value_type *l = str.c_str();
|
||||||
|
while (*l) {
|
||||||
|
if (*l == '\r') {
|
||||||
|
l++;
|
||||||
|
} else if (*l == '\n') {
|
||||||
|
l++;
|
||||||
|
} else if (*l == '\001') {
|
||||||
|
l++;
|
||||||
|
// if there are two \001, then we regard it as one character
|
||||||
|
if (*l == '\001') {
|
||||||
|
res += *l++;
|
||||||
|
}
|
||||||
|
} else if (*l == '\015') { // binary format
|
||||||
|
// 12 for total
|
||||||
|
// we are skipping the formatting stuffs
|
||||||
|
l++;
|
||||||
|
l += 2;
|
||||||
|
l++;
|
||||||
|
l += 2;
|
||||||
|
l += 2;
|
||||||
|
l += 2;
|
||||||
|
l += 2;
|
||||||
|
} else if (*l == '\016') { // human-readable format
|
||||||
|
// 23 for total, should we replace it with l += 23;
|
||||||
|
l++;
|
||||||
|
l += 4;
|
||||||
|
l += 2;
|
||||||
|
l += 4;
|
||||||
|
l += 4;
|
||||||
|
l += 4;
|
||||||
|
l += 4;
|
||||||
|
} else {
|
||||||
|
res += *l++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MacText::setTextInClipboard(const Common::U32String &str) {
|
||||||
|
_wm->_clipboard = str;
|
||||||
|
g_system->setTextInClipboard(stripFormat(str));
|
||||||
|
}
|
||||||
|
|
||||||
bool MacText::processEvent(Common::Event &event) {
|
bool MacText::processEvent(Common::Event &event) {
|
||||||
if (event.type == Common::EVENT_KEYDOWN) {
|
if (event.type == Common::EVENT_KEYDOWN) {
|
||||||
if (!_editable)
|
if (!_editable)
|
||||||
|
@ -1317,10 +1365,10 @@ bool MacText::processEvent(Common::Event &event) {
|
||||||
if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
|
if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
|
||||||
switch (event.kbd.keycode) {
|
switch (event.kbd.keycode) {
|
||||||
case Common::KEYCODE_x:
|
case Common::KEYCODE_x:
|
||||||
g_system->setTextInClipboard(cutSelection());
|
setTextInClipboard(cutSelection());
|
||||||
return true;
|
return true;
|
||||||
case Common::KEYCODE_c:
|
case Common::KEYCODE_c:
|
||||||
g_system->setTextInClipboard(getSelection(true, false));
|
setTextInClipboard(getSelection(true, false));
|
||||||
return true;
|
return true;
|
||||||
case Common::KEYCODE_v:
|
case Common::KEYCODE_v:
|
||||||
if (g_system->hasTextInClipboard()) {
|
if (g_system->hasTextInClipboard()) {
|
||||||
|
@ -1725,73 +1773,34 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is refer to how we deal U32String in splitString
|
Common::U32String MacText::getTextFromClipboard(int &size) {
|
||||||
// maybe we can optimize this specifically
|
|
||||||
Common::U32String stripFormat(const Common::U32String &str) {
|
|
||||||
Common::U32String res;
|
|
||||||
// calc the size of str
|
|
||||||
const Common::U32String::value_type *l = str.c_str();
|
|
||||||
while (*l) {
|
|
||||||
if (*l == '\r') {
|
|
||||||
l++;
|
|
||||||
} else if (*l == '\n') {
|
|
||||||
l++;
|
|
||||||
} else if (*l == '\001') {
|
|
||||||
l++;
|
|
||||||
// if there are two \001, then we regard it as one character
|
|
||||||
if (*l == '\001') {
|
|
||||||
res += *l++;
|
|
||||||
}
|
|
||||||
} else if (*l == '\015') { // binary format
|
|
||||||
// 12 for total
|
|
||||||
// we are skipping the formatting stuffs
|
|
||||||
l++;
|
|
||||||
l += 2;
|
|
||||||
l++;
|
|
||||||
l += 2;
|
|
||||||
l += 2;
|
|
||||||
l += 2;
|
|
||||||
l += 2;
|
|
||||||
} else if (*l == '\016') { // human-readable format
|
|
||||||
// 23 for total, should we replace it with l += 23;
|
|
||||||
l++;
|
|
||||||
l += 4;
|
|
||||||
l += 2;
|
|
||||||
l += 4;
|
|
||||||
l += 4;
|
|
||||||
l += 4;
|
|
||||||
l += 4;
|
|
||||||
} else {
|
|
||||||
res += *l++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mostly, we refering reshuffleParagraph to implement this function
|
|
||||||
void MacText::insertTextFromClipboard() {
|
|
||||||
// this part is for get the text from clipboard, we may wrap it into a function like getTextFromClipboard where we can call from wm
|
|
||||||
Common::U32String global_str = g_system->getTextFromClipboard();
|
Common::U32String global_str = g_system->getTextFromClipboard();
|
||||||
Common::U32String wm_str = _wm->_clipboard;
|
Common::U32String wm_str = _wm->_clipboard;
|
||||||
// str is what we need
|
// str is what we need
|
||||||
Common::U32String str;
|
Common::U32String str;
|
||||||
int ppos = 0;
|
|
||||||
if (wm_str.empty()) {
|
if (wm_str.empty()) {
|
||||||
// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
|
// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
|
||||||
str = global_str;
|
str = global_str;
|
||||||
ppos = str.size();
|
size = str.size();
|
||||||
} else {
|
} else {
|
||||||
Common::U32String tmp = stripFormat(_wm->_clipboard);
|
Common::U32String tmp = stripFormat(_wm->_clipboard);
|
||||||
if (tmp == global_str) {
|
if (tmp == global_str) {
|
||||||
// if the text is equal, then we use wm one which contains the format
|
// if the text is equal, then we use wm one which contains the format
|
||||||
str = wm_str;
|
str = wm_str;
|
||||||
ppos = tmp.size();
|
size = tmp.size();
|
||||||
} else {
|
} else {
|
||||||
// otherwise, we prefer the global one
|
// otherwise, we prefer the global one
|
||||||
str = global_str;
|
str = global_str;
|
||||||
ppos = str.size();
|
size = str.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mostly, we refering reshuffleParagraph to implement this function
|
||||||
|
void MacText::insertTextFromClipboard() {
|
||||||
|
int ppos = 0;
|
||||||
|
Common::U32String str = getTextFromClipboard(ppos);
|
||||||
|
|
||||||
if (_textLines.empty()) {
|
if (_textLines.empty()) {
|
||||||
splitString(str, 0);
|
splitString(str, 0);
|
||||||
|
|
|
@ -192,6 +192,13 @@ private:
|
||||||
void appendText_(const Common::U32String &strWithFont, uint oldLen);
|
void appendText_(const Common::U32String &strWithFont, uint oldLen);
|
||||||
void deletePreviousCharInternal(int *row, int *col);
|
void deletePreviousCharInternal(int *row, int *col);
|
||||||
void insertTextFromClipboard();
|
void insertTextFromClipboard();
|
||||||
|
void setTextInClipboard(const Common::U32String &str);
|
||||||
|
/**
|
||||||
|
* get text from WM clipboard or the global clipboard
|
||||||
|
* @param size will change to the length of real text in clipboard
|
||||||
|
* @return the text in clipboard, which may contained the format
|
||||||
|
*/
|
||||||
|
Common::U32String getTextFromClipboard(int &size);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
|
void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue