diff options
-rw-r--r-- | Plugins/emoticons/EmoticonsSelectionLayout.cpp | 272 | ||||
-rw-r--r-- | Plugins/emoticons/EmoticonsSelectionLayout.h | 68 | ||||
-rw-r--r-- | Plugins/emoticons/GroupListEmoticons.cpp | 393 | ||||
-rw-r--r-- | Plugins/emoticons/GroupListEmoticons.h | 48 | ||||
-rw-r--r-- | Plugins/emoticons/SingleListEmoticons.cpp | 186 | ||||
-rw-r--r-- | Plugins/emoticons/SingleListEmoticons.h | 31 | ||||
-rw-r--r-- | Plugins/emoticons/commons.h | 5 | ||||
-rw-r--r-- | Plugins/emoticons/emoticons.cpp | 2 | ||||
-rw-r--r-- | Plugins/emoticons/emoticons.dsp | 24 | ||||
-rw-r--r-- | Plugins/emoticons/emoticons.vcproj | 24 | ||||
-rw-r--r-- | Plugins/emoticons/options.cpp | 1 | ||||
-rw-r--r-- | Plugins/emoticons/selwin.cpp | 475 |
12 files changed, 1110 insertions, 419 deletions
diff --git a/Plugins/emoticons/EmoticonsSelectionLayout.cpp b/Plugins/emoticons/EmoticonsSelectionLayout.cpp new file mode 100644 index 0000000..a30bed0 --- /dev/null +++ b/Plugins/emoticons/EmoticonsSelectionLayout.cpp @@ -0,0 +1,272 @@ +#include "commons.h"
+
+void EmoticonsSelectionLayout::SetSelection(HWND hwnd, int sel)
+{
+ if (sel < 0)
+ sel = -1;
+ if (sel >= ssd->module->emoticons.getCount())
+ sel = -1;
+ if (sel != selection)
+ {
+ InvalidateRect(hwnd, NULL, FALSE);
+ selection = sel;
+ }
+}
+
+
+void EmoticonsSelectionLayout::DestroyToolTips()
+{
+ for(int i = 0; i < ssd->module->emoticons.getCount(); i++)
+ {
+ Emoticon *e = ssd->module->emoticons[i];
+
+ if (e->tt != NULL)
+ {
+ DestroyWindow(e->tt);
+ e->tt = NULL;
+ }
+ }
+}
+
+
+HFONT EmoticonsSelectionLayout::GetFont(HDC hdc)
+{
+ HFONT hFont;
+
+ if (ssd->hwndTarget != NULL)
+ {
+ CHARFORMAT2 cf;
+ ZeroMemory(&cf, sizeof(cf));
+ cf.cbSize = sizeof(cf);
+ cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_CHARSET | CFM_FACE | CFM_WEIGHT | CFM_SIZE;
+ SendMessage(ssd->hwndTarget, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
+
+ LOGFONT lf = {0};
+ lf.lfHeight = -MulDiv(cf.yHeight / 20, GetDeviceCaps(hdc, LOGPIXELSY), 72);
+ lf.lfWeight = cf.wWeight;
+ lf.lfItalic = (cf.dwEffects & CFE_ITALIC) == CFE_ITALIC;
+ lf.lfCharSet = cf.bCharSet;
+ lf.lfPitchAndFamily = cf.bPitchAndFamily;
+ lstrcpyn(lf.lfFaceName, cf.szFaceName, MAX_REGS(lf.lfFaceName));
+
+ hFont = CreateFontIndirect(&lf);
+ }
+ else
+ {
+ hFont = (HFONT) SendMessage(hwnd, WM_GETFONT, 0, 0);
+ }
+
+ return hFont;
+}
+
+void EmoticonsSelectionLayout::ReleaseFont(HFONT hFont)
+{
+ if (ssd->hwndTarget != NULL)
+ DeleteObject(hFont);
+}
+
+RECT EmoticonsSelectionLayout::CalcRect(TCHAR *txt)
+{
+ HDC hdc = GetDC(hwnd);
+ HFONT hFont = GetFont(hdc);
+ HFONT oldFont = (HFONT) SelectObject(hdc, hFont);
+
+ RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
+ DrawText(hdc, txt, lstrlen(txt), &rc, DT_CALCRECT | DT_NOPREFIX);
+
+ SelectObject(hdc, oldFont);
+ ReleaseFont(hFont);
+
+ ReleaseDC(hwnd, hdc);
+ return rc;
+}
+
+void EmoticonsSelectionLayout::GetEmoticonSize(Emoticon *e, int &width, int &height)
+{
+ width = 0;
+ height = 0;
+
+ if (e->img != NULL)
+ e->img->Load(height, width);
+
+ if (e->img == NULL || e->img->img == NULL)
+ {
+ RECT rc = CalcRect(e->texts[0]);
+ height = rc.bottom - rc.top + 1;
+ width = rc.right - rc.left + 1;
+ }
+}
+
+int EmoticonsSelectionLayout::GetNumOfCols(int num_emotes)
+{
+ int cols = num_emotes / MAX_LINES;
+ if (num_emotes % MAX_LINES != 0)
+ cols++;
+ return min(max(cols, MIN_COLS), MAX_COLS);
+}
+
+int EmoticonsSelectionLayout::GetNumOfLines(int num_emotes, int cols)
+{
+ int lines = num_emotes / cols;
+ if (num_emotes % cols != 0)
+ lines++;
+ return lines;
+}
+
+
+
+HWND CreateTooltip(HWND hwnd, RECT &rect, TCHAR *text)
+{
+ // struct specifying control classes to register
+ INITCOMMONCONTROLSEX iccex;
+ HWND hwndTT; // handle to the ToolTip control
+ // struct specifying info about tool in ToolTip control
+ TOOLINFO ti;
+ unsigned int uid = 0; // for ti initialization
+
+ // Load the ToolTip class from the DLL.
+ iccex.dwSize = sizeof(iccex);
+ iccex.dwICC = ICC_BAR_CLASSES;
+
+ if(!InitCommonControlsEx(&iccex))
+ return NULL;
+
+ /* CREATE A TOOLTIP WINDOW */
+ hwndTT = CreateWindowEx(WS_EX_TOPMOST,
+ TOOLTIPS_CLASS,
+ NULL,
+ WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ hwnd,
+ NULL,
+ hInst,
+ NULL
+ );
+
+ /* Gives problem with mToolTip
+ SetWindowPos(hwndTT,
+ HWND_TOPMOST,
+ 0,
+ 0,
+ 0,
+ 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ */
+
+ /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
+ ti.cbSize = sizeof(TOOLINFO);
+ ti.uFlags = TTF_SUBCLASS;
+ ti.hwnd = hwnd;
+ ti.hinst = hInst;
+ ti.uId = uid;
+ ti.lpszText = text;
+ // ToolTip control will cover the whole window
+ ti.rect.left = rect.left;
+ ti.rect.top = rect.top;
+ ti.rect.right = rect.right;
+ ti.rect.bottom = rect.bottom;
+
+ /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
+ SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
+ SendMessage(hwndTT, TTM_SETDELAYTIME, (WPARAM) (DWORD) TTDT_AUTOPOP, (LPARAM) MAKELONG(24 * 60 * 60 * 1000, 0));
+
+ return hwndTT;
+}
+
+
+void EmoticonsSelectionLayout::CreateEmoticonToolTip(Emoticon *e, RECT fr)
+{
+ Buffer<TCHAR> tt;
+ if (e->description[0] != _T('\0'))
+ {
+ tt += _T(" ");
+ tt += e->description;
+ tt.translate();
+ tt += _T(" ");
+ }
+
+ for(int k = 0; k < e->texts.getCount(); k++)
+ {
+ tt += _T(" ");
+ tt += e->texts[k];
+ tt += _T(" ");
+ }
+ tt.pack();
+
+ e->tt = CreateTooltip(hwnd, fr, tt.str);
+}
+
+void EmoticonsSelectionLayout::EraseBackground(HDC hdc)
+{
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+
+ HBRUSH hB = CreateSolidBrush(ssd->background);
+ FillRect(hdc, &rc, hB);
+ DeleteObject(hB);
+}
+
+void EmoticonsSelectionLayout::DrawEmoticonText(HDC hdc, TCHAR *txt, RECT rc)
+{
+ HFONT hFont = GetFont(hdc);
+ HFONT oldFont = (HFONT) SelectObject(hdc, hFont);
+
+ DrawText(hdc, txt, lstrlen(txt), &rc, DT_NOPREFIX);
+
+ SelectObject(hdc, oldFont);
+ ReleaseFont(hFont);
+}
+
+void EmoticonsSelectionLayout::DrawEmoticon(HDC hdc, int index, RECT fullRc)
+{
+ Emoticon *e = ssd->module->emoticons[index];
+
+ int width, height;
+ GetEmoticonSize(e, width, height);
+
+ RECT rc = fullRc;
+ rc.left += (rc.right - rc.left - width) / 2;
+ rc.top += (rc.bottom - rc.top - height) / 2;
+ rc.right = rc.left + width;
+ rc.bottom = rc.top + height;
+
+ if (e->img == NULL || e->img->img == NULL)
+ {
+ DrawEmoticonText(hdc, e->texts[0], rc);
+ }
+ else
+ {
+ HDC hdc_img = CreateCompatibleDC(hdc);
+ HBITMAP old_bmp = (HBITMAP) SelectObject(hdc_img, e->img->img);
+
+ if (e->img->transparent)
+ {
+ BLENDFUNCTION bf = {0};
+ bf.SourceConstantAlpha = 255;
+ bf.AlphaFormat = AC_SRC_ALPHA;
+ AlphaBlend(hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
+ hdc_img, 0, 0, rc.right - rc.left, rc.bottom - rc.top, bf);
+ }
+ else
+ {
+ BitBlt(hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
+ hdc_img, 0, 0, SRCCOPY);
+ }
+
+ SelectObject(hdc_img, old_bmp);
+ DeleteDC(hdc_img);
+ }
+
+ if (selection == index)
+ {
+ rc = fullRc;
+ rc.left -= 2;
+ rc.right += 2;
+ rc.top -= 2;
+ rc.bottom += 2;
+ FrameRect(hdc, &rc, (HBRUSH) GetStockObject(GRAY_BRUSH));
+ }
+}
diff --git a/Plugins/emoticons/EmoticonsSelectionLayout.h b/Plugins/emoticons/EmoticonsSelectionLayout.h new file mode 100644 index 0000000..e0b2bb7 --- /dev/null +++ b/Plugins/emoticons/EmoticonsSelectionLayout.h @@ -0,0 +1,68 @@ +#define MIN_COLS 5
+#define MAX_LINES 8
+#define MAX_COLS 12
+#define BORDER 3
+
+
+struct EmoticonSelectionData
+{
+ Module *module;
+ COLORREF background;
+
+ int xPosition;
+ int yPosition;
+ int Direction;
+ HWND hwndTarget;
+ UINT targetMessage;
+ LPARAM targetWParam;
+};
+
+
+class EmoticonsSelectionLayout
+{
+public:
+ EmoticonSelectionData *ssd;
+ HWND hwnd;
+ int selection;
+
+ struct {
+ int width;
+ int height;
+ } window;
+
+ virtual void Load() = 0;
+
+ virtual void OnUp(HWND hwnd) = 0;
+ virtual void OnDown(HWND hwnd) = 0;
+ virtual void OnLeft(HWND hwnd) = 0;
+ virtual void OnRight(HWND hwnd) = 0;
+
+ virtual void Draw(HDC hdc) = 0;
+
+ virtual void SetSelection(HWND hwnd, POINT p) = 0;
+
+ void SetSelection(HWND hwnd, int sel);
+
+ virtual void CreateToolTips() = 0;
+
+ void DestroyToolTips();
+
+protected:
+
+ HFONT GetFont(HDC hdc);
+ void ReleaseFont(HFONT hFont);
+ RECT CalcRect(TCHAR *txt);
+
+ void GetEmoticonSize(Emoticon *e, int &width, int &height);
+
+ int GetNumOfCols(int num_emotes);
+ int GetNumOfLines(int num_emotes, int cols);
+
+ void CreateEmoticonToolTip(Emoticon *e, RECT fr);
+
+ void EraseBackground(HDC hdc);
+
+ void DrawEmoticon(HDC hdc, int index, RECT rc);
+ void DrawEmoticonText(HDC hdc, TCHAR *txt, RECT rc);
+
+};
diff --git a/Plugins/emoticons/GroupListEmoticons.cpp b/Plugins/emoticons/GroupListEmoticons.cpp new file mode 100644 index 0000000..83a9e5f --- /dev/null +++ b/Plugins/emoticons/GroupListEmoticons.cpp @@ -0,0 +1,393 @@ +#include "commons.h"
+
+
+void GroupListEmoticons::Load()
+{
+ selection = -1;
+
+ num_groups = CountGroups();
+ groups = (Group *) malloc(num_groups * sizeof(Group));
+
+ char *current_group = ssd->module->emoticons[0]->group;
+
+ int current_id = -1;
+ int i;
+ for(i = 0; i < ssd->module->emoticons.getCount(); i++)
+ {
+ Emoticon *e = ssd->module->emoticons[i];
+
+ if (stricmp(e->group, current_group) != 0 || i == 0)
+ {
+ if (i != 0)
+ groups[current_id].end = i - 1;
+
+ current_group = e->group;
+ current_id++;
+
+ SetGroupName(groups[current_id], current_group);
+ groups[current_id].start = i;
+ }
+ }
+ groups[current_id].end = i - 1;
+
+ // First calc the width
+ window.width = 0;
+ for(i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+ group.count = group.end - group.start + 1;
+ GetMaxEmoticonSize(group);
+ group.cols = GetNumOfCols(group.count);
+
+ if (group.name[0] != '\0')
+ {
+ RECT rc = CalcRect(group.name);
+ window.width = max(window.width, rc.right - rc.left + 2 * BORDER + 1);
+ }
+
+ window.width = max(window.width, group.max_width * group.cols + (group.cols + 1) * BORDER);
+ }
+
+ // Now calc the height
+ window.height = 0;
+ for(i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+ group.top = window.height;
+
+ // Recalc the num of cols
+ int w = window.width - BORDER;
+ group.cols = w / (group.max_width + BORDER);
+
+ // If there is space left, put it into the emoticons
+ group.max_width += (w - group.cols * (group.max_width + BORDER)) / group.cols;
+
+ group.lines = GetNumOfLines(group.count, group.cols);
+
+ if (group.name[0] != '\0')
+ {
+ RECT rc = CalcRect(group.name);
+ window.height += HeightWithBorders(rc);
+ }
+
+ window.height += group.max_height * group.lines + (group.lines + 1) * BORDER;
+ }
+}
+
+
+int GroupListEmoticons::CountGroups()
+{
+ int groups = 1;
+ char *current_group = ssd->module->emoticons[0]->group;
+ for(int i = 1; i < ssd->module->emoticons.getCount(); i++)
+ {
+ Emoticon *e = ssd->module->emoticons[i];
+
+ if (stricmp(e->group, current_group) != 0)
+ {
+ current_group = e->group;
+ groups++;
+ }
+ }
+ return groups;
+}
+
+
+void GroupListEmoticons::SetGroupName(Group &group, char *name)
+{
+ TCHAR *tmp = mir_a2t(name);
+ group.name = mir_tstrdup(TranslateTS(tmp));
+ mir_free(tmp);
+}
+
+
+void GroupListEmoticons::GetMaxEmoticonSize(Group &group)
+{
+ group.max_height = 4;
+ group.max_width = 4;
+
+ for(int i = group.start; i <= group.end; i++)
+ {
+ Emoticon *e = ssd->module->emoticons[i];
+
+ int height, width;
+ GetEmoticonSize(e, width, height);
+
+ group.max_height = max(group.max_height, height);
+ group.max_width = max(group.max_width, width);
+ }
+}
+
+
+RECT GroupListEmoticons::GetEmoticonRect(Group &group, int index)
+{
+ int pos = index - group.start;
+ int line = pos / group.cols;
+ int col = pos % group.cols;
+
+ RECT rc;
+ rc.left = BORDER + col * (group.max_width + BORDER);
+ rc.top = BORDER + line * (group.max_height + BORDER);
+ rc.right = rc.left + group.max_width;
+ rc.bottom = rc.top + group.max_height;
+ return rc;
+}
+
+
+void GroupListEmoticons::CreateToolTips()
+{
+ int top = 0;
+
+ for(int i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+
+ if (group.name[0] != '\0')
+ {
+ RECT rc = CalcRect(group.name);
+ top += HeightWithBorders(rc);
+ }
+
+ for (int j = group.start; j <= group.end; j++)
+ {
+ Emoticon *e = ssd->module->emoticons[j];
+
+ RECT rc = GetEmoticonRect(group, j);
+ rc.top += top;
+ rc.bottom += top;
+ CreateEmoticonToolTip(e, rc);
+ }
+
+ top += group.max_height * group.lines + (group.lines + 1) * BORDER;
+ }
+}
+
+int GroupListEmoticons::HeightWithBorders(RECT rc)
+{
+ return rc.bottom - rc.top + 2 * BORDER + 1;
+}
+
+int GroupListEmoticons::GetIndex(Group &group, int line, int col)
+{
+ return line * group.cols + col + group.start;
+}
+
+void GroupListEmoticons::SetSelection(HWND hwnd, POINT p)
+{
+ // first find group
+ int i;
+ for(i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+ if (group.top > p.y)
+ break;
+ }
+ i--;
+
+ Group &group = groups[i];
+
+ p.y -= group.top;
+ if (group.name[0] != '\0')
+ {
+ RECT rc = CalcRect(group.name);
+ p.y -= HeightWithBorders(rc);
+ }
+
+ int col;
+ if (p.x % (BORDER + group.max_width) < BORDER)
+ col = -1;
+ else
+ col = p.x / (BORDER + group.max_width);
+
+ int line;
+ if (p.y % (BORDER + group.max_height) < BORDER)
+ line = -1;
+ else
+ line = p.y / (BORDER + group.max_height);
+
+ int index = GetIndex(group, line, col);
+
+ if (col >= 0 && line >= 0 && index <= group.end)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ else
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, -1);
+ }
+}
+
+int GroupListEmoticons::GetGroupByEmoticonIndex(int index)
+{
+ for(int i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+ if (index >= group.start && index <= group.end)
+ return i;
+ }
+ return 0;
+}
+
+void GroupListEmoticons::OnUp(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, ssd->module->emoticons.getCount() - 1);
+ }
+ else
+ {
+ int group_index = GetGroupByEmoticonIndex(selection);
+ Group *group = &groups[group_index];
+
+ int line = (selection - group->start) / group->cols;
+ int col = (selection - group->start) % group->cols;
+
+ line--;
+ int index = GetIndex(*group, line, col);
+
+ if (index >= group->start && index <= group->end)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ else
+ {
+ group_index--;
+ if (group_index < 0)
+ {
+ group_index = num_groups - 1;
+ col--;
+ }
+ group = &groups[group_index];
+
+ line = group->lines - 1;
+ if (group_index == num_groups - 1 && col < 0)
+ col = group->cols - 1;
+ else
+ col = max(0, min(col, group->cols - 1));
+
+ index = GetIndex(*group, line, col);
+ if (index < group->start || index > group->end)
+ index = GetIndex(*group, line-1, col);
+
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ }
+}
+
+void GroupListEmoticons::OnDown(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, 0);
+ }
+ else
+ {
+ int group_index = GetGroupByEmoticonIndex(selection);
+ Group *group = &groups[group_index];
+
+ int line = (selection - group->start) / group->cols;
+ int col = (selection - group->start) % group->cols;
+
+ line++;
+ int index = GetIndex(*group, line, col);
+
+ if (index >= group->start && index <= group->end)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ else
+ {
+ group_index++;
+ if (group_index >= num_groups)
+ {
+ group_index = 0;
+ col++;
+ }
+ group = &groups[group_index];
+
+ line = 0;
+ if (group_index != 0)
+ col = min(col, group->cols - 1);
+ else if (col >= group->cols)
+ col = 0;
+
+ index = GetIndex(*group, line, col);
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ }
+}
+
+void GroupListEmoticons::OnLeft(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, ssd->module->emoticons.getCount() - 1);
+ }
+ else
+ {
+ int index = (selection - 1) % ssd->module->emoticons.getCount();
+ if (index < 0)
+ index += ssd->module->emoticons.getCount();
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+}
+
+void GroupListEmoticons::OnRight(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, 0);
+ }
+ else
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, (selection + 1) % ssd->module->emoticons.getCount());
+ }
+}
+
+void GroupListEmoticons::Draw(HDC hdc)
+{
+ EraseBackground(hdc);
+
+ RECT client_rc;
+ GetClientRect(hwnd, &client_rc);
+
+ int top = 0;
+
+ for(int i = 0; i < num_groups; i++)
+ {
+ Group &group = groups[i];
+
+ if (group.name[0] != '\0')
+ {
+ RECT rc = CalcRect(group.name);
+ rc.top += top + BORDER;
+ rc.bottom += top + BORDER;
+
+ int width = rc.right - rc.left;
+ rc.left = client_rc.left + (client_rc.right - client_rc.left - width) / 2;
+ rc.right = rc.left + width;
+
+ RECT title_rc = client_rc;
+ title_rc.top = rc.top - BORDER;
+ title_rc.bottom = rc.bottom + BORDER + 1;
+ HBRUSH hB = CreateSolidBrush(RGB(200,200,200));
+ FillRect(hdc, &title_rc, hB);
+ DeleteObject(hB);
+
+ DrawEmoticonText(hdc, group.name, rc);
+
+ top += HeightWithBorders(rc);
+ }
+
+ for (int j = group.start; j <= group.end; j++)
+ {
+ RECT rc = GetEmoticonRect(group, j);
+ rc.top += top;
+ rc.bottom += top;
+
+ DrawEmoticon(hdc, j, rc);
+ }
+
+ top += group.max_height * group.lines + (group.lines + 1) * BORDER;
+ }
+}
diff --git a/Plugins/emoticons/GroupListEmoticons.h b/Plugins/emoticons/GroupListEmoticons.h new file mode 100644 index 0000000..3243dbc --- /dev/null +++ b/Plugins/emoticons/GroupListEmoticons.h @@ -0,0 +1,48 @@ +class GroupListEmoticons : public EmoticonsSelectionLayout
+{
+public:
+ struct Group {
+ TCHAR *name;
+ int start;
+ int end;
+ int count;
+ int max_height;
+ int max_width;
+ int lines;
+ int cols;
+ int top;
+ };
+
+ struct {
+ int line;
+ int col;
+ } sel;
+
+ int num_groups;
+ Group *groups;
+
+ virtual void Load();
+
+ void SetGroupName(Group &group, char *name);
+
+ int CountGroups();
+
+ void GetMaxEmoticonSize(Group &group);
+
+ RECT GetEmoticonRect(Group &group, int index);
+
+ virtual void CreateToolTips();
+
+ virtual void SetSelection(HWND hwnd, POINT p);
+
+ int GetIndex(Group &group, int col, int line);
+ int GetGroupByEmoticonIndex(int index);
+ int HeightWithBorders(RECT rc);
+
+ virtual void OnUp(HWND hwnd);
+ virtual void OnDown(HWND hwnd);
+ virtual void OnLeft(HWND hwnd);
+ virtual void OnRight(HWND hwnd);
+
+ virtual void Draw(HDC hdc);
+};
diff --git a/Plugins/emoticons/SingleListEmoticons.cpp b/Plugins/emoticons/SingleListEmoticons.cpp new file mode 100644 index 0000000..740d1e8 --- /dev/null +++ b/Plugins/emoticons/SingleListEmoticons.cpp @@ -0,0 +1,186 @@ +#include "commons.h"
+
+void SingleListEmoticons::GetMaxEmoticonSize()
+{
+ emoticons.max_height = 4;
+ emoticons.max_width = 4;
+
+ for(int i = 0; i < emoticons.count; i++)
+ {
+ Emoticon *e = ssd->module->emoticons[i];
+
+ int height, width;
+ GetEmoticonSize(e, width, height);
+
+ emoticons.max_height = max(emoticons.max_height, height);
+ emoticons.max_width = max(emoticons.max_width, width);
+ }
+}
+
+int SingleListEmoticons::GetEmoticonCountRoundedByCols()
+{
+ int roundCount = ssd->module->emoticons.getCount();
+ if (roundCount % emoticons.cols != 0)
+ roundCount += emoticons.cols - (roundCount % emoticons.cols);
+ return roundCount;
+}
+
+void SingleListEmoticons::CreateToolTips()
+{
+ for(int line = 0; line < emoticons.lines; line++)
+ {
+ for(int col = 0; col < emoticons.cols; col++)
+ {
+ int index = line * emoticons.cols + col;
+ if (index >= emoticons.count)
+ break;
+
+ Emoticon *e = ssd->module->emoticons[index];
+ CreateEmoticonToolTip(e, GetEmoticonRect(line, col));
+ }
+ }
+}
+
+void SingleListEmoticons::Load()
+{
+ selection = -1;
+
+ emoticons.count = ssd->module->emoticons.getCount();
+
+ GetMaxEmoticonSize();
+
+ emoticons.cols = GetNumOfCols(emoticons.count);
+ emoticons.lines = GetNumOfLines(emoticons.count, emoticons.cols);
+
+ window.width = emoticons.max_width * emoticons.cols + (emoticons.cols + 1) * BORDER + 1;
+ window.height = emoticons.max_height * emoticons.lines + (emoticons.lines + 1) * BORDER + 1;
+}
+
+void SingleListEmoticons::SetSelection(HWND hwnd, POINT p)
+{
+ int col;
+ if (p.x % (BORDER + emoticons.max_width) < BORDER)
+ col = -1;
+ else
+ col = p.x / (BORDER + emoticons.max_width);
+
+ int line;
+ if (p.y % (BORDER + emoticons.max_height) < BORDER)
+ line = -1;
+ else
+ line = p.y / (BORDER + emoticons.max_height);
+
+ int index = line * emoticons.cols + col;
+
+ if (col >= 0 && line >= 0 && index < ssd->module->emoticons.getCount())
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+ else
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, -1);
+ }
+}
+
+void SingleListEmoticons::OnUp(HWND hwnd)
+{
+ if (selection < 0)
+ {
+// int index = GetEmoticonCountRoundedByCols() - 1;
+// if (index >= ssd->module->emoticons.getCount())
+// index -= emoticons.cols;
+//
+// EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ EmoticonsSelectionLayout::SetSelection(hwnd, ssd->module->emoticons.getCount() - 1);
+ }
+ else
+ {
+ int roundCount = GetEmoticonCountRoundedByCols();
+
+ int index = (selection - emoticons.cols) % roundCount;
+ if (index < 0)
+ index += roundCount - 1;
+ if (index >= ssd->module->emoticons.getCount())
+ index -= emoticons.cols;
+
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+}
+
+void SingleListEmoticons::OnDown(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, 0);
+ }
+ else
+ {
+ int roundCount = GetEmoticonCountRoundedByCols();
+
+ int index = selection + emoticons.cols;
+ if (index >= roundCount)
+ {
+ index = (index + 1) % roundCount;
+ if (index >= ssd->module->emoticons.getCount())
+ index = (index + emoticons.cols) % roundCount;
+ }
+ else if (index >= ssd->module->emoticons.getCount())
+ index = (index + emoticons.cols + 1) % roundCount % emoticons.cols;
+
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+}
+
+void SingleListEmoticons::OnLeft(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, emoticons.cols - 1);
+ }
+ else
+ {
+ int index = (selection - 1) % ssd->module->emoticons.getCount();
+ if (index < 0)
+ index += ssd->module->emoticons.getCount();
+ EmoticonsSelectionLayout::SetSelection(hwnd, index);
+ }
+}
+
+void SingleListEmoticons::OnRight(HWND hwnd)
+{
+ if (selection < 0)
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, 0);
+ }
+ else
+ {
+ EmoticonsSelectionLayout::SetSelection(hwnd, (selection + 1) % ssd->module->emoticons.getCount());
+ }
+}
+
+RECT SingleListEmoticons::GetEmoticonRect(int line, int col)
+{
+ RECT rc;
+ rc.left = BORDER + col * (emoticons.max_width + BORDER);
+ rc.top = BORDER + line * (emoticons.max_height + BORDER);
+ rc.right = rc.left + emoticons.max_width;
+ rc.bottom = rc.top + emoticons.max_height;
+ return rc;
+}
+
+void SingleListEmoticons::Draw(HDC hdc)
+{
+ EraseBackground(hdc);
+
+ for(int line = 0; line < emoticons.lines; line++)
+ {
+ for(int col = 0; col < emoticons.cols; col++)
+ {
+ int index = line * emoticons.cols + col;
+ if (index >= emoticons.count)
+ break;
+
+ DrawEmoticon(hdc, index, GetEmoticonRect(line, col));
+ }
+ }
+}
diff --git a/Plugins/emoticons/SingleListEmoticons.h b/Plugins/emoticons/SingleListEmoticons.h new file mode 100644 index 0000000..9cdf5df --- /dev/null +++ b/Plugins/emoticons/SingleListEmoticons.h @@ -0,0 +1,31 @@ +class SingleListEmoticons : public EmoticonsSelectionLayout
+{
+public:
+ struct {
+ int count;
+ int max_height;
+ int max_width;
+ int lines;
+ int cols;
+ } emoticons;
+
+ virtual void Load();
+
+ void GetMaxEmoticonSize();
+
+ int GetEmoticonCountRoundedByCols();
+
+ virtual void CreateToolTips();
+
+ virtual void SetSelection(HWND hwnd, POINT p);
+
+ virtual void OnUp(HWND hwnd);
+ virtual void OnDown(HWND hwnd);
+ virtual void OnLeft(HWND hwnd);
+ virtual void OnRight(HWND hwnd);
+
+ virtual void Draw(HDC hdc);
+
+ RECT GetEmoticonRect(int line, int col);
+
+};
diff --git a/Plugins/emoticons/commons.h b/Plugins/emoticons/commons.h index 44ea7e9..857840a 100644 --- a/Plugins/emoticons/commons.h +++ b/Plugins/emoticons/commons.h @@ -135,7 +135,7 @@ struct Emoticon // For selection window
HWND tt;
- Emoticon() : name(0), description(0), group(0), texts(20), img(0), tt(0) {}
+ Emoticon() : name(0), description(0), group(""), texts(20), img(0), tt(0) {}
~Emoticon();
};
@@ -225,6 +225,9 @@ void FillModuleImages(EmoticonPack *pack); +#include "EmoticonsSelectionLayout.h"
+#include "SingleListEmoticons.h"
+#include "GroupListEmoticons.h"
#endif // __COMMONS_H__
diff --git a/Plugins/emoticons/emoticons.cpp b/Plugins/emoticons/emoticons.cpp index 5bb9c70..16b3d6e 100644 --- a/Plugins/emoticons/emoticons.cpp +++ b/Plugins/emoticons/emoticons.cpp @@ -1362,7 +1362,7 @@ BOOL LoadModule(Module *m) char tmp[1024];
char c;
int pos = 0;
- char *group = NULL;
+ char *group = "";
do
{
c = fgetc(file);
diff --git a/Plugins/emoticons/emoticons.dsp b/Plugins/emoticons/emoticons.dsp index 3714cab..b7baf04 100644 --- a/Plugins/emoticons/emoticons.dsp +++ b/Plugins/emoticons/emoticons.dsp @@ -168,6 +168,14 @@ SOURCE=..\utils\ContactAsyncQueue.h # End Source File
# Begin Source File
+SOURCE=.\EmoticonsSelectionLayout.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\GroupListEmoticons.h
+# End Source File
+# Begin Source File
+
SOURCE=.\m_emoticons.h
# End Source File
# Begin Source File
@@ -198,6 +206,10 @@ SOURCE=.\resource.h SOURCE=.\selwin.h
# End Source File
+# Begin Source File
+
+SOURCE=.\SingleListEmoticons.h
+# End Source File
# End Group
# Begin Group "Resource Files"
@@ -220,6 +232,14 @@ SOURCE=.\emoticons.cpp # End Source File
# Begin Source File
+SOURCE=.\EmoticonsSelectionLayout.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\GroupListEmoticons.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\utils\mir_icons.cpp
# End Source File
# Begin Source File
@@ -242,6 +262,10 @@ SOURCE=.\options.cpp SOURCE=.\selwin.cpp
# End Source File
+# Begin Source File
+
+SOURCE=.\SingleListEmoticons.cpp
+# End Source File
# End Group
# Begin Group "Docs"
diff --git a/Plugins/emoticons/emoticons.vcproj b/Plugins/emoticons/emoticons.vcproj index f359277..7556852 100644 --- a/Plugins/emoticons/emoticons.vcproj +++ b/Plugins/emoticons/emoticons.vcproj @@ -431,6 +431,14 @@ >
</File>
<File
+ RelativePath=".\EmoticonsSelectionLayout.h"
+ >
+ </File>
+ <File
+ RelativePath=".\GroupListEmoticons.h"
+ >
+ </File>
+ <File
RelativePath="m_emoticons.h"
>
</File>
@@ -462,6 +470,10 @@ RelativePath=".\selwin.h"
>
</File>
+ <File
+ RelativePath=".\SingleListEmoticons.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
@@ -553,6 +565,14 @@ </FileConfiguration>
</File>
<File
+ RelativePath=".\EmoticonsSelectionLayout.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\GroupListEmoticons.cpp"
+ >
+ </File>
+ <File
RelativePath="..\utils\mir_icons.cpp"
>
<FileConfiguration
@@ -756,6 +776,10 @@ RelativePath=".\selwin.cpp"
>
</File>
+ <File
+ RelativePath=".\SingleListEmoticons.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Docs"
diff --git a/Plugins/emoticons/options.cpp b/Plugins/emoticons/options.cpp index 76b68a1..7f1b513 100644 --- a/Plugins/emoticons/options.cpp +++ b/Plugins/emoticons/options.cpp @@ -100,6 +100,7 @@ void LoadOptions() }
+#undef BORDER
#define BORDER 5
diff --git a/Plugins/emoticons/selwin.cpp b/Plugins/emoticons/selwin.cpp index 9aba03c..4395b76 100644 --- a/Plugins/emoticons/selwin.cpp +++ b/Plugins/emoticons/selwin.cpp @@ -1,40 +1,6 @@ #include "commons.h"
-#define MIN_COLS 5
-#define MAX_LINES 8
-#define MAX_COLS 12
-#define BORDER 3
-
-
-struct EmoticonSelectionData
-{
- Module *module;
- COLORREF background;
- int max_height;
- int max_width;
- int lines;
- int cols;
- int selection;
-
- int xPosition;
- int yPosition;
- int Direction;
- HWND hwndTarget;
- UINT targetMessage;
- LPARAM targetWParam;
-
- void SetSelection(HWND hwnd, int sel)
- {
- if (sel < 0)
- sel = -1;
- if (sel >= module->emoticons.getCount())
- sel = -1;
- if (sel != selection)
- InvalidateRect(hwnd, NULL, FALSE);
- selection = sel;
- }
-};
HBITMAP CreateBitmap32(int cx, int cy)
@@ -59,68 +25,6 @@ HBITMAP CreateBitmap32(int cx, int cy) }
-HWND CreateTooltip(HWND hwnd, RECT &rect, TCHAR *text)
-{
- // struct specifying control classes to register
- INITCOMMONCONTROLSEX iccex;
- HWND hwndTT; // handle to the ToolTip control
- // struct specifying info about tool in ToolTip control
- TOOLINFO ti;
- unsigned int uid = 0; // for ti initialization
-
- // Load the ToolTip class from the DLL.
- iccex.dwSize = sizeof(iccex);
- iccex.dwICC = ICC_BAR_CLASSES;
-
- if(!InitCommonControlsEx(&iccex))
- return NULL;
-
- /* CREATE A TOOLTIP WINDOW */
- hwndTT = CreateWindowEx(WS_EX_TOPMOST,
- TOOLTIPS_CLASS,
- NULL,
- WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- hwnd,
- NULL,
- hInst,
- NULL
- );
-
- /* Gives problem with mToolTip
- SetWindowPos(hwndTT,
- HWND_TOPMOST,
- 0,
- 0,
- 0,
- 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
- */
-
- /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
- ti.cbSize = sizeof(TOOLINFO);
- ti.uFlags = TTF_SUBCLASS;
- ti.hwnd = hwnd;
- ti.hinst = hInst;
- ti.uId = uid;
- ti.lpszText = text;
- // ToolTip control will cover the whole window
- ti.rect.left = rect.left;
- ti.rect.top = rect.top;
- ti.rect.right = rect.right;
- ti.rect.bottom = rect.bottom;
-
- /* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
- SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
- SendMessage(hwndTT, TTM_SETDELAYTIME, (WPARAM) (DWORD) TTDT_AUTOPOP, (LPARAM) MAKELONG(24 * 60 * 60 * 1000, 0));
-
- return hwndTT;
-}
-
-
void AssertInsideScreen(RECT &rc)
{
// Make sure it is inside screen
@@ -173,144 +77,49 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA {
switch(msg)
{
- case WM_INITDIALOG:
+ case WM_INITDIALOG:
{
EmoticonSelectionData *ssd = (EmoticonSelectionData *) lParam;
- SetWindowLong(hwnd, GWL_USERDATA, (LONG) ssd);
-
- ssd->selection = -1;
- // Load emoticons
- ssd->max_height = 4;
- ssd->max_width = 4;
-
- HDC hdc = GetDC(hwnd);
-
- int num_emotes = ssd->module->emoticons.getCount();
- int i;
- for(i = 0; i < num_emotes; i++)
+ // Get background
+ ssd->background = RGB(255, 255, 255);
+ if (ssd->hwndTarget != NULL)
{
- Emoticon *e = ssd->module->emoticons[i];
- if (e->img != NULL)
- e->img->Load(ssd->max_height, ssd->max_width);
-
- if (e->img == NULL || e->img->img == NULL)
- {
- HFONT hFont;
- if (ssd->hwndTarget != NULL)
- {
- CHARFORMAT2 cf;
- ZeroMemory(&cf, sizeof(cf));
- cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_CHARSET | CFM_FACE | CFM_WEIGHT | CFM_SIZE;
- SendMessage(ssd->hwndTarget, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
-
- LOGFONT lf = {0};
- lf.lfHeight = -MulDiv(cf.yHeight / 20, GetDeviceCaps(hdc, LOGPIXELSY), 72);
- lf.lfWeight = cf.wWeight;
- lf.lfItalic = (cf.dwEffects & CFE_ITALIC) == CFE_ITALIC;
- lf.lfCharSet = cf.bCharSet;
- lf.lfPitchAndFamily = cf.bPitchAndFamily;
- lstrcpyn(lf.lfFaceName, cf.szFaceName, MAX_REGS(lf.lfFaceName));
-
- hFont = CreateFontIndirect(&lf);
- }
- else
- hFont = (HFONT) SendMessage(hwnd, WM_GETFONT, 0, 0);
-
- if (hFont != NULL)
- SelectObject(hdc, hFont);
-
- RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
- DrawText(hdc, e->texts[0], lstrlen(e->texts[0]), &rc, DT_CALCRECT | DT_NOPREFIX);
-
- ssd->max_height = max(ssd->max_height, rc.bottom - rc.top + 1);
- ssd->max_width = max(ssd->max_width, rc.right - rc.left + 1);
-
- if (ssd->hwndTarget != NULL)
- DeleteObject(hFont);
- }
+ ssd->background = SendMessage(ssd->hwndTarget, EM_SETBKGNDCOLOR, 0, ssd->background);
+ SendMessage(ssd->hwndTarget, EM_SETBKGNDCOLOR, 0, ssd->background);
}
- ReleaseDC(hwnd, hdc);
+ // Create positioning object
+ EmoticonsSelectionLayout *layout = new GroupListEmoticons();
+ layout->ssd = ssd;
+ layout->hwnd = hwnd;
+ SetWindowLong(hwnd, GWL_USERDATA, (LONG) layout);
- ssd->cols = num_emotes / MAX_LINES;
- if (num_emotes % MAX_LINES != 0)
- ssd->cols++;
- ssd->cols = min(max(ssd->cols, MIN_COLS), MAX_COLS);
-
- ssd->lines = num_emotes / ssd->cols;
- if (num_emotes % ssd->cols != 0)
- ssd->lines++;
+ layout->Load();
// Calc position
- int width = ssd->max_width * ssd->cols + (ssd->cols + 1) * BORDER + 1;
- int height = ssd->max_height * ssd->lines + (ssd->lines + 1) * BORDER + 1;
int x = ssd->xPosition;
int y = ssd->yPosition;
switch (ssd->Direction)
{
- case 1:
- x -= width;
- break;
- case 2:
- x -= width;
- y -= height;
- break;
- case 3:
- y -= height;
- break;
- }
-
- // Get background
- ssd->background = RGB(255, 255, 255);
- if (ssd->hwndTarget != NULL)
- {
- ssd->background = SendMessage(ssd->hwndTarget, EM_SETBKGNDCOLOR, 0, ssd->background);
- SendMessage(ssd->hwndTarget, EM_SETBKGNDCOLOR, 0, ssd->background);
+ case 1:
+ x -= layout->window.width;
+ break;
+ case 2:
+ x -= layout->window.width;
+ y -= layout->window.height;
+ break;
+ case 3:
+ y -= layout->window.height;
+ break;
}
- RECT rc = { x, y, x + width, y + height };
+ RECT rc = { x, y, x + layout->window.width + 2, y + layout->window.height + 2 };
AssertInsideScreen(rc);
- SetWindowPos(hwnd, HWND_TOPMOST, rc.left, rc.top, width, height, 0);
+ SetWindowPos(hwnd, HWND_TOPMOST, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0);
- for(i = 0; i < ssd->lines; i++)
- {
- for(int j = 0; j < ssd->cols; j++)
- {
- int index = i * ssd->cols + j;
- if (index >= ssd->module->emoticons.getCount())
- break;
-
- Emoticon *e = ssd->module->emoticons[index];
-
- RECT fr;
- fr.left = BORDER + j * (ssd->max_width + BORDER) - 1;
- fr.right = fr.left + ssd->max_width + 2;
- fr.top = BORDER + i * (ssd->max_height + BORDER) - 1;
- fr.bottom = fr.top + ssd->max_height + 2;
-
- Buffer<TCHAR> tt;
- if (e->description[0] != _T('\0'))
- {
- tt += _T(" ");
- tt += e->description;
- tt.translate();
- tt += _T(" ");
- }
-
- for(int k = 0; k < e->texts.getCount(); k++)
- {
- tt += _T(" ");
- tt += e->texts[k];
- tt += _T(" ");
- }
- tt.pack();
-
- e->tt = CreateTooltip(hwnd, fr, tt.str);
- }
- }
+ layout->CreateToolTips();
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
@@ -322,12 +131,12 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA return TRUE;
}
- case WM_PAINT:
+ case WM_PAINT:
{
RECT r;
if (GetUpdateRect(hwnd, &r, FALSE))
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
PAINTSTRUCT ps;
@@ -343,120 +152,22 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA SetBkMode(hdc, TRANSPARENT);
- // Erase background
- HBRUSH hB = CreateSolidBrush(ssd->background);
- FillRect(hdc, &rc, hB);
- DeleteObject(hB);
-
- // Draw emoticons
- for(int i = 0; i < ssd->lines; i++)
- {
- for(int j = 0; j < ssd->cols; j++)
- {
- int index = i * ssd->cols + j;
- if (index >= ssd->module->emoticons.getCount())
- break;
-
- Emoticon *e = ssd->module->emoticons[index];
- if (e->img == NULL || e->img->img == NULL)
- {
- HFONT hFont;
- if (ssd->hwndTarget != NULL)
- {
- CHARFORMAT2 cf;
- ZeroMemory(&cf, sizeof(cf));
- cf.cbSize = sizeof(cf);
- cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_CHARSET | CFM_FACE | CFM_WEIGHT | CFM_SIZE | CFM_COLOR;
- SendMessage(ssd->hwndTarget, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &cf);
-
- LOGFONT lf = {0};
- lf.lfHeight = -MulDiv(cf.yHeight / 20, GetDeviceCaps(hdc, LOGPIXELSY), 72);
- lf.lfWeight = cf.wWeight;
- lf.lfItalic = (cf.dwEffects & CFE_ITALIC) == CFE_ITALIC;
- lf.lfCharSet = cf.bCharSet;
- lf.lfPitchAndFamily = cf.bPitchAndFamily;
- lstrcpyn(lf.lfFaceName, cf.szFaceName, MAX_REGS(lf.lfFaceName));
-
- hFont = CreateFontIndirect(&lf);
- SetTextColor(hdc, cf.crTextColor);
- }
- else
- hFont = (HFONT) SendMessage(hwnd, WM_GETFONT, 0, 0);
-
- if (hFont != NULL)
- SelectObject(hdc, hFont);
-
- RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
- DrawText(hdc, e->texts[0], lstrlen(e->texts[0]), &rc, DT_CALCRECT | DT_NOPREFIX);
-
- int height = rc.bottom - rc.top + 1;
- int width = rc.right - rc.left + 1;
-
- rc.left = BORDER + j * (ssd->max_width + BORDER) + (ssd->max_width - width) / 2;
- rc.top = BORDER + i * (ssd->max_height + BORDER) + (ssd->max_height - height) / 2;
-
- rc.right = rc.left + width;
- rc.bottom = rc.top + height;
-
- DrawText(hdc, e->texts[0], lstrlen(e->texts[0]), &rc, DT_NOPREFIX);
-
- if (ssd->hwndTarget != NULL)
- DeleteObject(hFont);
- }
- else
- {
- BITMAP bmp;
- GetObject(e->img->img, sizeof(bmp), &bmp);
-
- int x = BORDER + j * (ssd->max_width + BORDER) + (ssd->max_width - bmp.bmWidth) / 2;
- int y = BORDER + i * (ssd->max_height + BORDER) + (ssd->max_height - bmp.bmHeight) / 2;
-
- HDC hdc_img = CreateCompatibleDC(hdc);
- HBITMAP old_bmp = (HBITMAP) SelectObject(hdc_img, e->img->img);
-
- if (e->img->transparent)
- {
- BLENDFUNCTION bf = {0};
- bf.SourceConstantAlpha = 255;
- bf.AlphaFormat = AC_SRC_ALPHA;
- AlphaBlend(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hdc_img, 0, 0, bmp.bmWidth, bmp.bmHeight, bf);
- }
- else
- {
- BitBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hdc_img, 0, 0, SRCCOPY);
- }
-
- SelectObject(hdc_img, old_bmp);
- DeleteDC(hdc_img);
-
- }
-
- if (ssd->selection == index)
- {
- RECT fr;
- fr.left = BORDER + j * (ssd->max_width + BORDER) - 1;
- fr.right = fr.left + ssd->max_width + 2;
- fr.top = BORDER + i * (ssd->max_height + BORDER) - 1;
- fr.bottom = fr.top + ssd->max_height + 2;
- FrameRect(hdc, &fr, (HBRUSH) GetStockObject(GRAY_BRUSH));
- }
- }
- }
+ layout->Draw(hdc);
// Copy buffer to screen
BitBlt(hdc_orig, rc.left, rc.top, rc.right - rc.left,
- rc.bottom - rc.top, hdc, rc.left, rc.top, SRCCOPY);
+ rc.bottom - rc.top, hdc, rc.left, rc.top, SRCCOPY);
DeleteDC(hdc);
DeleteObject(hBmp);
EndPaint(hwnd, &ps);
}
-
+
return TRUE;
}
- case WM_MOUSELEAVE:
+ case WM_MOUSELEAVE:
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
@@ -465,14 +176,14 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA tme.dwHoverTime = HOVER_DEFAULT;
TrackMouseEvent(&tme);
}
- case WM_NCMOUSEMOVE:
+ case WM_NCMOUSEMOVE:
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
- ssd->SetSelection(hwnd, -1);
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
+ layout->SetSelection(hwnd, -1);
break;
}
- case WM_MOUSEHOVER:
+ case WM_MOUSEHOVER:
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
@@ -481,41 +192,20 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA tme.dwHoverTime = HOVER_DEFAULT;
TrackMouseEvent(&tme);
}
- case WM_MOUSEMOVE:
+ case WM_MOUSEMOVE:
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
POINT p;
p.x = LOWORD(lParam);
p.y = HIWORD(lParam);
- int col;
- if (p.x % (BORDER + ssd->max_width) < BORDER)
- col = -1;
- else
- col = p.x / (BORDER + ssd->max_width);
-
- int line;
- if (p.y % (BORDER + ssd->max_height) < BORDER)
- line = -1;
- else
- line = p.y / (BORDER + ssd->max_height);
-
- int index = line * ssd->cols + col;
-
- if (col >= 0 && line >= 0 && index < ssd->module->emoticons.getCount())
- {
- ssd->SetSelection(hwnd, index);
- }
- else
- {
- ssd->SetSelection(hwnd, -1);
- }
+ layout->SetSelection(hwnd, p);
break;
}
- case WM_GETDLGCODE:
+ case WM_GETDLGCODE:
{
if (lParam != NULL)
{
@@ -525,74 +215,31 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA if (msg->message == WM_KEYDOWN && msg->time != last_time)
{
last_time = msg->time;
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
if (msg->wParam == VK_UP)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
-
- if (ssd->selection < 0)
- {
- ssd->SetSelection(hwnd, (ssd->lines - 1) * ssd->cols);
- }
- else
- {
- int index = (ssd->selection - ssd->cols) % ssd->module->emoticons.getCount();
- if (index < 0)
- index += ssd->module->emoticons.getCount();
- ssd->SetSelection(hwnd, index);
- }
+ layout->OnUp(hwnd);
}
else if (msg->wParam == VK_DOWN)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
-
- if (ssd->selection < 0)
- {
- ssd->SetSelection(hwnd, 0);
- }
- else
- {
- ssd->SetSelection(hwnd, (ssd->selection + ssd->cols) % ssd->module->emoticons.getCount());
- }
+ layout->OnDown(hwnd);
}
else if (msg->wParam == VK_LEFT)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
-
- if (ssd->selection < 0)
- {
- ssd->SetSelection(hwnd, ssd->cols - 1);
- }
- else
- {
- int index = (ssd->selection - 1) % ssd->module->emoticons.getCount();
- if (index < 0)
- index += ssd->module->emoticons.getCount();
- ssd->SetSelection(hwnd, index);
- }
+ layout->OnLeft(hwnd);
}
else if (msg->wParam == VK_RIGHT)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
-
- if (ssd->selection < 0)
- {
- ssd->SetSelection(hwnd, 0);
- }
- else
- {
- ssd->SetSelection(hwnd, (ssd->selection + 1) % ssd->module->emoticons.getCount());
- }
+ layout->OnRight(hwnd);
}
else if (msg->wParam == VK_HOME)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
- ssd->SetSelection(hwnd, 0);
+ layout->SetSelection(hwnd, 0);
}
else if (msg->wParam == VK_END)
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
- ssd->SetSelection(hwnd, ssd->module->emoticons.getCount() - 1);
+ layout->SetSelection(hwnd, layout->ssd->module->emoticons.getCount() - 1);
}
}
}
@@ -624,17 +271,17 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA case WM_LBUTTONUP:
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
- if (ssd->selection >= 0 && ssd->hwndTarget != NULL)
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
+ if (layout->selection >= 0 && layout->ssd->hwndTarget != NULL)
{
if (opts.only_replace_isolated)
{
TCHAR tmp[16];
- mir_sntprintf(tmp, MAX_REGS(tmp), _T(" %s "), ssd->module->emoticons[ssd->selection]->texts[0]);
- SendMessage(ssd->hwndTarget, ssd->targetMessage, ssd->targetWParam, (LPARAM) tmp);
+ mir_sntprintf(tmp, MAX_REGS(tmp), _T(" %s "), layout->ssd->module->emoticons[layout->selection]->texts[0]);
+ SendMessage(layout->ssd->hwndTarget, layout->ssd->targetMessage, layout->ssd->targetWParam, (LPARAM) tmp);
}
else
- SendMessage(ssd->hwndTarget, ssd->targetMessage, ssd->targetWParam, (LPARAM) ssd->module->emoticons[ssd->selection]->texts[0]);
+ SendMessage(layout->ssd->hwndTarget, layout->ssd->targetMessage, layout->ssd->targetWParam, (LPARAM) layout->ssd->module->emoticons[layout->selection]->texts[0]);
}
PostMessage(hwnd, WM_CLOSE, 0, 0);
@@ -643,24 +290,16 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA case WM_CLOSE:
{
- EmoticonSelectionData *ssd = (EmoticonSelectionData *) GetWindowLong(hwnd, GWL_USERDATA);
+ EmoticonsSelectionLayout *layout = (EmoticonsSelectionLayout *) GetWindowLong(hwnd, GWL_USERDATA);
SetWindowLong(hwnd, GWL_USERDATA, NULL);
- for(int i = 0; i < ssd->module->emoticons.getCount(); i++)
- {
- Emoticon *e = ssd->module->emoticons[i];
-
- if (e->tt != NULL)
- {
- DestroyWindow(e->tt);
- e->tt = NULL;
- }
- }
+ layout->DestroyToolTips();
DestroyWindow(hwnd);
- SetFocus(ssd->hwndTarget);
- delete ssd;
+ SetFocus(layout->ssd->hwndTarget);
+ delete layout->ssd;
+ delete layout;
break;
}
}
@@ -688,6 +327,8 @@ int ShowSelectionService(WPARAM wParam, LPARAM lParam) Module *m = GetModule(proto);
if (m == NULL)
return FALSE;
+ else if (m->emoticons.getCount() <= 0)
+ return FALSE;
EmoticonSelectionData * ssd = new EmoticonSelectionData();
ssd->module = m;
|