diff options
author | Eugene Sandulenko | 2017-08-03 22:50:01 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-08-04 21:54:20 +0200 |
commit | 23649e8d87bf2c1d8c93fa0c4a6502285b258429 (patch) | |
tree | bb1e573839ee5fbee1db80ae21b61c7136ce50ce /graphics/macgui | |
parent | 66f59aa893449596298a2cee1d8f761bcf8cc9bd (diff) | |
download | scummvm-rg350-23649e8d87bf2c1d8c93fa0c4a6502285b258429.tar.gz scummvm-rg350-23649e8d87bf2c1d8c93fa0c4a6502285b258429.tar.bz2 scummvm-rg350-23649e8d87bf2c1d8c93fa0c4a6502285b258429.zip |
GRAPHICS: MACGUI: Initial code for copying selection to clipboard
Diffstat (limited to 'graphics/macgui')
-rw-r--r-- | graphics/macgui/mactext.cpp | 76 | ||||
-rw-r--r-- | graphics/macgui/mactext.h | 2 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 14 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.h | 2 |
4 files changed, 94 insertions, 0 deletions
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index b3942f0d38..f2366790ef 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -492,4 +492,80 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) { } } +Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted) { + Common::String res; + + CLIP(startRow, 0, (int)_textLines.size() - 1); + CLIP(endRow, 0, (int)_textLines.size() - 1); + + for (int i = startRow; i <= endRow; i++) { + if (i == startRow && i == endRow) { + for (uint chunk = 0; chunk < _textLines[i].chunks.size() - 1; chunk++) { + if (startCol <= 0) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + if (endCol <= _textLines[i].chunks[chunk].text.size()) + res += _textLines[i].chunks[chunk].text; + else + res += Common::String(_textLines[i].chunks[chunk].text.c_str(), endCol); + } else if (_textLines[i].chunks[chunk].text.size() > startCol) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + res += Common::String(_textLines[i].chunks[chunk].text.c_str() + startCol); + } + + startCol -= _textLines[i].chunks[chunk].text.size(); + endCol -= _textLines[i].chunks[chunk].text.size(); + + if (endCol <= 0) + break; + } + } else if (i == startRow && startCol != 0) { + for (uint chunk = 0; chunk < _textLines[i].chunks.size() - 1; chunk++) { + if (startCol <= 0) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + res += _textLines[i].chunks[chunk].text; + } else if (_textLines[i].chunks[chunk].text.size() > startCol) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + res += Common::String(_textLines[i].chunks[chunk].text.c_str() + startCol); + } + + startCol -= _textLines[i].chunks[chunk].text.size(); + } + } else if (i == endRow) { + for (uint chunk = 0; chunk < _textLines[i].chunks.size() - 1; chunk++) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + if (endCol <= _textLines[i].chunks[chunk].text.size()) + res += _textLines[i].chunks[chunk].text; + else + res += Common::String(_textLines[i].chunks[chunk].text.c_str(), endCol); + + endCol -= _textLines[i].chunks[chunk].text.size(); + + if (endCol <= 0) + break; + } + } else { + for (uint chunk = 0; chunk < _textLines[i].chunks.size() - 1; chunk++) { + if (formatted) + res += _textLines[i].chunks[chunk].toString(); + + res += _textLines[i].chunks[chunk].text; + } + + res += '\n'; + } + } + + return res; +} + } // End of namespace Graphics diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index 7cbf40e8bc..eb567cf2a6 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -116,6 +116,8 @@ public: void getRowCol(int x, int y, int *sx, int *sy, int *row, int *col); + Common::String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false); + private: void splitString(Common::String &s); void render(int from, int to); diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 9d1de2f129..fb75f41cc5 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -212,6 +212,20 @@ void MacTextWindow::drawSelection() { } } +Common::String MacTextWindow::getSelection(bool formatted) { + if (_selectedText.endY == -1) + return Common::String(""); + + SelectedText s = _selectedText; + + if (s.startY > s.endY) { + SWAP(s.startRow, s.endRow); + SWAP(s.startCol, s.endCol); + } + + return _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, formatted); +} + bool MacTextWindow::processEvent(Common::Event &event) { /*WindowClick click =*/ isInBorder(event.mouse.x, event.mouse.y); diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h index bc1bf2d113..60ed820187 100644 --- a/graphics/macgui/mactextwindow.h +++ b/graphics/macgui/mactextwindow.h @@ -68,6 +68,8 @@ public: const Common::String getInput() { return _inputText; } void clearInput(); + Common::String getSelection(bool formatted = false); + private: void undrawInput(); void drawInput(); |