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