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; } } } }
public override void ApplyFormattingAndLayout(SlotData slotData, SlotStyleData slotStyleData, TableLayoutItemInfo layout) { base.ApplyFormattingAndLayout(slotData, slotStyleData, layout); Brush background = null; Brush foreground = null; short fontID = -1; //IMPLEMENT: the rest of the properties in SlotData, SlotStyleData, and TableLayoutItemInfo if (layout != null) { // margins and paddings Margin = new Spacing(layout.LeftMargin, layout.TopMargin, layout.RightMargin, layout.BottomMargin); Padding = new Spacing(layout.LeftPadding, layout.TopPadding, layout.RightPadding, layout.BottomPadding); // cropping Crop = layout.CropStrategy; } if (slotData != null) { // background if (slotData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { background = bgRes.Brush; } } // foreground if (slotData.Foreground.HasValue) { PaintStyleResult fgRes = ResolvePaintStyle(slotData.Foreground.Value, PaintStyleUse.Foreground); if (fgRes.Brush != null) { foreground = fgRes.Brush; } } // get font fontID = slotData.Font ?? -1; } if (slotStyleData != null) { // cropping Crop = slotStyleData.Crop; // background if (slotStyleData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotStyleData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { background = bgRes.Brush; } } // foreground if (slotStyleData.Foreground.HasValue) { PaintStyleResult fgRes = ResolvePaintStyle(slotStyleData.Foreground.Value, PaintStyleUse.Foreground); if (fgRes.Brush != null) { foreground = fgRes.Brush; } } // get font fontID = slotStyleData.Font; } // use parent foreground if needed if (foreground == null) { foreground = Atomic.Foreground; } // apply brushes Background = background; textControl.Foreground = foreground; // apply font if (fontID != -1) { FontReferencePaletteEntry fr = Atomic.FindCascadedPaletteItem(fontID) as FontReferencePaletteEntry; if (fr != null) { FontDefinition fd = fr.Resolve(Atomic.ParentNode.ApplicationID); if (fd != null) { fd.Apply(textControl); } } } // apply cropping, alignment, tick if ((Crop & CropStrategy.Wrap) == CropStrategy.Wrap) { textControl.TextWrapping = TextWrapping.Wrap; if ((Crop & CropStrategy.Tick) == CropStrategy.Tick) { textControl.TextTrimming = TextTrimming.WordEllipsis; } else { textControl.TextTrimming = TextTrimming.None; } } else if ((Crop & CropStrategy.Tick) == CropStrategy.Tick) { textControl.TextWrapping = TextWrapping.NoWrap; textControl.TextTrimming = TextTrimming.WordEllipsis; } else { textControl.TextWrapping = TextWrapping.NoWrap; textControl.TextTrimming = TextTrimming.None; } // set horizontal alignment (vertical one is done in layout) if ((Crop & CropStrategy.AlignLeft) == CropStrategy.AlignLeft) { textControl.TextAlignment = TextAlignment.Left; } else if ((Crop & CropStrategy.AlignHCenter) == CropStrategy.AlignHCenter) { textControl.TextAlignment = TextAlignment.Center; } else if ((Crop & CropStrategy.AlignRight) == CropStrategy.AlignRight) { textControl.TextAlignment = TextAlignment.Right; } }
public virtual void ApplyFormattingAndLayout(SlotData slotData, SlotStyleData slotStyleData, TableLayoutItemInfo layout) { }
public override void ApplyFormattingAndLayout(SlotData slotData, SlotStyleData slotStyleData, TableLayoutItemInfo layout) { base.ApplyFormattingAndLayout(slotData, slotStyleData, layout); //IMPLEMENT: the rest of the properties in SlotData, SlotStyleData, and TableLayoutItemInfo if (layout != null) { Margin = new Spacing(layout.LeftMargin, layout.TopMargin, layout.RightMargin, layout.BottomMargin); Padding = new Spacing(layout.LeftPadding, layout.TopPadding, layout.RightPadding, layout.BottomPadding); Crop = layout.CropStrategy; } if (slotData != null) { // background if (slotData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { Background = bgRes.Brush; } } } if (slotStyleData != null) { Crop = slotStyleData.Crop; // background if (slotStyleData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotStyleData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { Background = bgRes.Brush; } } } }
public RendererBase CreateRenderer(AtomicBlockBase parent, DisplayData data, SlotData slotData, SlotStyleData slotStyleData, TableLayoutItemInfo layout) { RendererBase res = null; if (data != null) { switch (data.DisplayType) { case DisplayType.String: res = new TextRenderer(parent); break; case DisplayType.ContentReference: { ContentReference cref = data.Data as ContentReference; if (cref != null) { switch (cref.MediaType) { case MediaPrimitiveType.Image: case MediaPrimitiveType.ImageStrip: res = new ImageRenderer(parent); break; default: DebugHelper.Out("Unsupported content reference media type: {0}", cref.MediaType); break; } } break; } case DisplayType.MediaMetaData: { MediaMetaData mmd = data.Data as MediaMetaData; if (mmd != null) { ContentReference cref = mmd[Core.System.CurrentDeviceGroup]; if (cref != null) { switch (cref.MediaType) { case MediaPrimitiveType.Image: case MediaPrimitiveType.ImageStrip: res = new ImageRenderer(parent); break; case MediaPrimitiveType.String: res = new TextRenderer(parent); break; default: DebugHelper.Out("Unsupported content reference media type: {0}", cref.MediaType); break; } } } break; } case DisplayType.EditableString: res = new TextEntryRenderer(parent); break; default: //IMPLEMENT: more display types DebugHelper.Out("Unsupported renderer type: {0}", data.DisplayType); break; } if (res != null) { res.SetDisplayData(data); res.ApplyFormattingAndLayout(slotData, slotStyleData, layout); } } return(res); }