25#include <com/sun/star/beans/XMultiPropertySet.hpp>
26#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
27#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
29#include <officecfg/Office/Common.hxx>
30#include <rtl/ustring.hxx>
59 sal_uInt16 nStart, nEnd;
65#define MAX_SYNTAX_HIGHLIGHT 20
66#define MAX_HIGHLIGHTTIME 200
82 const sal_Int32 nStrLen = aSource.size();
83 sal_Int32 nInsert = 0;
84 sal_Int32 nActPos = 0;
86 sal_Int32 nPortEnd = 0;
88 while(nActPos < nStrLen)
90 if((nActPos < nStrLen - 2) && (aSource[nActPos] == cOpenBracket))
94 if(nPortEnd < nActPos - 1 )
97 aText.nStart = nPortEnd;
100 aText.nEnd = nActPos - 1;
102 aPortionList.push_back( aText );
107 if(cExclamation == cFollowFirst)
110 if(cMinus == cFollowNext &&
111 nActPos < nStrLen - 3 && cMinus == aSource[nActPos + 3])
117 nPortStart = nActPos;
118 nPortEnd = nActPos + 1;
120 else if(cSlash == cFollowFirst)
123 nPortStart = nActPos;
129 sal_uInt16 nSrchPos = nActPos;
130 while(++nSrchPos < nStrLen - 1)
133 if( cNext == cSpace ||
138 else if(cNext == cCloseBracket)
143 if(nSrchPos > nActPos + 1)
146 OUString sToken( aSource.substr(nActPos + 1, nSrchPos - nActPos - 1 ) );
147 sToken = sToken.toAsciiUpperCase();
149 if(
nToken != HtmlTokenId::NONE)
153 nPortStart = nActPos;
156 SAL_WARN(
"sw",
"HTML token " << sToken <<
" not recognised!");
163 for(sal_Int32
i = nPortEnd;
i < nStrLen;
i++)
164 if(cCloseBracket == aSource[
i])
174 nPortEnd = nStrLen - 1;
180 aTextPortion.nStart = nPortStart + 1;
181 aTextPortion.nEnd = nPortEnd;
182 aTextPortion.eType = eFoundType;
183 aPortionList.push_back( aTextPortion );
191 if(nInsert && nPortEnd < nActPos - 1)
193 aText.nStart = nPortEnd + 1;
194 aText.nEnd = nActPos - 1;
196 aPortionList.push_back( aText );
202 public cppu::WeakImplHelper< css::beans::XPropertiesChangeListener >
210 virtual void SAL_CALL
disposing(css::lang::EventObject
const &)
override
217 css::uno::Sequence< css::beans::PropertyChangeEvent >
const &)
override
230 m_pHScrollbar(nullptr),
231 m_pVScrollbar(nullptr),
233 m_pSrcView(pParentView),
236 m_nStartLine(USHRT_MAX),
237 m_eSourceEncoding(osl_getThreadTextEncoding()),
239 m_bHighlighting(false),
240 m_aSyntaxIdle(
"sw uibase SwSrcEditWindow Syntax")
248 css::uno::Reference< css::beans::XMultiPropertySet >
n(
250 css::uno::UNO_QUERY_THROW);
252 std::unique_lock g(
mutex_);
255 n->addPropertiesChangeListener({
"FontHeight",
"FontName" },
m_xListener);
265 css::uno::Reference< css::beans::XMultiPropertySet >
n;
267 std::unique_lock g(
mutex_);
293 Window::DataChanged( rDCEvt );
297 case DataChangedEventType::SETTINGS:
302 if( rDCEvt.
GetFlags() & AllSettingsFlags::STYLE )
319 if ( nMaxVisAreaStart < 0 )
320 nMaxVisAreaStart = 0;
321 if (
m_pTextView->GetStartDocPos().Y() > nMaxVisAreaStart )
324 aStartDocPos.
setY( nMaxVisAreaStart );
329 Size aScrollSz(aOutSz.
Width() - nScrollStd, nScrollStd );
336 aScrollPos =
Point(aOutSz.
Width() - nScrollStd, 0);
347 if(m_nStartLine < m_pTextEngine->GetParagraphCount())
364 Window::DataChanged( rDCEvt );
368 case DataChangedEventType::SETTINGS:
370 if( rDCEvt.
GetFlags() & AllSettingsFlags::STYLE )
413 case CommandEventId::ContextMenu:
416 case CommandEventId::Wheel:
417 case CommandEventId::StartAutoScroll:
418 case CommandEventId::AutoScroll:
421 if( !pWData || CommandWheelMode::ZOOM != pWData->
GetMode() )
432 Window::Command(rCEvt);
448 Window::KeyInput( rKEvt );
454 rBindings.
Update( SID_BASICIDE_STAT_POS );
486 m_pOutWin->SetPointer(PointerStyle::Text);
556 tools::Long nDiff = m_pTextView->GetStartDocPos().X() - m_pHScrollbar->GetThumbPos();
557 GetTextView()->Scroll( nDiff, 0 );
558 m_pTextView->ShowCursor(
false );
559 m_pHScrollbar->SetThumbPos( m_pTextView->GetStartDocPos().X() );
560 GetSrcView()->GetViewFrame().GetBindings().Invalidate( SID_TABLE_CELL );
565 tools::Long nDiff = m_pTextView->GetStartDocPos().Y() - m_pVScrollbar->GetThumbPos();
566 GetTextView()->Scroll( 0, nDiff );
567 m_pTextView->ShowCursor(
false );
568 m_pVScrollbar->SetThumbPos( m_pTextView->GetStartDocPos().Y() );
569 GetSrcView()->GetViewFrame().GetBindings().Invalidate( SID_TABLE_CELL );
575 SAL_WARN_IF(m_pTextView ==
nullptr,
"sw",
"No View yet, but syntax highlighting?!");
577 m_bHighlighting =
true;
581 sal_uInt16 nCur = o3tl::narrowing<sal_uInt16>(aSel.
GetStart().
GetPara());
586 if(!m_aSyntaxLineTable.empty())
587 for(sal_uInt16
i = 0;
i < 80 &&
nCount < 40;
i++, nCur++)
589 if(m_aSyntaxLineTable.find(nCur) != m_aSyntaxLineTable.end())
591 DoSyntaxHighlight( nCur );
592 m_aSyntaxLineTable.erase( nCur );
594 if(m_aSyntaxLineTable.empty())
606 sal_uInt16 nLine = *m_aSyntaxLineTable.begin();
607 DoSyntaxHighlight( nLine );
608 m_aSyntaxLineTable.erase(nLine);
616 if(!m_aSyntaxLineTable.empty() && !pIdle->IsActive())
621 m_nCurTextWidth = m_pTextEngine->CalcTextWidth() + 25;
622 if ( m_nCurTextWidth != nPrevTextWidth )
623 SetScrollBarRanges();
624 m_bHighlighting =
false;
657 size_t nCount = aPortionList.size();
662 if ( rLast.nStart > rLast.nEnd )
665 aPortionList.pop_back();
674 sal_uInt16 nLastEnd = 0;
679 if ( r.nStart > r.nEnd )
682 if ( r.nStart > nLastEnd )
689 if ( (
i == (
nCount-1) ) && ( r.nEnd < aSource.size() ) )
690 r.nEnd = aSource.size();
696 if ( r.nStart > r.nEnd )
703 Color aColor(
SW_MOD()->GetColorConfig().GetColorValue(r.eType).nColor);
714 switch (pTextHint->GetId())
716 case SfxHintId::TextViewScrolled:
721 case SfxHintId::TextHeightChanged:
728 case SfxHintId::TextParaInserted:
729 case SfxHintId::TextParaContentChanged:
743 Window::ImplInvalidate(pRegion, nFlags);
750 case CommandEventId::Wheel:
751 case CommandEventId::StartAutoScroll:
752 case CommandEventId::AutoScroll:
755 if( !pWData || CommandWheelMode::ZOOM != pWData->
GetMode() )
760 Window::Command(rCEvt);
780 case RTL_TEXTENCODING_UTF7 :
781 case RTL_TEXTENCODING_UTF8 :
785 case RTL_TEXTENCODING_ISO_8859_3:
786 case RTL_TEXTENCODING_ISO_8859_1 :
787 case RTL_TEXTENCODING_MS_1252 :
788 case RTL_TEXTENCODING_APPLE_ROMAN :
789 case RTL_TEXTENCODING_IBM_850 :
790 case RTL_TEXTENCODING_ISO_8859_14 :
791 case RTL_TEXTENCODING_ISO_8859_15 :
799 case RTL_TEXTENCODING_IBM_865 :
807 case RTL_TEXTENCODING_ISO_8859_10 :
808 case RTL_TEXTENCODING_ISO_8859_13 :
809 case RTL_TEXTENCODING_ISO_8859_2 :
810 case RTL_TEXTENCODING_IBM_852 :
811 case RTL_TEXTENCODING_MS_1250 :
812 case RTL_TEXTENCODING_APPLE_CENTEURO :
819 case RTL_TEXTENCODING_ISO_8859_4 :
820 case RTL_TEXTENCODING_IBM_775 :
821 case RTL_TEXTENCODING_MS_1257 :
828 case RTL_TEXTENCODING_APPLE_FARSI : aLanguages[0] =
LANGUAGE_FARSI;
break;
831 case RTL_TEXTENCODING_IBM_861 :
832 case RTL_TEXTENCODING_APPLE_ICELAND :
838 case RTL_TEXTENCODING_IBM_437 :
841 case RTL_TEXTENCODING_IBM_862 :
842 case RTL_TEXTENCODING_MS_1255 :
843 case RTL_TEXTENCODING_APPLE_HEBREW :
844 case RTL_TEXTENCODING_ISO_8859_8 :
848 case RTL_TEXTENCODING_IBM_857 :
849 case RTL_TEXTENCODING_MS_1254 :
850 case RTL_TEXTENCODING_APPLE_TURKISH:
851 case RTL_TEXTENCODING_ISO_8859_9 :
855 case RTL_TEXTENCODING_IBM_860 :
859 case RTL_TEXTENCODING_IBM_869 :
860 case RTL_TEXTENCODING_MS_1253 :
861 case RTL_TEXTENCODING_APPLE_GREEK :
862 case RTL_TEXTENCODING_ISO_8859_7 :
863 case RTL_TEXTENCODING_IBM_737 :
867 case RTL_TEXTENCODING_KOI8_R :
868 case RTL_TEXTENCODING_ISO_8859_5 :
869 case RTL_TEXTENCODING_IBM_855 :
870 case RTL_TEXTENCODING_MS_1251 :
871 case RTL_TEXTENCODING_IBM_866 :
872 case RTL_TEXTENCODING_APPLE_CYRILLIC :
876 case RTL_TEXTENCODING_APPLE_UKRAINIAN:
877 case RTL_TEXTENCODING_KOI8_U:
881 case RTL_TEXTENCODING_IBM_864 :
882 case RTL_TEXTENCODING_MS_1256 :
883 case RTL_TEXTENCODING_ISO_8859_6 :
884 case RTL_TEXTENCODING_APPLE_ARABIC :
888 case RTL_TEXTENCODING_APPLE_CHINTRAD :
889 case RTL_TEXTENCODING_MS_950 :
890 case RTL_TEXTENCODING_GBT_12345 :
891 case RTL_TEXTENCODING_BIG5 :
892 case RTL_TEXTENCODING_EUC_TW :
893 case RTL_TEXTENCODING_BIG5_HKSCS :
897 case RTL_TEXTENCODING_EUC_JP :
898 case RTL_TEXTENCODING_ISO_2022_JP :
899 case RTL_TEXTENCODING_JIS_X_0201 :
900 case RTL_TEXTENCODING_JIS_X_0208 :
901 case RTL_TEXTENCODING_JIS_X_0212 :
902 case RTL_TEXTENCODING_APPLE_JAPANESE :
903 case RTL_TEXTENCODING_MS_932 :
904 case RTL_TEXTENCODING_SHIFT_JIS :
908 case RTL_TEXTENCODING_GB_2312 :
909 case RTL_TEXTENCODING_MS_936 :
910 case RTL_TEXTENCODING_GBK :
911 case RTL_TEXTENCODING_GB_18030 :
912 case RTL_TEXTENCODING_APPLE_CHINSIMP :
913 case RTL_TEXTENCODING_EUC_CN :
914 case RTL_TEXTENCODING_ISO_2022_CN :
918 case RTL_TEXTENCODING_APPLE_KOREAN :
919 case RTL_TEXTENCODING_MS_949 :
920 case RTL_TEXTENCODING_EUC_KR :
921 case RTL_TEXTENCODING_ISO_2022_KR :
922 case RTL_TEXTENCODING_MS_1361 :
926 case RTL_TEXTENCODING_APPLE_THAI :
927 case RTL_TEXTENCODING_MS_874 :
928 case RTL_TEXTENCODING_TIS_620 :
939 value_or(OUString()));
940 if(sFontName.isEmpty())
const LanguageTag & GetUILanguageTag() const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
CommandEventId GetCommand() const
const CommandWheelData * GetWheelData() const
CommandWheelMode GetMode() const
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
FontMetric Get(const OUString &rName, const OUString &rStyleName) const
virtual void Start(bool bStartTimer=true) override
const vcl::KeyCode & GetKeyCode() const
LanguageType getLanguageType(bool bResolveSystem=true) const
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void setY(tools::Long nY)
void Update(sal_uInt16 nId)
void Invalidate(sal_uInt16 nId)
void ExecutePopup(const OUString &rResName, vcl::Window *pWin=nullptr, const Point *pPos=nullptr)
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SfxBindings & GetBindings()
SfxViewFrame & GetViewFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
virtual bool KeyInput(const KeyEvent &rKeyEvent)
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
sal_Int32 GetScrollBarSize() const
const Color & GetWindowColor() const
const FontList * GetFontList() const
virtual void SetModified(bool=true) override
virtual ~ChangesListener() override
ChangesListener(SwSrcEditWindow &editor)
SwSrcEditWindow & m_Editor
virtual void SAL_CALL propertiesChange(css::uno::Sequence< css::beans::PropertyChangeEvent > const &) override
virtual void SAL_CALL disposing(css::lang::EventObject const &) override
std::set< sal_uInt16 > m_aSyntaxLineTable
virtual void GetFocus() override
std::unique_ptr< ExtTextEngine > m_pTextEngine
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void ImplInvalidate(const vcl::Region *pRegion, InvalidateFlags nFlags) override
void HandleWheelCommand(const CommandEvent &rCEvt)
VclPtr< ScrollAdaptor > m_pVScrollbar
SwSrcEditWindow(vcl::Window *pParent, SwSrcView *pParentView)
void ImpDoHighlight(std::u16string_view aSource, sal_uInt16 nLineOff)
virtual void DataChanged(const DataChangedEvent &) override
tools::Long m_nCurTextWidth
rtl_TextEncoding m_eSourceEncoding
virtual ~SwSrcEditWindow() override
void SetScrollBarRanges()
css::uno::Reference< css::beans::XMultiPropertySet > m_xNotifier
virtual void Command(const CommandEvent &rCEvt) override
rtl::Reference< ChangesListener > m_xListener
virtual void dispose() override
VclPtr< ScrollAdaptor > m_pHScrollbar
void DoSyntaxHighlight(sal_uInt16 nPara)
friend class ChangesListener
TextEngine * GetTextEngine()
virtual void Resize() override
std::unique_ptr< TextView > m_pTextView
VclPtr< TextViewOutWin > m_pOutWin
void SetTextEncoding(rtl_TextEncoding eEncoding)
SwDocShell * GetDocShell()
static bool DoesKeyChangeText(const KeyEvent &rKeyEvent)
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rFont)
sal_Int32 GetValue() const
sal_uInt32 GetPara() const
const TextPaM & GetStart() const
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
virtual void DataChanged(const DataChangedEvent &) override
virtual void Command(const CommandEvent &rCEvt) override
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void MouseMove(const MouseEvent &rMEvt) override
virtual void KeyInput(const KeyEvent &rKeyEvt) override
void ShowCursor(bool bGotoCursor=true, bool bForceVisCursor=true)
void MouseButtonDown(const MouseEvent &rMouseEvent)
void Command(const CommandEvent &rCEvt)
void SetAutoScroll(bool bAutoScroll)
void MouseMove(const MouseEvent &rMouseEvent)
void MouseButtonUp(const MouseEvent &rMouseEvent)
bool KeyInput(const KeyEvent &rKeyEvent)
void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
TextEngine * GetTextEngine() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
static VclPtr< reference_type > Create(Arg &&... arg)
void SetFontSize(const Size &)
void SetTransparent(bool bTransparent)
void SetFillColor(const Color &)
const OUString & GetFamilyName() const
const Size & GetFontSize() const
sal_uInt16 GetGroup() const
sal_uInt16 GetCode() const
virtual void dispose() override
vcl::Window * GetParent() const
bool HandleScrollCommand(const CommandEvent &rCmd, Scrollable *pHScrl, Scrollable *pVScrl)
const AllSettings & GetSettings() const
::OutputDevice const * GetOutDev() const
const vcl::Font & GetFont() const
Size GetOutputSizePixel() const
void SetPointFont(vcl::RenderContext &rRenderContext, const vcl::Font &rFont)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetHelpId(const OUString &)
constexpr OUStringLiteral HID_SOURCE_EDITWIN
constexpr sal_uInt16 KEY_INSERT
constexpr sal_uInt16 KEYGROUP_CURSOR
#define LANGUAGE_LITHUANIAN
#define LANGUAGE_ROMANIAN
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_PORTUGUESE
#define LANGUAGE_HUNGARIAN
#define LANGUAGE_ICELANDIC
#define LANGUAGE_CHINESE_SIMPLIFIED
#define LANGUAGE_JAPANESE
#define LANGUAGE_FRENCH_CANADIAN
#define LANGUAGE_UKRAINIAN
#define LANGUAGE_ARABIC_SAUDI_ARABIA
#define LANGUAGE_NORWEGIAN
#define LANGUAGE_CROATIAN
#define LANGUAGE_ESTONIAN
#define LINK(Instance, Class, Member)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
Any GetTime(const OUString &val)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
static bool lcl_GetLanguagesForEncoding(rtl_TextEncoding eEnc, LanguageType aLanguages[])
static void lcl_Highlight(std::u16string_view aSource, TextPortions &aPortionList)
#define MAX_SYNTAX_HIGHLIGHT
IMPL_LINK_NOARG(SwSrcEditWindow, HorzScrollHdl, weld::Scrollbar &, void)
std::vector< TextPortion > TextPortions
#define MAX_HIGHLIGHTTIME
IMPL_LINK(SwSrcEditWindow, SyntaxTimerHdl, Timer *, pIdle, void)
WinBits const WB_CLIPCHILDREN