OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [standalone/] [win32/] [OutputView.cpp] - Blame information for rev 321

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//####COPYRIGHTBEGIN####
2
//                                                                          
3
// ----------------------------------------------------------------------------
4
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5
//
6
// This program is part of the eCos host tools.
7
//
8
// This program is free software; you can redistribute it and/or modify it 
9
// under the terms of the GNU General Public License as published by the Free 
10
// Software Foundation; either version 2 of the License, or (at your option) 
11
// any later version.
12
// 
13
// This program is distributed in the hope that it will be useful, but WITHOUT 
14
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
15
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
16
// more details.
17
// 
18
// You should have received a copy of the GNU General Public License along with
19
// this program; if not, write to the Free Software Foundation, Inc., 
20
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
//
22
// ----------------------------------------------------------------------------
23
//                                                                          
24
//####COPYRIGHTEND####
25
// OutputView.cpp : implementation file
26
//
27
//
28
//===========================================================================
29
//===========================================================================
30
//#####DESCRIPTIONBEGIN####
31
//
32
// Author(s):   sdf
33
// Contact(s):  sdf
34
// Date:                1998/08/11
35
// Version:             0.01
36
// Purpose:     
37
// Description: This is the implementation of the output window view
38
// Requires:    
39
// Provides:    
40
// See also:    
41
// Known bugs:  
42
// Usage:       
43
//
44
//####DESCRIPTIONEND####
45
//
46
//===========================================================================
47
 
48
#include "stdafx.h"
49
#ifndef PLUGIN
50
#include "BCMenu.h"
51
#endif
52
#include "ConfigTool.h"
53
#include "OutputView.h"
54
#include "MainFrm.h"
55
#include "FindDialog.h"
56
#include "CTUtils.h"
57
#include "ConfigTooldoc.h"
58
 
59
#ifdef _DEBUG
60
#define new DEBUG_NEW
61
#undef THIS_FILE
62
static char THIS_FILE[] = __FILE__;
63
#endif
64
 
65
/////////////////////////////////////////////////////////////////////////////
66
// COutputView
67
 
68
IMPLEMENT_DYNCREATE(COutputView, CEditView)
69
 
70
COutputView::COutputView()
71
{
72
    CConfigTool::SetOutputView(this);
73
}
74
 
75
COutputView::~COutputView()
76
{
77
    CConfigTool::SetOutputView(0);
78
}
79
 
80
static UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);
81
 
82
BEGIN_MESSAGE_MAP(COutputView, CEditView)
83
        //{{AFX_MSG_MAP(COutputView)
84
        ON_WM_CONTEXTMENU()
85
        ON_WM_CHAR()
86
        ON_WM_KEYDOWN()
87
    ON_COMMAND(ID_EDIT_FINDAGAIN,OnEditFindAgain)
88
        ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)
89
        ON_COMMAND(ID_EDIT_FIND, OnEditFind)
90
        ON_REGISTERED_MESSAGE(WM_FINDREPLACE, OnEditFindReplace)
91
        ON_CONTROL_REFLECT(EN_CHANGE, OnEditChange)
92
        ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
93
        ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditDelete)
94
        ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClear)
95
        ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClear)
96
        ON_COMMAND(ID_LOG_SAVE, OnFileSave)
97
        ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
98
        ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
99
        ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
100
        ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
101
        ON_WM_MENUCHAR()
102
        //}}AFX_MSG_MAP
103
END_MESSAGE_MAP()
104
 
105
/////////////////////////////////////////////////////////////////////////////
106
// COutputView drawing
107
 
108
void COutputView::OnDraw(CDC* pDC)
109
{
110
        // TODO: add draw code here
111
        UNUSED_ALWAYS(pDC);
112
}
113
 
114
/////////////////////////////////////////////////////////////////////////////
115
// COutputView diagnostics
116
 
117
#ifdef _DEBUG
118
void COutputView::AssertValid() const
119
{
120
        CEditView::AssertValid();
121
}
122
 
123
void COutputView::Dump(CDumpContext& dc) const
124
{
125
        CEditView::Dump(dc);
126
}
127
#endif //_DEBUG
128
 
129
/////////////////////////////////////////////////////////////////////////////
130
// COutputView message handlers
131
 
132
void COutputView::AddText(const CString & str)
133
{
134
        CString strText;
135
        // Change \n into \r\n
136
        int nStart=0;
137
        for(int nIndex=0;nIndex<str.GetLength();nIndex++){
138
                if(str[nIndex]==_TCHAR('\n')){
139
                        if(nIndex==0||str[nIndex-1]!=_TCHAR('\r')){
140
                                strText+=str.Mid(nStart,nIndex-nStart);
141
                                strText+=_TCHAR('\r');
142
                                nStart=nIndex;
143
                        }
144
                }
145
        }
146
 
147
        strText+=str.Mid(nStart,nIndex-nStart);
148
 
149
        {
150
                int nStart,nEnd;
151
                int nLength=GetBufferLength();
152
                GetEditCtrl().GetSel(nStart,nEnd);
153
                // Replace selection
154
                GetEditCtrl().SetSel(nLength,nLength,TRUE);
155
                GetEditCtrl().ReplaceSel(strText);
156
                if(GetBufferLength()!=unsigned(nLength+strText.GetLength())){
157
                        // Try again by removing equivalent length from start of buffer.
158
                        // For neatness, remove whole lines
159
                        int nLine=GetEditCtrl().LineFromChar(strText.GetLength()-1);
160
                        int nIndex=GetEditCtrl().LineIndex(nLine+1);
161
                        GetEditCtrl().SetSel(0,nIndex-1,TRUE);
162
                        GetEditCtrl().ReplaceSel(_T(""));
163
                        nLength=GetBufferLength();
164
                        GetEditCtrl().SetSel(nLength,nLength,TRUE);
165
                        GetEditCtrl().ReplaceSel(strText);
166
                } else if(nStart!=nEnd) {
167
                        GetEditCtrl().SetSel(nStart,nEnd,TRUE);
168
                }
169
        }
170
}
171
 
172
void COutputView::OnInitialUpdate()
173
{
174
        CEditView::OnInitialUpdate();
175
        CConfigToolApp*pApp=(CConfigToolApp*)AfxGetApp();
176
        if(pApp->m_strBufferedLogMessages){
177
                AddText(pApp->m_strBufferedLogMessages);
178
                pApp->m_strBufferedLogMessages=_T("");
179
        }
180
}
181
 
182
void COutputView::Clear()
183
{
184
        GetEditCtrl().SetSel(0,-1);
185
        GetEditCtrl().Clear();
186
}
187
 
188
BOOL COutputView::PreCreateWindow(CREATESTRUCT& cs)
189
{
190
        //cs.style|=ES_MULTILINE|ES_READONLY|WS_VSCROLL;
191
        cs.style|=ES_MULTILINE|WS_VSCROLL|ES_NOHIDESEL;
192
        return CEditView::PreCreateWindow(cs);
193
}
194
 
195
void COutputView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
196
{
197
        if(VK_DELETE==nChar){
198
                MessageBeep (MB_OK);
199
        } else {
200
                CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
201
        }
202
}
203
 
204
void COutputView::OnContextMenu(CWnd* pWnd, CPoint point)
205
{
206
        Menu menu;
207
        menu.LoadMenu(IDR_OUTPUT_CONTEXT);
208
  menu.LoadToolbar(IDR_MAINFRAME);
209
        Menu *pPopup=(Menu *)menu.GetSubMenu(0);
210
        if(point.x<0){
211
                point=GetCaretPos();
212
                point.x=max(3,point.x);
213
                point.y=max(3,point.y);
214
                ClientToScreen(&point);
215
        }
216
        pPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x,point.y,this);
217
        UNUSED_ALWAYS(pWnd);
218
}
219
 
220
void COutputView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
221
{
222
        switch(nChar){
223
                case 0x03: // ctrl+c
224
                        SendMessage(WM_COMMAND,ID_EDIT_COPY,0);
225
                        break;
226
                case 0x01: // ctrl+a
227
                        SendMessage(WM_COMMAND,ID_EDIT_SELECT_ALL,0);
228
                        break;
229
                default:
230
                        MessageBeep     (MB_OK);
231
                        break;
232
        }
233
 
234
        UNUSED_ALWAYS(nFlags);
235
        UNUSED_ALWAYS(nRepCnt);
236
}
237
 
238
void COutputView::OnEditClear()
239
{
240
        Clear();
241
}
242
 
243
void COutputView::OnEditUndo()
244
{
245
        MessageBeep (MB_OK);
246
}
247
 
248
void COutputView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
249
{
250
        switch(lHint){
251
                case 0:
252
                default:
253
                        return;
254
        }
255
        UNUSED_ALWAYS(pSender);
256
        UNUSED_ALWAYS(pHint);
257
}
258
 
259
void COutputView::OnFileSave()
260
{
261
        CFileDialog dlg( FALSE, _T("log"), _T("ConfigTool"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
262
                _T("Log Files (*.log)|*.log|All Files (*.*)|*.*||"));
263
        if(IDOK==dlg.DoModal()){
264
                Save(dlg.GetPathName());
265
        }
266
}
267
 
268
void COutputView::OnEditSelectAll()
269
{
270
        GetEditCtrl().SetSel(0,-1);
271
}
272
 
273
void COutputView::OnEditCopy()
274
{
275
        GetEditCtrl().Copy();
276
}
277
 
278
void COutputView::OnUpdateEditCopy(CCmdUI* pCmdUI)
279
{
280
  int nStart,nEnd;
281
  GetEditCtrl().GetSel(nStart,nEnd);
282
        pCmdUI->Enable(nStart!=nEnd);
283
}
284
 
285
void COutputView::OnUpdateEditClear(CCmdUI* pCmdUI)
286
{
287
        pCmdUI->Enable(GetBufferLength()!=0);
288
}
289
 
290
void COutputView::Save(const CString & strFile)
291
{
292
        TRY
293
        {
294
                CStdioFile f( strFile, CFile::modeCreate | CFile::modeWrite );
295
                CStringArray arstr;
296
                GetContents(arstr);
297
                for(int i=0;i<arstr.GetSize();i++){
298
                        f.WriteString(arstr[i]);
299
                        f.WriteString(_T("\n"));
300
                }
301
                f.Close();
302
        }
303
        CATCH( CFileException, e )
304
        {
305
                CUtils::MessageBoxF(_T("Failed to write to %s - %s"),strFile,CUtils::Explanation(*e));
306
        }
307
        END_CATCH
308
 
309
}
310
 
311
void COutputView::GetContents(CStringArray & arstr)
312
{
313
        arstr.SetSize(GetEditCtrl().GetLineCount());
314
        for(int i=0;i<arstr.GetSize();i++){
315
                CString &str=arstr[i];
316
                for(int n=256;;n+=256){
317
                        TCHAR *pszBuf=str.GetBuffer(n);
318
                        int nLineLen=GetEditCtrl().GetLine(i,pszBuf,n-1);
319
                        pszBuf[nLineLen]=_TCHAR('\0');
320
                        str.ReleaseBuffer();
321
                        if(nLineLen<n-1){
322
                                break;
323
                        }
324
                }
325
        }
326
}
327
 
328
void COutputView::OnEditFindAgain()
329
{
330
    CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
331
    if(!FindText(pDoc->m_strFind,pDoc->m_nFindFlags&&FR_DOWN, pDoc->m_nFindFlags&FR_MATCHCASE)){
332
                CUtils::MessageBoxF(_T("Cannot find '%s'"),pDoc->m_strFind);
333
    }
334
}
335
 
336
void COutputView::OnUpdateEditFindAgain(CCmdUI* pCmdUI)
337
{
338
    pCmdUI->Enable(!CConfigTool::GetConfigToolDoc()->m_strFind.IsEmpty() && m_hWnd==CWnd::GetFocus()->m_hWnd);
339
}
340
 
341
void COutputView::OnFindNext( LPCTSTR lpszFind, BOOL bNext, BOOL bCase )
342
{
343
    CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
344
        pDoc->m_strFind=lpszFind;
345
    pDoc->m_nFindFlags=(bNext?FR_DOWN:0)|(bCase?FR_MATCHCASE:0);
346
    CEditView::OnFindNext(lpszFind, bNext, bCase );
347
}
348
 
349
void COutputView::OnTextNotFound( LPCTSTR lpszFind )
350
{
351
    CUtils::MessageBoxF(_T("Cannot find '%s'"),lpszFind);
352
    CEditView::OnTextNotFound(lpszFind);
353
}
354
 
355
void COutputView::OnEditFind()
356
{
357
    CConfigTool::GetMain()->m_bFindInProgress=true;
358
    CEditView::OnEditFind();
359
}
360
 
361
void COutputView::OnUpdateEditFind(CCmdUI* pCmdUI)
362
{
363
        pCmdUI->Enable(!CConfigTool::GetMain()->m_bFindInProgress);
364
}
365
 
366
LONG COutputView::OnEditFindReplace(WPARAM wParam, LPARAM lParam)
367
{
368
        CFindReplaceDialog* pDialog = CFindReplaceDialog::GetNotifier(lParam);
369
    if(pDialog->IsTerminating()){
370
        CConfigTool::GetMain()->m_bFindInProgress=false;
371
    }
372
    return CEditView::OnFindReplaceCmd(wParam, lParam);
373
}
374
 
375
void COutputView::OnEditChange ()
376
{
377
        // override CEditView::OnEditChange() to prevent
378
        // setting of the document modified flag
379
}
380
 
381
void COutputView::OnUpdateEditCut(CCmdUI* pCmdUI)
382
{
383
        pCmdUI->Enable(false);
384
}
385
 
386
void COutputView::OnUpdateEditPaste(CCmdUI* pCmdUI)
387
{
388
        pCmdUI->Enable(false);
389
}
390
 
391
void COutputView::OnUpdateEditDelete(CCmdUI* pCmdUI)
392
{
393
        pCmdUI->Enable(false);
394
}
395
 
396
LRESULT COutputView::OnMenuChar(UINT, UINT, CMenu*)
397
{
398
  const MSG *pMsg=GetCurrentMessage();
399
  // punt to the mainframe to deal with shortcuts in popups
400
  return AfxGetMainWnd()->SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
401
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.