1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <vcl/msgbox.hxx>
32 #include <vcl/field.hxx>
33 #include <svl/eitem.hxx>
34 #include <svl/intitem.hxx>
35 #include <svl/style.hxx>
37 #include <sfx2/styfitem.hxx>
38 #include <sfx2/styledlg.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/mgetempl.hxx>
41 #include <sfx2/objsh.hxx>
42 #include "sfxtypes.hxx"
43 #include "sfx2/sfxresid.hxx"
44 #include <sfx2/module.hxx>
46 #include <sfx2/sfx.hrc>
48 #include "mgetempl.hrc"
50 #include <svl/style.hrc>
52 // SfxManageStyleSheetPage -----------------------------------------------
54 SfxManageStyleSheetPage::SfxManageStyleSheetPage( Window
* pParent
, const SfxItemSet
& rAttrSet
) :
56 SfxTabPage( pParent
, SfxResId( TP_MANAGE_STYLES
), rAttrSet
),
58 aNameFt ( this, SfxResId( FT_NAME
) ),
59 aNameEd ( this, SfxResId( ED_NAME
) ),
60 aNameMLE ( this, SfxResId( MLE_NAME
) ),
61 aAutoCB ( this, SfxResId( CB_AUTO
) ),
63 aFollowFt ( this, SfxResId( FT_NEXT
) ),
64 aFollowLb ( this, SfxResId( LB_NEXT
) ),
66 aBaseFt ( this, SfxResId( FT_BASE
) ),
67 aBaseLb ( this, SfxResId( LB_BASE
) ),
69 aFilterFt ( this, SfxResId( FT_REGION
) ),
70 aFilterLb ( this, SfxResId( LB_REGION
) ),
72 aDescGb ( this, SfxResId( GB_DESC
) ),
73 aDescFt ( this, SfxResId( FT_DESC
) ),
74 aDescED ( this, SfxResId( ED_DESC
) ),
76 pStyle( &( (SfxStyleDialog
*)pParent
->GetParent() )->GetStyleSheet() ),
79 bModified ( sal_False
),
80 aName ( pStyle
->GetName() ),
81 aFollow ( pStyle
->GetFollow() ),
82 aParent ( pStyle
->GetParent() ),
83 nFlags ( pStyle
->GetMask() )
87 Constructor, initializes the list box with the templates
94 aDescED
.SetBackground( GetBackground() );
95 FixedInfo
* pInfo
= new FixedInfo( this );
96 aDescED
.SetFont( pInfo
->GetFont() );
102 // this Page needs ExchangeSupport
103 SetExchangeSupport();
105 ResMgr
* pResMgr
= SFX_APP()->GetModule_Impl()->GetResMgr();
106 OSL_ENSURE( pResMgr
, "No ResMgr in Module" );
107 pFamilies
= new SfxStyleFamilies( ResId( DLG_STYLE_DESIGNER
, *pResMgr
) );
109 SfxStyleSheetBasePool
* pPool
= 0;
110 SfxObjectShell
* pDocShell
= SfxObjectShell::Current();
113 pPool
= pDocShell
->GetStyleSheetPool();
114 OSL_ENSURE( pPool
, "no Pool or no DocShell" );
118 pPool
->SetSearchMask( pStyle
->GetFamily() );
119 pPool
->First(); // for SW - update internal list
122 if ( !pStyle
->GetName().Len() && pPool
)
124 // NullString as Name -> generate Name
125 String
aNoName( SfxResId( STR_NONAME
) );
127 String
aNo( aNoName
);
128 aNoName
+= String::CreateFromInt32( nNo
);
129 while ( pPool
->Find( aNoName
) )
133 aNoName
+= String::CreateFromInt32( nNo
);
135 pStyle
->SetName( aNoName
);
137 aFollow
= pStyle
->GetFollow();
138 aParent
= pStyle
->GetParent();
140 aNameEd
.SetText(pStyle
->GetName());
142 // Set the field read-only if it is NOT an user-defined style
143 // but allow selecting and copying
144 if ( !pStyle
->IsUserDefined() ) {
145 aNameEd
.SetReadOnly();
148 aNameMLE
.SetControlBackground( GetSettings().GetStyleSettings().GetDialogColor() );
149 aNameMLE
.SetText( pStyle
->GetName() );
150 aNameMLE
.EnableCursor( sal_False
);
154 if ( pStyle
->HasFollowSupport() && pPool
)
156 SfxStyleSheetBase
* pPoolStyle
= pPool
->First();
160 aFollowLb
.InsertEntry( pPoolStyle
->GetName() );
161 pPoolStyle
= pPool
->Next();
164 // A new Template is not jet in the Pool
165 if ( LISTBOX_ENTRY_NOTFOUND
== aFollowLb
.GetEntryPos( pStyle
->GetName() ) )
166 aFollowLb
.InsertEntry( pStyle
->GetName() );
173 aFilterFt
.SetPosPixel( aBaseFt
.GetPosPixel() );
174 aFilterLb
.SetPosPixel( aBaseLb
.GetPosPixel() );
176 aBaseFt
.SetPosPixel( aFollowFt
.GetPosPixel() );
177 aBaseLb
.SetPosPixel( aFollowLb
.GetPosPixel() );
180 if ( pStyle
->HasParentSupport() && pPool
)
182 if ( pStyle
->HasClearParentSupport() )
183 // the base template can be set to NULL
184 aBaseLb
.InsertEntry( String( SfxResId( STR_NONE
) ) );
186 SfxStyleSheetBase
* pPoolStyle
= pPool
->First();
190 const String
aStr( pPoolStyle
->GetName() );
191 // own name as base template
193 aBaseLb
.InsertEntry( aStr
);
194 pPoolStyle
= pPool
->Next();
203 size_t nCount
= pFamilies
->size();
205 for ( i
= 0; i
< nCount
; ++i
)
207 pItem
= pFamilies
->at( i
);
209 if ( pItem
->GetFamily() == pStyle
->GetFamily() )
215 sal_uInt16 nStyleFilterIdx
= 0xffff;
217 const SfxStyleFilter
& rList
= pItem
->GetFilterList();
218 nCount
= rList
.size();
220 sal_uInt16 nMask
= pStyle
->GetMask() & ~SFXSTYLEBIT_USERDEF
;
222 if ( !nMask
) // User Template?
223 nMask
= pStyle
->GetMask();
225 for ( i
= 0; i
< nCount
; ++i
)
227 SfxFilterTupel
* pTupel
= rList
[ i
];
229 if ( pTupel
->nFlags
!= SFXSTYLEBIT_AUTO
&&
230 pTupel
->nFlags
!= SFXSTYLEBIT_USED
&&
231 pTupel
->nFlags
!= SFXSTYLEBIT_ALL
)
233 aFilterLb
.InsertEntry( pTupel
->aName
, nIdx
);
234 aFilterLb
.SetEntryData(nIdx
, (void*)(long)i
);
236 if ( ( pTupel
->nFlags
& nMask
) == nMask
)
237 nStyleFilterIdx
= nIdx
;
242 if ( nStyleFilterIdx
!= 0xFFFF )
243 aFilterLb
.SelectEntryPos( nStyleFilterIdx
);
246 if ( !aFilterLb
.GetEntryCount() || !pStyle
->IsUserDefined() )
253 aFilterLb
.SaveValue();
254 SetDescriptionText_Impl();
256 if ( aFollowLb
.IsEnabled() || aBaseLb
.IsEnabled() )
258 aNameEd
.SetGetFocusHdl(
259 LINK( this, SfxManageStyleSheetPage
, GetFocusHdl
) );
260 aNameEd
.SetLoseFocusHdl(
261 LINK( this, SfxManageStyleSheetPage
, LoseFocusHdl
) );
263 // It is a style with auto update? (SW only)
264 if(SFX_ITEM_SET
== rAttrSet
.GetItemState(SID_ATTR_AUTO_STYLE_UPDATE
))
266 Size aSize
= aNameEd
.GetSizePixel();
268 aNameEd
.SetSizePixel(aSize
);
273 //-------------------------------------------------------------------------
275 SfxManageStyleSheetPage::~SfxManageStyleSheetPage()
279 Destructor, release of the data
283 aNameEd
.SetGetFocusHdl( Link() );
284 aNameEd
.SetLoseFocusHdl( Link() );
291 //-------------------------------------------------------------------------
293 void SfxManageStyleSheetPage::UpdateName_Impl( ListBox
* pBox
,
298 After the change of a template name update the ListBox pBox
302 ListBox* pBox ListBox, whose entries are to be updated
303 const String& rNew the new Name
307 if ( pBox
->IsEnabled() )
309 // it is the current entry, which name was modified
310 const sal_Bool bSelect
= pBox
->GetSelectEntry() == aBuf
;
311 pBox
->RemoveEntry( aBuf
);
312 pBox
->InsertEntry( rNew
);
315 pBox
->SelectEntry( rNew
);
319 //-------------------------------------------------------------------------
321 void SfxManageStyleSheetPage::SetDescriptionText_Impl()
325 Set attribute description. Get the set metric for this.
329 SfxMapUnit eUnit
= SFX_MAPUNIT_CM
;
330 FieldUnit
eFieldUnit( FUNIT_CM
);
331 SfxModule
* pModule
= SfxModule::GetActiveModule();
334 const SfxPoolItem
* pPoolItem
= pModule
->GetItem( SID_ATTR_METRIC
);
336 eFieldUnit
= (FieldUnit
)( (SfxUInt16Item
*)pPoolItem
)->GetValue();
339 switch ( eFieldUnit
)
341 case FUNIT_MM
: eUnit
= SFX_MAPUNIT_MM
; break;
344 case FUNIT_KM
: eUnit
= SFX_MAPUNIT_CM
; break;
346 case FUNIT_PICA
: eUnit
= SFX_MAPUNIT_POINT
; break;
349 case FUNIT_MILE
: eUnit
= SFX_MAPUNIT_INCH
; break;
352 OSL_FAIL( "non supported field unit" );
354 aDescFt
.SetText( pStyle
->GetDescription( eUnit
) );
357 //-------------------------------------------------------------------------
359 IMPL_LINK_INLINE_START( SfxManageStyleSheetPage
, GetFocusHdl
, Edit
*, pEdit
)
363 StarView Handler; GetFocus-Handler of the Edits with the template name.
367 aBuf
= pEdit
->GetText().EraseLeadingChars();
370 IMPL_LINK_INLINE_END( SfxManageStyleSheetPage
, GetFocusHdl
, Edit
*, pEdit
)
372 //-------------------------------------------------------------------------
374 IMPL_LINK_INLINE_START( SfxManageStyleSheetPage
, LoseFocusHdl
, Edit
*, pEdit
)
378 StarView Handler; loose-focus-handler of the edits of the template name.
379 This will update the listbox with the subsequent templates. The current
380 template itself is not returned in the listbox of the base templates.
384 const String
aStr( pEdit
->GetText().EraseLeadingChars() );
385 pEdit
->SetText( aStr
);
386 // Update the Listbox of the base template if possible
388 UpdateName_Impl( &aFollowLb
, aStr
);
391 IMPL_LINK_INLINE_END( SfxManageStyleSheetPage
, LoseFocusHdl
, Edit
*, pEdit
)
393 //-------------------------------------------------------------------------
395 sal_Bool
SfxManageStyleSheetPage::FillItemSet( SfxItemSet
& rSet
)
399 Handler for setting the (modified) data. I called from the OK of the
404 SfxItemSet &rAttrSet The set, which receives the data.
408 sal_Bool sal_True: The data had been changed
409 sal_False: The data had not been changed
417 const sal_uInt16 nFilterIdx
= aFilterLb
.GetSelectEntryPos();
421 if ( LISTBOX_ENTRY_NOTFOUND
!= nFilterIdx
&&
422 nFilterIdx
!= aFilterLb
.GetSavedValue() &&
423 aFilterLb
.IsEnabled() )
425 bModified
= sal_True
;
426 OSL_ENSURE( pItem
, "No Item" );
427 // is only possibly for user templates
428 sal_uInt16 nMask
= pItem
->GetFilterList()[ (size_t)aFilterLb
.GetEntryData( nFilterIdx
) ]->nFlags
| SFXSTYLEBIT_USERDEF
;
429 pStyle
->SetMask( nMask
);
431 if(aAutoCB
.IsVisible() &&
432 aAutoCB
.IsChecked() != aAutoCB
.GetSavedValue())
434 rSet
.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE
, aAutoCB
.IsChecked()));
440 //-------------------------------------------------------------------------
442 void SfxManageStyleSheetPage::Reset( const SfxItemSet
& /*rAttrSet*/ )
446 Handler to initialize the page with the initial data.
450 const SfxItemSet &rAttrSet The data set
458 bModified
= sal_False
;
459 String
sCmp( pStyle
->GetName() );
462 pStyle
->SetName( aName
);
463 aNameEd
.SetText( aName
);
465 if ( aFollowLb
.IsEnabled() )
467 sCmp
= pStyle
->GetFollow();
469 if ( sCmp
!= aFollow
)
470 pStyle
->SetFollow( aFollow
);
472 if ( !aFollow
.Len() )
473 aFollowLb
.SelectEntry( aName
);
475 aFollowLb
.SelectEntry( aFollow
);
478 if ( aBaseLb
.IsEnabled() )
480 sCmp
= pStyle
->GetParent();
482 if ( sCmp
!= aParent
)
483 pStyle
->SetParent( aParent
);
485 if ( !aParent
.Len() )
486 aBaseLb
.SelectEntry( String( SfxResId( STR_NONE
) ) );
488 aBaseLb
.SelectEntry( aParent
);
490 if ( String( SfxResId( STR_STANDARD
) ) == aName
)
492 // the default template can not be linked
498 if ( aFilterLb
.IsEnabled() )
500 sal_uInt16 nCmp
= pStyle
->GetMask();
502 if ( nCmp
!= nFlags
)
503 pStyle
->SetMask( nFlags
);
504 aFilterLb
.SelectEntryPos( aFilterLb
.GetSavedValue() );
508 //-------------------------------------------------------------------------
510 SfxTabPage
* SfxManageStyleSheetPage::Create( Window
* pParent
,
511 const SfxItemSet
&rAttrSet
)
515 Factory for the creation of the page.
523 return new SfxManageStyleSheetPage( pParent
, rAttrSet
);
526 //-------------------------------------------------------------------------
528 void SfxManageStyleSheetPage::ActivatePage( const SfxItemSet
& rSet
)
532 ActivatePage handler of SfxTabDialog, is used for the the update of the
533 descriptive text, since this might have changed through changes of data on
538 const SfxItemSet& the set for the exchange of data; is not used here.
542 <SfxTabDialog::ActivatePage(const SfxItemSet &)>
546 SetDescriptionText_Impl();
548 // It is a style with auto update? (SW only)
549 const SfxPoolItem
* pPoolItem
;
552 rSet
.GetItemState( SID_ATTR_AUTO_STYLE_UPDATE
, sal_False
, &pPoolItem
) )
553 aAutoCB
.Check( ( (const SfxBoolItem
*)pPoolItem
)->GetValue() );
557 //-------------------------------------------------------------------------
559 int SfxManageStyleSheetPage::DeactivatePage( SfxItemSet
* pItemSet
)
563 DeactivatePage-handler of SfxTabDialog; data is set on the template, so
564 that the correct inheritance on the other pages of the dialog is made.
565 If an error occurs, leaving the page is prevented.
568 SfxItemSet* the set for the exchange of data; is not used here.
572 <SfxTabDialog::DeactivatePage(SfxItemSet*)>
576 int nRet
= SfxTabPage::LEAVE_PAGE
;
578 if ( aNameEd
.IsModified() )
580 // By pressing <Enter> LoseFocus() is not trigged through StarView
581 if ( aNameEd
.HasFocus() )
582 LoseFocusHdl( &aNameEd
);
584 if ( !pStyle
->SetName( aNameEd
.GetText().EraseLeadingChars() ) )
586 InfoBox
aBox( this, SfxResId( MSG_TABPAGE_INVALIDNAME
) );
589 aNameEd
.SetSelection( Selection( SELECTION_MIN
, SELECTION_MAX
) );
590 return SfxTabPage::KEEP_PAGE
;
592 bModified
= sal_True
;
595 if ( pStyle
->HasFollowSupport() && aFollowLb
.IsEnabled() )
597 const String
aFollowEntry( aFollowLb
.GetSelectEntry() );
599 if ( pStyle
->GetFollow() != aFollowEntry
)
601 if ( !pStyle
->SetFollow( aFollowEntry
) )
603 InfoBox
aBox( this, SfxResId( MSG_TABPAGE_INVALIDSTYLE
) );
605 aFollowLb
.GrabFocus();
606 return SfxTabPage::KEEP_PAGE
;
608 bModified
= sal_True
;
612 if ( aBaseLb
.IsEnabled() )
614 String
aParentEntry( aBaseLb
.GetSelectEntry() );
616 if ( String( SfxResId( STR_NONE
) ) == aParentEntry
|| aParentEntry
== pStyle
->GetName() )
617 aParentEntry
.Erase();
619 if ( pStyle
->GetParent() != aParentEntry
)
621 if ( !pStyle
->SetParent( aParentEntry
) )
623 InfoBox
aBox( this, SfxResId( MSG_TABPAGE_INVALIDPARENT
) );
626 return SfxTabPage::KEEP_PAGE
;
628 bModified
= sal_True
;
629 nRet
|= (int)SfxTabPage::REFRESH_SET
;
634 FillItemSet( *pItemSet
);
639 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */