Esempio n. 1
0
        /// <summary>
        /// Get a localized control.
        /// </summary>
        /// <param name="dialog">The optional id of the control's dialog.</param>
        /// <param name="control">The id of the control.</param>
        /// <returns>The localized control or null if it wasn't found.</returns>
        public LocalizedControl GetLocalizedControl(string dialog, string control)
        {
            LocalizedControl localizedControl;

            this.localizedControls.TryGetValue(LocalizedControl.GetKey(dialog, control), out localizedControl);
            return(localizedControl);
        }
Esempio n. 2
0
        /// <summary>
        /// Parse a localized control.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="localization">The localization being parsed.</param>
        private void ParseUI(XmlNode node)
        {
            string dialog  = null;
            string control = null;
            int    x       = CompilerCore.IntegerNotSet;
            int    y       = CompilerCore.IntegerNotSet;
            int    width   = CompilerCore.IntegerNotSet;
            int    height  = CompilerCore.IntegerNotSet;
            int    attribs = 0;
            string text    = null;
            SourceLineNumberCollection sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);

            foreach (XmlAttribute attrib in node.Attributes)
            {
                if (0 == attrib.NamespaceURI.Length || attrib.NamespaceURI == Localization.XmlNamespaceUri)
                {
                    switch (attrib.LocalName)
                    {
                    case "Dialog":
                        dialog = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib, null);
                        break;

                    case "Control":
                        control = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib, null);
                        break;

                    case "X":
                        x = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue, null);
                        break;

                    case "Y":
                        y = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue, null);
                        break;

                    case "Width":
                        width = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue, null);
                        break;

                    case "Height":
                        height = Common.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, short.MaxValue, null);
                        break;

                    case "RightToLeft":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib, null))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesRTLRO;
                        }
                        break;

                    case "RightAligned":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib, null))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesRightAligned;
                        }
                        break;

                    case "LeftScroll":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib, null))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesLeftScroll;
                        }
                        break;

                    default:
                        throw new WixException(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name));
                    }
                }
                else
                {
                    throw new WixException(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name));
                }
            }

            text = node.InnerText;

            if (String.IsNullOrEmpty(control) && 0 < attribs)
            {
                if (MsiInterop.MsidbControlAttributesRTLRO == (attribs & MsiInterop.MsidbControlAttributesRTLRO))
                {
                    throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "RightToLeft", "Control"));
                }
                else if (MsiInterop.MsidbControlAttributesRightAligned == (attribs & MsiInterop.MsidbControlAttributesRightAligned))
                {
                    throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "RightAligned", "Control"));
                }
                else if (MsiInterop.MsidbControlAttributesLeftScroll == (attribs & MsiInterop.MsidbControlAttributesLeftScroll))
                {
                    throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "LeftScroll", "Control"));
                }
            }

            if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog))
            {
                throw new WixException(WixErrors.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name, "Dialog", "Control"));
            }

            string key = LocalizedControl.GetKey(dialog, control);

            if (this.localizedControls.ContainsKey(key))
            {
                if (String.IsNullOrEmpty(control))
                {
                    throw new WixException(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, dialog));
                }
                else
                {
                    throw new WixException(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, dialog, control));
                }
            }

            this.localizedControls.Add(key, new LocalizedControl(x, y, width, height, attribs, text));
        }