summaryrefslogtreecommitdiff
path: root/plugins/SmileyAdd
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-03-04 07:23:42 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-03-04 07:23:42 +0000
commit66cb770a982a2502456d10d73838df2b7239fd89 (patch)
treefc419dde94a9be3ebe8f2266ff46feb90d2bcbec /plugins/SmileyAdd
parentbc256df33a57e585367edffe33d3e58d53f82ce8 (diff)
new subclassing functions applied to all plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@3880 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SmileyAdd')
-rw-r--r--plugins/SmileyAdd/src/dlgboxsubclass.cpp26
-rw-r--r--plugins/SmileyAdd/src/richcall.cpp161
-rw-r--r--plugins/SmileyAdd/src/smileyroutines.cpp13
3 files changed, 76 insertions, 124 deletions
diff --git a/plugins/SmileyAdd/src/dlgboxsubclass.cpp b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
index eee8db0025..9184bf10ab 100644
--- a/plugins/SmileyAdd/src/dlgboxsubclass.cpp
+++ b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
@@ -61,7 +61,6 @@ public:
mutable HBITMAP hSmlBmp;
mutable HICON hSmlIco;
int idxLastChar;
- WNDPROC wpOrigWndProc;
HANDLE hContact;
bool doSmileyReplace;
bool doSmileyButton;
@@ -87,7 +86,6 @@ public:
OldButtonPlace = false;
isSplit = false;
isSend = false;
- wpOrigWndProc = NULL;
}
MsgWndData(const MsgWndData &dsb)
@@ -333,8 +331,7 @@ static void MsgWndDetect(HWND hwndDlg, HANDLE hContact, msgData* datm)
WaitForSingleObject(g_hMutex, 2000);
MsgWndData* msgwnd = g_MsgWndList.find((MsgWndData*)&hwndDlg);
- if (msgwnd == NULL)
- {
+ if (msgwnd == NULL) {
msgwnd = new MsgWndData(dat);
g_MsgWndList.insert(msgwnd);
}
@@ -342,11 +339,11 @@ static void MsgWndDetect(HWND hwndDlg, HANDLE hContact, msgData* datm)
msgwnd = NULL;
ReleaseMutex(g_hMutex);
- if (msgwnd != NULL)
- {
- msgwnd->wpOrigWndProc = (WNDPROC)SetWindowLongPtr(hwndDlg, GWLP_WNDPROC, (LONG_PTR)MessageDlgSubclass);
+ if (msgwnd != NULL) {
+ mir_subclassWindow(hwndDlg, MessageDlgSubclass);
msgwnd->CreateSmileyButton();
- if (hContact == NULL) SetRichCallback(msgwnd->REdit, msgwnd->hContact, true, true);
+ if (hContact == NULL)
+ SetRichCallback(msgwnd->REdit, msgwnd->hContact, true, true);
}
}
}
@@ -377,19 +374,16 @@ static LRESULT CALLBACK MessageDlgSubclass(HWND hwnd, UINT uMsg, WPARAM wParam,
break;
}
- LRESULT result = CallWindowProc(dat->wpOrigWndProc, hwnd, uMsg, wParam, lParam);
-
- if (!opt.PluginSupportEnabled) return result;
+ LRESULT result = mir_callNextSubclass(hwnd, MessageDlgSubclass, uMsg, wParam, lParam);
+ if (!opt.PluginSupportEnabled)
+ return result;
- switch(uMsg)
- {
+ switch(uMsg) {
case WM_DESTROY:
WaitForSingleObject(g_hMutex, 2000);
- SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)dat->wpOrigWndProc);
{
int ind = g_MsgWndList.getIndex((MsgWndData*)&hwnd);
- if ( ind != -1 )
- {
+ if ( ind != -1 ) {
delete g_MsgWndList[ind];
g_MsgWndList.remove(ind);
}
diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp
index d9b9123c48..463276baf4 100644
--- a/plugins/SmileyAdd/src/richcall.cpp
+++ b/plugins/SmileyAdd/src/richcall.cpp
@@ -30,7 +30,6 @@ typedef struct
{
HWND hwnd;
HANDLE hContact;
- WNDPROC wpOrigWndProc;
HWND hToolTip;
int tipActive;
bool inputarea;
@@ -40,7 +39,6 @@ typedef struct
typedef struct
{
HWND hwnd;
- WNDPROC wpOrigWndProc;
HWND hwndInput;
HWND hwndLog;
} RichEditOwnerData;
@@ -217,10 +215,7 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
CHARRANGE sel;
- WNDPROC wpOrigWndProc = rdt->wpOrigWndProc;
-
- switch(uMsg)
- {
+ switch(uMsg) {
case WM_DESTROY:
CloseRichCallback(hwnd, false);
break;
@@ -237,8 +232,7 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
case EM_STREAMOUT:
if (wParam & SFF_SELECTION)
SmileyToTextCutPrep(rdt);
- else
- {
+ else {
sel = allsel;
ReplaceContactSmileysWithText(rdt, sel, true);
}
@@ -264,10 +258,9 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
break;
}
- LRESULT result = CallWindowProc(wpOrigWndProc, hwnd, uMsg, wParam, lParam);
+ LRESULT result = mir_callNextSubclass(hwnd, RichEditSubclass, uMsg, wParam, lParam);
- switch(uMsg)
- {
+ switch(uMsg) {
case WM_DESTROY:
CloseRichCallback(hwnd, true);
break;
@@ -296,16 +289,12 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
case WM_KEYDOWN:
if ((wParam == 'C' || wParam == VK_INSERT) && (GetKeyState(VK_CONTROL) & 0x8000))
- {
SmileyToTextCutRest(rdt);
- }
- else if ((wParam == 'X' && (GetKeyState(VK_CONTROL) & 0x8000)) ||
- (wParam == VK_DELETE && (GetKeyState(VK_SHIFT) & 0x8000)))
- {
+
+ else if ((wParam == 'X' && (GetKeyState(VK_CONTROL) & 0x8000)) || (wParam == VK_DELETE && (GetKeyState(VK_SHIFT) & 0x8000)))
SmileyToTextCutRest(rdt);
- }
- else if (wParam == VK_TAB && ((GetKeyState(VK_CONTROL) | GetKeyState(VK_SHIFT)) & 0x8000) == 0)
- {
+
+ else if (wParam == VK_TAB && ((GetKeyState(VK_CONTROL) | GetKeyState(VK_SHIFT)) & 0x8000) == 0) {
sel.cpMax = LONG_MAX;
bool hascont = rdt->hContact != NULL;
ReplaceContactSmileys(rdt, sel, false, hascont);
@@ -325,27 +314,20 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
if (wParam > ' ' && opt.EnforceSpaces)
break;
- if (wParam == 0x16)
- {
+ if (wParam == 0x16) {
ReplaceContactSmileys(rdt, allsel, false, false);
break;
}
if (opt.DCursorSmiley)
- {
ReplaceContactSmileys(rdt, allsel, true, true);
- }
- else
- {
- if (wParam >= ' ' || wParam == '\n' || wParam == '\r')
- {
- SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
- sel.cpMin = max(sel.cpMin - 20, 0);
- sel.cpMax += 20;
+ else if (wParam >= ' ' || wParam == '\n' || wParam == '\r') {
+ SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
+ sel.cpMin = max(sel.cpMin - 20, 0);
+ sel.cpMax += 20;
- ReplaceContactSmileysWithText(rdt, sel, true);
- ReplaceContactSmileys(rdt, sel, false, true);
- }
+ ReplaceContactSmileysWithText(rdt, sel, true);
+ ReplaceContactSmileys(rdt, sel, false, true);
}
break;
@@ -369,13 +351,9 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP
void CloseRichCallback(HWND hwnd, bool force)
{
int ind = g_RichEditList.getIndex((RichEditData*)&hwnd);
- if ( ind != -1 )
- {
+ if ( ind != -1 ) {
RichEditData* rdt = g_RichEditList[ind];
- bool richsub = GetWindowLongPtr(hwnd, GWLP_WNDPROC) == (LONG_PTR)RichEditSubclass;
- if (richsub) SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)rdt->wpOrigWndProc);
- if (richsub || force)
- {
+ if (force) {
if (rdt->hToolTip) DestroyWindow(rdt->hToolTip);
delete rdt;
g_RichEditList.remove(ind);
@@ -386,8 +364,7 @@ void CloseRichCallback(HWND hwnd, bool force)
bool SetRichCallback(HWND hwnd, HANDLE hContact, bool subany, bool subnew)
{
RichEditData* rdt = g_RichEditList.find((RichEditData*)&hwnd);
- if (rdt == NULL)
- {
+ if (rdt == NULL) {
IRichEditOle* RichEditOle;
if (SendMessage(hwnd, EM_GETOLEINTERFACE, 0, (LPARAM)&RichEditOle) == 0)
return false;
@@ -400,18 +377,18 @@ bool SetRichCallback(HWND hwnd, HANDLE hContact, bool subany, bool subnew)
rdt->inputarea = (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) == 0;
rdt->dontReplace = false;
rdt->tipActive = -1;
- rdt->wpOrigWndProc = NULL;
rdt->hToolTip = NULL;
g_RichEditList.insert(rdt);
if (subnew)
- rdt->wpOrigWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)RichEditSubclass);
+ mir_subclassWindow(hwnd, RichEditSubclass);
}
- else
- {
- if (hContact && !rdt->hContact) rdt->hContact = hContact;
- if (subany && rdt->wpOrigWndProc == NULL)
- rdt->wpOrigWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)RichEditSubclass);
+ else {
+ if (hContact && !rdt->hContact)
+ rdt->hContact = hContact;
+
+ if (subany)
+ mir_subclassWindow(hwnd, RichEditSubclass);
}
return true;
}
@@ -419,17 +396,21 @@ bool SetRichCallback(HWND hwnd, HANDLE hContact, bool subany, bool subnew)
static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RichEditOwnerData* rdto = g_RichEditOwnerList.find((RichEditOwnerData*)&hwnd);
- if (rdto == NULL) return 0;
-
- WNDPROC wpOrigWndProc = rdto->wpOrigWndProc;
+ if (rdto == NULL)
+ return 0;
- switch(uMsg)
- {
+ switch(uMsg) {
case WM_DESTROY:
- {
+ if ( !Miranda_Terminated()) {
+ CHARRANGE sel = allsel;
+ if (rdto->hwndInput)
+ ReplaceSmileysWithText(rdto->hwndInput, sel, false);
+ if (rdto->hwndLog)
+ ReplaceSmileysWithText(rdto->hwndLog, sel, false);
+ }
+ else {
RichEditData* rdt = g_RichEditList.find((RichEditData*)&rdto->hwndInput);
- if (rdt && (!rdt->inputarea || opt.InputSmileys))
- {
+ if (rdt && (!rdt->inputarea || opt.InputSmileys)) {
CHARRANGE sel = allsel;
rdt->dontReplace = true;
ReplaceSmileysWithText(rdt->hwnd, sel, false);
@@ -438,13 +419,10 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara
CloseRichOwnerCallback(hwnd, false);
break;
-
case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624)
- {
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624) {
RichEditData* rdt = g_RichEditList.find((RichEditData*)&rdto->hwndInput);
- if (rdt && (!rdt->inputarea || opt.InputSmileys))
- {
+ if (rdt && (!rdt->inputarea || opt.InputSmileys)) {
rdt->dontReplace = true;
CHARRANGE sel = allsel;
ReplaceSmileysWithText(rdt->hwnd, sel, false);
@@ -453,20 +431,17 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara
break;
}
- LRESULT result = CallWindowProc(wpOrigWndProc, hwnd, uMsg, wParam, lParam);
+ LRESULT result = mir_callNextSubclass(hwnd, RichEditOwnerSubclass, uMsg, wParam, lParam);
- switch(uMsg)
- {
+ switch(uMsg) {
case WM_DESTROY:
CloseRichOwnerCallback(hwnd, true);
break;
case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624) // && lParam == 0)
- {
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624) {
RichEditData* rdt = g_RichEditList.find((RichEditData*)&rdto->hwndInput);
- if (rdt)
- {
+ if (rdt) {
CHARRANGE sel = allsel;
if (!result) ReplaceContactSmileys(rdt, sel, false, false);
rdt->dontReplace = false;
@@ -480,41 +455,32 @@ static LRESULT CALLBACK RichEditOwnerSubclass(HWND hwnd, UINT uMsg, WPARAM wPara
void CloseRichOwnerCallback(HWND hwnd, bool force)
{
int ind = g_RichEditOwnerList.getIndex((RichEditOwnerData*)&hwnd);
- if ( ind != -1 )
- {
- RichEditOwnerData* rdto = g_RichEditOwnerList[ind];
- bool richsub = GetWindowLongPtr(hwnd, GWLP_WNDPROC) == (LONG_PTR)RichEditOwnerSubclass;
- if (richsub)
- {
- SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)rdto->wpOrigWndProc);
- rdto->wpOrigWndProc = NULL;
- }
- if (force)
- {
- CloseRichCallback(rdto->hwndInput, true);
- CloseRichCallback(rdto->hwndLog, true);
+ if (ind == -1)
+ return;
- delete rdto;
- g_RichEditOwnerList.remove(ind);
- }
+ RichEditOwnerData* rdto = g_RichEditOwnerList[ind];
+ if (rdto && force) {
+ CloseRichCallback(rdto->hwndInput, true);
+ CloseRichCallback(rdto->hwndLog, true);
+
+ delete rdto;
+ g_RichEditOwnerList.remove(ind);
}
}
void SetRichOwnerCallback(HWND hwnd, HWND hwndInput, HWND hwndLog)
{
RichEditOwnerData* rdto = g_RichEditOwnerList.find((RichEditOwnerData*)&hwnd);
- if (rdto == NULL)
- {
+ if (rdto == NULL) {
rdto = new RichEditOwnerData;
-
rdto->hwnd = hwnd;
rdto->hwndInput = hwndInput;
rdto->hwndLog = hwndLog;
- rdto->wpOrigWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)RichEditOwnerSubclass);
g_RichEditOwnerList.insert(rdto);
+
+ mir_subclassWindow(hwnd, RichEditOwnerSubclass);
}
- else
- {
+ else {
if (rdto->hwndInput == NULL) rdto->hwndInput = hwndInput;
if (rdto->hwndLog == NULL) rdto->hwndLog = hwndLog;
}
@@ -522,25 +488,18 @@ void SetRichOwnerCallback(HWND hwnd, HWND hwndInput, HWND hwndLog)
void ProcessAllInputAreas(bool restoreText)
{
- for (int i=g_RichEditList.getCount(); i--; )
- {
+ for (int i=g_RichEditList.getCount(); i--; ) {
RichEditData* rdt = g_RichEditList[i];
- if (rdt->inputarea)
- {
- if (restoreText)
- {
+ if (rdt->inputarea) {
+ if (restoreText) {
CHARRANGE sel = allsel;
ReplaceContactSmileysWithText(rdt, sel, false);
}
- else
- {
- ReplaceContactSmileys(rdt, allsel, false, false);
- }
+ else ReplaceContactSmileys(rdt, allsel, false, false);
}
}
}
-
void RichEditData_Destroy(void)
{
int i;
diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp
index 5175309d1b..88efdf2367 100644
--- a/plugins/SmileyAdd/src/smileyroutines.cpp
+++ b/plugins/SmileyAdd/src/smileyroutines.cpp
@@ -221,14 +221,11 @@ 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)
{
-/*
- LARGE_INTEGER freq, strt, end;
- QueryPerformanceFrequency(&freq);
- QueryPerformanceCounter(&strt);
-*/
- IRichEditOle* RichEditOle;
+ 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)
@@ -534,9 +531,11 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType* smp, SmileyPackCType* smcp, const
void ReplaceSmileysWithText(HWND hwnd, CHARRANGE& sel, bool keepFrozen)
{
- IRichEditOle* RichEditOle;
+ 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)