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

Generated by: LCOV version 1.10