Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/ClassView.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 #include "MainFrm.h"
00004 #include "ClassView.h"
00005 #include "Resource.h"
00006 #include "AlienPlanets.h"
00007 
00008 class CClassViewMenuButton : public CMFCToolBarMenuButton
00009 {
00010         friend class CClassView;
00011 
00012         DECLARE_SERIAL(CClassViewMenuButton)
00013 
00014 public:
00015         CClassViewMenuButton(HMENU hMenu = NULL) : CMFCToolBarMenuButton((UINT)-1, hMenu, -1)
00016         {
00017         }
00018 
00019         virtual void OnDraw(CDC* pDC, const CRect& rect, CMFCToolBarImages* pImages, BOOL bHorz = TRUE,
00020                 BOOL bCustomizeMode = FALSE, BOOL bHighlight = FALSE, BOOL bDrawBorder = TRUE, BOOL bGrayDisabledButtons = TRUE)
00021         {
00022                 pImages = CMFCToolBar::GetImages();
00023 
00024                 CAfxDrawState ds;
00025                 pImages->PrepareDrawImage(ds);
00026 
00027                 CMFCToolBarMenuButton::OnDraw(pDC, rect, pImages, bHorz, bCustomizeMode, bHighlight, bDrawBorder, bGrayDisabledButtons);
00028 
00029                 pImages->EndDrawImage(ds);
00030         }
00031 };
00032 
00033 IMPLEMENT_SERIAL(CClassViewMenuButton, CMFCToolBarMenuButton, 1)
00034 
00035 
00036 // Construction/Destruction
00038 
00039 CClassView::CClassView()
00040 {
00041         m_nCurrSort = ID_SORTING_GROUPBYTYPE;
00042 }
00043 
00044 CClassView::~CClassView()
00045 {
00046 }
00047 
00048 BEGIN_MESSAGE_MAP(CClassView, CDockablePane)
00049         ON_WM_CREATE()
00050         ON_WM_SIZE()
00051         ON_WM_CONTEXTMENU()
00052         ON_COMMAND(ID_CLASS_ADD_MEMBER_FUNCTION, OnClassAddMemberFunction)
00053         ON_COMMAND(ID_CLASS_ADD_MEMBER_VARIABLE, OnClassAddMemberVariable)
00054         ON_COMMAND(ID_CLASS_DEFINITION, OnClassDefinition)
00055         ON_COMMAND(ID_CLASS_PROPERTIES, OnClassProperties)
00056         ON_COMMAND(ID_NEW_FOLDER, OnNewFolder)
00057         ON_WM_PAINT()
00058         ON_WM_SETFOCUS()
00059         ON_COMMAND_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnSort)
00060         ON_UPDATE_COMMAND_UI_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnUpdateSort)
00061 END_MESSAGE_MAP()
00062 
00064 // CClassView message handlers
00065 
00066 int CClassView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00067 {
00068         if (CDockablePane::OnCreate(lpCreateStruct) == -1)
00069                 return -1;
00070 
00071         CRect rectDummy;
00072         rectDummy.SetRectEmpty();
00073 
00074         // Create views:
00075         const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
00076 
00077         if (!m_wndClassView.Create(dwViewStyle, rectDummy, this, 2))
00078         {
00079                 TRACE0("Failed to create Class View\n");
00080                 return -1;      // fail to create
00081         }
00082 
00083         // Load images:
00084         m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_SORT);
00085         m_wndToolBar.LoadToolBar(IDR_SORT, 0, 0, TRUE /* Is locked */);
00086 
00087         OnChangeVisualStyle();
00088 
00089         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
00090         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
00091 
00092         m_wndToolBar.SetOwner(this);
00093 
00094         // All commands will be routed via this control , not via the parent frame:
00095         m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
00096 
00097         CMenu menuSort;
00098         menuSort.LoadMenu(IDR_POPUP_SORT);
00099 
00100         m_wndToolBar.ReplaceButton(ID_SORT_MENU, CClassViewMenuButton(menuSort.GetSubMenu(0)->GetSafeHmenu()));
00101 
00102         CClassViewMenuButton* pButton =  DYNAMIC_DOWNCAST(CClassViewMenuButton, m_wndToolBar.GetButton(0));
00103 
00104         if (pButton != NULL)
00105         {
00106                 pButton->m_bText = FALSE;
00107                 pButton->m_bImage = TRUE;
00108                 pButton->SetImage(GetCmdMgr()->GetCmdImage(m_nCurrSort));
00109                 pButton->SetMessageWnd(this);
00110         }
00111 
00112         // Fill in some static tree view data (dummy code, nothing magic here)
00113         FillClassView();
00114 
00115         return 0;
00116 }
00117 
00118 void CClassView::OnSize(UINT nType, int cx, int cy)
00119 {
00120         CDockablePane::OnSize(nType, cx, cy);
00121         AdjustLayout();
00122 }
00123 
00124 void CClassView::FillClassView()
00125 {
00126         HTREEITEM hRoot = m_wndClassView.InsertItem(_T("FakeApp classes"), 0, 0);
00127         m_wndClassView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
00128 
00129         HTREEITEM hClass = m_wndClassView.InsertItem(_T("CFakeAboutDlg"), 1, 1, hRoot);
00130         m_wndClassView.InsertItem(_T("CFakeAboutDlg()"), 3, 3, hClass);
00131 
00132         m_wndClassView.Expand(hRoot, TVE_EXPAND);
00133 
00134         hClass = m_wndClassView.InsertItem(_T("CFakeApp"), 1, 1, hRoot);
00135         m_wndClassView.InsertItem(_T("CFakeApp()"), 3, 3, hClass);
00136         m_wndClassView.InsertItem(_T("InitInstance()"), 3, 3, hClass);
00137         m_wndClassView.InsertItem(_T("OnAppAbout()"), 3, 3, hClass);
00138 
00139         hClass = m_wndClassView.InsertItem(_T("CFakeAppDoc"), 1, 1, hRoot);
00140         m_wndClassView.InsertItem(_T("CFakeAppDoc()"), 4, 4, hClass);
00141         m_wndClassView.InsertItem(_T("~CFakeAppDoc()"), 3, 3, hClass);
00142         m_wndClassView.InsertItem(_T("OnNewDocument()"), 3, 3, hClass);
00143 
00144         hClass = m_wndClassView.InsertItem(_T("CFakeAppView"), 1, 1, hRoot);
00145         m_wndClassView.InsertItem(_T("CFakeAppView()"), 4, 4, hClass);
00146         m_wndClassView.InsertItem(_T("~CFakeAppView()"), 3, 3, hClass);
00147         m_wndClassView.InsertItem(_T("GetDocument()"), 3, 3, hClass);
00148         m_wndClassView.Expand(hClass, TVE_EXPAND);
00149 
00150         hClass = m_wndClassView.InsertItem(_T("CFakeAppFrame"), 1, 1, hRoot);
00151         m_wndClassView.InsertItem(_T("CFakeAppFrame()"), 3, 3, hClass);
00152         m_wndClassView.InsertItem(_T("~CFakeAppFrame()"), 3, 3, hClass);
00153         m_wndClassView.InsertItem(_T("m_wndMenuBar"), 6, 6, hClass);
00154         m_wndClassView.InsertItem(_T("m_wndToolBar"), 6, 6, hClass);
00155         m_wndClassView.InsertItem(_T("m_wndStatusBar"), 6, 6, hClass);
00156 
00157         hClass = m_wndClassView.InsertItem(_T("Globals"), 2, 2, hRoot);
00158         m_wndClassView.InsertItem(_T("theFakeApp"), 5, 5, hClass);
00159         m_wndClassView.Expand(hClass, TVE_EXPAND);
00160 }
00161 
00162 void CClassView::OnContextMenu(CWnd* pWnd, CPoint point)
00163 {
00164         CTreeCtrl* pWndTree = (CTreeCtrl*)&m_wndClassView;
00165         ASSERT_VALID(pWndTree);
00166 
00167         if (pWnd != pWndTree)
00168         {
00169                 CDockablePane::OnContextMenu(pWnd, point);
00170                 return;
00171         }
00172 
00173         if (point != CPoint(-1, -1))
00174         {
00175                 // Select clicked item:
00176                 CPoint ptTree = point;
00177                 pWndTree->ScreenToClient(&ptTree);
00178 
00179                 UINT flags = 0;
00180                 HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
00181                 if (hTreeItem != NULL)
00182                 {
00183                         pWndTree->SelectItem(hTreeItem);
00184                 }
00185         }
00186 
00187         pWndTree->SetFocus();
00188         CMenu menu;
00189         menu.LoadMenu(IDR_POPUP_SORT);
00190 
00191         CMenu* pSumMenu = menu.GetSubMenu(0);
00192 
00193         if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
00194         {
00195                 CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
00196 
00197                 if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
00198                         return;
00199 
00200                 ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
00201                 UpdateDialogControls(this, FALSE);
00202         }
00203 }
00204 
00205 void CClassView::AdjustLayout()
00206 {
00207         if (GetSafeHwnd() == NULL)
00208         {
00209                 return;
00210         }
00211 
00212         CRect rectClient;
00213         GetClientRect(rectClient);
00214 
00215         int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
00216 
00217         m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
00218         m_wndClassView.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
00219 }
00220 
00221 BOOL CClassView::PreTranslateMessage(MSG* pMsg)
00222 {
00223         return CDockablePane::PreTranslateMessage(pMsg);
00224 }
00225 
00226 void CClassView::OnSort(UINT id)
00227 {
00228         if (m_nCurrSort == id)
00229         {
00230                 return;
00231         }
00232 
00233         m_nCurrSort = id;
00234 
00235         CClassViewMenuButton* pButton =  DYNAMIC_DOWNCAST(CClassViewMenuButton, m_wndToolBar.GetButton(0));
00236 
00237         if (pButton != NULL)
00238         {
00239                 pButton->SetImage(GetCmdMgr()->GetCmdImage(id));
00240                 m_wndToolBar.Invalidate();
00241                 m_wndToolBar.UpdateWindow();
00242         }
00243 }
00244 
00245 void CClassView::OnUpdateSort(CCmdUI* pCmdUI)
00246 {
00247         pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort);
00248 }
00249 
00250 void CClassView::OnClassAddMemberFunction()
00251 {
00252         AfxMessageBox(_T("Add member function..."));
00253 }
00254 
00255 void CClassView::OnClassAddMemberVariable()
00256 {
00257         // TODO: Add your command handler code here
00258 }
00259 
00260 void CClassView::OnClassDefinition()
00261 {
00262         // TODO: Add your command handler code here
00263 }
00264 
00265 void CClassView::OnClassProperties()
00266 {
00267         // TODO: Add your command handler code here
00268 }
00269 
00270 void CClassView::OnNewFolder()
00271 {
00272         AfxMessageBox(_T("New Folder..."));
00273 }
00274 
00275 void CClassView::OnPaint()
00276 {
00277         CPaintDC dc(this); // device context for painting
00278 
00279         CRect rectTree;
00280         m_wndClassView.GetWindowRect(rectTree);
00281         ScreenToClient(rectTree);
00282 
00283         rectTree.InflateRect(1, 1);
00284         dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
00285 }
00286 
00287 void CClassView::OnSetFocus(CWnd* pOldWnd)
00288 {
00289         CDockablePane::OnSetFocus(pOldWnd);
00290 
00291         m_wndClassView.SetFocus();
00292 }
00293 
00294 void CClassView::OnChangeVisualStyle()
00295 {
00296         m_ClassViewImages.DeleteImageList();
00297 
00298         UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_CLASS_VIEW_24 : IDB_CLASS_VIEW;
00299 
00300         CBitmap bmp;
00301         if (!bmp.LoadBitmap(uiBmpId))
00302         {
00303                 TRACE(_T("Can't load bitmap: %x\n"), uiBmpId);
00304                 ASSERT(FALSE);
00305                 return;
00306         }
00307 
00308         BITMAP bmpObj;
00309         bmp.GetBitmap(&bmpObj);
00310 
00311         UINT nFlags = ILC_MASK;
00312 
00313         nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
00314 
00315         m_ClassViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
00316         m_ClassViewImages.Add(&bmp, RGB(255, 0, 0));
00317 
00318         m_wndClassView.SetImageList(&m_ClassViewImages, TVSIL_NORMAL);
00319 
00320         m_wndToolBar.CleanUpLockedImages();
00321         m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_SORT_24 : IDR_SORT, 0, 0, TRUE /* Locked */);
00322 }