Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Syntax Edit
  New Posts New Posts RSS Feed - [solved] Problem with the "Prev Bookmark"
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[solved] Problem with the "Prev Bookmark"

 Post Reply Post Reply
Author
Message
Matsu View Drop Down
Newbie
Newbie


Joined: 04 October 2016
Status: Offline
Points: 7
Post Options Post Options   Thanks (1) Thanks(1)   Quote Matsu Quote  Post ReplyReply Direct Link To This Post Topic: [solved] Problem with the "Prev Bookmark"
    Posted: 04 October 2016 at 4:18am
I'm using ToolkitPro v 17.2 with VisualStudio 2010.

At MDITextEditor.exe in sample.
After open the 100 lines text file, set some book mark(1 line,10 line,20 line,50 line and 90 line),select the last line and click "Prev Bookmark " button then the carret can be moved 10 line, 20 line, 50line and 90 l ine but can't be moved 1 line.

Thanks.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 07 October 2016 at 10:37am
Hello Matsu,

Thank you for information. Problem in method CXTPSyntaxEditCtrl::PrevBookmark().

I also found issue with CXTPSyntaxEditCtrl::NextBookmark()  - if cursor is in some invisible top line (but with bottom lines works fine)  then it start searching next bookmark from first visible line.

I have added this issue to our bugs base.

Regards,
 Oleksandr Lebed
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 04 November 2017 at 12:26am
Hello Matsu,

I'm finally finish this task!
Problem was in changing range of return values of method CXTPSyntaxEditCtrl::CalculateVisibleRow() some time ago. PrevBookmark() and NextBookmark() expected negative values for rows which are before visible rows. After changes there no difference between first visible row (relative number '1') and any row which higher than first visible row - CalculateVisibleRow() returns also '1'.

I have found out that only PrevBookmark() and NextBookmark()  need these negative values, so we need to add new method.
int CXTPSyntaxEditCtrl::CalculateVisibleRow(int nStartDocumentRow, int nDocumentRow)
{
    return max(CalculateVisibleRow_(nStartDocumentRow, nDocumentRow), 1);
}

int CXTPSyntaxEditCtrl::CalculateVisibleRow_(int nStartDocumentRow, int nDocumentRow)
{
    int nVisRow = nDocumentRow - nStartDocumentRow + 1;
    int nNextCollapsedRow = nStartDocumentRow - 1;
    const int nRowCount = GetRowCount();

    POSITION pos = GetLineMarksManager()->FindNextLineMark(nNextCollapsedRow, xtpEditLMT_Collapsed);
    while (pos != NULL)
    {
        XTP_EDIT_LMDATA* pData = GetLineMarksManager()->GetNextLineMark(pos, xtpEditLMT_Collapsed);
        if (pData && pData->m_nRow >= nNextCollapsedRow) // mark should be not within previous collapsed block
        {
            if (pData->m_nRow >= nDocumentRow) // finish if mark is greater then row to calculate for
                break;

            XTP_EDIT_COLLAPSEDBLOCK* pCoDBlk = (XTP_EDIT_COLLAPSEDBLOCK*)pData->m_Param.GetPtr();
            if (!pCoDBlk)
                continue;

            int nBlkEnd = min(nRowCount, pCoDBlk->collBlock.lcEnd.nLine);
            if (nBlkEnd > nDocumentRow)
                nBlkEnd = nDocumentRow;        // DocumentRow in invisible(collapsed) block
            
            int nHiddenRows = nBlkEnd - pCoDBlk->collBlock.lcStart.nLine;

            nVisRow -= nHiddenRows;
            nNextCollapsedRow = pData->m_nRow + nHiddenRows;
        }
    }
    return nVisRow;
}

void CXTPSyntaxEditCtrl::PrevBookmark()
{
    CXTPSyntaxEditLineMarksManager* pMgr = GetLineMarksManager();
    if (!pMgr)
    {
        ASSERT(FALSE);
        return;
    }
    int nRow = GetCurRow();
    int nVisRow = CalculateVisibleRow_(m_nTopRow, GetCurrentDocumentRow());

    // move up to the prev bookmark before the current collapsed block area
    int nPrevRow = nRow;
    do {
        pMgr->FindPrevLineMark(--nPrevRow, xtpEditLMT_Bookmark);
    } while (nPrevRow > 0 && CalculateVisibleRow_(m_nTopRow, nPrevRow) == nVisRow);

    if (nPrevRow < 0)
    {
        POSITION posLast = pMgr->GetLastLineMark(xtpEditLMT_Bookmark);
        XTP_EDIT_LMDATA* pData = pMgr->GetLineMarkAt(posLast, xtpEditLMT_Bookmark);
        nPrevRow = pData ? pData->m_nRow : -1;
    }
    if (CalculateVisibleRow_(m_nTopRow, nPrevRow) == nVisRow)
    {
        nPrevRow = -1;
    }

    if (nPrevRow >= 0)
    {
        SetCurPos(nPrevRow, 1);

        Invalidate(FALSE);
    }
}

void CXTPSyntaxEditCtrl::NextBookmark()
{
    CXTPSyntaxEditLineMarksManager* pMgr = GetLineMarksManager();
    if (!pMgr)
    {
        ASSERT(FALSE);
        return;
    }

    int nRow = GetCurRow();
    int nVisRow = CalculateVisibleRow_(m_nTopRow, GetCurrentDocumentRow());

    // move down to the next bookmark after the current collapsed block area
    int nNextRow = nRow;
    do {
        pMgr->FindNextLineMark(++nNextRow, xtpEditLMT_Bookmark);
    } while (nNextRow > 0 && CalculateVisibleRow_(m_nTopRow, nNextRow) == nVisRow);

    if (nNextRow < 0)
    {
        // find first line mark
        POSITION posFirst = pMgr->GetFirstLineMark(xtpEditLMT_Bookmark);
        XTP_EDIT_LMDATA* pData = pMgr->GetNextLineMark(posFirst, xtpEditLMT_Bookmark);
        nNextRow = pData ? pData->m_nRow : -1;
    }

    if (CalculateVisibleRow_(m_nTopRow, nNextRow) == nVisRow)
    {
        nNextRow = -1;
    }

    if (nNextRow >= 0)
    {
        SetCurPos(nNextRow, 1);

        Invalidate(FALSE);
    }
}

Also as you can see in new CalculateVisibleRow_() I have fixed navigation by bookmarks when bookmark within collapsed block. Before this cursor was set under collapsed block, not on it's own line.

Unfortunately I'm not sure that this fix will be included in the nearest release.

Regards,
 Oleksandr Lebed
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.