<commit_before>/////////////////////////////////////////
//
//             OpenLieroX
//
// code under LGPL, based on JasonBs work,
// enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Net menu - News
// Created 12/8/02
// <NAME>

#include <set>
#include "DeprecatedGUI/CChatWidget.h"
#include "LieroX.h"
#include "Sounds.h"
#include "DeprecatedGUI/Graphics.h"
#include "DeprecatedGUI/Menu.h"
#include "GfxPrimitives.h"
#include "DeprecatedGUI/CButton.h"
#include "DeprecatedGUI/CBrowser.h"
#include "DeprecatedGUI/CListview.h"
#include "DeprecatedGUI/CTextbox.h"
#include "DeprecatedGUI/CLabel.h"
#include "DeprecatedGUI/CCheckbox.h"
#include "IRC.h"
#include "StringUtils.h"
#include "AuxLib.h"
#include "NotifyUser.h"
#include "DeprecatedGUI/CImage.h"
#include "DeprecatedGUI/CBox.h"
#include "Mutex.h"


namespace DeprecatedGUI {

	enum {
		nc_ChatText,
		nc_UserList,
		nc_ChatInput,
		nc_Back, // Back button is not added by default, it's only for global chat widget
	};

bool GlobalChatWidget_enabled = false;

static std::set<CChatWidget *> chatWidgets; // Instances of CChatWidget

void ChatWidget_ChatRegisterCallbacks();
void ChatWidget_ChatDeregisterCallbacks();
void ChatWidget_ChatNewMessage(const std::string& msg, int type);

/////////////////////////
// Re-fills the user list
void ChatWidget_ChatRefillUserList()
{
	const IRCClient *irc = GetGlobalIRC();
	if ( !irc || !irc->isConnected() )
			return;

	for( std::set<CChatWidget *> :: iterator cw = chatWidgets.begin(); cw != chatWidgets.end(); cw++ )
	{
		// User list
		CListview *l = (CListview *)(*cw)->getWidget(nc_UserList);
		l->Clear();
		int i = 0;
		for (std::list<std::string>::const_iterator it = irc->getUserList().begin(); it != irc->getUserList().end(); it++) {
			l->AddItem(*it, i, tLX->clListView);
			l->AddSubitem(LVS_TEXT, *it, (DynDrawIntf*)NULL, NULL);
		}
	}
}

CChatWidget::CChatWidget()
{
}

CChatWidget::~CChatWidget()
{
}

void CChatWidget::Create()
{
	CGuiSkinnedLayout::SetOffset( iX, iY );
	
	if( iWidth < 170 || iHeight < tLX->cFont.GetHeight() + 40 )
		warnings << "CChatWidget::CChatWidget(): too small dimensions given" << endl;

	this->Add( new CBrowser(), nc_ChatText, 0, 0, iWidth - 145, iHeight - tLX->cFont.GetHeight() - 8 );
	this->Add( new CListview(), nc_UserList, iWidth - 140, 0, 140, iHeight);
	this->Add( new CTextbox(), nc_ChatInput, 0,  iHeight - tLX->cFont.GetHeight() - 2, iWidth - 145, tLX->cFont.GetHeight());

	// Messages
	CBrowser *b = (CBrowser *)this->getWidget(nc_ChatText);
	b->InitializeChatBox();

	IRCClient *irc = GetGlobalIRC();
	if (irc)
		for (std::list<IRCClient::IRCChatLine>::const_iterator it = irc->getMessageList().begin();
			it != irc->getMessageList().end(); it++)  {
				ChatWidget_ChatNewMessage(it->text, it->type);
		}

	chatWidgets.insert(this);

	ChatWidget_ChatRegisterCallbacks();
	ChatWidget_ChatRefillUserList();

	CGuiSkinnedLayout::Create();

}

void CChatWidget::Destroy()
{
	chatWidgets.erase(this);
	if( chatWidgets.empty() )
		ChatWidget_ChatDeregisterCallbacks();
	CGuiSkinnedLayout::Destroy();
}

void CChatWidget::EnableChat()
{
	ChatWidget_ChatRegisterCallbacks();
};
void CChatWidget::DisableChat()
{
	ChatWidget_ChatDeregisterCallbacks();
	for( std::set<CChatWidget *> :: iterator cw = chatWidgets.begin(); cw != chatWidgets.end(); cw++ )
	{
		((CListview *)(*cw)->getWidget(nc_UserList))->Clear();
	}
};
<commit_msg>Fixed IRC chat history disappearing when switching between chat widgets<commit_after>/////////////////////////////////////////
//
//             OpenLieroX
//
// code under LGPL, based on JasonBs work,
// enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Net menu - News
// Created 12/8/02
// <NAME>

#include <set>
#include "DeprecatedGUI/CChatWidget.h"
#include "LieroX.h"
#include "Sounds.h"
#include "DeprecatedGUI/Graphics.h"
#include "DeprecatedGUI/Menu.h"
#include "GfxPrimitives.h"
#include "DeprecatedGUI/CButton.h"
#include "DeprecatedGUI/CBrowser.h"
#include "DeprecatedGUI/CListview.h"
#include "DeprecatedGUI/CTextbox.h"
#include "DeprecatedGUI/CLabel.h"
#include "DeprecatedGUI/CCheckbox.h"
#include "IRC.h"
#include "StringUtils.h"
#include "AuxLib.h"
#include "NotifyUser.h"
#include "DeprecatedGUI/CImage.h"
#include "DeprecatedGUI/CBox.h"
#include "Mutex.h"


namespace DeprecatedGUI {

