JError JXImage::WriteXPM ( const JCharacter* fileName ) const { #ifdef _J_HAS_XPM XpmAttributes attr; attr.valuemask = XpmColormap; attr.colormap = itsXColormap->GetXColormap(); int xpmErr; if (itsImage != NULL) { XImage* mask_image = NULL; if (itsMask != NULL) { itsMask->ConvertToImage(); mask_image = ((JXImage*) itsMask)->itsImage; } xpmErr = XpmWriteFileFromImage(*itsDisplay, const_cast<JCharacter*>(fileName), itsImage, mask_image, &attr); } else { assert( itsPixmap != None ); Pixmap mask_pixmap = None; if (itsMask != NULL) { itsMask->ConvertToPixmap(); mask_pixmap = ((JXImage*) itsMask)->itsPixmap; } xpmErr = XpmWriteFileFromPixmap(*itsDisplay, const_cast<JCharacter*>(fileName), itsPixmap, mask_pixmap, &attr); } if (xpmErr == XpmOpenFailed) { return JAccessDenied(fileName); } else if (xpmErr == XpmNoMemory) { return JNoProcessMemory(); } else { return JNoError(); } #else return XPMNotAvailable(); #endif }
int C_PrintProc(ClientData cl, Tcl_Interp *interp, int argc, char **argv) { char fileType, printMode; WindowType theWindow = theWindowArray[atoi(argv[1])]; char **xpmData; fileType = argv[4][0]; printMode = argv[5][0]; switch(fileType) { case 'x': #ifdef XPMENABLED if(argv[6][0]!='n' && (!Is_Trace_On(theWindow) || Is_X_AutoRescale(theWindow) || Is_Y_AutoRescale(theWindow))) { Iconic_Before(theWindow); C_RefreshGraphicsProc(NULL,NULL,1,argv); } XpmWriteFileFromPixmap(theDisplay,argv[2],theWindow->pixmap_buffer, 0,NULL); #endif break; case 'p': #ifdef XPMENABLED if(argv[4][1]=='n') /* png */ { if(argv[6][0]!='n' && (!Is_Trace_On(theWindow) || Is_X_AutoRescale(theWindow) || Is_Y_AutoRescale(theWindow))) { Iconic_Before(theWindow); C_RefreshGraphicsProc(NULL,NULL,1,argv); } XpmWriteFileFromPixmap(theDisplay,argv[2],theWindow->pixmap_buffer,0,0); { char name[512]; char name2[512]; char buffer[512]; int i; sprintf(name,"%s",argv[2]); i = strlen(name); if(i<5) return 0; /* invalid name */ sprintf(name+i-4,"%s",".xpm"); sprintf(name2,"%s",name); sprintf(name2+i-4,"%s",".png"); sprintf(buffer,"mv %s %s;convert %s %s; rm %s",name2,name,name,name2,name); system(buffer); break; } } #else break; #endif /* XPMENABLED */ case 'e': if(access(argv[2],F_OK) || printMode=='o' || printMode=='c') PSHeader(argv[2]); (*(theWindow->print_function)) (theWindow, argv[2], argv[3]); break; case 'a': (*(theWindow->ascii_print_function)) (theWindow, argv[2], printMode); break; case 'b': (*(theWindow->xgrafix_print_function)) (theWindow, argv[2], printMode); break; case 'g': #ifdef XPMENABLED if(argv[6][0]!='n' && (!Is_Trace_On(theWindow) || Is_X_AutoRescale(theWindow) || Is_Y_AutoRescale(theWindow))) { Iconic_Before(theWindow); C_RefreshGraphicsProc(NULL,NULL,1,argv); } XpmCreateDataFromPixmap(theDisplay, &xpmData, theWindow->pixmap_buffer, 0,NULL); XpmToGif(xpmData,argv[2]); XpmFree(xpmData); #endif break; } return TCL_OK; }
void paint_textfield(GUI* g,Window win,WIDGET* w) { int width; int taken=0; struct textfield_data_t* data=w->widget_data; if((w->status&STATUS_REPAINT)>0){ if(w->width==0){ while(w->string[taken]!='\0') taken++; for(width=taken;width<data->max_length;width++) w->string[width]='A'; w->width=XTextWidth(g->font,w->string,strlen(w->string))+6; w->height=g->font->ascent*2; for(width=taken;width<data->max_length;width++) w->string[width]='\0'; data->map=XCreatePixmap(g->dsp,g->mainWindow,w->width,3*w->height,24); } //not visible and background of whole thing XSetForeground(g->dsp,g->draw,g->bgColor); XFillRectangle(g->dsp,data->map,g->draw,0,0,w->width,w->height*3); // Normal if(data->background_color>-1) XSetForeground(g->dsp,g->draw,data->background_color); else XSetForeground(g->dsp,g->draw, g->whiteColor); XFillRectangle(g->dsp,data->map,g->draw,0,w->height,w->width,w->height); XSetForeground(g->dsp,g->draw,g->blackColor); XDrawRectangle(g->dsp,data->map,g->draw,0,w->height,w->width-1,w->height-1); // Not enabled if(data->background_color>-1) XSetForeground(g->dsp,g->draw,to_gray(data->background_color)); else XSetForeground(g->dsp,g->draw, to_gray(g->whiteColor)); XFillRectangle(g->dsp,data->map,g->draw,0,w->height*2,w->width,w->height); XSetForeground(g->dsp,g->draw,to_gray(g->blackColor)); XDrawRectangle(g->dsp,data->map,g->draw,0,w->height*2,w->width-1,w->height-1); // Debug print to file #ifdef DEBUG_PRINT_IMAGES char filename[1024]; sprintf(filename,"pic_output/textfield_%p.xpm",(void *)w); Pixmap p=XCreatePixmap(g->dsp,g->mainWindow,w->width,w->height*3,24); XSetForeground(g->dsp,g->draw,0xFFFFFFFF); XFillRectangle(g->dsp,p,g->draw,0,0,w->width,w->height*3); XpmWriteFileFromPixmap(g->dsp,filename,data->map,p,NULL); XFreePixmap(g->dsp,p); #endif w->status=w->status&(~STATUS_REPAINT); } if((w->status&STATUS_VISIBLE)==0){ XCopyArea(g->dsp,data->map,win,g->draw,0,0,w->width,w->height,w->x,w->y); } else if((w->status&STATUS_ENABLE)==0){ XCopyArea(g->dsp,data->map,win,g->draw,0,w->height*2,w->width,w->height,w->x,w->y); if(data->text_color>0){ XSetForeground(g->dsp,g->text, to_gray(data->text_color)); XDrawString(g->dsp,win,g->text,w->x+4,w->y+w->height/2+w->height/4,w->string,strlen(w->string)); XSetForeground(g->dsp,g->text,g->blackColor); } else{ XSetForeground(g->dsp,g->text, to_gray(g->blackColor)); XDrawString(g->dsp,win,g->text,w->x+4,w->y+w->height/2+w->height/4,w->string,strlen(w->string)); XSetForeground(g->dsp,g->text,g->blackColor); } } else{ XCopyArea(g->dsp,data->map,win,g->draw,0,w->height,w->width,w->height,w->x,w->y); if(data->text_color>0){ XSetForeground(g->dsp,g->text,(w->status&STATUS_ENABLE)>0 ? data->text_color : to_gray(data->text_color)); XDrawString(g->dsp,win,g->text,w->x+4,w->y+w->height/2+w->height/4,w->string,strlen(w->string)); XSetForeground(g->dsp,g->text,g->blackColor); } else{ XSetForeground(g->dsp,g->text,(w->status&STATUS_ENABLE)>0 ? g->blackColor : to_gray(g->blackColor)); XDrawString(g->dsp,win,g->text,w->x+4,w->y+w->height/2+w->height/4,w->string,strlen(w->string)); XSetForeground(g->dsp,g->text,g->blackColor); } } }