From 576f0a53d04ec049875414ab6c0b8e2bf99108df Mon Sep 17 00:00:00 2001 From: scheffle Date: Thu, 15 Feb 2024 15:05:22 +0100 Subject: [PATCH] add find panel to text editor --- vstgui/lib/CMakeLists.txt | 1 + vstgui/lib/ctexteditor.cpp | 581 +++++++++++++++++- vstgui/lib/ctexteditor.h | 16 +- vstgui/lib/enumbitset.h | 115 ++++ .../standalone/source/testappdelegate.cpp | 1 + vstgui/tests/unittest/CMakeLists.txt | 1 + vstgui/tests/unittest/lib/enumbitset_test.cpp | 113 ++++ .../editing/uiattributescontroller.cpp | 11 +- 8 files changed, 805 insertions(+), 34 deletions(-) create mode 100644 vstgui/lib/enumbitset.h create mode 100644 vstgui/tests/unittest/lib/enumbitset_test.cpp diff --git a/vstgui/lib/CMakeLists.txt b/vstgui/lib/CMakeLists.txt index 6397b2e1d..6ce971e4c 100644 --- a/vstgui/lib/CMakeLists.txt +++ b/vstgui/lib/CMakeLists.txt @@ -145,6 +145,7 @@ set(${target}_common_sources cvstguitimer.h dragging.h dispatchlist.h + enumbitset.h events.cpp events.h finally.h diff --git a/vstgui/lib/ctexteditor.cpp b/vstgui/lib/ctexteditor.cpp index d85a58617..139c1429f 100644 --- a/vstgui/lib/ctexteditor.cpp +++ b/vstgui/lib/ctexteditor.cpp @@ -17,6 +17,8 @@ #include "platform/iplatformfont.h" #include "platform/iplatformframe.h" #include "platform/platformfactory.h" +#include "controls/cbuttons.h" +#include "controls/ctextedit.h" #include "animation/timingfunctions.h" #include "animation/animations.h" @@ -134,10 +136,25 @@ struct NewLineProcessor }; struct LineNumberView; +struct FindPanelController; static constexpr CPoint MouseOutsidePos = {std::numeric_limits::max (), std::numeric_limits::max ()}; +//------------------------------------------------------------------------ +struct Key +{ + char16_t character; + VirtualKey virt; + Modifiers modifiers; + + bool operator== (const KeyboardEvent& event) const + { + return event.character == character && event.virt == virt && event.modifiers == modifiers; + } +}; +using CommandKeyArray = std::array (ITextEditor::Command::TakeFocus) + 1>; + //------------------------------------------------------------------------ struct TextEditorView : public CView, public ITextEditor, @@ -218,6 +235,8 @@ struct TextEditorView : public CView, bool handleCommand (Command cmd) const override; bool setCommandKeyBinding (Command cmd, char16_t character, VirtualKey virt, Modifiers modifiers) const override; + void setFindOptions (FindOptions opt) const override; + void setFindString (std::string_view utf8Text) const override; // commandos void selectAll () const; @@ -225,7 +244,11 @@ struct TextEditorView : public CView, bool doCopy () const; bool doPaste () const; bool useSelectionForFind () const; - bool doFind (bool forward = true) const; + bool doFind (bool forward = true, size_t oldPos = String::npos) const; + bool showFindPanel () const; + + String::size_type doFindCaseSensitive (bool forward) const; + String::size_type doFindIgnoreCase (bool forward) const; private: template @@ -267,17 +290,21 @@ struct TextEditorView : public CView, CRect invalidCursorRect () const; void toggleCursorVisibility () const; void restartBlinkTimer () const; + void onStyleChanged () const; + void setFindString (String&& text) const; TextEditorView& mutableThis () const { return *const_cast (this); } +public: //------------------------------------------------------------------------ - mutable struct + struct ModelData { TextModel model; std::shared_ptr