JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
LogWndView.cpp
Go to the documentation of this file.
1//
2// LogWndView.cpp : CLogWndView クラスの実装
3//
4
5#include "MFCBase.h"
6#include "LogWndFrame.h"
7#include "LogWndView.h"
8
9
10#ifdef _DEBUG
11#define new DEBUG_NEW
12#endif
13
14
15using namespace jbxl;
16using namespace jbxwl;
17
18
19IMPLEMENT_DYNCREATE(CLogWndView, CExTextView)
20
21
23{
24 //DEBUG_INFO("コンストラクタ:IN CLogWndView\n");
25
26 pFrame = NULL;
27 pDoc = NULL;
28 Title = _T("");
29
30 m_FontSizeX = 0;
31 m_FontSizeY = 0;
32 m_DocLastPos = 0;
33
34 m_msx = m_msy = 0;
35 m_mex = m_mey = 0;
36 m_mpress = FALSE;
37 m_dragsx = 0;
38 m_dragsy = 0;
39 m_dragex = 0;
40 m_dragey = 0;
41
42 m_copysy = -1;
43 m_copyey = -1;
44 m_locked = FALSE;
45
46 KanjiCode = CODE_SJIS;
47
48 //DEBUG_INFO("コンストラクタ:OUT CLogWndView\n");
49}
50
51
53{
54 DEBUG_INFO("DESTRUCTOR: CLogWndView: START\n");
55
56 while(m_locked) ::Sleep(10);
57
58 DEBUG_INFO("DESTRUCTOR: CLogWndView: END\n");
59}
60
61
62BEGIN_MESSAGE_MAP(CLogWndView, CExTextView)
63 ON_WM_CREATE()
64 ON_WM_DESTROY()
65 ON_WM_LBUTTONDOWN()
66 ON_WM_LBUTTONUP()
67 ON_WM_MOUSEMOVE()
68 ON_WM_ERASEBKGND()
69 ON_WM_SIZE()
70END_MESSAGE_MAP()
71
72
73BOOL CLogWndView::PreCreateWindow(CREATESTRUCT& cs)
74{
75 CSize sizeTotal(100, 100);
76 CSize sizeLine(m_FontSizeX, m_FontSizeY);
77 CSize sizePage(m_FontSizeX, m_FontSizeY*LINES_PER_PAGE);
78 SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
79
80 BOOL ret = CScrollView::PreCreateWindow(cs);
81 return ret;
82}
83
84
85//
87{
88 return CExTextView::OnEraseBkgnd(pDC);
89}
90
91
92void CLogWndView::OnSize(UINT nType, int cx, int cy)
93{
94 CExTextView::OnSize(nType, cx, cy);
95}
96
97
98void CLogWndView::OnDraw(CDC* pDC)
99{
100 if (pDoc==NULL) pDoc = GetDocument();
101 if (!pDoc || pDoc->ringBuffer==NULL) return;
102
103 CLogRingBuffer* pRB = pDoc->ringBuffer;
104 if (pRB->getMaxLineY()==0) return;
105
106 CSingleLock lock(&(pDoc->criticalKey));
107 lock.Lock();
108 while (!lock.IsLocked()) {
109 Sleep(100);
110 lock.Lock();
111 }
112
114
115 CFont* pOldFontX = pDC->SelectObject(&m_ScreenFont);
116 CRect rc;
117 pDC->GetClipBox(&rc);
118
119 int nLineBegin = rc.top/m_FontSizeY;
120 int nLineEnd = min((rc.bottom+m_FontSizeY-1)/m_FontSizeY, pRB->getMaxLineY());
121
122 for (int i=nLineBegin; i<nLineEnd; i++) {
123 Buffer buf = pRB->getRingBuffer(i);
124 if (buf.buf==NULL) break;
125
126 if (i>=m_copysy && i<=m_copyey) {
127 pDC->SetBkColor(RGB(200,200,200));
128 }
129 else {
130 pDC->SetBkColor(RGB(255,255,255));
131 }
132
133 if (buf.state==LOG_RB_WARNING) {
134 pDC->SetTextColor(RGB(20,20,200));
135 }
136 else if (buf.state==LOG_RB_ERROR) {
137 pDC->SetTextColor(RGB(200,20,20));
138 }
139 else if (buf.state==LOG_RB_DEBUG) {
140 pDC->SetTextColor(RGB(20,150,20));
141 }
142 else if (buf.state==LOG_RB_INFO) {
143 pDC->SetTextColor(RGB(20,150,150));
144 }
145 else {
146 pDC->SetTextColor(RGB(0,0,0));
147 }
148
149 //if (isText_Buffer(buf)) kanji_convert_Buffer(&buf);
150 CString outtext = mbs2ts((char*)buf.buf);
151 pDC->TextOut(DISPLAY_MARGIN, i*m_FontSizeY+DISPLAY_MARGIN, (LPCTSTR)outtext);
152 free_Buffer(&buf);
153 }
154
155 setScrollPosition(pDC, pRB);
156
157 lock.Unlock();
158
159 pDC->SelectObject(pOldFontX);
160}
161
162
163void CLogWndView::setScrollPosition(CDC* pDC, CLogRingBuffer* pRB)
164{
165 int lastPos = pRB->getLastPosition();
166 if (m_DocLastPos==lastPos) return;
167 m_DocLastPos = lastPos;
168
169 CRect rc;
170 GetClientRect(&rc);
171
172 POINT pt;
173 pt.x = 0;
174 pt.y = (lastPos+1)*m_FontSizeY - rc.bottom + rc.top;
175 if (pt.y<0) pt.y = 0;
176
177 ScrollToPosition(pt);
178}
179
180
182{
183 if (pDoc==NULL) pDoc = GetDocument();
184 if (!pDoc || !pDoc->ringBuffer) return;
185 CLogRingBuffer* pRB = pDoc->ringBuffer;
186 if (pRB->getMaxLineY()==0 || pRB->getMaxLineX()==0) return;
187
188 int scrollSizeX = m_FontSizeX*pRB->getMaxLineX() + DISPLAY_MARGIN;
189 int scrollSizeY = m_FontSizeY*pRB->getMaxLineY() + DISPLAY_MARGIN;
190 //if (scrollSizeY>SHRT_MAX) scrollSizeY = SHRT_MAX;
191
192 if (scrollSizeX!=m_ScrollSizeX || scrollSizeY!=m_ScrollSizeY) {
193 m_ScrollSizeX = scrollSizeX;
194 m_ScrollSizeY = scrollSizeY;
195
196 CSize sizeTotal(m_ScrollSizeX, m_ScrollSizeY);
197 CSize sizeLine(m_FontSizeX, m_FontSizeY);
198 CSize sizePage(m_FontSizeX, m_FontSizeY*LINES_PER_PAGE);
199
200 SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
201 }
202
203 return;
204}
205
206
208{
210
211 if (pDoc==NULL) pDoc = GetDocument();
212 if (!pDoc || pDoc->ringBuffer==NULL) return;
213 CLogRingBuffer* pRB = pDoc->ringBuffer;
214
215 CClientDC dc(this);
216 TEXTMETRIC tm;
217 dc.GetTextMetrics(&tm);
218
219 m_FontSizeX = dc.GetTextExtent(CString('0', 1)).cx; // フォントの横サイズ
220 m_FontSizeY = tm.tmHeight + tm.tmExternalLeading; // フォント(含行間)の縦サイズ
221
224 //if (m_ScrollSizeY>SHRT_MAX) m_ScrollSizeY = SHRT_MAX;
225
226 CSize sizeTotal(m_ScrollSizeX+2, m_ScrollSizeY);
227 CSize sizeLine(m_FontSizeX, m_FontSizeY);
228 CSize sizePage(m_FontSizeX, m_FontSizeY*LINES_PER_PAGE);
229
230 SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
231
232 return;
233}
234
235
237{
238 if (pDoc==NULL) pDoc = GetDocument();
239 if (!pDoc || pDoc->ringBuffer==NULL) return;
240 CLogRingBuffer* pRB = pDoc->ringBuffer;
241
242 CSingleLock lock(&(pDoc->criticalKey));
243 lock.Lock();
244 while (!lock.IsLocked()) {
245 Sleep(100);
246 lock.Lock();
247 }
248
251 //if (m_ScrollSizeY>SHRT_MAX) m_ScrollSizeY = SHRT_MAX;
252
253 CSize sizeTotal(m_ScrollSizeX+2, m_ScrollSizeY);
254 CSize sizeLine(m_FontSizeX, m_FontSizeY);
255 CSize sizePage(m_FontSizeX, m_FontSizeY*LINES_PER_PAGE);
256
257 SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
258
259 POINT pt;
260 pt.x = 0;
261 pt.y = 0;
262
263 ScrollToPosition(pt);
264
265 pDoc->clear();
266
267 InvalidateRect(NULL, TRUE);
268
269 lock.Unlock();
270}
271
272
273void CLogWndView::SetTitle(LPCTSTR title)
274{
275 this->Title = title;
276 pFrame->Title = title;
277 pFrame->SetTitle(title); // ルート&カレントウィンドウ
278 pFrame->SetWindowText(title); // カレントウィンドウ
279 pDoc->SetTitle(title); // ?
280
281 return;
282}
283
284
285#ifdef _DEBUG
286
288{
289 CScrollView::AssertValid();
290}
291
292
293//
294void CLogWndView::Dump(CDumpContext& dc) const
295{
296 CScrollView::Dump(dc);
297}
298
299
300//
301CLogWndDoc* CLogWndView::GetDocument() const // デバッグ以外のバージョンはインラインです.
302{
303 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLogWndDoc)));
304 return (CLogWndDoc*)m_pDocument;
305}
306
307
308#endif //_DEBUG
309
310
311
313// CLogWndView メッセージ ハンドラ
314// フォントの設定
315
316int CLogWndView::OnCreate(LPCREATESTRUCT lpcs)
317{
318 if (CScrollView::OnCreate(lpcs)==-1) return -1;
319
320 CString fname, fsize;
321 fname.LoadString(IDS_STR_FONT_GOTHIC); // MS ゴシック
322 fsize.LoadString(IDS_STR_FONT_SIZE); // 120
323 int sz = ttoi(fsize);
324
325 CClientDC dc(this);
326 m_ScreenFont.CreatePointFont(sz, (LPCTSTR)fname, &dc);
327
328 //
330 return 0;
331}
332
333
335{
336 m_ScreenFont.DeleteObject();
337 CScrollView::OnDestroy();
338}
339
340
341
343// Copy (& Paste)
344//
345void CLogWndView::OnLButtonDown(UINT nFlags, CPoint point)
346{
347 CPoint scrlpos = GetScrollPosition();
348 m_msx = point.x + scrlpos.x;
349 m_msy = point.y + scrlpos.y;
350
353 m_mpress = TRUE;
354
355 // Window内をクリック
356 CRect rc;
357 GetClientRect(&rc);
358 if (point.x>=rc.left && point.x<=rc.right && point.y>rc.top && point.y<=rc.bottom) {
359 m_copysy = -1;
360 m_copyey = -1;
361 InvalidateRect(NULL, FALSE);
362 }
363
364 CScrollView::OnLButtonDown(nFlags, point);
365}
366
367
368void CLogWndView::OnLButtonUp(UINT nFlags, CPoint point)
369{
370 m_mpress = FALSE;
371
372 CScrollView::OnLButtonUp(nFlags, point);
373}
374
375
376void CLogWndView::OnMouseMove(UINT nFlags, CPoint point)
377{
378 if (m_mpress) {
379 CPoint scrlpos = GetScrollPosition();
380 m_mex = point.x + scrlpos.x;
381 m_mey = point.y + scrlpos.y;
384
388 InvalidateRect(NULL, FALSE);
389 }
390 }
391
392 CScrollView::OnMouseMove(nFlags, point);
393}
394
395
397{
398 CString ret = _T("");
399
400 if (m_copysy < 0 || m_copysy > m_copyey) return ret;
401
402 CLogWndDoc* pdoc = GetDocument();
403 if (!pdoc || !pdoc->ringBuffer) return ret;
404 CLogRingBuffer* pRB = pdoc->ringBuffer;
405
406 for (int i=m_copysy; i<=m_copyey; i++) {
407 Buffer buf = dup_Buffer(pRB->pBuf[i]);
408 if (pRB->getKindData(i)!=LOG_RB_BINARY_DATA) {
409 if (buf.buf[buf.vldsz-1]!='\n') cat_s2Buffer("\n", &buf);
410 }
411
412 ret = ret + mbs2ts((char*)buf.buf);
413 free_Buffer(&buf);
414 }
415
416 return ret;
417}
418
419
420//
421// CScrollView が 32767pixel を越える場合の対応
422//
423BOOL CLogWndView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
424{
425 SCROLLINFO info;
426 info.cbSize = sizeof(SCROLLINFO);
427 info.fMask = SIF_TRACKPOS;
428
429 if (LOBYTE(nScrollCode)==SB_THUMBTRACK)
430 {
431 GetScrollInfo(SB_HORZ, &info);
432 nPos = info.nTrackPos;
433 }
434
435 if (HIBYTE(nScrollCode)==SB_THUMBTRACK)
436 {
437 GetScrollInfo(SB_VERT, &info);
438 nPos = info.nTrackPos;
439 }
440
441 return CScrollView::OnScroll(nScrollCode, nPos, bDoScroll);
442}
#define LINES_PER_PAGE
Definition LogWndView.h:7
#define DISPLAY_MARGIN
Definition LogWndView.h:6
virtual void OnInitialUpdate()
afx_msg void OnSize(UINT nType, int cx, int cy)
afx_msg BOOL OnEraseBkgnd(CDC *pDC)
CLogRingBuffer * ringBuffer
Definition LogWndDoc.h:72
CCriticalSection criticalKey
Definition LogWndDoc.h:73
afx_msg void OnDestroy(void)
afx_msg void OnDraw(CDC *pDC)
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
virtual void OnInitialUpdate()
BOOL OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
CLogWndDoc * pDoc
Definition LogWndView.h:29
afx_msg void OnSize(UINT nType, int cx, int cy)
CLogWndFrame * pFrame
Definition LogWndView.h:30
void SetTitle(LPCTSTR title)
afx_msg int OnCreate(LPCREATESTRUCT lpcs)
void setScrollPosition(CDC *pDC, CLogRingBuffer *pBR)
CString getCopyData(void)
afx_msg void OnLButtonUp(UINT nFlags, CPoint point)
virtual ~CLogWndView()
CLogWndDoc * GetDocument() const
virtual void AssertValid() const
virtual void Dump(CDumpContext &dc) const
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
void lock(void)
Definition LogWndView.h:35
void clearViewDoc(void)
afx_msg BOOL OnEraseBkgnd(CDC *pDC)
void resetScrollSize(void)
CString mbs2ts(char *str)
Definition WinTools.cpp:79
#define IDS_STR_FONT_GOTHIC
Definition resource.h:122
#define IDS_STR_FONT_SIZE
Definition resource.h:120