From: Leon W. <moo...@us...> - 2004-10-28 13:43:54
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13149 Modified Files: OutputEdit.cpp OutputEdit.h Log Message: Added automatic showing/hiding of the scrollbars. Index: OutputEdit.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/OutputEdit.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OutputEdit.cpp 6 Oct 2004 20:40:34 -0000 1.4 --- OutputEdit.cpp 28 Oct 2004 13:43:28 -0000 1.5 *************** *** 149,152 **** --- 149,153 ---- ON_COMMAND(ID_OUTPUT_ERROR, OnOutputError) ON_COMMAND(ID_OUTPUT_SAVE, OnOutputSave) + ON_CONTROL_REFLECT(EN_CHANGE, OnChange) //}}AFX_MSG_MAP END_MESSAGE_MAP() *************** *** 159,162 **** --- 160,166 ---- //CPaintDC dc(this); // device context for painting Default(); + + SetAutoScrollBars(); + if (m_bCanPaint) DrawLine(TRUE); *************** *** 381,382 **** --- 385,430 ---- return CEdit::PreTranslateMessage(pMsg); } + + void COutputEdit::OnChange() + { + SetAutoScrollBars(); + } + + void COutputEdit::SetAutoScrollBars() + { + // How about some automatic ScrollBars + + // First determine the longest line. + int iLine = 0; + for( int i = 0; i < GetLineCount(); ++ i ) + { + if( LineLength( LineIndex( iLine ) ) < LineLength( LineIndex( i ) ) ) + { + iLine = i; + } + } + + // Get the text of the longest line. + CString szText; + GetLine( iLine, szText.GetBuffer( LineLength( LineIndex( iLine ) ) ), LineLength( LineIndex( iLine ) ) ); + szText.ReleaseBuffer(); + + // Get the size of the client window + CRect rcClient; + GetClientRect( rcClient ); + + // Get the size of the line + CFont* pFont = GetFont(); + CClientDC dc(this); + dc.SelectObject(pFont); + CSize sizeText = dc.GetTextExtent( szText ); + + // Enable/Disable the scrollbars. + if( sizeText.cx > rcClient.Width() ) ShowScrollBar( SB_HORZ, TRUE ); + else ShowScrollBar( SB_HORZ, FALSE ); + + if( sizeText.cy * GetLineCount() > rcClient.Height() ) ShowScrollBar( SB_VERT, TRUE ); + else ShowScrollBar( SB_VERT, FALSE ); + + // End of automatic ScrollBar code. + } Index: OutputEdit.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/OutputEdit.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OutputEdit.h 6 Oct 2004 20:40:34 -0000 1.3 --- OutputEdit.h 28 Oct 2004 13:43:28 -0000 1.4 *************** *** 49,52 **** --- 49,53 ---- afx_msg void OnOutputError(); afx_msg void OnOutputSave(); + afx_msg void OnChange(); //}}AFX_MSG protected: *************** *** 64,67 **** --- 65,69 ---- int GetCurLine(); BOOL CanParseLine(); + void SetAutoScrollBars(); public: |