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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [configtoolview.cpp] - Blame information for rev 786

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
// configtoolview.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians
28
// Contact(s):  julians
29
// Date:        2000/10/05
30
// Version:     $Id: configtoolview.cpp,v 1.11 2001/07/13 15:17:43 julians Exp $
31
// Purpose:
32
// Description: Implementation file for the ecConfigToolView class
33
// Requires:
34
// Provides:
35
// See also:
36
// Known bugs:
37
// Usage:
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
// ============================================================================
44
// declarations
45
// ============================================================================
46
 
47
// ----------------------------------------------------------------------------
48
// headers
49
// ----------------------------------------------------------------------------
50
#ifdef __GNUG__
51
    #pragma implementation "configtoolview.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#ifdef __BORLANDC__
58
    #pragma hdrstop
59
#endif
60
 
61
#include "configtoolview.h"
62
#include "configtooldoc.h"
63
#include "configtree.h"
64
#include "configtool.h"
65
#include "shortdescrwin.h"
66
#include "mainwin.h"
67
#include "propertywin.h"
68
#include "ecutils.h"
69
 
70
IMPLEMENT_DYNAMIC_CLASS(ecConfigToolView, wxView)
71
 
72
BEGIN_EVENT_TABLE(ecConfigToolView, wxView)
73
END_EVENT_TABLE()
74
 
75
ecConfigToolView::ecConfigToolView()
76
{
77
    m_expandedForFind = wxTreeItemId();
78
}
79
 
80
// What to do when a view is created. Creates actual
81
// windows for displaying the view.
82
bool ecConfigToolView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
83
{
84
    wxGetApp().GetDocManager()->ActivateView(this, TRUE);
85
 
86
    // Single-window mode
87
#if 0
88
    m_frame = GetMainFrame();
89
 
90
    // Associate the appropriate frame with this view.
91
    SetFrame(m_frame);
92
 
93
    // Make sure the document manager knows that this is the
94
    // current view.
95
    Activate(TRUE);
96
 
97
    // Initialize the edit menu Undo and Redo items
98
    doc->GetCommandProcessor()->SetEditMenu(((pzMainFrame *)m_frame)->editMenu);
99
    doc->GetCommandProcessor()->Initialize();
100
#endif
101
 
102
    return TRUE;
103
}
104
 
105
void ecConfigToolView::OnDraw(wxDC *dc)
106
{
107
}
108
 
109
void ecConfigToolView::OnUpdate(wxView *WXUNUSED(sender), wxObject *hintObj)
110
{
111
    ecConfigToolDoc* pDoc = (ecConfigToolDoc*) GetDocument();
112
    ecConfigTreeCtrl* treeCtrl = wxGetApp().GetTreeCtrl();
113
 
114
    wxASSERT (pDoc);
115
 
116
    ecConfigItem* selItem = NULL;
117
 
118
    wxTreeItemId sel = treeCtrl->GetSelection();
119
    if (sel.IsOk())
120
    {
121
        ecTreeItemData* data = (ecTreeItemData*) treeCtrl->GetItemData(sel);
122
        if (data)
123
            selItem = data->GetConfigItem() ;
124
    }
125
 
126
    ecConfigToolHint* hint = (ecConfigToolHint*) hintObj;
127
    int hintOp = ecNoHint;
128
    if (hint)
129
        hintOp = hint->m_op;
130
 
131
    switch (hintOp)
132
    {
133
    case ecSelChanged:
134
 
135
        {
136
            // Note that we're cheating a bit here, since we're using the tree view
137
            // to update another view, instead of having a view per control as in the MFC
138
            // version. However, it doesn't seem to be worth the extra machinery.
139
                    // Update the description window
140
            if (selItem)
141
            {
142
                wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->SetValue(selItem->GetDescription());
143
 
144
                // Update the properties window
145
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
146
            }
147
            else
148
            {
149
                wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->Clear();
150
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->ClearAll();
151
            }
152
 
153
        }
154
        break;
155
    case ecAllSaved:
156
 
157
        {
158
            int nItem;
159
#if wxCHECK_VERSION(2, 6, 0)
160
            for(nItem=0;nItem<pDoc->GetItems().GetCount();nItem++)
161
#else
162
            for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
163
#endif
164
            {
165
                ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
166
                wxTreeItemId treeItem = pItem->GetTreeItem();
167
                if(treeItem){
168
                    treeCtrl->SetItemText(treeItem, pItem->GetItemNameOrMacro());
169
                    //InvalidateItem(h);
170
                }
171
            }
172
 
173
            // Update the properties window
174
            if (selItem)
175
            {
176
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
177
            }
178
 
179
            wxGetApp().GetMainFrame()->UpdateFrameTitle();
180
 
181
            // Update the value pane
182
            wxGetApp().GetMainFrame()->GetValueWindow()->Refresh();
183
        }
184
        break;
185
    case ecFilenameChanged:
186
 
187
        {
188
            // Update the properties window
189
            if (selItem)
190
            {
191
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
192
            }
193
            wxGetApp().GetMainFrame()->UpdateFrameTitle();
194
        }
195
        break;
196
    case ecNameFormatChanged:
197
        {
198
            int nItem;
199
#if wxCHECK_VERSION(2, 6, 0)
200
            for(nItem=0;nItem<pDoc->GetItems().GetCount();nItem++)
201
#else
202
            for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
203
#endif
204
            {
205
                ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
206
                wxString strName(pItem->GetItemNameOrMacro());
207
                if(pItem->Modified()){
208
                    strName+=wxT('*');
209
                }
210
                treeCtrl->SetItemText(pItem->GetTreeItem(), strName);
211
            }
212
 
213
            treeCtrl->Refresh();
214
        }
215
        break;
216
    case ecIntFormatChanged:
217
        {
218
            if (selItem && selItem->GetOptionType() == ecLong)
219
            {
220
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->SetItem(ecPropertyListCtrl::ecValue, selItem->StringValue());
221
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->SetItem(ecPropertyListCtrl::ecDefaultValue, ecUtils::IntToStr(selItem->DefaultValue(), wxGetApp().GetSettings().m_bHex));
222
            }
223
 
224
        }
225
        break;
226
    case ecClear:
227
        {
228
            m_expandedForFind = wxTreeItemId();
229
 
230
            treeCtrl->DeleteAllItems();
231
 
232
            wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->Clear();
233
            wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(NULL);
234
            wxGetApp().GetMainFrame()->GetValueWindow()->Refresh();
235
            break;
236
        }
237
 
238
    case ecValueChanged:
239
        {
240
            ecConfigItem& ti = *(ecConfigItem *)hint->m_item;
241
 
242
            // Update the tree item
243
            ti.ConvertFromCdl();
244
            ti.UpdateTreeItem(* treeCtrl);
245
 
246
            // Update the value cell
247
            ecValueWindow* valueWindow = wxGetApp().GetMainFrame()->GetValueWindow();
248
            if (valueWindow)
249
            {
250
                wxRect rect = valueWindow->GetItemRect(& ti);
251
#ifdef __WXMSW__
252
                valueWindow->Refresh(TRUE, & rect);
253
#else
254
                // For some reason, on Linux, the value window gets
255
                // blanked out if a dialog pops up as a result of the value change.
256
                valueWindow->Refresh();
257
#endif
258
            }
259
 
260
            // Properties window
261
            if (selItem)
262
            {
263
                wxGetApp().GetMainFrame()->GetPropertyListWindow()->RefreshValue();
264
            }
265
            wxGetApp().GetMainFrame()->UpdateFrameTitle();
266
        }
267
        break;
268
 
269
    case ecExternallyChanged:
270
        {
271
            int nItem;
272
#if wxCHECK_VERSION(2, 6, 0)
273
            for(nItem=0;nItem<pDoc->GetItems().GetCount();nItem++)
274
#else
275
            for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
276
#endif
277
            {
278
                ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
279
                pItem->UpdateTreeItem(* treeCtrl);
280
            }
281
            wxGetApp().GetMainFrame()->UpdateFrameTitle();
282
        }
283
        break;
284
    default:
285
        break; // not for us, apparently
286
  }
287
}
288
 
289
// Clean up windows used for displaying the view.
290
bool ecConfigToolView::OnClose(bool deleteWindow)
291
{
292
    ecConfigToolHint hint(NULL, ecClear);
293
    GetDocument()->UpdateAllViews (NULL, & hint);
294
 
295
    if (!GetDocument()->Close())
296
        return FALSE;
297
 
298
    wxGetApp().GetDocManager()->ActivateView(this, FALSE);
299
 
300
    // TODO: Set any pointers to this view to NULL
301
 
302
#if 0
303
    wxString s(wxTheApp->GetAppName());
304
    if (m_frame)
305
        m_frame->SetTitle(s);
306
 
307
    SetFrame((wxFrame *) NULL);
308
#endif
309
 
310
    Activate(FALSE);
311
 
312
    return TRUE;
313
}
314
 
315
void ecConfigToolView::OnChangeFilename()
316
{
317
    if (wxGetApp().GetTopWindow() && GetDocument())
318
    {
319
        wxString docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
320
        wxStripExtension(docTitle);
321
        GetDocument()->SetTitle(docTitle);
322
 
323
        wxString name(GetDocument()->GetFilename());
324
        wxStripExtension(name);
325
 
326
        ((ecConfigToolDoc*) GetDocument())->SetInstallTree(name + wxT("_install"));
327
        ((ecConfigToolDoc*) GetDocument())->SetBuildTree(name + wxT("_build"));
328
 
329
        wxString title;
330
 
331
        wxString modifiedMarker;
332
        if (GetDocument()->IsModified())
333
            modifiedMarker = wxT("*");
334
 
335
        title = docTitle + modifiedMarker + wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName();
336
 
337
        ((wxFrame*) wxGetApp().GetTopWindow())->SetTitle(title);
338
    }
339
}
340
 
341
// General disabler
342
void ecConfigToolView::OnUpdateDisable(wxUpdateUIEvent& event)
343
{
344
    event.Enable( FALSE );
345
}
346
 
347
void ecConfigToolView::Refresh(const wxString& macroName)
348
{
349
    ecConfigItem * pItem=wxGetApp().GetConfigToolDoc()->Find(macroName);
350
 
351
    if (pItem) // will be NULL if item has been removed
352
    {
353
        pItem->ConvertFromCdl();
354
 
355
        if (wxGetApp().GetTreeCtrl())
356
            pItem->UpdateTreeItem(* wxGetApp().GetTreeCtrl());
357
 
358
        // Update the cell contents.
359
        if (wxGetApp().GetMainFrame() && wxGetApp().GetMainFrame()->GetValueWindow())
360
        {
361
            wxRect rect = wxGetApp().GetMainFrame()->GetValueWindow()->GetItemRect(pItem);
362
            wxGetApp().GetMainFrame()->GetValueWindow()->Refresh(TRUE, & rect);
363
        }
364
    }
365
}
366
 
367
void ecConfigToolView::Refresh (wxTreeItemId h)
368
{
369
    if(h)
370
    {
371
        // TODO Not sure if we need this
372
#if 0
373
        AdjustItemImage(h);
374
        // Invalidate the labels of the affected items
375
        CRect rect;
376
        GetItemRect(h, rect, TRUE );
377
        rect.left+=m_TreeXOffsetAdjustment;
378
        InvalidateRect(rect);
379
        // Do the same for the cell view
380
        CRect rcBuddyClient;
381
        CConfigTool::GetCellView()->GetClientRect(rcBuddyClient);
382
        rect.left=rcBuddyClient.left;
383
        rect.right=rcBuddyClient.right;
384
        CConfigTool::GetCellView()->InvalidateRect(rect);
385
#endif
386
    }
387
}
388
 
389
ecConfigItem *ecConfigToolView::DoFind(const wxString& what, wxWindow* parent)
390
{
391
    ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
392
    if (!pDoc)
393
        return NULL;
394
#if wxCHECK_VERSION(2, 6, 0)
395
    int nCount = pDoc->GetItems().GetCount();
396
#else
397
    int nCount = pDoc->GetItems().Number();
398
#endif
399
 
400
    // static LPCTSTR arWhereImage[]={_T("name"),_T("macro"),_T("description string"),_T("current value"),_T("default value")};
401
 
402
    wxString strFind(what);
403
 
404
    if(! wxGetApp().GetSettings().m_findMatchCase)
405
    {
406
        strFind.MakeLower();
407
    }
408
 
409
    wxTreeItemId h = wxGetApp().GetTreeCtrl()->GetSelection();
410
 
411
    int nItem;
412
    if(!h){
413
        nItem=0;
414
    } else {
415
        for (nItem=nCount-1;nItem>=0;--nItem) {
416
            if(h==pDoc->GetItem(nItem)->GetTreeItem())
417
            {
418
                break;
419
            }
420
        }
421
        wxASSERT(nItem>=0);
422
    }
423
 
424
    ecConfigItem *pItem = NULL;
425
 
426
    int i;
427
    for (i=0 ; i < nCount ; i++)
428
    {
429
        if(wxGetApp().GetSettings().m_findDirection)
430
        {
431
            nItem=(nItem+1)%nCount;
432
        } else {
433
            nItem=(nCount+nItem-1)%nCount;
434
        }
435
        pItem = pDoc->GetItem(nItem);
436
 
437
        ecWhereType where = ecConfigItem::WhereStringToType(wxGetApp().GetSettings().m_findSearchWhat);
438
 
439
        wxString strName (pItem->StringValue(where));
440
 
441
        if (!wxGetApp().GetSettings().m_findMatchCase)
442
        {
443
            strName.MakeLower();
444
        }
445
 
446
        int nIndex = strName.Find(strFind);
447
        if(-1!=nIndex)
448
        {
449
            if (wxGetApp().GetSettings().m_findMatchWholeWord)
450
            {
451
                // Enforce whole-word semantics: to left and right
452
                if(nIndex>0 && IsWordChar(strName[(unsigned) (nIndex-1)])){
453
                    continue;
454
                }
455
                nIndex += strFind.Length();
456
                if (nIndex < strName.Length() && IsWordChar(strName[(unsigned) nIndex])){
457
                    continue;
458
                }
459
            }
460
            break;
461
        }
462
    }
463
 
464
    if (i < nCount)
465
    {
466
        if(m_expandedForFind)
467
        {
468
            wxGetApp().GetTreeCtrl()->Collapse(m_expandedForFind);
469
        }
470
 
471
        wxTreeItemId h=pItem->GetTreeItem();
472
        // Is h visible?
473
 
474
        wxTreeItemId hv;
475
 
476
        for(hv=wxGetApp().GetTreeCtrl()->GetFirstVisibleItem();hv;hv=wxGetApp().GetTreeCtrl()->GetNextVisible(hv))
477
        {
478
            if(hv==h)
479
            {
480
                break;
481
            }
482
        }
483
 
484
#if wxCHECK_VERSION(2, 6, 0)
485
        if (!hv.IsOk())
486
#else
487
        if (0==hv)
488
#endif
489
        {
490
            // we want to record the highest unexpanded item
491
            for(hv=wxGetApp().GetTreeCtrl()->GetItemParent(h);hv;hv=wxGetApp().GetTreeCtrl()->GetItemParent(hv))
492
            {
493
                if (!wxGetApp().GetTreeCtrl()->IsExpanded( hv))
494
                {
495
                    m_expandedForFind = hv;
496
                }
497
            }
498
        }
499
        wxGetApp().GetTreeCtrl()->EnsureVisible(h);
500
        wxGetApp().GetTreeCtrl()->SelectItem(h);
501
 
502
    } else
503
    {
504
        wxString msg;
505
        msg.Printf(_("Cannot find '%s' in %s"), (const wxChar*) what, (const wxChar*) wxGetApp().GetSettings().m_findSearchWhat );
506
        wxMessageBox(msg, _("Find"), wxOK|wxICON_INFORMATION, parent);
507
    }
508
 
509
    return pItem;
510
}
511
 
512
bool ecConfigToolView::IsWordChar(wxChar c)
513
{
514
  return wxIsalnum(c) || wxT('_')==c;
515
}
516
 
517
 

powered by: WebSVN 2.1.0

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