// CColoredButton message handlers void CColoredButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { EnableToolTips( TRUE); CDC *pDC = GetDC(); m_rectButton = lpDrawItemStruct->rcItem; m_rectButton.top+=2; m_rectButton.bottom-=2; m_dx = (m_rectButton.right-m_rectButton.left)/6; m_dy = (m_rectButton.top-m_rectButton.bottom)/2; if( m_bMixedColor && IsWindowEnabled()) { CBrush brush; brush.CreateHatchBrush(HS_BDIAGONAL, CLRF_CLR( RGBToColor(100,100,100))); pDC->FillRect( &m_rectButton, &brush); } else { ColorToComponents(); UBYTE ubR, ubG, ubB; UBYTE ubH, ubS, ubV, ubA; ubH = m_ubComponents[0][0]; ubS = m_ubComponents[0][1]; ubV = m_ubComponents[0][2]; ubA = m_ubComponents[0][3]; ubR = m_ubComponents[1][0]; ubG = m_ubComponents[1][1]; ubB = m_ubComponents[1][2]; #define FILL_RECT( col, x, y, w, h) {\ RECT rectToFill;\ rectToFill.left = m_rectButton.left+m_dx*x;\ if( w<0) rectToFill.right = m_rectButton.right-2;\ else rectToFill.right = m_rectButton.left+rectToFill.left+m_dx*w;\ rectToFill.top = m_rectButton.top-m_dy*y;\ rectToFill.bottom = m_rectButton.top+rectToFill.top-m_dy*h;\ COLORREF clrfColor = CLRF_CLR( col);\ if( !IsWindowEnabled()) clrfColor = CLRF_CLR( 0xBBBBBBBB);\ pDC->FillSolidRect( &rectToFill, clrfColor);\ pDC->DrawEdge( &rectToFill, EDGE_SUNKEN, BF_RECT);} FILL_RECT( HSVToColor( ubH, 255, 255), 0, 0, 1, 1); FILL_RECT( HSVToColor( ubH, ubS, 255), 1, 0, 1, 1); FILL_RECT( HSVToColor( ubH, 0, ubV), 2, 0, 1, 1); FILL_RECT( RGBToColor( ubA, ubA, ubA), 3, 0, 1, 2); FILL_RECT( RGBToColor( ubR, 0, 0), 0, 1, 1, 1); FILL_RECT( RGBToColor( 0, ubG, 0), 1, 1, 1, 1); FILL_RECT( RGBToColor( 0, 0, ubB), 2, 1, 1, 1); FILL_RECT( m_colColor, 4, 0, 2, 2); } pDC->DrawEdge( &lpDrawItemStruct->rcItem, EDGE_BUMP, BF_RECT); ReleaseDC( pDC); }
inline Bool HandleRFBServerMessage() { rfbServerToClientMsg msg; if(!ReadExact(rfbsock, (char *)&msg, 1)) return False; dprintf("HandleRFBServerMessage %d\n",msg.type); switch(msg.type) { case rfbSetColourMapEntries: { dprintf("rfbSetColourMapEntries\n"); int i; CARD16 rgb[3]; XColor xc; if(!ReadExact(rfbsock, ((char *)&msg.scme) + 1, sz_rfbSetColourMapEntriesMsg - 1)) return False; msg.scme.firstColour = Swap16IfLE(msg.scme.firstColour); msg.scme.nColours = Swap16IfLE(msg.scme.nColours); INIT_PALETTE(msg.scme.nColours); for(i = 0; i < msg.scme.nColours; i++) { xc.pixel = msg.scme.firstColour + i; if(addUseAlpha) { if(!ReadExact(rfbsock, (char *)rgb, 8)) return False; xc.transp = ((double)(0xff - (Swap16IfLE(rgb[0]) >> 8))) / ((double)0xff / (double)0xA0); xc.red = Swap16IfLE(rgb[1]) >> 8; xc.green = Swap16IfLE(rgb[2]) >> 8; xc.blue = Swap16IfLE(rgb[3]) >> 8; } else { if(!ReadExact(rfbsock, (char *)rgb, 6)) return False; xc.transp = 0; xc.red = Swap16IfLE(rgb[0]) >> 8; xc.green = Swap16IfLE(rgb[1]) >> 8; xc.blue = Swap16IfLE(rgb[2]) >> 8; } xc.flags = DoRed|DoGreen|DoBlue; INSERT_COLOUR (xc); } STORE_PALETTE(NULL); break; } case rfbFramebufferUpdate: { dprintf("rfbFramebufferUpdate\n"); //ShowOsd(True); rfbFramebufferUpdateRectHeader rect; int linesToRead; int bytesPerLine; int i; if(!ReadExact(rfbsock, ((char *)&msg.fu) + 1, sz_rfbFramebufferUpdateMsg - 1)) return False; msg.fu.nRects = Swap16IfLE(msg.fu.nRects); dprintf("# Rect %d\n",msg.fu.nRects); for(i = 0; i < msg.fu.nRects; i++) { if(!ReadExact(rfbsock, (char *)&rect, sz_rfbFramebufferUpdateRectHeader)) return False; rect.r.x = Swap16IfLE(rect.r.x); rect.r.y = Swap16IfLE(rect.r.y); rect.r.w = Swap16IfLE(rect.r.w); rect.r.h = Swap16IfLE(rect.r.h); rect.encoding = Swap32IfLE(rect.encoding); dprintf("Rect x/y/w/h %d/%d/%d/%d %u\n",rect.r.x,rect.r.y,rect.r.w,rect.r.h, (uint)rect.encoding); if((rect.r.x + rect.r.w > si.framebufferWidth) || (rect.r.y + rect.r.h > si.framebufferHeight)) { fprintf(stderr,"%s: rect too large: %dx%d at (%d, %d)\n", programName, rect.r.w, rect.r.h, rect.r.x, rect.r.y); return False; } if((rect.r.h * rect.r.w) == 0) { fprintf(stderr,"%s: zero size rect - ignoring\n",programName); continue; } switch(rect.encoding) { case rfbEncodingRaw: bytesPerLine = rect.r.w * myFormat.bitsPerPixel / 8; linesToRead = BUFFER_SIZE / bytesPerLine; while(rect.r.h > 0) { if(linesToRead > rect.r.h) linesToRead = rect.r.h; if(!ReadExact(rfbsock, buffer,bytesPerLine * linesToRead)) return False; CopyDataToScreen((CARD8 *)buffer, rect.r.x, rect.r.y, rect.r.w, linesToRead); rect.r.h -= linesToRead; rect.r.y += linesToRead; } break; case rfbEncodingCopyRect: { dprintf("rfbEncodingCopyRect\n"); rfbCopyRect cr; if(!ReadExact(rfbsock, (char *)&cr, sz_rfbCopyRect)) return False; cr.srcX = Swap16IfLE(cr.srcX); cr.srcY = Swap16IfLE(cr.srcY); COPY_AREA (cr.srcX, cr.srcY, rect.r.w, rect.r.h, rect.r.x, rect.r.y); break; } case rfbEncodingRRE: { dprintf("RRE\n"); rfbRREHeader hdr; CARD8 pix8; CARD16 pix16; CARD32 pix32; rfbRectangle subrect; int j; int dataSize; char *netbuff; char *p; if(!ReadExact(rfbsock, (char *)&hdr, sz_rfbRREHeader)) return False; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); switch(myFormat.bitsPerPixel) { case 8: if(!ReadExact(rfbsock, (char *)&pix8, 1)) return False; FILL_RECTNOREDRAW (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix8); dataSize = (sizeof(pix8) + sz_rfbRectangle) * hdr.nSubrects; netbuff = malloc(dataSize + 256); if(!ReadExact(rfbsock, netbuff, dataSize)) return False; p = netbuff; for(j = 0; j < hdr.nSubrects; j++) { memcpy((char*)&pix8, p, sizeof(pix8)); p += sizeof(pix8); memcpy((char*)&subrect, p, sz_rfbRectangle); p += sz_rfbRectangle; subrect.x = Swap16IfLE(subrect.x); subrect.y = Swap16IfLE(subrect.y); subrect.w = Swap16IfLE(subrect.w); subrect.h = Swap16IfLE(subrect.h); FILL_RECTNOREDRAW (rect.r.x + subrect.x, rect.r.y + subrect.y, subrect.w, subrect.h, pix8); } free(netbuff); REDRAWBOX(rect.r.x, rect.r.y, rect.r.w, rect.r.h); break; case 16: if(!ReadExact(rfbsock, (char *)&pix16, 2)) return False; FILL_RECTNOREDRAW (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix16); dataSize = (sizeof(pix16) + sz_rfbRectangle) * hdr.nSubrects; netbuff = malloc(dataSize + 256); if(!ReadExact(rfbsock, netbuff, dataSize)) return False; p = netbuff; for(j = 0; j < hdr.nSubrects; j++) { memcpy((char*)&pix16, p, sizeof(pix16)); p += sizeof(pix16); memcpy((char*)&subrect, p, sz_rfbRectangle); p += sz_rfbRectangle; subrect.x = Swap16IfLE(subrect.x); subrect.y = Swap16IfLE(subrect.y); subrect.w = Swap16IfLE(subrect.w); subrect.h = Swap16IfLE(subrect.h); FILL_RECTNOREDRAW (rect.r.x + subrect.x, rect.r.y + subrect.y, subrect.w, subrect.h, pix16); } free(netbuff); REDRAWBOX(rect.r.x, rect.r.y, rect.r.w, rect.r.h); break; case 32: if(!ReadExact(rfbsock, (char *)&pix32, 4)) return False; FILL_RECTNOREDRAW (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix32); dataSize = (sizeof(pix32) + sz_rfbRectangle) * hdr.nSubrects; netbuff = malloc(dataSize + 256); if(!ReadExact(rfbsock, netbuff, dataSize)) return False; p = netbuff; for(j = 0; j < hdr.nSubrects; j++) { memcpy((char*)&pix32, p, sizeof(pix32)); p += sizeof(pix32); memcpy((char*)&subrect, p, sz_rfbRectangle); p += sz_rfbRectangle; subrect.x = Swap16IfLE(subrect.x); subrect.y = Swap16IfLE(subrect.y); subrect.w = Swap16IfLE(subrect.w); subrect.h = Swap16IfLE(subrect.h); FILL_RECTNOREDRAW (rect.r.x + subrect.x, rect.r.y + subrect.y, subrect.w, subrect.h, pix32); } free(netbuff); REDRAWBOX(rect.r.x, rect.r.y, rect.r.w, rect.r.h); break; } break; } case rfbEncodingCoRRE: { dprintf("rfbEncodingCoRRE\n"); rfbRREHeader hdr; CARD8 pix8; CARD16 pix16; CARD32 pix32; int j; CARD8 *ptr; register int x, y, w, h; if(!ReadExact(rfbsock, (char *)&hdr, sz_rfbRREHeader)) return False; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); switch(myFormat.bitsPerPixel) { case 8: if(!ReadExact(rfbsock, (char *)&pix8, 1)) return False; FILL_RECT (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix8); if(!ReadExact(rfbsock, buffer, hdr.nSubrects * 5)) return False; ptr = (CARD8 *)buffer; for(j = 0; j < hdr.nSubrects; j++) { pix8 = *ptr++; x = *ptr++; y = *ptr++; w = *ptr++; h = *ptr++; FILL_RECT (rect.r.x + x, rect.r.y + y, w, h, pix8); } break; case 16: if(!ReadExact(rfbsock, (char *)&pix16, 2)) return False; FILL_RECT (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix16); if(!ReadExact(rfbsock, buffer, hdr.nSubrects * 6)) return False; ptr = (CARD8 *)buffer; for(j = 0; j < hdr.nSubrects; j++) { pix16 = *(CARD16 *)ptr; ptr += 2; x = *ptr++; y = *ptr++; w = *ptr++; h = *ptr++; FILL_RECT (rect.r.x + x, rect.r.y + y, w, h, pix16); } break; case 32: if(!ReadExact(rfbsock, (char *)&pix32, 4)) return False; FILL_RECT (rect.r.x, rect.r.y, rect.r.w, rect.r.h, pix32); if(!ReadExact(rfbsock, buffer, hdr.nSubrects * 8)) return False; ptr = (CARD8 *)buffer; for(j = 0; j < hdr.nSubrects; j++) { pix32 = *(CARD32 *)ptr; ptr += 4; x = *ptr++; y = *ptr++; w = *ptr++; h = *ptr++; FILL_RECT (rect.r.x + x, rect.r.y + y, w, h, pix32); } break; } break; } case rfbEncodingHextile: { dprintf("Hextile\n"); switch(myFormat.bitsPerPixel) { case 8: if(!HandleHextileEncoding8(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; case 16: if(!HandleHextileEncoding16(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; case 32: if(!HandleHextileEncoding32(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; } break; } default: printf("vnc: unknown rect encoding %u\n",(uint)rect.encoding); return False; } } //sendUpdateRequest = True; break; } case rfbBell: BELL; //ShowOsd(False); break; case rfbServerCutText: { char *str; if(!ReadExact(rfbsock, ((char *)&msg.sct) + 1, sz_rfbServerCutTextMsg - 1)) return False; msg.sct.length = Swap32IfLE(msg.sct.length); str = malloc(msg.sct.length); if(!ReadExact(rfbsock, str, msg.sct.length)) { free(str); return False; } /* XSelectInput(dpy, DefaultRootWindow(dpy), 0); XStoreBytes(dpy, str, msg.sct.length); XSetSelectionOwner(dpy, XA_PRIMARY, None, CurrentTime); XSelectInput(dpy, DefaultRootWindow(dpy), PropertyChangeMask); */ free(str); break; } case rfbReSizeFrameBuffer: { if(!ReadExact(rfbsock, ((char *)&msg.rsfb) + 1, sz_rfbReSizeFrameBufferMsg - 1)) return False; dprintf("rfbReSizeFrameBuffer: %d/%d | %d/%d\n",msg.rsfb.buffer_w,msg.rsfb.buffer_h,msg.rsfb.desktop_w,msg.rsfb.desktop_h); si.framebufferWidth = Swap16IfLE(msg.rsfb.buffer_w); si.framebufferHeight = Swap16IfLE(msg.rsfb.buffer_h); FILL_RECT(0, 0, si.framebufferWidth, si.framebufferHeight, 0); if(!SendFramebufferUpdateRequest(0, 0, si.framebufferWidth, si.framebufferHeight, False)) return False; } break; default: printf("%s: unknown message type %d from VNC server\n", programName,msg.type); return False; }