home *** CD-ROM | disk | FTP | other *** search
- /* g4edit.c Edit Area Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- void edit4_make( W4ENTRY *ew, G4EDIT *ea )
- {
- control4_construct( &ea->ca, ew ) ;
-
- ea->ca.gw.OldWindowProc = 0 ;
- ea->ca.gw.Id = 0 ;
- ea->ca.hParent = 0 ;
- ea->ca.area_type = c4edit ;
- ea->ca.area = (void *) ea ;
-
- ea->Pict = 0 ;
- ea->PictLen = -1 ;
- ea->Decimals = 0 ;
- ea->nChars = -1 ;
- ea->SelectAnchor = -1 ;
- ea->Margin = ea->MarginTotal = 0 ;
- ea->MaxLen = -1 ;
- ea->EntryType = t4str ;
- ea->Offset = 0 ;
- ea->Pos = 0 ;
- ea->pResult = 0 ;
- ea->pResultLen = 0 ;
-
- ea->isModify = 1 ;
-
- ea->width = 0 ;
- ea->x = -1 ;
- ea->y = -1 ;
-
- ea->data_field = 0 ;
- ea->edit_changed = 0 ;
- ea->is_valid = 1 ;
- }
-
- int edit4_make2( W4ENTRY *ew, G4EDIT *ea, int x, int y, char *str,
- int type_get, int width, int dec, int id )
- {
- ea->ca.gw.Style = WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP ;
- if ( type_get == t4num_str )
- ea->ca.gw.Style |= ES_RIGHT ;
-
- ea->ca.gw.Id = ( id < 0 ) ? entry4_nextid( ew ) : id ;
- ea->ca.gw.cw = ew->gw.cw ;
- ea->ca.hParent = ew->gw.hWindow ;
- ea->ca.ew = ew ;
-
- general4_init( &ea->ca.gw, ea->ca.gw.cw, "G4EDIT", 0, ea->ca.gw.Style,
- 0,0,0,0, ea->ca.hParent, ea->ca.gw.Id ) ;
-
- return edit4_init( ea, x, y, str, type_get, width, dec ) ;
- }
-
- G4EDIT *edit4_construct( W4ENTRY *ew )
- {
- G4EDIT *ea = (G4EDIT *) u4alloc( sizeof( G4EDIT )) ;
- if ( ea == 0 )
- e4error( w4cb( ew ), e4memory, (char *) 0 ) ;
- else
- edit4_make( ew, ea ) ;
- return ea ;
- }
-
- int edit4_calcpos( G4EDIT *ea, int pixels )
- {
- int text_pixels, len, i ;
-
- HDC hDC = w4get_dc( g4cb( ea ), ea->ca.gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- pixels -= ea->MarginTotal ;
- len = lstrlen(ea->Buffer) - ea->Offset ;
-
- for ( i = len; i >= 0; i-- )
- {
- text_pixels = LOWORD( GetTextExtent(hDC, ea->Buffer+ea->Offset, i) ) ;
- if ( pixels >= text_pixels )
- break ;
- }
- if ( w4release_dc( g4cb( ea ), ea->ca.gw.hWindow, hDC ) == 0 ) return -1 ;
-
- if ( i < 0 ) i = 0 ;
- return i + ea->Offset ;
- }
-
- int edit4_caretmove( G4EDIT *ea )
- {
- HDC hDC ;
- DWORD res ;
-
- if ( ea->Buffer == 0 ) return 0 ;
-
- hDC = w4get_dc( g4cb( ea ), ea->ca.gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- #ifdef S4DEBUG
- if ( ea->Offset > ea->Pos || ea->Offset < 0 || ea->Pos < 0 || ea->Pos > lstrlen(ea->Buffer)+1 )
- return e4error( g4cb( ea ), e4result, (char *) 0 ) ;
- #endif
- res = GetTextExtent( hDC, ea->Buffer+ea->Offset, ea->Pos-ea->Offset ) ;
-
- SetCaretPos( ea->MarginTotal+LOWORD(res), 0 ) ;
-
- if ( w4release_dc( g4cb( ea ), ea->ca.gw.hWindow, hDC ) == 0 ) return -1 ;
- return 0 ;
- }
-
- int edit4_delete( G4EDIT *ea, int pos, int len )
- {
- int l ;
-
- if ( len <= 0 ) return 0 ;
- if ( ea->Buffer[pos] == '\0' ) return 0 ;
-
- ea->edit_changed = 1 ;
- ea->is_valid = 0 ;
-
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
-
- if ( ea->Pict == 0 || pos >= ea->PictLen )
- {
- char *temp ;
- l = lstrlen( ea->Buffer ) ;
-
- /* No Picture for Deleted Section or no */
- temp = (char *) u4alloc( l-len+1 ) ;
- if ( temp == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memcpy( temp, ea->Buffer, pos ) ;
- memcpy( temp+pos, ea->Buffer+pos+len, l-(len+pos) ) ;
- temp[l-len] = 0 ;
- u4free( ea->Buffer ) ;
- ea->Buffer = temp ;
- return 0 ;
- }
-
- if ( pos + len > ea->PictLen )
- {
- /* Delete Part Overlaps Picture and Non-Picture */
- edit4_delete( ea, ea->PictLen, pos+len-ea->PictLen ) ;
- edit4_delete( ea, pos, ea->PictLen-ea->Pos ) ;
- return 0 ;
- }
-
- /* Only Picture for Delete Part */
- for(; len > 0;)
- {
- char PictCh ;
- int n ;
-
- PictCh = ea->Pict[pos] ;
-
- for( n = 1; ea->Pict[pos+n] != 0; n++ )
- if ( ea->Pict[pos+n] != PictCh )
- break ;
-
- if ( PictCh == '9' )
- {
- if ( len >= n )
- memset( ea->Buffer+pos, '0', n ) ;
- else
- memset( ea->Buffer+pos, '0', len ) ;
- }
- else
- {
- if ( edit4_picturecheck( ea, pos, 0 ) == 0 )
- {
- if ( len >= n )
- memset( ea->Buffer+pos, ' ', n ) ;
- else
- {
- memmove( ea->Buffer+pos, ea->Buffer+pos+len, n-len ) ;
- ea->Buffer[pos+n-1] = ' ' ;
- }
- }
- }
- pos += n ;
- len -= n ;
- }
- l = lstrlen( ea->Buffer ) ;
- for(; ea->Pos < l ; )
- {
- if ( *ea->Buffer+l == ' ' )
- ea->Buffer[l] = 0 ;
- else
- break ;
- }
- return 0 ;
- }
-
- int edit4_init( G4EDIT *ea, int x, int y, char *str, int type_get, int width, int dec )
- {
- char *pict ;
- TEXTMETRIC tm ;
- HDC hDC ;
- char *log_pict = "L" ;
-
- ea->Decimals = dec ;
-
- switch( type_get ) /* set default pictures */
- {
- case t4date_str:
- if ( g4picture( ea, ea->ca.gw.cw->cb.date_format ) < 0 )
- return -1 ;
- break ;
-
- case t4num_str:
- pict = (char *) u4alloc( width+1 ) ;
- if ( pict == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memset( pict, '#', width ) ;
- memset( pict+width-dec, '9', dec ) ;
- pict[width] = 0 ;
- if ( dec > 0 )
- pict[width-dec-1] = '.' ;
- if ( g4picture( ea, pict ) < 0 ) return -1 ;
- u4free( pict ) ;
- break ;
-
- case t4log:
- if ( g4picture( ea, log_pict ) < 0 ) return -1 ;
- break ;
- }
-
- ea->pResult = str ;
- ea->pResultLen = width ;
- ea->EntryType = type_get ;
-
- hDC = w4get_dc( g4cb( ea ), ea->ca.gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- w4get_metrics( hDC, &tm ) ;
-
- ea->Margin = tm.tmAveCharWidth/2 ;
- ea->x = x ;
- ea->y = y ;
-
- if ( w4release_dc( g4cb( ea ), ea->ca.gw.hWindow, hDC ) == 0 ) return -1 ;
-
- SetWindowLong( ea->ca.gw.hWindow, 0, (LONG) ea ) ;
- return 0 ;
- }
-
- int edit4_insertchar( G4EDIT *ea, char ch, int pos )
- { /* 0 - Inserted; 1 - Not Inserted */
- char pChar ;
- int nPictChars, i ;
-
- ea->edit_changed = 1 ;
- ea->is_valid = 0 ;
-
- if ( pos >= ea->PictLen )
- {
- char str1[2] ; str1[0] = ch ; str1[1] = '\0' ;
- return edit4_insertstr( ea, str1, pos ) ;
- }
-
- pChar = ea->Pict[pos] ;
-
- if ( edit4_picturecheck( ea, pos, &ch ) != 0 )
- return 1 ;
-
- for( nPictChars = 1;; nPictChars++ )
- {
- if ( pos+nPictChars >= ea->PictLen )
- break ;
- if ( ea->Pict[pos+nPictChars] != pChar )
- break ;
- }
-
- i = nPictChars - 1 ;
- for ( ; i>0 ; i-- )
- ea->Buffer[pos+i] = ea->Buffer[pos+i-1] ;
- ea->Buffer[pos] = ch ;
-
- edit4_posset( ea, pos + 1, 1 ) ;
- return 0 ;
- }
-
- int S4FUNCTION edit4_insertstr( G4EDIT *ea, char *str, int pos )
- { /* 0 - Inserted; 1 - Not Inserted */
- unsigned start_to_len, move_len, from_len, to_len ;
- char *temp, *to_ptr, *to_pos ;
-
- start_to_len = lstrlen( ea->Buffer ) ;
- move_len = start_to_len - pos ;
- from_len = lstrlen( str ) ;
- to_len = start_to_len + from_len ;
-
- temp = (char *) u4alloc( to_len+1 ) ;
- if ( temp == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
-
- ea->edit_changed = 1 ;
- ea->is_valid = 0 ;
-
- to_ptr = temp ;
- to_pos = to_ptr + pos ;
-
- memcpy( to_pos+from_len, ea->Buffer+pos, move_len ) ;
- memcpy( to_pos, str, from_len ) ;
- memcpy( to_ptr, ea->Buffer, pos ) ;
- to_ptr[to_len] = 0 ;
-
- u4free( ea->Buffer ) ;
- ea->Buffer = temp ;
-
- if ( lstrlen(ea->Buffer) > ea->MaxLen && ea->MaxLen > 0 )
- ea->Buffer[ea->MaxLen] = 0 ;
- if ( edit4_pictureverify( ea ) == 0 )
- {
- edit4_posset( ea, pos + from_len, 1 ) ;
- return 0 ;
- }
-
- memcpy( ea->Buffer, ea->BufferPrev, lstrlen( ea->BufferPrev ) ) ;
- return 1 ;
- }
-
- int edit4_insertsaved( G4EDIT *ea ) /* 0 - Inserted; 1 - Not Inserted */
- {
- int rc = 0 ;
- HANDLE h ;
-
- if ( IsClipboardFormatAvailable( CF_TEXT ) )
- {
- if ( OpenClipboard( ea->ca.gw.hWindow ) )
- {
- h = GetClipboardData( CF_TEXT ) ;
- if ( h != 0 )
- {
- char *ptr ;
-
- ptr = GlobalLock(h) ;
- rc = edit4_insertstr( ea, ptr, edit4_posget( ea ) ) ;
- GlobalUnlock(h) ;
- }
- CloseClipboard() ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- }
- }
- return rc ;
- }
-
- int edit4_paint( G4EDIT *ea )
- {
- RECT r ;
- int ExtraPixels, LowSelect, HighSelect, OnPos ;
- int start = 0, l = lstrlen( ea->Buffer ) ;
-
- HDC hDC = w4get_dc( g4cb( ea ), ea->ca.gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- HideCaret( 0 ) ;
-
- if ( SendMessage( ea->ca.gw.hWindow, WM_ERASEBKGND, hDC, 0 ) == 0 )
- {
- e4error( g4cb( ea ), e4result, "WM_ERASEBKGND", (char *) 0 ) ;
- return -1 ;
- }
- w4get_rect( ea->ca.gw.hWindow, &r, 0 ) ;
-
- if ( ea->Pos > l ) ea->Pos = l ;
- if ( ea->Offset >= ea->Pos ) ea->Offset = ea->Pos-1 ;
- if ( ea->Offset < 0 ) ea->Offset = 0 ;
-
- for(;;)
- {
- int wTot ;
- l = lstrlen( ea->Buffer ) ;
-
- ea->nChars = l - ea->Offset ;
- wTot = r.right - ea->Margin*2 ;
- if ( wTot < 0 ) wTot = 0 ;
- for(;;)
- {
- int wChars = LOWORD( GetTextExtent( hDC, ea->Buffer+ea->Offset, ea->nChars ) ) ;
- if ( wChars <= wTot )
- {
- ExtraPixels = wTot - wChars ;
- break ;
- }
- ea->nChars-- ;
- }
-
- if ( ea->Pos - ea->Offset < ea->nChars )
- break ;
- if ( ea->Pos - ea->Offset == ea->nChars )
- if ( ea->Pos == l )
- break ;
-
- ea->Offset = ea->Pos - ea->nChars + 1 ;
-
- if ( ea->Offset > ea->Pos )
- {
- ea->Offset = ea->Pos ;
- break ;
- }
- }
-
- if ( ea->Pos < ea->SelectAnchor )
- {
- LowSelect = ea->Pos ;
- HighSelect = ea->SelectAnchor ;
- }
- else
- {
- LowSelect = ea->SelectAnchor ;
- HighSelect = ea->Pos ;
- }
- if ( LowSelect < 0 )
- HighSelect = -1 ;
-
- SetTextAlign( hDC, TA_UPDATECP ) ;
- ea->MarginTotal = ea->Margin ;
- if ( ea->ca.gw.Style & ES_RIGHT )
- ea->MarginTotal += ExtraPixels ;
- else if ( ea->ca.gw.Style & ES_CENTER )
- ea->MarginTotal += ExtraPixels/2 ;
-
- MoveTo( hDC, ea->MarginTotal, 0 ) ;
-
- OnPos = ea->Offset ;
-
- if ( ea->Offset < LowSelect )
- {
- int n = LowSelect - OnPos ;
- if ( n > ea->nChars )
- n = ea->nChars ;
- start = LOWORD( GetTextExtent( hDC, ea->Buffer+OnPos, n ) ) ;
- edit4_textout( ea, hDC, 0, 0, ea->Buffer+OnPos, n ) ;
- ea->nChars -= n ;
- OnPos += n ;
- }
-
- if ( HighSelect > OnPos && ea->nChars > 0 )
- {
- DWORD bk = GetBkColor( hDC ) ;
- DWORD tx = GetTextColor( hDC ) ;
- int n = HighSelect - OnPos ;
-
- SetBkColor( hDC, tx ) ;
- SetTextColor( hDC, bk ) ;
-
- if ( n > ea->nChars )
- n = ea->nChars ;
- edit4_textout( ea, hDC, start, 0, ea->Buffer+OnPos, n ) ;
- start += LOWORD( GetTextExtent( hDC, ea->Buffer+OnPos, n ) ) ;
- ea->nChars -= n ;
- OnPos += n ;
-
- SetBkColor( hDC, bk ) ;
- SetTextColor( hDC, tx ) ;
- }
-
- if ( ea->nChars > 0 )
- edit4_textout( ea, hDC, start, 0, ea->Buffer+OnPos, ea->nChars ) ;
-
- if ( w4release_dc( g4cb( ea ), ea->ca.gw.hWindow, hDC )== 0 ) return -1 ;
-
- if ( GetFocus() == ea->ca.gw.hWindow )
- edit4_caretmove( ea ) ;
- ShowCaret(0) ;
- ValidateRect( ea->ca.gw.hWindow, 0 ) ;
-
- return 0 ;
- }
-
- int S4FUNCTION g4picture( G4EDIT *ea, char *pict )
- {
- int l ;
-
- #ifdef S4DEBUG
- if ( ea == 0 )
- e4severe( e4parm, "g4picture", E4_PARM_ZER, (char *) 0 ) ;
- #endif
-
- if ( ea->ca.gw.cw->cb.error_code < 0 ) return -1 ;
-
- if ( ea->EntryType == t4num_str )
- {
- /* ensures that the picture is of the form : "#,,,##.9,,,99" */
- char *ptr = strchr( pict, '.' ) ;
- if ( ptr == 0 )
- memset( pict, '#', lstrlen( pict )) ;
- else
- {
- memset( pict, '#', lstrlen( pict ) - lstrlen( ptr ) ) ;
- memset( ptr+1, '9', lstrlen( ptr ) - 1 ) ;
- }
- }
-
- l = lstrlen( pict ) ;
-
- if ( ea->Pict != 0 ) u4free( ea->Pict ) ;
- ea->PictLen = 0 ;
-
- if ( pict != 0 )
- {
- ea->Pict = (char *) u4alloc( l + 1 ) ;
- if ( ea->Pict == 0 ) return -1 ;
- ea->Pict[l] = 0 ;
-
- memcpy( ea->Pict, pict, l ) ;
- if ( ea->Pict != 0 )
- ea->PictLen = l ;
- }
- else
- ea->Pict = 0 ;
-
- return 0 ;
- }
-
- const char YES_CHAR = 'Y' ;
-
- int edit4_picturecheck( G4EDIT *ea, int pict_pos, char *pCh )
- {
- unsigned char ch = 0, cPict ;
- int final_rc ;
-
- if ( pCh != 0 ) ch = *pCh ;
-
- if ( ea->Pict == 0 )
- return e4error( g4cb( ea ), e4result, E4_RESULT_PIC, (char *) 0 ) ;
-
- if ( pict_pos >= ea->PictLen )
- return 0 ;
-
- cPict = ea->Pict[pict_pos] ;
- final_rc = 0 ;
-
- switch ( cPict )
- {
- case '!':
- case 'L':
- if ( pCh == 0 ) break ;
-
- AnsiUpperBuff( pCh, 1 ) ;
- if ( cPict == 'L' )
- {
- ch = *pCh ;
-
- if ( ch == 'Y' ) *pCh = 'T' ;
- if ( ch == 'N' ) *pCh = 'F' ;
-
- if ( ch != 'Y' && ch != 'N' &&
- #ifdef S4GERMAN
- ch != 'J' &&
- #endif
- ch != 'T' && ch != 'F' )
- final_rc = 1 ;
- }
- if ( cPict == 'Y' )
- {
- ch = *pCh ;
-
- #ifdef S4GERMAN
- if ( ch != 'Y' && ch != 'J' && ch != 'N' )
- final_rc = 1 ;
- #else
- if ( ch != 'Y' && ch != 'N' )
- final_rc = 1 ;
- #endif
- }
- break ;
-
- case 'X':
- return 0 ;
-
- case '9':
- if ( ch < '0' || ch > '9' )
- final_rc = 1 ;
- break ;
-
- case '#':
- if ( ch != '+' && ch != '-' && ch != ' ' && (ch < '0' || ch > '9') )
- final_rc = 1 ;
- break ;
-
- case 'A':
- case 'N':
- if ( ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' )
- break ;
- if ( (ch >= '0' && ch <= '9' || ch == '_' ) && cPict == 'N' )
- break ;
- #ifdef S4GERMAN /* ANSI char codes */
- if ( (ch == 196) || (ch == 214) || (ch == 220) || (ch == 223) ||
- (ch == 228) || (ch == 246) || (ch == 252) )
- break ;
- #endif
- #ifdef S4FRENCH /* ANSI char codes */
- if ( (ch == 192) || (ch == 194) || (ch == 206) || (ch == 207) ||
- (ch == 212) || (ch == 219) || (ch == 224) || (ch == 226) ||
- (ch == 238) || (ch == 239) || (ch == 244) || (ch == 251) ||
- (ch >= 199 && ch <= 203) || (ch >= 231 && ch <= 235) )
- break ;
- #endif
- final_rc = 1 ;
- break ;
-
- case 'C':
- case 'D':
- case 'M':
- case 'Y':
- if ( ea->EntryType == t4date_str )
- {
- final_rc = 1 ;
-
- if ( cPict == 'M' )
- {
- int i, num = 0 ;
-
- for ( i = 0; ea->Pict[i] != 0; i++ )
- if ( ea->Pict[i] == 'M' ) num++ ;
- if ( num > 2 )
- {
- if (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch == ' ')
- final_rc = 0 ;
- #ifdef S4GERMAN /* ANSI char codes */
- if ( (ch == 196) || (ch == 214) || (ch == 220) || (ch == 223) ||
- (ch == 228) || (ch == 246) || (ch == 252) )
- final_rc = 0 ;
- #endif
- #ifdef S4FRENCH /* ANSI char codes */
- if ( (ch == 192) || (ch == 194) || (ch == 206) || (ch == 207) ||
- (ch == 212) || (ch == 219) || (ch == 224) || (ch == 226) ||
- (ch == 238) || (ch == 239) || (ch == 244) || (ch == 251) ||
- (ch >= 199 && ch <= 203) || (ch >= 231 && ch <= 235) )
- final_rc = 0 ;
- #endif
- break ;
- }
- }
- if ( ch >= '0' && ch <= '9' || ch == ' ')
- final_rc = 0 ;
- break ;
- }
- else
- {
- if ( pCh == 0 ) break ;
- if ( cPict == 'Y' )
- {
- AnsiUpperBuff( pCh, 1 ) ;
- ch = *pCh ;
-
- #ifdef S4GERMAN
- if ( ch != 'Y' && ch != 'J' && ch != 'N' )
- final_rc = 1 ;
- #else
- if ( ch != 'Y' && ch != 'N' )
- final_rc = 1 ;
- #endif
- }
- }
- break ;
-
- default:
- if ( pCh != 0 )
- *pCh = cPict ;
- if ( ch == 0 || ch == cPict )
- return 2 ;
- else
- return 3 ;
- }
- if ( ch == 0 )
- final_rc = 0 ;
- return final_rc ;
- }
-
- int edit4_pictureverify( G4EDIT *ea )
- { /* 1 - Not Good; 0 - Good; < 0 Error */
- char *ptr ;
- int i, rc, len = lstrlen( ea->Buffer ) ;
-
- if ( (ea->EntryType == t4num_str) && (ea->BufferPrev != 0) )
- {
- int start, finish ;
-
- start = edit4_posget( ea ) + 1 ;
- finish = len - ea->Decimals - 1 ;
- if ( ea->Decimals == 0 ) finish++ ;
-
- if ( (start > finish) && (ea->Buffer[ea->Pos] == '.') ) return 1 ;
- if ( start > finish ) return 0 ; /* added this ... */
-
- memset( ea->Buffer+start, ' ', finish-start ) ;
-
- /* if '.' pressed on 'whole' part of number */
- if ( ( ea->Buffer[ea->Pos] == '.' ) && ( ea->Decimals > 0 ) )
- {
- if ( ea->Pos == 0 )
- {
- memset( ea->Buffer, ' ', finish ) ;
- ea->Buffer[finish-1] = '0' ;
- edit4_posset( ea, finish-1, 1 ) ;
- }
- else
- {
- if ( ea->Pos > 0 )
- {
- ptr = (char *) u4alloc( ea->Pos+1 ) ;
- if ( ptr == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memcpy( ptr, ea->Buffer, ea->Pos+1 ) ;
- memset( ea->Buffer, ' ', finish ) ;
- memcpy( ea->Buffer+finish-ea->Pos, ptr, ea->Pos ) ;
- edit4_posset( ea, finish-1, 1 ) ;
- u4free( ptr ) ;
- }
- }
-
- ptr = strchr( ea->Buffer, '.' ) ;
- if ( ptr != 0 )
- if ( strcspn( ea->Buffer, "1234567890" ) > len-ea->Decimals-1 )
- *(ptr-1) = '0' ;
-
- memset( ea->Buffer+finish+1, '0', len-finish-1 ) ;
- }
- }
- if ( ea->Pict == 0 )
- {
- if ( ea->EntryType == t4num_str )
- {
- for( i = 0; i < len ; i++ )
- {
- char ch = ea->Buffer[i] ;
- if ( ch != 0 && (ch < '0' || ch > '9') && ch != '+' && ch != '-' && ch != '.' )
- return 1 ;
- }
- return 0 ;
- }
- return 0 ;
- }
- ptr = ea->Buffer ;
- for ( i = 0; ea->Pict[i] != 0 && i < len; i++ )
- {
- rc = edit4_picturecheck( ea, i, ptr+i ) ;
- if ( rc == 1 || rc == 3 )
- return 1 ;
- }
- return 0 ;
- }
-
- int edit4_posget( G4EDIT *ea )
- {
- return ea->Pos ;
- }
-
- void edit4_posset( G4EDIT *ea, int new_pos, int pict_dir )
- { /* 0 - None; 1 Change Up; -1 Move Down */
- int l = lstrlen( ea->Buffer ) ;
-
- if ( ea->isModify == 0 ) return ;
- ea->Pos = new_pos ;
-
- if ( ea->Pos < 0 ) ea->Pos = 0 ;
- if ( ea->Pos > l ) ea->Pos = l ;
-
- for ( ; ea->Pos < ea->PictLen ; )
- {
- if ( edit4_picturecheck( ea, ea->Pos, 0 ) > 1 )
- {
- ea->Buffer[ea->Pos] = ea->Pict[ea->Pos] ;
- ea->Pos += pict_dir ;
-
- if ( ea->Pos < 0 )
- {
- ea->Pos = new_pos ;
- pict_dir = 1 ;
- }
- continue ;
- }
- if ( ea->Pos > l ) ea->Pos = l ;
- break ;
- }
-
- if ( ea->Pos < ea->Offset )
- {
- ea->Offset = ea->Pos - 1 ;
- if ( ea->Offset < 0 ) ea->Offset = 0 ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- }
- else
- {
- if ( ea->Pos-ea->Offset > ea->nChars )
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- else
- edit4_caretmove( ea ) ;
- }
- edit4_selectnone( ea ) ;
- }
-
- int S4FUNCTION g4edit_save( G4EDIT *ea )
- {
- int i, j ;
- int l = lstrlen( ea->Buffer ) ;
- int count ;
- D4DATA *data ;
-
- if ( ea->data_field != 0 )
- {
- data = f4data( ea->data_field ) ;
- count = (int) d4reccount( data ) ;
- }
-
- edit4_packnumeric( ea ) ;
-
- if ( ea->combo != 0 )
- {
- if ( l < ea->pResultLen )
- {
- memcpy( ea->pResult, ea->Buffer, l ) ;
- memset( ea->pResult+l, ' ', ea->pResultLen-l ) ;
- if ( ea->data_field == 0 )
- ea->pResult[l] = 0 ;
- }
- else
- memcpy( ea->pResult, ea->Buffer, ea->pResultLen ) ;
-
- if ( ea->data_field != 0 )
- if ( count > 0 )
- f4assign_ptr( ea->data_field ) ;
- else
- {
- d4append_start( data, 1 ) ;
- d4append( data ) ;
- }
- ea->edit_changed = 0 ;
- return 0 ;
- }
-
- if ( ea->edit_changed == 0 )
- return 0 ;
-
- if ( ea->data_field != 0 )
- if ( f4type( ea->data_field ) == 'M' )
- {
- m4assign( ea->data_field, ea->Buffer ) ;
- ea->edit_changed = 0 ;
- return 0 ;
- }
-
- if ( ea->Pict == 0 )
- {
- if ( l < ea->pResultLen )
- {
- memcpy( ea->pResult, ea->Buffer, l ) ;
- memset( ea->pResult+l, ' ', ea->pResultLen-l ) ;
- if ( ea->data_field == 0 )
- ea->pResult[l] = 0 ;
- }
- else
- memcpy( ea->pResult, ea->Buffer, ea->pResultLen ) ;
- }
- else
- { /* need to also make sure it is a valid date picture */
- if ( ea->EntryType == t4date_str )
- {
- if ( edit4_datecheck( ea ) != 0 )
- return -1 ;
- a4init( ea->pResult, ea->Buffer, ea->Pict );
- }
- else
- {
- for ( i=0, j=0 ; j < l ; i++, j++ )
- if ( j < ea->PictLen )
- {
- if ( ((ea->EntryType == 'n') || (ea->EntryType == 'N')) &&
- (ea->Decimals > 0) && (ea->Pict[j] == '.') )
- ea->pResult[i] = ea->Buffer[j] ;
- else
- {
- if ( strrchr( "!9#ALNXYCYDM", ea->Pict[j] ) != 0 )
- ea->pResult[i] = ea->Buffer[j] ;
- else
- i-- ;
- }
- }
- else
- ea->pResult[i] = ea->Buffer[j] ;
- }
- }
- if ( ea->data_field != 0 )
- if ( count > 0 )
- f4assign_ptr( ea->data_field ) ;
- else
- {
- d4append_start( data, 1 ) ;
- d4append( data ) ;
- }
-
- ea->edit_changed = 0 ;
-
- return 0 ;
- }
-
- void edit4_selectblanks( G4EDIT *ea, int dir, int flag )
- {
- char *ptr = ea->Buffer ;
- int len = lstrlen( ea->Buffer ) ;
-
- for(;;)
- {
- if ( ea->Pos < 0 )
- break ;
- if ( ! (flag && ptr[ea->Pos] == ' ' || ! flag && ptr[ea->Pos] != ' ') )
- break ;
- if ( (ea->Pos >= len) && (dir > 0) )
- break ;
- ea->Pos += dir ;
- }
- }
-
- int edit4_selectdelete( G4EDIT *ea )
- { /* 1 - Did delete; 0 - Nothing to delete */
- if ( ea->SelectAnchor >= 0 )
- {
- int rc ;
- if ( ea->Pos < ea->SelectAnchor )
- {
- rc = edit4_delete( ea, ea->Pos, ea->SelectAnchor-ea->Pos ) ;
- edit4_posset( ea, ea->Pos, 1 ) ;
- }
- else
- {
- rc = edit4_delete( ea, ea->SelectAnchor, ea->Pos-ea->SelectAnchor ) ;
- edit4_posset( ea, ea->SelectAnchor, 1 ) ;
- }
- edit4_selectnone( ea ) ;
- return rc ;
- }
- return 0 ;
- }
-
- void edit4_selectextraword( G4EDIT *ea, int dir )
- {
- if ( ea->SelectAnchor < 0 ) ea->SelectAnchor = ea->Pos ;
- if ( dir < 0 ) ea->Pos-- ;
- edit4_selectblanks( ea, dir, 1 ) ; /* Select past blanks */
- if ( dir > 0 )
- { /* Increasing selection */
- edit4_selectblanks( ea, dir, 0 ) ; /* Select past non-blanks */
- edit4_selectblanks( ea, dir, 1 ) ; /* Select past blanks */
- }
- else
- { /* Decreasing selection */
- edit4_selectblanks( ea, dir, 0 ) ; /* Select past non-blanks */
- ea->Pos++ ;
- }
- if ( ea->SelectAnchor == ea->Pos )
- edit4_selectnone( ea ) ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- }
-
- void edit4_selectnone( G4EDIT *ea )
- {
- if ( ea->SelectAnchor >= 0 )
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
-
- ea->SelectAnchor = -1 ;
- }
-
- int edit4_selectposlow( G4EDIT *ea )
- {
- if ( ea->SelectAnchor < ea->Pos )
- return ea->SelectAnchor ;
- return ea->Pos ;
- }
-
- int edit4_selectlen( G4EDIT *ea )
- {
- int len ;
-
- if ( ea->SelectAnchor < 0 )
- return 0 ;
- len = ea->SelectAnchor - ea->Pos ;
- if ( len < 0 ) len = -len ;
- return len ;
- }
-
- int edit4_selectsave( G4EDIT *ea ) /* Save to clipboard */
- {
- HANDLE h ;
- char *ptr ;
- int len, pos = edit4_selectposlow( ea ) ;
-
- if ( pos >= 0 )
- {
- if ( ! OpenClipboard( ea->ca.gw.hWindow ))
- return 1 ;
-
- len = edit4_selectlen( ea ) ;
-
- h = GlobalAlloc( GHND, (DWORD)(len)+1 ) ;
- if ( h == 0 )
- {
- e4error( g4cb( ea ), e4memory, "edit4_selectsave", (char *) 0 ) ;
- CloseClipboard() ;
- return -1 ;
- }
- ptr = GlobalLock( h ) ;
- memcpy( ptr, ea->Buffer+pos, edit4_selectlen( ea ) ) ;
-
- GlobalUnlock( h ) ;
-
- EmptyClipboard() ;
- SetClipboardData( CF_TEXT, h ) ;
- CloseClipboard() ;
- }
- return 0 ;
- }
-
- void edit4_selectto( G4EDIT *ea, int pos )
- {
- int l = lstrlen( ea->Buffer ) ;
-
- if ( pos < 0 ) pos = 0 ;
- if ( pos > l ) pos = l ;
- if ( ea->SelectAnchor < 0 )
- ea->SelectAnchor = ea->Pos ;
- ea->Pos = pos ;
- if ( ea->Pos == ea->SelectAnchor )
- ea->SelectAnchor = -1 ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- }
-
- void edit4_selectusingmouse( G4EDIT *ea, int pixels )
- {
- RECT r ;
-
- if ( g4handle( ea ) != GetFocus() ) return ;
-
- if ( pixels < 0 )
- {
- edit4_selectto( ea, ea->Pos-1 ) ;
- return ;
- }
-
- w4get_rect( ea->ca.gw.hWindow, &r, 0 ) ;
- if ( pixels > r.right )
- edit4_selectto( ea, ea->Pos+1 ) ;
- else
- edit4_selectto( ea, edit4_calcpos( ea, pixels ) ) ;
- }
-
- void edit4_typeoverflip( G4EDIT *ea )
- {
- ea->ca.gw.cw->TypeOver =! ea->ca.gw.cw->TypeOver ;
- edit4_caretcreate( ea ) ;
- ShowCaret( ea->ca.gw.hWindow ) ;
- }
-
- void edit4_undo( G4EDIT *ea )
- {
- int l = lstrlen( ea->Buffer ) ;
-
- ea->edit_changed = 1 ;
- ea->is_valid = 0 ;
-
- memcpy( ea->Buffer, ea->BufferPrev, l ) ;
- ea->SelectAnchor = -1 ;
- if ( ea->Pos > l ) ea->Pos = l ;
- InvalidateRect( ea->ca.gw.hWindow, NULL, 0 ) ;
- }
-
- int edit4_process_message( G4EDIT *ea, WORD message, WORD wParam, LONG lParam )
- {
- int l, rc, move = 1 ;
-
- if ( ea->Buffer != 0 ) l = lstrlen( ea->Buffer ) ;
- if ( ea == 0 ) return 0 ; /* static area chosen in browse */
-
- rc = control4_process_message( &ea->ca, message, wParam, lParam ) ;
- if ( rc ) return rc ;
-
- switch( message )
- {
- case WM_NCPAINT:
- {
- G4CONTROL *ca ;
- G4COMBO *cba ;
- W4ENTRY *ew = w4entry( ea ) ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- if ( ca->area_type == c4edit )
- {
- cba = (G4COMBO *) ((G4EDIT *)ca->area)->combo ;
- if ( cba != 0 )
- if ( (cba->is_down == 1) && (cba->isDrop == 1) )
- return 1 ;
- }
- return 0 ;
- }
-
- case WM_CHAR:
- if ( ea->isModify == 0 ) return 1 ;
- if ( wParam == VK_BACK ) return 1 ;
-
- if ( ea->BufferPrev != 0 )
- u4free( ea->BufferPrev ) ;
- ea->BufferPrev = (char *) u4alloc( l + 1 ) ;
- memcpy( ea->BufferPrev, ea->Buffer, l + 1 ) ;
- edit4_selectdelete( ea ) ;
-
- if ( (ea->ca.gw.cw->TypeOver) || (ea->EntryType == t4num_str) )
- rc = edit4_replace( ea, wParam, edit4_posget( ea ) ) ;
- else
- rc = edit4_insertchar( ea, (char) wParam, edit4_posget( ea ) ) ;
-
- if ( rc == 0 )
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- break ;
-
- case WM_KEYDOWN:
- {
- int is_shift, is_ctrl, is_none, is_shift_ctrl, final_pos ;
-
- if ( ea->combo != 0 )
- if ( (wParam == VK_UP) || (wParam == VK_DOWN) )
- {
- G4COMBO *combo = (G4COMBO *) ea->combo ;
- SendMessage( combo->list->ca.gw.hWindow, WM_KEYDOWN, wParam, NULL ) ;
- return 1 ;
- }
-
- if ( ea->isModify == 0 ) return 1 ;
- is_shift = GetKeyState( VK_SHIFT ) < 0 ;
- is_ctrl = GetKeyState( VK_CONTROL ) < 0 ;
- is_none = 1 ;
- if ( is_shift || is_ctrl ) is_none = 0 ;
- is_shift_ctrl = is_shift && is_ctrl ;
- if ( is_shift_ctrl )
- is_shift = is_ctrl = 0 ;
-
- switch ( wParam )
- {
- case VK_BACK:
- if ( is_none )
- {
- int cur_pos = edit4_posget( ea ) ;
- if ( cur_pos > 0 )
- {
- edit4_posset( ea, edit4_posget( ea ) - 1, -1 ) ;
- if ( edit4_posget( ea ) < cur_pos )
- edit4_delete( ea, edit4_posget( ea ), 1 ) ;
- }
- }
- return 1 ;
-
- case VK_INSERT:
- if ( is_ctrl ) edit4_selectsave( ea ) ;
- if ( is_shift )
- {
- u4free( ea->BufferPrev ) ;
- ea->BufferPrev = (char *) u4alloc( l + 1 ) ;
- memcpy( ea->BufferPrev, ea->Buffer, l + 1 ) ;
- edit4_insertsaved( ea ) ;
- }
- if ( is_none )
- if ( ea->isModify == 1 )
- edit4_typeoverflip( ea ) ;
- break ;
-
- case VK_DELETE:
- final_pos = edit4_selectposlow( ea ) ;
- if ( is_shift )
- {
- if ( final_pos < 0 )
- break ;
- if ( edit4_selectsave( ea ) )
- return 1 ;
- edit4_selectdelete( ea ) ;
- edit4_posset( ea, final_pos, 1 ) ;
- break ;
- }
- if ( edit4_selectdelete( ea ) )
- {
- edit4_posset( ea, final_pos, 1 ) ;
- break ;
- }
- edit4_delete( ea, edit4_posget( ea ), 1 ) ;
- break ;
-
- case VK_HOME:
- if ( is_shift || is_shift_ctrl )
- edit4_selectto( ea, 0 ) ;
- if ( is_none )
- edit4_posset( ea, 0, 1 ) ;
- break ;
-
- case VK_END:
- {
- int j = l - 1 ;
- while ( (ea->Buffer[j] == ' ') && (j>=0) )
- j-- ;
-
- if ( is_shift || is_shift_ctrl )
- edit4_selectto( ea, j+1 ) ;
- else
- edit4_posset( ea, j+1, 1 ) ;
- }
- break ;
-
- case VK_LEFT:
- move = -1 ;
- case VK_RIGHT:
- if ( is_shift )
- edit4_selectto( ea, ea->Pos + move ) ;
- if ( is_shift_ctrl )
- edit4_selectextraword( ea, move ) ;
- if ( is_none )
- edit4_posset( ea, edit4_posget( ea )+move, move ) ;
- break ;
- }
- break ;
- }
-
- case WM_PAINT:
- if ( ea->ca.nopaint == 1 )
- ea->ca.nopaint = 0 ;
- else
- edit4_paint( ea ) ;
- return 1 ;
-
- case WM_SETFOCUS:
- {
- W4ENTRY *entry = ea->ca.ew ;
-
- edit4_caretcreate( ea ) ;
- edit4_caretmove( ea ) ;
- ShowCaret( ea->ca.gw.hWindow ) ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
-
- if ( (entry->bw != 0) && (entry->isReady != 0) )
- {
- browse4_current( entry->bw, ea ) ;
- browse4_refreshhorzscrollpos( entry->bw ) ;
- }
- break ;
- }
-
- case WM_KILLFOCUS:
- edit4_packnumeric( ea ) ;
- edit4_selectnone(ea);
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- DestroyCaret() ;
- break ;
-
- case WM_SYSCHAR:
- if ( wParam == VK_BACK )
- if ( lParam & 0x20000000L )
- {
- edit4_undo( ea ) ;
- return 1 ;
- }
- if ( entry4_process_message( ea->ca.ew, WM_SYSCHAR, wParam, lParam ) )
- return 1 ;
- break ;
-
- case WM_LBUTTONDOWN:
- if ( control4_ok( ea->ca.ew, 1 ) == 0 )
- {
- if ( GetFocus() != ea->ca.gw.hWindow )
- {
- SetFocus( ea->ca.gw.hWindow ) ;
- ea->ca.ew->ControlList.selected = (void *) &ea->ca ;
- }
- if ( ea->isModify == 0 ) return 0 ;
- SetCapture( ea->ca.gw.hWindow ) ;
- if ( ! (wParam & MK_SHIFT) )
- edit4_selectnone( ea ) ;
- edit4_posset( ea, edit4_calcpos( ea, LOWORD(lParam) ), -1 ) ;
- }
- else
- {
- if ( GetFocus() == ea->ca.gw.hWindow )
- {
- if ( ea->isModify == 0 ) return 0 ;
- SetCapture( ea->ca.gw.hWindow ) ;
- if ( ! (wParam & MK_SHIFT) )
- edit4_selectnone( ea ) ;
- edit4_posset( ea, edit4_calcpos( ea, LOWORD(lParam) ), -1 ) ;
- }
- }
- break ;
-
- case WM_LBUTTONUP:
- if ( control4_ok( ea->ca.ew, 0 ) != 0 ) return 0 ;
- if ( ea->isModify == 0 ) return 0 ;
- if ( ea->ca.gw.hWindow != GetFocus() ) return 0 ;
- ReleaseCapture() ;
- edit4_selectto( ea, edit4_calcpos( ea, LOWORD(lParam) ) ) ;
- break ;
-
- case WM_MOUSEMOVE:
- if ( wParam & MK_LBUTTON )
- if ( ea->isModify == 1 )
- edit4_selectusingmouse( ea, LOWORD(lParam) ) ;
- break ;
- }
- return 0 ;
- }
-
- int S4FUNCTION g4edit_refresh( G4EDIT *ea )
- {
- ea->Pos = 0 ;
-
- if ( ea->combo != 0 )
- {
- combo4_setselection( ea->ca.gw.hWindow, ea->ca.ew, 1 ) ;
- return 0 ;
- }
-
- if ( ea->Buffer != 0 )
- u4free( ea->Buffer ) ;
-
- if ( ea->data_field != 0 )
- if ( f4type( ea->data_field ) == 'M' )
- if ( ea->pResult != 0 )
- {
- int len = m4len( ea->data_field ) ;
- ea->Buffer = (char *) u4alloc( len+1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- m4ncpy( ea->data_field, ea->Buffer, len+1 ) ;
- ea->MaxLen = -1 ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- return 0 ;
- }
-
- if ( ea->Pict == 0 )
- {
- ea->Buffer = (char *) u4alloc( ea->pResultLen+1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memset( ea->Buffer, ' ', ea->pResultLen+1 ) ;
- ea->Buffer[ea->pResultLen] = 0 ;
- u4ncpy( ea->Buffer, ea->pResult, ea->pResultLen+1 ) ;
- }
- else
- { /* if no picture specified for date, use default */
- if ( ea->EntryType == t4date_str )
- {
- ea->Buffer = (char *) u4alloc( ea->PictLen+1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memset( ea->Buffer, ' ', ea->PictLen+1 ) ;
- ea->Buffer[ea->PictLen] = 0 ;
- a4format( ea->pResult, ea->Buffer, ea->Pict ) ;
- }
- else
- {
- if ( ea->EntryType == t4num_str )
- {
- ea->Buffer = (char *) u4alloc( ea->PictLen+1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memset( ea->Buffer, ' ', ea->PictLen ) ;
- ea->Buffer[ea->PictLen] = 0 ;
- memcpy( ea->Buffer, ea->Pict, ea->PictLen ) ;
-
- if ( ea->pResult[ea->pResultLen-1] == ' ' )
- {
- double d ;
- c4atod2( ea->pResult, ea->pResultLen, &d ) ;
- c4dtoa45( d, ea->pResult, ea->pResultLen, ea->Decimals ) ;
- }
- memcpy( ea->Buffer, ea->pResult, ea->PictLen ) ;
- }
- else
- {
- int npict = edit4_nonpictchars( ea->Pict ) ;
- ea->Buffer = (char *) u4alloc( ea->pResultLen + npict + 1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memset( ea->Buffer, ' ', ea->pResultLen + npict + 1 ) ;
- ea->Buffer[ea->pResultLen+npict] = 0 ;
- memcpy( ea->Buffer, ea->Pict, ea->PictLen ) ;
- edit4_pictureapply( ea ) ;
- memcpy( ea->Buffer+ea->PictLen, ea->pResult+(ea->PictLen-npict), (ea->pResultLen-ea->PictLen+npict) ) ;
- }
- }
- }
-
- if ( ea->Pict != 0 )
- ea->Pos = ea->PictLen - lstrlen( strpbrk( ea->Pict, "!9#ALNXYCYDM" )) ;
-
- if ( ea->pResultLen > lstrlen( ea->Buffer ) )
- ea->MaxLen = ea->pResultLen ;
- else
- ea->MaxLen = lstrlen( ea->Buffer ) ;
-
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- return 0 ;
- }
-
- int edit4_replace( G4EDIT *ea, int chr, int pos )
- { /* 0 - Replaced; 1 - Not Replaced */
- int l = lstrlen( ea->BufferPrev ) ;
- if ( pos >= lstrlen( ea->Buffer ) )
- return edit4_insertchar( ea, (char) chr, pos ) ;
-
- ea->Buffer[pos] = (char) chr ;
-
- if ( edit4_pictureverify( ea ) != 0 )
- { /* reinstate the BufferPrev ... */
- if ( ea->Buffer != 0 ) u4free( ea->Buffer ) ;
- ea->Buffer = (char *) u4alloc( l + 1 ) ;
- if ( ea->Buffer == 0 )
- return e4error( g4cb( ea ), e4memory, (char *) 0 ) ;
- memcpy( ea->Buffer, ea->BufferPrev, l + 1 ) ;
- return 1 ;
- }
-
- ea->edit_changed = 1 ;
- ea->is_valid = 0 ;
- edit4_posset( ea, edit4_posget( ea ) + 1, 1 ) ;
-
- return 0 ;
- }
-
- int edit4_pictureapply( G4EDIT *ea )
- {
- int i, j ;
-
- for ( i=0, j=0 ; j<ea->PictLen ; i++, j++ )
- {
- if ( strrchr( "!9#ALNXYCYDM", ea->Buffer[j] ) == 0 )
- i-- ;
- else
- {
- if ( ea->Buffer[j] == '9' && ea->pResult[i] == ' ' )
- ea->Buffer[j] = '0' ;
- else
- ea->Buffer[j] = ea->pResult[i] ;
- }
- }
- if ( edit4_pictureverify( ea ) != 0 ) return 1 ; /* no good */
- return 0 ;
- }
-
- int edit4_nonpictchars( char *pict )
- {
- int len, i, npict = 0 ;
-
- len = lstrlen( pict ) ;
-
- for ( i = 0 ; i < len ; i++ )
- {
- switch ( pict[i] )
- {
- case '!':
- case '9':
- case '#':
- case 'A':
- case 'L':
- case 'N':
- case 'X':
- case 'Y': /* if any 'Y', it is a legal picture character */
- break ;
-
- case 'C':
- case 'D': /* these must have at least 2, or it */
- case 'M': /* is a nonpictchar ... */
- if ( pict[i+1] != pict[i] )
- {
- npict++ ;
- i++ ;
- }
- break ;
-
- default:
- npict++ ;
- }
- }
- return npict ;
- }
-
- G4EDIT *edit4_create( W4ENTRY *ew, C4CONTROLITEM *control, char *text,
- int low, int high )
- {
- G4EDIT *ea = entry4_get_create( ew, (control->X * low)/4, (control->Y * high)/8,
- text, t4str, 0, 0, control->Id ) ;
-
- MoveWindow( g4handle( ea ), (control->X * low)/4, (control->Y * high)/8,
- (control->CX * low)/4, (control->CY * high)/8, 1 ) ;
-
- g4set_style( ea, control->Style ) ;
- g4width( ea, (control->CX * low)/4 ) ;
-
- return ea ;
- }
-
- void edit4_textout( G4EDIT *ea, HDC hDC, int x, int y, char *str, int count )
- {
- char *upper = str ;
-
- if ( ea != 0 )
- if ( ea->isUpper == 1 )
- upper = AnsiUpper( str ) ;
-
- TextOut( hDC, x, y, upper, count ) ;
- }
-
- void edit4_selectall( G4EDIT *ea )
- {
- ea->Pos = lstrlen( ea->Buffer ) ;
- ea->SelectAnchor = 0 ;
- }
-
- void S4FUNCTION g4valid_work( G4EDIT *ea, S4VALID *valid, void *valid_data )
- {
- #ifdef S4DLL
- if ( ! u4ptr_equal( (void *) 0, (void *) ea->valid ))
- FreeProcInstance( (FARPROC) ea->valid ) ;
- #endif
- ea->valid = valid ;
- ea->valid_data = valid_data ;
- }
-
- void edit4_packnumeric( G4EDIT *ea )
- {
- if ( ea->EntryType == t4num_str )
- {
- int i, j, k ;
-
- j = lstrlen( ea->Buffer ) - 1 ;
- for ( i = j ; i >= 0 ; i-- )
- {
- ea->Buffer[j] = ea->Buffer[i] ;
- if ( ea->Buffer[i] != ' ' )
- j-- ;
- }
- for ( k = 0 ; k <= j ; k++ )
- ea->Buffer[k] = ' ' ;
- InvalidateRect( ea->ca.gw.hWindow, 0, 0 ) ;
- }
- }
-
- long S4FUNCTION g4get_style( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- return GetWindowLong( g4handle( control ), GWL_STYLE ) ;
- }
-
- void S4FUNCTION g4set_style( void *control_pointer, long style )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- control->gw.Style = style ;
- SetWindowLong( g4handle( control ), GWL_STYLE, style ) ;
- }
-
- void edit4_caretcreate( G4EDIT *ea )
- {
- DestroyCaret() ;
-
- if ( ea->ca.gw.cw->TypeOver == 1 )
- CreateCaret( ea->ca.gw.hWindow, 1, 1, w4char_height( ea->ca.ew ) ) ;
- else
- CreateCaret( ea->ca.gw.hWindow, 0, 1, w4char_height( ea->ca.ew ) ) ;
- }
-
- int edit4_datecheck( G4EDIT *ea ) /* return 0, okay, -1 BAD */
- {
- char day[9];
- long abc ;
- int mon, d, yr, rc = 0 ;
-
- day[8] = 0 ; memset( day, ' ', 8 ) ;
- a4init( day, ea->Buffer, ea->Pict );
- if ( strcmp( day, " " ) == 0 ) return 0 ; /* blank date - okay */
-
- abc = a4long( day ) ;
- a4assign( day, abc ) ;
-
- mon = a4month( day ) ;
- if ( (mon < 1) || (mon > 12) ) rc = -1 ;
-
- d = a4day( day ) ;
- if ( (d < 1) || (d > 31) ) rc = -1 ;
-
- yr = a4year( day ) ;
- if ( (yr < 1) ) rc = -1 ;
-
- ea->ca.gw.cw->bad_date = ( rc != 0 ) ? 1 : 0 ;
-
- return rc ;
- }
-
- /*****
- Here's how the changing of focus is handled among the controls :
-
- NB - Non Button Control
- PUSH - Either a BS_PUSHBUTTON or a BS_DEFPUSHBUTTON
- NPUSH - A button that is not a PUSH (ie. a CHECKBOX or RADIO)
-
- different cases action
- ------------------ ------
- 1. NB -> NB nothing
- 2. NB -> PUSH turn off default, ca = BS_DEF
- 3. NB -> NPUSH nothing
- 4. PUSH -> PUSH old = BS_PUSH, ca = BS_DEF
- 5. PUSH -> NB old = BS_PUSH, turn on default
- 6. PUSH -> NPUSH old = BS_PUSH, turn on default
- 7. NPUSH -> NPUSH nothing
- 8. NPUSH -> NB nothing
- 9. NPUSH -> PUSH turn off default, ca = BS_DEF
- *****/
-
- G4CONTROL *edit4_new( L4LIST *list, void *item, int dir )
- {
- G4BUTTON *old_but, *ca_but ;
- G4CONTROL *old, *ca1 ;
- G4CONTROL *ca = (G4CONTROL *) item ;
-
- if ( ca->area_type == c4list )
- {
- G4LIST *list = (G4LIST *)ca->area ;
- if ( list->combo != 0 )
- {
- G4COMBO *combo = (G4COMBO *) list->combo ;
- ca = &(combo->edit.ca) ;
- }
- }
- old = ca ;
-
- if ( dir > 0 )
- {
- do {
- if (ca == (G4CONTROL *) l4last( list))
- ca = 0 ;
- ca = (G4CONTROL *) l4next( list, ca ) ;
- } while( ca->area_type == c4display ) ;
- }
- else
- {
- do {
- if (ca == (G4CONTROL *) l4first( list))
- ca = 0 ;
- ca = (G4CONTROL *) l4prev( list, ca ) ;
- } while( ca->area_type == c4display ) ;
- }
-
- if ( old->area_type == c4edit )
- {
- G4COMBO *combo = (G4COMBO *) ((G4EDIT *)old->area)->combo ;
- if ( combo != 0 )
- {
- combo->is_down = 0 ;
- combo4_process_message( combo, WM_SYSKEYDOWN, VK_UP, 0x20000000L ) ;
- }
- }
-
- if ( ca->area_type == c4button )
- ca_but = (G4BUTTON *) ca->area ;
-
- if ( old->area_type != c4button )
- {
- if ( ca->area_type != c4button )
- return ca ;
- if ( (ca_but->ButtonType != BS_PUSHBUTTON) && (ca_but->ButtonType != BS_DEFPUSHBUTTON) )
- return ca ;
-
- edit4_default( list, 0 ) ;
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_DEFPUSHBUTTON, 1L ) ;
- return ca ;
- }
-
- old_but = (G4BUTTON *) old->area ;
- if ( (old_but->ButtonType != BS_PUSHBUTTON) && (old_but->ButtonType != BS_DEFPUSHBUTTON) )
- {
- if ( ca->area_type != c4button )
- return ca ;
- if ( (ca_but->ButtonType != BS_PUSHBUTTON) && (ca_but->ButtonType != BS_DEFPUSHBUTTON) )
- return ca ;
-
- edit4_default( list, 0 ) ;
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_DEFPUSHBUTTON, 1L ) ;
- return ca ;
- }
-
- if ( ca->area_type != c4button )
- {
- SendMessage( old->gw.hWindow, BM_SETSTYLE, (WORD) BS_PUSHBUTTON, 1L ) ;
- edit4_default( list, 1 ) ;
- return ca ;
- }
-
- if ( (ca_but->ButtonType != BS_PUSHBUTTON) && ( ca_but->ButtonType != BS_DEFPUSHBUTTON) )
- {
- SendMessage( old->gw.hWindow, BM_SETSTYLE, (WORD) BS_PUSHBUTTON, 1L ) ;
- edit4_default( list, 1 ) ;
- return ca ;
- }
-
- SendMessage( old->gw.hWindow, BM_SETSTYLE, (WORD) BS_PUSHBUTTON, 1L ) ;
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_DEFPUSHBUTTON, 1L ) ;
- return ca ;
- }
-
- void edit4_default( L4LIST *list, int on_off )
- {
- G4CONTROL *ca ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( list, ca ) ; )
- if ( ca->is_default == 1 )
- {
- if ( on_off )
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_DEFPUSHBUTTON, 1L ) ;
- else
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_PUSHBUTTON, 1L ) ;
- break ;
- }
- }
-