/*************************************************************************** 
 *                                                                         *
 *    File:         static.cpp                                             *
 *                                                                         *
 *    Description:  This file contains the main entry point into the       *
 *                  static controls test program system.                   *
 *                                                                         *
 *    Copyright:    (C) Copyright JBA Software Products 1995.              *
 *                  All Rights Reserved.                                   *
 *                                                                         *
 *    Date:         26 Oct 1996                                            *
 *                                                                         *
 *    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 "static.hpp"


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

static void GuiSetup (void);


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

WINDOW  wDLGMain;                                /* DLGMain info           */
WINDOW  wDLGStyle;                               /* DLGStyle info          */
WINDOW  wDLGAlign;                               /* DLGAlign info          */
WINDOW  wDLGType;                                /* DLGType info           */
WINDOW  wDLGPres;                                /* DLGPres info           */




/*************************************************************************** 
 *                                                                         *
 *    Function:     main                                                   *
 *                                                                         *
 *    Description:  This is main entry point into the                      *
 *                  static controls test program application.              *
 *                                                                         *
 ***************************************************************************/

int main (int argc, char *argv[])
{
    SWCNTRL  swctl;
    PAPPINFO pApp;
    
   /******************************
    * Initialize the application *
    ******************************/
    
    GuiInitApp ("static", "static controls test program");
    GuiSaveCmdLine (argc, argv);
    
    pApp = GuiAppInfo ();
    GuiInitWindows (pApp);
    GuiSetup ();
    
   /********************************
    * Load and display main window *
    ********************************/
    
    GuiSetWindow (&wDLGMain, IDD_DLGMAIN, WT_DIALOG, DLGMainWndProc, (HMODULE)0);
    if  (GuiLoadWindow (&wDLGMain, GuiDesktopWindow ()))
    {
       /*************************
        * Add entry to tasklist *
        *************************/
        
        strcpy (swctl.szSwtitle, pApp->szPgmTitle);
        
        swctl.hwnd          = wDLGMain.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 = wDLGMain.hwnd;
        GuiProcessWindow (&wDLGMain);
        GuiUnloadWindow (&wDLGMain);
    }
    
   /**************************
    * 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);
    GuiRegisterEntry (pApp->hab);
    GuiRegisterStatic (pApp->hab);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLGMainWndProc                                         *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLGMain window.                                        *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLGMainWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLGMain;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLGMain.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_PSHTYPE:
                      DLGMainPSHTypeClick ();
                      break;
                 case IDD_PSHALIGNMENT:
                      DLGMainPSHAlignmentClick ();
                      break;
                 case IDD_PSHSTYLES:
                      DLGMainPSHStylesClick ();
                      break;
                 case IDD_PSHPRES:
                      DLGMainPSHpresClick ();
                      break;
                 
                 default:
                      break;
             }
             return (mResult);
        
       /**************************
        * Window is being loaded *
        **************************/
        
        case WM_GUIWINDOWLOADED:
             DLGMainCreate ();
             return (FALSE);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void DLGMainPSHTypeClick (void)
{
    GuiSetWindow (&wDLGType, IDD_DLGTYPE, WT_DIALOG, DLGTypeWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLGType, &wDLGMain);
    GuiProcessWindow (&wDLGType);
    GuiUnloadWindow (&wDLGType);
}


void DLGMainPSHStylesClick (void)
{
    GuiSetWindow (&wDLGStyle, IDD_DLGSTYLE, WT_DIALOG, DLGStyleWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLGStyle, &wDLGMain);
    GuiProcessWindow (&wDLGStyle);
    GuiUnloadWindow (&wDLGStyle);
}


void DLGMainPSHAlignmentClick (void)
{
    GuiSetWindow (&wDLGAlign, IDD_DLGALIGN, WT_DIALOG, DLGAlignWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLGAlign, &wDLGMain);
    GuiProcessWindow (&wDLGAlign);
    GuiUnloadWindow (&wDLGAlign);
}


void DLGMainPSHpresClick (void)
{
    GuiSetWindow (&wDLGPres, IDD_DLGPRES, WT_DIALOG, DLGPresWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLGPres, &wDLGMain);
    GuiProcessWindow (&wDLGPres);
    GuiUnloadWindow (&wDLGPres);
}


void DLGMainCreate (void)
{
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLGStyleWndProc                                        *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLGStyle window.                                       *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLGStyleWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLGStyle;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLGStyle.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_PSHVISIBLE:
                      DLGStylePSHVisibleClick ();
                      break;
                 case IDD_PSHENABLE:
                      DLGStylePSHEnableClick ();
                      break;
                 
                 default:
                      break;
             }
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void DLGStylePSHVisibleClick (void)
{
    WINDOW  GuiTmp1;
    WINDOW  GuiTmp2;
    
    GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLV, WT_STATICTEXT);
    if (GuiGetShort (&GuiTmp1, WPID_VISIBLE) == FALSE)
    {
        GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLV, WT_STATICTEXT);
        GuiSetShort (&GuiTmp1, WPID_VISIBLE, TRUE);
        GuiSetControl (&wDLGStyle, &GuiTmp2, IDD_PSHVISIBLE, WT_PUSHBUTTON);
        GuiSetString (&GuiTmp2, WPID_TEXT, String("Invisible"));
    }
    else
    {
        GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLV, WT_STATICTEXT);
        GuiSetShort (&GuiTmp1, WPID_VISIBLE, FALSE);
        GuiSetControl (&wDLGStyle, &GuiTmp2, IDD_PSHVISIBLE, WT_PUSHBUTTON);
        GuiSetString (&GuiTmp2, WPID_TEXT, String("Visible"));
    }
}


void DLGStylePSHEnableClick (void)
{
    WINDOW  GuiTmp1;
    WINDOW  GuiTmp2;
    
    GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLD, WT_STATICTEXT);
    if (GuiGetShort (&GuiTmp1, WPID_ENABLED) == FALSE)
    {
        GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLD, WT_STATICTEXT);
        GuiSetShort (&GuiTmp1, WPID_ENABLED, TRUE);
        GuiSetControl (&wDLGStyle, &GuiTmp2, IDD_PSHENABLE, WT_PUSHBUTTON);
        GuiSetString (&GuiTmp2, WPID_TEXT, String("Disable"));
    }
    else
    {
        GuiSetControl (&wDLGStyle, &GuiTmp1, IDD_LBLD, WT_STATICTEXT);
        GuiSetShort (&GuiTmp1, WPID_ENABLED, FALSE);
        GuiSetControl (&wDLGStyle, &GuiTmp2, IDD_PSHENABLE, WT_PUSHBUTTON);
        GuiSetString (&GuiTmp2, WPID_TEXT, String("Enable"));
    }
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLGAlignWndProc                                        *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLGAlign window.                                       *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLGAlignWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLGAlign;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLGAlign.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))
             {
                 
                 default:
                      break;
             }
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLGTypeWndProc                                         *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLGType window.                                        *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLGTypeWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLGType;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLGType.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))
             {
                 
                 default:
                      break;
             }
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DLGPresWndProc                                         *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  DLGPres window.                                        *
 *                                                                         *
 ***************************************************************************/

PMENTRY DLGPresWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDLGPres;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDLGPres.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))
             {
                 
                 default:
                      break;
             }
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void Statics (PWINDOW WinOwner)
{
    GuiSetWindow (&wDLGMain, IDD_DLGMAIN, WT_DIALOG, DLGMainWndProc, (HMODULE)0);
    GuiLoadWindow (&wDLGMain, WinOwner);
    GuiProcessWindow (&wDLGMain);
    GuiUnloadWindow (&wDLGMain);
}


