/*************************************************************************** 
 *                                                                         *
 *    File:         Buttons.cpp                                            *
 *                                                                         *
 *    Description:  This file contains the main entry point into the       *
 *                  Test Program system.                                   *
 *                                                                         *
 *    Copyright:    (C) Copyright JBA Software (SDU) 1995.                 *
 *                  All Rights Reserved.                                   *
 *                                                                         *
 *    Date:         10 Jun 1997                                            *
 *                                                                         *
 *    Note:         Generated by the Guidelines code generation facility.  *
 *                                                                         *
 ***************************************************************************/

#define INCL_PM
#define INCL_NLS
#define INCL_BASE

#define GUIDELINES "3.1A"

#include <os2.h>                                 /* OS/2 include file      */
#include <stdio.h>                               /* Standard I/O functions */
#include <stdlib.h>                              /* Misc. functions        */
#include <string.h>                              /* String functions       */

#include "Buttons.hpp"


/*************************************************************************** 
 *    Private functions.                                                   *
 ***************************************************************************/

static void GuiSetup (void);


/*************************************************************************** 
 *    Global variables.                                                    *
 ***************************************************************************/

WINDOW  wDLG_Buttons;                            /* DLG_Buttons info       */


SHORT   i;


/*************************************************************************** 
 *                                                                         *
 *    Function:     main                                                   *
 *                                                                         *
 *    Description:  This is main entry point into the                      *
 *                  Test Program application.                              *
 *                                                                         *
 ***************************************************************************/

int main (int argc, char *argv[])
{
    SWCNTRL  swctl;
    PAPPINFO pApp;
    
   /******************************
    * Initialize the application *
    ******************************/
    
    GuiInitApp ("Buttons", "Test Program");
    GuiSaveCmdLine (argc, argv);
    
    pApp = GuiAppInfo ();
    GuiInitWindows (pApp);
    
    /* Initialize global variables */
    i = (SHORT)0;
    
    GuiSetup ();
    
   /********************************
    * Load and display main window *
    ********************************/
    
    GuiSetWindow (&wDLG_Buttons, IDD_DLG_BUTTONS, WT_DIALOG, DLG_ButtonsWndProc, (HMODULE)0);
    if  (GuiLoadWindow (&wDLG_Buttons, GuiDesktopWindow ()))
    {
       /*************************
        * Add entry to tasklist *
        *************************/
        
        strcpy (swctl.szSwtitle, pApp->szPgmTitle);
        
        swctl.hwnd          = wDLG_Buttons.hwnd;
        swctl.hwndIcon      = (HWND)0;
        swctl.hprog         = (HPROGRAM)0;
        swctl.idProcess     = pApp->pid;
        swctl.idSession     = 0;
        swctl.uchVisibility = SWL_VISIBLE;
        swctl.fbJump        = SWL_JUMPABLE;
        
        WinAddSwitchEntry (&swctl);
        
       /*******************************
        * Process the window template *
        *******************************/
        
        pApp->hwndMain = wDLG_Buttons.hwnd;
        GuiProcessWindow (&wDLG_Buttons);
        GuiUnloadWindow (&wDLG_Buttons);
    }
    
   /**************************
    * Termination processing *
    **************************/
    
    GuiExitWindows ();
    
    return (pApp->sExitCode);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     GuiSetup                                               *
 *                                                                         *
 *    Description:  This routine performs any processing required          *
 *                  to initialize the runtime environment for this         *
 *                  application or DLL.                                    *
 *                                                                         *
 ***************************************************************************/

static void GuiSetup (void)
{
    PAPPINFO pApp = GuiAppInfo ();
    
    GuiRegisterButton (pApp->hab);
    GuiRegisterListbox (pApp->hab);
    GuiRegisterStatic (pApp->hab);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLG_ButtonsWndProc                                     *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLG_Buttons window.                                    *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLG_ButtonsWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLG_Buttons;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLG_Buttons.hwnd)
        return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
    
    switch (msg)
    {
       /***********************
        * Property processing *
        ***********************/
        
        case WM_GUIGETPROPERTY:
        case WM_GUISETPROPERTY:
             break;
        
       /*******************************
        * Window resized/repositioned *
        *******************************/
        
        case WM_WINDOWPOSCHANGED:
             {
                 PSWP pSwp = (PSWP) mp1;
                 if  (pSwp->fl & SWP_SIZE)
                 {
                     GuiBroadcastMsg (hwnd, WM_GUIPARENTRESIZED, 0, 0);
                 }
             }
             break;
        
       /***************************
        * User command processing *
        ***************************/
        
        case WM_COMMAND:
             switch (SHORT1FROMMP (mp1))
             {
                 case IDD_PSH_USER:
                      DLG_ButtonsPSH_UserClick ();
                      break;
                 case IDD_PSH_TEXT:
                      DLG_ButtonsPSH_TextClick ();
                      break;
                 case IDD_PSH_ICON:
                      DLG_ButtonsPSH_IconClick ();
                      break;
                 case IDD_PSH_BITMAP:
                      DLG_ButtonsPSH_BitmapClick ();
                      break;
                 
                 default:
                      break;
             }
             return (mResult);
        
       /*************************
        * Control notifications *
        *************************/
        
        case WM_CONTROL:
             if  (!GuiEventLoop (mp1))
                 break;
             switch (SHORT1FROMMP (mp1))
             {
                 case IDD_RAD_1:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsRAD_1Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsRAD_1DblClick ();
                               break;
                      }
                      break;
                 case IDD_RAD_2:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsRAD_2Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsRAD_2DblClick ();
                               break;
                      }
                      break;
                 case IDD_RAD_3:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsRAD_3Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsRAD_3DblClick ();
                               break;
                      }
                      break;
                 case IDD_RAD_4:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsRAD_4Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsRAD_4DblClick ();
                               break;
                      }
                      break;
                 case IDD_RAD_5:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsRAD_5Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsRAD_5DblClick ();
                               break;
                      }
                      break;
                 case IDD_CHK_1:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsCHK_1Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsCHK_1DblClick ();
                               break;
                      }
                      break;
                 case IDD_CHK_3STATE2:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsCHK_3State2Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsCHK_3State2DblClick ();
                               break;
                      }
                      break;
                 case IDD_CHK_3STATE1:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsCHK_3State1Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsCHK_3State1DblClick ();
                               break;
                      }
                      break;
                 case IDD_CHK_2:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case BN_CLICKED:
                               DLG_ButtonsCHK_2Click ();
                               break;
                          case BN_DBLCLICKED:
                               DLG_ButtonsCHK_2DblClick ();
                               break;
                      }
                      break;
             }
             GuiEventLoop (0);
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void DLG_ButtonsRAD_1Click (void)
{
    ShowEvent (String("Radio 1 Clicked"));
}


void DLG_ButtonsRAD_2Click (void)
{
    ShowEvent (String("Radio 2 Clicked"));
}


void DLG_ButtonsRAD_3Click (void)
{
    ShowEvent (String("Radio 3 Clicked"));
}


void DLG_ButtonsRAD_4Click (void)
{
    ShowEvent (String("Radio 4 Clicked"));
}


void DLG_ButtonsRAD_5Click (void)
{
    ShowEvent (String("Radio 5 Clicked"));
}


void DLG_ButtonsRAD_5DblClick (void)
{
    ShowEvent (String("Radio 5 Double-Clicked"));
}


void DLG_ButtonsRAD_4DblClick (void)
{
    ShowEvent (String("Radio 4 Double-Clicked"));
}


void DLG_ButtonsRAD_3DblClick (void)
{
    ShowEvent (String("Radio 3 Double-Clicked"));
}


void DLG_ButtonsRAD_2DblClick (void)
{
    ShowEvent (String("Radio 2 Double-Clicked"));
}


void DLG_ButtonsRAD_1DblClick (void)
{
    ShowEvent (String("Radio 1 Double-Clicked"));
}


void DLG_ButtonsCHK_1Click (void)
{
    ShowEvent (String("Checkbox 1 Clicked"));
}


void DLG_ButtonsCHK_2Click (void)
{
    ShowEvent (String("Checkbox 2 Clicked"));
}


void DLG_ButtonsCHK_3State1Click (void)
{
    ShowEvent (String("3-State Checkbox 1 Clicked"));
}


void DLG_ButtonsCHK_3State2Click (void)
{
    ShowEvent (String("3-State Checkbox 2 Clicked"));
}


void DLG_ButtonsCHK_1DblClick (void)
{
    ShowEvent (String("Checkbox 1 Double-Clicked"));
}


void DLG_ButtonsCHK_2DblClick (void)
{
    ShowEvent (String("Checkbox 2 Double-Clicked"));
}


void DLG_ButtonsCHK_3State1DblClick (void)
{
    ShowEvent (String("3-State Checkbox 1 Double-Clicked"));
}


void DLG_ButtonsCHK_3State2DblClick (void)
{
    ShowEvent (String("3-State Checkbox 2 Double-Clicked"));
}


void DLG_ButtonsPSH_UserClick (void)
{
    ShowEvent (String("User Button Clicked"));
}


void DLG_ButtonsPSH_IconClick (void)
{
    ShowEvent (String("Icon PushButton Clicked"));
}


void DLG_ButtonsPSH_TextClick (void)
{
    ShowEvent (String("Text PushButton Clicked"));
}


void DLG_ButtonsPSH_BitmapClick (void)
{
    ShowEvent (String("Bitmap PushButton Clicked"));
}


void ShowEvent (String event)
{
    WINDOW  GuiTmp1;
    String  number;
    
    if ((int)i < 10)
    {
        number = String("000") + GuiStr (i);
    }
    else
    {
        if ((int)i < 100)
        {
            number = String("00") + GuiStr (i);
        }
        else
        {
            if ((int)i < 10)
            {
                number = String("0") + GuiStr (i);
            }
            else
            {
                number = GuiStr (i);
            }
        }
    }
    GuiSetControl (&wDLG_Buttons, &GuiTmp1, IDD_LST_EVENTS, WT_LISTBOX);
    GuiInsertItem (&GuiTmp1, -1, number + String(" ") + event);
    GuiSetControl (&wDLG_Buttons, &GuiTmp1, IDD_LST_EVENTS, WT_LISTBOX);
    GuiSetShort (&GuiTmp1, WPID_LISTBOXTOP, i);
    i = (SHORT) ((int)i + 1);
}


void Buttons (PWINDOW WinModal)
{
    GuiSetWindow (&wDLG_Buttons, IDD_DLG_BUTTONS, WT_DIALOG, DLG_ButtonsWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLG_Buttons, WinModal);
    GuiProcessWindow (&wDLG_Buttons);
    GuiUnloadWindow (&wDLG_Buttons);
}


