示例#1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new StyleListItem for the "Default Paragraph Characters" style and
        /// initializes various properties for that.
        /// </summary>
        /// <returns>A new StyleListItem for the "Default Paragraph Characters"
        /// psuedo-style.</returns>
        /// ------------------------------------------------------------------------------------
        public static StyleListItem CreateDefaultParaCharItem()
        {
            StyleListItem item = new StyleListItem();

            item.m_itemType = StyleListItemType.DefaultParaChars;
            return(item);
        }
示例#2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Marks the given style as a "current" style. This will allow it to be indicated in
        /// the list as one of the current styles.
        /// </summary>
        /// <param name="styleName">Name of the style.</param>
        /// ------------------------------------------------------------------------------------
        public void MarkCurrentStyle(string styleName)
        {
            if (string.IsNullOrEmpty(styleName))
            {
                return;
            }
            if (m_styleItemList.ContainsKey(styleName))
            {
                StyleListItem item = m_styleItemList[styleName];
                switch (item.Type)
                {
                case StyleType.kstParagraph:
                    m_currParaStyleName = styleName;
                    break;

                case StyleType.kstCharacter:
                    m_currCharStyleName = styleName;
                    break;

                default:
                    break;
                }
                item.IsCurrentStyle = true;
            }
        }
示例#3
0
        public void VerifyStylesSetToInUseInCombo()
        {
            CheckDisposed();

            // Set the combobox to show only character styles
            m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstCharacter;
            m_styleListHelper.MaxStyleLevel        = 5;      // show all styles

            // Initialize the combo box.
            m_styleListHelper.AddStyles(m_styleSheet);
            m_styleListHelper.MaxStyleLevel = 1;
            Assert.IsTrue(m_stylesComboBox.Items.Count > 0, "Oops! Everything got excluded.");

            // Trying to select the style should cause it to be set to "InUse" and it should be
            // added to the list.
            m_styleListHelper.SelectedStyleName = kStyleName;
            StyleListItem item = m_styleListHelper.SelectedStyle;

            // Assume if we have a style item the item was in the list
            Assert.IsNotNull(item);
            Assert.AreEqual(kStyleName, item.Name);
            Assert.IsTrue(item.StyleInfo.RealStyle.InUse);
            Assert.AreEqual(-2, item.UserLevel);
            Assert.AreEqual(-2, item.StyleInfo.UserLevel);
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Stores all the available styles from the style sheet. Later, the list is used to
        /// fill the combo or list box with the appropriate styles.
        /// </summary>
        /// <param name="cStyles">Number of styles in <paramref name="styleInfos"/></param>
        /// <param name="styleInfos">The collection of style infos.</param>
        /// <param name="pseudoStyles">Array of strings representing pseudo-styles that can be
        /// displayed for the purpose of mapping markers to data properties</param>
        /// ------------------------------------------------------------------------------------
        protected void BuildStyleItemList(int cStyles, IEnumerable styleInfos,
                                          string[] pseudoStyles)
        {
            if (styleInfos == null)
            {
                return;
            }

            int cPseudoStyles = (pseudoStyles == null) ? 0 : pseudoStyles.Length;

            if (m_styleItemList == null)
            {
                m_styleItemList = new Dictionary <string, StyleListItem>(1 + cStyles + cPseudoStyles);
            }
            else
            {
                m_styleItemList.Clear();
            }

            // Add an item for the Default Paragraph Characters pseudo style.
            m_styleItemList.Add(StyleUtils.DefaultParaCharsStyleName,
                                StyleListItem.CreateDefaultParaCharItem());

            foreach (BaseStyleInfo styleInfo in styleInfos)
            {
                m_styleItemList.Add(styleInfo.Name, new StyleListItem(styleInfo));
            }

            AddPseudoStyles(pseudoStyles);
            Refresh();
        }
示例#5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// This method is called during the drawing of combo box items and is used to determine
 /// the appropriate icon to draw next to the item's text. Determining the appropriate
 /// icon depends on the following factors:
 /// 1. whether or not the current item is selected
 /// 2. whether the current item is a character or paragraph style
 /// 3. whether the current item represents the style of the current view's selection
 /// </summary>
 /// <remarks>If the current item is selected we display the same icon but a different
 /// background color.</remarks>
 /// <param name="item">The item for which an icon is being returned</param>
 /// <param name="selected">whether or not the item is selected</param>
 /// <returns>The appropriate icon for the item</returns>
 /// ------------------------------------------------------------------------------------
 protected Image GetCorrectIcon(StyleListItem item, bool selected)
 {
     if (item.Type == StyleType.kstCharacter)
     {
         if (item.Name == m_currCharStyleName)
         {
             return(selected ? m_currSelectedCharStyleIcon : m_currCharStyleIcon);
         }
         else
         {
             return(selected ? m_selectedCharStyleIcon : m_charStyleIcon);
         }
     }
     else if (!item.IsDataPropertyStyle)
     {
         if (item.Name == m_currParaStyleName)
         {
             return(selected ? m_currSelectedParaStyleIcon : m_currParaStyleIcon);
         }
         else
         {
             return(selected ? m_selectedParaStyleIcon : m_paraStyleIcon);
         }
     }
     else
     {
         return(selected ? m_selectedDataPropStyleIcon : m_dataPropStyleIcon);
     }
 }
示例#6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Renames a style.
        /// </summary>
        /// <param name="oldName">The old name.</param>
        /// <param name="newName">The new name.</param>
        /// ------------------------------------------------------------------------------------
        public void Rename(string oldName, string newName)
        {
            StyleListItem style = m_styleItemList[oldName];

            m_styleItemList.Remove(oldName);
            style.StyleInfo.Name = newName;
            m_styleItemList.Add(newName, style);
            Refresh();
        }
示例#7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Draw the items in the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void CtrlDrawItem(object sender, DrawItemEventArgs e)
        {
            bool selected = ((e.State & DrawItemState.Selected) != 0);

            // Draw the item's background fill.
            e.Graphics.FillRectangle(new SolidBrush((selected ?
                                                     SystemColors.Highlight : SystemColors.Window)), e.Bounds);

            // Don't bother doing any more painting if there isn't anything to paint.
            if (e.Index < 0)
            {
                return;
            }

            Rectangle rc = e.Bounds;

            rc.Inflate(-1, 0);
            rc.X     += 2;
            rc.Width -= 2;

            // Get the item being drawn.
            StyleListItem item = (StyleListItem)ListBoxControl.Items[e.Index];

            //// If this is a current style, then draw a triangle mark
            //const int triangleHeight = 8;
            //if (item.IsCurrentStyle)
            //{
            //    Point[] triangle = new Point[] {
            //        new Point(rc.Left, rc.Top + (rc.Height - triangleHeight) / 2),
            //        new Point(rc.Left, rc.Top + (rc.Height + triangleHeight) / 2),
            //        new Point(rc.Left + triangleHeight * 3 / 4, rc.Top + (rc.Bottom - rc.Top) / 2)};
            //    e.Graphics.FillPolygon(
            //        selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText,
            //        triangle);
            //}
            //rc.X += triangleHeight;
            //rc.Width -= triangleHeight;

            // Determine what image to draw, considering the selection state of the item and
            // whether the item is a character style or a paragraph style.
            Image icon = GetCorrectIcon(item, selected);

            // Draw the icon only if we're not drawing a combo box's edit portion.
            if ((e.State & DrawItemState.ComboBoxEdit) == 0)
            {
                e.Graphics.DrawImage(icon, rc.Left, rc.Top + (rc.Height - icon.Height) / 2);
            }

            // Draw the item's text, considering the item's selection state. Item text in the
            // edit portion will be draw further left than those in the drop-down because text
            // in the edit portion doesn't have the icon to the left.
            e.Graphics.DrawString(item.Name, m_ctrl.Font,
                                  selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText,
                                  rc.Left + ((e.State & DrawItemState.ComboBoxEdit) != 0 ? 0 : icon.Width),
                                  rc.Top);
        }
示例#8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds the pseudo styles.
 /// </summary>
 /// <param name="pseudoStyles">The pseudo styles.</param>
 /// ------------------------------------------------------------------------------------
 private void AddPseudoStyles(string[] pseudoStyles)
 {
     if (pseudoStyles == null)
     {
         return;
     }
     foreach (string sPseudoStyle in pseudoStyles)
     {
         m_styleItemList.Add(sPseudoStyle,
                             StyleListItem.CreateDataPropertyItem(sPseudoStyle));
     }
 }
示例#9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new StyleListItem for a pseudo-style (used for import mapping to "data"
		/// properties).
		/// </summary>
		/// <param name="sName"></param>
		/// <returns>A new StyleListItem for the requested psuedo-style.</returns>
		/// ------------------------------------------------------------------------------------
		public static StyleListItem CreateDataPropertyItem(string sName)
		{
			StyleListItem item = new StyleListItem();
			item.m_styleInfo = new BaseStyleInfo();
			item.m_styleInfo.Name = sName;
			// We set this to Paragraph, but when filtering the list, we actually allow psuedo
			// styles to match either Paragraph or Character. The import code handles either
			// case correctly (I hope).
			item.m_styleInfo.IsParagraphStyle = true;
			item.m_itemType = StyleListItemType.DataProperty;
			return item;
		}
示例#10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Compare a StyleListItem to another item.
        /// </summary>
        /// <param name="obj">StyleListItem to compare to</param>
        /// <returns>less than 0 if this item is less than obj, 0 if they are equal, and
        /// greater than 0 if this item is greater than obj</returns>
        /// ------------------------------------------------------------------------------------
        public int CompareTo(object obj)
        {
            StyleListItem other = obj as StyleListItem;

            if (other == null)
            {
                return(0);
            }

            // compare the names
            return(Name.CompareTo(other.Name));
        }
示例#11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Returns an StStyle object given a style name.
        /// </summary>
        /// <param name="styleName"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public IStStyle StyleFromName(string styleName)
        {
            //TE-5609 Prevent crash in case of missing style by using TryGetValue.
            StyleListItem item = null;

            if (m_styleItemList.TryGetValue(styleName, out item))
            {
                Debug.Assert(item.StyleInfo.RealStyle != null);
                return(item.StyleInfo.RealStyle);
            }
            return(null);
        }
示例#12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new StyleListItem for a pseudo-style (used for import mapping to "data"
        /// properties).
        /// </summary>
        /// <param name="sName"></param>
        /// <returns>A new StyleListItem for the requested psuedo-style.</returns>
        /// ------------------------------------------------------------------------------------
        public static StyleListItem CreateDataPropertyItem(string sName)
        {
            StyleListItem item = new StyleListItem();

            item.m_styleInfo      = new BaseStyleInfo();
            item.m_styleInfo.Name = sName;
            // We set this to Paragraph, but when filtering the list, we actually allow psuedo
            // styles to match either Paragraph or Character. The import code handles either
            // case correctly (I hope).
            item.m_styleInfo.IsParagraphStyle = true;
            item.m_itemType = StyleListItemType.DataProperty;
            return(item);
        }
示例#13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Do common Refresh work for m_styleItemList member.
        /// </summary>
        /// <param name="selectedStyle">The selected style.</param>
        /// ------------------------------------------------------------------------------------
        protected void RefreshStyleItemList(string selectedStyle)
        {
            if (m_styleItemList != null)             // Added JohnT for robustness and to keep tests working.
            {
                // get the list of items into an array list that can be sorted
                List <StyleListItem> itemsList = new List <StyleListItem>(m_styleItemList.Values);

                // If the list contains the default paragraph characters style then remove it
                // from the list so it can be removed from the list while sorting.
                StyleListItem defaultParaCharsStyle = null;
                foreach (StyleListItem item in itemsList)
                {
                    if (item.Name == FdoResources.DefaultParaCharsStyleName)
                    {
                        defaultParaCharsStyle = item;
                        break;
                    }
                }
                if (defaultParaCharsStyle != null)
                {
                    itemsList.Remove(defaultParaCharsStyle);
                }

                // Sort the list, add the default paragraph chars style back in at the top of
                // the list, and add all of the items to the combo box.
                itemsList.Sort();
                if (defaultParaCharsStyle != null)
                {
                    itemsList.Insert(0, defaultParaCharsStyle);
                }
                foreach (StyleListItem item in itemsList)
                {
                    if (OkToAddItem(item))
                    {
                        AddStyleListItem(item);
                    }
                }

                SelectedStyleName = selectedStyle;
            }
        }
示例#14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When the selected style changes, apply the style
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        protected void CtrlSelectedIndexChanged(object sender, EventArgs e)
        {
            if (SelectedStyle == null &&
                (m_currParaStyleName != string.Empty || m_currCharStyleName != string.Empty))
            {
                SelectedStyleName = m_currParaStyleName == string.Empty ? m_currCharStyleName :
                                    m_currParaStyleName;

                Debug.Assert(SelectedStyle != null);
                if (SelectedStyle == null)
                {
                    return;
                }
            }

            if (StyleChosen != null && m_ignoreChosenDelegate == false)
            {
                StyleChosen(m_prevStyle, SelectedStyle);
            }

            m_prevStyle = SelectedStyle;
        }
示例#15
0
        public void VerifyAllStylesInCombo()
        {
            CheckDisposed();

            // Initialize the combo box.
            m_styleListHelper.AddStyles(m_styleSheet);

            // Get the count of styles in the DB.
            int styleCountExpected = m_lp.StylesOC.Count;

            // Verify that all the styles that are in the DB are in the combo box list.
            int i;

            foreach (IStStyle style in m_lp.StylesOC)
            {
                if (style.Context == ContextValues.Internal)
                {
                    styleCountExpected--;
                    continue;                     // skip internal styles which won't be in menu.
                }
                i = m_stylesComboBox.FindStringExact(style.Name);
                Assert.IsTrue(i > -1);
                StyleListItem comboItem = (StyleListItem)m_stylesComboBox.Items[i];
                Assert.AreEqual(style.Type, comboItem.Type);
                Assert.IsFalse(comboItem.IsDefaultParaCharsStyle,
                               "Style is Default Paragraph Characters, but should not be");
            }

            // Now check for the Default Paragraph Characters psuedo-style style.
            i = m_stylesComboBox.FindStringExact(FdoResources.DefaultParaCharsStyleName);
            Assert.IsTrue(i > -1);
            styleCountExpected++;             // Add one for this psuedo-style
            Assert.AreEqual(StyleType.kstCharacter,
                            ((StyleListItem)m_stylesComboBox.Items[i]).Type);
            Assert.IsTrue(((StyleListItem)m_stylesComboBox.Items[i]).IsDefaultParaCharsStyle,
                          "Style is not Default Paragraph Characters, but should be");

            Assert.AreEqual(styleCountExpected, m_stylesComboBox.Items.Count);
        }
示例#16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the styles in the m_ctrl list based on the ExcludeStylesWithContext and
        /// ShowOnlyStylesOfType properties. This should be called when the caller wants to
        /// update the m_ctrl list after changing one of those two properties, but doesn't want
        /// to rebuild the entire m_styleItemList.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Refresh()
        {
            if (m_styleItemList != null)             // Added JohnT for robustness and to keep tests working.
            {
                // get the list of items into an array list that can be sorted
                List <StyleListItem> itemsList = new List <StyleListItem>(m_styleItemList.Values.Where(OkToAddItem));

                // If the list contains the default paragraph characters style then remove it
                // from the list so it can be removed from the list while sorting.
                StyleListItem defaultParaCharsStyle = itemsList.FirstOrDefault(
                    item => item.Name == StyleUtils.DefaultParaCharsStyleName);

                if (defaultParaCharsStyle != null)
                {
                    itemsList.Remove(defaultParaCharsStyle);
                }

                // Sort the list, add the default paragraph chars style back in at the top of
                // the list, and add all of the items to the combo box.
                itemsList.Sort();
                if (defaultParaCharsStyle != null)
                {
                    itemsList.Insert(0, defaultParaCharsStyle);
                }

                StyleListItem[] newItems = itemsList.ToArray();
                if (m_prevList == null || !newItems.SequenceEqual(m_prevList))
                {
                    UpdateStyleList(newItems);
                    m_prevList = newItems;
                    if (newItems.Length == 0 || !itemsList.Contains(m_prevStyle))
                    {
                        m_prevStyle = null;
                    }
                }
            }
        }
示例#17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When the selected style changes, apply the style
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void CtrlSelectedIndexChanged(object sender, EventArgs e)
		{
			if (SelectedStyle == null &&
				(m_currParaStyleName != string.Empty || m_currCharStyleName != string.Empty))
			{
				SelectedStyleName = m_currParaStyleName == string.Empty ? m_currCharStyleName :
					m_currParaStyleName;

				Debug.Assert(SelectedStyle != null);
			}

			if (SelectedStyle == null)
				return;

			if (StyleChosen != null && m_ignoreChosenDelegate == false)
				StyleChosen(m_prevStyle, SelectedStyle);

			m_prevStyle = SelectedStyle;
		}
示例#18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method is called during the drawing of combo box items and is used to determine
		/// the appropriate icon to draw next to the item's text. Determining the appropriate
		/// icon depends on the following factors:
		/// 1. whether or not the current item is selected
		/// 2. whether the current item is a character or paragraph style
		/// 3. whether the current item represents the style of the current view's selection
		/// </summary>
		/// <remarks>If the current item is selected we display the same icon but a different
		/// background color.</remarks>
		/// <param name="item">The item for which an icon is being returned</param>
		/// <param name="selected">whether or not the item is selected</param>
		/// <returns>The appropriate icon for the item</returns>
		/// ------------------------------------------------------------------------------------
		protected Image GetCorrectIcon(StyleListItem item, bool selected)
		{
			if (item.Type == StyleType.kstCharacter)
			{
				if (item.Name == m_currCharStyleName)
					return (selected ? m_currSelectedCharStyleIcon : m_currCharStyleIcon);
				else
					return (selected ? m_selectedCharStyleIcon : m_charStyleIcon);
			}
			else if (!item.IsDataPropertyStyle)
			{
				if (item.Name == m_currParaStyleName)
					return (selected ? m_currSelectedParaStyleIcon : m_currParaStyleIcon);
				else
					return (selected ? m_selectedParaStyleIcon : m_paraStyleIcon);
			}
			else
			{
				return (selected ? m_selectedDataPropStyleIcon : m_dataPropStyleIcon);
			}
		}
示例#19
0
		/// <summary>
		/// Add item during refresh.
		/// </summary>
		/// <param name="item"></param>
		protected override void AddStyleListItem(StyleListItem item)
		{
			ListBoxControl.Items.Add(item);
		}
示例#20
0
		/// <summary>
		/// Add item during refresh.
		/// </summary>
		/// <param name="item"></param>
		protected override void AddStyleListItem(StyleListItem item)
		{
			// do nothing for this method
		}
示例#21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Called when a style is chosen in the style list
		/// </summary>
		/// <param name="prevStyle">The previous style</param>
		/// <param name="newStyle">The newly selected style</param>
		/// ------------------------------------------------------------------------------------
		void m_styleListHelper_StyleChosen(StyleListItem prevStyle, StyleListItem newStyle)
		{
			if (prevStyle != null)
			{
				// Make sure any previous changes are updated
				if (!prevStyle.IsDefaultParaCharsStyle)
					UpdateChanges((StyleInfo)prevStyle.StyleInfo);

				// If the new style is no longer selected, then select it. This can happen
				// when committing changes for a renamed style
				if (m_styleListHelper.SelectedStyle == null ||
					m_styleListHelper.SelectedStyle.Name != newStyle.Name)
				{
					m_styleListHelper.SelectedStyleName = newStyle.Name;
				}
			}

			Debug.Assert((newStyle.StyleInfo != null && newStyle.StyleInfo is StyleInfo) ||
				newStyle.IsDefaultParaCharsStyle);
			StyleInfo styleInfo = (StyleInfo)newStyle.StyleInfo;

			// Need to do this BEFORE removing/adding tabs to avoid an unfortunate series of
			// events when switching from a paragraph to a character style
			m_generalTab.UpdateForStyle(styleInfo);

			// If the new style is Default Paragraph Characters then disable everything
			if (newStyle.IsDefaultParaCharsStyle)
			{
				FillForDefaultParagraphCharacters();
				return;
			}

			// If the font tab was taken off for default paragraph characters, then
			// put it back in.
			if (!m_tabControl.TabPages.Contains(m_tbFont))
				m_tabControl.TabPages.Add(m_tbFont);

			// For character styles, hide the "Paragraph", "Bullets", and "Border" tabs
			if (styleInfo.IsCharacterStyle)
			{
				RemoveParagraphStyleTabs();
			}
			else if (styleInfo.IsParagraphStyle)
				EnsureParagraphStyleTabs();

			UpdateTabsForStyle(styleInfo);

			// Enable/disable the delete button based on the style being built-in
			m_btnDelete.Enabled = !styleInfo.IsBuiltIn;
			m_btnCopy.Enabled = styleInfo.CanInheritFrom;
		}
示例#22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This will apply the style filter to your item and tell you if it is valid or not.
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		/// <remarks>The include list behaves differently if there is a filter than if there
		/// is no filter applied.  If there isn't a filter then behave as an exclusive
		/// list (i.e. only contexts that are in the include list will be added). If there is a
		/// filter then behave as an additional list (i.e. contexts in the include list will be
		/// added even if they are excluded by the filter).
		/// REVIEW (TimS): Is this the best way to do the include list?</remarks>
		/// ------------------------------------------------------------------------------------
		protected bool OkToAddItem(StyleListItem item)
		{
			if (m_explicitStylesToDisplay != null)
				return (m_explicitStylesToDisplay.Contains(item.Name));
			// Some behavior for Flex is easier by excluding styles explicitly, rather than
			// displaying them explicitly.  See FWR-1178.
			if (m_explicitStylesToExclude != null)
				return !m_explicitStylesToExclude.Contains(item.Name);

			// Add the "Default Paragraph Characters" psuedo style in all cases except when
			// the filter tells us to only add paragraph styles.
			if (item.IsDefaultParaCharsStyle && m_typeFilter != StyleType.kstParagraph)
				return true;

			// Check the style level to see if the style is excluded
			if (item.UserLevel > MaxStyleLevel)
				return false;

			if (m_showOnlyUserModifiedStyles && !item.IsUserModifiedStyle)
				return false;

			// If there's an excluded context list and the item's context is in it,
			// it's not OK to add.
			if (m_excludedContexts != null && m_excludedContexts.Count > 0 &&
				m_excludedContexts.Contains(item.Context))
			{
				return false;
			}

			// If the context is internal and we aren't trying to show internal styles,
			// it's not OK to add
			// REVIEW: This should probably use StyleServices.IsContextInternal
			if (item.Context == ContextValues.Internal && !ShowingInternalStyles)
			{
				return false;
			}

			// If there's an excluded function list and the item's function is in it, it's not OK
			// to add.
			if (m_excludedFunctions != null && m_excludedFunctions.Count > 0 &&
				m_excludedFunctions.Contains(item.Function))
			{
				return false;
			}

			// Add or reject based on the Include context list
			if (!m_unionIncludeAndTypeFilter && m_includedContexts != null &&
				m_includedContexts.Count > 0 && !m_includedContexts.Contains(item.Context))
			{
				// include contexts used as intersection with filter type.
				return false;
			}
			else if (m_unionIncludeAndTypeFilter && m_includedContexts != null &&
				m_includedContexts.Count > 0 && m_includedContexts.Contains(item.Context))
			{
				// If there is a type filter then behave as an additional list (i.e. contexts in the
				// include list will be added even if they would be excluded by the filter).
				return true;
			}

			// See if the style should be excluded based on its type (character or paragraph)
			if (m_typeFilter == StyleType.kstParagraph && item.Type != StyleType.kstParagraph)
				return false;

			if (m_typeFilter == StyleType.kstCharacter && item.Type != StyleType.kstCharacter &&
				!item.IsDataPropertyStyle)
			{
				return false;
			}

			return true;
		}
示例#23
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Add an item to a control.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected abstract void AddStyleListItem(StyleListItem item);
示例#24
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add an item to a control.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected abstract void AddStyleListItem(StyleListItem item);
示例#25
0
		/// <summary>
		/// Add item during refresh.
		/// </summary>
		/// <param name="items"></param>
		protected override void UpdateStyleList(StyleListItem[] items)
		{
			// do nothing for this method
		}
示例#26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This event is called by the styles combo box when the user chooses a style from the
		/// combo box.
		/// </summary>
		/// <param name="prevStyle">The previously selected style (not used)</param>
		/// <param name="newStyle">The new style</param>
		/// ------------------------------------------------------------------------------------
		public void StyleChosenFromStylesComboBox(StyleListItem prevStyle, StyleListItem newStyle)
		{
			CheckDisposed();

			// See TE-4675 for some reasons why newStyle might be null.
			if (newStyle == null)
				return;

			Logger.WriteEvent(string.Format("Applying style {0}", newStyle.Name));
			IRootSite rootSite = ActiveView;
			if (rootSite != null)
			{
				Debug.Assert(rootSite.EditingHelper != null);

				Control ctrl = rootSite as Control;
				if (ctrl != null)
					ctrl.Focus();

				if (rootSite.EditingHelper.GetParaStyleNameFromSelection() == newStyle.Name)
					return;

				using (UndoTaskHelper undoHelper = new UndoTaskHelper(rootSite.CastAsIVwRootSite(),
					"kstidUndoStyleChanges"))
				{
					if (newStyle.IsDefaultParaCharsStyle)
						rootSite.EditingHelper.RemoveCharFormatting();
					else
						rootSite.EditingHelper.ApplyStyle(newStyle.Name);
					undoHelper.RollBack = false;
				}
			}
		}
示例#27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Show help topic for currently selected style. (This method is also in TeMainWnd.
		/// I tried to move it out but the reference chain would have made it ugly).
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ShowStylesHelp(StyleListItem item)
		{
			string helpTopic = null;

			if (item != null)
				helpTopic = TeStylesXmlAccessor.GetHelpTopicForStyle(item.Name);

			// I don't really like doing this, but oh well.
			if (string.IsNullOrEmpty(helpTopic) ||
				helpTopic.ToLower().StartsWith("help_topic_does_not_exist"))
			{
				helpTopic = TeResourceHelper.GetResourceString("kstidHelpTopicAllStyles");
			}

			Help.ShowHelp(new Label(), m_app.HelpFile, helpTopic);
		}
示例#28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Updates the styles in the m_ctrl list based on the ExcludeStylesWithContext and
		/// ShowOnlyStylesOfType properties. This should be called when the caller wants to
		/// update the m_ctrl list after changing one of those two properties, but doesn't want
		/// to rebuild the entire m_styleItemList.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void Refresh()
		{
			if (m_styleItemList != null) // Added JohnT for robustness and to keep tests working.
			{
				// get the list of items into an array list that can be sorted
				List<StyleListItem> itemsList = new List<StyleListItem>(m_styleItemList.Values.Where(OkToAddItem));

				// If the list contains the default paragraph characters style then remove it
				// from the list so it can be removed from the list while sorting.
				StyleListItem defaultParaCharsStyle = itemsList.FirstOrDefault(
					item => item.Name == StyleUtils.DefaultParaCharsStyleName);

				if (defaultParaCharsStyle != null)
					itemsList.Remove(defaultParaCharsStyle);

				// Sort the list, add the default paragraph chars style back in at the top of
				// the list, and add all of the items to the combo box.
				itemsList.Sort();
				if (defaultParaCharsStyle != null)
					itemsList.Insert(0, defaultParaCharsStyle);

				StyleListItem[] newItems = itemsList.ToArray();
				if (m_prevList == null || !newItems.SequenceEqual(m_prevList))
				{
					UpdateStyleList(newItems);
					m_prevList = newItems;
					if (newItems.Length == 0 || !itemsList.Contains(m_prevStyle))
						m_prevStyle = null;
				}
			}
		}
示例#29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Updates the list of items in the control to be the specified list of items.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected abstract void UpdateStyleList(StyleListItem[] items);
示例#30
0
 /// <summary>
 /// Add item during refresh.
 /// </summary>
 /// <param name="item"></param>
 protected override void AddStyleListItem(StyleListItem item)
 {
     // do nothing for this method
 }
示例#31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When the style changes, raise the ValidStateChanged event
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void StyleChosen(StyleListItem prevStyle, StyleListItem newStyle)
		{
			if (ValidStateChanged != null)
				ValidStateChanged(this, Valid);
		}
示例#32
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Add item during refresh.
 /// </summary>
 /// <param name="item"></param>
 /// ------------------------------------------------------------------------------------
 protected override void AddStyleListItem(StyleListItem item)
 {
     ComboBoxControl.Items.Add(item);
 }
示例#33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add item during refresh.
		/// </summary>
		/// <param name="items"></param>
		/// ------------------------------------------------------------------------------------
		protected override void UpdateStyleList(StyleListItem[] items)
		{
			if (m_ignoreListRefresh)
				return;

			string selectedStyle = ComboBoxControl.SelectedText;

			ComboBoxControl.Items.Clear();
			ComboBoxControl.BeginUpdate();
			ComboBoxControl.Items.AddRange(items);
			ComboBoxControl.EndUpdate();

			SelectedStyleName = selectedStyle;
		}
示例#34
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This will apply the style filter to your item and tell you if it is valid or not.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        /// <remarks>The include list behaves differently if there is a filter than if there
        /// is no filter applied.  If there isn't a filter then behave as an exclusive
        /// list (i.e. only contexts that are in the include list will be added). If there is a
        /// filter then behave as an additional list (i.e. contexts in the include list will be
        /// added even if they are excluded by the filter).
        /// REVIEW (TimS): Is this the best way to do the include list?</remarks>
        /// ------------------------------------------------------------------------------------
        protected bool OkToAddItem(StyleListItem item)
        {
            if (m_explicitStylesToDisplay != null)
            {
                return(m_explicitStylesToDisplay.Contains(item.Name));
            }
            // Some behavior for Flex is easier by excluding styles explicitly, rather than
            // displaying them explicitly.  See FWR-1178.
            if (m_explicitStylesToExclude != null)
            {
                return(!m_explicitStylesToExclude.Contains(item.Name));
            }

            // Add the "Default Paragraph Characters" psuedo style in all cases except when
            // the filter tells us to only add paragraph styles.
            if (item.IsDefaultParaCharsStyle && m_typeFilter != StyleType.kstParagraph)
            {
                return(true);
            }

            // Check the style level to see if the style is excluded
            if (item.UserLevel > MaxStyleLevel)
            {
                return(false);
            }

            if (m_showOnlyUserModifiedStyles && !item.IsUserModifiedStyle)
            {
                return(false);
            }

            // If there's an excluded context list and the item's context is in it,
            // it's not OK to add.
            if (m_excludedContexts != null && m_excludedContexts.Count > 0 &&
                m_excludedContexts.Contains(item.Context))
            {
                return(false);
            }

            // If the context is internal and we aren't trying to show internal styles,
            // it's not OK to add
            // REVIEW: This should probably use StyleServices.IsContextInternal
            if (item.Context == ContextValues.Internal && !ShowingInternalStyles)
            {
                return(false);
            }

            // If there's an excluded function list and the item's function is in it, it's not OK
            // to add.
            if (m_excludedFunctions != null && m_excludedFunctions.Count > 0 &&
                m_excludedFunctions.Contains(item.Function))
            {
                return(false);
            }

            // Add or reject based on the Include context list
            if (!m_unionIncludeAndTypeFilter && m_includedContexts != null &&
                m_includedContexts.Count > 0 && !m_includedContexts.Contains(item.Context))
            {
                // include contexts used as intersection with filter type.
                return(false);
            }
            else if (m_unionIncludeAndTypeFilter && m_includedContexts != null &&
                     m_includedContexts.Count > 0 && m_includedContexts.Contains(item.Context))
            {
                // If there is a type filter then behave as an additional list (i.e. contexts in the
                // include list will be added even if they would be excluded by the filter).
                return(true);
            }

            // See if the style should be excluded based on its type (character or paragraph)
            if (m_typeFilter == StyleType.kstParagraph && item.Type != StyleType.kstParagraph)
            {
                return(false);
            }

            if (m_typeFilter == StyleType.kstCharacter && item.Type != StyleType.kstCharacter &&
                !item.IsDataPropertyStyle)
            {
                return(false);
            }

            return(true);
        }
示例#35
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new StyleListItem for the "Default Paragraph Characters" style and
		/// initializes various properties for that.
		/// </summary>
		/// <returns>A new StyleListItem for the "Default Paragraph Characters"
		/// psuedo-style.</returns>
		/// ------------------------------------------------------------------------------------
		public static StyleListItem CreateDefaultParaCharItem()
		{
			StyleListItem item = new StyleListItem();
			item.m_itemType = StyleListItemType.DefaultParaChars;
			return item;
		}
示例#36
0
		/// <summary>
		/// Add item during refresh.
		/// </summary>
		/// <param name="items"></param>
		protected override void UpdateStyleList(StyleListItem[] items)
		{
			if (m_ignoreListRefresh)
				return;

			string selectedStyle = ListBoxControl.SelectedItem != null ?
				ListBoxControl.SelectedItem.ToString() : string.Empty;
			ListBoxControl.Items.Clear();
			ListBoxControl.BeginUpdate();
			ListBoxControl.Items.AddRange(items);
			ListBoxControl.EndUpdate();

			SelectedStyleName = selectedStyle;

			// Ensure an item is selected, even if the previous selection is no longer
			// shown.
			if (!String.IsNullOrEmpty(selectedStyle) && ListBoxControl.SelectedItem == null)
			{
				if (ListBoxControl.Items.Count > 0)
					ListBoxControl.SelectedIndex = 0;
			}
		}