summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-03-03 10:03:03 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-03-03 10:03:03 +0000
commit292cb6ecd2c5f834c8b535ca8bd6c678e84fab88 (patch)
treeda8a7590001734fc1de68ddebed124827828c6fb
parent5fe02998f36882b52451743f831e811c051b395f (diff)
- CComPtr rulez;
- obsolete code removed; git-svn-id: http://svn.miranda-ng.org/main/trunk@16400 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/SmileyAdd/src/AniSmileyObject.cpp39
-rw-r--r--plugins/SmileyAdd/src/SmileyBase.h37
-rw-r--r--plugins/SmileyAdd/src/dlgboxsubclass.cpp172
-rw-r--r--plugins/SmileyAdd/src/richcall.cpp58
-rw-r--r--plugins/SmileyAdd/src/smileyroutines.cpp87
-rw-r--r--plugins/SmileyAdd/src/smileyroutines.h9
-rw-r--r--plugins/SmileyAdd/src/stdafx.h15
7 files changed, 154 insertions, 263 deletions
diff --git a/plugins/SmileyAdd/src/AniSmileyObject.cpp b/plugins/SmileyAdd/src/AniSmileyObject.cpp
index c437b9ab5a..176d0760c3 100644
--- a/plugins/SmileyAdd/src/AniSmileyObject.cpp
+++ b/plugins/SmileyAdd/src/AniSmileyObject.cpp
@@ -84,32 +84,33 @@ public:
void GetDrawingProp()
{
- if (m_hwnd == NULL) return;
-
- IRichEditOle* RichEditOle;
- if (SendMessage(m_hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
+ if (m_hwnd == NULL)
return;
REOBJECT reObj = { 0 };
- reObj.cbStruct = sizeof(REOBJECT);
+ reObj.cbStruct = sizeof(reObj);
+ {
+ CComPtr<IRichEditOle> RichEditOle;
+ if (SendMessage(m_hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
+ return;
- HRESULT hr = RichEditOle->GetObject(m_lastObjNum, &reObj, REO_GETOBJ_NO_INTERFACES);
- if (hr == S_OK && reObj.dwUser == (DWORD_PTR)this && reObj.clsid == CLSID_NULL)
- m_richFlags = reObj.dwFlags;
- else {
- long objectCount = RichEditOle->GetObjectCount();
- for (long i = objectCount; i--; ) {
- hr = RichEditOle->GetObject(i, &reObj, REO_GETOBJ_NO_INTERFACES);
- if (FAILED(hr)) continue;
-
- if (reObj.dwUser == (DWORD_PTR)this && reObj.clsid == CLSID_NULL) {
- m_lastObjNum = i;
- m_richFlags = reObj.dwFlags;
- break;
+ HRESULT hr = RichEditOle->GetObject(m_lastObjNum, &reObj, REO_GETOBJ_NO_INTERFACES);
+ if (SUCCEEDED(hr) && reObj.dwUser == (DWORD_PTR)this && reObj.clsid == CLSID_NULL)
+ m_richFlags = reObj.dwFlags;
+ else {
+ long objectCount = RichEditOle->GetObjectCount();
+ for (long i = objectCount; i--; ) {
+ hr = RichEditOle->GetObject(i, &reObj, REO_GETOBJ_NO_INTERFACES);
+ if (FAILED(hr)) continue;
+
+ if (reObj.dwUser == (DWORD_PTR)this && reObj.clsid == CLSID_NULL) {
+ m_lastObjNum = i;
+ m_richFlags = reObj.dwFlags;
+ break;
+ }
}
}
}
- RichEditOle->Release();
if ((m_richFlags & REO_SELECTED) == 0) {
CHARRANGE sel;
diff --git a/plugins/SmileyAdd/src/SmileyBase.h b/plugins/SmileyAdd/src/SmileyBase.h
index d208360c3a..4f695b8ac8 100644
--- a/plugins/SmileyAdd/src/SmileyBase.h
+++ b/plugins/SmileyAdd/src/SmileyBase.h
@@ -32,22 +32,22 @@ EXTERN_C const IID IID_ISmileyAddSmiley;
class ISmileyBase : public IOleObject, public IViewObject2, public ITooltipData
{
-protected:
IOleAdviseHolder* m_spAdviseHolder;
- IAdviseSink* m_spAdviseSink;
- IOleClientSite* m_spClientSite;
- DWORD m_advf;
- LONG m_lRefCount;
-
- SIZEL m_sizeExtent;
- SIZEL m_sizeExtentHiM;
- RECT m_orect;
+ IAdviseSink* m_spAdviseSink;
+ IOleClientSite* m_spClientSite;
+
+ DWORD m_advf;
+ LONG m_lRefCount;
TCHAR* m_smltxt;
- HWND m_hwnd;
- bool m_visible;
- bool m_dirAniAllow;
+protected:
+ SIZEL m_sizeExtent;
+ SIZEL m_sizeExtentHiM;
+ RECT m_orect;
+ HWND m_hwnd;
+ bool m_visible;
+ bool m_dirAniAllow;
public:
ISmileyBase(void);
@@ -62,10 +62,10 @@ public:
virtual void Draw() PURE;
virtual void SetPosition(HWND hwnd, LPCRECT lpRect);
- //
+ //
// IUnknown members
//
- STDMETHOD_(ULONG, AddRef)(void);
+ STDMETHOD_(ULONG, AddRef)(void);
STDMETHOD_(ULONG, Release)(void);
STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
@@ -80,8 +80,7 @@ public:
STDMETHOD(GetMoniker)(DWORD /* dwAssign */, DWORD /* dwWhichMoniker */, IMoniker** /* ppmk */);
STDMETHOD(InitFromData)(IDataObject* /* pDataObject */, BOOL /* fCreation */, DWORD /* dwReserved */);
STDMETHOD(GetClipboardData)(DWORD /* dwReserved */, IDataObject** /* ppDataObject */);
- STDMETHOD(DoVerb)(LONG /*iVerb*/, LPMSG /* pMsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */,
- HWND /*hwndParent*/, LPCRECT /*lprcPosRect*/);
+ STDMETHOD(DoVerb)(LONG /*iVerb*/, LPMSG /* pMsg */, IOleClientSite* /* pActiveSite */, LONG /* lindex */, HWND /*hwndParent*/, LPCRECT /*lprcPosRect*/);
STDMETHOD(EnumVerbs)(IEnumOLEVERB** /*ppEnumOleVerb*/);
STDMETHOD(Update)(void);
STDMETHOD(IsUpToDate)(void);
@@ -102,8 +101,7 @@ public:
STDMETHOD(GetAdvise)(DWORD* /*pAspects*/, DWORD* /*pAdvf*/, IAdviseSink** ppAdvSink);
STDMETHOD(Freeze)(DWORD, long, void*, DWORD*);
STDMETHOD(Unfreeze)(DWORD);
- STDMETHOD(GetColorSet)(DWORD, long, void*, DVTARGETDEVICE*, HDC,
- LOGPALETTE**);
+ STDMETHOD(GetColorSet)(DWORD, long, void*, DVTARGETDEVICE*, HDC, LOGPALETTE**);
//
// IViewObject2 members
@@ -114,6 +112,5 @@ public:
// ITooltipData members
//
STDMETHOD(SetTooltip)(BSTR bstrHint);
- STDMETHOD(GetTooltip)(BSTR *bstrHint);
+ STDMETHOD(GetTooltip)(BSTR *bstrHint);
};
-
diff --git a/plugins/SmileyAdd/src/dlgboxsubclass.cpp b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
index 2bbee5dd06..0c5d6d184c 100644
--- a/plugins/SmileyAdd/src/dlgboxsubclass.cpp
+++ b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
@@ -19,24 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-//***************************************************//
-// DISCLAIMER!!!
-// we are not supposed to use this object, so be aware
-typedef struct NewMessageWindowLParam
-{
- MCONTACT hContact;
- int isSend;
- const char *szInitialText;
-}
-msgData;
-// this is an undocumented object!!!!!!!
-// subject to change in miranda versions...!!!!!!
-// DISCLAIMER!!!
-//***************************************************//
-
-static HHOOK g_hMessageHookPre = NULL;
-static HANDLE g_hMutex = NULL;
-static HANDLE g_hHookMsgWnd = NULL;
+static mir_cs csHook;
static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -91,7 +74,6 @@ public:
dsb.hSmlButton = NULL;
}
-
~MsgWndData()
{
clear();
@@ -139,12 +121,11 @@ public:
rect.right += pt.x - rect.left;
rect.top = pt.y;
rect.left = pt.x;
-
return rect;
}
- //helper function
- //identifies the message dialog
+ // helper function
+ // identifies the message dialog
bool IsMessageSendDialog(HWND hwndDlg)
{
TCHAR szClassName[32] = _T("");
@@ -156,8 +137,8 @@ public:
if ((REdit = GetDlgItem(hwndDlg, MI_IDC_LOG)) != NULL) {
GetClassName(REdit, szClassName, _countof(szClassName));
if (mir_tstrcmp(szClassName, _T("RichEdit20A")) != 0 &&
- mir_tstrcmp(szClassName, _T("RichEdit20W")) != 0 &&
- mir_tstrcmp(szClassName, _T("RICHEDIT50W")) != 0)
+ mir_tstrcmp(szClassName, _T("RichEdit20W")) != 0 &&
+ mir_tstrcmp(szClassName, _T("RICHEDIT50W")) != 0)
return false;
}
else return false;
@@ -165,9 +146,9 @@ public:
if ((MEdit = GetDlgItem(hwndDlg, MI_IDC_MESSAGE)) != NULL) {
GetClassName(MEdit, szClassName, _countof(szClassName));
if (mir_tstrcmp(szClassName, _T("Edit")) != 0 &&
- mir_tstrcmp(szClassName, _T("RichEdit20A")) != 0 &&
- mir_tstrcmp(szClassName, _T("RichEdit20W")) != 0 &&
- mir_tstrcmp(szClassName, _T("RICHEDIT50W")) != 0)
+ mir_tstrcmp(szClassName, _T("RichEdit20A")) != 0 &&
+ mir_tstrcmp(szClassName, _T("RichEdit20W")) != 0 &&
+ mir_tstrcmp(szClassName, _T("RICHEDIT50W")) != 0)
return false;
}
else return false;
@@ -190,7 +171,7 @@ public:
doSmileyButton = opt.ButtonStatus != 0;
OldButtonPlace = opt.ButtonStatus == 2;
- SmileyPackType* SmileyPack = GetSmileyPack(ProtocolName, hContact);
+ SmileyPackType *SmileyPack = GetSmileyPack(ProtocolName, hContact);
doSmileyButton &= SmileyPack != NULL && SmileyPack->VisibleSmileyCount() != 0;
bool showButtonLine;
@@ -234,7 +215,7 @@ public:
NULL); // window-creation data
// Conversion to bitmap done to prevent Miranda from scaling the image
- SmileyType* sml = FindButtonSmiley(SmileyPack);
+ SmileyType *sml = FindButtonSmiley(SmileyPack);
if (sml != NULL) {
hSmlBmp = sml->GetBitmap(GetSysColor(COLOR_BTNFACE), 0, 0);
SendMessage(hSmlButton, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hSmlBmp);
@@ -254,18 +235,18 @@ static int CompareMsgWndData(const MsgWndData* p1, const MsgWndData* p2)
{
return (int)((INT_PTR)p1->hwnd - (INT_PTR)p2->hwnd);
}
-static LIST<MsgWndData> g_MsgWndList(10, CompareMsgWndData);
+static LIST<MsgWndData> g_MsgWndList(10, CompareMsgWndData);
bool IsOldSrmm(void)
{
return ServiceExists(MS_MSG_GETWINDOWCLASS) == 0;
}
-
int UpdateSrmmDlg(WPARAM wParam, LPARAM /* lParam */)
{
- WaitForSingleObject(g_hMutex, 2000);
+ mir_cslock lck(csHook);
+
for (int i = 0; i < g_MsgWndList.getCount(); ++i) {
if (wParam == 0 || g_MsgWndList[i]->hContact == wParam) {
SendMessage(g_MsgWndList[i]->hwnd, WM_SETREDRAW, FALSE, 0);
@@ -273,67 +254,51 @@ int UpdateSrmmDlg(WPARAM wParam, LPARAM /* lParam */)
SendMessage(g_MsgWndList[i]->hwnd, WM_SETREDRAW, TRUE, 0);
}
}
- ReleaseMutex(g_hMutex);
-
return 0;
}
-
-//find the dialog info in the stored list
+// find the dialog info in the stored list
static MsgWndData* IsMsgWnd(HWND hwnd)
{
- WaitForSingleObject(g_hMutex, 2000);
- MsgWndData* res = g_MsgWndList.find((MsgWndData*)&hwnd);
- ReleaseMutex(g_hMutex);
-
- return res;
+ mir_cslock lck(csHook);
+ return g_MsgWndList.find((MsgWndData*)&hwnd);
}
-
-static void MsgWndDetect(HWND hwndDlg, MCONTACT hContact, msgData* datm)
+static void MsgWndDetect(HWND hwndDlg, MCONTACT hContact)
{
MsgWndData dat;
+ if (!dat.IsMessageSendDialog(hwndDlg))
+ return;
- if (dat.IsMessageSendDialog(hwndDlg)) {
- dat.hwnd = hwndDlg;
- if (datm != NULL) {
- dat.isSend = datm->isSend != 0;
- dat.hContact = datm->hContact;
- }
- else dat.hContact = hContact;
-
- // Get the protocol for this contact to display correct smileys.
- char *protonam = GetContactProto(DecodeMetaContact(dat.hContact));
- if (protonam) {
- strncpy(dat.ProtocolName, protonam, sizeof(dat.ProtocolName));
- dat.ProtocolName[sizeof(dat.ProtocolName) - 1] = 0;
- }
-
- WaitForSingleObject(g_hMutex, 2000);
+ dat.hwnd = hwndDlg;
+ dat.hContact = hContact;
- MsgWndData* msgwnd = g_MsgWndList.find((MsgWndData*)&hwndDlg);
- if (msgwnd == NULL) {
- msgwnd = new MsgWndData(dat);
- g_MsgWndList.insert(msgwnd);
- }
- else
- msgwnd = NULL;
- ReleaseMutex(g_hMutex);
-
- if (msgwnd != NULL) {
- mir_subclassWindow(hwndDlg, MessageDlgSubclass);
- msgwnd->CreateSmileyButton();
- if (hContact == NULL)
- SetRichCallback(msgwnd->REdit, msgwnd->hContact, true, true);
- }
+ // Get the protocol for this contact to display correct smileys.
+ char *protonam = GetContactProto(DecodeMetaContact(dat.hContact));
+ if (protonam) {
+ strncpy(dat.ProtocolName, protonam, sizeof(dat.ProtocolName));
+ dat.ProtocolName[sizeof(dat.ProtocolName) - 1] = 0;
+ }
+
+ mir_cslock lck(csHook);
+
+ MsgWndData *msgwnd = g_MsgWndList.find((MsgWndData*)&hwndDlg);
+ if (msgwnd == NULL) {
+ msgwnd = new MsgWndData(dat);
+ g_MsgWndList.insert(msgwnd);
+
+ mir_subclassWindow(hwndDlg, MessageDlgSubclass);
+ msgwnd->CreateSmileyButton();
+ if (hContact == NULL)
+ SetRichCallback(msgwnd->REdit, msgwnd->hContact, true, true);
}
}
-//global subclass function for all dialogs
+// global subclass function for all dialogs
static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- MsgWndData* dat = IsMsgWnd(hwnd);
+ MsgWndData *dat = IsMsgWnd(hwnd);
if (dat == NULL)
return 0;
@@ -345,7 +310,7 @@ static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam,
case DM_APPENDTOLOG:
if (opt.PluginSupportEnabled) {
- //get length of text now before things can get added...
+ // get length of text now before things can get added...
GETTEXTLENGTHEX gtl;
gtl.codepage = 1200;
gtl.flags = GTL_PRECISE | GTL_NUMCHARS;
@@ -360,29 +325,27 @@ static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam,
switch (uMsg) {
case WM_DESTROY:
- WaitForSingleObject(g_hMutex, 2000);
{
+ mir_cslock lck(csHook);
int ind = g_MsgWndList.getIndex((MsgWndData*)&hwnd);
if (ind != -1) {
delete g_MsgWndList[ind];
g_MsgWndList.remove(ind);
}
}
- ReleaseMutex(g_hMutex);
break;
case WM_SIZE:
if (dat->doSmileyButton) {
RECT rect = dat->CalcSmileyButtonPos();
- SetWindowPos(dat->hSmlButton, NULL, rect.left, rect.top,
- 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
+ SetWindowPos(dat->hSmlButton, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
break;
case DM_APPENDTOLOG:
if (dat->doSmileyReplace) {
- SmileyPackCType* smcp;
- SmileyPackType* SmileyPack = GetSmileyPack(dat->ProtocolName, dat->hContact, &smcp);
+ SmileyPackCType *smcp;
+ SmileyPackType *SmileyPack = GetSmileyPack(dat->ProtocolName, dat->hContact, &smcp);
if (SmileyPack != NULL) {
const CHARRANGE sel = { dat->idxLastChar, LONG_MAX };
ReplaceSmileys(dat->REdit, SmileyPack, smcp, sel, false, false, false);
@@ -392,8 +355,8 @@ static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam,
case DM_REMAKELOG:
if (dat->doSmileyReplace) {
- SmileyPackCType* smcp;
- SmileyPackType* SmileyPack = GetSmileyPack(dat->ProtocolName, dat->hContact, &smcp);
+ SmileyPackCType *smcp;
+ SmileyPackType *SmileyPack = GetSmileyPack(dat->ProtocolName, dat->hContact, &smcp);
if (SmileyPack != NULL) {
static const CHARRANGE sel = { 0, LONG_MAX };
ReplaceSmileys(dat->REdit, SmileyPack, smcp, sel, false, false, false);
@@ -430,8 +393,7 @@ static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam,
if (LOWORD(wParam) == MI_IDC_ADD && HIWORD(wParam) == BN_CLICKED && dat->doSmileyButton) {
RECT rect = dat->CalcSmileyButtonPos();
- SetWindowPos(dat->hSmlButton, NULL, rect.left, rect.top,
- 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
+ SetWindowPos(dat->hSmlButton, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
break;
}
@@ -444,7 +406,7 @@ static int MsgDlgHook(WPARAM, LPARAM lParam)
const MessageWindowEventData *wndEvtData = (MessageWindowEventData*)lParam;
switch (wndEvtData->uType) {
case MSG_WINDOW_EVT_OPENING:
- MsgWndDetect(wndEvtData->hwndWindow, wndEvtData->hContact, NULL);
+ MsgWndDetect(wndEvtData->hwndWindow, wndEvtData->hContact);
if (wndEvtData->cbSize >= sizeof(MessageWindowEventData)) {
SetRichOwnerCallback(wndEvtData->hwndWindow, wndEvtData->hwndInput, wndEvtData->hwndLog);
@@ -477,45 +439,15 @@ static int MsgDlgHook(WPARAM, LPARAM lParam)
return 0;
}
-
-//global subclass function for all dialogs
-static LRESULT CALLBACK MsgDlgHookProcPre(int code, WPARAM wParam, LPARAM lParam)
-{
- const CWPSTRUCT *msg = (CWPSTRUCT*)lParam;
-
- if (code == HC_ACTION && msg->message == WM_INITDIALOG)
- MsgWndDetect(msg->hwnd, NULL, (msgData*)msg->lParam);
-
- return CallNextHookEx(g_hMessageHookPre, code, wParam, lParam);
-}
-
-
void InstallDialogBoxHook(void)
{
- g_hMutex = CreateMutex(NULL, FALSE, NULL);
- g_hHookMsgWnd = HookEvent(ME_MSG_WINDOWEVENT, MsgDlgHook);
-
- // Hook message API
- if (g_hHookMsgWnd == NULL)
- g_hMessageHookPre = SetWindowsHookEx(WH_CALLWNDPROC, MsgDlgHookProcPre,
- NULL, GetCurrentThreadId());
+ HookEvent(ME_MSG_WINDOWEVENT, MsgDlgHook);
}
-
void RemoveDialogBoxHook(void)
{
- if (g_hHookMsgWnd) UnhookEvent(g_hHookMsgWnd);
- if (g_hMessageHookPre) UnhookWindowsHookEx(g_hMessageHookPre);
-
- WaitForSingleObject(g_hMutex, 2000);
+ mir_cslock lck(csHook);
for (int i = 0; i < g_MsgWndList.getCount(); i++)
delete g_MsgWndList[i];
g_MsgWndList.destroy();
- ReleaseMutex(g_hMutex);
-
- if (g_hMutex) CloseHandle(g_hMutex);
-
- g_hHookMsgWnd = NULL;
- g_hMessageHookPre = NULL;
- g_hMutex = NULL;
}
diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp
index 64530d6941..bcb93a8720 100644
--- a/plugins/SmileyAdd/src/richcall.cpp
+++ b/plugins/SmileyAdd/src/richcall.cpp
@@ -35,40 +35,23 @@ struct RichEditOwnerData
HWND hwndLog;
};
-static int CompareRichEditData(const RichEditData* p1, const RichEditData* p2)
-{
- return (int)((INT_PTR)p1->hwnd - (INT_PTR)p2->hwnd);
-}
-
-static LIST<RichEditData> g_RichEditList(10, CompareRichEditData);
-
-static int CompareRichEditData(const RichEditOwnerData* p1, const RichEditOwnerData* p2)
-{
- return (int)((INT_PTR)p1->hwnd - (INT_PTR)p2->hwnd);
-}
-
-static LIST<RichEditOwnerData> g_RichEditOwnerList(5, CompareRichEditData);
+static LIST<RichEditData> g_RichEditList(10, HandleKeySortT);
+static LIST<RichEditOwnerData> g_RichEditOwnerList(5, HandleKeySortT);
static void SetPosition(HWND hwnd)
{
- IRichEditOle* RichEditOle;
+ CComPtr<IRichEditOle> RichEditOle;
if (SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
return;
- ITextDocument* TextDocument;
- if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK) {
- RichEditOle->Release();
+ CComPtr<ITextDocument> TextDocument;
+ if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK)
return;
- }
// retrieve text range
- ITextRange* TextRange;
- if (TextDocument->Range(0, 0, &TextRange) != S_OK) {
- TextDocument->Release();
- RichEditOle->Release();
+ CComPtr<ITextRange> TextRange;
+ if (TextDocument->Range(0, 0, &TextRange) != S_OK)
return;
- }
- TextDocument->Release();
int objectCount = RichEditOle->GetObjectCount();
for (int i = objectCount - 1; i >= 0; i--) {
@@ -76,14 +59,16 @@ static void SetPosition(HWND hwnd)
reObj.cbStruct = sizeof(REOBJECT);
HRESULT hr = RichEditOle->GetObject(i, &reObj, REO_GETOBJ_POLEOBJ);
- if (FAILED(hr)) continue;
+ if (FAILED(hr))
+ continue;
- ISmileyBase *igsc = NULL;
+ CComPtr<ISmileyBase> igsc;
if (reObj.clsid == CLSID_NULL)
reObj.poleobj->QueryInterface(IID_ISmileyAddSmiley, (void**)&igsc);
reObj.poleobj->Release();
- if (igsc == NULL) continue;
+ if (igsc == NULL)
+ continue;
TextRange->SetRange(reObj.cp, reObj.cp);
@@ -107,15 +92,12 @@ static void SetPosition(HWND hwnd)
else rect.top = -1;
igsc->SetPosition(hwnd, &rect);
- igsc->Release();
}
- TextRange->Release();
- RichEditOle->Release();
}
static void SetTooltip(long x, long y, HWND hwnd, RichEditData* rdt)
{
- TCHAR* smltxt;
+ TCHAR *smltxt;
int needtip = CheckForTip(x, y, hwnd, &smltxt);
if (needtip == rdt->tipActive)
return;
@@ -314,15 +296,13 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
bool SetRichCallback(HWND hwnd, MCONTACT hContact, bool subany, bool subnew)
{
- RichEditData* rdt = g_RichEditList.find((RichEditData*)&hwnd);
+ RichEditData *rdt = g_RichEditList.find((RichEditData*)&hwnd);
if (rdt == NULL) {
- IRichEditOle* RichEditOle;
+ CComPtr<IRichEditOle> RichEditOle;
if (SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
return false;
- RichEditOle->Release();
rdt = new RichEditData;
-
rdt->hwnd = hwnd;
rdt->hContact = hContact;
rdt->inputarea = (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) == 0;
@@ -407,7 +387,7 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara
void SetRichOwnerCallback(HWND hwnd, HWND hwndInput, HWND hwndLog)
{
- RichEditOwnerData* rdto = g_RichEditOwnerList.find((RichEditOwnerData*)&hwnd);
+ RichEditOwnerData *rdto = g_RichEditOwnerList.find((RichEditOwnerData*)&hwnd);
if (rdto == NULL) {
rdto = new RichEditOwnerData;
rdto->hwnd = hwnd;
@@ -421,8 +401,10 @@ void SetRichOwnerCallback(HWND hwnd, HWND hwndInput, HWND hwndLog)
mir_subclassWindow(hwnd, RichEditOwnerSubclass);
}
else {
- if (rdto->hwndInput == NULL) rdto->hwndInput = hwndInput;
- if (rdto->hwndLog == NULL) rdto->hwndLog = hwndLog;
+ if (rdto->hwndInput == NULL)
+ rdto->hwndInput = hwndInput;
+ if (rdto->hwndLog == NULL)
+ rdto->hwndLog = hwndLog;
}
}
diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp
index 4e5534bbbc..1fee508cd0 100644
--- a/plugins/SmileyAdd/src/smileyroutines.cpp
+++ b/plugins/SmileyAdd/src/smileyroutines.cpp
@@ -183,47 +183,34 @@ void UpdateSelection(CHARRANGE& sel, int pos, int dif)
}
}
-void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const CHARRANGE& sel,
- bool useHidden, bool ignoreLast, bool unFreeze, bool fireView)
+void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const CHARRANGE& sel, bool useHidden, bool ignoreLast, bool unFreeze, bool fireView)
{
- IRichEditOle* RichEditOle = NULL;
+ CComPtr<IRichEditOle> RichEditOle;
if (SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
return;
if (RichEditOle == NULL)
return;
- ITextDocument* TextDocument = NULL;
- if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK) {
- RichEditOle->Release();
+ CComPtr<ITextDocument> TextDocument;
+ if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK)
return;
- }
long cnt;
if (smp == NULL && smcp == NULL) {
- if (unFreeze) TextDocument->Unfreeze(&cnt);
- TextDocument->Release();
- RichEditOle->Release();
+ if (unFreeze)
+ TextDocument->Unfreeze(&cnt);
return;
}
// retrieve text range
- ITextRange* TextRange;
- if (TextDocument->Range(sel.cpMin, sel.cpMax, &TextRange) != S_OK) {
- TextDocument->Release();
- RichEditOle->Release();
+ CComPtr<ITextRange> TextRange;
+ if (TextDocument->Range(sel.cpMin, sel.cpMax, &TextRange) != S_OK)
return;
- }
// retrieve text to parse for smileys
BSTR btxt = 0;
- if (TextRange->GetText(&btxt) != S_OK) {
- TextRange->Release();
- TextDocument->Release();
- RichEditOle->Release();
+ if (TextRange->GetText(&btxt) != S_OK)
return;
- } // fallthrough
-
- TextRange->Release();
SmileysQueueType smllist;
LookupAllSmileys(smp, smcp, btxt, smllist, false);
@@ -243,10 +230,10 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const
bool rdo = (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) != 0;
if (rdo) SendMessage(hwnd, EM_SETREADONLY, FALSE, 0);
- ITextSelection* TextSelection;
+ CComPtr<ITextSelection> TextSelection;
TextDocument->GetSelection(&TextSelection);
- ITextFont *TextFont;
+ CComPtr<ITextFont> TextFont;
TextSelection->GetFont(&TextFont);
//save selection
@@ -305,9 +292,10 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const
continue;
}
- SmileyType* sml = smllist[j].sml;
- SmileyCType* smlc = smllist[j].smlc;
- if (sml == NULL && smlc == NULL) continue;
+ SmileyType *sml = smllist[j].sml;
+ SmileyCType *smlc = smllist[j].smlc;
+ if (sml == NULL && smlc == NULL)
+ continue;
// Select text analyze
TextSelection->SetRange(smlpos.cpMin, smlpos.cpMax);
@@ -439,53 +427,46 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const
SysFreeString(spaceb);
TextSelection->SetRange(oldSel.cpMin, oldSel.cpMax);
- if (rdo) SendMessage(hwnd, EM_SETREADONLY, TRUE, 0);
-
- TextFont->Release();
- TextSelection->Release();
+ if (rdo)
+ SendMessage(hwnd, EM_SETREADONLY, TRUE, 0);
ReleaseDC(hwnd, hdc);
TextDocument->Unfreeze(&cnt);
- if (cnt == 0) UpdateWindow(hwnd);
+ if (cnt == 0)
+ UpdateWindow(hwnd);
}
if (unFreeze) {
TextDocument->Unfreeze(&cnt);
- if (cnt == 0) UpdateWindow(hwnd);
+ if (cnt == 0)
+ UpdateWindow(hwnd);
}
-
- TextDocument->Release();
- RichEditOle->Release();
}
-void ReplaceSmileysWithText(HWND hwnd, CHARRANGE& sel, bool keepFrozen)
+void ReplaceSmileysWithText(HWND hwnd, CHARRANGE &sel, bool keepFrozen)
{
- IRichEditOle* RichEditOle = NULL;
+ CComPtr<IRichEditOle> RichEditOle = NULL;
if (SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
return;
if (RichEditOle == NULL)
return;
- ITextDocument* TextDocument;
- if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK) {
- RichEditOle->Release();
+ CComPtr<ITextDocument> TextDocument;
+ if (RichEditOle->QueryInterface(IID_ITextDocument, (void**)&TextDocument) != S_OK)
return;
- }
// retrieve text range
- ITextRange* TextRange;
- if (TextDocument->Range(0, 0, &TextRange) != S_OK) {
- TextDocument->Release();
- RichEditOle->Release();
+ CComPtr<ITextRange> TextRange;
+ if (TextDocument->Range(0, 0, &TextRange) != S_OK)
return;
- }
long cnt;
TextDocument->Freeze(&cnt);
bool rdo = (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) != 0;
- if (rdo) SendMessage(hwnd, EM_SETREADONLY, FALSE, 0);
+ if (rdo)
+ SendMessage(hwnd, EM_SETREADONLY, FALSE, 0);
CHARRANGE oldSel;
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&oldSel);
@@ -528,10 +509,8 @@ void ReplaceSmileysWithText(HWND hwnd, CHARRANGE& sel, bool keepFrozen)
}
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&oldSel);
- if (rdo) SendMessage(hwnd, EM_SETREADONLY, TRUE, 0);
- if (!keepFrozen) TextDocument->Unfreeze(&cnt);
-
- TextRange->Release();
- TextDocument->Release();
- RichEditOle->Release();
+ if (rdo)
+ SendMessage(hwnd, EM_SETREADONLY, TRUE, 0);
+ if (!keepFrozen)
+ TextDocument->Unfreeze(&cnt);
}
diff --git a/plugins/SmileyAdd/src/smileyroutines.h b/plugins/SmileyAdd/src/smileyroutines.h
index f02f7cbd2d..3b0a08d60e 100644
--- a/plugins/SmileyAdd/src/smileyroutines.h
+++ b/plugins/SmileyAdd/src/smileyroutines.h
@@ -34,13 +34,10 @@ typedef SMOBJLIST<ReplaceSmileyType> SmileysQueueType;
-void LookupAllSmileys(SmileyPackType* smileyPack, SmileyPackCType* smileyCPack, const TCHAR* lpstrText,
- SmileysQueueType& smllist, const bool firstOnly);
-void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const CHARRANGE& sel,
- bool useHidden, bool ignoreLast, bool unFreeze, bool fireView = 0);
+void LookupAllSmileys(SmileyPackType* smileyPack, SmileyPackCType* smileyCPack, const TCHAR* lpstrText, SmileysQueueType& smllist, const bool firstOnly);
+void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const CHARRANGE& sel, bool useHidden, bool ignoreLast, bool unFreeze, bool fireView = 0);
void ReplaceSmileysWithText(HWND hwnd, CHARRANGE& sel, bool keepFrozen);
-void FindSmileyInText(SmileyPackType* smp, const TCHAR* str,
- unsigned& first, unsigned& size, SmileyType** index);
+void FindSmileyInText(SmileyPackType* smp, const TCHAR* str, unsigned& first, unsigned& size, SmileyType** index);
SmileyType* FindButtonSmiley(SmileyPackType* smp);
#endif
diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h
index 9cedd2947c..66e7f9f93a 100644
--- a/plugins/SmileyAdd/src/stdafx.h
+++ b/plugins/SmileyAdd/src/stdafx.h
@@ -30,17 +30,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define _CRTDBG_MAP_ALLOC
#include <windows.h>
+#include <richedit.h>
+#include <richole.h>
+#include <commctrl.h>
+#include <gdiplus.h>
+#include <tom.h>
+#include <msapi\comptr.h>
+
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
-#include <gdiplus.h>
-#include <m_clist.h>
-#include <commctrl.h>
-#include <richedit.h>
#include <delayimp.h>
-#include <richole.h>
-#include <tom.h>
+
#include <vector>
#include <map>
#include <algorithm>
@@ -49,6 +51,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <win2k.h>
#include <newpluginapi.h>
+#include <m_clist.h>
#include <m_langpack.h>
#include <m_options.h>
#include <m_protosvc.h>