summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2008-04-15 04:39:03 +0000
committerpescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7>2008-04-15 04:39:03 +0000
commit8a8d9afcb727bdd9da02bd2c525b7685ca9f25b7 (patch)
treeed50a61a2468dfe64708797c1d50bc3ac2c88ccd
parent1f4071514a3f75e80c539fcedc4d9603f1cb6b46 (diff)
Added support for font service
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@81 c086bb3d-8645-0410-b8da-73a8550f86e7
-rw-r--r--Plugins/emoticons/EmoticonsSelectionLayout.cpp2
-rw-r--r--Plugins/emoticons/EmoticonsSelectionLayout.h10
-rw-r--r--Plugins/emoticons/GroupListEmoticons.cpp101
-rw-r--r--Plugins/emoticons/GroupListEmoticons.h33
-rw-r--r--Plugins/emoticons/SingleListEmoticons.cpp13
-rw-r--r--Plugins/emoticons/SingleListEmoticons.h15
-rw-r--r--Plugins/emoticons/commons.h1
-rw-r--r--Plugins/emoticons/emoticons.cpp89
-rw-r--r--Plugins/emoticons/selwin.cpp6
9 files changed, 239 insertions, 31 deletions
diff --git a/Plugins/emoticons/EmoticonsSelectionLayout.cpp b/Plugins/emoticons/EmoticonsSelectionLayout.cpp
index b593bff..ba99e16 100644
--- a/Plugins/emoticons/EmoticonsSelectionLayout.cpp
+++ b/Plugins/emoticons/EmoticonsSelectionLayout.cpp
@@ -131,7 +131,7 @@ int EmoticonsSelectionLayout::GetNumOfCols(int num_emotes)
int cols = num_emotes / MAX_LINES;
if (num_emotes % MAX_LINES != 0)
cols++;
- return min(cols, MAX_COLS);
+ return min(max(MIN_COLS, min(cols, MAX_COLS)), num_emotes);
}
int EmoticonsSelectionLayout::GetNumOfLines(int num_emotes, int cols)
diff --git a/Plugins/emoticons/EmoticonsSelectionLayout.h b/Plugins/emoticons/EmoticonsSelectionLayout.h
index f476ba4..6b13a5f 100644
--- a/Plugins/emoticons/EmoticonsSelectionLayout.h
+++ b/Plugins/emoticons/EmoticonsSelectionLayout.h
@@ -1,4 +1,4 @@
-#define MIN_COLS 5
+#define MIN_COLS 6
#define MAX_LINES 8
#define MAX_COLS 12
#define BORDER 3
@@ -31,7 +31,8 @@ public:
int height;
} window;
- virtual void Load() = 0;
+ EmoticonsSelectionLayout() {}
+ virtual ~EmoticonsSelectionLayout() {}
virtual void OnUp(HWND hwnd) = 0;
virtual void OnDown(HWND hwnd) = 0;
@@ -50,8 +51,9 @@ public:
protected:
- HFONT GetFont(HDC hdc);
- void ReleaseFont(HFONT hFont);
+ virtual HFONT GetFont(HDC hdc);
+ virtual void ReleaseFont(HFONT hFont);
+
RECT CalcRect(TCHAR *txt);
#ifdef UNICODE
RECT CalcRect(char *txt);
diff --git a/Plugins/emoticons/GroupListEmoticons.cpp b/Plugins/emoticons/GroupListEmoticons.cpp
index 83a9e5f..cc9f3a2 100644
--- a/Plugins/emoticons/GroupListEmoticons.cpp
+++ b/Plugins/emoticons/GroupListEmoticons.cpp
@@ -1,10 +1,87 @@
#include "commons.h"
+GroupListEmoticons::GroupListEmoticons(HWND hwnd, EmoticonSelectionData *ssd)
+{
+ this->hwnd = hwnd;
+ this->ssd = ssd;
+ Load();
+}
+
+GroupListEmoticons::~GroupListEmoticons()
+{
+ DeleteObject(groupFont);
+ DeleteObject(emoticonFont);
+}
+
+
+HFONT mir_font_get(TCHAR *group, TCHAR *name, COLORREF *color)
+{
+ LOGFONT lf = {0};
+ FontIDT font = {0};
+ font.cbSize = sizeof(font);
+ lstrcpyn(font.group, group, MAX_REGS(font.group));
+ lstrcpyn(font.name, name, MAX_REGS(font.name));
+ COLORREF tmp = (COLORREF) CallService(MS_FONT_GETT, (WPARAM) &font, (LPARAM) &lf);
+ if (color != NULL)
+ *color = tmp;
+ return CreateFontIndirect(&lf);
+}
+
+COLORREF mir_color_get(TCHAR *group, TCHAR *name)
+{
+ ColourIDT cid = {0};
+ cid.cbSize = sizeof(cid);
+ lstrcpyn(cid.group, group, MAX_REGS(cid.group));
+ lstrcpyn(cid.name, name, MAX_REGS(cid.name));
+ return (COLORREF) CallService(MS_COLOUR_GETT, (WPARAM) &cid, 0);
+}
+
+HFONT GroupListEmoticons::GetFont(HDC hdc)
+{
+ return emoticonFont;
+}
+
+void GroupListEmoticons::ReleaseFont(HFONT hFont)
+{
+}
+
+
+RECT GroupListEmoticons::CalcRect(TCHAR *txt, HFONT hFont)
+{
+ HDC hdc = GetDC(hwnd);
+ 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);
+
+ ReleaseDC(hwnd, hdc);
+ return rc;
+}
+
+
+void GroupListEmoticons::DrawEmoticonText(HDC hdc, TCHAR *txt, RECT rc, HFONT hFont)
+{
+ HFONT oldFont = (HFONT) SelectObject(hdc, hFont);
+
+ DrawText(hdc, txt, lstrlen(txt), &rc, DT_NOPREFIX);
+
+ SelectObject(hdc, oldFont);
+}
+
+
void GroupListEmoticons::Load()
{
selection = -1;
+ // Load fonts
+ groupFont = mir_font_get(_T("Emoticons"), _T("Group Name"), &groupColor);
+ emoticonFont = mir_font_get(_T("Emoticons"), _T("Emoticons Text"), &emoticonColor);
+ groupBkgColor = mir_color_get(_T("Emoticons"), _T("Group Background"));
+ ssd->background = mir_color_get(_T("Emoticons"), _T("Emoticons Background"));
+
num_groups = CountGroups();
groups = (Group *) malloc(num_groups * sizeof(Group));
@@ -39,9 +116,9 @@ void GroupListEmoticons::Load()
GetMaxEmoticonSize(group);
group.cols = GetNumOfCols(group.count);
- if (group.name[0] != '\0')
+ if (group.name[0] != _T('\0'))
{
- RECT rc = CalcRect(group.name);
+ RECT rc = CalcRect(group.name, groupFont);
window.width = max(window.width, rc.right - rc.left + 2 * BORDER + 1);
}
@@ -66,7 +143,7 @@ void GroupListEmoticons::Load()
if (group.name[0] != '\0')
{
- RECT rc = CalcRect(group.name);
+ RECT rc = CalcRect(group.name, groupFont);
window.height += HeightWithBorders(rc);
}
@@ -144,7 +221,7 @@ void GroupListEmoticons::CreateToolTips()
if (group.name[0] != '\0')
{
- RECT rc = CalcRect(group.name);
+ RECT rc = CalcRect(group.name, groupFont);
top += HeightWithBorders(rc);
}
@@ -189,7 +266,7 @@ void GroupListEmoticons::SetSelection(HWND hwnd, POINT p)
p.y -= group.top;
if (group.name[0] != '\0')
{
- RECT rc = CalcRect(group.name);
+ RECT rc = CalcRect(group.name, groupFont);
p.y -= HeightWithBorders(rc);
}
@@ -351,6 +428,8 @@ void GroupListEmoticons::Draw(HDC hdc)
RECT client_rc;
GetClientRect(hwnd, &client_rc);
+ COLORREF old_text_color = SetTextColor(hdc, emoticonColor);
+
int top = 0;
for(int i = 0; i < num_groups; i++)
@@ -359,7 +438,7 @@ void GroupListEmoticons::Draw(HDC hdc)
if (group.name[0] != '\0')
{
- RECT rc = CalcRect(group.name);
+ RECT rc = CalcRect(group.name, groupFont);
rc.top += top + BORDER;
rc.bottom += top + BORDER;
@@ -370,11 +449,15 @@ void GroupListEmoticons::Draw(HDC hdc)
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));
+ HBRUSH hB = CreateSolidBrush(groupBkgColor);
FillRect(hdc, &title_rc, hB);
DeleteObject(hB);
- DrawEmoticonText(hdc, group.name, rc);
+ SetTextColor(hdc, groupColor);
+
+ DrawEmoticonText(hdc, group.name, rc, groupFont);
+
+ SetTextColor(hdc, emoticonColor);
top += HeightWithBorders(rc);
}
@@ -390,4 +473,6 @@ void GroupListEmoticons::Draw(HDC hdc)
top += group.max_height * group.lines + (group.lines + 1) * BORDER;
}
+
+ SetTextColor(hdc, old_text_color);
}
diff --git a/Plugins/emoticons/GroupListEmoticons.h b/Plugins/emoticons/GroupListEmoticons.h
index 3243dbc..b7cae82 100644
--- a/Plugins/emoticons/GroupListEmoticons.h
+++ b/Plugins/emoticons/GroupListEmoticons.h
@@ -21,15 +21,14 @@ public:
int num_groups;
Group *groups;
- virtual void Load();
+ HFONT groupFont;
+ HFONT emoticonFont;
+ COLORREF groupBkgColor;
+ COLORREF emoticonColor;
+ COLORREF groupColor;
- void SetGroupName(Group &group, char *name);
-
- int CountGroups();
-
- void GetMaxEmoticonSize(Group &group);
-
- RECT GetEmoticonRect(Group &group, int index);
+ GroupListEmoticons(HWND hwnd, EmoticonSelectionData *ssd);
+ virtual ~GroupListEmoticons();
virtual void CreateToolTips();
@@ -45,4 +44,22 @@ public:
virtual void OnRight(HWND hwnd);
virtual void Draw(HDC hdc);
+
+protected:
+
+ void Load();
+
+ RECT CalcRect(TCHAR *txt, HFONT hFont);
+ void DrawEmoticonText(HDC hdc, TCHAR *txt, RECT rc, HFONT hFont);
+
+ virtual HFONT GetFont(HDC hdc);
+ virtual void ReleaseFont(HFONT hFont);
+
+ void SetGroupName(Group &group, char *name);
+
+ int CountGroups();
+
+ void GetMaxEmoticonSize(Group &group);
+
+ RECT GetEmoticonRect(Group &group, int index);
};
diff --git a/Plugins/emoticons/SingleListEmoticons.cpp b/Plugins/emoticons/SingleListEmoticons.cpp
index 740d1e8..1015d33 100644
--- a/Plugins/emoticons/SingleListEmoticons.cpp
+++ b/Plugins/emoticons/SingleListEmoticons.cpp
@@ -1,5 +1,18 @@
#include "commons.h"
+SingleListEmoticons::SingleListEmoticons(HWND hwnd, EmoticonSelectionData *ssd)
+{
+ this->hwnd = hwnd;
+ this->ssd = ssd;
+ Load();
+}
+
+
+SingleListEmoticons::~SingleListEmoticons()
+{
+}
+
+
void SingleListEmoticons::GetMaxEmoticonSize()
{
emoticons.max_height = 4;
diff --git a/Plugins/emoticons/SingleListEmoticons.h b/Plugins/emoticons/SingleListEmoticons.h
index 9cdf5df..2beda77 100644
--- a/Plugins/emoticons/SingleListEmoticons.h
+++ b/Plugins/emoticons/SingleListEmoticons.h
@@ -9,11 +9,8 @@ public:
int cols;
} emoticons;
- virtual void Load();
-
- void GetMaxEmoticonSize();
-
- int GetEmoticonCountRoundedByCols();
+ SingleListEmoticons(HWND hwnd, EmoticonSelectionData *ssd);
+ virtual ~SingleListEmoticons();
virtual void CreateToolTips();
@@ -26,6 +23,14 @@ public:
virtual void Draw(HDC hdc);
+protected:
+
+ void Load();
+
RECT GetEmoticonRect(int line, int col);
+ void GetMaxEmoticonSize();
+
+ int GetEmoticonCountRoundedByCols();
+
};
diff --git a/Plugins/emoticons/commons.h b/Plugins/emoticons/commons.h
index 1653ed2..ec632bc 100644
--- a/Plugins/emoticons/commons.h
+++ b/Plugins/emoticons/commons.h
@@ -70,6 +70,7 @@ using namespace std;
#include <m_anismiley.h>
#include <anismiley.tlh>
#include <m_netlib.h>
+#include <m_fontservice.h>
#include "../utils/mir_memory.h"
#include "../utils/mir_options.h"
diff --git a/Plugins/emoticons/emoticons.cpp b/Plugins/emoticons/emoticons.cpp
index 3918ae3..ac84833 100644
--- a/Plugins/emoticons/emoticons.cpp
+++ b/Plugins/emoticons/emoticons.cpp
@@ -225,6 +225,92 @@ extern "C" int __declspec(dllexport) Unload(void)
return 0;
}
+COLORREF GetSRMMColor(char *tabsrmm, char *scriver, COLORREF def)
+{
+ COLORREF colour = (COLORREF) DBGetContactSettingDword(NULL, "TabSRMM_Fonts", tabsrmm, -1); // TabSRMM
+ if (colour == -1)
+ colour = (COLORREF) DBGetContactSettingDword(NULL, "SRMM", scriver, -1); // Scriver / SRMM
+ if (colour == -1)
+ colour = def; // Default
+ return colour;
+}
+
+BYTE GetSRMMByte(char *tabsrmm, char *scriver, BYTE def)
+{
+ BYTE ret = (BYTE) DBGetContactSettingByte(NULL, "TabSRMM_Fonts", tabsrmm, -1); // TabSRMM
+ if (ret == -1)
+ ret = (BYTE) DBGetContactSettingByte(NULL, "SRMM", scriver, -1); // Scriver / SRMM
+ if (ret == -1)
+ ret = def; // Default
+ return ret;
+}
+
+void GetSRMMTString(TCHAR *out, size_t out_size, char *tabsrmm, char *scriver, TCHAR *def)
+{
+ DBVARIANT dbv;
+ if (!DBGetContactSettingTString(NULL, "TabSRMM_Fonts", tabsrmm, &dbv))
+ {
+ lstrcpyn(out, dbv.ptszVal, out_size);
+ DBFreeVariant(&dbv);
+ }
+ else if (!DBGetContactSettingTString(NULL, "SRMM", scriver, &dbv))
+ {
+ lstrcpyn(out, dbv.ptszVal, out_size);
+ DBFreeVariant(&dbv);
+ }
+ else
+ {
+ lstrcpyn(out, def, out_size);
+ }
+}
+
+void InitFonts()
+{
+ FontIDT font = {0};
+ font.cbSize = sizeof(font);
+ lstrcpyn(font.group, _T("Emoticons"), MAX_REGS(font.group));
+ lstrcpyn(font.backgroundGroup, _T("Emoticons"), MAX_REGS(font.group));
+ strncpy(font.dbSettingsGroup, MODULE_NAME, MAX_REGS(font.dbSettingsGroup));
+ font.order = 0;
+ font.flags = FIDF_DEFAULTVALID | FIDF_ALLOWEFFECTS;
+
+ font.deffontsettings.colour = GetSRMMColor("Font16Col", "SRMFont8Col", RGB(0, 0, 0));
+ font.deffontsettings.size = GetSRMMByte("Font16Size", "SRMFont8Size", -12);
+ font.deffontsettings.style = GetSRMMByte("Font16Sty", "SRMFont8Sty", 0);
+ font.deffontsettings.charset = GetSRMMByte("Font16Set", "SRMFont8Set", DEFAULT_CHARSET);
+ GetSRMMTString(font.deffontsettings.szFace, MAX_REGS(font.deffontsettings.szFace), "Font16", "SRMFont8", _T("Tahoma"));
+
+ lstrcpyn(font.name, _T("Group Name"), MAX_REGS(font.name));
+ strncpy(font.prefix, "GroupName", MAX_REGS(font.prefix));
+ lstrcpyn(font.backgroundName, _T("Group Background"), MAX_REGS(font.backgroundName));
+ CallService(MS_FONT_REGISTERT, (WPARAM)&font, 0);
+
+ lstrcpyn(font.name, _T("Emoticons Text"), MAX_REGS(font.name));
+ strncpy(font.prefix, "EmoticonsText", MAX_REGS(font.prefix));
+ lstrcpyn(font.backgroundName, _T("Emoticons Background"), MAX_REGS(font.backgroundName));
+ CallService(MS_FONT_REGISTERT, (WPARAM)&font, 0);
+
+ COLORREF bkg = GetSRMMColor("inputbg", "InputBkgColour", GetSysColor(COLOR_WINDOW));
+
+ ColourIDT cid = {0};
+ cid.cbSize = sizeof(ColourID);
+ lstrcpyn(cid.group, _T("Emoticons"), MAX_REGS(cid.group));
+ strncpy(cid.dbSettingsGroup, MODULE_NAME, MAX_REGS(cid.dbSettingsGroup));
+ cid.order = 0;
+ cid.flags = 0;
+
+ lstrcpyn(cid.name, _T("Emoticons Background"), MAX_REGS(cid.name));
+ strncpy(cid.setting, "EmoticonsBackground", MAX_REGS(cid.setting));
+ cid.defcolour = bkg;
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&cid, 0);
+
+ lstrcpyn(cid.name, _T("Group Background"), MAX_REGS(cid.name));
+ strncpy(cid.setting, "GroupBackground", MAX_REGS(cid.setting));
+ cid.defcolour = RGB(GetRValue(bkg) > 120 ? GetRValue(bkg) - 30 : GetRValue(bkg) + 30,
+ GetGValue(bkg) > 120 ? GetGValue(bkg) - 30 : GetGValue(bkg) + 30,
+ GetBValue(bkg) > 120 ? GetBValue(bkg) - 30 : GetBValue(bkg) + 30);
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&cid, 0);
+}
// Called when all the modules are loaded
int ModulesLoaded(WPARAM wParam, LPARAM lParam)
@@ -291,6 +377,9 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam)
mir_sntprintf(emoticonPacksFolder, MAX_REGS(emoticonPacksFolder), _T("%s\\Customize\\Emoticons"), mirandaFolder);
}
+ // Fonts support
+ InitFonts();
+
InitOptions();
LoadModules();
diff --git a/Plugins/emoticons/selwin.cpp b/Plugins/emoticons/selwin.cpp
index adceeb6..8cf15d0 100644
--- a/Plugins/emoticons/selwin.cpp
+++ b/Plugins/emoticons/selwin.cpp
@@ -103,13 +103,9 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
}
// Create positioning object
- EmoticonsSelectionLayout *layout = new GroupListEmoticons();
- layout->ssd = ssd;
- layout->hwnd = hwnd;
+ EmoticonsSelectionLayout *layout = new GroupListEmoticons(hwnd, ssd);
SetWindowLong(hwnd, GWL_USERDATA, (LONG) layout);
- layout->Load();
-
// Calc position
int x = ssd->xPosition;