Skip to content

Commit

Permalink
StdMsg: frame drawing optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehazan committed May 8, 2023
1 parent 5ad1609 commit aba622e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/core/stdmsg/res/resource.rc
Expand Up @@ -81,6 +81,7 @@ EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "",IDC_SRMM_MESSAGE,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x1144,1,111,208,29,WS_EX_ACCEPTFILES | WS_EX_STATICEDGE
LTEXT "", IDC_FRAME, 1, 111, 208, 29, NOT WS_VISIBLE | WS_CLIPSIBLINGS
DEFPUSHBUTTON "&Send",IDOK,212,111,39,29
CONTROL "",IDC_SRMM_LOG,"RichEdit50W",WS_VSCROLL | WS_TABSTOP | 0x844,1,16,250,91,WS_EX_STATICEDGE
CONTROL "",IDC_SPLITTERX,"Static",SS_ENHMETAFILE,172,23,10,73
Expand Down
55 changes: 13 additions & 42 deletions src/core/stdmsg/src/msgdialog.cpp
Expand Up @@ -85,6 +85,8 @@ void CMsgDialog::Init()

timerFlash.OnEvent = Callback(this, &CMsgDialog::OnFlash);
timerType.OnEvent = Callback(this, &CMsgDialog::OnType);

m_hFrameBrush = CreateSolidBrush(0x00ff00);
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -248,6 +250,7 @@ void CMsgDialog::OnDestroy()
}

Window_FreeIcon_IcoLib(m_hwnd);
DeleteBrush(m_hFrameBrush);

CSuper::OnDestroy();

Expand Down Expand Up @@ -479,11 +482,16 @@ int CMsgDialog::Resizer(UTILRESIZECONTROL *urc)
return RD_ANCHORX_WIDTH | RD_ANCHORY_CUSTOM;

case IDC_SRMM_MESSAGE:
case IDC_FRAME:
urc->rcItem.right = bSend ? urc->dlgNewSize.cx - 64 : urc->dlgNewSize.cx;
urc->rcItem.top = underTB;
urc->rcItem.bottom = urc->dlgNewSize.cy - 1;
if (g_plugin.bShowAvatar && m_avatarPic)
urc->rcItem.left = m_avatarWidth + 4;
if (urc->wId == IDC_FRAME) {
urc->rcItem.left--; urc->rcItem.top--;
urc->rcItem.right++; urc->rcItem.bottom++;
}
return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM;

case IDC_AVATAR:
Expand Down Expand Up @@ -698,6 +706,10 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (LOWORD(wParam) == WA_ACTIVE)
OnActivate();
break;

case WM_CTLCOLORSTATIC:
if (lParam == (LPARAM)GetDlgItem(m_hwnd, IDC_FRAME))
return (INT_PTR)m_hFrameBrush;
}

return CSuper::DlgProc(uMsg, wParam, lParam);
Expand Down Expand Up @@ -726,45 +738,6 @@ static const CHARRANGE rangeAll = { 0, -1 };
LRESULT CMsgDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_NCPAINT:
if (!m_sEncryption.IsEmpty()) {
RECT rect;
GetWindowRect(m_message.GetHwnd(), &rect);
HRGN region = NULL;
if (wParam == NULLREGION) {
region = CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
}
else {
HRGN copy = CreateRectRgn(0, 0, 0, 0);
if (CombineRgn(copy, (HRGN)wParam, NULL, RGN_COPY))
region = copy;
else
DeleteObject(copy);
}

if (region) {
HRGN region2 = CreateRectRgn(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1);
CombineRgn(region, region, region2, RGN_DIFF);
DeleteObject(region2);
}

if (HDC hdc = GetDCEx(m_message.GetHwnd(), region, DCX_WINDOW | DCX_CACHE | DCX_INTERSECTRGN | DCX_LOCKWINDOWUPDATE)) {
HPEN pen = CreatePen(PS_INSIDEFRAME, 1, RGB(0, 220, 0));
HGDIOBJ old = SelectObject(hdc, pen);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
Rectangle(hdc, 0, 0, width, height);
SelectObject(hdc, old);
ReleaseDC(m_message.GetHwnd(), hdc);
DeleteObject(pen);
}
else if (region)
DeleteObject(region);

return 0;
}
break;

case EM_REPLACESEL:
PostMessage(m_message.GetHwnd(), EM_ACTIVATE, 0, 0);
break;
Expand Down Expand Up @@ -898,9 +871,7 @@ LRESULT CMsgDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam)
const char* enc = (const char*)CallProtoService(m_szProto, PS_GETCAPS, PFLAG_GETCURRENTENCRYPTION, m_hContact);
if (enc == (const char *)CALLSERVICE_NOTFOUND)
enc = nullptr;
if (!m_sEncryption.IsEmpty() ^ (bool)enc)
RedrawWindow(m_message.GetHwnd(), NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
m_sEncryption = enc;
ShowWindow(GetDlgItem(m_hwnd, IDC_FRAME), enc ? SW_SHOW : SW_HIDE);
}

case WM_KEYDOWN:
Expand Down
2 changes: 1 addition & 1 deletion src/core/stdmsg/src/msgs.h
Expand Up @@ -81,7 +81,7 @@ class CMsgDialog : public CSrmmBaseDialog
uint16_t m_wMinute = 0;
bool m_bIsMeta = false, m_bWindowCascaded = false, m_bNoActivate = false;
int m_iBBarHeight = 28;
CMStringA m_sEncryption;
HBRUSH m_hFrameBrush;

public:
CMsgDialog(CTabbedWindow *pOwner, MCONTACT hContact);
Expand Down
1 change: 1 addition & 0 deletions src/core/stdmsg/src/resource.h
Expand Up @@ -146,6 +146,7 @@
#define IDC_AVATARHEIGHT 1613
#define IDC_SHOWSECS 1614
#define IDC_POPLIST 1616
#define IDC_FRAME 1617
#define IDC_USETABS 1620
#define IDC_CLOSETABS 1621
#define IDC_TABSBOTTOM 1623
Expand Down

0 comments on commit aba622e

Please sign in to comment.