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