home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c163 / 3.ddi / SCRE_SOU.EXE / G4CONTRO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  6.4 KB  |  198 lines

  1. /* g4control.c  Control Area Routines  (c)Copyright Sequiter Software Inc., 1991.  All rights reserved. */
  2.  
  3. #include "c4window.h"
  4. #include "e4error.h"
  5.  
  6. #ifdef __TURBOC__
  7.    #pragma hdrstop
  8. #endif
  9.  
  10. void control4_construct( G4CONTROL *ca, W4ENTRY *ew )
  11. {
  12.    ca->nopaint    = 0 ;
  13.    ca->hParent    = 0 ;
  14.    ca->gw.Id      = 0 ;
  15.    ca->gw.Style   = 0 ;
  16.    ca->area_type  = c4control ;
  17.    ca->ew         = ew ;
  18.    ca->gw.cw      = ew->gw.cw ;
  19.    ca->is_default = 0 ;
  20. }
  21.  
  22. int control4_process_message( G4CONTROL *ca, WORD message, WORD wParam, LONG lParam )
  23. {
  24.    switch( message )
  25.    {
  26.       case WM_KEYDOWN:
  27.       case WM_SYSCHAR:
  28.          if ( ca->area_type == c4edit )
  29.          {
  30.             G4EDIT *ea = (G4EDIT *) ca->area ;
  31.             if ( ea->combo != 0 )  return 0 ;
  32.          }
  33.          if ( ca->area_type == c4list )  return 0 ;
  34.          if ( ca->ew->bw == 0 )  return 0 ;
  35.          return browse4_process_key( ca->ew->bw, message, wParam, lParam ) ;
  36.  
  37.       case WM_CHAR:
  38.          switch( wParam )
  39.          {
  40.             G4EDIT *ea ;
  41.             L4LIST *list ;
  42.             G4CONTROL *new_area ;
  43.             int is_shift ;
  44.  
  45.             case VK_TAB:
  46.                if ( control4_ok( ca->ew, 0 ) != 0 )  return 1 ;
  47.                new_area = ca ;
  48.                is_shift = GetKeyState( VK_SHIFT ) ;
  49.                if ( 0x06000000L == ( lParam & 0x06000000L ))
  50.                   is_shift = is_shift | 0xA000 ;
  51.  
  52.                for(;;)
  53.                {
  54.                   if ( 0xA000 == (is_shift & 0xA000) )
  55.                      new_area = edit4_new( &ca->ew->ControlList, new_area, -1 ) ;
  56.                   else
  57.                      new_area = edit4_new( &ca->ew->ControlList, new_area, 1 ) ;
  58.  
  59.                   if ( new_area == ca )
  60.                      return 1 ;
  61.  
  62.                   if ( new_area->gw.Style & WS_TABSTOP )
  63.                   {
  64.                      #ifdef S4DEBUG  /* some types don't get the focus */
  65.                         switch( new_area->area_type )
  66.                         {
  67.                            case c4button:
  68.                               if ( LOBYTE( LOWORD( new_area->gw.Style )) != BS_GROUPBOX )
  69.                                  break ;
  70.                            case c4display:
  71.                                  e4error( g4cb( ca ), e4result, E4_RESULT_TA2, (char *) 0 ) ;
  72.                                  return 1 ;
  73.                         }     
  74.                      #endif
  75.                       SetFocus( new_area->gw.hWindow ) ;
  76.                      ca->ew->ControlList.selected = (void *) new_area ;
  77.                      if ( (new_area->ew->bw != 0) && (new_area->area_type == c4edit) )
  78.                         browse4_refreshhorzscrollpos( new_area->ew->bw ) ;
  79.                      return 1 ;
  80.                   }
  81.                }
  82.  
  83.             case VK_RETURN:
  84.                if ( control4_ok( ca->ew, 0 ) != 0 )  return 1 ;
  85.                list = &ca->ew->ControlList ;
  86.  
  87.                if ( ca->area_type != c4button )
  88.                   for ( new_area = 0 ; new_area = (G4CONTROL *) l4next( list, new_area ) ; )
  89.                      if ( new_area->is_default != 0 )
  90.                      {
  91.                         button4_process_message( (G4BUTTON *) new_area->area, message, wParam, lParam ) ;
  92.                         return 1 ;
  93.                      }
  94.  
  95.                if ( entry4_controlssave( ca->ew ) == -1 )
  96.                   return -1 ;
  97.                control4_enable( ca ) ;
  98.                ca->ew->return_code = VK_RETURN ;
  99.                return 1 ;
  100.  
  101.             case VK_ESCAPE:
  102.                control4_enable( ca ) ;
  103.                ca->ew->return_code = VK_ESCAPE ;
  104.                return 1 ;
  105.          }
  106.          break ;
  107.  
  108.       case WM_KILLFOCUS:
  109.       {
  110.          G4COMBO *combo = 0 ;
  111.  
  112.          switch( ca->area_type )
  113.          {
  114.             case c4edit:
  115.                combo = (G4COMBO *) ((G4EDIT *)ca->area)->combo ;
  116.                break ;
  117.             case c4list:
  118.                combo = (G4COMBO *) ((G4LIST *)ca->area)->combo ;
  119.                break ;
  120.             case c4button:
  121.                combo = (G4COMBO *) ((G4BUTTON *)ca->area)->combo ;
  122.                break ;
  123.          }
  124.          if ( combo != 0 )
  125.          {
  126.             HWND hwnd = wParam ;
  127.             if ( (hwnd != combo->edit.ca.gw.hWindow)  &&
  128.                  (hwnd != combo->list->ca.gw.hWindow) &&
  129.                  (combo->button != 0) )
  130.                  if ( hwnd != combo->button->ca.gw.hWindow )
  131.                  {
  132.                     combo->is_down = 0 ;
  133.                     combo4_process_message( combo, WM_SYSKEYDOWN, VK_UP, 0x20000000L ) ;
  134.                  }
  135.          }
  136.       }
  137.       break ;
  138.    }
  139.    return 0 ;
  140. }
  141.  
  142. /*****
  143.    Returns 0 if all validation and dates are okay, returns 1 otherwise.
  144.    This function would have to be called whenever a request to change the
  145.    focus was made, ie. TAB, SHIFT-TAB, mouse clicks, RETURN (default button).
  146.    If it fails, the only thing the user can do is fix the bad validation or
  147.    date value, or ALT-F4 (subsequently losing all changes)
  148. *****/
  149.  
  150. int control4_ok( W4ENTRY *ew, int set_focus )
  151. {
  152.    G4CONTROL *ca ;
  153.    L4LIST *list = &ew->ControlList ;
  154.  
  155.    for ( ca = 0 ; ca = (G4CONTROL *) l4next( list, ca ) ; )
  156.       if (ca->area_type == c4edit)
  157.       {
  158.          G4EDIT *ea = ( G4EDIT *) ca ;
  159.          if ( ea->is_valid == 0 )
  160.          {
  161.             if ( ! u4ptr_equal( (void *) 0, (void *) ea->valid ) )
  162.                if ( (*ea->valid)( (struct G4EDIT_st *) ea, ea->valid_data ) != 0 )
  163.                {
  164.                   if ( set_focus )  SetFocus( g4handle( ea )) ;
  165.                   return 1 ;
  166.                }
  167.             if ( ea->EntryType == t4date_str )
  168.                if ( edit4_datecheck( ea ) != 0 )
  169.                {
  170.                   if ( set_focus )  SetFocus( g4handle( ea )) ;
  171.                   return 1 ;
  172.                }
  173.             ea->is_valid = 1 ;
  174.          }
  175.       }
  176.    return 0 ;
  177. }
  178.  
  179. int control4_enable( G4CONTROL *ca )
  180. {
  181.    G4CONTROL *control ;
  182.    L4LIST *list = &ca->ew->ControlList ;
  183.  
  184.    ca->ew->gw.IsDestroyed = 1 ;
  185.    ca->ew->isReady = 0 ;
  186.    if ( ca->ew->gw.hEnable != 0 )
  187.    {
  188.       EnableWindow( ca->ew->gw.hEnable, 1 ) ;
  189.       SetActiveWindow( ca->ew->gw.hEnable ) ;
  190.    }
  191.    ShowWindow( ca->hParent, SW_HIDE ) ;
  192.  
  193.    for ( control = 0 ; control = (G4CONTROL *) l4next( list, control ) ; )
  194.       ValidateRect( g4handle( control ), 0 ) ;
  195.  
  196.    return 0 ;
  197. }
  198.