Skip to content

Commit

Permalink
Add tracking of current part to ChildSession.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Meeks <[email protected]>
Change-Id: Ide3b98e5c0b1306edb90b026801ffc89d6eed44e
  • Loading branch information
mmeeks authored and caolanm committed Dec 17, 2024
1 parent 8901849 commit 014d63c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/Rectangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct Rectangle
}
}

/// Ctor from comma separated values
Rectangle(const std::string &rectangle);

/// Ctor via top/left and bottom/right coordinates
static Rectangle create(int x1, int y1, int x2, int y2)
{
Expand Down
16 changes: 16 additions & 0 deletions common/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,22 @@ namespace Util
return s;
}

Rectangle::Rectangle(const std::string &rectangle)
{
StringVector tokens(StringVector::tokenize(rectangle, ','));
if (tokens.size() == 4)
{
_x = std::stoi(tokens[0]);
_y = std::stoi(tokens[1]);
_width = std::stoi(tokens[2]);
_height = std::stoi(tokens[3]);
}
else
{
_x = _y = _width = _height = 0;
}
}

} // namespace Util

namespace SigUtil {
Expand Down
17 changes: 17 additions & 0 deletions kit/ChildSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ChildSession::ChildSession(const std::shared_ptr<ProtocolHandlerInterface>& prot
, _jailRoot(jailRoot)
, _docManager(&docManager)
, _viewId(-1)
, _currentPart(-1)
, _isDocLoaded(false)
, _copyToClipboard(false)
, _canonicalViewId(-1)
Expand Down Expand Up @@ -981,7 +982,10 @@ bool ChildSession::loadDocument(const StringVector& tokens)
if (_docType != "text" && part != -1)
{
getLOKitDocument()->setPart(part);
_currentPart = part;
}
else
_currentPart = getLOKitDocument()->getPart();

// Respond by the document status
LOG_DBG("Sending status after loading view " << _viewId);
Expand Down Expand Up @@ -2973,6 +2977,7 @@ bool ChildSession::setClientPart(const StringVector& tokens)
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT && part != getLOKitDocument()->getPart())
{
getLOKitDocument()->setPart(part);
_currentPart = part;
}

return true;
Expand Down Expand Up @@ -3041,6 +3046,8 @@ bool ChildSession::moveSelectedClientParts(const StringVector& tokens)
return true; // Non-fatal to fail.
}


/// Only used for writer
bool ChildSession::setPage(const StringVector& tokens)
{
int page;
Expand All @@ -3054,6 +3061,7 @@ bool ChildSession::setPage(const StringVector& tokens)
getLOKitDocument()->setView(_viewId);

getLOKitDocument()->setPart(page);

return true;
}

Expand Down Expand Up @@ -3412,6 +3420,7 @@ void ChildSession::loKitCallback(const int type, const std::string& payload)
sendTextFrame("graphicinnertextarea: " + payload);
break;
case LOK_CALLBACK_CELL_CURSOR:
updateCursorPosition(payload);
sendTextFrame("cellcursor: " + payload);
break;
case LOK_CALLBACK_CELL_FORMULA:
Expand Down Expand Up @@ -3450,8 +3459,16 @@ void ChildSession::loKitCallback(const int type, const std::string& payload)
getStatus();
break;
case LOK_CALLBACK_SET_PART:
{
int part;
StringVector tokens(StringVector::tokenize(payload, ','));
if (getTokenInteger(tokens[1], "part", part) &&
getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT)
_currentPart = part;

sendTextFrame("setpart: " + payload);
break;
}
case LOK_CALLBACK_UNO_COMMAND_RESULT:
{
Parser parser;
Expand Down
8 changes: 8 additions & 0 deletions kit/ChildSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ class ChildSession final : public Session
Session::dumpState(oss);

oss << "\n\tviewId: " << _viewId
<< "\n\tpart: " << _currentPart
<< "\n\tcursor: " << _cursorPosition
<< "\n\tcanonicalViewId: " << _canonicalViewId
<< "\n\tisDocLoaded: " << _isDocLoaded
<< "\n\tdocType: " << _docType
Expand Down Expand Up @@ -291,6 +293,12 @@ class ChildSession final : public Session
/// View ID, returned by createView() or 0 by default.
int _viewId;

/// Currently visible part
int _currentPart;

/// Last known position of a cursor for prioritizing rendering
Util::Rectangle _cursorPosition;

/// Whether document has been opened successfully
bool _isDocLoaded;

Expand Down

0 comments on commit 014d63c

Please sign in to comment.