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 unomodel.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 SM_DLLIMPLEMENTATION -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/starmath/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/starmath/sdi -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/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -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/starmath/source/unomodel.cxx

/home/maarten/src/libreoffice/core/starmath/source/unomodel.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#include <sal/config.h>
21#include <sal/log.hxx>
22
23#include <utility>
24
25#include <o3tl/any.hxx>
26#include <sfx2/printer.hxx>
27#include <svl/itemprop.hxx>
28#include <svl/itemset.hxx>
29#include <vcl/svapp.hxx>
30#include <unotools/localedatawrapper.hxx>
31#include <vcl/settings.hxx>
32#include <vcl/print.hxx>
33#include <toolkit/awt/vclxdevice.hxx>
34#include <com/sun/star/beans/PropertyAttribute.hpp>
35#include <com/sun/star/formula/SymbolDescriptor.hpp>
36#include <com/sun/star/awt/Size.hpp>
37#include <comphelper/propertysetinfo.hxx>
38#include <comphelper/sequence.hxx>
39#include <comphelper/servicehelper.hxx>
40#include <cppuhelper/queryinterface.hxx>
41#include <cppuhelper/supportsservice.hxx>
42#include <unotools/moduleoptions.hxx>
43#include <tools/mapunit.hxx>
44#include <tools/stream.hxx>
45
46#include <unomodel.hxx>
47#include <document.hxx>
48#include <view.hxx>
49#include <symbol.hxx>
50#include <starmath.hrc>
51#include <strings.hrc>
52#include <smmod.hxx>
53#include "cfgitem.hxx"
54
55using namespace ::cppu;
56using namespace ::std;
57using namespace ::comphelper;
58using namespace ::com::sun::star;
59using namespace ::com::sun::star::uno;
60using namespace ::com::sun::star::beans;
61using namespace ::com::sun::star::lang;
62using namespace ::com::sun::star::formula;
63using namespace ::com::sun::star::view;
64using namespace ::com::sun::star::script;
65
66SmPrintUIOptions::SmPrintUIOptions()
67{
68 SmModule *pp = SM_MOD()( static_cast<SmModule*>(SfxApplication::GetModule(SfxToolsModule
::Math)) )
;
69 SmMathConfig *pConfig = pp->GetConfig();
70 SAL_WARN_IF( !pConfig, "starmath", "SmConfig not found" )do { if (true && (!pConfig)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "starmath")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "SmConfig not found"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"
), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "70" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SmConfig not found"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"SmConfig not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "70" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SmConfig not found") == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "70" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SmConfig not found"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"SmConfig not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "70" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
71 if (!pConfig)
72 return;
73
74 sal_Int32 nNumProps = 10, nIdx=0;
75
76 // create sequence of print UI options
77 // (Actually IsIgnoreSpacesRight is a parser option. Without it we need only 8 properties here.)
78 m_aUIProperties.resize( nNumProps );
79
80 // load the math PrinterOptions into the custom tab
81 m_aUIProperties[nIdx].Name = "OptionsUIFile";
82 m_aUIProperties[nIdx++].Value <<= OUString("modules/smath/ui/printeroptions.ui");
83
84 // create Section for formula (results in an extra tab page in dialog)
85 SvtModuleOptions aOpt;
86 OUString aAppGroupname(
87 SmResId( RID_PRINTUIOPT_PRODNAMEreinterpret_cast<char const *>("RID_PRINTUIOPT_PRODNAME"
"\004" u8"%PRODUCTNAME %s")
).
88 replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::EModule::MATH ) ) );
89 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, ".HelpID:vcl:PrintDialog:TabPage:AppPage");
90
91 // create subgroup for print options
92 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("contents", SmResId( RID_PRINTUIOPT_CONTENTSreinterpret_cast<char const *>("RID_PRINTUIOPT_CONTENTS"
"\004" u8"Contents")
), OUString());
93
94 // create a bool option for title row (matches to SID_PRINTTITLE)
95 m_aUIProperties[nIdx++].Value = setBoolControlOpt("title", SmResId( RID_PRINTUIOPT_TITLEreinterpret_cast<char const *>("RID_PRINTUIOPT_TITLE" "\004"
u8"~Title")
),
96 ".HelpID:vcl:PrintDialog:TitleRow:CheckBox",
97 PRTUIOPT_TITLE_ROW"TitleRow",
98 pConfig->IsPrintTitle());
99 // create a bool option for formula text (matches to SID_PRINTTEXT)
100 m_aUIProperties[nIdx++].Value = setBoolControlOpt("formulatext", SmResId( RID_PRINTUIOPT_FRMLTXTreinterpret_cast<char const *>("RID_PRINTUIOPT_FRMLTXT"
"\004" u8"~Formula text")
),
101 ".HelpID:vcl:PrintDialog:FormulaText:CheckBox",
102 PRTUIOPT_FORMULA_TEXT"FormulaText",
103 pConfig->IsPrintFormulaText());
104 // create a bool option for border (matches to SID_PRINTFRAME)
105 m_aUIProperties[nIdx++].Value = setBoolControlOpt("borders", SmResId( RID_PRINTUIOPT_BORDERSreinterpret_cast<char const *>("RID_PRINTUIOPT_BORDERS"
"\004" u8"B~orders")
),
106 ".HelpID:vcl:PrintDialog:Border:CheckBox",
107 PRTUIOPT_BORDER"Border",
108 pConfig->IsPrintFrame());
109
110 // create subgroup for print format
111 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("size", SmResId( RID_PRINTUIOPT_SIZEreinterpret_cast<char const *>("RID_PRINTUIOPT_SIZE" "\004"
u8"Size")
), OUString());
112
113 // create a radio button group for print format (matches to SID_PRINTSIZE)
114 Sequence< OUString > aChoices{
115 SmResId( RID_PRINTUIOPT_ORIGSIZEreinterpret_cast<char const *>("RID_PRINTUIOPT_ORIGSIZE"
"\004" u8"O~riginal size")
),
116 SmResId( RID_PRINTUIOPT_FITTOPAGEreinterpret_cast<char const *>("RID_PRINTUIOPT_FITTOPAGE"
"\004" u8"Fit to ~page")
),
117 SmResId( RID_PRINTUIOPT_SCALINGreinterpret_cast<char const *>("RID_PRINTUIOPT_SCALING"
"\004" u8"~Scaling")
)
118 };
119 Sequence< OUString > aHelpIds{
120 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:0",
121 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:1",
122 ".HelpID:vcl:PrintDialog:PrintFormat:RadioButton:2"
123 };
124 Sequence< OUString > aWidgetIds{
125 "originalsize",
126 "fittopage",
127 "scaling"
128 };
129 OUString aPrintFormatProp( PRTUIOPT_PRINT_FORMAT"PrintFormat" );
130 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
131 aHelpIds,
132 aPrintFormatProp,
133 aChoices, static_cast< sal_Int32 >(pConfig->GetPrintSize())
134 );
135
136 // create a numeric box for scale dependent on PrintFormat = "Scaling" (matches to SID_PRINTZOOM)
137 vcl::PrinterOptionsHelper::UIControlOptions aRangeOpt( aPrintFormatProp, 2, true );
138 m_aUIProperties[nIdx++].Value = setRangeControlOpt("scalingspin", OUString(),
139 ".HelpID:vcl:PrintDialog:PrintScale:NumericField",
140 PRTUIOPT_PRINT_SCALE"PrintScale",
141 pConfig->GetPrintZoomFactor(), // initial value
142 10, // min value
143 1000, // max value
144 aRangeOpt);
145
146 Sequence< PropertyValue > aHintNoLayoutPage( 1 );
147 aHintNoLayoutPage[0].Name = "HintNoLayoutPage";
148 aHintNoLayoutPage[0].Value <<= true;
149 m_aUIProperties[nIdx++].Value <<= aHintNoLayoutPage;
150
151 assert(nIdx == nNumProps)(static_cast <bool> (nIdx == nNumProps) ? void (0) : __assert_fail
("nIdx == nNumProps", "/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
, 151, __extension__ __PRETTY_FUNCTION__))
;
152}
153
154
155
156namespace {
157
158enum SmModelPropertyHandles
159{
160 HANDLE_FORMULA,
161 HANDLE_FONT_NAME_VARIABLES,
162 HANDLE_FONT_NAME_FUNCTIONS,
163 HANDLE_FONT_NAME_NUMBERS,
164 HANDLE_FONT_NAME_TEXT,
165 HANDLE_CUSTOM_FONT_NAME_SERIF,
166 HANDLE_CUSTOM_FONT_NAME_SANS,
167 HANDLE_CUSTOM_FONT_NAME_FIXED,
168 HANDLE_CUSTOM_FONT_FIXED_POSTURE,
169 HANDLE_CUSTOM_FONT_FIXED_WEIGHT,
170 HANDLE_CUSTOM_FONT_SANS_POSTURE,
171 HANDLE_CUSTOM_FONT_SANS_WEIGHT,
172 HANDLE_CUSTOM_FONT_SERIF_POSTURE,
173 HANDLE_CUSTOM_FONT_SERIF_WEIGHT,
174 HANDLE_FONT_VARIABLES_POSTURE,
175 HANDLE_FONT_VARIABLES_WEIGHT,
176 HANDLE_FONT_FUNCTIONS_POSTURE,
177 HANDLE_FONT_FUNCTIONS_WEIGHT,
178 HANDLE_FONT_NUMBERS_POSTURE,
179 HANDLE_FONT_NUMBERS_WEIGHT,
180 HANDLE_FONT_TEXT_POSTURE,
181 HANDLE_FONT_TEXT_WEIGHT,
182 HANDLE_BASE_FONT_HEIGHT,
183 HANDLE_RELATIVE_FONT_HEIGHT_TEXT,
184 HANDLE_RELATIVE_FONT_HEIGHT_INDICES,
185 HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS,
186 HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS,
187 HANDLE_RELATIVE_FONT_HEIGHT_LIMITS,
188 HANDLE_IS_TEXT_MODE,
189 HANDLE_GREEK_CHAR_STYLE,
190 HANDLE_ALIGNMENT,
191 HANDLE_RELATIVE_SPACING,
192 HANDLE_RELATIVE_LINE_SPACING,
193 HANDLE_RELATIVE_ROOT_SPACING,
194 HANDLE_RELATIVE_INDEX_SUPERSCRIPT,
195 HANDLE_RELATIVE_INDEX_SUBSCRIPT,
196 HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT,
197 HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH,
198 HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH,
199 HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT,
200 HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE,
201 HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE,
202 HANDLE_RELATIVE_BRACKET_EXCESS_SIZE,
203 HANDLE_RELATIVE_BRACKET_DISTANCE,
204 HANDLE_IS_SCALE_ALL_BRACKETS,
205 HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE,
206 HANDLE_RELATIVE_MATRIX_LINE_SPACING,
207 HANDLE_RELATIVE_MATRIX_COLUMN_SPACING,
208 HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT,
209 HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT,
210 HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE,
211 HANDLE_RELATIVE_OPERATOR_SPACING,
212 HANDLE_LEFT_MARGIN,
213 HANDLE_RIGHT_MARGIN,
214 HANDLE_TOP_MARGIN,
215 HANDLE_BOTTOM_MARGIN,
216 HANDLE_PRINTER_NAME,
217 HANDLE_PRINTER_SETUP,
218 HANDLE_SYMBOLS,
219 HANDLE_SAVE_THUMBNAIL,
220 HANDLE_USED_SYMBOLS,
221 HANDLE_BASIC_LIBRARIES,
222 HANDLE_RUNTIME_UID,
223 HANDLE_LOAD_READONLY, // Security Options
224 HANDLE_DIALOG_LIBRARIES, // #i73329#
225 HANDLE_BASELINE,
226 HANDLE_INTEROP_GRAB_BAG,
227};
228
229}
230
231static rtl::Reference<PropertySetInfo> lcl_createModelPropertyInfo ()
232{
233 static PropertyMapEntry aModelPropertyInfoMap[] =
234 {
235 { OUString("Alignment") , HANDLE_ALIGNMENT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, 0 },
236 { OUString("BaseFontHeight") , HANDLE_BASE_FONT_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, 0 },
237 { OUString("BasicLibraries") , HANDLE_BASIC_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
238 { OUString("BottomMargin") , HANDLE_BOTTOM_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_BOTTOMSPACE22 },
239 { OUString("CustomFontNameFixed") , HANDLE_CUSTOM_FONT_NAME_FIXED , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_FIXED6 },
240 { OUString("CustomFontNameSans") , HANDLE_CUSTOM_FONT_NAME_SANS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_SANS5 },
241 { OUString("CustomFontNameSerif") , HANDLE_CUSTOM_FONT_NAME_SERIF , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_SERIF4 },
242 { OUString("DialogLibraries") , HANDLE_DIALOG_LIBRARIES , cppu::UnoType<script::XLibraryContainer>::get(), PropertyAttribute::READONLY, 0 },
243 { OUString("FontFixedIsBold") , HANDLE_CUSTOM_FONT_FIXED_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_FIXED6 },
244 { OUString("FontFixedIsItalic") , HANDLE_CUSTOM_FONT_FIXED_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_FIXED6 },
245 { OUString("FontFunctionsIsBold") , HANDLE_FONT_FUNCTIONS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_FUNCTION1 },
246 { OUString("FontFunctionsIsItalic") , HANDLE_FONT_FUNCTIONS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_FUNCTION1 },
247 { OUString("FontNameFunctions") , HANDLE_FONT_NAME_FUNCTIONS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_FUNCTION1 },
248 { OUString("FontNameNumbers") , HANDLE_FONT_NAME_NUMBERS , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_NUMBER2 },
249 { OUString("FontNameText") , HANDLE_FONT_NAME_TEXT , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_TEXT3 },
250 { OUString("FontNameVariables") , HANDLE_FONT_NAME_VARIABLES , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, FNT_VARIABLE0 },
251 { OUString("FontNumbersIsBold") , HANDLE_FONT_NUMBERS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_NUMBER2 },
252 { OUString("FontNumbersIsItalic") , HANDLE_FONT_NUMBERS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_NUMBER2 },
253 { OUString("FontSansIsBold") , HANDLE_CUSTOM_FONT_SANS_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_SANS5 },
254 { OUString("FontSansIsItalic") , HANDLE_CUSTOM_FONT_SANS_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_SANS5 },
255 { OUString("FontSerifIsBold") , HANDLE_CUSTOM_FONT_SERIF_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_SERIF4 },
256 { OUString("FontSerifIsItalic") , HANDLE_CUSTOM_FONT_SERIF_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_SERIF4 },
257 { OUString("FontTextIsBold") , HANDLE_FONT_TEXT_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_TEXT3 },
258 { OUString("FontTextIsItalic") , HANDLE_FONT_TEXT_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_TEXT3 },
259 { OUString("FontVariablesIsBold") , HANDLE_FONT_VARIABLES_WEIGHT , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_VARIABLE0 },
260 { OUString("FontVariablesIsItalic") , HANDLE_FONT_VARIABLES_POSTURE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, FNT_VARIABLE0 },
261 { OUString("Formula") , HANDLE_FORMULA , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, 0 },
262 { OUString("IsScaleAllBrackets") , HANDLE_IS_SCALE_ALL_BRACKETS , cppu::UnoType<bool>::get(), PROPERTY_NONE0, 0 },
263 { OUString("IsTextMode") , HANDLE_IS_TEXT_MODE , cppu::UnoType<bool>::get(), PROPERTY_NONE0, 0 },
264 { OUString("GreekCharStyle") , HANDLE_GREEK_CHAR_STYLE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, 0 },
265 { OUString("LeftMargin") , HANDLE_LEFT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_LEFTSPACE19 },
266 { OUString("PrinterName") , HANDLE_PRINTER_NAME , ::cppu::UnoType<OUString>::get(), PROPERTY_NONE0, 0 },
267 { OUString("PrinterSetup") , HANDLE_PRINTER_SETUP , cppu::UnoType<const Sequence < sal_Int8 >>::get(), PROPERTY_NONE0, 0 },
268 { OUString("RelativeBracketDistance") , HANDLE_RELATIVE_BRACKET_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_BRACKETSPACE12 },
269 { OUString("RelativeBracketExcessSize") , HANDLE_RELATIVE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_BRACKETSIZE11 },
270 { OUString("RelativeFontHeightFunctions") , HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, SIZ_FUNCTION2 },
271 { OUString("RelativeFontHeightIndices") , HANDLE_RELATIVE_FONT_HEIGHT_INDICES , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, SIZ_INDEX1 },
272 { OUString("RelativeFontHeightLimits") , HANDLE_RELATIVE_FONT_HEIGHT_LIMITS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, SIZ_LIMITS4 },
273 { OUString("RelativeFontHeightOperators") , HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, SIZ_OPERATOR3 },
274 { OUString("RelativeFontHeightText") , HANDLE_RELATIVE_FONT_HEIGHT_TEXT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, SIZ_TEXT0 },
275 { OUString("RelativeFractionBarExcessLength") , HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_FRACTION7 },
276 { OUString("RelativeFractionBarLineWeight") , HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_STROKEWIDTH8 },
277 { OUString("RelativeFractionDenominatorDepth") , HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH, ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_DENOMINATOR6 },
278 { OUString("RelativeFractionNumeratorHeight") , HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_NUMERATOR5 },
279 { OUString("RelativeIndexSubscript") , HANDLE_RELATIVE_INDEX_SUBSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_SUBSCRIPT4 },
280 { OUString("RelativeIndexSuperscript") , HANDLE_RELATIVE_INDEX_SUPERSCRIPT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_SUPERSCRIPT3 },
281 { OUString("RelativeLineSpacing") , HANDLE_RELATIVE_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_VERTICAL1 },
282 { OUString("RelativeLowerLimitDistance") , HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_LOWERLIMIT10 },
283 { OUString("RelativeMatrixColumnSpacing") , HANDLE_RELATIVE_MATRIX_COLUMN_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_MATRIXCOL14 },
284 { OUString("RelativeMatrixLineSpacing") , HANDLE_RELATIVE_MATRIX_LINE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_MATRIXROW13 },
285 { OUString("RelativeOperatorExcessSize") , HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_OPERATORSIZE17 },
286 { OUString("RelativeOperatorSpacing") , HANDLE_RELATIVE_OPERATOR_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_OPERATORSPACE18 },
287 { OUString("RelativeRootSpacing") , HANDLE_RELATIVE_ROOT_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_ROOT2 },
288 { OUString("RelativeScaleBracketExcessSize") , HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_NORMALBRACKETSIZE23 },
289 { OUString("RelativeSpacing") , HANDLE_RELATIVE_SPACING , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_HORIZONTAL0 },
290 { OUString("RelativeSymbolMinimumHeight") , HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_ORNAMENTSPACE16 },
291 { OUString("RelativeSymbolPrimaryHeight") , HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_ORNAMENTSIZE15 },
292 { OUString("RelativeUpperLimitDistance") , HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_UPPERLIMIT9 },
293 { OUString("RightMargin") , HANDLE_RIGHT_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_RIGHTSPACE20 },
294 { OUString("RuntimeUID") , HANDLE_RUNTIME_UID , cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
295 { OUString("SaveThumbnail") , HANDLE_SAVE_THUMBNAIL , cppu::UnoType<bool>::get(), PROPERTY_NONE0, 0 },
296 { OUString("Symbols") , HANDLE_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PROPERTY_NONE0, 0 },
297 { OUString("UserDefinedSymbolsInUse") , HANDLE_USED_SYMBOLS , cppu::UnoType<Sequence < SymbolDescriptor >>::get(), PropertyAttribute::READONLY, 0 },
298 { OUString("TopMargin") , HANDLE_TOP_MARGIN , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, DIS_TOPSPACE21 },
299 // #i33095# Security Options
300 { OUString("LoadReadonly") , HANDLE_LOAD_READONLY , cppu::UnoType<bool>::get(), PROPERTY_NONE0, 0 },
301 // #i972#
302 { OUString("BaseLine") , HANDLE_BASELINE , ::cppu::UnoType<sal_Int16>::get(), PROPERTY_NONE0, 0 },
303 { OUString("InteropGrabBag") , HANDLE_INTEROP_GRAB_BAG , cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), PROPERTY_NONE0, 0 },
304 { OUString(), 0, css::uno::Type(), 0, 0 }
305 };
306 return rtl::Reference<PropertySetInfo>( new PropertySetInfo ( aModelPropertyInfoMap ) );
307}
308
309SmModel::SmModel( SfxObjectShell *pObjSh )
310: SfxBaseModel(pObjSh)
311, PropertySetHelper ( lcl_createModelPropertyInfo () )
312{
313}
314
315SmModel::~SmModel() throw ()
316{
317}
318
319uno::Any SAL_CALL SmModel::queryInterface( const uno::Type& rType )
320{
321 uno::Any aRet = ::cppu::queryInterface ( rType,
322 // OWeakObject interfaces
323 &dynamic_cast<XInterface&>(static_cast<XUnoTunnel&>(*this)),
324 static_cast< XWeak* > ( this ),
325 // PropertySetHelper interfaces
326 static_cast< XPropertySet* > ( this ),
327 static_cast< XMultiPropertySet* > ( this ),
328 // my own interfaces
329 static_cast< XServiceInfo* > ( this ),
330 static_cast< XRenderable* > ( this ) );
331 if (!aRet.hasValue())
332 aRet = SfxBaseModel::queryInterface ( rType );
333 return aRet;
334}
335
336void SAL_CALL SmModel::acquire() throw()
337{
338 OWeakObject::acquire();
339}
340
341void SAL_CALL SmModel::release() throw()
342{
343 OWeakObject::release();
344}
345
346uno::Sequence< uno::Type > SAL_CALL SmModel::getTypes( )
347{
348 return comphelper::concatSequences(SfxBaseModel::getTypes(),
349 uno::Sequence {
350 cppu::UnoType<XServiceInfo>::get(),
351 cppu::UnoType<XPropertySet>::get(),
352 cppu::UnoType<XMultiPropertySet>::get(),
353 cppu::UnoType<XRenderable>::get() });
354}
355
356namespace
357{
358 class theSmModelUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmModelUnoTunnelId> {};
359}
360
361const uno::Sequence< sal_Int8 > & SmModel::getUnoTunnelId()
362{
363 return theSmModelUnoTunnelId::get().getSeq();
364}
365
366sal_Int64 SAL_CALL SmModel::getSomething( const uno::Sequence< sal_Int8 >& rId )
367{
368 if( isUnoTunnelId<SmModel>(rId) )
369 {
370 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
371 }
372
373 return SfxBaseModel::getSomething( rId );
374}
375
376static sal_Int16 lcl_AnyToINT16(const uno::Any& rAny)
377{
378 sal_Int16 nRet = 0;
379 if( auto x = o3tl::tryAccess<double>(rAny) )
380 nRet = static_cast<sal_Int16>(*x);
381 else
382 rAny >>= nRet;
383 return nRet;
384}
385
386OUString SmModel::getImplementationName()
387{
388 return "com.sun.star.comp.Math.FormulaDocument";
389}
390
391sal_Bool SmModel::supportsService(const OUString& rServiceName)
392{
393 return cppu::supportsService(this, rServiceName);
394}
395
396uno::Sequence< OUString > SmModel::getSupportedServiceNames()
397{
398 return uno::Sequence<OUString>{
399 "com.sun.star.document.OfficeDocument",
400 "com.sun.star.formula.FormulaProperties"
401 };
402}
403
404void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* pValues)
405{
406 SolarMutexGuard aGuard;
407
408 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
409
410 if ( nullptr == pDocSh )
1
Assuming the condition is false
2
Taking false branch
411 throw UnknownPropertyException();
412
413 SmFormat aFormat = pDocSh->GetFormat();
414
415 for (; *ppEntries; ppEntries++, pValues++ )
3
Loop condition is true. Entering loop body
416 {
417 if ((*ppEntries)->mnAttributes & PropertyAttribute::READONLY)
4
Assuming the condition is false
5
Taking false branch
418 throw PropertyVetoException();
419
420 switch ( (*ppEntries)->mnHandle )
6
Control jumps to 'case HANDLE_PRINTER_NAME:' at line 577
421 {
422 case HANDLE_FORMULA:
423 {
424 OUString aText;
425 *pValues >>= aText;
426 pDocSh->SetText(aText);
427 }
428 break;
429 case HANDLE_FONT_NAME_VARIABLES :
430 case HANDLE_FONT_NAME_FUNCTIONS :
431 case HANDLE_FONT_NAME_NUMBERS :
432 case HANDLE_FONT_NAME_TEXT :
433 case HANDLE_CUSTOM_FONT_NAME_SERIF :
434 case HANDLE_CUSTOM_FONT_NAME_SANS :
435 case HANDLE_CUSTOM_FONT_NAME_FIXED :
436 {
437 OUString sFontName;
438 *pValues >>= sFontName;
439 if(sFontName.isEmpty())
440 throw IllegalArgumentException();
441
442 if(aFormat.GetFont((*ppEntries)->mnMemberId).GetFamilyName() != sFontName)
443 {
444 const SmFace rOld = aFormat.GetFont((*ppEntries)->mnMemberId);
445
446 SmFace aSet( sFontName, rOld.GetFontSize() );
447 aSet.SetBorderWidth( rOld.GetBorderWidth() );
448 aSet.SetAlignment( ALIGN_BASELINE );
449 aFormat.SetFont( (*ppEntries)->mnMemberId, aSet );
450 }
451 }
452 break;
453 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
454 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
455 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
456 case HANDLE_FONT_VARIABLES_POSTURE :
457 case HANDLE_FONT_FUNCTIONS_POSTURE :
458 case HANDLE_FONT_NUMBERS_POSTURE :
459 case HANDLE_FONT_TEXT_POSTURE :
460 {
461 auto bVal = o3tl::tryAccess<bool>(*pValues);
462 if(!bVal)
463 throw IllegalArgumentException();
464 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
465 aNewFont.SetItalic(*bVal ? ITALIC_NORMAL : ITALIC_NONE);
466 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
467 }
468 break;
469 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
470 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
471 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
472 case HANDLE_FONT_VARIABLES_WEIGHT :
473 case HANDLE_FONT_FUNCTIONS_WEIGHT :
474 case HANDLE_FONT_NUMBERS_WEIGHT :
475 case HANDLE_FONT_TEXT_WEIGHT :
476 {
477 auto bVal = o3tl::tryAccess<bool>(*pValues);
478 if(!bVal)
479 throw IllegalArgumentException();
480 vcl::Font aNewFont(aFormat.GetFont((*ppEntries)->mnMemberId));
481 aNewFont.SetWeight(*bVal ? WEIGHT_BOLD : WEIGHT_NORMAL);
482 aFormat.SetFont((*ppEntries)->mnMemberId, aNewFont);
483 }
484 break;
485 case HANDLE_BASE_FONT_HEIGHT :
486 {
487 // Point!
488 sal_Int16 nVal = lcl_AnyToINT16(*pValues);
489 if(nVal < 1)
490 throw IllegalArgumentException();
491 Size aSize = aFormat.GetBaseSize();
492 aSize.setHeight( SmPtsTo100th_mm(nVal) );
493 aFormat.SetBaseSize(aSize);
494
495 // apply base size to fonts
496 const Size aTmp( aFormat.GetBaseSize() );
497 for (sal_uInt16 i = FNT_BEGIN0; i <= FNT_END7; i++)
498 aFormat.SetFontSize(i, aTmp);
499 }
500 break;
501 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
502 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
503 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
504 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
505 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
506 {
507 sal_Int16 nVal = 0;
508 *pValues >>= nVal;
509 if(nVal < 1)
510 throw IllegalArgumentException();
511 aFormat.SetRelSize((*ppEntries)->mnMemberId, nVal);
512 }
513 break;
514
515 case HANDLE_IS_TEXT_MODE :
516 {
517 aFormat.SetTextmode(*o3tl::doAccess<bool>(*pValues));
518 }
519 break;
520
521 case HANDLE_GREEK_CHAR_STYLE :
522 {
523 sal_Int16 nVal = 0;
524 *pValues >>= nVal;
525 if (nVal < 0 || nVal > 2)
526 throw IllegalArgumentException();
527 aFormat.SetGreekCharStyle( nVal );
528 }
529 break;
530
531 case HANDLE_ALIGNMENT :
532 {
533 // SmHorAlign uses the same values as HorizontalAlignment
534 sal_Int16 nVal = 0;
535 *pValues >>= nVal;
536 if(nVal < 0 || nVal > 2)
537 throw IllegalArgumentException();
538 aFormat.SetHorAlign(static_cast<SmHorAlign>(nVal));
539 }
540 break;
541
542 case HANDLE_RELATIVE_SPACING :
543 case HANDLE_RELATIVE_LINE_SPACING :
544 case HANDLE_RELATIVE_ROOT_SPACING :
545 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
546 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
547 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
548 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
549 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
550 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
551 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
552 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
553 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
554 case HANDLE_RELATIVE_BRACKET_DISTANCE :
555 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
556 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
557 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
558 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
559 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
560 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
561 case HANDLE_RELATIVE_OPERATOR_SPACING :
562 case HANDLE_LEFT_MARGIN :
563 case HANDLE_RIGHT_MARGIN :
564 case HANDLE_TOP_MARGIN :
565 case HANDLE_BOTTOM_MARGIN :
566 {
567 sal_Int16 nVal = 0;
568 *pValues >>= nVal;
569 if(nVal < 0)
570 throw IllegalArgumentException();
571 aFormat.SetDistance((*ppEntries)->mnMemberId, nVal);
572 }
573 break;
574 case HANDLE_IS_SCALE_ALL_BRACKETS :
575 aFormat.SetScaleNormalBrackets(*o3tl::doAccess<bool>(*pValues));
576 break;
577 case HANDLE_PRINTER_NAME:
578 {
579 // embedded documents just ignore this property for now
580 if ( pDocSh->GetCreateMode() != SfxObjectCreateMode::EMBEDDED )
7
Assuming the condition is true
8
Taking true branch
581 {
582 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
583 if (pPrinter)
9
Assuming 'pPrinter' is non-null
10
Taking true branch
584 {
585 OUString sPrinterName;
586 if ( !(*pValues >>= sPrinterName) )
11
Taking false branch
587 throw IllegalArgumentException();
588
589 if ( !sPrinterName.isEmpty() )
12
Taking true branch
590 {
591 VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName );
13
Calling constructor for 'VclPtrInstance<SfxPrinter>'
15
Returning from constructor for 'VclPtrInstance<SfxPrinter>'
592 if (pNewPrinter->IsKnown())
16
Assuming the condition is false
17
Taking false branch
593 pDocSh->SetPrinter ( pNewPrinter );
594 else
595 pNewPrinter.disposeAndClear();
18
Calling 'VclPtr::disposeAndClear'
596 }
597 }
598 }
599 }
600 break;
601 case HANDLE_PRINTER_SETUP:
602 {
603 Sequence < sal_Int8 > aSequence;
604 if ( !(*pValues >>= aSequence) )
605 throw IllegalArgumentException();
606
607 sal_uInt32 nSize = aSequence.getLength();
608 SvMemoryStream aStream ( aSequence.getArray(), nSize, StreamMode::READ );
609 aStream.Seek ( STREAM_SEEK_TO_BEGIN0L );
610 static sal_uInt16 const nRange[] =
611 {
612 SID_PRINTSIZE((30000 + 256) + 115), SID_PRINTSIZE((30000 + 256) + 115),
613 SID_PRINTZOOM((30000 + 256) + 116), SID_PRINTZOOM((30000 + 256) + 116),
614 SID_PRINTTITLE((30000 + 256) + 112), SID_PRINTTITLE((30000 + 256) + 112),
615 SID_PRINTTEXT((30000 + 256) + 113), SID_PRINTTEXT((30000 + 256) + 113),
616 SID_PRINTFRAME((30000 + 256) + 114), SID_PRINTFRAME((30000 + 256) + 114),
617 SID_NO_RIGHT_SPACES((30000 + 256) + 124), SID_NO_RIGHT_SPACES((30000 + 256) + 124),
618 SID_SAVE_ONLY_USED_SYMBOLS((30000 + 256) + 125), SID_SAVE_ONLY_USED_SYMBOLS((30000 + 256) + 125),
619 SID_AUTO_CLOSE_BRACKETS((30000 + 256) + 127), SID_AUTO_CLOSE_BRACKETS((30000 + 256) + 127),
620 0
621 };
622 auto pItemSet = std::make_unique<SfxItemSet>( SmDocShell::GetPool(), nRange );
623 SmModule *pp = SM_MOD()( static_cast<SmModule*>(SfxApplication::GetModule(SfxToolsModule
::Math)) )
;
624 pp->GetConfig()->ConfigToItemSet(*pItemSet);
625 VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, std::move(pItemSet) );
626
627 pDocSh->SetPrinter( pPrinter );
628 }
629 break;
630 case HANDLE_SYMBOLS:
631 {
632 // this is set
633 Sequence < SymbolDescriptor > aSequence;
634 if ( !(*pValues >>= aSequence) )
635 throw IllegalArgumentException();
636
637 SmModule *pp = SM_MOD()( static_cast<SmModule*>(SfxApplication::GetModule(SfxToolsModule
::Math)) )
;
638 SmSymbolManager &rManager = pp->GetSymbolManager();
639 for (const SymbolDescriptor& rDescriptor : std::as_const(aSequence))
640 {
641 vcl::Font aFont;
642 aFont.SetFamilyName ( rDescriptor.sFontName );
643 aFont.SetCharSet ( static_cast < rtl_TextEncoding > (rDescriptor.nCharSet) );
644 aFont.SetFamily ( static_cast < FontFamily > (rDescriptor.nFamily ) );
645 aFont.SetPitch ( static_cast < FontPitch > (rDescriptor.nPitch ) );
646 aFont.SetWeight ( static_cast < FontWeight > (rDescriptor.nWeight ) );
647 aFont.SetItalic ( static_cast < FontItalic > (rDescriptor.nItalic ) );
648 SmSym aSymbol ( rDescriptor.sName, aFont, static_cast < sal_Unicode > (rDescriptor.nCharacter),
649 rDescriptor.sSymbolSet );
650 aSymbol.SetExportName ( rDescriptor.sExportName );
651 rManager.AddOrReplaceSymbol ( aSymbol );
652 }
653 }
654 break;
655 // #i33095# Security Options
656 case HANDLE_LOAD_READONLY :
657 {
658 if ( (*pValues).getValueType() != cppu::UnoType<bool>::get() )
659 throw IllegalArgumentException();
660 bool bReadonly = false;
661 if ( *pValues >>= bReadonly )
662 pDocSh->SetLoadReadonly( bReadonly );
663 break;
664 }
665 case HANDLE_INTEROP_GRAB_BAG:
666 setGrabBagItem(*pValues);
667 break;
668 case HANDLE_SAVE_THUMBNAIL:
669 {
670 if ((*pValues).getValueType() != cppu::UnoType<bool>::get())
671 throw IllegalArgumentException();
672 bool bThumbnail = false;
673 if (*pValues >>= bThumbnail)
674 pDocSh->SetUseThumbnailSave(bThumbnail);
675 }
676 break;
677 }
678 }
679
680 pDocSh->SetFormat( aFormat );
681
682 // #i67283# since about all of the above changes are likely to change
683 // the formula size we have to recalculate the vis-area now
684 pDocSh->SetVisArea( tools::Rectangle( Point(0, 0), pDocSh->GetSize() ) );
685}
686
687void SmModel::_getPropertyValues( const PropertyMapEntry **ppEntries, Any *pValue )
688{
689 SmDocShell *pDocSh = static_cast < SmDocShell * > (GetObjectShell());
690
691 if ( nullptr == pDocSh )
692 throw UnknownPropertyException();
693
694 const SmFormat & aFormat = pDocSh->GetFormat();
695
696 for (; *ppEntries; ppEntries++, pValue++ )
697 {
698 switch ( (*ppEntries)->mnHandle )
699 {
700 case HANDLE_FORMULA:
701 *pValue <<= pDocSh->GetText();
702 break;
703 case HANDLE_FONT_NAME_VARIABLES :
704 case HANDLE_FONT_NAME_FUNCTIONS :
705 case HANDLE_FONT_NAME_NUMBERS :
706 case HANDLE_FONT_NAME_TEXT :
707 case HANDLE_CUSTOM_FONT_NAME_SERIF :
708 case HANDLE_CUSTOM_FONT_NAME_SANS :
709 case HANDLE_CUSTOM_FONT_NAME_FIXED :
710 {
711 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
712 *pValue <<= rFace.GetFamilyName();
713 }
714 break;
715 case HANDLE_CUSTOM_FONT_FIXED_POSTURE:
716 case HANDLE_CUSTOM_FONT_SANS_POSTURE :
717 case HANDLE_CUSTOM_FONT_SERIF_POSTURE:
718 case HANDLE_FONT_VARIABLES_POSTURE :
719 case HANDLE_FONT_FUNCTIONS_POSTURE :
720 case HANDLE_FONT_NUMBERS_POSTURE :
721 case HANDLE_FONT_TEXT_POSTURE :
722 {
723 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
724 *pValue <<= IsItalic( rFace );
725 }
726 break;
727 case HANDLE_CUSTOM_FONT_FIXED_WEIGHT :
728 case HANDLE_CUSTOM_FONT_SANS_WEIGHT :
729 case HANDLE_CUSTOM_FONT_SERIF_WEIGHT :
730 case HANDLE_FONT_VARIABLES_WEIGHT :
731 case HANDLE_FONT_FUNCTIONS_WEIGHT :
732 case HANDLE_FONT_NUMBERS_WEIGHT :
733 case HANDLE_FONT_TEXT_WEIGHT :
734 {
735 const SmFace & rFace = aFormat.GetFont((*ppEntries)->mnMemberId);
736 *pValue <<= IsBold( rFace );
737 }
738 break;
739 case HANDLE_BASE_FONT_HEIGHT :
740 {
741 // Point!
742 *pValue <<= sal_Int16(
743 SmRoundFraction(
744 Sm100th_mmToPts(aFormat.GetBaseSize().Height())));
745 }
746 break;
747 case HANDLE_RELATIVE_FONT_HEIGHT_TEXT :
748 case HANDLE_RELATIVE_FONT_HEIGHT_INDICES :
749 case HANDLE_RELATIVE_FONT_HEIGHT_FUNCTIONS :
750 case HANDLE_RELATIVE_FONT_HEIGHT_OPERATORS :
751 case HANDLE_RELATIVE_FONT_HEIGHT_LIMITS :
752 *pValue <<= static_cast<sal_Int16>(aFormat.GetRelSize((*ppEntries)->mnMemberId));
753 break;
754
755 case HANDLE_IS_TEXT_MODE :
756 *pValue <<= aFormat.IsTextmode();
757 break;
758
759 case HANDLE_GREEK_CHAR_STYLE :
760 *pValue <<= aFormat.GetGreekCharStyle();
761 break;
762
763 case HANDLE_ALIGNMENT :
764 // SmHorAlign uses the same values as HorizontalAlignment
765 *pValue <<= static_cast<sal_Int16>(aFormat.GetHorAlign());
766 break;
767
768 case HANDLE_RELATIVE_SPACING :
769 case HANDLE_RELATIVE_LINE_SPACING :
770 case HANDLE_RELATIVE_ROOT_SPACING :
771 case HANDLE_RELATIVE_INDEX_SUPERSCRIPT :
772 case HANDLE_RELATIVE_INDEX_SUBSCRIPT :
773 case HANDLE_RELATIVE_FRACTION_NUMERATOR_HEIGHT :
774 case HANDLE_RELATIVE_FRACTION_DENOMINATOR_DEPTH:
775 case HANDLE_RELATIVE_FRACTION_BAR_EXCESS_LENGTH:
776 case HANDLE_RELATIVE_FRACTION_BAR_LINE_WEIGHT :
777 case HANDLE_RELATIVE_UPPER_LIMIT_DISTANCE :
778 case HANDLE_RELATIVE_LOWER_LIMIT_DISTANCE :
779 case HANDLE_RELATIVE_BRACKET_EXCESS_SIZE :
780 case HANDLE_RELATIVE_BRACKET_DISTANCE :
781 case HANDLE_RELATIVE_SCALE_BRACKET_EXCESS_SIZE :
782 case HANDLE_RELATIVE_MATRIX_LINE_SPACING :
783 case HANDLE_RELATIVE_MATRIX_COLUMN_SPACING :
784 case HANDLE_RELATIVE_SYMBOL_PRIMARY_HEIGHT :
785 case HANDLE_RELATIVE_SYMBOL_MINIMUM_HEIGHT :
786 case HANDLE_RELATIVE_OPERATOR_EXCESS_SIZE :
787 case HANDLE_RELATIVE_OPERATOR_SPACING :
788 case HANDLE_LEFT_MARGIN :
789 case HANDLE_RIGHT_MARGIN :
790 case HANDLE_TOP_MARGIN :
791 case HANDLE_BOTTOM_MARGIN :
792 *pValue <<= static_cast<sal_Int16>(aFormat.GetDistance((*ppEntries)->mnMemberId));
793 break;
794 case HANDLE_IS_SCALE_ALL_BRACKETS :
795 *pValue <<= aFormat.IsScaleNormalBrackets();
796 break;
797 case HANDLE_PRINTER_NAME:
798 {
799 SfxPrinter *pPrinter = pDocSh->GetPrinter ( );
800 *pValue <<= pPrinter ? pPrinter->GetName() : OUString();
801 }
802 break;
803 case HANDLE_PRINTER_SETUP:
804 {
805 SfxPrinter *pPrinter = pDocSh->GetPrinter ();
806 if (pPrinter)
807 {
808 SvMemoryStream aStream;
809 pPrinter->Store( aStream );
810 sal_uInt32 nSize = aStream.TellEnd();
811 aStream.Seek ( STREAM_SEEK_TO_BEGIN0L );
812 Sequence < sal_Int8 > aSequence ( nSize );
813 aStream.ReadBytes(aSequence.getArray(), nSize);
814 *pValue <<= aSequence;
815 }
816 }
817 break;
818 case HANDLE_SYMBOLS:
819 case HANDLE_USED_SYMBOLS:
820 {
821 const bool bUsedSymbolsOnly = (*ppEntries)->mnHandle == HANDLE_USED_SYMBOLS;
822 const std::set< OUString > &rUsedSymbols = pDocSh->GetUsedSymbols();
823
824 // this is get
825 SmModule *pp = SM_MOD()( static_cast<SmModule*>(SfxApplication::GetModule(SfxToolsModule
::Math)) )
;
826 const SmSymbolManager &rManager = pp->GetSymbolManager();
827 vector < const SmSym * > aVector;
828
829 const SymbolPtrVec_t aSymbols( rManager.GetSymbols() );
830 for (const SmSym* pSymbol : aSymbols)
831 {
832 if (pSymbol && !pSymbol->IsPredefined() &&
833 (!bUsedSymbolsOnly ||
834 rUsedSymbols.find( pSymbol->GetName() ) != rUsedSymbols.end()))
835 aVector.push_back ( pSymbol );
836 }
837 Sequence < SymbolDescriptor > aSequence ( aVector.size() );
838 SymbolDescriptor * pDescriptor = aSequence.getArray();
839
840 for (const SmSym* pSymbol : aVector)
841 {
842 pDescriptor->sName = pSymbol->GetName();
843 pDescriptor->sExportName = pSymbol->GetExportName();
844 pDescriptor->sSymbolSet = pSymbol->GetSymbolSetName();
845 pDescriptor->nCharacter = static_cast < sal_Int32 > (pSymbol->GetCharacter());
846
847 vcl::Font rFont = pSymbol->GetFace();
848 pDescriptor->sFontName = rFont.GetFamilyName();
849 pDescriptor->nCharSet = sal::static_int_cast< sal_Int16 >(rFont.GetCharSet());
850 pDescriptor->nFamily = sal::static_int_cast< sal_Int16 >(rFont.GetFamilyType());
851 pDescriptor->nPitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
852 pDescriptor->nWeight = sal::static_int_cast< sal_Int16 >(rFont.GetWeight());
853 pDescriptor->nItalic = sal::static_int_cast< sal_Int16 >(rFont.GetItalic());
854 pDescriptor++;
855 }
856 *pValue <<= aSequence;
857 }
858 break;
859 case HANDLE_BASIC_LIBRARIES:
860 *pValue <<= pDocSh->GetBasicContainer();
861 break;
862 case HANDLE_DIALOG_LIBRARIES:
863 *pValue <<= pDocSh->GetDialogContainer();
864 break;
865 case HANDLE_RUNTIME_UID:
866 *pValue <<= getRuntimeUID();
867 break;
868 // #i33095# Security Options
869 case HANDLE_LOAD_READONLY :
870 {
871 *pValue <<= pDocSh->IsLoadReadonly();
872 break;
873 }
874 // #i972#
875 case HANDLE_BASELINE:
876 {
877 if ( !pDocSh->GetFormulaTree() )
878 pDocSh->Parse();
879 if ( pDocSh->GetFormulaTree() )
880 {
881 pDocSh->ArrangeFormula();
882
883 *pValue <<= static_cast<sal_Int32>( pDocSh->GetFormulaTree()->GetFormulaBaseline() );
884 }
885 break;
886 }
887 case HANDLE_INTEROP_GRAB_BAG:
888 getGrabBagItem(*pValue);
889 break;
890 case HANDLE_SAVE_THUMBNAIL:
891 {
892 *pValue <<= pDocSh->IsUseThumbnailSave();
893 }
894 break;
895 }
896 }
897}
898
899
900sal_Int32 SAL_CALL SmModel::getRendererCount(
901 const uno::Any& /*rSelection*/,
902 const uno::Sequence< beans::PropertyValue >& /*xOptions*/ )
903{
904 return 1;
905}
906
907
908static Size lcl_GuessPaperSize()
909{
910 Size aRes;
911 const LocaleDataWrapper& rLocWrp( AllSettings().GetLocaleDataWrapper() );
912 if( MeasurementSystem::Metric == rLocWrp.getMeasurementSystemEnum() )
913 {
914 // in 100th mm
915 PaperInfo aInfo( PAPER_A4 );
916 aRes.setWidth( aInfo.getWidth() );
917 aRes.setHeight( aInfo.getHeight() );
918 }
919 else
920 {
921 // in 100th mm
922 PaperInfo aInfo( PAPER_LETTER );
923 aRes.setWidth( aInfo.getWidth() );
924 aRes.setHeight( aInfo.getHeight() );
925 }
926 return aRes;
927}
928
929uno::Sequence< beans::PropertyValue > SAL_CALL SmModel::getRenderer(
930 sal_Int32 nRenderer,
931 const uno::Any& /*rSelection*/,
932 const uno::Sequence< beans::PropertyValue >& /*rxOptions*/ )
933{
934 SolarMutexGuard aGuard;
935
936 if (0 != nRenderer)
937 throw IllegalArgumentException();
938
939 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
940 if (!pDocSh)
941 throw RuntimeException();
942
943 SmPrinterAccess aPrinterAccess( *pDocSh );
944 Printer *pPrinter = aPrinterAccess.GetPrinter();
945 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
946
947 // if paper size is 0 (usually if no 'real' printer is found),
948 // guess the paper size
949 if (aPrtPaperSize.IsEmpty())
950 aPrtPaperSize = lcl_GuessPaperSize();
951 awt::Size aPageSize( aPrtPaperSize.Width(), aPrtPaperSize.Height() );
952
953 uno::Sequence< beans::PropertyValue > aRenderer(1);
954 PropertyValue &rValue = aRenderer.getArray()[0];
955 rValue.Name = "PageSize";
956 rValue.Value <<= aPageSize;
957
958 if (!m_pPrintUIOptions)
959 m_pPrintUIOptions.reset(new SmPrintUIOptions);
960 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
961
962 return aRenderer;
963}
964
965void SAL_CALL SmModel::render(
966 sal_Int32 nRenderer,
967 const uno::Any& rSelection,
968 const uno::Sequence< beans::PropertyValue >& rxOptions )
969{
970 SolarMutexGuard aGuard;
971
972 if (0 != nRenderer)
973 throw IllegalArgumentException();
974
975 SmDocShell *pDocSh = static_cast < SmDocShell * >( GetObjectShell() );
976 if (!pDocSh)
977 throw RuntimeException();
978
979 // get device to be rendered in
980 uno::Reference< awt::XDevice > xRenderDevice;
981 for (const auto& rxOption : rxOptions)
982 {
983 if( rxOption.Name == "RenderDevice" )
984 rxOption.Value >>= xRenderDevice;
985 }
986
987 if (!xRenderDevice.is())
988 return;
989
990 VCLXDevice* pDevice = comphelper::getUnoTunnelImplementation<VCLXDevice>( xRenderDevice );
991 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice()
992 : VclPtr< OutputDevice >();
993 if (!pOut)
994 throw RuntimeException();
995
996 pOut->SetMapMode(MapMode(MapUnit::Map100thMM));
997
998 uno::Reference< frame::XModel > xModel;
999 rSelection >>= xModel;
1000 if (xModel != pDocSh->GetModel())
1001 return;
1002
1003 //!! when called via API we may not have an active view
1004 //!! thus we go and look for a view that can be used.
1005 SfxViewShell* pViewSh = SfxViewShell::GetFirst( false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1006 while (pViewSh && pViewSh->GetObjectShell() != pDocSh)
1007 pViewSh = SfxViewShell::GetNext( *pViewSh, false /* search non-visible views as well*/, checkSfxViewShell<SmViewShell> );
1008 SmViewShell *pView = dynamic_cast< SmViewShell *>( pViewSh );
1009 SAL_WARN_IF( !pView, "starmath", "SmModel::render : no SmViewShell found" )do { if (true && (!pView)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "starmath")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "SmModel::render : no SmViewShell found"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"
), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "1009" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "SmModel::render : no SmViewShell found"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "SmModel::render : no SmViewShell found"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "1009" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SmModel::render : no SmViewShell found") == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"
), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "1009" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "SmModel::render : no SmViewShell found"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "SmModel::render : no SmViewShell found"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/unomodel.cxx"
":" "1009" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1010
1011 if (!pView)
1012 return;
1013
1014 SmPrinterAccess aPrinterAccess( *pDocSh );
1015 Printer *pPrinter = aPrinterAccess.GetPrinter();
1016
1017 Size aPrtPaperSize ( pPrinter->GetPaperSize() );
1018 Size aOutputSize ( pPrinter->GetOutputSize() );
1019 Point aPrtPageOffset( pPrinter->GetPageOffset() );
1020
1021 // no real printer ??
1022 if (aPrtPaperSize.IsEmpty())
1023 {
1024 aPrtPaperSize = lcl_GuessPaperSize();
1025 // factors from Windows DIN A4
1026 aOutputSize = Size( static_cast<long>(aPrtPaperSize.Width() * 0.941),
1027 static_cast<long>(aPrtPaperSize.Height() * 0.961));
1028 aPrtPageOffset = Point( static_cast<long>(aPrtPaperSize.Width() * 0.0250),
1029 static_cast<long>(aPrtPaperSize.Height() * 0.0214));
1030 }
1031 tools::Rectangle OutputRect( Point(), aOutputSize );
1032
1033
1034 // set minimum top and bottom border
1035 if (aPrtPageOffset.Y() < 2000)
1036 OutputRect.AdjustTop(2000 - aPrtPageOffset.Y() );
1037 if ((aPrtPaperSize.Height() - (aPrtPageOffset.Y() + OutputRect.Bottom())) < 2000)
1038 OutputRect.AdjustBottom( -(2000 - (aPrtPaperSize.Height() -
1039 (aPrtPageOffset.Y() + OutputRect.Bottom()))) );
1040
1041 // set minimum left and right border
1042 if (aPrtPageOffset.X() < 2500)
1043 OutputRect.AdjustLeft(2500 - aPrtPageOffset.X() );
1044 if ((aPrtPaperSize.Width() - (aPrtPageOffset.X() + OutputRect.Right())) < 1500)
1045 OutputRect.AdjustRight( -(1500 - (aPrtPaperSize.Width() -
1046 (aPrtPageOffset.X() + OutputRect.Right()))) );
1047
1048 if (!m_pPrintUIOptions)
1049 m_pPrintUIOptions.reset(new SmPrintUIOptions);
1050 m_pPrintUIOptions->processProperties( rxOptions );
1051
1052 pView->Impl_Print( *pOut, *m_pPrintUIOptions, OutputRect );
1053
1054 // release SmPrintUIOptions when everything is done.
1055 // That way, when SmPrintUIOptions is needed again it will read the latest configuration settings in its c-tor.
1056 if (m_pPrintUIOptions->getBoolValue( "IsLastPage" ))
1057 {
1058 m_pPrintUIOptions.reset();
1059 }
1060}
1061
1062void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xParent)
1063{
1064 SolarMutexGuard aGuard;
1065 SfxBaseModel::setParent( xParent );
1066 if (SfxObjectShell* pDoc = SfxObjectShell::GetShellFromComponent(xParent))
1067 GetObjectShell()->OnDocumentPrinterChanged(pDoc->GetDocumentPrinter());
1068}
1069
1070void SmModel::writeFormulaOoxml(
1071 ::sax_fastparser::FSHelperPtr const pSerializer,
1072 oox::core::OoxmlVersion const version,
1073 oox::drawingml::DocumentType const documentType, sal_Int8 nAlign)
1074{
1075 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType, nAlign);
1076}
1077
1078void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
1079{
1080 static_cast<SmDocShell*>(GetObjectShell())->writeFormulaRtf(rBuffer, nEncoding);
1081}
1082
1083void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
1084{
1085 static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
1086}
1087
1088Size SmModel::getFormulaSize() const
1089{
1090 return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
1091}
1092
1093/* 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;
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 ;-)
19
Calling 'Reference::clear'
26
Returning; memory was released
205 if (aTmp.get()) {
27
Calling 'Reference::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 )
14
Memory is allocated
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)
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)
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)
113 m_pBody->release();
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
19.1
Field 'm_pBody' is non-null
19.1
Field 'm_pBody' is non-null
19.1
Field 'm_pBody' is non-null
19.1
Field 'm_pBody' is non-null
)
20
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
21
Calling 'VclReferenceBase::release'
25
Returning; memory was released
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;
28
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)
22
Assuming the condition is true
23
Taking true branch
40 delete this;
24
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