From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- components/chatinput.cpp | 66 ------------------------------------------------ 1 file changed, 66 deletions(-) delete mode 100644 components/chatinput.cpp (limited to 'components/chatinput.cpp') diff --git a/components/chatinput.cpp b/components/chatinput.cpp deleted file mode 100644 index c3eca32..0000000 --- a/components/chatinput.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "chatinput.hpp" - -ChatInput::ChatInput() { - get_style_context()->add_class("message-input"); - set_propagate_natural_height(true); - set_min_content_height(20); - set_max_content_height(250); - set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - - // hack - auto cb = [this](GdkEventKey *e) -> bool { - return event(reinterpret_cast(e)); - }; - m_textview.signal_key_press_event().connect(cb, false); - m_textview.set_hexpand(false); - m_textview.set_halign(Gtk::ALIGN_FILL); - m_textview.set_valign(Gtk::ALIGN_CENTER); - m_textview.set_wrap_mode(Gtk::WRAP_WORD_CHAR); - m_textview.show(); - add(m_textview); -} - -void ChatInput::InsertText(const Glib::ustring &text) { - GetBuffer()->insert_at_cursor(text); - m_textview.grab_focus(); -} - -Glib::RefPtr ChatInput::GetBuffer() { - return m_textview.get_buffer(); -} - -// this isnt connected directly so that the chat window can handle stuff like the completer first -bool ChatInput::ProcessKeyPress(GdkEventKey *event) { - if (event->keyval == GDK_KEY_Escape) { - m_signal_escape.emit(); - return true; - } - - if (event->keyval == GDK_KEY_Return) { - if (event->state & GDK_SHIFT_MASK) - return false; - - auto buf = GetBuffer(); - auto text = buf->get_text(); - - const bool accepted = m_signal_submit.emit(text); - if (accepted) - buf->set_text(""); - - return true; - } - - return false; -} - -void ChatInput::on_grab_focus() { - m_textview.grab_focus(); -} - -ChatInput::type_signal_submit ChatInput::signal_submit() { - return m_signal_submit; -} - -ChatInput::type_signal_escape ChatInput::signal_escape() { - return m_signal_escape; -} -- cgit v1.2.3