From 14bdc60ec9715ed7a0e74ade4072cf86f3fefb4a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 2 Mar 2016 11:06:38 +0000 Subject: - crash fix on smiley pack change; - massive code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@16389 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SmileyAdd/src/AniSmileyObject.cpp | 34 ++--- plugins/SmileyAdd/src/SmileyBase.cpp | 125 +++++++-------- plugins/SmileyAdd/src/SmileyBase.h | 8 +- plugins/SmileyAdd/src/anim.cpp | 38 ++--- plugins/SmileyAdd/src/anim.h | 3 - plugins/SmileyAdd/src/customsmiley.cpp | 4 +- plugins/SmileyAdd/src/download.cpp | 30 ++-- plugins/SmileyAdd/src/general.cpp | 53 +++---- plugins/SmileyAdd/src/imagecache.cpp | 7 +- plugins/SmileyAdd/src/main.cpp | 9 +- plugins/SmileyAdd/src/options.cpp | 227 ++++++++++++--------------- plugins/SmileyAdd/src/richcall.cpp | 43 +++--- plugins/SmileyAdd/src/services.cpp | 113 ++++++-------- plugins/SmileyAdd/src/smileyroutines.cpp | 11 +- plugins/SmileyAdd/src/smileys.cpp | 28 ++-- plugins/SmileyAdd/src/smltool.cpp | 246 ++++++++++++++---------------- plugins/SmileyAdd/src/stdafx.h | 44 +----- 17 files changed, 459 insertions(+), 564 deletions(-) (limited to 'plugins') diff --git a/plugins/SmileyAdd/src/AniSmileyObject.cpp b/plugins/SmileyAdd/src/AniSmileyObject.cpp index 31d954e573..90a04df8fa 100644 --- a/plugins/SmileyAdd/src/AniSmileyObject.cpp +++ b/plugins/SmileyAdd/src/AniSmileyObject.cpp @@ -33,12 +33,12 @@ private: SmileyType *m_sml; ImageBase *m_img; - long m_counter; unsigned m_richFlags; long m_lastObjNum; AnimType m_animtype; bool m_allowAni; + bool m_bRegistered; public: CAniSmileyObject(SmileyType *sml, COLORREF clr, bool ishpp) @@ -48,7 +48,12 @@ public: m_sml = sml; } - ~CAniSmileyObject() + virtual ~CAniSmileyObject() + { + UnloadSmiley(); + } + + virtual void OnClose(void) { UnloadSmiley(); } @@ -59,19 +64,17 @@ public: m_img = m_sml->CreateCachedImage(); if (m_img && m_img->IsAnimated() && opt.AnimateDlg) { - m_img->SelectFrame(0); - long frtm = m_img->GetFrameDelay(); - m_counter = frtm / 10 + ((frtm % 10) >= 5); - m_sml->AddObject(this); + m_bRegistered = true; } } void UnloadSmiley() { - m_sml->RemoveObject(this); + if (m_bRegistered) + m_sml->RemoveObject(this); - if (m_img) { + if (m_img != NULL) { m_img->Release(); m_img = NULL; } @@ -287,9 +290,7 @@ public: return ISmileyBase::Close(dwSaveOption); } - STDMETHOD(Draw)(DWORD dwAspect, LONG, void*, DVTARGETDEVICE*, HDC, - HDC hdc, LPCRECTL pRectBounds, LPCRECTL /* pRectWBounds */, - BOOL(__stdcall *)(ULONG_PTR), ULONG_PTR) + STDMETHOD(Draw)(DWORD dwAspect, LONG, void*, DVTARGETDEVICE*, HDC, HDC hdc, LPCRECTL pRectBounds, LPCRECTL, BOOL(__stdcall *)(ULONG_PTR), ULONG_PTR) { if (dwAspect != DVASPECT_CONTENT) return DV_E_DVASPECT; if (pRectBounds == NULL) return E_INVALIDARG; @@ -332,8 +333,7 @@ public: m_orect = *(LPRECT)pRectBounds; default: - m_img->DrawInternal(hdc, pRectBounds->left, pRectBounds->top, - m_sizeExtent.cx - 1, m_sizeExtent.cy - 1); + m_img->DrawInternal(hdc, pRectBounds->left, pRectBounds->top, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1); break; } @@ -351,10 +351,10 @@ public: } }; -ISmileyBase* CreateAniSmileyObject(SmileyType* sml, COLORREF clr, bool ishpp) +ISmileyBase* CreateAniSmileyObject(SmileyType *sml, COLORREF clr, bool ishpp) { - if (!sml->IsValid()) return NULL; + if (!sml->IsValid()) + return NULL; - CAniSmileyObject *obj = new CAniSmileyObject(sml, clr, ishpp); - return obj; + return new CAniSmileyObject(sml, clr, ishpp); } diff --git a/plugins/SmileyAdd/src/SmileyBase.cpp b/plugins/SmileyAdd/src/SmileyBase.cpp index 69af533942..f5d545bfb6 100644 --- a/plugins/SmileyAdd/src/SmileyBase.cpp +++ b/plugins/SmileyAdd/src/SmileyBase.cpp @@ -25,23 +25,18 @@ static void HiMetricToPixel(const SIZEL * lpSizeInHiMetric, LPSIZEL lpSizeInPix) const int nPixelsPerInchY = GetDeviceCaps(hDCScreen, LOGPIXELSY); ReleaseDC(NULL, hDCScreen); - lpSizeInPix->cx = (lpSizeInHiMetric->cx * nPixelsPerInchX + (2540/2)) / 2540; - lpSizeInPix->cy = (lpSizeInHiMetric->cy * nPixelsPerInchY + (2540/2)) / 2540; + lpSizeInPix->cx = (lpSizeInHiMetric->cx * nPixelsPerInchX + (2540 / 2)) / 2540; + lpSizeInPix->cy = (lpSizeInHiMetric->cy * nPixelsPerInchY + (2540 / 2)) / 2540; } -static int CompareISmileyBase(const ISmileyBase* p1, const ISmileyBase* p2) -{ - return (int)((char*)p2 - (char*)p1); -} - -static LIST regSmileys(10, CompareISmileyBase); +static LIST regSmileys(10, PtrKeySortT); // {105C56DF-6455-4705-A501-51F1CCFCF688} -const GUID IID_ISmileyAddSmiley = +const GUID IID_ISmileyAddSmiley = { 0x105c56df, 0x6455, 0x4705, { 0xa5, 0x1, 0x51, 0xf1, 0xcc, 0xfc, 0xf6, 0x88 } }; // {58B32D03-1BD2-4840-992E-9AE799FD4ADE} -const GUID IID_ITooltipData = +const GUID IID_ITooltipData = { 0x58b32d03, 0x1bd2, 0x4840, { 0x99, 0x2e, 0x9a, 0xe7, 0x99, 0xfd, 0x4a, 0xde } }; ISmileyBase::ISmileyBase(void) @@ -69,13 +64,12 @@ ISmileyBase::~ISmileyBase(void) Close(OLECLOSE_NOSAVE); - if (m_spClientSite) - { + if (m_spClientSite) { m_spClientSite->Release(); m_spClientSite = NULL; } - if (m_spAdviseHolder) - { + + if (m_spAdviseHolder) { m_spAdviseHolder->Release(); m_spAdviseHolder = NULL; } @@ -83,14 +77,14 @@ ISmileyBase::~ISmileyBase(void) void ISmileyBase::OnClose(void) { - if (m_spAdviseHolder) m_spAdviseHolder->SendOnClose(); + if (m_spAdviseHolder) + m_spAdviseHolder->SendOnClose(); } -void ISmileyBase::SendOnViewChange(void) +void ISmileyBase::SendOnViewChange(void) { if (m_spAdviseSink) m_spAdviseSink->OnViewChange(DVASPECT_CONTENT, -1); - if (m_advf & ADVF_ONLYONCE) - { + if (m_advf & ADVF_ONLYONCE) { m_spAdviseSink->Release(); m_spAdviseSink = NULL; m_advf = 0; @@ -100,8 +94,7 @@ void ISmileyBase::SendOnViewChange(void) bool ISmileyBase::QueryHitPointSpecial(int x, int y, HWND hwnd, TCHAR** smltxt) { bool result = m_visible && m_hwnd == hwnd; - if (result) - { + if (result) { result = x >= m_orect.left && x <= m_orect.right && y >= m_orect.top && y <= m_orect.bottom; } @@ -118,28 +111,23 @@ void ISmileyBase::SetHint(TCHAR* smltxt) void ISmileyBase::SetPosition(HWND hwnd, LPCRECT lpRect) { m_hwnd = hwnd; - if (lpRect == NULL || (lpRect->top == -1 && lpRect->bottom == -1)) - { + if (lpRect == NULL || (lpRect->top == -1 && lpRect->bottom == -1)) { m_visible = false; - } - else - { + } + else { m_visible = true; m_dirAniAllow = true; m_orect.left = lpRect->left; m_orect.right = lpRect->left + m_sizeExtent.cx; - if (lpRect->top == -1) - { + if (lpRect->top == -1) { m_orect.top = lpRect->bottom - m_sizeExtent.cy; m_orect.bottom = lpRect->bottom; } - else if (lpRect->bottom == -1) - { + else if (lpRect->bottom == -1) { m_orect.top = lpRect->top; m_orect.bottom = lpRect->top + m_sizeExtent.cy; } - else - { + else { m_orect.top = lpRect->bottom - m_sizeExtent.cy; m_orect.bottom = lpRect->bottom; } @@ -150,13 +138,15 @@ void ISmileyBase::SetPosition(HWND hwnd, LPCRECT lpRect) // // IUnknown members // -ULONG ISmileyBase::AddRef(void) -{ return InterlockedIncrement(&m_lRefCount); } +ULONG ISmileyBase::AddRef(void) +{ + return InterlockedIncrement(&m_lRefCount); +} ULONG ISmileyBase::Release(void) { LONG count = InterlockedDecrement(&m_lRefCount); - if (count == 0) + if (count == 0) delete this; return count; } @@ -174,12 +164,11 @@ HRESULT ISmileyBase::QueryInterface(REFIID iid, void ** ppvObject) *ppvObject = static_cast(this); else if (iid == IID_IOleObject) *ppvObject = static_cast(this); - else if (iid == IID_IUnknown) + else if (iid == IID_IUnknown) *ppvObject = this; else if (iid == IID_IViewObject2) *ppvObject = static_cast(this); - else - { + else { *ppvObject = NULL; return E_NOINTERFACE; } @@ -207,29 +196,41 @@ HRESULT ISmileyBase::GetClientSite(IOleClientSite **ppClientSite) } HRESULT ISmileyBase::SetHostNames(LPCOLESTR /* szContainerApp */, LPCOLESTR /* szContainerObj */) -{ return S_OK; } +{ + return S_OK; +} HRESULT ISmileyBase::Close(DWORD /* dwSaveOption */) { regSmileys.remove(this); - if (m_spAdviseSink) m_spAdviseSink->Release(); - m_spAdviseSink = NULL; + if (m_spAdviseSink) { + m_spAdviseSink->Release(); + m_spAdviseSink = NULL; + } return S_OK; } HRESULT ISmileyBase::SetMoniker(DWORD /* dwWhichMoniker */, IMoniker* /* pmk */) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} HRESULT ISmileyBase::GetMoniker(DWORD /* dwAssign */, DWORD /* dwWhichMoniker */, IMoniker** /* ppmk */) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} HRESULT ISmileyBase::InitFromData(IDataObject* /* pDataObject */, BOOL /* fCreation */, DWORD /* dwReserved */) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} HRESULT ISmileyBase::GetClipboardData(DWORD /* dwReserved */, IDataObject** /* ppDataObject */) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} HRESULT ISmileyBase::DoVerb(LONG /* iVerb */, LPMSG /* pMsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */, HWND /* hwndParent */, LPCRECT /* lprcPosRect */) @@ -249,10 +250,12 @@ HRESULT ISmileyBase::GetUserClassID(CLSID *pClsid) } HRESULT ISmileyBase::GetUserType(DWORD /*dwFormOfType*/, LPOLESTR* /*pszUserType*/) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} HRESULT ISmileyBase::SetExtent(DWORD dwDrawAspect, SIZEL* psizel) -{ +{ if (dwDrawAspect != DVASPECT_CONTENT) return E_FAIL; if (psizel == NULL) return E_POINTER; @@ -296,26 +299,26 @@ HRESULT ISmileyBase::EnumAdvise(IEnumSTATDATA **ppEnumAdvise) HRESULT ISmileyBase::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus) { if (pdwStatus == NULL) return E_POINTER; - if (dwAspect == DVASPECT_CONTENT) - { - *pdwStatus = OLEMISC_STATIC | OLEMISC_INVISIBLEATRUNTIME | - OLEMISC_CANTLINKINSIDE | OLEMISC_NOUIACTIVATE; + if (dwAspect == DVASPECT_CONTENT) { + *pdwStatus = OLEMISC_STATIC | OLEMISC_INVISIBLEATRUNTIME | + OLEMISC_CANTLINKINSIDE | OLEMISC_NOUIACTIVATE; return S_OK; } - else - { + else { *pdwStatus = 0; return E_FAIL; } } HRESULT ISmileyBase::SetColorScheme(LOGPALETTE* /* pLogpal */) -{ return E_NOTIMPL; } +{ + return E_NOTIMPL; +} // // IViewObject members // -HRESULT ISmileyBase::SetAdvise(DWORD aspect, DWORD advf, IAdviseSink* pAdvSink) +HRESULT ISmileyBase::SetAdvise(DWORD aspect, DWORD advf, IAdviseSink* pAdvSink) { if (aspect != DVASPECT_CONTENT) return DV_E_DVASPECT; m_advf = advf; @@ -324,22 +327,22 @@ HRESULT ISmileyBase::SetAdvise(DWORD aspect, DWORD advf, IAdviseSink* pAdvSink) if (advf & ADVF_PRIMEFIRST) SendOnViewChange(); return S_OK; } -HRESULT ISmileyBase::GetAdvise(DWORD* /*pAspects*/, DWORD* /*pAdvf*/, IAdviseSink** ppAdvSink) +HRESULT ISmileyBase::GetAdvise(DWORD* /*pAspects*/, DWORD* /*pAdvf*/, IAdviseSink** ppAdvSink) { if (!ppAdvSink) return E_POINTER; *ppAdvSink = m_spAdviseSink; if (m_spAdviseSink) m_spAdviseSink->AddRef(); return S_OK; } + HRESULT ISmileyBase::Freeze(DWORD, long, void*, DWORD*) { return E_NOTIMPL; } HRESULT ISmileyBase::Unfreeze(DWORD) { return E_NOTIMPL; } -HRESULT ISmileyBase::GetColorSet(DWORD, long, void*, DVTARGETDEVICE*, HDC, - LOGPALETTE**) { return E_NOTIMPL; } +HRESULT ISmileyBase::GetColorSet(DWORD, long, void*, DVTARGETDEVICE*, HDC, LOGPALETTE**) { return E_NOTIMPL; } // // IViewObject2 members // -HRESULT ISmileyBase::GetExtent(DWORD aspect, long, DVTARGETDEVICE*, SIZEL* pSize) +HRESULT ISmileyBase::GetExtent(DWORD aspect, long, DVTARGETDEVICE*, SIZEL* pSize) { if (pSize == NULL) return E_POINTER; if (aspect != DVASPECT_CONTENT) return DV_E_DVASPECT; @@ -359,14 +362,14 @@ HRESULT ISmileyBase::SetTooltip(BSTR /* bstrHint */) HRESULT ISmileyBase::GetTooltip(BSTR *bstrHint) { if (bstrHint == NULL) return E_POINTER; - *bstrHint = SysAllocString(T2W_SM(m_smltxt)); + *bstrHint = SysAllocString(m_smltxt); return S_OK; } void CloseSmileys(void) { - for (int i=regSmileys.getCount()-1; i >= 0; i--) { + for (int i = regSmileys.getCount() - 1; i >= 0; i--) { regSmileys[i]->OnClose(); regSmileys[i]->Close(OLECLOSE_NOSAVE); } @@ -374,7 +377,7 @@ void CloseSmileys(void) int CheckForTip(int x, int y, HWND hwnd, TCHAR** smltxt) { - for (int i=0; i < regSmileys.getCount(); i++) + for (int i = 0; i < regSmileys.getCount(); i++) if (regSmileys[i]->QueryHitPointSpecial(x, y, hwnd, smltxt)) return i; diff --git a/plugins/SmileyAdd/src/SmileyBase.h b/plugins/SmileyAdd/src/SmileyBase.h index 06621a0310..d208360c3a 100644 --- a/plugins/SmileyAdd/src/SmileyBase.h +++ b/plugins/SmileyAdd/src/SmileyBase.h @@ -30,8 +30,7 @@ public: EXTERN_C const IID IID_ISmileyAddSmiley; -class ISmileyBase : - public IOleObject, public IViewObject2, public ITooltipData +class ISmileyBase : public IOleObject, public IViewObject2, public ITooltipData { protected: IOleAdviseHolder* m_spAdviseHolder; @@ -54,7 +53,7 @@ public: ISmileyBase(void); virtual ~ISmileyBase(void); - void OnClose(void); + virtual void OnClose(void); void SendOnViewChange(void); bool QueryHitPointSpecial(int x, int y, HWND hwnd, TCHAR** smltxt); @@ -118,6 +117,3 @@ public: STDMETHOD(GetTooltip)(BSTR *bstrHint); }; -int CheckForTip(int x, int y, HWND hwnd, TCHAR** smltxt); -void CloseSmileys(void); - diff --git a/plugins/SmileyAdd/src/anim.cpp b/plugins/SmileyAdd/src/anim.cpp index 9ad5f9b7eb..fdaedf9b9a 100644 --- a/plugins/SmileyAdd/src/anim.cpp +++ b/plugins/SmileyAdd/src/anim.cpp @@ -28,14 +28,12 @@ Animate::Animate(SmileyType *sml, RECT& rect, HDC hdcMem, HBRUSH hbr, bool clip) m_cliprect = rect; } - Animate::~Animate() { if (m_img) m_img->Release(); } - void Animate::StartAnimation(void) { m_img = m_sml->CreateCachedImage(); @@ -62,10 +60,9 @@ void Animate::ProcessTimerTick(HWND hwnd) } } - void Animate::DrawFrame(HDC hdc) { - long width = m_cliprect.right - m_cliprect.left; + long width = m_cliprect.right - m_cliprect.left; long height = m_cliprect.bottom - m_cliprect.top; RECT frc = { 0, 0, width, height }; @@ -79,9 +76,8 @@ void Animate::DrawFrame(HDC hdc) DrawFocusRect(hdc, &m_cliprect); } - -void Animate::Draw(HDC hdc) -{ +void Animate::Draw(HDC hdc) +{ if (m_running) { m_img->Draw(hdc, m_cliprect, m_clip); @@ -90,15 +86,14 @@ void Animate::Draw(HDC hdc) } } - -void Animate::SetOffset(int off, int wsize) -{ +void Animate::SetOffset(int off, int wsize) +{ const int dy = m_offset - off; m_cliprect.top += dy; m_cliprect.bottom += dy; - m_offset = off; + m_offset = off; m_running = m_cliprect.top >= 0 && m_cliprect.top < wsize; if (m_running) { @@ -114,15 +109,13 @@ void Animate::SetOffset(int off, int wsize) } } - void Animate::SetSel(int x, int y) { m_sel = x >= m_cliprect.left && x < m_cliprect.right && y >= m_cliprect.top && y < m_cliprect.bottom; } - AnimatedPack::AnimatedPack(HWND hwnd, int wsize, SIZE& sel, COLORREF bkg) - : m_AniList(40), m_hwnd(hwnd), m_wsize(wsize) + : m_AniList(40), m_hwnd(hwnd), m_wsize(wsize) { HDC hdc = GetDC(hwnd); @@ -134,44 +127,39 @@ AnimatedPack::AnimatedPack(HWND hwnd, int wsize, SIZE& sel, COLORREF bkg) ReleaseDC(hwnd, hdc); } - AnimatedPack::~AnimatedPack() { DeleteObject(m_hbr); - SelectObject(m_hdcMem, m_hOld); - DeleteObject(m_hBmp); + SelectObject(m_hdcMem, m_hOld); + DeleteObject(m_hBmp); DeleteDC(m_hdcMem); } - void AnimatedPack::Add(SmileyType *sml, RECT rect, bool clip) { m_AniList.insert(new Animate(sml, rect, m_hdcMem, m_hbr, clip)); } - void AnimatedPack::Draw(HDC hdc) { - for (int i=0; i < m_AniList.getCount(); i++) + for (int i = 0; i < m_AniList.getCount(); i++) m_AniList[i].Draw(hdc); } - void AnimatedPack::SetOffset(int off) { - for (int i=0; i < m_AniList.getCount(); i++) + for (int i = 0; i < m_AniList.getCount(); i++) m_AniList[i].SetOffset(off, m_wsize); } - void AnimatedPack::SetSel(RECT& rect) { - for (int i=0; i < m_AniList.getCount(); i++) + for (int i = 0; i < m_AniList.getCount(); i++) m_AniList[i].SetSel(rect.left, rect.top); } void AnimatedPack::ProcessTimerTick(HWND hwnd) { - for (int i=0; i < m_AniList.getCount(); i++) + for (int i = 0; i < m_AniList.getCount(); i++) m_AniList[i].ProcessTimerTick(hwnd); } diff --git a/plugins/SmileyAdd/src/anim.h b/plugins/SmileyAdd/src/anim.h index 8f31dca36e..eb1b0c0fe7 100644 --- a/plugins/SmileyAdd/src/anim.h +++ b/plugins/SmileyAdd/src/anim.h @@ -43,7 +43,6 @@ private: public: Animate(SmileyType *sml, RECT &rect, HDC hdcMem, HBRUSH hbr, bool clip); - Animate(const Animate& an); ~Animate(); void Draw(HDC hdc); @@ -68,8 +67,6 @@ private: HDC m_hdcMem; HBITMAP m_hOld; - static unsigned CALLBACK AnimateThreadFunc ( void* arg ); - public: AnimatedPack(HWND hwnd, int wsize, SIZE& sel, COLORREF bkg); ~AnimatedPack(); diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp index 3e1413509e..e46cb4a4cd 100644 --- a/plugins/SmileyAdd/src/customsmiley.cpp +++ b/plugins/SmileyAdd/src/customsmiley.cpp @@ -62,7 +62,7 @@ SmileyPackCType* SmileyPackCListType::GetSmileyPack(MCONTACT id) SmileyCType::SmileyCType(const CMString& fullpath, const TCHAR* filepath) { LoadFromResource(fullpath, 0); - CreateTriggerText(T2A_SM(filepath)); + CreateTriggerText(_T2A(filepath)); } bool SmileyCType::CreateTriggerText(char* text) @@ -123,7 +123,7 @@ bool SmileyPackCType::LoadSmileyDir(TCHAR* dir) return false; } -bool SmileyPackCType::LoadSmiley(TCHAR* path) +bool SmileyPackCType::LoadSmiley(TCHAR *path) { CMString dirs = path; int slash = dirs.ReverseFind('\\'); diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 47ec9317b9..7e511a952d 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -28,7 +28,9 @@ struct QueueElem bool needext; QueueElem(CMString& purl, CMString& pfname, bool ne) - : url(purl), fname(pfname), needext(ne) {} + : url(purl), fname(pfname), needext(ne) + { + } }; static HANDLE g_hDlMutex; @@ -40,27 +42,27 @@ static bool threadRunning; bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl) { int result = 0xBADBAD; - char *szRedirUrl = NULL; - NETLIBHTTPREQUEST nlhr = {0}; + char *szRedirUrl = NULL; + NETLIBHTTPREQUEST nlhr = { 0 }; // initialize the netlib request nlhr.cbSize = sizeof(nlhr); nlhr.requestType = REQUEST_GET; - nlhr.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_PERSISTENT | NLHRF_REDIRECT; + nlhr.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_PERSISTENT | NLHRF_REDIRECT; nlhr.szUrl = (char*)szUrl; nlhr.nlc = hHttpDwnl; // change the header so the plugin is pretended to be IE 6 + WinXP nlhr.headersCount = 2; - nlhr.headers=(NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); - nlhr.headers[0].szName = "User-Agent"; + nlhr.headers = (NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); + nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = NETLIB_USER_AGENT; - nlhr.headers[1].szName = "Connection"; + nlhr.headers[1].szName = "Connection"; nlhr.headers[1].szValue = "close"; while (result == 0xBADBAD) { // download the page - NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr); + NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr); if (nlhrReply) { hHttpDwnl = nlhrReply->nlc; // if the recieved code is 200 OK @@ -85,7 +87,7 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl) else if (nlhrReply->resultCode == 302 || nlhrReply->resultCode == 301 || nlhrReply->resultCode == 307) { // page moved // get the url for the new location and save it to szInfo // look for the reply header "Location" - for (int i=0; iheadersCount; i++) { + for (int i = 0; i < nlhrReply->headersCount; i++) { if (!mir_strcmp(nlhrReply->headers[i].szName, "Location")) { size_t rlen = 0; if (nlhrReply->headers[i].szValue[0] == '/') { @@ -96,10 +98,10 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl) rlen = szPath != NULL ? szPath - szUrl : mir_strlen(szUrl); } - szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + mir_strlen(nlhrReply->headers[i].szValue)*3 + 1); + szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + mir_strlen(nlhrReply->headers[i].szValue) * 3 + 1); strncpy(szRedirUrl, szUrl, rlen); - mir_strcpy(szRedirUrl+rlen, nlhrReply->headers[i].szValue); + mir_strcpy(szRedirUrl + rlen, nlhrReply->headers[i].szValue); nlhr.szUrl = szRedirUrl; break; @@ -113,7 +115,7 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl) result = 1; } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)nlhrReply); + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply); } mir_free(szRedirUrl); @@ -129,7 +131,7 @@ void __cdecl SmileyDownloadThread(void*) while (!Miranda_Terminated() && dlQueue.getCount()) { ReleaseMutex(g_hDlMutex); if (_taccess(dlQueue[0].fname.c_str(), 0) != 0) { - InternetDownloadFile(T2A_SM(dlQueue[0].url.c_str()), T2A_SM(dlQueue[0].fname.c_str()), hHttpDwnl); + InternetDownloadFile(_T2A(dlQueue[0].url.c_str()), _T2A(dlQueue[0].fname.c_str()), hHttpDwnl); WaitForSingleObject(g_hDlMutex, 3000); CMString fname(dlQueue[0].fname); @@ -210,7 +212,7 @@ void GetSmileyCacheFolder(void) FoldersGetCustomPathT(hFolder, cachepath, MAX_PATH, _T("")); HookEvent(ME_FOLDERS_PATH_CHANGED, FolderChanged); } - else mir_tstrncpy(cachepath, VARST( _T("%miranda_userdata%\\SmileyCache")), MAX_PATH); + else mir_tstrncpy(cachepath, VARST(_T("%miranda_userdata%\\SmileyCache")), MAX_PATH); } void DownloadInit(void) diff --git a/plugins/SmileyAdd/src/general.cpp b/plugins/SmileyAdd/src/general.cpp index 7b0dff73fd..2900f276b6 100644 --- a/plugins/SmileyAdd/src/general.cpp +++ b/plugins/SmileyAdd/src/general.cpp @@ -30,7 +30,7 @@ int CalculateTextHeight(HDC hdc, CHARFORMAT2* chf) HDC hcdc = CreateCompatibleDC(hdc); int logPixelsY = GetDeviceCaps(hdc, LOGPIXELSY); - HFONT hFont = CreateFont(-(chf->yHeight * logPixelsY / 1440), 0, 0, 0, + HFONT hFont = CreateFont(-(chf->yHeight * logPixelsY / 1440), 0, 0, 0, chf->wWeight, chf->dwEffects & CFE_ITALIC ? 1 : 0, 0, 0, chf->bCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, @@ -49,7 +49,7 @@ int CalculateTextHeight(HDC hdc, CHARFORMAT2* chf) HICON GetDefaultIcon(bool copy) { HICON resIco = IcoLib_GetIcon("SmileyAdd_ButtonSmiley"); - if (resIco == NULL) + if (resIco == NULL) resIco = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_SMILINGICON), IMAGE_ICON, 0, 0, copy ? 0 : LR_SHARED); else if (copy) { resIco = (HICON)CopyImage(resIco, IMAGE_ICON, 0, 0, 0); @@ -69,13 +69,13 @@ const TCHAR* GetImageExt(CMString &fname) int bytes = _read(fileId, buf, sizeof(buf)); if (bytes > 4) { - if ( *(unsigned short*)buf == 0xd8ff ) + if (*(unsigned short*)buf == 0xd8ff) ext = _T("jpg"); - else if ( *(unsigned short*)buf == 0x4d42 ) + else if (*(unsigned short*)buf == 0x4d42) ext = _T("bmp"); - else if ( *(unsigned*)buf == 0x474e5089 ) + else if (*(unsigned*)buf == 0x474e5089) ext = _T("png"); - else if ( *(unsigned*)buf == 0x38464947 ) + else if (*(unsigned*)buf == 0x38464947) ext = _T("gif"); } _close(fileId); @@ -83,7 +83,7 @@ const TCHAR* GetImageExt(CMString &fname) return ext; } -HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle) +HICON ImageList_GetIconFixed(HIMAGELIST himl, INT i, UINT fStyle) { ICONINFO ii; HICON hIcon; @@ -100,15 +100,15 @@ HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle) ii.yHotspot = 0; /* draw mask*/ - ii.hbmMask = CreateBitmap (cx, cy, 1, 1, NULL); - hOldDstBitmap = (HBITMAP)SelectObject (hdcDst, ii.hbmMask); + ii.hbmMask = CreateBitmap(cx, cy, 1, 1, NULL); + hOldDstBitmap = (HBITMAP)SelectObject(hdcDst, ii.hbmMask); PatBlt(hdcDst, 0, 0, cx, cy, WHITENESS); ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_MASK); /* draw image*/ - ii.hbmColor = CreateBitmap (cx, cy, 1, 32, NULL); - SelectObject (hdcDst, ii.hbmColor); - PatBlt (hdcDst, 0, 0, cx, cy, BLACKNESS); + ii.hbmColor = CreateBitmap(cx, cy, 1, 32, NULL); + SelectObject(hdcDst, ii.hbmColor); + PatBlt(hdcDst, 0, 0, cx, cy, BLACKNESS); ImageList_Draw(himl, i, hdcDst, 0, 0, fStyle | ILD_TRANSPARENT); /* @@ -117,11 +117,11 @@ HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle) */ SelectObject(hdcDst, hOldDstBitmap); - hIcon = CreateIconIndirect (&ii); + hIcon = CreateIconIndirect(&ii); - DeleteObject (ii.hbmMask); - DeleteObject (ii.hbmColor); - DeleteDC (hdcDst); + DeleteObject(ii.hbmMask); + DeleteObject(ii.hbmColor); + DeleteDC(hdcDst); return hIcon; } @@ -133,7 +133,7 @@ void pathToRelative(const CMString& pSrc, CMString& pOut) pOut = szOutPath; } -void pathToAbsolute(const CMString& pSrc, CMString& pOut) +void pathToAbsolute(const CMString& pSrc, CMString& pOut) { TCHAR szOutPath[MAX_PATH]; @@ -155,9 +155,9 @@ void pathToAbsolute(const CMString& pSrc, CMString& pOut) static int __fastcall SingleHexToDecimal(char c) { - if (c >= '0' && c <= '9') return c-'0'; - if (c >= 'a' && c <= 'f') return c-'a'+10; - if (c >= 'A' && c <= 'F') return c-'A'+10; + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; return -1; } @@ -165,7 +165,7 @@ void UrlDecode(char* str) { char* s = str, *d = str; - while(*s) { + while (*s) { if (*s == '%') { int digit1 = SingleHexToDecimal(s[1]); if (digit1 != -1) { @@ -174,8 +174,8 @@ void UrlDecode(char* str) s += 3; *d++ = (char)((digit1 << 4) | digit2); continue; - } - } + } + } } *d++ = *s++; } @@ -195,7 +195,8 @@ bool InitGdiPlus(void) if (g_gdiplusToken == 0 && !gdiPlusFail) Gdiplus::GdiplusStartup(&g_gdiplusToken, &gdiplusStartupInput, NULL); } - __except(EXCEPTION_EXECUTE_HANDLER) { + __except (EXCEPTION_EXECUTE_HANDLER) + { gdiPlusFail = true; ReportError(errmsg); } @@ -215,7 +216,7 @@ MCONTACT DecodeMetaContact(MCONTACT hContact) { if (hContact == NULL) return NULL; - + MCONTACT hReal = db_mc_getMostOnline(hContact); if (hReal == NULL || (INT_PTR)hReal == CALLSERVICE_NOTFOUND) hReal = hContact; @@ -232,7 +233,7 @@ void ReportError(const TCHAR *errmsg) { static const TCHAR title[] = _T("Miranda SmileyAdd"); - POPUPDATAT pd = {0}; + POPUPDATAT pd = { 0 }; mir_tstrcpy(pd.lpwzContactName, title); mir_tstrcpy(pd.lpwzText, errmsg); pd.iSeconds = -1; diff --git a/plugins/SmileyAdd/src/imagecache.cpp b/plugins/SmileyAdd/src/imagecache.cpp index c90d355e5f..fa6220934b 100644 --- a/plugins/SmileyAdd/src/imagecache.cpp +++ b/plugins/SmileyAdd/src/imagecache.cpp @@ -18,8 +18,6 @@ along with this program. If not, see . #include "stdafx.h" -static FI_INTERFACE *fei; - static HANDLE g_hMutexIm; static OBJLIST g_imagecache(25, ImageType::CompareImg); @@ -294,7 +292,7 @@ ImageType::ImageType(const unsigned id, const CMString& file, IStream* pStream) if (pStream) m_bmp = new Gdiplus::Bitmap(pStream); else - m_bmp = new Gdiplus::Bitmap(T2W_SM(file.c_str())); + m_bmp = new Gdiplus::Bitmap(file.c_str()); if (m_bmp->GetLastStatus() != Gdiplus::Ok) { delete m_bmp; @@ -335,7 +333,7 @@ ImageType::ImageType(const unsigned id, const CMString& file, const int index, c break; case icoFile: - m_bmp = new Gdiplus::Bitmap(T2W_SM(file.c_str())); + m_bmp = new Gdiplus::Bitmap(file.c_str()); break; default: @@ -513,7 +511,6 @@ void ImageFType::GetSize(SIZE& size) void InitImageCache(void) { g_hMutexIm = CreateMutex(NULL, FALSE, NULL); - CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei); } void DestroyImageCache(void) diff --git a/plugins/SmileyAdd/src/main.cpp b/plugins/SmileyAdd/src/main.cpp index 1c59ae7597..b5afa0b036 100644 --- a/plugins/SmileyAdd/src/main.cpp +++ b/plugins/SmileyAdd/src/main.cpp @@ -19,11 +19,13 @@ along with this program. If not, see . #include "stdafx.h" -//globals +// globals HINSTANCE g_hInst; HANDLE hEvent1; HGENMENU hContactMenuItem; +FI_INTERFACE *fei; + int hLangpack; static const PLUGININFOEX pluginInfoEx = @@ -87,10 +89,11 @@ extern "C" __declspec(dllexport) int Load(void) if (ServiceExists(MS_SMILEYADD_REPLACESMILEYS)) { ReportError(TranslateT("Only one instance of SmileyAdd could be executed.\nRemove duplicate instances from 'Plugins' directory")); - return 1; } + CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei); + InitImageCache(); Icon_Register(g_hInst, "SmileyAdd", &icon, 1); @@ -144,7 +147,7 @@ extern "C" __declspec(dllexport) int Unload(void) extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/) { - switch(fdwReason) { + switch (fdwReason) { case DLL_PROCESS_ATTACH: g_hInst = hinstDLL; DisableThreadLibraryCalls(hinstDLL); diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp index 5a8b883504..06e67ffe31 100644 --- a/plugins/SmileyAdd/src/options.cpp +++ b/plugins/SmileyAdd/src/options.cpp @@ -50,52 +50,12 @@ public: BOOL DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam); }; -static INT_PTR CALLBACK DlgProcSmileysOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -//Init and de-init functions, called from main -int SmileysOptionsInitialize(WPARAM addInfo, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.position = 910000000; - odp.hInstance = g_hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SMILEYS); - odp.pszTitle = LPGEN("Smileys"); - odp.pszGroup = LPGEN("Customize"); - odp.pfnDlgProc = DlgProcSmileysOptions; - odp.flags = ODPF_BOLDGROUPS; - Options_AddPage(addInfo, &odp); - return 0; -} - - -// -// dialog procedure for the options dialog. creates or -// retrieves the options class and calls it -// -static INT_PTR CALLBACK DlgProcSmileysOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - OptionsDialogType *pOD = (OptionsDialogType*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (pOD == NULL) { - pOD = new OptionsDialogType(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pOD); - } - - INT_PTR Result = pOD->DialogProcedure(msg, wParam, lParam); - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, Result); - - if (msg == WM_NCDESTROY) - delete pOD; - - return Result; -} - - //OptionsDialog class functions BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) { BOOL Result = FALSE; - switch(msg) { + switch (msg) { case WM_INITDIALOG: InitDialog(); Result = TRUE; @@ -108,7 +68,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_FILENAME: - switch(HIWORD(wParam)) { + switch (HIWORD(wParam)) { case EN_KILLFOCUS: FilenameChanged(); break; @@ -122,7 +82,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) case IDC_BROWSE: if (HIWORD(wParam) == BN_CLICKED) if (BrowseForSmileyPacks(GetSelProto())) { - UpdateControls(true); + UpdateControls(true); SetChanged(); } break; @@ -139,7 +99,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) } // no break! case IDC_USEPHYSPROTO: if (HIWORD(wParam) == BN_CLICKED) { - PopulateSmPackList(); + PopulateSmPackList(); SetChanged(); } break; @@ -195,7 +155,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) { + switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: @@ -208,7 +168,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) switch (((LPNMHDR)lParam)->code) { case NM_CLICK: { - TVHITTESTINFO ht = {0}; + TVHITTESTINFO ht = { 0 }; DWORD dwpos = GetMessagePos(); POINTSTOPOINT(ht.pt, MAKEPOINTS(dwpos)); @@ -222,13 +182,13 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) } case TVN_KEYDOWN: - if (((LPNMTVKEYDOWN) lParam)->wVKey == VK_SPACE) - PostMessage(m_hwndDialog, UM_CHECKSTATECHANGE, 0, - (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); + if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE) + PostMessage(m_hwndDialog, UM_CHECKSTATECHANGE, 0, + (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom)); break; case TVN_SELCHANGED: - LPNMTREEVIEW pnmtv = (LPNMTREEVIEW) lParam; + LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam; if (pnmtv->itemNew.state & TVIS_SELECTED) UpdateControls(); } @@ -242,8 +202,7 @@ BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam) void OptionsDialogType::AddCategory(void) { TCHAR cat[30]; - - GetDlgItemText(m_hwndDialog, IDC_NEWCATEGORY, cat, _countof(cat)); + GetDlgItemText(m_hwndDialog, IDC_NEWCATEGORY, cat, _countof(cat)); CMString catd = cat; if (!catd.IsEmpty()) { @@ -262,8 +221,8 @@ void OptionsDialogType::UserAction(HTREEITEM hItem) if (!BrowseForSmileyPacks(GetSelProto(hItem))) TreeView_SetCheckState(hLstView, hItem, TRUE) } - else - tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename(); + else + tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename(); if (hItem == TreeView_GetSelection(hLstView)) UpdateControls(); @@ -280,18 +239,17 @@ void OptionsDialogType::SetChanged(void) SendMessage(GetParent(m_hwndDialog), PSM_CHANGED, 0, 0); } - void OptionsDialogType::UpdateControls(bool force) { - const SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(GetSelProto()); - if (smc == NULL) return; + const SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(GetSelProto()); + if (smc == NULL) + return; - const CMString& smf = smc->GetFilename(); - - SetDlgItemText(m_hwndDialog, IDC_FILENAME, smf.c_str()); + const CMString &smf = smc->GetFilename(); + SetDlgItemText(m_hwndDialog, IDC_FILENAME, smf); if (smPack.GetFilename() != smf || force) - smPack.LoadSmileyFile(smf, smPack.GetName() , false, true); + smPack.LoadSmileyFile(smf, smPack.GetName(), false, true); HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST); TreeView_SetCheckState(hLstView, TreeView_GetSelection(hLstView), smPack.SmileyCount() != 0); @@ -301,11 +259,10 @@ void OptionsDialogType::UpdateControls(bool force) SetDlgItemText(m_hwndDialog, IDC_LIBNAME, TranslateTS(smPack.GetName().c_str())); } - long OptionsDialogType::GetSelProto(HTREEITEM hItem) { HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST); - TVITEM tvi = {0}; + TVITEM tvi = { 0 }; tvi.mask = TVIF_PARAM; tvi.hItem = hItem == NULL ? TreeView_GetSelection(hLstView) : hItem; @@ -324,12 +281,12 @@ void OptionsDialogType::UpdateVisibleSmPackList(void) for (int i = 0; i < smc.getCount(); i++) { bool visiblecat = usePhysProto ? !smc[i].IsAcc() : !smc[i].IsPhysProto(); bool visible = useOne ? !smc[i].IsProto() : visiblecat; - + if (!visible && smc[i].IsAcc() && !useOne) { CMString PhysProtoName = _T("AllProto"); CMString ProtoName = smc[i].GetName(); - DBVARIANT dbv; - if (db_get_ts(NULL, T2A_SM(ProtoName.GetBuffer()), "AM_BaseProto", &dbv) == 0){ + DBVARIANT dbv; + if (db_get_ts(NULL, _T2A(ProtoName.GetBuffer()), "AM_BaseProto", &dbv) == 0) { ProtoName = dbv.ptszVal; db_free(&dbv); } @@ -338,15 +295,15 @@ void OptionsDialogType::UpdateVisibleSmPackList(void) CMString FileName; if (!ProtoName.IsEmpty()) { - PhysProtoName += ProtoName; + PhysProtoName += ProtoName; SmileyCategoryType* scm = tmpsmcat.GetSmileyCategory(PhysProtoName); if (scm == NULL) visible = false; else if (scm->GetFilename().IsEmpty()) - visible = true; + visible = true; } } - + smc[i].SetVisible(visible); } } @@ -358,14 +315,14 @@ void OptionsDialogType::PopulateSmPackList(void) TreeView_SelectItem(hLstView, NULL); TreeView_DeleteAllItems(hLstView); - TVINSERTSTRUCT tvi = {0}; + TVINSERTSTRUCT tvi = { 0 }; tvi.hParent = TVI_ROOT; tvi.hInsertAfter = TVI_LAST; tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_STATE | TVIF_SELECTEDIMAGE | TVIF_PARAM; tvi.item.stateMask = TVIS_STATEIMAGEMASK | TVIS_SELECTED; UpdateVisibleSmPackList(); SmileyCategoryListType::SmileyCategoryVectorType& smc = *tmpsmcat.GetSmileyCategoryList(); - for (int i=0; i < smc.getCount(); i++) { + for (int i = 0; i < smc.getCount(); i++) { if (smc[i].IsVisible()) { tvi.item.pszText = (TCHAR*)smc[i].GetDisplayName().c_str(); if (!smc[i].IsProto()) { @@ -406,13 +363,13 @@ void OptionsDialogType::InitDialog(void) CheckDlgButton(m_hwndDialog, IDC_HQSCALING, opt.HQScaling ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(m_hwndDialog, IDC_SORTING_HORIZONTAL, opt.HorizontalSorting ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM) TranslateT("Off")); - SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM) TranslateT("Top")); + SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Off")); + SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Top")); if (IsOldSrmm()) - SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM) TranslateT("Bottom")); + SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_ADDSTRING, 0, (LPARAM)TranslateT("Bottom")); - SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_SETCURSEL, opt.ButtonStatus, 0); + SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_SETCURSEL, opt.ButtonStatus, 0); EnableWindow(GetDlgItem(m_hwndDialog, IDC_SMLBUT), opt.PluginSupportEnabled); EnableWindow(GetDlgItem(m_hwndDialog, IDC_USEPHYSPROTO), !opt.UseOneForAll); @@ -431,14 +388,14 @@ void OptionsDialogType::InitDialog(void) tmpsmcat = g_SmileyCategories; SmileyCategoryListType::SmileyCategoryVectorType& smc = *g_SmileyCategories.GetSmileyCategoryList(); - for (int i=0; i < smc.getCount(); i++) { + for (int i = 0; i < smc.getCount(); i++) { HICON hIcon = NULL; if (smc[i].IsProto()) { - hIcon = (HICON)CallProtoService(T2A_SM(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); - if (hIcon == NULL || (INT_PTR)hIcon == CALLSERVICE_NOTFOUND) - hIcon = (HICON)CallProtoService(T2A_SM(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0); - } - if (hIcon == NULL || hIcon == (HICON)CALLSERVICE_NOTFOUND) + hIcon = (HICON)CallProtoService(_T2A(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); + if (hIcon == NULL || (INT_PTR)hIcon == CALLSERVICE_NOTFOUND) + hIcon = (HICON)CallProtoService(_T2A(smc[i].GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0); + } + if (hIcon == NULL || hIcon == (HICON)CALLSERVICE_NOTFOUND) hIcon = GetDefaultIcon(); ImageList_AddIcon(hImList, hIcon); @@ -458,7 +415,6 @@ void OptionsDialogType::DestroyDialog(void) ImageList_Destroy(hImList); } - void OptionsDialogType::ApplyChanges(void) { ProcessAllInputAreas(true); @@ -480,26 +436,24 @@ void OptionsDialogType::ApplyChanges(void) opt.HQScaling = IsDlgButtonChecked(m_hwndDialog, IDC_HQSCALING) == BST_CHECKED; opt.HorizontalSorting = IsDlgButtonChecked(m_hwndDialog, IDC_SORTING_HORIZONTAL) == BST_CHECKED; - opt.ButtonStatus = (unsigned)SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_GETCURSEL, 0, 0); + opt.ButtonStatus = (unsigned)SendDlgItemMessage(m_hwndDialog, IDC_SMLBUT, CB_GETCURSEL, 0, 0); opt.MaxCustomSmileySize = GetDlgItemInt(m_hwndDialog, IDC_MAXCUSTSMSZ, NULL, FALSE); opt.MinSmileySize = GetDlgItemInt(m_hwndDialog, IDC_MINSMSZ, NULL, FALSE); opt.Save(); // Cleanup database - SmileyCategoryListType::SmileyCategoryVectorType& smc = *g_SmileyCategories.GetSmileyCategoryList(); - for (int i=0; i < smc.getCount(); i++) { - if (tmpsmcat.GetSmileyCategory(smc[i].GetName()) == NULL) { - CMString empty; + CMString empty; + SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList(); + for (int i = 0; i < smc.getCount(); i++) + if (tmpsmcat.GetSmileyCategory(smc[i].GetName()) == NULL) opt.WritePackFileName(empty, smc[i].GetName()); - } - } g_SmileyCategories = tmpsmcat; g_SmileyCategories.SaveSettings(); g_SmileyCategories.ClearAndLoadAll(); - smPack.LoadSmileyFile(tmpsmcat.GetSmileyCategory(GetSelProto())->GetFilename(), tmpsmcat.GetSmileyCategory(GetSelProto())->GetDisplayName(),false, true); + smPack.LoadSmileyFile(tmpsmcat.GetSmileyCategory(GetSelProto())->GetFilename(), tmpsmcat.GetSmileyCategory(GetSelProto())->GetDisplayName(), false, true); NotifyEventHooks(hEvent1, 0, 0); ProcessAllInputAreas(false); @@ -507,14 +461,14 @@ void OptionsDialogType::ApplyChanges(void) bool OptionsDialogType::BrowseForSmileyPacks(int item) { - OPENFILENAME ofn = {0}; + OPENFILENAME ofn = { 0 }; TCHAR filename[MAX_PATH] = _T(""); ofn.lpstrFile = filename; ofn.nMaxFile = _countof(filename); CMString inidir; - SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(item); + SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(item); if (smc->GetFilename().IsEmpty()) pathToAbsolute(_T("Smileys"), inidir); else { @@ -537,7 +491,7 @@ bool OptionsDialogType::BrowseForSmileyPacks(int item) pfilter = pfilter + mir_tstrlen(pfilter) + 1; mir_tstrcpy(pfilter, _T("*.*")); pfilter = pfilter + mir_tstrlen(pfilter) + 1; - *pfilter = '\0'; + *pfilter = '\0'; ofn.lpstrFilter = filter; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_READONLY | @@ -560,7 +514,7 @@ void OptionsDialogType::FilenameChanged(void) TCHAR str[MAX_PATH]; GetDlgItemText(m_hwndDialog, IDC_FILENAME, str, _countof(str)); - SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(GetSelProto()); + SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(GetSelProto()); if (smc->GetFilename() != str) { CMString temp(str); smc->SetFilename(temp); @@ -616,7 +570,7 @@ void OptionsType::Load(void) ScaleToTextheight = db_get_b(NULL, "SmileyAdd", "ScaleToTextheight", FALSE) != 0; UseOneForAll = db_get_b(NULL, "SmileyAdd", "UseOneForAll", TRUE) != 0; UsePhysProto = db_get_b(NULL, "SmileyAdd", "UsePhysProto", FALSE) != 0; - SurroundSmileyWithSpaces = + SurroundSmileyWithSpaces = db_get_b(NULL, "SmileyAdd", "SurroundSmileyWithSpaces", FALSE) != 0; ScaleAllSmileys = db_get_b(NULL, "SmileyAdd", "ScaleAllSmileys", FALSE) != 0; IEViewStyle = db_get_b(NULL, "SmileyAdd", "IEViewStyle", FALSE) != 0; @@ -634,61 +588,80 @@ void OptionsType::Load(void) HorizontalSorting = db_get_b(NULL, "SmileyAdd", "HorizontalSorting", 1) != 0; } - -void OptionsType::ReadPackFileName(CMString& filename, const CMString& name, const CMString& defaultFilename) +void OptionsType::ReadPackFileName(CMString &filename, const CMString &name, const CMString &defaultFilename) { CMString settingKey = name + _T("-filename"); - DBVARIANT dbv; - if (!db_get_ts(NULL, "SmileyAdd", T2A_SM(settingKey.c_str()), &dbv)) { - filename = dbv.ptszVal; - db_free(&dbv); - } - else filename = defaultFilename; + ptrT tszValue(db_get_tsa(NULL, "SmileyAdd", _T2A(settingKey.c_str()))); + filename = (tszValue != NULL) ? (TCHAR*)tszValue : defaultFilename; } -void OptionsType::WritePackFileName(const CMString& filename, const CMString& name) +void OptionsType::WritePackFileName(const CMString &filename, const CMString &name) { CMString settingKey = name + _T("-filename"); - db_set_ts(NULL, "SmileyAdd", T2A_SM(settingKey.c_str()), filename.c_str()); + db_set_ts(NULL, "SmileyAdd", _T2A(settingKey.c_str()), filename.c_str()); } - -void OptionsType::ReadCustomCategories(CMString& cats) +void OptionsType::ReadCustomCategories(CMString &cats) { - DBVARIANT dbv; - INT_PTR res = db_get_ts(NULL, "SmileyAdd", "CustomCategories", &dbv); - if (res == 0) { - cats = dbv.ptszVal; - db_free(&dbv); - } + ptrT tszValue(db_get_tsa(NULL, "SmileyAdd", "CustomCategories")); + if (tszValue != NULL) + cats = tszValue; } - -void OptionsType::WriteCustomCategories(const CMString& cats) +void OptionsType::WriteCustomCategories(const CMString &cats) { if (cats.IsEmpty()) db_unset(NULL, "SmileyAdd", "CustomCategories"); else - db_set_ts(NULL, "SmileyAdd", "CustomCategories", cats.c_str()); + db_set_ts(NULL, "SmileyAdd", "CustomCategories", cats.c_str()); } - -void OptionsType::ReadContactCategory(MCONTACT hContact, CMString& cats) +void OptionsType::ReadContactCategory(MCONTACT hContact, CMString &cats) { - DBVARIANT dbv; - INT_PTR res = db_get_ts(hContact, "SmileyAdd", "CustomCategory", &dbv); - if (res == 0) { - cats = dbv.ptszVal; - db_free(&dbv); - } + ptrT tszValue(db_get_tsa(hContact, "SmileyAdd", "CustomCategory")); + if (tszValue != NULL) + cats = tszValue; } - -void OptionsType::WriteContactCategory(MCONTACT hContact, const CMString& cats) +void OptionsType::WriteContactCategory(MCONTACT hContact, const CMString &cats) { if (cats.IsEmpty()) db_unset(hContact, "SmileyAdd", "CustomCategory"); else - db_set_ts(hContact, "SmileyAdd", "CustomCategory", cats.c_str()); + db_set_ts(hContact, "SmileyAdd", "CustomCategory", cats.c_str()); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Init and de-init functions, called from main + +static INT_PTR CALLBACK DlgProcSmileysOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + OptionsDialogType *pOD = (OptionsDialogType*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + if (pOD == NULL) { + pOD = new OptionsDialogType(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)pOD); + } + + INT_PTR Result = pOD->DialogProcedure(msg, wParam, lParam); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, Result); + + if (msg == WM_NCDESTROY) + delete pOD; + + return Result; +} + +int SmileysOptionsInitialize(WPARAM addInfo, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.position = 910000000; + odp.hInstance = g_hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SMILEYS); + odp.pszTitle = LPGEN("Smileys"); + odp.pszGroup = LPGEN("Customize"); + odp.pfnDlgProc = DlgProcSmileysOptions; + odp.flags = ODPF_BOLDGROUPS; + Options_AddPage(addInfo, &odp); + return 0; } diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp index e38a3eeec0..64530d6941 100644 --- a/plugins/SmileyAdd/src/richcall.cpp +++ b/plugins/SmileyAdd/src/richcall.cpp @@ -72,15 +72,15 @@ static void SetPosition(HWND hwnd) int objectCount = RichEditOle->GetObjectCount(); for (int i = objectCount - 1; i >= 0; i--) { - REOBJECT reObj = {0}; - reObj.cbStruct = sizeof(REOBJECT); + REOBJECT reObj = { 0 }; + reObj.cbStruct = sizeof(REOBJECT); HRESULT hr = RichEditOle->GetObject(i, &reObj, REO_GETOBJ_POLEOBJ); if (FAILED(hr)) continue; ISmileyBase *igsc = NULL; - if (reObj.clsid == CLSID_NULL) - reObj.poleobj->QueryInterface(IID_ISmileyAddSmiley, (void**) &igsc); + if (reObj.clsid == CLSID_NULL) + reObj.poleobj->QueryInterface(IID_ISmileyAddSmiley, (void**)&igsc); reObj.poleobj->Release(); if (igsc == NULL) continue; @@ -127,13 +127,13 @@ static void SetTooltip(long x, long y, HWND hwnd, RichEditData* rdt) if (needtip != -1) { if (rdt->tipActive == -1) { - rdt->hToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_NOPREFIX | WS_POPUP, + rdt->hToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_NOPREFIX | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, g_hInst, NULL); SendMessage(rdt->hToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); } - ti.lpszText = smltxt; + ti.lpszText = smltxt; SendMessage(rdt->hToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); SendMessage(rdt->hToolTip, TTM_ACTIVATE, TRUE, 0); } @@ -193,7 +193,7 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP CHARRANGE sel; - switch(uMsg) { + switch (uMsg) { case WM_COPY: case WM_CUT: SmileyToTextCutPrep(rdt); @@ -226,9 +226,9 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP break; } - LRESULT result = mir_callNextSubclass(hwnd, RichEditSubclass, uMsg, wParam, lParam); + LRESULT result = mir_callNextSubclass(hwnd, RichEditSubclass, uMsg, wParam, lParam); - switch(uMsg) { + switch (uMsg) { case WM_MOUSEMOVE: SetTooltip(LOWORD(lParam), HIWORD(lParam), hwnd, rdt); break; @@ -260,13 +260,13 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP else if (wParam == VK_TAB && ((GetKeyState(VK_CONTROL) | GetKeyState(VK_SHIFT)) & 0x8000) == 0) { sel.cpMax = LONG_MAX; - bool hascont = rdt->hContact != NULL; + bool hascont = rdt->hContact != NULL; ReplaceContactSmileys(rdt, sel, false, hascont); } break; case WM_CHAR: - if (!rdt->inputarea || (rdt->inputarea && !opt.InputSmileys)) + if (!rdt->inputarea || (rdt->inputarea && !opt.InputSmileys)) break; if (lParam & (1 << 28)) // ALT key @@ -336,9 +336,9 @@ bool SetRichCallback(HWND hwnd, MCONTACT hContact, bool subany, bool subnew) } else { if (hContact && !rdt->hContact) - rdt->hContact = hContact; + rdt->hContact = hContact; - if (subany) + if (subany) mir_subclassWindow(hwnd, RichEditSubclass); } return true; @@ -347,7 +347,7 @@ bool SetRichCallback(HWND hwnd, MCONTACT hContact, bool subany, bool subnew) void CloseRichCallback(HWND hwnd) { int ind = g_RichEditList.getIndex((RichEditData*)&hwnd); - if (ind == -1 ) + if (ind == -1) return; RichEditData* rdt = g_RichEditList[ind]; @@ -366,7 +366,7 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara if (rdto == NULL) return 0; - switch(uMsg) { + switch (uMsg) { case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624) { RichEditData* rdt = g_RichEditList.find((RichEditData*)&rdto->hwndInput); @@ -388,9 +388,9 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara break; } - LRESULT result = mir_callNextSubclass(hwnd, RichEditOwnerSubclass, uMsg, wParam, lParam); + LRESULT result = mir_callNextSubclass(hwnd, RichEditOwnerSubclass, uMsg, wParam, lParam); - switch(uMsg) { + switch (uMsg) { case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624) { RichEditData* rdt = g_RichEditList.find((RichEditData*)&rdto->hwndInput); @@ -444,7 +444,7 @@ void CloseRichOwnerCallback(HWND hwnd) void ProcessAllInputAreas(bool restoreText) { - for (int i=g_RichEditList.getCount()-1; i >= 0; i--) { + for (int i = g_RichEditList.getCount() - 1; i >= 0; i--) { RichEditData* rdt = g_RichEditList[i]; if (rdt->inputarea) { if (restoreText) { @@ -456,14 +456,13 @@ void ProcessAllInputAreas(bool restoreText) } } -void RichEditData_Destroy(void) +void RichEditData_Destroy(void) { - int i; - for (i=g_RichEditList.getCount()-1; i >= 0; i--) + for (int i = g_RichEditList.getCount() - 1; i >= 0; i--) CloseRichCallback(g_RichEditList[i]->hwnd); g_RichEditList.destroy(); - for (i=g_RichEditOwnerList.getCount()-1; i >= 0; i--) + for (int i = g_RichEditOwnerList.getCount() - 1; i >= 0; i--) CloseRichOwnerCallback(g_RichEditOwnerList[i]->hwnd); g_RichEditOwnerList.destroy(); } diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 067efab655..a4f3471b7f 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -50,16 +50,16 @@ SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact, SmileyPackCT categoryName = dbv.ptszVal; db_free(&dbv); } - else if (opt.UsePhysProto && db_get_ts(NULL, protonam, "AM_BaseProto", &dbv) == 0){ + else if (opt.UsePhysProto && db_get_ts(NULL, protonam, "AM_BaseProto", &dbv) == 0) { categoryName = _T("AllProto"); categoryName += dbv.ptszVal; - db_free(&dbv); + db_free(&dbv); CMString categoryFileName = g_SmileyCategories.GetSmileyCategory(categoryName) ? g_SmileyCategories.GetSmileyCategory(categoryName)->GetFilename() : _T(""); if (categoryFileName.IsEmpty()) - categoryName = A2T_SM(protonam); + categoryName = _A2T(protonam); } - else - categoryName = A2T_SM(protonam); + else + categoryName = _A2T(protonam); } } } @@ -68,10 +68,10 @@ SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact, SmileyPackCT if (proto == NULL || proto[0] == 0) categoryName = _T("Standard"); else { - categoryName = A2T_SM(proto); + categoryName = _A2T(proto); if (opt.UseOneForAll) { SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName); - if (smc == NULL || smc->IsProto()) + if (smc == NULL || smc->IsProto()) categoryName = _T("Standard"); } } @@ -83,23 +83,23 @@ SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact, SmileyPackCT INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam) { - SMADD_RICHEDIT3* smre = (SMADD_RICHEDIT3*) lParam; + SMADD_RICHEDIT3* smre = (SMADD_RICHEDIT3*)lParam; if (smre == NULL) return FALSE; - SMADD_RICHEDIT3 smrec = {0}; + SMADD_RICHEDIT3 smrec = { 0 }; memcpy(&smrec, smre, min(smre->cbSize, sizeof(smrec))); static const CHARRANGE selection = { 0, LONG_MAX }; if (smre->rangeToReplace == NULL) smrec.rangeToReplace = (CHARRANGE*)&selection; - else if (smrec.rangeToReplace->cpMax < 0) smrec.rangeToReplace->cpMax = LONG_MAX; + else if (smrec.rangeToReplace->cpMax < 0) smrec.rangeToReplace->cpMax = LONG_MAX; SmileyPackCType* smcp = NULL; - SmileyPackType* SmileyPack = GetSmileyPack(smrec.Protocolname, smrec.hContact, + SmileyPackType* SmileyPack = GetSmileyPack(smrec.Protocolname, smrec.hContact, (smrec.flags & (SAFLRE_OUTGOING | SAFLRE_NOCUSTOM)) ? NULL : &smcp); - ReplaceSmileys(smre->hwndRichEditControl, SmileyPack, smcp, *smrec.rangeToReplace, - smrec.hContact == NULL, false, false, (smre->flags & SAFLRE_FIREVIEW)?true:false); + ReplaceSmileys(smre->hwndRichEditControl, SmileyPack, smcp, *smrec.rangeToReplace, + smrec.hContact == NULL, false, false, (smre->flags & SAFLRE_FIREVIEW) ? true : false); return TRUE; } @@ -107,7 +107,7 @@ INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam) INT_PTR ShowSmileySelectionCommand(WPARAM, LPARAM lParam) { - SMADD_SHOWSEL3* smaddInfo = (SMADD_SHOWSEL3*) lParam; + SMADD_SHOWSEL3* smaddInfo = (SMADD_SHOWSEL3*)lParam; if (smaddInfo == NULL) return FALSE; HWND parent = smaddInfo->hwndParent; @@ -138,8 +138,7 @@ static int GetInfoCommandE(SMADD_INFO2* smre, bool retDup) SmileyPackType* SmileyPack = GetSmileyPack(smre->Protocolname, hContact); - if (SmileyPack == NULL || SmileyPack->SmileyCount() == 0) - { + if (SmileyPack == NULL || SmileyPack->SmileyCount() == 0) { smre->ButtonIcon = NULL; smre->NumberOfSmileys = 0; smre->NumberOfVisibleSmileys = 0; @@ -162,41 +161,41 @@ static int GetInfoCommandE(SMADD_INFO2* smre, bool retDup) INT_PTR GetInfoCommand(WPARAM, LPARAM lParam) { - return GetInfoCommandE((SMADD_INFO2*) lParam, false); + return GetInfoCommandE((SMADD_INFO2*)lParam, false); } INT_PTR GetInfoCommand2(WPARAM, LPARAM lParam) { - return GetInfoCommandE((SMADD_INFO2*) lParam, true); + return GetInfoCommandE((SMADD_INFO2*)lParam, true); } INT_PTR ParseTextBatch(WPARAM, LPARAM lParam) { - SMADD_BATCHPARSE2* smre = (SMADD_BATCHPARSE2*) lParam; + SMADD_BATCHPARSE2* smre = (SMADD_BATCHPARSE2*)lParam; if (smre == NULL) return FALSE; MCONTACT hContact = smre->hContact; SmileyPackCType* smcp = NULL; - SmileyPackType* SmileyPack = GetSmileyPack(smre->Protocolname, hContact, + SmileyPackType* SmileyPack = GetSmileyPack(smre->Protocolname, hContact, (smre->flag & (SAFL_OUTGOING | SAFL_NOCUSTOM)) ? NULL : &smcp); SmileysQueueType smllist; if (smre->flag & SAFL_UNICODE) - LookupAllSmileys(SmileyPack, smcp, W2T_SM(smre->wstr), smllist, false); + LookupAllSmileys(SmileyPack, smcp, smre->wstr, smllist, false); else - LookupAllSmileys(SmileyPack, smcp, A2T_SM(smre->astr), smllist, false); + LookupAllSmileys(SmileyPack, smcp, _A2T(smre->astr), smllist, false); if (smllist.getCount() == 0) return 0; - SMADD_BATCHPARSERES *res = new SMADD_BATCHPARSERES[smllist.getCount()]; + SMADD_BATCHPARSERES *res = new SMADD_BATCHPARSERES[smllist.getCount()]; SMADD_BATCHPARSERES* cres = res; - for (int j=0; j < smllist.getCount(); j++) { + for (int j = 0; j < smllist.getCount(); j++) { cres->startChar = smllist[j].loc.cpMin; cres->size = smllist[j].loc.cpMax - smllist[j].loc.cpMin; if (smllist[j].sml) { @@ -224,24 +223,20 @@ INT_PTR ParseTextBatch(WPARAM, LPARAM lParam) INT_PTR FreeTextBatch(WPARAM, LPARAM lParam) { - delete[] (SMADD_BATCHPARSERES*)lParam; + delete[](SMADD_BATCHPARSERES*)lParam; return TRUE; } INT_PTR RegisterPack(WPARAM, LPARAM lParam) { - SMADD_REGCAT* smre = (SMADD_REGCAT*) lParam; + SMADD_REGCAT* smre = (SMADD_REGCAT*)lParam; if (smre == NULL || smre->cbSize < sizeof(SMADD_REGCAT)) return FALSE; if (IsBadStringPtrA(smre->name, 50) || IsBadStringPtrA(smre->dispname, 50)) return FALSE; - unsigned lpcp = Langpack_GetDefaultCodePage(); - - CMString nmd(A2W_SM(smre->dispname, lpcp)); - - - CMString nm(A2T_SM(smre->name)); + CMString nmd(_A2T(smre->dispname)); + CMString nm(_A2T(smre->name)); g_SmileyCategories.AddAndLoad(nm, nmd); return TRUE; @@ -251,7 +246,7 @@ INT_PTR CustomCatMenu(WPARAM hContact, LPARAM lParam) { if (lParam != 0) { SmileyCategoryType* smct = g_SmileyCategories.GetSmileyCategory((unsigned)lParam - 3); - if (smct != NULL) + if (smct != NULL) opt.WriteContactCategory(hContact, smct->GetName()); else { CMString empty; @@ -261,7 +256,7 @@ INT_PTR CustomCatMenu(WPARAM hContact, LPARAM lParam) NotifyEventHooks(hEvent1, hContact, 0); } - for (int i=0; i < menuHandleArray.getCount(); i++) + for (int i = 0; i < menuHandleArray.getCount(); i++) Menu_RemoveItem((HGENMENU)menuHandleArray[i]); menuHandleArray.destroy(); @@ -277,14 +272,14 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) bool haveMenu = IsSmileyProto(protnam); if (haveMenu && opt.UseOneForAll) { unsigned cnt = 0; - for (int i=0; i < smc.getCount(); i++) + for (int i = 0; i < smc.getCount(); i++) cnt += smc[i].IsCustom(); haveMenu = cnt != 0; } Menu_ShowItem(hContactMenuItem, haveMenu); - for (int i=0; i < menuHandleArray.getCount(); i++) + for (int i = 0; i < menuHandleArray.getCount(); i++) Menu_RemoveItem((HGENMENU)menuHandleArray[i]); menuHandleArray.destroy(); @@ -300,7 +295,7 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) bool nonecheck = true; HGENMENU hMenu; - for (int i=0; i < smc.getCount(); i++) { + for (int i = 0; i < smc.getCount(); i++) { if (smc[i].IsExt() || (smc[i].IsProto() && opt.UseOneForAll) || smc[i].GetFilename().IsEmpty()) continue; @@ -309,7 +304,7 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) mi.name.t = (TCHAR*)smc[i].GetDisplayName().c_str(); if (cat == smc[i].GetName()) { - mi.flags |= CMIF_CHECKED; + mi.flags |= CMIF_CHECKED; nonecheck = false; } @@ -322,7 +317,7 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) mi.position = 1; mi.name.t = _T(""); if (cat == _T("")) { - mi.flags |= CMIF_CHECKED; + mi.flags |= CMIF_CHECKED; nonecheck = false; } @@ -344,14 +339,13 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) INT_PTR ReloadPack(WPARAM, LPARAM lParam) { - if (lParam) - { - CMString categoryName = A2T_SM((char*)lParam); + if (lParam) { + CMString categoryName = _A2T((char*)lParam); SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName); - if (smc != NULL) smc->Load(); + if (smc != NULL) + smc->Load(); } - else - { + else { g_SmileyCategories.ClearAll(); g_SmileyCategories.AddAllProtocolsAsCategory(); g_SmileyCategories.ClearAndLoadAll(); @@ -363,7 +357,7 @@ INT_PTR ReloadPack(WPARAM, LPARAM lParam) INT_PTR LoadContactSmileys(WPARAM, LPARAM lParam) { - if (opt.DisableCustom) return 0; + if (opt.DisableCustom) return 0; SMADD_CONT* cont = (SMADD_CONT*)lParam; @@ -385,11 +379,9 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam) { PROTOACCOUNT* acc = (PROTOACCOUNT*)lParam; - switch (wParam) - { + switch (wParam) { case PRAC_ADDED: - if (acc != NULL) - { + if (acc != NULL) { CMString catname(_T("Standard")); const CMString& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename(); g_SmileyCategories.AddAccountAsCategory(acc, defaultFile); @@ -397,12 +389,10 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam) break; case PRAC_CHANGED: - if (acc != NULL && acc->szModuleName != NULL) - { - CMString name(A2T_SM(acc->szModuleName)); + if (acc != NULL && acc->szModuleName != NULL) { + CMString name(_A2T(acc->szModuleName)); SmileyCategoryType* smc = g_SmileyCategories.GetSmileyCategory(name); - if (smc != NULL) - { + if (smc != NULL) { if (acc->tszAccountName) name = acc->tszAccountName; smc->SetDisplayName(name); } @@ -414,18 +404,13 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam) break; case PRAC_CHECKED: - if (acc != NULL) - { - if (acc->bIsEnabled) - { + if (acc != NULL) { + if (acc->bIsEnabled) { CMString catname(_T("Standard")); const CMString& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename(); g_SmileyCategories.AddAccountAsCategory(acc, defaultFile); } - else - { - g_SmileyCategories.DeleteAccountAsCategory(acc); - } + else g_SmileyCategories.DeleteAccountAsCategory(acc); } break; } @@ -439,7 +424,7 @@ int DbSettingChanged(WPARAM hContact, LPARAM lParam) DBCONTACTWRITESETTING* cws = (DBCONTACTWRITESETTING*)lParam; if (cws->value.type == DBVT_DELETED) - return 0; + return 0; if (strcmp(cws->szSetting, "Transport") == 0) { CMString catname(_T("Standard")); diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp index e5154dc051..4e5534bbbc 100644 --- a/plugins/SmileyAdd/src/smileyroutines.cpp +++ b/plugins/SmileyAdd/src/smileyroutines.cpp @@ -226,7 +226,7 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const TextRange->Release(); SmileysQueueType smllist; - LookupAllSmileys(smp, smcp, W2T_SM(btxt), smllist, false); + LookupAllSmileys(smp, smcp, btxt, smllist, false); SysFreeString(btxt); @@ -315,7 +315,7 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const BSTR bstrText = NULL; if (smlc == NULL && sml->IsText()) { - bstrText = SysAllocString(T2W_SM(sml->GetToolText().c_str())); + bstrText = SysAllocString(sml->GetToolText().c_str()); TextSelection->SetText(bstrText); } else { @@ -400,11 +400,12 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const } else UpdateSelection(oldSel, smlpos.cpMin, -(int)SysStringLen(bstrText)+1); - ISmileyBase* smileyBase = CreateAniSmileyObject(smlc ? smlc : sml, chf.crBackColor, ishpp); - if (smileyBase == NULL) continue; + ISmileyBase *smileyBase = CreateAniSmileyObject(smlc ? smlc : sml, chf.crBackColor, ishpp); + if (smileyBase == NULL) + continue; smileyBase->SetExtent(DVASPECT_CONTENT, &sizehm); - smileyBase->SetHint(W2T_SM(bstrText)); + smileyBase->SetHint(bstrText); smileyBase->SetPosition(hwnd, NULL); diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 8aafb54843..1c178a914f 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -240,7 +240,7 @@ void SmileyType::CallSmileyService(MCONTACT hContact) proto = (const char*)GetContactProto(hContact); if (proto == NULL) return; } - mir_snprintf(str, "%s%s", proto, T2A_SM(name.c_str())); + mir_snprintf(str, "%s%s", proto, _T2A(name.c_str())); CallService(str, ConvertServiceParam(hContact, par1.c_str()), ConvertServiceParam(hContact, par2.c_str())); @@ -385,11 +385,11 @@ bool SmileyPackType::LoadSmileyFile(const CMString& filename, const CMString& pa CMString tbuf; if (len > 2 && *(wchar_t*)buf == 0xfeff) - tbuf = W2T_SM((wchar_t*)buf + 1); + tbuf = ((wchar_t*)buf + 1); else if (len > 3 && buf[0] == '\xef' && buf[1] == '\xbb' && buf[2] == '\xbf') - tbuf = W2T_SM(A2W_SM(buf + 3, CP_UTF8)); + tbuf = _A2T(buf + 3, CP_UTF8); else - tbuf = A2T_SM(buf); + tbuf = _A2T(buf); delete[] buf; @@ -626,7 +626,7 @@ bool SmileyPackType::LoadSmileyFileXEP(CMString& tbuf, bool onlyInfo, CMString&) m1 = imagedt_re->createTMatcher(images); if (m1->findFirstMatch()) { - IStream* pStream = DecodeBase64Data(T2A_SM(m1->getGroup(1).c_str())); + IStream* pStream = DecodeBase64Data(_T2A(m1->getGroup(1).c_str())); if (pStream != NULL) { if (m_hSmList != NULL) ImageList_Destroy(m_hSmList); m_hSmList = ImageList_Read(pStream); @@ -669,7 +669,7 @@ bool SmileyPackType::LoadSmileyFileXEP(CMString& tbuf, bool onlyInfo, CMString&) m2 = imagedt_re->createTMatcher(images); if (m2->findFirstMatch()) { - IStream* pStream = DecodeBase64Data(T2A_SM(m2->getGroup(1).c_str())); + IStream* pStream = DecodeBase64Data(_T2A(m2->getGroup(1).c_str())); if (pStream != NULL) { dat->LoadFromImage(pStream); pStream->Release(); @@ -873,7 +873,7 @@ bool SmileyCategoryListType::DeleteCustomCategory(int index) void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMString& defaultFile) { if (Proto_IsAccountEnabled(acc) && acc->szProtoName && IsSmileyProto(acc->szModuleName)) { - CMString displayName(acc->tszAccountName ? acc->tszAccountName : A2T_SM(acc->szModuleName)); + CMString displayName(acc->tszAccountName ? acc->tszAccountName : _A2T(acc->szModuleName)); CMString PhysProtoName, paths; DBVARIANT dbv; @@ -896,7 +896,7 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStr char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - paths = A2T_SM(path); + paths = _A2T(path); CMString patha; pathToAbsolute(paths, patha); @@ -904,7 +904,7 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStr paths = defaultFile; } - CMString tname(A2T_SM(acc->szModuleName)); + CMString tname(_A2T(acc->szModuleName)); AddCategory(tname, displayName, acc->bIsVirtual ? smcVirtualProto : smcProto, paths); } } @@ -923,7 +923,7 @@ void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMString& defau char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - CMString paths = A2T_SM(path), patha; + CMString paths = _A2T(path), patha; pathToAbsolute(paths, patha); if (_taccess(patha.c_str(), 0) != 0) @@ -931,13 +931,13 @@ void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMString& defau CMString dName(acc), displayName; displayName.AppendFormat(TranslateT("%s global smiley pack"), dName.GetBuffer()); CMString tname("AllProto"); - tname += A2T_SM(acc); + tname += _A2T(acc); AddCategory(tname, displayName, smcPhysProto, paths); } void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc) { - CMString tname(A2T_SM(acc->szModuleName)); + CMString tname(_A2T(acc->szModuleName)); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char* proto = GetContactProto(hContact); @@ -972,7 +972,7 @@ void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, co db_free(&dbv); return; } - char* trsp = mir_strdup(T2A_SM(dbv.ptszVal)); + char* trsp = mir_strdup(_T2A(dbv.ptszVal)); _strlwr(trsp); const char *packname = NULL; @@ -994,7 +994,7 @@ void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, co char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packname); - CMString paths = A2T_SM(path), patha; + CMString paths = _A2T(path), patha; pathToAbsolute(paths, patha); if (_taccess(patha.c_str(), 0) != 0) diff --git a/plugins/SmileyAdd/src/smltool.cpp b/plugins/SmileyAdd/src/smltool.cpp index a4a2e41d22..c7eb03ff81 100644 --- a/plugins/SmileyAdd/src/smltool.cpp +++ b/plugins/SmileyAdd/src/smltool.cpp @@ -77,7 +77,7 @@ LRESULT CALLBACK DlgProcSmileyToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, SmileyToolWindowType *pOD = (SmileyToolWindowType*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (pOD == NULL) { pOD = new SmileyToolWindowType(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pOD); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)pOD); } LRESULT Result = pOD->DialogProcedure(msg, wParam, lParam); @@ -91,11 +91,11 @@ LRESULT CALLBACK DlgProcSmileyToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, } -SmileyToolWindowType::SmileyToolWindowType(HWND hWnd) -{ - m_hwndDialog = hWnd; - rowSel = -1; - m_AniPack = NULL; +SmileyToolWindowType::SmileyToolWindowType(HWND hWnd) +{ + m_hwndDialog = hWnd; + rowSel = -1; + m_AniPack = NULL; m_NumberOfVerticalButtons = 0; m_NumberOfHorizontalButtons = 0; @@ -114,7 +114,7 @@ LRESULT SmileyToolWindowType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lP switch (msg) { case WM_ACTIVATE: - if (wParam == WA_INACTIVE) + if (wParam == WA_INACTIVE) DestroyWindow(m_hwndDialog); break; @@ -132,7 +132,7 @@ LRESULT SmileyToolWindowType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lP m_AniPack = NULL; DestroyWindow(m_hToolTip); PostQuitMessage(0); - if (m_Choosing) + if (m_Choosing) SetFocus(m_hWndTarget); break; @@ -157,7 +157,7 @@ LRESULT SmileyToolWindowType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lP break; case WM_MOUSEWHEEL: - ScrollV(SB_MYMOVE, ((short)HIWORD(wParam))/-120); + ScrollV(SB_MYMOVE, ((short)HIWORD(wParam)) / -120); MouseMove(LOWORD(lParam), HIWORD(lParam)); break; @@ -172,7 +172,9 @@ LRESULT SmileyToolWindowType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lP struct smlsrvstruct { smlsrvstruct(SmileyType *tsml, MCONTACT thContact) - : sml(tsml), hContact(thContact) {} + : sml(tsml), hContact(thContact) + { + } SmileyType *sml; MCONTACT hContact; }; @@ -200,7 +202,7 @@ void SmileyToolWindowType::InsertSmiley(void) insertText += sml->GetInsertText(); if (opt.SurroundSmileyWithSpaces) insertText += ' '; - SendMessage(m_hWndTarget, m_TargetMessage, m_TargetWParam, (LPARAM) insertText.c_str()); + SendMessage(m_hWndTarget, m_TargetMessage, m_TargetWParam, (LPARAM)insertText.c_str()); } m_Choosing = true; DestroyWindow(m_hwndDialog); @@ -212,11 +214,11 @@ void SmileyToolWindowType::InsertSmiley(void) void SmileyToolWindowType::SmileySel(int but) { if (but != m_CurrentHotTrack) { - SCROLLINFO si; - si.cbSize = sizeof (si); - si.fMask = SIF_POS; + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_POS; si.nPos = 0; - GetScrollInfo (m_hwndDialog, SB_VERT, &si); + GetScrollInfo(m_hwndDialog, SB_VERT, &si); HDC hdc = GetDC(m_hwndDialog); if (m_CurrentHotTrack >= 0) { @@ -227,14 +229,14 @@ void SmileyToolWindowType::SmileySel(int but) } m_CurrentHotTrack = but; if (m_CurrentHotTrack >= 0) { - TOOLINFO ti = {0}; + TOOLINFO ti = { 0 }; ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.hwnd = m_hwndDialog; ti.uId = (UINT_PTR)m_hwndDialog; const CMString& toolText = m_pSmileyPack->GetSmiley(m_CurrentHotTrack)->GetToolText(); - ti.lpszText = const_cast(toolText.c_str()); + ti.lpszText = const_cast(toolText.c_str()); SendMessage(m_hToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); SendMessage(m_hToolTip, TTM_ACTIVATE, TRUE, 0); @@ -248,51 +250,51 @@ void SmileyToolWindowType::SmileySel(int but) void SmileyToolWindowType::ScrollV(int action, int dist) -{ - SCROLLINFO si; - si.cbSize = sizeof (si); - si.fMask = SIF_ALL; - GetScrollInfo (m_hwndDialog, SB_VERT, &si); +{ + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + GetScrollInfo(m_hwndDialog, SB_VERT, &si); // Save the position for comparison later on int yPos = si.nPos; switch (action) { - // user clicked the HOME keyboard key + // user clicked the HOME keyboard key case SB_TOP: si.nPos = si.nMin; break; - // user clicked the END keyboard key + // user clicked the END keyboard key case SB_BOTTOM: si.nPos = si.nMax; break; - // user clicked the top arrow + // user clicked the top arrow case SB_LINEUP: si.nPos -= 1; break; - // user clicked the bottom arrow + // user clicked the bottom arrow case SB_LINEDOWN: si.nPos += 1; break; - // user clicked the scroll bar shaft above the scroll box + // user clicked the scroll bar shaft above the scroll box case SB_PAGEUP: si.nPos -= si.nPage; break; - // user clicked the scroll bar shaft below the scroll box + // user clicked the scroll bar shaft below the scroll box case SB_PAGEDOWN: si.nPos += si.nPage; break; - // user dragged the scroll box + // user dragged the scroll box case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; - // user dragged the scroll box + // user dragged the scroll box case SB_MYMOVE: si.nPos += dist; break; @@ -300,19 +302,19 @@ void SmileyToolWindowType::ScrollV(int action, int dist) // Set the position and then retrieve it. Due to adjustments // by Windows it may not be the same as the value set. si.fMask = SIF_POS; - SetScrollInfo (m_hwndDialog, SB_VERT, &si, TRUE); - GetScrollInfo (m_hwndDialog, SB_VERT, &si); + SetScrollInfo(m_hwndDialog, SB_VERT, &si, TRUE); + GetScrollInfo(m_hwndDialog, SB_VERT, &si); // If the position has changed, scroll window and update it - if (si.nPos != yPos) { + if (si.nPos != yPos) { if (m_AniPack) m_AniPack->SetOffset(si.nPos*GetRowSize()); - ScrollWindowEx(m_hwndDialog, 0, (yPos - si.nPos) * GetRowSize(), + ScrollWindowEx(m_hwndDialog, 0, (yPos - si.nPos) * GetRowSize(), NULL, NULL, NULL, NULL, SW_INVALIDATE); - UpdateWindow (m_hwndDialog); + UpdateWindow(m_hwndDialog); } -} +} void SmileyToolWindowType::MouseMove(int xposition, int yposition) @@ -321,13 +323,13 @@ void SmileyToolWindowType::MouseMove(int xposition, int yposition) // SetFocus(m_hwndDialog); - SCROLLINFO si; - si.cbSize = sizeof (si); - si.fMask = SIF_POS; + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_POS; si.nPos = 0; - GetScrollInfo (m_hwndDialog, SB_VERT, &si); + GetScrollInfo(m_hwndDialog, SB_VERT, &si); - POINT pt = { xposition, yposition }; + POINT pt = { xposition, yposition }; int but = CalculateCoordinatesToButton(pt, si.nPos); SmileySel(but); } @@ -339,10 +341,9 @@ void SmileyToolWindowType::KeyUp(WPARAM wParam, LPARAM lParam) int colSel = -1, numKey = -1; int but = m_CurrentHotTrack; - switch(wParam) - { + switch (wParam) { case VK_END: - but = m_NumberOfButtons-1; + but = m_NumberOfButtons - 1; break; case VK_HOME: @@ -383,10 +384,9 @@ void SmileyToolWindowType::KeyUp(WPARAM wParam, LPARAM lParam) case VK_NUMPAD7: case VK_NUMPAD8: case VK_NUMPAD9: - if ((GetKeyState(VK_NUMLOCK) & 1) != 0) + if ((GetKeyState(VK_NUMLOCK) & 1) != 0) numKey = (int)wParam - VK_NUMPAD1; - else - { + else { rowSel = -1; return; } @@ -410,7 +410,7 @@ void SmileyToolWindowType::KeyUp(WPARAM wParam, LPARAM lParam) } if (numKey != -1) { - if (rowSel == -1) { + if (rowSel == -1) { rowSel = numKey; but = (opt.HorizontalSorting ? m_NumberOfHorizontalButtons : 1) * rowSel; } @@ -424,7 +424,7 @@ void SmileyToolWindowType::KeyUp(WPARAM wParam, LPARAM lParam) } if (but < 0) but = 0; - if (but >= (int)m_NumberOfButtons) but = m_NumberOfButtons-1; + if (but >= (int)m_NumberOfButtons) but = m_NumberOfButtons - 1; SmileySel(but); if (colSel != -1) @@ -435,7 +435,7 @@ void SmileyToolWindowType::KeyUp(WPARAM wParam, LPARAM lParam) void SmileyToolWindowType::InitDialog(LPARAM lParam) { LPCREATESTRUCT createStruct = (LPCREATESTRUCT)lParam; - SmileyToolWindowParam* stwp = (SmileyToolWindowParam*) createStruct->lpCreateParams; + SmileyToolWindowParam* stwp = (SmileyToolWindowParam*)createStruct->lpCreateParams; m_pSmileyPack = stwp->pSmileyPack; m_XPosition = stwp->xPosition; @@ -452,41 +452,41 @@ void SmileyToolWindowType::InitDialog(LPARAM lParam) CreateSmileyWinDim(); int width = m_BitmapWidth.cx; - int height = m_BitmapWidth.cy; + int height = m_BitmapWidth.cy; - const int colsz = GetRowSize(); + const int colsz = GetRowSize(); const int heightn = m_WindowSizeY; SCROLLINFO si; - si.cbSize = sizeof(si); - si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - si.nMin = 0; - si.nMax = height / colsz - 1; - si.nPage = heightn / colsz; - si.nPos = 0; - SetScrollInfo(m_hwndDialog, SB_VERT, &si, TRUE); + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + si.nMin = 0; + si.nMax = height / colsz - 1; + si.nPage = heightn / colsz; + si.nPos = 0; + SetScrollInfo(m_hwndDialog, SB_VERT, &si, TRUE); if (GetWindowLongPtr(m_hwndDialog, GWL_STYLE) & WS_VSCROLL) width += GetSystemMetrics(SM_CXVSCROLL); RECT rc = { 0, 0, width, heightn }; - AdjustWindowRectEx(&rc, GetWindowLongPtr(m_hwndDialog, GWL_STYLE), + AdjustWindowRectEx(&rc, GetWindowLongPtr(m_hwndDialog, GWL_STYLE), FALSE, GetWindowLongPtr(m_hwndDialog, GWL_EXSTYLE)); width = rc.right - rc.left; - height = rc.bottom - rc.top; + height = rc.bottom - rc.top; switch (m_Direction) { - case 1: - m_XPosition-=width; + case 1: + m_XPosition -= width; break; case 2: - m_XPosition-=width; - m_YPosition-=height; + m_XPosition -= width; + m_YPosition -= height; break; case 3: - m_YPosition-=height; + m_YPosition -= height; break; } @@ -505,18 +505,18 @@ void SmileyToolWindowType::InitDialog(LPARAM lParam) // Prevent window from opening off-screen if (m_YPosition + height > yScreen) m_YPosition = yScreen - height; - if (m_XPosition + width > xScreen) m_XPosition = xScreen - width; + if (m_XPosition + width > xScreen) m_XPosition = xScreen - width; if (m_YPosition < yoScreen) m_YPosition = yoScreen; if (m_XPosition < xoScreen) m_XPosition = xoScreen; // Move window to desired location - SetWindowPos(m_hwndDialog, NULL, m_XPosition, m_YPosition, + SetWindowPos(m_hwndDialog, NULL, m_XPosition, m_YPosition, width, height, SWP_NOZORDER); m_AniPack = new AnimatedPack(m_hwndDialog, height, m_ButtonSize, opt.SelWndBkgClr); SmileyPackType::SmileyVectorType &sml = m_pSmileyPack->GetSmileyList(); - for (unsigned i=0; iAdd(&sml[i], CalculateButtonToCoordinates(i, 0), opt.IEViewStyle); @@ -525,9 +525,9 @@ void SmileyToolWindowType::InitDialog(LPARAM lParam) if (opt.AnimateSel) SetTimer(m_hwndDialog, 1, 100, NULL); //add tooltips - m_hToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), + m_hToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_NOPREFIX | WS_POPUP, 0, 0, 0, 0, m_hwndDialog, NULL, g_hInst, NULL); - TOOLINFO ti = {0}; + TOOLINFO ti = { 0 }; ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.hwnd = m_hwndDialog; @@ -540,13 +540,13 @@ void SmileyToolWindowType::InitDialog(LPARAM lParam) void SmileyToolWindowType::PaintWindow(void) { SCROLLINFO si; - si.cbSize = sizeof(si); - si.fMask = SIF_POS; + si.cbSize = sizeof(si); + si.fMask = SIF_POS; si.nPos = 0; GetScrollInfo(m_hwndDialog, SB_VERT, &si); - PAINTSTRUCT ps; - HDC hdc = BeginPaint(m_hwndDialog, &ps); + PAINTSTRUCT ps; + HDC hdc = BeginPaint(m_hwndDialog, &ps); HBITMAP hBmp = CreateCompatibleBitmap(hdc, m_BitmapWidth.cx, m_BitmapWidth.cy); HDC hdcMem = CreateCompatibleDC(hdc); @@ -559,14 +559,14 @@ void SmileyToolWindowType::PaintWindow(void) BitBlt(hdc, 0, 0, m_BitmapWidth.cx, m_WindowSizeY, hdcMem, 0, 0, SRCCOPY); - SelectObject(hdcMem, hOld); - DeleteObject(hBmp); + SelectObject(hdcMem, hOld); + DeleteObject(hBmp); DeleteDC(hdcMem); if (m_CurrentHotTrack == -2) m_CurrentHotTrack = -1; - EndPaint(m_hwndDialog, &ps); + EndPaint(m_hwndDialog, &ps); } @@ -577,20 +577,16 @@ void SmileyToolWindowType::CreateSmileyWinDim(void) if (m_NumberOfButtons == 0) return; // Find largest smiley - if (m_pSmileyPack->selec.x == 0 || m_pSmileyPack->selec.y == 0) - { - if (opt.ScaleAllSmileys) - { + if (m_pSmileyPack->selec.x == 0 || m_pSmileyPack->selec.y == 0) { + if (opt.ScaleAllSmileys) { m_pSmileyPack->GetSmiley(0)->GetSize(m_ButtonSize); - ++m_ButtonSize.cx; ++m_ButtonSize.cy; + ++m_ButtonSize.cx; ++m_ButtonSize.cy; } - else - { + else { m_ButtonSize.cx = 0; m_ButtonSize.cy = 0; SmileyPackType::SmileyVectorType &sml = m_pSmileyPack->GetSmileyList(); - for (unsigned i=0; iselec; } - if (m_pSmileyPack->win.x == 0 || m_pSmileyPack->win.y == 0) - { - if (opt.IEViewStyle) - { + if (m_pSmileyPack->win.x == 0 || m_pSmileyPack->win.y == 0) { + if (opt.IEViewStyle) { // All integer square root unsigned i; - for (i=1; i*iwin.x; - m_NumberOfVerticalButtons = m_NumberOfButtons / m_NumberOfHorizontalButtons + + m_NumberOfVerticalButtons = m_NumberOfButtons / m_NumberOfHorizontalButtons + (m_NumberOfButtons % m_NumberOfHorizontalButtons != 0); } - m_BitmapWidth.cx = m_NumberOfHorizontalButtons * (m_ButtonSize.cx + m_ButtonSpace) + m_ButtonSpace; + m_BitmapWidth.cx = m_NumberOfHorizontalButtons * (m_ButtonSize.cx + m_ButtonSpace) + m_ButtonSpace; m_BitmapWidth.cy = m_NumberOfVerticalButtons * (m_ButtonSize.cy + m_ButtonSpace) + m_ButtonSpace; const int colsz = m_ButtonSize.cy + m_ButtonSpace; @@ -657,23 +648,20 @@ void SmileyToolWindowType::CreateSmileyBitmap(HDC hdc) FillRect(hdc, &rc, hBkgBrush); DeleteObject(hBkgBrush); - if (opt.IEViewStyle) - { + if (opt.IEViewStyle) { HPEN hpen = CreatePen(PS_DOT, 1, 0); HGDIOBJ hOldPen = SelectObject(hdc, hpen); POINT pts[2] = { {0, 0}, {m_BitmapWidth.cx, 0} }; - for (unsigned i=0; i<=m_NumberOfVerticalButtons; i++) - { + for (unsigned i = 0; i <= m_NumberOfVerticalButtons; i++) { pts[0].y = pts[1].y = i * (m_ButtonSize.cy + m_ButtonSpace); if (pts[0].y > m_WindowSizeY) break; Polyline(hdc, pts, 2); } pts[0].y = 0; pts[1].y = m_BitmapWidth.cy; - for (unsigned j=0; j<=m_NumberOfHorizontalButtons; j++) - { + for (unsigned j = 0; j <= m_NumberOfHorizontalButtons; j++) { pts[0].x = pts[1].x = j * (m_ButtonSize.cx + m_ButtonSpace); Polyline(hdc, pts, 2); } @@ -685,23 +673,21 @@ void SmileyToolWindowType::CreateSmileyBitmap(HDC hdc) RECT SmileyToolWindowType::CalculateButtonToCoordinates(int buttonPosition, int scroll) -{ +{ int row, rowpos; - if (opt.HorizontalSorting) - { + if (opt.HorizontalSorting) { row = buttonPosition / m_NumberOfHorizontalButtons; rowpos = buttonPosition % m_NumberOfHorizontalButtons; } - else - { + else { row = buttonPosition % m_NumberOfVerticalButtons; rowpos = buttonPosition / m_NumberOfVerticalButtons; } RECT pt; pt.left = rowpos * (m_ButtonSize.cx + m_ButtonSpace) + m_ButtonSpace; - pt.top = (row - scroll) * (m_ButtonSize.cy + m_ButtonSpace) + m_ButtonSpace; + pt.top = (row - scroll) * (m_ButtonSize.cy + m_ButtonSpace) + m_ButtonSpace; pt.right = pt.left + m_ButtonSize.cx; pt.bottom = pt.top + m_ButtonSize.cy; @@ -727,34 +713,32 @@ int SmileyToolWindowType::CalculateCoordinatesToButton(POINT pt, int scroll) void __cdecl SmileyToolThread(void *arg) { - SmileyToolWindowParam* stwp = (SmileyToolWindowParam*)arg; - if (stwp->pSmileyPack && stwp->pSmileyPack->VisibleSmileyCount()) - { + SmileyToolWindowParam *stwp = (SmileyToolWindowParam*)arg; + if (stwp->pSmileyPack && stwp->pSmileyPack->VisibleSmileyCount()) { WNDCLASSEX wndclass; - wndclass.cbSize = sizeof(wndclass); - wndclass.style = CS_SAVEBITS; - wndclass.lpfnWndProc = DlgProcSmileyToolWindow; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 4; - wndclass.hInstance = g_hInst; - wndclass.hIcon = NULL; - wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_SAVEBITS; + wndclass.lpfnWndProc = DlgProcSmileyToolWindow; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 4; + wndclass.hInstance = g_hInst; + wndclass.hIcon = NULL; + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = CreateSolidBrush(opt.SelWndBkgClr); - wndclass.lpszMenuName = NULL; + wndclass.lpszMenuName = NULL; wndclass.lpszClassName = _T("SmileyTool"); - wndclass.hIconSm = NULL; + wndclass.hIconSm = NULL; RegisterClassEx(&wndclass); - CreateWindowEx(WS_EX_TOPMOST | WS_EX_NOPARENTNOTIFY, _T("SmileyTool"), NULL, - WS_BORDER | WS_POPUP | WS_VISIBLE, + CreateWindowEx(WS_EX_TOPMOST | WS_EX_NOPARENTNOTIFY, _T("SmileyTool"), NULL, + WS_BORDER | WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, ((SmileyToolWindowParam*)arg)->hWndParent, NULL, g_hInst, arg); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { + while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h index 79677a8c68..9cedd2947c 100644 --- a/plugins/SmileyAdd/src/stdafx.h +++ b/plugins/SmileyAdd/src/stdafx.h @@ -87,6 +87,7 @@ typedef WCMatcher _TMatcher; #include "smileyroutines.h" #include "smltool.h" +extern FI_INTERFACE *fei; extern HINSTANCE g_hInst; extern HANDLE hNetlibUser; extern HANDLE hEvent1; @@ -117,42 +118,6 @@ extern LIST menuHandleArray; #define MAX_SMILEY_LENGTH 96 -class A2W_SM -{ -public: - wchar_t* m_psz; - - A2W_SM(const char* psz, unsigned nCodePage = CP_ACP) - { - const int nLength = MultiByteToWideChar(nCodePage, 0, psz, -1, NULL, 0); - m_psz = new wchar_t[nLength]; - MultiByteToWideChar(nCodePage, 0, psz, -1, m_psz, nLength); - } - ~A2W_SM() { delete [] m_psz; } - operator wchar_t*() const { return m_psz; } -}; - - -class W2A_SM -{ -public: - char* m_psz; - - W2A_SM(const wchar_t* psz, unsigned nCodePage = CP_ACP) - { - const int nLength = WideCharToMultiByte(nCodePage, 0, psz, -1, NULL, 0, NULL, NULL); - m_psz = new char[nLength]; - WideCharToMultiByte(nCodePage, 0, psz, -1, m_psz, nLength, NULL, NULL); - } - ~W2A_SM() { delete [] m_psz; } - operator char*() const { return m_psz; } -}; - -#define T2A_SM (char*)W2A_SM -#define T2W_SM(p1) (wchar_t*)p1 -#define A2T_SM (wchar_t*)A2W_SM -#define W2T_SM(p1) (TCHAR*)p1 - // init functions void InstallDialogBoxHook(void); void RemoveDialogBoxHook(void); @@ -168,13 +133,13 @@ bool IsSmileyProto(char* proto); HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle); -void pathToRelative(const CMString& pSrc, CMString& pOut); -void pathToAbsolute(const CMString& pSrc, CMString& pOut); +void pathToRelative(const CMString &pSrc, CMString &pOut); +void pathToAbsolute(const CMString &pSrc, CMString &pOut); bool InitGdiPlus(void); void DestroyGdiPlus(void); -void ReportError(const TCHAR* errmsg); +void ReportError(const TCHAR *errmsg); HICON GetDefaultIcon(bool copy = true); void CloseRichCallback(HWND hwnd); @@ -185,6 +150,7 @@ void ProcessAllInputAreas(bool restoreText); void RichEditData_Destroy(void); void CloseSmileys(void); +int CheckForTip(int x, int y, HWND hwnd, TCHAR **smltxt); void UrlDecode(char* str); -- cgit v1.2.3