File: | home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx |
Warning: | line 685, column 21 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 <memory> | ||||||
21 | #include <iderid.hxx> | ||||||
22 | #include <strings.hrc> | ||||||
23 | #include <helpids.h> | ||||||
24 | |||||||
25 | #include "baside2.hxx" | ||||||
26 | #include <baside3.hxx> | ||||||
27 | #include <basidesh.hxx> | ||||||
28 | #include <basobj.hxx> | ||||||
29 | #include <docsignature.hxx> | ||||||
30 | #include <iderdll.hxx> | ||||||
31 | #include "iderdll2.hxx" | ||||||
32 | #include <localizationmgr.hxx> | ||||||
33 | #include <managelang.hxx> | ||||||
34 | |||||||
35 | #include <basic/basmgr.hxx> | ||||||
36 | #include <com/sun/star/script/ModuleType.hpp> | ||||||
37 | #include <com/sun/star/script/XLibraryContainerPassword.hpp> | ||||||
38 | #include <com/sun/star/script/XLibraryContainer2.hpp> | ||||||
39 | #include <com/sun/star/frame/XLayoutManager.hpp> | ||||||
40 | #include <svl/srchdefs.hxx> | ||||||
41 | #include <sal/log.hxx> | ||||||
42 | #include <osl/diagnose.h> | ||||||
43 | #include <sfx2/app.hxx> | ||||||
44 | #include <sfx2/bindings.hxx> | ||||||
45 | #include <sfx2/childwin.hxx> | ||||||
46 | #include <sfx2/dinfdlg.hxx> | ||||||
47 | #include <sfx2/minfitem.hxx> | ||||||
48 | #include <sfx2/request.hxx> | ||||||
49 | #include <sfx2/viewfrm.hxx> | ||||||
50 | #include <svx/svxids.hrc> | ||||||
51 | #include <svl/eitem.hxx> | ||||||
52 | #include <svl/intitem.hxx> | ||||||
53 | #include <svl/visitem.hxx> | ||||||
54 | #include <svl/whiter.hxx> | ||||||
55 | #include <vcl/texteng.hxx> | ||||||
56 | #include <vcl/textview.hxx> | ||||||
57 | #include <vcl/svapp.hxx> | ||||||
58 | #include <vcl/weld.hxx> | ||||||
59 | |||||||
60 | constexpr sal_Int32 TAB_HEIGHT_MARGIN = 10; | ||||||
61 | |||||||
62 | namespace basctl | ||||||
63 | { | ||||||
64 | |||||||
65 | using namespace ::com::sun::star; | ||||||
66 | using namespace ::com::sun::star::uno; | ||||||
67 | using namespace ::com::sun::star::frame; | ||||||
68 | |||||||
69 | void Shell::ExecuteSearch( SfxRequest& rReq ) | ||||||
70 | { | ||||||
71 | if ( !pCurWin ) | ||||||
72 | return; | ||||||
73 | |||||||
74 | const SfxItemSet* pArgs = rReq.GetArgs(); | ||||||
75 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||
76 | |||||||
77 | // if searching has not been done before this time | ||||||
78 | if (nSlot == SID_BASICIDE_REPEAT_SEARCH((10000 + 500) + 3) && !mpSearchItem) | ||||||
79 | { | ||||||
80 | rReq.SetReturnValue(SfxBoolItem(nSlot, false)); | ||||||
81 | nSlot = 0; | ||||||
82 | } | ||||||
83 | |||||||
84 | switch ( nSlot ) | ||||||
85 | { | ||||||
86 | case SID_SEARCH_OPTIONS(10000 + 281): | ||||||
87 | break; | ||||||
88 | case SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291): | ||||||
89 | mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291)).Clone()); | ||||||
90 | break; | ||||||
91 | case FID_SEARCH_ON((10000 + 500) + 0): | ||||||
92 | mbJustOpened = true; | ||||||
93 | GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291)); | ||||||
94 | break; | ||||||
95 | case SID_BASICIDE_REPEAT_SEARCH((10000 + 500) + 3): | ||||||
96 | case FID_SEARCH_NOW((10000 + 500) + 2): | ||||||
97 | { | ||||||
98 | if (!pCurWin->HasActiveEditor()) | ||||||
99 | break; | ||||||
100 | |||||||
101 | // If it is a repeat searching | ||||||
102 | if ( nSlot == SID_BASICIDE_REPEAT_SEARCH((10000 + 500) + 3) ) | ||||||
103 | { | ||||||
104 | if( !mpSearchItem ) | ||||||
105 | mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291) )); | ||||||
106 | } | ||||||
107 | else | ||||||
108 | { | ||||||
109 | // Get SearchItem from request if it is the first searching | ||||||
110 | if ( pArgs ) | ||||||
111 | { | ||||||
112 | mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291)).Clone()); | ||||||
113 | } | ||||||
114 | } | ||||||
115 | |||||||
116 | sal_Int32 nFound = 0; | ||||||
117 | |||||||
118 | if ( mpSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL ) | ||||||
119 | { | ||||||
120 | sal_uInt16 nActModWindows = 0; | ||||||
121 | for (auto const& window : aWindowTable) | ||||||
122 | { | ||||||
123 | BaseWindow* pWin = window.second; | ||||||
124 | if (pWin->HasActiveEditor()) | ||||||
125 | nActModWindows++; | ||||||
126 | } | ||||||
127 | |||||||
128 | bool bAllModules = nActModWindows <= 1; | ||||||
129 | if (!bAllModules) | ||||||
130 | { | ||||||
131 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pCurWin ? pCurWin->GetFrameWeld() : nullptr, | ||||||
132 | VclMessageType::Question, VclButtonsType::YesNo, | ||||||
133 | IDEResId(RID_STR_SEARCHALLMODULESreinterpret_cast<char const *>("RID_STR_SEARCHALLMODULES" "\004" u8"Do you want to replace the text in all active modules?" )))); | ||||||
134 | xQueryBox->set_default_response(RET_YES); | ||||||
135 | bAllModules = xQueryBox->run() == RET_YES; | ||||||
136 | } | ||||||
137 | |||||||
138 | if (bAllModules) | ||||||
139 | { | ||||||
140 | for (auto const& window : aWindowTable) | ||||||
141 | { | ||||||
142 | BaseWindow* pWin = window.second; | ||||||
143 | nFound += pWin->StartSearchAndReplace( *mpSearchItem ); | ||||||
144 | } | ||||||
145 | } | ||||||
146 | else | ||||||
147 | nFound = pCurWin->StartSearchAndReplace( *mpSearchItem ); | ||||||
148 | |||||||
149 | OUString aReplStr(IDEResId(RID_STR_SEARCHREPLACESreinterpret_cast<char const *>("RID_STR_SEARCHREPLACES" "\004" u8"Search key replaced XX times"))); | ||||||
150 | aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound)); | ||||||
151 | |||||||
152 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(), | ||||||
153 | VclMessageType::Info, VclButtonsType::Ok, | ||||||
154 | aReplStr)); | ||||||
155 | xInfoBox->run(); | ||||||
156 | } | ||||||
157 | else | ||||||
158 | { | ||||||
159 | bool bCanceled = false; | ||||||
160 | nFound = pCurWin->StartSearchAndReplace( *mpSearchItem ); | ||||||
161 | if ( !nFound && !mpSearchItem->GetSelection() ) | ||||||
162 | { | ||||||
163 | // search other modules... | ||||||
164 | bool bChangeCurWindow = false; | ||||||
165 | auto it = std::find_if(aWindowTable.cbegin(), aWindowTable.cend(), | ||||||
166 | [this](const WindowTable::value_type& item) { return item.second == pCurWin; }); | ||||||
167 | if (it != aWindowTable.cend()) | ||||||
168 | ++it; | ||||||
169 | BaseWindow* pWin = it != aWindowTable.cend() ? it->second.get() : nullptr; | ||||||
170 | |||||||
171 | bool bSearchedFromStart = false; | ||||||
172 | while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) ) | ||||||
173 | { | ||||||
174 | if ( !pWin ) | ||||||
175 | { | ||||||
176 | SfxViewFrame* pViewFrame = GetViewFrame(); | ||||||
177 | SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG(5000 + 961) ) : nullptr; | ||||||
178 | auto xParent = pChildWin ? pChildWin->GetController() : nullptr; | ||||||
179 | |||||||
180 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(xParent ? xParent->getDialog() : nullptr, | ||||||
181 | VclMessageType::Question, VclButtonsType::YesNo, | ||||||
182 | IDEResId(RID_STR_SEARCHFROMSTARTreinterpret_cast<char const *>("RID_STR_SEARCHFROMSTART" "\004" u8"Search to last module complete. Continue at first module?" )))); | ||||||
183 | xQueryBox->set_default_response(RET_YES); | ||||||
184 | if (xQueryBox->run() == RET_YES) | ||||||
185 | { | ||||||
186 | it = aWindowTable.cbegin(); | ||||||
187 | if ( it != aWindowTable.cend() ) | ||||||
188 | pWin = it->second; | ||||||
189 | bSearchedFromStart = true; | ||||||
190 | } | ||||||
191 | else | ||||||
192 | bCanceled = true; | ||||||
193 | } | ||||||
194 | |||||||
195 | if (pWin && pWin->HasActiveEditor()) | ||||||
196 | { | ||||||
197 | if ( pWin != pCurWin ) | ||||||
198 | { | ||||||
199 | if ( pCurWin ) | ||||||
200 | pWin->SetSizePixel( pCurWin->GetSizePixel() ); | ||||||
201 | nFound = pWin->StartSearchAndReplace( *mpSearchItem, true ); | ||||||
202 | } | ||||||
203 | if ( nFound ) | ||||||
204 | { | ||||||
205 | bChangeCurWindow = true; | ||||||
206 | break; | ||||||
207 | } | ||||||
208 | } | ||||||
209 | if ( pWin && ( pWin != pCurWin ) ) | ||||||
210 | { | ||||||
211 | if ( it != aWindowTable.cend() ) | ||||||
212 | ++it; | ||||||
213 | pWin = it != aWindowTable.cend() ? it->second.get() : nullptr; | ||||||
214 | } | ||||||
215 | else | ||||||
216 | pWin = nullptr; | ||||||
217 | } | ||||||
218 | if ( !nFound && bSearchedFromStart ) | ||||||
219 | nFound = pCurWin->StartSearchAndReplace( *mpSearchItem, true ); | ||||||
220 | if ( bChangeCurWindow ) | ||||||
221 | SetCurWindow( pWin, true ); | ||||||
222 | } | ||||||
223 | if ( !nFound && !bCanceled ) | ||||||
224 | { | ||||||
225 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(), | ||||||
226 | VclMessageType::Info, VclButtonsType::Ok, | ||||||
227 | IDEResId(RID_STR_SEARCHNOTFOUNDreinterpret_cast<char const *>("RID_STR_SEARCHNOTFOUND" "\004" u8"Search key not found")))); | ||||||
228 | xInfoBox->run(); | ||||||
229 | } | ||||||
230 | } | ||||||
231 | |||||||
232 | rReq.Done(); | ||||||
233 | break; | ||||||
234 | } | ||||||
235 | default: | ||||||
236 | pCurWin->ExecuteCommand( rReq ); | ||||||
237 | } | ||||||
238 | } | ||||||
239 | |||||||
240 | void Shell::ExecuteCurrent( SfxRequest& rReq ) | ||||||
241 | { | ||||||
242 | if ( !pCurWin ) | ||||||
243 | return; | ||||||
244 | |||||||
245 | switch ( rReq.GetSlot() ) | ||||||
246 | { | ||||||
247 | case SID_BASICIDE_HIDECURPAGE( (30000 + 768) + 10 ): | ||||||
248 | { | ||||||
249 | pCurWin->StoreData(); | ||||||
250 | RemoveWindow( pCurWin, false ); | ||||||
251 | } | ||||||
252 | break; | ||||||
253 | case SID_BASICIDE_RENAMECURRENT( (30000 + 768) + 23 ): | ||||||
254 | { | ||||||
255 | pTabBar->StartEditMode( pTabBar->GetCurPageId() ); | ||||||
256 | } | ||||||
257 | break; | ||||||
258 | case SID_UNDO(5000 + 701): | ||||||
259 | case SID_REDO(5000 + 700): | ||||||
260 | if ( GetUndoManager() && pCurWin->AllowUndo() ) | ||||||
261 | GetViewFrame()->ExecuteSlot( rReq ); | ||||||
262 | break; | ||||||
263 | default: | ||||||
264 | pCurWin->ExecuteCommand( rReq ); | ||||||
265 | } | ||||||
266 | } | ||||||
267 | |||||||
268 | // no matter who's at the top, influence on the shell: | ||||||
269 | void Shell::ExecuteGlobal( SfxRequest& rReq ) | ||||||
270 | { | ||||||
271 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||
272 | switch ( nSlot ) | ||||||
| |||||||
273 | { | ||||||
274 | case SID_NEWDOCDIRECT(5000 + 537): | ||||||
275 | { | ||||||
276 | // we do not have a new document factory, | ||||||
277 | // so just forward to a fallback method. | ||||||
278 | SfxGetpApp()->ExecuteSlot(rReq); | ||||||
279 | } | ||||||
280 | break; | ||||||
281 | |||||||
282 | case SID_BASICSTOP(5000 + 958): | ||||||
283 | { | ||||||
284 | // maybe do not simply stop if on breakpoint! | ||||||
285 | if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
286 | pMCurWin->BasicStop(); | ||||||
287 | StopBasic(); | ||||||
288 | } | ||||||
289 | break; | ||||||
290 | |||||||
291 | case SID_SAVEDOC(5000 + 505): | ||||||
292 | { | ||||||
293 | if ( pCurWin ) | ||||||
294 | { | ||||||
295 | // rewrite date into the BASIC | ||||||
296 | StoreAllWindowData(); | ||||||
297 | |||||||
298 | // document basic | ||||||
299 | ScriptDocument aDocument( pCurWin->GetDocument() ); | ||||||
300 | if ( aDocument.isDocument() ) | ||||||
301 | { | ||||||
302 | uno::Reference< task::XStatusIndicator > xStatusIndicator; | ||||||
303 | |||||||
304 | const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg<SfxUnoAnyItem>(SID_PROGRESS_STATUSBAR_CONTROL(5000 + 1597)); | ||||||
305 | if ( pStatusIndicatorItem ) | ||||||
306 | OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator )do { if (!(pStatusIndicatorItem->GetValue() >>= xStatusIndicator )) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "306" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | ||||||
307 | else | ||||||
308 | { | ||||||
309 | // get statusindicator | ||||||
310 | SfxViewFrame *pFrame_ = GetFrame(); | ||||||
311 | if ( pFrame_ ) | ||||||
312 | { | ||||||
313 | uno::Reference< task::XStatusIndicatorFactory > xStatFactory( | ||||||
314 | pFrame_->GetFrame().GetFrameInterface(), | ||||||
315 | uno::UNO_QUERY ); | ||||||
316 | if( xStatFactory.is() ) | ||||||
317 | xStatusIndicator = xStatFactory->createStatusIndicator(); | ||||||
318 | } | ||||||
319 | |||||||
320 | if ( xStatusIndicator.is() ) | ||||||
321 | rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL(5000 + 1597), uno::Any( xStatusIndicator ) ) ); | ||||||
322 | } | ||||||
323 | |||||||
324 | aDocument.saveDocument( xStatusIndicator ); | ||||||
325 | } | ||||||
326 | |||||||
327 | if (SfxBindings* pBindings = GetBindingsPtr()) | ||||||
328 | { | ||||||
329 | pBindings->Invalidate( SID_DOC_MODIFIED(5000 + 584) ); | ||||||
330 | pBindings->Invalidate( SID_SAVEDOC(5000 + 505) ); | ||||||
331 | pBindings->Invalidate( SID_SIGNATURE(5000 + 1643) ); | ||||||
332 | } | ||||||
333 | } | ||||||
334 | } | ||||||
335 | break; | ||||||
336 | case SID_BASICIDE_MODULEDLG( (30000 + 768) + 5 ): | ||||||
337 | { | ||||||
338 | if ( rReq.GetArgs() ) | ||||||
339 | { | ||||||
340 | const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABIDTypedWhichId<SfxUInt16Item>( (30000 + 768) + 30 ) ); | ||||||
341 | Organize(rReq.GetFrameWeld(), rTabId.GetValue()); | ||||||
342 | } | ||||||
343 | else | ||||||
344 | Organize(rReq.GetFrameWeld(), 0); | ||||||
345 | } | ||||||
346 | break; | ||||||
347 | case SID_BASICIDE_CHOOSEMACRO( (30000 + 768) + 2 ): | ||||||
348 | { | ||||||
349 | ChooseMacro(rReq.GetFrameWeld(), nullptr); | ||||||
350 | } | ||||||
351 | break; | ||||||
352 | case SID_BASICIDE_CREATEMACRO( (30000 + 768) + 4 ): | ||||||
353 | case SID_BASICIDE_EDITMACRO( (30000 + 768) + 3 ): | ||||||
354 | { | ||||||
355 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "355" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
356 | const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFOTypedWhichId<SfxMacroInfoItem>( (30000 + 768) + 32 ) ); | ||||||
357 | BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager()); | ||||||
358 | DBG_ASSERT( pBasMgr, "Nothing selected in basic tree?" )do { if (true && (!(pBasMgr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "358" ": "), "%s", "Nothing selected in basic tree?"); } } while (false); | ||||||
359 | |||||||
360 | ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); | ||||||
361 | |||||||
362 | StartListening(*pBasMgr, DuplicateHandling::Prevent /* log on only once */); | ||||||
363 | OUString aLibName( rInfo.GetLib() ); | ||||||
364 | if ( aLibName.isEmpty() ) | ||||||
365 | aLibName = "Standard" ; | ||||||
366 | StarBASIC* pBasic = pBasMgr->GetLib( aLibName ); | ||||||
367 | if ( !pBasic ) | ||||||
368 | { | ||||||
369 | // load module and dialog library (if not loaded) | ||||||
370 | aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName ); | ||||||
371 | aDocument.loadLibraryIfExists( E_DIALOGS, aLibName ); | ||||||
372 | |||||||
373 | // get Basic | ||||||
374 | pBasic = pBasMgr->GetLib( aLibName ); | ||||||
375 | } | ||||||
376 | DBG_ASSERT( pBasic, "No Basic!" )do { if (true && (!(pBasic))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "376" ": "), "%s", "No Basic!"); } } while (false); | ||||||
377 | |||||||
378 | SetCurLib( aDocument, aLibName ); | ||||||
379 | |||||||
380 | if ( pBasic && rReq.GetSlot() == SID_BASICIDE_CREATEMACRO( (30000 + 768) + 4 ) ) | ||||||
381 | { | ||||||
382 | SbModule* pModule = pBasic->FindModule( rInfo.GetModule() ); | ||||||
383 | if ( !pModule ) | ||||||
384 | { | ||||||
385 | if ( !rInfo.GetModule().isEmpty() || pBasic->GetModules().empty() ) | ||||||
386 | { | ||||||
387 | const OUString& aModName = rInfo.GetModule(); | ||||||
388 | |||||||
389 | OUString sModuleCode; | ||||||
390 | if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) ) | ||||||
391 | pModule = pBasic->FindModule( aModName ); | ||||||
392 | } | ||||||
393 | else | ||||||
394 | pModule = pBasic->GetModules().front().get(); | ||||||
395 | } | ||||||
396 | DBG_ASSERT( pModule, "No Module!" )do { if (true && (!(pModule))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "396" ": "), "%s", "No Module!"); } } while (false); | ||||||
397 | if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxClassType::Method ) ) | ||||||
398 | CreateMacro( pModule, rInfo.GetMethod() ); | ||||||
399 | } | ||||||
400 | SfxViewFrame* pViewFrame = GetViewFrame(); | ||||||
401 | if ( pViewFrame ) | ||||||
402 | pViewFrame->ToTop(); | ||||||
403 | VclPtr<ModulWindow> pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true ); | ||||||
404 | DBG_ASSERT( pWin, "Edit/Create Macro: Window was not created/found!" )do { if (true && (!(pWin))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "404" ": "), "%s", "Edit/Create Macro: Window was not created/found!" ); } } while (false); | ||||||
405 | SetCurWindow( pWin, true ); | ||||||
406 | pWin->EditMacro( rInfo.GetMethod() ); | ||||||
407 | } | ||||||
408 | break; | ||||||
409 | |||||||
410 | case SID_BASICIDE_OBJCAT( (30000 + 768) + 6 ): | ||||||
411 | // toggling object catalog | ||||||
412 | aObjectCatalog->Show(!aObjectCatalog->IsVisible()); | ||||||
413 | if (pLayout) | ||||||
414 | pLayout->ArrangeWindows(); | ||||||
415 | // refresh the button state | ||||||
416 | if (SfxBindings* pBindings = GetBindingsPtr()) | ||||||
417 | pBindings->Invalidate(SID_BASICIDE_OBJCAT( (30000 + 768) + 6 )); | ||||||
418 | break; | ||||||
419 | |||||||
420 | case SID_BASICIDE_NAMECHANGEDONTAB( (30000 + 768) + 11 ): | ||||||
421 | { | ||||||
422 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "422" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
423 | const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABIDTypedWhichId<SfxUInt16Item>( (30000 + 768) + 30 ) ); | ||||||
424 | const SfxStringItem &rModName = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAMETypedWhichId<SfxStringItem>( (30000 + 768) + 35 ) ); | ||||||
425 | if ( aWindowTable.find( rTabId.GetValue() ) != aWindowTable.end() ) | ||||||
426 | { | ||||||
427 | VclPtr<BaseWindow> pWin = aWindowTable[ rTabId.GetValue() ]; | ||||||
428 | const OUString& aNewName( rModName.GetValue() ); | ||||||
429 | OUString aOldName( pWin->GetName() ); | ||||||
430 | if ( aNewName != aOldName ) | ||||||
431 | { | ||||||
432 | bool bRenameOk = false; | ||||||
433 | if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin.get())) | ||||||
434 | { | ||||||
435 | const OUString& aLibName = pModWin->GetLibName(); | ||||||
436 | ScriptDocument aDocument( pWin->GetDocument() ); | ||||||
437 | |||||||
438 | if (RenameModule(pModWin->GetFrameWeld(), aDocument, aLibName, aOldName, aNewName)) | ||||||
439 | { | ||||||
440 | bRenameOk = true; | ||||||
441 | // Because we listen for container events for script | ||||||
442 | // modules, rename will delete the 'old' window | ||||||
443 | // pWin has been invalidated, restore now | ||||||
444 | pWin = FindBasWin( aDocument, aLibName, aNewName, true ); | ||||||
445 | } | ||||||
446 | |||||||
447 | } | ||||||
448 | else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin.get())) | ||||||
449 | { | ||||||
450 | bRenameOk = pDlgWin->RenameDialog( aNewName ); | ||||||
451 | } | ||||||
452 | if ( bRenameOk ) | ||||||
453 | { | ||||||
454 | MarkDocumentModified( pWin->GetDocument() ); | ||||||
455 | } | ||||||
456 | else | ||||||
457 | { | ||||||
458 | // set old name in TabWriter | ||||||
459 | sal_uInt16 nId = GetWindowId( pWin ); | ||||||
460 | DBG_ASSERT( nId, "No entry in Tabbar!" )do { if (true && (!(nId))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "460" ": "), "%s", "No entry in Tabbar!"); } } while (false ); | ||||||
461 | if ( nId ) | ||||||
462 | pTabBar->SetPageText( nId, aOldName ); | ||||||
463 | } | ||||||
464 | } | ||||||
465 | |||||||
466 | // set focus to current window | ||||||
467 | pWin->GrabFocus(); | ||||||
468 | } | ||||||
469 | } | ||||||
470 | break; | ||||||
471 | case SID_BASICIDE_STOREMODULESOURCE( (30000 + 768) + 13 ): | ||||||
472 | case SID_BASICIDE_UPDATEMODULESOURCE( (30000 + 768) + 12 ): | ||||||
473 | { | ||||||
474 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "474" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
475 | const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFOTypedWhichId<SfxMacroInfoItem>( (30000 + 768) + 32 ) ); | ||||||
476 | BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager()); | ||||||
477 | DBG_ASSERT( pBasMgr, "Store source: No BasMgr?" )do { if (true && (!(pBasMgr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "477" ": "), "%s", "Store source: No BasMgr?"); } } while (false); | ||||||
478 | ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); | ||||||
479 | VclPtr<ModulWindow> pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true ); | ||||||
480 | if ( pWin ) | ||||||
481 | { | ||||||
482 | if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE( (30000 + 768) + 13 ) ) | ||||||
483 | pWin->StoreData(); | ||||||
484 | else | ||||||
485 | pWin->UpdateData(); | ||||||
486 | } | ||||||
487 | } | ||||||
488 | break; | ||||||
489 | case SID_BASICIDE_STOREALLMODULESOURCES( (30000 + 768) + 16 ): | ||||||
490 | case SID_BASICIDE_UPDATEALLMODULESOURCES( (30000 + 768) + 17 ): | ||||||
491 | { | ||||||
492 | for (auto const& window : aWindowTable) | ||||||
493 | { | ||||||
494 | BaseWindow* pWin = window.second; | ||||||
495 | if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin)) | ||||||
496 | { | ||||||
497 | if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES( (30000 + 768) + 16 ) ) | ||||||
498 | pWin->StoreData(); | ||||||
499 | else | ||||||
500 | pWin->UpdateData(); | ||||||
501 | } | ||||||
502 | } | ||||||
503 | } | ||||||
504 | break; | ||||||
505 | case SID_BASICIDE_LIBSELECTED( (30000 + 768) + 18 ): | ||||||
506 | case SID_BASICIDE_LIBREMOVED( (30000 + 768) + 28 ): | ||||||
507 | case SID_BASICIDE_LIBLOADED( (30000 + 768) + 27 ): | ||||||
508 | { | ||||||
509 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "509" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
510 | const SfxUnoAnyItem& rShellItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODELTypedWhichId<SfxUnoAnyItem>( (30000 + 768) + 51 ) ); | ||||||
511 | uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY ); | ||||||
512 | ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() ); | ||||||
513 | const SfxStringItem& rLibNameItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAMETypedWhichId<SfxStringItem>( (30000 + 768) + 34 ) ); | ||||||
514 | const OUString& aLibName( rLibNameItem.GetValue() ); | ||||||
515 | |||||||
516 | if ( nSlot == SID_BASICIDE_LIBSELECTED( (30000 + 768) + 18 ) ) | ||||||
517 | { | ||||||
518 | // load module and dialog library (if not loaded) | ||||||
519 | aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName ); | ||||||
520 | aDocument.loadLibraryIfExists( E_DIALOGS, aLibName ); | ||||||
521 | |||||||
522 | // check password, if library is password protected and not verified | ||||||
523 | bool bOK = true; | ||||||
524 | Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) ); | ||||||
525 | if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) ) | ||||||
526 | { | ||||||
527 | Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); | ||||||
528 | if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) ) | ||||||
529 | { | ||||||
530 | OUString aPassword; | ||||||
531 | bOK = QueryPassword(rReq.GetFrameWeld(), xModLibContainer, aLibName, aPassword); | ||||||
532 | } | ||||||
533 | } | ||||||
534 | |||||||
535 | if ( bOK ) | ||||||
536 | { | ||||||
537 | SetCurLib( aDocument, aLibName, true, false ); | ||||||
538 | } | ||||||
539 | else | ||||||
540 | { | ||||||
541 | // adjust old value... | ||||||
542 | if (SfxBindings* pBindings = GetBindingsPtr()) | ||||||
543 | pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR( (30000 + 768) + 19 ), true); | ||||||
544 | } | ||||||
545 | } | ||||||
546 | else if ( nSlot == SID_BASICIDE_LIBREMOVED( (30000 + 768) + 28 ) ) | ||||||
547 | { | ||||||
548 | if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) ) | ||||||
549 | { | ||||||
550 | RemoveWindows( aDocument, aLibName ); | ||||||
551 | if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) | ||||||
552 | { | ||||||
553 | m_aCurDocument = ScriptDocument::getApplicationScriptDocument(); | ||||||
554 | m_aCurLibName.clear(); | ||||||
555 | // no UpdateWindows! | ||||||
556 | if (SfxBindings* pBindings = GetBindingsPtr()) | ||||||
557 | pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR( (30000 + 768) + 19 ) ); | ||||||
558 | } | ||||||
559 | } | ||||||
560 | } | ||||||
561 | else // Loaded... | ||||||
562 | UpdateWindows(); | ||||||
563 | } | ||||||
564 | break; | ||||||
565 | case SID_BASICIDE_NEWMODULE( (30000 + 768) + 21 ): | ||||||
566 | { | ||||||
567 | VclPtr<ModulWindow> pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() ); | ||||||
568 | DBG_ASSERT( pWin, "New Module: Could not create window!" )do { if (true && (!(pWin))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "568" ": "), "%s", "New Module: Could not create window!" ); } } while (false); | ||||||
569 | SetCurWindow( pWin, true ); | ||||||
570 | } | ||||||
571 | break; | ||||||
572 | case SID_BASICIDE_NEWDIALOG( (30000 + 768) + 20 ): | ||||||
573 | { | ||||||
574 | VclPtr<DialogWindow> pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, OUString() ); | ||||||
575 | DBG_ASSERT( pWin, "New Module: Could not create window!" )do { if (true && (!(pWin))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "575" ": "), "%s", "New Module: Could not create window!" ); } } while (false); | ||||||
576 | SetCurWindow( pWin, true ); | ||||||
577 | } | ||||||
578 | break; | ||||||
579 | case SID_BASICIDE_SBXRENAMED( (30000 + 768) + 26 ): | ||||||
580 | { | ||||||
581 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "581" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
582 | } | ||||||
583 | break; | ||||||
584 | case SID_BASICIDE_SBXINSERTED( (30000 + 768) + 25 ): | ||||||
585 | { | ||||||
586 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "586" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
587 | const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBXTypedWhichId<SbxItem>( (30000 + 768) + 31 ) ); | ||||||
588 | const ScriptDocument& aDocument( rSbxItem.GetDocument() ); | ||||||
589 | const OUString& aLibName( rSbxItem.GetLibName() ); | ||||||
590 | const OUString& aName( rSbxItem.GetName() ); | ||||||
591 | if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) ) | ||||||
592 | { | ||||||
593 | if ( rSbxItem.GetType() == TYPE_MODULE ) | ||||||
594 | FindBasWin( aDocument, aLibName, aName, true ); | ||||||
595 | else if ( rSbxItem.GetType() == TYPE_DIALOG ) | ||||||
596 | FindDlgWin( aDocument, aLibName, aName, true ); | ||||||
597 | } | ||||||
598 | } | ||||||
599 | break; | ||||||
600 | case SID_BASICIDE_SBXDELETED( (30000 + 768) + 24 ): | ||||||
601 | { | ||||||
602 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "602" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
603 | const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBXTypedWhichId<SbxItem>( (30000 + 768) + 31 ) ); | ||||||
604 | const ScriptDocument& aDocument( rSbxItem.GetDocument() ); | ||||||
605 | VclPtr<BaseWindow> pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), true ); | ||||||
606 | if ( pWin ) | ||||||
607 | RemoveWindow( pWin, true ); | ||||||
608 | } | ||||||
609 | break; | ||||||
610 | case SID_BASICIDE_SHOWSBX( (30000 + 768) + 9 ): | ||||||
611 | { | ||||||
612 | DBG_ASSERT( rReq.GetArgs(), "arguments expected" )do { if (true && (!(rReq.GetArgs()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "612" ": "), "%s", "arguments expected"); } } while (false ); | ||||||
613 | const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBXTypedWhichId<SbxItem>( (30000 + 768) + 31 ) ); | ||||||
614 | const ScriptDocument& aDocument( rSbxItem.GetDocument() ); | ||||||
615 | const OUString& aLibName( rSbxItem.GetLibName() ); | ||||||
616 | const OUString& aName( rSbxItem.GetName() ); | ||||||
617 | SetCurLib( aDocument, aLibName ); | ||||||
618 | BaseWindow* pWin = nullptr; | ||||||
619 | if ( rSbxItem.GetType() == TYPE_DIALOG ) | ||||||
620 | { | ||||||
621 | pWin = FindDlgWin( aDocument, aLibName, aName, true ); | ||||||
622 | } | ||||||
623 | else if ( rSbxItem.GetType() == TYPE_MODULE ) | ||||||
624 | { | ||||||
625 | pWin = FindBasWin( aDocument, aLibName, aName, true ); | ||||||
626 | } | ||||||
627 | else if ( rSbxItem.GetType() == TYPE_METHOD ) | ||||||
628 | { | ||||||
629 | pWin = FindBasWin( aDocument, aLibName, aName, true ); | ||||||
630 | static_cast<ModulWindow*>(pWin)->EditMacro( rSbxItem.GetMethodName() ); | ||||||
631 | } | ||||||
632 | DBG_ASSERT( pWin, "Window was not created!" )do { if (true && (!(pWin))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "632" ": "), "%s", "Window was not created!"); } } while (false); | ||||||
633 | SetCurWindow( pWin, true ); | ||||||
634 | pTabBar->MakeVisible( pTabBar->GetCurPageId() ); | ||||||
635 | } | ||||||
636 | break; | ||||||
637 | case SID_BASICIDE_SHOWWINDOW( (30000 + 768) + 44 ): | ||||||
638 | { | ||||||
639 | std::unique_ptr< ScriptDocument > pDocument; | ||||||
640 | |||||||
641 | const SfxStringItem* pDocumentItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_DOCUMENTTypedWhichId<SfxUnoAnyItem>( (30000 + 768) + 45 )); | ||||||
642 | if ( pDocumentItem
| ||||||
643 | { | ||||||
644 | const OUString& sDocumentCaption = pDocumentItem->GetValue(); | ||||||
645 | if ( !sDocumentCaption.isEmpty() ) | ||||||
646 | pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) ); | ||||||
647 | } | ||||||
648 | |||||||
649 | const SfxUnoAnyItem* pDocModelItem = rReq.GetArg<SfxUnoAnyItem>(SID_BASICIDE_ARG_DOCUMENT_MODELTypedWhichId<SfxUnoAnyItem>( (30000 + 768) + 51 )); | ||||||
650 | if (!pDocument && pDocModelItem) | ||||||
651 | { | ||||||
652 | uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY ); | ||||||
653 | if ( xModel.is() ) | ||||||
654 | pDocument.reset( new ScriptDocument( xModel ) ); | ||||||
655 | } | ||||||
656 | |||||||
657 | if (!pDocument) | ||||||
658 | break; | ||||||
659 | |||||||
660 | const SfxStringItem* pLibNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_LIBNAMETypedWhichId<SfxStringItem>( (30000 + 768) + 34 )); | ||||||
661 | if ( !pLibNameItem
| ||||||
662 | break; | ||||||
663 | |||||||
664 | OUString aLibName( pLibNameItem->GetValue() ); | ||||||
665 | pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName ); | ||||||
666 | SetCurLib( *pDocument, aLibName ); | ||||||
667 | const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_NAME( (30000 + 768) + 46 )); | ||||||
668 | if ( pNameItem
| ||||||
669 | { | ||||||
670 | const OUString& aName( pNameItem->GetValue() ); | ||||||
671 | OUString aModType( "Module" ); | ||||||
672 | OUString aType( aModType ); | ||||||
673 | const SfxStringItem* pTypeItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_TYPE( (30000 + 768) + 47 )); | ||||||
674 | if ( pTypeItem
| ||||||
675 | aType = pTypeItem->GetValue(); | ||||||
676 | |||||||
677 | BaseWindow* pWin = nullptr; | ||||||
678 | if ( aType == aModType ) | ||||||
679 | pWin = FindBasWin( *pDocument, aLibName, aName ); | ||||||
680 | else if ( aType == "Dialog" ) | ||||||
681 | pWin = FindDlgWin( *pDocument, aLibName, aName ); | ||||||
682 | |||||||
683 | if ( pWin
| ||||||
684 | { | ||||||
685 | SetCurWindow( pWin, true ); | ||||||
| |||||||
686 | if ( pTabBar ) | ||||||
687 | pTabBar->MakeVisible( pTabBar->GetCurPageId() ); | ||||||
688 | |||||||
689 | if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin)) | ||||||
690 | { | ||||||
691 | const SfxUInt32Item* pLineItem = rReq.GetArg<SfxUInt32Item>(SID_BASICIDE_ARG_LINE( (30000 + 768) + 48 )); | ||||||
692 | if ( pLineItem ) | ||||||
693 | { | ||||||
694 | pModWin->AssertValidEditEngine(); | ||||||
695 | TextView* pTextView = pModWin->GetEditView(); | ||||||
696 | if ( pTextView ) | ||||||
697 | { | ||||||
698 | TextEngine* pTextEngine = pTextView->GetTextEngine(); | ||||||
699 | if ( pTextEngine ) | ||||||
700 | { | ||||||
701 | sal_uInt32 nLine = pLineItem->GetValue(); | ||||||
702 | sal_uInt32 nLineCount = 0; | ||||||
703 | for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i ) | ||||||
704 | nLineCount += pTextEngine->GetLineCount( i ); | ||||||
705 | if ( nLine > nLineCount ) | ||||||
706 | nLine = nLineCount; | ||||||
707 | if ( nLine > 0 ) | ||||||
708 | --nLine; | ||||||
709 | |||||||
710 | // scroll window and set selection | ||||||
711 | long nVisHeight = pModWin->GetOutputSizePixel().Height(); | ||||||
712 | long nTextHeight = pTextEngine->GetTextHeight(); | ||||||
713 | if ( nTextHeight > nVisHeight ) | ||||||
714 | { | ||||||
715 | long nMaxY = nTextHeight - nVisHeight; | ||||||
716 | long nOldY = pTextView->GetStartDocPos().Y(); | ||||||
717 | long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2; | ||||||
718 | nNewY = std::min( nNewY, nMaxY ); | ||||||
719 | pTextView->Scroll( 0, -( nNewY - nOldY ) ); | ||||||
720 | pTextView->ShowCursor( false ); | ||||||
721 | pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() ); | ||||||
722 | } | ||||||
723 | sal_uInt16 nCol1 = 0, nCol2 = 0; | ||||||
724 | const SfxUInt16Item* pCol1Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN1( (30000 + 768) + 49 )); | ||||||
725 | if ( pCol1Item ) | ||||||
726 | { | ||||||
727 | nCol1 = pCol1Item->GetValue(); | ||||||
728 | if ( nCol1 > 0 ) | ||||||
729 | --nCol1; | ||||||
730 | nCol2 = nCol1; | ||||||
731 | } | ||||||
732 | const SfxUInt16Item* pCol2Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN2( (30000 + 768) + 50 )); | ||||||
733 | if ( pCol2Item ) | ||||||
734 | { | ||||||
735 | nCol2 = pCol2Item->GetValue(); | ||||||
736 | if ( nCol2 > 0 ) | ||||||
737 | --nCol2; | ||||||
738 | } | ||||||
739 | TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) ); | ||||||
740 | pTextView->SetSelection( aSel ); | ||||||
741 | pTextView->ShowCursor(); | ||||||
742 | vcl::Window* pWindow_ = pTextView->GetWindow(); | ||||||
743 | if ( pWindow_ ) | ||||||
744 | pWindow_->GrabFocus(); | ||||||
745 | } | ||||||
746 | } | ||||||
747 | } | ||||||
748 | } | ||||||
749 | } | ||||||
750 | } | ||||||
751 | rReq.Done(); | ||||||
752 | } | ||||||
753 | break; | ||||||
754 | |||||||
755 | case SID_BASICIDE_MANAGE_LANG( (30000 + 768) + 52 ): | ||||||
756 | { | ||||||
757 | auto pRequest = std::make_shared<SfxRequest>(rReq); | ||||||
758 | rReq.Ignore(); // the 'old' request is not relevant any more | ||||||
759 | auto xDlg = std::make_shared<ManageLanguageDialog>(pCurWin ? pCurWin->GetFrameWeld() : nullptr, m_pCurLocalizationMgr); | ||||||
760 | weld::DialogController::runAsync(xDlg, [=](sal_Int32 /*nResult*/){ | ||||||
761 | pRequest->Done(); | ||||||
762 | }); | ||||||
763 | } | ||||||
764 | break; | ||||||
765 | |||||||
766 | default: | ||||||
767 | if (pLayout) | ||||||
768 | pLayout->ExecuteGlobal(rReq); | ||||||
769 | if (pCurWin) | ||||||
770 | pCurWin->ExecuteGlobal(rReq); | ||||||
771 | break; | ||||||
772 | } | ||||||
773 | } | ||||||
774 | |||||||
775 | void Shell::GetState(SfxItemSet &rSet) | ||||||
776 | { | ||||||
777 | SfxWhichIter aIter(rSet); | ||||||
778 | for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() ) | ||||||
779 | { | ||||||
780 | switch ( nWh ) | ||||||
781 | { | ||||||
782 | case SID_NEWDOCDIRECT(5000 + 537): | ||||||
783 | { | ||||||
784 | // we do not have a new document factory, | ||||||
785 | // so just forward to a fallback method. | ||||||
786 | SfxGetpApp()->GetSlotState(nWh, nullptr, &rSet); | ||||||
787 | } | ||||||
788 | break; | ||||||
789 | case SID_DOCINFOTypedWhichId<SfxDocumentInfoItem>(5000 + 535): | ||||||
790 | { | ||||||
791 | rSet.DisableItem( nWh ); | ||||||
792 | } | ||||||
793 | break; | ||||||
794 | case SID_SAVEDOC(5000 + 505): | ||||||
795 | { | ||||||
796 | bool bDisable = false; | ||||||
797 | |||||||
798 | if ( pCurWin ) | ||||||
799 | { | ||||||
800 | if ( !pCurWin->IsModified() ) | ||||||
801 | { | ||||||
802 | ScriptDocument aDocument( pCurWin->GetDocument() ); | ||||||
803 | bDisable = ( !aDocument.isAlive() ) | ||||||
804 | || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() ); | ||||||
805 | } | ||||||
806 | } | ||||||
807 | else | ||||||
808 | { | ||||||
809 | bDisable = true; | ||||||
810 | } | ||||||
811 | |||||||
812 | if ( bDisable ) | ||||||
813 | rSet.DisableItem( nWh ); | ||||||
814 | } | ||||||
815 | break; | ||||||
816 | case SID_NEWWINDOW(5000 + 620): | ||||||
817 | case SID_SAVEASDOC(5000 + 502): | ||||||
818 | { | ||||||
819 | rSet.DisableItem( nWh ); | ||||||
820 | } | ||||||
821 | break; | ||||||
822 | case SID_SIGNATURE(5000 + 1643): | ||||||
823 | { | ||||||
824 | SignatureState nState = SignatureState::NOSIGNATURES; | ||||||
825 | if ( pCurWin ) | ||||||
826 | { | ||||||
827 | DocumentSignature aSignature( pCurWin->GetDocument() ); | ||||||
828 | nState = aSignature.getScriptingSignatureState(); | ||||||
829 | } | ||||||
830 | rSet.Put( SfxUInt16Item( SID_SIGNATURE(5000 + 1643), static_cast<sal_uInt16>(nState) ) ); | ||||||
831 | } | ||||||
832 | break; | ||||||
833 | case SID_BASICIDE_MODULEDLG( (30000 + 768) + 5 ): | ||||||
834 | { | ||||||
835 | if ( StarBASIC::IsRunning() ) | ||||||
836 | rSet.DisableItem( nWh ); | ||||||
837 | } | ||||||
838 | break; | ||||||
839 | case SID_BASICIDE_OBJCAT( (30000 + 768) + 6 ): | ||||||
840 | if (pLayout) | ||||||
841 | rSet.Put(SfxBoolItem(nWh, aObjectCatalog->IsVisible())); | ||||||
842 | else | ||||||
843 | rSet.Put(SfxVisibilityItem(nWh, false)); | ||||||
844 | break; | ||||||
845 | case SID_BASICIDE_SHOWSBX( (30000 + 768) + 9 ): | ||||||
846 | case SID_BASICIDE_CREATEMACRO( (30000 + 768) + 4 ): | ||||||
847 | case SID_BASICIDE_EDITMACRO( (30000 + 768) + 3 ): | ||||||
848 | case SID_BASICIDE_NAMECHANGEDONTAB( (30000 + 768) + 11 ): | ||||||
849 | { | ||||||
850 | ; | ||||||
851 | } | ||||||
852 | break; | ||||||
853 | |||||||
854 | case SID_BASICIDE_ADDWATCH( (30000 + 768) + 1 ): | ||||||
855 | case SID_BASICIDE_REMOVEWATCH( (30000 + 768) + 7 ): | ||||||
856 | case SID_BASICLOAD(5000 + 951): | ||||||
857 | case SID_BASICSAVEAS(5000 + 953): | ||||||
858 | case SID_BASICIDE_MATCHGROUP( (30000 + 768) + 14 ): | ||||||
859 | { | ||||||
860 | if (!dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
861 | rSet.DisableItem( nWh ); | ||||||
862 | else if ( ( nWh == SID_BASICLOAD(5000 + 951) ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) ) | ||||||
863 | rSet.DisableItem( nWh ); | ||||||
864 | } | ||||||
865 | break; | ||||||
866 | case SID_BASICRUN(5000 + 955): | ||||||
867 | case SID_BASICSTEPINTO(5000 + 956): | ||||||
868 | case SID_BASICSTEPOVER(5000 + 957): | ||||||
869 | case SID_BASICSTEPOUT(5000 + 963): | ||||||
870 | case SID_BASICIDE_TOGGLEBRKPNT( (30000 + 768) + 0 ): | ||||||
871 | case SID_BASICIDE_MANAGEBRKPNTS( (30000 + 768) + 42 ): | ||||||
872 | { | ||||||
873 | if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
874 | { | ||||||
875 | if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule) | ||||||
876 | rSet.DisableItem(nWh); | ||||||
877 | } | ||||||
878 | else | ||||||
879 | rSet.DisableItem( nWh ); | ||||||
880 | } | ||||||
881 | break; | ||||||
882 | case SID_BASICCOMPILE(5000 + 954): | ||||||
883 | { | ||||||
884 | if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
885 | rSet.DisableItem( nWh ); | ||||||
886 | } | ||||||
887 | break; | ||||||
888 | case SID_BASICSTOP(5000 + 958): | ||||||
889 | { | ||||||
890 | // stop is always possible when some Basic is running... | ||||||
891 | if (!StarBASIC::IsRunning()) | ||||||
892 | rSet.DisableItem( nWh ); | ||||||
893 | } | ||||||
894 | break; | ||||||
895 | case SID_CHOOSE_CONTROLS( 10000 + 144 ): | ||||||
896 | case SID_DIALOG_TESTMODE( 10000 + 200 ): | ||||||
897 | case SID_INSERT_SELECT( 10000 + 199 ): | ||||||
898 | case SID_INSERT_PUSHBUTTON( 10000 + 146 ): | ||||||
899 | case SID_INSERT_RADIOBUTTON( 10000 + 147 ): | ||||||
900 | case SID_INSERT_CHECKBOX( 10000 + 148 ): | ||||||
901 | case SID_INSERT_LISTBOX( 10000 + 192 ): | ||||||
902 | case SID_INSERT_COMBOBOX( 10000 + 193 ): | ||||||
903 | case SID_INSERT_GROUPBOX( 10000 + 190 ): | ||||||
904 | case SID_INSERT_EDIT( 10000 + 191 ): | ||||||
905 | case SID_INSERT_FIXEDTEXT( 10000 + 189 ): | ||||||
906 | case SID_INSERT_IMAGECONTROL( 10000 + 926 ): | ||||||
907 | case SID_INSERT_PROGRESSBAR( 10000 + 927 ): | ||||||
908 | case SID_INSERT_HSCROLLBAR( 10000 + 195 ): | ||||||
909 | case SID_INSERT_VSCROLLBAR( 10000 + 196 ): | ||||||
910 | case SID_INSERT_HFIXEDLINE( 10000 + 928 ): | ||||||
911 | case SID_INSERT_VFIXEDLINE( 10000 + 929 ): | ||||||
912 | case SID_INSERT_DATEFIELD( 10000 + 936 ): | ||||||
913 | case SID_INSERT_TIMEFIELD( 10000 + 937 ): | ||||||
914 | case SID_INSERT_NUMERICFIELD( 10000 + 938 ): | ||||||
915 | case SID_INSERT_CURRENCYFIELD( 10000 + 939 ): | ||||||
916 | case SID_INSERT_FORMATTEDFIELD( 10000 + 940 ): | ||||||
917 | case SID_INSERT_PATTERNFIELD( 10000 + 941 ): | ||||||
918 | case SID_INSERT_FILECONTROL( 10000 + 942 ): | ||||||
919 | case SID_INSERT_SPINBUTTON( 10000 + 194 ): | ||||||
920 | case SID_INSERT_GRIDCONTROL( 10000 + 753 ): | ||||||
921 | case SID_INSERT_HYPERLINKCONTROL( 10000 + 1037 ): | ||||||
922 | case SID_INSERT_TREECONTROL( 10000 + 1063 ): | ||||||
923 | case SID_INSERT_FORM_RADIO( 10000 + 1106 ): | ||||||
924 | case SID_INSERT_FORM_CHECK( 10000 + 1107 ): | ||||||
925 | case SID_INSERT_FORM_LIST( 10000 + 1108 ): | ||||||
926 | case SID_INSERT_FORM_COMBO( 10000 + 1109 ): | ||||||
927 | case SID_INSERT_FORM_VSCROLL( 10000 + 1111 ): | ||||||
928 | case SID_INSERT_FORM_HSCROLL( 10000 + 1112 ): | ||||||
929 | case SID_INSERT_FORM_SPIN( 10000 + 1110 ): | ||||||
930 | { | ||||||
931 | if (!dynamic_cast<DialogWindow*>(pCurWin.get())) | ||||||
932 | rSet.DisableItem( nWh ); | ||||||
933 | } | ||||||
934 | break; | ||||||
935 | case SID_SEARCH_OPTIONS(10000 + 281): | ||||||
936 | { | ||||||
937 | SearchOptionFlags nOptions = SearchOptionFlags::NONE; | ||||||
938 | if( pCurWin ) | ||||||
939 | nOptions = pCurWin->GetSearchOptions(); | ||||||
940 | rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS(10000 + 281), static_cast<sal_uInt16>(nOptions) ) ); | ||||||
941 | } | ||||||
942 | break; | ||||||
943 | case SID_BASICIDE_LIBSELECTOR( (30000 + 768) + 19 ): | ||||||
944 | { | ||||||
945 | OUString aName; | ||||||
946 | if ( !m_aCurLibName.isEmpty() ) | ||||||
947 | { | ||||||
948 | LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName ); | ||||||
949 | aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName ); | ||||||
950 | } | ||||||
951 | SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR( (30000 + 768) + 19 ), aName ); | ||||||
952 | rSet.Put( aItem ); | ||||||
953 | } | ||||||
954 | break; | ||||||
955 | case SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291): | ||||||
956 | { | ||||||
957 | if ( !mpSearchItem ) | ||||||
958 | { | ||||||
959 | mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEMTypedWhichId<SvxSearchItem>(10000 + 291) )); | ||||||
960 | mpSearchItem->SetSearchString( GetSelectionText( true )); | ||||||
961 | } | ||||||
962 | |||||||
963 | if ( mbJustOpened && HasSelection() ) | ||||||
964 | { | ||||||
965 | OUString aText = GetSelectionText( true ); | ||||||
966 | |||||||
967 | if ( !aText.isEmpty() ) | ||||||
968 | { | ||||||
969 | mpSearchItem->SetSearchString( aText ); | ||||||
970 | mpSearchItem->SetSelection( false ); | ||||||
971 | } | ||||||
972 | else | ||||||
973 | mpSearchItem->SetSelection( true ); | ||||||
974 | } | ||||||
975 | |||||||
976 | mbJustOpened = false; | ||||||
977 | rSet.Put( *mpSearchItem ); | ||||||
978 | } | ||||||
979 | break; | ||||||
980 | case SID_BASICIDE_STAT_DATE( (30000 + 768) + 39 ): | ||||||
981 | { | ||||||
982 | SfxStringItem aItem( SID_BASICIDE_STAT_DATE( (30000 + 768) + 39 ), "Datum?!" ); | ||||||
983 | rSet.Put( aItem ); | ||||||
984 | } | ||||||
985 | break; | ||||||
986 | case SID_DOC_MODIFIED(5000 + 584): | ||||||
987 | { | ||||||
988 | bool bModified = false; | ||||||
989 | |||||||
990 | if ( pCurWin ) | ||||||
991 | { | ||||||
992 | if ( pCurWin->IsModified() ) | ||||||
993 | bModified = true; | ||||||
994 | else | ||||||
995 | { | ||||||
996 | ScriptDocument aDocument( pCurWin->GetDocument() ); | ||||||
997 | bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified(); | ||||||
998 | } | ||||||
999 | } | ||||||
1000 | |||||||
1001 | SfxBoolItem aItem(SID_DOC_MODIFIED(5000 + 584), bModified); | ||||||
1002 | rSet.Put( aItem ); | ||||||
1003 | } | ||||||
1004 | break; | ||||||
1005 | case SID_BASICIDE_STAT_TITLE( (30000 + 768) + 40 ): | ||||||
1006 | { | ||||||
1007 | if ( pCurWin ) | ||||||
1008 | { | ||||||
1009 | OUString aTitle = pCurWin->CreateQualifiedName(); | ||||||
1010 | SfxStringItem aItem( SID_BASICIDE_STAT_TITLE( (30000 + 768) + 40 ), aTitle ); | ||||||
1011 | rSet.Put( aItem ); | ||||||
1012 | } | ||||||
1013 | } | ||||||
1014 | break; | ||||||
1015 | // are interpreted by the controller: | ||||||
1016 | case SID_ATTR_SIZETypedWhichId<SvxSizeItem>( 10000 + 224 ): | ||||||
1017 | case SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ): | ||||||
1018 | break; | ||||||
1019 | case SID_UNDO(5000 + 701): | ||||||
1020 | case SID_REDO(5000 + 700): | ||||||
1021 | { | ||||||
1022 | if( GetUndoManager() ) // recursive GetState else | ||||||
1023 | GetViewFrame()->GetSlotState( nWh, nullptr, &rSet ); | ||||||
1024 | } | ||||||
1025 | break; | ||||||
1026 | case SID_BASICIDE_CURRENT_LANG( (30000 + 768) + 53 ): | ||||||
1027 | { | ||||||
1028 | if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() ) | ||||||
1029 | rSet.DisableItem( nWh ); | ||||||
1030 | else | ||||||
1031 | { | ||||||
1032 | OUString aItemStr; | ||||||
1033 | std::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr()); | ||||||
1034 | if ( pCurMgr->isLibraryLocalized() ) | ||||||
1035 | { | ||||||
1036 | Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales(); | ||||||
1037 | const lang::Locale* pLocale = aLocaleSeq.getConstArray(); | ||||||
1038 | sal_Int32 i, nCount = aLocaleSeq.getLength(); | ||||||
1039 | |||||||
1040 | // Force different results for any combination of locales and default locale | ||||||
1041 | OUString aLangStr; | ||||||
1042 | for ( i = 0; i <= nCount; ++i ) | ||||||
1043 | { | ||||||
1044 | lang::Locale aLocale; | ||||||
1045 | if( i < nCount ) | ||||||
1046 | aLocale = pLocale[i]; | ||||||
1047 | else | ||||||
1048 | aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale(); | ||||||
1049 | |||||||
1050 | aLangStr += aLocale.Language + aLocale.Country + aLocale.Variant; | ||||||
1051 | } | ||||||
1052 | aItemStr = aLangStr; | ||||||
1053 | } | ||||||
1054 | rSet.Put( SfxStringItem( nWh, aItemStr ) ); | ||||||
1055 | } | ||||||
1056 | } | ||||||
1057 | break; | ||||||
1058 | |||||||
1059 | case SID_BASICIDE_MANAGE_LANG( (30000 + 768) + 52 ): | ||||||
1060 | { | ||||||
1061 | if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() ) | ||||||
1062 | rSet.DisableItem( nWh ); | ||||||
1063 | } | ||||||
1064 | break; | ||||||
1065 | case SID_GOTOLINE(5000 + 1724): | ||||||
1066 | { | ||||||
1067 | // if this is not a module window hide the | ||||||
1068 | // setting, doesn't make sense for example if the | ||||||
1069 | // dialog editor is open | ||||||
1070 | if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
1071 | { | ||||||
1072 | rSet.DisableItem( nWh ); | ||||||
1073 | rSet.Put(SfxVisibilityItem(nWh, false)); | ||||||
1074 | } | ||||||
1075 | break; | ||||||
1076 | } | ||||||
1077 | case SID_BASICIDE_HIDECURPAGE( (30000 + 768) + 10 ): | ||||||
1078 | { | ||||||
1079 | if (pTabBar->GetPageCount() == 0) | ||||||
1080 | rSet.DisableItem(nWh); | ||||||
1081 | } | ||||||
1082 | break; | ||||||
1083 | case SID_BASICIDE_DELETECURRENT( (30000 + 768) + 22 ): | ||||||
1084 | case SID_BASICIDE_RENAMECURRENT( (30000 + 768) + 23 ): | ||||||
1085 | { | ||||||
1086 | if (pTabBar->GetPageCount() == 0 || StarBASIC::IsRunning()) | ||||||
1087 | rSet.DisableItem(nWh); | ||||||
1088 | else if (m_aCurDocument.isInVBAMode()) | ||||||
1089 | { | ||||||
1090 | // disable to delete or rename object modules in IDE | ||||||
1091 | BasicManager* pBasMgr = m_aCurDocument.getBasicManager(); | ||||||
1092 | StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib(m_aCurLibName) : nullptr; | ||||||
1093 | if (pBasic && dynamic_cast<ModulWindow*>(pCurWin.get())) | ||||||
1094 | { | ||||||
1095 | SbModule* pActiveModule = pBasic->FindModule( pCurWin->GetName() ); | ||||||
1096 | if ( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) ) | ||||||
1097 | rSet.DisableItem(nWh); | ||||||
1098 | } | ||||||
1099 | } | ||||||
1100 | } | ||||||
1101 | [[fallthrough]]; | ||||||
1102 | |||||||
1103 | case SID_BASICIDE_NEWMODULE( (30000 + 768) + 21 ): | ||||||
1104 | case SID_BASICIDE_NEWDIALOG( (30000 + 768) + 20 ): | ||||||
1105 | { | ||||||
1106 | Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); | ||||||
1107 | Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); | ||||||
1108 | if ( ( xModLibContainer.is() && xModLibContainer->hasByName( m_aCurLibName ) && xModLibContainer->isLibraryReadOnly( m_aCurLibName ) ) || | ||||||
1109 | ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( m_aCurLibName ) && xDlgLibContainer->isLibraryReadOnly( m_aCurLibName ) ) ) | ||||||
1110 | rSet.DisableItem(nWh); | ||||||
1111 | } | ||||||
1112 | break; | ||||||
1113 | default: | ||||||
1114 | if (pLayout) | ||||||
1115 | pLayout->GetState(rSet, nWh); | ||||||
1116 | } | ||||||
1117 | } | ||||||
1118 | if ( pCurWin ) | ||||||
1119 | pCurWin->GetState( rSet ); | ||||||
1120 | } | ||||||
1121 | |||||||
1122 | bool Shell::HasUIFeature(SfxShellFeature nFeature) const | ||||||
1123 | { | ||||||
1124 | assert((nFeature & ~SfxShellFeature::BasicMask) == SfxShellFeature::NONE)(static_cast <bool> ((nFeature & ~SfxShellFeature:: BasicMask) == SfxShellFeature::NONE) ? void (0) : __assert_fail ("(nFeature & ~SfxShellFeature::BasicMask) == SfxShellFeature::NONE" , "/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" , 1124, __extension__ __PRETTY_FUNCTION__)); | ||||||
1125 | bool bResult = false; | ||||||
1126 | |||||||
1127 | if (nFeature & SfxShellFeature::BasicShowBrowser) | ||||||
1128 | { | ||||||
1129 | // fade out (in) property browser in module (dialog) windows | ||||||
1130 | if (dynamic_cast<DialogWindow*>(pCurWin.get()) && !pCurWin->IsReadOnly()) | ||||||
1131 | bResult = true; | ||||||
1132 | } | ||||||
1133 | |||||||
1134 | return bResult; | ||||||
1135 | } | ||||||
1136 | |||||||
1137 | void Shell::SetCurWindow( BaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent ) | ||||||
1138 | { | ||||||
1139 | if ( pNewWin == pCurWin ) | ||||||
1140 | return; | ||||||
1141 | |||||||
1142 | pCurWin = pNewWin; | ||||||
1143 | if (pLayout) | ||||||
1144 | pLayout->Deactivating(); | ||||||
1145 | if (pCurWin) | ||||||
1146 | { | ||||||
1147 | if (pCurWin->GetType() == TYPE_MODULE) | ||||||
1148 | pLayout = pModulLayout.get(); | ||||||
1149 | else | ||||||
1150 | pLayout = pDialogLayout.get(); | ||||||
1151 | AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel()); | ||||||
1152 | pLayout->Activating(*pCurWin); | ||||||
1153 | GetViewFrame()->GetWindow().SetHelpId(pCurWin->GetHid()); | ||||||
1154 | if (bRememberAsCurrent) | ||||||
1155 | pCurWin->InsertLibInfo(); | ||||||
1156 | if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise | ||||||
1157 | pCurWin->Show(); | ||||||
1158 | pCurWin->Init(); | ||||||
1159 | if (!GetExtraData()->ShellInCriticalSection()) | ||||||
1160 | { | ||||||
1161 | vcl::Window* pFrameWindow = &GetViewFrame()->GetWindow(); | ||||||
1162 | vcl::Window* pFocusWindow = Application::GetFocusWindow(); | ||||||
1163 | while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) ) | ||||||
1164 | pFocusWindow = pFocusWindow->GetParent(); | ||||||
1165 | if ( pFocusWindow ) // Focus in BasicIDE | ||||||
1166 | pCurWin->GrabFocus(); | ||||||
1167 | } | ||||||
1168 | } | ||||||
1169 | else | ||||||
1170 | { | ||||||
1171 | SetWindow(pLayout); | ||||||
1172 | pLayout = nullptr; | ||||||
1173 | } | ||||||
1174 | if ( bUpdateTabBar ) | ||||||
1175 | { | ||||||
1176 | sal_uInt16 nKey = GetWindowId( pCurWin ); | ||||||
1177 | if ( pCurWin && ( pTabBar->GetPagePos( nKey ) == TabBar::PAGE_NOT_FOUND ) ) | ||||||
1178 | pTabBar->InsertPage( nKey, pCurWin->GetTitle() ); // has just been faded in | ||||||
1179 | pTabBar->SetCurPageId( nKey ); | ||||||
1180 | } | ||||||
1181 | if ( pCurWin && pCurWin->IsSuspended() ) // if the window is shown in the case of an error... | ||||||
1182 | pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED ); | ||||||
1183 | if ( pCurWin ) | ||||||
1184 | { | ||||||
1185 | SetWindow( pCurWin ); | ||||||
1186 | if ( pCurWin->GetDocument().isDocument() ) | ||||||
1187 | SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() ); | ||||||
1188 | } | ||||||
1189 | else if (pLayout) | ||||||
1190 | { | ||||||
1191 | SetWindow(pLayout); | ||||||
1192 | GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW"BASCTL_HID_BASICIDE_MODULWINDOW" ); | ||||||
1193 | SfxObjectShell::SetCurrentComponent(nullptr); | ||||||
1194 | } | ||||||
1195 | aObjectCatalog->SetCurrentEntry(pCurWin); | ||||||
1196 | SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : nullptr ); | ||||||
1197 | InvalidateBasicIDESlots(); | ||||||
1198 | InvalidateControlSlots(); | ||||||
1199 | EnableScrollbars(pCurWin != nullptr); | ||||||
1200 | |||||||
1201 | if ( m_pCurLocalizationMgr ) | ||||||
1202 | m_pCurLocalizationMgr->handleTranslationbar(); | ||||||
1203 | |||||||
1204 | ManageToolbars(); | ||||||
1205 | |||||||
1206 | // fade out (in) property browser in module (dialog) windows | ||||||
1207 | UIFeatureChanged(); | ||||||
1208 | } | ||||||
1209 | |||||||
1210 | void Shell::ManageToolbars() | ||||||
1211 | { | ||||||
1212 | static const char aMacroBarResName[] = "private:resource/toolbar/macrobar"; | ||||||
1213 | static const char aDialogBarResName[] = "private:resource/toolbar/dialogbar"; | ||||||
1214 | static const char aInsertControlsBarResName[] = "private:resource/toolbar/insertcontrolsbar"; | ||||||
1215 | static const char aFormControlsBarResName[] = "private:resource/toolbar/formcontrolsbar"; | ||||||
1216 | |||||||
1217 | if( !pCurWin ) | ||||||
1218 | return; | ||||||
1219 | |||||||
1220 | Reference< beans::XPropertySet > xFrameProps | ||||||
1221 | ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY ); | ||||||
1222 | if ( !xFrameProps.is() ) | ||||||
1223 | return; | ||||||
1224 | |||||||
1225 | Reference< css::frame::XLayoutManager > xLayoutManager; | ||||||
1226 | uno::Any a = xFrameProps->getPropertyValue( "LayoutManager" ); | ||||||
1227 | a >>= xLayoutManager; | ||||||
1228 | if ( !xLayoutManager.is() ) | ||||||
1229 | return; | ||||||
1230 | |||||||
1231 | xLayoutManager->lock(); | ||||||
1232 | if (dynamic_cast<DialogWindow*>(pCurWin.get())) | ||||||
1233 | { | ||||||
1234 | xLayoutManager->destroyElement( aMacroBarResName ); | ||||||
1235 | |||||||
1236 | xLayoutManager->requestElement( aDialogBarResName ); | ||||||
1237 | xLayoutManager->requestElement( aInsertControlsBarResName ); | ||||||
1238 | xLayoutManager->requestElement( aFormControlsBarResName ); | ||||||
1239 | } | ||||||
1240 | else | ||||||
1241 | { | ||||||
1242 | xLayoutManager->destroyElement( aDialogBarResName ); | ||||||
1243 | xLayoutManager->destroyElement( aInsertControlsBarResName ); | ||||||
1244 | xLayoutManager->destroyElement( aFormControlsBarResName ); | ||||||
1245 | |||||||
1246 | xLayoutManager->requestElement( aMacroBarResName ); | ||||||
1247 | } | ||||||
1248 | xLayoutManager->unlock(); | ||||||
1249 | } | ||||||
1250 | |||||||
1251 | VclPtr<BaseWindow> Shell::FindApplicationWindow() | ||||||
1252 | { | ||||||
1253 | return FindWindow( ScriptDocument::getApplicationScriptDocument(), "", "", TYPE_UNKNOWN ); | ||||||
1254 | } | ||||||
1255 | |||||||
1256 | VclPtr<BaseWindow> Shell::FindWindow( | ||||||
1257 | ScriptDocument const& rDocument, | ||||||
1258 | OUString const& rLibName, OUString const& rName, | ||||||
1259 | ItemType eType, bool bFindSuspended | ||||||
1260 | ) | ||||||
1261 | { | ||||||
1262 | for (auto const& window : aWindowTable) | ||||||
1263 | { | ||||||
1264 | BaseWindow* const pWin = window.second; | ||||||
1265 | if (pWin->Is(rDocument, rLibName, rName, eType, bFindSuspended)) | ||||||
1266 | return pWin; | ||||||
1267 | } | ||||||
1268 | return nullptr; | ||||||
1269 | } | ||||||
1270 | |||||||
1271 | bool Shell::CallBasicErrorHdl( StarBASIC const * pBasic ) | ||||||
1272 | { | ||||||
1273 | VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic ); | ||||||
1274 | if ( pModWin ) | ||||||
1275 | pModWin->BasicErrorHdl( pBasic ); | ||||||
1276 | return false; | ||||||
1277 | } | ||||||
1278 | |||||||
1279 | BasicDebugFlags Shell::CallBasicBreakHdl( StarBASIC const * pBasic ) | ||||||
1280 | { | ||||||
1281 | BasicDebugFlags nRet = BasicDebugFlags::NONE; | ||||||
1282 | VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic ); | ||||||
1283 | if ( pModWin ) | ||||||
1284 | { | ||||||
1285 | bool bAppWindowDisabled, bDispatcherLocked; | ||||||
1286 | sal_uInt16 nWaitCount; | ||||||
1287 | SfxUInt16Item *pSWActionCount, *pSWLockViewCount; | ||||||
1288 | BasicStopped( &bAppWindowDisabled, &bDispatcherLocked, | ||||||
1289 | &nWaitCount, &pSWActionCount, &pSWLockViewCount ); | ||||||
1290 | |||||||
1291 | nRet = pModWin->BasicBreakHdl(); | ||||||
1292 | |||||||
1293 | if ( StarBASIC::IsRunning() ) // if cancelled... | ||||||
1294 | { | ||||||
1295 | if ( bAppWindowDisabled ) | ||||||
1296 | Application::GetDefDialogParent()->Enable(false); | ||||||
1297 | |||||||
1298 | if ( nWaitCount ) | ||||||
1299 | { | ||||||
1300 | Shell* pShell = GetShell(); | ||||||
1301 | for ( sal_uInt16 n = 0; n < nWaitCount; n++ ) | ||||||
1302 | pShell->GetViewFrame()->GetWindow().EnterWait(); | ||||||
1303 | } | ||||||
1304 | } | ||||||
1305 | } | ||||||
1306 | return nRet; | ||||||
1307 | } | ||||||
1308 | |||||||
1309 | VclPtr<ModulWindow> Shell::ShowActiveModuleWindow( StarBASIC const * pBasic ) | ||||||
1310 | { | ||||||
1311 | SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false ); | ||||||
1312 | |||||||
1313 | SbModule* pActiveModule = StarBASIC::GetActiveModule(); | ||||||
1314 | if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule)) | ||||||
1315 | pActiveModule = pCMO->getClassModule(); | ||||||
1316 | |||||||
1317 | DBG_ASSERT( pActiveModule, "No active module in ErrorHdl!?" )do { if (true && (!(pActiveModule))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1317" ": "), "%s", "No active module in ErrorHdl!?"); } } while (false); | ||||||
1318 | if ( pActiveModule ) | ||||||
1319 | { | ||||||
1320 | VclPtr<ModulWindow> pWin; | ||||||
1321 | SbxObject* pParent = pActiveModule->GetParent(); | ||||||
1322 | if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent)) | ||||||
1323 | { | ||||||
1324 | if (BasicManager* pBasMgr = FindBasicManager(pLib)) | ||||||
1325 | { | ||||||
1326 | ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) ); | ||||||
1327 | const OUString& aLibName = pLib->GetName(); | ||||||
1328 | pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true ); | ||||||
1329 | DBG_ASSERT( pWin, "Error/Step-Hdl: Window was not created/found!" )do { if (true && (!(pWin))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1329" ": "), "%s", "Error/Step-Hdl: Window was not created/found!" ); } } while (false); | ||||||
1330 | SetCurLib( aDocument, aLibName ); | ||||||
1331 | SetCurWindow( pWin, true ); | ||||||
1332 | } | ||||||
1333 | } | ||||||
1334 | else | ||||||
1335 | SAL_WARN( "basctl.basicide", "No BASIC!")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "basctl.basicide")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break ; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "No BASIC!") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("basctl.basicide" ), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1335" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "No BASIC!"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "No BASIC!"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("basctl.basicide" ), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1335" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "No BASIC!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("basctl.basicide"), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1335" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "No BASIC!"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "No BASIC!"; :: sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("basctl.basicide" ), ("/home/maarten/src/libreoffice/core/basctl/source/basicide/basides1.cxx" ":" "1335" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||
1336 | if (BasicManager* pBasicMgr = FindBasicManager(pBasic)) | ||||||
1337 | StartListening(*pBasicMgr, DuplicateHandling::Prevent /* log on only once */); | ||||||
1338 | return pWin; | ||||||
1339 | } | ||||||
1340 | return nullptr; | ||||||
1341 | } | ||||||
1342 | |||||||
1343 | void Shell::AdjustPosSizePixel( const Point &rPos, const Size &rSize ) | ||||||
1344 | { | ||||||
1345 | // not if iconified because the whole text would be displaced then at restore | ||||||
1346 | if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 ) | ||||||
1347 | return; | ||||||
1348 | |||||||
1349 | Size aTabBarSize; | ||||||
1350 | aTabBarSize.setHeight( GetViewFrame()->GetWindow().GetFont().GetFontHeight() + TAB_HEIGHT_MARGIN ); | ||||||
1351 | aTabBarSize.setWidth( rSize.Width() ); | ||||||
1352 | |||||||
1353 | Size aSz( rSize ); | ||||||
1354 | Size aScrollBarBoxSz( aScrollBarBox->GetSizePixel() ); | ||||||
1355 | aSz.AdjustHeight( -(aScrollBarBoxSz.Height()) ); | ||||||
1356 | aSz.AdjustHeight( -(aTabBarSize.Height()) ); | ||||||
1357 | |||||||
1358 | Size aOutSz( aSz ); | ||||||
1359 | aSz.AdjustWidth( -(aScrollBarBoxSz.Width()) ); | ||||||
1360 | aScrollBarBox->SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) ); | ||||||
1361 | aVScrollBar->SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) ); | ||||||
1362 | aHScrollBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width(), aScrollBarBoxSz.Height() ) ); | ||||||
1363 | pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aScrollBarBoxSz.Height()+aSz.Height()), aTabBarSize ); | ||||||
1364 | |||||||
1365 | if (pLayout) | ||||||
1366 | pLayout->SetPosSizePixel(rPos, dynamic_cast<DialogWindow*>(pCurWin.get()) ? aSz : aOutSz); | ||||||
1367 | } | ||||||
1368 | |||||||
1369 | Reference< XModel > Shell::GetCurrentDocument() const | ||||||
1370 | { | ||||||
1371 | Reference< XModel > xDocument; | ||||||
1372 | if ( pCurWin && pCurWin->GetDocument().isDocument() ) | ||||||
1373 | xDocument = pCurWin->GetDocument().getDocument(); | ||||||
1374 | return xDocument; | ||||||
1375 | } | ||||||
1376 | |||||||
1377 | void Shell::Activate( bool bMDI ) | ||||||
1378 | { | ||||||
1379 | SfxViewShell::Activate( bMDI ); | ||||||
1380 | |||||||
1381 | if ( bMDI ) | ||||||
1382 | { | ||||||
1383 | if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get())) | ||||||
1384 | pDCurWin->UpdateBrowser(); | ||||||
1385 | } | ||||||
1386 | } | ||||||
1387 | |||||||
1388 | void Shell::Deactivate( bool bMDI ) | ||||||
1389 | { | ||||||
1390 | // bMDI == true means that another MDI has been activated; in case of a | ||||||
1391 | // deactivate due to a MessageBox bMDI is false | ||||||
1392 | if ( bMDI ) | ||||||
1393 | { | ||||||
1394 | if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin.get())) | ||||||
1395 | { | ||||||
1396 | pXDlgWin->DisableBrowser(); | ||||||
1397 | if( pXDlgWin->IsModified() ) | ||||||
1398 | MarkDocumentModified( pXDlgWin->GetDocument() ); | ||||||
1399 | } | ||||||
1400 | } | ||||||
1401 | } | ||||||
1402 | |||||||
1403 | } // namespace basctl | ||||||
1404 | |||||||
1405 | /* 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 |