Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name eventhandler.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/extensions/inc -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx

/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx

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 "eventhandler.hxx"
22#include <helpids.h>
23#include <propctrlr.h>
24#include "formbrowsertools.hxx"
25#include <strings.hrc>
26#include "formstrings.hxx"
27#include "handlerhelper.hxx"
28#include "modulepcr.hxx"
29#include "pcrcommon.hxx"
30#include "propertycontrolextender.hxx"
31
32#include <com/sun/star/awt/XTabControllerModel.hpp>
33#include <com/sun/star/beans/PropertyAttribute.hpp>
34#include <com/sun/star/beans/UnknownPropertyException.hpp>
35#include <com/sun/star/beans/theIntrospection.hpp>
36#include <com/sun/star/beans/XIntrospectionAccess.hpp>
37#include <com/sun/star/container/NoSuchElementException.hpp>
38#include <com/sun/star/container/XChild.hpp>
39#include <com/sun/star/container/XIndexAccess.hpp>
40#include <com/sun/star/container/XNameContainer.hpp>
41#include <com/sun/star/container/XNameReplace.hpp>
42#include <com/sun/star/form/FormComponentType.hpp>
43#include <com/sun/star/form/XForm.hpp>
44#include <com/sun/star/form/runtime/FormController.hpp>
45#include <com/sun/star/inspection/PropertyControlType.hpp>
46#include <com/sun/star/lang/NullPointerException.hpp>
47#include <com/sun/star/script/XEventAttacherManager.hpp>
48#include <com/sun/star/script/XScriptEventsSupplier.hpp>
49#include <com/sun/star/uri/UriReferenceFactory.hpp>
50#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
51
52#include <comphelper/namedvaluecollection.hxx>
53#include <comphelper/evtmethodhelper.hxx>
54#include <comphelper/sequence.hxx>
55#include <comphelper/types.hxx>
56#include <cppuhelper/implbase.hxx>
57#include <cppuhelper/supportsservice.hxx>
58#include <rtl/ref.hxx>
59#include <rtl/ustrbuf.hxx>
60#include <svx/svxdlg.hxx>
61#include <tools/diagnose_ex.h>
62
63#include <map>
64#include <algorithm>
65#include <iterator>
66
67namespace pcr
68{
69
70 using ::com::sun::star::uno::Reference;
71 using ::com::sun::star::uno::XComponentContext;
72 using ::com::sun::star::uno::Any;
73 using ::com::sun::star::uno::TypeClass_STRING;
74 using ::com::sun::star::uno::Type;
75 using ::com::sun::star::beans::theIntrospection;
76 using ::com::sun::star::beans::XPropertyChangeListener;
77 using ::com::sun::star::beans::Property;
78 using ::com::sun::star::beans::PropertyState;
79 using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
80 using ::com::sun::star::uno::Sequence;
81 using ::com::sun::star::script::ScriptEventDescriptor;
82 using ::com::sun::star::script::XScriptEventsSupplier;
83 using ::com::sun::star::lang::NullPointerException;
84 using ::com::sun::star::uno::Exception;
85 using ::com::sun::star::container::XChild;
86 using ::com::sun::star::container::XIndexAccess;
87 using ::com::sun::star::script::XEventAttacherManager;
88 using ::com::sun::star::uno::UNO_QUERY;
89 using ::com::sun::star::uno::UNO_QUERY_THROW;
90 using ::com::sun::star::uno::XInterface;
91 using ::com::sun::star::beans::XIntrospection;
92 using ::com::sun::star::beans::XIntrospectionAccess;
93 using ::com::sun::star::container::XNameContainer;
94 using ::com::sun::star::awt::XTabControllerModel;
95 using ::com::sun::star::form::XForm;
96 using ::com::sun::star::form::runtime::FormController;
97 using ::com::sun::star::form::runtime::XFormController;
98 using ::com::sun::star::beans::UnknownPropertyException;
99 using ::com::sun::star::uno::makeAny;
100 using ::com::sun::star::container::NoSuchElementException;
101 using ::com::sun::star::beans::XPropertySetInfo;
102 using ::com::sun::star::container::XNameReplace;
103 using ::com::sun::star::beans::PropertyValue;
104 using ::com::sun::star::inspection::LineDescriptor;
105 using ::com::sun::star::inspection::XPropertyControlFactory;
106 using ::com::sun::star::inspection::InteractiveSelectionResult;
107 using ::com::sun::star::inspection::InteractiveSelectionResult_Cancelled;
108 using ::com::sun::star::inspection::InteractiveSelectionResult_Success;
109 using ::com::sun::star::inspection::XObjectInspectorUI;
110 using ::com::sun::star::beans::PropertyChangeEvent;
111 using ::com::sun::star::frame::XFrame;
112 using ::com::sun::star::frame::XModel;
113 using ::com::sun::star::frame::XController;
114 using ::com::sun::star::uno::UNO_SET_THROW;
115 using com::sun::star::uri::UriReferenceFactory;
116 using com::sun::star::uri::XUriReferenceFactory;
117 using com::sun::star::uri::XVndSunStarScriptUrlReference;
118 using ::com::sun::star::lang::XEventListener;
119
120 namespace PropertyControlType = css::inspection::PropertyControlType;
121 namespace PropertyAttribute = css::beans::PropertyAttribute;
122 namespace FormComponentType = css::form::FormComponentType;
123
124 EventDescription::EventDescription( EventId _nId, const char* _pListenerNamespaceAscii, const char* _pListenerClassAsciiName,
125 const char* _pListenerMethodAsciiName, const char* pDisplayNameResId, const OString& _sHelpId, const OString& _sUniqueBrowseId )
126 :sDisplayName(PcrRes( pDisplayNameResId ))
127 ,sListenerMethodName( OUString::createFromAscii( _pListenerMethodAsciiName ) )
128 ,sHelpId( _sHelpId )
129 ,sUniqueBrowseId( _sUniqueBrowseId )
130 ,nId( _nId )
131 {
132 OUStringBuffer aQualifiedListenerClass;
133 aQualifiedListenerClass.append( "com.sun.star." );
134 aQualifiedListenerClass.appendAscii( _pListenerNamespaceAscii );
135 aQualifiedListenerClass.append( "." );
136 aQualifiedListenerClass.appendAscii( _pListenerClassAsciiName );
137 sListenerClassName = aQualifiedListenerClass.makeStringAndClear();
138 }
139
140 namespace
141 {
142 #define DESCRIBE_EVENT( map, asciinamespace, asciilistener, asciimethod, id_postfix )map.emplace( asciimethod, EventDescription( ++nEventId, asciinamespace
, asciilistener, asciimethod, RID_STR_EVT_id_postfix, HID_EVT_id_postfix
, UID_BRWEVT_id_postfix ) )
\
143 map.emplace( \
144 asciimethod, \
145 EventDescription( ++nEventId, asciinamespace, asciilistener, asciimethod, RID_STR_EVT_##id_postfix, HID_EVT_##id_postfix, UID_BRWEVT_##id_postfix ) )
146
147 bool lcl_getEventDescriptionForMethod( const OUString& _rMethodName, EventDescription& _out_rDescription )
148 {
149 static EventMap s_aKnownEvents = []() {
150 EventMap aMap;
151 sal_Int32 nEventId = 0;
152
153 DESCRIBE_EVENT(aMap, "form", "XApproveActionListener", "approveAction", APPROVEACTIONPERFORMED)aMap.emplace( "approveAction", EventDescription( ++nEventId, "form"
, "XApproveActionListener", "approveAction", reinterpret_cast
<char const *>("RID_STR_EVT_APPROVEACTIONPERFORMED" "\004"
u8"Approve action"), "EXTENSIONS_HID_EVT_APPROVEACTIONPERFORMED"
, "EXTENSIONS_UID_BRWEVT_APPROVEACTIONPERFORMED" ) )
;
154 DESCRIBE_EVENT(aMap, "awt", "XActionListener", "actionPerformed", ACTIONPERFORMED)aMap.emplace( "actionPerformed", EventDescription( ++nEventId
, "awt", "XActionListener", "actionPerformed", reinterpret_cast
<char const *>("RID_STR_EVT_ACTIONPERFORMED" "\004" u8"Execute action"
), "EXTENSIONS_HID_EVT_ACTIONPERFORMED", "EXTENSIONS_UID_BRWEVT_ACTIONPERFORMED"
) )
;
155 DESCRIBE_EVENT(aMap, "form", "XChangeListener", "changed", CHANGED)aMap.emplace( "changed", EventDescription( ++nEventId, "form"
, "XChangeListener", "changed", reinterpret_cast<char const
*>("RID_STR_EVT_CHANGED" "\004" u8"Changed"), "EXTENSIONS_HID_EVT_CHANGED"
, "EXTENSIONS_UID_BRWEVT_CHANGED" ) )
;
156 DESCRIBE_EVENT(aMap, "awt", "XTextListener", "textChanged", TEXTCHANGED)aMap.emplace( "textChanged", EventDescription( ++nEventId, "awt"
, "XTextListener", "textChanged", reinterpret_cast<char const
*>("RID_STR_EVT_TEXTCHANGED" "\004" u8"Text modified"), "EXTENSIONS_HID_EVT_TEXTCHANGED"
, "EXTENSIONS_UID_BRWEVT_TEXTCHANGED" ) )
;
157 DESCRIBE_EVENT(aMap, "awt", "XItemListener", "itemStateChanged", ITEMSTATECHANGED)aMap.emplace( "itemStateChanged", EventDescription( ++nEventId
, "awt", "XItemListener", "itemStateChanged", reinterpret_cast
<char const *>("RID_STR_EVT_ITEMSTATECHANGED" "\004" u8"Item status changed"
), "EXTENSIONS_HID_EVT_ITEMSTATECHANGED", "EXTENSIONS_UID_BRWEVT_ITEMSTATECHANGED"
) )
;
158 DESCRIBE_EVENT(aMap, "awt", "XFocusListener", "focusGained", FOCUSGAINED)aMap.emplace( "focusGained", EventDescription( ++nEventId, "awt"
, "XFocusListener", "focusGained", reinterpret_cast<char const
*>("RID_STR_EVT_FOCUSGAINED" "\004" u8"When receiving focus"
), "EXTENSIONS_HID_EVT_FOCUSGAINED", "EXTENSIONS_UID_BRWEVT_FOCUSGAINED"
) )
;
159 DESCRIBE_EVENT(aMap, "awt", "XFocusListener", "focusLost", FOCUSLOST)aMap.emplace( "focusLost", EventDescription( ++nEventId, "awt"
, "XFocusListener", "focusLost", reinterpret_cast<char const
*>("RID_STR_EVT_FOCUSLOST" "\004" u8"When losing focus"),
"EXTENSIONS_HID_EVT_FOCUSLOST", "EXTENSIONS_UID_BRWEVT_FOCUSLOST"
) )
;
160 DESCRIBE_EVENT(aMap, "awt", "XKeyListener", "keyPressed", KEYTYPED)aMap.emplace( "keyPressed", EventDescription( ++nEventId, "awt"
, "XKeyListener", "keyPressed", reinterpret_cast<char const
*>("RID_STR_EVT_KEYTYPED" "\004" u8"Key pressed"), "EXTENSIONS_HID_EVT_KEYTYPED"
, "EXTENSIONS_UID_BRWEVT_KEYTYPED" ) )
;
161 DESCRIBE_EVENT(aMap, "awt", "XKeyListener", "keyReleased", KEYUP)aMap.emplace( "keyReleased", EventDescription( ++nEventId, "awt"
, "XKeyListener", "keyReleased", reinterpret_cast<char const
*>("RID_STR_EVT_KEYUP" "\004" u8"Key released"), "EXTENSIONS_HID_EVT_KEYUP"
, "EXTENSIONS_UID_BRWEVT_KEYUP" ) )
;
162 DESCRIBE_EVENT(aMap, "awt", "XMouseListener", "mouseEntered", MOUSEENTERED)aMap.emplace( "mouseEntered", EventDescription( ++nEventId, "awt"
, "XMouseListener", "mouseEntered", reinterpret_cast<char const
*>("RID_STR_EVT_MOUSEENTERED" "\004" u8"Mouse inside"), "EXTENSIONS_HID_EVT_MOUSEENTERED"
, "EXTENSIONS_UID_BRWEVT_MOUSEENTERED" ) )
;
163 DESCRIBE_EVENT(aMap, "awt", "XMouseMotionListener", "mouseDragged", MOUSEDRAGGED)aMap.emplace( "mouseDragged", EventDescription( ++nEventId, "awt"
, "XMouseMotionListener", "mouseDragged", reinterpret_cast<
char const *>("RID_STR_EVT_MOUSEDRAGGED" "\004" u8"Mouse moved while key pressed"
), "EXTENSIONS_HID_EVT_MOUSEDRAGGED", "EXTENSIONS_UID_BRWEVT_MOUSEDRAGGED"
) )
;
164 DESCRIBE_EVENT(aMap, "awt", "XMouseMotionListener", "mouseMoved", MOUSEMOVED)aMap.emplace( "mouseMoved", EventDescription( ++nEventId, "awt"
, "XMouseMotionListener", "mouseMoved", reinterpret_cast<char
const *>("RID_STR_EVT_MOUSEMOVED" "\004" u8"Mouse moved")
, "EXTENSIONS_HID_EVT_MOUSEMOVED", "EXTENSIONS_UID_BRWEVT_MOUSEMOVED"
) )
;
165 DESCRIBE_EVENT(aMap, "awt", "XMouseListener", "mousePressed", MOUSEPRESSED)aMap.emplace( "mousePressed", EventDescription( ++nEventId, "awt"
, "XMouseListener", "mousePressed", reinterpret_cast<char const
*>("RID_STR_EVT_MOUSEPRESSED" "\004" u8"Mouse button pressed"
), "EXTENSIONS_HID_EVT_MOUSEPRESSED", "EXTENSIONS_UID_BRWEVT_MOUSEPRESSED"
) )
;
166 DESCRIBE_EVENT(aMap, "awt", "XMouseListener", "mouseReleased", MOUSERELEASED)aMap.emplace( "mouseReleased", EventDescription( ++nEventId, "awt"
, "XMouseListener", "mouseReleased", reinterpret_cast<char
const *>("RID_STR_EVT_MOUSERELEASED" "\004" u8"Mouse button released"
), "EXTENSIONS_HID_EVT_MOUSERELEASED", "EXTENSIONS_UID_BRWEVT_MOUSERELEASED"
) )
;
167 DESCRIBE_EVENT(aMap, "awt", "XMouseListener", "mouseExited", MOUSEEXITED)aMap.emplace( "mouseExited", EventDescription( ++nEventId, "awt"
, "XMouseListener", "mouseExited", reinterpret_cast<char const
*>("RID_STR_EVT_MOUSEEXITED" "\004" u8"Mouse outside"), "EXTENSIONS_HID_EVT_MOUSEEXITED"
, "EXTENSIONS_UID_BRWEVT_MOUSEEXITED" ) )
;
168 DESCRIBE_EVENT(aMap, "form", "XResetListener", "approveReset", APPROVERESETTED)aMap.emplace( "approveReset", EventDescription( ++nEventId, "form"
, "XResetListener", "approveReset", reinterpret_cast<char const
*>("RID_STR_EVT_APPROVERESETTED" "\004" u8"Prior to reset"
), "EXTENSIONS_HID_EVT_APPROVERESETTED", "EXTENSIONS_UID_BRWEVT_APPROVERESETTED"
) )
;
169 DESCRIBE_EVENT(aMap, "form", "XResetListener", "resetted", RESETTED)aMap.emplace( "resetted", EventDescription( ++nEventId, "form"
, "XResetListener", "resetted", reinterpret_cast<char const
*>("RID_STR_EVT_RESETTED" "\004" u8"After resetting"), "EXTENSIONS_HID_EVT_RESETTED"
, "EXTENSIONS_UID_BRWEVT_RESETTED" ) )
;
170 DESCRIBE_EVENT(aMap, "form", "XSubmitListener", "approveSubmit", SUBMITTED)aMap.emplace( "approveSubmit", EventDescription( ++nEventId, "form"
, "XSubmitListener", "approveSubmit", reinterpret_cast<char
const *>("RID_STR_EVT_SUBMITTED" "\004" u8"Before submitting"
), "EXTENSIONS_HID_EVT_SUBMITTED", "EXTENSIONS_UID_BRWEVT_SUBMITTED"
) )
;
171 DESCRIBE_EVENT(aMap, "form", "XUpdateListener", "approveUpdate", BEFOREUPDATE)aMap.emplace( "approveUpdate", EventDescription( ++nEventId, "form"
, "XUpdateListener", "approveUpdate", reinterpret_cast<char
const *>("RID_STR_EVT_BEFOREUPDATE" "\004" u8"Before updating"
), "EXTENSIONS_HID_EVT_BEFOREUPDATE", "EXTENSIONS_UID_BRWEVT_BEFOREUPDATE"
) )
;
172 DESCRIBE_EVENT(aMap, "form", "XUpdateListener", "updated", AFTERUPDATE)aMap.emplace( "updated", EventDescription( ++nEventId, "form"
, "XUpdateListener", "updated", reinterpret_cast<char const
*>("RID_STR_EVT_AFTERUPDATE" "\004" u8"After updating"), "EXTENSIONS_HID_EVT_AFTERUPDATE"
, "EXTENSIONS_UID_BRWEVT_AFTERUPDATE" ) )
;
173 DESCRIBE_EVENT(aMap, "form", "XLoadListener", "loaded", LOADED)aMap.emplace( "loaded", EventDescription( ++nEventId, "form",
"XLoadListener", "loaded", reinterpret_cast<char const *>
("RID_STR_EVT_LOADED" "\004" u8"When loading"), "EXTENSIONS_HID_EVT_LOADED"
, "EXTENSIONS_UID_BRWEVT_LOADED" ) )
;
174 DESCRIBE_EVENT(aMap, "form", "XLoadListener", "reloading", RELOADING)aMap.emplace( "reloading", EventDescription( ++nEventId, "form"
, "XLoadListener", "reloading", reinterpret_cast<char const
*>("RID_STR_EVT_RELOADING" "\004" u8"Before reloading"), "EXTENSIONS_HID_EVT_RELOADING"
, "EXTENSIONS_UID_BRWEVT_RELOADING" ) )
;
175 DESCRIBE_EVENT(aMap, "form", "XLoadListener", "reloaded", RELOADED)aMap.emplace( "reloaded", EventDescription( ++nEventId, "form"
, "XLoadListener", "reloaded", reinterpret_cast<char const
*>("RID_STR_EVT_RELOADED" "\004" u8"When reloading"), "EXTENSIONS_HID_EVT_RELOADED"
, "EXTENSIONS_UID_BRWEVT_RELOADED" ) )
;
176 DESCRIBE_EVENT(aMap, "form", "XLoadListener", "unloading", UNLOADING)aMap.emplace( "unloading", EventDescription( ++nEventId, "form"
, "XLoadListener", "unloading", reinterpret_cast<char const
*>("RID_STR_EVT_UNLOADING" "\004" u8"Before unloading"), "EXTENSIONS_HID_EVT_UNLOADING"
, "EXTENSIONS_UID_BRWEVT_UNLOADING" ) )
;
177 DESCRIBE_EVENT(aMap, "form", "XLoadListener", "unloaded", UNLOADED)aMap.emplace( "unloaded", EventDescription( ++nEventId, "form"
, "XLoadListener", "unloaded", reinterpret_cast<char const
*>("RID_STR_EVT_UNLOADED" "\004" u8"When unloading"), "EXTENSIONS_HID_EVT_UNLOADED"
, "EXTENSIONS_UID_BRWEVT_UNLOADED" ) )
;
178 DESCRIBE_EVENT(aMap, "form", "XConfirmDeleteListener", "confirmDelete", CONFIRMDELETE)aMap.emplace( "confirmDelete", EventDescription( ++nEventId, "form"
, "XConfirmDeleteListener", "confirmDelete", reinterpret_cast
<char const *>("RID_STR_EVT_CONFIRMDELETE" "\004" u8"Confirm deletion"
), "EXTENSIONS_HID_EVT_CONFIRMDELETE", "EXTENSIONS_UID_BRWEVT_CONFIRMDELETE"
) )
;
179 DESCRIBE_EVENT(aMap, "sdb", "XRowSetApproveListener", "approveRowChange", APPROVEROWCHANGE)aMap.emplace( "approveRowChange", EventDescription( ++nEventId
, "sdb", "XRowSetApproveListener", "approveRowChange", reinterpret_cast
<char const *>("RID_STR_EVT_APPROVEROWCHANGE" "\004" u8"Before record action"
), "EXTENSIONS_HID_EVT_APPROVEROWCHANGE", "EXTENSIONS_UID_BRWEVT_APPROVEROWCHANGE"
) )
;
180 DESCRIBE_EVENT(aMap, "sdbc", "XRowSetListener", "rowChanged", ROWCHANGE)aMap.emplace( "rowChanged", EventDescription( ++nEventId, "sdbc"
, "XRowSetListener", "rowChanged", reinterpret_cast<char const
*>("RID_STR_EVT_ROWCHANGE" "\004" u8"After record action"
), "EXTENSIONS_HID_EVT_ROWCHANGE", "EXTENSIONS_UID_BRWEVT_ROWCHANGE"
) )
;
181 DESCRIBE_EVENT(aMap, "sdb", "XRowSetApproveListener", "approveCursorMove", POSITIONING)aMap.emplace( "approveCursorMove", EventDescription( ++nEventId
, "sdb", "XRowSetApproveListener", "approveCursorMove", reinterpret_cast
<char const *>("RID_STR_EVT_POSITIONING" "\004" u8"Before record change"
), "EXTENSIONS_HID_EVT_POSITIONING", "EXTENSIONS_UID_BRWEVT_POSITIONING"
) )
;
182 DESCRIBE_EVENT(aMap, "sdbc", "XRowSetListener", "cursorMoved", POSITIONED)aMap.emplace( "cursorMoved", EventDescription( ++nEventId, "sdbc"
, "XRowSetListener", "cursorMoved", reinterpret_cast<char const
*>("RID_STR_EVT_POSITIONED" "\004" u8"After record change"
), "EXTENSIONS_HID_EVT_POSITIONED", "EXTENSIONS_UID_BRWEVT_POSITIONED"
) )
;
183 DESCRIBE_EVENT(aMap, "form", "XDatabaseParameterListener", "approveParameter", APPROVEPARAMETER)aMap.emplace( "approveParameter", EventDescription( ++nEventId
, "form", "XDatabaseParameterListener", "approveParameter", reinterpret_cast
<char const *>("RID_STR_EVT_APPROVEPARAMETER" "\004" u8"Fill parameters"
), "EXTENSIONS_HID_EVT_APPROVEPARAMETER", "EXTENSIONS_UID_BRWEVT_APPROVEPARAMETER"
) )
;
184 DESCRIBE_EVENT(aMap, "sdb", "XSQLErrorListener", "errorOccured", ERROROCCURRED)aMap.emplace( "errorOccured", EventDescription( ++nEventId, "sdb"
, "XSQLErrorListener", "errorOccured", reinterpret_cast<char
const *>("RID_STR_EVT_ERROROCCURRED" "\004" u8"Error occurred"
), "EXTENSIONS_HID_EVT_ERROROCCURRED", "EXTENSIONS_UID_BRWEVT_ERROROCCURRED"
) )
;
185 DESCRIBE_EVENT(aMap, "awt", "XAdjustmentListener", "adjustmentValueChanged", ADJUSTMENTVALUECHANGED)aMap.emplace( "adjustmentValueChanged", EventDescription( ++nEventId
, "awt", "XAdjustmentListener", "adjustmentValueChanged", reinterpret_cast
<char const *>("RID_STR_EVT_ADJUSTMENTVALUECHANGED" "\004"
u8"While adjusting"), "EXTENSIONS_HID_EVT_ADJUSTMENTVALUECHANGED"
, "EXTENSIONS_UID_BRWEVT_ADJUSTMENTVALUECHANGED" ) )
;
186
187 return aMap;
188 }();
189
190 EventMap::const_iterator pos = s_aKnownEvents.find( _rMethodName );
191 if ( pos == s_aKnownEvents.end() )
192 return false;
193
194 _out_rDescription = pos->second;
195 return true;
196 }
197
198 OUString lcl_getEventPropertyName( const OUString& _rListenerClassName, const OUString& _rMethodName )
199 {
200 return _rListenerClassName + OUStringChar(';') + _rMethodName;
201 }
202
203 ScriptEventDescriptor lcl_getAssignedScriptEvent( const EventDescription& _rEvent, const std::vector< ScriptEventDescriptor >& _rAllAssignedMacros )
204 {
205 ScriptEventDescriptor aScriptEvent;
206 // for the case there is actually no event assigned, initialize at least ListenerType and MethodName,
207 // so this ScriptEventDescriptor properly describes the given event
208 aScriptEvent.ListenerType = _rEvent.sListenerClassName;
209 aScriptEvent.EventMethod = _rEvent.sListenerMethodName;
210
211 for ( const ScriptEventDescriptor& rSED : _rAllAssignedMacros )
212 {
213 if ( rSED.ListenerType != _rEvent.sListenerClassName
214 || rSED.EventMethod != _rEvent.sListenerMethodName
215 )
216 continue;
217
218 if ( rSED.ScriptCode.isEmpty()
219 || rSED.ScriptType.isEmpty()
220 )
221 {
222 OSL_FAIL( "lcl_getAssignedScriptEvent: me thinks this should not happen!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "222" ": "), "%s", "lcl_getAssignedScriptEvent: me thinks this should not happen!"
); } } while (false)
;
223 continue;
224 }
225
226 aScriptEvent = rSED;
227
228 if ( aScriptEvent.ScriptType != "StarBasic" )
229 continue;
230
231 // this is an old-style macro specification:
232 // [document|application]:Library.Module.Function
233 // we need to translate this to the new-style macro specification
234 // vnd.sun.star.script:Library.Module.Function?language=Basic&location=[document|application]
235
236 sal_Int32 nPrefixLen = aScriptEvent.ScriptCode.indexOf( ':' );
237 OSL_ENSURE( nPrefixLen > 0, "lcl_getAssignedScriptEvent: illegal location!" )do { if (true && (!(nPrefixLen > 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "237" ": "), "%s", "lcl_getAssignedScriptEvent: illegal location!"
); } } while (false)
;
238 OUString sLocation = aScriptEvent.ScriptCode.copy( 0, nPrefixLen );
239 OUString sMacroPath = aScriptEvent.ScriptCode.copy( nPrefixLen + 1 );
240
241 aScriptEvent.ScriptCode =
242 "vnd.sun.star.script:" +
243 sMacroPath +
244 "?language=Basic&location=" +
245 sLocation;
246
247 // also, this new-style spec requires the script code to be "Script" instead of "StarBasic"
248 aScriptEvent.ScriptType = "Script";
249 }
250 return aScriptEvent;
251 }
252
253 OUString lcl_getQualifiedKnownListenerName( const ScriptEventDescriptor& _rFormComponentEventDescriptor )
254 {
255 EventDescription aKnownEvent;
256 if ( lcl_getEventDescriptionForMethod( _rFormComponentEventDescriptor.EventMethod, aKnownEvent ) )
257 return aKnownEvent.sListenerClassName;
258 OSL_FAIL( "lcl_getQualifiedKnownListenerName: unknown method name!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "258" ": "), "%s", "lcl_getQualifiedKnownListenerName: unknown method name!"
); } } while (false)
;
259 // somebody assigned an script to a form component event which we don't know
260 // Speaking strictly, this is not really an error - it is possible to do
261 // this programmatically -, but it should rarely happen, since it's not possible
262 // via UI
263 return _rFormComponentEventDescriptor.ListenerType;
264 }
265
266 typedef std::set< Type, TypeLessByName > TypeBag;
267
268 void lcl_addListenerTypesFor_throw( const Reference< XInterface >& _rxComponent,
269 const Reference< XIntrospection >& _rxIntrospection, TypeBag& _out_rTypes )
270 {
271 if ( !_rxComponent.is() )
272 return;
273 OSL_PRECOND( _rxIntrospection.is(), "lcl_addListenerTypesFor_throw: this will crash!" )do { if (true && (!(_rxIntrospection.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "273" ": "), "%s", "lcl_addListenerTypesFor_throw: this will crash!"
); } } while (false)
;
274
275 Reference< XIntrospectionAccess > xIntrospectionAccess(
276 _rxIntrospection->inspect( makeAny( _rxComponent ) ), UNO_SET_THROW );
277
278 Sequence< Type > aListeners( xIntrospectionAccess->getSupportedListeners() );
279
280 std::copy( aListeners.begin(), aListeners.end(),
281 std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
282 }
283 }
284
285 typedef ::cppu::WeakImplHelper < css::container::XNameReplace
286 > EventHolder_Base;
287
288 namespace {
289
290 /* A UNO component holding assigned event descriptions, for use with a SvxMacroAssignDlg */
291 class EventHolder : public EventHolder_Base
292 {
293 private:
294 typedef std::unordered_map< OUString, ScriptEventDescriptor > EventMap;
295 typedef std::map< EventId, OUString > EventMapIndexAccess;
296
297 EventMap m_aEventNameAccess;
298 EventMapIndexAccess m_aEventIndexAccess;
299
300 public:
301 EventHolder( );
302
303 void addEvent( EventId _nId, const OUString& _rEventName, const ScriptEventDescriptor& _rScriptEvent );
304
305 /** effectively the same as getByName, but instead of converting the ScriptEventDescriptor to the weird
306 format used by the macro assignment dialog, it is returned directly
307 */
308 ScriptEventDescriptor getNormalizedDescriptorByName( const OUString& _rEventName ) const;
309
310 // XNameReplace
311 virtual void SAL_CALL replaceByName( const OUString& _rName, const Any& aElement ) override;
312 virtual Any SAL_CALL getByName( const OUString& _rName ) override;
313 virtual Sequence< OUString > SAL_CALL getElementNames( ) override;
314 virtual sal_Bool SAL_CALL hasByName( const OUString& _rName ) override;
315 virtual Type SAL_CALL getElementType( ) override;
316 virtual sal_Bool SAL_CALL hasElements( ) override;
317
318 protected:
319 virtual ~EventHolder( ) override;
320
321 private:
322 ScriptEventDescriptor const & impl_getDescriptor_throw( const OUString& _rEventName ) const;
323 };
324
325 }
326
327 EventHolder::EventHolder()
328 {
329 }
330
331 EventHolder::~EventHolder()
332 {
333 m_aEventNameAccess.clear();
334 m_aEventIndexAccess.clear();
335 }
336
337 void EventHolder::addEvent( EventId _nId, const OUString& _rEventName, const ScriptEventDescriptor& _rScriptEvent )
338 {
339 std::pair< EventMap::iterator, bool > insertionResult =
340 m_aEventNameAccess.emplace( _rEventName, _rScriptEvent );
341 OSL_ENSURE( insertionResult.second, "EventHolder::addEvent: there already was a MacroURL for this event!" )do { if (true && (!(insertionResult.second))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "341" ": "), "%s", "EventHolder::addEvent: there already was a MacroURL for this event!"
); } } while (false)
;
342 m_aEventIndexAccess[ _nId ] = _rEventName;
343 }
344
345 ScriptEventDescriptor EventHolder::getNormalizedDescriptorByName( const OUString& _rEventName ) const
346 {
347 return impl_getDescriptor_throw( _rEventName );
348 }
349
350 ScriptEventDescriptor const & EventHolder::impl_getDescriptor_throw( const OUString& _rEventName ) const
351 {
352 EventMap::const_iterator pos = m_aEventNameAccess.find( _rEventName );
353 if ( pos == m_aEventNameAccess.end() )
354 throw NoSuchElementException( OUString(), *const_cast< EventHolder* >( this ) );
355 return pos->second;
356 }
357
358 void SAL_CALL EventHolder::replaceByName( const OUString& _rName, const Any& _rElement )
359 {
360 EventMap::iterator pos = m_aEventNameAccess.find( _rName );
361 if ( pos == m_aEventNameAccess.end() )
362 throw NoSuchElementException( OUString(), *this );
363
364 Sequence< PropertyValue > aScriptDescriptor;
365 OSL_VERIFY( _rElement >>= aScriptDescriptor )do { if (!(_rElement >>= aScriptDescriptor)) do { if (true
&& (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "365" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
366
367 ::comphelper::NamedValueCollection aExtractor( aScriptDescriptor );
368
369 pos->second.ScriptType = aExtractor.getOrDefault( "EventType", OUString() );
370 pos->second.ScriptCode = aExtractor.getOrDefault( "Script", OUString() );
371 }
372
373 Any SAL_CALL EventHolder::getByName( const OUString& _rName )
374 {
375 ScriptEventDescriptor aDescriptor( impl_getDescriptor_throw( _rName ) );
376
377 Sequence< PropertyValue > aScriptDescriptor( 2 );
378 aScriptDescriptor[0].Name = "EventType";
379 aScriptDescriptor[0].Value <<= aDescriptor.ScriptType;
380 aScriptDescriptor[1].Name = "Script";
381 aScriptDescriptor[1].Value <<= aDescriptor.ScriptCode;
382
383 return makeAny( aScriptDescriptor );
384 }
385
386 Sequence< OUString > SAL_CALL EventHolder::getElementNames( )
387 {
388 Sequence< OUString > aReturn( m_aEventIndexAccess.size() );
389 OUString* pReturn = aReturn.getArray();
390
391 // SvxMacroAssignDlg has a weird API: It expects a XNameReplace, means a container whose
392 // main access method is by name. In its UI, it shows the possible events in exactly the
393 // order in which XNameAccess::getElementNames returns them.
394 // However, SvxMacroAssignDlg *also* takes an index for the initial selection, which is
395 // relative to the sequence returned by XNameAccess::getElementNames.
396 // This is IMO weird, since it mixes index access with name access, which decreases efficiency
397 // of the implementation.
398 // Well, it means we're forced to return the events in getElementNames in exactly the same as they
399 // appear in the property browser UI.
400 for (auto const& elem : m_aEventIndexAccess)
401 {
402 *pReturn = elem.second;
403 ++pReturn;
404 }
405 return aReturn;
406 }
407
408 sal_Bool SAL_CALL EventHolder::hasByName( const OUString& _rName )
409 {
410 EventMap::const_iterator pos = m_aEventNameAccess.find( _rName );
411 return pos != m_aEventNameAccess.end();
412 }
413
414 Type SAL_CALL EventHolder::getElementType( )
415 {
416 return cppu::UnoType<Sequence< PropertyValue >>::get();
417 }
418
419 sal_Bool SAL_CALL EventHolder::hasElements( )
420 {
421 return !m_aEventNameAccess.empty();
422 }
423
424
425 EventHandler::EventHandler( const Reference< XComponentContext >& _rxContext )
426 :EventHandler_Base( m_aMutex )
427 ,m_xContext( _rxContext )
428 ,m_aPropertyListeners( m_aMutex )
429 ,m_bEventsMapInitialized( false )
430 ,m_bIsDialogElement( false )
431 ,m_nGridColumnType( -1 )
432 {
433 }
434
435 EventHandler::~EventHandler()
436 {
437 }
438
439 OUString SAL_CALL EventHandler::getImplementationName( )
440 {
441 return "com.sun.star.comp.extensions.EventHandler";
442 }
443
444 sal_Bool SAL_CALL EventHandler::supportsService( const OUString& ServiceName )
445 {
446 return cppu::supportsService(this, ServiceName);
447 }
448
449 Sequence< OUString > SAL_CALL EventHandler::getSupportedServiceNames( )
450 {
451 return { "com.sun.star.form.inspection.EventHandler" };
452 }
453
454 void SAL_CALL EventHandler::inspect( const Reference< XInterface >& _rxIntrospectee )
455 {
456 ::osl::MutexGuard aGuard( m_aMutex );
457
458 if ( !_rxIntrospectee.is() )
459 throw NullPointerException();
460
461 m_xComponent.set( _rxIntrospectee, UNO_QUERY_THROW );
462
463 m_bEventsMapInitialized = false;
464 EventMap aEmpty;
465 m_aEvents.swap( aEmpty );
466
467 m_bIsDialogElement = false;
468 m_nGridColumnType = -1;
469 try
470 {
471 Reference< XPropertySetInfo > xPSI( m_xComponent->getPropertySetInfo() );
472 m_bIsDialogElement = xPSI.is()
473 && xPSI->hasPropertyByName( PROPERTY_WIDTH"Width" )
474 && xPSI->hasPropertyByName( PROPERTY_HEIGHT"Height" )
475 && xPSI->hasPropertyByName( PROPERTY_POSITIONX"PositionX" )
476 && xPSI->hasPropertyByName( PROPERTY_POSITIONY"PositionY" );
477
478 Reference< XChild > xAsChild( _rxIntrospectee, UNO_QUERY );
479 if ( xAsChild.is() && !Reference< XForm >( _rxIntrospectee, UNO_QUERY ).is() )
480 {
481 if ( FormComponentType::GRIDCONTROL == classifyComponent( xAsChild->getParent() ) )
482 {
483 m_nGridColumnType = classifyComponent( _rxIntrospectee );
484 }
485 }
486 }
487 catch( const Exception& )
488 {
489 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "489" ": ", "extensions.propctrlr" );
;
490 }
491 }
492
493 Any SAL_CALL EventHandler::getPropertyValue( const OUString& _rPropertyName )
494 {
495 ::osl::MutexGuard aGuard( m_aMutex );
496
497 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
498
499 std::vector< ScriptEventDescriptor > aEvents;
500 impl_getComponentScriptEvents_nothrow( aEvents );
501
502 ScriptEventDescriptor aPropertyValue;
503 for ( const ScriptEventDescriptor& rSCD : aEvents )
504 {
505 if ( rEvent.sListenerClassName == rSCD.ListenerType
506 && rEvent.sListenerMethodName == rSCD.EventMethod
507 )
508 {
509 aPropertyValue = rSCD;
510 break;
511 }
512 }
513
514 return makeAny( aPropertyValue );
515 }
516
517 void SAL_CALL EventHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
518 {
519 ::osl::MutexGuard aGuard( m_aMutex );
520
521 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
522
523 ScriptEventDescriptor aNewScriptEvent;
524 OSL_VERIFY( _rValue >>= aNewScriptEvent )do { if (!(_rValue >>= aNewScriptEvent)) do { if (true &&
(!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), (
"legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "524" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
525
526 ScriptEventDescriptor aOldScriptEvent;
527 OSL_VERIFY( getPropertyValue( _rPropertyName ) >>= aOldScriptEvent )do { if (!(getPropertyValue( _rPropertyName ) >>= aOldScriptEvent
)) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "527" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
528 if ( aOldScriptEvent == aNewScriptEvent )
529 return;
530
531 if ( m_bIsDialogElement )
532 impl_setDialogElementScriptEvent_nothrow( aNewScriptEvent );
533 else
534 impl_setFormComponentScriptEvent_nothrow( aNewScriptEvent );
535
536 PropertyHandlerHelper::setContextDocumentModified( m_xContext );
537
538 PropertyChangeEvent aEvent;
539 aEvent.Source = m_xComponent;
540 aEvent.PropertyHandle = rEvent.nId;
541 aEvent.PropertyName = _rPropertyName;
542 aEvent.OldValue <<= aOldScriptEvent;
543 aEvent.NewValue <<= aNewScriptEvent;
544 m_aPropertyListeners.notify( aEvent, &XPropertyChangeListener::propertyChange );
545 }
546
547 Any SAL_CALL EventHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue )
548 {
549 ::osl::MutexGuard aGuard( m_aMutex );
550
551 OUString sNewScriptCode;
552 OSL_VERIFY( _rControlValue >>= sNewScriptCode )do { if (!(_rControlValue >>= sNewScriptCode)) do { if (
true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "552" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
553
554 std::vector< ScriptEventDescriptor > aAllAssignedEvents;
555 impl_getComponentScriptEvents_nothrow( aAllAssignedEvents );
556
557 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
558 ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( rEvent, aAllAssignedEvents );
559
560 OSL_ENSURE( sNewScriptCode.isEmpty(), "EventHandler::convertToPropertyValue: cannot convert a non-empty display name!" )do { if (true && (!(sNewScriptCode.isEmpty()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "560" ": "), "%s", "EventHandler::convertToPropertyValue: cannot convert a non-empty display name!"
); } } while (false)
;
561 // Usually, there is no possibility for the user to change the content of an event binding directly in the
562 // input field, this instead is done with the macro assignment dialog.
563 // The only exception is the user pressing "DEL" while the control has the focus, in this case, we reset the
564 // control content to an empty string. So this is the only scenario where this method is allowed to be called.
565
566 // Strictly, we would be able to convert the display value to a property value,
567 // using the "name (location, language)" format we used in convertToControlValue. However,
568 // there is no need for this code...
569
570 aAssignedScript.ScriptCode = sNewScriptCode;
571 return makeAny( aAssignedScript );
572 }
573
574 Any SAL_CALL EventHandler::convertToControlValue( const OUString& /*_rPropertyName*/, const Any& _rPropertyValue, const Type& _rControlValueType )
575 {
576 ::osl::MutexGuard aGuard( m_aMutex );
577
578 ScriptEventDescriptor aScriptEvent;
579 OSL_VERIFY( _rPropertyValue >>= aScriptEvent )do { if (!(_rPropertyValue >>= aScriptEvent)) do { if (
true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "579" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
580
581 OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,do { if (true && (!(_rControlValueType.getTypeClass()
== TypeClass_STRING))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "582" ": "), "%s", "EventHandler::convertToControlValue: unexpected ControlValue type class!"
); } } while (false)
582 "EventHandler::convertToControlValue: unexpected ControlValue type class!" )do { if (true && (!(_rControlValueType.getTypeClass()
== TypeClass_STRING))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "582" ": "), "%s", "EventHandler::convertToControlValue: unexpected ControlValue type class!"
); } } while (false)
;
583
584 OUString sScript( aScriptEvent.ScriptCode );
585 if ( !sScript.isEmpty() )
586 {
587 // format is: "name (location, language)"
588 try
589 {
590 // parse
591 Reference< XUriReferenceFactory > xUriRefFac = UriReferenceFactory::create( m_xContext );
592 Reference< XVndSunStarScriptUrlReference > xScriptUri( xUriRefFac->parse( sScript ), UNO_QUERY_THROW );
593
594 OUStringBuffer aComposeBuffer;
595
596 // name
597 aComposeBuffer.append( xScriptUri->getName() );
598
599 // location
600 const OUString sLocation = xScriptUri->getParameter( "location" );
601 const OUString sLanguage = xScriptUri->getParameter( "language" );
602
603 if ( !(sLocation.isEmpty() && sLanguage.isEmpty()) )
604 {
605 aComposeBuffer.append( " (" );
606
607 // location
608 OSL_ENSURE( !sLocation.isEmpty(), "EventHandler::convertToControlValue: unexpected: no location!" )do { if (true && (!(!sLocation.isEmpty()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "608" ": "), "%s", "EventHandler::convertToControlValue: unexpected: no location!"
); } } while (false)
;
609 if ( !sLocation.isEmpty() )
610 {
611 aComposeBuffer.append( sLocation );
612 aComposeBuffer.append( ", " );
613 }
614
615 // language
616 if ( !sLanguage.isEmpty() )
617 {
618 aComposeBuffer.append( sLanguage );
619 }
620
621 aComposeBuffer.append( ')' );
622 }
623
624 sScript = aComposeBuffer.makeStringAndClear();
625 }
626 catch( const Exception& )
627 {
628 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "628" ": ", "extensions.propctrlr" );
;
629 }
630 }
631
632 return makeAny( sScript );
633 }
634
635 PropertyState SAL_CALL EventHandler::getPropertyState( const OUString& /*_rPropertyName*/ )
636 {
637 return PropertyState_DIRECT_VALUE;
638 }
639
640 void SAL_CALL EventHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
641 {
642 ::osl::MutexGuard aGuard( m_aMutex );
643 if ( !_rxListener.is() )
644 throw NullPointerException();
645 m_aPropertyListeners.addListener( _rxListener );
646 }
647
648 void SAL_CALL EventHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
649 {
650 ::osl::MutexGuard aGuard( m_aMutex );
651 m_aPropertyListeners.removeListener( _rxListener );
652 }
653
654 Sequence< Property > SAL_CALL EventHandler::getSupportedProperties()
655 {
656 ::osl::MutexGuard aGuard( m_aMutex );
657 if ( !m_bEventsMapInitialized )
658 {
659 m_bEventsMapInitialized = true;
660 try
661 {
662 std::vector< Type > aListeners;
663 impl_getComponentListenerTypes_nothrow( aListeners );
664
665 OUString sListenerClassName;
666
667 // loop through all listeners and all methods, and see which we can present at the UI
668 for ( const Type& rListener : aListeners )
669 {
670 // the programmatic name of the listener, to be used as "property" name
671 sListenerClassName = rListener.getTypeName();
672 OSL_ENSURE( !sListenerClassName.isEmpty(), "EventHandler::getSupportedProperties: strange - no listener name ..." )do { if (true && (!(!sListenerClassName.isEmpty()))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "672" ": "), "%s", "EventHandler::getSupportedProperties: strange - no listener name ..."
); } } while (false)
;
673 if ( sListenerClassName.isEmpty() )
674 continue;
675
676 // loop through all methods
677 const Sequence<OUString> aEventMethods = comphelper::getEventMethodsForType( rListener );
678 for (const OUString& rMethod : aEventMethods)
679 {
680 EventDescription aEvent;
681 if ( !lcl_getEventDescriptionForMethod( rMethod, aEvent ) )
682 continue;
683
684 if ( !impl_filterMethod_nothrow( aEvent ) )
685 continue;
686
687 m_aEvents.emplace(
688 lcl_getEventPropertyName( sListenerClassName, rMethod ), aEvent );
689 }
690 }
691
692 }
693 catch( const Exception& )
694 {
695 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "695" ": ", "extensions.propctrlr" );
;
696 }
697 }
698
699 // sort them by ID - this is the relative ordering in the UI
700 std::map< EventId, Property > aOrderedProperties;
701 for (auto const& event : m_aEvents)
702 {
703 aOrderedProperties[ event.second.nId ] = Property(
704 event.first, event.second.nId,
705 ::cppu::UnoType<OUString>::get(),
706 PropertyAttribute::BOUND );
707 }
708
709 return comphelper::mapValuesToSequence( aOrderedProperties );
710 }
711
712 Sequence< OUString > SAL_CALL EventHandler::getSupersededProperties( )
713 {
714 // none
715 return Sequence< OUString >( );
716 }
717
718 Sequence< OUString > SAL_CALL EventHandler::getActuatingProperties( )
719 {
720 // none
721 return Sequence< OUString >( );
722 }
723
724 LineDescriptor SAL_CALL EventHandler::describePropertyLine( const OUString& _rPropertyName,
725 const Reference< XPropertyControlFactory >& _rxControlFactory )
726 {
727 if ( !_rxControlFactory.is() )
728 throw NullPointerException();
729
730 ::osl::MutexGuard aGuard( m_aMutex );
731
732 LineDescriptor aDescriptor;
733
734 aDescriptor.Control = _rxControlFactory->createPropertyControl( PropertyControlType::TextField, true );
735 new PropertyControlExtender( aDescriptor.Control );
736
737 const EventDescription& rEvent = impl_getEventForName_throw( _rPropertyName );
738 aDescriptor.DisplayName = rEvent.sDisplayName;
739 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( rEvent.sHelpId );
740 aDescriptor.PrimaryButtonId = OStringToOUString(rEvent.sUniqueBrowseId, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
741 aDescriptor.HasPrimaryButton = true;
742 aDescriptor.Category = "Events";
743 return aDescriptor;
744 }
745
746 sal_Bool SAL_CALL EventHandler::isComposable( const OUString& /*_rPropertyName*/ )
747 {
748 return false;
749 }
750
751 InteractiveSelectionResult SAL_CALL EventHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool /*_bPrimary*/, Any& /*_rData*/, const Reference< XObjectInspectorUI >& _rxInspectorUI )
752 {
753 if ( !_rxInspectorUI.is() )
1
Taking false branch
754 throw NullPointerException();
755
756 ::osl::MutexGuard aGuard( m_aMutex );
757 const EventDescription& rForEvent = impl_getEventForName_throw( _rPropertyName );
758
759 std::vector< ScriptEventDescriptor > aAllAssignedEvents;
760 impl_getComponentScriptEvents_nothrow( aAllAssignedEvents );
761
762 // SvxMacroAssignDlg-compatible structure holding all event/assignments
763 ::rtl::Reference< EventHolder > pEventHolder( new EventHolder );
764
765 for (auto const& event : m_aEvents)
766 {
767 // the script which is assigned to the current event (if any)
768 ScriptEventDescriptor aAssignedScript = lcl_getAssignedScriptEvent( event.second, aAllAssignedEvents );
769 pEventHolder->addEvent( event.second.nId, event.second.sListenerMethodName, aAssignedScript );
770 }
771
772 // the initial selection in the dialog
773 Sequence< OUString > aNames( pEventHolder->getElementNames() );
774 const OUString* pChosenEvent = std::find( aNames.begin(), aNames.end(), rForEvent.sListenerMethodName );
775 sal_uInt16 nInitialSelection = static_cast<sal_uInt16>( pChosenEvent - aNames.begin() );
776
777 // the dialog
778 SvxAbstractDialogFactory* pFactory = SvxAbstractDialogFactory::Create();
779
780 ScopedVclPtr<VclAbstractDialog> pDialog( pFactory->CreateSvxMacroAssignDlg(
2
Calling constructor for 'ScopedVclPtr<VclAbstractDialog>'
9
Returning from constructor for 'ScopedVclPtr<VclAbstractDialog>'
781 PropertyHandlerHelper::getDialogParentFrame( m_xContext ),
782 impl_getContextFrame_nothrow(),
783 m_bIsDialogElement,
784 pEventHolder.get(),
785 nInitialSelection
786 ) );
10
Calling implicit destructor for 'VclPtr<VclAbstractDialog>'
11
Calling '~Reference'
18
Returning from '~Reference'
19
Returning from destructor for 'VclPtr<VclAbstractDialog>'
787
788 if ( !pDialog )
20
Calling 'VclPtr::operator bool'
789 return InteractiveSelectionResult_Cancelled;
790
791 // DF definite problem here
792 // OK & Cancel seem to be both returning 0
793 if ( pDialog->Execute() == RET_CANCEL )
794 return InteractiveSelectionResult_Cancelled;
795
796 try
797 {
798 for (auto const& event : m_aEvents)
799 {
800 ScriptEventDescriptor aScriptDescriptor( pEventHolder->getNormalizedDescriptorByName( event.second.sListenerMethodName ) );
801
802 // set the new "property value"
803 setPropertyValue(
804 lcl_getEventPropertyName( event.second.sListenerClassName, event.second.sListenerMethodName ),
805 makeAny( aScriptDescriptor )
806 );
807 }
808 }
809 catch( const Exception& )
810 {
811 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "811" ": ", "extensions.propctrlr" );
;
812 }
813
814 return InteractiveSelectionResult_Success;
815 }
816
817 void SAL_CALL EventHandler::actuatingPropertyChanged( const OUString& /*_rActuatingPropertyName*/, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& /*_rxInspectorUI*/, sal_Bool /*_bFirstTimeInit*/ )
818 {
819 OSL_FAIL( "EventHandler::actuatingPropertyChanged: no actuating properties -> no callback (well, this is how it *should* be!)" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "819" ": "), "%s", "EventHandler::actuatingPropertyChanged: no actuating properties -> no callback (well, this is how it *should* be!)"
); } } while (false)
;
820 }
821
822 IMPLEMENT_FORWARD_XCOMPONENT( EventHandler, EventHandler_Base )void EventHandler::dispose( ) { EventHandler_Base::WeakComponentImplHelperBase
::dispose(); } void EventHandler::addEventListener( const css
::uno::Reference< css::lang::XEventListener >& Listener
) { EventHandler_Base::WeakComponentImplHelperBase::addEventListener
( Listener ); } void EventHandler::removeEventListener( const
css::uno::Reference< css::lang::XEventListener >& Listener
) { EventHandler_Base::WeakComponentImplHelperBase::removeEventListener
( Listener ); }
823
824 void SAL_CALL EventHandler::disposing()
825 {
826 EventMap aEmpty;
827 m_aEvents.swap( aEmpty );
828 m_xComponent.clear();
829 }
830
831 sal_Bool SAL_CALL EventHandler::suspend( sal_Bool /*_bSuspend*/ )
832 {
833 return true;
834 }
835
836 Reference< XFrame > EventHandler::impl_getContextFrame_nothrow() const
837 {
838 Reference< XFrame > xContextFrame;
839
840 try
841 {
842 Reference< XModel > xContextDocument( PropertyHandlerHelper::getContextDocument(m_xContext), UNO_QUERY_THROW );
843 Reference< XController > xController( xContextDocument->getCurrentController(), UNO_SET_THROW );
844 xContextFrame.set( xController->getFrame(), UNO_SET_THROW );
845 }
846 catch( const Exception& )
847 {
848 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "848" ": ", "extensions.propctrlr" );
;
849 }
850
851 return xContextFrame;
852 }
853
854 sal_Int32 EventHandler::impl_getComponentIndexInParent_throw() const
855 {
856 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
857 Reference< XIndexAccess > xParentAsIndexAccess( xChild->getParent(), UNO_QUERY_THROW );
858
859 // get the index of the inspected object within its parent container
860 sal_Int32 nElements = xParentAsIndexAccess->getCount();
861 for ( sal_Int32 i=0; i<nElements; ++i )
862 {
863 Reference< XInterface > xElement( xParentAsIndexAccess->getByIndex( i ), UNO_QUERY_THROW );
864 if ( xElement == m_xComponent )
865 return i;
866 }
867 throw NoSuchElementException();
868 }
869
870 void EventHandler::impl_getFormComponentScriptEvents_nothrow( std::vector < ScriptEventDescriptor >& _out_rEvents ) const
871 {
872 _out_rEvents.clear();
873 try
874 {
875 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
876 Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW );
877 comphelper::sequenceToContainer(_out_rEvents, xEventManager->getScriptEvents( impl_getComponentIndexInParent_throw() ));
878
879 // the form component script API has unqualified listener names, but for normalization
880 // purpose, we want fully qualified ones
881 for ( ScriptEventDescriptor& rSED : _out_rEvents)
882 {
883 rSED.ListenerType = lcl_getQualifiedKnownListenerName( rSED );
884 }
885 }
886 catch( const Exception& )
887 {
888 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "888" ": ", "extensions.propctrlr" );
;
889 }
890 }
891
892 void EventHandler::impl_getComponentListenerTypes_nothrow( std::vector< Type >& _out_rTypes ) const
893 {
894 _out_rTypes.clear();
895 try
896 {
897 // we use a set to avoid duplicates
898 TypeBag aListeners;
899
900 Reference< XIntrospection > xIntrospection = theIntrospection::get( m_xContext );
901
902 // --- model listeners
903 lcl_addListenerTypesFor_throw(
904 m_xComponent, xIntrospection, aListeners );
905
906 // --- "secondary component" (usually: "control" listeners)
907 {
908 Reference< XInterface > xSecondaryComponent( impl_getSecondaryComponentForEventInspection_throw() );
909 lcl_addListenerTypesFor_throw( xSecondaryComponent, xIntrospection, aListeners );
910 ::comphelper::disposeComponent( xSecondaryComponent );
911 }
912
913 // now that they're disambiguated, copy these types into our member
914 _out_rTypes.insert( _out_rTypes.end(), aListeners.begin(), aListeners.end() );
915 }
916 catch( const Exception& )
917 {
918 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "918" ": ", "extensions.propctrlr" );
;
919 }
920 }
921
922 void EventHandler::impl_getDialogElementScriptEvents_nothrow( std::vector < ScriptEventDescriptor >& _out_rEvents ) const
923 {
924 _out_rEvents.clear();
925 try
926 {
927 Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW );
928 Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_SET_THROW );
929 Sequence< OUString > aEventNames( xEvents->getElementNames() );
930
931 sal_Int32 nEventCount = aEventNames.getLength();
932 _out_rEvents.resize( nEventCount );
933
934 for( sal_Int32 i = 0; i < nEventCount; ++i )
935 OSL_VERIFY( xEvents->getByName( aEventNames[i] ) >>= _out_rEvents[i] )do { if (!(xEvents->getByName( aEventNames[i] ) >>= _out_rEvents
[i])) do { if (true && (!(0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "935" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
936 }
937 catch( const Exception& )
938 {
939 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "939" ": ", "extensions.propctrlr" );
;
940 }
941 }
942
943 Reference< XInterface > EventHandler::impl_getSecondaryComponentForEventInspection_throw( ) const
944 {
945 Reference< XInterface > xReturn;
946
947 // if it's a form, create a form controller for the additional events
948 Reference< XForm > xComponentAsForm( m_xComponent, UNO_QUERY );
949 if ( xComponentAsForm.is() )
950 {
951 Reference< XTabControllerModel > xComponentAsTCModel( m_xComponent, UNO_QUERY_THROW );
952 Reference< XFormController > xController = FormController::create( m_xContext );
953 xController->setModel( xComponentAsTCModel );
954
955 xReturn = xController;
956 }
957 else
958 {
959 OUString sControlService;
960 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_DEFAULTCONTROL ) >>= sControlService )do { if (!(m_xComponent->getPropertyValue( "DefaultControl"
) >>= sControlService)) do { if (true && (!(0)
)) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "960" ": "), "OSL_ASSERT: %s", "0"); } } while (false); }
while (0)
;
961
962 xReturn = m_xContext->getServiceManager()->createInstanceWithContext( sControlService, m_xContext );
963 }
964 return xReturn;
965 }
966
967 const EventDescription& EventHandler::impl_getEventForName_throw( const OUString& _rPropertyName ) const
968 {
969 EventMap::const_iterator pos = m_aEvents.find( _rPropertyName );
970 if ( pos == m_aEvents.end() )
971 throw UnknownPropertyException(_rPropertyName);
972 return pos->second;
973 }
974
975 namespace
976 {
977 bool lcl_endsWith( const OUString& _rText, const OUString& _rCheck )
978 {
979 sal_Int32 nTextLen = _rText.getLength();
980 sal_Int32 nCheckLen = _rCheck.getLength();
981 if ( nCheckLen > nTextLen )
982 return false;
983
984 return _rText.indexOf( _rCheck ) == ( nTextLen - nCheckLen );
985 }
986 }
987
988 void EventHandler::impl_setFormComponentScriptEvent_nothrow( const ScriptEventDescriptor& _rScriptEvent )
989 {
990 try
991 {
992 OUString sScriptCode( _rScriptEvent.ScriptCode );
993 OUString sScriptType( _rScriptEvent.ScriptType );
994 bool bResetScript = sScriptCode.isEmpty();
995
996 sal_Int32 nObjectIndex = impl_getComponentIndexInParent_throw();
997 Reference< XChild > xChild( m_xComponent, UNO_QUERY_THROW );
998 Reference< XEventAttacherManager > xEventManager( xChild->getParent(), UNO_QUERY_THROW );
999 std::vector< ScriptEventDescriptor > aEvents;
1000 comphelper::sequenceToContainer( aEvents, xEventManager->getScriptEvents( nObjectIndex ) );
1001
1002 // is there already a registered script for this event?
1003 sal_Int32 eventCount = aEvents.size(), event = 0;
1004 for ( event = 0; event < eventCount; ++event )
1005 {
1006 ScriptEventDescriptor* pEvent = &aEvents[event];
1007 if ( ( pEvent->EventMethod == _rScriptEvent.EventMethod )
1008 && ( lcl_endsWith( _rScriptEvent.ListenerType, pEvent->ListenerType ) )
1009 // (strange enough, the events we get from getScriptEvents are not fully qualified)
1010 )
1011 {
1012 // yes
1013 if ( !bResetScript )
1014 {
1015 // set to something non-empty -> overwrite
1016 pEvent->ScriptCode = sScriptCode;
1017 pEvent->ScriptType = sScriptType;
1018 }
1019 else
1020 {
1021 // set to empty -> remove from vector
1022 aEvents.erase(aEvents.begin() + event );
1023 --eventCount;
1024 }
1025 break;
1026 }
1027 }
1028 if ( ( event >= eventCount ) && !bResetScript )
1029 {
1030 // no, did not find it -> append
1031 aEvents.push_back( _rScriptEvent );
1032 }
1033
1034 xEventManager->revokeScriptEvents( nObjectIndex );
1035 xEventManager->registerScriptEvents( nObjectIndex, comphelper::containerToSequence(aEvents) );
1036
1037 PropertyHandlerHelper::setContextDocumentModified( m_xContext );
1038 }
1039 catch( const Exception& )
1040 {
1041 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "1041" ": ", "extensions.propctrlr" );
;
1042 }
1043 }
1044
1045 void EventHandler::impl_setDialogElementScriptEvent_nothrow( const ScriptEventDescriptor& _rScriptEvent )
1046 {
1047 try
1048 {
1049 OUString sScriptCode( _rScriptEvent.ScriptCode );
1050 bool bResetScript = sScriptCode.isEmpty();
1051
1052 Reference< XScriptEventsSupplier > xEventsSupplier( m_xComponent, UNO_QUERY_THROW );
1053 Reference< XNameContainer > xEvents( xEventsSupplier->getEvents(), UNO_SET_THROW );
1054
1055 OUString sCompleteName =
1056 _rScriptEvent.ListenerType +
1057 "::" +
1058 _rScriptEvent.EventMethod;
1059
1060 bool bExists = xEvents->hasByName( sCompleteName );
1061
1062 if ( bResetScript )
1063 {
1064 if ( bExists )
1065 xEvents->removeByName( sCompleteName );
1066 }
1067 else
1068 {
1069 Any aNewValue; aNewValue <<= _rScriptEvent;
1070
1071 if ( bExists )
1072 xEvents->replaceByName( sCompleteName, aNewValue );
1073 else
1074 xEvents->insertByName( sCompleteName, aNewValue );
1075 }
1076 }
1077 catch( const Exception& )
1078 {
1079 DBG_UNHANDLED_EXCEPTION("extensions.propctrlr")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/extensions/source/propctrlr/eventhandler.cxx"
":" "1079" ": ", "extensions.propctrlr" );
;
1080 }
1081 }
1082
1083 bool EventHandler::impl_filterMethod_nothrow( const EventDescription& _rEvent ) const
1084 {
1085 // some (control-triggered) events do not make sense for certain grid control columns. However,
1086 // our mechanism to retrieve control-triggered events does not know about this, so we do some
1087 // late filtering here.
1088 switch ( m_nGridColumnType )
1089 {
1090 case FormComponentType::COMBOBOX:
1091 if ( UID_BRWEVT_ACTIONPERFORMED"EXTENSIONS_UID_BRWEVT_ACTIONPERFORMED" == _rEvent.sUniqueBrowseId )
1092 return false;
1093 break;
1094 case FormComponentType::LISTBOX:
1095 if ( ( UID_BRWEVT_CHANGED"EXTENSIONS_UID_BRWEVT_CHANGED" == _rEvent.sUniqueBrowseId )
1096 || ( UID_BRWEVT_ACTIONPERFORMED"EXTENSIONS_UID_BRWEVT_ACTIONPERFORMED" == _rEvent.sUniqueBrowseId )
1097 )
1098 return false;
1099 break;
1100 }
1101
1102 return true;
1103 }
1104
1105} // namespace pcr
1106
1107extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface*
1108extensions_propctrlr_EventHandler_get_implementation(
1109 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
1110{
1111 return cppu::acquire(new pcr::EventHandler(context));
1112}
1113
1114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
21
Calling 'Reference::get'
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
3
Calling implicit copy constructor for 'VclPtr<VclAbstractDialog>'
4
Calling copy constructor for 'Reference<VclAbstractDialog>'
7
Returning from copy constructor for 'Reference<VclAbstractDialog>'
8
Returning from copy constructor for 'VclPtr<VclAbstractDialog>'
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
5
Assuming field 'm_pBody' is non-null
6
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
)
12
Taking true branch
113 m_pBody->release();
13
Calling 'VclReferenceBase::release'
17
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
22
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
14
Assuming the condition is true
15
Taking true branch
40 delete this;
16
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif