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 :SfxHint(SfxHintId::FmNavInserted
)
51 ,pEntryData( pInsertedEntryData
)
58 FmNavInsertedHint::~FmNavInsertedHint()
64 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData
* pAffectedEntryData
)
65 :SfxHint(SfxHintId::FmNavModelReplaced
), pEntryData( pAffectedEntryData
)
70 FmNavModelReplacedHint::~FmNavModelReplacedHint()
74 FmNavRemovedHint::FmNavRemovedHint( FmEntryData
* pRemovedEntryData
)
75 :SfxHint(SfxHintId::FmNavRemoved
), pEntryData( pRemovedEntryData
)
80 FmNavRemovedHint::~FmNavRemovedHint()
84 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData
* pData
, OUString _aNewName
)
85 :SfxHint(SfxHintId::FmNavNameChanged
), pEntryData( pData
)
86 ,aNewName(std::move( _aNewName
))
91 FmNavNameChangedHint::~FmNavNameChangedHint()
95 FmNavClearedHint::FmNavClearedHint() : SfxHint(SfxHintId::FmNavCleared
)
100 FmNavClearedHint::~FmNavClearedHint()
105 FmEntryDataList::FmEntryDataList()
110 FmEntryDataList::~FmEntryDataList()
115 void FmEntryDataList::removeNoDelete( FmEntryData
* pItem
)
117 auto it
= std::find_if(maEntryDataList
.begin(), maEntryDataList
.end(),
118 [&pItem
](const std::unique_ptr
<FmEntryData
>& rEntryData
) { return rEntryData
.get() == pItem
; });
119 if (it
!= maEntryDataList
.end())
121 // coverity[leaked_storage] - deliberately not deleted, ownership transferred
123 maEntryDataList
.erase( it
);
130 void FmEntryDataList::insert( std::unique_ptr
<FmEntryData
> pItem
, size_t Index
)
132 if ( Index
< maEntryDataList
.size() )
134 maEntryDataList
.insert( maEntryDataList
.begin() + Index
, std::move(pItem
) );
137 maEntryDataList
.push_back( std::move(pItem
) );
141 void FmEntryDataList::clear()
143 maEntryDataList
.clear();
147 FmEntryData::FmEntryData( FmEntryData
* pParentData
, const Reference
< XInterface
>& _rxIFace
)
148 :pParent( pParentData
)
150 pChildList
.reset( new FmEntryDataList() );
152 newObject( _rxIFace
);
156 FmEntryData::~FmEntryData()
162 void FmEntryData::newObject( const css::uno::Reference
< css::uno::XInterface
>& _rxIFace
)
164 // do not just copy, normalize it
165 m_xNormalizedIFace
.set( _rxIFace
, UNO_QUERY
);
166 m_xProperties
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
167 m_xChild
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
174 bool FmEntryData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
176 if(this == pEntryData
)
182 if( aText
!= pEntryData
->GetText() )
185 if( !pEntryData
->GetParent() && pParent
)
188 if( pEntryData
->GetParent() && !pParent
)
191 if( !pEntryData
->GetParent() && !pParent
)
194 if( !pParent
->IsEqualWithoutChildren(pEntryData
->GetParent()) )
200 FmFormData::FmFormData(const Reference
< XForm
>& _rxForm
, FmFormData
* _pParent
)
201 : FmEntryData(_pParent
, _rxForm
)
205 m_aNormalImage
= RID_SVXBMP_FORM
;
210 Reference
< XPropertySet
> xSet(m_xForm
, UNO_QUERY
);
213 OUString
aEntryName(::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
218 SetText( OUString() );
221 FmFormData::~FmFormData()
225 bool FmFormData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
227 if(this == pEntryData
)
229 FmFormData
* pFormData
= dynamic_cast<FmFormData
*>(pEntryData
);
232 if( m_xForm
.get() != pFormData
->GetFormIface().get() )
235 return FmEntryData::IsEqualWithoutChildren( pFormData
);
238 FmControlData::FmControlData(const Reference
< XFormComponent
>& _rxComponent
, FmFormData
* _pParent
)
239 : FmEntryData( _pParent
, _rxComponent
),
240 m_xFormComponent( _rxComponent
)
244 m_aNormalImage
= GetImage();
248 Reference
< XPropertySet
> xSet(m_xFormComponent
, UNO_QUERY
);
251 SetText( ::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
256 FmControlData::~FmControlData()
261 OUString
FmControlData::GetImage() const
264 OUString
aImage(RID_SVXBMP_CONTROL
);
266 Reference
< XServiceInfo
> xInfo( m_xFormComponent
, UNO_QUERY
);
267 if (!m_xFormComponent
.is())
271 // Spezielle Control-Images
272 SdrObjKind nObjectType
= getControlTypeByObject(xInfo
);
275 case SdrObjKind::FormButton
:
276 aImage
= RID_SVXBMP_BUTTON
;
279 case SdrObjKind::FormFixedText
:
280 aImage
= RID_SVXBMP_FIXEDTEXT
;
283 case SdrObjKind::FormEdit
:
284 aImage
= RID_SVXBMP_EDITBOX
;
287 case SdrObjKind::FormRadioButton
:
288 aImage
= RID_SVXBMP_RADIOBUTTON
;
291 case SdrObjKind::FormCheckbox
:
292 aImage
= RID_SVXBMP_CHECKBOX
;
295 case SdrObjKind::FormListbox
:
296 aImage
= RID_SVXBMP_LISTBOX
;
299 case SdrObjKind::FormCombobox
:
300 aImage
= RID_SVXBMP_COMBOBOX
;
303 case SdrObjKind::FormNavigationBar
:
304 aImage
= RID_SVXBMP_NAVIGATIONBAR
;
307 case SdrObjKind::FormGroupBox
:
308 aImage
= RID_SVXBMP_GROUPBOX
;
311 case SdrObjKind::FormImageButton
:
312 aImage
= RID_SVXBMP_IMAGEBUTTON
;
315 case SdrObjKind::FormFileControl
:
316 aImage
= RID_SVXBMP_FILECONTROL
;
319 case SdrObjKind::FormHidden
:
320 aImage
= RID_SVXBMP_HIDDEN
;
323 case SdrObjKind::FormDateField
:
324 aImage
= RID_SVXBMP_DATEFIELD
;
327 case SdrObjKind::FormTimeField
:
328 aImage
= RID_SVXBMP_TIMEFIELD
;
331 case SdrObjKind::FormNumericField
:
332 aImage
= RID_SVXBMP_NUMERICFIELD
;
335 case SdrObjKind::FormCurrencyField
:
336 aImage
= RID_SVXBMP_CURRENCYFIELD
;
339 case SdrObjKind::FormPatternField
:
340 aImage
= RID_SVXBMP_PATTERNFIELD
;
343 case SdrObjKind::FormImageControl
:
344 aImage
= RID_SVXBMP_IMAGECONTROL
;
347 case SdrObjKind::FormFormattedField
:
348 aImage
= RID_SVXBMP_FORMATTEDFIELD
;
351 case SdrObjKind::FormGrid
:
352 aImage
= RID_SVXBMP_GRID
;
355 case SdrObjKind::FormScrollbar
:
356 aImage
= RID_SVXBMP_SCROLLBAR
;
359 case SdrObjKind::FormSpinButton
:
360 aImage
= RID_SVXBMP_SPINBUTTON
;
369 bool FmControlData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
371 if(this == pEntryData
)
374 FmControlData
* pControlData
= dynamic_cast<FmControlData
*>(pEntryData
);
378 if( m_xFormComponent
.get() != pControlData
->GetFormComponent().get() )
381 return FmEntryData::IsEqualWithoutChildren( pControlData
);
384 void FmControlData::ModelReplaced(const Reference
< XFormComponent
>& _rxNew
)
386 m_xFormComponent
= _rxNew
;
387 newObject( m_xFormComponent
);
389 m_aNormalImage
= GetImage();
395 NavigatorFrame::NavigatorFrame( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
,
396 vcl::Window
* _pParent
)
397 : SfxDockingWindow(_pBindings
, _pMgr
, _pParent
, u
"FormNavigator"_ustr
, u
"svx/ui/formnavigator.ui"_ustr
)
398 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL
, *_pBindings
)
399 , m_xNavigatorTree(new NavigatorTree(m_xBuilder
->weld_tree_view(u
"treeview"_ustr
)))
401 SetHelpId( HID_FORM_NAVIGATOR_WIN
);
403 SetText( SvxResId(RID_STR_FMEXPLORER
) );
404 SfxDockingWindow::SetFloatingSize( Size(200,200) );
407 NavigatorFrame::~NavigatorFrame()
412 void NavigatorFrame::dispose()
414 m_xNavigatorTree
.reset();
415 ::SfxControllerItem::dispose();
416 SfxDockingWindow::dispose();
419 void NavigatorFrame::UpdateContent( FmFormShell
* pFormShell
)
421 m_xNavigatorTree
->UpdateContent(pFormShell
);
424 void NavigatorFrame::StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
426 if( !pState
|| SID_FM_FMEXPLORER_CONTROL
!= nSID
)
429 if( eState
>= SfxItemState::DEFAULT
)
431 FmFormShell
* pShell
= dynamic_cast<FmFormShell
*>( static_cast<const SfxObjectItem
*>(pState
)->GetShell() );
432 UpdateContent( pShell
);
435 UpdateContent( nullptr );
438 void NavigatorFrame::GetFocus()
440 if (m_xNavigatorTree
)
441 m_xNavigatorTree
->GrabFocus();
443 SfxDockingWindow::GetFocus();
446 bool NavigatorFrame::Close()
448 UpdateContent( nullptr );
449 return SfxDockingWindow::Close();
452 void NavigatorFrame::FillInfo( SfxChildWinInfo
& rInfo
) const
454 SfxDockingWindow::FillInfo( rInfo
);
455 rInfo
.bVisible
= false;
458 Size
NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign
)
460 if ( ( eAlign
== SfxChildAlignment::TOP
) || ( eAlign
== SfxChildAlignment::BOTTOM
) )
463 return SfxDockingWindow::CalcDockingSize( eAlign
);
466 SfxChildAlignment
NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign
, SfxChildAlignment _eAlign
)
468 if ( ( _eAlign
== SfxChildAlignment::LEFT
) || ( _eAlign
== SfxChildAlignment::RIGHT
) || ( _eAlign
== SfxChildAlignment::NOALIGNMENT
) )
473 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager
, SID_FM_SHOW_FMEXPLORER
)
475 NavigatorFrameManager::NavigatorFrameManager( vcl::Window
* _pParent
, sal_uInt16 _nId
,
476 SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
)
477 :SfxChildWindow( _pParent
, _nId
)
479 SetWindow( VclPtr
<NavigatorFrame
>::Create( _pBindings
, this, _pParent
) );
480 static_cast<SfxDockingWindow
*>(GetWindow())->Initialize( _pInfo
);
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */