Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/PropertiesWnd.cpp
Go to the documentation of this file.
00001 
00002 #include "stdafx.h"
00003 
00004 #include "PropertiesWnd.h"
00005 #include "Resource.h"
00006 #include "MainFrm.h"
00007 #include "AlienPlanets.h"
00008 
00009 #ifdef _DEBUG
00010 #undef THIS_FILE
00011 static char THIS_FILE[]=__FILE__;
00012 #define new DEBUG_NEW
00013 #endif
00014 
00016 // CResourceViewBar
00017 
00018 CPropertiesWnd::CPropertiesWnd()
00019 {
00020 }
00021 
00022 CPropertiesWnd::~CPropertiesWnd()
00023 {
00024 }
00025 
00026 BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
00027         ON_WM_CREATE()
00028         ON_WM_SIZE()
00029         ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
00030         ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
00031         ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)
00032         ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)
00033         ON_COMMAND(ID_PROPERTIES1, OnProperties1)
00034         ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)
00035         ON_COMMAND(ID_PROPERTIES2, OnProperties2)
00036         ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)
00037         ON_WM_SETFOCUS()
00038         ON_WM_SETTINGCHANGE()
00039 END_MESSAGE_MAP()
00040 
00042 // CResourceViewBar message handlers
00043 
00044 void CPropertiesWnd::AdjustLayout()
00045 {
00046         if (GetSafeHwnd() == NULL)
00047         {
00048                 return;
00049         }
00050 
00051         CRect rectClient,rectCombo;
00052         GetClientRect(rectClient);
00053 
00054         m_wndObjectCombo.GetWindowRect(&rectCombo);
00055 
00056         int cyCmb = rectCombo.Size().cy;
00057         int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
00058 
00059         m_wndObjectCombo.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), 200, SWP_NOACTIVATE | SWP_NOZORDER);
00060         m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
00061         m_wndPropList.SetWindowPos(NULL, rectClient.left, rectClient.top + cyCmb + cyTlb, rectClient.Width(), rectClient.Height() -(cyCmb+cyTlb), SWP_NOACTIVATE | SWP_NOZORDER);
00062 }
00063 
00064 int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00065 {
00066         if (CDockablePane::OnCreate(lpCreateStruct) == -1)
00067                 return -1;
00068 
00069         CRect rectDummy;
00070         rectDummy.SetRectEmpty();
00071 
00072         // Create combo:
00073         const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
00074 
00075         if (!m_wndObjectCombo.Create(dwViewStyle, rectDummy, this, 1))
00076         {
00077                 TRACE0("Failed to create Properties Combo \n");
00078                 return -1;      // fail to create
00079         }
00080 
00081         m_wndObjectCombo.AddString(_T("Application"));
00082         m_wndObjectCombo.AddString(_T("Properties Window"));
00083         m_wndObjectCombo.SetCurSel(0);
00084 
00085         if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))
00086         {
00087                 TRACE0("Failed to create Properties Grid \n");
00088                 return -1;      // fail to create
00089         }
00090 
00091         InitPropList();
00092 
00093         m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_PROPERTIES);
00094         m_wndToolBar.LoadToolBar(IDR_PROPERTIES, 0, 0, TRUE /* Is locked */);
00095         m_wndToolBar.CleanUpLockedImages();
00096         m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_PROPERTIES_HC : IDR_PROPERTIES, 0, 0, TRUE /* Locked */);
00097 
00098         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
00099         m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
00100         m_wndToolBar.SetOwner(this);
00101 
00102         // All commands will be routed via this control , not via the parent frame:
00103         m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
00104 
00105         AdjustLayout();
00106         return 0;
00107 }
00108 
00109 void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
00110 {
00111         CDockablePane::OnSize(nType, cx, cy);
00112         AdjustLayout();
00113 }
00114 
00115 void CPropertiesWnd::OnExpandAllProperties()
00116 {
00117         m_wndPropList.ExpandAll();
00118 }
00119 
00120 void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* /* pCmdUI */)
00121 {
00122 }
00123 
00124 void CPropertiesWnd::OnSortProperties()
00125 {
00126         m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());
00127 }
00128 
00129 void CPropertiesWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)
00130 {
00131         pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());
00132 }
00133 
00134 void CPropertiesWnd::OnProperties1()
00135 {
00136         // TODO: Add your command handler code here
00137 }
00138 
00139 void CPropertiesWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)
00140 {
00141         // TODO: Add your command update UI handler code here
00142 }
00143 
00144 void CPropertiesWnd::OnProperties2()
00145 {
00146         // TODO: Add your command handler code here
00147 }
00148 
00149 void CPropertiesWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)
00150 {
00151         // TODO: Add your command update UI handler code here
00152 }
00153 
00154 void CPropertiesWnd::InitPropList()
00155 {
00156         SetPropListFont();
00157 
00158         m_wndPropList.EnableHeaderCtrl(FALSE);
00159         m_wndPropList.EnableDescriptionArea();
00160         m_wndPropList.SetVSDotNetLook();
00161         m_wndPropList.MarkModifiedProperties();
00162 
00163         CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Appearance"));
00164 
00165         pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("3D Look"), (_variant_t) false, _T("Specifies the window's font will be non-bold and controls will have a 3D border")));
00166 
00167         CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("Border"), _T("Dialog Frame"), _T("One of: None, Thin, Resizable, or Dialog Frame"));
00168         pProp->AddOption(_T("None"));
00169         pProp->AddOption(_T("Thin"));
00170         pProp->AddOption(_T("Resizable"));
00171         pProp->AddOption(_T("Dialog Frame"));
00172         pProp->AllowEdit(FALSE);
00173 
00174         pGroup1->AddSubItem(pProp);
00175         pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("Caption"), (_variant_t) _T("About"), _T("Specifies the text that will be displayed in the window's title bar")));
00176 
00177         m_wndPropList.AddProperty(pGroup1);
00178 
00179         CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("Window Size"), 0, TRUE);
00180 
00181         pProp = new CMFCPropertyGridProperty(_T("Height"), (_variant_t) 250l, _T("Specifies the window's height"));
00182         pProp->EnableSpinControl(TRUE, 50, 300);
00183         pSize->AddSubItem(pProp);
00184 
00185         pProp = new CMFCPropertyGridProperty( _T("Width"), (_variant_t) 150l, _T("Specifies the window's width"));
00186         pProp->EnableSpinControl(TRUE, 50, 200);
00187         pSize->AddSubItem(pProp);
00188 
00189         m_wndPropList.AddProperty(pSize);
00190 
00191         CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("Font"));
00192 
00193         LOGFONT lf;
00194         CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
00195         font->GetLogFont(&lf);
00196 
00197         lstrcpy(lf.lfFaceName, _T("Arial"));
00198 
00199         pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("Font"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("Specifies the default font for the window")));
00200         pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("Use System Font"), (_variant_t) true, _T("Specifies that the window uses MS Shell Dlg font")));
00201 
00202         m_wndPropList.AddProperty(pGroup2);
00203 
00204         CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc"));
00205         pProp = new CMFCPropertyGridProperty(_T("(Name)"), _T("Application"));
00206         pProp->Enable(FALSE);
00207         pGroup3->AddSubItem(pProp);
00208 
00209         CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("Window Color"), RGB(210, 192, 254), NULL, _T("Specifies the default window color"));
00210         pColorProp->EnableOtherButton(_T("Other..."));
00211         pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));
00212         pGroup3->AddSubItem(pColorProp);
00213 
00214         static const TCHAR szFilter[] = _T("Icon Files(*.ico)|*.ico|All Files(*.*)|*.*||");
00215         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Icon"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("Specifies the window icon")));
00216 
00217         pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("Folder"), _T("c:\\")));
00218 
00219         m_wndPropList.AddProperty(pGroup3);
00220 
00221         CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("Hierarchy"));
00222 
00223         CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("First sub-level"));
00224         pGroup4->AddSubItem(pGroup41);
00225 
00226         CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("Second sub-level"));
00227         pGroup41->AddSubItem(pGroup411);
00228 
00229         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 1"), (_variant_t) _T("Value 1"), _T("This is a description")));
00230         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 2"), (_variant_t) _T("Value 2"), _T("This is a description")));
00231         pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("Item 3"), (_variant_t) _T("Value 3"), _T("This is a description")));
00232 
00233         pGroup4->Expand(FALSE);
00234         m_wndPropList.AddProperty(pGroup4);
00235 }
00236 
00237 void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
00238 {
00239         CDockablePane::OnSetFocus(pOldWnd);
00240         m_wndPropList.SetFocus();
00241 }
00242 
00243 void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
00244 {
00245         CDockablePane::OnSettingChange(uFlags, lpszSection);
00246         SetPropListFont();
00247 }
00248 
00249 void CPropertiesWnd::SetPropListFont()
00250 {
00251         ::DeleteObject(m_fntPropList.Detach());
00252 
00253         LOGFONT lf;
00254         afxGlobalData.fontRegular.GetLogFont(&lf);
00255 
00256         NONCLIENTMETRICS info;
00257         info.cbSize = sizeof(info);
00258 
00259         afxGlobalData.GetNonClientMetrics(info);
00260 
00261         lf.lfHeight = info.lfMenuFont.lfHeight;
00262         lf.lfWeight = info.lfMenuFont.lfWeight;
00263         lf.lfItalic = info.lfMenuFont.lfItalic;
00264 
00265         m_fntPropList.CreateFontIndirect(&lf);
00266 
00267         m_wndPropList.SetFont(&m_fntPropList);
00268         m_wndObjectCombo.SetFont(&m_fntPropList);
00269 }