GME  13
PartBrowserDlg.cpp
Go to the documentation of this file.
00001 // PartBrowserDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "PartBrowserDlg.h"
00006 #include "PartBrowserCtrl.h"
00007 #include "CommonError.h"
00008 #include "CommonSmart.h"
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015 
00017 // CPartBrowserDlg dialog
00018 
00019 
00020 CPartBrowserDlg::CPartBrowserDlg(CWnd* pParent /*=NULL*/)
00021         : CDialog(CPartBrowserDlg::IDD, pParent)
00022 {
00023         //{{AFX_DATA_INIT(CPartBrowserDlg)
00024                 // NOTE: the ClassWizard will add member initialization here
00025         //}}AFX_DATA_INIT
00026         mgaMetaModel = NULL;
00027         mgaProject = NULL;
00028 }
00029 
00030 void CPartBrowserDlg::DoDataExchange(CDataExchange* pDX)
00031 {
00032         CDialog::DoDataExchange(pDX);
00033         //{{AFX_DATA_MAP(CPartBrowserDlg)
00034         DDX_Control(pDX, IDC_ASPECT_TAB, tab);
00035         //}}AFX_DATA_MAP
00036 }
00037 
00038 void CPartBrowserDlg::SetCurrentProject(CComPtr<IMgaProject> project)
00039 {
00040         if (mgaProject != NULL)
00041                 mgaProject.Release();
00042         mgaProject = project;
00043         partFrame.GetPane().SetCurrentProject(project);
00044 }
00045 
00046 void CPartBrowserDlg::SetMetaModel(CComPtr<IMgaMetaModel> meta)
00047 {
00048         // FIXME: check if mgaMetaModel == meta
00049         if (mgaMetaModel != NULL)
00050                 mgaMetaModel.Release();
00051         mgaMetaModel = meta;
00052         partFrame.GetPane().SetMetaModel(meta);
00053 
00054         SetTabs();
00055 }
00056 
00057 void CPartBrowserDlg::SetBgColor(COLORREF bgColor)
00058 {
00059         partFrame.GetPane().SetBgColor(bgColor);
00060 }
00061 
00062 void CPartBrowserDlg::ChangeAspect(long ind)
00063 {
00064         tab.SetCurSel(ind);
00065         partFrame.GetPane().ChangeAspect(ind);
00066         Resize();
00067 }
00068 
00069 void CPartBrowserDlg::CycleAspect()
00070 {
00071         if (!mgaMetaModel)
00072                 return;
00073 
00074         CComPtr<IMgaMetaParts> mgaMetaParts;
00075         try {
00076                 CComPtr<IMgaMetaAspects> spAspects;
00077                 COMTHROW(mgaMetaModel->get_Aspects(&spAspects));
00078                 ASSERT(spAspects);
00079                 if (spAspects) {
00080                         long nAspects = 0;
00081                         COMTHROW(spAspects->get_Count(&nAspects));
00082                         if (nAspects <= 0)
00083                                 return;
00084 
00085                         long ind = (tab.GetCurSel() + 1) % nAspects;
00086                         tab.SetCurSel(ind);
00087 
00088                         partFrame.GetPane().ChangeAspect(ind);
00089                         SendAspectChange(ind);
00090                 }
00091         }
00092         catch (hresult_exception&) {
00093         }
00094 
00095         Resize();
00096 }
00097 
00098 void CPartBrowserDlg::SetTabs()
00099 {
00100         tab.DeleteAllItems();
00101         if (mgaMetaModel) {
00102                 try {
00103                         CComPtr<IMgaMetaAspects> spAspects;
00104                         COMTHROW(mgaMetaModel->get_Aspects(&spAspects));
00105                         ASSERT(spAspects);
00106                         if (spAspects) {
00107                                 long nAspects = 0;
00108                                 COMTHROW(spAspects->get_Count(&nAspects));
00109                                 TC_ITEM tcItem;
00110                                 for (long ind = 0; ind < nAspects; ind++) {
00111                                         CComPtr<IMgaMetaAspect> spAspect;
00112                                         COMTHROW(spAspects->get_Item(ind + 1, &spAspect));
00113                                         tcItem.mask = TCIF_TEXT;
00114                                         CComBSTR displayedNameBstr;
00115                                         COMTHROW(spAspect->get_DisplayedName(&displayedNameBstr));
00116                                         CComBSTR nameBStr;
00117                                         COMTHROW(spAspect->get_Name(&nameBStr));
00118                                         CString name;
00119                                         name = displayedNameBstr ? displayedNameBstr : nameBStr;
00120                                         tcItem.pszText = name.GetBuffer();
00121                                         tcItem.cchTextMax = name.GetLength();
00122                                         tab.InsertItem(ind, &tcItem);
00123                                 }
00124                         }
00125                 }
00126                 catch (hresult_exception&) {
00127                 }
00128         }
00129         Resize();
00130 }
00131 
00132 void CPartBrowserDlg::Resize()
00133 {
00134         CRect r;
00135         GetClientRect(&r);
00136         if (::IsWindow(tab.m_hWnd))
00137                 tab.MoveWindow(&r);
00138         if (::IsWindow(partFrame.m_hWnd)) {
00139                 tab.AdjustRect(FALSE, &r);
00140                 r.DeflateRect(1, 1);
00141                 partFrame.Resize(r);
00142         }
00143 }
00144 
00145 BEGIN_MESSAGE_MAP(CPartBrowserDlg, CDialog)
00146         //{{AFX_MSG_MAP(CPartBrowserDlg)
00147         ON_WM_SIZE()
00148         ON_NOTIFY(TCN_SELCHANGE, IDC_ASPECT_TAB, OnSelchangeAspectTab)
00149         //}}AFX_MSG_MAP
00150 END_MESSAGE_MAP()
00151 
00153 // CPartBrowserDlg message handlers
00154 
00155 BOOL CPartBrowserDlg::OnInitDialog()
00156 {
00157         CDialog::OnInitDialog();
00158         
00159         tab.SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
00160         partFrame.Create(IDD_PARTBROWSERFRAME_DIALOG, this);
00161 
00162         // Opportunity for some users to bring the tabs to the bottom again (TCS_BOTTOM is obsolete now)
00163         // TCS_BOTTOM style is obsolete (see MSDN: "This style is not supported if you use ComCtl32.dll version 6.")
00164         // this style appeared with Internet Explorer 3.x, ComCtl 6.0 is the Windows XP and Windows Vista version of ComCtl.
00165         // If user really wants to switch it back, he can force PartBrowser to use TCS_BOTTOM style by creating a
00166         // string registry key with "1" value under the "HKCU\Software\GME\GUI\PartBrowser\BottomTabs"
00167         HKEY hKey;
00168         if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\GME\\GUI\\PartBrowser"),
00169                                          0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
00170         {
00171                 TCHAR szData[128];
00172                 DWORD dwKeyDataType;
00173                 DWORD dwDataBufSize = sizeof(szData)/sizeof(TCHAR);
00174 
00175                 if (RegQueryValueEx(hKey, _T("BottomTabs"), NULL, &dwKeyDataType,
00176                                                         (LPBYTE) &szData, &dwDataBufSize) == ERROR_SUCCESS)
00177                 {
00178                         UINT uBottomTabs = _tcstoul(szData, NULL, 10);
00179                         if (uBottomTabs > 0) {
00180                                 LONG dwStyle = ::GetWindowLong(tab.m_hWnd, GWL_STYLE);
00181                                 dwStyle = dwStyle | TCS_BOTTOM;
00182                                 ::SetWindowLong(tab.m_hWnd, GWL_STYLE, dwStyle);
00183                         }
00184                 }
00185                 RegCloseKey(hKey);
00186         }
00187 
00188         SetTabs();
00189 
00190         return TRUE;    // return TRUE unless you set the focus to a control
00191                                         // EXCEPTION: OCX Property Pages should return FALSE
00192 }
00193 
00194 void CPartBrowserDlg::OnOK()
00195 {
00196         // do nothing to avoid getting kick out
00197 }
00198 
00199 void CPartBrowserDlg::OnCancel()
00200 {
00201         // do nothing to avoid getting kick out
00202 }
00203 
00204 void CPartBrowserDlg::OnSize(UINT nType, int cx, int cy)
00205 {
00206         CDialog::OnSize(nType, cx, cy);
00207 
00208         Resize();
00209 }
00210 
00211 void CPartBrowserDlg::OnSelchangeAspectTab(NMHDR* /*pNMHDR*/, LRESULT* pResult)
00212 {
00213         long s = tab.GetCurSel();
00214         if (s >= 0) {
00215                 partFrame.GetPane().ChangeAspect(s);
00216                 SendAspectChange(s);
00217         }
00218         Resize();
00219         *pResult = 0;
00220 }
00221 
00222 void CPartBrowserDlg::SendAspectChange(long index)
00223 {
00224         CWnd* wnd = GetParent();
00225         if (wnd->IsKindOf(RUNTIME_CLASS(CPartBrowserCtrl))) {
00226                 CPartBrowserCtrl* ctrl = STATIC_DOWNCAST(CPartBrowserCtrl, wnd);
00227                 ctrl->SendAspectChanged(index);
00228         }
00229 }