blob: 7c88ff6a90327623217033bd8dfda4c013ff7783 [file] [log] [blame]
Dennis Syrovatsky32ed3322005-12-15 09:37:38 +00001/* Copyright (C) 2005 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 *
18 * TightVNC distribution homepage on the Web: http://www.tightvnc.com/
19 *
20 */
21
22// -=- FTBrpwseDlg.cxx
23
24#include <vncviewer/FTBrowseDlg.h>
25
26using namespace rfb;
27using namespace rfb::win32;
28
29FTBrowseDlg::FTBrowseDlg(FTDialog *pFTDlg)
30{
Dennis Syrovatsky04e05c32005-12-15 09:51:03 +000031 m_pFTDlg = pFTDlg;
32 m_hwndDlg = NULL;
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000033 m_hwndTree = NULL;
34 m_hParentItem = NULL;
Dennis Syrovatsky32ed3322005-12-15 09:37:38 +000035}
36
37FTBrowseDlg::~FTBrowseDlg()
38{
Dennis Syrovatsky04e05c32005-12-15 09:51:03 +000039 destroy();
40}
Dennis Syrovatsky32ed3322005-12-15 09:37:38 +000041
Dennis Syrovatsky04e05c32005-12-15 09:51:03 +000042bool
43FTBrowseDlg::create()
44{
45 m_hwndDlg = CreateDialogParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_FTBROWSE),
46 m_pFTDlg->getWndHandle(), (DLGPROC) FTBrowseDlgProc,
47 (LONG) this);
48
49 if (m_hwndDlg == NULL) return false;
50
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000051 m_hwndTree = GetDlgItem(m_hwndDlg, IDC_FTBROWSETREE);
52
Dennis Syrovatsky04e05c32005-12-15 09:51:03 +000053 ShowWindow(m_hwndDlg, SW_SHOW);
54 UpdateWindow(m_hwndDlg);
55
56 return true;
57}
58
59void
60FTBrowseDlg::destroy()
61{
62 EndDialog(m_hwndDlg, 0);
Dennis Syrovatsky32ed3322005-12-15 09:37:38 +000063}
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +000064
Dennis Syrovatskyb0b72472005-12-15 10:02:16 +000065void
66FTBrowseDlg::addItems(FileInfo *pFI)
67{
68 TVITEM tvi;
69 TVINSERTSTRUCT tvins;
70
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000071 while (TreeView_GetChild(m_hwndTree, m_hParentItem) != NULL) {
72 TreeView_DeleteItem(m_hwndTree, TreeView_GetChild(m_hwndTree, m_hParentItem));
73 }
74
Dennis Syrovatskyb0b72472005-12-15 10:02:16 +000075 for (unsigned int i = 0; i < pFI->getNumEntries(); i++)
76 {
77 tvi.mask = TVIF_TEXT;
78 tvi.pszText = pFI->getNameAt(i);;
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000079 tvins.hParent = m_hParentItem;
Dennis Syrovatskyb0b72472005-12-15 10:02:16 +000080 tvins.item = tvi;
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000081 tvins.hParent = TreeView_InsertItem(m_hwndTree, &tvins);
82 TreeView_InsertItem(m_hwndTree, &tvins);
Dennis Syrovatskyb0b72472005-12-15 10:02:16 +000083 }
84}
85
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +000086char *
87FTBrowseDlg::getTVPath(HTREEITEM hTItem)
88{
89 char path[FT_FILENAME_SIZE];
90 char szText[FT_FILENAME_SIZE];
91
92 TVITEM tvi;
93 path[0] = '\0';
94
95 do {
96 tvi.mask = TVIF_TEXT | TVIF_HANDLE;
97 tvi.hItem = hTItem;
98 tvi.pszText = szText;
99 tvi.cchTextMax = FT_FILENAME_SIZE;
100 TreeView_GetItem(m_hwndTree, &tvi);
101 sprintf(path, "%s\\%s", path, tvi.pszText);
102 hTItem = TreeView_GetParent(m_hwndTree, hTItem);
103 } while(hTItem != NULL);
104
105 return pathInvert(path);
106}
107
108char *
109FTBrowseDlg::pathInvert(char *pPath)
110{
111 int len = strlen(pPath);
112 m_szPath[0] = '\0';
113 char *pos = NULL;
114
115 while ((pos = strrchr(pPath, '\\')) != NULL) {
116 if (strlen(m_szPath) == 0) {
117 strcpy(m_szPath, (pos + 1));
118 } else {
119 sprintf(m_szPath, "%s\\%s", m_szPath, (pos + 1));
120 }
121 *pos = '\0';
122 }
123
124 m_szPath[len] = '\0';
125 return m_szPath;
126}
127
128char *
129FTBrowseDlg::getPath()
130{
131 GetDlgItemText(m_hwndDlg, IDC_FTBROWSEPATH, m_szPath, FT_FILENAME_SIZE);
132 return m_szPath;
133}
134
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000135BOOL CALLBACK
136FTBrowseDlg::FTBrowseDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
137{
138 FTBrowseDlg *_this = (FTBrowseDlg *) GetWindowLong(hwnd, GWL_USERDATA);
139 switch (uMsg)
140 {
141 case WM_INITDIALOG:
142 {
143 SetWindowLong(hwnd, GWL_USERDATA, lParam);
144 return FALSE;
145 }
146 break;
147 case WM_COMMAND:
148 {
149 switch (LOWORD(wParam))
150 {
151 case IDOK:
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000152 _this->m_pFTDlg->onEndBrowseDlg(true);
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000153 return FALSE;
154 case IDCANCEL:
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000155 _this->m_pFTDlg->onEndBrowseDlg(false);
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000156 return FALSE;
157 }
158 }
159 break;
160 case WM_NOTIFY:
161 switch (LOWORD(wParam))
162 {
163 case IDC_FTBROWSETREE:
164 switch (((LPNMHDR) lParam)->code)
165 {
166 case TVN_SELCHANGED:
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000167 SetDlgItemText(hwnd, IDC_FTBROWSEPATH, _this->getTVPath(((NMTREEVIEW *) lParam)->itemNew.hItem));
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000168 return FALSE;
169 case TVN_ITEMEXPANDING:
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000170 {
171 NMTREEVIEW *nmCode = (NMTREEVIEW *) lParam;
172 if (nmCode->action == 2) {
173 _this->m_hParentItem = nmCode->itemNew.hItem;
174 _this->m_pFTDlg->getBrowseItems(_this->getTVPath(_this->m_hParentItem));
175 }
176 }
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000177 return FALSE;
178 }
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000179 break;
180 case WM_CLOSE:
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000181 _this->m_pFTDlg->onEndBrowseDlg(false);
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000182 return FALSE;
183 }
Dennis Syrovatsky1a3a5532005-12-15 14:20:03 +0000184 }
Dennis Syrovatsky2eee1c72005-12-15 09:43:34 +0000185 return 0;
186}