Skip to content

ui::testing::WindowSeams

Header: winui/testing/WindowSeams.hpp.

Installs platform services on a Window: its host, compositor, native host, spell checker and context-menu host. The clipboard and the launcher belong to the whole process instead, so a test swaps them with set_clipboard() and set_launcher().

A window gets these from whatever hosts it. The backend installs the real ones when it creates the native window, and HeadlessUI installs its own. A test uses this to hand the window a test double. Every pointer is non-owning and must outlive the window's use of it; nullptr removes the service. Get one with seams().

Example:

ui::Window                       window;
ui::testing::TestContextMenuHost menu;
ui::testing::seams(window).set_context_menu_host(&menu);

WindowSeams

WindowSeams(Window& window)

The seams of window.

set_window_host

void set_window_host(WindowHost* host)

The host that answers the window's requests (state, title, placement, ...).

window_host

WindowHost* window_host() const

The host set_window_host() installed, or nullptr: none yet, or the window was closed.

set_compositor

void set_compositor(detail::Compositor* compositor)

Where composited overlays (shadows, acrylic) are drawn.

set_native_host

void set_native_host(NativeHost* host)

What creates and places the native windows of NativeControls.

set_spell_checker

void set_spell_checker(SpellChecker* checker)

The spell checker text controls ask.

set_spell_checker_source

void set_spell_checker_source(Callback<SpellChecker* ()> source)

What makes the spell checker the first time a text control needs one.

set_context_menu_host

void set_context_menu_host(ContextMenuHost* host)

What shows a text control's context menu.

set_automation_events

void set_automation_events(AutomationEvents* events)

Where the window reports focus and property changes to automation clients.

handle_close_request

bool handle_close_request()

The user asked to close the window (the close button, Alt+F4). False when on_closing() vetoed it.

handle_closed

void handle_closed()

The native window is gone.

handle_opened

void handle_opened()

The native window exists and is about to show.

handle_menu_access

bool handle_menu_access(char32_t letter)

The menu key: Alt or F10 alone (letter 0), or Alt with a letter nothing else used. True when an element such as a menu bar took it, so the system does nothing more.

report_state

void report_state(WindowState state)

The window's state as the OS has it now.

report_state

void report_state(WindowState state, WindowState restores_to)

report_state() plus where restore() would land (Window::restores_to()), for a host that knows.

report_active

void report_active(bool active)

Whether the window is the active one.

report_scale

void report_scale(float scale)

Device pixels per DIP on the window's monitor.

report_caption_insets

void report_caption_insets(const CaptionInsets& insets)

The room the caption buttons take in a custom title bar.

report_visible

void report_visible(bool visible)

Whether the window is shown.

report_blur_behind

void report_blur_behind(bool active)

Whether the desktop behind the window is blurred for a glass frame.

report_caption_icon

void report_caption_icon(Bitmap icon)

The small icon the OS shows for the window, as pixels.

report_os_theme

void report_os_theme(const OsThemeSnapshot& os)

The OS theme state, at creation and after every change.

handle_system_menu_item

void handle_system_menu_item(std::size_t index)

The user picked the app's item index in the system menu.

handle_thumbnail_button

void handle_thumbnail_button(std::size_t index)

The user clicked taskbar thumbnail button index.

effective_style

WindowStyle effective_style() const

style() with Frame::Themed resolved against the current theme, the style the native window runs with. That is Borderless while the theme draws the frame and Standard when it has none. Every other frame passes through.

drawn_frame_border

float drawn_frame_border() const

The width in DIPs of the border the theme draws, which is also the resize band; 0 when the OS draws the frame.

caption_icon

const Bitmap& caption_icon() const

The icon a caption the theme draws shows when the window's icon() has no image or glyph of its own, as the host reported it; empty until it reports one.

drawn_title_bar

Element* drawn_title_bar() const

The caption the theme draws, as an automation node (a TitleBar holding the caption buttons) for the host to list before the content; nullptr when the OS draws the frame.

wants_blur_behind

bool wants_blur_behind() const

Whether the frame the theme draws is glass and wants the desktop behind the window blurred: Aero's frame, while transparency effects are on and the window is not full screen. The host answers with report_blur_behind().

frame_corner_cut

std::span<const std::uint8_t> frame_corner_cut() const

The rounded top corners of the frame the theme draws, as the pixels to cut off each top corner, one entry per row from the top, at 96 DPI. Empty for a square frame, while the window is maximized or full screen, and while the frame is glass. The host shapes the window with it.

blur_behind

bool blur_behind() const

Whether the host reported the blur as live (report_blur_behind()).

handle_pointer

void handle_pointer(const PointerEvent& e)

A pointer event in client DIPs, routed to popups, the modal layer or the content.

handle_key

bool handle_key(const KeyEvent& e)

A key event, routed to the focused element after shortcuts and Tab navigation.

handle_text

void handle_text(std::string_view text)

Typed text for the focused element.

handle_external_drag_enter

DragResponse handle_external_drag_enter(DataPackage data, Point position)

A drag from another app has come over the window at position, in client DIPs, carrying data. The drop targets there are asked as for a drag inside the app; returns their answer. Refused while a drag inside the app is running.

handle_external_drag_over

DragResponse handle_external_drag_over(Point position, std::optional<DataPackageOperation> requested = std::nullopt)

The drag from another app moved to position; requested replaces the operation the package asks for (the keys held changed it). Returns the answer there.

handle_external_drag_leave

void handle_external_drag_leave()

The drag from another app left the window, or was canceled.

handle_external_drag_drop

DataPackageOperation handle_external_drag_drop(Point position)

The drag from another app was released at position. Returns what the drop did, None when nothing took it.

handle_external_drop

DataPackageOperation handle_external_drop(DataPackage data, Point position)

Files dropped on the window from another app at position, reported only on release: the enter and the drop at once. Returns what the drop did, None when nothing took it.

handle_context_menu

bool handle_context_menu(std::optional<Point> position)

A context-menu request at position, or from the keyboard when nullopt. True when handled.

handle_automation_invoke

bool handle_automation_invoke(Element& element)

An automation client invoking element, as a screen reader does to press a button. True when it was invoked.

handle_native_context_menu

bool handle_native_context_menu(Element& native, std::optional<Point> position)

A context-menu request from a hosted native control. True when handled.

handle_native_content_changed

void handle_native_content_changed(NativeControl& native)

A hosted native control's content changed.

handle_native_notification

bool handle_native_notification(NativeControl& native, NativeNotification& notification)

A notification from a hosted native control. True when the control handled it.