*
* The MIT License (MIT)
*
- * Copyright (C) 2016 Kevin Lamonte
+ * Copyright (C) 2017 Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
return desktopBottom;
}
+ /**
+ * An optional TDesktop background window that is drawn underneath
+ * everything else.
+ */
+ private TDesktop desktop;
+
+ /**
+ * Set the TDesktop instance.
+ *
+ * @param desktop a TDesktop instance, or null to remove the one that is
+ * set
+ */
+ public final void setDesktop(final TDesktop desktop) {
+ if (this.desktop != null) {
+ this.desktop.onClose();
+ }
+ this.desktop = desktop;
+ }
+
+ /**
+ * Get the TDesktop instance.
+ *
+ * @return the desktop, or null if it is not set
+ */
+ public final TDesktop getDesktop() {
+ return desktop;
+ }
+
// ------------------------------------------------------------------------
// General behavior -------------------------------------------------------
// ------------------------------------------------------------------------
timers = new LinkedList<TTimer>();
accelerators = new HashMap<TKeypress, TMenuItem>();
menuItems = new ArrayList<TMenuItem>();
+ desktop = new TDesktop(this);
// Setup the main consumer thread
primaryEventHandler = new WidgetEventHandler(this, true);
// Start with a clean screen
getScreen().clear();
- // Draw the background
- CellAttributes background = theme.getColor("tapplication.background");
- getScreen().putAll(GraphicsChars.HATCH, background);
+ // Draw the desktop
+ if (desktop != null) {
+ desktop.drawChildren();
+ }
// Draw each window in reverse Z order
List<TWindow> sorted = new LinkedList<TWindow>(windows);
Collections.sort(sorted);
- TWindow topLevel = sorted.get(0);
+ TWindow topLevel = null;
+ if (sorted.size() > 0) {
+ topLevel = sorted.get(0);
+ }
Collections.reverse(sorted);
for (TWindow window: sorted) {
window.drawChildren();
}
// Draw the status bar of the top-level window
- TStatusBar statusBar = topLevel.getStatusBar();
+ TStatusBar statusBar = null;
+ if (topLevel != null) {
+ statusBar = topLevel.getStatusBar();
+ }
if (statusBar != null) {
getScreen().resetClipping();
statusBar.setWidth(getScreen().getWidth());
oldMouseX = 0;
oldMouseY = 0;
}
+ if (desktop != null) {
+ desktop.setDimensions(0, 0, resize.getWidth(),
+ resize.getHeight() - 1);
+ }
return;
}
}
// Dispatch events to the active window -------------------------------
+ boolean dispatchToDesktop = true;
for (TWindow window: windows) {
if (window.isActive()) {
if (event instanceof TMouseEvent) {
assert (mouse.getY() == mouse.getAbsoluteY());
mouse.setX(mouse.getX() - window.getX());
mouse.setY(mouse.getY() - window.getY());
+
+ if (window.mouseWouldHit(mouse)) {
+ dispatchToDesktop = false;
+ }
+ } else if (event instanceof TKeypressEvent) {
+ dispatchToDesktop = false;
}
+
if (debugEvents) {
System.err.printf("TApplication dispatch event: %s\n",
event);
break;
}
}
+ if (dispatchToDesktop) {
+ // This event is fair game for the desktop to process.
+ if (desktop != null) {
+ desktop.handleEvent(event);
+ }
+ }
}
+
/**
* Dispatch one event to the appropriate widget or application-level
* event handler. This is the secondary event handler used by certain
return;
}
+ // Do not add the desktop to the window list.
+ if (window instanceof TDesktop) {
+ return;
+ }
+
synchronized (windows) {
// Do not allow a modal window to spawn a non-modal window. If a
// modal window is active, then this window will become modal