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

📄 folderctrl.cpp

📁 funambol window mobile客户端源代码
💻 CPP
字号:
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#include "stdafx.h"
#include "FolderCtrl.h"
#include "ui.h"
#include "afxcmn.h"

#include <list>
using namespace std;


#if defined(WIN32_PLATFORM_PSPC)
// Pocket PC platform

#include <windows.h>
#include <tchar.h>
#include <commctrl.h>


//Globals
HIMAGELIST himl;            // handle of the image list
HINSTANCE g_hInstance = NULL;

/*
GetDirectoryContents(HWND, LPTSTR, HTREEITEM)
   PARAMETERS:
       hwndTV          - TreeView to add the contents to
       pszDirectory    - Path of the directory to list the contents for
       htiParent       - TreeView item to add the contents as children of
*/
BOOL GetDirectoryContents(HWND hwndTV, LPTSTR pszDirectory,
                          HTREEITEM htiParent)
{
    WIN32_FIND_DATA findData;
    HANDLE fileHandle;
    BOOL fInserted = FALSE;
    DWORD       dwError;

    __try
    {
        // Get the first file in the directory
        fileHandle = FindFirstFile(pszDirectory, &findData);
        if (fileHandle != INVALID_HANDLE_VALUE)
        {
            if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                if (!AddItemToTree(hwndTV, findData.cFileName, htiParent,TRUE))
                    __leave;

            // Loop on all remaining entries in the directory
            while (FindNextFile(fileHandle, &findData))
            {
                if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    if (!AddItemToTree(hwndTV, findData.cFileName, htiParent, TRUE))
                        __leave;
            }
        } else {
            if ( ERROR_NO_MORE_FILES == (dwError=GetLastError()))
            {
                TV_ITEM         tvi;
                tvi.hItem = htiParent;
                tvi.mask = TVIF_CHILDREN;
                tvi.cChildren = 0;
            }
        }
        // All done, everything worked.
        fInserted = TRUE;
    }
    __finally
    {
        if (fileHandle != INVALID_HANDLE_VALUE )
            FindClose(fileHandle);
    }
    return (fInserted);
}



HTREEITEM AddItemToTree(HWND, LPTSTR, HTREEITEM, BOOL);

/*
InitTreeViewImageLists(HWND)
  PARAMETERS:
      hwndTV  - Handle of the treeview that these image lists are being added to.
*/
BOOL InitTreeViewImageLists(HWND hwndTV)
{
    HBITMAP       hbmp;

    // Create the image list for the item pictures
    if ((himl = ImageList_Create(CX_BITMAP, CY_BITMAP, ILC_MASK, NUM_BITMAPS, 0))
        == NULL)
        return FALSE;

    hbmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_IMAGES));

    if (-1 == ImageList_AddMasked(himl, hbmp, RGB(0, 255, 0)))
    {
        return FALSE;
    }

    // Clean up the GDI objects
    DeleteObject(hbmp);

    // Fail if not all the images were added
    if (ImageList_GetImageCount(himl) < NUM_BITMAPS)
        return FALSE;

    // Associate the image list with the treeview control
    TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);

    return TRUE;
}



BOOL InitTreeViewItems(HWND hwndTV)
{
   //AddItemToTree(hwndTV, TEXT("\\"), NULL, TRUE);
   return TRUE;
}

/*
AddItemToTree(HWND, LPSTR, int, int)
      hwndTV     - handle of the treeview to add the item to
      lpszItem   - string to add to the tree
      htiParent  - handle of the tree item that will be this item's parent
      fDirectory - TRUE if this item is a directory
*/
HTREEITEM AddItemToTree(HWND hwndTV, LPTSTR lpszItem, HTREEITEM htiParent, BOOL fDirectory){
    TV_ITEM          tvi;
    TV_INSERTSTRUCT  tvins;
    HTREEITEM        hti;

    // Filter out the "." and ".." directories.
    if (!lstrcmpi(lpszItem, TEXT(".")) || !lstrcmpi(lpszItem, TEXT("..")))
        return (HTREEITEM)TRUE;

    // Start by initializing the structures
    memset(&tvi, 0, sizeof(TV_ITEM));
    memset(&tvins,0, sizeof(TV_INSERTSTRUCT));
    tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;

    // If it's a directory, add a child count so the expand button shows
    if (fDirectory)
    {
        tvi.mask |= TVIF_CHILDREN;
        tvi.cChildren = 1;
    }
    else
    {
        tvi.mask |= TVIF_CHILDREN;
        tvi.cChildren = 0;
    }

    // Set the text of the item
    tvi.pszText = lpszItem;
    tvi.cchTextMax = lstrlen(lpszItem);

    // Give the item the appropriate image
    //if (fDirectory){
    tvi.iSelectedImage = tvi.iImage = IMAGE_CLOSED;
    //}

    tvins.item = tvi;
    tvins.hInsertAfter = TVI_SORT;

    // Set the parent item based on the specified level
    if (!htiParent)
        tvins.hParent = TVI_ROOT;
    else
        tvins.hParent = htiParent;

    // Add the item to the tree view control
    hti = (HTREEITEM) SendMessage(hwndTV, TVM_INSERTITEM, 0,
        (LPARAM)(LPTV_INSERTSTRUCT) &tvins);

    return hti;
}

