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] - Diff between revs 26 and 174

Only display areas with differences | Details | Blame | View Log

Rev 26 Rev 174
//####COPYRIGHTBEGIN####
//####COPYRIGHTBEGIN####
//                                                                          
//                                                                          
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
//
//
// This program is part of the eCos host tools.
// This program is part of the eCos host tools.
//
//
// This program is free software; you can redistribute it and/or modify it 
// This program is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the Free 
// under the terms of the GNU General Public License as published by the Free 
// Software Foundation; either version 2 of the License, or (at your option) 
// Software Foundation; either version 2 of the License, or (at your option) 
// any later version.
// any later version.
// 
// 
// This program is distributed in the hope that it will be useful, but WITHOUT 
// This program is distributed in the hope that it will be useful, but WITHOUT 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
// more details.
// more details.
// 
// 
// You should have received a copy of the GNU General Public License along with
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 
// this program; if not, write to the Free Software Foundation, Inc., 
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
//                                                                          
//                                                                          
//####COPYRIGHTEND####
//####COPYRIGHTEND####
// FolderDialog.cpp : implementation file
// FolderDialog.cpp : implementation file
//
//
//
//
//===========================================================================
//===========================================================================
//#####DESCRIPTIONBEGIN####
//#####DESCRIPTIONBEGIN####
//
//
// Author(s):   sdf
// Author(s):   sdf
// Contact(s):  sdf
// Contact(s):  sdf
// Date:                1998/08/11
// Date:                1998/08/11
// Version:             0.01
// Version:             0.01
// Purpose:     
// Purpose:     
// Description: This is the implementation of the _T("browse for folder") dialog class
// Description: This is the implementation of the _T("browse for folder") dialog class
// Requires:    
// Requires:    
// Provides:    
// Provides:    
// See also:    
// See also:    
// Known bugs:  
// Known bugs:  
// Usage:       
// Usage:       
//
//
//####DESCRIPTIONEND####
//####DESCRIPTIONEND####
//
//
//===========================================================================
//===========================================================================
 
 
#include "stdafx.h"
#include "stdafx.h"
#include "FolderDialog.h"
#include "FolderDialog.h"
#include "shlobj.h"
#include "shlobj.h"
#include "CTUtils.h"
#include "CTUtils.h"
#include "NewFolderDialog.h"
#include "NewFolderDialog.h"
 
 
#ifdef _DEBUG
#ifdef _DEBUG
#define new DEBUG_NEW
#define new DEBUG_NEW
#undef THIS_FILE
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
static char THIS_FILE[] = __FILE__;
#endif
#endif
 
 
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CFolderDialog dialog
// CFolderDialog dialog
 
 
CFolderDialog::CFolderDialog(BOOL bAllowCreation/*=TRUE*/,UINT id/*=0*/)
CFolderDialog::CFolderDialog(BOOL bAllowCreation/*=TRUE*/,UINT id/*=0*/)
    : CeCosDialog(id?id:IDD_FOLDER_DIALOG, NULL),
    : CeCosDialog(id?id:IDD_FOLDER_DIALOG, NULL),
        m_bAllowCreation(bAllowCreation),
        m_bAllowCreation(bAllowCreation),
        m_pButton(NULL)
        m_pButton(NULL)
{
{
        //{{AFX_DATA_INIT(CFolderDialog)
        //{{AFX_DATA_INIT(CFolderDialog)
        //}}AFX_DATA_INIT
        //}}AFX_DATA_INIT
        m_strTitle=_T("Choose Folder");
        m_strTitle=_T("Choose Folder");
        GetCurrentDirectory(MAX_PATH,m_strFolder.GetBuffer(MAX_PATH));
        GetCurrentDirectory(MAX_PATH,m_strFolder.GetBuffer(MAX_PATH));
        m_strFolder.ReleaseBuffer();
        m_strFolder.ReleaseBuffer();
}
}
 
 
 
 
void CFolderDialog::DoDataExchange(CDataExchange* pDX)
void CFolderDialog::DoDataExchange(CDataExchange* pDX)
{
{
        CeCosDialog::DoDataExchange(pDX);
        CeCosDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CFolderDialog)
        //{{AFX_DATA_MAP(CFolderDialog)
        //}}AFX_DATA_MAP
        //}}AFX_DATA_MAP
}
}
 
 
 
 
BEGIN_MESSAGE_MAP(CFolderDialog, CeCosDialog)
BEGIN_MESSAGE_MAP(CFolderDialog, CeCosDialog)
        //{{AFX_MSG_MAP(CFolderDialog)
        //{{AFX_MSG_MAP(CFolderDialog)
        ON_BN_CLICKED(IDC_FOLDER_DIALOG_BROWSE, OnBrowse)
        ON_BN_CLICKED(IDC_FOLDER_DIALOG_BROWSE, OnBrowse)
        ON_EN_CHANGE(IDC_FOLDER, OnChangeFolder)
        ON_EN_CHANGE(IDC_FOLDER, OnChangeFolder)
        //}}AFX_MSG_MAP
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()
END_MESSAGE_MAP()
 
 
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CFolderDialog message handlers
// CFolderDialog message handlers
 
 
void CFolderDialog::OnBrowse()
void CFolderDialog::OnBrowse()
{
{
    m_wndProc=NULL;
    m_wndProc=NULL;
        GetDlgItemText(IDC_FOLDER,m_strFolder);
        GetDlgItemText(IDC_FOLDER,m_strFolder);
 
 
        BROWSEINFO bi;
        BROWSEINFO bi;
    bi.hwndOwner = GetSafeHwnd();
    bi.hwndOwner = GetSafeHwnd();
    bi.pidlRoot = NULL;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = m_strFolder.GetBuffer(MAX_PATH);
    bi.pszDisplayName = m_strFolder.GetBuffer(MAX_PATH);
    bi.lpszTitle = _T("");
    bi.lpszTitle = _T("");
    bi.ulFlags = BIF_RETURNONLYFSDIRS/*|0x0010 BIF_EDITBOX*/;
    bi.ulFlags = BIF_RETURNONLYFSDIRS/*|0x0010 BIF_EDITBOX*/;
    bi.lpfn = (BFFCALLBACK)CBBrowseCallbackProc;
    bi.lpfn = (BFFCALLBACK)CBBrowseCallbackProc;
    bi.lParam = (LPARAM)this;
    bi.lParam = (LPARAM)this;
 
 
        static const UINT arids[]={IDOK,IDCANCEL,IDC_FOLDER_DIALOG_BROWSE,IDC_FOLDER};
        static const UINT arids[]={IDOK,IDCANCEL,IDC_FOLDER_DIALOG_BROWSE,IDC_FOLDER};
        BOOL arbEnabled[4];
        BOOL arbEnabled[4];
 
 
        ASSERT(sizeof arids/sizeof arids[0] == sizeof arbEnabled/sizeof arbEnabled[0]);
        ASSERT(sizeof arids/sizeof arids[0] == sizeof arbEnabled/sizeof arbEnabled[0]);
 
 
        for(int i=0;i<sizeof arids/sizeof arids[0];i++){
        for(int i=0;i<sizeof arids/sizeof arids[0];i++){
                UINT id=arids[i];
                UINT id=arids[i];
                arbEnabled[i]=GetDlgItem(id)->IsWindowEnabled();
                arbEnabled[i]=GetDlgItem(id)->IsWindowEnabled();
                GetDlgItem(id)->EnableWindow(FALSE);
                GetDlgItem(id)->EnableWindow(FALSE);
        }
        }
    LPITEMIDLIST iil = SHBrowseForFolder(&bi);
    LPITEMIDLIST iil = SHBrowseForFolder(&bi);
        m_strFolder.ReleaseBuffer();
        m_strFolder.ReleaseBuffer();
        if(iil)
        if(iil)
        {
        {
                SHGetPathFromIDList(iil,m_strFolder.GetBuffer(MAX_PATH));
                SHGetPathFromIDList(iil,m_strFolder.GetBuffer(MAX_PATH));
        m_strFolder.ReleaseBuffer();
        m_strFolder.ReleaseBuffer();
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        }
        }
 
 
        for(i=0;i<sizeof arids/sizeof arids[0];i++){
        for(i=0;i<sizeof arids/sizeof arids[0];i++){
                UINT id=arids[i];
                UINT id=arids[i];
                GetDlgItem(id)->EnableWindow(arbEnabled[i]);
                GetDlgItem(id)->EnableWindow(arbEnabled[i]);
        }
        }
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
 
 
        if(m_bAllowCreation){
        if(m_bAllowCreation){
                deleteZ(m_pButton);
                deleteZ(m_pButton);
        }
        }
}
}
 
 
// Use callback to expand folder in edit box at time of browse
// Use callback to expand folder in edit box at time of browse
int CALLBACK CFolderDialog::CBBrowseCallbackProc( HWND hwnd,
int CALLBACK CFolderDialog::CBBrowseCallbackProc( HWND hwnd,
        UINT uMsg,
        UINT uMsg,
        LPARAM lParam,
        LPARAM lParam,
        LPARAM lpData
        LPARAM lpData
        )
        )
{
{
    CFolderDialog *pDlg=(CFolderDialog *)lpData;
    CFolderDialog *pDlg=(CFolderDialog *)lpData;
    switch(uMsg){
    switch(uMsg){
        case BFFM_INITIALIZED:
        case BFFM_INITIALIZED:
                if(pDlg->m_bAllowCreation){
                if(pDlg->m_bAllowCreation){
                        CWnd *pWnd=CWnd::FromHandle(hwnd);
                        CWnd *pWnd=CWnd::FromHandle(hwnd);
                        pDlg->m_pButton=new CButton();
                        pDlg->m_pButton=new CButton();
                        // Get rect of IDOK button
                        // Get rect of IDOK button
                        CRect rect1;
                        CRect rect1;
                        pWnd->GetDlgItem(IDOK)->GetWindowRect(&rect1);
                        pWnd->GetDlgItem(IDOK)->GetWindowRect(&rect1);
                        pWnd->ScreenToClient(&rect1);
                        pWnd->ScreenToClient(&rect1);
 
 
                        // Get rect of IDCANCEL button to the right
                        // Get rect of IDCANCEL button to the right
                        CRect rect2;
                        CRect rect2;
                        pWnd->GetDlgItem(IDCANCEL)->GetWindowRect(&rect2);
                        pWnd->GetDlgItem(IDCANCEL)->GetWindowRect(&rect2);
                        pWnd->ScreenToClient(&rect2);
                        pWnd->ScreenToClient(&rect2);
                        int nXDiff=rect2.left-rect1.left;
                        int nXDiff=rect2.left-rect1.left;
 
 
                        CRect rect(rect1);
                        CRect rect(rect1);
                        rect.left-=nXDiff;
                        rect.left-=nXDiff;
                        rect.right-=nXDiff;
                        rect.right-=nXDiff;
                        pDlg->m_pButton->Create(_T("&New..."), WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, rect, pWnd, ID_NEW_FOLDER);
                        pDlg->m_pButton->Create(_T("&New..."), WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, rect, pWnd, ID_NEW_FOLDER);
                        pDlg->m_pButton->SendMessage(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
                        pDlg->m_pButton->SendMessage(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
                        m_wndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (long)WindowProcNew);
                        m_wndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (long)WindowProcNew);
                }
                }
            ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)pDlg->m_strFolder);
            ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)pDlg->m_strFolder);
        case BFFM_SELCHANGED:
        case BFFM_SELCHANGED:
            {
            {
                // Change the cwd such that if the New button is used, we know where we are to start from
                // Change the cwd such that if the New button is used, we know where we are to start from
                ITEMIDLIST *iil=(ITEMIDLIST *)lParam;
                ITEMIDLIST *iil=(ITEMIDLIST *)lParam;
                CString strFolder;
                CString strFolder;
                        SHGetPathFromIDList(iil,strFolder.GetBuffer(MAX_PATH));
                        SHGetPathFromIDList(iil,strFolder.GetBuffer(MAX_PATH));
                strFolder.ReleaseBuffer();
                strFolder.ReleaseBuffer();
                SetCurrentDirectory(strFolder);
                SetCurrentDirectory(strFolder);
            }
            }
            break;
            break;
        default:
        default:
            ;
            ;
    }
    }
 
 
        return 0;
        return 0;
}
}
 
 
 
 
WNDPROC CFolderDialog::m_wndProc=NULL;
WNDPROC CFolderDialog::m_wndProc=NULL;
LRESULT CALLBACK CFolderDialog::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK CFolderDialog::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
{
        if (message ==  WM_COMMAND && wParam==MAKEWPARAM(ID_NEW_FOLDER,BN_CLICKED)){
        if (message ==  WM_COMMAND && wParam==MAKEWPARAM(ID_NEW_FOLDER,BN_CLICKED)){
                CNewFolderDialog dlg;
                CNewFolderDialog dlg;
        // Start from the cwd (maintained by BFFM_SELCHANGED above)
        // Start from the cwd (maintained by BFFM_SELCHANGED above)
                GetCurrentDirectory(MAX_PATH,dlg.m_strFolder.GetBuffer(MAX_PATH));
                GetCurrentDirectory(MAX_PATH,dlg.m_strFolder.GetBuffer(MAX_PATH));
                dlg.m_strFolder.ReleaseBuffer();
                dlg.m_strFolder.ReleaseBuffer();
 
 
                if(IDOK==dlg.DoModal()){
                if(IDOK==dlg.DoModal()){
            // Feed the new directory back as the current selection in the browse dialog
            // Feed the new directory back as the current selection in the browse dialog
                        ::SendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR )dlg.m_strFolder);
                        ::SendMessage (hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR )dlg.m_strFolder);
                }
                }
                return 0;
                return 0;
        } else {
        } else {
                return CallWindowProc(m_wndProc, hwnd, message, wParam, lParam);
                return CallWindowProc(m_wndProc, hwnd, message, wParam, lParam);
        }
        }
}
}
 
 
void CFolderDialog::OnOK()
void CFolderDialog::OnOK()
{
{
        GetDlgItemText(IDC_FOLDER,m_strFolder);
        GetDlgItemText(IDC_FOLDER,m_strFolder);
        if(!m_strFolder.IsDir()){
        if(!m_strFolder.IsDir()){
                if(m_bAllowCreation){
                if(m_bAllowCreation){
                        if(!m_strFolder.CreateDirectory()){
                        if(!m_strFolder.CreateDirectory()){
                                CUtils::MessageBoxF(_T("Could not create folder %s"),m_strFolder);
                                CUtils::MessageBoxF(_T("Could not create folder %s"),m_strFolder);
                                return;
                                return;
                        }
                        }
                } else {
                } else {
                        CUtils::MessageBoxF(_T("Folder %s does not exist"),m_strFolder);
                        CUtils::MessageBoxF(_T("Folder %s does not exist"),m_strFolder);
                        return;
                        return;
                }
                }
        } else if (m_bAllowCreation && IDNO==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2, _T("Folder %s already exists - overwrite?"),m_strFolder)){
        } else if (m_bAllowCreation && IDNO==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2, _T("Folder %s already exists - overwrite?"),m_strFolder)){
                return;
                return;
        }
        }
        CeCosDialog::OnOK();
        CeCosDialog::OnOK();
}
}
 
 
BOOL CFolderDialog::OnInitDialog()
BOOL CFolderDialog::OnInitDialog()
{
{
        CeCosDialog::OnInitDialog();
        CeCosDialog::OnInitDialog();
        if(m_bAllowCreation&&m_strDesc.IsEmpty()){
        if(m_bAllowCreation&&m_strDesc.IsEmpty()){
                m_strDesc.LoadString(IDS_DEFAULT_FOLDER_DIALOG_DESC);
                m_strDesc.LoadString(IDS_DEFAULT_FOLDER_DIALOG_DESC);
        }
        }
        SetDlgItemText(IDC_STATIC_DESC,m_strDesc);
        SetDlgItemText(IDC_STATIC_DESC,m_strDesc);
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        SetWindowText(m_strTitle);
        SetWindowText(m_strTitle);
        SetCurrentDirectory(m_strFolder);
        SetCurrentDirectory(m_strFolder);
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        SetDlgItemText(IDC_FOLDER,m_strFolder);
        GetDlgItem(IDC_FOLDER)->SetFocus();
        GetDlgItem(IDC_FOLDER)->SetFocus();
        GetDlgItem(IDC_FOLDER)->SendMessage(EM_SETSEL,0,-1);
        GetDlgItem(IDC_FOLDER)->SendMessage(EM_SETSEL,0,-1);
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
        GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
        return FALSE;  // return TRUE unless you set the focus to a control
        return FALSE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE
                      // EXCEPTION: OCX Property Pages should return FALSE
}
}
 
 
void CFolderDialog::OnCancel()
void CFolderDialog::OnCancel()
{
{
        CeCosDialog::OnCancel();
        CeCosDialog::OnCancel();
}
}
 
 
 
 
 
 
void CFolderDialog::OnChangeFolder()
void CFolderDialog::OnChangeFolder()
{
{
        CString str;
        CString str;
        GetDlgItemText(IDC_FOLDER,str);
        GetDlgItemText(IDC_FOLDER,str);
        GetDlgItem(IDOK)->EnableWindow(!str.IsEmpty());
        GetDlgItem(IDOK)->EnableWindow(!str.IsEmpty());
}
}
 
 

powered by: WebSVN 2.1.0

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