private void UnpackDefinition()
        {
            // extract colours
            if (Data != null)
            {
                AtomicBlockStateData stateData = Data[BlockState.Normal];

                if (stateData != null)
                {
                    if (stateData.ComponentForeground.HasValue)
                    {
                        PaintStyleResult res = ResolvePaintStyle(stateData.ComponentForeground.Value);

                        if ((res.Brush != null) && (res.Brush is SolidColorBrush))
                        {
                            ForegroundColour = ((SolidColorBrush)res.Brush).Color;
                        }
                    }

                    if (stateData.ComponentBackground.HasValue)
                    {
                        PaintStyleResult res = ResolvePaintStyle(stateData.ComponentBackground.Value);

                        if ((res.Brush != null) && (res.Brush is SolidColorBrush))
                        {
                            BackgroundColour = ((SolidColorBrush)res.Brush).Color;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void UnpackContent()
        {
            if ((Data != null) && Data.HasState(BlockState.Normal))
            {
                // visibility
                isVisible = !Data.RenderingHints[RenderingHintKey.Visibility].Equals(WaveConstant.False, StringComparison.InvariantCultureIgnoreCase);

                // opacity
                string opData = Data.RenderingHints[RenderingHintKey.Opacity];

                if (!String.IsNullOrEmpty(opData))
                {
                    double temp = 0;

                    if (Double.TryParse(opData, out temp))
                    {
                        opacity = temp;
                    }
                }

                // try to get colours
                AtomicBlockStateData state = Data[BlockState.Normal];

                if (state != null)
                {
                    if (state.ComponentBackground.HasValue && (state.ComponentBackground.Value.StyleType == PaletteEntryType.Colour))
                    {
                        PaintStyleResult res = ResolvePaintStyle(state.ComponentBackground.Value);

                        if ((res.Context == PaintStyleResult.Result.Colour) && (res.Brush is SolidColorBrush))
                        {
                            background = ((SolidColorBrush)res.Brush).Color;
                        }
                    }

                    if (state.ComponentForeground.HasValue && (state.ComponentForeground.Value.StyleType == PaletteEntryType.Colour))
                    {
                        PaintStyleResult res = ResolvePaintStyle(state.ComponentForeground.Value);

                        if ((res.Context == PaintStyleResult.Result.Colour) && (res.Brush is SolidColorBrush))
                        {
                            foreground = ((SolidColorBrush)res.Brush).Color;
                        }
                    }
                }
            }
        }
Exemple #3
0
        protected override void SwitchToState(BlockState state)
        {
            if (state == currentState)
            {
                return;
            }

            if (((state == BlockState.Normal) && !hasNormalState) || ((state == BlockState.Focused) && !hasFocusedState) ||
                ((state == BlockState.CheckedNormal) && !hasCheckedNormalState) || ((state == BlockState.CheckedFocused) && !hasCheckedFocusedState))
            {
                return;
            }

            // save old state
            BlockState oldState = currentState;

            // set current state
            currentState = state;

            // clean-up
            WaveChildren.Clear();
            Children.Clear();

            // try to create new state
            AtomicBlockStateData stateData = Data[state];

            if (stateData != null)
            {
                // background
                if (stateData.ComponentBackground.HasValue)
                {
                    PaintStyleResult bgRes = ResolvePaintStyle(stateData.ComponentBackground.Value);

                    if (bgRes.Brush != null)
                    {
                        Background = bgRes.Brush;
                    }
                }

                // foreground
                if (stateData.ComponentForeground.HasValue)
                {
                    PaintStyleResult fgRes = ResolvePaintStyle(stateData.ComponentForeground.Value);

                    if (fgRes.Brush != null)
                    {
                        Foreground = fgRes.Brush;
                    }
                }

                // margins and paddings
                Margin  = new Spacing(stateData.MarginLeft, stateData.MarginTop, stateData.MarginRight, stateData.MarginBottom);
                Padding = new Spacing(stateData.PaddingLeft, stateData.PaddingTop, stateData.PaddingRight, stateData.PaddingBottom);

                // setup layout
                TableLayoutTemplate table = stateData.LayoutTemplate as TableLayoutTemplate;

                if (table != null)
                {
                    // save this layout for layout passes
                    currentLayout = table;

                    // create slots
                    for (int i = 0; i < stateData.SlotInfo.Count; i++)
                    {
                        int          slotIndex = stateData.SlotInfo[i].SlotIndex ?? i;
                        RendererBase renderer  = null;

                        // find layout information for the slot
                        TableLayoutItemInfo slotLayout = null;

                        if ((table.LayoutItems != null) && (i < table.LayoutItems.Count))
                        {
                            slotLayout = table.LayoutItems[i];
                        }

                        // find display data for the slot
                        DisplayData dd = null;

                        if (Data.StaticDisplayData != null)
                        {
                            if (slotIndex < Data.StaticDisplayData.Count)
                            {
                                // static display data
                                dd = Data.StaticDisplayData[slotIndex];
                            }
                            else if (serverDisplayData != null)
                            {
                                // server display data (with modified index)
                                dd = serverDisplayData[slotIndex - Data.StaticDisplayData.Count];
                            }
                        }
                        else if (serverDisplayData != null)
                        {
                            // server display data
                            dd = serverDisplayData[slotIndex];
                        }

                        if ((dd != null) && (i < table.LayoutItems.Count))
                        {
                            renderer = Core.UIFactory.CreateRenderer(this, dd, stateData.SlotInfo[i], null, slotLayout);

                            if (renderer != null)
                            {
                                TableLayout.SetSlotPosition(
                                    renderer,
                                    new TableLayoutPosition()
                                {
                                    Column     = table.LayoutItems[i].SlotX,
                                    Row        = table.LayoutItems[i].SlotY,
                                    ColumnSpan = table.LayoutItems[i].SlotXEnd - table.LayoutItems[i].SlotX,
                                    RowSpan    = table.LayoutItems[i].SlotYEnd - table.LayoutItems[i].SlotY
                                });

                                renderer.HorizontalAlignment = HorizontalAlignment.Stretch;
                                renderer.VerticalAlignment   = VerticalAlignment.Stretch;

                                WaveChildren.Add(renderer);
                                Children.Add(renderer);
                            }
                        }
                    }
                }

                // fire required anchors
                switch (oldState)
                {
                case BlockState.Normal:
                {
                    switch (state)
                    {
                    case BlockState.Focused:
                        FireAction(Anchor.OnFocused);
                        break;

                    case BlockState.CheckedNormal:
                        FireAction(Anchor.OnChecked);
                        break;

                    case BlockState.CheckedFocused:
                        FireAction(Anchor.OnChecked);
                        FireAction(Anchor.OnFocused);
                        break;
                    }

                    break;
                }

                case BlockState.Focused:
                {
                    switch (state)
                    {
                    case BlockState.Normal:
                        FireAction(Anchor.OnUnfocused);
                        break;

                    case BlockState.CheckedNormal:
                        FireAction(Anchor.OnChecked);
                        FireAction(Anchor.OnUnfocused);
                        break;

                    case BlockState.CheckedFocused:
                        FireAction(Anchor.OnChecked);
                        break;
                    }

                    break;
                }

                case BlockState.CheckedNormal:
                {
                    switch (state)
                    {
                    case BlockState.Normal:
                        FireAction(Anchor.OnUnchecked);
                        break;

                    case BlockState.Focused:
                        FireAction(Anchor.OnUnchecked);
                        FireAction(Anchor.OnFocused);
                        break;

                    case BlockState.CheckedFocused:
                        FireAction(Anchor.OnFocused);
                        break;
                    }

                    break;
                }

                case BlockState.CheckedFocused:
                {
                    switch (state)
                    {
                    case BlockState.Normal:
                        FireAction(Anchor.OnUnchecked);
                        FireAction(Anchor.OnUnfocused);
                        break;

                    case BlockState.Focused:
                        FireAction(Anchor.OnUnchecked);
                        break;

                    case BlockState.CheckedNormal:
                        FireAction(Anchor.OnUnfocused);
                        break;
                    }

                    break;
                }
                }
            }
        }