diff options
author | Eugene Sandulenko | 2017-08-14 09:19:41 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-08-14 09:19:41 +0200 |
commit | 615af937df6d2b7ea7a6b24630d7adb199eb2471 (patch) | |
tree | 560ab48f4eb19a99f6706a2cf2b01694c5945379 /graphics/macgui | |
parent | 3de1fd1f3ee9f62b163c4d897dc7a58e79f21ce3 (diff) | |
download | scummvm-rg350-615af937df6d2b7ea7a6b24630d7adb199eb2471.tar.gz scummvm-rg350-615af937df6d2b7ea7a6b24630d7adb199eb2471.tar.bz2 scummvm-rg350-615af937df6d2b7ea7a6b24630d7adb199eb2471.zip |
GRAPHICS: MACGUI: Initial code for MacTextWindow::cutSelection()
Diffstat (limited to 'graphics/macgui')
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 39 | ||||
-rw-r--r-- | graphics/macgui/mactextwindow.h | 3 |
2 files changed, 37 insertions, 5 deletions
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 6fc9cabf6a..a45d1d641b 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -234,6 +234,39 @@ void MacTextWindow::clearSelection() { _selectedText.endY = _selectedText.startY = -1; } +bool MacTextWindow::isCutAllowed() { + if (_selectedText.startRow >= (int)(_mactext->getLineCount() - _inputTextHeight) && + _selectedText.endRow >= (int)(_mactext->getLineCount() - _inputTextHeight)) + return true; + + return false; +} + +Common::String MacTextWindow::cutSelection() { + if (!isCutAllowed()) + return Common::String(""); + + SelectedText s = _selectedText; + + if (s.startY > s.endY || (s.startY == s.endY && s.startX > s.endX)) { + SWAP(s.startRow, s.endRow); + SWAP(s.startCol, s.endCol); + } + + Common::String selection = _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false); + + const char *selStart = strstr(_inputText.c_str(), selection.c_str()); + + if (!selStart) + warning("Cannot find substring '%s' in '%s'", selection.c_str(), _inputText.c_str()); + + int selPos = selStart - _inputText.c_str(); + + _inputText = Common::String(_inputText.c_str(), selPos) + Common::String(_inputText.c_str() + selPos + selection.size()); + + return selection; +} + bool MacTextWindow::processEvent(Common::Event &event) { WindowClick click = isInBorder(event.mouse.x, event.mouse.y); @@ -322,11 +355,7 @@ bool MacTextWindow::processEvent(Common::Event &event) { } else { _menu->enableCommand("Edit", "Copy", true); - bool cutAllowed = false; - - if (_selectedText.startRow >= (int)(_mactext->getLineCount() - _inputTextHeight) && - _selectedText.endRow >= (int)(_mactext->getLineCount() - _inputTextHeight)) - cutAllowed = true; + bool cutAllowed = isCutAllowed(); _menu->enableCommand("Edit", "Cut", cutAllowed); _menu->enableCommand("Edit", "Clear", cutAllowed); diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h index f2cf8bb639..6dd464e9af 100644 --- a/graphics/macgui/mactextwindow.h +++ b/graphics/macgui/mactextwindow.h @@ -71,9 +71,12 @@ public: Common::String getSelection(bool formatted = false, bool newlines = true); void clearSelection(); + Common::String cutSelection(); const SelectedText *getSelectedText() { return &_selectedText; } private: + bool isCutAllowed(); + void undrawInput(); void drawInput(); void drawSelection(); |