GRAPHICS: MACGUI: add clipboard which can help saving format from mactext for wm
This commit is contained in:
parent
8f36696f0f
commit
f68b3736a3
2 changed files with 42 additions and 20 deletions
|
@ -1727,8 +1727,8 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
|
|||
|
||||
// this is refer to how we deal U32String in splitString
|
||||
// maybe we can optimize this specifically
|
||||
int getU32StringLen(const Common::U32String &str) {
|
||||
int res = 0;
|
||||
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) {
|
||||
|
@ -1740,29 +1740,29 @@ int getU32StringLen(const Common::U32String &str) {
|
|||
l++;
|
||||
// if there are two \001, then we regard it as one character
|
||||
if (*l == '\001') {
|
||||
res++;
|
||||
l++;
|
||||
res += *l++;
|
||||
}
|
||||
} else if (*l == '\015') { // binary format
|
||||
// 12 for total
|
||||
// we are skipping the formatting stuffs
|
||||
l++;
|
||||
uint16 fontId = *l++; fontId = (fontId << 8) | *l++;
|
||||
l += 2;
|
||||
l++;
|
||||
uint16 fontSize = *l++; fontSize = (fontSize << 8) | *l++;
|
||||
uint16 palinfo1 = *l++; palinfo1 = (palinfo1 << 8) | *l++;
|
||||
uint16 palinfo2 = *l++; palinfo2 = (palinfo2 << 8) | *l++;
|
||||
uint16 palinfo3 = *l++; palinfo3 = (palinfo3 << 8) | *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++;
|
||||
uint16 fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3;
|
||||
l = readHex(&fontId, l, 4);
|
||||
l = readHex(&textSlant, l, 2);
|
||||
l = readHex(&fontSize, l, 4);
|
||||
l = readHex(&palinfo1, l, 4);
|
||||
l = readHex(&palinfo2, l, 4);
|
||||
l = readHex(&palinfo3, l, 4);
|
||||
l += 4;
|
||||
l += 2;
|
||||
l += 4;
|
||||
l += 4;
|
||||
l += 4;
|
||||
l += 4;
|
||||
} else {
|
||||
res++;
|
||||
l++;
|
||||
res += *l++;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
@ -1770,8 +1770,28 @@ int getU32StringLen(const Common::U32String &str) {
|
|||
|
||||
// mostly, we refering reshuffleParagraph to implement this function
|
||||
void MacText::insertTextFromClipboard() {
|
||||
Common::U32String str = g_system->getTextFromClipboard();
|
||||
int ppos = getU32StringLen(str);
|
||||
// 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 wm_str = _wm->_clipboard;
|
||||
// str is what we need
|
||||
Common::U32String str;
|
||||
int ppos = 0;
|
||||
if (wm_str.empty()) {
|
||||
// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
|
||||
str = global_str;
|
||||
ppos = str.size();
|
||||
} else {
|
||||
Common::U32String tmp = stripFormat(_wm->_clipboard);
|
||||
if (tmp == global_str) {
|
||||
// if the text is equal, then we use wm one which contains the format
|
||||
str = wm_str;
|
||||
ppos = tmp.size();
|
||||
} else {
|
||||
// otherwise, we prefer the global one
|
||||
str = global_str;
|
||||
ppos = str.size();
|
||||
}
|
||||
}
|
||||
|
||||
if (_textLines.empty()) {
|
||||
splitString(str, 0);
|
||||
|
|
|
@ -330,6 +330,8 @@ public:
|
|||
|
||||
MacWidget *_hoveredWidget;
|
||||
|
||||
Common::U32String _clipboard;
|
||||
|
||||
private:
|
||||
void loadDesktop();
|
||||
void drawDesktop();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue