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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [configtree.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, 2008, 2009 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
// configtree.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians, jld
29
// Date:        2000/08/24
30
// Version:     $Id: configtree.cpp,v 1.8 2001/04/24 14:39:13 julians Exp $
31
// Purpose:
32
// Description: Implementation file for ecConfigTreeCtrl
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 "configtree.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 "wx/cshelp.h"
62
 
63
// Include XPM icons
64
#if !defined(__WXMSW__)
65
#include "bitmaps/closedfolder.xpm"
66
#include "bitmaps/closedfolder_dis.xpm"
67
#include "bitmaps/package_closed.xpm"
68
#include "bitmaps/package_closed_dis.xpm"
69
#include "bitmaps/package_open.xpm"
70
#include "bitmaps/package_open_dis.xpm"
71
#include "bitmaps/checked.xpm"
72
#include "bitmaps/checked_dis.xpm"
73
#include "bitmaps/unchecked.xpm"
74
#include "bitmaps/unchecked_dis.xpm"
75
#include "bitmaps/integer.xpm"
76
#include "bitmaps/integer_dis.xpm"
77
#include "bitmaps/integer2.xpm"
78
#include "bitmaps/integer2_dis.xpm"
79
#include "bitmaps/enumerated.xpm"
80
#include "bitmaps/enumerated_dis.xpm"
81
#include "bitmaps/radioon.xpm"
82
#include "bitmaps/radioon_dis.xpm"
83
#include "bitmaps/radiooff.xpm"
84
#include "bitmaps/radiooff_dis.xpm"
85
#include "bitmaps/text.xpm"
86
#include "bitmaps/text_dis.xpm"
87
#endif
88
 
89
#include "configtree.h"
90
#include "configpropdlg.h"
91
#include "configtooldoc.h"
92
#include "configtoolview.h"
93
 
94
/*
95
 * ecConfigTreeCtrl
96
 */
97
 
98
IMPLEMENT_CLASS(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)
99
 
100
BEGIN_EVENT_TABLE(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)
101
    EVT_MOUSE_EVENTS(ecConfigTreeCtrl::OnMouseEvent)
102
    EVT_CHAR(ecConfigTreeCtrl::OnKeyDown)
103
    EVT_TREE_SEL_CHANGED(-1, ecConfigTreeCtrl::OnSelChanged)
104
    EVT_HELP(-1, ecConfigTreeCtrl::OnHelp)
105
END_EVENT_TABLE()
106
 
107
ecConfigTreeCtrl::ecConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
108
                                   const wxSize& sz, long style):
109
wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style)
110
{
111
    LoadIcons();
112
 
113
    m_propertiesMenu = new wxMenu;
114
 
115
    m_propertiesMenu->Append(ecID_WHATS_THIS, _("&What's This?"));
116
    m_propertiesMenu->AppendSeparator();
117
    m_propertiesMenu->Append(ecID_TREE_PROPERTIES, _("P&roperties"));
118
    m_propertiesMenu->Append(ecID_TREE_RESTORE_DEFAULTS, _("Restore &Defaults"));
119
    m_propertiesMenu->Append(ecID_TREE_VISIT_DOC, _("Visit Documentation"));
120
    m_propertiesMenu->Append(ecID_TREE_VIEW_HEADER, _("View Header"));
121
    m_propertiesMenu->AppendSeparator();
122
    m_propertiesMenu->Append(ecID_TREE_UNLOAD_PACKAGE, _("&Unload Package..."));
123
 
124
    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
125
         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")).Ok())
126
    {
127
        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")));
128
    }
129
}
130
 
131
// Load the icons and initialize the tree
132
void ecConfigTreeCtrl::LoadIcons()
133
{
134
    m_imageList = new wxImageList(16, 16, TRUE);
135
    m_iconDB.SetImageList(m_imageList);
136
    SetImageList(m_imageList);
137
 
138
    // We associate names and states so we can easily get the appropriate
139
    // icon for a given tree item. This gets used in ecConfigItem::UpdateTreeIcon.
140
 
141
    m_iconDB.AddInfo("Container", wxICON(closedfolder), 0, TRUE);
142
    m_iconDB.AddInfo("Container", wxICON(closedfolder_dis), 0, FALSE);
143
 
144
    m_iconDB.AddInfo("Package", wxICON(package_open), 0, TRUE);
145
    m_iconDB.AddInfo("Package", wxICON(package_open_dis), 0, FALSE);
146
 
147
    m_iconDB.AddInfo("Checkbox", wxICON(checked), 0, TRUE);
148
    m_iconDB.AddInfo("Checkbox", wxICON(checked_dis), 0, FALSE);
149
    m_iconDB.AddInfo("Checkbox", wxICON(unchecked), 1, TRUE);
150
    m_iconDB.AddInfo("Checkbox", wxICON(unchecked_dis), 1, FALSE);
151
 
152
    m_iconDB.AddInfo("Radiobox", wxICON(radioon), 0, TRUE);
153
    m_iconDB.AddInfo("Radiobox", wxICON(radioon_dis), 0, FALSE);
154
    m_iconDB.AddInfo("Radiobox", wxICON(radiooff), 1, TRUE);
155
    m_iconDB.AddInfo("Radiobox", wxICON(radiooff_dis), 1, FALSE);
156
 
157
    m_iconDB.AddInfo("Text", wxICON(text), 0, TRUE);
158
    m_iconDB.AddInfo("Text", wxICON(text_dis), 0, FALSE);
159
 
160
    m_iconDB.AddInfo("Enumerated", wxICON(enumerated), 0, TRUE);
161
    m_iconDB.AddInfo("Enumerated", wxICON(enumerated_dis), 0, FALSE);
162
 
163
    m_iconDB.AddInfo("Integer", wxICON(integer), 0, TRUE);
164
    m_iconDB.AddInfo("Integer", wxICON(integer_dis), 0, FALSE);
165
}
166
 
167
ecConfigTreeCtrl::~ecConfigTreeCtrl()
168
{
169
    delete m_propertiesMenu;
170
 
171
    SetImageList(NULL);
172
    delete m_imageList;
173
}
174
 
175
void ecConfigTreeCtrl::OnSelChanged(wxTreeEvent& event)
176
{
177
    ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
178
    if (doc)
179
    {
180
        ecConfigToolHint hint(NULL, ecSelChanged);
181
        doc->UpdateAllViews(NULL, & hint);
182
    }
183
}
184
 
185
void ecConfigTreeCtrl::OnMouseEvent(wxMouseEvent& event)
186
{
187
    int flags = 0;
188
    wxTreeItemId item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
189
 
190
#if wxCHECK_VERSION(2, 6, 0)
191
    if (!item.IsOk())
192
#else
193
    if (item == 0 || !item.IsOk())
194
#endif
195
    {
196
        if (event.RightDown())
197
            PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
198
        return;
199
    }
200
 
201
    if (event.LeftDown())
202
    {
203
        if (flags & wxTREE_HITTEST_ONITEMICON)
204
        {
205
            ecTreeItemData* data = (ecTreeItemData*) GetItemData(item);
206
            data->GetConfigItem()->OnIconLeftDown(* this);
207
        }
208
    }
209
    else if (event.RightDown())
210
    {
211
        if ((flags & wxTREE_HITTEST_ONITEMBUTTON) ||
212
            (flags & wxTREE_HITTEST_ONITEMICON) ||
213
            (flags & wxTREE_HITTEST_ONITEMINDENT) ||
214
            (flags & wxTREE_HITTEST_ONITEMLABEL))
215
        {
216
            SelectItem(item);
217
            GetPropertiesMenu()->SetClientData((void*) TRUE);
218
            PopupMenu(GetPropertiesMenu(), event.GetX(), event.GetY());
219
        }
220
        else
221
        {
222
            wxGetApp().GetWhatsThisMenu()->SetClientData((void*) FALSE);
223
            PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
224
        }
225
        return;
226
    }
227
    event.Skip();
228
}
229
 
