X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWindow.java;h=58195c915f1ae885485891f159539f53ece7b474;hb=12b90437b5f22c2ae6e9b9b14c3b62b60f6143e5;hp=3f860d636cac5db22e3454f0661acb3efe5ae4e6;hpb=c88c4ced6e9392a53030a1c680fe114931a1a928;p=fanfix.git diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index 3f860d6..58195c9 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -34,6 +34,7 @@ import java.util.Set; import jexer.backend.Screen; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.StringUtils; import jexer.event.TCommandEvent; import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; @@ -607,6 +608,15 @@ public class TWindow extends TWidget { @Override public void onKeypress(final TKeypressEvent keypress) { + if (inWindowMove || inWindowResize) { + // ESC or ENTER - Exit size/move + if (keypress.equals(kbEsc) || keypress.equals(kbEnter)) { + inWindowMove = false; + inWindowResize = false; + return; + } + } + if (inKeyboardResize) { // ESC or ENTER - Exit size/move @@ -848,6 +858,38 @@ public class TWindow extends TWidget { super.onMenu(menu); } + /** + * Method that subclasses can override to handle window/screen resize + * events. + * + * @param resize resize event + */ + @Override + public void onResize(final TResizeEvent resize) { + if (resize.getType() == TResizeEvent.Type.WIDGET) { + if (getChildren().size() == 1) { + TWidget child = getChildren().get(0); + if ((child instanceof TSplitPane) + || (child instanceof TPanel) + ) { + if (this instanceof TDesktop) { + child.onResize(new TResizeEvent( + TResizeEvent.Type.WIDGET, + resize.getWidth(), resize.getHeight())); + } else { + child.onResize(new TResizeEvent( + TResizeEvent.Type.WIDGET, + resize.getWidth() - 2, resize.getHeight() - 2)); + } + } + return; + } + } + + // Pass on to TWidget. + super.onResize(resize); + } + // ------------------------------------------------------------------------ // TWidget ---------------------------------------------------------------- // ------------------------------------------------------------------------ @@ -886,10 +928,11 @@ public class TWindow extends TWidget { true); // Draw the title - int titleLeft = (getWidth() - title.length() - 2) / 2; + int titleLength = StringUtils.width(title); + int titleLeft = (getWidth() - titleLength - 2) / 2; putCharXY(titleLeft, 0, ' ', border); - putStringXY(titleLeft + 1, 0, title); - putCharXY(titleLeft + title.length() + 1, 0, ' ', border); + putStringXY(titleLeft + 1, 0, title, border); + putCharXY(titleLeft + titleLength + 1, 0, ' ', border); if (isActive()) { @@ -1122,9 +1165,9 @@ public class TWindow extends TWidget { restoreWindowX = getX(); restoreWindowY = getY(); setWidth(getScreen().getWidth()); - setHeight(application.getDesktopBottom() - 1); + setHeight(application.getDesktopBottom() - application.getDesktopTop()); setX(0); - setY(1); + setY(application.getDesktopTop()); maximized = true; onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(), @@ -1186,6 +1229,7 @@ public class TWindow extends TWidget { /** * Activate window (bring to top and receive events). */ + @Override public void activate() { application.activateWindow(this); } @@ -1381,7 +1425,7 @@ public class TWindow extends TWidget { * @return true if this window does not want the application-wide mouse * cursor drawn over it */ - public final boolean hasHiddenMouse() { + public boolean hasHiddenMouse() { return hideMouse; } @@ -1396,4 +1440,16 @@ public class TWindow extends TWidget { this.hideMouse = hideMouse; } + /** + * Generate a human-readable string for this window. + * + * @return a human-readable string + */ + @Override + public String toString() { + return String.format("%s(%8x) \'%s\' position (%d, %d) geometry %dx%d" + + " hidden %s modal %s", getClass().getName(), hashCode(), title, + getX(), getY(), getWidth(), getHeight(), hidden, isModal()); + } + }