
/* settitle.c
 *
 * Wimp function library
 *  Joseph Heenan, 1998.
 *
 *
 *
 *
 * $Log: settitle,v $
 * Revision 1.2  1998/05/10 20:13:11  jogu
 * Added names to file headers
 * Added implicit cast for frontend_taskname to wimp_report_error
 *   (it defines 'name' without 'const')
 *
 * Revision 1.1.1.1  1998/05/10 19:56:03  jogu
 * WimpCLib V1.00 (created from newshound c.wimpc rev 1.2)
 *
 *
 */

#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include "swis.h"
#include "wimplib.h"

#include "wimpclib.h"


int wimpc_settitle(int window, const char *text)
{
  const int flags = WimpIcon_Text | WimpIcon_Indirected;
  WimpGetWindowInfoBlock info;
  int info_bit0 = ((int) &info) + 1;

  info.window_handle = window;
  E_CHECK_RETURN( -1, wimp_get_window_info( (void *)info_bit0 ) );

  if ( (info.window_data.title_flags & flags) != flags )
    E_RETURN( -1, "Icon is not a text icon or is not indirected" );

  *info.window_data.title_data.it.buffer = 0;
  strncat( info.window_data.title_data.it.buffer, text, info.window_data.title_data.it.buffer_size - 1 );

  if (info.window_data.flags & WimpWindow_Open)
  {
    /* redraw titlebar if window open */
    WimpGetWindowOutlineBlock outline;
    outline.window_handle = window;
    E_CHECK_RETURN( -1, wimp_get_window_outline( &outline ) );
    E_CHECK_RETURN( -1, wimp_force_redraw( -1, outline.outline.xmin,
                                           info.window_data.visible_area.ymax,
                                           outline.outline.xmax,
                                           outline.outline.ymax ) );
  }
  return 0;
}

