Move events out of TermControl.h ; Use TYPED_EVENT in more places (#9526)

This is a small refactor on my way to much bigger, more painful refactors. This PR does five things:

* `TermControl.*` has historically had all the control-relevant EventArgs defined in the same file as TermControl. That's just added clutter to the files, clutter that could have been in it's own place.  We'll move all those event arg to their own files. 
* We'll also move `IDirectKeyListener` to its own file while we're at it.
* We'll update some of `TermControl`'s old `DEFINE`/`DECLARE_TYPED_EVENT` macros to the newer `TYPED_EVENT` macro, which is a bit nicer. 
* We'll change `TermControl.TitleChanged` to a typed event. I needed that for a future PR, so let's just do it here
* While we're updating `TYPED_EVENT` macros, let's do `TerminalPage` too.  

### checklist 
* [x] I work here
* [x] This is work for #1256, but we've got a long way to go before that works.
This commit is contained in:
Mike Griese 2021-03-18 17:02:39 -05:00 committed by GitHub
parent 2ed367fb49
commit fb734d166c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 295 additions and 226 deletions

View file

@ -1016,7 +1016,7 @@ namespace winrt::TerminalApp::implementation
void AppLogic::_ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme)
{
// Propagate the event to the host layer, so it can update its own UI
_requestedThemeChangedHandlers(*this, newTheme);
_RequestedThemeChangedHandlers(*this, newTheme);
}
UIElement AppLogic::GetRoot() noexcept
@ -1369,8 +1369,4 @@ namespace winrt::TerminalApp::implementation
return _root ? _root->AlwaysOnTop() : false;
}
// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(AppLogic, RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
}

View file

@ -83,7 +83,7 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
TYPED_EVENT(RequestedThemeChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
private:
bool _isUwp{ false };

View file

@ -27,18 +27,18 @@ namespace winrt::TerminalApp::implementation
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
RoutedEventArgs const& e)
{
_minimizeClickHandlers(*this, e);
_MinimizeClickHandlers(*this, e);
}
void MinMaxCloseControl::_MaximizeClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
RoutedEventArgs const& e)
{
_maximizeClickHandlers(*this, e);
_MaximizeClickHandlers(*this, e);
}
void MinMaxCloseControl::_CloseClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
RoutedEventArgs const& e)
{
_closeClickHandlers(*this, e);
_CloseClickHandlers(*this, e);
}
void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
@ -95,9 +95,4 @@ namespace winrt::TerminalApp::implementation
break;
}
}
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
}

View file

