Chat-O-Matic/libs/libinterface/EnterTextView.cpp
Jaidyn Ann 89ff195c8d Set room topic/name through conversation view
If the user has permission to change a room's subject or name, they can
now edit the text views displaying them (toward the top of the window).
When enter is pressed, the changes will be sent to the protocol.

To do this, a BTextView subclass was added to libinterface
(splitting somewhat from SendTextView)― EnterTextView sends a message
containing the text to the given target when the user hits enter sans
modifiers.
2021-07-29 22:00:01 -05:00

52 lines
1.0 KiB
C++

/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "EnterTextView.h"
#include <Window.h>
EnterTextView::EnterTextView(const char* name)
:
BTextView(name),
fTarget(NULL)
{
}
EnterTextView::EnterTextView(const char* name, const BFont* initialFont,
const rgb_color* initialColor, uint32 flags)
:
BTextView(name, initialFont, initialColor, flags),
fTarget(NULL)
{
}
void
EnterTextView::KeyDown(const char* bytes, int32 numBytes)
{
int32 modifiers = Window()->CurrentMessage()->GetInt32("modifiers", 0);
if (fTarget != NULL && (bytes[0] == B_ENTER) && (modifiers == 0))
{
BMessage* msg = new BMessage(fMessage);
if (fTextSlot.IsEmpty() == false)
msg->AddString(fTextSlot.String(), Text());
fTarget->MessageReceived(msg);
}
else
BTextView::KeyDown(bytes, numBytes);
}
void
EnterTextView::SetMessage(BMessage msg, const char* textSlot)
{
fMessage = msg;
if (textSlot != NULL)
fTextSlot.SetTo(textSlot);
}