summaryrefslogtreecommitdiff
path: root/yapp/popwin.cpp
diff options
context:
space:
mode:
author(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2010-04-25 15:57:51 +0000
committer(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2010-04-25 15:57:51 +0000
commit5ac26cff397836222eb8d51d866890f96321c601 (patch)
tree7ab4ff3ed3c36675df3d2da5a912311df499a8fa /yapp/popwin.cpp
parent8e4bd51aa53343a76b1ddc9c7e47f3d56cb24437 (diff)
Optimizations, removed redundant code, better compatibility with popup+
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@512 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'yapp/popwin.cpp')
-rw-r--r--yapp/popwin.cpp56
1 files changed, 35 insertions, 21 deletions
diff --git a/yapp/popwin.cpp b/yapp/popwin.cpp
index 010da7a..557a9cf 100644
--- a/yapp/popwin.cpp
+++ b/yapp/popwin.cpp
@@ -2,7 +2,6 @@
#include "popwin.h"
#include "message_pump.h"
#include "options.h"
-#include "str_utils.h"
HMODULE hUserDll;
BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = 0;
@@ -16,6 +15,19 @@ BOOL (WINAPI *MyGetMonitorInfo)(HMONITOR hMonitor, LPMONITORINFO mi) = 0;
DWORD pop_start_x, pop_start_y;
int global_mouse_in = 0;
+void trimW(wchar_t *str) {
+ int len = (int)wcslen(str), pos;
+ // trim whitespace (e.g. from OTR detection)
+ for(pos = len - 1; pos >= 0; pos--) {
+ if(str[pos] == L' ' || str[pos] == L'\t' || str[pos] == L'\r' || str[pos] == L'\n') str[pos] = 0;
+ else break;
+ }
+
+ // remove tabs
+ for(pos = len - 1; pos >= 0; pos--)
+ if(str[pos] == L'\t') str[pos] = L' ';
+}
+
void SetStartValues() {
RECT wa_rect;
if(options.use_mim_monitor && MyMonitorFromRect && MyGetMonitorInfo) {
@@ -80,7 +92,7 @@ void RepositionWindows() {
void AddWindowToStack(HWND hwnd) {
SetStartValues();
- HWNDStackNode *new_node = (HWNDStackNode *)malloc(sizeof(HWNDStackNode));
+ HWNDStackNode *new_node = (HWNDStackNode *)mir_alloc(sizeof(HWNDStackNode));
new_node->hwnd = hwnd;
new_node->next = hwnd_stack_top;
hwnd_stack_top = new_node;
@@ -112,7 +124,7 @@ void RemoveWindowFromStack(HWND hwnd) {
} else {
hwnd_stack_top = current->next;
}
- free(current);
+ mir_free(current);
stack_size--;
break;
}
@@ -161,7 +173,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_CREATE:
{
CREATESTRUCT *cs = (CREATESTRUCT *)lParam;
- pwd = (PopupWindowData *)malloc(sizeof(PopupWindowData));
+ pwd = (PopupWindowData *)mir_alloc(sizeof(PopupWindowData));
pd = (PopupData *)cs->lpCreateParams;
pwd->pd = pd;
pwd->hNotify = 0;
@@ -523,10 +535,12 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
SendMessage(hwnd, PM_DIENOTIFY, 0, 0);
- if(pd && pd->pwzTitle) free(pd->pwzTitle);
- if(pd && pd->pwzText) free(pd->pwzText);
- if(pd) free(pd);
- free(pwd); pwd = 0; pd = 0;
+ if (pd) {
+ mir_free(pd->pwzTitle);
+ mir_free(pd->pwzText);
+ mir_free(pd);
+ }
+ mir_free(pwd); pwd = 0; pd = 0;
SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
break;
@@ -565,12 +579,12 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
return TRUE;
case PUM_SETTEXT:
{
- if(pd->pszText) free(pd->pszText);
+ mir_free(pd->pszText);
if(lParam)
- pd->pwzText = wcsdup((wchar_t *)lParam);
+ pd->pwzText = mir_wstrdup((wchar_t *)lParam);
else
- pd->pwzText = 0;
- // free((void *)lParam); // freed in message pump in case the window has gone
+ pd->pwzText = NULL;
+ // mir_free((void *)lParam); // freed in message pump in case the window has gone
InvalidateRect(hwnd, 0, TRUE);
RepositionWindows();
}
@@ -669,9 +683,11 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case PUM_CHANGE:
{
KillTimer(hwnd, ID_CLOSETIMER);
- if(pd && pd->pwzTitle) free(pd->pwzTitle);
- if(pd && pd->pwzText) free(pd->pwzText);
- if(pd) free(pd);
+ if (pd) {
+ mir_free(pd->pwzTitle);
+ mir_free(pd->pwzText);
+ mir_free(pd);
+ }
pwd->pd = pd = (PopupData *)lParam;
if(pd->timeout != -1) {
@@ -703,14 +719,12 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
pd->hIcon = (HICON)MNotifyGetDWord(pwd->hNotify, NFOPT_ICON, 0);
const wchar_t *swzName = MNotifyGetWString(pwd->hNotify, NFOPT_TITLEW, 0);
- if(pd->pwzTitle) free(pd->pwzTitle);
- if(swzName) pd->pwzTitle = wcsdup(swzName);
- else pd->pwzTitle = 0;
+ mir_free(pd->pwzTitle);
+ pd->pwzTitle = mir_wstrdup(swzName);
const wchar_t *swzText = MNotifyGetWString(pwd->hNotify, NFOPT_TEXTW, 0);
- if(pd->pwzText) free(pd->pwzText);
- if(swzText) pd->pwzText = wcsdup(swzText);
- else pd->pwzText= 0;
+ mir_free(pd->pwzText);
+ pd->pwzText = mir_wstrdup(swzText);
InvalidateRect(hwnd, 0, TRUE);
RepositionWindows();