LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/dialog - templdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 1392 0.1 %
Date: 2012-12-17 Functions: 2 189 1.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10