OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [common/] [win32/] [FolderDialog.cpp] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//####COPYRIGHTBEGIN####
2
//                                                                          
3
// ----------------------------------------------------------------------------
4
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5
//
6
// This program is part of the eCos host tools.
7
//
8
// This program is free software; you can redistribute it and/or modify it 
9
// under the terms of the GNU General Public License as published by the Free 
10
// Software Foundation; either version 2 of the License, or (at your option) 
11
// any later version.
12
// 
13
// This program is distributed in the hope that it will be useful, but WITHOUT 
14
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
15
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
16
// more details.
17
// 
18
// You should have received a copy of the GNU General Public License along with
19
// this program; if not, write to the Free Software Foundation, Inc., 
20
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
//
22
// ----------------------------------------------------------------------------
23
//                                                                          
24
//####COPYRIGHTEND####
25
// FolderDialog.cpp : implementation file
26
//
27
//
28
//===========================================================================
29
//#####DESCRIPTIONBEGIN####
30
//
31
// Author(s):   sdf
32
// Contact(s):  sdf
33
// Date:                1998/08/11
34
// Version:             0.01
35
// Purpose:     
36
// Description: This is the implementation of the _T("browse for folder") dialog class
37
// Requires:    
38
// Provides:    
39
// See also:    
40
// Known bugs:  
41
// Usage:       
42
//
43
//####DESCRIPTIONEND####
44
//
45
//===========================================================================
46
 
47
#include "stdafx.h"
48
#include "FolderDialog.h"
49
#include "shlobj.h"
50
#include "CTUtils.h"
51
#include "NewFolderDialog.h"
52
 
53
#ifdef _DEBUG
54
#define new DEBUG_NEW
55
#undef THIS_FILE
56
static char THIS_FILE[] = __FILE__;
57
#endif
58
 
59
/////////////////////////////////////////////////////////////////////////////
60
// CFolderDialog dialog
61
 
62
CFolderDialog::CFolderDialog(BOOL bAllowCreation/*=TRUE*/,UINT id/*=0*/)
63
    : CeCosDialog(id?id:IDD_FOLDER_DIALOG, NULL),
64
        m_bAllowCreation(bAllowCreation),
65
        m_pButton(NULL)
66
{
67
        //{{AFX_DATA_INIT(CFolderDialog)
68
        //}}AFX_DATA_INIT
69
        m_strTitle=_T("Choose Folder");
70
        GetCurrentDirectory(MAX_PATH,m_strFolder.GetBuffer(MAX_PATH));
71
        m_strFolder.ReleaseBuffer();
72
}
73
 
74
 
75
void CFolderDialog::DoDataExchange(CDataExchange* pDX)
76
{
77
        CeCosDialog::DoDataExchange(pDX);
78
        //{{AFX_DATA_MAP(CFolderDialog)
79
        //}}AFX_DATA_MAP
80
}
81
 
82
 
83
BEGIN_MESSAGE_MAP(CFolderDialog, CeCosDialog)
84
        //{{AFX_MSG_MAP(CFolderDialog)
85
        ON_BN_CLICKED(IDC_FOLDER_DIALOG_BROWSE, OnBrowse)
86
        ON_EN_CHANGE(IDC_FOLDER, OnChangeFolder)
87
        //}}AFX_MSG_MAP
88
END_MESSAGE_MAP()
89
 
90
/////////////////////////////////////////////////////////////////////////////
91
// CFolderDialog message handlers
92
 
93
void CFolderDialog::OnBrowse()
94
{
95
    m_wndProc=NULL;
96
        GetDlgItemText(IDC_FOLDER,m_strFolder);
97
 
98
        BROWSEINFO bi;
99
    bi.hwndOwner = GetSafeHwnd();
100
    bi.pidlRoot = NULL;
101
    bi.pszDisplayName = m_strFolder.GetBuffer(MAX_PATH);
102
    bi.lpszTitle = _T("");
103
    bi.ulFlags = BIF_RETURNONLYFSDIRS/*|0x0010 BIF_EDITBOX*/;
104
    bi.lpfn = (BFFCALLBACK)CBBrowseCallbackProc;
105
    bi.lParam = (LPARAM)this;
106
 
107
        static const UINT arids[]={IDOK,IDCANCEL,IDC_FOLDER_DIALOG_BROWSE,IDC_FOLDER};
108
        BOOL arbEnabled[4];
109
 
110
        ASSERT(sizeof arids/sizeof arids[0] == sizeof arbEnabled/sizeof arbEnabled[0]);
111
 
112
        for(int i=0;i<sizeof arids/sizeof arids[0];i++){
113
                UINT id=arids[i];
114
                arbEnabled[i]=GetDlgItem(id)->IsWindowEnabled();
115
                GetDlgItem(id)->EnableWindow(FALSE);
116
        }
117
    LPITEMIDLIST iil = SHBrowseForFolder(&bi);
118
        m_strFolder.ReleaseBuffer();
119
        if(iil)
120
        {
121
                SHGetPathFromIDList(iil,m_strFolder.GetBuffer(MAX_PATH));
122
        m_strFolder.ReleaseBuffer();
123
        SetDlgItemText(IDC_FOLDER,m_strFolder);
124
        }
125
 
126
        for(i=0;i<sizeof arids/sizeof arids[0];i++){
127
                UINT id=arids[i];
128
                GetDlgItem(id)->EnableWindow(arbEnabled[i]);
129
        }
130
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
131
 
132
        if(m_bAllowCreation){
133
                deleteZ(m_pButton);
134
        }
135
}
136
 
137
// Use callback to expand folder in edit box at time of browse
138
int CALLBACK CFolderDialog::CBBrowseCallbackProc( HWND hwnd,
139
        UINT uMsg,
140
        LPARAM lParam,
141
        LPARAM lpData
142
        )
143
{
144
    CFolderDialog *pDlg=(CFolderDialog *)lpData;
145
    switch(uMsg){
146
        case BFFM_INITIALIZED:
147
                if(pDlg->m_bAllowCreation){
148
                        CWnd *pWnd=CWnd::FromHandle(hwnd);
149
                        pDlg->m_pButton=new CButton();
150
                        // Get rect of IDOK button
151
                        CRect rect1;
152
                        pWnd->GetDlgItem(IDOK)->GetWindowRect(&rect1);
153
                        pWnd->ScreenToClient(&rect1);
154
 
155
                        // Get rect of IDCANCEL button to the right
156
                        CRect rect2;
157
                        pWnd->GetDlgItem(IDCANCEL)->GetWindowRect(&rect2);
158
                        pWnd->ScreenToClient(&rect2);
159
                        int nXDiff=rect2.left-rect1.left;
160
 
161
                        CRect rect(rect1);
162
                        rect.left-=nXDiff;
163
                        rect.right-=nXDiff;
164
                        pDlg->m_pButton->Create(_T("&New..."), WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, rect, pWnd, ID_NEW_FOLDER);
165
                        pDlg->m_pButton->SendMessage(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
166
                        m_wndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (long)WindowProcNew);
167
                }
168
            ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)pDlg->m_strFolder);
169
        case BFFM_SELCHANGED:
170
            {
171
                // Change the cwd such that if the New button is used, we know where we are to start from
172
                ITEMIDLIST *iil=(ITEMIDLIST *)lParam;
173
                CString strFolder;
174
                        SHGetPathFromIDList(iil,strFolder.GetBuffer(MAX_PATH));
175
                strFolder.ReleaseBuffer();
176
                SetCurrentDirectory(strFolder);
177
            }
178
            break;
179
        default:
180
            ;
181
    }
182
 
183
        return 0;
184
}
185
 
186
 
187
WNDPROC CFolderDialog::m_wndProc=NULL;
188
LRESULT CALLBACK CFolderDialog::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
189
{
190
        if (message ==  WM_COMMAND && wParam==MAKEWPARAM(ID_NEW_FOLDER,BN_CLICKED)){
191
                CNewFolderDialog dlg;
192
        // Start from the cwd (maintained by BFFM_SELCHANGED above)
193
                GetCurrentDirectory(MAX_PATH,dlg.m_strFolder.GetBuffer(MAX_PATH));
194
                dlg.m_strFolder.ReleaseBuffer();
195
 
196
                if(IDOK==dlg.DoModal()){
197
            // Feed the new directory back as the current selection in the browse dialog
198
                        ::SendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR )dlg.m_strFolder);
199
                }
200
                return 0;
201
        } else {
202
                return CallWindowProc(m_wndProc, hwnd, message, wParam, lParam);
203
        }
204
}
205
 
206
void CFolderDialog::OnOK()
207
{
208
        GetDlgItemText(IDC_FOLDER,m_strFolder);
209
        if(!m_strFolder.IsDir()){
210
                if(m_bAllowCreation){
211
                        if(!m_strFolder.CreateDirectory()){
212
                                CUtils::MessageBoxF(_T("Could not create folder %s"),m_strFolder);
213
                                return;
214
                        }
215
                } else {
216
                        CUtils::MessageBoxF(_T("Folder %s does not exist"),m_strFolder);
217
                        return;
218
                }
219
        } else if (m_bAllowCreation && IDNO==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2, _T("Folder %s already exists - overwrite?"),m_strFolder)){
220
                return;
221
        }
222
        CeCosDialog::OnOK();
223
}
224
 
225
BOOL CFolderDialog::OnInitDialog()
226
{
227
        CeCosDialog::OnInitDialog();
228
        if(m_bAllowCreation&&m_strDesc.IsEmpty()){
229
                m_strDesc.LoadString(IDS_DEFAULT_FOLDER_DIALOG_DESC);
230
        }
231
        SetDlgItemText(IDC_STATIC_DESC,m_strDesc);
232
        SetDlgItemText(IDC_FOLDER,m_strFolder);
233
        SetWindowText(m_strTitle);
234
        SetCurrentDirectory(m_strFolder);
235
        SetDlgItemText(IDC_FOLDER,m_strFolder);
236
        GetDlgItem(IDC_FOLDER)->SetFocus();
237
        GetDlgItem(IDC_FOLDER)->SendMessage(EM_SETSEL,0,-1);
238
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
239
        return FALSE;  // return TRUE unless you set the focus to a control
240
                      // EXCEPTION: OCX Property Pages should return FALSE
241
}
242
 
243
void CFolderDialog::OnCancel()
244
{
245
        CeCosDialog::OnCancel();
246
}
247
 
248
 
249
 
250
void CFolderDialog::OnChangeFolder()
251
{
252
        CString str;
253
        GetDlgItemText(IDC_FOLDER,str);
254
        GetDlgItem(IDOK)->EnableWindow(!str.IsEmpty());
255
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.