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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [FolderDialog.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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