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; } } } }
protected override void SwitchToState(BlockState state) { if (state == currentState) { return; } // clean-up WaveChildren.Clear(); Children.Clear(); // try to create new state SingleSlotBlockStateData stateData = Data[state]; if (stateData != null) { // 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); // create slot slot = Core.UIFactory.CreateRenderer(this, displayData[stateData.SlotIndex], null, stateData.SlotStyle, null); if (slot != null) { WaveChildren.Add(slot); Children.Add(slot); } // fire required anchors switch (currentState) { 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; } } // and finally save current state currentState = state; } }