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

📄 apron.c

📁 这是一个在Brew环境下开发的SVG矢量图播放器
💻 C
📖 第 1 页 / 共 5 页
字号:
  FALSE     : On Failure.

SIDE EFFECTS
  None.
======================================================================*/
static boolean apron_DisplayContentMenu(
    apron * pMe)
{
    return (apron_SVGViewerCore(pMe, APRON_EVENT_TIMEOUT, EVT_USER, 0, 0));
}

/*======================================================================
FUNCTION
  apron_BuildContentMenu

DESCRIPTION
  This function prepares the menu with all the supported content files 
  present in the content directory.

DEPENDENCIES
  The function fails when there is more than permissible number of 
  Content in the Content Directory.

PARAMETERS
  pMe         [in] : Pointer to Application's structure.
  contentDir  [in] : Pointer to the Content Directory.

RETURN VALUE
  TRUE  : On Success.
  FALSE : On Failure,
            1. Content Directory does not exist.
            2. No Content in the Content Directory.
            3. Presence of more than the permissible number of 
                Content in the Content Directory.
            4. Memory allocation failure.

SIDE EFFECTS
  The Application exits when this function fails.
======================================================================*/
static boolean apron_BuildContentMenu(
    apron * pMe,
    char *  contentDir)
{
    uint16        numFiles        = 0;
    uint16        contentCount    = 0;
    CtlAddItem    controlItem     = {0};
    AEEFileInfoEx fileInfo        = {0};
    AECHAR *      fileNameInWide  = NULL;
    char *        fileName        = NULL;
    char *        fullFileName    = NULL;
    char fileXtn[APRON_FILE_EXTENSION_LENGTH] = {0};

    if(SUCCESS != ISHELL_CreateInstance(pMe->pShell, AEECLSID_FILEMGR, (void**)(&pMe->pFileMgr)))
    {
        DBGPRINTF("Apron: FileMgr CreateInstance Failed");
        return (FALSE);
    }

    //TODO: Can use int IFILEMGR_Test(IFileMgr * pIFileMgr, const char * pszName)
    if(SUCCESS  != IFILEMGR_EnumInit(pMe->pFileMgr, contentDir, FALSE))
    {
        DBGPRINTF("Apron: Could not initialize FileMgr with the ContentDirectory");

        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;
        return (FALSE);
    }

    fullFileName = MALLOC(APRON_MAX_FILE_NAME * sizeof(char));
    if(NULL == fullFileName)
    {           
        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;

        return (FALSE);
    }

    // Enumerate all music files and add them to menu
    fileNameInWide = MALLOC(APRON_MAX_FILE_NAME * sizeof(AECHAR));
    if(NULL == fileNameInWide)
    {
        FREEIF(fullFileName);

        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;

        return (FALSE);
    }

    fileName = MALLOC(APRON_MAX_FILE_NAME * sizeof(char));
    if(NULL == fileName)
    {
        FREEIF(fullFileName);
        FREEIF(fileNameInWide);

        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;

        return (FALSE);
    }

    contentCount = apron_GetContentCount(pMe->pFileMgr, contentDir);
    if((APRON_MAX_CONTENT_FILES < contentCount) ||
            (0 == contentCount))
    {
        DBGPRINTF("Apron: Number of content files in ContentDirectory: %d", contentCount);
        FREEIF(fileName);
        FREEIF(fileNameInWide);
        FREEIF(fullFileName);
        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;
        return (FALSE);
    }

    pMe->contentInfo.ppFileNames = MALLOC(contentCount * APRON_MAX_FILE_NAME);
    if(NULL == pMe->contentInfo.ppFileNames)
    {
        FREEIF(fileName);
        FREEIF(fileNameInWide);
        FREEIF(fullFileName);
        IFILEMGR_Release(pMe->pFileMgr);
        pMe->pFileMgr = NULL;
        return (FALSE);
    }

    // Set Title
    IMENUCTL_SetTitle(pMe->pContentMenu, APRON_RES_FILE, IDS_CONTENT_MENU_TITLE, NULL);

    // Default Items in the Menu  
    controlItem.pImage      = NULL;
    controlItem.pszResImage = APRON_RES_FILE;
    controlItem.pszResText  = NULL; /* No Resource File for Filenames */
    controlItem.wText       = 0;    /* No Resource ID for Filenames */
    controlItem.wFont       = AEE_FONT_NORMAL;
    controlItem.dwData      = IDF_ALIGN_LEFT;

    //Initialize Structure
    MEMSET(&fileInfo, 0, sizeof(AEEFileInfoEx));
    fileInfo.nStructSize  = sizeof(AEEFileInfoEx);
    fileInfo.pszFile      = fullFileName;
    fileInfo.nMaxFile     = APRON_MAX_FILE_NAME;

    numFiles = 0;  

    while((APRON_MAX_CONTENT_FILES > numFiles) &&
            (TRUE == IFILEMGR_EnumNextEx(pMe->pFileMgr, &fileInfo)))
    {
        apron_GetFileNameAndExtension(fileInfo.pszFile, fileName, fileXtn);

        if(TRUE == apron_IsContentTypeSupported(fileXtn))
        {
            STRNCPY((char *)((int)pMe->contentInfo.ppFileNames + (numFiles * APRON_MAX_FILE_NAME)), 
                    fileInfo.pszFile, APRON_MAX_FILE_NAME);
            STRTOWSTR(fileName, fileNameInWide, APRON_MAX_FILE_NAME);

            controlItem.pText   = fileNameInWide;
            controlItem.wImage  = apron_GetContentTypeIconResId(fileXtn);
            controlItem.wItemID = numFiles;
            numFiles++;

            IMENUCTL_AddItemEx(pMe->pContentMenu, &controlItem);
        }
    }

    pMe->contentInfo.numFiles = numFiles;

    FREEIF(fileName);
    FREEIF(fileNameInWide);
    FREEIF(fullFileName);
    IFILEMGR_Release(pMe->pFileMgr);
    pMe->pFileMgr = NULL;

    if(0 == numFiles)
    {
        DBGPRINTF("Apron: No content in ContentDirectory");    
        return (FALSE);
    }else
    {
        return (TRUE);
    }
}


/*======================================================================
FUNCTION
  apron_GetFileNameAndExtension

DESCRIPTION
  This function extracts the File Name & File Extension from the File 
  Name with complete path information 

DEPENDENCIES
  The function uses the following definitions:
    1. APRON_FILE_NAME_EXTENSION_SEPERATOR
    2. APRON_FILE_EXTENSION_LENGTH
    3. APRON_MAX_FILE_NAME 
    4. APRON_DIRECTORY_FILE_NAME_SEPERATOR 

PARAMETERS
  fileNameWithXtn  [in] : Pointer to File Name with complete path
  fileName        [out] : Pointer to File Name only
  fileXtn         [out] : Pointer to File Extension only

RETURN VALUE
  TRUE  : Always.

SIDE EFFECTS
  None.
======================================================================*/
static boolean apron_GetFileNameAndExtension(
    char * fileNameWithXtn,
    char * fileName,
    char * fileXtn)
{
    char *  pText               = NULL;
    int     fileNameWithXtnLen  = 0;
    int     fileXtnLen          = 0;

    pText = STRRCHR(fileNameWithXtn, APRON_FILE_NAME_EXTENSION_SEPERATOR);
    if(NULL != pText)
    {
        ++pText;
    }

    if(NULL == pText)
    {
        STRLCPY(fileXtn, fileNameWithXtn, APRON_FILE_EXTENSION_LENGTH);
        STRLCPY(fileName, fileNameWithXtn, APRON_MAX_FILE_NAME);
        return (TRUE);
    }

    STRLCPY(fileXtn, pText, APRON_FILE_EXTENSION_LENGTH);

    pText = NULL;
    pText = STRRCHR(fileNameWithXtn, APRON_DIRECTORY_FILE_NAME_SEPERATOR);
    if(NULL != pText)
    {
        ++pText;
    }

    if(NULL == pText)
    {    
        STRLCPY(fileName, fileNameWithXtn, APRON_MAX_FILE_NAME);
        return (TRUE);
    }

    STRLCPY(fileName, pText, APRON_MAX_FILE_NAME);

    fileNameWithXtnLen  = STRLEN(fileName);
    fileXtnLen          = STRLEN(fileXtn);

    //INFO: Accounting for '.'
    fileXtnLen++;
    fileName[fileNameWithXtnLen - fileXtnLen] = '\0';

    return (TRUE);
}

/*======================================================================
FUNCTION
  apron_IsContentTypeSupported

DESCRIPTION
  This function checks for the support of a File Extension 

DEPENDENCIES
  The function uses the following definitions:
    1. APRON_FILE_EXTENSION_LENGTH
    2. APRON_SUPPORTED_FILE_TYPES

PARAMETERS
  fileXtn [in] : Pointer to File Extension 

RETURN VALUE
  TRUE  : When the File Extension is supported.
  FALSE : When the File Extension isn't supported.

SIDE EFFECTS
  None.
======================================================================*/
static boolean apron_IsContentTypeSupported(
    char * fileXtn)
{
    char  fileTypes[][APRON_FILE_EXTENSION_LENGTH] = APRON_SUPPORTED_FILE_TYPES;
    int   count   = 0;
    int   maxType = (sizeof(fileTypes) / APRON_FILE_EXTENSION_LENGTH);

    for(count = 0; count < maxType; count++)
    {
        if(0 == STRCMP(fileTypes[count], fileXtn))
        {
            return (TRUE);
        }
    }

    return (FALSE);
}

/*======================================================================
FUNCTION
  apron_IsContentTypeSupported

DESCRIPTION
  This function returns the Resource Identifier of the Content Type Icon
  corresponding to the File Extension. If there isn't any corresponding
  Content Type Icon corresponding to the File Extension, Resource 
  Identifier of Unknown Content Type Icon is returned.

DEPENDENCIES
  The function uses the following Resource Identifiers:
    1. IDO_CONTENT_ICON_SVGZ
    2. IDO_CONTENT_ICON_SVG
    3. IDO_CONTENT_ICON_UNKNOWN

PARAMETERS
  fileXtn [in] : Pointer to File Extension 

RETURN VALUE
  uint16 : The Resource Identifier of the Content Type Icon.

SIDE EFFECTS
  None.
======================================================================*/
static uint16 apron_GetContentTypeIconResId(
    char * fileXtn)
{
    if(0 == STRCMP("svg", fileXtn))
    {
        return (IDO_CONTENT_ICON_SVG);
    }else if(0 == STRCMP("svgz", fileXtn))
    {
        return (IDO_CONTENT_ICON_SVGZ);
    }else 
    {
        return (IDO_CONTENT_ICON_UNKNOWN);
    } 
}

/*======================================================================
FUNCTION
  apron_SetAllMenuProperties

DESCRIPTION
  This function sets the properties of all displayable items of the
  Application.

DEPENDENCIES
  The function uses the following definitions:
    1. APRON_STATUS_MENU_HEIGHT

PARAMETERS
  pMe [in] : Pointer to the Application's structure 

RETURN VALUE
  TRUE : Always.

SIDE EFFECTS
  None.
======================================================================*/
static boolean apron_SetAllMenuProperties(
    apron * pMe)
{
    //TODO: Set Colors
    AEEItemStyle  rNormalStyle;
    AEEItemStyle  rSelStyle;
    AEERect       contextMenuRect;
    AEERect       otherMenuRect;

    contextMenuRect.x    = pMe->screenRect.x;
    contextMenuRect.y    = (int16)(pMe->screenRect.y + pMe->screenRect.dy + APRON_STATUS_MENU_HEIGHT);
    contextMenuRect.dx   = pMe->screenRect.dx;
    contextMenuRect.dy   = (int16)APRON_CONTEXT_MENU_HEIGHT;

    otherMenuRect.x   = pMe->screenRect.x;
    otherMenuRect.y   = pMe->screenRect.y;
    otherMenuRect.dx  = pMe->screenRect.dx;
    otherMenuRect.dy  = (int16)(pMe->screenRect.dy + APRON_STATUS_MENU_HEIGHT);

    ISTATIC_SetRect(pMe->pReadOnlyMenu, &otherMenuRect);
    IMENUCTL_SetRect(pMe->pOptionsMenu, &otherMenuRect);
    IMENUCTL_SetRect(pMe->pContentMenu, &otherMenuRect);
    IMENUCTL_SetRect(pMe->pContextMenu, &contextMenuRect);

    //Define Properties
    ISTATIC_SetProperties(pMe->pReadOnlyMenu, (ST_NOSCROLL | ST_ASCII));
    IMENUCTL_SetProperties(pMe->pOptionsMenu, (MP_WRAPSCROLL | (IMENUCTL_GetProperties(pMe->pOptionsMenu))));
    IMENUCTL_SetProperties(pMe->pContentMenu, (MP_WRAPSCROLL | (IMENUCTL_GetProperties(pMe->pContentMenu))));
    IMENUCTL_SetProperties(pMe->pContextMenu, (MP_WRAPSCROLL | (IMENUCTL_GetProperties(pMe->pContextMenu))));

    //Define Style
    ISHELL_GetItemStyle(pMe->pShell, AEE_IT_MENU, &rNormalStyle, &rSelStyle);

    rNormalStyle.roImage  = AEE_RO_TRANSPARENT;
    rSelStyle.roImage     = AEE_RO_TRANSPARENT;

    IMENUCTL_SetStyle(pMe->pOptionsMenu, &rNormalStyle, &rSelStyle );
    IMENUCTL_SetStyle(pMe->pContentMenu, &rNormalStyle, &rSelStyle );
    IMENUCTL_SetStyle(pMe->pContextMenu, &rNormalStyle, &rSelStyle );

    ITEXTCTL_SetMaxSize(pMe->pTextInputMenu, 5); //TODO: FIXTHIS

    return (TRUE);
}

/*======================================================================
FUNCTION
  apron_AppStart

DESCRIPTION
  This function is called by the Application's Event handler when the 
  Application starts.

  This function calls the State Handling functions with StatUp event.

⌨️ 快捷键说明

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