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: propertywin.cpp,v 1.7 2001/04/24 14:39:13 julians Exp $
35 // Description: Implementation file for ecPropertyListCtrl
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "propertywin.h"
57 // Includes other headers for precompiled compilation
64 #include "propertywin.h"
65 #include "configtool.h"
66 #include "configitem.h"
67 #include "configtooldoc.h"
70 // specify the CDL properties which are to be visible in the properties view
71 const std::string ecPropertyListCtrl::visible_properties [] =
73 CdlPropertyId_ActiveIf,
74 CdlPropertyId_BuildProc,
75 CdlPropertyId_Calculated,
76 CdlPropertyId_CancelProc,
77 CdlPropertyId_CheckProc,
78 CdlPropertyId_Compile,
79 CdlPropertyId_ConfirmProc,
80 CdlPropertyId_DecorationProc,
81 CdlPropertyId_DefaultValue,
83 CdlPropertyId_DefineHeader,
84 CdlPropertyId_DefineProc,
85 // CdlPropertyId_Description,
87 // CdlPropertyId_Display,
88 CdlPropertyId_DisplayProc,
90 CdlPropertyId_EntryProc,
92 CdlPropertyId_DefineFormat,
94 CdlPropertyId_Hardware,
95 CdlPropertyId_IfDefine,
96 CdlPropertyId_Implements,
97 CdlPropertyId_IncludeDir,
98 CdlPropertyId_IncludeFiles,
99 CdlPropertyId_InitProc,
100 CdlPropertyId_InstallProc,
101 CdlPropertyId_LegalValues,
102 CdlPropertyId_Library,
103 CdlPropertyId_LicenseProc,
105 CdlPropertyId_Makefile,
106 CdlPropertyId_MakeObject,
107 CdlPropertyId_NoDefine,
108 CdlPropertyId_Object,
109 CdlPropertyId_Parent,
110 CdlPropertyId_Requires,
111 CdlPropertyId_Screen,
112 CdlPropertyId_Script,
113 CdlPropertyId_UpdateProc,
117 const wxChar* ecPropertyListCtrl::sm_fieldTypeImage[ecMAXFIELDTYPE]=
118 {wxT("Type"), wxT("Value"), wxT("Default"), wxT("Macro"), wxT("File"), wxT("URL"), wxT("Enabled")};
125 IMPLEMENT_CLASS(ecPropertyListCtrl, wxListCtrl)
127 BEGIN_EVENT_TABLE(ecPropertyListCtrl, wxListCtrl)
128 EVT_RIGHT_DOWN(ecPropertyListCtrl::OnRightClick)
129 EVT_LEFT_DCLICK(ecPropertyListCtrl::OnDoubleClick)
132 ecPropertyListCtrl::ecPropertyListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
133 const wxSize& sz, long style):
134 wxListCtrl(parent, id, pt, sz, style)
136 if (!wxGetApp().GetSettings().GetWindowSettings().GetUseDefaults() &&
137 wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Properties")).Ok())
139 SetFont(wxGetApp().GetSettings().GetWindowSettings().GetFont(wxT("Properties")));
145 m_nFirstProperty = 0;
146 m_nOnSizeRecursionCount = 0;
153 for (j = 0; j < 4; j++)
156 // Insert some dummy items
159 info.m_text = _("URL");
160 info.m_mask = wxLIST_MASK_TEXT ; // | wxLIST_MASK_IMAGE | wxLIST_MASK_DATA;
163 //info.m_data = (long) doc;
165 long item = InsertItem(info);
167 SetItem(i, 1, _("redirects/interrupts.html"));
170 info.m_text = _("Enabled");
171 info.m_mask = wxLIST_MASK_TEXT ; // | wxLIST_MASK_IMAGE | wxLIST_MASK_DATA;
174 //info.m_data = (long) doc;
176 item = InsertItem(info);
178 SetItem(i, 1, _("True"));
185 void ecPropertyListCtrl::OnRightClick(wxMouseEvent& event)
187 PopupMenu(wxGetApp().GetWhatsThisMenu(), event.GetX(), event.GetY());
190 void ecPropertyListCtrl::AddColumns()
192 InsertColumn(0, "Property", wxLIST_FORMAT_LEFT, 100);
193 InsertColumn(1, "Value", wxLIST_FORMAT_LEFT, 300);
196 void ecPropertyListCtrl::Fill(ecConfigItem *pti)
203 } else /* if(pti!=m_pti) */ {
206 ecOptionType type=m_pti->GetOptionType();
209 // Initially flag all items as unnecessary - calls of SetItem or SetProperty will change this
210 for(i=GetItemCount()-1;i>=0;--i){
213 if (m_pti->HasBool () || (ecOptionTypeNone!=type)){
214 SetItem(ecMacro, m_pti->GetMacro ());
217 if (m_pti->HasBool ()){
218 SetItem(ecEnabled, m_pti->IsEnabled() ? wxT("True") : wxT("False"));
221 if(!m_pti->GetFilename().IsEmpty()){
222 SetItem(ecFile, m_pti->GetFilename());
224 SetItem(ecURL, m_pti->GetURL());
226 if (ecOptionTypeNone!=type){
230 SetItem(ecValue, m_pti->StringValue());
231 SetItem(ecDefaultValue, m_pti->StringDefaultValue());
234 SetItem(ecValue, ecUtils::IntToStr(m_pti->Value(), wxGetApp().GetSettings().m_bHex));
235 SetItem(ecDefaultValue, ecUtils::IntToStr(m_pti->DefaultValue(), wxGetApp().GetSettings().m_bHex));
238 SetItem(ecValue, ecUtils::DoubleToStr(m_pti->DoubleValue()));
239 SetItem(ecDefaultValue, ecUtils::DoubleToStr(m_pti->DoubleDefaultValue()));
242 SetItem(ecValue,m_pti->StringValue());
243 SetItem(ecDefaultValue,m_pti->StringDefaultValue());
250 // SetItem(ecType, ecConfigItem::TreeItemTypeImage[type]);
253 // List all the properties applicable to me
254 const std::string name = ecUtils::UnicodeToStdStr (m_pti->GetMacro ());
255 if (name.size () > 0)
257 const CdlConfiguration config = wxGetApp().GetConfigToolDoc ()->GetCdlConfig ();
258 const CdlNode node = config->find_node (name, true);
260 const std::vector<CdlProperty> & properties = node->get_properties ();
261 std::vector<CdlProperty>::const_iterator property_i;
262 // CMapStringToPtr map; // count of each property name
263 wxHashTable map(wxKEY_STRING); // count of each property name
265 for (property_i = properties.begin (); property_i != properties.end (); property_i++) {// for each property
266 // get the property name
267 const CdlProperty &prop=*property_i;
268 const wxString strName(prop->get_property_name ().c_str());
269 enum {VISIBLE_PROPERTIES_COUNT=sizeof visible_properties/sizeof visible_properties[0]};
270 if (std::find (visible_properties, visible_properties + VISIBLE_PROPERTIES_COUNT, ecUtils::UnicodeToStdStr(strName)) != visible_properties + VISIBLE_PROPERTIES_COUNT) {// if the property should be displayed
271 // set the property arguments
272 wxString strPropertyArgs;
273 const std::vector<std::string> & argv = prop->get_argv ();
275 p = (void*) map.Delete(strName);
277 p=(void *)((int)p+1);
278 map.Put(strName, (wxObject*) p);
280 std::vector<std::string>::const_iterator argv_i;
281 for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++){ // for each property argument...
282 if (argv_i != argv.begin ()){ // ...except the first (the property name)
283 wxString strArg(ecUtils::StripExtraWhitespace (wxString(argv_i->c_str())));
284 if (strPropertyArgs.Len() + strArg.Len() + 1 > 256) {// if the string is too long for the list control
285 break; // no need to add any further arguments
287 strPropertyArgs += strArg; // add the argument to the string
288 strPropertyArgs += wxT (" "); // separate arguments by a space character
291 // the list control appears to display a maximum of 256 characters
292 int nIndex=SetItem(strName, strPropertyArgs, GetItemCount(), (int)p);
293 SetItemData(nIndex, (long) prop);
295 // display the exclamation icon if the property is in a conflicts list
297 // PropertyInConflictsList (* property_i, config->get_structural_conflicts ()) || ignore for now
298 PropertyInConflictsList (prop, config->get_all_conflicts ());
300 // TODO: set the image for a conflict item
301 // CListCtrl::SetItem (nIndex, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
306 for(i=GetItemCount()-1;i>=0;--i){
307 if(0==GetItemData(i)){
309 if(i<m_nFirstProperty){
318 int nAvailWidth=rect.Width()-GetColumnWidth(0);
319 int w=max(m_nMaxValueWidth,nAvailWidth);
320 m_f[1]=double(w)/double(rect.Width());
328 bool ecPropertyListCtrl::PropertyInConflictsList (CdlProperty property, const std::list<CdlConflict> & conflicts)
330 std::list<CdlConflict>::const_iterator conf_i;
331 for (conf_i = conflicts.begin (); conf_i != conflicts.end (); conf_i++) // for each conflict
332 if (property == (* conf_i)->get_property ())
338 void ecPropertyListCtrl::RefreshValue()
343 if (m_pti->HasBool ()){
344 SetItem(ecEnabled, m_pti->IsEnabled () ? wxT("True") : wxT("False"));
346 if (m_pti->GetOptionType () != ecOptionTypeNone){
347 SetItem(ecValue, m_pti->StringValue());
349 for (int nItem = m_nFirstProperty; nItem < GetItemCount (); nItem++)
351 CdlProperty property = (CdlProperty) GetItemData (nItem);
354 // display the exclamation icon if the property is in a conflicts list
355 const CdlConfiguration config = wxGetApp().GetConfigToolDoc ()->GetCdlConfig ();
357 // PropertyInConflictsList (property, config->get_structural_conflicts ()) || ignore for now
358 PropertyInConflictsList (property, config->get_all_conflicts ());
361 // CListCtrl::SetItem (nItem, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
366 int ecPropertyListCtrl::SetItem(ecFieldType f, const wxString& value)
368 int nIndex=SetItem(sm_fieldTypeImage[f], value, m_nFirstProperty);
369 if(nIndex==m_nFirstProperty){
372 SetItemData(nIndex,1);
376 int ecPropertyListCtrl::SetItem(const wxString& item, const wxString& value, int nInsertAs, int nRepeat)
378 wxASSERT( nInsertAs <= GetItemCount() );
382 info.flags =LVFI_STRING;
384 info.vkDirection=VK_DOWN;
387 nIndex=FindItem(&info,nIndex);
388 } while (--nRepeat>0 && nIndex!=-1);
390 // NB: wxListCtrl doesn't support reverse search, so could do it explicitly
391 // by iterating through the items.
392 // But for now, just ignore the nRepeat flag and find the first one.
394 nIndex = FindItem(0, /* nIndex */ item);
397 nIndex = InsertItem(nInsertAs, item);
400 wxListCtrl::SetItem(nIndex, 1, value);
405 CFont *pOldFont=pDC->SelectObject(GetFont());
406 m_nMaxValueWidth=max(m_nMaxValueWidth,pDC->GetTextExtent(pszValue).cx);
407 pDC->SelectObject(pOldFont);
414 void ecPropertyListCtrl::OnDoubleClick(wxMouseEvent& event)
416 // Double-clicked the item
419 long item = HitTest(event.GetPosition(), flags);
422 const wxString strText = wxListCtrlGetItemTextColumn(*this, item,0);
423 if(strText == wxT("File")){
425 } else if (strText == wxT("URL")) {
432 int pos=GetMessagePos();
433 CPoint pt(GET_X_LPARAM(pos),GET_Y_LPARAM(pos));
435 int nItem=HitTest(pt,NULL);
437 if(GetItemData(nItem)>1){
438 // This is a property row
439 const CdlGoalExpression goal = dynamic_cast<CdlGoalExpression> ((CdlProperty) GetItemData (nItem));
441 // This is a rule row
442 const CdlExpression expression = goal->get_expression ();
443 if (1 == expression->references.size ()) // if the property contains a single reference
445 // assume that the reference is to another user visible node and try to find it
446 std::string macro_name = expression->references [0].get_destination_name ();
447 CConfigItem * pItem = CConfigTool::GetConfigToolDoc ()->Find (CString (macro_name.c_str ()));
448 if (pItem) // the referenced node was found so select it
450 CConfigTool::GetControlView()->GetTreeCtrl().SelectItem(pItem->HItem());
455 const CString strText(GetItemText(nItem,0));
456 if(strText==FieldTypeImage[File]){
458 } else if (strText==FieldTypeImage[URL]) {