diff --git a/application/EditingFilter.cpp b/application/EditingFilter.cpp deleted file mode 100644 index 37e12a1..0000000 --- a/application/EditingFilter.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2009-2011, Andrea Anzani. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Andrea Anzani, andrea.anzani@gmail.com - */ - -#include -#include -#include - -#include "AppMessages.h" -#include "EditingFilter.h" - - -EditingFilter::EditingFilter(BTextView* view) - : - BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, B_KEY_DOWN, NULL), - fView(view) -{ -} - - -filter_result -EditingFilter::Filter(BMessage* message, BHandler** target) -{ - int32 modifiers; - - int8 byte; - message->FindInt8("byte", &byte); - - // If we have modifiers but none are the Alt key - if (message->FindInt32("modifiers", &modifiers)) - return B_DISPATCH_MESSAGE; - - // If the Alt key jives with the command_enter status - if ((modifiers & B_COMMAND_KEY) != 0 && byte == B_ENTER) { - fView->Insert("\n"); - return B_SKIP_MESSAGE; - } else if ((modifiers & B_COMMAND_KEY) == 0 && byte == B_ENTER) { - fView->Window()->PostMessage(APP_CHAT); - return B_SKIP_MESSAGE; - } - - return B_DISPATCH_MESSAGE; -} diff --git a/application/EditingFilter.h b/application/EditingFilter.h deleted file mode 100644 index ed3ca27..0000000 --- a/application/EditingFilter.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2009-2011, Andrea Anzani. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _EDITING_FILTER_H -#define _EDITING_FILTER_H - -#include -#include - -class EditingFilter : public BMessageFilter { -public: - EditingFilter(BTextView* view); - - virtual filter_result Filter(BMessage* message, BHandler** target); - -private: - BTextView* fView; -}; - -#endif // _EDITING_FILTER_H diff --git a/application/Makefile b/application/Makefile index 5c74f50..73f2bad 100644 --- a/application/Makefile +++ b/application/Makefile @@ -38,7 +38,6 @@ SRCS = \ application/ChatCommand.cpp \ application/Contact.cpp \ application/Conversation.cpp \ - application/EditingFilter.cpp \ application/ImageCache.cpp \ application/Notifier.cpp \ application/ProtocolLooper.cpp \ @@ -68,6 +67,7 @@ SRCS = \ application/views/RosterItem.cpp \ application/views/RosterListView.cpp \ application/views/RosterView.cpp \ + application/views/SendTextView.cpp \ application/views/StatusMenuItem.cpp \ application/views/StatusView.cpp \ application/views/TemplateView.cpp \ diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 9e41053..92c9b61 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -26,6 +26,7 @@ #include "RenderView.h" #include "Conversation.h" #include "NotifyMessage.h" +#include "SendTextView.h" #include "User.h" #include "UserItem.h" #include "UserListView.h" @@ -40,6 +41,7 @@ ConversationView::ConversationView() { fMessageCount = 0; _InitInterface(); + fSendView->MakeFocus(true); } @@ -89,7 +91,7 @@ ConversationView::MessageReceived(BMessage* message) switch (message->what) { case APP_CHAT: { - BString text = message->FindString("body"); + BString text = fSendView->Text(); if (text == "") return; int64 instance = fConversation->GetProtocolLooper()->GetInstance(); @@ -100,6 +102,8 @@ ConversationView::MessageReceived(BMessage* message) msg.AddString("chat_id", fConversation->GetId()); msg.AddString("body", text); fConversation->ImMessage(&msg); + + fSendView->SetText(""); break; } case IM_MESSAGE: @@ -277,10 +281,12 @@ ConversationView::ObserveString(int32 what, BString str) void ConversationView::_InitInterface() { - fReceiveView = new RenderView("fReceiveView"); + fReceiveView = new RenderView("receiveView"); BScrollView* scrollViewReceive = new BScrollView("receiveScrollView", fReceiveView, B_WILL_DRAW, false, true); + fSendView = new SendTextView("sendView", this); + fNameTextView = new BTextView("roomName", B_WILL_DRAW); fNameTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); fNameTextView->MakeEditable(false); @@ -310,9 +316,13 @@ ConversationView::_InitInterface() .Add(fProtocolView) .End() .AddSplit(B_HORIZONTAL, 0) - .Add(scrollViewReceive, 5) + .AddGroup(B_VERTICAL, B_USE_HALF_ITEM_SPACING, 8) + .Add(scrollViewReceive, 20) + .Add(fSendView, 1) + .End() .Add(scrollViewUsers, 1) - .End(); + .End() + .End(); } diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index 061a45d..c858540 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -17,6 +17,7 @@ class BTextView; class BitmapView; class RenderView; +class SendTextView; class User; class UserListView; @@ -62,8 +63,9 @@ private: BitmapView* fProtocolView; BitmapView* fIcon; - RenderView* fReceiveView; + RenderView* fReceiveView; UserListView* fUserList; + SendTextView* fSendView; }; diff --git a/application/views/SendTextView.cpp b/application/views/SendTextView.cpp new file mode 100644 index 0000000..c2c1654 --- /dev/null +++ b/application/views/SendTextView.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "SendTextView.h" + +#include + +#include "AppMessages.h" + + +SendTextView::SendTextView(const char* name, ConversationView* convView) + : + BTextView(name), + fConversationView(convView) +{ +} + + +void +SendTextView::KeyDown(const char* bytes, int32 numBytes) +{ + int32 modifiers = Window()->CurrentMessage()->GetInt32("modifiers", 0); + + if ((bytes[0] == B_ENTER) && (modifiers & B_COMMAND_KEY)) + Insert("\n"); + else if (bytes[0] == B_ENTER) + fConversationView->MessageReceived(new BMessage(APP_CHAT)); + else + BTextView::KeyDown(bytes, numBytes); +} diff --git a/application/views/SendTextView.h b/application/views/SendTextView.h new file mode 100644 index 0000000..452d73e --- /dev/null +++ b/application/views/SendTextView.h @@ -0,0 +1,24 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef _SEND_TEXT_VIEW_H +#define _SEND_TEXT_VIEW_H + +#include + +#include "ConversationView.h" + + +class SendTextView : public BTextView { +public: + SendTextView(const char* name, ConversationView* convView); + + void KeyDown(const char* bytes, int32 numBytes); + +private: + ConversationView* fConversationView; +}; + + +#endif // _SEND_TEXT_VIEW_H diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index c315a34..96d23dc 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -25,7 +25,6 @@ #include "ConversationItem.h" #include "ConversationListView.h" #include "ConversationView.h" -#include "EditingFilter.h" #include "MainWindow.h" #include "NotifyMessage.h" #include "PreferencesWindow.h" @@ -55,8 +54,6 @@ MainWindow::MainWindow() AddFilter(fServer); // Also through the editing filter (enter to send) - AddCommonFilter(new EditingFilter(fSendView)); - fSendView->MakeFocus(true); CenterOnScreen(); @@ -208,13 +205,6 @@ MainWindow::MessageReceived(BMessage* message) } break; } - case APP_CHAT: - { - message->AddString("body", fSendView->Text()); - fChatView->MessageReceived(message); - fSendView->SetText(""); - break; - } case APP_DISABLE_ACCOUNT: _ToggleMenuItems(); break; @@ -337,7 +327,6 @@ MainWindow::SetConversation(Conversation* chat) float weightSend = fRightView->ItemWeight((int32)1); fRightView->RemoveChild(fRightView->FindView("chatView")); - fRightView->RemoveChild(fRightView->FindView("fSendScroll")); if (chat != NULL) { fChatView = chat->GetView(); @@ -351,7 +340,6 @@ MainWindow::SetConversation(Conversation* chat) SetTitle(APP_NAME); fRightView->AddChild(fChatView, 9); - fRightView->AddChild(fSendScroll, 1); // Apply saved chat and textbox size to new views if (weightChat * weightSend != 0) { @@ -419,10 +407,6 @@ MainWindow::_InitInterface() // Right-side of window, Chat + Textbox fRightView = new BSplitView(B_VERTICAL, 0); fChatView = new ConversationView(); - fSendView = new BTextView("fSendView"); - fSendScroll = new BScrollView("fSendScroll", fSendView, - B_WILL_DRAW, false, true); - fSendView->SetWordWrap(true); BLayoutBuilder::Group<>(this, B_VERTICAL) .Add((fMenuBar = _CreateMenuBar())) diff --git a/application/windows/MainWindow.h b/application/windows/MainWindow.h index 9c37d0b..c7025ea 100644 --- a/application/windows/MainWindow.h +++ b/application/windows/MainWindow.h @@ -68,8 +68,6 @@ private: // Right panel, chat BSplitView* fRightView; - BScrollView* fSendScroll; - BTextView* fSendView; ConversationView* fChatView; Conversation* fConversation; };