bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / dialog / uiregionsw.cxx
blobaf33f8c3666057839129df8c3280c54adddac182
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <regionsw.hxx>
22 #include <svl/urihelper.hxx>
23 #include <svl/PasswordHelper.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/eitem.hxx>
28 #include <sfx2/passwd.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <sfx2/docinsert.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include <editeng/sizeitem.hxx>
36 #include <svtools/htmlcfg.hxx>
37 #include "svtools/treelistentry.hxx"
39 #include <comphelper/storagehelper.hxx>
40 #include <uitool.hxx>
41 #include <IMark.hxx>
42 #include <section.hxx>
43 #include <docary.hxx>
44 #include <doc.hxx> // for the SwSectionFmt-Array
45 #include <basesh.hxx>
46 #include <wdocsh.hxx>
47 #include <view.hxx>
48 #include <swmodule.hxx>
49 #include <wrtsh.hxx>
50 #include <swundo.hxx> // for Undo-Ids
51 #include <column.hxx>
52 #include <fmtfsize.hxx>
53 #include <shellio.hxx>
55 #include <helpid.h>
56 #include <cmdid.h>
57 #include <regionsw.hrc>
58 #include <comcore.hrc>
59 #include <globals.hrc>
60 #include <sfx2/bindings.hxx>
61 #include <sfx2/htmlmode.hxx>
62 #include <svx/dlgutil.hxx>
63 #include <svx/dialogs.hrc>
64 #include <svx/svxdlg.hxx>
65 #include <svx/flagsdef.hxx>
67 using namespace ::com::sun::star;
69 static void lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox );
71 static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames, const SwSectionFmt* pNewFmt )
73 const SwSectionFmt* pFmt;
74 if( !pNewFmt )
76 sal_uInt16 nCount = rSh.GetSectionFmtCount();
77 for(sal_uInt16 i=0;i<nCount;i++)
79 SectionType eTmpType;
80 if( !(pFmt = &rSh.GetSectionFmt(i))->GetParent() &&
81 pFmt->IsInNodesArr() &&
82 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
83 && TOX_HEADER_SECTION != eTmpType )
85 String* pString =
86 new String(pFmt->GetSection()->GetSectionName());
87 if(pAvailNames)
88 pAvailNames->InsertEntry(*pString);
89 rSubRegions.InsertEntry(*pString);
90 lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
94 else
96 SwSections aTmpArr;
97 sal_uInt16 nCnt = pNewFmt->GetChildSections(aTmpArr,SORTSECT_POS);
98 if( nCnt )
100 SectionType eTmpType;
101 for( sal_uInt16 n = 0; n < nCnt; ++n )
102 if( (pFmt = aTmpArr[n]->GetFmt())->IsInNodesArr()&&
103 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
104 && TOX_HEADER_SECTION != eTmpType )
106 String* pString =
107 new String(pFmt->GetSection()->GetSectionName());
108 if(pAvailNames)
109 pAvailNames->InsertEntry(*pString);
110 rSubRegions.InsertEntry(*pString);
111 lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
117 static void lcl_FillSubRegionList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames )
119 lcl_FillList( rSh, rSubRegions, pAvailNames, 0 );
120 IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
121 for( IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
122 ppMark != pMarkAccess->getMarksEnd();
123 ++ppMark)
125 const ::sw::mark::IMark* pBkmk = ppMark->get();
126 if( pBkmk->IsExpanded() )
127 rSubRegions.InsertEntry( pBkmk->GetName() );
131 /*----------------------------------------------------------------------------
132 Description: user data class for region information
133 ----------------------------------------------------------------------------*/
135 class SectRepr
137 private:
138 SwSectionData m_SectionData;
139 SwFmtCol m_Col;
140 SvxBrushItem m_Brush;
141 SwFmtFtnAtTxtEnd m_FtnNtAtEnd;
142 SwFmtEndAtTxtEnd m_EndNtAtEnd;
143 SwFmtNoBalancedColumns m_Balance;
144 SvxFrameDirectionItem m_FrmDirItem;
145 SvxLRSpaceItem m_LRSpaceItem;
146 sal_uInt16 m_nArrPos;
147 // shows, if maybe textcontent is in the region
148 bool m_bContent : 1;
149 // for multiselection, mark at first, then work with TreeListBox!
150 bool m_bSelected : 1;
151 uno::Sequence<sal_Int8> m_TempPasswd;
153 public:
154 SectRepr(sal_uInt16 nPos, SwSection& rSect);
155 bool operator==(const SectRepr& rSectRef) const
156 { return m_nArrPos == rSectRef.GetArrPos(); }
158 bool operator< (const SectRepr& rSectRef) const
159 { return m_nArrPos < rSectRef.GetArrPos(); }
161 SwSectionData & GetSectionData() { return m_SectionData; }
162 SwSectionData const&GetSectionData() const { return m_SectionData; }
163 SwFmtCol& GetCol() { return m_Col; }
164 SvxBrushItem& GetBackground() { return m_Brush; }
165 SwFmtFtnAtTxtEnd& GetFtnNtAtEnd() { return m_FtnNtAtEnd; }
166 SwFmtEndAtTxtEnd& GetEndNtAtEnd() { return m_EndNtAtEnd; }
167 SwFmtNoBalancedColumns& GetBalance() { return m_Balance; }
168 SvxFrameDirectionItem& GetFrmDir() { return m_FrmDirItem; }
169 SvxLRSpaceItem& GetLRSpace() { return m_LRSpaceItem; }
171 sal_uInt16 GetArrPos() const { return m_nArrPos; }
172 String GetFile() const;
173 String GetSubRegion() const;
174 void SetFile(String const& rFile);
175 void SetFilter(String const& rFilter);
176 void SetSubRegion(String const& rSubRegion);
178 bool IsContent() { return m_bContent; }
179 void SetContent(bool const bValue) { m_bContent = bValue; }
181 void SetSelected() { m_bSelected = true; }
182 bool IsSelected() const { return m_bSelected; }
184 uno::Sequence<sal_Int8> & GetTempPasswd() { return m_TempPasswd; }
185 void SetTempPasswd(const uno::Sequence<sal_Int8> & rPasswd)
186 { m_TempPasswd = rPasswd; }
190 SectRepr::SectRepr( sal_uInt16 nPos, SwSection& rSect )
191 : m_SectionData( rSect )
192 , m_Brush( RES_BACKGROUND )
193 , m_FrmDirItem( FRMDIR_ENVIRONMENT, RES_FRAMEDIR )
194 , m_LRSpaceItem( RES_LR_SPACE )
195 , m_nArrPos(nPos)
196 , m_bContent(m_SectionData.GetLinkFileName().Len() == 0)
197 , m_bSelected(false)
199 SwSectionFmt *pFmt = rSect.GetFmt();
200 if( pFmt )
202 m_Col = pFmt->GetCol();
203 m_Brush = pFmt->GetBackground();
204 m_FtnNtAtEnd = pFmt->GetFtnAtTxtEnd();
205 m_EndNtAtEnd = pFmt->GetEndAtTxtEnd();
206 m_Balance.SetValue(pFmt->GetBalancedColumns().GetValue());
207 m_FrmDirItem = pFmt->GetFrmDir();
208 m_LRSpaceItem = pFmt->GetLRSpace();
212 void SectRepr::SetFile( const String& rFile )
214 String sNewFile( INetURLObject::decode( rFile, INET_HEX_ESCAPE,
215 INetURLObject::DECODE_UNAMBIGUOUS,
216 RTL_TEXTENCODING_UTF8 ));
217 String sOldFileName( m_SectionData.GetLinkFileName() );
218 String sSub( sOldFileName.GetToken( 2, sfx2::cTokenSeparator ) );
220 if( rFile.Len() || sSub.Len() )
222 sNewFile += sfx2::cTokenSeparator;
223 if( rFile.Len() ) // Filter only with FileName
224 sNewFile += sOldFileName.GetToken( 1, sfx2::cTokenSeparator );
226 sNewFile += sfx2::cTokenSeparator;
227 sNewFile += sSub;
230 m_SectionData.SetLinkFileName( sNewFile );
232 if( rFile.Len() || sSub.Len() )
234 m_SectionData.SetType( FILE_LINK_SECTION );
236 else
238 m_SectionData.SetType( CONTENT_SECTION );
243 void SectRepr::SetFilter( const String& rFilter )
245 String sNewFile;
246 String sOldFileName( m_SectionData.GetLinkFileName() );
247 String sFile( sOldFileName.GetToken( 0, sfx2::cTokenSeparator ) );
248 String sSub( sOldFileName.GetToken( 2, sfx2::cTokenSeparator ) );
250 if( sFile.Len() )
251 (((( sNewFile = sFile ) += sfx2::cTokenSeparator ) += rFilter )
252 += sfx2::cTokenSeparator ) += sSub;
253 else if( sSub.Len() )
254 (( sNewFile = sfx2::cTokenSeparator ) += sfx2::cTokenSeparator ) += sSub;
256 m_SectionData.SetLinkFileName( sNewFile );
258 if( sNewFile.Len() )
260 m_SectionData.SetType( FILE_LINK_SECTION );
264 void SectRepr::SetSubRegion(const String& rSubRegion)
266 String sNewFile;
267 String sOldFileName( m_SectionData.GetLinkFileName() );
268 String sFilter( sOldFileName.GetToken( 1, sfx2::cTokenSeparator ) );
269 sOldFileName = sOldFileName.GetToken( 0, sfx2::cTokenSeparator );
271 if( rSubRegion.Len() || sOldFileName.Len() )
272 (((( sNewFile = sOldFileName ) += sfx2::cTokenSeparator ) += sFilter )
273 += sfx2::cTokenSeparator ) += rSubRegion;
275 m_SectionData.SetLinkFileName( sNewFile );
277 if( rSubRegion.Len() || sOldFileName.Len() )
279 m_SectionData.SetType( FILE_LINK_SECTION );
281 else
283 m_SectionData.SetType( CONTENT_SECTION );
288 String SectRepr::GetFile() const
290 String sLinkFile( m_SectionData.GetLinkFileName() );
291 if( sLinkFile.Len() )
293 if (DDE_LINK_SECTION == m_SectionData.GetType())
295 sal_uInt16 n = sLinkFile.SearchAndReplace( sfx2::cTokenSeparator, ' ' );
296 sLinkFile.SearchAndReplace( sfx2::cTokenSeparator, ' ', n );
298 else
299 sLinkFile = INetURLObject::decode( sLinkFile.GetToken( 0,
300 sfx2::cTokenSeparator ),
301 INET_HEX_ESCAPE,
302 INetURLObject::DECODE_UNAMBIGUOUS,
303 RTL_TEXTENCODING_UTF8 );
305 return sLinkFile;
309 String SectRepr::GetSubRegion() const
311 String sLinkFile( m_SectionData.GetLinkFileName() );
312 if( sLinkFile.Len() )
313 sLinkFile = sLinkFile.GetToken( 2, sfx2::cTokenSeparator );
314 return sLinkFile;
317 /*----------------------------------------------------------------------------
318 Description: dialog edit regions
319 ----------------------------------------------------------------------------*/
320 SwEditRegionDlg::SwEditRegionDlg( Window* pParent, SwWrtShell& rWrtSh )
321 : SfxModalDialog(pParent, "EditSectionDialog",
322 "modules/swriter/ui/editsectiondialog.ui")
323 , m_bSubRegionsFilled(false)
324 , aImageIL(SW_RES(IL_SECTION_BITMAPS))
325 , rSh(rWrtSh)
326 , m_pDocInserter(NULL)
327 , m_pOldDefDlgParent(NULL)
328 , bDontCheckPasswd(true)
330 get(m_pCurName, "curname");
331 get(m_pTree, "tree");
332 m_pTree->set_height_request(m_pTree->GetTextHeight() * 16);
333 get(m_pFileCB, "link");
334 m_pFileCB->SetState(STATE_NOCHECK);
335 get(m_pDDECB, "dde");
336 get(m_pDDEFrame, "ddedepend");
337 get(m_pFileNameFT, "filenameft");
338 get(m_pDDECommandFT, "ddeft");
339 get(m_pFileNameED, "filename");
340 get(m_pFilePB, "file");
341 get(m_pSubRegionFT, "sectionft");
342 get(m_pSubRegionED, "section");
343 m_pSubRegionED->SetStyle(m_pSubRegionED->GetStyle() | WB_SORT);
344 get(m_pProtectCB, "protect");
345 m_pProtectCB->SetState(STATE_NOCHECK);
346 get(m_pPasswdCB, "withpassword");
347 get(m_pPasswdPB, "password");
348 get(m_pHideCB, "hide");
349 m_pHideCB->SetState(STATE_NOCHECK);
350 get(m_pConditionFT, "conditionft");
351 get(m_pConditionED, "condition");
352 // edit in readonly sections
353 get(m_pEditInReadonlyCB, "editinro");
354 m_pEditInReadonlyCB->SetState(STATE_NOCHECK);
355 get(m_pOptionsPB, "options");
356 get(m_pDismiss, "remove");
357 get(m_pOK, "ok");
359 bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
361 m_pTree->SetSelectHdl(LINK(this, SwEditRegionDlg, GetFirstEntryHdl));
362 m_pTree->SetDeselectHdl(LINK(this, SwEditRegionDlg, DeselectHdl));
363 m_pCurName->SetModifyHdl(LINK(this, SwEditRegionDlg, NameEditHdl));
364 m_pConditionED->SetModifyHdl( LINK( this, SwEditRegionDlg, ConditionEditHdl));
365 m_pOK->SetClickHdl ( LINK( this, SwEditRegionDlg, OkHdl));
366 m_pPasswdCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangePasswdHdl));
367 m_pPasswdPB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangePasswdHdl));
368 m_pHideCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeHideHdl));
369 // edit in readonly sections
370 m_pEditInReadonlyCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeEditInReadonlyHdl));
372 m_pOptionsPB->SetClickHdl(LINK(this, SwEditRegionDlg, OptionsHdl));
373 m_pProtectCB->SetClickHdl(LINK(this, SwEditRegionDlg, ChangeProtectHdl));
374 m_pDismiss->SetClickHdl ( LINK( this, SwEditRegionDlg, ChangeDismissHdl));
375 m_pFileCB->SetClickHdl(LINK(this, SwEditRegionDlg, UseFileHdl));
376 m_pFilePB->SetClickHdl(LINK(this, SwEditRegionDlg, FileSearchHdl));
377 m_pFileNameED->SetModifyHdl(LINK(this, SwEditRegionDlg, FileNameHdl));
378 m_pSubRegionED->SetModifyHdl(LINK(this, SwEditRegionDlg, FileNameHdl));
379 m_pSubRegionED->AddEventListener(LINK(this, SwEditRegionDlg, SubRegionEventHdl));
380 m_pSubRegionED->EnableAutocomplete(true, true);
382 m_pTree->SetSelectionMode( MULTIPLE_SELECTION );
383 m_pTree->SetStyle(m_pTree->GetStyle()|WB_HASBUTTONSATROOT|WB_CLIPCHILDREN|WB_HSCROLL);
384 m_pTree->SetSpaceBetweenEntries(0);
386 if(bWeb)
388 m_pDDECB->Hide();
389 get<VclContainer>("hideframe")->Hide();
390 m_pPasswdCB->Hide();
393 m_pDDECB->SetClickHdl(LINK(this, SwEditRegionDlg, DDEHdl));
395 pCurrSect = rSh.GetCurrSection();
396 RecurseList( 0, 0 );
397 // if the cursor is not in a region
398 // the first one will always be selected
399 if( !m_pTree->FirstSelected() && m_pTree->First() )
400 m_pTree->Select( m_pTree->First() );
401 m_pTree->Show();
402 bDontCheckPasswd = sal_False;
405 sal_Bool SwEditRegionDlg::CheckPasswd(CheckBox* pBox)
407 if(bDontCheckPasswd)
408 return sal_True;
409 sal_Bool bRet = sal_True;
410 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
411 while( pEntry )
413 SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
414 if (!pRepr->GetTempPasswd().getLength()
415 && pRepr->GetSectionData().GetPassword().getLength())
417 SfxPasswordDialog aPasswdDlg(this);
418 bRet = sal_False;
419 if (aPasswdDlg.Execute())
421 String sNewPasswd( aPasswdDlg.GetPassword() );
422 ::com::sun::star::uno::Sequence <sal_Int8 > aNewPasswd;
423 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
424 if (SvPasswordHelper::CompareHashPassword(
425 pRepr->GetSectionData().GetPassword(), sNewPasswd))
427 pRepr->SetTempPasswd(aNewPasswd);
428 bRet = sal_True;
430 else
432 InfoBox(this, SW_RES(REG_WRONG_PASSWORD)).Execute();
436 pEntry = m_pTree->NextSelected(pEntry);
438 if(!bRet && pBox)
440 //reset old button state
441 if(pBox->IsTriStateEnabled())
442 pBox->SetState(pBox->IsChecked() ? STATE_NOCHECK : STATE_DONTKNOW);
443 else
444 pBox->Check(!pBox->IsChecked());
447 return bRet;
450 /*---------------------------------------------------------------------
451 Description: recursively look for child-sections
452 ---------------------------------------------------------------------*/
453 void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pEntry )
455 SwSection* pSect = 0;
456 SvTreeListEntry* pSelEntry = 0;
458 if (!pFmt)
460 sal_uInt16 nCount=rSh.GetSectionFmtCount();
461 for ( sal_uInt16 n=0; n < nCount; n++ )
463 SectionType eTmpType;
464 if( !( pFmt = &rSh.GetSectionFmt(n))->GetParent() &&
465 pFmt->IsInNodesArr() &&
466 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
467 && TOX_HEADER_SECTION != eTmpType )
469 SectRepr* pSectRepr = new SectRepr( n,
470 *(pSect=pFmt->GetSection()) );
471 Image aImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden());
472 pEntry = m_pTree->InsertEntry(pSect->GetSectionName(), aImg, aImg);
473 pEntry->SetUserData(pSectRepr);
474 RecurseList( pFmt, pEntry );
475 if (pEntry->HasChildren())
476 m_pTree->Expand(pEntry);
477 if (pCurrSect==pSect)
478 m_pTree->Select(pEntry);
482 else
484 SwSections aTmpArr;
485 SvTreeListEntry* pNEntry;
486 sal_uInt16 nCnt = pFmt->GetChildSections(aTmpArr,SORTSECT_POS);
487 if( nCnt )
489 for( sal_uInt16 n = 0; n < nCnt; ++n )
491 SectionType eTmpType;
492 pFmt = aTmpArr[n]->GetFmt();
493 if( pFmt->IsInNodesArr() &&
494 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
495 && TOX_HEADER_SECTION != eTmpType )
497 pSect=aTmpArr[n];
498 SectRepr* pSectRepr=new SectRepr(
499 FindArrPos( pSect->GetFmt() ), *pSect );
500 Image aImage = BuildBitmap( pSect->IsProtect(),
501 pSect->IsHidden());
502 pNEntry = m_pTree->InsertEntry(
503 pSect->GetSectionName(), aImage, aImage, pEntry);
504 pNEntry->SetUserData(pSectRepr);
505 RecurseList( aTmpArr[n]->GetFmt(), pNEntry );
506 if( pNEntry->HasChildren())
507 m_pTree->Expand(pNEntry);
508 if (pCurrSect==pSect)
509 pSelEntry = pNEntry;
514 if(0 != pSelEntry)
516 m_pTree->MakeVisible(pSelEntry);
517 m_pTree->Select(pSelEntry);
521 sal_uInt16 SwEditRegionDlg::FindArrPos(const SwSectionFmt* pFmt )
523 sal_uInt16 nCount=rSh.GetSectionFmtCount();
524 for (sal_uInt16 i=0;i<nCount;i++)
525 if (pFmt==&rSh.GetSectionFmt(i))
526 return i;
528 OSL_FAIL("SectionFormat not on the list" );
529 return USHRT_MAX;
532 SwEditRegionDlg::~SwEditRegionDlg( )
534 SvTreeListEntry* pEntry = m_pTree->First();
535 while( pEntry )
537 delete (SectRepr*)pEntry->GetUserData();
538 pEntry = m_pTree->Next( pEntry );
541 delete m_pDocInserter;
544 void SwEditRegionDlg::SelectSection(const String& rSectionName)
546 SvTreeListEntry* pEntry = m_pTree->First();
547 while(pEntry)
549 SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
550 if (pRepr->GetSectionData().GetSectionName() == rSectionName)
551 break;
552 pEntry = m_pTree->Next(pEntry);
554 if(pEntry)
556 m_pTree->SelectAll(false);
557 m_pTree->Select(pEntry);
558 m_pTree->MakeVisible(pEntry);
562 /*---------------------------------------------------------------------
563 Description: selected entry in TreeListBox is showed in
564 Edit window
565 in case of multiselection some controls are disabled
566 ---------------------------------------------------------------------*/
567 IMPL_LINK( SwEditRegionDlg, GetFirstEntryHdl, SvTreeListBox *, pBox )
569 bDontCheckPasswd = true;
570 SvTreeListEntry* pEntry=pBox->FirstSelected();
571 m_pHideCB->Enable(true);
572 // edit in readonly sections
573 m_pEditInReadonlyCB->Enable(true);
575 m_pProtectCB->Enable(true);
576 m_pFileCB->Enable(true);
577 ::com::sun::star::uno::Sequence <sal_Int8> aCurPasswd;
578 if( 1 < pBox->GetSelectionCount() )
580 m_pHideCB->EnableTriState(true);
581 m_pProtectCB->EnableTriState(true);
582 // edit in readonly sections
583 m_pEditInReadonlyCB->EnableTriState(true);
585 m_pFileCB->EnableTriState(true);
587 bool bHiddenValid = true;
588 bool bProtectValid = true;
589 bool bConditionValid = true;
590 // edit in readonly sections
591 bool bEditInReadonlyValid = true;
592 bool bEditInReadonly = true;
594 bool bHidden = true;
595 bool bProtect = true;
596 String sCondition;
597 bool bFirst = true;
598 bool bFileValid = true;
599 bool bFile = true;
600 bool bPasswdValid = true;
602 while( pEntry )
604 SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
605 SwSectionData const& rData( pRepr->GetSectionData() );
606 if(bFirst)
608 sCondition = rData.GetCondition();
609 bHidden = rData.IsHidden();
610 bProtect = rData.IsProtectFlag();
611 // edit in readonly sections
612 bEditInReadonly = rData.IsEditInReadonlyFlag();
614 bFile = (rData.GetType() != CONTENT_SECTION);
615 aCurPasswd = rData.GetPassword();
617 else
619 String sTemp(rData.GetCondition());
620 if(sCondition != sTemp)
621 bConditionValid = sal_False;
622 bHiddenValid = (bHidden == rData.IsHidden());
623 bProtectValid = (bProtect == rData.IsProtectFlag());
624 // edit in readonly sections
625 bEditInReadonlyValid =
626 (bEditInReadonly == rData.IsEditInReadonlyFlag());
628 bFileValid = (bFile ==
629 (rData.GetType() != CONTENT_SECTION));
630 bPasswdValid = (aCurPasswd == rData.GetPassword());
632 pEntry = pBox->NextSelected(pEntry);
633 bFirst = false;
636 m_pHideCB->SetState(!bHiddenValid ? STATE_DONTKNOW :
637 bHidden ? STATE_CHECK : STATE_NOCHECK);
638 m_pProtectCB->SetState(!bProtectValid ? STATE_DONTKNOW :
639 bProtect ? STATE_CHECK : STATE_NOCHECK);
640 // edit in readonly sections
641 m_pEditInReadonlyCB->SetState(!bEditInReadonlyValid ? STATE_DONTKNOW :
642 bEditInReadonly ? STATE_CHECK : STATE_NOCHECK);
644 m_pFileCB->SetState(!bFileValid ? STATE_DONTKNOW :
645 bFile ? STATE_CHECK : STATE_NOCHECK);
647 if (bConditionValid)
648 m_pConditionED->SetText(sCondition);
649 else
651 m_pConditionFT->Enable(false);
652 m_pConditionED->Enable(false);
655 m_pCurName->Enable(false);
656 m_pDDECB->Enable(false);
657 m_pDDEFrame->Enable(false);
658 m_pOptionsPB->Enable(false);
659 bool bPasswdEnabled = m_pProtectCB->GetState() == STATE_CHECK;
660 m_pPasswdCB->Enable(bPasswdEnabled);
661 m_pPasswdPB->Enable(bPasswdEnabled);
662 if(!bPasswdValid)
664 pEntry = pBox->FirstSelected();
665 pBox->SelectAll( sal_False );
666 pBox->Select( pEntry );
667 GetFirstEntryHdl(pBox);
668 return 0;
670 else
671 m_pPasswdCB->Check(aCurPasswd.getLength() > 0);
673 else if (pEntry )
675 m_pCurName->Enable(sal_True);
676 m_pOptionsPB->Enable(true);
677 SectRepr* pRepr=(SectRepr*) pEntry->GetUserData();
678 SwSectionData const& rData( pRepr->GetSectionData() );
679 m_pConditionED->SetText(rData.GetCondition());
680 m_pHideCB->Enable();
681 m_pHideCB->SetState((rData.IsHidden()) ? STATE_CHECK : STATE_NOCHECK);
682 bool bHide = STATE_CHECK == m_pHideCB->GetState();
683 m_pConditionED->Enable(bHide);
684 m_pConditionFT->Enable(bHide);
685 m_pPasswdCB->Check(rData.GetPassword().getLength() > 0);
687 m_pOK->Enable();
688 m_pPasswdCB->Enable();
689 m_pCurName->SetText(pBox->GetEntryText(pEntry));
690 m_pCurName->Enable();
691 m_pDismiss->Enable();
692 String aFile = pRepr->GetFile();
693 String sSub = pRepr->GetSubRegion();
694 m_bSubRegionsFilled = false;
695 m_pSubRegionED->Clear();
696 if(aFile.Len()||sSub.Len())
698 m_pFileCB->Check(true);
699 m_pFileNameED->SetText(aFile);
700 m_pSubRegionED->SetText(sSub);
701 m_pDDECB->Check(rData.GetType() == DDE_LINK_SECTION);
703 else
705 m_pFileCB->Check(false);
706 m_pFileNameED->SetText(aFile);
707 m_pDDECB->Enable(false);
708 m_pDDECB->Check(false);
710 UseFileHdl(m_pFileCB);
711 DDEHdl(m_pDDECB);
712 m_pProtectCB->SetState((rData.IsProtectFlag())
713 ? STATE_CHECK : STATE_NOCHECK);
714 m_pProtectCB->Enable();
716 // edit in readonly sections
717 m_pEditInReadonlyCB->SetState((rData.IsEditInReadonlyFlag())
718 ? STATE_CHECK : STATE_NOCHECK);
719 m_pEditInReadonlyCB->Enable();
721 bool bPasswdEnabled = m_pProtectCB->IsChecked();
722 m_pPasswdCB->Enable(bPasswdEnabled);
723 m_pPasswdPB->Enable(bPasswdEnabled);
725 bDontCheckPasswd = sal_False;
726 return 0;
729 IMPL_LINK( SwEditRegionDlg, DeselectHdl, SvTreeListBox *, pBox )
731 if( !pBox->GetSelectionCount() )
733 m_pHideCB->Enable(false);
734 m_pProtectCB->Enable(false);
735 // edit in readonly sections
736 m_pEditInReadonlyCB->Enable(false);
738 m_pPasswdCB->Enable(false);
739 m_pConditionFT->Enable(false);
740 m_pConditionED->Enable(false);
741 m_pFileCB->Enable(sal_False);
742 m_pDDEFrame->Enable(false);
743 m_pDDECB->Enable(false);
744 m_pCurName->Enable(false);
746 UseFileHdl(m_pFileCB);
747 DDEHdl(m_pDDECB);
749 return 0;
752 /*---------------------------------------------------------------------
753 Description: in OkHdl the modified settings are being applied
754 and reversed regions are deleted
755 ---------------------------------------------------------------------*/
756 IMPL_LINK_NOARG(SwEditRegionDlg, OkHdl)
758 // temp. Array because during changing of a region the position
759 // inside of the "Core-Arrays" can be shifted:
760 // - at linked regions, when they have more SubRegions or get
761 // new ones.
762 // StartUndo must certainly also happen not before the formats
763 // are copied (ClearRedo!)
765 const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
766 SwSectionFmts aOrigArray(rDocFmts);
768 rSh.StartAllAction();
769 rSh.StartUndo();
770 rSh.ResetSelect( 0,sal_False );
771 SvTreeListEntry* pEntry = m_pTree->First();
773 while( pEntry )
775 SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
776 SwSectionFmt* pFmt = aOrigArray[ pRepr->GetArrPos() ];
777 if (!pRepr->GetSectionData().IsProtectFlag())
779 pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
781 sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
782 if( USHRT_MAX != nNewPos )
784 SfxItemSet* pSet = pFmt->GetAttrSet().Clone( sal_False );
785 if( pFmt->GetCol() != pRepr->GetCol() )
786 pSet->Put( pRepr->GetCol() );
788 if( pFmt->GetBackground(sal_False) != pRepr->GetBackground() )
789 pSet->Put( pRepr->GetBackground() );
791 if( pFmt->GetFtnAtTxtEnd(sal_False) != pRepr->GetFtnNtAtEnd() )
792 pSet->Put( pRepr->GetFtnNtAtEnd() );
794 if( pFmt->GetEndAtTxtEnd(sal_False) != pRepr->GetEndNtAtEnd() )
795 pSet->Put( pRepr->GetEndNtAtEnd() );
797 if( pFmt->GetBalancedColumns() != pRepr->GetBalance() )
798 pSet->Put( pRepr->GetBalance() );
800 if( pFmt->GetFrmDir() != pRepr->GetFrmDir() )
801 pSet->Put( pRepr->GetFrmDir() );
803 if( pFmt->GetLRSpace() != pRepr->GetLRSpace())
804 pSet->Put( pRepr->GetLRSpace());
806 rSh.UpdateSection( nNewPos, pRepr->GetSectionData(),
807 pSet->Count() ? pSet : 0 );
808 delete pSet;
810 pEntry = m_pTree->Next( pEntry );
813 for (SectReprArr::reverse_iterator aI = aSectReprArr.rbegin(), aEnd = aSectReprArr.rend(); aI != aEnd; ++aI)
815 SwSectionFmt* pFmt = aOrigArray[ aI->GetArrPos() ];
816 sal_uInt16 nNewPos = rDocFmts.GetPos( pFmt );
817 if( USHRT_MAX != nNewPos )
818 rSh.DelSectionFmt( nNewPos );
821 aOrigArray.clear();
823 // EndDialog must be called ahead of EndAction's end,
824 // otherwise ScrollError can occur.
825 EndDialog(RET_OK);
827 rSh.EndUndo();
828 rSh.EndAllAction();
830 return 0;
833 /*---------------------------------------------------------------------
834 Description: Toggle protect
835 ---------------------------------------------------------------------*/
836 IMPL_LINK( SwEditRegionDlg, ChangeProtectHdl, TriStateBox *, pBox )
838 if(!CheckPasswd(pBox))
839 return 0;
840 pBox->EnableTriState(false);
841 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
842 OSL_ENSURE(pEntry,"no entry found");
843 sal_Bool bCheck = STATE_CHECK == pBox->GetState();
844 while( pEntry )
846 SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
847 pRepr->GetSectionData().SetProtectFlag(bCheck);
848 Image aImage = BuildBitmap(bCheck,
849 STATE_CHECK == m_pHideCB->GetState());
850 m_pTree->SetExpandedEntryBmp( pEntry, aImage );
851 m_pTree->SetCollapsedEntryBmp( pEntry, aImage );
852 pEntry = m_pTree->NextSelected(pEntry);
854 m_pPasswdCB->Enable(bCheck);
855 m_pPasswdPB->Enable(bCheck);
856 return 0;
859 /*---------------------------------------------------------------------
860 Description: Toggle hide
861 ---------------------------------------------------------------------*/
862 IMPL_LINK( SwEditRegionDlg, ChangeHideHdl, TriStateBox *, pBox )
864 if(!CheckPasswd(pBox))
865 return 0;
866 pBox->EnableTriState(false);
867 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
868 OSL_ENSURE(pEntry,"no entry found");
869 while( pEntry )
871 SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
872 pRepr->GetSectionData().SetHidden(STATE_CHECK == pBox->GetState());
874 Image aImage = BuildBitmap(STATE_CHECK == m_pProtectCB->GetState(),
875 STATE_CHECK == pBox->GetState());
876 m_pTree->SetExpandedEntryBmp( pEntry, aImage );
877 m_pTree->SetCollapsedEntryBmp( pEntry, aImage );
879 pEntry = m_pTree->NextSelected(pEntry);
882 bool bHide = STATE_CHECK == pBox->GetState();
883 m_pConditionED->Enable(bHide);
884 m_pConditionFT->Enable(bHide);
885 return 0;
888 /*---------------------------------------------------------------------
889 Description: Toggle edit in readonly
890 ---------------------------------------------------------------------*/
891 IMPL_LINK( SwEditRegionDlg, ChangeEditInReadonlyHdl, TriStateBox *, pBox )
893 if(!CheckPasswd(pBox))
894 return 0;
895 pBox->EnableTriState(false);
896 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
897 OSL_ENSURE(pEntry,"no entry found");
898 while( pEntry )
900 SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
901 pRepr->GetSectionData().SetEditInReadonlyFlag(
902 STATE_CHECK == pBox->GetState());
903 pEntry = m_pTree->NextSelected(pEntry);
906 return 0;
909 /*---------------------------------------------------------------------
910 Description: clear selected region
911 ---------------------------------------------------------------------*/
912 IMPL_LINK_NOARG(SwEditRegionDlg, ChangeDismissHdl)
914 if(!CheckPasswd())
915 return 0;
916 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
917 SvTreeListEntry* pChild;
918 SvTreeListEntry* pParent;
919 // at first mark all selected
920 while(pEntry)
922 const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
923 pSectRepr->SetSelected();
924 pEntry = m_pTree->NextSelected(pEntry);
926 pEntry = m_pTree->FirstSelected();
927 // then delete
928 while(pEntry)
930 const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
931 SvTreeListEntry* pRemove = 0;
932 bool bRestart = false;
933 if(pSectRepr->IsSelected())
935 aSectReprArr.insert( pSectRepr );
936 while( (pChild = m_pTree->FirstChild(pEntry) )!= 0 )
938 // because of the repositioning we have to start at the beginning again
939 bRestart = true;
940 pParent = m_pTree->GetParent(pEntry);
941 m_pTree->GetModel()->Move(pChild, pParent, m_pTree->GetModel()->GetRelPos(pEntry));
943 pRemove = pEntry;
945 if(bRestart)
946 pEntry = m_pTree->First();
947 else
948 pEntry = m_pTree->Next(pEntry);
949 if(pRemove)
950 m_pTree->GetModel()->Remove( pRemove );
953 if ( m_pTree->FirstSelected() == 0 )
955 m_pConditionFT->Enable(false);
956 m_pConditionED->Enable(false);
957 m_pDismiss-> Enable(sal_False);
958 m_pCurName->Enable(false);
959 m_pProtectCB->Enable(false);
960 m_pPasswdCB->Enable(false);
961 m_pHideCB->Enable(false);
962 // edit in readonly sections
963 m_pEditInReadonlyCB->Enable(false);
964 m_pEditInReadonlyCB->SetState(STATE_NOCHECK);
965 m_pProtectCB->SetState(STATE_NOCHECK);
966 m_pPasswdCB->Check(false);
967 m_pHideCB->SetState(STATE_NOCHECK);
968 m_pFileCB->Check(false);
969 // otherwise the focus would be on HelpButton
970 m_pOK->GrabFocus();
971 UseFileHdl(m_pFileCB);
973 return 0;
976 /*---------------------------------------------------------------------
977 Description: link CheckBox to file?
978 ---------------------------------------------------------------------*/
979 IMPL_LINK( SwEditRegionDlg, UseFileHdl, CheckBox *, pBox )
981 if(!CheckPasswd(pBox))
982 return 0;
983 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
984 pBox->EnableTriState(sal_False);
985 sal_Bool bMulti = 1 < m_pTree->GetSelectionCount();
986 sal_Bool bFile = pBox->IsChecked();
987 if(pEntry)
989 while(pEntry)
991 const SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
992 sal_Bool bContent = pSectRepr->IsContent();
993 if( pBox->IsChecked() && bContent && rSh.HasSelection() )
995 if( RET_NO == QueryBox( this, SW_RES(QB_CONNECT) ).Execute() )
996 pBox->Check( sal_False );
998 if( bFile )
999 pSectRepr->SetContent(sal_False);
1000 else
1002 pSectRepr->SetFile(aEmptyStr);
1003 pSectRepr->SetSubRegion(aEmptyStr);
1004 pSectRepr->GetSectionData().SetLinkFilePassword(aEmptyStr);
1007 pEntry = m_pTree->NextSelected(pEntry);
1009 m_pDDECB->Enable(bFile && ! bMulti);
1010 m_pDDEFrame->Enable(bFile && ! bMulti);
1011 if( bFile )
1013 m_pProtectCB->SetState(STATE_CHECK);
1014 m_pFileNameED->GrabFocus();
1017 else
1019 m_pDDECB->Check(false);
1020 DDEHdl(m_pDDECB);
1021 m_pSubRegionED->SetText(OUString());
1024 else
1026 pBox->Check(false);
1027 pBox->Enable(false);
1028 m_pDDECB->Check(false);
1029 m_pDDECB->Enable(false);
1030 m_pDDEFrame->Enable(false);
1032 return 0;
1035 /*---------------------------------------------------------------------
1036 Description: call dialog paste file
1037 ---------------------------------------------------------------------*/
1038 IMPL_LINK_NOARG(SwEditRegionDlg, FileSearchHdl)
1040 if(!CheckPasswd(0))
1041 return 0;
1043 m_pOldDefDlgParent = Application::GetDefDialogParent();
1044 Application::SetDefDialogParent( this );
1045 delete m_pDocInserter;
1046 m_pDocInserter =
1047 new ::sfx2::DocumentInserter( OUString("swriter") );
1048 m_pDocInserter->StartExecuteModal( LINK( this, SwEditRegionDlg, DlgClosedHdl ) );
1049 return 0;
1052 IMPL_LINK_NOARG(SwEditRegionDlg, OptionsHdl)
1054 if(!CheckPasswd())
1055 return 0;
1056 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1058 if(pEntry)
1060 SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1061 SfxItemSet aSet(rSh.GetView().GetPool(),
1062 RES_COL, RES_COL,
1063 RES_COLUMNBALANCE, RES_FRAMEDIR,
1064 RES_BACKGROUND, RES_BACKGROUND,
1065 RES_FRM_SIZE, RES_FRM_SIZE,
1066 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
1067 RES_LR_SPACE, RES_LR_SPACE,
1068 RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
1071 aSet.Put( pSectRepr->GetCol() );
1072 aSet.Put( pSectRepr->GetBackground() );
1073 aSet.Put( pSectRepr->GetFtnNtAtEnd() );
1074 aSet.Put( pSectRepr->GetEndNtAtEnd() );
1075 aSet.Put( pSectRepr->GetBalance() );
1076 aSet.Put( pSectRepr->GetFrmDir() );
1077 aSet.Put( pSectRepr->GetLRSpace() );
1079 const SwSectionFmts& rDocFmts = rSh.GetDoc()->GetSections();
1080 SwSectionFmts aOrigArray(rDocFmts);
1082 SwSectionFmt* pFmt = aOrigArray[pSectRepr->GetArrPos()];
1083 long nWidth = rSh.GetSectionWidth(*pFmt);
1084 aOrigArray.clear();
1085 if (!nWidth)
1086 nWidth = USHRT_MAX;
1088 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
1089 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
1091 SwSectionPropertyTabDialog aTabDlg(this, aSet, rSh);
1092 if(RET_OK == aTabDlg.Execute())
1094 const SfxItemSet* pOutSet = aTabDlg.GetOutputItemSet();
1095 if( pOutSet && pOutSet->Count() )
1097 const SfxPoolItem *pColItem, *pBrushItem,
1098 *pFtnItem, *pEndItem, *pBalanceItem,
1099 *pFrmDirItem, *pLRSpaceItem;
1100 SfxItemState eColState = pOutSet->GetItemState(
1101 RES_COL, sal_False, &pColItem );
1102 SfxItemState eBrushState = pOutSet->GetItemState(
1103 RES_BACKGROUND, sal_False, &pBrushItem );
1104 SfxItemState eFtnState = pOutSet->GetItemState(
1105 RES_FTN_AT_TXTEND, sal_False, &pFtnItem );
1106 SfxItemState eEndState = pOutSet->GetItemState(
1107 RES_END_AT_TXTEND, sal_False, &pEndItem );
1108 SfxItemState eBalanceState = pOutSet->GetItemState(
1109 RES_COLUMNBALANCE, sal_False, &pBalanceItem );
1110 SfxItemState eFrmDirState = pOutSet->GetItemState(
1111 RES_FRAMEDIR, sal_False, &pFrmDirItem );
1112 SfxItemState eLRState = pOutSet->GetItemState(
1113 RES_LR_SPACE, sal_False, &pLRSpaceItem);
1115 if( SFX_ITEM_SET == eColState ||
1116 SFX_ITEM_SET == eBrushState ||
1117 SFX_ITEM_SET == eFtnState ||
1118 SFX_ITEM_SET == eEndState ||
1119 SFX_ITEM_SET == eBalanceState||
1120 SFX_ITEM_SET == eFrmDirState||
1121 SFX_ITEM_SET == eLRState)
1123 SvTreeListEntry* pSelEntry = m_pTree->FirstSelected();
1124 while( pSelEntry )
1126 SectReprPtr pRepr = (SectReprPtr)pSelEntry->GetUserData();
1127 if( SFX_ITEM_SET == eColState )
1128 pRepr->GetCol() = *(SwFmtCol*)pColItem;
1129 if( SFX_ITEM_SET == eBrushState )
1130 pRepr->GetBackground() = *(SvxBrushItem*)pBrushItem;
1131 if( SFX_ITEM_SET == eFtnState )
1132 pRepr->GetFtnNtAtEnd() = *(SwFmtFtnAtTxtEnd*)pFtnItem;
1133 if( SFX_ITEM_SET == eEndState )
1134 pRepr->GetEndNtAtEnd() = *(SwFmtEndAtTxtEnd*)pEndItem;
1135 if( SFX_ITEM_SET == eBalanceState )
1136 pRepr->GetBalance().SetValue(((SwFmtNoBalancedColumns*)pBalanceItem)->GetValue());
1137 if( SFX_ITEM_SET == eFrmDirState )
1138 pRepr->GetFrmDir().SetValue(((SvxFrameDirectionItem*)pFrmDirItem)->GetValue());
1139 if( SFX_ITEM_SET == eLRState )
1140 pRepr->GetLRSpace() = *(SvxLRSpaceItem*)pLRSpaceItem;
1142 pSelEntry = m_pTree->NextSelected(pSelEntry);
1149 return 0;
1152 /*---------------------------------------------------------------------
1153 Description: Applying of the filename or the
1154 linked region
1155 ---------------------------------------------------------------------*/
1156 IMPL_LINK( SwEditRegionDlg, FileNameHdl, Edit *, pEdit )
1158 Selection aSelect = pEdit->GetSelection();
1159 if(!CheckPasswd())
1160 return 0;
1161 pEdit->SetSelection(aSelect);
1162 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1163 OSL_ENSURE(pEntry,"no entry found");
1164 SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1165 if (pEdit == m_pFileNameED)
1167 m_bSubRegionsFilled = false;
1168 m_pSubRegionED->Clear();
1169 if (m_pDDECB->IsChecked())
1171 String sLink( pEdit->GetText() );
1172 sal_uInt16 nPos = 0;
1173 while( STRING_NOTFOUND != (nPos = sLink.SearchAscii( " ", nPos )) )
1174 sLink.Erase( nPos--, 1 );
1176 nPos = sLink.SearchAndReplace( ' ', sfx2::cTokenSeparator );
1177 sLink.SearchAndReplace( ' ', sfx2::cTokenSeparator, nPos );
1179 pSectRepr->GetSectionData().SetLinkFileName( sLink );
1180 pSectRepr->GetSectionData().SetType( DDE_LINK_SECTION );
1182 else
1184 String sTmp(pEdit->GetText());
1185 if(sTmp.Len())
1187 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
1188 INetURLObject aAbs;
1189 if( pMedium )
1190 aAbs = pMedium->GetURLObject();
1191 sTmp = URIHelper::SmartRel2Abs(
1192 aAbs, sTmp, URIHelper::GetMaybeFileHdl() );
1194 pSectRepr->SetFile( sTmp );
1195 pSectRepr->GetSectionData().SetLinkFilePassword( aEmptyStr );
1198 else
1200 pSectRepr->SetSubRegion( pEdit->GetText() );
1202 return 0;
1205 IMPL_LINK( SwEditRegionDlg, DDEHdl, CheckBox*, pBox )
1207 if(!CheckPasswd(pBox))
1208 return 0;
1209 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1210 if(pEntry)
1212 bool bFile = m_pFileCB->IsChecked();
1213 SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1214 SwSectionData & rData( pSectRepr->GetSectionData() );
1215 sal_Bool bDDE = pBox->IsChecked();
1216 if(bDDE)
1218 m_pFileNameFT->Hide();
1219 m_pDDECommandFT->Enable();
1220 m_pDDECommandFT->Show();
1221 m_pSubRegionFT->Hide();
1222 m_pSubRegionED->Hide();
1223 if (FILE_LINK_SECTION == rData.GetType())
1225 pSectRepr->SetFile(OUString());
1226 m_pFileNameED->SetText(OUString());
1227 rData.SetLinkFilePassword(OUString());
1229 rData.SetType(DDE_LINK_SECTION);
1231 else
1233 m_pDDECommandFT->Hide();
1234 m_pFileNameFT->Enable(bFile);
1235 m_pFileNameFT->Show();
1236 m_pSubRegionED->Show();
1237 m_pSubRegionFT->Show();
1238 m_pSubRegionED->Enable(bFile);
1239 m_pSubRegionFT->Enable(bFile);
1240 m_pSubRegionED->Enable(bFile);
1241 if (DDE_LINK_SECTION == rData.GetType())
1243 rData.SetType(FILE_LINK_SECTION);
1244 pSectRepr->SetFile(OUString());
1245 rData.SetLinkFilePassword(OUString());
1246 m_pFileNameED->SetText(OUString());
1249 m_pFilePB->Enable(bFile && !bDDE);
1251 return 0;
1254 IMPL_LINK( SwEditRegionDlg, ChangePasswdHdl, Button *, pBox )
1256 bool bChange = pBox == m_pPasswdPB;
1257 if(!CheckPasswd(0))
1259 if(!bChange)
1260 m_pPasswdCB->Check(!m_pPasswdCB->IsChecked());
1261 return 0;
1263 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1264 bool bSet = bChange ? bChange : m_pPasswdCB->IsChecked();
1265 OSL_ENSURE(pEntry,"no entry found");
1266 while( pEntry )
1268 SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
1269 if(bSet)
1271 if(!pRepr->GetTempPasswd().getLength() || bChange)
1273 SfxPasswordDialog aPasswdDlg(this);
1274 aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
1275 if(RET_OK == aPasswdDlg.Execute())
1277 String sNewPasswd( aPasswdDlg.GetPassword() );
1278 if( aPasswdDlg.GetConfirm() == sNewPasswd )
1280 SvPasswordHelper::GetHashPassword( pRepr->GetTempPasswd(), sNewPasswd );
1282 else
1284 InfoBox(pBox, SW_RES(REG_WRONG_PASSWD_REPEAT)).Execute();
1285 ChangePasswdHdl(pBox);
1286 break;
1289 else
1291 if(!bChange)
1292 m_pPasswdCB->Check(false);
1293 break;
1296 pRepr->GetSectionData().SetPassword(pRepr->GetTempPasswd());
1298 else
1300 pRepr->GetSectionData().SetPassword(uno::Sequence<sal_Int8 >());
1302 pEntry = m_pTree->NextSelected(pEntry);
1304 return 0;
1307 /*---------------------------------------------------------------------
1308 Description: the current region name is being added to the
1309 TreeListBox immediately during editing, with empty
1310 string no Ok()
1311 ---------------------------------------------------------------------*/
1312 IMPL_LINK_NOARG(SwEditRegionDlg, NameEditHdl)
1314 if(!CheckPasswd(0))
1315 return 0;
1316 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1317 OSL_ENSURE(pEntry,"no entry found");
1318 if (pEntry)
1320 OUString aName = m_pCurName->GetText();
1321 m_pTree->SetEntryText(pEntry,aName);
1322 SectReprPtr pRepr = (SectReprPtr) pEntry->GetUserData();
1323 pRepr->GetSectionData().SetSectionName(aName);
1325 m_pOK->Enable(!aName.isEmpty());
1327 return 0;
1330 IMPL_LINK( SwEditRegionDlg, ConditionEditHdl, Edit *, pEdit )
1332 Selection aSelect = pEdit->GetSelection();
1333 if(!CheckPasswd(0))
1334 return 0;
1335 pEdit->SetSelection(aSelect);
1336 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1337 OSL_ENSURE(pEntry,"no entry found");
1338 while( pEntry )
1340 SectReprPtr pRepr = (SectReprPtr)pEntry->GetUserData();
1341 pRepr->GetSectionData().SetCondition(pEdit->GetText());
1342 pEntry = m_pTree->NextSelected(pEntry);
1344 return 0;
1347 IMPL_LINK( SwEditRegionDlg, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
1349 String sFileName, sFilterName, sPassword;
1350 if ( _pFileDlg->GetError() == ERRCODE_NONE )
1352 SfxMedium* pMedium = m_pDocInserter->CreateMedium();
1353 if ( pMedium )
1355 sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1356 sFilterName = pMedium->GetFilter()->GetFilterName();
1357 const SfxPoolItem* pItem;
1358 if ( SFX_ITEM_SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, sal_False, &pItem ) )
1359 sPassword = ( (SfxStringItem*)pItem )->GetValue();
1360 ::lcl_ReadSections(*pMedium, *m_pSubRegionED);
1361 delete pMedium;
1365 SvTreeListEntry* pEntry = m_pTree->FirstSelected();
1366 OSL_ENSURE( pEntry, "no entry found" );
1367 if ( pEntry )
1369 SectReprPtr pSectRepr = (SectRepr*)pEntry->GetUserData();
1370 pSectRepr->SetFile( sFileName );
1371 pSectRepr->SetFilter( sFilterName );
1372 pSectRepr->GetSectionData().SetLinkFilePassword(sPassword);
1373 m_pFileNameED->SetText(pSectRepr->GetFile());
1376 Application::SetDefDialogParent( m_pOldDefDlgParent );
1377 return 0;
1380 IMPL_LINK( SwEditRegionDlg, SubRegionEventHdl, VclWindowEvent *, pEvent )
1382 if( !m_bSubRegionsFilled && pEvent && pEvent->GetId() == VCLEVENT_DROPDOWN_PRE_OPEN )
1384 //if necessary fill the names bookmarks/sections/tables now
1386 OUString sFileName = m_pFileNameED->GetText();
1387 if(!sFileName.isEmpty())
1389 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
1390 INetURLObject aAbs;
1391 if( pMedium )
1392 aAbs = pMedium->GetURLObject();
1393 sFileName = URIHelper::SmartRel2Abs(
1394 aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1396 //load file and set the shell
1397 SfxMedium aMedium( sFileName, STREAM_STD_READ );
1398 sFileName = aMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1399 ::lcl_ReadSections(aMedium, *m_pSubRegionED);
1401 else
1402 lcl_FillSubRegionList(rSh, *m_pSubRegionED, 0);
1403 m_bSubRegionsFilled = true;
1405 return 0;
1408 Image SwEditRegionDlg::BuildBitmap( sal_Bool bProtect, sal_Bool bHidden )
1410 ImageList& rImgLst = aImageIL;
1411 return rImgLst.GetImage((!bHidden+(bProtect<<1)) + 1);
1414 /*--------------------------------------------------------------------
1415 Description: helper function - read region names from medium
1416 --------------------------------------------------------------------*/
1417 static void lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox )
1419 rBox.Clear();
1420 uno::Reference < embed::XStorage > xStg;
1421 if( rMedium.IsStorage() && (xStg = rMedium.GetStorage()).is() )
1423 std::vector<String*> aArr;
1424 sal_uInt32 nFormat = SotStorage::GetFormatID( xStg );
1425 if ( nFormat == SOT_FORMATSTR_ID_STARWRITER_60 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_60 ||
1426 nFormat == SOT_FORMATSTR_ID_STARWRITER_8 || nFormat == SOT_FORMATSTR_ID_STARWRITERGLOB_8)
1427 SwGetReaderXML()->GetSectionList( rMedium, aArr );
1429 for(std::vector<String*>::const_iterator it(aArr.begin()); it != aArr.end(); ++it) {
1430 rBox.InsertEntry( **it );
1431 delete *it;
1436 SwInsertSectionTabDialog::SwInsertSectionTabDialog(
1437 Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh) :
1438 SfxTabDialog( pParent, SW_RES(DLG_INSERT_SECTION), &rSet ),
1439 rWrtSh(rSh)
1440 , m_pSectionData(0)
1442 String sInsert(SW_RES(ST_INSERT));
1443 GetOKButton().SetText(sInsert);
1444 FreeResource();
1445 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
1446 OSL_ENSURE(pFact, "Dialogdiet fail!");
1447 AddTabPage(TP_INSERT_SECTION, SwInsertSectionTabPage::Create, 0);
1448 AddTabPage(TP_COLUMN, SwColumnPage::Create, 0);
1449 AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0);
1450 AddTabPage(TP_SECTION_FTNENDNOTES, SwSectionFtnEndTabPage::Create, 0);
1451 AddTabPage(TP_SECTION_INDENTS, SwSectionIndentTabPage::Create, 0);
1453 SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
1454 long nHtmlMode = rHtmlOpt.GetExportMode();
1456 bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
1457 if(bWeb)
1459 RemoveTabPage(TP_SECTION_FTNENDNOTES);
1460 RemoveTabPage(TP_SECTION_INDENTS);
1461 if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
1462 RemoveTabPage(TP_COLUMN);
1464 SetCurPageId(TP_INSERT_SECTION);
1467 SwInsertSectionTabDialog::~SwInsertSectionTabDialog()
1471 void SwInsertSectionTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
1473 if(TP_INSERT_SECTION == nId)
1474 ((SwInsertSectionTabPage&)rPage).SetWrtShell(rWrtSh);
1475 else if( TP_BACKGROUND == nId )
1477 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
1478 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
1479 rPage.PageCreated(aSet);
1481 else if( TP_COLUMN == nId )
1483 const SwFmtFrmSize& rSize = (const SwFmtFrmSize&)GetInputSetImpl()->Get(RES_FRM_SIZE);
1484 ((SwColumnPage&)rPage).SetPageWidth(rSize.GetWidth());
1485 ((SwColumnPage&)rPage).ShowBalance(sal_True);
1486 ((SwColumnPage&)rPage).SetInSection(sal_True);
1488 else if(TP_SECTION_INDENTS == nId)
1489 ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
1492 void SwInsertSectionTabDialog::SetSectionData(SwSectionData const& rSect)
1494 m_pSectionData.reset( new SwSectionData(rSect) );
1497 short SwInsertSectionTabDialog::Ok()
1499 short nRet = SfxTabDialog::Ok();
1500 OSL_ENSURE(m_pSectionData.get(),
1501 "SwInsertSectionTabDialog: no SectionData?");
1502 const SfxItemSet* pOutputItemSet = GetOutputItemSet();
1503 rWrtSh.InsertSection(*m_pSectionData, pOutputItemSet);
1504 SfxViewFrame* pViewFrm = rWrtSh.GetView().GetViewFrame();
1505 uno::Reference< frame::XDispatchRecorder > xRecorder =
1506 pViewFrm->GetBindings().GetRecorder();
1507 if ( xRecorder.is() )
1509 SfxRequest aRequest( pViewFrm, FN_INSERT_REGION);
1510 const SfxPoolItem* pCol;
1511 if(SFX_ITEM_SET == pOutputItemSet->GetItemState(RES_COL, sal_False, &pCol))
1513 aRequest.AppendItem(SfxUInt16Item(SID_ATTR_COLUMNS,
1514 ((const SwFmtCol*)pCol)->GetColumns().size()));
1516 aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_NAME,
1517 m_pSectionData->GetSectionName()));
1518 aRequest.AppendItem(SfxStringItem( FN_PARAM_REGION_CONDITION,
1519 m_pSectionData->GetCondition()));
1520 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_HIDDEN,
1521 m_pSectionData->IsHidden()));
1522 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_PROTECT,
1523 m_pSectionData->IsProtectFlag()));
1524 // edit in readonly sections
1525 aRequest.AppendItem(SfxBoolItem( FN_PARAM_REGION_EDIT_IN_READONLY,
1526 m_pSectionData->IsEditInReadonlyFlag()));
1528 String sLinkFileName( m_pSectionData->GetLinkFileName() );
1529 aRequest.AppendItem(SfxStringItem( FN_PARAM_1, sLinkFileName.GetToken( 0, sfx2::cTokenSeparator )));
1530 aRequest.AppendItem(SfxStringItem( FN_PARAM_2, sLinkFileName.GetToken( 1, sfx2::cTokenSeparator )));
1531 aRequest.AppendItem(SfxStringItem( FN_PARAM_3, sLinkFileName.GetToken( 2, sfx2::cTokenSeparator )));
1532 aRequest.Done();
1534 return nRet;
1537 SwInsertSectionTabPage::SwInsertSectionTabPage(
1538 Window *pParent, const SfxItemSet &rAttrSet) :
1539 SfxTabPage( pParent, SW_RES(TP_INSERT_SECTION), rAttrSet ),
1540 aNameFL ( this, SW_RES( FL_NAME ) ),
1541 aCurName ( this, SW_RES( ED_RNAME ) ),
1542 aLinkFL ( this, SW_RES( FL_LINK ) ),
1543 aFileCB ( this, SW_RES( CB_FILE ) ),
1544 aDDECB ( this, SW_RES( CB_DDE ) ) ,
1545 aDDECommandFT ( this, SW_RES( FT_DDE ) ) ,
1546 aFileNameFT ( this, SW_RES( FT_FILE ) ) ,
1547 aFileNameED ( this, SW_RES( ED_FILE ) ),
1548 aFilePB ( this, SW_RES( PB_FILE ) ),
1549 aSubRegionFT ( this, SW_RES( FT_SUBREG ) ) ,
1550 aSubRegionED ( this, SW_RES( LB_SUBREG ) ) ,
1552 aProtectFL ( this, SW_RES( FL_PROTECT ) ),
1553 aProtectCB ( this, SW_RES( CB_PROTECT ) ),
1554 aPasswdCB ( this, SW_RES( CB_PASSWD ) ),
1555 aPasswdPB ( this, SW_RES( PB_PASSWD ) ),
1557 aHideFL ( this, SW_RES( FL_HIDE ) ),
1558 aHideCB ( this, SW_RES( CB_HIDE ) ),
1559 aConditionFT ( this, SW_RES( FT_CONDITION ) ),
1560 aConditionED ( this, SW_RES( ED_CONDITION ) ),
1561 // edit in readonly sections
1562 aPropertiesFL ( this, SW_RES( FL_PROPERTIES ) ),
1563 aEditInReadonlyCB ( this, SW_RES( CB_EDIT_IN_READONLY ) ),
1565 m_pWrtSh(0),
1566 m_pDocInserter(NULL),
1567 m_pOldDefDlgParent(NULL)
1569 FreeResource();
1571 aProtectCB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, ChangeProtectHdl));
1572 aPasswdCB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
1573 aPasswdPB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, ChangePasswdHdl));
1574 aHideCB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, ChangeHideHdl));
1575 // edit in readonly sections
1576 aEditInReadonlyCB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, ChangeEditInReadonlyHdl));
1577 aFileCB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, UseFileHdl ));
1578 aFilePB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, FileSearchHdl ));
1579 aCurName.SetModifyHdl ( LINK( this, SwInsertSectionTabPage, NameEditHdl));
1580 aDDECB.SetClickHdl ( LINK( this, SwInsertSectionTabPage, DDEHdl ));
1581 ChangeProtectHdl(&aProtectCB);
1582 aPasswdPB.SetAccessibleRelationMemberOf(&aProtectFL);
1583 aSubRegionED.EnableAutocomplete( sal_True, sal_True );
1586 SwInsertSectionTabPage::~SwInsertSectionTabPage()
1588 delete m_pDocInserter;
1591 void SwInsertSectionTabPage::SetWrtShell(SwWrtShell& rSh)
1593 m_pWrtSh = &rSh;
1595 bool bWeb = 0 != PTR_CAST(SwWebDocShell, m_pWrtSh->GetView().GetDocShell());
1596 if(bWeb)
1598 aHideCB .Hide();
1599 aConditionED .Hide();
1600 aConditionFT .Hide();
1601 aDDECB .Hide();
1602 aDDECommandFT .Hide();
1605 lcl_FillSubRegionList( *m_pWrtSh, aSubRegionED, &aCurName );
1607 SwSectionData *const pSectionData =
1608 static_cast<SwInsertSectionTabDialog*>(GetTabDialog())
1609 ->GetSectionData();
1610 if (pSectionData) // something set?
1612 aCurName.SetText(
1613 rSh.GetUniqueSectionName(& pSectionData->GetSectionName()));
1614 aProtectCB.Check( 0 != pSectionData->IsProtectFlag() );
1615 m_sFileName = pSectionData->GetLinkFileName();
1616 m_sFilePasswd = pSectionData->GetLinkFilePassword();
1617 aFileCB.Check( 0 != m_sFileName.Len() );
1618 aFileNameED.SetText( m_sFileName );
1619 UseFileHdl( &aFileCB );
1621 else
1623 aCurName.SetText( rSh.GetUniqueSectionName() );
1627 sal_Bool SwInsertSectionTabPage::FillItemSet( SfxItemSet& )
1629 SwSectionData aSection(CONTENT_SECTION, aCurName.GetText());
1630 aSection.SetCondition(aConditionED.GetText());
1631 sal_Bool bProtected = aProtectCB.IsChecked();
1632 aSection.SetProtectFlag(bProtected);
1633 aSection.SetHidden(aHideCB.IsChecked());
1634 // edit in readonly sections
1635 aSection.SetEditInReadonlyFlag(aEditInReadonlyCB.IsChecked());
1637 if(bProtected)
1639 aSection.SetPassword(m_aNewPasswd);
1641 String sFileName = aFileNameED.GetText();
1642 String sSubRegion = aSubRegionED.GetText();
1643 sal_Bool bDDe = aDDECB.IsChecked();
1644 if(aFileCB.IsChecked() && (sFileName.Len() || sSubRegion.Len() || bDDe))
1646 String aLinkFile;
1647 if( bDDe )
1649 aLinkFile = sFileName;
1651 sal_uInt16 nPos = 0;
1652 while( STRING_NOTFOUND != (nPos = aLinkFile.SearchAscii( " ", nPos )) )
1653 aLinkFile.Erase( nPos--, 1 );
1655 nPos = aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeparator );
1656 aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeparator, nPos );
1658 else
1660 if(sFileName.Len())
1662 SfxMedium* pMedium = m_pWrtSh->GetView().GetDocShell()->GetMedium();
1663 INetURLObject aAbs;
1664 if( pMedium )
1665 aAbs = pMedium->GetURLObject();
1666 aLinkFile = URIHelper::SmartRel2Abs(
1667 aAbs, sFileName, URIHelper::GetMaybeFileHdl() );
1668 aSection.SetLinkFilePassword( m_sFilePasswd );
1671 aLinkFile += sfx2::cTokenSeparator;
1672 aLinkFile += m_sFilterName;
1673 aLinkFile += sfx2::cTokenSeparator;
1674 aLinkFile += sSubRegion;
1677 aSection.SetLinkFileName(aLinkFile);
1678 if(aLinkFile.Len())
1680 aSection.SetType( aDDECB.IsChecked() ?
1681 DDE_LINK_SECTION :
1682 FILE_LINK_SECTION);
1685 ((SwInsertSectionTabDialog*)GetTabDialog())->SetSectionData(aSection);
1686 return sal_True;
1689 void SwInsertSectionTabPage::Reset( const SfxItemSet& )
1693 SfxTabPage* SwInsertSectionTabPage::Create( Window* pParent,
1694 const SfxItemSet& rAttrSet)
1696 return new SwInsertSectionTabPage(pParent, rAttrSet);
1699 IMPL_LINK( SwInsertSectionTabPage, ChangeHideHdl, CheckBox *, pBox )
1701 sal_Bool bHide = pBox->IsChecked();
1702 aConditionED.Enable(bHide);
1703 aConditionFT.Enable(bHide);
1704 return 0;
1707 IMPL_LINK_NOARG(SwInsertSectionTabPage, ChangeEditInReadonlyHdl)
1709 return 0;
1712 IMPL_LINK( SwInsertSectionTabPage, ChangeProtectHdl, CheckBox *, pBox )
1714 sal_Bool bCheck = pBox->IsChecked();
1715 aPasswdCB.Enable(bCheck);
1716 aPasswdPB.Enable(bCheck);
1717 return 0;
1720 IMPL_LINK( SwInsertSectionTabPage, ChangePasswdHdl, Button *, pButton )
1722 sal_Bool bChange = pButton == &aPasswdPB;
1723 sal_Bool bSet = bChange ? bChange : aPasswdCB.IsChecked();
1724 if(bSet)
1726 if(!m_aNewPasswd.getLength() || bChange)
1728 SfxPasswordDialog aPasswdDlg(this);
1729 aPasswdDlg.ShowExtras(SHOWEXTRAS_CONFIRM);
1730 if(RET_OK == aPasswdDlg.Execute())
1732 String sNewPasswd( aPasswdDlg.GetPassword() );
1733 if( aPasswdDlg.GetConfirm() == sNewPasswd )
1735 SvPasswordHelper::GetHashPassword( m_aNewPasswd, sNewPasswd );
1737 else
1739 InfoBox(pButton, SW_RES(REG_WRONG_PASSWD_REPEAT)).Execute();
1742 else if(!bChange)
1743 aPasswdCB.Check(sal_False);
1746 else
1747 m_aNewPasswd.realloc(0);
1748 return 0;
1751 IMPL_LINK_NOARG_INLINE_START(SwInsertSectionTabPage, NameEditHdl)
1753 String aName=aCurName.GetText();
1754 GetTabDialog()->GetOKButton().Enable(aName.Len() && aCurName.GetEntryPos( aName ) == USHRT_MAX);
1755 return 0;
1757 IMPL_LINK_NOARG_INLINE_END(SwInsertSectionTabPage, NameEditHdl)
1759 IMPL_LINK( SwInsertSectionTabPage, UseFileHdl, CheckBox *, pBox )
1761 if( pBox->IsChecked() )
1763 if( m_pWrtSh->HasSelection() &&
1764 RET_NO == QueryBox( this, SW_RES(QB_CONNECT) ).Execute() )
1765 pBox->Check( sal_False );
1768 sal_Bool bFile = pBox->IsChecked();
1769 aFileNameFT.Enable(bFile);
1770 aFileNameED.Enable(bFile);
1771 aFilePB.Enable(bFile);
1772 aSubRegionFT.Enable(bFile);
1773 aSubRegionED.Enable(bFile);
1774 aDDECommandFT.Enable(bFile);
1775 aDDECB.Enable(bFile);
1776 if( bFile )
1778 aFileNameED.GrabFocus();
1779 aProtectCB.Check( sal_True );
1781 else
1783 aDDECB.Check(sal_False);
1784 DDEHdl(&aDDECB);
1786 return 0;
1789 IMPL_LINK_NOARG(SwInsertSectionTabPage, FileSearchHdl)
1791 m_pOldDefDlgParent = Application::GetDefDialogParent();
1792 Application::SetDefDialogParent( this );
1793 delete m_pDocInserter;
1794 m_pDocInserter = new ::sfx2::DocumentInserter(
1795 OUString("swriter") );
1796 m_pDocInserter->StartExecuteModal( LINK( this, SwInsertSectionTabPage, DlgClosedHdl ) );
1797 return 0;
1800 IMPL_LINK( SwInsertSectionTabPage, DDEHdl, CheckBox*, pBox )
1802 sal_Bool bDDE = pBox->IsChecked();
1803 sal_Bool bFile = aFileCB.IsChecked();
1804 aFilePB.Enable(!bDDE && bFile);
1805 if(bDDE)
1807 aFileNameFT.Hide();
1808 aDDECommandFT.Enable(bDDE);
1809 aDDECommandFT.Show();
1810 aSubRegionFT.Hide();
1811 aSubRegionED.Hide();
1812 aFileNameED.SetAccessibleName(aDDECommandFT.GetText());
1814 else
1816 aDDECommandFT.Hide();
1817 aFileNameFT.Enable(bFile);
1818 aFileNameFT.Show();
1819 aSubRegionFT.Show();
1820 aSubRegionED.Show();
1821 aSubRegionED.Enable(bFile);
1822 aFileNameED.SetAccessibleName(aFileNameFT.GetText());
1824 return 0;
1827 IMPL_LINK( SwInsertSectionTabPage, DlgClosedHdl, sfx2::FileDialogHelper *, _pFileDlg )
1829 if ( _pFileDlg->GetError() == ERRCODE_NONE )
1831 SfxMedium* pMedium = m_pDocInserter->CreateMedium();
1832 if ( pMedium )
1834 m_sFileName = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1835 m_sFilterName = pMedium->GetFilter()->GetFilterName();
1836 const SfxPoolItem* pItem;
1837 if ( SFX_ITEM_SET == pMedium->GetItemSet()->GetItemState( SID_PASSWORD, sal_False, &pItem ) )
1838 m_sFilePasswd = ( (SfxStringItem*)pItem )->GetValue();
1839 aFileNameED.SetText( INetURLObject::decode(
1840 m_sFileName, INET_HEX_ESCAPE, INetURLObject::DECODE_UNAMBIGUOUS, RTL_TEXTENCODING_UTF8 ) );
1841 ::lcl_ReadSections( *pMedium, aSubRegionED );
1842 delete pMedium;
1845 else
1846 m_sFilterName = m_sFilePasswd = aEmptyStr;
1848 Application::SetDefDialogParent( m_pOldDefDlgParent );
1849 return 0;
1852 // --------------------------------------------------------------
1854 // numbering format conversion:
1855 // ListBox - format - enum-value
1856 // 0 - A, B, C, ... - 0
1857 // 1 - a, b, c, ... - 1
1858 // 2 - I, II, III, ... - 2
1859 // 3 - i, ii, iii, ... - 3
1860 // 4 - 1, 2, 3, ... - 4
1861 // 5 - A, .., AA, .., - 9
1862 // 6 - a, .., aa, .., - 10
1864 inline SvxExtNumType GetNumType( sal_uInt16 n )
1866 return (SvxExtNumType)(4 < n ? n + 4 : n );
1869 SwSectionFtnEndTabPage::SwSectionFtnEndTabPage( Window *pParent,
1870 const SfxItemSet &rAttrSet)
1871 : SfxTabPage( pParent, SW_RES( TP_SECTION_FTNENDNOTES ), rAttrSet ),
1872 aFtnFL ( this, SW_RES( FL_FTN ) ),
1873 aFtnNtAtTextEndCB ( this, SW_RES( CB_FTN_AT_TXTEND ) ),
1875 aFtnNtNumCB ( this, SW_RES( CB_FTN_NUM ) ),
1876 aFtnOffsetLbl ( this, SW_RES( FT_FTN_OFFSET )),
1877 aFtnOffsetFld ( this, SW_RES( FLD_FTN_OFFSET )),
1879 aFtnNtNumFmtCB ( this, SW_RES( CB_FTN_NUM_FMT ) ),
1880 aFtnPrefixFT ( this, SW_RES( FT_FTN_PREFIX )),
1881 aFtnPrefixED ( this, SW_RES( ED_FTN_PREFIX )),
1882 aFtnNumViewBox ( this, SW_RES( LB_FTN_NUMVIEW ), INSERT_NUM_EXTENDED_TYPES),
1883 aFtnSuffixFT ( this, SW_RES( FT_FTN_SUFFIX )),
1884 aFtnSuffixED ( this, SW_RES( ED_FTN_SUFFIX )),
1886 aEndFL ( this, SW_RES( FL_END ) ),
1887 aEndNtAtTextEndCB ( this, SW_RES( CB_END_AT_TXTEND )),
1889 aEndNtNumCB ( this, SW_RES( CB_END_NUM )),
1890 aEndOffsetLbl ( this, SW_RES( FT_END_OFFSET )),
1891 aEndOffsetFld ( this, SW_RES( FLD_END_OFFSET )),
1893 aEndNtNumFmtCB ( this, SW_RES( CB_END_NUM_FMT ) ),
1894 aEndPrefixFT ( this, SW_RES( FT_END_PREFIX )),
1895 aEndPrefixED ( this, SW_RES( ED_END_PREFIX )),
1896 aEndNumViewBox ( this, SW_RES( LB_END_NUMVIEW ), INSERT_NUM_EXTENDED_TYPES),
1897 aEndSuffixFT ( this, SW_RES( FT_END_SUFFIX )),
1898 aEndSuffixED ( this, SW_RES( ED_END_SUFFIX ))
1900 FreeResource();
1902 Link aLk( LINK( this, SwSectionFtnEndTabPage, FootEndHdl));
1903 aFtnNtAtTextEndCB.SetClickHdl( aLk );
1904 aFtnNtNumCB.SetClickHdl( aLk );
1905 aEndNtAtTextEndCB.SetClickHdl( aLk );
1906 aEndNtNumCB.SetClickHdl( aLk );
1907 aFtnNtNumFmtCB.SetClickHdl( aLk );
1908 aEndNtNumFmtCB.SetClickHdl( aLk );
1911 SwSectionFtnEndTabPage::~SwSectionFtnEndTabPage()
1915 sal_Bool SwSectionFtnEndTabPage::FillItemSet( SfxItemSet& rSet )
1917 SwFmtFtnAtTxtEnd aFtn( aFtnNtAtTextEndCB.IsChecked()
1918 ? ( aFtnNtNumCB.IsChecked()
1919 ? ( aFtnNtNumFmtCB.IsChecked()
1920 ? FTNEND_ATTXTEND_OWNNUMANDFMT
1921 : FTNEND_ATTXTEND_OWNNUMSEQ )
1922 : FTNEND_ATTXTEND )
1923 : FTNEND_ATPGORDOCEND );
1925 switch( aFtn.GetValue() )
1927 case FTNEND_ATTXTEND_OWNNUMANDFMT:
1928 aFtn.SetNumType( aFtnNumViewBox.GetSelectedNumberingType() );
1929 aFtn.SetPrefix( aFtnPrefixED.GetText().replaceAll("\\t", "\t") ); // fdo#65666
1930 aFtn.SetSuffix( aFtnSuffixED.GetText().replaceAll("\\t", "\t") );
1931 // no break;
1933 case FTNEND_ATTXTEND_OWNNUMSEQ:
1934 aFtn.SetOffset( static_cast< sal_uInt16 >( aFtnOffsetFld.GetValue()-1 ) );
1935 // no break;
1938 SwFmtEndAtTxtEnd aEnd( aEndNtAtTextEndCB.IsChecked()
1939 ? ( aEndNtNumCB.IsChecked()
1940 ? ( aEndNtNumFmtCB.IsChecked()
1941 ? FTNEND_ATTXTEND_OWNNUMANDFMT
1942 : FTNEND_ATTXTEND_OWNNUMSEQ )
1943 : FTNEND_ATTXTEND )
1944 : FTNEND_ATPGORDOCEND );
1946 switch( aEnd.GetValue() )
1948 case FTNEND_ATTXTEND_OWNNUMANDFMT:
1949 aEnd.SetNumType( aEndNumViewBox.GetSelectedNumberingType() );
1950 aEnd.SetPrefix( aEndPrefixED.GetText().replaceAll("\\t", "\t") );
1951 aEnd.SetSuffix( aEndSuffixED.GetText().replaceAll("\\t", "\t") );
1952 // no break;
1954 case FTNEND_ATTXTEND_OWNNUMSEQ:
1955 aEnd.SetOffset( static_cast< sal_uInt16 >( aEndOffsetFld.GetValue()-1 ) );
1956 // no break;
1959 rSet.Put( aFtn );
1960 rSet.Put( aEnd );
1962 return sal_True;
1965 void SwSectionFtnEndTabPage::ResetState( sal_Bool bFtn,
1966 const SwFmtFtnEndAtTxtEnd& rAttr )
1968 CheckBox *pNtAtTextEndCB, *pNtNumCB, *pNtNumFmtCB;
1969 FixedText*pPrefixFT, *pSuffixFT;
1970 Edit *pPrefixED, *pSuffixED;
1971 SwNumberingTypeListBox *pNumViewBox;
1972 FixedText* pOffsetTxt;
1973 NumericField *pOffsetFld;
1975 if( bFtn )
1977 pNtAtTextEndCB = &aFtnNtAtTextEndCB;
1978 pNtNumCB = &aFtnNtNumCB;
1979 pNtNumFmtCB = &aFtnNtNumFmtCB;
1980 pPrefixFT = &aFtnPrefixFT;
1981 pPrefixED = &aFtnPrefixED;
1982 pSuffixFT = &aFtnSuffixFT;
1983 pSuffixED = &aFtnSuffixED;
1984 pNumViewBox = &aFtnNumViewBox;
1985 pOffsetTxt = &aFtnOffsetLbl;
1986 pOffsetFld = &aFtnOffsetFld;
1988 else
1990 pNtAtTextEndCB = &aEndNtAtTextEndCB;
1991 pNtNumCB = &aEndNtNumCB;
1992 pNtNumFmtCB = &aEndNtNumFmtCB;
1993 pPrefixFT = &aEndPrefixFT;
1994 pPrefixED = &aEndPrefixED;
1995 pSuffixFT = &aEndSuffixFT;
1996 pSuffixED = &aEndSuffixED;
1997 pNumViewBox = &aEndNumViewBox;
1998 pOffsetTxt = &aEndOffsetLbl;
1999 pOffsetFld = &aEndOffsetFld;
2002 sal_uInt16 eState = rAttr.GetValue();
2003 switch( eState )
2005 case FTNEND_ATTXTEND_OWNNUMANDFMT:
2006 pNtNumFmtCB->SetState( STATE_CHECK );
2007 // no break;
2009 case FTNEND_ATTXTEND_OWNNUMSEQ:
2010 pNtNumCB->SetState( STATE_CHECK );
2011 // no break;
2013 case FTNEND_ATTXTEND:
2014 pNtAtTextEndCB->SetState( STATE_CHECK );
2015 // no break;
2018 pNumViewBox->SelectNumberingType( rAttr.GetNumType() );
2019 pOffsetFld->SetValue( rAttr.GetOffset() + 1 );
2020 pPrefixED->SetText( rAttr.GetPrefix().replaceAll("\t", "\\t") );
2021 pSuffixED->SetText( rAttr.GetSuffix().replaceAll("\t", "\\t") );
2023 switch( eState )
2025 case FTNEND_ATPGORDOCEND:
2026 pNtNumCB->Enable( sal_False );
2027 // no break;
2029 case FTNEND_ATTXTEND:
2030 pNtNumFmtCB->Enable( sal_False );
2031 pOffsetFld->Enable( sal_False );
2032 pOffsetTxt->Enable( sal_False );
2033 // no break;
2035 case FTNEND_ATTXTEND_OWNNUMSEQ:
2036 pNumViewBox->Enable( sal_False );
2037 pPrefixFT->Enable( sal_False );
2038 pPrefixED->Enable( sal_False );
2039 pSuffixFT->Enable( sal_False );
2040 pSuffixED->Enable( sal_False );
2041 // no break;
2045 void SwSectionFtnEndTabPage::Reset( const SfxItemSet& rSet )
2047 ResetState( sal_True, (const SwFmtFtnAtTxtEnd&)rSet.Get(
2048 RES_FTN_AT_TXTEND, sal_False ));
2049 ResetState( sal_False, (const SwFmtEndAtTxtEnd&)rSet.Get(
2050 RES_END_AT_TXTEND, sal_False ));
2053 SfxTabPage* SwSectionFtnEndTabPage::Create( Window* pParent,
2054 const SfxItemSet& rAttrSet)
2056 return new SwSectionFtnEndTabPage(pParent, rAttrSet);
2059 IMPL_LINK( SwSectionFtnEndTabPage, FootEndHdl, CheckBox *, pBox )
2061 sal_Bool bFoot = &aFtnNtAtTextEndCB == pBox || &aFtnNtNumCB == pBox ||
2062 &aFtnNtNumFmtCB == pBox ;
2064 CheckBox *pNumBox, *pNumFmtBox, *pEndBox;
2065 SwNumberingTypeListBox* pNumViewBox;
2066 FixedText* pOffsetTxt;
2067 NumericField *pOffsetFld;
2068 FixedText*pPrefixFT, *pSuffixFT;
2069 Edit *pPrefixED, *pSuffixED;
2071 if( bFoot )
2073 pEndBox = &aFtnNtAtTextEndCB;
2074 pNumBox = &aFtnNtNumCB;
2075 pNumFmtBox = &aFtnNtNumFmtCB;
2076 pNumViewBox = &aFtnNumViewBox;
2077 pOffsetTxt = &aFtnOffsetLbl;
2078 pOffsetFld = &aFtnOffsetFld;
2079 pPrefixFT = &aFtnPrefixFT;
2080 pSuffixFT = &aFtnSuffixFT;
2081 pPrefixED = &aFtnPrefixED;
2082 pSuffixED = &aFtnSuffixED;
2084 else
2086 pEndBox = &aEndNtAtTextEndCB;
2087 pNumBox = &aEndNtNumCB;
2088 pNumFmtBox = &aEndNtNumFmtCB;
2089 pNumViewBox = &aEndNumViewBox;
2090 pOffsetTxt = &aEndOffsetLbl;
2091 pOffsetFld = &aEndOffsetFld;
2092 pPrefixFT = &aEndPrefixFT;
2093 pSuffixFT = &aEndSuffixFT;
2094 pPrefixED = &aEndPrefixED;
2095 pSuffixED = &aEndSuffixED;
2098 sal_Bool bEnableAtEnd = STATE_CHECK == pEndBox->GetState();
2099 sal_Bool bEnableNum = bEnableAtEnd && STATE_CHECK == pNumBox->GetState();
2100 sal_Bool bEnableNumFmt = bEnableNum && STATE_CHECK == pNumFmtBox->GetState();
2102 pNumBox->Enable( bEnableAtEnd );
2103 pOffsetTxt->Enable( bEnableNum );
2104 pOffsetFld->Enable( bEnableNum );
2105 pNumFmtBox->Enable( bEnableNum );
2106 pNumViewBox->Enable( bEnableNumFmt );
2107 pPrefixED->Enable( bEnableNumFmt );
2108 pSuffixED->Enable( bEnableNumFmt );
2109 pPrefixFT->Enable( bEnableNumFmt );
2110 pSuffixFT->Enable( bEnableNumFmt );
2112 return 0;
2115 SwSectionPropertyTabDialog::SwSectionPropertyTabDialog(
2116 Window* pParent, const SfxItemSet& rSet, SwWrtShell& rSh) :
2117 SfxTabDialog(pParent, SW_RES(DLG_SECTION_PROPERTIES), &rSet),
2118 rWrtSh(rSh)
2120 FreeResource();
2121 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2122 OSL_ENSURE(pFact, "Dialogdiet fail!");
2123 AddTabPage(TP_COLUMN, SwColumnPage::Create, 0);
2124 AddTabPage(TP_BACKGROUND, pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), 0 );
2125 AddTabPage(TP_SECTION_FTNENDNOTES, SwSectionFtnEndTabPage::Create, 0);
2126 AddTabPage(TP_SECTION_INDENTS, SwSectionIndentTabPage::Create, 0);
2128 SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
2129 long nHtmlMode = rHtmlOpt.GetExportMode();
2130 bool bWeb = 0 != PTR_CAST( SwWebDocShell, rSh.GetView().GetDocShell() );
2131 if(bWeb)
2133 RemoveTabPage(TP_SECTION_FTNENDNOTES);
2134 RemoveTabPage(TP_SECTION_INDENTS);
2135 if( HTML_CFG_NS40 != nHtmlMode && HTML_CFG_WRITER != nHtmlMode)
2136 RemoveTabPage(TP_COLUMN);
2140 SwSectionPropertyTabDialog::~SwSectionPropertyTabDialog()
2144 void SwSectionPropertyTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
2146 if( TP_BACKGROUND == nId )
2148 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
2149 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE, SVX_SHOW_SELECTOR));
2150 rPage.PageCreated(aSet);
2152 else if( TP_COLUMN == nId )
2154 ((SwColumnPage&)rPage).ShowBalance(sal_True);
2155 ((SwColumnPage&)rPage).SetInSection(sal_True);
2157 else if(TP_SECTION_INDENTS == nId)
2158 ((SwSectionIndentTabPage&)rPage).SetWrtShell(rWrtSh);
2161 SwSectionIndentTabPage::SwSectionIndentTabPage( Window *pParent, const SfxItemSet &rAttrSet ) :
2162 SfxTabPage(pParent, SW_RES(TP_SECTION_INDENTS), rAttrSet),
2163 aIndentFL(this, SW_RES(FL_INDENT )),
2164 aBeforeFT(this, SW_RES(FT_BEFORE )),
2165 aBeforeMF(this, SW_RES(MF_BEFORE )),
2166 aAfterFT(this, SW_RES(FT_AFTER )),
2167 aAfterMF(this, SW_RES(MF_AFTER )),
2168 aPreviewWin(this, SW_RES(WIN_PREVIEW ))
2170 FreeResource();
2171 Link aLk = LINK(this, SwSectionIndentTabPage, IndentModifyHdl);
2172 aBeforeMF.SetModifyHdl(aLk);
2173 aAfterMF.SetModifyHdl(aLk);
2174 aPreviewWin.SetAccessibleName(aIndentFL.GetText());
2177 SwSectionIndentTabPage::~SwSectionIndentTabPage()
2181 sal_Bool SwSectionIndentTabPage::FillItemSet( SfxItemSet& rSet)
2183 if(aBeforeMF.IsValueModified() ||
2184 aAfterMF.IsValueModified())
2186 SvxLRSpaceItem aLRSpace(
2187 static_cast< long >(aBeforeMF.Denormalize(aBeforeMF.GetValue(FUNIT_TWIP))) ,
2188 static_cast< long >(aAfterMF.Denormalize(aAfterMF.GetValue(FUNIT_TWIP))), 0, 0, RES_LR_SPACE);
2189 rSet.Put(aLRSpace);
2191 return sal_True;
2194 void SwSectionIndentTabPage::Reset( const SfxItemSet& rSet)
2196 //this page doesn't show up in HTML mode
2197 FieldUnit aMetric = ::GetDfltMetric(sal_False);
2198 SetMetric(aBeforeMF, aMetric);
2199 SetMetric(aAfterMF , aMetric);
2201 SfxItemState eItemState = rSet.GetItemState( RES_LR_SPACE );
2202 if ( eItemState >= SFX_ITEM_AVAILABLE )
2204 const SvxLRSpaceItem& rSpace =
2205 (const SvxLRSpaceItem&)rSet.Get( RES_LR_SPACE );
2207 aBeforeMF.SetValue( aBeforeMF.Normalize(rSpace.GetLeft()), FUNIT_TWIP );
2208 aAfterMF.SetValue( aAfterMF.Normalize(rSpace.GetRight()), FUNIT_TWIP );
2210 else
2212 aBeforeMF.SetEmptyFieldValue();
2213 aAfterMF.SetEmptyFieldValue();
2215 aBeforeMF.SaveValue();
2216 aAfterMF.SaveValue();
2217 IndentModifyHdl(0);
2220 SfxTabPage* SwSectionIndentTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet)
2222 return new SwSectionIndentTabPage(pParent, rAttrSet);
2225 void SwSectionIndentTabPage::SetWrtShell(SwWrtShell& rSh)
2227 //set sensible values at the preview
2228 aPreviewWin.SetAdjust(SVX_ADJUST_BLOCK);
2229 aPreviewWin.SetLastLine(SVX_ADJUST_BLOCK);
2230 const SwRect& rPageRect = rSh.GetAnyCurRect( RECT_PAGE, 0 );
2231 Size aPageSize(rPageRect.Width(), rPageRect.Height());
2232 aPreviewWin.SetSize(aPageSize);
2235 IMPL_LINK_NOARG(SwSectionIndentTabPage, IndentModifyHdl)
2237 aPreviewWin.SetLeftMargin( static_cast< long >(aBeforeMF.Denormalize(aBeforeMF.GetValue(FUNIT_TWIP))) );
2238 aPreviewWin.SetRightMargin( static_cast< long >(aAfterMF.Denormalize(aAfterMF.GetValue(FUNIT_TWIP))) );
2239 aPreviewWin.Draw(sal_True);
2240 return 0;
2243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */