/// <summary> /// Show Properties dialog. Return true if list is changed /// </summary> /// <param name="parent"></param> /// <returns></returns> public bool ShowPropertiesDialog(MkaDocument parent) { if (SelectionCount < 1) { return(false); } MkaMokkanInfo info = new MkaMokkanInfo(); GraphicsProperties properties = new GraphicsProperties(); bool multi = (SelectionCount > 1); // get properties from selected object GetProperties(ref info, ref properties); MkaPropertiesMokkan dlg = new MkaPropertiesMokkan(this, info, properties, multi); CommandChange c = new CommandChange(this); if (dlg.ShowDialog(parent) != DialogResult.OK) { return(false); } if (ApplyProperties(dlg.MokkanProperty, dlg.Properties)) { c.NewState(this); parent.AddCommandToHistory(c); return(true); } return(false); }
/// <summary> /// Constructor /// </summary> public DrawObject() { _id = this.GetHashCode(); _mkaInfo = new MkaMokkanInfo(); _mkaInfo.Properties = GraphicsProperties.LastProperties.Clone(); _selected = false; }
/// <summary> /// Constructor /// </summary> public MkaPropertiesMokkan(MokkanList mokkans, MkaMokkanInfo info, GraphicsProperties properties, bool multi) { InitializeComponent(); MokkanList = mokkans; MokkanProperty = info; Properties = properties; mkaGraphicsProperties.Properties = Properties; _multi = multi; }
public virtual void FromXml(XmlElement xmlEle, IXmlContext cnt) { XmlElement _infoEle = xmlEle["info"]; if (null != _infoEle) { _mkaInfo = cnt.FromXml(_infoEle as XmlElement) as MkaMokkanInfo; } XmlElement _formatEle = xmlEle["format"]; if (null != _formatEle) { _mkaInfo.Properties = cnt.FromXml(_formatEle as XmlElement) as GraphicsProperties; } }
/// <summary> /// Store previous status /// </summary> private void propertyGrid_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e) { if (SelectedType == SelectedObjectType.Mokkan) { command = new CommandChange(MokkanList); } int i; if (propertyGrid.SelectedObjects.Length > 1) { Rids = new int[propertyGrid.SelectedObjects.Length]; for (i = 0; i < propertyGrid.SelectedObjects.Length; i++) { MkaMokkanInfo mk = (MkaMokkanInfo)propertyGrid.SelectedObjects[i]; Rids[i] = mk.RBangou; } } }
/// <summary> /// Check id is duplicated or not /// </summary> private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { GridItem changedItem = e.ChangedItem; _sError = ""; _error = false; if ((changedItem.PropertyDescriptor.Name == MkaDefine.BatOoChiku) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatChuushouChiku) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatIkoumei) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatDosoumei) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatDate) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatBangou) || (changedItem.PropertyDescriptor.Name == MkaDefine.GlassItaBangou)) { String value = changedItem.Value.ToString().Trim(); if (value == String.Empty) { _sError = String.Format(MkaMessage.ErrInputRequest, changedItem.PropertyDescriptor.DisplayName); _error = true; changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } } else if ((changedItem.PropertyDescriptor.Name == MkaDefine.BatChousaJisuu) || (changedItem.PropertyDescriptor.Name == MkaDefine.BatGrid) || (changedItem.PropertyDescriptor.Name == MkaDefine.GlassKaishiRBangou)) { int value = Convert.ToInt32(changedItem.Value); if (value <= 0) { _sError = String.Format(MkaMessage.ErrNumberRequest, changedItem.PropertyDescriptor.DisplayName); _error = true; changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } else { if (changedItem.PropertyDescriptor.Name == MkaDefine.GlassKaishiRBangou) { DocumentArea.Rearrange(value - (int)e.OldValue); } } } else if (changedItem.PropertyDescriptor.Name == MkaDefine.MokkanRBangou) { int rid = Convert.ToInt32(changedItem.Value); if (rid < 0) { _sError = String.Format(MkaMessage.ErrNumberRequest, changedItem.PropertyDescriptor.DisplayName); _error = true; changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } else if (MokkanList.CheckDoubleRID(rid)) { _sError = String.Format(MkaMessage.ErrDublication, changedItem.Label); _error = true; if (propertyGrid.SelectedObjects.Length == 1) { changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } else { int i; for (i = 0; i < propertyGrid.SelectedObjects.Length; i++) { MkaMokkanInfo mk = (MkaMokkanInfo)propertyGrid.SelectedObjects[i]; mk.RBangou = Rids[i]; } } } } else if (changedItem.PropertyDescriptor.Name == MkaDefine.GraphicPenWidth) { float penWid = (float)Convert.ToDouble(changedItem.Value); if (penWid < 0.25 || penWid > 6) { _sError = MkaMessage.ErrInvalidPenWidth; _error = true; changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } } else if (changedItem.PropertyDescriptor.Name == MkaDefine.GraphicColorAlpha) { int alpha = Convert.ToInt32(changedItem.Value); if (alpha < 0 || alpha > 255) { _sError = MkaMessage.ErrInvalidAlpha; _error = true; changedItem.PropertyDescriptor.SetValue(propertyGrid.SelectedObject, e.OldValue); } } if (_error) { MkaMessage.ShowError(_sError); this.Focus(); changedItem.Select(); return; } if (SelectedType == SelectedObjectType.Mokkan) { command.NewState(MokkanList); DocumentArea.AddCommandToHistory(command); } DocumentArea.SetDirty(); // raise data change event _owner.PropertyDataChange(); }
/// <summary> /// Apply properties for all selected objects. /// Returns TRue if at least one property is changed. /// </summary> private bool ApplyProperties(MkaMokkanInfo info, GraphicsProperties properties) { bool changed = false; if (SelectionCount == 1) { if (SelectedObjects[0].MokkanInfo.RBangou != info.RBangou) { SelectedObjects[0].MokkanInfo.RBangou = info.RBangou; changed = true; } } foreach (DrawObject o in Selection) { if (o.MokkanInfo.KariShakubun != info.KariShakubun) { o.MokkanInfo.KariShakubun = info.KariShakubun; changed = true; } if (o.MokkanInfo.GaihouShoshuuJyouhou != info.GaihouShoshuuJyouhou) { o.MokkanInfo.GaihouShoshuuJyouhou = info.GaihouShoshuuJyouhou; changed = true; } if (o.MokkanInfo.ShasinBangouJyouhou != info.ShasinBangouJyouhou) { o.MokkanInfo.ShasinBangouJyouhou = info.ShasinBangouJyouhou; changed = true; } if (o.MokkanInfo.Bikou != info.Bikou) { o.MokkanInfo.Bikou = info.Bikou; changed = true; } // border color if (o.Properties.BorderColor != properties.BorderColor) { o.Properties.BorderColor = properties.BorderColor; changed = true; } // border pen width if (o.Properties.PenWidth != properties.PenWidth) { o.Properties.PenWidth = properties.PenWidth; changed = true; } // fill area color if (o.Properties.FillColor != properties.FillColor) { o.Properties.FillColor = properties.FillColor; changed = true; } // fill area transparent if (o.Properties.FillColorAlpha != properties.FillColorAlpha) { o.Properties.FillColorAlpha = properties.FillColorAlpha; changed = true; } // remain id show position if (o.Properties.RShowPosition != properties.RShowPosition) { o.Properties.RShowPosition = properties.RShowPosition; changed = true; } } return(changed); }
/// <summary> /// Get properties from selected objects and fill GraphicsProperties instance /// </summary> /// <returns></returns> private void GetProperties(ref MkaMokkanInfo info, ref GraphicsProperties properties) { bool bFirst = true; string firstKariShakubun = ""; string firstGaihouShoshuuJyouhou = ""; string firstShashinBangouJyouhou = ""; string firstBikou = ""; string firstBorderColor = ""; float firstPenWidth = 1; string firstFillColor = ""; int firstAreaAlpha = 0; ShowPosition firstPos = ShowPosition.Top; bool allKariShakubunAreEqual = true; bool allGaihouShoshuuJyouhouAreEqual = true; bool allShashinBangouJyouhouAreEqual = true; bool allBikouAreEqual = true; bool allBorderColorAreEqual = true; bool allPenWidthAreEqual = true; bool allFillColorAreEqual = true; bool allAreaAlphaAreEqual = true; bool allShowPosAreEqual = true; foreach (DrawObject o in Selection) { if (bFirst) { firstKariShakubun = o.MokkanInfo.KariShakubun; firstGaihouShoshuuJyouhou = o.MokkanInfo.GaihouShoshuuJyouhou; firstShashinBangouJyouhou = o.MokkanInfo.ShasinBangouJyouhou; firstBikou = o.MokkanInfo.Bikou; firstBorderColor = o.Properties.BorderColorHtml; firstPenWidth = o.Properties.PenWidth; firstFillColor = o.Properties.FillColorHtml; firstAreaAlpha = o.Properties.FillColorAlpha; firstPos = o.Properties.RShowPosition; bFirst = false; } else { if (o.MokkanInfo.KariShakubun != firstKariShakubun) { allKariShakubunAreEqual = false; } if (o.MokkanInfo.GaihouShoshuuJyouhou != firstGaihouShoshuuJyouhou) { allGaihouShoshuuJyouhouAreEqual = false; } if (o.MokkanInfo.ShasinBangouJyouhou != firstShashinBangouJyouhou) { allShashinBangouJyouhouAreEqual = false; } if (o.MokkanInfo.Bikou != firstBikou) { allBikouAreEqual = false; } if (o.Properties.BorderColorHtml != firstBorderColor) { allBorderColorAreEqual = false; } if (o.Properties.PenWidth != firstPenWidth) { allPenWidthAreEqual = false; } if (o.Properties.FillColorHtml != firstFillColor) { allFillColorAreEqual = false; } if (o.Properties.FillColorAlpha != firstAreaAlpha) { allAreaAlphaAreEqual = false; } if (o.Properties.RShowPosition != firstPos) { allShowPosAreEqual = false; } } } if (SelectionCount == 1) { info.RBangou = SelectedObjects[0].MokkanInfo.RBangou; } if (allKariShakubunAreEqual) { info.KariShakubun = firstKariShakubun; } if (allGaihouShoshuuJyouhouAreEqual) { info.GaihouShoshuuJyouhou = firstGaihouShoshuuJyouhou; } if (allShashinBangouJyouhouAreEqual) { info.ShasinBangouJyouhou = firstShashinBangouJyouhou; } if (allBikouAreEqual) { info.Bikou = firstBikou; } if (allBorderColorAreEqual) { properties.BorderColor = ColorTranslator.FromHtml(firstBorderColor); } if (allPenWidthAreEqual) { properties.PenWidth = firstPenWidth; } if (allFillColorAreEqual) { properties.FillColor = ColorTranslator.FromHtml(firstFillColor); } if (allAreaAlphaAreEqual) { properties.FillColorAlpha = firstAreaAlpha; } if (allShowPosAreEqual) { properties.RShowPosition = firstPos; } }