forked from FlatGlobus/WTLBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputWindow.cpp
274 lines (233 loc) · 7.63 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
// Copyright (C) FlatGlobus([email protected]) All rights reserved.
//
// This file is a part of the WTLBuilder.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#include "StdAfx.h"
#include "OutputWindow.h"
#include "_util.h"
#include "cscripteditor.h"
#define FIRST_ROW_WIDTH 20
//////////////////////////////////////////////////////////////////////////
const UINT COutputWindow::_controlsToClip[] =
{
//{{WTLBUILDER_CTRLTOCLIP
IDC_LISTVIEW,
IDC_COUTPUTWINDOW_PANEL3,
//}}WTLBUILDER_CTRLTOCLIP
0
};
//////////////////////////////////////////////////////////////////////////
COutputWindow::COutputWindow(void)
//{{WTLBUILDER_CONSTRUCTOR
//}}WTLBUILDER_CONSTRUCTOR
{
RegisterEvent(evOutput,this,&COutputWindow::OutputStr);
RegisterEvent(evScriptError,this,&COutputWindow::OutputScriptError);
RegisterEvent(evClearOutput, this, &COutputWindow::ClearList);
}
COutputWindow::~COutputWindow(void)
{
//{{WTLBUILDER_MEMBER_DESTRUCTION
//}}WTLBUILDER_MEMBER_DESTRUCTION
UnRegisterEvent(this);
}
BOOL COutputWindow::PreTranslateMessage(MSG* pMsg)
{
m_toolTip.RelayEvent(pMsg);
return thisClass::PreTranslateMessage(pMsg);
}
LRESULT COutputWindow::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_toolTip.Create(m_hWnd);
//{{WTLBUILDER_MEMBER_CREATION
m_formFont.CreateFont(-12,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,_T("MS Sans Serif"));
SetFont((HFONT)m_formFont);
ResizeClient(805,144);
SetWindowText(_T("Output"));
m_listviewctrl.Create(m_hWnd,CRect(0,26,805,146),NULL,WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SINGLESEL|LVS_NOLABELWRAP|LVS_ALIGNTOP|LVS_NOCOLUMNHEADER|LVS_NOSORTHEADER,0,IDC_LISTVIEW);
m_listviewctrl.SetFont((HFONT)m_formFont);
m_listviewctrl.SetExtendedListViewStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP,0);
m_panel3.Create(m_hWnd,CRect(0,0,805,26),NULL,WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,WS_EX_CONTROLPARENT,IDC_COUTPUTWINDOW_PANEL3);
m_panel3.SetFont((HFONT)m_formFont);
m_panel3.SetInnerBorder(0);
m_panel3.SetOuterBorder(0);
m_panel3.SetEdgeType(BF_RECT);
m_panel3.SetBkColor(RGB(0xF0,0xF0,0xF0));
m_panel3.SetTextColor(RGB(0x00,0x00,0x00));
m_panel3.SetHorizTextAlign(DT_CENTER);
m_panel3.SetVertTextAlign(DT_VCENTER);
m_panel3.SetSingleLine(true);
m_clear_list.Create(m_panel3,CRect(0,0,20,20),_T(""),WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP|BS_PUSHBUTTON,0,IDC_CLEAR_LIST);
m_clear_list.SetFont((HFONT)m_formFont);
m_clear_list.SetFlat(true);
m_clear_list.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_clear_list.SetColor(CButtonST::BTNST_COLOR_BK_IN,GetSysColor(COLOR_BTNFACE));
m_clear_list.SetColor(CButtonST::BTNST_COLOR_BK_OUT,GetSysColor(COLOR_BTNFACE));
m_clear_list.SetIcon(IDI_CLEAR_ERR,IDI_CLEAR_ERR);
//}}WTLBUILDER_MEMBER_CREATION
//{{WTLBUILDER_POST_CREATION
//}}WTLBUILDER_POST_CREATION
//{{WTLBUILDER_TABSTOP
m_clear_list.SetWindowPos(m_listviewctrl,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
//}}WTLBUILDER_TABSTOP
imageList.Create(16,16,ILC_COLOR8,0,0);
CRect rc;
m_listviewctrl.GetClientRect(&rc);
m_listviewctrl.InsertColumn(0,_T(""),LVCFMT_LEFT,rc.Width()/*FIRST_ROW_WIDTH*/,-1);
//m_listviewctrl.InsertColumn(1,_T(""),LVCFMT_LEFT,rc.Width()-FIRST_ROW_WIDTH);
m_listviewctrl.SetImageList(imageList,LVSIL_SMALL);
imageList.AddIcon(AtlLoadIcon(IDI_INFO_MSG));
imageList.AddIcon(AtlLoadIcon(IDI_WARN_MSG));
imageList.AddIcon(AtlLoadIcon(IDI_ERROR_MSG));
InitLayout();
return 0;
}
void COutputWindow::DefineLayout()
{
//{{WTLBUILDER_ATTACH_CONTROLS
AttachForm(m_listviewctrl,ATTACH_LEFT);
AttachWidget(m_listviewctrl,ATTACH_TOP,m_panel3);
AttachForm(m_listviewctrl,ATTACH_RIGHT);
AttachForm(m_listviewctrl,ATTACH_BOTTOM);
AttachForm(m_panel3,ATTACH_LEFT);
AttachForm(m_panel3,ATTACH_TOP);
AttachForm(m_panel3,ATTACH_RIGHT);
//}}WTLBUILDER_ATTACH_CONTROLS
}
void COutputWindow::InitLayout()
{
//{{WTLBUILDER_INITLAYOUT
_minClientSize.cx = 805;
_minClientSize.cy = 144;
_prevClientSize = _minClientSize;
_minWindowSize.cx = 821;
_minWindowSize.cy = 182;
SetNPositions(1);
ShowHandle(false);
DefineLayout();
//}}WTLBUILDER_INITLAYOUT
//SetScrollSize(_minClientSize);
}
void COutputWindow::GetDialogRect(LPRECT r)
{
GetClientRect(r);
if (r->right < m_sizeAll.cx)
{
r->right = m_sizeAll.cx;
}
if (r->bottom < m_sizeAll.cy)
{
r->bottom = m_sizeAll.cy;
}
}
void COutputWindow::GetOffset(LPPOINT offset)
{
*offset = m_ptOffset;
}
void COutputWindow::DoPaint(CDCHandle /*dc*/)
{
}
void __stdcall COutputWindow::Show(void)
{
if(IsWindow())
ShowWindow(SW_SHOW);
}
void __stdcall COutputWindow::Hide(void)
{
if(IsWindow())
ShowWindow(SW_HIDE);
}
void __stdcall COutputWindow::Clear(void)
{
for(;m_listviewctrl.GetItemCount();)
{
CScriptError * se=(CScriptError *)m_listviewctrl.GetItemData(0);
if(se!=NULL)
delete se;
m_listviewctrl.DeleteItem(0);
}
//m_listviewctrl.
}
HWND COutputWindow::Create(HWND Parent)
{
CRect rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc , 0);
int desiredWidth = rc.Width()-200;
rc.left=rc.Width()/2-desiredWidth/2;
rc.right=rc.left+desiredWidth;
rc.top=rc.bottom-300;
thisClass::Create(Parent,rc);
return m_hWnd;
}
//called from script
void __stdcall COutputWindow::put_Info(BSTR strText)
{
USES_CONVERSION;
LPCTSTR lpText = OLE2CT(strText);
//m_listviewctrl.AddItem(m_listviewctrl.GetItemCount(),0,lpText,0);
OutputStr(InfoMsg, lpText);
}
void __stdcall COutputWindow::put_Warn(BSTR strText)
{
USES_CONVERSION;
LPCTSTR lpText = OLE2CT(strText);
//m_listviewctrl.AddItem(m_listviewctrl.GetItemCount(), 0, lpText, 0);
OutputStr(WarnMsg, lpText);
}
void __stdcall COutputWindow::put_Err(BSTR strText)
{
USES_CONVERSION;
LPCTSTR lpText = OLE2CT(strText);
//m_listviewctrl.AddItem(m_listviewctrl.GetItemCount(), 0, lpText, 0);
OutputStr(ErrorMsg, lpText);
}
//called from program
void COutputWindow::OutputStr(int msgType,LPCTSTR msg)
{
m_listviewctrl.AddItem(m_listviewctrl.GetItemCount(),0,msg,msgType);
Show();
}
LRESULT COutputWindow::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
bHandled = TRUE;
return 0;
}
LRESULT COutputWindow::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
ShowWindow(SW_HIDE);
bHandled = TRUE;
return 0;
}
void COutputWindow::OutputScriptError(CScriptError *se)
{
CString errStr = MakeString("Script error: function name %s line %u %s %s", (LPCTSTR)se->GetFunc(), se->GetLine(), (LPCTSTR)se->GetError(), (LPCTSTR)se->GetDescr());
int idx = m_listviewctrl.AddItem(m_listviewctrl.GetItemCount(),0,errStr,ErrorMsg);
if(idx != -1)
m_listviewctrl.SetItemData(idx,(DWORD_PTR)se);
Show();
}
LRESULT COutputWindow::OnDblClick(int,LPNMHDR pnmh, BOOL&)
{
int idx=m_listviewctrl.GetSelectedIndex();
if(idx > -1)
{
CScriptError *se = (CScriptError *)m_listviewctrl.GetItemData(idx);
if(se!=NULL && se->GetFile().IsEmpty()==FALSE)
{
CScriptEditor * editor = new CScriptEditor();
editor->Create(GetParent(),se);
}
}
return 0;
}
LRESULT COutputWindow::OnClearList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
m_listviewctrl.DeleteAllItems();
return 0;
}
void COutputWindow::ClearList()
{
m_listviewctrl.DeleteAllItems();
}