home *** CD-ROM | disk | FTP | other *** search
- /* w4entry.c Edit Window Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- int entry4_process_message( W4ENTRY *ew, WORD message, WORD wParam, LONG lParam )
- {
- HWND hwnd ;
- G4CONTROL *ca ;
- LPDRAWITEMSTRUCT draw ;
-
- switch( message )
- {
- case WM_COMMAND:
- if ( ew->gw.cw->cb.error_code < 0 ) return 1 ;
- if ( HIWORD( lParam ) == LBN_SELCHANGE )
- {
- G4LIST *list = g4lookup_list( ew, wParam ) ;
- G4COMBO *combo ;
- if ( list == 0 ) return 1 ;
- combo = (G4COMBO *)list->combo ;
- if ( combo != 0 )
- combo4_setselection( combo->edit.ca.gw.hWindow, ew, 0 ) ;
- else
- list4_setselection( LOWORD( lParam ), ew ) ;
- break ;
- }
- break ;
-
- case WM_KILLFOCUS:
- DestroyCaret();
- break ;
-
- case WM_SETFOCUS:
- DestroyCaret();
- case WM_USER:
- if ( ew->gw.cw->cb.error_code < 0 ) return 1 ;
- hwnd = GetFocus() ;
- if ( hwnd == ew->gw.hWindow )
- {
- if ( ew->ControlList.selected == 0 )
- {
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- if ( ca->gw.Style & WS_TABSTOP )
- {
- #ifdef S4DEBUG /* some types don't get the focus */
- switch( ca->area_type )
- {
- case c4button:
- if ( LOBYTE( LOWORD( ca->gw.Style )) != BS_GROUPBOX )
- break ;
- case c4display:
- e4error( w4cb( ew ), e4result, E4_RESULT_TA2, (char *) 0 ) ;
- return 1 ;
- }
- #endif
-
- SetFocus( ca->gw.hWindow ) ;
- if ( ca->area_type == c4button )
- {
- G4BUTTON *ca_but = (G4BUTTON *) ca->area ;
- if ( (ca_but->ButtonType == BS_PUSHBUTTON) ||
- (ca_but->ButtonType == BS_DEFPUSHBUTTON) )
- {
- edit4_default( &ew->ControlList, 0 ) ;
- SendMessage( ca->gw.hWindow, BM_SETSTYLE, (WORD) BS_DEFPUSHBUTTON, 1L ) ;
- }
- }
- ew->ControlList.selected = (void *) ca ;
- return 1 ;
- }
- #ifdef S4DEBUG
- e4error( w4cb( ew ), e4result, E4_RESULT_TA1, (char *) 0 ) ;
- return 1 ;
- #endif
- }
- else
- SetFocus( g4handle( (G4CONTROL *) ew->ControlList.selected )) ;
- }
- break ;
-
- case WM_CLOSE:
- ew->gw.IsDestroyed = 1 ;
- ew->isReady = 0 ;
- if ( ew->gw.hEnable != 0 )
- {
- EnableWindow( ew->gw.hEnable, 1 ) ;
- SetActiveWindow( ew->gw.hEnable ) ;
- }
- break ;
-
- case WM_SYSCOMMAND:
- if ( ew->gw.cw->cb.error_code < 0 ) return 1 ;
- if ( wParam == SC_CLOSE )
- {
- ca = (G4CONTROL *) l4first( &ew->ControlList ) ;
- if ( ca != 0 )
- control4_process_message( ca, WM_CHAR, VK_ESCAPE, lParam ) ;
- }
- break ;
-
- case WM_NCDESTROY:
- if ( ew->release == 1 )
- entry4_free( ew ) ;
- break ;
-
- case WM_PAINT:
- if ( ew->gw.cw->cb.error_code < 0 )
- {
- SendMessage( ew->gw.hWindow, WM_CLOSE, 0, 0 ) ;
- return 1 ;
- }
- if ( ew->isReady == 0 )
- {
- if ( ew->bw != 0 )
- {
- if ( d4reccount( ew->bw->pData ) < 1 )
- {
- d4append_blank( ew->bw->pData ) ;
- d4top( ew->bw->pData ) ;
- ew->bw->CurRec = 1 ;
- }
- }
- list4_setselect( ew ) ;
- entry4_resizeedits( ew ) ;
- entry4_controlsrefresh( ew ) ;
- PostMessage( ew->gw.hWindow, WM_USER, 0, 0 ) ;
- if ( ew->bw != 0 )
- {
- browse4_area_create( ew ) ;
- browse4_movecontrols( ew->bw, 0 ) ;
- browse4_scrollset( ew->bw ) ;
- }
- ew->isReady = 1 ;
- }
- break ;
-
- case WM_DRAWITEM:
- draw = (LPDRAWITEMSTRUCT) lParam ;
- if ( draw->itemAction == ODA_DRAWENTIRE )
- combo4_buttondraw( draw, ew );
- break ;
- }
- return 0 ;
- }
-
- void entry4_construct( W4ENTRY *ew )
- {
- ew->release = 1 ;
- ew->return_code = -1 ;
- ew->Pos = 0 ;
- ew->bw = 0 ;
- ew->max_id = 2000 ;
- ew->isReady = 0 ;
- ew->hasMessageLoop = 0 ;
- }
-
- int entry4_controlsrefresh( W4ENTRY *ew )
- {
- G4CONTROL *ca ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- {
- if ( ca->area_type == c4edit )
- if ( ((G4EDIT *)ca->area)->pResult != 0 )
- g4edit_refresh( (G4EDIT *)(ca->area) ) ;
- }
- return 0 ;
- }
-
- int entry4_controlssave( W4ENTRY *ew )
- {
- G4CONTROL *ca ;
- int rc = 0 ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- {
- if ( ca->area_type == c4edit )
- if ( ((G4EDIT *)(ca->area))->pResult != 0 )
- {
- if ( g4edit_save( (G4EDIT *)(ca->area) ) != 0 )
- rc = -1 ;
- }
- if ( ca->area_type == c4list )
- if ( ((G4LIST *)(ca->area))->pResult != 0 )
- g4list_save( (G4LIST *)(ca->area) ) ;
- if ( ca->area_type == c4button )
- g4button_save( (G4BUTTON *)(ca->area) ) ;
- }
- return rc ;
- }
-
- G4EDIT *entry4_get_create( W4ENTRY *ew, int x, int y, char *str,
- int type_get, int width, int dec, int id )
- {
- G4EDIT *ea ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4numeric()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return 0 ;
-
- ea = edit4_construct( ew ) ;
- if ( ea == 0 ) return 0 ;
- if ( edit4_make2( ew, ea, x, y, str, type_get, width, dec, id ) < 0 )
- {
- if ( ea->Pict != 0 ) u4free( ea->Pict ) ;
- return 0 ;
- }
- l4add( &ew->ControlList, (void *) &ea->ca ) ;
- return ea ;
- }
-
- G4EDIT *S4FUNCTION g4text( W4ENTRY *ew, int x, int y, char *ptr, unsigned ptr_len )
- {
- return entry4_get_create( ew, x, y, ptr, t4str, ptr_len, 0, -1 ) ;
- }
-
- G4EDIT *S4FUNCTION g4date( W4ENTRY *ew, int x, int y, char *dt )
- {
- return entry4_get_create( ew, x, y, dt, t4date_str, 8, 0, -1 ) ;
- }
-
- G4EDIT *S4FUNCTION g4numeric( W4ENTRY *ew, int x, int y, char *str, int width, int dec )
- {
- G4EDIT *ea ;
- char *pict ;
- double doub ;
- c4atod2( str, width, &doub ) ;
- c4dtoa45( doub, str, width, dec ) ;
-
- pict = (char *) u4alloc( width+1 ) ;
- if ( pict == 0 )
- {
- e4error( w4cb( ew ), e4memory, "g4numeric()", (void *) 0 ) ;
- return 0 ;
- }
- memset( pict, '#', width ) ;
- memset( pict+width-dec, '9', dec ) ;
- pict[width] = 0 ;
- if ( dec > 0 )
- pict[width-dec-1] = '.' ;
- ea = entry4_get_create( ew, x, y, str, 'N', width, dec, -1 ) ;
- g4picture( ea, pict ) ;
- u4free( pict ) ;
-
- ea->EntryType = t4num_str ;
-
- g4set_style( ea, g4get_style( ea ) | ES_RIGHT ) ;
-
- ea->data_field = 0 ;
- ea->pResult = str ;
- ea->pResultLen = width ;
- ea->Decimals = dec ;
-
- return ea ;
- }
-
- G4EDIT *S4FUNCTION g4logical( W4ENTRY *ew, int x, int y, char *str )
- {
- return entry4_get_create( ew, x, y, str, t4log, 1, 0, -1 ) ;
- }
-
- void entry4_init( W4ENTRY *ew, C4WINDOWS *cw, char *class_name, char *caption, DWORD style,
- int x, int y, int width, int height, HWND parent, HMENU menu )
- {
- memset( &ew->ControlList, 0, sizeof( ew->ControlList )) ;
- entry4_construct( ew ) ;
- general4_init( &ew->gw, cw, class_name, caption, style, x, y, width, height, parent, menu ) ;
- }
-
- W4ENTRY *S4FUNCTION w4create( C4WINDOWS *cw, char *caption, DWORD style, int x, int y, int width,
- int height, HWND parent, HMENU menu )
- {
- W4ENTRY *ew = (W4ENTRY *) u4alloc( sizeof( W4ENTRY )) ;
- #ifdef S4DEBUG
- if ( ew == 0 )
- {
- e4error( &cw->cb, e4parm, "w4create()", E4_PARM_ZER, (void *) 0 ) ;
- return 0 ;
- }
- #endif
-
- if ( style == 0 )
- style = WS_POPUPWINDOW | WS_CAPTION ;
-
- entry4_init( ew, cw, "W4ENTRY", caption, style, x, y, width, height, parent, menu ) ;
- SetWindowLong( ew->gw.hWindow, 0, (LONG) ew ) ;
- return ew ;
- }
-
- G4CONTROL *S4FUNCTION g4lookup( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4lookup()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- {
- if ( ca->area_type == c4edit )
- {
- G4COMBO *cba = (G4COMBO *) ((G4EDIT *)ca->area)->combo ;
- if ( cba != 0 )
- {
- if ( cba->list != 0 )
- if ( cba->list->ca.gw.Id == id )
- return &(cba->list->ca) ;
- if ( cba->button != 0 )
- if ( cba->button->ca.gw.Id == id )
- return &(cba->button->ca) ;
- }
- }
- if ( ca->gw.Id == id )
- return ca ;
- }
- #ifdef S4DEBUG
- e4error( w4cb( ew ), e4parm, E4_RESULT_ID, (char *) 0 ) ;
- #endif
- return (G4CONTROL *) 0 ;
- }
-
- G4BUTTON *S4FUNCTION g4lookup_button( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca = g4lookup( ew, id ) ;
- if ( ca == 0 ) return 0 ;
-
- #ifdef S4DEBUG
- if ( ca->area_type != c4button )
- e4error( w4cb( ew ), e4parm, E4_RESULT_IDB, (char *) 0 ) ;
- #endif
- return (G4BUTTON *) ca->area ;
- }
-
- G4DISPLAY *S4FUNCTION g4lookup_display( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca = g4lookup( ew, id ) ;
- if ( ca == 0 ) return 0 ;
-
- #ifdef S4DEBUG
- if ( ca->area_type != c4display )
- e4error( w4cb( ew ), e4parm, E4_RESULT_IDD, (char *) 0 ) ;
- #endif
- return (G4DISPLAY *) ca->area ;
- }
-
- G4LIST *S4FUNCTION g4lookup_list( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca = g4lookup( ew, id ) ;
- if ( ca == 0 ) return 0 ;
-
- #ifdef S4DEBUG
- if ( ca->area_type != c4list )
- e4error( w4cb( ew ), e4parm, E4_RESULT_IDL, (char *) 0 ) ;
- #endif
- return (G4LIST *) ca->area ;
- }
-
- G4EDIT *S4FUNCTION g4lookup_edit( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca = g4lookup( ew, id ) ;
- if ( ca == 0 ) return 0 ;
-
- #ifdef S4DEBUG
- if ( ca->area_type != c4edit )
- e4error( w4cb( ew ), e4parm, E4_RESULT_IDT, (char *) 0 ) ;
- #endif
- return (G4EDIT *) ca->area ;
- }
-
- G4COMBO *S4FUNCTION g4lookup_combo( W4ENTRY *ew, int id )
- {
- G4CONTROL *ca = g4lookup( ew, id ) ;
- G4EDIT *ea ;
-
- if ( ca == 0 ) return 0 ;
- ea = (G4EDIT *) ca->area ;
-
- #ifdef S4DEBUG
- if ( ea->combo == 0 )
- e4error( w4cb( ew ), e4parm, E4_RESULT_IDC, (char *) 0 ) ;
- #endif
- return (G4COMBO *) ea->combo ;
- }
-
- int S4FUNCTION g4read( W4ENTRY *ew, HWND hDisableWindow )
- {
- int return_code ;
- G4CONTROL *ca ;
-
- if ( ew->gw.cw->cb.error_code < 0 ) return -1 ;
-
- #ifdef S4DEBUG
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- {
- G4LIST *list = 0 ;
- int len, count, i ;
-
- switch( ca->area_type )
- {
- case c4display:
- if ( ((G4DISPLAY *)ca->area)->text_len == 0 )
- return e4error( w4cb( ew ), e4result, E4_RESULT_G4D, (char *) 0 ) ;
- break ;
-
- case c4edit:
- if ( ((G4EDIT *)ca->area)->pResultLen == 0 )
- return e4error( w4cb( ew ), e4result, E4_RESULT_G4E, (char *) 0 ) ;
- break ;
-
- case c4list:
- if ( ((G4LIST *)ca->area)->pResultLen == 0 )
- return e4error( w4cb( ew ), e4result, E4_RESULT_G4L, (char *) 0 ) ;
- break ;
-
- default:
- break ;
- }
- /* not currently working ...
- if ( ca->area_type == c4edit )
- {
- G4EDIT *ea = (G4EDIT *) ca->area ;
- if ( ea->combo != 0 )
- list = ea->combo->list ;
- }
- if ( ca->area_type == c4list )
- list = (G4LIST *) ca->area ;
- if ( list != 0 )
- {
- count = SendMessage( g4handle( list ), LB_GETCOUNT, 0, 0 ) ;
- for ( i=0 ; i<count ; i++ )
- {
- len = SendMessage( g4handle( list ), LB_GETTEXTLEN, i, 0 ) ;
- if ( len > list->pResultLen )
- return e4error( w4cb( ew ), e4result, E4_RESULT_BUF, (char *) 0 ) ;
- }
- }
- */
- }
- #endif
-
- SetActiveWindow( ew->gw.hWindow ) ;
- ShowWindow( ew->gw.hWindow,SW_SHOWNORMAL ) ;
- UpdateWindow( ew->gw.hWindow ) ;
-
- ew->hasMessageLoop = 1 ;
- general4_read( &ew->gw, hDisableWindow ) ;
- return_code = ew->return_code ;
-
- ew->gw.IsDestroyed = 0 ;
- g4release( ew, ew->release ) ;
-
- return return_code ;
- }
-
- int entry4_readstring( char* str, H4SEQ_READ *seq, int nOption )
- {
- int i ;
- char ch[2] ; ch[0] = ch[1] = 0 ;
-
- h4seq_read( seq, ch, 1 ) ;
-
- if ( (unsigned)(ch[0]) >= 0x80 )
- return (int) (unsigned char) ch[0] ;
-
- for (i=0 ; ch[0] != 0; i++, h4seq_read( seq, ch, 1 ) )
- str[i] = ch[0] ;
-
- str[i] = 0 ;
- return 0 ;
- }
-
- W4ENTRY *S4FUNCTION w4create_dialog( C4WINDOWS *cw, HWND hPar, char *DlgName )
- {
- return (W4ENTRY *) entry4_init_dialog( cw, hPar, DlgName, c4entrywin, 0 ) ;
- }
-
- void *entry4_init_dialog( C4WINDOWS *cw, HWND hPar, char *DlgName,
- int win_type, int do_browse )
- {
- H4FILE res ;
- HANDLE hDlg ;
- H4SEQ_READ seq_read ;
- C4DIALOGINFO info ;
- char buf[1024], menu_name[256], class_name[256], caption[256] ;
- HMENU hMenu = 0 ;
- long base_units, offset ;
- W4ENTRY *ew ;
- int i, low, high, extra_y = 0, extra_x = 0 ;
- char *name = { "Dialog Resource" } ;
-
- res.code_base = &cw->cb ;
- res.hand = -1 ;
- res.is_temp = 0 ;
-
- hDlg = FindResource( w4hInst( cw ), DlgName, RT_DIALOG ) ;
- if ( hDlg == 0 )
- {
- e4error( &cw->cb, e4result, E4_RESULT_RES, (char *) 0 ) ;
- return 0 ;
- }
- res.hand = AccessResource( w4hInst( cw ), hDlg ) ;
- res.name = name ;
-
- offset = _llseek( res.hand, 0L, 1 ) ;
-
- h4seq_read_init( &seq_read, &res, offset, buf, sizeof(buf) ) ;
- h4seq_read( &seq_read, &info, sizeof(info) ) ;
- if ( cw->cb.error_code < 0 ) return 0 ;
-
- menu_name[255] = class_name[255] = caption[255] = 0 ;
-
- entry4_readstring( menu_name, &seq_read, 3 ) ;
- entry4_readstring( class_name, &seq_read, 0 ) ;
- entry4_readstring( caption, &seq_read, 0 ) ;
-
- if ( lstrlen(menu_name) > 0 )
- hMenu = LoadMenu( w4hInst( cw ), menu_name ) ;
-
- if ( hMenu == 0 )
- if ( win_type == c4browsewin )
- extra_y += GetSystemMetrics( SM_CYMENU ) ;
-
- if ( (char *) caption != 0 )
- extra_y += GetSystemMetrics( SM_CYCAPTION ) ;
-
- /* depending on the frame used, add a certain width/height, these include :
- WS_THICKFRAME, WS_DLGFRAME, sizeable and nonsizeable frames ...
- For now, assume a sizeable frame ... */
-
- extra_y += 2 * GetSystemMetrics( SM_CYFRAME ) ;
- extra_x += 2 * GetSystemMetrics( SM_CXFRAME ) ;
-
- /* note that if the menu line is multiple line, then the user defined window
- may be obstructed, similarly, the horizontal and vertical scroll bars are
- made within the window, so the user should take that into account when
- sizing the window in the resource editor. */
-
- base_units = GetDialogBaseUnits() ;
- low = LOWORD( base_units ) ;
- high = HIWORD( base_units ) ;
-
- if ( win_type == c4entrywin )
- ew = w4create( cw, caption, info.Style,
- (info.X * low ) / 4,
- (info.Y * high) / 8,
- ((info.CX * low ) / 4)+extra_x,
- ((info.CY * high) / 8)+extra_y, hPar, hMenu ) ;
- else
- {
- ew = b4create( cw, caption, info.Style,
- (info.X * low ) / 4,
- (info.Y * high) / 8,
- ((info.CX * low ) / 4)+extra_x,
- ((info.CY * high) / 8)+extra_y, hPar, 0, do_browse ) ;
- }
-
- if ( ew == 0 ) return 0 ;
-
- if ( DS_SETFONT & info.Style ) /* doesn't currently work */
- {
- short point_size ;
- char type_face[256] ;
-
- h4seq_read( &seq_read, &point_size, sizeof(point_size) ) ;
- type_face[255] = 0 ;
- entry4_readstring( type_face, &seq_read, 0 ) ;
- }
-
- for( i = 0; i < (int) info.ItemCount; i++)
- {
- int iClass ;
- C4CONTROLITEM control ;
- char sClass[256], text[256], more_info[256] ;
- G4COMBO *cba = 0 ;
-
- sClass[255] = text[255] = more_info[255] = 0 ;
-
- h4seq_read( &seq_read, &control, sizeof(control) ) ;
- iClass = entry4_readstring( sClass, &seq_read, 1 ) ;
- entry4_readstring( text, &seq_read, 3 ) ;
- entry4_readstring( more_info, &seq_read, 0 ) ;
-
- if ( control.Id > ew->max_id )
- ew->max_id = control.Id + 1 ;
-
- switch ( iClass )
- {
- case 0x80: /* Button */
- button4_create( ew, &control, text, low, high ) ;
- break ;
-
- case 0x81: /* Edit */
- edit4_create( ew, &control, text, low, high ) ;
- break ;
-
- case 0x82: /* Static */
- display4_create( ew, &control, text, lstrlen(text), low, high ) ;
- break ;
-
- case 0x83: /* ListBox */
- list4_create( ew, &control, text, low, high ) ;
- break ;
-
- case 0x85: /* ComboBox */
- cba = combo4_create( ew, &control, text, lstrlen(text), low, high ) ;
-
- if ( CBS_DROPDOWNLIST == (control.Style & CBS_DROPDOWNLIST) )
- g4modify( &cba->edit, 0 ) ;
- else
- g4modify( &cba->edit, 1 ) ;
-
- if ( CBS_SIMPLE == (control.Style & CBS_SIMPLE) )
- if ( control.Style+1 & 0x0002 )
- g4combo_simple( cba ) ;
-
- break ;
- }
- }
- _lclose( res.hand ) ;
- res.hand = -1 ;
-
- if ( win_type == c4entrywin )
- return ew ;
- else
- return ew->bw ;
- }
-
- int S4FUNCTION g4width( G4EDIT *ea, int n_pixels )
- {
- #ifdef S4DEBUG
- if ( ea == 0 )
- e4severe( e4parm, "g4width()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ea->ca.gw.cw->cb.error_code < 0 ) return -1 ;
-
- ea->width = n_pixels ;
- return ea->width ;
- }
-
- int entry4_resizeedits( W4ENTRY *ew )
- {
- int width, height_pix ;
- G4CONTROL *ca ;
- TEXTMETRIC tm ;
- G4EDIT *ea ;
- HDC hDC ;
-
- for ( ca = 0 ; ca = (G4CONTROL *) l4next( &ew->ControlList, ca ) ; )
- if ( ca->area_type == c4edit )
- {
- ea = (G4EDIT *)(ca->area) ;
- hDC = w4get_dc( w4cb( ew ), ea->ca.gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- w4get_metrics( hDC, &tm ) ;
-
- if ( ea->width > 0 )
- width = ea->width ;
- else
- {
- if ( ea->Pict == 0 )
- width = ea->pResultLen ;
- else
- width = ea->pResultLen + edit4_nonpictchars( ea->Pict ) ;
- width = width * ( 1+tm.tmAveCharWidth ) ;
- }
-
- if ( width <= tm.tmMaxCharWidth )
- ea->width = width = tm.tmMaxCharWidth + ea->Margin ;
-
- height_pix = tm.tmHeight + tm.tmInternalLeading ;
-
- if ( w4release_dc( w4cb( ew ), ea->ca.gw.hWindow, hDC ) == 0 )
- return -1 ;
-
- MoveWindow( ea->ca.gw.hWindow, ea->x, ea->y, width, height_pix, 0 ) ;
- }
- return 0 ;
- }
-
- void S4FUNCTION g4set_buffer( G4EDIT *ea, char *buf, unsigned buf_len )
- {
- #ifdef S4DEBUG
- if ( ea == 0 )
- e4severe( e4parm, "g4set_buffer()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ea->ca.gw.cw->cb.error_code < 0 ) return ;
-
- ea->pResult = buf ;
- ea->pResultLen = buf_len ;
- ea->data_field = 0 ;
- }
-
- int S4FUNCTION g4set_field( G4EDIT *ea, F4FIELD *fld_ptr )
- {
- int type_get ;
-
- #ifdef S4DEBUG
- if ( (ea == 0) || (fld_ptr == 0) )
- e4severe( e4parm, "g4set_field()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ea->ca.gw.cw->cb.error_code < 0 ) return -1 ;
-
- ea->data_field = fld_ptr ;
- ea->pResult = f4ptr( fld_ptr ) ;
- ea->pResultLen = f4len( fld_ptr ) ;
- ea->Decimals = f4decimals( fld_ptr ) ;
-
- switch( f4type( fld_ptr ) )
- {
- case 'C':
- case 'M':
- type_get = t4str ;
- break ;
-
- case 'D':
- type_get = t4date_str ;
- break ;
-
- case 'L':
- type_get = t4log ;
- break ;
-
- case 'N':
- case 'F':
- type_get = t4num_str ;
- g4set_style( ea, g4get_style( ea ) | ES_RIGHT ) ;
- break ;
- }
- return edit4_init( ea, ea->x, ea->y, ea->pResult, type_get, ea->pResultLen,
- ea->Decimals ) ;
- }
-
- int S4FUNCTION g4field_id( W4ENTRY *ew, int id, F4FIELD *fld )
- {
- G4EDIT *ea;
- int type_get ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4field_id()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return -1 ;
-
- ea = g4lookup_edit( ew, id ) ;
- return g4set_field( ea, fld ) ;
- }
-
- G4EDIT *S4FUNCTION g4field( W4ENTRY *ew, int x, int y, F4FIELD *fld )
- {
- G4EDIT *ea ;
- int type_get ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4field()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return 0 ;
-
- switch( f4type( fld ) )
- {
- case 'C':
- case 'M':
- type_get = t4str ;
- break ;
-
- case 'D':
- type_get = t4date_str ;
- break ;
-
- case 'L':
- type_get = t4log ;
- break ;
-
- case 'N':
- case 'F':
- type_get = t4num_str ;
- break ;
- }
-
- ea = entry4_get_create( ew, x, y, f4ptr( fld ), type_get,
- f4len( fld ), f4decimals( fld ), -1 ) ;
- g4set_field( ea, fld ) ;
- return ea ;
- }
-
- void S4FUNCTION g4upper( G4EDIT *ea )
- {
- #ifdef S4DEBUG
- if ( ea == 0 )
- e4severe( e4parm, "g4upper()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- ea->isUpper = 1 ;
- }
-
- int S4FUNCTION w4char_width( W4ENTRY *ew )
- {
- int width ;
- TEXTMETRIC tm ;
- HDC hDC ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "w4char_width()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return -1 ;
-
- hDC = w4get_dc( w4cb( ew ), ew->gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- w4get_metrics( hDC, &tm ) ;
- width = tm.tmAveCharWidth ;
-
- if ( w4release_dc( w4cb( ew ), ew->gw.hWindow, hDC ) == 0 ) return -1 ;
-
- return width ;
- }
-
- int S4FUNCTION w4char_height( W4ENTRY *ew )
- {
- int height ;
- TEXTMETRIC tm ;
- HDC hDC ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "w4char_height()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return -1 ;
-
- hDC = w4get_dc( w4cb( ew ), ew->gw.hWindow ) ;
- if ( hDC == 0 ) return -1 ;
-
- w4get_metrics( hDC, &tm ) ;
- height = tm.tmHeight + tm.tmExternalLeading ;
-
- if ( w4release_dc( w4cb( ew ), ew->gw.hWindow, hDC ) == 0 ) return -1 ;
-
- return height ;
- }
-
- int entry4_nextid( W4ENTRY *ew )
- {
- ew->max_id++ ;
- return ew->max_id-1 ;
- }
-
- void entry4_free( W4ENTRY *ew )
- {
- B4AREA *ba ;
- G4CONTROL *ca ;
- int n_links ;
-
- for ( n_links = (&ew->ControlList)->n_link ; n_links > 0 ; n_links-- )
- {
- ca = (G4CONTROL *) l4pop( &ew->ControlList ) ;
-
- switch ( ca->area_type )
- {
- case c4edit:
- if ( ((G4EDIT *) ca->area)->combo != 0 )
- combo4_free( (G4COMBO *) ((G4EDIT *) ca->area)->combo ) ;
- else
- edit4_free( (G4EDIT *) ca->area ) ;
- break ;
-
- case c4list:
- list4_free( (G4LIST *) ca->area ) ;
- break ;
-
- case c4button:
- button4_free( (G4BUTTON *) ca->area ) ;
- break ;
- }
- }
- if ( ew->bw != 0 )
- {
- for ( n_links = (&ew->bw->BrowseList)->n_link ; n_links > 0 ; n_links-- )
- {
- ba = (B4AREA *) l4pop( &ew->bw->BrowseList ) ;
- u4free( ba ) ;
- }
- #ifdef __DLL__
- if ( ! u4ptr_equal( (void *) 0, (void *) ew->bw->del ) )
- {
- FreeProcInstance( (FARPROC) ew->bw->del ) ;
- ew->bw->del = 0 ;
- }
- if ( ! u4ptr_equal( (void *) 0, (void *) ew->bw->record ) )
- {
- FreeProcInstance( (FARPROC) ew->bw->record ) ;
- ew->bw->record = 0 ;
- }
- #endif
- }
- if ( ew->hasMessageLoop == 0 )
- {
- if ( ew->bw != 0 )
- u4free( ew->bw ) ;
- else
- u4free( ew ) ;
- }
- else
- ew->hasMessageLoop = 0 ;
- }
-
- void edit4_free( G4EDIT *ea )
- {
- if ( ea->Pict != 0 ) u4free( ea->Pict ) ;
- if ( ea->Buffer != 0 ) u4free( ea->Buffer ) ;
- if ( ea->BufferPrev != 0 ) u4free( ea->BufferPrev ) ;
-
- #ifdef __DLL__
- if ( ! u4ptr_equal( (void *) 0, (void *) ea->valid ) )
- FreeProcInstance( (FARPROC) ea->valid ) ;
- #endif
-
- u4free( ea ) ;
- }
-
- void list4_free( G4LIST *la )
- {
- if ( la->select != 0 ) u4free( la->select ) ;
- if ( la->pStr != 0 ) u4free( la->pStr ) ;
-
- u4free( la ) ;
- }
-
- void button4_free( G4BUTTON *bna )
- {
- if ( bna != 0 )
- {
- #ifdef __DLL__
- if ( bna->internal == 0 )
- if ( ! u4ptr_equal( (void *) 0, (void *) bna->routine ) )
- FreeProcInstance( (FARPROC) bna->routine ) ;
- #endif
- u4free( bna ) ;
- }
- }
-
- void combo4_free( G4COMBO *cba )
- {
- list4_free( cba->list ) ;
- button4_free( cba->button ) ;
-
- u4free( cba ) ;
- }
-
- HWND S4FUNCTION w4handle( W4ENTRY *entry )
- {
- #ifdef S4DEBUG
- if ( entry == 0 )
- e4severe( e4parm, "w4handle()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- return entry->gw.hWindow ;
- }
-
- HWND S4FUNCTION g4handle( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- #ifdef S4DEBUG
- if ( control == 0 )
- e4severe( e4parm, "g4handle()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return control->gw.hWindow ;
- }
-
- int S4FUNCTION g4id( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- #ifdef S4DEBUG
- if ( control == 0 )
- e4severe( e4parm, "g4id()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return control->gw.Id ;
- }
-
- W4ENTRY *S4FUNCTION w4entry( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- #ifdef S4DEBUG
- if ( control == 0 )
- e4severe( e4parm, "w4entry()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return control->ew ;
- }
-
- void S4FUNCTION g4modify( G4EDIT *edit, int can_modify )
- {
- #ifdef S4DEBUG
- if ( edit == 0 )
- e4severe( e4parm, "g4modify()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- edit->isModify = can_modify ;
- }
-
- HANDLE S4FUNCTION w4hInst( void *ptr )
- {
- C4CODE *cb = (C4CODE *) ptr ;
- #ifdef S4DEBUG
- if ( cb == 0 )
- e4severe( e4parm, "w4hInst()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return cb->hInst ;
- }
-
- HANDLE S4FUNCTION g4hInst( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- #ifdef S4DEBUG
- if ( control == 0 )
- e4severe( e4parm, "g4hInst()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return control->gw.cw->cb.hInst ;
- }
-
- C4CODE *S4FUNCTION w4cb( W4ENTRY *ew )
- {
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "w4cb()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return &ew->gw.cw->cb ;
- }
-
- C4CODE *S4FUNCTION g4cb( void *control_pointer )
- {
- G4CONTROL *control = (G4CONTROL *) control_pointer ;
- #ifdef S4DEBUG
- if ( control == 0 )
- e4severe( e4parm, "g4cb()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
- return &control->gw.cw->cb ;
- }
-
- int S4FUNCTION g4release( W4ENTRY *ew, int do_release )
- {
- ew->release = do_release ;
- if ( do_release )
- {
- DestroyWindow( ew->gw.hWindow ) ;
- entry4_free( ew ) ;
- }
- return 0 ; /* return error if in S4DEBUG ... */
- }
-