Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/MultiLineEditableTextBox.cpp
Ben Marsh 20bf0eb6a1 Updating copyright notices to 2017 (copying from //Tasks/UE4/Dev-Copyright-2017).
#rb none
#lockdown Nick.Penwarden

[CL 3226823 by Ben Marsh in Main branch]
2016-12-08 08:52:44 -05:00

181 lines
4.9 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "Components/MultiLineEditableTextBox.h"
#include "UObject/ConstructorHelpers.h"
#include "Engine/Font.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/Input/SMultiLineEditableTextBox.h"
#define LOCTEXT_NAMESPACE "UMG"
/////////////////////////////////////////////////////
// UMultiLineEditableTextBox
UMultiLineEditableTextBox::UMultiLineEditableTextBox(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
ForegroundColor_DEPRECATED = FLinearColor::Black;
BackgroundColor_DEPRECATED = FLinearColor::White;
ReadOnlyForegroundColor_DEPRECATED = FLinearColor::Black;
SMultiLineEditableTextBox::FArguments Defaults;
WidgetStyle = *Defaults._Style;
TextStyle = *Defaults._TextStyle;
AllowContextMenu = Defaults._AllowContextMenu.Get();
AutoWrapText = true;
if (!IsRunningDedicatedServer())
{
static ConstructorHelpers::FObjectFinder<UFont> RobotoFontObj(TEXT("/Engine/EngineFonts/Roboto"));
Font_DEPRECATED = FSlateFontInfo(RobotoFontObj.Object, 12, FName("Bold"));
WidgetStyle.SetFont(Font_DEPRECATED);
WidgetStyle.SetForegroundColor(ForegroundColor_DEPRECATED);
WidgetStyle.SetBackgroundColor(BackgroundColor_DEPRECATED);
WidgetStyle.SetReadOnlyForegroundColor(ReadOnlyForegroundColor_DEPRECATED);
}
}
void UMultiLineEditableTextBox::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
MyEditableTextBlock.Reset();
}
TSharedRef<SWidget> UMultiLineEditableTextBox::RebuildWidget()
{
MyEditableTextBlock = SNew(SMultiLineEditableTextBox)
.Style(&WidgetStyle)
.TextStyle(&TextStyle)
.AllowContextMenu(AllowContextMenu)
// .MinDesiredWidth(MinimumDesiredWidth)
// .Padding(Padding)
// .IsCaretMovedWhenGainFocus(IsCaretMovedWhenGainFocus)
// .SelectAllTextWhenFocused(SelectAllTextWhenFocused)
// .RevertTextOnEscape(RevertTextOnEscape)
// .ClearKeyboardFocusOnCommit(ClearKeyboardFocusOnCommit)
// .SelectAllTextOnCommit(SelectAllTextOnCommit)
.OnTextChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnTextChanged))
.OnTextCommitted(BIND_UOBJECT_DELEGATE(FOnTextCommitted, HandleOnTextCommitted))
;
return MyEditableTextBlock.ToSharedRef();
}
void UMultiLineEditableTextBox::SynchronizeProperties()
{
Super::SynchronizeProperties();
TAttribute<FText> HintTextBinding = OPTIONAL_BINDING(FText, HintText);
MyEditableTextBlock->SetStyle(&WidgetStyle);
MyEditableTextBlock->SetText(Text);
MyEditableTextBlock->SetHintText(HintTextBinding);
MyEditableTextBlock->SetAllowContextMenu(AllowContextMenu);
// MyEditableTextBlock->SetIsReadOnly(IsReadOnly);
// MyEditableTextBlock->SetIsPassword(IsPassword);
// MyEditableTextBlock->SetColorAndOpacity(ColorAndOpacity);
// TODO UMG Complete making all properties settable on SMultiLineEditableTextBox
Super::SynchronizeTextLayoutProperties(*MyEditableTextBlock);
}
FText UMultiLineEditableTextBox::GetText() const
{
if ( MyEditableTextBlock.IsValid() )
{
return MyEditableTextBlock->GetText();
}
return Text;
}
void UMultiLineEditableTextBox::SetText(FText InText)
{
Text = InText;
if ( MyEditableTextBlock.IsValid() )
{
MyEditableTextBlock->SetText(Text);
}
}
void UMultiLineEditableTextBox::SetError(FText InError)
{
if ( MyEditableTextBlock.IsValid() )
{
MyEditableTextBlock->SetError(InError);
}
}
void UMultiLineEditableTextBox::HandleOnTextChanged(const FText& InText)
{
OnTextChanged.Broadcast(InText);
}
void UMultiLineEditableTextBox::HandleOnTextCommitted(const FText& InText, ETextCommit::Type CommitMethod)
{
OnTextCommitted.Broadcast(InText, CommitMethod);
}
void UMultiLineEditableTextBox::PostLoad()
{
Super::PostLoad();
if ( GetLinkerUE4Version() < VER_UE4_DEPRECATE_UMG_STYLE_ASSETS )
{
if ( Style_DEPRECATED != nullptr )
{
const FEditableTextBoxStyle* StylePtr = Style_DEPRECATED->GetStyle<FEditableTextBoxStyle>();
if ( StylePtr != nullptr )
{
WidgetStyle = *StylePtr;
}
Style_DEPRECATED = nullptr;
}
}
if (GetLinkerUE4Version() < VER_UE4_DEPRECATE_UMG_STYLE_OVERRIDES)
{
if (Font_DEPRECATED.HasValidFont())
{
WidgetStyle.Font = Font_DEPRECATED;
Font_DEPRECATED = FSlateFontInfo();
}
if (ForegroundColor_DEPRECATED != FLinearColor::Black)
{
WidgetStyle.ForegroundColor = ForegroundColor_DEPRECATED;
ForegroundColor_DEPRECATED = FLinearColor::Black;
}
if (BackgroundColor_DEPRECATED != FLinearColor::White)
{
WidgetStyle.BackgroundColor = BackgroundColor_DEPRECATED;
BackgroundColor_DEPRECATED = FLinearColor::White;
}
if (ReadOnlyForegroundColor_DEPRECATED != FLinearColor::Black)
{
WidgetStyle.ReadOnlyForegroundColor = ReadOnlyForegroundColor_DEPRECATED;
ReadOnlyForegroundColor_DEPRECATED = FLinearColor::Black;
}
}
}
#if WITH_EDITOR
const FText UMultiLineEditableTextBox::GetPaletteCategory()
{
return LOCTEXT("Input", "Input");
}
#endif
/////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE