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

  1. /* g4display.c  Static 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. G4DISPLAY *display4_construct( W4ENTRY *ew )
  11. {
  12.    G4DISPLAY *sa = (G4DISPLAY *) u4alloc( sizeof( G4DISPLAY )) ;
  13.    if ( sa == 0 )
  14.    {
  15.       e4error( w4cb( ew ), e4memory, (char *) 0 ) ;
  16.       return 0 ;
  17.    }
  18.    control4_construct( &sa->ca, ew ) ;
  19.  
  20.    sa->ca.gw.OldWindowProc = 0 ;
  21.    sa->ca.gw.Id            = 0 ;
  22.    sa->ca.hParent          = 0 ;
  23.    sa->ca.area_type        = c4display ;
  24.    sa->ca.area             = (void *) sa ;
  25.  
  26.    sa->text     = 0 ;
  27.    sa->text_len = 0 ;
  28.  
  29.    sa->x     = -1 ;
  30.    sa->y     = -1 ;
  31.    sa->width = -1 ;
  32.  
  33.    return sa ;
  34. }
  35.  
  36. G4DISPLAY *S4FUNCTION g4display( W4ENTRY *ew, int x, int y, char *ptr )
  37. {
  38.    return g4display_len( ew, x, y, ptr, lstrlen( ptr ) ) ;
  39. }
  40.  
  41. G4DISPLAY *S4FUNCTION g4display_len( W4ENTRY *ew, int x, int y, char *ptr, int ptr_len )
  42. {
  43.    TEXTMETRIC tm ;
  44.    C4CONTROLITEM control ;
  45.    HDC hDC ;
  46.  
  47.    #ifdef S4DEBUG
  48.       if ( ew == 0 )
  49.          e4severe( e4parm, "g4display_len()", E4_PARM_ZER, (void *) 0 ) ;
  50.    #endif
  51.  
  52.    hDC = w4get_dc( w4cb( ew ), ew->gw.hWindow ) ;
  53.    if ( hDC == 0 )  return 0 ;
  54.  
  55.    w4get_metrics( hDC, &tm ) ;
  56.  
  57.    control.X     = x ;
  58.    control.Y     = y ;
  59.    control.CX    = LOWORD( GetTextExtent( hDC, ptr, ptr_len ) ) ;
  60.    control.CY    = tm.tmHeight + tm.tmInternalLeading ;
  61.    control.Style = 0L ;
  62.    control.Id    = entry4_nextid( ew ) ;
  63.  
  64.    if ( w4release_dc( w4cb( ew ), ew->gw.hWindow, hDC ) == 0 )  return 0 ;
  65.  
  66.    return display4_create( ew, &control, ptr, ptr_len, -1, -1 ) ;
  67. }
  68.  
  69. G4DISPLAY *display4_create( W4ENTRY *ew, C4CONTROLITEM *control, char *text,
  70.                             int text_len, int low, int high )
  71. {
  72.    int height ;
  73.  
  74.    G4DISPLAY *sa = display4_construct( ew ) ;
  75.    if ( sa == 0 )  return 0 ;
  76.  
  77.    l4add( &ew->ControlList, (void *) &sa->ca ) ;
  78.  
  79.    if ( low < 0 )   
  80.    {
  81.       sa->x     = control->X  ;
  82.       sa->y     = control->Y  ;
  83.       sa->width = control->CX ;
  84.       height    = control->CY ;
  85.    }
  86.    else
  87.    {
  88.       sa->x     = (control->X  * low ) / 4 ;
  89.       sa->y     = (control->Y  * high) / 8 ;
  90.       sa->width = (control->CX * low ) / 4 ;
  91.       height    = (control->CY * high) / 8 ;
  92.    }
  93.  
  94.    sa->ca.gw.Style = control->Style | WS_VISIBLE | WS_CHILD ;
  95.  
  96.    sa->text = text ;
  97.    sa->text_len = text_len ;
  98.  
  99.    sa->ca.gw.hWindow = w4create_window( "Static", sa->text, sa->ca.gw.Style,
  100.                             sa->x, sa->y, sa->width, height,
  101.                             w4handle( ew ), control->Id, w4hInst( ew ), 0 ) ;
  102.  
  103.    sa->ca.hParent = ew->gw.hWindow ;
  104.    sa->ca.ew      = ew ;
  105.    sa->ca.gw.Id   = control->Id ;
  106.    sa->ca.gw.cw   = ew->gw.cw ;
  107.  
  108.    SetWindowLong( sa->ca.gw.hWindow, 0, (LONG) sa ) ;
  109.  
  110.    return sa ;
  111. }
  112.  
  113. void S4FUNCTION g4display_buffer( G4DISPLAY *sa, char *buf, unsigned buf_len )
  114. {
  115.    char *temp ;
  116.  
  117.    #ifdef S4DEBUG
  118.       if ( sa == 0 )
  119.          e4severe( e4parm, "g4display_buffer()", E4_PARM_ZER, (void *) 0 ) ;
  120.    #endif
  121.  
  122.    temp = (char *) u4alloc( buf_len+1 ) ;
  123.    if ( temp == 0 )  return ;
  124.    u4ncpy( temp, buf, buf_len+1 ) ;
  125.  
  126.    sa->text     = buf ;
  127.    sa->text_len = buf_len ;
  128.  
  129.    SetWindowText( g4handle( (void *) sa ), temp ) ;
  130.    u4free( temp ) ;
  131. }
  132.  
  133. int S4FUNCTION g4display_update( G4DISPLAY *sa )  /* 0 good, -x bad */
  134. {
  135.    RECT      rEdit, rParent ;
  136.    LPPOINT   point ;
  137.    B4AREA   *ba ;
  138.    B4BROWSE *bw ;
  139.    int leftmost = c4pix, rightmost = -c4pix ;
  140.  
  141.    #ifdef S4DEBUG
  142.       if ( sa == 0 )
  143.          e4severe( e4parm, "g4display_update()", E4_PARM_ZER, (void *) 0 ) ;
  144.    #endif
  145.  
  146.    bw = sa->ca.ew->bw ;
  147.  
  148.    if ( bw == 0 )
  149.    #ifdef S4DEBUG
  150.       return e4error( g4cb( sa ), e4parm, "g4display_update()", E4_PARM_ZER, (char *) 0 ) ;
  151.    #else
  152.       return -1 ;
  153.    #endif
  154.  
  155.    if ( sa->ca.gw.cw->cb.error_code < 0 )  return -1 ;
  156.  
  157.    ba = (B4AREA *) u4alloc( sizeof(B4AREA) ) ;
  158.    if ( ba == 0 )
  159.    {
  160.       e4error( g4cb( sa ), e4parm, "g4display_update()", e4memory, (char *) 0 ) ;
  161.       return -1 ;
  162.    }
  163.  
  164.    ba->sa = sa ;
  165.    ba->ea = 0  ;
  166.  
  167.    w4get_rect( sa->ca.gw.hWindow, &rEdit, 1 ) ;
  168.    w4get_rect( bw->entry.gw.hWindow, &rParent, 1 ) ;
  169.  
  170.    point = (LPPOINT) (&rEdit) ;
  171.    ScreenToClient( bw->entry.gw.hWindow, point ) ;
  172.    ScreenToClient( bw->entry.gw.hWindow, point+1 ) ;
  173.  
  174.    ba->LeftPos = rEdit.left ;
  175.    if ( bw->MarginTop < 0 )
  176.    {
  177.       bw->HeightEdit  = rEdit.bottom - rEdit.top ;
  178.       bw->PixelsExtra = bw->HeightEdit - bw->Pixels ;
  179.       bw->MarginTop   = rEdit.top ;
  180.    }
  181.  
  182.    ba->WidthBrowse = ba->WidthControl = rEdit.right - rEdit.left ; 
  183.  
  184.    general4_init( &ba->gw, bw->entry.gw.cw, "B4AREA", 0, WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  185.                   0,0,0,0, bw->entry.gw.hWindow, 0 ) ;
  186.  
  187.    SetWindowLong( ba->gw.hWindow, 0, (LONG) ba ) ;
  188.    browse4_add( bw, ba ) ;
  189.  
  190.    ba->bw = bw ;
  191.  
  192.    MoveWindow( ba->sa->ca.gw.hWindow, ba->LeftPos, bw->MarginTop + bw->PixelsExtra,
  193.                ba->WidthControl, bw->HeightEdit, 1 ) ;
  194.  
  195.    for ( ba=0 ; ba = (B4AREA *) l4next( &bw->BrowseList, ba ) ; )
  196.    {
  197.       if ( ba->ea != 0 )
  198.          w4get_rect( ba->ea->ca.gw.hWindow, &rEdit, 1 ) ;
  199.       else
  200.          w4get_rect( ba->sa->ca.gw.hWindow, &rEdit, 1 ) ;
  201.  
  202.       if ( rEdit.left  < leftmost  )  leftmost  = rEdit.left  ;
  203.       if ( rEdit.right > rightmost )  rightmost = rEdit.right ;
  204.    }
  205.    if ( leftmost > 0 )  leftmost = 0 ;
  206.    bw->MaxWidth = rightmost - leftmost ;
  207.  
  208.    browse4_scrollset( bw ) ;
  209.    browse4_resized( bw ) ;
  210.    if ( bw->entry.gw.cw->cb.error_code < 0 )  return -1 ;
  211.    return 0 ;
  212. }
  213.