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