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

📄 multipage.c

📁 ucgui的3.98版本的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    WM_UNLOCK();
  } else {
    GUI_DEBUG_ERROROUT_IF(hObj==0, "MULTIPAGE_Create failed")
  }
  return hObj;
}

/*********************************************************************
*
*       Exported routines:  Page management
*
**********************************************************************
*/
/*********************************************************************
*
*       MULTIPAGE_AddPage
*/
void MULTIPAGE_AddPage(MULTIPAGE_Handle hObj, WM_HWIN hWin ,const char* pText) {
  MULTIPAGE_Obj* pObj;
  GUI_USE_PARA(hWin);
  if (hObj) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (!hWin) {
      /* If we get no handle we must find it. To do this, we search      */
      /* all children until we found one that has not yet become a page. */
      MULTIPAGE_PAGE* pPage;
      WM_HWIN hChild;
      WM_Obj* pChild;
      WM_Obj* pClient = WM_H2P(pObj->hClient);
      int i;
      for (hChild = pClient->hFirstChild; hChild && !hWin; hChild = pChild->hNext) {
        pChild = WM_H2P(hChild);
        hWin = hChild;
        for (i = 0; i < pObj->Handles.NumItems; i++) {
          pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, i);
          if (pPage->hWin == hChild) {
            hWin = 0;
            break;
          }
        }
      }
    } else {
      /* If we get a handle we must ensure that it was attached to the multipage */
      WM_AttachWindowAt(hWin, pObj->hClient, 0, 0);
    }
    if (hWin) {
      MULTIPAGE_PAGE Page;
      char NullByte = 0;
      if (!pText) {
        pText = &NullByte;
      }
      Page.hWin   = hWin;
      Page.Status = MULTIPAGE_STATE_ENABLED;
      if (GUI_ARRAY_AddItem(&pObj->Handles, &Page, sizeof(MULTIPAGE_PAGE) + strlen(pText)) == 0) {
        MULTIPAGE_PAGE* pPage;
        pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, pObj->Handles.NumItems - 1);
        memcpy(&pPage->acText, pText, strlen(pText) + 1);
      }
      MULTIPAGE_SelectPage(hObj, pObj->Handles.NumItems - 1);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_DeletePage
*/
void MULTIPAGE_DeletePage(MULTIPAGE_Handle hObj, unsigned Index, int Delete) {
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      if ((int)Index < pObj->Handles.NumItems) {
        WM_HWIN hWin;
        MULTIPAGE_PAGE* pPage;
        pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, Index);
        hWin = pPage->hWin;
        /* Remove the page from the multipage object */
        if (Index == pObj->Selection) {
          if (Index == ((unsigned)pObj->Handles.NumItems - 1)) {
            _ShowPage(pObj, Index - 1);
            pObj->Selection--;
          } else {
            _ShowPage(pObj, Index + 1);
          }
        } else {
          if (Index < pObj->Selection) {
            pObj->Selection--;
          }
        }
        GUI_ARRAY_DeleteItem(&pObj->Handles, Index);
        _UpdatePositions(hObj, pObj);
        /* Delete the window of the page */
        if (Delete) {
          WM_DeleteWindow(hWin);
        }
      }
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_SelectPage
*/
void MULTIPAGE_SelectPage(MULTIPAGE_Handle hObj, unsigned Index) {
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      if ((int)Index < pObj->Handles.NumItems) {
        if (_GetEnable(pObj, Index)) {
          if (Index != pObj->Selection) {
            /* Switch to page */
            _ShowPage(pObj, Index);
            pObj->Selection = Index;
            _UpdatePositions(hObj, pObj);
          } else {
            /* Page is already visible, so move at least the input focus to the page */
            MULTIPAGE_PAGE * pPage;
            pPage = (MULTIPAGE_PAGE *)GUI_ARRAY_GetpItem(&pObj->Handles, Index);
            WM_SetFocus(pPage->hWin);
          }
        }
      }
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_DisablePage
*/
void MULTIPAGE_DisablePage(MULTIPAGE_Handle hObj, unsigned Index) {
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      _SetEnable(pObj, Index, 0);
      WM_InvalidateWindow(hObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_EnablePage
*/
void MULTIPAGE_EnablePage(MULTIPAGE_Handle hObj, unsigned Index) {
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      _SetEnable(pObj, Index, 1);
      WM_InvalidateWindow(hObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       Exported routines:  Various methods
*
**********************************************************************
*/
/*********************************************************************
*
*       MULTIPAGE_SetText
*/
void MULTIPAGE_SetText(MULTIPAGE_Handle hObj, const char* pText, unsigned Index) {
  MULTIPAGE_Obj* pObj;
  if (hObj && pText) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      if ((int)Index < pObj->Handles.NumItems) {
        MULTIPAGE_PAGE* pPage;
        MULTIPAGE_PAGE Page;
        pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, Index);
        Page.hWin   = pPage->hWin;
        Page.Status = pPage->Status;
        if (GUI_ARRAY_SetItem(&pObj->Handles, Index, &Page, sizeof(MULTIPAGE_PAGE) + strlen(pText))) {
          pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, Index);
          memcpy(&pPage->acText, pText, strlen(pText) + 1);          
          _UpdatePositions(hObj, pObj);
        }
      }
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_SetBkColor
*/
void MULTIPAGE_SetBkColor(MULTIPAGE_Handle hObj, GUI_COLOR Color, unsigned Index) {
  MULTIPAGE_Obj* pObj;
  if (hObj && ((int)Index < MULTIPAGE_NUMCOLORS)) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      pObj->aBkColor[Index] = Color;
      WM_InvalidateWindow(hObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_SetTextColor
*/
void MULTIPAGE_SetTextColor(MULTIPAGE_Handle hObj, GUI_COLOR Color, unsigned Index) {
  MULTIPAGE_Obj* pObj;
  if (hObj && ((int)Index < MULTIPAGE_NUMCOLORS)) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      pObj->aTextColor[Index] = Color;
      WM_InvalidateWindow(hObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_SetFont
*/
void MULTIPAGE_SetFont(MULTIPAGE_Handle hObj, const GUI_FONT GUI_UNI_PTR * pFont) {
  MULTIPAGE_Obj* pObj;
  if (hObj && pFont) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      pObj->Font = pFont;
      _UpdatePositions(hObj, pObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_SetAlign
*/
void MULTIPAGE_SetAlign(MULTIPAGE_Handle hObj, unsigned Align) {
  MULTIPAGE_Obj* pObj;
  GUI_RECT rClient;
  if (hObj) {
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      pObj->Align = Align;
      _CalcClientRect(pObj, &rClient);
      WM_MoveTo(pObj->hClient, rClient.x0 + pObj->Widget.Win.Rect.x0,
                               rClient.y0 + pObj->Widget.Win.Rect.y0);
      _UpdatePositions(hObj, pObj);
    }
    WM_UNLOCK();
  }
}

/*********************************************************************
*
*       MULTIPAGE_GetSelection
*/
int MULTIPAGE_GetSelection(MULTIPAGE_Handle hObj) {
  int r = 0;
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      r = pObj->Selection;
    }
    WM_UNLOCK();
  }
  return r;
}

/*********************************************************************
*
*       MULTIPAGE_GetWindow
*/
WM_HWIN MULTIPAGE_GetWindow(MULTIPAGE_Handle hObj, unsigned Index) {
  WM_HWIN r = 0;
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      if ((int)Index < pObj->Handles.NumItems) {
        MULTIPAGE_PAGE* pPage;
        pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, Index);
        r = pPage->hWin;
      }
    }
    WM_UNLOCK();
  }
  return r;
}

/*********************************************************************
*
*       MULTIPAGE_IsPageEnabled
*/
int MULTIPAGE_IsPageEnabled(MULTIPAGE_Handle hObj, unsigned Index) {
  int r = 0;
  if (hObj) {
    MULTIPAGE_Obj* pObj;
    WM_LOCK();
    pObj = MULTIPAGE_H2P(hObj);
    if (pObj) {
      r = _GetEnable(pObj, Index);
    }
    WM_UNLOCK();
  }
  return r;
}

#else /* avoid empty object files */

void MULTIPAGE_C(void);
void MULTIPAGE_C(void){}

#endif  /* #if GUI_WINSUPPORT */


	 	 			 		    	 				 	  			   	 	 	 	 	 	  	  	      	   		 	 	 		  		  	 		 	  	  			     			       	   	 			  		    	 	     	 				  	 					 	 			   	  	  			 				 		 	 	 			     			 

⌨️ 快捷键说明

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