230
void ecConfigTreeCtrl::OnKeyDown(wxKeyEvent& event)
231
{
232
    wxTreeItemId id = GetSelection();
233
    if (event.GetKeyCode() == WXK_F10 && event.ShiftDown())
234
    {
235
        if (id.IsOk())
236
        {
237
            wxRect rect;
238
            if (GetBoundingRect(id, rect))
239
            {
240
                GetPropertiesMenu()->SetClientData((void*) TRUE);
241
                PopupMenu(GetPropertiesMenu(), 100, rect.GetTop() + 4);
242
            }
243
        }
244
    }
245
    else if (event.GetKeyCode() == '<')
246
    {
247
        if (id.IsOk())
248
        {
249
            ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
250
            item->BumpItem(-1);
251
        }
252
    }
253
    else if (event.GetKeyCode() == '>')
254
    {
255
        if (id.IsOk())
256
        {
257
            ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
258
            item->BumpItem(+1);
259
        }
260
    }
261
    else if (event.GetKeyCode() == WXK_SPACE)
262
    {
263
        if (id.IsOk())
264
        {
265
            ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
266
            item->BumpItem(0);
267
        }
268
    }
269
    else if (event.GetKeyCode() == WXK_RETURN && event.AltDown())
270
    {
271
        if (id.IsOk())
272
        {
273
            ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
274
 
275
            ecConfigPropertiesDialog dialog(wxGetApp().GetTopWindow(), item);
276
            dialog.SetTitle(item->GetName());
277
            dialog.ShowModal();
278
        }
279
    }
280
    else
281
    {
282
        event.Skip();
283
    }
284
}
285
 
286
// show help for this window
287
void ecConfigTreeCtrl::OnHelp(wxHelpEvent& event)
288
{
289
    wxPoint pt = ScreenToClient(event.GetPosition());
290
    int flags = 0;
291
    wxTreeItemId id = HitTest(pt, flags);
292
    wxHelpProvider *helpProvider = wxHelpProvider::Get();
293
    if ( helpProvider && id > 0)
294
    {
295
        ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
296
 
297
        if (item)
298
        {
299
            wxGetApp().GetHelpController().DisplayTextPopup(item->GetDescription(), event.GetPosition());
300
            return;
301
        }
302
    }
303
 
304
    event.Skip();
305
}
306
 
307
/*
308
* ecValueWindow
309
*/
310
 
311
IMPLEMENT_CLASS(ecValueWindow, wxTreeCompanionWindow)
312
 
313
BEGIN_EVENT_TABLE(ecValueWindow, wxTreeCompanionWindow)
314
    EVT_MOUSE_EVENTS(ecValueWindow::OnMouseEvent)
315
    EVT_SCROLLWIN(ecValueWindow::OnScroll)
316
    EVT_TREE_ITEM_EXPANDED(-1, ecValueWindow::OnExpand)
317
    EVT_TREE_ITEM_COLLAPSED(-1, ecValueWindow::OnExpand)
318
END_EVENT_TABLE()
319
 
320
ecValueWindow::ecValueWindow(wxWindow* parent, wxWindowID id,
321
                             const wxPoint& pos,
322
                             const wxSize& sz,
323
                             long style):
324
wxTreeCompanionWindow(parent, id, pos, sz, style)
325
{
326
#if wxCHECK_VERSION(2, 6, 0)
327
    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
328
#else
329
    SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_LISTBOX));
330
#endif
331
 
332
    if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
333
         wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")).Ok())
334
    {
335
        SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")));
336
    }
337
    else
338
#if wxCHECK_VERSION(2, 6, 0)
339
        SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
340
#else
341
        SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
342
#endif
343
 
344
    m_editWindow = NULL;
345
    m_configItem = NULL;
346
}
347
 
348
// Returns the rectangle which will enclose the value for this tree item
349
wxRect ecValueWindow::GetItemRect(ecConfigItem* item)
350
{
351
    if (!m_treeCtrl)
352
        return wxRect(0, 0, 0, 0);
353
 
354
    wxSize clientSize = GetClientSize();
355
    wxRect itemRect;
356
    int cy=0;
357
    wxTreeItemId h;
358
    for(h=m_treeCtrl->GetFirstVisibleItem();h.IsOk() && m_treeCtrl->IsVisible(h);h=m_treeCtrl->GetNextVisible(h))
359
    {
360
        ecTreeItemData* data = (ecTreeItemData*) m_treeCtrl->GetItemData(h);
361
        if (data->GetConfigItem() == item)
362
        {
363
            if (m_treeCtrl->GetBoundingRect(h, itemRect))
364
            {
365
                cy = itemRect.GetTop();
366
                wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
367
                return drawItemRect;
368
            }
369
            else
370
                return wxRect(0, 0, 0, 0);
371
        }
372
    }
373
    return wxRect(0, 0, 0, 0);
374
}
375
 
376
void ecValueWindow::OnMouseEvent(wxMouseEvent& event)
377
{
378
    if (event.LeftDown() && (event.GetX() > 2))
379
    {
380
        // Find if this corresponds to a tree item
381
        int flags = 0;
382
        wxTreeItemId item = m_treeCtrl->HitTest(wxPoint(4, event.GetY()), flags);
383
        if (item.IsOk())
384
        {
385
            m_treeCtrl->SelectItem(item);
386
            ecConfigItem* configItem = ((ecTreeItemData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
387
            if (configItem->CanEdit())
388
                BeginEditing(configItem);
389
            else if (m_configItem)
390
                EndEditing();
391
        }
392
    }
393
    else if (event.RightDown())
394
    {
395
        // Find if this corresponds to a tree item
396
        int flags = 0;
397
        wxTreeItemId item = m_treeCtrl->HitTest(wxPoint(4, event.GetY()), flags);
398
#if wxCHECK_VERSION(2, 6, 0)
399
        if (item.IsOk())
400
#else
401
        if (item != 0)
402
#endif
403
        {
404
                if (m_configItem)
405
                    EndEditing();
406
 
407
            ecConfigItem* configItem = ((ecTreeItemData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
408
            m_treeCtrl->SelectItem(item);
409
            ((ecConfigTreeCtrl*) m_treeCtrl)->GetPropertiesMenu()->SetClientData((void*) TRUE);
410
            PopupMenu(((ecConfigTreeCtrl*) m_treeCtrl)->GetPropertiesMenu(), event.GetX(), event.GetY());
411
        }
412
        else
413
        {
414
            wxGetApp().GetWhatsThisMenu()->SetClientData((void*) FALSE);
415
            PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
416
        }
417
    }
418
}
419
 
420
void ecValueWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect)
421
{
422
    if (m_treeCtrl)
423
    {
424
        ecConfigItem* item = ((ecTreeItemData*) m_treeCtrl->GetItemData(id))->GetConfigItem();
425
        if (!item)
426
            return;
427
        wxString text = item->GetDisplayValue();
428
 
429
        if (text.IsEmpty())
430
            return;
431
 
432
#if wxCHECK_VERSION(2, 6, 0)
433
        static wxColour normalColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
434
        static wxColour disabledColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
435
#else
436
        static wxColour normalColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
437
        static wxColour disabledColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT);
438
#endif
439
        dc.SetTextForeground( (item->GetModifiable() && (item->GetConfigType() != ecPackage)) ? normalColour : disabledColour );
440
 
441
        int textW, textH;
442
        dc.GetTextExtent(text, & textW, & textH);
443
 
444
        int x = 2;
445
        int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);
446
 
447
        dc.DrawText(text, x, y);
448
    }
449
}
450
 
451
bool ecValueWindow::BeginEditing(ecConfigItem* item)
452
{
453
    if (m_configItem)
454
        EndEditing();
455
 
456
    m_configItem = item;
457
 
458
    m_editWindow = item->CreateEditWindow(this);
459
    if (m_editWindow)
460
    {
461
        m_editWindow->Show(FALSE);
462
 
463
        item->TransferDataToWindow(m_editWindow);
464
 
465
        // Position the control
466
        PositionEditWindow();
467
 
468
        m_editWindow->Show(TRUE);
469
        m_editWindow->SetFocus();
470
 
471
        return TRUE;
472
    }
473
    else
474
    {
475
        m_configItem = NULL;
476
        return FALSE;
477
    }
478
}
479
 
480
// Position the control
481
void ecValueWindow::PositionEditWindow()
482
{
483
    if (!m_configItem || !m_editWindow)
484
        return;
485
 
486
    // Position the control
487
    wxSize clientSize = GetClientSize();
488
    wxRect itemRect;
489
    m_treeCtrl->GetBoundingRect(m_configItem->GetTreeItem(), itemRect);
490
 
491
    wxSize sz = m_editWindow->GetSize();
492
 
493
    // m_editWindow->SetSize(2, itemRect.y+1, clientSize.x, itemRect.GetHeight() /* -2 */);
494
    m_editWindow->SetSize(0, itemRect.y, clientSize.x, sz.y);
495
}
496
 
497
bool ecValueWindow::EndEditing()
498
{
499
    if (m_configItem)
500
    {
501
        if (m_editWindow && !wxGetApp().GetValuesLocked())
502
            m_configItem->TransferDataFromWindow(m_editWindow);
503
        m_configItem = NULL;
504
    }
505
 
506
    if (m_editWindow)
507
    {
508
        delete m_editWindow;
509
        m_editWindow = NULL;
510
    }
511
 
512
    return TRUE;
513
}
514
 
515
void ecValueWindow::OnScroll(wxScrollWinEvent& event)
516
{
517
    wxTreeCompanionWindow::OnScroll(event);
518
 
519
    PositionEditWindow();
520
}
521
 
522
void ecValueWindow::OnExpand(wxTreeEvent& event)
523
{
524
    wxTreeCompanionWindow::OnExpand(event);
525
 
526
    EndEditing();
527
}
528
 
529
/*
530
* wxIconStateInfo
531
*/
532
 
533
wxIconStateInfo::wxIconStateInfo(const wxString& name)
534
{
535
    m_maxStates = 0;
536
    m_name = name;
537
    int i;
538
    for (i = 0; i < wxMAX_ICON_STATES; i++)
539
        m_states[i] = 0;
540
}
541
 
542
int wxIconStateInfo::GetIconId(int state, bool enabled) const
543
{
544
    wxASSERT ( state < (wxMAX_ICON_STATES * 2) );
545
    wxASSERT ( state < m_maxStates );
546
 
547
    return m_states[state * 2 + (enabled ? 0 : 1)];
548
}
549
 
550
void wxIconStateInfo::SetIconId(int state, bool enabled, int iconId)
551
{
552
    wxASSERT ( state < (wxMAX_ICON_STATES * 2) );
553
    if (state+1 > m_maxStates)
554
        m_maxStates = state+1;
555
 
556
    m_states[state * 2 + (enabled ? 0 : 1)] = iconId;
557
}
558
 
559
/*
560
* wxIconStateInfoDb
561
* Contains a list of wxIconStateInfos
562
*/
563
 
564
wxIconStateInfoDB::wxIconStateInfoDB(wxImageList* imageList)
565
{
566
    m_imageList = imageList;
567
    DeleteContents(TRUE);
568
}
569
 
570
void wxIconStateInfoDB::AppendInfo(wxIconStateInfo* info)
571
{
572
    Append(info);
573
}
574
 
575
// Easy way of initialising both the image list and the
576
// info db. It will generate image ids itself while appending the icon.
577
bool wxIconStateInfoDB::AddInfo(const wxString& name, const wxIcon& icon, int state, bool enabled)
578
{
579
    wxASSERT (m_imageList != NULL);
580
 
581
    wxIconStateInfo* info = FindInfo(name);
582
    if (!info)
583
    {
584
        info = new wxIconStateInfo(name);
585
        Append(info);
586
    }
587
    info->SetIconId(state, enabled, m_imageList->Add(icon));
588
    return TRUE;
589
}
590
 
591
wxIconStateInfo* wxIconStateInfoDB::FindInfo(const wxString& name) const
592
{
593
#if wxCHECK_VERSION(2, 6, 0)
594
    wxNode* node = GetFirst();
595
    while (node)
596
    {
597
        wxIconStateInfo* info = (wxIconStateInfo*) node->GetData();
598
        if (info->GetName() == name)
599
            return info;
600
        node = node->GetNext();
601
#else
602
    wxNode* node = First();
603
    while (node)
604
    {
605
        wxIconStateInfo* info = (wxIconStateInfo*) node->Data();
606
        if (info->GetName() == name)
607
            return info;
608
        node = node->Next();
609
#endif
610
    }
611
    return NULL;
612
}
613
 
614
int wxIconStateInfoDB::GetIconId(const wxString& name, int state, bool enabled) const
615
{
616
    wxIconStateInfo* info = FindInfo(name);
617
    if (!info)
618
        return -1;
619
    return info->GetIconId(state, enabled);
620
}
621
 
622
bool wxIconStateInfoDB::SetIconId(const wxString& name, int state, bool enabled, int iconId)
623
{
624
    wxIconStateInfo* info = FindInfo(name);
625
    if (!info)
626
        return FALSE;
627
    info->SetIconId(state, enabled, iconId);
628
    return TRUE;
629
}
630
 
631
#if 0
632
wxIcon wxIconStateInfoDB::GetIcon(const wxString& name, int state, bool enabled) const
633
{
634
    wxASSERT( m_imageList != NULL );
635
 
636
    wxIconStateInfo* info = FindInfo(name);
637
    if (!info)
638
        return wxNullIcon;
639
    int id = info->GetIconId(state, enabled);
640
    if (id < 0)
641
        return wxNullIcon;
642
    else
643
        return m_imageList->GetImage(id); // Doesn't exist
644
}
645
#endif
646
 
647
/*
648
* ecSplitterScrolledWindow
649
* This window holds the tree and value windows.
650
* We derive a new class mainly to intercept popup menu commands from both child windows
651
* without resorting to placing their handlers in the main frame.
652
*/
653
 
654
BEGIN_EVENT_TABLE(ecSplitterScrolledWindow, wxSplitterScrolledWindow)
655
    EVT_MENU(ecID_WHATS_THIS, ecSplitterScrolledWindow::OnWhatsThis)
656
    EVT_MENU(ecID_TREE_PROPERTIES, ecSplitterScrolledWindow::OnProperties)
657
    EVT_MENU(ecID_TREE_RESTORE_DEFAULTS, ecSplitterScrolledWindow::OnRestoreDefaults)
658
    EVT_MENU(ecID_TREE_VISIT_DOC, ecSplitterScrolledWindow::OnVisitDoc)
659
    EVT_MENU(ecID_TREE_VIEW_HEADER, ecSplitterScrolledWindow::OnViewHeader)
660
    EVT_MENU(ecID_TREE_UNLOAD_PACKAGE, ecSplitterScrolledWindow::OnUnloadPackage)
661
 
662
    EVT_UPDATE_UI(ecID_TREE_RESTORE_DEFAULTS, ecSplitterScrolledWindow::OnUpdateRestoreDefaults)
663
    EVT_UPDATE_UI(ecID_TREE_VISIT_DOC, ecSplitterScrolledWindow::OnUpdateVisitDoc)
664
    EVT_UPDATE_UI(ecID_TREE_VIEW_HEADER, ecSplitterScrolledWindow::OnUpdateViewHeader)
665
    EVT_UPDATE_UI(ecID_TREE_UNLOAD_PACKAGE, ecSplitterScrolledWindow::OnUpdateUnloadPackage)
666
END_EVENT_TABLE()
667
 
668
static bool ecIsMenuForItem(wxCommandEvent& event)
669
{
670
    wxObject* obj = event.GetEventObject();
671
    wxMenu* menu = NULL;
672
 
673
    if (obj->IsKindOf(CLASSINFO(wxMenu)))
674
    {
675
        // Menu has some client data which tells us if the menu was clicked over an item
676
        // or not
677
        menu = (wxMenu*) obj;
678
        return (bool) (menu->GetClientData() != 0) ;
679
    }
680
    else
681
        return FALSE;
682
}
683
 
684
void ecSplitterScrolledWindow::OnWhatsThis(wxCommandEvent& event)
685
{
686
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
687
    wxASSERT (treeCtrl != NULL) ;
688
 
689
    wxTreeItemId id = treeCtrl->GetSelection();
690
#if wxCHECK_VERSION(2, 6, 0)
691
    if (id.IsOk() && ecIsMenuForItem(event))
692
#else
693
    if (id != 0 && ecIsMenuForItem(event))
694
#endif
695
    {
696
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
697
 
698
        wxPoint pt = wxGetMousePosition();
699
        wxString msg;
700
        msg.Printf("Popping at %d x %d", pt.x, pt.y);
701
        wxLogDebug(msg);
702
 
703
        wxGetApp().GetHelpController().DisplayTextPopup(item->GetDescription(), wxGetMousePosition());
704
    }
705
    else
706
        event.Skip();
707
}
708
 
709
void ecSplitterScrolledWindow::OnProperties(wxCommandEvent& event)
710
{
711
    wxObject* obj = event.GetEventObject();
712
    wxMenu* menu = NULL;
713
 
714
    if (obj->IsKindOf(CLASSINFO(wxMenu)))
715
    {
716
        // Menu has some client data which tells us if the menu was clicked over an item
717
        // or not
718
        menu = (wxMenu*) obj;
719
    }
720
 
721
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
722
    wxASSERT (treeCtrl != NULL) ;
723
 
724
    wxTreeItemId id = treeCtrl->GetSelection();
725
#if wxCHECK_VERSION(2, 6, 0)
726
    if (id.IsOk() && ecIsMenuForItem(event))
727
#else
728
    if (id != 0 && ecIsMenuForItem(event))
729
#endif
730
    {
731
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
732
 
733
        ecConfigPropertiesDialog dialog(wxGetApp().GetTopWindow(), item);
734
        dialog.SetTitle(item->GetName());
735
        dialog.ShowModal();
736
    }
737
}
738
 
739
void ecSplitterScrolledWindow::OnRestoreDefaults(wxCommandEvent& event)
740
{
741
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
742
    wxASSERT (treeCtrl != NULL) ;
743
 
744
    wxTreeItemId id = treeCtrl->GetSelection();
745
#if wxCHECK_VERSION(2, 6, 0)
746
    if (id.IsOk() && ecIsMenuForItem(event))
747
#else
748
    if (id != 0 && ecIsMenuForItem(event))
749
#endif
750
    {
751
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
752
        if (item->HasModifiedChildren())
753
        {
754
            int ans = wxMessageBox(_("Restore defaults for nested items?"), wxGetApp().GetSettings().GetAppName(), wxYES_NO|wxCANCEL|wxICON_QUESTION);
755
            switch (ans)
756
            {
757
            case wxYES:
758
                RestoreDefault(id, TRUE);
759
                break;
760
            case wxNO:
761
                RestoreDefault(id, FALSE);
762
                break;
763
            case wxCANCEL:
764
                break;
765
            default:
766
                wxASSERT(FALSE);
767
                break;
768
            }
769
        }
770
        else
771
        {
772
            RestoreDefault(id, FALSE);
773
        }
774
        // current values may have changed so refresh the other views
775
        wxGetApp().GetConfigToolDoc ()->UpdateFailingRuleCount ();
776
 
777
        if (item->GetOptionType () != ecOptionTypeNone)
778
        {
779
            ecConfigToolHint hint(item, ecValueChanged);
780
            wxGetApp().GetConfigToolDoc ()->UpdateAllViews (NULL, & hint);
781
        }
782
    }
783
}
784
 
785
void ecSplitterScrolledWindow::RestoreDefault(wxTreeItemId h, bool bRecurse /* = FALSE */, bool bTopLevel /* = TRUE */)
786
{
787
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
788
    wxASSERT (treeCtrl != NULL) ;
789
 
790
    ecConfigItem* ti = ((ecTreeItemData*) treeCtrl->GetItemData(h))->GetConfigItem();
791
 
792
    const CdlValuable valuable = ti->GetCdlValuable();
793
 
794
    if (valuable && (CdlValueFlavor_None != valuable->get_flavor ())) // skip the root node and nodes without a value
795
        valuable->set_source (CdlValueSource_Default);
796
    treeCtrl->SetItemText (h, ti->GetItemNameOrMacro ()); // remove asterisk in control view
797
 
798
    if (bTopLevel && ti->HasRadio ()) // if user-specified item is a radio button
799
    {
800
        for (ecConfigItem * pItem = ti->FirstRadio (); pItem; pItem = pItem->NextRadio ())
801
        {
802
            if (ti != pItem)
803
            {
804
                const CdlValuable valuable = pItem->GetCdlValuable();
805
                wxASSERT (valuable);
806
                valuable->set_source (CdlValueSource_Default); // restore default for each sibling radio button
807
                treeCtrl->SetItemText (pItem->GetTreeItem(), pItem->GetItemNameOrMacro ()); // remove asterisk in control view
808
            }
809
 
810
        }
811
    }
812
 
813
    if (bRecurse)
814
    {
815
#if wxCHECK_VERSION(2, 6, 0)
816
                wxTreeItemIdValue cookie;
817
#else
818
        long cookie;
819
#endif
820
        for (h = treeCtrl->GetFirstChild(h, cookie); h; h = treeCtrl->GetNextSibling(h))
821
        {
822
            RestoreDefault (h, TRUE, FALSE);
823
        }
824
    }
825
}
826
 
827
void ecSplitterScrolledWindow::OnVisitDoc(wxCommandEvent& event)
828
{
829
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
830
    wxASSERT (treeCtrl != NULL) ;
831
 
832
    wxTreeItemId id = treeCtrl->GetSelection();
833
#if wxCHECK_VERSION(2, 6, 0)
834
    if (id.IsOk() && ecIsMenuForItem(event))
835
#else
836
    if (id != 0 && ecIsMenuForItem(event))
837
#endif
838
    {
839
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
840
 
841
        item->ViewURL();
842
    }
843
    else
844
        event.Skip();
845
}
846
 
847
void ecSplitterScrolledWindow::OnViewHeader(wxCommandEvent& event)
848
{
849
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
850
    wxASSERT (treeCtrl != NULL) ;
851
 
852
    wxTreeItemId id = treeCtrl->GetSelection();
853
#if wxCHECK_VERSION(2, 6, 0)
854
    if (id.IsOk() && ecIsMenuForItem(event))
855
#else
856
    if (id != 0 && ecIsMenuForItem(event))
857
#endif
858
    {
859
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
860
 
861
        item->ViewHeader();
862
    }
863
    else
864
        event.Skip();
865
}
866
 
867
void ecSplitterScrolledWindow::OnUnloadPackage(wxCommandEvent& event)
868
{
869
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
870
    wxASSERT (treeCtrl != NULL) ;
871
 
872
    wxTreeItemId id = treeCtrl->GetSelection();
873
#if wxCHECK_VERSION(2, 6, 0)
874
    if (id.IsOk())
875
#else
876
    if (id != 0)
877
#endif
878
    {
879
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
880
 
881
        if (wxYES == wxMessageBox(_("Are you sure you wish to unload this package?"), wxGetApp().GetSettings().GetAppName(),
882
                wxYES_NO|wxICON_QUESTION))
883
        {
884
            item->Unload();
885
            delete item;
886
            wxGetApp().GetConfigToolDoc()->RegenerateData();
887
        }
888
    }
889
}
890
 
891
void ecSplitterScrolledWindow::OnUpdateRestoreDefaults(wxUpdateUIEvent& event)
892
{
893
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
894
    wxASSERT (treeCtrl != NULL) ;
895
 
896
    wxTreeItemId id = treeCtrl->GetSelection();
897
#if wxCHECK_VERSION(2, 6, 0)
898
    if (id.IsOk())
899
#else
900
    if (id != 0)
901
#endif
902
    {
903
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
904
 
905
        event.Enable( IsChanged(id, TRUE ) );
906
    }
907
}
908
 
909
void ecSplitterScrolledWindow::OnUpdateVisitDoc(wxUpdateUIEvent& event)
910
{
911
    event.Enable( TRUE );
912
}
913
 
914
void ecSplitterScrolledWindow::OnUpdateViewHeader(wxUpdateUIEvent& event)
915
{
916
    ecConfigToolDoc *pDoc=wxGetApp().GetConfigToolDoc();
917
    event.Enable( pDoc && !pDoc->GetBuildTree().IsEmpty() ) ;
918
}
919
 
920
void ecSplitterScrolledWindow::OnUpdateUnloadPackage(wxUpdateUIEvent& event)
921
{
922
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
923
    wxASSERT (treeCtrl != NULL) ;
924
 
925
    wxTreeItemId id = treeCtrl->GetSelection();
926
#if wxCHECK_VERSION(2, 6, 0)
927
    if (id.IsOk())
928
#else
929
    if (id != 0)
930
#endif
931
    {
932
        ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
933
 
934
        event.Enable( item->IsPackage() &&
935
            !wxGetApp().GetConfigToolDoc()->GetCdlPkgData()->
936
            is_hardware_package (ecUtils::UnicodeToStdStr (item->GetMacro())));
937
    }
938
}
939
 
940
bool ecSplitterScrolledWindow::IsChanged(wxTreeItemId id, bool bRecurse)
941
{
942
    ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
943
    wxASSERT (treeCtrl != NULL) ;
944
 
945
    ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
946
    bool rc = item->Modified ();
947
 
948
    if(!rc && bRecurse)
949
    {
950
#if wxCHECK_VERSION(2, 6, 0)
951
                wxTreeItemIdValue cookie;
952
#else
953
        long cookie;
954
#endif
955
        for (id=treeCtrl->GetFirstChild(id, cookie);id;id=treeCtrl->GetNextSibling(id))
956
        {
957
            if (IsChanged(id,TRUE))
958
            {
959
                rc=TRUE;
960
                break;
961
            }
962
        }
963
    }
964
    return rc;
965
}

powered by: WebSVN 2.1.0

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