⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tkwingdi.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 5 页
字号:
    if(hdc)      CkDeleteDC(hdc);  }}/* *---------------------------------------------------------------------- * CkGraph_ClearDC -- *	reset the values in a DC with the default values of a freshly *      created memory DC *---------------------------------------------------------------------- */void CkGraph_ClearDC(HDC dc){    CkSetBkMode(dc,clearBkMode);    CkSetTextColor(dc,clearTextColor);    CkSetBkColor(dc,clearBkColor);}#ifdef CKGRAPH_DEBUGvoid CkGraph_CheckSelectedBitmap(HDC hdc,HBITMAP hbitmap){  CompatDC *curr;  CompatDC *found=NULL;  for (curr = compatDCList; curr != NULL; curr = curr->next) {    if (curr->hdc==hdc){      found=curr;    }    if (curr->used && curr->hbitmap == hbitmap && curr->hdc!=hdc ) {      dprintf("AddSelBitmap: hdc 0x%x already has bitmap 0x%x selected,"               "during setting of 0x%x\n",               curr->hdc,curr->hbitmap,hdc);    }  }  if(found!=NULL)    found->hbitmap=hbitmap;}#endiftypedef struct _PixElem {  HBITMAP pixmap;  int width;  int height;  int planes;  int depth;  int used;  int delete_after_use;  struct _PixElem* next;} PixElem;static PixElem* pixmapList=NULL;static PixElem* currpix=NULL;int xpixmaps=0;static void DeletePixmap(HBITMAP pixmap) {  if (pixmap != NULL)    CkDeleteBitmap(pixmap);}static HBITMAP NewPixmap(int width,int height,int planes,int depth) {  return CkCreateBitmap(width, height, planes, depth, NULL);}/* *---------------------------------------------------------------------- * AddPixmap -- *	Add a pixmap to our list of known pixmaps.   *---------------------------------------------------------------------- */static void AddPixmap( HBITMAP pixmap,int width ,int height,int planes,int depth,int delete_after_use) {    PixElem *pixElem;    pixElem = (PixElem *) ckalloc(sizeof(PixElem));    pixElem->next = pixmapList;    pixElem->pixmap = pixmap;    pixElem->width = width;    pixElem->height = height;    pixElem->planes = planes;    pixElem->depth = depth;    pixElem->used=1;    pixElem->delete_after_use=delete_after_use;    currpix=pixmapList = pixElem;    xpixmaps++;}/* *---------------------------------------------------------------------- * RemovePixmap -- *	Removes a pixmap from our list of known pixmaps *---------------------------------------------------------------------- */static void RemovePixmap(HBITMAP pixmap) {  PixElem *prev, *curr, *next;  for (prev = NULL, curr = pixmapList; curr != NULL;  prev = curr, curr = next)  {    next = curr->next;    if (curr->pixmap == pixmap) {      if (prev != NULL) {        prev->next = curr->next;      } else {        pixmapList = curr->next;      }      xpixmaps--;      if(xpixmaps<0)        panic("xpixmaps<0 in RemovePixmap");      if(currpix==curr)        currpix=NULL;      ckfree((char *) curr);      return;    }  }}#define FINDFREEPIXMAP() \  (currpix!=NULL && currpix->used==0 ) ? currpix : \                                                      FindFreePixmap()/* *---------------------------------------------------------------------- * FindFreePixmap -- *	Finds an unused HBITMAP *---------------------------------------------------------------------- */static PixElem* FindFreePixmap(void){    PixElem  *curr;    for (curr = pixmapList; curr != NULL; curr = curr->next) {      if(curr->used==0)        return currpix=curr;    }    return 0;}#define FINDPIXMAP(_pixmap) \  (currpix && currpix->pixmap==(_pixmap)) ? currpix : FindPixmap(_pixmap)/* *---------------------------------------------------------------------- * FindPixmap -- *	Finds a HBITMAP in the Lists of Pixmaps *---------------------------------------------------------------------- */static PixElem* FindPixmap(HBITMAP pixmap){  PixElem *curr;  for (curr = pixmapList; curr != NULL; curr = curr->next) {    if (curr->pixmap == pixmap) {      return currpix=curr;    }  }  return NULL;}/*                                                                               *----------------------------------------------------------------------         * CkGraph_GetHashedBitmap --   *      searches a free element in the list, if nothing is found, creates        *      a new Pixmap and adds it to the list                               *----------------------------------------------------------------------         */      HBITMAP CkGraph_GetHashedBitmap( int width, int height,int planes,int depth){   PixElem* pe=FINDFREEPIXMAP();   if(!pe){     HBITMAP pixmap=NewPixmap(width,height,planes,depth);     AddPixmap(pixmap,width,height,planes,depth,0);     return pixmap;   }   pe->used=1;   if( (pe->width < width) || (pe->height < height) ||        (pe->planes != planes) || (pe->depth != depth) ){     DeletePixmap(pe->pixmap);     if(pe->planes==planes && pe->depth==depth){       width =max(width, pe->width);       height=max(height,pe->height);     } else {       //dprintf("pe->planes:%d planes:%d,pe->depth:%d depth:%d\n",       //         pe->planes,planes,pe->depth,depth);     }     pe->pixmap=NewPixmap(width,height,planes,depth);     pe->width=width;     pe->height=height;     pe->planes=planes;     pe->depth=depth;   }   return pe->pixmap;}/*                                                                               *----------------------------------------------------------------------         * CkGraph_ReleaseHashedBitmap --      *      releases a list element, the Pixmap remains allocated,              *      if delete_after_use is 0 *----------------------------------------------------------------------         */   void CkGraph_ReleaseHashedBitmap(HBITMAP pixmap){  PixElem* pe;  //if(pixmapList==NULL)  //  return;  if((pe=FINDPIXMAP(pixmap))==NULL){    panic("Could not ReleaseHashedBitmap");  }  pe->used=0;  if(pe->delete_after_use){    RemovePixmap(pixmap);    DeletePixmap(pixmap);  }}/*                                                                               *----------------------------------------------------------------------         * CkGraph_FreeHashedBitmaps --  *      frees all allocated Pixmaps during termination of the program  *----------------------------------------------------------------------         */    void CkGraph_FreeHashedBitmaps(void){  while(pixmapList!=NULL){    HBITMAP pixmap=pixmapList->pixmap;    RemovePixmap(pixmap);    DeletePixmap(pixmap);  }  /*PixElem *curr;  for (curr = pixmapList; curr != NULL;) {    PixElem* temp=curr;    HBITMAP pixmap=temp->pixmap;    curr=curr->next;    RemovePixmap(pixmap);    DeletePixmap(pixmap);  }*/}/* *---------------------------------------------------------------------- * CkGraph_IsPixmap -- *	Returns TRUE if the drawable is a pixmap. *---------------------------------------------------------------------- */int CkGraph_IsPixmap(HANDLE drawable){  if((FINDPIXMAP(drawable))!=NULL)    return TRUE;  else    return FALSE;}#ifdef CKGRAPH_DEBUG/* * in this structure the handle of an gdi allocated is stored */typedef struct GdiObj {  char              *file;  int                line;  ClientData         handle;  int                type;  struct GdiObj *next;  struct GdiObj *prev;} GdiObj;/*  * in this List all gdi-allocated objects are stored */static GdiObj *gdiObjlistPtr = (GdiObj*)0;  static void CkGraphCreateObject(int type,ClientData handle,char* file,int line){  GdiObj* result = (GdiObj *)ckalloc(sizeof(GdiObj));  result->file   = file;  result->line   = line;  result->handle = handle;  result->type   = type;  result->next  = gdiObjlistPtr;  result->prev  = NULL;  if (gdiObjlistPtr != NULL)    gdiObjlistPtr->prev = result;  gdiObjlistPtr = result;}static GdiObj* CkGraphFindObject(int type,ClientData handle){   GdiObj* objPtr;   for (objPtr = gdiObjlistPtr ;objPtr;objPtr=objPtr->next)     if((objPtr->type==type && objPtr->handle==handle)||        (objPtr->type==CKOBJ_UNKNOWN && objPtr->handle==handle))       return objPtr;   return (GdiObj*)0;}static void CkGraphDeleteObject(int type,ClientData handle,char* file,int line){  GdiObj* objPtr;  if((objPtr=CkGraphFindObject(type,handle))==(GdiObj*)0){    if (!is_stockobject(type,(HGDIOBJ)handle)) {      dprintf("Could not find %s %8lx %s %d for delete\n",        obj_type(type),handle,file,line);      CkGraph_DumpActiveObjects(NULL);    }    return;  }  if (objPtr->next)      objPtr->next->prev = objPtr->prev;  if (objPtr->prev)      objPtr->prev->next = objPtr->next;  if (gdiObjlistPtr == objPtr)      gdiObjlistPtr = objPtr->next;  ckfree((char *) objPtr);}static int isDC (int type){  switch(type){    case CKOBJ_DC:    case CKOBJ_MEMDC:    case CKOBJ_METAFILE:    case CKOBJ_METADC:    case CKOBJ_ENHMETAFILE:    case CKOBJ_ENHMETADC:    return 1;  }  return 0;}#endif /*CKGRAPH_DEBUG*//* * per gdi-HDC there are all selected handles held in this structure * it enables the control over the selecting and destroying of objects */  #define MAXGDIOBJ 15typedef struct GdiContext {  int type; //type of DC can be:    //CKOBJ_DC;    //CKOBJ_MEMDC    //CKOBJ_METAFILE    //CKOBJ_METADC    //CKOBJ_ENHMETAFILE    //CKOBJ_ENHMETADC  HDC hdc;  HGDIOBJ hobjs[MAXGDIOBJ]; //selectable objects  HBITMAP defaultbitmap;  //HPALETTE defaultpalette;  int palettevalid;  int rop;  int bkmode;  int fillmode;  COLORREF bkcolor;  COLORREF textcolor;  HRGN hrgn;  int  hrgntype;  int  hrgn_xoff;  int  hrgn_yoff;  struct GdiContext *next;  struct GdiContext *prev;} GdiContext;static GdiContext *devHead = (GdiContext*)0;  /* List of allocated dcs */static GdiContext *currdc = (GdiContext*)0;  /* hashed dc */static void CkGraphCreateDeviceContext(int type,HDC hdc){  GdiContext* result = (GdiContext *)ckalloc(sizeof(GdiContext));  memset(result,0,sizeof(GdiContext));  result->type  = type;  result->hdc   = hdc;  result->textcolor   = CLR_INVALID;  result->bkcolor     = CLR_INVALID;  result->hrgn        = NULL;  result->hrgntype    = NULLREGION;  result->next  = devHead;  result->prev  = (GdiContext*)0;  if (devHead)    devHead->prev = result;  currdc = devHead = result;}#define FINDCONTEXT(_hdc) \  (currdc && currdc->hdc==(_hdc) ) ? currdc : CkGraphFindDeviceContext(_hdc)static GdiContext* CkGraphFindDeviceContext(HDC hdc){   GdiContext* devPtr;   //if(currdc && currdc->hdc==hdc)   //  return currdc;   for (devPtr = devHead ;devPtr;devPtr=devPtr->next)     if(devPtr->hdc==hdc){       return currdc=devPtr;   }   return (GdiContext*)0;}static void CkGraphDeleteDeviceContext(HDC hdc){  GdiContext* devPtr=FINDCONTEXT(hdc);  if(devPtr==(GdiContext*)0){#ifdef CKGRAPH_DEBUG    dprintf("Could not find 0x%x for delete\n",hdc);#endif    return;  }  if(currdc==devPtr)    currdc=(GdiContext*)0;  if (devPtr->next)      devPtr->next->prev = devPtr->prev;  if (devPtr->prev)      devPtr->prev->next = devPtr->next;  if (devHead == devPtr)      devHead = devPtr->next;  ckfree((char *) devPtr);}/* * checks if the GdiContext structures represent the actual state * in the DC's and prints out the state */typedef struct _SelectTest {  int type;  HGDIOBJ defobj;} SelectTest;void CkGraph_CheckDCs( char* fileName ) {  GdiContext* devPtr;  for (devPtr=devHead;devPtr!=NULL;devPtr=devPtr->next) {    int i;#define OBJCOUNT 6    SelectTest selTest[OBJCOUNT];     selTest[0].type=                CKOBJ_PEN ;    selTest[0].defobj=(HGDIOBJ)stock_NULL_PEN;    selTest[1].type=                CKOBJ_BRUSH ;    selTest[1].defobj=(HGDIOBJ)stock_NULL_BRUSH;    selTest[2].type=                       CKOBJ_PAL ;    selTest[2].defobj=(HGDIOBJ)stock_DEFAULT_PALETTE;    selTest[3].type=                  CKOBJ_FONT ;    selTest[3].defobj=(HGDIOBJ)stock_SYSTEM_FONT;    selTest[4].type=    CKOBJ_REGION ;    selTest[4].defobj=(HGDIOBJ)NULL;    selTest[5].type=                  CKOBJ_BITMAP ;    selTest[5].defobj=(HGDIOBJ)devPtr->defaultbitmap;    dprintf("%-12.12s 0x%8.8x\n",obj_type(devPtr->type),(int)devPtr->hdc);    for (i=0;i<OBJCOUNT;i++) {      HGDIOBJ hsel;      if(selTest[i].type==CKOBJ_PAL) {        hsel=(HGDIOBJ)SelectPalette(devPtr->hdc,selTest[i].defobj,TRUE);      } else {        hsel=SelectObject(devPtr->hdc,selTest[i].defobj);      }      dprintf("  %-12.12s 0x%8.8x %s\n",obj_type(selTest[i].type),hsel,               is_stockobject(selTest[i].type,hsel)?"stockobj":"");      if(devPtr->hobjs[selTest[i].type]!=0 &&           hsel!=devPtr->hobjs[selTest[i].type]) {        /*         * the actual selected object is not the one we expect         */        dprintf("    %-12.12s 0x%8.8x was expected\n","ERROR",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -