Allow un-handled mouse events to propagate via sigslot event in Window.

This commit is contained in:
casey langen 2022-03-10 22:53:44 -08:00
parent 16f265a116
commit 684f73a18f
20 changed files with 50 additions and 39 deletions

View File

@ -431,7 +431,7 @@ bool TransportWindow::KeyPress(const std::string& kn) {
return false; return false;
} }
bool TransportWindow::MouseEvent(const IMouseHandler::Event& event) { bool TransportWindow::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) { if (event.Button1Clicked()) {
if (this->shufflePos.Contains(event)) { if (this->shufflePos.Contains(event)) {
this->playback.ToggleShuffle(); this->playback.ToggleShuffle();
@ -466,7 +466,7 @@ bool TransportWindow::MouseEvent(const IMouseHandler::Event& event) {
} }
} }
} }
return false; return Window::ProcessMouseEvent(event);
} }
bool TransportWindow::FocusNext() { bool TransportWindow::FocusNext() {

View File

@ -64,11 +64,11 @@ namespace musik {
virtual ~TransportWindow(); virtual ~TransportWindow();
virtual void ProcessMessage(musik::core::runtime::IMessage &message); void ProcessMessage(musik::core::runtime::IMessage &message) override;
virtual void OnFocusChanged(bool focused); void OnFocusChanged(bool focused) override;
virtual void OnRedraw(); void OnRedraw() override;
virtual bool KeyPress(const std::string& key); bool KeyPress(const std::string& key) override;
virtual bool MouseEvent(const IMouseHandler::Event& mouseEvent); bool ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) override;
void SetFocus(FocusTarget target); void SetFocus(FocusTarget target);
FocusTarget GetFocus() const; FocusTarget GetFocus() const;

View File

@ -574,12 +574,12 @@ process:
Event event(rawMouseEvent, window); Event event(rawMouseEvent, window);
if (event.MouseWheelDown() || event.MouseWheelUp()) { if (event.MouseWheelDown() || event.MouseWheelUp()) {
if (state.focused) { if (state.focused) {
state.focused->MouseEvent(event); state.focused->ProcessMouseEvent(event);
} }
} }
else if (mouseButtonState.Update(rawMouseEvent)) { else if (mouseButtonState.Update(rawMouseEvent)) {
event.state = mouseButtonState.ToCursesState(); event.state = mouseButtonState.ToCursesState();
active->MouseEvent(event); active->ProcessMouseEvent(event);
} }
} }
} }

View File

@ -93,11 +93,11 @@ bool Checkbox::KeyPress(const std::string& key) {
return false; return false;
} }
bool Checkbox::MouseEvent(const IMouseHandler::Event& event) { bool Checkbox::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) { if (event.Button1Clicked()) {
this->FocusInParent(); this->FocusInParent();
this->SetChecked(!this->checked); this->SetChecked(!this->checked);
return true; return true;
} }
return false; return TextLabel::ProcessMouseEvent(event);
} }

View File

@ -503,7 +503,7 @@ bool LayoutBase::KeyPress(const std::string& key) {
return false; return false;
} }
bool LayoutBase::MouseEvent(const IMouseHandler::Event& mouseEvent) { bool LayoutBase::ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) {
for (auto window : this->children) { for (auto window : this->children) {
auto x = window->GetX(); auto x = window->GetX();
auto y = window->GetY(); auto y = window->GetY();
@ -513,10 +513,10 @@ bool LayoutBase::MouseEvent(const IMouseHandler::Event& mouseEvent) {
mouseEvent.y >= y && mouseEvent.y < y + cy) mouseEvent.y >= y && mouseEvent.y < y + cy)
{ {
auto relative = IMouseHandler::Event(mouseEvent, window.get()); auto relative = IMouseHandler::Event(mouseEvent, window.get());
if (window->MouseEvent(relative)) { if (window->ProcessMouseEvent(relative)) {
return true; return true;
} }
} }
} }
return false; return Window::ProcessMouseEvent(mouseEvent);
} }

View File

@ -311,9 +311,9 @@ bool ListWindow::KeyPress(const std::string& key) {
return ScrollableWindow::KeyPress(key); return ScrollableWindow::KeyPress(key);
} }
bool ListWindow::MouseEvent(const IMouseHandler::Event& event) { bool ListWindow::ProcessMouseEvent(const IMouseHandler::Event& event) {
/* CAL TODO: this method assumes each row is a single cell tall. */ /* CAL TODO: this method assumes each row is a single cell tall. */
bool result = ScrollableWindow::MouseEvent(event); bool result = ScrollableWindow::ProcessMouseEvent(event);
auto first = this->scrollPosition.firstVisibleEntryIndex; auto first = this->scrollPosition.firstVisibleEntryIndex;

View File

@ -140,7 +140,9 @@ bool ScrollableWindow::KeyPress(const std::string& key) {
return false; return false;
} }
bool ScrollableWindow::MouseEvent(const IMouseHandler::Event& event) { bool ScrollableWindow::ProcessMouseEvent(const IMouseHandler::Event& event) {
const bool result = Window::ProcessMouseEvent(event);
if (event.Button1Clicked()) { if (event.Button1Clicked()) {
this->FocusInParent(); this->FocusInParent();
return true; return true;
@ -153,7 +155,8 @@ bool ScrollableWindow::MouseEvent(const IMouseHandler::Event& event) {
this->PageUp(); this->PageUp();
return true; return true;
} }
return false;
return result;
} }

View File

@ -148,7 +148,7 @@ bool ShortcutsWindow::KeyPress(const std::string& key) {
return false; return false;
} }
bool ShortcutsWindow::MouseEvent(const IMouseHandler::Event& mouseEvent) { bool ShortcutsWindow::ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) {
if (mouseEvent.Button1Clicked()) { if (mouseEvent.Button1Clicked()) {
for (auto entry : this->entries) { for (auto entry : this->entries) {
auto& pos = entry->position; auto& pos = entry->position;
@ -167,7 +167,7 @@ bool ShortcutsWindow::MouseEvent(const IMouseHandler::Event& mouseEvent) {
} }
} }
} }
return false; return Window::ProcessMouseEvent(mouseEvent);
} }
void ShortcutsWindow::OnFocusChanged(bool focused) { void ShortcutsWindow::OnFocusChanged(bool focused) {

View File

@ -279,11 +279,11 @@ void TextInput::SetHint(const std::string& hint) {
this->Redraw(); this->Redraw();
} }
bool TextInput::MouseEvent(const IMouseHandler::Event& event) { bool TextInput::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) { if (event.Button1Clicked()) {
this->position = std::max(0, std::min((int)this->bufferLength, event.x)); this->position = std::max(0, std::min((int)this->bufferLength, event.x));
this->FocusInParent(); this->FocusInParent();
return true; return true;
} }
return false; return Window::ProcessMouseEvent(event);
} }

View File

@ -128,11 +128,11 @@ bool TextLabel::KeyPress(const std::string& key) {
return false; return false;
} }
bool TextLabel::MouseEvent(const IMouseHandler::Event& event) { bool TextLabel::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) { if (event.Button1Clicked()) {
this->FocusInParent(); this->FocusInParent();
this->Activated(this); this->Activated(this);
return true; return true;
} }
return false; return Window::ProcessMouseEvent(event);
} }

View File

@ -967,7 +967,8 @@ void Window::SetNavigationKeys(std::shared_ptr<INavigationKeys> keys) {
::keys = keys; ::keys = keys;
} }
bool Window::MouseEvent(const IMouseHandler::Event& mouseEvent) { bool Window::ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) {
this->MouseEvent(this, &mouseEvent);
return false; return false;
} }

View File

@ -50,12 +50,16 @@ namespace cursespp {
virtual ~Checkbox(); virtual ~Checkbox();
virtual void SetText(const std::string& value);
virtual std::string GetText();
virtual void SetChecked(bool checked); virtual void SetChecked(bool checked);
virtual bool IsChecked() { return this->checked; } virtual bool IsChecked() { return this->checked; }
virtual bool KeyPress(const std::string& key);
virtual bool MouseEvent(const IMouseHandler::Event& event); /* TextLabel */
virtual void SetText(const std::string& value) override;
virtual std::string GetText() override;
/* Window */
bool KeyPress(const std::string& key) override;
bool ProcessMouseEvent(const IMouseHandler::Event& event) override;
private: private:
bool checked; bool checked;

View File

@ -72,6 +72,6 @@ namespace cursespp {
}; };
virtual ~IMouseHandler() { } virtual ~IMouseHandler() { }
virtual bool MouseEvent(const Event& mouseEvent) = 0; virtual bool ProcessMouseEvent(const Event& mouseEvent) = 0;
}; };
} }

View File

@ -96,7 +96,7 @@ namespace cursespp {
bool KeyPress(const std::string& key) override; bool KeyPress(const std::string& key) override;
/* IMouseHandler */ /* IMouseHandler */
bool MouseEvent(const IMouseHandler::Event& mouseEvent) override; bool ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) override;
/* IWindowGroup */ /* IWindowGroup */
bool AddWindow(IWindowPtr window) override; bool AddWindow(IWindowPtr window) override;

View File

@ -70,7 +70,7 @@ namespace cursespp {
const IScrollAdapter::ScrollPosition& GetScrollPosition() override; const IScrollAdapter::ScrollPosition& GetScrollPosition() override;
bool KeyPress(const std::string& key) override; bool KeyPress(const std::string& key) override;
bool MouseEvent(const IMouseHandler::Event& event) override; bool ProcessMouseEvent(const IMouseHandler::Event& event) override;
void SetScrollbarVisible(bool visible); void SetScrollbarVisible(bool visible);
void SetDecorator(Decorator decorator); void SetDecorator(Decorator decorator);

View File

@ -64,7 +64,7 @@ namespace cursespp {
void OnRedraw() override; void OnRedraw() override;
/* IMouseHandler */ /* IMouseHandler */
bool MouseEvent(const IMouseHandler::Event& event) override; bool ProcessMouseEvent(const IMouseHandler::Event& event) override;
/* IScrollable */ /* IScrollable */
void ScrollToTop() override; void ScrollToTop() override;

View File

@ -63,7 +63,7 @@ namespace cursespp {
void SetActive(const std::string& key); void SetActive(const std::string& key);
bool KeyPress(const std::string& key) override; bool KeyPress(const std::string& key) override;
bool MouseEvent(const IMouseHandler::Event& mouseEvent) override; bool ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) override;
protected: protected:
void OnRedraw() override; void OnRedraw() override;

View File

@ -72,7 +72,7 @@ namespace cursespp {
void OnRedraw() override; void OnRedraw() override;
/* IMouseHandler */ /* IMouseHandler */
bool MouseEvent(const IMouseHandler::Event& event) override; bool ProcessMouseEvent(const IMouseHandler::Event& event) override;
/* regular methods we define */ /* regular methods we define */
void SetRawKeyBlacklist(const std::vector<std::string>&& blacklist); void SetRawKeyBlacklist(const std::vector<std::string>&& blacklist);

View File

@ -58,7 +58,7 @@ namespace cursespp {
/* IWindow */ /* IWindow */
void OnRedraw() override; void OnRedraw() override;
bool KeyPress(const std::string& key) override; bool KeyPress(const std::string& key) override;
bool MouseEvent(const IMouseHandler::Event& event) override; bool ProcessMouseEvent(const IMouseHandler::Event& event) override;
/* virtual methods we define */ /* virtual methods we define */
virtual void SetBold(bool bold); virtual void SetBold(bool bold);

View File

@ -38,6 +38,7 @@
#include <cursespp/IWindow.h> #include <cursespp/IWindow.h>
#include <cursespp/INavigationKeys.h> #include <cursespp/INavigationKeys.h>
#include <musikcore/runtime/IMessageQueue.h> #include <musikcore/runtime/IMessageQueue.h>
#include <sigslot/sigslot.h>
#ifdef WIN32 #ifdef WIN32
#if defined(PDCURSES_WINCON) || defined(_CONSOLE) #if defined(PDCURSES_WINCON) || defined(_CONSOLE)
@ -61,6 +62,8 @@ namespace cursespp {
static const int kFirstReservedMessageId; static const int kFirstReservedMessageId;
static const int kLastReservedMessageId; static const int kLastReservedMessageId;
sigslot::signal2<IWindow*, const IMouseHandler::Event*> MouseEvent;
Window(IWindow* parent = nullptr); Window(IWindow* parent = nullptr);
virtual ~Window(); virtual ~Window();
@ -137,7 +140,7 @@ namespace cursespp {
bool HasBadBounds() noexcept { return this->badBounds; } bool HasBadBounds() noexcept { return this->badBounds; }
/* IMouseHandler */ /* IMouseHandler */
bool MouseEvent(const IMouseHandler::Event& mouseEvent) override; bool ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) override;
protected: protected: