home *** CD-ROM | disk | FTP | other *** search
- /* g4display.c Static Area Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- G4DISPLAY *display4_construct( W4ENTRY *ew )
- {
- G4DISPLAY *sa = (G4DISPLAY *) u4alloc( sizeof( G4DISPLAY )) ;
- if ( sa == 0 )
- {
- e4error( w4cb( ew ), e4memory, (char *) 0 ) ;
- return 0 ;
- }
- control4_construct( &sa->ca, ew ) ;
-
- sa->ca.gw.OldWindowProc = 0 ;
- sa->ca.gw.Id = 0 ;
- sa->ca.hParent = 0 ;
- sa->ca.area_type = c4display ;
- sa->ca.area = (void *) sa ;
-
- sa->text = 0 ;
- sa->text_len = 0 ;
-
- sa->x = -1 ;
- sa->y = -1 ;
- sa->width = -1 ;
-
- return sa ;
- }
-
- G4DISPLAY *S4FUNCTION g4display( W4ENTRY *ew, int x, int y, char *ptr )
- {
- return g4display_len( ew, x, y, ptr, lstrlen( ptr ) ) ;
- }
-
- G4DISPLAY *S4FUNCTION g4display_len( W4ENTRY *ew, int x, int y, char *ptr, int ptr_len )
- {
- TEXTMETRIC tm ;
- C4CONTROLITEM control ;
- HDC hDC ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4display_len()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- hDC = w4get_dc( w4cb( ew ), ew->gw.hWindow ) ;
- if ( hDC == 0 ) return 0 ;
-
- w4get_metrics( hDC, &tm ) ;
-
- control.X = x ;
- control.Y = y ;
- control.CX = LOWORD( GetTextExtent( hDC, ptr, ptr_len ) ) ;
- control.CY = tm.tmHeight + tm.tmInternalLeading ;
- control.Style = 0L ;
- control.Id = entry4_nextid( ew ) ;
-
- if ( w4release_dc( w4cb( ew ), ew->gw.hWindow, hDC ) == 0 ) return 0 ;
-
- return display4_create( ew, &control, ptr, ptr_len, -1, -1 ) ;
- }
-
- G4DISPLAY *display4_create( W4ENTRY *ew, C4CONTROLITEM *control, char *text,
- int text_len, int low, int high )
- {
- int height ;
-
- G4DISPLAY *sa = display4_construct( ew ) ;
- if ( sa == 0 ) return 0 ;
-
- l4add( &ew->ControlList, (void *) &sa->ca ) ;
-
- if ( low < 0 )
- {
- sa->x = control->X ;
- sa->y = control->Y ;
- sa->width = control->CX ;
- height = control->CY ;
- }
- else
- {
- sa->x = (control->X * low ) / 4 ;
- sa->y = (control->Y * high) / 8 ;
- sa->width = (control->CX * low ) / 4 ;
- height = (control->CY * high) / 8 ;
- }
-
- sa->ca.gw.Style = control->Style | WS_VISIBLE | WS_CHILD ;
-
- sa->text = text ;
- sa->text_len = text_len ;
-
- sa->ca.gw.hWindow = w4create_window( "Static", sa->text, sa->ca.gw.Style,
- sa->x, sa->y, sa->width, height,
- w4handle( ew ), control->Id, w4hInst( ew ), 0 ) ;
-
- sa->ca.hParent = ew->gw.hWindow ;
- sa->ca.ew = ew ;
- sa->ca.gw.Id = control->Id ;
- sa->ca.gw.cw = ew->gw.cw ;
-
- SetWindowLong( sa->ca.gw.hWindow, 0, (LONG) sa ) ;
-
- return sa ;
- }
-
- void S4FUNCTION g4display_buffer( G4DISPLAY *sa, char *buf, unsigned buf_len )
- {
- char *temp ;
-
- #ifdef S4DEBUG
- if ( sa == 0 )
- e4severe( e4parm, "g4display_buffer()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- temp = (char *) u4alloc( buf_len+1 ) ;
- if ( temp == 0 ) return ;
- u4ncpy( temp, buf, buf_len+1 ) ;
-
- sa->text = buf ;
- sa->text_len = buf_len ;
-
- SetWindowText( g4handle( (void *) sa ), temp ) ;
- u4free( temp ) ;
- }
-
- int S4FUNCTION g4display_update( G4DISPLAY *sa ) /* 0 good, -x bad */
- {
- RECT rEdit, rParent ;
- LPPOINT point ;
- B4AREA *ba ;
- B4BROWSE *bw ;
- int leftmost = c4pix, rightmost = -c4pix ;
-
- #ifdef S4DEBUG
- if ( sa == 0 )
- e4severe( e4parm, "g4display_update()", E4_PARM_ZER, (void *) 0 ) ;
- #endif
-
- bw = sa->ca.ew->bw ;
-
- if ( bw == 0 )
- #ifdef S4DEBUG
- return e4error( g4cb( sa ), e4parm, "g4display_update()", E4_PARM_ZER, (char *) 0 ) ;
- #else
- return -1 ;
- #endif
-
- if ( sa->ca.gw.cw->cb.error_code < 0 ) return -1 ;
-
- ba = (B4AREA *) u4alloc( sizeof(B4AREA) ) ;
- if ( ba == 0 )
- {
- e4error( g4cb( sa ), e4parm, "g4display_update()", e4memory, (char *) 0 ) ;
- return -1 ;
- }
-
- ba->sa = sa ;
- ba->ea = 0 ;
-
- w4get_rect( sa->ca.gw.hWindow, &rEdit, 1 ) ;
- w4get_rect( bw->entry.gw.hWindow, &rParent, 1 ) ;
-
- point = (LPPOINT) (&rEdit) ;
- ScreenToClient( bw->entry.gw.hWindow, point ) ;
- ScreenToClient( bw->entry.gw.hWindow, point+1 ) ;
-
- ba->LeftPos = rEdit.left ;
- if ( bw->MarginTop < 0 )
- {
- bw->HeightEdit = rEdit.bottom - rEdit.top ;
- bw->PixelsExtra = bw->HeightEdit - bw->Pixels ;
- bw->MarginTop = rEdit.top ;
- }
-
- ba->WidthBrowse = ba->WidthControl = rEdit.right - rEdit.left ;
-
- general4_init( &ba->gw, bw->entry.gw.cw, "B4AREA", 0, WS_CHILD | WS_VISIBLE | WS_TABSTOP,
- 0,0,0,0, bw->entry.gw.hWindow, 0 ) ;
-
- SetWindowLong( ba->gw.hWindow, 0, (LONG) ba ) ;
- browse4_add( bw, ba ) ;
-
- ba->bw = bw ;
-
- MoveWindow( ba->sa->ca.gw.hWindow, ba->LeftPos, bw->MarginTop + bw->PixelsExtra,
- ba->WidthControl, bw->HeightEdit, 1 ) ;
-
- for ( ba=0 ; ba = (B4AREA *) l4next( &bw->BrowseList, ba ) ; )
- {
- if ( ba->ea != 0 )
- w4get_rect( ba->ea->ca.gw.hWindow, &rEdit, 1 ) ;
- else
- w4get_rect( ba->sa->ca.gw.hWindow, &rEdit, 1 ) ;
-
- if ( rEdit.left < leftmost ) leftmost = rEdit.left ;
- if ( rEdit.right > rightmost ) rightmost = rEdit.right ;
- }
- if ( leftmost > 0 ) leftmost = 0 ;
- bw->MaxWidth = rightmost - leftmost ;
-
- browse4_scrollset( bw ) ;
- browse4_resized( bw ) ;
- if ( bw->entry.gw.cw->cb.error_code < 0 ) return -1 ;
- return 0 ;
- }
-