From f0492a995d94e6e13dd06d4eb4e47328bca28484 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 29 May 2021 15:47:54 -0500 Subject: [PATCH] Merge MainWindow and ChatWindow --- application/ChatWindow.cpp | 173 ------------------------------- application/ChatWindow.h | 49 --------- application/Conversation.cpp | 4 +- application/MainWindow.cpp | 56 ++++++++-- application/MainWindow.h | 21 ++-- application/Makefile | 1 - application/Server.cpp | 1 - application/User.h | 1 - application/views/StatusView.cpp | 9 +- 9 files changed, 66 insertions(+), 249 deletions(-) delete mode 100644 application/ChatWindow.cpp delete mode 100644 application/ChatWindow.h diff --git a/application/ChatWindow.cpp b/application/ChatWindow.cpp deleted file mode 100644 index 82717f0..0000000 --- a/application/ChatWindow.cpp +++ /dev/null @@ -1,173 +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 "ChatWindow.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "CayaMessages.h" -#include "CayaProtocolMessages.h" -#include "CayaPreferences.h" -#include "ConversationView.h" -#include "Conversation.h" -#include "Contact.h" -#include "EditingFilter.h" -#include "CayaConstants.h" -#include "CayaRenderView.h" -#include "NotifyMessage.h" - -ChatWindow::ChatWindow() - : - BWindow(BRect(200, 200, 500, 500), "Chat", B_TITLED_WINDOW, 0) -{ - fChatView = new ConversationView(); - - fSendView = new BTextView("fSendView"); - fSendScroll = new BScrollView("fSendScroll", fSendView, - B_WILL_DRAW, false, true); - fSendView->SetWordWrap(true); - - AddCommonFilter(new EditingFilter(fSendView)); - fSendView->MakeFocus(true); - - BLayoutBuilder::Group<>(this, B_VERTICAL) - .Add(fChatView) - .Add(fSendScroll) - .End(); -} - - -ChatWindow::ChatWindow(Conversation* cl) - : - ChatWindow() -{ - fChatView = new ConversationView(cl); - SetConversation(cl); -} - - -void -ChatWindow::SetConversation(Conversation* chat) -{ - BView* current = FindView("chatView"); - RemoveChild(FindView("chatView")); - RemoveChild(FindView("fSendScroll")); - - fChatView = chat->GetView(); - - AddChild(fChatView); - AddChild(fSendScroll); -} - - -void -ChatWindow::ShowWindow() -{ - if (IsHidden()) - Show(); - - if (IsMinimized()) - Minimize(false); - - if (!IsActive()) - Activate(true); -} - - -bool -ChatWindow::QuitRequested() -{ - BMessage msg(CAYA_CLOSE_CHAT_WINDOW); -// msg.AddString("chat_id", fConversation->GetId()); -// fConversation->Messenger().SendMessage(&msg); - return false; -} - - -void -ChatWindow::MessageReceived(BMessage* message) -{ - switch (message->what) { - case CAYA_CHAT: - message->PrintToStream(); - message->AddString("body", fSendView->Text()); - fChatView->MessageReceived(message); - fSendView->SetText(""); - break; - - case IM_MESSAGE: - fChatView->ImMessage(message); - break; - - default: - BWindow::MessageReceived(message); - break; - } -} - - -void -ChatWindow::ImMessage(BMessage* msg) -{ - fChatView->ImMessage(msg); -} - - -void -ChatWindow::ObserveString(int32 what, BString str) -{ - fChatView->ObserveString(what, str); -} - - -void -ChatWindow::ObservePointer(int32 what, void* ptr) -{ - fChatView->ObservePointer(what, ptr); -} - - -void -ChatWindow::ObserveInteger(int32 what, int32 val) -{ - fChatView->ObserveInteger(what, val); -} - - -void -ChatWindow::AvoidFocus(bool avoid) -{ - // This is needed to avoid the window focus when - // a new message is received, since it could be a lot annoying - // for the user - if (avoid) - SetFlags(B_AVOID_FOCUS); - else - SetFlags(Flags() &~ B_AVOID_FOCUS); -} - - diff --git a/application/ChatWindow.h b/application/ChatWindow.h deleted file mode 100644 index d2142f2..0000000 --- a/application/ChatWindow.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2009-2011, Andrea Anzani. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _CHAT_WINDOW_H -#define _CHAT_WINDOW_H - -#include -#include -#include -#include - -#include "CayaConstants.h" -#include "Observer.h" - -class BitmapView; -class BScrollVie; -class Conversation; -class ConversationView; -class CayaRenderView; -class Contact; - - -class ChatWindow : public BWindow, public Observer { -public: - ChatWindow(); - ChatWindow(Conversation* cl); - void SetConversation(Conversation* chat); - - virtual void ShowWindow(); - - virtual void MessageReceived(BMessage* message); - virtual bool QuitRequested(); - - void ImMessage(BMessage* msg); - - void ObserveString(int32 what, BString str); - void ObservePointer(int32 what, void* ptr); - void ObserveInteger(int32 what, int32 val); - - void AvoidFocus(bool avoid); -private: - BScrollView* fSendScroll; - BTextView* fSendView; - ConversationView* fChatView; -}; - -#endif // _CHAT_WINDOW_H - diff --git a/application/Conversation.cpp b/application/Conversation.cpp index f5e0d08..292d16b 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -13,7 +13,6 @@ #include "CayaProtocolMessages.h" #include "CayaRenderView.h" #include "CayaUtils.h" -#include "ChatWindow.h" #include "ConversationItem.h" #include "ConversationView.h" #include "MainWindow.h" @@ -97,8 +96,7 @@ Conversation::ObserveInteger(int32 what, int32 val) void Conversation::ShowView(bool typing, bool userAction) { - ((TheApp*)be_app)->GetMainWindow()->GetChatWindow()->SetConversation(this); - ((TheApp*)be_app)->GetMainWindow()->GetChatWindow()->ShowWindow(); + ((TheApp*)be_app)->GetMainWindow()->SetConversation(this); } diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 574a7fa..6c1a6c4 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -26,10 +26,10 @@ #include "CayaMessages.h" #include "CayaProtocolMessages.h" #include "CayaPreferences.h" -#include "ChatWindow.h" #include "ConversationItem.h" #include "ConversationListView.h" #include "ConversationView.h" +#include "EditingFilter.h" #include "NotifyMessage.h" #include "MainWindow.h" #include "PreferencesDialog.h" @@ -49,9 +49,6 @@ MainWindow::MainWindow() { fStatusView = new StatusView("statusView"); - fChatWindow = new ChatWindow(); - fChatWindow->Show(); - // Menubar BMenuBar* menuBar = new BMenuBar("MenuBar"); @@ -75,12 +72,31 @@ MainWindow::MainWindow() fListView = new ConversationListView("roomList"); - BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f) + fChatView = new ConversationView(); + + fSendView = new BTextView("fSendView"); + fSendScroll = new BScrollView("fSendScroll", fSendView, + B_WILL_DRAW, false, true); + fSendView->SetWordWrap(true); + AddCommonFilter(new EditingFilter(fSendView)); + fSendView->MakeFocus(true); + + fRightView = new BGroupView("rightView", B_VERTICAL); + fRightView->AddChild(fChatView); + fRightView->AddChild(fSendScroll); + + + BLayoutBuilder::Group<>(this, B_VERTICAL) .Add(menuBar) - .Add(fListView) - .AddGroup(B_VERTICAL) + + .AddGroup(B_HORIZONTAL) .SetInsets(5, 5, 5, 10) - .Add(fStatusView) + .AddGroup(B_VERTICAL) + .Add(fListView) + .Add(fStatusView) + .End() + + .Add(fRightView) .End() .End(); @@ -175,6 +191,15 @@ MainWindow::MessageReceived(BMessage* message) break; } + case CAYA_CHAT: + { + message->AddString("body", fSendView->Text()); + fChatView->MessageReceived(message); + fSendView->SetText(""); + + break; + } + case IM_MESSAGE: ImMessage(message); break; @@ -232,7 +257,6 @@ MainWindow::ImMessage(BMessage* msg) case IM_MESSAGE_RECEIVED: { _EnsureConversationItem(msg); -// fChatWindow->PostMessage(msg); break; } case IM_MESSAGE_SENT: @@ -245,6 +269,20 @@ MainWindow::ImMessage(BMessage* msg) } +void +MainWindow::SetConversation(Conversation* chat) +{ + BView* current = fRightView->FindView("chatView"); + fRightView->RemoveChild(fRightView->FindView("chatView")); + fRightView->RemoveChild(fRightView->FindView("fSendScroll")); + + fChatView = chat->GetView(); + + fRightView->AddChild(fChatView); + fRightView->AddChild(fSendScroll); +} + + void MainWindow::ObserveInteger(int32 what, int32 val) { diff --git a/application/MainWindow.h b/application/MainWindow.h index 6a0d241..21535d4 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -10,13 +10,14 @@ #include "Observer.h" -class BCardLayout; +class BGroupView; class BTextControl; +class BTextView; +class Conversation; class ConversationItem; class ConversationListView; class ConversationView; -class ChatWindow; class Server; class StatusView; class RosterItem; @@ -38,7 +39,7 @@ public: void ObserveInteger(int32 what, int32 val); - ChatWindow* GetChatWindow() { return fChatWindow; } + void SetConversation(Conversation* chat); Server* GetServer() const { return fServer; } void UpdateListItem(ConversationItem* item); @@ -49,11 +50,19 @@ public: private: ConversationItem* _EnsureConversationItem(BMessage* msg); - ChatWindow* fChatWindow; - ConversationListView* fListView; - StatusView* fStatusView; Server* fServer; bool fWorkspaceChanged; + + // Left panel, chat list + ConversationListView* fListView; + StatusView* fStatusView; + + // Right panel, chat + BGroupView* fRightView; + BScrollView* fSendScroll; + BTextView* fSendView; + ConversationView* fChatView; + }; #endif // _MAIN_WINDOW_H diff --git a/application/Makefile b/application/Makefile index 326b837..ff4ff38 100644 --- a/application/Makefile +++ b/application/Makefile @@ -39,7 +39,6 @@ SRCS = \ application/CayaUtils.cpp \ application/Contact.cpp \ application/Conversation.cpp \ - application/ChatWindow.cpp \ application/EditingFilter.cpp \ application/ImageCache.cpp \ application/Main.cpp \ diff --git a/application/Server.cpp b/application/Server.cpp index 90605e9..5f0eff9 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -25,7 +25,6 @@ #include "CayaProtocol.h" #include "CayaPreferences.h" #include "CayaProtocolMessages.h" -#include "ChatWindow.h" #include "ImageCache.h" #include "ProtocolManager.h" #include "RosterItem.h" diff --git a/application/User.h b/application/User.h index 030ba6c..9571536 100644 --- a/application/User.h +++ b/application/User.h @@ -18,7 +18,6 @@ class BBitmap; -class ChatWindow; class Conversation; class UserPopUp; class ProtocolLooper; diff --git a/application/views/StatusView.cpp b/application/views/StatusView.cpp index 1900baa..20650a5 100644 --- a/application/views/StatusView.cpp +++ b/application/views/StatusView.cpp @@ -9,8 +9,7 @@ #include "StatusView.h" #include -#include -#include +#include #include #include #include @@ -75,8 +74,7 @@ StatusView::StatusView(const char* name) fAvatar->SetExplicitPreferredSize(BSize(50, 50)); // Set layout - SetLayout(new BGroupLayout(B_VERTICAL)); - AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 5) + BLayoutBuilder::Group<>(this, B_HORIZONTAL) .AddGroup(B_VERTICAL) .Add(statusField) .AddGroup(B_HORIZONTAL) @@ -85,8 +83,7 @@ StatusView::StatusView(const char* name) .End() .End() .Add(fAvatar) -// .TopView() - ); + .End(); }