=== modified file 'src/com/goldencode/p2j/ui/client/FontManager.java' --- src/com/goldencode/p2j/ui/client/FontManager.java 2016-04-19 19:24:50 +0000 +++ src/com/goldencode/p2j/ui/client/FontManager.java 2016-05-02 12:49:45 +0000 @@ -40,6 +40,7 @@ ** 020 SBI 20160110 Changed to install/upload binary fonts only if they are not detected. ** 021 EVL 20160415 Fix for system font index calculation. Adding separate font for stack trace ** window. +** 022 SBI 20160502 Extended parameter type to create GuiFontResolver for top level windows. */ package com.goldencode.p2j.ui.client; @@ -279,7 +280,7 @@ * * @return See above. */ - public static FontDetails resolveFont(Window window, int font, ScreenDriver driver) + public static FontDetails resolveFont(TopLevelWindow window, int font, ScreenDriver driver) { if (driver.isChui()) { === modified file 'src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-04-13 19:52:18 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ComboBoxGuiImpl.java 2016-05-02 12:50:56 +0000 @@ -60,6 +60,8 @@ ** 021 HC 20160406 COMBO-BOX drop-down resources cleanup. Various drop-down related fixes. ** 022 HC 20160413 Fixed COMBO-BOX focus management, this also resolves ENTER not confirming ** selected item in the drop-down. +** 023 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes. */ package com.goldencode.p2j.ui.client.gui; @@ -1507,14 +1509,14 @@ { gd.setColor(gc.fgColor); } - gd.drawString(display, xt, yt); + gd.drawString(display, dim.width, dim.height, xt, yt, 0, 0); } else { gd.setColor(lightShadow); - gd.drawString(display, xt + 1, yt + 1); + gd.drawString(display, dim.width, dim.height, xt + 1, yt + 1, 1, 1); gd.setColor(darkShadow); - gd.drawString(display, xt, yt); + gd.drawString(display, dim.width, dim.height, xt, yt, 0, 0); } // draw dotted rectangle around focused item text === modified file 'src/com/goldencode/p2j/ui/client/gui/GuiFontResolver.java' --- src/com/goldencode/p2j/ui/client/gui/GuiFontResolver.java 2015-05-18 20:48:28 +0000 +++ src/com/goldencode/p2j/ui/client/gui/GuiFontResolver.java 2016-05-02 12:49:01 +0000 @@ -18,6 +18,7 @@ ** 005 CA 20150507 No need to re-scale the font, it gets scaled when it gets created - so all ** fonts are assumed to match the legacy metrics. ** 006 GES 20150425 Eliminated AWT dependencies. +** 007 SBI 20160502 Extended parameter type to create GuiFontResolver for top level windows. */ package com.goldencode.p2j.ui.client.gui; @@ -41,7 +42,7 @@ private Map fontCache = new HashMap<>(); /** Window instance. */ - private Window window; + private TopLevelWindow window; /** Screen driver. */ private GuiDriver gd; @@ -68,7 +69,7 @@ * @param config * Widget configuration. */ - public GuiFontResolver(Window window, GuiDriver gd, BaseConfig config) + public GuiFontResolver(TopLevelWindow window, GuiDriver gd, BaseConfig config) { this(window, gd, config, false); } @@ -86,7 +87,7 @@ * Flag identifying that the referenced font must default to the default fixed font, * if is not specified. */ - public GuiFontResolver(Window window, GuiDriver gd, BaseConfig config, boolean fixedFont) + public GuiFontResolver(TopLevelWindow window, GuiDriver gd, BaseConfig config, boolean fixedFont) { this.window = window; this.gd = gd; === modified file 'src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java' --- src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-04-13 19:52:18 +0000 +++ src/com/goldencode/p2j/ui/client/gui/ScrollableSelectionListGuiImpl.java 2016-05-02 13:02:14 +0000 @@ -46,6 +46,8 @@ ** 016 HC 20160406 COMBO-BOX drop-down resources cleanup. Various drop-down related fixes. ** 017 HC 20160413 Fixed COMBO-BOX focus management, this also resolves ENTER not confirming ** selected item in the drop-down. +** 018 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, fixed GuiFontResolver to have a correct top level window. */ package com.goldencode.p2j.ui.client.gui; @@ -59,7 +61,6 @@ import com.goldencode.p2j.ui.chui.ThinClient; import com.goldencode.p2j.ui.client.*; import com.goldencode.p2j.ui.client.event.*; -import com.goldencode.p2j.ui.client.event.listener.*; import com.goldencode.p2j.ui.client.gui.GuiFontResolver.FontCache; import com.goldencode.p2j.ui.client.gui.driver.*; import com.goldencode.p2j.ui.client.model.*; @@ -123,8 +124,6 @@ // initialize screen driver gd = (GuiDriver) OutputManager.getDriver(); - // and font resolver - gf = new GuiFontResolver(WindowManager.resolveWindow(this), gd, box.config(), false); // color initializing selectionBack = gd.getSysColor(SysColor.COLOR_HIGHLIGHT); selectionFore = gd.getSysColor(SysColor.COLOR_HIGHLIGHTTEXT); @@ -155,7 +154,13 @@ // get actual rows to view final int rowsVisible = visibleRows(); - + + if (gf == null) + { + // and font resolver + gf = new GuiFontResolver(topLevelWindow(), gd, box.config(), false); + } + // resolve font final FontCache fntCache = gf.font(); @@ -694,10 +699,10 @@ } // draw item text - gd.drawString(getItemText(number), + gd.drawString(getItemText(number), rw, rh, box != null && box.config().mode == ComboBoxConfig.Mode.SIMPLE ? x + ComboBoxGuiImpl.ENTRY_SHIFT : x + ComboBoxGuiImpl.TEXT_SHIFT, - y + 1 + (rh + fontSize)/2); + y + 1 + (rh + fontSize)/2, 0, 0); // draw the dotted line for selected item (not for SIMPLE mode of the combo-box) if (enabled && number == currentRow() && === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-04-14 15:15:50 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/AbstractGuiDriver.java 2016-05-02 13:00:34 +0000 @@ -53,6 +53,8 @@ ** 018 HC 20160407 Overhaul of window-activation logic. Removed setOverlayWindowLocation(), the ** method was unnecessary and was causing the COMBO-BOX drop-down location ** incorrect. +** 019 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes. */ package com.goldencode.p2j.ui.client.gui.driver; @@ -703,6 +705,48 @@ } /** + * Draw a string which can be centered within its box and can have an offset along horizontal + * and/or vertical. If the box is provided width its nonzero width and height, then x and y + * coordinates don't take into account and the given text is centered within the provided box + * and shifted along horizontal and/or vertical. + * + * @param text + * text string to draw. + * @param boxWidth + * The text box width, which needs to be matched when drawing. + * @param boxHeight + * The text box width, which needs to be matched when drawing. + * @param x + * The left position. + * @param y + * The top position. + * @param xOffset + * The horizontal text offset from its centered position. + * @param yOffset + * The vertical text offset from its centered position. + */ + @Override + public void drawString(String text, int boxWidth, int boxHeight, int x, int y, + int xOffset, int yOffset) + { + if (isEmptyText(text)) + { + return; + } + + PaintStructure ps = new PaintStructure(PaintPrimitives.DRAW_STRING); + ps.text = text; + ps.x = x; + ps.y = y; + ps.width = boxWidth; + ps.height = boxHeight; + ps.xOffset = xOffset; + ps.yOffset = yOffset; + + ews.offer(ps); + } + + /** * The method performs a layout operation on the supplied text and * returns the resulting paragraph height while maintaining the * supplied maximum width. === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java' --- src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-04-21 08:31:31 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/GuiDriver.java 2016-05-02 12:58:52 +0000 @@ -76,6 +76,8 @@ ** setDesktopBgColor(ColorRgb color). ** 042 HC 20160407 Removed setOverlayWindowLocation(), the method was unnecessary and was ** causing the COMBO-BOX drop-down location incorrect. +** 043 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes. */ package com.goldencode.p2j.ui.client.gui.driver; @@ -176,6 +178,30 @@ public void drawStringCentered(String text, int legacyWidth, int legacyHeight, int x, int height); /** + * Draw a string which can be centered within its box and can have an offset along horizontal + * and/or vertical. If the box is provided width its nonzero width and height, then x and y + * coordinates don't take into account and the given text is centered within the provided box + * and shifted along horizontal and/or vertical. + * + * @param text + * text string to draw. + * @param boxWidth + * The text box width, which needs to be matched when drawing. + * @param boxHeight + * The text box width, which needs to be matched when drawing. + * @param x + * The left position. + * @param y + * The top position. + * @param xOffset + * The horizontal text offset from its centered position. + * @param yOffset + * The vertical text offset from its centered position. + */ + public void drawString(String text, int boxWidth, int boxHeight, int x, int y, + int xOffset, int yOffset); + + /** * The method performs a layout operation on the supplied text and * returns the resulting paragraph height while maintaining the * supplied maximum width. === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java 2016-03-25 01:36:48 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java 2016-05-02 13:03:32 +0000 @@ -34,6 +34,8 @@ ** 012 CA 20160323 In getTextHeight(), return the font's height, as p2j.fonts.js computes the ** text's height in the same way. ** SBI 20160324 Implemented SET_DESKTOP_BGCOLOR. +** 013 SBI 20160502 Fixed the web combo box entry and drop down list items to be aligned within +** their boxes. */ package com.goldencode.p2j.ui.client.gui.driver.web; @@ -323,7 +325,8 @@ switch (ps.id) { case DRAW_STRING: - websock.drawString(ps.text, ps.centered, ps.x, ps.y); + websock.drawString(ps.text, ps.centered, ps.x, ps.y, ps.width, ps.height, + ps.xOffset, ps.yOffset); break; case DRAW_STRING_SCALED: websock.drawStringScaled(ps.text, ps.centered, ps.x, ps.y, ps.width, ps.height); === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java' --- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-04-27 15:18:42 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebSocket.java 2016-05-02 13:01:20 +0000 @@ -51,6 +51,8 @@ ** customer-specific application. ** SBI 20160422 The resize drawing operations must not be cached. ** 015 SBI 20160427 Added graphicsCached parameter to turn off the graphics cache for testing. +** SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes. */ package com.goldencode.p2j.ui.client.gui.driver.web; @@ -2512,7 +2514,36 @@ */ public void drawString(String text, boolean centered, int x, int y) { - int length = 1 + 4 + text.length() * 2 + 4 + 4 + 4; + drawString(text, centered, x, y, 0, 0, 0, 0); + } + + /** + * Draw a string which can be centered within its box and can have an offset along horizontal + * and/or vertical. If the box is provided width its nonzero width and height, then x and y + * coordinates don't take into account and the given text is centered within the provided box + * and shifted along horizontal and/or vertical. + * + * @param text + * text string to draw. + * @param centered + * Flag indicating if the text is centered vertically. + * @param x + * The left position. + * @param y + * The top position. + * @param boxWidth + * The text box width, which needs to be matched when drawing. + * @param boxHeight + * The text box width, which needs to be matched when drawing. + * @param xOffset + * The horizontal text offset from its centered position. + * @param yOffset + * The vertical text offset from its centered position. + */ + public void drawString(String text, boolean centered, int x, int y, int boxWidth, int boxHeight, + int xOffset, int yOffset) + { + int length = text.length() * 2 + 33; byte[] message = allocateDrawingOp(PaintPrimitives.DRAW_STRING, length); int offset = 1; @@ -2530,6 +2561,18 @@ writeMessageInt32(message, offset, y); offset += 4; + + writeMessageInt32(message, offset, boxWidth); + offset += 4; + + writeMessageInt32(message, offset, boxHeight); + offset += 4; + + writeMessageInt32(message, offset, xOffset); + offset += 4; + + writeMessageInt32(message, offset, yOffset); + offset += 4; } /** === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-04-28 09:48:03 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.canvas_renderer.js 2016-05-02 12:59:36 +0000 @@ -27,6 +27,8 @@ ** SBI 20160213 Reduced putImageData invocations for horizontal and vertical lines. ** SBI 20160322 Changed to work around if the window canvas has a zero width or height. ** 006 SBI 20160415 Replaced logFormatted(...) by log(...). +** 007 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, added drawTextBoxAlligned. */ "use strict"; @@ -1776,6 +1778,64 @@ } /** + * Draw a string that can be centered within its box and can have an offset along horizontal + * and/or vertical. If the box is provided width its nonzero width and height, then x and y + * coordinates don't take into account and the given text is centered within the provided box + * and shifted along horizontal and/or vertical. + * + * @param {String} text + * The text to draw. + * @param {Number} x + * The left position. + * @param {Number} y + * The top position. + * @param {Number} boxWidth + * The text box width, which needs to be matched when drawing. + * @param {Number} boxHeight + * The text box width, which needs to be matched when drawing. + * @param {Number} xOffset + * The horizontal text offset from its centered position. + * @param {Number} yOffset + * The vertical text offset from its centered position. + */ +CanvasRenderer.prototype.drawTextBoxAlligned = function(text, x, y, boxWidth, boxHeight, + xOffset, yOffset) +{ + var origY = y; + + var textWidth; + var cfont = p2j.screen.getCurrentFont(); + if (cfont) + { + textWidth = p2j.fonts.getTextWidth(cfont, text); + if (boxWidth > 0) + { + x = (boxWidth - textWidth - 16) / 2 + xOffset; + } + } + + this.ctx.textBaseline = 'bottom'; + + this.ctx.fillText(text, x, y); + + if (p2j.fonts.isUnderlined(cfont)) + { + // if the style is underline, draw a line under the text + var txtHeight = p2j.fonts.getTextHeight(cfont, text); + if (textWidth === undefined) + { + textWidth = p2j.fonts.getTextWidth(cfont, text); + } + + var x1 = x; + var x2 = x + textWidth; + var y1 = origY; + var y2 = y1; + + this.strokeLineSegment(x1, y1, x2, y2, this.rawColor); + } +} +/** * Draws a given text at the given (x,y) position fitted to the given text rectangle. * * @param {Number} currentFont === modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js' --- src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-04-27 15:18:42 +0000 +++ src/com/goldencode/p2j/ui/client/gui/driver/web/res/p2j.screen.js 2016-05-02 13:00:08 +0000 @@ -48,6 +48,8 @@ ** 012 SBI 20160414 Fixed doWindowActivationChange(...) and activateTopVisibleWindow(...). ** SBI 20160422 The resize drawing operations must not be cached. ** 013 SBI 20160427 Added graphicsCached parameter to turn off the graphics cache for testing. +** 014 SBI 20160502 Fixed the web combobox entry and drop down list items to be aligned within +** their boxes, added drawTextBoxAlligned. */ "use strict"; @@ -1369,7 +1371,29 @@ y = p2j.socket.readInt32BinaryMessage(message, idx + offset); offset = offset + 4; - this.canvasRenderer.drawText(text, x, y, centered); + + var boxWidth = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + var boxHeight = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + var xOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + var yOffset = p2j.socket.readInt32BinaryMessage(message, idx + offset); + offset = offset + 4; + + if (boxWidth === 0 || boxHeight === 0) + { + this.canvasRenderer.drawText(text, x, y, centered); + } + else + { + this.canvasRenderer.drawTextBoxAlligned(text, x, y, boxWidth, boxHeight, + xOffset, yOffset); + } + extra = " text = " + text + "; x = " + x + "; y = " + y + "; centered = " + centered; break;