GME  13
AnnotatorRectanglePart.cpp
Go to the documentation of this file.
00001 //################################################################################################
00002 //
00003 // Annotator rectangle part decorator class
00004 //      AnnotatorRectanglePart.cpp
00005 //
00006 //################################################################################################
00007 
00008 #include "StdAfx.h"
00009 #include "AnnotationDefs.h"
00010 #include "AnnotatorRectanglePart.h"
00011 #include "DecoratorExceptions.h"
00012 
00013 
00014 namespace AnnotatorDecor {
00015 
00016 //################################################################################################
00017 //
00018 // CLASS : AnnotatorRectanglePart
00019 //
00020 //################################################################################################
00021 
00022 AnnotatorRectanglePart::AnnotatorRectanglePart(PartBase* pPart, CComPtr<IMgaCommonDecoratorEvents>& eventSink):
00023         VectorPart(pPart, eventSink),
00024         m_regRoot                               (NULL),
00025         m_crBgColor                             (AN_DEFAULT_BGCOLOR),
00026         m_bRoundCornerRect              (false),
00027         m_iRoundCornerRadius    (9)
00028 {
00029         m_crShadow                                      = AN_DEFAULT_SHADOWCOLOR;
00030         m_crGradient                            = AN_DEFAULT_GRADIENTCOLOR;
00031 
00032         brushColorVariableName  = DecoratorSDK::PREF_FILLCOLOR;
00033 }
00034 
00035 AnnotatorRectanglePart::~AnnotatorRectanglePart()
00036 {
00037 }
00038 
00039 void AnnotatorRectanglePart::SetParam(const CString& strName, VARIANT vValue)
00040 {
00041         if (!strName.CompareNoCase(AN_PARAM_ROOTNODE)) {
00042                 CComVariant     variantval(vValue);
00043                 try {
00044                         if (!m_regRoot) {
00045                                 COMTHROW(variantval.ChangeType(VT_UNKNOWN));
00046                                 CComPtr<IUnknown> unk(variantval.punkVal);
00047                                 COMTHROW(unk.QueryInterface(&m_regRoot));
00048                         }
00049                         ReadPreferences();
00050                 }
00051                 catch (hresult_exception&) {
00052                         throw DecoratorException((DecoratorExceptionCode)E_DECORATOR_UNKNOWN_PARAMETER);
00053                 }
00054         } else {
00055                 throw DecoratorException((DecoratorExceptionCode)E_DECORATOR_UNKNOWN_PARAMETER);
00056         }
00057 }
00058 
00059 bool AnnotatorRectanglePart::GetParam(const CString& strName, VARIANT* pvValue)
00060 {
00061         if (!strName.CompareNoCase(AN_PARAM_ROOTNODE)) {
00062                 CComVariant     variantval;
00063                 variantval.Attach(pvValue);
00064                 variantval = m_regRoot;
00065         } else {
00066                 throw DecoratorException((DecoratorExceptionCode)E_DECORATOR_UNKNOWN_PARAMETER);
00067         }
00068         return true;
00069 }
00070 
00071 void AnnotatorRectanglePart::Draw(CDC* pDC, Gdiplus::Graphics* gdip)
00072 {
00073         VectorPart::Draw(pDC, gdip);
00074 }
00075 
00076 void AnnotatorRectanglePart::InitializeEx(CComPtr<IMgaProject>& pProject, CComPtr<IMgaMetaPart>& pPart, CComPtr<IMgaFCO>& pFCO,
00077                                                                                   HWND parentWnd, DecoratorSDK::PreferenceMap& preferences)
00078 {
00079         preferences[DecoratorSDK::PREF_FILLCOLOR]                       = DecoratorSDK::PreferenceVariant(m_crBgColor);
00080         preferences[DecoratorSDK::PREF_SHADOWCOLOR]                     = DecoratorSDK::PreferenceVariant(m_crShadow);
00081         preferences[DecoratorSDK::PREF_GRADIENTCOLOR]           = DecoratorSDK::PreferenceVariant(m_crGradient);
00082         preferences[DecoratorSDK::PREF_ITEMGRADIENTFILL]        = DecoratorSDK::PreferenceVariant(m_bGradientFill);
00083         preferences[DecoratorSDK::PREF_GRADIENTDIRECTION]       = DecoratorSDK::PreferenceVariant(m_iGradientDirection);
00084         preferences[DecoratorSDK::PREF_ITEMSHADOWCAST]          = DecoratorSDK::PreferenceVariant(m_bCastShadow);
00085         preferences[DecoratorSDK::PREF_SHADOWTHICKNESS]         = DecoratorSDK::PreferenceVariant(m_iShadowDepth);
00086         preferences[DecoratorSDK::PREF_SHADOWDIRECTION]         = DecoratorSDK::PreferenceVariant(m_iShadowDirection);
00087         preferences[DecoratorSDK::PREF_ROUNDCORNERRECT]         = DecoratorSDK::PreferenceVariant(m_bRoundCornerRect);
00088         preferences[DecoratorSDK::PREF_ROUNDCORNERRADIUS]       = DecoratorSDK::PreferenceVariant(m_iRoundCornerRadius);
00089 
00090         VectorPart::InitializeEx(pProject, pPart, pFCO, parentWnd, preferences);
00091 
00092         DecoratorSDK::SimpleCoordCommand* leftMost                      = new DecoratorSDK::SimpleCoordCommand(DecoratorSDK::LeftMost);
00093         DecoratorSDK::SimpleCoordCommand* topMost                       = new DecoratorSDK::SimpleCoordCommand(DecoratorSDK::TopMost);
00094         DecoratorSDK::SimpleCoordCommand* rightMost                     = new DecoratorSDK::SimpleCoordCommand(DecoratorSDK::RightMost);
00095         DecoratorSDK::SimpleCoordCommand* bottomMost            = new DecoratorSDK::SimpleCoordCommand(DecoratorSDK::BottomMost);
00096         DecoratorSDK::AbsoluteCoordCommand* radiusCommand       = new DecoratorSDK::AbsoluteCoordCommand(m_bRoundCornerRect ? m_iRoundCornerRadius : 0);
00097         m_coordCommands.push_back(leftMost);
00098         m_coordCommands.push_back(topMost);
00099         m_coordCommands.push_back(rightMost);
00100         m_coordCommands.push_back(bottomMost);
00101         m_coordCommands.push_back(radiusCommand);
00102 
00103         AddCommand(DecoratorSDK::VectorCommand(DecoratorSDK::VectorCommand::BeginPath));
00104         std::vector<const DecoratorSDK::CoordCommand*> m_roundRectangleParams;
00105         m_roundRectangleParams.push_back(leftMost);
00106         m_roundRectangleParams.push_back(topMost);
00107         m_roundRectangleParams.push_back(rightMost);
00108         m_roundRectangleParams.push_back(bottomMost);
00109         m_roundRectangleParams.push_back(radiusCommand);
00110         AddCommand(DecoratorSDK::VectorCommand(m_roundRectangleParams, DecoratorSDK::VectorCommand::AddRoundRectangleToPath));
00111         AddCommand(DecoratorSDK::VectorCommand(DecoratorSDK::VectorCommand::EndPath));
00112         AddCommand(DecoratorSDK::VectorCommand(DecoratorSDK::VectorCommand::CopyShadowPath));
00113         AddCommand(DecoratorSDK::VectorCommand(DecoratorSDK::VectorCommand::CastShadowPath));
00114         DecoratorSDK::AbsoluteCoordCommand* colorCmd = new DecoratorSDK::AbsoluteCoordCommand(m_crBgColor);
00115         DecoratorSDK::AbsoluteCoordCommand* grayedCmd = new DecoratorSDK::AbsoluteCoordCommand(AN_DEFAULT_GRAYEDOUTCOLOR);
00116         m_coordCommands.push_back(colorCmd);
00117         m_coordCommands.push_back(grayedCmd);
00118         AddCommand(DecoratorSDK::VectorCommand(colorCmd, grayedCmd, DecoratorSDK::VectorCommand::FillPath));
00119 }
00120 
00121 void AnnotatorRectanglePart::ReadPreferences(void)
00122 {
00123         try {
00124                 CComBSTR bstr;
00125                 CComPtr<IMgaRegNode> bgcolNode;
00126                 CComBSTR bgcolName(AN_BGCOLOR_PREF);
00127                 COMTHROW(m_regRoot->get_SubNodeByName(bgcolName, &bgcolNode));
00128                 if (bgcolNode != NULL) {
00129                         COMTHROW(bgcolNode->get_Value(&bstr));
00130                 }
00131                 CString strVal(bstr);
00132                 unsigned int val;
00133                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00134                         unsigned int r = (val & 0xff0000) >> 16;
00135                         unsigned int g = (val & 0xff00) >> 8;
00136                         unsigned int b = val & 0xff;
00137                         m_crBgColor = RGB(r,g,b);
00138                 } else {
00139                         m_crBgColor = AN_DEFAULT_BGCOLOR;
00140                 }
00141         }
00142         catch (hresult_exception&) {
00143                 m_crBgColor = AN_DEFAULT_BGCOLOR;
00144         }
00145 
00146         try {
00147                 CComBSTR bstr;
00148                 CComPtr<IMgaRegNode> shadowcolNode;
00149                 CComBSTR shadowcolName(AN_SHADOWCOLOR_PREF);
00150                 COMTHROW(m_regRoot->get_SubNodeByName(shadowcolName, &shadowcolNode));
00151                 if (shadowcolNode != NULL) {
00152                         COMTHROW(shadowcolNode->get_Value(&bstr));
00153                 }
00154                 CString strVal(bstr);
00155                 unsigned int val;
00156                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00157                         unsigned int r = (val & 0xff0000) >> 16;
00158                         unsigned int g = (val & 0xff00) >> 8;
00159                         unsigned int b = val & 0xff;
00160                         m_crShadow = RGB(r,g,b);
00161                 } else {
00162                         m_crShadow = AN_DEFAULT_SHADOWCOLOR;
00163                 }
00164         }
00165         catch (hresult_exception&) {
00166                 m_crShadow = AN_DEFAULT_SHADOWCOLOR;
00167         }
00168 
00169         try {
00170                 CComBSTR bstr;
00171                 CComPtr<IMgaRegNode> gradientcolNode;
00172                 CComBSTR gradientcolName(AN_GRADIENTCOLOR_PREF);
00173                 COMTHROW(m_regRoot->get_SubNodeByName(gradientcolName, &gradientcolNode));
00174                 if (gradientcolNode != NULL) {
00175                         COMTHROW(gradientcolNode->get_Value(&bstr));
00176                 }
00177                 CString strVal(bstr);
00178                 unsigned int val;
00179                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00180                         unsigned int r = (val & 0xff0000) >> 16;
00181                         unsigned int g = (val & 0xff00) >> 8;
00182                         unsigned int b = val & 0xff;
00183                         m_crGradient = RGB(r,g,b);
00184                 } else {
00185                         m_crGradient = AN_DEFAULT_GRADIENTCOLOR;
00186                 }
00187         }
00188         catch (hresult_exception&) {
00189                 m_crGradient = AN_DEFAULT_GRADIENTCOLOR;
00190         }
00191 
00192         try {
00193                 m_bGradientFill = AN_DEFAULT_GRADIENTFILL;
00194                 CComBSTR bstr;
00195                 CComPtr<IMgaRegNode> lfNode;
00196                 CComBSTR lfName(AN_GRADIENTFILL_PREF);
00197                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00198                 if (lfNode != NULL) {
00199                         COMTHROW(lfNode->get_Value(&bstr));
00200                         if (bstr == "1")
00201                                 m_bGradientFill = true;
00202                         else
00203                                 m_bGradientFill = false;
00204                 }
00205         }
00206         catch (hresult_exception &) {
00207                 m_bGradientFill = AN_DEFAULT_GRADIENTFILL;
00208         }
00209 
00210         // 'GradientDirection'
00211         try {
00212                 m_iGradientDirection = AN_DEFAULT_GRADIENTDIRECTION;
00213                 CComBSTR bstr;
00214                 CComPtr<IMgaRegNode> lfNode;
00215                 CComBSTR lfName(AN_GRADIENTDIRECTION_PREF);
00216                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00217                 if (lfNode != NULL) {
00218                         COMTHROW(lfNode->get_Value(&bstr));
00219                         CString strVal(bstr);
00220                         if (_stscanf(strVal,_T("%ld"),&m_iGradientDirection) != 1) {
00221                                 m_iGradientDirection = AN_DEFAULT_GRADIENTDIRECTION;
00222                         }
00223                 }
00224         }
00225         catch (hresult_exception &) {
00226                 m_iGradientDirection = AN_DEFAULT_GRADIENTDIRECTION;
00227         }
00228 
00229         // 'CastShadow'
00230         try {
00231                 m_bCastShadow = AN_DEFAULT_CASTSHADOW;
00232                 CComBSTR bstr;
00233                 CComPtr<IMgaRegNode> lfNode;
00234                 CComBSTR lfName(AN_CASTSHADOW_PREF);
00235                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00236                 if (lfNode != NULL) {
00237                         COMTHROW(lfNode->get_Value(&bstr));
00238                         if (bstr == "1")
00239                                 m_bCastShadow = true;
00240                         else
00241                                 m_bCastShadow = false;
00242                 }
00243         }
00244         catch (hresult_exception &) {
00245                 m_bCastShadow = AN_DEFAULT_CASTSHADOW;
00246         }
00247 
00248         // 'ShadowDepth'
00249         try {
00250                 m_iShadowDepth = AN_DEFAULT_SHADOWDEPTH;
00251                 CComBSTR bstr;
00252                 CComPtr<IMgaRegNode> lfNode;
00253                 CComBSTR lfName(AN_SHADOWDEPTH_PREF);
00254                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00255                 if (lfNode != NULL) {
00256                         COMTHROW(lfNode->get_Value(&bstr));
00257                         CString strVal(bstr);
00258                         if (_stscanf(strVal,_T("%ld"),&m_iShadowDepth) != 1) {
00259                                 m_iShadowDepth = AN_DEFAULT_SHADOWDEPTH;
00260                         }
00261                 }
00262         }
00263         catch (hresult_exception &) {
00264                 m_iShadowDepth = AN_DEFAULT_SHADOWDEPTH;
00265         }
00266 
00267         // 'ShadowDirection'
00268         try {
00269                 m_iShadowDirection = AN_DEFAULT_SHADOWDIRECTION;
00270                 CComBSTR bstr;
00271                 CComPtr<IMgaRegNode> lfNode;
00272                 CComBSTR lfName(AN_SHADOWDIRECTION_PREF);
00273                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00274                 if (lfNode != NULL) {
00275                         COMTHROW(lfNode->get_Value(&bstr));
00276                         CString strVal(bstr);
00277                         if (_stscanf(strVal,_T("%ld"),&m_iShadowDirection) != 1) {
00278                                 m_iShadowDirection = AN_DEFAULT_SHADOWDIRECTION;
00279                         }
00280                 }
00281         }
00282         catch (hresult_exception &) {
00283                 m_iShadowDirection = AN_DEFAULT_SHADOWDIRECTION;
00284         }
00285 
00286         // 'RoundCornerRect'
00287         try {
00288                 m_bRoundCornerRect = AN_DEFAULT_ROUNDCORNERRECT;
00289                 CComBSTR bstr;
00290                 CComPtr<IMgaRegNode> lfNode;
00291                 CComBSTR lfName(AN_ROUNDCORNERRECT_PREF);
00292                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00293                 if (lfNode != NULL) {
00294                         COMTHROW(lfNode->get_Value(&bstr));
00295                         if (bstr == "1")
00296                                 m_bRoundCornerRect = true;
00297                         else
00298                                 m_bRoundCornerRect = false;
00299                 }
00300         }
00301         catch (hresult_exception &) {
00302                 m_bRoundCornerRect = AN_DEFAULT_ROUNDCORNERRECT;
00303         }
00304 
00305         // 'RoundCornerRadius'
00306         try {
00307                 m_iRoundCornerRadius = AN_DEFAULT_ROUNDCORNERRADIUS;
00308                 CComBSTR bstr;
00309                 CComPtr<IMgaRegNode> lfNode;
00310                 CComBSTR lfName(AN_ROUNDCORNERRADIUS_PREF);
00311                 COMTHROW(m_regRoot->get_SubNodeByName(lfName, &lfNode));
00312                 if (lfNode != NULL) {
00313                         COMTHROW(lfNode->get_Value(&bstr));
00314                         CString strVal(bstr);
00315                         if (_stscanf(strVal,_T("%ld"),&m_iRoundCornerRadius) != 1) {
00316                                 m_iRoundCornerRadius = AN_DEFAULT_ROUNDCORNERRADIUS;
00317                         }
00318                 }
00319         }
00320         catch (hresult_exception &) {
00321                 m_iRoundCornerRadius = AN_DEFAULT_ROUNDCORNERRADIUS;
00322         }
00323 }
00324 
00325 }; // namespace AnnotatorDecor