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

📄 listedit.c

📁 在uc_GUI中增加的列表编辑框list_edit源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                                uC/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed
*              in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File        : LISTEDIT.c
Purpose     : Implementation of listview widget
---------------------------END-OF-HEADER------------------------------
modify by fzz 20060119
*/

//#include	"conio.h"
//#include    "stdio.h"

#include "GUI_ARRAY.h"
#include <stdlib.h>
#include <string.h>
#include "LISTEDIT_Private.h"
#include "HEADER.h"
#include "WIDGET.h"
#include "SCROLLBAR.h"
#include "GUIDebug.h"
#include "GUI_Protected.h"
#include "WM_Intern.h"

#if GUI_WINSUPPORT

/*********************************************************************
*
*       Private config defaults
*
**********************************************************************
*/

/* Define default fonts */
#ifndef LISTEDIT_FONT_DEFAULT
  #define LISTEDIT_FONT_DEFAULT &GUI_Font13_1
#endif

/* Define colors */
#ifndef LISTEDIT_BKCOLOR0_DEFAULT
  #define LISTEDIT_BKCOLOR0_DEFAULT GUI_WHITE     /* Not selected */
#endif

#ifndef LISTEDIT_BKCOLOR1_DEFAULT
  #define LISTEDIT_BKCOLOR1_DEFAULT GUI_GRAY      /* Selected, no focus */
#endif

#ifndef LISTEDIT_BKCOLOR2_DEFAULT
  #define LISTEDIT_BKCOLOR2_DEFAULT GUI_BLUE      /* Selected, focus */
#endif

#ifndef LISTEDIT_BKCOLOR3_DEFAULT
  #define LISTEDIT_BKCOLOR3_DEFAULT GUI_GREEN     /* Selected, focus Colum  */
#endif

#ifndef LISTEDIT_TEXTCOLOR0_DEFAULT
  #define LISTEDIT_TEXTCOLOR0_DEFAULT GUI_BLACK   /* Not selected */
#endif

#ifndef LISTEDIT_TEXTCOLOR1_DEFAULT
  #define LISTEDIT_TEXTCOLOR1_DEFAULT GUI_WHITE   /* Selected, no focus */
#endif

#ifndef LISTEDIT_TEXTCOLOR2_DEFAULT
  #define LISTEDIT_TEXTCOLOR2_DEFAULT GUI_WHITE   /* Selected, focus */
#endif

#ifndef LISTEDIT_TEXTCOLOR3_DEFAULT
  #define LISTEDIT_TEXTCOLOR3_DEFAULT GUI_BLACK   /* Selected, focus colum*/
#endif

#ifndef LISTEDIT_GRIDCOLOR_DEFAULT
  #define LISTEDIT_GRIDCOLOR_DEFAULT GUI_LIGHTGRAY
#endif

/* Define default alignment */
#ifndef LISTEDIT_ALIGN_DEFAULT
  #define LISTEDIT_ALIGN_DEFAULT (GUI_TA_VCENTER | GUI_TA_HCENTER)
#endif



/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
LISTEDIT_PROPS LISTEDIT_DefaultProps = {
  LISTEDIT_BKCOLOR0_DEFAULT,
  LISTEDIT_BKCOLOR1_DEFAULT,
  LISTEDIT_BKCOLOR2_DEFAULT,
  LISTEDIT_BKCOLOR3_DEFAULT,
  LISTEDIT_TEXTCOLOR0_DEFAULT,
  LISTEDIT_TEXTCOLOR1_DEFAULT,
  LISTEDIT_TEXTCOLOR2_DEFAULT,
  LISTEDIT_TEXTCOLOR3_DEFAULT,
  LISTEDIT_GRIDCOLOR_DEFAULT,
  LISTEDIT_FONT_DEFAULT
};

/*********************************************************************
*
*       Static routines
*
**********************************************************************
*/
/*********************************************************************
*
*       LISTEDIT__GetRowDistY
*/
unsigned LISTEDIT__GetRowDistY(const LISTEDIT_Obj* pObj) {
  unsigned RowDistY;
  if (pObj->RowDistY) {
    RowDistY = pObj->RowDistY;
  } else {
    RowDistY = GUI_GetYDistOfFont(pObj->Props.pFont);
    if (pObj->ShowGrid) {
      RowDistY++;
    }
  }
  return RowDistY;
}

/*********************************************************************
*
*       LISTEDIT__GetColDistY
*/
unsigned LISTEDIT__GetColDistX(const LISTEDIT_Obj* pObj,int col) 
{  
  return HEADER_GetItemWidth(pObj->hHeader,col);  
}

