diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c index f8ca6210..793352f6 100644 --- a/textscreen/txt_button.c +++ b/textscreen/txt_button.c @@ -21,13 +21,14 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" static void TXT_ButtonSizeCalc(TXT_UNCAST_ARG(button)) { TXT_CAST_ARG(txt_button_t, button); - button->widget.w = strlen(button->label); + button->widget.w = TXT_UTF8_Strlen(button->label); button->widget.h = 1; } @@ -41,9 +42,9 @@ static void TXT_ButtonDrawer(TXT_UNCAST_ARG(button)) TXT_SetWidgetBG(button); - TXT_DrawString(button->label); + TXT_DrawUTF8String(button->label); - for (i=strlen(button->label); i < w; ++i) + for (i = TXT_UTF8_Strlen(button->label); i < w; ++i) { TXT_DrawString(" "); } diff --git a/textscreen/txt_button.h b/textscreen/txt_button.h index c1631452..cde528f6 100644 --- a/textscreen/txt_button.h +++ b/textscreen/txt_button.h @@ -41,7 +41,7 @@ struct txt_button_s /** * Create a new button widget. * - * @param label The label to use on the new button. + * @param label The label to use on the new button (UTF-8 format). * @return Pointer to the new button widget. */ @@ -51,7 +51,7 @@ txt_button_t *TXT_NewButton(char *label); * Create a new button widget, binding the "pressed" signal to a * specified callback function. * - * @param label The label to use on the new button. + * @param label The label to use on the new button (UTF-8 format). * @param func The callback function to invoke. * @param user_data User-specified pointer to pass to the callback. * @return Pointer to the new button widget. @@ -64,7 +64,7 @@ txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func, * Change the label used on a button. * * @param button The button. - * @param label The new label. + * @param label The new label (UTF-8 format). */ void TXT_SetButtonLabel(txt_button_t *button, char *label); diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c index 0b2c2e3b..57256d93 100644 --- a/textscreen/txt_checkbox.c +++ b/textscreen/txt_checkbox.c @@ -21,6 +21,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" static void TXT_CheckBoxSizeCalc(TXT_UNCAST_ARG(checkbox)) @@ -29,7 +30,7 @@ static void TXT_CheckBoxSizeCalc(TXT_UNCAST_ARG(checkbox)) // Minimum width is the string length + right-side space for padding - checkbox->widget.w = strlen(checkbox->label) + 5; + checkbox->widget.w = TXT_UTF8_Strlen(checkbox->label) + 5; checkbox->widget.h = 1; } @@ -63,9 +64,9 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox)) TXT_RestoreColors(&colors); TXT_SetWidgetBG(checkbox); - TXT_DrawString(checkbox->label); + TXT_DrawUTF8String(checkbox->label); - for (i=strlen(checkbox->label); i < w-4; ++i) + for (i = TXT_UTF8_Strlen(checkbox->label); i < w-4; ++i) { TXT_DrawString(" "); } diff --git a/textscreen/txt_checkbox.h b/textscreen/txt_checkbox.h index ec344e16..08f37d44 100644 --- a/textscreen/txt_checkbox.h +++ b/textscreen/txt_checkbox.h @@ -49,7 +49,7 @@ struct txt_checkbox_s /** * Create a new checkbox. * - * @param label The label for the new checkbox. + * @param label The label for the new checkbox (UTF-8 format). * @param variable Pointer to the variable containing this checkbox's * value. * @return Pointer to the new checkbox. @@ -63,7 +63,7 @@ txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable); * An inverted checkbox displays the opposite of a normal checkbox; * where it would be checked, it appears unchecked, and vice-versa. * - * @param label The label for the new checkbox. + * @param label The label for the new checkbox (UTF-8 format). * @param variable Pointer to the variable containing this checkbox's * value. * @return Pointer to the new checkbox. diff --git a/textscreen/txt_desktop.h b/textscreen/txt_desktop.h index 3c6cf12b..c8f5d543 100644 --- a/textscreen/txt_desktop.h +++ b/textscreen/txt_desktop.h @@ -36,7 +36,7 @@ int TXT_WindowKeyPress(txt_window_t *window, int c); /** * Set the title displayed at the top of the screen. * - * @param title The title to display. + * @param title The title to display (UTF-8 format). */ void TXT_SetDesktopTitle(char *title); diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c index e49ebb33..a342b70a 100644 --- a/textscreen/txt_dropdown.c +++ b/textscreen/txt_dropdown.c @@ -22,9 +22,10 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" -typedef struct +typedef struct { txt_window_t *window; txt_dropdown_list_t *list; @@ -196,7 +197,7 @@ static int DropdownListWidth(txt_dropdown_list_t *list) for (i=0; inum_values; ++i) { - int w = strlen(list->values[i]); + int w = TXT_UTF8_Strlen(list->values[i]); if (w > result) { result = w; @@ -238,9 +239,9 @@ static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list)) // Draw the string and fill to the end with spaces - TXT_DrawString(str); + TXT_DrawUTF8String(str); - for (i=strlen(str); iwidget.w; ++i) + for (i = TXT_UTF8_Strlen(str); i < list->widget.w; ++i) { TXT_DrawString(" "); } diff --git a/textscreen/txt_dropdown.h b/textscreen/txt_dropdown.h index bb2f12b8..ca21ec8d 100644 --- a/textscreen/txt_dropdown.h +++ b/textscreen/txt_dropdown.h @@ -57,7 +57,7 @@ struct txt_dropdown_list_s * @param variable Pointer to the variable containing the * list's value. * @param values Pointer to an array of strings containing - * the labels to use for the list. + * the labels to use for the list (UTF-8 format). * @param num_values The number of variables in the list. */ diff --git a/textscreen/txt_fileselect.h b/textscreen/txt_fileselect.h index ffba4064..c72c6135 100644 --- a/textscreen/txt_fileselect.h +++ b/textscreen/txt_fileselect.h @@ -56,7 +56,7 @@ char *TXT_SelectFile(char *prompt, char **extensions); * Create a new txt_fileselect_t widget. * * @param variable Pointer to a char * variable in which the selected - * file should be stored. + * file should be stored (UTF-8 format). * @param size Width of the file selector widget in characters. * @param prompt Pointer to a string containing a prompt to display * in the file selection window. diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index c85f3b8a..567e2794 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -92,7 +92,7 @@ void TXT_DrawDesktopBackground(const char *title) TXT_BGColor(TXT_COLOR_GREY, 0); TXT_DrawString(" "); - TXT_DrawString(title); + TXT_DrawUTF8String(title); } void TXT_DrawShadow(int x, int y, int w, int h) @@ -167,8 +167,8 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) TXT_DrawString(" "); } - TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1); - TXT_DrawString(title); + TXT_GotoXY(x + (w - TXT_UTF8_Strlen(title)) / 2, y + 1); + TXT_DrawUTF8String(title); } // Draw the window's shadow. diff --git a/textscreen/txt_inputbox.h b/textscreen/txt_inputbox.h index eb05fb00..7396eebd 100644 --- a/textscreen/txt_inputbox.h +++ b/textscreen/txt_inputbox.h @@ -49,10 +49,11 @@ struct txt_inputbox_s * * @param value Pointer to a string variable that contains * a pointer to the current value of the - * input box. The value should be allocated + * input box. The value should be allocated * dynamically; when the string is changed it * will be freed and the variable set to point - * to the new string value. + * to the new string value. String will be in + * UTF-8 format. * @param size Width of the input box, in characters. * @return Pointer to the new input box widget. */ diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c index 79bd770d..25975585 100644 --- a/textscreen/txt_label.c +++ b/textscreen/txt_label.c @@ -36,7 +36,7 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) unsigned int x, y; int origin_x, origin_y; unsigned int align_indent = 0; - unsigned int w; + unsigned int w, sw; w = label->widget.w; @@ -53,19 +53,19 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) for (y=0; yh; ++y) { - // Calculate the amount to indent this line due to the align + // Calculate the amount to indent this line due to the align // setting - + sw = TXT_UTF8_Strlen(label->lines[y]); switch (label->widget.align) { case TXT_HORIZ_LEFT: align_indent = 0; break; case TXT_HORIZ_CENTER: - align_indent = (label->w - strlen(label->lines[y])) / 2; + align_indent = (label->w - sw) / 2; break; case TXT_HORIZ_RIGHT: - align_indent = label->w - strlen(label->lines[y]); + align_indent = label->w - sw; break; } @@ -83,7 +83,7 @@ static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) // The string itself TXT_DrawUTF8String(label->lines[y]); - x += TXT_UTF8_Strlen(label->lines[y]); + x += sw; // Gap at the end diff --git a/textscreen/txt_label.h b/textscreen/txt_label.h index 458e7ff7..3786843a 100644 --- a/textscreen/txt_label.h +++ b/textscreen/txt_label.h @@ -45,7 +45,7 @@ struct txt_label_s /** * Create a new label widget. * - * @param label String to display in the widget. + * @param label String to display in the widget (UTF-8 format). * @return Pointer to the new label widget. */ @@ -55,7 +55,7 @@ txt_label_t *TXT_NewLabel(char *label); * Set the string displayed in a label widget. * * @param label The widget. - * @param value The string to display. + * @param value The string to display (UTF-8 format). */ void TXT_SetLabel(txt_label_t *label, char *value); diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h index b92869d0..1565f0bf 100644 --- a/textscreen/txt_main.h +++ b/textscreen/txt_main.h @@ -154,7 +154,7 @@ int TXT_GetModifierState(txt_modifier_t mod); // keyboard (like that returned by TXT_INPUT_RAW), and the resulting string // takes keyboard layout into consideration. For example, // TXT_GetKeyDescription('q') on a French keyboard returns "A". -// The contents of the filled buffer will be in UTF8 format, but will never +// The contents of the filled buffer will be in UTF-8 format, but will never // contain characters which can't be shown on the screen. void TXT_GetKeyDescription(int key, char *buf, size_t buf_len); diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c index 0a37b828..aaeaa515 100644 --- a/textscreen/txt_radiobutton.c +++ b/textscreen/txt_radiobutton.c @@ -21,6 +21,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" static void TXT_RadioButtonSizeCalc(TXT_UNCAST_ARG(radiobutton)) @@ -29,7 +30,7 @@ static void TXT_RadioButtonSizeCalc(TXT_UNCAST_ARG(radiobutton)) // Minimum width is the string length + right-side spaces for padding - radiobutton->widget.w = strlen(radiobutton->label) + 5; + radiobutton->widget.w = TXT_UTF8_Strlen(radiobutton->label) + 5; radiobutton->widget.h = 1; } @@ -64,9 +65,9 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton)) TXT_RestoreColors(&colors); TXT_SetWidgetBG(radiobutton); - TXT_DrawString(radiobutton->label); + TXT_DrawUTF8String(radiobutton->label); - for (i=strlen(radiobutton->label); i < w-5; ++i) + for (i=TXT_UTF8_Strlen(radiobutton->label); i < w-5; ++i) { TXT_DrawString(" "); } diff --git a/textscreen/txt_radiobutton.h b/textscreen/txt_radiobutton.h index dd751f23..ec5eead8 100644 --- a/textscreen/txt_radiobutton.h +++ b/textscreen/txt_radiobutton.h @@ -54,7 +54,8 @@ struct txt_radiobutton_s /** * Create a new radio button widget. * - * @param label The label to display next to the radio button. + * @param label The label to display next to the radio button + * (UTF-8 format). * @param variable Pointer to the variable tracking whether this * radio button is selected. * @param value If the variable is equal to this value, the @@ -68,7 +69,7 @@ txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value); * Set the label on a radio button. * * @param radiobutton The radio button. - * @param value The new label. + * @param value The new label (UTF-8 format). */ void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, char *value); diff --git a/textscreen/txt_separator.c b/textscreen/txt_separator.c index d59a81fa..a8a2c5f4 100644 --- a/textscreen/txt_separator.c +++ b/textscreen/txt_separator.c @@ -19,6 +19,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" static void TXT_SeparatorSizeCalc(TXT_UNCAST_ARG(separator)) @@ -29,7 +30,7 @@ static void TXT_SeparatorSizeCalc(TXT_UNCAST_ARG(separator)) { // Minimum width is the string length + two spaces for padding - separator->widget.w = strlen(separator->label) + 2; + separator->widget.w = TXT_UTF8_Strlen(separator->label) + 2; } else { @@ -53,14 +54,14 @@ static void TXT_SeparatorDrawer(TXT_UNCAST_ARG(separator)) // to overlap the window borders. TXT_DrawSeparator(x-2, y, w + 4); - + if (separator->label != NULL) { TXT_GotoXY(x, y); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); TXT_DrawString(" "); - TXT_DrawString(separator->label); + TXT_DrawUTF8String(separator->label); TXT_DrawString(" "); } } diff --git a/textscreen/txt_separator.h b/textscreen/txt_separator.h index da88f611..a9948c45 100644 --- a/textscreen/txt_separator.h +++ b/textscreen/txt_separator.h @@ -45,8 +45,8 @@ extern txt_widget_class_t txt_separator_class; /** * Create a new horizontal separator widget. * - * @param label Label to display on the separator. If this is - * set to NULL, no label is displayed. + * @param label Label to display on the separator (UTF-8 format). + * If this is set to NULL, no label is displayed. * @return The new separator widget. */ @@ -56,7 +56,7 @@ txt_separator_t *TXT_NewSeparator(char *label); * Change the label on a separator. * * @param separator The separator. - * @param label The new label. + * @param label The new label (UTF-8 format). */ void TXT_SetSeparatorLabel(txt_separator_t *separator, char *label); diff --git a/textscreen/txt_spinctrl.c b/textscreen/txt_spinctrl.c index 605c0848..04838ec1 100644 --- a/textscreen/txt_spinctrl.c +++ b/textscreen/txt_spinctrl.c @@ -24,6 +24,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" // Generate the format string to be used for displaying floats @@ -143,6 +144,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) unsigned int i; unsigned int padding; txt_saved_colors_t colors; + int bw; int focused; focused = spincontrol->widget.focused; @@ -172,7 +174,8 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) i = 0; - padding = spincontrol->widget.w - strlen(spincontrol->buffer) - 4; + bw = TXT_UTF8_Strlen(spincontrol->buffer); + padding = spincontrol->widget.w - bw - 4; while (i < padding) { @@ -180,8 +183,8 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol)) ++i; } - TXT_DrawString(spincontrol->buffer); - i += strlen(spincontrol->buffer); + TXT_DrawUTF8String(spincontrol->buffer); + i += bw; while (i < spincontrol->widget.w - 4) { @@ -203,7 +206,8 @@ static void TXT_SpinControlDestructor(TXT_UNCAST_ARG(spincontrol)) static void AddCharacter(txt_spincontrol_t *spincontrol, int key) { - if (strlen(spincontrol->buffer) < SpinControlWidth(spincontrol)) + if (TXT_UTF8_Strlen(spincontrol->buffer) < SpinControlWidth(spincontrol) + && strlen(spincontrol->buffer) < spincontrol->buffer_len - 2) { spincontrol->buffer[strlen(spincontrol->buffer) + 1] = '\0'; spincontrol->buffer[strlen(spincontrol->buffer)] = key; @@ -212,7 +216,7 @@ static void AddCharacter(txt_spincontrol_t *spincontrol, int key) static void Backspace(txt_spincontrol_t *spincontrol) { - if (strlen(spincontrol->buffer) > 0) + if (TXT_UTF8_Strlen(spincontrol->buffer) > 0) { spincontrol->buffer[strlen(spincontrol->buffer) - 1] = '\0'; } diff --git a/textscreen/txt_window.h b/textscreen/txt_window.h index 412bad4f..13a0e171 100644 --- a/textscreen/txt_window.h +++ b/textscreen/txt_window.h @@ -94,7 +94,8 @@ struct txt_window_s /** * Open a new window. * - * @param title Title to display in the titlebar of the new window. + * @param title Title to display in the titlebar of the new window + * (UTF-8 format). * @return Pointer to a new @ref txt_window_t structure * representing the new window. */ @@ -191,8 +192,8 @@ void TXT_SetMouseListener(txt_window_t *window, /** * Open a window displaying a message. * - * @param title Title of the window. - * @param message The message to display in the window. + * @param title Title of the window (UTF-8 format). + * @param message The message to display in the window (UTF-8 format). * @return The new window. */ diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index 94210d56..750c43eb 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -22,6 +22,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" #include "txt_window.h" static void TXT_WindowActionSizeCalc(TXT_UNCAST_ARG(action)) @@ -34,7 +35,8 @@ static void TXT_WindowActionSizeCalc(TXT_UNCAST_ARG(action)) // Width is label length, plus key description length, plus '=' // and two surrounding spaces. - action->widget.w = strlen(action->label) + strlen(buf) + 3; + action->widget.w = TXT_UTF8_Strlen(action->label) + + TXT_UTF8_Strlen(buf) + 3; action->widget.h = 1; } @@ -52,12 +54,12 @@ static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action)) TXT_DrawString(" "); TXT_FGColor(TXT_COLOR_BRIGHT_GREEN); - TXT_DrawString(buf); + TXT_DrawUTF8String(buf); TXT_FGColor(TXT_COLOR_BRIGHT_CYAN); TXT_DrawString("="); TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); - TXT_DrawString(action->label); + TXT_DrawUTF8String(action->label); TXT_DrawString(" "); } diff --git a/textscreen/txt_window_action.h b/textscreen/txt_window_action.h index 08c1e1ee..5a2f6b02 100644 --- a/textscreen/txt_window_action.h +++ b/textscreen/txt_window_action.h @@ -48,7 +48,7 @@ struct txt_window_action_s * * @param key The keyboard key that triggers this action. * @param label Label to display for this action in the tray - * at the bottom of the window. + * at the bottom of the window (UTF-8 format). * @return Pointer to the new window action widget. */