From 52df81b4d4b945cdd4d347f96886406ac3389c84 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 14 Mar 2008 07:59:12 +0000 Subject: [PATCH] TextFields now support width properly svn changeset:4045/svn branch:trunk --- .../gwt/client/ui/IPopupCalendar.java | 8 ++++ .../terminal/gwt/client/ui/ITextualDate.java | 48 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java index 098967b8d9..c398c1b742 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupCalendar.java @@ -111,4 +111,12 @@ public class IPopupCalendar extends ITextualDate implements Paintable, calendar.setFocus(focus); } + protected int getFieldExtraWidth() { + if (fieldExtraWidth < 0) { + fieldExtraWidth = super.getFieldExtraWidth(); + fieldExtraWidth += calendarToggle.getOffsetWidth(); + } + return fieldExtraWidth; + } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java index beff13d1c5..02a401833d 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java @@ -8,13 +8,14 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener; import com.itmill.toolkit.terminal.gwt.client.DateLocale; import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.UIDL; import com.itmill.toolkit.terminal.gwt.client.util.SimpleDateFormat; public class ITextualDate extends IDateField implements Paintable, - ChangeListener { + ChangeListener, ContainerResizedListener { private final ITextField text; @@ -22,6 +23,12 @@ public class ITextualDate extends IDateField implements Paintable, private DateLocale dl; + private String width; + + private boolean needLayout; + + protected int fieldExtraWidth = -1; + public ITextualDate() { super(); text = new ITextField(); @@ -237,4 +244,43 @@ public class ITextualDate extends IDateField implements Paintable, return format.trim(); } + + public void setWidth(String newWidth) { + if (!"".equals(newWidth) && (width == null || !newWidth.equals(width))) { + needLayout = true; + width = newWidth; + super.setWidth(width); + iLayout(); + if (newWidth.indexOf("%") < 0) { + needLayout = false; + } + } else { + if (width != null && !"".equals(width)) { + super.setWidth(""); + needLayout = true; + iLayout(); + needLayout = false; + width = null; + } + } + } + + /** + * Returns pixels in x-axis reserved for other than textfield content. + * + * @return extra width in pixels + */ + protected int getFieldExtraWidth() { + if (fieldExtraWidth < 0) { + text.setWidth("0px"); + fieldExtraWidth = text.getOffsetWidth(); + } + return fieldExtraWidth; + } + + public void iLayout() { + if (needLayout) { + text.setWidth((getOffsetWidth() - getFieldExtraWidth()) + "px"); + } + } } -- 2.39.5