*
* 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"),
import java.util.Set;
import jexer.backend.Screen;
-import jexer.bits.Cell;
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
import jexer.event.TCommandEvent;
*/
public static final int HIDEONCLOSE = 0x40;
+ /**
+ * Menus cannot be used when this window is active (default no).
+ */
+ public static final int OVERRIDEMENU = 0x80;
+
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
// ------------------------------------------------------------------------
*/
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 -----------------------------------------------------------
// ------------------------------------------------------------------------
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
}
* 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
}
this.mouse = mouse;
inKeyboardResize = false;
+ inWindowMove = false;
+ inWindowResize = false;
if ((mouse.getAbsoluteY() == getY())
&& mouse.isMouse1()
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;
* 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);
}
return false;
}
+ /**
+ * Returns true if this window does not want menus to work while it is
+ * visible.
+ *
+ * @return true if this window does not want menus to work while it is
+ * visible
+ */
+ public final boolean hasOverriddenMenu() {
+ if ((flags & OVERRIDEMENU) != 0) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Retrieve the background color.
*
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());
}
}
- // ------------------------------------------------------------------------
- // 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.
+ * 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 attr attributes to use (bold, foreColor, backColor)
- * @param clip if true, honor clipping/offset
+ * @return true if this window does not want the application-wide mouse
+ * cursor drawn over it
*/
- public final void putAttrXY(final int x, final int y,
- final CellAttributes attr, final boolean clip) {
-
- getScreen().putAttrXY(x, y, attr, clip);
+ public final boolean hasHiddenMouse() {
+ return hideMouse;
}
/**
- * Fill the entire screen with one character with attributes.
+ * Set request to prevent the application-wide mouse cursor from being
+ * drawn over this window.
*
- * @param ch character to draw
- * @param attr attributes to use (bold, foreColor, backColor)
+ * @param hideMouse if true, this window does not want the
+ * application-wide mouse cursor drawn over it
*/
- 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.
- *
- * @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)
- */
- public final void putCharXY(final int x, final int y, final char ch,
- final CellAttributes attr) {
-
- getScreen().putCharXY(x, y, ch, attr);
- }
-
- /**
- * Render one character without changing the underlying attributes.
- *
- * @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
- */
- 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;
}
}