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;
}
bool TransportWindow::MouseEvent(const IMouseHandler::Event& event) {
bool TransportWindow::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) {
if (this->shufflePos.Contains(event)) {
this->playback.ToggleShuffle();
@ -466,7 +466,7 @@ bool TransportWindow::MouseEvent(const IMouseHandler::Event& event) {
}
}
}
return false;
return Window::ProcessMouseEvent(event);
}
bool TransportWindow::FocusNext() {

View File

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

View File

@ -574,12 +574,12 @@ process:
Event event(rawMouseEvent, window);
if (event.MouseWheelDown() || event.MouseWheelUp()) {
if (state.focused) {
state.focused->MouseEvent(event);
state.focused->ProcessMouseEvent(event);
}
}
else if (mouseButtonState.Update(rawMouseEvent)) {
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;
}
bool Checkbox::MouseEvent(const IMouseHandler::Event& event) {
bool Checkbox::ProcessMouseEvent(const IMouseHandler::Event& event) {
if (event.Button1Clicked()) {
this->FocusInParent();
this->SetChecked(!this->checked);
return true;
}
return false;
return TextLabel::ProcessMouseEvent(event);
}

View File

@ -503,7 +503,7 @@ bool LayoutBase::KeyPress(const std::string& key) {
return false;
}
bool LayoutBase::MouseEvent(const IMouseHandler::Event& mouseEvent) {
bool LayoutBase::ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) {
for (auto window : this->children) {
auto x = window->GetX();
auto y = window->GetY();
@ -513,10 +513,10 @@ bool LayoutBase::MouseEvent(const IMouseHandler::Event& mouseEvent) {
mouseEvent.y >= y && mouseEvent.y < y + cy)
{
auto relative = IMouseHandler::Event(mouseEvent, window.get());
if (window->MouseEvent(relative)) {
if (window->ProcessMouseEvent(relative)) {
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);
}
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. */
bool result = ScrollableWindow::MouseEvent(event);
bool result = ScrollableWindow::ProcessMouseEvent(event);
auto first = this->scrollPosition.firstVisibleEntryIndex;

View File

@ -140,7 +140,9 @@ bool ScrollableWindow::KeyPress(const std::string& key) {
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()) {
this->FocusInParent();
return true;
@ -153,7 +155,8 @@ bool ScrollableWindow::MouseEvent(const IMouseHandler::Event& event) {
this->PageUp();
return true;
}
return false;
return result;
}

View File

@ -148,7 +148,7 @@ bool ShortcutsWindow::KeyPress(const std::string& key) {
return false;
}
bool ShortcutsWindow::MouseEvent(const IMouseHandler::Event& mouseEvent) {
bool ShortcutsWindow::ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) {
if (mouseEvent.Button1Clicked()) {
for (auto entry : this->entries) {
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) {

View File

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

View File

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

View File

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

View File

@ -50,12 +50,16 @@ namespace cursespp {
virtual ~Checkbox();
virtual void SetText(const std::string& value);
virtual std::string GetText();
virtual void SetChecked(bool 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:
bool checked;

View File

@ -72,6 +72,6 @@ namespace cursespp {
};
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;
/* IMouseHandler */
bool MouseEvent(const IMouseHandler::Event& mouseEvent) override;
bool ProcessMouseEvent(const IMouseHandler::Event& mouseEvent) override;
/* IWindowGroup */
bool AddWindow(IWindowPtr window) override;

View File

@ -70,7 +70,7 @@ namespace cursespp {
const IScrollAdapter::ScrollPosition& GetScrollPosition() 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 SetDecorator(Decorator decorator);

View File

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

View File

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

View File

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

View File

@ -58,7 +58,7 @@ namespace cursespp {
/* IWindow */
void OnRedraw() 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 void SetBold(bool bold);

View File

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