GME  13
AnnotationBrowserDlg.cpp
Go to the documentation of this file.
00001 // AnnotationBrowserDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "mgautil.h"
00006 #include "AnnotationBrowserDlg.h"
00007 #include "..\Annotator\AnnotationDefs.h"
00008 #include "resource.h"
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015 
00016 const TCHAR * show_str = _T("Show");
00017 const TCHAR * hide_str = _T("Hide");
00019 // CAnnotationBrowserDlg dialog
00020 
00021 
00022 CAnnotationBrowserDlg::CAnnotationBrowserDlg(const CComPtr<IMgaModel> &model, const CComPtr<IMgaRegNode> &focus, CWnd* pParent /*=NULL*/)
00023         : CDialog(CAnnotationBrowserDlg::IDD, pParent)
00024 {
00025         //{{AFX_DATA_INIT(CAnnotationBrowserDlg)
00026         m_modelName                             = _T("");
00027         m_modelRole                             = _T("");
00028         m_modelKind                             = _T("");
00029         m_anName                                = _T("");
00030         m_anText                                = _T("");
00031         m_anFont                                = _T("");
00032         m_aaDefPos                              = FALSE;
00033         m_aaXCoord                              = 0;
00034         m_aaYCoord                              = 0;
00035         m_bGradientFill                 = FALSE;
00036         m_iGradientDirection    = 0;
00037         m_bCastShadow                   = FALSE;
00038         m_iShadowDepth                  = 9;
00039         m_iShadowDirection              = 45;
00040         m_bRoundCornerRect              = FALSE;
00041         m_iRoundCornerRadius    = 9;
00042         //}}AFX_DATA_INIT
00043 
00044         m_model = model;
00045         m_focus = focus;
00046 }
00047 
00048 CAnnotationBrowserDlg::~CAnnotationBrowserDlg()
00049 {
00050         POSITION pos = m_annotations.GetHeadPosition();
00051         while (pos) {
00052                 delete m_annotations.GetNext(pos);
00053         }
00054 }
00055 
00056 void CAnnotationBrowserDlg::DoDataExchange(CDataExchange* pDX)
00057 {
00058         CDialog::DoDataExchange(pDX);
00059         //{{AFX_DATA_MAP(CAnnotationBrowserDlg)
00060         DDX_Control(pDX, IDC_LIST_ASPECT, m_wndAnnotationAspectList);
00061         DDX_Control(pDX, IDC_ANNOTATION_LIST, m_wndAnnotationList);
00062         DDX_Control(pDX, IDC_ANNOTATION, m_wndAnnotation);
00063         DDX_Text(pDX, IDC_MODELNAME, m_modelName);
00064         DDX_Text(pDX, IDC_MODELROLE, m_modelRole);
00065         DDX_Text(pDX, IDC_MODELKIND, m_modelKind);
00066         DDX_Text(pDX, IDC_EDIT_NAME, m_anName);
00067         DDX_Text(pDX, IDC_EDIT_TEXT, m_anText);
00068         DDX_Text(pDX, IDC_EDIT_FONT, m_anFont);
00069         DDX_Check(pDX, IDC_CHECK_DEFPOS, m_aaDefPos);
00070         DDX_Text(pDX, IDC_EDIT_XCOORD, m_aaXCoord);
00071         DDX_Text(pDX, IDC_EDIT_YCOORD, m_aaYCoord);
00072         DDX_Check(pDX, IDC_CHECK_GRADIENTFILL, m_bGradientFill);
00073         DDX_Text(pDX, IDC_EDIT_GRADIENTDIR, m_iGradientDirection);
00074         DDX_Check(pDX, IDC_CHECK_CASTSHADOW, m_bCastShadow);
00075         DDX_Text(pDX, IDC_EDIT_SHADOWDEPTH, m_iShadowDepth);
00076         DDX_Text(pDX, IDC_EDIT_SHADOWDIRECTION, m_iShadowDirection);
00077         DDX_Check(pDX, IDC_CHECK_ROUNDCORNER, m_bRoundCornerRect);
00078         DDX_Text(pDX, IDC_EDIT_CORNERRADIUS, m_iRoundCornerRadius);
00079         //}}AFX_DATA_MAP
00080         DDX_Control(pDX, IDC_CHECK1, m_inheritable);
00081         DDX_Control(pDX, IDC_SHOWHIDEBUTTON, m_showHideBtn);
00082         DDX_Control(pDX, IDC_REDERIVEBUTTON, m_rederiveBtn);
00083 }
00084 
00085 
00086 BEGIN_MESSAGE_MAP(CAnnotationBrowserDlg, CDialog)
00087         //{{AFX_MSG_MAP(CAnnotationBrowserDlg)
00088         ON_WM_SIZE()
00089         ON_NOTIFY(LVN_ITEMCHANGED, IDC_ANNOTATION_LIST, OnItemchangedAnnotationList)
00090         ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
00091         ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_ASPECT, OnItemchangedListAspect)
00092         ON_BN_CLICKED(IDC_CHECK_DEFPOS, OnCheckDefpos)
00093         ON_BN_CLICKED(IDC_SHOWHIDEBUTTON, OnBnClickedShowhidebutton)
00094         ON_BN_CLICKED(IDC_REDERIVEBUTTON, OnBnClickedRederivebutton)
00095         ON_BN_CLICKED(IDC_CHECK_GRADIENTFILL, OnBnClickedCheckGradientfill)
00096         ON_BN_CLICKED(IDC_CHECK_CASTSHADOW, OnBnClickedCheckCastshadow)
00097         ON_BN_CLICKED(IDC_CHECK_ROUNDCORNER, OnBnClickedCheckRoundCorner)
00098         //}}AFX_MSG_MAP
00099 END_MESSAGE_MAP()
00100 
00102 // CAnnotationBrowserDlg message handlers
00103 
00104 BOOL CAnnotationBrowserDlg::OnInitDialog() 
00105 {
00106         CDialog::OnInitDialog();
00107         
00108         m_colorbtn.SubclassDlgItem(IDC_COMBO_COLOR,this); 
00109         m_bgcolorbtn.SubclassDlgItem(IDC_COMBO_BGCOLOR,this); 
00110         m_shadowcolorbtn.SubclassDlgItem(IDC_COMBO_SHADOWCOLOR,this); 
00111         m_gradientcolorbtn.SubclassDlgItem(IDC_COMBO_GRADIENTCOLOR,this); 
00112 
00113         CRect rect(0,0,0,0);
00114 
00115         m_wndSplitterBar.Create(WS_CHILD|WS_BORDER|WS_DLGFRAME|WS_VISIBLE, rect,this,999);
00116         m_wndSplitterBar.SetPanes(&m_wndAnnotationList,&m_wndAnnotation);
00117 
00118         CRect clientRect;
00119         m_wndAnnotationList.GetClientRect(&clientRect);
00120         int ctrlSize = clientRect.Width();
00121         m_wndAnnotationList.InsertColumn(0, _T("Name"), LVCFMT_LEFT,  ctrlSize / 3, -1);
00122         m_wndAnnotationList.InsertColumn(1, _T("Text"), LVCFMT_LEFT,  (2*ctrlSize) / 3, -1);
00123 
00124         m_wndAnnotationAspectList.GetClientRect(&clientRect);
00125         ctrlSize = clientRect.Width();
00126         m_wndAnnotationAspectList.InsertColumn(0, _T("Aspect"), LVCFMT_LEFT,  ctrlSize, -1);
00127 
00128         DWORD dwStyle = ::SendMessage(m_wndAnnotationAspectList.GetSafeHwnd(),LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
00129         dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES ;
00130         ::SendMessage(m_wndAnnotationAspectList.GetSafeHwnd(),LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
00131 
00132         dwStyle = ::SendMessage(m_wndAnnotationList.GetSafeHwnd(),LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
00133         dwStyle |= LVS_EX_FULLROWSELECT;
00134         ::SendMessage(m_wndAnnotationList.GetSafeHwnd(),LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);
00135 
00136         try {
00137                 CComBSTR bstr_tmp;
00138                 COMTHROW(m_model->get_Name(&bstr_tmp));
00139                 CopyTo(bstr_tmp, m_modelName);
00140                 SetWindowTextW(L"Annotations for '" + m_modelName + "'");
00141 
00142                 CComPtr<IMgaMetaFCO> metaFco;
00143                 COMTHROW(m_model->get_Meta(&metaFco));
00144                 if (metaFco) {
00145                         bstr_tmp.Empty();
00146                         COMTHROW(metaFco->get_DisplayedName(&bstr_tmp));
00147                         CopyTo(bstr_tmp,m_modelKind);
00148                 }
00149                 else {
00150                         m_modelKind = _T("N/A");
00151                 }
00152 
00153                 CComPtr<IMgaMetaRole> metaRole;
00154                 COMTHROW(m_model->get_MetaRole(&metaRole) );
00155                 if (metaRole) {
00156                         bstr_tmp.Empty();
00157                         COMTHROW(metaRole->get_Name(&bstr_tmp));
00158                         CopyTo(bstr_tmp, m_modelRole);
00159                 }
00160                 else {
00161                         m_modelRole = _T("N/A");
00162                 }
00163         }
00164         catch (hresult_exception &){
00165                 ASSERT(("Error while initializing Annotation Browser.", false));
00166         }
00167         UpdateData(FALSE);
00168 
00169         if (m_model) {
00170                 FillAspects();
00171                 FillAnnotations();
00172         }
00173 
00174         int listIdx = 0, focusIdx = 0;
00175         POSITION pos = m_annotations.GetHeadPosition();
00176         if (pos) {
00177                 while (pos) {
00178                         CAnnotationNode *node = m_annotations.GetNext(pos);
00179                         LVITEM lvItem;
00180                         lvItem.mask = LVIF_PARAM | LVIF_TEXT;
00181                         lvItem.iItem = listIdx++;
00182                         lvItem.iSubItem = 0;
00183                         lvItem.pszText = node->m_name.GetBuffer(node->m_name.GetLength());
00184                         lvItem.lParam = (LPARAM)node;
00185 
00186                         int retIdx = m_wndAnnotationList.InsertItem(&lvItem);
00187                         if (node->m_regNode->Path == m_focus->Path) {
00188                                 focusIdx = retIdx;
00189                         }
00190 
00191                         lvItem.mask = LVIF_TEXT;
00192                         lvItem.iItem = retIdx;
00193                         lvItem.iSubItem = 1;
00194                         lvItem.pszText = node->m_text.GetBuffer(node->m_text.GetLength());
00195                         m_wndAnnotationList.SetItem(&lvItem);
00196                 }
00197                 m_wndAnnotationList.SetItemState(focusIdx, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
00198                 m_wndAnnotationList.EnsureVisible(focusIdx, FALSE);
00199         }
00200         else
00201         {
00202                 // FIXME: should disable more things, but this gets the point across
00203                 GetDlgItem(IDC_EDIT_NAME)->EnableWindow(FALSE);
00204                 GetDlgItem(IDC_EDIT_TEXT)->EnableWindow(FALSE);
00205         }
00206 
00207         ::PostMessage(GetSafeHwnd(), WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(IDC_EDIT_TEXT)->GetSafeHwnd()), TRUE);
00208         /*
00209         //Test
00210         for (int i = 0; i< m_aspectNames.GetSize(); i++) {
00211                 m_wndAnnotationAspectList.InsertItem(i, m_aspectNames[i]);
00212                 m_wndAnnotationAspectList.SetCheck(i, i % 2);
00213         }
00214 */
00215         return TRUE;  // return TRUE unless you set the focus to a control
00216                       // EXCEPTION: OCX Property Pages should return FALSE
00217 }
00218 
00219 void CAnnotationBrowserDlg::OnSize(UINT nType, int cx, int cy) 
00220 {
00221         CDialog::OnSize(nType, cx, cy);
00222 
00223         CRect origTopRect(0, 0, 0+406, 0+20), origBottomRect(0, 334, 0+406, 334+20 ); 
00224         MapDialogRect(&origTopRect);
00225         MapDialogRect(&origBottomRect);
00226 
00227         CRect rectList, rectPanel;
00228         if (m_wndAnnotationList.GetSafeHwnd()) {
00229                 m_wndAnnotationList.GetWindowRect(&rectList);
00230                 ScreenToClient(&rectList);
00231         }
00232         if (m_wndAnnotation.GetSafeHwnd()) {
00233                 m_wndAnnotation.GetWindowRect(&rectPanel);
00234                 ScreenToClient(&rectPanel);
00235         }
00236 
00237         // Not perfect....
00238         double ratio = (double)rectList.Width()/((double)rectPanel.Width()+(double)rectList.Width());
00239 
00240         if (m_wndAnnotation.GetSafeHwnd() && m_wndAnnotationList.GetSafeHwnd()) {
00241                 m_wndAnnotationList.SetWindowPos(NULL, 0, origTopRect.bottom, static_cast<int>(cx*ratio), cy - (origBottomRect.bottom-origBottomRect.top) - origTopRect.bottom, SWP_NOZORDER);
00242                 m_wndAnnotation.SetWindowPos(NULL, static_cast<int>(cx*ratio)+GetSystemMetrics(SM_CYFRAME), origTopRect.bottom, cx - (static_cast<int>(cx*ratio)+GetSystemMetrics(SM_CYFRAME)), cy - (origBottomRect.bottom-origBottomRect.top) - origTopRect.bottom, SWP_NOZORDER);
00243                 m_wndSplitterBar.SetPanes(&m_wndAnnotationList,&m_wndAnnotation);
00244         }
00245 
00246         CRect rect3(0, 338, 0+406, 338+17);
00247         MapDialogRect(&rect3);
00248         CRect rectDlg;
00249         GetClientRect(&rectDlg);
00250         ratio = ((double)(rectDlg.Width())/ 406.0 );
00251 
00252         CWnd* wndOK = this->GetDlgItem(IDOK);
00253         if (wndOK) {
00254                 CRect origWnd;
00255                 wndOK->GetClientRect(&origWnd);
00256                 wndOK->MoveWindow(static_cast<int>(112.0 * ratio), rectDlg.bottom - (rect3.bottom - rect3.top), origWnd.Width(), origWnd.Height());
00257         }
00258         CWnd* wndCANCEL = this->GetDlgItem(IDCANCEL);
00259         if (wndCANCEL) {
00260                 CRect origWnd;
00261                 wndCANCEL->GetClientRect(&origWnd);
00262                 wndCANCEL->MoveWindow(static_cast<int>(242.0 * ratio), rectDlg.bottom - (rect3.bottom - rect3.top), origWnd.Width(), origWnd.Height());
00263         }
00264 }
00265 
00266 void CAnnotationBrowserDlg::OnOK() 
00267 {
00268         POSITION pos = m_wndAnnotationList.GetFirstSelectedItemPosition();
00269         if (pos) {
00270                 int nItem = m_wndAnnotationList.GetNextSelectedItem(pos);
00271                 CAnnotationNode *node = (CAnnotationNode *)m_wndAnnotationList.GetItemData(nItem);
00272                 SavePanelToNode(node);
00273         }
00274         
00275         CDialog::OnOK();
00276 }
00277 
00278 void CAnnotationBrowserDlg::FillAspects()
00279 {
00280         m_aspectNames.RemoveAll();
00281         m_aspectNames.Add(_T("DEFAULT"));
00282 
00283         CComPtr<IMgaMetaFCO>    metaFCO;
00284         COMTHROW(m_model->get_Meta(&metaFCO));
00285         CComPtr<IMgaMetaModel>  metaModel;
00286         COMTHROW(metaFCO.QueryInterface(&metaModel));
00287         CComPtr<IMgaMetaAspects>        aspects;
00288         COMTHROW(metaModel->get_Aspects(&aspects));
00289         MGACOLL_ITERATE(IMgaMetaAspect, aspects) {
00290                 CComPtr<IMgaMetaAspect> aspect;
00291                 aspect = MGACOLL_ITER;
00292 
00293                 CComBSTR bstr;
00294                 COMTHROW(aspect->get_Name(&bstr));
00295                 COLE2T aspectName(bstr);
00296                 m_aspectNames.Add(aspectName);
00297         }
00298         MGACOLL_ITERATE_END;
00299 }
00300 
00301 void CAnnotationBrowserDlg::FillAnnotations()
00302 {
00303         try {
00304                 CComBSTR annRootName(AN_ROOT);
00305                 CComPtr<IMgaRegNode> annRootNode;
00306                 COMTHROW(m_model->get_RegistryNode(annRootName, &annRootNode));
00307                 CComPtr<IMgaRegNodes> subNodes;
00308                 COMTHROW(annRootNode->get_SubNodes(VARIANT_TRUE, &subNodes));//get all nodes (inheriteds also)
00309                 MGACOLL_ITERATE(IMgaRegNode, subNodes) {
00310                         CComPtr<IMgaRegNode> subNode;
00311                         subNode = MGACOLL_ITER;
00312                         CAnnotationNode *node = new CAnnotationNode(subNode, m_model->DerivedFrom);
00313                         node->Read(this);
00314                         m_annotations.AddTail(node);
00315                 }
00316                 MGACOLL_ITERATE_END;
00317         }
00318         catch (hresult_exception &) {
00319                 ASSERT(("Error while reading annotations.", false));
00320         }
00321 }
00322 
00323 
00324 void CAnnotationBrowserDlg::UpdateAnnotations(void)
00325 {
00326         POSITION pos = m_annotations.GetHeadPosition();
00327         while (pos) {
00328                 m_annotations.GetNext(pos)->Write(this);
00329         }
00330 }
00331 
00332 void CAnnotationBrowserDlg::OnItemchangedAnnotationList(NMHDR* pNMHDR, LRESULT* pResult) 
00333 {
00334         NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00335         *pResult = 0;
00336 
00337         if ((pNMListView->uChanged & LVIF_STATE) == LVIF_STATE) {
00338                 CAnnotationNode *node = (CAnnotationNode*)pNMListView->lParam;
00339 
00340                 if ( (pNMListView->uNewState & LVIS_SELECTED) && (!(pNMListView->uOldState & LVIS_SELECTED)) ) {
00341                         LoadNodeToPanel(node);
00342                 }
00343                 if ( (!(pNMListView->uNewState & LVIS_SELECTED)) && (pNMListView->uOldState & LVIS_SELECTED) ) {
00344                         SavePanelToNode(node);          
00345                 }
00346                 if (!(pNMListView->uNewState & LVIS_SELECTED) && !this->m_wndAnnotationList.GetFirstSelectedItemPosition()) {
00347                         GetDlgItem(IDC_EDIT_NAME)->EnableWindow(FALSE);
00348                         GetDlgItem(IDC_EDIT_TEXT)->EnableWindow(FALSE);
00349                 }
00350                 else
00351                 {
00352                         GetDlgItem(IDC_EDIT_NAME)->EnableWindow(TRUE);
00353                         GetDlgItem(IDC_EDIT_TEXT)->EnableWindow(TRUE);
00354                 }
00355         }
00356 }
00357 
00358 void CAnnotationBrowserDlg::UpdateFontStr(void) {
00359         int height = m_anLogFont.lfHeight;
00360         if (height < 0) {
00361                 height = -MulDiv(height, 72, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY));
00362         }
00363         m_anFont.Format(_T("%s, %d, %s%s"), m_anLogFont.lfFaceName, height, m_anLogFont.lfWeight <= 500 ? _T("Regular") : _T("Bold"), m_anLogFont.lfItalic ? _T(", Italic") : _T(""));
00364 }
00365 
00366 void CAnnotationBrowserDlg::SavePanelToNode(CAnnotationNode *node) {
00367         UpdateData();
00368         node->m_name = m_anName;
00369         node->m_text = m_anText;
00370 
00371         // set inheritable if checkbutton is checked
00372         node->m_inheritable  = (m_inheritable.GetCheck() == BST_CHECKED);
00373 
00374         // set hidden attr iff window text is 'show'
00375         CString tx;
00376         m_showHideBtn.GetWindowText( tx);
00377         node->m_hidden = tx == show_str;
00378 
00379         memcpy(&(node->m_logfont), &m_anLogFont, sizeof(LOGFONT));
00380         node->m_color                           = m_colorbtn.currentcolor;
00381         node->m_bgcolor                         = m_bgcolorbtn.currentcolor;
00382         node->m_crShadow                        = m_shadowcolorbtn.currentcolor;
00383         node->m_crGradient                      = m_gradientcolorbtn.currentcolor;
00384         node->m_bGradientFill           = (m_bGradientFill == TRUE);
00385         node->m_iGradientDirection      = m_iGradientDirection;
00386         node->m_bCastShadow                     = (m_bCastShadow == TRUE);
00387         node->m_iShadowDepth            = m_iShadowDepth;
00388         node->m_iShadowDirection        = m_iShadowDirection;
00389         node->m_bRoundCornerRect        = (m_bRoundCornerRect == TRUE);
00390         node->m_iRoundCornerRadius      = m_iRoundCornerRadius;
00391 
00392         POSITION pos = m_wndAnnotationAspectList.GetFirstSelectedItemPosition();
00393         if (pos) {
00394                 int nItem = m_wndAnnotationAspectList.GetNextSelectedItem(pos);
00395                 CAnnotationAspect *aa = (CAnnotationAspect *)m_wndAnnotationAspectList.GetItemData(nItem);
00396                 SaveVisibilityPanelToAA(aa);
00397         }
00398 
00399         for (int i = 0; i < m_wndAnnotationAspectList.GetItemCount(); i++) {
00400                 node->m_aspects[i].m_isVisible = (m_wndAnnotationAspectList.GetCheck(i) == TRUE);
00401         }
00402 
00403         LVFINDINFO lvInfo;
00404         lvInfo.flags = LVFI_PARAM;
00405         lvInfo.lParam = (LPARAM)node;
00406         int nItem = m_wndAnnotationList.FindItem(&lvInfo);
00407         if (nItem >= 0) {
00408                 LVITEM lvItem;
00409                 
00410                 lvItem.mask = LVIF_TEXT;
00411                 lvItem.iItem = nItem;
00412                 lvItem.iSubItem = 0;
00413                 lvItem.pszText = node->m_name.GetBuffer(node->m_name.GetLength());
00414                 m_wndAnnotationList.SetItem(&lvItem);
00415 
00416                 lvItem.iSubItem = 1;
00417                 lvItem.pszText = node->m_text.GetBuffer(node->m_text.GetLength());
00418                 m_wndAnnotationList.SetItem(&lvItem);
00419         }
00420 }
00421 
00422 void CAnnotationBrowserDlg::LoadNodeToPanel(CAnnotationNode *node) {
00423         m_anName = node->m_name;
00424         m_anText = node->m_text;
00425 
00426         // inheritable checkbox
00427         m_inheritable.SetCheck( node->m_inheritable? BST_CHECKED:BST_UNCHECKED );
00428         
00429         // rederive btn
00430         m_rederiveBtn.EnableWindow(node->m_canBeRederived);
00431         
00432         // show/hide btn
00433         m_showHideBtn.SetWindowText(node->m_hidden?show_str:hide_str);
00434         m_showHideBtn.EnableWindow(node->m_hidden);
00435         if (node->m_hidden == false && node->m_archetype)
00436         {
00437                 IMgaRegNodePtr archetypeRegNode = node->m_archetype->RegistryNode[node->m_regNode->Path];
00438                 long status = ATTSTATUS_UNDEFINED;
00439                 archetypeRegNode->GetStatus(&status);
00440                 if (status == ATTSTATUS_UNDEFINED)
00441                 {
00442                         m_showHideBtn.EnableWindow(FALSE);
00443                 }
00444                 else
00445                 {
00446                         m_showHideBtn.EnableWindow(TRUE);
00447                 }
00448         }
00449 
00450         memcpy(&m_anLogFont, &(node->m_logfont), sizeof(LOGFONT));
00451         m_colorbtn.currentcolor = node->m_color;
00452         m_bgcolorbtn.currentcolor = node->m_bgcolor;
00453         m_shadowcolorbtn.currentcolor = node->m_crShadow;
00454         m_gradientcolorbtn.currentcolor = node->m_crGradient;
00455         m_bGradientFill = node->m_bGradientFill ? TRUE : FALSE;
00456         m_iGradientDirection = node->m_iGradientDirection;
00457         GetDlgItem(IDC_STATIC_GRADIENTCOLOR)->EnableWindow(node->m_bGradientFill);
00458         GetDlgItem(IDC_COMBO_GRADIENTCOLOR)->EnableWindow(node->m_bGradientFill);
00459         GetDlgItem(IDC_STATIC_GRADIENTDIR)->EnableWindow(node->m_bGradientFill);
00460         GetDlgItem(IDC_EDIT_GRADIENTDIR)->EnableWindow(node->m_bGradientFill);
00461         m_bCastShadow = node->m_bCastShadow ? TRUE : FALSE;
00462         m_iShadowDepth = node->m_iShadowDepth;
00463         GetDlgItem(IDC_STATIC_SHADOWCOLOR)->EnableWindow(node->m_bCastShadow);
00464         GetDlgItem(IDC_COMBO_SHADOWCOLOR)->EnableWindow(node->m_bCastShadow);
00465         GetDlgItem(IDC_STATIC_SHADOWDEPTH)->EnableWindow(node->m_bCastShadow);
00466         GetDlgItem(IDC_EDIT_SHADOWDEPTH)->EnableWindow(node->m_bCastShadow);
00467         GetDlgItem(IDC_STATIC_SHADOWDIRECTION)->EnableWindow(node->m_bCastShadow);
00468         GetDlgItem(IDC_EDIT_SHADOWDIRECTION)->EnableWindow(node->m_bCastShadow);
00469         m_iShadowDirection = node->m_iShadowDirection;
00470         m_bRoundCornerRect = node->m_bRoundCornerRect ? TRUE : FALSE;
00471         GetDlgItem(IDC_STATIC_CORNERRADIUS)->EnableWindow(node->m_bRoundCornerRect);
00472         GetDlgItem(IDC_EDIT_CORNERRADIUS)->EnableWindow(node->m_bRoundCornerRect);
00473         m_iRoundCornerRadius = node->m_iRoundCornerRadius;
00474 
00475         m_wndAnnotationAspectList.DeleteAllItems();
00476         for (int i = 0; i < m_aspectNames.GetSize(); i++) {
00477                 LVITEM lvItem;
00478                 lvItem.mask = LVIF_PARAM | LVIF_TEXT;
00479                 lvItem.iItem = i;
00480                 lvItem.iSubItem = 0;
00481                 lvItem.pszText = m_aspectNames[i].GetBuffer(m_aspectNames[i].GetLength());
00482                 lvItem.lParam = (LPARAM)&(node->m_aspects[i]);
00483 
00484                 int retIdx = m_wndAnnotationAspectList.InsertItem(&lvItem);
00485                 m_wndAnnotationAspectList.SetCheck(retIdx, node->m_aspects[i].m_isVisible ? TRUE : FALSE);
00486         }
00487         m_wndAnnotationAspectList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
00488         m_wndAnnotationAspectList.EnsureVisible(0, FALSE);
00489 
00490         UpdateFontStr();
00491         UpdateData(FALSE);
00492         m_colorbtn.RedrawWindow();
00493         m_bgcolorbtn.RedrawWindow();
00494         m_shadowcolorbtn.RedrawWindow();
00495         m_gradientcolorbtn.RedrawWindow();
00496 }
00497 
00498 void CAnnotationBrowserDlg::OnButtonFont() 
00499 {
00500         UpdateData(TRUE);//fix for JIRA bug GME-133
00501         CFontDialog dlg(&m_anLogFont);
00502         if (dlg.DoModal() == IDOK) {
00503                 dlg.GetCurrentFont(&m_anLogFont);
00504                 UpdateFontStr();
00505                 UpdateData(FALSE);
00506         }
00507 }
00508 
00509 void CAnnotationBrowserDlg::OnItemchangedListAspect(NMHDR* pNMHDR, LRESULT* pResult) 
00510 {
00511         NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00512         *pResult = 0;
00513 
00514         if ((pNMListView->uChanged & LVIF_STATE) == LVIF_STATE) {
00515                 CAnnotationAspect *aa = (CAnnotationAspect*)pNMListView->lParam;
00516 
00517                 if ( (pNMListView->uNewState & LVIS_SELECTED) && (!(pNMListView->uOldState & LVIS_SELECTED)) ) {
00518                         LoadAAToVisibilityPanel(aa);
00519                 }
00520                 if ( (!(pNMListView->uNewState & LVIS_SELECTED)) && (pNMListView->uOldState & LVIS_SELECTED) ) {
00521                         SaveVisibilityPanelToAA(aa);            
00522                 }
00523         }
00524 }
00525 
00526 
00527 void CAnnotationBrowserDlg::LoadAAToVisibilityPanel(CAnnotationAspect *aa) {
00528         m_aaXCoord = aa->m_loc.x;
00529         m_aaYCoord = aa->m_loc.y;
00530         m_aaDefPos = aa->m_isLocDef ? TRUE : FALSE;
00531         GetDlgItem(IDC_EDIT_XCOORD)->EnableWindow(aa->m_isLocDef ? FALSE : TRUE);
00532         GetDlgItem(IDC_EDIT_YCOORD)->EnableWindow(aa->m_isLocDef ? FALSE : TRUE);
00533         UpdateData(FALSE);
00534 }
00535 
00536 void CAnnotationBrowserDlg::SaveVisibilityPanelToAA(CAnnotationAspect *aa) {
00537         UpdateData();
00538         aa->m_loc.x = m_aaXCoord;
00539         aa->m_loc.y = m_aaYCoord;
00540         aa->m_isLocDef = (m_aaDefPos == TRUE);
00541 }
00542 
00543 void CAnnotationBrowserDlg::OnCheckDefpos() 
00544 {
00545         CButton *check = (CButton*)GetDlgItem(IDC_CHECK_DEFPOS);
00546         GetDlgItem(IDC_EDIT_XCOORD)->EnableWindow(check->GetCheck() > 0 ? FALSE : TRUE);
00547         GetDlgItem(IDC_EDIT_YCOORD)->EnableWindow(check->GetCheck() > 0 ? FALSE : TRUE);                
00548 }
00549 
00550 void CAnnotationBrowserDlg::OnBnClickedShowhidebutton()
00551 {
00552         // swap 'show' and 'hide'
00553         CString tx;
00554         m_showHideBtn.GetWindowText( tx);
00555         m_showHideBtn.SetWindowText( tx == show_str?hide_str:show_str);
00556 }
00557 
00558 void CAnnotationBrowserDlg::OnBnClickedRederivebutton()
00559 {
00560         POSITION pos = m_wndAnnotationList.GetFirstSelectedItemPosition();
00561         if (pos) {
00562                 // the actually selected item
00563                 int nItem = m_wndAnnotationList.GetNextSelectedItem(pos);
00564                 CAnnotationNode *node = (CAnnotationNode *)m_wndAnnotationList.GetItemData(nItem);
00565                 
00566                 // rederive by clearing the node contents
00567                 if (node)
00568                         COMTHROW(node->m_regNode->RemoveTree());
00569                 
00570                 // read back the values from node->regNode, this time (i)nherited values are read
00571                 node->Read( this);
00572                 
00573                 LoadNodeToPanel(node);
00574         }
00575 }
00576 
00577 void CAnnotationBrowserDlg::OnBnClickedCheckGradientfill()
00578 {
00579         CButton* pCheck = (CButton*)GetDlgItem(IDC_CHECK_GRADIENTFILL);
00580         BOOL bGradientFill = pCheck->GetCheck();
00581 
00582         GetDlgItem(IDC_STATIC_GRADIENTCOLOR)->EnableWindow(bGradientFill);
00583         GetDlgItem(IDC_COMBO_GRADIENTCOLOR)->EnableWindow(bGradientFill);
00584         GetDlgItem(IDC_STATIC_GRADIENTDIR)->EnableWindow(bGradientFill);
00585         GetDlgItem(IDC_EDIT_GRADIENTDIR)->EnableWindow(bGradientFill);
00586 }
00587 
00588 void CAnnotationBrowserDlg::OnBnClickedCheckCastshadow()
00589 {
00590         CButton* pCheck = (CButton*)GetDlgItem(IDC_CHECK_CASTSHADOW);
00591         BOOL bCastShadow = pCheck->GetCheck();
00592 
00593         GetDlgItem(IDC_STATIC_SHADOWCOLOR)->EnableWindow(bCastShadow);
00594         GetDlgItem(IDC_COMBO_SHADOWCOLOR)->EnableWindow(bCastShadow);
00595         GetDlgItem(IDC_STATIC_SHADOWDEPTH)->EnableWindow(bCastShadow);
00596         GetDlgItem(IDC_EDIT_SHADOWDEPTH)->EnableWindow(bCastShadow);
00597         GetDlgItem(IDC_STATIC_SHADOWDIRECTION)->EnableWindow(bCastShadow);
00598         GetDlgItem(IDC_EDIT_SHADOWDIRECTION)->EnableWindow(bCastShadow);
00599 }
00600 
00601 void CAnnotationBrowserDlg::OnBnClickedCheckRoundCorner()
00602 {
00603         CButton* pCheck = (CButton*)GetDlgItem(IDC_CHECK_ROUNDCORNER);
00604         BOOL bRoundCorner = pCheck->GetCheck();
00605 
00606         GetDlgItem(IDC_STATIC_CORNERRADIUS)->EnableWindow(bRoundCorner);
00607         GetDlgItem(IDC_EDIT_CORNERRADIUS)->EnableWindow(bRoundCorner);
00608 }