bool GUIIsRectInUpdateRect( gui_window *wnd, WPI_RECT *rect ) { WPI_RECT update_rect; WPI_RECT intersect; if( !wnd || !wnd->ps || !rect ) { return( true ); } #ifdef __OS2_PM__ update_rect = *(wnd->ps); #else _wpi_getpaintrect( wnd->ps, &update_rect ); #endif _wpi_intersectrect( GUIMainHInst, &intersect, &update_rect, rect ); if( _wpi_isrectempty( GUIMainHInst, &intersect ) ) { return( false ); } return( true ); }
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 GUIDrawTextBitmapRGB( gui_window *wnd, const char *text, size_t length, int height, gui_coord *pos, WPI_COLOUR fore, WPI_COLOUR back, gui_ord extentx, bool draw_extent, int bitmap ) { int nDrawX, nDrawY; UINT lenx; HBRUSH brush; HBRUSH old_brush; HPEN pen; HPEN old_pen; int old_rop; size_t num_chars; WPI_RECT rect; gui_coord indent; int hscroll_pos; gui_coord extent; WPI_COLOUR colour; GUI_RECTDIM left, top, right, bottom; GUI_RECTDIM paint_left, paint_top, paint_right, paint_bottom; WPI_RECT paint_rect; WPI_RECT draw_rect; //draw_cache dcache; if( ( wnd->hdc == NULLHANDLE ) || ( wnd->ps == NULL ) || ( ( text == NULL ) && ( bitmap == 0 ) ) || ( ( bitmap != 0 ) && ( height == 0 ) ) ) { return; } old_rop = 0; old_brush = (HBRUSH)NULL; brush = (HBRUSH)NULL; old_pen = (HPEN)NULL; pen = (HPEN)NULL; GUIGetMetrics( wnd ); if( !bitmap ) { height = AVGYCHAR(GUItm); } rect = wnd->hwnd_client; _wpi_getrectvalues( rect, &left, &top, &right, &bottom); _wpi_getpaintrect( wnd->ps, &paint_rect ); _wpi_getwrectvalues( paint_rect, &paint_left, &paint_top, &paint_right, &paint_bottom ); top = paint_top / height * height; bottom = ( paint_bottom + height - 1) / height * height; if( GUI_DO_HSCROLL( wnd ) ) { hscroll_pos = GUIGetScrollPos( wnd, SB_HORZ ); } else { hscroll_pos = 0; } if( bitmap == 0 ) { num_chars = strlen( text ); if( num_chars > length ) { num_chars = length; } } indent.x = pos->x; indent.y = pos->y; GUIScaleToScreenR( &indent ); nDrawY = indent.y; if( GUI_DO_VSCROLL( wnd ) ) { nDrawY -= GUIGetScrollPos( wnd, SB_VERT ); } nDrawX = left; nDrawX += ( indent.x - hscroll_pos ); if( bitmap > 0 ) { lenx = length ; } else { lenx = GUIGetTextExtentX( wnd, text, num_chars ); } if( draw_extent ) { /* blanks out some portion of rest of the line */ if( extentx != GUI_NO_COLUMN ) { extent.x = extentx; GUIScaleToScreen( &extent ); right = nDrawX + extent.x; } } else { right = nDrawX + lenx; } nDrawY = _wpi_cvth_y_size( nDrawY, _wpi_getheightrect(wnd->hwnd_client), height ); _wpi_setrectvalues( &draw_rect, nDrawX, nDrawY, right, nDrawY+height ); if( GUIIsRectInUpdateRect( wnd, &draw_rect ) ) { colour = _wpi_getnearestcolor( wnd->hdc, back ); brush = _wpi_createsolidbrush( colour ); pen = _wpi_createpen( PS_SOLID, 1, colour ); if( pen == NULLHANDLE ) { GUIError(LIT( Pen_Failed )); } old_brush = _wpi_selectbrush( wnd->hdc, brush ); old_pen = _wpi_selectpen( wnd->hdc, pen ); #ifdef __OS2_PM__ _wpi_rectangle( wnd->hdc, nDrawX, nDrawY+1, right, nDrawY + height - 1 ); #else _wpi_rectangle( wnd->hdc, nDrawX, nDrawY, right, nDrawY + height); #endif /* if visible even with scrolling */ if( nDrawX < ( paint_right + hscroll_pos ) ) { if( bitmap > 0 ) { GUIDrawBitmap( bitmap, wnd->hdc, nDrawX, nDrawY, colour); } else { #ifdef __OS2_PM__ nDrawY += _wpi_metricdescent( GUItm ); #endif old_rop = _wpi_setrop2( wnd->hdc, R2_COPYPEN ); SetText( wnd, fore, back ); _wpi_textout( wnd->hdc, nDrawX, nDrawY, text, num_chars ); } } /* restore old resources */ if( old_rop != 0 ) { _wpi_setrop2( wnd->hdc, old_rop ); } if( old_brush != (HBRUSH)NULL ) { _wpi_getoldbrush( wnd->hdc, old_brush ); } if( brush != (HBRUSH)NULL ) { _wpi_deletebrush( brush ); } if( old_pen != (HPEN)NULL ) { _wpi_getoldpen( wnd->hdc, old_pen ); } if( pen != (HPEN)NULL ) { _wpi_deletepen( pen ); } } }
WPI_MRESULT CALLBACK GraphWndProc( HWND Wnd, WPI_MSG message, WPI_PARAM1 wParam, WPI_PARAM2 lParam ) //============================================================= { WPI_PRES Win_dc; PAINTSTRUCT ps; int width, height; int x, y, t; int h_minpos, h_maxpos, h_currpos; int v_minpos, v_maxpos, v_currpos; WPI_RECTDIM left, top, right, bottom; WPI_RECT rect; struct ScrollStruct scroll_info; LPWDATA w; HWND frame; #if defined( __OS2__ ) int wheight; WPI_RECT wrect; #endif w = _GetWindowData( Wnd ); if( w == NULL ) { return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); } #if defined( __OS2__ ) frame = w->frame; #else frame = Wnd; #endif switch( message ) { #if defined( __WINDOWS__ ) case WM_SETFOCUS: SetFocus( _MainWindow ); case WM_SYSCOMMAND: case WM_MOUSEACTIVATE: _MakeWindowActive( w ); return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_KILLFOCUS: if( ( wParam != NULL) && ( wParam != _MainWindow ) ) { _ShowWindowActive( NULL, w ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); #else case WM_FOCUSCHANGE: case WM_SYSCOMMAND: _MakeWindowActive( w ); return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); #endif case WM_PAINT: // Setup Win_dc = _wpi_beginpaint( Wnd, NULLHANDLE, &ps ); _wpi_torgbmode( Win_dc ); _wpi_getpaintrect( &ps, &rect ); _wpi_getwrectvalues( rect, &left, &top, &right, &bottom ); width = _wpi_getwidthrect( rect ); height = _wpi_getheightrect( rect ); // Copy from the memory dc to the screen #if defined( __OS2__ ) GetClientRect( Wnd, &wrect ); wheight = _wpi_getheightrect( wrect ); y = _GetPresHeight() - wheight - _BitBlt_Coord.ycoord + top; #else y = _BitBlt_Coord.ycoord + top; #endif _wpi_bitblt( Win_dc, left, top, width, height, _Mem_dc, _BitBlt_Coord.xcoord + left, y, SRCCOPY ); //Cleanup _wpi_endpaint( Wnd, Win_dc, &ps ); break; #if defined( __OS2__ ) case WM_CLOSE: WinDestroyWindow( w->frame ); return( 0 ); #endif case WM_DESTROY: // free the system resources allocated if( _Mem_dc ){ _wpi_deletecliprgn( _Mem_dc, _ClipRgn ); _wpi_deletecompatiblepres( _Mem_dc, _Hdc ); if( _Mem_bmp ){ _wpi_deletebitmap( _Mem_bmp ); if( !_IsStockFont() ){ _wpi_f_deletefont( _CurFnt ); } } #if defined( __OS2__ ) WinSendMsg( _GetWinMenuHandle(), ( ULONG )MM_DELETEITEM, MPFROM2SHORT( ( w->handles[0] + DID_WIND_STDIO ), FALSE ), 0 ); #endif _DestroyAWindow( w ); } break; case WM_VSCROLL: scroll_info = getscrolldata( frame, SB_VERT ); CalPos( &scroll_info, wParam, lParam, &v_currpos, &y ); // Make sure we have to refresh first if( _BitBlt_Coord.ycoord != y ) { _BitBlt_Coord.ycoord = y; _wpi_setscrollpos( frame, SB_VERT, v_currpos, TRUE ); _wpi_invalidaterect( Wnd, NULL, 0 ); _wpi_updatewindow( Wnd ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_HSCROLL: scroll_info = getscrolldata( frame, SB_HORZ ); CalPos( &scroll_info, wParam, lParam, &h_currpos, &x ); // make sure we need to refresh first if( _BitBlt_Coord.xcoord != x ) { _BitBlt_Coord.xcoord = x; _wpi_setscrollpos( frame, SB_HORZ, h_currpos, TRUE ); _wpi_invalidaterect( Wnd, NULL, 0 ); _wpi_updatewindow( Wnd ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_SIZE: x = _wpi_getsystemmetrics( SM_CXSCREEN ); y = _wpi_getsystemmetrics( SM_CYSCREEN ); _wpi_getscrollrange( frame, SB_VERT, &v_minpos, &v_maxpos ); _wpi_getscrollrange( frame, SB_HORZ, &h_minpos, &h_maxpos ); _wpi_getclientrect( Wnd, &rect ); _wpi_getrectvalues( rect, &left, &top, &right, &bottom ); height = bottom - top + 1; width = right - left + 1; if( width >= x ) { // hide the scroll bar #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ), FALSE ); #else ShowScrollBar( Wnd, SB_HORZ, FALSE ); #endif _BitBlt_Coord.xcoord = 0; h_currpos = 0; } else { // if the window isn't as big as the device context // show the scroll bar t = x - width + 1; if( x - _BitBlt_Coord.xcoord + 1 < width ) { _BitBlt_Coord.xcoord = x - width + 1; } if( _BitBlt_Coord.xcoord == t ) { h_currpos = h_maxpos; } else { h_currpos = CalScrollAmt( h_maxpos, h_minpos, _BitBlt_Coord.xcoord, x, width ); } #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ), TRUE ); #else ShowScrollBar( Wnd, SB_HORZ, 1 ); #endif } if( height >= y ) { // hide the scroll bar #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ), FALSE ); #else ShowScrollBar( Wnd, SB_VERT, 0 ); #endif _BitBlt_Coord.ycoord = 0; v_currpos = 0; } else { // if the the window isn't as big as the device context // then show the scroll bar t = y - height + 1; if( y - _BitBlt_Coord.ycoord + 1 < height ) { _BitBlt_Coord.ycoord = t; } if( _BitBlt_Coord.ycoord == t ) { v_currpos = v_maxpos; } else { v_currpos = CalScrollAmt( v_maxpos, v_minpos, _BitBlt_Coord.ycoord, y, height ); } #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ), TRUE ); #else ShowScrollBar( Wnd, SB_VERT, 1 ); #endif } // Adjust the scroll bar thumbs' positions _wpi_setscrollpos( frame, SB_HORZ, h_currpos, TRUE ); _wpi_setscrollpos( frame, SB_VERT, v_currpos, TRUE ); #if defined( __OS2__ ) Win_dc = WinBeginPaint( Wnd, NULL, &rect ); WinFillRect( Win_dc, &rect, CLR_BLACK ); WinEndPaint( Win_dc ); #endif _wpi_invalidaterect( Wnd, NULL, 0 ); break; default: return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); } return( NULL ); }