home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / TIMEXSRC.ZIP / UA_MWIN.C < prev    next >
C/C++ Source or Header  |  1990-03-29  |  6KB  |  222 lines

  1. /* ua_mwin.c -- Main window control
  2.  
  3.     February 1990    Mark E. Mallett, Personal Workstation Magazine
  4.  
  5. This module contains the code controlling the main window, and, in
  6. effect, the timexua program.
  7.  
  8. Included are the following routines:
  9.  
  10.     main_winproc        Main window procedure
  11.  
  12. */
  13.  
  14. #define    INCL_WIN
  15.  
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <os2.h>
  19.  
  20. #include "timex.h"
  21. #include "ua_timex.h"
  22. #include "ua_pm.h"
  23. #include "ua_baif.h"
  24.  
  25.  
  26. /* Local definitions */
  27.  
  28.  
  29. /* External data referenced */
  30.  
  31. extern  EVENT   *CureventP;     /* Current event being modified */
  32. extern  HWND    CurwinH;        /* Currently active window */
  33. extern    HWND    EvlistH;    /* Event list window handle */
  34. extern  HWND    MainwinH;       /* Main window handle */
  35.  
  36. /* External routines used */
  37.  
  38. extern    MRESULT    EXPENTRY    event_winproc();
  39. extern  void                    get_events( void );
  40.  
  41. /* Local data publicly available */
  42.  
  43.  
  44. /* Local routines and forward declarations */
  45.  
  46. static  void    mw_delete( void );    /* Perform a DELETE action */
  47. static  void    mw_modify( void );    /* Perform a MODIFY action */
  48.  
  49. /* Private data */
  50.  
  51.  
  52. /*
  53.  
  54. *//* main_winproc( winH, msgcode, mp1, mp2 )
  55.  
  56.     Window procedure for the main window
  57.  
  58. Accepts :
  59.  
  60.     winH        Window handler
  61.     msgcode        Message code
  62.     mp1        First message parameter
  63.     mp2        Second window parameter
  64.  
  65. Returns :
  66.  
  67. */
  68.  
  69. MRESULT EXPENTRY
  70. main_winproc(
  71.     HWND        winH,        /* Window handle */
  72.     USHORT        msgcode,    /* Message code */
  73.     MPARAM        mp1,        /* First parm */
  74.     MPARAM        mp2        /* Second parm */
  75. ) {
  76.     int        eecode;        /* Event editing result code */
  77.     HWND        eewin;        /* Event editing window handle */
  78.         HWND            oldcwH;         /* Previous curwin handle */
  79.  
  80.     /* Dispatch on the message code */
  81.     switch( msgcode ) {
  82.     case    WM_INITDLG:
  83.         EvlistH = WinWindowFromID( winH, MEL_EVLIST );
  84.         break;
  85.  
  86.     case    WM_COMMAND:        /* Command from a button */
  87.         switch ( COMMANDMSG( &msgcode )->cmd ) {
  88.                 case MEL_CREATE:        /* Create an event */
  89.                     /* Present fill-in form in create mode */
  90.                     eewin = WinLoadDlg( HWND_DESKTOP, winH, event_winproc,
  91.                                 NULL, WID_EVENTEDIT, NULL );
  92.                     oldcwH = CurwinH;
  93.                     CurwinH = eewin;
  94.                     eecode = WinProcessDlg( eewin );
  95.                     WinDestroyWindow( eewin );
  96.                     CurwinH = oldcwH;
  97.                     return( 0 );
  98.  
  99.  
  100.         case MEL_MODIFY:    /* Modify an event */
  101.                     mw_modify();        /* Perform the modify function */
  102.                     return( 0 );
  103.  
  104.                 case MEL_DELETE:        /* Delete the selected event */
  105.                     mw_delete();        /* Perform the delete function */
  106.                     return( 0 );
  107.  
  108.         case MEL_NEWLIST:    /* Obtain new list of events */
  109.             get_events();
  110.             return( 0 );
  111.         }
  112.         break;
  113.  
  114.  
  115.     case WM_ERASEBACKGROUND:
  116.         return( 1 );
  117.  
  118.     }
  119.  
  120.     /* Not handled here... give to parent handler */
  121.     return( WinDefWindowProc( winH, msgcode, mp1, mp2 ) );
  122. }
  123. /*
  124.  
  125. *//* mw_delete()
  126.  
  127.         Control the delete event
  128.  
  129. Accepts :
  130.  
  131.  
  132. Returns :
  133.  
  134.  
  135. */
  136.  
  137. static void
  138. mw_delete( void ) {
  139.  
  140.         int             listX;          /* Event list item number */
  141.         char            evname[100];    /* Name of the event */
  142.  
  143.  
  144.     /* Get the currently selected event */
  145.     listX = (int)WinSendMsg( EvlistH, LM_QUERYSELECTION,
  146.                                 MPFROMSHORT( LIT_FIRST ), 0L );
  147.     if ( listX == LIT_NONE ) {
  148.         /* No item selected; ignore. */
  149.         warning( EC_OK, "No event selected." );
  150.     }
  151.     else {
  152.  
  153.         /* Obtain the event */
  154.         WinSendMsg( EvlistH, LM_QUERYITEMTEXT,
  155.                                 MPFROM2SHORT( listX, 99 ),
  156.                                 MPFROMP( &evname[0] ) );
  157.  
  158.         /* Attempt to delete it */
  159.         if ( ba_del( &evname[0] ) )
  160.             /* Success -- get new list of events */
  161.             get_events();
  162.     }
  163. }
  164. /*
  165.  
  166. *//* mw_modify()
  167.  
  168.         Control the modify event
  169.  
  170. Accepts :
  171.  
  172.  
  173. Returns :
  174.  
  175.  
  176. */
  177.  
  178. static void
  179. mw_modify( void ) {
  180.  
  181.         int             listX;          /* Event list item number */
  182.         int             eecode;         /* Event editing result code */
  183.         HWND            eewin;          /* Event editing window handle */
  184.         HWND            oldcwH;         /* Previous curwinH */
  185.         char            evname[100];    /* Name of the event */
  186.  
  187.  
  188.     /* Get the currently selected event */
  189.     listX = (int)WinSendMsg( EvlistH, LM_QUERYSELECTION,
  190.                                 MPFROMSHORT( LIT_FIRST ), 0L );
  191.     if ( listX == LIT_NONE ) {
  192.         /* No item selected; ignore. */
  193.         warning( EC_OK, "No event selected." );
  194.     }
  195.     else {
  196.  
  197.         /* Obtain the event */
  198.         WinSendMsg( EvlistH, LM_QUERYITEMTEXT,
  199.                                 MPFROM2SHORT( listX, 99 ),
  200.                                 MPFROMP( &evname[0] ) );
  201.         CureventP = ba_get( &evname[0] );
  202.         if ( CureventP == NULL ) {
  203.             warning( EC_OK, "Can't get event \"%s\"", &evname[0] );
  204.         }
  205.         else {
  206.  
  207.             /* Get and process the event-edit dialog */
  208.             eewin = WinLoadDlg( HWND_DESKTOP, MainwinH, event_winproc,
  209.                                 NULL, WID_EVENTEDIT, NULL );
  210.             oldcwH = CurwinH;
  211.             CurwinH = eewin;
  212.             eecode = WinProcessDlg( eewin );
  213.             WinDestroyWindow( eewin );
  214.             CurwinH = oldcwH;
  215.  
  216.             /* Get rid of current event that we made */
  217.             free( CureventP );
  218.             CureventP = NULL;
  219.         }
  220.     }
  221. }
  222.