Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/FileView.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 #include "mainfrm.h"
00004 #include "FileView.h"
00005 #include "Resource.h"
00006 #include "AlienPlanets.h"
00007 
00008 #ifdef _DEBUG
00009 #undef THIS_FILE
00010 static char THIS_FILE[]=__FILE__;
00011 #define new DEBUG_NEW
00012 #endif
00013 
00015 // CFileView
00016 
00017 CFileView::CFileView()
00018 {
00019 }
00020 
00021 CFileView::~CFileView()
00022 {
00023 }
00024 
00025 BEGIN_MESSAGE_MAP(CFileView, CDockablePane)
00026         ON_WM_CREATE()
00027         ON_WM_SIZE()
00028         ON_WM_CONTEXTMENU()
00029         ON_COMMAND(ID_PROPERTIES, OnProperties)
00030         ON_COMMAND(ID_OPEN, OnFileOpen)
00031         ON_COMMAND(ID_OPEN_WITH, OnFileOpenWith)
00032         ON_COMMAND(ID_DUMMY_COMPILE, OnDummyCompile)
00033         ON_COMMAND(ID_EDIT_CUT, OnEditCut)
00034         ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
00035         ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
00036         ON_WM_PAINT()
00037         ON_WM_SETFOCUS()
00038 END_MESSAGE_MAP()
00039 
00041 // CWorkspaceBar message handlers
00042 
00043 int CFileView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00044 {
00045         if (CDockablePane::OnCreate(lpCreateStruct) == -1)
00046                 return -1;
00047 
00048         CRect rectDummy;
00049         rectDummy.SetRectEmpty();
00050 
00051         // Create view:
00052         const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
00053 
00054         if (!m_wndFileView.Create(dwViewStyle, rectDummy, this, 4))
00055         {
00056                 TRACE0("Failed to create file view\n");
00057                 return -1;      // fail to create
00058         }
00059 
00060         // Load view images:
00061         m_FileViewImages.Create(IDB_FILE_VIEW, 16, 0, RGB(255, 0, 255));
00062         m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
00063 
00064         m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_EXPLORER);
00065         m_wndToolBar.LoadToolBar(IDR_EXPLORER, 0, 0, TRUE /* Is locked */);
00066 
00067         OnChangeVisualStyle();
00068 
00069         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
00070 
00071         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
00072 
00073         m_wndToolBar.SetOwner(this);
00074 
00075         // All commands will be routed via this control , not via the parent frame:
00076         m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
00077 
00078         // Fill in some static tree view data (dummy code, nothing magic here)
00079         FillFileView();
00080         AdjustLayout();
00081 
00082         return 0;
00083 }
00084 
00085 void CFileView::OnSize(UINT nType, int cx, int cy)
00086 {
00087         CDockablePane::OnSize(nType, cx, cy);
00088         AdjustLayout();
00089 }
00090 
00091 void CFileView::FillFileView()
00092 {
00093         HTREEITEM hRoot = m_wndFileView.InsertItem(_T("FakeApp files"), 0, 0);
00094         m_wndFileView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
00095 
00096         HTREEITEM hSrc = m_wndFileView.InsertItem(_T("FakeApp Source Files"), 0, 0, hRoot);
00097 
00098         m_wndFileView.InsertItem(_T("FakeApp.cpp"), 1, 1, hSrc);
00099         m_wndFileView.InsertItem(_T("FakeApp.rc"), 1, 1, hSrc);
00100         m_wndFileView.InsertItem(_T("FakeAppDoc.cpp"), 1, 1, hSrc);
00101         m_wndFileView.InsertItem(_T("FakeAppView.cpp"), 1, 1, hSrc);
00102         m_wndFileView.InsertItem(_T("MainFrm.cpp"), 1, 1, hSrc);
00103         m_wndFileView.InsertItem(_T("StdAfx.cpp"), 1, 1, hSrc);
00104 
00105         HTREEITEM hInc = m_wndFileView.InsertItem(_T("FakeApp Header Files"), 0, 0, hRoot);
00106 
00107         m_wndFileView.InsertItem(_T("FakeApp.h"), 2, 2, hInc);
00108         m_wndFileView.InsertItem(_T("FakeAppDoc.h"), 2, 2, hInc);
00109         m_wndFileView.InsertItem(_T("FakeAppView.h"), 2, 2, hInc);
00110         m_wndFileView.InsertItem(_T("Resource.h"), 2, 2, hInc);
00111         m_wndFileView.InsertItem(_T("MainFrm.h"), 2, 2, hInc);
00112         m_wndFileView.InsertItem(_T("StdAfx.h"), 2, 2, hInc);
00113 
00114         HTREEITEM hRes = m_wndFileView.InsertItem(_T("FakeApp Resource Files"), 0, 0, hRoot);
00115 
00116         m_wndFileView.InsertItem(_T("FakeApp.ico"), 2, 2, hRes);
00117         m_wndFileView.InsertItem(_T("FakeApp.rc2"), 2, 2, hRes);
00118         m_wndFileView.InsertItem(_T("FakeAppDoc.ico"), 2, 2, hRes);
00119         m_wndFileView.InsertItem(_T("FakeToolbar.bmp"), 2, 2, hRes);
00120 
00121         m_wndFileView.Expand(hRoot, TVE_EXPAND);
00122         m_wndFileView.Expand(hSrc, TVE_EXPAND);
00123         m_wndFileView.Expand(hInc, TVE_EXPAND);
00124 }
00125 
00126 void CFileView::OnContextMenu(CWnd* pWnd, CPoint point)
00127 {
00128         CTreeCtrl* pWndTree = (CTreeCtrl*) &m_wndFileView;
00129         ASSERT_VALID(pWndTree);
00130 
00131         if (pWnd != pWndTree)
00132         {
00133                 CDockablePane::OnContextMenu(pWnd, point);
00134                 return;
00135         }
00136 
00137         if (point != CPoint(-1, -1))
00138         {
00139                 // Select clicked item:
00140                 CPoint ptTree = point;
00141                 pWndTree->ScreenToClient(&ptTree);
00142 
00143                 UINT flags = 0;
00144                 HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
00145                 if (hTreeItem != NULL)
00146                 {
00147                         pWndTree->SelectItem(hTreeItem);
00148                 }
00149         }
00150 
00151         pWndTree->SetFocus();
00152         theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EXPLORER, point.x, point.y, this, TRUE);
00153 }
00154 
00155 void CFileView::AdjustLayout()
00156 {
00157         if (GetSafeHwnd() == NULL)
00158         {
00159                 return;
00160         }
00161 
00162         CRect rectClient;
00163         GetClientRect(rectClient);
00164 
00165         int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
00166 
00167         m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
00168         m_wndFileView.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
00169 }
00170 
00171 void CFileView::OnProperties()
00172 {
00173         AfxMessageBox(_T("Properties...."));
00174 
00175 }
00176 
00177 void CFileView::OnFileOpen()
00178 {
00179         // TODO: Add your command handler code here
00180 }
00181 
00182 void CFileView::OnFileOpenWith()
00183 {
00184         // TODO: Add your command handler code here
00185 }
00186 
00187 void CFileView::OnDummyCompile()
00188 {
00189         // TODO: Add your command handler code here
00190 }
00191 
00192 void CFileView::OnEditCut()
00193 {
00194         // TODO: Add your command handler code here
00195 }
00196 
00197 void CFileView::OnEditCopy()
00198 {
00199         // TODO: Add your command handler code here
00200 }
00201 
00202 void CFileView::OnEditClear()
00203 {
00204         // TODO: Add your command handler code here
00205 }
00206 
00207 void CFileView::OnPaint()
00208 {
00209         CPaintDC dc(this); // device context for painting
00210 
00211         CRect rectTree;
00212         m_wndFileView.GetWindowRect(rectTree);
00213         ScreenToClient(rectTree);
00214 
00215         rectTree.InflateRect(1, 1);
00216         dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
00217 }
00218 
00219 void CFileView::OnSetFocus(CWnd* pOldWnd)
00220 {
00221         CDockablePane::OnSetFocus(pOldWnd);
00222 
00223         m_wndFileView.SetFocus();
00224 }
00225 
00226 void CFileView::OnChangeVisualStyle()
00227 {
00228         m_wndToolBar.CleanUpLockedImages();
00229         m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_EXPLORER_24 : IDR_EXPLORER, 0, 0, TRUE /* Locked */);
00230 
00231         m_FileViewImages.DeleteImageList();
00232 
00233         UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_FILE_VIEW_24 : IDB_FILE_VIEW;
00234 
00235         CBitmap bmp;
00236         if (!bmp.LoadBitmap(uiBmpId))
00237         {
00238                 TRACE(_T("Can't load bitmap: %x\n"), uiBmpId);
00239                 ASSERT(FALSE);
00240                 return;
00241         }
00242 
00243         BITMAP bmpObj;
00244         bmp.GetBitmap(&bmpObj);
00245 
00246         UINT nFlags = ILC_MASK;
00247 
00248         nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
00249 
00250         m_FileViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
00251         m_FileViewImages.Add(&bmp, RGB(255, 0, 255));
00252 
00253         m_wndFileView.SetImageList(&m_FileViewImages, TVSIL_NORMAL);
00254 }
00255 
00256