void do_paste_to_text_field(widget_list *widget, const char* text) { text_field *tf; int bytes = strlen(text); text_message* msg; int p; if ((widget == NULL) || (widget->widget_info == NULL)) return; // if not editable, don't allow paste if (!(widget->Flags & TEXT_FIELD_EDITABLE)) return; tf = (text_field *) widget->widget_info; msg = &tf->buffer[tf->msg]; // if can't grow and would over fill, just use what we can if ((msg->len + bytes >= msg->size) && !(widget->Flags & TEXT_FIELD_CAN_GROW)) bytes = msg->size - msg->len - 1; resize_text_message_data (msg, msg->len + bytes); p = tf->cursor; memmove (&msg->data[p + bytes], &msg->data[p], msg->len - p + 1); memcpy (&msg->data[p], text, bytes); msg->len += bytes; tf->cursor += bytes; text_field_find_cursor_line (tf); }
void do_paste_to_text_field(text_field *tf, const char* text) { // XXX FIXME: We should probably check if the text field // is editable, and the data buffer reallocatable. int bytes = strlen(text); text_message* msg = &tf->buffer[tf->msg]; int p; resize_text_message_data (msg, msg->len + bytes); p = tf->cursor; memmove (&msg->data[p + bytes], &msg->data[p], msg->len - p + 1); memcpy (&msg->data[p], text, bytes); msg->len += bytes; tf->cursor += bytes; text_field_find_cursor_line (tf); }
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; }