1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <i18nlangtag/languagetag.hxx>
22 #include <vcl/commandevent.hxx>
23 #include <vcl/builder.hxx>
24 #include <vcl/decoview.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/menu.hxx>
27 #include <vcl/specialchars.hxx>
28 #include <vcl/timer.hxx>
29 #include <vcl/vclevent.hxx>
30 #include <vcl/xtextedt.hxx>
31 #include <vcl/textview.hxx>
32 #include <vcl/ptrstyle.hxx>
34 #include <svl/undo.hxx>
35 #include <svl/lstner.hxx>
36 #include <vcl/uitest/uiobject.hxx>
38 #include <vcl/settings.hxx>
39 #include <vcl/toolkit/scrbar.hxx>
40 #include <vcl/toolkit/vclmedit.hxx>
41 #include <vcl/weld.hxx>
42 #include <osl/diagnose.h>
43 #include <tools/json_writer.hxx>
44 #include <strings.hrc>
47 class ImpVclMEdit
: public SfxListener
50 VclPtr
<VclMultiLineEdit
> pVclMultiLineEdit
;
52 VclPtr
<TextWindow
> mpTextWindow
;
53 VclPtr
<ScrollBar
> mpHScrollBar
;
54 VclPtr
<ScrollBar
> mpVScrollBar
;
55 VclPtr
<ScrollBarBox
> mpScrollBox
;
57 tools::Long mnTextWidth
;
58 mutable Selection maSelection
;
61 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
62 void ImpUpdateScrollBarVis( WinBits nWinStyle
);
63 void ImpInitScrollBars();
64 void ImpSetScrollBarRanges();
65 void ImpSetHScrollBarThumbPos();
66 DECL_LINK( ScrollHdl
, ScrollBar
*, void );
69 ImpVclMEdit( VclMultiLineEdit
* pVclMultiLineEdit
, WinBits nWinStyle
);
70 virtual ~ImpVclMEdit() override
;
72 void SetModified( bool bMod
);
74 void SetReadOnly( bool bRdOnly
);
75 bool IsReadOnly() const;
77 void SetMaxTextLen(sal_Int32 nLen
);
78 sal_Int32
GetMaxTextLen() const;
80 void SetMaxTextWidth(tools::Long nMaxWidth
);
82 void InsertText( const OUString
& rStr
);
83 OUString
GetSelected() const;
84 OUString
GetSelected( LineEnd aSeparator
) const;
86 void SetSelection( const Selection
& rSelection
);
87 const Selection
& GetSelection() const;
93 void SetText( const OUString
& rStr
);
94 OUString
GetText() const;
95 OUString
GetText( LineEnd aSeparator
) const;
96 OUString
GetTextLines( LineEnd aSeparator
) const;
101 bool HandleCommand( const CommandEvent
& rCEvt
);
103 void Enable( bool bEnable
);
105 Size
CalcMinimumSize() const;
106 Size
CalcBlockSize( sal_uInt16 nColumns
, sal_uInt16 nLines
) const;
107 void GetMaxVisColumnsAndLines( sal_uInt16
& rnCols
, sal_uInt16
& rnLines
) const;
109 void SetAlign( WinBits nWinStyle
);
111 void InitFromStyle( WinBits nWinStyle
);
113 TextWindow
* GetTextWindow() { return mpTextWindow
; }
114 ScrollBar
& GetHScrollBar() { return *mpHScrollBar
; }
115 ScrollBar
& GetVScrollBar() { return *mpVScrollBar
; }
118 ImpVclMEdit::ImpVclMEdit( VclMultiLineEdit
* pEdt
, WinBits nWinStyle
)
119 : pVclMultiLineEdit(pEdt
)
120 , mpTextWindow(VclPtr
<TextWindow
>::Create(pEdt
))
121 , mpHScrollBar(VclPtr
<ScrollBar
>::Create(pVclMultiLineEdit
, WB_HSCROLL
|WB_DRAG
))
122 , mpVScrollBar(VclPtr
<ScrollBar
>::Create(pVclMultiLineEdit
, WB_VSCROLL
|WB_DRAG
))
123 , mpScrollBox(VclPtr
<ScrollBarBox
>::Create(pVclMultiLineEdit
, WB_SIZEABLE
))
126 mpVScrollBar
->SetScrollHdl( LINK( this, ImpVclMEdit
, ScrollHdl
) );
127 mpHScrollBar
->SetScrollHdl( LINK( this, ImpVclMEdit
, ScrollHdl
) );
128 mpTextWindow
->Show();
129 InitFromStyle( nWinStyle
);
130 StartListening( *mpTextWindow
->GetTextEngine() );
133 void ImpVclMEdit::ImpUpdateScrollBarVis( WinBits nWinStyle
)
135 const bool bHaveVScroll
= mpVScrollBar
->IsVisible();
136 const bool bHaveHScroll
= mpHScrollBar
->IsVisible();
137 const bool bHaveScrollBox
= mpScrollBox
->IsVisible();
139 bool bNeedVScroll
= ( nWinStyle
& WB_VSCROLL
) == WB_VSCROLL
;
140 const bool bNeedHScroll
= ( nWinStyle
& WB_HSCROLL
) == WB_HSCROLL
;
142 const bool bAutoVScroll
= ( nWinStyle
& WB_AUTOVSCROLL
) == WB_AUTOVSCROLL
;
143 if ( !bNeedVScroll
&& bAutoVScroll
)
145 TextEngine
& rEngine( *mpTextWindow
->GetTextEngine() );
146 tools::Long
nOverallTextHeight(0);
147 for ( sal_uInt32 i
=0; i
<rEngine
.GetParagraphCount(); ++i
)
148 nOverallTextHeight
+= rEngine
.GetTextHeight( i
);
149 if ( nOverallTextHeight
> mpTextWindow
->GetOutputSizePixel().Height() )
153 const bool bNeedScrollBox
= bNeedVScroll
&& bNeedHScroll
;
155 bool bScrollbarsChanged
= false;
156 if ( bHaveVScroll
!= bNeedVScroll
)
158 mpVScrollBar
->Show(bNeedVScroll
);
159 bScrollbarsChanged
= true;
162 if ( bHaveHScroll
!= bNeedHScroll
)
164 mpHScrollBar
->Show(bNeedHScroll
);
165 bScrollbarsChanged
= true;
168 if ( bHaveScrollBox
!= bNeedScrollBox
)
170 mpScrollBox
->Show(bNeedScrollBox
);
173 if ( bScrollbarsChanged
)
180 void ImpVclMEdit::InitFromStyle( WinBits nWinStyle
)
182 ImpUpdateScrollBarVis( nWinStyle
);
183 SetAlign( nWinStyle
);
185 if ( nWinStyle
& WB_NOHIDESELECTION
)
186 mpTextWindow
->SetAutoFocusHide( false );
188 mpTextWindow
->SetAutoFocusHide( true );
190 if ( nWinStyle
& WB_READONLY
)
191 mpTextWindow
->GetTextView()->SetReadOnly( true );
193 mpTextWindow
->GetTextView()->SetReadOnly( false );
195 if ( nWinStyle
& WB_IGNORETAB
)
197 mpTextWindow
->SetIgnoreTab( true );
201 mpTextWindow
->SetIgnoreTab( false );
202 // #103667# VclMultiLineEdit has the flag, but focusable window also needs this flag
203 WinBits nStyle
= mpTextWindow
->GetStyle();
204 nStyle
|= WB_NODIALOGCONTROL
;
205 mpTextWindow
->SetStyle( nStyle
);
209 ImpVclMEdit::~ImpVclMEdit()
211 EndListening( *mpTextWindow
->GetTextEngine() );
212 mpTextWindow
.disposeAndClear();
213 mpHScrollBar
.disposeAndClear();
214 mpVScrollBar
.disposeAndClear();
215 mpScrollBox
.disposeAndClear();
216 pVclMultiLineEdit
.disposeAndClear();
219 void ImpVclMEdit::ImpSetScrollBarRanges()
221 const tools::Long nTextHeight
= mpTextWindow
->GetTextEngine()->GetTextHeight();
222 mpVScrollBar
->SetRange( Range( 0, nTextHeight
-1 ) );
224 mpHScrollBar
->SetRange( Range( 0, mnTextWidth
-1 ) );
227 void ImpVclMEdit::ImpInitScrollBars()
229 static const sal_Unicode sampleChar
= { 'x' };
231 ImpSetScrollBarRanges();
234 aCharBox
.setWidth( mpTextWindow
->GetTextWidth( OUString(sampleChar
) ) );
235 aCharBox
.setHeight( mpTextWindow
->GetTextHeight() );
236 Size aOutSz
= mpTextWindow
->GetOutputSizePixel();
238 mpHScrollBar
->SetVisibleSize( aOutSz
.Width() );
239 mpHScrollBar
->SetPageSize( aOutSz
.Width() * 8 / 10 );
240 mpHScrollBar
->SetLineSize( aCharBox
.Width()*10 );
241 ImpSetHScrollBarThumbPos();
243 mpVScrollBar
->SetVisibleSize( aOutSz
.Height() );
244 mpVScrollBar
->SetPageSize( aOutSz
.Height() * 8 / 10 );
245 mpVScrollBar
->SetLineSize( aCharBox
.Height() );
246 mpVScrollBar
->SetThumbPos( mpTextWindow
->GetTextView()->GetStartDocPos().Y() );
249 void ImpVclMEdit::ImpSetHScrollBarThumbPos()
251 tools::Long nX
= mpTextWindow
->GetTextView()->GetStartDocPos().X();
252 if ( !mpTextWindow
->GetTextEngine()->IsRightToLeft() )
253 mpHScrollBar
->SetThumbPos( nX
);
255 mpHScrollBar
->SetThumbPos( mnTextWidth
- mpHScrollBar
->GetVisibleSize() - nX
);
259 IMPL_LINK( ImpVclMEdit
, ScrollHdl
, ScrollBar
*, pCurScrollBar
, void )
261 tools::Long nDiffX
= 0, nDiffY
= 0;
263 if ( pCurScrollBar
== mpVScrollBar
)
264 nDiffY
= mpTextWindow
->GetTextView()->GetStartDocPos().Y() - pCurScrollBar
->GetThumbPos();
265 else if ( pCurScrollBar
== mpHScrollBar
)
266 nDiffX
= mpTextWindow
->GetTextView()->GetStartDocPos().X() - pCurScrollBar
->GetThumbPos();
268 mpTextWindow
->GetTextView()->Scroll( nDiffX
, nDiffY
);
269 // mpTextWindow->GetTextView()->ShowCursor( false, true );
272 void ImpVclMEdit::SetAlign( WinBits nWinStyle
)
274 bool bRTL
= AllSettings::GetLayoutRTL();
275 mpTextWindow
->GetTextEngine()->SetRightToLeft( bRTL
);
277 if ( nWinStyle
& WB_CENTER
)
278 mpTextWindow
->GetTextEngine()->SetTextAlign( TxtAlign::Center
);
279 else if ( nWinStyle
& WB_RIGHT
)
280 mpTextWindow
->GetTextEngine()->SetTextAlign( !bRTL
? TxtAlign::Right
: TxtAlign::Left
);
281 else if ( nWinStyle
& WB_LEFT
)
282 mpTextWindow
->GetTextEngine()->SetTextAlign( !bRTL
? TxtAlign::Left
: TxtAlign::Right
);
285 void ImpVclMEdit::SetModified( bool bMod
)
287 mpTextWindow
->GetTextEngine()->SetModified( bMod
);
290 void ImpVclMEdit::SetReadOnly( bool bRdOnly
)
292 mpTextWindow
->GetTextView()->SetReadOnly( bRdOnly
);
293 // TODO: Adjust color?
296 bool ImpVclMEdit::IsReadOnly() const
298 return mpTextWindow
->GetTextView()->IsReadOnly();
301 void ImpVclMEdit::SetMaxTextLen(sal_Int32 nLen
)
303 mpTextWindow
->GetTextEngine()->SetMaxTextLen(nLen
);
306 sal_Int32
ImpVclMEdit::GetMaxTextLen() const
308 return mpTextWindow
->GetTextEngine()->GetMaxTextLen();
311 void ImpVclMEdit::InsertText( const OUString
& rStr
)
313 mpTextWindow
->GetTextView()->InsertText( rStr
);
316 OUString
ImpVclMEdit::GetSelected() const
318 return mpTextWindow
->GetTextView()->GetSelected();
321 OUString
ImpVclMEdit::GetSelected( LineEnd aSeparator
) const
323 return mpTextWindow
->GetTextView()->GetSelected( aSeparator
);
326 void ImpVclMEdit::SetMaxTextWidth(tools::Long nMaxWidth
)
328 mpTextWindow
->GetTextEngine()->SetMaxTextWidth(nMaxWidth
);
331 void ImpVclMEdit::Resize()
336 WinBits
nWinStyle( pVclMultiLineEdit
->GetStyle() );
337 if ( ( nWinStyle
& WB_AUTOVSCROLL
) == WB_AUTOVSCROLL
)
338 ImpUpdateScrollBarVis( nWinStyle
);
340 Size aSz
= pVclMultiLineEdit
->GetOutputSizePixel();
341 Size aEditSize
= aSz
;
342 tools::Long nSBWidth
= pVclMultiLineEdit
->GetSettings().GetStyleSettings().GetScrollBarSize();
343 nSBWidth
= pVclMultiLineEdit
->CalcZoom( nSBWidth
);
345 if (mpHScrollBar
->IsVisible())
346 aSz
.AdjustHeight( -(nSBWidth
+1) );
347 if (mpVScrollBar
->IsVisible())
348 aSz
.AdjustWidth( -(nSBWidth
+1) );
350 if (!mpHScrollBar
->IsVisible())
351 mpTextWindow
->GetTextEngine()->SetMaxTextWidth( aSz
.Width() );
353 mpHScrollBar
->setPosSizePixel( 0, aEditSize
.Height()-nSBWidth
, aSz
.Width(), nSBWidth
);
355 Point aTextWindowPos
;
356 if (mpVScrollBar
->IsVisible())
358 if( AllSettings::GetLayoutRTL() )
360 mpVScrollBar
->setPosSizePixel( 0, 0, nSBWidth
, aSz
.Height() );
361 aTextWindowPos
.AdjustX(nSBWidth
);
364 mpVScrollBar
->setPosSizePixel( aEditSize
.Width()-nSBWidth
, 0, nSBWidth
, aSz
.Height() );
367 if (mpScrollBox
->IsVisible())
368 mpScrollBox
->setPosSizePixel( aSz
.Width(), aSz
.Height(), nSBWidth
, nSBWidth
);
370 Size
aTextWindowSize( aSz
);
371 if ( aTextWindowSize
.Width() < 0 )
372 aTextWindowSize
.setWidth( 0 );
373 if ( aTextWindowSize
.Height() < 0 )
374 aTextWindowSize
.setHeight( 0 );
376 Size
aOldTextWindowSize( mpTextWindow
->GetSizePixel() );
377 mpTextWindow
->SetPosSizePixel( aTextWindowPos
, aTextWindowSize
);
378 if ( aOldTextWindowSize
== aTextWindowSize
)
381 // Changing the text window size might effectively have changed the need for
382 // scrollbars, so do another iteration.
384 OSL_ENSURE( nIteration
< 3, "ImpVclMEdit::Resize: isn't this expected to terminate with the second iteration?" );
386 } while ( nIteration
<= 3 ); // artificial break after four iterations
391 void ImpVclMEdit::GetFocus()
393 mpTextWindow
->GrabFocus();
396 void ImpVclMEdit::Cut()
398 if ( !mpTextWindow
->GetTextView()->IsReadOnly() )
399 mpTextWindow
->GetTextView()->Cut();
402 void ImpVclMEdit::Copy()
404 mpTextWindow
->GetTextView()->Copy();
407 void ImpVclMEdit::Paste()
409 if ( !mpTextWindow
->GetTextView()->IsReadOnly() )
410 mpTextWindow
->GetTextView()->Paste();
413 void ImpVclMEdit::SetText( const OUString
& rStr
)
415 bool bWasModified
= mpTextWindow
->GetTextEngine()->IsModified();
416 mpTextWindow
->GetTextEngine()->SetText( rStr
);
418 mpTextWindow
->GetTextEngine()->SetModified( false );
420 mpTextWindow
->GetTextView()->SetSelection( TextSelection() );
422 WinBits
nWinStyle( pVclMultiLineEdit
->GetStyle() );
423 if ( ( nWinStyle
& WB_AUTOVSCROLL
) == WB_AUTOVSCROLL
)
424 ImpUpdateScrollBarVis( nWinStyle
);
427 OUString
ImpVclMEdit::GetText() const
429 return mpTextWindow
->GetTextEngine()->GetText();
432 OUString
ImpVclMEdit::GetText( LineEnd aSeparator
) const
434 return mpTextWindow
->GetTextEngine()->GetText( aSeparator
);
437 OUString
ImpVclMEdit::GetTextLines( LineEnd aSeparator
) const
439 return mpTextWindow
->GetTextEngine()->GetTextLines( aSeparator
);
442 void ImpVclMEdit::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
444 switch (rHint
.GetId())
446 case SfxHintId::TextViewScrolled
:
447 if (mpHScrollBar
->IsVisible())
448 ImpSetHScrollBarThumbPos();
449 if (mpVScrollBar
->IsVisible())
450 mpVScrollBar
->SetThumbPos( mpTextWindow
->GetTextView()->GetStartDocPos().Y() );
453 case SfxHintId::TextHeightChanged
:
454 if ( mpTextWindow
->GetTextView()->GetStartDocPos().Y() )
456 tools::Long nOutHeight
= mpTextWindow
->GetOutputSizePixel().Height();
457 tools::Long nTextHeight
= mpTextWindow
->GetTextEngine()->GetTextHeight();
458 if ( nTextHeight
< nOutHeight
)
459 mpTextWindow
->GetTextView()->Scroll( 0, mpTextWindow
->GetTextView()->GetStartDocPos().Y() );
461 ImpSetScrollBarRanges();
464 case SfxHintId::TextFormatted
:
465 if (mpHScrollBar
->IsVisible())
467 const tools::Long nWidth
= mpTextWindow
->GetTextEngine()->CalcTextWidth();
468 if ( nWidth
!= mnTextWidth
)
470 mnTextWidth
= nWidth
;
471 mpHScrollBar
->SetRange( Range( 0, mnTextWidth
-1 ) );
472 ImpSetHScrollBarThumbPos();
477 case SfxHintId::TextModified
:
478 ImpUpdateScrollBarVis(pVclMultiLineEdit
->GetStyle());
479 pVclMultiLineEdit
->Modify();
482 case SfxHintId::TextViewSelectionChanged
:
483 pVclMultiLineEdit
->SelectionChanged();
486 case SfxHintId::TextViewCaretChanged
:
487 pVclMultiLineEdit
->CaretChanged();
494 void ImpVclMEdit::SetSelection( const Selection
& rSelection
)
496 OUString aText
= mpTextWindow
->GetTextEngine()->GetText();
498 Selection
aNewSelection( rSelection
);
499 if ( aNewSelection
.Min() < 0 )
500 aNewSelection
.Min() = 0;
501 else if ( aNewSelection
.Min() > aText
.getLength() )
502 aNewSelection
.Min() = aText
.getLength();
503 if ( aNewSelection
.Max() < 0 )
504 aNewSelection
.Max() = 0;
505 else if ( aNewSelection
.Max() > aText
.getLength() )
506 aNewSelection
.Max() = aText
.getLength();
508 tools::Long nEnd
= std::max( aNewSelection
.Min(), aNewSelection
.Max() );
509 TextSelection aTextSel
;
510 sal_uInt32 nPara
= 0;
515 if ( x
== aNewSelection
.Min() )
516 aTextSel
.GetStart() = TextPaM( nPara
, nChar
);
517 if ( x
== aNewSelection
.Max() )
518 aTextSel
.GetEnd() = TextPaM( nPara
, nChar
);
520 if ( ( x
< aText
.getLength() ) && ( aText
[ x
] == '\n' ) )
529 mpTextWindow
->GetTextView()->SetSelection( aTextSel
);
532 const Selection
& ImpVclMEdit::GetSelection() const
534 maSelection
= Selection();
535 TextSelection
aTextSel( mpTextWindow
->GetTextView()->GetSelection() );
537 // flatten selection => every line-break a character
539 ExtTextEngine
* pExtTextEngine
= mpTextWindow
->GetTextEngine();
541 for ( sal_uInt32 n
= 0; n
< aTextSel
.GetStart().GetPara(); ++n
)
543 maSelection
.Min() += pExtTextEngine
->GetTextLen( n
);
547 // first paragraph with selection
548 maSelection
.Max() = maSelection
.Min();
549 maSelection
.Min() += aTextSel
.GetStart().GetIndex();
551 for ( sal_uInt32 n
= aTextSel
.GetStart().GetPara(); n
< aTextSel
.GetEnd().GetPara(); ++n
)
553 maSelection
.Max() += pExtTextEngine
->GetTextLen( n
);
557 maSelection
.Max() += aTextSel
.GetEnd().GetIndex();
562 Size
ImpVclMEdit::CalcMinimumSize() const
564 Size
aSz( mpTextWindow
->GetTextEngine()->CalcTextWidth(),
565 mpTextWindow
->GetTextEngine()->GetTextHeight() );
567 if (mpHScrollBar
->IsVisible())
568 aSz
.AdjustHeight(mpHScrollBar
->GetSizePixel().Height() );
569 if (mpVScrollBar
->IsVisible())
570 aSz
.AdjustWidth(mpVScrollBar
->GetSizePixel().Width() );
575 Size
ImpVclMEdit::CalcBlockSize( sal_uInt16 nColumns
, sal_uInt16 nLines
) const
577 static const sal_Unicode sampleChar
= 'X';
581 aCharSz
.setWidth( mpTextWindow
->GetTextWidth( OUString(sampleChar
) ) );
582 aCharSz
.setHeight( mpTextWindow
->GetTextHeight() );
585 aSz
.setHeight( nLines
*aCharSz
.Height() );
587 aSz
.setHeight( mpTextWindow
->GetTextEngine()->GetTextHeight() );
590 aSz
.setWidth( nColumns
*aCharSz
.Width() );
592 aSz
.setWidth( mpTextWindow
->GetTextEngine()->CalcTextWidth() );
594 if (mpHScrollBar
->IsVisible())
595 aSz
.AdjustHeight(mpHScrollBar
->GetSizePixel().Height() );
596 if (mpVScrollBar
->IsVisible())
597 aSz
.AdjustWidth(mpVScrollBar
->GetSizePixel().Width() );
602 void ImpVclMEdit::GetMaxVisColumnsAndLines( sal_uInt16
& rnCols
, sal_uInt16
& rnLines
) const
604 static const sal_Unicode sampleChar
= { 'x' };
605 Size aOutSz
= mpTextWindow
->GetOutputSizePixel();
606 Size
aCharSz( mpTextWindow
->GetTextWidth( OUString(sampleChar
) ), mpTextWindow
->GetTextHeight() );
607 rnCols
= static_cast<sal_uInt16
>(aOutSz
.Width()/aCharSz
.Width());
608 rnLines
= static_cast<sal_uInt16
>(aOutSz
.Height()/aCharSz
.Height());
611 void ImpVclMEdit::Enable( bool bEnable
)
613 mpTextWindow
->Enable( bEnable
);
614 if (mpHScrollBar
->IsVisible())
615 mpHScrollBar
->Enable( bEnable
);
616 if (mpVScrollBar
->IsVisible())
617 mpVScrollBar
->Enable( bEnable
);
620 bool ImpVclMEdit::HandleCommand( const CommandEvent
& rCEvt
)
623 CommandEventId nCommand
= rCEvt
.GetCommand();
624 if (nCommand
== CommandEventId::Wheel
||
625 nCommand
== CommandEventId::StartAutoScroll
||
626 nCommand
== CommandEventId::AutoScroll
||
627 nCommand
== CommandEventId::GesturePan
)
629 ScrollBar
* pHScrollBar
= mpHScrollBar
->IsVisible() ? mpHScrollBar
.get() : nullptr;
630 ScrollBar
* pVScrollBar
= mpVScrollBar
->IsVisible() ? mpVScrollBar
.get() : nullptr;
631 mpTextWindow
->HandleScrollCommand(rCEvt
, pHScrollBar
, pVScrollBar
);
637 TextWindow::TextWindow(Edit
* pParent
)
642 mbFocusSelectionHide
= false;
644 mbActivePopup
= false;
645 mbSelectOnTab
= true;
647 SetPointer( PointerStyle::Text
);
649 mpExtTextEngine
.reset(new ExtTextEngine
);
650 mpExtTextEngine
->SetMaxTextLen(EDIT_NOLIMIT
);
651 if( pParent
->GetStyle() & WB_BORDER
)
652 mpExtTextEngine
->SetLeftMargin( 2 );
653 mpExtTextEngine
->SetLocale( GetSettings().GetLanguageTag().getLocale() );
654 mpExtTextView
.reset(new TextView( mpExtTextEngine
.get(), this ));
655 mpExtTextEngine
->InsertView( mpExtTextView
.get() );
656 mpExtTextEngine
->EnableUndo( true );
657 mpExtTextView
->ShowCursor();
659 Color aBackgroundColor
= GetSettings().GetStyleSettings().GetWorkspaceColor();
660 SetBackground( aBackgroundColor
);
661 pParent
->SetBackground( aBackgroundColor
);
664 TextWindow::~TextWindow()
669 void TextWindow::dispose()
672 mpExtTextView
.reset();
673 mpExtTextEngine
.reset();
677 void TextWindow::MouseMove( const MouseEvent
& rMEvt
)
679 mpExtTextView
->MouseMove( rMEvt
);
680 Window::MouseMove( rMEvt
);
683 void TextWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
685 mbInMBDown
= true; // so that GetFocus does not select everything
686 mpExtTextView
->MouseButtonDown( rMEvt
);
691 void TextWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
693 mpExtTextView
->MouseButtonUp( rMEvt
);
696 void TextWindow::KeyInput( const KeyEvent
& rKEvent
)
699 sal_uInt16 nCode
= rKEvent
.GetKeyCode().GetCode();
700 if ( nCode
== css::awt::Key::SELECT_ALL
||
701 ( (nCode
== KEY_A
) && rKEvent
.GetKeyCode().IsMod1() && !rKEvent
.GetKeyCode().IsMod2() )
704 mpExtTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL
, TEXT_INDEX_ALL
) ) );
707 else if ( (nCode
== KEY_S
) && rKEvent
.GetKeyCode().IsShift() && rKEvent
.GetKeyCode().IsMod1() )
709 if ( vcl::GetGetSpecialCharsFunction() )
711 // to maintain the selection
712 mbActivePopup
= true;
713 OUString aChars
= vcl::GetGetSpecialCharsFunction()(GetFrameWeld(), GetFont());
714 if (!aChars
.isEmpty())
716 mpExtTextView
->InsertText( aChars
);
717 mpExtTextView
->GetTextEngine()->SetModified( true );
719 mbActivePopup
= false;
723 else if ( nCode
== KEY_TAB
)
727 if (!rKEvent
.GetKeyCode().IsMod1())
728 bDone
= mpExtTextView
->KeyInput(rKEvent
);
731 // tdf#107625 make ctrl+tab act like tab when MultiLine Edit normally accepts tab as an input char
732 vcl::KeyCode
aKeyCode(rKEvent
.GetKeyCode().GetCode(), rKEvent
.GetKeyCode().GetModifier() & ~KEY_MOD1
);
733 KeyEvent
aKEventWithoutMod1(rKEvent
.GetCharCode(), aKeyCode
, rKEvent
.GetRepeat());
734 Window::KeyInput(aKEventWithoutMod1
);
741 bDone
= mpExtTextView
->KeyInput( rKEvent
);
745 Window::KeyInput( rKEvent
);
748 void TextWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
750 mpExtTextView
->Paint(rRenderContext
, rRect
);
753 void TextWindow::Resize()
757 void TextWindow::Command( const CommandEvent
& rCEvt
)
759 if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
761 VclPtr
<PopupMenu
> pPopup
= mxParent
->CreatePopupMenu();
762 bool bEnableCut
= true;
763 bool bEnableCopy
= true;
764 bool bEnableDelete
= true;
765 bool bEnablePaste
= true;
766 bool bEnableSpecialChar
= true;
767 bool bEnableUndo
= true;
769 if ( !mpExtTextView
->HasSelection() )
773 bEnableDelete
= false;
775 if ( mpExtTextView
->IsReadOnly() )
778 bEnablePaste
= false;
779 bEnableDelete
= false;
780 bEnableSpecialChar
= false;
782 if ( !mpExtTextView
->GetTextEngine()->HasUndoManager() || !mpExtTextView
->GetTextEngine()->GetUndoManager().GetUndoActionCount() )
786 pPopup
->EnableItem(pPopup
->GetItemId(u
"cut"), bEnableCut
);
787 pPopup
->EnableItem(pPopup
->GetItemId(u
"copy"), bEnableCopy
);
788 pPopup
->EnableItem(pPopup
->GetItemId(u
"delete"), bEnableDelete
);
789 pPopup
->EnableItem(pPopup
->GetItemId(u
"paste"), bEnablePaste
);
790 pPopup
->SetItemText(pPopup
->GetItemId(u
"specialchar"),
791 BuilderUtils::convertMnemonicMarkup(VclResId(STR_SPECIAL_CHARACTER_MENU_ENTRY
)));
792 pPopup
->EnableItem(pPopup
->GetItemId(u
"specialchar"), bEnableSpecialChar
);
793 pPopup
->EnableItem(pPopup
->GetItemId(u
"undo"), bEnableUndo
);
794 pPopup
->ShowItem(pPopup
->GetItemId(u
"specialchar"), !vcl::GetGetSpecialCharsFunction());
796 mbActivePopup
= true;
797 Point aPos
= rCEvt
.GetMousePosPixel();
798 if ( !rCEvt
.IsMouseEvent() )
800 // Sometime do show Menu centered in the selection !!!
801 Size aSize
= GetOutputSizePixel();
802 aPos
= Point( aSize
.Width()/2, aSize
.Height()/2 );
804 sal_uInt16 n
= pPopup
->Execute( this, aPos
);
805 OUString sCommand
= pPopup
->GetItemIdent(n
);
806 if (sCommand
== "undo")
808 mpExtTextView
->Undo();
809 mpExtTextEngine
->SetModified( true );
810 mpExtTextEngine
->Broadcast( TextHint( SfxHintId::TextModified
) );
812 else if (sCommand
== "cut")
814 mpExtTextView
->Cut();
815 mpExtTextEngine
->SetModified( true );
816 mpExtTextEngine
->Broadcast( TextHint( SfxHintId::TextModified
) );
818 else if (sCommand
== "copy")
820 mpExtTextView
->Copy();
822 else if (sCommand
== "paste")
824 mpExtTextView
->Paste();
825 mpExtTextEngine
->SetModified( true );
826 mpExtTextEngine
->Broadcast( TextHint( SfxHintId::TextModified
) );
828 else if (sCommand
== "delete")
830 mpExtTextView
->DeleteSelected();
831 mpExtTextEngine
->SetModified( true );
832 mpExtTextEngine
->Broadcast( TextHint( SfxHintId::TextModified
) );
834 else if (sCommand
== "selectall")
836 mpExtTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL
, TEXT_INDEX_ALL
) ) );
838 else if (sCommand
== "specialchar")
840 OUString aChars
= vcl::GetGetSpecialCharsFunction()(GetFrameWeld(), GetFont());
841 if (!aChars
.isEmpty())
843 mpExtTextView
->InsertText( aChars
);
844 mpExtTextEngine
->SetModified( true );
845 mpExtTextEngine
->Broadcast( TextHint( SfxHintId::TextModified
) );
849 mbActivePopup
= false;
853 mpExtTextView
->Command( rCEvt
);
855 Window::Command( rCEvt
);
858 void TextWindow::GetFocus()
864 bool bGotoCursor
= !mpExtTextView
->IsReadOnly();
865 if ( mbFocusSelectionHide
&& IsReallyVisible() && mbSelectOnTab
&& !mbInMBDown
)
867 // select everything, but do not scroll
868 bool bAutoScroll
= mpExtTextView
->IsAutoScroll();
869 mpExtTextView
->SetAutoScroll( false );
870 mpExtTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL
, TEXT_INDEX_ALL
) ) );
871 mpExtTextView
->SetAutoScroll( bAutoScroll
);
874 mpExtTextView
->SetPaintSelection( true );
875 mpExtTextView
->ShowCursor( bGotoCursor
);
878 void TextWindow::LoseFocus()
882 if ( mbFocusSelectionHide
&& !mbActivePopup
&& mpExtTextView
)
883 mpExtTextView
->SetPaintSelection( false );
886 VclMultiLineEdit::VclMultiLineEdit( vcl::Window
* pParent
, WinBits nWinStyle
)
887 : Edit( pParent
, nWinStyle
)
889 SetType( WindowType::MULTILINEEDIT
);
890 pImpVclMEdit
.reset(new ImpVclMEdit( this, nWinStyle
));
891 ImplInitSettings( true );
893 SetCompoundControl( true );
894 SetStyle( ImplInitStyle( nWinStyle
) );
897 VclMultiLineEdit::~VclMultiLineEdit()
902 void VclMultiLineEdit::dispose()
904 pImpVclMEdit
.reset();
908 WinBits
VclMultiLineEdit::ImplInitStyle( WinBits nStyle
)
910 if ( !(nStyle
& WB_NOTABSTOP
) )
911 nStyle
|= WB_TABSTOP
;
913 if ( !(nStyle
& WB_NOGROUP
) )
916 if ( !(nStyle
& WB_IGNORETAB
))
917 nStyle
|= WB_NODIALOGCONTROL
;
922 void VclMultiLineEdit::ApplySettings(vcl::RenderContext
& rRenderContext
)
924 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
926 // The Font has to be adjusted, as the TextEngine does not take care of
927 // TextColor/Background
929 Color aTextColor
= rStyleSettings
.GetFieldTextColor();
930 if (IsControlForeground())
931 aTextColor
= GetControlForeground();
934 aTextColor
= rStyleSettings
.GetDisableColor();
936 vcl::Font aFont
= rStyleSettings
.GetFieldFont();
937 aFont
.SetTransparent(IsPaintTransparent());
938 ApplyControlFont(rRenderContext
, aFont
);
940 vcl::Font theFont
= rRenderContext
.GetFont();
941 theFont
.SetColor(aTextColor
);
942 if (IsPaintTransparent())
943 theFont
.SetFillColor(COL_TRANSPARENT
);
945 theFont
.SetFillColor(IsControlBackground() ? GetControlBackground() : rStyleSettings
.GetFieldColor());
947 pImpVclMEdit
->GetTextWindow()->SetFont(theFont
);
948 // FIXME: next call causes infinite invalidation loop, rethink how to properly fix this situation
949 // pImpVclMEdit->GetTextWindow()->GetTextEngine()->SetFont(theFont);
950 pImpVclMEdit
->GetTextWindow()->SetTextColor(aTextColor
);
952 if (IsPaintTransparent())
954 pImpVclMEdit
->GetTextWindow()->SetPaintTransparent(true);
955 pImpVclMEdit
->GetTextWindow()->SetBackground();
956 pImpVclMEdit
->GetTextWindow()->SetControlBackground();
957 rRenderContext
.SetBackground();
958 SetControlBackground();
962 if (IsControlBackground())
963 pImpVclMEdit
->GetTextWindow()->SetBackground(GetControlBackground());
965 pImpVclMEdit
->GetTextWindow()->SetBackground(rStyleSettings
.GetFieldColor());
966 // also adjust for VclMultiLineEdit as the TextComponent might hide Scrollbars
967 rRenderContext
.SetBackground(pImpVclMEdit
->GetTextWindow()->GetBackground());
971 void VclMultiLineEdit::ImplInitSettings(bool bBackground
)
973 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
975 // The Font has to be adjusted, as the TextEngine does not take care of
976 // TextColor/Background
978 Color aTextColor
= rStyleSettings
.GetFieldTextColor();
979 if (IsControlForeground())
980 aTextColor
= GetControlForeground();
982 aTextColor
= rStyleSettings
.GetDisableColor();
984 vcl::Font aFont
= rStyleSettings
.GetFieldFont();
985 aFont
.SetTransparent(IsPaintTransparent());
986 ApplyControlFont(*GetOutDev(), aFont
);
988 vcl::Font TheFont
= GetFont();
989 TheFont
.SetColor(aTextColor
);
990 if (IsPaintTransparent())
991 TheFont
.SetFillColor(COL_TRANSPARENT
);
993 TheFont
.SetFillColor(IsControlBackground() ? GetControlBackground() : rStyleSettings
.GetFieldColor());
994 pImpVclMEdit
->GetTextWindow()->SetFont(TheFont
);
995 pImpVclMEdit
->GetTextWindow()->GetTextEngine()->SetFont(TheFont
);
996 pImpVclMEdit
->GetTextWindow()->SetTextColor(aTextColor
);
1001 if (IsPaintTransparent())
1003 pImpVclMEdit
->GetTextWindow()->SetPaintTransparent(true);
1004 pImpVclMEdit
->GetTextWindow()->SetBackground();
1005 pImpVclMEdit
->GetTextWindow()->SetControlBackground();
1007 SetControlBackground();
1011 if (IsControlBackground())
1012 pImpVclMEdit
->GetTextWindow()->SetBackground(GetControlBackground());
1014 pImpVclMEdit
->GetTextWindow()->SetBackground(rStyleSettings
.GetFieldColor());
1015 // also adjust for VclMultiLineEdit as the TextComponent might hide Scrollbars
1016 SetBackground(pImpVclMEdit
->GetTextWindow()->GetBackground());
1020 void VclMultiLineEdit::Modify()
1022 aModifyHdlLink
.Call( *this );
1024 CallEventListeners( VclEventId::EditModify
);
1027 void VclMultiLineEdit::SelectionChanged()
1029 CallEventListeners(VclEventId::EditSelectionChanged
);
1032 void VclMultiLineEdit::CaretChanged()
1034 CallEventListeners(VclEventId::EditCaretChanged
);
1037 void VclMultiLineEdit::SetModifyFlag()
1039 pImpVclMEdit
->SetModified( true );
1042 void VclMultiLineEdit::SetReadOnly( bool bReadOnly
)
1044 pImpVclMEdit
->SetReadOnly( bReadOnly
);
1045 Edit::SetReadOnly( bReadOnly
);
1047 // #94921# ReadOnly can be overwritten in InitFromStyle() when WB not set.
1048 WinBits nStyle
= GetStyle();
1050 nStyle
|= WB_READONLY
;
1052 nStyle
&= ~WB_READONLY
;
1056 bool VclMultiLineEdit::IsReadOnly() const
1058 if (!pImpVclMEdit
) // might be called from within the dtor, when pImpVclMEdit == NULL is a valid state
1061 return pImpVclMEdit
->IsReadOnly();
1064 void VclMultiLineEdit::SetMaxTextLen(sal_Int32 nMaxLen
)
1066 pImpVclMEdit
->SetMaxTextLen(nMaxLen
);
1069 void VclMultiLineEdit::SetMaxTextWidth(tools::Long nMaxWidth
)
1071 pImpVclMEdit
->SetMaxTextWidth(nMaxWidth
);
1074 sal_Int32
VclMultiLineEdit::GetMaxTextLen() const
1076 return pImpVclMEdit
->GetMaxTextLen();
1079 void VclMultiLineEdit::ReplaceSelected( const OUString
& rStr
)
1081 pImpVclMEdit
->InsertText( rStr
);
1084 void VclMultiLineEdit::DeleteSelected()
1086 pImpVclMEdit
->InsertText( OUString() );
1089 OUString
VclMultiLineEdit::GetSelected() const
1091 return pImpVclMEdit
->GetSelected();
1094 OUString
VclMultiLineEdit::GetSelected( LineEnd aSeparator
) const
1096 return pImpVclMEdit
->GetSelected( aSeparator
);
1099 void VclMultiLineEdit::Cut()
1101 pImpVclMEdit
->Cut();
1104 void VclMultiLineEdit::Copy()
1106 pImpVclMEdit
->Copy();
1109 void VclMultiLineEdit::Paste()
1111 pImpVclMEdit
->Paste();
1114 void VclMultiLineEdit::SetText( const OUString
& rStr
)
1116 pImpVclMEdit
->SetText( rStr
);
1119 OUString
VclMultiLineEdit::GetText() const
1121 return pImpVclMEdit
? pImpVclMEdit
->GetText() : OUString();
1124 OUString
VclMultiLineEdit::GetText( LineEnd aSeparator
) const
1126 return pImpVclMEdit
? pImpVclMEdit
->GetText( aSeparator
) : OUString();
1129 OUString
VclMultiLineEdit::GetTextLines( LineEnd aSeparator
) const
1131 return pImpVclMEdit
? pImpVclMEdit
->GetTextLines( aSeparator
) : OUString();
1134 void VclMultiLineEdit::Resize()
1136 pImpVclMEdit
->Resize();
1139 void VclMultiLineEdit::GetFocus()
1141 if ( !pImpVclMEdit
) // might be called from within the dtor, when pImpVclMEdit == NULL is a valid state
1144 pImpVclMEdit
->GetFocus();
1147 void VclMultiLineEdit::SetSelection( const Selection
& rSelection
)
1149 pImpVclMEdit
->SetSelection( rSelection
);
1152 const Selection
& VclMultiLineEdit::GetSelection() const
1154 return pImpVclMEdit
->GetSelection();
1157 Size
VclMultiLineEdit::CalcMinimumSize() const
1159 Size aSz
= pImpVclMEdit
->CalcMinimumSize();
1161 sal_Int32 nLeft
, nTop
, nRight
, nBottom
;
1162 GetBorder(nLeft
, nTop
, nRight
, nBottom
);
1163 aSz
.AdjustWidth(nLeft
+nRight
);
1164 aSz
.AdjustHeight(nTop
+nBottom
);
1169 Size
VclMultiLineEdit::CalcAdjustedSize( const Size
& rPrefSize
) const
1171 Size aSz
= rPrefSize
;
1172 sal_Int32 nLeft
, nTop
, nRight
, nBottom
;
1173 GetBorder(nLeft
, nTop
, nRight
, nBottom
);
1175 // center vertically for whole lines
1177 tools::Long nHeight
= aSz
.Height() - nTop
- nBottom
;
1178 tools::Long nLineHeight
= pImpVclMEdit
->CalcBlockSize( 1, 1 ).Height();
1179 tools::Long nLines
= nHeight
/ nLineHeight
;
1183 aSz
.setHeight( nLines
* nLineHeight
);
1184 aSz
.AdjustHeight(nTop
+nBottom
);
1189 Size
VclMultiLineEdit::CalcBlockSize( sal_uInt16 nColumns
, sal_uInt16 nLines
) const
1191 Size aSz
= pImpVclMEdit
->CalcBlockSize( nColumns
, nLines
);
1193 sal_Int32 nLeft
, nTop
, nRight
, nBottom
;
1194 GetBorder(nLeft
, nTop
, nRight
, nBottom
);
1195 aSz
.AdjustWidth(nLeft
+nRight
);
1196 aSz
.AdjustHeight(nTop
+nBottom
);
1200 void VclMultiLineEdit::GetMaxVisColumnsAndLines( sal_uInt16
& rnCols
, sal_uInt16
& rnLines
) const
1202 pImpVclMEdit
->GetMaxVisColumnsAndLines( rnCols
, rnLines
);
1205 void VclMultiLineEdit::StateChanged( StateChangedType nType
)
1207 if( nType
== StateChangedType::Enable
)
1209 pImpVclMEdit
->Enable( IsEnabled() );
1210 ImplInitSettings( false );
1212 else if( nType
== StateChangedType::ReadOnly
)
1214 pImpVclMEdit
->SetReadOnly( IsReadOnly() );
1216 else if ( nType
== StateChangedType::Zoom
)
1218 pImpVclMEdit
->GetTextWindow()->SetZoom( GetZoom() );
1219 ImplInitSettings( false );
1222 else if ( nType
== StateChangedType::ControlFont
)
1224 ImplInitSettings( false );
1228 else if ( nType
== StateChangedType::ControlForeground
)
1230 ImplInitSettings( false );
1233 else if ( nType
== StateChangedType::ControlBackground
)
1235 ImplInitSettings( true );
1238 else if ( nType
== StateChangedType::Style
)
1240 pImpVclMEdit
->InitFromStyle( GetStyle() );
1241 SetStyle( ImplInitStyle( GetStyle() ) );
1243 else if ( nType
== StateChangedType::InitShow
)
1245 if( IsPaintTransparent() )
1247 pImpVclMEdit
->GetTextWindow()->SetPaintTransparent( true );
1248 pImpVclMEdit
->GetTextWindow()->SetBackground();
1249 pImpVclMEdit
->GetTextWindow()->SetControlBackground();
1251 SetControlBackground();
1255 Control::StateChanged( nType
);
1258 void VclMultiLineEdit::DataChanged( const DataChangedEvent
& rDCEvt
)
1260 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
1261 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
1263 ImplInitSettings( true );
1268 Control::DataChanged( rDCEvt
);
1271 void VclMultiLineEdit::Draw( OutputDevice
* pDev
, const Point
& rPos
, SystemTextColorFlags nFlags
)
1273 ImplInitSettings(true);
1275 Point aPos
= pDev
->LogicToPixel( rPos
);
1276 Size aSize
= GetSizePixel();
1278 vcl::Font aFont
= pImpVclMEdit
->GetTextWindow()->GetDrawPixelFont(pDev
);
1279 aFont
.SetTransparent( true );
1283 pDev
->SetFont( aFont
);
1284 pDev
->SetTextFillColor();
1286 // Border/Background
1287 pDev
->SetLineColor();
1288 pDev
->SetFillColor();
1289 bool bBorder
= (GetStyle() & WB_BORDER
);
1290 bool bBackground
= IsControlBackground();
1291 if ( bBorder
|| bBackground
)
1293 tools::Rectangle
aRect( aPos
, aSize
);
1296 DecorationView
aDecoView( pDev
);
1297 aRect
= aDecoView
.DrawFrame( aRect
, DrawFrameStyle::DoubleIn
);
1301 pDev
->SetFillColor( GetControlBackground() );
1302 pDev
->DrawRect( aRect
);
1306 pDev
->SetSystemTextColor(nFlags
, IsEnabled());
1308 OUString aText
= GetText();
1309 Size
aTextSz( pDev
->GetTextWidth( aText
), pDev
->GetTextHeight() );
1310 sal_uLong nLines
= static_cast<sal_uLong
>(aSize
.Height() / aTextSz
.Height());
1313 aTextSz
.setHeight( nLines
*aTextSz
.Height() );
1314 tools::Long nOnePixel
= GetDrawPixel( pDev
, 1 );
1315 tools::Long nOffX
= 3*nOnePixel
;
1316 tools::Long nOffY
= 2*nOnePixel
;
1319 if ( ( nOffY
< 0 ) || ( (nOffY
+aTextSz
.Height()) > aSize
.Height() ) || ( (nOffX
+aTextSz
.Width()) > aSize
.Width() ) )
1321 tools::Rectangle
aClip( aPos
, aSize
);
1322 if ( aTextSz
.Height() > aSize
.Height() )
1323 aClip
.AdjustBottom(aTextSz
.Height() - aSize
.Height() + 1 ); // so that HP-printer does not 'optimize-away'
1324 pDev
->IntersectClipRegion( aClip
);
1328 aTE
.SetText( GetText() );
1329 aTE
.SetMaxTextWidth( aSize
.Width() );
1330 aTE
.SetFont( aFont
);
1331 aTE
.SetTextAlign( pImpVclMEdit
->GetTextWindow()->GetTextEngine()->GetTextAlign() );
1332 aTE
.Draw( pDev
, Point( aPos
.X() + nOffX
, aPos
.Y() + nOffY
) );
1337 bool VclMultiLineEdit::EventNotify( NotifyEvent
& rNEvt
)
1340 if( rNEvt
.GetType() == NotifyEventType::COMMAND
)
1342 bDone
= pImpVclMEdit
->HandleCommand( *rNEvt
.GetCommandEvent() );
1344 return bDone
|| Edit::EventNotify( rNEvt
);
1347 bool VclMultiLineEdit::PreNotify( NotifyEvent
& rNEvt
)
1351 if( ( rNEvt
.GetType() == NotifyEventType::KEYINPUT
) && ( !GetTextView()->IsCursorEnabled() ) )
1353 const KeyEvent
& rKEvent
= *rNEvt
.GetKeyEvent();
1354 if ( !rKEvent
.GetKeyCode().IsShift() && ( rKEvent
.GetKeyCode().GetGroup() == KEYGROUP_CURSOR
) )
1357 TextSelection aSel
= pImpVclMEdit
->GetTextWindow()->GetTextView()->GetSelection();
1358 if ( aSel
.HasRange() )
1360 aSel
.GetStart() = aSel
.GetEnd();
1361 pImpVclMEdit
->GetTextWindow()->GetTextView()->SetSelection( aSel
);
1365 switch ( rKEvent
.GetKeyCode().GetCode() )
1369 if ( pImpVclMEdit
->GetVScrollBar().IsVisible() )
1370 pImpVclMEdit
->GetVScrollBar().DoScrollAction( ScrollType::LineUp
);
1375 if ( pImpVclMEdit
->GetVScrollBar().IsVisible() )
1376 pImpVclMEdit
->GetVScrollBar().DoScrollAction( ScrollType::LineDown
);
1381 if ( pImpVclMEdit
->GetVScrollBar().IsVisible() )
1382 pImpVclMEdit
->GetVScrollBar().DoScrollAction( ScrollType::PageUp
);
1387 if ( pImpVclMEdit
->GetVScrollBar().IsVisible() )
1388 pImpVclMEdit
->GetVScrollBar().DoScrollAction( ScrollType::PageDown
);
1393 if ( pImpVclMEdit
->GetHScrollBar().IsVisible() )
1394 pImpVclMEdit
->GetHScrollBar().DoScrollAction( ScrollType::LineUp
);
1399 if ( pImpVclMEdit
->GetHScrollBar().IsVisible() )
1400 pImpVclMEdit
->GetHScrollBar().DoScrollAction( ScrollType::LineDown
);
1405 if ( rKEvent
.GetKeyCode().IsMod1() )
1406 pImpVclMEdit
->GetTextWindow()->GetTextView()->
1407 SetSelection( TextSelection( TextPaM( 0, 0 ) ) );
1412 if ( rKEvent
.GetKeyCode().IsMod1() )
1413 pImpVclMEdit
->GetTextWindow()->GetTextView()->
1414 SetSelection( TextSelection( TextPaM( TEXT_PARA_ALL
, TEXT_INDEX_ALL
) ) );
1426 return bDone
|| Edit::PreNotify( rNEvt
);
1429 // Internals for derived classes, e.g. TextComponent
1431 ExtTextEngine
* VclMultiLineEdit::GetTextEngine() const
1433 return pImpVclMEdit
->GetTextWindow()->GetTextEngine();
1436 TextView
* VclMultiLineEdit::GetTextView() const
1438 return pImpVclMEdit
->GetTextWindow()->GetTextView();
1441 ScrollBar
& VclMultiLineEdit::GetVScrollBar() const
1443 return pImpVclMEdit
->GetVScrollBar();
1446 void VclMultiLineEdit::EnableFocusSelectionHide( bool bHide
)
1448 pImpVclMEdit
->GetTextWindow()->SetAutoFocusHide( bHide
);
1451 void VclMultiLineEdit::DisableSelectionOnFocus()
1453 pImpVclMEdit
->GetTextWindow()->DisableSelectionOnFocus();
1456 void VclMultiLineEdit::EnableCursor( bool bEnable
)
1458 GetTextView()->EnableCursor( bEnable
);
1461 bool VclMultiLineEdit::CanUp() const
1463 TextView
* pTextView
= GetTextView();
1464 const TextSelection
& rTextSelection
= pTextView
->GetSelection();
1465 TextPaM
aPaM(rTextSelection
.GetEnd());
1466 return aPaM
!= pTextView
->CursorUp(aPaM
);
1469 bool VclMultiLineEdit::CanDown() const
1471 TextView
* pTextView
= GetTextView();
1472 const TextSelection
& rTextSelection
= pTextView
->GetSelection();
1473 TextPaM
aPaM(rTextSelection
.GetEnd());
1474 return aPaM
!= pTextView
->CursorDown(aPaM
);
1477 TextWindow
* VclMultiLineEdit::GetTextWindow()
1479 return pImpVclMEdit
->GetTextWindow();
1482 FactoryFunction
VclMultiLineEdit::GetUITestFactory() const
1484 return MultiLineEditUIObject::create
;
1487 bool VclMultiLineEdit::set_property(const OUString
&rKey
, const OUString
&rValue
)
1489 if (rKey
== "cursor-visible")
1490 EnableCursor(toBool(rValue
));
1491 else if (rKey
== "accepts-tab")
1492 pImpVclMEdit
->GetTextWindow()->SetIgnoreTab(!toBool(rValue
));
1494 return Edit::set_property(rKey
, rValue
);
1498 void VclMultiLineEdit::DumpAsPropertyTree(tools::JsonWriter
& rJsonWriter
)
1500 Edit::DumpAsPropertyTree(rJsonWriter
);
1502 rJsonWriter
.put("cursor", pImpVclMEdit
->GetTextWindow()->GetTextView()->IsCursorEnabled());
1505 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */