summaryrefslogtreecommitdiff
path: root/sw/source/uibase/docvw/srcedtw.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/uibase/docvw/srcedtw.cxx')
-rw-r--r--sw/source/uibase/docvw/srcedtw.cxx167
1 files changed, 75 insertions, 92 deletions
diff --git a/sw/source/uibase/docvw/srcedtw.cxx b/sw/source/uibase/docvw/srcedtw.cxx
index 042dcc727eaa..b4196d97f1bf 100644
--- a/sw/source/uibase/docvw/srcedtw.cxx
+++ b/sw/source/uibase/docvw/srcedtw.cxx
@@ -33,7 +33,6 @@
#include <vcl/event.hxx>
#include <vcl/svapp.hxx>
#include <vcl/textview.hxx>
-#include <vcl/scrbar.hxx>
#include <vcl/ptrstyle.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
@@ -44,6 +43,7 @@
#include <editeng/flstitem.hxx>
#include <vcl/metric.hxx>
#include <svtools/ctrltool.hxx>
+#include <svtools/scrolladaptor.hxx>
#include <tools/time.hxx>
#include <swmodule.hxx>
#include <docsh.hxx>
@@ -67,7 +67,7 @@ struct TextPortion
typedef std::vector<TextPortion> TextPortions;
-static void lcl_Highlight(const OUString& rSource, TextPortions& aPortionList)
+static void lcl_Highlight(std::u16string_view aSource, TextPortions& aPortionList)
{
const sal_Unicode cOpenBracket = '<';
const sal_Unicode cCloseBracket= '>';
@@ -79,15 +79,15 @@ static void lcl_Highlight(const OUString& rSource, TextPortions& aPortionList)
const sal_Unicode cLF = 0x0a;
const sal_Unicode cCR = 0x0d;
- const sal_uInt16 nStrLen = rSource.getLength();
- sal_uInt16 nInsert = 0; // number of inserted portions
- sal_uInt16 nActPos = 0; // position, where '<' was found
- sal_uInt16 nPortStart = USHRT_MAX; // for the TextPortion
- sal_uInt16 nPortEnd = 0;
+ const sal_Int32 nStrLen = aSource.size();
+ sal_Int32 nInsert = 0; // number of inserted portions
+ sal_Int32 nActPos = 0; // position, where '<' was found
+ sal_Int32 nPortStart = SAL_MAX_INT32; // for the TextPortion
+ sal_Int32 nPortEnd = 0;
TextPortion aText;
while(nActPos < nStrLen)
{
- if((nActPos < nStrLen - 2) && (rSource[nActPos] == cOpenBracket))
+ if((nActPos < nStrLen - 2) && (aSource[nActPos] == cOpenBracket))
{
svtools::ColorConfigEntry eFoundType = svtools::HTMLUNKNOWN;
// insert 'empty' portion
@@ -102,13 +102,13 @@ static void lcl_Highlight(const OUString& rSource, TextPortions& aPortionList)
aPortionList.push_back( aText );
nInsert++;
}
- sal_Unicode cFollowFirst = rSource[nActPos + 1];
- sal_Unicode cFollowNext = rSource[nActPos + 2];
+ sal_Unicode cFollowFirst = aSource[nActPos + 1];
+ sal_Unicode cFollowNext = aSource[nActPos + 2];
if(cExclamation == cFollowFirst)
{
// "<!" SGML or comment
if(cMinus == cFollowNext &&
- nActPos < nStrLen - 3 && cMinus == rSource[nActPos + 3])
+ nActPos < nStrLen - 3 && cMinus == aSource[nActPos + 3])
{
eFoundType = svtools::HTMLCOMMENT;
}
@@ -129,7 +129,7 @@ static void lcl_Highlight(const OUString& rSource, TextPortions& aPortionList)
sal_uInt16 nSrchPos = nActPos;
while(++nSrchPos < nStrLen - 1)
{
- sal_Unicode cNext = rSource[nSrchPos];
+ sal_Unicode cNext = aSource[nSrchPos];
if( cNext == cSpace ||
cNext == cTab ||
cNext == cLF ||
@@ -143,33 +143,25 @@ static void lcl_Highlight(const OUString& rSource, TextPortions& aPortionList)
if(nSrchPos > nActPos + 1)
{
// some string was found
- OUString sToken = rSource.copy(nActPos + 1, nSrchPos - nActPos - 1 );
+ OUString sToken( aSource.substr(nActPos + 1, nSrchPos - nActPos - 1 ) );
sToken = sToken.toAsciiUpperCase();
HtmlTokenId nToken = ::GetHTMLToken(sToken);
if(nToken != HtmlTokenId::NONE)
{
- // Token was found
eFoundType = svtools::HTMLKEYWORD;
nPortEnd = nSrchPos;
nPortStart = nActPos;
}
else
- {
- // what was that?
- SAL_WARN(
- "sw.level2",
- "Token " << sToken
- << " not recognised!");
- }
-
+ SAL_WARN("sw", "HTML token " << sToken << " not recognised!");
}
}
// now we still have to look for '>'
if(svtools::HTMLUNKNOWN != eFoundType)
{
bool bFound = false;
- for(sal_uInt16 i = nPortEnd; i < nStrLen; i++)
- if(cCloseBracket == rSource[i])
+ for(sal_Int32 i = nPortEnd; i < nStrLen; i++)
+ if(cCloseBracket == aSource[i])
{
bFound = true;
nPortEnd = i;
@@ -210,25 +202,25 @@ class SwSrcEditWindow::ChangesListener:
public cppu::WeakImplHelper< css::beans::XPropertiesChangeListener >
{
public:
- explicit ChangesListener(SwSrcEditWindow & editor): editor_(editor) {}
+ explicit ChangesListener(SwSrcEditWindow & editor): m_Editor(editor) {}
private:
virtual ~ChangesListener() override {}
virtual void SAL_CALL disposing(css::lang::EventObject const &) override
{
- osl::MutexGuard g(editor_.mutex_);
- editor_.m_xNotifier.clear();
+ std::unique_lock g(m_Editor.mutex_);
+ m_Editor.m_xNotifier.clear();
}
virtual void SAL_CALL propertiesChange(
css::uno::Sequence< css::beans::PropertyChangeEvent > const &) override
{
SolarMutexGuard g;
- editor_.SetFont();
+ m_Editor.SetFont();
}
- SwSrcEditWindow & editor_;
+ SwSrcEditWindow & m_Editor;
};
SwSrcEditWindow::SwSrcEditWindow( vcl::Window* pParent, SwSrcView* pParentView ) :
@@ -257,13 +249,10 @@ SwSrcEditWindow::SwSrcEditWindow( vcl::Window* pParent, SwSrcView* pParentView )
officecfg::Office::Common::Font::SourceViewFont::get(),
css::uno::UNO_QUERY_THROW);
{
- osl::MutexGuard g(mutex_);
+ std::unique_lock g(mutex_);
m_xNotifier = n;
}
- css::uno::Sequence< OUString > s(2);
- s[0] = "FontHeight";
- s[1] = "FontName";
- n->addPropertiesChangeListener(s, m_xListener);
+ n->addPropertiesChangeListener({ "FontHeight", "FontName" }, m_xListener);
}
SwSrcEditWindow::~SwSrcEditWindow()
@@ -275,7 +264,7 @@ void SwSrcEditWindow::dispose()
{
css::uno::Reference< css::beans::XMultiPropertySet > n;
{
- osl::MutexGuard g(mutex_);
+ std::unique_lock g(mutex_);
n = m_xNotifier;
}
if (n.is()) {
@@ -382,9 +371,9 @@ void TextViewOutWin::DataChanged( const DataChangedEvent& rDCEvt )
{
const Color &rCol = GetSettings().GetStyleSettings().GetWindowColor();
SetBackground( rCol );
- vcl::Font aFont( pTextView->GetTextEngine()->GetFont() );
+ vcl::Font aFont( m_pTextView->GetTextEngine()->GetFont() );
aFont.SetFillColor( rCol );
- pTextView->GetTextEngine()->SetFont( aFont );
+ m_pTextView->GetTextEngine()->SetFont( aFont );
}
break;
default: break;
@@ -393,31 +382,28 @@ void TextViewOutWin::DataChanged( const DataChangedEvent& rDCEvt )
void TextViewOutWin::MouseMove( const MouseEvent &rEvt )
{
- if ( pTextView )
- pTextView->MouseMove( rEvt );
+ if ( m_pTextView )
+ m_pTextView->MouseMove( rEvt );
}
void TextViewOutWin::MouseButtonUp( const MouseEvent &rEvt )
{
- if ( pTextView )
+ if ( m_pTextView )
{
- pTextView->MouseButtonUp( rEvt );
- SfxViewFrame *pFrame = static_cast<SwSrcEditWindow*>(GetParent())->GetSrcView()->GetViewFrame();
- if ( pFrame )
- {
- SfxBindings& rBindings = pFrame->GetBindings();
- rBindings.Invalidate( SID_TABLE_CELL );
- rBindings.Invalidate( SID_CUT );
- rBindings.Invalidate( SID_COPY );
- }
+ m_pTextView->MouseButtonUp( rEvt );
+ SfxViewFrame& rFrame = static_cast<SwSrcEditWindow*>(GetParent())->GetSrcView()->GetViewFrame();
+ SfxBindings& rBindings = rFrame.GetBindings();
+ rBindings.Invalidate( SID_TABLE_CELL );
+ rBindings.Invalidate( SID_CUT );
+ rBindings.Invalidate( SID_COPY );
}
}
void TextViewOutWin::MouseButtonDown( const MouseEvent &rEvt )
{
GrabFocus();
- if ( pTextView )
- pTextView->MouseButtonDown( rEvt );
+ if ( m_pTextView )
+ m_pTextView->MouseButtonDown( rEvt );
}
void TextViewOutWin::Command( const CommandEvent& rCEvt )
@@ -440,8 +426,8 @@ void TextViewOutWin::Command( const CommandEvent& rCEvt )
break;
default:
- if ( pTextView )
- pTextView->Command( rCEvt );
+ if ( m_pTextView )
+ m_pTextView->Command( rCEvt );
else
Window::Command(rCEvt);
}
@@ -453,9 +439,9 @@ void TextViewOutWin::KeyInput( const KeyEvent& rKEvt )
SwSrcEditWindow* pSrcEditWin = static_cast<SwSrcEditWindow*>(GetParent());
bool bChange = !pSrcEditWin->IsReadonly() || !TextEngine::DoesKeyChangeText( rKEvt );
if(bChange)
- bDone = pTextView->KeyInput( rKEvt );
+ bDone = m_pTextView->KeyInput( rKEvt );
- SfxBindings& rBindings = static_cast<SwSrcEditWindow*>(GetParent())->GetSrcView()->GetViewFrame()->GetBindings();
+ SfxBindings& rBindings = static_cast<SwSrcEditWindow*>(GetParent())->GetSrcView()->GetViewFrame().GetBindings();
if ( !bDone )
{
if ( !SfxViewShell::Current()->KeyInput( rKEvt ) )
@@ -487,7 +473,7 @@ void TextViewOutWin::KeyInput( const KeyEvent& rKEvt )
void TextViewOutWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
- pTextView->Paint(rRenderContext, rRect);
+ m_pTextView->Paint(rRenderContext, rRect);
}
void SwSrcEditWindow::CreateTextEngine()
@@ -501,15 +487,14 @@ void SwSrcEditWindow::CreateTextEngine()
m_pOutWin->Show();
// create Scrollbars
- m_pHScrollbar = VclPtr<ScrollBar>::Create(this, WB_3DLOOK |WB_HSCROLL|WB_DRAG);
+ m_pHScrollbar = VclPtr<ScrollAdaptor>::Create(this, true);
m_pHScrollbar->EnableRTL( false );
- m_pHScrollbar->SetScrollHdl(LINK(this, SwSrcEditWindow, ScrollHdl));
+ m_pHScrollbar->SetScrollHdl(LINK(this, SwSrcEditWindow, HorzScrollHdl));
m_pHScrollbar->Show();
- m_pVScrollbar = VclPtr<ScrollBar>::Create(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
+ m_pVScrollbar = VclPtr<ScrollAdaptor>::Create(this, false);
m_pVScrollbar->EnableRTL( false );
- m_pVScrollbar->SetScrollHdl(LINK(this, SwSrcEditWindow, ScrollHdl));
- m_pHScrollbar->EnableDrag();
+ m_pVScrollbar->SetScrollHdl(LINK(this, SwSrcEditWindow, VertScrollHdl));
m_pVScrollbar->Show();
m_pTextEngine.reset(new ExtTextEngine);
@@ -523,7 +508,7 @@ void SwSrcEditWindow::CreateTextEngine()
vcl::Font aFont;
aFont.SetTransparent( false );
aFont.SetFillColor( rCol );
- SetPointFont(*this, aFont);
+ SetPointFont(*GetOutDev(), aFont);
aFont = GetFont();
aFont.SetFillColor( rCol );
m_pOutWin->SetFont( aFont );
@@ -538,7 +523,7 @@ void SwSrcEditWindow::CreateTextEngine()
InitScrollBars();
StartListening( *m_pTextEngine );
- SfxBindings& rBind = GetSrcView()->GetViewFrame()->GetBindings();
+ SfxBindings& rBind = GetSrcView()->GetViewFrame().GetBindings();
rBind.Invalidate( SID_TABLE_CELL );
}
@@ -566,23 +551,22 @@ void SwSrcEditWindow::InitScrollBars()
}
-IMPL_LINK(SwSrcEditWindow, ScrollHdl, ScrollBar*, pScroll, void)
+IMPL_LINK_NOARG(SwSrcEditWindow, HorzScrollHdl, weld::Scrollbar&, void)
{
- if(pScroll == m_pVScrollbar)
- {
- tools::Long nDiff = m_pTextView->GetStartDocPos().Y() - pScroll->GetThumbPos();
- GetTextView()->Scroll( 0, nDiff );
- m_pTextView->ShowCursor( false );
- pScroll->SetThumbPos( m_pTextView->GetStartDocPos().Y() );
- }
- else
- {
- tools::Long nDiff = m_pTextView->GetStartDocPos().X() - pScroll->GetThumbPos();
- GetTextView()->Scroll( nDiff, 0 );
- m_pTextView->ShowCursor( false );
- pScroll->SetThumbPos( m_pTextView->GetStartDocPos().X() );
- }
- GetSrcView()->GetViewFrame()->GetBindings().Invalidate( SID_TABLE_CELL );
+ tools::Long nDiff = m_pTextView->GetStartDocPos().X() - m_pHScrollbar->GetThumbPos();
+ GetTextView()->Scroll( nDiff, 0 );
+ m_pTextView->ShowCursor( false );
+ m_pHScrollbar->SetThumbPos( m_pTextView->GetStartDocPos().X() );
+ GetSrcView()->GetViewFrame().GetBindings().Invalidate( SID_TABLE_CELL );
+}
+
+IMPL_LINK_NOARG(SwSrcEditWindow, VertScrollHdl, weld::Scrollbar&, void)
+{
+ tools::Long nDiff = m_pTextView->GetStartDocPos().Y() - m_pVScrollbar->GetThumbPos();
+ GetTextView()->Scroll( 0, nDiff );
+ m_pTextView->ShowCursor( false );
+ m_pVScrollbar->SetThumbPos( m_pTextView->GetStartDocPos().Y() );
+ GetSrcView()->GetViewFrame().GetBindings().Invalidate( SID_TABLE_CELL );
}
IMPL_LINK( SwSrcEditWindow, SyntaxTimerHdl, Timer*, pIdle, void )
@@ -594,7 +578,7 @@ IMPL_LINK( SwSrcEditWindow, SyntaxTimerHdl, Timer*, pIdle, void )
sal_uInt16 nCount = 0;
// at first the region around the cursor is processed
TextSelection aSel = m_pTextView->GetSelection();
- sal_uInt16 nCur = static_cast<sal_uInt16>(aSel.GetStart().GetPara());
+ sal_uInt16 nCur = o3tl::narrowing<sal_uInt16>(aSel.GetStart().GetPara());
if(nCur > 40)
nCur -= 40;
else
@@ -665,10 +649,10 @@ void SwSrcEditWindow::DoSyntaxHighlight( sal_uInt16 nPara )
}
-void SwSrcEditWindow::ImpDoHighlight( const OUString& rSource, sal_uInt16 nLineOff )
+void SwSrcEditWindow::ImpDoHighlight( std::u16string_view aSource, sal_uInt16 nLineOff )
{
TextPortions aPortionList;
- lcl_Highlight(rSource, aPortionList);
+ lcl_Highlight(aSource, aPortionList);
size_t nCount = aPortionList.size();
if ( !nCount )
@@ -702,8 +686,8 @@ void SwSrcEditWindow::ImpDoHighlight( const OUString& rSource, sal_uInt16 nLineO
r.nStart = nLastEnd;
}
nLastEnd = r.nEnd+1;
- if ( ( i == (nCount-1) ) && ( r.nEnd < rSource.getLength() ) )
- r.nEnd = rSource.getLength();
+ if ( ( i == (nCount-1) ) && ( r.nEnd < aSource.size() ) )
+ r.nEnd = aSource.size();
}
}
@@ -745,7 +729,7 @@ void SwSrcEditWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
case SfxHintId::TextParaContentChanged:
if ( !m_bHighlighting )
{
- m_aSyntaxLineTable.insert( static_cast<sal_uInt16>(pTextHint->GetValue()) );
+ m_aSyntaxLineTable.insert( o3tl::narrowing<sal_uInt16>(pTextHint->GetValue()) );
m_aSyntaxIdle.Start();
}
break;
@@ -753,10 +737,10 @@ void SwSrcEditWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
}
}
-void SwSrcEditWindow::Invalidate(InvalidateFlags )
+void SwSrcEditWindow::ImplInvalidate(const vcl::Region* pRegion, InvalidateFlags nFlags)
{
m_pOutWin->Invalidate();
- Window::Invalidate();
+ Window::ImplInvalidate(pRegion, nFlags);
}
void SwSrcEditWindow::Command( const CommandEvent& rCEvt )
@@ -963,20 +947,19 @@ void SwSrcEditWindow::SetFont()
if(lcl_GetLanguagesForEncoding(m_eSourceEncoding, aLanguages))
{
//TODO: check for multiple languages
- aFont = OutputDevice::GetDefaultFont(DefaultFontType::FIXED, aLanguages[0], GetDefaultFontFlags::NONE, this);
+ aFont = OutputDevice::GetDefaultFont(DefaultFontType::FIXED, aLanguages[0], GetDefaultFontFlags::NONE, GetOutDev());
}
else
aFont = OutputDevice::GetDefaultFont(DefaultFontType::SANS_UNICODE,
- Application::GetSettings().GetLanguageTag().getLanguageType(), GetDefaultFontFlags::NONE, this);
+ Application::GetSettings().GetLanguageTag().getLanguageType(), GetDefaultFontFlags::NONE, GetOutDev());
sFontName = aFont.GetFamilyName();
}
const SvxFontListItem* pFontListItem =
static_cast<const SvxFontListItem* >(m_pSrcView->GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ));
- const FontList* pList = pFontListItem->GetFontList();
- FontMetric aFontMetric = pList->Get(sFontName,WEIGHT_NORMAL, ITALIC_NONE);
+ const FontList* pList = pFontListItem->GetFontList();
+ vcl::Font aFont(pList->Get(sFontName, WEIGHT_NORMAL, ITALIC_NONE));
const vcl::Font& rFont = GetTextEngine()->GetFont();
- vcl::Font aFont(aFontMetric);
Size aSize(rFont.GetFontSize());
//font height is stored in point and set in twip
aSize.setHeight(