Fix for paste clamping the string length to UI_MAX_DRAW_STR

This commit is contained in:
Campbell Barton 2014-05-03 06:06:19 +10:00
parent fc591473b2
commit 43d5e54a79

@ -1675,7 +1675,9 @@ static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleB
/* c = copy, v = paste */
static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, char mode)
{
char buf[UI_MAX_DRAW_STR + 1] = {0};
int buf_paste_len = 0;
const char *buf_paste = "";
bool buf_paste_alloc = false;
if (mode == 'v' && but->lock == true) {
return;
@ -1690,14 +1692,18 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if (mode == 'v') {
/* extract first line from clipboard in case of multi-line copies */
int pbuf_len;
char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len);
if (pbuf) {
BLI_strncpy(buf, pbuf, sizeof(buf));
MEM_freeN(pbuf);
const char *buf_paste_test;
buf_paste_test = WM_clipboard_text_get_firstline(false, &buf_paste_len);
if (buf_paste_test) {
buf_paste = buf_paste_test;
buf_paste_alloc = true;
}
}
/* No return from here down */
/* numeric value */
if (ELEM(but->type, NUM, NUMSLI)) {
@ -1707,18 +1713,19 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
else if (mode == 'c') {
/* Get many decimal places, then strip trailing zeros.
* note: too high values start to give strange results (6 or so is ok) */
ui_get_but_string_ex(but, buf, sizeof(buf), 6);
BLI_str_rstrip_float_zero(buf, '\0');
char buf_copy[UI_MAX_DRAW_STR];
ui_get_but_string_ex(but, buf_copy, sizeof(buf_copy), 6);
BLI_str_rstrip_float_zero(buf_copy, '\0');
WM_clipboard_text_set(buf, 0);
WM_clipboard_text_set(buf_copy, 0);
}
else {
double val;
if (ui_set_but_string_eval_num(C, but, buf, &val)) {
if (ui_set_but_string_eval_num(C, but, buf_paste, &val)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
data->value = val;
ui_set_but_string(C, but, buf);
ui_set_but_string(C, but, buf_paste);
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
}
@ -1732,12 +1739,13 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
/* pass */
}
else if (mode == 'c') {
char buf_copy[UI_MAX_DRAW_STR];
ui_get_but_vectorf(but, xyz);
BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f]", xyz[0], xyz[1], xyz[2]);
WM_clipboard_text_set(buf, 0);
BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f]", xyz[0], xyz[1], xyz[2]);
WM_clipboard_text_set(buf_copy, 0);
}
else {
if (sscanf(buf, "[%f, %f, %f]", &xyz[0], &xyz[1], &xyz[2]) == 3) {
if (sscanf(buf_paste, "[%f, %f, %f]", &xyz[0], &xyz[1], &xyz[2]) == 3) {
if (normalize_v3(xyz) == 0.0f) {
/* better set Z up then have a zero vector */
xyz[2] = 1.0;
@ -1758,6 +1766,8 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
/* pass */
}
else if (mode == 'c') {
char buf_copy[UI_MAX_DRAW_STR];
if (but->rnaprop && RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4)
rgba[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
else
@ -1768,12 +1778,12 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
srgb_to_linearrgb_v3_v3(rgba, rgba);
BLI_snprintf(buf, sizeof(buf), "[%f, %f, %f, %f]", rgba[0], rgba[1], rgba[2], rgba[3]);
WM_clipboard_text_set(buf, 0);
BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f, %f]", rgba[0], rgba[1], rgba[2], rgba[3]);
WM_clipboard_text_set(buf_copy, 0);
}
else {
if (sscanf(buf, "[%f, %f, %f, %f]", &rgba[0], &rgba[1], &rgba[2], &rgba[3]) == 4) {
if (sscanf(buf_paste, "[%f, %f, %f, %f]", &rgba[0], &rgba[1], &rgba[2], &rgba[3]) == 4) {
/* assume linear colors in buffer */
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
linearrgb_to_srgb_v3_v3(rgba, rgba);
@ -1797,7 +1807,6 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
}
else if (mode == 'c') {
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
BLI_strncpy(buf, active_data->str, UI_MAX_DRAW_STR);
WM_clipboard_text_set(active_data->str, 0);
active_data->cancel = true;
button_activate_state(C, but, BUTTON_STATE_EXIT);
@ -1805,8 +1814,10 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
else {
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
if (ui_is_but_utf8(but)) BLI_strncpy_utf8(active_data->str, buf, active_data->maxlen);
else BLI_strncpy(active_data->str, buf, active_data->maxlen);
if (ui_is_but_utf8(but))
BLI_strncpy_utf8(active_data->str, buf_paste, active_data->maxlen);
else
BLI_strncpy(active_data->str, buf_paste, active_data->maxlen);
if (ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)) {
/* else uiSearchboxData.active member is not updated [#26856] */
@ -1819,43 +1830,39 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
/* colorband (not supported by system clipboard) */
else if (but->type == BUT_COLORBAND) {
if (mode == 'c') {
if (but->poin == NULL)
return;
memcpy(&but_copypaste_coba, but->poin, sizeof(ColorBand));
if (but->poin != NULL) {
memcpy(&but_copypaste_coba, but->poin, sizeof(ColorBand));
}
}
else {
if (but_copypaste_coba.tot == 0)
return;
if (but_copypaste_coba.tot != 0) {
if (!but->poin)
but->poin = MEM_callocN(sizeof(ColorBand), "colorband");
if (!but->poin)
but->poin = MEM_callocN(sizeof(ColorBand), "colorband");
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand));
button_activate_state(C, but, BUTTON_STATE_EXIT);
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand));
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
}
}
else if (but->type == BUT_CURVE) {
if (mode == 'c') {
if (but->poin == NULL)
return;
but_copypaste_curve_alive = true;
curvemapping_free_data(&but_copypaste_curve);
curvemapping_copy_data(&but_copypaste_curve, (CurveMapping *) but->poin);
if (but->poin != NULL) {
but_copypaste_curve_alive = true;
curvemapping_free_data(&but_copypaste_curve);
curvemapping_copy_data(&but_copypaste_curve, (CurveMapping *) but->poin);
}
}
else {
if (!but_copypaste_curve_alive)
return;
if (but_copypaste_curve_alive) {
if (!but->poin)
but->poin = MEM_callocN(sizeof(CurveMapping), "curvemapping");
if (!but->poin)
but->poin = MEM_callocN(sizeof(CurveMapping), "curvemapping");
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
curvemapping_free_data((CurveMapping *) but->poin);
curvemapping_copy_data((CurveMapping *) but->poin, &but_copypaste_curve);
button_activate_state(C, but, BUTTON_STATE_EXIT);
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
curvemapping_free_data((CurveMapping *) but->poin);
curvemapping_copy_data((CurveMapping *) but->poin, &but_copypaste_curve);
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
}
}
/* operator button (any type) */
@ -1881,6 +1888,10 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
WM_clipboard_text_set(str, 0);
}
}
if (buf_paste_alloc) {
MEM_freeN((void *)buf_paste);
}
}
/* ************************ password text ******************************