GME  13
InspectorDlg.cpp
Go to the documentation of this file.
00001 // InspectorDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "ObjectInspector.h"
00006 #include "ObjectInspectorCtl.h"
00007 #include "InspectorDlg.h"
00008 
00009 TCHAR   *panelTitles[] = {  _T("Attributes"), _T("Preferences"),_T("Properties")};
00010 
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016 
00018 // CInspectorDlg dialog
00019 
00020 
00021 CInspectorDlg::CInspectorDlg(CWnd* pParent /*=NULL*/)
00022         : CDialog(CInspectorDlg::IDD, pParent)
00023 {
00024         //{{AFX_DATA_INIT(CInspectorDlg)
00025         m_forKind = FALSE;
00026         //}}AFX_DATA_INIT
00027 
00028         
00029         
00030 
00031         m_oldSize.cx = -1;
00032         m_oldSize.cy = -1;
00033 
00034         for (int i = 0; i < INSP_PANEL_NUM; i++) 
00035         {
00036                 m_inspectorLists[i] = new CInspectorList(i==INSP_PREF_PANEL || i==INSP_PROP_PANEL);
00037         }
00038         m_inspectorSheet.SetInspectorLists(m_inspectorLists);
00039 
00040 
00041         for (int j = 0; j < INSP_PANEL_NUM; j++) {
00042                 m_inspectorEntries[j] = new CInspectorEntryList();
00043         }
00044 
00045         for (int k = 0; k < INSP_PANEL_NUM; k++) 
00046         {
00047                 m_bIsPanelVisible[k]=false;
00048         }
00049 
00050         m_currentPanel = 0;
00051 
00052         // this method is called only once
00053         CItemData::getRealFmtString();
00054 }
00055 
00056 
00057 CInspectorDlg::~CInspectorDlg()
00058 {
00059         for (int i = 0; i < INSP_PANEL_NUM; i++) {
00060                 delete m_inspectorLists[i];
00061         }
00062         for (int j = 0; j < INSP_PANEL_NUM; j++) {
00063                 delete m_inspectorEntries[j];
00064         }
00065 }
00066 
00067 
00068 void CInspectorDlg::DoDataExchange(CDataExchange* pDX)
00069 {
00070         CDialog::DoDataExchange(pDX);
00071         //{{AFX_DATA_MAP(CInspectorDlg)
00072         DDX_Control(pDX, IDC_INSPECTOR_SHEET, m_inspectorSheet);
00073         DDX_Control(pDX, IDC_STATIC_HELP, m_wndHelp);
00074         DDX_Check(pDX, IDC_CHECK_KIND, m_forKind);
00075         //}}AFX_DATA_MAP
00076 }
00077 
00078 
00079 BEGIN_MESSAGE_MAP(CInspectorDlg, CDialog)
00080         //{{AFX_MSG_MAP(CInspectorDlg)
00081         ON_WM_SIZE()
00082         ON_NOTIFY(TCN_SELCHANGE, IDC_INSPECTOR_SHEET, OnSelchangeInspectorSheet)
00083         ON_MESSAGE(LBN_ON_ITEM_CHANGED, OnItemChanged)
00084         ON_MESSAGE(MSG_NAME_EDIT_END_OK, OnNameEditEndOK)
00085         ON_MESSAGE(MSG_NAME_EDIT_END_CANCEL, OnNameEditEndCancel)
00086         ON_EN_KILLFOCUS(IDC_EDIT_NAME, OnKillfocusEditName)
00087         //}}AFX_MSG_MAP
00088 END_MESSAGE_MAP()
00089 
00091 // CInspectorDlg message handlers
00092 
00093 void CInspectorDlg::OnSize(UINT nType, int cx, int cy) 
00094 {
00095         CDialog::OnSize(nType, cx, cy);
00096 
00097 
00098         if ((m_oldSize.cx < 0) || (m_oldSize.cy < 0)) {
00099                 m_oldSize.cx = cx;
00100                 m_oldSize.cy = cy;
00101                 return;
00102         }
00103 
00104         cx = max(INSP_MIN_SIZEX, cx);
00105         cy = max(INSP_MIN_SIZEY, cy);
00106 
00107         int dx = cx - m_oldSize.cx;
00108         int dy = cy - m_oldSize.cy;
00109 
00110         CWnd *control = GetDlgItem(IDC_EDIT_NAME);
00111         if (control->GetSafeHwnd()) {
00112                 CRect ctrlRect;
00113                 control->GetWindowRect(&ctrlRect);
00114                 ScreenToClient(&ctrlRect);
00115                 ctrlRect.right += dx;
00116                 control->MoveWindow(&ctrlRect);
00117         }
00118         
00119         control = GetDlgItem(IDC_CHECK_KIND);
00120         if (control->GetSafeHwnd()) {
00121                 CRect ctrlRect;
00122                 control->GetWindowRect(&ctrlRect);
00123                 ScreenToClient(&ctrlRect);
00124                 ctrlRect.right += dx;
00125                 ctrlRect.left += dx;
00126                 control->MoveWindow(&ctrlRect);
00127         }
00128 
00129         control = GetDlgItem(IDC_INSPECTOR_SHEET);
00130         if (control->GetSafeHwnd()) {
00131                 CRect ctrlRect;
00132                 control->GetWindowRect(&ctrlRect);
00133                 ScreenToClient(&ctrlRect);
00134                 ctrlRect.right += dx;
00135                 ctrlRect.bottom += dy;
00136                 control->MoveWindow(&ctrlRect);
00137         }
00138 
00139         control = GetDlgItem(IDC_STATIC_HELP);
00140 
00141         if (control->GetSafeHwnd()) 
00142         {
00143                 CRect ctrlRect;
00144                 control->GetWindowRect(&ctrlRect);
00145                 ScreenToClient(&ctrlRect);
00146                 
00147                 static int nHelpCtrlSize=ctrlRect.Height();
00148 
00149                 ctrlRect.right += dx;           
00150                 
00151                 if(ctrlRect.Height()>=nHelpCtrlSize)
00152                 {
00153                         ctrlRect.top += dy;
00154 
00155                 }
00156                 else
00157                 {
00158 /*                      int nDiff=nHelpCtrlSize-ctrlRect.Height();
00159                         if(nDiff>0 && dy>nDiff)
00160                         {
00161                                 ctrlRect.top +=(dy-(nHelpCtrlSize-ctrlRect.Height()));
00162                         }*/
00163                 }
00164 
00165                 ctrlRect.bottom += dy;
00166 
00167                 control->MoveWindow(&ctrlRect);                                                         
00168         }               
00169 
00170         m_wndSplitterBar.SetPanes(&m_inspectorSheet, &m_wndHelp);
00171 
00172         m_oldSize.cx = cx;
00173         m_oldSize.cy = cy;
00174 }
00175 
00176 BOOL CInspectorDlg::OnInitDialog() 
00177 {
00178         CDialog::OnInitDialog();
00179 
00180         m_NameCtrl.SubclassWindow(GetDlgItem(IDC_EDIT_NAME)->GetSafeHwnd());
00181         m_NameCtrl.EnableWindow(FALSE);
00182 
00183         LOGFONT logFont;
00184         memset(&logFont, 0, sizeof(LOGFONT));
00185         logFont.lfCharSet = DEFAULT_CHARSET;
00186         logFont.lfHeight = INSP_ENTRY_FONT_PTSIZE;
00187         logFont.lfWeight = FW_BOLD;
00188         lstrcpyn(logFont.lfFaceName, INSP_ENTRY_FONT_FACE, sizeof(logFont.lfFaceName)/sizeof(TCHAR));
00189 
00190         VERIFY(m_BoldFont.CreatePointFontIndirect(&logFont, NULL));
00191 
00192         
00193         CWnd* pHelpTitle=GetDlgItem(IDC_HELP_TITLE);
00194         if(pHelpTitle->GetSafeHwnd())
00195         {
00196                 pHelpTitle->SetFont(&m_BoldFont);
00197         }
00198 
00199         // Create inspector lists
00200         for (int i = 0; i < INSP_PANEL_NUM; i++) {
00201                 m_inspectorSheet.InsertItem(i, panelTitles[i]);
00202         
00203                 CRect listRect;
00204                 m_inspectorSheet.GetClientRect(&listRect);
00205                 m_inspectorSheet.AdjustRect(FALSE, &listRect);
00206                 m_inspectorLists[i]->Create(WS_CHILD | WS_VISIBLE, listRect,&m_inspectorSheet,IDC_INSPECTOR_LIST0+i);
00207                 m_inspectorLists[i]->ShowWindow(SW_HIDE);
00208         }
00209 
00210 
00211         // Test 
00212 /*
00213         CListItem ListItem;
00214 
00215         CItemData ItemData;
00216         
00217         ListItem.bIsContainer=true;
00218 
00219         ListItem.strName="General Properties";
00220         
00221         ListItem.Value=ItemData;
00222         ListItem.DefValue=ItemData;
00223         m_inspectorLists[0]->AddItem(ListItem);
00224 
00225         ListItem.bIsContainer=false;
00226         ListItem.strName="Eye color";
00227         ItemData.SetColorValue(RGB(255,0,0));
00228         
00229         ListItem.Value=ItemData;
00230         ListItem.DefValue=ItemData;
00231         m_inspectorLists[0]->AddItem(ListItem);
00232         
00233         ListItem.strName="Her eyes are blue";
00234         ItemData.SetBoolValue(false);
00235         
00236         ListItem.Value=ItemData;
00237         ListItem.DefValue=ItemData;
00238         m_inspectorLists[0]->AddItem(ListItem);
00239 
00240         ListItem.strName="Fat";
00241         ItemData.SetDoubleValue(2.2);
00242         
00243         ListItem.Value=ItemData;
00244         ListItem.DefValue=ItemData;
00245         m_inspectorLists[0]->AddItem(ListItem);
00246 
00247         ListItem.strName="Amount";
00248         ItemData.SetIntValue(2);
00249 
00250         ListItem.Value=ItemData;
00251         ListItem.DefValue=ItemData;
00252         m_inspectorLists[0]->AddItem(ListItem);
00253 
00254 
00255         ListItem.strName="Say";
00256         ItemData.SetStringValue("Hello");
00257 
00258         ListItem.Value=ItemData;
00259         ListItem.DefValue=ItemData;
00260         m_inspectorLists[0]->AddItem(ListItem);
00261 
00262         ListItem.strName="Where would you go?";
00263         ItemData.SetCompassValue(1);
00264         
00265         ListItem.Value=ItemData;
00266         ListItem.DefValue=ItemData;
00267         m_inspectorLists[0]->AddItem(ListItem);
00268 
00269         ListItem.strName="Where is Detroit?";
00270         ItemData.SetCompassExclValue(1);
00271         
00272         ListItem.Value=ItemData;
00273         ListItem.DefValue=ItemData;
00274         m_inspectorLists[0]->AddItem(ListItem);
00275 
00276         
00277         ListItem.strName="Specific Properties";
00278         ListItem.bIsContainer=true;
00279         ItemData.dataType=ITEMDATA_NULL;
00280         
00281         ListItem.Value=ItemData;
00282         ListItem.DefValue=ItemData;
00283         m_inspectorLists[0]->AddItem(ListItem);
00284         
00285         ListItem.bIsContainer=false;
00286         ListItem.strName="Turkey Preference";
00287         ItemData.SetStringValue("Goes down with Thanksgiving");
00288         ListItem.bIsDefault=true;
00289         
00290         ListItem.Value=ItemData;
00291         ListItem.DefValue=ItemData;
00292         m_inspectorLists[0]->AddItem(ListItem);
00293 
00294         ListItem.bIsDefault=false;
00295         CStringArray strArr;
00296         CString strElement;
00297 
00298         strElement="Row 1";
00299         strArr.Add(strElement);
00300 
00301         strElement="Row 2";
00302         strArr.Add(strElement);
00303         
00304         strElement="Row 3";
00305         strArr.Add(strElement);
00306 
00307         strElement="Row 4";
00308         strArr.Add(strElement);
00309         ItemData.SetStringValue(strArr,4);
00310         
00311         ListItem.Value=ItemData;
00312         ListItem.DefValue=ItemData;
00313         m_inspectorLists[0]->AddItem(ListItem);
00314 
00315 
00316 
00317         ItemData.SetListValue(strArr,2);
00318 
00319         ListItem.Value=ItemData;
00320         ListItem.DefValue=ItemData;
00321         m_inspectorLists[0]->AddItem(ListItem);
00322 
00323 
00324 */
00325 
00327 
00328 
00329         // Create Splitter
00330         CRect rect(0,0,0,0);
00331         m_wndSplitterBar.Create(WS_CHILD|WS_VISIBLE, rect,this,IDC_SPLITTER_BAR,TRUE);
00332         m_wndSplitterBar.SetPanes(&m_inspectorSheet,&m_wndHelp);
00333         
00334         // Initialize Panel contents
00335         SwitchPanel(INSP_ATTR_PANEL);
00336 
00337         return TRUE;  // return TRUE unless you set the focus to a control
00338                       // EXCEPTION: OCX Property Pages should return FALSE
00339 }
00340 
00341 void CInspectorDlg::OnSelchangeInspectorSheet(NMHDR* pNMHDR, LRESULT* pResult) 
00342 {
00343         SwitchPanel(m_inspectorSheet.GetCurSel());
00344         *pResult = 0;
00345 }
00346 
00347 void CInspectorDlg::SwitchPanel(int panel)
00348 {
00349         CWnd *checkBox = GetDlgItem(IDC_CHECK_KIND);
00350 
00351         m_inspectorLists[m_currentPanel]->ShowWindow(SW_HIDE);
00352 
00353         if(m_bIsPanelVisible[panel])
00354         {
00355                 m_inspectorLists[panel]->ShowWindow(TRUE);
00356                 checkBox->EnableWindow(panel == INSP_PREF_PANEL);
00357         }
00358         else
00359         {
00360                 checkBox->EnableWindow(FALSE);
00361         }
00362         m_currentPanel = panel;
00363 
00364         m_inspectorLists[panel]->RefreshState();
00365 }
00366 
00367 void CInspectorDlg::Reset(bool preserveScrollPos)
00368 {
00369 }
00370 
00371 void CInspectorDlg::ShowPanel(int panel)
00372 {
00373         m_inspectorSheet.SetCurSel(panel);
00374         SwitchPanel(panel);
00375 }
00376 
00377 void CInspectorDlg::CyclePanel(bool frwd)
00378 {
00379         int k = m_inspectorSheet.GetCurSel();
00380         ShowPanel( (frwd?++k:k+2) % 3);
00381 }
00382 
00383 
00384 void CInspectorDlg::SetHelp(const CString &strTitle, const CString &strText)
00385 {
00386         CStatic* pHelpTitle=(CStatic*)this->GetDlgItem(IDC_HELP_TITLE);
00387         if(pHelpTitle->GetSafeHwnd())
00388         {
00389                 pHelpTitle->SetWindowText(strTitle);
00390         }
00391 
00392         CStatic* pHelpText=(CStatic*)this->GetDlgItem(IDC_HELP_TEXT);
00393         if(pHelpText->GetSafeHwnd())
00394         {
00395                 pHelpText->SetWindowText(strText);
00396         }
00397 }
00398 
00399 LRESULT CInspectorDlg::OnItemChanged(WPARAM wParam, LPARAM lParam)
00400 {
00401 /*
00402 #ifdef _DEBUG
00403         CString strTemp;
00404         strTemp.Format(_T("Item Changed: %u on Page %u"),wParam,lParam);
00405         MessageBox(strTemp,_T("Item Changed"));
00406 #endif
00407 */
00408         if(lParam==INSP_PREF_PANEL)
00409         {
00410                 OnItemChangedPreference(wParam);
00411         }
00412         else if(lParam==INSP_ATTR_PANEL)
00413         {
00414                 OnItemChangedAttribute(wParam);
00415         }
00416         return TRUE;
00417 }
00418 
00419 void CInspectorDlg::SetName(const CString &strName, bool bIsReadOnly,bool bIsEnabled)
00420 {
00421         m_NameCtrl.SetWindowText(strName);
00422         
00423         m_NameCtrl.SetReadOnly(bIsReadOnly);
00424         m_NameCtrl.EnableWindow(bIsEnabled);
00425         
00426         m_strName=strName;
00427 }
00428 
00429 void CInspectorDlg::ShowPanel(int nPanel,bool bIsVisible)
00430 {
00431         m_bIsPanelVisible[nPanel]=bIsVisible;
00432         
00433         if(nPanel==m_currentPanel)
00434         {
00435                 m_inspectorLists[nPanel]->ShowWindow(bIsVisible?SW_SHOW:SW_HIDE);
00436                                 
00437         }               
00438 }
00439 
00440 void CInspectorDlg::OnItemChangedAttribute(int nItem)
00441 {
00442         CListItem ListItem;
00443         m_inspectorLists[INSP_ATTR_PANEL]->GetItem(nItem,ListItem);
00444 
00445         CObjectInspectorCtrl* pParent=(CObjectInspectorCtrl*)GetParent();
00446 
00447         pParent->WriteAttributeItemToMga(ListItem);
00448 }
00449 
00450 
00451 void CInspectorDlg::OnItemChangedPreference(int nItem)
00452 {
00453 
00454         CListItem ListItem;
00455         m_inspectorLists[INSP_PREF_PANEL]->GetItem(nItem,ListItem);
00456         
00457 
00458         UINT uSrcValue;
00459         UINT uDstValue;
00460         CString strSrcValue;
00461         CString strDstValue;
00462         CString strValue;
00463 
00464 
00465         if(ListItem.dwUserData==AUTOROUTER_SOURCE)
00466         {
00467                 CListItem ListItemDst;
00468 
00469                 VERIFY(m_inspectorLists[INSP_PREF_PANEL]->FindByKey(ListItem.dwKeyValue,AUTOROUTER_DESTINATION,ListItemDst));
00470 
00471                 uSrcValue=ListItem.Value.compassVal;
00472                 uDstValue=ListItemDst.Value.compassVal;
00473                 
00474                 CCompassData::toMgaStringCheck(strSrcValue,uSrcValue,true);
00475                 CCompassData::toMgaStringCheck(strDstValue,uDstValue,false);
00476                 
00477                 strValue=strDstValue+strSrcValue;
00478                 ListItem.Value.stringVal.SetAtGrow(0,strValue);
00479         }
00480 
00481         if(ListItem.dwUserData==AUTOROUTER_DESTINATION)
00482         {
00483                 CListItem ListItemSrc;
00484 
00485                 VERIFY(m_inspectorLists[INSP_PREF_PANEL]->FindByKey(ListItem.dwKeyValue,AUTOROUTER_SOURCE,ListItemSrc));
00486 
00487                 uSrcValue=ListItemSrc.Value.compassVal;
00488                 uDstValue=ListItem.Value.compassVal;
00489                 
00490                 CCompassData::toMgaStringCheck(strSrcValue,uSrcValue,true);
00491                 CCompassData::toMgaStringCheck(strDstValue,uDstValue,false);
00492                 
00493                 strValue=strDstValue+strSrcValue;
00494                 ListItem.Value.stringVal.SetAtGrow(0,strValue);
00495         }
00496 
00497         CObjectInspectorCtrl* pParent=(CObjectInspectorCtrl*)GetParent();
00498 
00499         UpdateData(TRUE); // For Kind checkbox
00500         bool bIsKind=(m_forKind!=0);
00501         pParent->WritePreferenceItemToMga(ListItem,bIsKind);
00502 }
00503 
00504 
00505 
00506 afx_msg LRESULT CInspectorDlg::OnNameEditEndOK(WPARAM /*wParam*/, LPARAM /*lParam*/)
00507 {
00508         if(m_NameCtrl.GetModify())
00509         {
00510                 m_NameCtrl.GetWindowText(m_strName);
00511                 CObjectInspectorCtrl* pParent=(CObjectInspectorCtrl*)GetParent();
00512                 pParent->WriteNameToMga(m_strName);
00513         }
00514 
00515         return TRUE;
00516 }
00517 
00518 
00519 afx_msg LRESULT CInspectorDlg::OnNameEditEndCancel(WPARAM /*wParam*/, LPARAM /*lParam*/)
00520 {
00521 
00522         if(m_NameCtrl.GetModify())
00523         {
00524                 m_NameCtrl.SetWindowText(m_strName);
00525                 // The following instructions would issue a whole undo to the MgaProject, causing JIRA GME-231
00526                 //CObjectInspectorCtrl* pParent=(CObjectInspectorCtrl*)GetParent();
00527                 //if( pParent) pParent->UndoRedo();
00528         }
00529         return TRUE;
00530 }
00531 
00532 void CInspectorDlg::OnKillfocusEditName() 
00533 {
00534         OnNameEditEndOK(0,0);
00535 
00536         m_inspectorSheet.SetFocus();
00537         
00538 }
00539 
00540 void CInspectorDlg::Refresh()
00541 {
00542         ShowPanel(m_currentPanel);      
00543 }