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

Generated by: LCOV version 1.10