X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWindow.java;h=e50e16fd1c5a9eec4f6b45c4e836a5d31b6bbdec;hb=c1d8e2b874088d4336bd3ba0a04623176d2039a0;hp=140a38aa263f1c2138aed7ff558ada47df9507e1;hpb=d6ee0801333ff93dffd851f4c1a44519c96c371d;p=fanfix.git diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index 140a38a..e50e16f 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -185,6 +185,15 @@ public class TWindow extends TWidget { */ protected TStatusBar statusBar = null; + /** + * A window may request that TApplication NOT draw the mouse cursor over + * it by setting this to true. This is currently only used within Jexer + * by TTerminalWindow so that only the bottom-most instance of nested + * Jexer's draws the mouse within its application window. But perhaps + * other applications can use it, so public getter/setter is provided. + */ + private boolean hideMouse = false; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -337,19 +346,32 @@ public class TWindow extends TWidget { return false; } + /** + * Subclasses should override this method to perform any user prompting + * before they are offscreen. Note that unlike other windowing toolkits, + * windows can NOT use this function in some manner to avoid being + * closed. This is called by application.closeWindow(). + */ + protected void onPreClose() { + // Default: do nothing. + } + /** * Subclasses should override this method to cleanup resources. This is * called by application.closeWindow(). */ - public void onClose() { - // Default: do nothing + protected void onClose() { + // Default: perform widget-specific cleanup. + for (TWidget w: getChildren()) { + w.close(); + } } /** * Called by application.switchWindow() when this window gets the * focus, and also by application.addWindow(). */ - public void onFocus() { + protected void onFocus() { // Default: do nothing } @@ -357,21 +379,21 @@ public class TWindow extends TWidget { * Called by application.switchWindow() when another window gets the * focus. */ - public void onUnfocus() { + protected void onUnfocus() { // Default: do nothing } /** * Called by application.hideWindow(). */ - public void onHide() { + protected void onHide() { // Default: do nothing } /** * Called by application.showWindow(). */ - public void onShow() { + protected void onShow() { // Default: do nothing } @@ -385,6 +407,8 @@ public class TWindow extends TWidget { this.mouse = mouse; inKeyboardResize = false; + inWindowMove = false; + inWindowResize = false; if ((mouse.getAbsoluteY() == getY()) && mouse.isMouse1() @@ -854,8 +878,8 @@ public class TWindow extends TWidget { CellAttributes background = getBackground(); int borderType = getBorderType(); - getScreen().drawBox(0, 0, getWidth(), getHeight(), border, - background, borderType, true); + drawBox(0, 0, getWidth(), getHeight(), border, background, borderType, + true); // Draw the title int titleLeft = (getWidth() - title.length() - 2) / 2; @@ -1264,7 +1288,15 @@ public class TWindow extends TWidget { if (!isModal() && (inWindowMove || inWindowResize || inKeyboardResize) ) { - assert (isActive()); + if (!isActive()) { + // The user's terminal never passed a mouse up event, and now + // another window is active but we never finished a drag. + inWindowMove = false; + inWindowResize = false; + inKeyboardResize = false; + return getTheme().getColor("twindow.border.inactive"); + } + return getTheme().getColor("twindow.border.windowmove"); } else if (isModal() && inWindowMove) { assert (isActive()); @@ -1323,148 +1355,26 @@ public class TWindow extends TWidget { } } - // ------------------------------------------------------------------------ - // Passthru for Screen functions ------------------------------------------ - // ------------------------------------------------------------------------ - - /** - * Get the attributes at one location. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @return attributes at (x, y) - */ - public final CellAttributes getAttrXY(final int x, final int y) { - return getScreen().getAttrXY(x, y); - } - - /** - * Set the attributes at one location. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param attr attributes to use (bold, foreColor, backColor) - */ - public final void putAttrXY(final int x, final int y, - final CellAttributes attr) { - - getScreen().putAttrXY(x, y, attr); - } - - /** - * Set the attributes at one location. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param attr attributes to use (bold, foreColor, backColor) - * @param clip if true, honor clipping/offset - */ - public final void putAttrXY(final int x, final int y, - final CellAttributes attr, final boolean clip) { - - getScreen().putAttrXY(x, y, attr, clip); - } - - /** - * Fill the entire screen with one character with attributes. - * - * @param ch character to draw - * @param attr attributes to use (bold, foreColor, backColor) - */ - public final void putAll(final char ch, final CellAttributes attr) { - getScreen().putAll(ch, attr); - } - - /** - * Render one character with attributes. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param ch character + attributes to draw - */ - public final void putCharXY(final int x, final int y, final Cell ch) { - getScreen().putCharXY(x, y, ch); - } - /** - * Render one character with attributes. + * Returns true if this window does not want the application-wide mouse + * cursor drawn over it. * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param ch character to draw - * @param attr attributes to use (bold, foreColor, backColor) + * @return true if this window does not want the application-wide mouse + * cursor drawn over it */ - public final void putCharXY(final int x, final int y, final char ch, - final CellAttributes attr) { - - getScreen().putCharXY(x, y, ch, attr); + public final boolean hasHiddenMouse() { + return hideMouse; } /** - * Render one character without changing the underlying attributes. + * Set request to prevent the application-wide mouse cursor from being + * drawn over this window. * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param ch character to draw + * @param hideMouse if true, this window does not want the + * application-wide mouse cursor drawn over it */ - public final void putCharXY(final int x, final int y, final char ch) { - getScreen().putCharXY(x, y, ch); - } - - /** - * Render a string. Does not wrap if the string exceeds the line. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param str string to draw - * @param attr attributes to use (bold, foreColor, backColor) - */ - public final void putStringXY(final int x, final int y, final String str, - final CellAttributes attr) { - - getScreen().putStringXY(x, y, str, attr); - } - - /** - * Render a string without changing the underlying attribute. Does not - * wrap if the string exceeds the line. - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param str string to draw - */ - public final void putStringXY(final int x, final int y, final String str) { - getScreen().putStringXY(x, y, str); - } - - /** - * Draw a vertical line from (x, y) to (x, y + n). - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param n number of characters to draw - * @param ch character to draw - * @param attr attributes to use (bold, foreColor, backColor) - */ - public final void vLineXY(final int x, final int y, final int n, - final char ch, final CellAttributes attr) { - - getScreen().vLineXY(x, y, n, ch, attr); - } - - /** - * Draw a horizontal line from (x, y) to (x + n, y). - * - * @param x column coordinate. 0 is the left-most column. - * @param y row coordinate. 0 is the top-most row. - * @param n number of characters to draw - * @param ch character to draw - * @param attr attributes to use (bold, foreColor, backColor) - */ - public final void hLineXY(final int x, final int y, final int n, - final char ch, final CellAttributes attr) { - - getScreen().hLineXY(x, y, n, ch, attr); + public final void setHiddenMouse(final boolean hideMouse) { + this.hideMouse = hideMouse; } }