[Libreoffice-commits] core.git: Branch 'feature/mailmerge-toolbar' - 2 commits - officecfg/registry sw/inc sw/Library_sw.mk sw/sdi sw/source sw/uiconfig sw/util

Jan Holesovsky kendy at collabora.com
Fri Jan 1 15:48:14 PST 2016


Rebased ref, commits from common ancestor:
commit f83a3743b345f6c369b5256e66dfa441ace6baa1
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Sat Jan 2 00:38:18 2016 +0100

    mailmerge: Toolbar edit box to show or change the current entry number.
    
    Change-Id: I935c059da44f2309c3cb1a8b2e93341c353bee01

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
index 42559cf..7a93a8f 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
@@ -855,6 +855,17 @@
           <value>starshapes;.uno:StarShapes.star5</value>
         </prop>
       </node>
+      <node oor:name="lo.writer.MMCurrentEntryController" oor:op="replace">
+        <prop oor:name="Command">
+          <value>.uno:MailMergeCurrentEntry</value>
+        </prop>
+        <prop oor:name="Module">
+          <value/>
+        </prop>
+        <prop oor:name="Controller">
+          <value>lo.writer.MMCurrentEntryController</value>
+        </prop>
+      </node>
       <node oor:name="lo.writer.MMExcludeEntryController" oor:op="replace">
         <prop oor:name="Command">
           <value>.uno:MailMergeExcludeEntry</value>
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 03bdc51..cd8ee2d 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -256,6 +256,7 @@
 #define FN_MAILMERGE_PREV_ENTRY (FN_INSERT + 71)    /* mail merge toolbar - go to the previous entry */
 #define FN_MAILMERGE_NEXT_ENTRY (FN_INSERT + 72)    /* mail merge toolbar - go to the next entry */
 #define FN_MAILMERGE_LAST_ENTRY (FN_INSERT + 73)    /* mail merge toolbar - go to the next entry */
+#define FN_MAILMERGE_CURRENT_ENTRY (FN_INSERT + 74) /* mail merge toolbar - show or change the current entry */
 #define FN_MAILMERGE_EXCLUDE_ENTRY (FN_INSERT + 75) /* mail merge toolbar - checkbox to exclude the current entry */
 
 #define FN_DRAWTEXT_ATTR_DLG    (FN_INSERT + 76)    /* position DrawText */
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index fe92ba9..92b246d 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -5323,6 +5323,30 @@ SfxVoidItem MailMergeLastEntry FN_MAILMERGE_LAST_ENTRY
     GroupId = GID_DOCUMENT;
 ]
 
+SfxVoidItem MailMergeCurrentEntry FN_MAILMERGE_CURRENT_ENTRY
+()
+[
+    /* flags: */
+    AutoUpdate = TRUE,
+    Cachable = Cachable,
+    FastCall = TRUE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = TRUE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_DOCUMENT;
+]
+
 SfxVoidItem MailMergeExcludeEntry FN_MAILMERGE_EXCLUDE_ENTRY
 ()
 [
diff --git a/sw/sdi/wrtapp.sdi b/sw/sdi/wrtapp.sdi
index 794f796..16e5094 100644
--- a/sw/sdi/wrtapp.sdi
+++ b/sw/sdi/wrtapp.sdi
@@ -89,6 +89,12 @@ interface StarWriter
         StateMethod = StateOther ;
     ]
 
+    FN_MAILMERGE_CURRENT_ENTRY
+    [
+        ExecMethod = ExecOther ;
+        StateMethod = StateOther ;
+    ]
+
     FN_MAILMERGE_EXCLUDE_ENTRY
     [
         StateMethod = StateOther ;
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index e8670b4..06e4e5e 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -225,9 +225,11 @@ void SwModule::StateOther(SfxItemSet &rSet)
                 }
             }
             break;
+            case FN_MAILMERGE_CURRENT_ENTRY:
             case FN_MAILMERGE_EXCLUDE_ENTRY:
             {
                 // just trigger calling statusChanged() of MMExcludeEntryController
+                // resp. MMCurrentEntryController
                 rSet.InvalidateItem(nWhich);
             }
             break;
@@ -751,6 +753,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
         case FN_MAILMERGE_PREV_ENTRY:
         case FN_MAILMERGE_NEXT_ENTRY:
         case FN_MAILMERGE_LAST_ENTRY:
+        case FN_MAILMERGE_CURRENT_ENTRY:
         {
             SwView* pView = ::GetActiveView();
             SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem();
@@ -764,6 +767,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
                 case FN_MAILMERGE_PREV_ENTRY:  pConfigItem->MoveResultSet(nPos - 1); break;
                 case FN_MAILMERGE_NEXT_ENTRY:  pConfigItem->MoveResultSet(nPos + 1); break;
                 case FN_MAILMERGE_LAST_ENTRY:  pConfigItem->MoveResultSet(-1); break;
+                case FN_MAILMERGE_CURRENT_ENTRY: /* don't move the result set, just update the document */ break;
                 default: break;
             }
 
@@ -790,6 +794,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
             rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY);
             rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY);
             rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY);
+            rBindings.Invalidate(FN_MAILMERGE_CURRENT_ENTRY);
             rBindings.Invalidate(FN_MAILMERGE_EXCLUDE_ENTRY);
             rBindings.Update();
         }
diff --git a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
index d4dacfb..749d65f 100644
--- a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
+++ b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
@@ -36,6 +36,74 @@ using namespace css;
 
 namespace {
 
+/// Controller for .uno:MailMergeCurrentEntry toolbar checkbox: creates the checkbox & handles the value.
+class MMCurrentEntryController : public svt::ToolboxController, public lang::XServiceInfo
+{
+    VclPtr<Edit> m_pCurrentEdit;
+
+    DECL_LINK_TYPED(CurrentEditUpdatedHdl, Edit&, void);
+
+public:
+    MMCurrentEntryController(const uno::Reference<uno::XComponentContext>& rContext)
+        : svt::ToolboxController(rContext, uno::Reference<frame::XFrame>(), OUString(".uno:MailMergeCurrentEntry"))
+        , m_pCurrentEdit(nullptr)
+    {
+    }
+
+    virtual ~MMCurrentEntryController()
+    {
+    }
+
+    // XInterface
+    virtual uno::Any SAL_CALL queryInterface(const uno::Type& aType) throw (uno::RuntimeException, std::exception) override
+    {
+        uno::Any a(ToolboxController::queryInterface(aType));
+        if (a.hasValue())
+            return a;
+
+        return ::cppu::queryInterface(aType, static_cast<lang::XServiceInfo*>(this));
+    }
+
+    void SAL_CALL acquire() throw ()
+    {
+        ToolboxController::acquire();
+    }
+
+    void SAL_CALL release() throw ()
+    {
+        ToolboxController::release();
+    }
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) override
+    {
+        return OUString("lo.writer.MMCurrentEntryController");
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) throw (uno::RuntimeException, std::exception) override
+    {
+        return cppu::supportsService(this, rServiceName);
+    }
+
+    virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) override
+    {
+        uno::Sequence<OUString> aServices { "com.sun.star.frame.ToolbarController" };
+        return aServices;
+    }
+
+    // XComponent
+    virtual void SAL_CALL dispose() throw (uno::RuntimeException, std::exception) override;
+
+    // XInitialization
+    virtual void SAL_CALL initialize(const uno::Sequence< uno::Any >& aArguments) throw (uno::Exception, uno::RuntimeException, std::exception) override;
+
+    // XToolbarController
+    virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception) override;
+
+    // XStatusListener
+    virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception) override;
+};
+
 /// Controller for .uno:MailMergeExcludeEntry toolbar checkbox: creates the checkbox & handles the value.
 class MMExcludeEntryController : public svt::ToolboxController, public lang::XServiceInfo
 {
@@ -104,6 +172,78 @@ public:
     virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception) override;
 };
 
+void MMCurrentEntryController::dispose() throw (uno::RuntimeException, std::exception)
+{
+    SolarMutexGuard aSolarMutexGuard;
+
+    svt::ToolboxController::dispose();
+    m_pCurrentEdit.disposeAndClear();
+}
+
+void MMCurrentEntryController::initialize(const uno::Sequence< uno::Any >& aArguments) throw (uno::Exception, uno::RuntimeException, std::exception)
+{
+    svt::ToolboxController::initialize(aArguments);
+}
+
+uno::Reference<awt::XWindow> MMCurrentEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception)
+{
+    vcl::Window* pParent = VCLUnoHelper::GetWindow(rParent);
+    ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent);
+    if (pToolbar)
+    {
+        // make it visible
+        m_pCurrentEdit = VclPtr<Edit>::Create(pToolbar);
+        m_pCurrentEdit->SetWidthInChars(4);
+        m_pCurrentEdit->SetSizePixel(m_pCurrentEdit->GetOptimalSize());
+
+        m_pCurrentEdit->SetModifyHdl(LINK(this, MMCurrentEntryController, CurrentEditUpdatedHdl));
+    }
+
+    return uno::Reference<awt::XWindow>(VCLUnoHelper::GetInterface(m_pCurrentEdit));
+}
+
+IMPL_LINK_TYPED(MMCurrentEntryController, CurrentEditUpdatedHdl, Edit&, rEdit, void)
+{
+    SwView* pView = ::GetActiveView();
+    SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem();
+
+    if (!pConfigItem)
+        return;
+
+    OUString aText(rEdit.GetText());
+    sal_Int32 nEntry = aText.toInt32();
+    if (!aText.isEmpty() && nEntry != pConfigItem->GetResultSetPosition())
+    {
+        pConfigItem->MoveResultSet(nEntry);
+        // notify about the change
+        dispatchCommand(".uno:MailMergeCurrentEntry", uno::Sequence<beans::PropertyValue>());
+    }
+};
+
+void MMCurrentEntryController::statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception)
+{
+    if (!m_pCurrentEdit)
+        return;
+
+    SwView* pView = ::GetActiveView();
+    SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem();
+
+    if (!pConfigItem || !rEvent.IsEnabled)
+    {
+        m_pCurrentEdit->Disable();
+        m_pCurrentEdit->SetText("");
+    }
+    else
+    {
+        sal_Int32 nEntry = m_pCurrentEdit->GetText().toInt32();
+        if (!m_pCurrentEdit->IsEnabled() || nEntry != pConfigItem->GetResultSetPosition())
+        {
+            m_pCurrentEdit->Enable();
+            m_pCurrentEdit->SetText(OUString::number(pConfigItem->GetResultSetPosition()));
+        }
+    }
+}
+
 void MMExcludeEntryController::dispose() throw (uno::RuntimeException, std::exception)
 {
     SolarMutexGuard aSolarMutexGuard;
@@ -166,6 +306,14 @@ void MMExcludeEntryController::statusChanged(const frame::FeatureStateEvent& rEv
 }
 
 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface * SAL_CALL
+lo_writer_MMCurrentEntryController_get_implementation(
+    uno::XComponentContext *context,
+    uno::Sequence<uno::Any> const &)
+{
+    return cppu::acquire(new MMCurrentEntryController(context));
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface * SAL_CALL
 lo_writer_MMExcludeEntryController_get_implementation(
     uno::XComponentContext *context,
     uno::Sequence<uno::Any> const &)
diff --git a/sw/uiconfig/swform/toolbar/mailmerge.xml b/sw/uiconfig/swform/toolbar/mailmerge.xml
index 61cca36..ff9773d 100644
--- a/sw/uiconfig/swform/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swform/toolbar/mailmerge.xml
@@ -13,6 +13,7 @@
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeFirstEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeCurrentEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
diff --git a/sw/uiconfig/swreport/toolbar/mailmerge.xml b/sw/uiconfig/swreport/toolbar/mailmerge.xml
index 61cca36..ff9773d 100644
--- a/sw/uiconfig/swreport/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swreport/toolbar/mailmerge.xml
@@ -13,6 +13,7 @@
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeFirstEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeCurrentEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
diff --git a/sw/uiconfig/swriter/toolbar/mailmerge.xml b/sw/uiconfig/swriter/toolbar/mailmerge.xml
index 61cca36..ff9773d 100644
--- a/sw/uiconfig/swriter/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swriter/toolbar/mailmerge.xml
@@ -13,6 +13,7 @@
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeFirstEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeCurrentEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
diff --git a/sw/uiconfig/swxform/toolbar/mailmerge.xml b/sw/uiconfig/swxform/toolbar/mailmerge.xml
index 61cca36..ff9773d 100644
--- a/sw/uiconfig/swxform/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swxform/toolbar/mailmerge.xml
@@ -13,6 +13,7 @@
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeFirstEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeCurrentEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
diff --git a/sw/util/sw.component b/sw/util/sw.component
index ff6b032..c069d63 100644
--- a/sw/util/sw.component
+++ b/sw/util/sw.component
@@ -27,6 +27,10 @@
     <service name="com.sun.star.sdb.DataAccessDescriptor"/>
     <service name="com.sun.star.text.MailMerge"/>
   </implementation>
+  <implementation name="lo.writer.MMCurrentEntryController"
+      constructor="lo_writer_MMCurrentEntryController_get_implementation">
+    <service name="com.sun.star.frame.ToolbarController"/>
+  </implementation>
   <implementation name="lo.writer.MMExcludeEntryController"
       constructor="lo_writer_MMExcludeEntryController_get_implementation">
     <service name="com.sun.star.frame.ToolbarController"/>
commit 3ea3c5deb2af86180153445dc28690e8a643130b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Dec 30 00:00:37 2015 +0100

    mailmerge: Implement toolbar controller to exclude entries.
    
    This can be used as a "How to implement a custom widget / control in
    the toolbar" example:
    
    * the Controller.xcu change introduces a .uno:MailMergeExcludeEntry command so
      that it can be added in the toolbar .xml description (in this case
      mailmerge.xml)
    
    * the swriter.sdi introduces the .uno:MailMergeExcludeEntry command for the
      sfx2 handling - so that it can get notifications about enable/disable
      changes, invalidates, etc.
    
    * wrtapp.sdi + associated apphdl.cxx change make it possible to forward
      command invalidates (the rBindings.Invalidate(FN_MAILMERGE_EXCLUDE_ENTRY);)
      to the MMExcludeEntryController::statusChanged() for further handling
      (in this case setting the checked state according to the current data)
    
    * MMExcludeEntryController::createItemWindow() implements the custom widget
      itself (in this case a checkbox, but can be any VCL widget, even a custom
      one)
    
    * the rest (sw.component and the associated getImplementationName(),
      supportsService(), etc.) takes care of the instantiation of the controller.
    
    Change-Id: I68269538f779a6680b0ba98395b7985d3f1ab95a

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
index 31c9e4c..42559cf 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
@@ -855,6 +855,17 @@
           <value>starshapes;.uno:StarShapes.star5</value>
         </prop>
       </node>
+      <node oor:name="lo.writer.MMExcludeEntryController" oor:op="replace">
+        <prop oor:name="Command">
+          <value>.uno:MailMergeExcludeEntry</value>
+        </prop>
+        <prop oor:name="Module">
+          <value/>
+        </prop>
+        <prop oor:name="Controller">
+          <value>lo.writer.MMExcludeEntryController</value>
+        </prop>
+      </node>
       <node oor:name="com.sun.star.svx.FindTextToolboxController" oor:op="replace">
         <prop oor:name="Command">
           <value>.uno:FindText</value>
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index f9725be..f8c16b7 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -768,6 +768,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/uibase/dbui/maildispatcher \
     sw/source/uibase/dbui/mailmergechildwindow \
     sw/source/uibase/dbui/mailmergehelper \
+    sw/source/uibase/dbui/mailmergetoolbarcontrols \
     sw/source/uibase/dbui/mmconfigitem \
     sw/source/uibase/uno/unomailmerge \
 ))
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index bd622fe..03bdc51 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -256,6 +256,7 @@
 #define FN_MAILMERGE_PREV_ENTRY (FN_INSERT + 71)    /* mail merge toolbar - go to the previous entry */
 #define FN_MAILMERGE_NEXT_ENTRY (FN_INSERT + 72)    /* mail merge toolbar - go to the next entry */
 #define FN_MAILMERGE_LAST_ENTRY (FN_INSERT + 73)    /* mail merge toolbar - go to the next entry */
+#define FN_MAILMERGE_EXCLUDE_ENTRY (FN_INSERT + 75) /* mail merge toolbar - checkbox to exclude the current entry */
 
 #define FN_DRAWTEXT_ATTR_DLG    (FN_INSERT + 76)    /* position DrawText */
 
diff --git a/sw/inc/dbui.hrc b/sw/inc/dbui.hrc
index 8aeb2c7..9bb6168 100644
--- a/sw/inc/dbui.hrc
+++ b/sw/inc/dbui.hrc
@@ -81,7 +81,7 @@
 #define ST_LAYOUT               (RC_DBUI_BEGIN + 56)
 #define ST_PREPAREMERGE         (RC_DBUI_BEGIN + 57)
 #define ST_MERGE                (RC_DBUI_BEGIN + 58)
-#define ST_OUTPUT               (RC_DBUI_BEGIN + 59)
+#define ST_EXCLUDE              (RC_DBUI_BEGIN + 59)
 #define ST_FINISH               (RC_DBUI_BEGIN + 60)
 #define ST_ADDRESSLIST          (RC_DBUI_BEGIN + 61)
 
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 2b067fc..fe92ba9 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -5323,6 +5323,30 @@ SfxVoidItem MailMergeLastEntry FN_MAILMERGE_LAST_ENTRY
     GroupId = GID_DOCUMENT;
 ]
 
+SfxVoidItem MailMergeExcludeEntry FN_MAILMERGE_EXCLUDE_ENTRY
+()
+[
+    /* flags: */
+    AutoUpdate = TRUE,
+    Cachable = Cachable,
+    FastCall = TRUE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = TRUE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_DOCUMENT;
+]
+
 SfxVoidItem MailMergeCreateDocuments FN_MAILMERGE_CREATE_DOCUMENTS
 ()
 [
diff --git a/sw/sdi/wrtapp.sdi b/sw/sdi/wrtapp.sdi
index 2a9883f..794f796 100644
--- a/sw/sdi/wrtapp.sdi
+++ b/sw/sdi/wrtapp.sdi
@@ -89,6 +89,11 @@ interface StarWriter
         StateMethod = StateOther ;
     ]
 
+    FN_MAILMERGE_EXCLUDE_ENTRY
+    [
+        StateMethod = StateOther ;
+    ]
+
     FN_MAILMERGE_CREATE_DOCUMENTS
     [
         ExecMethod = ExecOther ;
diff --git a/sw/source/ui/dbui/mailmergewizard.src b/sw/source/ui/dbui/mailmergewizard.src
index 7231ce2..176af67 100644
--- a/sw/source/ui/dbui/mailmergewizard.src
+++ b/sw/source/ui/dbui/mailmergewizard.src
@@ -59,9 +59,9 @@ String ST_MERGE
     Text [ en-US ] = "Personalize document";
 };
 
-String ST_OUTPUT
+String ST_EXCLUDE
 {
-    Text [ en-US ] = "Save, print or send";
+    Text [ en-US ] = "Exclude recipient";
 };
 
 String ST_FINISH
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index ec12358..e8670b4 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -225,6 +225,12 @@ void SwModule::StateOther(SfxItemSet &rSet)
                 }
             }
             break;
+            case FN_MAILMERGE_EXCLUDE_ENTRY:
+            {
+                // just trigger calling statusChanged() of MMExcludeEntryController
+                rSet.InvalidateItem(nWhich);
+            }
+            break;
             case FN_MAILMERGE_CREATE_DOCUMENTS:
             case FN_MAILMERGE_SAVE_DOCUMENTS:
             case FN_MAILMERGE_PRINT_DOCUMENTS:
@@ -784,6 +790,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
             rBindings.Invalidate(FN_MAILMERGE_PREV_ENTRY);
             rBindings.Invalidate(FN_MAILMERGE_NEXT_ENTRY);
             rBindings.Invalidate(FN_MAILMERGE_LAST_ENTRY);
