xref: /core/sfx2/source/dialog/templdlg.cxx (revision ca5c9591)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
21 
22 #include <vcl/commandinfoprovider.hxx>
23 #include <svl/intitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/style.hxx>
26 #include <comphelper/processfactory.hxx>
27 #include <comphelper/propertyvalue.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/frame/ModuleManager.hpp>
31 #include <com/sun/star/frame/UnknownModuleException.hpp>
32 #include <officecfg/Office/Common.hxx>
33 
34 #include <sal/log.hxx>
35 #include <osl/diagnose.h>
36 #include <comphelper/diagnose_ex.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/templdlg.hxx>
41 #include <templdgi.hxx>
42 #include <sfx2/styfitem.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <sfx2/tplpitem.hxx>
45 #include <sfx2/sfxresid.hxx>
46 #include <svl/itemset.hxx>
47 
48 #include <sfx2/sfxsids.hrc>
49 #include <sfx2/strings.hrc>
50 #include <helpids.h>
51 #include <sfx2/viewfrm.hxx>
52 
53 using namespace css;
54 using namespace css::beans;
55 using namespace css::frame;
56 using namespace css::uno;
57 
58 class SfxCommonTemplateDialog_Impl::DeletionWatcher
59 {
60     typedef void (DeletionWatcher::* bool_type)();
61 
62 public:
DeletionWatcher(SfxCommonTemplateDialog_Impl & rDialog)63     explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
64         : m_pDialog(&rDialog)
65         , m_pPrevious(m_pDialog->impl_setDeletionWatcher(this))
66     {
67     }
68 
~DeletionWatcher()69     ~DeletionWatcher()
70     {
71         if (m_pDialog)
72             m_pDialog->impl_setDeletionWatcher(m_pPrevious);
73     }
74 
75     DeletionWatcher(const DeletionWatcher&) = delete;
76     DeletionWatcher& operator=(const DeletionWatcher&) = delete;
77 
78     // Signal that the dialog was deleted
signal()79     void signal()
80     {
81         m_pDialog = nullptr;
82         if (m_pPrevious)
83             m_pPrevious->signal();
84     }
85 
86     // Return true if the dialog was deleted
operator bool_type() const87     operator bool_type() const
88     {
89         return m_pDialog ? nullptr : &DeletionWatcher::signal;
90     }
91 
92 private:
93     SfxCommonTemplateDialog_Impl* m_pDialog;
94     DeletionWatcher *const m_pPrevious; /// let's add more epicycles!
95 };
96 
ExecuteDrop(const ExecuteDropEvent & rEvt)97 sal_Int8 SfxCommonTemplateDialog_Impl::ExecuteDrop(const ExecuteDropEvent& rEvt)
98 {
99     // handle drop of content into the treeview to create a new style
100     m_aStyleListExecuteDrop.Call(rEvt);
101     return DND_ACTION_NONE;
102 }
103 
IMPL_LINK(SfxCommonTemplateDialog_Impl,OnAsyncExecuteDrop,void *,pStyleList,void)104 IMPL_LINK(SfxCommonTemplateDialog_Impl, OnAsyncExecuteDrop, void*, pStyleList, void)
105 {
106     StyleList* pStyle = static_cast<StyleList*>(pStyleList);
107     if (pStyle == &m_aStyleList)
108         ActionSelect(u"new"_ustr, m_aStyleList);
109 }
110 
111 namespace SfxTemplate
112 {
113     // converts from SFX_STYLE_FAMILY Ids to 1-6
SfxFamilyIdToNId(SfxStyleFamily nFamily)114     static sal_uInt16 SfxFamilyIdToNId(SfxStyleFamily nFamily)
115     {
116         switch ( nFamily )
117         {
118             case SfxStyleFamily::Char:   return 1;
119             case SfxStyleFamily::Para:   return 2;
120             case SfxStyleFamily::Frame:  return 3;
121             case SfxStyleFamily::Page:   return 4;
122             case SfxStyleFamily::Pseudo: return 5;
123             case SfxStyleFamily::Table:  return 6;
124             default:                     return 0xffff;
125         }
126     }
127     // converts from 1-6 to SFX_STYLE_FAMILY Ids
NIdToSfxFamilyId(sal_uInt16 nId)128     static SfxStyleFamily NIdToSfxFamilyId(sal_uInt16 nId)
129     {
130         switch (nId)
131         {
132             case 1:
133                 return SfxStyleFamily::Char;
134             case 2:
135                 return SfxStyleFamily::Para;
136             case 3:
137                 return SfxStyleFamily::Frame;
138             case 4:
139                 return SfxStyleFamily::Page;
140             case 5:
141                 return SfxStyleFamily::Pseudo;
142             case 6:
143                 return SfxStyleFamily::Table;
144             default:
145                 return SfxStyleFamily::All;
146         }
147     }
148 }
149 
SfxTemplatePanelControl(SfxBindings * pBindings,weld::Widget * pParent)150 SfxTemplatePanelControl::SfxTemplatePanelControl(SfxBindings* pBindings, weld::Widget* pParent)
151     : PanelLayout(pParent, u"TemplatePanel"_ustr, u"sfx/ui/templatepanel.ui"_ustr)
152     , m_aSpotlightParaStyles(SID_SPOTLIGHT_PARASTYLES, *pBindings, *this)
153     , m_aSpotlightCharStyles(SID_SPOTLIGHT_CHARSTYLES, *pBindings, *this)
154     , pImpl(new SfxTemplateDialog_Impl(pBindings, this))
155 {
156     OSL_ASSERT(pBindings!=nullptr);
157 }
158 
~SfxTemplatePanelControl()159 SfxTemplatePanelControl::~SfxTemplatePanelControl()
160 {
161     m_aSpotlightParaStyles.dispose();
162     m_aSpotlightCharStyles.dispose();
163 }
164 
NotifyItemUpdate(const sal_uInt16 nSId,const SfxItemState eState,const SfxPoolItem * pState)165 void SfxTemplatePanelControl::NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState,
166                                                const SfxPoolItem* pState)
167 {
168     switch (nSId)
169     {
170         case SID_SPOTLIGHT_PARASTYLES:
171             if (eState >= SfxItemState::DEFAULT)
172             {
173                 const SfxBoolItem* pItem = dynamic_cast<const SfxBoolItem*>(pState);
174                 if (pItem)
175                 {
176                     bool bValue = pItem->GetValue();
177                     if (bValue || (!bValue && pImpl->m_aStyleList.IsHighlightParaStyles()))
178                     {
179                         pImpl->m_aStyleList.SetHighlightParaStyles(bValue);
180                         pImpl->FamilySelect(SfxTemplate::SfxFamilyIdToNId(SfxStyleFamily::Para),
181                                             pImpl->m_aStyleList, true);
182                     }
183                 }
184             }
185             break;
186         case SID_SPOTLIGHT_CHARSTYLES:
187             if (eState >= SfxItemState::DEFAULT)
188             {
189                 const SfxBoolItem* pItem = dynamic_cast<const SfxBoolItem*>(pState);
190                 if (pItem)
191                 {
192                     bool bValue = pItem->GetValue();
193                     if (bValue || (!bValue && pImpl->m_aStyleList.IsHighlightCharStyles()))
194                     {
195                         pImpl->m_aStyleList.SetHighlightCharStyles(bValue);
196                         pImpl->FamilySelect(SfxTemplate::SfxFamilyIdToNId(SfxStyleFamily::Char),
197                                             pImpl->m_aStyleList, true);
198                     }
199                 }
200             }
201             break;
202     }
203 }
204 
connect_stylelist_execute_drop(const Link<const ExecuteDropEvent &,sal_Int8> & rLink)205 void SfxCommonTemplateDialog_Impl::connect_stylelist_execute_drop(
206     const Link<const ExecuteDropEvent&, sal_Int8>& rLink)
207 {
208     m_aStyleListExecuteDrop = rLink;
209 }
210 
connect_stylelist_has_selected_style(const Link<void *,bool> & rLink)211 void SfxCommonTemplateDialog_Impl::connect_stylelist_has_selected_style(const Link<void*, bool>& rLink)
212 {
213     m_aStyleListHasSelectedStyle = rLink;
214 }
215 
connect_stylelist_update_style_dependents(const Link<void *,void> & rLink)216 void SfxCommonTemplateDialog_Impl::connect_stylelist_update_style_dependents(const Link<void*, void>& rLink)
217 {
218     m_aStyleListUpdateStyleDependents = rLink;
219 }
220 
connect_stylelist_enable_tree_drag(const Link<bool,void> rLink)221 void SfxCommonTemplateDialog_Impl::connect_stylelist_enable_tree_drag(const Link<bool, void> rLink)
222 {
223     m_aStyleListEnableTreeDrag = rLink;
224 }
225 
connect_stylelist_enable_delete(const Link<void *,void> rLink)226 void SfxCommonTemplateDialog_Impl::connect_stylelist_enable_delete(const Link<void*, void> rLink)
227 {
228     m_aStyleListEnableDelete = rLink;
229 }
230 
connect_stylelist_set_water_can_state(const Link<const SfxBoolItem *,void> rLink)231 void SfxCommonTemplateDialog_Impl::connect_stylelist_set_water_can_state(
232     const Link<const SfxBoolItem*, void> rLink)
233 {
234     m_aStyleListSetWaterCanState = rLink;
235 }
236 
237 // Constructor
238 
SfxCommonTemplateDialog_Impl(SfxBindings * pB,weld::Container * pC,weld::Builder * pBuilder)239 SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl(SfxBindings* pB, weld::Container* pC, weld::Builder* pBuilder)
240     : pBindings(pB)
241     , xModuleManager(frame::ModuleManager::create(::comphelper::getProcessComponentContext()))
242     , m_pDeletionWatcher(nullptr)
243     , m_aStyleList(pBuilder, pB, this, pC, u"treeview"_ustr, u"flatview"_ustr)
244     , mxPreviewCheckbox(pBuilder->weld_check_button(u"showpreview"_ustr))
245     , mxHighlightCheckbox(pBuilder->weld_check_button(u"highlightstyles"_ustr))
246     , mxFilterLb(pBuilder->weld_combo_box(u"filter"_ustr))
247     , nActFamily(0xffff)
248     , nActFilter(0)
249     , bIsWater(false)
250     , bUpdate(false)
251     , bWaterDisabled(false)
252     , bNewByExampleDisabled(false)
253     , bUpdateByExampleDisabled(false)
254     , m_bWantHierarchical(false)
255 {
256     mxFilterLb->set_help_id(HID_TEMPLATE_FILTER);
257     mxPreviewCheckbox->set_active(officecfg::Office::Common::StylesAndFormatting::Preview::get());
258 }
259 
EnableEdit(bool bEnable,StyleList * rStyleList)260 void SfxTemplateDialog_Impl::EnableEdit(bool bEnable, StyleList* rStyleList)
261 {
262     if(rStyleList == &m_aStyleList || rStyleList == nullptr)
263         SfxCommonTemplateDialog_Impl::EnableEdit( bEnable, &m_aStyleList );
264     if( !bEnable || !bUpdateByExampleDisabled )
265         EnableItem(u"update"_ustr, bEnable);
266 }
267 
IMPL_LINK(SfxCommonTemplateDialog_Impl,ReadResource_Hdl,StyleList &,rStyleList,void)268 IMPL_LINK(SfxCommonTemplateDialog_Impl, ReadResource_Hdl, StyleList&, rStyleList, void)
269 {
270     nActFilter = 0xffff;
271 
272     SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
273     SfxObjectShell* pCurObjShell = pViewFrame->GetObjectShell();
274     if (pCurObjShell)
275     {
276         nActFilter = static_cast<sal_uInt16>(LoadFactoryStyleFilter_Hdl(pCurObjShell));
277         if (0xffff == nActFilter)
278         {
279             nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
280         }
281     }
282 
283     size_t nCount = m_aStyleListReadResource.Call(nullptr);
284 
285 // Insert in the reverse order of occurrence in the Style Families. This is for
286 // the toolbar of the designer. The list box of the catalog respects the
287 // correct order by itself.
288 
289 // Sequences: the order of Resource = the order of Toolbar for example list box.
290 // Order of ascending SIDs: Low SIDs are displayed first when templates of
291 // several families are active.
292 
293     // in the Writer the UpdateStyleByExample Toolbox button is removed and
294     // the NewStyle button gets a PopupMenu
295     if(nCount > 4)
296         ReplaceUpdateButtonByMenu();
297 
298     for( ; nCount--; )
299     {
300         const SfxStyleFamilyItem &rItem = rStyleList.GetFamilyItemByIndex( nCount );
301         sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId( rItem.GetFamily() );
302         InsertFamilyItem(nId, rItem);
303     }
304 }
305 
IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl,ClearResource_Hdl,void *,void)306 IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl, ClearResource_Hdl, void*, void)
307 {
308     ClearFamilyList();
309     m_aStyleListClear.Call(nullptr);
310 }
311 
312 SfxCommonTemplateDialog_Impl::DeletionWatcher *
impl_setDeletionWatcher(DeletionWatcher * const pNewWatcher)313 SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(
314         DeletionWatcher *const pNewWatcher)
315 {
316     DeletionWatcher *const pRet(m_pDeletionWatcher);
317     m_pDeletionWatcher = pNewWatcher;
318     return pRet;
319 }
320 
Initialize()321 void SfxCommonTemplateDialog_Impl::Initialize()
322 {
323     m_aStyleList.connect_ReadResource(LINK(this, SfxCommonTemplateDialog_Impl, ReadResource_Hdl));
324     m_aStyleList.connect_ClearResource(LINK(this, SfxCommonTemplateDialog_Impl, ClearResource_Hdl));
325     m_aStyleList.connect_LoadFactoryStyleFilter(LINK(this, SfxCommonTemplateDialog_Impl, LoadFactoryStyleFilter_Hdl));
326     m_aStyleList.connect_SaveSelection(LINK(this, SfxCommonTemplateDialog_Impl, SaveSelection_Hdl));
327     m_aStyleList.connect_UpdateFamily(LINK(this, SfxCommonTemplateDialog_Impl, UpdateFamily_Hdl));
328     m_aStyleList.connect_UpdateStyles(LINK(this, SfxCommonTemplateDialog_Impl, UpdateStyles_Hdl));
329 
330     mxFilterLb->connect_changed(LINK(this, SfxCommonTemplateDialog_Impl, FilterSelectHdl));
331     mxPreviewCheckbox->connect_toggled(LINK(this, SfxCommonTemplateDialog_Impl, PreviewHdl));
332     mxHighlightCheckbox->connect_toggled(LINK(this, SfxCommonTemplateDialog_Impl, HighlightHdl));
333 
334     m_aStyleList.Initialize();
335 
336     SfxStyleFamily eFam = SfxTemplate::NIdToSfxFamilyId(nActFamily);
337     mxHighlightCheckbox->set_visible(m_aStyleList.HasStylesHighlighterFeature()
338                                 && (eFam == SfxStyleFamily::Para || eFam == SfxStyleFamily::Char));
339 }
340 
IMPL_LINK(SfxCommonTemplateDialog_Impl,UpdateStyles_Hdl,StyleFlags,nFlags,void)341 IMPL_LINK(SfxCommonTemplateDialog_Impl, UpdateStyles_Hdl, StyleFlags, nFlags, void)
342 {
343     const SfxStyleFamilyItem* pItem = m_aStyleList.GetFamilyItem();
344 
345     if (nFlags & StyleFlags::UpdateFamily) // Update view type list (Hierarchical, All, etc.
346     {
347         CheckItem(OUString::number(nActFamily)); // check Button in Toolbox
348 
349         mxFilterLb->freeze();
350         mxFilterLb->clear();
351 
352         //insert hierarchical at the beginning
353         mxFilterLb->append(OUString::number(static_cast<int>(SfxStyleSearchBits::All)),
354                            SfxResId(STR_STYLE_FILTER_HIERARCHICAL));
355         const SfxStyleFilter& rFilter = pItem->GetFilterList();
356         for (const SfxFilterTuple& i : rFilter)
357             mxFilterLb->append(OUString::number(static_cast<int>(i.nFlags)), i.aName);
358         mxFilterLb->thaw();
359 
360         if (nActFilter < mxFilterLb->get_count() - 1)
361             mxFilterLb->set_active(nActFilter + 1);
362         else
363         {
364             nActFilter = 0;
365             m_aStyleList.FilterSelect(nActFilter, false);
366             mxFilterLb->set_active(1);
367         }
368 
369         // if the tree view again, select family hierarchy
370         if (m_aStyleList.IsTreeView() || m_bWantHierarchical)
371         {
372             mxFilterLb->set_active_text(SfxResId(STR_STYLE_FILTER_HIERARCHICAL));
373             EnableHierarchical(true, m_aStyleList);
374         }
375     }
376     else
377     {
378         if (nActFilter < mxFilterLb->get_count() - 1)
379             mxFilterLb->set_active(nActFilter + 1);
380         else
381         {
382             nActFilter = 0;
383             m_aStyleList.FilterSelect(nActFilter, false);
384             mxFilterLb->set_active(1);
385         }
386     }
387 
388     if (!(nFlags & StyleFlags::UpdateFamilyList))
389         return;
390 
391     EnableItem(u"watercan"_ustr, false);
392 }
393 
~SfxCommonTemplateDialog_Impl()394 SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
395 {
396     // Set the UNO's in an 'off' state. FN_PARAM_1 is used to prevent the sidebar from trying to
397     // reopen while it is being closed here.
398     if (m_aStyleList.IsHighlightParaStyles())
399     {
400         SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
401         SfxFlagItem aParam(FN_PARAM_1);
402         rDispatcher.ExecuteList(SID_SPOTLIGHT_PARASTYLES, SfxCallMode::SYNCHRON, { &aParam });
403     }
404     if (m_aStyleList.IsHighlightCharStyles())
405     {
406         SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
407         SfxFlagItem aParam(FN_PARAM_1);
408         rDispatcher.ExecuteList(SID_SPOTLIGHT_CHARSTYLES, SfxCallMode::SYNCHRON, { &aParam });
409     }
410 
411     if ( bIsWater )
412         Execute_Impl(SID_STYLE_WATERCAN, u""_ustr, u""_ustr, 0, m_aStyleList);
413     m_aStyleListClear.Call(nullptr);
414     m_aStyleListCleanup.Call(nullptr);
415     if ( m_pDeletionWatcher )
416         m_pDeletionWatcher->signal();
417     mxPreviewCheckbox.reset();
418     mxFilterLb.reset();
419 }
420 
421 /**
422  * Is it safe to show the water-can / fill icon. If we've a
423  * hierarchical widget - we have only single select, otherwise
424  * we need to check if we have a multi-selection. We either have
425  * a mxTreeBox showing or an mxFmtLb (which we hide when not shown)
426  */
IsSafeForWaterCan() const427 bool SfxCommonTemplateDialog_Impl::IsSafeForWaterCan() const
428 {
429     return m_aStyleListWaterCan.Call(nullptr);
430 }
431 
SelectStyle(const OUString & rStr,bool bIsCallback,StyleList & rStyleList)432 void SfxCommonTemplateDialog_Impl::SelectStyle(const OUString &rStr, bool bIsCallback, StyleList& rStyleList)
433 {
434     rStyleList.SelectStyle(rStr, bIsCallback);
435 
436     bWaterDisabled = !IsSafeForWaterCan();
437 
438     // tdf#134598 call UpdateStyleDependents to update watercan
439     UpdateStyleDependents_Hdl(nullptr);
440 }
441 
EnableTreeDrag(bool bEnable)442 void SfxCommonTemplateDialog_Impl::EnableTreeDrag(bool bEnable)
443 {
444     m_aStyleListEnableTreeDrag.Call(bEnable);
445 }
446 
447 // Updated display: Watering the house
SetWaterCanState(const SfxBoolItem * pItem)448 void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
449 {
450     bWaterDisabled = (pItem == nullptr);
451 
452     if(!bWaterDisabled)
453         //make sure the watercan is only activated when there is (only) one selection
454         bWaterDisabled = !IsSafeForWaterCan();
455 
456     if(pItem && !bWaterDisabled)
457     {
458         CheckItem(u"watercan"_ustr, pItem->GetValue());
459         EnableItem(u"watercan"_ustr);
460     }
461     else
462     {
463         if(!bWaterDisabled)
464             EnableItem(u"watercan"_ustr);
465         else
466             EnableItem(u"watercan"_ustr, false);
467     }
468 
469 // Ignore while in watercan mode statusupdates
470 
471     m_aStyleListSetWaterCanState.Call(pItem);
472 }
473 
474 // Item with the status of a Family is copied and noted
475 // (is updated when all states have also been updated.)
476 // See also: <SfxBindings::AddDoneHdl(const Link &)>
SetFamilyState(sal_uInt16 nSlotId,const SfxTemplateItem * pItem)477 void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
478 {
479     m_aStyleList.SetFamilyState(nSlotId, pItem);
480     bUpdate = true;
481 }
482 
483 // Internal: Perform functions through the Dispatcher
Execute_Impl(sal_uInt16 nId,const OUString & rStr,const OUString & rRefStr,sal_uInt16 nFamily,StyleList & rStyleList,SfxStyleSearchBits nMask,sal_uInt16 * pIdx,const sal_uInt16 * pModifier)484 bool SfxCommonTemplateDialog_Impl::Execute_Impl(
485     sal_uInt16 nId, const OUString &rStr, const OUString& rRefStr, sal_uInt16 nFamily, StyleList& rStyleList,
486     SfxStyleSearchBits nMask, sal_uInt16 *pIdx, const sal_uInt16* pModifier)
487 {
488     SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
489     SfxStringItem aItem(nId, rStr);
490     SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
491     SfxUInt16Item aMask( SID_STYLE_MASK, static_cast<sal_uInt16>(nMask) );
492     SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
493     SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
494     const SfxPoolItem* pItems[ 6 ];
495     sal_uInt16 nCount = 0;
496     if( !rStr.isEmpty() )
497         pItems[ nCount++ ] = &aItem;
498     pItems[ nCount++ ] = &aFamily;
499     if( nMask != SfxStyleSearchBits::Auto )
500         pItems[ nCount++ ] = &aMask;
501     if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
502     {
503         // Special solution for Numbering update in Writer
504         const OUString aTemplName(rStyleList.GetSelectedEntry());
505         aUpdName.SetValue(aTemplName);
506         pItems[ nCount++ ] = &aUpdName;
507     }
508 
509     if ( !rRefStr.isEmpty() )
510         pItems[ nCount++ ] = &aRefName;
511 
512     pItems[ nCount++ ] = nullptr;
513 
514     DeletionWatcher aDeleted(*this);
515     sal_uInt16 nModi = pModifier ? *pModifier : 0;
516     const SfxPoolItemHolder aResult(rDispatcher.Execute(
517         nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
518         pItems, nModi));
519 
520     // Dialog can be destroyed while in Execute() because started
521     // subdialogs are not modal to it (#i97888#).
522     if (!aResult || aDeleted )
523         return false;
524 
525     if ((nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId)
526         && rStyleList.EnableExecute())
527     {
528         const SfxUInt16Item* pFilterItem(dynamic_cast<const SfxUInt16Item*>(aResult.getItem()));
529         assert(pFilterItem);
530         SfxStyleSearchBits nFilterFlags = static_cast<SfxStyleSearchBits>(pFilterItem->GetValue()) & ~SfxStyleSearchBits::UserDefined;
531         if(nFilterFlags == SfxStyleSearchBits::Auto)       // User Template?
532             nFilterFlags = static_cast<SfxStyleSearchBits>(pFilterItem->GetValue());
533         const SfxStyleFamilyItem *pFamilyItem = rStyleList.GetFamilyItem();
534         const size_t nFilterCount = pFamilyItem->GetFilterList().size();
535 
536         for ( size_t i = 0; i < nFilterCount; ++i )
537         {
538             const SfxFilterTuple &rTupel = pFamilyItem->GetFilterList()[ i ];
539 
540             if ( ( rTupel.nFlags & nFilterFlags ) == nFilterFlags && pIdx )
541                 *pIdx = i;
542         }
543     }
544 
545     return true;
546 }
547 
548 // Handler Listbox of Filter
EnableHierarchical(bool const bEnable,StyleList & rStyleList)549 void SfxCommonTemplateDialog_Impl::EnableHierarchical(bool const bEnable, StyleList& rStyleList)
550 {
551     OUString aSelectedEntry = rStyleList.GetSelectedEntry();
552     if (bEnable)
553     {
554         if (!rStyleList.IsHierarchical())
555         {
556             // Turn on treeView
557             m_bWantHierarchical = true;
558             SaveSelection_Hdl(rStyleList); // fdo#61429 store "hierarchical"
559             m_aStyleList.SetHierarchical();
560         }
561     }
562     else
563     {
564         m_aStyleList.SetFilterControlsHandle();
565         // If bHierarchical, then the family can have changed
566         // minus one since hierarchical is inserted at the start
567         m_bWantHierarchical = false; // before FilterSelect
568         FilterSelect(mxFilterLb->get_active() - 1);
569     }
570     SelectStyle(aSelectedEntry, false, rStyleList);
571 }
572 
573 // Other filters; can be switched by the users or as a result of new or
574 // editing, if the current document has been assigned a different filter.
FilterSelect(sal_uInt16 nEntry)575 void SfxCommonTemplateDialog_Impl::FilterSelect(
576     sal_uInt16 nEntry // Idx of the new Filters
577     )
578 {
579     nActFilter = nEntry;
580     m_aStyleList.FilterSelect(nActFilter, true);
581 }
582 
IsUpdate(StyleList &)583 void SfxCommonTemplateDialog_Impl::IsUpdate(StyleList&)
584 {
585     SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
586     SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
587     nActFilter = static_cast<sal_uInt16>(LoadFactoryStyleFilter_Hdl(pDocShell));
588     if (0xffff == nActFilter)
589     {
590         nActFilter = pDocShell->GetAutoStyleFilterIndex();
591     }
592 }
593 
IMPL_LINK(SfxCommonTemplateDialog_Impl,FilterSelectHdl,weld::ComboBox &,rBox,void)594 IMPL_LINK(SfxCommonTemplateDialog_Impl, FilterSelectHdl, weld::ComboBox&, rBox, void)
595 {
596     if (SfxResId(STR_STYLE_FILTER_HIERARCHICAL) == rBox.get_active_text())
597     {
598         EnableHierarchical(true, m_aStyleList);
599     }
600     else
601     {
602         EnableHierarchical(false, m_aStyleList);
603     }
604 }
605 
606 // Select-Handler for the Toolbox
FamilySelect(sal_uInt16 nEntry,StyleList &,bool bRefresh)607 void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry, StyleList&, bool bRefresh)
608 {
609     assert((0 < nEntry && nEntry <= MAX_FAMILIES) || 0xffff == nEntry);
610     if( nEntry != nActFamily || bRefresh )
611     {
612         CheckItem(OUString::number(nActFamily), false);
613         nActFamily = nEntry;
614         m_aStyleList.FamilySelect(nEntry, bRefresh);
615 
616         SfxStyleFamily eFam = SfxTemplate::NIdToSfxFamilyId(nActFamily);
617         mxHighlightCheckbox->set_visible(m_aStyleList.HasStylesHighlighterFeature()
618                                 && (eFam == SfxStyleFamily::Para || eFam == SfxStyleFamily::Char));
619         if (mxHighlightCheckbox->is_visible())
620         {
621             bool bActive = false;
622             if (eFam == SfxStyleFamily::Para)
623                 bActive = m_aStyleList.IsHighlightParaStyles();
624             else if (eFam == SfxStyleFamily::Char)
625                 bActive = m_aStyleList.IsHighlightCharStyles();
626             mxHighlightCheckbox->set_active(bActive);
627         }
628     }
629 }
630 
ActionSelect(const OUString & rEntry,StyleList & rStyleList)631 void SfxCommonTemplateDialog_Impl::ActionSelect(const OUString& rEntry, StyleList& rStyleList)
632 {
633     if (rEntry == "watercan")
634     {
635         const bool bOldState = !IsCheckedItem(rEntry);
636         bool bCheck;
637         SfxBoolItem aBool;
638         // when a template is chosen.
639         if (!bOldState && m_aStyleListHasSelectedStyle.Call(nullptr))
640         {
641             const OUString aTemplName(rStyleList.GetSelectedEntry());
642             Execute_Impl(SID_STYLE_WATERCAN, aTemplName, u""_ustr,
643                          static_cast<sal_uInt16>(m_aStyleList.GetFamilyItem()->GetFamily()), rStyleList);
644             bCheck = true;
645         }
646         else
647         {
648             Execute_Impl(SID_STYLE_WATERCAN, u""_ustr, u""_ustr, 0, rStyleList);
649             bCheck = false;
650         }
651         CheckItem(rEntry, bCheck);
652         aBool.SetValue(bCheck);
653         SetWaterCanState(&aBool);
654     }
655     else if (rEntry == "new" || rEntry == "newmenu")
656     {
657         m_aStyleListNewMenu.Call(nullptr);
658     }
659     else if (rEntry == "update")
660     {
661         Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
662                 u""_ustr, u""_ustr,
663                 static_cast<sal_uInt16>(m_aStyleList.GetFamilyItem()->GetFamily()), rStyleList);
664     }
665     else if (rEntry == "load")
666         SfxGetpApp()->GetDispatcher_Impl()->Execute(SID_TEMPLATE_LOAD);
667     else
668         SAL_WARN("sfx", "not implemented: " << rEntry);
669 }
670 
getModuleIdentifier(const Reference<XModuleManager2> & i_xModMgr,SfxObjectShell const * i_pObjSh)671 static OUString getModuleIdentifier( const Reference< XModuleManager2 >& i_xModMgr, SfxObjectShell const * i_pObjSh )
672 {
673     assert(i_xModMgr.is() && "getModuleIdentifier(): no XModuleManager");
674     assert(i_pObjSh && "getModuleIdentifier(): no ObjectShell");
675 
676     OUString sIdentifier;
677 
678     try
679     {
680         sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
681     }
682     catch ( css::frame::UnknownModuleException& )
683     {
684         SAL_WARN("sfx", "getModuleIdentifier(): unknown module" );
685     }
686     catch ( Exception& )
687     {
688         TOOLS_WARN_EXCEPTION( "sfx", "getModuleIdentifier(): exception of XModuleManager::identify()" );
689     }
690 
691     return sIdentifier;
692 }
693 
IMPL_LINK(SfxCommonTemplateDialog_Impl,LoadFactoryStyleFilter_Hdl,SfxObjectShell const *,i_pObjSh,sal_Int32)694 IMPL_LINK(SfxCommonTemplateDialog_Impl, LoadFactoryStyleFilter_Hdl, SfxObjectShell const*, i_pObjSh, sal_Int32)
695 {
696     OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
697 
698     ::comphelper::SequenceAsHashMap aFactoryProps(
699         xModuleManager->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
700     sal_Int32 nFilter = aFactoryProps.getUnpackedValueOrDefault( u"ooSetupFactoryStyleFilter"_ustr, sal_Int32(-1) );
701 
702     m_bWantHierarchical = (nFilter & 0x1000) != 0;
703     nFilter &= ~0x1000; // clear it
704 
705     return nFilter;
706 }
707 
SaveFactoryStyleFilter(SfxObjectShell const * i_pObjSh,sal_Int32 i_nFilter)708 void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell const * i_pObjSh, sal_Int32 i_nFilter )
709 {
710     OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
711     Sequence< PropertyValue > lProps{ comphelper::makePropertyValue(
712         u"ooSetupFactoryStyleFilter"_ustr, i_nFilter | (m_bWantHierarchical ? 0x1000 : 0)) };
713     xModuleManager->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), Any( lProps ) );
714 }
715 
IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl,SaveSelection_Hdl,StyleList &,SfxObjectShell *)716 IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl, SaveSelection_Hdl, StyleList&, SfxObjectShell*)
717 {
718     SfxViewFrame *const pViewFrame(pBindings->GetDispatcher_Impl()->GetFrame());
719     SfxObjectShell *const pDocShell(pViewFrame->GetObjectShell());
720     if (pDocShell)
721     {
722         pDocShell->SetAutoStyleFilterIndex(nActFilter);
723         SaveFactoryStyleFilter( pDocShell, nActFilter );
724     }
725     return pDocShell;
726 }
727 
IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl,PreviewHdl,weld::Toggleable &,void)728 IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl, PreviewHdl, weld::Toggleable&, void)
729 {
730     std::shared_ptr<comphelper::ConfigurationChanges> batch( comphelper::ConfigurationChanges::create() );
731     bool bCustomPreview = mxPreviewCheckbox->get_active();
732     officecfg::Office::Common::StylesAndFormatting::Preview::set(bCustomPreview, batch );
733     batch->commit();
734 
735     FamilySelect(nActFamily, m_aStyleList, true);
736 }
737 
IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl,HighlightHdl,weld::Toggleable &,void)738 IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl, HighlightHdl, weld::Toggleable&, void)
739 {
740     SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
741     SfxStyleFamily eFam = SfxTemplate::NIdToSfxFamilyId(nActFamily);
742     if (eFam == SfxStyleFamily::Para)
743        rDispatcher.Execute(SID_SPOTLIGHT_PARASTYLES, SfxCallMode::SYNCHRON);
744     else if (eFam == SfxStyleFamily::Char)
745        rDispatcher.Execute(SID_SPOTLIGHT_CHARSTYLES, SfxCallMode::SYNCHRON);
746 }
747 
IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl,UpdateStyleDependents_Hdl,void *,void)748 IMPL_LINK_NOARG(SfxCommonTemplateDialog_Impl, UpdateStyleDependents_Hdl, void*, void)
749 {
750     m_aStyleListUpdateStyleDependents.Call(nullptr);
751     EnableItem(u"watercan"_ustr, !bWaterDisabled);
752     m_aStyleListEnableDelete.Call(nullptr);
753 }
754 
EnableExample_Impl(sal_uInt16 nId,bool bEnable)755 void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, bool bEnable)
756 {
757     bool bDisable = !bEnable || !IsSafeForWaterCan();
758     if (nId == SID_STYLE_NEW_BY_EXAMPLE)
759     {
760         bNewByExampleDisabled = bDisable;
761         m_aStyleList.EnableNewByExample(bNewByExampleDisabled);
762         EnableItem(u"new"_ustr, bEnable);
763         EnableItem(u"newmenu"_ustr, bEnable);
764     }
765     else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
766     {
767         bUpdateByExampleDisabled = bDisable;
768         EnableItem(u"update"_ustr, bEnable);
769     }
770 }
771 
772 class ToolbarDropTarget final : public DropTargetHelper
773 {
774 private:
775     SfxTemplateDialog_Impl& m_rParent;
776 
777 public:
ToolbarDropTarget(SfxTemplateDialog_Impl & rDialog,weld::Toolbar & rToolbar)778     ToolbarDropTarget(SfxTemplateDialog_Impl& rDialog, weld::Toolbar& rToolbar)
779         : DropTargetHelper(rToolbar.get_drop_target())
780         , m_rParent(rDialog)
781     {
782     }
783 
AcceptDrop(const AcceptDropEvent & rEvt)784     virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override
785     {
786         return m_rParent.AcceptToolbarDrop(rEvt, *this);
787     }
788 
ExecuteDrop(const ExecuteDropEvent & rEvt)789     virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
790     {
791         return m_rParent.ExecuteDrop(rEvt);
792     }
793 };
794 
SfxTemplateDialog_Impl(SfxBindings * pB,SfxTemplatePanelControl * pDlgWindow)795 SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(SfxBindings* pB, SfxTemplatePanelControl* pDlgWindow)
796     : SfxCommonTemplateDialog_Impl(pB, pDlgWindow->get_container(), pDlgWindow->get_builder())
797     , m_xActionTbL(pDlgWindow->get_builder()->weld_toolbar(u"left"_ustr))
798     , m_xActionTbR(pDlgWindow->get_builder()->weld_toolbar(u"right"_ustr))
799     , m_xToolMenu(pDlgWindow->get_builder()->weld_menu(u"toolmenu"_ustr))
800     , m_nActionTbLVisible(0)
801 {
802     m_xActionTbR->set_item_help_id(u"watercan"_ustr, HID_TEMPLDLG_WATERCAN);
803     // shown/hidden in SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
804     m_xActionTbR->set_item_help_id(u"new"_ustr, HID_TEMPLDLG_NEWBYEXAMPLE);
805     m_xActionTbR->set_item_help_id(u"newmenu"_ustr, HID_TEMPLDLG_NEWBYEXAMPLE);
806     m_xActionTbR->set_item_menu(u"newmenu"_ustr, m_xToolMenu.get());
807     m_xToolMenu->connect_activate(LINK(this, SfxTemplateDialog_Impl, ToolMenuSelectHdl));
808     m_xActionTbR->set_item_help_id(u"update"_ustr, HID_TEMPLDLG_UPDATEBYEXAMPLE);
809 
810     Initialize();
811 }
812 
Initialize()813 void SfxTemplateDialog_Impl::Initialize()
814 {
815     SfxCommonTemplateDialog_Impl::Initialize();
816 
817     m_xActionTbL->connect_clicked(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
818     m_xActionTbR->connect_clicked(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
819     m_xActionTbL->set_help_id(HID_TEMPLDLG_TOOLBOX_LEFT);
820 
821     m_xToolbarDropTargetHelper.reset(new ToolbarDropTarget(*this, *m_xActionTbL));
822 }
823 
EnableFamilyItem(sal_uInt16 nId,bool bEnable)824 void SfxTemplateDialog_Impl::EnableFamilyItem(sal_uInt16 nId, bool bEnable)
825 {
826     m_xActionTbL->set_item_sensitive(OUString::number(nId), bEnable);
827 }
828 
829 // Insert element into dropdown filter "Frame Styles", "List Styles", etc.
InsertFamilyItem(sal_uInt16 nId,const SfxStyleFamilyItem & rItem)830 void SfxTemplateDialog_Impl::InsertFamilyItem(sal_uInt16 nId, const SfxStyleFamilyItem &rItem)
831 {
832     OUString sHelpId;
833     switch( rItem.GetFamily() )
834     {
835         case SfxStyleFamily::Char:     sHelpId = ".uno:CharStyle"; break;
836         case SfxStyleFamily::Para:     sHelpId = ".uno:ParaStyle"; break;
837         case SfxStyleFamily::Frame:    sHelpId = ".uno:FrameStyle"; break;
838         case SfxStyleFamily::Page:     sHelpId = ".uno:PageStyle"; break;
839         case SfxStyleFamily::Pseudo:   sHelpId = ".uno:ListStyle"; break;
840         case SfxStyleFamily::Table:    sHelpId = ".uno:TableStyle"; break;
841         default: OSL_FAIL("unknown StyleFamily"); break;
842     }
843 
844     OUString sId(OUString::number(nId));
845     m_xActionTbL->set_item_visible(sId, true);
846     m_xActionTbL->set_item_icon_name(sId, rItem.GetImage());
847     m_xActionTbL->set_item_tooltip_text(sId, rItem.GetText());
848     m_xActionTbL->set_item_help_id(sId, sHelpId);
849     ++m_nActionTbLVisible;
850 }
851 
ReplaceUpdateButtonByMenu()852 void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
853 {
854     m_xActionTbR->set_item_visible(u"update"_ustr, false);
855     m_xActionTbR->set_item_visible(u"new"_ustr, false);
856     m_xActionTbR->set_item_visible(u"newmenu"_ustr, true);
857     FillToolMenu();
858 }
859 
ClearFamilyList()860 void SfxTemplateDialog_Impl::ClearFamilyList()
861 {
862     for (int i = 0, nCount = m_xActionTbL->get_n_items(); i < nCount; ++i)
863         m_xActionTbL->set_item_visible(m_xActionTbL->get_item_ident(i), false);
864 
865 }
866 
~SfxTemplateDialog_Impl()867 SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
868 {
869     m_xToolbarDropTargetHelper.reset();
870     m_xActionTbL.reset();
871     m_xActionTbR.reset();
872 }
873 
EnableItem(const OUString & rMesId,bool bCheck)874 void SfxTemplateDialog_Impl::EnableItem(const OUString& rMesId, bool bCheck)
875 {
876     if (rMesId == "watercan" && !bCheck && IsCheckedItem(u"watercan"_ustr))
877         Execute_Impl(SID_STYLE_WATERCAN, u""_ustr, u""_ustr, 0, m_aStyleList);
878     m_xActionTbR->set_item_sensitive(rMesId, bCheck);
879 }
880 
CheckItem(const OUString & rMesId,bool bCheck)881 void SfxTemplateDialog_Impl::CheckItem(const OUString &rMesId, bool bCheck)
882 {
883     if (rMesId == "watercan")
884     {
885         bIsWater=bCheck;
886         m_xActionTbR->set_item_active(u"watercan"_ustr, bCheck);
887     }
888     else
889         m_xActionTbL->set_item_active(rMesId, bCheck);
890 }
891 
IsCheckedItem(const OUString & rMesId)892 bool SfxTemplateDialog_Impl::IsCheckedItem(const OUString& rMesId)
893 {
894     if (rMesId == "watercan")
895         return m_xActionTbR->get_item_active(u"watercan"_ustr);
896     return m_xActionTbL->get_item_active(rMesId);
897 }
898 
IMPL_LINK(SfxTemplateDialog_Impl,ToolBoxLSelect,const OUString &,rEntry,void)899 IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxLSelect, const OUString&, rEntry, void)
900 {
901     FamilySelect(rEntry.toUInt32(), m_aStyleList);
902 }
903 
IMPL_LINK(SfxTemplateDialog_Impl,ToolBoxRSelect,const OUString &,rEntry,void)904 IMPL_LINK(SfxTemplateDialog_Impl, ToolBoxRSelect, const OUString&, rEntry, void)
905 {
906     if (rEntry == "newmenu")
907         m_xActionTbR->set_menu_item_active(rEntry, !m_xActionTbR->get_menu_item_active(rEntry));
908     else
909         ActionSelect(rEntry, m_aStyleList);
910 }
911 
FillToolMenu()912 void SfxTemplateDialog_Impl::FillToolMenu()
913 {
914     //create a popup menu in Writer
915     OUString sTextDoc(u"com.sun.star.text.TextDocument"_ustr);
916 
917     auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:StyleNewByExample"_ustr, sTextDoc);
918     OUString sLabel = vcl::CommandInfoProvider::GetPopupLabelForCommand(aProperties);
919     m_xToolMenu->append(u"new"_ustr, sLabel);
920     aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:StyleUpdateByExample"_ustr, sTextDoc);
921     sLabel = vcl::CommandInfoProvider::GetPopupLabelForCommand(aProperties);
922     m_xToolMenu->append(u"update"_ustr, sLabel);
923     m_xToolMenu->append_separator(u"separator"_ustr);
924 
925     aProperties = vcl::CommandInfoProvider::GetCommandProperties(u".uno:LoadStyles"_ustr, sTextDoc);
926     sLabel = vcl::CommandInfoProvider::GetPopupLabelForCommand(aProperties);
927     m_xToolMenu->append(u"load"_ustr, sLabel);
928 }
929 
IMPL_LINK(SfxTemplateDialog_Impl,ToolMenuSelectHdl,const OUString &,rMenuId,void)930 IMPL_LINK(SfxTemplateDialog_Impl, ToolMenuSelectHdl, const OUString&, rMenuId, void)
931 {
932     if (rMenuId.isEmpty())
933         return;
934     ActionSelect(rMenuId, m_aStyleList);
935 }
936 
SetFamily(SfxStyleFamily const nFamily)937 void SfxCommonTemplateDialog_Impl::SetFamily(SfxStyleFamily const nFamily)
938 {
939     sal_uInt16 const nId(SfxTemplate::SfxFamilyIdToNId(nFamily));
940     assert((0 < nId && nId <= MAX_FAMILIES) || 0xffff == nId);
941     if ( nId != nActFamily )
942     {
943         m_aStyleListSetFamily.Call(nId);
944         nActFamily = nId;
945     }
946 }
947 
IMPL_LINK(SfxCommonTemplateDialog_Impl,UpdateFamily_Hdl,StyleList &,rStyleList,void)948 IMPL_LINK(SfxCommonTemplateDialog_Impl, UpdateFamily_Hdl, StyleList&, rStyleList, void)
949 {
950     bWaterDisabled = false;
951     bUpdateByExampleDisabled = false;
952 
953     if (IsCheckedItem(u"watercan"_ustr) &&
954         // only if that area is allowed
955         rStyleList.CurrentFamilyHasState())
956     {
957         Execute_Impl(SID_STYLE_APPLY, rStyleList.GetSelectedEntry(), OUString(),
958                      static_cast<sal_uInt16>(rStyleList.GetFamilyItem()->GetFamily()), rStyleList);
959     }
960 }
961 
ReplaceUpdateButtonByMenu()962 void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
963 {
964     //does nothing
965 }
966 
AcceptToolbarDrop(const AcceptDropEvent & rEvt,const DropTargetHelper & rHelper)967 sal_Int8 SfxTemplateDialog_Impl::AcceptToolbarDrop(const AcceptDropEvent& rEvt, const DropTargetHelper& rHelper)
968 {
969     sal_Int8 nReturn = DND_ACTION_NONE;
970 
971     // auto flip to the category under the mouse
972     int nIndex = m_xActionTbL->get_drop_index(rEvt.maPosPixel);
973     if (nIndex >= m_nActionTbLVisible)
974         nIndex = m_nActionTbLVisible - 1;
975 
976     OUString sIdent = m_xActionTbL->get_item_ident(nIndex);
977     if (!sIdent.isEmpty() && !m_xActionTbL->get_item_active(sIdent))
978         ToolBoxLSelect(sIdent);
979 
980     // special case: page styles are allowed to create new styles by example
981     // but not allowed to be created by drag and drop
982     if (sIdent.toUInt32() != SfxTemplate::SfxFamilyIdToNId(SfxStyleFamily::Page) &&
983         rHelper.IsDropFormatSupported(SotClipboardFormatId::OBJECTDESCRIPTOR) &&
984         !bNewByExampleDisabled)
985     {
986         nReturn = DND_ACTION_COPY;
987     }
988     return nReturn;
989 }
990 
EnableEdit(bool b,StyleList * rStyleList)991 void SfxCommonTemplateDialog_Impl::EnableEdit(bool b, StyleList* rStyleList)
992 {
993     if (rStyleList == &m_aStyleList || rStyleList == nullptr)
994         m_aStyleList.Enableedit(b);
995 }
EnableDel(bool b,const StyleList * rStyleList)996 void SfxCommonTemplateDialog_Impl::EnableDel(bool b, const StyleList* rStyleList)
997 {
998     if (rStyleList == &m_aStyleList || rStyleList == nullptr)
999         m_aStyleList.Enabledel(b);
1000 }
EnableNew(bool b,const StyleList * rStyleList)1001 void SfxCommonTemplateDialog_Impl::EnableNew(bool b, const StyleList* rStyleList)
1002 {
1003     if (rStyleList == &m_aStyleList || rStyleList == nullptr)
1004         m_aStyleList.Enablenew(b);
1005 }
EnableHide(bool b,const StyleList * rStyleList)1006 void SfxCommonTemplateDialog_Impl::EnableHide(bool b, const StyleList* rStyleList)
1007 {
1008     if (rStyleList == &m_aStyleList || rStyleList == nullptr)
1009         m_aStyleList.Enablehide(b);
1010 }
EnableShow(bool b,const StyleList * rStyleList)1011 void SfxCommonTemplateDialog_Impl::EnableShow(bool b, const StyleList* rStyleList)
1012 {
1013     if (rStyleList == &m_aStyleList || rStyleList == nullptr)
1014         m_aStyleList.Enableshow(b);
1015 }
1016 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1017