diff options
author | Ivan Timofeev <timofeev.i.s@gmail.com> | 2012-11-26 23:26:17 +0400 |
---|---|---|
committer | Ivan Timofeev <timofeev.i.s@gmail.com> | 2012-11-27 00:15:15 +0400 |
commit | 37c4a408ebd2895ca06e6a22c54591494e9ec52c (patch) | |
tree | 1d160e70875b0aaafa919e0feaa0c71cab2ea5fa /vcl | |
parent | 95b4c0322d486d7899917ed22dd1f8193af77dcf (diff) |
vcl: Edit: add placeholder text feature, import it from .ui
Change-Id: I65d305b07dba5ddd80a108d5ef1b36f75eb67243
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/edit.hxx | 4 | ||||
-rw-r--r-- | vcl/source/control/edit.cxx | 37 |
2 files changed, 39 insertions, 2 deletions
diff --git a/vcl/inc/vcl/edit.hxx b/vcl/inc/vcl/edit.hxx index e2b9186b4a7e..3ad29cf2f544 100644 --- a/vcl/inc/vcl/edit.hxx +++ b/vcl/inc/vcl/edit.hxx @@ -62,6 +62,7 @@ private: DDInfo* mpDDInfo; Impl_IMEInfos* mpIMEInfos; XubString maText; + OUString maPlaceholderText; XubString maSaveValue; XubString maUndoText; XubString maRedoText; @@ -209,6 +210,9 @@ public: virtual void SetText( const XubString& rStr, const Selection& rNewSelection ); virtual XubString GetText() const; + virtual void SetPlaceholderText( const OUString& rStr ); + virtual OUString GetPlaceholderText() const; + void SaveValue() { maSaveValue = GetText(); } const XubString& GetSavedValue() const { return maSaveValue; } diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index 0c1ae909cd4b..a82a465f169a 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -238,6 +238,8 @@ bool Edit::set_property(const rtl::OString &rKey, const rtl::OString &rValue) nBits |= WB_PASSWORD; SetStyle(nBits); } + else if (rKey == "placeholder-text") + SetPlaceholderText(OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); else return Control::set_property(rKey, rValue); return true; @@ -255,6 +257,7 @@ void Edit::take_properties(Window &rOther) Edit &rOtherEdit = static_cast<Edit&>(rOther); maText = rOtherEdit.maText; + maPlaceholderText = rOtherEdit.maPlaceholderText; maSaveValue = rOtherEdit.maSaveValue; maUndoText = rOtherEdit.maUndoText; maRedoText = rOtherEdit.maRedoText; @@ -601,10 +604,12 @@ void Edit::ImplRepaint( xub_StrLen nStart, xub_StrLen nEnd, bool bLayout ) ImplClearBackground( 0, GetOutputSizePixel().Width() ); + bool bPaintPlaceholderText = aText.Len() == 0 && !maPlaceholderText.isEmpty(); + const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); if ( IsEnabled() ) ImplInitSettings( sal_False, sal_True, sal_False ); - else + if ( !IsEnabled() || bPaintPlaceholderText ) SetTextColor( rStyleSettings.GetDisableColor() ); // Set background color of the normal text @@ -630,7 +635,11 @@ void Edit::ImplRepaint( xub_StrLen nStart, xub_StrLen nEnd, bool bLayout ) long nPos = nStart ? pDX[2*nStart] : 0; aPos.X() = nPos + mnXOffset + ImplGetExtraOffset(); - if ( !bDrawSelection && !mpIMEInfos ) + if ( bPaintPlaceholderText ) + { + DrawText( aPos, maPlaceholderText ); + } + else if ( !bDrawSelection && !mpIMEInfos ) { DrawText( aPos, aText, nStart, nEnd - nStart ); } @@ -2863,6 +2872,30 @@ XubString Edit::GetText() const // ----------------------------------------------------------------------- +void Edit::SetPlaceholderText( const OUString& rStr ) +{ + if ( mpSubEdit ) + mpSubEdit->SetPlaceholderText( rStr ); + else if ( maPlaceholderText != rStr ) + { + maPlaceholderText = rStr; + if ( GetText().Len() == 0 ) + Invalidate(); + } +} + +// ----------------------------------------------------------------------- + +OUString Edit::GetPlaceholderText() const +{ + if ( mpSubEdit ) + return mpSubEdit->GetPlaceholderText(); + + return maPlaceholderText; +} + +// ----------------------------------------------------------------------- + void Edit::SetModifyFlag() { if ( mpSubEdit ) |