home *** CD-ROM | disk | FTP | other *** search
- /* g4control.c Control Area Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- void control4_construct( G4CONTROL *ca, W4ENTRY *ew )
- {
- ca->nopaint = 0 ;
- ca->hParent = 0 ;
- ca->gw.Id = 0 ;
- ca->gw.Style = 0 ;
- ca->area_type = c4control ;
- ca->ew = ew ;
- ca->gw.cw = ew->gw.cw ;
- ca->is_default = 0 ;
- }
-
- int control4_process_message( G4CONTROL *ca, WORD message, WORD wParam, LONG lParam )
- {
- switch( message )
- {
- case WM_KEYDOWN:
- case WM_SYSCHAR:
- if ( ca->area_type == c4edit )
- {
- G4EDIT *ea = (G4EDIT *) ca->area ;
- if ( ea->combo != 0 ) return 0 ;
- }
- if ( ca->area_type == c4list ) return 0 ;
- if ( ca->ew->bw == 0 ) return 0 ;
- return browse4_process_key( ca->ew->bw, message, wParam, lParam ) ;
-
- case WM_CHAR:
- switch( wParam )
- {
- G4EDIT *ea ;
- L4LIST *list ;
- G4CONTROL *new_area ;
- int is_shift ;
-
- case VK_TAB:
- if ( control4_ok( ca->ew, 0 ) != 0 ) return 1 ;
- new_area = ca ;
- is_shift = GetKeyState( VK_SHIFT ) ;
- if ( 0x06000000L == ( lParam & 0x06000000L ))
- is_shift = is_shift | 0xA000 ;
-
- for(;;)
- {
- if ( 0xA000 == (is_shift & 0xA000) )
- new_area = edit4_new( &ca->ew->ControlList, new_area, -1 ) ;
- else
- new_area = edit4_new( &ca->ew->ControlList, new_area, 1 ) ;
-
- if ( new_area == ca )
- return 1 ;
-
- if ( new_area->gw.Style & WS_TABSTOP )
- {
- #ifdef S4DEBUG /* some types don't get the focus */
- switch( new_area->area_type )
- {
- case c4button:
- if ( LOBYTE( LOWORD( new_area->gw.Style )) != BS_GROUPBOX )
- break ;
- case c4display:
- e4error( g4cb( ca ), e4result, E4_RESULT_TA2, (char *) 0 ) ;
- return 1 ;
- }
- #endif
- SetFocus( new_area->gw.hWindow ) ;
- ca->ew->ControlList.selected = (void *) new_area ;
- if ( (new_area->ew->bw != 0) && (new_area->area_type == c4edit) )
- browse4_refreshhorzscrollpos( new_area->ew->bw ) ;
- return 1 ;
- }
- }
-
- case VK_RETURN:
- if ( control4_ok( ca->ew, 0 ) != 0 ) return 1 ;
- list = &ca->ew->ControlList ;
-
- if ( ca->area_type != c4button )
- for ( new_area = 0 ; new_area = (G4CONTROL *) l4next( list, new_area ) ; )
- if ( new_area->is_default != 0 )
- {
- button4_process_message( (G4BUTTON *) new_area->area, message, wParam, lParam ) ;
- return 1 ;
- }
-
- if ( entry4_controlssave( ca->ew ) == -1 )
- return -1 ;
- control4_enable( ca ) ;
- ca->ew->return_code = VK_RETURN ;
- return 1 ;
-
- case VK_ESCAPE:
- control4_enable( ca ) ;
- ca->ew->return_code = VK_ESCAPE ;
- return 1 ;
- }
- break ;
-
- case WM_KILLFOCUS:
- {
- G4COMBO *combo = 0 ;
-
- switch( ca->area_type )
- {
- case c4edit:
- combo = (G4COMBO *) ((G4EDIT *)ca->area)->combo ;
- break ;
- case c4list:
- combo = (G4COMBO *) ((G4LIST *)ca->area)->combo ;
- break ;
- case c4button:
- combo = (G4COMBO *) ((G4BUTTON *)ca->area)->combo ;
- break ;
- }
- if ( combo != 0 )
- {
- HWND hwnd = wParam ;
- if ( (hwnd != combo->edit.ca.gw.hWindow) &&
- (hwnd != combo->list->ca.gw.hWindow) &&
- (combo->button != 0) )
- if ( hwnd != combo->button->ca.gw.hWindow )
- {
- combo->is_down = 0 ;
- combo4_process_message( combo, WM_SYSKEYDOWN, VK_UP, 0x20000000L ) ;
- }
- }
- }
- break ;
- }
- return 0 ;
- }
-
- /*****
- Returns 0 if all validation and dates are okay, returns 1 otherwise.
- This function would have to be called whenever a request to change the
- focus was made, ie. TAB, SHIFT-TAB, mouse clicks, RETURN (default button).
- If it fails, the only thing the user can do is fix the bad validation or
- date value, or ALT-F4 (subsequently losing all changes)
- *****/
-
- int control4_ok( W4ENTRY *ew, int set_focus )
- {
- G4CONTROL *ca ;
- L4LIST *list = &ew->ControlList ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( list, ca ) ; )
- if (ca->area_type == c4edit)
- {
- G4EDIT *ea = ( G4EDIT *) ca ;
- if ( ea->is_valid == 0 )
- {
- if ( ! u4ptr_equal( (void *) 0, (void *) ea->valid ) )
- if ( (*ea->valid)( (struct G4EDIT_st *) ea, ea->valid_data ) != 0 )
- {
- if ( set_focus ) SetFocus( g4handle( ea )) ;
- return 1 ;
- }
- if ( ea->EntryType == t4date_str )
- if ( edit4_datecheck( ea ) != 0 )
- {
- if ( set_focus ) SetFocus( g4handle( ea )) ;
- return 1 ;
- }
- ea->is_valid = 1 ;
- }
- }
- return 0 ;
- }
-
- int control4_enable( G4CONTROL *ca )
- {
- G4CONTROL *control ;
- L4LIST *list = &ca->ew->ControlList ;
-
- ca->ew->gw.IsDestroyed = 1 ;
- ca->ew->isReady = 0 ;
- if ( ca->ew->gw.hEnable != 0 )
- {
- EnableWindow( ca->ew->gw.hEnable, 1 ) ;
- SetActiveWindow( ca->ew->gw.hEnable ) ;
- }
- ShowWindow( ca->hParent, SW_HIDE ) ;
-
- for ( control = 0 ; control = (G4CONTROL *) l4next( list, control ) ; )
- ValidateRect( g4handle( control ), 0 ) ;
-
- return 0 ;
- }
-