/* * selectColor - select the color */ static void selectColor( WPI_POINT *pt, HWND hwnd ) { int i; WPI_PRES pres; HWND currentwnd; int top; int bottom; WPI_RECT wrect; currentwnd = _wpi_getdlgitem( hwnd, BK_CURRENT ); pres = _wpi_getpres( currentwnd ); _wpi_mapwindowpoints( hwnd, currentwnd, pt, 1 ); _wpi_torgbmode( pres ); for( i = 0; i < 16; i++ ) { top = availColor[i].box.top; bottom = availColor[i].box.bottom; top = _wpi_cvth_y( top, 2 * SQR_SIZE ); bottom = _wpi_cvth_y( bottom, 2 * SQR_SIZE ); _wpi_setintwrectvalues( &wrect, availColor[i].box.left, top, availColor[i].box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { screenColor.color = availColor[i].color; DisplayColorBox( pres, &screenColor ); inverseColor.color = GetInverseColor( screenColor.color ); DisplayColorBox( pres, &inverseColor ); break; } } _wpi_releasepres( currentwnd, pres ); } /* selectColor */
/* * DisplayColorBox - display the colors on the given device context * - PM Note: we assume the presentation space is already in RGB mode */ void DisplayColorBox( WPI_PRES pres, palette_box *box ) { int top; int bottom; HBRUSH hcolorbrush; HBRUSH holdbrush; HPEN holdpen; HPEN blackpen; int height; blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); holdpen = _wpi_selectobject( pres, blackpen ); hcolorbrush = _wpi_createsolidbrush( box->color ); holdbrush = _wpi_selectobject( pres, hcolorbrush ); height = 2 * SQR_SIZE + 1; top = _wpi_cvth_y( box->box.top, height ); bottom = _wpi_cvth_y( box->box.bottom, height ); _wpi_rectangle( pres, box->box.left, top, box->box.right, bottom ); _wpi_selectobject( pres, holdbrush ); _wpi_deleteobject( hcolorbrush ); _wpi_selectobject( pres, holdpen ); _wpi_deleteobject( blackpen ); } /* DisplayColorBox */
/* * outlineRect - draw the outline of a rectangle */ static void outlineRect( statwnd *sw, WPI_PRES pres, WPI_RECT *r ) { WPI_POINT pt; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; HPEN oldpen; sw = sw; _wpi_getrectvalues( *r, &left, &top, &right, &bottom ); _wpi_setpoint( &pt, left, bottom - 1 ); _wpi_cvth_pt( &pt, sw->wndHeight ); _wpi_movetoex( pres, &pt, NULL ); oldpen = _wpi_selectobject( pres, penLight ); pt.x = right - 1; _wpi_lineto( pres, &pt ); pt.y = _wpi_cvth_y( top, sw->wndHeight ); _wpi_lineto( pres, &pt ); _wpi_selectobject( pres, penShade ); pt.x = left; _wpi_lineto( pres, &pt ); pt.y = _wpi_cvth_y( bottom - 1, sw->wndHeight ); _wpi_lineto( pres, &pt ); _wpi_selectobject( pres, oldpen ); } /* outlineRect */
/* * selectScreen - selects the screen color */ static void selectScreen( WPI_POINT *pt, int mousebutton ) { WPI_RECT wrect; int top; int bottom; if( !fShowScreenClr ) { return; } top = _wpi_cvth_y( screenColor.box.top, screenHeight ); bottom = _wpi_cvth_y( screenColor.box.bottom, screenHeight ); _wpi_setintwrectvalues( &wrect, screenColor.box.left, top, screenColor.box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { SetColor( mousebutton, screenColor.color, screenColor.color, SCREEN_CLR ); return; } top = _wpi_cvth_y( inverseColor.box.top, screenHeight ); bottom = _wpi_cvth_y( inverseColor.box.bottom, screenHeight ); _wpi_setintwrectvalues( &wrect, inverseColor.box.left, top, inverseColor.box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { SetColor( mousebutton, inverseColor.color, inverseColor.color, INVERSE_CLR ); return; } } /* selectScreen */
/* * editCurrentColor - edit the color under the cursor */ static void editCurrentColor( WPI_POINT *pt ) { int i; WPI_RECT wrect; int top; int bottom; for( i = 0; i < PALETTE_SIZE; i++ ) { top = _wpi_cvth_y( paletteBox[i].box.top, colorsHeight ); bottom = _wpi_cvth_y( paletteBox[i].box.bottom, colorsHeight ); _wpi_setintwrectvalues( &wrect, paletteBox[i].box.left, top, paletteBox[i].box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { if( numberOfColors == 2 ) { return; } else { #ifndef __OS2_PM__ EditColors(); #endif return; } } } } /* editCurrentColor */
/* * ScreenWndProc - handle messages for the screen and inverse windows */ WPI_MRESULT CALLBACK ScreenWndProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam, WPI_PARAM2 lparam ) { WPI_POINT pt; WPI_RECT wrect1; WPI_RECT wrect2; int top; int bottom; switch( msg ) { case WM_PAINT: paintScreen( hwnd ); break; case WM_LBUTTONDOWN: IMGED_MAKEPOINT( wparam, lparam, pt ); selectScreen( &pt, LMOUSEBUTTON ); break; case WM_LBUTTONDBLCLK: if( !fShowScreenClr ) { break; } IMGED_MAKEPOINT( wparam, lparam, pt ); top = _wpi_cvth_y( screenColor.box.top, screenHeight ); bottom = _wpi_cvth_y( screenColor.box.bottom, screenHeight ); _wpi_setintwrectvalues( &wrect1, screenColor.box.left, top, screenColor.box.right, bottom ); top = _wpi_cvth_y( inverseColor.box.top, screenHeight ); bottom = _wpi_cvth_y( inverseColor.box.bottom, screenHeight ); _wpi_setintwrectvalues( &wrect2, inverseColor.box.left, top, inverseColor.box.right, bottom ); if( _wpi_ptinrect( &wrect1, pt ) || _wpi_ptinrect( &wrect2, pt ) ) { ChooseBkColor(); } break; case WM_RBUTTONDOWN: IMGED_MAKEPOINT( wparam, lparam, pt ); selectScreen( &pt, RMOUSEBUTTON ); break; default: return( DefWindowProc( hwnd, msg, wparam, lparam ) ); } return( 0 ); } /* ScreenWndProc */
bool GUITrackFloatingPopup( gui_window *wnd, gui_point *location, gui_mouse_track track, gui_ctl_id *curr_id ) { WPI_POINT pt; ULONG flags; GUI_RECTDIM left, top, right, bottom; HMENU popup; if( ( popup = GUIHFloatingPopup ) == (HMENU)NULL ) { return( false ); } GUIScaleToScreenRPt( location ); _wpi_getrectvalues( wnd->hwnd_client_rect, &left, &top, &right, &bottom ); location->x += left; location->y += top; if( GUI_DO_HSCROLL( wnd ) ) { location->x -= GUIGetScrollPos( wnd, SB_HORZ ); } if( GUI_DO_VSCROLL( wnd ) ) { location->y -= GUIGetScrollPos( wnd, SB_VERT ); } CurrId = NO_SELECT; if( ( curr_id != NULL ) && ( *curr_id != 0 ) ) { CurrId = *curr_id; } location->y = _wpi_cvth_y( location->y, (bottom - top) ); pt.x = location->x; pt.y = location->y; _wpi_mapwindowpoints( wnd->hwnd, HWND_DESKTOP, &pt, 1 ); flags = TPM_LEFTALIGN; if( track & GUI_TRACK_LEFT ) { flags |= TPM_LEFTBUTTON; } if( track & GUI_TRACK_RIGHT ) { flags |= TPM_RIGHTBUTTON; } InitComplete = false; GUIFlushKeys(); _wpi_trackpopupmenu( popup, flags, pt.x, pt.y, wnd->hwnd_frame ); _wpi_destroymenu( popup ); GUIHFloatingPopup = NULLHANDLE; if( ( CurrId != NO_SELECT ) && ( curr_id != NULL ) ) { *curr_id = CurrId; } CurrId = NO_SELECT; GUIDeleteFloatingPopups( wnd ); return( true ); }
/* * paintCurrent - paint the current window (process WM_PAINT) */ static void paintCurrent( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; WPI_RECT rect; HBITMAP oldbitmap; int top; int bottom; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_bitblt( pres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_bitblt( pres, CUR_RCOL_X - 1, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_setbackmode( pres, TRANSPARENT ); _wpi_settextcolor( pres, GetInverseColor( lButton.solid ) ); top = _wpi_cvth_y( CUR_COL_Y, currentHeight ); bottom = _wpi_cvth_y( CUR_COL_Y + CUR_SQR_SIZE, currentHeight ); _wpi_setintwrectvalues( &rect, CUR_LCOL_X, top, CUR_LCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "L", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_settextcolor( pres, GetInverseColor( rButton.solid ) ); _wpi_setintwrectvalues( &rect, CUR_RCOL_X, top, CUR_RCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "R", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintCurrent */
/* * selectColor - select the color under the cursor */ static void selectColor( WPI_POINT *pt, int mousebutton ) { short i; WPI_RECT wrect; int top; int bottom; for( i = 0; i < PALETTE_SIZE; i++ ) { top = _wpi_cvth_y( paletteBox[i].box.top, colorsHeight ); bottom = _wpi_cvth_y( paletteBox[i].box.bottom, colorsHeight ); _wpi_setintrectvalues( &wrect, paletteBox[i].box.left, top, paletteBox[i].box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { SetColor( mousebutton, paletteBox[i].color, paletteBox[i].solid_color, NORMAL_CLR ); return; } } } /* selectColor */
void _L1GetPic( short x1, short y1, short x2, short y2, /*===============================*/ struct picture _WCI86HUGE *image ) /* Copy that portion of the screen inside the viewport to the buffer pointed by 'image'. */ { short dx; /* width of rectangle in pixels */ short dy; /* height of rectangle in pixels */ short t; #if defined( _DEFAULT_WINDOWS ) WPI_PRES dc; short srcy; #else short line_len; /* length of each line in bytes */ #if !defined( __386__ ) unsigned short new_off; #endif char *tmp; gr_device _FARD *dev_ptr; /* pointer to _CurrState->deviceptr */ char _WCI86HUGE *pic; /* buffer to store image */ copy_fn *copy; /* pointer to copy routine */ setup_fn *setup; #endif if( x1 > x2 ) { // ensure x1 < x2 t = x1; x1 = x2; x2 = t; } if( y1 > y2 ) { // ensure y1 < y2 t = y1; y1 = y2; y2 = t; } if( _L0BlockClip( &x1, &y1, &x2, &y2 ) != 0 ) { /* clip image to */ image->picwidth = 0; /* active viewport */ image->picheight = 0; _ErrorStatus = _GRNOOUTPUT; return; } dx = x2 - x1 + 1; /* row width in pixels */ dy = y2 - y1 + 1; /* height in pixel rows */ image->picwidth = dx; /* save width in image picture */ image->picheight = dy; /* save height in image picture */ #if defined( _DEFAULT_WINDOWS ) dc = _Mem_dc; // Create a memory DC to put the image in image->buffer = _wpi_createcompatiblepres( dc, _GetInst(), &( image->pdc ) ); image->bmp = _wpi_createcompatiblebitmap( dc, dx, dy ); if( ( image->buffer == NULL ) || ( image->bmp == NULL ) ) { _ErrorStatus = _GRINSUFFICIENTMEMORY; return; } _wpi_selectbitmap( image->buffer, image->bmp ); // Transfer the image to a memory DC #if defined( __OS2__ ) srcy = _wpi_cvth_y( y2, _GetPresHeight() ); #else srcy = y1; #endif _wpi_bitblt( image->buffer, 0, 0, dx, dy, dc, x1, srcy, SRCCOPY ); #else image->bpp = _CurrState->vc.bitsperpixel; /* save bpp - never used ? */ line_len = _RowLen( dx ); /* width of row in bytes */ _StartDevice(); dev_ptr = _CurrState->deviceptr; copy = dev_ptr->readrow; pic = &image->buffer; tmp = NULL; setup = dev_ptr->setup; for( ; y1 <= y2; ++y1 ) { /* copy screen image to buffer */ ( *setup )( x1, y1, 0 ); #if !defined( __386__ ) // check whether the entire row will fit in the buffer new_off = FP_OFF( pic ) + line_len - 1; if( new_off < FP_OFF( pic ) ) { if( tmp == NULL ) { // may have been already allocated if( _stackavail() - line_len > 0x100 ) { tmp = __alloca( _RoundUp( line_len ) ); } } if( tmp != NULL ) { ( *copy )( tmp, _Screen.mem, dx, _Screen.bit_pos, 0 ); for( t = 0; t < line_len; ++t ) { *pic = tmp[ t ]; ++pic; // the PIA function will handle this properly } } else { _ErrorStatus = _GRINSUFFICIENTMEMORY; pic += line_len; } } else { #endif ( *copy )( pic, _Screen.mem, dx, _Screen.bit_pos, 0 ); pic += line_len; #if !defined( __386__ ) } #endif } _ResetDevice(); #endif }
/* * drawBorder - draw the border for the view window */ static void drawBorder( img_node *node ) { WPI_PRES presborder; HPEN hgraypen; HPEN hwhitepen; HPEN hblackpen; HPEN holdpen; WPI_RECT rcclient; HBRUSH hnewbrush; HBRUSH holdbrush; HBRUSH nullbrush; int width; int height; #ifndef __NT__ WPI_POINT pt; #endif int top; int bottom; presborder = _wpi_getpres( node->viewhwnd ); #if defined( __NT__ ) hwhitepen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNHIGHLIGHT ) ); hblackpen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNTEXT ) ); #else hwhitepen = _wpi_createpen( PS_SOLID, 0, CLR_WHITE ); hblackpen = _wpi_createpen( PS_SOLID, 0, CLR_BLACK ); #endif GetClientRect( node->viewhwnd, &rcclient ); width = _wpi_getwidthrect( rcclient ); height = _wpi_getheightrect( rcclient ); if( node->imgtype != BITMAP_IMG ) { #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); #else hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_DARKGRAY ); #endif holdpen = _wpi_selectobject( presborder, hgraypen ); #if defined( __NT__ ) hnewbrush = _wpi_createsolidbrush( GetSysColor( COLOR_BTNFACE ) ); #else hnewbrush = _wpi_createsolidbrush( CLR_PALEGRAY ); #endif holdbrush = _wpi_selectobject( presborder, hnewbrush ); top = 0; bottom = height; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); _wpi_rectangle( presborder, 0, top, width, bottom ); /* * Draw black border and selected background color in the view window. */ _wpi_selectobject( presborder, hblackpen ); _wpi_selectobject( presborder, holdbrush ); _wpi_deleteobject( hnewbrush ); hnewbrush = _wpi_createsolidbrush( bkgroundColor ); _wpi_selectobject( presborder, hnewbrush ); top = BORDER_WIDTH - 1; bottom = height - BORDER_WIDTH + 1; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); #ifndef __NT__ /* * Draw the border relative to the size of the object being displayed, * not the window containing it. */ _wpi_rectangle( presborder, BORDER_WIDTH - 1, top, node->width + BORDER_WIDTH + 1, top + node->height + 2 ); #endif _wpi_selectobject( presborder, holdbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hnewbrush ); } else { #ifdef __OS2_PM__ // I can't seem to get the thick pen to work so I'm using this // method. hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_PALEGRAY ); holdpen = _wpi_selectobject( presborder, hgraypen ); hnewbrush = _wpi_createsolidbrush( CLR_PALEGRAY ); holdbrush = _wpi_selectobject( presborder, hnewbrush ); _wpi_rectangle( presborder, 0, 0, width + 1, BORDER_WIDTH + 1 ); _wpi_rectangle( presborder, 0, 0, BORDER_WIDTH + 1, height + 1 ); _wpi_rectangle( presborder, 0, height - BORDER_WIDTH, width + 1, height + 1 ); _wpi_rectangle( presborder, width - BORDER_WIDTH, 0, width + 1, height + 1 ); _wpi_selectobject( presborder, holdbrush ); _wpi_deleteobject( hnewbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hgraypen ); #else #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_INSIDEFRAME, BORDER_WIDTH, GetSysColor( COLOR_BTNFACE ) ); #else hgraypen = _wpi_createpen( PS_INSIDEFRAME, BORDER_WIDTH, CLR_PALEGRAY ); #endif holdpen = _wpi_selectobject( presborder, hgraypen ); nullbrush = _wpi_createnullbrush(); holdbrush = _wpi_selectbrush( presborder, nullbrush ); _wpi_rectangle( presborder, 0, 0, rcclient.right, rcclient.bottom ); _wpi_getoldbrush( presborder, holdbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hgraypen ); _wpi_deletenullbrush( nullbrush ); #endif nullbrush = _wpi_createnullbrush(); #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); #else hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_DARKGRAY ); #endif holdbrush = _wpi_selectbrush( presborder, nullbrush ); holdpen = _wpi_selectobject( presborder, hgraypen ); top = 0; bottom = height; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); _wpi_rectangle( presborder, 0, top, width, bottom ); _wpi_selectobject( presborder, hblackpen ); top = BORDER_WIDTH - 1; bottom = height - BORDER_WIDTH + 1; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); #ifndef __NT__ /* * Draw the border relative to the size of the object being displayed, * not the window containing it. */ _wpi_rectangle( presborder, BORDER_WIDTH - 1, top, node->width + BORDER_WIDTH + 1, top + node->height + 2 ); #endif _wpi_selectobject( presborder, holdpen ); _wpi_selectbrush( presborder, holdbrush ); _wpi_deletenullbrush( nullbrush ); } /* * Give the view window the 3D effect. */ #ifndef __NT__ holdpen = _wpi_selectobject( presborder, hwhitepen ); _wpi_setpoint( &pt, 0, height - 1 ); _wpi_cvth_pt( &pt, height ); _wpi_movetoex( presborder, &pt, NULL ); _wpi_setpoint( &pt, 0, 0 ); _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = width; _wpi_lineto( presborder, &pt ); _wpi_setpoint( &pt, width - BORDER_WIDTH + 1, BORDER_WIDTH - 2 ); _wpi_cvth_pt( &pt, height ); _wpi_movetoex( presborder, &pt, NULL ); pt.y = height - BORDER_WIDTH + 1; _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = BORDER_WIDTH - 2; _wpi_lineto( presborder, &pt ); _wpi_selectobject( presborder, hgraypen ); _wpi_setpoint( &pt, BORDER_WIDTH - 2, BORDER_WIDTH - 2 ); _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = width - BORDER_WIDTH + 1; _wpi_lineto( presborder, &pt ); _wpi_selectobject( presborder, holdpen ); #endif _wpi_deleteobject( hgraypen ); _wpi_deleteobject( hwhitepen ); _wpi_deleteobject( hblackpen ); _wpi_releasepres( node->viewhwnd, presborder ); } /* drawBorder */
/* * SetColor - set the current colors */ void SetColor( int mousebutton, COLORREF color, COLORREF solid, wie_clrtype type ) { HDC hdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; HPEN blackpen; HPEN oldpen; HBRUSH brush; HBRUSH oldbrush; int top; int bottom; blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); if( mousebutton == LMOUSEBUTTON ) { lButton.color = color; lButton.solid = solid; lButton.type = type; if( lButton.bitmap != NULL ) { _wpi_deletebitmap( lButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { lButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { lButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } else { rButton.color = color; rButton.solid = solid; rButton.type = type; if( rButton.bitmap != NULL ) { _wpi_deletebitmap( rButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { rButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { rButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } _wpi_deleteobject( blackpen ); InvalidateRect( hCurrentWnd, NULL, TRUE ); } /* SetColor */
/* * InitPaletteBitmaps - initialize the available color bitmaps */ void InitPaletteBitmaps( HWND hwnd, HBITMAP *colorbitmap, HBITMAP *monobitmap ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; HBITMAP oldbitmap; COLORREF color; int i; int left_sqr; HBRUSH colorbrush; HBRUSH oldbrush; HPEN blackpen; HPEN oldpen; int top; int bottom; int height; pres = _wpi_getpres( hwnd ); *colorbitmap = _wpi_createcompatiblebitmap( pres, CUR_BMP_WIDTH, CUR_BMP_HEIGHT ); *monobitmap = _wpi_createbitmap( CUR_BMP_WIDTH, CUR_BMP_HEIGHT, 1, 1, NULL ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_releasepres( hwnd, pres ); _wpi_torgbmode( mempres ); blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); oldpen = _wpi_selectobject( mempres, blackpen ); oldbitmap = _wpi_selectobject( mempres, *colorbitmap ); /* * PM NOTE: All box coordinates are relative to the window's origin * of top left. So we convert the height for PM. */ left_sqr = 0; height = 2 * SQR_SIZE + 1; for( i = 0; i < PALETTE_SIZE; i += 2 ) { color = RGB( palette[COLOR_16][i].rgbRed, palette[COLOR_16][i].rgbGreen, palette[COLOR_16][i].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( 0, height ); bottom = _wpi_cvth_y( SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); color = RGB( palette[COLOR_16][i + 1].rgbRed, palette[COLOR_16][i + 1].rgbGreen, palette[COLOR_16][i + 1].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( SQR_SIZE, height ); bottom = _wpi_cvth_y( 2 * SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); left_sqr += SQR_SIZE; } _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, *monobitmap ); left_sqr = 0; for( i = 0; i < PALETTE_SIZE; i += 2 ) { color = RGB( palette[COLOR_2][i].rgbRed, palette[COLOR_2][i].rgbGreen, palette[COLOR_2][i].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( 0, height ); bottom = _wpi_cvth_y( SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); color = RGB( palette[COLOR_2][i + 1].rgbRed, palette[COLOR_2][i + 1].rgbGreen, palette[COLOR_2][i + 1].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( SQR_SIZE, height ); bottom = _wpi_cvth_y( 2 * SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); left_sqr += SQR_SIZE; } _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_deleteobject( blackpen ); } /* InitPaletteBitmaps */