Merge MainWindow and ChatWindow
This commit is contained in:
parent
b9d120a8f6
commit
f0492a995d
|
@ -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 <Alert.h>
|
||||
#include <Application.h>
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
#include <GridLayout.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <Layout.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <ListView.h>
|
||||
#include <Message.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
#include <StringList.h>
|
||||
#include <Notification.h>
|
||||
|
||||
#include <libinterface/BitmapView.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
@ -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 <Notification.h>
|
||||
#include <StringView.h>
|
||||
#include <TextView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
class BBitmap;
|
||||
|
||||
class ChatWindow;
|
||||
class Conversation;
|
||||
class UserPopUp;
|
||||
class ProtocolLooper;
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
#include "StatusView.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Message.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue