diff options
Diffstat (limited to 'basctl/source/basicide/baside2b.cxx')
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 319 |
1 files changed, 220 insertions, 99 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 9671d149ca2b..e5fd31d22a21 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -40,11 +40,14 @@ #include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/script/XLibraryContainer2.hpp> #include <comphelper/string.hxx> +#include <comphelper/diagnose_ex.hxx> +#include <o3tl/string_view.hxx> #include <officecfg/Office/Common.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/progress.hxx> #include <sfx2/viewfrm.hxx> #include <tools/debug.hxx> +#include <utility> #include <vcl/image.hxx> #include <vcl/weld.hxx> #include <vcl/weldutils.hxx> @@ -66,6 +69,9 @@ #include <unotools/charclass.hxx> #include "textwindowpeer.hxx" #include "uiobject.hxx" +#include <basegfx/utils/zoomtools.hxx> +#include <svl/itemset.hxx> +#include <BasicColorConfig.hxx> namespace basctl { @@ -230,7 +236,7 @@ public: } private: - sal_uLong nCurState; + sal_uInt32 nCurState; }; EditorWindow::EditorWindow (vcl::Window* pParent, ModulWindow* pModulWindow) : @@ -243,10 +249,14 @@ EditorWindow::EditorWindow (vcl::Window* pParent, ModulWindow* pModulWindow) : bHighlighting(false), bDoSyntaxHighlight(true), bDelayHighlight(true), + m_nLastHighlightPara(0), pCodeCompleteWnd(VclPtr<CodeCompleteWindow>::Create(this)) { set_id("EditorWindow"); - SetBackground(Wallpaper(rModulWindow.GetLayout().GetSyntaxBackgroundColor())); + const Wallpaper aBackground(rModulWindow.GetLayout().GetSyntaxBackgroundColor()); + SetBackground(aBackground); + GetWindow(GetWindowType::Border)->SetBackground(aBackground); + SetLineHighlightColor(GetShell()->GetColorConfig()->GetCurrentColorScheme().m_aLineHighlightColor); SetPointer( PointerStyle::Text ); SetHelpId( HID_BASICIDE_EDITORWINDOW ); @@ -258,6 +268,10 @@ EditorWindow::EditorWindow (vcl::Window* pParent, ModulWindow* pModulWindow) : std::unique_lock g(mutex_); notifier_ = n; } + + // The zoom level applied to the editor window is the zoom slider value in the shell + nCurrentZoomLevel = GetShell()->GetCurrentZoomSliderValue(); + const Sequence<OUString> aPropertyNames{"FontHeight", "FontName"}; n->addPropertiesChangeListener(aPropertyNames, listener_); } @@ -467,8 +481,9 @@ void EditorWindow::MouseButtonUp( const MouseEvent &rEvt ) void EditorWindow::MouseButtonDown( const MouseEvent &rEvt ) { GrabFocus(); - if ( pEditView ) - pEditView->MouseButtonDown( rEvt ); + if (!pEditView) + return; + pEditView->MouseButtonDown(rEvt); if( pCodeCompleteWnd->IsVisible() ) { if (pEditView->GetSelection() != pCodeCompleteWnd->GetTextSelection()) @@ -489,8 +504,25 @@ void EditorWindow::Command( const CommandEvent& rCEvt ) ( rCEvt.GetCommand() == CommandEventId::StartAutoScroll ) || ( rCEvt.GetCommand() == CommandEventId::AutoScroll ) ) { - HandleScrollCommand( rCEvt, rModulWindow.GetHScrollBar(), &rModulWindow.GetEditVScrollBar() ); - } else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) { + const CommandWheelData* pData = rCEvt.GetWheelData(); + + // Check if it is a Ctrl+Wheel zoom command + if (pData && pData->IsMod1()) + { + const sal_uInt16 nOldZoom = GetCurrentZoom(); + sal_uInt16 nNewZoom; + if( pData->GetDelta() < 0 ) + nNewZoom = std::max<sal_uInt16>(basctl::Shell::GetMinZoom(), + basegfx::zoomtools::zoomOut(nOldZoom)); + else + nNewZoom = std::min<sal_uInt16>(basctl::Shell::GetMaxZoom(), + basegfx::zoomtools::zoomIn(nOldZoom)); + GetShell()->SetGlobalEditorZoomLevel(nNewZoom); + } + else + HandleScrollCommand(rCEvt, &rModulWindow.GetEditHScrollBar(), &rModulWindow.GetEditVScrollBar()); + } + else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) { SfxDispatcher* pDispatcher = GetDispatcher(); if ( pDispatcher ) { @@ -534,7 +566,11 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) if (pCodeCompleteWnd->IsVisible() && CodeCompleteOptions::IsCodeCompleteOn()) { - if (pCodeCompleteWnd->HandleKeyInput(rKEvt)) + pCodeCompleteWnd->HandleKeyInput(rKEvt); + if( rKEvt.GetKeyCode().GetCode() == KEY_UP + || rKEvt.GetKeyCode().GetCode() == KEY_DOWN + || rKEvt.GetKeyCode().GetCode() == KEY_TAB + || rKEvt.GetKeyCode().GetCode() == KEY_POINT) return; } @@ -599,6 +635,13 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) pBindings->Update( SID_BASICIDE_STAT_POS ); pBindings->Update( SID_BASICIDE_STAT_TITLE ); } + if ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_ALPHA || + rKEvt.GetKeyCode().GetGroup() == KEYGROUP_NUM ) + { + // If the module is read-only, warn that it can't be edited + if ( rModulWindow.IsReadOnly() ) + rModulWindow.ShowReadOnlyInfoBar(); + } if ( !bWasModified && pEditEngine->IsModified() ) { pBindings->Invalidate( SID_SAVEDOC ); @@ -689,6 +732,11 @@ void EditorWindow::HandleAutoCorrect() } } +void EditorWindow::SetLineHighlightColor(Color aColor) +{ + m_aLineHighlightColor = aColor; +} + TextSelection EditorWindow::GetLastHighlightPortionTextSelection() const {//creates a text selection from the highlight portion on the cursor const sal_uInt32 nLine = GetEditView()->GetSelection().GetStart().GetPara(); @@ -714,9 +762,9 @@ TextSelection EditorWindow::GetLastHighlightPortionTextSelection() const if( aPortions.empty() ) return TextSelection(); - OUString sStr = aLine.copy( r.nBegin, r.nEnd - r.nBegin ); + std::u16string_view sStr = aLine.subView( r.nBegin, r.nEnd - r.nBegin ); TextPaM aStart( nLine, r.nBegin ); - TextPaM aEnd( nLine, r.nBegin + sStr.getLength() ); + TextPaM aEnd( nLine, r.nBegin + sStr.size() ); return TextSelection( aStart, aEnd ); } @@ -792,17 +840,17 @@ void EditorWindow::HandleProcedureCompletion() if( aCurrPortions.size() >= 3 ) {//at least 3 tokens: (sub|function) whitespace identifier... HighlightPortion& r = aCurrPortions.front(); - OUString sStr = aCurrLine.copy(r.nBegin, r.nEnd - r.nBegin); + std::u16string_view sStr = aCurrLine.subView(r.nBegin, r.nEnd - r.nBegin); if( r.tokenType == TokenType::Keywords ) { - if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") ) + if( o3tl::equalsIgnoreAsciiCase(sStr, u"sub") || o3tl::equalsIgnoreAsciiCase(sStr, u"function") ) { pEditView->InsertText( sText );//append to the end GetEditView()->SetSelection(aSel); break; } - if( sStr.equalsIgnoreAsciiCase("end") ) + if( o3tl::equalsIgnoreAsciiCase(sStr, u"end") ) break; } } @@ -810,7 +858,7 @@ void EditorWindow::HandleProcedureCompletion() } } -bool EditorWindow::GetProcedureName(OUString const & rLine, OUString& rProcType, OUString& rProcName) const +bool EditorWindow::GetProcedureName(std::u16string_view rLine, OUString& rProcType, OUString& rProcName) const { std::vector<HighlightPortion> aPortions; aHighlighter.getHighlightPortions(rLine, aPortions); @@ -823,10 +871,10 @@ bool EditorWindow::GetProcedureName(OUString const & rLine, OUString& rProcType, for (auto const& portion : aPortions) { - OUString sTokStr = rLine.copy(portion.nBegin, portion.nEnd - portion.nBegin); + std::u16string_view sTokStr = rLine.substr(portion.nBegin, portion.nEnd - portion.nBegin); - if( portion.tokenType == TokenType::Keywords && ( sTokStr.equalsIgnoreAsciiCase("sub") - || sTokStr.equalsIgnoreAsciiCase("function")) ) + if( portion.tokenType == TokenType::Keywords && ( o3tl::equalsIgnoreAsciiCase(sTokStr, u"sub") + || o3tl::equalsIgnoreAsciiCase(sTokStr, u"function")) ) { rProcType = sTokStr; bFoundType = true; @@ -936,9 +984,34 @@ void EditorWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectan if (!pEditEngine) // We need it now at latest CreateEditEngine(); + HighlightCurrentLine(rRenderContext); + pEditView->Paint(rRenderContext, rRect); } +void EditorWindow::HighlightCurrentLine(vcl::RenderContext& rRenderContext) +{ + // If the cursor is in a single line and nothing is selected, then a highlight color + // is applied to the background of the current line + TextPaM aStartPaM = pEditView->GetSelection().GetStart(); + TextPaM aEndPaM = pEditView->GetSelection().GetEnd(); + if (aStartPaM == aEndPaM) + { + Size aWinSize(GetOutputSizePixel()); + sal_Int16 nDocPosY = pEditView->GetStartDocPos().Y(); + sal_Int16 nY1 = pEditEngine->PaMtoEditCursor(aStartPaM).TopLeft().Y(); + sal_Int16 nY2 = pEditEngine->PaMtoEditCursor(aStartPaM).BottomRight().Y(); + // Only draw if the cursor is in a visible position + if ((nY1 >= nDocPosY && nY1 <= nDocPosY + aWinSize.Height()) + || (nY2 >= nDocPosY && nY2 <= nDocPosY + aWinSize.Height())) + { + tools::Rectangle aRect(Point(0, nY1 - nDocPosY), Point(aWinSize.Width(), nY2 - nDocPosY)); + rRenderContext.SetFillColor(m_aLineHighlightColor); + rRenderContext.DrawRect(aRect); + } + } +} + void EditorWindow::LoseFocus() { // tdf#114258 wait until the next event loop cycle to do this so it doesn't @@ -970,20 +1043,14 @@ void EditorWindow::SetSourceInBasic() // Returns the position of the last character of any of the following // EOL char combinations: CR, CR/LF, LF, return -1 if no EOL is found -sal_Int32 searchEOL( const OUString& rStr, sal_Int32 fromIndex ) +sal_Int32 searchEOL( std::u16string_view rStr, sal_Int32 fromIndex ) { - sal_Int32 iRetPos = -1; + size_t iLF = rStr.find( LINE_SEP, fromIndex ); + if( iLF != std::u16string_view::npos ) + return iLF; - sal_Int32 iLF = rStr.indexOf( LINE_SEP, fromIndex ); - if( iLF != -1 ) - { - iRetPos = iLF; - } - else - { - iRetPos = rStr.indexOf( LINE_SEP_CR, fromIndex ); - } - return iRetPos; + size_t iCR = rStr.find( LINE_SEP_CR, fromIndex ); + return iCR == std::u16string_view::npos ? -1 : iCR; } void EditorWindow::CreateEditEngine() @@ -1016,7 +1083,7 @@ void EditorWindow::CreateEditEngine() // nLines*4: SetText+Formatting+DoHighlight+Formatting // it could be cut down on one formatting but you would wait even longer // for the text then if the source code is long... - pProgress.reset(new ProgressInfo(GetShell()->GetViewFrame()->GetObjectShell(), + pProgress.reset(new ProgressInfo(GetShell()->GetViewFrame().GetObjectShell(), IDEResId(RID_STR_GENERATESOURCE), nLines * 4)); setTextEngineText(*pEditEngine, aOUSource); @@ -1078,9 +1145,8 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) TextHint const& rTextHint = *pTextHint; if( rTextHint.GetId() == SfxHintId::TextViewScrolled ) { - if ( rModulWindow.GetHScrollBar() ) - rModulWindow.GetHScrollBar()->SetThumbPos( pEditView->GetStartDocPos().X() ); rModulWindow.GetEditVScrollBar().SetThumbPos( pEditView->GetStartDocPos().Y() ); + rModulWindow.GetEditHScrollBar().SetThumbPos( pEditView->GetStartDocPos().X() ); rModulWindow.GetBreakPointWindow().DoScroll ( rModulWindow.GetBreakPointWindow().GetCurYOffset() - pEditView->GetStartDocPos().Y() ); rModulWindow.GetLineNumberWindow().DoScroll @@ -1102,15 +1168,13 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) } else if( rTextHint.GetId() == SfxHintId::TextFormatted ) { - if ( rModulWindow.GetHScrollBar() ) + + const tools::Long nWidth = pEditEngine->CalcTextWidth(); + if ( nWidth != nCurTextWidth ) { - const tools::Long nWidth = pEditEngine->CalcTextWidth(); - if ( nWidth != nCurTextWidth ) - { - nCurTextWidth = nWidth; - rModulWindow.GetHScrollBar()->SetRange( Range( 0, nCurTextWidth-1) ); - rModulWindow.GetHScrollBar()->SetThumbPos( pEditView->GetStartDocPos().X() ); - } + nCurTextWidth = nWidth; + rModulWindow.GetEditHScrollBar().SetRange( Range( 0, nCurTextWidth-1) ); + rModulWindow.GetEditHScrollBar().SetThumbPos( pEditView->GetStartDocPos().X() ); } tools::Long nPrevTextWidth = nCurTextWidth; nCurTextWidth = pEditEngine->CalcTextWidth(); @@ -1138,9 +1202,27 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) pBindings->Invalidate( SID_COPY ); } } + else if( rTextHint.GetId() == SfxHintId::TextViewCaretChanged ) + { + // Check whether the line number where the caret is has changed and the + // highlight needs to be redrawn + sal_uInt32 nStartPara = pEditView->GetSelection().GetStart().GetPara(); + sal_uInt32 nEndPara = pEditView->GetSelection().GetEnd().GetPara(); + if (nStartPara == nEndPara && nStartPara != m_nLastHighlightPara) + { + m_nLastHighlightPara = nStartPara; + Invalidate(); + rModulWindow.GetLineNumberWindow().Invalidate(); + } + else if (nStartPara != nEndPara) + { + // If multiple lines are selected, then update the line number window + rModulWindow.GetLineNumberWindow().Invalidate(); + } + } } -OUString EditorWindow::GetActualSubName( sal_uLong nLine ) +OUString EditorWindow::GetActualSubName( sal_uInt32 nLine ) { SbxArrayRef pMethods = rModulWindow.GetSbModule()->GetMethods(); for (sal_uInt32 i = 0; i < pMethods->Count(); i++) @@ -1165,10 +1247,8 @@ void EditorWindow::SetScrollBarRanges() if ( !pEditEngine ) return; - if ( rModulWindow.GetHScrollBar() ) - rModulWindow.GetHScrollBar()->SetRange( Range( 0, nCurTextWidth-1 ) ); - rModulWindow.GetEditVScrollBar().SetRange( Range( 0, pEditEngine->GetTextHeight()-1 ) ); + rModulWindow.GetEditHScrollBar().SetRange( Range( 0, nCurTextWidth-1 ) ); } void EditorWindow::InitScrollBars() @@ -1184,17 +1264,14 @@ void EditorWindow::InitScrollBars() rModulWindow.GetEditVScrollBar().SetThumbPos(pEditView->GetStartDocPos().Y()); rModulWindow.GetEditVScrollBar().Show(); - if (rModulWindow.GetHScrollBar()) - { - rModulWindow.GetHScrollBar()->SetVisibleSize(aOutSz.Width()); - rModulWindow.GetHScrollBar()->SetPageSize(aOutSz.Width() * 8 / 10); - rModulWindow.GetHScrollBar()->SetLineSize(GetTextWidth( "x" ) ); - rModulWindow.GetHScrollBar()->SetThumbPos(pEditView->GetStartDocPos().X()); - rModulWindow.GetHScrollBar()->Show(); - } + rModulWindow.GetEditHScrollBar().SetVisibleSize(aOutSz.Width()); + rModulWindow.GetEditHScrollBar().SetPageSize(aOutSz.Width() * 8 / 10); + rModulWindow.GetEditHScrollBar().SetLineSize(GetTextWidth( "x" )); + rModulWindow.GetEditHScrollBar().SetThumbPos(pEditView->GetStartDocPos().X()); + rModulWindow.GetEditHScrollBar().Show(); } -void EditorWindow::ImpDoHighlight( sal_uLong nLine ) +void EditorWindow::ImpDoHighlight( sal_uInt32 nLine ) { if ( !bDoSyntaxHighlight ) return; @@ -1226,13 +1303,17 @@ void EditorWindow::ChangeFontColor( Color aColor ) void EditorWindow::UpdateSyntaxHighlighting () { - const sal_uInt32 nCount = pEditEngine->GetParagraphCount(); - for (sal_uInt32 i = 0; i < nCount; ++i) - DoDelayedSyntaxHighlight(i); + if (pEditEngine) + { + const sal_uInt32 nCount = pEditEngine->GetParagraphCount(); + for (sal_uInt32 i = 0; i < nCount; ++i) + DoDelayedSyntaxHighlight(i); + } } void EditorWindow::ImplSetFont() { + // Get default font name and height defined in the Options dialog OUString sFontName(officecfg::Office::Common::Font::SourceViewFont::FontName::get().value_or(OUString())); if (sFontName.isEmpty()) { @@ -1241,7 +1322,12 @@ void EditorWindow::ImplSetFont() GetDefaultFontFlags::NONE, GetOutDev())); sFontName = aTmpFont.GetFamilyName(); } - Size aFontSize(0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get()); + sal_uInt16 nDefaultFontHeight = officecfg::Office::Common::Font::SourceViewFont::FontHeight::get(); + + // Calculate font size considering zoom level + sal_uInt16 nNewFontHeight = nDefaultFontHeight * (static_cast<float>(nCurrentZoomLevel) / 100); + Size aFontSize(0, nNewFontHeight); + vcl::Font aFont(sFontName, aFontSize); aFont.SetColor(rModulWindow.GetLayout().GetFontColor()); SetPointFont(*GetOutDev(), aFont); // FIXME RenderContext @@ -1249,6 +1335,7 @@ void EditorWindow::ImplSetFont() rModulWindow.GetBreakPointWindow().SetFont(aFont); rModulWindow.GetLineNumberWindow().SetFont(aFont); + rModulWindow.Invalidate(); if (pEditEngine) { @@ -1256,9 +1343,28 @@ void EditorWindow::ImplSetFont() pEditEngine->SetFont(aFont); pEditEngine->SetModified(bModified); } + + // Update controls + if (SfxBindings* pBindings = GetBindingsPtr()) + { + pBindings->Invalidate( SID_BASICIDE_CURRENT_ZOOM ); + pBindings->Invalidate( SID_ATTR_ZOOMSLIDER ); + } +} + +void EditorWindow::SetEditorZoomLevel(sal_uInt16 nNewZoomLevel) +{ + if (nCurrentZoomLevel == nNewZoomLevel) + return; + + if (nNewZoomLevel < MIN_ZOOM_LEVEL || nNewZoomLevel > MAX_ZOOM_LEVEL) + return; + + nCurrentZoomLevel = nNewZoomLevel; + ImplSetFont(); } -void EditorWindow::DoSyntaxHighlight( sal_uLong nPara ) +void EditorWindow::DoSyntaxHighlight( sal_uInt32 nPara ) { // because of the DelayedSyntaxHighlight it's possible // that this line does not exist anymore! @@ -1271,7 +1377,7 @@ void EditorWindow::DoSyntaxHighlight( sal_uLong nPara ) } } -void EditorWindow::DoDelayedSyntaxHighlight( sal_uLong nPara ) +void EditorWindow::DoDelayedSyntaxHighlight( sal_uInt32 nPara ) { // line is only added to list, processed in TimerHdl // => don't manipulate breaks while EditEngine is formatting @@ -1313,7 +1419,7 @@ IMPL_LINK_NOARG(EditorWindow, SyntaxTimerHdl, Timer *, void) bHighlighting = false; } -void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, bool bInserted ) +void EditorWindow::ParagraphInsertedDeleted( sal_uInt32 nPara, bool bInserted ) { if ( pProgress ) pProgress->StepProgress(); @@ -1346,7 +1452,7 @@ void EditorWindow::CreateProgress( const OUString& rText, sal_uInt32 nRange ) { DBG_ASSERT( !pProgress, "ProgressInfo exists already" ); pProgress.reset(new ProgressInfo( - GetShell()->GetViewFrame()->GetObjectShell(), + GetShell()->GetViewFrame().GetObjectShell(), rText, nRange )); @@ -1419,7 +1525,7 @@ void BreakPointWindow::ShowMarker(vcl::RenderContext& rRenderContext) Size const aOutSz = GetOutDev()->GetOutputSize(); tools::Long const nLineHeight = GetTextHeight(); - Image aMarker = GetImage(bErrorMarker ? OUString(RID_BMP_ERRORMARKER) : OUString(RID_BMP_STEPMARKER)); + Image aMarker = GetImage(bErrorMarker ? RID_BMP_ERRORMARKER : RID_BMP_STEPMARKER); Size aMarkerSz(aMarker.GetSizePixel()); aMarkerSz = rRenderContext.PixelToLogic(aMarkerSz); @@ -1427,7 +1533,7 @@ void BreakPointWindow::ShowMarker(vcl::RenderContext& rRenderContext) aMarkerOff.setX( (aOutSz.Width() - aMarkerSz.Width()) / 2 ); aMarkerOff.setY( (nLineHeight - aMarkerSz.Height()) / 2 ); - sal_uLong nY = nMarkerPos * nLineHeight - nCurYOffset; + tools::Long nY = nMarkerPos * nLineHeight - nCurYOffset; Point aPos(0, nY); aPos += aMarkerOff; @@ -1482,7 +1588,7 @@ void BreakPointWindow::MouseButtonDown( const MouseEvent& rMEvt ) { tools::Long nYPos = aMousePos.Y() + nCurYOffset; tools::Long nLine = nYPos / nLineHeight + 1; - rModulWindow.ToggleBreakPoint( static_cast<sal_uLong>(nLine) ); + rModulWindow.ToggleBreakPoint( static_cast<sal_uInt16>(nLine) ); Invalidate(); } } @@ -1506,7 +1612,7 @@ void BreakPointWindow::Command( const CommandEvent& rCEvt ) // test if break point is enabled... std::unique_ptr<weld::Menu> xBrkPropMenu = xUIBuilder->weld_menu("breakmenu"); xBrkPropMenu->set_active("active", pBrk->bEnabled); - OString sCommand = xBrkPropMenu->popup_at_rect(pPopupParent, aRect); + OUString sCommand = xBrkPropMenu->popup_at_rect(pPopupParent, aRect); if (sCommand == "active") { pBrk->bEnabled = !pBrk->bEnabled; @@ -1524,7 +1630,7 @@ void BreakPointWindow::Command( const CommandEvent& rCEvt ) else { std::unique_ptr<weld::Menu> xBrkListMenu = xUIBuilder->weld_menu("breaklistmenu"); - OString sCommand = xBrkListMenu->popup_at_rect(pPopupParent, aRect); + OUString sCommand = xBrkListMenu->popup_at_rect(pPopupParent, aRect); if (sCommand == "manage") { BreakPointDialog aBrkDlg(pPopupParent, GetBreakPoints()); @@ -1588,8 +1694,8 @@ struct WatchItem WatchItem* mpArrayParentItem; - explicit WatchItem (OUString const& rName): - maName(rName), + explicit WatchItem (OUString aName): + maName(std::move(aName)), nDimLevel(0), nDimCount(0), mpArrayParentItem(nullptr) @@ -1668,7 +1774,7 @@ void WatchWindow::dispose() // Destroy user data m_xTreeListBox->all_foreach([this](weld::TreeIter& rEntry){ - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(rEntry).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(rEntry)); delete pItem; return false; }); @@ -1729,7 +1835,7 @@ void WatchWindow::AddWatch( const OUString& rVName ) lcl_SeparateNameAndIndex( rVName, aVar, aIndex ); WatchItem* pWatchItem = new WatchItem(aVar); - OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pWatchItem))); + OUString sId(weld::toId(pWatchItem)); std::unique_ptr<weld::TreeIter> xRet = m_xTreeListBox->make_iterator(); m_xTreeListBox->insert(nullptr, -1, &aVar, &sId, nullptr, nullptr, false, xRet.get()); m_xTreeListBox->set_text(*xRet, "", 1); @@ -1752,7 +1858,7 @@ void WatchWindow::RemoveSelectedWatch() m_xTreeListBox->remove(*xEntry); bEntry = m_xTreeListBox->get_cursor(xEntry.get()); if (bEntry) - m_xEdit->set_text(reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(*xEntry).toInt64())->maName); + m_xEdit->set_text(weld::fromId<WatchItem*>(m_xTreeListBox->get_id(*xEntry))->maName); else m_xEdit->set_text(OUString()); if ( !m_xTreeListBox->n_children() ) @@ -1772,7 +1878,7 @@ IMPL_LINK_NOARG(WatchWindow, TreeListHdl, weld::TreeView&, void) bool bCurEntry = m_xTreeListBox->get_cursor(xCurEntry.get()); if (!bCurEntry) return; - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(*xCurEntry).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(*xCurEntry)); if (!pItem) return; m_xEdit->set_text(pItem->maName); @@ -1941,8 +2047,13 @@ ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) : aBrkWindow(VclPtr<BreakPointWindow>::Create(this, pParent)), aLineNumberWindow(VclPtr<LineNumberWindow>::Create(this, pParent)), aEdtWindow(VclPtr<EditorWindow>::Create(this, pParent)), - aEWVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL | WB_DRAG) ) + aEWVScrollBar(VclPtr<ScrollAdaptor>::Create(this, false)), + aEWHScrollBar(VclPtr<ScrollAdaptor>::Create(this, true)) { + // tdf#153853 The line numbering and breakpoint windows should appear on + // the left, even on RTL locales + EnableRTL(false); + aEdtWindow->Show(); aBrkWindow->Show(); @@ -1950,6 +2061,11 @@ ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) : aEWVScrollBar->SetPageSize(nScrollPage); aEWVScrollBar->SetScrollHdl( LINK( this, ComplexEditorWindow, ScrollHdl ) ); aEWVScrollBar->Show(); + + aEWHScrollBar->SetLineSize(nScrollLine); + aEWHScrollBar->SetPageSize(nScrollPage); + aEWHScrollBar->SetScrollHdl( LINK( this, ComplexEditorWindow, ScrollHdl ) ); + aEWHScrollBar->Show(); } ComplexEditorWindow::~ComplexEditorWindow() @@ -1963,6 +2079,7 @@ void ComplexEditorWindow::dispose() aLineNumberWindow.disposeAndClear(); aEdtWindow.disposeAndClear(); aEWVScrollBar.disposeAndClear(); + aEWHScrollBar.disposeAndClear(); vcl::Window::dispose(); } @@ -1974,39 +2091,42 @@ void ComplexEditorWindow::Resize() aSz.AdjustHeight( -(2*DWBORDER) ); tools::Long nBrkWidth = 20; tools::Long nSBWidth = aEWVScrollBar->GetSizePixel().Width(); + tools::Long nSBHeight = aEWHScrollBar->GetSizePixel().Height(); - Size aBrkSz(nBrkWidth, aSz.Height()); - - Size aLnSz(aLineNumberWindow->GetWidth(), aSz.Height()); + Size aBrkSz(nBrkWidth, aSz.Height() - nSBHeight); if (aLineNumberWindow->IsVisible()) { - aBrkWindow->SetPosSizePixel( Point( DWBORDER, DWBORDER ), aBrkSz ); - aLineNumberWindow->SetPosSizePixel(Point(DWBORDER + aBrkSz.Width() - 1, DWBORDER), aLnSz); - Size aEWSz(aSz.Width() - nBrkWidth - aLineNumberWindow->GetWidth() - nSBWidth + 2, aSz.Height()); - aEdtWindow->SetPosSizePixel( Point( DWBORDER + aBrkSz.Width() + aLnSz.Width() - 1, DWBORDER ), aEWSz ); + Size aLnSz(aLineNumberWindow->GetWidth(), aSz.Height() - nSBHeight); + Size aEWSz(aSz.Width() - nBrkWidth - aLineNumberWindow->GetWidth() - nSBWidth, aSz.Height() - nSBHeight); + aBrkWindow->SetPosSizePixel(Point(DWBORDER, DWBORDER), aBrkSz); + aLineNumberWindow->SetPosSizePixel(Point(DWBORDER + nBrkWidth, DWBORDER), aLnSz); + aEdtWindow->SetPosSizePixel(Point(DWBORDER + nBrkWidth + aLnSz.Width(), DWBORDER), aEWSz); } else { + Size aEWSz(aSz.Width() - nBrkWidth - nSBWidth, aSz.Height() - nSBHeight); aBrkWindow->SetPosSizePixel( Point( DWBORDER, DWBORDER ), aBrkSz ); - Size aEWSz(aSz.Width() - nBrkWidth - nSBWidth + 2, aSz.Height()); - aEdtWindow->SetPosSizePixel(Point(DWBORDER + aBrkSz.Width() - 1, DWBORDER), aEWSz); + aEdtWindow->SetPosSizePixel(Point(DWBORDER + nBrkWidth, DWBORDER), aEWSz); } - aEWVScrollBar->SetPosSizePixel( Point( aOutSz.Width() - DWBORDER - nSBWidth, DWBORDER ), Size( nSBWidth, aSz.Height() ) ); + aEWVScrollBar->SetPosSizePixel(Point(aOutSz.Width() - DWBORDER - nSBWidth, DWBORDER), + Size(nSBWidth, aSz.Height() - nSBHeight)); + aEWHScrollBar->SetPosSizePixel(Point(DWBORDER, aOutSz.Height() - DWBORDER - nSBHeight), + Size(aSz.Width() - nSBWidth, nSBHeight)); } -IMPL_LINK(ComplexEditorWindow, ScrollHdl, ScrollBar *, pCurScrollBar, void ) +IMPL_LINK_NOARG(ComplexEditorWindow, ScrollHdl, weld::Scrollbar&, void) { if (aEdtWindow->GetEditView()) { - DBG_ASSERT( pCurScrollBar == aEWVScrollBar.get(), "Who is scrolling?" ); - tools::Long nDiff = aEdtWindow->GetEditView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos(); - aEdtWindow->GetEditView()->Scroll( 0, nDiff ); - aBrkWindow->DoScroll( nDiff ); - aLineNumberWindow->DoScroll( nDiff ); + tools::Long nXDiff = aEdtWindow->GetEditView()->GetStartDocPos().X() - aEWHScrollBar->GetThumbPos(); + tools::Long nYDiff = aEdtWindow->GetEditView()->GetStartDocPos().Y() - aEWVScrollBar->GetThumbPos(); + aEdtWindow->GetEditView()->Scroll(nXDiff, nYDiff); + aBrkWindow->DoScroll( nYDiff ); + aLineNumberWindow->DoScroll( nYDiff ); aEdtWindow->GetEditView()->ShowCursor(false); - pCurScrollBar->SetThumbPos( aEdtWindow->GetEditView()->GetStartDocPos().Y() ); + aEWVScrollBar->SetThumbPos( aEdtWindow->GetEditView()->GetStartDocPos().Y() ); } } @@ -2032,10 +2152,10 @@ void ComplexEditorWindow::SetLineNumberDisplay(bool b) Resize(); } -uno::Reference< awt::XWindowPeer > +uno::Reference< awt::XVclWindowPeer > EditorWindow::GetComponentInterface(bool bCreate) { - uno::Reference< awt::XWindowPeer > xPeer( + uno::Reference< awt::XVclWindowPeer > xPeer( Window::GetComponentInterface(false)); if (!xPeer.is() && bCreate) { @@ -2069,7 +2189,7 @@ IMPL_LINK(WatchWindow, RequestingChildrenHdl, const weld::TreeIter&, rParent, bo if (m_xTreeListBox->iter_has_child(rParent)) return true; - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(rParent).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(rParent)); std::unique_ptr<weld::TreeIter> xRet = m_xTreeListBox->make_iterator(); SbxDimArray* pArray = pItem->mpArray.get(); @@ -2097,7 +2217,7 @@ IMPL_LINK(WatchWindow, RequestingChildrenHdl, const weld::TreeIter&, rParent, bo OUString const& rName = pItem->maMemberList.back(); WatchItem* pWatchItem = new WatchItem(rName); - OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pWatchItem))); + OUString sId(weld::toId(pWatchItem)); m_xTreeListBox->insert(&rParent, -1, &rName, &sId, nullptr, nullptr, false, xRet.get()); m_xTreeListBox->set_text(*xRet, "", 1); @@ -2148,7 +2268,7 @@ IMPL_LINK(WatchWindow, RequestingChildrenHdl, const weld::TreeIter&, rParent, bo aDisplayName += aIndexStr; pChildItem->maDisplayName = aDisplayName; - OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pChildItem))); + OUString sId(weld::toId(pChildItem)); m_xTreeListBox->insert(&rParent, -1, &aDisplayName, &sId, nullptr, nullptr, false, xRet.get()); @@ -2178,12 +2298,12 @@ SbxBase* WatchWindow::ImplGetSBXForEntry(const weld::TreeIter& rEntry, bool& rbA SbxBase* pSBX = nullptr; rbArrayElement = false; - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(rEntry).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(rEntry)); OUString aVName( pItem->maName ); std::unique_ptr<weld::TreeIter> xParentEntry = m_xTreeListBox->make_iterator(&rEntry); bool bParentEntry = m_xTreeListBox->iter_parent(*xParentEntry); - WatchItem* pParentItem = bParentEntry ? reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(*xParentEntry).toInt64()) : nullptr; + WatchItem* pParentItem = bParentEntry ? weld::fromId<WatchItem*>(m_xTreeListBox->get_id(*xParentEntry)) : nullptr; if( pParentItem ) { SbxObject* pObj = pParentItem->mpObject.get(); @@ -2216,7 +2336,7 @@ SbxBase* WatchWindow::ImplGetSBXForEntry(const weld::TreeIter& rEntry, bool& rbA IMPL_LINK(WatchWindow, EditingEntryHdl, const weld::TreeIter&, rIter, bool) { - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(rIter).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(rIter)); bool bEdit = false; if (StarBASIC::IsRunning() && StarBASIC::GetActiveMethod() && !SbxBase::IsError()) @@ -2293,7 +2413,7 @@ void implCollapseModifiedObjectEntry(const weld::TreeIter& rParent, weld::TreeVi { implCollapseModifiedObjectEntry(*xDeleteEntry, rTree); - WatchItem* pItem = reinterpret_cast<WatchItem*>(rTree.get_id(*xDeleteEntry).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(rTree.get_id(*xDeleteEntry)); delete pItem; rTree.remove(*xDeleteEntry); rTree.copy_iterator(rParent, *xDeleteEntry); @@ -2352,7 +2472,7 @@ void WatchWindow::UpdateWatches(bool bBasicStopped) setBasicWatchMode( true ); m_xTreeListBox->all_foreach([this, pCurMethod, bBasicStopped](weld::TreeIter& rEntry){ - WatchItem* pItem = reinterpret_cast<WatchItem*>(m_xTreeListBox->get_id(rEntry).toInt64()); + WatchItem* pItem = weld::fromId<WatchItem*>(m_xTreeListBox->get_id(rEntry)); DBG_ASSERT( !pItem->maName.isEmpty(), "Var? - Must not be empty!" ); OUString aWatchStr; OUString aTypeStr; @@ -2742,6 +2862,7 @@ CodeCompleteWindow::CodeCompleteWindow(EditorWindow* pPar) m_xListBox->connect_changed(LINK(this, CodeCompleteWindow, ImplSelectHdl)); m_xListBox->connect_key_press(LINK(this, CodeCompleteWindow, KeyInputHdl)); m_xListBox->make_sorted(); + m_xListBox->set_direction(false); m_xListBox->set_size_request(150, 150); // default, this will adopt the line length SetSizePixel(m_xContainer->get_preferred_size()); |