Ejemplo n.º 1
0
void CPropertiesList::Fill(CConfigItem *pti)
{
  if(NULL==pti){
    DeleteAllItems();
    m_nFirstProperty=0;
    m_pti=NULL;
  } else if(pti!=m_pti){
    m_pti=pti;
    m_nMaxValueWidth=0;
    CConfigItem::TreeItemType type=m_pti->Type();
    int i;  

    // Initially flag all items as unnecessary - calls of SetItem or SetProperty will change this
    for(i=GetItemCount()-1;i>=0;--i){
      SetItemData(i,0);
    }
	  if (m_pti->HasBool () || (CConfigItem::None!=type)){
      SetItem(Macro, m_pti->Macro ());
    }
  
    if (m_pti->HasBool ()){
      SetItem(Enabled,m_pti->IsEnabled() ? _T("True") : _T("False"));
    }
    
    if(!m_pti->FileName().IsEmpty()){
      SetItem(File,m_pti->FileName());
    }
    SetItem(URL,m_pti->GetURL());

    if(CConfigItem::None!=type){
      switch(type){
        case CConfigItem::String:
          SetItem(Value,m_pti->StringValue());
          SetItem(DefaultValue,m_pti->StringDefaultValue());
          break;
        case CConfigItem::Integer:
          SetItem(Value,CUtils::IntToStr(m_pti->Value(),CConfigTool::GetConfigToolDoc()->m_bHex));
          SetItem(DefaultValue,CUtils::IntToStr(m_pti->DefaultValue(),CConfigTool::GetConfigToolDoc()->m_bHex));
          break;
        case CConfigItem::Double:
          SetItem(Value,CUtils::DoubleToStr(m_pti->DoubleValue()));
          SetItem(DefaultValue,CUtils::DoubleToStr(m_pti->DoubleDefaultValue()));
          break;
        case CConfigItem::Enum:
          SetItem(Value,m_pti->StringValue());
          SetItem(DefaultValue,m_pti->StringDefaultValue());
          break;
        default:
          ASSERT(FALSE);
          break;
      }
      SetItem(Type,CConfigItem::TreeItemTypeImage[type]);
    }
    
    // List all the properties applicable to me
    const std::string name = CUtils::UnicodeToStdStr (m_pti->Macro ());
    if (name.size () > 0)
    {
      const CdlConfiguration config = CConfigTool::GetConfigToolDoc ()->GetCdlConfig ();
      const CdlNode node = config->find_node (name, true);
      ASSERT (node);
      const std::vector<CdlProperty> & properties = node->get_properties ();
      std::vector<CdlProperty>::const_iterator property_i;
      CMapStringToPtr map; // count of each property name
      for (property_i = properties.begin (); property_i != properties.end (); property_i++) {// for each property
        // get the property name
        const CdlProperty &prop=*property_i;
        const CString strName(prop->get_property_name ().c_str());
        enum {VISIBLE_PROPERTIES_COUNT=sizeof visible_properties/sizeof visible_properties[0]};
        if (std::find (visible_properties, visible_properties + VISIBLE_PROPERTIES_COUNT, CUtils::UnicodeToStdStr(strName)) != visible_properties + VISIBLE_PROPERTIES_COUNT) {// if the property should be displayed
          // set the property arguments
          CString strPropertyArgs;
          const std::vector<std::string> & argv = prop->get_argv ();
          void *p;
          if(!map.Lookup(strName,p)){
            p=0;
          }

          p=(void *)((int)p+1);
          map.SetAt(strName,p);
          
          std::vector<std::string>::const_iterator argv_i;
          for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++){ // for each property argument...
            if (argv_i != argv.begin ()){                              // ...except the first (the property name)
              CString strArg(CUtils::StripExtraWhitespace (CString(argv_i->c_str())));
              if (strPropertyArgs.GetLength () + strArg.GetLength() + 1 > 256) {// if the string is too long for the list control
                break; // no need to add any further arguments
              }
              strPropertyArgs += strArg; // add the argument to the string
              strPropertyArgs += _T (" "); // separate arguments by a space character
            }
          }
          // the list control appears to display a maximum of 256 characters
          int nIndex=SetItem(strName,strPropertyArgs,GetItemCount(),(int)p);
          SetItemData(nIndex,(DWORD)prop);
          
          // display the exclamation icon if the property is in a conflicts list
          bool bConflictItem =
            //					PropertyInConflictsList (* property_i, config->get_structural_conflicts ()) || ignore for now
            PropertyInConflictsList (prop, config->get_all_conflicts ());
          CListCtrl::SetItem (nIndex, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
        }
      }
    }
    
    for(i=GetItemCount()-1;i>=0;--i){
      if(0==GetItemData(i)){
        DeleteItem(i);
        if(i<m_nFirstProperty){
          m_nFirstProperty--;
        }
      }
    }
    CRect rect;
    GetClientRect(rect);
    int nAvailWidth=rect.Width()-GetColumnWidth(0);
    int w=max(m_nMaxValueWidth,nAvailWidth);
    m_f[1]=double(w)/double(rect.Width());
    SetColumnWidth(1,w); 
  }
}
Ejemplo n.º 2
0
void ecPropertyListCtrl::Fill(ecConfigItem *pti)
{
    if(NULL==pti){
        ClearAll();
        AddColumns();
        m_nFirstProperty=0;
        m_pti=NULL;
    } else /* if(pti!=m_pti) */ {
        m_pti=pti;
        m_nMaxValueWidth=0;
        ecOptionType type=m_pti->GetOptionType();
        int i;  
        
        // Initially flag all items as unnecessary - calls of SetItem or SetProperty will change this
        for(i=GetItemCount()-1;i>=0;--i){
            SetItemData(i,0);
        }
        if (m_pti->HasBool () || (ecOptionTypeNone!=type)){
            SetItem(ecMacro, m_pti->GetMacro ());
        }
        
        if (m_pti->HasBool ()){
            SetItem(ecEnabled, m_pti->IsEnabled() ? wxT("True") : wxT("False"));
        }
        
        if(!m_pti->GetFilename().IsEmpty()){
            SetItem(ecFile, m_pti->GetFilename());
        }
        SetItem(ecURL, m_pti->GetURL());
        
        if (ecOptionTypeNone!=type){

            switch(type){
            case ecString:
                SetItem(ecValue, m_pti->StringValue());
                SetItem(ecDefaultValue, m_pti->StringDefaultValue());
                break;
            case ecLong:
                SetItem(ecValue, ecUtils::IntToStr(m_pti->Value(), wxGetApp().GetSettings().m_bHex));
                SetItem(ecDefaultValue, ecUtils::IntToStr(m_pti->DefaultValue(), wxGetApp().GetSettings().m_bHex));
                break;
            case ecDouble:
                SetItem(ecValue, ecUtils::DoubleToStr(m_pti->DoubleValue()));
                SetItem(ecDefaultValue, ecUtils::DoubleToStr(m_pti->DoubleDefaultValue()));
                break;
            case ecEnumerated:
                SetItem(ecValue,m_pti->StringValue());
                SetItem(ecDefaultValue,m_pti->StringDefaultValue());
                break;
            default:
                wxASSERT( FALSE );
                break;
            }
            // TODO: set image
            // SetItem(ecType, ecConfigItem::TreeItemTypeImage[type]);
        }

        // List all the properties applicable to me
        const std::string name = ecUtils::UnicodeToStdStr (m_pti->GetMacro ());
        if (name.size () > 0)
        {
            const CdlConfiguration config = wxGetApp().GetConfigToolDoc ()->GetCdlConfig ();
            const CdlNode node = config->find_node (name, true);
            wxASSERT (node);
            const std::vector<CdlProperty> & properties = node->get_properties ();
            std::vector<CdlProperty>::const_iterator property_i;
            // CMapStringToPtr map; // count of each property name
            wxHashTable map(wxKEY_STRING);  // count of each property name

            for (property_i = properties.begin (); property_i != properties.end (); property_i++) {// for each property
                // get the property name
                const CdlProperty &prop=*property_i;
                const wxString strName(prop->get_property_name ().c_str());
                enum {VISIBLE_PROPERTIES_COUNT=sizeof visible_properties/sizeof visible_properties[0]};
                if (std::find (visible_properties, visible_properties + VISIBLE_PROPERTIES_COUNT, ecUtils::UnicodeToStdStr(strName)) != visible_properties + VISIBLE_PROPERTIES_COUNT) {// if the property should be displayed
                    // set the property arguments
                    wxString strPropertyArgs;
                    const std::vector<std::string> & argv = prop->get_argv ();
                    void *p;
                    p = (void*) map.Delete(strName);
                    
                    p=(void *)((int)p+1);
                    map.Put(strName, (wxObject*) p);
                    
                    std::vector<std::string>::const_iterator argv_i;
                    for (argv_i = argv.begin (); argv_i != argv.end (); argv_i++){ // for each property argument...
                        if (argv_i != argv.begin ()){                              // ...except the first (the property name)
                            wxString strArg(ecUtils::StripExtraWhitespace (wxString(argv_i->c_str())));
                            if (strPropertyArgs.Len() + strArg.Len() + 1 > 256) {// if the string is too long for the list control
                                break; // no need to add any further arguments
                            }
                            strPropertyArgs += strArg; // add the argument to the string
                            strPropertyArgs += wxT (" "); // separate arguments by a space character
                        }
                    }
                    // the list control appears to display a maximum of 256 characters
                    int nIndex=SetItem(strName, strPropertyArgs, GetItemCount(), (int)p);
                    SetItemData(nIndex, (long) prop);
                    
                    // display the exclamation icon if the property is in a conflicts list
                    bool bConflictItem =
                        //					PropertyInConflictsList (* property_i, config->get_structural_conflicts ()) || ignore for now
                        PropertyInConflictsList (prop, config->get_all_conflicts ());

                    // TODO: set the image for a conflict item
                    // CListCtrl::SetItem (nIndex, 0, LVIF_IMAGE, NULL, bConflictItem ? 1 : 0, 0, 0, 0 );
                }
            }
        }

        for(i=GetItemCount()-1;i>=0;--i){
            if(0==GetItemData(i)){
                DeleteItem(i);
                if(i<m_nFirstProperty){
                    m_nFirstProperty--;
                }
            }
        }
        // TODO
#if 0
        CRect rect;
        GetClientRect(rect);
        int nAvailWidth=rect.Width()-GetColumnWidth(0);
        int w=max(m_nMaxValueWidth,nAvailWidth);
        m_f[1]=double(w)/double(rect.Width());
        SetColumnWidth(1,w); 
#endif
    }

    Refresh();
}