/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.unitext.internal.rtf;

public class RichTextRow extends RichTextItem {

    public boolean endOf;

    public boolean lastRow;

    public static class CellInfo {
    
        public int id;
    
        public boolean horMerge;
    
        public boolean vertMergeFirst;
    
        public boolean vertMergeNext;
    
        public int width;
    
        @Override
        public String toString() {
            return (((Integer)id).toString() + " " + (horMerge ? "Merge " : "") + (vertMergeFirst ? "VertMergeFirst " : "") + (vertMergeNext ? "VertMergeNext " : ""));
        }
    
        public static CellInfo _new248(int _arg1) {
            CellInfo res = new CellInfo();
            res.id = _arg1;
            return res;
        }
        public CellInfo() {
        }
    }


    public java.util.ArrayList<CellInfo> cellsInfo = new java.util.ArrayList<CellInfo>();

    public boolean _addCmd(String cmd) {
        if (cmd == null) 
            return false;
        if (com.pullenti.unisharp.Utils.stringsEq(cmd, "lastrow")) {
            lastRow = true;
            return true;
        }
        CellInfo last = (cellsInfo.size() == 0 ? null : cellsInfo.get(cellsInfo.size() - 1));
        if (cmd.startsWith("cellx")) {
            int idd;
            com.pullenti.unisharp.Outargwrapper<Integer> wrapidd249 = new com.pullenti.unisharp.Outargwrapper<Integer>();
            boolean inoutres250 = com.pullenti.unisharp.Utils.parseInteger(cmd.substring(5), 0, null, wrapidd249);
            idd = (wrapidd249.value != null ? wrapidd249.value : 0);
            if (inoutres250) {
                if (idd > 0) {
                    for (CellInfo ii : cellsInfo) {
                        if (ii.id == idd) {
                            if (last.id == 0) {
                                if (last.horMerge) 
                                    ii.horMerge = true;
                                if (last.vertMergeFirst) 
                                    ii.vertMergeFirst = true;
                                if (last.vertMergeNext) 
                                    ii.vertMergeNext = true;
                                cellsInfo.remove(last);
                            }
                            return true;
                        }
                    }
                    if (last != null && last.id == 0) 
                        last.id = idd;
                    else 
                        cellsInfo.add(CellInfo._new248(idd));
                }
            }
            return true;
        }
        if (cmd.startsWith("clwWidth")) {
            int wi;
            com.pullenti.unisharp.Outargwrapper<Integer> wrapwi251 = new com.pullenti.unisharp.Outargwrapper<Integer>();
            boolean inoutres252 = com.pullenti.unisharp.Utils.parseInteger(cmd.substring(8), 0, null, wrapwi251);
            wi = (wrapwi251.value != null ? wrapwi251.value : 0);
            if (inoutres252) {
                if (last == null || last.id > 0) 
                    cellsInfo.add((last = new CellInfo()));
                last.width = wi;
                return true;
            }
        }
        if (com.pullenti.unisharp.Utils.stringsEq(cmd, "clmgf")) {
            if (last == null || last.id > 0) 
                cellsInfo.add((last = new CellInfo()));
            last.horMerge = true;
            return true;
        }
        if (com.pullenti.unisharp.Utils.stringsEq(cmd, "clvmgf")) {
            if (last == null || last.id > 0) 
                cellsInfo.add((last = new CellInfo()));
            last.vertMergeFirst = true;
            return true;
        }
        if (com.pullenti.unisharp.Utils.stringsEq(cmd, "clvmrg")) {
            if (last == null || last.id > 0) 
                cellsInfo.add((last = new CellInfo()));
            last.vertMergeNext = true;
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return ((lastRow ? "LastRow " : "") + (endOf ? "HasEnd " : "") + super.toString());
    }
    public RichTextRow() {
        super();
    }
    public static RichTextRow _globalInstance;
    
    static {
        try { _globalInstance = new RichTextRow(); } 
        catch(Exception e) { }
    }
}
