Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / templdlg.cxx
blobdc5324cf55514552146d5996a07f38441512f126
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <boost/noncopyable.hpp>
21 #include <boost/scoped_ptr.hpp>
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>
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"
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>
65 #include <comphelper/configurationhelper.hxx>
66 #include <comphelper/string.hxx>
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;
73 //=========================================================================
74 // Window is now created dynamically. So here margins, etc.
76 #define SFX_TEMPLDLG_HFRAME 3
77 #define SFX_TEMPLDLG_VTOPFRAME 3
79 #define SFX_TEMPLDLG_VBOTFRAME 3
80 #define SFX_TEMPLDLG_MIDHSPACE 3
81 #define SFX_TEMPLDLG_MIDVSPACE 3
82 #define SFX_TEMPLDLG_FILTERHEIGHT 100
84 static sal_uInt16 nLastItemId = USHRT_MAX;
86 // filter box has maximum 14 entries visible
87 #define MAX_FILTER_ENTRIES 14
89 //=========================================================================
91 TYPEINIT0(SfxCommonTemplateDialog_Impl);
92 TYPEINIT1(SfxTemplateDialog_Impl,SfxCommonTemplateDialog_Impl);
94 SFX_IMPL_DOCKINGWINDOW_WITHID(SfxTemplateDialogWrapper, SID_STYLE_DESIGNER)
96 //-------------------------------------------------------------------------
98 class SfxCommonTemplateDialog_Impl::DeletionWatcher : private boost::noncopyable
100 typedef void (DeletionWatcher::* bool_type)();
102 public:
103 explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
104 : m_pDialog(&rDialog)
106 m_pDialog->impl_setDeletionWatcher(this);
109 ~DeletionWatcher()
111 if (m_pDialog)
112 m_pDialog->impl_setDeletionWatcher(0);
115 // Signal that the dialog was deleted
116 void signal()
118 m_pDialog = 0;
121 // Return true if the dialog was deleted
122 operator bool_type() const
124 return m_pDialog ? 0 : &DeletionWatcher::signal;
127 private:
128 SfxCommonTemplateDialog_Impl* m_pDialog;
131 // Re-direct functions
133 SfxTemplateDialog::SfxTemplateDialog
135 SfxBindings *pBind,
136 SfxChildWindow *pCW,
137 Window *pParent
140 /* [Description]
141 Designer class.
143 : SfxDockingWindow( pBind, pCW, pParent, SfxResId(DLG_STYLE_DESIGNER) ),
145 pImpl( new SfxTemplateDialog_Impl( pBind, this ) )
148 pImpl->updateNonFamilyImages();
151 //-------------------------------------------------------------------------
153 SfxTemplateDialog::~SfxTemplateDialog()
155 delete pImpl;
158 ISfxTemplateCommon* SfxTemplateDialog::GetISfxTemplateCommon()
160 return pImpl->GetISfxTemplateCommon();
163 void SfxTemplateDialog::SetParagraphFamily()
165 // first select the paragraph family
166 pImpl->FamilySelect( SFX_STYLE_FAMILY_PARA );
167 // then select the automatic filter
168 pImpl->SetAutomaticFilter();
171 // ------------------------------------------------------------------------
173 void SfxTemplateDialog::DataChanged( const DataChangedEvent& _rDCEvt )
175 if ( ( DATACHANGED_SETTINGS == _rDCEvt.GetType() ) &&
176 ( 0 != ( SETTINGS_STYLE & _rDCEvt.GetFlags() ) ) )
178 pImpl->updateFamilyImages();
179 pImpl->updateNonFamilyImages();
182 SfxDockingWindow::DataChanged( _rDCEvt );
185 //-------------------------------------------------------------------------
187 void SfxTemplateDialog::Update()
189 pImpl->Update();
192 //-------------------------------------------------------------------------
194 void SfxTemplateDialog::Resize()
196 if(pImpl)
197 pImpl->Resize();
198 SfxDockingWindow::Resize();
202 //-------------------------------------------------------------------------
204 SfxChildAlignment SfxTemplateDialog::CheckAlignment(SfxChildAlignment eActAlign,SfxChildAlignment eAlign)
206 switch (eAlign)
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 return eActAlign;
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 return eAlign;
224 default:
225 return eAlign;
229 //-------------------------------------------------------------------------
231 void DropListBox_Impl::MouseButtonDown( const MouseEvent& rMEvt )
233 nModifier = rMEvt.GetModifier();
235 sal_Bool bHitEmptySpace = ( NULL == GetEntry( rMEvt.GetPosPixel(), sal_True ) );
236 if( bHitEmptySpace && ( rMEvt.GetClicks() == 2 ) && rMEvt.IsMod1() )
237 Control::MouseButtonDown( rMEvt );
238 else
239 SvTreeListBox::MouseButtonDown( rMEvt );
242 sal_Int8 DropListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
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.
250 if ( IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
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 if( pDialog->nActFamily == SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE ) ||
255 pDialog->bNewByExampleDisabled )
256 return DND_ACTION_NONE;
257 else
258 return DND_ACTION_COPY;
260 return SvTreeListBox::AcceptDrop( rEvt );
263 //-------------------------------------------------------------------------
265 sal_Int8 DropListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
267 sal_Int8 nRet = DND_ACTION_NONE;
268 SfxObjectShell* pDocShell = pDialog->GetObjectShell();
269 TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
270 sal_uInt32 nFormatCount = aHelper.GetFormatCount();
271 if ( pDocShell )
273 sal_Bool bFormatFound = sal_False;
275 for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
277 SotFormatStringId nId = aHelper.GetFormat(i);
278 TransferableObjectDescriptor aDesc;
280 if ( aHelper.GetTransferableObjectDescriptor( nId, aDesc ) )
282 if ( aDesc.maClassName == pDocShell->GetFactory().GetClassId() )
284 PostUserEvent( LINK( this, DropListBox_Impl, OnAsyncExecuteDrop ), 0 );
286 bFormatFound = sal_True;
287 nRet = rEvt.mnAction;
288 break;
293 if ( !bFormatFound )
294 return SvTreeListBox::ExecuteDrop( rEvt );
297 return nRet;
301 IMPL_LINK_NOARG(DropListBox_Impl, OnAsyncExecuteDrop)
303 pDialog->ActionSelect( SID_STYLE_NEW_BY_EXAMPLE );
304 return 0;
307 long DropListBox_Impl::Notify( NotifyEvent& rNEvt )
309 long nRet = 0;
310 if( rNEvt.GetType() == EVENT_KEYINPUT )
312 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
313 if(!rKeyCode.GetModifier())
315 if( pDialog->bCanDel && KEY_DELETE == rKeyCode.GetCode())
317 pDialog->DeleteHdl( NULL );
318 nRet = 1;
320 else if( KEY_RETURN == rKeyCode.GetCode())
322 GetDoubleClickHdl().Call(this);
323 nRet = 1;
327 if(!nRet)
328 nRet = SvTreeListBox::Notify( rNEvt );
329 return nRet;
333 //-------------------------------------------------------------------------
336 SfxActionListBox::SfxActionListBox
338 SfxCommonTemplateDialog_Impl* pParent,
339 WinBits nWinBits
342 /* [Description]
344 ListBox class that starts a PopupMenu (designer specific) in the
345 command handler.
348 : DropListBox_Impl(pParent->GetWindow(), nWinBits, pParent)
351 EnableContextMenuHandling();
354 //-------------------------------------------------------------------------
356 PopupMenu* SfxActionListBox::CreateContextMenu( void )
359 if( !( GetSelectionCount() > 0 ) )
361 pDialog->EnableEdit( sal_False );
362 pDialog->EnableDel( sal_False );
364 return pDialog->CreateContextMenu();
367 //-------------------------------------------------------------------------
369 SfxTemplateDialogWrapper::SfxTemplateDialogWrapper(Window *pParentWnd,
370 sal_uInt16 nId, SfxBindings *p, SfxChildWinInfo *pInfo) :
371 SfxChildWindow(pParentWnd, nId)
373 SfxTemplateDialog *pWin = new SfxTemplateDialog(p, this, pParentWnd);
374 pWindow = pWin;
375 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
377 pWin->Initialize( pInfo );
378 pWin->SetMinOutputSizePixel(pWin->pImpl->GetMinOutputSizePixel());
381 void SfxTemplateDialogWrapper::SetParagraphFamily()
383 // forward to SfxTemplateDialog, because SfxTemplateDialog isn't exported
384 static_cast< SfxTemplateDialog* >( GetWindow() )->SetParagraphFamily();
389 //===== SfxTemplatePanelControl ===============================================
391 SfxTemplatePanelControl::SfxTemplatePanelControl (
392 SfxBindings* pBindings,
393 Window* pParentWindow)
394 : DockingWindow(pParentWindow, SfxResId(DLG_STYLE_DESIGNER) ),
395 pImpl(new SfxTemplateDialog_Impl(pBindings, this)),
396 mpBindings(pBindings)
398 OSL_ASSERT(mpBindings!=NULL);
400 pImpl->updateNonFamilyImages();
402 SetStyle(GetStyle() & ~WB_DOCKABLE);
408 SfxTemplatePanelControl::~SfxTemplatePanelControl (void)
410 delete pImpl;
416 ISfxTemplateCommon* SfxTemplatePanelControl::GetISfxTemplateCommon()
418 return pImpl->GetISfxTemplateCommon();
424 void SfxTemplatePanelControl::SetParagraphFamily()
426 // first select the paragraph family
427 pImpl->FamilySelect( SFX_STYLE_FAMILY_PARA );
428 // then select the automatic filter
429 pImpl->SetAutomaticFilter();
435 void SfxTemplatePanelControl::DataChanged( const DataChangedEvent& _rDCEvt )
437 if ( ( DATACHANGED_SETTINGS == _rDCEvt.GetType() ) &&
438 ( 0 != ( SETTINGS_STYLE & _rDCEvt.GetFlags() ) ) )
440 pImpl->updateFamilyImages();
441 pImpl->updateNonFamilyImages();
444 DockingWindow::DataChanged( _rDCEvt );
450 void SfxTemplatePanelControl::Update()
452 pImpl->Update();
458 void SfxTemplatePanelControl::Resize()
460 if(pImpl)
461 pImpl->Resize();
462 DockingWindow::Resize();
466 void SfxTemplatePanelControl::FreeResource (void)
468 DockingWindow::FreeResource();
472 SfxChildAlignment SfxTemplatePanelControl::CheckAlignment(SfxChildAlignment eActAlign,SfxChildAlignment eAlign)
474 switch (eAlign)
476 case SFX_ALIGN_TOP:
477 case SFX_ALIGN_HIGHESTTOP:
478 case SFX_ALIGN_LOWESTTOP:
479 case SFX_ALIGN_BOTTOM:
480 case SFX_ALIGN_LOWESTBOTTOM:
481 case SFX_ALIGN_HIGHESTBOTTOM:
482 return eActAlign;
484 case SFX_ALIGN_LEFT:
485 case SFX_ALIGN_RIGHT:
486 case SFX_ALIGN_FIRSTLEFT:
487 case SFX_ALIGN_LASTLEFT:
488 case SFX_ALIGN_FIRSTRIGHT:
489 case SFX_ALIGN_LASTRIGHT:
490 return eAlign;
492 default:
493 return eAlign;
498 void SfxTemplatePanelControl::StateChanged( StateChangedType nStateChange )
500 if ( nStateChange == STATE_CHANGE_INITSHOW )
502 SfxViewFrame *pFrame = mpBindings->GetDispatcher_Impl()->GetFrame();
503 Window* pEditWin = pFrame->GetViewShell()->GetWindow();
505 Size aSize = pEditWin->GetSizePixel();
506 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
507 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
508 Size aWinSize = GetSizePixel();
509 aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
510 aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
511 // SetFloatingPos( aPoint );
514 DockingWindow::StateChanged( nStateChange );
518 //=========================================================================
519 typedef std::vector<OUString> ExpandedEntries_t;
521 /* [Description]
523 TreeListBox class for displaying the hierarchical view of the templates
526 class StyleTreeListBox_Impl : public DropListBox_Impl
528 private:
529 SvTreeListEntry* pCurEntry;
530 Link aDoubleClickLink;
531 Link aDropLink;
532 String aParent;
533 String aStyle;
535 protected:
536 virtual void Command( const CommandEvent& rMEvt );
537 virtual long Notify( NotifyEvent& rNEvt );
538 virtual sal_Bool DoubleClickHdl();
539 virtual long ExpandingHdl();
540 virtual void ExpandedHdl();
541 virtual sal_Bool NotifyMoving(SvTreeListEntry* pTarget,
542 SvTreeListEntry* pEntry,
543 SvTreeListEntry*& rpNewParent,
544 sal_uIntPtr& rNewChildPos);
545 public:
546 StyleTreeListBox_Impl( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle = 0);
548 void SetDoubleClickHdl(const Link &rLink) { aDoubleClickLink = rLink; }
549 void SetDropHdl(const Link &rLink) { aDropLink = rLink; }
550 using SvTreeListBox::GetParent;
551 const String& GetParent() const { return aParent; }
552 const String& GetStyle() const { return aStyle; }
553 void MakeExpanded_Impl(ExpandedEntries_t& rEntries) const;
555 virtual PopupMenu* CreateContextMenu( void );
558 //-------------------------------------------------------------------------
561 void StyleTreeListBox_Impl::MakeExpanded_Impl(ExpandedEntries_t& rEntries) const
563 SvTreeListEntry *pEntry;
564 for(pEntry=(SvTreeListEntry*)FirstVisible();pEntry;pEntry=(SvTreeListEntry*)NextVisible(pEntry))
566 if(IsExpanded(pEntry))
568 rEntries.push_back(GetEntryText(pEntry));
573 PopupMenu* StyleTreeListBox_Impl::CreateContextMenu()
575 return pDialog->CreateContextMenu();
578 sal_Bool StyleTreeListBox_Impl::DoubleClickHdl()
580 /* [Description]
582 DoubleClick-Handler; calls the link.
583 SV virtual method.
586 aDoubleClickLink.Call(this);
587 return sal_False;
590 //-------------------------------------------------------------------------
592 void StyleTreeListBox_Impl::Command( const CommandEvent& rCEvt )
594 /* [Description]
596 Command Handler; this executes a PopupMenu (designer-specific)
597 SV virtual method.
600 SvTreeListBox::Command(rCEvt);
603 //-------------------------------------------------------------------------
605 long StyleTreeListBox_Impl::Notify( NotifyEvent& rNEvt )
607 // handle <RETURN> as double click
609 long nRet = 0;
610 if ( rNEvt.GetType() == EVENT_KEYINPUT )
612 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
613 if ( !rKeyCode.GetModifier() && KEY_RETURN == rKeyCode.GetCode() )
615 aDoubleClickLink.Call( this );
616 nRet = 1;
620 if ( !nRet )
621 nRet = DropListBox_Impl::Notify( rNEvt );
623 return nRet;
626 //-------------------------------------------------------------------------
628 sal_Bool StyleTreeListBox_Impl::NotifyMoving(SvTreeListEntry* pTarget,
629 SvTreeListEntry* pEntry,
630 SvTreeListEntry*& rpNewParent,
631 sal_uIntPtr& lPos)
632 /* [Description]
634 NotifyMoving Handler; This leads via a link on the event to the dialog.
635 SV virtual method.
638 if(!pTarget || !pEntry)
639 return sal_False;
640 aParent = GetEntryText(pTarget);
641 aStyle = GetEntryText(pEntry);
642 const sal_Bool bRet = (sal_Bool)aDropLink.Call(this);
643 rpNewParent = pTarget;
644 lPos=0;
645 IntlWrapper aIntlWrapper( Application::GetSettings().GetLanguageTag() );
646 const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
647 for(SvTreeListEntry *pTmpEntry=FirstChild(pTarget);
648 pTmpEntry && COMPARE_LESS==pCollator->compareString(
649 GetEntryText(pTmpEntry),GetEntryText(pEntry));
650 pTmpEntry=NextSibling(pTmpEntry),lPos++) ;
652 return bRet? (sal_Bool)2: sal_False;
655 //-------------------------------------------------------------------------
657 long StyleTreeListBox_Impl::ExpandingHdl()
659 /* [Description]
661 ExpandingHdl Handler; the current entry is noticed.
662 SV virtual method.
664 [Cross-reference]
665 <StyleTreeListBox_Impl::ExpandedHdl()>
668 pCurEntry = GetCurEntry();
669 return sal_True;
672 //-------------------------------------------------------------------------
674 void StyleTreeListBox_Impl::ExpandedHdl()
676 /* [Description]
678 ExpandedHdl Handler;
679 SV virtual method.
681 [Cross-reference]
682 <StyleTreeListBox_Impl::ExpandingHdl()>
686 SvTreeListEntry *pEntry = GetHdlEntry();
687 if(!IsExpanded(pEntry) && pCurEntry != GetCurEntry())
688 SelectAll( sal_False );
689 pCurEntry = 0;
692 //-------------------------------------------------------------------------
694 StyleTreeListBox_Impl::StyleTreeListBox_Impl(
695 SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle) :
696 DropListBox_Impl(pParent->GetWindow(), nWinStyle, pParent),
697 pCurEntry(0)
699 /* [Description]
701 Constructor StyleTreeListBox_Impl
704 EnableContextMenuHandling();
707 //-------------------------------------------------------------------------
709 class StyleTreeArr_Impl;
711 /* [Description]
713 Internal structure for the establishment of the hierarchical view
716 struct StyleTree_Impl
718 String aName;
719 String aParent;
720 StyleTreeArr_Impl *pChildren;
721 sal_Bool bIsExpanded;
722 sal_Bool HasParent() const { return aParent.Len() != 0; }
724 StyleTree_Impl(const String &rName, const String &rParent):
725 aName(rName), aParent(rParent), pChildren(0), bIsExpanded(0) {}
726 ~StyleTree_Impl();
727 void Put(StyleTree_Impl* pIns, sal_uIntPtr lPos=ULONG_MAX);
728 sal_uIntPtr Count();
731 class StyleTreeArr_Impl : public std::vector<StyleTree_Impl*>
733 public:
734 ~StyleTreeArr_Impl()
736 for(const_iterator it = begin(); it != end(); ++it)
737 delete *it;
742 sal_uIntPtr StyleTree_Impl::Count()
744 return pChildren ? pChildren->size() : 0L;
747 //-------------------------------------------------------------------------
749 StyleTree_Impl::~StyleTree_Impl()
751 delete pChildren;
754 //-------------------------------------------------------------------------
756 void StyleTree_Impl::Put(StyleTree_Impl* pIns, sal_uIntPtr lPos)
758 if ( !pChildren )
759 pChildren = new StyleTreeArr_Impl;
761 if ( ULONG_MAX == lPos )
762 pChildren->push_back( pIns );
763 else
764 pChildren->insert( pChildren->begin() + (sal_uInt16)lPos, pIns );
767 //-------------------------------------------------------------------------
769 StyleTreeArr_Impl &MakeTree_Impl(StyleTreeArr_Impl &rArr)
771 const sal_uInt16 nCount = rArr.size();
773 comphelper::string::NaturalStringSorter aSorter(
774 ::comphelper::getProcessComponentContext(),
775 Application::GetSettings().GetLanguageTag().getLocale());
777 // Arrange all under their Parents
778 sal_uInt16 i;
779 for(i = 0; i < nCount; ++i)
781 StyleTree_Impl* pEntry = rArr[i];
782 if(pEntry->HasParent())
784 for(sal_uInt16 j = 0; j < nCount; ++j)
786 StyleTree_Impl* pCmp = rArr[j];
787 if(pCmp->aName == pEntry->aParent)
789 // Paste initial filter
790 sal_uInt16 nPos;
791 for( nPos = 0 ; nPos < pCmp->Count() &&
792 aSorter.compare((*pCmp->pChildren)[nPos]->aName, pEntry->aName) < 0 ; nPos++)
794 pCmp->Put(pEntry,nPos);
795 break;
801 for(i = 0; i < rArr.size(); )
803 if(rArr[i]->HasParent())
804 rArr.erase(rArr.begin() + i);
805 else
806 ++i;
808 return rArr;
811 //-------------------------------------------------------------------------
814 inline sal_Bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
815 const OUString &rStr)
817 for (size_t n = 0; n < rEntries.size(); ++n)
819 if (rEntries[n] == rStr)
820 return sal_True;
822 return sal_False;
827 SvTreeListEntry* FillBox_Impl(SvTreeListBox *pBox,
828 StyleTree_Impl* pEntry,
829 const ExpandedEntries_t& rEntries,
830 SvTreeListEntry* pParent = 0)
832 SvTreeListEntry* pNewEntry = pBox->InsertEntry(pEntry->aName, pParent);
833 const sal_uInt16 nCount = pEntry->pChildren ? pEntry->pChildren->size() : 0;
834 for(sal_uInt16 i = 0; i < nCount; ++i)
835 FillBox_Impl(pBox, (*pEntry->pChildren)[i], rEntries, pNewEntry);
836 return pNewEntry;
839 //-------------------------------------------------------------------------
840 // Constructor
842 SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, Window* pW, bool ) :
844 aISfxTemplateCommon ( this ),
845 pBindings ( pB ),
846 pWindow ( pW ),
847 pModule ( NULL ),
848 pTimer ( NULL ),
849 m_pStyleFamiliesId ( NULL ),
850 pStyleSheetPool ( NULL ),
851 pTreeBox ( NULL ),
852 pCurObjShell ( NULL ),
853 xModuleManager ( frame::ModuleManager::create(::comphelper::getProcessComponentContext()) ),
854 m_pDeletionWatcher ( NULL ),
856 aFmtLb ( this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH ),
857 aFilterLb ( pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP ),
859 nActFamily ( 0xffff ),
860 nActFilter ( 0 ),
861 nAppFilter ( 0 ),
863 bDontUpdate ( sal_False ),
864 bIsWater ( sal_False ),
865 bEnabled ( sal_True ),
866 bUpdate ( sal_False ),
867 bUpdateFamily ( sal_False ),
868 bCanEdit ( sal_False ),
869 bCanDel ( sal_False ),
870 bCanNew ( sal_True ),
871 bCanHide ( sal_True ),
872 bCanShow ( sal_False ),
873 bWaterDisabled ( sal_False ),
874 bNewByExampleDisabled ( sal_False ),
875 bUpdateByExampleDisabled( sal_False ),
876 bTreeDrag ( sal_True ),
877 bHierarchical ( sal_False ),
878 m_bWantHierarchical ( sal_False ),
879 bBindingUpdate ( sal_True )
881 aFmtLb.SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
882 aFmtLb.SetHelpId( HID_TEMPLATE_FMT );
883 aFilterLb.SetHelpId( HID_TEMPLATE_FILTER );
884 aFmtLb.SetStyle( aFmtLb.GetStyle() | WB_SORT | WB_HIDESELECTION );
885 Font aFont = aFmtLb.GetFont();
886 aFont.SetWeight( WEIGHT_NORMAL );
887 aFmtLb.SetFont( aFont );
890 //-------------------------------------------------------------------------
892 sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId)
894 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nId );
895 return SfxFamilyIdToNId(pItem->GetFamily())-1;
898 //-------------------------------------------------------------------------
900 void SfxTemplateDialog_Impl::EnableEdit(sal_Bool bEnable)
902 SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
903 if( !bEnable || !bUpdateByExampleDisabled )
904 EnableItem( SID_STYLE_UPDATE_BY_EXAMPLE, bEnable);
907 //-------------------------------------------------------------------------
909 void SfxCommonTemplateDialog_Impl::ReadResource()
911 // Read global user resource
912 for(sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
913 pFamilyState[i] = 0;
915 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
916 pCurObjShell = pViewFrame->GetObjectShell();
917 ResMgr* pMgr = pCurObjShell ? pCurObjShell->GetResMgr() : NULL;
918 ResId aFamId( DLG_STYLE_DESIGNER, *pMgr );
919 aFamId.SetRT(RSC_SFX_STYLE_FAMILIES);
920 m_pStyleFamiliesId = new ResId( aFamId.GetId(), *pMgr );
921 m_pStyleFamiliesId->SetRT(RSC_SFX_STYLE_FAMILIES);
922 if( !pMgr || !pMgr->IsAvailable( aFamId ) )
923 pStyleFamilies = new SfxStyleFamilies;
924 else
925 pStyleFamilies = new SfxStyleFamilies( aFamId );
927 nActFilter = pCurObjShell ? static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pCurObjShell ) ) : SFXSTYLEBIT_ALL;
928 if ( pCurObjShell && SFXSTYLEBIT_ALL == nActFilter )
929 nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
931 // Paste in the toolbox
932 // reverse order, since always inserted at the head
933 size_t nCount = pStyleFamilies->size();
935 pBindings->ENTERREGISTRATIONS();
937 size_t i;
938 for(i = 0; i < nCount; ++i)
940 sal_uInt16 nSlot = 0;
941 switch( (sal_uInt16)pStyleFamilies->at( i )->GetFamily() )
943 case SFX_STYLE_FAMILY_CHAR: nSlot = SID_STYLE_FAMILY1; break;
944 case SFX_STYLE_FAMILY_PARA: nSlot = SID_STYLE_FAMILY2; break;
945 case SFX_STYLE_FAMILY_FRAME:nSlot = SID_STYLE_FAMILY3; break;
946 case SFX_STYLE_FAMILY_PAGE: nSlot = SID_STYLE_FAMILY4; break;
947 case SFX_STYLE_FAMILY_PSEUDO: nSlot = SID_STYLE_FAMILY5; break;
948 default: OSL_FAIL("unknown StyleFamily"); break;
950 pBoundItems[i] =
951 new SfxTemplateControllerItem(nSlot, *this, *pBindings);
953 pBoundItems[i++] = new SfxTemplateControllerItem(
954 SID_STYLE_WATERCAN, *this, *pBindings);
955 pBoundItems[i++] = new SfxTemplateControllerItem(
956 SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings);
957 pBoundItems[i++] = new SfxTemplateControllerItem(
958 SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings);
959 pBoundItems[i++] = new SfxTemplateControllerItem(
960 SID_STYLE_NEW, *this, *pBindings);
961 pBoundItems[i++] = new SfxTemplateControllerItem(
962 SID_STYLE_DRAGHIERARCHIE, *this, *pBindings);
963 pBoundItems[i++] = new SfxTemplateControllerItem(
964 SID_STYLE_EDIT, *this, *pBindings);
965 pBoundItems[i++] = new SfxTemplateControllerItem(
966 SID_STYLE_DELETE, *this, *pBindings);
967 pBoundItems[i++] = new SfxTemplateControllerItem(
968 SID_STYLE_FAMILY, *this, *pBindings);
969 pBindings->LEAVEREGISTRATIONS();
971 for(; i < COUNT_BOUND_FUNC; ++i)
972 pBoundItems[i] = 0;
974 StartListening(*pBindings);
976 // Insert in the reverse order of occurrence in the Style Families. This is for
977 // the toolbar of the designer. The list box of the catalog respects the
978 // correct order by itself.
980 // Sequences: the order of Resource = the order of Toolbar for example list box.
981 // Order of ascending SIDs: Low SIDs are displayed first when templates of
982 // several families are active.
984 // in the Writer the UpdateStyleByExample Toolbox button is removed and
985 // the NewStyle button gets a PopupMenu
986 if(nCount > 4)
987 ReplaceUpdateButtonByMenu();
989 for( ; nCount--; )
991 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nCount );
992 sal_uInt16 nId = SfxFamilyIdToNId( pItem->GetFamily() );
993 InsertFamilyItem( nId, pItem );
996 LoadedFamilies();
998 sal_uInt16 nStart = SID_STYLE_FAMILY1;
999 sal_uInt16 nEnd = SID_STYLE_FAMILY4;
1001 for ( i = nStart; i <= nEnd; i++ )
1002 pBindings->Update(i);
1004 pModule = pCurObjShell ? pCurObjShell->GetModule() : NULL;
1007 //-------------------------------------------------------------------------
1009 void SfxCommonTemplateDialog_Impl::ClearResource()
1011 ClearFamilyList();
1012 impl_clear();
1015 void SfxCommonTemplateDialog_Impl::impl_clear()
1017 DELETEX(pStyleFamilies);
1018 sal_uInt16 i;
1019 for ( i = 0; i < MAX_FAMILIES; ++i )
1020 DELETEX(pFamilyState[i]);
1021 for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
1022 delete pBoundItems[i];
1023 pCurObjShell = NULL;
1025 DELETEZ( m_pStyleFamiliesId );
1028 void SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(DeletionWatcher* pNewWatcher)
1030 m_pDeletionWatcher = pNewWatcher;
1033 //-------------------------------------------------------------------------
1035 void SfxCommonTemplateDialog_Impl::Initialize()
1037 // Read global user resource
1038 ReadResource();
1039 pBindings->Invalidate( SID_STYLE_FAMILY );
1040 pBindings->Update( SID_STYLE_FAMILY );
1042 Update_Impl();
1044 aFilterLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) );
1045 aFmtLb.SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) );
1046 aFmtLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) );
1047 aFmtLb.SetSelectionMode(MULTIPLE_SELECTION);
1050 aFilterLb.Show();
1051 if (!bHierarchical)
1052 aFmtLb.Show();
1055 //-------------------------------------------------------------------------
1057 SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
1059 String aEmpty;
1060 if ( bIsWater )
1061 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
1062 GetWindow()->Hide();
1063 impl_clear();
1064 if ( pStyleSheetPool )
1065 EndListening(*pStyleSheetPool);
1066 pStyleSheetPool = NULL;
1067 delete pTreeBox;
1068 delete pTimer;
1069 if ( m_pDeletionWatcher )
1070 m_pDeletionWatcher->signal();
1073 //-------------------------------------------------------------------------
1075 sal_uInt16 SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SfxStyleFamily nFamily )
1077 switch ( nFamily )
1079 case SFX_STYLE_FAMILY_CHAR: return 1;
1080 case SFX_STYLE_FAMILY_PARA: return 2;
1081 case SFX_STYLE_FAMILY_FRAME: return 3;
1082 case SFX_STYLE_FAMILY_PAGE: return 4;
1083 case SFX_STYLE_FAMILY_PSEUDO: return 5;
1084 default: return 0;
1088 void SfxCommonTemplateDialog_Impl::SetAutomaticFilter()
1090 sal_uInt16 nCount = aFilterLb.GetEntryCount();
1091 for ( sal_uInt16 i = 0; i < nCount; ++i )
1093 sal_uIntPtr nFlags = (sal_uIntPtr)aFilterLb.GetEntryData(i);
1094 if ( SFXSTYLEBIT_AUTO == nFlags )
1096 // automatic entry found -> select it
1097 aFilterLb.SelectEntryPos(i);
1098 // then call the handler to filter the styles
1099 FilterSelect( i - 1 );
1100 break;
1105 //-------------------------------------------------------------------------
1106 // Helper function: Access to the current family item
1107 const SfxStyleFamilyItem *SfxCommonTemplateDialog_Impl::GetFamilyItem_Impl() const
1109 const size_t nCount = pStyleFamilies->size();
1110 for(size_t i = 0; i < nCount; ++i)
1112 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( i );
1113 sal_uInt16 nId = SfxFamilyIdToNId(pItem->GetFamily());
1114 if(nId == nActFamily)
1115 return pItem;
1117 return 0;
1120 SfxStyleSheetBase *SfxCommonTemplateDialog_Impl::GetSelectedStyle() const
1122 if (!IsInitialized() || !pStyleSheetPool || !HasSelectedStyle())
1123 return NULL;
1124 const String aTemplName( GetSelectedEntry() );
1125 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1126 return pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
1129 //-------------------------------------------------------------------------
1131 void SfxCommonTemplateDialog_Impl::SelectStyle(const String &rStr)
1133 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1134 if ( !pItem )
1135 return;
1136 const SfxStyleFamily eFam = pItem->GetFamily();
1137 SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( rStr, eFam, SFXSTYLEBIT_ALL );
1138 if( pStyle )
1140 bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
1141 EnableEdit( bReadWrite );
1142 EnableHide( bReadWrite && !pStyle->IsHidden( ) && !pStyle->IsUsed( ) );
1143 EnableShow( bReadWrite && pStyle->IsHidden( ) );
1145 else
1147 EnableEdit( sal_False );
1148 EnableHide( sal_False );
1149 EnableShow( sal_False );
1152 if ( pTreeBox )
1154 if ( rStr.Len() )
1156 SvTreeListEntry* pEntry = pTreeBox->First();
1157 while ( pEntry )
1159 if ( pTreeBox->GetEntryText( pEntry ) == rStr )
1161 pTreeBox->MakeVisible( pEntry );
1162 pTreeBox->Select( pEntry );
1163 return;
1165 pEntry = pTreeBox->Next( pEntry );
1168 else
1169 pTreeBox->SelectAll( sal_False );
1171 else
1173 sal_Bool bSelect = ( rStr.Len() > 0 );
1174 if ( bSelect )
1176 SvTreeListEntry* pEntry = (SvTreeListEntry*)aFmtLb.FirstVisible();
1177 while ( pEntry && aFmtLb.GetEntryText( pEntry ) != rStr )
1178 pEntry = (SvTreeListEntry*)aFmtLb.NextVisible( pEntry );
1179 if ( !pEntry )
1180 bSelect = sal_False;
1181 else
1183 if (!aFmtLb.IsSelected(pEntry))
1185 aFmtLb.MakeVisible( pEntry );
1186 aFmtLb.SelectAll(false);
1187 aFmtLb.Select( pEntry );
1188 bWaterDisabled = (aFmtLb.GetSelectionCount() <=1 ? sal_False : sal_True);
1189 FmtSelectHdl( NULL );
1194 if ( !bSelect )
1196 aFmtLb.SelectAll( sal_False );
1197 EnableEdit(sal_False);
1198 EnableHide( sal_False );
1199 EnableShow( sal_False );
1204 //-------------------------------------------------------------------------
1206 String SfxCommonTemplateDialog_Impl::GetSelectedEntry() const
1208 String aRet;
1209 if ( pTreeBox )
1211 SvTreeListEntry* pEntry = pTreeBox->FirstSelected();
1212 if ( pEntry )
1213 aRet = pTreeBox->GetEntryText( pEntry );
1215 else
1217 SvTreeListEntry* pEntry = aFmtLb.FirstSelected();
1218 if ( pEntry )
1219 aRet = aFmtLb.GetEntryText( pEntry );
1221 return aRet;
1224 //-------------------------------------------------------------------------
1226 void SfxCommonTemplateDialog_Impl::EnableTreeDrag( sal_Bool bEnable )
1228 if ( pStyleSheetPool )
1230 SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
1231 if ( pTreeBox )
1233 if ( pStyle && pStyle->HasParentSupport() && bEnable )
1234 pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
1235 else
1236 pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
1239 bTreeDrag = bEnable;
1242 //-------------------------------------------------------------------------
1244 void SfxCommonTemplateDialog_Impl::FillTreeBox()
1246 OSL_ENSURE( pTreeBox, "FillTreeBox() without treebox");
1247 if(pStyleSheetPool && nActFamily != 0xffff)
1249 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1250 pStyleSheetPool->SetSearchMask(pItem->GetFamily(), SFXSTYLEBIT_ALL_VISIBLE);
1251 StyleTreeArr_Impl aArr;
1252 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
1253 if(pStyle && pStyle->HasParentSupport() && bTreeDrag )
1254 pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
1255 else
1256 pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
1257 while(pStyle)
1259 StyleTree_Impl* pNew =
1260 new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
1261 aArr.push_back(pNew);
1262 pStyle = pStyleSheetPool->Next();
1264 MakeTree_Impl(aArr);
1265 ExpandedEntries_t aEntries;
1266 if(pTreeBox)
1267 ((const StyleTreeListBox_Impl *)pTreeBox)->
1268 MakeExpanded_Impl( aEntries);
1269 pTreeBox->SetUpdateMode( sal_False );
1270 pTreeBox->Clear();
1271 const sal_uInt16 nCount = aArr.size();
1272 for(sal_uInt16 i = 0; i < nCount; ++i)
1273 FillBox_Impl(pTreeBox, aArr[i], aEntries);
1275 EnableItem(SID_STYLE_WATERCAN,sal_False);
1277 SfxTemplateItem* pState = pFamilyState[nActFamily-1];
1279 if ( nCount )
1280 pTreeBox->Expand( pTreeBox->First() );
1282 for ( SvTreeListEntry* pEntry = pTreeBox->First(); pEntry; pEntry = pTreeBox->Next( pEntry ) )
1284 if ( IsExpanded_Impl( aEntries, pTreeBox->GetEntryText( pEntry ) ) )
1285 pTreeBox->Expand( pEntry );
1288 pTreeBox->SetUpdateMode( sal_True );
1290 String aStyle;
1291 if(pState) // Select current entry
1292 aStyle = pState->GetStyleName();
1293 SelectStyle(aStyle);
1294 EnableDelete();
1298 //-------------------------------------------------------------------------
1299 sal_Bool SfxCommonTemplateDialog_Impl::HasSelectedStyle() const
1301 return pTreeBox? pTreeBox->FirstSelected() != 0:
1302 aFmtLb.GetSelectionCount() != 0;
1306 //-------------------------------------------------------------------------
1308 // internal: Refresh the display
1309 // nFlags: what we should update.
1310 void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags)
1312 OSL_ENSURE(nFlags, "nothing to do");
1313 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1314 if (!pItem)
1316 // Is the case for the template catalog
1317 SfxTemplateItem **ppItem = pFamilyState;
1318 const size_t nFamilyCount = pStyleFamilies->size();
1319 size_t n;
1320 for( n = 0; n < nFamilyCount; n++ )
1321 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1322 if ( n == nFamilyCount )
1323 // It happens sometimes, God knows why
1324 return;
1325 ppItem += StyleNrToInfoOffset(n);
1326 nAppFilter = (*ppItem)->GetValue();
1327 FamilySelect( StyleNrToInfoOffset(n)+1 );
1328 pItem = GetFamilyItem_Impl();
1331 const SfxStyleFamily eFam = pItem->GetFamily();
1333 SfxFilterTupel* pT = ( nActFilter < pItem->GetFilterList().size() ? pItem->GetFilterList()[nActFilter] : NULL );
1334 sal_uInt16 nFilter = pT ? pT->nFlags : 0;
1335 if(!nFilter) // automatic
1336 nFilter = nAppFilter;
1338 OSL_ENSURE(pStyleSheetPool, "no StyleSheetPool");
1339 if(pStyleSheetPool)
1341 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1342 pItem = GetFamilyItem_Impl();
1343 if((nFlags & UPDATE_FAMILY) == UPDATE_FAMILY) // Update view type list (Hierarchical, All, etc.
1345 CheckItem(nActFamily, sal_True); // check Button in Toolbox
1346 aFilterLb.SetUpdateMode(sal_False);
1347 aFilterLb.Clear();
1348 //insert hierarchical at the beginning
1349 sal_uInt16 nPos = aFilterLb.InsertEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString(), 0);
1350 aFilterLb.SetEntryData( nPos, (void*)(sal_uIntPtr)SFXSTYLEBIT_ALL );
1351 const SfxStyleFilter& rFilter = pItem->GetFilterList();
1352 for( size_t i = 0; i < rFilter.size(); ++i)
1354 sal_uIntPtr nFilterFlags = rFilter[ i ]->nFlags;
1355 nPos = aFilterLb.InsertEntry( rFilter[ i ]->aName );
1356 aFilterLb.SetEntryData( nPos, (void*)nFilterFlags );
1358 if(nActFilter < aFilterLb.GetEntryCount() - 1)
1359 aFilterLb.SelectEntryPos(nActFilter + 1);
1360 else
1362 nActFilter = 0;
1363 aFilterLb.SelectEntryPos(1);
1364 SfxFilterTupel* pActT = ( nActFilter < rFilter.size() ) ? rFilter[ nActFilter ] : NULL;
1365 sal_uInt16 nFilterFlags = pActT ? pActT->nFlags : 0;
1366 pStyleSheetPool->SetSearchMask(eFam, nFilterFlags);
1369 // if the tree view again, select family hierarchy
1370 if (pTreeBox || m_bWantHierarchical)
1372 aFilterLb.SelectEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString());
1373 EnableHierarchical(true);
1376 // show maximum 14 entries
1377 aFilterLb.SetDropDownLineCount( MAX_FILTER_ENTRIES );
1378 aFilterLb.SetUpdateMode(sal_True);
1380 else
1382 if (nActFilter < aFilterLb.GetEntryCount() - 1)
1383 aFilterLb.SelectEntryPos(nActFilter + 1);
1384 else
1386 nActFilter = 0;
1387 aFilterLb.SelectEntryPos(1);
1391 if(nFlags & UPDATE_FAMILY_LIST)
1393 EnableItem(SID_STYLE_WATERCAN,sal_False);
1395 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
1396 SvTreeListEntry* pEntry = aFmtLb.First();
1397 std::vector<OUString> aStrings;
1399 comphelper::string::NaturalStringSorter aSorter(
1400 ::comphelper::getProcessComponentContext(),
1401 Application::GetSettings().GetLanguageTag().getLocale());
1403 while( pStyle )
1405 //Bubblesort
1406 size_t nPos;
1407 for(nPos = aStrings.size(); nPos && aSorter.compare(aStrings[nPos-1], pStyle->GetName()) > 0; --nPos)
1409 aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
1410 pStyle = pStyleSheetPool->Next();
1413 size_t nCount = aStrings.size();
1414 size_t nPos = 0;
1415 while(nPos < nCount && pEntry &&
1416 aStrings[nPos] == OUString(aFmtLb.GetEntryText(pEntry)))
1418 ++nPos;
1419 pEntry = aFmtLb.Next( pEntry );
1422 if( nPos < nCount || pEntry )
1424 // Fills the display box
1425 aFmtLb.SetUpdateMode(sal_False);
1426 aFmtLb.Clear();
1428 for(nPos = 0; nPos < nCount; ++nPos)
1429 aFmtLb.InsertEntry(aStrings[nPos], 0, sal_False, nPos);
1431 aFmtLb.SetUpdateMode(true);
1433 // Selects the current style if any
1434 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1435 String aStyle;
1436 if(pState)
1437 aStyle = pState->GetStyleName();
1438 SelectStyle(aStyle);
1439 EnableDelete();
1444 //-------------------------------------------------------------------------
1446 // Updated display: Watering the house
1447 void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
1449 bWaterDisabled = pItem == 0;
1451 if(!bWaterDisabled)
1452 //make sure the watercan is only activated when there is (only) one selection
1453 bWaterDisabled = (aFmtLb.GetSelectionCount() <=1 ? sal_False : sal_True);
1455 if(pItem && !bWaterDisabled)
1457 CheckItem(SID_STYLE_WATERCAN, pItem->GetValue());
1458 EnableItem( SID_STYLE_WATERCAN, sal_True );
1460 else
1461 if(!bWaterDisabled)
1462 EnableItem(SID_STYLE_WATERCAN, sal_True);
1463 else
1464 EnableItem(SID_STYLE_WATERCAN, sal_False);
1466 // Ignore while in watercan mode statusupdates
1468 size_t nCount = pStyleFamilies->size();
1469 pBindings->EnterRegistrations();
1470 for(size_t n = 0; n < nCount; n++)
1472 SfxControllerItem *pCItem=pBoundItems[n];
1473 sal_Bool bChecked = pItem && pItem->GetValue();
1474 if( pCItem->IsBound() == bChecked )
1476 if( !bChecked )
1477 pCItem->ReBind();
1478 else
1479 pCItem->UnBind();
1482 pBindings->LeaveRegistrations();
1485 //-------------------------------------------------------------------------
1487 // Item with the status of a Family is copied and noted
1488 // (is updated when all states have also been updated.)
1489 // See also: <SfxBindings::AddDoneHdl(const Link &)>
1491 void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
1493 sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START;
1494 DELETEZ(pFamilyState[nIdx]);
1495 if ( pItem )
1496 pFamilyState[nIdx] = new SfxTemplateItem(*pItem);
1497 bUpdate = sal_True;
1499 // If used templates (how the hell you find this out??)
1500 bUpdateFamily = sal_True;
1503 //-------------------------------------------------------------------------
1504 // Notice from SfxBindings that the update is completed. Pushes out the update
1505 // of the display.
1507 void SfxCommonTemplateDialog_Impl::Update_Impl()
1509 sal_Bool bDocChanged=sal_False;
1510 SfxStyleSheetBasePool* pNewPool = NULL;
1511 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1512 SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
1513 if( pDocShell )
1514 pNewPool = pDocShell->GetStyleSheetPool();
1516 if ( pNewPool != pStyleSheetPool && pDocShell )
1518 SfxModule* pNewModule = pDocShell->GetModule();
1519 if( pNewModule && pNewModule != pModule )
1521 ClearResource();
1522 ReadResource();
1524 if ( pStyleSheetPool )
1526 EndListening(*pStyleSheetPool);
1527 pStyleSheetPool = 0;
1530 if ( pNewPool )
1532 StartListening(*pNewPool);
1533 pStyleSheetPool = pNewPool;
1534 bDocChanged=sal_True;
1538 if (bUpdateFamily)
1539 UpdateFamily_Impl();
1541 sal_uInt16 i;
1542 for(i = 0; i < MAX_FAMILIES; ++i)
1543 if(pFamilyState[i])
1544 break;
1545 if(i == MAX_FAMILIES || !pNewPool)
1546 // nothing is allowed
1547 return;
1549 SfxTemplateItem *pItem = 0;
1550 // current region not within the allowed region or default
1551 if(nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1] ) )
1553 CheckItem(nActFamily, sal_False);
1554 SfxTemplateItem **ppItem = pFamilyState;
1555 const size_t nFamilyCount = pStyleFamilies->size();
1556 size_t n;
1557 for( n = 0; n < nFamilyCount; n++ )
1558 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1559 ppItem+=StyleNrToInfoOffset(n);
1561 nAppFilter = (*ppItem)->GetValue();
1562 FamilySelect( StyleNrToInfoOffset(n)+1 );
1564 pItem = *ppItem;
1566 else if( bDocChanged )
1568 // other DocShell -> all new
1569 CheckItem( nActFamily, sal_True );
1570 nActFilter = static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pDocShell ) );
1571 if ( SFXSTYLEBIT_ALL == nActFilter )
1572 nActFilter = pDocShell->GetAutoStyleFilterIndex();
1574 nAppFilter = pItem->GetValue();
1575 if(!pTreeBox)
1577 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1579 else
1580 FillTreeBox();
1582 else
1584 // other filters for automatic
1585 CheckItem( nActFamily, sal_True );
1586 const SfxStyleFamilyItem *pStyleItem = GetFamilyItem_Impl();
1587 if ( 0 == pStyleItem->GetFilterList()[ nActFilter ]->nFlags
1588 && nAppFilter != pItem->GetValue())
1590 nAppFilter = pItem->GetValue();
1591 if(!pTreeBox)
1592 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1593 else
1594 FillTreeBox();
1596 else
1597 nAppFilter = pItem->GetValue();
1599 const String aStyle(pItem->GetStyleName());
1600 SelectStyle(aStyle);
1601 EnableDelete();
1602 EnableNew( bCanNew );
1605 //-------------------------------------------------------------------------
1607 IMPL_LINK( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, pTim )
1609 (void)pTim; // unused
1610 if(!bDontUpdate)
1612 bDontUpdate=sal_True;
1613 if(!pTreeBox)
1614 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1615 else
1617 FillTreeBox();
1618 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1619 if(pState)
1621 const String aStyle(pState->GetStyleName());
1622 SelectStyle(aStyle);
1623 EnableDelete();
1626 bDontUpdate=sal_False;
1627 DELETEZ(pTimer);
1629 else
1630 pTimer->Start();
1631 return 0;
1635 //-------------------------------------------------------------------------
1636 void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1638 // tap update
1639 if(rHint.Type() == TYPE(SfxSimpleHint))
1641 switch(((SfxSimpleHint&) rHint ).GetId())
1643 case SFX_HINT_UPDATEDONE:
1645 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1646 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
1647 if (
1648 bUpdate &&
1650 !IsCheckedItem(SID_STYLE_WATERCAN) ||
1651 (pDocShell && pDocShell->GetStyleSheetPool() != pStyleSheetPool)
1655 bUpdate = sal_False;
1656 Update_Impl();
1658 else if ( bUpdateFamily )
1660 UpdateFamily_Impl();
1663 if( pStyleSheetPool )
1665 String aStr = GetSelectedEntry();
1666 if( aStr.Len() && pStyleSheetPool )
1668 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1669 if( !pItem ) break;
1670 const SfxStyleFamily eFam = pItem->GetFamily();
1671 SfxStyleSheetBase *pStyle =
1672 pStyleSheetPool->Find(
1673 aStr, eFam, SFXSTYLEBIT_ALL );
1674 if( pStyle )
1676 bool bReadWrite = !(pStyle->GetMask() & SFXSTYLEBIT_READONLY);
1677 EnableEdit( bReadWrite );
1678 EnableHide( bReadWrite && !pStyle->IsUsed( ) && !pStyle->IsHidden( ) );
1679 EnableShow( bReadWrite && pStyle->IsHidden( ) );
1681 else
1683 EnableEdit(sal_False);
1684 EnableHide(sal_False);
1685 EnableShow(sal_False);
1689 break;
1692 // Necessary if switching between documents and in both documents
1693 // the same template is used. Do not immediately call Update_Impl,
1694 // for the case that one of the documents is an internal InPlaceObjekt!
1695 case SFX_HINT_DOCCHANGED:
1696 bUpdate = sal_True;
1697 break;
1698 case SFX_HINT_DYING:
1700 EndListening(*pStyleSheetPool);
1701 pStyleSheetPool=0;
1702 break;
1707 // Do not set timer when the stylesheet pool is in the box, because it is
1708 // possible that a new one is registered after the timer is up -
1709 // works bad in UpdateStyles_Impl ()!
1711 sal_uIntPtr nId = rHint.ISA(SfxSimpleHint) ? ( (SfxSimpleHint&)rHint ).GetId() : 0;
1713 if(!bDontUpdate && nId != SFX_HINT_DYING &&
1714 (rHint.Type() == TYPE(SfxStyleSheetPoolHint)||
1715 rHint.Type() == TYPE(SfxStyleSheetHint) ||
1716 rHint.Type() == TYPE( SfxStyleSheetHintExtended )))
1718 if(!pTimer)
1720 pTimer=new Timer;
1721 pTimer->SetTimeout(500);
1722 pTimer->SetTimeoutHdl(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut));
1724 pTimer->Start();
1730 //-------------------------------------------------------------------------
1731 // Other filters; can be switched by the users or as a result of new or
1732 // editing, if the current document has been assigned a different filter.
1733 void SfxCommonTemplateDialog_Impl::FilterSelect(
1734 sal_uInt16 nEntry, // Idx of the new Filters
1735 sal_Bool bForce ) // Force update, even if the new filter is
1736 // equal to the current
1738 if( nEntry != nActFilter || bForce )
1740 nActFilter = nEntry;
1741 SfxObjectShell *const pDocShell = SaveSelection();
1742 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
1743 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
1744 if ( pOldStyleSheetPool != pStyleSheetPool )
1746 if ( pOldStyleSheetPool )
1747 EndListening(*pOldStyleSheetPool);
1748 if ( pStyleSheetPool )
1749 StartListening(*pStyleSheetPool);
1752 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1756 //-------------------------------------------------------------------------
1758 // Internal: Perform functions through the Dispatcher
1759 sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl(
1760 sal_uInt16 nId, const String &rStr, const String& rRefStr, sal_uInt16 nFamily,
1761 sal_uInt16 nMask, sal_uInt16 *pIdx, const sal_uInt16* pModifier)
1763 SfxDispatcher &rDispatcher = *SFX_APP()->GetDispatcher_Impl();
1764 SfxStringItem aItem(nId, rStr);
1765 SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
1766 SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
1767 SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
1768 SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
1769 const SfxPoolItem* pItems[ 6 ];
1770 sal_uInt16 nCount = 0;
1771 if( rStr.Len() )
1772 pItems[ nCount++ ] = &aItem;
1773 pItems[ nCount++ ] = &aFamily;
1774 if( nMask )
1775 pItems[ nCount++ ] = &aMask;
1776 if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
1778 // Special solution for Numbering update in Writer
1779 const String aTemplName(GetSelectedEntry());
1780 aUpdName.SetValue(aTemplName);
1781 pItems[ nCount++ ] = &aUpdName;
1784 if ( rRefStr.Len() )
1785 pItems[ nCount++ ] = &aRefName;
1787 pItems[ nCount++ ] = 0;
1789 DeletionWatcher aDeleted(*this);
1790 sal_uInt16 nModi = pModifier ? *pModifier : 0;
1791 const SfxPoolItem* pItem = rDispatcher.Execute(
1792 nId, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
1793 pItems, nModi );
1795 // Dialog can be destroyed while in Execute() because started
1796 // subdialogs are not modal to it (#i97888#).
1797 if ( !pItem || aDeleted )
1798 return sal_False;
1800 if ( (nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId) && (aFmtLb.GetSelectionCount() <= 1) )
1802 SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem);
1803 OSL_ENSURE(pFilterItem, "SfxUINT16Item expected");
1804 sal_uInt16 nFilterFlags = pFilterItem->GetValue() & ~SFXSTYLEBIT_USERDEF;
1805 if(!nFilterFlags) // User Template?
1806 nFilterFlags = pFilterItem->GetValue();
1807 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
1808 const size_t nFilterCount = pFamilyItem->GetFilterList().size();
1810 for ( size_t i = 0; i < nFilterCount; ++i )
1812 const SfxFilterTupel *pTupel = pFamilyItem->GetFilterList()[ i ];
1814 if ( ( pTupel->nFlags & nFilterFlags ) == nFilterFlags && pIdx )
1815 *pIdx = i;
1819 return sal_True;
1822 //-------------------------------------------------------------------------
1824 // Handler der Listbox der Filter
1825 void SfxCommonTemplateDialog_Impl::EnableHierarchical(bool const bEnable)
1827 if (bEnable)
1829 if (!bHierarchical)
1831 // Turn on treeView
1832 bHierarchical=sal_True;
1833 m_bWantHierarchical = sal_True;
1834 SaveSelection(); // fdo#61429 store "hierarchical"
1835 const String aSelectEntry( GetSelectedEntry());
1836 aFmtLb.Hide();
1838 pTreeBox = new StyleTreeListBox_Impl(
1839 this, WB_HASBUTTONS | WB_HASLINES |
1840 WB_BORDER | WB_TABSTOP | WB_HASLINESATROOT |
1841 WB_HASBUTTONSATROOT | WB_HIDESELECTION | WB_QUICK_SEARCH );
1842 pTreeBox->SetFont( aFmtLb.GetFont() );
1844 pTreeBox->SetPosSizePixel(aFmtLb.GetPosPixel(), aFmtLb.GetSizePixel());
1845 pTreeBox->SetNodeDefaultImages();
1846 pTreeBox->SetSelectHdl(
1847 LINK(this, SfxCommonTemplateDialog_Impl, FmtSelectHdl));
1848 ((StyleTreeListBox_Impl*)pTreeBox)->
1849 SetDoubleClickHdl(
1850 LINK(this, SfxCommonTemplateDialog_Impl, ApplyHdl));
1851 ((StyleTreeListBox_Impl*)pTreeBox)->
1852 SetDropHdl(LINK(this, SfxCommonTemplateDialog_Impl, DropHdl));
1853 pTreeBox->SetIndent(10);
1854 FillTreeBox();
1855 SelectStyle(aSelectEntry);
1856 pTreeBox->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString());
1857 pTreeBox->Show();
1860 else
1862 DELETEZ(pTreeBox);
1863 aFmtLb.Show();
1864 // If bHierarchical, then the family can have changed
1865 // minus one since hierarchical is inserted at the start
1866 m_bWantHierarchical = sal_False; // before FilterSelect
1867 FilterSelect(aFilterLb.GetSelectEntryPos() - 1, bHierarchical );
1868 bHierarchical=sal_False;
1872 IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox )
1874 if (SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString() == pBox->GetSelectEntry())
1876 EnableHierarchical(true);
1878 else
1880 EnableHierarchical(false);
1883 return 0;
1886 //-------------------------------------------------------------------------
1888 // Select-Handler for the Toolbox
1889 void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry)
1891 if( nEntry != nActFamily )
1893 CheckItem( nActFamily, sal_False );
1894 nActFamily = nEntry;
1895 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
1896 SfxUInt16Item aItem( SID_STYLE_FAMILY, nEntry );
1897 pDispat->Execute( SID_STYLE_FAMILY, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
1898 pBindings->Invalidate( SID_STYLE_FAMILY );
1899 pBindings->Update( SID_STYLE_FAMILY );
1900 UpdateFamily_Impl();
1904 //-------------------------------------------------------------------------
1906 void SfxCommonTemplateDialog_Impl::ActionSelect(sal_uInt16 nEntry)
1908 String aEmpty;
1909 switch(nEntry)
1911 case SID_STYLE_WATERCAN:
1913 const sal_Bool bState = IsCheckedItem(nEntry);
1914 sal_Bool bCheck;
1915 SfxBoolItem aBool;
1916 // when a template is chosen.
1917 if(!bState && aFmtLb.GetSelectionCount())
1919 const String aTemplName(
1920 GetSelectedEntry());
1921 Execute_Impl(
1922 SID_STYLE_WATERCAN, aTemplName, aEmpty,
1923 (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
1924 bCheck = sal_True;
1926 else
1928 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
1929 bCheck = sal_False;
1931 CheckItem(nEntry, bCheck);
1932 aBool.SetValue(bCheck);
1933 SetWaterCanState(&aBool);
1934 break;
1936 case SID_STYLE_NEW_BY_EXAMPLE:
1938 if(pStyleSheetPool && nActFamily != 0xffff)
1940 const SfxStyleFamily eFam=GetFamilyItem_Impl()->GetFamily();
1941 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1942 sal_uInt16 nFilter;
1943 if( pItem && nActFilter != SFXSTYLEBIT_ALL )
1945 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
1946 if(!nFilter) // automatisch
1947 nFilter = nAppFilter;
1949 else
1950 nFilter=pStyleSheetPool->GetSearchMask();
1951 pStyleSheetPool->SetSearchMask( eFam, SFXSTYLEBIT_USERDEF );
1953 SfxNewStyleDlg *pDlg = new SfxNewStyleDlg(pWindow, *pStyleSheetPool);
1954 // why? : FloatingWindow must not be parent of a modal dialog
1955 if(RET_OK == pDlg->Execute())
1957 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1958 const String aTemplName(pDlg->GetName());
1959 Execute_Impl(SID_STYLE_NEW_BY_EXAMPLE,
1960 aTemplName, aEmpty,
1961 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(),
1962 nFilter);
1964 pStyleSheetPool->SetSearchMask( eFam, nFilter );
1965 delete pDlg;
1967 break;
1969 case SID_STYLE_UPDATE_BY_EXAMPLE:
1971 Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
1972 aEmpty, aEmpty,
1973 (sal_uInt16)GetFamilyItem_Impl()->GetFamily());
1974 break;
1976 case SID_TEMPLATE_LOAD:
1977 SFX_APP()->GetDispatcher_Impl()->Execute(nEntry);
1978 break;
1979 default: OSL_FAIL("not implemented"); break;
1983 //-------------------------------------------------------------------------
1985 static OUString getModuleIdentifier( const Reference< XModuleManager2 >& i_xModMgr, SfxObjectShell* i_pObjSh )
1987 OSL_ENSURE( i_xModMgr.is(), "getModuleIdentifier(): no XModuleManager" );
1988 OSL_ENSURE( i_pObjSh, "getModuleIdentifier(): no ObjectShell" );
1990 OUString sIdentifier;
1994 sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
1996 catch ( ::com::sun::star::frame::UnknownModuleException& )
1998 OSL_TRACE( "getModuleIdentifier(): unknown module" );
2000 catch ( Exception& )
2002 OSL_FAIL( "getModuleIdentifier(): exception of XModuleManager::identify()" );
2005 return sIdentifier;
2008 //-------------------------------------------------------------------------
2010 sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh )
2012 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
2013 sal_Int32 nFilter = -1;
2015 Sequence< PropertyValue > lProps;
2016 ::comphelper::SequenceAsHashMap aFactoryProps(
2017 xModuleManager->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
2018 sal_Int32 nDefault = -1;
2019 nFilter = aFactoryProps.getUnpackedValueOrDefault( "ooSetupFactoryStyleFilter", nDefault );
2021 m_bWantHierarchical =
2022 (nFilter & SFXSTYLEBIT_HIERARCHY) ? sal_True : sal_False;
2023 nFilter &= ~SFXSTYLEBIT_HIERARCHY; // clear it
2025 return nFilter;
2028 //-------------------------------------------------------------------------
2030 void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter )
2032 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
2033 Sequence< PropertyValue > lProps(1);
2034 lProps[0].Name = "ooSetupFactoryStyleFilter";
2035 lProps[0].Value = makeAny(
2036 i_nFilter | (m_bWantHierarchical ? SFXSTYLEBIT_HIERARCHY : 0));
2037 xModuleManager->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) );
2040 SfxObjectShell* SfxCommonTemplateDialog_Impl::SaveSelection()
2042 SfxViewFrame *const pViewFrame(pBindings->GetDispatcher_Impl()->GetFrame());
2043 SfxObjectShell *const pDocShell(pViewFrame->GetObjectShell());
2044 if (pDocShell)
2046 pDocShell->SetAutoStyleFilterIndex(nActFilter);
2047 SaveFactoryStyleFilter( pDocShell, nActFilter );
2049 return pDocShell;
2052 //-------------------------------------------------------------------------
2054 IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox )
2056 bDontUpdate=sal_True;
2057 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
2058 const SfxStyleFamily eFam = pItem->GetFamily();
2059 long ret= pStyleSheetPool->SetParent(eFam,pBox->GetStyle(), pBox->GetParent())? 1L: 0L;
2060 bDontUpdate=sal_False;
2061 return ret;
2064 //-------------------------------------------------------------------------
2066 // Handler for the New-Buttons
2067 void SfxCommonTemplateDialog_Impl::NewHdl(void *)
2069 String aEmpty;
2070 if ( nActFamily != 0xffff && (aFmtLb.GetSelectionCount() <= 1))
2072 Window* pTmp;
2073 pTmp = Application::GetDefDialogParent();
2074 if ( ISA(SfxTemplateDialog_Impl) )
2075 Application::SetDefDialogParent( pWindow->GetParent() );
2076 else
2077 Application::SetDefDialogParent( pWindow );
2079 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
2080 const SfxStyleFamily eFam=pItem->GetFamily();
2081 sal_uInt16 nMask;
2082 if( pItem && nActFilter != SFXSTYLEBIT_ALL )
2084 nMask = pItem->GetFilterList()[ nActFilter ]->nFlags;
2085 if(!nMask) // automatic
2086 nMask = nAppFilter;
2088 else
2089 nMask=pStyleSheetPool->GetSearchMask();
2091 pStyleSheetPool->SetSearchMask(eFam,nMask);
2093 Execute_Impl(SID_STYLE_NEW,
2094 aEmpty, GetSelectedEntry(),
2095 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2096 nMask);
2098 Application::SetDefDialogParent( pTmp );
2102 //-------------------------------------------------------------------------
2104 // Handler for the edit-Buttons
2105 void SfxCommonTemplateDialog_Impl::EditHdl(void *)
2107 if(IsInitialized() && HasSelectedStyle())
2109 sal_uInt16 nFilter = nActFilter;
2110 String aTemplName(GetSelectedEntry());
2111 GetSelectedStyle(); // -Wall required??
2112 Window* pTmp;
2113 //DefModalDialogParent set for modality of the following dialogs
2114 pTmp = Application::GetDefDialogParent();
2115 if ( ISA(SfxTemplateDialog_Impl) )
2116 Application::SetDefDialogParent( pWindow->GetParent() );
2117 else
2118 Application::SetDefDialogParent( pWindow );
2119 if ( Execute_Impl( SID_STYLE_EDIT, aTemplName, String(),
2120 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(), 0, &nFilter ) )
2123 Application::SetDefDialogParent( pTmp );
2127 //-------------------------------------------------------------------------
2129 // Handler for the Delete-Buttons
2130 void SfxCommonTemplateDialog_Impl::DeleteHdl(void *)
2132 if ( IsInitialized() && HasSelectedStyle() )
2134 bool bUsedStyle = 0; // one of the selected styles are used in the document?
2135 String aRet;
2137 std::vector<SvTreeListEntry*> aList;
2138 SvTreeListEntry* pEntry = aFmtLb.FirstSelected();
2139 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
2141 String aMsg = SfxResId(STR_DELETE_STYLE_USED).toString();
2142 aMsg += SfxResId(STR_DELETE_STYLE).toString();
2144 while (pEntry)
2146 aList.push_back( pEntry );
2147 // check the style is used or not
2148 if (pTreeBox)
2149 aRet = pTreeBox->GetEntryText( pEntry );
2150 else
2151 aRet = aFmtLb.GetEntryText( pEntry );
2153 const String aTemplName( aRet );
2155 SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
2157 if ( pStyle->IsUsed() ) // pStyle is in use in the document?
2159 if (bUsedStyle) // add a separator for the second and later styles
2160 aMsg += ", ";
2161 aMsg += aTemplName;
2162 bUsedStyle = 1;
2165 pEntry = aFmtLb.NextSelected( pEntry );
2168 bool aApproved = 0;
2170 // we only want to show the dialog once and if we want to delete a style in use (UX-advice)
2171 if ( bUsedStyle )
2173 #if defined UNX
2174 QueryBox aBox( SFX_APP()->GetTopWindow(), WB_YES_NO | WB_DEF_NO, aMsg );
2175 #else
2176 QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , aMsg );
2177 #endif
2178 aApproved = aBox.Execute() == RET_YES;
2181 // if there are no used styles selected or the user approved the changes
2182 if ( !bUsedStyle || aApproved )
2184 std::vector<SvTreeListEntry*>::const_iterator it = aList.begin(), itEnd = aList.end();
2186 for (; it != itEnd; ++it)
2188 if (pTreeBox)
2189 aRet = pTreeBox->GetEntryText( *it );
2190 else
2191 aRet = aFmtLb.GetEntryText( *it );
2193 const String aTemplName( aRet );
2194 PrepareDeleteAction();
2195 bDontUpdate = sal_True; // To prevent the Treelistbox to shut down while deleting
2196 Execute_Impl( SID_STYLE_DELETE, aTemplName,
2197 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2199 if ( pTreeBox )
2201 pTreeBox->RemoveParentKeepChildren( *it );
2202 bDontUpdate = sal_False;
2205 bDontUpdate = sal_False; //if everything is deleted set bDontUpdate back to false
2206 UpdateStyles_Impl(UPDATE_FAMILY_LIST); //and force-update the list
2211 void SfxCommonTemplateDialog_Impl::HideHdl(void *)
2213 if ( IsInitialized() && HasSelectedStyle() )
2215 const String aTemplName( GetSelectedEntry() );
2216 SfxStyleSheetBase* pStyle = GetSelectedStyle();
2217 if ( pStyle )
2219 Execute_Impl( SID_STYLE_HIDE, aTemplName,
2220 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2225 void SfxCommonTemplateDialog_Impl::ShowHdl(void *)
2227 if ( IsInitialized() && HasSelectedStyle() )
2229 const String aTemplName( GetSelectedEntry() );
2230 SfxStyleSheetBase* pStyle = GetSelectedStyle();
2231 if ( pStyle )
2233 Execute_Impl( SID_STYLE_SHOW, aTemplName,
2234 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2239 //-------------------------------------------------------------------------
2241 void SfxCommonTemplateDialog_Impl::EnableDelete()
2243 if(IsInitialized() && HasSelectedStyle())
2245 OSL_ENSURE(pStyleSheetPool, "No StyleSheetPool");
2246 const String aTemplName(GetSelectedEntry());
2247 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
2248 const SfxStyleFamily eFam = pItem->GetFamily();
2249 sal_uInt16 nFilter = 0;
2250 if(pItem->GetFilterList().size() > nActFilter)
2251 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
2252 if(!nFilter) // automatic
2253 nFilter = nAppFilter;
2254 const SfxStyleSheetBase *pStyle =
2255 pStyleSheetPool->Find(aTemplName,eFam, pTreeBox? SFXSTYLEBIT_ALL : nFilter);
2257 OSL_ENSURE(pStyle, "Style not found");
2258 if(pStyle && pStyle->IsUserDefined())
2260 EnableDel(sal_True);
2262 else
2264 EnableDel(sal_False);
2267 else
2269 EnableDel(sal_False);
2273 //-------------------------------------------------------------------------
2274 // After selecting a focused item if possible again on the app window
2275 void SfxCommonTemplateDialog_Impl::ResetFocus()
2277 if(ISA(SfxTemplateDialog_Impl))
2279 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
2280 SfxViewShell *pVu = pViewFrame->GetViewShell();
2281 Window *pAppWin = pVu ? pVu->GetWindow(): 0;
2282 if(pAppWin)
2283 pAppWin->GrabFocus();
2287 //-------------------------------------------------------------------------
2289 // Doppelclick on a style sheet in the ListBox is applied.
2290 IMPL_LINK( SfxCommonTemplateDialog_Impl, ApplyHdl, Control *, pControl )
2292 (void)pControl; //unused
2293 // only if that region is allowed
2294 if ( IsInitialized() && 0 != pFamilyState[nActFamily-1] &&
2295 GetSelectedEntry().Len() )
2297 sal_uInt16 nModifier = aFmtLb.GetModifier();
2298 Execute_Impl(SID_STYLE_APPLY,
2299 GetSelectedEntry(), String(),
2300 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2301 0, 0, &nModifier );
2303 ResetFocus();
2304 return 0;
2307 //-------------------------------------------------------------------------
2309 // Selection of a template during the Watercan-Status
2310 IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox )
2312 // Trigger Help PI, if this is permitted of call handlers and field
2313 if( !pListBox || pListBox->IsSelected( pListBox->GetHdlEntry() ) )
2315 // Only when the watercan is on
2316 if ( IsInitialized() &&
2317 IsCheckedItem(SID_STYLE_WATERCAN) &&
2318 // only if that region is allowed
2319 0 != pFamilyState[nActFamily-1] && (aFmtLb.GetSelectionCount() <= 1) )
2321 String aEmpty;
2322 Execute_Impl(SID_STYLE_WATERCAN,
2323 aEmpty, aEmpty, 0);
2324 Execute_Impl(SID_STYLE_WATERCAN,
2325 GetSelectedEntry(), aEmpty,
2326 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily());
2328 EnableItem(SID_STYLE_WATERCAN, !bWaterDisabled);
2329 EnableDelete();
2331 if( pListBox )
2332 SelectStyle( pListBox->GetEntryText( pListBox->GetHdlEntry() ));
2334 return 0;
2337 //-------------------------------------------------------------------------
2339 IMPL_LINK( SfxCommonTemplateDialog_Impl, MenuSelectHdl, Menu *, pMenu )
2341 if( pMenu )
2343 nLastItemId = pMenu->GetCurItemId();
2344 Application::PostUserEvent(
2345 LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ), 0 );
2346 return sal_True;
2349 switch(nLastItemId) {
2350 case ID_NEW: NewHdl(0); break;
2351 case ID_EDIT: EditHdl(0); break;
2352 case ID_DELETE: DeleteHdl(0); break;
2353 case ID_HIDE: HideHdl(0); break;
2354 case ID_SHOW: ShowHdl(0); break;
2355 default: return sal_False;
2357 return sal_True;
2360 // -----------------------------------------------------------------------
2362 void SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl( const Point& rPos, Window* pWin )
2364 // Bug# 94152: This part should never be called, because before this happens, the TreeListBox should captured this!
2365 OSL_FAIL( "+SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl(): How could this happen? Please infirm developer ASAP!" );
2367 PopupMenu* pMenu = CreateContextMenu();
2368 pMenu->Execute( pWin, rPos );
2369 delete pMenu;
2372 // -----------------------------------------------------------------------
2374 SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const
2376 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
2377 if( !pFamilyItem || nActFamily == 0xffff )
2378 return SFX_STYLE_FAMILY_PARA;
2379 else
2380 return pFamilyItem->GetFamily();
2383 // -----------------------------------------------------------------------
2385 void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, sal_Bool bEnable)
2387 if( nId == SID_STYLE_NEW_BY_EXAMPLE )
2389 bNewByExampleDisabled = (aFmtLb.GetSelectionCount() <=1 ? !bEnable : sal_True);
2391 else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
2392 bUpdateByExampleDisabled = (aFmtLb.GetSelectionCount() <=1 ? !bEnable : sal_True);
2394 EnableItem(nId, bEnable);
2397 void SfxCommonTemplateDialog_Impl::PrepareDeleteAction()
2401 // -----------------------------------------------------------------------
2403 PopupMenu* SfxCommonTemplateDialog_Impl::CreateContextMenu( void )
2405 if ( bBindingUpdate )
2407 pBindings->Invalidate( SID_STYLE_NEW, sal_True, sal_False );
2408 pBindings->Update( SID_STYLE_NEW );
2409 bBindingUpdate = sal_False;
2411 PopupMenu* pMenu = new PopupMenu( SfxResId( MN_CONTEXT_TEMPLDLG ) );
2412 pMenu->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ) );
2413 pMenu->EnableItem( ID_EDIT, bCanEdit );
2414 pMenu->EnableItem( ID_DELETE, bCanDel );
2415 pMenu->EnableItem( ID_NEW, bCanNew );
2416 pMenu->EnableItem( ID_HIDE, bCanHide );
2417 pMenu->EnableItem( ID_SHOW, bCanShow );
2419 return pMenu;
2422 // ------------------------------------------------------------------------
2425 SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(
2426 SfxBindings* pB, SfxTemplateDialog* pDlgWindow ) :
2428 SfxCommonTemplateDialog_Impl( pB, pDlgWindow, true ),
2430 m_pFloat ( pDlgWindow ),
2431 m_bZoomIn ( sal_False ),
2432 m_aActionTbL ( pDlgWindow, this ),
2433 m_aActionTbR ( pDlgWindow, SfxResId( TB_ACTION ) )
2436 pDlgWindow->FreeResource();
2437 Initialize();
2440 SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(
2441 SfxBindings* pB, SfxTemplatePanelControl* pDlgWindow )
2442 : SfxCommonTemplateDialog_Impl( pB, pDlgWindow, true ),
2443 m_pFloat ( pDlgWindow ),
2444 m_bZoomIn ( sal_False ),
2445 m_aActionTbL ( pDlgWindow, this ),
2446 m_aActionTbR ( pDlgWindow, SfxResId( TB_ACTION ) )
2448 pDlgWindow->FreeResource();
2449 Initialize();
2452 void SfxTemplateDialog_Impl::Initialize (void)
2454 SfxCommonTemplateDialog_Impl::Initialize();
2456 m_aActionTbL.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
2457 m_aActionTbR.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
2458 m_aActionTbR.SetDropdownClickHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRClick));
2459 m_aActionTbL.Show();
2460 m_aActionTbR.Show();
2461 Font aFont=aFilterLb.GetFont();
2462 aFont.SetWeight( WEIGHT_NORMAL );
2463 aFilterLb.SetFont( aFont );
2464 m_aActionTbL.SetHelpId( HID_TEMPLDLG_TOOLBOX_LEFT );
2467 // ------------------------------------------------------------------------
2469 void SfxTemplateDialog_Impl::EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnable )
2471 m_aActionTbL.EnableItem( nId, bEnable );
2474 //-------------------------------------------------------------------------
2475 // Insert element into dropdown filter "Frame Styles", "List Styles", etc.
2477 void SfxTemplateDialog_Impl::InsertFamilyItem(sal_uInt16 nId,const SfxStyleFamilyItem *pItem)
2479 OString sHelpId;
2480 switch( (sal_uInt16) pItem->GetFamily() )
2482 case SFX_STYLE_FAMILY_CHAR: sHelpId = ".uno:CharStyle"; break;
2483 case SFX_STYLE_FAMILY_PARA: sHelpId = ".uno:ParaStyle"; break;
2484 case SFX_STYLE_FAMILY_FRAME: sHelpId = ".uno:FrameStyle"; break;
2485 case SFX_STYLE_FAMILY_PAGE: sHelpId = ".uno:PageStyle"; break;
2486 case SFX_STYLE_FAMILY_PSEUDO: sHelpId = ".uno:ListStyle"; break;
2487 default: OSL_FAIL("unknown StyleFamily"); break;
2489 m_aActionTbL.InsertItem( nId, pItem->GetImage(), pItem->GetText(), 0, 0);
2490 m_aActionTbL.SetHelpId( nId, sHelpId );
2493 // ------------------------------------------------------------------------
2495 void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2497 m_aActionTbR.HideItem(SID_STYLE_UPDATE_BY_EXAMPLE);
2498 m_aActionTbR.SetItemBits( SID_STYLE_NEW_BY_EXAMPLE,
2499 TIB_DROPDOWNONLY|m_aActionTbR.GetItemBits( SID_STYLE_NEW_BY_EXAMPLE ));
2502 // ------------------------------------------------------------------------
2503 void SfxTemplateDialog_Impl::updateFamilyImages()
2505 if ( !m_pStyleFamiliesId )
2506 // we do not have a resource id to load the new images from
2507 return;
2509 // let the families collection update the images
2510 pStyleFamilies->updateImages( *m_pStyleFamiliesId );
2512 // and set the new images on our toolbox
2513 size_t nLoop = pStyleFamilies->size();
2514 for( ; nLoop--; )
2516 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nLoop );
2517 sal_uInt16 nId = SfxFamilyIdToNId( pItem->GetFamily() );
2518 m_aActionTbL.SetItemImage( nId, pItem->GetImage() );
2522 // ------------------------------------------------------------------------
2523 void SfxTemplateDialog_Impl::updateNonFamilyImages()
2525 m_aActionTbR.SetImageList( ImageList( SfxResId( DLG_STYLE_DESIGNER ) ) );
2528 // ------------------------------------------------------------------------
2530 void SfxTemplateDialog_Impl::ClearFamilyList()
2532 m_aActionTbL.Clear();
2535 //-------------------------------------------------------------------------
2537 void SfxCommonTemplateDialog_Impl::InvalidateBindings()
2539 pBindings->Invalidate(SID_STYLE_NEW_BY_EXAMPLE, sal_True, sal_False);
2540 pBindings->Update( SID_STYLE_NEW_BY_EXAMPLE );
2541 pBindings->Invalidate(SID_STYLE_UPDATE_BY_EXAMPLE, sal_True, sal_False);
2542 pBindings->Update( SID_STYLE_UPDATE_BY_EXAMPLE );
2543 pBindings->Invalidate( SID_STYLE_WATERCAN, sal_True, sal_False);
2544 pBindings->Update( SID_STYLE_WATERCAN );
2545 pBindings->Invalidate( SID_STYLE_NEW, sal_True, sal_False );
2546 pBindings->Update( SID_STYLE_NEW );
2547 pBindings->Invalidate( SID_STYLE_DRAGHIERARCHIE, sal_True, sal_False );
2548 pBindings->Update( SID_STYLE_DRAGHIERARCHIE );
2551 //-------------------------------------------------------------------------
2553 SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
2557 //-------------------------------------------------------------------------
2559 void SfxTemplateDialog_Impl::LoadedFamilies()
2561 updateFamilyImages();
2562 Resize();
2565 //-------------------------------------------------------------------------
2567 // Overloaded Resize-Handler ( StarView )
2568 // The size of the Listboxen is adjusted
2569 void SfxTemplateDialog_Impl::Resize()
2571 SfxDockingWindow* pDockingWindow = dynamic_cast<SfxDockingWindow*>(m_pFloat);
2572 FloatingWindow *pF = pDockingWindow!=NULL ? pDockingWindow->GetFloatingWindow() : NULL;
2573 if ( pF )
2575 m_bZoomIn = pF->IsRollUp();
2576 if ( m_bZoomIn )
2577 return;
2580 if (m_pFloat == NULL)
2581 return;
2582 Size aDlgSize=m_pFloat->PixelToLogic(m_pFloat->GetOutputSizePixel());
2583 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
2584 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
2585 Size aMinSize = GetMinOutputSizePixel();
2587 long nListHeight = m_pFloat->PixelToLogic( aFilterLb.GetSizePixel() ).Height();
2588 long nWidth = aDlgSize.Width()- 2 * SFX_TEMPLDLG_HFRAME;
2590 m_aActionTbL.SetPosSizePixel(m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,SFX_TEMPLDLG_VTOPFRAME)),
2591 m_pFloat->LogicToPixel(aSizeATL));
2593 // only change the position of the right toolbox, when the window is wide
2594 // enough
2595 Point aPosATR(aDlgSize.Width()-SFX_TEMPLDLG_HFRAME-aSizeATR.Width(),SFX_TEMPLDLG_VTOPFRAME);
2596 if(aDlgSize.Width() >= aMinSize.Width())
2597 m_aActionTbR.SetPosPixel(m_pFloat->LogicToPixel(aPosATR));
2598 else
2599 m_aActionTbR.SetPosPixel( m_pFloat->LogicToPixel(
2600 Point( SFX_TEMPLDLG_HFRAME + aSizeATL.Width() + SFX_TEMPLDLG_MIDHSPACE,
2601 SFX_TEMPLDLG_VTOPFRAME ) ) );
2603 m_aActionTbR.SetSizePixel(m_pFloat->LogicToPixel(aSizeATR));
2605 Point aFilterPos(
2606 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,
2607 aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-nListHeight)) );
2609 Size aFilterSize(
2610 m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) );
2612 Point aFmtPos(
2613 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME +
2614 SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) );
2615 Size aFmtSize(
2616 m_pFloat->LogicToPixel(Size(nWidth,
2617 aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME -
2618 SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE-
2619 nListHeight-aSizeATL.Height())) );
2621 // only change the position of the listbox, when the window is high enough
2622 if(aDlgSize.Height() >= aMinSize.Height())
2624 aFilterLb.SetPosPixel(aFilterPos);
2625 aFmtLb.SetPosPixel( aFmtPos );
2626 if(pTreeBox)
2627 pTreeBox->SetPosPixel(aFmtPos);
2629 else
2630 aFmtSize.Height() += aFilterSize.Height();
2632 aFilterLb.SetSizePixel(aFilterSize);
2633 aFmtLb.SetSizePixel( aFmtSize );
2634 if(pTreeBox)
2635 pTreeBox->SetSizePixel(aFmtSize);
2638 // -----------------------------------------------------------------------
2641 Size SfxTemplateDialog_Impl::GetMinOutputSizePixel()
2643 if (m_pFloat != NULL)
2645 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
2646 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
2647 Size aMinSize=Size(
2648 aSizeATL.Width()+aSizeATR.Width()+
2649 2*SFX_TEMPLDLG_HFRAME + SFX_TEMPLDLG_MIDHSPACE,
2650 4*aSizeATL.Height()+2*SFX_TEMPLDLG_MIDVSPACE);
2651 return aMinSize;
2653 else
2654 return Size(0,0);
2657 //-------------------------------------------------------------------------
2659 void SfxTemplateDialog_Impl::Command( const CommandEvent& rCEvt )
2661 if (m_pFloat != NULL)
2663 if(COMMAND_CONTEXTMENU == rCEvt.GetCommand())
2664 ExecuteContextMenu_Impl( rCEvt.GetMousePosPixel(), m_pFloat );
2665 else
2666 m_pFloat->Command(rCEvt);
2670 //-------------------------------------------------------------------------
2672 void SfxTemplateDialog_Impl::EnableItem(sal_uInt16 nMesId, sal_Bool bCheck)
2674 String aEmpty;
2675 switch(nMesId)
2677 case SID_STYLE_WATERCAN :
2678 if(!bCheck && IsCheckedItem(SID_STYLE_WATERCAN))
2679 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
2680 case SID_STYLE_NEW_BY_EXAMPLE:
2681 case SID_STYLE_UPDATE_BY_EXAMPLE:
2682 m_aActionTbR.EnableItem(nMesId,bCheck);
2683 break;
2687 //-------------------------------------------------------------------------
2689 void SfxTemplateDialog_Impl::CheckItem(sal_uInt16 nMesId, sal_Bool bCheck)
2691 switch(nMesId)
2693 case SID_STYLE_WATERCAN :
2694 bIsWater=bCheck;
2695 m_aActionTbR.CheckItem(SID_STYLE_WATERCAN,bCheck);
2696 break;
2697 default:
2698 m_aActionTbL.CheckItem(nMesId,bCheck); break;
2702 //-------------------------------------------------------------------------
2704 sal_Bool SfxTemplateDialog_Impl::IsCheckedItem(sal_uInt16 nMesId)
2706 switch(nMesId)
2708 case SID_STYLE_WATERCAN :
2709 return m_aActionTbR.GetItemState(SID_STYLE_WATERCAN)==STATE_CHECK;
2710 default:
2711 return m_aActionTbL.GetItemState(nMesId)==STATE_CHECK;
2715 //-------------------------------------------------------------------------
2717 IMPL_LINK_INLINE_START( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
2719 const sal_uInt16 nEntry = pBox->GetCurItemId();
2720 FamilySelect(nEntry);
2721 return 0;
2723 IMPL_LINK_INLINE_END( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
2725 //-------------------------------------------------------------------------
2726 static OUString lcl_GetLabel(uno::Any& rAny)
2728 OUString sRet;
2729 uno::Sequence< beans::PropertyValue >aPropSeq;
2730 if ( rAny >>= aPropSeq )
2732 for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
2734 if ( aPropSeq[i].Name == "Label" )
2736 aPropSeq[i].Value >>= sRet;
2737 break;
2741 return sRet;
2743 //-------------------------------------------------------------------------
2745 IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRSelect, ToolBox *, pBox )
2747 const sal_uInt16 nEntry = pBox->GetCurItemId();
2748 if(nEntry != SID_STYLE_NEW_BY_EXAMPLE ||
2749 TIB_DROPDOWN != (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
2750 ActionSelect(nEntry);
2751 return 0;
2753 //-------------------------------------------------------------------------
2754 IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRClick, ToolBox *, pBox )
2756 const sal_uInt16 nEntry = pBox->GetCurItemId();
2757 if(nEntry == SID_STYLE_NEW_BY_EXAMPLE &&
2758 TIB_DROPDOWN == (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
2760 //create a popup menu in Writer
2761 boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
2762 uno::Reference< container::XNameAccess > xNameAccess(
2763 frame::UICommandDescription::create(
2764 ::comphelper::getProcessComponentContext()) );
2765 uno::Reference< container::XNameAccess > xUICommands;
2766 OUString sTextDoc("com.sun.star.text.TextDocument");
2767 if(xNameAccess->hasByName(sTextDoc))
2769 uno::Any a = xNameAccess->getByName( sTextDoc );
2770 a >>= xUICommands;
2772 if(!xUICommands.is())
2773 return 0;
2776 uno::Sequence< beans::PropertyValue > aPropSeq;
2777 uno::Any aCommand = xUICommands->getByName(OUString(".uno:StyleNewByExample"));
2778 OUString sLabel = lcl_GetLabel( aCommand );
2779 pMenu->InsertItem( SID_STYLE_NEW_BY_EXAMPLE, sLabel );
2780 pMenu->SetHelpId(SID_STYLE_NEW_BY_EXAMPLE, HID_TEMPLDLG_NEWBYEXAMPLE);
2782 aCommand = xUICommands->getByName(OUString(".uno:StyleUpdateByExample"));
2783 sLabel = lcl_GetLabel( aCommand );
2785 pMenu->InsertItem( SID_STYLE_UPDATE_BY_EXAMPLE, sLabel );
2786 pMenu->SetHelpId(SID_STYLE_UPDATE_BY_EXAMPLE, HID_TEMPLDLG_UPDATEBYEXAMPLE);
2788 aCommand = xUICommands->getByName(OUString(".uno:LoadStyles"));
2789 sLabel = lcl_GetLabel( aCommand );
2790 pMenu->InsertItem( SID_TEMPLATE_LOAD, sLabel );
2791 pMenu->SetHelpId(SID_TEMPLATE_LOAD, ".uno:LoadStyles");
2793 pMenu->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, MenuSelectHdl));
2794 pMenu->Execute( pBox,
2795 pBox->GetItemRect(nEntry),
2796 POPUPMENU_EXECUTE_DOWN );
2797 pBox->EndSelection();
2799 catch(uno::Exception&)
2802 pBox->Invalidate();
2804 return 0;
2806 //-------------------------------------------------------------------------
2807 IMPL_LINK( SfxTemplateDialog_Impl, MenuSelectHdl, Menu*, pMenu)
2809 sal_uInt16 nMenuId = pMenu->GetCurItemId();
2810 ActionSelect(nMenuId);
2811 return 0;
2813 //-------------------------------------------------------------------------
2816 void SfxCommonTemplateDialog_Impl::SetFamily( sal_uInt16 nId )
2818 if ( nId != nActFamily )
2820 if ( nActFamily != 0xFFFF )
2821 CheckItem( nActFamily, sal_False );
2822 nActFamily = nId;
2823 if ( nId != 0xFFFF )
2824 bUpdateFamily = sal_True;
2828 void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl()
2830 bUpdateFamily = sal_False;
2832 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
2833 SfxViewFrame *pViewFrame = pDispat->GetFrame();
2834 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
2836 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
2837 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
2838 if ( pOldStyleSheetPool != pStyleSheetPool )
2840 if ( pOldStyleSheetPool )
2841 EndListening(*pOldStyleSheetPool);
2842 if ( pStyleSheetPool )
2843 StartListening(*pStyleSheetPool);
2846 bWaterDisabled = sal_False;
2847 bCanNew = (aFmtLb.GetSelectionCount() <=1 ? sal_True : sal_False);
2848 bTreeDrag = sal_True;
2849 bUpdateByExampleDisabled = sal_False;
2851 if ( pStyleSheetPool )
2853 if(!pTreeBox)
2854 UpdateStyles_Impl(UPDATE_FAMILY | UPDATE_FAMILY_LIST);
2855 else
2857 UpdateStyles_Impl(UPDATE_FAMILY);
2858 FillTreeBox();
2862 InvalidateBindings();
2864 if ( IsCheckedItem( SID_STYLE_WATERCAN ) &&
2865 // only if that area is allowed
2866 0 != pFamilyState[ nActFamily - 1 ] )
2867 Execute_Impl( SID_STYLE_APPLY, GetSelectedEntry(),
2868 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2870 void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2872 //does nothing
2875 void SfxTemplateDialog::StateChanged( StateChangedType nStateChange )
2877 if ( nStateChange == STATE_CHANGE_INITSHOW )
2879 SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
2880 Window* pEditWin = pFrame->GetViewShell()->GetWindow();
2882 Size aSize = pEditWin->GetSizePixel();
2883 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
2884 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
2885 Size aWinSize = GetSizePixel();
2886 aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
2887 aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
2888 SetFloatingPos( aPoint );
2891 SfxDockingWindow::StateChanged( nStateChange );
2894 DropToolBox_Impl::DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog) :
2895 ToolBox(pParent),
2896 DropTargetHelper(this),
2897 rParent(*pTemplateDialog)
2901 DropToolBox_Impl::~DropToolBox_Impl()
2905 sal_Int8 DropToolBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
2907 sal_Int8 nReturn = DND_ACTION_NONE;
2908 sal_uInt16 nItemId = GetItemId( rEvt.maPosPixel );
2909 if(USHRT_MAX != nItemId && !IsItemChecked( nItemId ))
2911 SetCurItemId(nItemId);
2912 GetSelectHdl().Call(this);
2914 // special case: page styles are allowed to create new styles by example
2915 // but not allowed to be created by drag and drop
2916 if ( nItemId != SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE )&&
2917 IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
2918 !rParent.bNewByExampleDisabled )
2920 nReturn = DND_ACTION_COPY;
2922 return nReturn;
2925 sal_Int8 DropToolBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
2927 return rParent.aFmtLb.ExecuteDrop(rEvt);
2930 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */