merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / config / optcomp.cxx
blobd4fec5d027133c8842a917b2d376e7918810b67e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optcomp.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
37 #include "optcomp.hxx"
39 #include "docsh.hxx"
40 #include "swmodule.hxx"
41 #include "swtypes.hxx"
42 #include "uiitems.hxx"
43 #include "view.hxx"
44 #include "wrtsh.hxx"
46 #include "optcomp.hrc"
47 #include "globals.hrc"
48 #include <tools/urlobj.hxx>
49 #ifndef _UTL__HXX_
50 #include <unotools/configmgr.hxx>
51 #endif
52 #include <vcl/msgbox.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <sfx2/docfilt.hxx>
55 #include <sfx2/fcontnr.hxx>
56 #include <IDocumentSettingAccess.hxx>
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::document;
60 using namespace ::com::sun::star::uno;
61 using ::rtl::OUString;
62 using namespace ::std;
64 #define ASCII_STR(s) OUString( RTL_CONSTASCII_USTRINGPARAM( s ) )
65 #define DEFAULT_ENTRY COMPATIBILITY_DEFAULT_NAME
66 #define USER_ENTRY ASCII_STR( "_user" )
67 #define BUTTON_BORDER 2
69 // struct CompatibilityItem ----------------------------------------------
71 struct CompatibilityItem
73 String m_sName;
74 String m_sModule;
75 bool m_bUsePrtMetrics;
76 bool m_bAddSpacing;
77 bool m_bAddSpacingAtPages;
78 bool m_bUseOurTabStops;
79 bool m_bNoExtLeading;
80 bool m_bUseLineSpacing;
81 bool m_bAddTableSpacing;
82 bool m_bUseObjPos;
83 bool m_bUseOurTextWrapping;
84 bool m_bConsiderWrappingStyle;
85 bool m_bExpandWordSpace;
86 bool m_bIsDefault;
87 bool m_bIsUser;
89 CompatibilityItem( const String& _rName, const String& _rModule,
90 bool _bUsePrtMetrics, bool _bAddSpacing, bool _bAddSpacingAtPages,
91 bool _bUseOurTabStops, bool _bNoExtLeading, bool _bUseLineSpacing,
92 bool _bAddTableSpacing, bool _bUseObjPos, bool _bUseOurTextWrapping,
93 bool _bConsiderWrappingStyle, bool _bExpandWordSpace,
94 bool _bIsDefault, bool _bIsUser ) :
96 m_sName ( _rName ),
97 m_sModule ( _rModule ),
98 m_bUsePrtMetrics ( _bUsePrtMetrics ),
99 m_bAddSpacing ( _bAddSpacing ),
100 m_bAddSpacingAtPages ( _bAddSpacingAtPages ),
101 m_bUseOurTabStops ( _bUseOurTabStops ),
102 m_bNoExtLeading ( _bNoExtLeading ),
103 m_bUseLineSpacing ( _bUseLineSpacing ),
104 m_bAddTableSpacing ( _bAddTableSpacing ),
105 m_bUseObjPos ( _bUseObjPos ),
106 m_bUseOurTextWrapping ( _bUseOurTextWrapping ),
107 m_bConsiderWrappingStyle( _bConsiderWrappingStyle ),
108 m_bExpandWordSpace ( _bExpandWordSpace ),
109 m_bIsDefault ( _bIsDefault ),
110 m_bIsUser ( _bIsUser ) {}
113 #include <vector>
115 struct SwCompatibilityOptPage_Impl
117 typedef vector< CompatibilityItem > SwCompatibilityItemList;
119 SwCompatibilityItemList m_aList;
122 // class SwCompatibilityOptPage ------------------------------------------
124 SwCompatibilityOptPage::SwCompatibilityOptPage( Window* pParent, const SfxItemSet& rSet ) :
126 SfxTabPage( pParent, SW_RES( TP_OPTCOMPATIBILITY_PAGE ), rSet ),
128 m_aMainFL ( this, SW_RES( FL_MAIN ) ),
129 m_aFormattingFT ( this, SW_RES( FT_FORMATTING ) ),
130 m_aFormattingLB ( this, SW_RES( LB_FORMATTING ) ),
131 m_aOptionsFT ( this, SW_RES( FT_OPTIONS ) ),
132 m_aOptionsLB ( this, SW_RES( LB_OPTIONS ) ),
133 m_aResetPB ( this, SW_RES( PB_RESET ) ),
134 m_aDefaultPB ( this, SW_RES( PB_DEFAULT ) ),
135 m_sUserEntry ( SW_RES( STR_USERENTRY ) ),
136 m_sUseAsDefaultQuery( SW_RES( STR_QRYBOX_USEASDEFAULT ) ),
137 m_pWrtShell ( NULL ),
138 m_pImpl ( new SwCompatibilityOptPage_Impl ),
139 m_nSavedOptions ( 0 )
142 // init options strings with local resource ids -> so do it before FreeResource()
143 for ( USHORT nResId = STR_COMP_OPTIONS_START; nResId < STR_COMP_OPTIONS_END; ++nResId )
145 String sEntry = String( SW_RES( nResId ) );
146 if ( STR_TAB_ALIGNMENT == nResId ||
147 STR_LINE_SPACING == nResId ||
148 STR_USE_OBJPOSITIONING == nResId ||
149 STR_USE_OURTEXTWRAPPING == nResId )
150 ReplaceFormatName( sEntry );
151 SvLBoxEntry* pEntry = m_aOptionsLB.SvTreeListBox::InsertEntry( sEntry );
152 if ( pEntry )
154 m_aOptionsLB.SetCheckButtonState( pEntry, SV_BUTTON_UNCHECKED );
155 pEntry->SetUserData( (void*)(ULONG)nResId );
158 m_aOptionsLB.SetWindowBits( m_aOptionsLB.GetStyle() | WB_HSCROLL | WB_HIDESELECTION );
159 m_aOptionsLB.SetHighlightRange();
161 FreeResource();
163 InitControls( rSet );
165 // set handler
166 m_aFormattingLB.SetSelectHdl( LINK( this, SwCompatibilityOptPage, SelectHdl ) );
167 m_aDefaultPB.SetClickHdl( LINK( this, SwCompatibilityOptPage, UseAsDefaultHdl ) );
169 // hide some controls, will be implemented later!!!
170 m_aFormattingFT.Hide();
171 m_aFormattingLB.Hide();
172 m_aResetPB.Hide();
173 // so move and resize the other controls
174 Point aMovePnt = m_aFormattingFT.GetPosPixel();
175 Point aNewPnt = m_aOptionsFT.GetPosPixel();
176 aNewPnt.Y() = aMovePnt.Y();
177 m_aOptionsFT.SetPosPixel( aNewPnt );
178 aMovePnt = m_aFormattingLB.GetPosPixel();
179 aNewPnt = m_aOptionsLB.GetPosPixel();
180 long nDelta = aNewPnt.Y() - aMovePnt.Y();
181 aNewPnt.Y() = aMovePnt.Y();
182 m_aOptionsLB.SetPosPixel( aNewPnt );
183 Size aNewSz = m_aOptionsLB.GetSizePixel();
184 aNewSz.Height() += nDelta;
185 m_aOptionsLB.SetSizePixel( aNewSz );
188 // -----------------------------------------------------------------------
190 SwCompatibilityOptPage::~SwCompatibilityOptPage()
192 delete m_pImpl;
195 // -----------------------------------------------------------------------
197 void SwCompatibilityOptPage::ReplaceFormatName( String& rEntry )
199 static const String sOpenOfficeName = String::CreateFromAscii("OpenOffice.org");
200 static const String sAsianName = String::CreateFromAscii("StarSuite");
202 Any aAny = ::utl::ConfigManager::
203 GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME );
204 rtl::OUString sTmp;
205 if ( aAny >>= sTmp )
207 String sFormatName = sTmp;
208 String sFormatVersion;
209 bool bOpenOffice = ( sOpenOfficeName == sFormatName );
210 if ( bOpenOffice )
211 sFormatVersion = String::CreateFromAscii("1.1");
212 else
213 sFormatVersion = String::CreateFromAscii("6.0/7");
214 if ( !bOpenOffice && ( sAsianName != sFormatName ) )
215 sFormatName = String::CreateFromAscii("StarOffice");
217 rEntry.SearchAndReplace( String::CreateFromAscii("%FORMATNAME"), sFormatName );
218 rEntry.SearchAndReplace( String::CreateFromAscii("%FORMATVERSION"), sFormatVersion );
222 // -----------------------------------------------------------------------
224 ULONG convertBools2Ulong_Impl
226 bool _bUsePrtMetrics,
227 bool _bAddSpacing,
228 bool _bAddSpacingAtPages,
229 bool _bUseOurTabStops,
230 bool _bNoExtLeading,
231 bool _bUseLineSpacing,
232 bool _bAddTableSpacing,
233 bool _bUseObjPos,
234 bool _bUseOurTextWrapping,
235 bool _bConsiderWrappingStyle,
236 bool _bExpandWordSpace
239 ULONG nRet = 0;
240 ULONG nSetBit = 1;
242 if ( _bUsePrtMetrics )
243 nRet |= nSetBit;
244 nSetBit = nSetBit << 1;
245 if ( _bAddSpacing )
246 nRet |= nSetBit;
247 nSetBit = nSetBit << 1;
248 if ( _bAddSpacingAtPages )
249 nRet |= nSetBit;
250 nSetBit = nSetBit << 1;
251 if ( _bUseOurTabStops )
252 nRet |= nSetBit;
253 nSetBit = nSetBit << 1;
254 if ( _bNoExtLeading )
255 nRet |= nSetBit;
256 nSetBit = nSetBit << 1;
257 if ( _bUseLineSpacing )
258 nRet |= nSetBit;
259 nSetBit = nSetBit << 1;
260 if ( _bAddTableSpacing )
261 nRet |= nSetBit;
262 nSetBit = nSetBit << 1;
263 if ( _bUseObjPos )
264 nRet |= nSetBit;
265 nSetBit = nSetBit << 1;
266 if ( _bUseOurTextWrapping )
267 nRet |= nSetBit;
268 nSetBit = nSetBit << 1;
269 if ( _bConsiderWrappingStyle )
270 nRet |= nSetBit;
271 nSetBit = nSetBit << 1;
272 if ( _bExpandWordSpace )
273 nRet |= nSetBit;
275 return nRet;
278 // -----------------------------------------------------------------------
280 void SwCompatibilityOptPage::InitControls( const SfxItemSet& rSet )
282 // init objectshell and detect document name
283 String sDocTitle;
284 const SfxPoolItem* pItem = NULL;
285 SfxObjectShell* pObjShell = NULL;
286 if ( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_WRTSHELL, FALSE, &pItem ) )
287 m_pWrtShell = (SwWrtShell*)( (const SwPtrItem*)pItem )->GetValue();
288 if ( m_pWrtShell )
290 pObjShell = m_pWrtShell->GetView().GetDocShell();
291 if ( pObjShell )
292 sDocTitle = pObjShell->GetTitle( SFX_TITLE_TITLE );
294 else
296 m_aMainFL.Disable();
297 m_aFormattingFT.Disable();
298 m_aFormattingLB.Disable();
299 m_aOptionsFT.Disable();
300 m_aOptionsLB.Disable();
301 m_aResetPB.Disable();
302 m_aDefaultPB.Disable();
304 String sText = m_aMainFL.GetText();
305 sText.SearchAndReplace( String::CreateFromAscii("%DOCNAME"), sDocTitle );
306 m_aMainFL.SetText( sText );
308 // loading file formats
309 Sequence< Sequence< PropertyValue > > aList = m_aConfigItem.GetList();
310 OUString sName;
311 OUString sModule;
312 bool bUsePrtMetrics = false;
313 bool bAddSpacing = false;
314 bool bAddSpacingAtPages = false;
315 bool bUseOurTabStops = false;
316 bool bNoExtLeading = false;
317 bool bUseLineSpacing = false;
318 bool bAddTableSpacing = false;
319 bool bUseObjPos = false;
320 bool bUseOurTextWrapping = false;
321 bool bConsiderWrappingStyle = false;
322 bool bExpandWordSpace = false;
323 int i, j, nCount = aList.getLength();
324 for ( i = 0; i < nCount; ++i )
326 String sNewEntry;
327 const Sequence< PropertyValue >& rEntry = aList[i];
328 for ( j = 0; j < rEntry.getLength(); j++ )
330 PropertyValue aValue = rEntry[j];
331 if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_NAME )
332 aValue.Value >>= sName;
333 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_MODULE )
334 aValue.Value >>= sModule;
335 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_USEPRTMETRICS )
336 aValue.Value >>= bUsePrtMetrics;
337 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_ADDSPACING )
338 aValue.Value >>= bAddSpacing;
339 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_ADDSPACINGATPAGES )
340 aValue.Value >>= bAddSpacingAtPages;
341 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_USEOURTABSTOPS )
342 aValue.Value >>= bUseOurTabStops;
343 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_NOEXTLEADING )
344 aValue.Value >>= bNoExtLeading;
345 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_USELINESPACING )
346 aValue.Value >>= bUseLineSpacing;
347 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_ADDTABLESPACING )
348 aValue.Value >>= bAddTableSpacing;
349 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_USEOBJECTPOSITIONING )
350 aValue.Value >>= bUseObjPos;
351 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_USEOURTEXTWRAPPING )
352 aValue.Value >>= bUseOurTextWrapping;
353 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_CONSIDERWRAPPINGSTYLE )
354 aValue.Value >>= bConsiderWrappingStyle;
355 else if ( aValue.Name == COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE )
356 aValue.Value >>= bExpandWordSpace;
359 CompatibilityItem aItem(
360 sName, sModule, bUsePrtMetrics, bAddSpacing,
361 bAddSpacingAtPages, bUseOurTabStops, bNoExtLeading,
362 bUseLineSpacing, bAddTableSpacing, bUseObjPos,
363 bUseOurTextWrapping, bConsiderWrappingStyle, bExpandWordSpace,
364 ( sName.equals( DEFAULT_ENTRY ) != sal_False ),
365 ( sName.equals( USER_ENTRY ) != sal_False ) );
366 m_pImpl->m_aList.push_back( aItem );
368 if ( aItem.m_bIsDefault )
369 continue;
371 if ( sName.equals( USER_ENTRY ) )
372 sNewEntry = m_sUserEntry;
373 else if ( pObjShell && sName.getLength() > 0 )
375 SfxFilterContainer* pFacCont = pObjShell->GetFactory().GetFilterContainer();
376 const SfxFilter* pFilter = pFacCont->GetFilter4FilterName( sName );
377 if ( pFilter )
378 sNewEntry = pFilter->GetUIName();
381 if ( sNewEntry.Len() == 0 )
382 sNewEntry = sName;
384 USHORT nPos = m_aFormattingLB.InsertEntry( sNewEntry );
385 ULONG nOptions = convertBools2Ulong_Impl(
386 bUsePrtMetrics, bAddSpacing, bAddSpacingAtPages,
387 bUseOurTabStops, bNoExtLeading, bUseLineSpacing,
388 bAddTableSpacing, bUseObjPos, bUseOurTextWrapping,
389 bConsiderWrappingStyle, bExpandWordSpace );
390 m_aFormattingLB.SetEntryData( nPos, (void*)(long)nOptions );
393 m_aFormattingLB.SetDropDownLineCount( m_aFormattingLB.GetEntryCount() );
395 // check if the default button text is not too wide otherwise we have to stretch the button
396 // and move its position and the position of the reset button
397 long nTxtWidth = m_aDefaultPB.GetTextWidth( m_aDefaultPB.GetText() );
398 Size aBtnSz = m_aDefaultPB.GetSizePixel();
399 if ( nTxtWidth > aBtnSz.Width() )
401 long nDelta = nTxtWidth - aBtnSz.Width() + 2 * BUTTON_BORDER;
402 aBtnSz.Width() += nDelta;
403 Point aBtnPnt = m_aDefaultPB.GetPosPixel();
404 aBtnPnt.X() -= nDelta;
405 m_aDefaultPB.SetPosSizePixel( aBtnPnt, aBtnSz );
406 aBtnPnt = m_aResetPB.GetPosPixel();
407 aBtnPnt.X() -= 2 * nDelta;
408 m_aResetPB.SetPosSizePixel( aBtnPnt, aBtnSz );
412 // -----------------------------------------------------------------------
414 IMPL_LINK( SwCompatibilityOptPage, SelectHdl, ListBox*, EMPTYARG )
416 USHORT nPos = m_aFormattingLB.GetSelectEntryPos();
417 ULONG nOptions = (ULONG)(void*)m_aFormattingLB.GetEntryData( nPos );
418 SetCurrentOptions( nOptions );
420 return 0;
423 // -----------------------------------------------------------------------
425 IMPL_LINK( SwCompatibilityOptPage, UseAsDefaultHdl, PushButton*, EMPTYARG )
427 QueryBox aBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), m_sUseAsDefaultQuery );
428 if ( aBox.Execute() == RET_YES )
430 for ( vector< CompatibilityItem >::iterator pItem = m_pImpl->m_aList.begin();
431 pItem != m_pImpl->m_aList.end(); ++pItem )
433 if ( pItem->m_bIsDefault )
435 USHORT nCount = static_cast< USHORT >( m_aOptionsLB.GetEntryCount() );
436 for ( USHORT i = 0; i < nCount; ++i )
438 bool bChecked = ( m_aOptionsLB.IsChecked(i) != FALSE );
439 CompatibilityOptions eOption = static_cast< CompatibilityOptions >(i);
440 switch ( eOption )
442 case COPT_USE_PRINTERDEVICE : pItem->m_bUsePrtMetrics = bChecked; break;
443 case COPT_ADD_SPACING : pItem->m_bAddSpacing = bChecked; break;
444 case COPT_ADD_SPACING_AT_PAGES : pItem->m_bAddSpacingAtPages = bChecked; break;
445 case COPT_USE_OUR_TABSTOPS : pItem->m_bUseOurTabStops = bChecked; break;
446 case COPT_NO_EXTLEADING : pItem->m_bNoExtLeading = bChecked; break;
447 case COPT_USE_LINESPACING : pItem->m_bUseLineSpacing = bChecked; break;
448 case COPT_ADD_TABLESPACING : pItem->m_bAddTableSpacing = bChecked; break;
449 case COPT_USE_OBJECTPOSITIONING: pItem->m_bUseObjPos = bChecked; break;
450 case COPT_USE_OUR_TEXTWRAPPING: pItem->m_bUseOurTextWrapping = bChecked; break;
451 case COPT_CONSIDER_WRAPPINGSTYLE: pItem->m_bConsiderWrappingStyle = bChecked; break;
452 case COPT_EXPAND_WORDSPACE: pItem->m_bExpandWordSpace = bChecked; break;
453 default:
455 DBG_ERRORFILE( "SwCompatibilityOptPage::UseAsDefaultHdl(): wrong option" );
459 break;
463 WriteOptions();
466 return 0;
469 // -----------------------------------------------------------------------
471 void SwCompatibilityOptPage::SetCurrentOptions( ULONG nOptions )
473 ULONG nCount = m_aOptionsLB.GetEntryCount();
474 DBG_ASSERT( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
475 for ( USHORT i = 0; i < nCount; ++i )
477 BOOL bChecked = ( ( nOptions & 0x00000001 ) == 0x00000001 );
478 m_aOptionsLB.CheckEntryPos( i, bChecked );
479 nOptions = nOptions >> 1;
483 // -----------------------------------------------------------------------
485 ULONG SwCompatibilityOptPage::GetDocumentOptions() const
487 ULONG nRet = 0;
488 if ( m_pWrtShell )
490 const IDocumentSettingAccess& rIDocumentSettingAccess = *m_pWrtShell->getIDocumentSettingAccess();
491 nRet = convertBools2Ulong_Impl(
492 rIDocumentSettingAccess.get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) == sal_False,
493 rIDocumentSettingAccess.get(IDocumentSettingAccess::PARA_SPACE_MAX) != sal_False,
494 rIDocumentSettingAccess.get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES) != sal_False,
495 rIDocumentSettingAccess.get(IDocumentSettingAccess::TAB_COMPAT) == sal_False,
496 rIDocumentSettingAccess.get(IDocumentSettingAccess::ADD_EXT_LEADING) == sal_False,
497 rIDocumentSettingAccess.get(IDocumentSettingAccess::OLD_LINE_SPACING) != sal_False,
498 rIDocumentSettingAccess.get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS) != sal_False,
499 rIDocumentSettingAccess.get(IDocumentSettingAccess::USE_FORMER_OBJECT_POS) != sal_False,
500 rIDocumentSettingAccess.get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) != sal_False,
501 rIDocumentSettingAccess.get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) != sal_False,
502 rIDocumentSettingAccess.get(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK) != sal_True );
504 return nRet;
507 // -----------------------------------------------------------------------
509 void SwCompatibilityOptPage::WriteOptions()
511 m_aConfigItem.Clear();
512 for ( vector< CompatibilityItem >::const_iterator pItem = m_pImpl->m_aList.begin();
513 pItem != m_pImpl->m_aList.end(); ++pItem )
514 m_aConfigItem.AppendItem(
515 pItem->m_sName, pItem->m_sModule, pItem->m_bUsePrtMetrics, pItem->m_bAddSpacing,
516 pItem->m_bAddSpacingAtPages, pItem->m_bUseOurTabStops,
517 pItem->m_bNoExtLeading, pItem->m_bUseLineSpacing,
518 pItem->m_bAddTableSpacing, pItem->m_bUseObjPos,
519 pItem->m_bUseOurTextWrapping, pItem->m_bConsiderWrappingStyle,
520 pItem->m_bExpandWordSpace );
523 // -----------------------------------------------------------------------
525 SfxTabPage* SwCompatibilityOptPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
527 return new SwCompatibilityOptPage( pParent, rAttrSet );
530 // -----------------------------------------------------------------------
532 BOOL SwCompatibilityOptPage::FillItemSet( SfxItemSet& )
534 BOOL bModified = FALSE;
535 if ( m_pWrtShell )
537 ULONG nSavedOptions = m_nSavedOptions;
538 ULONG nCount = m_aOptionsLB.GetEntryCount();
539 DBG_ASSERT( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
541 bool bSetParaSpaceMax = false;
543 for ( USHORT i = 0; i < nCount; ++i )
545 CompatibilityOptions nOption = static_cast< CompatibilityOptions >(i);
546 BOOL bChecked = m_aOptionsLB.IsChecked(i);
547 BOOL bSavedChecked = ( ( nSavedOptions & 0x00000001 ) == 0x00000001 );
548 if ( bChecked != bSavedChecked )
550 if ( COPT_USE_PRINTERDEVICE == nOption )
552 m_pWrtShell->SetUseVirDev( !bChecked );
553 bModified = TRUE;
555 else if ( ( COPT_ADD_SPACING == nOption || COPT_ADD_SPACING_AT_PAGES == nOption ) && !bSetParaSpaceMax )
556 bSetParaSpaceMax = true;
557 else if ( COPT_USE_OUR_TABSTOPS == nOption )
559 m_pWrtShell->SetTabCompat( !bChecked );
560 bModified = TRUE;
562 else if ( COPT_NO_EXTLEADING == nOption )
564 m_pWrtShell->SetAddExtLeading( !bChecked );
565 bModified = TRUE;
567 else if ( COPT_USE_LINESPACING == nOption )
569 m_pWrtShell->SetUseFormerLineSpacing( bChecked );
570 bModified = TRUE;
572 else if ( COPT_ADD_TABLESPACING == nOption )
574 m_pWrtShell->SetAddParaSpacingToTableCells( bChecked );
575 bModified = TRUE;
577 else if ( COPT_ADD_TABLESPACING == nOption )
579 m_pWrtShell->SetAddParaSpacingToTableCells( bChecked );
580 bModified = TRUE;
582 else if ( COPT_USE_OBJECTPOSITIONING == nOption )
584 m_pWrtShell->SetUseFormerObjectPositioning( bChecked );
585 bModified = TRUE;
587 else if ( COPT_USE_OUR_TEXTWRAPPING == nOption )
589 m_pWrtShell->SetUseFormerTextWrapping( bChecked );
590 bModified = TRUE;
592 else if ( COPT_CONSIDER_WRAPPINGSTYLE == nOption )
594 m_pWrtShell->SetConsiderWrapOnObjPos( bChecked );
595 bModified = TRUE;
597 else if ( COPT_EXPAND_WORDSPACE == nOption )
599 m_pWrtShell->SetDoNotJustifyLinesWithManualBreak( !bChecked );
600 bModified = TRUE;
604 nSavedOptions = nSavedOptions >> 1;
607 if ( bSetParaSpaceMax )
609 m_pWrtShell->SetParaSpaceMax( m_aOptionsLB.IsChecked( (USHORT)COPT_ADD_SPACING ) );
610 m_pWrtShell->SetParaSpaceMaxAtPages( m_aOptionsLB.IsChecked( (USHORT)COPT_ADD_SPACING_AT_PAGES ) );
611 bModified = TRUE;
615 if ( bModified )
616 WriteOptions();
618 return bModified;
621 // -----------------------------------------------------------------------
623 void SwCompatibilityOptPage::Reset( const SfxItemSet& )
625 m_aOptionsLB.SelectEntryPos( 0 );
627 ULONG nOptions = GetDocumentOptions();
628 SetCurrentOptions( nOptions );
629 m_nSavedOptions = nOptions;