1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
40 //M*/// LogView.cpp : implementation file
50 static char THIS_FILE[] = __FILE__;
54 /////////////////////////////////////////////////////////////////////////////
57 IMPLEMENT_DYNCREATE(CLogView, CEditView)
59 CLogView::CLogView() : m_edit(GetEditCtrl()), m_logLength(30000)
68 BEGIN_MESSAGE_MAP(CLogView, CEditView)
69 //{{AFX_MSG_MAP(CLogView)
71 ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
75 /////////////////////////////////////////////////////////////////////////////
78 void CLogView::OnDraw(CDC* pDC)
80 CDocument* pDoc = GetDocument();
81 // TODO: add draw code here
84 /////////////////////////////////////////////////////////////////////////////
85 // CLogView diagnostics
88 void CLogView::AssertValid() const
93 void CLogView::Dump(CDumpContext& dc) const
99 /////////////////////////////////////////////////////////////////////////////
100 // CLogView message handlers
102 int CLogView::OnCreate(LPCREATESTRUCT lpCreateStruct)
104 if (CView::OnCreate(lpCreateStruct) == -1)
107 m_edit.SetReadOnly();
111 int CLogView::AddLine(LPCTSTR strings)
115 strcpy(newstring, "\r\n");
116 if (strlen(strings)<252)
117 strcat(newstring, strings);
119 strncat(newstring, strings, 252);
122 int end = m_length;//m_edit.GetWindowTextLength();
123 if(end + (int)strlen(strings) > m_logLength)
125 /* Delete the beginning to free the space */
126 m_edit.SetSel(0, end + strlen(strings) - m_logLength);
127 m_edit.ReplaceSel("");
131 m_edit.SetWindowText(strings);
135 int number_lines = m_edit.GetLineCount();
136 int start = m_edit.LineIndex(number_lines-1);
138 int len = m_edit.LineLength(end);
140 m_edit.SetSel(end, end+1);
141 m_edit.ReplaceSel(strings);
144 m_edit.SetSel(end, end+1);
145 m_edit.ReplaceSel(newstring);
151 void CLogView::AddString(LPCTSTR _text)
153 char* text = _strdup(_text);
154 int index = 0, i = 0;
155 // int length = m_edit.GetWindowTextLength();
156 int length = m_length;
157 int l = strlen(text);
158 char* buffer = new char[strlen(text) + 2];
163 while(text[i] != 0 && text[i] != 10 && text[i] != 13) i++;
166 length = ClearHead(strlen(&text[index]));
167 m_edit.SetSel(length, length + 1);
168 m_edit.ReplaceSel(&text[index]);
174 if(text[i + 1] == 13)
180 length = ClearHead(strlen(&text[index]));
181 m_edit.SetSel(length, length + 1);
182 m_edit.ReplaceSel(&text[index]);
190 memcpy(buffer, &text[index], i - index);
191 buffer[i - index] = 13;
192 buffer[i - index + 1] = 10;
193 buffer[i - index + 2] = 0;
194 length = ClearHead(strlen(buffer));;
195 m_edit.SetSel(length, length + 1);
196 m_edit.ReplaceSel(buffer);
205 if(text[i + 1] == 10)
211 memcpy(buffer, &text[index], i - index);
212 buffer[i - index] = 13;
213 buffer[i - index + 1] = 10;
214 buffer[i - index + 2] = 0;
216 length = ClearHead(strlen(buffer));
217 m_edit.SetSel(length, length + 1);
218 m_edit.ReplaceSel(buffer);
230 int CLogView::ClearHead(int textLength)
232 int length = m_length;//m_edit.GetWindowTextLength();
233 if(length + textLength > m_logLength)
235 /* Delete the beginning to free the space */
236 m_edit.SetSel(0, length + textLength - m_logLength);
237 // m_edit.SetSel(0, -1);
238 m_edit.ReplaceSel("");
241 return m_length;//m_edit.GetWindowTextLength();
244 void CLogView::OnChange()
246 m_length = m_edit.GetWindowTextLength();