nss: upgrade to release 3.73
[LibreOffice.git] / basctl / source / dlged / propbrw.cxx
blob5ddf9ec154b10408225f4c806d1c9d5af1231b18
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <propbrw.hxx>
22 #include <basidesh.hxx>
23 #include <dlgedobj.hxx>
24 #include <iderid.hxx>
25 #include <baside3.hxx>
26 #include <strings.hrc>
28 #include <strings.hxx>
30 #include <com/sun/star/frame/Frame.hpp>
31 #include <com/sun/star/inspection/XObjectInspector.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <comphelper/types.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <cppuhelper/component_context.hxx>
36 #include <tools/debug.hxx>
37 #include <svx/svditer.hxx>
38 #include <svx/svdview.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <vcl/layout.hxx>
42 #include <vcl/stdtext.hxx>
43 #include <vcl/weld.hxx>
45 #include <memory>
47 namespace basctl
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::frame;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star::container;
56 using namespace ::comphelper;
59 void PropBrw::Update( const SfxViewShell* pShell )
61 Shell const* pIdeShell = dynamic_cast<Shell const*>(pShell);
62 OSL_ENSURE( pIdeShell || !pShell, "PropBrw::Update: invalid shell!" );
63 if (pIdeShell)
64 ImplUpdate(pIdeShell->GetCurrentDocument(), pIdeShell->GetCurDlgView());
65 else if (pShell)
66 ImplUpdate(nullptr, pShell->GetDrawView());
67 else
68 ImplUpdate(nullptr, nullptr);
72 namespace
75 const tools::Long STD_WIN_SIZE_X = 300;
76 const tools::Long STD_WIN_SIZE_Y = 350;
78 const tools::Long STD_MIN_SIZE_X = 250;
79 const tools::Long STD_MIN_SIZE_Y = 250;
81 const tools::Long WIN_BORDER = 2;
83 } // namespace
85 PropBrw::PropBrw (DialogWindowLayout& rLayout_):
86 DockingWindow(&rLayout_),
87 m_xContentArea(VclPtr<VclVBox>::Create(this)),
88 m_bInitialStateChange(true),
89 m_xContextDocument(SfxViewShell::Current() ? SfxViewShell::Current()->GetCurrentDocument() : Reference<XModel>()),
90 pView(nullptr)
92 Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
93 SetMinOutputSizePixel(Size(STD_MIN_SIZE_X,STD_MIN_SIZE_Y));
94 SetOutputSizePixel(aPropWinSize);
96 // turn off WB_CLIPCHILDREN otherwise the bg won't extend "under"
97 // transparent children of the widget
98 m_xContentArea->SetControlBackground(m_xContentArea->GetSettings().GetStyleSettings().GetWindowColor());
99 m_xContentArea->SetBackground(m_xContentArea->GetControlBackground());
100 m_xContentArea->SetStyle(m_xContentArea->GetStyle() & ~WB_CLIPCHILDREN);
101 m_xContentArea->Show();
105 // create a frame wrapper for myself
106 m_xMeAsFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
107 m_xMeAsFrame->initialize(VCLUnoHelper::GetInterface(m_xContentArea));
108 m_xMeAsFrame->setName( "form property browser" ); // change name!
110 catch (const Exception&)
112 OSL_FAIL("PropBrw::PropBrw: could not create/initialize my frame!");
113 m_xMeAsFrame.clear();
116 ImplReCreateController();
120 void PropBrw::ImplReCreateController()
122 OSL_PRECOND( m_xMeAsFrame.is(), "PropBrw::ImplCreateController: no frame for myself!" );
123 if ( !m_xMeAsFrame.is() )
124 return;
126 if ( m_xBrowserController.is() )
127 ImplDestroyController();
131 Reference< XComponentContext > xOwnContext = comphelper::getProcessComponentContext();
133 // a ComponentContext for the
134 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
136 ::cppu::ContextEntry_Init( "DialogParentWindow", Any(VCLUnoHelper::GetInterface(this))),
137 ::cppu::ContextEntry_Init( "ContextDocument", Any( m_xContextDocument ) )
139 Reference< XComponentContext > xInspectorContext(
140 ::cppu::createComponentContext( aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ), xOwnContext ) );
142 // create a property browser controller
143 Reference< XMultiComponentFactory > xFactory( xInspectorContext->getServiceManager(), UNO_SET_THROW );
144 static const char16_t s_sControllerServiceName[] = u"com.sun.star.awt.PropertyBrowserController";
145 m_xBrowserController.set( xFactory->createInstanceWithContext( s_sControllerServiceName, xInspectorContext ), UNO_QUERY );
146 if ( !m_xBrowserController.is() )
148 vcl::Window* pWin = GetParent();
149 ShowServiceNotAvailableError(pWin ? pWin->GetFrameWeld() : nullptr, s_sControllerServiceName, true);
151 else
153 Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
154 DBG_ASSERT(xAsXController.is(), "PropBrw::PropBrw: invalid controller object!");
155 if (!xAsXController.is())
157 ::comphelper::disposeComponent(m_xBrowserController);
158 m_xBrowserController.clear();
160 else
162 xAsXController->attachFrame( Reference<XFrame>(m_xMeAsFrame,UNO_QUERY_THROW) );
166 Point aPropWinPos( WIN_BORDER, WIN_BORDER );
167 Size aPropWinSize(STD_WIN_SIZE_X,STD_WIN_SIZE_Y);
168 aPropWinSize.AdjustWidth( -(2*WIN_BORDER) );
169 aPropWinSize.AdjustHeight( -(2*WIN_BORDER) );
171 VclContainer::setLayoutAllocation(*m_xContentArea, aPropWinPos, aPropWinSize);
172 m_xContentArea->Show();
174 catch (const Exception&)
176 OSL_FAIL("PropBrw::PropBrw: could not create/initialize the browser controller!");
179 ::comphelper::disposeComponent(m_xBrowserController);
181 catch(const Exception&)
185 m_xBrowserController.clear();
187 Resize();
190 PropBrw::~PropBrw()
192 disposeOnce();
195 void PropBrw::dispose()
197 if ( m_xBrowserController.is() )
198 ImplDestroyController();
199 m_xContentArea.disposeAndClear();
200 DockingWindow::dispose();
204 void PropBrw::ImplDestroyController()
206 implSetNewObject( Reference< XPropertySet >() );
208 if ( m_xMeAsFrame.is() )
209 m_xMeAsFrame->setComponent( nullptr, nullptr );
211 Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
212 if ( xAsXController.is() )
213 xAsXController->attachFrame( nullptr );
217 ::comphelper::disposeComponent( m_xBrowserController );
219 catch( const Exception& )
221 DBG_UNHANDLED_EXCEPTION("basctl");
224 m_xBrowserController.clear();
227 bool PropBrw::Close()
229 ImplDestroyController();
231 if( IsRollUp() )
232 RollDown();
234 return DockingWindow::Close();
237 Sequence< Reference< XInterface > >
238 PropBrw::CreateMultiSelectionSequence( const SdrMarkList& _rMarkList )
240 Sequence< Reference< XInterface > > aSeq;
241 InterfaceArray aInterfaces;
243 const size_t nMarkCount = _rMarkList.GetMarkCount();
244 for( size_t i = 0 ; i < nMarkCount ; ++i )
246 SdrObject* pCurrent = _rMarkList.GetMark(i)->GetMarkedSdrObj();
248 std::unique_ptr<SdrObjListIter> pGroupIterator;
249 if (pCurrent->IsGroupObject())
251 pGroupIterator.reset(new SdrObjListIter(pCurrent->GetSubList()));
252 pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : nullptr;
255 while (pCurrent)
257 if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pCurrent))
259 Reference< XInterface > xControlInterface(pDlgEdObj->GetUnoControlModel(), UNO_QUERY);
260 if (xControlInterface.is())
261 aInterfaces.push_back(xControlInterface);
264 // next element
265 pCurrent = pGroupIterator && pGroupIterator->IsMore() ? pGroupIterator->Next() : nullptr;
269 sal_Int32 nCount = aInterfaces.size();
270 aSeq.realloc( nCount );
271 Reference< XInterface >* pInterfaces = aSeq.getArray();
272 for( sal_Int32 i = 0 ; i < nCount ; i++ )
273 pInterfaces[i] = aInterfaces[i];
275 return aSeq;
279 void PropBrw::implSetNewObjectSequence
280 ( const Sequence< Reference< XInterface > >& _rObjectSeq )
282 Reference< inspection::XObjectInspector > xObjectInspector(m_xBrowserController, UNO_QUERY);
283 if ( xObjectInspector.is() )
285 xObjectInspector->inspect( _rObjectSeq );
287 OUString aText = IDEResId(RID_STR_BRWTITLE_PROPERTIES)
288 + IDEResId(RID_STR_BRWTITLE_MULTISELECT);
289 SetText( aText );
294 void PropBrw::implSetNewObject( const Reference< XPropertySet >& _rxObject )
296 if ( m_xBrowserController.is() )
298 m_xBrowserController->setPropertyValue( "IntrospectedObject",
299 Any( _rxObject )
302 // set the new title according to the selected object
303 SetText( GetHeadlineName( _rxObject ) );
308 OUString PropBrw::GetHeadlineName( const Reference< XPropertySet >& _rxObject )
310 OUString aName;
311 Reference< lang::XServiceInfo > xServiceInfo( _rxObject, UNO_QUERY );
313 if (xServiceInfo.is()) // single selection
315 OUString sResId;
316 aName = IDEResId(RID_STR_BRWTITLE_PROPERTIES);
318 if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
320 sResId = RID_STR_CLASS_DIALOG;
322 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
324 sResId = RID_STR_CLASS_BUTTON;
326 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
328 sResId = RID_STR_CLASS_RADIOBUTTON;
330 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
332 sResId = RID_STR_CLASS_CHECKBOX;
334 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
336 sResId = RID_STR_CLASS_LISTBOX;
338 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
340 sResId = RID_STR_CLASS_COMBOBOX;
342 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
344 sResId = RID_STR_CLASS_GROUPBOX;
346 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
348 sResId = RID_STR_CLASS_EDIT;
350 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
352 sResId = RID_STR_CLASS_FIXEDTEXT;
354 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
356 sResId = RID_STR_CLASS_IMAGECONTROL;
358 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
360 sResId = RID_STR_CLASS_PROGRESSBAR;
362 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
364 sResId = RID_STR_CLASS_SCROLLBAR;
366 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
368 sResId = RID_STR_CLASS_FIXEDLINE;
370 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
372 sResId = RID_STR_CLASS_DATEFIELD;
374 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
376 sResId = RID_STR_CLASS_TIMEFIELD;
378 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
380 sResId = RID_STR_CLASS_NUMERICFIELD;
382 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
384 sResId = RID_STR_CLASS_CURRENCYFIELD;
386 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
388 sResId = RID_STR_CLASS_FORMATTEDFIELD;
390 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
392 sResId = RID_STR_CLASS_PATTERNFIELD;
394 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
396 sResId = RID_STR_CLASS_FILECONTROL;
398 else if ( xServiceInfo->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
400 sResId = RID_STR_CLASS_TREECONTROL;
402 else if ( xServiceInfo->supportsService( "com.sun.star.awt.grid.UnoControlGridModel" ) )
404 sResId = RID_STR_CLASS_GRIDCONTROL;
406 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedHyperlinkModel" ) )
408 sResId = RID_STR_CLASS_HYPERLINKCONTROL;
410 else
412 sResId = RID_STR_CLASS_CONTROL;
415 if (!sResId.isEmpty())
417 aName += sResId;
420 else if (!_rxObject.is()) // no properties
422 aName = IDEResId(RID_STR_BRWTITLE_NO_PROPERTIES);
425 return aName;
428 void PropBrw::ImplUpdate( const Reference< XModel >& _rxContextDocument, SdrView* pNewView )
430 Reference< XModel > xContextDocument( _rxContextDocument );
432 // if we should simply "empty" ourself, assume the context document didn't change
433 if ( !pNewView )
435 OSL_ENSURE( !_rxContextDocument.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
436 xContextDocument = m_xContextDocument;
439 if ( xContextDocument != m_xContextDocument )
441 m_xContextDocument = xContextDocument;
442 ImplReCreateController();
447 if ( pView )
449 EndListening( *(pView->GetModel()) );
450 pView = nullptr;
453 if ( !pNewView )
454 return;
456 pView = pNewView;
458 // set focus on initialization
459 if ( m_bInitialStateChange )
461 m_xContentArea->GrabFocus();
462 m_bInitialStateChange = false;
465 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
466 const size_t nMarkCount = rMarkList.GetMarkCount();
468 if ( nMarkCount == 0 )
470 EndListening( *(pView->GetModel()) );
471 pView = nullptr;
472 implSetNewObject( nullptr );
473 return;
476 Reference< XPropertySet > xNewObject;
477 Sequence< Reference< XInterface > > aNewObjects;
478 if ( nMarkCount == 1 )
480 if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(rMarkList.GetMark(0)->GetMarkedSdrObj()))
482 if ( pDlgEdObj->IsGroupObject() ) // group object
483 aNewObjects = CreateMultiSelectionSequence( rMarkList );
484 else // single selection
485 xNewObject.set(pDlgEdObj->GetUnoControlModel(), css::uno::UNO_QUERY);
488 else if ( nMarkCount > 1 ) // multiple selection
490 aNewObjects = CreateMultiSelectionSequence( rMarkList );
493 if ( aNewObjects.hasElements() )
494 implSetNewObjectSequence( aNewObjects );
495 else
496 implSetNewObject( xNewObject );
498 StartListening( *(pView->GetModel()) );
500 catch ( const PropertyVetoException& ) { /* silence */ }
501 catch ( const Exception& )
503 DBG_UNHANDLED_EXCEPTION("basctl");
507 } // namespace basctl
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */