/**
 * @file    value.c
 * @brief   Writing the text of a VALUE widget.
 *          A reading aid for the tutorial page "widget-types", not a complete
 *          plugin: the functions below would be wired into an IcPlugin
 *          (on_widget_event) or called from init()/a Worker callback.
 *
 * @note    ASCII-only and C89 on purpose (VC6 / CP950 safe, and it must pass
 *          the syntax-only guard). The widget ids match value.nxlay.
 */

#include <string.h>

#include "nexus_plugin_api.h"

/** @brief The HostAPI table, saved by init() (not shown here). */
static const NxHostApi *s_host = (const NxHostApi *)0;

/** @brief widget id of the VALUE ([w.1] in value.nxlay). */
#define WID_VERSION 1

/**
 * @brief  Shows text after the "Version" label.
 * @param[in] ctx  This mount's context.
 * @param[in] text New text (UTF-8); must not be NULL.
 * @return ERR_OK, or ERR_INVALID_PARAM when the widget is not a VALUE.
 * @note   Any thread; no event is generated for your own write.
 */
NxLong value_show(NxPluginCtx ctx, const char *text)
{
    NxPropVal v;

    memset(&v, 0, sizeof(v));
    v.SizeOfStruct = (NxDword)sizeof(v);
    v.kind         = (NxWord)NX_WKIND_STR;   /* a VALUE takes a string */
    v.u.str.ptr    = text;
    v.u.str.len    = (NxDword)strlen(text);
    return s_host->SetWidgetProp(ctx, 0, WID_VERSION, NX_WP_VALUE, &v);
}
