-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputWnd.cpp
199 lines (156 loc) · 5.5 KB
/
OutputWnd.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
#include MfcPrecompileFile//#include "MFCpch.h"
#include "OutputWnd.h"
#include "MFCRes.h"
#include "MFCFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COutputBar
OutputWnd::OutputWnd() noexcept
{
}
OutputWnd::~OutputWnd()
{
}
BEGIN_MESSAGE_MAP(OutputWnd, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
int OutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy;
rectDummy.SetRectEmpty();
// Create tabs window:
if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 1))
{
TRACE0("Failed to create output tab window\n");
return -1; // fail to create
}
// Create output panes:
const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||
!m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||
!m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))
{
TRACE0("Failed to create output windows\n");
return -1; // fail to create
}
UpdateFonts();
CString strTabName;
BOOL bNameValid;
// Attach list windows to tab:
bNameValid = strTabName.LoadString(IDS_BUILD_TAB);
ASSERT(bNameValid);
m_wndTabs.AddTab(&m_wndOutputBuild, strTabName, (UINT)0);
bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);
ASSERT(bNameValid);
m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);
bNameValid = strTabName.LoadString(IDS_FIND_TAB);
ASSERT(bNameValid);
m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);
// Fill output tabs with some dummy text (nothing magic here)
FillBuildWindow();
FillDebugWindow();
FillFindWindow();
return 0;
}
void OutputWnd::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
// Tab control should cover the whole client area:
m_wndTabs.SetWindowPos (nullptr, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}
void OutputWnd::AdjustHorzScroll(CListBox& wndListBox)
{
CClientDC dc(this);
CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
int cxExtentMax = 0;
for (int i = 0; i < wndListBox.GetCount(); i ++)
{
CString strItem;
wndListBox.GetText(i, strItem);
cxExtentMax = max(cxExtentMax, (int)dc.GetTextExtent(strItem).cx);
}
wndListBox.SetHorizontalExtent(cxExtentMax);
dc.SelectObject(pOldFont);
}
void OutputWnd::FillBuildWindow()
{
m_wndOutputBuild.AddString(_T("Build output is being displayed here."));
m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));
m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));
}
void OutputWnd::FillDebugWindow()
{
m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));
m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));
m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));
}
void OutputWnd::FillFindWindow()
{
m_wndOutputFind.AddString(_T("Find output is being displayed here."));
m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));
m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));
}
void OutputWnd::UpdateFonts()
{
m_wndOutputBuild.SetFont(&afxGlobalData.fontRegular);
m_wndOutputDebug.SetFont(&afxGlobalData.fontRegular);
m_wndOutputFind.SetFont(&afxGlobalData.fontRegular);
}
/////////////////////////////////////////////////////////////////////////////
// OutputList1
OutputList::OutputList() noexcept
{
}
OutputList::~OutputList()
{
}
BEGIN_MESSAGE_MAP(OutputList, CListBox)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
ON_WM_WINDOWPOSCHANGING()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// OutputList message handlers
void OutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
CMenu menu;
menu.LoadMenu(IDR_OUTPUT_POPUP);
CMenu* pSumMenu = menu.GetSubMenu(0);
if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
{
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
return;
((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
UpdateDialogControls(this, FALSE);
}
SetFocus();
}
void OutputList::OnEditCopy()
{
MessageBox(_T("Copy output"));
}
void OutputList::OnEditClear()
{
MessageBox(_T("Clear output"));
}
void OutputList::OnViewOutput()
{
CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
if (pMainFrame != nullptr && pParentBar != nullptr)
{
pMainFrame->SetFocus();
pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
pMainFrame->RecalcLayout();
}
}