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