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 .
21 #include <svx/strings.hrc>
25 #include <svx/svdobjkind.hxx>
26 #include <svx/fmtools.hxx>
29 #include <svx/svxids.hrc>
32 #include <bitmaps.hlst>
33 #include <svx/dialmgr.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <sfx2/objitem.hxx>
38 #include <svx/fmshell.hxx>
39 #include <comphelper/types.hxx>
42 using namespace ::svxform
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::form
;
45 using namespace ::com::sun::star::beans
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::container
;
49 FmNavInsertedHint::FmNavInsertedHint( FmEntryData
* pInsertedEntryData
, sal_uInt32 nRelPos
)
50 :pEntryData( pInsertedEntryData
)
57 FmNavInsertedHint::~FmNavInsertedHint()
63 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData
* pAffectedEntryData
)
64 :pEntryData( pAffectedEntryData
)
69 FmNavModelReplacedHint::~FmNavModelReplacedHint()
73 FmNavRemovedHint::FmNavRemovedHint( FmEntryData
* pRemovedEntryData
)
74 :pEntryData( pRemovedEntryData
)
79 FmNavRemovedHint::~FmNavRemovedHint()
83 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData
* pData
, OUString _aNewName
)
85 ,aNewName(std::move( _aNewName
))
90 FmNavNameChangedHint::~FmNavNameChangedHint()
94 FmNavClearedHint::FmNavClearedHint()
99 FmNavClearedHint::~FmNavClearedHint()
104 FmEntryDataList::FmEntryDataList()
109 FmEntryDataList::~FmEntryDataList()
114 void FmEntryDataList::removeNoDelete( FmEntryData
* pItem
)
116 auto it
= std::find_if(maEntryDataList
.begin(), maEntryDataList
.end(),
117 [&pItem
](const std::unique_ptr
<FmEntryData
>& rEntryData
) { return rEntryData
.get() == pItem
; });
118 if (it
!= maEntryDataList
.end())
120 // coverity[leaked_storage] - deliberately not deleted, ownership transferred
122 maEntryDataList
.erase( it
);
129 void FmEntryDataList::insert( std::unique_ptr
<FmEntryData
> pItem
, size_t Index
)
131 if ( Index
< maEntryDataList
.size() )
133 maEntryDataList
.insert( maEntryDataList
.begin() + Index
, std::move(pItem
) );
136 maEntryDataList
.push_back( std::move(pItem
) );
140 void FmEntryDataList::clear()
142 maEntryDataList
.clear();
146 FmEntryData::FmEntryData( FmEntryData
* pParentData
, const Reference
< XInterface
>& _rxIFace
)
147 :pParent( pParentData
)
149 pChildList
.reset( new FmEntryDataList() );
151 newObject( _rxIFace
);
155 FmEntryData::~FmEntryData()
161 void FmEntryData::newObject( const css::uno::Reference
< css::uno::XInterface
>& _rxIFace
)
163 // do not just copy, normalize it
164 m_xNormalizedIFace
.set( _rxIFace
, UNO_QUERY
);
165 m_xProperties
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
166 m_xChild
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
170 FmEntryData::FmEntryData( const FmEntryData
& rEntryData
)
172 pChildList
.reset( new FmEntryDataList() );
173 aText
= rEntryData
.GetText();
174 m_aNormalImage
= rEntryData
.GetNormalImage();
175 pParent
= rEntryData
.GetParent();
177 FmEntryData
* pChildData
;
178 size_t nEntryCount
= rEntryData
.GetChildList()->size();
179 for( size_t i
= 0; i
< nEntryCount
; i
++ )
181 pChildData
= rEntryData
.GetChildList()->at( i
);
182 std::unique_ptr
<FmEntryData
> pNewChildData
= pChildData
->Clone();
183 pChildList
->insert( std::move(pNewChildData
), size_t(-1) );
186 m_xNormalizedIFace
= rEntryData
.m_xNormalizedIFace
;
187 m_xProperties
= rEntryData
.m_xProperties
;
188 m_xChild
= rEntryData
.m_xChild
;
193 bool FmEntryData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
195 if(this == pEntryData
)
201 if( aText
!= pEntryData
->GetText() )
204 if( !pEntryData
->GetParent() && pParent
)
207 if( pEntryData
->GetParent() && !pParent
)
210 if( !pEntryData
->GetParent() && !pParent
)
213 if( !pParent
->IsEqualWithoutChildren(pEntryData
->GetParent()) )
219 FmFormData::FmFormData(const Reference
< XForm
>& _rxForm
, FmFormData
* _pParent
)
220 : FmEntryData(_pParent
, _rxForm
)
224 m_aNormalImage
= RID_SVXBMP_FORM
;
229 Reference
< XPropertySet
> xSet(m_xForm
, UNO_QUERY
);
232 OUString
aEntryName(::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
237 SetText( OUString() );
240 FmFormData::~FmFormData()
244 FmFormData::FmFormData( const FmFormData
& rFormData
)
245 :FmEntryData( rFormData
)
247 m_xForm
= rFormData
.GetFormIface();
251 std::unique_ptr
<FmEntryData
> FmFormData::Clone()
253 return std::unique_ptr
<FmEntryData
>(new FmFormData( *this ));
257 bool FmFormData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
259 if(this == pEntryData
)
261 FmFormData
* pFormData
= dynamic_cast<FmFormData
*>(pEntryData
);
264 if( m_xForm
.get() != pFormData
->GetFormIface().get() )
267 return FmEntryData::IsEqualWithoutChildren( pFormData
);
270 FmControlData::FmControlData(const Reference
< XFormComponent
>& _rxComponent
, FmFormData
* _pParent
)
271 : FmEntryData( _pParent
, _rxComponent
),
272 m_xFormComponent( _rxComponent
)
276 m_aNormalImage
= GetImage();
280 Reference
< XPropertySet
> xSet(m_xFormComponent
, UNO_QUERY
);
283 SetText( ::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
288 FmControlData::~FmControlData()
293 FmControlData::FmControlData( const FmControlData
& rControlData
)
294 :FmEntryData( rControlData
)
296 m_xFormComponent
= rControlData
.GetFormComponent();
300 std::unique_ptr
<FmEntryData
> FmControlData::Clone()
302 return std::unique_ptr
<FmEntryData
>(new FmControlData( *this ));
306 OUString
FmControlData::GetImage() const
309 OUString
aImage(RID_SVXBMP_CONTROL
);
311 Reference
< XServiceInfo
> xInfo( m_xFormComponent
, UNO_QUERY
);
312 if (!m_xFormComponent
.is())
316 // Spezielle Control-Images
317 SdrObjKind nObjectType
= getControlTypeByObject(xInfo
);
320 case SdrObjKind::FormButton
:
321 aImage
= RID_SVXBMP_BUTTON
;
324 case SdrObjKind::FormFixedText
:
325 aImage
= RID_SVXBMP_FIXEDTEXT
;
328 case SdrObjKind::FormEdit
:
329 aImage
= RID_SVXBMP_EDITBOX
;
332 case SdrObjKind::FormRadioButton
:
333 aImage
= RID_SVXBMP_RADIOBUTTON
;
336 case SdrObjKind::FormCheckbox
:
337 aImage
= RID_SVXBMP_CHECKBOX
;
340 case SdrObjKind::FormListbox
:
341 aImage
= RID_SVXBMP_LISTBOX
;
344 case SdrObjKind::FormCombobox
:
345 aImage
= RID_SVXBMP_COMBOBOX
;
348 case SdrObjKind::FormNavigationBar
:
349 aImage
= RID_SVXBMP_NAVIGATIONBAR
;
352 case SdrObjKind::FormGroupBox
:
353 aImage
= RID_SVXBMP_GROUPBOX
;
356 case SdrObjKind::FormImageButton
:
357 aImage
= RID_SVXBMP_IMAGEBUTTON
;
360 case SdrObjKind::FormFileControl
:
361 aImage
= RID_SVXBMP_FILECONTROL
;
364 case SdrObjKind::FormHidden
:
365 aImage
= RID_SVXBMP_HIDDEN
;
368 case SdrObjKind::FormDateField
:
369 aImage
= RID_SVXBMP_DATEFIELD
;
372 case SdrObjKind::FormTimeField
:
373 aImage
= RID_SVXBMP_TIMEFIELD
;
376 case SdrObjKind::FormNumericField
:
377 aImage
= RID_SVXBMP_NUMERICFIELD
;
380 case SdrObjKind::FormCurrencyField
:
381 aImage
= RID_SVXBMP_CURRENCYFIELD
;
384 case SdrObjKind::FormPatternField
:
385 aImage
= RID_SVXBMP_PATTERNFIELD
;
388 case SdrObjKind::FormImageControl
:
389 aImage
= RID_SVXBMP_IMAGECONTROL
;
392 case SdrObjKind::FormFormattedField
:
393 aImage
= RID_SVXBMP_FORMATTEDFIELD
;
396 case SdrObjKind::FormGrid
:
397 aImage
= RID_SVXBMP_GRID
;
400 case SdrObjKind::FormScrollbar
:
401 aImage
= RID_SVXBMP_SCROLLBAR
;
404 case SdrObjKind::FormSpinButton
:
405 aImage
= RID_SVXBMP_SPINBUTTON
;
414 bool FmControlData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
416 if(this == pEntryData
)
419 FmControlData
* pControlData
= dynamic_cast<FmControlData
*>(pEntryData
);
423 if( m_xFormComponent
.get() != pControlData
->GetFormComponent().get() )
426 return FmEntryData::IsEqualWithoutChildren( pControlData
);
429 void FmControlData::ModelReplaced(const Reference
< XFormComponent
>& _rxNew
)
431 m_xFormComponent
= _rxNew
;
432 newObject( m_xFormComponent
);
434 m_aNormalImage
= GetImage();
440 NavigatorFrame::NavigatorFrame( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
,
441 vcl::Window
* _pParent
)
442 : SfxDockingWindow(_pBindings
, _pMgr
, _pParent
, "FormNavigator", "svx/ui/formnavigator.ui")
443 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL
, *_pBindings
)
444 , m_xNavigatorTree(new NavigatorTree(m_xBuilder
->weld_tree_view("treeview")))
446 SetHelpId( HID_FORM_NAVIGATOR_WIN
);
448 SetText( SvxResId(RID_STR_FMEXPLORER
) );
449 SfxDockingWindow::SetFloatingSize( Size(200,200) );
452 NavigatorFrame::~NavigatorFrame()
457 void NavigatorFrame::dispose()
459 m_xNavigatorTree
.reset();
460 ::SfxControllerItem::dispose();
461 SfxDockingWindow::dispose();
464 void NavigatorFrame::UpdateContent( FmFormShell
* pFormShell
)
466 m_xNavigatorTree
->UpdateContent(pFormShell
);
469 void NavigatorFrame::StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
471 if( !pState
|| SID_FM_FMEXPLORER_CONTROL
!= nSID
)
474 if( eState
>= SfxItemState::DEFAULT
)
476 FmFormShell
* pShell
= dynamic_cast<FmFormShell
*>( static_cast<const SfxObjectItem
*>(pState
)->GetShell() );
477 UpdateContent( pShell
);
480 UpdateContent( nullptr );
483 void NavigatorFrame::GetFocus()
485 if (m_xNavigatorTree
)
486 m_xNavigatorTree
->GrabFocus();
488 SfxDockingWindow::GetFocus();
491 bool NavigatorFrame::Close()
493 UpdateContent( nullptr );
494 return SfxDockingWindow::Close();
497 void NavigatorFrame::FillInfo( SfxChildWinInfo
& rInfo
) const
499 SfxDockingWindow::FillInfo( rInfo
);
500 rInfo
.bVisible
= false;
503 Size
NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign
)
505 if ( ( eAlign
== SfxChildAlignment::TOP
) || ( eAlign
== SfxChildAlignment::BOTTOM
) )
508 return SfxDockingWindow::CalcDockingSize( eAlign
);
511 SfxChildAlignment
NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign
, SfxChildAlignment _eAlign
)
513 if ( ( _eAlign
== SfxChildAlignment::LEFT
) || ( _eAlign
== SfxChildAlignment::RIGHT
) || ( _eAlign
== SfxChildAlignment::NOALIGNMENT
) )
518 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager
, SID_FM_SHOW_FMEXPLORER
)
520 NavigatorFrameManager::NavigatorFrameManager( vcl::Window
* _pParent
, sal_uInt16 _nId
,
521 SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
)
522 :SfxChildWindow( _pParent
, _nId
)
524 SetWindow( VclPtr
<NavigatorFrame
>::Create( _pBindings
, this, _pParent
) );
525 static_cast<SfxDockingWindow
*>(GetWindow())->Initialize( _pInfo
);
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */