From f9998d03b607b35bc9d6c44198ff92f19a497a32 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Thu, 4 May 2000 22:32:24 +0000 Subject: [PATCH] Added 'Split Cell' and fixed initialization of 'Join Cells' in table menu. Added stubs for 'Split Cell' git-svn-id: svn://10.0.0.236/trunk@68273 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditorShell.cpp | 19 ++++++++ mozilla/editor/base/nsHTMLEditor.h | 1 + mozilla/editor/base/nsHTMLEditorLog.cpp | 14 ++++++ mozilla/editor/base/nsHTMLEditorLog.h | 1 + mozilla/editor/base/nsTableEditor.cpp | 31 +++++++++++- mozilla/editor/composer/src/nsEditorShell.cpp | 19 ++++++++ mozilla/editor/idl/nsIEditorShell.idl | 24 ++++++++++ mozilla/editor/libeditor/html/nsHTMLEditor.h | 1 + .../editor/libeditor/html/nsHTMLEditorLog.cpp | 14 ++++++ .../editor/libeditor/html/nsHTMLEditorLog.h | 1 + .../editor/libeditor/html/nsTableEditor.cpp | 31 +++++++++++- mozilla/editor/public/nsITableEditor.h | 48 ++++++++++++++++--- .../ui/composer/content/EditorCommands.js | 24 +++++++++- .../ui/composer/content/editorOverlay.xul | 11 ++--- .../composer/locale/en-US/editor.properties | 2 +- .../composer/locale/en-US/editorOverlay.dtd | 4 +- 16 files changed, 228 insertions(+), 17 deletions(-) diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index a4869b74257..63ea35a5cb7 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -3581,6 +3581,25 @@ nsEditorShell::JoinTableCells() return result; } +NS_IMETHODIMP +nsEditorShell::SplitTableCell() +{ + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr tableEditor = do_QueryInterface(mEditor); + if (tableEditor) + result = tableEditor->SplitTableCell(); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + return result; +} + NS_IMETHODIMP nsEditorShell::SelectTableCell() { diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 49719c6c8f6..20df24ca023 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -192,6 +192,7 @@ public: NS_IMETHOD SelectTable(); NS_IMETHOD SelectAllTableCells(); NS_IMETHOD JoinTableCells(); + NS_IMETHOD SplitTableCell(); NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex); NS_IMETHOD GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& aColCount); diff --git a/mozilla/editor/base/nsHTMLEditorLog.cpp b/mozilla/editor/base/nsHTMLEditorLog.cpp index 2b1a7386654..d2c1d90c8eb 100644 --- a/mozilla/editor/base/nsHTMLEditorLog.cpp +++ b/mozilla/editor/base/nsHTMLEditorLog.cpp @@ -636,6 +636,20 @@ nsHTMLEditorLog:: JoinTableCells() return nsHTMLEditor::JoinTableCells(); } +NS_IMETHODIMP +nsHTMLEditorLog:: SplitTableCell() +{ + nsAutoHTMLEditorLogLock logLock(this); + + if (!mLocked && mFileSpec) + { + Write("window.editorShell.SplitTableCell();\n"); + Flush(); + } + + return nsHTMLEditor::SplitTableCell(); +} + NS_IMETHODIMP nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable) diff --git a/mozilla/editor/base/nsHTMLEditorLog.h b/mozilla/editor/base/nsHTMLEditorLog.h index 7dedb0d1798..1468229672d 100644 --- a/mozilla/editor/base/nsHTMLEditorLog.h +++ b/mozilla/editor/base/nsHTMLEditorLog.h @@ -100,6 +100,7 @@ public: NS_IMETHOD DeleteTableColumn(PRInt32 aNumber); NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(); + NS_IMETHOD SplitTableCell(); NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD StartLogging(nsIFileSpec *aLogFile); diff --git a/mozilla/editor/base/nsTableEditor.cpp b/mozilla/editor/base/nsTableEditor.cpp index 06af8d76f53..7f1e0e06b28 100644 --- a/mozilla/editor/base/nsTableEditor.cpp +++ b/mozilla/editor/base/nsTableEditor.cpp @@ -1315,6 +1315,35 @@ nsHTMLEditor::SelectTableColumn() return res; } +NS_IMETHODIMP +nsHTMLEditor::SplitTableCell() +{ + nsCOMPtr table; + nsCOMPtr targetCell; + PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; + PRBool isSelected; + nsCOMPtr cell2; + PRInt32 startRowIndex2, startColIndex2, rowSpan2, colSpan2, actualRowSpan2, actualColSpan2; + PRBool isSelected2; + + // Get cell and table at selection anchor node (and other data) + nsresult res = GetCellContext(nsnull, + getter_AddRefs(table), + getter_AddRefs(targetCell), + nsnull, nsnull, + &startRowIndex, &startColIndex); + if (NS_FAILED(res)) return res; + if(!table || !targetCell) return NS_EDITOR_ELEMENT_NOT_FOUND; + + // We need rowspan and colspan data + res = GetCellDataAt(table, startRowIndex, startColIndex, *getter_AddRefs(targetCell), + startRowIndex, startColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); + + //TODO: FINISH THIS! + return res; +} + NS_IMETHODIMP nsHTMLEditor::JoinTableCells() { @@ -1358,7 +1387,7 @@ nsHTMLEditor::JoinTableCells() if (firstCell) { - // Merge selected cells + // Merge selected cells into uppper-left-most cell } else { diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index a4869b74257..63ea35a5cb7 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -3581,6 +3581,25 @@ nsEditorShell::JoinTableCells() return result; } +NS_IMETHODIMP +nsEditorShell::SplitTableCell() +{ + nsresult result = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr tableEditor = do_QueryInterface(mEditor); + if (tableEditor) + result = tableEditor->SplitTableCell(); + } + break; + default: + result = NS_ERROR_NOT_IMPLEMENTED; + } + return result; +} + NS_IMETHODIMP nsEditorShell::SelectTableCell() { diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 29532a41a33..e31f3b279ba 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -321,7 +321,31 @@ interface nsIEditorShell : nsISupports void DeleteTableCellContents(); void DeleteTableRow(in PRInt32 number); void DeleteTableColumn(in PRInt32 number); + /** Merges contents of all selected cells + * for selected cells that are adjacent, + * this will result in a larger cell with appropriate + * rowspan and colspan, and original cells are deleted + * The resulting cell is in the location of the + * cell at the upper-left corner of the adjacent + * block of selected cells + * Non-adjacent cells are not deleted, + * but their contents are still moved + * to the upper-left cell + * If there are no selected cells, + * and selection or caret is in a cell, + * that cell and the one to the right + * are merged + */ void JoinTableCells(); + + /** Split a cell that has rowspan and/or colspan > 0 + * into cells such that all new cells have + * rowspan = 1 and colspan = 1 + * All of the contents are not touched -- + * they will appear to be in the upper-left cell + */ + void SplitTableCell(); + /** Table selection methods * Selecting a row or column actually * selects all cells (not TR in the case of rows) diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 49719c6c8f6..20df24ca023 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -192,6 +192,7 @@ public: NS_IMETHOD SelectTable(); NS_IMETHOD SelectAllTableCells(); NS_IMETHOD JoinTableCells(); + NS_IMETHOD SplitTableCell(); NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD GetCellIndexes(nsIDOMElement *aCell, PRInt32& aRowIndex, PRInt32& aColIndex); NS_IMETHOD GetTableSize(nsIDOMElement *aTable, PRInt32& aRowCount, PRInt32& aColCount); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp index 2b1a7386654..d2c1d90c8eb 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorLog.cpp @@ -636,6 +636,20 @@ nsHTMLEditorLog:: JoinTableCells() return nsHTMLEditor::JoinTableCells(); } +NS_IMETHODIMP +nsHTMLEditorLog:: SplitTableCell() +{ + nsAutoHTMLEditorLogLock logLock(this); + + if (!mLocked && mFileSpec) + { + Write("window.editorShell.SplitTableCell();\n"); + Flush(); + } + + return nsHTMLEditor::SplitTableCell(); +} + NS_IMETHODIMP nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable) diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorLog.h b/mozilla/editor/libeditor/html/nsHTMLEditorLog.h index 7dedb0d1798..1468229672d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorLog.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditorLog.h @@ -100,6 +100,7 @@ public: NS_IMETHOD DeleteTableColumn(PRInt32 aNumber); NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(); + NS_IMETHOD SplitTableCell(); NS_IMETHOD NormalizeTable(nsIDOMElement *aTable); NS_IMETHOD StartLogging(nsIFileSpec *aLogFile); diff --git a/mozilla/editor/libeditor/html/nsTableEditor.cpp b/mozilla/editor/libeditor/html/nsTableEditor.cpp index 06af8d76f53..7f1e0e06b28 100644 --- a/mozilla/editor/libeditor/html/nsTableEditor.cpp +++ b/mozilla/editor/libeditor/html/nsTableEditor.cpp @@ -1315,6 +1315,35 @@ nsHTMLEditor::SelectTableColumn() return res; } +NS_IMETHODIMP +nsHTMLEditor::SplitTableCell() +{ + nsCOMPtr table; + nsCOMPtr targetCell; + PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; + PRBool isSelected; + nsCOMPtr cell2; + PRInt32 startRowIndex2, startColIndex2, rowSpan2, colSpan2, actualRowSpan2, actualColSpan2; + PRBool isSelected2; + + // Get cell and table at selection anchor node (and other data) + nsresult res = GetCellContext(nsnull, + getter_AddRefs(table), + getter_AddRefs(targetCell), + nsnull, nsnull, + &startRowIndex, &startColIndex); + if (NS_FAILED(res)) return res; + if(!table || !targetCell) return NS_EDITOR_ELEMENT_NOT_FOUND; + + // We need rowspan and colspan data + res = GetCellDataAt(table, startRowIndex, startColIndex, *getter_AddRefs(targetCell), + startRowIndex, startColIndex, rowSpan, colSpan, + actualRowSpan, actualColSpan, isSelected); + + //TODO: FINISH THIS! + return res; +} + NS_IMETHODIMP nsHTMLEditor::JoinTableCells() { @@ -1358,7 +1387,7 @@ nsHTMLEditor::JoinTableCells() if (firstCell) { - // Merge selected cells + // Merge selected cells into uppper-left-most cell } else { diff --git a/mozilla/editor/public/nsITableEditor.h b/mozilla/editor/public/nsITableEditor.h index 92ac2930279..cd9f07680f8 100644 --- a/mozilla/editor/public/nsITableEditor.h +++ b/mozilla/editor/public/nsITableEditor.h @@ -100,15 +100,30 @@ public: NS_IMETHOD SelectTable()=0; NS_IMETHOD SelectAllTableCells()=0; - /** Join the contents of the selected cells into one cell, - * expanding that cells ROWSPAN and COLSPAN to take up - * the same number of cellmap locations as before. - * Cells whose contents were moved are deleted. - * If there's one cell selected or caret is in one cell, - * it is joined with the cell to the right, if it exists + /** Merges contents of all selected cells + * for selected cells that are adjacent, + * this will result in a larger cell with appropriate + * rowspan and colspan, and original cells are deleted + * The resulting cell is in the location of the + * cell at the upper-left corner of the adjacent + * block of selected cells + * Non-adjacent cells are not deleted, + * but their contents are still moved + * to the upper-left cell + * If there are no selected cells, + * and selection or caret is in a cell, + * that cell and the one to the right + * are merged */ NS_IMETHOD JoinTableCells()=0; + /** Split a cell that has rowspan and/or colspan > 0 + * into cells such that all new cells have + * rowspan = 1 and colspan = 1 + * All of the contents are not touched -- + * they will appear to be in the upper-left cell + */ + NS_IMETHOD SplitTableCell()=0; /** Scan through all rows and add cells as needed so * all locations in the cellmap are occupied. @@ -286,6 +301,27 @@ public: * associated with the cell */ NS_IMETHOD GetNextSelectedCell(nsIDOMElement **aCell, nsIDOMRange **aRange)=0; + + /** Get first selected element from first selection range. + * Assumes cell-selection model where each cell + * is in a separate range (selection parent node is table row) + * @param aCell Selected cell or null if ranges don't contain cell selections + * @param aRange Optional: if not null, return the selection range + * associated with the cell + * Returns NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found (passes NS_SUCCEEDED macro) + */ + NS_IMETHOD GetFirstSelectedCell(nsIDOMElement **aCell, nsIDOMRange **aRange)=0; + + /** Get next selected cell element from first selection range. + * Assumes cell-selection model where each cell + * is in a separate range (selection parent node is table row) + * Always call GetFirstSelectedCell() to initialize stored index of "next" cell + * @param aCell Selected cell or null if no more selected cells + * or ranges don't contain cell selections + * @param aRange Optional: if not null, return the selection range + * associated with the cell + */ + NS_IMETHOD GetNextSelectedCell(nsIDOMElement **aCell, nsIDOMRange **aRange)=0; }; #endif // nsITableEditor_h__ diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index d480ff8409f..2675fe9f4ee 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -1104,10 +1104,26 @@ function EditorInitFormatMenu() menuStr = menuStr.replace(/%obj%/,"").replace(/^\s+/, ""); } - menuItem.setAttribute("value", menuStr) + menuItem.setAttribute("value", menuStr); } } +function InitTableMenu() +{ + // Change text on the "Join..." item depending if we + // are joining selected cells or just cell to right + // TODO: What to do about normal selection that crosses + // table border? Try to figure out all cells + // included in the selection? + var menuText; + if (editorShell.GetFirstSelectedCell()) + menuText = editorShell.GetString("JoinSelectedCells"); + else + menuText = editorShell.GetString("JoinCellToRight"); + + document.getElementById("tableJoinCells").setAttribute("value",menuText); +} + function EditorInitToolbars() { // Nothing to do now, but we might want some state updating here @@ -1573,6 +1589,12 @@ function EditorJoinTableCells() contentWindow.focus(); } +function EditorSplitTableCell() +{ + editorShell.SplitTableCell(); + contentWindow.focus(); +} + function EditorDeleteTable() { editorShell.DeleteTable(); diff --git a/mozilla/editor/ui/composer/content/editorOverlay.xul b/mozilla/editor/ui/composer/content/editorOverlay.xul index 6f9e6404080..7ba1e5f7579 100644 --- a/mozilla/editor/ui/composer/content/editorOverlay.xul +++ b/mozilla/editor/ui/composer/content/editorOverlay.xul @@ -293,7 +293,6 @@ - @@ -595,7 +594,7 @@ oncommand="goDoCommand('cmd_colorProperties')"/> - + @@ -629,10 +628,10 @@ - - - - + + + + diff --git a/mozilla/editor/ui/composer/locale/en-US/editor.properties b/mozilla/editor/ui/composer/locale/en-US/editor.properties index 0f2426132b0..d700674c524 100644 --- a/mozilla/editor/ui/composer/locale/en-US/editor.properties +++ b/mozilla/editor/ui/composer/locale/en-US/editor.properties @@ -97,6 +97,6 @@ NamedAnchor=Named Anchor Tag=Tag #Don't translate "%obj%" it will be replaced with one of above object nouns ObjectProperties=%obj% Properties... -#Next 2 must contain the "tablejoin.accesskey" letter in editorOverlay.dtd +#Next 2 must contain the "tablejoincells.accesskey" letter in editorOverlay.dtd JoinSelectedCells=Join Selected Cells JoinCellToRight=Join with Cell to the Right diff --git a/mozilla/editor/ui/composer/locale/en-US/editorOverlay.dtd b/mozilla/editor/ui/composer/locale/en-US/editorOverlay.dtd index 47fae4e8e23..32784667830 100644 --- a/mozilla/editor/ui/composer/locale/en-US/editorOverlay.dtd +++ b/mozilla/editor/ui/composer/locale/en-US/editorOverlay.dtd @@ -490,7 +490,9 @@ Menu item text for "[Page|Table|Cell] Background color" is filled from ("JoinSelectedCells" and "JoinCellToRight") the access key must exist in both of those strings --> - + + +