mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
- Teached ro_gui_set_icon_string() and ro_gui_get_icon_string() about the difference between direct and indirect icons.
- ro_gui_get_icon_string(): - Constify return value of ro_gui_get_icon_string() as you really shouldn't change its contents via this pointer. - Enfore NUL string termination as return value (instead of other control char termination) - Merged ro_gui_set_icon_string_le() into ro_gui_set_icon_string() by adding ro_gui_set_icon_string() and extra to_utf8 parameter. - ro_gui_strncmp(): added svn path=/trunk/netsurf/; revision=4907
This commit is contained in:
parent
039362166c
commit
c40fc354b3
@ -320,7 +320,7 @@ void ro_gui_configure_register(const char *window,
|
||||
|
||||
/* Set the icon's text in current local encoding */
|
||||
ro_gui_set_icon_string(configure_window, tool->i,
|
||||
messages_get(tool->name));
|
||||
messages_get(tool->name), true);
|
||||
|
||||
/* link into our list alphabetically */
|
||||
if ((!configure_tools) ||
|
||||
@ -379,7 +379,7 @@ bool ro_gui_configure_translate(void)
|
||||
for (tool = configure_tools; tool; tool = tool->next) {
|
||||
/* re-translate the text */
|
||||
ro_gui_set_icon_string(configure_window, tool->i,
|
||||
messages_get(tool->name));
|
||||
messages_get(tool->name), true);
|
||||
|
||||
/* update the width */
|
||||
error = xwimptextop_string_width(tool->translated,
|
||||
|
@ -148,7 +148,7 @@ void ro_gui_dialog_init(void)
|
||||
|
||||
/* about us */
|
||||
dialog_info = ro_gui_dialog_create("info");
|
||||
ro_gui_set_icon_string(dialog_info, 4, netsurf_version);
|
||||
ro_gui_set_icon_string(dialog_info, 4, netsurf_version, true);
|
||||
ro_gui_wimp_event_set_help_prefix(dialog_info, "HelpAppInfo");
|
||||
|
||||
/* page info */
|
||||
@ -687,7 +687,7 @@ void ro_gui_dialog_prepare_zoom(struct gui_window *g)
|
||||
{
|
||||
char scale_buffer[8];
|
||||
sprintf(scale_buffer, "%.0f", g->bw->scale * 100);
|
||||
ro_gui_set_icon_string(dialog_zoom, ICON_ZOOM_VALUE, scale_buffer);
|
||||
ro_gui_set_icon_string(dialog_zoom, ICON_ZOOM_VALUE, scale_buffer, true);
|
||||
ro_gui_set_icon_selected_state(dialog_zoom, ICON_ZOOM_FRAMES, true);
|
||||
ro_gui_set_icon_shaded_state(dialog_zoom, ICON_ZOOM_FRAMES,
|
||||
!(g->bw->parent));
|
||||
@ -730,7 +730,7 @@ bool ro_gui_dialog_openurl_apply(wimp_w w) {
|
||||
void ro_gui_dialog_prepare_open_url(void)
|
||||
{
|
||||
int suggestions;
|
||||
ro_gui_set_icon_string(dialog_openurl, ICON_OPENURL_URL, "");
|
||||
ro_gui_set_icon_string(dialog_openurl, ICON_OPENURL_URL, "", true);
|
||||
global_history_get_recent(&suggestions);
|
||||
ro_gui_set_icon_shaded_state(dialog_openurl,
|
||||
ICON_OPENURL_MENU, (suggestions <= 0));
|
||||
|
@ -814,9 +814,9 @@ bool ro_gui_download_keypress(wimp_key *key)
|
||||
return true;
|
||||
|
||||
case wimp_KEY_RETURN: {
|
||||
char *name = ro_gui_get_icon_string(dw->window, ICON_DOWNLOAD_PATH);
|
||||
if (!strrchr(name, '.'))
|
||||
{
|
||||
const char *name = ro_gui_get_icon_string(dw->window,
|
||||
ICON_DOWNLOAD_PATH);
|
||||
if (!strrchr(name, '.')) {
|
||||
warn_user("NoPathError", NULL);
|
||||
return true;
|
||||
}
|
||||
|
@ -2318,7 +2318,7 @@ void warn_user(const char *warning, const char *detail)
|
||||
detail ? detail : "");
|
||||
warn_buffer[sizeof warn_buffer - 1] = 0;
|
||||
ro_gui_set_icon_string(dialog_warning, ICON_WARNING_MESSAGE,
|
||||
warn_buffer);
|
||||
warn_buffer, true);
|
||||
xwimp_set_icon_state(dialog_warning, ICON_WARNING_HELP,
|
||||
wimp_ICON_DELETED, wimp_ICON_DELETED);
|
||||
ro_gui_dialog_open(dialog_warning);
|
||||
|
@ -223,7 +223,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer)
|
||||
return;
|
||||
}
|
||||
|
||||
ro_gui_set_icon_string(dialog_tooltip, 0, url);
|
||||
ro_gui_set_icon_string(dialog_tooltip, 0, url, true);
|
||||
|
||||
/* resize icon appropriately */
|
||||
ic.w = dialog_tooltip;
|
||||
|
@ -249,7 +249,7 @@ void ro_gui_hotlist_prepare_folder_dialog(struct node *node)
|
||||
name = messages_get("Folder");
|
||||
}
|
||||
ro_gui_set_window_title(dialog_folder, title);
|
||||
ro_gui_set_icon_string(dialog_folder, ICON_FOLDER_NAME, name);
|
||||
ro_gui_set_icon_string(dialog_folder, ICON_FOLDER_NAME, name, true);
|
||||
ro_gui_wimp_event_memorise(dialog_folder);
|
||||
}
|
||||
|
||||
@ -277,8 +277,8 @@ void ro_gui_hotlist_prepare_entry_dialog(struct node *node)
|
||||
name = messages_get("Link");
|
||||
}
|
||||
ro_gui_set_window_title(dialog_entry, title);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_NAME, name);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_URL, url);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_NAME, name, true);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_URL, url, true);
|
||||
ro_gui_wimp_event_memorise(dialog_entry);
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ bool ro_gui_hotlist_dialog_apply(wimp_w w)
|
||||
return false;
|
||||
}
|
||||
ro_gui_set_icon_string(w,
|
||||
(url ? ICON_ENTRY_NAME : ICON_FOLDER_NAME), title);
|
||||
url ? ICON_ENTRY_NAME : ICON_FOLDER_NAME, title, true);
|
||||
|
||||
/* update/insert our data */
|
||||
if (!node) {
|
||||
@ -366,7 +366,7 @@ bool ro_gui_hotlist_dialog_apply(wimp_w w)
|
||||
if (element) {
|
||||
free((void *)element->text);
|
||||
element->text = url;
|
||||
ro_gui_set_icon_string(w, ICON_ENTRY_URL, url);
|
||||
ro_gui_set_icon_string(w, ICON_ENTRY_URL, url, true);
|
||||
}
|
||||
free((void *)node->data.text);
|
||||
node->data.text = title;
|
||||
|
@ -904,11 +904,11 @@ void ro_gui_menu_prepare_pageinfo(struct gui_window *g)
|
||||
}
|
||||
}
|
||||
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ICON, icon);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TITLE, title);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_URL, url);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ENC, enc);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TYPE, mime);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ICON, icon, true);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TITLE, title, true);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_URL, url, true);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ENC, enc, true);
|
||||
ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TYPE, mime, true);
|
||||
}
|
||||
|
||||
|
||||
@ -936,10 +936,10 @@ void ro_gui_menu_prepare_objectinfo(struct box *box)
|
||||
if (box->object->mime_type)
|
||||
mime = box->object->mime_type;
|
||||
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_ICON, icon_buf);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_URL, url);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TARGET, target);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TYPE, mime);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_ICON, icon_buf, true);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_URL, url, true);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TARGET, target, true);
|
||||
ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TYPE, mime, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -208,7 +208,8 @@ query_id query_user(const char *query, const char *detail,
|
||||
messages_get(query), detail ? detail : "");
|
||||
query_buffer[sizeof query_buffer - 1] = 0;
|
||||
|
||||
ro_gui_set_icon_string(qw->window, ICON_QUERY_MESSAGE, query_buffer);
|
||||
ro_gui_set_icon_string(qw->window, ICON_QUERY_MESSAGE,
|
||||
query_buffer, true);
|
||||
|
||||
xwimp_set_icon_state(qw->window, ICON_QUERY_HELP,
|
||||
wimp_ICON_DELETED, wimp_ICON_DELETED);
|
||||
|
@ -221,7 +221,7 @@ void ro_gui_save_prepare(gui_save_type save_type, struct content *c)
|
||||
ro_gui_set_icon_sprite(dialog_saveas, ICON_SAVE_ICON, saveas_area,
|
||||
icon_buf);
|
||||
|
||||
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name_buf);
|
||||
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name_buf, true);
|
||||
ro_gui_wimp_event_memorise(dialog_saveas);
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ void ro_gui_save_start_drag(wimp_pointer *pointer)
|
||||
*/
|
||||
bool ro_gui_save_ok(wimp_w w)
|
||||
{
|
||||
char *name = ro_gui_get_icon_string(w, ICON_SAVE_PATH);
|
||||
const char *name = ro_gui_get_icon_string(w, ICON_SAVE_PATH);
|
||||
char path[256];
|
||||
|
||||
if (!strrchr(name, '.')) {
|
||||
@ -602,7 +602,8 @@ void ro_gui_save_datasave_ack(wimp_message *message)
|
||||
}
|
||||
|
||||
if (saving_from_dialog)
|
||||
ro_gui_set_icon_string(gui_save_sourcew, ICON_SAVE_PATH, path);
|
||||
ro_gui_set_icon_string(gui_save_sourcew, ICON_SAVE_PATH,
|
||||
path, true);
|
||||
|
||||
if (ro_gui_save_content(c, path)) {
|
||||
os_error *error;
|
||||
|
@ -247,7 +247,7 @@ void ro_gui_search_prepare(struct gui_window *g)
|
||||
|
||||
search_current_window = g;
|
||||
|
||||
ro_gui_set_icon_string(dialog_search, ICON_SEARCH_TEXT, "");
|
||||
ro_gui_set_icon_string(dialog_search, ICON_SEARCH_TEXT, "", true);
|
||||
ro_gui_set_icon_selected_state(dialog_search,
|
||||
ICON_SEARCH_CASE_SENSITIVE, false);
|
||||
ro_gui_set_icon_selected_state(dialog_search,
|
||||
@ -326,7 +326,7 @@ bool ro_gui_search_keypress(wimp_key *key)
|
||||
void start_search(bool forwards)
|
||||
{
|
||||
int string_len;
|
||||
char *string;
|
||||
const char *string;
|
||||
int i = 0;
|
||||
|
||||
string = ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT);
|
||||
@ -874,7 +874,7 @@ void show_all(bool all)
|
||||
void show_status(bool found)
|
||||
{
|
||||
ro_gui_set_icon_string(dialog_search, ICON_SEARCH_STATUS,
|
||||
found ? "" : messages_get("NotFound"));
|
||||
found ? "" : messages_get("NotFound"), true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -70,7 +70,7 @@ void theme_install_start(struct content *c)
|
||||
}
|
||||
|
||||
ro_gui_set_icon_string(dialog_theme_install, ICON_THEME_INSTALL_MESSAGE,
|
||||
messages_get("ThemeInstDown"));
|
||||
messages_get("ThemeInstDown"), true);
|
||||
ro_gui_set_icon_shaded_state(dialog_theme_install,
|
||||
ICON_THEME_INSTALL_INSTALL, true);
|
||||
ro_gui_wimp_event_register_close_window(dialog_theme_install,
|
||||
@ -111,7 +111,7 @@ void theme_install_callback(content_msg msg, struct content *c,
|
||||
buffer[sizeof buffer - 1] = '\0';
|
||||
ro_gui_set_icon_string(dialog_theme_install,
|
||||
ICON_THEME_INSTALL_MESSAGE,
|
||||
buffer);
|
||||
buffer, true);
|
||||
ro_gui_set_icon_shaded_state(dialog_theme_install,
|
||||
ICON_THEME_INSTALL_INSTALL, false);
|
||||
break;
|
||||
|
@ -68,7 +68,7 @@ static bool url_complete_callback(const char *url,
|
||||
*/
|
||||
void ro_gui_url_complete_start(struct gui_window *g)
|
||||
{
|
||||
char *url;
|
||||
const char *url;
|
||||
|
||||
if ((!g->toolbar) || (!g->toolbar->display_url) ||
|
||||
(g->window == url_complete_parent))
|
||||
@ -95,7 +95,7 @@ bool ro_gui_url_complete_keypress(struct gui_window *g, uint32_t key)
|
||||
{
|
||||
wimp_window_state state;
|
||||
char *match_url;
|
||||
char *url;
|
||||
const char *url;
|
||||
int i, lines;
|
||||
int old_selection;
|
||||
int height;
|
||||
@ -295,12 +295,12 @@ bool ro_gui_url_complete_keypress(struct gui_window *g, uint32_t key)
|
||||
if (url_complete_matches_selection == -1) {
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL,
|
||||
url_complete_original_url);
|
||||
url_complete_original_url, true);
|
||||
} else {
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL,
|
||||
url_complete_matches[
|
||||
url_complete_matches_selection]);
|
||||
url_complete_matches_selection], true);
|
||||
free(url_complete_matched_string);
|
||||
url_complete_matched_string = strdup(url_complete_matches[
|
||||
url_complete_matches_selection]);
|
||||
@ -584,7 +584,7 @@ void ro_gui_url_complete_redraw(wimp_draw *redraw)
|
||||
url_complete_icon.extent.y1 = -line * 44;
|
||||
url_complete_icon.extent.y0 = -(line + 1) * 44;
|
||||
url_complete_icon.data.indirected_text.text =
|
||||
url_complete_matches[line];
|
||||
(char *)url_complete_matches[line];
|
||||
url_complete_icon.data.indirected_text.size =
|
||||
strlen(url_complete_matches[line]);
|
||||
|
||||
@ -653,7 +653,7 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer)
|
||||
os_error *error;
|
||||
int selection, old_selection;
|
||||
struct gui_window *g;
|
||||
char *url;
|
||||
const char *url;
|
||||
|
||||
if ((mouse_x == pointer->pos.x) && (mouse_y == pointer->pos.y) &&
|
||||
(!pointer->buttons))
|
||||
@ -718,7 +718,7 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer)
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL,
|
||||
url_complete_matches[
|
||||
url_complete_matches_selection]);
|
||||
url_complete_matches_selection], true);
|
||||
global_history_add_recent(url_complete_matches[
|
||||
url_complete_matches_selection]);
|
||||
|
||||
@ -742,7 +742,7 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer)
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL,
|
||||
url_complete_matches[
|
||||
url_complete_matches_selection]);
|
||||
url_complete_matches_selection], true);
|
||||
ro_gui_url_complete_keypress(g, 0);
|
||||
}
|
||||
return true;
|
||||
|
243
riscos/wimp.c
243
riscos/wimp.c
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
||||
* Copyright 2008 John Tytgat <joty@netsurf-browser.org>
|
||||
*
|
||||
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||
*
|
||||
@ -44,6 +45,7 @@
|
||||
|
||||
static void ro_gui_wimp_cache_furniture_sizes(wimp_w w);
|
||||
static size_t ro_gui_strlen(const char *str);
|
||||
static int ro_gui_strncmp(const char *s1, const char *s2, size_t len);
|
||||
|
||||
static wimpextend_furniture_sizes furniture_sizes;
|
||||
static wimp_w furniture_window = NULL;
|
||||
@ -214,16 +216,20 @@ void ro_gui_force_redraw_icon(wimp_w w, wimp_i i)
|
||||
|
||||
|
||||
/**
|
||||
* Read the contents of an icon.
|
||||
* Read the contents of a text or sprite icon.
|
||||
*
|
||||
* \param w window handle
|
||||
* \param i icon handle
|
||||
* \return string in icon
|
||||
* \return NUL terminated string in icon
|
||||
*
|
||||
* \todo this doesn't do local encoding -> UTF-8 to match what is done in
|
||||
* ro_gui_set_icon_string.
|
||||
*/
|
||||
char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
|
||||
const char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
|
||||
{
|
||||
wimp_icon_state ic;
|
||||
os_error *error;
|
||||
char *itext;
|
||||
|
||||
ic.w = w;
|
||||
ic.i = i;
|
||||
@ -234,27 +240,55 @@ char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
|
||||
warn_user("WimpError", error->errmess);
|
||||
return NULL;
|
||||
}
|
||||
return ic.icon.data.indirected_text.text;
|
||||
itext = (ic.icon.flags & wimp_ICON_INDIRECTED) ?
|
||||
ic.icon.data.indirected_text.text
|
||||
:
|
||||
ic.icon.data.text;
|
||||
/* Garantee NUL termination. */
|
||||
itext[ro_gui_strlen(itext)] = '\0';
|
||||
return itext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the contents of an icon to a string.
|
||||
* Set the contents of a text or sprite icon to a string.
|
||||
*
|
||||
* \param w window handle
|
||||
* \param i icon handle
|
||||
* \param text string (UTF-8 encoded) (copied)
|
||||
* \param text NUL terminated string (copied)
|
||||
* \param is_utf8 When true, the given string is UTF-8 encoded and will be
|
||||
* converted to local encoding currently used by the Wimp. When false, the
|
||||
* given string is assumed to be in local encoding in use by the Wimp.
|
||||
*/
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text)
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
|
||||
{
|
||||
wimp_caret caret;
|
||||
wimp_icon_state ic;
|
||||
os_error *error;
|
||||
int old_len, len;
|
||||
size_t old_len, new_len;
|
||||
char *local_text = NULL;
|
||||
utf8_convert_ret err;
|
||||
const char *text_for_icon;
|
||||
char *dst_text;
|
||||
size_t dst_max_len;
|
||||
unsigned int button_type;
|
||||
|
||||
if (is_utf8) {
|
||||
utf8_convert_ret err;
|
||||
/* convert text to local encoding */
|
||||
err = utf8_to_local_encoding(text, 0, &local_text);
|
||||
if (err != UTF8_CONVERT_OK) {
|
||||
/* A bad encoding should never happen, so assert this */
|
||||
assert(err != UTF8_CONVERT_BADENC);
|
||||
LOG(("utf8_to_enc failed"));
|
||||
/* Paranoia */
|
||||
local_text = NULL;
|
||||
}
|
||||
text_for_icon = local_text ? local_text : text;
|
||||
}
|
||||
else
|
||||
text_for_icon = text;
|
||||
new_len = strlen(text_for_icon);
|
||||
|
||||
/* get the icon data */
|
||||
ic.w = w;
|
||||
ic.i = i;
|
||||
@ -263,143 +297,63 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text)
|
||||
LOG(("xwimp_get_icon_state: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* convert text to local encoding */
|
||||
err = utf8_to_local_encoding(text, 0, &local_text);
|
||||
if (err != UTF8_CONVERT_OK) {
|
||||
/* A bad encoding should never happen, so assert this */
|
||||
assert(err != UTF8_CONVERT_BADENC);
|
||||
LOG(("utf8_to_enc failed"));
|
||||
/* Paranoia */
|
||||
local_text = NULL;
|
||||
if (ic.icon.flags & wimp_ICON_INDIRECTED) {
|
||||
dst_text = ic.icon.data.indirected_text.text;
|
||||
dst_max_len = ic.icon.data.indirected_text.size;
|
||||
}
|
||||
len = strlen(local_text ? local_text : text);
|
||||
else {
|
||||
dst_text = ic.icon.data.text;
|
||||
dst_max_len = sizeof(ic.icon.data.text);
|
||||
}
|
||||
old_len = ro_gui_strlen(dst_text);
|
||||
assert(old_len < dst_max_len);
|
||||
|
||||
/* check that the existing text is not the same as the updated text
|
||||
* to stop flicker */
|
||||
if (ic.icon.data.indirected_text.size &&
|
||||
!strncmp(ic.icon.data.indirected_text.text,
|
||||
local_text ? local_text : text,
|
||||
(unsigned int)ic.icon.data.indirected_text.size - 1)) {
|
||||
free(local_text);
|
||||
return;
|
||||
}
|
||||
if (dst_max_len) {
|
||||
if (!ro_gui_strncmp(dst_text, text_for_icon, dst_max_len))
|
||||
goto exit;
|
||||
|
||||
/* copy the text across */
|
||||
old_len = ro_gui_strlen(ic.icon.data.indirected_text.text);
|
||||
if (ic.icon.data.indirected_text.size) {
|
||||
strncpy(ic.icon.data.indirected_text.text,
|
||||
local_text ? local_text : text,
|
||||
(unsigned int)ic.icon.data.indirected_text.size - 1);
|
||||
ic.icon.data.indirected_text.text[
|
||||
ic.icon.data.indirected_text.size - 1] = '\0';
|
||||
}
|
||||
/* copy the text across */
|
||||
strncpy(dst_text, text_for_icon, dst_max_len - 1);
|
||||
dst_text[dst_max_len - 1] = '\0';
|
||||
|
||||
/* handle the caret being in the icon */
|
||||
button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE)
|
||||
>> wimp_ICON_BUTTON_TYPE_SHIFT;
|
||||
if ((button_type == wimp_BUTTON_WRITABLE) ||
|
||||
(button_type == wimp_BUTTON_WRITE_CLICK_DRAG)) {
|
||||
error = xwimp_get_caret_position(&caret);
|
||||
if (error) {
|
||||
LOG(("xwimp_get_caret_position: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
free(local_text);
|
||||
return;
|
||||
}
|
||||
if ((caret.w == w) && (caret.i == i)) {
|
||||
if ((caret.index > len) || (caret.index == old_len))
|
||||
caret.index = len;
|
||||
error = xwimp_set_caret_position(w, i, caret.pos.x,
|
||||
caret.pos.y, -1, caret.index);
|
||||
/* handle the caret being in the icon */
|
||||
button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE)
|
||||
>> wimp_ICON_BUTTON_TYPE_SHIFT;
|
||||
if ((button_type == wimp_BUTTON_WRITABLE) ||
|
||||
(button_type == wimp_BUTTON_WRITE_CLICK_DRAG)) {
|
||||
error = xwimp_get_caret_position(&caret);
|
||||
if (error) {
|
||||
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
||||
LOG(("xwimp_get_caret_position: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
goto exit;
|
||||
}
|
||||
if ((caret.w == w) && (caret.i == i)) {
|
||||
if ((size_t)caret.index > new_len
|
||||
|| (size_t)caret.index == old_len)
|
||||
caret.index = new_len;
|
||||
error = xwimp_set_caret_position(w, i, caret.pos.x,
|
||||
caret.pos.y, -1, caret.index);
|
||||
if (error) {
|
||||
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
}
|
||||
}
|
||||
}
|
||||
ro_gui_redraw_icon(w, i);
|
||||
}
|
||||
ro_gui_redraw_icon(w, i);
|
||||
|
||||
exit:
|
||||
free(local_text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the contents of an icon to a string.
|
||||
*
|
||||
* \param w window handle
|
||||
* \param i icon handle
|
||||
* \param text string (in local encoding) (copied)
|
||||
*/
|
||||
void ro_gui_set_icon_string_le(wimp_w w, wimp_i i, const char *text)
|
||||
{
|
||||
wimp_caret caret;
|
||||
wimp_icon_state ic;
|
||||
os_error *error;
|
||||
int old_len, len;
|
||||
unsigned int button_type;
|
||||
|
||||
/* get the icon data */
|
||||
ic.w = w;
|
||||
ic.i = i;
|
||||
error = xwimp_get_icon_state(&ic);
|
||||
if (error) {
|
||||
LOG(("xwimp_get_icon_state: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that the existing text is not the same as the updated text
|
||||
* to stop flicker */
|
||||
if (ic.icon.data.indirected_text.size &&
|
||||
!strncmp(ic.icon.data.indirected_text.text,
|
||||
text,
|
||||
(unsigned int)ic.icon.data.indirected_text.size - 1))
|
||||
return;
|
||||
|
||||
/* copy the text across */
|
||||
old_len = strlen(ic.icon.data.indirected_text.text);
|
||||
if (ic.icon.data.indirected_text.size) {
|
||||
strncpy(ic.icon.data.indirected_text.text, text,
|
||||
(unsigned int)ic.icon.data.indirected_text.size - 1);
|
||||
ic.icon.data.indirected_text.text[
|
||||
ic.icon.data.indirected_text.size - 1] = '\0';
|
||||
}
|
||||
|
||||
/* handle the caret being in the icon */
|
||||
button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE)
|
||||
>> wimp_ICON_BUTTON_TYPE_SHIFT;
|
||||
if ((button_type == wimp_BUTTON_WRITABLE) ||
|
||||
(button_type == wimp_BUTTON_WRITE_CLICK_DRAG)) {
|
||||
error = xwimp_get_caret_position(&caret);
|
||||
if (error) {
|
||||
LOG(("xwimp_get_caret_position: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
return;
|
||||
}
|
||||
if ((caret.w == w) && (caret.i == i)) {
|
||||
len = strlen(text);
|
||||
if ((caret.index > len) || (caret.index == old_len))
|
||||
caret.index = len;
|
||||
error = xwimp_set_caret_position(w, i, caret.pos.x,
|
||||
caret.pos.y, -1, caret.index);
|
||||
if (error) {
|
||||
LOG(("xwimp_set_caret_position: 0x%x: %s",
|
||||
error->errnum, error->errmess));
|
||||
warn_user("WimpError", error->errmess);
|
||||
}
|
||||
}
|
||||
}
|
||||
ro_gui_redraw_icon(w, i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the contents of an icon to a number.
|
||||
*
|
||||
@ -417,7 +371,7 @@ void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value)
|
||||
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
ro_gui_set_icon_string(w, i, buffer);
|
||||
ro_gui_set_icon_string(w, i, buffer, true);
|
||||
}
|
||||
|
||||
|
||||
@ -451,7 +405,7 @@ void ro_gui_set_icon_decimal(wimp_w w, wimp_i i, int value, int decimal_places)
|
||||
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
ro_gui_set_icon_string(w, i, buffer);
|
||||
ro_gui_set_icon_string(w, i, buffer, true);
|
||||
}
|
||||
|
||||
|
||||
@ -1006,13 +960,36 @@ bool ro_gui_wimp_check_window_furniture(wimp_w w, wimp_window_flags mask)
|
||||
*/
|
||||
size_t ro_gui_strlen(const char *str)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *str_begin;
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
while (*(str++) >= ' ')
|
||||
len++;
|
||||
for (str_begin = str; *str++ >= ' '; /* */)
|
||||
/* */;
|
||||
|
||||
return len;
|
||||
return str - str_begin - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* RO GUI-specific strncmp, for control character terminated strings
|
||||
*
|
||||
* \param s1 The first string for comparison
|
||||
* \param s2 The second string for comparison
|
||||
* \param len Maximum number of bytes to be checked
|
||||
* \return 0 for equal strings up to len bytes; pos for s1 being bigger than
|
||||
* s2; neg for s1 being smaller than s2.
|
||||
*/
|
||||
int ro_gui_strncmp(const char *s1, const char *s2, size_t len)
|
||||
{
|
||||
while (len--) {
|
||||
char c1 = *s1++;
|
||||
char c2 = *s2++;
|
||||
if (c1 < ' ' || c2 < ' ')
|
||||
return (c1 < ' ' ? 0 : c1) - (c2 < ' ' ? 0 : c2);
|
||||
int diff = c1 - c2;
|
||||
if (diff)
|
||||
return diff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -43,9 +43,8 @@ void ro_convert_pixels_to_os_units(os_coord *pixels, os_mode mode);
|
||||
|
||||
#define ro_gui_redraw_icon(w, i) xwimp_set_icon_state(w, i, 0, 0)
|
||||
void ro_gui_force_redraw_icon(wimp_w w, wimp_i i);
|
||||
char *ro_gui_get_icon_string(wimp_w w, wimp_i i);
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text);
|
||||
void ro_gui_set_icon_string_le(wimp_w w, wimp_i i, const char *text);
|
||||
const char *ro_gui_get_icon_string(wimp_w w, wimp_i i);
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8);
|
||||
|
||||
void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value);
|
||||
void ro_gui_set_icon_decimal(wimp_w w, wimp_i i, int value, int decimal_places);
|
||||
|
@ -180,7 +180,7 @@ bool ro_gui_wimp_event_restore(wimp_w w)
|
||||
case EVENT_TEXT_FIELD:
|
||||
if (event->previous_value.textual)
|
||||
ro_gui_set_icon_string(window->w, event->i,
|
||||
event->previous_value.textual);
|
||||
event->previous_value.textual, true);
|
||||
break;
|
||||
case EVENT_CHECKBOX:
|
||||
case EVENT_RADIO:
|
||||
@ -381,8 +381,8 @@ bool ro_gui_wimp_event_menu_selection(wimp_w w, wimp_i i, wimp_menu *menu,
|
||||
if (menu_entry->menu_flags & wimp_MENU_TICKED)
|
||||
return true;
|
||||
|
||||
ro_gui_set_icon_string_le(window->w, event->data.menu_gright.field,
|
||||
menu_entry->data.indirected_text.text);
|
||||
ro_gui_set_icon_string(window->w, event->data.menu_gright.field,
|
||||
menu_entry->data.indirected_text.text, false);
|
||||
ro_gui_wimp_event_prepare_menu(window->w, event);
|
||||
if (window->menu_selection)
|
||||
window->menu_selection(window->w, event->i);
|
||||
@ -591,7 +591,7 @@ bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer)
|
||||
void ro_gui_wimp_event_prepare_menu(wimp_w w, struct icon_event *event)
|
||||
{
|
||||
int i;
|
||||
char *text;
|
||||
const char *text;
|
||||
unsigned int button_type;
|
||||
wimp_icon_state ic;
|
||||
wimp_menu *menu;
|
||||
|
@ -1017,13 +1017,13 @@ void gui_window_set_url(struct gui_window *g, const char *url)
|
||||
{
|
||||
wimp_caret caret;
|
||||
os_error *error;
|
||||
char *toolbar_url;
|
||||
const char *toolbar_url;
|
||||
|
||||
if (!g->toolbar)
|
||||
return;
|
||||
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL, url);
|
||||
ICON_TOOLBAR_URL, url, true);
|
||||
ro_gui_force_redraw_icon(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_FAVICON);
|
||||
|
||||
@ -1083,7 +1083,7 @@ void gui_window_stop_throbber(struct gui_window *g)
|
||||
if (g->toolbar) {
|
||||
strcpy(throb_buf, "throbber0");
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_THROBBER, throb_buf);
|
||||
ICON_TOOLBAR_THROBBER, throb_buf, true);
|
||||
if ((g->toolbar->descriptor) && (g->toolbar->descriptor->throbber_redraw))
|
||||
ro_gui_force_redraw_icon(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_THROBBER);
|
||||
@ -2014,7 +2014,7 @@ void ro_gui_throb(void)
|
||||
top_g->throbber = 1;
|
||||
sprintf(throb_buf, "throbber%i", top_g->throbber);
|
||||
ro_gui_set_icon_string(top_g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_THROBBER, throb_buf);
|
||||
ICON_TOOLBAR_THROBBER, throb_buf, true);
|
||||
if (top_g->toolbar->descriptor->throbber_redraw)
|
||||
ro_gui_force_redraw_icon(top_g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_THROBBER);
|
||||
@ -2278,7 +2278,7 @@ bool ro_gui_window_keypress(wimp_key *key)
|
||||
struct content *content;
|
||||
wimp_window_state state;
|
||||
int y;
|
||||
char *toolbar_url;
|
||||
const char *toolbar_url;
|
||||
os_error *error;
|
||||
wimp_pointer pointer;
|
||||
float scale;
|
||||
@ -2378,7 +2378,7 @@ bool ro_gui_window_keypress(wimp_key *key)
|
||||
return false;
|
||||
ro_gui_url_complete_close(NULL, 0);
|
||||
ro_gui_set_icon_string(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL, "www.");
|
||||
ICON_TOOLBAR_URL, "www.", true);
|
||||
xwimp_set_caret_position(g->toolbar->toolbar_handle,
|
||||
ICON_TOOLBAR_URL, 0, 0, -1, 4);
|
||||
ro_gui_url_complete_start(g);
|
||||
|
Loading…
Reference in New Issue
Block a user