Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/OutputWnd.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 
00004 #include "OutputWnd.h"
00005 #include "Resource.h"
00006 #include "MainFrm.h"
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013 
00015 // COutputBar
00016 
00017 COutputWnd::COutputWnd()
00018 {
00019 }
00020 
00021 COutputWnd::~COutputWnd()
00022 {
00023 }
00024 
00025 BEGIN_MESSAGE_MAP(COutputWnd, CDockablePane)
00026         ON_WM_CREATE()
00027         ON_WM_SIZE()
00028 END_MESSAGE_MAP()
00029 
00030 int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00031 {
00032         if (CDockablePane::OnCreate(lpCreateStruct) == -1)
00033                 return -1;
00034 
00035         CRect rectDummy;
00036         rectDummy.SetRectEmpty();
00037 
00038         // Create tabs window:
00039         if (!m_wndTabs.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, 1))
00040         {
00041                 TRACE0("Failed to create output tab window\n");
00042                 return -1;      // fail to create
00043         }
00044 
00045         // Create output panes:
00046         const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
00047 
00048         if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_wndTabs, 2) ||
00049                 !m_wndOutputDebug.Create(dwStyle, rectDummy, &m_wndTabs, 3) ||
00050                 !m_wndOutputFind.Create(dwStyle, rectDummy, &m_wndTabs, 4))
00051         {
00052                 TRACE0("Failed to create output windows\n");
00053                 return -1;      // fail to create
00054         }
00055 
00056         UpdateFonts();
00057 
00058         CString strTabName;
00059         BOOL bNameValid;
00060 
00061         // Attach list windows to tab:
00062         bNameValid = strTabName.LoadString(IDS_BUILD_TAB);
00063         ASSERT(bNameValid);
00064         m_wndTabs.AddTab(&m_wndOutputBuild, strTabName, (UINT)0);
00065         bNameValid = strTabName.LoadString(IDS_DEBUG_TAB);
00066         ASSERT(bNameValid);
00067         m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);
00068         bNameValid = strTabName.LoadString(IDS_FIND_TAB);
00069         ASSERT(bNameValid);
00070         m_wndTabs.AddTab(&m_wndOutputFind, strTabName, (UINT)2);
00071 
00072         // Fill output tabs with some dummy text (nothing magic here)
00073         FillBuildWindow();
00074         FillDebugWindow();
00075         FillFindWindow();
00076 
00077         return 0;
00078 }
00079 
00080 void COutputWnd::OnSize(UINT nType, int cx, int cy)
00081 {
00082         CDockablePane::OnSize(nType, cx, cy);
00083 
00084         // Tab control should cover the whole client area:
00085         m_wndTabs.SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
00086 }
00087 
00088 void COutputWnd::AdjustHorzScroll(CListBox& wndListBox)
00089 {
00090         CClientDC dc(this);
00091         CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
00092 
00093         int cxExtentMax = 0;
00094 
00095         for (int i = 0; i < wndListBox.GetCount(); i ++)
00096         {
00097                 CString strItem;
00098                 wndListBox.GetText(i, strItem);
00099 
00100                 cxExtentMax = max(cxExtentMax, dc.GetTextExtent(strItem).cx);
00101         }
00102 
00103         wndListBox.SetHorizontalExtent(cxExtentMax);
00104         dc.SelectObject(pOldFont);
00105 }
00106 
00107 void COutputWnd::FillBuildWindow()
00108 {
00109         m_wndOutputBuild.AddString(_T("Build output is being displayed here."));
00110         m_wndOutputBuild.AddString(_T("The output is being displayed in rows of a list view"));
00111         m_wndOutputBuild.AddString(_T("but you can change the way it is displayed as you wish..."));
00112 }
00113 
00114 void COutputWnd::FillDebugWindow()
00115 {
00116         m_wndOutputDebug.AddString(_T("Debug output is being displayed here."));
00117         m_wndOutputDebug.AddString(_T("The output is being displayed in rows of a list view"));
00118         m_wndOutputDebug.AddString(_T("but you can change the way it is displayed as you wish..."));
00119 }
00120 
00121 void COutputWnd::FillFindWindow()
00122 {
00123         m_wndOutputFind.AddString(_T("Find output is being displayed here."));
00124         m_wndOutputFind.AddString(_T("The output is being displayed in rows of a list view"));
00125         m_wndOutputFind.AddString(_T("but you can change the way it is displayed as you wish..."));
00126 }
00127 
00128 void COutputWnd::UpdateFonts()
00129 {
00130         m_wndOutputBuild.SetFont(&afxGlobalData.fontRegular);
00131         m_wndOutputDebug.SetFont(&afxGlobalData.fontRegular);
00132         m_wndOutputFind.SetFont(&afxGlobalData.fontRegular);
00133 }
00134 
00136 // COutputList1
00137 
00138 COutputList::COutputList()
00139 {
00140 }
00141 
00142 COutputList::~COutputList()
00143 {
00144 }
00145 
00146 BEGIN_MESSAGE_MAP(COutputList, CListBox)
00147         ON_WM_CONTEXTMENU()
00148         ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
00149         ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
00150         ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
00151         ON_WM_WINDOWPOSCHANGING()
00152 END_MESSAGE_MAP()
00154 // COutputList message handlers
00155 
00156 void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
00157 {
00158         CMenu menu;
00159         menu.LoadMenu(IDR_OUTPUT_POPUP);
00160 
00161         CMenu* pSumMenu = menu.GetSubMenu(0);
00162 
00163         if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
00164         {
00165                 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
00166 
00167                 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
00168                         return;
00169 
00170                 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
00171                 UpdateDialogControls(this, FALSE);
00172         }
00173 
00174         SetFocus();
00175 }
00176 
00177 void COutputList::OnEditCopy()
00178 {
00179         MessageBox(_T("Copy output"));
00180 }
00181 
00182 void COutputList::OnEditClear()
00183 {
00184         MessageBox(_T("Clear output"));
00185 }
00186 
00187 void COutputList::OnViewOutput()
00188 {
00189         CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
00190         CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
00191 
00192         if (pMainFrame != NULL && pParentBar != NULL)
00193         {
00194                 pMainFrame->SetFocus();
00195                 pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
00196                 pMainFrame->RecalcLayout();
00197 
00198         }
00199 }