private void ProcessOneLayoutForCountry(IntPtr configRegistry, ref XklConfigItem item,
                                                ref XklConfigItem subitem, IntPtr data)
        {
            var           subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
            XklConfigItem country       = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
            var           description   = subitemIsNull ? item.Description : subitem.Description;
            var           name          = subitemIsNull ? item.Name : subitem.Name;
            var           variant       = subitemIsNull ? String.Empty : subitem.Description;
            var           layouts       = GetLayoutList(description);

            foreach (var desc in layouts)
            {
                if (desc.LayoutId == name && desc.Description == description && desc.LayoutVariant == variant)
                {
                    return;
                }
            }
            var langCode = subitemIsNull ? item.Short_Description : subitem.Short_Description;

            if (String.IsNullOrEmpty(langCode))
            {
                langCode = subitemIsNull ? item.Name : subitem.Name;
            }
            var newLayout = new LayoutDescription {
                LayoutId      = name,
                Description   = description,
                LayoutVariant = variant,
                LanguageCode  = Get2LetterLanguageCode(langCode),
                CountryCode   = country.Name
            };

            layouts.Add(newLayout);
        }
Exemple #2
0
        private void ProcessLanguage(IntPtr configRegistry, ref XklConfigItem item, IntPtr unused)
        {
            IntPtr dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(item));

            Marshal.StructureToPtr(item, dataPtr, false);
            xkl_config_registry_foreach_language_variant(configRegistry, item.Name,
                                                         ProcessOneLayoutForLanguage, dataPtr);
            Marshal.FreeHGlobal(dataPtr);
        }
        private void ProcessCountry(IntPtr configRegistry, ref XklConfigItem item, IntPtr unused)
        {
            IntPtr dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(item));

            try
            {
                Marshal.StructureToPtr(item, dataPtr, false);
                xkl_config_registry_foreach_country_variant(configRegistry, item.Name,
                                                            ProcessOneLayoutForCountry, dataPtr);
            }
            finally
            {
                Marshal.FreeHGlobal(dataPtr);
            }
        }
        private void ProcessMainLayout(IntPtr configRegistry, ref XklConfigItem item, IntPtr data)
        {
            IntPtr dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(item));

            try
            {
                StoreLayoutInfo(item, data);
                Marshal.StructureToPtr(item, dataPtr, false);
                xkl_config_registry_foreach_layout_variant(configRegistry, item.Name,
                                                           ProcessLayoutVariant, dataPtr);
            }
            finally
            {
                Marshal.FreeHGlobal(dataPtr);
            }
        }
        private void ProcessOneLayoutForLanguage(IntPtr configRegistry, ref XklConfigItem item,
                                                 ref XklConfigItem subitem, IntPtr data)
        {
            var           subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
            XklConfigItem language      = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
            var           description   = subitemIsNull ? item.Description : subitem.Description;
            var           layouts       = GetLayoutList(description);
            var           newLayout     = new LayoutDescription {
                LayoutId      = subitemIsNull ? item.Name : subitem.Name,
                Description   = description,
                LayoutVariant = subitemIsNull ? string.Empty : subitem.Description,
                LanguageCode  = Get2LetterLanguageCode(language.Name),
                CountryCode   = item.Name.ToUpper()
            };

            layouts.Add(newLayout);
        }
        void StoreLayoutInfo(XklConfigItem item, IntPtr data)
        {
            var description = item.Description;
            var variant     = data != IntPtr.Zero ? description : String.Empty;
            var layouts     = GetLayoutList(description);

            foreach (var desc in layouts)
            {
                if (desc.LayoutId == item.Name && desc.Description == description && desc.LayoutVariant == variant)
                {
                    return;
                }
            }
            var newLayout = new LayoutDescription {
                LayoutId      = item.Name,
                Description   = description,
                LayoutVariant = variant
            };

            if (data != IntPtr.Zero)
            {
                XklConfigItem parent   = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
                var           langCode = String.IsNullOrEmpty(item.Short_Description) ? parent.Short_Description : item.Short_Description;
                if (String.IsNullOrEmpty(langCode))
                {
                    langCode = String.IsNullOrEmpty(item.Name) ? parent.Name : item.Name;
                }
                newLayout.LanguageCode = Get2LetterLanguageCode(langCode);
                if (parent.Name.Length == 2 || item.Name != item.Short_Description)
                {
                    newLayout.CountryCode = parent.Name.ToUpper();
                }
            }
            else
            {
                newLayout.LanguageCode = Get2LetterLanguageCode(String.IsNullOrEmpty(item.Short_Description) ? item.Name : item.Short_Description);
                if (item.Name.Length == 2 || item.Name != item.Short_Description)
                {
                    newLayout.CountryCode = item.Name.ToUpper();
                }
            }
            layouts.Add(newLayout);
        }
Exemple #7
0
        private void ProcessOneLayoutForLanguage(IntPtr configRegistry, ref XklConfigItem item,
                                                 ref XklConfigItem subitem, IntPtr data)
        {
            var           subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
            XklConfigItem language      = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
            var           description   = subitemIsNull ? item.Description :
                                          item.Description + " - " + subitem.Description;
            List <LayoutDescription> layouts;

            if (m_Layouts.ContainsKey(description))
            {
                layouts = m_Layouts[description];
            }
            else
            {
                layouts = new List <LayoutDescription>();
                m_Layouts[description] = layouts;
            }

            var newLayout = new LayoutDescription {
                LayoutId      = subitemIsNull ? item.Name : item.Name + "\t" + subitem.Name,
                Description   = description,
                LayoutVariant = subitemIsNull ? string.Empty : subitem.Description,
                LanguageCode  = language.Name
            };

            if (item.Short_Description.Length < 3)
            {
                // we have a two letter country code; need to find the three-letter one
                newLayout.CountryCode =
                    Icu.GetISO3Country(item.Short_Description + "_" + item.Name).ToUpper();
            }
            else
            {
                newLayout.CountryCode = item.Short_Description.ToUpper();
            }
            layouts.Add(newLayout);
        }
        private void ProcessOneLayoutForLanguage(IntPtr configRegistry, ref XklConfigItem item,
                                                 ref XklConfigItem subitem, IntPtr data)
        {
            var subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
            var language      = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
            var description   = subitemIsNull ? item.Description : subitem.Description;
            var name          = subitemIsNull ? item.Name : subitem.Name;
            var variant       = subitemIsNull ? string.Empty : subitem.Description;
            var layouts       = GetLayoutList(description);

            var newLayout = new LayoutDescription {
                LayoutId      = name,
                Description   = description,
                LayoutVariant = variant,
                LanguageCode  = Get2LetterLanguageCode(language.Name),
                CountryCode   = item.Name.ToUpper()
            };

            // don't add same layout twice (LT-20288)
            if (!layouts.Any(layout => layout.Equals(newLayout)))
            {
                layouts.Add(newLayout);
            }
        }
 private void ProcessLayoutVariant(IntPtr configRegistry, ref XklConfigItem item, IntPtr data)
 {
     StoreLayoutInfo(item, data);
 }
		void StoreLayoutInfo(XklConfigItem item, IntPtr data)
		{
			var description = item.Description;
			var variant = data != IntPtr.Zero ? description : String.Empty;
			var layouts = GetLayoutList(description);
			foreach (var desc in layouts)
			{
				if (desc.LayoutId == item.Name && desc.Description == description && desc.LayoutVariant == variant)
					return;
			}
			var newLayout = new LayoutDescription {
				LayoutId = item.Name,
				Description = description,
				LayoutVariant = variant
			};
			if (data != IntPtr.Zero)
			{
				XklConfigItem parent = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
				var langCode = String.IsNullOrEmpty(item.Short_Description) ? parent.Short_Description : item.Short_Description;
				if (String.IsNullOrEmpty(langCode))
					langCode = String.IsNullOrEmpty(item.Name) ? parent.Name : item.Name;
				newLayout.LanguageCode = Get2LetterLanguageCode(langCode);
				if (parent.Name.Length == 2 || item.Name != item.Short_Description)
					newLayout.CountryCode = parent.Name.ToUpper();
			}
			else
			{
				newLayout.LanguageCode = Get2LetterLanguageCode(String.IsNullOrEmpty(item.Short_Description) ? item.Name : item.Short_Description);
				if (item.Name.Length == 2 || item.Name != item.Short_Description)
					newLayout.CountryCode = item.Name.ToUpper();
			}
			layouts.Add(newLayout);
		}
		private void ProcessLayoutVariant(IntPtr configRegistry, ref XklConfigItem item, IntPtr data)
		{
			StoreLayoutInfo(item, data);
		}
		private void ProcessMainLayout(IntPtr configRegistry, ref XklConfigItem item, IntPtr data)
		{
			IntPtr dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(item));
			try
			{
				StoreLayoutInfo(item, data);
				Marshal.StructureToPtr(item, dataPtr, false);
				xkl_config_registry_foreach_layout_variant(configRegistry, item.Name,
					ProcessLayoutVariant, dataPtr);
			}
			finally
			{
				Marshal.FreeHGlobal(dataPtr);
			}
		}
		private void ProcessOneLayoutForCountry(IntPtr configRegistry, ref XklConfigItem item,
			ref XklConfigItem subitem, IntPtr data)
		{
			var subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
			XklConfigItem country = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
			var description = subitemIsNull ? item.Description : subitem.Description;
			var name = subitemIsNull ? item.Name : subitem.Name;
			var variant = subitemIsNull ? String.Empty : subitem.Description;
			var layouts = GetLayoutList(description);
			foreach (var desc in layouts)
			{
				if (desc.LayoutId == name && desc.Description == description && desc.LayoutVariant == variant)
					return;
			}
			var langCode = subitemIsNull ? item.Short_Description : subitem.Short_Description;
			if (String.IsNullOrEmpty(langCode))
				langCode = subitemIsNull ? item.Name : subitem.Name;
			var newLayout = new LayoutDescription {
				LayoutId = name,
				Description = description,
				LayoutVariant = variant,
				LanguageCode = Get2LetterLanguageCode(langCode),
				CountryCode = country.Name
			};
			layouts.Add(newLayout);
		}
		private void ProcessCountry(IntPtr configRegistry, ref XklConfigItem item, IntPtr unused)
		{
			IntPtr dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(item));
			try
			{
				Marshal.StructureToPtr(item, dataPtr, false);
				xkl_config_registry_foreach_country_variant(configRegistry, item.Name,
					ProcessOneLayoutForCountry, dataPtr);
			}
			finally
			{
				Marshal.FreeHGlobal(dataPtr);
			}
		}
		private void ProcessOneLayoutForLanguage(IntPtr configRegistry, ref XklConfigItem item,
			ref XklConfigItem subitem, IntPtr data)
		{
			var subitemIsNull = subitem.Parent.RefCount == IntPtr.Zero;
			XklConfigItem language = (XklConfigItem)Marshal.PtrToStructure(data, typeof(XklConfigItem));
			var description = subitemIsNull ? item.Description : subitem.Description;
			var layouts = GetLayoutList(description);
			var newLayout = new LayoutDescription {
				LayoutId = subitemIsNull ? item.Name : subitem.Name,
				Description = description,
				LayoutVariant = subitemIsNull ? string.Empty : subitem.Description,
				LanguageCode = Get2LetterLanguageCode(language.Name),
				CountryCode = item.Name.ToUpper()
			};
			layouts.Add(newLayout);
		}