Exemplo n.º 1
0
void CInvertSplit::SavePosition()
{
	if ( GetRowCount() == 1 ) 
        return;

    int ideal;
    GetRowInfo(0, m_nUpSize, ideal);
    GetRowInfo(1, m_nDownSize, ideal);
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pWnd - 
//-----------------------------------------------------------------------------
void CMySplitterWnd::ToggleMax(CWnd *pWnd)
{
	int ir, ic;

	if(!pMaxPrev)
	{
		int dummy;
		// save current info
		GetRowInfo(0, sizePrev[1][0], dummy);
		GetRowInfo(1, sizePrev[1][1], dummy);
		GetColumnInfo(0, sizePrev[0][0], dummy);
		GetColumnInfo(1, sizePrev[0][1], dummy);
	}

	if(pWnd != pMaxPrev)
	{
		// maximize this one
		int iRow, iCol;
		CRect r;
		GetClientRect(r);
		VERIFY(IsChildPane(pWnd, &iRow, &iCol));

		for(ir = 0; ir < 2; ir++)
		{
			for(ic = 0; ic < 2; ic++)
			{
				SetRowInfo(ir, 0, 0);
				SetColumnInfo(ic, 0, 0);
			}
		}

		SetRowInfo(iRow, r.Height(), 5);
		SetColumnInfo(iCol, r.Width(), 5);

		pMaxPrev = pWnd;
	}
	else
	{
		// restore saved info
		SetRowInfo(0, sizePrev[1][0], 0);
		SetRowInfo(1, sizePrev[1][1], 0);
		SetColumnInfo(0, sizePrev[0][0], 0);
		SetColumnInfo(1, sizePrev[0][1], 0);

		pMaxPrev = NULL;
	}

	RecalcLayout();
}
int CXTPSyntaxEditDrawTextProcessor::DispPosToStrPos(int nRow, int nDispPos, BOOL bVirtualSpace)
{
	CXTPRowInfo* pRowI = GetRowInfo(nRow);
	ASSERT(pRowI);
	if (!pRowI)
		return 0;

	ASSERT(nDispPos >= 0);
	if (nDispPos < 0)
		return 0;

	int nCount = pRowI->arDispCol2StrPos.GetDataSize();
	if (nDispPos >= nCount)
	{
		int nStrPos = nCount > 0 ? pRowI->arDispCol2StrPos[nCount - 1] : 0;
		if (bVirtualSpace)
		{
			int nCount2 = pRowI->arStrPos2DispCol.GetDataSize();
			ASSERT(nStrPos <= nCount2);

			int nStrPos2 = min(nStrPos, nCount2 - 1);
			int nLastDispPos = (nStrPos2 >= 0) ? (pRowI->arStrPos2DispCol[nStrPos2]) : nCount;
			ASSERT(nDispPos >= nLastDispPos);

			nStrPos += nDispPos - nLastDispPos /* + 1*/;
		}
		else
		{
			nStrPos++;
		}
		return nStrPos;
	}

	return pRowI->arDispCol2StrPos[nDispPos];
}
Exemplo n.º 4
0
void CInvertSplit::OnSize(UINT nType, int cx, int cy) 
{
    
    CSplitterWnd::OnSize(nType, cx, cy);

    if ( ! m_bInited ) 
        return;

    int ideal, Up, Down;
    GetRowInfo(0, Up, ideal);
    GetRowInfo(1, Down, ideal);
    
    Up = m_nUpSize*(Up+Down)/(m_nDownSize+m_nUpSize);
    SetRowInfo(0, Up, 10);
    RecalcLayout();

}
void CXTPSyntaxEditDrawTextProcessor::SetRowTabPositions(int nRow, LPCTSTR pcszOrigRowText)
{
	CXTPRowInfo* pRowI = GetRowInfo(nRow);
	ASSERT(pRowI);
	if (!pRowI)
		return;

	pRowI->arTabs.RemoveAll();
	pRowI->arDispCol2StrPos.RemoveAll();
	pRowI->arStrPos2DispCol.RemoveAll();

	int nDispPos = 0;
	int nStrPos = 0;
	for (LPCTSTR p = pcszOrigRowText; p && *p != 0; p = _tcsinc(p), nStrPos++)
	{
		pRowI->arStrPos2DispCol.AddData(nDispPos);

		if (*p == _T('\t'))
		{
			int nSpaces = m_nTabSize - (nDispPos % m_nTabSize);
			for (int i = 0; i < nSpaces; i++)
			{
				if (i == 0)
				{
					pRowI->arTabs.AddData(0);
					pRowI->arDispCol2StrPos.AddData(nStrPos);
				}
				else
				{
					pRowI->arTabs.AddData((BYTE)(nSpaces - i));
					//pRowI->arDispCol2StrPos.AddData(nStrPos + 1);
//Corrected, only with the next real character we have the next nStrPos.
					pRowI->arDispCol2StrPos.AddData(nStrPos);
				}
			}
			nDispPos += nSpaces;
		}
		else
		{
#ifdef XTP_FIXED
// multi-byte character incorrect.
			for (int index = 0; index < ( isleadbyte(*p) != 0 ? 2 : 1 ); index ++)
			{
				pRowI->arTabs.AddData(0);
				pRowI->arDispCol2StrPos.AddData(nStrPos);
				nDispPos++;
			}
#else
			pRowI->arTabs.AddData(0);
			pRowI->arDispCol2StrPos.AddData(nStrPos);
			nDispPos++;
#endif
		}
	}
	pRowI->arStrPos2DispCol.AddData(nDispPos);
	pRowI->arDispCol2StrPos.AddData(nStrPos);
}
int CXTPSyntaxEditDrawTextProcessor::GetRowWidth(int nRow)
{
	CXTPRowInfo* pRI = GetRowInfo(nRow);
	ASSERT(pRI);
	if (pRI)
		return pRI->nMaxWidth;

	return 0;
}
Exemplo n.º 7
0
void CMySplitterWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
  CSplitterWnd::OnLButtonUp(nFlags, point);

  // this hideous code is so that we know when the user has resized the
  // input pane, so we don't snap the size back to what it was
  if (m_pDoc)
    {
    int cyCur,
        cyMin;
    GetRowInfo (COMMAND_PANE, cyCur, cyMin);

    // snap to boundary stuff (version 4.16)
    if (((GetKeyState (VK_LCONTROL) & 0x8000) != 0 ||
        (GetKeyState (VK_RCONTROL) & 0x8000) != 0) && m_pDoc->m_input_font)
      {
      CDC dc;

      dc.CreateCompatibleDC (NULL);
      dc.SelectObject (m_pDoc->m_input_font);

      TEXTMETRIC tm;
      dc.GetTextMetrics(&tm);

      // need to know height of entire font (eg. 12 point FixedSys is 15)
      int m_iLineHeight = tm.tmHeight; 

      const int iFudge = 4;   // trial and error stuff, if anyone has a better idea let me know

      double fLines = (cyCur - iFudge) / m_iLineHeight;
      int iLines = floor (fLines + 0.5);   // round to nearest number of lines
      if (iLines)   
        cyCur =  m_iLineHeight * iLines + iFudge;  // calculate desired height for those lines
      else
        cyCur = 0;  // zero lines is still zero
      } // end of ctrl key held down

    if (!(m_pDoc->m_mush_name.IsEmpty ()))
      App.db_write_int ("worlds", (LPCTSTR) CFormat ("%s:%s", (LPCTSTR) m_pDoc->m_mush_name, "Bottom Height"), cyCur);

//    TRACE1 ("Bottom height (saved) = %i\n", cyCur);

    if (m_pDoc->m_pActiveCommandView)
      m_pDoc->m_pActiveCommandView->m_owner_frame->FixUpSplitterBar ();
    else if (m_pDoc->m_pActiveOutputView)
      m_pDoc->m_pActiveOutputView->m_owner_frame->FixUpSplitterBar ();

	  }

}
int CXTPSyntaxEditDrawTextProcessor::GetRowsMaxWidth()
{
	int nMaxWidth = 0;

	int nRowsCount = GetRowsCount(TRUE);
	for (int i = 0; i < nRowsCount; i++)
	{
		CXTPRowInfo* pRI = GetRowInfo(i);
		if (pRI && pRI->nMaxWidth > nMaxWidth)
		{
			nMaxWidth = pRI->nMaxWidth;
		}
	}

	return nMaxWidth;
}
Exemplo n.º 9
0
void CSizingControlBar::GetRowSizingBars(CSCBArray& arrSCBars)
{
    arrSCBars.RemoveAll();

    int nFirst, nLast, nThis;
    GetRowInfo(nFirst, nLast, nThis);

    for (int i = nFirst; i <= nLast; i++)
    {
        CControlBar* pBar = (CControlBar*)m_pDockBar->m_arrBars[i];
        if (HIWORD(pBar) == 0) continue; // placeholder
        if (!pBar->IsVisible()) continue;
        if (FindSizingBar(pBar) >= 0)
            arrSCBars.Add((CSizingControlBar*)pBar);
    }
}
Exemplo n.º 10
0
void CSizingControlBar::AlignControlBars()
{
    int nFirst, nLast, nThis;
    GetRowInfo(nFirst, nLast, nThis);

    BOOL bHorz = IsHorzDocked();
    BOOL bNeedRecalc = FALSE;
    int nPos, nAlign = bHorz ? -2 : 0;

    CRect rc, rcDock;
    m_pDockBar->GetWindowRect(&rcDock);

    for (int i = nFirst; i <= nLast; i++)
    {
        CControlBar* pBar = (CControlBar*)m_pDockBar->m_arrBars[i];
        if (HIWORD(pBar) == 0) continue; // placeholder
        if (!pBar->IsVisible()) continue;

        pBar->GetWindowRect(&rc);
        rc.OffsetRect(-rcDock.TopLeft());

        if ((nPos = FindSizingBar(pBar)) >= 0)
            rc = CRect(rc.TopLeft(), bHorz ?
                m_arrBars[nPos]->m_szHorz : m_arrBars[nPos]->m_szVert);

        if ((bHorz ? rc.left : rc.top) != nAlign)
        {
            if (!bHorz)
                rc.OffsetRect(0, nAlign - rc.top - 2);
            else if (m_nDockBarID == AFX_IDW_DOCKBAR_TOP)
                rc.OffsetRect(nAlign - rc.left, -2);
            else
                rc.OffsetRect(nAlign - rc.left, 0);
            pBar->MoveWindow(rc);
            bNeedRecalc = TRUE;
        }
        nAlign += (bHorz ? rc.Width() : rc.Height()) - 2;
    }

    if (bNeedRecalc)
    {
        m_pDockSite->DelayRecalcLayout();
        TRACE(_T("ccc\n"));
    }
}
int CXTPSyntaxEditDrawTextProcessor::AlignColIdxToTabs(int nRow, int nCol, BOOL bVirtualSpace)
{
	CXTPRowInfo* pRI = GetRowInfo(nRow);
	ASSERT(pRI);
	if (!pRI)
		return nCol;
	if (nCol >= 0 && nCol < pRI->arTabs.GetDataSize())
	{
		nCol += pRI->arTabs[nCol];
	}

	if (!bVirtualSpace && nCol > pRI->arCharsEnds.GetDataSize())
	{
		nCol = pRI->arCharsEnds.GetDataSize();
	}

	return nCol;
}
int CXTPSyntaxEditDrawTextProcessor::GetColPosX(int nRow, int nCol, int* pnChawWidth,
												 BOOL bVirtualSpace)
{
	CXTPRowInfo* pRI = GetRowInfo(nRow);
	if (!pRI)
		return 0;

	int nPosX = 0;
	if (pnChawWidth)
		*pnChawWidth = 0;

	int nColsCount = pRI->arCharsEnds.GetDataSize();

	if (nCol <= 0)
	{
		nPosX = 0;
	}
	else if (nCol < nColsCount)
	{
		nPosX = pRI->arCharsEnds[nCol - 1];
		if (pnChawWidth)
			*pnChawWidth = pRI->arCharsEnds[nCol] - pRI->arCharsEnds[nCol - 1];
	}
	else
	{
		if (nColsCount)
			nPosX = pRI->arCharsEnds[nColsCount - 1];

		if (bVirtualSpace)
		{
			ASSERT(m_nSpaceWidth);

			nPosX += m_nSpaceWidth * (nCol - nColsCount);
		}

		if (pnChawWidth)
			*pnChawWidth = m_nSpaceWidth;
	}

	nPosX = m_rcTextRect.left - m_nScrollXOffset + nPosX;

	return nPosX;
}
BOOL CXTPSyntaxEditDrawTextProcessor::ColFromXPos(int nRow, int nX, int& rnCol, BOOL bVirtualSpace)
{
	rnCol = 0;

	CXTPRowInfo* pRI = GetRowInfo(nRow);
	ASSERT(pRI);
	if (!pRI)
		return FALSE;

	int nX2 = nX - m_rcTextRect.left + m_nScrollXOffset;
	if (nX2 < 0)
		return FALSE;

	int nCharsCount = pRI->arCharsEnds.GetDataSize();
	int nPrevCharEnd = 0;

	for (int i = 0; i < nCharsCount; i++)
	{
		int nCharEnd = pRI->arCharsEnds[i];
		if (nX2 >= nPrevCharEnd && nX2 <= nCharEnd)
		{
			int nMiddle = nPrevCharEnd + (nCharEnd - nPrevCharEnd) / 2;
			rnCol = i + ((nX2 < nMiddle) ? 0 : 1);
			return TRUE;
		}
		nPrevCharEnd = nCharEnd;
	}

	rnCol = nCharsCount;

	ASSERT(m_nSpaceWidth);
	ASSERT(nX2 >= nPrevCharEnd);
	int nFreeWidth = nX2 - nPrevCharEnd;

	if (bVirtualSpace)
	{
		rnCol = nCharsCount + nFreeWidth / max(1, m_nSpaceWidth);
	}

	return FALSE;
}
Exemplo n.º 14
0
BOOL CInvertSplit::SplitRow()
{
    CRect rect;

    int TotalSize, MinSize;
    GetRowInfo(0, TotalSize, MinSize);

    TotalSize -=  m_cySplitter;
    int Before = TotalSize*m_nUpSize/(m_nDownSize+m_nUpSize) + m_cyBorder;

    BOOL bRet = CSplitterWnd::SplitRow(Before);

    if ( !bRet ) 
        return FALSE;

    CSmcView* pView = (CSmcView*)GetPane(0, 0 );
    CSmcView* pMainView = (CSmcView*)GetPane(1, 0 );
    CSmcDoc* pDoc = pView->GetDocument();

    pMainView->GetClientRect(&rect);
    int lineCount = rect.Height() / pDoc->m_nYsize;
    // now scroll this lines
    int minpos, maxpos;
    pView->GetScrollRange(SB_VERT, &minpos, &maxpos);
    pView->SetScrollPos(SB_VERT, maxpos - lineCount, TRUE);

    pView->InvalidateRect(NULL, FALSE);
    pView->UpdateWindow();

    // Copy contents of old view to the new view 
    pMainView->m_strList.RemoveAll();
    pMainView->m_strList.AddHead(&pView->m_strList);
    pMainView->m_nCurrentBg  = pView->m_nCurrentBg;
    pMainView->m_nCurrentFg  = pView->m_nCurrentFg;
    pMainView->m_bAnsiBold = pView->m_bAnsiBold;
    pMainView->InvalidateRect(NULL, FALSE);
    pMainView->UpdateWindow();

    return bRet;
}
Exemplo n.º 15
0
void CSizingControlBar::GetRowSizingBars(CSCBArray& arrSCBars, int& nThis)
{
    arrSCBars.RemoveAll();

    int nFirstT, nLastT, nThisT;
    GetRowInfo(nFirstT, nLastT, nThisT);

    nThis = -1;
    for (int i = nFirstT; i <= nLastT; i++)
    {
        CSizingControlBar* pBar = static_cast<CSizingControlBar*> (m_pDockBar->m_arrBars[i]);
        if (HIWORD(pBar) == 0) continue; // placeholder
        if (!pBar->IsVisible()) continue;
        if (pBar->IsKindOf(RUNTIME_CLASS(CSizingControlBar)))
        {
            if (pBar == this)
                nThis = arrSCBars.GetSize();

            arrSCBars.Add(pBar);
        }
    }
}
Exemplo n.º 16
0
void CTabSplitterWnd::SaveSize()
{
#ifdef _DEBUG
	if (m_strSection == szSplitterSection)
		TRACE0("Warning: SetSection has not been called in IMSplitterWnd!\n");
#endif

	GetColumnInfo(0, m_cxCur, m_cxMin);

	if (m_cxCur)
		afxGetApp()->WriteProfileInt(m_strSection, szPaneWidthCurrent, m_cxCur);

	if (m_cxMin)
		afxGetApp()->WriteProfileInt(m_strSection, szPaneWidthMinimum, m_cxMin);

	GetRowInfo(0, m_cyCur, m_cyMin);

	if (m_cyCur)
		afxGetApp()->WriteProfileInt(m_strSection, szPaneHeightCurrent, m_cyCur);
	
	if (m_cyMin)
		afxGetApp()->WriteProfileInt(m_strSection, szPaneHeightMinimum, m_cyMin);
}
int CXTPSyntaxEditDrawTextProcessor::StrPosToDispPos(int nRow, int nStrPos, BOOL bVirtualSpace)
{
	CXTPRowInfo* pRowI = GetRowInfo(nRow);
	ASSERT(pRowI);
	if (!pRowI)
		return 0;

	ASSERT(nStrPos >= 0);
	if (nStrPos < 0)
		return 0;

	int nCount = pRowI->arStrPos2DispCol.GetDataSize();
	if (nStrPos >= nCount)
	{
		int nDispPos = nCount > 0 ? pRowI->arStrPos2DispCol[nCount - 1] + 1 : 0;
		if (bVirtualSpace)
		{
			nDispPos += nStrPos - nCount + 1;
		}
		return nDispPos;
	}

	return pRowI->arStrPos2DispCol[nStrPos];
}
Exemplo n.º 18
0
// 消息响应
LRESULT CDuiGridCtrl::OnMessage(UINT uID, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	if(((uID == SCROLL_V) || (uID == SCROLL_H)) && (Msg == MSG_SCROLL_CHANGE))
	{
		// 如果是滚动条的位置变更事件,则刷新显示
		UpdateControl(true);
	}else
	if((uID == GetID()) && (Msg == MSG_BUTTON_DOWN) && (lParam != -1))
	{
		// 点击了行的某个链接
		GridRowInfo* pRowInfo = GetRowInfo(wParam);
		if(pRowInfo && (lParam >= 0) && (lParam < (int)pRowInfo->vecItemInfo.size()))
		{
			GridItemInfo &itemInfo = pRowInfo->vecItemInfo.at(lParam);
			// 转换为MSG_BUTTON_UP消息,因为DuiSystem任务处理时候只处理MSG_BUTTON_UP消息
			if(!itemInfo.strLinkAction.IsEmpty())
			{
				DuiSystem::AddDuiActionTask(uID, MSG_BUTTON_UP, wParam, lParam, GetName(), itemInfo.strLinkAction, GetParent());
			}
		}
	}

	return __super::OnMessage(uID, Msg, wParam, lParam); 
}
Exemplo n.º 19
0
BOOL CSizingControlBar::NegociateSpace(int nLengthAvail, BOOL bHorz)
{
    ASSERT(bHorz == IsHorzDocked());

    int nFirst, nLast, nThis;
    GetRowInfo(nFirst, nLast, nThis);

    // step 1: subtract the visible fixed bars' lengths
    for (int i = nFirst; i <= nLast; i++)
    {
        CControlBar* pFBar = (CControlBar*)m_pDockBar->m_arrBars[i];
        if (HIWORD(pFBar) == 0) continue; // placeholder
        if (!pFBar->IsVisible() || (FindSizingBar(pFBar) >= 0)) continue;

        CRect rcBar;
        pFBar->GetWindowRect(&rcBar);

        nLengthAvail -= (bHorz ? rcBar.Width() - 2 : rcBar.Height() - 2);
    }

    CSCBArray arrSCBars;
    GetRowSizingBars(arrSCBars);
    CSizingControlBar* pBar;

    // step 2: compute actual and min lengths; also the common width
    int nActualLength = 0;
    int nMinLength = 2;
    int nWidth = 0;
    for (i = 0; i < arrSCBars.GetSize(); i++)
    {
        pBar = arrSCBars[i];
        nActualLength += bHorz ? pBar->m_szHorz.cx - 2 :
            pBar->m_szVert.cy - 2;
        nMinLength += bHorz ? pBar->m_szMin.cx - 2:
            pBar->m_szMin.cy - 2;
        nWidth = max(nWidth, bHorz ? pBar->m_szHorz.cy :
            pBar->m_szVert.cx);
    }
    
    // step 3: pop the bar out of the row if not enough room
    if (nMinLength > nLengthAvail)
    {
        if (nFirst < nThis || nThis < nLast)
        {   // not enough room - create a new row
            m_pDockBar->m_arrBars.InsertAt(nLast + 1, this);
            m_pDockBar->m_arrBars.InsertAt(nLast + 1, (CControlBar*) NULL);
            m_pDockBar->m_arrBars.RemoveAt(nThis);
        }
        return FALSE;
    }

    // step 4: make the bars same width
    for (i = 0; i < arrSCBars.GetSize(); i++)
        if (bHorz)
            arrSCBars[i]->m_szHorz.cy = nWidth;
        else
            arrSCBars[i]->m_szVert.cx = nWidth;

    if (nActualLength == nLengthAvail)
        return TRUE; // no change

    // step 5: distribute the difference between the bars, but
    //         don't shrink them below minsize
    int nDelta = nLengthAvail - nActualLength;

    while (nDelta != 0)
    {
        int nDeltaOld = nDelta;
        for (i = 0; i < arrSCBars.GetSize(); i++)
        {
            pBar = arrSCBars[i];
            int nLMin = bHorz ? pBar->m_szMin.cx : pBar->m_szMin.cy;
            int nL = bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy;
            
            if ((nL == nLMin) && (nDelta < 0) || // already at min length
                pBar->m_bKeepSize) // or wants to keep its size
                continue;
            
            // sign of nDelta
            int nDelta2 = (nDelta == 0) ? 0 : ((nDelta < 0) ? -1 : 1);

            (bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy) += nDelta2;
            nDelta -= nDelta2;
            if (nDelta == 0) break;
        }
        // clear m_bKeepSize flags
        if ((nDeltaOld == nDelta) || (nDelta == 0))
            for (i = 0; i < arrSCBars.GetSize(); i++)
                arrSCBars[i]->m_bKeepSize = FALSE;
    }

    return TRUE;
}
Exemplo n.º 20
0
BOOL CSizingControlBar::NegotiateSpace(int nLengthTotal, BOOL bHorz)
{
    ASSERT(bHorz == IsHorzDocked());

    int nFirst, nLast, nThis;
    GetRowInfo(nFirst, nLast, nThis);

    int nLengthAvail = nLengthTotal;
    int nLengthActual = 0;
    int nLengthMin = 2;
    int nWidthMax = 0;
    CSizingControlBar* pBar;

    for (int i = nFirst; i <= nLast; i++)
    {
        pBar = (CSizingControlBar*) m_pDockBar->m_arrBars[i];
        if (HIWORD(pBar) == 0) continue; // placeholder
        if (!pBar->IsVisible()) continue;
        BOOL bIsSizingBar = 
            pBar->IsKindOf(RUNTIME_CLASS(CSizingControlBar));

        int nLengthBar; // minimum length of the bar
        if (bIsSizingBar)
            nLengthBar = bHorz ? pBar->m_szMinHorz.cx - 2 :
                pBar->m_szMinVert.cy - 2;
        else
        {
            CRect rcBar;
            pBar->GetWindowRect(&rcBar);
            nLengthBar = bHorz ? rcBar.Width() - 2 : rcBar.Height() - 2;
        }

        nLengthMin += nLengthBar;
        if (nLengthMin > nLengthTotal)
        {
            // split the row after fixed bar
            if (i < nThis)
            {
                m_pDockBar->m_arrBars.InsertAt(i + 1,
                    (CControlBar*) NULL);
                return FALSE;
            }
            
            // only this sizebar remains on the row, adjust it to minsize
            if (i == nThis)
            {
                if (bHorz)
                    m_szHorz.cx = m_szMinHorz.cx;
                else
                    m_szVert.cy = m_szMinVert.cy;

                return TRUE; // the dockbar will split the row for us
            }

            // we have enough bars - go negotiate with them
            m_pDockBar->m_arrBars.InsertAt(i, (CControlBar*) NULL);
            nLast = i - 1;
            break;
        }

        if (bIsSizingBar)
        {
            nLengthActual += bHorz ? pBar->m_szHorz.cx - 2 : 
                pBar->m_szVert.cy - 2;
            nWidthMax = max(nWidthMax, bHorz ? pBar->m_szHorz.cy :
                pBar->m_szVert.cx);
        }
        else
            nLengthAvail -= nLengthBar;
    }

    CSCBArray arrSCBars;
    GetRowSizingBars(arrSCBars);
    int nNumBars = (int)arrSCBars.GetSize();
    int nDelta = nLengthAvail - nLengthActual;

    // return faster when there is only one sizing bar per row (this one)
    if (nNumBars == 1)
    {
        ASSERT(arrSCBars[0] == this);

        if (nDelta == 0)
            return TRUE;
        
        m_bKeepSize = FALSE;
        (bHorz ? m_szHorz.cx : m_szVert.cy) += nDelta;

        return TRUE;
    }

    // make all the bars the same width
    for (i = 0; i < nNumBars; i++)
        if (bHorz)
            arrSCBars[i]->m_szHorz.cy = nWidthMax;
        else
            arrSCBars[i]->m_szVert.cx = nWidthMax;

    // distribute the difference between the bars,
    // but don't shrink them below their minsizes
    while (nDelta != 0)
    {
        int nDeltaOld = nDelta;
        for (i = 0; i < nNumBars; i++)
        {
            pBar = arrSCBars[i];
            int nLMin = bHorz ?
                pBar->m_szMinHorz.cx : pBar->m_szMinVert.cy;
            int nL = bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy;

            if ((nL == nLMin) && (nDelta < 0) || // already at min length
                pBar->m_bKeepSize) // or wants to keep its size
                continue;

            // sign of nDelta
            int nDelta2 = (nDelta == 0) ? 0 : ((nDelta < 0) ? -1 : 1);

            (bHorz ? pBar->m_szHorz.cx : pBar->m_szVert.cy) += nDelta2;
            nDelta -= nDelta2;
            if (nDelta == 0) break;
        }
        // clear m_bKeepSize flags
        if ((nDeltaOld == nDelta) || (nDelta == 0))
            for (i = 0; i < nNumBars; i++)
                arrSCBars[i]->m_bKeepSize = FALSE;
    }

    return TRUE;
}
int CXTPSyntaxEditDrawTextProcessor::DrawRowPart(CDC* pDC, int nRow, LPCTSTR pcszText, int nchCount)
{
	if (m_nDrawingRow != nRow)
	{
		if (nRow >= 0) // the new row started
			ResetRowInfo(nRow);

		m_nDrawingRow = nRow;
		m_nNextRowPosX = 0;
	}

	if (nRow == -1)
		return 0;


	//--------------------------------------------------------
	int nTextLen = 0;

	if (nchCount < 0)
	{
		nchCount = (int) _tcsclen(pcszText);
		nTextLen = (int) _tcslen(pcszText);
	}
	else
	{
#ifdef XTP_FIXED
// "nchCount" meen byte length.
// so, need not translate form TextLength to ByteLength.
		nTextLen = nchCount;
#else
		nTextLen = (int) _tcsnbcnt(pcszText, nchCount);
#endif
	}
//  ASSERT(nchCount <= (int) _tcsclen(pcszText));

	//--------------------------------------------------------
	int nY = m_rcTextRect.top + nRow * m_nRowHeight;
	int nX = m_rcTextRect.left - m_nScrollXOffset + m_nNextRowPosX;

	CRect rcText = m_rcTextRect;
	rcText.left = max(rcText.left, nX); // ENSURE THE TEXT IS CLIPPED APPROPRIATELY
	pDC->ExtTextOut(nX, nY, ETO_CLIPPED, &rcText, pcszText, nTextLen, NULL);

	//--------------------------------------------------------
	if (m_arBuf_aDx.GetSize() < nTextLen)
		m_arBuf_aDx.SetSize(nTextLen + 100);

	int nMaxExtent = m_rcTextRect.Width() + m_nScrollXOffset - m_nNextRowPosX + 30; // 30 is a gap to be sure
	nMaxExtent = max(nMaxExtent, 30);

	int nFit = 0;
	LPINT alpDx = (int*)m_arBuf_aDx.GetData();
	CSize szText(0, 0);

	BOOL bResExt = GetTextExtentExPoint(pDC->m_hAttribDC, pcszText, nTextLen,
										0,      // nMaxExtent,
										NULL,   // &nFit,
										alpDx,  // array of partial string widths
										&szText // string dimensions
									);
	nFit = nTextLen;

	VERIFY(bResExt);

	CXTPRowInfo* pRI = GetRowInfo(nRow);
	if (pRI)
	{
		if (nFit >= 0 && nFit <= nTextLen)
		{
			int i;

			LPCTSTR p = pcszText;
			LPCTSTR p_prev = pcszText;
			for (i = 0; i < nFit; i++)
			{
				pRI->arCharsEnds.AddData(m_nNextRowPosX + alpDx[i]);

				p_prev = p;
				p = _tcsinc(p);
				int nCharLen = int(p - p_prev);
#ifdef XTP_FIXED
				if (nCharLen > 1)
					pRI->arCharsEnds.AddData(m_nNextRowPosX + alpDx[i]);
				// ASSERT( nCharLen > 2 );
#endif
				i += nCharLen - 1; // skip second byte for MBCS chars.
			}
		}
		else
		{
			ASSERT(FALSE);
		}

		pRI->nMaxWidth += szText.cx;
	}

	m_nNextRowPosX += szText.cx;

	return m_nNextRowPosX;
}
int CXTPSyntaxEditDrawTextProcessor::PrintRowPart(CDC* pDC, int nRow, int nPosY, UINT nFlags,
												  LPCTSTR pcszText, int nchCount, int *pnPrintedTextLen)
{
	if (pnPrintedTextLen)
		*pnPrintedTextLen = 0;

	if (m_nPrintingRow != nRow)
	{
		m_nPrintingRow = nRow;
		m_ptNextPrintPos = CPoint(0, 0);
	}

	if (nRow == -1)
		return 0;

	//--------------------------------------------------------
	int nTextLen = 0;

	if (nchCount < 0)
	{
		nchCount = (int)_tcsclen(pcszText);
		nTextLen = (int)_tcslen(pcszText);
	}
	else
	{
		nTextLen = (int)_tcsnbcnt(pcszText, nchCount);
	}
	ASSERT(nchCount <= (int)_tcsclen(pcszText));

	//--------------------------------------------------------
	if (m_arBuf_aDx.GetSize() < nTextLen)
		m_arBuf_aDx.SetSize(nTextLen + 100);

	LPINT alpDx = (int*)m_arBuf_aDx.GetData();

	//--------------------------------------------------------
	CRect rcText = m_rcTextRect;
	int nTextLen_rest = nTextLen;
	LPCTSTR pTxt = NULL;

	for (pTxt = pcszText; nTextLen_rest;)
	{
		int nY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y;
		int nX = m_rcTextRect.left + m_ptNextPrintPos.x;

		if (nY + GetRowHeight() > m_rcTextRect.bottom)
			break;

		//--------------------------------------------------------
		int nMaxExtent = max(0, rcText.right - nX - 20);
		int nFit = 0;

		CSize szText(0, 0);

		BOOL bResExt = GetTextExtentExPoint(
						m_bUseOutputDC ? pDC->m_hDC : pDC->m_hAttribDC,  // HDC hdc, // handle to DC
						pTxt,               // LPCTSTR lpString,         // character string
						nTextLen_rest,      // int nCount,               // number of characters
						nMaxExtent,         // maximum extent for string
						&nFit,              // LPINT lpnFit,    // maximum number of characters
						alpDx,     // array of partial string widths
						&szText //LPSIZE lpSize    // string dimensions
					);
		VERIFY(bResExt);

		//nFit = min(nFit, nTextLen_rest);

		LPCTSTR pTextToDtaw = pTxt;
		BOOL bAllTextDrawn = (nFit == nTextLen_rest);

		if (nFit > 0 && nFit <= nTextLen_rest)
		{
			CString strSeps = _T(" .,!?)-+=;\\"); //_T(" .,!?)-+=*&^%$#@~`:;\\|/");
			int nFit_wb = 0;
			int nTextLen_wb = nTextLen_rest;
			LPCTSTR pTxt_wb = pTxt;

			LPCTSTR p_prev = NULL;
			int i = 0;
			for (i = 0; i < nFit; i++)
			{
				p_prev = pTxt;
				pTxt = _tcsinc(pTxt);
				int nCharLen = int(pTxt - p_prev);
				i += nCharLen - 1; // skip second byte for MBCS chars.

				nTextLen_rest--;

				if ((nFlags & DT_WORDBREAK) && strSeps.Find(*p_prev, 0) >= 0)
				{
					nFit_wb = i+1;
					nTextLen_wb = nTextLen_rest;
					pTxt_wb = pTxt;
				}
			}

			if (!bAllTextDrawn && (nFlags & DT_WORDBREAK))
			{
				if (nFit_wb >= 0)
				{
					nFit = nFit_wb;
					nTextLen_rest = nTextLen_wb;
					pTxt = pTxt_wb;
				}
			}

			if (nFit)
			{
				m_ptNextPrintPos.x += alpDx[nFit - 1] + 1;
			}
		}

		// Draw text (if need)
		if (nFit && (nFlags & DT_CALCRECT) == 0)
		{
			rcText.left = max(rcText.left, nX); // ENSURE THE TEXT IS CLIPPED APPROPRIATELY
			pDC->ExtTextOut(nX, nY, ETO_CLIPPED, &rcText, pTextToDtaw, nFit, NULL);
		}

		CXTPRowInfo* pRI = GetRowInfo(nRow);
		if (pRI)
			pRI->nMaxWidth = m_ptNextPrintPos.x;

		// Move point to the next line (if need)
		if (!bAllTextDrawn && (nFlags & DT_SINGLELINE) == 0)
		{
			int nIconX = m_rcTextRect.left + m_ptNextPrintPos.x + 3;
			int nIconY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y;

			int nDelta = GetRowHeight() - GetRowHeight()/4;

			CPen pen1(PS_SOLID, 1, RGB(0,0,0));
			CPen pen2(PS_SOLID, 2, RGB(0,0,0));

			CPen* pPen_old = pDC->SelectObject(&pen1);

			pDC->MoveTo(nIconX, nIconY + nDelta/2);
			pDC->LineTo(nIconX, nIconY + nDelta);
			pDC->LineTo(nIconX + nDelta/2 - 1, nIconY + nDelta);

			pDC->SelectObject(&pen2);
			pDC->MoveTo(nIconX + 1, nIconY + nDelta - 1);
			pDC->LineTo(nIconX + nDelta/2, nIconY + nDelta/2);

			pDC->SelectObject(pPen_old);

			int nSublineOffsetX = m_tmText.tmAveCharWidth * 3;
			m_ptNextPrintPos.y += GetRowHeight();
			m_ptNextPrintPos.x = nSublineOffsetX;

			if (pRI)
				pRI->nMaxWidth = m_ptNextPrintPos.x;
		}
		else
		{
			break;
		}
	}

	if (pnPrintedTextLen)
	{
		int nLen0 = int(pTxt - pcszText);
		*pnPrintedTextLen = (int)_tcsnccnt(pcszText, nLen0);
	}

	return m_ptNextPrintPos.y + GetRowHeight();
}