BOOL CCellView::InCell(HTREEITEM h) { CancelCellEdit(); if(h && TI(h).IsEnabled()){ CConfigItem &ti=TI(h); // edit cell only if option is both active and modifiable const CdlValuable valuable = ti.GetCdlValuable(); // check packages explicitly because is_modifiable() returns true for a package if ((! valuable) || (valuable->is_modifiable () && valuable->is_active () && ! ti.IsPackage ())){ CRect rcEdit; GetItemRect(h,rcEdit); rcEdit.bottom++; switch(ti.Type()){ case CConfigItem::Double: { double d; CUtils::StrToDouble(ti.StringValue(),d); m_pwndCell=new CDoubleEdit(d); m_pwndCell->Create(WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, rcEdit, this, IDC_CELL); } break; case CConfigItem::Integer: { ItemIntegerType i; CUtils::StrToItemIntegerType(ti.StringValue(),i); m_pwndCell=new CIntegerEdit(i); } m_pwndCell->Create(WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, rcEdit, this, IDC_CELL); break; case CConfigItem::String: { CStringEdit *pStringEdit=new CStringEdit(ti.StringValue()); m_pwndCell=pStringEdit; m_pwndCell->Create(WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL, rcEdit, this, IDC_CELL); pStringEdit->EnableDoubleClickEdit(true,IDC_CT_EDIT); } break; case CConfigItem::Enum: { CStringArray arEnum; ti.EvalEnumStrings(arEnum); rcEdit.bottom += (2+(int)arEnum.GetSize()-1)*rcEdit.Height(); m_pwndCell=new CComboEdit(ti.StringValue(),arEnum); m_pwndCell->Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST, rcEdit, this, IDC_CELL); } break; default: return 0; break; } m_hInCell=h; m_pwndCell->SetFont(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT))); m_pwndCell->SetFocus(); m_pwndCell->GetWindowText(m_strInitialCell); } } return NULL!=m_hInCell; }
bool ecConfigItem::IsModifiable() const { const CdlValuable valuable = GetCdlValuable(); if (valuable && ((GetOptionType() != ecOptionTypeNone) || HasBool())) { return (valuable->is_modifiable () && valuable->is_active ()); } else return GetCdlItem()->is_active(); }
// Bump by specified amount, or toggle if a boolean value bool ecConfigItem::BumpItem(int nInc) { bool rc = FALSE; // Take an action for clicking on the icon ecConfigToolDoc* pDoc = wxGetApp().GetConfigToolDoc(); // do not modify the option value if it is inactive or not modifiable const CdlValuable valuable = GetCdlValuable(); if (!valuable || (valuable->is_modifiable () && valuable->is_active ())) { if (0 == nInc) // if a toggle request { if (HasBool () && ! (HasRadio () && IsEnabled ())) { // only enable (not disable) a radio button rc = pDoc->SetEnabled (*this, ! this->IsEnabled ()); // toggle enabled/disabled state } } else if (IsEnabled ()) { // the item is enabled... switch(GetOptionType()) { case ecOptionTypeNone: case ecString: case ecDouble: break; case ecEnumerated: { wxArrayString arEnum; EvalEnumStrings (arEnum); // calculate legal values just in time if (0==arEnum.Count()) // if no legal values... break; // ...do nothing int nIndex = -1; const wxString strCurrent = StringValue (); int nEnum; for (nEnum = 0; (nEnum < arEnum.Count()) && (nIndex == -1); nEnum++) if (strCurrent == arEnum[nEnum]) 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.Count()-1; // make it positive rc=pDoc->SetValue (*this, arEnum[nIndex % arEnum.Count()]); } break; case ecLong: { // TODO: if we're editing, we should get the value in the edit item // and not the ecConfigItem. long nOldValue = Value(); if(nInc==1 && nOldValue==-1){ nOldValue=0; } else if(nInc==-1 && nOldValue==0){ nOldValue=-1; } else { nOldValue+=nInc; } rc=pDoc->SetValue(*this, 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: break; } } } return rc; }
void CCellView::OnDraw(CDC* pDC) { CTreeCtrl &Tree=CConfigTool::GetControlView()->GetTreeCtrl(); CConfigToolDoc* pDoc=CConfigTool::GetConfigToolDoc(); if(pDoc->ItemCount()>0) { CRect rect; Tree.GetItemRect(Tree.GetRootItem(),rect,TRUE); m_nFirstVisibleItem=rect.top; CRect rcClient; GetClientRect(rcClient); CPen *pOldPen=pDC->SelectObject(&m_GrayPen); CFont *pOldFont=pDC->SelectObject(CConfigTool::GetControlView()->GetFont()); pDC->SetBkMode(TRANSPARENT); CRect rcClip; pDC->GetClipBox(rcClip); CPtrArray arItems; int dy=CConfigTool::GetControlView()->GetItemHeight(); int cy=0; for(HTREEITEM h=Tree.GetFirstVisibleItem();h;h=Tree.GetNextVisibleItem(h)) { if(cy>rcClip.bottom){ break; } CRect rcEdit(0,cy,rcClient.right,cy+dy); cy+=dy; pDC->MoveTo(rcClient.left,rcEdit.top); pDC->LineTo(rcClient.right,rcEdit.top); CConfigItem &ti=TI(h); if(h!=m_hInCell){ switch(ti.Type()){ case CConfigItem::Enum: // Using combobox rcEdit.left+=2; rcEdit.top+=2; // fall through case CConfigItem::Integer: case CConfigItem::Double: case CConfigItem::String: // Using editbox rcEdit.top+=2; rcEdit.left+=3; { CString str(ti.StringValue()); // cell contents is greyed if the option is not both active and modifiable // or if a booldata item is not enabled const CdlValuable valuable = ti.GetCdlValuable(); // check for a package explicitly because is_modifiable() returns true for a package pDC->SetTextColor (GetSysColor ((! valuable) || (valuable->is_modifiable () && valuable->is_active () && ((! ti.HasBool ()) || ti.IsEnabled ()) && ! ti.IsPackage ()) ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT)); pDC->TextOut(rcEdit.left,rcEdit.top,str); } break; default: break; } } } pDC->MoveTo(rcClient.left,cy); pDC->LineTo(rcClient.right,cy); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldFont); } }