1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
33 // Version: $Id: configtree.cpp,v 1.8 2001/04/24 14:39:13 julians Exp $
35 // Description: Implementation file for ecConfigTreeCtrl
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "configtree.h"
57 // Includes other headers for precompiled compilation
64 #include "wx/cshelp.h"
67 #if !defined(__WXMSW__)
68 #include "bitmaps/closedfolder.xpm"
69 #include "bitmaps/closedfolder_dis.xpm"
70 #include "bitmaps/package_closed.xpm"
71 #include "bitmaps/package_closed_dis.xpm"
72 #include "bitmaps/package_open.xpm"
73 #include "bitmaps/package_open_dis.xpm"
74 #include "bitmaps/checked.xpm"
75 #include "bitmaps/checked_dis.xpm"
76 #include "bitmaps/unchecked.xpm"
77 #include "bitmaps/unchecked_dis.xpm"
78 #include "bitmaps/integer.xpm"
79 #include "bitmaps/integer_dis.xpm"
80 #include "bitmaps/integer2.xpm"
81 #include "bitmaps/integer2_dis.xpm"
82 #include "bitmaps/enumerated.xpm"
83 #include "bitmaps/enumerated_dis.xpm"
84 #include "bitmaps/radioon.xpm"
85 #include "bitmaps/radioon_dis.xpm"
86 #include "bitmaps/radiooff.xpm"
87 #include "bitmaps/radiooff_dis.xpm"
88 #include "bitmaps/text.xpm"
89 #include "bitmaps/text_dis.xpm"
92 #include "configtree.h"
93 #include "configpropdlg.h"
94 #include "configtooldoc.h"
95 #include "configtoolview.h"
101 IMPLEMENT_CLASS(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)
103 BEGIN_EVENT_TABLE(ecConfigTreeCtrl, wxRemotelyScrolledTreeCtrl)
104 EVT_PAINT(ecConfigTreeCtrl::OnPaint)
105 EVT_MOUSE_EVENTS(ecConfigTreeCtrl::OnMouseEvent)
106 EVT_CHAR(ecConfigTreeCtrl::OnKeyDown)
107 EVT_TREE_SEL_CHANGED(-1, ecConfigTreeCtrl::OnSelChanged)
108 EVT_TREE_ITEM_EXPANDED(-1, ecConfigTreeCtrl::OnCollapseExpand)
109 EVT_TREE_ITEM_COLLAPSED(-1, ecConfigTreeCtrl::OnCollapseExpand)
110 EVT_HELP(-1, ecConfigTreeCtrl::OnHelp)
113 ecConfigTreeCtrl::ecConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
114 const wxSize& sz, long style):
115 wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style)
119 m_propertiesMenu = new wxMenu;
121 m_propertiesMenu->Append(ecID_WHATS_THIS, _("&What's This?"));
122 m_propertiesMenu->AppendSeparator();
123 m_propertiesMenu->Append(ecID_TREE_PROPERTIES, _("P&roperties"));
124 m_propertiesMenu->Append(ecID_TREE_RESTORE_DEFAULTS, _("Restore &Defaults"));
125 m_propertiesMenu->Append(ecID_TREE_VISIT_DOC, _("Visit Documentation"));
126 m_propertiesMenu->Append(ecID_TREE_VIEW_HEADER, _("View Header"));
127 m_propertiesMenu->AppendSeparator();
128 m_propertiesMenu->Append(ecID_TREE_UNLOAD_PACKAGE, _("&Unload Package..."));
130 if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
131 wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")).Ok())
133 SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")));
137 // Load the icons and initialize the tree
138 void ecConfigTreeCtrl::LoadIcons()
140 m_imageList = new wxImageList(16, 16, TRUE);
141 m_iconDB.SetImageList(m_imageList);
142 SetImageList(m_imageList);
144 // We associate names and states so we can easily get the appropriate
145 // icon for a given tree item. This gets used in ecConfigItem::UpdateTreeIcon.
147 m_iconDB.AddInfo("Container", wxICON(closedfolder), 0, TRUE);
148 m_iconDB.AddInfo("Container", wxICON(closedfolder_dis), 0, FALSE);
150 m_iconDB.AddInfo("Package", wxICON(package_open), 0, TRUE);
151 m_iconDB.AddInfo("Package", wxICON(package_open_dis), 0, FALSE);
153 m_iconDB.AddInfo("Checkbox", wxICON(checked), 0, TRUE);
154 m_iconDB.AddInfo("Checkbox", wxICON(checked_dis), 0, FALSE);
155 m_iconDB.AddInfo("Checkbox", wxICON(unchecked), 1, TRUE);
156 m_iconDB.AddInfo("Checkbox", wxICON(unchecked_dis), 1, FALSE);
158 m_iconDB.AddInfo("Radiobox", wxICON(radioon), 0, TRUE);
159 m_iconDB.AddInfo("Radiobox", wxICON(radioon_dis), 0, FALSE);
160 m_iconDB.AddInfo("Radiobox", wxICON(radiooff), 1, TRUE);
161 m_iconDB.AddInfo("Radiobox", wxICON(radiooff_dis), 1, FALSE);
163 m_iconDB.AddInfo("Text", wxICON(text), 0, TRUE);
164 m_iconDB.AddInfo("Text", wxICON(text_dis), 0, FALSE);
166 m_iconDB.AddInfo("Enumerated", wxICON(enumerated), 0, TRUE);
167 m_iconDB.AddInfo("Enumerated", wxICON(enumerated_dis), 0, FALSE);
169 m_iconDB.AddInfo("Integer", wxICON(integer), 0, TRUE);
170 m_iconDB.AddInfo("Integer", wxICON(integer_dis), 0, FALSE);
173 // Add some dummy items
174 ecConfigItem* item = NULL;
175 wxTreeItemId rootId = AddRoot(_(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(NULL, _("Configuration"), ecContainer)));
177 item->SetTreeItem(rootId);
178 item->UpdateTreeItem(* this);
180 wxTreeItemId childId1 = AppendItem(rootId, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("My Package"), ecPackage, ecFlavorData, ecString)));
181 item->SetTreeItem(childId1);
182 item->GetValue() = _("v1_4_1");
183 item->UpdateTreeItem(* this);
185 wxTreeItemId childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 1"), ecOption, ecFlavorData, ecString)));
186 item->SetTreeItem(childId2);
187 item->GetValue() = _("The value for this option");
188 item->UpdateTreeItem(* this);
190 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 2"), ecOption, ecFlavorData, ecLong)));
191 item->SetTreeItem(childId2);
192 item->GetValue() = (long) 176343;
193 item->UpdateTreeItem(* this);
195 childId2 = AppendItem(childId2, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 3"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, TRUE, ecHintCheck)));
196 item->SetTreeItem(childId2);
197 item->GetValue() = (bool) TRUE;
198 item->UpdateTreeItem(* this);
200 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 4"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, FALSE, ecHintCheck)));
201 item->SetTreeItem(childId2);
202 item->UpdateTreeItem(* this);
204 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 5"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, TRUE, ecHintRadio)));
205 item->SetTreeItem(childId2);
206 item->UpdateTreeItem(* this);
208 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 6"), ecOption, ecFlavorBool, ecOptionTypeNone, TRUE, FALSE, ecHintRadio)));
209 item->SetTreeItem(childId2);
210 item->GetValue() = (bool) TRUE ;
211 item->UpdateTreeItem(* this);
214 childId1 = AppendItem(rootId, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("My Container"), ecContainer)));
215 item->SetTreeItem(childId1);
216 item->UpdateTreeItem(* this);
218 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 1"), ecOption, ecFlavorData, ecString, FALSE)));
219 item->SetTreeItem(childId2);
220 item->GetValue() = _("The value for this option");
221 item->UpdateTreeItem(* this);
223 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 2"), ecOption, ecFlavorData, ecLong, FALSE)));
224 item->SetTreeItem(childId2);
225 item->GetValue() = (long) 176343;
226 item->UpdateTreeItem(* this);
228 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 3"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, TRUE, ecHintCheck)));
229 item->SetTreeItem(childId2);
230 item->GetValue() = (bool) TRUE;
231 item->UpdateTreeItem(* this);
233 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 4"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, FALSE, ecHintCheck)));
234 item->SetTreeItem(childId2);
235 item->UpdateTreeItem(* this);
237 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 5"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, TRUE, ecHintRadio)));
238 item->SetTreeItem(childId2);
239 item->UpdateTreeItem(* this);
241 childId2 = AppendItem(childId1, _(""), -1, -1, new ecTreeItemData(item = new ecConfigItem(item, _("Option 6"), ecOption, ecFlavorBool, ecOptionTypeNone, FALSE, FALSE, ecHintRadio)));
242 item->SetTreeItem(childId2);
243 item->GetValue() = (bool) TRUE ;
244 item->UpdateTreeItem(* this);
250 ecConfigTreeCtrl::~ecConfigTreeCtrl()
252 delete m_propertiesMenu;
258 // Draw the lines on top of the tree
259 void ecConfigTreeCtrl::OnPaint(wxPaintEvent& event)
263 wxTreeCtrl::OnPaint(event);
265 // Reset the device origin since it may have been set
266 dc.SetDeviceOrigin(0, 0);
268 wxSize sz = GetClientSize();
270 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
272 dc.SetBrush(* wxTRANSPARENT_BRUSH);
274 wxSize clientSize = GetClientSize();
277 wxTreeItemId h, lastH;
278 for(h=GetFirstVisibleItem();h;h=GetNextVisible(h))
280 if (GetBoundingRect(h, itemRect))
282 cy = itemRect.GetTop();
283 dc.DrawLine(0, cy, clientSize.x, cy);
288 if (lastH && lastH.IsOk() && GetBoundingRect(lastH, itemRect))
290 cy = itemRect.GetBottom();
291 dc.DrawLine(0, cy, clientSize.x, cy);
295 void ecConfigTreeCtrl::OnSelChanged(wxTreeEvent& event)
297 ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
300 ecConfigToolHint hint(NULL, ecSelChanged);
301 doc->UpdateAllViews(NULL, & hint);
305 void ecConfigTreeCtrl::OnMouseEvent(wxMouseEvent& event)
308 wxTreeItemId item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
310 if (item == 0 || !item.IsOk())
312 if (event.RightDown())
313 PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
317 if (event.LeftDown())
319 if (flags & wxTREE_HITTEST_ONITEMICON)
321 ecTreeItemData* data = (ecTreeItemData*) GetItemData(item);
322 data->GetConfigItem()->OnIconLeftDown(* this);
325 else if (event.RightDown())
327 if ((flags & wxTREE_HITTEST_ONITEMBUTTON) ||
328 (flags & wxTREE_HITTEST_ONITEMICON) ||
329 (flags & wxTREE_HITTEST_ONITEMINDENT) ||
330 (flags & wxTREE_HITTEST_ONITEMLABEL))
333 GetPropertiesMenu()->SetClientData((void*) TRUE);
334 PopupMenu(GetPropertiesMenu(), event.GetX(), event.GetY());
338 wxGetApp().GetWhatsThisMenu()->SetClientData((void*) FALSE);
339 PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
346 void ecConfigTreeCtrl::OnKeyDown(wxKeyEvent& event)
348 wxTreeItemId id = GetSelection();
349 if (event.GetKeyCode() == WXK_F10 && event.ShiftDown())
354 if (GetBoundingRect(id, rect))
356 GetPropertiesMenu()->SetClientData((void*) TRUE);
357 PopupMenu(GetPropertiesMenu(), 100, rect.GetTop() + 4);
361 else if (event.GetKeyCode() == '<')
365 ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
369 else if (event.GetKeyCode() == '>')
373 ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
377 else if (event.GetKeyCode() == WXK_SPACE)
381 ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
385 else if (event.GetKeyCode() == WXK_RETURN && event.AltDown())
389 ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
391 ecConfigPropertiesDialog dialog(wxGetApp().GetTopWindow(), item);
392 dialog.SetTitle(item->GetName());
402 void ecConfigTreeCtrl::OnCollapseExpand(wxTreeEvent& event)
404 if (GetCompanionWindow())
405 GetCompanionWindow()->Refresh();
408 // show help for this window
409 void ecConfigTreeCtrl::OnHelp(wxHelpEvent& event)
411 wxPoint pt = ScreenToClient(event.GetPosition());
413 wxTreeItemId id = HitTest(pt, flags);
414 wxHelpProvider *helpProvider = wxHelpProvider::Get();
415 if ( helpProvider && id > 0)
417 ecConfigItem* item = ((ecTreeItemData*) GetItemData(id))->GetConfigItem();
421 wxGetApp().GetHelpController().DisplayTextPopup(item->GetDescription(), event.GetPosition());
433 IMPLEMENT_CLASS(ecValueWindow, wxTreeCompanionWindow)
435 BEGIN_EVENT_TABLE(ecValueWindow, wxTreeCompanionWindow)
436 EVT_PAINT(ecValueWindow::OnPaint)
437 EVT_MOUSE_EVENTS(ecValueWindow::OnMouseEvent)
438 EVT_SCROLLWIN(ecValueWindow::OnScroll)
439 EVT_TREE_ITEM_EXPANDED(-1, ecValueWindow::OnExpand)
440 EVT_TREE_ITEM_COLLAPSED(-1, ecValueWindow::OnExpand)
443 ecValueWindow::ecValueWindow(wxWindow* parent, wxWindowID id,
447 wxTreeCompanionWindow(parent, id, pos, sz, style)
449 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_LISTBOX));
451 if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
452 wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")).Ok())
454 SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Configuration")));
457 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
464 void ecValueWindow::OnPaint(wxPaintEvent& event)
471 wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
473 dc.SetBrush(* wxTRANSPARENT_BRUSH);
474 wxFont font(GetFont());
476 //dc.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT));
477 dc.SetBackgroundMode(wxTRANSPARENT);
479 wxSize clientSize = GetClientSize();
482 wxTreeItemId h, lastH;
483 for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h))
485 if (m_treeCtrl->GetBoundingRect(h, itemRect))
487 cy = itemRect.GetTop();
488 wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
492 // Draw the actual item
493 DrawItem(dc, h, drawItemRect);
494 dc.DrawLine(0, cy, clientSize.x, cy);
497 if (lastH && lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect))
499 cy = itemRect.GetBottom();
500 dc.DrawLine(0, cy, clientSize.x, cy);
504 // Returns the rectangle which will enclose the value for this tree item
505 wxRect ecValueWindow::GetItemRect(ecConfigItem* item)
508 return wxRect(0, 0, 0, 0);
510 wxSize clientSize = GetClientSize();
514 for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h))
516 ecTreeItemData* data = (ecTreeItemData*) m_treeCtrl->GetItemData(h);
517 if (data->GetConfigItem() == item)
519 if (m_treeCtrl->GetBoundingRect(h, itemRect))
521 cy = itemRect.GetTop();
522 wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
526 return wxRect(0, 0, 0, 0);
529 return wxRect(0, 0, 0, 0);
532 void ecValueWindow::OnMouseEvent(wxMouseEvent& event)
534 if (event.LeftDown() && (event.GetX() > 2))
536 // Find if this corresponds to a tree item
538 wxTreeItemId item = m_treeCtrl->HitTest(wxPoint(4, event.GetY()), flags);
541 m_treeCtrl->SelectItem(item);
542 ecConfigItem* configItem = ((ecTreeItemData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
543 if (configItem->CanEdit())
544 BeginEditing(configItem);
547 else if (event.RightDown())
549 // Find if this corresponds to a tree item
551 wxTreeItemId item = m_treeCtrl->HitTest(wxPoint(4, event.GetY()), flags);
554 ecConfigItem* configItem = ((ecTreeItemData*) m_treeCtrl->GetItemData(item))->GetConfigItem();
555 m_treeCtrl->SelectItem(item);
556 ((ecConfigTreeCtrl*) m_treeCtrl)->GetPropertiesMenu()->SetClientData((void*) TRUE);
557 PopupMenu(((ecConfigTreeCtrl*) m_treeCtrl)->GetPropertiesMenu(), event.GetX(), event.GetY());
561 wxGetApp().GetWhatsThisMenu()->SetClientData((void*) FALSE);
562 PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
567 void ecValueWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect)
571 ecConfigItem* item = ((ecTreeItemData*) m_treeCtrl->GetItemData(id))->GetConfigItem();
574 wxString text = item->GetDisplayValue();
579 static wxColour normalColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
580 static wxColour disabledColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_GRAYTEXT);
581 dc.SetTextForeground( (item->GetActive() && (item->GetConfigType() != ecPackage)) ? normalColour : disabledColour );
584 dc.GetTextExtent(text, & textW, & textH);
587 int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);
589 dc.DrawText(text, x, y);
593 bool ecValueWindow::BeginEditing(ecConfigItem* item)
600 m_editWindow = item->CreateEditWindow(this);
603 m_editWindow->Show(FALSE);
605 item->TransferDataToWindow(m_editWindow);
607 // Position the control
608 PositionEditWindow();
610 m_editWindow->Show(TRUE);
611 m_editWindow->SetFocus();
622 // Position the control
623 void ecValueWindow::PositionEditWindow()
625 if (!m_configItem || !m_editWindow)
628 // Position the control
629 wxSize clientSize = GetClientSize();
631 m_treeCtrl->GetBoundingRect(m_configItem->GetTreeItem(), itemRect);
633 wxSize sz = m_editWindow->GetSize();
635 // m_editWindow->SetSize(2, itemRect.y+1, clientSize.x, itemRect.GetHeight() /* -2 */);
636 m_editWindow->SetSize(0, itemRect.y, clientSize.x, sz.y);
639 bool ecValueWindow::EndEditing()
643 if (m_editWindow && !wxGetApp().GetValuesLocked())
644 m_configItem->TransferDataFromWindow(m_editWindow);
657 void ecValueWindow::OnScroll(wxScrollWinEvent& event)
659 wxTreeCompanionWindow::OnScroll(event);
661 PositionEditWindow();
664 void ecValueWindow::OnExpand(wxTreeEvent& event)
666 wxTreeCompanionWindow::OnExpand(event);
675 wxIconStateInfo::wxIconStateInfo(const wxString& name)
680 for (i = 0; i < wxMAX_ICON_STATES; i++)
684 int wxIconStateInfo::GetIconId(int state, bool enabled) const
686 wxASSERT ( state < (wxMAX_ICON_STATES * 2) );
687 wxASSERT ( state < m_maxStates );
689 return m_states[state * 2 + (enabled ? 0 : 1)];
692 void wxIconStateInfo::SetIconId(int state, bool enabled, int iconId)
694 wxASSERT ( state < (wxMAX_ICON_STATES * 2) );
695 if (state+1 > m_maxStates)
696 m_maxStates = state+1;
698 m_states[state * 2 + (enabled ? 0 : 1)] = iconId;
703 * Contains a list of wxIconStateInfos
706 wxIconStateInfoDB::wxIconStateInfoDB(wxImageList* imageList)
708 m_imageList = imageList;
709 DeleteContents(TRUE);
712 void wxIconStateInfoDB::AppendInfo(wxIconStateInfo* info)
717 // Easy way of initialising both the image list and the
718 // info db. It will generate image ids itself while appending the icon.
719 bool wxIconStateInfoDB::AddInfo(const wxString& name, const wxIcon& icon, int state, bool enabled)
721 wxASSERT (m_imageList != NULL);
723 wxIconStateInfo* info = FindInfo(name);
726 info = new wxIconStateInfo(name);
729 info->SetIconId(state, enabled, m_imageList->Add(icon));
733 wxIconStateInfo* wxIconStateInfoDB::FindInfo(const wxString& name) const
735 wxNode* node = First();
738 wxIconStateInfo* info = (wxIconStateInfo*) node->Data();
739 if (info->GetName() == name)
746 int wxIconStateInfoDB::GetIconId(const wxString& name, int state, bool enabled) const
748 wxIconStateInfo* info = FindInfo(name);
751 return info->GetIconId(state, enabled);
754 bool wxIconStateInfoDB::SetIconId(const wxString& name, int state, bool enabled, int iconId)
756 wxIconStateInfo* info = FindInfo(name);
759 info->SetIconId(state, enabled, iconId);
764 wxIcon wxIconStateInfoDB::GetIcon(const wxString& name, int state, bool enabled) const
766 wxASSERT( m_imageList != NULL );
768 wxIconStateInfo* info = FindInfo(name);
771 int id = info->GetIconId(state, enabled);
775 return m_imageList->GetImage(id); // Doesn't exist
780 * ecSplitterScrolledWindow
781 * This window holds the tree and value windows.
782 * We derive a new class mainly to intercept popup menu commands from both child windows
783 * without resorting to placing their handlers in the main frame.
786 BEGIN_EVENT_TABLE(ecSplitterScrolledWindow, wxSplitterScrolledWindow)
787 EVT_MENU(ecID_WHATS_THIS, ecSplitterScrolledWindow::OnWhatsThis)
788 EVT_MENU(ecID_TREE_PROPERTIES, ecSplitterScrolledWindow::OnProperties)
789 EVT_MENU(ecID_TREE_RESTORE_DEFAULTS, ecSplitterScrolledWindow::OnRestoreDefaults)
790 EVT_MENU(ecID_TREE_VISIT_DOC, ecSplitterScrolledWindow::OnVisitDoc)
791 EVT_MENU(ecID_TREE_VIEW_HEADER, ecSplitterScrolledWindow::OnViewHeader)
792 EVT_MENU(ecID_TREE_UNLOAD_PACKAGE, ecSplitterScrolledWindow::OnUnloadPackage)
794 EVT_UPDATE_UI(ecID_TREE_RESTORE_DEFAULTS, ecSplitterScrolledWindow::OnUpdateRestoreDefaults)
795 EVT_UPDATE_UI(ecID_TREE_VISIT_DOC, ecSplitterScrolledWindow::OnUpdateVisitDoc)
796 EVT_UPDATE_UI(ecID_TREE_VIEW_HEADER, ecSplitterScrolledWindow::OnUpdateViewHeader)
797 EVT_UPDATE_UI(ecID_TREE_UNLOAD_PACKAGE, ecSplitterScrolledWindow::OnUpdateUnloadPackage)
800 static bool ecIsMenuForItem(wxCommandEvent& event)
802 wxObject* obj = event.GetEventObject();
805 if (obj->IsKindOf(CLASSINFO(wxMenu)))
807 // Menu has some client data which tells us if the menu was clicked over an item
809 menu = (wxMenu*) obj;
810 return (bool) (menu->GetClientData() != 0) ;
816 void ecSplitterScrolledWindow::OnWhatsThis(wxCommandEvent& event)
818 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
819 wxASSERT (treeCtrl != NULL) ;
821 wxTreeItemId id = treeCtrl->GetSelection();
822 if (id != 0 && ecIsMenuForItem(event))
824 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
826 wxPoint pt = wxGetMousePosition();
828 msg.Printf("Popping at %d x %d", pt.x, pt.y);
831 wxGetApp().GetHelpController().DisplayTextPopup(item->GetDescription(), wxGetMousePosition());
837 void ecSplitterScrolledWindow::OnProperties(wxCommandEvent& event)
839 wxObject* obj = event.GetEventObject();
842 if (obj->IsKindOf(CLASSINFO(wxMenu)))
844 // Menu has some client data which tells us if the menu was clicked over an item
846 menu = (wxMenu*) obj;
849 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
850 wxASSERT (treeCtrl != NULL) ;
852 wxTreeItemId id = treeCtrl->GetSelection();
853 if (id != 0 && ecIsMenuForItem(event))
855 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
857 ecConfigPropertiesDialog dialog(wxGetApp().GetTopWindow(), item);
858 dialog.SetTitle(item->GetName());
863 void ecSplitterScrolledWindow::OnRestoreDefaults(wxCommandEvent& event)
865 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
866 wxASSERT (treeCtrl != NULL) ;
868 wxTreeItemId id = treeCtrl->GetSelection();
869 if (id != 0 && ecIsMenuForItem(event))
871 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
872 if (item->HasModifiedChildren())
874 int ans = wxMessageBox(_("Restore defaults for nested items?"), wxGetApp().GetSettings().GetAppName(), wxYES_NO|wxCANCEL|wxICON_QUESTION);
878 RestoreDefault(id, TRUE);
881 RestoreDefault(id, FALSE);
892 RestoreDefault(id, FALSE);
894 // current values may have changed so refresh the other views
895 wxGetApp().GetConfigToolDoc ()->UpdateFailingRuleCount ();
897 if (item->GetOptionType () != ecOptionTypeNone)
899 ecConfigToolHint hint(item, ecValueChanged);
900 wxGetApp().GetConfigToolDoc ()->UpdateAllViews (NULL, & hint);
905 void ecSplitterScrolledWindow::RestoreDefault(wxTreeItemId h, bool bRecurse /* = FALSE */, bool bTopLevel /* = TRUE */)
907 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
908 wxASSERT (treeCtrl != NULL) ;
910 ecConfigItem* ti = ((ecTreeItemData*) treeCtrl->GetItemData(h))->GetConfigItem();
912 const CdlValuable valuable = ti->GetCdlValuable();
914 if (valuable && (CdlValueFlavor_None != valuable->get_flavor ())) // skip the root node and nodes without a value
915 valuable->set_source (CdlValueSource_Default);
916 treeCtrl->SetItemText (h, ti->GetItemNameOrMacro ()); // remove asterisk in control view
918 if (bTopLevel && ti->HasRadio ()) // if user-specified item is a radio button
920 for (ecConfigItem * pItem = ti->FirstRadio (); pItem; pItem = pItem->NextRadio ())
924 const CdlValuable valuable = pItem->GetCdlValuable();
926 valuable->set_source (CdlValueSource_Default); // restore default for each sibling radio button
927 treeCtrl->SetItemText (pItem->GetTreeItem(), pItem->GetItemNameOrMacro ()); // remove asterisk in control view
936 for (h = treeCtrl->GetFirstChild(h, cookie); h; h = treeCtrl->GetNextSibling(h))
938 RestoreDefault (h, TRUE, FALSE);
943 void ecSplitterScrolledWindow::OnVisitDoc(wxCommandEvent& event)
945 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
946 wxASSERT (treeCtrl != NULL) ;
948 wxTreeItemId id = treeCtrl->GetSelection();
949 if (id != 0 && ecIsMenuForItem(event))
951 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
959 void ecSplitterScrolledWindow::OnViewHeader(wxCommandEvent& event)
961 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
962 wxASSERT (treeCtrl != NULL) ;
964 wxTreeItemId id = treeCtrl->GetSelection();
965 if (id != 0 && ecIsMenuForItem(event))
967 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
975 void ecSplitterScrolledWindow::OnUnloadPackage(wxCommandEvent& event)
977 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
978 wxASSERT (treeCtrl != NULL) ;
980 wxTreeItemId id = treeCtrl->GetSelection();
983 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
985 if (wxYES == wxMessageBox(_("Are you sure you wish to unload this package?"), wxGetApp().GetSettings().GetAppName(),
986 wxYES_NO|wxICON_QUESTION))
989 wxGetApp().GetConfigToolDoc()->RegenerateData();
994 void ecSplitterScrolledWindow::OnUpdateRestoreDefaults(wxUpdateUIEvent& event)
996 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
997 wxASSERT (treeCtrl != NULL) ;
999 wxTreeItemId id = treeCtrl->GetSelection();
1002 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
1004 event.Enable( IsChanged(id, TRUE ) );
1008 void ecSplitterScrolledWindow::OnUpdateVisitDoc(wxUpdateUIEvent& event)
1010 event.Enable( TRUE );
1013 void ecSplitterScrolledWindow::OnUpdateViewHeader(wxUpdateUIEvent& event)
1015 ecConfigToolDoc *pDoc=wxGetApp().GetConfigToolDoc();
1016 event.Enable( pDoc && !pDoc->GetBuildTree().IsEmpty() ) ;
1019 void ecSplitterScrolledWindow::OnUpdateUnloadPackage(wxUpdateUIEvent& event)
1021 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
1022 wxASSERT (treeCtrl != NULL) ;
1024 wxTreeItemId id = treeCtrl->GetSelection();
1027 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
1029 event.Enable( item->IsPackage() );
1033 bool ecSplitterScrolledWindow::IsChanged(wxTreeItemId id, bool bRecurse)
1035 ecConfigTreeCtrl* treeCtrl = (ecConfigTreeCtrl*) FindWindow(ecID_TREE_CTRL);
1036 wxASSERT (treeCtrl != NULL) ;
1038 ecConfigItem* item = ((ecTreeItemData*) treeCtrl->GetItemData(id))->GetConfigItem();
1039 bool rc = item->Modified ();
1044 for (id=treeCtrl->GetFirstChild(id, cookie);id;id=treeCtrl->GetNextSibling(id))
1046 if (IsChanged(id,TRUE))