home *** CD-ROM | disk | FTP | other *** search
-
- #include <windows.h>
- #include <wininet.h>
- #include <commctrl.h>
- #include "comctlhd.h"
- #include "clist.h"
- #include "resource.h"
-
-
- TVNODEINFO gTVNodeInfo;
- CCommonCtrl::CCommonCtrl(HINSTANCE hInst, HWND hwndParent)
- {
- m_hInst = hInst;
- m_hWndParent = hwndParent;
- m_icount = 0;
- for (int i = 0; i < 10; i++)
- m_prootlvl[i]= NULL;
- return;
- }
-
- CCommonCtrl::~CCommonCtrl()
- {
- node *pnode;
- int i;
-
- for (i = 0; i < m_icount; i++)
- {
- if (NULL != m_prootlvl[i])
- {
- pnode = ((m_prootlvl[i])->getfirstnode());
- //close cached handle
- InternetCloseHandle(pnode->data.hConnect);
- m_prootlvl[i]->remove();
- delete m_prootlvl[i];
- }
- }
- for (i = 0; i < 2; i++)
- DeleteObject(m_hb[i]);
- ImageList_Destroy(m_himg);
-
- return;
- }
-
- //**********************************************************************
- // CCommonCtrl::ImageListInit
- //
- // Purpose: Initialize ImageList and its images
- // Parameters: None.
- // Return Value:
- // BOOL - TRUE if initialization succeeded, FALSE otherwise.
- //
- //********************************************************************
-
- BOOL CCommonCtrl::ImageListInit()
- {
-
- m_himg = ImageList_Create(13,13, ILC_COLOR16, 3, 0);
- if (NULL == m_himg)
- return FALSE;
- m_hb[0] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_LEAF));
- ImageList_Add(m_himg, m_hb[0], NULL);
- m_hb[1] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_OPEN));
- ImageList_Add(m_himg, m_hb[1], NULL);
- m_hb[2] = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_CLOSED));
- ImageList_Add(m_himg, m_hb[2], NULL);
-
- return TRUE;
-
- }
-
-
-
- //**********************************************************************
- // CCommonCtrl::TreeViewAdd
- //
- // Purpose: Wrapper for calling TreeView_Add macro
- // Parameters:
- // LPTSTR pszText - TreeView item text
- // LPTVDTA ptvdta - TreeView item (TV_ITEM) values
- // LPTVNODEINFO lptvnodei - Structure containing data associated
- // with a TreeView item whose pointer is stored in TV_ITEM.lParam
- // LPDWORD dwContext - context value which represents a pointer
- // to a TVNODEINFO structure to be used in asynchronous calls
- // Return Value:
- // HTREEITEM - handle to the TreeView item created
- //
- //********************************************************************
-
- HTREEITEM CCommonCtrl::TreeViewAdd(TCHAR *pszText, LPTVDATA ptvdta, LPTVNODEINFO ptvnodei, LPDWORD pdwContext)
- {
- HTREEITEM htvitem;
- TV_INSERTSTRUCT tvins;
- TV_ITEM tvi;
- LPTVNODEINFO ptv;
- int i, index = 0;
- BOOL finditem = FALSE;
-
- //set TV_ITEM values
- tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
- tvi.pszText = pszText;
- tvi.cchTextMax = lstrlen(pszText);
- tvi.iImage = ptvdta->imgIndex;
- tvi.iSelectedImage = ptvdta->imgIndexSelected;
-
- //root level node
- if (!ptvnodei->dwAttributes)
- {
- //since root level nodes are just stored in an array and
- //an element may have been deleted, check for an vacated element
- for (i = 0; i < m_icount; i++)
- {
- if (NULL == m_prootlvl[i])
- {
- //vacated element found
- index = i;
- break;
- }
- }
- if (!index)
- {
- //all elements are full, create new entry for root level data
- m_prootlvl[m_icount] = new Clist();
- //tvi.lParam = (LPARAM)m_prootlvl[m_icount];
- ptv = m_prootlvl[m_icount]->insertatend(ptvnodei);
- finditem = TRUE;
- //tvi.lParam = (LPARAM)ptv;
- index = m_icount;
- m_icount++;
- }
- else
- {
- //vacated element found
- m_prootlvl[index] = new Clist();
- //tvi.lParam = (LPARAM)m_prootlvl[index];
- ptv = m_prootlvl[index]->insertatend(ptvnodei);
- finditem = TRUE;
- //tvi.lParam = (LPARAM)ptv;
-
- }
-
- }
- else
- {
- for (i = 0; i < m_icount; i++)
- {
- if (NULL != m_prootlvl[i])
- {
- if (!lstrcmp((m_prootlvl[i]->getfirstnode())->data.pszSite, ptvnodei->pszSite))
- {
- ptv = m_prootlvl[i]->insertatend(ptvnodei);
- finditem = TRUE;
- index = i;
- //tvi.lParam = (LPARAM)ptv;
- break;
- }
- }
- }
- }
- //we should ASSERT here on finditem
- ASSERT(finditem);
-
- //set index value which provides a pointer from the TreeView item
- //to its root level Ftp site node
- ptv->index = index;
-
- //store the TVNODEINFO in the 32-bit lParam of the TV_ITEM
- tvi.lParam = (LPARAM)ptv;
-
- //set dwContext value to be used in asynchrounous calls
- *pdwContext = (DWORD)(tvi.lParam);
-
- //set the TV_INSERTSTRUCT values
- tvins.hParent = ptvdta->hParent;
- tvins.hInsertAfter = TVI_LAST;
- tvins.item = tvi;
-
- //add new treeview item and make visible
- htvitem = TreeView_InsertItem(m_hWndTV, &tvins);
- TreeView_EnsureVisible(m_hWndTV, htvitem);
-
-
- return htvitem;
- }
-
- //**********************************************************************
- // CCommonCtrl::TreeViewAdd
- //
- // Purpose: Wrapper for calling TreeView_GetParent and TreeView_GetItem
- // macros to get parent data
- // Parameters:
- // HTREEITEM ptvitem - handle to TreeView item to get parent for
- // LPTV_ITEM ptviParent - OUT parameter of parent item (TV_ITEM) values
- // UINT mask - mask for specifying items of parent to get
- // LPTSTR curdir - buffer used to get TV_ITEM.pszText
- // Return Value:
- // HTREEITEM - handle to the TreeView parent item
- //
- //********************************************************************
-
- HTREEITEM CCommonCtrl::TreeViewParent(HTREEITEM ptvitem, LPTV_ITEM ptviParent, UINT mask, LPTSTR curdir)
- {
- HTREEITEM hParent;
- BOOL ret;
- hParent = TreeView_GetParent(m_hWndTV, ptvitem);
- ptviParent->hItem = hParent;
- ptviParent->mask = mask;
- ptviParent->pszText = curdir;
- ptviParent->cchTextMax = MAX_PATH;
- ret = TreeView_GetItem(m_hWndTV, ptviParent);
- return hParent;
- }
-
- //**********************************************************************
- // CCommonCtrl::TreeViewAdd
- //
- // Purpose: Wrapper for calling TreeView_GetItem macro
- // Parameters:
- // HTREEITEM phtvitem - handle to TreeView item
- // LPTV_ITEM ptvi - OUT parameter of item (TV_ITEM) values
- // UINT mask - mask for specifying items of parent to get
- // LPTSTR buf - buffer used to get TV_ITEM.pszText
- // Return Value:
- // BOOL - TRUE if initialization succeeded, FALSE otherwise.
- //
- //********************************************************************
-
- BOOL CCommonCtrl::TreeViewItem(HTREEITEM phtvitem, LPTV_ITEM ptvi, UINT mask, LPTSTR buf)
- {
- BOOL ret;
- ptvi->hItem = phtvitem;
- ptvi->pszText = buf;
- ptvi->cchTextMax = 80;
- ptvi->mask = mask;
- ret = TreeView_GetItem(m_hWndTV, ptvi);
- return ret;
- }