Ejemplo n.º 1
0
void cleanup_text_buffers(void)
{
	int i;

	free_text_message_data (&input_text_line);
	for(i = 0; i < DISPLAY_TEXT_BUFFER_SIZE; i++)
		free_text_message_data (display_text_buffer + i);
}
Ejemplo n.º 2
0
void close_ipu (INPUT_POPUP *ipu)
{
	if (ipu->popup_win > 0)
	{
		destroy_window(ipu->popup_win);
		clear_text_message_data (&ipu->popup_text);
		free_text_message_data (&ipu->popup_text);
		init_ipu(ipu, -1, 200, 100, 10, 1, NULL, NULL);
	}
}
Ejemplo n.º 3
0
static int notepad_remove_category(widget_list* UNUSED(w),
	int UNUSED(mx), int UNUSED(my), Uint32 flags)
{
	static Uint32 last_click = 0;
	int i, id = -1, cur_tab, t;

	// only handle mouse button clicks, not scroll wheels moves
	if ( (flags & ELW_MOUSE_BUTTON) == 0) return 0;

	if (!safe_button_click(&last_click))
		return 1;

	t = tab_collection_get_tab_id (notepad_win, note_tabcollection_id);
	cur_tab = tab_collection_get_tab (notepad_win, note_tabcollection_id);

	for (i = 0; i < nr_notes; i++)
	{
		if (t == note_list[i].window)
		{
			id = i;
			break;
		}
	}
	if (id >= nr_notes || id == -1)
	{
		return 0;
	}

	tab_collection_close_tab (notepad_win, note_tabcollection_id, cur_tab);
	widget_destroy (main_note_tab_id, note_list[id].button_id);
	free_text_message_data (&(note_list[id].text));

	// shift all notes after the deleted note one up
	if (id < nr_notes-1)
	{
		memmove (&(note_list[id]), &(note_list[id+1]), (nr_notes-id-1) * sizeof (note));
		for ( ; id < nr_notes-1; id++)
			note_button_set_pos (id);
	}
	nr_notes--;

	update_note_button_scrollbar(0);

	return 1;
}
Ejemplo n.º 4
0
void clear_display_text_buffer ()
{
	int i;
	for (i = 0; i < DISPLAY_TEXT_BUFFER_SIZE; ++i)
	{
		if (!display_text_buffer[i].deleted && display_text_buffer[i].data != NULL && display_text_buffer[i].data[0] != '\0'){
			free_text_message_data (display_text_buffer + i);
		}
		display_text_buffer[i].deleted= 1;
	}

	last_message = -1;
	last_server_message_time = cur_time;

	clear_console();
	if(use_windowed_chat == 2){
		clear_chat_wins();
	}
}
Ejemplo n.º 5
0
void put_colored_text_in_buffer (Uint8 color, Uint8 channel, const Uint8 *text_to_add, int len)
{
	text_message *msg;
	int minlen, text_color;
	Uint32 cnr = 0, ibreak = -1, jbreak = -1;
	char time_stamp[12];
	struct tm *l_time; time_t c_time;

	check_chat_text_to_overtext (text_to_add, len, channel);

	// check for auto-length
	if (len < 0)
		len = strlen ((char*)text_to_add);

	// set the time when we got this message
	last_server_message_time = cur_time;

	// if the buffer is full, delete some old lines and move the remainder to the front
	if (++last_message >= DISPLAY_TEXT_BUFFER_SIZE)
	{
		const size_t num_move = DISPLAY_TEXT_BUFFER_SIZE - DISPLAY_TEXT_BUFFER_DEL;
		size_t i;
		for (i=0; i<DISPLAY_TEXT_BUFFER_DEL; i++)
		{
			msg = &(display_text_buffer[i]);
			if (msg->data)
			{
				msg->deleted = 1;
				update_text_windows(msg);
				free_text_message_data (msg);
			}
		}
		memmove(display_text_buffer, &display_text_buffer[DISPLAY_TEXT_BUFFER_DEL], sizeof(text_message)*num_move);
		last_message -= DISPLAY_TEXT_BUFFER_DEL;
		for (i = num_move; i < DISPLAY_TEXT_BUFFER_SIZE; i++)
			init_text_message (display_text_buffer + i, 0);
	}

	msg = &(display_text_buffer[last_message]);

	// Try to make a guess at the number of wrapping newlines required,
	// but allow al least for a null byte and up to 8 extra newlines and
	// colour codes
	minlen = len + 18 + (len/60);
	if (show_timestamp)
	{
		minlen += 12;
		time (&c_time);
		l_time = localtime (&c_time);
		strftime (time_stamp, sizeof(time_stamp), "[%H:%M:%S] ", l_time);
	}
	cnr = get_active_channel (channel);
	if (cnr != 0)
		// allow some space for the channel number
		minlen += 20;
	if (msg->data == NULL)
		alloc_text_message_data (msg, minlen);
	else
		resize_text_message_data (msg, minlen);

	if (cnr != 0)
	{
		for (ibreak = 0; ibreak < len; ibreak++)
		{
			if (text_to_add[ibreak] == ']') break;
		}
	}

	if (channel == CHAT_LOCAL)
	{
		for (jbreak = 0; jbreak < len; jbreak++)
		{
			if (text_to_add[jbreak] == ':' && text_to_add[jbreak+1] == ' ') break;
		}
	}

	if (dark_channeltext==1)
		text_color = c_grey2;
	else if (dark_channeltext==2)
		text_color = c_grey4;

	if (ibreak >= len)
	{
		// not a channel, or something's messed up
		if(!is_color (text_to_add[0]))
		{
			// force the color
			if (show_timestamp)
			{
				safe_snprintf (msg->data, msg->size, "%c%s%.*s", to_color_char (color), time_stamp, len, text_to_add);
			}
			else
			{
				safe_snprintf (msg->data, msg->size, "%c%.*s", to_color_char (color), len, text_to_add);
			}
		}
		else
		{
			// color set by server
			if (show_timestamp)
			{
				if(dark_channeltext && channel==CHAT_LOCAL && from_color_char(text_to_add[0])==c_grey1 && jbreak < (len-3))
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s%.*s", to_color_char (text_color), time_stamp, jbreak+1, &text_to_add[1], len-jbreak-3, &text_to_add[jbreak+3]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s", text_to_add[0], time_stamp, len-1, &text_to_add[1]);
				}
			}
			else
			{
				if(dark_channeltext && channel==CHAT_LOCAL && from_color_char(text_to_add[0])==c_grey1 && jbreak < (len-3))
				{
					safe_snprintf (msg->data, msg->size, "%c%.*s%.*s", to_color_char (text_color), jbreak+1, &text_to_add[1], len-jbreak-3, &text_to_add[jbreak+3]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%.*s", len, text_to_add);
				}
			}
		}
	}
	else
	{
		char nr_str[16];
		int has_additional_color = is_color(text_to_add[ibreak+3]);
		if (cnr >= 1000000000)
			safe_snprintf (nr_str, sizeof (nr_str), "guild");
		else
			safe_snprintf (nr_str, sizeof (nr_str), "%u", cnr);

		if(!is_color (text_to_add[0]))
		{
			// force the color
			if (show_timestamp)
			{
				if (dark_channeltext)
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s @ %s%.*s%c%.*s", to_color_char (color), time_stamp, ibreak, text_to_add, nr_str, 3, &text_to_add[ibreak], to_color_char (text_color), len-ibreak-3-has_additional_color, &text_to_add[ibreak+3+has_additional_color]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s @ %s%.*s", to_color_char (color), time_stamp, ibreak, text_to_add, nr_str, len-ibreak, &text_to_add[ibreak]);
				}
			}
			else
			{
				if (dark_channeltext)
				{
					safe_snprintf (msg->data, msg->size, "%c%.*s @ %s%.*s%c%.*s", to_color_char (color), ibreak, text_to_add, nr_str, 3, &text_to_add[ibreak], to_color_char (text_color), len-ibreak-3-has_additional_color, &text_to_add[ibreak+3+has_additional_color]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%c%.*s @ %s%.*s", to_color_char (color), ibreak, text_to_add, nr_str, len-ibreak, &text_to_add[ibreak]);
				}
			}
		}
		else
		{
			// color set by server
			if (show_timestamp)
			{
				if (dark_channeltext)
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s @ %s%.*s%c%.*s", text_to_add[0], time_stamp, ibreak-1, &text_to_add[1], nr_str, 3, &text_to_add[ibreak], to_color_char (text_color), len-ibreak-3-has_additional_color, &text_to_add[ibreak+3+has_additional_color]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%c%s%.*s @ %s%.*s", text_to_add[0], time_stamp, ibreak-1, &text_to_add[1], nr_str, len-ibreak, &text_to_add[ibreak]);
				}
			}
			else
			{
				if (dark_channeltext)
				{
					safe_snprintf (msg->data, msg->size, "%.*s @ %s%.*s%c%.*s", ibreak, text_to_add, nr_str, 3, &text_to_add[ibreak], to_color_char (text_color), len-ibreak-3-has_additional_color, &text_to_add[ibreak+3+has_additional_color]);
				}
				else
				{
					safe_snprintf (msg->data, msg->size, "%.*s @ %s%.*s", ibreak, text_to_add, nr_str, len-ibreak, &text_to_add[ibreak]);
				}
			}
		}
	}

	msg->len = strlen (msg->data);
	msg->chan_idx = channel;
	msg->channel = cnr;

	// set invalid wrap data to force rewrapping
	msg->wrap_lines = 0;
	msg->wrap_zoom = 0.0f;
	msg->wrap_width = 0;

	msg->deleted = 0;
	recolour_message(msg);
	update_text_windows(msg);

	// log the message
	write_to_log (channel, (unsigned char*)msg->data, msg->len);

	return;
}