/*
BuildDirectory(HWND, TV_ITEM, LPTSTR)
      hwndTV  - handle of the treeview control
      tvi     - item to build the path for
      lpszDir - string to place the path into
*/
BOOL BuildDirectory(HWND hwndTV, TV_ITEM tvi, LPTSTR lpszDir)
{
    HTREEITEM hti;
    LPTSTR sz0, sz1;

    // Allocate memory for the temp strings
    sz0 = (LPTSTR) LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT,sizeof(TCHAR) * MAX_PATH);
    sz1 = (LPTSTR) LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT,sizeof(TCHAR) * MAX_PATH);
    // Get the text for the first item
    tvi.mask |= TVIF_TEXT;
    tvi.pszText = sz0;
    tvi.cchTextMax =  MAX_PATH;

    if (!TreeView_GetItem(hwndTV, &tvi))
        return (FALSE);

    // Create the initial string
    wsprintf(sz1, TEXT("%s"), tvi.pszText);
    lstrcpy(lpszDir, sz1);

    hti = tvi.hItem;

    // Now add the parent directories if any
    while (hti = TreeView_GetParent(hwndTV, hti))
    {
        tvi.mask = TVIF_TEXT;
        tvi.hItem = hti;
        if (!TreeView_GetItem(hwndTV, &tvi))
            return (FALSE);

        lstrcpy(sz1, lpszDir);
        if (wcscmp(tvi.pszText,TEXT("\\")) == 0) //we are at the root.
            wsprintf(lpszDir, TEXT("%s%s"), tvi.pszText, sz1);
        else
            wsprintf(lpszDir, TEXT("%s\\%s"), tvi.pszText, sz1);
    }

    // Add the wildcard needed for FindFirstFile()
    lstrcpy(sz1, lpszDir);
    if (wcscmp(sz1,TEXT("\\")) == 0) //we are at the root.
        wsprintf(lpszDir, TEXT("%s*.*"), sz1);
    else
        wsprintf(lpszDir, TEXT("%s\\*.*"), sz1);

    LocalFree(sz0);
    LocalFree(sz1);

    return (TRUE);
}

#endif


#if defined(WIN32_PLATFORM_WFSP)
// Smartphone platform
void AddItemToList(CListBox* list1, CString item)
{
    if (!lstrcmpi(item, TEXT(".")) )
        return ;
    list1->AddString(item);
}

BOOL InitListViewItems(CListBox* list1)
{
    AddItemToList(list1, TEXT("\\"));
    return TRUE;
}


BOOL GetDirectoryContents( CListBox* list1, LPTSTR pszDirectory)
{
    WIN32_FIND_DATA findData;
    HANDLE fileHandle;
    BOOL fInserted = FALSE;

    // TODO: ...
    if( wcscmp(pszDirectory,  _T("*")))
        AddItemToList(list1, _T(".."));
    // Get the first file in the directory
    fileHandle = FindFirstFile(pszDirectory, &findData);
    if (fileHandle != INVALID_HANDLE_VALUE)
    {
        if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            AddItemToList(list1, findData.cFileName);
        // Loop on all remaining entries in the directory
        while (FindNextFile(fileHandle, &findData))
        {
            if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    AddItemToList( list1, findData.cFileName);
        }
    }
    else
    {
        // All done, everything worked.
        fInserted = TRUE;
    }

    if (fileHandle != INVALID_HANDLE_VALUE )
        FindClose(fileHandle);

    return (fInserted);
}

BOOL BuildDirectory(list<CString> path, CString& outString)
{
    outString = _T("");
    list<CString>::const_iterator it;
    for(it=path.begin(); it!=path.end(); ++it)
        outString += (CString)*it;
    if(outString == "")
        outString = "\\";
    return TRUE;
}
#endif


⌨️ 快捷键说明

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