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

Generated by: LCOV version 1.10