BOOL CMapInfo::OnInitDialog() { CDialog::OnInitDialog(); m_nTotalBrushes = 0; m_nTotalEntities = 0; m_nNet = 0; for (brush_t *pBrush=active_brushes.next ; pBrush != &active_brushes ; pBrush=pBrush->next) { m_nTotalBrushes++; if (pBrush->owner == world_entity) m_nNet++; } CMapStringToPtr mapEntity; int nValue = 0; for (entity_t *pEntity=entities.next ; pEntity != &entities ; pEntity=pEntity->next) { m_nTotalEntities++; nValue = 0; mapEntity.Lookup(pEntity->eclass->name, reinterpret_cast<void* &>(nValue)); nValue++ ; mapEntity.SetAt(pEntity->eclass->name, reinterpret_cast<void *>(nValue)); } m_lstEntity.ResetContent(); m_lstEntity.SetTabStops(96); CString strKey; POSITION pos = mapEntity.GetStartPosition(); while (pos) { mapEntity.GetNextAssoc(pos, strKey, reinterpret_cast<void* &>(nValue)); CString strList; strList.Format("%s\t%i", strKey, nValue); m_lstEntity.AddString(strList); } UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CFontComboBox::EnumFontFamiliesEx(CDC& dc, BYTE nCharSet) { CMapStringToPtr map; CString str; GetTheText(str); EmptyContents(); ResetContent(); LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfCharSet = nCharSet; if (dc.m_hDC != NULL) { if (theApp.m_bWin4) { ::EnumFontFamiliesEx(dc.m_hDC, &lf, (FONTENUMPROC) EnumFamPrinterCallBackEx, (LPARAM) this, NULL); } else { ::EnumFontFamilies(dc.m_hDC, NULL, (FONTENUMPROC) EnumFamPrinterCallBack, (LPARAM) this); } } else { HDC hDC = theApp.m_dcScreen.m_hDC; ASSERT(hDC != NULL); if (theApp.m_bWin4) { ::EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC) EnumFamScreenCallBackEx, (LPARAM) this, NULL); } else { ::EnumFontFamilies(hDC, NULL, (FONTENUMPROC) EnumFamScreenCallBack, (LPARAM) this); } } // now walk through the fonts and remove (charset) from fonts with only one int nCount = m_arrayFontDesc.GetSize(); // walk through fonts adding names to string map // first time add value 0, after that add value 1 for (int i = 0; i<nCount;i++) { CFontDesc* pDesc = (CFontDesc*)m_arrayFontDesc[i]; void* pv = NULL; if (map.Lookup(pDesc->m_strName, pv)) // found it { if (pv == NULL) // only one entry so far { map.RemoveKey(pDesc->m_strName); map.SetAt(pDesc->m_strName, (void*)1); } } else // not found map.SetAt(pDesc->m_strName, (void*)0); } for (i = 0; i<nCount;i++) { CFontDesc* pDesc = (CFontDesc*)m_arrayFontDesc[i]; CString str = pDesc->m_strName; void* pv = NULL; VERIFY(map.Lookup(str, pv)); if (pv != NULL && !pDesc->m_strScript.IsEmpty()) { str += " ("; str += pDesc->m_strScript; str += ")"; } int nIndex = AddString(str); ASSERT(nIndex >=0); if (nIndex >=0) //no error SetItemData(nIndex, (DWORD)pDesc); } SetTheText(str); m_arrayFontDesc.RemoveAll(); }
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); } }
void CAddTaskLinksEdit::UpdateLinksByWindowText() { if (NULL == m_pDoc) return; //AfxMessageBox(_T("abc")); set<CRssFeed*> setRssUpdatefeed;//订阅 // 取现在Doc里的所有ed2k的fileHash,组成set。 set<CFileHashKey> setKeysInDoc; setKeysInDoc = m_pDoc->GetAllKeysInDoc(); // 把EditCtrl里的内容变成一行一行的字符串,并把每一行放入列表中。 CString strText; GetWindowText(strText); CList<CString> lstLinks; ::ConvertStrToStrList(&lstLinks, strText); CFileHashKey key; CAddTaskDoc::SItem docItem; CString strLine; CED2KLink *pLink = NULL; //CList<CString> lstUrls; CMapStringToPtr setUrls; CString strPrefix; // Added by VC-yavey on 2010-04-16 <begin> // 初始化rss url m_pDoc->GetRssUrlSet().clear(); // Added by VC-yavey on 2010-04-16 <end> // 分析每一行,并做相应的处理。 POSITION pos = lstLinks.GetHeadPosition(); if ( pos == NULL && !m_setLastRssfeed.empty() ) { set<CRssFeed*>::iterator it;//删除掉无用的rss订阅对象 for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; ++it ) { delete *it; } m_setLastRssfeed.clear(); } bool bHasRssLink = false; while (NULL != pos) { strLine = lstLinks.GetNext(pos); strLine = Decode3URL(strLine); strPrefix = strLine.Left(strLine.Find(_T(':'))); if (0 == strPrefix.CompareNoCase(_T("ed2k"))) { try { pLink = NULL; // MODIFIED by VC-yavey on 2010-04-16 // 处理订阅协议 pLink = CED2KLink::CreateLinkFromUrl(strLine); } catch (...) { SAFE_DELETE(pLink); } if (NULL != pLink) { // MODIFIED by VC-yavey on 2010-04-16 // 处理订阅协议 switch ( pLink->GetKind() ) { case CED2KLink::kFile: key = ((CED2KFileLink*)pLink)->GetHashKey(); // MODIFIED by VC-yavey on 2010-04-16, 统一放到最后删除 //SAFE_DELETE(pLink); setKeysInDoc.erase(key); docItem.strLinkText = strLine; docItem.bCheck = TRUE; m_pDoc->SetItem(key, docItem, CAddTaskDoc::IM_TEXT | CAddTaskDoc::IM_CHECK, GetSafeHwnd()); break; case CED2KLink::kRss: { bHasRssLink = true; CString strRssLink; CAddTaskDoc::RssUrlSet & setUrl = m_pDoc->GetRssUrlSet(); strRssLink = ((CED2KRssLink*)pLink)->GetRssUrl(); //added by lost 判断上次获取到订阅中的 if ( !m_setLastRssfeed.empty() ) { bool bAlready = false; set<CRssFeed*>::iterator it; for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; it++ ) { ASSERT( *it != NULL); CRssFeed * pFeed = *it; if ( pFeed->m_strFeedUrl == strRssLink ) { bAlready = true; setRssUpdatefeed.insert( (*it) ); break; } } if (!bAlready) { setUrl.insert( strRssLink ) ; } } else { setUrl.insert( strRssLink ) ; } //added by lost } break; } SAFE_DELETE(pLink); } } else if (0 == strPrefix.CompareNoCase(_T("http")) || 0 == strPrefix.CompareNoCase(_T("ftp"))) { setUrls.SetAt(strLine, NULL); //lstUrls.AddTail(strLine); } } CAddTaskDoc::RssUrlSet & setUrl = m_pDoc->GetRssUrlSet(); if (!setUrl.empty()) { if (pThread == NULL) { UPDATERSS_PARAM * paramRSS = new UPDATERSS_PARAM; paramRSS->setRssLink = setUrl; paramRSS->thisEdit = this; pThread = AfxBeginThread( ThreadUpdateRSS, paramRSS );//线程获取FEED信息 } } //从获取到的FEED集合中得到所有文件hash set<CFileHashKey> setKeysInLastFeed; if ( !setRssUpdatefeed.empty() ) { set<CRssFeed*>::iterator itRss; for ( itRss = setRssUpdatefeed.begin(); setRssUpdatefeed.end() != itRss; itRss++ ) { CRssFeed* pFeed = *itRss; CED2KLink *pLinkRss = NULL; for ( CRssFeed::ItemIterator it = pFeed->GetItemIterBegin(); it != pFeed->GetItemIterEnd(); ++it ) { CRssFeed::Item & item = it->second; try { pLinkRss = NULL; pLinkRss = CED2KLink::CreateLinkFromUrl(item.m_strEnclosure); } catch (...) { SAFE_DELETE(pLinkRss); } if (NULL != pLinkRss) { switch ( pLinkRss->GetKind() ) { case CED2KLink::kFile: key = ((CED2KFileLink*)pLinkRss)->GetHashKey(); setKeysInLastFeed.insert(key); } } } SAFE_DELETE(pLinkRss); } if ( !m_setRssHash.empty() ) { m_setRssHash.clear();//直接清除set //set<CFileHashKey>::iterator itKey; //for ( itKey = m_setRssHash.begin(); m_setRssHash.end() != itKey; itKey++ )//erase后就不可以再用itKey++了 切记 //{ // itKey = m_setRssHash.erase(itKey); //} } m_setRssHash = setKeysInLastFeed; set<CRssFeed*>::iterator it;//删除掉无用的rss订阅对象 for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; ) { if (setRssUpdatefeed.find(*it) == setRssUpdatefeed.end()) { delete *it; it = m_setLastRssfeed.erase(it); } else { ++it; } } setRssUpdatefeed.clear();//清空set } // EditCtrl里没有的ed2k链接,则在doc里把它删除。 set<CFileHashKey>::iterator it; for (it = setKeysInDoc.begin(); setKeysInDoc.end() != it; it++) { //docItem.bCheck = FALSE; //m_pDoc->SetItem(*it, docItem, CAddTaskDoc::IM_CHECK, GetSafeHwnd()); if ( !setKeysInLastFeed.empty() && setKeysInLastFeed.find(*it) != setKeysInLastFeed.end() ) {//与Feed中某hash值匹配 continue; } m_pDoc->RemoveItem(*it); } if (bHasRssLink) (((CDlgAddTask*)GetParent())->m_chkboxRssAutoDown).ShowWindow(SW_SHOW); else (((CDlgAddTask*)GetParent())->m_chkboxRssAutoDown).ShowWindow(SW_HIDE); m_pDoc->UpdateUrlItems(&setUrls, GetSafeHwnd()); }