LCOV - code coverage report
Current view: top level - sfx2/source/dialog - templdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 1330 0.3 %
Date: 2015-06-13 12:38:46 Functions: 3 146 2.1 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <boost/noncopyable.hpp>
      21             : 
      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             : 
      36             : #include <sfx2/sfxhelp.hxx>
      37             : #include <sfx2/app.hxx>
      38             : #include <sfx2/dispatch.hxx>
      39             : #include <sfx2/bindings.hxx>
      40             : #include <sfx2/templdlg.hxx>
      41             : #include "templdgi.hxx"
      42             : #include "tplcitem.hxx"
      43             : #include "sfxtypes.hxx"
      44             : #include <sfx2/styfitem.hxx>
      45             : #include <sfx2/objsh.hxx>
      46             : #include <sfx2/viewsh.hxx>
      47             : #include <sfx2/newstyle.hxx>
      48             : #include <sfx2/tplpitem.hxx>
      49             : #include <sfx2/sfxresid.hxx>
      50             : 
      51             : #include "templdlg.hrc"
      52             : #include <sfx2/sfx.hrc>
      53             : #include "dialog.hrc"
      54             : #include "arrdecl.hxx"
      55             : #include <sfx2/docfilt.hxx>
      56             : #include <sfx2/docfac.hxx>
      57             : #include <sfx2/doctempl.hxx>
      58             : #include <sfx2/module.hxx>
      59             : #include <sfx2/imgmgr.hxx>
      60             : #include "helpid.hrc"
      61             : #include "appdata.hxx"
      62             : #include <sfx2/viewfrm.hxx>
      63             : 
      64             : #include <svtools/svlbitm.hxx>
      65             : #include <svtools/treelistentry.hxx>
      66             : #include <comphelper/string.hxx>
      67             : 
      68             : #include <sfx2/StyleManager.hxx>
      69             : #include <sfx2/StylePreviewRenderer.hxx>
      70             : 
      71             : using namespace css;
      72             : using namespace css::beans;
      73             : using namespace css::frame;
      74             : using namespace css::uno;
      75             : 
      76             : namespace
      77             : {
      78             : 
      79             : class StyleLBoxString : public SvLBoxString
      80             : {
      81             :     SfxStyleFamily meStyleFamily;
      82             :     std::unique_ptr<sfx2::StylePreviewRenderer> mpStylePreviewRenderer;
      83             : 
      84             : public:
      85             :     StyleLBoxString(SvTreeListEntry* pEntry,
      86             :                     sal_uInt16 nFlags,
      87             :                     const OUString& sText,
      88             :                     const SfxStyleFamily& eStyleFamily);
      89             : 
      90             :     virtual ~StyleLBoxString();
      91             : 
      92             :     virtual void Paint(const Point& aPos,
      93             :                        SvTreeListBox& rDevice,
      94             :                        vcl::RenderContext& rRenderContext,
      95             :                        const SvViewDataEntry* pView,
      96             :                        const SvTreeListEntry& rEntry) SAL_OVERRIDE;
      97             : 
      98             :     virtual void InitViewData(SvTreeListBox* pView,
      99             :                               SvTreeListEntry* pEntry,
     100             :                               SvViewDataItem* pViewData) SAL_OVERRIDE;
     101             : };
     102             : 
     103             : 
     104           0 : StyleLBoxString::StyleLBoxString(SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& sText, const SfxStyleFamily& eStyleFamily)
     105             :     : SvLBoxString(pEntry, nFlags, sText)
     106           0 :     , meStyleFamily(eStyleFamily)
     107           0 : {}
     108             : 
     109           0 : StyleLBoxString::~StyleLBoxString()
     110           0 : {}
     111             : 
     112           0 : void StyleLBoxString::InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
     113             : {
     114           0 :     if (!pViewData)
     115             :     {
     116           0 :         pViewData = pView->GetViewDataItem(pEntry, this);
     117             :     }
     118             : 
     119           0 :     SfxObjectShell* pShell = SfxObjectShell::Current();
     120           0 :     if (!pShell)
     121           0 :         return;
     122             : 
     123           0 :     sfx2::StyleManager* pStyleManager = pShell->GetStyleManager();
     124             : 
     125           0 :     if (!pStyleManager)
     126             :     {
     127           0 :         return;
     128             :     }
     129           0 :     mpStylePreviewRenderer.reset(pStyleManager->CreateStylePreviewRenderer(*pView, GetText(), meStyleFamily, 32 * pView->GetDPIScaleFactor()));
     130             : 
     131           0 :     if (!mpStylePreviewRenderer)
     132             :     {
     133           0 :         return;
     134             :     }
     135             : 
     136           0 :     if (mpStylePreviewRenderer->recalculate())
     137             :     {
     138           0 :         pViewData->maSize = mpStylePreviewRenderer->getRenderSize();
     139             :     }
     140             :     else
     141             :     {
     142           0 :         SvLBoxString::InitViewData(pView, pEntry, pViewData);
     143             :     }
     144             : }
     145             : 
     146           0 : void StyleLBoxString::Paint(
     147             :     const Point& aPos, SvTreeListBox& /*rDevice*/, vcl::RenderContext& rRenderContext,
     148             :     const SvViewDataEntry* pView, const SvTreeListEntry& /*rEntry*/)
     149             : {
     150           0 :     bool bResult = false;
     151             : 
     152           0 :     if (mpStylePreviewRenderer)
     153             :     {
     154           0 :         Rectangle aPaintRectangle = pView->GetPaintRectangle();
     155           0 :         bResult = mpStylePreviewRenderer->render(aPaintRectangle);
     156             :     }
     157             : 
     158           0 :     if (!bResult)
     159             :     {
     160           0 :         rRenderContext.DrawText(aPos, GetText());
     161             :     }
     162           0 : }
     163             : 
     164             : } // end anonymous namespace
     165             : 
     166             : // Window is now created dynamically. So here margins, etc.
     167             : 
     168             : #define SFX_TEMPLDLG_HFRAME         3
     169             : #define SFX_TEMPLDLG_VTOPFRAME      3
     170             : 
     171             : #define SFX_TEMPLDLG_VBOTFRAME      3
     172             : #define SFX_TEMPLDLG_MIDHSPACE      3
     173             : #define SFX_TEMPLDLG_MIDVSPACE      3
     174             : #define SFX_TEMPLDLG_FILTERHEIGHT   100
     175             : 
     176             : static sal_uInt16 nLastItemId = USHRT_MAX;
     177             : 
     178             : // filter box has maximum 14 entries visible
     179             : #define MAX_FILTER_ENTRIES          14
     180             : 
     181             : 
     182           0 : TYPEINIT0(SfxCommonTemplateDialog_Impl);
     183           0 : TYPEINIT1(SfxTemplateDialog_Impl,SfxCommonTemplateDialog_Impl);
     184             : 
     185             : class SfxCommonTemplateDialog_Impl::DeletionWatcher : private boost::noncopyable
     186             : {
     187             :     typedef void (DeletionWatcher::* bool_type)();
     188             : 
     189             : public:
     190           0 :     explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
     191             :         : m_pDialog(&rDialog)
     192           0 :         , m_pPrevious(m_pDialog->impl_setDeletionWatcher(this))
     193             :     {
     194           0 :     }
     195             : 
     196           0 :     ~DeletionWatcher()
     197             :     {
     198           0 :         if (m_pDialog)
     199           0 :             m_pDialog->impl_setDeletionWatcher(m_pPrevious);
     200           0 :     }
     201             : 
     202             :     // Signal that the dialog was deleted
     203           0 :     void signal()
     204             :     {
     205           0 :         m_pDialog = 0;
     206           0 :         if (m_pPrevious)
     207           0 :             m_pPrevious->signal();
     208           0 :     }
     209             : 
     210             :     // Return true if the dialog was deleted
     211           0 :     operator bool_type() const
     212             :     {
     213           0 :         return m_pDialog ? 0 : &DeletionWatcher::signal;
     214             :     }
     215             : 
     216             : private:
     217             :     SfxCommonTemplateDialog_Impl* m_pDialog;
     218             :     DeletionWatcher *const m_pPrevious; /// let's add more epicycles!
     219             : };
     220             : 
     221           0 : void DropListBox_Impl::MouseButtonDown( const MouseEvent& rMEvt )
     222             : {
     223           0 :     nModifier = rMEvt.GetModifier();
     224             : 
     225           0 :     bool bHitEmptySpace = ( NULL == GetEntry( rMEvt.GetPosPixel(), true ) );
     226           0 :     if( bHitEmptySpace && ( rMEvt.GetClicks() == 2 ) && rMEvt.IsMod1() )
     227           0 :         Control::MouseButtonDown( rMEvt );
     228             :     else
     229           0 :         SvTreeListBox::MouseButtonDown( rMEvt );
     230           0 : }
     231             : 
     232             : /** Drop is enabled as long as it is allowed to create a new style by example, i.e. to
     233             :     create a style out of the current selection.
     234             : */
     235           0 : sal_Int8 DropListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
     236             : {
     237           0 :     if ( IsDropFormatSupported( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
     238             :     {
     239             :         // special case: page styles are allowed to create new styles by example
     240             :         // but not allowed to be created by drag and drop
     241           0 :         if (pDialog->GetActualFamily() == SFX_STYLE_FAMILY_PAGE ||
     242             :                 pDialog->bNewByExampleDisabled)
     243           0 :             return DND_ACTION_NONE;
     244             :         else
     245           0 :             return DND_ACTION_COPY;
     246             :     }
     247           0 :     return SvTreeListBox::AcceptDrop( rEvt );
     248             : }
     249             : 
     250           0 : sal_Int8 DropListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
     251             : {
     252           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     253           0 :     SfxObjectShell* pDocShell = pDialog->GetObjectShell();
     254           0 :     TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
     255           0 :     sal_uInt32 nFormatCount = aHelper.GetFormatCount();
     256           0 :     if ( pDocShell )
     257             :     {
     258           0 :         bool bFormatFound = false;
     259             : 
     260           0 :         for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
     261             :         {
     262           0 :             SotClipboardFormatId nId = aHelper.GetFormat(i);
     263           0 :             TransferableObjectDescriptor aDesc;
     264             : 
     265           0 :             if ( aHelper.GetTransferableObjectDescriptor( nId, aDesc ) )
     266             :             {
     267           0 :                 if ( aDesc.maClassName == pDocShell->GetFactory().GetClassId() )
     268             :                 {
     269           0 :                     PostUserEvent( LINK( this, DropListBox_Impl, OnAsyncExecuteDrop ), 0, true );
     270             : 
     271           0 :                     bFormatFound = true;
     272           0 :                     nRet =  rEvt.mnAction;
     273           0 :                     break;
     274             :                 }
     275             :             }
     276           0 :         }
     277             : 
     278           0 :         if ( !bFormatFound )
     279           0 :             return SvTreeListBox::ExecuteDrop( rEvt );
     280             :     }
     281             : 
     282           0 :     return nRet;
     283             : }
     284             : 
     285           0 : IMPL_LINK_NOARG(DropListBox_Impl, OnAsyncExecuteDrop)
     286             : {
     287           0 :     pDialog->ActionSelect( SID_STYLE_NEW_BY_EXAMPLE );
     288           0 :     return 0;
     289             : }
     290             : 
     291           0 : bool DropListBox_Impl::Notify( NotifyEvent& rNEvt )
     292             : {
     293           0 :     bool nRet = false;
     294           0 :     if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
     295             :     {
     296           0 :         const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
     297           0 :         if(!rKeyCode.GetModifier())
     298             :         {
     299           0 :             if( pDialog->bCanDel && KEY_DELETE == rKeyCode.GetCode())
     300             :             {
     301           0 :                 pDialog->DeleteHdl( NULL );
     302           0 :                 nRet =  true;
     303             :             }
     304           0 :             else if( KEY_RETURN == rKeyCode.GetCode())
     305             :             {
     306           0 :                 GetDoubleClickHdl().Call(this);
     307           0 :                 nRet = true;
     308             :             }
     309             :         }
     310             :     }
     311           0 :     if(!nRet)
     312           0 :         nRet = SvTreeListBox::Notify( rNEvt );
     313           0 :     return nRet;
     314             : }
     315             : 
     316             : /** ListBox class that starts a PopupMenu (designer specific) in the
     317             :     command handler.
     318             : */
     319           0 : SfxActionListBox::SfxActionListBox(SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits)
     320           0 :     : DropListBox_Impl(pParent->GetWindow(), nWinBits, pParent)
     321             : {
     322           0 :     EnableContextMenuHandling();
     323           0 : }
     324             : 
     325           0 : void SfxActionListBox::Recalc()
     326             : {
     327           0 :     SetEntryHeight(32 * GetDPIScaleFactor());
     328           0 :     RecalcViewData();
     329           0 : }
     330             : 
     331           0 : PopupMenu* SfxActionListBox::CreateContextMenu()
     332             : {
     333             : 
     334           0 :     if( !( GetSelectionCount() > 0 ) )
     335             :     {
     336           0 :         pDialog->EnableEdit( false );
     337           0 :         pDialog->EnableDel( false );
     338             :     }
     339           0 :     return pDialog->CreateContextMenu();
     340             : }
     341             : 
     342           0 : SfxTemplatePanelControl::SfxTemplatePanelControl(SfxBindings* pBindings, vcl::Window* pParentWindow)
     343             :     : DockingWindow(pParentWindow, SfxResId(DLG_STYLE_DESIGNER))
     344           0 :     , pImpl(new SfxTemplateDialog_Impl(pBindings, this))
     345           0 :     , mpBindings(pBindings)
     346             : {
     347             :     OSL_ASSERT(mpBindings!=NULL);
     348             : 
     349           0 :     pImpl->updateNonFamilyImages();
     350             : 
     351           0 :     SetStyle(GetStyle() & ~WB_DOCKABLE);
     352           0 : }
     353             : 
     354           0 : SfxTemplatePanelControl::~SfxTemplatePanelControl()
     355             : {
     356           0 :     disposeOnce();
     357           0 : }
     358             : 
     359           0 : void SfxTemplatePanelControl::dispose()
     360             : {
     361           0 :     pImpl.reset();
     362           0 :     DockingWindow::dispose();
     363           0 : }
     364             : 
     365           0 : void SfxTemplatePanelControl::DataChanged( const DataChangedEvent& _rDCEvt )
     366             : {
     367           0 :     if ( ( DataChangedEventType::SETTINGS == _rDCEvt.GetType() ) &&
     368           0 :          ( AllSettingsFlags::STYLE & _rDCEvt.GetFlags() ) )
     369             :     {
     370           0 :         pImpl->updateFamilyImages();
     371           0 :         pImpl->updateNonFamilyImages();
     372             :     }
     373             : 
     374           0 :     DockingWindow::DataChanged( _rDCEvt );
     375           0 : }
     376             : 
     377           0 : void SfxTemplatePanelControl::Resize()
     378             : {
     379           0 :     if(pImpl)
     380           0 :         pImpl->Resize();
     381           0 :     DockingWindow::Resize();
     382           0 : }
     383             : 
     384           0 : void SfxTemplatePanelControl::FreeResource()
     385             : {
     386           0 :     DockingWindow::FreeResource();
     387           0 : }
     388             : 
     389           0 : void SfxTemplatePanelControl::StateChanged( StateChangedType nStateChange )
     390             : {
     391           0 :     if (nStateChange == StateChangedType::InitShow)
     392             :     {
     393           0 :         SfxViewFrame* pFrame = mpBindings->GetDispatcher_Impl()->GetFrame();
     394           0 :         vcl::Window* pEditWin = pFrame->GetViewShell()->GetWindow();
     395             : 
     396           0 :         Size aSize = pEditWin->GetSizePixel();
     397           0 :         Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
     398           0 :         aPoint = GetParent()->ScreenToOutputPixel( aPoint );
     399           0 :         Size aWinSize = GetSizePixel();
     400           0 :         aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
     401           0 :         aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
     402             :         // SetFloatingPos( aPoint );
     403             :     }
     404             : 
     405           0 :     DockingWindow::StateChanged( nStateChange );
     406           0 : }
     407             : 
     408           0 : void StyleTreeListBox_Impl::MakeExpanded_Impl(ExpandedEntries_t& rEntries) const
     409             : {
     410             :     SvTreeListEntry* pEntry;
     411           0 :     for (pEntry = FirstVisible(); pEntry; pEntry = NextVisible(pEntry))
     412             :     {
     413           0 :         if (IsExpanded(pEntry))
     414             :         {
     415           0 :             rEntries.push_back(GetEntryText(pEntry));
     416             :         }
     417             :     }
     418           0 : }
     419             : 
     420           0 : PopupMenu* StyleTreeListBox_Impl::CreateContextMenu()
     421             : {
     422           0 :     return pDialog->CreateContextMenu();
     423             : }
     424             : 
     425             : /** DoubleClick-Handler; calls the link.
     426             :     SV virtual method.
     427             : */
     428           0 : bool StyleTreeListBox_Impl::DoubleClickHdl()
     429             : {
     430           0 :     aDoubleClickLink.Call(this);
     431           0 :     return false;
     432             : }
     433             : 
     434             : /** Command Handler; this executes a PopupMenu (designer-specific)
     435             :     SV virtual method.
     436             : */
     437           0 : void StyleTreeListBox_Impl::Command( const CommandEvent& rCEvt )
     438             : {
     439           0 :     SvTreeListBox::Command(rCEvt);
     440           0 : }
     441             : 
     442           0 : bool StyleTreeListBox_Impl::Notify( NotifyEvent& rNEvt )
     443             : {
     444             :     // handle <RETURN> as double click
     445             : 
     446           0 :     bool nRet = false;
     447           0 :     if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
     448             :     {
     449           0 :         const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
     450           0 :         if ( !rKeyCode.GetModifier() && KEY_RETURN == rKeyCode.GetCode() )
     451             :         {
     452           0 :             aDoubleClickLink.Call( this );
     453           0 :             nRet = true;
     454             :         }
     455             :     }
     456             : 
     457           0 :     if ( !nRet )
     458           0 :         nRet = DropListBox_Impl::Notify( rNEvt );
     459             : 
     460           0 :     return nRet;
     461             : }
     462             : 
     463             : /** NotifyMoving Handler; This leads via a link on the event to the dialog.
     464             :     SV virtual method.
     465             : */
     466           0 : TriState StyleTreeListBox_Impl::NotifyMoving(SvTreeListEntry*  pTarget,
     467             :                                          SvTreeListEntry*  pEntry,
     468             :                                          SvTreeListEntry*& rpNewParent,
     469             :                                          sal_uIntPtr& lPos)
     470             : {
     471           0 :     if(!pTarget || !pEntry)
     472           0 :         return TRISTATE_FALSE;
     473           0 :     aParent = GetEntryText(pTarget);
     474           0 :     aStyle  = GetEntryText(pEntry);
     475           0 :     const bool bRet = (bool)aDropLink.Call(this);
     476           0 :     rpNewParent = pTarget;
     477           0 :     lPos=0;
     478           0 :     IntlWrapper aIntlWrapper( Application::GetSettings().GetLanguageTag() );
     479           0 :     const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
     480           0 :     for(SvTreeListEntry *pTmpEntry=FirstChild(pTarget);
     481           0 :         pTmpEntry && pCollator->compareString(
     482           0 :             GetEntryText(pTmpEntry),GetEntryText(pEntry)) < 0;
     483             :         pTmpEntry=NextSibling(pTmpEntry),lPos++) ;
     484             : 
     485           0 :     return bRet ? TRISTATE_INDET : TRISTATE_FALSE;
     486             : }
     487             : 
     488             : /** ExpandingHdl Handler; the current entry is noticed.
     489             :     SV virtual method.
     490             : 
     491             :     [Cross-reference]
     492             :     <StyleTreeListBox_Impl::ExpandedHdl()>
     493             : */
     494           0 : bool  StyleTreeListBox_Impl::ExpandingHdl()
     495             : {
     496           0 :     pCurEntry = GetCurEntry();
     497           0 :     return true;
     498             : }
     499             : 
     500             : /**  ExpandedHdl Handler;
     501             :     SV virtual method.
     502             : 
     503             :     [Cross-reference]
     504             :     <StyleTreeListBox_Impl::ExpandingHdl()>
     505             : */
     506           0 : void  StyleTreeListBox_Impl::ExpandedHdl()
     507             : {
     508           0 :     SvTreeListEntry *pEntry = GetHdlEntry();
     509           0 :     if(!IsExpanded(pEntry) && pCurEntry != GetCurEntry())
     510           0 :         SelectAll( false );
     511           0 :     pCurEntry = 0;
     512           0 : }
     513             : 
     514             : /** Constructor StyleTreeListBox_Impl */
     515           0 : StyleTreeListBox_Impl::StyleTreeListBox_Impl(SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle)
     516             :     : DropListBox_Impl(pParent->GetWindow(), nWinStyle, pParent)
     517           0 :     , pCurEntry(0)
     518             : {
     519           0 :     EnableContextMenuHandling();
     520           0 : }
     521             : 
     522           0 : void StyleTreeListBox_Impl::Recalc()
     523             : {
     524           0 :     SetEntryHeight(32 * GetDPIScaleFactor());
     525           0 :     RecalcViewData();
     526           0 : }
     527             : 
     528             : /** Internal structure for the establishment of the hierarchical view */
     529             : class StyleTree_Impl;
     530             : typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl;
     531             : 
     532             : class StyleTree_Impl
     533             : {
     534             : private:
     535             :     OUString aName;
     536             :     OUString aParent;
     537             :     StyleTreeArr_Impl pChildren;
     538             : 
     539             : public:
     540             : 
     541           0 :     bool HasParent() const { return !aParent.isEmpty(); }
     542             : 
     543           0 :     StyleTree_Impl(const OUString &rName, const OUString &rParent):
     544           0 :         aName(rName), aParent(rParent), pChildren(0) {}
     545             :     ~StyleTree_Impl();
     546             :     void Put(StyleTree_Impl* pIns, sal_uIntPtr lPos=ULONG_MAX);
     547             :     size_t Count();
     548             : 
     549           0 :     OUString getName() { return aName; }
     550           0 :     OUString getParent() { return aParent; }
     551           0 :     StyleTree_Impl *operator[](size_t idx) const { return pChildren[idx]; }
     552             : };
     553             : 
     554           0 : size_t StyleTree_Impl::Count()
     555             : {
     556           0 :     return pChildren.size();
     557             : }
     558             : 
     559           0 : StyleTree_Impl::~StyleTree_Impl()
     560             : {
     561           0 :     for(StyleTreeArr_Impl::const_iterator it = pChildren.begin(); it != pChildren.end(); ++it)
     562           0 :         delete *it;
     563           0 : }
     564             : 
     565           0 : void StyleTree_Impl::Put(StyleTree_Impl* pIns, sal_uIntPtr lPos)
     566             : {
     567           0 :     if ( ULONG_MAX == lPos )
     568           0 :         pChildren.push_back( pIns );
     569             :     else
     570           0 :         pChildren.insert( pChildren.begin() + (sal_uInt16)lPos, pIns );
     571           0 : }
     572             : 
     573             : 
     574             : 
     575           0 : StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
     576             : {
     577           0 :     const sal_uInt16 nCount = rArr.size();
     578             : 
     579             :     comphelper::string::NaturalStringSorter aSorter(
     580             :         ::comphelper::getProcessComponentContext(),
     581           0 :         Application::GetSettings().GetLanguageTag().getLocale());
     582             : 
     583             :     // Arrange all under their Parents
     584             :     sal_uInt16 i;
     585           0 :     for(i = 0; i < nCount; ++i)
     586             :     {
     587           0 :         StyleTree_Impl* pEntry = rArr[i];
     588           0 :         if(pEntry->HasParent())
     589             :         {
     590           0 :             for(sal_uInt16 j = 0; j < nCount; ++j)
     591             :             {
     592           0 :                 StyleTree_Impl* pCmp = rArr[j];
     593           0 :                 if(pCmp->getName() == pEntry->getParent())
     594             :                 {
     595             :                     // Paste initial filter
     596             :                     sal_uInt16 nPos;
     597           0 :                     for( nPos = 0 ; nPos < pCmp->Count() &&
     598           0 :                              aSorter.compare((*pCmp)[nPos]->getName(), pEntry->getName()) < 0 ; nPos++)
     599             :                     {};
     600           0 :                     pCmp->Put(pEntry,nPos);
     601           0 :                     break;
     602             :                 }
     603             :             }
     604             :         }
     605             :     }
     606             : 
     607           0 :     for(i = 0; i < rArr.size(); )
     608             :     {
     609           0 :         if(rArr[i]->HasParent())
     610           0 :             rArr.erase(rArr.begin() + i);
     611             :         else
     612           0 :             ++i;
     613             :     }
     614           0 :     return rArr;
     615             : }
     616             : 
     617           0 : inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
     618             :                              const OUString &rStr)
     619             : {
     620           0 :     for (size_t n = 0; n < rEntries.size(); ++n)
     621             :     {
     622           0 :         if (rEntries[n] == rStr)
     623           0 :             return true;
     624             :     }
     625           0 :     return false;
     626             : }
     627             : 
     628           0 : SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox,
     629             :                               StyleTree_Impl* pEntry,
     630             :                               const ExpandedEntries_t& rEntries,
     631             :                               SfxStyleFamily eStyleFamily,
     632             :                               SvTreeListEntry* pParent = nullptr)
     633             : {
     634           0 :     SvTreeListEntry* pTreeListEntry = pBox->InsertEntry(pEntry->getName(), pParent);
     635             : 
     636           0 :     StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, pEntry->getName(), eStyleFamily);
     637             : 
     638           0 :     pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
     639             : 
     640           0 :     pBox->GetModel()->InvalidateEntry(pTreeListEntry);
     641             : 
     642           0 :     for(size_t i = 0; i < pEntry->Count(); ++i)
     643             :     {
     644           0 :         FillBox_Impl(pBox, (*pEntry)[i], rEntries, eStyleFamily, pTreeListEntry);
     645             :     }
     646           0 :     return pTreeListEntry;
     647             : }
     648             : 
     649             : // Constructor
     650             : 
     651           0 : SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl::Window* pW, bool )
     652             :     : mbIgnoreSelect(false)
     653             :     , pBindings(pB)
     654             :     , pWindow(pW)
     655             :     , pModule(NULL)
     656             :     , pIdle(NULL)
     657             :     , m_pStyleFamiliesId(NULL)
     658             :     , pStyleFamilies(NULL)
     659             :     , pStyleSheetPool(NULL)
     660             :     , pTreeBox(NULL)
     661             :     , pCurObjShell(NULL)
     662             :     , xModuleManager(frame::ModuleManager::create(::comphelper::getProcessComponentContext()))
     663             :     , m_pDeletionWatcher(NULL)
     664             : 
     665             :     , aFmtLb( VclPtr<SfxActionListBox>::Create(this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH) )
     666             :     , aFilterLb( VclPtr<ListBox>::Create(pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP) )
     667             : 
     668             :     , nActFamily(0xffff)
     669             :     , nActFilter(0)
     670             :     , nAppFilter(0)
     671             : 
     672             :     , bDontUpdate(false)
     673             :     , bIsWater(false)
     674             :     , bEnabled(true)
     675             :     , bUpdate(false)
     676             :     , bUpdateFamily(false)
     677             :     , bCanEdit(false)
     678             :     , bCanDel(false)
     679             :     , bCanNew(true)
     680             :     , bCanHide(true)
     681             :     , bCanShow(false)
     682             :     , bWaterDisabled(false)
     683             :     , bNewByExampleDisabled(false)
     684             :     , bUpdateByExampleDisabled(false)
     685             :     , bTreeDrag(true)
     686             :     , bHierarchical(false)
     687             :     , m_bWantHierarchical(false)
     688           0 :     , bBindingUpdate(true)
     689             : {
     690           0 :     aFmtLb->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
     691           0 :     aFmtLb->SetHelpId( HID_TEMPLATE_FMT );
     692           0 :     aFilterLb->SetHelpId( HID_TEMPLATE_FILTER );
     693           0 :     aFmtLb->SetStyle( aFmtLb->GetStyle() | WB_SORT | WB_HIDESELECTION );
     694           0 :     vcl::Font aFont = aFmtLb->GetFont();
     695           0 :     aFont.SetWeight( WEIGHT_NORMAL );
     696           0 :     aFmtLb->SetFont( aFont );
     697             : 
     698           0 :     memset(pBoundItems, 0, sizeof(pBoundItems));
     699           0 :     memset(pFamilyState, 0, sizeof(pFamilyState));
     700           0 : }
     701             : 
     702           0 : sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId)
     703             : {
     704           0 :     const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nId );
     705           0 :     return SfxTemplate::SfxFamilyIdToNId(pItem->GetFamily())-1;
     706             : }
     707             : 
     708           0 : void SfxTemplateDialog_Impl::EnableEdit(bool bEnable)
     709             : {
     710           0 :     SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
     711           0 :     if( !bEnable || !bUpdateByExampleDisabled )
     712           0 :         EnableItem( SID_STYLE_UPDATE_BY_EXAMPLE, bEnable);
     713           0 : }
     714             : 
     715           0 : void SfxCommonTemplateDialog_Impl::ReadResource()
     716             : {
     717             :     // Read global user resource
     718           0 :     for(sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
     719           0 :         pFamilyState[i] = 0;
     720             : 
     721           0 :     SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
     722           0 :     pCurObjShell = pViewFrame->GetObjectShell();
     723           0 :     pModule = pCurObjShell ? pCurObjShell->GetModule() : NULL;
     724           0 :     ResMgr* pMgr = pModule ? pModule->GetResMgr() : NULL;
     725           0 :     if (pMgr)
     726             :     {
     727           0 :         ResId aFamId( DLG_STYLE_DESIGNER, *pMgr );
     728           0 :         aFamId.SetRT(RSC_SFX_STYLE_FAMILIES);
     729           0 :         m_pStyleFamiliesId = new ResId( aFamId.GetId(), *pMgr );
     730           0 :         m_pStyleFamiliesId->SetRT(RSC_SFX_STYLE_FAMILIES);
     731           0 :         if (pMgr->IsAvailable(aFamId))
     732           0 :             pStyleFamilies = new SfxStyleFamilies( aFamId );
     733             :     }
     734           0 :     if (!pStyleFamilies)
     735           0 :         pStyleFamilies = new SfxStyleFamilies;
     736             : 
     737           0 :     nActFilter = pCurObjShell ? static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pCurObjShell ) ) : SFXSTYLEBIT_ALL;
     738           0 :     if ( pCurObjShell && SFXSTYLEBIT_ALL == nActFilter )
     739           0 :         nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
     740             : 
     741             :     // Paste in the toolbox
     742             :     // reverse order, since always inserted at the head
     743           0 :     size_t nCount = pStyleFamilies->size();
     744             : 
     745           0 :     pBindings->ENTERREGISTRATIONS();
     746             : 
     747             :     size_t i;
     748           0 :     for (i = 0; i < nCount; ++i)
     749             :     {
     750           0 :         sal_uInt16 nSlot = 0;
     751           0 :         switch( (sal_uInt16)pStyleFamilies->at( i )->GetFamily() )
     752             :         {
     753             :             case SFX_STYLE_FAMILY_CHAR:
     754           0 :                 nSlot = SID_STYLE_FAMILY1; break;
     755             :             case SFX_STYLE_FAMILY_PARA:
     756           0 :                 nSlot = SID_STYLE_FAMILY2; break;
     757             :             case SFX_STYLE_FAMILY_FRAME:
     758           0 :                 nSlot = SID_STYLE_FAMILY3; break;
     759             :             case SFX_STYLE_FAMILY_PAGE:
     760           0 :                 nSlot = SID_STYLE_FAMILY4; break;
     761             :             case SFX_STYLE_FAMILY_PSEUDO:
     762           0 :                 nSlot = SID_STYLE_FAMILY5; break;
     763           0 :             default: OSL_FAIL("unknown StyleFamily"); break;
     764             :         }
     765             :         pBoundItems[i] =
     766           0 :             new SfxTemplateControllerItem(nSlot, *this, *pBindings);
     767             :     }
     768           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     769           0 :         SID_STYLE_WATERCAN, *this, *pBindings);
     770           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     771           0 :         SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings);
     772           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     773           0 :         SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings);
     774           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     775           0 :         SID_STYLE_NEW, *this, *pBindings);
     776           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     777           0 :         SID_STYLE_DRAGHIERARCHIE, *this, *pBindings);
     778           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     779           0 :         SID_STYLE_EDIT, *this, *pBindings);
     780           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     781           0 :         SID_STYLE_DELETE, *this, *pBindings);
     782           0 :     pBoundItems[i++] = new SfxTemplateControllerItem(
     783           0 :         SID_STYLE_FAMILY, *this, *pBindings);
     784           0 :     pBindings->LEAVEREGISTRATIONS();
     785             : 
     786           0 :     for(; i < COUNT_BOUND_FUNC; ++i)
     787           0 :         pBoundItems[i] = 0;
     788             : 
     789           0 :     StartListening(*pBindings);
     790             : 
     791             : // Insert in the reverse order of occurrence in the Style Families. This is for
     792             : // the toolbar of the designer. The list box of the catalog respects the
     793             : // correct order by itself.
     794             : 
     795             : // Sequences: the order of Resource = the order of Toolbar for example list box.
     796             : // Order of ascending SIDs: Low SIDs are displayed first when templates of
     797             : // several families are active.
     798             : 
     799             :     // in the Writer the UpdateStyleByExample Toolbox button is removed and
     800             :     // the NewStyle button gets a PopupMenu
     801           0 :     if(nCount > 4)
     802           0 :         ReplaceUpdateButtonByMenu();
     803             : 
     804           0 :     for( ; nCount--; )
     805             :     {
     806           0 :         const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nCount );
     807           0 :         sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId( pItem->GetFamily() );
     808           0 :         InsertFamilyItem( nId, pItem );
     809             :     }
     810             : 
     811           0 :     LoadedFamilies();
     812             : 
     813           0 :     sal_uInt16 nStart = SID_STYLE_FAMILY1;
     814           0 :     sal_uInt16 nEnd = SID_STYLE_FAMILY4;
     815             : 
     816           0 :     for ( i = nStart; i <= nEnd; i++ )
     817           0 :         pBindings->Update(i);
     818           0 : }
     819             : 
     820           0 : void SfxCommonTemplateDialog_Impl::ClearResource()
     821             : {
     822           0 :     ClearFamilyList();
     823           0 :     impl_clear();
     824           0 : }
     825             : 
     826           0 : void SfxCommonTemplateDialog_Impl::impl_clear()
     827             : {
     828           0 :     delete pStyleFamilies;
     829           0 :     pStyleFamilies = NULL;
     830             :     sal_uInt16 i;
     831           0 :     for ( i = 0; i < MAX_FAMILIES; ++i )
     832           0 :         DELETEX(SfxTemplateItem, pFamilyState[i]);
     833           0 :     for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
     834           0 :         delete pBoundItems[i];
     835           0 :     pCurObjShell = NULL;
     836             : 
     837           0 :     DELETEZ( m_pStyleFamiliesId );
     838           0 : }
     839             : 
     840             : SfxCommonTemplateDialog_Impl::DeletionWatcher *
     841           0 : SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(
     842             :         DeletionWatcher *const pNewWatcher)
     843             : {
     844           0 :     DeletionWatcher *const pRet(m_pDeletionWatcher);
     845           0 :     m_pDeletionWatcher = pNewWatcher;
     846           0 :     return pRet;
     847             : }
     848             : 
     849           0 : void SfxCommonTemplateDialog_Impl::Initialize()
     850             : {
     851             :     // Read global user resource
     852           0 :     ReadResource();
     853           0 :     pBindings->Invalidate( SID_STYLE_FAMILY );
     854           0 :     pBindings->Update( SID_STYLE_FAMILY );
     855             : 
     856           0 :     Update_Impl();
     857             : 
     858           0 :     aFilterLb->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) );
     859           0 :     aFmtLb->SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) );
     860           0 :     aFmtLb->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) );
     861           0 :     aFmtLb->SetSelectionMode(MULTIPLE_SELECTION);
     862             : 
     863             : 
     864           0 :     aFilterLb->Show();
     865           0 :     if (!bHierarchical)
     866           0 :         aFmtLb->Show();
     867           0 : }
     868             : 
     869           0 : SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
     870             : {
     871           0 :     OUString aEmpty;
     872             : #if defined STYLESPREVIEW
     873             :     Execute_Impl(SID_STYLE_END_PREVIEW,
     874             :         OUString(), OUString(),
     875             :         0, 0, 0, 0 );
     876             : #endif
     877           0 :     if ( bIsWater )
     878           0 :         Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
     879           0 :     GetWindow()->Hide();
     880           0 :     impl_clear();
     881           0 :     if ( pStyleSheetPool )
     882           0 :         EndListening(*pStyleSheetPool);
     883           0 :     pStyleSheetPool = NULL;
     884           0 :     pTreeBox.disposeAndClear();
     885           0 :     delete pIdle;
     886           0 :     if ( m_pDeletionWatcher )
     887           0 :         m_pDeletionWatcher->signal();
     888           0 :     aFmtLb.disposeAndClear();
     889           0 :     aFilterLb.disposeAndClear();
     890           0 : }
     891             : 
     892             : namespace SfxTemplate
     893             : {
     894           0 :     sal_uInt16 SfxFamilyIdToNId(SfxStyleFamily nFamily)
     895             :     {
     896           0 :         switch ( nFamily )
     897             :         {
     898           0 :             case SFX_STYLE_FAMILY_CHAR:   return 1;
     899           0 :             case SFX_STYLE_FAMILY_PARA:   return 2;
     900           0 :             case SFX_STYLE_FAMILY_FRAME:  return 3;
     901           0 :             case SFX_STYLE_FAMILY_PAGE:   return 4;
     902           0 :             case SFX_STYLE_FAMILY_PSEUDO: return 5;
     903           0 :             default:                      return 0;
     904             :         }
     905             :     }
     906             : 
     907        4372 :     SfxStyleFamily NIdToSfxFamilyId(sal_uInt16 nId)
     908             :     {
     909        4372 :         switch (nId)
     910             :         {
     911           0 :             case 1: return SFX_STYLE_FAMILY_CHAR;
     912           0 :             case 2: return SFX_STYLE_FAMILY_PARA;
     913           0 :             case 3: return SFX_STYLE_FAMILY_FRAME;
     914           0 :             case 4: return SFX_STYLE_FAMILY_PAGE;
     915           0 :             case 5: return SFX_STYLE_FAMILY_PSEUDO;
     916        4372 :             default: return SFX_STYLE_FAMILY_ALL;
     917             :         }
     918             :     }
     919             : }
     920             : 
     921             : // Helper function: Access to the current family item
     922           0 : const SfxStyleFamilyItem *SfxCommonTemplateDialog_Impl::GetFamilyItem_Impl() const
     923             : {
     924           0 :     const size_t nCount = pStyleFamilies->size();
     925           0 :     for(size_t i = 0; i < nCount; ++i)
     926             :     {
     927           0 :         const SfxStyleFamilyItem *pItem = pStyleFamilies->at( i );
     928           0 :         sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId(pItem->GetFamily());
     929           0 :         if(nId == nActFamily)
     930           0 :             return pItem;
     931             :     }
     932           0 :     return 0;
     933             : }
     934             : 
     935           0 : SfxStyleSheetBase *SfxCommonTemplateDialog_Impl::GetSelectedStyle() const
     936             : {
     937           0 :     if (!IsInitialized() || !pStyleSheetPool || !HasSelectedStyle())
     938           0 :         return NULL;
     939           0 :     const OUString aTemplName( GetSelectedEntry() );
     940           0 :     const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
     941           0 :     return pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
     942             : }
     943             : 
     944           0 : void SfxCommonTemplateDialog_Impl::SelectStyle(const OUString &rStr)
     945             : {
     946           0 :     const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
     947           0 :     if ( !pItem )
     948           0 :         return;
     949           0 :     const SfxStyleFamily eFam = pItem->GetFamily();
     950           0 :     SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( rStr, eFam, SFXSTYLEBIT_ALL );
     951           0 :     if( pStyle )
     952             :     {
     953           0 :         bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
     954           0 :         EnableEdit( bReadWrite );
     955           0 :         EnableHide( bReadWrite && !pStyle->IsHidden( ) && !pStyle->IsUsed( ) );
     956           0 :         EnableShow( bReadWrite && pStyle->IsHidden( ) );
     957             :     }
     958             :     else
     959             :     {
     960           0 :         EnableEdit( false );
     961           0 :         EnableHide( false );
     962           0 :         EnableShow( false );
     963             :     }
     964             : 
     965           0 :     if ( pTreeBox )
     966             :     {
     967           0 :         if ( !rStr.isEmpty() )
     968             :         {
     969           0 :             SvTreeListEntry* pEntry = pTreeBox->First();
     970           0 :             while ( pEntry )
     971             :             {
     972           0 :                 if ( pTreeBox->GetEntryText( pEntry ) == rStr )
     973             :                 {
     974           0 :                     pTreeBox->MakeVisible( pEntry );
     975           0 :                     pTreeBox->Select( pEntry );
     976           0 :                     return;
     977             :                 }
     978           0 :                 pEntry = pTreeBox->Next( pEntry );
     979             :             }
     980             :         }
     981             :         else
     982           0 :             pTreeBox->SelectAll( false );
     983             :     }
     984             :     else
     985             :     {
     986           0 :         bool bSelect = ! rStr.isEmpty();
     987           0 :         if ( bSelect )
     988             :         {
     989           0 :             SvTreeListEntry* pEntry = aFmtLb->FirstVisible();
     990           0 :             while ( pEntry && aFmtLb->GetEntryText( pEntry ) != rStr )
     991           0 :                 pEntry = aFmtLb->NextVisible( pEntry );
     992           0 :             if ( !pEntry )
     993           0 :                 bSelect = false;
     994             :             else
     995             :             {
     996           0 :                 if (!aFmtLb->IsSelected(pEntry))
     997             :                 {
     998           0 :                     aFmtLb->MakeVisible( pEntry );
     999           0 :                     aFmtLb->SelectAll(false);
    1000           0 :                     aFmtLb->Select( pEntry );
    1001           0 :                     bWaterDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1);
    1002           0 :                     FmtSelectHdl( NULL );
    1003             :                 }
    1004             :             }
    1005             :         }
    1006             : 
    1007           0 :         if ( !bSelect )
    1008             :         {
    1009           0 :             aFmtLb->SelectAll( false );
    1010           0 :             EnableEdit(false);
    1011           0 :             EnableHide( false );
    1012           0 :             EnableShow( false );
    1013             :         }
    1014             :     }
    1015             : }
    1016             : 
    1017           0 : OUString SfxCommonTemplateDialog_Impl::GetSelectedEntry() const
    1018             : {
    1019           0 :     OUString aRet;
    1020           0 :     if ( pTreeBox )
    1021             :     {
    1022           0 :         SvTreeListEntry* pEntry = pTreeBox->FirstSelected();
    1023           0 :         if ( pEntry )
    1024           0 :             aRet = pTreeBox->GetEntryText( pEntry );
    1025             :     }
    1026             :     else
    1027             :     {
    1028           0 :         SvTreeListEntry* pEntry = aFmtLb->FirstSelected();
    1029           0 :         if ( pEntry )
    1030           0 :             aRet = aFmtLb->GetEntryText( pEntry );
    1031             :     }
    1032           0 :     return aRet;
    1033             : }
    1034             : 
    1035           0 : void SfxCommonTemplateDialog_Impl::EnableTreeDrag( bool bEnable )
    1036             : {
    1037           0 :     if ( pStyleSheetPool )
    1038             :     {
    1039           0 :         SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
    1040           0 :         if ( pTreeBox )
    1041             :         {
    1042           0 :             if ( pStyle && pStyle->HasParentSupport() && bEnable )
    1043           0 :                 pTreeBox->SetDragDropMode(DragDropMode::CTRL_MOVE);
    1044             :             else
    1045           0 :                 pTreeBox->SetDragDropMode(DragDropMode::NONE);
    1046             :         }
    1047             :     }
    1048           0 :     bTreeDrag = bEnable;
    1049           0 : }
    1050             : 
    1051           0 : void SfxCommonTemplateDialog_Impl::FillTreeBox()
    1052             : {
    1053             :     OSL_ENSURE( pTreeBox, "FillTreeBox() without treebox");
    1054           0 :     if (pStyleSheetPool && nActFamily != 0xffff)
    1055             :     {
    1056           0 :         const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
    1057           0 :         if (!pItem)
    1058           0 :             return;
    1059           0 :         pStyleSheetPool->SetSearchMask(pItem->GetFamily(), SFXSTYLEBIT_ALL_VISIBLE);
    1060           0 :         StyleTreeArr_Impl aArr;
    1061           0 :         SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
    1062             : 
    1063           0 :         if(pStyle && pStyle->HasParentSupport() && bTreeDrag )
    1064           0 :             pTreeBox->SetDragDropMode(DragDropMode::CTRL_MOVE);
    1065             :         else
    1066           0 :             pTreeBox->SetDragDropMode(DragDropMode::NONE);
    1067             : 
    1068           0 :         while (pStyle)
    1069             :         {
    1070           0 :             StyleTree_Impl* pNew = new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
    1071           0 :             aArr.push_back(pNew);
    1072           0 :             pStyle = pStyleSheetPool->Next();
    1073             :         }
    1074             : 
    1075           0 :         MakeTree_Impl(aArr);
    1076           0 :         ExpandedEntries_t aEntries;
    1077           0 :         pTreeBox->MakeExpanded_Impl(aEntries);
    1078           0 :         pTreeBox->SetUpdateMode( false );
    1079           0 :         pTreeBox->Clear();
    1080           0 :         const sal_uInt16 nCount = aArr.size();
    1081             : 
    1082           0 :         for (sal_uInt16 i = 0; i < nCount; ++i)
    1083             :         {
    1084           0 :             FillBox_Impl(pTreeBox, aArr[i], aEntries, pItem->GetFamily());
    1085             :         }
    1086           0 :         pTreeBox->Recalc();
    1087             : 
    1088           0 :         EnableItem(SID_STYLE_WATERCAN, false);
    1089             : 
    1090           0 :         SfxTemplateItem* pState = pFamilyState[nActFamily - 1];
    1091             : 
    1092           0 :         if (nCount)
    1093           0 :             pTreeBox->Expand(pTreeBox->First());
    1094             : 
    1095           0 :         for (SvTreeListEntry* pEntry = pTreeBox->First(); pEntry; pEntry = pTreeBox->Next(pEntry))
    1096             :         {
    1097           0 :             if (IsExpanded_Impl(aEntries, pTreeBox->GetEntryText(pEntry)))
    1098           0 :                 pTreeBox->Expand(pEntry);
    1099             :         }
    1100             : 
    1101           0 :         pTreeBox->SetUpdateMode( true );
    1102             : 
    1103           0 :         OUString aStyle;
    1104           0 :         if(pState)  // Select current entry
    1105           0 :             aStyle = pState->GetStyleName();
    1106           0 :         SelectStyle(aStyle);
    1107           0 :         EnableDelete();
    1108             :     }
    1109             : }
    1110             : 
    1111           0 : bool SfxCommonTemplateDialog_Impl::HasSelectedStyle() const
    1112             : {
    1113           0 :     return pTreeBox? pTreeBox->FirstSelected() != 0:
    1114           0 :             aFmtLb->GetSelectionCount() != 0;
    1115             : }
    1116             : 
    1117             : // internal: Refresh the display
    1118             : // nFlags: what we should update.
    1119           0 : void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags)
    1120             : {
    1121             :     OSL_ENSURE(nFlags, "nothing to do");
    1122           0 :     const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    1123           0 :     if (!pItem)
    1124             :     {
    1125             :         // Is the case for the template catalog
    1126           0 :         SfxTemplateItem **ppItem = pFamilyState;
    1127           0 :         const size_t nFamilyCount = pStyleFamilies->size();
    1128             :         size_t n;
    1129           0 :         for( n = 0; n < nFamilyCount; n++ )
    1130           0 :             if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
    1131           0 :         if ( n == nFamilyCount )
    1132             :             // It happens sometimes, God knows why
    1133           0 :             return;
    1134           0 :         ppItem += StyleNrToInfoOffset(n);
    1135           0 :         nAppFilter = (*ppItem)->GetValue();
    1136           0 :         FamilySelect(  StyleNrToInfoOffset(n)+1 );
    1137           0 :         pItem = GetFamilyItem_Impl();
    1138             :     }
    1139             : 
    1140           0 :     const SfxStyleFamily eFam = pItem->GetFamily();
    1141             : 
    1142           0 :     SfxFilterTupel* pT = ( nActFilter < pItem->GetFilterList().size() ? pItem->GetFilterList()[nActFilter] : NULL );
    1143           0 :     sal_uInt16 nFilter     = pT ? pT->nFlags : 0;
    1144           0 :     if(!nFilter)   // automatic
    1145           0 :         nFilter = nAppFilter;
    1146             : 
    1147             :     OSL_ENSURE(pStyleSheetPool, "no StyleSheetPool");
    1148           0 :     if(pStyleSheetPool)
    1149             :     {
    1150           0 :         pStyleSheetPool->SetSearchMask(eFam, nFilter);
    1151           0 :         pItem = GetFamilyItem_Impl();
    1152           0 :         if((nFlags & UPDATE_FAMILY) == UPDATE_FAMILY)   // Update view type list (Hierarchical, All, etc.
    1153             :         {
    1154           0 :             CheckItem(nActFamily, true);    // check Button in Toolbox
    1155           0 :             aFilterLb->SetUpdateMode(false);
    1156           0 :             aFilterLb->Clear();
    1157             :             //insert hierarchical at the beginning
    1158           0 :             sal_uInt16 nPos = aFilterLb->InsertEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString(), 0);
    1159           0 :             aFilterLb->SetEntryData( nPos, reinterpret_cast<void*>(SFXSTYLEBIT_ALL) );
    1160           0 :             const SfxStyleFilter& rFilter = pItem->GetFilterList();
    1161           0 :             for( size_t i = 0; i < rFilter.size(); ++i)
    1162             :             {
    1163           0 :                 sal_uIntPtr nFilterFlags = rFilter[ i ]->nFlags;
    1164           0 :                 nPos = aFilterLb->InsertEntry( rFilter[ i ]->aName );
    1165           0 :                 aFilterLb->SetEntryData( nPos, reinterpret_cast<void*>(nFilterFlags) );
    1166             :             }
    1167           0 :             if(nActFilter < aFilterLb->GetEntryCount() - 1)
    1168           0 :                 aFilterLb->SelectEntryPos(nActFilter + 1);
    1169             :             else
    1170             :             {
    1171           0 :                 nActFilter = 0;
    1172           0 :                 aFilterLb->SelectEntryPos(1);
    1173           0 :                 SfxFilterTupel* pActT = ( nActFilter < rFilter.size() ) ? rFilter[ nActFilter ] : NULL;
    1174           0 :                 sal_uInt16 nFilterFlags = pActT ? pActT->nFlags : 0;
    1175           0 :                 pStyleSheetPool->SetSearchMask(eFam, nFilterFlags);
    1176             :             }
    1177             : 
    1178             :             // if the tree view again, select family hierarchy
    1179           0 :             if (pTreeBox || m_bWantHierarchical)
    1180             :             {
    1181           0 :                 aFilterLb->SelectEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString());
    1182           0 :                 EnableHierarchical(true);
    1183             :             }
    1184             : 
    1185             :             // show maximum 14 entries
    1186           0 :             aFilterLb->SetDropDownLineCount( MAX_FILTER_ENTRIES );
    1187           0 :             aFilterLb->SetUpdateMode(true);
    1188             :         }
    1189             :         else
    1190             :         {
    1191           0 :             if (nActFilter < aFilterLb->GetEntryCount() - 1)
    1192           0 :                 aFilterLb->SelectEntryPos(nActFilter + 1);
    1193             :             else
    1194             :             {
    1195           0 :                 nActFilter = 0;
    1196           0 :                 aFilterLb->SelectEntryPos(1);
    1197             :             }
    1198             :         }
    1199             : 
    1200           0 :         if(nFlags & UPDATE_FAMILY_LIST)
    1201             :         {
    1202           0 :             EnableItem(SID_STYLE_WATERCAN,false);
    1203             : 
    1204           0 :             SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
    1205           0 :             SvTreeListEntry* pEntry = aFmtLb->First();
    1206           0 :             std::vector<OUString> aStrings;
    1207             : 
    1208             :             comphelper::string::NaturalStringSorter aSorter(
    1209             :                 ::comphelper::getProcessComponentContext(),
    1210           0 :                 Application::GetSettings().GetLanguageTag().getLocale());
    1211             : 
    1212           0 :             while( pStyle )
    1213             :             {
    1214             :                 //Bubblesort
    1215             :                 size_t nPos;
    1216           0 :                 for(nPos = aStrings.size(); nPos && aSorter.compare(aStrings[nPos-1], pStyle->GetName()) > 0; --nPos)
    1217             :                 {};
    1218           0 :                 aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
    1219           0 :                 pStyle = pStyleSheetPool->Next();
    1220             :             }
    1221             : 
    1222           0 :             size_t nCount = aStrings.size();
    1223           0 :             size_t nPos = 0;
    1224           0 :             while(nPos < nCount && pEntry &&
    1225           0 :                   aStrings[nPos] == aFmtLb->GetEntryText(pEntry))
    1226             :             {
    1227           0 :                 ++nPos;
    1228           0 :                 pEntry = aFmtLb->Next( pEntry );
    1229             :             }
    1230             : 
    1231           0 :             if( nPos < nCount || pEntry )
    1232             :             {
    1233             :                 // Fills the display box
    1234           0 :                 aFmtLb->SetUpdateMode(false);
    1235           0 :                 aFmtLb->Clear();
    1236             : 
    1237           0 :                 for(nPos = 0; nPos < nCount; ++nPos)
    1238             :                 {
    1239           0 :                     SvTreeListEntry* pTreeListEntry = aFmtLb->InsertEntry(aStrings[nPos], 0, false, nPos);
    1240           0 :                     StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, aStrings[nPos], eFam);
    1241           0 :                     pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
    1242           0 :                     aFmtLb->GetModel()->InvalidateEntry(pTreeListEntry);
    1243             :                 }
    1244           0 :                 aFmtLb->Recalc();
    1245           0 :                 aFmtLb->SetUpdateMode(true);
    1246             :             }
    1247             :             // Selects the current style if any
    1248           0 :             SfxTemplateItem *pState = pFamilyState[nActFamily-1];
    1249           0 :             OUString aStyle;
    1250           0 :             if(pState)
    1251           0 :                 aStyle = pState->GetStyleName();
    1252             : #if defined STYLESPREVIEW
    1253             :             mbIgnoreSelect = true; // in case we get a selection change
    1254             :             // in anycase we should stop any preview
    1255             :             Execute_Impl(SID_STYLE_END_PREVIEW,
    1256             :             OUString(), OUString(),
    1257             :             0, 0, 0, 0 );
    1258             : #endif
    1259           0 :             SelectStyle(aStyle);
    1260           0 :             EnableDelete();
    1261             :         }
    1262             :     }
    1263             : }
    1264             : 
    1265             : // Updated display: Watering the house
    1266           0 : void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
    1267             : {
    1268           0 :     bWaterDisabled =  pItem == 0;
    1269             : 
    1270           0 :     if(!bWaterDisabled)
    1271             :         //make sure the watercan is only activated when there is (only) one selection
    1272           0 :         bWaterDisabled = pTreeBox || aFmtLb->GetSelectionCount() <= 1;
    1273             : 
    1274           0 :     if(pItem && !bWaterDisabled)
    1275             :     {
    1276           0 :         CheckItem(SID_STYLE_WATERCAN, pItem->GetValue());
    1277           0 :         EnableItem( SID_STYLE_WATERCAN, true );
    1278             :     }
    1279             :     else
    1280           0 :         if(!bWaterDisabled)
    1281           0 :             EnableItem(SID_STYLE_WATERCAN, true);
    1282             :         else
    1283           0 :             EnableItem(SID_STYLE_WATERCAN, false);
    1284             : 
    1285             : // Ignore while in watercan mode statusupdates
    1286             : 
    1287           0 :     size_t nCount = pStyleFamilies->size();
    1288           0 :     pBindings->EnterRegistrations();
    1289           0 :     for(size_t n = 0; n < nCount; n++)
    1290             :     {
    1291           0 :         SfxControllerItem *pCItem=pBoundItems[n];
    1292           0 :         bool bChecked = pItem && pItem->GetValue();
    1293           0 :         if( pCItem->IsBound() == bChecked )
    1294             :         {
    1295           0 :             if( !bChecked )
    1296           0 :                 pCItem->ReBind();
    1297             :             else
    1298           0 :                 pCItem->UnBind();
    1299             :         }
    1300             :     }
    1301           0 :     pBindings->LeaveRegistrations();
    1302           0 : }
    1303             : 
    1304             : // Item with the status of a Family is copied and noted
    1305             : // (is updated when all states have also been updated.)
    1306             : // See also: <SfxBindings::AddDoneHdl(const Link &)>
    1307           0 : void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
    1308             : {
    1309           0 :     sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START;
    1310           0 :     DELETEZ(pFamilyState[nIdx]);
    1311           0 :     if ( pItem )
    1312           0 :         pFamilyState[nIdx] = new SfxTemplateItem(*pItem);
    1313           0 :     bUpdate = true;
    1314             : 
    1315             :     // If used templates (how the hell you find this out??)
    1316           0 :     bUpdateFamily = true;
    1317           0 : }
    1318             : 
    1319             : // Notice from SfxBindings that the update is completed. Pushes out the update
    1320             : // of the display.
    1321           0 : void SfxCommonTemplateDialog_Impl::Update_Impl()
    1322             : {
    1323           0 :     bool bDocChanged=false;
    1324           0 :     SfxStyleSheetBasePool* pNewPool = NULL;
    1325           0 :     SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
    1326           0 :     SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
    1327           0 :     if( pDocShell )
    1328           0 :         pNewPool = pDocShell->GetStyleSheetPool();
    1329             : 
    1330           0 :     if ( pNewPool != pStyleSheetPool && pDocShell )
    1331             :     {
    1332           0 :         SfxModule* pNewModule = pDocShell->GetModule();
    1333           0 :         if( pNewModule && pNewModule != pModule )
    1334             :         {
    1335           0 :             ClearResource();
    1336           0 :             ReadResource();
    1337             :         }
    1338           0 :         if ( pStyleSheetPool )
    1339             :         {
    1340           0 :             EndListening(*pStyleSheetPool);
    1341           0 :             pStyleSheetPool = 0;
    1342             :         }
    1343             : 
    1344           0 :         if ( pNewPool )
    1345             :         {
    1346           0 :             StartListening(*pNewPool);
    1347           0 :             pStyleSheetPool = pNewPool;
    1348           0 :             bDocChanged=true;
    1349             :         }
    1350             :     }
    1351             : 
    1352           0 :     if (bUpdateFamily)
    1353           0 :         UpdateFamily_Impl();
    1354             : 
    1355             :     sal_uInt16 i;
    1356           0 :     for(i = 0; i < MAX_FAMILIES; ++i)
    1357           0 :         if(pFamilyState[i])
    1358           0 :             break;
    1359           0 :     if(i == MAX_FAMILIES || !pNewPool)
    1360             :         // nothing is allowed
    1361           0 :         return;
    1362             : 
    1363           0 :      SfxTemplateItem *pItem = 0;
    1364             :      // current region not within the allowed region or default
    1365           0 :      if(nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1] ) )
    1366             :      {
    1367           0 :          CheckItem(nActFamily, false);
    1368           0 :          SfxTemplateItem **ppItem = pFamilyState;
    1369           0 :          const size_t nFamilyCount = pStyleFamilies->size();
    1370             :          size_t n;
    1371           0 :          for( n = 0; n < nFamilyCount; n++ )
    1372           0 :              if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
    1373           0 :          ppItem+=StyleNrToInfoOffset(n);
    1374             : 
    1375           0 :          nAppFilter = (*ppItem)->GetValue();
    1376           0 :          FamilySelect(  StyleNrToInfoOffset(n)+1 );
    1377             : 
    1378           0 :          pItem = *ppItem;
    1379             :      }
    1380           0 :      else if( bDocChanged )
    1381             :      {
    1382             :          // other DocShell -> all new
    1383           0 :          CheckItem( nActFamily, true );
    1384           0 :          nActFilter = static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pDocShell ) );
    1385           0 :          if ( SFXSTYLEBIT_ALL == nActFilter )
    1386           0 :             nActFilter = pDocShell->GetAutoStyleFilterIndex();
    1387             : 
    1388           0 :          nAppFilter = pItem->GetValue();
    1389           0 :          if(!pTreeBox)
    1390             :          {
    1391           0 :              UpdateStyles_Impl(UPDATE_FAMILY_LIST);
    1392             :          }
    1393             :          else
    1394           0 :              FillTreeBox();
    1395             :      }
    1396             :      else
    1397             :      {
    1398             :          // other filters for automatic
    1399           0 :          CheckItem( nActFamily, true );
    1400           0 :          const SfxStyleFamilyItem *pStyleItem =  GetFamilyItem_Impl();
    1401           0 :          if ( pStyleItem && 0 == pStyleItem->GetFilterList()[ nActFilter ]->nFlags
    1402           0 :             && nAppFilter != pItem->GetValue())
    1403             :          {
    1404           0 :              nAppFilter = pItem->GetValue();
    1405           0 :              if(!pTreeBox)
    1406           0 :                  UpdateStyles_Impl(UPDATE_FAMILY_LIST);
    1407             :              else
    1408           0 :                  FillTreeBox();
    1409             :          }
    1410             :          else
    1411           0 :              nAppFilter = pItem->GetValue();
    1412             :      }
    1413           0 :      const OUString aStyle(pItem->GetStyleName());
    1414           0 :      SelectStyle(aStyle);
    1415           0 :      EnableDelete();
    1416           0 :      EnableNew( bCanNew );
    1417             : }
    1418             : 
    1419           0 : IMPL_LINK_NOARG_TYPED( SfxCommonTemplateDialog_Impl, TimeOut, Idle *, void )
    1420             : {
    1421           0 :     if(!bDontUpdate)
    1422             :     {
    1423           0 :         bDontUpdate=true;
    1424           0 :         if(!pTreeBox)
    1425           0 :             UpdateStyles_Impl(UPDATE_FAMILY_LIST);
    1426             :         else
    1427             :         {
    1428           0 :             FillTreeBox();
    1429           0 :             SfxTemplateItem *pState = pFamilyState[nActFamily-1];
    1430           0 :             if(pState)
    1431             :             {
    1432           0 :                 const OUString aStyle(pState->GetStyleName());
    1433           0 :                 SelectStyle(aStyle);
    1434           0 :                 EnableDelete();
    1435             :             }
    1436             :         }
    1437           0 :         bDontUpdate=false;
    1438           0 :         DELETEZ(pIdle);
    1439             :     }
    1440             :     else
    1441           0 :         pIdle->Start();
    1442           0 : }
    1443             : 
    1444           0 : void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
    1445             : {
    1446             :     // tap update
    1447           0 :     const SfxSimpleHint* pSfxSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
    1448           0 :     if(pSfxSimpleHint)
    1449             :     {
    1450           0 :         switch(pSfxSimpleHint->GetId())
    1451             :         {
    1452             :           case SFX_HINT_UPDATEDONE:
    1453             :             {
    1454           0 :                 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
    1455           0 :                 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
    1456           0 :                 if (
    1457           0 :                     bUpdate &&
    1458             :                     (
    1459           0 :                      !IsCheckedItem(SID_STYLE_WATERCAN) ||
    1460           0 :                      (pDocShell && pDocShell->GetStyleSheetPool() != pStyleSheetPool)
    1461             :                     )
    1462             :                    )
    1463             :                 {
    1464           0 :                     bUpdate = false;
    1465           0 :                     Update_Impl();
    1466             :                 }
    1467           0 :                 else if ( bUpdateFamily )
    1468             :                 {
    1469           0 :                     UpdateFamily_Impl();
    1470             :                 }
    1471             : 
    1472           0 :                 if( pStyleSheetPool )
    1473             :                 {
    1474           0 :                     OUString aStr = GetSelectedEntry();
    1475           0 :                     if( !aStr.isEmpty() && pStyleSheetPool )
    1476             :                     {
    1477           0 :                         const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    1478           0 :                         if( !pItem ) break;
    1479           0 :                         const SfxStyleFamily eFam = pItem->GetFamily();
    1480             :                         SfxStyleSheetBase *pStyle =
    1481             :                             pStyleSheetPool->Find(
    1482           0 :                                 aStr, eFam, SFXSTYLEBIT_ALL );
    1483           0 :                         if( pStyle )
    1484             :                         {
    1485           0 :                             bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
    1486           0 :                             EnableEdit( bReadWrite );
    1487           0 :                             EnableHide( bReadWrite && !pStyle->IsUsed( ) && !pStyle->IsHidden( ) );
    1488           0 :                             EnableShow( bReadWrite && pStyle->IsHidden( ) );
    1489             :                         }
    1490             :                         else
    1491             :                         {
    1492           0 :                             EnableEdit(false);
    1493           0 :                             EnableHide(false);
    1494           0 :                             EnableShow(false);
    1495             :                         }
    1496           0 :                     }
    1497             :                 }
    1498           0 :                 break;
    1499             :             }
    1500             : 
    1501             :         // Necessary if switching between documents and in both documents
    1502             :         // the same template is used. Do not immediately call Update_Impl,
    1503             :         // for the case that one of the documents is an internal InPlaceObjekt!
    1504             :           case SFX_HINT_DOCCHANGED:
    1505           0 :             bUpdate = true;
    1506           0 :             break;
    1507             :           case SFX_HINT_DYING:
    1508             :           {
    1509           0 :             EndListening(*pStyleSheetPool);
    1510           0 :             pStyleSheetPool=0;
    1511           0 :             break;
    1512             :           }
    1513             :         }
    1514             :     }
    1515             : 
    1516             :     // Do not set timer when the stylesheet pool is in the box, because it is
    1517             :     // possible that a new one is registered after the timer is up -
    1518             :     // works bad in UpdateStyles_Impl ()!
    1519             : 
    1520           0 :     sal_uIntPtr nId = pSfxSimpleHint ? pSfxSimpleHint->GetId() : 0;
    1521             : 
    1522           0 :     if(!bDontUpdate && nId != SFX_HINT_DYING &&
    1523           0 :        (dynamic_cast<const SfxStyleSheetPoolHint*>(&rHint) ||
    1524           0 :         dynamic_cast<const SfxStyleSheetHint*>(&rHint) ||
    1525           0 :         dynamic_cast<const SfxStyleSheetHintExtended*>(&rHint)))
    1526             :     {
    1527           0 :         if(!pIdle)
    1528             :         {
    1529           0 :             pIdle=new Idle;
    1530           0 :             pIdle->SetPriority(SchedulerPriority::LOWEST);
    1531           0 :             pIdle->SetIdleHdl(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut));
    1532             :         }
    1533           0 :         pIdle->Start();
    1534             : 
    1535             :     }
    1536           0 : }
    1537             : 
    1538             : // Other filters; can be switched by the users or as a result of new or
    1539             : // editing, if the current document has been assigned a different filter.
    1540           0 : void SfxCommonTemplateDialog_Impl::FilterSelect(
    1541             :                 sal_uInt16 nEntry,  // Idx of the new Filters
    1542             :                 bool bForce )   // Force update, even if the new filter is
    1543             :                                 // equal to the current
    1544             : {
    1545           0 :     if( nEntry != nActFilter || bForce )
    1546             :     {
    1547           0 :         nActFilter = nEntry;
    1548           0 :         SfxObjectShell *const pDocShell = SaveSelection();
    1549           0 :         SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
    1550           0 :         pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
    1551           0 :         if ( pOldStyleSheetPool != pStyleSheetPool )
    1552             :         {
    1553           0 :             if ( pOldStyleSheetPool )
    1554           0 :                 EndListening(*pOldStyleSheetPool);
    1555           0 :             if ( pStyleSheetPool )
    1556           0 :                 StartListening(*pStyleSheetPool);
    1557             :         }
    1558             : 
    1559           0 :         UpdateStyles_Impl(UPDATE_FAMILY_LIST);
    1560             :     }
    1561           0 : }
    1562             : 
    1563             : // Internal: Perform functions through the Dispatcher
    1564           0 : bool SfxCommonTemplateDialog_Impl::Execute_Impl(
    1565             :     sal_uInt16 nId, const OUString &rStr, const OUString& rRefStr, sal_uInt16 nFamily,
    1566             :     sal_uInt16 nMask, sal_uInt16 *pIdx, const sal_uInt16* pModifier)
    1567             : {
    1568           0 :     SfxDispatcher &rDispatcher = *SfxGetpApp()->GetDispatcher_Impl();
    1569           0 :     SfxStringItem aItem(nId, rStr);
    1570           0 :     SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
    1571           0 :     SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
    1572           0 :     SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
    1573           0 :     SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
    1574             :     const SfxPoolItem* pItems[ 6 ];
    1575           0 :     sal_uInt16 nCount = 0;
    1576           0 :     if( !rStr.isEmpty() )
    1577           0 :         pItems[ nCount++ ] = &aItem;
    1578           0 :     pItems[ nCount++ ] = &aFamily;
    1579           0 :     if( nMask )
    1580           0 :         pItems[ nCount++ ] = &aMask;
    1581           0 :     if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
    1582             :     {
    1583             :         // Special solution for Numbering update in Writer
    1584           0 :         const OUString aTemplName(GetSelectedEntry());
    1585           0 :         aUpdName.SetValue(aTemplName);
    1586           0 :         pItems[ nCount++ ] = &aUpdName;
    1587             :     }
    1588             : 
    1589           0 :     if ( !rRefStr.isEmpty() )
    1590           0 :         pItems[ nCount++ ] = &aRefName;
    1591             : 
    1592           0 :     pItems[ nCount++ ] = 0;
    1593             : 
    1594           0 :     DeletionWatcher aDeleted(*this);
    1595           0 :     sal_uInt16 nModi = pModifier ? *pModifier : 0;
    1596             :     const SfxPoolItem* pItem = rDispatcher.Execute(
    1597             :         nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD | SfxCallMode::MODAL,
    1598           0 :         pItems, nModi );
    1599             : 
    1600             :     // Dialog can be destroyed while in Execute() because started
    1601             :     // subdialogs are not modal to it (#i97888#).
    1602           0 :     if ( !pItem || aDeleted )
    1603           0 :         return false;
    1604             : 
    1605           0 :     if ( (nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId) && (pTreeBox || aFmtLb->GetSelectionCount() <= 1) )
    1606             :     {
    1607           0 :         const SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem);
    1608             :         OSL_ENSURE(pFilterItem, "SfxUINT16Item expected");
    1609           0 :         sal_uInt16 nFilterFlags = pFilterItem->GetValue() & ~SFXSTYLEBIT_USERDEF;
    1610           0 :         if(!nFilterFlags)       // User Template?
    1611           0 :             nFilterFlags = pFilterItem->GetValue();
    1612           0 :         const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
    1613           0 :         const size_t nFilterCount = pFamilyItem->GetFilterList().size();
    1614             : 
    1615           0 :         for ( size_t i = 0; i < nFilterCount; ++i )
    1616             :         {
    1617           0 :             const SfxFilterTupel *pTupel = pFamilyItem->GetFilterList()[ i ];
    1618             : 
    1619           0 :             if ( ( pTupel->nFlags & nFilterFlags ) == nFilterFlags && pIdx )
    1620           0 :                 *pIdx = i;
    1621             :         }
    1622             :     }
    1623             : 
    1624           0 :     return true;
    1625             : }
    1626             : 
    1627             : // Handler der Listbox der Filter
    1628           0 : void SfxCommonTemplateDialog_Impl::EnableHierarchical(bool const bEnable)
    1629             : {
    1630           0 :     if (bEnable)
    1631             :     {
    1632           0 :         if (!bHierarchical)
    1633             :         {
    1634             :             // Turn on treeView
    1635           0 :             bHierarchical=true;
    1636           0 :             m_bWantHierarchical = true;
    1637           0 :             SaveSelection(); // fdo#61429 store "hierarchical"
    1638           0 :             const OUString aSelectEntry( GetSelectedEntry());
    1639           0 :             aFmtLb->Hide();
    1640             : 
    1641           0 :             pTreeBox = VclPtr<StyleTreeListBox_Impl>::Create(
    1642             : 
    1643             :                     this, WB_HASBUTTONS | WB_HASLINES |
    1644             :                     WB_BORDER | WB_TABSTOP | WB_HASLINESATROOT |
    1645           0 :                     WB_HASBUTTONSATROOT | WB_HIDESELECTION | WB_QUICK_SEARCH );
    1646           0 :             pTreeBox->SetFont( aFmtLb->GetFont() );
    1647             : 
    1648           0 :             pTreeBox->SetPosSizePixel(aFmtLb->GetPosPixel(), aFmtLb->GetSizePixel());
    1649           0 :             pTreeBox->SetNodeDefaultImages();
    1650           0 :             pTreeBox->SetSelectHdl(
    1651           0 :                 LINK(this, SfxCommonTemplateDialog_Impl, FmtSelectHdl));
    1652             :             pTreeBox->SetDoubleClickHdl(
    1653           0 :                     LINK(this, SfxCommonTemplateDialog_Impl,  ApplyHdl));
    1654           0 :             pTreeBox->SetDropHdl(LINK(this, SfxCommonTemplateDialog_Impl,  DropHdl));
    1655           0 :             pTreeBox->SetOptimalImageIndent();
    1656           0 :             FillTreeBox();
    1657           0 :             SelectStyle(aSelectEntry);
    1658           0 :             pTreeBox->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
    1659           0 :             pTreeBox->Show();
    1660             :         }
    1661             :     }
    1662             :     else
    1663             :     {
    1664           0 :         pTreeBox.disposeAndClear();
    1665           0 :         aFmtLb->Show();
    1666             :         // If bHierarchical, then the family can have changed
    1667             :         // minus one since hierarchical is inserted at the start
    1668           0 :         m_bWantHierarchical = false; // before FilterSelect
    1669           0 :         FilterSelect(aFilterLb->GetSelectEntryPos() - 1, bHierarchical );
    1670           0 :         bHierarchical=false;
    1671             :     }
    1672           0 : }
    1673             : 
    1674           0 : IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox )
    1675             : {
    1676           0 :     if (SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString() == pBox->GetSelectEntry())
    1677             :     {
    1678           0 :         EnableHierarchical(true);
    1679             :     }
    1680             :     else
    1681             :     {
    1682           0 :         EnableHierarchical(false);
    1683             :     }
    1684             : 
    1685           0 :     return 0;
    1686             : }
    1687             : 
    1688             : // Select-Handler for the Toolbox
    1689           0 : void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry)
    1690             : {
    1691           0 :     if( nEntry != nActFamily )
    1692             :     {
    1693           0 :         CheckItem( nActFamily, false );
    1694           0 :         nActFamily = nEntry;
    1695           0 :         SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
    1696           0 :         SfxUInt16Item aItem( SID_STYLE_FAMILY, nEntry );
    1697           0 :         pDispat->Execute( SID_STYLE_FAMILY, SfxCallMode::SYNCHRON, &aItem, 0L );
    1698           0 :         pBindings->Invalidate( SID_STYLE_FAMILY );
    1699           0 :         pBindings->Update( SID_STYLE_FAMILY );
    1700           0 :         UpdateFamily_Impl();
    1701             :     }
    1702           0 : }
    1703             : 
    1704           0 : void SfxCommonTemplateDialog_Impl::ActionSelect(sal_uInt16 nEntry)
    1705             : {
    1706           0 :     OUString aEmpty;
    1707           0 :     switch(nEntry)
    1708             :     {
    1709             :         case SID_STYLE_WATERCAN:
    1710             :         {
    1711           0 :             const bool bState = IsCheckedItem(nEntry);
    1712             :             bool bCheck;
    1713           0 :             SfxBoolItem aBool;
    1714             :             // when a template is chosen.
    1715           0 :             if (!bState && HasSelectedStyle())
    1716             :             {
    1717             :                 const OUString aTemplName(
    1718           0 :                     GetSelectedEntry());
    1719             :                 Execute_Impl(
    1720             :                     SID_STYLE_WATERCAN, aTemplName, aEmpty,
    1721           0 :                     (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
    1722           0 :                 bCheck = true;
    1723             :             }
    1724             :             else
    1725             :             {
    1726           0 :                 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
    1727           0 :                 bCheck = false;
    1728             :             }
    1729           0 :             CheckItem(nEntry, bCheck);
    1730           0 :             aBool.SetValue(bCheck);
    1731           0 :             SetWaterCanState(&aBool);
    1732           0 :             break;
    1733             :         }
    1734             :         case SID_STYLE_NEW_BY_EXAMPLE:
    1735             :         {
    1736           0 :             if(pStyleSheetPool && nActFamily != 0xffff)
    1737             :             {
    1738           0 :                 const SfxStyleFamily eFam=GetFamilyItem_Impl()->GetFamily();
    1739           0 :                 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    1740             :                 sal_uInt16 nFilter;
    1741           0 :                 if( pItem && nActFilter != SFXSTYLEBIT_ALL )
    1742             :                 {
    1743           0 :                     nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
    1744           0 :                     if(!nFilter)    // automatisch
    1745           0 :                         nFilter = nAppFilter;
    1746             :                 }
    1747             :                 else
    1748           0 :                     nFilter=pStyleSheetPool->GetSearchMask();
    1749           0 :                 pStyleSheetPool->SetSearchMask( eFam, SFXSTYLEBIT_USERDEF );
    1750             : 
    1751           0 :                 ScopedVclPtrInstance< SfxNewStyleDlg > pDlg(pWindow, *pStyleSheetPool);
    1752             :                 // why? : FloatingWindow must not be parent of a modal dialog
    1753           0 :                 if(RET_OK == pDlg->Execute())
    1754             :                 {
    1755           0 :                     pStyleSheetPool->SetSearchMask(eFam, nFilter);
    1756           0 :                     const OUString aTemplName(pDlg->GetName());
    1757             :                     Execute_Impl(SID_STYLE_NEW_BY_EXAMPLE,
    1758             :                                  aTemplName, aEmpty,
    1759           0 :                                  (sal_uInt16)GetFamilyItem_Impl()->GetFamily(),
    1760           0 :                                  nFilter);
    1761             :                 }
    1762           0 :                 pStyleSheetPool->SetSearchMask( eFam, nFilter );
    1763             :             }
    1764           0 :             break;
    1765             :         }
    1766             :         case SID_STYLE_UPDATE_BY_EXAMPLE:
    1767             :         {
    1768             :             Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
    1769             :                     aEmpty, aEmpty,
    1770           0 :                     (sal_uInt16)GetFamilyItem_Impl()->GetFamily());
    1771           0 :             break;
    1772             :         }
    1773             :         case SID_TEMPLATE_LOAD:
    1774           0 :             SfxGetpApp()->GetDispatcher_Impl()->Execute(nEntry);
    1775           0 :         break;
    1776           0 :         default: OSL_FAIL("not implemented"); break;
    1777           0 :     }
    1778           0 : }
    1779             : 
    1780           0 : static OUString getModuleIdentifier( const Reference< XModuleManager2 >& i_xModMgr, SfxObjectShell* i_pObjSh )
    1781             : {
    1782             :     OSL_ENSURE( i_xModMgr.is(), "getModuleIdentifier(): no XModuleManager" );
    1783             :     OSL_ENSURE( i_pObjSh, "getModuleIdentifier(): no ObjectShell" );
    1784             : 
    1785           0 :     OUString sIdentifier;
    1786             : 
    1787             :     try
    1788             :     {
    1789           0 :         sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
    1790             :     }
    1791           0 :     catch ( ::com::sun::star::frame::UnknownModuleException& )
    1792             :     {
    1793             :         OSL_TRACE( "getModuleIdentifier(): unknown module" );
    1794             :     }
    1795           0 :     catch ( Exception& )
    1796             :     {
    1797             :         OSL_FAIL( "getModuleIdentifier(): exception of XModuleManager::identify()" );
    1798             :     }
    1799             : 
    1800           0 :     return sIdentifier;
    1801             : }
    1802             : 
    1803           0 : sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh )
    1804             : {
    1805             :     OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
    1806             : 
    1807             :     ::comphelper::SequenceAsHashMap aFactoryProps(
    1808           0 :         xModuleManager->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
    1809           0 :     sal_Int32 nDefault = -1;
    1810           0 :     sal_Int32 nFilter = aFactoryProps.getUnpackedValueOrDefault( "ooSetupFactoryStyleFilter", nDefault );
    1811             : 
    1812             :     m_bWantHierarchical =
    1813           0 :         (nFilter & SFXSTYLEBIT_HIERARCHY) != 0;
    1814           0 :     nFilter &= ~SFXSTYLEBIT_HIERARCHY; // clear it
    1815             : 
    1816           0 :     return nFilter;
    1817             : }
    1818             : 
    1819           0 : void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter )
    1820             : {
    1821             :     OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
    1822           0 :     Sequence< PropertyValue > lProps(1);
    1823           0 :     lProps[0].Name = "ooSetupFactoryStyleFilter";
    1824           0 :     lProps[0].Value = makeAny(
    1825           0 :             i_nFilter | (m_bWantHierarchical ? SFXSTYLEBIT_HIERARCHY : 0));
    1826           0 :     xModuleManager->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) );
    1827           0 : }
    1828             : 
    1829           0 : SfxObjectShell* SfxCommonTemplateDialog_Impl::SaveSelection()
    1830             : {
    1831           0 :     SfxViewFrame *const pViewFrame(pBindings->GetDispatcher_Impl()->GetFrame());
    1832           0 :     SfxObjectShell *const pDocShell(pViewFrame->GetObjectShell());
    1833           0 :     if (pDocShell)
    1834             :     {
    1835           0 :         pDocShell->SetAutoStyleFilterIndex(nActFilter);
    1836           0 :         SaveFactoryStyleFilter( pDocShell, nActFilter );
    1837             :     }
    1838           0 :     return pDocShell;
    1839             : }
    1840             : 
    1841           0 : IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox )
    1842             : {
    1843           0 :     bDontUpdate=true;
    1844           0 :     const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    1845           0 :     const SfxStyleFamily eFam = pItem->GetFamily();
    1846           0 :     long ret= pStyleSheetPool->SetParent(eFam,pBox->GetStyle(), pBox->GetParent())? 1L: 0L;
    1847           0 :     bDontUpdate=false;
    1848           0 :     return ret;
    1849             : }
    1850             : 
    1851             : // Handler for the New-Buttons
    1852           0 : void SfxCommonTemplateDialog_Impl::NewHdl(void *)
    1853             : {
    1854           0 :     OUString aEmpty;
    1855           0 :     if ( nActFamily != 0xffff && (pTreeBox || aFmtLb->GetSelectionCount() <= 1))
    1856             :     {
    1857             :         vcl::Window* pTmp;
    1858           0 :         pTmp = Application::GetDefDialogParent();
    1859           0 :         if ( ISA(SfxTemplateDialog_Impl) )
    1860           0 :             Application::SetDefDialogParent( pWindow->GetParent() );
    1861             :         else
    1862           0 :             Application::SetDefDialogParent( pWindow );
    1863             : 
    1864           0 :         const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    1865           0 :         const SfxStyleFamily eFam=pItem->GetFamily();
    1866             :         sal_uInt16 nMask;
    1867           0 :         if( nActFilter != SFXSTYLEBIT_ALL )
    1868             :         {
    1869           0 :             nMask = pItem->GetFilterList()[ nActFilter ]->nFlags;
    1870           0 :             if(!nMask)    // automatic
    1871           0 :                 nMask = nAppFilter;
    1872             :         }
    1873             :         else
    1874           0 :             nMask=pStyleSheetPool->GetSearchMask();
    1875             : 
    1876           0 :         pStyleSheetPool->SetSearchMask(eFam,nMask);
    1877             : 
    1878             :         Execute_Impl(SID_STYLE_NEW,
    1879             :                      aEmpty, GetSelectedEntry(),
    1880           0 :                      ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
    1881           0 :                      nMask);
    1882             : 
    1883           0 :         Application::SetDefDialogParent( pTmp );
    1884           0 :     }
    1885           0 : }
    1886             : 
    1887             : // Handler for the edit-Buttons
    1888           0 : void SfxCommonTemplateDialog_Impl::EditHdl(void *)
    1889             : {
    1890           0 :     if(IsInitialized() && HasSelectedStyle())
    1891             :     {
    1892           0 :         sal_uInt16 nFilter = nActFilter;
    1893           0 :         OUString aTemplName(GetSelectedEntry());
    1894           0 :         GetSelectedStyle(); // -Wall required??
    1895             :         vcl::Window* pTmp;
    1896             :         //DefModalDialogParent set for modality of the following dialogs
    1897           0 :         pTmp = Application::GetDefDialogParent();
    1898           0 :         if ( ISA(SfxTemplateDialog_Impl) )
    1899           0 :             Application::SetDefDialogParent( pWindow->GetParent() );
    1900             :         else
    1901           0 :             Application::SetDefDialogParent( pWindow );
    1902           0 :         if ( Execute_Impl( SID_STYLE_EDIT, aTemplName, OUString(),
    1903           0 :                           (sal_uInt16)GetFamilyItem_Impl()->GetFamily(), 0, &nFilter ) )
    1904             :         {
    1905             :         }
    1906           0 :         Application::SetDefDialogParent( pTmp );
    1907             :     }
    1908           0 : }
    1909             : 
    1910             : // Handler for the Delete-Buttons
    1911           0 : void SfxCommonTemplateDialog_Impl::DeleteHdl(void *)
    1912             : {
    1913           0 :     if ( IsInitialized() && HasSelectedStyle() )
    1914             :     {
    1915           0 :         bool bUsedStyle = false;     // one of the selected styles are used in the document?
    1916             : 
    1917           0 :         std::vector<SvTreeListEntry*> aList;
    1918           0 :         SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
    1919           0 :         const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
    1920             : 
    1921           0 :         OUString aMsg = SfxResId(STR_DELETE_STYLE_USED).toString();
    1922           0 :         aMsg += SfxResId(STR_DELETE_STYLE).toString();
    1923             : 
    1924           0 :         while (pEntry)
    1925             :         {
    1926           0 :             aList.push_back( pEntry );
    1927             :             // check the style is used or not
    1928           0 :             const OUString aTemplName(pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry));
    1929             : 
    1930           0 :             SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
    1931             : 
    1932           0 :             if ( pStyle->IsUsed() )  // pStyle is in use in the document?
    1933             :             {
    1934           0 :                 if (bUsedStyle) // add a separator for the second and later styles
    1935           0 :                     aMsg += ", ";
    1936           0 :                 aMsg += aTemplName;
    1937           0 :                 bUsedStyle = true;
    1938             :             }
    1939             : 
    1940           0 :             pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
    1941           0 :         }
    1942             : 
    1943           0 :         bool aApproved = false;
    1944             : 
    1945             :         // we only want to show the dialog once and if we want to delete a style in use (UX-advice)
    1946           0 :         if ( bUsedStyle )
    1947             :         {
    1948             :         #if defined UNX
    1949           0 :             ScopedVclPtrInstance<MessageDialog> aBox(SfxGetpApp()->GetTopWindow(), aMsg,
    1950           0 :                                VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
    1951             :         #else
    1952             :             ScopedVclPtrInstance<MessageDialog> aBox(GetWindow(), aMsg,
    1953             :                                VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
    1954             :         #endif
    1955           0 :             aApproved = aBox->Execute() == RET_YES;
    1956             :         }
    1957             : 
    1958             :         // if there are no used styles selected or the user approved the changes
    1959           0 :         if ( !bUsedStyle || aApproved )
    1960             :         {
    1961           0 :             std::vector<SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end();
    1962             : 
    1963           0 :             for (; it != itEnd; ++it)
    1964             :             {
    1965           0 :                 const OUString aTemplName(pTreeBox ? pTreeBox->GetEntryText(*it) : aFmtLb->GetEntryText(*it));
    1966           0 :                 bDontUpdate = true; // To prevent the Treelistbox to shut down while deleting
    1967             :                 Execute_Impl( SID_STYLE_DELETE, aTemplName,
    1968           0 :                               OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
    1969             : 
    1970           0 :                 if ( pTreeBox )
    1971             :                 {
    1972           0 :                     pTreeBox->RemoveParentKeepChildren( *it );
    1973           0 :                     bDontUpdate = false;
    1974             :                 }
    1975           0 :             }
    1976           0 :             bDontUpdate = false; //if everything is deleted set bDontUpdate back to false
    1977           0 :             UpdateStyles_Impl(UPDATE_FAMILY_LIST); //and force-update the list
    1978           0 :         }
    1979             :     }
    1980           0 : }
    1981             : 
    1982           0 : void SfxCommonTemplateDialog_Impl::HideHdl(void *)
    1983             : {
    1984           0 :     if ( IsInitialized() && HasSelectedStyle() )
    1985             :     {
    1986           0 :         SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
    1987             : 
    1988           0 :         while (pEntry)
    1989             :         {
    1990           0 :             OUString aTemplName = pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry);
    1991             : 
    1992             :             Execute_Impl( SID_STYLE_HIDE, aTemplName,
    1993           0 :                           OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
    1994             : 
    1995           0 :             pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
    1996           0 :         }
    1997             :     }
    1998           0 : }
    1999             : 
    2000           0 : void SfxCommonTemplateDialog_Impl::ShowHdl(void *)
    2001             : {
    2002             : 
    2003           0 :     if ( IsInitialized() && HasSelectedStyle() )
    2004             :     {
    2005           0 :         SvTreeListEntry* pEntry = pTreeBox ? pTreeBox->FirstSelected() : aFmtLb->FirstSelected();
    2006             : 
    2007           0 :         while (pEntry)
    2008             :         {
    2009           0 :             OUString aTemplName = pTreeBox ? pTreeBox->GetEntryText(pEntry) : aFmtLb->GetEntryText(pEntry);
    2010             : 
    2011             :             Execute_Impl( SID_STYLE_SHOW, aTemplName,
    2012           0 :                           OUString(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
    2013             : 
    2014           0 :             pEntry = pTreeBox ? pTreeBox->NextSelected(pEntry) : aFmtLb->NextSelected(pEntry);
    2015           0 :         }
    2016             :     }
    2017           0 : }
    2018             : 
    2019           0 : void SfxCommonTemplateDialog_Impl::EnableDelete()
    2020             : {
    2021           0 :     if(IsInitialized() && HasSelectedStyle())
    2022             :     {
    2023             :         OSL_ENSURE(pStyleSheetPool, "No StyleSheetPool");
    2024           0 :         const OUString aTemplName(GetSelectedEntry());
    2025           0 :         const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
    2026           0 :         const SfxStyleFamily eFam = pItem->GetFamily();
    2027           0 :         sal_uInt16 nFilter = 0;
    2028           0 :         if(pItem->GetFilterList().size() > nActFilter)
    2029           0 :             nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
    2030           0 :         if(!nFilter)    // automatic
    2031           0 :             nFilter = nAppFilter;
    2032             :         const SfxStyleSheetBase *pStyle =
    2033           0 :             pStyleSheetPool->Find(aTemplName,eFam, pTreeBox? SFXSTYLEBIT_ALL : nFilter);
    2034             : 
    2035             :         OSL_ENSURE(pStyle, "Style not found");
    2036           0 :         if(pStyle && pStyle->IsUserDefined())
    2037             :         {
    2038           0 :             EnableDel(true);
    2039             :         }
    2040             :         else
    2041             :         {
    2042           0 :             EnableDel(false);
    2043           0 :         }
    2044             :     }
    2045             :     else
    2046             :     {
    2047           0 :         EnableDel(false);
    2048             :     }
    2049           0 : }
    2050             : 
    2051             : // After selecting a focused item if possible again on the app window
    2052           0 : void SfxCommonTemplateDialog_Impl::ResetFocus()
    2053             : {
    2054           0 :     if(ISA(SfxTemplateDialog_Impl))
    2055             :     {
    2056           0 :         SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
    2057           0 :         SfxViewShell *pVu = pViewFrame->GetViewShell();
    2058           0 :         vcl::Window *pAppWin = pVu ? pVu->GetWindow(): 0;
    2059           0 :         if(pAppWin)
    2060           0 :             pAppWin->GrabFocus();
    2061             :     }
    2062           0 : }
    2063             : 
    2064             : // Double-click on a style sheet in the ListBox is applied.
    2065           0 : IMPL_LINK( SfxCommonTemplateDialog_Impl, ApplyHdl, Control *, pControl )
    2066             : {
    2067             :     (void)pControl; //unused
    2068             :     // only if that region is allowed
    2069           0 :     if ( IsInitialized() && 0 != pFamilyState[nActFamily-1] &&
    2070           0 :          !GetSelectedEntry().isEmpty() )
    2071             :     {
    2072           0 :         sal_uInt16 nModifier = aFmtLb->GetModifier();
    2073             :         Execute_Impl(SID_STYLE_APPLY,
    2074             :                      GetSelectedEntry(), OUString(),
    2075           0 :                      ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
    2076           0 :                      0, 0, &nModifier );
    2077             :     }
    2078           0 :     ResetFocus();
    2079           0 :     return 0;
    2080             : }
    2081             : 
    2082             : // Selection of a template during the Watercan-Status
    2083           0 : IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox )
    2084             : {
    2085             :     // Trigger Help PI, if this is permitted of call handlers and field
    2086           0 :     if( !pListBox || pListBox->IsSelected( pListBox->GetHdlEntry() ) )
    2087             :     {
    2088             :         // Only when the watercan is on
    2089           0 :         if ( IsInitialized() &&
    2090           0 :              IsCheckedItem(SID_STYLE_WATERCAN) &&
    2091             :              // only if that region is allowed
    2092           0 :              0 != pFamilyState[nActFamily-1] && (pTreeBox || aFmtLb->GetSelectionCount() <= 1) )
    2093             :         {
    2094           0 :             OUString aEmpty;
    2095             :             Execute_Impl(SID_STYLE_WATERCAN,
    2096           0 :                          aEmpty, aEmpty, 0);
    2097             :             Execute_Impl(SID_STYLE_WATERCAN,
    2098             :                          GetSelectedEntry(), aEmpty,
    2099           0 :                          ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily());
    2100             :         }
    2101           0 :         EnableItem(SID_STYLE_WATERCAN, !bWaterDisabled);
    2102           0 :         EnableDelete();
    2103             :     }
    2104           0 :     if( pListBox )
    2105             :     {
    2106           0 :         SelectStyle( pListBox->GetEntryText( pListBox->GetHdlEntry() ));
    2107             : #if defined STYLESPREVIEW
    2108             :         sal_uInt16 nModifier = aFmtLb->GetModifier();
    2109             :         if ( mbIgnoreSelect )
    2110             :         {
    2111             :             Execute_Impl(SID_STYLE_END_PREVIEW,
    2112             :             OUString(), OUString(),
    2113             :             0, 0, 0, 0 );
    2114             :             mbIgnoreSelect = false;
    2115             :         }
    2116             :         else
    2117             :         {
    2118             :             Execute_Impl(SID_STYLE_PREVIEW,
    2119             :                      GetSelectedEntry(), OUString(),
    2120             :                      ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
    2121             :                      0, 0, &nModifier );
    2122             :         }
    2123             : #endif
    2124             :     }
    2125             : 
    2126           0 :     return 0;
    2127             : }
    2128             : 
    2129           0 : IMPL_LINK( SfxCommonTemplateDialog_Impl, MenuSelectHdl, Menu *, pMenu )
    2130             : {
    2131           0 :     if( pMenu )
    2132             :     {
    2133           0 :         nLastItemId = pMenu->GetCurItemId();
    2134             :         Application::PostUserEvent(
    2135           0 :             LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ), 0 );
    2136           0 :         return sal_IntPtr(true);
    2137             :     }
    2138             : 
    2139           0 :     switch(nLastItemId) {
    2140           0 :     case ID_NEW: NewHdl(0); break;
    2141           0 :     case ID_EDIT: EditHdl(0); break;
    2142           0 :     case ID_DELETE: DeleteHdl(0); break;
    2143           0 :     case ID_HIDE: HideHdl(0); break;
    2144           0 :     case ID_SHOW: ShowHdl(0); break;
    2145           0 :     default: return sal_IntPtr(false);
    2146             :     }
    2147           0 :     return sal_IntPtr(true);
    2148             : }
    2149             : 
    2150           0 : SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const
    2151             : {
    2152           0 :     const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
    2153           0 :     if( !pFamilyItem || nActFamily == 0xffff )
    2154           0 :         return SFX_STYLE_FAMILY_PARA;
    2155             :     else
    2156           0 :         return pFamilyItem->GetFamily();
    2157             : }
    2158             : 
    2159           0 : void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, bool bEnable)
    2160             : {
    2161           0 :     if( nId == SID_STYLE_NEW_BY_EXAMPLE )
    2162             :     {
    2163           0 :         bNewByExampleDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1) || !bEnable;
    2164             :     }
    2165           0 :     else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
    2166           0 :         bUpdateByExampleDisabled = !(pTreeBox || aFmtLb->GetSelectionCount() <= 1) || !bEnable;
    2167             : 
    2168           0 :     EnableItem(nId, bEnable);
    2169           0 : }
    2170             : 
    2171           0 : PopupMenu* SfxCommonTemplateDialog_Impl::CreateContextMenu()
    2172             : {
    2173           0 :     if ( bBindingUpdate )
    2174             :     {
    2175           0 :         pBindings->Invalidate( SID_STYLE_NEW, true, false );
    2176           0 :         pBindings->Update( SID_STYLE_NEW );
    2177           0 :         bBindingUpdate = false;
    2178             :     }
    2179           0 :     PopupMenu* pMenu = new PopupMenu( SfxResId( MN_CONTEXT_TEMPLDLG ) );
    2180           0 :     pMenu->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ) );
    2181           0 :     pMenu->EnableItem( ID_EDIT, bCanEdit );
    2182           0 :     pMenu->EnableItem( ID_DELETE, bCanDel );
    2183           0 :     pMenu->EnableItem( ID_NEW, bCanNew );
    2184           0 :     pMenu->EnableItem( ID_HIDE, bCanHide );
    2185           0 :     pMenu->EnableItem( ID_SHOW, bCanShow );
    2186             : 
    2187           0 :     return pMenu;
    2188             : }
    2189             : 
    2190           0 : SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(SfxBindings* pB, SfxTemplatePanelControl* pDlgWindow)
    2191             :     : SfxCommonTemplateDialog_Impl(pB, pDlgWindow, true)
    2192             :     , m_pFloat(pDlgWindow)
    2193             :     , m_bZoomIn(false)
    2194             :     , m_aActionTbL(VclPtrInstance<DropToolBox_Impl>(pDlgWindow, this))
    2195           0 :     , m_aActionTbR(VclPtrInstance<ToolBox> (pDlgWindow, SfxResId(TB_ACTION)))
    2196             : {
    2197           0 :     pDlgWindow->FreeResource();
    2198           0 :     Initialize();
    2199           0 : }
    2200             : 
    2201           0 : void SfxTemplateDialog_Impl::Initialize()
    2202             : {
    2203           0 :     SfxCommonTemplateDialog_Impl::Initialize();
    2204             : 
    2205           0 :     m_aActionTbL->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
    2206           0 :     m_aActionTbR->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
    2207           0 :     m_aActionTbR->SetDropdownClickHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRClick));
    2208           0 :     m_aActionTbL->Show();
    2209           0 :     m_aActionTbR->Show();
    2210           0 :     vcl::Font aFont = aFilterLb->GetFont();
    2211           0 :     aFont.SetWeight( WEIGHT_NORMAL );
    2212           0 :     aFilterLb->SetFont( aFont );
    2213           0 :     m_aActionTbL->SetHelpId( HID_TEMPLDLG_TOOLBOX_LEFT );
    2214           0 : }
    2215             : 
    2216           0 : void SfxTemplateDialog_Impl::EnableFamilyItem( sal_uInt16 nId, bool bEnable )
    2217             : {
    2218           0 :     m_aActionTbL->EnableItem( nId, bEnable );
    2219           0 : }
    2220             : 
    2221             : // Insert element into dropdown filter "Frame Styles", "List Styles", etc.
    2222           0 : void SfxTemplateDialog_Impl::InsertFamilyItem(sal_uInt16 nId,const SfxStyleFamilyItem *pItem)
    2223             : {
    2224           0 :     OString sHelpId;
    2225           0 :     switch( (sal_uInt16) pItem->GetFamily() )
    2226             :     {
    2227           0 :         case SFX_STYLE_FAMILY_CHAR:     sHelpId = ".uno:CharStyle"; break;
    2228           0 :         case SFX_STYLE_FAMILY_PARA:     sHelpId = ".uno:ParaStyle"; break;
    2229           0 :         case SFX_STYLE_FAMILY_FRAME:    sHelpId = ".uno:FrameStyle"; break;
    2230           0 :         case SFX_STYLE_FAMILY_PAGE:     sHelpId = ".uno:PageStyle"; break;
    2231           0 :         case SFX_STYLE_FAMILY_PSEUDO:   sHelpId = ".uno:ListStyle"; break;
    2232           0 :         default: OSL_FAIL("unknown StyleFamily"); break;
    2233             :     }
    2234           0 :     m_aActionTbL->InsertItem( nId, pItem->GetImage(), pItem->GetText(), ToolBoxItemBits::NONE, 0);
    2235           0 :     m_aActionTbL->SetHelpId( nId, sHelpId );
    2236           0 : }
    2237             : 
    2238           0 : void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
    2239             : {
    2240           0 :     m_aActionTbR->HideItem(SID_STYLE_UPDATE_BY_EXAMPLE);
    2241             :     m_aActionTbR->SetItemBits( SID_STYLE_NEW_BY_EXAMPLE,
    2242           0 :             ToolBoxItemBits::DROPDOWNONLY|m_aActionTbR->GetItemBits( SID_STYLE_NEW_BY_EXAMPLE ));
    2243           0 : }
    2244             : 
    2245           0 : void SfxTemplateDialog_Impl::updateFamilyImages()
    2246             : {
    2247           0 :     if ( !m_pStyleFamiliesId )
    2248             :         // we do not have a resource id to load the new images from
    2249           0 :         return;
    2250             : 
    2251             :     // let the families collection update the images
    2252           0 :     pStyleFamilies->updateImages( *m_pStyleFamiliesId );
    2253             : 
    2254             :     // and set the new images on our toolbox
    2255           0 :     size_t nLoop = pStyleFamilies->size();
    2256           0 :     for( ; nLoop--; )
    2257             :     {
    2258           0 :         const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nLoop );
    2259           0 :         sal_uInt16 nId = SfxTemplate::SfxFamilyIdToNId( pItem->GetFamily() );
    2260           0 :         m_aActionTbL->SetItemImage( nId, pItem->GetImage() );
    2261             :     }
    2262             : }
    2263             : 
    2264           0 : void SfxTemplateDialog_Impl::updateNonFamilyImages()
    2265             : {
    2266           0 :     m_aActionTbR->SetImageList( ImageList( SfxResId( DLG_STYLE_DESIGNER ) ) );
    2267           0 : }
    2268             : 
    2269           0 : void SfxTemplateDialog_Impl::ClearFamilyList()
    2270             : {
    2271           0 :     m_aActionTbL->Clear();
    2272           0 : }
    2273             : 
    2274           0 : void SfxCommonTemplateDialog_Impl::InvalidateBindings()
    2275             : {
    2276           0 :     pBindings->Invalidate(SID_STYLE_NEW_BY_EXAMPLE, true, false);
    2277           0 :     pBindings->Update( SID_STYLE_NEW_BY_EXAMPLE );
    2278           0 :     pBindings->Invalidate(SID_STYLE_UPDATE_BY_EXAMPLE, true, false);
    2279           0 :     pBindings->Update( SID_STYLE_UPDATE_BY_EXAMPLE );
    2280           0 :     pBindings->Invalidate( SID_STYLE_WATERCAN, true, false);
    2281           0 :     pBindings->Update( SID_STYLE_WATERCAN );
    2282           0 :     pBindings->Invalidate( SID_STYLE_NEW, true, false );
    2283           0 :     pBindings->Update( SID_STYLE_NEW );
    2284           0 :     pBindings->Invalidate( SID_STYLE_DRAGHIERARCHIE, true, false );
    2285           0 :     pBindings->Update( SID_STYLE_DRAGHIERARCHIE );
    2286           0 : }
    2287             : 
    2288           0 : SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
    2289             : {
    2290           0 :     m_pFloat.clear();
    2291           0 :     m_aActionTbL.disposeAndClear();
    2292           0 :     m_aActionTbR.disposeAndClear();
    2293           0 : }
    2294             : 
    2295           0 : void SfxTemplateDialog_Impl::LoadedFamilies()
    2296             : {
    2297           0 :     updateFamilyImages();
    2298           0 :     Resize();
    2299           0 : }
    2300             : 
    2301             : // Override Resize-Handler ( StarView )
    2302             : // The size of the Listboxen is adjusted
    2303           0 : void SfxTemplateDialog_Impl::Resize()
    2304             : {
    2305           0 :     SfxDockingWindow* pDockingWindow = dynamic_cast<SfxDockingWindow*>(m_pFloat.get());
    2306           0 :     FloatingWindow *pF = pDockingWindow!=NULL ? pDockingWindow->GetFloatingWindow() : NULL;
    2307           0 :     if (pF)
    2308             :     {
    2309           0 :         m_bZoomIn = pF->IsRollUp();
    2310           0 :         if (m_bZoomIn)
    2311           0 :             return;
    2312             :     }
    2313             : 
    2314           0 :     if (m_pFloat == nullptr)
    2315           0 :         return;
    2316           0 :     Size aDlgSize=m_pFloat->PixelToLogic(m_pFloat->GetOutputSizePixel());
    2317           0 :     Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL->CalcWindowSizePixel());
    2318           0 :     Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR->CalcWindowSizePixel());
    2319           0 :     Size aMinSize = GetMinOutputSizePixel();
    2320             : 
    2321           0 :     long nListHeight = m_pFloat->PixelToLogic( aFilterLb->GetSizePixel() ).Height();
    2322           0 :     long nWidth = aDlgSize.Width()- 2 * SFX_TEMPLDLG_HFRAME;
    2323             : 
    2324           0 :     m_aActionTbL->SetPosSizePixel(m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,SFX_TEMPLDLG_VTOPFRAME)),
    2325           0 :                                  m_pFloat->LogicToPixel(aSizeATL));
    2326             : 
    2327             :     // only change the position of the right toolbox, when the window is wide
    2328             :     // enough
    2329           0 :     Point aPosATR(aDlgSize.Width()-SFX_TEMPLDLG_HFRAME-aSizeATR.Width(),SFX_TEMPLDLG_VTOPFRAME);
    2330           0 :     if(aDlgSize.Width() >= aMinSize.Width())
    2331           0 :         m_aActionTbR->SetPosPixel(m_pFloat->LogicToPixel(aPosATR));
    2332             :     else
    2333           0 :         m_aActionTbR->SetPosPixel( m_pFloat->LogicToPixel(
    2334           0 :             Point( SFX_TEMPLDLG_HFRAME + aSizeATL.Width() + SFX_TEMPLDLG_MIDHSPACE,
    2335           0 :                    SFX_TEMPLDLG_VTOPFRAME ) ) );
    2336             : 
    2337           0 :     m_aActionTbR->SetSizePixel(m_pFloat->LogicToPixel(aSizeATR));
    2338             : 
    2339             :     Point aFilterPos(
    2340           0 :         m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,
    2341           0 :             aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-nListHeight)) );
    2342             : 
    2343             :     Size aFilterSize(
    2344           0 :         m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) );
    2345             : 
    2346             :     Point aFmtPos(
    2347           0 :         m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME +
    2348           0 :                             SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) );
    2349             :     Size aFmtSize(
    2350           0 :         m_pFloat->LogicToPixel(Size(nWidth,
    2351           0 :                     aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME -
    2352           0 :                     SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE-
    2353           0 :                     nListHeight-aSizeATL.Height())) );
    2354             : 
    2355             :     // only change the position of the listbox, when the window is high enough
    2356           0 :     if(aDlgSize.Height() >= aMinSize.Height())
    2357             :     {
    2358           0 :         aFilterLb->SetPosPixel(aFilterPos);
    2359           0 :         aFmtLb->SetPosPixel( aFmtPos );
    2360           0 :         if(pTreeBox)
    2361           0 :             pTreeBox->SetPosPixel(aFmtPos);
    2362             :     }
    2363             :     else
    2364           0 :         aFmtSize.Height() += aFilterSize.Height();
    2365             : 
    2366           0 :     aFilterLb->SetSizePixel(aFilterSize);
    2367           0 :     aFmtLb->SetSizePixel( aFmtSize );
    2368           0 :     if(pTreeBox)
    2369           0 :         pTreeBox->SetSizePixel(aFmtSize);
    2370             : }
    2371             : 
    2372           0 : Size SfxTemplateDialog_Impl::GetMinOutputSizePixel()
    2373             : {
    2374           0 :     if (m_pFloat != nullptr)
    2375             :     {
    2376           0 :         Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL->CalcWindowSizePixel());
    2377           0 :         Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR->CalcWindowSizePixel());
    2378             :         Size aMinSize=Size(
    2379           0 :             aSizeATL.Width()+aSizeATR.Width()+
    2380             :                 2*SFX_TEMPLDLG_HFRAME + SFX_TEMPLDLG_MIDHSPACE,
    2381           0 :             4*aSizeATL.Height()+2*SFX_TEMPLDLG_MIDVSPACE);
    2382           0 :         return aMinSize;
    2383             :     }
    2384             :     else
    2385           0 :         return Size(0,0);
    2386             : }
    2387             : 
    2388           0 : void SfxTemplateDialog_Impl::EnableItem(sal_uInt16 nMesId, bool bCheck)
    2389             : {
    2390           0 :     OUString aEmpty;
    2391           0 :     switch(nMesId)
    2392             :     {
    2393             :         case SID_STYLE_WATERCAN :
    2394           0 :             if(!bCheck && IsCheckedItem(SID_STYLE_WATERCAN))
    2395           0 :                 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
    2396             :             //fall-through
    2397             :         case SID_STYLE_NEW_BY_EXAMPLE:
    2398             :         case SID_STYLE_UPDATE_BY_EXAMPLE:
    2399           0 :             m_aActionTbR->EnableItem(nMesId,bCheck);
    2400           0 :             break;
    2401           0 :     }
    2402           0 : }
    2403             : 
    2404           0 : void SfxTemplateDialog_Impl::CheckItem(sal_uInt16 nMesId, bool bCheck)
    2405             : {
    2406           0 :     switch(nMesId)
    2407             :     {
    2408             :         case SID_STYLE_WATERCAN :
    2409           0 :             bIsWater=bCheck;
    2410           0 :             m_aActionTbR->CheckItem(SID_STYLE_WATERCAN,bCheck);
    2411           0 :             break;
    2412             :         default:
    2413           0 :             m_aActionTbL->CheckItem(nMesId,bCheck); break;
    2414             :     }
    2415           0 : }
    2416             : 
    2417           0 : bool SfxTemplateDialog_Impl::IsCheckedItem(sal_uInt16 nMesId)
    2418             : {
    2419           0 :     switch(nMesId)
    2420             :     {
    2421             :         case SID_STYLE_WATERCAN :
    2422           0 :             return m_aActionTbR->GetItemState(SID_STYLE_WATERCAN)==TRISTATE_TRUE;
    2423             :         default:
    2424           0 :             return m_aActionTbL->GetItemState(nMesId)==TRISTATE_TRUE;
    2425             :     }
    2426             : }
    2427             : 
    2428           0 : IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox, void )
    2429             : {
    2430           0 :     const sal_uInt16 nEntry = pBox->GetCurItemId();
    2431           0 :     FamilySelect(nEntry);
    2432           0 : }
    2433             : 
    2434           0 : static OUString lcl_GetLabel(uno::Any& rAny)
    2435             : {
    2436           0 :     OUString sRet;
    2437           0 :     uno::Sequence< beans::PropertyValue >aPropSeq;
    2438           0 :     if ( rAny >>= aPropSeq )
    2439             :     {
    2440           0 :         for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
    2441             :         {
    2442           0 :             if ( aPropSeq[i].Name == "Label" )
    2443             :             {
    2444           0 :                 aPropSeq[i].Value >>= sRet;
    2445           0 :                 break;
    2446             :             }
    2447             :         }
    2448             :     }
    2449           0 :     return sRet;
    2450             : }
    2451             : 
    2452           0 : IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxRSelect, ToolBox *, pBox, void )
    2453             : {
    2454           0 :     const sal_uInt16 nEntry = pBox->GetCurItemId();
    2455           0 :     if(nEntry != SID_STYLE_NEW_BY_EXAMPLE ||
    2456           0 :             ToolBoxItemBits::DROPDOWN != (pBox->GetItemBits(nEntry)&ToolBoxItemBits::DROPDOWN))
    2457           0 :         ActionSelect(nEntry);
    2458           0 : }
    2459             : 
    2460           0 : IMPL_LINK_TYPED( SfxTemplateDialog_Impl, ToolBoxRClick, ToolBox *, pBox, void )
    2461             : {
    2462           0 :     const sal_uInt16 nEntry = pBox->GetCurItemId();
    2463           0 :     if(nEntry == SID_STYLE_NEW_BY_EXAMPLE &&
    2464           0 :             ToolBoxItemBits::DROPDOWN == (pBox->GetItemBits(nEntry)&ToolBoxItemBits::DROPDOWN))
    2465             :     {
    2466             :         //create a popup menu in Writer
    2467           0 :         boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
    2468             :         uno::Reference< container::XNameAccess > xNameAccess(
    2469             :                 frame::theUICommandDescription::get(
    2470           0 :                     ::comphelper::getProcessComponentContext()) );
    2471           0 :         uno::Reference< container::XNameAccess > xUICommands;
    2472           0 :         OUString sTextDoc("com.sun.star.text.TextDocument");
    2473           0 :         if(xNameAccess->hasByName(sTextDoc))
    2474             :         {
    2475           0 :             uno::Any a = xNameAccess->getByName( sTextDoc );
    2476           0 :             a >>= xUICommands;
    2477             :         }
    2478           0 :         if(!xUICommands.is())
    2479           0 :             return;
    2480             :         try
    2481             :         {
    2482           0 :             uno::Any aCommand = xUICommands->getByName(".uno:StyleNewByExample");
    2483           0 :             OUString sLabel = lcl_GetLabel( aCommand );
    2484           0 :             pMenu->InsertItem( SID_STYLE_NEW_BY_EXAMPLE, sLabel );
    2485           0 :             pMenu->SetHelpId(SID_STYLE_NEW_BY_EXAMPLE, HID_TEMPLDLG_NEWBYEXAMPLE);
    2486             : 
    2487           0 :             aCommand = xUICommands->getByName(".uno:StyleUpdateByExample");
    2488           0 :             sLabel = lcl_GetLabel( aCommand );
    2489             : 
    2490           0 :             pMenu->InsertItem( SID_STYLE_UPDATE_BY_EXAMPLE, sLabel );
    2491           0 :             pMenu->SetHelpId(SID_STYLE_UPDATE_BY_EXAMPLE, HID_TEMPLDLG_UPDATEBYEXAMPLE);
    2492             : 
    2493           0 :             aCommand = xUICommands->getByName(".uno:LoadStyles");
    2494           0 :             sLabel = lcl_GetLabel( aCommand );
    2495           0 :             pMenu->InsertItem( SID_TEMPLATE_LOAD, sLabel );
    2496           0 :             pMenu->SetHelpId(SID_TEMPLATE_LOAD, ".uno:LoadStyles");
    2497             : 
    2498           0 :             pMenu->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, MenuSelectHdl));
    2499             :             pMenu->Execute( pBox,
    2500           0 :                             pBox->GetItemRect(nEntry),
    2501           0 :                             PopupMenuFlags::ExecuteDown );
    2502           0 :             pBox->EndSelection();
    2503             :         }
    2504           0 :         catch(uno::Exception&)
    2505             :         {
    2506             :         }
    2507           0 :         pBox->Invalidate();
    2508             :     }
    2509             : }
    2510             : 
    2511           0 : IMPL_LINK( SfxTemplateDialog_Impl, MenuSelectHdl, Menu*, pMenu)
    2512             : {
    2513           0 :     sal_uInt16 nMenuId = pMenu->GetCurItemId();
    2514           0 :     ActionSelect(nMenuId);
    2515           0 :     return 0;
    2516             : }
    2517             : 
    2518           0 : void SfxCommonTemplateDialog_Impl::SetFamily( sal_uInt16 nId )
    2519             : {
    2520           0 :     if ( nId != nActFamily )
    2521             :     {
    2522           0 :         if ( nActFamily != 0xFFFF )
    2523           0 :             CheckItem( nActFamily, false );
    2524           0 :         nActFamily = nId;
    2525           0 :         if ( nId != 0xFFFF )
    2526           0 :             bUpdateFamily = true;
    2527             :     }
    2528           0 : }
    2529             : 
    2530           0 : void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl()
    2531             : {
    2532           0 :     bUpdateFamily = false;
    2533             : 
    2534           0 :     SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
    2535           0 :     SfxViewFrame *pViewFrame = pDispat->GetFrame();
    2536           0 :     SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
    2537             : 
    2538           0 :     SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
    2539           0 :     pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
    2540           0 :     if ( pOldStyleSheetPool != pStyleSheetPool )
    2541             :     {
    2542           0 :         if ( pOldStyleSheetPool )
    2543           0 :             EndListening(*pOldStyleSheetPool);
    2544           0 :         if ( pStyleSheetPool )
    2545           0 :             StartListening(*pStyleSheetPool);
    2546             :     }
    2547             : 
    2548           0 :     bWaterDisabled = false;
    2549           0 :     bCanNew = pTreeBox || aFmtLb->GetSelectionCount() <= 1;
    2550           0 :     bTreeDrag = true;
    2551           0 :     bUpdateByExampleDisabled = false;
    2552             : 
    2553           0 :     if (pStyleSheetPool)
    2554             :     {
    2555           0 :         if (!pTreeBox)
    2556           0 :             UpdateStyles_Impl(UPDATE_FAMILY | UPDATE_FAMILY_LIST);
    2557             :         else
    2558             :         {
    2559           0 :             UpdateStyles_Impl(UPDATE_FAMILY);
    2560           0 :             FillTreeBox();
    2561             :         }
    2562             :     }
    2563             : 
    2564           0 :     InvalidateBindings();
    2565             : 
    2566           0 :     if (IsCheckedItem(SID_STYLE_WATERCAN) &&
    2567             :          // only if that area is allowed
    2568           0 :          0 != pFamilyState[nActFamily - 1])
    2569             :     {
    2570             :         Execute_Impl(SID_STYLE_APPLY,
    2571             :                      GetSelectedEntry(),
    2572             :                      OUString(),
    2573           0 :                      static_cast<sal_uInt16>(GetFamilyItem_Impl()->GetFamily()));
    2574             :     }
    2575           0 : }
    2576             : 
    2577           0 : void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
    2578             : {
    2579             :     //does nothing
    2580           0 : }
    2581             : 
    2582           0 : DropToolBox_Impl::DropToolBox_Impl(vcl::Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog) :
    2583             :     ToolBox(pParent),
    2584             :     DropTargetHelper(this),
    2585           0 :     rParent(*pTemplateDialog)
    2586             : {
    2587           0 : }
    2588             : 
    2589           0 : sal_Int8 DropToolBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
    2590             : {
    2591           0 :     sal_Int8 nReturn = DND_ACTION_NONE;
    2592           0 :     sal_uInt16 nItemId = GetItemId( rEvt.maPosPixel );
    2593           0 :     if(USHRT_MAX != nItemId && !IsItemChecked( nItemId ))
    2594             :     {
    2595           0 :         SetCurItemId(nItemId);
    2596           0 :         GetSelectHdl().Call(this);
    2597             :     }
    2598             :     // special case: page styles are allowed to create new styles by example
    2599             :     // but not allowed to be created by drag and drop
    2600           0 :     if ( nItemId != SfxTemplate::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE )&&
    2601           0 :         IsDropFormatSupported( SotClipboardFormatId::OBJECTDESCRIPTOR ) &&
    2602           0 :         !rParent.bNewByExampleDisabled )
    2603             :     {
    2604           0 :         nReturn = DND_ACTION_COPY;
    2605             :     }
    2606           0 :     return nReturn;
    2607             : }
    2608             : 
    2609           0 : sal_Int8 DropToolBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
    2610             : {
    2611           0 :      return rParent.aFmtLb->ExecuteDrop(rEvt);
    2612         648 : }
    2613             : 
    2614             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11