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 // MainFrm.cpp : implementation of the CMainFrame class:
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
35 // Description: This is the implementation of the main frame class
42 //####DESCRIPTIONEND####
44 //===========================================================================
48 #define WM_SUBPROCESS (WM_USER+42)
50 #include "BinDirDialog.h"
51 #include "BuildOptionsDialog.h"
52 #include "CTOptionsDialog.h"
55 #include "ConfigItem.h"
56 #include "ConfigTool.h"
57 #include "ConfigToolDoc.h"
58 #include "ControlView.h"
60 #include "FindDialog.h"
61 #include "FolderDialog.h"
64 #include "MessageBox.h"
65 #include "PlatformsDialog.h"
67 #include "OutputView.h"
68 #include "PropertiesView.h"
69 #include "RegionGeneralPage.h"
70 #include "RulesView.h"
71 #include "SectionGeneralPage.h"
72 #include "SectionRelocationPage.h"
74 #include "SplitterWndEx.h"
75 #include "Subprocess.h"
76 #include "TestResource.h"
77 #include "ThinSplitter.h"
78 #include "ViewOptions.h"
80 #define INCLUDEFILE "build.hxx"
81 #include "IncludeSTL.h"
85 #include <windowsx.h> // for GET_X_LPARAM, GET_Y_LPARAM
90 static char THIS_FILE[] = __FILE__;
94 /////////////////////////////////////////////////////////////////////////////
97 IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
98 //UINT WM_FINDREPLACE = RegisterWindowMessage(FINDMSGSTRING);
100 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
101 //{{AFX_MSG_MAP(CMainFrame)
103 ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
104 ON_UPDATE_COMMAND_UI(ID_VIEW_PROPERTIES, OnUpdateViewProperties)
105 ON_COMMAND(ID_VIEW_MLT, OnViewMLT)
106 ON_COMMAND(ID_VIEW_SHORTDESC, OnViewShortdesc)
107 ON_UPDATE_COMMAND_UI(ID_VIEW_SHORTDESC, OnUpdateViewShortdesc)
108 ON_COMMAND(ID_VIEW_OUTPUT, OnViewOutput)
109 ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateViewOutput)
110 ON_UPDATE_COMMAND_UI(ID_BUILD_CONFIGURE, OnUpdateBuildConfigure)
111 ON_COMMAND(ID_BUILD_STOP, OnBuildStop)
112 ON_UPDATE_COMMAND_UI(ID_BUILD_STOP, OnUpdateBuildStop)
113 ON_COMMAND(ID_BUILD_CONFIGURE, OnConfigurationBuild)
115 ON_COMMAND(ID_BUILD_TESTS, OnBuildTests)
116 ON_UPDATE_COMMAND_UI(ID_BUILD_TESTS, OnUpdateBuildTests)
117 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
118 ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
119 ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
120 ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew)
121 ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit)
122 ON_UPDATE_COMMAND_UI(ID_VIEW_MLT, OnUpdateViewMLT)
124 ON_UPDATE_COMMAND_UI(ID_CONFIGURATION_REFRESH, OnUpdateConfigurationRefresh)
125 ON_COMMAND(ID_CONFIGURATION_REFRESH, OnConfigurationRefresh)
126 ON_COMMAND(ID_MENU_VIEW_SETTINGS, OnViewSettings)
127 ON_COMMAND(ID_TOOLS_PATHS, OnToolsPaths)
129 ON_UPDATE_COMMAND_UI(ID_CONFIGURATION_REPOSITORY, OnUpdateConfigurationRepository)
130 ON_COMMAND(ID_WINDOW_NEXT, OnWindowNext)
131 ON_COMMAND(ID_WINDOW_PREV, OnWindowPrev)
132 ON_COMMAND(ID_HELP_SUBMIT_PR, OnHelpSubmitPr)
133 ON_COMMAND(ID_HELP_ECOS, OnHelpEcos)
134 ON_COMMAND(ID_HELP_RED_HATONTHEWEB, OnHelpRedHatHome)
135 ON_COMMAND(ID_HELP_UITRON, OnHelpUitron)
136 ON_COMMAND(ID_HELP_ECOSHOME, OnHelpEcoshome)
137 ON_COMMAND(ID_RUN_SIM, OnRunSim)
138 ON_COMMAND(ID_BUILD_CLEAN, OnBuildClean)
139 ON_UPDATE_COMMAND_UI(ID_BUILD_CLEAN, OnUpdateBuildClean)
140 ON_COMMAND(ID_TOOLS_SHELL, OnToolsShell)
142 ON_COMMAND(ID_BUILD_OPTIONS, OnBuildOptions)
143 ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
144 ON_COMMAND(ID_USERTOOLS_PATHS, OnUsertoolsPaths)
145 ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
146 ON_UPDATE_COMMAND_UI(ID_RUN_SIM, OnUpdateRunSim)
147 ON_COMMAND(ID_VIEW_CONFLICTS, OnViewConflicts)
148 ON_UPDATE_COMMAND_UI(ID_VIEW_CONFLICTS, OnUpdateViewConflicts)
149 ON_COMMAND(ID_VIEW_MLTBAR, OnViewMltbar)
150 ON_UPDATE_COMMAND_UI(ID_VIEW_MLTBAR, OnUpdateViewMltbar)
151 ON_COMMAND(ID_RESOLVE_CONFLICTS, OnResolveConflicts)
152 ON_UPDATE_COMMAND_UI(ID_RESOLVE_CONFLICTS, OnUpdateResolveConflicts)
153 ON_COMMAND(ID_GO_HOME, OnGoHome)
155 ON_WM_INITMENUPOPUP()
156 ON_UPDATE_COMMAND_UI(ID_BUILD_OPTIONS, OnUpdateBuildOptions)
157 ON_MESSAGE(WM_SUBPROCESS,OnSubprocess)
158 ON_UPDATE_COMMAND_UI(ID_TOOLS_ADMINISTRATION, OnUpdateToolsAdministration)
160 ON_COMMAND(ID_EDIT_PLATFORMS, OnEditPlatforms)
162 ON_COMMAND(ID_HELP, OnHelp)
165 ON_NOTIFY(HHN_NAVCOMPLETE, ID_HHNOTIFICATION, OnNavComplete)
166 ON_NOTIFY(HHN_TRACK, ID_HHNOTIFICATION, OnNavComplete)
167 ON_NOTIFY(HHN_WINDOW_CREATE,ID_HHNOTIFICATION, OnNavComplete)
170 UINT CMainFrame::indicators[] =
172 ID_SEPARATOR, // status line indicator
174 ID_SEPARATOR, // status line indicator
178 bool CMainFrame::m_arMounted[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
180 /////////////////////////////////////////////////////////////////////////////
181 // CMainFrame construction/destruction
183 CMainFrame::CMainFrame():
184 m_pFindReplaceDialog(NULL),
186 m_nThermometerMax(0),
187 m_bFindInProgress(false),
188 m_bStatusBarCreated(false)
192 CMainFrame::~CMainFrame()
196 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
200 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
203 if (!m_wndToolBar.Create(this,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,AFX_IDW_TOOLBAR) ||
204 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
206 TRACE0("Failed to create toolbar\n");
207 return -1; // fail to create
210 if (!m_wndMLTToolBar.Create(this,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,AFX_IDW_TOOLBAR+1) ||
211 !m_wndMLTToolBar.LoadToolBar(IDR_MLTBAR))
213 TRACE0("Failed to create MLT toolbar\n");
214 return -1; // fail to create
216 m_bMLTToolbarVisible=true;
218 if (!m_wndStatusBar.Create(this) ||
219 !m_wndStatusBar.SetIndicators(indicators,
220 sizeof(indicators)/sizeof(UINT)))
222 TRACE0("Failed to create status bar\n");
223 return -1; // fail to create
225 m_bStatusBarCreated=true;
227 CFont *pOldFont=pDC->SelectObject(m_wndStatusBar.GetFont());
228 m_nThermometerPaneSize=100;
229 m_nPercentagePaneSize=pDC->GetTextExtent(_T("100%")).cx;
230 m_nFailRulePaneSize=pDC->GetTextExtent(_T("333 conflicts")).cx;
231 pDC->SelectObject(pOldFont);
235 m_wndStatusBar.GetItemRect(ThermometerPane, rect);
237 m_Progress.Create(WS_VISIBLE|WS_CHILD|PBS_SMOOTH, rect,&m_wndStatusBar, ID_THERMOMETER);
238 m_Progress.SetRange(0,100);
239 m_Progress.SetPos(0);
241 //CConfigTool::GetConfigToolDoc()->UpdateFailingRuleCount();
242 // TODO: Delete these three lines if you don't want the toolbar to
244 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
245 m_wndMLTToolBar.EnableDocking(CBRS_ALIGN_ANY);
247 EnableDocking(CBRS_ALIGN_ANY);
248 DockControlBar(&m_wndToolBar);
249 DockControlBar(&m_wndMLTToolBar);
251 CSplashWnd::ShowSplashScreen(this);
256 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
258 //cs.style|=~FWS_ADDTOTITLE;
259 return CFrameWnd::PreCreateWindow(cs);
262 /////////////////////////////////////////////////////////////////////////////
263 // CMainFrame diagnostics
266 void CMainFrame::AssertValid() const
268 CFrameWnd::AssertValid();
271 void CMainFrame::Dump(CDumpContext& dc) const
278 /////////////////////////////////////////////////////////////////////////////
279 // CMainFrame message handlers
280 CMainFrame::ViewStruct CMainFrame::arView[PaneTypeMax]={
281 CMainFrame::ViewStruct(_T("Cell"), true,RUNTIME_CLASS(CCellView)),
282 CMainFrame::ViewStruct(_T("Configuration"), true,RUNTIME_CLASS(CControlView)),
283 CMainFrame::ViewStruct(_T("Short Description"), true,RUNTIME_CLASS(CDescView)),
284 CMainFrame::ViewStruct(_T("Output"), true,RUNTIME_CLASS(COutputView)),
285 CMainFrame::ViewStruct(_T("Properties"), true,RUNTIME_CLASS(CPropertiesView)),
286 CMainFrame::ViewStruct(_T("Rules"), false,RUNTIME_CLASS(CRulesView)),
287 CMainFrame::ViewStruct(_T("Memory Layout"), false,RUNTIME_CLASS(CMLTView))
290 // This data defines the layout of the nested splitters
291 CMainFrame::Split CMainFrame::arSplit[]={
292 CMainFrame::Split(Horz,1,0.8),
293 CMainFrame::Split(Horz,2,0.7),
294 CMainFrame::Split(Vert,3,0.5),
295 CMainFrame::Split(Thin,4,0.4),
296 CMainFrame::Split(Control,5),
297 CMainFrame::Split(Cell,5),
298 CMainFrame::Split(Horz,4,0.6),
299 CMainFrame::Split(Rules,5),
300 CMainFrame::Split(Horz,5,0.5),
301 CMainFrame::Split(Properties,6),
302 CMainFrame::Split(ShortDesc,6),
303 CMainFrame::Split(MLT,3),
304 CMainFrame::Split(Output,2)
307 BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
309 for(int i=0;i<sizeof arView/sizeof arView[0];i++){
310 ViewStruct &v=arView[(PaneType)i];
311 v.bVisible=GetApp()->GetProfileInt(_T("Windows"),v.pszName,v.bVisible);
314 GetClientRect(rcClient);
318 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
320 // x Tree (T)| Cell(T) | x
321 // x ^^^^^^^^^^^^^^^^^^| Rules (2) x
323 // x | |---------------------------x
325 // x | | Properties (2) x
326 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
328 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
332 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
334 for(i=0;i<sizeof arSplit/sizeof arSplit[0];i++){
335 const CSize szDefault(50,50);
337 CSplitterWndEx *pParent=NULL;
341 // Search backwards for our parent. This is the first entry back of level one higher.
342 for(int j=i-1;j>=0;--j){
343 Split &sp=arSplit[j];
344 if(sp.nLevel==s.nLevel-1){
346 nRowParent=(bSecond && Horz==sp.type);
347 nColParent=(bSecond && Horz!=sp.type);
349 } else if(sp.nLevel==s.nLevel){
353 if(s.type>=0 /* a view */){
354 TRACE(_T("Create view index=%d [%s]\n"),i,arView[s.type].pszName);
355 VERIFY(pParent->CreateView (nRowParent, nColParent, arView[s.type].pClass, szDefault, pContext));
356 arView[s.type].pView=(CView *)pParent->GetPane(nRowParent,nColParent);
357 arView[s.type].pParent=pParent;
359 int nRows=1+(Horz==s.type);
360 int nCols=1+(Horz!=s.type);
365 id=AFX_IDW_PANE_FIRST;
367 id=pParent->IdFromRowCol(nRowParent,nColParent);
371 TRACE(_T("Create thin splitter index=%d\n"),i);
372 s.pSplit=new CThinSplitter;
373 VERIFY(s.pSplit->CreateStatic (pParent, 1, 2, WS_CHILD|WS_VISIBLE|WS_BORDER, id));
374 s.pSplit->SetScrollStyle(WS_VSCROLL);
376 TRACE(_T("Create splitter index=%d\n"),i);
377 s.pSplit=new CSplitterWndEx;
378 VERIFY(s.pSplit->CreateStatic (pwndParent, nRows, nCols, WS_CHILD|WS_VISIBLE|WS_BORDER, id));
383 for(i=0;i<PaneTypeMax;i++){
385 ViewStruct &v=arView[(PaneType)i];
386 GetApp()->LoadFont(v.pszName,lf);
387 if(!arView[(PaneType)i].font.CreateFontIndirect(&lf)){
388 CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT))->GetLogFont(&lf);
390 SetPaneFont((PaneType)i,lf);
391 //v.pParent->ShowPane(v.pView,v.bVisible);
394 for(i=0;i<sizeof arSplit/sizeof arSplit[0];i++){
397 s.pSplit->RecalcLayout();
401 UNUSED_ALWAYS(lpcs); // avoid compiler warning
405 void CMainFrame::OnViewProperties()
407 arView[Properties].bVisible^=1;
408 arView[Properties].pParent->ShowPane(arView[Properties].pView,arView[Properties].bVisible);
411 void CMainFrame::OnUpdateViewProperties(CCmdUI* pCmdUI)
413 pCmdUI->SetCheck(arView[Properties].bVisible);
416 void CMainFrame::OnViewMLT()
418 arView[MLT].bVisible^=1;
419 arView[MLT].pParent->ShowPane(arView[MLT].pView,arView[MLT].bVisible);
420 ShowControlBar(&m_wndMLTToolBar,arView[MLT].bVisible&m_bMLTToolbarVisible,false);
423 void CMainFrame::OnViewShortdesc()
425 arView[ShortDesc].bVisible^=1;
426 arView[ShortDesc].pParent->ShowPane(arView[ShortDesc].pView,arView[ShortDesc].bVisible);
429 void CMainFrame::OnUpdateViewShortdesc(CCmdUI* pCmdUI)
431 pCmdUI->SetCheck(arView[ShortDesc].bVisible);
434 void CMainFrame::OnViewOutput()
436 arView[Output].bVisible^=1;
437 arView[Output].pParent->ShowPane(arView[Output].pView,arView[Output].bVisible);
440 void CMainFrame::OnUpdateViewOutput(CCmdUI* pCmdUI)
442 pCmdUI->SetCheck(arView[Output].bVisible);
445 void CMainFrame::OnUpdateBuildConfigure(CCmdUI* pCmdUI)
447 pCmdUI->Enable(!m_sp.ProcessAlive());
450 void CMainFrame::OnBuildStop()
452 m_sp.Kill(); // leave the rest to OnSubprocessComplete()
455 void CMainFrame::OnUpdateBuildStop(CCmdUI* pCmdUI)
457 pCmdUI->Enable(m_sp.ProcessAlive());
460 void CMainFrame::OnConfigurationBuild()
465 DWORD CMainFrame::ThreadFunc(LPVOID param)
467 CMainFrame *pMain=(CMainFrame *)param;
468 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
469 CString strCmd(_T("make -n "));
470 strCmd+=pMain->m_strBuildTarget;
471 SetCurrentDirectory(pDoc->BuildTree());
474 sp.Run(strOut,strCmd);
475 // Don't attempt to change the thermometer itself - not safe from a separate thread
476 pMain->m_nThermometerMax=pDoc->GetCompilationCount(strOut);
481 void CMainFrame::Build(const CString &strWhat/*=_T("")*/)
483 ASSERT(!m_sp.ProcessAlive());
484 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
486 if(!arView[Output].bVisible){
487 SendMessage(WM_COMMAND,ID_VIEW_OUTPUT,0);
490 if(pDoc->IsModified()||pDoc->BuildTree().IsEmpty()){
491 SendMessage (WM_COMMAND, ID_FILE_SAVE);
494 if(!(pDoc->IsModified()||pDoc->BuildTree().IsEmpty())){ // verify the save worked
495 CString strCmd (_T("make"));
496 if(!strWhat.IsEmpty()){
500 if(!GetApp()->m_strMakeOptions.IsEmpty()){
502 strCmd+=GetApp()->m_strMakeOptions;
505 strCmd += _T(" --directory ");
507 // Quoting the name may not mix with the 'sh' command on Unix, so only do it
508 // under Windows where it's more likely there will be spaces needing quoting.
510 CString buildDir(pDoc->BuildTree());
512 #if 1 // ecUSE_ECOS_X_NOTATION
513 std::string cPath = cygpath(std::string(pDoc->BuildTree()));
514 buildDir = cPath.c_str();
516 strCmd += CString(_T("\"")) + buildDir + CString(_T("\""));
518 strCmd += CString(pDoc->BuildTree()) ;
521 if(PrepareEnvironment()){
522 m_strBuildTarget=strWhat;
523 SetThermometerMax(250); // This is just a guess. The thread we are about to spawn will work out the correct answer
525 UpdateThermometer(0);
526 CloseHandle(CreateThread(NULL, 0, ThreadFunc, this, 0 ,&m_dwThreadId));
528 strMsg.Format(_T("Building %s"),strWhat);
529 SetIdleMessage(strMsg);
531 SetTimer(42,1000,0); // This timer checks for process completion
532 SetCurrentDirectory(pDoc->BuildTree());
533 m_sp.Run(SubprocessOutputFunc, this, strCmd, false);
540 CConfigToolApp * CMainFrame::GetApp()
542 return (CConfigToolApp *)AfxGetApp();
545 void CMainFrame::ActivateFrame(int nCmdShow)
547 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
549 SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcDefault, 0);
550 // Insist on nothing more than 1000 width, with the golden ratio
551 rcDefault.DeflateRect(max(0,(rcDefault.Width()-1000)/2),max(0,(rcDefault.Height()-618)/2));
553 GetApp()->RestoreWindowPlacement (this, _T("Window size"),rcDefault);
554 LoadBarState(_T("DockState"));
556 ShowControlBar(&m_wndMLTToolBar,arView[MLT].bVisible,false);
557 CFrameWnd::ActivateFrame(nCmdShow); // must be before we muck about with the splitters
560 GetClientRect(rcClient);
561 for(int j=0;j<sizeof arSplit/sizeof arSplit[0];j++){
565 strKey.Format(_T("Split %d"),j);
566 const CString strSplit(GetApp()->GetProfileString(_T("Split"),strKey));
567 double fSplit=s.fFrac;
568 _tscanf(_T("%f"),&fSplit);
569 s.pSplit->SetSplitPoint(fSplit);
570 s.pSplit->RecalcLayout();
574 for(int i=0;i<PaneTypeMax;i++){
575 ViewStruct &v=arView[(PaneType)i];
576 v.pParent->ShowPane(v.pView,v.bVisible);
580 pDoc->UpdateFailingRuleCount();
584 void CMainFrame::OnDestroy()
587 GetApp()->SaveWindowPlacement (this, _T("Window size"));
589 for(int i=0;i<PaneTypeMax;i++){
591 ViewStruct &v=arView[(PaneType)i];
592 v.font.GetLogFont(&lf);
593 GetApp()->SaveFont(v.pszName,lf);
595 for(int j=0;j<sizeof arSplit/sizeof arSplit[0];j++){
599 strSplit.Format(_T("%f"),s.pSplit->GetSplitPoint());
601 strKey.Format(_T("%d"),j);
602 GetApp()->WriteProfileString(_T("Split"),strKey,strSplit);
605 for(j=0;j<sizeof arSplit/sizeof arSplit[0];j++){
612 if(m_sp.ProcessAlive()){
616 for(i=0;i<sizeof arView/sizeof arView[0];i++){
617 GetApp()->WriteProfileInt(_T("Windows"), arView[i].pszName, arView[i].bVisible);
620 CFrameWnd::OnDestroy();
623 void CMainFrame::OnBuildTests()
628 void CMainFrame::OnUpdateBuildTests(CCmdUI* pCmdUI)
630 pCmdUI->Enable(!m_sp.ProcessAlive());
633 void CMainFrame::OnUpdateFileSave(CCmdUI* pCmdUI)
635 pCmdUI->Enable(!m_sp.ProcessAlive());
638 void CMainFrame::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
640 pCmdUI->Enable(!m_sp.ProcessAlive());
643 void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI)
645 pCmdUI->Enable(!m_sp.ProcessAlive());
648 void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI)
650 pCmdUI->Enable(!m_sp.ProcessAlive());
653 void CMainFrame::OnUpdateAppExit(CCmdUI* pCmdUI)
655 pCmdUI->Enable(!m_sp.ProcessAlive());
658 void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
660 CFrameWnd::OnSysCommand(nID, lParam);
664 void CMainFrame::OnUpdateConfigurationRefresh(CCmdUI* pCmdUI)
666 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
667 pCmdUI->Enable(!m_sp.ProcessAlive() && !pDoc->BuildTree().IsEmpty());
670 void CMainFrame::OnConfigurationRefresh()
672 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
676 void CMainFrame::OnViewSettings()
682 void CMainFrame::OnHelp() // Help->Configuration Tool Help
684 CConfigTool::GetConfigToolDoc()->ShowURL(CUtils::LoadString(IDS_CONFIGTOOL_HELP));
687 void CMainFrame::OnSize(UINT nType, int cx, int cy)
689 CFrameWnd::OnSize(nType, cx, cy);
691 cx=max(0,cx-m_nFailRulePaneSize-m_nThermometerPaneSize-m_nPercentagePaneSize);
692 m_wndStatusBar.SetPaneInfo(StatusPane, 0, SBPS_STRETCH , 0);
693 m_wndStatusBar.SetPaneInfo(ThermometerPane, 0, SBPS_NORMAL, m_nThermometerPaneSize);
694 m_wndStatusBar.SetPaneInfo(PercentagePane, 0, SBPS_NORMAL, m_nPercentagePaneSize);
695 m_wndStatusBar.SetPaneInfo(FailRulePane, 0, SBPS_NORMAL, m_nFailRulePaneSize);
697 m_wndStatusBar.GetItemRect(ThermometerPane, rc);
698 // Reposition the progress control correctly!
699 m_Progress.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0);
703 void CMainFrame::OnUpdateConfigurationRepository(CCmdUI* pCmdUI)
705 pCmdUI->Enable(!m_sp.ProcessAlive());
708 void CMainFrame::OnWindowNext()
713 void CMainFrame::OnWindowPrev()
718 void CMainFrame::BumpWindow(int nInc)
720 CWnd *pWnd=CWnd::GetFocus();
722 int nWindows=sizeof arView/sizeof arView[0];
723 for(int i=0;i<nWindows;i++){
724 CWnd *pThisWnd=arView[i].pView;
725 if(pWnd->m_hWnd==pThisWnd->m_hWnd){
726 for(int j=((i+nInc+nWindows)%nWindows);j!=i;j=((j+nInc+nWindows)%nWindows)){
727 if(arView[j].bVisible){
728 arView[j].pView->SetFocus();
737 void CMainFrame::OnHelpSubmitPr()
740 if(strURL.LoadString(IDS_ECOS_PR_URL)){
741 CConfigTool::GetConfigToolDoc()->ShowURL(strURL);
745 void CMainFrame::OnHelpEcos()
748 if(strURL.LoadString(IDS_ECOS_SOURCEWARE_URL)){
749 CConfigTool::GetConfigToolDoc()->ShowURL(strURL);
753 void CMainFrame::OnHelpEcoshome()
756 if(strURL.LoadString(IDS_ECOS_HOME_URL)){
757 CConfigTool::GetConfigToolDoc()->ShowURL(strURL);
761 void CMainFrame::OnHelpRedHatHome()
764 if(strURL.LoadString(IDS_RED_HAT_HOME_URL)){
765 CConfigTool::GetConfigToolDoc()->ShowURL(strURL);
769 void CMainFrame::OnHelpUitron()
772 if(strURL.LoadString(IDS_UITRON_HOME_URL)){
773 CConfigTool::GetConfigToolDoc()->ShowURL(strURL);
777 void CMainFrame::OnBuildClean()
782 void CMainFrame::OnUpdateBuildClean(CCmdUI* pCmdUI)
784 pCmdUI->Enable(!m_sp.ProcessAlive());
787 void CMainFrame::OnToolsShell()
789 if(PrepareEnvironment()){
791 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
792 const CFileName strOldFolder(CFileName::SetCurrentDirectory(pDoc->BuildTree()));
793 CUtils::Launch(_T(""),CUtils::LoadString(IDS_SHELL_NAME));
794 if(!strOldFolder.IsEmpty()){ // if the current directory was changed
795 SetCurrentDirectory(strOldFolder); // restore the previous current directory
800 bool CMainFrame::PrepareEnvironment(bool bWithBuildTools /* = true */)
803 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
804 CConfigToolApp *pApp=(CConfigToolApp *)GetApp();
805 ::SetEnvironmentVariable(_T("PATH"),pApp->m_strOriginalPath);
807 const CString strPrefix(pDoc->CurrentTargetPrefix());
810 bool rc=(! bWithBuildTools) || pApp->m_arstrBinDirs.Lookup(strPrefix,strBinDir);
812 SendMessage(WM_COMMAND,ID_TOOLS_PATHS,0);
813 rc=pApp->m_arstrBinDirs.Lookup(strPrefix,strBinDir);
818 CFileName strUserBinDir(pApp->m_strUserToolsDir);
819 if(strUserBinDir.IsEmpty()){
820 if(1==pDoc->m_arstrUserToolPaths.GetSize()){
821 pApp->m_strUserToolsDir=pDoc->m_arstrUserToolPaths[0];
823 SendMessage(WM_COMMAND,ID_USERTOOLS_PATHS,0);
825 strUserBinDir=pApp->m_strUserToolsDir;
827 if(!strUserBinDir.IsEmpty()){
829 // calculate the directory of the host tools from this application's module name
830 CFileName strHostToolsBinDir;
831 ::GetModuleFileName (::GetModuleHandle (NULL), strHostToolsBinDir.GetBuffer (1 + MAX_PATH), MAX_PATH);
832 strHostToolsBinDir.ReleaseBuffer ();
833 strHostToolsBinDir = strHostToolsBinDir.Head ();
835 strHostToolsBinDir = _T("C:\\Progra~1\\Redhat~1\\eCos");
838 // tools directories are in the order host-tools, user-tools, comp-tools, install/bin (if present), contrib-tools (if present) on the path
839 const CFileName strContribBinDir(strUserBinDir,_T("..\\contrib\\bin"));
840 CFileName strUsrBinDir(strUserBinDir,_T("..\\usr\\bin"));
841 const CFileName strInstallBinDir(pDoc->InstallTree (),_T("bin"));
843 // In case strUserBinDir is e.g. c:\program files\red hat\cygwin-00r1\usertools\h-i686-pc-cygwin\bin
844 if (!strUsrBinDir.IsDir ())
845 strUsrBinDir = CFileName(strUserBinDir + _T("..\\..\\..\\H-i686-pc-cygwin\\bin"));
848 (strUsrBinDir.IsDir () && ! CUtils::AddToPath (strUsrBinDir)) ||
849 (strContribBinDir.IsDir () && ! CUtils::AddToPath (strContribBinDir)) ||
850 (strInstallBinDir.IsDir () && ! CUtils::AddToPath (strInstallBinDir)) ||
851 (bWithBuildTools && ! CUtils::AddToPath (strBinDir)) ||
852 ! CUtils::AddToPath (strUserBinDir) ||
853 ! CUtils::AddToPath (strHostToolsBinDir)) {
854 CUtils::MessageBoxF(_T("Failed to set PATH environment variable - rc=%d"),GetLastError());
857 if(!SetEnvironmentVariable(_T("MAKE_MODE"),_T("unix"))){
858 CUtils::MessageBoxF(_T("Failed to set MAKE_MODE environment variable - rc=%d"),GetLastError());
861 SetEnvironmentVariable(_T("GDBTK_LIBRARY"),NULL);
862 SetEnvironmentVariable(_T("GCC_EXEC_PREFIX"),NULL);
863 SetEnvironmentVariable(_T("ECOS_REPOSITORY"),pDoc->PackagesDir()); // useful for ecosconfig
865 if (! pDoc->BuildTree().IsEmpty())
866 CygMount(pDoc->BuildTree()[0]);
867 if (! pDoc->InstallTree().IsEmpty())
868 CygMount(pDoc->InstallTree()[0]);
869 if (! pDoc->Repository().IsEmpty())
870 CygMount(pDoc->Repository()[0]);
874 ::GetEnvironmentVariable(_T("PATH"), buf, 512);
875 CConfigTool::Log(buf);
886 void CMainFrame::OnClose()
888 if(m_sp.ProcessAlive()){
889 if(IDNO==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2,_T("A build is in progress: exit anyway?"))){
894 SaveBarState(_T("DockState"));
895 CFrameWnd::OnClose();
898 void CMainFrame::OnBuildOptions()
900 CBuildOptionsDialog dlg;
904 void CMainFrame::OnUpdateBuildOptions(CCmdUI* pCmdUI)
906 pCmdUI->Enable(TRUE);
909 void CMainFrame::OnToolsOptions()
911 CToolsOptionsDialog dlg;
915 void CMainFrame::OnUpdateViewMLT(CCmdUI* pCmdUI)
917 pCmdUI->SetCheck(arView[MLT].bVisible);
920 void CMainFrame::OnViewConflicts()
922 arView[Rules].bVisible^=1;
923 arView[Rules].pParent->ShowPane(arView[Rules].pView,arView[Rules].bVisible);
926 void CMainFrame::OnUpdateViewConflicts(CCmdUI* pCmdUI)
928 pCmdUI->SetCheck(arView[Rules].bVisible);
931 void CMainFrame::OnToolsPaths()
933 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
934 CConfigToolApp *pApp=(CConfigToolApp *)GetApp();
937 const CString strPrefix(pDoc->CurrentTargetPrefix());
939 CStringArray arstrPaths;
940 for(POSITION pos = pApp->m_arstrBinDirs.GetStartPosition(); pos != NULL; ){
942 pApp->m_arstrBinDirs.GetNextAssoc(pos, strP, strB);
944 arstrPaths.Add(strB);
950 CBinDirDialog dlg(arstrPaths,strDefault);
952 dlg.m_strDesc.Format(CUtils::LoadString(IDS_COMPTOOLS_DLG_DESC),strPrefix.IsEmpty()?_T("native"):strPrefix,strPrefix.IsEmpty()?_T(""):strPrefix+_T("-"));
953 dlg.m_strTitle=_T("Build Tools");
955 if(IDOK==dlg.DoModal()){
957 strExe.Format(_T("%s\\%s%sgcc.exe"),dlg.m_strFolder,strPrefix,strPrefix.IsEmpty()?_T(""):_T("-"));
959 IDYES==CUtils::MessageBoxFT(MB_YESNO,_T("%s does not appear to contain the build tools - use this folder anyway?"),dlg.m_strFolder)){
960 pApp->m_arstrBinDirs.SetAt(strPrefix,dlg.m_strFolder);
965 void CMainFrame::OnUsertoolsPaths()
967 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
968 CConfigToolApp * pApp = (CConfigToolApp *) GetApp ();
970 CStringArray arstrPaths;
971 arstrPaths.Copy(pDoc->m_arstrUserToolPaths);
972 if(!pApp->m_strUserToolsDir.IsEmpty()){
973 arstrPaths.Add(pApp->m_strUserToolsDir);
975 CBinDirDialog dlg(arstrPaths, pApp->m_strUserToolsDir);
977 dlg.m_strDesc.LoadString(IDS_USERTOOLS_DLG_DESC);
978 dlg.m_strTitle=_T("User Tools");
980 if(IDOK==dlg.DoModal()){
981 CFileName strFile(dlg.m_strFolder);
982 strFile+=_T("ls.exe");
983 if(strFile.Exists()||
984 IDYES==CUtils::MessageBoxFT(MB_YESNO,_T("%s does not appear to contain the user tools - use this folder anyway?"),dlg.m_strFolder)){
985 pApp->m_strUserToolsDir=dlg.m_strFolder;
990 void CMainFrame::UpdateThermometer(int nLines)
992 if(nLines>=0 && 0!=m_nThermometerMax){
993 int nPercentage=min(100,(100*nLines)/m_nThermometerMax);
994 m_Progress.SetPos(nPercentage);
997 str.Format(_T("%d%%"),nPercentage);
999 m_wndStatusBar.SetPaneText(PercentagePane,str);
1003 void CMainFrame::SetThermometerMax (int nMax)
1006 UpdateThermometer(0);
1008 m_nThermometerMax=nMax;
1011 LRESULT CMainFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
1013 if (AFX_IDS_IDLEMESSAGE==wParam){
1015 lParam=(LPARAM)(LPCTSTR )m_strIdleMessage;
1017 return CFrameWnd::OnSetMessageString(wParam, lParam);
1020 void CMainFrame::SetIdleMessage (LPCTSTR pszIdleMessage)
1022 if(NULL==pszIdleMessage){
1023 m_strIdleMessage.LoadString(AFX_IDS_IDLEMESSAGE);
1025 m_strIdleMessage=pszIdleMessage;
1027 SendMessage(WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE, 0);
1030 void CMainFrame::OnRunSim()
1032 CConfigTool::GetConfigToolDoc()->RunTests();
1035 bool CMainFrame::SetPaneFont(PaneType pane,const LOGFONT &lf)
1037 CFont &font=arView[pane].font;
1039 font.CreateFontIndirect(&lf);
1042 CConfigTool::GetOutputView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1045 CConfigTool::GetDescView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1046 CConfigTool::GetDescView()->Invalidate();
1050 CConfigTool::GetControlView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1051 CConfigTool::GetCellView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1052 CConfigTool::GetControlView()->Invalidate();
1053 CConfigTool::GetCellView()->Invalidate();
1056 CConfigTool::GetPropertiesView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1057 CConfigTool::GetPropertiesView()->Invalidate();
1060 CConfigTool::GetRulesView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1061 CConfigTool::GetRulesView()->Invalidate();
1064 CConfigTool::GetRulesView()->SendMessage(WM_SETFONT, (WPARAM)(HFONT)font, 0);
1065 CConfigTool::GetRulesView()->Invalidate();
1074 CFont &CMainFrame::GetPaneFont(PaneType pane)
1076 return arView[pane].font;
1079 void CMainFrame::OnUpdateRunSim(CCmdUI* pCmdUI)
1081 pCmdUI->Enable(!CConfigTool::GetConfigToolDoc()->InstallTree().IsEmpty() && !m_sp.ProcessAlive());
1084 void CMainFrame::SetFailRulePane(int nCount)
1090 strCount = _T("No conflicts");
1093 strCount = _T("1 conflict");
1096 strCount.Format (_T("%d conflicts"), nCount);
1099 if(m_bStatusBarCreated){
1100 m_wndStatusBar.SetPaneText (FailRulePane, strCount);
1104 void CMainFrame::OnUpdateFrameTitle (BOOL bAddToTitle)
1106 if ((GetStyle() & FWS_ADDTOTITLE) == 0)
1107 return; // leave it alone!
1109 #ifndef _AFX_NO_OLE_SUPPORT
1110 // allow hook to set the title (used for OLE support)
1111 if (m_pNotifyHook != NULL && m_pNotifyHook->OnUpdateFrameTitle())
1115 CDocument* pDoc=CConfigTool::GetConfigToolDoc();
1116 if (bAddToTitle && pDoc != NULL)
1117 UpdateFrameTitleForDocument(pDoc->GetTitle() + (pDoc->IsModified () ? "*" : ""));
1119 UpdateFrameTitleForDocument(NULL);
1122 void CMainFrame::OnViewMltbar()
1124 m_bMLTToolbarVisible^=1;
1125 ShowControlBar(&m_wndMLTToolBar,m_bMLTToolbarVisible,false);
1128 void CMainFrame::OnUpdateViewMltbar(CCmdUI* pCmdUI)
1130 pCmdUI->Enable(arView[MLT].bVisible);
1131 pCmdUI->SetCheck(m_bMLTToolbarVisible);
1134 void CMainFrame::OnResolveConflicts()
1136 if(CConfigToolDoc::NotDone==CConfigTool::GetConfigToolDoc()->ResolveGlobalConflicts()){
1137 // Global inference handler was never invoked. Say something
1138 CUtils::MessageBoxF(_T("No solutions can be automatically determined for the current set of conflicts."));
1142 void CMainFrame::OnUpdateResolveConflicts(CCmdUI* pCmdUI)
1144 pCmdUI->Enable(CConfigTool::GetConfigToolDoc()->GetCdlInterpreter()->get_toplevel()->get_all_conflicts().size()>0);
1147 void CMainFrame::OnGoHome() // Help->eCos Documentation
1149 CConfigTool::GetConfigToolDoc()->ShowURL(CUtils::LoadString(IDS_ECOS_HELP));
1152 HMENU CMainFrame::NewMenu()
1154 // Load the menu from the resources
1155 m_menu.LoadMenu(IDR_MAINFRAME);
1157 m_menu.LoadToolbar(IDR_MAINFRAME);
1158 m_menu.LoadToolbar(IDR_MISCBAR);
1160 m_menu.ModifyODMenu(NULL,ID_HELP,IDB_HELP);
1161 m_menu.ModifyODMenu(NULL,ID_GO_HOME,IDB_HELP);
1162 m_menu.ModifyODMenu(NULL,ID_HELP_RED_HATONTHEWEB,IDB_HTML);
1163 m_menu.ModifyODMenu(NULL,ID_HELP_ECOSHOME,IDB_HTML);
1164 m_menu.ModifyODMenu(NULL,ID_HELP_ECOS,IDB_HTML);
1165 m_menu.ModifyODMenu(NULL,ID_HELP_UITRON,IDB_HTML);
1167 return(m_menu.Detach());
1171 //This handler ensure that the popup menu items are drawn correctly
1172 void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
1175 if(lpMeasureItemStruct->CtlType==ODT_MENU){
1176 if(IsMenu((HMENU)lpMeasureItemStruct->itemID)){
1177 CMenu* cmenu=CMenu::FromHandle((HMENU)lpMeasureItemStruct->itemID);
1178 if(BCMenu::IsMenu(cmenu)){
1179 m_menu.MeasureItem(lpMeasureItemStruct);
1184 if(!setflag)CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
1187 //This handler ensures that keyboard shortcuts work
1188 LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
1191 if(BCMenu::IsMenu(pMenu))
1192 lresult=BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
1194 lresult=CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
1198 //This handler updates the menus from time to time
1199 void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
1201 CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
1203 if(BCMenu::IsMenu(pPopupMenu))BCMenu::UpdateMenu(pPopupMenu);
1207 void CALLBACK CMainFrame::SubprocessOutputFunc(void *pParam,LPCTSTR psz)
1209 LPTSTR pszCopy=new TCHAR[1+_tcslen(psz)];
1210 _tcscpy(pszCopy,psz);
1211 // Post a message to the mainframe because it wouldn't be safe to manipulate controls from a different thread
1212 ((CMainFrame *)pParam)->PostMessage(WM_SUBPROCESS,(WPARAM)pszCopy);
1215 LRESULT CMainFrame::OnSubprocess(WPARAM wParam, LPARAM)
1217 LPTSTR psz=(LPTSTR)wParam;
1218 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
1219 m_nLogicalLines+=pDoc->GetCompilationCount(psz);
1220 UpdateThermometer (m_nLogicalLines);
1221 CConfigTool::GetOutputView()->AddText(psz);
1226 void CMainFrame::OnUpdateToolsAdministration(CCmdUI* pCmdUI)
1228 pCmdUI->Enable(!m_sp.ProcessAlive());
1231 void CMainFrame::CygMount(TCHAR c)
1233 // May not be alpha if it's e.g. a UNC network path
1238 if(!m_arMounted[c-_TCHAR('a')]){
1239 m_arMounted[c-_TCHAR('a')]=true;
1243 strCmd.Format(_T("mount %c: /ecos-%c"),c,c);
1245 sub.Run(strOutput,strCmd);
1249 BOOL CMainFrame::OnHelpInfo(HELPINFO* pHelpInfo)
1251 // TODO: Add your message handler code here and/or call default
1253 return CFrameWnd::OnHelpInfo(pHelpInfo);
1256 void CMainFrame::OnNavComplete(NMHDR* pHdr, LRESULT*)
1258 TRACE(_T("HH Notify\n"));
1261 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
1263 if(WM_NOTIFY==pMsg->message){
1264 LPNMHDR pHdr=(LPNMHDR)pMsg->lParam;
1265 TRACE(_T("WM_NOTIFY id=%d idFrom=%d code=%d\n"),pMsg->wParam,pHdr->idFrom,pHdr->code);
1268 return CFrameWnd::PreTranslateMessage(pMsg);
1271 void CMainFrame::OnEditPlatforms()
1273 CPlatformsDialog dlg;
1274 if(IDOK==dlg.DoModal()){
1275 CeCosTestPlatform::RemoveAllPlatforms();
1276 for(unsigned int i=0;i<dlg.PlatformCount();i++){
1277 CeCosTestPlatform::Add(*dlg.Platform(i));
1279 CeCosTestPlatform::Save();
1283 void CMainFrame::OnTimer(UINT nIDEvent)
1285 if(!m_sp.ProcessAlive()){
1286 KillTimer(nIDEvent);
1288 TRACE(_T("m_nThermometerMax=%d m_nLogicalLines=%d\n"),m_nThermometerMax,m_nLogicalLines);
1289 if(0==m_sp.GetExitCode){
1290 UpdateThermometer(m_nThermometerMax);
1291 Sleep(250); // Allow user to see it
1293 UpdateThermometer(0);
1294 SetThermometerMax(0);
1296 CFrameWnd::OnTimer(nIDEvent);