/*
======================================================================
radio.c

Ernie Wright  15 Apr 05
MSVC 4.0

Functions that manage the radio buttons on QV's main window.
====================================================================== */

#include <windows.h>
#include <stdio.h>
#include "qv.h"


/*
======================================================================
radioSelect()

Set one of the buttons.  The previously selected button is deselected.
====================================================================== */

void radioSelect( HWND hwnd, int i )
{
   CheckRadioButton( hwnd, IDC_RADIO, IDC_RADIO + 9, IDC_RADIO + i );
}


/*
======================================================================
radioEnable()

Enable or disable a radio button.
====================================================================== */

void radioEnable( HWND hwnd, int i, int state )
{
   EnableWindow( GetDlgItem( hwnd, IDC_RADIO + i ), state );
}


/*
======================================================================
radioCreate()

Create a row of ten radio buttons, used to select the ten frames QV
can display.
====================================================================== */

void radioCreate( HWND hwnd )
{
   HINSTANCE hinst;
   int i;

   hinst = ( HINSTANCE ) GetWindowLongPtr( hwnd, GWLP_HINSTANCE );
   for ( i = 0; i < 10; i++ ) {
      CreateWindowEx( 0, "button", NULL,
         WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON,
         RADIO_L + i * ( RADIO_W + 1 ), 10, RADIO_W, RADIO_H,
         hwnd, ( HMENU )( IDC_RADIO + i ), hinst, NULL );
   }
   radioSelect( hwnd, 0 );
}


/*
======================================================================
radioHeight()

Return the pixel height of the radio button row.  This is actually the
pixel offset from the top border of the status window.
====================================================================== */

int radioHeight( void )
{
   return RADIO_H + 4;
}


/*
======================================================================
radioResize()

Respond to the resizing of the parent window.

   w           new parent window width
   h           new height
   sh          bottom margin (status window) height
====================================================================== */

int radioResize( HWND hwnd, int w, int h, int sh )
{
   int x, y, i;

   x = ( w - 10 * RADIO_W ) / 2;
   y = h - sh - radioHeight();

   for ( i = 0; i < 10; i++ )
      MoveWindow( GetDlgItem( hwnd, IDC_RADIO + i ),
         x + i * RADIO_W, y, RADIO_W, RADIO_H, TRUE );

   return radioHeight();
}