/*********************************************************************
*
*       _GetNumVisibleRows
*
* Purpose:
*   Returns the number of visible rows according the header
*   and (if exist) horizontal scrollbar.
*
* Return value:
*   Number of visible rows. If no entire row can be displayed, this
*   function will return one.
*/
static unsigned _GetNumVisibleRows(LISTEDIT_Handle hObj, const LISTEDIT_Obj* pObj) 
{
  unsigned RowDistY, ySize, r = 1;
  GUI_RECT Rect;
  WM_GetInsideRectExScrollbar(hObj, &Rect);
  ySize    = Rect.y1 - Rect.y0 + 1 - HEADER_GetHeight(pObj->hHeader);
  RowDistY = LISTEDIT__GetRowDistY(pObj);
  if (RowDistY) {
    r = ySize / RowDistY;
    r = (r == 0) ? 1 : r;
  }
  return r;
}

/*********************************************************************
*
*       _GetNumVisibleCols
*/
static unsigned _GetNumVisibleCols(LISTEDIT_Handle hObj, const LISTEDIT_Obj* pObj) 
{
  unsigned ColDistX=0, xSize;
  int i=0;
  GUI_RECT Rect;
  WM_GetInsideRectExScrollbar(hObj, &Rect);
  xSize    = Rect.x1 - Rect.x0 + 1 ;  
  for(i=pObj->ScrollStateH.v;i<HEADER_GetNumItems(pObj->hHeader);i++)
  {
	  ColDistX+=LISTEDIT__GetColDistX(pObj,i);  
	  if(ColDistX>xSize)
		  break;
  }
  return i-pObj->ScrollStateH.v;  
}


/*********************************************************************
*
*       _Paint
*/
static void _Paint(LISTEDIT_Handle hObj, LISTEDIT_Obj* pObj, WM_MESSAGE* pMsg) 
{	
  const GUI_ARRAY* pRow;
  int	OldColorIndex=0;
  GUI_RECT ClipRect, Rect;
  int  NumVisRows, NumRows, NumCols,NumVisCols;
  int LBorder, RBorder, EffectSize;
  int xPos, yPos, Width, RowDistY;//,ColDistX;
  int Align, i, j, EndRow,EndCol;
  // Init some values 
 // NumColumns = HEADER_GetNumItems(pObj->hHeader);
  NumRows    = GUI_ARRAY_GetNumItems(&pObj->RowArray);
  NumVisRows = _GetNumVisibleRows(hObj, pObj);
  NumCols    =  HEADER_GetNumItems(pObj->hHeader);
  NumVisCols = _GetNumVisibleCols(hObj, pObj); 
  RowDistY   = LISTEDIT__GetRowDistY(pObj);
  //ColDistX	 = LISTEDIT__GetColDistX(pObj,0);
  LBorder    = pObj->LBorder;
  RBorder    = pObj->RBorder;
  EffectSize = pObj->Widget.pEffect->EffectSize;
  yPos       = HEADER_GetHeight(pObj->hHeader) + EffectSize;
  EndRow     = pObj->ScrollStateV.v + (((NumVisRows + 1) > NumRows) ? NumRows : NumVisRows + 1);
  //xPos=0;
  EndCol     = pObj->ScrollStateH.v + (((NumVisCols + 1) > NumCols) ? NumCols : NumVisCols + 1);
  if(EndCol>NumCols)
	  EndCol=NumCols;
  if(EndCol<0)
	  EndCol=0;
  // Calculate clipping rectangle 
  ClipRect = *(const GUI_RECT*)pMsg->Data.p;
  GUI_MoveRect(&ClipRect, -pObj->Widget.Win.Rect.x0, -pObj->Widget.Win.Rect.y0);
  WM_GetInsideRectExScrollbar(hObj, &Rect);
  GUI__IntersectRect(&ClipRect, &Rect);
  // Set drawing color, font and text mode 
  LCD_SetColor(pObj->Props.aTextColor[0]);
  GUI_SetFont(pObj->Props.pFont);
  GUI_SetTextMode(GUI_TM_TRANS);
  // Do the drawing 
  for (i = pObj->ScrollStateV.v; i < EndRow; i++) 
  {
    pRow = (const GUI_ARRAY*)GUI_ARRAY_GetpItem(&pObj->RowArray, i);
    if (pRow) 
	{
      Rect.y0 = yPos;
      // Break when all other rows are outside the drawing area 
      if (Rect.y0 > ClipRect.y1) 
	  {
        break;
      }
      Rect.y1 = yPos + RowDistY - 1;
      // Make sure that we draw only when row is in drawing area 
      if (Rect.y1 >= ClipRect.y0) 
	  {
        int ColorIndex;
        // Set background color 
        if (i == pObj->RowSel) 
		{			
          ColorIndex = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 2 : 1;
        }
		else 
		{
          ColorIndex = 0;
        }
        LCD_SetBkColor(pObj->Props.aBkColor[ColorIndex]);
        // Iterate over all columns 
        if (pObj->ShowGrid) 
		{
          Rect.y1--;
        }
		{
			int tmpposx=0,l=0;
			for(l=0;l<pObj->ScrollStateH.v;l++)
			{
				tmpposx += HEADER_GetItemWidth(pObj->hHeader,l);
			}			
			xPos = EffectSize - tmpposx;
		}
		//xPos = EffectSize - pObj->ScrollStateH.v;
		OldColorIndex=ColorIndex;
        //for (j = pObj->ScrollStateH.v; j < EndCol; j++) 
		for (j = 0; j < EndCol; j++) 
		{
          Width   = HEADER_GetItemWidth(pObj->hHeader, j);
          Rect.x0 = xPos;
          // Break when all other columns are outside the drawing area 
          if (Rect.x0 > ClipRect.x1) 
		  {
            break;
          }
          Rect.x1 = xPos + Width - 1;
          // Make sure that we draw only when column is in drawing area 
          if (Rect.x1 >= ClipRect.x0) 
		  {
            LISTEDIT_ITEM * pItem;
            pItem = (LISTEDIT_ITEM *)GUI_ARRAY_GetpItem(pRow, j);
            if (pItem->hItemInfo) 
			{
			    LISTEDIT_ITEM_INFO * pItemInfo;
				pItemInfo = (LISTEDIT_ITEM_INFO *)GUI_ALLOC_h2p(pItem->hItemInfo);		
				if (j == pObj->ColSel && i==pObj->RowSel) 
				{			
					ColorIndex = 3;
				}
				else 
				{
					ColorIndex = OldColorIndex;
				}				
				LCD_SetBkColor(pItemInfo->aBkColor[ColorIndex]);
				LCD_SetColor(pItemInfo->aTextColor[ColorIndex]);
            }
			else 
			{
				if (j == pObj->ColSel && i==pObj->RowSel) 
				{			
					ColorIndex = 3;
				}
				else 
				{
					ColorIndex = OldColorIndex;
				}
				LCD_SetBkColor(pObj->Props.aBkColor[ColorIndex]);
				LCD_SetColor(pObj->Props.aTextColor[ColorIndex]);
            }
            // Clear background 
            GUI_ClearRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
            // Draw text 
            Rect.x0 += LBorder;
            Rect.x1 -= RBorder;
            Align = *((int*)GUI_ARRAY_GetpItem(&pObj->AlignArray, j));
			if (j == pObj->ColSel && i==pObj->RowSel)
				GUI_DispStringInRect(pObj->CurString, &Rect, Align);
			else
				GUI_DispStringInRect(pItem->acText, &Rect, Align);
			ColorIndex = OldColorIndex;			
			LCD_SetBkColor(pObj->Props.aBkColor[ColorIndex]);
			LCD_SetColor(pObj->Props.aTextColor[ColorIndex]);
            if (pItem->hItemInfo) 
			{
              LCD_SetBkColor(pObj->Props.aBkColor[ColorIndex]);
            }
          }
          xPos += Width;
        }		
        // Clear unused area to the right of items 
        if (xPos <= ClipRect.x1) 
		{
          GUI_ClearRect(xPos, Rect.y0, ClipRect.x1, Rect.y1);
        }
      }
      yPos += RowDistY;
    }
  }
  // Clear unused area below items 
  if (yPos <= ClipRect.y1) 
  {
	LCD_SetBkColor(pObj->Props.aBkColor[0]);
    GUI_ClearRect(ClipRect.x0, yPos, ClipRect.x1, ClipRect.y1);
  }
  // Draw grid 
  if (pObj->ShowGrid) {
    LCD_SetColor(pObj->Props.GridColor);
    yPos = HEADER_GetHeight(pObj->hHeader) + EffectSize - 1;
    for (i = 0; i < NumVisRows; i++) {
      yPos += RowDistY;
      // Break when all other rows are outside the drawing area 
      if (yPos > ClipRect.y1) {

⌨️ 快捷键说明

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