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>
41 using namespace ::svxform
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::form
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::container
;
48 FmNavInsertedHint::FmNavInsertedHint( FmEntryData
* pInsertedEntryData
, sal_uInt32 nRelPos
)
49 :pEntryData( pInsertedEntryData
)
56 FmNavInsertedHint::~FmNavInsertedHint()
62 FmNavModelReplacedHint::FmNavModelReplacedHint( FmEntryData
* pAffectedEntryData
)
63 :pEntryData( pAffectedEntryData
)
68 FmNavModelReplacedHint::~FmNavModelReplacedHint()
72 FmNavRemovedHint::FmNavRemovedHint( FmEntryData
* pRemovedEntryData
)
73 :pEntryData( pRemovedEntryData
)
78 FmNavRemovedHint::~FmNavRemovedHint()
82 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData
* pData
, const OUString
& rNewName
)
89 FmNavNameChangedHint::~FmNavNameChangedHint()
93 FmNavClearedHint::FmNavClearedHint()
98 FmNavClearedHint::~FmNavClearedHint()
103 FmEntryDataList::FmEntryDataList()
108 FmEntryDataList::~FmEntryDataList()
113 void FmEntryDataList::removeNoDelete( FmEntryData
* pItem
)
115 auto it
= std::find_if(maEntryDataList
.begin(), maEntryDataList
.end(),
116 [&pItem
](const std::unique_ptr
<FmEntryData
>& rEntryData
) { return rEntryData
.get() == pItem
; });
117 if (it
!= maEntryDataList
.end())
120 maEntryDataList
.erase( it
);
127 void FmEntryDataList::insert( std::unique_ptr
<FmEntryData
> pItem
, size_t Index
)
129 if ( Index
< maEntryDataList
.size() )
131 maEntryDataList
.insert( maEntryDataList
.begin() + Index
, std::move(pItem
) );
134 maEntryDataList
.push_back( std::move(pItem
) );
138 void FmEntryDataList::clear()
140 maEntryDataList
.clear();
144 FmEntryData::FmEntryData( FmEntryData
* pParentData
, const Reference
< XInterface
>& _rxIFace
)
145 :pParent( pParentData
)
147 pChildList
.reset( new FmEntryDataList() );
149 newObject( _rxIFace
);
153 FmEntryData::~FmEntryData()
159 void FmEntryData::newObject( const css::uno::Reference
< css::uno::XInterface
>& _rxIFace
)
161 // do not just copy, normalize it
162 m_xNormalizedIFace
.set( _rxIFace
, UNO_QUERY
);
163 m_xProperties
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
164 m_xChild
.set(m_xNormalizedIFace
, css::uno::UNO_QUERY
);
168 FmEntryData::FmEntryData( const FmEntryData
& rEntryData
)
170 pChildList
.reset( new FmEntryDataList() );
171 aText
= rEntryData
.GetText();
172 m_aNormalImage
= rEntryData
.GetNormalImage();
173 pParent
= rEntryData
.GetParent();
175 FmEntryData
* pChildData
;
176 size_t nEntryCount
= rEntryData
.GetChildList()->size();
177 for( size_t i
= 0; i
< nEntryCount
; i
++ )
179 pChildData
= rEntryData
.GetChildList()->at( i
);
180 std::unique_ptr
<FmEntryData
> pNewChildData
= pChildData
->Clone();
181 pChildList
->insert( std::move(pNewChildData
), size_t(-1) );
184 m_xNormalizedIFace
= rEntryData
.m_xNormalizedIFace
;
185 m_xProperties
= rEntryData
.m_xProperties
;
186 m_xChild
= rEntryData
.m_xChild
;
191 bool FmEntryData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
193 if(this == pEntryData
)
199 if( aText
!= pEntryData
->GetText() )
202 if( !pEntryData
->GetParent() && pParent
)
205 if( pEntryData
->GetParent() && !pParent
)
208 if( !pEntryData
->GetParent() && !pParent
)
211 if( !pParent
->IsEqualWithoutChildren(pEntryData
->GetParent()) )
217 FmFormData::FmFormData(const Reference
< XForm
>& _rxForm
, FmFormData
* _pParent
)
218 : FmEntryData(_pParent
, _rxForm
)
222 m_aNormalImage
= RID_SVXBMP_FORM
;
227 Reference
< XPropertySet
> xSet(m_xForm
, UNO_QUERY
);
230 OUString
aEntryName(::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
235 SetText( OUString() );
238 FmFormData::~FmFormData()
242 FmFormData::FmFormData( const FmFormData
& rFormData
)
243 :FmEntryData( rFormData
)
245 m_xForm
= rFormData
.GetFormIface();
249 std::unique_ptr
<FmEntryData
> FmFormData::Clone()
251 return std::unique_ptr
<FmEntryData
>(new FmFormData( *this ));
255 bool FmFormData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
257 if(this == pEntryData
)
259 FmFormData
* pFormData
= dynamic_cast<FmFormData
*>(pEntryData
);
262 if( m_xForm
.get() != pFormData
->GetFormIface().get() )
265 return FmEntryData::IsEqualWithoutChildren( pFormData
);
268 FmControlData::FmControlData(const Reference
< XFormComponent
>& _rxComponent
, FmFormData
* _pParent
)
269 : FmEntryData( _pParent
, _rxComponent
),
270 m_xFormComponent( _rxComponent
)
274 m_aNormalImage
= GetImage();
278 Reference
< XPropertySet
> xSet(m_xFormComponent
, UNO_QUERY
);
281 SetText( ::comphelper::getString(xSet
->getPropertyValue( FM_PROP_NAME
)));
286 FmControlData::~FmControlData()
291 FmControlData::FmControlData( const FmControlData
& rControlData
)
292 :FmEntryData( rControlData
)
294 m_xFormComponent
= rControlData
.GetFormComponent();
298 std::unique_ptr
<FmEntryData
> FmControlData::Clone()
300 return std::unique_ptr
<FmEntryData
>(new FmControlData( *this ));
304 OUString
FmControlData::GetImage() const
307 OUString
aImage(RID_SVXBMP_CONTROL
);
309 Reference
< XServiceInfo
> xInfo( m_xFormComponent
, UNO_QUERY
);
310 if (!m_xFormComponent
.is())
314 // Spezielle Control-Images
315 sal_Int16 nObjectType
= getControlTypeByObject(xInfo
);
319 aImage
= RID_SVXBMP_BUTTON
;
322 case OBJ_FM_FIXEDTEXT
:
323 aImage
= RID_SVXBMP_FIXEDTEXT
;
327 aImage
= RID_SVXBMP_EDITBOX
;
330 case OBJ_FM_RADIOBUTTON
:
331 aImage
= RID_SVXBMP_RADIOBUTTON
;
334 case OBJ_FM_CHECKBOX
:
335 aImage
= RID_SVXBMP_CHECKBOX
;
339 aImage
= RID_SVXBMP_LISTBOX
;
342 case OBJ_FM_COMBOBOX
:
343 aImage
= RID_SVXBMP_COMBOBOX
;
346 case OBJ_FM_NAVIGATIONBAR
:
347 aImage
= RID_SVXBMP_NAVIGATIONBAR
;
350 case OBJ_FM_GROUPBOX
:
351 aImage
= RID_SVXBMP_GROUPBOX
;
354 case OBJ_FM_IMAGEBUTTON
:
355 aImage
= RID_SVXBMP_IMAGEBUTTON
;
358 case OBJ_FM_FILECONTROL
:
359 aImage
= RID_SVXBMP_FILECONTROL
;
363 aImage
= RID_SVXBMP_HIDDEN
;
366 case OBJ_FM_DATEFIELD
:
367 aImage
= RID_SVXBMP_DATEFIELD
;
370 case OBJ_FM_TIMEFIELD
:
371 aImage
= RID_SVXBMP_TIMEFIELD
;
374 case OBJ_FM_NUMERICFIELD
:
375 aImage
= RID_SVXBMP_NUMERICFIELD
;
378 case OBJ_FM_CURRENCYFIELD
:
379 aImage
= RID_SVXBMP_CURRENCYFIELD
;
382 case OBJ_FM_PATTERNFIELD
:
383 aImage
= RID_SVXBMP_PATTERNFIELD
;
386 case OBJ_FM_IMAGECONTROL
:
387 aImage
= RID_SVXBMP_IMAGECONTROL
;
390 case OBJ_FM_FORMATTEDFIELD
:
391 aImage
= RID_SVXBMP_FORMATTEDFIELD
;
395 aImage
= RID_SVXBMP_GRID
;
398 case OBJ_FM_SCROLLBAR
:
399 aImage
= RID_SVXBMP_SCROLLBAR
;
402 case OBJ_FM_SPINBUTTON
:
403 aImage
= RID_SVXBMP_SPINBUTTON
;
410 bool FmControlData::IsEqualWithoutChildren( FmEntryData
* pEntryData
)
412 if(this == pEntryData
)
415 FmControlData
* pControlData
= dynamic_cast<FmControlData
*>(pEntryData
);
419 if( m_xFormComponent
.get() != pControlData
->GetFormComponent().get() )
422 return FmEntryData::IsEqualWithoutChildren( pControlData
);
425 void FmControlData::ModelReplaced(const Reference
< XFormComponent
>& _rxNew
)
427 m_xFormComponent
= _rxNew
;
428 newObject( m_xFormComponent
);
430 m_aNormalImage
= GetImage();
436 NavigatorFrame::NavigatorFrame( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
,
437 vcl::Window
* _pParent
)
438 : SfxDockingWindow(_pBindings
, _pMgr
, _pParent
, "FormNavigator", "svx/ui/formnavigator.ui")
439 , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL
, *_pBindings
)
440 , m_xNavigatorTree(new NavigatorTree(m_xBuilder
->weld_tree_view("treeview")))
442 SetHelpId( HID_FORM_NAVIGATOR_WIN
);
444 SetText( SvxResId(RID_STR_FMEXPLORER
) );
445 SfxDockingWindow::SetFloatingSize( Size(200,200) );
448 NavigatorFrame::~NavigatorFrame()
453 void NavigatorFrame::dispose()
455 m_xNavigatorTree
.reset();
456 ::SfxControllerItem::dispose();
457 SfxDockingWindow::dispose();
460 void NavigatorFrame::UpdateContent( FmFormShell
* pFormShell
)
462 m_xNavigatorTree
->UpdateContent(pFormShell
);
465 void NavigatorFrame::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
467 if( !pState
|| SID_FM_FMEXPLORER_CONTROL
!= nSID
)
470 if( eState
>= SfxItemState::DEFAULT
)
472 FmFormShell
* pShell
= dynamic_cast<FmFormShell
*>( static_cast<const SfxObjectItem
*>(pState
)->GetShell() );
473 UpdateContent( pShell
);
476 UpdateContent( nullptr );
479 void NavigatorFrame::GetFocus()
481 if (m_xNavigatorTree
)
482 m_xNavigatorTree
->GrabFocus();
484 SfxDockingWindow::GetFocus();
487 bool NavigatorFrame::Close()
489 UpdateContent( nullptr );
490 return SfxDockingWindow::Close();
493 void NavigatorFrame::FillInfo( SfxChildWinInfo
& rInfo
) const
495 SfxDockingWindow::FillInfo( rInfo
);
496 rInfo
.bVisible
= false;
499 Size
NavigatorFrame::CalcDockingSize( SfxChildAlignment eAlign
)
501 if ( ( eAlign
== SfxChildAlignment::TOP
) || ( eAlign
== SfxChildAlignment::BOTTOM
) )
504 return SfxDockingWindow::CalcDockingSize( eAlign
);
507 SfxChildAlignment
NavigatorFrame::CheckAlignment( SfxChildAlignment _eActAlign
, SfxChildAlignment _eAlign
)
509 if ( ( _eAlign
== SfxChildAlignment::LEFT
) || ( _eAlign
== SfxChildAlignment::RIGHT
) || ( _eAlign
== SfxChildAlignment::NOALIGNMENT
) )
514 SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager
, SID_FM_SHOW_FMEXPLORER
)
516 NavigatorFrameManager::NavigatorFrameManager( vcl::Window
* _pParent
, sal_uInt16 _nId
,
517 SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
)
518 :SfxChildWindow( _pParent
, _nId
)
520 SetWindow( VclPtr
<NavigatorFrame
>::Create( _pBindings
, this, _pParent
) );
521 static_cast<SfxDockingWindow
*>(GetWindow())->Initialize( _pInfo
);
525 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */