diff options
author | George Hazan <ghazan@miranda.im> | 2019-05-29 21:51:22 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-05-29 21:51:22 +0300 |
commit | 4cae6446ffc3e024d7b7f0e1fd888459f7ab514e (patch) | |
tree | 9b1b8476939657193ceacb9eaf046ce7ea145406 | |
parent | 68e4b1b9f6c46df3f46952a40d9f3b1d11323418 (diff) |
SmileyAdd:
- options dialog rewritten using UI classes;
- unused code removed;
- massive code cleaning
-rw-r--r-- | plugins/SmileyAdd/src/download.cpp | 24 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/general.cpp | 24 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/options.cpp | 875 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.cpp | 32 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.h | 21 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/stdafx.h | 29 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/version.h | 2 |
7 files changed, 411 insertions, 596 deletions
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 7df7478090..4042119869 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -36,7 +36,7 @@ struct QueueElem static HANDLE g_hDlMutex;
static OBJLIST<QueueElem> dlQueue(10);
-static wchar_t cachepath[MAX_PATH];
+static wchar_t g_wszCachePath[MAX_PATH];
static bool threadRunning;
bool InternetDownloadFile(const char *szUrl, char *szDest, HNETLIBCONN &hHttpDwnl)
@@ -167,7 +167,7 @@ bool GetSmileyFile(CMStringW &url, const CMStringW &packstr) bin2hexW(hash, sizeof(hash), wszHash);
CMStringW filename;
- filename.AppendFormat(L"%s\\%s\\", cachepath, packstr.c_str());
+ filename.AppendFormat(L"%s\\%s\\", g_wszCachePath, packstr.c_str());
int pathpos = filename.GetLength();
MRegexp16 urlsplit(L".*/(.*)");
@@ -219,20 +219,10 @@ bool GetSmileyFile(CMStringW &url, const CMStringW &packstr) int FolderChanged(WPARAM, LPARAM)
{
- FoldersGetCustomPathT(hFolder, cachepath, MAX_PATH, L"");
+ FoldersGetCustomPathT(hFolder, g_wszCachePath, MAX_PATH, L"");
return 0;
}
-void GetSmileyCacheFolder(void)
-{
- hFolder = FoldersRegisterCustomPathT(LPGEN("SmileyAdd"), LPGEN("Smiley cache"), MIRANDA_USERDATAT L"\\SmileyCache");
- if (hFolder) {
- FoldersGetCustomPathT(hFolder, cachepath, MAX_PATH, L"");
- HookEvent(ME_FOLDERS_PATH_CHANGED, FolderChanged);
- }
- else mir_wstrncpy(cachepath, VARSW(L"%miranda_userdata%\\SmileyCache"), MAX_PATH);
-}
-
void DownloadInit(void)
{
NETLIBUSER nlu = {};
@@ -241,7 +231,13 @@ void DownloadInit(void) nlu.szDescriptiveName.w = TranslateT("SmileyAdd HTTP connections");
hNetlibUser = Netlib_RegisterUser(&nlu);
- GetSmileyCacheFolder();
+ hFolder = FoldersRegisterCustomPathT(LPGEN("SmileyAdd"), LPGEN("Smiley cache"), MIRANDA_USERDATAT L"\\SmileyCache");
+ if (hFolder) {
+ FolderChanged(0, 0);
+ HookEvent(ME_FOLDERS_PATH_CHANGED, FolderChanged);
+ }
+ else mir_wstrncpy(g_wszCachePath, VARSW(L"%miranda_userdata%\\SmileyCache"), MAX_PATH);
+
g_hDlMutex = CreateMutex(nullptr, FALSE, nullptr);
}
diff --git a/plugins/SmileyAdd/src/general.cpp b/plugins/SmileyAdd/src/general.cpp index 9291389d6f..9456033e4c 100644 --- a/plugins/SmileyAdd/src/general.cpp +++ b/plugins/SmileyAdd/src/general.cpp @@ -124,30 +124,6 @@ HICON ImageList_GetIconFixed(HIMAGELIST himl, INT i, UINT fStyle) return hIcon;
}
-void pathToRelative(const CMStringW &pSrc, CMStringW &pOut)
-{
- wchar_t szOutPath[MAX_PATH];
- PathToRelativeW(pSrc.c_str(), szOutPath);
- pOut = szOutPath;
-}
-
-void pathToAbsolute(const CMStringW &pSrc, CMStringW &pOut)
-{
- wchar_t szOutPath[MAX_PATH];
-
- wchar_t *szVarPath = Utils_ReplaceVarsW(pSrc.c_str());
- if (szVarPath == (wchar_t*)CALLSERVICE_NOTFOUND || szVarPath == nullptr) {
- wchar_t szExpPath[MAX_PATH];
- ExpandEnvironmentStrings(pSrc.c_str(), szExpPath, _countof(szExpPath));
- PathToAbsoluteW(szExpPath, szOutPath);
- }
- else {
- PathToAbsoluteW(szVarPath, szOutPath);
- mir_free(szVarPath);
- }
- pOut = szOutPath;
-}
-
bool InitGdiPlus(void)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp index a50d4f247a..57bd307f8d 100644 --- a/plugins/SmileyAdd/src/options.cpp +++ b/plugins/SmileyAdd/src/options.cpp @@ -22,504 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. OptionsType opt;
-#define UM_CHECKSTATECHANGE (WM_USER + 100)
-
-class OptionsDialogType
-{
-private:
- HWND m_hwndDialog;
- SmileyCategoryListType tmpsmcat;
- SmileyPackType smPack;
-
- void InitDialog(void);
- void DestroyDialog(void);
- void AddCategory(void);
- void ApplyChanges(void);
- void UpdateControls(bool force = false);
- void SetChanged(void);
- bool BrowseForSmileyPacks(int item);
- void FilenameChanged(void);
- void ShowSmileyPreview(void);
- void PopulateSmPackList(void);
- void UpdateVisibleSmPackList(void);
- void UserAction(HTREEITEM hItem);
- long GetSelProto(HTREEITEM hItem = nullptr);
-
-public:
- OptionsDialogType(HWND hWnd) { m_hwndDialog = hWnd; }
- BOOL DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam);
-};
-
-//OptionsDialog class functions
-BOOL OptionsDialogType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lParam)
-{
- BOOL Result = FALSE;
-
- switch (msg) {
- case WM_INITDIALOG:
- InitDialog();
- Result = TRUE;
- break;
-
- case WM_DESTROY:
- DestroyDialog();
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_FILENAME:
- switch (HIWORD(wParam)) {
- case EN_KILLFOCUS:
- FilenameChanged();
- break;
-
- case EN_CHANGE:
- if (GetFocus() == (HWND)lParam) SetChanged();
- break;
- }
- break;
-
- case IDC_BROWSE:
- if (HIWORD(wParam) == BN_CLICKED)
- if (BrowseForSmileyPacks(GetSelProto())) {
- UpdateControls(true);
- SetChanged();
- }
- break;
-
- case IDC_SMLOPTBUTTON:
- if (HIWORD(wParam) == BN_CLICKED)
- ShowSmileyPreview();
- break;
-
- case IDC_USESTDPACK:
- if (HIWORD(wParam) == BN_CLICKED) {
- BOOL en = IsDlgButtonChecked(m_hwndDialog, IDC_USESTDPACK) == BST_CHECKED;
- EnableWindow(GetDlgItem(m_hwndDialog, IDC_USEPHYSPROTO), en);
- } // no break!
- case IDC_USEPHYSPROTO:
- if (HIWORD(wParam) == BN_CLICKED) {
- PopulateSmPackList();
- SetChanged();
- }
- break;
-
- case IDC_ADDCATEGORY:
- if (HIWORD(wParam) == BN_CLICKED)
- AddCategory();
- break;
-
- case IDC_DELETECATEGORY:
- if (HIWORD(wParam) == BN_CLICKED)
- if (tmpsmcat.DeleteCustomCategory(GetSelProto())) {
- PopulateSmPackList();
- SetChanged();
- }
- break;
-
- case IDC_SPACES:
- case IDC_SCALETOTEXTHEIGHT:
- case IDC_APPENDSPACES:
- case IDC_SCALEALLSMILEYS:
- case IDC_IEVIEWSTYLE:
- case IDC_ANIMATESEL:
- case IDC_ANIMATEDLG:
- case IDC_INPUTSMILEYS:
- case IDC_DCURSORSMILEY:
- case IDC_DISABLECUSTOM:
- case IDC_HQSCALING:
- case IDC_SORTING_HORIZONTAL:
- if (HIWORD(wParam) == BN_CLICKED)
- SetChanged();
- break;
-
- case IDC_MAXCUSTSMSZ:
- case IDC_MINSMSZ:
- if (HIWORD(wParam) == EN_CHANGE && GetFocus() == (HWND)lParam)
- SetChanged();
- break;
- }
- break;
-
- case UM_CHECKSTATECHANGE:
- UserAction((HTREEITEM)lParam);
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- ApplyChanges();
- break;
- }
- break;
-
- case IDC_CATEGORYLIST:
- switch (((LPNMHDR)lParam)->code) {
- case NM_CLICK:
- {
- TVHITTESTINFO ht = { 0 };
-
- DWORD dwpos = GetMessagePos();
- POINTSTOPOINT(ht.pt, MAKEPOINTS(dwpos));
- MapWindowPoints(HWND_DESKTOP, ((LPNMHDR)lParam)->hwndFrom, &ht.pt, 1);
-
- TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &ht);
- if (TVHT_ONITEM & ht.flags)
- FilenameChanged();
- if (TVHT_ONITEMSTATEICON & ht.flags)
- PostMessage(m_hwndDialog, UM_CHECKSTATECHANGE, 0, (LPARAM)ht.hItem);
- }
-
- case TVN_KEYDOWN:
- if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE)
- PostMessage(m_hwndDialog, UM_CHECKSTATECHANGE, 0,
- (LPARAM)TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom));
- break;
-
- case TVN_SELCHANGED:
- LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
- if (pnmtv->itemNew.state & TVIS_SELECTED)
- UpdateControls();
- }
- }
- break;
- }
-
- return Result;
-}
-
-void OptionsDialogType::AddCategory(void)
-{
- wchar_t cat[30];
- GetDlgItemText(m_hwndDialog, IDC_NEWCATEGORY, cat, _countof(cat));
- CMStringW catd = cat;
-
- if (!catd.IsEmpty()) {
- tmpsmcat.AddCategory(cat, catd, smcCustom);
-
- PopulateSmPackList();
- SetChanged();
- }
-}
-
-void OptionsDialogType::UserAction(HTREEITEM hItem)
-{
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
-
- if (TreeView_GetCheckState(hLstView, hItem)) {
- if (!BrowseForSmileyPacks(GetSelProto(hItem)))
- TreeView_SetCheckState(hLstView, hItem, TRUE)
- }
- else
- tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename();
-
- if (hItem == TreeView_GetSelection(hLstView))
- UpdateControls();
- else
- TreeView_SelectItem(hLstView, hItem);
-
- SetChanged();
- PopulateSmPackList();
-}
-
-
-void OptionsDialogType::SetChanged(void)
-{
- SendMessage(GetParent(m_hwndDialog), PSM_CHANGED, 0, 0);
-}
-
-void OptionsDialogType::UpdateControls(bool force)
-{
- const SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(GetSelProto());
- if (smc == nullptr)
- return;
-
- const CMStringW &smf = smc->GetFilename();
- SetDlgItemText(m_hwndDialog, IDC_FILENAME, smf);
-
- if (smPack.GetFilename() != smf || force)
- smPack.LoadSmileyFile(smf, smPack.GetName(), false, true);
-
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
- TreeView_SetCheckState(hLstView, TreeView_GetSelection(hLstView), smPack.SmileyCount() != 0);
-
- SetDlgItemText(m_hwndDialog, IDC_LIBAUTHOR, smPack.GetAuthor().c_str());
- SetDlgItemText(m_hwndDialog, IDC_LIBVERSION, smPack.GetVersion().c_str());
- SetDlgItemText(m_hwndDialog, IDC_LIBNAME, TranslateW(smPack.GetName().c_str()));
-}
-
-long OptionsDialogType::GetSelProto(HTREEITEM hItem)
-{
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
- TVITEM tvi = { 0 };
-
- tvi.mask = TVIF_PARAM;
- tvi.hItem = hItem == nullptr ? TreeView_GetSelection(hLstView) : hItem;
-
- TreeView_GetItem(hLstView, &tvi);
-
- return (long)tvi.lParam;
-}
-
-void OptionsDialogType::UpdateVisibleSmPackList(void)
-{
- bool useOne = IsDlgButtonChecked(m_hwndDialog, IDC_USESTDPACK) == BST_UNCHECKED;
- bool usePhysProto = IsDlgButtonChecked(m_hwndDialog, IDC_USEPHYSPROTO) == BST_CHECKED;
-
- SmileyCategoryListType::SmileyCategoryVectorType &smc = *tmpsmcat.GetSmileyCategoryList();
- for (auto &it : smc) {
- bool visiblecat = usePhysProto ? !it->IsAcc() : !it->IsPhysProto();
- bool visible = useOne ? !it->IsProto() : visiblecat;
-
- if (!visible && it->IsAcc() && !useOne) {
- CMStringW PhysProtoName = L"AllProto";
- CMStringW ProtoName = it->GetName();
- DBVARIANT dbv;
- if (db_get_ws(0, _T2A(ProtoName.GetBuffer()), "AM_BaseProto", &dbv) == 0) {
- ProtoName = dbv.pwszVal;
- db_free(&dbv);
- }
- else
- ProtoName.Empty();
-
- CMStringW FileName;
- if (!ProtoName.IsEmpty()) {
- PhysProtoName += ProtoName;
- SmileyCategoryType *scm = tmpsmcat.GetSmileyCategory(PhysProtoName);
- if (scm == nullptr)
- visible = false;
- else if (scm->GetFilename().IsEmpty())
- visible = true;
- }
- }
-
- it->SetVisible(visible);
- }
-}
-
-void OptionsDialogType::PopulateSmPackList(void)
-{
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
-
- TreeView_SelectItem(hLstView, NULL);
- TreeView_DeleteAllItems(hLstView);
-
- TVINSERTSTRUCT tvi = {};
- tvi.hParent = TVI_ROOT;
- tvi.hInsertAfter = TVI_LAST;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_STATE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.stateMask = TVIS_STATEIMAGEMASK | TVIS_SELECTED;
- UpdateVisibleSmPackList();
- SmileyCategoryListType::SmileyCategoryVectorType &smc = *tmpsmcat.GetSmileyCategoryList();
- for (int i = 0; i < smc.getCount(); i++) {
- if (smc[i].IsVisible()) {
- tvi.item.pszText = (wchar_t*)smc[i].GetDisplayName().c_str();
- if (!smc[i].IsProto()) {
- tvi.item.iImage = 0;
- tvi.item.iSelectedImage = 0;
- }
- else {
- tvi.item.iImage = i;
- tvi.item.iSelectedImage = i;
- }
- tvi.item.lParam = i;
- tvi.item.state = INDEXTOSTATEIMAGEMASK(smPack.LoadSmileyFile(smc[i].GetFilename(), smc[i].GetDisplayName(), true, true) ? 2 : 1);
- TreeView_InsertItem(hLstView, &tvi);
-
- smPack.Clear();
- }
- }
- TreeView_SelectItem(hLstView, TreeView_GetRoot(hLstView));
-}
-
-void OptionsDialogType::InitDialog(void)
-{
- TranslateDialogDefault(m_hwndDialog);
-
- CheckDlgButton(m_hwndDialog, IDC_SPACES, opt.EnforceSpaces ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_SCALETOTEXTHEIGHT, opt.ScaleToTextheight ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_USESTDPACK, opt.UseOneForAll ? BST_UNCHECKED : BST_CHECKED);
- CheckDlgButton(m_hwndDialog, IDC_USEPHYSPROTO, opt.UsePhysProto ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_APPENDSPACES, opt.SurroundSmileyWithSpaces ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_SCALEALLSMILEYS, opt.ScaleAllSmileys ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_IEVIEWSTYLE, opt.IEViewStyle ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_ANIMATESEL, opt.AnimateSel ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_ANIMATEDLG, opt.AnimateDlg ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_INPUTSMILEYS, opt.InputSmileys ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_DCURSORSMILEY, opt.DCursorSmiley ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_DISABLECUSTOM, opt.DisableCustom ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_HQSCALING, opt.HQScaling ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(m_hwndDialog, IDC_SORTING_HORIZONTAL, opt.HorizontalSorting ? BST_CHECKED : BST_UNCHECKED);
-
- EnableWindow(GetDlgItem(m_hwndDialog, IDC_USEPHYSPROTO), !opt.UseOneForAll);
-
- SendDlgItemMessage(m_hwndDialog, IDC_MAXCUSTSPIN, UDM_SETRANGE32, 0, 99);
- SendDlgItemMessage(m_hwndDialog, IDC_MAXCUSTSPIN, UDM_SETPOS, 0, opt.MaxCustomSmileySize);
- SendDlgItemMessage(m_hwndDialog, IDC_MAXCUSTSMSZ, EM_LIMITTEXT, 2, 0);
-
- SendDlgItemMessage(m_hwndDialog, IDC_MINSPIN, UDM_SETRANGE32, 0, 99);
- SendDlgItemMessage(m_hwndDialog, IDC_MINSPIN, UDM_SETPOS, 0, opt.MinSmileySize);
- SendDlgItemMessage(m_hwndDialog, IDC_MINSMSZ, EM_LIMITTEXT, 2, 0);
-
- // Create and populate image list
- HIMAGELIST hImList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
- ILC_MASK | ILC_COLOR32, g_SmileyCategories.NumberOfSmileyCategories(), 0);
-
- tmpsmcat = g_SmileyCategories;
-
- SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList();
- for (auto &it : smc) {
- HICON hIcon = nullptr;
- if (it->IsProto()) {
- hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0);
- if (hIcon == nullptr || (INT_PTR)hIcon == CALLSERVICE_NOTFOUND)
- hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0);
- }
- if (hIcon == nullptr || hIcon == (HICON)CALLSERVICE_NOTFOUND)
- hIcon = GetDefaultIcon();
-
- ImageList_AddIcon(hImList, hIcon);
- DestroyIcon(hIcon);
- }
-
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
- TreeView_SetImageList(hLstView, hImList, TVSIL_NORMAL);
-
- PopulateSmPackList();
-}
-
-void OptionsDialogType::DestroyDialog(void)
-{
- HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
- HIMAGELIST hImList = TreeView_SetImageList(hLstView, NULL, TVSIL_NORMAL);
- ImageList_Destroy(hImList);
-}
-
-void OptionsDialogType::ApplyChanges(void)
-{
- ProcessAllInputAreas(true);
- CloseSmileys();
-
- opt.EnforceSpaces = IsDlgButtonChecked(m_hwndDialog, IDC_SPACES) == BST_CHECKED;
- opt.ScaleToTextheight = IsDlgButtonChecked(m_hwndDialog, IDC_SCALETOTEXTHEIGHT) == BST_CHECKED;
- opt.UseOneForAll = IsDlgButtonChecked(m_hwndDialog, IDC_USESTDPACK) == BST_UNCHECKED;
- opt.UsePhysProto = IsDlgButtonChecked(m_hwndDialog, IDC_USEPHYSPROTO) == BST_CHECKED;
- opt.SurroundSmileyWithSpaces = IsDlgButtonChecked(m_hwndDialog, IDC_APPENDSPACES) == BST_CHECKED;
- opt.ScaleAllSmileys = IsDlgButtonChecked(m_hwndDialog, IDC_SCALEALLSMILEYS) == BST_CHECKED;
- opt.IEViewStyle = IsDlgButtonChecked(m_hwndDialog, IDC_IEVIEWSTYLE) == BST_CHECKED;
- opt.AnimateSel = IsDlgButtonChecked(m_hwndDialog, IDC_ANIMATESEL) == BST_CHECKED;
- opt.AnimateDlg = IsDlgButtonChecked(m_hwndDialog, IDC_ANIMATEDLG) == BST_CHECKED;
- opt.InputSmileys = IsDlgButtonChecked(m_hwndDialog, IDC_INPUTSMILEYS) == BST_CHECKED;
- opt.DCursorSmiley = IsDlgButtonChecked(m_hwndDialog, IDC_DCURSORSMILEY) == BST_CHECKED;
- opt.DisableCustom = IsDlgButtonChecked(m_hwndDialog, IDC_DISABLECUSTOM) == BST_CHECKED;
- opt.HQScaling = IsDlgButtonChecked(m_hwndDialog, IDC_HQSCALING) == BST_CHECKED;
- opt.HorizontalSorting = IsDlgButtonChecked(m_hwndDialog, IDC_SORTING_HORIZONTAL) == BST_CHECKED;
-
- opt.MaxCustomSmileySize = GetDlgItemInt(m_hwndDialog, IDC_MAXCUSTSMSZ, nullptr, FALSE);
- opt.MinSmileySize = GetDlgItemInt(m_hwndDialog, IDC_MINSMSZ, nullptr, FALSE);
-
- opt.Save();
-
- // Cleanup database
- CMStringW empty;
- SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList();
- for (auto &it : smc)
- if (tmpsmcat.GetSmileyCategory(it->GetName()) == nullptr)
- opt.WritePackFileName(empty, it->GetName());
-
- g_SmileyCategories = tmpsmcat;
- g_SmileyCategories.SaveSettings();
- g_SmileyCategories.ClearAndLoadAll();
-
- smPack.LoadSmileyFile(tmpsmcat.GetSmileyCategory(GetSelProto())->GetFilename(), tmpsmcat.GetSmileyCategory(GetSelProto())->GetDisplayName(), false, true);
-
- NotifyEventHooks(hEvent1, 0, 0);
- ProcessAllInputAreas(false);
-}
-
-bool OptionsDialogType::BrowseForSmileyPacks(int item)
-{
- OPENFILENAME ofn = { 0 };
-
- wchar_t filename[MAX_PATH] = L"";
- ofn.lpstrFile = filename;
- ofn.nMaxFile = _countof(filename);
-
- CMStringW inidir;
- SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(item);
- if (smc->GetFilename().IsEmpty())
- pathToAbsolute(L"Smileys", inidir);
- else {
- pathToAbsolute(smc->GetFilename(), inidir);
- inidir.Truncate(inidir.ReverseFind('\\'));
- }
-
- ofn.lpstrInitialDir = inidir.c_str();
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = m_hwndDialog;
-
- wchar_t filter[512], *pfilter;
- mir_wstrcpy(filter, TranslateT("Smiley packs"));
- mir_wstrcat(filter, L" (*.msl;*.asl;*.xep)");
- pfilter = filter + mir_wstrlen(filter) + 1;
- mir_wstrcpy(pfilter, L"*.msl;*.asl;*.xep");
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- mir_wstrcpy(pfilter, TranslateT("All files"));
- mir_wstrcat(pfilter, L" (*.*)");
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- mir_wstrcpy(pfilter, L"*.*");
- pfilter = pfilter + mir_wstrlen(pfilter) + 1;
- *pfilter = '\0';
- ofn.lpstrFilter = filter;
-
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_READONLY |
- OFN_EXPLORER | OFN_LONGNAMES | OFN_NOCHANGEDIR;
- ofn.lpstrDefExt = L"msl";
-
- if (GetOpenFileName(&ofn)) {
- CMStringW relpath;
- pathToRelative(filename, relpath);
- smc->SetFilename(relpath);
-
- return true;
- }
-
- return false;
-}
-
-void OptionsDialogType::FilenameChanged(void)
-{
- wchar_t str[MAX_PATH];
- GetDlgItemText(m_hwndDialog, IDC_FILENAME, str, _countof(str));
-
- SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(GetSelProto());
- if (smc->GetFilename() != str) {
- CMStringW temp(str);
- smc->SetFilename(temp);
- UpdateControls();
- }
-}
-
-void OptionsDialogType::ShowSmileyPreview(void)
-{
- RECT rect;
- GetWindowRect(GetDlgItem(m_hwndDialog, IDC_SMLOPTBUTTON), &rect);
-
- SmileyToolWindowParam *stwp = new SmileyToolWindowParam;
- stwp->pSmileyPack = &smPack;
- stwp->hWndParent = m_hwndDialog;
- stwp->hWndTarget = nullptr;
- stwp->targetMessage = 0;
- stwp->targetWParam = 0;
- stwp->xPosition = rect.left;
- stwp->yPosition = rect.bottom + 4;
- stwp->direction = 1;
- stwp->hContact = NULL;
-
- mir_forkThread<SmileyToolWindowParam>(SmileyToolThread, stwp);
-}
+/////////////////////////////////////////////////////////////////////////////////////////
void OptionsType::Save(void)
{
@@ -610,31 +113,381 @@ void OptionsType::WriteContactCategory(MCONTACT hContact, const CMStringW &cats) /////////////////////////////////////////////////////////////////////////////////////////
// Init and de-init functions, called from main
-static INT_PTR CALLBACK DlgProcSmileysOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+class COptionsDialog : public CDlgBase
{
- OptionsDialogType *pOD = (OptionsDialogType*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- if (pOD == nullptr) {
- pOD = new OptionsDialogType(hwndDlg);
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)pOD);
+ SmileyCategoryListType tmpsmcat;
+ SmileyPackType smPack;
+
+ bool BrowseForSmileyPacks(int item)
+ {
+ wchar_t filter[512], filename[MAX_PATH] = L"";
+ mir_snwprintf(filter, L"%s (*.msl;*.asl;*.xep)%c*.msl;*.asl;*.xep%c%s (*.*)%c*.*%c", TranslateT("Smiley packs"), 0, 0, TranslateT("All files"), 0, 0);
+
+ CMStringW inidir;
+ SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(item);
+ if (smc->GetFilename().IsEmpty())
+ inidir = VARSW(L"Smileys");
+ else {
+ inidir = VARSW(smc->GetFilename());
+ inidir.Truncate(inidir.ReverseFind('\\'));
+ }
+
+ OPENFILENAME ofn = {};
+ ofn.lpstrFile = filename;
+ ofn.nMaxFile = _countof(filename);
+ ofn.lpstrInitialDir = inidir.c_str();
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.hwndOwner = m_hwnd;
+ ofn.lpstrFilter = filter;
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_READONLY | OFN_EXPLORER | OFN_LONGNAMES | OFN_NOCHANGEDIR;
+ ofn.lpstrDefExt = L"msl";
+ if (!GetOpenFileNameW(&ofn))
+ return false;
+
+ wchar_t szOutPath[MAX_PATH];
+ PathToRelativeW(filename, szOutPath);
+ smc->SetFilename(szOutPath);
+ return true;
}
- INT_PTR Result = pOD->DialogProcedure(msg, wParam, lParam);
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, Result);
+ long GetSelProto(HTREEITEM hItem = nullptr)
+ {
+ TVITEMEX tvi = {};
+ tvi.mask = TVIF_PARAM;
+ tvi.hItem = hItem == nullptr ? categories.GetSelection() : hItem;
+ categories.GetItem(&tvi);
+ return (long)tvi.lParam;
+ }
- if (msg == WM_NCDESTROY)
- delete pOD;
+ void PopulateSmPackList(void)
+ {
+ categories.SelectItem(NULL);
+ categories.DeleteAllItems();
+
+ UpdateVisibleSmPackList();
+
+ TVINSERTSTRUCT tvi = {};
+ tvi.hParent = TVI_ROOT;
+ tvi.hInsertAfter = TVI_LAST;
+ tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_STATE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
+ tvi.item.stateMask = TVIS_STATEIMAGEMASK | TVIS_SELECTED;
+
+ SmileyCategoryListType::SmileyCategoryVectorType &smc = *tmpsmcat.GetSmileyCategoryList();
+ for (int i = 0; i < smc.getCount(); i++) {
+ if (smc[i].IsVisible()) {
+ tvi.item.pszText = (wchar_t *)smc[i].GetDisplayName().c_str();
+ if (!smc[i].IsProto()) {
+ tvi.item.iImage = 0;
+ tvi.item.iSelectedImage = 0;
+ }
+ else {
+ tvi.item.iImage = i;
+ tvi.item.iSelectedImage = i;
+ }
+ tvi.item.lParam = i;
+ tvi.item.state = INDEXTOSTATEIMAGEMASK(smPack.LoadSmileyFile(smc[i].GetFilename(), smc[i].GetDisplayName(), true, true) ? 2 : 1);
+ categories.InsertItem(&tvi);
- return Result;
-}
+ smPack.Clear();
+ }
+ }
+ categories.SelectItem(categories.GetRoot());
+ }
+
+ void UpdateControls(bool force = false)
+ {
+ const SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(GetSelProto());
+ if (smc == nullptr)
+ return;
+
+ const CMStringW &smf = smc->GetFilename();
+ SetDlgItemText(m_hwnd, IDC_FILENAME, smf);
+
+ if (smPack.GetFilename() != smf || force)
+ smPack.LoadSmileyFile(smf, smPack.GetName(), false, true);
+
+ categories.SetCheckState(categories.GetSelection(), smPack.SmileyCount() != 0);
+
+ SetDlgItemText(m_hwnd, IDC_LIBAUTHOR, smPack.GetAuthor().c_str());
+ SetDlgItemText(m_hwnd, IDC_LIBVERSION, smPack.GetVersion().c_str());
+ SetDlgItemText(m_hwnd, IDC_LIBNAME, TranslateW(smPack.GetName().c_str()));
+ }
+
+ void UpdateVisibleSmPackList()
+ {
+ bool useOne = !chkStdPack.GetState();
+ bool usePhysProto = chkUsePhys.GetState();
+
+ SmileyCategoryListType::SmileyCategoryVectorType &smc = *tmpsmcat.GetSmileyCategoryList();
+ for (auto &it : smc) {
+ bool visiblecat = usePhysProto ? !it->IsAcc() : !it->IsPhysProto();
+ bool visible = useOne ? !it->IsProto() : visiblecat;
+
+ if (!visible && it->IsAcc() && !useOne) {
+ CMStringW PhysProtoName = L"AllProto";
+ CMStringW ProtoName = it->GetName();
+ DBVARIANT dbv;
+ if (db_get_ws(0, _T2A(ProtoName.GetBuffer()), "AM_BaseProto", &dbv) == 0) {
+ ProtoName = dbv.pwszVal;
+ db_free(&dbv);
+ }
+ else
+ ProtoName.Empty();
+
+ CMStringW FileName;
+ if (!ProtoName.IsEmpty()) {
+ PhysProtoName += ProtoName;
+ SmileyCategoryType *scm = tmpsmcat.GetSmileyCategory(PhysProtoName);
+ if (scm == nullptr)
+ visible = false;
+ else if (scm->GetFilename().IsEmpty())
+ visible = true;
+ }
+ }
+
+ it->SetVisible(visible);
+ }
+ }
+
+ void UserAction(HTREEITEM hItem)
+ {
+ if (categories.GetCheckState(hItem)) {
+ if (!BrowseForSmileyPacks(GetSelProto(hItem)))
+ categories.SetCheckState(hItem, TRUE);
+ }
+ else tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename();
+
+ if (hItem == categories.GetSelection())
+ UpdateControls();
+ else
+ categories.SelectItem(hItem);
+
+ NotifyChange();
+ PopulateSmPackList();
+ }
+
+ CCtrlEdit edtFilename;
+ CCtrlCheck chkStdPack, chkUsePhys;
+ CCtrlButton btnAdd, btnBrowse, btnDelete, btnPreview;
+ CCtrlTreeView categories;
+
+public:
+ COptionsDialog() :
+ CDlgBase(g_plugin, IDD_OPT_SMILEYS),
+ btnAdd(this, IDC_ADDCATEGORY),
+ btnBrowse(this, IDC_BROWSE),
+ btnDelete(this, IDC_DELETECATEGORY),
+ btnPreview(this, IDC_SMLOPTBUTTON),
+ chkStdPack(this, IDC_USESTDPACK),
+ chkUsePhys(this, IDC_USEPHYSPROTO),
+ categories(this, IDC_CATEGORYLIST),
+ edtFilename(this, IDC_FILENAME)
+ {
+ btnAdd.OnClick = Callback(this, &COptionsDialog::onClick_Add);
+ btnBrowse.OnClick = Callback(this, &COptionsDialog::onClick_Browse);
+ btnDelete.OnClick = Callback(this, &COptionsDialog::onClick_Delete);
+ btnPreview.OnClick = Callback(this, &COptionsDialog::onClick_Preview);
+
+ chkStdPack.OnChange = Callback(this, &COptionsDialog::onChange_StdPack);
+ chkUsePhys.OnChange = Callback(this, &COptionsDialog::onChange_UsePhys);
+ edtFilename.OnChange = Callback(this, &COptionsDialog::onChange_Filename);
+
+ categories.OnSelChanged = Callback(this, &COptionsDialog::onSelectChange_Tree);
+ categories.OnItemChanged = Callback(this, &COptionsDialog::onChange_Filename);
+ }
+
+ bool OnInitDialog() override
+ {
+ chkStdPack.SetState(opt.UseOneForAll);
+ chkUsePhys.SetState(opt.UsePhysProto);
+ chkUsePhys.Enable(!opt.UseOneForAll);
+
+ CheckDlgButton(m_hwnd, IDC_SPACES, opt.EnforceSpaces ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_SCALETOTEXTHEIGHT, opt.ScaleToTextheight ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_APPENDSPACES, opt.SurroundSmileyWithSpaces ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_SCALEALLSMILEYS, opt.ScaleAllSmileys ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_IEVIEWSTYLE, opt.IEViewStyle ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_ANIMATESEL, opt.AnimateSel ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_ANIMATEDLG, opt.AnimateDlg ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_INPUTSMILEYS, opt.InputSmileys ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_DCURSORSMILEY, opt.DCursorSmiley ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_DISABLECUSTOM, opt.DisableCustom ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_HQSCALING, opt.HQScaling ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(m_hwnd, IDC_SORTING_HORIZONTAL, opt.HorizontalSorting ? BST_CHECKED : BST_UNCHECKED);
+
+ SendDlgItemMessage(m_hwnd, IDC_MAXCUSTSPIN, UDM_SETRANGE32, 0, 99);
+ SendDlgItemMessage(m_hwnd, IDC_MAXCUSTSPIN, UDM_SETPOS, 0, opt.MaxCustomSmileySize);
+ SendDlgItemMessage(m_hwnd, IDC_MAXCUSTSMSZ, EM_LIMITTEXT, 2, 0);
+
+ SendDlgItemMessage(m_hwnd, IDC_MINSPIN, UDM_SETRANGE32, 0, 99);
+ SendDlgItemMessage(m_hwnd, IDC_MINSPIN, UDM_SETPOS, 0, opt.MinSmileySize);
+ SendDlgItemMessage(m_hwnd, IDC_MINSMSZ, EM_LIMITTEXT, 2, 0);
+
+ // Create and populate image list
+ HIMAGELIST hImList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
+ ILC_MASK | ILC_COLOR32, g_SmileyCategories.NumberOfSmileyCategories(), 0);
+
+ tmpsmcat = g_SmileyCategories;
+
+ SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList();
+ for (auto &it : smc) {
+ HICON hIcon = nullptr;
+ if (it->IsProto()) {
+ hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0);
+ if (hIcon == nullptr || (INT_PTR)hIcon == CALLSERVICE_NOTFOUND)
+ hIcon = (HICON)CallProtoService(_T2A(it->GetName().c_str()), PS_LOADICON, PLI_PROTOCOL, 0);
+ }
+ if (hIcon == nullptr || hIcon == (HICON)CALLSERVICE_NOTFOUND)
+ hIcon = GetDefaultIcon();
+
+ ImageList_AddIcon(hImList, hIcon);
+ DestroyIcon(hIcon);
+ }
+
+ categories.SetImageList(hImList, TVSIL_NORMAL);
+
+ PopulateSmPackList();
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ ProcessAllInputAreas(true);
+ CloseSmileys();
+
+ opt.UseOneForAll = chkStdPack.GetState();
+ opt.UsePhysProto = chkUsePhys.GetState();
+
+ opt.EnforceSpaces = IsDlgButtonChecked(m_hwnd, IDC_SPACES) == BST_CHECKED;
+ opt.ScaleToTextheight = IsDlgButtonChecked(m_hwnd, IDC_SCALETOTEXTHEIGHT) == BST_CHECKED;
+ opt.SurroundSmileyWithSpaces = IsDlgButtonChecked(m_hwnd, IDC_APPENDSPACES) == BST_CHECKED;
+ opt.ScaleAllSmileys = IsDlgButtonChecked(m_hwnd, IDC_SCALEALLSMILEYS) == BST_CHECKED;
+ opt.IEViewStyle = IsDlgButtonChecked(m_hwnd, IDC_IEVIEWSTYLE) == BST_CHECKED;
+ opt.AnimateSel = IsDlgButtonChecked(m_hwnd, IDC_ANIMATESEL) == BST_CHECKED;
+ opt.AnimateDlg = IsDlgButtonChecked(m_hwnd, IDC_ANIMATEDLG) == BST_CHECKED;
+ opt.InputSmileys = IsDlgButtonChecked(m_hwnd, IDC_INPUTSMILEYS) == BST_CHECKED;
+ opt.DCursorSmiley = IsDlgButtonChecked(m_hwnd, IDC_DCURSORSMILEY) == BST_CHECKED;
+ opt.DisableCustom = IsDlgButtonChecked(m_hwnd, IDC_DISABLECUSTOM) == BST_CHECKED;
+ opt.HQScaling = IsDlgButtonChecked(m_hwnd, IDC_HQSCALING) == BST_CHECKED;
+ opt.HorizontalSorting = IsDlgButtonChecked(m_hwnd, IDC_SORTING_HORIZONTAL) == BST_CHECKED;
+
+ opt.MaxCustomSmileySize = GetDlgItemInt(m_hwnd, IDC_MAXCUSTSMSZ, nullptr, FALSE);
+ opt.MinSmileySize = GetDlgItemInt(m_hwnd, IDC_MINSMSZ, nullptr, FALSE);
+
+ opt.Save();
+
+ // Cleanup database
+ CMStringW empty;
+ SmileyCategoryListType::SmileyCategoryVectorType &smc = *g_SmileyCategories.GetSmileyCategoryList();
+ for (auto &it : smc)
+ if (tmpsmcat.GetSmileyCategory(it->GetName()) == nullptr)
+ opt.WritePackFileName(empty, it->GetName());
+
+ g_SmileyCategories = tmpsmcat;
+ g_SmileyCategories.SaveSettings();
+ g_SmileyCategories.ClearAndLoadAll();
+
+ smPack.LoadSmileyFile(tmpsmcat.GetSmileyCategory(GetSelProto())->GetFilename(), tmpsmcat.GetSmileyCategory(GetSelProto())->GetDisplayName(), false, true);
+
+ NotifyEventHooks(hEvent1, 0, 0);
+ ProcessAllInputAreas(false);
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ HIMAGELIST hImList = categories.GetImageList(TVSIL_NORMAL);
+ ImageList_Destroy(hImList);
+ }
+
+ void onClick_Add(CCtrlButton*)
+ {
+ wchar_t cat[30];
+ GetDlgItemText(m_hwnd, IDC_NEWCATEGORY, cat, _countof(cat));
+ CMStringW catd = cat;
+
+ if (!catd.IsEmpty()) {
+ tmpsmcat.AddCategory(cat, catd, smcCustom, DEFAULT_FILE_NAME);
+
+ PopulateSmPackList();
+ NotifyChange();
+ }
+ }
+
+ void onClick_Browse(CCtrlButton*)
+ {
+ if (BrowseForSmileyPacks(GetSelProto())) {
+ UpdateControls(true);
+ NotifyChange();
+ }
+ }
+
+ void onClick_Delete(CCtrlButton*)
+ {
+ if (tmpsmcat.DeleteCustomCategory(GetSelProto())) {
+ PopulateSmPackList();
+ NotifyChange();
+ }
+ }
+
+ void onClick_Preview(CCtrlButton*)
+ {
+ RECT rect;
+ GetWindowRect(GetDlgItem(m_hwnd, IDC_SMLOPTBUTTON), &rect);
+
+ SmileyToolWindowParam *stwp = new SmileyToolWindowParam;
+ stwp->pSmileyPack = &smPack;
+ stwp->hWndParent = m_hwnd;
+ stwp->hWndTarget = nullptr;
+ stwp->targetMessage = 0;
+ stwp->targetWParam = 0;
+ stwp->xPosition = rect.left;
+ stwp->yPosition = rect.bottom + 4;
+ stwp->direction = 1;
+ stwp->hContact = NULL;
+
+ mir_forkThread<SmileyToolWindowParam>(SmileyToolThread, stwp);
+ }
+
+ void onChange_Filename(CCtrlEdit*)
+ {
+ wchar_t str[MAX_PATH];
+ GetDlgItemTextW(m_hwnd, IDC_FILENAME, str, _countof(str));
+
+ SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(GetSelProto());
+ if (smc->GetFilename() != str) {
+ smc->SetFilename(str);
+ UpdateControls();
+ }
+ }
+
+ void onChange_StdPack(CCtrlCheck*)
+ {
+ chkUsePhys.Enable(chkStdPack.GetState());
+ PopulateSmPackList();
+ NotifyChange();
+ }
+
+ void onChange_UsePhys(CCtrlCheck*)
+ {
+ PopulateSmPackList();
+ NotifyChange();
+ }
+
+ void onSelectChange_Tree(CCtrlTreeView::TEventInfo *ev)
+ {
+ if (ev->nmtv->itemNew.state & TVIS_SELECTED)
+ UpdateControls();
+ }
+};
int SmileysOptionsInitialize(WPARAM addInfo, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 910000000;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SMILEYS);
odp.szTitle.a = LPGEN("Smileys");
odp.szGroup.a = LPGEN("Customize");
- odp.pfnDlgProc = DlgProcSmileysOptions;
+ odp.pDialog = new COptionsDialog();
odp.flags = ODPF_BOLDGROUPS;
g_plugin.addOptions(addInfo, &odp);
return 0;
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index b661ce2f0c..9e70af2581 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -350,9 +350,8 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW & return false; } - CMStringW modpath; - pathToAbsolute(filename, modpath); - if (_waccess(filename, 4) != 0) { + CMStringW modpath = VARSW(filename); + if (_waccess(modpath, 4) != 0) { if (!noerr) { static const wchar_t errmsg[] = LPGENW("Smiley pack %s for category \"%s\" not found.\nSelect correct smiley pack in the Options -> Customize -> Smileys."); wchar_t msgtxt[1024]; @@ -668,12 +667,10 @@ bool SmileyPackListType::AddSmileyPack(CMStringW &filename, CMStringW &packname) SmileyPackType* SmileyPackListType::GetSmileyPack(CMStringW &filename) { - CMStringW modpath; - pathToAbsolute(filename, modpath); + CMStringW modpath = VARSW(filename); for (auto &it : m_SmileyPacks) { - CMStringW modpath1; - pathToAbsolute(it->GetFilename(), modpath1); + CMStringW modpath1(VARSW(it->GetFilename())); if (mir_wstrcmpi(modpath.c_str(), modpath1.c_str()) == 0) return it; } @@ -749,7 +746,7 @@ SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(unsigned index) return index < (unsigned)m_SmileyCategories.getCount() ? &m_SmileyCategories[index] : nullptr; } -SmileyPackType* SmileyCategoryListType::GetSmileyPack(CMStringW &categoryname) +SmileyPackType* SmileyCategoryListType::GetSmileyPack(const CMStringW &categoryname) { SmileyCategoryType *smc = GetSmileyCategory(categoryname); return smc != nullptr ? smc->GetSmileyPack() : nullptr; @@ -774,7 +771,8 @@ void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW & if (GetSmileyCategory(name) != nullptr) return; - AddCategory(name, displayName, smcExt); + AddCategory(name, displayName, smcExt, DEFAULT_FILE_NAME); + // Load only if other smileys have been loaded already if (m_SmileyCategories.getCount() > 1) m_SmileyCategories[m_SmileyCategories.getCount() - 1].Load(); @@ -823,10 +821,7 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStr char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - paths = _A2T(path); - CMStringW patha; - pathToAbsolute(paths, patha); - + CMStringW patha = VARSW(_A2T(path)); if (_waccess(patha.c_str(), 0) != 0) paths = defaultFile; } @@ -850,11 +845,10 @@ void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMStringW &defa char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - CMStringW paths = _A2T(path), patha; - pathToAbsolute(paths, patha); - + CMStringW paths = _A2T(path), patha = VARSW(paths); if (_waccess(patha.c_str(), 0) != 0) paths = defaultFile; + CMStringW dName(acc), displayName; displayName.AppendFormat(TranslateT("%s global smiley pack"), dName.GetBuffer()); CMStringW tname("AllProto"); @@ -922,9 +916,7 @@ void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, co char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packname); - CMStringW paths = _A2T(path), patha; - pathToAbsolute(paths, patha); - + CMStringW paths = _A2T(path), patha = VARSW(paths); if (_waccess(patha.c_str(), 0) != 0) paths = defaultFile; @@ -940,7 +932,7 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void) { CMStringW displayName = TranslateT("Standard"); CMStringW tname = L"Standard"; - AddCategory(tname, displayName, smcStd); + AddCategory(tname, displayName, smcStd, DEFAULT_FILE_NAME); const CMStringW &defaultFile = GetSmileyCategory(tname)->GetFilename(); diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index dfcde52468..00252e758f 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MS_SMILEYADD_CUSTOMCATMENU "SmileyAdd/CustomCatMenu"
+#define DEFAULT_FILE_NAME L"Smileys\\nova\\default.msl"
+
const unsigned HiddenSmiley = 1;
const unsigned RegExSmiley = 2;
const unsigned ServiceSmiley = 4;
@@ -274,8 +276,8 @@ public: SmileyPackType* GetSmileyPack(void);
- void SetFilename(CMStringW& name) { m_Filename = name; }
- void SetDisplayName(CMStringW& name) { m_DisplayName = name; }
+ void SetFilename(const CMStringW& name) { m_Filename = name; }
+ void SetDisplayName(const CMStringW& name) { m_DisplayName = name; }
void SetVisible(bool vis) { visible = vis; }
void ClearFilename(void) { m_Filename.Empty(); }
@@ -297,20 +299,19 @@ private: public:
void SetSmileyPackStore(SmileyPackListType *pSPS) { m_pSmileyPackStore = pSPS; }
- SmileyCategoryType* GetSmileyCategory(const CMStringW& name);
+ SmileyCategoryType* GetSmileyCategory(const CMStringW &name);
SmileyCategoryType* GetSmileyCategory(unsigned index);
- SmileyPackType* GetSmileyPack(CMStringW& name);
+ SmileyPackType* GetSmileyPack(const CMStringW &name);
SmileyCategoryVectorType* GetSmileyCategoryList(void) { return &m_SmileyCategories; };
int NumberOfSmileyCategories(void) { return m_SmileyCategories.getCount(); }
- void AddCategory(const CMStringW& name, const CMStringW& displayName, SmcType typ,
- const CMStringW& defaultFilename = CMStringW(L"Smileys\\nova\\default.msl"));
- void AddAndLoad(const CMStringW& name, const CMStringW& displayName);
+ void AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename);
+ void AddAndLoad(const CMStringW &name, const CMStringW &displayName);
void AddAllProtocolsAsCategory(void);
- void AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW& defaultFile);
- void AddProtoAsCategory(char *acc, const CMStringW& defaultFile);
- void AddContactTransportAsCategory(MCONTACT hContact, const CMStringW& defaultFile);
+ void AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW &defaultFile);
+ void AddProtoAsCategory(char *acc, const CMStringW &defaultFile);
+ void AddContactTransportAsCategory(MCONTACT hContact, const CMStringW &defaultFile);
void ClearAndLoadAll(void);
void ClearAll(void)
diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h index 35949d1e36..d0d2bc2fa1 100644 --- a/plugins/SmileyAdd/src/stdafx.h +++ b/plugins/SmileyAdd/src/stdafx.h @@ -52,26 +52,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <win2k.h>
#include <newpluginapi.h>
+#include <m_button.h>
#include <m_clist.h>
-#include <m_langpack.h>
-#include <m_options.h>
-#include <m_protosvc.h>
#include <m_database.h>
-#include <m_button.h>
-#include <m_message.h>
-#include <m_netlib.h>
+#include <m_folders.h>
+#include <m_fontservice.h>
#include <m_hotkeys.h>
-#include <m_popup.h>
-#include <m_icolib.h>
#include <m_genmenu.h>
+#include <m_gui.h>
+#include <m_icolib.h>
#include <m_imgsrvc.h>
-#include <m_regexp.h>
-#include <m_fontservice.h>
-#include <m_xml.h>
-
+#include <m_langpack.h>
+#include <m_message.h>
#include <m_metacontacts.h>
+#include <m_netlib.h>
+#include <m_options.h>
+#include <m_popup.h>
+#include <m_protosvc.h>
+#include <m_regexp.h>
#include <m_smileyadd.h>
-#include <m_folders.h>
+#include <m_xml.h>
#include "resource.h"
#include "version.h"
@@ -129,9 +129,6 @@ bool IsSmileyProto(char *proto); HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle);
-void pathToRelative(const CMStringW &pSrc, CMStringW &pOut);
-void pathToAbsolute(const CMStringW &pSrc, CMStringW &pOut);
-
bool InitGdiPlus(void);
void DestroyGdiPlus(void);
diff --git a/plugins/SmileyAdd/src/version.h b/plugins/SmileyAdd/src/version.h index 9f256db3d2..96815a5b35 100644 --- a/plugins/SmileyAdd/src/version.h +++ b/plugins/SmileyAdd/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 3
#define __RELEASE_NUM 1
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|