/// <summary> /// Will return the resources for the provided digital signature. /// </summary> /// <param name="signature">The signature to get resources for.</param> /// <returns>The signature resources.</returns> internal static SignatureResources GetResources(DigitalSignature signature, CertificatePriorityStatus certStatus) { const int defaultHeight = 35; const int defaultWidth = 35; SignatureResources resources = new SignatureResources(); string none = SR.Get(SRID.SignatureResourceHelperNone); resources._displayImage = GetImageFromStatus( defaultHeight, defaultWidth, signature.SignatureState, certStatus); resources._location = string.IsNullOrEmpty(signature.Location) ? none : signature.Location; resources._reason = string.IsNullOrEmpty(signature.Reason) ? none : signature.Reason; resources._signBy = GetFormattedDate(signature.SignedOn); resources._subjectName = signature.SubjectName; resources._summaryMessage = GetSummaryMessage(signature, certStatus); Trace.SafeWrite( Trace.Rights, "Resources generated for {0} summary: {1}", resources._subjectName, resources._summaryMessage); return(resources); }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ /// <summary> /// oKButton_Click /// </summary> private void _addButton_Click(object sender, EventArgs e) { //Check to see this the input is valid if (ValidateUserData()) { //Create SignatureResource to pass back to DocumentSignatureManager SignatureResources sigResources = new SignatureResources(); //Get the user data. sigResources._subjectName = _requestedSignerNameTextBox.Text; sigResources._reason = _intentComboBox.Text; sigResources._location = _requestedLocationTextBox.Text; //Add the SignatureDefinition. _documentSignatureManager.OnAddRequestSignature(sigResources, _dateTimePicker.Value); //Close the Add Request dialog Close(); } else { System.Windows.MessageBox.Show( SR.Get(SRID.DigitalSignatureWarnErrorReadOnlyInputError), SR.Get(SRID.DigitalSignatureWarnErrorSigningErrorTitle), System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation ); } }
/// <summary> /// _listBoxSummary_DrawItem handles the DrawItem event. /// </summary> /// <param name="sender">object</param> /// <param name="e">DrawItemEventArgs</param> /// <returns></returns> private void _listBoxSummary_DrawItem(object sender, DrawItemEventArgs e) { // draws it if this is a valid item if (e.Index > -1 && e.Index < _listBoxSummary.Items.Count) { // if we can draw the item we do SignatureResources item = (SignatureResources)_listBoxSummary.Items[e.Index]; e.DrawBackground(); DrawListBoxSummaryItem(e.Graphics, e.Bounds, item, _listBoxSummary.SelectedIndex == e.Index ); e.DrawFocusRectangle(); } }
/// <summary> /// CalculateItemHeight calculates the height for a ListBox item. /// </summary> /// <param name="graphics"></param> /// <param name="item">ListBoxSummaryItem</param> /// <returns></returns> private int CalculateItemHeight(Graphics graphics, SignatureResources item) { // //Determine the height of all the text fields taking into account //the reserved widths and padding. All height/padding and width are //non-negative // int heightIntent = (int)graphics.MeasureString(item._reason, _listBoxSummary.Font, IntentTextWidth - CellPadding.Left - CellPadding.Right).Height; int heightSummary = 0; int heightSignBy = 0; int heightLocale = 0; if (_showRequestDialog) { // For the request dialog, we use the subject name instead of the summary message heightSummary = (int)graphics.MeasureString(item._subjectName, _listBoxSummary.Font, SummaryNameTextWidth - CellPadding.Left - CellPadding.Right).Height; heightSignBy = (int)graphics.MeasureString(item._signBy, _listBoxSummary.Font, SignByTextWidth - CellPadding.Left - CellPadding.Right).Height; heightLocale = (int)graphics.MeasureString(item._location, _listBoxSummary.Font, LocaleTextWidth - CellPadding.Left - CellPadding.Right).Height; } else { heightSummary = (int)graphics.MeasureString(item._summaryMessage, _listBoxSummary.Font, SummaryNameTextWidth - CellPadding.Left - CellPadding.Right).Height; } //Want to return the biggest height. int h = Math.Max(Math.Max(Math.Max(Math.Max(IconHeight, heightSummary), heightIntent), heightLocale), heightSignBy); //Will return max text height plus the cellpadding. return(h + CellPadding.Top + CellPadding.Bottom); }
/// <summary> /// DrawListBoxSummaryItem draws the item in the given bounds and /// taking the reserved widths and padding. /// </summary> /// <param name="sender">object</param> /// <param name="e">DrawItemEventArgs</param> /// <returns></returns> private void DrawListBoxSummaryItem(Graphics graphics, Rectangle bounds, SignatureResources item, bool isSelected) { StringFormat stringFormat = new StringFormat(); // Determine the StringFormat we use to render our text -- for // RTL we need to set the DirectionRightToLeft Flag, for LTR // we use the default. // Additionally, in RTL we right-align rendered text to its bounding // rect (StringAlignment.Near). if (RightToLeft == RightToLeft.Yes) { stringFormat.LineAlignment = StringAlignment.Near; stringFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft; } // Calculate the X offsets for the bounding rects for the items we're // going to display (for RTL the X coordinates are effectively mirrored) int iconXOffset; int statusXOffset; int intentXOffset; // Flip for RTL Layout if (RightToLeftLayout) { iconXOffset = bounds.Right - (CellPadding.Right + IconWidth); // We offset the status and intent text by the padding on both sides so that the // right edge of the text is properly aligned with the column header. statusXOffset = bounds.Right + CellPadding.Right - (IconWidth + SummaryNameTextWidth); intentXOffset = bounds.Right + CellPadding.Right + CellPadding.Left - (IconWidth + SummaryNameTextWidth + IntentTextWidth); } else { iconXOffset = bounds.Left + CellPadding.Left; statusXOffset = bounds.Left + IconWidth + CellPadding.Left; intentXOffset = bounds.Left + IconWidth + SummaryNameTextWidth + CellPadding.Left; } // The text color for this item Brush brush = isSelected ? SystemBrushes.HighlightText : SystemBrushes.ControlText; //Create bounds to draw Icon Rectangle iconRect = new Rectangle( iconXOffset, bounds.Y + CellPadding.Top, IconWidth - CellPadding.Left - CellPadding.Right, bounds.Height - CellPadding.Top - CellPadding.Bottom ); //All padding and width are non-negative. //Create bounds to draw Name / Status text Rectangle statusRect = new Rectangle( statusXOffset, bounds.Y + CellPadding.Top, SummaryNameTextWidth - CellPadding.Left - CellPadding.Right, bounds.Height - CellPadding.Top - CellPadding.Bottom ); //Create bounds to draw Intent text Rectangle intentRect = new Rectangle( intentXOffset, bounds.Y + CellPadding.Top, IntentTextWidth - CellPadding.Left - CellPadding.Right, bounds.Height - CellPadding.Top - CellPadding.Bottom ); if (_showRequestDialog) { int signByXOffset; int localeXOffset; //Flip for RTL Layout if (RightToLeftLayout) { // We offset the sign by and locale text by the padding on both sides so that the // right edge of the text is properly aligned with the column header. signByXOffset = bounds.Left + CellPadding.Left + CellPadding.Right; localeXOffset = bounds.Left + CellPadding.Left + CellPadding.Right + SignByTextWidth; } else { signByXOffset = bounds.Left + IconWidth + SummaryNameTextWidth + IntentTextWidth + SignByTextWidth + CellPadding.Left; localeXOffset = bounds.Left + IconWidth + SummaryNameTextWidth + IntentTextWidth + CellPadding.Left; } //Create bounds to draw SignedBy text Rectangle signByRect = new Rectangle( signByXOffset, bounds.Y + CellPadding.Top, SignByTextWidth - CellPadding.Left - CellPadding.Right, bounds.Height - CellPadding.Top - CellPadding.Bottom ); //Create bounds to draw Locale text Rectangle localeRect = new Rectangle( localeXOffset, bounds.Y + CellPadding.Top, LocaleTextWidth - CellPadding.Left - CellPadding.Right, bounds.Height - CellPadding.Top - CellPadding.Bottom ); //Draw the Name Text graphics.DrawString(item._subjectName, _listBoxSummary.Font, brush, statusRect, stringFormat); //Draw the SignedBy Text graphics.DrawString(item._signBy, _listBoxSummary.Font, brush, signByRect, stringFormat); //Draw the locale Text graphics.DrawString(item._location, _listBoxSummary.Font, brush, localeRect, stringFormat); } else { //Draw the summary text graphics.DrawString(item._summaryMessage, _listBoxSummary.Font, brush, statusRect, stringFormat); //Draw the icon Debug.Assert(item._displayImage != null, "Signature icon is null"); if (item._displayImage != null) { graphics.DrawImage(item._displayImage, iconRect.Location); } } //Draw the Intent Text graphics.DrawString(item._reason, _listBoxSummary.Font, brush, intentRect, stringFormat); }
/// <summary> /// AddDigSig add the Dig Sig to the ListBox. /// </summary> /// <param name="rds">The IDigitalSignature to add to the ListBox.</param> /// <returns></returns> private void AddDigSig(SignatureResources signatureResources) { //Add the item to the ListBox. _listBoxSummary.Items.Add(signatureResources); }