TField cut/paste working
[nikiroo-utils.git] / src / jexer / TApplication.java
index 7c96258b4405c00a5660788262a235a3c69c74d9..13cd07958ee3a61c9b36e2a76cf0f2560e48920a 100644 (file)
@@ -47,7 +47,9 @@ import java.util.ResourceBundle;
 
 import jexer.bits.Cell;
 import jexer.bits.CellAttributes;
+import jexer.bits.Clipboard;
 import jexer.bits.ColorTheme;
+import jexer.bits.StringUtils;
 import jexer.event.TCommandEvent;
 import jexer.event.TInputEvent;
 import jexer.event.TKeypressEvent;
@@ -147,6 +149,11 @@ public class TApplication implements Runnable {
      */
     private Backend backend;
 
+    /**
+     * The clipboard for copy and paste.
+     */
+    private Clipboard clipboard = new Clipboard();
+
     /**
      * Actual mouse coordinate X.
      */
@@ -269,7 +276,7 @@ public class TApplication implements Runnable {
      * constant.  Someday it would be nice to have a multi-line menu or
      * toolbars.
      */
-    private static final int desktopTop = 1;
+    private int desktopTop = 1;
 
     /**
      * Y coordinate of the bottom edge of the desktop.
@@ -288,11 +295,72 @@ public class TApplication implements Runnable {
      */
     private boolean focusFollowsMouse = false;
 
+    /**
+     * If true, display a text-based mouse cursor.
+     */
+    private boolean textMouse = true;
+
+    /**
+     * If true, hide the mouse after typing a keystroke.
+     */
+    private boolean hideMouseWhenTyping = false;
+
+    /**
+     * If true, the mouse should not be displayed because a keystroke was
+     * typed.
+     */
+    private boolean typingHidMouse = false;
+
+    /**
+     * If true, hide the status bar.
+     */
+    private boolean hideStatusBar = false;
+
+    /**
+     * If true, hide the menu bar.
+     */
+    private boolean hideMenuBar = false;
+
     /**
      * The list of commands to run before the next I/O check.
      */
     private List<Runnable> invokeLaters = new LinkedList<Runnable>();
 
+    /**
+     * The last time the screen was resized.
+     */
+    private long screenResizeTime = 0;
+
+    /**
+     * If true, screen selection is a rectangle.
+     */
+    private boolean screenSelectionRectangle = false;
+
+    /**
+     * If true, the mouse is dragging a screen selection.
+     */
+    private boolean inScreenSelection = false;
+
+    /**
+     * Screen selection starting X.
+     */
+    private int screenSelectionX0;
+
+    /**
+     * Screen selection starting Y.
+     */
+    private int screenSelectionY0;
+
+    /**
+     * Screen selection ending X.
+     */
+    private int screenSelectionX1;
+
+    /**
+     * Screen selection ending Y.
+     */
+    private int screenSelectionY1;
+
     /**
      * WidgetEventHandler is the main event consumer loop.  There are at most
      * two such threads in existence: the primary for normal case and a
@@ -518,9 +586,7 @@ public class TApplication implements Runnable {
                     }
                 } // while (!application.quit)
 
-                assert (dirty == true);
-
-                // Flush the screen contents
+                 // Flush the screen contents
                 if (debugThreads) {
                     System.err.printf("%d %s backend.flushScreen()\n",
                         System.currentTimeMillis(), Thread.currentThread());
@@ -685,8 +751,32 @@ public class TApplication implements Runnable {
      * Finish construction once the backend is set.
      */
     private void TApplicationImpl() {
+        // Text block mouse option
+        if (System.getProperty("jexer.textMouse", "true").equals("false")) {
+            textMouse = false;
+        }
+
+        // Hide mouse when typing option
+        if (System.getProperty("jexer.hideMouseWhenTyping",
+                "false").equals("true")) {
+
+            hideMouseWhenTyping = true;
+        }
+
+        // Hide status bar option
+        if (System.getProperty("jexer.hideStatusBar",
+                "false").equals("true")) {
+            hideStatusBar = true;
+        }
+
+        // Hide menu bar option
+        if (System.getProperty("jexer.hideMenuBar", "false").equals("true")) {
+            hideMenuBar = true;
+        }
+
         theme           = new ColorTheme();
-        desktopBottom   = getScreen().getHeight() - 1;
+        desktopTop      = (hideMenuBar ? 0 : 1);
+        desktopBottom   = getScreen().getHeight() - 1 + (hideStatusBar ? 1 : 0);
         fillEventQueue  = new LinkedList<TInputEvent>();
         drainEventQueue = new LinkedList<TInputEvent>();
         windows         = new LinkedList<TWindow>();
@@ -718,6 +808,7 @@ public class TApplication implements Runnable {
                 );
             }
         }
+
     }
 
     // ------------------------------------------------------------------------
