Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / templdlg.cxx
blob3a2a8ecd846d44a7628b7ae12495c52d5a28764c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <boost/noncopyable.hpp>
30 #include <boost/scoped_ptr.hpp>
32 #include <vcl/menu.hxx>
33 #include <svl/intitem.hxx>
34 #include <svl/stritem.hxx>
35 #include <svl/style.hxx>
36 #include <svl/svstdarr.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include <comphelper/sequenceashashmap.hxx>
39 #include <unotools/intlwrapper.hxx>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/frame/XModuleManager.hpp>
45 #include "sfx2/sfxhelp.hxx"
46 #include <sfx2/app.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/bindings.hxx>
49 #include <sfx2/templdlg.hxx>
50 #include "templdgi.hxx"
51 #include "tplcitem.hxx"
52 #include "sfxtypes.hxx"
53 #include <sfx2/styfitem.hxx>
54 #include <sfx2/objsh.hxx>
55 #include <sfx2/viewsh.hxx>
56 #include <sfx2/newstyle.hxx>
57 #include "sfx2/tplpitem.hxx"
58 #include "sfx2/sfxresid.hxx"
60 #include "templdlg.hrc"
61 #include <sfx2/sfx.hrc>
62 #include "dialog.hrc"
63 #include "arrdecl.hxx"
64 #include "fltfnc.hxx"
65 #include <sfx2/docfilt.hxx>
66 #include <sfx2/docfac.hxx>
67 #include "docvor.hxx"
68 #include <sfx2/doctempl.hxx>
69 #include <sfx2/module.hxx>
70 #include "sfx2/imgmgr.hxx"
71 #include "helpid.hrc"
72 #include "appdata.hxx"
73 #include <sfx2/viewfrm.hxx>
75 #include <comphelper/configurationhelper.hxx>
76 #include <comphelper/string.hxx>
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::beans;
80 using namespace ::com::sun::star::frame;
81 using namespace ::com::sun::star::uno;
83 //=========================================================================
84 // Window is now created dynamically. So here margins, etc.
86 #define SFX_TEMPLDLG_HFRAME 3
87 #define SFX_TEMPLDLG_VTOPFRAME 3
89 #define SFX_TEMPLDLG_VBOTFRAME 3
90 #define SFX_TEMPLDLG_MIDHSPACE 3
91 #define SFX_TEMPLDLG_MIDVSPACE 3
92 #define SFX_TEMPLDLG_FILTERHEIGHT 100
94 static sal_uInt16 nLastItemId = USHRT_MAX;
96 // filter box has maximum 12 entries visible
97 #define MAX_FILTER_ENTRIES 12
99 // Special constant to save hierarchical mode
100 // We've to use this hack since this is not the
101 // index in the filter listbox that is saved but the
102 // index in the filters list and hierarchical is not
103 // in it
104 #define HIERARCHICAL_FILTER_INDEX 0xfffe // 0xffff is reserved
106 //=========================================================================
108 TYPEINIT0(SfxCommonTemplateDialog_Impl);
109 TYPEINIT1(SfxTemplateDialog_Impl,SfxCommonTemplateDialog_Impl);
110 TYPEINIT1(SfxTemplateCatalog_Impl,SfxCommonTemplateDialog_Impl);
112 SFX_IMPL_DOCKINGWINDOW(SfxTemplateDialogWrapper, SID_STYLE_DESIGNER)
114 //-------------------------------------------------------------------------
116 class SfxCommonTemplateDialog_Impl::DeletionWatcher : private boost::noncopyable
118 typedef void (DeletionWatcher::* bool_type)();
120 public:
121 explicit DeletionWatcher(SfxCommonTemplateDialog_Impl& rDialog)
122 : m_pDialog(&rDialog)
124 m_pDialog->impl_setDeletionWatcher(this);
127 ~DeletionWatcher()
129 if (m_pDialog)
130 m_pDialog->impl_setDeletionWatcher(0);
133 // Signal that the dialog was deleted
134 void signal()
136 m_pDialog = 0;
139 // Return true if the dialog was deleted
140 operator bool_type() const
142 return m_pDialog ? 0 : &DeletionWatcher::signal;
145 private:
146 SfxCommonTemplateDialog_Impl* m_pDialog;
149 // Re-direct functions
151 SfxTemplateDialog::SfxTemplateDialog
153 SfxBindings *pBind,
154 SfxChildWindow *pCW,
155 Window *pParent
158 /* [Description]
159 Designer class.
161 : SfxDockingWindow( pBind, pCW, pParent, SfxResId(DLG_STYLE_DESIGNER) ),
163 pImpl( new SfxTemplateDialog_Impl( pParent, pBind, this ) )
166 pImpl->updateNonFamilyImages();
169 //-------------------------------------------------------------------------
171 SfxTemplateDialog::~SfxTemplateDialog()
173 delete pImpl;
176 ISfxTemplateCommon* SfxTemplateDialog::GetISfxTemplateCommon()
178 return pImpl->GetISfxTemplateCommon();
181 void SfxTemplateDialog::SetParagraphFamily()
183 // first select the paragraph family
184 pImpl->FamilySelect( SFX_STYLE_FAMILY_PARA );
185 // then select the automatic filter
186 pImpl->SetAutomaticFilter();
189 // ------------------------------------------------------------------------
191 void SfxTemplateDialog::DataChanged( const DataChangedEvent& _rDCEvt )
193 if ( ( DATACHANGED_SETTINGS == _rDCEvt.GetType() ) &&
194 ( 0 != ( SETTINGS_STYLE & _rDCEvt.GetFlags() ) ) )
196 pImpl->updateFamilyImages();
197 pImpl->updateNonFamilyImages();
200 SfxDockingWindow::DataChanged( _rDCEvt );
203 //-------------------------------------------------------------------------
205 void SfxTemplateDialog::Update()
207 pImpl->Update();
210 //-------------------------------------------------------------------------
212 void SfxTemplateDialog::Resize()
214 if(pImpl)
215 pImpl->Resize();
216 SfxDockingWindow::Resize();
220 //-------------------------------------------------------------------------
222 SfxChildAlignment SfxTemplateDialog::CheckAlignment(SfxChildAlignment eActAlign,SfxChildAlignment eAlign)
224 switch (eAlign)
226 case SFX_ALIGN_TOP:
227 case SFX_ALIGN_HIGHESTTOP:
228 case SFX_ALIGN_LOWESTTOP:
229 case SFX_ALIGN_BOTTOM:
230 case SFX_ALIGN_LOWESTBOTTOM:
231 case SFX_ALIGN_HIGHESTBOTTOM:
232 return eActAlign;
234 case SFX_ALIGN_LEFT:
235 case SFX_ALIGN_RIGHT:
236 case SFX_ALIGN_FIRSTLEFT:
237 case SFX_ALIGN_LASTLEFT:
238 case SFX_ALIGN_FIRSTRIGHT:
239 case SFX_ALIGN_LASTRIGHT:
240 return eAlign;
242 default:
243 return eAlign;
247 //-------------------------------------------------------------------------
249 SfxTemplateCatalog::SfxTemplateCatalog(Window *pParent, SfxBindings *pBindings)
250 : SfxModalDialog(pParent,SfxResId(RID_STYLECATALOG))
252 pImpl = new SfxTemplateCatalog_Impl(pParent, pBindings, this);
255 //-------------------------------------------------------------------------
257 SfxTemplateCatalog::~SfxTemplateCatalog()
259 delete pImpl;
262 //-------------------------------------------------------------------------
264 void DropListBox_Impl::MouseButtonDown( const MouseEvent& rMEvt )
266 nModifier = rMEvt.GetModifier();
268 sal_Bool bHitEmptySpace = ( NULL == GetEntry( rMEvt.GetPosPixel(), sal_True ) );
269 if( bHitEmptySpace && ( rMEvt.GetClicks() == 2 ) && rMEvt.IsMod1() )
270 Control::MouseButtonDown( rMEvt );
271 else
272 SvTreeListBox::MouseButtonDown( rMEvt );
275 sal_Int8 DropListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
277 /* [Description: ]
278 Drop is enabled as long as it is allowed to create a new style by example, i.e. to
279 create a style out of the current selection.
283 if ( IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
285 // special case: page styles are allowed to create new styles by example
286 // but not allowed to be created by drag and drop
287 if( pDialog->nActFamily == SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE ) ||
288 pDialog->bNewByExampleDisabled )
289 return DND_ACTION_NONE;
290 else
291 return DND_ACTION_COPY;
293 return SvTreeListBox::AcceptDrop( rEvt );
296 //-------------------------------------------------------------------------
298 sal_Int8 DropListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
300 sal_Int8 nRet = DND_ACTION_NONE;
301 SfxObjectShell* pDocShell = pDialog->GetObjectShell();
302 TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
303 sal_uInt32 nFormatCount = aHelper.GetFormatCount();
304 if ( pDocShell )
306 sal_Bool bFormatFound = sal_False;
308 for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
310 SotFormatStringId nId = aHelper.GetFormat(i);
311 TransferableObjectDescriptor aDesc;
313 if ( aHelper.GetTransferableObjectDescriptor( nId, aDesc ) )
315 if ( aDesc.maClassName == pDocShell->GetFactory().GetClassId() )
317 PostUserEvent( LINK( this, DropListBox_Impl, OnAsyncExecuteDrop ), 0 );
319 bFormatFound = sal_True;
320 nRet = rEvt.mnAction;
321 break;
326 if ( !bFormatFound )
327 return SvTreeListBox::ExecuteDrop( rEvt );
330 return nRet;
334 IMPL_LINK_NOARG(DropListBox_Impl, OnAsyncExecuteDrop)
336 pDialog->ActionSelect( SID_STYLE_NEW_BY_EXAMPLE );
337 return 0;
340 long DropListBox_Impl::Notify( NotifyEvent& rNEvt )
342 long nRet = 0;
343 if( rNEvt.GetType() == EVENT_KEYINPUT )
345 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
346 if(!rKeyCode.GetModifier())
348 if( pDialog->bCanDel && KEY_DELETE == rKeyCode.GetCode())
350 pDialog->DeleteHdl( NULL );
351 nRet = 1;
353 else if( KEY_RETURN == rKeyCode.GetCode())
355 GetDoubleClickHdl().Call(this);
356 nRet = 1;
360 if(!nRet)
361 nRet = SvTreeListBox::Notify( rNEvt );
362 return nRet;
366 //-------------------------------------------------------------------------
369 SfxActionListBox::SfxActionListBox
371 SfxCommonTemplateDialog_Impl* pParent,
372 WinBits nWinBits
375 /* [Description]
377 ListBox class that starts a PopupMenu (designer specific) in the
378 command handler.
381 : DropListBox_Impl(pParent->GetWindow(), nWinBits, pParent)
384 EnableContextMenuHandling();
387 //-------------------------------------------------------------------------
389 SfxActionListBox::SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent,
390 const ResId &rResId) :
391 DropListBox_Impl(pParent->GetWindow(), rResId, pParent)
393 EnableContextMenuHandling();
396 //-------------------------------------------------------------------------
398 PopupMenu* SfxActionListBox::CreateContextMenu( void )
401 if( !( GetSelectionCount() > 0 ) )
403 pDialog->EnableEdit( sal_False );
404 pDialog->EnableDel( sal_False );
406 return pDialog->CreateContextMenu();
409 //-------------------------------------------------------------------------
411 SfxTemplateDialogWrapper::SfxTemplateDialogWrapper(Window *pParentWnd,
412 sal_uInt16 nId, SfxBindings *p, SfxChildWinInfo *pInfo) :
413 SfxChildWindow(pParentWnd, nId)
415 SfxTemplateDialog *pWin = new SfxTemplateDialog(p, this, pParentWnd);
416 pWindow = pWin;
417 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
419 pWin->Initialize( pInfo );
420 pWin->SetMinOutputSizePixel(pWin->pImpl->GetMinOutputSizePixel());
423 void SfxTemplateDialogWrapper::SetParagraphFamily()
425 // forward to SfxTemplateDialog, because SfxTemplateDialog isn't exported
426 static_cast< SfxTemplateDialog* >( GetWindow() )->SetParagraphFamily();
429 //=========================================================================
430 SV_DECL_PTRARR_DEL(ExpandedEntries, StringPtr,16)
431 SV_IMPL_PTRARR(ExpandedEntries, StringPtr)
433 /* [Description]
435 TreeListBox class for displaying the hierarchical view of the templates
438 class StyleTreeListBox_Impl : public DropListBox_Impl
440 private:
441 SvLBoxEntry* pCurEntry;
442 SfxCommonTemplateDialog_Impl* pCommon;
443 Link aDoubleClickLink;
444 Link aDropLink;
445 String aParent;
446 String aStyle;
448 protected:
449 virtual void Command( const CommandEvent& rMEvt );
450 virtual long Notify( NotifyEvent& rNEvt );
451 virtual sal_Bool DoubleClickHdl();
452 virtual long ExpandingHdl();
453 virtual void ExpandedHdl();
454 virtual sal_Bool NotifyMoving(SvLBoxEntry* pTarget,
455 SvLBoxEntry* pEntry,
456 SvLBoxEntry*& rpNewParent,
457 sal_uIntPtr& rNewChildPos);
458 public:
459 StyleTreeListBox_Impl( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle = 0);
461 void SetDoubleClickHdl(const Link &rLink) { aDoubleClickLink = rLink; }
462 void SetDropHdl(const Link &rLink) { aDropLink = rLink; }
463 using SvLBox::GetParent;
464 const String& GetParent() const { return aParent; }
465 const String& GetStyle() const { return aStyle; }
466 void MakeExpanded_Impl(ExpandedEntries& rEntries) const;
468 virtual PopupMenu* CreateContextMenu( void );
471 //-------------------------------------------------------------------------
474 void StyleTreeListBox_Impl::MakeExpanded_Impl(ExpandedEntries& rEntries) const
476 SvLBoxEntry *pEntry;
477 sal_uInt16 nCount=0;
478 for(pEntry=(SvLBoxEntry*)FirstVisible();pEntry;pEntry=(SvLBoxEntry*)NextVisible(pEntry))
480 if(IsExpanded(pEntry))
482 StringPtr pString=new String(GetEntryText(pEntry));
483 rEntries.Insert(pString,nCount++);
488 PopupMenu* StyleTreeListBox_Impl::CreateContextMenu()
490 return pDialog->CreateContextMenu();
493 sal_Bool StyleTreeListBox_Impl::DoubleClickHdl()
495 /* [Description]
497 DoubleClick-Handler; calls the link.
498 SV virtual method.
501 aDoubleClickLink.Call(this);
502 return sal_False;
505 //-------------------------------------------------------------------------
507 void StyleTreeListBox_Impl::Command( const CommandEvent& rCEvt )
509 /* [Description]
511 Command Handler; this executes a PopupMenu (designer-specific)
512 SV virtual method.
515 SvTreeListBox::Command(rCEvt);
518 //-------------------------------------------------------------------------
520 long StyleTreeListBox_Impl::Notify( NotifyEvent& rNEvt )
522 // handle <RETURN> as double click
524 long nRet = 0;
525 if ( rNEvt.GetType() == EVENT_KEYINPUT )
527 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
528 if ( !rKeyCode.GetModifier() && KEY_RETURN == rKeyCode.GetCode() )
530 aDoubleClickLink.Call( this );
531 nRet = 1;
535 if ( !nRet )
536 nRet = DropListBox_Impl::Notify( rNEvt );
538 return nRet;
541 //-------------------------------------------------------------------------
543 sal_Bool StyleTreeListBox_Impl::NotifyMoving(SvLBoxEntry* pTarget,
544 SvLBoxEntry* pEntry,
545 SvLBoxEntry*& rpNewParent,
546 sal_uIntPtr& lPos)
547 /* [Description]
549 NotifyMoving Handler; This leads via a link on the event to the dialog.
550 SV virtual method.
553 if(!pTarget || !pEntry)
554 return sal_False;
555 aParent = GetEntryText(pTarget);
556 aStyle = GetEntryText(pEntry);
557 const sal_Bool bRet = (sal_Bool)aDropLink.Call(this);
558 rpNewParent = pTarget;
559 lPos=0;
560 IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
561 const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
562 for(SvLBoxEntry *pTmpEntry=FirstChild(pTarget);
563 pTmpEntry && COMPARE_LESS==pCollator->compareString(
564 GetEntryText(pTmpEntry),GetEntryText(pEntry));
565 pTmpEntry=NextSibling(pTmpEntry),lPos++) ;
567 return bRet? (sal_Bool)2: sal_False;
570 //-------------------------------------------------------------------------
572 long StyleTreeListBox_Impl::ExpandingHdl()
574 /* [Description]
576 ExpandingHdl Handler; the current entry is noticed.
577 SV virtual method.
579 [Cross-reference]
580 <StyleTreeListBox_Impl::ExpandedHdl()>
583 pCurEntry = GetCurEntry();
584 return sal_True;
587 //-------------------------------------------------------------------------
589 void StyleTreeListBox_Impl::ExpandedHdl()
591 /* [Description]
593 ExpandedHdl Handler;
594 SV virtual method.
596 [Cross-reference]
597 <StyleTreeListBox_Impl::ExpandingHdl()>
601 SvLBoxEntry *pEntry = GetHdlEntry();
602 if(!IsExpanded(pEntry) && pCurEntry != GetCurEntry())
603 SelectAll( sal_False );
604 pCurEntry = 0;
607 //-------------------------------------------------------------------------
609 StyleTreeListBox_Impl::StyleTreeListBox_Impl(
610 SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle) :
611 DropListBox_Impl(pParent->GetWindow(), nWinStyle, pParent),
612 pCurEntry(0),
613 pCommon(pParent)
615 /* [Description]
617 Constructor StyleTreeListBox_Impl
620 EnableContextMenuHandling();
623 //-------------------------------------------------------------------------
625 class StyleTreeArr_Impl;
628 /* [Description]
630 Internal structure for the establishment of the hierarchical view
633 struct StyleTree_Impl
635 String aName;
636 String aParent;
637 StyleTreeArr_Impl *pChildren;
638 sal_Bool bIsExpanded;
639 sal_Bool HasParent() const { return aParent.Len() != 0; }
641 StyleTree_Impl(const String &rName, const String &rParent):
642 aName(rName), aParent(rParent), pChildren(0), bIsExpanded(0) {}
643 ~StyleTree_Impl();
644 void Put(StyleTree_Impl* pIns, sal_uIntPtr lPos=ULONG_MAX);
645 sal_uIntPtr Count();
648 typedef StyleTree_Impl* StyleTree_ImplPtr;
649 SV_DECL_PTRARR_DEL(StyleTreeArr_Impl, StyleTree_ImplPtr, 16)
650 SV_IMPL_PTRARR(StyleTreeArr_Impl, StyleTree_ImplPtr)
653 sal_uIntPtr StyleTree_Impl::Count()
655 return pChildren ? pChildren->Count() : 0L;
658 //-------------------------------------------------------------------------
660 StyleTree_Impl::~StyleTree_Impl()
662 delete pChildren;
665 //-------------------------------------------------------------------------
667 void StyleTree_Impl::Put(StyleTree_Impl* pIns, sal_uIntPtr lPos)
669 if ( !pChildren )
670 pChildren = new StyleTreeArr_Impl;
672 if ( ULONG_MAX == lPos )
673 lPos = pChildren->Count();
674 pChildren->Insert( pIns, (sal_uInt16)lPos );
677 //-------------------------------------------------------------------------
679 StyleTreeArr_Impl &MakeTree_Impl(StyleTreeArr_Impl &rArr)
681 const sal_uInt16 nCount = rArr.Count();
683 comphelper::string::NaturalStringSorter aSorter(
684 ::comphelper::getProcessComponentContext(),
685 Application::GetSettings().GetLocale());
687 // Arrange all under their Parents
688 sal_uInt16 i;
689 for(i = 0; i < nCount; ++i)
691 StyleTree_ImplPtr pEntry = rArr[i];
692 if(pEntry->HasParent())
694 for(sal_uInt16 j = 0; j < nCount; ++j)
696 StyleTree_ImplPtr pCmp = rArr[j];
697 if(pCmp->aName == pEntry->aParent)
699 // Paste initial filter
700 sal_uInt16 nPos;
701 for( nPos = 0 ; nPos < pCmp->Count() &&
702 aSorter.compare((*pCmp->pChildren)[nPos]->aName, pEntry->aName) < 0 ; nPos++)
704 pCmp->Put(pEntry,nPos);
705 break;
711 for(i = 0; i < rArr.Count(); )
713 if(rArr[i]->HasParent())
714 rArr.Remove(i);
715 else
716 ++i;
718 return rArr;
721 //-------------------------------------------------------------------------
724 inline sal_Bool IsExpanded_Impl( const ExpandedEntries& rEntries,
725 const String &rStr)
727 sal_uInt16 nCount=rEntries.Count();
728 for(sal_uInt16 n=0;n<nCount;n++)
729 if(*rEntries[n]==rStr)
730 return sal_True;
731 return sal_False;
736 SvLBoxEntry* FillBox_Impl(SvTreeListBox *pBox,
737 StyleTree_ImplPtr pEntry,
738 const ExpandedEntries& rEntries,
739 SvLBoxEntry* pParent = 0)
741 SvLBoxEntry* pNewEntry = pBox->InsertEntry(pEntry->aName, pParent);
742 const sal_uInt16 nCount = pEntry->pChildren? pEntry->pChildren->Count(): 0;
743 for(sal_uInt16 i = 0; i < nCount; ++i)
744 FillBox_Impl(pBox, (*pEntry->pChildren)[i], rEntries, pNewEntry);
745 return pNewEntry;
748 //-------------------------------------------------------------------------
749 // Constructor
751 SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, SfxDockingWindow* pW ) :
753 aISfxTemplateCommon ( this ),
754 pBindings ( pB ),
755 pWindow ( pW ),
756 pModule ( NULL ),
757 pTimer ( NULL ),
758 m_pStyleFamiliesId ( NULL ),
759 pStyleSheetPool ( NULL ),
760 pTreeBox ( NULL ),
761 pCurObjShell ( NULL ),
762 xModuleManager ( ::comphelper::getProcessServiceFactory()->createInstance(
763 DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY ),
764 m_pDeletionWatcher ( NULL ),
766 aFmtLb ( this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH ),
767 aFilterLb ( pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP ),
769 nActFamily ( 0xffff ),
770 nActFilter ( 0 ),
771 nAppFilter ( 0 ),
773 bDontUpdate ( sal_False ),
774 bIsWater ( sal_False ),
775 bEnabled ( sal_True ),
776 bUpdate ( sal_False ),
777 bUpdateFamily ( sal_False ),
778 bCanEdit ( sal_False ),
779 bCanDel ( sal_False ),
780 bCanNew ( sal_True ),
781 bWaterDisabled ( sal_False ),
782 bNewByExampleDisabled ( sal_False ),
783 bUpdateByExampleDisabled( sal_False ),
784 bTreeDrag ( sal_True ),
785 bHierarchical ( sal_False ),
786 bBindingUpdate ( sal_True )
788 aFmtLb.SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST));
789 aFmtLb.SetHelpId( HID_TEMPLATE_FMT );
790 aFilterLb.SetHelpId( HID_TEMPLATE_FILTER );
791 aFmtLb.SetStyle( aFmtLb.GetStyle() | WB_SORT | WB_HIDESELECTION );
792 Font aFont = aFmtLb.GetFont();
793 aFont.SetWeight( WEIGHT_NORMAL );
794 aFmtLb.SetFont( aFont );
797 //-------------------------------------------------------------------------
799 SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, ModalDialog* pW ) :
801 aISfxTemplateCommon ( this ),
802 pBindings ( pB ),
803 pWindow ( pW ),
804 pModule ( NULL ),
805 pTimer ( NULL ),
806 pStyleSheetPool ( NULL ),
807 pTreeBox ( NULL ),
808 pCurObjShell ( NULL ),
809 m_pDeletionWatcher ( NULL ),
811 aFmtLb ( this, SfxResId( BT_VLIST ) ),
812 aFilterLb ( pW, SfxResId( BT_FLIST ) ),
814 nActFamily ( 0xffff ),
815 nActFilter ( 0 ),
816 nAppFilter ( 0 ),
818 bDontUpdate ( sal_False ),
819 bIsWater ( sal_False ),
820 bEnabled ( sal_True ),
821 bUpdate ( sal_False ),
822 bUpdateFamily ( sal_False ),
823 bCanEdit ( sal_False ),
824 bCanDel ( sal_False ),
825 bCanNew ( sal_True ),
826 bWaterDisabled ( sal_False ),
827 bNewByExampleDisabled ( sal_False ),
828 bUpdateByExampleDisabled( sal_False ),
829 bTreeDrag ( sal_True ),
830 bHierarchical ( sal_False ),
831 bBindingUpdate ( sal_True )
834 aFmtLb.SetStyle( aFmtLb.GetStyle() | WB_SORT );
837 //-------------------------------------------------------------------------
839 sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId)
841 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nId );
842 return SfxFamilyIdToNId(pItem->GetFamily())-1;
845 //-------------------------------------------------------------------------
847 void SfxTemplateDialog_Impl::EnableEdit(sal_Bool bEnable)
849 SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
850 if( !bEnable || !bUpdateByExampleDisabled )
851 EnableItem( SID_STYLE_UPDATE_BY_EXAMPLE, bEnable);
854 //-------------------------------------------------------------------------
856 void SfxCommonTemplateDialog_Impl::ReadResource()
858 // Read global user resource
859 for(sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
860 pFamilyState[i] = 0;
862 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
863 pCurObjShell = pViewFrame->GetObjectShell();
864 ResMgr* pMgr = pCurObjShell ? pCurObjShell->GetResMgr() : NULL;
865 ResId aFamId( DLG_STYLE_DESIGNER, *pMgr );
866 aFamId.SetRT(RSC_SFX_STYLE_FAMILIES);
867 m_pStyleFamiliesId = new ResId( aFamId.GetId(), *pMgr );
868 m_pStyleFamiliesId->SetRT(RSC_SFX_STYLE_FAMILIES);
869 if( !pMgr || !pMgr->IsAvailable( aFamId ) )
870 pStyleFamilies = new SfxStyleFamilies;
871 else
872 pStyleFamilies = new SfxStyleFamilies( aFamId );
874 nActFilter = pCurObjShell ? static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pCurObjShell ) ) : 0xFFFF;
875 if ( pCurObjShell && 0xFFFF == nActFilter )
876 nActFilter = pCurObjShell->GetAutoStyleFilterIndex();
878 // Paste in the toolbox
879 // reverse order, since always inserted at the head
880 size_t nCount = pStyleFamilies->size();
882 pBindings->ENTERREGISTRATIONS();
884 size_t i;
885 for(i = 0; i < nCount; ++i)
887 sal_uInt16 nSlot = 0;
888 switch( (sal_uInt16)pStyleFamilies->at( i )->GetFamily() )
890 case SFX_STYLE_FAMILY_CHAR: nSlot = SID_STYLE_FAMILY1; break;
891 case SFX_STYLE_FAMILY_PARA: nSlot = SID_STYLE_FAMILY2; break;
892 case SFX_STYLE_FAMILY_FRAME:nSlot = SID_STYLE_FAMILY3; break;
893 case SFX_STYLE_FAMILY_PAGE: nSlot = SID_STYLE_FAMILY4; break;
894 case SFX_STYLE_FAMILY_PSEUDO: nSlot = SID_STYLE_FAMILY5; break;
895 default: OSL_FAIL("unknown StyleFamily"); break;
897 pBoundItems[i] =
898 new SfxTemplateControllerItem(nSlot, *this, *pBindings);
900 pBoundItems[i++] = new SfxTemplateControllerItem(
901 SID_STYLE_WATERCAN, *this, *pBindings);
902 pBoundItems[i++] = new SfxTemplateControllerItem(
903 SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings);
904 pBoundItems[i++] = new SfxTemplateControllerItem(
905 SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings);
906 pBoundItems[i++] = new SfxTemplateControllerItem(
907 SID_STYLE_NEW, *this, *pBindings);
908 pBoundItems[i++] = new SfxTemplateControllerItem(
909 SID_STYLE_DRAGHIERARCHIE, *this, *pBindings);
910 pBoundItems[i++] = new SfxTemplateControllerItem(
911 SID_STYLE_EDIT, *this, *pBindings);
912 pBoundItems[i++] = new SfxTemplateControllerItem(
913 SID_STYLE_DELETE, *this, *pBindings);
914 pBoundItems[i++] = new SfxTemplateControllerItem(
915 SID_STYLE_FAMILY, *this, *pBindings);
916 pBindings->LEAVEREGISTRATIONS();
918 for(; i < COUNT_BOUND_FUNC; ++i)
919 pBoundItems[i] = 0;
921 StartListening(*pBindings);
923 // Insert in the reverse order of occurrence in the Style Families. This is for
924 // the toolbar of the designer. The list box of the catalog respects the
925 // correct order by itself.
927 // Sequences: the order of Resource = the order of Toolbar for example list box.
928 // Order of ascending SIDs: Low SIDs are displayed first when templates of
929 // several families are active.
931 // in the Writer the UpdateStyleByExample Toolbox button is removed and
932 // the NewStyle button gets a PopupMenu
933 if(nCount > 4)
934 ReplaceUpdateButtonByMenu();
936 for( ; nCount--; )
938 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nCount );
939 sal_uInt16 nId = SfxFamilyIdToNId( pItem->GetFamily() );
940 InsertFamilyItem( nId, pItem );
943 LoadedFamilies();
945 sal_uInt16 nStart = SID_STYLE_FAMILY1;
946 sal_uInt16 nEnd = SID_STYLE_FAMILY4;
948 for ( i = nStart; i <= nEnd; i++ )
949 pBindings->Update(i);
951 pModule = pCurObjShell ? pCurObjShell->GetModule() : NULL;
954 //-------------------------------------------------------------------------
956 void SfxCommonTemplateDialog_Impl::ClearResource()
958 ClearFamilyList();
959 impl_clear();
962 void SfxCommonTemplateDialog_Impl::impl_clear()
964 DELETEX(pStyleFamilies);
965 sal_uInt16 i;
966 for ( i = 0; i < MAX_FAMILIES; ++i )
967 DELETEX(pFamilyState[i]);
968 for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
969 delete pBoundItems[i];
970 pCurObjShell = NULL;
972 DELETEZ( m_pStyleFamiliesId );
975 void SfxCommonTemplateDialog_Impl::impl_setDeletionWatcher(DeletionWatcher* pNewWatcher)
977 m_pDeletionWatcher = pNewWatcher;
980 //-------------------------------------------------------------------------
982 void SfxCommonTemplateDialog_Impl::Initialize()
984 // Read global user resource
985 ReadResource();
986 pBindings->Invalidate( SID_STYLE_FAMILY );
987 pBindings->Update( SID_STYLE_FAMILY );
988 Update_Impl();
990 aFilterLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) );
991 aFmtLb.SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) );
992 aFmtLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) );
994 aFilterLb.Show();
995 aFmtLb.Show();
998 //-------------------------------------------------------------------------
1000 SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl()
1002 String aEmpty;
1003 if ( bIsWater )
1004 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
1005 GetWindow()->Hide();
1006 impl_clear();
1007 if ( pStyleSheetPool )
1008 EndListening(*pStyleSheetPool);
1009 pStyleSheetPool = NULL;
1010 delete pTreeBox;
1011 delete pTimer;
1012 if ( m_pDeletionWatcher )
1013 m_pDeletionWatcher->signal();
1016 //-------------------------------------------------------------------------
1018 sal_uInt16 SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SfxStyleFamily nFamily )
1020 switch ( nFamily )
1022 case SFX_STYLE_FAMILY_CHAR: return 1;
1023 case SFX_STYLE_FAMILY_PARA: return 2;
1024 case SFX_STYLE_FAMILY_FRAME: return 3;
1025 case SFX_STYLE_FAMILY_PAGE: return 4;
1026 case SFX_STYLE_FAMILY_PSEUDO: return 5;
1027 default: return 0;
1031 void SfxCommonTemplateDialog_Impl::SetAutomaticFilter()
1033 sal_uInt16 nCount = aFilterLb.GetEntryCount();
1034 for ( sal_uInt16 i = 0; i < nCount; ++i )
1036 sal_uIntPtr nFlags = (sal_uIntPtr)aFilterLb.GetEntryData(i);
1037 if ( SFXSTYLEBIT_AUTO == nFlags )
1039 // automatic entry found -> select it
1040 aFilterLb.SelectEntryPos(i);
1041 // then call the handler to filter the styles
1042 FilterSelect( i - 1 );
1043 break;
1048 //-------------------------------------------------------------------------
1049 // Helper function: Access to the current family item
1050 const SfxStyleFamilyItem *SfxCommonTemplateDialog_Impl::GetFamilyItem_Impl() const
1052 const size_t nCount = pStyleFamilies->size();
1053 for(size_t i = 0; i < nCount; ++i)
1055 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( i );
1056 sal_uInt16 nId = SfxFamilyIdToNId(pItem->GetFamily());
1057 if(nId == nActFamily)
1058 return pItem;
1060 return 0;
1063 SfxStyleSheetBase *SfxCommonTemplateDialog_Impl::GetSelectedStyle() const
1065 if (!IsInitialized() || !pStyleSheetPool || !HasSelectedStyle())
1066 return NULL;
1067 const String aTemplName( GetSelectedEntry() );
1068 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1069 return pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL );
1072 //-------------------------------------------------------------------------
1074 void SfxCommonTemplateDialog_Impl::SelectStyle(const String &rStr)
1076 const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl();
1077 if ( !pItem )
1078 return;
1079 const SfxStyleFamily eFam = pItem->GetFamily();
1080 SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( rStr, eFam, SFXSTYLEBIT_ALL );
1081 if( pStyle )
1082 EnableEdit( !(pStyle->GetMask() & SFXSTYLEBIT_READONLY) );
1083 else
1084 EnableEdit(sal_False);
1086 if ( pTreeBox )
1088 if ( rStr.Len() )
1090 SvLBoxEntry* pEntry = pTreeBox->First();
1091 while ( pEntry )
1093 if ( pTreeBox->GetEntryText( pEntry ) == rStr )
1095 pTreeBox->MakeVisible( pEntry );
1096 pTreeBox->Select( pEntry );
1097 return;
1099 pEntry = pTreeBox->Next( pEntry );
1102 else
1103 pTreeBox->SelectAll( sal_False );
1105 else
1107 sal_Bool bSelect = ( rStr.Len() > 0 );
1108 if ( bSelect )
1110 SvLBoxEntry* pEntry = (SvLBoxEntry*)aFmtLb.FirstVisible();
1111 while ( pEntry && aFmtLb.GetEntryText( pEntry ) != rStr )
1112 pEntry = (SvLBoxEntry*)aFmtLb.NextVisible( pEntry );
1113 if ( !pEntry )
1114 bSelect = sal_False;
1115 else
1117 aFmtLb.MakeVisible( pEntry );
1118 aFmtLb.Select( pEntry );
1119 bWaterDisabled = !HasSelectedStyle();
1120 FmtSelectHdl( NULL );
1124 if ( !bSelect )
1126 aFmtLb.SelectAll( sal_False );
1127 EnableEdit(sal_False);
1132 //-------------------------------------------------------------------------
1134 String SfxCommonTemplateDialog_Impl::GetSelectedEntry() const
1136 String aRet;
1137 if ( pTreeBox )
1139 SvLBoxEntry* pEntry = pTreeBox->FirstSelected();
1140 if ( pEntry )
1141 aRet = pTreeBox->GetEntryText( pEntry );
1143 else
1145 SvLBoxEntry* pEntry = aFmtLb.FirstSelected();
1146 if ( pEntry )
1147 aRet = aFmtLb.GetEntryText( pEntry );
1149 return aRet;
1152 //-------------------------------------------------------------------------
1154 void SfxCommonTemplateDialog_Impl::EnableTreeDrag( sal_Bool bEnable )
1156 if ( pStyleSheetPool )
1158 SfxStyleSheetBase* pStyle = pStyleSheetPool->First();
1159 if ( pTreeBox )
1161 if ( pStyle && pStyle->HasParentSupport() && bEnable )
1162 pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
1163 else
1164 pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
1167 bTreeDrag = bEnable;
1170 //-------------------------------------------------------------------------
1172 void SfxCommonTemplateDialog_Impl::FillTreeBox()
1174 OSL_ENSURE( pTreeBox, "FillTreeBox() without treebox");
1175 if(pStyleSheetPool && nActFamily != 0xffff)
1177 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1178 pStyleSheetPool->SetSearchMask(pItem->GetFamily(), SFXSTYLEBIT_ALL);
1179 StyleTreeArr_Impl aArr;
1180 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
1181 if(pStyle && pStyle->HasParentSupport() && bTreeDrag )
1182 pTreeBox->SetDragDropMode(SV_DRAGDROP_CTRL_MOVE);
1183 else
1184 pTreeBox->SetDragDropMode(SV_DRAGDROP_NONE);
1185 while(pStyle)
1187 StyleTree_ImplPtr pNew =
1188 new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
1189 aArr.Insert(pNew, aArr.Count());
1190 pStyle = pStyleSheetPool->Next();
1192 MakeTree_Impl(aArr);
1193 ExpandedEntries aEntries;
1194 if(pTreeBox)
1195 ((const StyleTreeListBox_Impl *)pTreeBox)->
1196 MakeExpanded_Impl( aEntries);
1197 pTreeBox->SetUpdateMode( sal_False );
1198 pTreeBox->Clear();
1199 const sal_uInt16 nCount = aArr.Count();
1200 for(sal_uInt16 i = 0; i < nCount; ++i)
1201 FillBox_Impl(pTreeBox, aArr[i], aEntries);
1203 EnableItem(SID_STYLE_WATERCAN,sal_False);
1205 SfxTemplateItem* pState = pFamilyState[nActFamily-1];
1207 if ( nCount )
1208 pTreeBox->Expand( pTreeBox->First() );
1210 for ( SvLBoxEntry* pEntry = pTreeBox->First(); pEntry; pEntry = pTreeBox->Next( pEntry ) )
1212 if ( IsExpanded_Impl( aEntries, pTreeBox->GetEntryText( pEntry ) ) )
1213 pTreeBox->Expand( pEntry );
1216 pTreeBox->SetUpdateMode( sal_True );
1218 String aStyle;
1219 if(pState) // Select current entry
1220 aStyle = pState->GetStyleName();
1221 SelectStyle(aStyle);
1222 EnableDelete();
1226 //-------------------------------------------------------------------------
1227 sal_Bool SfxCommonTemplateDialog_Impl::HasSelectedStyle() const
1229 return pTreeBox? pTreeBox->FirstSelected() != 0:
1230 aFmtLb.GetSelectionCount() != 0;
1234 //-------------------------------------------------------------------------
1236 // internal: Refresh the display
1237 // nFlags: what we should update.
1238 void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags)
1240 OSL_ENSURE(nFlags, "nothing to do");
1241 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1242 if (!pItem)
1244 // Is the case for the template catalog
1245 SfxTemplateItem **ppItem = pFamilyState;
1246 const size_t nFamilyCount = pStyleFamilies->size();
1247 size_t n;
1248 for( n = 0; n < nFamilyCount; n++ )
1249 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1250 if ( n == nFamilyCount )
1251 // It happens sometimes, God knows why
1252 return;
1253 ppItem += StyleNrToInfoOffset(n);
1254 nAppFilter = (*ppItem)->GetValue();
1255 FamilySelect( StyleNrToInfoOffset(n)+1 );
1256 pItem = GetFamilyItem_Impl();
1259 const SfxStyleFamily eFam = pItem->GetFamily();
1261 SfxFilterTupel* pT = ( nActFilter < pItem->GetFilterList().size() ? pItem->GetFilterList()[nActFilter] : NULL );
1262 sal_uInt16 nFilter = pT ? pT->nFlags : 0;
1263 if(!nFilter) // automatic
1264 nFilter = nAppFilter;
1266 OSL_ENSURE(pStyleSheetPool, "no StyleSheetPool");
1267 if(pStyleSheetPool)
1269 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1270 pItem = GetFamilyItem_Impl();
1271 if((nFlags & UPDATE_FAMILY) == UPDATE_FAMILY) // Update view type list (Hierarchical, All, etc.
1273 CheckItem(nActFamily, sal_True); // check Button in Toolbox
1274 aFilterLb.SetUpdateMode(sal_False);
1275 aFilterLb.Clear();
1276 //insert hierarchical at the beginning
1277 sal_uInt16 nPos = aFilterLb.InsertEntry(String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)), 0);
1278 aFilterLb.SetEntryData( nPos, (void*)(sal_uIntPtr)SFXSTYLEBIT_ALL );
1279 const SfxStyleFilter& rFilter = pItem->GetFilterList();
1280 for( size_t i = 0; i < rFilter.size(); ++i)
1282 sal_uIntPtr nFilterFlags = rFilter[ i ]->nFlags;
1283 nPos = aFilterLb.InsertEntry( rFilter[ i ]->aName );
1284 aFilterLb.SetEntryData( nPos, (void*)nFilterFlags );
1286 if(nActFilter < aFilterLb.GetEntryCount() - 1)
1287 aFilterLb.SelectEntryPos(nActFilter + 1);
1288 else
1290 nActFilter = 0;
1291 aFilterLb.SelectEntryPos(1);
1292 SfxFilterTupel* pActT = ( nActFilter < rFilter.size() ) ? rFilter[ nActFilter ] : NULL;
1293 sal_uInt16 nFilterFlags = pActT ? pActT->nFlags : 0;
1294 pStyleSheetPool->SetSearchMask(eFam, nFilterFlags);
1297 // if the tree view again, select family hierarchy
1298 if(pTreeBox)
1299 aFilterLb.SelectEntry(String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)));
1301 // show maximum 12 entries
1302 aFilterLb.SetDropDownLineCount( MAX_FILTER_ENTRIES );
1303 aFilterLb.SetUpdateMode(sal_True);
1305 else
1307 if( nActFilter < aFilterLb.GetEntryCount() - 1)
1308 aFilterLb.SelectEntryPos(nActFilter + 1);
1309 else
1311 nActFilter = 0;
1312 aFilterLb.SelectEntryPos(1);
1316 if(nFlags & UPDATE_FAMILY_LIST)
1318 EnableItem(SID_STYLE_WATERCAN,sal_False);
1320 SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
1321 SvLBoxEntry* pEntry = aFmtLb.First();
1322 std::vector<rtl::OUString> aStrings;
1324 comphelper::string::NaturalStringSorter aSorter(
1325 ::comphelper::getProcessComponentContext(),
1326 Application::GetSettings().GetLocale());
1328 while( pStyle )
1330 //Bubblesort
1331 size_t nPos;
1332 for(nPos = aStrings.size(); nPos && aSorter.compare(aStrings[nPos-1], pStyle->GetName()) > 0; --nPos)
1334 aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
1335 pStyle = pStyleSheetPool->Next();
1338 size_t nCount = aStrings.size();
1339 size_t nPos = 0;
1340 while(nPos < nCount && pEntry &&
1341 aStrings[nPos] == rtl::OUString(aFmtLb.GetEntryText(pEntry)))
1343 ++nPos;
1344 pEntry = aFmtLb.Next( pEntry );
1347 if( nPos < nCount || pEntry )
1349 // Fills the display box
1350 aFmtLb.SetUpdateMode(sal_False);
1351 aFmtLb.Clear();
1353 for(nPos = 0; nPos < nCount; ++nPos)
1354 aFmtLb.InsertEntry(aStrings[nPos], 0, sal_False, nPos);
1356 aFmtLb.SetUpdateMode(true);
1358 // Selects the current style if any
1359 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1360 String aStyle;
1361 if(pState)
1362 aStyle = pState->GetStyleName();
1363 SelectStyle(aStyle);
1364 EnableDelete();
1369 //-------------------------------------------------------------------------
1371 // Updated display: Watering the house
1372 void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
1374 bWaterDisabled = pItem == 0;
1376 if(!bWaterDisabled)
1377 bWaterDisabled = !HasSelectedStyle();
1379 if(pItem && !bWaterDisabled)
1381 CheckItem(SID_STYLE_WATERCAN, pItem->GetValue());
1382 EnableItem( SID_STYLE_WATERCAN, sal_True );
1384 else
1385 if(!bWaterDisabled)
1386 EnableItem(SID_STYLE_WATERCAN, sal_True);
1387 else
1388 EnableItem(SID_STYLE_WATERCAN, sal_False);
1390 // Ignore while in watercan mode statusupdates
1392 size_t nCount = pStyleFamilies->size();
1393 pBindings->EnterRegistrations();
1394 for(size_t n = 0; n < nCount; n++)
1396 SfxControllerItem *pCItem=pBoundItems[n];
1397 sal_Bool bChecked = pItem && pItem->GetValue();
1398 if( pCItem->IsBound() == bChecked )
1400 if( !bChecked )
1401 pCItem->ReBind();
1402 else
1403 pCItem->UnBind();
1406 pBindings->LeaveRegistrations();
1409 //-------------------------------------------------------------------------
1411 // Item with the status of a Family is copied and noted
1412 // (is updated when all states have also been updated.)
1413 // See also: <SfxBindings::AddDoneHdl(const Link &)>
1415 void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
1417 sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START;
1418 DELETEZ(pFamilyState[nIdx]);
1419 if ( pItem )
1420 pFamilyState[nIdx] = new SfxTemplateItem(*pItem);
1421 bUpdate = sal_True;
1423 // If used templates (how the hell you find this out??)
1424 bUpdateFamily = sal_True;
1427 //-------------------------------------------------------------------------
1428 // Notice from SfxBindings that the update is completed. Pushes out the update
1429 // of the display.
1431 void SfxCommonTemplateDialog_Impl::Update_Impl()
1433 sal_Bool bDocChanged=sal_False;
1434 SfxStyleSheetBasePool* pNewPool = NULL;
1435 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1436 SfxObjectShell* pDocShell = pViewFrame->GetObjectShell();
1437 if( pDocShell )
1438 pNewPool = pDocShell->GetStyleSheetPool();
1440 if ( pNewPool != pStyleSheetPool && pDocShell )
1442 SfxModule* pNewModule = pDocShell->GetModule();
1443 if( pNewModule && pNewModule != pModule )
1445 ClearResource();
1446 ReadResource();
1448 if ( pStyleSheetPool )
1450 EndListening(*pStyleSheetPool);
1451 pStyleSheetPool = 0;
1454 if ( pNewPool )
1456 StartListening(*pNewPool);
1457 pStyleSheetPool = pNewPool;
1458 bDocChanged=sal_True;
1462 if (bUpdateFamily)
1463 UpdateFamily_Impl();
1465 sal_uInt16 i;
1466 for(i = 0; i < MAX_FAMILIES; ++i)
1467 if(pFamilyState[i])
1468 break;
1469 if(i == MAX_FAMILIES || !pNewPool)
1470 // nothing is allowed
1471 return;
1473 SfxTemplateItem *pItem = 0;
1474 // current region not within the allowed region or default
1475 if(nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1] ) )
1477 CheckItem(nActFamily, sal_False);
1478 SfxTemplateItem **ppItem = pFamilyState;
1479 const size_t nFamilyCount = pStyleFamilies->size();
1480 size_t n;
1481 for( n = 0; n < nFamilyCount; n++ )
1482 if( ppItem[ StyleNrToInfoOffset(n) ] ) break;
1483 ppItem+=StyleNrToInfoOffset(n);
1485 nAppFilter = (*ppItem)->GetValue();
1486 FamilySelect( StyleNrToInfoOffset(n)+1 );
1488 pItem = *ppItem;
1490 else if( bDocChanged )
1492 // other DocShell -> all new
1493 CheckItem( nActFamily, sal_True );
1494 nActFilter = static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pDocShell ) );
1495 if ( 0xFFFF == nActFilter )
1496 nActFilter = pDocShell->GetAutoStyleFilterIndex();
1498 nAppFilter = pItem->GetValue();
1499 if(!pTreeBox)
1501 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1503 else
1504 FillTreeBox();
1506 else
1508 // other filters for automatic
1509 CheckItem( nActFamily, sal_True );
1510 const SfxStyleFamilyItem *pStyleItem = GetFamilyItem_Impl();
1511 if ( 0 == pStyleItem->GetFilterList()[ nActFilter ]->nFlags
1512 && nAppFilter != pItem->GetValue())
1514 nAppFilter = pItem->GetValue();
1515 if(!pTreeBox)
1516 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1517 else
1518 FillTreeBox();
1520 else
1521 nAppFilter = pItem->GetValue();
1523 const String aStyle(pItem->GetStyleName());
1524 SelectStyle(aStyle);
1525 EnableDelete();
1526 EnableNew( bCanNew );
1529 //-------------------------------------------------------------------------
1531 IMPL_LINK( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, pTim )
1533 (void)pTim; // unused
1534 if(!bDontUpdate)
1536 bDontUpdate=sal_True;
1537 if(!pTreeBox)
1538 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1539 else
1541 FillTreeBox();
1542 SfxTemplateItem *pState = pFamilyState[nActFamily-1];
1543 if(pState)
1545 const String aStyle(pState->GetStyleName());
1546 SelectStyle(aStyle);
1547 EnableDelete();
1550 bDontUpdate=sal_False;
1551 DELETEZ(pTimer);
1553 else
1554 pTimer->Start();
1555 return 0;
1559 //-------------------------------------------------------------------------
1560 void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1562 // tap update
1563 if(rHint.Type() == TYPE(SfxSimpleHint))
1565 switch(((SfxSimpleHint&) rHint ).GetId())
1567 case SFX_HINT_UPDATEDONE:
1569 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1570 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
1571 if (
1572 bUpdate &&
1574 !IsCheckedItem(SID_STYLE_WATERCAN) ||
1575 (pDocShell && pDocShell->GetStyleSheetPool() != pStyleSheetPool)
1579 bUpdate = sal_False;
1580 Update_Impl();
1582 else if ( bUpdateFamily )
1584 UpdateFamily_Impl();
1587 if( pStyleSheetPool )
1589 String aStr = GetSelectedEntry();
1590 if( aStr.Len() && pStyleSheetPool )
1592 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1593 if( !pItem ) break;
1594 const SfxStyleFamily eFam = pItem->GetFamily();
1595 SfxStyleSheetBase *pStyle =
1596 pStyleSheetPool->Find(
1597 aStr, eFam, SFXSTYLEBIT_ALL );
1598 if( pStyle )
1599 EnableEdit(
1600 !(pStyle->GetMask() & SFXSTYLEBIT_READONLY) );
1601 else
1602 EnableEdit(sal_False);
1605 break;
1608 // Necessary if switching between documents and in both documents
1609 // the same template is used. Do not immediately call Update_Impl,
1610 // for the case that one of the documents is an internal InPlaceObjekt!
1611 case SFX_HINT_DOCCHANGED:
1612 bUpdate = sal_True;
1613 break;
1614 case SFX_HINT_DYING:
1616 EndListening(*pStyleSheetPool);
1617 pStyleSheetPool=0;
1618 break;
1623 // Do not set timer when the stylesheet pool is in the box, because it is
1624 // possible that a new one is registered after the timer is up -
1625 // works bad in UpdateStyles_Impl ()!
1627 sal_uIntPtr nId = rHint.ISA(SfxSimpleHint) ? ( (SfxSimpleHint&)rHint ).GetId() : 0;
1629 if(!bDontUpdate && nId != SFX_HINT_DYING &&
1630 (rHint.Type() == TYPE(SfxStyleSheetPoolHint)||
1631 rHint.Type() == TYPE(SfxStyleSheetHint) ||
1632 rHint.Type() == TYPE( SfxStyleSheetHintExtended )))
1634 if(!pTimer)
1636 pTimer=new Timer;
1637 pTimer->SetTimeout(500);
1638 pTimer->SetTimeoutHdl(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut));
1640 pTimer->Start();
1646 //-------------------------------------------------------------------------
1648 // Other filters; can be switched by the users or as a result of new or
1649 // editing, if the current document has been assigned a different filter.
1650 void SfxCommonTemplateDialog_Impl::FilterSelect(
1651 sal_uInt16 nEntry, // Idx of the new Filters
1652 sal_Bool bForce ) // Force update, even if the new filter is
1653 // equal to the current
1655 if( nEntry != nActFilter || bForce )
1657 nActFilter = nEntry;
1658 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1659 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
1660 if (pDocShell)
1662 pDocShell->SetAutoStyleFilterIndex(nActFilter);
1663 SaveFactoryStyleFilter( pDocShell, nActFilter );
1666 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
1667 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
1668 if ( pOldStyleSheetPool != pStyleSheetPool )
1670 if ( pOldStyleSheetPool )
1671 EndListening(*pOldStyleSheetPool);
1672 if ( pStyleSheetPool )
1673 StartListening(*pOldStyleSheetPool);
1676 UpdateStyles_Impl(UPDATE_FAMILY_LIST);
1680 //-------------------------------------------------------------------------
1682 // Internal: Perform functions through the Dispatcher
1683 sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl(
1684 sal_uInt16 nId, const String &rStr, const String& rRefStr, sal_uInt16 nFamily,
1685 sal_uInt16 nMask, sal_uInt16 *pIdx, const sal_uInt16* pModifier)
1687 SfxDispatcher &rDispatcher = *SFX_APP()->GetDispatcher_Impl();
1688 SfxStringItem aItem(nId, rStr);
1689 SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
1690 SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
1691 SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
1692 SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
1693 const SfxPoolItem* pItems[ 6 ];
1694 sal_uInt16 nCount = 0;
1695 if( rStr.Len() )
1696 pItems[ nCount++ ] = &aItem;
1697 pItems[ nCount++ ] = &aFamily;
1698 if( nMask )
1699 pItems[ nCount++ ] = &aMask;
1700 if(SID_STYLE_UPDATE_BY_EXAMPLE == nId)
1702 // Special solution for Numbering update in Writer
1703 const String aTemplName(GetSelectedEntry());
1704 aUpdName.SetValue(aTemplName);
1705 pItems[ nCount++ ] = &aUpdName;
1707 if ( rRefStr.Len() )
1708 pItems[ nCount++ ] = &aRefName;
1710 pItems[ nCount++ ] = 0;
1712 DeletionWatcher aDeleted(*this);
1713 sal_uInt16 nModi = pModifier ? *pModifier : 0;
1714 const SfxPoolItem* pItem = rDispatcher.Execute(
1715 nId, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
1716 pItems, nModi );
1718 // Dialog can be destroyed while in Execute() because started
1719 // subdialogs are not modal to it (#i97888#).
1720 if ( !pItem || aDeleted )
1721 return sal_False;
1723 if ( nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId )
1725 SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem);
1726 OSL_ENSURE(pFilterItem, "SfxUINT16Item expected");
1727 sal_uInt16 nFilterFlags = pFilterItem->GetValue() & ~SFXSTYLEBIT_USERDEF;
1728 if(!nFilterFlags) // User Template?
1729 nFilterFlags = pFilterItem->GetValue();
1730 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
1731 const size_t nFilterCount = pFamilyItem->GetFilterList().size();
1733 for ( size_t i = 0; i < nFilterCount; ++i )
1735 const SfxFilterTupel *pTupel = pFamilyItem->GetFilterList()[ i ];
1737 if ( ( pTupel->nFlags & nFilterFlags ) == nFilterFlags && pIdx )
1738 *pIdx = i;
1742 return sal_True;
1745 //-------------------------------------------------------------------------
1747 // Handler der Listbox der Filter
1748 IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox )
1750 if ( pBox->GetSelectEntry() == String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)) )
1752 if ( !bHierarchical )
1754 // Turn on treeView
1755 bHierarchical=sal_True;
1756 const String aSelectEntry( GetSelectedEntry());
1757 aFmtLb.Hide();
1759 pTreeBox = new StyleTreeListBox_Impl(
1760 this, WB_HASBUTTONS | WB_HASLINES |
1761 WB_BORDER | WB_TABSTOP | WB_HASLINESATROOT |
1762 WB_HASBUTTONSATROOT | WB_HIDESELECTION | WB_QUICK_SEARCH );
1763 pTreeBox->SetFont( aFmtLb.GetFont() );
1765 pTreeBox->SetPosSizePixel(aFmtLb.GetPosPixel(), aFmtLb.GetSizePixel());
1766 pTreeBox->SetNodeDefaultImages();
1767 pTreeBox->SetSelectHdl(
1768 LINK(this, SfxCommonTemplateDialog_Impl, FmtSelectHdl));
1769 ((StyleTreeListBox_Impl*)pTreeBox)->
1770 SetDoubleClickHdl(
1771 LINK(this, SfxCommonTemplateDialog_Impl, ApplyHdl));
1772 ((StyleTreeListBox_Impl*)pTreeBox)->
1773 SetDropHdl(LINK(this, SfxCommonTemplateDialog_Impl, DropHdl));
1774 pTreeBox->SetIndent(10);
1775 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
1776 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
1777 if (pDocShell)
1778 SaveFactoryStyleFilter( pDocShell, HIERARCHICAL_FILTER_INDEX );
1779 FillTreeBox();
1780 SelectStyle(aSelectEntry);
1781 pTreeBox->SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST));
1782 pTreeBox->Show();
1786 else
1788 DELETEZ(pTreeBox);
1789 aFmtLb.Show();
1790 // If bHierarchical, then the family can have changed
1791 // minus one since hierarchical is inserted at the start
1792 FilterSelect(pBox->GetSelectEntryPos() - 1, bHierarchical );
1793 bHierarchical=sal_False;
1796 return 0;
1799 //-------------------------------------------------------------------------
1801 // Select-Handler for the Toolbox
1802 void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry)
1804 if( nEntry != nActFamily )
1806 CheckItem( nActFamily, sal_False );
1807 nActFamily = nEntry;
1808 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
1809 SfxUInt16Item aItem( SID_STYLE_FAMILY, nEntry );
1810 pDispat->Execute( SID_STYLE_FAMILY, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
1811 pBindings->Invalidate( SID_STYLE_FAMILY );
1812 pBindings->Update( SID_STYLE_FAMILY );
1813 UpdateFamily_Impl();
1817 //-------------------------------------------------------------------------
1819 void SfxCommonTemplateDialog_Impl::ActionSelect(sal_uInt16 nEntry)
1821 String aEmpty;
1822 switch(nEntry)
1824 case SID_STYLE_WATERCAN:
1826 const sal_Bool bState = IsCheckedItem(nEntry);
1827 sal_Bool bCheck;
1828 SfxBoolItem aBool;
1829 // when a template is chosen.
1830 if(!bState && aFmtLb.GetSelectionCount())
1832 const String aTemplName(
1833 GetSelectedEntry());
1834 Execute_Impl(
1835 SID_STYLE_WATERCAN, aTemplName, aEmpty,
1836 (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
1837 bCheck = sal_True;
1839 else
1841 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
1842 bCheck = sal_False;
1844 CheckItem(nEntry, bCheck);
1845 aBool.SetValue(bCheck);
1846 SetWaterCanState(&aBool);
1847 break;
1849 case SID_STYLE_NEW_BY_EXAMPLE:
1851 if(pStyleSheetPool && nActFamily != 0xffff)
1853 const SfxStyleFamily eFam=GetFamilyItem_Impl()->GetFamily();
1854 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1855 sal_uInt16 nFilter;
1856 if( pItem && nActFilter != 0xffff )
1858 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
1859 if(!nFilter) // automatisch
1860 nFilter = nAppFilter;
1862 else
1863 nFilter=pStyleSheetPool->GetSearchMask();
1864 pStyleSheetPool->SetSearchMask( eFam, SFXSTYLEBIT_USERDEF );
1866 SfxNewStyleDlg *pDlg = new SfxNewStyleDlg(pWindow, *pStyleSheetPool);
1867 // why? : FloatingWindow must not be parent of a modal dialog
1868 if(RET_OK == pDlg->Execute())
1870 pStyleSheetPool->SetSearchMask(eFam, nFilter);
1871 const String aTemplName(pDlg->GetName());
1872 Execute_Impl(SID_STYLE_NEW_BY_EXAMPLE,
1873 aTemplName, aEmpty,
1874 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(),
1875 nFilter);
1877 pStyleSheetPool->SetSearchMask( eFam, nFilter );
1878 delete pDlg;
1880 break;
1882 case SID_STYLE_UPDATE_BY_EXAMPLE:
1884 Execute_Impl(SID_STYLE_UPDATE_BY_EXAMPLE,
1885 aEmpty, aEmpty,
1886 (sal_uInt16)GetFamilyItem_Impl()->GetFamily());
1887 break;
1889 case SID_TEMPLATE_LOAD:
1890 SFX_APP()->GetDispatcher_Impl()->Execute(nEntry);
1891 break;
1892 default: OSL_FAIL("not implemented"); break;
1896 //-------------------------------------------------------------------------
1898 static rtl::OUString getModuleIdentifier( const Reference< XModuleManager >& i_xModMgr, SfxObjectShell* i_pObjSh )
1900 OSL_ENSURE( i_xModMgr.is(), "getModuleIdentifier(): no XModuleManager" );
1901 OSL_ENSURE( i_pObjSh, "getModuleIdentifier(): no ObjectShell" );
1903 ::rtl::OUString sIdentifier;
1907 sIdentifier = i_xModMgr->identify( i_pObjSh->GetModel() );
1909 catch ( ::com::sun::star::frame::UnknownModuleException& )
1911 OSL_TRACE( "getModuleIdentifier(): unknown module" );
1913 catch ( Exception& )
1915 OSL_FAIL( "getModuleIdentifier(): exception of XModuleManager::identify()" );
1918 return sIdentifier;
1921 //-------------------------------------------------------------------------
1923 sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh )
1925 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
1926 sal_Int32 nFilter = -1;
1928 Sequence< PropertyValue > lProps;
1929 Reference< ::com::sun::star::container::XNameAccess > xContainer( xModuleManager, UNO_QUERY );
1930 if ( xContainer.is() )
1932 ::comphelper::SequenceAsHashMap aFactoryProps(
1933 xContainer->getByName( getModuleIdentifier( xModuleManager, i_pObjSh ) ) );
1934 sal_Int32 nDefault = -1;
1935 nFilter = aFactoryProps.getUnpackedValueOrDefault( DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter"), nDefault );
1938 return nFilter;
1941 //-------------------------------------------------------------------------
1943 void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter )
1945 OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" );
1946 Reference< ::com::sun::star::container::XNameReplace > xContainer( xModuleManager, UNO_QUERY );
1947 if ( xContainer.is() )
1949 Sequence< PropertyValue > lProps(1);
1950 lProps[0].Name = DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter");
1951 lProps[0].Value = makeAny( i_nFilter );;
1952 xContainer->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) );
1956 //-------------------------------------------------------------------------
1958 IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox )
1960 bDontUpdate=sal_True;
1961 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1962 const SfxStyleFamily eFam = pItem->GetFamily();
1963 long ret= pStyleSheetPool->SetParent(eFam,pBox->GetStyle(), pBox->GetParent())? 1L: 0L;
1964 bDontUpdate=sal_False;
1965 return ret;
1968 //-------------------------------------------------------------------------
1970 // Handler for the New-Buttons
1971 void SfxCommonTemplateDialog_Impl::NewHdl(void *)
1973 String aEmpty;
1974 if ( nActFamily != 0xffff )
1976 Window* pTmp;
1977 pTmp = Application::GetDefDialogParent();
1978 if ( ISA(SfxTemplateDialog_Impl) )
1979 Application::SetDefDialogParent( pWindow->GetParent() );
1980 else
1981 Application::SetDefDialogParent( pWindow );
1983 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
1984 const SfxStyleFamily eFam=pItem->GetFamily();
1985 sal_uInt16 nMask;
1986 if( pItem && nActFilter != 0xffff )
1988 nMask = pItem->GetFilterList()[ nActFilter ]->nFlags;
1989 if(!nMask) // automatic
1990 nMask = nAppFilter;
1992 else
1993 nMask=pStyleSheetPool->GetSearchMask();
1995 pStyleSheetPool->SetSearchMask(eFam,nMask);
1997 Execute_Impl(SID_STYLE_NEW,
1998 aEmpty, GetSelectedEntry(),
1999 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2000 nMask);
2002 Application::SetDefDialogParent( pTmp );
2006 //-------------------------------------------------------------------------
2008 // Handler for the edit-Buttons
2009 void SfxCommonTemplateDialog_Impl::EditHdl(void *)
2011 if(IsInitialized() && HasSelectedStyle())
2013 sal_uInt16 nFilter = nActFilter;
2014 String aTemplName(GetSelectedEntry());
2015 GetSelectedStyle(); // -Wall required??
2016 Window* pTmp;
2017 //DefModalDialogParent set for modality of the following dialogs
2018 pTmp = Application::GetDefDialogParent();
2019 if ( ISA(SfxTemplateDialog_Impl) )
2020 Application::SetDefDialogParent( pWindow->GetParent() );
2021 else
2022 Application::SetDefDialogParent( pWindow );
2023 if ( Execute_Impl( SID_STYLE_EDIT, aTemplName, String(),
2024 (sal_uInt16)GetFamilyItem_Impl()->GetFamily(), 0, &nFilter ) )
2027 Application::SetDefDialogParent( pTmp );
2031 //-------------------------------------------------------------------------
2033 // Handler for the Delete-Buttons
2034 void SfxCommonTemplateDialog_Impl::DeleteHdl(void *)
2036 if ( IsInitialized() && HasSelectedStyle() )
2038 const String aTemplName( GetSelectedEntry() );
2039 SfxStyleSheetBase* pStyle = GetSelectedStyle();
2040 if ( pStyle )
2042 String aMsg;
2043 if ( pStyle->IsUsed() )
2044 aMsg = String( SfxResId( STR_DELETE_STYLE_USED ) );
2045 aMsg += String ( SfxResId( STR_DELETE_STYLE ) );
2046 aMsg.SearchAndReplaceAscii( "$1", aTemplName );
2047 #if defined UNX
2048 QueryBox aBox( SFX_APP()->GetTopWindow(), WB_YES_NO | WB_DEF_NO, aMsg );
2049 #else
2050 QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , aMsg );
2051 #endif
2052 if ( RET_YES == aBox.Execute() )
2054 PrepareDeleteAction();
2056 if ( pTreeBox ) // To prevent the Treelistbox to shut down while
2057 // deleting.
2059 bDontUpdate = sal_True;
2061 Execute_Impl( SID_STYLE_DELETE, aTemplName,
2062 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2064 if ( pTreeBox )
2066 pTreeBox->RemoveParentKeepChildren( pTreeBox->FirstSelected() );
2067 bDontUpdate = sal_False;
2074 //-------------------------------------------------------------------------
2076 void SfxCommonTemplateDialog_Impl::EnableDelete()
2078 if(IsInitialized() && HasSelectedStyle())
2080 OSL_ENSURE(pStyleSheetPool, "No StyleSheetPool");
2081 const String aTemplName(GetSelectedEntry());
2082 const SfxStyleFamilyItem *pItem = GetFamilyItem_Impl();
2083 const SfxStyleFamily eFam = pItem->GetFamily();
2084 sal_uInt16 nFilter = 0;
2085 if(pItem->GetFilterList().size() > nActFilter)
2086 nFilter = pItem->GetFilterList()[ nActFilter ]->nFlags;
2087 if(!nFilter) // automatic
2088 nFilter = nAppFilter;
2089 const SfxStyleSheetBase *pStyle =
2090 pStyleSheetPool->Find(aTemplName,eFam, pTreeBox? SFXSTYLEBIT_ALL: nFilter);
2092 OSL_ENSURE(pStyle, "Style ot found");
2093 if(pStyle && pStyle->IsUserDefined())
2095 EnableDel(sal_True);
2097 else
2099 EnableDel(sal_False);
2102 else
2104 EnableDel(sal_False);
2108 //-------------------------------------------------------------------------
2109 // After selecting a focused item if possible again on the app window
2110 void SfxCommonTemplateDialog_Impl::ResetFocus()
2112 if(ISA(SfxTemplateDialog_Impl))
2114 SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
2115 SfxViewShell *pVu = pViewFrame->GetViewShell();
2116 Window *pAppWin = pVu ? pVu->GetWindow(): 0;
2117 if(pAppWin)
2118 pAppWin->GrabFocus();
2122 //-------------------------------------------------------------------------
2124 // Doppelclick on a style sheet in the ListBox is applied.
2125 IMPL_LINK( SfxCommonTemplateDialog_Impl, ApplyHdl, Control *, pControl )
2127 (void)pControl; //unused
2128 // only if that region is allowed
2129 if ( IsInitialized() && 0 != pFamilyState[nActFamily-1] &&
2130 GetSelectedEntry().Len() )
2132 sal_uInt16 nModifier = aFmtLb.GetModifier();
2133 Execute_Impl(SID_STYLE_APPLY,
2134 GetSelectedEntry(), String(),
2135 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily(),
2136 0, 0, &nModifier );
2137 if(ISA(SfxTemplateCatalog_Impl))
2138 ((SfxTemplateCatalog_Impl*) this)->pReal->EndDialog(RET_OK);
2140 ResetFocus();
2141 return 0;
2144 //-------------------------------------------------------------------------
2146 // Selection of a template during the Watercan-Status
2147 IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox )
2149 // Trigger Help PI, if this is permitted of call handlers and field
2150 if( !pListBox || pListBox->IsSelected( pListBox->GetHdlEntry() ) )
2152 // Only when the watercan is on
2153 if ( IsInitialized() &&
2154 IsCheckedItem(SID_STYLE_WATERCAN) &&
2155 // only if that region is allowed
2156 0 != pFamilyState[nActFamily-1] )
2158 String aEmpty;
2159 Execute_Impl(SID_STYLE_WATERCAN,
2160 aEmpty, aEmpty, 0);
2161 Execute_Impl(SID_STYLE_WATERCAN,
2162 GetSelectedEntry(), aEmpty,
2163 ( sal_uInt16 )GetFamilyItem_Impl()->GetFamily());
2165 EnableItem(SID_STYLE_WATERCAN, !bWaterDisabled);
2166 EnableDelete();
2168 if( pListBox )
2169 SelectStyle( pListBox->GetEntryText( pListBox->GetHdlEntry() ));
2171 return 0;
2174 //-------------------------------------------------------------------------
2176 IMPL_LINK( SfxCommonTemplateDialog_Impl, MenuSelectHdl, Menu *, pMenu )
2178 if( pMenu )
2180 nLastItemId = pMenu->GetCurItemId();
2181 Application::PostUserEvent(
2182 LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ), 0 );
2183 return sal_True;
2186 switch(nLastItemId) {
2187 case ID_NEW: NewHdl(0); break;
2188 case ID_EDIT: EditHdl(0); break;
2189 case ID_DELETE: DeleteHdl(0); break;
2190 default: return sal_False;
2192 return sal_True;
2195 // -----------------------------------------------------------------------
2197 void SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl( const Point& rPos, Window* pWin )
2199 // Bug# 94152: This part should never be called, because before this happens, the TreeListBox should captured this!
2200 OSL_FAIL( "+SfxCommonTemplateDialog_Impl::ExecuteContextMenu_Impl(): How could this happen? Please infirm developer ASAP!" );
2202 PopupMenu* pMenu = CreateContextMenu();
2203 pMenu->Execute( pWin, rPos );
2204 delete pMenu;
2207 // -----------------------------------------------------------------------
2209 SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const
2211 const SfxStyleFamilyItem *pFamilyItem = GetFamilyItem_Impl();
2212 if( !pFamilyItem || nActFamily == 0xffff )
2213 return SFX_STYLE_FAMILY_PARA;
2214 else
2215 return pFamilyItem->GetFamily();
2218 // -----------------------------------------------------------------------
2220 void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, sal_Bool bEnable)
2222 if( nId == SID_STYLE_NEW_BY_EXAMPLE )
2223 bNewByExampleDisabled = !bEnable;
2224 else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE )
2225 bUpdateByExampleDisabled = !bEnable;
2226 EnableItem(nId, bEnable);
2229 void SfxCommonTemplateDialog_Impl::PrepareDeleteAction()
2233 // -----------------------------------------------------------------------
2235 PopupMenu* SfxCommonTemplateDialog_Impl::CreateContextMenu( void )
2237 if ( bBindingUpdate )
2239 pBindings->Invalidate( SID_STYLE_NEW, sal_True, sal_False );
2240 pBindings->Update( SID_STYLE_NEW );
2241 bBindingUpdate = sal_False;
2243 PopupMenu* pMenu = new PopupMenu( SfxResId( MN_CONTEXT_TEMPLDLG ) );
2244 pMenu->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, MenuSelectHdl ) );
2245 pMenu->EnableItem( ID_EDIT, bCanEdit );
2246 pMenu->EnableItem( ID_DELETE, bCanDel );
2247 pMenu->EnableItem( ID_NEW, bCanNew );
2249 return pMenu;
2252 // ------------------------------------------------------------------------
2254 SfxTemplateDialog_Impl::SfxTemplateDialog_Impl(
2255 Window* /*pParent*/, SfxBindings* pB, SfxTemplateDialog* pDlgWindow ) :
2257 SfxCommonTemplateDialog_Impl( pB, pDlgWindow ),
2259 m_pFloat ( pDlgWindow ),
2260 m_bZoomIn ( sal_False ),
2261 m_aActionTbL ( pDlgWindow, this ),
2262 m_aActionTbR ( pDlgWindow, SfxResId( TB_ACTION ) )
2265 pDlgWindow->FreeResource();
2266 SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
2267 pCurObjShell = pViewFrame->GetObjectShell();
2268 sal_uInt16 nSavedFilter = static_cast< sal_uInt16 >( LoadFactoryStyleFilter( pCurObjShell ) );
2269 Initialize();
2271 m_aActionTbL.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxLSelect));
2272 m_aActionTbR.SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRSelect));
2273 m_aActionTbR.SetDropdownClickHdl(LINK(this, SfxTemplateDialog_Impl, ToolBoxRClick));
2274 m_aActionTbL.Show();
2275 m_aActionTbR.Show();
2276 Font aFont=aFilterLb.GetFont();
2277 aFont.SetWeight( WEIGHT_NORMAL );
2278 aFilterLb.SetFont( aFont );
2279 m_aActionTbL.SetHelpId( HID_TEMPLDLG_TOOLBOX_LEFT );
2280 if( nSavedFilter == HIERARCHICAL_FILTER_INDEX )
2282 bHierarchical = sal_False; // Force content refresh
2283 aFilterLb.SelectEntry(String(SfxResId(STR_STYLE_FILTER_HIERARCHICAL)));
2284 FilterSelectHdl(&aFilterLb);
2288 // ------------------------------------------------------------------------
2290 void SfxTemplateDialog_Impl::EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnable )
2292 m_aActionTbL.EnableItem( nId, bEnable );
2295 //-------------------------------------------------------------------------
2296 // Insert element into dropdown filter "Frame Styles", "List Styles", etc.
2298 void SfxTemplateDialog_Impl::InsertFamilyItem(sal_uInt16 nId,const SfxStyleFamilyItem *pItem)
2300 rtl::OString sHelpId;
2301 switch( (sal_uInt16) pItem->GetFamily() )
2303 case SFX_STYLE_FAMILY_CHAR: sHelpId = ".uno:CharStyle"; break;
2304 case SFX_STYLE_FAMILY_PARA: sHelpId = ".uno:ParaStyle"; break;
2305 case SFX_STYLE_FAMILY_FRAME: sHelpId = ".uno:FrameStyle"; break;
2306 case SFX_STYLE_FAMILY_PAGE: sHelpId = ".uno:PageStyle"; break;
2307 case SFX_STYLE_FAMILY_PSEUDO: sHelpId = ".uno:ListStyle"; break;
2308 default: OSL_FAIL("unknown StyleFamily"); break;
2310 m_aActionTbL.InsertItem( nId, pItem->GetImage(), pItem->GetText(), 0, 0);
2311 m_aActionTbL.SetHelpId( nId, sHelpId );
2314 // ------------------------------------------------------------------------
2316 void SfxTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2318 m_aActionTbR.HideItem(SID_STYLE_UPDATE_BY_EXAMPLE);
2319 m_aActionTbR.SetItemBits( SID_STYLE_NEW_BY_EXAMPLE,
2320 TIB_DROPDOWNONLY|m_aActionTbR.GetItemBits( SID_STYLE_NEW_BY_EXAMPLE ));
2323 // ------------------------------------------------------------------------
2324 void SfxTemplateDialog_Impl::updateFamilyImages()
2326 if ( !m_pStyleFamiliesId )
2327 // we do not have a resource id to load the new images from
2328 return;
2330 // let the families collection update the images
2331 pStyleFamilies->updateImages( *m_pStyleFamiliesId );
2333 // and set the new images on our toolbox
2334 size_t nLoop = pStyleFamilies->size();
2335 for( ; nLoop--; )
2337 const SfxStyleFamilyItem *pItem = pStyleFamilies->at( nLoop );
2338 sal_uInt16 nId = SfxFamilyIdToNId( pItem->GetFamily() );
2339 m_aActionTbL.SetItemImage( nId, pItem->GetImage() );
2343 // ------------------------------------------------------------------------
2344 void SfxTemplateDialog_Impl::updateNonFamilyImages()
2346 m_aActionTbR.SetImageList( ImageList( SfxResId( DLG_STYLE_DESIGNER ) ) );
2349 // ------------------------------------------------------------------------
2351 void SfxTemplateDialog_Impl::ClearFamilyList()
2353 m_aActionTbL.Clear();
2356 //-------------------------------------------------------------------------
2358 void SfxCommonTemplateDialog_Impl::InvalidateBindings()
2360 pBindings->Invalidate(SID_STYLE_NEW_BY_EXAMPLE, sal_True, sal_False);
2361 pBindings->Update( SID_STYLE_NEW_BY_EXAMPLE );
2362 pBindings->Invalidate(SID_STYLE_UPDATE_BY_EXAMPLE, sal_True, sal_False);
2363 pBindings->Update( SID_STYLE_UPDATE_BY_EXAMPLE );
2364 pBindings->Invalidate( SID_STYLE_WATERCAN, sal_True, sal_False);
2365 pBindings->Update( SID_STYLE_WATERCAN );
2366 pBindings->Invalidate( SID_STYLE_NEW, sal_True, sal_False );
2367 pBindings->Update( SID_STYLE_NEW );
2368 pBindings->Invalidate( SID_STYLE_DRAGHIERARCHIE, sal_True, sal_False );
2369 pBindings->Update( SID_STYLE_DRAGHIERARCHIE );
2372 //-------------------------------------------------------------------------
2374 SfxTemplateDialog_Impl::~SfxTemplateDialog_Impl()
2378 //-------------------------------------------------------------------------
2380 void SfxTemplateDialog_Impl::LoadedFamilies()
2382 updateFamilyImages();
2383 Resize();
2386 //-------------------------------------------------------------------------
2388 // Overloaded Resize-Handler ( StarView )
2389 // The size of the Listboxen is adjusted
2390 void SfxTemplateDialog_Impl::Resize()
2392 FloatingWindow *pF = m_pFloat->GetFloatingWindow();
2393 if ( pF )
2395 m_bZoomIn = pF->IsRollUp();
2396 if ( m_bZoomIn )
2397 return;
2400 Size aDlgSize=m_pFloat->PixelToLogic(m_pFloat->GetOutputSizePixel());
2401 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
2402 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
2403 Size aMinSize = GetMinOutputSizePixel();
2405 long nListHeight = m_pFloat->PixelToLogic( aFilterLb.GetSizePixel() ).Height();
2406 long nWidth = aDlgSize.Width()- 2 * SFX_TEMPLDLG_HFRAME;
2408 m_aActionTbL.SetPosSizePixel(m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,SFX_TEMPLDLG_VTOPFRAME)),
2409 m_pFloat->LogicToPixel(aSizeATL));
2411 // only change the position of the right toolbox, when the window is wide
2412 // enough
2413 Point aPosATR(aDlgSize.Width()-SFX_TEMPLDLG_HFRAME-aSizeATR.Width(),SFX_TEMPLDLG_VTOPFRAME);
2414 if(aDlgSize.Width() >= aMinSize.Width())
2415 m_aActionTbR.SetPosPixel(m_pFloat->LogicToPixel(aPosATR));
2416 else
2417 m_aActionTbR.SetPosPixel( m_pFloat->LogicToPixel(
2418 Point( SFX_TEMPLDLG_HFRAME + aSizeATL.Width() + SFX_TEMPLDLG_MIDHSPACE,
2419 SFX_TEMPLDLG_VTOPFRAME ) ) );
2421 m_aActionTbR.SetSizePixel(m_pFloat->LogicToPixel(aSizeATR));
2423 Point aFilterPos(
2424 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME,
2425 aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-nListHeight)) );
2427 Size aFilterSize(
2428 m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) );
2430 Point aFmtPos(
2431 m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME +
2432 SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) );
2433 Size aFmtSize(
2434 m_pFloat->LogicToPixel(Size(nWidth,
2435 aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME -
2436 SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE-
2437 nListHeight-aSizeATL.Height())) );
2439 // only change the position of the listbox, when the window is high enough
2440 if(aDlgSize.Height() >= aMinSize.Height())
2442 aFilterLb.SetPosPixel(aFilterPos);
2443 aFmtLb.SetPosPixel( aFmtPos );
2444 if(pTreeBox)
2445 pTreeBox->SetPosPixel(aFmtPos);
2447 else
2448 aFmtSize.Height() += aFilterSize.Height();
2450 aFilterLb.SetSizePixel(aFilterSize);
2451 aFmtLb.SetSizePixel( aFmtSize );
2452 if(pTreeBox)
2453 pTreeBox->SetSizePixel(aFmtSize);
2456 // -----------------------------------------------------------------------
2459 Size SfxTemplateDialog_Impl::GetMinOutputSizePixel()
2461 Size aSizeATL=m_pFloat->PixelToLogic(m_aActionTbL.CalcWindowSizePixel());
2462 Size aSizeATR=m_pFloat->PixelToLogic(m_aActionTbR.CalcWindowSizePixel());
2463 Size aMinSize=Size(
2464 aSizeATL.Width()+aSizeATR.Width()+
2465 2*SFX_TEMPLDLG_HFRAME + SFX_TEMPLDLG_MIDHSPACE,
2466 4*aSizeATL.Height()+2*SFX_TEMPLDLG_MIDVSPACE);
2467 return aMinSize;
2470 //-------------------------------------------------------------------------
2472 void SfxTemplateDialog_Impl::Command( const CommandEvent& rCEvt )
2474 if(COMMAND_CONTEXTMENU == rCEvt.GetCommand())
2475 ExecuteContextMenu_Impl( rCEvt.GetMousePosPixel(), m_pFloat );
2476 else
2477 m_pFloat->Command(rCEvt);
2480 //-------------------------------------------------------------------------
2482 void SfxTemplateDialog_Impl::EnableItem(sal_uInt16 nMesId, sal_Bool bCheck)
2484 String aEmpty;
2485 switch(nMesId)
2487 case SID_STYLE_WATERCAN :
2488 if(!bCheck && IsCheckedItem(SID_STYLE_WATERCAN))
2489 Execute_Impl(SID_STYLE_WATERCAN, aEmpty, aEmpty, 0);
2490 case SID_STYLE_NEW_BY_EXAMPLE:
2491 case SID_STYLE_UPDATE_BY_EXAMPLE:
2492 m_aActionTbR.EnableItem(nMesId,bCheck);
2493 break;
2497 //-------------------------------------------------------------------------
2499 void SfxTemplateDialog_Impl::CheckItem(sal_uInt16 nMesId, sal_Bool bCheck)
2501 switch(nMesId)
2503 case SID_STYLE_WATERCAN :
2504 bIsWater=bCheck;
2505 m_aActionTbR.CheckItem(SID_STYLE_WATERCAN,bCheck);
2506 break;
2507 default:
2508 m_aActionTbL.CheckItem(nMesId,bCheck); break;
2512 //-------------------------------------------------------------------------
2514 sal_Bool SfxTemplateDialog_Impl::IsCheckedItem(sal_uInt16 nMesId)
2516 switch(nMesId)
2518 case SID_STYLE_WATERCAN :
2519 return m_aActionTbR.GetItemState(SID_STYLE_WATERCAN)==STATE_CHECK;
2520 default:
2521 return m_aActionTbL.GetItemState(nMesId)==STATE_CHECK;
2525 //-------------------------------------------------------------------------
2527 IMPL_LINK_INLINE_START( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
2529 const sal_uInt16 nEntry = pBox->GetCurItemId();
2530 FamilySelect(nEntry);
2531 return 0;
2533 IMPL_LINK_INLINE_END( SfxTemplateDialog_Impl, ToolBoxLSelect, ToolBox *, pBox )
2535 //-------------------------------------------------------------------------
2536 ::rtl::OUString lcl_GetLabel(uno::Any& rAny)
2538 ::rtl::OUString sRet;
2539 uno::Sequence< beans::PropertyValue >aPropSeq;
2540 if ( rAny >>= aPropSeq )
2542 for( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
2544 if ( aPropSeq[i].Name == "Label" )
2546 aPropSeq[i].Value >>= sRet;
2547 break;
2551 return sRet;
2553 //-------------------------------------------------------------------------
2555 IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRSelect, ToolBox *, pBox )
2557 const sal_uInt16 nEntry = pBox->GetCurItemId();
2558 if(nEntry != SID_STYLE_NEW_BY_EXAMPLE ||
2559 TIB_DROPDOWN != (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
2560 ActionSelect(nEntry);
2561 return 0;
2563 //-------------------------------------------------------------------------
2564 IMPL_LINK( SfxTemplateDialog_Impl, ToolBoxRClick, ToolBox *, pBox )
2566 const sal_uInt16 nEntry = pBox->GetCurItemId();
2567 if(nEntry == SID_STYLE_NEW_BY_EXAMPLE &&
2568 TIB_DROPDOWN == (pBox->GetItemBits(nEntry)&TIB_DROPDOWN))
2570 //create a popup menu in Writer
2571 boost::scoped_ptr<PopupMenu> pMenu(new PopupMenu);
2572 uno::Reference< container::XNameAccess > xNameAccess(
2573 ::comphelper::getProcessServiceFactory()->
2574 createInstance( ::rtl::OUString(
2575 "com.sun.star.frame.UICommandDescription") ), uno::UNO_QUERY );
2576 uno::Reference< container::XNameAccess > xUICommands;
2577 if ( xNameAccess.is() )
2579 rtl::OUString sTextDoc("com.sun.star.text.TextDocument");
2580 if(xNameAccess->hasByName(sTextDoc))
2582 uno::Any a = xNameAccess->getByName( sTextDoc );
2583 a >>= xUICommands;
2586 if(!xUICommands.is())
2587 return 0;
2590 uno::Sequence< beans::PropertyValue > aPropSeq;
2591 uno::Any aCommand = xUICommands->getByName(::rtl::OUString(".uno:StyleNewByExample"));
2592 ::rtl::OUString sLabel = lcl_GetLabel( aCommand );
2593 pMenu->InsertItem( SID_STYLE_NEW_BY_EXAMPLE, sLabel );
2594 pMenu->SetHelpId(SID_STYLE_NEW_BY_EXAMPLE, HID_TEMPLDLG_NEWBYEXAMPLE);
2596 aCommand = xUICommands->getByName(::rtl::OUString(".uno:StyleUpdateByExample"));
2597 sLabel = lcl_GetLabel( aCommand );
2599 pMenu->InsertItem( SID_STYLE_UPDATE_BY_EXAMPLE, sLabel );
2600 pMenu->SetHelpId(SID_STYLE_UPDATE_BY_EXAMPLE, HID_TEMPLDLG_UPDATEBYEXAMPLE);
2602 aCommand = xUICommands->getByName(::rtl::OUString(".uno:LoadStyles"));
2603 sLabel = lcl_GetLabel( aCommand );
2604 pMenu->InsertItem( SID_TEMPLATE_LOAD, sLabel );
2605 pMenu->SetHelpId(SID_TEMPLATE_LOAD, ".uno:LoadStyles");
2607 pMenu->SetSelectHdl(LINK(this, SfxTemplateDialog_Impl, MenuSelectHdl));
2608 pMenu->Execute( pBox,
2609 pBox->GetItemRect(nEntry),
2610 POPUPMENU_EXECUTE_DOWN );
2611 pBox->EndSelection();
2613 catch(uno::Exception&)
2616 pBox->Invalidate();
2618 return 0;
2620 //-------------------------------------------------------------------------
2621 IMPL_LINK( SfxTemplateDialog_Impl, MenuSelectHdl, Menu*, pMenu)
2623 sal_uInt16 nMenuId = pMenu->GetCurItemId();
2624 ActionSelect(nMenuId);
2625 return 0;
2627 //-------------------------------------------------------------------------
2629 SfxTemplateCatalog_Impl::SfxTemplateCatalog_Impl( Window* /*pParent*/, SfxBindings* pB,
2630 SfxTemplateCatalog* pTmpWindow ) :
2632 SfxCommonTemplateDialog_Impl( pB, pTmpWindow ),
2634 aFamList ( pTmpWindow, SfxResId( BT_TOOL ) ),
2635 aOkBtn ( pTmpWindow, SfxResId( BT_OK ) ),
2636 aCancelBtn ( pTmpWindow, SfxResId( BT_CANCEL ) ),
2637 aNewBtn ( pTmpWindow, SfxResId( BT_NEW ) ),
2638 aChangeBtn ( pTmpWindow, SfxResId( BT_EDIT ) ),
2639 aDelBtn ( pTmpWindow, SfxResId( BT_DEL ) ),
2640 aOrgBtn ( pTmpWindow, SfxResId( BT_ORG ) ),
2641 aHelpBtn ( pTmpWindow, SfxResId( BT_HELP ) ),
2642 pReal ( pTmpWindow ),
2643 aHelper ( pTmpWindow )
2646 aNewBtn.Disable();
2647 aDelBtn.Disable();
2648 aChangeBtn.Disable();
2650 SFX_APP()->Get_Impl()->pTemplateCommon = GetISfxTemplateCommon();
2651 pTmpWindow->FreeResource();
2653 Initialize();
2655 aFamList.SetSelectHdl( LINK( this, SfxTemplateCatalog_Impl, FamListSelect ) );
2656 aOkBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, OkHdl ) );
2657 aCancelBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, CancelHdl ) );
2658 aNewBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, NewHdl ) );
2659 aDelBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, DelHdl ) );
2660 aChangeBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, ChangeHdl ) );
2661 aOrgBtn.SetClickHdl( LINK( this, SfxTemplateCatalog_Impl, OrgHdl ) );
2664 //-------------------------------------------------------------------------
2666 SfxTemplateCatalog_Impl::~SfxTemplateCatalog_Impl()
2668 SFX_APP()->Get_Impl()->pTemplateCommon = 0;
2671 //-------------------------------------------------------------------------
2673 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, OkHdl, Button *, pButton )
2675 (void)pButton; //unused
2676 ApplyHdl( NULL );
2677 pReal->EndDialog( RET_OK );
2678 return 0;
2680 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, OkHdl, Button *, pButton )
2682 //-------------------------------------------------------------------------
2684 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, CancelHdl, Button *, pButton )
2686 (void)pButton; //unused
2687 pReal->EndDialog( RET_CANCEL );
2688 return 0;
2690 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, CancelHdl, Button *, pButton )
2692 //-------------------------------------------------------------------------
2694 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, NewHdl, Button *, pButton )
2696 (void)pButton; //unused
2697 aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
2698 SfxCommonTemplateDialog_Impl::NewHdl( NULL );
2699 return 0;
2701 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, NewHdl, Button *, pButton )
2703 //-------------------------------------------------------------------------
2705 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, ChangeHdl, Button *, pButton )
2707 (void)pButton; //unused
2708 aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
2709 SfxCommonTemplateDialog_Impl::EditHdl( NULL );
2710 return 0;
2712 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, ChangeHdl, Button *, pButton )
2714 //-------------------------------------------------------------------------
2716 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, DelHdl, Button *, pButton )
2718 (void)pButton; //unused
2719 SfxCommonTemplateDialog_Impl::DeleteHdl( NULL );
2720 return 0;
2722 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, DelHdl, Button *, pButton )
2724 //-------------------------------------------------------------------------
2726 IMPL_LINK( SfxTemplateCatalog_Impl, OrgHdl, Button *, pButton )
2728 (void)pButton; //unused
2729 aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
2730 SfxDocumentTemplates aTemplates;
2731 aTemplates.Construct();
2732 SfxTemplateOrganizeDlg* pDlg = new SfxTemplateOrganizeDlg( pReal, &aTemplates );
2733 const short nRet = pDlg->Execute();
2734 delete pDlg;
2735 if ( RET_OK == nRet )
2736 Update_Impl();
2737 else if ( RET_EDIT_STYLE == nRet )
2738 pReal->EndDialog( RET_CANCEL );
2739 return 0;
2742 //-------------------------------------------------------------------------
2744 void SfxTemplateCatalog_Impl::EnableEdit( sal_Bool bEnable )
2746 SfxCommonTemplateDialog_Impl::EnableEdit( bEnable );
2747 aChangeBtn.Enable( bEnable );
2750 //-------------------------------------------------------------------------
2752 void SfxTemplateCatalog_Impl::EnableDel( sal_Bool bEnable )
2754 SfxCommonTemplateDialog_Impl::EnableDel( bEnable );
2755 aDelBtn.Enable( bEnable );
2758 void SfxTemplateCatalog_Impl::EnableNew(sal_Bool bEnable)
2760 SfxCommonTemplateDialog_Impl::EnableNew( bEnable );
2761 aNewBtn.Enable( bEnable );
2764 //-------------------------------------------------------------------------
2766 IMPL_LINK_INLINE_START( SfxTemplateCatalog_Impl, FamListSelect, ListBox *, pList )
2768 const sal_uInt16 nEntry = aFamIds[pList->GetSelectEntryPos()];
2769 FamilySelect(nEntry);
2770 return 0;
2772 IMPL_LINK_INLINE_END( SfxTemplateCatalog_Impl, FamListSelect, ListBox *, pList )
2774 //-------------------------------------------------------------------------
2776 void SfxTemplateCatalog_Impl::EnableItem( sal_uInt16 nMesId, sal_Bool bCheck )
2778 if ( nMesId == SID_STYLE_WATERCAN )
2779 aOkBtn.Enable( bCheck );
2780 if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
2781 return;
2784 //-------------------------------------------------------------------------
2786 void SfxTemplateCatalog_Impl::CheckItem(sal_uInt16 nMesId, sal_Bool /*bCheck*/)
2788 if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
2789 return;
2790 sal_uInt16 i;
2791 for ( i = 0; i < aFamIds.size() && aFamIds[i] != nMesId; i++ ) ;
2792 aFamList.SelectEntryPos(i);
2795 //-------------------------------------------------------------------------
2797 sal_Bool SfxTemplateCatalog_Impl::IsCheckedItem(sal_uInt16 nMesId)
2799 if ( nMesId > SFX_STYLE_FAMILY_PSEUDO || nMesId < SFX_STYLE_FAMILY_CHAR )
2800 return sal_False;
2801 sal_uInt16 i;
2802 for ( i = 0; i < aFamIds.size() && aFamIds[i] != nMesId; i++ )
2804 return aFamList.IsEntrySelected( rtl::OUString::valueOf(static_cast<sal_Int32>(i)) );
2807 //-------------------------------------------------------------------------
2808 // The list has only to master the disabling, since during his life time no
2809 // changes in selection can be made,
2810 void SfxTemplateCatalog_Impl::EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnable )
2812 if ( !bEnable )
2813 for ( sal_uInt16 nPos = aFamIds.size(); nPos--; )
2814 if ( aFamIds[ nPos ] == nId )
2816 aFamIds.erase( aFamIds.begin() + nPos );
2817 aFamList.RemoveEntry( nPos );
2821 void SfxTemplateCatalog_Impl::InsertFamilyItem( sal_uInt16 nId, const SfxStyleFamilyItem* pItem )
2823 if ( nId > SFX_STYLE_FAMILY_PSEUDO || nId < SFX_STYLE_FAMILY_CHAR )
2824 return;
2825 aFamList.InsertEntry( pItem->GetText(), 0 );
2826 aFamIds.insert( aFamIds.begin(), nId );
2829 void SfxTemplateCatalog_Impl::ClearFamilyList()
2831 aFamList.Clear();
2832 aFamIds.clear();
2835 void SfxTemplateCatalog_Impl::PrepareDeleteAction()
2837 aDelBtn.Disable();
2838 aCancelBtn.SetText( String( SfxResId( STR_CLOSE ) ) );
2842 void SfxCommonTemplateDialog_Impl::SetFamily( sal_uInt16 nId )
2844 if ( nId != nActFamily )
2846 if ( nActFamily != 0xFFFF )
2847 CheckItem( nActFamily, sal_False );
2848 nActFamily = nId;
2849 if ( nId != 0xFFFF )
2850 bUpdateFamily = sal_True;
2854 void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl()
2856 bUpdateFamily = sal_False;
2858 SfxDispatcher* pDispat = pBindings->GetDispatcher_Impl();
2859 SfxViewFrame *pViewFrame = pDispat->GetFrame();
2860 SfxObjectShell *pDocShell = pViewFrame->GetObjectShell();
2862 SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool;
2863 pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0;
2864 if ( pOldStyleSheetPool != pStyleSheetPool )
2866 if ( pOldStyleSheetPool )
2867 EndListening(*pOldStyleSheetPool);
2868 if ( pStyleSheetPool )
2869 StartListening(*pOldStyleSheetPool);
2872 bWaterDisabled = sal_False;
2873 bCanNew = sal_True;
2874 bTreeDrag = sal_True;
2875 bUpdateByExampleDisabled = sal_False;
2877 if ( pStyleSheetPool )
2879 if(!pTreeBox)
2880 UpdateStyles_Impl(UPDATE_FAMILY | UPDATE_FAMILY_LIST);
2881 else
2883 UpdateStyles_Impl(UPDATE_FAMILY);
2884 FillTreeBox();
2888 InvalidateBindings();
2890 if ( IsCheckedItem( SID_STYLE_WATERCAN ) &&
2891 // only if that area is allowed
2892 0 != pFamilyState[ nActFamily - 1 ] )
2893 Execute_Impl( SID_STYLE_APPLY, GetSelectedEntry(),
2894 String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() );
2896 void SfxCommonTemplateDialog_Impl::ReplaceUpdateButtonByMenu()
2898 //does nothing
2901 void SfxTemplateDialog::StateChanged( StateChangedType nStateChange )
2903 if ( nStateChange == STATE_CHANGE_INITSHOW )
2905 SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
2906 Window* pEditWin = pFrame->GetViewShell()->GetWindow();
2908 Size aSize = pEditWin->GetSizePixel();
2909 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
2910 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
2911 Size aWinSize = GetSizePixel();
2912 aPoint.X() += aSize.Width() - aWinSize.Width() - 20;
2913 aPoint.Y() += aSize.Height() / 2 - aWinSize.Height() / 2;
2914 SetFloatingPos( aPoint );
2917 SfxDockingWindow::StateChanged( nStateChange );
2920 DropToolBox_Impl::DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog) :
2921 ToolBox(pParent),
2922 DropTargetHelper(this),
2923 rParent(*pTemplateDialog)
2927 DropToolBox_Impl::~DropToolBox_Impl()
2931 sal_Int8 DropToolBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
2933 sal_Int8 nReturn = DND_ACTION_NONE;
2934 sal_uInt16 nItemId = GetItemId( rEvt.maPosPixel );
2935 if(USHRT_MAX != nItemId && !IsItemChecked( nItemId ))
2937 SetCurItemId(nItemId);
2938 GetSelectHdl().Call(this);
2940 // special case: page styles are allowed to create new styles by example
2941 // but not allowed to be created by drag and drop
2942 if ( nItemId != SfxCommonTemplateDialog_Impl::SfxFamilyIdToNId( SFX_STYLE_FAMILY_PAGE )&&
2943 IsDropFormatSupported( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) &&
2944 !rParent.bNewByExampleDisabled )
2946 nReturn = DND_ACTION_COPY;
2948 return nReturn;
2951 sal_Int8 DropToolBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
2953 return rParent.aFmtLb.ExecuteDrop(rEvt);
2956 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */