LibreOffice Module svx (master)  1
fmexpl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include <svx/strings.hrc>
22 #include <fmexpl.hxx>
23 
24 #include <helpids.h>
25 #include <svx/svdobjkind.hxx>
26 #include <svx/fmtools.hxx>
27 #include <fmexch.hxx>
28 
29 #include <svx/svxids.hrc>
30 
31 #include <fmprop.hxx>
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>
37 
38 #include <svx/fmshell.hxx>
39 #include <comphelper/types.hxx>
40 
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;
47 
48 FmNavInsertedHint::FmNavInsertedHint( FmEntryData* pInsertedEntryData, sal_uInt32 nRelPos )
49  :pEntryData( pInsertedEntryData )
50  ,nPos( nRelPos )
51 
52 {
53 }
54 
55 
57 {
58 }
59 
60 
61 
63  :pEntryData( pAffectedEntryData )
64 {
65 }
66 
67 
69 {
70 }
71 
73  :pEntryData( pRemovedEntryData )
74 {
75 }
76 
77 
79 {
80 }
81 
82 FmNavNameChangedHint::FmNavNameChangedHint( FmEntryData* pData, const OUString& rNewName )
83  :pEntryData( pData )
84  ,aNewName( rNewName )
85 {
86 }
87 
88 
90 {
91 }
92 
94 {
95 }
96 
97 
99 {
100 }
101 
102 
104 {
105 }
106 
107 
109 {
110 }
111 
112 
114 {
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())
118  {
119  it->release();
120  maEntryDataList.erase( it );
121  return;
122  }
123  assert(false);
124 }
125 
126 
127 void FmEntryDataList::insert( std::unique_ptr<FmEntryData> pItem, size_t Index )
128 {
129  if ( Index < maEntryDataList.size() )
130  {
131  maEntryDataList.insert( maEntryDataList.begin() + Index, std::move(pItem) );
132  }
133  else
134  maEntryDataList.push_back( std::move(pItem) );
135 }
136 
137 
139 {
140  maEntryDataList.clear();
141 }
142 
143 
144 FmEntryData::FmEntryData( FmEntryData* pParentData, const Reference< XInterface >& _rxIFace )
145  :pParent( pParentData )
146 {
147  pChildList.reset( new FmEntryDataList() );
148 
149  newObject( _rxIFace );
150 }
151 
152 
154 {
155  pChildList->clear();
156 }
157 
158 
159 void FmEntryData::newObject( const css::uno::Reference< css::uno::XInterface >& _rxIFace )
160 {
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);
165 }
166 
167 
169 {
170  pChildList.reset( new FmEntryDataList() );
171  aText = rEntryData.GetText();
172  m_aNormalImage = rEntryData.GetNormalImage();
173  pParent = rEntryData.GetParent();
174 
175  FmEntryData* pChildData;
176  size_t nEntryCount = rEntryData.GetChildList()->size();
177  for( size_t i = 0; i < nEntryCount; i++ )
178  {
179  pChildData = rEntryData.GetChildList()->at( i );
180  std::unique_ptr<FmEntryData> pNewChildData = pChildData->Clone();
181  pChildList->insert( std::move(pNewChildData), size_t(-1) );
182  }
183 
185  m_xProperties = rEntryData.m_xProperties;
186  m_xChild = rEntryData.m_xChild;
187 }
188 
189 
190 
192 {
193  if(this == pEntryData)
194  return true;
195 
196  if( !pEntryData )
197  return false;
198 
199  if( aText != pEntryData->GetText() )
200  return false;
201 
202  if( !pEntryData->GetParent() && pParent )
203  return false;
204 
205  if( pEntryData->GetParent() && !pParent )
206  return false;
207 
208  if( !pEntryData->GetParent() && !pParent )
209  return true;
210 
211  if( !pParent->IsEqualWithoutChildren(pEntryData->GetParent()) )
212  return false;
213 
214  return true;
215 }
216 
217 FmFormData::FmFormData(const Reference< XForm >& _rxForm, FmFormData* _pParent)
218  : FmEntryData(_pParent, _rxForm)
219  , m_xForm(_rxForm)
220 {
221  // set images
222  m_aNormalImage = RID_SVXBMP_FORM;
223 
224  // set title
225  if (m_xForm.is())
226  {
227  Reference< XPropertySet > xSet(m_xForm, UNO_QUERY);
228  if (xSet.is())
229  {
230  OUString aEntryName(::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
231  SetText(aEntryName);
232  }
233  }
234  else
235  SetText( OUString() );
236 }
237 
239 {
240 }
241 
243  :FmEntryData( rFormData )
244 {
245  m_xForm = rFormData.GetFormIface();
246 }
247 
248 
249 std::unique_ptr<FmEntryData> FmFormData::Clone()
250 {
251  return std::unique_ptr<FmEntryData>(new FmFormData( *this ));
252 }
253 
254 
256 {
257  if(this == pEntryData)
258  return true;
259  FmFormData* pFormData = dynamic_cast<FmFormData*>(pEntryData);
260  if( !pFormData )
261  return false;
262  if( m_xForm.get() != pFormData->GetFormIface().get() )
263  return false;
264 
265  return FmEntryData::IsEqualWithoutChildren( pFormData );
266 }
267 
268 FmControlData::FmControlData(const Reference< XFormComponent >& _rxComponent, FmFormData* _pParent)
269 : FmEntryData( _pParent, _rxComponent ),
270  m_xFormComponent( _rxComponent )
271 {
272 
273  // set images
274  m_aNormalImage = GetImage();
275 
276 
277  // set title
278  Reference< XPropertySet > xSet(m_xFormComponent, UNO_QUERY);
279  if( xSet.is() )
280  {
281  SetText( ::comphelper::getString(xSet->getPropertyValue( FM_PROP_NAME )));
282  }
283 }
284 
285 
287 {
288 }
289 
290 
292  :FmEntryData( rControlData )
293 {
294  m_xFormComponent = rControlData.GetFormComponent();
295 }
296 
297 
298 std::unique_ptr<FmEntryData> FmControlData::Clone()
299 {
300  return std::unique_ptr<FmEntryData>(new FmControlData( *this ));
301 }
302 
303 
304 OUString FmControlData::GetImage() const
305 {
306  // Default-Image
307  OUString aImage(RID_SVXBMP_CONTROL);
308 
309  Reference< XServiceInfo > xInfo( m_xFormComponent, UNO_QUERY );
310  if (!m_xFormComponent.is())
311  return aImage;
312 
313 
314  // Spezielle Control-Images
315  SdrObjKind nObjectType = getControlTypeByObject(xInfo);
316  switch (nObjectType)
317  {
319  aImage = RID_SVXBMP_BUTTON;
320  break;
321 
323  aImage = RID_SVXBMP_FIXEDTEXT;
324  break;
325 
327  aImage = RID_SVXBMP_EDITBOX;
328  break;
329 
331  aImage = RID_SVXBMP_RADIOBUTTON;
332  break;
333 
335  aImage = RID_SVXBMP_CHECKBOX;
336  break;
337 
339  aImage = RID_SVXBMP_LISTBOX;
340  break;
341 
343  aImage = RID_SVXBMP_COMBOBOX;
344  break;
345 
347  aImage = RID_SVXBMP_NAVIGATIONBAR;
348  break;
349 
351  aImage = RID_SVXBMP_GROUPBOX;
352  break;
353 
355  aImage = RID_SVXBMP_IMAGEBUTTON;
356  break;
357 
359  aImage = RID_SVXBMP_FILECONTROL;
360  break;
361 
363  aImage = RID_SVXBMP_HIDDEN;
364  break;
365 
367  aImage = RID_SVXBMP_DATEFIELD;
368  break;
369 
371  aImage = RID_SVXBMP_TIMEFIELD;
372  break;
373 
375  aImage = RID_SVXBMP_NUMERICFIELD;
376  break;
377 
379  aImage = RID_SVXBMP_CURRENCYFIELD;
380  break;
381 
383  aImage = RID_SVXBMP_PATTERNFIELD;
384  break;
385 
387  aImage = RID_SVXBMP_IMAGECONTROL;
388  break;
389 
391  aImage = RID_SVXBMP_FORMATTEDFIELD;
392  break;
393 
395  aImage = RID_SVXBMP_GRID;
396  break;
397 
399  aImage = RID_SVXBMP_SCROLLBAR;
400  break;
401 
403  aImage = RID_SVXBMP_SPINBUTTON;
404  break;
405 
406  default:;
407  }
408 
409  return aImage;
410 }
411 
413 {
414  if(this == pEntryData)
415  return true;
416 
417  FmControlData* pControlData = dynamic_cast<FmControlData*>(pEntryData);
418  if( !pControlData )
419  return false;
420 
421  if( m_xFormComponent.get() != pControlData->GetFormComponent().get() )
422  return false;
423 
424  return FmEntryData::IsEqualWithoutChildren( pControlData );
425 }
426 
427 void FmControlData::ModelReplaced(const Reference< XFormComponent >& _rxNew)
428 {
429  m_xFormComponent = _rxNew;
431  // set images anew
433 }
434 
435 namespace svxform
436 {
437 
439  vcl::Window* _pParent )
440  : SfxDockingWindow(_pBindings, _pMgr, _pParent, "FormNavigator", "svx/ui/formnavigator.ui")
441  , SfxControllerItem( SID_FM_FMEXPLORER_CONTROL, *_pBindings )
442  , m_xNavigatorTree(new NavigatorTree(m_xBuilder->weld_tree_view("treeview")))
443  {
445 
446  SetText( SvxResId(RID_STR_FMEXPLORER) );
448  }
449 
451  {
452  disposeOnce();
453  }
454 
456  {
457  m_xNavigatorTree.reset();
460  }
461 
463  {
464  m_xNavigatorTree->UpdateContent(pFormShell);
465  }
466 
467  void NavigatorFrame::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
468  {
469  if( !pState || SID_FM_FMEXPLORER_CONTROL != nSID )
470  return;
471 
472  if( eState >= SfxItemState::DEFAULT )
473  {
474  FmFormShell* pShell = dynamic_cast<FmFormShell*>( static_cast<const SfxObjectItem*>(pState)->GetShell() );
475  UpdateContent( pShell );
476  }
477  else
478  UpdateContent( nullptr );
479  }
480 
482  {
483  if (m_xNavigatorTree )
484  m_xNavigatorTree->GrabFocus();
485  else
486  SfxDockingWindow::GetFocus();
487  }
488 
490  {
491  UpdateContent( nullptr );
492  return SfxDockingWindow::Close();
493  }
494 
496  {
498  rInfo.bVisible = false;
499  }
500 
502  {
503  if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
504  return Size();
505 
506  return SfxDockingWindow::CalcDockingSize( eAlign );
507  }
508 
510  {
511  if ( ( _eAlign == SfxChildAlignment::LEFT ) || ( _eAlign == SfxChildAlignment::RIGHT ) || ( _eAlign == SfxChildAlignment::NOALIGNMENT ) )
512  return _eAlign;
513  return _eActAlign;
514  }
515 
516  SFX_IMPL_DOCKINGWINDOW( NavigatorFrameManager, SID_FM_SHOW_FMEXPLORER )
517 
518  NavigatorFrameManager::NavigatorFrameManager( vcl::Window* _pParent, sal_uInt16 _nId,
519  SfxBindings* _pBindings, SfxChildWinInfo* _pInfo )
520  :SfxChildWindow( _pParent, _nId )
521  {
522  SetWindow( VclPtr<NavigatorFrame>::Create( _pBindings, this, _pParent ) );
523  static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo );
524  }
525 }
526 
527 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::form::XForm > m_xForm
Definition: fmexpl.hxx:224
void UpdateContent(FmFormShell *pFormShell)
Definition: fmexpl.cxx:462
OUString m_aNormalImage
Definition: fmexpl.hxx:134
void removeNoDelete(FmEntryData *pItem)
Definition: fmexpl.cxx:113
virtual void SetHelpId(const OString &) override
virtual ~FmControlData() override
Definition: fmexpl.cxx:286
virtual ~FmNavClearedHint() override
Definition: fmexpl.cxx:98
virtual SfxChildAlignment CheckAlignment(SfxChildAlignment, SfxChildAlignment) override
Definition: fmexpl.cxx:509
virtual void SetText(const OUString &rStr) override
FmEntryData * GetParent() const
Definition: fmexpl.hxx:156
FmNavRemovedHint(FmEntryData *pInsertedEntryData)
Definition: fmexpl.cxx:72
css::uno::Reference< css::beans::XPropertySet > m_xProperties
Definition: fmexpl.hxx:130
virtual bool IsEqualWithoutChildren(FmEntryData *pEntryData) override
Definition: fmexpl.cxx:412
virtual void GetFocus() override
Definition: fmexpl.cxx:481
virtual Size CalcDockingSize(SfxChildAlignment) override
Definition: fmexpl.cxx:501
SdrObjKind
Definition: svdobjkind.hxx:24
virtual ~FmNavModelReplacedHint() override
Definition: fmexpl.cxx:68
void insert(std::unique_ptr< FmEntryData > pItem, size_t Index)
Definition: fmexpl.cxx:127
std::unique_ptr< FmEntryDataList > pChildList
Definition: fmexpl.hxx:138
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
void SetFloatingSize(const Size &rSize)
css::uno::Reference< css::uno::XInterface > m_xNormalizedIFace
Definition: fmexpl.hxx:129
FmEntryData * at(size_t Index)
Definition: fmexpl.hxx:190
virtual bool Close() override
void SetText(const OUString &rText)
Definition: fmexpl.hxx:150
void FillInfo(SfxChildWinInfo &rInfo) const override
Definition: fmexpl.cxx:495
FmEntryData * pParent
Definition: fmexpl.hxx:139
virtual ~FmNavNameChangedHint() override
Definition: fmexpl.cxx:89
virtual bool IsEqualWithoutChildren(FmEntryData *pEntryData)
Definition: fmexpl.cxx:191
virtual ~FmNavInsertedHint() override
Definition: fmexpl.cxx:56
const OUString & GetText() const
Definition: fmexpl.hxx:155
Shell * GetShell()
int i
const css::uno::Reference< css::form::XForm > & GetFormIface() const
Definition: fmexpl.hxx:231
virtual void dispose()
virtual Size CalcDockingSize(SfxChildAlignment)
std::vector< std::unique_ptr< FmEntryData > > maEntryDataList
Definition: fmexpl.hxx:184
NavigatorFrame(SfxBindings *pBindings, SfxChildWindow *pMgr, vcl::Window *pParent)
Definition: fmexpl.cxx:438
void newObject(const css::uno::Reference< css::uno::XInterface > &_rxIFace)
Definition: fmexpl.cxx:159
OUString GetImage() const
Definition: fmexpl.cxx:304
css::uno::Reference< css::container::XChild > m_xChild
Definition: fmexpl.hxx:131
virtual std::unique_ptr< FmEntryData > Clone()=0
const css::uno::Reference< css::form::XFormComponent > & GetFormComponent() const
Definition: fmexpl.hxx:253
FmNavNameChangedHint(FmEntryData *pData, const OUString &rNewName)
Definition: fmexpl.cxx:82
void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: fmexpl.cxx:467
virtual ~FmEntryData()
Definition: fmexpl.cxx:153
void clear()
Definition: fmexpl.cxx:138
virtual bool IsEqualWithoutChildren(FmEntryData *pEntryData) override
Definition: fmexpl.cxx:255
virtual ~NavigatorFrame() override
Definition: fmexpl.cxx:450
std::unique_ptr< NavigatorTree > m_xNavigatorTree
Definition: fmexpl.hxx:520
size_t size() const
Definition: fmexpl.hxx:193
const OUString & GetNormalImage() const
Definition: fmexpl.hxx:153
virtual std::unique_ptr< FmEntryData > Clone() override
Definition: fmexpl.cxx:249
FmNavModelReplacedHint(FmEntryData *pAffectedEntryData)
Definition: fmexpl.cxx:62
FmEntryData(FmEntryData *pParentData, const css::uno::Reference< css::uno::XInterface > &_rIFace)
virtual void FillInfo(SfxChildWinInfo &) const
SfxItemState
SfxChildAlignment
FmControlData(const css::uno::Reference< css::form::XFormComponent > &_rxComponent, FmFormData *_pParent)
SdrObjKind getControlTypeByObject(const Reference< css::lang::XServiceInfo > &_rxObject)
Definition: fmtools.cxx:284
constexpr OUStringLiteral FM_PROP_NAME
Definition: fmprop.hxx:31
void ModelReplaced(const css::uno::Reference< css::form::XFormComponent > &_rxNew)
Definition: fmexpl.cxx:427
char aEntryName[20]
virtual ~FmNavRemovedHint() override
Definition: fmexpl.cxx:78
virtual bool Close() override
Definition: fmexpl.cxx:489
class FmSearchEngine - Impl class for FmSearchDialog
virtual std::unique_ptr< FmEntryData > Clone() override
Definition: fmexpl.cxx:298
FmFormData(const css::uno::Reference< css::form::XForm > &_rxForm, FmFormData *_pParent)
OUString getString(const Any &_rAny)
css::uno::Reference< css::form::XFormComponent > m_xFormComponent
Definition: fmexpl.hxx:240
virtual void dispose() override
struct _ADOIndex Index
constexpr OStringLiteral HID_FORM_NAVIGATOR_WIN
Definition: helpids.h:47
virtual void dispose() override
Definition: fmexpl.cxx:455
FmEntryDataList * GetChildList() const
Definition: fmexpl.hxx:157
sal_uInt16 nPos
FmNavInsertedHint(FmEntryData *pInsertedEntryData, sal_uInt32 nRelPos)
Definition: fmexpl.cxx:48
virtual ~FmFormData() override
Definition: fmexpl.cxx:238
OUString aText
Definition: fmexpl.hxx:135