/// <summary> /// Constructor /// </summary> public AdifMacro() { AdifField = new StaticText(); SetValue(DesignTextPropertyKey, new TextParts()); DesignText.Add(new StaticText()); SetValue(NoFieldTextPropertyKey, new TextParts()); NoFieldText.Add(new StaticText()); }
/// <summary> /// Constructor /// </summary> public AdifExistsMacro() { AdifField = new StaticText(); SetValue(DesignTextPropertyKey, new TextParts()); DesignText.Add(new StaticText()); SetValue(ExistsTextPropertyKey, new TextParts()); ExistsText.Add(new StaticText()); SetValue(DoesntExistTextPropertyKey, new TextParts()); DoesntExistText.Add(new StaticText()); }
/// <summary> /// Factory for UserPrefs objects. /// Deserializes UserPrefs object stored in qslPrefs.xml if file exists. /// Otherwise creates a default UserPrefs object /// </summary> /// <param name="showMessages">boolean indicating whether an error message should be /// displayed if an error occurs.</param> /// <param name="prefsInitilized">boolean indicating whether the prefs object was initialized /// or loaded. Value of true indicates that the object was initialized, not loaded</param> /// <param name="prefsError">boolean indicating if an error occurred while trying /// to deserialize the prefs file.</param> /// <returns>Deserialized or default UserPrefs object</returns> public static UserPreferences CreateUserPreferences(bool showMessages, out bool prefsInitialized, out bool prefsError) { // filename of the user prefs file FileStream fStream = null; // default user preferences. Created here in case there are new preferences that // were not saved in the preferences file UserPreferences prefs = CreateDefaultUserPreferences(out prefsInitialized); prefsError = true; // set to false if prefs file is read try { // get file info FileInfo prefsInfo = new FileInfo(userPreferencesFilename); if (prefsInfo.Exists) { // file exists, so read it fStream = new FileStream(userPreferencesFilename, FileMode.Open, FileAccess.Read); XmlSerializer xmlFormat = new XmlSerializer(typeof(UserPreferences)); prefs = (UserPreferences)xmlFormat.Deserialize(fStream); prefsInitialized = false; // prefs file has been loaded prefsError = false; // no error loading file } else { prefsError = false; if(showMessages) { // no user prefs file, so inform user, and create a default MessageBox.Show("User Preferences file does not exist.\r\n" + "User Preferences are being initialized.\r\n" + "Preferences may be set from the Edit dropdown menu", "No User Preferences Found", MessageBoxButton.OK, MessageBoxImage.Information); } } } catch (SecurityException e) { Exception ex = new Exception("You do not have permission to access the User Preferences File.\r\n" + "Preferences will be initialized.", e); App.Logger.Log(ex); } catch (UnauthorizedAccessException e) { Exception ex = new Exception("You do not have permission to access the User Preferences File.\r\n" + "Preferences will be initialized.", e); App.Logger.Log(ex); } catch (PathTooLongException e) { Exception ex = new Exception("Path to User Preferences File exceeds the system defined maximum length.\r\n" + "Preferences will be initialized.", e); App.Logger.Log(ex); } catch (FileNotFoundException e) { prefsInitialized = true; prefsError = false; Exception ex = new Exception("There appears to be a problem with your file system.\r\n" + "This program has found the file, but it cannot be opened.\r\n" + "Preferences will be initialized.", e); App.Logger.Log(ex); } catch (IOException e) { Exception ex = new Exception("An IO error occurred while attempting to access the User Preferences file:\r\n" + e.Message + "\r\n" + "Preferences will be initialized.", e); App.Logger.Log(ex); } catch (Exception e) { Exception ex = new Exception("Programming Error: Bad User Preferences filename or mode:\r\n" + userPreferencesFilename + "\r\n" + "Please do the following when you have finished using HamQSLer:\r\n" + "1. Make a copy of the log file.\r\n" + "2. Post a bug report, including the content of this message./r/n" + "Preferences will be initialized. You may continue to use the program.", e); App.Logger.Log(ex); } finally { // be sure to close the file if(fStream != null) fStream.Close(); } // check if there is a callsign from the file // and create default if not if(prefs.Callsign.Count == 0) { StaticText sText = new StaticText(); sText.Text = "MyCall"; prefs.Callsign.Add(sText); } else { foreach(TextPart part in prefs.Callsign) { part.RemoveExtraneousStaticTextMacros(); } } // check if there is a Name and QTH from the file // and create default if not if(prefs.NameQth.Count == 0) { StaticText nText = new StaticText(); nText.Text = "MyQth"; prefs.NameQth.Add(nText); } else { foreach(TextPart part in prefs.NameQth) { part.RemoveExtraneousStaticTextMacros(); } } // check if there is a salutation from the file // and create default if not if(prefs.Salutation.Count == 0) { StaticText salText = new StaticText(); salText.Text = "Thanks for the QSO"; prefs.Salutation.Add(salText); CountMacro macro = new CountMacro(); macro.CountEquals = true; macro.Count = 1; ((StaticText)macro.DesignText[0]).Text = "$"; ((StaticText)macro.TrueText[0]).Text = string.Empty; ((StaticText)macro.FalseText[0]).Text = "s"; prefs.Salutation.Add(macro); StaticText text73 = new StaticText(); text73.Text = ". 73,"; prefs.Salutation.Add(text73); } else { foreach(TextPart part in prefs.Salutation) { part.RemoveExtraneousStaticTextMacros(); } } if(prefs.ConfirmingText.Count == 0) { StaticText cText = new StaticText(); cText.Text = "Confirming 2-Way QSO"; prefs.ConfirmingText.Add(cText); CountMacro macro = new CountMacro(); macro.CountEquals = true; macro.Count = 1; ((StaticText)macro.DesignText[0]).Text = "$"; ((StaticText)macro.TrueText[0]).Text = string.Empty; ((StaticText)macro.FalseText[0]).Text = "s"; prefs.ConfirmingText.Add(macro); StaticText withText = new StaticText(); withText.Text = " with "; prefs.ConfirmingText.Add(withText); } else { foreach(TextPart part in prefs.ConfirmingText) { part.RemoveExtraneousStaticTextMacros(); } } // if prefs have been initialized, it is necessary to save the file // return the UserPrefs object if(prefsInitialized) { // note: we do not want to suppress error Message box displays when saving the prefs file prefs.SerializeAsXml(); } return prefs; }
/// <summary> /// Make a deep copy of this StaticText object /// </summary> /// <returns>StaticText object that is a deep copy of this one</returns> public override TextPart Clone() { StaticText sText = new StaticText(); sText.Text = Text; return sText; }
/// <summary> /// Executed event handler for the InsertStaticTextBefore menu item /// </summary> /// <param name="sender">not used</param> /// <param name="e">not used</param> private void OnInsertStaticTextBeforeCommand_Executed(object sender, ExecutedRoutedEventArgs e) { // create a new StaticText object and add it to the TextItems. StaticText sText = new StaticText(); int position = GetPosition(); if(position != -1) { PartItems.Insert(position, sText); UpdateDialog(); // redraw the Dialog contents } }
/// <summary> /// Create a TextWFItem object based on an XmlNode for it from an /// XQSL file /// </summary> /// <param name="card">The CardWF object that will contain the text item</param> /// <param name="node">XmlNode object containing the text item data</param> /// <param name="culture">CultureInfo object that describes the culture /// that the XQSL file was saved with</param> /// <returns></returns> private static TextWFItem CreateTextItem(CardWF card, XmlNode node, CultureInfo culture) { TextWFItem tItem = new TextWFItem(); tItem.QslCard = card; XmlNode tiNode = XmlProcs.GetFirstChildElement(node); while(tiNode != null) { XmlText text = XmlProcs.GetTextNode(tiNode); switch(tiNode.Name) { case "CardItem": GetCardItemData(tItem, tiNode, culture); break; case "FaceName": tItem.TextFontFace = GetValidFont(text.Value); break; case "TextFontWeight": tItem.IsBold = false; switch(text.Value) { case "Normal": break; case "Bold": // note fall through case "Black": tItem.IsBold = true; break; } break; case "IsItalic": tItem.IsItalic = text.Value=="true" ? true : false; break; case "FontSize": if(text != null) { float value = 0F; if(!float.TryParse(text.Value, NumberStyles.Float, culture, out value)) { if(!float.TryParse(text.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { XmlException ex = new XmlException( "Bad TextItem property value in Card File" + Environment.NewLine + "Did you modify the card file by hand?"); ex.Data.Add("Property", "FontSize"); ex.Data.Add("Value", text.Value); App.Logger.Log(ex); } } tItem.FontSize = value * FontScaleFactor; } break; case "TextBrush": tItem.TextColor = XmlProcs.ConvertXmlToColor(tiNode, culture); break; case "Text": StaticText sText = new StaticText(); if(text.Value != null) { sText.Text = text.Value; tItem.Text.Clear(); tItem.Text.Add(sText); } break; case "CheckboxBefore": if(text != null) { tItem.CheckboxBefore = text.Value == "true" ? true : false; } break; case "CheckboxAfter": if(text != null) { tItem.CheckboxAfter = text.Value == "true" ? true : false; } break; } tiNode = XmlProcs.GetNextSiblingElement(tiNode); } return tItem; }
/// <summary> /// Create a QsosWFBox object based on an XmlNode for it from an /// XQSL file /// </summary> /// <param name="card">The CardWF object that will contain the text item</param> /// <param name="node">XmlNode object that contains the data for the text item</param> /// <param name="culture">CultureInfo object that describes the culture /// that the XQSL file was saved with</param> /// <returns></returns> private static QsosWFBox CreateQsosBox(CardWF card, XmlNode node, CultureInfo culture) { QsosWFBox qBox = new QsosWFBox(); qBox.QslCard = card; qBox.FontSize = 12.0F * FontScaleFactor; XmlNode qNode = XmlProcs.GetFirstChildElement(node); while(qNode != null) { XmlText text = XmlProcs.GetTextNode(qNode); switch(qNode.Name) { case "QsoBoxBase": qNode = XmlProcs.GetFirstChildElement(qNode); break; case "CardItem": GetCardItemData(qBox, qNode, culture); break; case "ShowManager": if(text != null) { qBox.ShowManager = text.Value=="true" ? true : false; } break; case "ShowFrequency": if(text != null) { qBox.ShowFrequency = text.Value=="true" ? true : false; } break; case "ShowPseTnx": if(text != null) { qBox.ShowPseTnx = text.Value=="true" ? true : false; } break; case "MaximumQsos": if(text != null) { qBox.MaximumQsos = Int32.Parse(text.Value, culture); } break; case "DateFormat": if(text != null) { qBox.DateFormat = text.Value; } break; case "LineTextBrush": qBox.LineTextColor = XmlProcs.ConvertXmlToColor(qNode, culture); break; case "CallsignBrush": qBox.CallsignColor = XmlProcs.ConvertXmlToColor(qNode, culture); break; case "ManagerBrush": qBox.ManagerColor = XmlProcs.ConvertXmlToColor(qNode, culture); break; case "FaceName": if(text != null) { qBox.FontName = GetValidFont(text.Value); } break; case "BackgroundBrush": qBox.BackgroundColor = XmlProcs.ConvertXmlToColor(qNode, culture); break; case "BackgroundOpacity": if(text != null) { float value = 0F; if(!float.TryParse(text.Value, NumberStyles.Float, culture, out value)) { if(!float.TryParse(text.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { XmlException ex = new XmlException( "Bad QsosBox property value in card file." + Environment.NewLine + "Did you modify the card file by hand?"); ex.Data.Add("Property", "BackgroundOpacity"); ex.Data.Add("Value", text.Value); App.Logger.Log(ex); } } qBox.BackgroundOpacity = value; } break; case "ConfirmingMultiText": CountMacro cMacro = new CountMacro(); StaticText designText = new StaticText(); designText.Text = ((App)App.Current).UserPreferences. ConfirmingText.GetText(card, null, true); cMacro.DesignText.Clear(); cMacro.DesignText.Add(designText); StaticText falseText = new StaticText(); string fText = text.Value; if(!fText.EndsWith(" ")) { fText += " "; } falseText.Text = fText; cMacro.FalseText.Clear(); cMacro.FalseText.Add(falseText); qBox.ConfirmingText.Clear(); qBox.ConfirmingText.Add(cMacro); break; case "Confirming1Text": // code assumes that Confirming1Text occurs // after ConfirmingMultiText in the // xqsl file. This matches the save order in // QslDesignAndPrint. StaticText trueText = new StaticText(); string tText = text.Value; if(!tText.EndsWith(" ")) { tText += " "; } trueText.Text = tText; CountMacro countMacro = qBox.ConfirmingText[0] as CountMacro; countMacro.TrueText.Clear(); countMacro.TrueText.Add(trueText); break; case "ViaText": if(text != null) { qBox.ViaText = text.Value; } break; case "YYYYMMDDText": if(text != null) { qBox.YYYYMMDDText = text.Value; } break; case "DDMMMYYText": if(text != null) { qBox.DDMMMYYText = text.Value; } break; case "DDMMYYText": if(text != null) { qBox.DDMMYYText = text.Value; } break; case "TimeText": if(text != null) { qBox.TimeText = text.Value; } break; case "ModeText": if(text != null) { qBox.ModeText = text.Value; } break; case "BandText": if(text != null) { qBox.BandText = text.Value; } break; case "FrequencyText": if(text != null) { qBox.FreqText = text.Value; } break; case "RSTText": if(text != null) { qBox.RSTText = text.Value; } break; case "QSLText": if(text != null) { qBox.QSLText = text.Value; } break; case "PseText": if(text != null) { qBox.PseText = text.Value; } break; case "TnxText": if(text != null) { qBox.TnxText = text.Value; } break; } qNode = XmlProcs.GetNextSiblingElement(qNode); } return qBox; }
/// <summary> /// Add a TextWFItem to the card /// </summary> /// <returns>TextWFItem that was added</returns> public TextWFItem AddTextItem() { TextWFItem tItem = new TextWFItem(); tItem.QslCard = QslCard; tItem.IsSelected = true; StaticText sText = new StaticText(); sText.Text = "Text Item"; tItem.Text.Add(sText); tItem.X = (QslCard.Width - tItem.Width) / 2; tItem.Y = (QslCard.Height - tItem.Height) / 2; QslCard.TextItems.Add(tItem); return tItem; }
/// <summary> /// Adds a TextItem to the card. /// </summary> public void AddText() { TextItem ti = new TextItem(); ti.QslCard = this; TextItems.Add(ti); StaticText sText = new StaticText(); sText.Text = "Text Item"; ti.Text.Add(sText); // ti.SetDisplayText(); CardItem ci = GetHighlighted(); if(ci != null) { ci.IsHighlighted = false; } ti.IsSelected = true; IsDirty = true; }