⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlview.cpp

📁 eCos1.31版
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  if(CConfigTool::GetCellView()->ActiveCell()==h){    rc=CConfigTool::GetCellView()->GetCellValue();  } else   {    rc=ti.Value();  }  return rc;}void CControlView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) {  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  switch(lHint)  {		case CConfigToolDoc::AllSaved:            {        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)        {          CConfigItem *pItem=pDoc->Item(nItem);          HTREEITEM h=pItem->HItem();          if(h){            SetItemText(h,pItem->ItemNameOrMacro());            InvalidateItem(h);          }        }      }      break;    case CConfigToolDoc::NameFormatChanged:      {        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)        {          CConfigItem *pItem=pDoc->Item(nItem);          CString strName(pItem->ItemNameOrMacro());          if(pItem->Modified()){            strName+=_TCHAR('*');          }          SetItemText(pItem->HItem(),strName);        }                Invalidate();      }      break;    case CConfigToolDoc::IntFormatChanged:      break;    case CConfigToolDoc::Clear:		      m_hExpandedForFind=NULL;      m_hContext=NULL;      DeleteAllItems();      break;    case CConfigToolDoc::ValueChanged:      {        CConfigItem &ti=*(CConfigItem *)pHint;        HTREEITEM h=ti.HItem();        AdjustItemImage(h);        switch(ti.Type()){        case CConfigItem::Integer:          //		            case CConfigItem::Boolean:          //		            case CConfigItem::Radio:          {            ItemIntegerType n=ti.Value();            Refresh (h);            for(HTREEITEM hc=GetChildItem(h);hc;hc=GetNextSiblingItem (hc)){              Refresh (hc);            }            /*            // In the case of radio buttons, do the same thing to my siblings:            if(ti.Type()==CConfigItem::Radio && n==1){            for(HTREEITEM hs=ti.FirstRadio()->HItem();hs;hs=GetNextSiblingItem(hs)){            if(TI(hs).Type()==CConfigItem::Radio && hs!=h){            AdjustItemImage(hs);            // Enable or disable their children            for(HTREEITEM hn=GetChildItem(hs);hn;hn=GetNextSiblingItem(hn)){            Refresh (hn);            }            }            }            }            */            if(pDoc->m_bAutoExpand){              if ( (0==(GetItemState(h,TVIS_EXPANDED) & TVIS_EXPANDED)) != (0==n) ){                Expand(h,n?TVE_EXPAND:TVE_COLLAPSE);                SetScrollRangePos();              }                            //SetHScrollRangePos();              if(CConfigTool::GetCellView()){                CConfigTool::GetCellView()->Invalidate();              }            }          }          break;        default:          break;        }        CRect rect;        GetItemRect(h,rect,FALSE);        InvalidateRect(rect);      }		              break;    case CConfigToolDoc::ExternallyChanged:      {        for(int nItem=0;nItem<pDoc->ItemCount();nItem++){          CConfigItem *pItem=pDoc->Item(nItem);          AdjustItemImage(pItem->HItem());        }      }      break;    case 0:      if(pDoc->ItemCount()>0)      {        CRect rect;        GetItemRect(GetFirstVisibleItem(),rect,FALSE);        m_nItemHeight=rect.Height();        m_nWorkspace=m_nItemHeight;        SetScrollRangePos();        SetHScrollRangePos(); #ifdef _DEBUG        int nCP=0;        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)        {          CConfigItem *pItem=pDoc->Item(nItem);          ASSERT(pItem->HItem());          switch(pItem->Type()){          case CConfigItem::None:            break;          case CConfigItem::String:          case CConfigItem::Enum:          case CConfigItem::Integer:          case CConfigItem::Double:            //		case CConfigItem::Boolean:            nCP++;            break;            //		case CConfigItem::Radio:            //			nCP+=(pItem==pItem->FirstRadio());            //			break;          default:            ASSERT(FALSE);            break;          }        }        TRACE(_T("### done creating - %d config items created: %d configuration points\n"),GetCount(),nCP);#endif                SetScrollRangePos();              }    default:      break; // not for us, apparently  }  UNUSED_ALWAYS(pSender);}void CControlView::OnRestoreDefaults() {  if(TI(m_hContext).HasModifiedChildren())  {    switch(CUtils::MessageBoxFT(MB_YESNOCANCEL,_T("Restore defaults for nested items?")))    {    case IDYES:      RestoreDefault(m_hContext,TRUE);      break;    case IDNO:      RestoreDefault(m_hContext,FALSE);      break;    case IDCANCEL:      break;    default:      ASSERT(FALSE);      break;    }  } else   {    RestoreDefault(m_hContext,FALSE);  }    // current values may have changed so refresh the other views  //CConfigTool::GetConfigToolDoc ()->UpdateFailingRuleCount ();  if (TI (m_hContext).Type () != CConfigItem::None)    CConfigTool::GetConfigToolDoc ()->UpdateAllViews (NULL, CConfigToolDoc::ValueChanged, (CObject *) GetItemData (m_hContext));}void CControlView::OnPopupProperties() {  if(NULL==m_hContext){    m_hContext=GetSelectedItem();  }  if(NULL!=m_hContext){    CCTPropertiesDialog dlg(TI(m_hContext));    dlg.DoModal();    m_hContext=NULL;  }}void CControlView::RestoreDefault(HTREEITEM h, BOOL bRecurse /* = FALSE */, BOOL bTopLevel /* = TRUE */){  CConfigItem &ti = TI (h);  const CdlValuable valuable = ti.GetCdlValuable();  if (valuable && (CdlValueFlavor_None != valuable->get_flavor ())) // skip the root node and nodes without a value    valuable->set_source (CdlValueSource_Default);  SetItemText (h, ti.ItemNameOrMacro ()); // remove asterisk in control view    if (bTopLevel && ti.HasRadio ()) // if user-specified item is a radio button  {    for (CConfigItem * pItem = ti.FirstRadio (); pItem; pItem = pItem->NextRadio ())    {      if (&ti != pItem)      {        const CdlValuable valuable = pItem->GetCdlValuable();        ASSERT (valuable);        valuable->set_source (CdlValueSource_Default); // restore default for each sibling radio button        SetItemText (pItem->HItem (), pItem->ItemNameOrMacro ()); // remove asterisk in control view      }          }  }    if (bRecurse)  {    for (h = GetChildItem (h); h; h = GetNextSiblingItem (h))    {      RestoreDefault (h, TRUE, FALSE);    }  }}BOOL CControlView::IsChanged(HTREEITEM h, BOOL bRecurse){  BOOL rc = TI (h).Modified ();  //	CConfigItem &ti=TI(h);  //	BOOL rc=(0!=ti.StringDefaultValue().Compare(ti.StringValue()));		  if(!rc && bRecurse)  {    for(h=GetChildItem(h);h;h=GetNextSiblingItem(h))    {      if(IsChanged(h,TRUE))      {        rc=TRUE;        break;      }    }  }  return rc;}void CControlView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {  if(nChar==VK_APPS){    HTREEITEM h=GetSelectedItem();    ShowPopupMenu(h);    return;  }  CTreeView::OnKeyDown(nChar, nRepCnt, nFlags);}void CControlView::InvalidateItem(HTREEITEM h){  if(CConfigTool::GetCellView()->ActiveCell()==h)  {    //m_pwndCell->Invalidate();  }   else   {    CRect rect;    GetItemRect(h,rect,FALSE);    InvalidateRect(rect);  }}/*void CControlView::OnViewSwitches() {m_bSwitches ^= 1;	CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();for(int nItem=0;nItem<pDoc->ItemCount();nItem++){CConfigItem *pItem=pDoc->Item(nItem);HTREEITEM h=pItem->HItem();if(pItem->m_Icon==CConfigItem::IconCheckbox){pItem->m_Icon=CConfigItem::IconSwitch;} else if(pItem->m_Icon==CConfigItem::IconSwitch){pItem->m_Icon=CConfigItem::IconCheckbox;}AdjustItemImage(h);}  Invalidate();      }          void CControlView::OnUpdateViewSwitches(CCmdUI* pCmdUI)       {      pCmdUI->SetCheck(m_bSwitches);      }              void CControlView::OnViewCheckboxes()         {        OnViewSwitches();        }        void CControlView::OnUpdateViewCheckboxes(CCmdUI* pCmdUI)         {        pCmdUI->SetCheck(!m_bSwitches);        }*/void CControlView::OnViewUrl() {  TI(m_hContext).ViewURL();}bool CControlView::BumpItem(HTREEITEM h,int nInc){  bool rc=false;  // Take an action for clicking on the icon  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  CConfigItem &ti=TI(h);    // do not modify the option value if it is inactive or not modifiable  const CdlValuable valuable = ti.GetCdlValuable();  if (!valuable || (valuable->is_modifiable () && valuable->is_active ())) {    if (0 == nInc) // if a toggle request    {      if (ti.HasBool () && ! (ti.HasRadio () && ti.IsEnabled ())) { // only enable (not disable) a radio button        rc=pDoc->SetEnabled (ti, ! ti.IsEnabled ()); // toggle enabled/disabled state      }    } else if (ti.IsEnabled ()) { // the item is enabled...      switch(ti.Type())      {      case CConfigItem::None:      case CConfigItem::String:      case CConfigItem::Double:        break;      case CConfigItem::Enum:        {          CStringArray arEnum;          ti.EvalEnumStrings (arEnum); // calculate legal values just in time          if (0==arEnum.GetSize()) // if no legal values...            break;           // ...do nothing          int nIndex = -1;          const CString strCurrent = ti.StringValue ();          for (int nEnum = 0; (nEnum < arEnum.GetSize()) && (nIndex == -1); nEnum++)            if (0 == arEnum[nEnum].Compare (strCurrent))						        nIndex = nEnum; // the index of the current value            				        if (nIndex != -1) // if the current value is still legal                  nIndex += (nInc < 0 ? -1 : 1); // increment/decrement the index                else                  nIndex = 0; // otherwise select the first enum                                if (nIndex < 0) // if the new index is negative                  nIndex = arEnum.GetSize()-1; // make it positive                                rc=pDoc->SetValue (ti, arEnum[nIndex % arEnum.GetSize()]);        }        break;      case CConfigItem::Integer:        {          ItemIntegerType nOldValue=Value(h);          if(nInc==1 && nOldValue==ItemIntegerType (-1)){            nOldValue=0;          } else if(nInc==-1 && nOldValue==0){            nOldValue=ItemIntegerType (-1);          } else {            nOldValue+=nInc;          }          rc=pDoc->SetValue(ti,nOldValue);          break;        }                break;        /*        case CConfigItem::Boolean:                  {          ItemIntegerType nOldValue=Value(h);          pDoc->SetValue(ti,nOldValue^1);          }          break;		        case CConfigItem::Radio:                          if(0==Value(h)){              pDoc->SetValue(ti, (ItemIntegerType) 1);              }              break;        */      default:        ASSERT(FALSE);        break;      }    }  }  return rc;}int CControlView::OnCreate(LPCREATESTRUCT lpCreateStruct) {  if (CTreeView::OnCreate(lpCreateStruct) == -1)    return -1;    BOOL b=m_il.Create(IDB_BITMAP2,16,1,RGB(0,128,128));    // This code is necessary because of what appears to be an inconsistency between  // different versions of the common control dll.  In some the text rectangles seem  // not to take into account the offset introduced by the item image of the root item.  // The offset is used in the OnPaint handler to make sure the greyed text is in the  // right place.    // Begin hack  {    HTREEITEM h=InsertItem(_T("Foo"));    CRect rect1,rect2;    GetItemRect(h,rect1,TRUE);        SetImageList(&m_il,TVSIL_NORMAL);    GetItemRect(h,rect2,TRUE);    m_TreeXOffsetAdjustment=rect1.left==0?(rect2.left-rect1.left):0;    DeleteItem(h);  }  // End hack    ASSERT(b);    CRect rcClient;  GetClientRect(rcClient);	  CSplitterWnd *pSplitter=(CSplitterWnd*)GetParent();  pSplitter->SetColumnInfo(1,rcClient.Width()/4,0);    return 0;}void CControlView::KillScrollBars(){  CSplitterWnd *pSplit=(CSplitterWnd *)GetParent();  int min,curX,curY;  const int col=0;  pSplit->GetColumnInfo(col,curX,min);  if(-1==curX){    return;  }  pSplit->GetRowInfo   (0,curY,min);  if(-1==curY){    return;  }  CRect rcClient;  GetClientRect(rcClient);  /*  TRACE("splitter[%d]=(%d,%d) view=(%d,%d)",		col,    curX,curY,    rcClient.Width(),rcClient.Height());		*/  if(curX>rcClient.Width()&&curY>rcClient.Height()){    //sdf ShowScrollBar(SB_BOTH,FALSE);    ShowScrollBar(SB_VERT,FALSE);  } else {    if(curX>rcClient.Width()){      //TRACE(" -VERT\n");      ShowScrollBar(SB_VERT,FALSE);    }    if(curY>rcClient.Height()){      //TRACE(" -HORZ\n");      //sdf ShowScrollBar(SB_HORZ,FALSE);    }  }  //TRACE("\n");}void CControlView::SetScrollPos(){  if(m_bHasVScroll==1){    CRect rect;    GetTreeCtrl().GetItemRect(GetTreeCtrl().GetRootItem(),rect,FALSE);    CScrollBar *cv=(CScrollBar *)(GetParent()->GetDlgItem(AFX_IDW_VSCROLL_FIRST));    //BOOL cv=TRUE;    if(cv && m_bHasVScroll){      //TRACE("SetScrollPos %d\n",-rect.top);      cv->SetScrollPos(-rect.top);      //SetScrollInfo(SB_VERT,&si,SIF_POS);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -