LibreOffice Module basctl (master) 1
propbrw.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 <propbrw.hxx>
22#include <basidesh.hxx>
23#include <dlgedobj.hxx>
24#include <iderid.hxx>
25#include <baside3.hxx>
26#include <strings.hrc>
27
28#include <strings.hxx>
29
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>
36#include <tools/debug.hxx>
37#include <svx/svditer.hxx>
38#include <svx/svdview.hxx>
41#include <vcl/layout.hxx>
42#include <vcl/stdtext.hxx>
43#include <vcl/weld.hxx>
44
45#include <memory>
46
47namespace basctl
48{
49
50using namespace ::com::sun::star;
51using namespace ::com::sun::star::uno;
52using namespace ::com::sun::star::lang;
53using namespace ::com::sun::star::frame;
54using namespace ::com::sun::star::beans;
55using namespace ::com::sun::star::container;
56using namespace ::comphelper;
57
58
59void PropBrw::Update( const SfxViewShell* pShell )
60{
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);
69}
70
71
72namespace
73{
74
75const tools::Long STD_WIN_SIZE_X = 300;
76const tools::Long STD_WIN_SIZE_Y = 350;
77
78const tools::Long STD_MIN_SIZE_X = 250;
79const tools::Long STD_MIN_SIZE_Y = 250;
80
81const tools::Long WIN_BORDER = 2;
82
83} // namespace
84
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)
91{
93 SetMinOutputSizePixel(Size(STD_MIN_SIZE_X,STD_MIN_SIZE_Y));
94 SetOutputSizePixel(aPropWinSize);
95
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();
102
103 try
104 {
105 // create a frame wrapper for myself
106 m_xMeAsFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
108 m_xMeAsFrame->setName( "form property browser" ); // change name!
109 }
110 catch (const Exception&)
111 {
112 OSL_FAIL("PropBrw::PropBrw: could not create/initialize my frame!");
113 m_xMeAsFrame.clear();
114 }
115
117}
118
119
121{
122 OSL_PRECOND( m_xMeAsFrame.is(), "PropBrw::ImplCreateController: no frame for myself!" );
123 if ( !m_xMeAsFrame.is() )
124 return;
125
126 if ( m_xBrowserController.is() )
128
129 try
130 {
132
133 // a ComponentContext for the
134 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
135 {
136 ::cppu::ContextEntry_Init( "DialogParentWindow", Any(VCLUnoHelper::GetInterface(this))),
137 ::cppu::ContextEntry_Init( "ContextDocument", Any( m_xContextDocument ) )
138 };
139 Reference< XComponentContext > xInspectorContext(
140 ::cppu::createComponentContext( aHandlerContextInfo, std::size( aHandlerContextInfo ), xOwnContext ) );
141
142 // create a property browser controller
143 Reference< XMultiComponentFactory > xFactory( xInspectorContext->getServiceManager(), UNO_SET_THROW );
144 static constexpr OUStringLiteral s_sControllerServiceName = u"com.sun.star.awt.PropertyBrowserController";
145 m_xBrowserController.set( xFactory->createInstanceWithContext( s_sControllerServiceName, xInspectorContext ), UNO_QUERY );
146 if ( !m_xBrowserController.is() )
147 {
148 vcl::Window* pWin = GetParent();
149 ShowServiceNotAvailableError(pWin ? pWin->GetFrameWeld() : nullptr, s_sControllerServiceName, true);
150 }
151 else
152 {
153 Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
154 DBG_ASSERT(xAsXController.is(), "PropBrw::PropBrw: invalid controller object!");
155 if (!xAsXController.is())
156 {
157 ::comphelper::disposeComponent(m_xBrowserController);
158 m_xBrowserController.clear();
159 }
160 else
161 {
162 xAsXController->attachFrame( Reference<XFrame>(m_xMeAsFrame,UNO_QUERY_THROW) );
163 }
164 }
165
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) );
170
171 VclContainer::setLayoutAllocation(*m_xContentArea, aPropWinPos, aPropWinSize);
172 m_xContentArea->Show();
173 }
174 catch (const Exception&)
175 {
176 OSL_FAIL("PropBrw::PropBrw: could not create/initialize the browser controller!");
177 try
178 {
179 ::comphelper::disposeComponent(m_xBrowserController);
180 }
181 catch(const Exception&)
182 {
183 }
184
185 m_xBrowserController.clear();
186 }
187 Resize();
188}
189
191{
192 disposeOnce();
193}
194
196{
197 if ( m_xBrowserController.is() )
201}
202
203
205{
207
208 if ( m_xMeAsFrame.is() )
209 m_xMeAsFrame->setComponent( nullptr, nullptr );
210
211 Reference< XController > xAsXController( m_xBrowserController, UNO_QUERY );
212 if ( xAsXController.is() )
213 xAsXController->attachFrame( nullptr );
214
215 try
216 {
217 ::comphelper::disposeComponent( m_xBrowserController );
218 }
219 catch( const Exception& )
220 {
221 DBG_UNHANDLED_EXCEPTION("basctl");
222 }
223
224 m_xBrowserController.clear();
225}
226
228{
230
231 return DockingWindow::Close();
232}
233
236{
238 InterfaceArray aInterfaces;
239
240 const size_t nMarkCount = _rMarkList.GetMarkCount();
241 for( size_t i = 0 ; i < nMarkCount ; ++i )
242 {
243 SdrObject* pCurrent = _rMarkList.GetMark(i)->GetMarkedSdrObj();
244
245 std::optional<SdrObjListIter> oGroupIterator;
246 if (pCurrent->IsGroupObject())
247 {
248 oGroupIterator.emplace(pCurrent->GetSubList());
249 pCurrent = oGroupIterator->IsMore() ? oGroupIterator->Next() : nullptr;
250 }
251
252 while (pCurrent)
253 {
254 if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pCurrent))
255 {
256 Reference< XInterface > xControlInterface(pDlgEdObj->GetUnoControlModel(), UNO_QUERY);
257 if (xControlInterface.is())
258 aInterfaces.push_back(xControlInterface);
259 }
260
261 // next element
262 pCurrent = oGroupIterator && oGroupIterator->IsMore() ? oGroupIterator->Next() : nullptr;
263 }
264 }
265
266 sal_Int32 nCount = aInterfaces.size();
267 aSeq.realloc( nCount );
268 Reference< XInterface >* pInterfaces = aSeq.getArray();
269 for( sal_Int32 i = 0 ; i < nCount ; i++ )
270 pInterfaces[i] = aInterfaces[i];
271
272 return aSeq;
273}
274
275
277 ( const Sequence< Reference< XInterface > >& _rObjectSeq )
278{
280 if ( xObjectInspector.is() )
281 {
282 xObjectInspector->inspect( _rObjectSeq );
283
284 OUString aText = IDEResId(RID_STR_BRWTITLE_PROPERTIES)
285 + IDEResId(RID_STR_BRWTITLE_MULTISELECT);
286 SetText( aText );
287 }
288}
289
290
292{
293 if ( m_xBrowserController.is() )
294 {
295 m_xBrowserController->setPropertyValue( "IntrospectedObject",
296 Any( _rxObject )
297 );
298
299 // set the new title according to the selected object
300 SetText( GetHeadlineName( _rxObject ) );
301 }
302}
303
304
305OUString PropBrw::GetHeadlineName( const Reference< XPropertySet >& _rxObject )
306{
307 OUString aName;
308 Reference< lang::XServiceInfo > xServiceInfo( _rxObject, UNO_QUERY );
309
310 if (xServiceInfo.is()) // single selection
311 {
312 OUString sResId;
313 aName = IDEResId(RID_STR_BRWTITLE_PROPERTIES);
314
315 if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDialogModel" ) )
316 {
317 sResId = RID_STR_CLASS_DIALOG;
318 }
319 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlButtonModel" ) )
320 {
321 sResId = RID_STR_CLASS_BUTTON;
322 }
323 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlRadioButtonModel" ) )
324 {
326 }
327 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCheckBoxModel" ) )
328 {
329 sResId = RID_STR_CLASS_CHECKBOX;
330 }
331 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlListBoxModel" ) )
332 {
333 sResId = RID_STR_CLASS_LISTBOX;
334 }
335 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlComboBoxModel" ) )
336 {
337 sResId = RID_STR_CLASS_COMBOBOX;
338 }
339 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlGroupBoxModel" ) )
340 {
341 sResId = RID_STR_CLASS_GROUPBOX;
342 }
343 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlEditModel" ) )
344 {
345 sResId = RID_STR_CLASS_EDIT;
346 }
347 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedTextModel" ) )
348 {
350 }
351 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlImageControlModel" ) )
352 {
354 }
355 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlProgressBarModel" ) )
356 {
358 }
359 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlScrollBarModel" ) )
360 {
362 }
363 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedLineModel" ) )
364 {
366 }
367 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlDateFieldModel" ) )
368 {
370 }
371 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlTimeFieldModel" ) )
372 {
374 }
375 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlNumericFieldModel" ) )
376 {
378 }
379 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlCurrencyFieldModel" ) )
380 {
382 }
383 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFormattedFieldModel" ) )
384 {
386 }
387 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlPatternFieldModel" ) )
388 {
390 }
391 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFileControlModel" ) )
392 {
394 }
395 else if ( xServiceInfo->supportsService( "com.sun.star.awt.tree.TreeControlModel" ) )
396 {
398 }
399 else if ( xServiceInfo->supportsService( "com.sun.star.awt.grid.UnoControlGridModel" ) )
400 {
402 }
403 else if ( xServiceInfo->supportsService( "com.sun.star.awt.UnoControlFixedHyperlinkModel" ) )
404 {
406 }
407 else
408 {
409 sResId = RID_STR_CLASS_CONTROL;
410 }
411
412 if (!sResId.isEmpty())
413 {
414 aName += sResId;
415 }
416 }
417 else if (!_rxObject.is()) // no properties
418 {
419 aName = IDEResId(RID_STR_BRWTITLE_NO_PROPERTIES);
420 }
421
422 return aName;
423}
424
425void PropBrw::ImplUpdate( const Reference< XModel >& _rxContextDocument, SdrView* pNewView )
426{
427 Reference< XModel > xContextDocument( _rxContextDocument );
428
429 // if we should simply "empty" ourself, assume the context document didn't change
430 if ( !pNewView )
431 {
432 OSL_ENSURE( !_rxContextDocument.is(), "PropBrw::ImplUpdate: no view, but a document?!" );
433 xContextDocument = m_xContextDocument;
434 }
435
436 if ( xContextDocument != m_xContextDocument )
437 {
438 m_xContextDocument = xContextDocument;
440 }
441
442 try
443 {
444 if ( pView )
445 {
447 pView = nullptr;
448 }
449
450 if ( !pNewView )
451 return;
452
453 pView = pNewView;
454
455 // set focus on initialization
457 {
458 m_xContentArea->GrabFocus();
459 m_bInitialStateChange = false;
460 }
461
462 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
463 const size_t nMarkCount = rMarkList.GetMarkCount();
464
465 if ( nMarkCount == 0 )
466 {
468 pView = nullptr;
469 implSetNewObject( nullptr );
470 return;
471 }
472
473 Reference< XPropertySet > xNewObject;
475 if ( nMarkCount == 1 )
476 {
477 if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(rMarkList.GetMark(0)->GetMarkedSdrObj()))
478 {
479 if ( pDlgEdObj->IsGroupObject() ) // group object
480 aNewObjects = CreateMultiSelectionSequence( rMarkList );
481 else // single selection
482 xNewObject.set(pDlgEdObj->GetUnoControlModel(), css::uno::UNO_QUERY);
483 }
484 }
485 else if ( nMarkCount > 1 ) // multiple selection
486 {
487 aNewObjects = CreateMultiSelectionSequence( rMarkList );
488 }
489
490 if ( aNewObjects.hasElements() )
491 implSetNewObjectSequence( aNewObjects );
492 else
493 implSetNewObject( xNewObject );
494
496 }
497 catch ( const PropertyVetoException& ) { /* silence */ }
498 catch ( const Exception& )
499 {
500 DBG_UNHANDLED_EXCEPTION("basctl");
501 }
502}
503
504} // namespace basctl
505
506/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMinOutputSizePixel(const Size &rSize)
void SetOutputSizePixel(const Size &rNewSize) override
virtual void SetText(const OUString &rStr) override
virtual bool Close()
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
virtual SdrObjList * GetSubList() const
bool IsGroupObject() const
SdrModel & GetModel() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
virtual SdrView * GetDrawView() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
void disposeAndClear()
virtual void dispose() override
Definition: bastypes.cxx:336
void ImplDestroyController()
Definition: propbrw.cxx:204
virtual ~PropBrw() override
Definition: propbrw.cxx:190
PropBrw(DialogWindowLayout &)
Definition: propbrw.cxx:85
static OUString GetHeadlineName(const css::uno::Reference< css::beans::XPropertySet > &_rxObject)
bool m_bInitialStateChange
Definition: propbrw.hxx:46
css::uno::Reference< css::beans::XPropertySet > m_xBrowserController
Definition: propbrw.hxx:51
static css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > CreateMultiSelectionSequence(const SdrMarkList &_rMarkList)
Definition: propbrw.cxx:235
std::vector< css::uno::Reference< css::uno::XInterface > > InterfaceArray
Definition: propbrw.hxx:58
virtual bool Close() override
Definition: propbrw.cxx:227
virtual void dispose() override
Definition: propbrw.cxx:195
void ImplReCreateController()
Definition: propbrw.cxx:120
void Update(const SfxViewShell *pShell)
Definition: propbrw.cxx:59
css::uno::Reference< css::frame::XFrame2 > m_xMeAsFrame
Definition: propbrw.hxx:49
VclPtr< vcl::Window > m_xContentArea
Definition: propbrw.hxx:45
void ImplUpdate(const css::uno::Reference< css::frame::XModel > &_rxContextDocument, SdrView *pView)
Definition: propbrw.cxx:425
void implSetNewObject(const css::uno::Reference< css::beans::XPropertySet > &_rxObject)
css::uno::Reference< css::frame::XModel > m_xContextDocument
Definition: propbrw.hxx:53
SdrView * pView
Definition: propbrw.hxx:55
void implSetNewObjectSequence(const css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > &_rObjectSeq)
Definition: propbrw.cxx:277
virtual css::uno::Reference< css::frame::XModel > GetCurrentDocument() const override
Definition: basides1.cxx:1515
SdrView * GetCurDlgView() const
Definition: basides3.cxx:133
vcl::Window * GetParent() const
virtual void Resize()
weld::Window * GetFrameWeld() const
int nCount
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
Reference< XSingleServiceFactory > xFactory
OUString aName
Sequence< sal_Int8 > aSeq
OUString IDEResId(TranslateId aId)
Definition: iderdll.cxx:108
@ Exception
Reference< XComponentContext > getProcessComponentContext()
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
void VCL_DLLPUBLIC ShowServiceNotAvailableError(weld::Widget *pParent, std::u16string_view rServiceName, bool bError)
constexpr OUStringLiteral RID_STR_CLASS_DIALOG
Definition: strings.hxx:17
constexpr OUStringLiteral RID_STR_CLASS_CHECKBOX
Definition: strings.hxx:20
constexpr OUStringLiteral RID_STR_CLASS_FILECONTROL
Definition: strings.hxx:36
constexpr OUStringLiteral RID_STR_CLASS_GROUPBOX
Definition: strings.hxx:23
constexpr OUStringLiteral RID_STR_CLASS_FIXEDTEXT
Definition: strings.hxx:25
constexpr OUStringLiteral RID_STR_CLASS_TIMEFIELD
Definition: strings.hxx:31
constexpr OUStringLiteral RID_STR_CLASS_LISTBOX
Definition: strings.hxx:21
constexpr OUStringLiteral RID_STR_CLASS_FORMATTEDFIELD
Definition: strings.hxx:34
constexpr OUStringLiteral RID_STR_CLASS_PATTERNFIELD
Definition: strings.hxx:35
constexpr OUStringLiteral RID_STR_CLASS_GRIDCONTROL
Definition: strings.hxx:38
constexpr OUStringLiteral RID_STR_CLASS_RADIOBUTTON
Definition: strings.hxx:19
constexpr OUStringLiteral RID_STR_CLASS_TREECONTROL
Definition: strings.hxx:37
constexpr OUStringLiteral RID_STR_CLASS_CURRENCYFIELD
Definition: strings.hxx:33
constexpr OUStringLiteral RID_STR_CLASS_PROGRESSBAR
Definition: strings.hxx:27
constexpr OUStringLiteral RID_STR_CLASS_BUTTON
Definition: strings.hxx:18
constexpr OUStringLiteral RID_STR_CLASS_NUMERICFIELD
Definition: strings.hxx:32
constexpr OUStringLiteral RID_STR_CLASS_DATEFIELD
Definition: strings.hxx:30
constexpr OUStringLiteral RID_STR_CLASS_SCROLLBAR
Definition: strings.hxx:28
constexpr OUStringLiteral RID_STR_CLASS_CONTROL
Definition: strings.hxx:16
constexpr OUStringLiteral RID_STR_CLASS_COMBOBOX
Definition: strings.hxx:22
constexpr OUStringLiteral RID_STR_CLASS_IMAGECONTROL
Definition: strings.hxx:26
constexpr OUStringLiteral RID_STR_CLASS_EDIT
Definition: strings.hxx:24
constexpr OUStringLiteral RID_STR_CLASS_HYPERLINKCONTROL
Definition: strings.hxx:40
constexpr OUStringLiteral RID_STR_CLASS_FIXEDLINE
Definition: strings.hxx:29
const tools::Long STD_WIN_SIZE_Y
const tools::Long STD_WIN_SIZE_X
WinBits const WB_CLIPCHILDREN