OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [standalone/] [wxwin/] [configtoolview.cpp] - Blame information for rev 502

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

powered by: WebSVN 2.1.0

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