Improved the behaviour to don't get focus when a message is received or the user is typing, from that rev the chat window will appear on the screen without leaving the focus of your current application. But there are two exeptions...when a window is created the first time or the user open it from the contacts list it will get focus. Other little fixes, changed variable names and style.
This commit is contained in:
parent
d661379bc4
commit
92f2ee4547
|
@ -96,6 +96,20 @@ ChatWindow::ChatWindow(ContactLinker* cl)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
ChatWindow::ShowWindow()
|
||||
{
|
||||
if (IsHidden())
|
||||
Show();
|
||||
|
||||
if (IsMinimized())
|
||||
Minimize(false);
|
||||
|
||||
if (!IsActive())
|
||||
Activate(true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ChatWindow::QuitRequested()
|
||||
{
|
||||
|
@ -153,6 +167,7 @@ ChatWindow::MessageReceived(BMessage* message)
|
|||
case IM_MESSAGE:
|
||||
ImMessage(message);
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
|
@ -265,3 +280,16 @@ ChatWindow::AppendStatus(CayaStatus status)
|
|||
fReceiveView->Append("\n", COL_TEXT, COL_TEXT, R_TEXT);
|
||||
fReceiveView->ScrollToSelection();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ class ChatWindow : public BWindow, public Observer {
|
|||
public:
|
||||
ChatWindow(ContactLinker* cl);
|
||||
|
||||
virtual void ShowWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
|
@ -32,6 +34,7 @@ public:
|
|||
void ObserveInteger(int32 what, int32 val);
|
||||
void AppendStatus(CayaStatus status);
|
||||
|
||||
void AvoidFocus(bool avoid);
|
||||
private:
|
||||
BTextView* fSendView;
|
||||
ContactLinker* fContactLinker;
|
||||
|
|
|
@ -34,7 +34,8 @@ ContactLinker::ContactLinker(BString id, BMessenger msgn)
|
|||
fMessenger(msgn),
|
||||
fLooper(NULL),
|
||||
fStatus(CAYA_OFFLINE),
|
||||
fPopUp(NULL)
|
||||
fPopUp(NULL),
|
||||
fNewWindow(true)
|
||||
{
|
||||
// Create the roster item and register it as observer
|
||||
fRosterItem = new RosterItem(id.String(), this);
|
||||
|
@ -59,29 +60,38 @@ ContactLinker::DeleteWindow()
|
|||
UnregisterObserver(fChatWindow);
|
||||
fChatWindow->Quit();
|
||||
fChatWindow = NULL;
|
||||
fNewWindow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContactLinker::ShowWindow()
|
||||
ContactLinker::ShowWindow(bool typing, bool userAction)
|
||||
{
|
||||
if (fChatWindow == NULL)
|
||||
CreateChatWindow();
|
||||
|
||||
fChatWindow->AvoidFocus(true);
|
||||
|
||||
if (CayaPreferences::Item()->MoveToCurrentWorkspace)
|
||||
fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE);
|
||||
|
||||
if (fChatWindow->IsHidden())
|
||||
fChatWindow->Show();
|
||||
|
||||
if (fChatWindow->IsMinimized())
|
||||
fChatWindow->Minimize(false);
|
||||
|
||||
if (CayaPreferences::Item()->FocusOnMessageReceived == true
|
||||
|| CayaPreferences::Item()->FocusUserIsTyping == true)
|
||||
fChatWindow->Activate(true);
|
||||
if (fNewWindow || userAction) {
|
||||
fChatWindow->AvoidFocus(false);
|
||||
fChatWindow->ShowWindow();
|
||||
fNewWindow = false;
|
||||
} else {
|
||||
if (typing) {
|
||||
if (CayaPreferences::Item()->RaiseUserIsTyping)
|
||||
fChatWindow->ShowWindow();
|
||||
} else {
|
||||
if (CayaPreferences::Item()->RaiseOnMessageReceived
|
||||
|| fChatWindow->IsHidden())
|
||||
fChatWindow->ShowWindow();
|
||||
}
|
||||
}
|
||||
fChatWindow->AvoidFocus(false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
ChatWindow* GetChatWindow();
|
||||
void DeleteWindow();
|
||||
|
||||
void ShowWindow();
|
||||
void ShowWindow(bool typing = false, bool userAction = false);
|
||||
void HideWindow();
|
||||
|
||||
void ShowPopUp(BPoint where);
|
||||
|
@ -70,6 +70,8 @@ private:
|
|||
BBitmap* fAvatarBitmap;
|
||||
CayaStatus fStatus;
|
||||
ContactPopUp* fPopUp;
|
||||
|
||||
bool fNewWindow;
|
||||
};
|
||||
|
||||
#endif // _CONTACT_LINKER_H_
|
||||
|
|
|
@ -137,7 +137,8 @@ void
|
|||
MainWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kSearchContact: {
|
||||
case kSearchContact:
|
||||
{
|
||||
void* control = NULL;
|
||||
if (message->FindPointer("source", &control) != B_OK)
|
||||
return;
|
||||
|
@ -165,16 +166,18 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case CAYA_SHOW_SETTINGS: {
|
||||
case CAYA_SHOW_SETTINGS:
|
||||
{
|
||||
PreferencesDialog* dialog = new PreferencesDialog();
|
||||
dialog->Show();
|
||||
break;
|
||||
}
|
||||
case CAYA_OPEN_CHAT_WINDOW: {
|
||||
case CAYA_OPEN_CHAT_WINDOW:
|
||||
{
|
||||
int index = message->FindInt32("index");
|
||||
RosterItem* ritem = ItemAt(index);
|
||||
if (ritem != NULL)
|
||||
ritem->GetContactLinker()->ShowWindow();
|
||||
ritem->GetContactLinker()->ShowWindow(false, true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -321,8 +321,7 @@ Server::ImMessage(BMessage* msg)
|
|||
ContactLinker* item = fRosterMap.ValueFor(id, &found);
|
||||
if (found) {
|
||||
ChatWindow* win = item->GetChatWindow();
|
||||
if (CayaPreferences::Item()->FocusOnMessageReceived)
|
||||
item->ShowWindow();
|
||||
item->ShowWindow();
|
||||
win->PostMessage(msg);
|
||||
}
|
||||
}
|
||||
|
@ -338,8 +337,7 @@ Server::ImMessage(BMessage* msg)
|
|||
ContactLinker* item = fRosterMap.ValueFor(id, &found);
|
||||
if (found) {
|
||||
ChatWindow* win = item->GetChatWindow();
|
||||
if (CayaPreferences::Item()->FocusUserIsTyping)
|
||||
item->ShowWindow();
|
||||
item->ShowWindow(true);
|
||||
win->PostMessage(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ template<> const char* CayaPreferences::fFilename = "preferences";
|
|||
CayaPreferencesData::CayaPreferencesData()
|
||||
:
|
||||
MoveToCurrentWorkspace(true),
|
||||
FocusOnMessageReceived(false),
|
||||
FocusUserIsTyping(false),
|
||||
RaiseOnMessageReceived(false),
|
||||
RaiseUserIsTyping(false),
|
||||
HideCayaDeskbar(false),
|
||||
DisableReplicant(true),
|
||||
IgnoreEmoticons(false),
|
||||
|
@ -78,8 +78,8 @@ CayaPreferencesData::Flatten(BPositionIO* flatData) const
|
|||
|
||||
// Behaviour
|
||||
_AddBool(flatData, MoveToCurrentWorkspace);
|
||||
_AddBool(flatData, FocusOnMessageReceived);
|
||||
_AddBool(flatData, FocusUserIsTyping);
|
||||
_AddBool(flatData, RaiseOnMessageReceived);
|
||||
_AddBool(flatData, RaiseUserIsTyping);
|
||||
|
||||
_AddBool(flatData, NotifyProtocolStatus);
|
||||
_AddBool(flatData, NotifyContactStatus);
|
||||
|
@ -142,8 +142,8 @@ CayaPreferencesData::Unflatten(type_code code, BPositionIO* flatData)
|
|||
|
||||
// Behaviour
|
||||
MoveToCurrentWorkspace = _ReadBool(flatData);
|
||||
FocusOnMessageReceived = _ReadBool(flatData);
|
||||
FocusUserIsTyping = _ReadBool(flatData);
|
||||
RaiseOnMessageReceived = _ReadBool(flatData);
|
||||
RaiseUserIsTyping = _ReadBool(flatData);
|
||||
|
||||
NotifyProtocolStatus = _ReadBool(flatData);
|
||||
NotifyContactStatus = _ReadBool(flatData);
|
||||
|
|
|
@ -26,8 +26,8 @@ public:
|
|||
status_t Unflatten(type_code code, BPositionIO* flatData);
|
||||
|
||||
bool MoveToCurrentWorkspace;
|
||||
bool FocusOnMessageReceived;
|
||||
bool FocusUserIsTyping;
|
||||
bool RaiseOnMessageReceived;
|
||||
bool RaiseUserIsTyping;
|
||||
bool NotifyProtocolStatus;
|
||||
bool NotifyContactStatus;
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include "TheApp.h"
|
||||
|
||||
const uint32 kToCurrentWorkspace = 'CBcw';
|
||||
const uint32 kFocusOnMessageReceived= 'FCmr';
|
||||
const uint32 kFocusUserIsTyping = 'FCit';
|
||||
const uint32 kRaiseOnMessageReceived = 'FCmr';
|
||||
const uint32 kRaiseUserIsTyping = 'FCit';
|
||||
const uint32 kNotifyProtocolsLogin = 'NTpl';
|
||||
const uint32 kNotifyContactStatus = 'NTcl';
|
||||
|
||||
|
@ -42,13 +42,13 @@ PreferencesBehavior::PreferencesBehavior()
|
|||
"Move window to current workspace",
|
||||
new BMessage(kToCurrentWorkspace));
|
||||
|
||||
fFocusOnMessageReceived = new BCheckBox("FocusOnMessageReceived",
|
||||
"Get focus when a message is received",
|
||||
new BMessage(kFocusOnMessageReceived));
|
||||
fRaiseOnMessageReceived = new BCheckBox("FocusOnMessageReceived",
|
||||
"Auto-raise when a message is received",
|
||||
new BMessage(kRaiseOnMessageReceived));
|
||||
|
||||
fFocusUserIsTyping = new BCheckBox("FocusUserIsTyping",
|
||||
"Get focus when user is typing",
|
||||
new BMessage(kFocusUserIsTyping));
|
||||
fRaiseUserIsTyping = new BCheckBox("FocusUserIsTyping",
|
||||
"Auto-raise when user is typing",
|
||||
new BMessage(kRaiseUserIsTyping));
|
||||
|
||||
fPlaySoundOnMessageReceived = new BCheckBox("PlaySoundOnMessageReceived",
|
||||
"Play sound event", NULL);
|
||||
|
@ -82,8 +82,8 @@ PreferencesBehavior::PreferencesBehavior()
|
|||
.Add(fOnIncoming)
|
||||
.AddGroup(B_VERTICAL, spacing)
|
||||
.Add(fToCurrentWorkspace)
|
||||
.Add(fFocusOnMessageReceived)
|
||||
.Add(fFocusUserIsTyping)
|
||||
.Add(fRaiseOnMessageReceived)
|
||||
.Add(fRaiseUserIsTyping)
|
||||
.Add(fMarkUnreadWindow)
|
||||
.Add(fMarkUnreadReplicant)
|
||||
.Add(fPlaySoundOnMessageReceived)
|
||||
|
@ -106,17 +106,17 @@ void
|
|||
PreferencesBehavior::AttachedToWindow()
|
||||
{
|
||||
fToCurrentWorkspace->SetTarget(this);
|
||||
fFocusUserIsTyping->SetTarget(this);
|
||||
fFocusOnMessageReceived->SetTarget(this);
|
||||
fRaiseUserIsTyping->SetTarget(this);
|
||||
fRaiseOnMessageReceived->SetTarget(this);
|
||||
fNotifyProtocols->SetTarget(this);
|
||||
fNotifyContactStatus->SetTarget(this);
|
||||
|
||||
fToCurrentWorkspace->SetValue(
|
||||
CayaPreferences::Item()->MoveToCurrentWorkspace);
|
||||
fFocusUserIsTyping->SetValue(
|
||||
CayaPreferences::Item()->FocusUserIsTyping);
|
||||
fFocusOnMessageReceived->SetValue(
|
||||
CayaPreferences::Item()->FocusOnMessageReceived);
|
||||
fRaiseUserIsTyping->SetValue(
|
||||
CayaPreferences::Item()->RaiseUserIsTyping);
|
||||
fRaiseOnMessageReceived->SetValue(
|
||||
CayaPreferences::Item()->RaiseOnMessageReceived);
|
||||
fNotifyProtocols->SetValue(
|
||||
CayaPreferences::Item()->NotifyProtocolStatus);
|
||||
fNotifyContactStatus->SetValue(
|
||||
|
@ -132,13 +132,13 @@ PreferencesBehavior::MessageReceived(BMessage* message)
|
|||
CayaPreferences::Item()->MoveToCurrentWorkspace
|
||||
= fToCurrentWorkspace->Value();
|
||||
break;
|
||||
case kFocusOnMessageReceived:
|
||||
CayaPreferences::Item()->FocusOnMessageReceived
|
||||
= fFocusOnMessageReceived->Value();
|
||||
case kRaiseOnMessageReceived:
|
||||
CayaPreferences::Item()->RaiseOnMessageReceived
|
||||
= fRaiseOnMessageReceived->Value();
|
||||
break;
|
||||
case kFocusUserIsTyping:
|
||||
CayaPreferences::Item()->FocusUserIsTyping
|
||||
= fFocusUserIsTyping->Value();
|
||||
case kRaiseUserIsTyping:
|
||||
CayaPreferences::Item()->RaiseUserIsTyping
|
||||
= fRaiseUserIsTyping->Value();
|
||||
break;
|
||||
case kNotifyProtocolsLogin:
|
||||
CayaPreferences::Item()->NotifyProtocolStatus
|
||||
|
|
|
@ -22,8 +22,8 @@ private:
|
|||
|
||||
BStringView* fOnIncoming;
|
||||
BCheckBox* fToCurrentWorkspace;
|
||||
BCheckBox* fFocusOnMessageReceived;
|
||||
BCheckBox* fFocusUserIsTyping;
|
||||
BCheckBox* fRaiseOnMessageReceived;
|
||||
BCheckBox* fRaiseUserIsTyping;
|
||||
BCheckBox* fPlaySoundOnMessageReceived;
|
||||
BCheckBox* fMarkUnreadWindow;
|
||||
BCheckBox* fMarkUnreadReplicant;
|
||||
|
|
Ŝarĝante…
Reference in New Issue