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 ); }
/* * initPRES - initialize our presentation space for drawing text */ static bool initPRES( statwnd *sw, WPI_PRES pres ) { if( sw->sectionDataFont == NULL ) { return( false ); } #ifdef __NT__ oldFont = _wpi_selectfont( pres, systemDataFont ); #else oldFont = _wpi_selectfont( pres, sw->sectionDataFont ); #endif oldBrush = _wpi_selectbrush( pres, brushButtonFace ); oldBkColor = _wpi_getbackcolour( pres ); _wpi_setbackcolour( pres, colorButtonFace ); #ifdef __OS2_PM__ GpiSetBackMix( pres, BM_OVERPAINT ); #else oldTextColor = GetTextColor( pres ); SetTextColor( pres, colorTextFace ); #endif return( true ); } /* initPRES */
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 GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; WPI_RECT fill_area; #ifdef __OS2_PM__ ULONG flags; RECTL client; #endif isdlg=isdlg; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; /* Setup Paint */ wnd->ps = &ps; wnd->hdc = _wpi_beginpaint( hwnd, NULLHANDLE, wnd->ps ); _wpi_torgbmode( wnd->hdc ); _wpi_getpaintrect( wnd->ps, &fill_area ); #ifdef __OS2_PM__ fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); #endif #if defined( __NT__ ) if( isdlg ) { _wpi_fillrect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ), wnd->bk_brush ); } #endif if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } else { wnd->prev_font = NULL; } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } #ifdef __OS2_PM__ if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( wnd->hdc, &client, 1, 1, 0, 0, flags ); } #endif _wpi_endpaint( hwnd, wnd->hdc, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; } #else // this is some experimental PM stuff void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; PAINTSTRUCT fill_area; // experimenal stuff HPS hps; RECTL client; LONG width, height; ULONG flags; int compat_created; gui_paint_info *pinfo; // figure out which paint info to use if( !isdlg && wnd->root == hwnd ) { pinfo = &wnd->root_pinfo; } else { pinfo = &wnd->hwnd_pinfo; } pinfo->in_use++; compat_created = FALSE; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; if( isdlg ) { _wpi_getclientrect( hwnd, &client ); } else { WinQueryWindowRect( hwnd, &client ); } width = client.xRight - client.xLeft; height = client.yTop - client.yBottom; wnd->ps = &ps; //hps = _wpi_beginpaint( hwnd, pinfo->normal_pres, wnd->ps ); hps = _wpi_beginpaint( hwnd, NULL, wnd->ps ); if( pinfo->compatible_pres == (WPI_PRES)NULL ) { compat_created = TRUE; pinfo->compatible_pres = _wpi_createcompatiblepres( hps, GUIMainHInst, &pinfo->compatible_hdc ); pinfo->draw_bmp = _wpi_createcompatiblebitmap( hps, width, height ); pinfo->old_bmp = _wpi_selectbitmap( pinfo->compatible_pres, pinfo->draw_bmp ); } // the condition is here VERY conservative!! // its gains have to analyzed if( compat_created || pinfo->force_count ) { wnd->hdc = pinfo->compatible_pres; //wnd->hdc = hps; _wpi_torgbmode( wnd->hdc ); fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); wnd->prev_font = NULL; if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } if( pinfo->force_count ) { //pinfo->force_count--; } } //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); if( pinfo->in_use == 1 ) { //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); _wpi_bitblt( hps, ps.xLeft, ps.yBottom, ps.xRight - ps.xLeft, ps.yTop - ps.yBottom, wnd->hdc, ps.xLeft, ps.yBottom, SRCCOPY ); if( pinfo->delete_when_done ) { GUIFreePaintHandles( pinfo, TRUE ); } } if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( hps, &client, 1, 1, 0, 0, flags ); } _wpi_endpaint( hwnd, hps, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; if( pinfo->in_use ) { pinfo->in_use--; } } #endif void GUIInvalidatePaintHandles( gui_window *wnd ) { GUIFreeWndPaintHandles( wnd, FALSE ); }
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 ); }