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