bool GetControlExtent( gui_window * wnd, unsigned id, const char *text, size_t length, gui_coord *coord ) { int my_length; WPI_PRES dc; WPI_FONT old; WPI_FONT first; HWND hwnd; if( text && GetControlInfo( wnd, id, &hwnd, &dc ) ) { my_length = strlen( text ); if( length != (size_t)-1 ) { if( my_length > length ) { my_length = length; } } if( wnd->font != NULL ) { old = _wpi_selectfont( dc, wnd->font ); } else { old = NULL; } _wpi_gettextextent( dc, text, my_length, &coord->x, &coord->y ); if( old != NULL ) { first = _wpi_selectfont( dc, old ); } _wpi_releasepres( hwnd, dc ); GUIScreenToScaleR( coord ); return( true ); } return( false ); }
static void textdim( /******************/ char *text_line, text_def *text, int *width, int *height ) { WPI_FONT font_hld; WPI_FONT old_font; if( text_line == NULL ) { text_line = Dummy_text; } font_hld = _wtextinit( text ); old_font = _wpi_selectfont( Win_dc, font_hld ); _wpi_gettextextent( Win_dc, text_line, strlen( text_line ), width, height ); _wpi_getoldfont( Win_dc, old_font ); _wtextdone( font_hld ); }
static void textdim_font( /***********************/ char *text_line, WPI_FONT font_hld, int *width, int *height ) { WPI_FONT old_font; if( text_line == NULL ) { text_line = Dummy_text; } font_hld = font_hld; // unused in Windows old_font = _wpi_selectfont( Win_dc, font_hld ); _wpi_gettextextent( Win_dc, text_line, strlen( text_line ), width, height ); _wpi_getoldfont( Win_dc, old_font ); }
void _wtextout( /*************/ char *text, float x, float y, int hor_align, int ver_align, void *wfont ) { WORD horiz_flags; WORD vert_flags; WPI_FONT old_font; int dx; int dy; WPI_TEXTMETRIC font_info; int len; int bk_mode; int px1; int py1; int px2; int py2; int width; int height; WPI_FONT font; font = (WPI_FONT) wfont; bk_mode = _wpi_getbackmode( Win_dc ); _wpi_setbackmode( Win_dc, TRANSPARENT ); len = strlen( text ); convert_pt( x, y, &dx, &dy ); old_font = _wpi_selectfont( Win_dc, font ); if( Text_path == TEXT_VERTICAL ) { _wpi_gettextmetrics( Win_dc, &font_info ); width = _wpi_metricmaxcharwidth( font_info ); height = len * _wpi_metricheight( font_info ); } else { _wpi_gettextextent( Win_dc, text, len, &width, &height ); } px1 = px2 = dx; py1 = py2 = dy; switch( hor_align ) { case TEXT_H_LEFT: horiz_flags = TA_LEFT; px2 += width; break; case TEXT_H_CENTER: horiz_flags = TA_CENTER; px1 -= width / 2; px2 += width / 2; break; case TEXT_H_RIGHT: horiz_flags = TA_RIGHT; px2 -= width; break; } switch( ver_align ) { case TEXT_V_TOP: py2 += height * WPI_VERT_MULT; break; case TEXT_V_CENTER: py1 -= height / 2 * WPI_VERT_MULT; py2 += height / 2 * WPI_VERT_MULT; break; case TEXT_V_BOTTOM: py2 -= height * WPI_VERT_MULT; break; } rgn_rectangle( px1, py1, px2, py2 ); if( Text_path == TEXT_HORIZONTAL ) { /* normal right path */ switch( ver_align ) { case TEXT_V_TOP: #ifdef PLAT_OS2 /* OS/2 has problems with TA_LEFT && TA_TOP aligned text */ /* This is a messy solution until we actually figure out */ /* what the problem is. */ vert_flags = TA_BOTTOM; _wpi_gettextmetrics( Win_dc, &font_info ); dy += _wpi_metricheight( font_info ) * WPI_VERT_MULT; #else vert_flags = TA_TOP; #endif break; case TEXT_V_CENTER: #ifdef PLAT_OS2 vert_flags = TA_HALF; #else /* OS/2 has a much cleverer way of doing this */ /* but Windows apparently doesn't */ vert_flags = TA_TOP; _wpi_gettextmetrics( Win_dc, &font_info ); dy -= _wpi_metricheight( font_info ) / 2 * WPI_VERT_MULT; #endif break; case TEXT_V_BOTTOM: vert_flags = TA_BOTTOM; break; } _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); _wpi_textout( Win_dc, dx, dy, text, len ); } else { /* must display text vertically... do it by hand */ vert_flags = TA_TOP; _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); switch( ver_align ) { case TEXT_V_BOTTOM: dy -= _wpi_metricheight( font_info ) * len * WPI_VERT_MULT; break; case TEXT_V_CENTER: dy -= (_wpi_metricheight( font_info ) * len) / 2 * WPI_VERT_MULT; break; } _wpi_settextalign( Win_dc, horiz_flags, vert_flags ); for( ; len > 0; --len, dy += _wpi_metricheight( font_info ) * WPI_VERT_MULT, ++text ) { _wpi_textout( Win_dc, dx, dy, text, 1 ); } } _wpi_getoldfont( Win_dc, old_font ); _wpi_setbackmode( Win_dc, bk_mode ); }
/* * outputText - output a text string */ static void outputText( statwnd *sw, WPI_PRES pres, char *buff, WPI_RECT *r, UINT flags, int curr_block ) { WPI_RECT ir; WPI_RECT draw_rect; size_t len; int ext; int width; WPI_RECTDIM ir_left; WPI_RECTDIM ir_right; WPI_RECTDIM ir_top; WPI_RECTDIM ir_bottom; WPI_RECTDIM r_left; WPI_RECTDIM r_right; WPI_RECTDIM r_top; WPI_RECTDIM r_bottom; UINT pmflags; #ifndef __NT__ int height; #else SIZE sz; #endif if( sw->sectionData[curr_block] != NULL ) { if( !strcmp( buff, sw->sectionData[curr_block] ) && flags == sw->sectionDataFlags[curr_block] ) { return; } } len = strlen( buff ); if( len == 0 ) { return; } MemFree( sw->sectionData[curr_block] ); sw->sectionData[curr_block] = MemAlloc( len + 1 ); memcpy( sw->sectionData[curr_block], buff, len + 1 ); sw->sectionDataFlags[curr_block] = flags | DT_TEXTATTRS; #ifndef __NT__ _wpi_gettextextent( pres, buff, (int)len, &ext, &height ); #else GetTextExtentPoint( pres, buff, (int)len, &sz ); ext = sz.cx; #endif ir = *r; _wpi_getrectvalues( ir, &ir_left, &ir_top, &ir_right, &ir_bottom ); #ifdef __OS2_PM__ ir_left++; ir_top++; ir_bottom++; _wpi_setrectvalues( &draw_rect, ir_left, ir_top, ir_right, ir_bottom ); #else draw_rect = *r; #endif if( flags & DT_CENTER ) { width = ( ir_right - ir_left - ext ) / 2; if( width > 0 ) { ir_right = ir_left + width; _wpi_setrectvalues( &ir, ir_left, ir_top, ir_right, ir_bottom ); _wpi_fillrect( pres, &ir, colorButtonFace, brushButtonFace ); _wpi_getrectvalues( *r, &r_left, &r_top, &r_right, &r_bottom ); ir_right = r_right; ir_left = r_right - width; _wpi_setrectvalues( &ir, ir_left, ir_top, ir_right, ir_bottom ); _wpi_fillrect( pres, &ir, colorButtonFace, brushButtonFace ); } } else if( flags & DT_RIGHT ) { ir_right -= ext; if( ir_right >= ir_left ) { _wpi_setrectvalues( &ir, ir_left, ir_top, ir_right, ir_bottom ); _wpi_fillrect( pres, &ir, colorButtonFace, brushButtonFace ); } } else { ir_left += ext; if( ir_left < ir_right ) { _wpi_setrectvalues( &ir, ir_left, ir_top, ir_right, ir_bottom ); _wpi_fillrect( pres, &ir, colorButtonFace, brushButtonFace ); } } pmflags = flags | DT_TEXTATTRS; _wpi_drawtext( pres, buff, -1, &draw_rect, pmflags ); } /* outputText */