Exemplo n.º 1
0
/***********************************************************
handle send button event
***********************************************************/
bool ChatBox::HandleEnterKey (const CEGUI::EventArgs& e)
{
	const CEGUI::KeyEventArgs& we =
    static_cast<const CEGUI::KeyEventArgs&>(e);

	const CEGUI::WindowEventArgs& wine =
    static_cast<const CEGUI::WindowEventArgs&>(e);


	if(we.scancode == CEGUI::Key::LeftControl || we.scancode == CEGUI::Key::RightControl)
	{
		_control_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftShift || we.scancode == CEGUI::Key::RightShift)
	{
		_shift_key_on = true;
		return true;
	}


	if(wine.window->getName() == "Chat/edit")
	{
		if(we.scancode == CEGUI::Key::Return)
		{
			HandleSend (e);

			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
			(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			bed->deactivate();
			return true;
		}

		if(we.scancode == CEGUI::Key::ArrowUp)
		{
			if(_itltext == _lasttexts.end())
				_itltext = _lasttexts.begin();
			else
			{
				std::list<std::string>::iterator ittmp = _itltext;
				++ittmp;
				if(ittmp != _lasttexts.end())
					++_itltext;
			}

			try
			{
				if(_itltext != _lasttexts.end())
				{
					CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText(
														(const unsigned char *)_itltext->c_str());
				}
				else
				{
					CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText("");
				}
			}
			catch(...){}

			return true;
		}
		if(we.scancode == CEGUI::Key::ArrowDown)
		{
			if(_itltext != _lasttexts.end())
			{
				if(_itltext != _lasttexts.begin())
					--_itltext;
				else
					_itltext = _lasttexts.end();
			}

			if(_itltext != _lasttexts.end())
			{
				CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText(
													(const unsigned char *)_itltext->c_str());
			}
			else
			{
				CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText("");
			}

			return true;
		}


		if(we.scancode == CEGUI::Key::ArrowUp || we.scancode == CEGUI::Key::ArrowDown)
			return true;



		// paste text
		if(we.scancode == CEGUI::Key::V && _control_key_on)
		{
			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
				(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			if(bed->isActive())
			{
				if(_text_copyed != "")
				{
					size_t selB = bed->getSelectionStartIndex();
					size_t selE = bed->getSelectionLength();
					CEGUI::String str = bed->getText();
					if(selE > 0)
					{
						str = str.erase(selB, selE);
					}

					if(str.size() + _text_copyed.size() < bed->getMaxTextLength())
					{
						size_t idx = bed->getCaratIndex();
						str = str.insert(idx, (unsigned char *)_text_copyed.c_str());
						bed->setText(str);
						bed->setCaratIndex(idx + _text_copyed.size());
					}
				}

				return true;
			}
		}
	}



	// copy text
	if(we.scancode == CEGUI::Key::C && _control_key_on)
	{
		CEGUI::Window * actw = _myChat->getActiveChild();
		if(actw != NULL)
		{
			if(actw->getName() == "Chat/edit")
			{
				CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *> (actw);
				size_t selB = bed->getSelectionStartIndex();
				size_t selE = bed->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = bed->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
			else
			{
				CEGUI::MultiLineEditbox* txt = static_cast<CEGUI::MultiLineEditbox *>(actw);
				size_t selB = txt->getSelectionStartIndex();
				size_t selE = txt->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = txt->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
		}

	}

    return false;
}
Exemplo n.º 2
0
/***********************************************************
handle send button event
***********************************************************/
bool ChatBox::HandleEnterKey (const CEGUI::EventArgs& e)
{
	const CEGUI::KeyEventArgs& we =
    static_cast<const CEGUI::KeyEventArgs&>(e);

	const CEGUI::WindowEventArgs& wine =
    static_cast<const CEGUI::WindowEventArgs&>(e);


	if(we.scancode == CEGUI::Key::LeftControl || we.scancode == CEGUI::Key::RightControl)
	{
		_control_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftShift || we.scancode == CEGUI::Key::RightShift)
	{
		_shift_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftAlt || we.scancode == CEGUI::Key::RightAlt)
	{
		return true;
	}

	if(wine.window->getName() == "Chat/edit")
	{
		if(we.scancode == CEGUI::Key::Return)
		{
			HandleSend (e);

			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
			(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			bed->deactivate();
			return true;
		}

		if(we.scancode == CEGUI::Key::ArrowUp)
		{
			if(_itltext == _lasttexts.end())
				_itltext = _lasttexts.begin();
			else
			{
				std::list<std::string>::iterator ittmp = _itltext;
				++ittmp;
				if(ittmp != _lasttexts.end())
					++_itltext;
			}

			try
			{
				CEGUI::Window *windowchat = CEGUI::WindowManager::getSingleton().getWindow("Chat/edit");
				std::string text = "";
				if(_itltext != _lasttexts.end())
					text = *_itltext;

				if(windowchat)
					windowchat->setText((const unsigned char *)text.c_str());
			}
			catch(...){}

			//++_currSelectedch;
			//if(_currSelectedch >= (int)_channels.size())
			//	--_currSelectedch;
			//else
			//{
			//	std::list<std::string>::const_iterator it = _channels.begin();
			//	std::list<std::string>::const_iterator end = _channels.end();
			//	for(int cc=0; cc<_currSelectedch && it != end; ++it, ++cc);

			//	CEGUI::PushButton * bch = static_cast<CEGUI::PushButton *>
			//		(CEGUI::WindowManager::getSingleton().getWindow("Chat/bChannel"));
			//	bch->setProperty("Text", *it);
			//}



			return true;
		}
		if(we.scancode == CEGUI::Key::ArrowDown)
		{
			if(_itltext != _lasttexts.end())
			{
				if(_itltext != _lasttexts.begin())
					--_itltext;
				else
					_itltext = _lasttexts.end();
			}

			CEGUI::Window *windowchat = CEGUI::WindowManager::getSingleton().getWindow("Chat/edit");
			std::string text = "";
			if(_itltext != _lasttexts.end())
				text = *_itltext;

			if(windowchat)
				windowchat->setText((const unsigned char *)text.c_str());


			//--_currSelectedch;
			//if(_currSelectedch < 0)
			//	++_currSelectedch;
			//else
			//{
			//	std::list<std::string>::const_iterator it = _channels.begin();
			//	std::list<std::string>::const_iterator end = _channels.end();
			//	for(int cc=0; cc<_currSelectedch && it != end; ++it, ++cc);

			//	CEGUI::PushButton * bch = static_cast<CEGUI::PushButton *>
			//		(CEGUI::WindowManager::getSingleton().getWindow("Chat/bChannel"));
			//	bch->setProperty("Text", *it);
			//}

			return true;
		}


		if(we.scancode == CEGUI::Key::ArrowUp || we.scancode == CEGUI::Key::ArrowDown)
			return true;



		// paste text
		if(we.scancode == CEGUI::Key::V && _control_key_on)
		{
			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
				(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			if(bed && bed->isActive())
			{
				if(_text_copyed != "")
				{
					size_t selB = bed->getSelectionStartIndex();
					size_t selE = bed->getSelectionLength();
					CEGUI::String str = bed->getText();
					if(selE > 0)
					{
						str = str.erase(selB, selE);
					}

					if(str.size() + _text_copyed.size() < bed->getMaxTextLength())
					{
						size_t idx = bed->getCaratIndex();
						str = str.insert(idx, (unsigned char *)_text_copyed.c_str());
						bed->setText(str);
						bed->setCaratIndex(idx + _text_copyed.size());
					}
				}

				return true;
			}
		}
	}



	// copy text
	if(we.scancode == CEGUI::Key::C && _control_key_on)
	{
		CEGUI::Window * actw = _myChat->getActiveChild();
		if(actw != NULL)
		{
			if(actw->getName() == "Chat/edit")
			{
				CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *> (actw);
				size_t selB = bed->getSelectionStartIndex();
				size_t selE = bed->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = bed->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
			else
			{
				CEGUI::MultiLineEditbox* txt = static_cast<CEGUI::MultiLineEditbox *>(actw);
				size_t selB = txt->getSelectionStartIndex();
				size_t selE = txt->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = txt->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
		}

	}

    return false;
}
Exemplo n.º 3
0
bool GUI_Paste_From_Clipboard( void )
{
	CEGUI::Window *sheet = CEGUI::System::getSingleton().getGUISheet();

	// no sheet
	if( !sheet )
	{
		return 0;
	}

	CEGUI::Window *window_active = sheet->getActiveChild();

	// no active window
	if( !window_active )
	{
		return 0;
	}

	const CEGUI::String &type = window_active->getType();

	// MultiLineEditbox
	if( type.find( "/MultiLineEditbox" ) != CEGUI::String::npos )
	{
		CEGUI::MultiLineEditbox *editbox = static_cast<CEGUI::MultiLineEditbox*>(window_active);

		if( editbox->isReadOnly() )
		{
			return 0;
		}

		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();

		CEGUI::String new_text = editbox->getText();
		// erase selected text
		new_text.erase( beg, len );

		// get clipboard text
		CEGUI::String clipboard_text = reinterpret_cast<const CEGUI::utf8*>(Get_Clipboard_Content().c_str());
		// set new text
		editbox->setText( new_text.insert( beg, clipboard_text ) );
		// set new carat index
		editbox->setCaratIndex( editbox->getCaratIndex() + clipboard_text.length() );
	}
	// Editbox
	else if( type.find( "/Editbox" ) != CEGUI::String::npos )
	{
		CEGUI::Editbox *editbox = static_cast<CEGUI::Editbox*>(window_active);

		if( editbox->isReadOnly() )
		{
			return 0;
		}

		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();

		CEGUI::String new_text = editbox->getText();
		// erase selected text
		new_text.erase( beg, len );

		// get clipboard text
		CEGUI::String clipboard_text = reinterpret_cast<const CEGUI::utf8*>(Get_Clipboard_Content().c_str());
		// set new text
		editbox->setText( new_text.insert( beg, clipboard_text ) );
		// set new carat index
		editbox->setCaratIndex( editbox->getCaratIndex() + clipboard_text.length() );
	}
	else
	{
		return 0;
	}

	return 1;
}