Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/string.hxx>
30 : : #include <tools/shl.hxx>
31 : : #include <swtypes.hxx>
32 : : #include <helpid.h>
33 : : #include <uiitems.hxx>
34 : : #include <modcfg.hxx>
35 : : #include "swmodule.hxx"
36 : : #include "usrpref.hxx"
37 : : #include "wrtsh.hxx"
38 : : #include "linkenum.hxx"
39 : : #include <uitool.hxx>
40 : : #include <view.hxx>
41 : :
42 : : #include "globals.hrc"
43 : : #include "cmdid.h"
44 : :
45 : : #include "optload.hrc"
46 : : #include "optload.hxx"
47 : : #include <svx/dlgutil.hxx>
48 : : #include <svx/htmlmode.hxx>
49 : : #include <fldmgr.hxx>
50 : : #include <poolfmt.hxx>
51 : : #include <expfld.hxx>
52 : : #include <caption.hxx>
53 : : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
54 : :
55 : : #include <svtools/insdlg.hxx>
56 : : #include <sot/clsids.hxx>
57 : : #include <unotools/configmgr.hxx>
58 : : #include <docsh.hxx>
59 : : #include <config.hrc>
60 : : #include <SwStyleNameMapper.hxx>
61 : : #include <numrule.hxx>
62 : : #include <SwNodeNum.hxx>
63 : :
64 : : #include <doc.hxx>
65 : : #include <svl/cjkoptions.hxx>
66 : :
67 : : using namespace ::com::sun::star;
68 : :
69 : : #include <svl/eitem.hxx>
70 : :
71 : 0 : SwLoadOptPage::SwLoadOptPage( Window* pParent, const SfxItemSet& rSet ) :
72 : :
73 : : SfxTabPage( pParent, SW_RES( TP_OPTLOAD_PAGE ), rSet ),
74 : :
75 : : aUpdateFL ( this, SW_RES( FL_UPDATE ) ),
76 : : aLinkFT ( this, SW_RES( FT_LINK ) ),
77 : : aAlwaysRB ( this, SW_RES( RB_ALWAYS ) ),
78 : : aRequestRB ( this, SW_RES( RB_REQUEST ) ),
79 : : aNeverRB ( this, SW_RES( RB_NEVER ) ),
80 : :
81 : : aFieldFT ( this, SW_RES( FT_FIELD ) ),
82 : : aAutoUpdateFields ( this, SW_RES( CB_AUTO_UPDATE_FIELDS ) ),
83 : : aAutoUpdateCharts ( this, SW_RES( CB_AUTO_UPDATE_CHARTS ) ),
84 : :
85 : : aSettingsFL ( this, SW_RES( FL_SETTINGS ) ),
86 : : aMetricFT ( this, SW_RES( FT_METRIC ) ),
87 : : aMetricLB ( this, SW_RES( LB_METRIC ) ),
88 : : aTabFT ( this, SW_RES( FT_TAB ) ),
89 : : aTabMF ( this, SW_RES( MF_TAB ) ),
90 : : aUseSquaredPageMode ( this, SW_RES( CB_USE_SQUARE_PAGE_MODE ) ),
91 : : aUseCharUnit ( this , SW_RES( CB_USE_CHAR_UNIT ) ),
92 : :
93 : : pWrtShell ( NULL ),
94 : : bHTMLMode ( sal_False ),
95 : : nLastTab ( 0 ),
96 : 0 : nOldLinkMode( MANUAL )
97 : :
98 : : {
99 : 0 : FreeResource();
100 : :
101 : 0 : SvxStringArray aMetricArr( SW_RES( STR_ARR_METRIC ) );
102 : 0 : for ( sal_uInt16 i = 0; i < aMetricArr.Count(); ++i )
103 : : {
104 : 0 : String sMetric = aMetricArr.GetStringByPos( i );
105 : 0 : FieldUnit eFUnit = (FieldUnit)aMetricArr.GetValue( i );
106 : :
107 : 0 : switch ( eFUnit )
108 : : {
109 : : case FUNIT_MM:
110 : : case FUNIT_CM:
111 : : case FUNIT_POINT:
112 : : case FUNIT_PICA:
113 : : case FUNIT_INCH:
114 : : {
115 : : // use only these metrics
116 : 0 : sal_uInt16 nPos = aMetricLB.InsertEntry( sMetric );
117 : 0 : aMetricLB.SetEntryData( nPos, (void*)(long)eFUnit );
118 : : }
119 : : default:; //prevent warning
120 : : }
121 : 0 : }
122 : 0 : aMetricLB.SetSelectHdl(LINK(this, SwLoadOptPage, MetricHdl));
123 : :
124 : : const SfxPoolItem* pItem;
125 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem )
126 : 0 : && ((SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
127 : : {
128 : 0 : aTabFT.Hide();
129 : 0 : aTabMF.Hide();
130 : : }
131 : :
132 : 0 : SvtCJKOptions aCJKOptions;
133 : 0 : if(!aCJKOptions.IsAsianTypographyEnabled())
134 : : {
135 : 0 : aUseSquaredPageMode.Hide();
136 : 0 : aUseCharUnit.Hide();
137 : 0 : }
138 : 0 : }
139 : :
140 : 0 : SwLoadOptPage::~SwLoadOptPage()
141 : : {
142 : 0 : }
143 : :
144 : 0 : SfxTabPage* SwLoadOptPage::Create( Window* pParent,
145 : : const SfxItemSet& rAttrSet )
146 : : {
147 : 0 : return new SwLoadOptPage(pParent, rAttrSet );
148 : : }
149 : :
150 : 0 : sal_Bool SwLoadOptPage::FillItemSet( SfxItemSet& rSet )
151 : : {
152 : 0 : sal_Bool bRet = sal_False;
153 : 0 : SwModule* pMod = SW_MOD();
154 : :
155 : 0 : sal_uInt16 nNewLinkMode = AUTOMATIC;
156 : 0 : if (aNeverRB.IsChecked())
157 : 0 : nNewLinkMode = NEVER;
158 : 0 : else if (aRequestRB.IsChecked())
159 : 0 : nNewLinkMode = MANUAL;
160 : :
161 : 0 : SwFldUpdateFlags eFldFlags = aAutoUpdateFields.IsChecked() ?
162 : 0 : aAutoUpdateCharts.IsChecked() ? AUTOUPD_FIELD_AND_CHARTS : AUTOUPD_FIELD_ONLY : AUTOUPD_OFF;
163 : :
164 : 0 : if(aAutoUpdateFields.IsChecked() != aAutoUpdateFields.GetSavedValue() ||
165 : 0 : aAutoUpdateCharts.IsChecked() != aAutoUpdateCharts.GetSavedValue())
166 : : {
167 : 0 : pMod->ApplyFldUpdateFlags(eFldFlags);
168 : 0 : if(pWrtShell)
169 : : {
170 : 0 : pWrtShell->SetFldUpdateFlags(eFldFlags);
171 : 0 : pWrtShell->SetModified();
172 : : }
173 : : }
174 : :
175 : 0 : if (nNewLinkMode != nOldLinkMode)
176 : : {
177 : 0 : pMod->ApplyLinkMode(nNewLinkMode);
178 : 0 : if (pWrtShell)
179 : : {
180 : 0 : pWrtShell->SetLinkUpdMode( nNewLinkMode );
181 : 0 : pWrtShell->SetModified();
182 : : }
183 : :
184 : 0 : bRet = sal_True;
185 : : }
186 : :
187 : 0 : const sal_uInt16 nMPos = aMetricLB.GetSelectEntryPos();
188 : 0 : if ( nMPos != aMetricLB.GetSavedValue() )
189 : : {
190 : : // Double-Cast for VA3.0
191 : 0 : sal_uInt16 nFieldUnit = (sal_uInt16)(long)aMetricLB.GetEntryData( nMPos );
192 : 0 : rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)nFieldUnit ) );
193 : 0 : bRet = sal_True;
194 : : }
195 : :
196 : 0 : if(aTabMF.IsVisible() && aTabMF.GetText() != aTabMF.GetSavedValue())
197 : : {
198 : : rSet.Put(SfxUInt16Item(SID_ATTR_DEFTABSTOP,
199 : 0 : (sal_uInt16)aTabMF.Denormalize(aTabMF.GetValue(FUNIT_TWIP))));
200 : 0 : bRet = sal_True;
201 : : }
202 : :
203 : 0 : sal_Bool bIsUseCharUnitFlag = aUseCharUnit.IsChecked();
204 : 0 : SvtCJKOptions aCJKOptions;
205 : 0 : bIsUseCharUnitFlag = bIsUseCharUnitFlag && aCJKOptions.IsAsianTypographyEnabled();
206 : 0 : if( bIsUseCharUnitFlag != aUseCharUnit.GetSavedValue())
207 : : {
208 : 0 : rSet.Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bIsUseCharUnitFlag ));
209 : 0 : bRet = sal_True;
210 : : }
211 : :
212 : 0 : sal_Bool bIsSquaredPageModeFlag = aUseSquaredPageMode.IsChecked();
213 : 0 : if ( bIsSquaredPageModeFlag != aUseSquaredPageMode.GetSavedValue() )
214 : : {
215 : 0 : pMod->ApplyDefaultPageMode( bIsSquaredPageModeFlag );
216 : 0 : if ( pWrtShell )
217 : : {
218 : 0 : SwDoc* pDoc = pWrtShell->GetDoc();
219 : 0 : pDoc->SetDefaultPageMode( bIsSquaredPageModeFlag );
220 : 0 : pWrtShell->SetModified();
221 : : }
222 : 0 : bRet = sal_True;
223 : : }
224 : :
225 : 0 : return bRet;
226 : : }
227 : :
228 : 0 : void SwLoadOptPage::Reset( const SfxItemSet& rSet)
229 : : {
230 : 0 : const SwMasterUsrPref* pUsrPref = SW_MOD()->GetUsrPref(sal_False);
231 : : const SfxPoolItem* pItem;
232 : :
233 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_WRTSHELL, sal_False, &pItem))
234 : 0 : pWrtShell = (SwWrtShell*)((const SwPtrItem*)pItem)->GetValue();
235 : :
236 : 0 : SwFldUpdateFlags eFldFlags = AUTOUPD_GLOBALSETTING;
237 : 0 : nOldLinkMode = GLOBALSETTING;
238 : 0 : if (pWrtShell)
239 : : {
240 : 0 : eFldFlags = pWrtShell->GetFldUpdateFlags(sal_True);
241 : 0 : nOldLinkMode = pWrtShell->GetLinkUpdMode(sal_True);
242 : : }
243 : 0 : if(GLOBALSETTING == nOldLinkMode)
244 : 0 : nOldLinkMode = pUsrPref->GetUpdateLinkMode();
245 : 0 : if(AUTOUPD_GLOBALSETTING == eFldFlags)
246 : 0 : eFldFlags = pUsrPref->GetFldUpdateFlags();
247 : :
248 : 0 : aAutoUpdateFields.Check(eFldFlags != AUTOUPD_OFF);
249 : 0 : aAutoUpdateCharts.Check(eFldFlags == AUTOUPD_FIELD_AND_CHARTS);
250 : :
251 : 0 : switch (nOldLinkMode)
252 : : {
253 : 0 : case NEVER: aNeverRB.Check(); break;
254 : 0 : case MANUAL: aRequestRB.Check(); break;
255 : 0 : case AUTOMATIC: aAlwaysRB.Check(); break;
256 : : }
257 : :
258 : 0 : aAutoUpdateFields.SaveValue();
259 : 0 : aAutoUpdateCharts.SaveValue();
260 : 0 : aMetricLB.SetNoSelection();
261 : 0 : if ( rSet.GetItemState( SID_ATTR_METRIC ) >= SFX_ITEM_AVAILABLE )
262 : : {
263 : 0 : const SfxUInt16Item& rItem = (SfxUInt16Item&)rSet.Get( SID_ATTR_METRIC );
264 : 0 : FieldUnit eFieldUnit = (FieldUnit)rItem.GetValue();
265 : :
266 : 0 : for ( sal_uInt16 i = 0; i < aMetricLB.GetEntryCount(); ++i )
267 : : {
268 : 0 : if ( (int)(sal_IntPtr)aMetricLB.GetEntryData( i ) == (int)eFieldUnit )
269 : : {
270 : 0 : aMetricLB.SelectEntryPos( i );
271 : 0 : break;
272 : : }
273 : : }
274 : 0 : ::SetFieldUnit(aTabMF, eFieldUnit);
275 : : }
276 : 0 : aMetricLB.SaveValue();
277 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_DEFTABSTOP, sal_False, &pItem))
278 : : {
279 : 0 : nLastTab = ((SfxUInt16Item*)pItem)->GetValue();
280 : 0 : aTabMF.SetValue(aTabMF.Normalize(nLastTab), FUNIT_TWIP);
281 : : }
282 : 0 : aTabMF.SaveValue();
283 : :
284 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem))
285 : : {
286 : 0 : bHTMLMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
287 : : }
288 : :
289 : : //default page mode loading
290 : 0 : if(pWrtShell)
291 : : {
292 : 0 : sal_Bool bSquaredPageMode = pWrtShell->GetDoc()->IsSquaredPageMode();
293 : 0 : aUseSquaredPageMode.Check( bSquaredPageMode );
294 : 0 : aUseSquaredPageMode.SaveValue();
295 : : }
296 : :
297 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_APPLYCHARUNIT, sal_False, &pItem))
298 : : {
299 : 0 : sal_Bool bUseCharUnit = ((const SfxBoolItem*)pItem)->GetValue();
300 : 0 : aUseCharUnit.Check(bUseCharUnit);
301 : : }
302 : : else
303 : : {
304 : 0 : aUseCharUnit.Check(pUsrPref->IsApplyCharUnit());
305 : : }
306 : 0 : aUseCharUnit.SaveValue();
307 : 0 : }
308 : :
309 : 0 : IMPL_LINK_NOARG(SwLoadOptPage, MetricHdl)
310 : : {
311 : 0 : const sal_uInt16 nMPos = aMetricLB.GetSelectEntryPos();
312 : 0 : if(nMPos != USHRT_MAX)
313 : : {
314 : : // Double-Cast for VA3.0
315 : 0 : FieldUnit eFieldUnit = (FieldUnit)(long)aMetricLB.GetEntryData( nMPos );
316 : 0 : sal_Bool bModified = aTabMF.IsModified();
317 : : long nVal = bModified ?
318 : 0 : sal::static_int_cast<sal_Int32, sal_Int64 >( aTabMF.Denormalize( aTabMF.GetValue( FUNIT_TWIP ) )) :
319 : 0 : nLastTab;
320 : 0 : ::SetFieldUnit( aTabMF, eFieldUnit );
321 : 0 : aTabMF.SetValue( aTabMF.Normalize( nVal ), FUNIT_TWIP );
322 : 0 : if(!bModified)
323 : 0 : aTabMF.ClearModifyFlag();
324 : : }
325 : :
326 : 0 : return 0;
327 : : }
328 : :
329 : 0 : SwCaptionOptDlg::SwCaptionOptDlg(Window* pParent, const SfxItemSet& rSet) :
330 : 0 : SfxSingleTabDialog(pParent, rSet, 0)
331 : : {
332 : : // create TabPage
333 : 0 : SetTabPage((SwCaptionOptPage*) SwCaptionOptPage::Create(this, rSet));
334 : 0 : }
335 : :
336 : 0 : SwCaptionOptDlg::~SwCaptionOptDlg()
337 : : {
338 : 0 : }
339 : :
340 : 0 : SwCaptionPreview::SwCaptionPreview( Window* pParent, const ResId& rResId )
341 : 0 : : Window( pParent, rResId )
342 : : {
343 : 0 : maDrawPos = Point( 4, 6 );
344 : :
345 : 0 : Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
346 : 0 : SetBackground( aBack );
347 : 0 : SetFillColor( aBack.GetColor() );
348 : 0 : SetLineColor( aBack.GetColor() );
349 : 0 : SetBorderStyle( WINDOW_BORDER_MONO );
350 : 0 : Font aFont(GetFont());
351 : 0 : aFont.SetHeight(aFont.GetHeight() * 120 / 100 );
352 : 0 : SetFont(aFont);
353 : 0 : }
354 : :
355 : 0 : void SwCaptionPreview::SetPreviewText( const String& rText )
356 : : {
357 : 0 : if( rText != maText )
358 : : {
359 : 0 : maText = rText;
360 : 0 : Invalidate();
361 : : }
362 : 0 : }
363 : :
364 : 0 : void SwCaptionPreview::Paint( const Rectangle& rRect )
365 : : {
366 : 0 : Window::Paint( rRect );
367 : :
368 : 0 : DrawRect( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
369 : 0 : DrawText( Point( 4, 6 ), maText );
370 : 0 : }
371 : :
372 : 0 : SwCaptionOptPage::SwCaptionOptPage( Window* pParent, const SfxItemSet& rSet )
373 : : : SfxTabPage(pParent, SW_RES(TP_OPTCAPTION_PAGE), rSet),
374 : : aCheckFT (this, SW_RES(FT_OBJECTS )),
375 : : aCheckLB (this, SW_RES(CLB_OBJECTS )),
376 : : aFtCaptionOrder(this, SW_RES( FT_ORDER )),
377 : : aLbCaptionOrder(this, SW_RES( LB_ORDER )),
378 : : aPreview (this, SW_RES(WIN_PREVIEW )),
379 : : aSettingsGroupFL(this, SW_RES(FL_SETTINGS_2 )),
380 : : aCategoryText (this, SW_RES(TXT_CATEGORY )),
381 : : aCategoryBox (this, SW_RES(BOX_CATEGORY )),
382 : : aFormatText (this, SW_RES(TXT_FORMAT )),
383 : : aFormatBox (this, SW_RES(BOX_FORMAT )),
384 : : aNumberingSeparatorFT(this, SW_RES(FT_NUM_SEP )),
385 : : aNumberingSeparatorED(this, SW_RES(ED_NUM_SEP )),
386 : : aTextText (this, SW_RES(TXT_TEXT )),
387 : : aTextEdit (this, SW_RES(EDT_TEXT )),
388 : : aPosText (this, SW_RES(TXT_POS )),
389 : : aPosBox (this, SW_RES(BOX_POS )),
390 : : aNumCaptFL (this, SW_RES(FL_NUMCAPT )),
391 : : aFtLevel (this, SW_RES(FT_LEVEL )),
392 : : aLbLevel (this, SW_RES(LB_LEVEL )),
393 : : aFtDelim (this, SW_RES(FT_SEPARATOR )),
394 : : aEdDelim (this, SW_RES(ED_SEPARATOR )),
395 : : aCategoryFL (this, SW_RES(FL_CATEGORY )),
396 : : aCharStyleFT (this, SW_RES(FT_CHARSTYLE )),
397 : : aCharStyleLB (this, SW_RES(LB_CHARSTYLE )),
398 : : aApplyBorderCB (this, SW_RES(CB_APPLYBORDER)),
399 : :
400 : : sSWTable (SW_RES(STR_TABLE )),
401 : : sSWFrame (SW_RES(STR_FRAME )),
402 : : sSWGraphic (SW_RES(STR_GRAPHIC )),
403 : : sOLE (SW_RES(STR_OLE )),
404 : :
405 : : sBegin (SW_RESSTR(STR_BEGINNING )),
406 : : sEnd (SW_RESSTR(STR_END )),
407 : : sAbove (SW_RESSTR(STR_ABOVE )),
408 : : sBelow (SW_RESSTR(STR_CP_BELOW )),
409 : : sNone (SW_RESSTR( STR_CATEGORY_NONE )),
410 : :
411 : 0 : pMgr (new SwFldMgr()),
412 : 0 : bHTMLMode(sal_False)
413 : : {
414 : 0 : Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
415 : 0 : aPreview.SetBackground( aBack );
416 : :
417 : 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_LABEL_ABB, sIllustration );
418 : 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_LABEL_TABLE, sTable );
419 : 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_LABEL_FRAME, sText );
420 : 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_LABEL_DRAWING, sDrawing );
421 : :
422 : : sal_uInt16 i, nCount;
423 : 0 : SwWrtShell *pSh = ::GetActiveWrtShell();
424 : :
425 : : // aFormatBox
426 : 0 : sal_uInt16 nSelFmt = SVX_NUM_ARABIC;
427 : 0 : if (pSh)
428 : : {
429 : 0 : nCount = pMgr->GetFldTypeCount();
430 : : SwFieldType* pFldType;
431 : 0 : for ( i = nCount; i; )
432 : : {
433 : 0 : pFldType = pMgr->GetFldType(USHRT_MAX, --i);
434 : 0 : if (pFldType->GetName().equals(aCategoryBox.GetText()))
435 : : {
436 : 0 : nSelFmt = (sal_uInt16)((SwSetExpFieldType*)pFldType)->GetSeqFormat();
437 : 0 : break;
438 : : }
439 : : }
440 : :
441 : 0 : ::FillCharStyleListBox( aCharStyleLB, pSh->GetView().GetDocShell(), sal_True, sal_True );
442 : : }
443 : :
444 : :
445 : 0 : nCount = pMgr->GetFormatCount(TYP_SEQFLD, sal_False);
446 : 0 : for ( i = 0; i < nCount; ++i )
447 : : {
448 : 0 : aFormatBox.InsertEntry( pMgr->GetFormatStr(TYP_SEQFLD, i) );
449 : 0 : sal_uInt16 nFmtId = pMgr->GetFormatId(TYP_SEQFLD, i);
450 : 0 : aFormatBox.SetEntryData( i, reinterpret_cast<void*>(nFmtId) );
451 : 0 : if( nFmtId == nSelFmt )
452 : 0 : aFormatBox.SelectEntryPos( i );
453 : : }
454 : :
455 : 0 : for (i = 0; i < MAXLEVEL; i++)
456 : 0 : aLbLevel.InsertEntry(String::CreateFromInt32(i + 1));
457 : :
458 : 0 : sal_Unicode nLvl = MAXLEVEL;
459 : 0 : rtl::OUString sDelim(": ");
460 : :
461 : 0 : if (pSh)
462 : : {
463 : : SwSetExpFieldType* pFldType = (SwSetExpFieldType*)pMgr->GetFldType(
464 : 0 : RES_SETEXPFLD, aCategoryBox.GetText() );
465 : 0 : if( pFldType )
466 : : {
467 : 0 : sDelim = pFldType->GetDelimiter();
468 : 0 : nLvl = pFldType->GetOutlineLvl();
469 : : }
470 : : }
471 : :
472 : 0 : aLbLevel.SelectEntryPos( nLvl < MAXLEVEL ? nLvl + 1 : 0 );
473 : 0 : aEdDelim.SetText( sDelim );
474 : :
475 : 0 : aCheckLB.SetHelpId(HID_OPTCAPTION_CLB);
476 : :
477 : 0 : FreeResource();
478 : :
479 : 0 : Link aLk = LINK( this, SwCaptionOptPage, ModifyHdl );
480 : 0 : aCategoryBox.SetModifyHdl( aLk );
481 : 0 : aNumberingSeparatorED.SetModifyHdl( aLk );
482 : 0 : aTextEdit .SetModifyHdl( aLk );
483 : :
484 : 0 : aLk = LINK(this, SwCaptionOptPage, SelectHdl);
485 : 0 : aCategoryBox.SetSelectHdl( aLk );
486 : 0 : aFormatBox .SetSelectHdl( aLk );
487 : :
488 : 0 : aLbCaptionOrder.SetSelectHdl( LINK(this, SwCaptionOptPage, OrderHdl));
489 : :
490 : 0 : aCheckLB.SetSelectHdl( LINK(this, SwCaptionOptPage, ShowEntryHdl) );
491 : 0 : aCheckLB.SetCheckButtonHdl( LINK(this, SwCaptionOptPage, ShowEntryHdl) );
492 : 0 : aCheckLB.SetDeselectHdl( LINK(this, SwCaptionOptPage, SaveEntryHdl) );
493 : 0 : }
494 : :
495 : 0 : SwCaptionOptPage::~SwCaptionOptPage()
496 : : {
497 : 0 : DelUserData();
498 : 0 : delete pMgr;
499 : 0 : }
500 : :
501 : 0 : SfxTabPage* SwCaptionOptPage::Create( Window* pParent,
502 : : const SfxItemSet& rAttrSet )
503 : : {
504 : 0 : return new SwCaptionOptPage(pParent, rAttrSet );
505 : : }
506 : :
507 : 0 : sal_Bool SwCaptionOptPage::FillItemSet( SfxItemSet& )
508 : : {
509 : 0 : sal_Bool bRet = sal_False;
510 : 0 : SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
511 : :
512 : 0 : SaveEntry(aCheckLB.FirstSelected()); // apply current entry
513 : :
514 : 0 : SvLBoxEntry* pEntry = aCheckLB.First();
515 : :
516 : 0 : while (pEntry)
517 : : {
518 : 0 : InsCaptionOpt* pData = (InsCaptionOpt*)pEntry->GetUserData();
519 : 0 : bRet |= pModOpt->SetCapOption(bHTMLMode, pData);
520 : 0 : pEntry = aCheckLB.Next(pEntry);
521 : : }
522 : :
523 : 0 : sal_uInt16 nCheckCount = aCheckLB.GetCheckedEntryCount();
524 : 0 : pModOpt->SetInsWithCaption( bHTMLMode, nCheckCount > 0 );
525 : :
526 : 0 : sal_Int32 nPos = aLbCaptionOrder.GetSelectEntryPos();
527 : 0 : pModOpt->SetCaptionOrderNumberingFirst(nPos == 1 ? sal_True : sal_False );
528 : :
529 : 0 : return bRet;
530 : : }
531 : :
532 : 0 : void SwCaptionOptPage::Reset( const SfxItemSet& rSet)
533 : : {
534 : : const SfxPoolItem* pItem;
535 : 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem))
536 : : {
537 : 0 : bHTMLMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
538 : : }
539 : :
540 : 0 : DelUserData();
541 : 0 : aCheckLB.GetModel()->Clear(); // remove all entries
542 : :
543 : : // Writer objects
544 : 0 : sal_uInt16 nPos = 0;
545 : 0 : aCheckLB.InsertEntry(sSWTable);
546 : 0 : SetOptions(nPos++, TABLE_CAP);
547 : 0 : aCheckLB.InsertEntry(sSWFrame);
548 : 0 : SetOptions(nPos++, FRAME_CAP);
549 : 0 : aCheckLB.InsertEntry(sSWGraphic);
550 : 0 : SetOptions(nPos++, GRAPHIC_CAP);
551 : :
552 : : // get Productname and -version
553 : 0 : rtl::OUString sWithoutVersion( utl::ConfigManager::getProductName() );
554 : : rtl::OUString sComplete(
555 : : sWithoutVersion + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")) +
556 : 0 : utl::ConfigManager::getProductVersion() );
557 : :
558 : 0 : SvObjectServerList aObjS;
559 : 0 : aObjS.FillInsertObjects();
560 : 0 : aObjS.Remove( SvGlobalName( SO3_SW_CLASSID ) ); // remove Writer-ID
561 : :
562 : 0 : for ( sal_uLong i = 0; i < aObjS.Count(); ++i )
563 : : {
564 : 0 : const SvGlobalName &rOleId = aObjS[i].GetClassName();
565 : 0 : const String* pClassName = &aObjS[i].GetHumanName();
566 : 0 : if ( rOleId == SvGlobalName( SO3_OUT_CLASSID ) )
567 : 0 : pClassName = &sOLE;
568 : 0 : String sClass( *pClassName );
569 : : // don't show product version
570 : 0 : sClass.SearchAndReplace( sComplete, sWithoutVersion );
571 : 0 : aCheckLB.InsertEntry( sClass );
572 : 0 : SetOptions( nPos++, OLE_CAP, &rOleId );
573 : 0 : }
574 : : aLbCaptionOrder.SelectEntryPos(
575 : 0 : SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst() ? 1 : 0);
576 : 0 : ModifyHdl();
577 : 0 : }
578 : :
579 : 0 : void SwCaptionOptPage::SetOptions(const sal_uInt16 nPos,
580 : : const SwCapObjType eObjType, const SvGlobalName *pOleId)
581 : : {
582 : 0 : SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
583 : 0 : const InsCaptionOpt* pOpt = pModOpt->GetCapOption(bHTMLMode, eObjType, pOleId);
584 : :
585 : 0 : if (pOpt)
586 : : {
587 : 0 : aCheckLB.SetEntryData(nPos, new InsCaptionOpt(*pOpt));
588 : 0 : aCheckLB.CheckEntryPos(nPos, pOpt->UseCaption());
589 : : }
590 : : else
591 : 0 : aCheckLB.SetEntryData(nPos, new InsCaptionOpt(eObjType, pOleId));
592 : 0 : }
593 : :
594 : 0 : void SwCaptionOptPage::DelUserData()
595 : : {
596 : 0 : SvLBoxEntry* pEntry = aCheckLB.First();
597 : :
598 : 0 : while (pEntry)
599 : : {
600 : 0 : delete (InsCaptionOpt*)pEntry->GetUserData();
601 : 0 : pEntry->SetUserData(0);
602 : 0 : pEntry = aCheckLB.Next(pEntry);
603 : : }
604 : 0 : }
605 : :
606 : 0 : IMPL_LINK_NOARG(SwCaptionOptPage, ShowEntryHdl)
607 : : {
608 : 0 : SvLBoxEntry* pSelEntry = aCheckLB.FirstSelected();
609 : :
610 : 0 : if (pSelEntry)
611 : : {
612 : 0 : sal_Bool bChecked = aCheckLB.IsChecked((sal_uInt16)aCheckLB.GetModel()->GetAbsPos(pSelEntry));
613 : :
614 : 0 : aSettingsGroupFL.Enable( bChecked );
615 : 0 : aCategoryText.Enable( bChecked );
616 : 0 : aCategoryBox.Enable( bChecked );
617 : 0 : aFormatText.Enable( bChecked );
618 : 0 : aFormatBox.Enable( bChecked );
619 : 0 : sal_Bool bNumSep = bChecked && aLbCaptionOrder.GetSelectEntryPos() == 1;
620 : 0 : aNumberingSeparatorED.Enable( bNumSep );
621 : 0 : aNumberingSeparatorFT.Enable( bNumSep );
622 : 0 : aTextText.Enable( bChecked );
623 : 0 : aTextEdit.Enable( bChecked );
624 : 0 : aPosText.Enable( bChecked );
625 : 0 : aPosBox.Enable( bChecked );
626 : 0 : aNumCaptFL.Enable( bChecked );
627 : 0 : aFtLevel.Enable( bChecked );
628 : 0 : aLbLevel.Enable( bChecked );
629 : 0 : aFtDelim.Enable( bChecked );
630 : 0 : aEdDelim.Enable( bChecked );
631 : 0 : aCategoryFL.Enable( bChecked );
632 : 0 : aCharStyleFT.Enable( bChecked );
633 : 0 : aCharStyleLB.Enable( bChecked );
634 : 0 : aApplyBorderCB.Enable( bChecked );
635 : 0 : aPreview.Enable( bChecked );
636 : :
637 : 0 : SwWrtShell *pSh = ::GetActiveWrtShell();
638 : :
639 : 0 : InsCaptionOpt* pOpt = (InsCaptionOpt*)pSelEntry->GetUserData();
640 : :
641 : 0 : aCategoryBox.Clear();
642 : 0 : aCategoryBox.InsertEntry( sNone );
643 : 0 : if (pSh)
644 : : {
645 : 0 : sal_uInt16 nCount = pMgr->GetFldTypeCount();
646 : :
647 : 0 : for (sal_uInt16 i = 0; i < nCount; i++)
648 : : {
649 : 0 : SwFieldType *pType = pMgr->GetFldType( USHRT_MAX, i );
650 : 0 : if( pType->Which() == RES_SETEXPFLD &&
651 : 0 : ((SwSetExpFieldType *) pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
652 : 0 : aCategoryBox.InsertEntry(SwBoxEntry(pType->GetName()));
653 : : }
654 : : }
655 : : else
656 : : {
657 : 0 : aCategoryBox.InsertEntry(SwBoxEntry(sIllustration));
658 : 0 : aCategoryBox.InsertEntry(SwBoxEntry(sTable));
659 : 0 : aCategoryBox.InsertEntry(SwBoxEntry(sText));
660 : 0 : aCategoryBox.InsertEntry(SwBoxEntry(sDrawing));
661 : : }
662 : :
663 : 0 : if(pOpt->GetCategory().Len())
664 : 0 : aCategoryBox.SetText(pOpt->GetCategory());
665 : : else
666 : 0 : aCategoryBox.SetText( sNone );
667 : 0 : if (pOpt->GetCategory().Len() &&
668 : 0 : aCategoryBox.GetEntryPos(pOpt->GetCategory()) == COMBOBOX_ENTRY_NOTFOUND)
669 : 0 : aCategoryBox.InsertEntry(pOpt->GetCategory());
670 : 0 : if (!aCategoryBox.GetText().Len())
671 : : {
672 : 0 : sal_uInt16 nPos = 0;
673 : 0 : switch(pOpt->GetObjType())
674 : : {
675 : : case OLE_CAP:
676 : 0 : case GRAPHIC_CAP: nPos = 1; break;
677 : 0 : case TABLE_CAP: nPos = 2; break;
678 : 0 : case FRAME_CAP: nPos = 3; break;
679 : : }
680 : 0 : aCategoryBox.SetText(aCategoryBox.GetEntry(nPos).GetName());
681 : : }
682 : :
683 : 0 : for (sal_uInt16 i = 0; i < aFormatBox.GetEntryCount(); i++)
684 : : {
685 : 0 : if (pOpt->GetNumType() == (sal_uInt16)(sal_uLong)aFormatBox.GetEntryData(i))
686 : : {
687 : 0 : aFormatBox.SelectEntryPos(i);
688 : 0 : break;
689 : : }
690 : : }
691 : 0 : aTextEdit.SetText(pOpt->GetCaption());
692 : :
693 : 0 : aPosBox.Clear();
694 : 0 : switch (pOpt->GetObjType())
695 : : {
696 : : case GRAPHIC_CAP:
697 : : case TABLE_CAP:
698 : : case OLE_CAP:
699 : 0 : aPosBox.InsertEntry(sAbove);
700 : 0 : aPosBox.InsertEntry(sBelow);
701 : 0 : break;
702 : : case FRAME_CAP:
703 : 0 : aPosBox.InsertEntry(sBegin);
704 : 0 : aPosBox.InsertEntry(sEnd);
705 : 0 : break;
706 : : }
707 : 0 : aPosBox.SelectEntryPos(pOpt->GetPos());
708 : 0 : aPosBox.Enable( pOpt->GetObjType() != GRAPHIC_CAP &&
709 : 0 : pOpt->GetObjType() != OLE_CAP &&
710 : 0 : aPosText.IsEnabled() );
711 : 0 : aPosBox.SelectEntryPos(pOpt->GetPos());
712 : :
713 : 0 : sal_uInt16 nLevelPos = ( pOpt->GetLevel() < MAXLEVEL ) ? pOpt->GetLevel() + 1 : 0;
714 : 0 : aLbLevel.SelectEntryPos( nLevelPos );
715 : 0 : aEdDelim.SetText(pOpt->GetSeparator());
716 : 0 : aNumberingSeparatorED.SetText( pOpt->GetNumSeparator() );
717 : 0 : if(pOpt->GetCharacterStyle().Len())
718 : 0 : aCharStyleLB.SelectEntry( pOpt->GetCharacterStyle() );
719 : : else
720 : 0 : aCharStyleLB.SelectEntryPos( 0 );
721 : 0 : aApplyBorderCB.Enable( aCategoryBox.IsEnabled() &&
722 : 0 : pOpt->GetObjType() != TABLE_CAP && pOpt->GetObjType() != FRAME_CAP );
723 : 0 : aApplyBorderCB.Check( pOpt->CopyAttributes() );
724 : : }
725 : :
726 : 0 : ModifyHdl();
727 : :
728 : 0 : return 0;
729 : : }
730 : :
731 : 0 : IMPL_LINK_NOARG(SwCaptionOptPage, SaveEntryHdl)
732 : : {
733 : 0 : SvLBoxEntry* pEntry = aCheckLB.GetHdlEntry();
734 : :
735 : 0 : if (pEntry) // save all
736 : 0 : SaveEntry(pEntry);
737 : :
738 : 0 : return 0;
739 : : }
740 : :
741 : 0 : void SwCaptionOptPage::SaveEntry(SvLBoxEntry* pEntry)
742 : : {
743 : 0 : if (pEntry)
744 : : {
745 : 0 : InsCaptionOpt* pOpt = (InsCaptionOpt*)pEntry->GetUserData();
746 : :
747 : 0 : pOpt->UseCaption() = aCheckLB.IsChecked((sal_uInt16)aCheckLB.GetModel()->GetAbsPos(pEntry));
748 : 0 : String aName( aCategoryBox.GetText() );
749 : 0 : if(aName == sNone)
750 : 0 : pOpt->SetCategory(aEmptyStr);
751 : : else
752 : 0 : pOpt->SetCategory(comphelper::string::strip(aName, ' '));
753 : 0 : pOpt->SetNumType((sal_uInt16)(sal_uLong)aFormatBox.GetEntryData(aFormatBox.GetSelectEntryPos()));
754 : 0 : pOpt->SetCaption(aTextEdit.IsEnabled() ? aTextEdit.GetText() : aEmptyStr );
755 : 0 : pOpt->SetPos(aPosBox.GetSelectEntryPos());
756 : 0 : sal_uInt16 nPos = aLbLevel.GetSelectEntryPos();
757 : 0 : sal_uInt16 nLevel = ( nPos > 0 && nPos != LISTBOX_ENTRY_NOTFOUND ) ? nPos - 1 : MAXLEVEL;
758 : 0 : pOpt->SetLevel(nLevel);
759 : 0 : pOpt->SetSeparator(aEdDelim.GetText());
760 : 0 : pOpt->SetNumSeparator( aNumberingSeparatorED.GetText());
761 : 0 : if(!aCharStyleLB.GetSelectEntryPos())
762 : 0 : pOpt->SetCharacterStyle(aEmptyStr);
763 : : else
764 : 0 : pOpt->SetCharacterStyle(aCharStyleLB.GetSelectEntry());
765 : 0 : pOpt->CopyAttributes() = aApplyBorderCB.IsChecked();
766 : : }
767 : 0 : }
768 : :
769 : 0 : IMPL_LINK_NOARG(SwCaptionOptPage, ModifyHdl)
770 : : {
771 : 0 : String sFldTypeName = aCategoryBox.GetText();
772 : :
773 : 0 : SfxSingleTabDialog *pDlg = (SfxSingleTabDialog *)GetParent();
774 : 0 : PushButton *pBtn = pDlg->GetOKButton();
775 : 0 : if (pBtn)
776 : 0 : pBtn->Enable(sFldTypeName.Len() != 0);
777 : 0 : sal_Bool bEnable = aCategoryBox.IsEnabled() && sFldTypeName != sNone;
778 : :
779 : 0 : aFormatText.Enable(bEnable);
780 : 0 : aFormatBox.Enable(bEnable);
781 : 0 : aTextText.Enable(bEnable);
782 : 0 : aTextEdit.Enable(bEnable);
783 : :
784 : 0 : DrawSample();
785 : 0 : return 0;
786 : : }
787 : :
788 : 0 : IMPL_LINK_NOARG_INLINE_START(SwCaptionOptPage, SelectHdl)
789 : : {
790 : 0 : DrawSample();
791 : 0 : return 0;
792 : : }
793 : 0 : IMPL_LINK_NOARG_INLINE_END(SwCaptionOptPage, SelectHdl)
794 : :
795 : 0 : IMPL_LINK( SwCaptionOptPage, OrderHdl, ListBox*, pBox )
796 : : {
797 : 0 : DrawSample();
798 : 0 : sal_Int32 nPos = pBox->GetSelectEntryPos();
799 : 0 : aNumberingSeparatorFT.Enable( nPos == 1 );
800 : 0 : aNumberingSeparatorED.Enable( nPos == 1 );
801 : 0 : return 0;
802 : : }
803 : :
804 : 0 : void SwCaptionOptPage::DrawSample()
805 : : {
806 : 0 : String aStr;
807 : :
808 : 0 : if( aCategoryBox.GetText() != sNone)
809 : : {
810 : : //#i61007# order of captions
811 : 0 : bool bOrderNumberingFirst = aLbCaptionOrder.GetSelectEntryPos() == 1;
812 : : // number
813 : : sal_uInt16 nNumFmt = (sal_uInt16)(sal_uLong)aFormatBox.GetEntryData(
814 : 0 : aFormatBox.GetSelectEntryPos() );
815 : 0 : if( SVX_NUM_NUMBER_NONE != nNumFmt )
816 : : {
817 : : //#i61007# order of captions
818 : 0 : if( !bOrderNumberingFirst )
819 : : {
820 : : // category
821 : 0 : aStr += aCategoryBox.GetText();
822 : 0 : aStr += ' ';
823 : : }
824 : :
825 : 0 : SwWrtShell *pSh = ::GetActiveWrtShell();
826 : 0 : String sFldTypeName( aCategoryBox.GetText() );
827 : 0 : if (pSh)
828 : : {
829 : : SwSetExpFieldType* pFldType = (SwSetExpFieldType*)pMgr->GetFldType(
830 : 0 : RES_SETEXPFLD, sFldTypeName );
831 : 0 : if( pFldType && pFldType->GetOutlineLvl() < MAXLEVEL )
832 : : {
833 : 0 : sal_uInt8 nLvl = pFldType->GetOutlineLvl();
834 : 0 : SwNumberTree::tNumberVector aNumVector;
835 : 0 : for( sal_uInt8 i = 0; i <= nLvl; ++i )
836 : 0 : aNumVector.push_back(1);
837 : :
838 : : String sNumber( pSh->GetOutlineNumRule()->MakeNumString(
839 : 0 : aNumVector, sal_False ));
840 : 0 : if( sNumber.Len() )
841 : 0 : (aStr += sNumber) += pFldType->GetDelimiter();
842 : : }
843 : : }
844 : :
845 : 0 : switch( nNumFmt )
846 : : {
847 : 0 : case SVX_NUM_CHARS_UPPER_LETTER: aStr += 'A'; break;
848 : 0 : case SVX_NUM_CHARS_UPPER_LETTER_N: aStr += 'A'; break;
849 : 0 : case SVX_NUM_CHARS_LOWER_LETTER: aStr += 'a'; break;
850 : 0 : case SVX_NUM_CHARS_LOWER_LETTER_N: aStr += 'a'; break;
851 : 0 : case SVX_NUM_ROMAN_UPPER: aStr += 'I'; break;
852 : 0 : case SVX_NUM_ROMAN_LOWER: aStr += 'i'; break;
853 : : //case ARABIC:
854 : 0 : default: aStr += '1'; break;
855 : 0 : }
856 : : }
857 : : //#i61007# order of captions
858 : 0 : if( bOrderNumberingFirst )
859 : : {
860 : 0 : aStr += aNumberingSeparatorED.GetText();
861 : 0 : aStr += aCategoryBox.GetText();
862 : : }
863 : 0 : aStr += aTextEdit.GetText();
864 : : }
865 : 0 : aPreview.SetPreviewText( aStr );
866 : 0 : }
867 : :
868 : : // Description: ComboBox without Spaces
869 : 0 : void CaptionComboBox::KeyInput(const KeyEvent& rEvt)
870 : : {
871 : 0 : if( rEvt.GetKeyCode().GetCode() != KEY_SPACE )
872 : 0 : SwComboBox::KeyInput(rEvt);
873 : 0 : }
874 : :
875 : :
876 : :
877 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|