📄 tkwingdi.c
字号:
} } CkGraphCreateObject(type,(ClientData)hdcmem,file,line); tkWinGdi_CreateCompatibleDC++; } GTRACE(("%d:CreateCompatibleDC(0x%x) return 0x%x in %s %d\n",tkWinGdi_CreateCompatibleDC,hdc,hdcmem,file,line);)#endif CkGraphCreateDeviceContext(CKOBJ_MEMDC,hdcmem); return hdcmem;}#ifdef CKGRAPH_DEBUGint CkGraph_DeleteDC(HDC hdc,char* file,int line)#elseint CkGraph_DeleteDC(HDC hdc)#endif{ int result;#ifdef CKGRAPH_DEBUG int type; if(!Wtk_test_win32s()){ if((type=GetObjectType(hdc))!=CKOBJ_MEMDC && type!=CKOBJ_DC ){ dprintf("ObjectType in DeleteDC is %s\n",obj_type(type)); } } #endif /*select out the palette because otherwise the deletion of the palette sometimes fail*/ SelectPalette(hdc,stock_DEFAULT_PALETTE,TRUE); result=DeleteDC(hdc);#ifdef CKGRAPH_DEBUG if(!result) dprintf("CkDeleteDC failed in %s %d\n",file,line); CkGraphDeleteObject(type,(ClientData)hdc,file,line); tkWinGdi_DeleteDC++; GTRACE(("%d:DeleteDC(0x%x) return 0x%x in %s %d\n",tkWinGdi_DeleteDC,hdc,result,file,line);)#endif CkGraphDeleteDeviceContext(hdc); return result;}#ifdef CKGRAPH_DEBUGHDC CkGraph_BeginPaint(HWND hwnd,LPPAINTSTRUCT lpps,char* file,int line)#elseHDC CkGraph_BeginPaint(HWND hwnd,LPPAINTSTRUCT lpps)#endif{ HDC hdc; if((hdc=BeginPaint(hwnd,lpps))==(HDC)0){#ifdef CKGRAPH_DEBUG dprintf("CkBeginPaint failed in %s %d\n",file,line);#endif return (HDC)0; }#ifdef CKGRAPH_DEBUG CkGraphCreateObject(CKOBJ_DC,(ClientData)hdc,file,line); tkWinGdi_BeginPaint++; GTRACE(("%d:BeginPaint(0x%x,..) return 0x%x in %s %d\n",tkWinGdi_BeginPaint,hwnd,hdc,file,line);)#endif CkGraphCreateDeviceContext(CKOBJ_DC,hdc); return hdc;}#ifdef CKGRAPH_DEBUGBOOL CkGraph_EndPaint(HWND hwnd, PAINTSTRUCT* lpPaint,char* file,int line)#elseBOOL CkGraph_EndPaint(HWND hwnd, PAINTSTRUCT* lpPaint)#endif{ HDC hdc=lpPaint->hdc; BOOL result; result=EndPaint(hwnd,lpPaint);#ifdef CKGRAPH_DEBUG if(result==FALSE) dprintf("CkEndPaint failed in %s %d\n",file,line); CkGraphDeleteObject(CKOBJ_DC,(ClientData)hdc,file,line); tkWinGdi_EndPaint++; GTRACE(("%d:EndPaint(0x%x,..) return 0x%x in %s %d\n",tkWinGdi_EndPaint,hwnd,result,file,line);)#endif CkGraphDeleteDeviceContext(hdc); return result;}#ifdef CKGRAPH_DEBUGHGDIOBJ CkGraph_SelectObject(HDC hdc,HGDIOBJ hobj_in,char* file,int line)#elseHGDIOBJ CkGraph_SelectObject(HDC hdc,HGDIOBJ hobj_in)#endif{ HGDIOBJ hobj_out; int typein; int typeout; GdiContext *devPtr=FINDCONTEXT(hdc); /*regions are not considered here*/ if(Wtk_test_win32s()){ dprintf("CkSelectObject called under win32s"#ifdef CKGRAPH_DEBUG " in %s %d\n",file,line#endif ); } if((hobj_out=SelectObject(hdc,hobj_in))==(HGDIOBJ)0){#ifdef CKGRAPH_DEBUG dprintf("CkSelectObject failed in %s %d\n",file,line);#endif return (HGDIOBJ)0; } //GetObjectType only runs well under NT and Win95 not Win32s //use the CkGraph_Selectxx functions instead typein=convert_gdiobjtype(GetObjectType(hobj_in)); typeout=convert_gdiobjtype(GetObjectType(hobj_out)); if(devPtr && typein>=0 && typein<MAXGDIOBJ){ devPtr->hobjs[typein]=hobj_in; if(typeout==CKOBJ_BITMAP && !devPtr->defaultbitmap) devPtr->defaultbitmap=hobj_out; } /* if(!(CkGraphFindObject(typein,hobj_in) || CkGraphFindObject(typeout,hobj_out))){ if(!(is_stockobject(typein,hobj_in) || is_stockobject(typeout,hobj_out))) dprintf("CkSelectObject with handles not from us in %s %d\n",file,line); } */#ifdef CKGRAPH_DEBUG tkWinGdi_SelectObject++; GTRACE(("%d:SelectObject(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectObject,hdc,hobj_in,hobj_out,file,line);)#endif return hobj_out;}#ifdef CKGRAPH_DEBUGHBITMAP CkGraph_SelectBitmap(HDC hdc,HBITMAP hbitmap,char* file,int line)#elseHBITMAP CkGraph_SelectBitmap(HDC hdc,HBITMAP hbitmap)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); GdiContext *dcPtr; HBITMAP hout; if(!hbitmap){#ifdef CKGRAPH_DEBUG dprintf("No bitmap in CkGraph_SelectBitmap for %s %d\n",file,line);#else dprintf("No bitmap in CkGraph_SelectBitmap\n");#endif return (HBITMAP)0; } //if already selected,make a simple return if(devPtr && devPtr->hobjs[CKOBJ_BITMAP]==(HGDIOBJ)hbitmap){#ifdef CKGRAPH_DEBUG //check, if we REALLY assume this correct! if(SelectObject(hdc,devPtr->defaultbitmap)!=hbitmap) dprintf("bitmap 0x%x not selected into 0x%x\n",hbitmap,hdc); hbitmap=SelectObject(hdc,hbitmap);#endif return hbitmap; } //check for defaultbitmap //there are seldom cases,where the defaultbitmap of another //hdc is selected into a hdc with a defaultbitmap==0,where the //tests not work if(devPtr && hbitmap!=devPtr->defaultbitmap){ //only one bitmap per hdc,check it for (dcPtr = devHead ;dcPtr;dcPtr=dcPtr->next){ if(dcPtr==devPtr) continue; if(dcPtr->hobjs[CKOBJ_BITMAP]==(HGDIOBJ)hbitmap){#ifdef CKGRAPH_DEBUG if(tkWinGdi_verbose>1){ GdiObj *objPtr=CkGraphFindObject(dcPtr->type,(ClientData)dcPtr->hdc); dprintf("SelectBitmap(0x%x):%s %d,found another hdc 0x%x %s %d with the same bitmap,def=0x%x\n", hbitmap,file,line,dcPtr->hdc,objPtr?objPtr->file:"??",objPtr?objPtr->line:0,dcPtr->defaultbitmap); }#endif#ifdef CKGRAPH_DEBUG hout=SelectObject(dcPtr->hdc,dcPtr->defaultbitmap);#else SelectObject(dcPtr->hdc,dcPtr->defaultbitmap);#endif#ifdef CKGRAPH_DEBUG tkWinGdi_SelectBitmap++; GTRACE(("%d:SelectBitmapO(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectBitmap,dcPtr->hdc,dcPtr->defaultbitmap,hout,file,line);)#endif dcPtr->hobjs[CKOBJ_BITMAP]=dcPtr->defaultbitmap; break; } } } hout=(HBITMAP)SelectObject(hdc,(HGDIOBJ)hbitmap); if(hout && devPtr){ devPtr->hobjs[CKOBJ_BITMAP]=(HGDIOBJ)hbitmap; if(!devPtr->defaultbitmap) devPtr->defaultbitmap=hout; }#ifdef CKGRAPH_DEBUG tkWinGdi_SelectBitmap++; if(!hout) dprintf("SelectBitmap failed in %s %d\n",file,line); GTRACE(("%d:SelectBitmap(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectBitmap,hdc,hbitmap,hout,file,line);)#endif return hout;}/* look for a bitmap already selected into a registered dc and deselect this bitmap from the dc*/#ifdef CKGRAPH_DEBUGvoid CkGraph_CheckOutBitmap(HBITMAP hbitmap,char* file,int line)#elsevoid CkGraph_CheckOutBitmap(HBITMAP hbitmap)#endif /*CKGRAPH_DEBUG*/{ GdiContext *dcPtr; for (dcPtr = devHead ;dcPtr;dcPtr=dcPtr->next){ if(dcPtr->hobjs[CKOBJ_BITMAP]==(HGDIOBJ)hbitmap){#ifdef CKGRAPH_DEBUG GdiObj *objPtr=CkGraphFindObject(dcPtr->type,(ClientData)dcPtr->hdc); dprintf("CheckOutBitmap(0x%x):%s %d,found another hdc 0x%x %s %d with the same bitmap,def=0x%x\n", hbitmap,file,line,dcPtr->hdc,objPtr?objPtr->file:"??",objPtr?objPtr->line:0,dcPtr->defaultbitmap);#endif SelectObject(dcPtr->hdc,dcPtr->defaultbitmap); dcPtr->hobjs[CKOBJ_BITMAP]=dcPtr->defaultbitmap; break; } }}#ifdef CKGRAPH_DEBUGHPEN CkGraph_SelectPen(HDC hdc,HPEN hpen,char* file,int line)#elseHPEN CkGraph_SelectPen(HDC hdc,HPEN hpen)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); HPEN hout; //if already selected,make a simple return if(devPtr && devPtr->hobjs[CKOBJ_PEN]==(HGDIOBJ)hpen){#ifdef CKGRAPH_DEBUG if((hout=(HPEN)SelectObject(hdc,(HGDIOBJ)stock_NULL_PEN))!=hpen){ dprintf("pen is 0x%x, should be 0x%x in %s %d\n",hout,hpen,file,line); } hpen=(HPEN)SelectObject(hdc,(HGDIOBJ)hpen);#endif return hpen; } hout=(HPEN)SelectObject(hdc,(HGDIOBJ)hpen); if(hout && devPtr) devPtr->hobjs[CKOBJ_PEN]=(HGDIOBJ)hpen;#ifdef CKGRAPH_DEBUG tkWinGdi_SelectPen++; if(!hout) dprintf("CkSelectPen failed in %s %d\n",file,line); GTRACE(("%d:SelectPen(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectPen,hdc,hpen,hout,file,line);)#endif return hout;}#ifdef CKGRAPH_DEBUGHBRUSH CkGraph_SelectBrush(HDC hdc,HBRUSH hbrush,char* file,int line)#elseHBRUSH CkGraph_SelectBrush(HDC hdc,HBRUSH hbrush)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); HBRUSH hout; //if already selected,make a simple return if(devPtr && devPtr->hobjs[CKOBJ_BRUSH]==(HGDIOBJ)hbrush){#ifdef CKGRAPH_DEBUG if((hout=SelectObject(hdc,stock_NULL_BRUSH))!=hbrush) dprintf("brush is 0x%x, should be 0x%x in %s %d\n",hout,hbrush,file,line); hbrush=SelectObject(hdc,hbrush);#endif return hbrush; } hout=(HBRUSH)SelectObject(hdc,(HGDIOBJ)hbrush); if(hout && devPtr) devPtr->hobjs[CKOBJ_BRUSH]=(HGDIOBJ)hbrush;#ifdef CKGRAPH_DEBUG tkWinGdi_SelectBrush++; if(!hout) dprintf("CkSelectBrush failed in %s %d\n",file,line); GTRACE(("%d:SelectBrush(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectBrush,hdc,hbrush,hout,file,line);)#endif return hout;}#ifdef CKGRAPH_DEBUGint CkGraph_SelectClipRgn(HDC hdc,HRGN hrgn,char* file,int line)#elseint CkGraph_SelectClipRgn(HDC hdc,HRGN hrgn)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); int result; /* * if the region is already selected,make a simple return */ if(devPtr && devPtr->hrgn==hrgn) return devPtr->hrgntype; result=SelectClipRgn(hdc,hrgn); if(result!=ERROR && devPtr) { devPtr->hrgn=hrgn; devPtr->hrgntype=result; } /* * reset the offsets to mark them invalid */ if(devPtr) { devPtr->hrgn_xoff=0; devPtr->hrgn_yoff=0; }#ifdef CKGRAPH_DEBUG tkWinGdi_SelectClipRgn++; if(result==ERROR) dprintf("CkSelectClipRgn failed in %s %d\n",file,line); GTRACE(("%d:SelectClipRgn(0x%x,0x%x) return 0x%x in %s %d\n",tkWinGdi_SelectClipRgn,hdc,hrgn,result,file,line);)#endif return result;}#ifdef CKGRAPH_DEBUGint CkGraph_OffsetClipRgn(HDC hdc,int xoff,int yoff,char* file,int line)#elseint CkGraph_OffsetClipRgn(HDC hdc,int xoff,int yoff)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); int result; /* * if the offsets don't differ make a simple return * however in the case of xoff==yoff==0 we force an Offset * because a previous selecting might be invoked before */ if(devPtr && devPtr->hrgn_xoff==xoff && devPtr->hrgn_yoff==yoff && xoff!=0 && yoff!=0 ) { return devPtr->hrgntype; } result=OffsetClipRgn(hdc,xoff,yoff); if(result!=ERROR && devPtr) { devPtr->hrgn_xoff=xoff; devPtr->hrgn_yoff=yoff; }#ifdef CKGRAPH_DEBUG tkWinGdi_OffsetClipRgn++; if(result==ERROR) dprintf("CkOffsetClipRgn failed in %s %d\n",file,line); GTRACE(("%d:OffsetClipRgn(0x%x,%d,%d) return 0x%x in %s %d\n",tkWinGdi_OffsetClipRgn,hdc,xoff,yoff,result,file,line);)#endif return result;}#ifdef CKGRAPH_DEBUGHPALETTE CkGraph_SelectPalette(HDC hdc,HPALETTE hpal,BOOL f,char* file,int line)#elseHPALETTE CkGraph_SelectPalette(HDC hdc,HPALETTE hpal,BOOL f)#endif /*CKGRAPH_DEBUG*/{ GdiContext *devPtr=FINDCONTEXT(hdc); HPALETTE hout; //if already selected,make a simple return if(devPtr && devPtr->hobjs[CKOBJ_PAL]==(HGDIOBJ)hpal){#ifdef CKGRAPH_DEBUG if((hout=SelectPalette(hdc,stock_DEFAULT_PALETTE,f))!=hpal) dprintf("palette is 0x%x,should be 0x%x in %s %d\n",hout,hpal,file,line); hpal=SelectPalette(hdc,hpal,f);#endif return hpal; } hout=SelectPalette(hdc,hpal,f); if(hout && devPtr){ devPtr->hobjs[CKOBJ_PAL]=(HGDIOBJ)hpal; devPtr->palettevalid=0;/* if(!devPtr->defaultpalette){ devPtr->defaultpalette=hout; if(hout==stock_DEFAULT_PALETTE){ dprintf("Default palette was selected\n"); } }*/ }#ifdef CKGRAPH_DEBUG tkWinGdi_SelectPalette++; if(!hout) dprintf("CkSelectPalette failed in %s %d\n",file,line); GTRACE(("%d:SelectPalette(0x%x,0x%x,%d) return 0x%x in %s %d\n",tkWinGdi_SelectPalette,hdc,hpal,f,hout,file,line);)#endif return hout;}#ifdef CKGRAPH_DEBUGUINT CkGraph_RealizePalette(HDC hdc,char* file,int line)#elseUINT CkGraph_RealizePalette(HDC hdc)#endif /*CKGRAPH_DEBUG*/{ UINT numcolors; GdiContext *devPtr=FINDCONTEXT(hdc); if (devPtr && devPtr->type==CKOBJ_MEMDC && devPtr->palettevalid==1){ return 0; } numcolors=RealizePalette(hdc);#ifdef CKGRAPH_DEBUG tkWinGdi_RealizePalette++; if(numcolors==GDI_ERROR) dprintf("CkRealizePalette failed in %s %d\n",file,line); GTRACE(("%d:RealizePalette(0x%x) return %d in %s %d\n",tkWinGdi_RealizePalette,hdc,numcolors,file,line);)#endif if (devPtr && devPtr->type==CKOBJ_MEMDC){ devPtr->palettevalid=1; } return numcolors;}static void InvalidateSelectedPalette(HPALETTE hPal){ GdiContext *dcPtr; for (dcPtr = devHead ;dcPtr;dcPtr=dcPtr->next){ if(dcPtr->hobjs[CKOBJ_PAL]==hPal) dcPtr->palettevalid=0; }}#ifdef CKGRAPH_DEBUGUINT CkGraph_SetPaletteEntries(HPALETTE hPal,UINT iStart,UINT cEntries , CONST PALETTEENTRY* lppe,char* file,int line)#elseUINT CkGraph_SetPaletteEntries(HPALETTE hPal,UINT iStart,UINT cEntries , CONST PALETTEENTRY* lppe)#endif /*CKGRAPH_DEBUG*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -