X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWindow.java;h=6763df3063640e5e2504dfa34d2e6f5bf6997b43;hb=2bc32111fa17ae50a8aaa09ab347191fefc494a1;hp=16945496e1f792d526240f3982aca67fc0f8a6a9;hpb=9696a8f6da9a0d204740420d6d8571176ab81944;p=fanfix.git diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index 1694549..6763df3 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -32,9 +32,9 @@ import java.util.HashSet; import java.util.Set; import jexer.backend.Screen; -import jexer.bits.Cell; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.StringUtils; import jexer.event.TCommandEvent; import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; @@ -849,6 +849,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 ---------------------------------------------------------------- // ------------------------------------------------------------------------ @@ -887,10 +919,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()) { @@ -1123,9 +1156,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(), @@ -1187,6 +1220,7 @@ public class TWindow extends TWidget { /** * Activate window (bring to top and receive events). */ + @Override public void activate() { application.activateWindow(this); } @@ -1195,6 +1229,7 @@ public class TWindow extends TWidget { * Close window. Note that windows without a close box can still be * closed by calling the close() method. */ + @Override public void close() { application.closeWindow(this); } @@ -1381,7 +1416,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; }