File: | home/maarten/src/libreoffice/core/editeng/source/outliner/outleeng.cxx |
Warning: | line 49, column 5 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 <editeng/editeng.hxx> | |||
21 | #include <editeng/eerdll.hxx> | |||
22 | ||||
23 | #include <editeng/outliner.hxx> | |||
24 | #include "outleeng.hxx" | |||
25 | #include "paralist.hxx" | |||
26 | #include <editeng/editrids.hrc> | |||
27 | #include <svl/itemset.hxx> | |||
28 | #include <editeng/editstat.hxx> | |||
29 | #include "outlundo.hxx" | |||
30 | ||||
31 | OutlinerEditEng::OutlinerEditEng( Outliner* pEngOwner, SfxItemPool* pPool ) | |||
32 | : EditEngine( pPool ) | |||
33 | { | |||
34 | pOwner = pEngOwner; | |||
35 | } | |||
36 | ||||
37 | OutlinerEditEng::~OutlinerEditEng() | |||
38 | { | |||
39 | } | |||
40 | ||||
41 | void OutlinerEditEng::PaintingFirstLine( sal_Int32 nPara, const Point& rStartPos, long /*nBaseLineY*/, const Point& rOrigin, short nOrientation, OutputDevice* pOutDev ) | |||
42 | { | |||
43 | if( GetControlWord() & EEControlBits::OUTLINER ) | |||
| ||||
44 | { | |||
45 | PaintFirstLineInfo aInfo( nPara, rStartPos, pOutDev ); | |||
46 | pOwner->maPaintFirstLineHdl.Call( &aInfo ); | |||
47 | } | |||
48 | ||||
49 | pOwner->PaintBullet( nPara, rStartPos, rOrigin, nOrientation, pOutDev ); | |||
| ||||
50 | } | |||
51 | ||||
52 | const SvxNumberFormat* OutlinerEditEng::GetNumberFormat( sal_Int32 nPara ) const | |||
53 | { | |||
54 | const SvxNumberFormat* pFmt = nullptr; | |||
55 | if (pOwner) | |||
56 | pFmt = pOwner->GetNumberFormat( nPara ); | |||
57 | return pFmt; | |||
58 | } | |||
59 | ||||
60 | ||||
61 | tools::Rectangle OutlinerEditEng::GetBulletArea( sal_Int32 nPara ) | |||
62 | { | |||
63 | tools::Rectangle aBulletArea { Point(), Point() }; | |||
64 | if ( nPara < pOwner->pParaList->GetParagraphCount() ) | |||
65 | { | |||
66 | if ( pOwner->ImplHasNumberFormat( nPara ) ) | |||
67 | aBulletArea = pOwner->ImpCalcBulletArea( nPara, false, false ); | |||
68 | } | |||
69 | return aBulletArea; | |||
70 | } | |||
71 | ||||
72 | void OutlinerEditEng::ParagraphInserted( sal_Int32 nNewParagraph ) | |||
73 | { | |||
74 | pOwner->ParagraphInserted( nNewParagraph ); | |||
75 | ||||
76 | EditEngine::ParagraphInserted( nNewParagraph ); | |||
77 | } | |||
78 | ||||
79 | void OutlinerEditEng::ParagraphDeleted( sal_Int32 nDeletedParagraph ) | |||
80 | { | |||
81 | pOwner->ParagraphDeleted( nDeletedParagraph ); | |||
82 | ||||
83 | EditEngine::ParagraphDeleted( nDeletedParagraph ); | |||
84 | } | |||
85 | ||||
86 | void OutlinerEditEng::ParagraphConnected( sal_Int32 /*nLeftParagraph*/, sal_Int32 nRightParagraph ) | |||
87 | { | |||
88 | if( pOwner && pOwner->IsUndoEnabled() && !pOwner->GetEditEngine().IsInUndo() ) | |||
89 | { | |||
90 | Paragraph* pPara = pOwner->GetParagraph( nRightParagraph ); | |||
91 | if( pPara && Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) ) | |||
92 | { | |||
93 | pOwner->InsertUndo( std::make_unique<OutlinerUndoChangeParaFlags>( pOwner, nRightParagraph, ParaFlag::ISPAGE, ParaFlag::NONE ) ); | |||
94 | } | |||
95 | } | |||
96 | } | |||
97 | ||||
98 | ||||
99 | void OutlinerEditEng::StyleSheetChanged( SfxStyleSheet* pStyle ) | |||
100 | { | |||
101 | pOwner->StyleSheetChanged( pStyle ); | |||
102 | } | |||
103 | ||||
104 | void OutlinerEditEng::ParaAttribsChanged( sal_Int32 nPara ) | |||
105 | { | |||
106 | pOwner->ParaAttribsChanged( nPara ); | |||
107 | } | |||
108 | ||||
109 | bool OutlinerEditEng::SpellNextDocument() | |||
110 | { | |||
111 | return pOwner->SpellNextDocument(); | |||
112 | } | |||
113 | ||||
114 | bool OutlinerEditEng::ConvertNextDocument() | |||
115 | { | |||
116 | return pOwner->ConvertNextDocument(); | |||
117 | } | |||
118 | ||||
119 | OUString OutlinerEditEng::GetUndoComment( sal_uInt16 nUndoId ) const | |||
120 | { | |||
121 | switch( nUndoId ) | |||
122 | { | |||
123 | case OLUNDO_DEPTH200: | |||
124 | return EditResId(RID_OUTLUNDO_DEPTHreinterpret_cast<char const *>("RID_OUTLUNDO_DEPTH" "\004" u8"Indent")); | |||
125 | ||||
126 | case OLUNDO_EXPAND200 +2: | |||
127 | return EditResId(RID_OUTLUNDO_EXPANDreinterpret_cast<char const *>("RID_OUTLUNDO_EXPAND" "\004" u8"Show subpoints")); | |||
128 | ||||
129 | case OLUNDO_COLLAPSE200 +3: | |||
130 | return EditResId(RID_OUTLUNDO_COLLAPSEreinterpret_cast<char const *>("RID_OUTLUNDO_COLLAPSE" "\004" u8"Collapse")); | |||
131 | ||||
132 | case OLUNDO_ATTR200 +5: | |||
133 | return EditResId(RID_OUTLUNDO_ATTRreinterpret_cast<char const *>("RID_OUTLUNDO_ATTR" "\004" u8"Apply attributes")); | |||
134 | ||||
135 | case OLUNDO_INSERT200 +6: | |||
136 | return EditResId(RID_OUTLUNDO_INSERTreinterpret_cast<char const *>("RID_OUTLUNDO_INSERT" "\004" u8"Insert")); | |||
137 | ||||
138 | default: | |||
139 | return EditEngine::GetUndoComment( nUndoId ); | |||
140 | } | |||
141 | } | |||
142 | ||||
143 | void OutlinerEditEng::DrawingText( const Point& rStartPos, const OUString& rText, sal_Int32 nTextStart, sal_Int32 nTextLen, | |||
144 | const long* pDXArray, const SvxFont& rFont, sal_Int32 nPara, sal_uInt8 nRightToLeft, | |||
145 | const EEngineData::WrongSpellVector* pWrongSpellVector, | |||
146 | const SvxFieldData* pFieldData, | |||
147 | bool bEndOfLine, | |||
148 | bool bEndOfParagraph, | |||
149 | const css::lang::Locale* pLocale, | |||
150 | const Color& rOverlineColor, | |||
151 | const Color& rTextLineColor) | |||
152 | { | |||
153 | pOwner->DrawingText(rStartPos,rText,nTextStart,nTextLen,pDXArray,rFont,nPara,nRightToLeft, | |||
154 | pWrongSpellVector, pFieldData, bEndOfLine, bEndOfParagraph, false/*bEndOfBullet*/, pLocale, rOverlineColor, rTextLineColor); | |||
155 | } | |||
156 | ||||
157 | void OutlinerEditEng::DrawingTab( const Point& rStartPos, long nWidth, const OUString& rChar, | |||
158 | const SvxFont& rFont, sal_Int32 nPara, sal_uInt8 nRightToLeft, | |||
159 | bool bEndOfLine, bool bEndOfParagraph, | |||
160 | const Color& rOverlineColor, const Color& rTextLineColor) | |||
161 | { | |||
162 | pOwner->DrawingTab(rStartPos, nWidth, rChar, rFont, nPara, nRightToLeft, | |||
163 | bEndOfLine, bEndOfParagraph, rOverlineColor, rTextLineColor ); | |||
164 | } | |||
165 | ||||
166 | OUString OutlinerEditEng::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rpTxtColor, std::optional<Color>& rpFldColor ) | |||
167 | { | |||
168 | return pOwner->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor ); | |||
169 | } | |||
170 | ||||
171 | void OutlinerEditEng::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) | |||
172 | { | |||
173 | Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara ); | |||
174 | if( !pPara ) | |||
175 | return; | |||
176 | ||||
177 | if ( !IsInUndo() && IsUndoEnabled() ) | |||
178 | pOwner->UndoActionStart( OLUNDO_ATTR200 +5 ); | |||
179 | ||||
180 | EditEngine::SetParaAttribs( nPara, rSet ); | |||
181 | ||||
182 | pOwner->ImplCheckNumBulletItem( nPara ); | |||
183 | // #i100014# | |||
184 | // It is not a good idea to subtract 1 from a count and cast the result | |||
185 | // to sal_uInt16 without check, if the count is 0. | |||
186 | pOwner->ImplCheckParagraphs( nPara, pOwner->pParaList->GetParagraphCount() ); | |||
187 | ||||
188 | if ( !IsInUndo() && IsUndoEnabled() ) | |||
189 | pOwner->UndoActionEnd(); | |||
190 | } | |||
191 | ||||
192 | /* 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_EDITENG_OUTLINER_HXX |
20 | #define INCLUDED_EDITENG_OUTLINER_HXX |
21 | |
22 | #include <editeng/editdata.hxx> |
23 | #include <editeng/editstat.hxx> |
24 | #include <i18nlangtag/lang.h> |
25 | #include <rtl/ustring.hxx> |
26 | #include <svl/SfxBroadcaster.hxx> |
27 | #include <svl/languageoptions.hxx> |
28 | #include <svl/undo.hxx> |
29 | #include <tools/gen.hxx> |
30 | #include <tools/color.hxx> |
31 | #include <vcl/outdev.hxx> |
32 | #include <vcl/errcode.hxx> |
33 | #include <tools/link.hxx> |
34 | #include <editeng/editengdllapi.h> |
35 | |
36 | #include <vcl/GraphicObject.hxx> |
37 | |
38 | #include <editeng/svxfont.hxx> |
39 | #include <editeng/eedata.hxx> |
40 | #include <editeng/paragraphdata.hxx> |
41 | #include <o3tl/typed_flags_set.hxx> |
42 | |
43 | #include <optional> |
44 | #include <functional> |
45 | #include <memory> |
46 | #include <vector> |
47 | |
48 | class OutlinerEditEng; |
49 | class Outliner; |
50 | class EditView; |
51 | class EditUndo; |
52 | class ParagraphList; |
53 | class OutlinerParaObject; |
54 | class SvStream; |
55 | class SvxSearchItem; |
56 | class SvxFieldItem; |
57 | namespace vcl { class Window; } |
58 | class KeyEvent; |
59 | class MouseEvent; |
60 | class CommandEvent; |
61 | class MapMode; |
62 | class SfxStyleSheetPool; |
63 | class SfxStyleSheet; |
64 | class SfxItemPool; |
65 | class SfxItemSet; |
66 | class SvxNumberFormat; |
67 | class EditEngine; |
68 | class SvKeyValueIterator; |
69 | class SvxForbiddenCharactersTable; |
70 | class OverflowingText; |
71 | class NonOverflowingText; |
72 | class OutlinerViewShell; |
73 | enum class CharCompressType; |
74 | enum class TransliterationFlags; |
75 | class SvxFieldData; |
76 | enum class PointerStyle; |
77 | class SvxNumRule; |
78 | enum class TextRotation; |
79 | |
80 | namespace com::sun::star::linguistic2 { |
81 | class XSpellChecker1; |
82 | class XHyphenator; |
83 | } |
84 | namespace svx{ |
85 | struct SpellPortion; |
86 | typedef std::vector<SpellPortion> SpellPortions; |
87 | } |
88 | namespace basegfx { class B2DPolyPolygon; } |
89 | namespace com::sun::star::lang { struct Locale; } |
90 | |
91 | |
92 | |
93 | // internal use only! |
94 | enum class ParaFlag |
95 | { |
96 | NONE = 0x0000, |
97 | HOLDDEPTH = 0x4000, |
98 | SETBULLETTEXT = 0x8000, |
99 | ISPAGE = 0x0100, |
100 | }; |
101 | namespace o3tl |
102 | { |
103 | template<> struct typed_flags<ParaFlag> : is_typed_flags<ParaFlag, 0xc100> {}; |
104 | } |
105 | |
106 | // Undo-Action-Ids |
107 | #define OLUNDO_DEPTH200 EDITUNDO_USER200 |
108 | // #define OLUNDO_HEIGHT EDITUNDO_USER+1 |
109 | #define OLUNDO_EXPAND200 +2 EDITUNDO_USER200+2 |
110 | #define OLUNDO_COLLAPSE200 +3 EDITUNDO_USER200+3 |
111 | // #define OLUNDO_REMOVE EDITUNDO_USER+4 |
112 | #define OLUNDO_ATTR200 +5 EDITUNDO_USER200+5 |
113 | #define OLUNDO_INSERT200 +6 EDITUNDO_USER200+6 |
114 | // #define OLUNDO_MOVEPARAGRAPHS EDITUNDO_USER+7 |
115 | |
116 | class Paragraph : protected ParagraphData |
117 | { |
118 | private: |
119 | friend class Outliner; |
120 | friend class ParagraphList; |
121 | friend class OutlinerView; |
122 | friend class OutlinerParaObject; |
123 | friend class OutlinerEditEng; |
124 | friend class OutlinerUndoCheckPara; |
125 | friend class OutlinerUndoChangeParaFlags; |
126 | |
127 | Paragraph& operator=(const Paragraph& rPara ) = delete; |
128 | |
129 | OUString aBulText; |
130 | Size aBulSize; |
131 | ParaFlag nFlags; |
132 | bool bVisible; |
133 | |
134 | bool IsVisible() const { return bVisible; } |
135 | void SetText( const OUString& rText ) { aBulText = rText; aBulSize.setWidth(-1); } |
136 | void Invalidate() { aBulSize.setWidth(-1); } |
137 | void SetDepth( sal_Int16 nNewDepth ) { nDepth = nNewDepth; aBulSize.setWidth(-1); } |
138 | const OUString& GetText() const { return aBulText; } |
139 | |
140 | Paragraph( sal_Int16 nDepth ); |
141 | Paragraph( const Paragraph& ) = delete; |
142 | Paragraph( const ParagraphData& ); |
143 | |
144 | sal_Int16 GetDepth() const { return nDepth; } |
145 | |
146 | sal_Int16 GetNumberingStartValue() const { return mnNumberingStartValue; } |
147 | void SetNumberingStartValue( sal_Int16 nNumberingStartValue ); |
148 | |
149 | bool IsParaIsNumberingRestart() const { return mbParaIsNumberingRestart; } |
150 | void SetParaIsNumberingRestart( bool bParaIsNumberingRestart ); |
151 | |
152 | void SetFlag( ParaFlag nFlag ) { nFlags |= nFlag; } |
153 | void RemoveFlag( ParaFlag nFlag ) { nFlags &= ~nFlag; } |
154 | bool HasFlag( ParaFlag nFlag ) const { return bool(nFlags & nFlag); } |
155 | public: |
156 | ~Paragraph(); |
157 | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
158 | }; |
159 | |
160 | struct ParaRange |
161 | { |
162 | sal_Int32 nStartPara; |
163 | sal_Int32 nEndPara; |
164 | |
165 | ParaRange( sal_Int32 nS, sal_Int32 nE ) : nStartPara(nS), nEndPara(nE) {} |
166 | |
167 | void Adjust(); |
168 | }; |
169 | |
170 | inline void ParaRange::Adjust() |
171 | { |
172 | if ( nStartPara > nEndPara ) |
173 | { |
174 | std::swap(nStartPara, nEndPara); |
175 | } |
176 | } |
177 | |
178 | class EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) OutlinerView final |
179 | { |
180 | friend class Outliner; |
181 | |
182 | Outliner* pOwner; |
183 | std::unique_ptr<EditView> pEditView; |
184 | |
185 | enum class MouseTarget { |
186 | Text = 0, |
187 | Bullet = 1, |
188 | Hypertext = 2, // Outside OutputArea |
189 | Outside = 3 // Outside OutputArea |
190 | }; |
191 | |
192 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) void ImplExpandOrCollaps( sal_Int32 nStartPara, sal_Int32 nEndPara, bool bExpand ); |
193 | |
194 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) sal_Int32 ImpCheckMousePos( const Point& rPosPixel, MouseTarget& reTarget); |
195 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) void ImpToggleExpand( Paragraph const * pParentPara ); |
196 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) ParaRange ImpGetSelectedParagraphs( bool bIncludeHiddenChildren ); |
197 | |
198 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) sal_Int32 ImpInitPaste( sal_Int32& rStart ); |
199 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) void ImpPasted( sal_Int32 nStart, sal_Int32 nPrevParaCount, sal_Int32 nSize); |
200 | EDITENG_DLLPRIVATE__attribute__ ((visibility("hidden"))) sal_Int32 ImpCalcSelectedPages( bool bIncludeFirstSelected ); |
201 | |
202 | Link<LinkParamNone*,void> aEndCutPasteLink; |
203 | |
204 | public: |
205 | OutlinerView( Outliner* pOut, vcl::Window* pWindow ); |
206 | ~OutlinerView(); |
207 | |
208 | EditView& GetEditView() const { return *pEditView; } |
209 | |
210 | void Scroll( long nHorzScroll, long nVertScroll ); |
211 | |
212 | void Paint( const tools::Rectangle& rRect, OutputDevice* pTargetDevice = nullptr ); |
213 | bool PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFrameWin = nullptr ); |
214 | bool MouseButtonDown( const MouseEvent& ); |
215 | bool MouseButtonUp( const MouseEvent& ); |
216 | void ReleaseMouse(); |
217 | bool MouseMove( const MouseEvent& ); |
218 | |
219 | void ShowCursor( bool bGotoCursor = true, bool bActivate = false ); |
220 | void HideCursor( bool bDeactivate = false ); |
221 | |
222 | Outliner* GetOutliner() const { return pOwner; } |
223 | |
224 | void SetWindow( vcl::Window* pWindow ); |
225 | vcl::Window* GetWindow() const; |
226 | |
227 | void SetReadOnly( bool bReadOnly ); |
228 | bool IsReadOnly() const; |
229 | |
230 | void SetOutputArea( const tools::Rectangle& rRect ); |
231 | tools::Rectangle const & GetOutputArea() const; |
232 | |
233 | tools::Rectangle const & GetVisArea() const; |
234 | |
235 | void CreateSelectionList (std::vector<Paragraph*> &aSelList) ; |
236 | |
237 | void Select( Paragraph const * pParagraph, bool bSelect = true); |
238 | |
239 | OUString GetSelected() const; |
240 | void SelectRange( sal_Int32 nFirst, sal_Int32 nCount ); |
241 | void SetAttribs( const SfxItemSet& ); |
242 | void Indent( short nDiff ); |
243 | void AdjustDepth( short nDX ); // Later replace with Indent! |
244 | |
245 | void AdjustHeight( long nDY ); |
246 | |
247 | void Read( SvStream& rInput, EETextFormat eFormat, SvKeyValueIterator* pHTTPHeaderAttrs ); |
248 | |
249 | void InsertText( const OUString& rNew, bool bSelect = false ); |
250 | void InsertText( const OutlinerParaObject& rParaObj ); |
251 | void Expand(); |
252 | void Collapse(); |
253 | void ExpandAll(); |
254 | void CollapseAll(); |
255 | |
256 | void SetBackgroundColor( const Color& rColor ); |
257 | Color const & GetBackgroundColor() const; |
258 | |
259 | /// Informs this edit view about which view shell contains it. |
260 | void RegisterViewShell(OutlinerViewShell* pViewShell); |
261 | |
262 | SfxItemSet GetAttribs(); |
263 | |
264 | void Cut(); |
265 | void Copy(); |
266 | void Paste( bool bUseSpecial = false ); |
267 | void PasteSpecial(); |
268 | |
269 | const SfxStyleSheet* GetStyleSheet() const; |
270 | SfxStyleSheet* GetStyleSheet(); |
271 | |
272 | void SetControlWord( EVControlBits nWord ); |
273 | EVControlBits GetControlWord() const; |
274 | |
275 | void SetAnchorMode( EEAnchorMode eMode ); |
276 | EEAnchorMode GetAnchorMode() const; |
277 | |
278 | PointerStyle GetPointer( const Point& rPosPixel ); |
279 | void Command( const CommandEvent& rCEvt ); |
280 | |
281 | void StartSpeller(); |
282 | EESpellState StartThesaurus(); |
283 | sal_Int32 StartSearchAndReplace( const SvxSearchItem& rSearchItem ); |
284 | |
285 | // for text conversion |
286 | void StartTextConversion( LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont, sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc ); |
287 | |
288 | void TransliterateText( TransliterationFlags nTransliterationMode ); |
289 | |
290 | ESelection GetSelection() const; |
291 | |
292 | SvtScriptType GetSelectedScriptType() const; |
293 | |
294 | void SetVisArea( const tools::Rectangle& rRect ); |
295 | void SetSelection( const ESelection& ); |
296 | void GetSelectionRectangles(std::vector<tools::Rectangle>& rLogicRects) const; |
297 | |
298 | void RemoveAttribs( bool bRemoveParaAttribs, bool bKeepLanguages = false ); |
299 | void RemoveAttribsKeepLanguages( bool bRemoveParaAttribs ); |
300 | bool HasSelection() const; |
301 | |
302 | void InsertField( const SvxFieldItem& rFld ); |
303 | const SvxFieldItem* GetFieldUnderMousePointer() const; |
304 | const SvxFieldItem* GetFieldAtSelection() const; |
305 | /// Return the field at the current cursor position or nullptr if no field found |
306 | const SvxFieldData* GetFieldAtCursor() const; |
307 | /// Select the field at the current cursor position |
308 | void SelectFieldAtCursor(); |
309 | |
310 | /** enables bullets for the selected paragraphs if the bullets/numbering of the first paragraph is off |
311 | or disables bullets/numbering for the selected paragraphs if the bullets/numbering of the first paragraph is on |
312 | */ |
313 | void ToggleBullets(); |
314 | |
315 | void ToggleBulletsNumbering( |
316 | const bool bToggle, |
317 | const bool bHandleBullets, |
318 | const SvxNumRule* pNumRule ); |
319 | |
320 | /** apply bullets/numbering for paragraphs |
321 | |
322 | @param boolean bHandleBullets |
323 | true: handle bullets |
324 | false: handle numbering |
325 | |
326 | @param pNewNumRule |
327 | numbering rule which needs to be applied. can be 0. |
328 | |
329 | @param boolean bAtSelection |
330 | true: apply bullets/numbering at selected paragraphs |
331 | false: apply bullets/numbering at all paragraphs |
332 | */ |
333 | void ApplyBulletsNumbering( |
334 | const bool bHandleBullets, |
335 | const SvxNumRule* pNewNumRule, |
336 | const bool bCheckCurrentNumRuleBeforeApplyingNewNumRule, |
337 | const bool bAtSelection = false ); |
338 | |
339 | /** switch off bullets/numbering for paragraphs |
340 | |
341 | @param boolean bAtSelection |
342 | true: switch off bullets/numbering at selected paragraphs |
343 | false: switch off bullets/numbering at all paragraphs |
344 | */ |
345 | void SwitchOffBulletsNumbering( |
346 | const bool bAtSelection = false ); |
347 | |
348 | bool IsCursorAtWrongSpelledWord(); |
349 | bool IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWrong = false ); |
350 | void ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo&,void> const * pCallBack ); |
351 | |
352 | void SetInvalidateMore( sal_uInt16 nPixel ); |
353 | sal_uInt16 GetInvalidateMore() const; |
354 | |
355 | OUString GetSurroundingText() const; |
356 | Selection GetSurroundingTextSelection() const; |
357 | |
358 | void SetEndCutPasteLinkHdl(const Link<LinkParamNone*,void> &rLink) { aEndCutPasteLink = rLink; } |
359 | }; |
360 | |
361 | /// Interface class to not depend on SfxViewShell in editeng. |
362 | class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) OutlinerViewShell |
363 | { |
364 | public: |
365 | virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const = 0; |
366 | virtual ViewShellId GetViewShellId() const = 0; |
367 | virtual void SetDocId(ViewShellDocId nId) = 0; |
368 | virtual ViewShellDocId GetDocId() const = 0; |
369 | /// Wrapper around SfxLokHelper::notifyOtherViews(). |
370 | virtual void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) = 0; |
371 | /// Wrapper around SfxLokHelper::notifyOtherView(). |
372 | virtual void NotifyOtherView(OutlinerViewShell* pOtherShell, int nType, const OString& rKey, const OString& rPayload) = 0; |
373 | virtual vcl::Window* GetEditWindowForActiveOLEObj() const = 0; |
374 | |
375 | protected: |
376 | ~OutlinerViewShell() throw () {} |
377 | }; |
378 | |
379 | // some thesaurus functionality to avoid code duplication in different projects... |
380 | bool EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) GetStatusValueForThesaurusFromContext( OUString &rStatusVal, LanguageType &rLang, const EditView &rEditView ); |
381 | void EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) ReplaceTextWithSynonym( EditView &rEditView, const OUString &rSynonmText ); |
382 | |
383 | typedef ::std::vector< OutlinerView* > ViewList; |
384 | |
385 | class EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) DrawPortionInfo |
386 | { |
387 | public: |
388 | const Point& mrStartPos; |
389 | const OUString maText; |
390 | sal_Int32 mnTextStart; |
391 | sal_Int32 mnTextLen; |
392 | sal_Int32 mnPara; |
393 | const SvxFont& mrFont; |
394 | const long* mpDXArray; |
395 | |
396 | const EEngineData::WrongSpellVector* mpWrongSpellVector; |
397 | const SvxFieldData* mpFieldData; |
398 | const css::lang::Locale* mpLocale; |
399 | const Color maOverlineColor; |
400 | const Color maTextLineColor; |
401 | |
402 | sal_uInt8 mnBiDiLevel; |
403 | |
404 | bool mbFilled; |
405 | long mnWidthToFill; |
406 | |
407 | bool mbEndOfLine : 1; |
408 | bool mbEndOfParagraph : 1; |
409 | bool mbEndOfBullet : 1; |
410 | |
411 | bool IsRTL() const { return mnBiDiLevel % 2 == 1; } |
412 | |
413 | DrawPortionInfo( |
414 | const Point& rPos, |
415 | const OUString& rTxt, |
416 | sal_Int32 nTxtStart, |
417 | sal_Int32 nTxtLen, |
418 | const SvxFont& rFnt, |
419 | sal_Int32 nPar, |
420 | const long* pDXArr, |
421 | const EEngineData::WrongSpellVector* pWrongSpellVector, |
422 | const SvxFieldData* pFieldData, |
423 | const css::lang::Locale* pLocale, |
424 | const Color& rOverlineColor, |
425 | const Color& rTextLineColor, |
426 | sal_uInt8 nBiDiLevel, |
427 | bool bFilled, |
428 | long nWidthToFill, |
429 | bool bEndOfLine, |
430 | bool bEndOfParagraph, |
431 | bool bEndOfBullet) |
432 | : mrStartPos(rPos), |
433 | maText(rTxt), |
434 | mnTextStart(nTxtStart), |
435 | mnTextLen(nTxtLen), |
436 | mnPara(nPar), |
437 | mrFont(rFnt), |
438 | mpDXArray(pDXArr), |
439 | mpWrongSpellVector(pWrongSpellVector), |
440 | mpFieldData(pFieldData), |
441 | mpLocale(pLocale), |
442 | maOverlineColor(rOverlineColor), |
443 | maTextLineColor(rTextLineColor), |
444 | mnBiDiLevel(nBiDiLevel), |
445 | mbFilled( bFilled ), |
446 | mnWidthToFill( nWidthToFill ), |
447 | mbEndOfLine(bEndOfLine), |
448 | mbEndOfParagraph(bEndOfParagraph), |
449 | mbEndOfBullet(bEndOfBullet) |
450 | {} |
451 | }; |
452 | |
453 | class EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) DrawBulletInfo |
454 | { |
455 | public: |
456 | const GraphicObject maBulletGraphicObject; |
457 | Point maBulletPosition; |
458 | Size maBulletSize; |
459 | |
460 | DrawBulletInfo( |
461 | const GraphicObject& rBulletGraphicObject, |
462 | const Point& rBulletPosition, |
463 | const Size& rBulletSize) |
464 | : maBulletGraphicObject(rBulletGraphicObject), |
465 | maBulletPosition(rBulletPosition), |
466 | maBulletSize(rBulletSize) |
467 | {} |
468 | }; |
469 | |
470 | struct EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) PaintFirstLineInfo |
471 | { |
472 | sal_Int32 mnPara; |
473 | const Point& mrStartPos; |
474 | VclPtr<OutputDevice> mpOutDev; |
475 | |
476 | PaintFirstLineInfo( sal_Int32 nPara, const Point& rStartPos, OutputDevice* pOutDev ) |
477 | : mnPara( nPara ), mrStartPos( rStartPos ), mpOutDev( pOutDev ) |
478 | {} |
479 | }; |
480 | |
481 | class SdrPage; |
482 | |
483 | class EditFieldInfo |
484 | { |
485 | private: |
486 | Outliner* pOutliner; |
487 | const SvxFieldItem& rFldItem; |
488 | |
489 | std::optional<Color> mxTxtColor; |
490 | std::optional<Color> mxFldColor; |
491 | |
492 | OUString aRepresentation; |
493 | |
494 | sal_Int32 nPara; |
495 | sal_Int32 nPos; |
496 | |
497 | EditFieldInfo( const EditFieldInfo& ) = delete; |
498 | |
499 | SdrPage* mpSdrPage; |
500 | |
501 | public: |
502 | EditFieldInfo( Outliner* pOutl, const SvxFieldItem& rFItem, sal_Int32 nPa, sal_Int32 nPo ) |
503 | : rFldItem( rFItem ) |
504 | { |
505 | pOutliner = pOutl; |
506 | nPara = nPa; nPos = nPo; |
507 | mpSdrPage = nullptr; |
508 | } |
509 | |
510 | Outliner* GetOutliner() const { return pOutliner; } |
511 | |
512 | const SvxFieldItem& GetField() const { return rFldItem; } |
513 | |
514 | std::optional<Color> const & GetTextColor() const { return mxTxtColor; } |
515 | void SetTextColor( std::optional<Color> xCol ) { mxTxtColor = xCol; } |
516 | |
517 | std::optional<Color> const & GetFieldColor() const { return mxFldColor; } |
518 | void SetFieldColor( std::optional<Color> xCol ) { mxFldColor = xCol; } |
519 | |
520 | sal_Int32 GetPara() const { return nPara; } |
521 | sal_Int32 GetPos() const { return nPos; } |
522 | |
523 | const OUString& GetRepresentation() const { return aRepresentation; } |
524 | OUString& GetRepresentation() { return aRepresentation; } |
525 | void SetRepresentation( const OUString& rStr ){ aRepresentation = rStr; } |
526 | |
527 | void SetSdrPage( SdrPage* pPage ) { mpSdrPage = pPage; } |
528 | SdrPage* GetSdrPage() const { return mpSdrPage; } |
529 | }; |
530 | |
531 | struct EBulletInfo |
532 | { |
533 | SvxFont aFont; |
534 | tools::Rectangle aBounds; |
535 | OUString aText; |
536 | sal_Int32 nParagraph; |
537 | sal_uInt16 nType; // see SvxNumberType |
538 | bool bVisible; |
539 | |
540 | EBulletInfo() : nParagraph( EE_PARA_NOT_FOUND((sal_Int32) 0x7FFFFFFF) ), nType( 0 ), bVisible( false ) {} |
541 | }; |
542 | |
543 | enum class OutlinerMode { |
544 | DontKnow = 0x0000, |
545 | TextObject = 0x0001, |
546 | TitleObject = 0x0002, |
547 | OutlineObject = 0x0003, |
548 | OutlineView = 0x0004 |
549 | }; |
550 | |
551 | class EDITENG_DLLPUBLIC__attribute__ ((visibility("default"))) Outliner : public SfxBroadcaster |
552 | { |
553 | public: |
554 | struct ParagraphHdlParam { Outliner* pOutliner; Paragraph* pPara; }; |
555 | struct DepthChangeHdlParam { Outliner* pOutliner; Paragraph* pPara; ParaFlag nPrevFlags; }; |
556 | private: |
557 | friend class OutlinerView; |
558 | friend class OutlinerEditEng; |
559 | friend class OutlinerParaObject; |
560 | friend class OLUndoExpand; |
561 | friend class OutlinerUndoChangeDepth; |
562 | friend class OutlinerUndoCheckPara; |
563 | friend class OutlinerUndoChangeParaFlags; |
564 | |
565 | friend class TextChainingUtils; |
566 | |
567 | std::unique_ptr<OutlinerEditEng> pEditEngine; |
568 | |
569 | std::unique_ptr<ParagraphList> pParaList; |
570 | ViewList aViewList; |
571 | |
572 | sal_Int32 mnFirstSelPage; |
573 | Link<DrawPortionInfo*,void> aDrawPortionHdl; |
574 | Link<DrawBulletInfo*,void> aDrawBulletHdl; |
575 | Link<ParagraphHdlParam,void> aParaInsertedHdl; |
576 | Link<ParagraphHdlParam,void> aParaRemovingHdl; |
577 | Link<DepthChangeHdlParam,void> aDepthChangedHdl; |
578 | Link<Outliner*,void> aBeginMovingHdl; |
579 | Link<Outliner*,void> aEndMovingHdl; |
580 | Link<OutlinerView*,bool> aIndentingPagesHdl; |
581 | Link<OutlinerView*,bool> aRemovingPagesHdl; |
582 | Link<EditFieldInfo*,void> aCalcFieldValueHdl; |
583 | Link<PaintFirstLineInfo*,void> maPaintFirstLineHdl; |
584 | Link<PasteOrDropInfos*,void> maBeginPasteOrDropHdl; |
585 | Link<PasteOrDropInfos*,void> maEndPasteOrDropHdl; |
586 | |
587 | sal_Int32 nDepthChangedHdlPrevDepth; |
588 | sal_Int16 nMaxDepth; |
589 | static constexpr sal_Int16 gnMinDepth = -1; |
590 | |
591 | OutlinerMode nOutlinerMode; |
592 | |
593 | bool bFirstParaIsEmpty; |
594 | sal_uInt8 nBlockInsCallback; |
595 | bool bStrippingPortions; |
596 | bool bPasting; |
597 | |
598 | DECL_LINK( ParaVisibleStateChangedHdl, Paragraph&, void )static void LinkStubParaVisibleStateChangedHdl(void *, Paragraph &); void ParaVisibleStateChangedHdl(Paragraph&); |
599 | DECL_LINK( BeginMovingParagraphsHdl, MoveParagraphsInfo&, void )static void LinkStubBeginMovingParagraphsHdl(void *, MoveParagraphsInfo &); void BeginMovingParagraphsHdl(MoveParagraphsInfo& ); |
600 | DECL_LINK( EndMovingParagraphsHdl, MoveParagraphsInfo&, void )static void LinkStubEndMovingParagraphsHdl(void *, MoveParagraphsInfo &); void EndMovingParagraphsHdl(MoveParagraphsInfo&); |
601 | DECL_LINK( BeginPasteOrDropHdl, PasteOrDropInfos&, void )static void LinkStubBeginPasteOrDropHdl(void *, PasteOrDropInfos &); void BeginPasteOrDropHdl(PasteOrDropInfos&); |
602 | DECL_LINK( EndPasteOrDropHdl, PasteOrDropInfos&, void )static void LinkStubEndPasteOrDropHdl(void *, PasteOrDropInfos &); void EndPasteOrDropHdl(PasteOrDropInfos&); |
603 | DECL_LINK( EditEngineNotifyHdl, EENotify&, void )static void LinkStubEditEngineNotifyHdl(void *, EENotify& ); void EditEngineNotifyHdl(EENotify&); |
604 | void ImplCheckParagraphs( sal_Int32 nStart, sal_Int32 nEnd ); |
605 | bool ImplHasNumberFormat( sal_Int32 nPara ) const; |
606 | Size ImplGetBulletSize( sal_Int32 nPara ); |
607 | sal_uInt16 ImplGetNumbering( sal_Int32 nPara, const SvxNumberFormat* pParaFmt ); |
608 | void ImplCalcBulletText( sal_Int32 nPara, bool bRecalcLevel, bool bRecalcChildren ); |
609 | OUString ImplGetBulletText( sal_Int32 nPara ); |
610 | void ImplCheckNumBulletItem( sal_Int32 nPara ); |
611 | void ImplInitDepth( sal_Int32 nPara, sal_Int16 nDepth, bool bCreateUndo ); |
612 | void ImplSetLevelDependentStyleSheet( sal_Int32 nPara ); |
613 | |
614 | void ImplBlockInsertionCallbacks( bool b ); |
615 | |
616 | void ImpFilterIndents( sal_Int32 nFirstPara, sal_Int32 nLastPara ); |
617 | bool ImpConvertEdtToOut( sal_Int32 nPara ); |
618 | |
619 | void ImpTextPasted( sal_Int32 nStartPara, sal_Int32 nCount ); |
620 | vcl::Font ImpCalcBulletFont( sal_Int32 nPara ) const; |
621 | tools::Rectangle ImpCalcBulletArea( sal_Int32 nPara, bool bAdjust, bool bReturnPaperPos ); |
622 | bool ImpCanIndentSelectedPages( OutlinerView* pCurView ); |
623 | bool ImpCanDeleteSelectedPages( OutlinerView* pCurView ); |
624 | bool ImpCanDeleteSelectedPages( OutlinerView* pCurView, sal_Int32 nFirstPage, sal_Int32 nPages ); |
625 | |
626 | OutlinerMode ImplGetOutlinerMode() const { return nOutlinerMode; } |
627 | void ImplCheckDepth( sal_Int16& rnDepth ) const; |
628 | |
629 | protected: |
630 | void ParagraphInserted( sal_Int32 nParagraph ); |
631 | void ParagraphDeleted( sal_Int32 nParagraph ); |
632 | void ParaAttribsChanged( sal_Int32 nParagraph ); |
633 | |
634 | void StyleSheetChanged( SfxStyleSheet const * pStyle ); |
635 | |
636 | void InvalidateBullet(sal_Int32 nPara); |
637 | void PaintBullet( sal_Int32 nPara, const Point& rStartPos, |
638 | const Point& rOrigin, short nOrientation, |
639 | OutputDevice* pOutDev ); |
640 | |
641 | // used by OutlinerEditEng. Allows Outliner objects to provide |
642 | // bullet access to the EditEngine. |
643 | const SvxNumberFormat* GetNumberFormat( sal_Int32 nPara ) const; |
644 | |
645 | public: |
646 | |
647 | Outliner( SfxItemPool* pPool, OutlinerMode nOutlinerMode ); |
648 | virtual ~Outliner() override; |
649 | |
650 | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
651 | |
652 | void Init( OutlinerMode nOutlinerMode ); |
653 | OutlinerMode GetMode() const { return nOutlinerMode; } |
654 | |
655 | void SetVertical( bool bVertical); |
656 | void SetRotation(TextRotation nRotation); |
657 | bool IsVertical() const; |
658 | bool IsTopToBottom() const; |
659 | |
660 | void SetFixedCellHeight( bool bUseFixedCellHeight ); |
661 | |
662 | void SetDefaultHorizontalTextDirection( EEHorizontalTextDirection eHTextDir ); |
663 | EEHorizontalTextDirection GetDefaultHorizontalTextDirection() const; |
664 | |
665 | LanguageType GetLanguage( sal_Int32 nPara, sal_Int32 nPos ) const; |
666 | |
667 | void SetAsianCompressionMode( CharCompressType nCompressionMode ); |
668 | |
669 | void SetKernAsianPunctuation( bool bEnabled ); |
670 | |
671 | void SetAddExtLeading( bool b ); |
672 | |
673 | size_t InsertView( OutlinerView* pView, size_t nIndex = size_t(-1) ); |
674 | void RemoveView( OutlinerView const * pView ); |
675 | void RemoveView( size_t nIndex ); |
676 | OutlinerView* GetView( size_t nIndex ) const; |
677 | size_t GetViewCount() const; |
678 | |
679 | Paragraph* Insert( const OUString& rText, sal_Int32 nAbsPos = EE_PARA_APPEND((sal_Int32) 0x7FFFFFFF), sal_Int16 nDepth = 0 ); |
680 | void SetText( const OutlinerParaObject& ); |
681 | void AddText( const OutlinerParaObject&, bool bAppend = false ); |
682 | void SetText( const OUString& rText, Paragraph* pParagraph ); |
683 | OUString GetText( Paragraph const * pPara, sal_Int32 nParaCount=1 ) const; |
684 | |
685 | void SetToEmptyText(); |
686 | |
687 | std::unique_ptr<OutlinerParaObject> CreateParaObject( sal_Int32 nStartPara = 0, sal_Int32 nParaCount = EE_PARA_ALL((sal_Int32) 0x7FFFFFFF) ) const; |
688 | |
689 | const SfxItemSet& GetEmptyItemSet() const; |
690 | |
691 | void SetRefMapMode( const MapMode& ); |
692 | MapMode const & GetRefMapMode() const; |
693 | |
694 | void SetBackgroundColor( const Color& rColor ); |
695 | Color const & GetBackgroundColor() const; |
696 | |
697 | void SetMaxDepth( sal_Int16 nDepth ); |
698 | sal_Int16 GetMaxDepth() const { return nMaxDepth; } |
699 | |
700 | void SetUpdateMode( bool bUpdate ); |
701 | bool GetUpdateMode() const; |
702 | |
703 | void Clear(); |
704 | |
705 | void RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich ); |
706 | |
707 | sal_Int32 GetParagraphCount() const; |
708 | Paragraph* GetParagraph( sal_Int32 nAbsPos ) const; |
709 | |
710 | bool HasChildren( Paragraph const * pParagraph ) const; |
711 | sal_Int32 GetChildCount( Paragraph const * pParent ) const; |
712 | bool IsExpanded( Paragraph const * pPara ) const; |
713 | Paragraph* GetParent( Paragraph const * pParagraph ) const; |
714 | sal_Int32 GetAbsPos( Paragraph const * pPara ); |
715 | |
716 | sal_Int16 GetDepth( sal_Int32 nPara ) const; |
717 | void SetDepth( Paragraph* pParagraph, sal_Int16 nNewDepth ); |
718 | |
719 | void EnableUndo( bool bEnable ); |
720 | bool IsUndoEnabled() const; |
721 | void UndoActionStart( sal_uInt16 nId ); |
722 | void UndoActionEnd(); |
723 | void InsertUndo( std::unique_ptr<EditUndo> pUndo ); |
724 | bool IsInUndo() const; |
725 | |
726 | void ClearModifyFlag(); |
727 | bool IsModified() const; |
728 | |
729 | void ParagraphInsertedHdl(Paragraph*); |
730 | void SetParaInsertedHdl(const Link<ParagraphHdlParam,void>& rLink){aParaInsertedHdl=rLink;} |
731 | const Link<ParagraphHdlParam,void>& GetParaInsertedHdl() const { return aParaInsertedHdl; } |
732 | |
733 | void SetParaRemovingHdl(const Link<ParagraphHdlParam,void>& rLink){aParaRemovingHdl=rLink;} |
734 | const Link<ParagraphHdlParam,void>& GetParaRemovingHdl() const { return aParaRemovingHdl; } |
735 | |
736 | std::unique_ptr<NonOverflowingText> GetNonOverflowingText() const; |
737 | std::unique_ptr<OverflowingText> GetOverflowingText() const; |
738 | void ClearOverflowingParaNum(); |
739 | bool IsPageOverflow(); |
740 | |
741 | std::unique_ptr<OutlinerParaObject> GetEmptyParaObject() const; |
742 | |
743 | |
744 | void DepthChangedHdl(Paragraph*, ParaFlag nPrevFlags); |
745 | void SetDepthChangedHdl(const Link<DepthChangeHdlParam,void>& rLink){aDepthChangedHdl=rLink;} |
746 | const Link<DepthChangeHdlParam,void>& GetDepthChangedHdl() const { return aDepthChangedHdl; } |
747 | sal_Int16 GetPrevDepth() const { return static_cast<sal_Int16>(nDepthChangedHdlPrevDepth); } |
748 | |
749 | bool RemovingPagesHdl( OutlinerView* ); |
750 | void SetRemovingPagesHdl(const Link<OutlinerView*,bool>& rLink){aRemovingPagesHdl=rLink;} |
751 | bool IndentingPagesHdl( OutlinerView* ); |
752 | void SetIndentingPagesHdl(const Link<OutlinerView*,bool>& rLink){aIndentingPagesHdl=rLink;} |
753 | // valid only in the two upper handlers |
754 | sal_Int32 GetSelPageCount() const { return nDepthChangedHdlPrevDepth; } |
755 | |
756 | void SetCalcFieldValueHdl(const Link<EditFieldInfo*,void>& rLink ) { aCalcFieldValueHdl= rLink; } |
757 | const Link<EditFieldInfo*,void>& GetCalcFieldValueHdl() const { return aCalcFieldValueHdl; } |
758 | |
759 | void SetDrawPortionHdl(const Link<DrawPortionInfo*,void>& rLink){aDrawPortionHdl=rLink;} |
760 | |
761 | void SetDrawBulletHdl(const Link<DrawBulletInfo*,void>& rLink){aDrawBulletHdl=rLink;} |
762 | |
763 | void SetPaintFirstLineHdl(const Link<PaintFirstLineInfo*,void>& rLink) { maPaintFirstLineHdl = rLink; } |
764 | |
765 | void SetModifyHdl( const Link<LinkParamNone*,void>& rLink ); |
766 | Link<LinkParamNone*,void> const & GetModifyHdl() const; |
767 | |
768 | void SetNotifyHdl( const Link<EENotify&,void>& rLink ); |
769 | |
770 | void SetStatusEventHdl( const Link<EditStatus&, void>& rLink ); |
771 | Link<EditStatus&, void> const & GetStatusEventHdl() const; |
772 | |
773 | void Draw( OutputDevice* pOutDev, const tools::Rectangle& rOutRect ); |
774 | void Draw( OutputDevice* pOutDev, const Point& rStartPos ); |
775 | |
776 | const Size& GetPaperSize() const; |
777 | void SetPaperSize( const Size& rSize ); |
778 | |
779 | void SetPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon ); |
780 | void SetPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DPolyPolygon* pLinePolyPolygon); |
781 | void ClearPolygon(); |
782 | |
783 | const Size& GetMinAutoPaperSize() const; |
784 | void SetMinAutoPaperSize( const Size& rSz ); |
785 | |
786 | const Size& GetMaxAutoPaperSize() const; |
787 | void SetMaxAutoPaperSize( const Size& rSz ); |
788 | |
789 | void SetDefTab( sal_uInt16 nTab ); |
790 | |
791 | bool IsFlatMode() const; |
792 | void SetFlatMode( bool bFlat ); |
793 | |
794 | void EnableAutoColor( bool b ); |
795 | |
796 | void ForceAutoColor( bool b ); |
797 | bool IsForceAutoColor() const; |
798 | |
799 | EBulletInfo GetBulletInfo( sal_Int32 nPara ); |
800 | |
801 | void SetWordDelimiters( const OUString& rDelimiters ); |
802 | OUString const & GetWordDelimiters() const; |
803 | OUString GetWord( sal_Int32 nPara, sal_Int32 nIndex ); |
804 | |
805 | void StripPortions(); |
806 | |
807 | void DrawingText( const Point& rStartPos, const OUString& rText, |
808 | sal_Int32 nTextStart, sal_Int32 nTextLen, |
809 | const long* pDXArray, const SvxFont& rFont, |
810 | sal_Int32 nPara, sal_uInt8 nRightToLeft, |
811 | const EEngineData::WrongSpellVector* pWrongSpellVector, |
812 | const SvxFieldData* pFieldData, |
813 | bool bEndOfLine, |
814 | bool bEndOfParagraph, |
815 | bool bEndOfBullet, |
816 | const css::lang::Locale* pLocale, |
817 | const Color& rOverlineColor, |
818 | const Color& rTextLineColor); |
819 | |
820 | void DrawingTab( const Point& rStartPos, long nWidth, const OUString& rChar, |
821 | const SvxFont& rFont, sal_Int32 nPara, sal_uInt8 nRightToLeft, |
822 | bool bEndOfLine, |
823 | bool bEndOfParagraph, |
824 | const Color& rOverlineColor, |
825 | const Color& rTextLineColor); |
826 | |
827 | Size CalcTextSize(); |
828 | Size CalcTextSizeNTP(); |
829 | |
830 | void SetStyleSheetPool( SfxStyleSheetPool* pSPool ); |
831 | SfxStyleSheetPool* GetStyleSheetPool(); |
832 | |
833 | bool IsInSelectionMode() const; |
834 | |
835 | void SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle ); |
836 | SfxStyleSheet* GetStyleSheet( sal_Int32 nPara ); |
837 | |
838 | void SetParaAttribs( sal_Int32 nPara, const SfxItemSet& ); |
839 | SfxItemSet const & GetParaAttribs( sal_Int32 nPara ); |
840 | |
841 | void Remove( Paragraph const * pPara, sal_Int32 nParaCount ); |
842 | bool Expand( Paragraph const * ); |
843 | bool Collapse( Paragraph const * ); |
844 | |
845 | void SetParaFlag( Paragraph* pPara, ParaFlag nFlag ); |
846 | static bool HasParaFlag( const Paragraph* pPara, ParaFlag nFlag ); |
847 | |
848 | |
849 | void SetControlWord( EEControlBits nWord ); |
850 | EEControlBits GetControlWord() const; |
851 | |
852 | const Link<Outliner*,void>& GetBeginMovingHdl() const { return aBeginMovingHdl; } |
853 | void SetBeginMovingHdl(const Link<Outliner*,void>& rLink) {aBeginMovingHdl=rLink;} |
854 | const Link<Outliner*,void>& GetEndMovingHdl() const {return aEndMovingHdl;} |
855 | void SetEndMovingHdl( const Link<Outliner*,void>& rLink){aEndMovingHdl=rLink;} |
856 | |
857 | sal_uLong GetLineCount( sal_Int32 nParagraph ) const; |
858 | sal_Int32 GetLineLen( sal_Int32 nParagraph, sal_Int32 nLine ) const; |
859 | sal_uLong GetLineHeight( sal_Int32 nParagraph ); |
860 | |
861 | ErrCode Read( SvStream& rInput, const OUString& rBaseURL, EETextFormat, SvKeyValueIterator* pHTTPHeaderAttrs = nullptr ); |
862 | |
863 | SfxUndoManager& GetUndoManager(); |
864 | SfxUndoManager* SetUndoManager(SfxUndoManager* pNew); |
865 | |
866 | void QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ); |
867 | void QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ); |
868 | void QuickInsertLineBreak( const ESelection& rSel ); |
869 | |
870 | // Only for EditEngine mode |
871 | void QuickInsertText( const OUString& rText, const ESelection& rSel ); |
872 | void QuickDelete( const ESelection& rSel ); |
873 | /// Set attributes from rSet an all characters of nPara. |
874 | void SetCharAttribs(sal_Int32 nPara, const SfxItemSet& rSet); |
875 | void RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich = 0 ); |
876 | void QuickFormatDoc(); |
877 | |
878 | bool UpdateFields(); |
879 | void RemoveFields( const std::function<bool ( const SvxFieldData* )>& isFieldData = [] (const SvxFieldData* ){return true;} ); |
880 | |
881 | virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rTxtColor, std::optional<Color>& rFldColor ); |
882 | |
883 | void SetSpeller( css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpeller ); |
884 | css::uno::Reference< css::linguistic2::XSpellChecker1 > const & |
885 | GetSpeller(); |
886 | void SetHyphenator( css::uno::Reference< css::linguistic2::XHyphenator > const & xHyph ); |
887 | |
888 | static void SetForbiddenCharsTable(const std::shared_ptr<SvxForbiddenCharactersTable>& xForbiddenChars); |
889 | |
890 | // Deprecated |
891 | void SetDefaultLanguage( LanguageType eLang ); |
892 | |
893 | void CompleteOnlineSpelling(); |
894 | |
895 | EESpellState HasSpellErrors(); |
896 | bool HasText( const SvxSearchItem& rSearchItem ); |
897 | virtual bool SpellNextDocument(); |
898 | |
899 | // for text conversion |
900 | bool HasConvertibleTextPortion( LanguageType nLang ); |
901 | virtual bool ConvertNextDocument(); |
902 | |
903 | void SetEditTextObjectPool( SfxItemPool* pPool ); |
904 | SfxItemPool* GetEditTextObjectPool() const; |
905 | |
906 | void SetRefDevice( OutputDevice* pRefDev ); |
907 | OutputDevice* GetRefDevice() const; |
908 | |
909 | sal_uLong GetTextHeight() const; |
910 | tools::Rectangle GetParaBounds( sal_Int32 nParagraph ) const; |
911 | Point GetDocPos( const Point& rPaperPos ) const; |
912 | bool IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder ); |
913 | bool IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder, bool* pbBulletPos ); |
914 | |
915 | void SetGlobalCharStretching( sal_uInt16 nX = 100, sal_uInt16 nY = 100 ); |
916 | void GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const; |
917 | void EraseVirtualDevice(); |
918 | |
919 | bool ShouldCreateBigTextObject() const; |
920 | |
921 | const EditEngine& GetEditEngine() const; |
922 | |
923 | // this is needed for StarOffice Api |
924 | void SetLevelDependentStyleSheet( sal_Int32 nPara ); |
925 | |
926 | OutlinerMode GetOutlinerMode() const { return nOutlinerMode; } |
927 | |
928 | // spell and return a sentence |
929 | bool SpellSentence(EditView const & rEditView, svx::SpellPortions& rToFill ); |
930 | // put spell position to start of current sentence |
931 | void PutSpellingToSentenceStart( EditView const & rEditView ); |
932 | // applies a changed sentence |
933 | void ApplyChangedSentence(EditView const & rEditView, const svx::SpellPortions& rNewPortions, bool bRecheck ); |
934 | |
935 | /** sets a link that is called at the beginning of a drag operation at an edit view */ |
936 | void SetBeginDropHdl( const Link<EditView*,void>& rLink ); |
937 | |
938 | /** sets a link that is called at the end of a drag operation at an edit view */ |
939 | void SetEndDropHdl( const Link<EditView*,void>& rLink ); |
940 | |
941 | /** sets a link that is called before a drop or paste operation. */ |
942 | void SetBeginPasteOrDropHdl( const Link<PasteOrDropInfos*,void>& rLink ); |
943 | |
944 | /** sets a link that is called after a drop or paste operation. */ |
945 | void SetEndPasteOrDropHdl( const Link<PasteOrDropInfos*,void>& rLink ); |
946 | |
947 | sal_Int16 GetNumberingStartValue( sal_Int32 nPara ); |
948 | void SetNumberingStartValue( sal_Int32 nPara, sal_Int16 nNumberingStartValue ); |
949 | |
950 | bool IsParaIsNumberingRestart( sal_Int32 nPara ); |
951 | void SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart ); |
952 | |
953 | /** determine the bullets/numbering status of the given paragraphs |
954 | |
955 | @param nParaStart |
956 | index of paragraph at which the check starts |
957 | |
958 | @param nParaEnd |
959 | index of paragraph at which the check ends |
960 | |
961 | @returns |
962 | 0 : all paragraphs have bullets |
963 | 1 : all paragraphs have numbering |
964 | 2 : otherwise |
965 | */ |
966 | sal_Int32 GetBulletsNumberingStatus( |
967 | const sal_Int32 nParaStart, |
968 | const sal_Int32 nParaEnd ) const; |
969 | |
970 | // convenient method to determine the bullets/numbering status for all paragraphs |
971 | sal_Int32 GetBulletsNumberingStatus() const; |
972 | }; |
973 | |
974 | #endif |
975 | |
976 | /* 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 |