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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [win32/] [OutputView.cpp] - Blame information for rev 790

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

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

powered by: WebSVN 2.1.0

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