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