bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / templdlg.cxx
blobad731633772d7f765f1275aaef67b13d24733d09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <boost/noncopyable.hpp>
22 #include <vcl/menu.hxx>
23 #include <vcl/settings.hxx>
24 #include <svl/intitem.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/style.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <unotools/intlwrapper.hxx>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/frame/ModuleManager.hpp>
34 #include <com/sun/star/frame/theUICommandDescription.hpp>
35 #include <officecfg/Office/Common.hxx>
37 #include <sfx2/sfxhelp.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/templdlg.hxx>
42 #include "templdgi.hxx"
43 #include "tplcitem.hxx"
44 #include "sfxtypes.hxx"
45 #include <sfx2/styfitem.hxx>
46 #include <sfx2/objsh.hxx>
47 #include <sfx2/viewsh.hxx>
48 #include <sfx2/newstyle.hxx>
49 #include <sfx2/tplpitem.hxx>
50 #include <sfx2/sfxresid.hxx>
52 #include "templdlg.hrc"
53 #include <sfx2/sfx.hrc>
54 #include "dialog.hrc"
55 #include "arrdecl.hxx"
56 #include <sfx2/docfilt.hxx>
57 #include <sfx2/docfac.hxx>
58 #include <sfx2/doctempl.hxx>
59 #include <sfx2/module.hxx>
60 #include <sfx2/imgmgr.hxx>
61 #include "helpid.hrc"
62 #include "appdata.hxx"
63 #include <sfx2/viewfrm.hxx>
65 #include <svtools/svlbitm.hxx>
66 #include <svtools/treelistentry.hxx>
67 #include <comphelper/string.hxx>
69 #include <sfx2/StyleManager.hxx>
70 #include <sfx2/StylePreviewRenderer.hxx>
72 using namespace css;
73 using namespace css::beans;
74 using namespace css::frame;
75 using namespace css::uno;
77 namespace
80 class StyleLBoxString : public SvLBoxString
82 SfxStyleFamily meStyleFamily;
83 SvViewDataItem* mpViewData;
85 public:
86 StyleLBoxString(SvTreeListEntry* pEntry,
87 sal_uInt16 nFlags,
88 const OUString& sText,
89 const SfxStyleFamily& eStyleFamily);
91 virtual ~StyleLBoxString();
93 virtual void Paint(const Point& aPos,
94 SvTreeListBox& rDevice,
95 vcl::RenderContext& rRenderContext,
96 const SvViewDataEntry* pView,
97 const SvTreeListEntry* pEntry) SAL_OVERRIDE;
99 virtual void InitViewData(SvTreeListBox* pView,
100 SvTreeListEntry* pEntry,
101 SvViewDataItem* pViewData) SAL_OVERRIDE;
105 StyleLBoxString::StyleLBoxString(SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& sText, const SfxStyleFamily& eStyleFamily)
106 : SvLBoxString(pEntry, nFlags, sText)
107 , meStyleFamily(eStyleFamily)
110 StyleLBoxString::~StyleLBoxString()
113 void StyleLBoxString::InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
115 if (!pViewData)
117 pViewData = pView->GetViewDataItem(pEntry, this);
119 mpViewData = pViewData;
122 void StyleLBoxString::Paint(
123 const Point& aPos, SvTreeListBox& rDevice, vcl::RenderContext& rRenderContext,
124 const SvViewDataEntry* pView, const SvTreeListEntry* pEntry)
126 std::unique_ptr<sfx2::StylePreviewRenderer> pStylePreviewRenderer;
128 if (!pEntry)
129 return;
131 bool bResult = false;
133 SfxObjectShell* pShell = SfxObjectShell::Current();
134 if (!pShell)
135 return;
137 sfx2::StyleManager* pStyleManager = pShell->GetStyleManager();
139 if (pStyleManager)
141 bool bInit = (!pStylePreviewRenderer);
143 pStylePreviewRenderer.reset(pStyleManager->CreateStylePreviewRenderer(rRenderContext, GetText(), meStyleFamily, 32 * rRenderContext.GetDPIScaleFactor()));
145 if (pStylePreviewRenderer)
147 if (pStylePreviewRenderer->recalculate())
149 mpViewData->maSize = pStylePreviewRenderer->getRenderSize();
151 else if (bInit)
153 SvLBoxString::InitViewData( const_cast<SvTreeListBox*>(&rDevice), const_cast<SvTreeListEntry*>(pEntry), mpViewData);
158 if (pStylePreviewRenderer)
160 Rectangle aPaintRectangle = pView->GetPaintRectangle();
161 bResult = pStylePreviewRenderer->render(aPaintRectangle);
164 if (!bResult)
166 rRenderContext.DrawText(aPos, GetText());
170 } // end anonymous namespace
172 // Window is now created dynamically. So here margins, etc.
174 #define SFX_TEMPLDLG_HFRAME 3
175 #define SFX_TEMPLDLG_VTOPFRAME 3
177 #define SFX_TEMPLDLG_VBOTFRAME 3
178 #define SFX_TEMPLDLG_MIDHSPACE 3
179 #define SFX_TEMPLDLG_MIDVSPACE 3
180 #define SFX_TEMPLDLG_FILTERHEIGHT 100
182 static sal_uInt16 nLastItemId = USHRT_MAX;
184 // filter box has maximum 14 entries visible
185 #define MAX_FILTER_ENTRIES 14
188 TYPEINIT0(SfxCommonTemplateDialog_Impl);
189 TYPEINIT1(SfxTemplateDialog_Impl,SfxCommonTemplateDialog_Impl);
191 class SfxCommonTemplateDialog_Impl::DeletionWatcher : private boost::noncopyable
193 typedef void (DeletionWatcher::* bool_type)();
195 public:
196 explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
197 : m_pDialog(&rDialog)
198 , m_pPrevious(m_pDialog->impl_setDeletionWatcher(this))
202 ~DeletionWatcher()
204 if (m_pDialog)
205 m_pDialog->impl_setDeletionWatcher(m_pPrevious);
208 // Signal that the dialog was deleted
209 void signal()
211 m_pDialog = 0;
212 if (m_pPrevious)
213 m_pPrevious->signal();
216 // Return true if the dialog was deleted
217 operator bool_type() const
219 return m_pDialog ? 0 : &DeletionWatcher::signal;
222 private:
223 SfxCommonTemplateDialog_Impl* m_pDialog;
224 DeletionWatcher *const m_pPrevious; /// let's add more epicycles!
227 void DropListBox_Impl::MouseButtonDown( const MouseEvent& rMEvt )
229 nModifier = rMEvt.GetModifier();
231 bool bHitEmptySpace = ( NULL == GetEntry( rMEvt.GetPosPixel(), true ) );
232 if( bHitEmptySpace && ( rMEvt.GetClicks() == 2 ) && rMEvt.IsMod1() )
233 Control::MouseButtonDown( rMEvt );
234 else
235 SvTreeListBox::MouseButtonDown( rMEvt );
238 /** Drop is enabled as long as it is allowed to create a new style by example, i.e. to
239 create a style out of the current selection.
241 sal_Int8 DropListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
243 if ( IsDropFormatSupported( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
245 // special case: page styles are allowed to create new styles by example
246 // but not allowed to be created by drag and drop
247 if (pDialog->GetActualFamily() == SFX_STYLE_FAMILY_PAGE ||
248 pDialog->bNewByExampleDisabled)
249 return DND_ACTION_NONE;
250 else
251 return DND_ACTION_COPY;
253 return SvTreeListBox::AcceptDrop( rEvt );
256 sal_Int8 DropListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
258 sal_Int8 nRet = DND_ACTION_NONE;
259 SfxObjectShell* pDocShell = pDialog->GetObjectShell();
260 TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
261 sal_uInt32 nFormatCount = aHelper.GetFormatCount();
262 if ( pDocShell )
264 bool bFormatFound = false;
266 for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
268 SotClipboardFormatId nId = aHelper.GetFormat(i);
269 TransferableObjectDescriptor aDesc;
271 if ( aHelper.GetTransferableObjectDescriptor( nId, aDesc ) )
273 if ( aDesc.maClassName == pDocShell->GetFactory().GetClassId() )
275 PostUserEvent( LINK( this, DropListBox_Impl, OnAsyncExecuteDrop ), 0, true );
277 bFormatFound = true;
278 nRet = rEvt.mnAction;
279 break;
284 if ( !bFormatFound )
285 return SvTreeListBox::ExecuteDrop( rEvt );
288 return nRet;
291 IMPL_LINK_NOARG(DropListBox_Impl, OnAsyncExecuteDrop)
293 pDialog->ActionSelect( SID_STYLE_NEW_BY_EXAMPLE );
294 return 0;
297 bool DropListBox_Impl::Notify( NotifyEvent& rNEvt )
299 bool nRet = false;
300 if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
302 const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
303 if(!rKeyCode.GetModifier())
305 if( pDialog->bCanDel && KEY_DELETE == rKeyCode.GetCode())
307 pDialog->DeleteHdl( NULL );
308 nRet = true;
310 else if( KEY_RETURN == rKeyCode.GetCode())
312 GetDoubleClickHdl().Call(this);
313 nRet = true;
317 if(!nRet)
318 nRet = SvTreeListBox::Notify( rNEvt );
319 return nRet;
322 /** ListBox class that starts a PopupMenu (designer specific) in the
323 command handler.
325 SfxActionListBox::SfxActionListBox(SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits)
326 : DropListBox_Impl(pParent->GetWindow(), nWinBits, pParent)
328 EnableContextMenuHandling();
331 void SfxActionListBox::Recalc()
333 if (officecfg::Office::Common::StylesAndFormatting::Preview::get())
335 SetEntryHeight(32 * GetDPIScaleFactor());
336 RecalcViewData();
340 PopupMenu* SfxActionListBox::CreateContextMenu()
343 if( !( GetSelectionCount() > 0 ) )
345 pDialog->EnableEdit( false );
346 pDialog->EnableDel( false );
348 return pDialog->CreateContextMenu();
351 SfxTemplatePanelControl::SfxTemplatePanelControl(SfxBindings* pBindings, vcl::Window* pParentWindow)
352 : DockingWindow(pParentWindow, SfxResId(DLG_STYLE_DESIGNER))
353 , pImpl(new SfxTemplateDialog_Impl(pBindings, this))
354 , mpBindings(pBindings)
356 OSL_ASSERT(mpBindings!=NULL);
358 pImpl->updateNonFamilyImages();
360 SetStyle(GetStyle() & ~WB_DOCKABLE);
363 SfxTemplatePanelControl::~SfxTemplatePanelControl()
365 disposeOnce();
368 void SfxTemplatePanelControl::dispose()
370 pImpl.reset();
371 DockingWindow::dispose();
374 void SfxTemplatePanelControl::DataChanged( const DataChangedEvent& _rDCEvt )
376 if ( ( DataChangedEventType::SETTINGS == _rDCEvt.GetType() ) &&
377 ( AllSettingsFlags::STYLE & _rDCEvt.GetFlags() ) )
379 pImpl->updateFamilyImages();
380 pImpl->updateNonFamilyImages();
383 DockingWindow::DataChanged( _rDCEvt );
386 void SfxTemplatePanelControl::Resize()
388 if(pImpl)
389 pImpl->Resize();
390 DockingWindow::Resize();
393 void SfxTemplatePanelControl::FreeResource()
395 DockingWindow::FreeResource();
398 void SfxTemplatePanelControl::StateChanged( StateChangedType nStateChange )
400 if (nStateChange == StateChangedType::InitShow)
402 SfxViewFrame* pFrame = mpBindings->GetDispatcher_Impl()->GetFrame();
403 vcl::Window* pEditWin = pFrame->GetViewShell()->GetWindow();
405 Size aSize = pEditWin->GetSizePixel();
406 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
407 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
408 Size aWinSize = GetSizePixel();
409 aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
410 aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
411 // SetFloatingPos( aPoint );
414 DockingWindow::StateChanged( nStateChange );
417 void StyleTreeListBox_Impl::MakeExpanded_Impl(ExpandedEntries_t& rEntries) const
419 SvTreeListEntry* pEntry;
420 for (pEntry = FirstVisible(); pEntry; pEntry = NextVisible(pEntry))
422 if (IsExpanded(pEntry))
424 rEntries.push_back(GetEntryText(pEntry));
429 PopupMenu* StyleTreeListBox_Impl::CreateContextMenu()
431 return pDialog->CreateContextMenu();
434 /** DoubleClick-Handler; calls the link.
435 SV virtual method.
437 bool StyleTreeListBox_Impl::DoubleClickHdl()
439 aDoubleClickLink.Call(this);
440 return false;
443 /** Command Handler; this executes a PopupMenu (designer-specific)
444 SV virtual method.
446 void StyleTreeListBox_Impl::Command( const CommandEvent& rCEvt )
448 SvTreeListBox::Command(rCEvt);
451 bool StyleTreeListBox_Impl::Notify( NotifyEvent& rNEvt )
453 // handle <RETURN> as double click
455 bool nRet = false;
456 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
458 const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
459 if ( !rKeyCode.GetModifier() && KEY_RETURN == rKeyCode.GetCode() )
461 aDoubleClickLink.Call( this );
462 nRet = true;
466 if ( !nRet )
467 nRet = DropListBox_Impl::Notify( rNEvt );
469 return nRet;
472 /** NotifyMoving Handler; This leads via a link on the event to the dialog.
473 SV virtual method.
475 TriState StyleTreeListBox_Impl::NotifyMoving(SvTreeListEntry* pTarget,
476 SvTreeListEntry* pEntry,
477 SvTreeListEntry*& rpNewParent,
478 sal_uIntPtr& lPos)
480 if(!pTarget || !pEntry)
481 return TRISTATE_FALSE;
482 aParent = GetEntryText(pTarget);
483 aStyle = GetEntryText(pEntry);
484 const bool bRet = (bool)aDropLink.Call(this);
485 rpNewParent = pTarget;
486 lPos=0;
487 IntlWrapper aIntlWrapper( Application::GetSettings().GetLanguageTag() );
488 const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
489 for(SvTreeListEntry *pTmpEntry=FirstChild(pTarget);
490 pTmpEntry && pCollator->compareString(
491 GetEntryText(pTmpEntry),GetEntryText(pEntry)) < 0;
492 pTmpEntry=NextSibling(pTmpEntry),lPos++) ;
494 return bRet ? TRISTATE_INDET : TRISTATE_FALSE;
497 /** ExpandingHdl Handler; the current entry is noticed.
498 SV virtual method.
500 [Cross-reference]
501 <StyleTreeListBox_Impl::ExpandedHdl()>
503 bool StyleTreeListBox_Impl::ExpandingHdl()
505 pCurEntry = GetCurEntry();
506 return true;
509 /** ExpandedHdl Handler;
510 SV virtual method.
512 [Cross-reference]
513 <StyleTreeListBox_Impl::ExpandingHdl()>
515 void StyleTreeListBox_Impl::ExpandedHdl()
517 SvTreeListEntry *pEntry = GetHdlEntry();
518 if(!IsExpanded(pEntry) && pCurEntry != GetCurEntry())
519 SelectAll( false );
520 pCurEntry = 0;
523 /** Constructor StyleTreeListBox_Impl */
524 StyleTreeListBox_Impl::StyleTreeListBox_Impl(SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle)
525 : DropListBox_Impl(pParent->GetWindow(), nWinStyle, pParent)
526 , pCurEntry(0)
528 EnableContextMenuHandling();
531 void StyleTreeListBox_Impl::Recalc()
533 if (officecfg::Office::Common::StylesAndFormatting::Preview::get())
535 SetEntryHeight(32 * GetDPIScaleFactor());
536 RecalcViewData();
540 /** Internal structure for the establishment of the hierarchical view */
541 class StyleTree_Impl;
542 typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl;
544 class StyleTree_Impl
546 private:
547 OUString aName;
548 OUString aParent;
549 StyleTreeArr_Impl pChildren;
551 public:
553 bool HasParent() const { return !aParent.isEmpty(); }
555 StyleTree_Impl(const OUString &rName, const OUString &rParent):
556 aName(rName), aParent(rParent), pChildren(0) {}
557 ~StyleTree_Impl();
558 void Put(StyleTree_Impl* pIns, sal_uIntPtr lPos=ULONG_MAX);
559 sal_uIntPtr Count();
561 OUString getName() { return aName; }
562 OUString getParent() { return aParent; }
563 StyleTree_Impl *operator[](size_t idx) const { return pChildren[idx]; }
566 sal_uIntPtr StyleTree_Impl::Count()
568 return pChildren.size();
571 StyleTree_Impl::~StyleTree_Impl()
573 for(StyleTreeArr_Impl::const_iterator it = pChildren.begin(); it != pChildren.end(); ++it)
574 delete *it;
577 void StyleTree_Impl::Put(StyleTree_Impl* pIns, sal_uIntPtr lPos)
579 if ( ULONG_MAX == lPos )
580 pChildren.push_back( pIns );
581 else
582 pChildren.insert( pChildren.begin() + (sal_uInt16)lPos, pIns );
587 StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
589 const sal_uInt16 nCount = rArr.size();
591 comphelper::string::NaturalStringSorter aSorter(
592 ::comphelper::getProcessComponentContext(),
593 Application::GetSettings().GetLanguageTag().getLocale());
595 // Arrange all under their Parents
596 sal_uInt16 i;
597 for(i = 0; i < nCount; ++i)
599 StyleTree_Impl* pEntry = rArr[i];
600 if(pEntry->HasParent())
602 for(sal_uInt16 j = 0; j < nCount; ++j)
604 StyleTree_Impl* pCmp = rArr[j];
605 if(pCmp->getName() == pEntry->getParent())
607 // Paste initial filter
608 sal_uInt16 nPos;
609 for( nPos = 0 ; nPos < pCmp->Count() &&
610 aSorter.compare((*pCmp)[nPos]->getName(), pEntry->getName()) < 0 ; nPos++)
612 pCmp->Put(pEntry,nPos);
613 break;
619 for(i = 0; i < rArr.size(); )
621 if(rArr[i]->HasParent())
622 rArr.erase(rArr.begin() + i);
623 else
624 ++i;
626 return rArr;
629 inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
630 const OUString &rStr)
632 for (size_t n = 0; n < rEntries.size(); ++n)
634 if (rEntries[n] == rStr)
635 return true;
637 return false;
640 SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox,
641 StyleTree_Impl* pEntry,
642 const ExpandedEntries_t& rEntries,
643 SfxStyleFamily eStyleFamily,
644 SvTreeListEntry* pParent = nullptr)
646 SvTreeListEntry* pTreeListEntry = pBox->InsertEntry(pEntry->getName(), pParent);
648 if (officecfg::Office::Common::StylesAndFormatting::Preview::get())
650 StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, pEntry->getName(), eStyleFamily);
651 pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
654 pBox->GetModel()->InvalidateEntry(pTreeListEntry);
656 for(sal_uInt16 i = 0; i < pEntry->Count(); ++i)
658 FillBox_Impl(pBox, (*pEntry)[i], rEntries, eStyleFamily, pTreeListEntry);
660 return pTreeListEntry;
663 // Constructor
665 SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl::Window* pW, bool )
666 : mbIgnoreSelect(false)
667 , pBindings(pB)
668 , pWindow(pW)
669 , pModule(NULL)
670 , pIdle(NULL)
671 , m_pStyleFamiliesId(NULL)
672 , pStyleFamilies(NULL)
673 , pStyleSheetPool(NULL)
674 , pTreeBox(NULL)
675 , pCurObjShell(NULL)
676 , xModuleManager(frame::ModuleManager::create(::comphelper::getProcessComponentContext()))
677 , m_pDeletionWatcher(NULL)
679 , aFmtLb( VclPtr<SfxActionListBox>::Create(this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH) )
680 , aFilterLb( VclPtr<ListBox>::Create(pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP) )
682 , nActFamily(0xffff)
683 , nActFilter(0)
684 , nAppFilter(0)
686 , bDontUpdate(false)
687 , bIsWater(false)
688 , bEnabled(true)
689 , bUpdate(false)
690 , bUpdateFamily(false)
691 , bCanEdit(false)
692 , bCanDel(false)
693 , bCanNew(true)
694 , bCanHide(true)
695 , bCanShow(false)
696 , bWaterDisabled(false)
697 , bNewByExampleDisabled(false)
698 , bUpdateByExampleDisabled(false)
699 , bTreeDrag(true)
700 , bHierarchical(false)
701 , m_bWantHierarchical(false)
702 , bBindingUpdate(true)
704 aFmtLb->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
705 aFmtLb->SetHelpId( HID_TEMPLATE_FMT );
706 aFilterLb->SetHelpId( HID_TEMPLATE_FILTER );
707 aFmtLb->SetStyle( aFmtLb->GetStyle() | WB_SORT | WB_HIDESELECTION );
708 vcl::Font aFont = aFmtLb->GetFont();
709 aFont.SetWeight( WEIGHT_NORMAL );
710 aFmtLb->SetFont( aFont );
712 memset(pBoundItems, 0, sizeof(pBoundItems));
713 memset(pFamilyState, 0, sizeof(pFamilyState));
716 sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId)
718 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nId );
719 return SfxTemplate::SfxFamilyIdToNId(pItem->GetFamily())-1;
722 void SfxTemplateDialog_Impl::EnableEdit(bool bEnable)
724 SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
725 if( !bEnable || !bUpdateByExampleDisabled )
726 EnableItem( SID_STYLE_UPDATE_BY_EXAMPLE, bEnable);
729 void SfxCommonTemplateDialog_Impl::ReadResource()
731 // Read global user resource
732 for(sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
733 pFamilyState[i] = 0;
735 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
736 pCurObjShell = pViewFrame->GetObjectShell();
737 pModule = pCurObjShell ? pCurObjShell->GetModule() : NULL;
738 ResMgr* pMgr = pModule ? pModule->GetResMgr() : NULL;
739 if (pMgr)
741 ResId aFamId( DLG_STYLE_DESIGNER, *pMgr );
742 aFamId.SetRT(RSC_SFX_STYLE_FAMILIES);
743 m_pStyleFamiliesId = new ResId( aFamId.GetId(), *pMgr );
744 m_pStyleFamiliesId->SetRT(RSC_SFX_STYLE_FAMILIES);
745 if (pMgr->IsAvailable(aFamId))
746 pStyleFamilies = new SfxStyleFamilies( aFamId );
748 if (!pStyleFamilies)
749 pStyleFamilies = new SfxStyleFamilies;
751 nActFilter = pCurObjShell ? static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pCurObjShell ) ) : SFXSTYLEBIT_ALL;
752 if ( pCurObjShell && SFXSTYLEBIT_ALL == nActFilter )
753 nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
755 // Paste in the toolbox
756 // reverse order, since always inserted at the head
757 size_t nCount = pStyleFamilies->size();
759 pBindings->ENTERREGISTRATIONS();
761 size_t i;
762 for (i = 0; i < nCount; ++i)
764 sal_uInt16 nSlot = 0;
765 switch( (sal_uInt16)pStyleFamilies->at( i )->GetFamily() )
767 case SFX_STYLE_FAMILY_CHAR:
768 nSlot = SID_STYLE_FAMILY1; break;
769 case SFX_STYLE_FAMILY_PARA:
770 nSlot = SID_STYLE_FAMILY2; break;
771 case SFX_STYLE_FAMILY_FRAME:
772 nSlot = SID_STYLE_FAMILY3; break;
773 case SFX_STYLE_FAMILY_PAGE:
774 nSlot = SID_STYLE_FAMILY4; break;
775 case SFX_STYLE_FAMILY_PSEUDO:
776 nSlot = SID_STYLE_FAMILY5; break;
777 default: OSL_FAIL("unknown StyleFamily"); break;
779 pBoundItems[i] =
780 new SfxTemplateControllerItem(nSlot, *this, *pBindings);
782 pBoundItems[i++] = new SfxTemplateControllerItem(
783 SID_STYLE_WATERCAN, *this, *pBindings);
784 pBoundItems[i++] = new SfxTemplateControllerItem(
785 SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings);
786 pBoundItems[i++] = new SfxTemplateControllerItem(
787 SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings);
788 pBoundItems[i++] = new SfxTemplateControllerItem(
789 SID_STYLE_NEW, *this, *pBindings);
790 pBoundItems[i++] = new SfxTemplateControllerItem(
791 SID_STYLE_DRAGHIERARCHIE, *this, *pBindings);
792 pBoundItems[i++] = new SfxTemplateControllerItem(
793 SID_STYLE_EDIT, *this, *pBindings);
794 pBoundItems[i++] = new SfxTemplateControllerItem(
795 SID_STYLE_DELETE, *this, *pBindings);
796 pBoundItems[i++] = new SfxTemplateControllerItem(
797 SID_STYLE_FAMILY, *this, *pBindings);
798 pBindings->LEAVEREGISTRATIONS();
800 for(; i < COUNT_BOUND_FUNC; ++i)
801 pBoundItems[i] = 0;
803 StartListening(*pBindings);
805 // Insert in the reverse order of occurrence in the Style Families. This is for
806 // the toolbar of the designer. The list box of the catalog respects the
807 // correct order by itself.
809 // Sequences: the order of Resource = the order of Toolbar for example list box.
810 // Order of ascending SIDs: Low SIDs are displayed first when templates of
811 // several families are active.
813 // in the Writer the UpdateStyleByExample Toolbox button is removed and
814 // the NewStyle button gets a PopupMenu
815 if(nCount > 4)
816 ReplaceUpdateButtonByMenu();
818 for( ; nCount--; )
820 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nCount );
821 sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId( pItem->GetFamily() );
822 InsertFamilyItem( nId, pItem );
825 LoadedFamilies();
827 sal_uInt16 nStart = SID_STYLE_FAMILY1;
828 sal_uInt16 nEnd = SID_STYLE_FAMILY4;
830 for ( i = nStart; i <= nEnd; i++ )
831 pBindings->Update(i);
834 void SfxCommonTemplateDialog_Impl::ClearResource()
836 ClearFamilyList();
837 impl_clear();
840 void SfxCommonTemplateDialog_Impl::impl_clear()
842 delete pStyleFamilies;
843 pStyleFamilies = NULL;
844 sal_uInt16 i;
845 for ( i = 0; i < MAX_FAMILIES; ++i )
846 DELETEX(SfxTemplateItem, pFamilyState[i]);
847 for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
848 delete pBoundItems[i];
849 pCurObjShell = NULL;
851 DELETEZ( m_pStyleFamiliesId );
854 SfxCommonTemplateDialog_Impl::DeletionWatcher *
855 SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(
856 DeletionWatcher *const pNewWatcher)
858 DeletionWatcher *const pRet(m_pDeletionWatcher);
859 m_pDeletionWatcher = pNewWatcher;
860 return pRet;
863 void SfxCommonTemplateDialog_Impl::Initialize()
865 // Read global user resource
866 ReadResource();
867 pBindings->Invalidate( SID_STYLE_FAMILY );
868 pBindings->Update( SID_STYLE_FAMILY );
870 Update_Impl();
872 aFilterLb->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) );
873 aFmtLb->SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) );
874 aFmtLb->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) );
875 aFmtLb->SetSelectionMode(MULTIPLE_SELECTION);
878 aFilterLb->Show();
879 if (!bHierarchical)
880 aFmtLb->Show();
883 SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
885 OUString aEmpty;
886 #if defined STYLESPREVIEW
887 Execute_Impl(SID_STYLE_END_PREVIEW,
888 OUString(), OUString(),
889 0, 0, 0, 0 );
890 #endif
891 if ( bIsWater )
892 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
893 GetWindow()->Hide();
894 impl_clear();
895 if ( pStyleSheetPool )
896 EndListening(*pStyleSheetPool);
897 pStyleSheetPool = NULL;
898 pTreeBox.disposeAndClear();
899 delete pIdle;
900 if ( m_pDeletionWatcher )
901 m_pDeletionWatcher->signal();
902 aFmtLb.disposeAndClear();
903 aFilterLb.disposeAndClear();
906 namespace SfxTemplate
908 sal_uInt16 SfxFamilyIdToNId(SfxStyleFamily nFamily)
910 switch ( nFamily )
912 case SFX_STYLE_FAMILY_CHAR: return 1;
913 case SFX_STYLE_FAMILY_PARA: return 2;
914 case SFX_STYLE_FAMILY_FRAME: return 3;
915 case SFX_STYLE_FAMILY_PAGE: return 4;
916 case SFX_STYLE_FAMILY_PSEUDO: return 5;
917 default: return 0;
921 SfxStyleFamily NIdToSfxFamilyId(sal_uInt16 nId)
923 switch (nId)
925 case 1: return SFX_STYLE_FAMILY_CHAR;
926 case 2: return SFX_STYLE_FAMILY_PARA;
927 case 3: return SFX_STYLE_FAMILY_FRAME;
928 case 4: return SFX_STYLE_FAMILY_PAGE;
929 case 5: return SFX_STYLE_FAMILY_PSEUDO;
930 default: return SFX_STYLE_FAMILY_ALL;
935 // Helper function: Access to the current family item
936 const SfxStyleFamilyItem *SfxCommonTemplateDialog_Impl::GetFamilyItem_Impl() const
938 const size_t nCount = pStyleFamilies->size();
939 for(size_t i = 0; i < nCount; ++i)
941 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( i );
942 sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId(pItem->GetFamily());
943 if(nId == nActFamily)
944 return pItem;
946 return 0;
949 SfxStyleSheetBase *SfxCommonTemplateDialog_Impl::GetSelectedStyle() const
951 if (!IsInitialized() || !pStyleSheetPool || !HasSelectedStyle())
952 return NULL;
953 const OUString aTemplName( GetSelectedEntry() );
954 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
955 return pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
958 void SfxCommonTemplateDialog_Impl::SelectStyle(const OUString &rStr)
960 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
961 if ( !pItem )
962 return;
963 const SfxStyleFamily eFam = pItem->GetFamily();
964 SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( rStr, eFam, SFXSTYLEBIT_ALL );
965 if( pStyle )
967 bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
968 EnableEdit( bReadWrite );
969 EnableHide( bReadWrite && !pStyle->IsHidden( ) && !pStyle->IsUsed( ) );
970 EnableShow( bReadWrite && pStyle->IsHidden( ) );
972 else
974 EnableEdit( false );
975 EnableHide( false );
976 EnableShow( false );
979 if ( pTreeBox )
981 if ( !rStr.isEmpty() )
983 SvTreeListEntry* pEntry = pTreeBox->First();
984 while ( pEntry )
986 if ( pTreeBox->GetEntryText( pEntry ) == rStr )
988 pTreeBox->MakeVisible( pEntry );
989 pTreeBox->Select( pEntry );
990 return;
992 pEntry = pTreeBox->Next( pEntry );
995 else
996 pTreeBox->SelectAll( false );
998 else
1000 bool bSelect = ! rStr.isEmpty();
1001 if ( bSelect )
1003 SvTreeListEntry* pEntry = aFmtLb->FirstVisible();
1004 while ( pEntry && aFmtLb->GetEntryText( pEntry ) != rStr )
1005 pEntry = aFmtLb->NextVisible( pEntry );
1006 if ( !pEntry )
1007 bSelect = false;
1008 else
1010 if (!aFmtLb->IsSelected(pEntry))
1012 aFmtLb->MakeVisible( pEntry );
1013 aFmtLb->SelectAll(false);
1014 aFmtLb->Select( pEntry );
1015 bWaterDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1);
1016 FmtSelectHdl( NULL );
1021 if ( !bSelect )
1023 aFmtLb->SelectAll( false );
1024 EnableEdit(false);
1025 EnableHide( false );
1026 EnableShow( false );
1031 OUString SfxCommonTemplateDialog_Impl::GetSelectedEntry() const
1033 OUString aRet;
1034 if ( pTreeBox )
1036 SvTreeListEntry* pEntry = pTreeBox->FirstSelected();
1037 if ( pEntry )
1038 aRet = pTreeBox->GetEntryText( pEntry );
1040 else
1042 SvTreeListEntry* pEntry = aFmtLb->FirstSelected();
1043 if ( pEntry )
1044 aRet = aFmtLb->GetEntryText( pEntry );
1046 return aRet;
1049 void SfxCommonTemplateDialog_Impl::EnableTreeDrag( bool bEnable )
1051 if ( pStyleSheetPool )
1053 SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
1054 if ( pTreeBox )
1056 if ( pStyle && pStyle->HasParentSupport() && bEnable )
1057 pTreeBox->SetDragDropMode(DragDropMode::CTRL_MOVE);
1058 else
1059 pTreeBox->SetDragDropMode(DragDropMode::NONE);
1062 bTreeDrag = bEnable;
1065 void SfxCommonTemplateDialog_Impl::FillTreeBox()
1067 OSL_ENSURE( pTreeBox, "FillTreeBox() without treebox");
1068 if (pStyleSheetPool && nActFamily != 0xffff)
1070 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1071 if (!pItem)
1072 return;
1073 pStyleSheetPool->SetSearchMask(pItem->GetFamily(), SFXSTYLEBIT_ALL_VISIBLE);
1074 StyleTreeArr_Impl aArr;
1075 SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
1077 if(pStyle && pStyle->HasParentSupport() && bTreeDrag )
1078 pTreeBox->SetDragDropMode(DragDropMode::CTRL_MOVE);
1079 else
1080 pTreeBox->SetDragDropMode(DragDropMode::NONE);
1082 while (pStyle)
1084 StyleTree_Impl* pNew = new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
1085 aArr.push_back(pNew);
1086 pStyle = pStyleSheetPool->Next();
1089 MakeTree_Impl(aArr);
1090 ExpandedEntries_t aEntries;
1091 pTreeBox->MakeExpanded_Impl(aEntries);
1092 pTreeBox->SetUpdateMode( false );
1093 pTreeBox->Clear();
1094 const sal_uInt16 nCount = aArr.size();
1096 for (sal_uInt16 i = 0; i < nCount; ++i)
1098 FillBox_Impl(pTreeBox, aArr[i], aEntries, pItem->GetFamily());
1100 pTreeBox->Recalc();
1102 EnableItem(SID_STYLE_WATERCAN, false);
1104 SfxTemplateItem* pState = pFamilyState[nActFamily - 1];
1106 if (nCount)
1107 pTreeBox->Expand(pTreeBox->First());
1109 for (SvTreeListEntry* pEntry = pTreeBox->First(); pEntry; pEntry = pTreeBox->Next(pEntry))
1111 if (IsExpanded_Impl(aEntries, pTreeBox->GetEntryText(pEntry)))
1112 pTreeBox->Expand(pEntry);
1115 pTreeBox->SetUpdateMode( true );
1117 OUString aStyle;
1118 if(pState) // Select current entry
1119 aStyle = pState->GetStyleName();
1120 SelectStyle(aStyle);
1121 EnableDelete();
1125 bool SfxCommonTemplateDialog_Impl::HasSelectedStyle() const
1127 return pTreeBox? pTreeBox->FirstSelected() != 0:
1128 aFmtLb->GetSelectionCount() != 0;
1131 // internal: Refresh the display
1132 // nFlags: what we should update.
1133 void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags)
1135 OSL_ENSURE(nFlags, "nothing to do");
1136 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1137 if (!pItem)
1139 // Is the case for the template catalog
1140 SfxTemplateItem **ppItem = pFamilyState;
1141 const size_t nFamilyCount = pStyleFamilies->size();
1142 size_t n;
1143 for( n = 0; n < nFamilyCount; n++ )
1144 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1145 if ( n == nFamilyCount )
1146 // It happens sometimes, God knows why
1147 return;
1148 ppItem += StyleNrToInfoOffset(n);
1149 nAppFilter = (*ppItem)->GetValue();
1150 FamilySelect( StyleNrToInfoOffset(n)+1 );
1151 pItem = GetFamilyItem_Impl();
1154 const SfxStyleFamily eFam = pItem->GetFamily();
1156 SfxFilterTupel* pT = ( nActFilter < pItem->GetFilterList().size() ? pItem->GetFilterList()[nActFilter] : NULL );
1157 sal_uInt16 nFilter = pT ? pT->nFlags : 0;
1158 if(!nFilter) // automatic
1159 nFilter = nAppFilter;
1161 OSL_ENSURE(pStyleSheetPool, "no StyleSheetPool");
1162 if(pStyleSheetPool)
1164 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1165 pItem = GetFamilyItem_Impl();
1166 if((nFlags & UPDATE_FAMILY) == UPDATE_FAMILY) // Update view type list (Hierarchical, All, etc.
1168 CheckItem(nActFamily, true); // check Button in Toolbox
1169 aFilterLb->SetUpdateMode(false);
1170 aFilterLb->Clear();
1171 //insert hierarchical at the beginning
1172 sal_uInt16 nPos = aFilterLb->InsertEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString(), 0);
1173 aFilterLb->SetEntryData( nPos, reinterpret_cast<void*>(SFXSTYLEBIT_ALL) );
1174 const SfxStyleFilter& rFilter = pItem->GetFilterList();
1175 for( size_t i = 0; i < rFilter.size(); ++i)
1177 sal_uIntPtr nFilterFlags = rFilter[ i ]->nFlags;
1178 nPos = aFilterLb->InsertEntry( rFilter[ i ]->aName );
1179 aFilterLb->SetEntryData( nPos, reinterpret_cast<void*>(nFilterFlags) );
1181 if(nActFilter < aFilterLb->GetEntryCount() - 1)
1182 aFilterLb->SelectEntryPos(nActFilter + 1);
1183 else
1185 nActFilter = 0;
1186 aFilterLb->SelectEntryPos(1);
1187 SfxFilterTupel* pActT = ( nActFilter < rFilter.size() ) ? rFilter[ nActFilter ] : NULL;
1188 sal_uInt16 nFilterFlags = pActT ? pActT->nFlags : 0;
1189 pStyleSheetPool->SetSearchMask(eFam, nFilterFlags);
1192 // if the tree view again, select family hierarchy
1193 if (pTreeBox || m_bWantHierarchical)
1195 aFilterLb->SelectEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString());
1196 EnableHierarchical(true);
1199 // show maximum 14 entries
1200 aFilterLb->SetDropDownLineCount( MAX_FILTER_ENTRIES );
1201 aFilterLb->SetUpdateMode(true);
1203 else
1205 if (nActFilter < aFilterLb->GetEntryCount() - 1)
1206 aFilterLb->SelectEntryPos(nActFilter + 1);
1207 else
1209 nActFilter = 0;
1210 aFilterLb->SelectEntryPos(1);
1214 if(nFlags & UPDATE_FAMILY_LIST)
1216 EnableItem(SID_STYLE_WATERCAN,false);
1218 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
1219 SvTreeListEntry* pEntry = aFmtLb->First();
1220 std::vector<OUString> aStrings;
1222 comphelper::string::NaturalStringSorter aSorter(
1223 ::comphelper::getProcessComponentContext(),
1224 Application::GetSettings().GetLanguageTag().getLocale());
1226 while( pStyle )
1228 //Bubblesort
1229 size_t nPos;
1230 for(nPos = aStrings.size(); nPos && aSorter.compare(aStrings[nPos-1], pStyle->GetName()) > 0; --nPos)
1232 aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
1233 pStyle = pStyleSheetPool->Next();
1236 size_t nCount = aStrings.size();
1237 size_t nPos = 0;
1238 while(nPos < nCount && pEntry &&
1239 aStrings[nPos] == aFmtLb->GetEntryText(pEntry))
1241 ++nPos;
1242 pEntry = aFmtLb->Next( pEntry );
1245 if( nPos < nCount || pEntry )
1247 // Fills the display box
1248 aFmtLb->SetUpdateMode(false);
1249 aFmtLb->Clear();
1251 for(nPos = 0; nPos < nCount; ++nPos)
1253 SvTreeListEntry* pTreeListEntry = aFmtLb->InsertEntry(aStrings[nPos], 0, false, nPos);
1254 if (officecfg::Office::Common::StylesAndFormatting::Preview::get())
1256 StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, aStrings[nPos], eFam);
1257 pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
1259 aFmtLb->GetModel()->InvalidateEntry(pTreeListEntry);
1261 aFmtLb->Recalc();
1262 aFmtLb->SetUpdateMode(true);
1264 // Selects the current style if any
1265 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1266 OUString aStyle;
1267 if(pState)
1268 aStyle = pState->GetStyleName();
1269 #if defined STYLESPREVIEW
1270 mbIgnoreSelect = true; // in case we get a selection change
1271 // in anycase we should stop any preview
1272 Execute_Impl(SID_STYLE_END_PREVIEW,
1273 OUString(), OUString(),
1274 0, 0, 0, 0 );
1275 #endif
1276 SelectStyle(aStyle);
1277 EnableDelete();
1282 // Updated display: Watering the house
1283 void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
1285 bWaterDisabled = pItem == 0;
1287 if(!bWaterDisabled)
1288 //make sure the watercan is only activated when there is (only) one selection
1289 bWaterDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1);
1291 if(pItem && !bWaterDisabled)
1293 CheckItem(SID_STYLE_WATERCAN, pItem->GetValue());
1294 EnableItem( SID_STYLE_WATERCAN, true );
1296 else
1297 if(!bWaterDisabled)
1298 EnableItem(SID_STYLE_WATERCAN, true);
1299 else
1300 EnableItem(SID_STYLE_WATERCAN, false);
1302 // Ignore while in watercan mode statusupdates
1304 size_t nCount = pStyleFamilies->size();
1305 pBindings->EnterRegistrations();
1306 for(size_t n = 0; n < nCount; n++)
1308 SfxControllerItem *pCItem=pBoundItems[n];
1309 bool bChecked = pItem && pItem->GetValue();
1310 if( pCItem->IsBound() == bChecked )
1312 if( !bChecked )
1313 pCItem->ReBind();
1314 else
1315 pCItem->UnBind();
1318 pBindings->LeaveRegistrations();
1321 // Item with the status of a Family is copied and noted
1322 // (is updated when all states have also been updated.)
1323 // See also: <SfxBindings::AddDoneHdl(const Link &)>
1324 void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
1326 sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START;
1327 DELETEZ(pFamilyState[nIdx]);
1328 if ( pItem )
1329 pFamilyState[nIdx] = new SfxTemplateItem(*pItem);
1330 bUpdate = true;
1332 // If used templates (how the hell you find this out??)
1333 bUpdateFamily = true;
1336 // Notice from SfxBindings that the update is completed. Pushes out the update
1337 // of the display.
1338 void SfxCommonTemplateDialog_Impl::Update_Impl()
1340 bool bDocChanged=false;
1341 SfxStyleSheetBasePool* pNewPool = NULL;
1342 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1343 SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
1344 if( pDocShell )
1345 pNewPool = pDocShell->GetStyleSheetPool();
1347 if ( pNewPool != pStyleSheetPool && pDocShell )
1349 SfxModule* pNewModule = pDocShell->GetModule();
1350 if( pNewModule && pNewModule != pModule )
1352 ClearResource();
1353 ReadResource();
1355 if ( pStyleSheetPool )
1357 EndListening(*pStyleSheetPool);
1358 pStyleSheetPool = 0;
1361 if ( pNewPool )
1363 StartListening(*pNewPool);
1364 pStyleSheetPool = pNewPool;
1365 bDocChanged=true;
1369 if (bUpdateFamily)
1370 UpdateFamily_Impl();
1372 sal_uInt16 i;
1373 for(i = 0; i < MAX_FAMILIES; ++i)
1374 if(pFamilyState[i])
1375 break;
1376 if(i == MAX_FAMILIES || !pNewPool)
1377 // nothing is allowed
1378 return;
1380 SfxTemplateItem *pItem = 0;
1381 // current region not within the allowed region or default
1382 if(nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1] ) )
1384 CheckItem(nActFamily, false);
1385 SfxTemplateItem **ppItem = pFamilyState;
1386 const size_t nFamilyCount = pStyleFamilies->size();
1387 size_t n;
1388 for( n = 0; n < nFamilyCount; n++ )
1389 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1390 ppItem+=StyleNrToInfoOffset(n);
1392 nAppFilter = (*ppItem)->GetValue();
1393 FamilySelect( StyleNrToInfoOffset(n)+1 );
1395 pItem = *ppItem;
1397 else if( bDocChanged )
1399 // other DocShell -> all new
1400 CheckItem( nActFamily, true );
1401 nActFilter = static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pDocShell ) );
1402 if ( SFXSTYLEBIT_ALL == nActFilter )
1403 nActFilter = pDocShell->GetAutoStyleFilterIndex();
1405 nAppFilter = pItem->GetValue();
1406 if(!pTreeBox)
1408 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1410 else
1411 FillTreeBox();
1413 else
1415 // other filters for automatic
1416 CheckItem( nActFamily, true );
1417 const SfxStyleFamilyItem *pStyleItem = GetFamilyItem_Impl();
1418 if ( pStyleItem && 0 == pStyleItem->GetFilterList()[ nActFilter ]->nFlags
1419 && nAppFilter != pItem->GetValue())
1421 nAppFilter = pItem->GetValue();
1422 if(!pTreeBox)
1423 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1424 else
1425 FillTreeBox();
1427 else
1428 nAppFilter = pItem->GetValue();
1430 const OUString aStyle(pItem->GetStyleName());
1431 SelectStyle(aStyle);
1432 EnableDelete();
1433 EnableNew( bCanNew );
1436 IMPL_LINK_NOARG_TYPED( SfxCommonTemplateDialog_Impl, TimeOut, Idle *, void )
1438 if(!bDontUpdate)
1440 bDontUpdate=true;
1441 if(!pTreeBox)
1442 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1443 else
1445 FillTreeBox();
1446 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1447 if(pState)
1449 const OUString aStyle(pState->GetStyleName());
1450 SelectStyle(aStyle);
1451 EnableDelete();
1454 bDontUpdate=false;
1455 DELETEZ(pIdle);
1457 else
1458 pIdle->Start();
1461 void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1463 // tap update
1464 const SfxSimpleHint* pSfxSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1465 if(pSfxSimpleHint)
1467 switch(pSfxSimpleHint->GetId())
1469 case SFX_HINT_UPDATEDONE:
1471 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1472 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
1473 if (
1474 bUpdate &&
1476 !IsCheckedItem(SID_STYLE_WATERCAN) ||
1477 (pDocShell && pDocShell->GetStyleSheetPool() != pStyleSheetPool)
1481 bUpdate = false;
1482 Update_Impl();
1484 else if ( bUpdateFamily )
1486 UpdateFamily_Impl();
1489 if( pStyleSheetPool )
1491 OUString aStr = GetSelectedEntry();
1492 if( !aStr.isEmpty() && pStyleSheetPool )
1494 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1495 if( !pItem ) break;
1496 const SfxStyleFamily eFam = pItem->GetFamily();
1497 SfxStyleSheetBase *pStyle =
1498 pStyleSheetPool->Find(
1499 aStr, eFam, SFXSTYLEBIT_ALL );
1500 if( pStyle )
1502 bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
1503 EnableEdit( bReadWrite );
1504 EnableHide( bReadWrite && !pStyle->IsUsed( ) && !pStyle->IsHidden( ) );
1505 EnableShow( bReadWrite && pStyle->IsHidden( ) );
1507 else
1509 EnableEdit(false);
1510 EnableHide(false);
1511 EnableShow(false);
1515 break;
1518 // Necessary if switching between documents and in both documents
1519 // the same template is used. Do not immediately call Update_Impl,
1520 // for the case that one of the documents is an internal InPlaceObjekt!
1521 case SFX_HINT_DOCCHANGED:
1522 bUpdate = true;
1523 break;
1524 case SFX_HINT_DYING:
1526 EndListening(*pStyleSheetPool);
1527 pStyleSheetPool=0;
1528 break;
1533 // Do not set timer when the stylesheet pool is in the box, because it is
1534 // possible that a new one is registered after the timer is up -
1535 // works bad in UpdateStyles_Impl ()!
1537 sal_uIntPtr nId = pSfxSimpleHint ? pSfxSimpleHint->GetId() : 0;
1539 if(!bDontUpdate && nId != SFX_HINT_DYING &&
1540 (dynamic_cast<const SfxStyleSheetPoolHint*>(&rHint) ||
1541 dynamic_cast<const SfxStyleSheetHint*>(&rHint) ||
1542 dynamic_cast<const SfxStyleSheetHintExtended*>(&rHint)))
1544 if(!pIdle)
1546 pIdle=new Idle;
1547 pIdle->SetPriority(SchedulerPriority::LOWEST);
1548 pIdle->SetIdleHdl(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut));
1550 pIdle->Start();
1555 // Other filters; can be switched by the users or as a result of new or
1556 // editing, if the current document has been assigned a different filter.
1557 void SfxCommonTemplateDialog_Impl::FilterSelect(
1558 sal_uInt16 nEntry, // Idx of the new Filters
1559 bool bForce ) // Force update, even if the new filter is
1560 // equal to the current
1562 if( nEntry != nActFilter || bForce )
1564 nActFilter = nEntry;
1565 SfxObjectShell *const pDocShell = SaveSelection();
1566 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
1567 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
1568 if ( pOldStyleSheetPool != pStyleSheetPool )
1570 if ( pOldStyleSheetPool )
1571 EndListening(*pOldStyleSheetPool);
1572 if ( pStyleSheetPool )
1573 StartListening(*pStyleSheetPool);
1576 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1580 // Internal: Perform functions through the Dispatcher
1581 bool SfxCommonTemplateDialog_Impl::Execute_Impl(
1582 sal_uInt16 nId, const OUString &rStr, const OUString& rRefStr, sal_uInt16 nFamily,
1583 sal_uInt16 nMask, sal_uInt16 *pIdx, const sal_uInt16* pModifier)
1585 SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
1586 SfxStringItem aItem(nId, rStr);
1587 SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
1588 SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
1589 SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
1590 SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
1591 const SfxPoolItem* pItems[ 6 ];
1592 sal_uInt16 nCount = 0;
1593 if( !rStr.isEmpty() )
1594 pItems[ nCount++ ] = &aItem;
1595 pItems[ nCount++ ] = &aFamily;
1596 if( nMask )
1597 pItems[ nCount++ ] = &aMask;
1598 if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
1600 // Special solution for Numbering update in Writer
1601 const OUString aTemplName(GetSelectedEntry());
1602 aUpdName.SetValue(aTemplName);
1603 pItems[ nCount++ ] = &aUpdName;
1606 if ( !rRefStr.isEmpty() )
1607 pItems[ nCount++ ] = &aRefName;
1609 pItems[ nCount++ ] = 0;
1611 DeletionWatcher aDeleted(*this);
1612 sal_uInt16 nModi = pModifier ? *pModifier : 0;
1613 const SfxPoolItem* pItem = rDispatcher.Execute(
1614 nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD | SfxCallMode::MODAL,
1615 pItems, nModi );
1617 // Dialog can be destroyed while in Execute() because started
1618 // subdialogs are not modal to it (#i97888#).
1619 if ( !pItem || aDeleted )
1620 return false;
1622 if ( (nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId) && (pTreeBox || aFmtLb->GetSelectionCount() <= 1) )
1624 const SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem);
1625 OSL_ENSURE(pFilterItem, "SfxUINT16Item expected");
1626 sal_uInt16 nFilterFlags = pFilterItem->GetValue() & ~SFXSTYLEBIT_USERDEF;
1627 if(!nFilterFlags) // User Template?
1628 nFilterFlags = pFilterItem->GetValue();
1629 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
1630 const size_t nFilterCount = pFamilyItem->GetFilterList().size();
1632 for ( size_t i = 0; i < nFilterCount; ++i )
1634 const SfxFilterTupel *pTupel = pFamilyItem->GetFilterList()[ i ];
1636 if ( ( pTupel->nFlags & nFilterFlags ) == nFilterFlags && pIdx )
1637 *pIdx = i;
1641 return true;
1644 // Handler der Listbox der Filter
1645 void SfxCommonTemplateDialog_Impl::EnableHierarchical(bool const bEnable)
1647 if (bEnable)
1649 if (!bHierarchical)
1651 // Turn on treeView
1652 bHierarchical=true;
1653 m_bWantHierarchical = true;
1654 SaveSelection(); // fdo#61429 store "hierarchical"
1655 const OUString aSelectEntry( GetSelectedEntry());
1656 aFmtLb->Hide();
1658 pTreeBox = VclPtr<StyleTreeListBox_Impl>::Create(
1660 this, WB_HASBUTTONS | WB_HASLINES |
1661 WB_BORDER | WB_TABSTOP | WB_HASLINESATROOT |
1662 WB_HASBUTTONSATROOT | WB_HIDESELECTION | WB_QUICK_SEARCH );
1663 pTreeBox->SetFont( aFmtLb->GetFont() );
1665 pTreeBox->SetPosSizePixel(aFmtLb->GetPosPixel(), aFmtLb->GetSizePixel());
1666 pTreeBox->SetNodeDefaultImages();
1667 pTreeBox->SetSelectHdl(
1668 LINK(this, SfxCommonTemplateDialog_Impl, FmtSelectHdl));
1669 pTreeBox->SetDoubleClickHdl(
1670 LINK(this, SfxCommonTemplateDialog_Impl, ApplyHdl));
1671 pTreeBox->SetDropHdl(LINK(this, SfxCommonTemplateDialog_Impl, DropHdl));
1672 pTreeBox->SetOptimalImageIndent();
1673 FillTreeBox();
1674 SelectStyle(aSelectEntry);
1675 pTreeBox->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
1676 pTreeBox->Show();
1679 else
1681 pTreeBox.disposeAndClear();
1682 aFmtLb->Show();
1683 // If bHierarchical, then the family can have changed
1684 // minus one since hierarchical is inserted at the start
1685 m_bWantHierarchical = false; // before FilterSelect
1686 FilterSelect(aFilterLb->GetSelectEntryPos() - 1, bHierarchical );
1687 bHierarchical=false;
1691 IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox )
1693 if (SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString() == pBox->GetSelectEntry())
1695 EnableHierarchical(true);
1697 else
1699 EnableHierarchical(false);
1702 return 0;
1705 // Select-Handler for the Toolbox
1706 void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry)
1708 if( nEntry != nActFamily )
1710 CheckItem( nActFamily, false );
1711 nActFamily = nEntry;
1712 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
1713 SfxUInt16Item aItem( SID_STYLE_FAMILY, nEntry );
1714 pDispat->Execute( SID_STYLE_FAMILY, SfxCallMode::SYNCHRON, &aItem, 0L );
1715 pBindings->Invalidate( SID_STYLE_FAMILY );
1716 pBindings->Update( SID_STYLE_FAMILY );
1717 UpdateFamily_Impl();
1721 void SfxCommonTemplateDialog_Impl::ActionSelect(sal_uInt16 nEntry)
1723 OUString aEmpty;
1724 switch(nEntry)
1726 case SID_STYLE_WATERCAN:
1728 const bool bState = IsCheckedItem(nEntry);
1729 bool bCheck;
1730 SfxBoolItem aBool;
1731 // when a template is chosen.
1732 if (!bState && HasSelectedStyle())
1734 const OUString aTemplName(
1735 GetSelectedEntry());
1736 Execute_Impl(
1737 SID_STYLE_WATERCAN, aTemplName, aEmpty,
1738 (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
1739 bCheck = true;
1741 else
1743 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
1744 bCheck = false;
1746 CheckItem(nEntry, bCheck);
1747 aBool.SetValue(bCheck);
1748 SetWaterCanState(&aBool);
1749 break;
1751 case SID_STYLE_NEW_BY_EXAMPLE:
1753 if(pStyleSheetPool && nActFamily != 0xffff)
1755 const SfxStyleFamily eFam=GetFamilyItem_Impl()->GetFamily();
1756 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1757 sal_uInt16 nFilter;
1758 if( pItem && nActFilter != SFXSTYLEBIT_ALL )
1760 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
1761 if(!nFilter) // automatisch
1762 nFilter = nAppFilter;
1764 else
1765 nFilter=pStyleSheetPool->GetSearchMask();
1766 pStyleSheetPool->SetSearchMask( eFam, SFXSTYLEBIT_USERDEF );
1768 ScopedVclPtrInstance< SfxNewStyleDlg > pDlg(pWindow, *pStyleSheetPool);
1769 // why? : FloatingWindow must not be parent of a modal dialog
1770 if(RET_OK == pDlg->Execute())
1772 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1773 const OUString aTemplName(pDlg->GetName());
1774 Execute_Impl(SID_STYLE_NEW_BY_EXAMPLE,
1775 aTemplName, aEmpty,
1776 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(),
1777 nFilter);
1779 pStyleSheetPool->SetSearchMask( eFam, nFilter );
1781 break;
1783 case SID_STYLE_UPDATE_BY_EXAMPLE:
1785 Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
1786 aEmpty, aEmpty,
1787 (sal_uInt16)GetFamilyItem_Impl()->GetFamily());
1788 break;
1790 case SID_TEMPLATE_LOAD:
1791 SfxGetpApp()->GetDispatcher_Impl()->Execute(nEntry);
1792 break;
1793 default: OSL_FAIL("not implemented"); break;
1797 static OUString getModuleIdentifier( const Reference< XModuleManager2 >& i_xModMgr, SfxObjectShell* i_pObjSh )
1799 OSL_ENSURE( i_xModMgr.is(), "getModuleIdentifier(): no XModuleManager" );
1800 OSL_ENSURE( i_pObjSh, "getModuleIdentifier(): no ObjectShell" );
1802 OUString sIdentifier;
1806 sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
1808 catch ( ::com::sun::star::frame::UnknownModuleException& )
1810 OSL_TRACE( "getModuleIdentifier(): unknown module" );
1812 catch ( Exception& )
1814 OSL_FAIL( "getModuleIdentifier(): exception of XModuleManager::identify()" );
1817 return sIdentifier;
1820 sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh )
1822 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
1823 sal_Int32 nFilter = -1;
1825 ::comphelper::SequenceAsHashMap aFactoryProps(
1826 xModuleManager->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
1827 sal_Int32 nDefault = -1;
1828 nFilter = aFactoryProps.getUnpackedValueOrDefault( "ooSetupFactoryStyleFilter", nDefault );
1830 m_bWantHierarchical =
1831 (nFilter & SFXSTYLEBIT_HIERARCHY) != 0;
1832 nFilter &= ~SFXSTYLEBIT_HIERARCHY; // clear it
1834 return nFilter;
1837 void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter )
1839 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
1840 Sequence< PropertyValue > lProps(1);
1841 lProps[0].Name = "ooSetupFactoryStyleFilter";
1842 lProps[0].Value = makeAny(
1843 i_nFilter | (m_bWantHierarchical ? SFXSTYLEBIT_HIERARCHY : 0));
1844 xModuleManager->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) );
1847 SfxObjectShell* SfxCommonTemplateDialog_Impl::SaveSelection()
1849 SfxViewFrame *const pViewFrame(pBindings->GetDispatcher_Impl()->GetFrame());
1850 SfxObjectShell *const pDocShell(pViewFrame->GetObjectShell());
1851 if (pDocShell)
1853 pDocShell->SetAutoStyleFilterIndex(nActFilter);
1854 SaveFactoryStyleFilter( pDocShell, nActFilter );
1856 return pDocShell;
1859 IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox )
1861 bDontUpdate=true;
1862 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1863 const SfxStyleFamily eFam = pItem->GetFamily();
1864 long ret= pStyleSheetPool->SetParent(eFam,pBox->GetStyle(), pBox->GetParent())? 1L: 0L;
1865 bDontUpdate=false;
1866 return ret;
1869 // Handler for the New-Buttons
1870 void SfxCommonTemplateDialog_Impl::NewHdl(void *)
1872 OUString aEmpty;
1873 if ( nActFamily != 0xffff && (pTreeBox || aFmtLb->GetSelectionCount() <= 1))
1875 vcl::Window* pTmp;
1876 pTmp = Application::GetDefDialogParent();
1877 if ( ISA(SfxTemplateDialog_Impl) )
1878 Application::SetDefDialogParent( pWindow->GetParent() );
1879 else
1880 Application::SetDefDialogParent( pWindow );
1882 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1883 const SfxStyleFamily eFam=pItem->GetFamily();
1884 sal_uInt16 nMask;
1885 if( nActFilter != SFXSTYLEBIT_ALL )
1887 nMask = pItem->GetFilterList()[ nActFilter ]->nFlags;
1888 if(!nMask) // automatic
1889 nMask = nAppFilter;
1891 else
1892 nMask=pStyleSheetPool->GetSearchMask();
1894 pStyleSheetPool->SetSearchMask(eFam,nMask);
1896 Execute_Impl(SID_STYLE_NEW,
1897 aEmpty, GetSelectedEntry(),
1898 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
1899 nMask);
1901 Application::SetDefDialogParent( pTmp );
1905 // Handler for the edit-Buttons
1906 void SfxCommonTemplateDialog_Impl::EditHdl(void *)
1908 if(IsInitialized() && HasSelectedStyle())
1910 sal_uInt16 nFilter = nActFilter;
1911 OUString aTemplName(GetSelectedEntry());
1912 GetSelectedStyle(); // -Wall required??
1913 vcl::Window* pTmp;
1914 //DefModalDialogParent set for modality of the following dialogs
1915 pTmp = Application::GetDefDialogParent();
1916 if ( ISA(SfxTemplateDialog_Impl) )
1917 Application::SetDefDialogParent( pWindow->GetParent() );
1918 else
1919 Application::SetDefDialogParent( pWindow );
1920 if ( Execute_Impl( SID_STYLE_EDIT, aTemplName, OUString(),
1921 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(), 0, &nFilter ) )
1924 Application::SetDefDialogParent( pTmp );
1928 // Handler for the Delete-Buttons
1929 void SfxCommonTemplateDialog_Impl::DeleteHdl(void *)
1931 if ( IsInitialized() && HasSelectedStyle() )
1933 bool bUsedStyle = false; // one of the selected styles are used in the document?
1935 std::vector<SvTreeListEntry*> aList;
1936 SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
1937 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1939 OUString aMsg = SfxResId(STR_DELETE_STYLE_USED).toString();
1940 aMsg += SfxResId(STR_DELETE_STYLE).toString();
1942 while (pEntry)
1944 aList.push_back( pEntry );
1945 // check the style is used or not
1946 const OUString aTemplName(pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry));
1948 SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
1950 if ( pStyle->IsUsed() ) // pStyle is in use in the document?
1952 if (bUsedStyle) // add a separator for the second and later styles
1953 aMsg += ", ";
1954 aMsg += aTemplName;
1955 bUsedStyle = true;
1958 pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
1961 bool aApproved = false;
1963 // we only want to show the dialog once and if we want to delete a style in use (UX-advice)
1964 if ( bUsedStyle )
1966 #if defined UNX
1967 ScopedVclPtrInstance<MessageDialog> aBox(SfxGetpApp()->GetTopWindow(), aMsg,
1968 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
1969 #else
1970 ScopedVclPtrInstance<MessageDialog> aBox(GetWindow(), aMsg,
1971 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
1972 #endif
1973 aApproved = aBox->Execute() == RET_YES;
1976 // if there are no used styles selected or the user approved the changes
1977 if ( !bUsedStyle || aApproved )
1979 std::vector<SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end();
1981 for (; it != itEnd; ++it)
1983 const OUString aTemplName(pTreeBox ? pTreeBox->GetEntryText(*it) : aFmtLb->GetEntryText(*it));
1984 bDontUpdate = true; // To prevent the Treelistbox to shut down while deleting
1985 Execute_Impl( SID_STYLE_DELETE, aTemplName,
1986 OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
1988 if ( pTreeBox )
1990 pTreeBox->RemoveParentKeepChildren( *it );
1991 bDontUpdate = false;
1994 bDontUpdate = false; //if everything is deleted set bDontUpdate back to false
1995 UpdateStyles_Impl(UPDATE_FAMILY_LIST); //and force-update the list
2000 void SfxCommonTemplateDialog_Impl::HideHdl(void *)
2002 if ( IsInitialized() && HasSelectedStyle() )
2004 SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
2006 while (pEntry)
2008 OUString aTemplName = pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry);
2010 Execute_Impl( SID_STYLE_HIDE, aTemplName,
2011 OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2013 pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
2018 void SfxCommonTemplateDialog_Impl::ShowHdl(void *)
2021 if ( IsInitialized() && HasSelectedStyle() )
2023 SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
2025 while (pEntry)
2027 OUString aTemplName = pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry);
2029 Execute_Impl( SID_STYLE_SHOW, aTemplName,
2030 OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2032 pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
2037 void SfxCommonTemplateDialog_Impl::EnableDelete()
2039 if(IsInitialized() && HasSelectedStyle())
2041 OSL_ENSURE(pStyleSheetPool, "No StyleSheetPool");
2042 const OUString aTemplName(GetSelectedEntry());
2043 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
2044 const SfxStyleFamily eFam = pItem->GetFamily();
2045 sal_uInt16 nFilter = 0;
2046 if(pItem->GetFilterList().size() > nActFilter)
2047 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
2048 if(!nFilter) // automatic
2049 nFilter = nAppFilter;
2050 const SfxStyleSheetBase *pStyle =
2051 pStyleSheetPool->Find(aTemplName,eFam, pTreeBox? SFXSTYLEBIT_ALL : nFilter);
2053 OSL_ENSURE(pStyle, "Style not found");
2054 if(pStyle && pStyle->IsUserDefined())
2056 EnableDel(true);
2058 else
2060 EnableDel(false);
2063 else
2065 EnableDel(false);
2069 // After selecting a focused item if possible again on the app window
2070 void SfxCommonTemplateDialog_Impl::ResetFocus()
2072 if(ISA(SfxTemplateDialog_Impl))
2074 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
2075 SfxViewShell *pVu = pViewFrame->GetViewShell();
2076 vcl::Window *pAppWin = pVu ? pVu->GetWindow(): 0;
2077 if(pAppWin)
2078 pAppWin->GrabFocus();
2082 // Double-click on a style sheet in the ListBox is applied.
2083 IMPL_LINK( SfxCommonTemplateDialog_Impl, ApplyHdl, Control *, pControl )
2085 (void)pControl; //unused
2086 // only if that region is allowed
2087 if ( IsInitialized() && 0 != pFamilyState[nActFamily-1] &&
2088 !GetSelectedEntry().isEmpty() )
2090 sal_uInt16 nModifier = aFmtLb->GetModifier();
2091 Execute_Impl(SID_STYLE_APPLY,
2092 GetSelectedEntry(), OUString(),
2093 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2094 0, 0, &nModifier );
2096 ResetFocus();
2097 return 0;
2100 // Selection of a template during the Watercan-Status
2101 IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox )
2103 // Trigger Help PI, if this is permitted of call handlers and field
2104 if( !pListBox || pListBox->IsSelected( pListBox->GetHdlEntry() ) )
2106 // Only when the watercan is on
2107 if ( IsInitialized() &&
2108 IsCheckedItem(SID_STYLE_WATERCAN) &&
2109 // only if that region is allowed
2110 0 != pFamilyState[nActFamily-1] && (pTreeBox || aFmtLb->GetSelectionCount() <= 1) )
2112 OUString aEmpty;
2113 Execute_Impl(SID_STYLE_WATERCAN,
2114 aEmpty, aEmpty, 0);
2115 Execute_Impl(SID_STYLE_WATERCAN,
2116 GetSelectedEntry(), aEmpty,
2117 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily());
2119 EnableItem(SID_STYLE_WATERCAN, !bWaterDisabled);
2120 EnableDelete();
2122 if( pListBox )
2124 SelectStyle( pListBox->GetEntryText( pListBox->GetHdlEntry() ));
2125 #if defined STYLESPREVIEW
2126 sal_uInt16 nModifier = aFmtLb->GetModifier();
2127 if ( mbIgnoreSelect )
2129 Execute_Impl(SID_STYLE_END_PREVIEW,
2130 OUString(), OUString(),
2131 0, 0, 0, 0 );
2132 mbIgnoreSelect = false;
2134 else
2136 Execute_Impl(SID_STYLE_PREVIEW,
2137 GetSelectedEntry(), OUString(),
2138 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2139 0, 0, &nModifier );
2141 #endif
2144 return 0;
2147 IMPL_LINK( SfxCommonTemplateDialog_Impl, MenuSelectHdl, Menu *, pMenu )
2149 if( pMenu )
2151 nLastItemId = pMenu->GetCurItemId();
2152 Application::PostUserEvent(
2153 LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ), 0 );
2154 return sal_IntPtr(true);
2157 switch(nLastItemId) {
2158 case ID_NEW: NewHdl(0); break;
2159 case ID_EDIT: EditHdl(0); break;
2160 case ID_DELETE: DeleteHdl(0); break;
2161 case ID_HIDE: HideHdl(0); break;
2162 case ID_SHOW: ShowHdl(0); break;
2163 default: return sal_IntPtr(false);
2165 return sal_IntPtr(true);
2168 SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const
2170 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
2171 if( !pFamilyItem || nActFamily == 0xffff )
2172 return SFX_STYLE_FAMILY_PARA;
2173 else
2174 return pFamilyItem->GetFamily();
2177 void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, bool bEnable)
2179 if( nId == SID_STYLE_NEW_BY_EXAMPLE )
2181 bNewByExampleDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1) || !bEnable;
2183 else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
2184 bUpdateByExampleDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1) || !bEnable;
2186 EnableItem(nId, bEnable);
2189 PopupMenu* SfxCommonTemplateDialog_Impl::CreateContextMenu()
2191 if ( bBindingUpdate )
2193 pBindings->Invalidate( SID_STYLE_NEW, true, false );
2194 pBindings->Update( SID_STYLE_NEW );
2195 bBindingUpdate = false;
2197 PopupMenu* pMenu = new PopupMenu( SfxResId( MN_CONTEXT_TEMPLDLG ) );
2198 pMenu->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ) );
2199 pMenu->EnableItem( ID_EDIT, bCanEdit );
2200 pMenu->EnableItem( ID_DELETE, bCanDel );
2201 pMenu->EnableItem( ID_NEW, bCanNew );
2202 pMenu->EnableItem( ID_HIDE, bCanHide );
2203 pMenu->EnableItem( ID_SHOW, bCanShow );
2205 return pMenu;
2208 SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(SfxBindings* pB, SfxTemplatePanelControl* pDlgWindow)
2209 : SfxCommonTemplateDialog_Impl(pB, pDlgWindow, true)
2210 , m_pFloat(pDlgWindow)
2211 , m_bZoomIn(false)
2212 , m_aActionTbL(VclPtrInstance<DropToolBox_Impl>(pDlgWindow, this))
2213 , m_aActionTbR(VclPtrInstance<ToolBox> (pDlgWindow, SfxResId(TB_ACTION)))
2215 pDlgWindow->FreeResource();
2216 Initialize();
2219 void SfxTemplateDialog_Impl::Initialize()
2221 SfxCommonTemplateDialog_Impl::Initialize();
2223 m_aActionTbL->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
2224 m_aActionTbR->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
2225 m_aActionTbR->SetDropdownClickHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRClick));
2226 m_aActionTbL->Show();
2227 m_aActionTbR->Show();
2228 vcl::Font aFont = aFilterLb->GetFont();
2229 aFont.SetWeight( WEIGHT_NORMAL );
2230 aFilterLb->SetFont( aFont );
2231 m_aActionTbL->SetHelpId( HID_TEMPLDLG_TOOLBOX_LEFT );
2234 void SfxTemplateDialog_Impl::EnableFamilyItem( sal_uInt16 nId, bool bEnable )
2236 m_aActionTbL->EnableItem( nId, bEnable );
2239 // Insert element into dropdown filter "Frame Styles", "List Styles", etc.
2240 void SfxTemplateDialog_Impl::InsertFamilyItem(sal_uInt16 nId,const SfxStyleFamilyItem *pItem)
2242 OString sHelpId;
2243 switch( (sal_uInt16) pItem->GetFamily() )
2245 case SFX_STYLE_FAMILY_CHAR: sHelpId = ".uno:CharStyle"; break;
2246 case SFX_STYLE_FAMILY_PARA: sHelpId = ".uno:ParaStyle"; break;
2247 case SFX_STYLE_FAMILY_FRAME: sHelpId = ".uno:FrameStyle"; break;
2248 case SFX_STYLE_FAMILY_PAGE: sHelpId = ".uno:PageStyle"; break;
2249 case SFX_STYLE_FAMILY_PSEUDO: sHelpId = ".uno:ListStyle"; break;
2250 default: OSL_FAIL("unknown StyleFamily"); break;
2252 m_aActionTbL->InsertItem( nId, pItem->GetImage(), pItem->GetText(), ToolBoxItemBits::NONE, 0);
2253 m_aActionTbL->SetHelpId( nId, sHelpId );
2256 void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2258 m_aActionTbR->HideItem(SID_STYLE_UPDATE_BY_EXAMPLE);
2259 m_aActionTbR->SetItemBits( SID_STYLE_NEW_BY_EXAMPLE,
2260 ToolBoxItemBits::DROPDOWNONLY|m_aActionTbR->GetItemBits( SID_STYLE_NEW_BY_EXAMPLE ));
2263 void SfxTemplateDialog_Impl::updateFamilyImages()
2265 if ( !m_pStyleFamiliesId )
2266 // we do not have a resource id to load the new images from
2267 return;
2269 // let the families collection update the images
2270 pStyleFamilies->updateImages( *m_pStyleFamiliesId );
2272 // and set the new images on our toolbox
2273 size_t nLoop = pStyleFamilies->size();
2274 for( ; nLoop--; )
2276 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nLoop );
2277 sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId( pItem->GetFamily() );
2278 m_aActionTbL->SetItemImage( nId, pItem->GetImage() );
2282 void SfxTemplateDialog_Impl::updateNonFamilyImages()
2284 m_aActionTbR->SetImageList( ImageList( SfxResId( DLG_STYLE_DESIGNER ) ) );
2287 void SfxTemplateDialog_Impl::ClearFamilyList()
2289 m_aActionTbL->Clear();
2292 void SfxCommonTemplateDialog_Impl::InvalidateBindings()
2294 pBindings->Invalidate(SID_STYLE_NEW_BY_EXAMPLE, true, false);
2295 pBindings->Update( SID_STYLE_NEW_BY_EXAMPLE );
2296 pBindings->Invalidate(SID_STYLE_UPDATE_BY_EXAMPLE, true, false);
2297 pBindings->Update( SID_STYLE_UPDATE_BY_EXAMPLE );
2298 pBindings->Invalidate( SID_STYLE_WATERCAN, true, false);
2299 pBindings->Update( SID_STYLE_WATERCAN );
2300 pBindings->Invalidate( SID_STYLE_NEW, true, false );
2301 pBindings->Update( SID_STYLE_NEW );
2302 pBindings->Invalidate( SID_STYLE_DRAGHIERARCHIE, true, false );
2303 pBindings->Update( SID_STYLE_DRAGHIERARCHIE );
2306 SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
2308 m_pFloat.clear();
2309 m_aActionTbL.disposeAndClear();
2310 m_aActionTbR.disposeAndClear();
2313 void SfxTemplateDialog_Impl::LoadedFamilies()
2315 updateFamilyImages();
2316 Resize();
2319 // Override Resize-Handler ( StarView )
2320 // The size of the Listboxen is adjusted
2321 void SfxTemplateDialog_Impl::Resize()
2323 SfxDockingWindow* pDockingWindow = dynamic_cast<SfxDockingWindow*>(m_pFloat.get());
2324 FloatingWindow *pF = pDockingWindow!=NULL ? pDockingWindow->GetFloatingWindow() : NULL;
2325 if (pF)
2327 m_bZoomIn = pF->IsRollUp();
2328 if (m_bZoomIn)
2329 return;
2332 if (m_pFloat == nullptr)
2333 return;
2334 Size aDlgSize=m_pFloat->PixelToLogic(m_pFloat->GetOutputSizePixel());
2335 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL->CalcWindowSizePixel());
2336 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR->CalcWindowSizePixel());
2337 Size aMinSize = GetMinOutputSizePixel();
2339 long nListHeight = m_pFloat->PixelToLogic( aFilterLb->GetSizePixel() ).Height();
2340 long nWidth = aDlgSize.Width()- 2 * SFX_TEMPLDLG_HFRAME;
2342 m_aActionTbL->SetPosSizePixel(m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,SFX_TEMPLDLG_VTOPFRAME)),
2343 m_pFloat->LogicToPixel(aSizeATL));
2345 // only change the position of the right toolbox, when the window is wide
2346 // enough
2347 Point aPosATR(aDlgSize.Width()-SFX_TEMPLDLG_HFRAME-aSizeATR.Width(),SFX_TEMPLDLG_VTOPFRAME);
2348 if(aDlgSize.Width() >= aMinSize.Width())
2349 m_aActionTbR->SetPosPixel(m_pFloat->LogicToPixel(aPosATR));
2350 else
2351 m_aActionTbR->SetPosPixel( m_pFloat->LogicToPixel(
2352 Point( SFX_TEMPLDLG_HFRAME + aSizeATL.Width() + SFX_TEMPLDLG_MIDHSPACE,
2353 SFX_TEMPLDLG_VTOPFRAME ) ) );
2355 m_aActionTbR->SetSizePixel(m_pFloat->LogicToPixel(aSizeATR));
2357 Point aFilterPos(
2358 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,
2359 aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-nListHeight)) );
2361 Size aFilterSize(
2362 m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) );
2364 Point aFmtPos(
2365 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME +
2366 SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) );
2367 Size aFmtSize(
2368 m_pFloat->LogicToPixel(Size(nWidth,
2369 aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME -
2370 SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE-
2371 nListHeight-aSizeATL.Height())) );
2373 // only change the position of the listbox, when the window is high enough
2374 if(aDlgSize.Height() >= aMinSize.Height())
2376 aFilterLb->SetPosPixel(aFilterPos);
2377 aFmtLb->SetPosPixel( aFmtPos );
2378 if(pTreeBox)
2379 pTreeBox->SetPosPixel(aFmtPos);
2381 else
2382 aFmtSize.Height() += aFilterSize.Height();
2384 aFilterLb->SetSizePixel(aFilterSize);
2385 aFmtLb->SetSizePixel( aFmtSize );
2386 if(pTreeBox)
2387 pTreeBox->SetSizePixel(aFmtSize);
2390 Size SfxTemplateDialog_Impl::GetMinOutputSizePixel()
2392 if (m_pFloat != nullptr)
2394 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL->CalcWindowSizePixel());
2395 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR->CalcWindowSizePixel());
2396 Size aMinSize=Size(
2397 aSizeATL.Width()+aSizeATR.Width()+
2398 2*SFX_TEMPLDLG_HFRAME + SFX_TEMPLDLG_MIDHSPACE,
2399 4*aSizeATL.Height()+2*SFX_TEMPLDLG_MIDVSPACE);
2400 return aMinSize;
2402 else
2403 return Size(0,0);
2406 void SfxTemplateDialog_Impl::EnableItem(sal_uInt16 nMesId, bool bCheck)
2408 OUString aEmpty;
2409 switch(nMesId)
2411 case SID_STYLE_WATERCAN :
2412 if(!bCheck && IsCheckedItem(SID_STYLE_WATERCAN))
2413 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
2414 //fall-through
2415 case SID_STYLE_NEW_BY_EXAMPLE:
2416 case SID_STYLE_UPDATE_BY_EXAMPLE:
2417 m_aActionTbR->EnableItem(nMesId,bCheck);
2418 break;
2422 void SfxTemplateDialog_Impl::CheckItem(sal_uInt16 nMesId, bool bCheck)
2424 switch(nMesId)
2426 case SID_STYLE_WATERCAN :
2427 bIsWater=bCheck;
2428 m_aActionTbR->CheckItem(SID_STYLE_WATERCAN,bCheck);
2429 break;
2430 default:
2431 m_aActionTbL->CheckItem(nMesId,bCheck); break;
2435 bool SfxTemplateDialog_Impl::IsCheckedItem(sal_uInt16 nMesId)
2437 switch(nMesId)
2439 case SID_STYLE_WATERCAN :
2440 return m_aActionTbR->GetItemState(SID_STYLE_WATERCAN)==TRISTATE_TRUE;
2441 default:
2442 return m_aActionTbL->GetItemState(nMesId)==TRISTATE_TRUE;
2446 IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox, void )
2448 const sal_uInt16 nEntry = pBox->GetCurItemId();
2449 FamilySelect(nEntry);
2452 static OUString lcl_GetLabel(uno::Any& rAny)
2454 OUString sRet;
2455 uno::Sequence< beans::PropertyValue >aPropSeq;
2456 if ( rAny >>= aPropSeq )
2458 for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
2460 if ( aPropSeq[i].Name == "Label" )
2462 aPropSeq[i].Value >>= sRet;
2463 break;
2467 return sRet;
2470 IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxRSelect, ToolBox *, pBox, void )
2472 const sal_uInt16 nEntry = pBox->GetCurItemId();
2473 if(nEntry != SID_STYLE_NEW_BY_EXAMPLE ||
2474 ToolBoxItemBits::DROPDOWN != (pBox->GetItemBits(nEntry)&ToolBoxItemBits::DROPDOWN))
2475 ActionSelect(nEntry);
2478 IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxRClick, ToolBox *, pBox, void )
2480 const sal_uInt16 nEntry = pBox->GetCurItemId();
2481 if(nEntry == SID_STYLE_NEW_BY_EXAMPLE &&
2482 ToolBoxItemBits::DROPDOWN == (pBox->GetItemBits(nEntry)&ToolBoxItemBits::DROPDOWN))
2484 //create a popup menu in Writer
2485 boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
2486 uno::Reference< container::XNameAccess > xNameAccess(
2487 frame::theUICommandDescription::get(
2488 ::comphelper::getProcessComponentContext()) );
2489 uno::Reference< container::XNameAccess > xUICommands;
2490 OUString sTextDoc("com.sun.star.text.TextDocument");
2491 if(xNameAccess->hasByName(sTextDoc))
2493 uno::Any a = xNameAccess->getByName( sTextDoc );
2494 a >>= xUICommands;
2496 if(!xUICommands.is())
2497 return;
2500 uno::Any aCommand = xUICommands->getByName(".uno:StyleNewByExample");
2501 OUString sLabel = lcl_GetLabel( aCommand );
2502 pMenu->InsertItem( SID_STYLE_NEW_BY_EXAMPLE, sLabel );
2503 pMenu->SetHelpId(SID_STYLE_NEW_BY_EXAMPLE, HID_TEMPLDLG_NEWBYEXAMPLE);
2505 aCommand = xUICommands->getByName(".uno:StyleUpdateByExample");
2506 sLabel = lcl_GetLabel( aCommand );
2508 pMenu->InsertItem( SID_STYLE_UPDATE_BY_EXAMPLE, sLabel );
2509 pMenu->SetHelpId(SID_STYLE_UPDATE_BY_EXAMPLE, HID_TEMPLDLG_UPDATEBYEXAMPLE);
2511 aCommand = xUICommands->getByName(".uno:LoadStyles");
2512 sLabel = lcl_GetLabel( aCommand );
2513 pMenu->InsertItem( SID_TEMPLATE_LOAD, sLabel );
2514 pMenu->SetHelpId(SID_TEMPLATE_LOAD, ".uno:LoadStyles");
2516 pMenu->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, MenuSelectHdl));
2517 pMenu->Execute( pBox,
2518 pBox->GetItemRect(nEntry),
2519 PopupMenuFlags::ExecuteDown );
2520 pBox->EndSelection();
2522 catch(uno::Exception&)
2525 pBox->Invalidate();
2529 IMPL_LINK( SfxTemplateDialog_Impl, MenuSelectHdl, Menu*, pMenu)
2531 sal_uInt16 nMenuId = pMenu->GetCurItemId();
2532 ActionSelect(nMenuId);
2533 return 0;
2536 void SfxCommonTemplateDialog_Impl::SetFamily( sal_uInt16 nId )
2538 if ( nId != nActFamily )
2540 if ( nActFamily != 0xFFFF )
2541 CheckItem( nActFamily, false );
2542 nActFamily = nId;
2543 if ( nId != 0xFFFF )
2544 bUpdateFamily = true;
2548 void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl()
2550 bUpdateFamily = false;
2552 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
2553 SfxViewFrame *pViewFrame = pDispat->GetFrame();
2554 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
2556 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
2557 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
2558 if ( pOldStyleSheetPool != pStyleSheetPool )
2560 if ( pOldStyleSheetPool )
2561 EndListening(*pOldStyleSheetPool);
2562 if ( pStyleSheetPool )
2563 StartListening(*pStyleSheetPool);
2566 bWaterDisabled = false;
2567 bCanNew = pTreeBox || aFmtLb->GetSelectionCount() <= 1;
2568 bTreeDrag = true;
2569 bUpdateByExampleDisabled = false;
2571 if (pStyleSheetPool)
2573 if (!pTreeBox)
2574 UpdateStyles_Impl(UPDATE_FAMILY | UPDATE_FAMILY_LIST);
2575 else
2577 UpdateStyles_Impl(UPDATE_FAMILY);
2578 FillTreeBox();
2582 InvalidateBindings();
2584 if (IsCheckedItem(SID_STYLE_WATERCAN) &&
2585 // only if that area is allowed
2586 0 != pFamilyState[nActFamily - 1])
2588 Execute_Impl(SID_STYLE_APPLY,
2589 GetSelectedEntry(),
2590 OUString(),
2591 static_cast<sal_uInt16>(GetFamilyItem_Impl()->GetFamily()));
2595 void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2597 //does nothing
2600 DropToolBox_Impl::DropToolBox_Impl(vcl::Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog) :
2601 ToolBox(pParent),
2602 DropTargetHelper(this),
2603 rParent(*pTemplateDialog)
2607 sal_Int8 DropToolBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
2609 sal_Int8 nReturn = DND_ACTION_NONE;
2610 sal_uInt16 nItemId = GetItemId( rEvt.maPosPixel );
2611 if(USHRT_MAX != nItemId && !IsItemChecked( nItemId ))
2613 SetCurItemId(nItemId);
2614 GetSelectHdl().Call(this);
2616 // special case: page styles are allowed to create new styles by example
2617 // but not allowed to be created by drag and drop
2618 if ( nItemId != SfxTemplate::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE )&&
2619 IsDropFormatSupported( SotClipboardFormatId::OBJECTDESCRIPTOR ) &&
2620 !rParent.bNewByExampleDisabled )
2622 nReturn = DND_ACTION_COPY;
2624 return nReturn;
2627 sal_Int8 DropToolBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
2629 return rParent.aFmtLb->ExecuteDrop(rEvt);
2632 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */