[Scummvm-git-logs] scummvm master -> 4419ae9a0b22809da759f813b2a7b3708cfe0ed6

sev- sev at scummvm.org
Thu Jun 3 11:19:25 UTC 2021


This automated email contains information about 22 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c84f16ca22 GRAPHICS: MACGUI: fix the coordinate calculating, bring the mactext selection work again
0176107051 GRAPHICS: MACGUI: add a check when we disabling the hoveredWidget
b11dfdfeaa GRAPHICS: MACGUI: change the behavior of cursor and selectedText, currently, we won't draw the cursor when we have selec
cfac0f0513 GRAPHICS: MACGUI: add offset to drawSelection
bd6887a6ea GRAPHICS: MACGUI: implement deleteSelection by using deletePreviousChar
73b10b3e5e GRAPHICS: MACGUI: clean the surface when we are drawing selection in mactext
4d4ad3c310 GRAPHICS: MACGUI: bring copy, paste, cut to mactext. currently, we are using copy with formatting
f0763f44cc GRAPHICS: MACGUI: fix the cursor position when using paste in mactext
1b92db9f80 GRAPHICS: MACGUI: fix incorrect selection drawing when mactext is not active
f320de75ff GRAPHICS: MACGUI: implement delete to mactext by using existing functions
eda07a54be GRAPHICS: MACGUI: modify the behaviour when we inserting character when we have selection in mactext
ecac522c7f GRAPHICS: MACGUI: make mactext can scrollable now
924b7e1e08 GRAPHICS: MACGUI: fix incorrect offset calculating when drawing selection in mactext
f89977b4a2 GRAPHICS: MACGUI: fix and add the basic text operations in mactextwindow which is used in WAGE
8f36696f0f GRAPHICS: MACGUI: clean code for code analyse
f68b3736a3 GRAPHICS: MACGUI: add clipboard which can help saving format from mactext for wm
a5e6f59533 GRAPHICS: MACGUI: implement getTextFromClipboard and setTextInClipboard for mactext
43826c7839 GRAPHICS: MACGUI: clean the code for stripFormat in mactext
c88b6e2e04 GRAPHICS: MACGUI: move WM clipboard operations from mactext to macwindowmanager
e7e09e6bee GRAPHICS: MACGUI: make mactextwindow suit for new WM clipboard
d4abe958bd GRAPHICS: MACGUI: clean code for WM clipboard operations
4419ae9a0b GRAPHICS: MACGUI: add default format before we are using the text from global clipboard


Commit: c84f16ca2265ea5dabd4aef6c14e71fdb62443fb
    https://github.com/scummvm/scummvm/commit/c84f16ca2265ea5dabd4aef6c14e71fdb62443fb
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: fix the coordinate calculating, bring the mactext selection work again

Changed paths:
    graphics/macgui/macwindow.cpp


diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 77221f564b..814e67e4a7 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -424,7 +424,7 @@ bool MacWindow::processEvent(Common::Event &event) {
 
 	switch (event.type) {
 	case Common::EVENT_MOUSEMOVE:
-		if (_wm->_mouseDown && _wm->_hoveredWidget && !_wm->_hoveredWidget->_dims.contains(_dims.left - event.mouse.x, _dims.top - event.mouse.y)) {
+		if (_wm->_mouseDown && _wm->_hoveredWidget && !_wm->_hoveredWidget->_dims.contains(event.mouse.x - _dims.left, event.mouse.y - _dims.top)) {
 			_wm->_hoveredWidget->setActive(false);
 			_wm->_hoveredWidget = nullptr;
 		}


Commit: 0176107051206051ce3ab6d50e21e84a3be92531
    https://github.com/scummvm/scummvm/commit/0176107051206051ce3ab6d50e21e84a3be92531
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: add a check when we disabling the hoveredWidget

Changed paths:
    graphics/macgui/macwindow.cpp


diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 814e67e4a7..47b73ed54a 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -426,6 +426,9 @@ bool MacWindow::processEvent(Common::Event &event) {
 	case Common::EVENT_MOUSEMOVE:
 		if (_wm->_mouseDown && _wm->_hoveredWidget && !_wm->_hoveredWidget->_dims.contains(event.mouse.x - _dims.left, event.mouse.y - _dims.top)) {
 			_wm->_hoveredWidget->setActive(false);
+			// since we de-active the hoveredWidget, so we need to check whether it's the activeWidget of wm
+			if (_wm->getActiveWidget() == _wm->_hoveredWidget)
+				_wm->setActiveWidget(nullptr);
 			_wm->_hoveredWidget = nullptr;
 		}
 


Commit: b11dfdfeaa0e62b71cd79d6b443eca50d1e07c18
    https://github.com/scummvm/scummvm/commit/b11dfdfeaa0e62b71cd79d6b443eca50d1e07c18
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: change the behavior of cursor and selectedText, currently, we won't draw the cursor when we have selectedText

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 9a6dbc75b2..20799d2cd8 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1049,7 +1049,8 @@ bool MacText::draw(bool forceRedraw) {
 		_composeSurface->frameRect(borderRect, 0);
 	}
 
-	if (_cursorState)
+	// if we are drawing the selection text, then we don't draw the cursor
+	if (_cursorState && !(_selectedText.endY != -1 && _active))
 		_composeSurface->blitFrom(*_cursorSurface, *_cursorRect, Common::Point(_cursorX, _cursorY + offset.y + 1));
 
 	if (_selectedText.endY != -1 && _active)
@@ -1106,6 +1107,13 @@ void MacText::drawSelection() {
 	if (_selectedText.endY == -1)
 		return;
 
+	// we check if the selection size is 0, then we don't draw it anymore
+	// it's a small optimize, but can bring us correct behavior
+	if (_selectedText.startX == _selectedText.endX && _selectedText.startY == _selectedText.endY) {
+		_selectedText.startY = _selectedText.endY = -1;
+		return;
+	}
+
 	SelectedText s = _selectedText;
 
 	if (s.startY > s.endY || (s.startY == s.endY && s.startX > s.endX)) {


Commit: cfac0f0513c31ca2b936471f76648969430fc72c
    https://github.com/scummvm/scummvm/commit/cfac0f0513c31ca2b936471f76648969430fc72c
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: add offset to drawSelection

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 20799d2cd8..484f3cd94c 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1054,7 +1054,7 @@ bool MacText::draw(bool forceRedraw) {
 		_composeSurface->blitFrom(*_cursorSurface, *_cursorRect, Common::Point(_cursorX, _cursorY + offset.y + 1));
 
 	if (_selectedText.endY != -1 && _active)
-		drawSelection();
+		drawSelection(offset.x, offset.y);
 
 	return true;
 }
@@ -1103,13 +1103,13 @@ uint getNewlinesInString(const Common::U32String &str) {
 	return newLines;
 }
 
-void MacText::drawSelection() {
+void MacText::drawSelection(int xoff, int yoff) {
 	if (_selectedText.endY == -1)
 		return;
 
 	// we check if the selection size is 0, then we don't draw it anymore
 	// it's a small optimize, but can bring us correct behavior
-	if (_selectedText.startX == _selectedText.endX && _selectedText.startY == _selectedText.endY) {
+	if (!_inTextSelection && _selectedText.startX == _selectedText.endX && _selectedText.startY == _selectedText.endY) {
 		_selectedText.startY = _selectedText.endY = -1;
 		return;
 	}
@@ -1142,6 +1142,9 @@ void MacText::drawSelection() {
 	int numLines = 0;
 	int x1 = 0, x2 = 0;
 
+	start = MIN<int>(start + yoff, getDimensions().height());
+	end = MIN<int>(end + yoff, getDimensions().height());
+
 	for (int y = start; y < end; y++) {
 		if (!numLines) {
 			x1 = 0;
@@ -1155,6 +1158,8 @@ void MacText::drawSelection() {
 				numLines = getLineHeight(s.endRow);
 				x2 = s.endX;
 			}
+			x1 = MIN<int>(x1 + xoff, getDimensions().width() - 1);
+			x2 = MIN<int>(x2 + xoff, getDimensions().width() - 1);
 		} else {
 			numLines--;
 		}
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index a466baec20..f617f24e66 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -252,7 +252,7 @@ private:
 
 	void scroll(int delta);
 
-	void drawSelection();
+	void drawSelection(int xoff, int yoff);
 	void updateCursorPos();
 
 	void startMarking(int x, int y);


Commit: bd6887a6ea2e6a4ba7a8292f70a998b6286801b0
    https://github.com/scummvm/scummvm/commit/bd6887a6ea2e6a4ba7a8292f70a998b6286801b0
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: implement deleteSelection by using deletePreviousChar

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 484f3cd94c..5a2de7d715 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1293,8 +1293,7 @@ Common::U32String MacText::cutSelection() {
 
 	Common::U32String selection = MacText::getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false);
 
-	// TODO: Remove the actual text
-
+	deleteSelection();
 	clearSelection();
 
 	return selection;
@@ -1313,6 +1312,12 @@ bool MacText::processEvent(Common::Event &event) {
 
 		switch (event.kbd.keycode) {
 		case Common::KEYCODE_BACKSPACE:
+			// if we have the selectedText, then we delete it
+			if (_selectedText.endY != -1) {
+				cutSelection();
+				_contentIsDirty = true;
+				return true;
+			}
 			if (_cursorRow > 0 || _cursorCol > 0) {
 				deletePreviousChar(&_cursorRow, &_cursorCol);
 				updateCursorPos();
@@ -1719,10 +1724,42 @@ void MacText::insertChar(byte c, int *row, int *col) {
 	D(9, "**insertChar cursor row %d col %d", _cursorRow, _cursorCol);
 }
 
-void MacText::deletePreviousChar(int *row, int *col) {
-	if (*col == 0 && *row == 0) // nothing to do
+void MacText::deleteSelection() {
+	// TODO: maybe we need to implement an individual delete part for mactext
+	if (_selectedText.endY == -1 || (_selectedText.startX == _selectedText.endX && _selectedText.startY == _selectedText.endY))
 		return;
+	if (_selectedText.startRow == -1 || _selectedText.startCol == -1 || _selectedText.endRow == -1 || _selectedText.endCol == -1)
+		error("deleting non-existing selected area");
+
+	SelectedText s = _selectedText;
+	if (s.startY > s.endY || (s.startY == s.endY && s.startX > s.endX)) {
+		SWAP(s.startX, s.endX);
+		SWAP(s.startY, s.endY);
+		SWAP(s.startRow, s.endRow);
+		SWAP(s.startCol, s.endCol);
+	}
 
+	int row = s.endRow, col = s.endCol;
+
+	while (row != s.startRow || col != s.startCol) {
+		if (row == 0 && col == 0)
+			break;
+		deletePreviousCharInternal(&row, &col);
+	}
+
+	reshuffleParagraph(&row, &col);
+
+	_fullRefresh = true;
+	recalcDims();
+	render();
+
+	// update cursor position
+	_cursorRow = row;
+	_cursorCol = col;
+	updateCursorPos();
+}
+
+void MacText::deletePreviousCharInternal(int *row, int *col) {
 	if (*col == 0) { // Need to glue the lines
 		*col = getLineCharWidth(*row - 1);
 		(*row)--;
@@ -1755,6 +1792,12 @@ void MacText::deletePreviousChar(int *row, int *col) {
 	}
 
 	_textLines[*row].width = -1; // flush the cache
+}
+
+void MacText::deletePreviousChar(int *row, int *col) {
+	if (*col == 0 && *row == 0) // nothing to do
+		return;
+	deletePreviousCharInternal(row, col);
 
 	for (int i = 0; i < (int)_textLines.size(); i++) {
 		D(9, "**deleteChar line %d", i);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index f617f24e66..f7bb35cfba 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -190,6 +190,7 @@ public:
 
 private:
 	void appendText_(const Common::U32String &strWithFont, uint oldLen);
+	void deletePreviousCharInternal(int *row, int *col);
 
 public:
 	void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
@@ -203,6 +204,7 @@ public:
 	int getLineHeight(int line);
 	int getTextMaxWidth() { return _textMaxWidth; }
 
+	void deleteSelection();
 	void deletePreviousChar(int *row, int *col);
 	void addNewLine(int *row, int *col);
 	void insertChar(byte c, int *row, int *col);


Commit: 73b10b3e5e63f56177c594a262b0f8d75187d094
    https://github.com/scummvm/scummvm/commit/73b10b3e5e63f56177c594a262b0f8d75187d094
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: clean the surface when we are drawing selection in mactext

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 5a2de7d715..f1181d2a1e 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1032,8 +1032,17 @@ bool MacText::draw(bool forceRedraw) {
 	_contentIsDirty = false;
 	_cursorDirty = false;
 
+	// if we are drawing the selection, then we better clear the surface
+	// let me explain here, sometimes, when we are render the text in _surface, we may not render the whole line
+	// such as, a line only contains \n, thus, we may only render part of this line
+	// when we are drawing the selection, it will reverse all the pixels in selected area. And when you only render part of a line in selected area
+	// drawSelection will reverse that not rendered part again and again, and which will lead to blinking
+
 	Common::Point offset(calculateOffset());
 
+	if (_selectedText.endY != -1 && _active)
+		_composeSurface->clear(_bgcolor);
+
 	if (!_cursorState)
 		_composeSurface->blitFrom(*_cursorSurface2, *_cursorRect, Common::Point(_cursorX, _cursorY + offset.y + 1));
 


Commit: 4d4ad3c31097e45859b6a8b925b412edaddaefa1
    https://github.com/scummvm/scummvm/commit/4d4ad3c31097e45859b6a8b925b412edaddaefa1
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: bring copy, paste, cut to mactext. currently, we are using copy with formatting

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index f1181d2a1e..484c19728e 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1300,7 +1300,7 @@ Common::U32String MacText::cutSelection() {
 		SWAP(s.startCol, s.endCol);
 	}
 
-	Common::U32String selection = MacText::getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false);
+	Common::U32String selection = MacText::getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, true, false);
 
 	deleteSelection();
 	clearSelection();
@@ -1316,6 +1316,23 @@ bool MacText::processEvent(Common::Event &event) {
 		setActive(true);
 
 		if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
+			switch (event.kbd.keycode) {
+			case Common::KEYCODE_x:
+				g_system->setTextInClipboard(cutSelection());
+				return true;
+			case Common::KEYCODE_c:
+				g_system->setTextInClipboard(getSelection(true, false));
+				return true;
+			case Common::KEYCODE_v:
+				if (g_system->hasTextInClipboard()) {
+					if (_selectedText.endY != -1)
+						cutSelection();
+					insertTextFromClipboard();
+				}
+				return true;
+			default:
+				break;
+			}
 			return false;
 		}
 
@@ -1687,6 +1704,34 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 	return res;
 }
 
+void MacText::insertTextFromClipboard() {
+	Common::U32String str = g_system->getTextFromClipboard();
+	if (_textLines.empty()) {
+		splitString(str, 0);
+	} else {
+		int start = _cursorRow, end = _cursorRow;
+
+		while (start && !_textLines[start - 1].paragraphEnd)
+			start--;
+
+		while (end < (int)_textLines.size() - 1 && !_textLines[end].paragraphEnd)
+			end++;
+
+		Common::U32String pre_str = getTextChunk(start, 0, _cursorRow, _cursorCol, true, false);
+		Common::U32String sub_str = getTextChunk(_cursorRow, _cursorCol, end, getLineCharWidth(end, true), true, false);
+
+		// Remove it from the text
+		for (int i = start; i <= end; i++) {
+			_textLines.remove_at(start);
+		}
+		Common::U32String res = pre_str + str + sub_str;
+		splitString(pre_str + str + sub_str, start);
+	}
+	recalcDims();
+	render();
+	_fullRefresh = true;
+}
+
 //////////////////
 // Text editing
 void MacText::insertChar(byte c, int *row, int *col) {
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index f7bb35cfba..ae112b3a9a 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -191,6 +191,7 @@ public:
 private:
 	void appendText_(const Common::U32String &strWithFont, uint oldLen);
 	void deletePreviousCharInternal(int *row, int *col);
+	void insertTextFromClipboard();
 
 public:
 	void appendTextDefault(const Common::U32String &str, bool skipAdd = false);


Commit: f0763f44cc047e41de83573ff383833de02c4587
    https://github.com/scummvm/scummvm/commit/f0763f44cc047e41de83573ff383833de02c4587
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: fix the cursor position when using paste in mactext

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 484c19728e..3759bd621c 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1704,8 +1704,54 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 	return res;
 }
 
+// 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;
+	// 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
+			l++;
+			uint16 fontId = *l++; fontId = (fontId << 8) | *l++;
+			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++;
+		} else if (*l == '\016') {	// human-readable format
+			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);
+		} else {
+			res++;
+			l++;
+		}
+	}
+	return res;
+}
+
+// mostly, we refering reshuffleParagraph to implement this function
 void MacText::insertTextFromClipboard() {
 	Common::U32String str = g_system->getTextFromClipboard();
+	int ppos = getU32StringLen(str);
+
 	if (_textLines.empty()) {
 		splitString(str, 0);
 	} else {
@@ -1717,6 +1763,10 @@ void MacText::insertTextFromClipboard() {
 		while (end < (int)_textLines.size() - 1 && !_textLines[end].paragraphEnd)
 			end++;
 
+		for (int i = start; i < _cursorRow; i++)
+			ppos += getLineCharWidth(i);
+		ppos += _cursorCol;
+
 		Common::U32String pre_str = getTextChunk(start, 0, _cursorRow, _cursorCol, true, false);
 		Common::U32String sub_str = getTextChunk(_cursorRow, _cursorCol, end, getLineCharWidth(end, true), true, false);
 
@@ -1726,8 +1776,17 @@ void MacText::insertTextFromClipboard() {
 		}
 		Common::U32String res = pre_str + str + sub_str;
 		splitString(pre_str + str + sub_str, start);
+
+		_cursorRow = start;
+	}
+
+	while (ppos > getLineCharWidth(_cursorRow, true)) {
+		ppos -= getLineCharWidth(_cursorRow, true);
+		_cursorRow++;
 	}
+	_cursorCol = ppos;
 	recalcDims();
+	updateCursorPos();
 	render();
 	_fullRefresh = true;
 }


Commit: 1b92db9f80f5e8fa3ac5288321701f34e0e01e9d
    https://github.com/scummvm/scummvm/commit/1b92db9f80f5e8fa3ac5288321701f34e0e01e9d
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: fix incorrect selection drawing when mactext is not active

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 3759bd621c..ca57df9e7f 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1040,7 +1040,7 @@ bool MacText::draw(bool forceRedraw) {
 
 	Common::Point offset(calculateOffset());
 
-	if (_selectedText.endY != -1 && _active)
+	if (_selectedText.endY != -1)
 		_composeSurface->clear(_bgcolor);
 
 	if (!_cursorState)


Commit: f320de75ffcb3a811cfe8d3ab220364935e58d82
    https://github.com/scummvm/scummvm/commit/f320de75ffcb3a811cfe8d3ab220364935e58d82
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: implement delete to mactext by using existing functions

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index ca57df9e7f..ecec077466 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1408,8 +1408,25 @@ bool MacText::processEvent(Common::Event &event) {
 			return true;
 
 		case Common::KEYCODE_DELETE:
-			// TODO
-			warning("MacText::processEvent(): Delete is not yet implemented");
+			// first try to delete the selected text
+			if (_selectedText.endY != -1) {
+				cutSelection();
+				_contentIsDirty = true;
+				return true;
+			}
+			// move cursor to next one and delete previous char
+			if (_cursorCol >= getLineCharWidth(_cursorRow)) {
+				if (_cursorRow == getLineCount() - 1) {
+					return true;
+				}
+				_cursorRow++;
+				_cursorCol = 0;
+			} else {
+				_cursorCol++;
+			}
+			deletePreviousChar(&_cursorRow, &_cursorCol);
+			updateCursorPos();
+			_contentIsDirty = true;
 			return true;
 
 		default:


Commit: eda07a54be997f69519618803f69dbbfda1a87cf
    https://github.com/scummvm/scummvm/commit/eda07a54be997f69519618803f69dbbfda1a87cf
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: modify the behaviour when we inserting character when we have selection in mactext

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index ecec077466..15f22063b5 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1434,6 +1434,11 @@ bool MacText::processEvent(Common::Event &event) {
 				return false;
 
 			if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
+				// if we have selected text, then we delete it, then we try to insert char
+				if (_selectedText.endY != -1) {
+					cutSelection();
+					_contentIsDirty = true;
+				}
 				insertChar((byte)event.kbd.ascii, &_cursorRow, &_cursorCol);
 				updateCursorPos();
 				_contentIsDirty = true;


Commit: ecac522c7f5500145ca35c05ce76cd0140f04f0d
    https://github.com/scummvm/scummvm/commit/ecac522c7f5500145ca35c05ce76cd0140f04f0d
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: make mactext can scrollable now

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/macwindow.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 15f22063b5..83eea89128 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1028,21 +1028,23 @@ bool MacText::draw(bool forceRedraw) {
 		return false;
 	}
 
-	// TODO: Clear surface fully when background colour changes.
-	_contentIsDirty = false;
-	_cursorDirty = false;
-
 	// if we are drawing the selection, then we better clear the surface
 	// let me explain here, sometimes, when we are render the text in _surface, we may not render the whole line
 	// such as, a line only contains \n, thus, we may only render part of this line
 	// when we are drawing the selection, it will reverse all the pixels in selected area. And when you only render part of a line in selected area
 	// drawSelection will reverse that not rendered part again and again, and which will lead to blinking
 
-	Common::Point offset(calculateOffset());
-
-	if (_selectedText.endY != -1)
+	// we need to find out a way to judge whether we need to clear the surface
+	// currently, we just use the _contentIsDirty
+	if (_selectedText.endY != -1 || _contentIsDirty)
 		_composeSurface->clear(_bgcolor);
 
+	// TODO: Clear surface fully when background colour changes.
+	_contentIsDirty = false;
+	_cursorDirty = false;
+
+	Common::Point offset(calculateOffset());
+
 	if (!_cursorState)
 		_composeSurface->blitFrom(*_cursorSurface2, *_cursorRect, Common::Point(_cursorX, _cursorY + offset.y + 1));
 
diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 47b73ed54a..8cbd994857 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -493,6 +493,12 @@ bool MacWindow::processEvent(Common::Event &event) {
 
 		return false;
 
+	case Common::EVENT_WHEELUP:
+	case Common::EVENT_WHEELDOWN:
+		if (_wm->getActiveWidget() && _wm->getActiveWidget()->processEvent(event))
+			return true;
+		return false;
+
 	default:
 		return false;
 	}


Commit: 924b7e1e08cd5fbf56ffeac2709044513a92ba67
    https://github.com/scummvm/scummvm/commit/924b7e1e08cd5fbf56ffeac2709044513a92ba67
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: fix incorrect offset calculating when drawing selection in mactext

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 83eea89128..1544a6e66a 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1153,9 +1153,6 @@ void MacText::drawSelection(int xoff, int yoff) {
 	int numLines = 0;
 	int x1 = 0, x2 = 0;
 
-	start = MIN<int>(start + yoff, getDimensions().height());
-	end = MIN<int>(end + yoff, getDimensions().height());
-
 	for (int y = start; y < end; y++) {
 		if (!numLines) {
 			x1 = 0;
@@ -1175,7 +1172,7 @@ void MacText::drawSelection(int xoff, int yoff) {
 			numLines--;
 		}
 
-		byte *ptr = (byte *)_composeSurface->getBasePtr(x1, y);
+		byte *ptr = (byte *)_composeSurface->getBasePtr(x1, MIN<int>(y + yoff, getDimensions().height() - 1));
 
 		for (int x = x1; x < x2; x++, ptr++)
 			if (*ptr == _fgcolor)


Commit: f89977b4a27cc486e7de37bbf756377ff6f17b35
    https://github.com/scummvm/scummvm/commit/f89977b4a27cc486e7de37bbf756377ff6f17b35
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: fix and add the basic text operations in mactextwindow which is used in WAGE

Changed paths:
    graphics/macgui/mactextwindow.cpp


diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index ee323589dd..6f1fd4e2c8 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -217,7 +217,7 @@ bool MacTextWindow::draw(bool forceRedraw) {
 	// Compose
 	_mactext->draw(_composeSurface, 0, _scrollPos, _composeSurface->w, _scrollPos + _composeSurface->h, 1, 1);
 
-	if (_cursorState)
+	if (_cursorState && _selectedText.endY == -1)
 		_composeSurface->blitFrom(*_cursorSurface, *_cursorRect, Common::Point(_cursorX + 1, _cursorY + 1));
 
 	if (_selectedText.endY != -1)
@@ -392,13 +392,35 @@ bool MacTextWindow::processEvent(Common::Event &event) {
 		_wm->setActiveWindow(getId());
 
 		if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
+			switch (event.kbd.keycode) {
+			case Common::KEYCODE_x:
+				g_system->setTextInClipboard(cutSelection());
+				return true;
+			case Common::KEYCODE_c:
+				g_system->setTextInClipboard(getSelection(true, false));
+				return true;
+			case Common::KEYCODE_v:
+				if (g_system->hasTextInClipboard()) {
+					if (_selectedText.endY != -1)
+						cutSelection();
+					appendInput(g_system->getTextFromClipboard());
+					_inputIsDirty = true;
+				}
+				return true;
+			default:
+				break;
+			}
 			return false;
 		}
 
 		switch (event.kbd.keycode) {
 		case Common::KEYCODE_BACKSPACE:
 			if (!_inputText.empty()) {
-				_inputText.deleteLastChar();
+				if (_selectedText.endY != -1) {
+					cutSelection();
+				} else {
+					_inputText.deleteLastChar();
+				}
 				_inputIsDirty = true;
 			}
 			return true;
@@ -413,6 +435,8 @@ bool MacTextWindow::processEvent(Common::Event &event) {
 				return false;
 
 			if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
+				if (_selectedText.endY != -1)
+					cutSelection();
 				_inputText += (char)event.kbd.ascii;
 				_inputIsDirty = true;
 


Commit: 8f36696f0f459f00a311053b7ad1d2acb2c1e1dd
    https://github.com/scummvm/scummvm/commit/8f36696f0f459f00a311053b7ad1d2acb2c1e1dd
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: clean code for code analyse

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 1544a6e66a..ee3643ca49 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1795,7 +1795,6 @@ void MacText::insertTextFromClipboard() {
 		for (int i = start; i <= end; i++) {
 			_textLines.remove_at(start);
 		}
-		Common::U32String res = pre_str + str + sub_str;
 		splitString(pre_str + str + sub_str, start);
 
 		_cursorRow = start;


Commit: f68b3736a33b97b5b7ce365062684a2f5ca38ce6
    https://github.com/scummvm/scummvm/commit/f68b3736a33b97b5b7ce365062684a2f5ca38ce6
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: add clipboard which can help saving format from mactext for wm

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/macwindowmanager.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index ee3643ca49..a91cea7dbc 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -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);
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 7ea5d9b33b..aceece18e8 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -330,6 +330,8 @@ public:
 
 	MacWidget *_hoveredWidget;
 
+	Common::U32String _clipboard;
+
 private:
 	void loadDesktop();
 	void drawDesktop();


Commit: a5e6f5953386514ae6d46df0f080245ee313c473
    https://github.com/scummvm/scummvm/commit/a5e6f5953386514ae6d46df0f080245ee313c473
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: implement getTextFromClipboard and setTextInClipboard for mactext

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index a91cea7dbc..52e101697e 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1307,6 +1307,54 @@ Common::U32String MacText::cutSelection() {
 	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) {
 	if (event.type == Common::EVENT_KEYDOWN) {
 		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)) {
 			switch (event.kbd.keycode) {
 			case Common::KEYCODE_x:
-				g_system->setTextInClipboard(cutSelection());
+				setTextInClipboard(cutSelection());
 				return true;
 			case Common::KEYCODE_c:
-				g_system->setTextInClipboard(getSelection(true, false));
+				setTextInClipboard(getSelection(true, false));
 				return true;
 			case Common::KEYCODE_v:
 				if (g_system->hasTextInClipboard()) {
@@ -1725,73 +1773,34 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 	return res;
 }
 
-// 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;
-}
-
-// 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 MacText::getTextFromClipboard(int &size) {
 	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();
+		size = 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();
+			size = tmp.size();
 		} else {
 			// otherwise, we prefer the global one
 			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()) {
 		splitString(str, 0);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index ae112b3a9a..ee86ef31cb 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -192,6 +192,13 @@ private:
 	void appendText_(const Common::U32String &strWithFont, uint oldLen);
 	void deletePreviousCharInternal(int *row, int *col);
 	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:
 	void appendTextDefault(const Common::U32String &str, bool skipAdd = false);


Commit: 43826c7839a6f2fb0ff721e487cc8e4304761ed9
    https://github.com/scummvm/scummvm/commit/43826c7839a6f2fb0ff721e487cc8e4304761ed9
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: clean the code for stripFormat in mactext

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 52e101697e..d74ef15b5d 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1325,24 +1325,11 @@ Common::U32String stripFormat(const Common::U32String &str) {
 				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;
+			// this number 12, and the number 23, is the size of our format
+			l += 12;
 		} 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;
+			l += 23;
 		} else {
 			res += *l++;
 		}


Commit: c88b6e2e048827f42e9acacb9ca8934473273752
    https://github.com/scummvm/scummvm/commit/c88b6e2e048827f42e9acacb9ca8934473273752
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: move WM clipboard operations from mactext to macwindowmanager

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index d74ef15b5d..2172c2ffce 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1307,41 +1307,6 @@ Common::U32String MacText::cutSelection() {
 	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
-			// we are skipping the formatting stuffs
-			// this number 12, and the number 23, is the size of our format
-			l += 12;
-		} else if (*l == '\016') {	// human-readable format
-			l += 23;
-		} 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) {
 	if (event.type == Common::EVENT_KEYDOWN) {
 		if (!_editable)
@@ -1352,10 +1317,10 @@ bool MacText::processEvent(Common::Event &event) {
 		if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
 			switch (event.kbd.keycode) {
 			case Common::KEYCODE_x:
-				setTextInClipboard(cutSelection());
+				_wm->setTextInClipboard(cutSelection());
 				return true;
 			case Common::KEYCODE_c:
-				setTextInClipboard(getSelection(true, false));
+				_wm->setTextInClipboard(getSelection(true, false));
 				return true;
 			case Common::KEYCODE_v:
 				if (g_system->hasTextInClipboard()) {
@@ -1760,34 +1725,10 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 	return res;
 }
 
-Common::U32String MacText::getTextFromClipboard(int &size) {
-	Common::U32String global_str = g_system->getTextFromClipboard();
-	Common::U32String wm_str = _wm->_clipboard;
-	// str is what we need
-	Common::U32String str;
-	if (wm_str.empty()) {
-		// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
-		str = global_str;
-		size = 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;
-			size = tmp.size();
-		} else {
-			// otherwise, we prefer the global one
-			str = global_str;
-			size = str.size();
-		}
-	}
-	return str;
-}
-
 // mostly, we refering reshuffleParagraph to implement this function
 void MacText::insertTextFromClipboard() {
 	int ppos = 0;
-	Common::U32String str = getTextFromClipboard(ppos);
+	Common::U32String str = _wm->getTextFromClipboard(&ppos);
 
 	if (_textLines.empty()) {
 		splitString(str, 0);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index ee86ef31cb..ae112b3a9a 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -192,13 +192,6 @@ private:
 	void appendText_(const Common::U32String &strWithFont, uint oldLen);
 	void deletePreviousCharInternal(int *row, int *col);
 	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:
 	void appendTextDefault(const Common::U32String &str, bool skipAdd = false);
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 08a2c76197..23d3a08bce 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -395,6 +395,68 @@ void MacWindowManager::disableScreenCopy() {
 	g_system->copyRectToScreen(_screenCopy->getBasePtr(0, 0), _screenCopy->pitch, 0, 0, _screenCopy->w, _screenCopy->h);
 }
 
+// this is refer to how we deal U32String in splitString in mactext
+// 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
+			// we are skipping the formatting stuffs
+			// this number 12, and the number 23, is the size of our format
+			l += 12;
+		} else if (*l == '\016') {	// human-readable format
+			l += 23;
+		} else {
+			res += *l++;
+		}
+	}
+	return res;
+}
+
+void MacWindowManager::setTextInClipboard(const Common::U32String &str) {
+	_clipboard = str;
+	g_system->setTextInClipboard(stripFormat(str));
+}
+
+Common::U32String MacWindowManager::getTextFromClipboard(int *size) {
+	Common::U32String global_str = g_system->getTextFromClipboard();
+	Common::U32String wm_str = _clipboard;
+	// str is what we need
+	Common::U32String str;
+	if (wm_str.empty()) {
+		// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
+		str = global_str;
+		if (size)
+			*size = str.size();
+	} else {
+		Common::U32String tmp = stripFormat(_clipboard);
+		if (tmp == global_str) {
+			// if the text is equal, then we use wm one which contains the format
+			str = wm_str;
+			if (size)
+				*size = tmp.size();
+		} else {
+			// otherwise, we prefer the global one
+			str = global_str;
+			if (size)
+				*size = str.size();
+		}
+	}
+	return str;
+}
+
 bool MacWindowManager::isMenuActive() {
 	if (!_menu)
 		return false;
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index aceece18e8..41c39db797 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -315,6 +315,14 @@ public:
 	Common::SeekableReadStream *getBorderFile(byte windowType, uint32 flags);
 	Common::SeekableReadStream *getFile(const Common::String &filename);
 
+	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 = nullptr);
+
 public:
 	MacFontManager *_fontMan;
 	uint32 _mode;
@@ -330,8 +338,6 @@ public:
 
 	MacWidget *_hoveredWidget;
 
-	Common::U32String _clipboard;
-
 private:
 	void loadDesktop();
 	void drawDesktop();
@@ -388,6 +394,8 @@ private:
 	Common::HashMap<uint32, uint> _colorHash;
 
 	Common::Archive *_dataBundle;
+
+	Common::U32String _clipboard;
 };
 
 } // End of namespace Graphics


Commit: e7e09e6beedaf74ea91f27b8b9541ebaee93c0f1
    https://github.com/scummvm/scummvm/commit/e7e09e6beedaf74ea91f27b8b9541ebaee93c0f1
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: make mactextwindow suit for new WM clipboard

Changed paths:
    graphics/macgui/mactextwindow.cpp


diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index 6f1fd4e2c8..399f2f854d 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -394,16 +394,16 @@ bool MacTextWindow::processEvent(Common::Event &event) {
 		if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
 			switch (event.kbd.keycode) {
 			case Common::KEYCODE_x:
-				g_system->setTextInClipboard(cutSelection());
+				_wm->setTextInClipboard(cutSelection());
 				return true;
 			case Common::KEYCODE_c:
-				g_system->setTextInClipboard(getSelection(true, false));
+				_wm->setTextInClipboard(getSelection(true, false));
 				return true;
 			case Common::KEYCODE_v:
 				if (g_system->hasTextInClipboard()) {
 					if (_selectedText.endY != -1)
 						cutSelection();
-					appendInput(g_system->getTextFromClipboard());
+					appendInput(_wm->getTextFromClipboard());
 					_inputIsDirty = true;
 				}
 				return true;


Commit: d4abe958bdf3c4d25c27f4011d5a19b3ee56e541
    https://github.com/scummvm/scummvm/commit/d4abe958bdf3c4d25c27f4011d5a19b3ee56e541
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: clean code for WM clipboard operations

Changed paths:
    graphics/macgui/macwindowmanager.cpp


diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 23d3a08bce..c2b17a594f 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -432,10 +432,9 @@ void MacWindowManager::setTextInClipboard(const Common::U32String &str) {
 
 Common::U32String MacWindowManager::getTextFromClipboard(int *size) {
 	Common::U32String global_str = g_system->getTextFromClipboard();
-	Common::U32String wm_str = _clipboard;
 	// str is what we need
 	Common::U32String str;
-	if (wm_str.empty()) {
+	if (_clipboard.empty()) {
 		// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
 		str = global_str;
 		if (size)
@@ -444,7 +443,7 @@ Common::U32String MacWindowManager::getTextFromClipboard(int *size) {
 		Common::U32String tmp = stripFormat(_clipboard);
 		if (tmp == global_str) {
 			// if the text is equal, then we use wm one which contains the format
-			str = wm_str;
+			str = _clipboard;
 			if (size)
 				*size = tmp.size();
 		} else {


Commit: 4419ae9a0b22809da759f813b2a7b3708cfe0ed6
    https://github.com/scummvm/scummvm/commit/4419ae9a0b22809da759f813b2a7b3708cfe0ed6
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-06-03T13:19:10+02:00

Commit Message:
GRAPHICS: MACGUI: add default format before we are using the text from global clipboard

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 2172c2ffce..26fcec52c3 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1728,7 +1728,7 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 // mostly, we refering reshuffleParagraph to implement this function
 void MacText::insertTextFromClipboard() {
 	int ppos = 0;
-	Common::U32String str = _wm->getTextFromClipboard(&ppos);
+	Common::U32String str = _wm->getTextFromClipboard(Common::U32String(_defaultFormatting.toString()), &ppos);
 
 	if (_textLines.empty()) {
 		splitString(str, 0);
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index c2b17a594f..37331e585a 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -430,13 +430,13 @@ void MacWindowManager::setTextInClipboard(const Common::U32String &str) {
 	g_system->setTextInClipboard(stripFormat(str));
 }
 
-Common::U32String MacWindowManager::getTextFromClipboard(int *size) {
+Common::U32String MacWindowManager::getTextFromClipboard(const Common::U32String &format, int *size) {
 	Common::U32String global_str = g_system->getTextFromClipboard();
 	// str is what we need
 	Common::U32String str;
 	if (_clipboard.empty()) {
 		// if wm clipboard is empty, then we use the global clipboard, which won't contain the format
-		str = global_str;
+		str = format + global_str;
 		if (size)
 			*size = str.size();
 	} else {
@@ -448,7 +448,7 @@ Common::U32String MacWindowManager::getTextFromClipboard(int *size) {
 				*size = tmp.size();
 		} else {
 			// otherwise, we prefer the global one
-			str = global_str;
+			str = format + global_str;
 			if (size)
 				*size = str.size();
 		}
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 41c39db797..70899dd81e 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -321,7 +321,7 @@ public:
 	 * @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 = nullptr);
+	Common::U32String getTextFromClipboard(const Common::U32String &format = Common::U32String(), int *size = nullptr);
 
 public:
 	MacFontManager *_fontMan;




More information about the Scummvm-git-logs mailing list