Skip to content

Commit

Permalink
GRAPHICS: MACGUI: Initial code for Cutting/Paste multiline input texts
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 8, 2017
1 parent aef786f commit 0e2d14a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engines/wage/gui.cpp
Expand Up @@ -391,7 +391,7 @@ void Gui::actionCut() {
int startPos = s->startCol;
int endPos = s->endCol;

if (startPos > endPos)
if (s->startRow > s->endRow || (s->startRow == s->endRow && startPos > endPos))
SWAP(startPos, endPos);

Common::String input = _consoleWindow->getInput();
Expand Down
5 changes: 3 additions & 2 deletions graphics/macgui/mactext.cpp
Expand Up @@ -498,7 +498,7 @@ 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 MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {
Common::String res;

startRow = CLIP(startRow, 0, (int)_textLines.size() - 1);
Expand Down Expand Up @@ -567,7 +567,8 @@ Common::String MacText::getTextChunk(int startRow, int startCol, int endRow, int
res += _textLines[i].chunks[chunk].text;
}

res += '\n';
if (newlines)
res += '\n';
}
}

Expand Down
2 changes: 1 addition & 1 deletion graphics/macgui/mactext.h
Expand Up @@ -116,7 +116,7 @@ class MacText {

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);
Common::String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);

private:
void splitString(Common::String &s);
Expand Down
7 changes: 4 additions & 3 deletions graphics/macgui/mactextwindow.cpp
Expand Up @@ -216,7 +216,7 @@ void MacTextWindow::drawSelection() {
}
}

Common::String MacTextWindow::getSelection(bool formatted) {
Common::String MacTextWindow::getSelection(bool formatted, bool newlines) {
if (_selectedText.endY == -1)
return Common::String("");

Expand All @@ -227,7 +227,7 @@ Common::String MacTextWindow::getSelection(bool formatted) {
SWAP(s.startCol, s.endCol);
}

return _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, formatted);
return _mactext->getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, formatted, newlines);
}

void MacTextWindow::clearSelection() {
Expand Down Expand Up @@ -324,7 +324,8 @@ bool MacTextWindow::processEvent(Common::Event &event) {

bool cutAllowed = false;

if (_selectedText.startRow == _selectedText.endRow && _selectedText.startRow == _mactext->getLineCount() - 1)
if (_selectedText.startRow >= _mactext->getLineCount() - _inputTextHeight &&
_selectedText.endRow >= _mactext->getLineCount() - _inputTextHeight)
cutAllowed = true;

_menu->enableCommand("Edit", "Cut", cutAllowed);
Expand Down
2 changes: 1 addition & 1 deletion graphics/macgui/mactextwindow.h
Expand Up @@ -69,7 +69,7 @@ class MacTextWindow : public MacWindow {
void clearInput();
void appendInput(Common::String str);

Common::String getSelection(bool formatted = false);
Common::String getSelection(bool formatted = false, bool newlines = true);
void clearSelection();
const SelectedText *getSelectedText() { return &_selectedText; }

Expand Down

0 comments on commit 0e2d14a

Please sign in to comment.