summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-31 13:09:10 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-31 13:09:10 +0300
commit5b2fa6f292b910409066b2ca748b3f7b8ff020b1 (patch)
tree97408436343ad0144a9b76e4dea1897ee1942d3e
parent6a495da1906284b770f1aceee892d7e60fe1582e (diff)
NewStory:
- fixes #3755 (NewStory: неработающий тэг color парсится криво); - fixes bug with template preview in the options dialog
-rw-r--r--libs/mTextControl/src/textcontrol.cpp14
-rw-r--r--plugins/ExternalAPI/m_text.h10
-rw-r--r--plugins/NewStory/src/history_array.cpp35
-rw-r--r--plugins/NewStory/src/history_array.h3
-rw-r--r--plugins/NewStory/src/options.cpp8
-rw-r--r--plugins/NewStory/src/templates.cpp37
6 files changed, 83 insertions, 24 deletions
diff --git a/libs/mTextControl/src/textcontrol.cpp b/libs/mTextControl/src/textcontrol.cpp
index f1b92d2f10..5a871d42e5 100644
--- a/libs/mTextControl/src/textcontrol.cpp
+++ b/libs/mTextControl/src/textcontrol.cpp
@@ -109,6 +109,20 @@ static LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam,
InvalidateRect(hwnd, nullptr, TRUE);
return TRUE;
+ case MTM_UPDATEEX:
+ if (data->text) {
+ delete[] data->text;
+ data->text = nullptr;
+ }
+
+ if (data->mtext)
+ MTextDestroy(data->mtext);
+
+ data->mtext = MTextCreateEx(data->htu, (char*)lParam, wParam);
+ MTextSetParent(data->mtext, hwnd);
+ InvalidateRect(hwnd, nullptr, TRUE);
+ return TRUE;
+
case WM_PAINT:
return MTextControl_OnPaint(hwnd);
diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h
index d6607e2eb1..d2165802ac 100644
--- a/plugins/ExternalAPI/m_text.h
+++ b/plugins/ExternalAPI/m_text.h
@@ -3,8 +3,14 @@
// Text control
#define MTEXTCONTROLCLASS "MTextControl"
-#define MTM_SETUSER WM_USER
-#define MTM_UPDATE WM_USER+1
+
+#define MTM_SETUSER (WM_USER)
+#define MTM_UPDATE (WM_USER+1)
+
+// analog of calling MTextCreateEx
+// wParam = MTEXT_FLG_*
+// lParam = (void*)text
+#define MTM_UPDATEEX (WM_USER+2)
typedef struct TextObject *HText;
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index bffdfc944a..eedcbb0b9b 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -214,6 +214,41 @@ bool ItemData::isLinkChar(int idx) const
return ((res & CFM_LINK) && (cf.dwEffects & CFE_LINK)) || ((res & CFM_REVISED) && (cf.dwEffects & CFE_REVISED));
}
+void ItemData::fill(int tmpl)
+{
+ switch (tmpl) {
+ case TPL_MESSAGE:
+ dbe.eventType = EVENTTYPE_MESSAGE;
+ break;
+ case TPL_MSG_HEAD:
+ m_grouping = GROUPING_HEAD;
+ dbe.eventType = EVENTTYPE_MESSAGE;
+ break;
+ case TPL_MSG_GRP:
+ m_grouping = GROUPING_ITEM;
+ dbe.eventType = EVENTTYPE_MESSAGE;
+ break;
+ case TPL_FILE:
+ dbe.eventType = EVENTTYPE_FILE;
+ break;
+ case TPL_SIGN:
+ dbe.eventType = EVENTTYPE_STATUSCHANGE;
+ break;
+ case TPL_AUTH:
+ dbe.eventType = EVENTTYPE_AUTHREQUEST;
+ break;
+ case TPL_ADDED:
+ dbe.eventType = EVENTTYPE_ADDED;
+ break;
+ case TPL_PRESENCE:
+ dbe.eventType = EVENTTYPE_JABBER_PRESENCE;
+ break;
+ default:
+ dbe.eventType = 309247;
+ break;
+ }
+}
+
int ItemData::getTemplate() const
{
switch (dbe.eventType) {
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index 151ff568ca..0f30c64740 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -36,6 +36,7 @@ struct ItemData
void checkCreate(HWND hwnd);
void setText();
+ void fill(int tmpl);
void load(bool bFullLoad);
bool isLink(POINT pt, CMStringW *url = nullptr) const;
bool isLinkChar(int idx) const;
@@ -46,7 +47,7 @@ struct ItemData
CMStringA formatRtf();
CMStringW formatString() { return TplFormatString(getTemplate(), hContact, this); }
- CMStringW formatStringEx(int tpl, wchar_t *sztpl);
+ CMStringW formatStringEx(wchar_t *sztpl);
inline wchar_t *getWBuf()
{
diff --git a/plugins/NewStory/src/options.cpp b/plugins/NewStory/src/options.cpp
index ee84cd1b79..ab1be7e672 100644
--- a/plugins/NewStory/src/options.cpp
+++ b/plugins/NewStory/src/options.cpp
@@ -78,14 +78,14 @@ class CTemplateOptsDlg : public CBaseOptsDlg
{
replaceStrW(m_curr->tmpValue, m_edit.GetText());
- ItemData item;
+ ItemData item = {};
item.hContact = m_hContact;
item.hEvent = m_hDbEVent;
item.load(true);
+ item.fill(int(m_curr - templates)); // copy data from template to event
- CMStringW wszText(item.formatStringEx(int(m_curr - templates), m_curr->tmpValue));
- preview.SetText(wszText);
- gpreview.SetText(wszText);
+ preview.SetText(item.formatStringEx(m_curr->tmpValue));
+ gpreview.SendMsg(MTM_UPDATEEX, MTEXT_FLG_RTF, LPARAM(item.formatRtf().c_str()));
}
CCtrlBase preview, gpreview;
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index b6ab2d727f..6721ee39cc 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -47,38 +47,40 @@ static void AppendUnicodeToBuffer(CMStringA &buf, const wchar_t *p)
buf.AppendChar((char)*p);
}
else if (*p == '[') {
- if (p[1] == 'c' && p[3] == ']') {
- buf.AppendFormat("\\cf%c ", p[2]);
- p += 3;
+ p++;
+ if (*p == 'c' && p[2] == ']') {
+ buf.AppendFormat("\\cf%c ", p[1]);
+ p += 2;
continue;
}
char *pEnd = "";
- if (p[1] == '/') {
+ if (*p == '/') {
pEnd = "0";
p++;
}
- if (p[1] == 'b' && p[2] == ']') {
+ if (*p == 'b' && p[1] == ']') {
buf.AppendFormat("\\b%s ", pEnd);
- p += 2;
+ p++;
}
- else if (p[1] == 'i' && p[2] == ']') {
+ else if (*p == 'i' && p[1] == ']') {
buf.AppendFormat("\\i%s ", pEnd);
- p += 2;
+ p++;
}
- else if (p[1] == 'u' && p[2] == ']') {
+ else if (*p == 'u' && p[1] == ']') {
buf.AppendFormat("\\ul%s ", pEnd);
- p += 2;
+ p++;
}
- else if (p[1] == 's' && p[2] == ']') {
+ else if (*p == 's' && p[1] == ']') {
buf.AppendFormat("\\strike%s ", pEnd);
- p += 2;
+ p++;
}
- else if (p[1] == 'c' && p[2] == ']') {
- buf.Append("\\cf1 ");
- p += 2;
+ else {
+ buf.AppendChar('[');
+ if (*pEnd == '0')
+ p--;
+ p--;
}
- else buf.AppendChar('[');
}
else if (*p < 128) {
buf.AppendChar((char)*p);
@@ -153,9 +155,10 @@ CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item)
///////////////////////////////////////////////////////////////////////////////
// Template formatting for options dialog
-CMStringW ItemData::formatStringEx(int tpl, wchar_t *sztpl)
+CMStringW ItemData::formatStringEx(wchar_t *sztpl)
{
CMStringW buf;
+ int tpl = getTemplate();
if (tpl < 0 || tpl >= TPL_COUNT || !sztpl)
return buf;