	enum {
		nc_ChatText,
		nc_UserList,
		nc_ChatInput,
		nc_Back, // Back button is not added by default, it's only for global chat widget
	};

bool GlobalChatWidget_enabled = false;

static std::set<CChatWidget *> chatWidgets; // Instances of CChatWidget

void ChatWidget_ChatRegisterCallbacks();
void ChatWidget_ChatDeregisterCallbacks();
void ChatWidget_ChatNewMessage(const std::string& msg, int type);

/////////////////////////
// Re-fills the user list
void ChatWidget_ChatRefillUserList()
{
	const IRCClient *irc = GetGlobalIRC();
	if ( !irc || !irc->isConnected() )
			return;

	for( std::set<CChatWidget *> :: iterator cw = chatWidgets.begin(); cw != chatWidgets.end(); cw++ )
	{
		// User list
		CListview *l = (CListview *)(*cw)->getWidget(nc_UserList);
		l->Clear();
		int i = 0;
		for (std::list<std::string>::const_iterator it = irc->getUserList().begin(); it != irc->getUserList().end(); it++) {
			l->AddItem(*it, i, tLX->clListView);
			l->AddSubitem(LVS_TEXT, *it, (DynDrawIntf*)NULL, NULL);
		}
	}
}

CChatWidget::CChatWidget()
{
}

CChatWidget::~CChatWidget()
{
}

void CChatWidget::Create()
{
	CGuiSkinnedLayout::SetOffset( iX, iY );
	
	if( iWidth < 170 || iHeight < tLX->cFont.GetHeight() + 40 )
		warnings << "CChatWidget::CChatWidget(): too small dimensions given" << endl;

	this->Add( new CBrowser(), nc_ChatText, 0, 0, iWidth - 145, iHeight - tLX->cFont.GetHeight() - 8 );
	this->Add( new CListview(), nc_UserList, iWidth - 140, 0, 140, iHeight);
	this->Add( new CTextbox(), nc_ChatInput, 0,  iHeight - tLX->cFont.GetHeight() - 2, iWidth - 145, tLX->cFont.GetHeight());

	// Messages
	CBrowser *b = (CBrowser *)this->getWidget(nc_ChatText);
	b->InitializeChatBox();

	chatWidgets.insert(this);

	IRCClient *irc = GetGlobalIRC();
	if (irc)
		for (std::list<IRCClient::IRCChatLine>::const_iterator it = irc->getMessageList().begin();
			it != irc->getMessageList().end(); it++)  {
				ChatWidget_ChatNewMessage(it->text, it->type);
		}

	ChatWidget_ChatRegisterCallbacks();
	ChatWidget_ChatRefillUserList();

	CGuiSkinnedLayout::Create();

}

void CChatWidget::Destroy()
{
	chatWidgets.erase(this);
	if( chatWidgets.empty() )
		ChatWidget_ChatDeregisterCallbacks();
	CGuiSkinnedLayout::Destroy();
}

void CChatWidget::EnableChat()
{
	ChatWidget_ChatRegisterCallbacks();
};
void CChatWidget::DisableChat()
{
	ChatWidget_ChatDeregisterCallbacks();
	for( std::set<CChatWidget *> :: iterator cw = chatWidgets.begin(); cw != chatWidgets.end(); cw++ )
	{
		((CListview *)(*cw)->getWidget(nc_UserList))->Clear();
	}
};

{'fraction_non_alphanumeric': 0.1918165989553105, 'fraction_numerical': 0.008415554265815438, 'mean_word_length': 4.20619335347432, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646752', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2436, 'n_words': 495}