File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <svl/zforlist.hxx> | |||
21 | ||||
22 | #include "DataBrowser.hxx" | |||
23 | #include "DataBrowserModel.hxx" | |||
24 | #include <strings.hrc> | |||
25 | #include <DataSeriesHelper.hxx> | |||
26 | #include <DiagramHelper.hxx> | |||
27 | #include <CommonConverters.hxx> | |||
28 | #include <NumberFormatterWrapper.hxx> | |||
29 | #include <servicenames_charttypes.hxx> | |||
30 | #include <ResId.hxx> | |||
31 | #include <bitmaps.hlst> | |||
32 | #include <helpids.h> | |||
33 | ||||
34 | #include <vcl/weld.hxx> | |||
35 | #include <vcl/settings.hxx> | |||
36 | #include <vcl/svapp.hxx> | |||
37 | #include <vcl/virdev.hxx> | |||
38 | #include <rtl/math.hxx> | |||
39 | #include <o3tl/safeint.hxx> | |||
40 | #include <osl/diagnose.h> | |||
41 | #include <toolkit/helper/vclunohelper.hxx> | |||
42 | ||||
43 | #include <com/sun/star/chart2/XChartDocument.hpp> | |||
44 | #include <com/sun/star/chart2/XChartType.hpp> | |||
45 | #include <com/sun/star/container/XIndexReplace.hpp> | |||
46 | ||||
47 | #include <algorithm> | |||
48 | ||||
49 | ||||
50 | using namespace ::com::sun::star; | |||
51 | using ::com::sun::star::uno::Reference; | |||
52 | ||||
53 | using namespace ::svt; | |||
54 | ||||
55 | namespace | |||
56 | { | |||
57 | /* BrowserMode::COLUMNSELECTION : single cells may be selected rather than only | |||
58 | entire rows | |||
59 | BrowserMode::(H|V)LINES : show horizontal or vertical grid-lines | |||
60 | BrowserMode::AUTO_(H|V)SCROLL : scroll automated horizontally or vertically when | |||
61 | cursor is moved beyond the edge of the dialog | |||
62 | BrowserMode::HIDESELECT : Do not mark the current row with selection color | |||
63 | (usually blue) | |||
64 | ! BrowserMode::HIDECURSOR would prevent flickering in edit fields, but navigating | |||
65 | with shift up/down, and entering non-editable cells would be problematic, | |||
66 | e.g. the first cell, or when being in read-only mode | |||
67 | */ | |||
68 | const BrowserMode BrowserStdFlags = BrowserMode::COLUMNSELECTION | | |||
69 | BrowserMode::HLINES | BrowserMode::VLINES | | |||
70 | BrowserMode::AUTO_HSCROLL | BrowserMode::AUTO_VSCROLL | | |||
71 | BrowserMode::HIDESELECT; | |||
72 | ||||
73 | sal_Int32 lcl_getRowInData( long nRow ) | |||
74 | { | |||
75 | return static_cast< sal_Int32 >( nRow ); | |||
76 | } | |||
77 | ||||
78 | sal_Int32 lcl_getColumnInData( sal_uInt16 nCol ) | |||
79 | { | |||
80 | return static_cast< sal_Int32 >( nCol ) - 1; | |||
81 | } | |||
82 | ||||
83 | } // anonymous namespace | |||
84 | ||||
85 | namespace chart | |||
86 | { | |||
87 | ||||
88 | namespace impl | |||
89 | { | |||
90 | ||||
91 | class SeriesHeaderEdit | |||
92 | { | |||
93 | public: | |||
94 | explicit SeriesHeaderEdit(std::unique_ptr<weld::Entry> xControl); | |||
95 | ||||
96 | void setStartColumn( sal_Int32 nStartColumn ); | |||
97 | sal_Int32 getStartColumn() const { return m_nStartColumn;} | |||
98 | void SetShowWarningBox( bool bShowWarning ); | |||
99 | ||||
100 | OUString GetText() const { return m_xControl->get_text(); } | |||
101 | void SetText(const OUString& rText) { m_xControl->set_text(rText); } | |||
102 | ||||
103 | bool HasFocus() const { return m_xControl->has_focus(); } | |||
104 | ||||
105 | void set_size_request(int nWidth, int nHeight) { m_xControl->set_size_request(nWidth, nHeight); } | |||
106 | void set_margin_left(int nLeft) { m_xControl->set_margin_left(nLeft); } | |||
107 | ||||
108 | void SetModifyHdl(const Link<SeriesHeaderEdit&,void>& rLink) { m_aModifyHdl = rLink; } | |||
109 | void SetGetFocusHdl(const Link<SeriesHeaderEdit&,void>& rLink) { m_aFocusInHdl = rLink; } | |||
110 | ||||
111 | private: | |||
112 | DECL_LINK(NameEdited, weld::Entry&, void)static void LinkStubNameEdited(void *, weld::Entry&); void NameEdited(weld::Entry&); | |||
113 | DECL_LINK(NameFocusIn, weld::Widget&, void)static void LinkStubNameFocusIn(void *, weld::Widget&); void NameFocusIn(weld::Widget&); | |||
114 | DECL_LINK(MousePressHdl, const MouseEvent&, bool)static bool LinkStubMousePressHdl(void *, const MouseEvent& ); bool MousePressHdl(const MouseEvent&); | |||
115 | ||||
116 | std::unique_ptr<weld::Entry> m_xControl; | |||
117 | Link<SeriesHeaderEdit&,void> m_aModifyHdl; | |||
118 | Link<SeriesHeaderEdit&,void> m_aFocusInHdl; | |||
119 | sal_Int32 m_nStartColumn; | |||
120 | bool m_bShowWarningBox; | |||
121 | }; | |||
122 | ||||
123 | SeriesHeaderEdit::SeriesHeaderEdit(std::unique_ptr<weld::Entry> xControl) | |||
124 | : m_xControl(std::move(xControl)) | |||
125 | , m_nStartColumn(0) | |||
126 | , m_bShowWarningBox(false) | |||
127 | { | |||
128 | m_xControl->set_help_id(HID_SCH_DATA_SERIES_LABEL"CHART2_HID_SCH_DATA_SERIES_LABEL"); | |||
129 | m_xControl->connect_changed(LINK(this, SeriesHeaderEdit, NameEdited)::tools::detail::makeLink( ::tools::detail::castTo<SeriesHeaderEdit *>(this), &SeriesHeaderEdit::LinkStubNameEdited)); | |||
130 | m_xControl->connect_focus_in(LINK(this, SeriesHeaderEdit, NameFocusIn)::tools::detail::makeLink( ::tools::detail::castTo<SeriesHeaderEdit *>(this), &SeriesHeaderEdit::LinkStubNameFocusIn)); | |||
131 | m_xControl->connect_mouse_press(LINK(this, SeriesHeaderEdit, MousePressHdl)::tools::detail::makeLink( ::tools::detail::castTo<SeriesHeaderEdit *>(this), &SeriesHeaderEdit::LinkStubMousePressHdl)); | |||
132 | } | |||
133 | ||||
134 | IMPL_LINK_NOARG(SeriesHeaderEdit, NameEdited, weld::Entry&, void)void SeriesHeaderEdit::LinkStubNameEdited(void * instance, weld ::Entry& data) { return static_cast<SeriesHeaderEdit * >(instance)->NameEdited(data); } void SeriesHeaderEdit:: NameEdited(__attribute__ ((unused)) weld::Entry&) | |||
135 | { | |||
136 | m_aModifyHdl.Call(*this); | |||
137 | } | |||
138 | ||||
139 | IMPL_LINK_NOARG(SeriesHeaderEdit, NameFocusIn, weld::Widget&, void)void SeriesHeaderEdit::LinkStubNameFocusIn(void * instance, weld ::Widget& data) { return static_cast<SeriesHeaderEdit * >(instance)->NameFocusIn(data); } void SeriesHeaderEdit ::NameFocusIn(__attribute__ ((unused)) weld::Widget&) | |||
140 | { | |||
141 | m_aFocusInHdl.Call(*this); | |||
142 | } | |||
143 | ||||
144 | void SeriesHeaderEdit::setStartColumn( sal_Int32 nStartColumn ) | |||
145 | { | |||
146 | m_nStartColumn = nStartColumn; | |||
147 | } | |||
148 | ||||
149 | void SeriesHeaderEdit::SetShowWarningBox( bool bShowWarning ) | |||
150 | { | |||
151 | m_bShowWarningBox = bShowWarning; | |||
152 | } | |||
153 | ||||
154 | IMPL_LINK_NOARG(SeriesHeaderEdit, MousePressHdl, const MouseEvent&, bool)bool SeriesHeaderEdit::LinkStubMousePressHdl(void * instance, const MouseEvent& data) { return static_cast<SeriesHeaderEdit *>(instance)->MousePressHdl(data); } bool SeriesHeaderEdit ::MousePressHdl(__attribute__ ((unused)) const MouseEvent& ) | |||
155 | { | |||
156 | if (m_bShowWarningBox) | |||
157 | { | |||
158 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xControl.get(), | |||
159 | VclMessageType::Warning, VclButtonsType::Ok, | |||
160 | SchResId(STR_INVALID_NUMBERreinterpret_cast<char const *>("STR_INVALID_NUMBER" "\004" u8"Numbers are required. Check your input.")))); | |||
161 | xWarn->run(); | |||
162 | } | |||
163 | ||||
164 | return false; | |||
165 | } | |||
166 | ||||
167 | class SeriesHeader | |||
168 | { | |||
169 | public: | |||
170 | explicit SeriesHeader(weld::Container* pParent, weld::Container* pColorParent); | |||
171 | ~SeriesHeader(); | |||
172 | ||||
173 | void SetColor( const Color & rCol ); | |||
174 | void SetPos(); | |||
175 | void SetWidth( sal_Int32 nWidth ); | |||
176 | void SetChartType( const Reference< chart2::XChartType > & xChartType, | |||
177 | bool bSwapXAndYAxis ); | |||
178 | void SetSeriesName( const OUString & rName ); | |||
179 | void SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ); | |||
180 | ||||
181 | void SetPixelWidth( sal_Int32 nWidth ); | |||
182 | ||||
183 | sal_Int32 GetStartColumn() const { return m_nStartCol;} | |||
184 | sal_Int32 GetEndColumn() const { return m_nEndCol;} | |||
185 | ||||
186 | static const sal_Int32 nSymbolHeight = 10; | |||
187 | static const sal_Int32 nSymbolDistance = 2; | |||
188 | ||||
189 | static sal_Int32 GetRelativeAppFontXPosForNameField() { return nSymbolHeight + nSymbolDistance; } | |||
190 | ||||
191 | void Show(); | |||
192 | void Hide(); | |||
193 | ||||
194 | /** call this before destroying the class. This notifies the listeners to | |||
195 | changes of the edit field for the series name. | |||
196 | */ | |||
197 | void applyChanges(); | |||
198 | ||||
199 | void SetGetFocusHdl(const Link<SeriesHeaderEdit&,void>& rLink); | |||
200 | ||||
201 | void SetEditChangedHdl( const Link<SeriesHeaderEdit&,void> & rLink ); | |||
202 | ||||
203 | bool HasFocus() const; | |||
204 | ||||
205 | private: | |||
206 | Timer m_aUpdateDataTimer; | |||
207 | ||||
208 | std::unique_ptr<weld::Builder> m_xBuilder1; | |||
209 | std::unique_ptr<weld::Builder> m_xBuilder2; | |||
210 | ||||
211 | weld::Container* m_pParent; | |||
212 | weld::Container* m_pColorParent; | |||
213 | ||||
214 | std::unique_ptr<weld::Container> m_xContainer1; | |||
215 | std::unique_ptr<weld::Container> m_xContainer2; | |||
216 | std::unique_ptr<weld::Image> m_spSymbol; | |||
217 | std::unique_ptr<SeriesHeaderEdit> m_spSeriesName; | |||
218 | std::unique_ptr<weld::Image> m_spColorBar; | |||
219 | VclPtr< OutputDevice> m_xDevice; | |||
220 | Link<SeriesHeaderEdit&,void> m_aChangeLink; | |||
221 | Color m_aColor; | |||
222 | ||||
223 | void notifyChanges(); | |||
224 | DECL_LINK( ImplUpdateDataHdl, Timer*, void )static void LinkStubImplUpdateDataHdl(void *, Timer*); void ImplUpdateDataHdl (Timer*); | |||
225 | DECL_LINK( SeriesNameEdited, SeriesHeaderEdit&, void )static void LinkStubSeriesNameEdited(void *, SeriesHeaderEdit &); void SeriesNameEdited(SeriesHeaderEdit&); | |||
226 | ||||
227 | static OUString GetChartTypeImage( | |||
228 | const Reference< chart2::XChartType > & xChartType, | |||
229 | bool bSwapXAndYAxis | |||
230 | ); | |||
231 | ||||
232 | sal_Int32 m_nStartCol, m_nEndCol; | |||
233 | sal_Int32 m_nWidth; | |||
234 | bool m_bSeriesNameChangePending; | |||
235 | }; | |||
236 | ||||
237 | SeriesHeader::SeriesHeader(weld::Container* pParent, weld::Container* pColorParent) | |||
238 | : m_aUpdateDataTimer("UpdateDataTimer") | |||
239 | , m_xBuilder1(Application::CreateBuilder(pParent, "modules/schart/ui/columnfragment.ui")) | |||
240 | , m_xBuilder2(Application::CreateBuilder(pColorParent, "modules/schart/ui/imagefragment.ui")) | |||
241 | , m_pParent(pParent) | |||
242 | , m_pColorParent(pColorParent) | |||
243 | , m_xContainer1(m_xBuilder1->weld_container("container")) | |||
244 | , m_xContainer2(m_xBuilder2->weld_container("container")) | |||
245 | , m_spSymbol(m_xBuilder1->weld_image("image")) | |||
246 | , m_spSeriesName(new SeriesHeaderEdit(m_xBuilder1->weld_entry("entry"))) | |||
247 | , m_spColorBar(m_xBuilder2->weld_image("image")) | |||
248 | , m_xDevice(Application::GetDefaultDevice()) | |||
249 | , m_nStartCol( 0 ) | |||
250 | , m_nEndCol( 0 ) | |||
251 | , m_nWidth( 42 ) | |||
252 | , m_bSeriesNameChangePending( false ) | |||
253 | { | |||
254 | m_aUpdateDataTimer.SetInvokeHandler(LINK(this, SeriesHeader, ImplUpdateDataHdl)::tools::detail::makeLink( ::tools::detail::castTo<SeriesHeader *>(this), &SeriesHeader::LinkStubImplUpdateDataHdl)); | |||
255 | m_aUpdateDataTimer.SetDebugName( "SeriesHeader UpdateDataTimer" ); | |||
256 | m_aUpdateDataTimer.SetTimeout(4 * EDIT_UPDATEDATA_TIMEOUT350); | |||
257 | ||||
258 | m_spSeriesName->SetModifyHdl(LINK(this, SeriesHeader, SeriesNameEdited)::tools::detail::makeLink( ::tools::detail::castTo<SeriesHeader *>(this), &SeriesHeader::LinkStubSeriesNameEdited)); | |||
259 | Show(); | |||
260 | } | |||
261 | ||||
262 | SeriesHeader::~SeriesHeader() | |||
263 | { | |||
264 | m_aUpdateDataTimer.Stop(); | |||
265 | m_pParent->move(m_xContainer1.get(), nullptr); | |||
266 | m_pColorParent->move(m_xContainer2.get(), nullptr); | |||
267 | } | |||
268 | ||||
269 | void SeriesHeader::notifyChanges() | |||
270 | { | |||
271 | m_aChangeLink.Call(*m_spSeriesName); | |||
272 | m_bSeriesNameChangePending = false; | |||
273 | } | |||
274 | ||||
275 | void SeriesHeader::applyChanges() | |||
276 | { | |||
277 | if( m_bSeriesNameChangePending ) | |||
278 | { | |||
279 | notifyChanges(); | |||
280 | } | |||
281 | } | |||
282 | ||||
283 | void SeriesHeader::SetColor( const Color & rCol ) | |||
284 | { | |||
285 | m_aColor = rCol; | |||
286 | } | |||
287 | ||||
288 | void SeriesHeader::SetPos() | |||
289 | { | |||
290 | // chart type symbol | |||
291 | Size aSize( nSymbolHeight, nSymbolHeight ); | |||
292 | aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); | |||
293 | m_spSymbol->set_size_request(aSize.Width(), aSize.Height()); | |||
294 | ||||
295 | // series name edit field | |||
296 | m_spSeriesName->set_margin_left(2); | |||
297 | ||||
298 | aSize.setWidth(nSymbolHeight); | |||
299 | aSize.setHeight(12); | |||
300 | aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); | |||
301 | aSize.setWidth(m_nWidth - aSize.Width() - 2); | |||
302 | m_spSeriesName->set_size_request(aSize.Width(), aSize.Height()); | |||
303 | ||||
304 | // color bar | |||
305 | aSize.setHeight(3); | |||
306 | aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); | |||
307 | aSize.setWidth(m_nWidth); | |||
308 | m_spColorBar->set_size_request(aSize.Width(), aSize.Height()); | |||
309 | ||||
310 | auto xVirDev(m_spColorBar->create_virtual_device()); | |||
311 | xVirDev->SetOutputSizePixel(aSize); | |||
312 | xVirDev->SetFillColor(m_aColor); | |||
313 | xVirDev->SetLineColor(m_aColor); | |||
314 | xVirDev->DrawRect(tools::Rectangle(Point(0, 0), aSize)); | |||
315 | m_spColorBar->set_image(xVirDev.get()); | |||
316 | } | |||
317 | ||||
318 | void SeriesHeader::SetWidth( sal_Int32 nWidth ) | |||
319 | { | |||
320 | m_nWidth = nWidth; | |||
321 | SetPos(); | |||
322 | } | |||
323 | ||||
324 | void SeriesHeader::SetPixelWidth( sal_Int32 nWidth ) | |||
325 | { | |||
326 | SetWidth(nWidth); | |||
327 | } | |||
328 | ||||
329 | void SeriesHeader::SetChartType( | |||
330 | const Reference< chart2::XChartType > & xChartType, | |||
331 | bool bSwapXAndYAxis | |||
332 | ) | |||
333 | { | |||
334 | m_spSymbol->set_from_icon_name( GetChartTypeImage( xChartType, bSwapXAndYAxis ) ); | |||
335 | } | |||
336 | ||||
337 | void SeriesHeader::SetSeriesName( const OUString & rName ) | |||
338 | { | |||
339 | m_spSeriesName->SetText(rName); | |||
340 | } | |||
341 | ||||
342 | void SeriesHeader::SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ) | |||
343 | { | |||
344 | m_nStartCol = nStartCol; | |||
345 | m_nEndCol = std::max(nEndCol, nStartCol); | |||
346 | m_spSeriesName->setStartColumn( nStartCol ); | |||
347 | } | |||
348 | ||||
349 | void SeriesHeader::Show() | |||
350 | { | |||
351 | m_xContainer1->show(); | |||
352 | m_xContainer2->show(); | |||
353 | } | |||
354 | ||||
355 | void SeriesHeader::Hide() | |||
356 | { | |||
357 | m_xContainer1->hide(); | |||
358 | m_xContainer2->hide(); | |||
359 | } | |||
360 | ||||
361 | void SeriesHeader::SetEditChangedHdl( const Link<SeriesHeaderEdit&,void> & rLink ) | |||
362 | { | |||
363 | m_aChangeLink = rLink; | |||
364 | } | |||
365 | ||||
366 | IMPL_LINK_NOARG(SeriesHeader, ImplUpdateDataHdl, Timer*, void)void SeriesHeader::LinkStubImplUpdateDataHdl(void * instance, Timer* data) { return static_cast<SeriesHeader *>(instance )->ImplUpdateDataHdl(data); } void SeriesHeader::ImplUpdateDataHdl (__attribute__ ((unused)) Timer*) | |||
367 | { | |||
368 | notifyChanges(); | |||
369 | } | |||
370 | ||||
371 | IMPL_LINK_NOARG(SeriesHeader, SeriesNameEdited, SeriesHeaderEdit&, void)void SeriesHeader::LinkStubSeriesNameEdited(void * instance, SeriesHeaderEdit & data) { return static_cast<SeriesHeader *>(instance )->SeriesNameEdited(data); } void SeriesHeader::SeriesNameEdited (__attribute__ ((unused)) SeriesHeaderEdit&) | |||
372 | { | |||
373 | m_bSeriesNameChangePending = true; | |||
374 | m_aUpdateDataTimer.Start(); | |||
375 | } | |||
376 | ||||
377 | void SeriesHeader::SetGetFocusHdl( const Link<SeriesHeaderEdit&,void>& rLink ) | |||
378 | { | |||
379 | m_spSeriesName->SetGetFocusHdl( rLink ); | |||
380 | } | |||
381 | ||||
382 | bool SeriesHeader::HasFocus() const | |||
383 | { | |||
384 | return m_spSeriesName->HasFocus(); | |||
385 | } | |||
386 | ||||
387 | OUString SeriesHeader::GetChartTypeImage( | |||
388 | const Reference< chart2::XChartType > & xChartType, | |||
389 | bool bSwapXAndYAxis | |||
390 | ) | |||
391 | { | |||
392 | OUString aResult; | |||
393 | if( !xChartType.is()) | |||
394 | return aResult; | |||
395 | OUString aChartTypeName( xChartType->getChartType()); | |||
396 | ||||
397 | if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_AREA"com.sun.star.chart2.AreaChartType" ) | |||
398 | { | |||
399 | aResult = BMP_TYPE_AREA"chart2/res/typearea_16.png"; | |||
400 | } | |||
401 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_COLUMN"com.sun.star.chart2.ColumnChartType" ) | |||
402 | { | |||
403 | if( bSwapXAndYAxis ) | |||
404 | aResult = BMP_TYPE_BAR"chart2/res/typebar_16.png"; | |||
405 | else | |||
406 | aResult = BMP_TYPE_COLUMN"chart2/res/typecolumn_16.png"; | |||
407 | } | |||
408 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_LINE"com.sun.star.chart2.LineChartType" ) | |||
409 | { | |||
410 | aResult = BMP_TYPE_LINE"chart2/res/typepointline_16.png"; | |||
411 | } | |||
412 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER"com.sun.star.chart2.ScatterChartType" ) | |||
413 | { | |||
414 | aResult = BMP_TYPE_XY"chart2/res/typexy_16.png"; | |||
415 | } | |||
416 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_PIE"com.sun.star.chart2.PieChartType" ) | |||
417 | { | |||
418 | aResult = BMP_TYPE_PIE"chart2/res/typepie_16.png"; | |||
419 | } | |||
420 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_NET"com.sun.star.chart2.NetChartType" | |||
421 | || aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET"com.sun.star.chart2.FilledNetChartType" ) | |||
422 | { | |||
423 | aResult = BMP_TYPE_NET"chart2/res/typenet_16.png"; | |||
424 | } | |||
425 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK"com.sun.star.chart2.CandleStickChartType" ) | |||
426 | { | |||
427 | // @todo: correct image for candle-stick type | |||
428 | aResult = BMP_TYPE_STOCK"chart2/res/typestock_16.png"; | |||
429 | } | |||
430 | else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE"com.sun.star.chart2.BubbleChartType" ) | |||
431 | { | |||
432 | aResult = BMP_TYPE_BUBBLE"chart2/res/typebubble_16.png"; | |||
433 | } | |||
434 | ||||
435 | return aResult; | |||
436 | } | |||
437 | ||||
438 | } // namespace impl | |||
439 | ||||
440 | namespace | |||
441 | { | |||
442 | ||||
443 | /** returns false, if no header as the focus. | |||
444 | ||||
445 | If a header has the focus, true is returned and the index of the header | |||
446 | with focus is set at pIndex if pOutIndex is not 0. | |||
447 | */ | |||
448 | bool lcl_SeriesHeaderHasFocus( | |||
449 | const std::vector< std::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader, | |||
450 | sal_Int32 * pOutIndex = nullptr ) | |||
451 | { | |||
452 | sal_Int32 nIndex = 0; | |||
453 | for (auto const& elem : rSeriesHeader) | |||
454 | { | |||
455 | if(elem->HasFocus()) | |||
456 | { | |||
457 | if( pOutIndex ) | |||
458 | *pOutIndex = nIndex; | |||
459 | return true; | |||
460 | } | |||
461 | ++nIndex; | |||
462 | } | |||
463 | return false; | |||
464 | } | |||
465 | ||||
466 | sal_Int32 lcl_getColumnInDataOrHeader( | |||
467 | sal_uInt16 nCol, const std::vector< std::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader ) | |||
468 | { | |||
469 | sal_Int32 nColIdx = 0; | |||
470 | bool bHeaderHasFocus( lcl_SeriesHeaderHasFocus( rSeriesHeader, &nColIdx )); | |||
471 | ||||
472 | if( bHeaderHasFocus ) | |||
473 | nColIdx = lcl_getColumnInData( static_cast< sal_uInt16 >( rSeriesHeader[nColIdx]->GetStartColumn())); | |||
474 | else | |||
475 | nColIdx = lcl_getColumnInData( nCol ); | |||
476 | ||||
477 | return nColIdx; | |||
478 | } | |||
479 | ||||
480 | } // anonymous namespace | |||
481 | ||||
482 | DataBrowser::DataBrowser(const css::uno::Reference<css::awt::XWindow> &rParent, | |||
483 | weld::Container* pColumns, weld::Container* pColors) : | |||
484 | ::svt::EditBrowseBox(VCLUnoHelper::GetWindow(rParent), | |||
485 | EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::HANDLE_COLUMN_TEXT, | |||
486 | WB_BORDER | WB_TABSTOP, BrowserStdFlags ), | |||
487 | m_nSeekRow( 0 ), | |||
488 | m_bIsReadOnly( false ), | |||
489 | m_bDataValid( true ), | |||
490 | m_aNumberEditField(VclPtr<FormattedControl>::Create(&EditBrowseBox::GetDataWindow(), false)), | |||
491 | m_aTextEditField(VclPtr<EditControl>::Create(&EditBrowseBox::GetDataWindow())), | |||
492 | m_pColumnsWin(pColumns), | |||
493 | m_pColorsWin(pColors), | |||
494 | m_rNumberEditController( new ::svt::FormattedFieldCellController( m_aNumberEditField.get() )), | |||
495 | m_rTextEditController( new ::svt::EditCellController( m_aTextEditField.get() )) | |||
496 | { | |||
497 | double fNan; | |||
498 | ::rtl::math::setNan( & fNan ); | |||
499 | Formatter& rFormatter = m_aNumberEditField->get_formatter(); | |||
500 | rFormatter.SetDefaultValue( fNan ); | |||
501 | rFormatter.TreatAsNumber( true ); | |||
502 | RenewTable(); | |||
503 | } | |||
504 | ||||
505 | DataBrowser::~DataBrowser() | |||
506 | { | |||
507 | disposeOnce(); | |||
508 | } | |||
509 | ||||
510 | void DataBrowser::dispose() | |||
511 | { | |||
512 | m_aSeriesHeaders.clear(); | |||
513 | m_aNumberEditField.disposeAndClear(); | |||
514 | m_aTextEditField.disposeAndClear(); | |||
| ||||
515 | ::svt::EditBrowseBox::dispose(); | |||
516 | } | |||
517 | ||||
518 | bool DataBrowser::MayInsertRow() const | |||
519 | { | |||
520 | return ! IsReadOnly() | |||
521 | && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )); | |||
522 | } | |||
523 | ||||
524 | bool DataBrowser::MayInsertColumn() const | |||
525 | { | |||
526 | return ! IsReadOnly(); | |||
527 | } | |||
528 | ||||
529 | bool DataBrowser::MayDeleteRow() const | |||
530 | { | |||
531 | return ! IsReadOnly() | |||
532 | && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) | |||
533 | && ( GetCurRow() >= 0 ) | |||
534 | && ( GetRowCount() > 1 ); | |||
535 | } | |||
536 | ||||
537 | bool DataBrowser::MayDeleteColumn() const | |||
538 | { | |||
539 | // if a series header has the focus | |||
540 | if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) | |||
541 | return true; | |||
542 | ||||
543 | return ! IsReadOnly() | |||
544 | && ( GetCurColumnId() > 1 ) | |||
545 | && ( ColCount() > 2 ); | |||
546 | } | |||
547 | ||||
548 | bool DataBrowser::MayMoveUpRows() const | |||
549 | { | |||
550 | return ! IsReadOnly() | |||
551 | && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) | |||
552 | && ( GetCurRow() > 0 ) | |||
553 | && ( GetCurRow() <= GetRowCount() - 1 ); | |||
554 | } | |||
555 | ||||
556 | bool DataBrowser::MayMoveDownRows() const | |||
557 | { | |||
558 | return ! IsReadOnly() | |||
559 | && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) | |||
560 | && ( GetCurRow() >= 0 ) | |||
561 | && ( GetCurRow() < GetRowCount() - 1 ); | |||
562 | } | |||
563 | ||||
564 | bool DataBrowser::MayMoveLeftColumns() const | |||
565 | { | |||
566 | // if a series header (except the last one) has the focus | |||
567 | { | |||
568 | sal_Int32 nColIndex(0); | |||
569 | if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex )) | |||
570 | return (o3tl::make_unsigned( nColIndex ) <= (m_aSeriesHeaders.size() - 1)) && (static_cast< sal_uInt32 >( nColIndex ) != 0); | |||
571 | } | |||
572 | ||||
573 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
574 | return ! IsReadOnly() | |||
575 | && ( nColIdx > 1 ) | |||
576 | && ( nColIdx <= ColCount() - 2 ) | |||
577 | && m_apDataBrowserModel | |||
578 | && !m_apDataBrowserModel->isCategoriesColumn( nColIdx ); | |||
579 | } | |||
580 | ||||
581 | bool DataBrowser::MayMoveRightColumns() const | |||
582 | { | |||
583 | // if a series header (except the last one) has the focus | |||
584 | { | |||
585 | sal_Int32 nColIndex(0); | |||
586 | if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex )) | |||
587 | return (o3tl::make_unsigned( nColIndex ) < (m_aSeriesHeaders.size() - 1)); | |||
588 | } | |||
589 | ||||
590 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
591 | return ! IsReadOnly() | |||
592 | && ( nColIdx > 0 ) | |||
593 | && ( nColIdx < ColCount()-2 ) | |||
594 | && m_apDataBrowserModel | |||
595 | && !m_apDataBrowserModel->isCategoriesColumn( nColIdx ); | |||
596 | } | |||
597 | ||||
598 | void DataBrowser::clearHeaders() | |||
599 | { | |||
600 | for( const auto& spHeader : m_aSeriesHeaders ) | |||
601 | spHeader->applyChanges(); | |||
602 | m_aSeriesHeaders.clear(); | |||
603 | } | |||
604 | ||||
605 | void DataBrowser::RenewTable() | |||
606 | { | |||
607 | if (!m_apDataBrowserModel) | |||
608 | return; | |||
609 | ||||
610 | long nOldRow = GetCurRow(); | |||
611 | sal_uInt16 nOldColId = GetCurColumnId(); | |||
612 | ||||
613 | bool bLastUpdateMode = GetUpdateMode(); | |||
614 | SetUpdateMode( false ); | |||
615 | ||||
616 | if( IsModified() ) | |||
617 | SaveModified(); | |||
618 | ||||
619 | DeactivateCell(); | |||
620 | ||||
621 | RemoveColumns(); | |||
622 | RowRemoved( 1, GetRowCount() ); | |||
623 | ||||
624 | // for row numbers | |||
625 | InsertHandleColumn( static_cast< sal_uInt16 >( | |||
626 | GetDataWindow().LogicToPixel( Size( 42, 0 )).getWidth() )); | |||
627 | ||||
628 | OUString aDefaultSeriesName(SchResId(STR_COLUMN_LABELreinterpret_cast<char const *>("STR_COLUMN_LABEL" "\004" u8"Column %COLUMNNUMBER"))); | |||
629 | replaceParamterInString( aDefaultSeriesName, "%COLUMNNUMBER", OUString::number( 24 ) ); | |||
630 | sal_Int32 nColumnWidth = GetDataWindow().GetTextWidth( aDefaultSeriesName ) | |||
631 | + GetDataWindow().LogicToPixel(Point(8 + impl::SeriesHeader::GetRelativeAppFontXPosForNameField(), 0), MapMode(MapUnit::MapAppFont)).X(); | |||
632 | sal_Int32 nColumnCount = m_apDataBrowserModel->getColumnCount(); | |||
633 | // nRowCount is a member of a base class | |||
634 | sal_Int32 nRowCountLocal = m_apDataBrowserModel->getMaxRowCount(); | |||
635 | for( sal_Int32 nColIdx=1; nColIdx<=nColumnCount; ++nColIdx ) | |||
636 | { | |||
637 | InsertDataColumn( static_cast< sal_uInt16 >( nColIdx ), GetColString( nColIdx ), nColumnWidth ); | |||
638 | } | |||
639 | ||||
640 | RowInserted( 1, nRowCountLocal ); | |||
641 | GoToRow( std::min( nOldRow, GetRowCount() - 1 )); | |||
642 | GoToColumnId( std::min( nOldColId, static_cast< sal_uInt16 >( ColCount() - 1 ))); | |||
643 | ||||
644 | // fill series headers | |||
645 | clearHeaders(); | |||
646 | const DataBrowserModel::tDataHeaderVector& aHeaders( m_apDataBrowserModel->getDataHeaders()); | |||
647 | Link<impl::SeriesHeaderEdit&,void> aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )::tools::detail::makeLink( ::tools::detail::castTo<DataBrowser *>(this), &DataBrowser::LinkStubSeriesHeaderGotFocus)); | |||
648 | Link<impl::SeriesHeaderEdit&,void> aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )::tools::detail::makeLink( ::tools::detail::castTo<DataBrowser *>(this), &DataBrowser::LinkStubSeriesHeaderChanged)); | |||
649 | ||||
650 | for (auto const& elemHeader : aHeaders) | |||
651 | { | |||
652 | auto spHeader = std::make_shared<impl::SeriesHeader>( m_pColumnsWin, m_pColorsWin ); | |||
653 | Reference< beans::XPropertySet > xSeriesProp( elemHeader.m_xDataSeries, uno::UNO_QUERY ); | |||
654 | sal_Int32 nColor = 0; | |||
655 | // @todo: Set "DraftColor", i.e. interpolated colors for gradients, bitmaps, etc. | |||
656 | if( xSeriesProp.is() && | |||
657 | ( xSeriesProp->getPropertyValue( "Color" ) >>= nColor )) | |||
658 | spHeader->SetColor( Color( nColor )); | |||
659 | spHeader->SetChartType( elemHeader.m_xChartType, elemHeader.m_bSwapXAndYAxis ); | |||
660 | spHeader->SetSeriesName( | |||
661 | DataSeriesHelper::getDataSeriesLabel( | |||
662 | elemHeader.m_xDataSeries, | |||
663 | (elemHeader.m_xChartType.is() ? | |||
664 | elemHeader.m_xChartType->getRoleOfSequenceForSeriesLabel() : | |||
665 | OUString("values-y")))); | |||
666 | // index is 1-based, as 0 is for the column that contains the row-numbers | |||
667 | spHeader->SetRange( elemHeader.m_nStartColumn + 1, elemHeader.m_nEndColumn + 1 ); | |||
668 | spHeader->SetGetFocusHdl( aFocusLink ); | |||
669 | spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); | |||
670 | m_aSeriesHeaders.push_back( spHeader ); | |||
671 | } | |||
672 | ||||
673 | ImplAdjustHeaderControls(); | |||
674 | SetUpdateMode( bLastUpdateMode ); | |||
675 | ActivateCell(); | |||
676 | Invalidate(); | |||
677 | } | |||
678 | ||||
679 | OUString DataBrowser::GetColString( sal_Int32 nColumnId ) const | |||
680 | { | |||
681 | OSL_ASSERT(m_apDataBrowserModel)do { if (true && (!(m_apDataBrowserModel))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/chart2/source/controller/dialogs/DataBrowser.cxx" ":" "681" ": "), "OSL_ASSERT: %s", "m_apDataBrowserModel"); } } while (false); | |||
682 | if( nColumnId > 0 ) | |||
683 | return m_apDataBrowserModel->getRoleOfColumn( nColumnId - 1 ); | |||
684 | return OUString(); | |||
685 | } | |||
686 | ||||
687 | OUString DataBrowser::GetCellText( long nRow, sal_uInt16 nColumnId ) const | |||
688 | { | |||
689 | OUString aResult; | |||
690 | ||||
691 | if( nColumnId == 0 ) | |||
692 | { | |||
693 | aResult = OUString::number(static_cast< sal_Int32 >( nRow ) + 1); | |||
694 | } | |||
695 | else if( nRow >= 0 && m_apDataBrowserModel) | |||
696 | { | |||
697 | sal_Int32 nColIndex = static_cast< sal_Int32 >( nColumnId ) - 1; | |||
698 | ||||
699 | if( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::NUMBER ) | |||
700 | { | |||
701 | double fData( m_apDataBrowserModel->getCellNumber( nColIndex, nRow )); | |||
702 | ||||
703 | if( ! std::isnan( fData ) && | |||
704 | m_spNumberFormatterWrapper ) | |||
705 | { | |||
706 | bool bColorChanged = false; | |||
707 | Color nLabelColor; | |||
708 | aResult = m_spNumberFormatterWrapper->getFormattedString( | |||
709 | GetNumberFormatKey( nColumnId ), | |||
710 | fData, nLabelColor, bColorChanged ); | |||
711 | } | |||
712 | } | |||
713 | else if( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::TEXTORDATE ) | |||
714 | { | |||
715 | uno::Any aAny = m_apDataBrowserModel->getCellAny( nColIndex, nRow ); | |||
716 | OUString aText; | |||
717 | double fDouble=0.0; | |||
718 | if( aAny>>=aText ) | |||
719 | aResult = aText; | |||
720 | else if( aAny>>=fDouble ) | |||
721 | { | |||
722 | if( ! std::isnan( fDouble ) && m_spNumberFormatterWrapper ) | |||
723 | { | |||
724 | // If a numberformat was available here we could directly | |||
725 | // obtain the corresponding edit format in | |||
726 | // getDateTimeInputNumberFormat() instead of doing the | |||
727 | // guess work. | |||
728 | sal_Int32 nNumberFormat = DiagramHelper::getDateTimeInputNumberFormat( | |||
729 | Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY), fDouble ); | |||
730 | Color nLabelColor; | |||
731 | bool bColorChanged = false; | |||
732 | aResult = m_spNumberFormatterWrapper->getFormattedString( | |||
733 | nNumberFormat, fDouble, nLabelColor, bColorChanged ); | |||
734 | } | |||
735 | } | |||
736 | } | |||
737 | else | |||
738 | { | |||
739 | OSL_ASSERT( m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::TEXT )do { if (true && (!(m_apDataBrowserModel->getCellType ( nColIndex ) == DataBrowserModel::TEXT))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/chart2/source/controller/dialogs/DataBrowser.cxx" ":" "739" ": "), "OSL_ASSERT: %s", "m_apDataBrowserModel->getCellType( nColIndex ) == DataBrowserModel::TEXT" ); } } while (false); | |||
740 | aResult = m_apDataBrowserModel->getCellText( nColIndex, nRow ); | |||
741 | } | |||
742 | } | |||
743 | ||||
744 | return aResult; | |||
745 | } | |||
746 | ||||
747 | double DataBrowser::GetCellNumber( long nRow, sal_uInt16 nColumnId ) const | |||
748 | { | |||
749 | double fResult; | |||
750 | ::rtl::math::setNan( & fResult ); | |||
751 | ||||
752 | if(( nColumnId >= 1 ) && ( nRow >= 0 ) && m_apDataBrowserModel) | |||
753 | { | |||
754 | fResult = m_apDataBrowserModel->getCellNumber( | |||
755 | static_cast< sal_Int32 >( nColumnId ) - 1, nRow ); | |||
756 | } | |||
757 | ||||
758 | return fResult; | |||
759 | } | |||
760 | ||||
761 | void DataBrowser::Resize() | |||
762 | { | |||
763 | bool bLastUpdateMode = GetUpdateMode(); | |||
764 | SetUpdateMode( false ); | |||
765 | ||||
766 | ::svt::EditBrowseBox::Resize(); | |||
767 | ImplAdjustHeaderControls(); | |||
768 | SetUpdateMode( bLastUpdateMode ); | |||
769 | } | |||
770 | ||||
771 | void DataBrowser::SetReadOnly( bool bNewState ) | |||
772 | { | |||
773 | if( m_bIsReadOnly != bNewState ) | |||
774 | { | |||
775 | m_bIsReadOnly = bNewState; | |||
776 | Invalidate(); | |||
777 | DeactivateCell(); | |||
778 | } | |||
779 | } | |||
780 | ||||
781 | void DataBrowser::CursorMoved() | |||
782 | { | |||
783 | EditBrowseBox::CursorMoved(); | |||
784 | ||||
785 | if( GetUpdateMode() ) | |||
786 | m_aCursorMovedHdlLink.Call( this ); | |||
787 | } | |||
788 | ||||
789 | void DataBrowser::MouseButtonDown( const BrowserMouseEvent& rEvt ) | |||
790 | { | |||
791 | if( !m_bDataValid ) | |||
792 | ShowWarningBox(); | |||
793 | else | |||
794 | EditBrowseBox::MouseButtonDown( rEvt ); | |||
795 | } | |||
796 | ||||
797 | void DataBrowser::ShowWarningBox() | |||
798 | { | |||
799 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(), | |||
800 | VclMessageType::Warning, VclButtonsType::Ok, | |||
801 | SchResId(STR_INVALID_NUMBERreinterpret_cast<char const *>("STR_INVALID_NUMBER" "\004" u8"Numbers are required. Check your input.")))); | |||
802 | xWarn->run(); | |||
803 | } | |||
804 | ||||
805 | bool DataBrowser::ShowQueryBox() | |||
806 | { | |||
807 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), | |||
808 | VclMessageType::Question, VclButtonsType::YesNo, | |||
809 | SchResId(STR_DATA_EDITOR_INCORRECT_INPUTreinterpret_cast<char const *>("STR_DATA_EDITOR_INCORRECT_INPUT" "\004" u8"Your last input is incorrect.\nIgnore this change and close the dialog?" )))); | |||
810 | return xQueryBox->run() == RET_YES; | |||
811 | } | |||
812 | ||||
813 | bool DataBrowser::IsDataValid() const | |||
814 | { | |||
815 | bool bValid = true; | |||
816 | const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); | |||
817 | ||||
818 | if( m_apDataBrowserModel->getCellType( nCol ) == DataBrowserModel::NUMBER ) | |||
819 | { | |||
820 | sal_uInt32 nDummy = 0; | |||
821 | double fDummy = 0.0; | |||
822 | OUString aText(m_aNumberEditField->get_widget().get_text()); | |||
823 | ||||
824 | if( !aText.isEmpty() && | |||
825 | m_spNumberFormatterWrapper && | |||
826 | m_spNumberFormatterWrapper->getSvNumberFormatter() && | |||
827 | ! m_spNumberFormatterWrapper->getSvNumberFormatter()->IsNumberFormat( | |||
828 | aText, nDummy, fDummy )) | |||
829 | { | |||
830 | bValid = false; | |||
831 | } | |||
832 | } | |||
833 | ||||
834 | return bValid; | |||
835 | } | |||
836 | ||||
837 | void DataBrowser::CellModified() | |||
838 | { | |||
839 | m_bDataValid = IsDataValid(); | |||
840 | m_aCursorMovedHdlLink.Call( this ); | |||
841 | } | |||
842 | ||||
843 | void DataBrowser::SetDataFromModel( | |||
844 | const Reference< chart2::XChartDocument > & xChartDoc, | |||
845 | const Reference< uno::XComponentContext > & xContext ) | |||
846 | { | |||
847 | m_xChartDoc.set( xChartDoc ); | |||
848 | ||||
849 | m_apDataBrowserModel.reset( new DataBrowserModel( m_xChartDoc, xContext )); | |||
850 | m_spNumberFormatterWrapper = | |||
851 | std::make_shared<NumberFormatterWrapper>( | |||
852 | Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY )); | |||
853 | ||||
854 | Formatter& rFormatter = m_aNumberEditField->get_formatter(); | |||
855 | rFormatter.SetFormatter( m_spNumberFormatterWrapper->getSvNumberFormatter() ); | |||
856 | ||||
857 | RenewTable(); | |||
858 | ||||
859 | const sal_Int32 nColCnt = m_apDataBrowserModel->getColumnCount(); | |||
860 | const sal_Int32 nRowCnt = m_apDataBrowserModel->getMaxRowCount(); | |||
861 | if( nRowCnt && nColCnt ) | |||
862 | { | |||
863 | GoToRow( 0 ); | |||
864 | GoToColumnId( 1 ); | |||
865 | } | |||
866 | } | |||
867 | ||||
868 | void DataBrowser::InsertColumn() | |||
869 | { | |||
870 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
871 | ||||
872 | if( nColIdx >= 0 && m_apDataBrowserModel) | |||
873 | { | |||
874 | // save changes made to edit-field | |||
875 | if( IsModified() ) | |||
876 | SaveModified(); | |||
877 | ||||
878 | m_apDataBrowserModel->insertDataSeries( nColIdx ); | |||
879 | RenewTable(); | |||
880 | } | |||
881 | } | |||
882 | ||||
883 | void DataBrowser::InsertTextColumn() | |||
884 | { | |||
885 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
886 | ||||
887 | if( nColIdx >= 0 && m_apDataBrowserModel) | |||
888 | { | |||
889 | // save changes made to edit-field | |||
890 | if( IsModified() ) | |||
891 | SaveModified(); | |||
892 | ||||
893 | m_apDataBrowserModel->insertComplexCategoryLevel( nColIdx ); | |||
894 | RenewTable(); | |||
895 | } | |||
896 | } | |||
897 | ||||
898 | void DataBrowser::RemoveColumn() | |||
899 | { | |||
900 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
901 | ||||
902 | if( nColIdx >= 0 && m_apDataBrowserModel) | |||
903 | { | |||
904 | // save changes made to edit-field | |||
905 | if( IsModified() ) | |||
906 | SaveModified(); | |||
907 | ||||
908 | m_bDataValid = true; | |||
909 | m_apDataBrowserModel->removeDataSeriesOrComplexCategoryLevel( nColIdx ); | |||
910 | RenewTable(); | |||
911 | } | |||
912 | } | |||
913 | ||||
914 | void DataBrowser::InsertRow() | |||
915 | { | |||
916 | sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); | |||
917 | ||||
918 | if( nRowIdx >= 0 && m_apDataBrowserModel) | |||
919 | { | |||
920 | // save changes made to edit-field | |||
921 | if( IsModified() ) | |||
922 | SaveModified(); | |||
923 | ||||
924 | m_apDataBrowserModel->insertDataPointForAllSeries( nRowIdx ); | |||
925 | RenewTable(); | |||
926 | } | |||
927 | } | |||
928 | ||||
929 | void DataBrowser::RemoveRow() | |||
930 | { | |||
931 | sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); | |||
932 | ||||
933 | if( nRowIdx >= 0 && m_apDataBrowserModel) | |||
934 | { | |||
935 | // save changes made to edit-field | |||
936 | if( IsModified() ) | |||
937 | SaveModified(); | |||
938 | ||||
939 | m_bDataValid = true; | |||
940 | m_apDataBrowserModel->removeDataPointForAllSeries( nRowIdx ); | |||
941 | RenewTable(); | |||
942 | } | |||
943 | } | |||
944 | ||||
945 | void DataBrowser::MoveLeftColumn() | |||
946 | { | |||
947 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
948 | ||||
949 | if( !(nColIdx > 0 && m_apDataBrowserModel)) | |||
950 | return; | |||
951 | ||||
952 | // save changes made to edit-field | |||
953 | if( IsModified() ) | |||
954 | SaveModified(); | |||
955 | ||||
956 | m_apDataBrowserModel->swapDataSeries( nColIdx - 1 ); | |||
957 | ||||
958 | // keep cursor in swapped column | |||
959 | if(( 0 < GetCurColumnId() ) && ( GetCurColumnId() <= ColCount() - 1 )) | |||
960 | { | |||
961 | Dispatch( BROWSER_CURSORLEFT733 ); | |||
962 | } | |||
963 | RenewTable(); | |||
964 | } | |||
965 | ||||
966 | void DataBrowser::MoveRightColumn() | |||
967 | { | |||
968 | sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); | |||
969 | ||||
970 | if( !(nColIdx >= 0 && m_apDataBrowserModel)) | |||
971 | return; | |||
972 | ||||
973 | // save changes made to edit-field | |||
974 | if( IsModified() ) | |||
975 | SaveModified(); | |||
976 | ||||
977 | m_apDataBrowserModel->swapDataSeries( nColIdx ); | |||
978 | ||||
979 | // keep cursor in swapped column | |||
980 | if( GetCurColumnId() < ColCount() - 1 ) | |||
981 | { | |||
982 | Dispatch( BROWSER_CURSORRIGHT734 ); | |||
983 | } | |||
984 | RenewTable(); | |||
985 | } | |||
986 | ||||
987 | void DataBrowser::MoveUpRow() | |||
988 | { | |||
989 | sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); | |||
990 | ||||
991 | if( !(nRowIdx > 0 && m_apDataBrowserModel)) | |||
992 | return; | |||
993 | ||||
994 | // save changes made to edit-field | |||
995 | if( IsModified() ) | |||
996 | SaveModified(); | |||
997 | ||||
998 | m_apDataBrowserModel->swapDataPointForAllSeries( nRowIdx - 1 ); | |||
999 | ||||
1000 | // keep cursor in swapped row | |||
1001 | if(( 0 < GetCurRow() ) && ( GetCurRow() <= GetRowCount() - 1 )) | |||
1002 | { | |||
1003 | Dispatch( BROWSER_CURSORUP732 ); | |||
1004 | } | |||
1005 | RenewTable(); | |||
1006 | } | |||
1007 | ||||
1008 | void DataBrowser::MoveDownRow() | |||
1009 | { | |||
1010 | sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); | |||
1011 | ||||
1012 | if( !(nRowIdx >= 0 && m_apDataBrowserModel)) | |||
1013 | return; | |||
1014 | ||||
1015 | // save changes made to edit-field | |||
1016 | if( IsModified() ) | |||
1017 | SaveModified(); | |||
1018 | ||||
1019 | m_apDataBrowserModel->swapDataPointForAllSeries( nRowIdx ); | |||
1020 | ||||
1021 | // keep cursor in swapped row | |||
1022 | if( GetCurRow() < GetRowCount() - 1 ) | |||
1023 | { | |||
1024 | Dispatch( BROWSER_CURSORDOWN731 ); | |||
1025 | } | |||
1026 | RenewTable(); | |||
1027 | } | |||
1028 | ||||
1029 | void DataBrowser::SetCursorMovedHdl( const Link<DataBrowser*,void>& rLink ) | |||
1030 | { | |||
1031 | m_aCursorMovedHdlLink = rLink; | |||
1032 | } | |||
1033 | ||||
1034 | // implementations for ::svt::EditBrowseBox (pure virtual methods) | |||
1035 | void DataBrowser::PaintCell( | |||
1036 | OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColumnId ) const | |||
1037 | { | |||
1038 | Point aPos( rRect.TopLeft()); | |||
1039 | aPos.AdjustX(1 ); | |||
1040 | ||||
1041 | OUString aText = GetCellText( m_nSeekRow, nColumnId ); | |||
1042 | Size TxtSize( GetDataWindow().GetTextWidth( aText ), GetDataWindow().GetTextHeight()); | |||
1043 | ||||
1044 | // clipping | |||
1045 | if( aPos.X() < rRect.Right() || aPos.X() + TxtSize.Width() > rRect.Right() || | |||
1046 | aPos.Y() < rRect.Top() || aPos.Y() + TxtSize.Height() > rRect.Bottom()) | |||
1047 | rDev.SetClipRegion(vcl::Region(rRect)); | |||
1048 | ||||
1049 | // allow for a disabled control ... | |||
1050 | bool bEnabled = IsEnabled(); | |||
1051 | Color aOriginalColor = rDev.GetTextColor(); | |||
1052 | if( ! bEnabled ) | |||
1053 | rDev.SetTextColor( GetSettings().GetStyleSettings().GetDisableColor() ); | |||
1054 | ||||
1055 | // draw the text | |||
1056 | rDev.DrawText( aPos, aText ); | |||
1057 | ||||
1058 | // reset the color (if necessary) | |||
1059 | if( ! bEnabled ) | |||
1060 | rDev.SetTextColor( aOriginalColor ); | |||
1061 | ||||
1062 | if( rDev.IsClipRegion()) | |||
1063 | rDev.SetClipRegion(); | |||
1064 | } | |||
1065 | ||||
1066 | bool DataBrowser::SeekRow( long nRow ) | |||
1067 | { | |||
1068 | if( ! EditBrowseBox::SeekRow( nRow )) | |||
1069 | return false; | |||
1070 | ||||
1071 | if( nRow < 0 ) | |||
1072 | m_nSeekRow = - 1; | |||
1073 | else | |||
1074 | m_nSeekRow = nRow; | |||
1075 | ||||
1076 | return true; | |||
1077 | } | |||
1078 | ||||
1079 | bool DataBrowser::IsTabAllowed( bool bForward ) const | |||
1080 | { | |||
1081 | long nRow = GetCurRow(); | |||
1082 | long nCol = GetCurColumnId(); | |||
1083 | ||||
1084 | // column 0 is header-column | |||
1085 | long nBadCol = bForward | |||
1086 | ? GetColumnCount() - 1 | |||
1087 | : 1; | |||
1088 | long nBadRow = bForward | |||
1089 | ? GetRowCount() - 1 | |||
1090 | : 0; | |||
1091 | ||||
1092 | if( !m_bDataValid ) | |||
1093 | { | |||
1094 | const_cast< DataBrowser* >( this )->ShowWarningBox(); | |||
1095 | return false; | |||
1096 | } | |||
1097 | ||||
1098 | return ( nRow != nBadRow || | |||
1099 | nCol != nBadCol ); | |||
1100 | } | |||
1101 | ||||
1102 | ::svt::CellController* DataBrowser::GetController( long /*nRow*/, sal_uInt16 nCol ) | |||
1103 | { | |||
1104 | if( m_bIsReadOnly ) | |||
1105 | return nullptr; | |||
1106 | ||||
1107 | if( CellContainsNumbers( nCol )) | |||
1108 | { | |||
1109 | Formatter& rFormatter = m_aNumberEditField->get_formatter(); | |||
1110 | rFormatter.UseInputStringForFormatting(); | |||
1111 | rFormatter.SetFormatKey( GetNumberFormatKey( nCol )); | |||
1112 | return m_rNumberEditController.get(); | |||
1113 | } | |||
1114 | ||||
1115 | return m_rTextEditController.get(); | |||
1116 | } | |||
1117 | ||||
1118 | void DataBrowser::InitController( | |||
1119 | ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol ) | |||
1120 | { | |||
1121 | if( rController == m_rTextEditController ) | |||
1122 | { | |||
1123 | OUString aText( GetCellText( nRow, nCol ) ); | |||
1124 | weld::Entry& rEntry = m_aTextEditField->get_widget(); | |||
1125 | rEntry.set_text(aText); | |||
1126 | rEntry.select_region(0, -1); | |||
1127 | } | |||
1128 | else if( rController == m_rNumberEditController ) | |||
1129 | { | |||
1130 | // treat invalid and empty text as Nan | |||
1131 | Formatter& rFormatter = m_aNumberEditField->get_formatter(); | |||
1132 | rFormatter.EnableNotANumber( true ); | |||
1133 | if( std::isnan( GetCellNumber( nRow, nCol ))) | |||
1134 | rFormatter.SetTextValue( OUString()); | |||
1135 | else | |||
1136 | rFormatter.SetValue( GetCellNumber( nRow, nCol ) ); | |||
1137 | weld::Entry& rEntry = m_aNumberEditField->get_widget(); | |||
1138 | rEntry.select_region(0, -1); | |||
1139 | } | |||
1140 | else | |||
1141 | { | |||
1142 | OSL_FAIL( "Invalid Controller" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/chart2/source/controller/dialogs/DataBrowser.cxx" ":" "1142" ": "), "%s", "Invalid Controller"); } } while (false ); | |||
1143 | } | |||
1144 | } | |||
1145 | ||||
1146 | bool DataBrowser::CellContainsNumbers( sal_uInt16 nCol ) const | |||
1147 | { | |||
1148 | if (!m_apDataBrowserModel) | |||
1149 | return false; | |||
1150 | return m_apDataBrowserModel->getCellType( lcl_getColumnInData( nCol )) == DataBrowserModel::NUMBER; | |||
1151 | } | |||
1152 | ||||
1153 | sal_uInt32 DataBrowser::GetNumberFormatKey( sal_uInt16 nCol ) const | |||
1154 | { | |||
1155 | if (!m_apDataBrowserModel) | |||
1156 | return 0; | |||
1157 | return m_apDataBrowserModel->getNumberFormatKey( lcl_getColumnInData( nCol ) ); | |||
1158 | } | |||
1159 | ||||
1160 | bool DataBrowser::isDateTimeString( const OUString& aInputString, double& fOutDateTimeValue ) | |||
1161 | { | |||
1162 | sal_uInt32 nNumberFormat=0; | |||
1163 | SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper ? m_spNumberFormatterWrapper->getSvNumberFormatter() : nullptr; | |||
1164 | if( !aInputString.isEmpty() && pSvNumberFormatter && pSvNumberFormatter->IsNumberFormat( aInputString, nNumberFormat, fOutDateTimeValue ) ) | |||
1165 | { | |||
1166 | SvNumFormatType nType = pSvNumberFormatter->GetType( nNumberFormat); | |||
1167 | return (nType & SvNumFormatType::DATE) || (nType & SvNumFormatType::TIME); | |||
1168 | } | |||
1169 | return false; | |||
1170 | } | |||
1171 | ||||
1172 | bool DataBrowser::SaveModified() | |||
1173 | { | |||
1174 | if( ! IsModified() ) | |||
1175 | return true; | |||
1176 | ||||
1177 | bool bChangeValid = true; | |||
1178 | ||||
1179 | const sal_Int32 nRow = lcl_getRowInData( GetCurRow()); | |||
1180 | const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); | |||
1181 | ||||
1182 | OSL_ENSURE( nRow >= 0 || nCol >= 0, "This cell should not be modified!" )do { if (true && (!(nRow >= 0 || nCol >= 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/chart2/source/controller/dialogs/DataBrowser.cxx" ":" "1182" ": "), "%s", "This cell should not be modified!") ; } } while (false); | |||
1183 | ||||
1184 | SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper ? m_spNumberFormatterWrapper->getSvNumberFormatter() : nullptr; | |||
1185 | switch( m_apDataBrowserModel->getCellType( nCol )) | |||
1186 | { | |||
1187 | case DataBrowserModel::NUMBER: | |||
1188 | { | |||
1189 | sal_uInt32 nDummy = 0; | |||
1190 | double fDummy = 0.0; | |||
1191 | OUString aText(m_aNumberEditField->get_widget().get_text()); | |||
1192 | // an empty string is valid, if no numberformatter exists, all | |||
1193 | // values are treated as valid | |||
1194 | if( !aText.isEmpty() && pSvNumberFormatter && | |||
1195 | ! pSvNumberFormatter->IsNumberFormat( aText, nDummy, fDummy ) ) | |||
1196 | { | |||
1197 | bChangeValid = false; | |||
1198 | } | |||
1199 | else | |||
1200 | { | |||
1201 | Formatter& rFormatter = m_aNumberEditField->get_formatter(); | |||
1202 | double fData = rFormatter.GetValue(); | |||
1203 | bChangeValid = m_apDataBrowserModel->setCellNumber( nCol, nRow, fData ); | |||
1204 | } | |||
1205 | } | |||
1206 | break; | |||
1207 | case DataBrowserModel::TEXTORDATE: | |||
1208 | { | |||
1209 | weld::Entry& rEntry = m_aTextEditField->get_widget(); | |||
1210 | OUString aText(rEntry.get_text()); | |||
1211 | double fValue = 0.0; | |||
1212 | bChangeValid = false; | |||
1213 | if( isDateTimeString( aText, fValue ) ) | |||
1214 | bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::Any( fValue ) ); | |||
1215 | if(!bChangeValid) | |||
1216 | bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::Any( aText ) ); | |||
1217 | } | |||
1218 | break; | |||
1219 | case DataBrowserModel::TEXT: | |||
1220 | { | |||
1221 | weld::Entry& rEntry = m_aTextEditField->get_widget(); | |||
1222 | OUString aText(rEntry.get_text()); | |||
1223 | bChangeValid = m_apDataBrowserModel->setCellText( nCol, nRow, aText ); | |||
1224 | } | |||
1225 | break; | |||
1226 | } | |||
1227 | ||||
1228 | // the first valid change changes this to true | |||
1229 | if( bChangeValid ) | |||
1230 | { | |||
1231 | RowModified( GetCurRow(), GetCurColumnId()); | |||
1232 | ::svt::CellController* pCtrl = GetController( GetCurRow(), GetCurColumnId()); | |||
1233 | if( pCtrl ) | |||
1234 | pCtrl->SaveValue(); | |||
1235 | } | |||
1236 | ||||
1237 | return bChangeValid; | |||
1238 | } | |||
1239 | ||||
1240 | bool DataBrowser::EndEditing() | |||
1241 | { | |||
1242 | SaveModified(); | |||
1243 | ||||
1244 | // apply changes made to series headers | |||
1245 | for( const auto& spHeader : m_aSeriesHeaders ) | |||
1246 | spHeader->applyChanges(); | |||
1247 | ||||
1248 | if( m_bDataValid ) | |||
1249 | return true; | |||
1250 | else | |||
1251 | return ShowQueryBox(); | |||
1252 | } | |||
1253 | ||||
1254 | void DataBrowser::ColumnResized( sal_uInt16 nColId ) | |||
1255 | { | |||
1256 | bool bLastUpdateMode = GetUpdateMode(); | |||
1257 | SetUpdateMode( false ); | |||
1258 | ||||
1259 | EditBrowseBox::ColumnResized( nColId ); | |||
1260 | ImplAdjustHeaderControls(); | |||
1261 | SetUpdateMode( bLastUpdateMode ); | |||
1262 | } | |||
1263 | ||||
1264 | void DataBrowser::EndScroll() | |||
1265 | { | |||
1266 | bool bLastUpdateMode = GetUpdateMode(); | |||
1267 | SetUpdateMode( false ); | |||
1268 | ||||
1269 | EditBrowseBox::EndScroll(); | |||
1270 | RenewSeriesHeaders(); | |||
1271 | ||||
1272 | SetUpdateMode( bLastUpdateMode ); | |||
1273 | } | |||
1274 | ||||
1275 | void DataBrowser::RenewSeriesHeaders() | |||
1276 | { | |||
1277 | clearHeaders(); | |||
1278 | DataBrowserModel::tDataHeaderVector aHeaders( m_apDataBrowserModel->getDataHeaders()); | |||
1279 | Link<impl::SeriesHeaderEdit&,void> aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )::tools::detail::makeLink( ::tools::detail::castTo<DataBrowser *>(this), &DataBrowser::LinkStubSeriesHeaderGotFocus)); | |||
1280 | Link<impl::SeriesHeaderEdit&,void> aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )::tools::detail::makeLink( ::tools::detail::castTo<DataBrowser *>(this), &DataBrowser::LinkStubSeriesHeaderChanged)); | |||
1281 | ||||
1282 | for (auto const& elemHeader : aHeaders) | |||
1283 | { | |||
1284 | auto spHeader = std::make_shared<impl::SeriesHeader>( m_pColumnsWin, m_pColorsWin ); | |||
1285 | Reference< beans::XPropertySet > xSeriesProp(elemHeader.m_xDataSeries, uno::UNO_QUERY); | |||
1286 | sal_Int32 nColor = 0; | |||
1287 | if( xSeriesProp.is() && | |||
1288 | ( xSeriesProp->getPropertyValue( "Color" ) >>= nColor )) | |||
1289 | spHeader->SetColor( Color( nColor )); | |||
1290 | spHeader->SetChartType( elemHeader.m_xChartType, elemHeader.m_bSwapXAndYAxis ); | |||
1291 | spHeader->SetSeriesName( | |||
1292 | DataSeriesHelper::getDataSeriesLabel( | |||
1293 | elemHeader.m_xDataSeries, | |||
1294 | (elemHeader.m_xChartType.is() ? | |||
1295 | elemHeader.m_xChartType->getRoleOfSequenceForSeriesLabel() : | |||
1296 | OUString( "values-y")))); | |||
1297 | spHeader->SetRange( elemHeader.m_nStartColumn + 1, elemHeader.m_nEndColumn + 1 ); | |||
1298 | spHeader->SetGetFocusHdl( aFocusLink ); | |||
1299 | spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); | |||
1300 | m_aSeriesHeaders.push_back( spHeader ); | |||
1301 | } | |||
1302 | ||||
1303 | ImplAdjustHeaderControls(); | |||
1304 | } | |||
1305 | ||||
1306 | void DataBrowser::ImplAdjustHeaderControls() | |||
1307 | { | |||
1308 | sal_uInt16 nColCount = GetColumnCount(); | |||
1309 | sal_uInt32 nCurrentPos = GetPosPixel().getX(); | |||
1310 | sal_uInt32 nMaxPos = nCurrentPos + GetOutputSizePixel().getWidth(); | |||
1311 | sal_uInt32 nStartPos = nCurrentPos; | |||
1312 | ||||
1313 | // width of header column | |||
1314 | nCurrentPos += GetColumnWidth( 0 ); | |||
1315 | ||||
1316 | weld::Container* pWin = m_pColumnsWin; | |||
1317 | weld::Container* pColorWin = m_pColorsWin; | |||
1318 | pWin->set_margin_left(nCurrentPos); | |||
1319 | pColorWin->set_margin_left(nCurrentPos); | |||
1320 | ||||
1321 | tSeriesHeaderContainer::iterator aIt( m_aSeriesHeaders.begin()); | |||
1322 | sal_uInt16 i = GetFirstVisibleColNumber(); | |||
1323 | while( (aIt != m_aSeriesHeaders.end()) && ((*aIt)->GetStartColumn() < i) ) | |||
1324 | { | |||
1325 | (*aIt)->Hide(); | |||
1326 | ++aIt; | |||
1327 | } | |||
1328 | for( ; i < nColCount && aIt != m_aSeriesHeaders.end(); ++i ) | |||
1329 | { | |||
1330 | if( (*aIt)->GetStartColumn() == i ) | |||
1331 | nStartPos = nCurrentPos; | |||
1332 | ||||
1333 | nCurrentPos += (GetColumnWidth( i )); | |||
1334 | ||||
1335 | if( (*aIt)->GetEndColumn() == i ) | |||
1336 | { | |||
1337 | if( nStartPos < nMaxPos ) | |||
1338 | { | |||
1339 | (*aIt)->SetPixelWidth( nCurrentPos - nStartPos ); | |||
1340 | (*aIt)->Show(); | |||
1341 | ||||
1342 | if (pWin) | |||
1343 | { | |||
1344 | pWin->set_margin_left(nStartPos); | |||
1345 | pColorWin->set_margin_left(nStartPos); | |||
1346 | pWin = pColorWin = nullptr; | |||
1347 | } | |||
1348 | ||||
1349 | } | |||
1350 | else | |||
1351 | (*aIt)->Hide(); | |||
1352 | ++aIt; | |||
1353 | } | |||
1354 | } | |||
1355 | } | |||
1356 | ||||
1357 | IMPL_LINK( DataBrowser, SeriesHeaderGotFocus, impl::SeriesHeaderEdit&, rEdit, void )void DataBrowser::LinkStubSeriesHeaderGotFocus(void * instance , impl::SeriesHeaderEdit& data) { return static_cast<DataBrowser *>(instance)->SeriesHeaderGotFocus(data); } void DataBrowser ::SeriesHeaderGotFocus(impl::SeriesHeaderEdit& rEdit) | |||
1358 | { | |||
1359 | rEdit.SetShowWarningBox( !m_bDataValid ); | |||
1360 | ||||
1361 | if( !m_bDataValid ) | |||
1362 | GoToCell( 0, 0 ); | |||
1363 | else | |||
1364 | { | |||
1365 | MakeFieldVisible( GetCurRow(), static_cast< sal_uInt16 >( rEdit.getStartColumn()) ); | |||
1366 | ActivateCell(); | |||
1367 | m_aCursorMovedHdlLink.Call( this ); | |||
1368 | } | |||
1369 | } | |||
1370 | ||||
1371 | IMPL_LINK( DataBrowser, SeriesHeaderChanged, impl::SeriesHeaderEdit&, rEdit, void )void DataBrowser::LinkStubSeriesHeaderChanged(void * instance , impl::SeriesHeaderEdit& data) { return static_cast<DataBrowser *>(instance)->SeriesHeaderChanged(data); } void DataBrowser ::SeriesHeaderChanged(impl::SeriesHeaderEdit& rEdit) | |||
1372 | { | |||
1373 | Reference< chart2::XDataSeries > xSeries( | |||
1374 | m_apDataBrowserModel->getDataSeriesByColumn( rEdit.getStartColumn() - 1 )); | |||
1375 | Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); | |||
1376 | if( !xSource.is()) | |||
1377 | return; | |||
1378 | ||||
1379 | Reference< chart2::XChartType > xChartType( | |||
1380 | m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType ); | |||
1381 | if( xChartType.is()) | |||
1382 | { | |||
1383 | Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( | |||
1384 | DataSeriesHelper::getDataSequenceByRole( xSource, xChartType->getRoleOfSequenceForSeriesLabel())); | |||
1385 | if( xLabeledSeq.is()) | |||
1386 | { | |||
1387 | Reference< container::XIndexReplace > xIndexReplace( xLabeledSeq->getLabel(), uno::UNO_QUERY ); | |||
1388 | if( xIndexReplace.is()) | |||
1389 | xIndexReplace->replaceByIndex( | |||
1390 | 0, uno::Any( rEdit.GetText())); | |||
1391 | } | |||
1392 | } | |||
1393 | } | |||
1394 | ||||
1395 | } // namespace chart | |||
1396 | ||||
1397 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<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 | */ |
56 | template <class reference_type> |
57 | class 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 | |
66 | public: |
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 ;-) |
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 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<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 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
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 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
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 | |
378 | private: |
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 | |
387 | protected: |
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 |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
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 | |
421 | private: |
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: */ |
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 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
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
| ||||||||
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; | ||||||||
| |||||||||
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 | ||||||||
277 | namespace 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 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct 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: */ |
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 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
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) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |