diff options
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/ImageDataObject.cpp | 140 | ||||
-rw-r--r-- | plugins/TabSRMM/src/modplus.cpp | 88 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msglog.cpp | 85 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 8 | ||||
-rw-r--r-- | plugins/TabSRMM/src/stdafx.h | 6 | ||||
-rw-r--r-- | plugins/TabSRMM/src/templates.cpp | 147 |
6 files changed, 201 insertions, 273 deletions
diff --git a/plugins/TabSRMM/src/ImageDataObject.cpp b/plugins/TabSRMM/src/ImageDataObject.cpp index c7de9efd61..cefd6547cc 100644 --- a/plugins/TabSRMM/src/ImageDataObject.cpp +++ b/plugins/TabSRMM/src/ImageDataObject.cpp @@ -31,126 +31,48 @@ #include "stdafx.h"
-extern void ReleaseRichEditOle(IRichEditOle *ole)
-{
- ole->Release();
-}
-
-extern void ImageDataInsertBitmap(IRichEditOle *ole, HBITMAP hBm)
-{
- CImageDataObject::InsertBitmap(ole, hBm);
-}
-
-int CacheIconToBMP(TLogIcon *theIcon, HICON hIcon, COLORREF backgroundColor, int sizeX, int sizeY)
-{
- int IconSizeX = sizeX;
- int IconSizeY = sizeY;
-
- if ((IconSizeX == 0) || (IconSizeY == 0)) {
- Utils::getIconSize(hIcon, IconSizeX, IconSizeY);
- if (sizeX != 0)
- IconSizeX = sizeX;
- if (sizeY != 0)
- IconSizeY = sizeY;
- }
- RECT rc;
- BITMAPINFOHEADER bih = { 0 };
- int widthBytes;
- theIcon->hBkgBrush = CreateSolidBrush(backgroundColor);
- bih.biSize = sizeof(bih);
- bih.biBitCount = 24;
- bih.biPlanes = 1;
- bih.biCompression = BI_RGB;
- bih.biHeight = IconSizeY;
- bih.biWidth = IconSizeX;
- widthBytes = ((bih.biWidth * bih.biBitCount + 31) >> 5) * 4;
- rc.top = rc.left = 0;
- rc.right = bih.biWidth;
- rc.bottom = bih.biHeight;
- theIcon->hdc = GetDC(0);
- theIcon->hBmp = CreateCompatibleBitmap(theIcon->hdc, bih.biWidth, bih.biHeight);
- theIcon->hdcMem = CreateCompatibleDC(theIcon->hdc);
- theIcon->hoBmp = (HBITMAP)SelectObject(theIcon->hdcMem, theIcon->hBmp);
- FillRect(theIcon->hdcMem, &rc, theIcon->hBkgBrush);
- DrawIconEx(theIcon->hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
- SelectObject(theIcon->hdcMem, theIcon->hoBmp);
- return TRUE;
-}
-
-void DeleteCachedIcon(TLogIcon *theIcon)
-{
- DeleteDC(theIcon->hdcMem);
- DeleteObject(theIcon->hBmp);
- ReleaseDC(NULL, theIcon->hdc);
- DeleteObject(theIcon->hBkgBrush);
-}
-
// returns true on success, false on failure
bool CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap)
{
- SCODE sc;
- BITMAP bminfo;
-
// Get the image data object
- //
CImageDataObject *pods = new CImageDataObject;
- LPDATAOBJECT lpDataObject;
- pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject);
+ CComPtr<IDataObject> lpDataObject;
+ pods->QueryInterface(IID_IDataObject, (void**)&lpDataObject);
+ BITMAP bminfo;
GetObject(hBitmap, sizeof(bminfo), &bminfo);
pods->SetBitmap(hBitmap);
// Get the RichEdit container site
- //
- IOleClientSite *pOleClientSite;
+ CComPtr<IOleClientSite> pOleClientSite;
pRichEditOle->GetClientSite(&pOleClientSite);
- // Initialize a Storage Object
- //
- IStorage *pStorage;
-
- LPLOCKBYTES lpLockBytes = NULL;
- sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
- if (sc != S_OK) {
- pOleClientSite->Release();
+ CComPtr<ILockBytes> lpLockBytes;
+ if (FAILED(::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
return false;
- }
- sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
- STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage);
- if (sc != S_OK) {
- lpLockBytes = NULL;
- pOleClientSite->Release();
+
+ // Initialize a Storage Object
+ CComPtr<IStorage> pStorage;
+ if (FAILED(::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage)))
return false;
- }
+
// The final ole object which will be inserted in the richedit control
- //
- IOleObject *pOleObject;
- pOleObject = pods->GetOleObject(pOleClientSite, pStorage);
- if (pOleObject == NULL) {
- pStorage->Release();
- pOleClientSite->Release();
+ CComPtr<IOleObject> pOleObject = pods->GetOleObject(pOleClientSite, pStorage);
+ if (pOleObject == NULL)
return false;
- }
// all items are "contained" -- this makes our reference to this object
// weak -- which is needed for links to embedding silent update.
OleSetContainedObject(pOleObject, TRUE);
// Now Add the object to the RichEdit
- //
- REOBJECT reobject;
- memset(&reobject, 0, sizeof(REOBJECT));
- reobject.cbStruct = sizeof(REOBJECT);
-
CLSID clsid;
- sc = pOleObject->GetUserClassID(&clsid);
- if (sc != S_OK) {
- pOleObject->Release();
- pStorage->Release();
- pOleClientSite->Release();
+ if (FAILED(pOleObject->GetUserClassID(&clsid)))
return false;
- }
+ // Insert the bitmap at the current location in the richedit control
+ REOBJECT reobject = {};
+ reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = REO_CP_SELECTION;
reobject.dvaspect = DVASPECT_CONTENT;
@@ -158,25 +80,9 @@ bool CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) reobject.polesite = pOleClientSite;
reobject.pstg = pStorage;
reobject.dwFlags = bminfo.bmHeight <= 12 ? 0 : REO_BELOWBASELINE;
-
- // Insert the bitmap at the current location in the richedit control
- //
- sc = pRichEditOle->InsertObject(&reobject);
-
- // Release all unnecessary interfaces
- //
- pOleObject->Release();
- pOleClientSite->Release();
- lpLockBytes->Release();
- pStorage->Release();
- lpDataObject->Release();
- if (sc != S_OK)
- return false;
- else
- return true;
+ return pRichEditOle->InsertObject(&reobject) == S_OK;
}
-
void CImageDataObject::SetBitmap(HBITMAP hBitmap)
{
STGMEDIUM stgm;
@@ -194,14 +100,10 @@ void CImageDataObject::SetBitmap(HBITMAP hBitmap) this->SetData(&fm, &stgm, TRUE);
}
-
-IOleObject *CImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage)
+IOleObject* CImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage)
{
- SCODE sc;
IOleObject *pOleObject;
- sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT,
- &m_format, pOleClientSite, pStorage, (void **)& pOleObject);
- if (sc != S_OK)
- pOleObject = NULL;
+ if (FAILED(::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, &m_format, pOleClientSite, pStorage, (void **)&pOleObject)))
+ return NULL;
return pOleObject;
}
diff --git a/plugins/TabSRMM/src/modplus.cpp b/plugins/TabSRMM/src/modplus.cpp index 3885fbe072..99620abb18 100644 --- a/plugins/TabSRMM/src/modplus.cpp +++ b/plugins/TabSRMM/src/modplus.cpp @@ -68,9 +68,9 @@ static int CustomButtonPressed(WPARAM wParam, LPARAM lParam) BBButton bbd = {};
bbd.dwButtonID = 1;
bbd.pszModuleName = "Tabmodplus";
- Srmm_SetButtonState(wParam, &bbd);
+ Srmm_GetButtonState(cbcd->hwndFrom, &bbd);
- wchar_t *pszText = L"";
+ ptrW pszText;
CHARRANGE cr;
cr.cpMin = cr.cpMax = 0;
SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_EXGETSEL, 0, (LPARAM)&cr);
@@ -81,80 +81,56 @@ static int CustomButtonPressed(WPARAM wParam, LPARAM lParam) SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText);
}
- int state = 0;
- if (cbcd->flags & BBCF_RIGHTBUTTON)
- state = 1;
- else if (textlenght)
- state = 2;
- else if (bbd.bbbFlags & BBSF_PUSHED)
- state = 3;
- else
- state = 4;
-
- wchar_t *pszFormatedText = NULL, *pszMenu[256] = { 0 };
-
size_t bufSize;
+ CMStringW pwszFormatedText;
- switch (state) {
- case 1:
- {
+ if (cbcd->flags & BBCF_RIGHTBUTTON) {
int menulimit = M.GetByte("tabmodplus", "MenuCount", 0);
- if (menulimit == 0)
- break;
-
- HMENU hMenu = CreatePopupMenu();
-
- for (int menunum = 0; menunum < menulimit; menunum++) {
- pszMenu[menunum] = getMenuEntry(menunum);
- AppendMenu(hMenu, MF_STRING, menunum + 1, pszMenu[menunum]);
+ if (menulimit != 0) {
+ HMENU hMenu = CreatePopupMenu();
+ LIST<wchar_t> arMenuLines(1);
+
+ for (int menunum = 0; menunum < menulimit; menunum++) {
+ wchar_t *pwszText = getMenuEntry(menunum);
+ arMenuLines.insert(pwszText);
+ AppendMenu(hMenu, MF_STRING, menunum + 1, pwszText);
+ }
+
+ int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
+ if (res != 0) {
+ bufSize = textlenght + mir_wstrlen(arMenuLines[res-1]) + 2;
+ pwszFormatedText.Format(arMenuLines[res-1], pszText);
+ }
+
+ for (int i = 0; i < arMenuLines.getCount(); i++)
+ mir_free(arMenuLines[i]);
}
-
- int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL);
- if (res == 0)
- break;
-
- bufSize = textlenght + mir_wstrlen(pszMenu[res - 1]) + 2;
- pszFormatedText = (wchar_t*)_alloca(bufSize*sizeof(wchar_t));
- mir_snwprintf(pszFormatedText, bufSize, pszMenu[res - 1], pszText);
}
- break;
-
- case 2:
+ else if (textlenght) {
SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText);
- bufSize = textlenght + 12;
- pszFormatedText = (wchar_t*)_alloca(bufSize*sizeof(wchar_t));
- mir_snwprintf(pszFormatedText, bufSize, L"[img]%s[/img]", pszText);
+ pwszFormatedText.Format(L"[img]%s[/img]", pszText);
bbd.pwszTooltip = 0;
bbd.hIcon = 0;
bbd.bbbFlags = BBSF_RELEASED;
Srmm_SetButtonState(wParam, &bbd);
- break;
-
- case 3:
- pszFormatedText = L"[img]";
+ }
+ else if (bbd.bbbFlags & BBSF_PUSHED) {
+ pwszFormatedText = L"[img]";
bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]");
Srmm_SetButtonState(wParam, &bbd);
- break;
-
- case 4:
- pszFormatedText = L"[/img]";
+ }
+ else {
+ pwszFormatedText = L"[/img]";
bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]");
Srmm_SetButtonState(wParam, &bbd);
- break;
}
- for (int i = 0; pszMenu[i]; i++)
- mir_free(pszMenu[i]);
-
- if (pszFormatedText)
- SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pszFormatedText);
-
- if (textlenght)
- mir_free(pszText);
+ if (!pwszFormatedText.IsEmpty())
+ SendDlgItemMessage(cbcd->hwndFrom, IDC_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pwszFormatedText.c_str());
return 1;
}
diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index a376fc46fa..1b452bedae 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -178,8 +178,13 @@ void FreeLogFonts() DeleteObject(CInfoPanel::m_ipConfig.hFonts[i]);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
void TSAPI CacheMsgLogIcons()
{
+ for (int i = 0; i < _countof(Logicons); i++)
+ DestroyIcon(Logicons[i]);
+
Logicons[0] = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
Logicons[1] = Skin_LoadIcon(SKINICON_EVENT_URL);
Logicons[2] = Skin_LoadIcon(SKINICON_EVENT_FILE);
@@ -189,6 +194,56 @@ void TSAPI CacheMsgLogIcons() Logicons[6] = PluginConfig.g_iconErr;
}
+struct TLogIcon
+{
+ TLogIcon(HICON, COLORREF);
+ ~TLogIcon();
+
+ HBITMAP m_hBmp;
+ HDC m_hdc, m_hdcMem;
+ HBRUSH m_hBkgBrush;
+};
+
+TLogIcon::TLogIcon(HICON hIcon, COLORREF backgroundColor)
+{
+ int IconSizeX = 0, IconSizeY = 0;
+ Utils::getIconSize(hIcon, IconSizeX, IconSizeY);
+
+ m_hBkgBrush = CreateSolidBrush(backgroundColor);
+
+ BITMAPINFOHEADER bih = { 0 };
+ bih.biSize = sizeof(bih);
+ bih.biBitCount = 24;
+ bih.biPlanes = 1;
+ bih.biCompression = BI_RGB;
+ bih.biHeight = IconSizeY;
+ bih.biWidth = IconSizeX;
+
+ RECT rc;
+ rc.top = rc.left = 0;
+ rc.right = bih.biWidth;
+ rc.bottom = bih.biHeight;
+
+ m_hdc = GetDC(0);
+ m_hBmp = CreateCompatibleBitmap(m_hdc, bih.biWidth, bih.biHeight);
+ m_hdcMem = CreateCompatibleDC(m_hdc);
+
+ HBITMAP hoBmp = (HBITMAP)SelectObject(m_hdcMem, m_hBmp);
+ FillRect(m_hdcMem, &rc, m_hBkgBrush);
+ DrawIconEx(m_hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
+ SelectObject(m_hdcMem, hoBmp);
+}
+
+TLogIcon::~TLogIcon()
+{
+ DeleteDC(m_hdcMem);
+ DeleteObject(m_hBmp);
+ ReleaseDC(NULL, m_hdc);
+ DeleteObject(m_hBkgBrush);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static int TSAPI GetColorIndex(char *rtffont)
{
char *p;
@@ -1033,8 +1088,6 @@ static void SetupLogFormatting(TWindowData *dat) static void ReplaceIcons(HWND hwndDlg, TWindowData *dat, LONG startAt, int fAppend, BOOL isSent)
{
- DWORD dwScale = M.GetDword("iconscale", 0);
-
wchar_t trbuffer[40];
TEXTRANGE tr;
tr.lpstrText = trbuffer;
@@ -1076,8 +1129,6 @@ static void ReplaceIcons(HWND hwndDlg, TWindowData *dat, LONG startAt, int fAppe fi.chrg.cpMin = startAt;
if (dat->dwFlags & MWF_LOG_SHOWICONS) {
- BYTE bIconIndex = 0;
- char bDirection = 0;
fi.lpstrText = L"#~#";
fi.chrg.cpMax = -1;
@@ -1086,7 +1137,7 @@ static void ReplaceIcons(HWND hwndDlg, TWindowData *dat, LONG startAt, int fAppe cf2.cbSize = sizeof(cf2);
cf2.dwMask = CFM_BACKCOLOR;
- IRichEditOle *ole;
+ CComPtr<IRichEditOle> ole;
SendMessage(hwndrtf, EM_GETOLEINTERFACE, 0, (LPARAM)&ole);
while (SendMessageA(hwndrtf, EM_FINDTEXTEX, FR_DOWN, (LPARAM)&fi) > -1) {
CHARRANGE cr;
@@ -1097,23 +1148,27 @@ static void ReplaceIcons(HWND hwndDlg, TWindowData *dat, LONG startAt, int fAppe tr.chrg.cpMin = fi.chrgText.cpMin + 3;
tr.chrg.cpMax = fi.chrgText.cpMin + 5;
SendMessage(hwndrtf, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
- bIconIndex = ((BYTE)trbuffer[0] - (BYTE)'0');
+
+ int bIconIndex = trbuffer[0] - '0';
if (bIconIndex >= NR_LOGICONS) {
fi.chrg.cpMin = fi.chrgText.cpMax + 6;
continue;
}
- bDirection = trbuffer[1];
+
+ char bDirection = trbuffer[1];
SendMessage(hwndrtf, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
- COLORREF crDefault = cf2.crBackColor == 0 ? (true ? (bDirection == '>' ? (fAppend ? dat->pContainer->theme.outbg : dat->pContainer->theme.oldoutbg) :
- (fAppend ? dat->pContainer->theme.inbg : dat->pContainer->theme.oldinbg)) : dat->pContainer->theme.bg) : cf2.crBackColor;
-
- TLogIcon theIcon;
- CacheIconToBMP(&theIcon, Logicons[bIconIndex], crDefault, dwScale, dwScale);
- ImageDataInsertBitmap(ole, theIcon.hBmp);
- DeleteCachedIcon(&theIcon);
+ COLORREF crDefault;
+ if (cf2.crBackColor != 0)
+ crDefault = cf2.crBackColor;
+ else if (bDirection == '>')
+ crDefault = (fAppend) ? dat->pContainer->theme.outbg : dat->pContainer->theme.oldoutbg;
+ else
+ crDefault = (fAppend) ? dat->pContainer->theme.inbg : dat->pContainer->theme.oldinbg;
+
+ TLogIcon theIcon(Logicons[bIconIndex], crDefault);
+ CImageDataObject::InsertBitmap(ole, theIcon.m_hBmp);
fi.chrg.cpMin = cr.cpMax + 6;
}
- ole->Release();
}
// do smiley replacing, using the service
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index 324bf50356..60613c4458 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -126,7 +126,7 @@ struct TitleBtn { #define BTN_MAX 1
#define BTN_CLOSE 2
-#define NR_LOGICONS 8
+#define NR_LOGICONS 7
#define NR_BUTTONBARICONS 37//MaD: 29
#define NR_SIDEBARICONS 2
@@ -741,12 +741,6 @@ struct CREOleCallback2 : public CREOleCallback #define HOTKEY_MODIFIERS_CTRLALT 1
#define HOTKEY_MODIFIERS_ALTSHIFT 2
-struct TLogIcon {
- HBITMAP hBmp, hoBmp;
- HDC hdc, hdcMem;
- HBRUSH hBkgBrush;
-};
-
#include "../TabSRMM_icons/resource.h" // icon pack values
struct TCpTable {
diff --git a/plugins/TabSRMM/src/stdafx.h b/plugins/TabSRMM/src/stdafx.h index 485b157a3b..2f3124c19a 100644 --- a/plugins/TabSRMM/src/stdafx.h +++ b/plugins/TabSRMM/src/stdafx.h @@ -47,6 +47,8 @@ #include <locale.h>
#include <msapi/vsstyle.h>
+#include <msapi/comptr.h>
+
#include <m_avatars.h>
#include <m_message.h>
#include <win2k.h>
@@ -230,7 +232,6 @@ extern LOGFONTA logfonts[MSGDLGFONTCOUNT + 2]; extern COLORREF fontcolors[MSGDLGFONTCOUNT + 2];
extern HINSTANCE hinstance;
extern BOOL g_bIMGtagButton;
-extern TLogIcon msgLogIcons[NR_LOGICONS * 3];
extern const wchar_t *pszIDCSAVE_save, *pszIDCSAVE_close;
extern char *TemplateNames[];
extern HANDLE hUserPrefsWindowList;
@@ -247,9 +248,6 @@ int SplitmsgShutdown(void); void LogErrorMessage(HWND hwndDlg, TWindowData *dat, int i, wchar_t *szMsg);
int Chat_Load(), Chat_Unload();
void FreeLogFonts();
-void ImageDataInsertBitmap(IRichEditOle *ole, HBITMAP hBm);
-int CacheIconToBMP(TLogIcon *theIcon, HICON hIcon, COLORREF backgroundColor, int sizeX, int sizeY);
-void DeleteCachedIcon(TLogIcon *theIcon);
INT_PTR SendMessageCommand(WPARAM wParam, LPARAM lParam);
INT_PTR SendMessageCommand_W(WPARAM wParam, LPARAM lParam);
diff --git a/plugins/TabSRMM/src/templates.cpp b/plugins/TabSRMM/src/templates.cpp index 91c4cd1e79..2b70be3611 100644 --- a/plugins/TabSRMM/src/templates.cpp +++ b/plugins/TabSRMM/src/templates.cpp @@ -245,23 +245,24 @@ INT_PTR CALLBACK DlgProcTemplateEditor(HWND hwndDlg, UINT msg, WPARAM wParam, LP InvalidateRect(GetDlgItem(hwndDlg, IDC_TEMPLATELIST), NULL, FALSE); } break; - case IDC_SAVETEMPLATE: - { - wchar_t newTemplate[TEMPLATE_LENGTH + 2]; - GetDlgItemText(hwndDlg, IDC_EDITTEMPLATE, newTemplate, _countof(newTemplate)); - memcpy(tSet->szTemplates[teInfo->inEdit], newTemplate, sizeof(wchar_t) * TEMPLATE_LENGTH); - teInfo->changed = FALSE; - teInfo->updateInfo[teInfo->inEdit] = FALSE; - Utils::enableDlgControl(hwndDlg, IDC_SAVETEMPLATE, FALSE); - Utils::enableDlgControl(hwndDlg, IDC_FORGET, FALSE); - Utils::enableDlgControl(hwndDlg, IDC_TEMPLATELIST, TRUE); - Utils::enableDlgControl(hwndDlg, IDC_REVERT, FALSE); - InvalidateRect(GetDlgItem(hwndDlg, IDC_TEMPLATELIST), NULL, FALSE); - db_set_ws(teInfo->hContact, teInfo->rtl ? RTLTEMPLATES_MODULE : TEMPLATES_MODULE, TemplateNames[teInfo->inEdit], newTemplate); - SendDlgItemMessage(hwndDlg, IDC_EDITTEMPLATE, EM_SETREADONLY, TRUE, 0); - } - break; + case IDC_SAVETEMPLATE: + { + wchar_t newTemplate[TEMPLATE_LENGTH + 2]; + + GetDlgItemText(hwndDlg, IDC_EDITTEMPLATE, newTemplate, _countof(newTemplate)); + memcpy(tSet->szTemplates[teInfo->inEdit], newTemplate, sizeof(wchar_t) * TEMPLATE_LENGTH); + teInfo->changed = FALSE; + teInfo->updateInfo[teInfo->inEdit] = FALSE; + Utils::enableDlgControl(hwndDlg, IDC_SAVETEMPLATE, FALSE); + Utils::enableDlgControl(hwndDlg, IDC_FORGET, FALSE); + Utils::enableDlgControl(hwndDlg, IDC_TEMPLATELIST, TRUE); + Utils::enableDlgControl(hwndDlg, IDC_REVERT, FALSE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_TEMPLATELIST), NULL, FALSE); + db_set_ws(teInfo->hContact, teInfo->rtl ? RTLTEMPLATES_MODULE : TEMPLATES_MODULE, TemplateNames[teInfo->inEdit], newTemplate); + SendDlgItemMessage(hwndDlg, IDC_EDITTEMPLATE, EM_SETREADONLY, TRUE, 0); + } + break; case IDC_FORGET: teInfo->changed = FALSE; @@ -302,68 +303,70 @@ INT_PTR CALLBACK DlgProcTemplateEditor(HWND hwndDlg, UINT msg, WPARAM wParam, LP break; case WM_DRAWITEM: - { - DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; - int iItem = dis->itemData; - SetBkMode(dis->hDC, TRANSPARENT); - FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); - if (dis->itemState & ODS_SELECTED) { - if (teInfo->updateInfo[iItem] == TRUE) { - HBRUSH bkg = CreateSolidBrush(RGB(255, 0, 0)); - HBRUSH oldBkg = (HBRUSH)SelectObject(dis->hDC, bkg); - FillRect(dis->hDC, &dis->rcItem, bkg); - SelectObject(dis->hDC, oldBkg); - DeleteObject(bkg); - } - else - FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); + { + DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; + int iItem = dis->itemData; + SetBkMode(dis->hDC, TRANSPARENT); + FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); + if (dis->itemState & ODS_SELECTED) { + if (teInfo->updateInfo[iItem] == TRUE) { + HBRUSH bkg = CreateSolidBrush(RGB(255, 0, 0)); + HBRUSH oldBkg = (HBRUSH)SelectObject(dis->hDC, bkg); + FillRect(dis->hDC, &dis->rcItem, bkg); + SelectObject(dis->hDC, oldBkg); + DeleteObject(bkg); + } + else FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); - SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); - } - else { - if (teInfo->updateInfo[iItem] == TRUE) - SetTextColor(dis->hDC, RGB(255, 0, 0)); - else - SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT)); + SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); + } + else { + if (teInfo->updateInfo[iItem] == TRUE) + SetTextColor(dis->hDC, RGB(255, 0, 0)); + else + SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT)); + } + char *pszName = Translate(TemplateNames[iItem]); + TextOutA(dis->hDC, dis->rcItem.left, dis->rcItem.top, pszName, (int)mir_strlen(pszName)); } - char *pszName = Translate(TemplateNames[iItem]); - TextOutA(dis->hDC, dis->rcItem.left, dis->rcItem.top, pszName, (int)mir_strlen(pszName)); - } - return TRUE; + return TRUE; - case DM_UPDATETEMPLATEPREVIEW: { - DBEVENTINFO dbei = { 0 }; - int iIndex = SendDlgItemMessage(hwndDlg, IDC_TEMPLATELIST, LB_GETCURSEL, 0, 0); - wchar_t szTemp[TEMPLATE_LENGTH + 2]; + case DM_UPDATETEMPLATEPREVIEW: + { + int iIndex = SendDlgItemMessage(hwndDlg, IDC_TEMPLATELIST, LB_GETCURSEL, 0, 0); + wchar_t szTemp[TEMPLATE_LENGTH + 2]; - if (teInfo->changed) { - memcpy(szTemp, tSet->szTemplates[teInfo->inEdit], (TEMPLATE_LENGTH * sizeof(wchar_t))); - GetDlgItemText(hwndDlg, IDC_EDITTEMPLATE, tSet->szTemplates[teInfo->inEdit], TEMPLATE_LENGTH); + if (teInfo->changed) { + memcpy(szTemp, tSet->szTemplates[teInfo->inEdit], (TEMPLATE_LENGTH * sizeof(wchar_t))); + GetDlgItemText(hwndDlg, IDC_EDITTEMPLATE, tSet->szTemplates[teInfo->inEdit], TEMPLATE_LENGTH); + } + + DBEVENTINFO dbei = { 0 }; + dbei.szModule = dat->szProto; + dbei.timestamp = time(NULL); + dbei.eventType = (iIndex == 6) ? EVENTTYPE_STATUSCHANGE : EVENTTYPE_MESSAGE; + dbei.eventType = (iIndex == 7) ? EVENTTYPE_ERRMSG : dbei.eventType; + if (dbei.eventType == EVENTTYPE_ERRMSG) + dbei.szModule = (char *)L"Sample error message"; + dbei.cbSize = sizeof(dbei); + dbei.pBlob = (iIndex == 6) ? (BYTE *)"is now offline (was online)" : (BYTE *)"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."; + dbei.cbBlob = (int)mir_strlen((char *)dbei.pBlob) + 1; + dbei.flags = (iIndex == 1 || iIndex == 3 || iIndex == 5) ? DBEF_SENT : 0; + dbei.flags |= (teInfo->rtl ? DBEF_RTL : 0); + dat->lastEventTime = (iIndex == 4 || iIndex == 5) ? time(NULL) - 1 : 0; + dat->iLastEventType = MAKELONG(dbei.flags, dbei.eventType); + SetDlgItemText(hwndDlg, IDC_PREVIEW, L""); + dat->dwFlags = MWF_LOG_ALL; + dat->dwFlags = (teInfo->rtl ? dat->dwFlags | MWF_LOG_RTL : dat->dwFlags & ~MWF_LOG_RTL); + dat->dwFlags = (iIndex == 0 || iIndex == 1) ? dat->dwFlags & ~MWF_LOG_GROUPMODE : dat->dwFlags | MWF_LOG_GROUPMODE; + mir_snwprintf(dat->szMyNickname, L"My Nickname"); + StreamInEvents(hwndDlg, 0, 1, 0, &dbei); + SendDlgItemMessage(hwndDlg, IDC_PREVIEW, EM_SETSEL, -1, -1); + if (teInfo->changed) + memcpy(tSet->szTemplates[teInfo->inEdit], szTemp, TEMPLATE_LENGTH * sizeof(wchar_t)); } - dbei.szModule = dat->szProto; - dbei.timestamp = time(NULL); - dbei.eventType = (iIndex == 6) ? EVENTTYPE_STATUSCHANGE : EVENTTYPE_MESSAGE; - dbei.eventType = (iIndex == 7) ? EVENTTYPE_ERRMSG : dbei.eventType; - if (dbei.eventType == EVENTTYPE_ERRMSG) - dbei.szModule = (char *)L"Sample error message"; - dbei.cbSize = sizeof(dbei); - dbei.pBlob = (iIndex == 6) ? (BYTE *)"is now offline (was online)" : (BYTE *)"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."; - dbei.cbBlob = (int)mir_strlen((char *)dbei.pBlob) + 1; - dbei.flags = (iIndex == 1 || iIndex == 3 || iIndex == 5) ? DBEF_SENT : 0; - dbei.flags |= (teInfo->rtl ? DBEF_RTL : 0); - dat->lastEventTime = (iIndex == 4 || iIndex == 5) ? time(NULL) - 1 : 0; - dat->iLastEventType = MAKELONG(dbei.flags, dbei.eventType); - SetDlgItemText(hwndDlg, IDC_PREVIEW, L""); - dat->dwFlags = MWF_LOG_ALL; - dat->dwFlags = (teInfo->rtl ? dat->dwFlags | MWF_LOG_RTL : dat->dwFlags & ~MWF_LOG_RTL); - dat->dwFlags = (iIndex == 0 || iIndex == 1) ? dat->dwFlags & ~MWF_LOG_GROUPMODE : dat->dwFlags | MWF_LOG_GROUPMODE; - mir_snwprintf(dat->szMyNickname, L"My Nickname"); - StreamInEvents(hwndDlg, 0, 1, 0, &dbei); - SendDlgItemMessage(hwndDlg, IDC_PREVIEW, EM_SETSEL, -1, -1); - if (teInfo->changed) - memcpy(tSet->szTemplates[teInfo->inEdit], szTemp, TEMPLATE_LENGTH * sizeof(wchar_t)); break; - } + case WM_DESTROY: Utils::enableDlgControl(teInfo->hwndParent, IDC_MODIFY, TRUE); Utils::enableDlgControl(teInfo->hwndParent, IDC_RTLMODIFY, TRUE); |