1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/shl.hxx>
21 #include <tools/urlobj.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <vcl/settings.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/filedlghelper.hxx>
27 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
31 #include <svx/dialmgr.hxx>
32 #include <svx/svdobj.hxx>
33 #include <svx/svdopath.hxx>
34 #include "svx/drawitem.hxx"
35 #include <svx/xpool.hxx>
36 #include <svx/xtable.hxx>
37 #include "cuitabline.hxx"
38 #include <svx/svxdlg.hxx>
39 #include <dialmgr.hxx>
40 #include "svx/dlgutil.hxx"
41 #include <basegfx/range/b2drange.hxx>
42 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <basegfx/polygon/b2dpolygon.hxx>
45 #include <basegfx/polygon/b2dpolypolygontools.hxx>
46 #include <basegfx/matrix/b2dhommatrixtools.hxx>
47 #include <svx/dialogs.hrc>
49 #define XOUT_WIDTH 150
51 SvxLineEndDefTabPage::SvxLineEndDefTabPage
54 const SfxItemSet
& rInAttrs
59 , "cui/ui/lineendstabpage.ui"
61 rOutAttrs ( rInAttrs
),
64 pXPool ( (XOutdevItemPool
*) rInAttrs
.GetPool() ),
65 aXLStyle ( XLINE_SOLID
),
66 aXWidth ( XOUT_WIDTH
),
67 aXColor ( OUString(), COL_BLACK
),
68 aXLineAttr ( pXPool
),
69 rXLSet ( aXLineAttr
.GetItemSet() ),
72 get(m_pEdtName
,"EDT_NAME");
73 get(m_pLbLineEnds
,"LB_LINEENDS");
74 get(m_pBtnAdd
,"BTN_ADD");
75 get(m_pBtnModify
,"BTN_MODIFY");
76 get(m_pBtnDelete
,"BTN_DELETE");
77 get(m_pBtnLoad
,"BTN_LOAD");
78 get(m_pBtnSave
,"BTN_SAVE");
79 get(m_pCtlPreview
,"CTL_PREVIEW");
81 // this page needs ExchangeSupport
84 rXLSet
.Put( aXLStyle
);
85 rXLSet
.Put( aXWidth
);
86 rXLSet
.Put( aXColor
);
87 rXLSet
.Put( XLineStartWidthItem( m_pCtlPreview
->GetOutputSize().Height() / 2 ) );
88 rXLSet
.Put( XLineEndWidthItem( m_pCtlPreview
->GetOutputSize().Height() / 2 ) );
91 m_pCtlPreview
->SetLineAttributes(aXLineAttr
.GetItemSet());
93 m_pBtnAdd
->SetClickHdl( LINK( this, SvxLineEndDefTabPage
, ClickAddHdl_Impl
) );
94 m_pBtnModify
->SetClickHdl( LINK( this, SvxLineEndDefTabPage
, ClickModifyHdl_Impl
) );
95 m_pBtnDelete
->SetClickHdl( LINK( this, SvxLineEndDefTabPage
, ClickDeleteHdl_Impl
) );
96 m_pBtnLoad
->SetClickHdl( LINK( this, SvxLineEndDefTabPage
, ClickLoadHdl_Impl
) );
97 m_pBtnSave
->SetClickHdl( LINK( this, SvxLineEndDefTabPage
, ClickSaveHdl_Impl
) );
99 m_pLbLineEnds
->SetSelectHdl( LINK( this, SvxLineEndDefTabPage
, SelectLineEndHdl_Impl
) );
103 void SvxLineEndDefTabPage::Resize()
105 rXLSet
.Put(XLineStartWidthItem(m_pCtlPreview
->GetOutputSize().Height() / 2 ));
106 rXLSet
.Put(XLineEndWidthItem(m_pCtlPreview
->GetOutputSize().Height() / 2 ));
107 SfxTabPage::Resize();
112 SvxLineEndDefTabPage::~SvxLineEndDefTabPage()
118 void SvxLineEndDefTabPage::Construct()
120 m_pLbLineEnds
->Fill( pLineEndList
);
122 bool bCreateArrowPossible
= true;
126 bCreateArrowPossible
= false;
128 else if( !pPolyObj
->ISA( SdrPathObj
) )
130 SdrObjTransformInfoRec aInfoRec
;
131 pPolyObj
->TakeObjInfo( aInfoRec
);
132 SdrObject
* pNewObj
= 0;
133 if( aInfoRec
.bCanConvToPath
)
134 pNewObj
= pPolyObj
->ConvertToPolyObj( true, false );
136 bCreateArrowPossible
= pNewObj
&& pNewObj
->ISA( SdrPathObj
);
137 SdrObject::Free( pNewObj
);
140 if( !bCreateArrowPossible
)
141 m_pBtnAdd
->Disable();
146 void SvxLineEndDefTabPage::ActivatePage( const SfxItemSet
& )
148 if( nDlgType
== 0 ) // area dialog
150 // ActivatePage() is called before the dialog receives PageCreated() !!!
151 if( pLineEndList
.is() )
153 if( *pPosLineEndLb
!= LISTBOX_ENTRY_NOTFOUND
)
155 m_pLbLineEnds
->SelectEntryPos( *pPosLineEndLb
);
156 SelectLineEndHdl_Impl( this );
158 INetURLObject
aURL( pLineEndList
->GetPath() );
160 aURL
.Append( pLineEndList
->GetName() );
161 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
163 *pPosLineEndLb
= LISTBOX_ENTRY_NOTFOUND
;
170 int SvxLineEndDefTabPage::DeactivatePage( SfxItemSet
* _pSet
)
175 FillItemSet( *_pSet
);
177 return( LEAVE_PAGE
);
182 void SvxLineEndDefTabPage::CheckChanges_Impl()
184 sal_Int32 nPos
= m_pLbLineEnds
->GetSelectEntryPos();
186 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
188 OUString aString
= m_pEdtName
->GetText();
190 if( aString
!= m_pLbLineEnds
->GetSelectEntry() )
192 MessageDialog
aQueryBox( GetParentDialog()
193 ,"AskChangeLineEndDialog"
194 ,"cui/ui/querychangelineenddialog.ui");
196 if ( aQueryBox
.Execute() == RET_YES
)
197 ClickModifyHdl_Impl( this );
200 nPos
= m_pLbLineEnds
->GetSelectEntryPos();
202 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
203 *pPosLineEndLb
= nPos
;
208 bool SvxLineEndDefTabPage::FillItemSet( SfxItemSet
& rSet
)
210 if( nDlgType
== 0 ) // line dialog
212 if( *pPageType
== 3 )
216 long nPos
= m_pLbLineEnds
->GetSelectEntryPos();
217 XLineEndEntry
* pEntry
= pLineEndList
->GetLineEnd( nPos
);
219 rSet
.Put( XLineStartItem( pEntry
->GetName(), pEntry
->GetLineEnd() ) );
220 rSet
.Put( XLineEndItem( pEntry
->GetName(), pEntry
->GetLineEnd() ) );
228 void SvxLineEndDefTabPage::Reset( const SfxItemSet
& )
230 m_pLbLineEnds
->SelectEntryPos( 0 );
233 if( pLineEndList
->Count() > 0 )
235 int nPos
= m_pLbLineEnds
->GetSelectEntryPos();
237 XLineEndEntry
* pEntry
= pLineEndList
->GetLineEnd( nPos
);
239 m_pEdtName
->SetText( m_pLbLineEnds
->GetSelectEntry() );
241 rXLSet
.Put( XLineStartItem( OUString(), pEntry
->GetLineEnd() ) );
242 rXLSet
.Put( XLineEndItem( OUString(), pEntry
->GetLineEnd() ) );
245 m_pCtlPreview
->SetLineAttributes(aXLineAttr
.GetItemSet());
247 m_pCtlPreview
->Invalidate();
250 // determine button state
251 if( pLineEndList
->Count() )
253 m_pBtnModify
->Enable();
254 m_pBtnDelete
->Enable();
255 m_pBtnSave
->Enable();
259 m_pBtnModify
->Disable();
260 m_pBtnDelete
->Disable();
261 m_pBtnSave
->Disable();
267 SfxTabPage
* SvxLineEndDefTabPage::Create( Window
* pWindow
, const SfxItemSet
& rSet
)
269 return( new SvxLineEndDefTabPage( pWindow
, rSet
) );
274 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, SelectLineEndHdl_Impl
)
276 if( pLineEndList
->Count() > 0 )
278 int nPos
= m_pLbLineEnds
->GetSelectEntryPos();
280 XLineEndEntry
* pEntry
= pLineEndList
->GetLineEnd( nPos
);
282 m_pEdtName
->SetText( m_pLbLineEnds
->GetSelectEntry() );
284 rXLSet
.Put( XLineStartItem( OUString(), pEntry
->GetLineEnd() ) );
285 rXLSet
.Put( XLineEndItem( OUString(), pEntry
->GetLineEnd() ) );
288 m_pCtlPreview
->SetLineAttributes(aXLineAttr
.GetItemSet());
290 m_pCtlPreview
->Invalidate();
292 // Is not set before, in order to only take the new style,
293 // if there is an entry selected in the ListBox
301 long SvxLineEndDefTabPage::ChangePreviewHdl_Impl( void* )
303 m_pCtlPreview
->Invalidate();
309 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, ClickModifyHdl_Impl
)
311 sal_Int32 nPos
= m_pLbLineEnds
->GetSelectEntryPos();
313 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
315 ResMgr
& rMgr
= CUI_MGR();
316 OUString
aDesc( ResId( RID_SVXSTR_DESC_LINEEND
, rMgr
) );
317 OUString
aName( m_pEdtName
->GetText() );
318 long nCount
= pLineEndList
->Count();
319 bool bDifferent
= true;
321 // check whether the name is existing already
322 for ( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
323 if ( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
326 // if yes, repeat and demand a new name
329 MessageDialog
aWarningBox( GetParentDialog()
330 ,"DuplicateNameDialog"
331 ,"cui/ui/queryduplicatedialog.ui");
332 aWarningBox
.Execute();
334 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
335 DBG_ASSERT(pFact
, "Dialogdiet fail!");
336 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( GetParentDialog(), aName
, aDesc
);
337 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
340 while( !bDifferent
&& bLoop
&& pDlg
->Execute() == RET_OK
)
342 pDlg
->GetName( aName
);
345 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
347 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
354 aWarningBox
.Execute();
359 // if not existing, enter the entry
362 const XLineEndEntry
* pOldEntry
= pLineEndList
->GetLineEnd( nPos
);
366 // #123497# Need to replace the existing entry with a new one (old returned needs to be deleted)
367 XLineEndEntry
* pEntry
= new XLineEndEntry(pOldEntry
->GetLineEnd(), aName
);
368 delete pLineEndList
->Replace(pEntry
, nPos
);
370 m_pEdtName
->SetText( aName
);
372 m_pLbLineEnds
->Modify( *pEntry
, nPos
, pLineEndList
->GetUiBitmap( nPos
) );
373 m_pLbLineEnds
->SelectEntryPos( nPos
);
375 // Flag fuer modifiziert setzen
376 *pnLineEndListState
|= CT_MODIFIED
;
382 OSL_ENSURE(false, "LineEnd to be modified not existing (!)");
391 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, ClickAddHdl_Impl
)
395 const SdrObject
* pNewObj
;
396 SdrObject
* pConvPolyObj
= NULL
;
398 if( pPolyObj
->ISA( SdrPathObj
) )
404 SdrObjTransformInfoRec aInfoRec
;
405 pPolyObj
->TakeObjInfo( aInfoRec
);
407 if( aInfoRec
.bCanConvToPath
)
409 pNewObj
= pConvPolyObj
= pPolyObj
->ConvertToPolyObj( true, false );
411 if( !pNewObj
|| !pNewObj
->ISA( SdrPathObj
) )
412 return( 0L ); // cancel, additional safety, which
413 // has no use for group objects though.
415 else return( 0L ); // cancel
418 basegfx::B2DPolyPolygon
aNewPolyPolygon(((SdrPathObj
*)pNewObj
)->GetPathPoly());
419 basegfx::B2DRange
aNewRange(basegfx::tools::getRange(aNewPolyPolygon
));
422 aNewPolyPolygon
.transform(basegfx::tools::createTranslateB2DHomMatrix( -aNewRange
.getMinX(), -aNewRange
.getMinY()));
424 SdrObject::Free( pConvPolyObj
);
426 XLineEndEntry
* pEntry
;
428 ResMgr
& rMgr
= CUI_MGR();
429 OUString
aNewName( SVX_RES( RID_SVXSTR_LINEEND
) );
430 OUString
aDesc( ResId( RID_SVXSTR_DESC_LINEEND
, rMgr
) );
433 long nCount
= pLineEndList
->Count();
435 bool bDifferent
= false;
437 while ( !bDifferent
)
441 aName
+= OUString::number( j
++ );
444 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
445 if ( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
449 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
450 DBG_ASSERT(pFact
, "Dialogdiet fail!");
451 AbstractSvxNameDialog
* pDlg
= pFact
->CreateSvxNameDialog( GetParentDialog(), aName
, aDesc
);
452 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
455 while ( bLoop
&& pDlg
->Execute() == RET_OK
)
457 pDlg
->GetName( aName
);
460 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
462 if( aName
== pLineEndList
->GetLineEnd( i
)->GetName() )
469 pEntry
= new XLineEndEntry( aNewPolyPolygon
, aName
);
471 long nLineEndCount
= pLineEndList
->Count();
472 pLineEndList
->Insert( pEntry
, nLineEndCount
);
474 // add to the ListBox
475 m_pLbLineEnds
->Append( *pEntry
, pLineEndList
->GetUiBitmap( nLineEndCount
) );
476 m_pLbLineEnds
->SelectEntryPos( m_pLbLineEnds
->GetEntryCount() - 1 );
478 *pnLineEndListState
|= CT_MODIFIED
;
480 SelectLineEndHdl_Impl( this );
484 MessageDialog
aBox( GetParentDialog()
485 ,"DuplicateNameDialog"
486 ,"cui/ui/queryduplicatedialog.ui");
493 m_pBtnAdd
->Disable();
495 // determine button state
496 if ( pLineEndList
->Count() )
498 m_pBtnModify
->Enable();
499 m_pBtnDelete
->Enable();
500 m_pBtnSave
->Enable();
507 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, ClickDeleteHdl_Impl
)
509 sal_Int32 nPos
= m_pLbLineEnds
->GetSelectEntryPos();
511 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
513 MessageDialog
aQueryBox( GetParentDialog()
514 ,"AskDelLineEndDialog"
515 ,"cui/ui/querydeletelineenddialog.ui");
517 if ( aQueryBox
.Execute() == RET_YES
)
519 delete pLineEndList
->Remove( nPos
);
520 m_pLbLineEnds
->RemoveEntry( nPos
);
521 m_pLbLineEnds
->SelectEntryPos( 0 );
523 SelectLineEndHdl_Impl( this );
524 *pPageType
= 0; // LineEnd shall not be taken over
526 *pnLineEndListState
|= CT_MODIFIED
;
528 ChangePreviewHdl_Impl( this );
531 // determine button state
532 if( !pLineEndList
->Count() )
534 m_pBtnModify
->Disable();
535 m_pBtnDelete
->Disable();
536 m_pBtnSave
->Disable();
543 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, ClickLoadHdl_Impl
)
545 sal_uInt16 nReturn
= RET_YES
;
547 if ( *pnLineEndListState
& CT_MODIFIED
)
549 nReturn
= MessageDialog( GetParentDialog()
551 ,"cui/ui/querysavelistdialog.ui").Execute();
553 if ( nReturn
== RET_YES
)
554 pLineEndList
->Save();
557 if ( nReturn
!= RET_CANCEL
)
559 ::sfx2::FileDialogHelper
aDlg(com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0 );
560 OUString
aStrFilterType( "*.soe" );
561 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
562 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
563 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
565 if( aDlg
.Execute() == ERRCODE_NONE
)
567 INetURLObject
aURL( aDlg
.GetPath() );
568 INetURLObject
aPathURL( aURL
);
570 aPathURL
.removeSegment();
571 aPathURL
.removeFinalSlash();
573 XLineEndListRef pLeList
= XPropertyList::CreatePropertyList(XLINE_END_LIST
, aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), "" )->AsLineEndList();
574 pLeList
->SetName( aURL
.getName() );
575 if( pLeList
->Load() )
577 pLineEndList
= pLeList
;
578 ( (SvxLineTabDialog
*) GetParentDialog() )->SetNewLineEndList( pLineEndList
);
579 m_pLbLineEnds
->Clear();
580 m_pLbLineEnds
->Fill( pLineEndList
);
583 pLineEndList
->SetName( aURL
.getName() );
585 *pnLineEndListState
|= CT_CHANGED
;
586 *pnLineEndListState
&= ~CT_MODIFIED
;
589 MessageDialog( GetParentDialog()
590 ,"NoLoadedFileDialog"
591 ,"cui/ui/querynoloadedfiledialog.ui").Execute();
595 // determine button state
596 if ( pLineEndList
->Count() )
598 m_pBtnModify
->Enable();
599 m_pBtnDelete
->Enable();
600 m_pBtnSave
->Enable();
604 m_pBtnModify
->Disable();
605 m_pBtnDelete
->Disable();
606 m_pBtnSave
->Disable();
613 IMPL_LINK_NOARG(SvxLineEndDefTabPage
, ClickSaveHdl_Impl
)
615 ::sfx2::FileDialogHelper
aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, 0 );
616 OUString
aStrFilterType( "*.soe" );
617 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
619 INetURLObject
aFile( SvtPathOptions().GetPalettePath() );
620 DBG_ASSERT( aFile
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
622 if( !pLineEndList
->GetName().isEmpty() )
624 aFile
.Append( pLineEndList
->GetName() );
626 if( aFile
.getExtension().isEmpty() )
627 aFile
.SetExtension( "soe" );
630 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
631 if ( aDlg
.Execute() == ERRCODE_NONE
)
633 INetURLObject
aURL( aDlg
.GetPath() );
634 INetURLObject
aPathURL( aURL
);
636 aPathURL
.removeSegment();
637 aPathURL
.removeFinalSlash();
639 pLineEndList
->SetName( aURL
.getName() );
640 pLineEndList
->SetPath( aPathURL
.GetMainURL( INetURLObject::NO_DECODE
) );
642 if( pLineEndList
->Save() )
644 *pnLineEndListState
|= CT_SAVED
;
645 *pnLineEndListState
&= ~CT_MODIFIED
;
649 MessageDialog( GetParentDialog()
651 ,"cui/ui/querynosavefiledialog.ui").Execute();
657 void SvxLineEndDefTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
659 SfxTabPage::DataChanged( rDCEvt
);
661 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
663 sal_Int32 nOldSelect
= m_pLbLineEnds
->GetSelectEntryPos();
664 m_pLbLineEnds
->Clear();
665 m_pLbLineEnds
->Fill( pLineEndList
);
666 m_pLbLineEnds
->SelectEntryPos( nOldSelect
);
670 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */