Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions WinUIEditor/EditorBaseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ namespace winrt::WinUIEditor::implementation
const ImageBrush brush{};
brush.ImageSource(virtualSurfaceImageSource);
imageTarget.Background(brush);

_wrapper->SetContainer(imageTarget);
UpdateVisibleArea();
}

#ifndef WINUI3
Expand Down Expand Up @@ -539,6 +542,8 @@ namespace winrt::WinUIEditor::implementation
{
if (_vsisNative)
{
UpdateVisibleArea();

auto width{ ConvertFromDipToPixelUnit(args.NewSize().Width, _dpiScale) };
auto height{ ConvertFromDipToPixelUnit(args.NewSize().Height, _dpiScale) };
_wrapper->Width(width);
Expand All @@ -552,6 +557,7 @@ namespace winrt::WinUIEditor::implementation
{
auto properties{ e.GetCurrentPoint(sender.as<UIElement>()).Properties() };
_scintilla->PointerWheelChanged(properties.MouseWheelDelta(), properties.IsHorizontalMouseWheel(), e.KeyModifiers());
UpdateVisibleArea();
}

void EditorBaseControl::ImageTarget_DragEnter(IInspectable const &sender, DragEventArgs const &e)
Expand Down Expand Up @@ -672,4 +678,35 @@ namespace winrt::WinUIEditor::implementation
_wrapper->TrimDxgiDevice();
}
#endif

void EditorBaseControl::UpdateVisibleArea()
{
auto container = _wrapper->GetContainer();

// Get the XamlRoot associated with the UIElement
auto xamlRoot = XamlRoot();
if (!xamlRoot)
{
throw std::runtime_error("XamlRoot is null. Ensure the element is attached to the visual tree.");
}

// Get the bounds of the UIElement relative to the XamlRoot
auto elementTransform = TransformToVisual(xamlRoot.Content());
Rect elementBounds = elementTransform.TransformBounds(
Rect{ 0, 0, (float)ActualWidth(), (float)ActualHeight() });

// Get the bounds of the XamlRoot
auto xamlRootSize = xamlRoot.Content().ActualSize();
Rect xamlRootBounds{ 0, 0, xamlRootSize.x, xamlRootSize.y };

// Calculate the intersection of the two rectangles
auto intersection = RectHelper::Intersect(elementBounds, xamlRootBounds);

_scintilla->SetVisibleArea(
ConvertFromDipToPixelUnit(intersection.X, _dpiScale),
ConvertFromDipToPixelUnit(intersection.Y, _dpiScale),
ConvertFromDipToPixelUnit(intersection.Width, _dpiScale),
ConvertFromDipToPixelUnit(intersection.Height, _dpiScale)
);
}
}
1 change: 1 addition & 0 deletions WinUIEditor/EditorBaseControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace winrt::WinUIEditor::implementation
Windows::UI::Xaml::Application::Suspending_revoker _suspendingRevoker{};
void Application_Suspending(Windows::Foundation::IInspectable const &sender, Windows::ApplicationModel::SuspendingEventArgs const &args);
#endif
void UpdateVisibleArea();
};
}

Expand Down
10 changes: 10 additions & 0 deletions WinUIEditor/MainWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ namespace WinUIEditor
void MainWrapper::SetPositionRelative(Scintilla::Internal::PRectangle rc, Wrapper const &wrapper)
{
}

void MainWrapper::SetContainer(winrt::DUX::FrameworkElement const& container)
{
_container = container;
}

winrt::DUX::FrameworkElement MainWrapper::GetContainer()
{
return _container;
}
}
5 changes: 5 additions & 0 deletions WinUIEditor/MainWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ namespace WinUIEditor
void Destroy() override;
void SetPositionRelative(Scintilla::Internal::PRectangle rc, Wrapper const &wrapper) override;

void SetContainer(winrt::DUX::FrameworkElement const& container);
winrt::DUX::FrameworkElement MainWrapper::GetContainer();

private:
winrt::DUX::Input::Pointer _lastPointer{ nullptr };
winrt::DUX::UIElement _mouseCaptureElement{ nullptr };
winrt::DUX::Controls::Primitives::ScrollBar _horizontalScrollBar{ nullptr };
winrt::DUX::Controls::Primitives::ScrollBar _verticalScrollBar{ nullptr };
bool _captured{ false };

winrt::DUX::FrameworkElement _container{ nullptr };
};
}
9 changes: 7 additions & 2 deletions scintilla/winui/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ namespace Scintilla::Internal {
paintState = PaintState::painting;
paintingAllText = true;
// Todo: This is in contradiction with the above paragraph about drawing size. But invalidation results in flickering
DrawBit(RECT{ 0, 0, _mainWrapper->Width(), _mainWrapper->Height() });
DrawBit(visibleArea); // draw ony visible area, _mainWrapper->Width() & Height() can be too big
}

paintState = PaintState::notPainting;
Expand Down Expand Up @@ -2651,7 +2651,7 @@ namespace Scintilla::Internal {
_mainWrapper->CreateGraphicsDevices();
InvalidateStyleRedraw(); // just Redraw() does not work
}
else
else if (beginDrawHR == S_OK)
{
const auto &d2dDeviceContext{ _mainWrapper->D2dDeviceContext() };

Expand Down Expand Up @@ -3202,4 +3202,9 @@ namespace Scintilla::Internal {

sisNativeWithD2D->EndDraw();
}

void ScintillaWinUI::SetVisibleArea(LONG x, LONG y, LONG width, LONG height)
{
visibleArea = RECT{ x, y, width, height };
}
}
3 changes: 3 additions & 0 deletions scintilla/winui/ScintillaWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace Scintilla::Internal {
static sptr_t DirectStatusFunction(sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam, int *pStatus);
sptr_t WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) override;

void SetVisibleArea(LONG x, LONG y, LONG width, LONG height);
private:
bool _tsfCore;

Expand Down Expand Up @@ -281,6 +282,8 @@ namespace Scintilla::Internal {
winrt::fire_and_forget DoDragAsync();
int CalculateNotifyMessageUtf16Length(Scintilla::Notification const &code, Scintilla::ModificationFlags const &modFlags, bool notifyTsf, const char *text, Scintilla::Position mbLength);
sptr_t OnSetDocPointer(uptr_t wParam, sptr_t lParam);

RECT visibleArea;
};

class CallTipCallback : public ::winrt::implements<CallTipCallback, ::IVirtualSurfaceUpdatesCallbackNative>
Expand Down