@@ -814,6 +905,11 @@ public class TApplication implements Runnable {
         // resources.
         closeAllWindows();
 
+        // Close the desktop.
+        if (desktop != null) {
+            setDesktop(null);
+        }
+
         // Give the overarching application an opportunity to release
         // resources.
         onExit();
@@ -862,7 +958,7 @@ public class TApplication implements Runnable {
             return true;
         }
 
-        if (command.equals(cmMenu)) {
+        if (command.equals(cmMenu) && (hideMenuBar == false)) {
             if (!modalWindowActive() && (activeMenu == null)) {
                 if (menus.size() > 0) {
                     menus.get(0).setActive(true);
@@ -925,10 +1021,28 @@ public class TApplication implements Runnable {
             openImage();
             return true;
         }
-        if (menu.getId() == TMenu.MID_CHANGE_FONT) {
+        if (menu.getId() == TMenu.MID_SCREEN_OPTIONS) {
             new TFontChooserWindow(this);
             return true;
         }
+
+        if (menu.getId() == TMenu.MID_CUT) {
+            postMenuEvent(new TCommandEvent(cmCut));
+            return true;
+        }
+        if (menu.getId() == TMenu.MID_COPY) {
+            postMenuEvent(new TCommandEvent(cmCopy));
+            return true;
+        }
+        if (menu.getId() == TMenu.MID_PASTE) {
+            postMenuEvent(new TCommandEvent(cmPaste));
+            return true;
+        }
+        if (menu.getId() == TMenu.MID_CLEAR) {
+            postMenuEvent(new TCommandEvent(cmClear));
+            return true;
+        }
+
         return false;
     }
 
@@ -947,6 +1061,7 @@ public class TApplication implements Runnable {
             && !keypress.getKey().isCtrl()
             && (activeMenu == null)
             && !modalWindowActive()
+            && (hideMenuBar == false)
         ) {
 
             assert (subMenus.size() == 0);
@@ -974,6 +1089,47 @@ public class TApplication implements Runnable {
                 Thread.currentThread() + " finishEventProcessing()\n");
         }
 
+        // See if we need to enable/disable the edit menu.
+        EditMenuUser widget = null;
+        if (activeMenu == null) {
+            if (activeWindow != null) {
+                if (activeWindow.getActiveChild() instanceof EditMenuUser) {
+                    widget = (EditMenuUser) activeWindow.getActiveChild();
+                }
+            } else if (desktop != null) {
+                if (desktop.getActiveChild() instanceof EditMenuUser) {
+                    widget = (EditMenuUser) desktop.getActiveChild();
+                }
+            }
+            if (widget == null) {
+                disableMenuItem(TMenu.MID_CUT);
+                disableMenuItem(TMenu.MID_COPY);
+                disableMenuItem(TMenu.MID_PASTE);
+                disableMenuItem(TMenu.MID_CLEAR);
+            } else {
+                if (widget.isEditMenuCut()) {
+                    enableMenuItem(TMenu.MID_CUT);
+                } else {
+                    disableMenuItem(TMenu.MID_CUT);
+                }
+                if (widget.isEditMenuCopy()) {
+                    enableMenuItem(TMenu.MID_COPY);
+                } else {
+                    disableMenuItem(TMenu.MID_COPY);
+                }
+                if (widget.isEditMenuPaste()) {
+                    enableMenuItem(TMenu.MID_PASTE);
+                } else {
+                    disableMenuItem(TMenu.MID_PASTE);
+                }
+                if (widget.isEditMenuClear()) {
+                    enableMenuItem(TMenu.MID_CLEAR);
+                } else {
+                    disableMenuItem(TMenu.MID_CLEAR);
+                }
+            }
+        }
+
         // Process timers and call doIdle()'s
         doIdle();
 
@@ -1026,17 +1182,26 @@ public class TApplication implements Runnable {
             if (event instanceof TResizeEvent) {
                 TResizeEvent resize = (TResizeEvent) event;
                 synchronized (getScreen()) {
-                    getScreen().setDimensions(resize.getWidth(),
-                        resize.getHeight());
+                    if ((System.currentTimeMillis() - screenResizeTime >= 15)
+                        || (resize.getWidth() < getScreen().getWidth())
+                        || (resize.getHeight() < getScreen().getHeight())
+                    ) {
+                        getScreen().setDimensions(resize.getWidth(),
+                            resize.getHeight());
+                        screenResizeTime = System.currentTimeMillis();
+                    }
                     desktopBottom = getScreen().getHeight() - 1;
+                    if (hideStatusBar) {
+                        desktopBottom++;
+                    }
                     mouseX = 0;
                     mouseY = 0;
                     oldMouseX = 0;
                     oldMouseY = 0;
                 }
                 if (desktop != null) {
-                    desktop.setDimensions(0, 0, resize.getWidth(),
-                        resize.getHeight() - 1);
+                    desktop.setDimensions(0, desktopTop, resize.getWidth(),
+                        (desktopBottom - desktopTop));
                     desktop.onResize(resize);
                 }
 
@@ -1076,9 +1241,39 @@ public class TApplication implements Runnable {
 
         // Special application-wide events -----------------------------------
 
+        if (event instanceof TKeypressEvent) {
+            if (hideMouseWhenTyping) {
+                typingHidMouse = true;
+            }
+        }
+
         // Peek at the mouse position
         if (event instanceof TMouseEvent) {
+            typingHidMouse = false;
+
             TMouseEvent mouse = (TMouseEvent) event;
+            if (mouse.isMouse1() && (mouse.isShift() || mouse.isCtrl())) {
+                // Screen selection.
+                if (inScreenSelection) {
+                    screenSelectionX1 = mouse.getX();
+                    screenSelectionY1 = mouse.getY();
+                } else {
+                    inScreenSelection = true;
+                    screenSelectionX0 = mouse.getX();
+                    screenSelectionY0 = mouse.getY();
+                    screenSelectionX1 = mouse.getX();
+                    screenSelectionY1 = mouse.getY();
+                    screenSelectionRectangle = mouse.isCtrl();
+                }
+            } else {
+                if (inScreenSelection) {
+                    getScreen().copySelection(clipboard, screenSelectionX0,
+                        screenSelectionY0, screenSelectionX1, screenSelectionY1,
+                        screenSelectionRectangle);
+                }
+                inScreenSelection = false;
+            }
+
             if ((mouseX != mouse.getX()) || (mouseY != mouse.getY())) {
                 oldMouseX = mouseX;
                 oldMouseY = mouseY;
@@ -1099,7 +1294,8 @@ public class TApplication implements Runnable {
                             mouse.getAbsoluteX(), mouse.getAbsoluteY(),
                             mouse.isMouse1(), mouse.isMouse2(),
                             mouse.isMouse3(),
-                            mouse.isMouseWheelUp(), mouse.isMouseWheelDown());
+                            mouse.isMouseWheelUp(), mouse.isMouseWheelDown(),
+                            mouse.isAlt(), mouse.isCtrl(), mouse.isShift());
 
                     } else {
                         // The first click of a potential double-click.
@@ -1223,6 +1419,8 @@ public class TApplication implements Runnable {
                 }
             } else if (event instanceof TKeypressEvent) {
                 dispatchToDesktop = false;
+            } else if (event instanceof TMenuEvent) {
+                dispatchToDesktop = false;
             }
 
             if (debugEvents) {
@@ -1263,6 +1461,8 @@ public class TApplication implements Runnable {
 
         // Peek at the mouse position
         if (event instanceof TMouseEvent) {
+            typingHidMouse = false;
+
             TMouseEvent mouse = (TMouseEvent) event;
             if ((mouseX != mouse.getX()) || (mouseY != mouse.getY())) {
                 oldMouseX = mouseX;
@@ -1284,7 +1484,8 @@ public class TApplication implements Runnable {
                             mouse.getAbsoluteX(), mouse.getAbsoluteY(),
                             mouse.isMouse1(), mouse.isMouse2(),
                             mouse.isMouse3(),
-                            mouse.isMouseWheelUp(), mouse.isMouseWheelDown());
+                            mouse.isMouseWheelUp(), mouse.isMouseWheelDown(),
+                            mouse.isAlt(), mouse.isCtrl(), mouse.isShift());
 
                     } else {
                         // The first click of a potential double-click.
@@ -1500,6 +1701,15 @@ public class TApplication implements Runnable {
         return theme;
     }
 
+    /**
+     * Get the clipboard.
+     *
+     * @return the clipboard
+     */
+    public final Clipboard getClipboard() {
+        return clipboard;
+    }
+
     /**
      * Repaint the screen on the next update.
      */
@@ -1534,6 +1744,8 @@ public class TApplication implements Runnable {
      */
     public final void setDesktop(final TDesktop desktop) {
         if (this.desktop != null) {
+            this.desktop.onPreClose();
+            this.desktop.onUnfocus();
             this.desktop.onClose();
         }
         this.desktop = desktop;
@@ -1595,7 +1807,7 @@ public class TApplication implements Runnable {
         String version = getClass().getPackage().getImplementationVersion();
         if (version == null) {
             // This is Java 9+, use a hardcoded string here.
-            version = "0.3.2";
+            version = "1.0.0";
         }
         messageBox(i18n.getString("aboutDialogTitle"),
             MessageFormat.format(i18n.getString("aboutDialogText"), version),
@@ -1640,27 +1852,15 @@ public class TApplication implements Runnable {
     // ------------------------------------------------------------------------
 
     /**
-     * Invert the cell color at a position.  This is used to track the mouse.
+     * Draw the text mouse at position.
      *
      * @param x column position
      * @param y row position
      */
-    private void invertCell(final int x, final int y) {
-        invertCell(x, y, false);
-    }
-
-    /**
-     * Invert the cell color at a position.  This is used to track the mouse.
-     *
-     * @param x column position
-     * @param y row position
-     * @param onlyThisCell if true, only invert this cell
-     */
-    private void invertCell(final int x, final int y,
-        final boolean onlyThisCell) {
+    private void drawTextMouse(final int x, final int y) {
 
         if (debugThreads) {
-            System.err.printf("%d %s invertCell() %d %d\n",
+            System.err.printf("%d %s drawTextMouse() %d %d\n",
                 System.currentTimeMillis(), Thread.currentThread(), x, y);
 
             if (activeWindow != null) {
@@ -1682,45 +1882,20 @@ public class TApplication implements Runnable {
             }
         }
 
-        Cell cell = getScreen().getCharXY(x, y);
-        if (cell.isImage()) {
-            cell.invertImage();
-        } else {
-            if (cell.getForeColorRGB() < 0) {
-                cell.setForeColor(cell.getForeColor().invert());
-            } else {
-                cell.setForeColorRGB(cell.getForeColorRGB() ^ 0x00ffffff);
-            }
-            if (cell.getBackColorRGB() < 0) {
-                cell.setBackColor(cell.getBackColor().invert());
-            } else {
-                cell.setBackColorRGB(cell.getBackColorRGB() ^ 0x00ffffff);
-            }
-        }
-        getScreen().putCharXY(x, y, cell);
-        if ((onlyThisCell == true) || (cell.getWidth() == Cell.Width.SINGLE)) {
-            return;
-        }
-
-        // This cell is one half of a fullwidth glyph.  Invert the other
-        // half.
-        if (cell.getWidth() == Cell.Width.LEFT) {
-            if (x < getScreen().getWidth() - 1) {
-                Cell rightHalf = getScreen().getCharXY(x + 1, y);
-                if (rightHalf.getWidth() == Cell.Width.RIGHT) {
-                    invertCell(x + 1, y, true);
-                    return;
-                }
+        // If this cell is on top of the desktop, and the desktop has
+        // requested a hidden mouse, bail out.
+        if ((desktop != null) && (activeWindow == null) && (activeMenu == null)) {
+            if ((desktop.hasHiddenMouse() == true)
+                && (x > desktop.getX())
+                && (x < desktop.getX() + desktop.getWidth() - 1)
+                && (y > desktop.getY())
+                && (y < desktop.getY() + desktop.getHeight() - 1)
+            ) {
+                return;
             }
         }
-        assert (cell.getWidth() == Cell.Width.RIGHT);
 
-        if (x > 0) {
-            Cell leftHalf = getScreen().getCharXY(x - 1, y);
-            if (leftHalf.getWidth() == Cell.Width.LEFT) {
-                invertCell(x - 1, y, true);
-            }
-        }
+        getScreen().invertCell(x, y);
     }
 
     /**
@@ -1780,8 +1955,16 @@ public class TApplication implements Runnable {
                     }
                 }
 
-                // Draw mouse at the new position.
-                invertCell(mouseX, mouseY);
+                if (inScreenSelection) {
+                    getScreen().setSelection(screenSelectionX0,
+                        screenSelectionY0, screenSelectionX1, screenSelectionY1,
+                        screenSelectionRectangle);
+                }
+
+                if ((textMouse == true) && (typingHidMouse == false)) {
+                    // Draw mouse at the new position.
+                    drawTextMouse(mouseX, mouseY);
+                }
 
                 oldDrawnMouseX = mouseX;
                 oldDrawnMouseY = mouseY;
@@ -1822,63 +2005,71 @@ public class TApplication implements Runnable {
             }
         }
 
-        // Draw the blank menubar line - reset the screen clipping first so
-        // it won't trim it out.
-        getScreen().resetClipping();
-        getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
-            theme.getColor("tmenu"));
-        // Now draw the menus.
-        int x = 1;
-        for (TMenu menu: menus) {
-            CellAttributes menuColor;
-            CellAttributes menuMnemonicColor;
-            if (menu.isActive()) {
-                menuIsActive = true;
-                menuColor = theme.getColor("tmenu.highlighted");
-                menuMnemonicColor = theme.getColor("tmenu.mnemonic.highlighted");
-                topLevel = menu;
-            } else {
-                menuColor = theme.getColor("tmenu");
-                menuMnemonicColor = theme.getColor("tmenu.mnemonic");
-            }
-            // Draw the menu title
-            getScreen().hLineXY(x, 0, menu.getTitle().length() + 2, ' ',
-                menuColor);
-            getScreen().putStringXY(x + 1, 0, menu.getTitle(), menuColor);
-            // Draw the highlight character
-            getScreen().putCharXY(x + 1 + menu.getMnemonic().getShortcutIdx(),
-                0, menu.getMnemonic().getShortcut(), menuMnemonicColor);
-
-            if (menu.isActive()) {
-                ((TWindow) menu).drawChildren();
-                // Reset the screen clipping so we can draw the next title.
-                getScreen().resetClipping();
-            }
-            x += menu.getTitle().length() + 2;
-        }
+        if (hideMenuBar == false) {
 
-        for (TMenu menu: subMenus) {
-            // Reset the screen clipping so we can draw the next sub-menu.
+            // Draw the blank menubar line - reset the screen clipping first
+            // so it won't trim it out.
             getScreen().resetClipping();
-            ((TWindow) menu).drawChildren();
+            getScreen().hLineXY(0, 0, getScreen().getWidth(), ' ',
+                theme.getColor("tmenu"));
+            // Now draw the menus.
+            int x = 1;
+            for (TMenu menu: menus) {
+                CellAttributes menuColor;
+                CellAttributes menuMnemonicColor;
+                if (menu.isActive()) {
+                    menuIsActive = true;
+                    menuColor = theme.getColor("tmenu.highlighted");
+                    menuMnemonicColor = theme.getColor("tmenu.mnemonic.highlighted");
+                    topLevel = menu;
+                } else {
+                    menuColor = theme.getColor("tmenu");
+                    menuMnemonicColor = theme.getColor("tmenu.mnemonic");
+                }
+                // Draw the menu title
+                getScreen().hLineXY(x, 0,
+                    StringUtils.width(menu.getTitle()) + 2, ' ', menuColor);
+                getScreen().putStringXY(x + 1, 0, menu.getTitle(), menuColor);
+                // Draw the highlight character
+                getScreen().putCharXY(x + 1 +
+                    menu.getMnemonic().getScreenShortcutIdx(),
+                    0, menu.getMnemonic().getShortcut(), menuMnemonicColor);
+
+                if (menu.isActive()) {
+                    ((TWindow) menu).drawChildren();
+                    // Reset the screen clipping so we can draw the next
+                    // title.
+                    getScreen().resetClipping();
+                }
+                x += StringUtils.width(menu.getTitle()) + 2;
+            }
+
+            for (TMenu menu: subMenus) {
+                // Reset the screen clipping so we can draw the next
+                // sub-menu.
+                getScreen().resetClipping();
+                ((TWindow) menu).drawChildren();
+            }
         }
         getScreen().resetClipping();
 
-        // Draw the status bar of the top-level window
-        TStatusBar statusBar = null;
-        if (topLevel != null) {
-            statusBar = topLevel.getStatusBar();
-        }
-        if (statusBar != null) {
-            getScreen().resetClipping();
-            statusBar.setWidth(getScreen().getWidth());
-            statusBar.setY(getScreen().getHeight() - topLevel.getY());
-            statusBar.draw();
-        } else {
-            CellAttributes barColor = new CellAttributes();
-            barColor.setTo(getTheme().getColor("tstatusbar.text"));
-            getScreen().hLineXY(0, desktopBottom, getScreen().getWidth(), ' ',
-                barColor);
+        if (hideStatusBar == false) {
+            // Draw the status bar of the top-level window
+            TStatusBar statusBar = null;
+            if (topLevel != null) {
+                statusBar = topLevel.getStatusBar();
+            }
+            if (statusBar != null) {
+                getScreen().resetClipping();
+                statusBar.setWidth(getScreen().getWidth());
+                statusBar.setY(getScreen().getHeight() - topLevel.getY());
+                statusBar.draw();
+            } else {
+                CellAttributes barColor = new CellAttributes();
+                barColor.setTo(getTheme().getColor("tstatusbar.text"));
+                getScreen().hLineXY(0, desktopBottom, getScreen().getWidth(),
+                    ' ', barColor);
+            }
         }
 
         // Draw the mouse pointer
@@ -1907,18 +2098,43 @@ public class TApplication implements Runnable {
                 getScreen().unsetImageRow(mouseY);
             }
         }
-        invertCell(mouseX, mouseY);
+
+        if (inScreenSelection) {
+            getScreen().setSelection(screenSelectionX0, screenSelectionY0,
+                screenSelectionX1, screenSelectionY1, screenSelectionRectangle);
+        }
+
+        if ((textMouse == true) && (typingHidMouse == false)) {
+            drawTextMouse(mouseX, mouseY);
+        }
         oldDrawnMouseX = mouseX;
         oldDrawnMouseY = mouseY;
 
         // Place the cursor if it is visible
         if (!menuIsActive) {
+
+            int visibleWindowCount = 0;
+            for (TWindow window: sorted) {
+                if (window.isShown()) {
+                    visibleWindowCount++;
+                }
+            }
+            if (visibleWindowCount == 0) {
+                // No windows are visible, only the desktop.  Allow it to
+                // have the cursor.
+                if (desktop != null) {
+                    sorted.add(desktop);
+                }
+            }
+
             TWidget activeWidget = null;
             if (sorted.size() > 0) {
                 activeWidget = sorted.get(sorted.size() - 1).getActiveChild();
+                int cursorClipTop = desktopTop;
+                int cursorClipBottom = desktopBottom;
                 if (activeWidget.isCursorVisible()) {
-                    if ((activeWidget.getCursorAbsoluteY() < desktopBottom)
-                        && (activeWidget.getCursorAbsoluteY() > desktopTop)
+                    if ((activeWidget.getCursorAbsoluteY() <= cursorClipBottom)
+                        && (activeWidget.getCursorAbsoluteY() >= cursorClipTop)
                     ) {
                         getScreen().putCursor(true,
                             activeWidget.getCursorAbsoluteX(),
@@ -2077,9 +2293,6 @@ public class TApplication implements Runnable {
 
         assert (!window.isActive());
         if (activeWindow != null) {
-            // TODO: see if this assertion is really necessary.
-            // assert (activeWindow.getZ() == 0);
-
             activeWindow.setActive(false);
 
             // Increment every window Z that is on top of window
@@ -2380,6 +2593,7 @@ public class TApplication implements Runnable {
             if (((window.flags & TWindow.CENTERED) == 0)
                 && ((window.flags & TWindow.ABSOLUTEXY) == 0)
                 && (smartWindowPlacement == true)
+                && (!(window instanceof TDesktop))
             ) {
 
                 doSmartPlacement(window);
@@ -2718,6 +2932,7 @@ public class TApplication implements Runnable {
             && (!modalWindowActive())
             && (!overrideMenuWindowActive())
             && (mouse.getAbsoluteY() == 0)
+            && (hideMenuBar == false)
         ) {
 
             for (TMenu menu: subMenus) {
@@ -2729,7 +2944,7 @@ public class TApplication implements Runnable {
             for (TMenu menu: menus) {
                 if ((mouse.getAbsoluteX() >= menu.getTitleX())
                     && (mouse.getAbsoluteX() < menu.getTitleX()
-                        + menu.getTitle().length() + 2)
+                        + StringUtils.width(menu.getTitle()) + 2)
                 ) {
                     menu.setActive(true);
                     activeMenu = menu;
@@ -2745,6 +2960,7 @@ public class TApplication implements Runnable {
             && (mouse.isMouse1())
             && (activeMenu != null)
             && (mouse.getAbsoluteY() == 0)
+            && (hideMenuBar == false)
         ) {
 
             TMenu oldMenu = activeMenu;
@@ -2757,7 +2973,7 @@ public class TApplication implements Runnable {
             for (TMenu menu: menus) {
                 if ((mouse.getAbsoluteX() >= menu.getTitleX())
                     && (mouse.getAbsoluteX() < menu.getTitleX()
-                        + menu.getTitle().length() + 2)
+                        + StringUtils.width(menu.getTitle()) + 2)
                 ) {
                     menu.setActive(true);
                     activeMenu = menu;
@@ -2913,6 +3129,7 @@ public class TApplication implements Runnable {
      */
     public final void switchMenu(final boolean forward) {
         assert (activeMenu != null);
+        assert (hideMenuBar == false);
 
         for (TMenu menu: subMenus) {
             menu.setActive(false);
@@ -3042,7 +3259,7 @@ public class TApplication implements Runnable {
         for (TMenu menu: menus) {
             menu.setX(x);
             menu.setTitleX(x);
-            x += menu.getTitle().length() + 2;
+            x += StringUtils.width(menu.getTitle()) + 2;
 
             // Don't let the menu window exceed the screen width
             int rightEdge = menu.getX() + menu.getWidth();
@@ -3122,7 +3339,7 @@ public class TApplication implements Runnable {
         TMenu toolMenu = addMenu(i18n.getString("toolMenuTitle"));
         toolMenu.addDefaultItem(TMenu.MID_REPAINT);
         toolMenu.addDefaultItem(TMenu.MID_VIEW_IMAGE);
-        toolMenu.addDefaultItem(TMenu.MID_CHANGE_FONT);
+        toolMenu.addDefaultItem(TMenu.MID_SCREEN_OPTIONS);
         TStatusBar toolStatusBar = toolMenu.newStatusBar(i18n.
             getString("toolMenuStatus"));
         toolStatusBar.addShortcutKeypress(kbF1, cmHelp, i18n.getString("Help"));
@@ -3152,10 +3369,10 @@ public class TApplication implements Runnable {
      */
     public final TMenu addEditMenu() {
         TMenu editMenu = addMenu(i18n.getString("editMenuTitle"));
-        editMenu.addDefaultItem(TMenu.MID_CUT);
-        editMenu.addDefaultItem(TMenu.MID_COPY);
-        editMenu.addDefaultItem(TMenu.MID_PASTE);
-        editMenu.addDefaultItem(TMenu.MID_CLEAR);
+        editMenu.addDefaultItem(TMenu.MID_CUT, false);
+        editMenu.addDefaultItem(TMenu.MID_COPY, false);
+        editMenu.addDefaultItem(TMenu.MID_PASTE, false);
+        editMenu.addDefaultItem(TMenu.MID_CLEAR, false);
         TStatusBar statusBar = editMenu.newStatusBar(i18n.
             getString("editMenuStatus"));
         statusBar.addShortcutKeypress(kbF1, cmHelp, i18n.getString("Help"));