From f7d2c07c102d940727b0f053864c04ed32a76ff8 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 13 Oct 2012 09:49:24 +0000 Subject: Quotes: folders restructurization git-svn-id: http://svn.miranda-ng.org/main/trunk@1905 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Quotes/src/ExtraImages.cpp | 143 +++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 protocols/Quotes/src/ExtraImages.cpp (limited to 'protocols/Quotes/src/ExtraImages.cpp') diff --git a/protocols/Quotes/src/ExtraImages.cpp b/protocols/Quotes/src/ExtraImages.cpp new file mode 100644 index 0000000000..35a59a8c1d --- /dev/null +++ b/protocols/Quotes/src/ExtraImages.cpp @@ -0,0 +1,143 @@ +#include "StdAfx.h" +#include "ExtraImages.h" +#include "IconLib.h" +#include "EconomicRateInfo.h" +#include "ModuleInfo.h" +#include "QuotesProviders.h" +#include "IQuotesProvider.h" +#include "Log.h" +#include "DBUtils.h" + +namespace +{ + inline HANDLE extra_add_icon(const char* psz) + { + return reinterpret_cast( + CallService(MS_CLIST_EXTRA_ADD_ICON,reinterpret_cast(Quotes_LoadIconEx(psz)),0)); + } + + const HANDLE INVALID_IMAGE_HANDLE = reinterpret_cast(-1); +} + +CExtraImages::CExtraImages() + : m_hExtraIcons(ExtraIcon_Register(ICON_STR_QUOTE,QUOTES_PROTOCOL_NAME,Quotes_MakeIconName(ICON_STR_MAIN).c_str())), + m_bExtraImagesInit(false), + m_nSlot(DBGetContactSettingWord(NULL,QUOTES_PROTOCOL_NAME,DB_STR_QUOTE_EXTRA_IMAGE_SLOT,EXTRA_ICON_ADV1)) +{ + m_ahExtraImages[eiUp] = INVALID_IMAGE_HANDLE; + m_ahExtraImages[eiDown] = INVALID_IMAGE_HANDLE; + m_ahExtraImages[eiNotChanged] = INVALID_IMAGE_HANDLE; +} + +CExtraImages::~CExtraImages() +{ +} + +CExtraImages& CExtraImages::GetInstance() +{ + static CExtraImages s_ei; + return s_ei; +} + +void CExtraImages::RebuildExtraImages() +{ + if(NULL == m_hExtraIcons) + { + m_bExtraImagesInit = false; + CGuard cs(m_lmExtraImages); + m_ahExtraImages[eiUp] = extra_add_icon(ICON_STR_QUOTE_UP); + m_ahExtraImages[eiDown] = extra_add_icon(ICON_STR_QUOTE_DOWN); + m_ahExtraImages[eiNotChanged] = extra_add_icon(ICON_STR_QUOTE_NOT_CHANGED); + m_bExtraImagesInit = true; + } +} + + +bool CExtraImages::SetContactExtraImage(HANDLE hContact,EImageIndex nIndex)const +{ +// tstring s = Quotes_DBGetStringT(hContact,LIST_MODULE_NAME,CONTACT_LIST_NAME); +// tostringstream o; +// o << _T("SetContactExtraImage for ") << s << _T("\nExtra image list init: ") << m_bExtraImagesInit << _T("\n"); + + bool bResult = false; + if(m_hExtraIcons) + { +// o << "Using extra icon interface\n"; + std::string sIconName; + switch(nIndex) + { + case eiUp: + sIconName = Quotes_MakeIconName(ICON_STR_QUOTE_UP); + break; + case eiDown: + sIconName = Quotes_MakeIconName(ICON_STR_QUOTE_DOWN); + break; + case eiNotChanged: + sIconName = Quotes_MakeIconName(ICON_STR_QUOTE_NOT_CHANGED); + break; + } + bResult = (0 == ExtraIcon_SetIcon(m_hExtraIcons,hContact,sIconName.c_str())); + } + else if(m_bExtraImagesInit && ServiceExists(MS_CLIST_EXTRA_ADD_ICON)) + { +// o << "Using contact list interface index is "; + IconExtraColumn iec = {0}; + iec.cbSize = sizeof(iec); + iec.ColumnType = m_nSlot; + + { + CGuard cs(m_lmExtraImages); + switch(nIndex) + { + case eiUp: +// o << "up\n"; + iec.hImage = m_ahExtraImages[eiUp]; + break; + case eiDown: +// o << "down\n"; + iec.hImage = m_ahExtraImages[eiDown]; + break; + case eiNotChanged: +// o << "not changed\n"; + iec.hImage = m_ahExtraImages[eiNotChanged]; + break; + default: +// o << "invalid\n"; + iec.hImage = INVALID_IMAGE_HANDLE; + break; + } + } + + bResult = (0 == CallService(MS_CLIST_EXTRA_SET_ICON,reinterpret_cast(hContact),reinterpret_cast(&iec))); + } + +// o << "Result is " << bResult; +// LogIt(Info,o.str()); + return bResult; +} + +int QuotesEventFunc_onExtraImageListRebuild(WPARAM /*wp*/,LPARAM /*lp*/) +{ + if (ServiceExists(MS_CLIST_EXTRA_ADD_ICON)) + { + CExtraImages::GetInstance().RebuildExtraImages(); + } + + return 0; +} + +int QuotesEventFunc_onExtraImageApply(WPARAM wp,LPARAM lp) +{ + HANDLE hContact = reinterpret_cast(wp); + + const CModuleInfo::TQuotesProvidersPtr& pProviders = CModuleInfo::GetQuoteProvidersPtr(); + CQuotesProviders::TQuotesProviderPtr pProvider = pProviders->GetContactProviderPtr(hContact); + if(pProvider) + { + pProvider->SetContactExtraIcon(hContact); + } + + return 0; +} + + -- cgit v1.2.3