1 /*******************************************************************************
\r
2 * Copyright (c) 2006 Sybase, Inc. and others.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Sybase, Inc. - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.eclipse.jst.pagedesigner.css2.layout;
\r
14 import org.eclipse.draw2d.Graphics;
\r
15 import org.eclipse.draw2d.geometry.Dimension;
\r
16 import org.eclipse.draw2d.geometry.Rectangle;
\r
17 import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo;
\r
18 import org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider;
\r
23 public class CSSWidgetLayout extends CSSBlockFlowLayout implements ICSSPainter {
\r
24 private WidgetBox _widgetBox;
\r
26 private ICSSWidgetProvider _provider;
\r
32 public CSSWidgetLayout(CSSFigure flowfigure, ICSSWidgetProvider provider) {
\r
34 _provider = provider;
\r
38 * normally this method is called directly after constructor
\r
42 public void setProvider(ICSSWidgetProvider provider) {
\r
43 _provider = provider;
\r
47 * @return the provider
\r
49 public ICSSWidgetProvider getProvider() {
\r
50 // return ((CSSWidgetFigure)this.getFlowFigure()).getProvider();
\r
57 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock()
\r
59 public boolean isInlineBlock() {
\r
60 ICSSWidgetProvider provider = getProvider();
\r
61 return provider.isInline();
\r
67 * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout()
\r
69 protected void layoutChildren() {
\r
70 ICSSWidgetProvider provider = getProvider();
\r
72 // if we did endLine, then will result in context create a new line, so
\r
73 // we may in the new line now.
\r
74 // passing in the top margin, and context will consider that when
\r
75 // creating the new line.
\r
77 int suggestedWith = _blockBox.getContentWidth();
\r
78 int suggestedHeight = _blockBox.getContentHeight();
\r
79 // int suggestedWith = getSuggestedWidth(line, style, provider);
\r
80 // int suggestedHeight = getSuggestedHeight(line, style, provider);
\r
82 DimensionInfo resultInfo = provider.getPreferredDimension(
\r
83 suggestedWith, suggestedHeight);
\r
84 Dimension resultSize = resultInfo.getDimension();
\r
86 _widgetBox = new WidgetBox(); // ((CSSWidgetFigure)getFlowFigure()).getWidgetBox();
\r
87 // if (provider.isHandlingBorder() || style == null)
\r
89 _widgetBox.setWidth(resultSize.width);
\r
90 _widgetBox.setHeight(resultSize.height);
\r
91 _widgetBox.setAscent(resultInfo.getAscent());
\r
95 // widgetBox.setWidth(resultSize.width +
\r
96 // style.getBorderInsets().getWidth());
\r
97 // widgetBox.setHeight(resultSize.height +
\r
98 // style.getBorderInsets().getHeight());
\r
99 // widgetBox.setAscent(resultInfo.getAscent()+style.getBorderInsets().top);
\r
101 this.addToCurrentLine(_widgetBox);
\r
102 // if (!provider.isInline())
\r
104 // context.endLine();
\r
111 * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose()
\r
113 public void dispose() {
\r
114 // TODO: anything to dispose?
\r
117 // public int getSuggestedWidth(LineBox line, ICSSStyle style,
\r
118 // ICSSWidgetProvider provider)
\r
120 // if (style == null) return -1;
\r
122 // Object width = style.getStyleProperty(ICSSPropertyID.ATTR_WIDTH);
\r
123 // Length recommendedWidth = (width instanceof Length) ? (Length) width :
\r
127 // if (recommendedWidth == null || recommendedWidth.getValue() <= 0)
\r
133 // if (recommendedWidth.isPercentage())
\r
135 // rw = line.getAvailableWidth() * recommendedWidth.getValue() / 100;
\r
139 // rw = recommendedWidth.getValue();
\r
142 // if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder())
\r
144 // rw += style.getBorderInsets().getWidth() +
\r
145 // style.getPaddingInsets().getWidth();
\r
147 // else if (style.isSizeIncludeBorderPadding() &&
\r
148 // !provider.isHandlingBorder())
\r
150 // rw -= style.getBorderInsets().getWidth() +
\r
151 // style.getPaddingInsets().getWidth();
\r
158 // public int getSuggestedHeight(LineBox line, ICSSStyle style,
\r
159 // ICSSWidgetProvider provider)
\r
161 // if (style == null) return -1;
\r
163 // Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT);
\r
164 // Length recommendedHeight = (height instanceof Length) ? (Length) height :
\r
168 // if (recommendedHeight == null || recommendedHeight.getValue() <= 0)
\r
174 // if (recommendedHeight.isPercentage())
\r
176 // // we don't support percentage height for this version, ignore
\r
181 // rh = recommendedHeight.getValue();
\r
184 // if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder())
\r
186 // rh += style.getBorderInsets().getHeight() +
\r
187 // style.getPaddingInsets().getHeight();
\r
189 // else if (style.isSizeIncludeBorderPadding() &&
\r
190 // !provider.isHandlingBorder())
\r
192 // rh -= style.getBorderInsets().getHeight() +
\r
193 // style.getPaddingInsets().getHeight();
\r
203 * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics)
\r
205 public void paintFigure(Graphics g) {
\r
206 ICSSWidgetProvider provider = this.getProvider();
\r
207 if (provider != null && _widgetBox != null) {
\r
208 provider.paintFigure(g, new Rectangle(_widgetBox._x, _widgetBox._y,
\r
209 _widgetBox.getWidth(), _widgetBox.getHeight()));
\r
216 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#handlingBorderForBlock()
\r
218 public boolean handlingBorderForBlock() {
\r
219 ICSSWidgetProvider provider = this.getProvider();
\r
220 if (provider != null) {
\r
221 return provider.isHandlingBorder();
\r
223 return super.handlingBorderForBlock();
\r