@ -27,9 +27,9 @@ namespace winrt::TerminalApp::implementation
void _CloseClick(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(MinimizeClick, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(MaximizeClick, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(CloseClick, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
};
}

View file

@ -312,7 +312,7 @@ bool Pane::NavigateFocus(const FocusDirection& direction)
// - <none>
// Return Value:
// - <none>
void Pane::_ControlConnectionStateChangedHandler(const TermControl& /*sender*/,
void Pane::_ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const winrt::Windows::Foundation::IInspectable& /*args*/)
{
std::unique_lock lock{ _createCloseLock };

View file

@ -145,7 +145,7 @@ private:
winrt::fire_and_forget _CloseChildRoutine(const bool closeFirst);
void _FocusFirstChild();
void _ControlConnectionStateChangedHandler(const winrt::Microsoft::Terminal::Control::TermControl& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
void _ControlConnectionStateChangedHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& /*args*/);
void _ControlWarningBellHandler(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::Foundation::IInspectable const& e);
void _ControlGotFocusHandler(winrt::Windows::Foundation::IInspectable const& sender,

View file

@ -188,7 +188,7 @@ namespace winrt::TerminalApp::implementation
}
// Inform the host that our titlebar content has changed.
_setTitleBarContentHandlers(*this, _tabRow);
_SetTitleBarContentHandlers(*this, _tabRow);
}
// Hookup our event handlers to the ShortcutActionDispatch
@ -872,7 +872,7 @@ namespace winrt::TerminalApp::implementation
if (page && tab)
{
page->_raiseVisualBellHandlers(nullptr, nullptr);
page->_RaiseVisualBellHandlers(nullptr, nullptr);
}
});
@ -1211,7 +1211,7 @@ namespace winrt::TerminalApp::implementation
if (_settings.GlobalSettings().ShowTitleInTitlebar() && tab == _GetFocusedTab())
{
_titleChangeHandlers(*this, newTabTitle);
_TitleChangedHandlers(*this, newTabTitle);
}
}
@ -1377,7 +1377,7 @@ namespace winrt::TerminalApp::implementation
// To close the window here, we need to close the hosting window.
if (_tabs.Size() == 0)
{
_lastTabClosedHandlers(*this, nullptr);
_LastTabClosedHandlers(*this, nullptr);
}
else if (focusedTabIndex.has_value() && focusedTabIndex.value() == gsl::narrow_cast<uint32_t>(tabIndex))
{
@ -2352,7 +2352,7 @@ namespace winrt::TerminalApp::implementation
// - eventArgs: the arguments specifying how to set the progress indicator
void TerminalPage::_SetTaskbarProgressHandler(const IInspectable /*sender*/, const IInspectable /*eventArgs*/)
{
_setTaskbarProgressHandlers(*this, nullptr);
_SetTaskbarProgressHandlers(*this, nullptr);
}
// Method Description:
@ -2490,7 +2490,7 @@ namespace winrt::TerminalApp::implementation
// Raise an event that our title changed
if (_settings.GlobalSettings().ShowTitleInTitlebar())
{
_titleChangeHandlers(*this, tab.Title());
_TitleChangedHandlers(*this, tab.Title());
}
}
CATCH_LOG();
@ -2628,7 +2628,7 @@ namespace winrt::TerminalApp::implementation
// will let the user hot-reload this setting, but any runtime changes to
// the alwaysOnTop setting will be lost.
_isAlwaysOnTop = _settings.GlobalSettings().AlwaysOnTop();
_alwaysOnTopChangedHandlers(*this, nullptr);
_AlwaysOnTopChangedHandlers(*this, nullptr);
// Settings AllowDependentAnimations will affect whether animations are
// enabled application-wide, so we don't need to check it each time we
@ -2807,7 +2807,7 @@ namespace winrt::TerminalApp::implementation
{
_isInFocusMode = !_isInFocusMode;
_UpdateTabView();
_focusModeChangedHandlers(*this, nullptr);
_FocusModeChangedHandlers(*this, nullptr);
}
// Method Description:
@ -2821,7 +2821,7 @@ namespace winrt::TerminalApp::implementation
{
_isFullscreen = !_isFullscreen;
_UpdateTabView();
_fullscreenChangedHandlers(*this, nullptr);
_FullscreenChangedHandlers(*this, nullptr);
}
// Method Description:
@ -2833,7 +2833,7 @@ namespace winrt::TerminalApp::implementation
void TerminalPage::ToggleAlwaysOnTop()
{
_isAlwaysOnTop = !_isAlwaysOnTop;
_alwaysOnTopChangedHandlers(*this, nullptr);
_AlwaysOnTopChangedHandlers(*this, nullptr);
}
// Method Description:
@ -3340,16 +3340,4 @@ namespace winrt::TerminalApp::implementation
}
}
}
// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, UIElement);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FocusModeChanged, _focusModeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, FullscreenChanged, _fullscreenChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, AlwaysOnTopChanged, _alwaysOnTopChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, RaiseVisualBell, _raiseVisualBellHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TerminalPage, SetTaskbarProgress, _setTaskbarProgressHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
}

View file

