예제 #1
0
int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
		 char** list,
		 int x1,int y1,int x2,int y2,
		 Pixel colour,Pixel backColour,
		 int border,SelectionChangedHookPtr selChangedHook)
{
   int bpp = rfbScreen->bitsPerPixel/8;
   char* frameBufferBackup;
   void* screenDataBackup = rfbScreen->screenData;
   KbdAddEventProcPtr kbdAddEventBackup = rfbScreen->kbdAddEvent;
   PtrAddEventProcPtr ptrAddEventBackup = rfbScreen->ptrAddEvent;
   GetCursorProcPtr getCursorPtrBackup = rfbScreen->getCursorPtr;
   DisplayHookPtr displayHookBackup = rfbScreen->displayHook;
   rfbSelectData selData;
   int i,j,k;
   int fx1,fy1,fx2,fy2; /* for font bbox */

   if(list==0 || *list==0)
     return(-1);
   
   rfbWholeFontBBox(font, &fx1, &fy1, &fx2, &fy2);
   selData.textH = fy2-fy1;
   /* I need at least one line for the choice and one for the buttons */
   if(y2-y1<selData.textH*2+3*border)
     return(-1);
   selData.xhot = -fx1;
   selData.yhot = -fy2;
   selData.x1 = x1+border;
   selData.y1 = y1+border;
   selData.y2 = y2-selData.textH-3*border;
   selData.x2 = x2-2*border;
   selData.pageH = (selData.y2-selData.y1)/selData.textH;

   i = rfbWidthOfString(font,okStr);
   j = rfbWidthOfString(font,cancelStr);
   selData.buttonWidth= k = 4*border+(i<j)?j:i;
   selData.okBX = x1+(x2-x1-2*k)/3;
   if(selData.okBX<x1+border) /* too narrow! */
     return(-1);
   selData.cancelBX = x1+k+(x2-x1-2*k)*2/3;
   selData.okX = selData.okBX+(k-i)/2;
   selData.cancelX = selData.cancelBX+(k-j)/2;
   selData.okY = y2-border;

   rfbUndrawCursor(rfbScreen);
   frameBufferBackup = (char*)malloc(bpp*(x2-x1)*(y2-y1));

   selData.state = SELECTING;
   selData.screen = rfbScreen;
   selData.font = font;
   selData.list = list;
   selData.colour = colour;
   selData.backColour = backColour;
   for(i=0;list[i];i++);
   selData.selected = i;
   selData.listSize = i;
   selData.displayStart = i;
   selData.lastButtons = 0;
   selData.selChangedHook = selChangedHook;
   
   rfbScreen->screenData = &selData;
   rfbScreen->kbdAddEvent = selKbdAddEvent;
   rfbScreen->ptrAddEvent = selPtrAddEvent;
   rfbScreen->getCursorPtr = selGetCursorPtr;
   rfbScreen->displayHook = 0;
   
   /* backup screen */
   for(j=0;j<y2-y1;j++)
     memcpy(frameBufferBackup+j*(x2-x1)*bpp,
	    rfbScreen->frameBuffer+j*rfbScreen->paddedWidthInBytes+x1*bpp,
	    (x2-x1)*bpp);

   /* paint list and buttons */
   rfbFillRect(rfbScreen,x1,y1,x2,y2,colour);
   selPaintButtons(&selData,FALSE,FALSE);
   selSelect(&selData,0);

   /* modal loop */
   while(selData.state == SELECTING)
     rfbProcessEvents(rfbScreen,20000);

   /* copy back screen data */
   for(j=0;j<y2-y1;j++)
     memcpy(rfbScreen->frameBuffer+j*rfbScreen->paddedWidthInBytes+x1*bpp,
	    frameBufferBackup+j*(x2-x1)*bpp,
	    (x2-x1)*bpp);
   free(frameBufferBackup);
   rfbMarkRectAsModified(rfbScreen,x1,y1,x2,y2);
   rfbScreen->screenData = screenDataBackup;
   rfbScreen->kbdAddEvent = kbdAddEventBackup;
   rfbScreen->ptrAddEvent = ptrAddEventBackup;
   rfbScreen->getCursorPtr = getCursorPtrBackup;
   rfbScreen->displayHook = displayHookBackup;

   if(selData.state==CANCEL)
     selData.selected=-1;
   return(selData.selected);
}
예제 #2
0
vncConsolePtr vcGetConsole(int *argc,char **argv,
			   int width,int height,rfbFontDataPtr font
#ifdef USE_ATTRIBUTE_BUFFER
			   ,rfbBool withAttributes
#endif
			   )
{
  vncConsolePtr c=(vncConsolePtr)malloc(sizeof(vncConsole));

  c->font=font;
  c->width=width;
  c->height=height;
  c->screenBuffer=(char*)malloc(width*height);
  memset(c->screenBuffer,' ',width*height);
#ifdef USE_ATTRIBUTE_BUFFER
  if(withAttributes) {
    c->attributeBuffer=(char*)malloc(width*height);
    memset(c->attributeBuffer,0x07,width*height);
  } else
    c->attributeBuffer=NULL;
#endif
  c->x=0;
  c->y=0;
  c->sstart = 0;
  c->sheight = c->height;
  c->wrapBottomToTop=FALSE;
  c->cursorActive=TRUE;
  c->cursorIsDrawn=FALSE;
  c->dontDrawCursor=FALSE;
  c->inputBuffer=(char*)malloc(1024);
  c->inputSize=1024;
  c->inputCount=0;
  c->selection=0;
  c->selectTimeOut=40000; /* 40 ms */
  c->doEcho=TRUE;

  c->wasRightButtonDown=FALSE;
  c->currentlyMarking=FALSE;

  rfbWholeFontBBox(font,&c->xhot,&c->cHeight,&c->cWidth,&c->yhot);
  c->cWidth-=c->xhot;
  c->cHeight=-c->cHeight-c->yhot;

  /* text cursor */
  c->cx1=c->cWidth/8;
  c->cx2=c->cWidth*7/8;
  c->cy2=c->cHeight-1-c->yhot+c->cHeight/16;
  if(c->cy2>=c->cHeight)
    c->cy2=c->cHeight-1;
  c->cy1=c->cy2-c->cHeight/8;
  if(c->cy1<0)
    c->cy2=0;

  if(!(c->screen = rfbGetScreen(argc,argv,c->cWidth*c->width,c->cHeight*c->height,8,1,1)))
    return NULL;
  c->screen->screenData=(void*)c;
  c->screen->displayHook=vcMakeSureCursorIsDrawn;
  c->screen->frameBuffer=
    (char*)malloc(c->screen->width*c->screen->height);
  memset(c->screen->frameBuffer,c->backColour,
	 c->screen->width*c->screen->height);
  c->screen->kbdAddEvent=vcKbdAddEventProc;
  c->screen->ptrAddEvent=vcPtrAddEventProc;
  c->screen->setXCutText=vcSetXCutTextProc;

  MakeColourMap16(c);
  c->foreColour=0x7;
  c->backColour=0;

  return(c);
}