xref: /AOO41X/main/sw/source/ui/dialog/uiregionsw.cxx (revision dec99bbd1eb6ae693d6ee672c1a69e3a32d917e7)
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 #include <hintids.hxx>
31 #include <regionsw.hxx>
32 #include <svl/urihelper.hxx>
33 #include <svl/PasswordHelper.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/eitem.hxx>
38 #include <sfx2/passwd.hxx>
39 #include <sfx2/docfilt.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/linkmgr.hxx>
43 #include <sfx2/docinsert.hxx>
44 #include <sfx2/filedlghelper.hxx>
45 #include <editeng/sizeitem.hxx>
46 #include <svtools/htmlcfg.hxx>
47 
48 #include <comphelper/storagehelper.hxx>
49 #include <uitool.hxx>
50 #include <IMark.hxx>
51 #include <section.hxx>
52 #include <docary.hxx>
53 #include <doc.hxx>                      // fuers SwSectionFmt-Array
54 #include <basesh.hxx>
55 #include <wdocsh.hxx>
56 #include <view.hxx>
57 #include <swmodule.hxx>
58 #include <wrtsh.hxx>
59 #include <swundo.hxx>                   // fuer Undo-Ids
60 #include <column.hxx>
61 #include <fmtfsize.hxx>
62 #include <swunodef.hxx>
63 #include <shellio.hxx>
64 
65 #include <helpid.h>
66 #include <cmdid.h>
67 #include <regionsw.hrc>
68 #include <comcore.hrc>
69 #include <globals.hrc>
70 #include <sfx2/bindings.hxx>
71 #include <svx/htmlmode.hxx>
72 #include <svx/dlgutil.hxx>
73 #include <svx/dialogs.hrc>
74 #include <svx/svxdlg.hxx>
75 #include <svx/flagsdef.hxx>
76 
77 using namespace ::com::sun::star;
78 
79 
80 // sw/inc/docary.hxx
81 SV_IMPL_PTRARR( SwSectionFmts, SwSectionFmtPtr )
82 
83 #define FILE_NAME_LENGTH 17
84 
85 static void   lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox );
86 
lcl_FillList(SwWrtShell & rSh,ComboBox & rSubRegions,ComboBox * pAvailNames,const SwSectionFmt * pNewFmt)87 void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames, const SwSectionFmt* pNewFmt )
88 {
89     const SwSectionFmt* pFmt;
90     if( !pNewFmt )
91     {
92         sal_uInt16 nCount = rSh.GetSectionFmtCount();
93         for(sal_uInt16 i=0;i<nCount;i++)
94         {
95             SectionType eTmpType;
96             if( !(pFmt = &rSh.GetSectionFmt(i))->GetParent() &&
97                     pFmt->IsInNodesArr() &&
98                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
99                     && TOX_HEADER_SECTION != eTmpType )
100             {
101                     String* pString =
102                         new String(pFmt->GetSection()->GetSectionName());
103                     if(pAvailNames)
104                         pAvailNames->InsertEntry(*pString);
105                     rSubRegions.InsertEntry(*pString);
106                     lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
107             }
108         }
109     }
110     else
111     {
112         SwSections aTmpArr;
113         sal_uInt16 nCnt = pNewFmt->GetChildSections(aTmpArr,SORTSECT_POS);
114         if( nCnt )
115         {
116             SectionType eTmpType;
117             for( sal_uInt16 n = 0; n < nCnt; ++n )
118                 if( (pFmt = aTmpArr[n]->GetFmt())->IsInNodesArr()&&
119                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
120                     && TOX_HEADER_SECTION != eTmpType )
121                 {
122                     String* pString =
123                         new String(pFmt->GetSection()->GetSectionName());
124                     if(pAvailNames)
125                         pAvailNames->InsertEntry(*pString);
126                     rSubRegions.InsertEntry(*pString);
127                     lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
128                 }
129         }
130     }
131 }
132 
lcl_FillSubRegionList(SwWrtShell & rSh,ComboBox & rSubRegions,ComboBox * pAvailNames)133 void lcl_FillSubRegionList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames )
134 {
135     lcl_FillList( rSh, rSubRegions, pAvailNames, 0 );
136     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
137     for( IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin();
138         ppMark != pMarkAccess->getBookmarksBegin();
139         ppMark++)
140     {
141         const ::sw::mark::IMark* pBkmk = ppMark->get();
142         if( pBkmk->IsExpanded() )
143             rSubRegions.InsertEntry( pBkmk->GetName() );
144     }
145 }
146 
147 /* -----------------25.06.99 15:38-------------------
148 
149  --------------------------------------------------*/
150 class SwTestPasswdDlg : public SfxPasswordDialog
151 {
152 public:
SwTestPasswdDlg(Window * pParent)153         SwTestPasswdDlg(Window* pParent) :
154         SfxPasswordDialog(pParent)
155         {
156             SetHelpId(HID_DLG_PASSWD_SECTION);
157         }
158 };
159 
160 /*----------------------------------------------------------------------------
161  Beschreibung: User Data Klasse fuer Bereichsinformationen
162 ----------------------------------------------------------------------------*/
163 
164 class SectRepr
165 {
166 private:
167     SwSectionData           m_SectionData;
168     SwFmtCol                m_Col;
169     SvxBrushItem            m_Brush;
170     SwFmtFtnAtTxtEnd        m_FtnNtAtEnd;
171     SwFmtEndAtTxtEnd        m_EndNtAtEnd;
172     SwFmtNoBalancedColumns  m_Balance;
173     SvxFrameDirectionItem   m_FrmDirItem;
174     SvxLRSpaceItem          m_LRSpaceItem;
175     sal_uInt16                  m_nArrPos;
176     // zeigt an, ob evtl. Textinhalt im Bereich ist
177     bool                    m_bContent  : 1;
178     // fuer Multiselektion erst markieren, dann mit der TreeListBox arbeiten!
179     bool                    m_bSelected : 1;
180     uno::Sequence<sal_Int8> m_TempPasswd;
181 
182 public:
183     SectRepr(sal_uInt16 nPos, SwSection& rSect);
operator ==(SectRepr & rSectRef) const184     bool    operator==(SectRepr& rSectRef) const
185             { return m_nArrPos == rSectRef.GetArrPos(); }
186 
operator <(SectRepr & rSectRef) const187     bool    operator< (SectRepr& rSectRef) const
188             { return m_nArrPos <  rSectRef.GetArrPos(); }
189 
GetSectionData()190     SwSectionData &     GetSectionData()        { return m_SectionData; }
GetSectionData() const191     SwSectionData const&GetSectionData() const  { return m_SectionData; }
GetCol()192     SwFmtCol&               GetCol()            { return m_Col; }
GetBackground()193     SvxBrushItem&           GetBackground()     { return m_Brush; }
GetFtnNtAtEnd()194     SwFmtFtnAtTxtEnd&       GetFtnNtAtEnd()     { return m_FtnNtAtEnd; }
GetEndNtAtEnd()195     SwFmtEndAtTxtEnd&       GetEndNtAtEnd()     { return m_EndNtAtEnd; }
GetBalance()196     SwFmtNoBalancedColumns& GetBalance()        { return m_Balance; }
GetFrmDir()197     SvxFrameDirectionItem&  GetFrmDir()         { return m_FrmDirItem; }
GetLRSpace()198     SvxLRSpaceItem&         GetLRSpace()        { return m_LRSpaceItem; }
199 
GetArrPos() const200     sal_uInt16              GetArrPos() const { return m_nArrPos; }
201     String              GetFile() const;
202     String              GetSubRegion() const;
203     void                SetFile(String const& rFile);
204     void                SetFilter(String const& rFilter);
205     void                SetSubRegion(String const& rSubRegion);
206 
IsContent()207     bool                IsContent() { return m_bContent; }
SetContent(bool const bValue)208     void                SetContent(bool const bValue) { m_bContent = bValue; }
209 
SetSelected()210     void                SetSelected() { m_bSelected = true; }
IsSelected() const211     bool                IsSelected() const { return m_bSelected; }
212 
GetTempPasswd()213     uno::Sequence<sal_Int8> & GetTempPasswd() { return m_TempPasswd; }
SetTempPasswd(const uno::Sequence<sal_Int8> & rPasswd)214     void SetTempPasswd(const uno::Sequence<sal_Int8> & rPasswd)
215         { m_TempPasswd = rPasswd; }
216 };
217 
218 
SV_IMPL_OP_PTRARR_SORT(SectReprArr,SectReprPtr)219 SV_IMPL_OP_PTRARR_SORT( SectReprArr, SectReprPtr )
220 
221 SectRepr::SectRepr( sal_uInt16 nPos, SwSection& rSect )
222     : m_SectionData( rSect )
223     , m_Brush( RES_BACKGROUND )
224     , m_FrmDirItem( FRMDIR_ENVIRONMENT, RES_FRAMEDIR )
225     , m_LRSpaceItem( RES_LR_SPACE )
226     , m_nArrPos(nPos)
227     , m_bContent(m_SectionData.GetLinkFileName().Len() == 0)
228     , m_bSelected(false)
229 {
230     SwSectionFmt *pFmt = rSect.GetFmt();
231     if( pFmt )
232     {
233         m_Col = pFmt->GetCol();
234         m_Brush = pFmt->GetBackground();
235         m_FtnNtAtEnd = pFmt->GetFtnAtTxtEnd();
236         m_EndNtAtEnd = pFmt->GetEndAtTxtEnd();
237         m_Balance.SetValue(pFmt->GetBalancedColumns().GetValue());
238         m_FrmDirItem = pFmt->GetFrmDir();
239         m_LRSpaceItem = pFmt->GetLRSpace();
240     }
241 }
242 
SetFile(const String & rFile)243 void SectRepr::SetFile( const String& rFile )
244 {
245     String sNewFile( INetURLObject::decode( rFile, INET_HEX_ESCAPE,
246                                         INetURLObject::DECODE_UNAMBIGUOUS,
247                                         RTL_TEXTENCODING_UTF8 ));
248     String sOldFileName( m_SectionData.GetLinkFileName() );
249     String sSub( sOldFileName.GetToken( 2, sfx2::cTokenSeperator ) );
250 
251     if( rFile.Len() || sSub.Len() )
252     {
253         sNewFile += sfx2::cTokenSeperator;
254         if( rFile.Len() ) // Filter nur mit FileName
255             sNewFile += sOldFileName.GetToken( 1, sfx2::cTokenSeperator );
256 
257         sNewFile += sfx2::cTokenSeperator;
258         sNewFile += sSub;
259     }
260 
261     m_SectionData.SetLinkFileName( sNewFile );
262 
263     if( rFile.Len() || sSub.Len() )
264     {
265         m_SectionData.SetType( FILE_LINK_SECTION );
266     }
267     else
268     {
269         m_SectionData.SetType( CONTENT_SECTION );
270     }
271 }
272 
273 
SetFilter(const String & rFilter)274 void SectRepr::SetFilter( const String& rFilter )
275 {
276     String sNewFile;
277     String sOldFileName( m_SectionData.GetLinkFileName() );
278     String sFile( sOldFileName.GetToken( 0, sfx2::cTokenSeperator ) );
279     String sSub( sOldFileName.GetToken( 2, sfx2::cTokenSeperator ) );
280 
281     if( sFile.Len() )
282         (((( sNewFile = sFile ) += sfx2::cTokenSeperator ) += rFilter )
283                                 += sfx2::cTokenSeperator ) += sSub;
284     else if( sSub.Len() )
285         (( sNewFile = sfx2::cTokenSeperator ) += sfx2::cTokenSeperator ) += sSub;
286 
287     m_SectionData.SetLinkFileName( sNewFile );
288 
289     if( sNewFile.Len() )
290     {
291         m_SectionData.SetType( FILE_LINK_SECTION );
292     }
293 }
294 
SetSubRegion(const String & rSubRegion)295 void SectRepr::SetSubRegion(const String& rSubRegion)
296 {
297     String sNewFile;
298     String sOldFileName( m_SectionData.GetLinkFileName() );
299     String sFilter( sOldFileName.GetToken( 1, sfx2::cTokenSeperator ) );
300     sOldFileName = sOldFileName.GetToken( 0, sfx2::cTokenSeperator );
301 
302     if( rSubRegion.Len() || sOldFileName.Len() )
303         (((( sNewFile = sOldFileName ) += sfx2::cTokenSeperator ) += sFilter )
304                                        += sfx2::cTokenSeperator ) += rSubRegion;
305 
306     m_SectionData.SetLinkFileName( sNewFile );
307 
308     if( rSubRegion.Len() || sOldFileName.Len() )
309     {
310         m_SectionData.SetType( FILE_LINK_SECTION );
311     }
312     else
313     {
314         m_SectionData.SetType( CONTENT_SECTION );
315     }
316 }
317 
318 
GetFile() const319 String SectRepr::GetFile() const
320 {
321     String sLinkFile( m_SectionData.GetLinkFileName() );
322     if( sLinkFile.Len() )
323     {
324         if (DDE_LINK_SECTION == m_SectionData.GetType())
325         {
326             sal_uInt16 n = sLinkFile.SearchAndReplace( sfx2::cTokenSeperator, ' ' );
327             sLinkFile.SearchAndReplace( sfx2::cTokenSeperator, ' ',  n );
328         }
329         else
330             sLinkFile = INetURLObject::decode( sLinkFile.GetToken( 0,
331                                                sfx2::cTokenSeperator ),
332                                         INET_HEX_ESCAPE,
333                                         INetURLObject::DECODE_UNAMBIGUOUS,
334                                         RTL_TEXTENCODING_UTF8 );
335     }
336     return sLinkFile;
337 }
338 
339 
GetSubRegion() const340 String SectRepr::GetSubRegion() const
341 {
342     String sLinkFile( m_SectionData.GetLinkFileName() );
343     if( sLinkFile.Len() )
344         sLinkFile = sLinkFile.GetToken( 2, sfx2::cTokenSeperator );
345     return sLinkFile;
346 }
347 
348 
349 
350 /*----------------------------------------------------------------------------
351  Beschreibung: Dialog Bearbeiten Bereiche
352 ----------------------------------------------------------------------------*/
353 
354 //---------------------------------------------------------------------
355 
SwEditRegionDlg(Window * pParent,SwWrtShell & rWrtSh)356 SwEditRegionDlg::SwEditRegionDlg( Window* pParent, SwWrtShell& rWrtSh )
357     : SfxModalDialog( pParent, SW_RES(MD_EDIT_REGION) ),
358     aNameFL             ( this, SW_RES( FL_NAME ) ),
359     aCurName            ( this, SW_RES( ED_RANAME ) ),
360     aTree               ( this, SW_RES( TLB_SECTION )),
361     aLinkFL             ( this, SW_RES( FL_LINK ) ),
362     aFileCB             ( this, SW_RES( CB_FILE ) ),
363     aDDECB              ( this, SW_RES( CB_DDE ) ) ,
364     aFileNameFT         ( this, SW_RES( FT_FILE ) ) ,
365     aDDECommandFT       ( this, SW_RES( FT_DDE ) ) ,
366     aFileNameED         ( this, SW_RES( ED_FILE ) ),
367     aFilePB             ( this, SW_RES( PB_FILE ) ),
368     aSubRegionFT        ( this, SW_RES( FT_SUBREG ) ) ,
369     aSubRegionED        ( this, SW_RES( LB_SUBREG ) ) ,
370     bSubRegionsFilled( false ),
371 
372     aProtectFL          ( this, SW_RES( FL_PROTECT ) ),
373     aProtectCB          ( this, SW_RES( CB_PROTECT ) ),
374     aPasswdCB           ( this, SW_RES( CB_PASSWD ) ),
375     aPasswdPB           ( this, SW_RES( PB_PASSWD ) ),
376 
377     aHideFL             ( this, SW_RES( FL_HIDE ) ),
378     aHideCB             ( this, SW_RES( CB_HIDE ) ),
379     aConditionFT        ( this, SW_RES( FT_CONDITION ) ),
380     aConditionED        ( this, SW_RES( ED_CONDITION ) ),
381 
382     // --> FME 2004-06-22 #114856# edit in readonly sections
383     aPropertiesFL       ( this, SW_RES( FL_PROPERTIES ) ),
384     aEditInReadonlyCB   ( this, SW_RES( CB_EDIT_IN_READONLY ) ),
385     // <--
386 
387     aOK                 ( this, SW_RES( PB_OK ) ),
388     aCancel             ( this, SW_RES( PB_CANCEL ) ),
389     aOptionsPB          ( this, SW_RES( PB_OPTIONS ) ),
390     aDismiss            ( this, SW_RES( CB_DISMISS ) ),
391     aHelp               ( this, SW_RES( PB_HELP ) ),
392 
393     aImageIL            (       SW_RES(IL_BITMAPS)),
394     aImageILH           (       SW_RES(ILH_BITMAPS)),
395 
396     rSh( rWrtSh ),
397     pAktEntry( 0 ),
398     m_pDocInserter        ( NULL ),
399     m_pOldDefDlgParent    ( NULL ),
400     bDontCheckPasswd    ( sal_True)
401 {
402     FreeResource();
403 
404     bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
405 
406     aTree.SetSelectHdl      ( LINK( this, SwEditRegionDlg, GetFirstEntryHdl));
407     aTree.SetDeselectHdl    ( LINK( this, SwEditRegionDlg, DeselectHdl));
408     aCurName.SetModifyHdl   ( LINK( this, SwEditRegionDlg, NameEditHdl));
409     aConditionED.SetModifyHdl( LINK( this, SwEditRegionDlg, ConditionEditHdl));
410     aOK.SetClickHdl         ( LINK( this, SwEditRegionDlg, OkHdl));
411     aPasswdCB.SetClickHdl   ( LINK( this, SwEditRegionDlg, ChangePasswdHdl));
412     aPasswdPB.SetClickHdl   ( LINK( this, SwEditRegionDlg, ChangePasswdHdl));
413     aHideCB.SetClickHdl     ( LINK( this, SwEditRegionDlg, ChangeHideHdl));
414     // --> FME 2004-06-22 #114856# edit in readonly sections
415     aEditInReadonlyCB.SetClickHdl ( LINK( this, SwEditRegionDlg, ChangeEditInReadonlyHdl));
416     // <--
417 
418     aOptionsPB.Show();
419     aOptionsPB.SetClickHdl  ( LINK( this, SwEditRegionDlg, OptionsHdl));
420     aProtectCB.SetClickHdl  ( LINK( this, SwEditRegionDlg, ChangeProtectHdl));
421     aDismiss.SetClickHdl    ( LINK( this, SwEditRegionDlg, ChangeDismissHdl));
422     aFileCB.SetClickHdl     ( LINK( this, SwEditRegionDlg, UseFileHdl ));
423     aFilePB.SetClickHdl     ( LINK( this, SwEditRegionDlg, FileSearchHdl ));
424     aFileNameED.SetModifyHdl( LINK( this, SwEditRegionDlg, FileNameHdl ));
425     aSubRegionED.SetModifyHdl( LINK( this, SwEditRegionDlg, FileNameHdl ));
426     aSubRegionED.AddEventListener( LINK( this, SwEditRegionDlg, SubRegionEventHdl ));
427     aSubRegionED.EnableAutocomplete( sal_True, sal_True );
428 
429     aTree.SetHelpId(HID_REGION_TREE);
430     aTree.SetSelectionMode( MULTIPLE_SELECTION );
431     aTree.SetStyle(aTree.GetStyle()|WB_HASBUTTONSATROOT|WB_CLIPCHILDREN|WB_HSCROLL);
432     aTree.SetSpaceBetweenEntries(0);
433 
434     if(bWeb)
435     {
436         aConditionFT         .Hide();
437         aConditionED    .Hide();
438         aPasswdCB       .Hide();
439         aHideCB         .Hide();
440 
441         aDDECB              .Hide();
442         aDDECommandFT       .Hide();
443     }
444 
445     aDDECB.SetClickHdl      ( LINK( this, SwEditRegionDlg, DDEHdl ));
446 
447     //Ermitteln der vorhandenen Bereiche
448     pCurrSect = rSh.GetCurrSection();
449     RecurseList( 0, 0 );
450     //falls der Cursor nicht in einem Bereich steht,
451     //wird immer der erste selektiert
452     if( !aTree.FirstSelected() && aTree.First() )
453         aTree.Select( aTree.First() );
454     aTree.Show();
455     bDontCheckPasswd = sal_False;
456 
457     aPasswdPB.SetAccessibleRelationMemberOf(&aProtectFL);
458     aPasswdPB.SetAccessibleRelationLabeledBy(&aPasswdCB);
459     aSubRegionED.SetAccessibleName(aSubRegionFT.GetText());
460     aTree.SetAllEntriesAccessibleRoleType(TREEBOX_ALLITEM_ACCROLE_TYPE_TREE);
461 }
462 /* -----------------------------26.04.01 14:56--------------------------------
463 
464  ---------------------------------------------------------------------------*/
CheckPasswd(CheckBox * pBox)465 sal_Bool SwEditRegionDlg::CheckPasswd(CheckBox* pBox)
466 {
467     if(bDontCheckPasswd)
468         return sal_True;
469     sal_Bool bRet = sal_True;
470     SvLBoxEntry* pEntry = aTree.FirstSelected();
471     while( pEntry )
472     {
473         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
474         if (!pRepr->GetTempPasswd().getLength()
475             && pRepr->GetSectionData().GetPassword().getLength())
476         {
477             SwTestPasswdDlg aPasswdDlg(this);
478             bRet = sal_False;
479             if (aPasswdDlg.Execute())
480             {
481                 String sNewPasswd( aPasswdDlg.GetPassword() );
482                 UNO_NMSPC::Sequence <sal_Int8 > aNewPasswd;
483                 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
484                 if (SvPasswordHelper::CompareHashPassword(
485                         pRepr->GetSectionData().GetPassword(), sNewPasswd))
486                 {
487                     pRepr->SetTempPasswd(aNewPasswd);
488                     bRet = sal_True;
489                 }
490                 else
491                 {
492                     InfoBox(this, SW_RES(REG_WRONG_PASSWORD)).Execute();
493                 }
494             }
495         }
496         pEntry = aTree.NextSelected(pEntry);
497     }
498     if(!bRet && pBox)
499     {
500         //reset old button state
501         if(pBox->IsTriStateEnabled())
502             pBox->SetState(pBox->IsChecked() ? STATE_NOCHECK : STATE_DONTKNOW);
503         else
504             pBox->Check(!pBox->IsChecked());
505     }
506 
507     return bRet;
508 }
509 /*---------------------------------------------------------------------
510     Beschreibung: Durchsuchen nach Child-Sections, rekursiv
511 ---------------------------------------------------------------------*/
512 
RecurseList(const SwSectionFmt * pFmt,SvLBoxEntry * pEntry)513 void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvLBoxEntry* pEntry )
514 {
515     SwSection* pSect = 0;
516     SvLBoxEntry* pSelEntry = 0;
517 
518     if (!pFmt)
519     {
520         sal_uInt16 nCount=rSh.GetSectionFmtCount();
521         for ( sal_uInt16 n=0; n < nCount; n++ )
522         {
523             SectionType eTmpType;
524             if( !( pFmt = &rSh.GetSectionFmt(n))->GetParent() &&
525                 pFmt->IsInNodesArr() &&
526                 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
527                 && TOX_HEADER_SECTION != eTmpType )
528             {
529                 SectRepr* pSectRepr = new SectRepr( n,
530                                             *(pSect=pFmt->GetSection()) );
531                 Image aImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden(), sal_False);
532                 pEntry = aTree.InsertEntry(pSect->GetSectionName(), aImg, aImg);
533                 Image aHCImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden(), sal_True);
534                 aTree.SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
535                 aTree.SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
536                 pEntry->SetUserData(pSectRepr);
537                 RecurseList( pFmt, pEntry );
538                 if (pEntry->HasChilds())
539                     aTree.Expand(pEntry);
540                 if (pCurrSect==pSect)
541                     aTree.Select(pEntry);
542             }
543         }
544     }
545     else
546     {
547         SwSections aTmpArr;
548         SvLBoxEntry* pNEntry;
549         sal_uInt16 nCnt = pFmt->GetChildSections(aTmpArr,SORTSECT_POS);
550         if( nCnt )
551         {
552             for( sal_uInt16 n = 0; n < nCnt; ++n )
553             {
554                 SectionType eTmpType;
555                 pFmt = aTmpArr[n]->GetFmt();
556                 if( pFmt->IsInNodesArr() &&
557                     (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
558                     && TOX_HEADER_SECTION != eTmpType )
559                 {
560                     pSect=aTmpArr[n];
561                     SectRepr* pSectRepr=new SectRepr(
562                                     FindArrPos( pSect->GetFmt() ), *pSect );
563                     Image aImage = BuildBitmap( pSect->IsProtect(),
564                                             pSect->IsHidden(), sal_False);
565                     pNEntry = aTree.InsertEntry(
566                         pSect->GetSectionName(), aImage, aImage, pEntry);
567                     Image aHCImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden(), sal_True);
568                     aTree.SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
569                     aTree.SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
570                     pNEntry->SetUserData(pSectRepr);
571                     RecurseList( aTmpArr[n]->GetFmt(), pNEntry );
572                     if( pNEntry->HasChilds())
573                         aTree.Expand(pNEntry);
574                     if (pCurrSect==pSect)
575                         pSelEntry = pNEntry;
576                 }
577             }
578         }
579     }
580     if(0 != pSelEntry)
581     {
582         aTree.MakeVisible(pSelEntry);
583         aTree.Select(pSelEntry);
584     }
585 }
586 /*---------------------------------------------------------------------
587 
588 ---------------------------------------------------------------------*/
589 
FindArrPos(const SwSectionFmt * pFmt)590 sal_uInt16 SwEditRegionDlg::FindArrPos(const SwSectionFmt* pFmt )
591 {
592     sal_uInt16 nCount=rSh.GetSectionFmtCount();
593     for (sal_uInt16 i=0;i<nCount;i++)
594         if (pFmt==&rSh.GetSectionFmt(i))
595             return i;
596 
597     DBG_ERROR(  "SectionFormat nicht in der Liste" );
598     return USHRT_MAX;
599 }
600 /*---------------------------------------------------------------------
601  Beschreibung:
602 ---------------------------------------------------------------------*/
603 
~SwEditRegionDlg()604 SwEditRegionDlg::~SwEditRegionDlg( )
605 {
606     SvLBoxEntry* pEntry = aTree.First();
607     while( pEntry )
608     {
609         delete (SectRepr*)pEntry->GetUserData();
610         pEntry = aTree.Next( pEntry );
611     }
612 
613     aSectReprArr.DeleteAndDestroy( 0, aSectReprArr.Count() );
614     delete m_pDocInserter;
615 }
616 /* -----------------------------09.10.2001 15:41------------------------------
617 
618  ---------------------------------------------------------------------------*/
SelectSection(const String & rSectionName)619 void    SwEditRegionDlg::SelectSection(const String& rSectionName)
620 {
621     SvLBoxEntry* pEntry = aTree.First();
622     while(pEntry)
623     {
624         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
625         if (pRepr->GetSectionData().GetSectionName() == rSectionName)
626             break;
627         pEntry = aTree.Next(pEntry);
628     }
629     if(pEntry)
630     {
631         aTree.SelectAll( sal_False);
632         aTree.Select(pEntry);
633         aTree.MakeVisible(pEntry);
634     }
635 }
636 /*---------------------------------------------------------------------
637     Beschreibung:   Selektierte Eintrag in der TreeListBox wird im
638                     Edit-Fenster angezeigt
639                     Bei Multiselektion werden einige Controls disabled
640 ---------------------------------------------------------------------*/
641 
IMPL_LINK(SwEditRegionDlg,GetFirstEntryHdl,SvTreeListBox *,pBox)642 IMPL_LINK( SwEditRegionDlg, GetFirstEntryHdl, SvTreeListBox *, pBox )
643 {
644     bDontCheckPasswd = sal_True;
645     SvLBoxEntry* pEntry=pBox->FirstSelected();
646     aHideCB     .Enable(sal_True);
647     // --> FME 2004-06-22 #114856# edit in readonly sections
648     aEditInReadonlyCB.Enable(sal_True);
649     // <--
650     aProtectCB  .Enable(sal_True);
651     aFileCB     .Enable(sal_True);
652     UNO_NMSPC::Sequence <sal_Int8> aCurPasswd;
653     if( 1 < pBox->GetSelectionCount() )
654     {
655         aHideCB.EnableTriState( sal_True );
656         aProtectCB.EnableTriState( sal_True );
657         // --> FME 2004-06-22 #114856# edit in readonly sections
658         aEditInReadonlyCB.EnableTriState ( sal_True );
659         // <--
660         aFileCB.EnableTriState( sal_True );
661 
662         bool bHiddenValid       = true;
663         bool bProtectValid      = true;
664         bool bConditionValid    = true;
665         // --> FME 2004-06-22 #114856# edit in readonly sections
666         bool bEditInReadonlyValid = true;
667         bool bEditInReadonly    = true;
668         // <--
669         bool bHidden            = true;
670         bool bProtect           = true;
671         String sCondition;
672         sal_Bool bFirst             = sal_True;
673         sal_Bool bFileValid         = sal_True;
674         sal_Bool bFile              = sal_True;
675         sal_Bool bPasswdValid       = sal_True;
676 
677         while( pEntry )
678         {
679             SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
680             SwSectionData const& rData( pRepr->GetSectionData() );
681             if(bFirst)
682             {
683                 sCondition      = rData.GetCondition();
684                 bHidden         = rData.IsHidden();
685                 bProtect        = rData.IsProtectFlag();
686                 // --> FME 2004-06-22 #114856# edit in readonly sections
687                 bEditInReadonly = rData.IsEditInReadonlyFlag();
688                 // <--
689                 bFile           = (rData.GetType() != CONTENT_SECTION);
690                 aCurPasswd      = rData.GetPassword();
691             }
692             else
693             {
694                 String sTemp(rData.GetCondition());
695                 if(sCondition != sTemp)
696                     bConditionValid = sal_False;
697                 bHiddenValid      = (bHidden == rData.IsHidden());
698                 bProtectValid     = (bProtect == rData.IsProtectFlag());
699                 // --> FME 2004-06-22 #114856# edit in readonly sections
700                 bEditInReadonlyValid =
701                     (bEditInReadonly == rData.IsEditInReadonlyFlag());
702                 // <--
703                 bFileValid        = (bFile ==
704                     (rData.GetType() != CONTENT_SECTION));
705                 bPasswdValid      = (aCurPasswd == rData.GetPassword());
706             }
707             pEntry = pBox->NextSelected(pEntry);
708             bFirst = sal_False;
709         }
710 
711         aHideCB.SetState( !bHiddenValid ? STATE_DONTKNOW :
712                     bHidden ? STATE_CHECK : STATE_NOCHECK);
713         aProtectCB.SetState( !bProtectValid ? STATE_DONTKNOW :
714                     bProtect ? STATE_CHECK : STATE_NOCHECK);
715         // --> FME 2004-06-22 #114856# edit in readonly sections
716         aEditInReadonlyCB.SetState( !bEditInReadonlyValid ? STATE_DONTKNOW :
717                     bEditInReadonly ? STATE_CHECK : STATE_NOCHECK);
718         // <--
719         aFileCB.SetState(!bFileValid ? STATE_DONTKNOW :
720                     bFile ? STATE_CHECK : STATE_NOCHECK);
721 
722         if(bConditionValid)
723             aConditionED.SetText(sCondition);
724         else
725         {
726 //          aConditionED.SetText(aEmptyStr);
727             aConditionFT.Enable(sal_False);
728             aConditionED.Enable(sal_False);
729         }
730 
731         aFilePB.Enable(sal_False);
732         aFileNameFT .Enable(sal_False);
733         aFileNameED .Enable(sal_False);
734         aSubRegionFT.Enable(sal_False);
735         aSubRegionED.Enable(sal_False);
736 //        aNameFT     .Enable(sal_False);
737         aCurName    .Enable(sal_False);
738         aOptionsPB  .Enable(sal_False);
739         aDDECB              .Enable(sal_False);
740         aDDECommandFT       .Enable(sal_False);
741         sal_Bool bPasswdEnabled = aProtectCB.GetState() == STATE_CHECK;
742         aPasswdCB.Enable(bPasswdEnabled);
743         aPasswdPB.Enable(bPasswdEnabled);
744         if(!bPasswdValid)
745         {
746             pEntry = pBox->FirstSelected();
747             pBox->SelectAll( sal_False );
748             pBox->Select( pEntry );
749             GetFirstEntryHdl(pBox);
750             return 0;
751         }
752         else
753             aPasswdCB.Check(aCurPasswd.getLength() > 0);
754     }
755     else if (pEntry )
756     {
757 //        aNameFT     .Enable(sal_True);
758         aCurName    .Enable(sal_True);
759         aOptionsPB  .Enable(sal_True);
760         SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
761         SwSectionData const& rData( pRepr->GetSectionData() );
762         aConditionED.SetText(rData.GetCondition());
763         aHideCB.Enable();
764         aHideCB.SetState((rData.IsHidden()) ? STATE_CHECK : STATE_NOCHECK);
765         sal_Bool bHide = STATE_CHECK == aHideCB.GetState();
766         aConditionED.Enable(bHide);
767         aConditionFT.Enable(bHide);
768         aPasswdCB.Check(rData.GetPassword().getLength() > 0);
769 
770         aOK.Enable();
771         aPasswdCB.Enable();
772         aCurName.SetText(pBox->GetEntryText(pEntry));
773         aCurName.Enable();
774         aDismiss.Enable();
775         String aFile = pRepr->GetFile();
776         String sSub = pRepr->GetSubRegion();
777         bSubRegionsFilled = false;
778         aSubRegionED.Clear();
779         if(aFile.Len()||sSub.Len())
780         {
781             aFileCB.Check(sal_True);
782             aFileNameED.SetText(aFile);
783             aSubRegionED.SetText(sSub);
784             aDDECB.Check(rData.GetType() == DDE_LINK_SECTION);
785         }
786         else
787         {
788             aFileCB.Check(sal_False);
789             aFileNameED.SetText(aFile);
790             aDDECB.Enable(sal_False);
791             aDDECB.Check(sal_False);
792         }
793         UseFileHdl(&aFileCB);
794         DDEHdl( &aDDECB );
795         aProtectCB.SetState((rData.IsProtectFlag())
796                 ? STATE_CHECK : STATE_NOCHECK);
797         aProtectCB.Enable();
798 
799         // --> FME 2004-06-22 #114856# edit in readonly sections
800         aEditInReadonlyCB.SetState((rData.IsEditInReadonlyFlag())
801                 ? STATE_CHECK : STATE_NOCHECK);
802         aEditInReadonlyCB.Enable();
803         // <--
804 
805         sal_Bool bPasswdEnabled = aProtectCB.IsChecked();
806         aPasswdCB.Enable(bPasswdEnabled);
807         aPasswdPB.Enable(bPasswdEnabled);
808     }
809     bDontCheckPasswd = sal_False;
810     return 0;
811 }
812 /*-----------------28.06.97 09:19-------------------
813 
814 --------------------------------------------------*/
IMPL_LINK(SwEditRegionDlg,DeselectHdl,SvTreeListBox *,pBox)815 IMPL_LINK( SwEditRegionDlg, DeselectHdl, SvTreeListBox *, pBox )
816 {
817     if( !pBox->GetSelectionCount() )
818     {
819         aHideCB     .Enable(sal_False);
820         aProtectCB  .Enable(sal_False);
821         // --> FME 2004-06-22 #114856# edit in readonly sections
822         aEditInReadonlyCB.Enable(sal_False);
823         // <--
824         aPasswdCB   .Enable(sal_False);
825         aPasswdCB   .Enable(sal_False);
826         aConditionFT     .Enable(sal_False);
827         aConditionED.Enable(sal_False);
828         aFileCB     .Enable(sal_False);
829         aFilePB     .Enable(sal_False);
830         aFileNameFT  .Enable(sal_False);
831         aFileNameED  .Enable(sal_False);
832         aSubRegionFT .Enable(sal_False);
833         aSubRegionED .Enable(sal_False);
834 //        aNameFT      .Enable(sal_False);
835         aCurName     .Enable(sal_False);
836         aDDECB              .Enable(sal_False);
837         aDDECommandFT       .Enable(sal_False);
838 
839         UseFileHdl(&aFileCB);
840         DDEHdl( &aDDECB );
841     }
842     return 0;
843 }
844 
845 /*---------------------------------------------------------------------
846     Beschreibung:   Im OkHdl werden die veraenderten Einstellungen
847                     uebernommen und aufgehobene Bereiche geloescht
848 ---------------------------------------------------------------------*/
849 
IMPL_LINK(SwEditRegionDlg,OkHdl,CheckBox *,EMPTYARG)850 IMPL_LINK( SwEditRegionDlg, OkHdl, CheckBox *, EMPTYARG )
851 {
852     // JP 13.03.96:
853     // temp. Array weil sich waehrend des aendern eines Bereiches die
854     // Position innerhalb des "Core-Arrays" verschieben kann:
855     //  - bei gelinkten Bereichen, wenn sie weitere SubBereiche haben oder
856     //    neu erhalten.
857     // JP 30.05.97: StartUndo darf natuerlich auch erst nach dem Kopieren
858     //              der Formate erfolgen (ClearRedo!)
859 
860     const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
861     SwSectionFmts aOrigArray( 0, 5 );
862     aOrigArray.Insert( &rDocFmts, 0 );
863 
864     rSh.StartAllAction();
865     rSh.StartUndo();
866     rSh.ResetSelect( 0,sal_False );
867     SvLBoxEntry* pEntry = aTree.First();
868 
869     while( pEntry )
870     {
871         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
872         SwSectionFmt* pFmt = aOrigArray[ pRepr->GetArrPos() ];
873         if (!pRepr->GetSectionData().IsProtectFlag())
874         {
875             pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
876         }
877         sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
878         if( USHRT_MAX != nNewPos )
879         {
880             SfxItemSet* pSet = pFmt->GetAttrSet().Clone( sal_False );
881             if( pFmt->GetCol() != pRepr->GetCol() )
882                 pSet->Put( pRepr->GetCol() );
883 
884             if( pFmt->GetBackground(sal_False) != pRepr->GetBackground() )
885                 pSet->Put( pRepr->GetBackground() );
886 
887             if( pFmt->GetFtnAtTxtEnd(sal_False) != pRepr->GetFtnNtAtEnd() )
888                 pSet->Put( pRepr->GetFtnNtAtEnd() );
889 
890             if( pFmt->GetEndAtTxtEnd(sal_False) != pRepr->GetEndNtAtEnd() )
891                 pSet->Put( pRepr->GetEndNtAtEnd() );
892 
893             if( pFmt->GetBalancedColumns() != pRepr->GetBalance() )
894                 pSet->Put( pRepr->GetBalance() );
895 
896             if( pFmt->GetFrmDir() != pRepr->GetFrmDir() )
897                 pSet->Put( pRepr->GetFrmDir() );
898 
899             if( pFmt->GetLRSpace() != pRepr->GetLRSpace())
900                 pSet->Put( pRepr->GetLRSpace());
901 
902             rSh.UpdateSection( nNewPos, pRepr->GetSectionData(),
903                             pSet->Count() ? pSet : 0 );
904             delete pSet;
905         }
906         pEntry = aTree.Next( pEntry );
907     }
908 
909     for(sal_uInt16 i = aSectReprArr.Count(); i; )
910     {
911         SwSectionFmt* pFmt = aOrigArray[ aSectReprArr[ --i ]->GetArrPos() ];
912         sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
913         if( USHRT_MAX != nNewPos )
914             rSh.DelSectionFmt( nNewPos );
915     }
916 //    rSh.ChgSectionPasswd(aNewPasswd);
917 
918     aOrigArray.Remove( 0, aOrigArray.Count() );
919 
920     //JP 21.05.97: EndDialog muss vor Ende der EndAction gerufen werden,
921     //              sonst kann es ScrollFehler geben.
922     EndDialog(RET_OK);
923 
924     rSh.EndUndo();
925     rSh.EndAllAction();
926 
927     return 0;
928 }
929 /*---------------------------------------------------------------------
930  Beschreibung: Toggle protect
931 ---------------------------------------------------------------------*/
932 
IMPL_LINK(SwEditRegionDlg,ChangeProtectHdl,TriStateBox *,pBox)933 IMPL_LINK( SwEditRegionDlg, ChangeProtectHdl, TriStateBox *, pBox )
934 {
935     if(!CheckPasswd(pBox))
936         return 0;
937     pBox->EnableTriState( sal_False );
938     SvLBoxEntry* pEntry=aTree.FirstSelected();
939     DBG_ASSERT(pEntry,"kein Entry gefunden");
940     sal_Bool bCheck = STATE_CHECK == pBox->GetState();
941     while( pEntry )
942     {
943         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
944         pRepr->GetSectionData().SetProtectFlag(bCheck);
945         Image aImage = BuildBitmap( bCheck,
946                                     STATE_CHECK == aHideCB.GetState(), sal_False);
947         aTree.SetExpandedEntryBmp(pEntry, aImage, BMP_COLOR_NORMAL);
948         aTree.SetCollapsedEntryBmp(pEntry, aImage, BMP_COLOR_NORMAL);
949         Image aHCImg = BuildBitmap( bCheck, STATE_CHECK == aHideCB.GetState(), sal_True);
950         aTree.SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
951         aTree.SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
952         pEntry = aTree.NextSelected(pEntry);
953     }
954     aPasswdCB.Enable(bCheck);
955     aPasswdPB.Enable(bCheck);
956     return 0;
957 }
958 /*---------------------------------------------------------------------
959  Beschreibung: Toggle hide
960 ---------------------------------------------------------------------*/
961 
IMPL_LINK(SwEditRegionDlg,ChangeHideHdl,TriStateBox *,pBox)962 IMPL_LINK( SwEditRegionDlg, ChangeHideHdl, TriStateBox *, pBox )
963 {
964     if(!CheckPasswd(pBox))
965         return 0;
966     pBox->EnableTriState( sal_False );
967     SvLBoxEntry* pEntry=aTree.FirstSelected();
968     DBG_ASSERT(pEntry,"kein Entry gefunden");
969     while( pEntry )
970     {
971         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
972         pRepr->GetSectionData().SetHidden(STATE_CHECK == pBox->GetState());
973         Image aImage = BuildBitmap(STATE_CHECK == aProtectCB.GetState(),
974                                     STATE_CHECK == pBox->GetState(), sal_False);
975         aTree.SetExpandedEntryBmp(pEntry, aImage, BMP_COLOR_NORMAL);
976         aTree.SetCollapsedEntryBmp(pEntry, aImage, BMP_COLOR_NORMAL);
977         Image aHCImg = BuildBitmap( STATE_CHECK == aProtectCB.GetState(),
978                                     STATE_CHECK == pBox->GetState(), sal_True);
979         aTree.SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
980         aTree.SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
981 
982         pEntry = aTree.NextSelected(pEntry);
983     }
984 
985     sal_Bool bHide = STATE_CHECK == pBox->GetState();
986     aConditionED.Enable(bHide);
987     aConditionFT.Enable(bHide);
988     return 0;
989 }
990 
991 /*---------------------------------------------------------------------
992  Beschreibung: Toggle edit in readonly
993 ---------------------------------------------------------------------*/
994 
IMPL_LINK(SwEditRegionDlg,ChangeEditInReadonlyHdl,TriStateBox *,pBox)995 IMPL_LINK( SwEditRegionDlg, ChangeEditInReadonlyHdl, TriStateBox *, pBox )
996 {
997     if(!CheckPasswd(pBox))
998         return 0;
999     pBox->EnableTriState( sal_False );
1000     SvLBoxEntry* pEntry=aTree.FirstSelected();
1001     DBG_ASSERT(pEntry,"kein Entry gefunden");
1002     while( pEntry )
1003     {
1004         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
1005         pRepr->GetSectionData().SetEditInReadonlyFlag(
1006                 STATE_CHECK == pBox->GetState());
1007         pEntry = aTree.NextSelected(pEntry);
1008     }
1009 
1010     return 0;
1011 }
1012 
1013 /*---------------------------------------------------------------------
1014  Beschreibung: selektierten Bereich aufheben
1015 ---------------------------------------------------------------------*/
1016 
IMPL_LINK(SwEditRegionDlg,ChangeDismissHdl,CheckBox *,EMPTYARG)1017 IMPL_LINK( SwEditRegionDlg, ChangeDismissHdl, CheckBox *, EMPTYARG )
1018 {
1019     if(!CheckPasswd())
1020         return 0;
1021     SvLBoxEntry* pEntry = aTree.FirstSelected();
1022     SvLBoxEntry* pChild;
1023     SvLBoxEntry* pParent;
1024     //zuerst alle selektierten markieren
1025     while(pEntry)
1026     {
1027         const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1028         pSectRepr->SetSelected();
1029         pEntry = aTree.NextSelected(pEntry);
1030     }
1031     pEntry = aTree.FirstSelected();
1032     // dann loeschen
1033     while(pEntry)
1034     {
1035         const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1036         SvLBoxEntry* pRemove = 0;
1037         sal_Bool bRestart = sal_False;
1038         if(pSectRepr->IsSelected())
1039         {
1040             aSectReprArr.Insert( pSectRepr );
1041             while( (pChild = aTree.FirstChild(pEntry) )!= 0 )
1042             {
1043                 //durch das Umhaengen muss wieder am Anfang aufgesetzt werden
1044                 bRestart = sal_True;
1045                 pParent=aTree.GetParent(pEntry);
1046                 aTree.GetModel()->Move(pChild, pParent, aTree.GetModel()->GetRelPos(pEntry));
1047             }
1048             pRemove = pEntry;
1049         }
1050         if(bRestart)
1051             pEntry = aTree.First();
1052         else
1053             pEntry = aTree.Next(pEntry);
1054         if(pRemove)
1055             aTree.GetModel()->Remove( pRemove );
1056     }
1057 
1058     if ( (pEntry=aTree.FirstSelected()) == 0 )
1059     {
1060         aConditionFT.        Enable(sal_False);
1061         aConditionED.   Enable(sal_False);
1062         aDismiss.       Enable(sal_False);
1063         aCurName.       Enable(sal_False);
1064         aProtectCB.     Enable(sal_False);
1065         aPasswdCB.      Enable(sal_False);
1066         aHideCB.        Enable(sal_False);
1067         // --> FME 2004-06-22 #114856# edit in readonly sections
1068         aEditInReadonlyCB.Enable(sal_False);
1069         aEditInReadonlyCB.SetState(STATE_NOCHECK);
1070         // <--
1071         aProtectCB.     SetState(STATE_NOCHECK);
1072         aPasswdCB.      Check(sal_False);
1073         aHideCB.        SetState(STATE_NOCHECK);
1074         aFileCB.        Check(sal_False);
1075         //sonst liegt der Focus auf dem HelpButton
1076         aOK.GrabFocus();
1077         UseFileHdl(&aFileCB);
1078     }
1079     return 0;
1080 }
1081 /*---------------------------------------------------------------------
1082  Beschreibung: CheckBox mit Datei verknuepfen?
1083 ---------------------------------------------------------------------*/
1084 
IMPL_LINK(SwEditRegionDlg,UseFileHdl,CheckBox *,pBox)1085 IMPL_LINK( SwEditRegionDlg, UseFileHdl, CheckBox *, pBox )
1086 {
1087     if(!CheckPasswd(pBox))
1088         return 0;
1089     SvLBoxEntry* pEntry = aTree.FirstSelected();
1090     pBox->EnableTriState(sal_False);
1091     sal_Bool bMulti = 1 < aTree.GetSelectionCount();
1092     sal_Bool bFile = pBox->IsChecked();
1093     if(pEntry)
1094     {
1095         while(pEntry)
1096         {
1097             const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1098             sal_Bool bContent = pSectRepr->IsContent();
1099             if( pBox->IsChecked() && bContent && rSh.HasSelection() )
1100             {
1101                 if( RET_NO == QueryBox( this, SW_RES(QB_CONNECT) ).Execute() )
1102                     pBox->Check( sal_False );
1103             }
1104             if( bFile )
1105                 pSectRepr->SetContent(sal_False);
1106             else
1107             {
1108                 pSectRepr->SetFile(aEmptyStr);
1109                 pSectRepr->SetSubRegion(aEmptyStr);
1110                 pSectRepr->GetSectionData().SetLinkFilePassword(aEmptyStr);
1111             }
1112 
1113             pEntry = aTree.NextSelected(pEntry);
1114         }
1115         aFileNameFT.Enable(bFile && ! bMulti);
1116         aFileNameED.Enable(bFile && ! bMulti);
1117         aFilePB.Enable(bFile && ! bMulti);
1118         aSubRegionED.Enable(bFile && ! bMulti);
1119         aSubRegionFT.Enable(bFile && ! bMulti);
1120         aDDECommandFT.Enable(bFile && ! bMulti);
1121         aDDECB.Enable(bFile && ! bMulti);
1122         if( bFile )
1123         {
1124             aProtectCB.SetState(STATE_CHECK);
1125             aFileNameED.GrabFocus();
1126 
1127         }
1128         else
1129         {
1130             aDDECB.Check(sal_False);
1131             DDEHdl(&aDDECB);
1132 //          aFileNameED.SetText(aEmptyStr);
1133             aSubRegionED.SetText(aEmptyStr);
1134         }
1135     }
1136     else
1137     {
1138         pBox->Check(sal_False);
1139         pBox->Enable(sal_False);
1140         aFilePB.Enable(sal_False);
1141         aFileNameED.Enable(sal_False);
1142         aFileNameFT.Enable(sal_False);
1143         aSubRegionED.Enable(sal_False);
1144         aSubRegionFT.Enable(sal_False);
1145         aDDECB.Check(sal_False);
1146         aDDECB.Enable(sal_False);
1147         aDDECommandFT.Enable(sal_False);
1148     }
1149     return 0;
1150 }
1151 
1152 /*---------------------------------------------------------------------
1153     Beschreibung: Dialog Datei einfuegen rufen
1154 ---------------------------------------------------------------------*/
1155 
IMPL_LINK(SwEditRegionDlg,FileSearchHdl,PushButton *,EMPTYARG)1156 IMPL_LINK( SwEditRegionDlg, FileSearchHdl, PushButton *, EMPTYARG )
1157 {
1158     if(!CheckPasswd(0))
1159         return 0;
1160 
1161     m_pOldDefDlgParent = Application::GetDefDialogParent();
1162     Application::SetDefDialogParent( this );
1163     if ( m_pDocInserter )
1164         delete m_pDocInserter;
1165     m_pDocInserter = new ::sfx2::DocumentInserter( 0, String::CreateFromAscii("swriter") );
1166     m_pDocInserter->StartExecuteModal( LINK( this, SwEditRegionDlg, DlgClosedHdl ) );
1167     return 0;
1168 }
1169 
1170 /*---------------------------------------------------------------------
1171     Beschreibung:
1172 ---------------------------------------------------------------------*/
1173 
IMPL_LINK(SwEditRegionDlg,OptionsHdl,PushButton *,EMPTYARG)1174 IMPL_LINK( SwEditRegionDlg, OptionsHdl, PushButton *, EMPTYARG )
1175 {
1176     if(!CheckPasswd())
1177         return 0;
1178     SvLBoxEntry* pEntry = aTree.FirstSelected();
1179 
1180     if(pEntry)
1181     {
1182         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1183         SfxItemSet aSet(rSh.GetView().GetPool(),
1184                             RES_COL, RES_COL,
1185                             RES_COLUMNBALANCE, RES_FRAMEDIR,
1186                             RES_BACKGROUND, RES_BACKGROUND,
1187                             RES_FRM_SIZE, RES_FRM_SIZE,
1188                             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
1189                             RES_LR_SPACE, RES_LR_SPACE,
1190                             RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
1191                             0);
1192 
1193         aSet.Put( pSectRepr->GetCol() );
1194         aSet.Put( pSectRepr->GetBackground() );
1195         aSet.Put( pSectRepr->GetFtnNtAtEnd() );
1196         aSet.Put( pSectRepr->GetEndNtAtEnd() );
1197         aSet.Put( pSectRepr->GetBalance() );
1198         aSet.Put( pSectRepr->GetFrmDir() );
1199         aSet.Put( pSectRepr->GetLRSpace() );
1200 
1201         const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
1202         SwSectionFmts aOrigArray( 0, 5 );
1203         aOrigArray.Insert( &rDocFmts, 0 );
1204 
1205         SwSectionFmt* pFmt = aOrigArray[pSectRepr->GetArrPos()];
1206         long nWidth = rSh.GetSectionWidth(*pFmt);
1207         aOrigArray.Remove( 0, aOrigArray.Count() );
1208         if (!nWidth)
1209             nWidth = USHRT_MAX;
1210 
1211         aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
1212         aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
1213 
1214         SwSectionPropertyTabDialog aTabDlg(this, aSet, rSh);
1215         if(RET_OK == aTabDlg.Execute())
1216         {
1217             const SfxItemSet* pOutSet = aTabDlg.GetOutputItemSet();
1218             if( pOutSet && pOutSet->Count() )
1219             {
1220                 const SfxPoolItem *pColItem, *pBrushItem,
1221                                   *pFtnItem, *pEndItem, *pBalanceItem,
1222                                   *pFrmDirItem, *pLRSpaceItem;
1223                 SfxItemState eColState = pOutSet->GetItemState(
1224                                         RES_COL, sal_False, &pColItem );
1225                 SfxItemState eBrushState = pOutSet->GetItemState(
1226                                         RES_BACKGROUND, sal_False, &pBrushItem );
1227                 SfxItemState eFtnState = pOutSet->GetItemState(
1228                                         RES_FTN_AT_TXTEND, sal_False, &pFtnItem );
1229                 SfxItemState eEndState = pOutSet->GetItemState(
1230                                         RES_END_AT_TXTEND, sal_False, &pEndItem );
1231                 SfxItemState eBalanceState = pOutSet->GetItemState(
1232                                         RES_COLUMNBALANCE, sal_False, &pBalanceItem );
1233                 SfxItemState eFrmDirState = pOutSet->GetItemState(
1234                                         RES_FRAMEDIR, sal_False, &pFrmDirItem );
1235                 SfxItemState eLRState = pOutSet->GetItemState(
1236                                         RES_LR_SPACE, sal_False, &pLRSpaceItem);
1237 
1238                 if( SFX_ITEM_SET == eColState ||
1239                     SFX_ITEM_SET == eBrushState ||
1240                     SFX_ITEM_SET == eFtnState ||
1241                     SFX_ITEM_SET == eEndState ||
1242                     SFX_ITEM_SET == eBalanceState||
1243                     SFX_ITEM_SET == eFrmDirState||
1244                     SFX_ITEM_SET == eLRState)
1245                 {
1246                     SvLBoxEntry* pSelEntry = aTree.FirstSelected();
1247                     while( pSelEntry )
1248                     {
1249                         SectReprPtr pRepr = (SectReprPtr)pSelEntry->GetUserData();
1250                         if( SFX_ITEM_SET == eColState )
1251                             pRepr->GetCol() = *(SwFmtCol*)pColItem;
1252                         if( SFX_ITEM_SET == eBrushState )
1253                             pRepr->GetBackground() = *(SvxBrushItem*)pBrushItem;
1254                         if( SFX_ITEM_SET == eFtnState )
1255                             pRepr->GetFtnNtAtEnd() = *(SwFmtFtnAtTxtEnd*)pFtnItem;
1256                         if( SFX_ITEM_SET == eEndState )
1257                             pRepr->GetEndNtAtEnd() = *(SwFmtEndAtTxtEnd*)pEndItem;
1258                         if( SFX_ITEM_SET == eBalanceState )
1259                             pRepr->GetBalance().SetValue(((SwFmtNoBalancedColumns*)pBalanceItem)->GetValue());
1260                         if( SFX_ITEM_SET == eFrmDirState )
1261                             pRepr->GetFrmDir().SetValue(((SvxFrameDirectionItem*)pFrmDirItem)->GetValue());
1262                         if( SFX_ITEM_SET == eLRState )
1263                             pRepr->GetLRSpace() = *(SvxLRSpaceItem*)pLRSpaceItem;
1264 
1265                         pSelEntry = aTree.NextSelected(pSelEntry);
1266                     }
1267                 }
1268             }
1269         }
1270     }
1271 
1272     return 0;
1273 }
1274 
1275 /*---------------------------------------------------------------------
1276     Beschreibung:   Uebernahme des Dateinamen oder
1277                     des verknuepften Bereichs
1278 ---------------------------------------------------------------------*/
1279 
IMPL_LINK(SwEditRegionDlg,FileNameHdl,Edit *,pEdit)1280 IMPL_LINK( SwEditRegionDlg, FileNameHdl, Edit *, pEdit )
1281 {
1282     Selection aSelect = pEdit->GetSelection();
1283     if(!CheckPasswd())
1284         return 0;
1285     pEdit->SetSelection(aSelect);
1286     SvLBoxEntry* pEntry=aTree.FirstSelected();
1287     DBG_ASSERT(pEntry,"kein Entry gefunden");
1288     SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1289     if(pEdit == &aFileNameED)
1290     {
1291         bSubRegionsFilled = false;
1292         aSubRegionED.Clear();
1293         if( aDDECB.IsChecked() )
1294         {
1295             String sLink( pEdit->GetText() );
1296             sal_uInt16 nPos = 0;
1297             while( STRING_NOTFOUND != (nPos = sLink.SearchAscii( "  ", nPos )) )
1298                 sLink.Erase( nPos--, 1 );
1299 
1300             nPos = sLink.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1301             sLink.SearchAndReplace( ' ', sfx2::cTokenSeperator, nPos );
1302 
1303             pSectRepr->GetSectionData().SetLinkFileName( sLink );
1304             pSectRepr->GetSectionData().SetType( DDE_LINK_SECTION );
1305         }
1306         else
1307         {
1308             String sTmp(pEdit->GetText());
1309             if(sTmp.Len())
1310             {
1311                 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
1312                 INetURLObject aAbs;
1313                 if( pMedium )
1314                     aAbs = pMedium->GetURLObject();
1315                 sTmp = URIHelper::SmartRel2Abs(
1316                     aAbs, sTmp, URIHelper::GetMaybeFileHdl() );
1317             }
1318             pSectRepr->SetFile( sTmp );
1319             pSectRepr->GetSectionData().SetLinkFilePassword( aEmptyStr );
1320         }
1321     }
1322     else
1323     {
1324         pSectRepr->SetSubRegion( pEdit->GetText() );
1325     }
1326     return 0;
1327 }
1328 /*---------------------------------------------------------------------
1329     Beschreibung:
1330 ---------------------------------------------------------------------*/
1331 
IMPL_LINK(SwEditRegionDlg,DDEHdl,CheckBox *,pBox)1332 IMPL_LINK( SwEditRegionDlg, DDEHdl, CheckBox*, pBox )
1333 {
1334     if(!CheckPasswd(pBox))
1335         return 0;
1336     SvLBoxEntry* pEntry=aTree.FirstSelected();
1337     if(pEntry)
1338     {
1339         sal_Bool bFile = aFileCB.IsChecked();
1340         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1341         SwSectionData & rData( pSectRepr->GetSectionData() );
1342         sal_Bool bDDE = pBox->IsChecked();
1343         if(bDDE)
1344         {
1345             aFileNameFT.Hide();
1346             aDDECommandFT.Enable();
1347             aDDECommandFT.Show();
1348             aSubRegionFT.Hide();
1349             aSubRegionED.Hide();
1350             if (FILE_LINK_SECTION == rData.GetType())
1351             {
1352                 pSectRepr->SetFile(aEmptyStr);
1353                 aFileNameED.SetText(aEmptyStr);
1354                 rData.SetLinkFilePassword( aEmptyStr );
1355             }
1356             rData.SetType(DDE_LINK_SECTION);
1357             aFileNameED.SetAccessibleName(aDDECommandFT.GetText());
1358         }
1359         else
1360         {
1361             aDDECommandFT.Hide();
1362             aFileNameFT.Enable(bFile);
1363             aFileNameFT.Show();
1364             aSubRegionED.Show();
1365             aSubRegionFT.Show();
1366             aSubRegionED.Enable(bFile);
1367             aSubRegionFT.Enable(bFile);
1368             aSubRegionED.Enable(bFile);
1369             if (DDE_LINK_SECTION == rData.GetType())
1370             {
1371                 rData.SetType(FILE_LINK_SECTION);
1372                 pSectRepr->SetFile(aEmptyStr);
1373                 rData.SetLinkFilePassword( aEmptyStr );
1374                 aFileNameED.SetText(aEmptyStr);
1375             }
1376             aFileNameED.SetAccessibleName(aFileNameFT.GetText());
1377         }
1378         aFilePB.Enable(bFile && !bDDE);
1379     }
1380     return 0;
1381 }
1382 /*---------------------------------------------------------------------
1383 
1384 ---------------------------------------------------------------------*/
1385 
IMPL_LINK(SwEditRegionDlg,ChangePasswdHdl,Button *,pBox)1386 IMPL_LINK( SwEditRegionDlg, ChangePasswdHdl, Button *, pBox )
1387 {
1388     sal_Bool bChange = pBox == &aPasswdPB;
1389     if(!CheckPasswd(0))
1390     {
1391         if(!bChange)
1392             aPasswdCB.Check(!aPasswdCB.IsChecked());
1393         return 0;
1394     }
1395     SvLBoxEntry* pEntry=aTree.FirstSelected();
1396     sal_Bool bSet = bChange ? bChange : aPasswdCB.IsChecked();
1397     DBG_ASSERT(pEntry,"kein Entry gefunden");
1398     while( pEntry )
1399     {
1400         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
1401         if(bSet)
1402         {
1403             if(!pRepr->GetTempPasswd().getLength() || bChange)
1404             {
1405                 SwTestPasswdDlg aPasswdDlg(this);
1406                 aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
1407                 if(RET_OK == aPasswdDlg.Execute())
1408                 {
1409                     String sNewPasswd( aPasswdDlg.GetPassword() );
1410                     if( aPasswdDlg.GetConfirm() == sNewPasswd )
1411                     {
1412                         SvPasswordHelper::GetHashPassword( pRepr->GetTempPasswd(), sNewPasswd );
1413                     }
1414                     else
1415                     {
1416                         InfoBox(pBox, SW_RES(REG_WRONG_PASSWD_REPEAT)).Execute();
1417                         ChangePasswdHdl(pBox);
1418                         break;
1419                     }
1420                 }
1421                 else
1422                 {
1423                     if(!bChange)
1424                         aPasswdCB.Check(sal_False);
1425                     break;
1426                 }
1427             }
1428             pRepr->GetSectionData().SetPassword(pRepr->GetTempPasswd());
1429         }
1430         else
1431         {
1432             pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
1433         }
1434         pEntry = aTree.NextSelected(pEntry);
1435     }
1436     return 0;
1437 }
1438 /*---------------------------------------------------------------------
1439     Beschreibung:   Aktueller Bereichsname wird sofort beim editieren
1440                     in die TreeListBox eingetragen, mit leerem String
1441                     kein Ok()
1442 ---------------------------------------------------------------------*/
1443 
IMPL_LINK(SwEditRegionDlg,NameEditHdl,Edit *,EMPTYARG)1444 IMPL_LINK( SwEditRegionDlg, NameEditHdl, Edit *, EMPTYARG )
1445 {
1446     if(!CheckPasswd(0))
1447         return 0;
1448     SvLBoxEntry* pEntry=aTree.FirstSelected();
1449     DBG_ASSERT(pEntry,"kein Entry gefunden");
1450     if (pEntry)
1451     {
1452         String  aName = aCurName.GetText();
1453         aTree.SetEntryText(pEntry,aName);
1454         SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
1455         pRepr->GetSectionData().SetSectionName(aName);
1456 
1457         aOK.Enable(aName.Len() != 0);
1458     }
1459     return 0;
1460 }
1461 /*---------------------------------------------------------------------
1462 
1463 ---------------------------------------------------------------------*/
1464 
IMPL_LINK(SwEditRegionDlg,ConditionEditHdl,Edit *,pEdit)1465 IMPL_LINK( SwEditRegionDlg, ConditionEditHdl, Edit *, pEdit )
1466 {
1467     Selection aSelect = pEdit->GetSelection();
1468     if(!CheckPasswd(0))
1469         return 0;
1470     pEdit->SetSelection(aSelect);
1471     SvLBoxEntry* pEntry = aTree.FirstSelected();
1472     DBG_ASSERT(pEntry,"kein Entry gefunden");
1473     while( pEntry )
1474     {
1475         SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
1476         pRepr->GetSectionData().SetCondition(pEdit->GetText());
1477         pEntry = aTree.NextSelected(pEntry);
1478     }
1479     return 0;
1480 }
1481 
IMPL_LINK(SwEditRegionDlg,DlgClosedHdl,sfx2::FileDialogHelper *,_pFileDlg)1482 IMPL_LINK( SwEditRegionDlg, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
1483 {
1484     String sFileName, sFilterName, sPassword;
1485     if ( _pFileDlg->GetError() == ERRCODE_NONE )
1486     {
1487         SfxMedium* pMedium = m_pDocInserter->CreateMedium();
1488         if ( pMedium )
1489         {
1490             sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1491             sFilterName = pMedium->GetFilter()->GetFilterName();
1492             const SfxPoolItem* pItem;
1493             if ( SFX_ITEM_SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, sal_False, &pItem ) )
1494                 sPassword = ( (SfxStringItem*)pItem )->GetValue();
1495             ::lcl_ReadSections( *pMedium, aSubRegionED );
1496             delete pMedium;
1497         }
1498     }
1499 
1500     SvLBoxEntry* pEntry = aTree.FirstSelected();
1501     DBG_ASSERT( pEntry, "no entry found" );
1502     if ( pEntry )
1503     {
1504         SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1505         pSectRepr->SetFile( sFileName );
1506         pSectRepr->SetFilter( sFilterName );
1507         pSectRepr->GetSectionData().SetLinkFilePassword(sPassword);
1508         aFileNameED.SetText( pSectRepr->GetFile() );
1509     }
1510 
1511     Application::SetDefDialogParent( m_pOldDefDlgParent );
1512     return 0;
1513 }
1514 /*-- 03.09.2009 16:24:18---------------------------------------------------
1515 
1516   -----------------------------------------------------------------------*/
IMPL_LINK(SwEditRegionDlg,SubRegionEventHdl,VclWindowEvent *,pEvent)1517 IMPL_LINK( SwEditRegionDlg, SubRegionEventHdl, VclWindowEvent *, pEvent )
1518 {
1519     if( !bSubRegionsFilled && pEvent && pEvent->GetId() == VCLEVENT_DROPDOWN_PRE_OPEN )
1520     {
1521         //if necessary fill the names bookmarks/sections/tables now
1522 
1523         rtl::OUString sFileName = aFileNameED.GetText();
1524         if(sFileName.getLength())
1525         {
1526             SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
1527             INetURLObject aAbs;
1528             if( pMedium )
1529                 aAbs = pMedium->GetURLObject();
1530             sFileName = URIHelper::SmartRel2Abs(
1531                     aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1532 
1533             //load file and set the shell
1534             SfxMedium aMedium( sFileName, STREAM_STD_READ );
1535             sFileName = aMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1536             ::lcl_ReadSections( aMedium, aSubRegionED );
1537         }
1538         else
1539             lcl_FillSubRegionList( rSh, aSubRegionED, 0 );
1540         bSubRegionsFilled = true;
1541     }
1542     return 0;
1543 }
1544 
1545 /* -----------------------------08.05.2002 15:00------------------------------
1546 
1547  ---------------------------------------------------------------------------*/
BuildBitmap(sal_Bool bProtect,sal_Bool bHidden,sal_Bool bHighContrast)1548 Image SwEditRegionDlg::BuildBitmap(sal_Bool bProtect,sal_Bool bHidden, sal_Bool bHighContrast)
1549 {
1550     ImageList& rImgLst = bHighContrast ? aImageILH : aImageIL;
1551     return rImgLst.GetImage((!bHidden+(bProtect<<1)) + 1);
1552 }
1553 
1554 /*--------------------------------------------------------------------
1555     Beschreibung:   Hilfsfunktion - Bereichsnamen aus dem Medium lesen
1556  --------------------------------------------------------------------*/
1557 
lcl_ReadSections(SfxMedium & rMedium,ComboBox & rBox)1558 static void lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox )
1559 {
1560     rBox.Clear();
1561     uno::Reference < embed::XStorage > xStg;
1562     if( rMedium.IsStorage() && (xStg = rMedium.GetStorage()).is() )
1563     {
1564         SvStrings aArr( 10, 10 );
1565         sal_uInt32 nFormat = SotStorage::GetFormatID( xStg );
1566         if ( nFormat == SOT_FORMATSTR_ID_STARWRITER_60 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_60 ||
1567             nFormat == SOT_FORMATSTR_ID_STARWRITER_8 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_8)
1568             SwGetReaderXML()->GetSectionList( rMedium, aArr );
1569 
1570         for( sal_uInt16 n = 0; n < aArr.Count(); ++n )
1571             rBox.InsertEntry( *aArr[ n ] );
1572 
1573         aArr.DeleteAndDestroy(0, aArr.Count());
1574     }
1575 }
1576 /* -----------------21.05.99 10:16-------------------
1577  *
1578  * --------------------------------------------------*/
SwInsertSectionTabDialog(Window * pParent,const SfxItemSet & rSet,SwWrtShell & rSh)1579 SwInsertSectionTabDialog::SwInsertSectionTabDialog(
1580             Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh) :
1581     SfxTabDialog( pParent, SW_RES(DLG_INSERT_SECTION), &rSet ),
1582     rWrtSh(rSh)
1583     , m_pSectionData(0)
1584 {
1585     String sInsert(SW_RES(ST_INSERT));
1586     GetOKButton().SetText(sInsert);
1587     FreeResource();
1588     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1589     DBG_ASSERT(pFact, "Dialogdiet fail!");
1590     AddTabPage(TP_INSERT_SECTION, SwInsertSectionTabPage::Create, 0);
1591     AddTabPage(TP_COLUMN,   SwColumnPage::Create,    0);
1592     AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0);
1593     AddTabPage(TP_SECTION_FTNENDNOTES, SwSectionFtnEndTabPage::Create, 0);
1594     AddTabPage(TP_SECTION_INDENTS, SwSectionIndentTabPage::Create, 0);
1595 
1596     SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
1597     long nHtmlMode = pHtmlOpt->GetExportMode();
1598 
1599     sal_Bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
1600     if(bWeb)
1601     {
1602         RemoveTabPage(TP_SECTION_FTNENDNOTES);
1603         RemoveTabPage(TP_SECTION_INDENTS);
1604         if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
1605             RemoveTabPage(TP_COLUMN);
1606     }
1607     SetCurPageId(TP_INSERT_SECTION);
1608 }
1609 /* -----------------21.05.99 10:17-------------------
1610  *
1611  * --------------------------------------------------*/
~SwInsertSectionTabDialog()1612 SwInsertSectionTabDialog::~SwInsertSectionTabDialog()
1613 {
1614 }
1615 /* -----------------21.05.99 10:23-------------------
1616  *
1617  * --------------------------------------------------*/
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)1618 void SwInsertSectionTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
1619 {
1620     if(TP_INSERT_SECTION == nId)
1621         ((SwInsertSectionTabPage&)rPage).SetWrtShell(rWrtSh);
1622     else if( TP_BACKGROUND == nId  )
1623     {
1624             SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1625             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
1626             rPage.PageCreated(aSet);
1627     }
1628     else if( TP_COLUMN == nId )
1629     {
1630         const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)GetInputSetImpl()->Get(RES_FRM_SIZE);
1631         ((SwColumnPage&)rPage).SetPageWidth(rSize.GetWidth());
1632         ((SwColumnPage&)rPage).ShowBalance(sal_True);
1633         ((SwColumnPage&)rPage).SetInSection(sal_True);
1634     }
1635     else if(TP_SECTION_INDENTS == nId)
1636         ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
1637 }
1638 /* -----------------21.05.99 13:08-------------------
1639  *
1640  * --------------------------------------------------*/
1641 
SetSectionData(SwSectionData const & rSect)1642 void SwInsertSectionTabDialog::SetSectionData(SwSectionData const& rSect)
1643 {
1644     m_pSectionData.reset( new SwSectionData(rSect) );
1645 }
1646 /* -----------------21.05.99 13:10-------------------
1647  *
1648  * --------------------------------------------------*/
Ok()1649 short   SwInsertSectionTabDialog::Ok()
1650 {
1651     short nRet = SfxTabDialog::Ok();
1652     DBG_ASSERT(m_pSectionData.get(),
1653             "SwInsertSectionTabDialog: no SectionData?");
1654     const SfxItemSet* pOutputItemSet = GetOutputItemSet();
1655     rWrtSh.InsertSection(*m_pSectionData, pOutputItemSet);
1656     SfxViewFrame* pViewFrm = rWrtSh.GetView().GetViewFrame();
1657     uno::Reference< frame::XDispatchRecorder > xRecorder =
1658             pViewFrm->GetBindings().GetRecorder();
1659     if ( xRecorder.is() )
1660     {
1661         SfxRequest aRequest( pViewFrm, FN_INSERT_REGION);
1662         const SfxPoolItem* pCol;
1663         if(SFX_ITEM_SET == pOutputItemSet->GetItemState(RES_COL, sal_False, &pCol))
1664         {
1665             aRequest.AppendItem(SfxUInt16Item(SID_ATTR_COLUMNS,
1666                 ((const SwFmtCol*)pCol)->GetColumns().Count()));
1667         }
1668         aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_NAME,
1669                     m_pSectionData->GetSectionName()));
1670         aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_CONDITION,
1671                     m_pSectionData->GetCondition()));
1672         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_HIDDEN,
1673                     m_pSectionData->IsHidden()));
1674         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_PROTECT,
1675                     m_pSectionData->IsProtectFlag()));
1676         // --> FME 2004-06-22 #114856# edit in readonly sections
1677         aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_EDIT_IN_READONLY,
1678                     m_pSectionData->IsEditInReadonlyFlag()));
1679         // <--
1680 
1681         String sLinkFileName( m_pSectionData->GetLinkFileName() );
1682         aRequest.AppendItem(SfxStringItem( FN_PARAM_1, sLinkFileName.GetToken( 0, sfx2::cTokenSeperator )));
1683         aRequest.AppendItem(SfxStringItem( FN_PARAM_2, sLinkFileName.GetToken( 1, sfx2::cTokenSeperator )));
1684         aRequest.AppendItem(SfxStringItem( FN_PARAM_3, sLinkFileName.GetToken( 2, sfx2::cTokenSeperator )));
1685         aRequest.Done();
1686     }
1687     return nRet;
1688 }
1689 
1690 /* -----------------21.05.99 10:31-------------------
1691  *
1692  * --------------------------------------------------*/
SwInsertSectionTabPage(Window * pParent,const SfxItemSet & rAttrSet)1693 SwInsertSectionTabPage::SwInsertSectionTabPage(
1694                             Window *pParent, const SfxItemSet &rAttrSet) :
1695     SfxTabPage( pParent, SW_RES(TP_INSERT_SECTION), rAttrSet ),
1696     aNameFL       ( this, SW_RES( FL_NAME ) ),
1697     aCurName            ( this, SW_RES( ED_RNAME ) ),
1698     aLinkFL             ( this, SW_RES( FL_LINK ) ),
1699     aFileCB             ( this, SW_RES( CB_FILE ) ),
1700     aDDECB              ( this, SW_RES( CB_DDE ) ) ,
1701     aDDECommandFT       ( this, SW_RES( FT_DDE ) ) ,
1702     aFileNameFT         ( this, SW_RES( FT_FILE ) ) ,
1703     aFileNameED         ( this, SW_RES( ED_FILE ) ),
1704     aFilePB             ( this, SW_RES( PB_FILE ) ),
1705     aSubRegionFT        ( this, SW_RES( FT_SUBREG ) ) ,
1706     aSubRegionED        ( this, SW_RES( LB_SUBREG ) ) ,
1707 
1708     aProtectFL          ( this, SW_RES( FL_PROTECT ) ),
1709     aProtectCB          ( this, SW_RES( CB_PROTECT ) ),
1710     aPasswdCB           ( this, SW_RES( CB_PASSWD ) ),
1711     aPasswdPB           ( this, SW_RES( PB_PASSWD ) ),
1712 
1713     aHideFL             ( this, SW_RES( FL_HIDE ) ),
1714     aHideCB             ( this, SW_RES( CB_HIDE ) ),
1715     aConditionFT             ( this, SW_RES( FT_CONDITION ) ),
1716     aConditionED        ( this, SW_RES( ED_CONDITION ) ),
1717     // --> FME 2004-06-22 #114856# edit in readonly sections
1718     aPropertiesFL       ( this, SW_RES( FL_PROPERTIES ) ),
1719     aEditInReadonlyCB   ( this, SW_RES( CB_EDIT_IN_READONLY ) ),
1720     // <--
1721 
1722     m_pWrtSh(0),
1723     m_pDocInserter(NULL),
1724     m_pOldDefDlgParent(NULL)
1725 {
1726     FreeResource();
1727 
1728     aProtectCB.SetClickHdl  ( LINK( this, SwInsertSectionTabPage, ChangeProtectHdl));
1729     aPasswdCB.SetClickHdl   ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
1730     aPasswdPB.SetClickHdl   ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
1731     aHideCB.SetClickHdl     ( LINK( this, SwInsertSectionTabPage, ChangeHideHdl));
1732     // --> FME 2004-06-22 #114856# edit in readonly sections
1733     aEditInReadonlyCB.SetClickHdl       ( LINK( this, SwInsertSectionTabPage, ChangeEditInReadonlyHdl));
1734     // <--
1735     aFileCB.SetClickHdl     ( LINK( this, SwInsertSectionTabPage, UseFileHdl ));
1736     aFilePB.SetClickHdl     ( LINK( this, SwInsertSectionTabPage, FileSearchHdl ));
1737     aCurName.SetModifyHdl   ( LINK( this, SwInsertSectionTabPage, NameEditHdl));
1738     aDDECB.SetClickHdl      ( LINK( this, SwInsertSectionTabPage, DDEHdl ));
1739     ChangeProtectHdl(&aProtectCB);
1740     aPasswdPB.SetAccessibleRelationMemberOf(&aProtectFL);
1741     aSubRegionED.EnableAutocomplete( sal_True, sal_True );
1742 }
1743 /* -----------------21.05.99 10:31-------------------
1744  *
1745  * --------------------------------------------------*/
~SwInsertSectionTabPage()1746 SwInsertSectionTabPage::~SwInsertSectionTabPage()
1747 {
1748     delete m_pDocInserter;
1749 }
1750 
SetWrtShell(SwWrtShell & rSh)1751 void    SwInsertSectionTabPage::SetWrtShell(SwWrtShell& rSh)
1752 {
1753     m_pWrtSh = &rSh;
1754 
1755     sal_Bool bWeb = 0 != PTR_CAST(SwWebDocShell, m_pWrtSh->GetView().GetDocShell());
1756     if(bWeb)
1757     {
1758         aHideCB         .Hide();
1759         aConditionED    .Hide();
1760         aConditionFT    .Hide();
1761         aDDECB           .Hide();
1762         aDDECommandFT    .Hide();
1763     }
1764 
1765     lcl_FillSubRegionList( *m_pWrtSh, aSubRegionED, &aCurName );
1766 
1767     SwSectionData *const pSectionData =
1768         static_cast<SwInsertSectionTabDialog*>(GetTabDialog())
1769             ->GetSectionData();
1770     if (pSectionData) // something set?
1771     {
1772         aCurName.SetText(
1773             rSh.GetUniqueSectionName(& pSectionData->GetSectionName()));
1774         aProtectCB.Check( 0 != pSectionData->IsProtectFlag() );
1775         m_sFileName = pSectionData->GetLinkFileName();
1776         m_sFilePasswd = pSectionData->GetLinkFilePassword();
1777         aFileCB.Check( 0 != m_sFileName.Len() );
1778         aFileNameED.SetText( m_sFileName );
1779         UseFileHdl( &aFileCB );
1780     }
1781     else
1782     {
1783         aCurName.SetText( rSh.GetUniqueSectionName() );
1784     }
1785 }
1786 /* -----------------21.05.99 10:32-------------------
1787  *
1788  * --------------------------------------------------*/
FillItemSet(SfxItemSet &)1789 sal_Bool SwInsertSectionTabPage::FillItemSet( SfxItemSet& )
1790 {
1791     SwSectionData aSection(CONTENT_SECTION, aCurName.GetText());
1792     aSection.SetCondition(aConditionED.GetText());
1793     sal_Bool bProtected = aProtectCB.IsChecked();
1794     aSection.SetProtectFlag(bProtected);
1795     aSection.SetHidden(aHideCB.IsChecked());
1796     // --> FME 2004-06-22 #114856# edit in readonly sections
1797     aSection.SetEditInReadonlyFlag(aEditInReadonlyCB.IsChecked());
1798     // <--
1799     if(bProtected)
1800     {
1801         aSection.SetPassword(m_aNewPasswd);
1802     }
1803     String sFileName = aFileNameED.GetText();
1804     String sSubRegion = aSubRegionED.GetText();
1805     sal_Bool bDDe = aDDECB.IsChecked();
1806     if(aFileCB.IsChecked() && (sFileName.Len() || sSubRegion.Len() || bDDe))
1807     {
1808         String aLinkFile;
1809         if( bDDe )
1810         {
1811             aLinkFile = sFileName;
1812 
1813             sal_uInt16 nPos = 0;
1814             while( STRING_NOTFOUND != (nPos = aLinkFile.SearchAscii( "  ", nPos )) )
1815                 aLinkFile.Erase( nPos--, 1 );
1816 
1817             nPos = aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeperator );
1818             aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeperator, nPos );
1819         }
1820         else
1821         {
1822             if(sFileName.Len())
1823             {
1824                 SfxMedium* pMedium = m_pWrtSh->GetView().GetDocShell()->GetMedium();
1825                 INetURLObject aAbs;
1826                 if( pMedium )
1827                     aAbs = pMedium->GetURLObject();
1828                 aLinkFile = URIHelper::SmartRel2Abs(
1829                     aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1830                 aSection.SetLinkFilePassword( m_sFilePasswd );
1831             }
1832 
1833             aLinkFile += sfx2::cTokenSeperator;
1834             aLinkFile += m_sFilterName;
1835             aLinkFile += sfx2::cTokenSeperator;
1836             aLinkFile += sSubRegion;
1837         }
1838 
1839         aSection.SetLinkFileName(aLinkFile);
1840         if(aLinkFile.Len())
1841         {
1842             aSection.SetType( aDDECB.IsChecked() ?
1843                                     DDE_LINK_SECTION :
1844                                         FILE_LINK_SECTION);
1845         }
1846     }
1847     ((SwInsertSectionTabDialog*)GetTabDialog())->SetSectionData(aSection);
1848     return sal_True;
1849 }
1850 /* -----------------21.05.99 10:32-------------------
1851  *
1852  * --------------------------------------------------*/
Reset(const SfxItemSet &)1853 void SwInsertSectionTabPage::Reset( const SfxItemSet& )
1854 {
1855 }
1856 /* -----------------21.05.99 11:22-------------------
1857  *
1858  * --------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)1859 SfxTabPage* SwInsertSectionTabPage::Create( Window* pParent,
1860                                 const SfxItemSet& rAttrSet)
1861 {
1862     return new SwInsertSectionTabPage(pParent, rAttrSet);
1863 }
1864 /*---------------------------------------------------------------------
1865 
1866 ---------------------------------------------------------------------*/
1867 
IMPL_LINK(SwInsertSectionTabPage,ChangeHideHdl,CheckBox *,pBox)1868 IMPL_LINK( SwInsertSectionTabPage, ChangeHideHdl, CheckBox *, pBox )
1869 {
1870     sal_Bool bHide = pBox->IsChecked();
1871     aConditionED.Enable(bHide);
1872     aConditionFT.Enable(bHide);
1873     return 0;
1874 }
1875 /*---------------------------------------------------------------------
1876 
1877 ---------------------------------------------------------------------*/
1878 
IMPL_LINK(SwInsertSectionTabPage,ChangeEditInReadonlyHdl,CheckBox *,EMPTYARG)1879 IMPL_LINK( SwInsertSectionTabPage, ChangeEditInReadonlyHdl, CheckBox *, EMPTYARG )
1880 {
1881     return 0;
1882 }
1883 /*---------------------------------------------------------------------
1884 
1885 ---------------------------------------------------------------------*/
1886 
IMPL_LINK(SwInsertSectionTabPage,ChangeProtectHdl,CheckBox *,pBox)1887 IMPL_LINK( SwInsertSectionTabPage, ChangeProtectHdl, CheckBox *, pBox )
1888 {
1889     sal_Bool bCheck = pBox->IsChecked();
1890     aPasswdCB.Enable(bCheck);
1891     aPasswdPB.Enable(bCheck);
1892     return 0;
1893 }
1894 /* -----------------------------26.04.01 14:50--------------------------------
1895 
1896  ---------------------------------------------------------------------------*/
IMPL_LINK(SwInsertSectionTabPage,ChangePasswdHdl,Button *,pButton)1897 IMPL_LINK( SwInsertSectionTabPage, ChangePasswdHdl, Button *, pButton )
1898 {
1899     sal_Bool bChange = pButton == &aPasswdPB;
1900     sal_Bool bSet = bChange ? bChange : aPasswdCB.IsChecked();
1901     if(bSet)
1902     {
1903         if(!m_aNewPasswd.getLength() || bChange)
1904         {
1905             SwTestPasswdDlg aPasswdDlg(this);
1906             aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
1907             if(RET_OK == aPasswdDlg.Execute())
1908             {
1909                 String sNewPasswd( aPasswdDlg.GetPassword() );
1910                 if( aPasswdDlg.GetConfirm() == sNewPasswd )
1911                 {
1912                     SvPasswordHelper::GetHashPassword( m_aNewPasswd, sNewPasswd );
1913                 }
1914                 else
1915                 {
1916                     InfoBox(pButton, SW_RES(REG_WRONG_PASSWD_REPEAT)).Execute();
1917                 }
1918             }
1919             else if(!bChange)
1920                 aPasswdCB.Check(sal_False);
1921         }
1922     }
1923     else
1924         m_aNewPasswd.realloc(0);
1925     return 0;
1926 }
1927 /*---------------------------------------------------------------------
1928 
1929 ---------------------------------------------------------------------*/
1930 
IMPL_LINK_INLINE_START(SwInsertSectionTabPage,NameEditHdl,Edit *,EMPTYARG)1931 IMPL_LINK_INLINE_START( SwInsertSectionTabPage, NameEditHdl, Edit *, EMPTYARG )
1932 {
1933     String  aName=aCurName.GetText();
1934     GetTabDialog()->GetOKButton().Enable(aName.Len() && aCurName.GetEntryPos( aName ) == USHRT_MAX);
1935     return 0;
1936 }
IMPL_LINK_INLINE_END(SwInsertSectionTabPage,NameEditHdl,Edit *,EMPTYARG)1937 IMPL_LINK_INLINE_END( SwInsertSectionTabPage, NameEditHdl, Edit *, EMPTYARG )
1938 
1939 /*---------------------------------------------------------------------
1940 
1941 ---------------------------------------------------------------------*/
1942 
1943 IMPL_LINK( SwInsertSectionTabPage, UseFileHdl, CheckBox *, pBox )
1944 {
1945     if( pBox->IsChecked() )
1946     {
1947         if( m_pWrtSh->HasSelection() &&
1948             RET_NO == QueryBox( this, SW_RES(QB_CONNECT) ).Execute() )
1949             pBox->Check( sal_False );
1950     }
1951 
1952     sal_Bool bFile = pBox->IsChecked();
1953     aFileNameFT.Enable(bFile);
1954     aFileNameED.Enable(bFile);
1955     aFilePB.Enable(bFile);
1956     aSubRegionFT.Enable(bFile);
1957     aSubRegionED.Enable(bFile);
1958     aDDECommandFT.Enable(bFile);
1959     aDDECB.Enable(bFile);
1960     if( bFile )
1961     {
1962 //      aFileNameED.SetText( aFileName );
1963         aFileNameED.GrabFocus();
1964         aProtectCB.Check( sal_True );
1965     }
1966     else
1967     {
1968         aDDECB.Check(sal_False);
1969         DDEHdl(&aDDECB);
1970 //      aFileNameED.SetText(aEmptyStr);
1971     }
1972     return 0;
1973 }
1974 
1975 /*---------------------------------------------------------------------
1976 
1977 ---------------------------------------------------------------------*/
1978 
IMPL_LINK(SwInsertSectionTabPage,FileSearchHdl,PushButton *,EMPTYARG)1979 IMPL_LINK( SwInsertSectionTabPage, FileSearchHdl, PushButton *, EMPTYARG )
1980 {
1981     m_pOldDefDlgParent = Application::GetDefDialogParent();
1982     Application::SetDefDialogParent( this );
1983     if ( m_pDocInserter )
1984         delete m_pDocInserter;
1985     m_pDocInserter = new ::sfx2::DocumentInserter( 0, String::CreateFromAscii("swriter") );
1986     m_pDocInserter->StartExecuteModal( LINK( this, SwInsertSectionTabPage, DlgClosedHdl ) );
1987     return 0;
1988 }
1989 
1990 /*---------------------------------------------------------------------
1991 
1992 ---------------------------------------------------------------------*/
1993 
IMPL_LINK(SwInsertSectionTabPage,DDEHdl,CheckBox *,pBox)1994 IMPL_LINK( SwInsertSectionTabPage, DDEHdl, CheckBox*, pBox )
1995 {
1996     sal_Bool bDDE = pBox->IsChecked();
1997     sal_Bool bFile = aFileCB.IsChecked();
1998     aFilePB.Enable(!bDDE && bFile);
1999     if(bDDE)
2000     {
2001         aFileNameFT.Hide();
2002         aDDECommandFT.Enable(bDDE);
2003         aDDECommandFT.Show();
2004         aSubRegionFT.Hide();
2005         aSubRegionED.Hide();
2006         aFileNameED.SetAccessibleName(aDDECommandFT.GetText());
2007     }
2008     else
2009     {
2010         aDDECommandFT.Hide();
2011         aFileNameFT.Enable(bFile);
2012         aFileNameFT.Show();
2013         aSubRegionFT.Show();
2014         aSubRegionED.Show();
2015         aSubRegionED.Enable(bFile);
2016         aFileNameED.SetAccessibleName(aFileNameFT.GetText());
2017     }
2018     return 0;
2019 }
2020 
IMPL_LINK(SwInsertSectionTabPage,DlgClosedHdl,sfx2::FileDialogHelper *,_pFileDlg)2021 IMPL_LINK( SwInsertSectionTabPage, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
2022 {
2023     if ( _pFileDlg->GetError() == ERRCODE_NONE )
2024     {
2025         SfxMedium* pMedium = m_pDocInserter->CreateMedium();
2026         if ( pMedium )
2027         {
2028             m_sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
2029             m_sFilterName = pMedium->GetFilter()->GetFilterName();
2030             const SfxPoolItem* pItem;
2031             if ( SFX_ITEM_SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, sal_False, &pItem ) )
2032                 m_sFilePasswd = ( (SfxStringItem*)pItem )->GetValue();
2033             aFileNameED.SetText( INetURLObject::decode(
2034                 m_sFileName, INET_HEX_ESCAPE, INetURLObject::DECODE_UNAMBIGUOUS, RTL_TEXTENCODING_UTF8 ) );
2035             ::lcl_ReadSections( *pMedium, aSubRegionED );
2036             delete pMedium;
2037         }
2038     }
2039     else
2040         m_sFilterName = m_sFilePasswd = aEmptyStr;
2041 
2042     Application::SetDefDialogParent( m_pOldDefDlgParent );
2043     return 0;
2044 }
2045 
2046 // --------------------------------------------------------------
2047 
2048 // Numerierungsformat Umsetzung:
2049 // ListBox  - Format            - Enum-Wert
2050 // 0        - A, B, C, ...      - 0
2051 // 1        - a, b, c, ...      - 1
2052 // 2        - I, II, III, ...   - 2
2053 // 3        - i, ii, iii, ...   - 3
2054 // 4        - 1, 2, 3, ...      - 4
2055 // 5        - A, .., AA, ..,    - 9
2056 // 6        - a, .., aa, ..,    - 10
2057 
GetNumPos(sal_uInt16 n)2058 inline sal_uInt16 GetNumPos( sal_uInt16 n )
2059 {
2060     return SVX_NUM_ARABIC < n ? n - 4 : n;
2061 }
2062 
GetNumType(sal_uInt16 n)2063 inline SvxExtNumType GetNumType( sal_uInt16 n )
2064 {
2065     return (SvxExtNumType)(4 < n ? n + 4 : n );
2066 }
2067 
SwSectionFtnEndTabPage(Window * pParent,const SfxItemSet & rAttrSet)2068 SwSectionFtnEndTabPage::SwSectionFtnEndTabPage( Window *pParent,
2069                                                 const SfxItemSet &rAttrSet)
2070     : SfxTabPage( pParent, SW_RES( TP_SECTION_FTNENDNOTES ), rAttrSet ),
2071     aFtnFL              ( this, SW_RES( FL_FTN ) ),
2072     aFtnNtAtTextEndCB   ( this, SW_RES( CB_FTN_AT_TXTEND ) ),
2073 
2074     aFtnNtNumCB         ( this, SW_RES( CB_FTN_NUM ) ),
2075     aFtnOffsetLbl       ( this, SW_RES( FT_FTN_OFFSET   )),
2076     aFtnOffsetFld       ( this, SW_RES( FLD_FTN_OFFSET   )),
2077 
2078     aFtnNtNumFmtCB      ( this, SW_RES( CB_FTN_NUM_FMT ) ),
2079     aFtnPrefixFT        ( this, SW_RES( FT_FTN_PREFIX   )),
2080     aFtnPrefixED        ( this, SW_RES( ED_FTN_PREFIX    )),
2081     aFtnNumViewBox      ( this, SW_RES( LB_FTN_NUMVIEW  ), INSERT_NUM_EXTENDED_TYPES),
2082     aFtnSuffixFT        ( this, SW_RES( FT_FTN_SUFFIX    )),
2083     aFtnSuffixED        ( this, SW_RES( ED_FTN_SUFFIX    )),
2084 
2085     aEndFL              ( this, SW_RES( FL_END ) ),
2086     aEndNtAtTextEndCB   ( this, SW_RES( CB_END_AT_TXTEND )),
2087 
2088     aEndNtNumCB         ( this, SW_RES( CB_END_NUM )),
2089     aEndOffsetLbl       ( this, SW_RES( FT_END_OFFSET   )),
2090     aEndOffsetFld       ( this, SW_RES( FLD_END_OFFSET   )),
2091 
2092     aEndNtNumFmtCB      ( this, SW_RES( CB_END_NUM_FMT ) ),
2093     aEndPrefixFT        ( this, SW_RES( FT_END_PREFIX   )),
2094     aEndPrefixED        ( this, SW_RES( ED_END_PREFIX    )),
2095     aEndNumViewBox      ( this, SW_RES( LB_END_NUMVIEW  ), INSERT_NUM_EXTENDED_TYPES),
2096     aEndSuffixFT        ( this, SW_RES( FT_END_SUFFIX    )),
2097     aEndSuffixED        ( this, SW_RES( ED_END_SUFFIX    ))
2098 {
2099     FreeResource();
2100 
2101     Link aLk( LINK( this, SwSectionFtnEndTabPage, FootEndHdl));
2102     aFtnNtAtTextEndCB.SetClickHdl( aLk );
2103     aFtnNtNumCB.SetClickHdl( aLk );
2104     aEndNtAtTextEndCB.SetClickHdl( aLk );
2105     aEndNtNumCB.SetClickHdl( aLk );
2106     aFtnNtNumFmtCB.SetClickHdl( aLk );
2107     aEndNtNumFmtCB.SetClickHdl( aLk );
2108 }
2109 
~SwSectionFtnEndTabPage()2110 SwSectionFtnEndTabPage::~SwSectionFtnEndTabPage()
2111 {
2112 }
2113 
FillItemSet(SfxItemSet & rSet)2114 sal_Bool SwSectionFtnEndTabPage::FillItemSet( SfxItemSet& rSet )
2115 {
2116     SwFmtFtnAtTxtEnd aFtn( aFtnNtAtTextEndCB.IsChecked()
2117                             ? ( aFtnNtNumCB.IsChecked()
2118                                 ? ( aFtnNtNumFmtCB.IsChecked()
2119                                     ? FTNEND_ATTXTEND_OWNNUMANDFMT
2120                                     : FTNEND_ATTXTEND_OWNNUMSEQ )
2121                                 : FTNEND_ATTXTEND )
2122                             : FTNEND_ATPGORDOCEND );
2123 
2124     switch( aFtn.GetValue() )
2125     {
2126     case FTNEND_ATTXTEND_OWNNUMANDFMT:
2127         aFtn.SetNumType( aFtnNumViewBox.GetSelectedNumberingType() );
2128         aFtn.SetPrefix( aFtnPrefixED.GetText() );
2129         aFtn.SetSuffix( aFtnSuffixED.GetText() );
2130         // no break;
2131 
2132     case FTNEND_ATTXTEND_OWNNUMSEQ:
2133         aFtn.SetOffset( static_cast< sal_uInt16 >( aFtnOffsetFld.GetValue()-1 ) );
2134         // no break;
2135     }
2136 
2137     SwFmtEndAtTxtEnd aEnd( aEndNtAtTextEndCB.IsChecked()
2138                             ? ( aEndNtNumCB.IsChecked()
2139                                 ? ( aEndNtNumFmtCB.IsChecked()
2140                                     ? FTNEND_ATTXTEND_OWNNUMANDFMT
2141                                     : FTNEND_ATTXTEND_OWNNUMSEQ )
2142                                 : FTNEND_ATTXTEND )
2143                             : FTNEND_ATPGORDOCEND );
2144 
2145     switch( aEnd.GetValue() )
2146     {
2147     case FTNEND_ATTXTEND_OWNNUMANDFMT:
2148         aEnd.SetNumType( aEndNumViewBox.GetSelectedNumberingType() );
2149         aEnd.SetPrefix( aEndPrefixED.GetText() );
2150         aEnd.SetSuffix( aEndSuffixED.GetText() );
2151         // no break;
2152 
2153     case FTNEND_ATTXTEND_OWNNUMSEQ:
2154         aEnd.SetOffset( static_cast< sal_uInt16 >( aEndOffsetFld.GetValue()-1 ) );
2155         // no break;
2156     }
2157 
2158     rSet.Put( aFtn );
2159     rSet.Put( aEnd );
2160 
2161     return sal_True;
2162 }
2163 
ResetState(sal_Bool bFtn,const SwFmtFtnEndAtTxtEnd & rAttr)2164 void SwSectionFtnEndTabPage::ResetState( sal_Bool bFtn,
2165                                     const SwFmtFtnEndAtTxtEnd& rAttr )
2166 {
2167     CheckBox *pNtAtTextEndCB, *pNtNumCB, *pNtNumFmtCB;
2168     FixedText*pPrefixFT, *pSuffixFT;
2169     Edit *pPrefixED, *pSuffixED;
2170     SwNumberingTypeListBox *pNumViewBox;
2171     FixedText* pOffsetTxt;
2172     NumericField *pOffsetFld;
2173 
2174     if( bFtn )
2175     {
2176         pNtAtTextEndCB = &aFtnNtAtTextEndCB;
2177         pNtNumCB = &aFtnNtNumCB;
2178         pNtNumFmtCB = &aFtnNtNumFmtCB;
2179         pPrefixFT = &aFtnPrefixFT;
2180         pPrefixED = &aFtnPrefixED;
2181         pSuffixFT = &aFtnSuffixFT;
2182         pSuffixED = &aFtnSuffixED;
2183         pNumViewBox = &aFtnNumViewBox;
2184         pOffsetTxt = &aFtnOffsetLbl;
2185         pOffsetFld = &aFtnOffsetFld;
2186     }
2187     else
2188     {
2189         pNtAtTextEndCB = &aEndNtAtTextEndCB;
2190         pNtNumCB = &aEndNtNumCB;
2191         pNtNumFmtCB = &aEndNtNumFmtCB;
2192         pPrefixFT = &aEndPrefixFT;
2193         pPrefixED = &aEndPrefixED;
2194         pSuffixFT = &aEndSuffixFT;
2195         pSuffixED = &aEndSuffixED;
2196         pNumViewBox = &aEndNumViewBox;
2197         pOffsetTxt = &aEndOffsetLbl;
2198         pOffsetFld = &aEndOffsetFld;
2199     }
2200 
2201     sal_uInt16 eState = rAttr.GetValue();
2202     switch( eState )
2203     {
2204     // case FTNEND_ATPGORDOCEND:
2205     case FTNEND_ATTXTEND_OWNNUMANDFMT:
2206         pNtNumFmtCB->SetState( STATE_CHECK );
2207         // no break;
2208 
2209     case FTNEND_ATTXTEND_OWNNUMSEQ:
2210         pNtNumCB->SetState( STATE_CHECK );
2211         // no break;
2212 
2213     case FTNEND_ATTXTEND:
2214         pNtAtTextEndCB->SetState( STATE_CHECK );
2215         // no break;
2216     }
2217 
2218     pNumViewBox->SelectNumberingType( rAttr.GetNumType() );
2219     pOffsetFld->SetValue( rAttr.GetOffset() + 1 );
2220     pPrefixED->SetText( rAttr.GetPrefix() );
2221     pSuffixED->SetText( rAttr.GetSuffix() );
2222 
2223     switch( eState )
2224     {
2225     case FTNEND_ATPGORDOCEND:
2226         pNtNumCB->Enable( sal_False );
2227         // no break;
2228 
2229     case FTNEND_ATTXTEND:
2230         pNtNumFmtCB->Enable( sal_False );
2231         pOffsetFld->Enable( sal_False );
2232         pOffsetTxt->Enable( sal_False );
2233         // no break;
2234 
2235     case FTNEND_ATTXTEND_OWNNUMSEQ:
2236         pNumViewBox->Enable( sal_False );
2237         pPrefixFT->Enable( sal_False );
2238         pPrefixED->Enable( sal_False );
2239         pSuffixFT->Enable( sal_False );
2240         pSuffixED->Enable( sal_False );
2241         // no break;
2242     }
2243 }
2244 
Reset(const SfxItemSet & rSet)2245 void SwSectionFtnEndTabPage::Reset( const SfxItemSet& rSet )
2246 {
2247     ResetState( sal_True, (const SwFmtFtnAtTxtEnd&)rSet.Get(
2248                                     RES_FTN_AT_TXTEND, sal_False ));
2249     ResetState( sal_False, (const SwFmtEndAtTxtEnd&)rSet.Get(
2250                                     RES_END_AT_TXTEND, sal_False ));
2251 }
2252 
Create(Window * pParent,const SfxItemSet & rAttrSet)2253 SfxTabPage* SwSectionFtnEndTabPage::Create( Window* pParent,
2254                                 const SfxItemSet& rAttrSet)
2255 {
2256     return new SwSectionFtnEndTabPage(pParent, rAttrSet);
2257 }
2258 
IMPL_LINK(SwSectionFtnEndTabPage,FootEndHdl,CheckBox *,pBox)2259 IMPL_LINK( SwSectionFtnEndTabPage, FootEndHdl, CheckBox *, pBox )
2260 {
2261 //  pBox->EnableTriState( sal_False );
2262     sal_Bool bFoot = &aFtnNtAtTextEndCB == pBox || &aFtnNtNumCB == pBox ||
2263                     &aFtnNtNumFmtCB == pBox ;
2264 
2265     CheckBox *pNumBox, *pNumFmtBox, *pEndBox;
2266     SwNumberingTypeListBox* pNumViewBox;
2267     FixedText* pOffsetTxt;
2268     NumericField *pOffsetFld;
2269     FixedText*pPrefixFT, *pSuffixFT;
2270     Edit *pPrefixED, *pSuffixED;
2271 
2272     if( bFoot )
2273     {
2274         pEndBox = &aFtnNtAtTextEndCB;
2275         pNumBox = &aFtnNtNumCB;
2276         pNumFmtBox = &aFtnNtNumFmtCB;
2277         pNumViewBox = &aFtnNumViewBox;
2278         pOffsetTxt = &aFtnOffsetLbl;
2279         pOffsetFld = &aFtnOffsetFld;
2280         pPrefixFT = &aFtnPrefixFT;
2281         pSuffixFT = &aFtnSuffixFT;
2282         pPrefixED = &aFtnPrefixED;
2283         pSuffixED = &aFtnSuffixED;
2284     }
2285     else
2286     {
2287         pEndBox = &aEndNtAtTextEndCB;
2288         pNumBox = &aEndNtNumCB;
2289         pNumFmtBox = &aEndNtNumFmtCB;
2290         pNumViewBox = &aEndNumViewBox;
2291         pOffsetTxt = &aEndOffsetLbl;
2292         pOffsetFld = &aEndOffsetFld;
2293         pPrefixFT = &aEndPrefixFT;
2294         pSuffixFT = &aEndSuffixFT;
2295         pPrefixED = &aEndPrefixED;
2296         pSuffixED = &aEndSuffixED;
2297     }
2298 
2299     sal_Bool bEnableAtEnd = STATE_CHECK == pEndBox->GetState();
2300     sal_Bool bEnableNum = bEnableAtEnd && STATE_CHECK == pNumBox->GetState();
2301     sal_Bool bEnableNumFmt = bEnableNum && STATE_CHECK == pNumFmtBox->GetState();
2302 
2303     pNumBox->Enable( bEnableAtEnd );
2304     pOffsetTxt->Enable( bEnableNum );
2305     pOffsetFld->Enable( bEnableNum );
2306     pNumFmtBox->Enable( bEnableNum );
2307     pNumViewBox->Enable( bEnableNumFmt );
2308     pPrefixED->Enable( bEnableNumFmt );
2309     pSuffixED->Enable( bEnableNumFmt );
2310     pPrefixFT->Enable( bEnableNumFmt );
2311     pSuffixFT->Enable( bEnableNumFmt );
2312 
2313     return 0;
2314 }
2315 
2316 /* -----------------21.05.99 13:59-------------------
2317  *
2318  * --------------------------------------------------*/
SwSectionPropertyTabDialog(Window * pParent,const SfxItemSet & rSet,SwWrtShell & rSh)2319 SwSectionPropertyTabDialog::SwSectionPropertyTabDialog(
2320     Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh) :
2321     SfxTabDialog(pParent, SW_RES(DLG_SECTION_PROPERTIES), &rSet),
2322     rWrtSh(rSh)
2323 {
2324     FreeResource();
2325     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2326     DBG_ASSERT(pFact, "Dialogdiet fail!");
2327     AddTabPage(TP_COLUMN,   SwColumnPage::Create,    0);
2328     AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
2329     AddTabPage(TP_SECTION_FTNENDNOTES, SwSectionFtnEndTabPage::Create, 0);
2330     AddTabPage(TP_SECTION_INDENTS, SwSectionIndentTabPage::Create, 0);
2331 
2332     SvxHtmlOptions* pHtmlOpt = SvxHtmlOptions::Get();
2333     long nHtmlMode = pHtmlOpt->GetExportMode();
2334     sal_Bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
2335     if(bWeb)
2336     {
2337         RemoveTabPage(TP_SECTION_FTNENDNOTES);
2338         RemoveTabPage(TP_SECTION_INDENTS);
2339         if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
2340             RemoveTabPage(TP_COLUMN);
2341     }
2342 }
2343 /* -----------------21.05.99 13:59-------------------
2344  *
2345  * --------------------------------------------------*/
~SwSectionPropertyTabDialog()2346 SwSectionPropertyTabDialog::~SwSectionPropertyTabDialog()
2347 {
2348 }
2349 /* -----------------21.05.99 13:59-------------------
2350  *
2351  * --------------------------------------------------*/
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)2352 void SwSectionPropertyTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
2353 {
2354     if( TP_BACKGROUND == nId  )
2355     {
2356             SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
2357             aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
2358             rPage.PageCreated(aSet);
2359     }
2360     else if( TP_COLUMN == nId )
2361     {
2362         ((SwColumnPage&)rPage).ShowBalance(sal_True);
2363         ((SwColumnPage&)rPage).SetInSection(sal_True);
2364     }
2365     else if(TP_SECTION_INDENTS == nId)
2366         ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
2367 }
2368 /*-- 13.06.2003 09:59:08---------------------------------------------------
2369 
2370   -----------------------------------------------------------------------*/
SwSectionIndentTabPage(Window * pParent,const SfxItemSet & rAttrSet)2371 SwSectionIndentTabPage::SwSectionIndentTabPage( Window *pParent, const SfxItemSet &rAttrSet ) :
2372     SfxTabPage(pParent, SW_RES(TP_SECTION_INDENTS), rAttrSet),
2373     aIndentFL(this,     SW_RES(FL_INDENT     )),
2374     aBeforeFT(this,     SW_RES(FT_BEFORE     )),
2375     aBeforeMF(this,     SW_RES(MF_BEFORE     )),
2376     aAfterFT(this,      SW_RES(FT_AFTER      )),
2377     aAfterMF(this,      SW_RES(MF_AFTER      )),
2378     aPreviewWin(this,   SW_RES(WIN_PREVIEW   ))
2379 {
2380     FreeResource();
2381     Link aLk = LINK(this, SwSectionIndentTabPage, IndentModifyHdl);
2382     aBeforeMF.SetModifyHdl(aLk);
2383     aAfterMF.SetModifyHdl(aLk);
2384     aPreviewWin.SetAccessibleName(aIndentFL.GetText());
2385 }
2386 /*-- 13.06.2003 09:59:23---------------------------------------------------
2387 
2388   -----------------------------------------------------------------------*/
~SwSectionIndentTabPage()2389 SwSectionIndentTabPage::~SwSectionIndentTabPage()
2390 {
2391 }
2392 /*-- 13.06.2003 09:59:23---------------------------------------------------
2393 
2394   -----------------------------------------------------------------------*/
FillItemSet(SfxItemSet & rSet)2395 sal_Bool SwSectionIndentTabPage::FillItemSet( SfxItemSet& rSet)
2396 {
2397     if(aBeforeMF.IsValueModified() ||
2398             aAfterMF.IsValueModified())
2399     {
2400         SvxLRSpaceItem aLRSpace(
2401                 static_cast< long >(aBeforeMF.Denormalize(aBeforeMF.GetValue(FUNIT_TWIP))) ,
2402                 static_cast< long >(aAfterMF.Denormalize(aAfterMF.GetValue(FUNIT_TWIP))), 0, 0, RES_LR_SPACE);
2403         rSet.Put(aLRSpace);
2404     }
2405     return sal_True;
2406 }
2407 /*-- 13.06.2003 09:59:24---------------------------------------------------
2408 
2409   -----------------------------------------------------------------------*/
Reset(const SfxItemSet & rSet)2410 void SwSectionIndentTabPage::Reset( const SfxItemSet& rSet)
2411 {
2412     //this page doesn't show up in HTML mode
2413     FieldUnit aMetric = ::GetDfltMetric(sal_False);
2414     SetMetric(aBeforeMF, aMetric);
2415     SetMetric(aAfterMF , aMetric);
2416 
2417     SfxItemState eItemState = rSet.GetItemState( RES_LR_SPACE );
2418     if ( eItemState >= SFX_ITEM_AVAILABLE )
2419     {
2420         const SvxLRSpaceItem& rSpace =
2421             (const SvxLRSpaceItem&)rSet.Get( RES_LR_SPACE );
2422 
2423         aBeforeMF.SetValue( aBeforeMF.Normalize(rSpace.GetLeft()), FUNIT_TWIP );
2424         aAfterMF.SetValue( aAfterMF.Normalize(rSpace.GetRight()), FUNIT_TWIP );
2425     }
2426     else
2427     {
2428         aBeforeMF.SetEmptyFieldValue();
2429         aAfterMF.SetEmptyFieldValue();
2430     }
2431     aBeforeMF.SaveValue();
2432     aAfterMF.SaveValue();
2433     IndentModifyHdl(0);
2434 }
2435 /*-- 13.06.2003 09:59:24---------------------------------------------------
2436 
2437   -----------------------------------------------------------------------*/
Create(Window * pParent,const SfxItemSet & rAttrSet)2438 SfxTabPage*  SwSectionIndentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
2439 {
2440     return new SwSectionIndentTabPage(pParent, rAttrSet);
2441 }
2442 /* -----------------13.06.2003 13:57-----------------
2443 
2444  --------------------------------------------------*/
SetWrtShell(SwWrtShell & rSh)2445 void SwSectionIndentTabPage::SetWrtShell(SwWrtShell& rSh)
2446 {
2447     //set sensible values at the preview
2448     aPreviewWin.SetAdjust(SVX_ADJUST_BLOCK);
2449     aPreviewWin.SetLastLine(SVX_ADJUST_BLOCK);
2450     const SwRect& rPageRect = rSh.GetAnyCurRect( RECT_PAGE, 0 );
2451     Size aPageSize(rPageRect.Width(), rPageRect.Height());
2452     aPreviewWin.SetSize(aPageSize);
2453 }
2454 /* -----------------13.06.2003 14:02-----------------
2455 
2456  --------------------------------------------------*/
IMPL_LINK(SwSectionIndentTabPage,IndentModifyHdl,MetricField *,EMPTYARG)2457 IMPL_LINK(SwSectionIndentTabPage, IndentModifyHdl, MetricField*, EMPTYARG)
2458 {
2459     aPreviewWin.SetLeftMargin( static_cast< long >(aBeforeMF.Denormalize(aBeforeMF.GetValue(FUNIT_TWIP))) );
2460     aPreviewWin.SetRightMargin( static_cast< long >(aAfterMF.Denormalize(aAfterMF.GetValue(FUNIT_TWIP))) );
2461     aPreviewWin.Draw(sal_True);
2462     return 0;
2463 }
2464 
2465