/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the btnEdit control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void btnEdit_Click(object sender, EventArgs e)
        {
            RenderingSelectionRule rule = m_listRules.SelectedItem as RenderingSelectionRule;
            string origName             = rule.Name;
            string origQ = rule.QuestionMatchingPattern;
            string origR = rule.RenderingMatchingPattern;
            Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Where(r => r != rule).Any(r => r.Name == n);

            using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique))
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    if (!rule.Valid)
                    {
                        m_listRules.SetItemChecked(m_listRules.SelectedIndex, false);
                    }

                    m_listRules.Invalidate();
                }
                else
                {
                    rule.Name = origName;
                    rule.QuestionMatchingPattern  = origQ;
                    rule.RenderingMatchingPattern = origR;
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the btnNew control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void btnNew_Click(object sender, System.EventArgs e)
        {
            int    i    = 1;
            string name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, i);

            Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Any(r => r.Name == n);

            while (!nameIsUnique(name))
            {
                name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, ++i);
            }

            RenderingSelectionRule rule = new RenderingSelectionRule(name);

            using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique))
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    m_listRules.SelectedIndex = m_listRules.Items.Add(rule);
                    if (rule.Valid)
                    {
                        m_listRules.SetItemChecked(m_listRules.SelectedIndex, true);
                    }
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the btnCopy control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void btnCopy_Click(object sender, EventArgs e)
        {
            int iOrigRule = m_listRules.SelectedIndex;
            RenderingSelectionRule origRule = m_listRules.SelectedItem as RenderingSelectionRule;
            RenderingSelectionRule newRule  = new RenderingSelectionRule(origRule.QuestionMatchingPattern, origRule.RenderingMatchingPattern);

            int    i    = 1;
            string name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, string.Empty);

            Func <string, bool> nameIsUnique = n => !m_listRules.Items.Cast <RenderingSelectionRule>().Any(r => r.Name == n);

            while (!nameIsUnique(name))
            {
                name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, "(" + i++ + ")");
            }

            newRule.Name = name;

            using (RulesWizardDlg dlg = new RulesWizardDlg(newRule, Word.AllWords, m_selectKeyboard, nameIsUnique))
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    m_listRules.SelectedIndex = m_listRules.Items.Add(newRule);
                    if (newRule.Valid)
                    {
                        m_listRules.SetItemChecked(m_listRules.SelectedIndex, m_listRules.GetItemChecked(iOrigRule));
                    }
                }
            }
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the btnNew control.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void btnNew_Click(object sender, System.EventArgs e)
		{
			int i = 1;
			string name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, i);

			Func<string, bool> nameIsUnique = n => !m_listRules.Items.Cast<RenderingSelectionRule>().Any(r => r.Name == n);
			while (!nameIsUnique(name))
				name = string.Format(Properties.Resources.kstidNewSelectionRuleNameTemplate, ++i);

			RenderingSelectionRule rule = new RenderingSelectionRule(name);

			using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique))
			{
				if (dlg.ShowDialog(this) == DialogResult.OK)
				{
					m_listRules.SelectedIndex = m_listRules.Items.Add(rule);
					if (rule.Valid)
						m_listRules.SetItemChecked(m_listRules.SelectedIndex, true);
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the btnEdit control.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void btnEdit_Click(object sender, EventArgs e)
		{
			RenderingSelectionRule rule = m_listRules.SelectedItem as RenderingSelectionRule;
			string origName = rule.Name;
			string origQ = rule.QuestionMatchingPattern;
			string origR = rule.RenderingMatchingPattern;
			Func<string, bool> nameIsUnique = n => !m_listRules.Items.Cast<RenderingSelectionRule>().Where(r => r != rule).Any(r => r.Name == n);
			using (RulesWizardDlg dlg = new RulesWizardDlg(rule, Word.AllWords, m_selectKeyboard, nameIsUnique))
			{
				if (dlg.ShowDialog(this) == DialogResult.OK)
				{
					if (!rule.Valid)
						m_listRules.SetItemChecked(m_listRules.SelectedIndex, false);

					m_listRules.Invalidate();
				}
				else
				{
					rule.Name = origName;
					rule.QuestionMatchingPattern = origQ;
					rule.RenderingMatchingPattern = origR;
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Click event of the btnCopy control.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void btnCopy_Click(object sender, EventArgs e)
		{
			int iOrigRule = m_listRules.SelectedIndex;
			RenderingSelectionRule origRule = m_listRules.SelectedItem as RenderingSelectionRule;
			RenderingSelectionRule newRule = new RenderingSelectionRule(origRule.QuestionMatchingPattern, origRule.RenderingMatchingPattern);

			int i = 1;
			string name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, string.Empty);

			Func<string, bool> nameIsUnique = n => !m_listRules.Items.Cast<RenderingSelectionRule>().Any(r => r.Name == n);
			while (!nameIsUnique(name))
				name = string.Format(Properties.Resources.kstidCopiedSelectionRuleNameTemplate, origRule.Name, "(" + i++ + ")");

			newRule.Name = name;

			using (RulesWizardDlg dlg = new RulesWizardDlg(newRule, Word.AllWords, m_selectKeyboard, nameIsUnique))
			{
				if (dlg.ShowDialog(this) == DialogResult.OK)
				{
					m_listRules.SelectedIndex = m_listRules.Items.Add(newRule);
					if (newRule.Valid)
						m_listRules.SetItemChecked(m_listRules.SelectedIndex, m_listRules.GetItemChecked(iOrigRule));
				}
			}
		}