summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-22 21:50:38 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-22 21:50:38 +0300
commitde72c19d77098ca5a5870cfeb8bce5068e8a1092 (patch)
tree19e3d79e740c220e749d435b7365310a02e8d03f /plugins/NewStory/src
parent444a4a54745a33980b8d5bbe156cffaa3981f2ad (diff)
NewStory: fix for the template preview window in options
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r--plugins/NewStory/src/history_array.cpp38
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/history_control.cpp89
-rw-r--r--plugins/NewStory/src/history_control.h2
-rw-r--r--plugins/NewStory/src/options.cpp30
5 files changed, 89 insertions, 72 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 3aef75df2c..26e7add7c8 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -201,18 +201,20 @@ int ItemData::calcHeight(int top, int width, POINT *pPos)
pos.x = 2;
pos.y = top + 2;
- if (g_plugin.bShowType) // Message type icon
- pos.x += 18;
+ if (!pOwner->bReadOnly) {
+ if (g_plugin.bShowType) // Message type icon
+ pos.x += 18;
- if (g_plugin.bShowDirection) // Message direction icon
- pos.x += 18;
+ if (g_plugin.bShowDirection) // Message direction icon
+ pos.x += 18;
- if (dbe.flags & DBEF_BOOKMARK) // Bookmark icon
- pos.x += 18;
+ if (dbe.flags & DBEF_BOOKMARK) // Bookmark icon
+ pos.x += 18;
- sz.cx -= pos.x;
- if (m_bOfflineDownloaded != 0) // Download completed icon
- sz.cx -= 18;
+ sz.cx -= pos.x;
+ if (m_bOfflineDownloaded != 0) // Download completed icon
+ sz.cx -= 18;
+ }
leftOffset = pos.x;
if (savedHeight == -1) {
@@ -456,14 +458,14 @@ void ItemData::load(bool bLoadAlways)
dbe.unload();
}
-void ItemData::setText()
+void ItemData::setText(const wchar_t *pwszText)
{
int fontid, colorid;
getFontColor(fontid, colorid);
pOwner->webPage.clText = g_fontTable[fontid].cl;
pOwner->webPage.clBack = g_colorTable[colorid].cl;
- m_doc = litehtml::document::createFromString(T2Utf(formatHtml()), &pOwner->webPage);
+ m_doc = litehtml::document::createFromString(T2Utf(formatHtml(pwszText)), &pOwner->webPage);
}
// Array
@@ -683,12 +685,14 @@ ItemData* HistoryArray::insert(int pos)
{
int count = getCount();
ItemData *pNew = &allocateItem();
- ItemData *pPrev = get(count-1, false);
-
- for (int i = count; i >= pos; i--) {
- memcpy(pNew, pPrev, sizeof(ItemData));
- pNew = pPrev;
- pPrev = get(i - 1, false);
+
+ if (count > 0) {
+ ItemData *pPrev = get(count - 1, false);
+ for (int i = count; i >= pos; i--) {
+ memcpy(pNew, pPrev, sizeof(ItemData));
+ pNew = pPrev;
+ pPrev = get(i - 1, false);
+ }
}
ItemData tmp;
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index ae32334d84..a03e8b4066 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -41,7 +41,7 @@ struct ItemData
bool fetch(void);
void fill(int tmpl);
void load(bool bLoad = false);
- void setText();
+ void setText(const wchar_t *pwszText = nullptr);
int getTemplate() const;
int getCopyTemplate() const;
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 1022ff0173..3ccad39066 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -673,7 +673,7 @@ void NewstoryListData::Paint(simpledib::dib &dib)
webPage.clBack = g_colorTable[COLOR_HIGHLIGHT_BACK].cl;
clLine = g_colorTable[COLOR_FRAME].cl;
}
- else if (pItem->m_bSelected) {
+ else if (pItem->m_bSelected && !bReadOnly) {
webPage.clText = g_colorTable[COLOR_SELTEXT].cl;
webPage.clBack = g_colorTable[COLOR_SELBACK].cl;
clLine = g_colorTable[COLOR_SELFRAME].cl;
@@ -695,53 +695,56 @@ void NewstoryListData::Paint(simpledib::dib &dib)
SetBkMode(dib, TRANSPARENT);
pos.x = 2;
- HICON hIcon;
- // Message type icon
- if (g_plugin.bShowType) {
- switch (pItem->dbe.eventType) {
- case EVENTTYPE_MESSAGE:
- hIcon = g_plugin.getIcon(IDI_SENDMSG);
- break;
- case EVENTTYPE_FILE:
- hIcon = Skin_LoadIcon(SKINICON_EVENT_FILE);
- break;
- case EVENTTYPE_STATUSCHANGE:
- hIcon = g_plugin.getIcon(IDI_SIGNIN);
- break;
- default:
- hIcon = g_plugin.getIcon(IDI_UNKNOWN);
- break;
+ if (!bReadOnly) {
+ HICON hIcon;
+
+ // Message type icon
+ if (g_plugin.bShowType) {
+ switch (pItem->dbe.eventType) {
+ case EVENTTYPE_MESSAGE:
+ hIcon = g_plugin.getIcon(IDI_SENDMSG);
+ break;
+ case EVENTTYPE_FILE:
+ hIcon = Skin_LoadIcon(SKINICON_EVENT_FILE);
+ break;
+ case EVENTTYPE_STATUSCHANGE:
+ hIcon = g_plugin.getIcon(IDI_SIGNIN);
+ break;
+ default:
+ hIcon = g_plugin.getIcon(IDI_UNKNOWN);
+ break;
+ }
+ DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL);
+ pos.x += 18;
}
- DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL);
- pos.x += 18;
- }
- // Direction icon
- if (g_plugin.bShowDirection) {
- if (pItem->dbe.flags & DBEF_SENT)
- hIcon = g_plugin.getIcon(IDI_MSGOUT);
- else
- hIcon = g_plugin.getIcon(IDI_MSGIN);
- DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL);
- pos.x += 18;
- }
+ // Direction icon
+ if (g_plugin.bShowDirection) {
+ if (pItem->dbe.flags & DBEF_SENT)
+ hIcon = g_plugin.getIcon(IDI_MSGOUT);
+ else
+ hIcon = g_plugin.getIcon(IDI_MSGIN);
+ DrawIconEx(dib, pos.x, pos.y, hIcon, 16, 16, 0, 0, DI_NORMAL);
+ pos.x += 18;
+ }
- // Bookmark icon
- if (pItem->dbe.flags & DBEF_BOOKMARK) {
- DrawIconEx(dib, pos.x, pos.y, g_plugin.getIcon(IDI_BOOKMARK), 16, 16, 0, 0, DI_NORMAL);
- pos.x += 18;
- }
+ // Bookmark icon
+ if (pItem->dbe.flags & DBEF_BOOKMARK) {
+ DrawIconEx(dib, pos.x, pos.y, g_plugin.getIcon(IDI_BOOKMARK), 16, 16, 0, 0, DI_NORMAL);
+ pos.x += 18;
+ }
- // Finished icon
- if (pItem->m_bOfflineDownloaded != 0) {
- if (pItem->completed())
- DrawIconEx(dib, cachedWindowWidth - 20, pos.y, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL);
- else {
- HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 4, g_colorTable[COLOR_PROGRESS].cl));
- MoveToEx(dib, rc.left, rc.bottom - 4, 0);
- LineTo(dib, rc.left + (rc.right - rc.left) * int(pItem->m_bOfflineDownloaded) / 100, rc.bottom - 4);
- DeleteObject(SelectObject(dib, hpn));
+ // Finished icon
+ if (pItem->m_bOfflineDownloaded != 0) {
+ if (pItem->completed())
+ DrawIconEx(dib, cachedWindowWidth - 20, pos.y, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL);
+ else {
+ HPEN hpn = (HPEN)SelectObject(dib, CreatePen(PS_SOLID, 4, g_colorTable[COLOR_PROGRESS].cl));
+ MoveToEx(dib, rc.left, rc.bottom - 4, 0);
+ LineTo(dib, rc.left + (rc.right - rc.left) * int(pItem->m_bOfflineDownloaded) / 100, rc.bottom - 4);
+ DeleteObject(SelectObject(dib, hpn));
+ }
}
}
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index a7ff76727c..0579426b1d 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -52,7 +52,7 @@ struct NewstoryListData : public MZeroedObject
RECT rcLastPaint;
MCONTACT m_hContact = INVALID_CONTACT_ID;
- bool bWasShift, bSortAscending, bWasAtBottom;
+ bool bWasShift, bSortAscending, bWasAtBottom, bReadOnly;
HWND m_hwnd;
HWND hwndEditBox;
diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp
index b83ff73fb5..1310285089 100644
--- a/plugins/NewStory/src/options.cpp
+++ b/plugins/NewStory/src/options.cpp
@@ -85,7 +85,8 @@ static void AppendSymbol(CMStringW &buf, const wchar_t *pwszSymbol, const wchar_
class CTemplateOptsDlg : public CBaseOptsDlg
{
TemplateInfo *m_curr = 0;
- ItemData m_tempItem;
+ ItemData *m_tempItem;
+ NewstoryListData *m_histCtrl;
CCtrlBase preview, gpreview;
CCtrlEdit m_edit;
@@ -131,12 +132,18 @@ public:
ImageList_AddIcon(himgTree, g_plugin.getIcon(IDI_TPLGROUP));
- m_tempItem.wszNick = TranslateT("Test contact");
- m_tempItem.wtext = mir_wstrdup(TranslateT("The quick brown fox jumps over the lazy dog."));
- m_tempItem.dbe.flags = DBEF_TEMPORARY | DBEF_BOOKMARK;
- m_tempItem.dbe.szModule = MODULENAME;
- m_tempItem.dbe.eventType = EVENTTYPE_MESSAGE;
- m_tempItem.dbe.timestamp = time(0);
+ m_histCtrl = (NewstoryListData *)GetWindowLongPtr(gpreview.GetHwnd(), 0);
+ m_histCtrl->bReadOnly = true;
+
+ m_tempItem = m_histCtrl->items.insert(0);
+ m_tempItem->pOwner = m_histCtrl;
+ m_tempItem->wszNick = TranslateT("Test contact");
+ m_tempItem->wtext = mir_wstrdup(TranslateT("The quick brown fox jumps over the lazy dog."));
+ m_tempItem->dbe.flags = DBEF_TEMPORARY | DBEF_BOOKMARK;
+ m_tempItem->dbe.szModule = MODULENAME;
+ m_tempItem->dbe.eventType = EVENTTYPE_MESSAGE;
+ m_tempItem->dbe.timestamp = time(0);
+ m_histCtrl->totalCount++;
HTREEITEM hGroup = 0, hFirst = 0;
const wchar_t *pwszPrevGroup = nullptr;
@@ -263,11 +270,14 @@ public:
replaceStrW(m_curr->tmpValue, m_edit.GetText());
- m_tempItem.fill(int(m_curr - templates)); // copy data from template to event
+ m_tempItem->savedHeight = -1;
+ m_tempItem->fill(int(m_curr - templates)); // copy data from template to event
- CMStringW wszText(m_tempItem.formatStringEx(m_curr->tmpValue));
+ CMStringW wszText(m_tempItem->formatStringEx(m_curr->tmpValue));
preview.SetText(wszText);
- // gpreview.SendMsg(MTM_UPDATEEX, MTEXT_FLG_RTF, LPARAM(m_tempItem.formatRtf(wszText).c_str()));
+
+ m_tempItem->setText(wszText);
+ InvalidateRect(gpreview.GetHwnd(), 0, TRUE);
}
void onSelChanged(CCtrlTreeView::TEventInfo *)