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 // ViewOptions.cpp : implementation file
27 //===========================================================================
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
36 // Description: This is the implementation of the Configuration -> Options View tab
43 //####DESCRIPTIONEND####
45 //===========================================================================
48 #include "ConfigTool.h"
49 #include "ViewOptions.h"
50 #include "ConfigToolDoc.h"
57 static char THIS_FILE[] = __FILE__;
60 /////////////////////////////////////////////////////////////////////////////
61 // CViewOptions property page
63 CViewOptions::CViewOptions()
64 : CeCosDialog(IDD, NULL)
66 //{{AFX_DATA_INIT(CViewOptions)
68 m_FontChosen=CMainFrame::PaneTypeMax;
71 CViewOptions::~CViewOptions()
75 void CViewOptions::DoDataExchange(CDataExchange* pDX)
77 CeCosDialog::DoDataExchange(pDX);
78 //{{AFX_DATA_MAP(CViewOptions)
83 BEGIN_MESSAGE_MAP(CViewOptions, CeCosDialog)
84 //{{AFX_MSG_MAP(CViewOptions)
85 ON_BN_CLICKED(IDC_RADIO_ASSOCIATED, OnRadioAssociated)
86 ON_BN_CLICKED(IDC_RADIO_CUSTOM, OnRadioCustom)
87 ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
88 ON_BN_CLICKED(IDC_RADIO_INTERNAL_BROWSER, OnRadioInternalBrowser)
89 ON_BN_CLICKED(IDC_RADIO_ASSOCIATED_BROWSER, OnRadioAssociatedBrowser)
90 ON_BN_CLICKED(IDC_RADIO_CUSTOM_BROWSER, OnRadioCustomBrowser)
91 ON_BN_CLICKED(IDC_BROWSE_BROWSER, OnBrowseBrowser)
92 ON_BN_CLICKED(IDC_FONT, OnFont)
93 ON_CBN_SELCHANGE(IDC_PANECOMBO, OnSelchangePanecombo)
97 /////////////////////////////////////////////////////////////////////////////
98 // CViewOptions message handlers
100 const CFileName CViewOptions::strHeaderfileAssociation=CViewOptions::HeaderFileAssociation();
102 void CViewOptions::OnOK()
106 CMainFrame *pMain=CConfigTool::GetMain();
107 if(CMainFrame::PaneTypeMax!=m_FontChosen){
108 pMain->SetPaneFont(m_FontChosen, m_lf);
111 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
114 if(((CButton *)GetDlgItem(IDC_RADIO_CUSTOM_BROWSER))->GetCheck()){
115 CFileName strBrowser;
116 GetDlgItemText(IDC_EDIT_BROWSER,strBrowser);
117 if(strBrowser.IsEmpty() || !strBrowser.Exists()){
118 CUtils::MessageBoxF(_T("If you wish to use a custom browser you must specify a valid executable"));
119 GetDlgItem(IDC_EDIT_BROWSER)->SetFocus();
123 pDoc->m_strBrowser=strBrowser;
124 pDoc->m_eUseCustomBrowser=CConfigToolDoc::CustomExternal;
125 } else if (((CButton *)GetDlgItem(IDC_RADIO_ASSOCIATED_BROWSER))->GetCheck()){
126 pDoc->m_eUseCustomBrowser=CConfigToolDoc::AssociatedExternal;
128 pDoc->m_eUseCustomBrowser=CConfigToolDoc::Internal;
131 pDoc->m_bUseCustomViewer=((CButton *)GetDlgItem(IDC_RADIO_CUSTOM))->GetCheck();
132 if(pDoc->m_bUseCustomViewer){
134 GetDlgItemText(IDC_EDIT,strViewer);
135 if(strViewer.IsEmpty() || !strViewer.IsFile()){
136 CUtils::MessageBoxF(_T("If you wish to use a custom viewer you must specify a valid executable"));
137 GetDlgItem(IDC_EDIT)->SetFocus();
141 pDoc->m_strViewer=strViewer;
144 bool bHex=((CButton *)GetDlgItem(IDC_RADIO_HEXADECIMAL))->GetCheck();
145 if(bHex!=pDoc->m_bHex){
147 pDoc->UpdateAllViews(0,CConfigToolDoc::IntFormatChanged);
150 bool bMacros=((CButton *)GetDlgItem(IDC_RADIO_MACRO_NAMES))->GetCheck();
151 if(bMacros!=pDoc->m_bMacroNames){
152 pDoc->m_bMacroNames=bMacros;
153 pDoc->UpdateAllViews(0,CConfigToolDoc::NameFormatChanged);
159 void CViewOptions::OnRadioAssociated()
162 GetDlgItem(IDC_EDIT)->EnableWindow(FALSE);
163 GetDlgItem(IDC_BROWSE)->EnableWindow(FALSE);
166 void CViewOptions::OnRadioCustom()
169 GetDlgItem(IDC_EDIT)->EnableWindow(TRUE);
170 GetDlgItem(IDC_BROWSE)->EnableWindow(TRUE);
173 void CViewOptions::OnBrowse()
175 CFileDialog dlg(TRUE, _T("exe"), _T(""), OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
176 _T("Executables (*.exe;*.bat;*.com)|*.exe;*.bat;*.com"));
177 if(IDOK==dlg.DoModal()){
178 SetDlgItemText(IDC_EDIT,dlg.GetPathName());
182 BOOL CViewOptions::OnInitDialog()
184 CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_PANECOMBO);
185 CMainFrame *pMain=CConfigTool::GetMain();
186 for(int i=0;i<CMainFrame::PaneTypeMax;i++){
187 if(i==CMainFrame::Control || i==CMainFrame::Output || i==CMainFrame::ShortDesc){
188 int nIndex=pCombo->AddString(pMain->GetPaneName((CMainFrame::PaneType)i));
189 pCombo->SetItemData(nIndex,i);
192 pCombo->SetCurSel(0);
194 CeCosDialog::OnInitDialog();
196 if(!strHeaderfileAssociation.IsEmpty()){
198 str1.Format(_T("%s (%s)"),_T("Associated viewer"),strHeaderfileAssociation);
199 SetDlgItemText(IDC_RADIO_ASSOCIATED,str1);
201 SetDlgItemText(IDC_RADIO_ASSOCIATED,_T("Associated viewer"));
204 // Compute the association with doc (.htm) files
206 if(CConfigToolDoc::DefaultExternalBrowser().IsEmpty()){
207 SetDlgItemText(IDC_RADIO_ASSOCIATED_BROWSER,_T("Associated browser"));
210 str1.Format(_T("%s (%s)"),_T("Associated browser"),CConfigToolDoc::DefaultExternalBrowser().Tail());
211 SetDlgItemText(IDC_RADIO_ASSOCIATED_BROWSER,str1);
214 CConfigToolDoc*pDoc=CConfigTool::GetConfigToolDoc();
215 if(strHeaderfileAssociation.IsEmpty()){
216 GetDlgItem(IDC_RADIO_ASSOCIATED)->EnableWindow(FALSE);
217 GetDlgItem(IDC_BROWSE)->EnableWindow(TRUE);
218 ((CButton *)GetDlgItem(IDC_RADIO_CUSTOM))->SetCheck(TRUE);
220 ((CButton *)GetDlgItem(pDoc->m_bUseCustomViewer?IDC_RADIO_CUSTOM:IDC_RADIO_ASSOCIATED))->SetCheck(TRUE);
221 GetDlgItem(IDC_EDIT)->EnableWindow(pDoc->m_bUseCustomViewer);
222 GetDlgItem(IDC_BROWSE)->EnableWindow(pDoc->m_bUseCustomViewer);
224 SetDlgItemText(IDC_EDIT,pDoc->m_strViewer);
226 if(CConfigToolDoc::DefaultExternalBrowser().IsEmpty()){
227 GetDlgItem(IDC_RADIO_ASSOCIATED_BROWSER)->EnableWindow(FALSE);
228 GetDlgItem(IDC_BROWSE_BROWSER)->EnableWindow(TRUE);
229 if(CConfigToolDoc::AssociatedExternal==pDoc->m_eUseCustomBrowser){
230 pDoc->m_eUseCustomBrowser=CConfigToolDoc::CustomExternal;
234 switch(pDoc->m_eUseCustomBrowser){
235 case CConfigToolDoc::Internal:
236 ((CButton *)GetDlgItem(IDC_RADIO_INTERNAL_BROWSER))->SetCheck(TRUE);
238 case CConfigToolDoc::AssociatedExternal:
239 ((CButton *)GetDlgItem(IDC_RADIO_ASSOCIATED_BROWSER))->SetCheck(TRUE);
241 case CConfigToolDoc::CustomExternal:
242 ((CButton *)GetDlgItem(IDC_RADIO_CUSTOM_BROWSER))->SetCheck(TRUE);
243 GetDlgItem(IDC_EDIT_BROWSER)->EnableWindow(TRUE);
244 GetDlgItem(IDC_BROWSE_BROWSER)->EnableWindow(TRUE);
250 SetDlgItemText(IDC_EDIT_BROWSER,pDoc->m_strBrowser);
252 ((CButton *)GetDlgItem(IDC_RADIO_DECIMAL))->SetCheck(!pDoc->m_bHex);
253 ((CButton *)GetDlgItem(IDC_RADIO_DESCRIPTIVE_NAMES))->SetCheck(!pDoc->m_bMacroNames);
254 ((CButton *)GetDlgItem(IDC_RADIO_HEXADECIMAL))->SetCheck(pDoc->m_bHex);
255 ((CButton *)GetDlgItem(IDC_RADIO_MACRO_NAMES))->SetCheck(pDoc->m_bMacroNames);
258 return TRUE; // return TRUE unless you set the focus to a control
259 // EXCEPTION: OCX Property Pages should return FALSE
262 void CViewOptions::OnRadioInternalBrowser()
265 GetDlgItem(IDC_EDIT_BROWSER)->EnableWindow(FALSE);
266 GetDlgItem(IDC_BROWSE_BROWSER)->EnableWindow(FALSE);
269 void CViewOptions::OnRadioAssociatedBrowser()
272 GetDlgItem(IDC_EDIT_BROWSER)->EnableWindow(FALSE);
273 GetDlgItem(IDC_BROWSE_BROWSER)->EnableWindow(FALSE);
276 void CViewOptions::OnRadioCustomBrowser()
279 GetDlgItem(IDC_EDIT_BROWSER)->EnableWindow(TRUE);
280 GetDlgItem(IDC_BROWSE_BROWSER)->EnableWindow(TRUE);
283 void CViewOptions::OnBrowseBrowser()
285 CFileDialog dlg(TRUE, _T("exe"), _T(""), OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
286 _T("Executables (*.exe;*.bat;*.com)|*.exe;*.bat;*.com"));
287 if(IDOK==dlg.DoModal()){
288 SetDlgItemText(IDC_EDIT_BROWSER,dlg.GetPathName());
293 void CViewOptions::OnFont()
296 CMainFrame *pMain=CConfigTool::GetMain();
297 CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_PANECOMBO);
298 int nSel=pCombo->GetCurSel();
299 CMainFrame::PaneType pane=(CMainFrame::PaneType)pCombo->GetItemData(nSel);
300 pMain->GetPaneFont(pane).GetLogFont(&lf);
301 CFontDialog dlg(&lf);
302 if(IDOK==dlg.DoModal()){
305 memcpy(&m_lf,dlg.m_cf.lpLogFont, sizeof LOGFONT);
309 void CViewOptions::OnSelchangePanecombo()
311 if(CMainFrame::PaneTypeMax!=m_FontChosen){
313 ((CComboBox *)GetDlgItem(IDC_PANECOMBO))->GetLBText(m_FontChosen,str);
314 if(IDYES==CUtils::MessageBoxFT(MB_YESNO,_T("Apply font changes to %s pane?"),(LPCTSTR)str)){
315 CMainFrame *pMain=CConfigTool::GetMain();
316 pMain->SetPaneFont(m_FontChosen, m_lf);
318 m_FontChosen=CMainFrame::PaneTypeMax;
322 CFileName CViewOptions::HeaderFileAssociation()
324 // Compute the association with header (.h) files
325 const CFileName strFile(CFileName::GetTempPath()+_T("tmp.h"));
328 if(f.Open(strFile,CFile::modeCreate|CFile::modeWrite)){
330 bool rc=((int)FindExecutable(strFile,_T("."),strExe.GetBuffer(MAX_PATH))>32);
331 strExe.ReleaseBuffer();
333 strExe=strExe.Tail();
337 ::DeleteFile(strFile);