diff options
-rw-r--r-- | sc/Library_sc.mk | 1 | ||||
-rw-r--r-- | sc/UIConfig_scalc.mk | 1 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/documen3.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/mergecellsdialog.hxx | 42 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/mergecellsdialog.cxx | 50 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 28 | ||||
-rw-r--r-- | sc/uiconfig/scalc/ui/mergecellsdialog.ui | 154 |
10 files changed, 294 insertions, 12 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 5fa9cf3f2547..fd20f7604f7c 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -473,6 +473,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/miscdlgs/crnrdlg \ sc/source/ui/miscdlgs/datastreamdlg \ sc/source/ui/miscdlgs/highred \ + sc/source/ui/miscdlgs/mergecellsdialog \ sc/source/ui/miscdlgs/optsolver \ sc/source/ui/miscdlgs/protectiondlg \ sc/source/ui/miscdlgs/redcom \ diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk index 366eef035f34..0a00bdadae48 100644 --- a/sc/UIConfig_scalc.mk +++ b/sc/UIConfig_scalc.mk @@ -141,6 +141,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\ sc/uiconfig/scalc/ui/notebookbar \ sc/uiconfig/scalc/ui/notebookbar_groups \ sc/uiconfig/scalc/ui/managenamesdialog \ + sc/uiconfig/scalc/ui/mergecellsdialog \ sc/uiconfig/scalc/ui/movecopysheet \ sc/uiconfig/scalc/ui/movingaveragedialog \ sc/uiconfig/scalc/ui/multipleoperationsdialog \ diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index eccc49cf4603..bfef7e49ecce 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1137,6 +1137,8 @@ public: SC_DLLPUBLIC void DoMergeContents( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ); + SC_DLLPUBLIC void DoEmptyBlock( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, + SCCOL nEndCol, SCROW nEndRow ); // without checking: SC_DLLPUBLIC void DoMerge( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions = true ); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 374561cbb937..3d181c9c2437 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -2000,6 +2000,19 @@ void ScDocument::DoMergeContents( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SetString(nStartCol,nStartRow,nTab,aTotal.makeStringAndClear()); } +void ScDocument::DoEmptyBlock( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, + SCCOL nEndCol, SCROW nEndRow ) +{ + SCCOL nCol; + SCROW nRow; + for (nRow=nStartRow; nRow<=nEndRow; nRow++) + for (nCol=nStartCol; nCol<=nEndCol; nCol++) + { // empty block except first cell + if (nCol != nStartCol || nRow != nStartRow) + SetString(nCol,nRow,nTab,""); + } +} + void ScDocument::DoMerge( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions ) { diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 69550297d555..b72da3a7a935 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -4673,7 +4673,7 @@ bool ScDocFunc::FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillDir e return true; } -bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bool bRecord, bool bApi ) +bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bool bRecord, bool bApi, bool bEmptyMergedCells /*=false*/ ) { using ::std::set; @@ -4721,9 +4721,12 @@ bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bo for (set<SCTAB>::const_iterator itr = itrBeg; itr != itrEnd; ++itr) { SCTAB nTab = *itr; - bool bNeedContents = bContents && - ( !rDoc.IsBlockEmpty( nTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) || - !rDoc.IsBlockEmpty( nTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) ); + bool bIsBlockEmpty = ( nStartRow == nEndRow ) + ? rDoc.IsBlockEmpty( nTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) + : rDoc.IsBlockEmpty( nTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) && + rDoc.IsBlockEmpty( nTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ); + bool bNeedContents = bContents && !bIsBlockEmpty; + bool bNeedEmpty = bEmptyMergedCells && !bIsBlockEmpty && !bNeedContents; // if DoMergeContents then cells are emptyed if (bRecord) { @@ -4747,6 +4750,8 @@ bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bo if (bNeedContents) rDoc.DoMergeContents( nTab, nStartCol,nStartRow, nEndCol,nEndRow ); + else if ( bNeedEmpty ) + rDoc.DoEmptyBlock( nTab, nStartCol,nStartRow, nEndCol,nEndRow ); rDoc.DoMerge( nTab, nStartCol,nStartRow, nEndCol,nEndRow ); if (rOption.mbCenter) diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index b7709294b7c4..aa29c7ee24ea 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -188,7 +188,7 @@ public: void ResizeMatrix( const ScRange& rOldRange, const ScAddress& rNewEnd ); bool MergeCells( const ScCellMergeOption& rOption, bool bContents, - bool bRecord, bool bApi ); + bool bRecord, bool bApi, bool bEmptyMergedCells = false ); bool UnmergeCells( const ScRange& rRange, bool bRecord ); bool UnmergeCells( const ScCellMergeOption& rOption, bool bRecord ); diff --git a/sc/source/ui/inc/mergecellsdialog.hxx b/sc/source/ui/inc/mergecellsdialog.hxx new file mode 100644 index 000000000000..3d230740dbb6 --- /dev/null +++ b/sc/source/ui/inc/mergecellsdialog.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_SC_SOURCE_UI_INC_MERGECELLSDIALOG_HXX +#define INCLUDED_SC_SOURCE_UI_INC_MERGECELLSDIALOG_HXX + +#include <vcl/button.hxx> +#include <vcl/dialog.hxx> +#include <vcl/fixed.hxx> + +enum ScMergeCellsOption +{ + MoveContentHiddenCells, + KeepContentHiddenCells, + EmptyContentHiddenCells +}; + +class ScMergeCellsDialog : public ModalDialog +{ + VclPtr<RadioButton> mpRBMoveContent; + VclPtr<RadioButton> mpRBKeepContent; + VclPtr<RadioButton> mpRBEmptyContent; + +public: + ScMergeCellsDialog( vcl::Window * pParent ); + virtual ~ScMergeCellsDialog(); + virtual void dispose() override; + + ScMergeCellsOption GetMergeCellsOption(); +}; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/miscdlgs/mergecellsdialog.cxx b/sc/source/ui/miscdlgs/mergecellsdialog.cxx new file mode 100644 index 000000000000..3156f14f9091 --- /dev/null +++ b/sc/source/ui/miscdlgs/mergecellsdialog.cxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include "mergecellsdialog.hxx" + +ScMergeCellsDialog::ScMergeCellsDialog( vcl::Window * pParent ) + : ModalDialog( pParent, "MergeCellsDialog", + "modules/scalc/ui/mergecellsdialog.ui" ) +{ + get(mpRBMoveContent, "move-cells-radio"); + get(mpRBKeepContent, "keep-content-radio"); + get(mpRBEmptyContent, "empty-cells-radio"); + + mpRBKeepContent->Check(); +} + +ScMergeCellsDialog::~ScMergeCellsDialog() +{ + disposeOnce(); +} + +void ScMergeCellsDialog::dispose() +{ + mpRBMoveContent.disposeAndClear(); + mpRBKeepContent.disposeAndClear(); + mpRBEmptyContent.disposeAndClear(); + ModalDialog::dispose(); +} + +ScMergeCellsOption ScMergeCellsDialog::GetMergeCellsOption() +{ + if ( mpRBMoveContent->IsChecked() ) + return MoveContentHiddenCells; + if ( mpRBKeepContent->IsChecked() ) + return KeepContentHiddenCells; + if ( mpRBEmptyContent->IsChecked() ) + return EmptyContentHiddenCells; + assert(!"Unknown selection for merge cells."); + return KeepContentHiddenCells; // default value + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 2251efd4dd32..c9d38d2a999f 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -86,6 +86,7 @@ #include <rowheightcontext.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> +#include "mergecellsdialog.hxx" #include <vector> #include <memory> @@ -1081,19 +1082,32 @@ bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter ) } bool bOk = true; + bool bEmptyMergedCells = false; if (bAskDialog) { if (!bApi) { - ScopedVclPtrInstance<MessBox> aBox( GetViewData().GetDialogParent(), - WinBits(WB_YES_NO_CANCEL | WB_DEF_NO), - ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ), - ScGlobal::GetRscString( STR_MERGE_NOTEMPTY ) ); + VclPtr<ScMergeCellsDialog> aBox = VclPtr<ScMergeCellsDialog>::Create( GetViewData().GetDialogParent() ); sal_uInt16 nRetVal = aBox->Execute(); - if ( nRetVal == RET_YES ) - rDoContents = true; + if ( nRetVal == RET_OK ) + { + switch ( aBox->GetMergeCellsOption() ) + { + case MoveContentHiddenCells: + rDoContents = true; + break; + case KeepContentHiddenCells: + break; // keep default values + case EmptyContentHiddenCells: + bEmptyMergedCells = true; + break; + default: + assert(!"Unknown option for merge cells."); + break; + } + } else if ( nRetVal == RET_CANCEL ) bOk = false; } @@ -1101,7 +1115,7 @@ bool ScViewFunc::MergeCells( bool bApi, bool& rDoContents, bool bCenter ) if (bOk) { - bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, true/*bRecord*/, bApi ); + bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, true/*bRecord*/, bApi, bEmptyMergedCells ); if (bOk) { diff --git a/sc/uiconfig/scalc/ui/mergecellsdialog.ui b/sc/uiconfig/scalc/ui/mergecellsdialog.ui new file mode 100644 index 000000000000..ac45f304def5 --- /dev/null +++ b/sc/uiconfig/scalc/ui/mergecellsdialog.ui @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.3 --> +<interface> + <requires lib="gtk+" version="3.0"/> + <object class="GtkDialog" id="MergeCellsDialog"> + <property name="can_focus">False</property> + <property name="border_width">6</property> + <property name="title" translatable="yes">Merge Cells</property> + <property name="type_hint">dialog</property> + <child internal-child="vbox"> + <object class="GtkBox" id="dialog-vbox1"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">12</property> + <child internal-child="action_area"> + <object class="GtkButtonBox" id="dialog-action_area1"> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="ok"> + <property name="label">gtk-ok</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="cancel"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="help"> + <property name="label">gtk-help</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + <property name="secondary">True</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkLabel" id="label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Some cells are not empty.</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="move-cells-radio"> + <property name="label" translatable="yes">Move the contents of the hidden cells into the first cell</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <property name="group">keep-content-radio</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="keep-content-radio"> + <property name="label" translatable="yes">Keep the contents of the hidden cells</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="empty-cells-radio"> + <property name="label" translatable="yes">Empty the contents of the hidden cells</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <property name="group">keep-content-radio</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> +</interface> |