1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
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)
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
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.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // BinDirDialog.cpp : implementation file
29 #include "ConfigTool.h"
30 #include "configtooldoc.h"
31 #include "BinDirDialog.h"
32 #include "ConfigItem.h"
37 static char THIS_FILE[] = __FILE__;
40 /////////////////////////////////////////////////////////////////////////////
41 // CBinDirDialog dialog
44 CBinDirDialog::CBinDirDialog(const CStringArray &arstrPaths, const CString &strDefault)
45 : CFolderDialog(FALSE, CBinDirDialog::IDD), m_arstrPaths(arstrPaths), m_strDefault(strDefault)
47 //{{AFX_DATA_INIT(CBinDirDialog)
48 // NOTE: the ClassWizard will add member initialization here
50 m_strFolder = _T(""); // Internationalization OK
54 void CBinDirDialog::DoDataExchange(CDataExchange* pDX)
56 CFolderDialog::DoDataExchange(pDX);
57 //{{AFX_DATA_MAP(CBinDirDialog)
58 // NOTE: the ClassWizard will add DDX and DDV calls here
63 BEGIN_MESSAGE_MAP(CBinDirDialog, CFolderDialog)
64 //{{AFX_MSG_MAP(CBinDirDialog)
65 ON_CBN_EDITCHANGE(IDC_FOLDER, OnEditchangeFolder)
66 ON_CBN_SELCHANGE(IDC_FOLDER, OnSelchangeFolder)
67 ON_BN_CLICKED(IDC_FOLDER_DIALOG_BROWSE, OnBrowse)
71 /////////////////////////////////////////////////////////////////////////////
72 // CBinDirDialog message handlers
74 BOOL CBinDirDialog::OnInitDialog()
76 CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_FOLDER);
77 CFolderDialog::OnInitDialog();
80 CFont *pOldFont=pDC->SelectObject(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
83 for(int i=0;i<m_arstrPaths.GetSize();i++){
84 const CFileName &str=m_arstrPaths[i];
85 for(int j=i+1;j<m_arstrPaths.GetSize();j++){
86 const CFileName &ostr=m_arstrPaths[j];
87 if(ostr.SameFile(str)){
91 if(str.IsDir()&&pCombo->FindString(-1,str)<0){
92 pCombo->AddString(str);
93 nMaxTextLength=max(nMaxTextLength,pDC->GetTextExtent(str).cx);
97 pDC->SelectObject(pOldFont);
101 pCombo->GetClientRect(rcClient);
102 int nExpand=nMaxTextLength-(rcClient.Width()-GetSystemMetrics(SM_CXVSCROLL)-2*GetSystemMetrics(SM_CXBORDER)-5);
104 static const UINT arids[]={IDC_STATIC_DESC, IDOK,IDCANCEL,IDC_FOLDER_DIALOG_BROWSE,IDC_FOLDER};
106 for(int i=0;i<sizeof arids/sizeof arids[0];i++){
108 GetDlgItem(id)->GetWindowRect(rect);
109 ScreenToClient(rect);
110 if(IDC_FOLDER!=id && IDC_STATIC_DESC!=id){
114 GetDlgItem(id)->MoveWindow(rect);
122 GetDlgItem(IDOK)->EnableWindow(!m_strFolder.IsEmpty());
123 for(i=pCombo->GetCount()-1;i>=0;--i){
125 pCombo->GetLBText(i,str);
126 if(str.SameFile(m_strDefault)){
127 pCombo->SetCurSel(i);
128 GetDlgItem(IDOK)->EnableWindow(TRUE);
132 return FALSE; // return TRUE unless you set the focus to a control
133 // EXCEPTION: OCX Property Pages should return FALSE
136 void CBinDirDialog::OnEditchangeFolder()
139 GetDlgItemText(IDC_FOLDER,str);
140 GetDlgItem(IDOK)->EnableWindow(!str.IsEmpty());
143 void CBinDirDialog::OnSelchangeFolder()
145 GetDlgItem(IDOK)->EnableWindow(-1!=((CComboBox *)GetDlgItem(IDC_FOLDER))->GetCurSel());
148 void CBinDirDialog::OnBrowse()
151 CFolderDialog::OnBrowse();
152 GetDlgItemText(IDC_FOLDER,str);
153 GetDlgItem(IDOK)->EnableWindow(!str.IsEmpty());