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

📄 strview.c

📁 汉字在计算机内存放分为两种情况
💻 C
字号:
#include <gendef.h>
#include <osg.h>
#include "strview.h"


#ifndef NULL
#define NULL 0
#endif

typedef void (*DrawFunc)(void * ,int ,int ,int ,int ,int ,int );

void DrawStrViewText(void *tp,int x,int y ,int index,int color)
{      
	
	 pSTRVIEW pview  = (pSTRVIEW )tp;
	 char *p = GetStrViewData(pview,index);
         char buf[60];
	 if(p)
 	 {
 	        sprintf(buf,"%d. %s",index,p);
        	FNTDrawText(color,0,x,y,buf);/*0:画16位字体,1:24位字体*/
 	 }
	
 
}

 void DrawStrViewCell(void *p,int x,int y,int width,int high,int index,int color)
 {
 	
 	 pSTRVIEW pview  = (pSTRVIEW )p;
 	 
 	 GFMDrawRectangle(x,y  ,width,high ,3,1);
	 if(pview->locked || pview->cellnum <=0 ) return ;
 	 if(pview->cellnum <=0) return ;
 	 
	 if(index - pview->baseindex == pview->coursory)
	   DrawStrViewText(pview,x + 10,y+ 5, index,218);/*是焦点项的话画出黄色字体*/
	 else
	   DrawStrViewText(pview,x + 10,y+5 , index,0);

 

}

 void DrawStrViewFrame(pSTRVIEW pview)
 { 
	 DrawFunc  DrawCellFunc;
	int i;
	if(pview->locked) return ;

	if(pview->OwnerDrawCell)
		DrawCellFunc = pview->OwnerDrawCell;
	else
		DrawCellFunc = DrawStrViewCell;

    
	 /*绘画框架*/
	/* GFMDrawRectangle(pview->localx,pview->localy  ,
		  pview->width, pview->high ,3,1);
	
	 /*绘画单元*/
	 for( i = 0 ;i < pview->ospnum;i++)
	 {
		 if( i == pview->coursory)
		  (*DrawCellFunc)(pview, pview->localx,pview->localy + pview->cellhigh * i,/*	焦点状态CELL*/
		        pview->cellwidth,pview->cellhigh  ,pview->baseindex + i,4);
		 else if(pview->baseindex + i >= pview->cellnum)/*消除不存再的单元画面*/
			GFMDrawRectangle( pview->localx,pview->localy + pview->cellhigh * i,/*	焦点状态CELL*/
			pview->width, pview->cellhigh,4,1); 
		 else
		  (*DrawCellFunc)(pview,pview->localx,pview->localy + pview->cellhigh * i,/*一般状态CELL*/
			 pview->cellwidth,pview->cellhigh,pview->baseindex + i,5); 
	 }
 
 }


void     ShowStrView( pSTRVIEW pview)
{

  if(pview->OwnerDrawFrame)
	  (*pview->OwnerDrawFrame)(pview);
  else
	  DrawStrViewFrame(pview);

}

 pSTRVIEW CreateStrView(int x,int y,int width,int high,int ospnum,int itemnum,int ptrmode)/*prtmode:是否建立指针缓冲*/
 {
     	 pSTRVIEW p  = (pSTRVIEW)malloc(sizeof(STRVIEW));
	 memset(p,0,sizeof(STRVIEW));
	 p->localx = x;
	 p->localy = y;
	 p->width = width;
	 p->high = high;
	 p->cellwidth = width;
	 p->cellhigh = high / ospnum;
	 p->ospnum =  ospnum;
	 p->itemmode = ptrmode; 
	 p->strlist = CreateStrList(itemnum);
	 p->coursory = -1;
	   
	 if(!p->strlist)
	 {
	    free(p);
		return NULL;
	 }
	 return p;
 }

 void      DeleteStrView(pSTRVIEW pview)
 {
	 DeleteStrList(pview->strlist);
	 free(pview);
 }

 void     FreeStrViewtItems(pSTRVIEW pview)
{
	 FreeStrListItems(pview->strlist);
	 pview->cellnum = 0;
	 pview->baseindex  = 0;
	 pview->coursory = 0;
	  
}

 int  MoveStrViewCursor(pSTRVIEW pview,int xstep,int ystep)
 {
         int realy;/*画回*/
         int index;
	 DrawFunc  DrawCellFunc;
     	
     	 if(!pview||pview->locked || pview->cellnum <=0 ) 
     	 return -1;
     	
     	 if(pview->OwnerDrawCell)  /*有自绘函数则选择自绘*/
     	     DrawCellFunc = pview->OwnerDrawCell;
     	 else
     	     DrawCellFunc =  DrawStrViewCell;
     	     
     	 realy =   pview->coursory * pview->cellhigh + pview->localy;
     	 index =   pview->coursory  + pview->baseindex;
     	 pview->coursory += ystep;

     	 DrawCellFunc(pview,pview->localx,realy,/*一般状态CELL*/
			 pview->cellwidth,pview->cellhigh,index,5);
			  
	 if(pview->coursory + pview->baseindex >  pview->cellnum - 1)/*已经到ITEM极限*/
	 {
		 if((pview->cellnum % pview->ospnum) == 0)/*刚好满叶时*/
		 {
			pview->coursory = pview->ospnum -1;
			/*return pview->cellnum -1;*/
		 }else/*不满叶时*/
		 {
			pview->coursory  = pview->cellnum %pview->ospnum -1;
			
			pview->baseindex = pview->cellnum - (pview->cellnum % pview->ospnum); 
			/*return pview->baseindex + pview->coursory;*/
		 }
	 }
	
	 if(pview->coursory > pview->ospnum - 1)/*可以向前翻叶时翻叶*/
	 {
		 pview->coursory = 0;
		 pview->baseindex += pview->ospnum;
		 ShowStrView(pview);
		 return 1;
		/*return pview->baseindex + pview->coursory;*/
	 }

	 if(pview->coursory  < 0 && pview->baseindex > 0)/*可以向后翻叶时*/
	 { 
		 pview->baseindex -= pview->ospnum ;
		 pview->coursory = pview->ospnum -1;
		 ShowStrView(pview);
		 return 1;
                /* return pview->baseindex + pview->coursory;*/
	 }

	 if(pview->coursory < 0)/*向左移动光标到极限时*/
	 {
		 pview->coursory = 0;
		 /*return  pview->baseindex + pview->coursory;*/
	 }
 
 
         realy =   pview->coursory * pview->cellhigh + pview->localy;
     	
	 index =   pview->coursory  + pview->baseindex;
     	 DrawCellFunc(pview,pview->localx,realy,/*一般状态CELL*/
			 pview->cellwidth,pview->cellhigh,index,5);
     
	 return pview->baseindex + pview->coursory;
 }

 /*
 向LRLIST增加ITEM,若已经设定POINTER模式,只是简单的增加指针。
 */
 int       AddToStrViewEx(pSTRVIEW pview,char *data)
 {
 	
 	  if(!data) return;
 	  pview->cellnum++;
 	  if(pview->coursory< 0)
	     pview->coursory = 0;
	     
	  if( pview->itemmode == ITEM_NOD)
		return   AddStrListItem(pview->strlist,data);
	  else
        	return   AddStrPtrItem(pview->strlist,data);
 }
 
 int       AddToStrView(pSTRVIEW pview,char *data)
 {
	
	     
	   if(data)
 	  {
	     pview->cellnum++;
	     if((pview->cellnum - pview->baseindex) > (pview->ospnum))
	     {
	      pview->baseindex += pview->ospnum;
	      pview->coursory = 0; 
	     }
	     
	     
	  }else return;
	  
	 
	  if(pview->coursory< 0)
	     pview->coursory = 0;
	     
	  if( pview->itemmode == ITEM_NOD)
		return   AddStrListItem(pview->strlist,data);
	  else
        	return   AddStrPtrItem(pview->strlist,data);
 } 
 
 int ModifyStrViewItem(pSTRVIEW pview,char *data,int index)
 {
   return ModifyStrListItem(pview->strlist,data,index);	
 }
 
 int  InsertToStrView(pSTRVIEW pview,char *data,int cellx,int celly)
 {

	 return (int)data;
 }

										  										  
 void    DelFromStrView(pSTRVIEW pview,int index)
 {
 	
 	
 	 
 	 if(pview->cellnum <= 0)
 	 {
 	   pview->cellnum = 0;
 	   pview->coursory = -1;
	   return;
	 }
	
	 DeleteStrListItem(pview->strlist,index);
	 pview->coursory--;
	 pview->cellnum--;
	 
	 if( pview->coursory< 0 && pview->baseindex >= pview->ospnum)
	 {
	    pview->baseindex -= pview->ospnum;
	    if(pview->baseindex < 0) pview->baseindex  =0 ;
	    pview->coursory = (pview->ospnum -1);
	 }
	 else if(pview->coursory< 0 && pview->cellnum <=0)
	 {
	    pview->coursory = -1;
	    pview->cellnum = 0;   
	 }
	 else if(pview->coursory < 0 && pview->cellnum >= 1)
	    pview->coursory = 0;
	 
	
 }

 char *	 GetStrViewData(pSTRVIEW pview,int index)
 {
	 return GetStrItem(pview->strlist,index);
 }

 void	LockStrView(pSTRVIEW pview)
 {
	if(pview)
	 pview->locked = 1;
 }
 void   UnLockStrView(pSTRVIEW pview)
{
	if(pview)
	pview->locked = 0;
}

int     IsStrViewLocked(pSTRVIEW pview)
{
	if(pview)
	return pview->locked;
}
                           

⌨️ 快捷键说明

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