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

📄 listbox.lst

📁 Keil C下通过的UCGUI,UCGUI的移植源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
                  }
                } else {     /* Mouse moved out */
                  Notification = WM_NOTIFICATION_MOVED_OUT;
                }
                WM_NotifyParent(hObj, Notification);
                return 0;                        /* Message handled */
              }
              
              /*********************************************************************
              *
              *       Callback
              */
              static void _LISTBOX_Callback (WM_MESSAGE*pMsg) {
                LISTBOX_Handle hObj = pMsg->hWin;
                LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
                WM_SCROLL_STATE ScrollState;
                /* Let widget handle the standard messages */
                if (WIDGET_HandleActive(hObj, pMsg) == 0) {
                  return;
                }
                switch (pMsg->MsgId) {
                case WM_NOTIFY_PARENT:
                  switch (pMsg->Data.v) {
                  case WM_NOTIFICATION_VALUE_CHANGED:
                    WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
                    pObj->ScrollState.v = ScrollState.v;
                    WM_InvalidateWindow(hObj);
                    break;
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 7   

                  case WM_NOTIFICATION_SCROLLBAR_ADDED:
                    _SetScrollState(hObj);
                    break;
                  }
                  break;
                case WM_PAINT:
                  _Paint(hObj);
                  break;
                case WM_TOUCH:
                  if (_OnTouch(hObj, pObj, pMsg) == 0)
                    return;
                  break;
                case WM_DELETE:
                  _FreeAttached(pObj);
                  break;       /* No return here ... WM_DefaultProc needs to be called */
               case WM_KEY:
                  if ( ((WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0) {
                    int Key = ((WM_KEY_INFO*)(pMsg->Data.p))->Key;
                    switch (Key) {
                      case GUI_KEY_TAB:
                        break;                    /* Send to parent by not doing anything */
                      default:
                        LISTBOX_AddKey(hObj, Key);
                        return;
                    }
                  }
                  break;
                }
                WM_DefaultProc(pMsg);
              }
              
              /*********************************************************************
              *
              *       Exported routines:  Create
              *
              **********************************************************************
              */
              
              LISTBOX_Handle LISTBOX_CreateAsChild(
                const GUI_ConstString* ppText,
                WM_HWIN hWinParent,
                int x0, int y0, int xsize, int ysize, int Flags)
              {
                LISTBOX_Handle hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, 
                                                             hWinParent, Flags, _LISTBOX_Callback,
                                                             sizeof(LISTBOX_Obj)-sizeof(WM_Obj));
                if (hObj) {
                  LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
                  /* init widget specific variables */
                  WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED);
                  /* pObj->ppText = 0; */   /* Zero init not required */
                  pObj->pFont  = _pDefaultFont;
                  pObj->aBackColor[0] = LISTBOX_BKCOLOR0_DEFAULT;
                  pObj->aBackColor[1] = LISTBOX_BKCOLOR1_DEFAULT;
                  pObj->aBackColor[2] = LISTBOX_BKCOLOR2_DEFAULT;
                  pObj->aTextColor[0] = LISTBOX_TEXTCOLOR0_DEFAULT;
                  pObj->aTextColor[1] = LISTBOX_TEXTCOLOR1_DEFAULT;
                  pObj->aTextColor[2] = LISTBOX_TEXTCOLOR2_DEFAULT;
                  if (hObj && ppText) {
                    LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
                    INIT_ID(pObj);
                    /* init member variables */
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 8   

                    /* Check size */
                    if (!xsize) {
                      const GUI_FONT* pFontOld = GUI_SetFont(pObj->pFont);
                      int i;
                                  for (i=0; *(ppText+i); i++) {
                        int Size = GUI_GetStringDistX(*(ppText+i));
                        if (Size>xsize)
                                            xsize = Size;
                                  }
                      GUI_SetFont(pFontOld);
                          }
                    /* Set non-zero attributes */
                    LISTBOX_SetText(hObj, ppText);
                  }
                  _CalcScrollParas(hObj);
                }
                return hObj;
              }
              
              LISTBOX_Handle LISTBOX_Create(
                                  const GUI_ConstString* ppText,
                                  int x0, int y0, int xsize, int ysize, int Flags)
              {
                 return LISTBOX_CreateAsChild(ppText, WM_HWIN_NULL /*hWin*/, x0, y0, xsize, ysize, Flags);
              }
              
              LISTBOX_Handle LISTBOX_CreateIndirect(const GUI_WIDGET_CREATE_INFO* pCreateInfo, WM_HWIN hWinParent, int x
             -0, int y0, WM_CALLBACK* cb) {
                LISTBOX_Handle  hThis;
                GUI_USE_PARA(cb);
                hThis = LISTBOX_CreateAsChild(0,
                                              hWinParent,
                                              pCreateInfo->x0 + x0, 
                                              pCreateInfo->y0 + y0, 
                                              pCreateInfo->xSize, 
                                              pCreateInfo->ySize, 
                                              pCreateInfo->Flags);
                if (hThis) {
                  LISTBOX_Obj* pObj = LISTBOX_H2P(hThis);
                  INIT_ID(pObj);
                  pObj->Widget.Id     = pCreateInfo->Id;
                  pObj->Widget.State  = LISTBOX_STATE_INACTIVE;
                }
                return hThis;
              }
              
              /*********************************************************************
              *
              *       Exported routines:  Various methods
              *
              **********************************************************************
              */
              
              void LISTBOX_AddKey(LISTBOX_Handle hObj, int Key) {
                if (hObj) {
                  WM_LOCK();
                  switch (Key) {
                    case GUI_KEY_DOWN:
                      LISTBOX_IncSel(hObj);
                      break;
                    case GUI_KEY_UP:
                      LISTBOX_DecSel(hObj);
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 9   

                      break;
                    default:
                      _SelectByKey(hObj, Key);
                      break;
                  }
                  WM_UNLOCK();
                }
              }
              
              void LISTBOX_AddString(LISTBOX_Handle hObj, const char* s) {
                int len;
                WM_HMEM hNewItem, hNewBuffer;
                WM_HMEM *pOldBuffer;
                WM_HMEM *pNewBuffer;
                char* sNewString;
                LISTBOX_Obj* pObj;
                if (hObj && s) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  len = strlen(s);
                  if ((hNewItem = WM_ALLOC(len +1)) ==0) {
                    GUI_DEBUG_ERROROUT("LISTBOX_AddString failed to alloc buffer");
                  } else {
                    /* Add the new item to the buffer */
                    if ((hNewBuffer = WM_ALLOC(sizeof(WM_HMEM) * (pObj->NumItems + 1))) == 0) {
                      GUI_DEBUG_ERROROUT("LISTBOX_AddString failed to alloc buffer");
                      WM_FREE(hNewItem);
                    } else {
                      pNewBuffer = WM_HMEM2Ptr(hNewBuffer);
                      sNewString = WM_HMEM2Ptr(hNewItem);
                      strcpy(sNewString, s);
                      /* Copy contents of handle buffer (if any) */
                      if (pObj->haHandle) {
                        pOldBuffer = WM_HMEM2Ptr(pObj->haHandle);
                        memcpy(pNewBuffer, pOldBuffer, pObj->NumItems * sizeof(WM_HMEM));
                        WM_FREE(pObj->haHandle);
                      }
                      *(pNewBuffer + pObj->NumItems) = hNewItem;
                      pObj->haHandle = hNewBuffer;
                      pObj->NumItems++;
                    }
                  }
                  LISTBOX_Invalidate(hObj);
                  WM_UNLOCK();
                }
              }
              
              /*********************************************************************
              *
              *       LISTBOX_GetNumItems
              */
              int LISTBOX_GetNumItems(LISTBOX_Handle hObj) {
                int r = 0;
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  r = pObj->NumItems;
                  WM_UNLOCK();
                }
                return r;
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 10  

              }
              
              
              void LISTBOX_SetText(LISTBOX_Handle hObj, const GUI_ConstString* ppText) {
                int i;
                const char* s;
                if (hObj) {
                  WM_LOCK();
                  if (ppText) {
                    for (i = 0; (s = *(ppText+i)) != 0; i++) {
                      LISTBOX_AddString(hObj, s);
                    }
                  }
                  _CalcScrollParas(hObj);
                  LISTBOX_Invalidate(hObj);
                  WM_UNLOCK();
                }
              }
              
              void LISTBOX_SetFont(LISTBOX_Handle hObj, const GUI_FONT* pfont) {
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  pObj->pFont = pfont;
                  _CalcScrollParas(hObj);
                  LISTBOX_Invalidate(hObj);
                  WM_UNLOCK();
                }
              }
              
              
              void LISTBOX_SetBackColor(LISTBOX_Handle hObj, int index, GUI_COLOR color) {
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  pObj->aBackColor[index] = color;
                  LISTBOX_Invalidate(hObj);
                  WM_UNLOCK();
                }
              }
              
              void LISTBOX_SetTextColor(LISTBOX_Handle hObj, int index, GUI_COLOR color) {
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  pObj->aTextColor[index] = color;
                  LISTBOX_Invalidate(hObj);
                  WM_UNLOCK();
                }
              }
              
              void LISTBOX_SetSel (LISTBOX_Handle hObj, int Sel) {
                int NumItems, MaxSel;
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 11  

                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  NumItems = _GetNumItems(pObj);
                  MaxSel = NumItems ? NumItems-1 : 0;
                  if (Sel > MaxSel) {
                    Sel = MaxSel;
                  }
                  if (Sel != pObj->Sel) {
                    pObj->Sel = Sel;
                    LISTBOX_Invalidate(hObj);
                    WM_NotifyParent(hObj, WM_NOTIFICATION_SEL_CHANGED);
                  }
                  _CheckSel(hObj);
                  WM_UNLOCK();
                }
              }
              
              void LISTBOX_IncSel      (LISTBOX_Handle hObj) {
                int Sel = LISTBOX_GetSel(hObj);
                LISTBOX_SetSel(hObj, Sel+1);
              }
              
              void LISTBOX_DecSel      (LISTBOX_Handle hObj) {
                int Sel = LISTBOX_GetSel(hObj);
                if (Sel)
                        Sel--;
                LISTBOX_SetSel(hObj, Sel);
              }
              
              int  LISTBOX_GetSel (LISTBOX_Handle hObj) {
                int r = 0;
                LISTBOX_Obj* pObj;
                if (hObj) {
                  WM_LOCK();
                  pObj = LISTBOX_H2P(hObj);
                  ASSERT_IS_VALID_PTR(pObj);
                  r = pObj->Sel;
                  WM_UNLOCK();
                }
                return r;
              }
              
              void LISTBOX_SetDefaultFont(const GUI_FONT* pFont) {
                _pDefaultFont = pFont;
              }
              
              const GUI_FONT* LISTBOX_GetDefaultFont(void) {
                return _pDefaultFont;
              }
              
              #else                            /* Avoid problems with empty object modules */
 662            void LISTBOX_C(void) {}
 663          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =      1    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
C51 COMPILER V8.05a   LISTBOX                                                              04/11/2008 14:19:36 PAGE 12  

   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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