// Read the current punch pattern out of the dotGrid PunchPattern GetPunchPattern() { PunchPattern punch = new PunchPattern(); punch.size = dotGrid.DotsAcross; punch.dots = dotGrid.GetAllDots(); if (punch.IsEmpty) { return(null); } else { return(punch); } }
// Place a punch pattern in the dot grid. void SetPunchPattern(PunchPattern punch) { if (punch == null) { dotGrid.DotsAcross = PunchcardAppearance.gridSize; dotGrid.DotsDown = PunchcardAppearance.gridSize; dotGrid.Clear(); } else { dotGrid.DotsAcross = punch.size; dotGrid.DotsDown = punch.size; dotGrid.SetAllDots(punch.dots); } }
private void Application_WindowBeforeRightClickEvent(Word.Selection curselection, ref bool cancel) { GlobalClass.myselection = curselection; var wordrange = GlobalClass.myword.Selection.Range; int left, top, width, height; GlobalClass.myword.ActiveWindow.GetPoint(out left, out top, out width, out height, wordrange); var curword = curselection.Range.Words[1].Text; var curwordcount = curselection.Range.Words.Count; PunchPattern punckPattern = null; if (_listpukPattern != null) { punckPattern = _listpukPattern.Find(t => t.IndexStart <= curselection.Range.Start && t.IndexEnd >= curselection.Range.End); } if (punckPattern != null && punckPattern.ErrorCode > 0) { cancel = true; _currentPuncPattern = punckPattern; _cpuncForm = new CPPPunctuation(); _cpuncForm.Deactivate += CpPuncForm_Deactivate; _cpuncForm.ShowBallonScreen(new Point(left, top)); _cpuncForm.ShowFormWithMessage = punckPattern.ErroMessage + Environment.NewLine + punckPattern.ErrorCorrection; } else { // else spell var isSpellisCorrect = _chkSpell.Cheak_Spell(curword.Trim()); if (curword.Trim().Length > 1 && curwordcount == 1 && isSpellisCorrect == false) { cancel = true; _cspellForm = new CPPSPell(); _cspellForm.Deactivate += cpSpellForm_Deactivate; _cspellForm.ShowBallonScreen(new Point(left, top)); var suggestList = _chkSpell.Suggest(curword); _cspellForm.ShowDlg(suggestList); } } }
// Draw a pattern of dots. The center of the edge dots are on the edges of the given rectangle, so the dots // protrude out a dot radius from the rectangle. private void DrawPattern(IGraphicsTarget g, PunchPattern pattern, RectangleF punchRect) { float dxPerDot = (pattern.size > 1) ? punchRect.Width / (pattern.size - 1) : 0; float dyPerDot = (pattern.size > 1) ? punchRect.Height / (pattern.size - 1) : 0; float r = PunchcardAppearance.dotRadius; for (int row = 0; row < pattern.size; ++row) { for (int col = 0; col < pattern.size; ++col) { if (pattern.dots[row, col]) { float xCenter = punchRect.Left + dxPerDot * col; float yCenter = punchRect.Top + dyPerDot * row; g.FillEllipse(blackBrush, new PointF(xCenter, yCenter), r, r); } } } }
// Render one punch box private void RenderPunchBox(IGraphicsTarget g, CourseView.ControlView controlView, RectangleF rect) { // Draw the ordinal number, if there is one. if (controlView.ordinal > 0) { DrawSingleLineText(g, controlView.ordinal.ToString(), PunchcardAppearance.controlNumberFont, new PointF(rect.Left + 6, rect.Top + 3), StringAlignment.Near, StringAlignment.Near); } // If it's a score course, and a score has been defined, then put the score. if (courseView.Kind == CourseView.CourseViewKind.Score) { int points = 0; if (controlView.courseControlIds[0].IsNotNone) { points = eventDB.GetCourseControl(controlView.courseControlIds[0]).points; } if (points > 0) { DrawSingleLineText(g, points.ToString(), PunchcardAppearance.scoreFont, new PointF((rect.Left + rect.Right) / 2, rect.Top + 3), StringAlignment.Center, StringAlignment.Near); } } // Draw the code. string code = string.Format("({0})", eventDB.GetControl(controlView.controlId).code); DrawSingleLineText(g, code, PunchcardAppearance.codeFont, new PointF(rect.Right - 5F, rect.Top + 3), StringAlignment.Far, StringAlignment.Near); // Draw the punch pattern. RectangleF punchRect = RectangleF.FromLTRB(rect.Left + 20F, rect.Top + 27.5F, rect.Right - 20F, rect.Bottom - 12.5F); PunchPattern pattern = eventDB.GetControl(controlView.controlId).punches; if (pattern != null) { DrawPattern(g, pattern, punchRect); } }
public void SetAllPunchPatterns() { Setup("changeevent\\speciallegs3.coursescribe"); Dictionary<string, PunchPattern> dict = new Dictionary<string, PunchPattern>(); PunchPattern pattern; pattern = new PunchPattern(); pattern.size = 9; pattern.dots = new bool[9,9]; pattern.dots[1,1] = pattern.dots[4,6] = pattern.dots[8,1] = true; dict["31"] = pattern; dict["32"] = null; pattern = new PunchPattern(); pattern.size = 9; pattern.dots = new bool[9, 9]; pattern.dots[6,1] = pattern.dots[6,4] = pattern.dots[6,7] = true; dict["34"] = pattern; undomgr.BeginCommand(811, "Set punch patterns"); ChangeEvent.SetAllPunchPatterns(eventDB, dict); undomgr.EndCommand(811); ControlPoint control = eventDB.GetControl(ControlId(2)); Assert.IsNotNull(control.punches); Assert.AreEqual(9, control.punches.size); Assert.IsTrue(control.punches.dots[1, 1]); Assert.IsTrue(control.punches.dots[4,6]); Assert.IsFalse(control.punches.dots[6, 4]); control = eventDB.GetControl(ControlId(3)); Assert.IsNull(control.punches); control = eventDB.GetControl(ControlId(5)); Assert.IsNotNull(control.punches); Assert.AreEqual(9, control.punches.size); Assert.IsTrue(control.punches.dots[6, 1]); Assert.IsTrue(control.punches.dots[6,4]); Assert.IsFalse(control.punches.dots[4,6]); dict.Clear(); dict["31"] = null; pattern = new PunchPattern(); pattern.size = 9; pattern.dots = new bool[9, 9]; pattern.dots[1, 1] = pattern.dots[4, 4] = pattern.dots[7, 7] = true; dict["34"] = pattern; undomgr.BeginCommand(811, "Set punch patterns"); ChangeEvent.SetAllPunchPatterns(eventDB, dict); undomgr.EndCommand(811); control = eventDB.GetControl(ControlId(2)); Assert.IsNull(control.punches); control = eventDB.GetControl(ControlId(3)); Assert.IsNull(control.punches); control = eventDB.GetControl(ControlId(5)); Assert.IsNotNull(control.punches); Assert.AreEqual(9, control.punches.size); Assert.IsTrue(control.punches.dots[1, 1]); Assert.IsTrue(control.punches.dots[4, 4]); Assert.IsFalse(control.punches.dots[6, 4]); Assert.IsFalse(control.punches.dots[4,6]); }