X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWidget.java;h=034c1e9b26f0ae8fdb1a06550456db2d46bee606;hb=469c2b3cf74f88072a9a1e5758379f24b14f469e;hp=bca2be02f21f03cc305985a56fbf82c5314ae75c;hpb=c7a75ad30c309a84077cc29baace48a001af0fec;p=fanfix.git diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index bca2be0..034c1e9 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -611,67 +611,6 @@ public abstract class TWidget implements Comparable { * @param menu menu event */ public void onMenu(final TMenuEvent menu) { - - // Special case: if a split command comes in, insert a TPanel and - // TSplitPane in the hierarchy here. - TPanel panel = null; - TSplitPane pane = null; - List widgets = null; - switch (menu.getId()) { - case TMenu.MID_SPLIT_VERTICAL: - if (children.size() == 0) { - break; - } - panel = new TPanel(null, x, y, width, height); - pane = new TSplitPane(null, x, y, width, height, true); - widgets = new ArrayList(children); - for (TWidget w: widgets) { - w.setParent(panel, false); - } - children.clear(); - pane.setParent(this, false); - pane.setLeft(panel); - activate(pane); - for (TWidget w: widgets) { - assert (w.window != null); - assert (w.parent != null); - } - assert (pane.getWindow() != null); - assert (pane.getParent() != null); - assert (panel.getWindow() != null); - assert (panel.getParent() != null); - assert (pane.isActive() == true); - assert (panel.isActive() == true); - return; - case TMenu.MID_SPLIT_HORIZONTAL: - if (children.size() == 0) { - break; - } - panel = new TPanel(null, x, y, width, height); - pane = new TSplitPane(null, x, y, width, height, false); - widgets = new ArrayList(children); - for (TWidget w: widgets) { - w.setParent(panel, false); - } - children.clear(); - pane.setParent(this, false); - pane.setTop(panel); - activate(pane); - for (TWidget w: widgets) { - assert (w.window != null); - assert (w.parent != null); - } - assert (pane.getWindow() != null); - assert (pane.getParent() != null); - assert (panel.getWindow() != null); - assert (panel.getParent() != null); - assert (pane.isActive() == true); - assert (panel.isActive() == true); - return; - default: - break; - } - // Default: do nothing, pass to children instead for (TWidget widget: children) { widget.onMenu(menu); @@ -1115,6 +1054,11 @@ public abstract class TWidget implements Comparable { assert (window != null); + if (window instanceof TDesktop) { + // Desktop doesn't have a window border. + return cursorVisible; + } + // If cursor is out of my window's bounds, it is not visible. if ((getCursorAbsoluteX() >= window.getAbsoluteX() + window.getWidth() - 1) @@ -1311,6 +1255,10 @@ public abstract class TWidget implements Comparable { * Called by parent to render to TWindow. Note package private access. */ final void drawChildren() { + if (window == null) { + return; + } + // Set my clipping rectangle assert (window != null); assert (getScreen() != null); @@ -1327,10 +1275,16 @@ public abstract class TWidget implements Comparable { int absoluteRightEdge = window.getAbsoluteX() + window.getWidth(); int absoluteBottomEdge = window.getAbsoluteY() + window.getHeight(); - if (!(this instanceof TWindow) && !(this instanceof TVScroller)) { + if (!(this instanceof TWindow) + && !(this instanceof TVScroller) + && !(parent instanceof TDesktop) + ) { absoluteRightEdge -= 1; } - if (!(this instanceof TWindow) && !(this instanceof THScroller)) { + if (!(this instanceof TWindow) + && !(this instanceof THScroller) + && !(parent instanceof TDesktop) + ) { absoluteBottomEdge -= 1; } int myRightEdge = getAbsoluteX() + width; @@ -1593,6 +1547,98 @@ public abstract class TWidget implements Comparable { return this; } + /** + * Split this widget into two, putting all of this widget's children into + * a new TPanel, and returning a new TSplitPane with that panel on the + * left or right pane. + * + * @param newWidgetOnLeft if true, the new widget (if specified) will be + * on the left pane, and this widget's children will be placed on the + * right pane + * @param newWidget the new widget to add to the other pane, or null + * @return the new split pane widget + */ + public TSplitPane splitVertical(final boolean newWidgetOnLeft, + final TWidget newWidget) { + + TPanel panel = new TPanel(null, x, y, width, height); + TSplitPane splitPane = new TSplitPane(null, x, y, width, height, true); + List widgets = new ArrayList(children); + for (TWidget w: widgets) { + w.setParent(panel, false); + } + children.clear(); + splitPane.setParent(parent, false); + parent = null; + window = null; + if (newWidgetOnLeft) { + splitPane.setLeft(newWidget); + splitPane.setRight(panel); + } else { + splitPane.setRight(newWidget); + splitPane.setLeft(panel); + } + activate(splitPane); + for (TWidget w: widgets) { + assert (w.window != null); + assert (w.parent != null); + } + assert (splitPane.getWindow() != null); + assert (splitPane.getParent() != null); + assert (panel.getWindow() != null); + assert (panel.getParent() != null); + assert (splitPane.isActive() == true); + assert (panel.isActive() == true); + return splitPane; + } + + /** + * Split this widget into two, putting all of this widget's children into + * a new TPanel, and returning a new TSplitPane with that panel on the + * top or bottom pane. + * + * @param newWidgetOnTop if true, the new widget (if specified) will be + * on the top pane, and this widget's children will be placed on the + * bottom pane + * @param newWidget the new widget to add to the other pane, or null + * @return the new split pane widget + */ + public TSplitPane splitHorizontal(final boolean newWidgetOnTop, + final TWidget newWidget) { + + TPanel panel = new TPanel(null, x, y, width, height); + TSplitPane splitPane = new TSplitPane(null, x, y, width, height, false); + List widgets = new ArrayList(children); + for (TWidget w: widgets) { + w.setParent(panel, false); + } + children.clear(); + splitPane.setParent(parent, false); + parent = null; + splitPane.setTop(panel); + parent = null; + window = null; + if (newWidgetOnTop) { + splitPane.setTop(newWidget); + splitPane.setBottom(panel); + } else { + splitPane.setBottom(newWidget); + splitPane.setTop(panel); + } + activate(splitPane); + for (TWidget w: widgets) { + assert (w.window != null); + assert (w.parent != null); + } + assert (splitPane.getWindow() != null); + assert (splitPane.getParent() != null); + assert (panel.getWindow() != null); + assert (panel.getParent() != null); + assert (splitPane.isActive() == true); + assert (panel.isActive() == true); + return splitPane; + } + // ------------------------------------------------------------------------ // Passthru for Screen functions ------------------------------------------ // ------------------------------------------------------------------------