@ -6,9 +6,6 @@
#include "TerminalPage.g.h"
#include "TerminalTab.h"
#include "AppKeyBindings.h"
#include <winrt/Microsoft.Terminal.Control.h>
#include "AppCommandlineArgs.h"
static constexpr uint32_t DefaultRowsToScroll{ 3 };
@ -85,15 +82,15 @@ namespace winrt::TerminalApp::implementation
const winrt::hstring cwd = L"");
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangeHandlers, winrt::Windows::Foundation::IInspectable, winrt::hstring);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(LastTabClosed, _lastTabClosedHandlers, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTitleBarContent, _setTitleBarContentHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(FocusModeChanged, _focusModeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(FullscreenChanged, _fullscreenChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(AlwaysOnTopChanged, _alwaysOnTopChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RaiseVisualBell, _raiseVisualBellHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTaskbarProgress, _setTaskbarProgressHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(Initialized, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(TitleChanged, IInspectable, winrt::hstring);
TYPED_EVENT(LastTabClosed, IInspectable, winrt::TerminalApp::LastTabClosedEventArgs);
TYPED_EVENT(SetTitleBarContent, IInspectable, winrt::Windows::UI::Xaml::UIElement);
TYPED_EVENT(FocusModeChanged, IInspectable, IInspectable);
TYPED_EVENT(FullscreenChanged, IInspectable, IInspectable);
TYPED_EVENT(AlwaysOnTopChanged, IInspectable, IInspectable);
TYPED_EVENT(RaiseVisualBell, IInspectable, IInspectable);
TYPED_EVENT(SetTaskbarProgress, IInspectable, IInspectable);
TYPED_EVENT(Initialized, IInspectable, winrt::Windows::UI::Xaml::RoutedEventArgs);
private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
@ -336,7 +333,5 @@ namespace winrt::TerminalApp::implementation
namespace winrt::TerminalApp::factory_implementation
{
struct TerminalPage : TerminalPageT<TerminalPage, implementation::TerminalPage>
{
};
BASIC_FACTORY(TerminalPage);
}

View file

@ -542,7 +542,7 @@ namespace winrt::TerminalApp::implementation
{
auto weakThis{ get_weak() };
control.TitleChanged([weakThis](auto newTitle) {
control.TitleChanged([weakThis](auto&&, auto&&) {
// Check if Tab's lifetime has expired
if (auto tab{ weakThis.get() })
{

View file

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "EventArgs.h"
#include "TitleChangedEventArgs.g.cpp"
#include "CopyToClipboardEventArgs.g.cpp"
#include "PasteFromClipboardEventArgs.g.cpp"
#include "OpenHyperlinkEventArgs.g.cpp"
#include "NoticeEventArgs.g.cpp"
#include "ScrollPositionChangedArgs.g.cpp"
#include "RendererWarningArgs.g.cpp"

View file

@ -0,0 +1,129 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "TitleChangedEventArgs.g.h"
#include "CopyToClipboardEventArgs.g.h"
#include "PasteFromClipboardEventArgs.g.h"
#include "OpenHyperlinkEventArgs.g.h"
#include "NoticeEventArgs.g.h"
#include "ScrollPositionChangedArgs.g.h"
#include "RendererWarningArgs.g.h"
#include "cppwinrt_utils.h"
namespace winrt::Microsoft::Terminal::Control::implementation
{
struct TitleChangedEventArgs :
public TitleChangedEventArgsT<TitleChangedEventArgs>
{
public:
TitleChangedEventArgs(hstring title) :
_Title(title) {}
WINRT_PROPERTY(hstring, Title);
};
struct CopyToClipboardEventArgs :
public CopyToClipboardEventArgsT<CopyToClipboardEventArgs>
{
public:
CopyToClipboardEventArgs(hstring text) :
_text(text),
_html(),
_rtf(),
_formats(static_cast<CopyFormat>(0)) {}
CopyToClipboardEventArgs(hstring text, hstring html, hstring rtf, Windows::Foundation::IReference<CopyFormat> formats) :
_text(text),
_html(html),
_rtf(rtf),
_formats(formats) {}
hstring Text() { return _text; };
hstring Html() { return _html; };
hstring Rtf() { return _rtf; };
Windows::Foundation::IReference<CopyFormat> Formats() { return _formats; };
private:
hstring _text;
hstring _html;
hstring _rtf;
Windows::Foundation::IReference<CopyFormat> _formats;
};
struct PasteFromClipboardEventArgs :
public PasteFromClipboardEventArgsT<PasteFromClipboardEventArgs>
{
public:
PasteFromClipboardEventArgs(std::function<void(std::wstring)> clipboardDataHandler) :
m_clipboardDataHandler(clipboardDataHandler) {}
void HandleClipboardData(hstring value)
{
m_clipboardDataHandler(static_cast<std::wstring>(value));
};
private:
std::function<void(std::wstring)> m_clipboardDataHandler;
};
struct OpenHyperlinkEventArgs :
public OpenHyperlinkEventArgsT<OpenHyperlinkEventArgs>
{
public:
OpenHyperlinkEventArgs(hstring uri) :
_uri(uri) {}
hstring Uri() { return _uri; };
private:
hstring _uri;
};
struct NoticeEventArgs :
public NoticeEventArgsT<NoticeEventArgs>
{
public:
NoticeEventArgs(const NoticeLevel level, const hstring& message) :
_level(level),
_message(message) {}
NoticeLevel Level() { return _level; };
hstring Message() { return _message; };
private:
const NoticeLevel _level;
const hstring _message;
};
struct ScrollPositionChangedArgs :
public ScrollPositionChangedArgsT<ScrollPositionChangedArgs>
{
public:
ScrollPositionChangedArgs(const int viewTop,
const int viewHeight,
const int bufferSize) :
_ViewTop(viewTop),
_ViewHeight(viewHeight),
_BufferSize(bufferSize)
{
}
WINRT_PROPERTY(int32_t, ViewTop);
WINRT_PROPERTY(int32_t, ViewHeight);
WINRT_PROPERTY(int32_t, BufferSize);
};
struct RendererWarningArgs :
public RendererWarningArgsT<RendererWarningArgs>
{
public:
RendererWarningArgs(const uint64_t hr) :
_Result(hr)
{
}
WINRT_PROPERTY(uint64_t, Result);
};
}

View file

@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace Microsoft.Terminal.Control
{
delegate void FontSizeChangedEventArgs(Int32 width, Int32 height, Boolean isInitialChange);
delegate void ScrollPositionChangedEventArgs(Int32 viewTop, Int32 viewHeight, Int32 bufferLength);
[flags]
enum CopyFormat
{
HTML = 0x1,
RTF = 0x2,
All = 0xffffffff
};
runtimeclass CopyToClipboardEventArgs
{
String Text { get; };
String Html { get; };
String Rtf { get; };
Windows.Foundation.IReference<CopyFormat> Formats { get; };
}
runtimeclass TitleChangedEventArgs
{
String Title;
}
runtimeclass PasteFromClipboardEventArgs
{
void HandleClipboardData(String data);
}
runtimeclass OpenHyperlinkEventArgs
{
String Uri { get; };
}
enum NoticeLevel
{
Debug = 10,
Info = 20,
Warning = 30,
Error = 40,
};
runtimeclass NoticeEventArgs
{
NoticeLevel Level { get; };
String Message { get; };
}
runtimeclass ScrollPositionChangedArgs
{
Int32 ViewTop { get; };
Int32 ViewHeight { get; };
Int32 BufferSize { get; };
}
runtimeclass RendererWarningArgs
{
UInt64 Result { get; };
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace Microsoft.Terminal.Control
{
// C++/winrt makes it difficult to share this idl between two projects,
// Instead, we just pin the uuid and include it in both TermControl and App
// If you update this one, please update TerminalApp\IDirectKeyListener.idl.
// If you change this interface, please update the guid.
// If you press F7 or Alt and get a runtime error, go make sure both copies are the same.
[uuid("0ddf4edc-3fda-4dee-97ca-a417ee3dd510")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, UInt8 scanCode, Boolean down);
};
}

View file

@ -704,7 +704,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
auto noticeArgs = winrt::make<NoticeEventArgs>(NoticeLevel::Warning, std::move(message));
control->_raiseNoticeHandlers(*control, std::move(noticeArgs));
control->_RaiseNoticeHandlers(*control, std::move(noticeArgs));
}
}
@ -2134,7 +2134,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
co_await strong->Dispatcher();
auto noticeArgs = winrt::make<NoticeEventArgs>(NoticeLevel::Warning, std::move(msg));
strong->_raiseNoticeHandlers(*strong, std::move(noticeArgs));
strong->_RaiseNoticeHandlers(*strong, std::move(noticeArgs));
}();
}
@ -2399,7 +2399,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_TerminalTitleChanged(const std::wstring_view& wstr)
{
_titleChangedHandlers(winrt::hstring{ wstr });
_TitleChangedHandlers(*this, winrt::make<TitleChangedEventArgs>(winrt::hstring{ wstr }));
}
void TermControl::_TerminalTabColorChanged(const std::optional<til::color> /*color*/)
{
@ -2409,7 +2409,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_CopyToClipboard(const std::wstring_view& wstr)
{
auto copyArgs = winrt::make_self<CopyToClipboardEventArgs>(winrt::hstring(wstr));
_clipboardCopyHandlers(*this, *copyArgs);
_CopyToClipboardHandlers(*this, *copyArgs);
}
// Method Description:
@ -2540,7 +2540,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::to_hstring(htmlData),
winrt::to_hstring(rtfData),
formats);
_clipboardCopyHandlers(*this, *copyArgs);
_CopyToClipboardHandlers(*this, *copyArgs);
return true;
}
@ -2554,7 +2554,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);
// send paste event up to TermApp
_clipboardPasteHandlers(*this, *pasteArgs);
_PasteFromClipboardHandlers(*this, *pasteArgs);
}
// Method Description:
@ -3226,7 +3226,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
co_await Dispatcher();
auto hyperlinkArgs = winrt::make_self<OpenHyperlinkEventArgs>(heldUri);
_openHyperlinkHandlers(*strongThis, *hyperlinkArgs);
_OpenHyperlinkHandlers(*strongThis, *hyperlinkArgs);
}
// Method Description:
@ -3271,7 +3271,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::fire_and_forget TermControl::TaskbarProgressChanged()
{
co_await resume_foreground(Dispatcher(), CoreDispatcherPriority::High);
_setTaskbarProgressHandlers(*this, nullptr);
_SetTaskbarProgressHandlers(*this, nullptr);
}
// Method Description:
@ -3317,7 +3317,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (auto control{ weakThis.get() })
{
auto noticeArgs = winrt::make<NoticeEventArgs>(NoticeLevel::Info, RS_(L"TermControlReadOnly"));
control->_raiseNoticeHandlers(*control, std::move(noticeArgs));
control->_RaiseNoticeHandlers(*control, std::move(noticeArgs));
}
}
@ -3392,14 +3392,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
DEFINE_EVENT(TermControl, TitleChanged, _titleChangedHandlers, Control::TitleChangedEventArgs);
DEFINE_EVENT(TermControl, FontSizeChanged, _fontSizeChangedHandlers, Control::FontSizeChangedEventArgs);
DEFINE_EVENT(TermControl, ScrollPositionChanged, _scrollPositionChangedHandlers, Control::ScrollPositionChangedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, PasteFromClipboard, _clipboardPasteHandlers, Control::TermControl, Control::PasteFromClipboardEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, CopyToClipboard, _clipboardCopyHandlers, Control::TermControl, Control::CopyToClipboardEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, OpenHyperlink, _openHyperlinkHandlers, Control::TermControl, Control::OpenHyperlinkEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, SetTaskbarProgress, _setTaskbarProgressHandlers, Control::TermControl, IInspectable);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(TermControl, RaiseNotice, _raiseNoticeHandlers, Control::TermControl, Control::NoticeEventArgs);
// clang-format on
}

View file

@ -4,12 +4,7 @@
#pragma once
#include "TermControl.g.h"
#include "CopyToClipboardEventArgs.g.h"
#include "PasteFromClipboardEventArgs.g.h"
#include "OpenHyperlinkEventArgs.g.h"
#include "NoticeEventArgs.g.h"
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
#include <winrt/Microsoft.Terminal.Core.h>
#include "EventArgs.h"
#include "../../renderer/base/Renderer.hpp"
#include "../../renderer/dx/DxRenderer.hpp"
#include "../../renderer/uia/UiaRenderer.hpp"
@ -26,79 +21,6 @@ namespace Microsoft::Console::VirtualTerminal
namespace winrt::Microsoft::Terminal::Control::implementation
{
struct CopyToClipboardEventArgs :
public CopyToClipboardEventArgsT<CopyToClipboardEventArgs>
{
public:
CopyToClipboardEventArgs(hstring text) :
_text(text),
_html(),
_rtf(),
_formats(static_cast<CopyFormat>(0)) {}
CopyToClipboardEventArgs(hstring text, hstring html, hstring rtf, Windows::Foundation::IReference<CopyFormat> formats) :
_text(text),
_html(html),
_rtf(rtf),
_formats(formats) {}
hstring Text() { return _text; };
hstring Html() { return _html; };
hstring Rtf() { return _rtf; };
Windows::Foundation::IReference<CopyFormat> Formats() { return _formats; };
private:
hstring _text;
hstring _html;
hstring _rtf;
Windows::Foundation::IReference<CopyFormat> _formats;
};
struct PasteFromClipboardEventArgs :
public PasteFromClipboardEventArgsT<PasteFromClipboardEventArgs>
{
public:
PasteFromClipboardEventArgs(std::function<void(std::wstring)> clipboardDataHandler) :
m_clipboardDataHandler(clipboardDataHandler) {}
void HandleClipboardData(hstring value)
{
m_clipboardDataHandler(static_cast<std::wstring>(value));
};
private:
std::function<void(std::wstring)> m_clipboardDataHandler;
};
struct OpenHyperlinkEventArgs :
public OpenHyperlinkEventArgsT<OpenHyperlinkEventArgs>
{
public:
OpenHyperlinkEventArgs(hstring uri) :
_uri(uri) {}
hstring Uri() { return _uri; };
private:
hstring _uri;
};
struct NoticeEventArgs :
public NoticeEventArgsT<NoticeEventArgs>
{
public:
NoticeEventArgs(const NoticeLevel level, const hstring& message) :
_level(level),
_message(message) {}
NoticeLevel Level() { return _level; };
hstring Message() { return _message; };
private:
const NoticeLevel _level;
const hstring _message;
};
struct TermControl : TermControlT<TermControl>
{
TermControl(IControlSettings settings, TerminalConnection::ITerminalConnection connection);
@ -172,18 +94,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// clang-format off
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT(TitleChanged, _titleChangedHandlers, Control::TitleChangedEventArgs);
DECLARE_EVENT(FontSizeChanged, _fontSizeChangedHandlers, Control::FontSizeChangedEventArgs);
DECLARE_EVENT(ScrollPositionChanged, _scrollPositionChangedHandlers, Control::ScrollPositionChangedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(PasteFromClipboard, _clipboardPasteHandlers, Control::TermControl, Control::PasteFromClipboardEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CopyToClipboard, _clipboardCopyHandlers, Control::TermControl, Control::CopyToClipboardEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(OpenHyperlink, _openHyperlinkHandlers, Control::TermControl, Control::OpenHyperlinkEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTaskbarProgress, _setTaskbarProgressHandlers, Control::TermControl, IInspectable);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RaiseNotice, _raiseNoticeHandlers, Control::TermControl, Control::NoticeEventArgs);
TYPED_EVENT(TitleChanged, IInspectable, Control::TitleChangedEventArgs);
TYPED_EVENT(PasteFromClipboard, IInspectable, Control::PasteFromClipboardEventArgs);
TYPED_EVENT(CopyToClipboard, IInspectable, Control::CopyToClipboardEventArgs);
TYPED_EVENT(OpenHyperlink, IInspectable, Control::OpenHyperlinkEventArgs);
TYPED_EVENT(SetTaskbarProgress, IInspectable, IInspectable);
TYPED_EVENT(RaiseNotice, IInspectable, Control::NoticeEventArgs);
TYPED_EVENT(WarningBell, IInspectable, IInspectable);
TYPED_EVENT(ConnectionStateChanged, Control::TermControl, IInspectable);
TYPED_EVENT(ConnectionStateChanged, IInspectable, IInspectable);
TYPED_EVENT(Initialized, Control::TermControl, Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(TabColorChanged, IInspectable, IInspectable);
TYPED_EVENT(HidePointerCursor, IInspectable, IInspectable);
@ -358,7 +280,5 @@ namespace winrt::Microsoft::Terminal::Control::implementation
namespace winrt::Microsoft::Terminal::Control::factory_implementation
{
struct TermControl : TermControlT<TermControl, implementation::TermControl>
{
};
BASIC_FACTORY(TermControl);
}

View file

@ -3,61 +3,11 @@
import "IMouseWheelListener.idl";
import "IControlSettings.idl";
import "IDirectKeyListener.idl";
import "EventArgs.idl";
namespace Microsoft.Terminal.Control
{
delegate void TitleChangedEventArgs(String newTitle);
delegate void FontSizeChangedEventArgs(Int32 width, Int32 height, Boolean isInitialChange);
delegate void ScrollPositionChangedEventArgs(Int32 viewTop, Int32 viewHeight, Int32 bufferLength);
// C++/winrt makes it difficult to share this idl between two projects,
// Instead, we just pin the uuid and include it in both TermControl and App
// If you update this one, please update TerminalApp\IDirectKeyListener.idl.
// If you change this interface, please update the guid.
// If you press F7 or Alt and get a runtime error, go make sure both copies are the same.
[uuid("0ddf4edc-3fda-4dee-97ca-a417ee3dd510")] interface IDirectKeyListener {
Boolean OnDirectKeyEvent(UInt32 vkey, UInt8 scanCode, Boolean down);
};
[flags]
enum CopyFormat
{
HTML = 0x1,
RTF = 0x2,
All = 0xffffffff
};
runtimeclass CopyToClipboardEventArgs
{
String Text { get; };
String Html { get; };
String Rtf { get; };
Windows.Foundation.IReference<CopyFormat> Formats { get; };
}
runtimeclass PasteFromClipboardEventArgs
{
void HandleClipboardData(String data);
}
runtimeclass OpenHyperlinkEventArgs
{
String Uri { get; };
}
enum NoticeLevel
{
Debug = 10,
Info = 20,
Warning = 30,
Error = 40,
};
runtimeclass NoticeEventArgs
{
NoticeLevel Level { get; };
String Message { get; };
}
[default_interface] runtimeclass TermControl : Windows.UI.Xaml.Controls.UserControl, IDirectKeyListener, IMouseWheelListener
{
@ -69,21 +19,27 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.Control.IControlSettings Settings { get; };
event TitleChangedEventArgs TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, TitleChangedEventArgs> TitleChanged;
event FontSizeChangedEventArgs FontSizeChanged;
event Windows.Foundation.TypedEventHandler<TermControl, CopyToClipboardEventArgs> CopyToClipboard;
event Windows.Foundation.TypedEventHandler<TermControl, PasteFromClipboardEventArgs> PasteFromClipboard;
event Windows.Foundation.TypedEventHandler<TermControl, OpenHyperlinkEventArgs> OpenHyperlink;
event Windows.Foundation.TypedEventHandler<TermControl, Object> SetTaskbarProgress;
event Windows.Foundation.TypedEventHandler<TermControl, NoticeEventArgs> RaiseNotice;
event Windows.Foundation.TypedEventHandler<Object, CopyToClipboardEventArgs> CopyToClipboard;
event Windows.Foundation.TypedEventHandler<Object, PasteFromClipboardEventArgs> PasteFromClipboard;
event Windows.Foundation.TypedEventHandler<Object, OpenHyperlinkEventArgs> OpenHyperlink;
event Windows.Foundation.TypedEventHandler<Object, Object> SetTaskbarProgress;
event Windows.Foundation.TypedEventHandler<Object, NoticeEventArgs> RaiseNotice;
event Windows.Foundation.TypedEventHandler<Object, Object> WarningBell;
event Windows.Foundation.TypedEventHandler<Object, Object> HidePointerCursor;
event Windows.Foundation.TypedEventHandler<Object, Object> RestorePointerCursor;
event ScrollPositionChangedEventArgs ScrollPositionChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> ReadOnlyChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> FocusFollowMouseRequested;
event Windows.Foundation.TypedEventHandler<TermControl, Windows.UI.Xaml.RoutedEventArgs> Initialized;
// This is an event handler forwarder for the underlying connection.
// We expose this and ConnectionState here so that it might eventually be data bound.
event Windows.Foundation.TypedEventHandler<TermControl, IInspectable> ConnectionStateChanged;
event Windows.Foundation.TypedEventHandler<Object, IInspectable> ConnectionStateChanged;
Microsoft.Terminal.TerminalConnection.ConnectionState ConnectionState { get; };
String Title { get; };
@ -98,7 +54,6 @@ namespace Microsoft.Terminal.Control
void ScrollViewport(Int32 viewTop);
Int32 GetScrollOffset();
Int32 GetViewHeight();
event ScrollPositionChangedEventArgs ScrollPositionChanged;
void CreateSearchBoxControl();
@ -117,11 +72,8 @@ namespace Microsoft.Terminal.Control
String WorkingDirectory { get; };
Windows.Foundation.IReference<Windows.UI.Color> TabColor { get; };
event Windows.Foundation.TypedEventHandler<Object, Object> TabColorChanged;
Boolean ReadOnly { get; };
void ToggleReadOnly();
event Windows.Foundation.TypedEventHandler<Object, Object> ReadOnlyChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> FocusFollowMouseRequested;
}
}

View file

@ -28,6 +28,9 @@
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="EventArgs.h">
<DependentUpon>EventArgs.idl</DependentUpon>
</ClInclude>
<ClInclude Include="KeyChord.h">
<DependentUpon>KeyChord.idl</DependentUpon>
</ClInclude>
@ -51,6 +54,9 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="EventArgs.cpp">
<DependentUpon>EventArgs.idl</DependentUpon>
</ClCompile>
<ClCompile Include="init.cpp" />
<ClCompile Include="KeyChord.cpp">
<DependentUpon>KeyChord.idl</DependentUpon>
@ -73,7 +79,9 @@
</ItemGroup>
<!-- ========================= idl Files ======================== -->
<ItemGroup>
<Midl Include="EventArgs.idl" />
<Midl Include="KeyChord.idl" />
<Midl Include="IDirectKeyListener.idl" />
<Midl Include="IKeyBindings.idl" />
<Midl Include="IControlSettings.idl" />
<Midl Include="SearchBoxControl.idl">

View file

@ -48,6 +48,9 @@
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
#include <winrt/Microsoft.Terminal.Core.h>
#include <windows.ui.xaml.media.dxinterop.h>
#include <TraceLoggingProvider.h>