+            rBindings.Invalidate(FN_MAILMERGE_EXCLUDE_ENTRY);
             rBindings.Update();
         }
         break;
diff --git a/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
new file mode 100644
index 0000000..d4dacfb
--- /dev/null
+++ b/sw/source/uibase/dbui/mailmergetoolbarcontrols.cxx
@@ -0,0 +1,176 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cppuhelper/queryinterface.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <svtools/toolboxcontroller.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/button.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/toolbox.hxx>
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+#include <dbui.hrc>
+#include <mmconfigitem.hxx>
+#include <swmodule.hxx>
+#include <view.hxx>
+
+using namespace css;
+
+namespace {
+
+/// Controller for .uno:MailMergeExcludeEntry toolbar checkbox: creates the checkbox & handles the value.
+class MMExcludeEntryController : public svt::ToolboxController, public lang::XServiceInfo
+{
+    VclPtr<CheckBox> m_pExcludeCheckbox;
+
+    DECL_LINK_TYPED(ExcludeHdl, CheckBox&, void);
+
+public:
+    MMExcludeEntryController(const uno::Reference<uno::XComponentContext>& rContext)
+        : svt::ToolboxController(rContext, uno::Reference<frame::XFrame>(), OUString(".uno:MailMergeExcludeEntry"))
+        , m_pExcludeCheckbox(nullptr)
+    {
+    }
+
+    virtual ~MMExcludeEntryController()
+    {
+    }
+
+    // XInterface
+    virtual uno::Any SAL_CALL queryInterface(const uno::Type& aType) throw (uno::RuntimeException, std::exception) override
+    {
+        uno::Any a(ToolboxController::queryInterface(aType));
+        if (a.hasValue())
+            return a;
+
+        return ::cppu::queryInterface(aType, static_cast<lang::XServiceInfo*>(this));
+    }
+
+    void SAL_CALL acquire() throw ()
+    {
+        ToolboxController::acquire();
+    }
+
+    void SAL_CALL release() throw ()
+    {
+        ToolboxController::release();
+    }
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) override
+    {
+        return OUString("lo.writer.MMExcludeEntryController");
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) throw (uno::RuntimeException, std::exception) override
+    {
+        return cppu::supportsService(this, rServiceName);
+    }
+
+    virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) override
+    {
+        uno::Sequence<OUString> aServices { "com.sun.star.frame.ToolbarController" };
+        return aServices;
+    }
+
+    // XComponent
+    virtual void SAL_CALL dispose() throw (uno::RuntimeException, std::exception) override;
+
+    // XInitialization
+    virtual void SAL_CALL initialize(const uno::Sequence< uno::Any >& aArguments) throw (uno::Exception, uno::RuntimeException, std::exception) override;
+
+    // XToolbarController
+    virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception) override;
+
+    // XStatusListener
+    virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception) override;
+};
+
+void MMExcludeEntryController::dispose() throw (uno::RuntimeException, std::exception)
+{
+    SolarMutexGuard aSolarMutexGuard;
+
+    svt::ToolboxController::dispose();
+    m_pExcludeCheckbox.disposeAndClear();
+}
+
+void MMExcludeEntryController::initialize(const uno::Sequence< uno::Any >& aArguments) throw (uno::Exception, uno::RuntimeException, std::exception)
+{
+    svt::ToolboxController::initialize(aArguments);
+}
+
+uno::Reference<awt::XWindow> MMExcludeEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent) throw (uno::RuntimeException, std::exception)
+{
+    vcl::Window* pParent = VCLUnoHelper::GetWindow(rParent);
+    ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent);
+    if (pToolbar)
+    {
+        // make it visible
+        m_pExcludeCheckbox = VclPtr<CheckBox>::Create(pToolbar);
+        m_pExcludeCheckbox->SetText(SW_RES(ST_EXCLUDE));
+        m_pExcludeCheckbox->SetSizePixel(m_pExcludeCheckbox->GetOptimalSize());
+
+        m_pExcludeCheckbox->SetToggleHdl(LINK(this, MMExcludeEntryController, ExcludeHdl));
+    }
+
+    return uno::Reference<awt::XWindow>(VCLUnoHelper::GetInterface(m_pExcludeCheckbox));
+}
+
+IMPL_LINK_TYPED(MMExcludeEntryController, ExcludeHdl, CheckBox&, rCheckbox, void)
+{
+    SwView* pView = ::GetActiveView();
+    SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem();
+
+    if (pConfigItem)
+        pConfigItem->ExcludeRecord(pConfigItem->GetResultSetPosition(), rCheckbox.IsChecked());
+};
+
+void MMExcludeEntryController::statusChanged(const frame::FeatureStateEvent& rEvent) throw (uno::RuntimeException, std::exception)
+{
+    if (!m_pExcludeCheckbox)
+        return;
+
+    SwView* pView = ::GetActiveView();
+    SwMailMergeConfigItem* pConfigItem = pView->GetMailMergeConfigItem();
+
+    if (!pConfigItem || !rEvent.IsEnabled)
+    {
+        m_pExcludeCheckbox->Disable();
+        m_pExcludeCheckbox->Check(false);
+    }
+    else
+    {
+        m_pExcludeCheckbox->Enable();
+        m_pExcludeCheckbox->Check(pConfigItem->IsRecordExcluded(pConfigItem->GetResultSetPosition()));
+    }
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface * SAL_CALL
+lo_writer_MMExcludeEntryController_get_implementation(
+    uno::XComponentContext *context,
+    uno::Sequence<uno::Any> const &)
+{
+    return cppu::acquire(new MMExcludeEntryController(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/uiconfig/swform/toolbar/mailmerge.xml b/sw/uiconfig/swform/toolbar/mailmerge.xml
index 7610f2a..61cca36 100644
--- a/sw/uiconfig/swform/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swform/toolbar/mailmerge.xml
@@ -15,6 +15,7 @@
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeCreateDocuments"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeSaveDocuments"/>
diff --git a/sw/uiconfig/swreport/toolbar/mailmerge.xml b/sw/uiconfig/swreport/toolbar/mailmerge.xml
index 7610f2a..61cca36 100644
--- a/sw/uiconfig/swreport/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swreport/toolbar/mailmerge.xml
@@ -15,6 +15,7 @@
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeCreateDocuments"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeSaveDocuments"/>
diff --git a/sw/uiconfig/swriter/toolbar/mailmerge.xml b/sw/uiconfig/swriter/toolbar/mailmerge.xml
index 7610f2a..61cca36 100644
--- a/sw/uiconfig/swriter/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swriter/toolbar/mailmerge.xml
@@ -15,6 +15,7 @@
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeCreateDocuments"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeSaveDocuments"/>
diff --git a/sw/uiconfig/swxform/toolbar/mailmerge.xml b/sw/uiconfig/swxform/toolbar/mailmerge.xml
index 7610f2a..61cca36 100644
--- a/sw/uiconfig/swxform/toolbar/mailmerge.xml
+++ b/sw/uiconfig/swxform/toolbar/mailmerge.xml
@@ -15,6 +15,7 @@
   <toolbar:toolbaritem xlink:href=".uno:MailMergePrevEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeNextEntry"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeLastEntry"/>
+  <toolbar:toolbaritem xlink:href=".uno:MailMergeExcludeEntry"/>
   <toolbar:toolbarseparator/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeCreateDocuments"/>
   <toolbar:toolbaritem xlink:href=".uno:MailMergeSaveDocuments"/>
diff --git a/sw/util/sw.component b/sw/util/sw.component
index 010f41b..ff6b032 100644
--- a/sw/util/sw.component
+++ b/sw/util/sw.component
@@ -27,6 +27,10 @@
     <service name="com.sun.star.sdb.DataAccessDescriptor"/>
     <service name="com.sun.star.text.MailMerge"/>
   </implementation>
+  <implementation name="lo.writer.MMExcludeEntryController"
+      constructor="lo_writer_MMExcludeEntryController_get_implementation">
+    <service name="com.sun.star.frame.ToolbarController"/>
+  </implementation>
   <implementation name="SwXModule" constructor="SwXModule_get_implementation">
     <service name="com.sun.star.text.GlobalSettings"/>
   </implementation>


More information about the Libreoffice-commits mailing list