LibreOffice Module extensions (master) 1
browserline.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#include "browserline.hxx"
21
22#include <com/sun/star/uno/XComponentContext.hpp>
23#include <com/sun/star/inspection/PropertyLineElement.hpp>
24#include <com/sun/star/graphic/GraphicProvider.hpp>
25#include <com/sun/star/graphic/XGraphicProvider.hpp>
26
29#include <comphelper/string.hxx>
30#include <tools/debug.hxx>
32#include <utility>
33#include <vcl/settings.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/weld.hxx>
36#include <vcl/weldutils.hxx>
37
38namespace pcr
39{
40
41
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::XComponentContext;
44 using ::com::sun::star::inspection::XPropertyControl;
45 using ::com::sun::star::inspection::XPropertyControlContext;
46 using ::com::sun::star::uno::Exception;
47 using ::com::sun::star::graphic::GraphicProvider;
48 using ::com::sun::star::graphic::XGraphicProvider;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::graphic::XGraphic;
51
52 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
53
54 OBrowserLine::OBrowserLine(OUString aEntryName, weld::Container* pParent, weld::SizeGroup* pLabelGroup,
55 weld::Container* pInitialControlParent)
56 : m_sEntryName(std::move(aEntryName))
57 , m_xBuilder(Application::CreateBuilder(pParent, "modules/spropctrlr/ui/browserline.ui"))
58 , m_xContainer(m_xBuilder->weld_container("BrowserLine"))
59 , m_xFtTitle(m_xBuilder->weld_label("label"))
60 , m_xBrowseButton(m_xBuilder->weld_button("browse"))
61 , m_xAdditionalBrowseButton(m_xBuilder->weld_button("morebrowse"))
62 , m_pInitialControlParent(pInitialControlParent) // controls start with this as their parent and need to be moved into m_xContainer
63 , m_pParent(pParent)
64 , m_pControlWindow( nullptr )
65 , m_pBrowseButton(nullptr)
66 , m_pAdditionalBrowseButton( nullptr )
67 , m_pClickListener( nullptr )
68 , m_nNameWidth(0)
69 , m_nEnableFlags( 0xFFFF )
70 , m_bIndentTitle( false )
71 , m_bReadOnly( false )
72 {
73 pLabelGroup->add_widget(m_xFtTitle.get());
74 }
75
77 {
80 m_pParent->move(m_xContainer.get(), nullptr);
81 }
82
83 void OBrowserLine::IndentTitle( bool _bIndent )
84 {
85 if ( m_bIndentTitle != _bIndent )
86 {
87 m_bIndentTitle = _bIndent;
88 }
89 }
90
91 void OBrowserLine::SetComponentHelpIds(const OUString& rHelpId)
92 {
95
96 if ( m_pBrowseButton )
97 {
99
101 {
103 }
104 }
105 }
106
107 void OBrowserLine::setControl( const Reference< XPropertyControl >& rxControl )
108 {
109 m_xControl = rxControl;
110 auto xWindow = m_xControl->getControlWindow();
111 if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xWindow.get()))
112 m_pControlWindow = pTunnel->getWidget();
113 else
114 m_pControlWindow = nullptr;
115 DBG_ASSERT( m_pControlWindow, "OBrowserLine::setControl: setting NULL controls/windows is not allowed!" );
116
117 if ( m_pControlWindow )
118 {
121 m_xFtTitle->set_mnemonic_widget(m_pControlWindow);
123 }
124 }
125
127 {
128 bool bRes=false;
129
131 {
133 bRes = true;
134 }
136 {
138 bRes = true;
139 }
141 {
143 bRes = true;
144 }
145 return bRes;
146 }
147
148 void OBrowserLine::Show(bool bFlag)
149 {
150 m_xFtTitle->set_visible(bFlag);
153 if ( m_pBrowseButton )
157 }
158
160 {
161 Show(false);
162 }
163
164 void OBrowserLine::SetTitle(const OUString& rNewTitle )
165 {
166 if ( GetTitle() == rNewTitle )
167 return;
168 m_xFtTitle->set_label( rNewTitle );
171 if ( m_pBrowseButton )
174 }
175
177 {
178 OUStringBuffer aText(m_xFtTitle->get_label());
179
180 int n10DotsWidth = m_xFtTitle->get_pixel_size("..........").Width();
181 int nTextWidth = m_xFtTitle->get_pixel_size(OUString::unacquired(aText)).Width();
182 int nDiff = m_nNameWidth - nTextWidth;
183 int nExtraChars = (nDiff * 10) / n10DotsWidth;
184 for (int i = 0; i < nExtraChars; ++i)
185 aText.append(".");
186
187 // for Issue 69452
189 {
190 sal_Unicode const cRTL_mark = 0x200F;
191 aText.append( cRTL_mark );
192 }
193
194 m_xFtTitle->set_label(aText.makeStringAndClear());
195 }
196
197 OUString OBrowserLine::GetTitle() const
198 {
199 OUString sDisplayName = m_xFtTitle->get_label();
200
201 // for Issue 69452
203 {
204 sal_Unicode const cRTL_mark = 0x200F;
206 }
207
209
210 return sDisplayName;
211 }
212
213 void OBrowserLine::SetReadOnly( bool _bReadOnly )
214 {
215 if ( m_bReadOnly != _bReadOnly )
216 {
217 m_bReadOnly = _bReadOnly;
219 }
220 }
221
222 namespace
223 {
224 void implSetBitIfAffected(sal_uInt16& nEnabledBits, sal_Int16 _nAffectedMask, sal_Int16 _nTestBit, bool _bSet)
225 {
226 if ( _nAffectedMask & _nTestBit )
227 {
228 if ( _bSet )
229 nEnabledBits |= _nTestBit;
230 else
231 nEnabledBits &= ~_nTestBit;
232 }
233 }
234
235 void implEnable(weld::Widget* pWindow, bool bEnable)
236 {
237 // tdf#138131 get_sensitive comparison as bodge for
238 // vcl's recursive Enable behavior
239 if (pWindow && pWindow->get_sensitive() != bEnable)
240 pWindow->set_sensitive(bEnable);
241 }
242
243 void implEnable(weld::Widget* pWindow, sal_uInt16 nEnabledBits, sal_uInt16 nMatchBits)
244 {
245 bool bEnable = ((nEnabledBits & nMatchBits) == nMatchBits);
246 implEnable(pWindow, bEnable);
247 }
248 }
249
251 {
253 if ( m_pControlWindow )
254 implEnable( m_pControlWindow, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::InputControl );
255
256 if ( m_bReadOnly )
257 {
258 implEnable( m_pBrowseButton, false );
259 implEnable( m_pAdditionalBrowseButton, false );
260 }
261 else
262 {
263 implEnable( m_pBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::PrimaryButton );
264 implEnable( m_pAdditionalBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::SecondaryButton );
265 }
266 }
267
269 {
272 }
273
274
275 void OBrowserLine::EnablePropertyControls( sal_Int16 _nControls, bool _bEnable )
276 {
277 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::InputControl, _bEnable );
278 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::PrimaryButton, _bEnable );
279 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::SecondaryButton, _bEnable );
281 }
282
284 {
285 weld::Button* pButton;
286 if (bPrimary)
287 pButton = m_pBrowseButton;
288 else
290
291 if (!pButton )
292 {
293 if (bPrimary)
294 pButton = m_pBrowseButton = m_xBrowseButton.get();
295 else
297 pButton->connect_focus_in(LINK(this, OBrowserLine, OnButtonFocus));
298 pButton->connect_clicked(LINK(this, OBrowserLine, OnButtonClicked));
299 }
300
301 pButton->show();
302
303 return *pButton;
304 }
305
306 void OBrowserLine::ShowBrowseButton( const OUString& rImageURL, bool bPrimary )
307 {
308 weld::Button& rButton( impl_ensureButton( bPrimary ) );
309
310 OSL_PRECOND( !rImageURL.isEmpty(), "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!" );
311 Reference<XGraphic> xGraphic;
312 try
313 {
314 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
315 Reference< XGraphicProvider > xGraphicProvider( GraphicProvider::create(xContext) );
316
317 Sequence aMediaProperties{ comphelper::makePropertyValue("URL", rImageURL) };
318
319 xGraphic = Reference<XGraphic>(xGraphicProvider->queryGraphic(aMediaProperties), css::uno::UNO_SET_THROW);
320 }
321 catch( const Exception& )
322 {
323 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
324 }
325
326 rButton.set_image(xGraphic);
327 }
328
329 void OBrowserLine::ShowBrowseButton(const css::uno::Reference<css::graphic::XGraphic>& rGraphic, bool bPrimary)
330 {
331 weld::Button& rButton( impl_ensureButton( bPrimary ) );
332 rButton.set_image(rGraphic);
333 }
334
335 void OBrowserLine::ShowBrowseButton( bool bPrimary )
336 {
337 impl_ensureButton(bPrimary);
338 }
339
341 {
342 if (bPrimary)
343 {
344 if (m_pBrowseButton)
345 {
348 m_pBrowseButton = nullptr;
349 }
350 }
351 else
352 {
354 {
358 }
359 }
360 }
361
363 {
364 implHideBrowseButton(bPrimary);
365 }
366
367 void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth)
368 {
369 int nMinDotsWidth = m_xFtTitle->get_pixel_size("...").Width();
370 if (m_nNameWidth != nWidth + nMinDotsWidth)
371 m_nNameWidth = nWidth + nMinDotsWidth;
373 }
374
376 {
377 m_pClickListener = _pListener;
378 }
379
380 IMPL_LINK(OBrowserLine, OnButtonClicked, weld::Button&, rButton, void)
381 {
382 if ( m_pClickListener )
383 m_pClickListener->buttonClicked(this, &rButton == m_pBrowseButton);
384 }
385
386 IMPL_LINK_NOARG( OBrowserLine, OnButtonFocus, weld::Widget&, void )
387 {
388 if ( m_xControl.is() )
389 {
390 try
391 {
392 Reference< XPropertyControlContext > xContext( m_xControl->getControlContext(), css::uno::UNO_SET_THROW );
393 xContext->focusGained( m_xControl );
394 }
395 catch( const Exception& )
396 {
397 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
398 }
399 }
400 }
401
402} // namespace pcr
403
404/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool GetLayoutRTL()
sal_uInt16 m_nNameWidth
Definition: browserline.hxx:65
css::uno::Reference< css::inspection::XPropertyControl > m_xControl
Definition: browserline.hxx:58
OUString GetTitle() const
std::unique_ptr< weld::Button > m_xBrowseButton
Definition: browserline.hxx:55
OBrowserLine(OUString aEntryName, weld::Container *pParent, weld::SizeGroup *pLabelGroup, weld::Container *pInitialControlParent)
Definition: browserline.cxx:54
void setControl(const css::uno::Reference< css::inspection::XPropertyControl > &rxControl)
weld::Container * m_pInitialControlParent
Definition: browserline.hxx:59
weld::Button * m_pAdditionalBrowseButton
Definition: browserline.hxx:63
void EnablePropertyControls(sal_Int16 nControls, bool bEnable)
void implUpdateEnabledDisabled()
IButtonClickListener * m_pClickListener
Definition: browserline.hxx:64
void HideBrowseButton(bool bPrimary)
void SetTitle(const OUString &rString)
std::unique_ptr< weld::Container > m_xContainer
Definition: browserline.hxx:53
void implHideBrowseButton(bool bPrimary)
weld::Button & impl_ensureButton(bool bPrimary)
void SetClickListener(IButtonClickListener *pListener)
std::unique_ptr< weld::Button > m_xAdditionalBrowseButton
Definition: browserline.hxx:56
void IndentTitle(bool bIndent)
Definition: browserline.cxx:83
void EnablePropertyLine(bool bEnable)
void Show(bool bFlag=true)
void FullFillTitleString()
void SetTitleWidth(sal_uInt16)
void SetReadOnly(bool bReadOnly)
weld::Container * m_pParent
Definition: browserline.hxx:60
weld::Button * m_pBrowseButton
Definition: browserline.hxx:62
std::unique_ptr< weld::Label > m_xFtTitle
Definition: browserline.hxx:54
sal_uInt16 m_nEnableFlags
Definition: browserline.hxx:66
void ShowBrowseButton(const OUString &rImageURL, bool bPrimary)
void SetComponentHelpIds(const OUString &rHelpId)
Definition: browserline.cxx:91
weld::Widget * m_pControlWindow
Definition: browserline.hxx:61
void connect_clicked(const Link< Button &, void > &rLink)
virtual void set_image(VirtualDevice *pDevice)=0
virtual void move(weld::Widget *pWidget, weld::Container *pNewParent)=0
virtual void add_widget(weld::Widget *pWidget)=0
virtual void show()=0
virtual void grab_focus()=0
virtual void set_help_id(const OUString &rName)=0
virtual void hide()=0
virtual void set_accessible_name(const OUString &rName)=0
virtual void set_sensitive(bool sensitive)=0
virtual void set_grid_left_attach(int nAttach)=0
virtual void set_visible(bool visible)
virtual bool get_sensitive() const=0
virtual void connect_focus_in(const Link< Widget &, void > &rLink)
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
OUString sDisplayName
bool m_bReadOnly
@ Exception
OString stripEnd(const OString &rIn, char c)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
a property handler for any virtual string properties
Definition: browserline.cxx:39
IMPL_LINK(OBrowserLine, OnButtonClicked, weld::Button &, rButton, void)
IMPL_LINK_NOARG(OBrowserLine, OnButtonFocus, weld::Widget &, void)
Reference< XNameAccess > m_xContainer
char aEntryName[20]
sal_uInt16 sal_Unicode
Reference< XControl > m_xControl