Example #1
0
        public void Unpack(FieldList source)
        {
            if (source == null)
            {
                return;
            }

            UnpackDefinitionID(source);

            if (source.GetItemCount(DefAgentFieldID.PaletteEntryIndex) > 0)
            {
                int paletteSize = source[DefAgentFieldID.PaletteSize].AsShort() ?? 0;

                if (paletteSize > 0)
                {
                    // create internal array
                    entries = new PaletteEntryBase[paletteSize];

                    // add entries
                    IEnumerator <IFieldBase> enumerator = source.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryIndex)
                        {
                            int entryIndex = enumerator.Current.AsShort() ?? -1;

                            if (entryIndex != -1)
                            {
                                enumerator.MoveNext();

                                if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryType)
                                {
                                    PaletteEntryType entryType = (PaletteEntryType)(enumerator.Current.AsByte() ?? 0);
                                    PaletteEntryBase newEntry  = null;

                                    switch (entryType)
                                    {
                                    case PaletteEntryType.Undefined:
                                    default:
                                        break;

                                    case PaletteEntryType.Inherited:
                                        newEntry = new InheritedPaletteEntry();
                                        break;

                                    case PaletteEntryType.DoNotPaint:
                                        newEntry = new DoNotPaintPaletteEntry();
                                        break;

                                    case PaletteEntryType.FontReference:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            int fontDefID = enumerator.Current.AsInteger() ?? -1;

                                            if (fontDefID != -1)
                                            {
                                                newEntry = new FontReferencePaletteEntry(fontDefID);
                                            }
                                        }

                                        break;
                                    }

                                    case PaletteEntryType.Image:
                                    {
                                        break;
                                    }

                                    case PaletteEntryType.Colour:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            int?argb = enumerator.Current.AsInteger();

                                            if (argb.HasValue)
                                            {
                                                newEntry = new ColourPaletteEntry(argb.Value);
                                            }
                                        }

                                        break;
                                    }

                                    case PaletteEntryType.LinearGradient:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            FieldList gradientData = enumerator.Current as FieldList;

                                            if (gradientData != null)
                                            {
                                                newEntry = new LinearGradientPaletteEntry(gradientData);
                                            }
                                        }

                                        break;
                                    }

                                    case PaletteEntryType.ColourSequence:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            FieldList clsData = enumerator.Current as FieldList;

                                            if (clsData != null)
                                            {
                                                newEntry = new ColourSequencePaletteEntry(clsData);
                                            }
                                        }

                                        break;
                                    }

                                    case PaletteEntryType.PaletteReference:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            int rf = enumerator.Current.AsInteger() ?? -1;

                                            if (rf != -1)
                                            {
                                                newEntry = new PaletteReferencePaletteEntry(rf);
                                            }
                                        }

                                        break;
                                    }

                                    case PaletteEntryType.StyleSet:
                                    case PaletteEntryType.SystemDialogRoot:
                                    case PaletteEntryType.SystemDialogContainer:
                                    case PaletteEntryType.SystemDialogTitle:
                                    case PaletteEntryType.SystemDialogStaticText:
                                    case PaletteEntryType.SystemDialogListEntry:
                                    case PaletteEntryType.SystemDialogMenuBar:
                                    {
                                        enumerator.MoveNext();

                                        if (enumerator.Current.FieldID == (short)DefAgentFieldID.PaletteEntryData)
                                        {
                                            FieldList styleSetData = enumerator.Current as FieldList;

                                            if (styleSetData != null)
                                            {
                                                StyleSet sst = new StyleSet(entryType);
                                                sst.Unpack(styleSetData);

                                                newEntry = sst;
                                            }
                                        }

                                        break;
                                    }
                                    }

                                    if (newEntry != null)
                                    {
                                        entries[entryIndex] = newEntry;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // done
            IsUnpacked = true;
        }