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