29#include <officecfg/Office/BasicIDE.hxx>
37#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
38#include <com/sun/star/script/ModuleType.hpp>
39#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
40#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
41#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
42#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
57#include <svx/svxids.hrc>
70#include <osl/diagnose.h>
71#include <officecfg/Office/Common.hxx>
88short const ValidWindow = 0x1234;
95#if defined(OW) || defined(MTF)
112void lcl_PrintHeader(
Printer* pPrinter, sal_uInt16 nPages, sal_uInt16 nCurPage,
const OUString& rTitle,
bool bOutput )
124 aFont.SetWeight( WEIGHT_BOLD );
125 aFont.SetAlignment( ALIGN_BOTTOM );
138 Point(nXLeft, nYTop),
149 aFont.SetWeight( WEIGHT_NORMAL );
155 OUString aPageStr =
" [" +
IDEResId(RID_STR_PAGE) +
" " + OUString::number( nCurPage ) +
"]";
156 pPrinter->
DrawText( aPos, aPageStr );
170void lcl_ConvertTabsToSpaces( OUString& rLine )
172 if ( rLine.isEmpty() )
175 OUStringBuffer aResult( rLine );
177 sal_Int32 nMax = aResult.getLength();
178 while ( nPos < nMax )
180 if ( aResult[nPos] ==
'\t' )
183 OUStringBuffer aBlanker;
184 string::padToLength(aBlanker, ( 4 - ( nPos % 4 ) ),
' ');
185 aResult.remove( nPos, 1 );
186 aResult.insert( nPos, aBlanker );
187 nMax = aResult.getLength();
191 rLine = aResult.makeStringAndClear();
197 const OUString& aLibName,
const OUString& aName, OUString aModule)
199 , m_rLayout(*pParent)
200 , m_nValid(ValidWindow)
202 , m_aModule(
std::move(aModule))
277 bool const bModified = ( !
m_xModule->IsCompiled() ||
280 if ( bRunning || !bModified )
315 bool bMacrosDisabled = officecfg::Office::Common::Security::Scripting::DisableMacrosExecution::get();
318 std::unique_ptr<weld::MessageDialog> xBox(
320 VclButtonsType::Ok,
IDEResId(RID_STR_CANNOTRUNMACRO)));
337 sal_uInt16 nStart, nEnd;
343 for (sal_uInt32 nMacro = 0; nMacro <
m_xModule->GetMethods()->
Count(); nMacro++)
346 assert(pM &&
"Method?");
348 if ( nCurMethodStart >= nStart && nCurMethodStart <= nEnd )
419 xFP->appendFilter(
"BASIC" ,
"*.bas" );
421 xFP->setCurrentFilter(
"BASIC" );
427 SfxMedium aMedium( aPaths[0], StreamMode::READ | StreamMode::SHARE_DENYWRITE | StreamMode::NOCREATE );
438 if (pStream->
Tell() == 3)
452 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_COULDNTREAD)));
465 xFP.queryThrow<XFilePickerControlAccess>()->
setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0,
Any(
true));
467 xFP->appendFilter(
"BASIC",
"*.bas" );
469 xFP->setCurrentFilter(
"BASIC" );
475 SfxMedium aMedium( aPaths[0], StreamMode::WRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC );
494 VclMessageType::Warning, VclButtonsType::Ok,
IDEResId(RID_STR_COULDNTWRITE)));
532 for (sal_uInt32 nMethod = 0; nMethod <
m_xModule->GetMethods()->
Count(); nMethod++)
536 assert(pMethod &&
"Method not found! (NULL)");
619 if ( nErrCol2 != 0xFFFF )
626 bool const bMarkError = pBasic ==
GetBasic();
701 if ( !aWord.isEmpty() )
727 sal_uInt16 nStart, nEnd;
748 nNewStartY = std::min( nNewStartY, nMaxY );
749 pView->
Scroll( 0, -(nNewStartY-nOldStartY) );
835 sal_Int32 nLinespPage = aPaperSz.
Height()/nLineHeight;
838 sal_Int32 nCharspLine = aPaperSz.
Width() / std::max<tools::Long>(nXTextWidth, 1);
841 sal_Int32 nPages = nParas/nLinespPage+1;
842 sal_Int32 nCurPage = 1;
844 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nPrintPage == 0 );
846 for ( sal_uInt32 nPara = 0; nPara < nParas; ++nPara )
849 lcl_ConvertTabsToSpaces( aLine );
850 sal_Int32 nLines = aLine.getLength()/nCharspLine+1;
851 for (sal_Int32 nLine = 0; nLine < nLines; ++nLine)
853 sal_Int32 nBeginIndex = nLine*nCharspLine;
854 sal_Int32 nCopyCount = std::min<sal_Int32>(nCharspLine, aLine.getLength()-nBeginIndex);
855 OUString aTmpLine = aLine.copy(nBeginIndex, nCopyCount);
860 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nCurPage-1 == nPrintPage );
863 if( nCurPage-1 == nPrintPage )
864 pPrinter->
DrawText( aPos, aTmpLine );
902 case SID_BASICCOMPILE:
907 case SID_BASICSTEPOVER:
912 case SID_BASICSTEPINTO:
917 case SID_BASICSTEPOUT:
927 case SID_BASICSAVEAS:
932 case SID_IMPORT_DIALOG:
937 case SID_BASICIDE_MATCHGROUP:
942 case SID_BASICIDE_TOGGLEBRKPNT:
947 case SID_BASICIDE_MANAGEBRKPNTS:
952 case SID_BASICIDE_TOGGLEBRKPNTENABLED:
957 case SID_BASICIDE_ADDWATCH:
962 case SID_BASICIDE_REMOVEWATCH:
973 pBindings->Invalidate( SID_DOC_MODIFIED );
988 pBindings->Invalidate( SID_DOC_MODIFIED );
992 case SID_BASICIDE_BRKPNTSCHANGED:
1000 bool bLineNumbers = pItem && pItem->
GetValue();
1004 officecfg::Office::BasicIDE::EditorSettings::LineNumbering::set(bLineNumbers, batch);
1008 case SID_BASICIDE_DELETECURRENT:
1020 case FID_SEARCH_OFF:
1050 pBindings->Invalidate(SID_SIGNATURE);
1088 case SID_BASICIDE_STAT_POS:
1094 OUString aPos =
IDEResId( RID_STR_LINE ) +
1106 case SID_BASICIDE_STAT_TITLE:
1121 if (
GetEditorWindow().GetProcedureName(aCurrLine, sProcType, sProcName))
1126 if (!sProcName.isEmpty())
1127 aTitle +=
"." + sProcName;
1130 aTitle +=
" (" +
IDEResId(RID_STR_READONLY) +
")";
1132 SfxStringItem aTitleItem( SID_BASICIDE_STAT_TITLE, aTitle );
1137 case SID_ATTR_INSERT:
1149 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1183 OUString aModuleName;
1217 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1246 sal_uInt16 nFound = 0;
1247 if ( ( rSearchItem.
GetCommand() == SvxSearchCmd::FIND ) ||
1248 ( rSearchItem.
GetCommand() == SvxSearchCmd::FIND_ALL ) )
1252 else if ( ( rSearchItem.
GetCommand() == SvxSearchCmd::REPLACE ) ||
1253 ( rSearchItem.
GetCommand() == SvxSearchCmd::REPLACE_ALL ) )
1257 bool const bAll = rSearchItem.
GetCommand() == SvxSearchCmd::REPLACE_ALL;
1262 if ( bFromStart && !nFound )
1278 SearchOptionFlags::WHOLE_WORDS |
1279 SearchOptionFlags::BACKWARDS |
1280 SearchOptionFlags::REG_EXP |
1281 SearchOptionFlags::EXACT |
1282 SearchOptionFlags::SELECTION |
1283 SearchOptionFlags::SIMILARITY;
1287 nOptions |= SearchOptionFlags::REPLACE;
1288 nOptions |= SearchOptionFlags::REPLACE_ALL;
1305 for (sal_uInt32 nMethod = 0; nMethod <
m_xModule->GetMethods()->
Count(); nMethod++)
1308 assert(pMethod &&
"Method not found! (NULL)");
1325 OUString aModName(
GetName() );
1326 OUString aLibSubName;
1331 case script::ModuleType::DOCUMENT:
1333 aLibSubName =
IDEResId( RID_STR_DOCUMENT_OBJECTS );
1334 uno::Reference< container::XNameContainer > xLib =
aDocument.getOrCreateLibrary(
E_SCRIPTS, aLibName );
1339 if( !sObjName.isEmpty() )
1341 aModName +=
" (" + sObjName +
")";
1346 case script::ModuleType::FORM:
1347 aLibSubName =
IDEResId( RID_STR_USERFORMS );
1349 case script::ModuleType::NORMAL:
1350 aLibSubName =
IDEResId( RID_STR_NORMAL_MODULES );
1352 case script::ModuleType::CLASS:
1353 aLibSubName =
IDEResId( RID_STR_CLASS_MODULES );
1373 bool bPaste =
false;
1377 if ( xClipboard.is() )
1383 datatransfer::DataFlavor aFlavor;
1385 if ( xTransf->isDataFlavorSupported( aFlavor ) )
1395 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1436 rObjectCatalog(rObjectCatalog_)
1490 case SID_SHOW_PROPERTYBROWSER:
1494 case SID_BASICIDE_CHOOSEMACRO:
1539 aConfig.RemoveListener(
this);
1571 if (bFirst || aDocColor != m_aBackgroundColor)
1573 m_aBackgroundColor = aDocColor;
1574 if (!bFirst && pEditor)
1576 pEditor->SetBackground(
Wallpaper(m_aBackgroundColor));
1577 pEditor->Invalidate();
1582 if (bFirst || aFontColor != m_aFontColor)
1584 m_aFontColor = aFontColor;
1585 if (!bFirst && pEditor)
1586 pEditor->ChangeFontColor(m_aFontColor);
1589 bool bChanged =
false;
1590 for (
const auto& vId: vIds)
1592 Color const aColor = aConfig.GetColorValue(vId.eEntry).nColor;
1593 Color& rMyColor = aColors[vId.eTokenType];
1594 if (bFirst || aColor != rMyColor)
1600 if (bChanged && !bFirst && pEditor)
1601 pEditor->UpdateSyntaxHighlighting();
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static void SetDebugMode(bool bDebugMode)
static void EnableBreak(bool bEnable)
StarBASIC * GetLib(sal_uInt16 nLib) const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
Size GetOutputSize() const
float approximate_digit_width() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
const Color & GetLineColor() const
const MapMode & GetMapMode() const
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetFillColor() const
constexpr tools::Long Y() const
tools::Long AdjustY(tools::Long nVertMove)
constexpr tools::Long X() const
BasicDebugFlags GetDebugFlags() const
void SetDebugFlags(BasicDebugFlags n)
void GetLineRange(sal_uInt16 &, sal_uInt16 &)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
SvStream * GetOutStream()
sal_uInt16 GetSlot() const
const T * GetArg(sal_uInt16 nSlotId) const
weld::Window * GetFrameWeld() const
vcl::Window & GetWindow() const
SfxViewFrame & GetViewFrame() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static sal_uInt16 GetCol2()
static sal_uInt16 GetLine()
static ErrCode const & GetErrorCode()
static sal_uInt16 GetCol1()
SbModule * FindModule(std::u16string_view)
virtual void SetModified(bool) override
void StartReadingUnicodeText(rtl_TextEncoding eReadBomCharSet)
SvStream & WriteUChar(unsigned char nChar)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
SvxSearchCmd GetCommand() const
const i18nutil::SearchOptions2 & GetSearchOptions() const
SfxUndoManager & GetUndoManager()
TextView * GetActiveView() const
OUString GetWord(const TextPaM &rCursorPos, TextPaM *pStartOfWord=nullptr, TextPaM *pEndOfWord=nullptr)
tools::Long GetTextHeight() const
void Write(SvStream &rOutput)
void SetModified(bool bModified)
OUString GetText(LineEnd aSeparator=LINEEND_LF) const
sal_uInt32 GetParagraphCount() const
void SetUpdateMode(bool bUpdate)
tools::Long GetCharHeight() const
sal_uInt32 GetPara() const
sal_Int32 GetIndex() const
const TextPaM & GetStart() const
const TextPaM & GetEnd() const
void SetSelection(const TextSelection &rNewSel)
void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll)
void ShowCursor(bool bGotoCursor=true, bool bForceVisCursor=true)
vcl::Window * GetWindow() const
void Read(SvStream &rInput)
bool IsInsertMode() const
void SetReadOnly(bool bReadOnly)
bool Search(const i18nutil::SearchOptions2 &rSearchOptions, bool bForward)
bool KeyInput(const KeyEvent &rKeyEvent)
const TextSelection & GetSelection() const
sal_uInt16 Replace(const i18nutil::SearchOptions2 &rSearchOptions, bool bAll, bool bForward)
TextEngine * GetTextEngine() const
const Point & GetStartDocPos() const
void incBusy(const weld::Widget *pIgnore)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual void dispose() override
const OUString & GetLibName() const
ScriptDocument m_aDocument
OUString CreateQualifiedName()
const OUString & GetName() const
const ScriptDocument & GetDocument() const
ScrollAdaptor * GetHScrollBar() const
void InsertSorted(BreakPoint pBrk)
void SetBreakPointsInBasic(SbModule *pModule)
void remove(const BreakPoint *ptr)
BreakPoint * FindBreakPoint(sal_uInt16 nLine)
void SetLayoutWindow(Layout *)
encapsulates (actions on) the signature/state of a document
bool supportsSignatures() const
determines whether the instance is valid
void signScriptingContent(weld::Window *pDialogParent) const
signs the scripting content inside the document
void ForceSyntaxTimeout()
void CreateProgress(const OUString &rText, sal_uInt32 nRange)
sal_Int32 GetLineNumber() const
virtual void dispose() override
void AddToLeft(DockingWindow *pWin, Size const &rSize)
virtual void Deactivating()
virtual void Activating(BaseWindow &)
void AddToBottom(DockingWindow *pWin, Size const &rSize)
void NewConfig(bool bFirst)
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
virtual ~SyntaxColors() override
svtools::ColorConfig aConfig
void SetActiveEditor(EditorWindow *pEditor_)
ObjectCatalog & rObjectCatalog
virtual void dispose() override
void ShowWatchWindow(bool bVisible)
void ShowStackWindow(bool bVisible)
ModulWindowLayout(vcl::Window *pParent, ObjectCatalog &)
VclPtr< ModulWindow > pChild
virtual void Activating(BaseWindow &) override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
VclPtr< StackWindow > aStackWindow
virtual void Deactivating() override
virtual void OnFirstSize(tools::Long nWidth, tools::Long nHeight) override
basctl::ModulWindowLayout::SyntaxColors aSyntaxColors
virtual ~ModulWindowLayout() override
void BasicAddWatch(OUString const &)
virtual void UpdateDebug(bool bBasicStopped) override
VclPtr< WatchWindow > aWatchWindow
virtual void GetState(SfxItemSet &, unsigned nWhich) override
BreakPointWindow & GetBreakPointWindow()
void BasicToggleBreakPoint()
virtual void printPage(sal_Int32 nPage, Printer *pPrinter) override
virtual void Activating() override
sal_Int32 FormatAndPrint(Printer *pPrinter, sal_Int32 nPage)
virtual sal_Int32 countPages(Printer *pPrinter) override
BasicDebugFlags BasicBreakHdl()
virtual sal_uInt16 StartSearchAndReplace(SvxSearchItem const &, bool bFromStart=false) override
virtual void OnNewDocument() override
virtual bool IsModified() override
ScrollAdaptor & GetEditVScrollBar()
void EditMacro(const OUString &rMacroName)
virtual OUString GetHid() const override
virtual void BasicStopped() override
SbModuleRef const & XModule()
virtual void SetReadOnly(bool bReadOnly) override
virtual void ExecuteGlobal(SfxRequest &rReq) override
virtual void UpdateData() override
virtual void StoreData() override
void SetModule(const OUString &aModule)
virtual void dispose() override
VclPtr< ComplexEditorWindow > m_aXEditorWindow
virtual void GetState(SfxItemSet &) override
void ShowCursor(bool bOn)
BreakPointList & GetBreakPoints()
virtual void Deactivating() override
EditorWindow & GetEditorWindow()
OUString GetSbModuleName()
virtual EntryDescriptor CreateEntryDescriptor() override
virtual void GetFocus() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
virtual ItemType GetType() const override
virtual SearchOptionFlags GetSearchOptions() override
virtual void ExecuteCommand(SfxRequest &rReq) override
void BasicErrorHdl(StarBASIC const *pBasic)
virtual SfxUndoManager * GetUndoManager() override
virtual void DoScroll(Scrollable *pCurScrollBar) override
virtual bool HasActiveEditor() const override
void ToggleBreakPoint(sal_uInt16 nLine)
virtual bool AllowUndo() override
virtual bool IsReadOnly() override
virtual void BasicStarted() override
virtual void DoInit() override
ExtTextEngine * GetEditEngine()
virtual void Resize() override
virtual ~ModulWindow() override
void UpdateBreakPoint(const BreakPoint &rBrk)
virtual OUString GetTitle() override
ModulWindowLayout & m_rLayout
void BasicToggleBreakPointEnabled()
void AssertValidEditEngine()
static void getObjectName(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName, OUString &rObjName)
A docking window that contains a tree of the currently loaded macros.
void UpdateEntries()
Update the entries of Object Catalog Treelist.
encapsulates a document which contains Basic scripts and dialogs
bool removeModule(const OUString &_rLibName, const OUString &_rModuleName) const
removes a given script module from the document
BasicManager * getBasicManager() const
returns the BasicManager associated with this instance
bool updateModule(const OUString &_rLibName, const OUString &_rModName, const OUString &_rModuleCode) const
updates a given module with new code
static std::shared_ptr< ConfigurationChanges > create()
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
void SetContext(Context _eNewContext)
void SetFontSize(const Size &)
void SetTransparent(bool bTransparent)
void SetAlignment(TextAlign)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
const vcl::Font & GetFont() const
Size GetOutputSizePixel() const
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
weld::Window * GetFrameWeld() const
virtual OUString GetText() const
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard()
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral HID_BASICIDE_MODULWINDOW
constexpr sal_uInt16 KEY_DELETE
tools::Long const nRightMargin
tools::Long const nBottomMargin
tools::Long const nTopMargin
tools::Long const nBorder
tools::Long const nLeftMargin
void RunMethod(SbMethod const *pMethod)
SfxBindings * GetBindingsPtr()
void setTextEngineText(ExtTextEngine &, std::u16string_view)
constexpr OUStringLiteral FilterMask_All
bool implImportDialog(weld::Window *pWin, const ScriptDocument &rDocument, const OUString &aLibName)
OUString ChooseMacro(weld::Window *pParent, const uno::Reference< frame::XModel > &rxLimitToDocument, const uno::Reference< frame::XFrame > &xDocFrame, bool bChooseOnly)
OUString getTextEngineText(ExtTextEngine &)
Helper functions to get/set text in TextEngine using the stream interface.
void MarkDocumentModified(const ScriptDocument &rDocument)
sal_uInt32 CalcLineCount(SvStream &rStream)
void InvalidateDebuggerSlots()
OUString IDEResId(TranslateId aId)
static void lcl_PrintHeader(Printer *pPrinter, const OUString &rTitle)
bool QueryDelModule(std::u16string_view rName, weld::Widget *pParent)
css::uno::Reference< css::uno::XCurrentContext > NewFlagContext(const OUString &sName)
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
BasicDebugFlags nBasicFlags
void GetSelection(struct ESelection &rSel, SvxTextForwarder const *pForwarder) noexcept