This is a hacky RichTextBoxHost in XAML
Just to prove it can be done this way
This commit is contained in:
parent
dd212dde74
commit
27c4b8df09
|
@ -1347,7 +1347,8 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
GUID realGuid = { 0 };
|
||||
|
||||
TextBlockControlHost controlHost{};
|
||||
// TextBlockControlHost controlHost{};
|
||||
RichTextBoxControlHost controlHost{};
|
||||
|
||||
const int focusedTabIndex = _GetFocusedTabIndex();
|
||||
auto focusedTab = _tabs[focusedTabIndex];
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace TerminalApp
|
|||
interface IControlHost
|
||||
{
|
||||
Windows.UI.Xaml.Controls.Control GetControl();
|
||||
Windows.UI.Xaml.UIElement GetRoot();
|
||||
|
||||
event Windows.Foundation.TypedEventHandler<IControlHost, ClosedEventArgs> CloseRequested;
|
||||
void Close();
|
||||
|
@ -15,5 +16,9 @@ namespace TerminalApp
|
|||
event Windows.Foundation.TypedEventHandler<IControlHost, Microsoft.Terminal.TerminalControl.TitleChangedEventArgs> TitleChanged;
|
||||
String GetTitle();
|
||||
Windows.Foundation.Size MinimumSize { get; };
|
||||
|
||||
// Other things we'll need:
|
||||
// * bool IsFocused();
|
||||
// * void Focus()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ Pane::Pane(const GUID& profile, const IControlHost& control, const bool lastFocu
|
|||
_lastFocused{ lastFocused },
|
||||
_profile{ profile }
|
||||
{
|
||||
_root.Children().Append(_control.GetControl());
|
||||
_root.Children().Append(_control.GetRoot());
|
||||
_connectionClosedToken = _control.CloseRequested({ this, &Pane::_ControlClosedHandler2 });
|
||||
|
||||
// Set the background of the pane to match that of the theme's default grid
|
||||
|
@ -596,7 +596,7 @@ void Pane::_CloseChild(const bool closeFirst)
|
|||
_separatorRoot = { nullptr };
|
||||
|
||||
// Reattach the TermControl to our grid.
|
||||
_root.Children().Append(_control.GetControl());
|
||||
_root.Children().Append(_control.GetRoot());
|
||||
|
||||
if (_lastFocused)
|
||||
{
|
||||
|
|
43
src/cascadia/TerminalApp/RichTextBoxControlHost.cpp
Normal file
43
src/cascadia/TerminalApp/RichTextBoxControlHost.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "pch.h"
|
||||
#include "RichTextBoxControlHost.h"
|
||||
#include "RichTextBoxControlHost.g.cpp"
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
|
||||
namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
RichTextBoxControlHost::RichTextBoxControlHost()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
Windows::UI::Xaml::Controls::Control RichTextBoxControlHost::GetControl()
|
||||
{
|
||||
return _Editor();
|
||||
}
|
||||
|
||||
Windows::UI::Xaml::UIElement RichTextBoxControlHost::GetRoot()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RichTextBoxControlHost::Close()
|
||||
{
|
||||
throw hresult_not_implemented();
|
||||
}
|
||||
|
||||
hstring RichTextBoxControlHost::GetTitle()
|
||||
{
|
||||
return L"foo";
|
||||
}
|
||||
|
||||
winrt::Windows::Foundation::Size RichTextBoxControlHost::MinimumSize() const
|
||||
{
|
||||
return { 32, 32 };
|
||||
}
|
||||
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(RichTextBoxControlHost, CloseRequested, _closeRequestedHandlers, TerminalApp::IControlHost, TerminalApp::ClosedEventArgs);
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(RichTextBoxControlHost, TitleChanged, _titleChangedHandlers, TerminalApp::IControlHost, Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
|
||||
}
|
29
src/cascadia/TerminalApp/RichTextBoxControlHost.h
Normal file
29
src/cascadia/TerminalApp/RichTextBoxControlHost.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include "RichTextBoxControlHost.g.h"
|
||||
#include "../../cascadia/inc/cppwinrt_utils.h"
|
||||
|
||||
namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
struct RichTextBoxControlHost : RichTextBoxControlHostT<RichTextBoxControlHost>
|
||||
{
|
||||
RichTextBoxControlHost();
|
||||
|
||||
Windows::UI::Xaml::Controls::Control GetControl();
|
||||
Windows::UI::Xaml::UIElement GetRoot();
|
||||
void Close();
|
||||
hstring GetTitle();
|
||||
Windows::Foundation::Size MinimumSize() const;
|
||||
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CloseRequested, _closeRequestedHandlers, TerminalApp::IControlHost, TerminalApp::ClosedEventArgs);
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangedHandlers, TerminalApp::IControlHost, Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
|
||||
|
||||
// private:
|
||||
// winrt::Windows::UI::Xaml::Controls::RichEditBox _textBox{ nullptr };
|
||||
};
|
||||
}
|
||||
namespace winrt::TerminalApp::factory_implementation
|
||||
{
|
||||
struct RichTextBoxControlHost : RichTextBoxControlHostT<RichTextBoxControlHost, implementation::RichTextBoxControlHost>
|
||||
{
|
||||
};
|
||||
}
|
19
src/cascadia/TerminalApp/RichTextBoxControlHost.idl
Normal file
19
src/cascadia/TerminalApp/RichTextBoxControlHost.idl
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Even though this is in the same directory, we're building from a child
|
||||
// directory, so the midl compiler gets confused. TODO: This shouldn't need the
|
||||
// "../". Maybe there's a build rule we can add (gross) or we can just live with
|
||||
// it.
|
||||
import "../IControlHost.idl";
|
||||
|
||||
namespace TerminalApp
|
||||
{
|
||||
// I can't tell you how important it is that the base class of your custom
|
||||
// element is the UIElement that's at the root of the xaml file.
|
||||
[default_interface] runtimeclass RichTextBoxControlHost : Windows.UI.Xaml.Controls.Grid, IControlHost
|
||||
{
|
||||
RichTextBoxControlHost();
|
||||
};
|
||||
|
||||
}
|
118
src/cascadia/TerminalApp/RichTextBoxControlHost.xaml
Normal file
118
src/cascadia/TerminalApp/RichTextBoxControlHost.xaml
Normal file
|
@ -0,0 +1,118 @@
|
|||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
|
||||
the MIT License. See LICENSE in the project root for license information. -->
|
||||
<Grid
|
||||
x:Class="TerminalApp.RichTextBoxControlHost"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:TerminalApp"
|
||||
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:Name="_Root"
|
||||
Background="{ThemeResource SystemChromeLowColor}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<!-- <Grid.Resources>
|
||||
<Style TargetType="AppBarButton">
|
||||
<Setter Property="IsCompact" Value="True"/>
|
||||
</Style>
|
||||
</Grid.Resources> -->
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<RelativePanel
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Stretch">
|
||||
<!-- <RelativePanel.Resources>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Margin" Value="0,0,8,0" />
|
||||
</Style>
|
||||
</RelativePanel.Resources> -->
|
||||
<!-- <Button
|
||||
x:Name="openFileButton"
|
||||
AutomationProperties.Name="Open file"
|
||||
ToolTipService.ToolTip="Open file">
|
||||
<Button.Content>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button> -->
|
||||
<!-- <Button
|
||||
x:Name="saveFileButton"
|
||||
AutomationProperties.Name="Save file"
|
||||
ToolTipService.ToolTip="Save file"
|
||||
RelativePanel.RightOf="openFileButton">
|
||||
<Button.Content>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button> -->
|
||||
<Button
|
||||
x:Name="_CloseButton"
|
||||
Background="Transparent"
|
||||
AutomationProperties.Name="Close"
|
||||
ToolTipService.ToolTip="Close"
|
||||
RelativePanel.AlignRightWithPanel="True">
|
||||
<Button.Content>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</RelativePanel>
|
||||
|
||||
<!-- <StackPanel
|
||||
Grid.Row="0"
|
||||
Orientation="Horizontal">
|
||||
<AppBarButton x:Name="_OpenFileButton"
|
||||
Icon="OpenFile"/>
|
||||
|
||||
<AppBarButton Icon="Save"
|
||||
Margin="8,0,0,0"/>
|
||||
|
||||
<AppBarButton Icon="Bold"
|
||||
Margin="0,0,8,0"/>
|
||||
|
||||
<AppBarButton x:Name="_ItalicButton"
|
||||
Icon="Italic"
|
||||
Margin="0,0,8,0"/>
|
||||
|
||||
<AppBarButton x:Name="_UnderlineButton"
|
||||
Icon="Underline"/>
|
||||
|
||||
</StackPanel> -->
|
||||
|
||||
|
||||
<!-- <StackPanel
|
||||
Grid.Row="0"
|
||||
Orientation="Horizontal">
|
||||
<Button>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button>
|
||||
|
||||
<Button>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button>
|
||||
|
||||
<Button>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button>
|
||||
|
||||
<Button>
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button>
|
||||
|
||||
</StackPanel> -->
|
||||
<!-- <Button
|
||||
Grid.Row="0">
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
Foo
|
||||
</Button> -->
|
||||
<!-- <TextBlock>Foo</TextBlock> -->
|
||||
|
||||
<RichEditBox x:Name="_Editor"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Stretch"
|
||||
/>
|
||||
</Grid>
|
|
@ -15,6 +15,11 @@ namespace winrt::TerminalApp::implementation
|
|||
return _control.GetControl();
|
||||
}
|
||||
|
||||
Windows::UI::Xaml::UIElement TermControlHost::GetRoot()
|
||||
{
|
||||
return _control.GetControl();
|
||||
}
|
||||
|
||||
void TermControlHost::Close()
|
||||
{
|
||||
_control.Close();
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace winrt::TerminalApp::implementation
|
|||
TermControlHost(Microsoft::Terminal::TerminalControl::TermControl control);
|
||||
|
||||
Windows::UI::Xaml::Controls::Control GetControl();
|
||||
Windows::UI::Xaml::UIElement GetRoot();
|
||||
|
||||
void Close();
|
||||
hstring GetTitle();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "pch.h"
|
||||
#include "TextBlockControlHost.h"
|
||||
#include "TextBlockControlHost.g.cpp"
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
#include "TextBlockControlHost.g.cpp"
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
|
||||
namespace winrt::TerminalApp::implementation
|
||||
|
@ -21,6 +21,11 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
return _textBox;
|
||||
}
|
||||
Windows::UI::Xaml::UIElement TextBlockControlHost::GetRoot()
|
||||
{
|
||||
return _textBox;
|
||||
}
|
||||
|
||||
void TextBlockControlHost::Close()
|
||||
{
|
||||
throw hresult_not_implemented();
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace winrt::TerminalApp::implementation
|
|||
TextBlockControlHost();
|
||||
|
||||
Windows::UI::Xaml::Controls::Control GetControl();
|
||||
Windows::UI::Xaml::UIElement GetRoot();
|
||||
void Close();
|
||||
hstring GetTitle();
|
||||
Windows::Foundation::Size MinimumSize() const;
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
<Page Include="../TerminalPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="../RichTextBoxControlHost.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- ========================= Headers ======================== -->
|
||||
|
@ -47,6 +50,10 @@
|
|||
<DependentUpon>../TerminalPage.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="../RichTextBoxControlHost.h">
|
||||
<DependentUpon>../RichTextBoxControlHost.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="../Tab.h" />
|
||||
<ClInclude Include="../Pane.h" />
|
||||
<ClInclude Include="../ColorScheme.h" />
|
||||
|
@ -80,6 +87,10 @@
|
|||
<DependentUpon>../TerminalPage.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="../RichTextBoxControlHost.cpp">
|
||||
<DependentUpon>../RichTextBoxControlHost.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="../Tab.cpp" />
|
||||
<ClCompile Include="../Pane.cpp" />
|
||||
<ClCompile Include="../ColorScheme.cpp" />
|
||||
|
@ -130,6 +141,10 @@
|
|||
<DependentUpon>../TerminalPage.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Midl>
|
||||
<Midl Include="../RichTextBoxControlHost.idl">
|
||||
<DependentUpon>../RichTextBoxControlHost.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Midl>
|
||||
<Midl Include="../IControlHost.idl" />
|
||||
<Midl Include="../TermControlHost.idl" />
|
||||
<Midl Include="../TextBlockControlHost.idl" />
|
||||
|
|
Loading…
Reference in a new issue