forked from apex-hughin/CrimsonEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputWindow.cpp
290 lines (224 loc) · 8.78 KB
/
OutputWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// OutputWindow.cpp : implementation file
//
#include "stdafx.h"
#include "cedtHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
COutputWindow::COutputWindow()
{
memset( m_tbiToolbarOutput, 0x00, sizeof(m_tbiToolbarOutput) );
memset( m_tbiWinButtons, 0x00, sizeof(m_tbiWinButtons) );
m_tbiToolbarOutput[0].iBitmap = 0;
m_tbiToolbarOutput[0].idCommand = ID_DIRECTORY_ITEM_REFRESH;
m_tbiToolbarOutput[0].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[0].fsStyle = TBSTYLE_BUTTON;
m_tbiToolbarOutput[1].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[1].fsStyle = TBSTYLE_SEP;
m_tbiToolbarOutput[2].iBitmap = 1;
m_tbiToolbarOutput[2].idCommand = ID_DIRECTORY_ITEM_COPY;
m_tbiToolbarOutput[2].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[2].fsStyle = TBSTYLE_BUTTON;
m_tbiToolbarOutput[3].iBitmap = 2;
m_tbiToolbarOutput[3].idCommand = ID_DIRECTORY_ITEM_MOVE;
m_tbiToolbarOutput[3].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[3].fsStyle = TBSTYLE_BUTTON;
m_tbiToolbarOutput[4].iBitmap = 3;
m_tbiToolbarOutput[4].idCommand = ID_DIRECTORY_ITEM_DELETE;
m_tbiToolbarOutput[4].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[4].fsStyle = TBSTYLE_BUTTON;
m_tbiToolbarOutput[5].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiToolbarOutput[5].fsStyle = TBSTYLE_SEP;
m_tbiWinButtons[0].iBitmap = 1;
m_tbiWinButtons[0].idCommand = ID_OUTPUT_WINDOW_HIDE;
m_tbiWinButtons[0].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
m_tbiWinButtons[0].fsStyle = TBSTYLE_BUTTON;
}
COutputWindow::~COutputWindow()
{
m_imgToolbarOutput.Detach();
m_imgWinButtons.Detach();
}
BEGIN_MESSAGE_MAP(COutputWindow, CSizingControlBar)
//{{AFX_MSG_MAP(COutputWindow)
ON_WM_CREATE()
ON_WM_SIZE()
ON_LBN_DBLCLK(IDC_OUTPUT, OnDblclkOutput)
ON_WM_CONTEXTMENU()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COutputWindow message handlers
int COutputWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect rect(0, 0, 1, 1); DWORD dwStyle;
if (CSizingControlBar::OnCreate(lpCreateStruct) == -1) return -1;
dwStyle = WS_VISIBLE | WS_CHILD; CString szText( (LPCTSTR)IDS_CTRL_OUTPUT_WINDOW );
m_stcCaptionOutput.Create(szText, dwStyle, rect, this, IDC_OUTPUT_CAPTION);
dwStyle = WS_VISIBLE | WS_CHILD | CCS_NORESIZE | CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS;
m_btnWinButtons.Create(dwStyle, rect, this, IDC_OUTPUT_TOOLBAR);
dwStyle = WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS;
m_lstConsoleOutput.Create(dwStyle, rect, this, IDC_OUTPUT_LIST);
m_lstConsoleOutput.ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);
m_lstConsoleOutput.SetHorizontalExtent(2560);
m_lstConsoleOutput.SetTabStops(32); // dialog based unit (approximately 4 character)
dwStyle = WS_VISIBLE | WS_CHILD;
m_edtConsoleInput.Create(dwStyle, rect, this, IDC_OUTPUT_EDIT);
m_edtConsoleInput.ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);
m_edtConsoleInput.SetReadOnly(TRUE);
// set image list
// m_imgToolbarOutput.Create(IDB_OUTPUT_TOOLBAR, 16, 0, RGB(255, 0, 255));
// m_btnToolbarOutput.SetImageList( & m_imgToolbarOutput );
m_imgWinButtons.Create(IDB_WIN_BUTTONS, 12, 0, RGB(255, 0, 255));
m_btnWinButtons.SetImageList( & m_imgWinButtons );
// set control font
CFont * pFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
LOGFONT lf; pFont->GetLogFont( & lf ); m_fontControl.CreateFontIndirect( & lf );
m_stcCaptionOutput.SetFont( & m_fontControl, FALSE );
// set output font
ApplyOutputFont( FALSE );
// initialize toolbar
// m_btnToolbarOutput.AddButtons( 6, m_tbiToolbarOutput );
m_btnWinButtons.AddButtons( 1, m_tbiWinButtons );
// set occupied flag
m_bOccupied = FALSE;
return 0;
}
void COutputWindow::OnSize(UINT nType, int cx, int cy)
{
CSizingControlBar::OnSize(nType, cx, cy);
INT nBegX = 2, nEndX = cx - 4;
// nBegX = 2; m_btnToolbarOutput.MoveWindow(nBegX, 2, 22, 106);
nBegX += 0; m_stcCaptionOutput.MoveWindow(nBegX, 24, 18, cy-26);
nBegX += 2; m_btnWinButtons.MoveWindow(nBegX, 4, 19, 18);
nBegX += 20; m_lstConsoleOutput.MoveWindow(nBegX, 2, nEndX-nBegX, cy-24);
nBegX += 0; m_edtConsoleInput.MoveWindow(nBegX, cy-22, nEndX-nBegX, 20);
}
void COutputWindow::OnDblclkOutput()
{
INT nSelect = m_lstConsoleOutput.GetCurSel();
if( nSelect == LB_ERR ) return;
CString szString; m_lstConsoleOutput.GetText(nSelect, szString);
if( ! szString.GetLength() ) return;
INT nIndex1 = szString.Find('('); if( nIndex1 < 0 ) return;
INT nIndex2 = szString.Find(')'); if( nIndex2 < 0 ) return;
if( nIndex2 < nIndex1 ) return;
CString szPathName = szString.Left(nIndex1);
if( ! VerifyFilePath(szPathName) ) return;
CString szLineNum = szString.Mid(nIndex1+1, nIndex2-nIndex1-1);
INT nLineNum = atoi(szLineNum); if( ! nLineNum ) return;
CCedtApp * pApp = (CCedtApp *)AfxGetApp(); if( ! pApp ) return;
pApp->PostOpenDocumentFile( szPathName, nLineNum );
}
void COutputWindow::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu * pMenu, context; context.LoadMenu(IDR_OUTPUT_WINDOW);
pMenu = context.GetSubMenu(0);
UINT nFlags = TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
pMenu->TrackPopupMenu(nFlags, point.x, point.y, AfxGetMainWnd());
}
/////////////////////////////////////////////////////////////
// Operations
void COutputWindow::ApplyOutputFont(BOOL bRedraw)
{
if( m_fontOutput.m_hObject ) m_fontOutput.DeleteObject();
LOGFONT lf; memcpy( & lf, & CCedtView::m_lfMiscel[0x01], sizeof(LOGFONT) );
CDC * pDC = m_lstConsoleOutput.GetDC();
lf.lfHeight = -MulDiv( lf.lfHeight, pDC->GetDeviceCaps(LOGPIXELSY), 720 );
m_lstConsoleOutput.ReleaseDC( pDC );
m_fontOutput.CreateFontIndirect( & lf );
m_lstConsoleOutput.SetFont( & m_fontOutput, bRedraw );
m_edtConsoleInput.SetFont( & m_fontOutput, bRedraw );
}
void COutputWindow::EnableInputConsole(BOOL bEnable)
{
m_edtConsoleInput.SetWindowText("");
m_edtConsoleInput.SetReadOnly(!bEnable);
}
void COutputWindow::CopyAllTheContents()
{
CMemText Block; TCHAR szText[2048];
INT nCount = m_lstConsoleOutput.GetCount();
for(INT i = 0; i < nCount; i++) {
m_lstConsoleOutput.GetText(i, szText);
Block.AddTail( szText );
}
CCedtView::SetClipboardData( Block );
}
void COutputWindow::ClearAllTheContents()
{
m_lstConsoleOutput.ResetContent();
}
BOOL COutputWindow::AddStringToTheLast(LPCTSTR lpszString)
{
if( m_lstConsoleOutput.GetCount() >= OUTPUT_MAX_LINE_COUNT ) {
m_lstConsoleOutput.SetRedraw(FALSE);
m_lstConsoleOutput.DeleteString(0);
m_lstConsoleOutput.SetRedraw(TRUE);
}
INT nIndex = m_lstConsoleOutput.AddString(lpszString);
if( nIndex == LB_ERR || nIndex == LB_ERRSPACE ) return FALSE;
CRect rectClient; m_lstConsoleOutput.GetClientRect( & rectClient );
CRect rectItem; m_lstConsoleOutput.GetItemRect(nIndex, & rectItem);
INT nLineCount = rectClient.Height() / rectItem.Height();
INT nTop = m_lstConsoleOutput.GetTopIndex();
if( nIndex - nTop + 1 > nLineCount ) m_lstConsoleOutput.SetTopIndex( nIndex - nLineCount + 1);
return TRUE;
}
BOOL COutputWindow::ReplaceTheLastString(LPCTSTR lpszString)
{
INT nCount = m_lstConsoleOutput.GetCount();
if( nCount > 0 ) m_lstConsoleOutput.DeleteString(nCount-1);
INT nIndex = m_lstConsoleOutput.AddString(lpszString);
if( nIndex == LB_ERR || nIndex == LB_ERRSPACE ) return FALSE;
CRect rectClient; m_lstConsoleOutput.GetClientRect( & rectClient );
CRect rectItem; m_lstConsoleOutput.GetItemRect(nIndex, & rectItem);
INT nLineCount = rectClient.Height() / rectItem.Height();
INT nTop = m_lstConsoleOutput.GetTopIndex();
if( nIndex - nTop + 1 > nLineCount ) m_lstConsoleOutput.SetTopIndex( nIndex - nLineCount + 1);
return TRUE;
}
BOOL COutputWindow::GetTheLastString(CString & szString)
{
INT nCount = m_lstConsoleOutput.GetCount();
if( nCount > 0 ) m_lstConsoleOutput.GetText(nCount-1, szString);
else szString = "";
return TRUE;
}
BOOL COutputWindow::PreTranslateMessage(MSG* pMsg)
{
switch( pMsg->message ) {
case WM_KEYDOWN:
switch( pMsg->wParam ) {
case VK_RETURN:
OnKeyReturn();
return TRUE;
case VK_ESCAPE:
OnKeyEscape();
return TRUE;
}
break;
}
if( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ) {
TranslateMessage( pMsg );
DispatchMessage( pMsg );
return TRUE;
} else return CSizingControlBar::PreTranslateMessage(pMsg);
}
void COutputWindow::OnKeyReturn()
{
if( m_edtConsoleInput.GetStyle() & ES_READONLY ) return;
// PostMessage( WM_COMMAND, ID_COMMAND_SEND_INPUT, 0L );
TCHAR szInputString[4096];
m_edtConsoleInput.GetLine(0, szInputString, 4096);
CCedtView::SetChildInputString( szInputString );
m_edtConsoleInput.SetWindowText(""); // clear input console
}
void COutputWindow::OnKeyEscape()
{
if( m_edtConsoleInput.GetStyle() & ES_READONLY ) return;
// PostMessage( WM_COMMAND, ID_COMMAND_KILL_PROCESS, 0L );
CCedtView::KillChildProcess();
}