[Wgui-cvs] wgui/src wg_textbox.cpp,1.18,1.19
Status: Beta
Brought to you by:
greenwire
|
From: Rob W. <gre...@us...> - 2004-05-05 14:53:16
|
Update of /cvsroot/wgui/wgui/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv770/src Modified Files: wg_textbox.cpp Log Message: Fixed CTextBox highlighting bug. Index: wg_textbox.cpp =================================================================== RCS file: /cvsroot/wgui/wgui/src/wg_textbox.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** wg_textbox.cpp 27 Apr 2004 18:13:51 -0000 1.18 --- wg_textbox.cpp 5 May 2004 14:52:35 -0000 1.19 *************** *** 94,101 **** delete m_pCursorTimer; delete m_pDblClickTimer; - - // This shouldn't be necessary, as these are children of the control and should be deleted automatically - // delete m_pHorizontalScrollBar; - // delete m_pVerticalScrollBar; } --- 94,97 ---- *************** *** 111,114 **** --- 107,111 ---- std::string CTextBox::GetSelText(void) const // virtual { + std::string sSelText = ""; if (m_SelLength != 0) { *************** *** 123,132 **** SelStartNorm = m_SelStart; } ! return m_sWindowText.substr(SelStartNorm, SelLenNorm); ! } ! else ! { ! return ""; } } --- 120,127 ---- SelStartNorm = m_SelStart; } ! sSelText = m_sWindowText.substr(SelStartNorm, SelLenNorm); } + + return sSelText; } *************** *** 169,172 **** --- 164,168 ---- if (CApplication::Instance()->GetKeyFocus() == dynamic_cast<const CWindow*>(this) && !m_bReadOnly) { + // first normalize the selection std::string::size_type SelStartNorm = 0; std::string::size_type SelLenNorm = abs(m_SelLength); *************** *** 182,185 **** --- 178,182 ---- CPoint SelEndPoint(RowColFromIndex(SelStartNorm + SelLenNorm)); + // now get the dimensions for each character std::vector<CPoint> vOffsets; std::vector<CPoint> vBoundingDimensions; *************** *** 222,226 **** } ! // Selection if (m_SelLength != 0 && SelEndPoint.YPos() >= m_pVerticalScrollBar->GetValue()) { --- 219,223 ---- } ! // draw the selection if (m_SelLength != 0 && SelEndPoint.YPos() >= m_pVerticalScrollBar->GetValue()) { *************** *** 242,248 **** } if (m_SelLength == 0 && SelStartPoint.YPos() >= m_pVerticalScrollBar->GetValue() && m_bDrawCursor) { - //RenderStringWithCursor if (CursorPos >= TextRect.Left() && CursorPos <= TextRect.Right()) { --- 239,245 ---- } + // draw the cursor if (m_SelLength == 0 && SelStartPoint.YPos() >= m_pVerticalScrollBar->GetValue() && m_bDrawCursor) { if (CursorPos >= TextRect.Left() && CursorPos <= TextRect.Right()) { *************** *** 253,256 **** --- 250,254 ---- } + // finally, draw the text CPoint LineOrigin = TextRect.TopLeft() - CPoint(m_pHorizontalScrollBar->GetValue() * 10, 0); for(std::vector<CRenderedString*>::const_iterator iter = m_vpRenderedString.begin() + m_pVerticalScrollBar->GetValue(); *************** *** 291,295 **** { bool fSkipCursorPositioning = false; ! //If we haven't initialized the double click timer, do so. if (!m_pDblClickTimer->IsRunning()) { --- 289,293 ---- { bool fSkipCursorPositioning = false; ! // If we haven't initialized the double click timer, do so. if (!m_pDblClickTimer->IsRunning()) { *************** *** 298,303 **** else { ! //Raise double click event ! //This message is being dispatched, but to where? CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_DOUBLELCLICK, this, this, 0)); fSkipCursorPositioning = true; --- 296,300 ---- else { ! // Raise double click event CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_DOUBLELCLICK, this, this, 0)); fSkipCursorPositioning = true; *************** *** 311,317 **** --- 308,316 ---- if (!fSkipCursorPositioning) { + // set the cursor std::vector<CPoint> vOffsets; std::vector<std::vector<CRect> > vCharRects; int iIndex = 0; + // get the dimensions of all the characters for (std::vector<CRenderedString*>::iterator iter = m_vpRenderedString.begin(); iter != m_vpRenderedString.end(); ++iter, ++iIndex) { *************** *** 323,332 **** } CRect TextRect(GetClientRect()); unsigned int iCurLine = (Point.YPos() - TextRect.Top()) / m_iRowHeight + m_pVerticalScrollBar->GetValue(); ! if (iCurLine > m_iLineCount) { iCurLine = m_iLineCount - 1; } int xDelta = abs(Point.XPos() - (vCharRects[iCurLine][0].Left() + vOffsets[iCurLine].XPos() + TextRect.Left())); m_SelStart = 0; --- 322,333 ---- } + // figure out which line was clicked on CRect TextRect(GetClientRect()); unsigned int iCurLine = (Point.YPos() - TextRect.Top()) / m_iRowHeight + m_pVerticalScrollBar->GetValue(); ! if (iCurLine >= m_iLineCount) { iCurLine = m_iLineCount - 1; } + // figure out which character was clicked on int xDelta = abs(Point.XPos() - (vCharRects[iCurLine][0].Left() + vOffsets[iCurLine].XPos() + TextRect.Left())); m_SelStart = 0; *************** *** 413,416 **** --- 414,418 ---- if (m_bMouseDown) { + // get the dimensions for all the characters std::vector<CPoint> vOffsets; std::vector<std::vector<CRect> > vCharRects; *************** *** 425,432 **** --- 427,439 ---- } + // figure out which line was clicked on unsigned int iCurLine = 0; if (GetClientRect().HitTest(pMouseMessage->Point) == CRect::RELPOS_INSIDE) { iCurLine = (pMouseMessage->Point.YPos() - TextRect.Top()) / m_iRowHeight + m_pVerticalScrollBar->GetValue(); + if (iCurLine >= m_iLineCount) + { + iCurLine = m_iLineCount - 1; + } } else if (GetClientRect().HitTest(pMouseMessage->Point) == CRect::RELPOS_BELOW) *************** *** 434,437 **** --- 441,446 ---- iCurLine = m_iLineCount - 1; } + + // figure out which character was clicked on int xDelta = abs(pMouseMessage->Point.XPos() - (vCharRects[iCurLine][0].Left() + vOffsets[iCurLine].XPos() + TextRect.Left())); std::string::size_type CursorPos = 0; *************** *** 449,452 **** --- 458,462 ---- } + // set the highlighting if (CursorPos < m_DragStart) { |