diff options
Diffstat (limited to 'plugins/AVS/src/options.cpp')
-rw-r--r-- | plugins/AVS/src/options.cpp | 286 |
1 files changed, 1 insertions, 285 deletions
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index 8a489b6af2..83348a3f7f 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -26,27 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern OBJLIST<protoPicCacheEntry> g_ProtoPictures; extern HANDLE hEventChanged; -extern HICON g_hIcon; static BOOL dialoginit = TRUE; -struct WindowData -{ - WindowData(MCONTACT _1, HWND hwndDlg) : - hContact(_1) - { - hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwndDlg, DM_AVATARCHANGED); - } - - ~WindowData() - { - UnhookEvent(hHook); - } - - MCONTACT hContact; - HANDLE hHook = nullptr; -}; - static void RemoveProtoPic(protoPicCacheEntry *pce) { if (pce == nullptr) @@ -432,273 +414,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar } ///////////////////////////////////////////////////////////////////////////////////////// - -void LoadTransparentData(HWND hwndDlg, MCONTACT hContact) -{ - CheckDlgButton(hwndDlg, IDC_MAKETRANSPBKG, db_get_b(hContact, "ContactPhoto", "MakeTransparentBkg", g_plugin.getByte("MakeTransparentBkg", 0)) ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints", g_plugin.getWord("TranspBkgNumPoints", 5))); - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgColorDiff", g_plugin.getWord("TranspBkgColorDiff", 10))); - - BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), transp_enabled); -} - -static void SaveTransparentData(HWND hwndDlg, MCONTACT hContact) -{ - BOOL transp = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - if (g_plugin.getByte("MakeTransparentBkg", 0) == transp) - db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); - else - db_set_b(hContact, "ContactPhoto", "MakeTransparentBkg", transp); - - uint16_t tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0); - if (g_plugin.getWord("TranspBkgNumPoints", 5) == tmp) - db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); - else - db_set_w(hContact, "ContactPhoto", "TranspBkgNumPoints", tmp); - - tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0); - if (g_plugin.getWord("TranspBkgColorDiff", 10) == tmp) - db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); - else - db_set_w(hContact, "ContactPhoto", "TranspBkgColorDiff", tmp); -} - -void SaveTransparentData(HWND hwndDlg, MCONTACT hContact, BOOL locked) -{ - SaveTransparentData(hwndDlg, hContact); - - MCONTACT tmp = GetContactThatHaveTheAvatar(hContact, locked); - if (tmp != hContact) - SaveTransparentData(hwndDlg, tmp); -} - -INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WindowData *dat = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - MCONTACT hContact = (dat) ? dat->hContact : INVALID_CONTACT_ID; - - switch (msg) { - case WM_INITDIALOG: - dat = new WindowData(hContact = lParam, hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - - TranslateDialogDefault(hwndDlg); - if (hContact) { - wchar_t szTitle[512]; - mir_snwprintf(szTitle, TranslateT("Set avatar options for %s"), Clist_GetContactDisplayName(hContact)); - SetWindowText(hwndDlg, szTitle); - } - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - ShowWindow(hwndDlg, SW_SHOWNORMAL); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, FALSE); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_HIDEAVATAR, Contact::IsHidden(hContact) ? BST_CHECKED : BST_UNCHECKED); - - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2)); - - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); - - LoadTransparentData(hwndDlg, GetContactThatHaveTheAvatar(hContact)); - SendMessage(hwndDlg, WM_SETICON, IMAGE_ICON, (LPARAM)g_hIcon); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case ID_USE_DEFAULTS: - hContact = GetContactThatHaveTheAvatar(hContact); - - db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); - db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); - db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); - - LoadTransparentData(hwndDlg, hContact); - - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - break; - - case IDOK: - { - bool locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR) != 0; - bool hidden = IsDlgButtonChecked(hwndDlg, IDC_HIDEAVATAR) != 0; - SetAvatarAttribute(hContact, AVS_HIDEONCLIST, hidden); - if (hidden != Contact::IsHidden(hContact)) - Contact::Hide(hContact, hidden); - - if (!locked && db_get_b(hContact, "ContactPhoto", "NeedUpdate", 0)) - QueueAdd(hContact); - } - // Continue to the cancel handle - - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - - case IDC_PROTECTAVATAR: - { - BOOL locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR); - ProtectAvatar(hContact, locked ? 1 : 0); - } - break; - - case IDC_CHANGE: - SetAvatar(hContact, 0); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - break; - - case IDC_BKG_NUM_POINTS: - case IDC_BKG_COLOR_DIFFERENCE: - if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) - break; - - case IDC_MAKETRANSPBKG: - { - BOOL enable = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enable); - - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - } - break; - - case IDC_RESET: - ProtectAvatar(hContact, 0); - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } - } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - { - char *szProto = Proto_GetBaseAccountName(hContact); - db_unset(hContact, szProto, "AvatarHash"); - DeleteAvatarFromCache(hContact, FALSE); - - QueueAdd(hContact); - DestroyWindow(hwndDlg); - } - break; - - case IDC_DELETE: - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - ProtectAvatar(hContact, 0); - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } - } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - DeleteAvatarFromCache(hContact, FALSE); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - } - break; - - case WM_DRAWITEM: - { - LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; - if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) { - AVATARDRAWREQUEST avdrq = { 0 }; - GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw); - - FillRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNFACE)); - - avdrq.hContact = hContact; - avdrq.hTargetDC = dis->hDC; - avdrq.dwFlags |= AVDRQ_DRAWBORDER; - avdrq.clrBorder = GetSysColor(COLOR_BTNTEXT); - avdrq.radius = 6; - if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq)) { - // Get text rectangle - RECT rc = avdrq.rcDraw; - rc.top += 10; - rc.bottom -= 10; - rc.left += 10; - rc.right -= 10; - - // Calc text size - RECT rc_ret = rc; - DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc_ret, - DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT); - - // Calc needed size - rc.top += ((rc.bottom - rc.top) - (rc_ret.bottom - rc_ret.top)) / 2; - rc.bottom = rc.top + (rc_ret.bottom - rc_ret.top); - DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc, - DT_WORDBREAK | DT_NOPREFIX | DT_CENTER); - } - - FrameRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNSHADOW)); - } - } - return TRUE; - - case DM_SETAVATARNAME: - { - wchar_t szFinalName[MAX_PATH]; - DBVARIANT dbv = { 0 }; - uint8_t is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0); - - szFinalName[0] = 0; - - if (is_locked && !db_get_ws(hContact, "ContactPhoto", "Backup", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - else if (!db_get_ws(hContact, "ContactPhoto", "RFile", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - else if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - szFinalName[MAX_PATH - 1] = 0; - SetDlgItemText(hwndDlg, IDC_AVATARNAME, szFinalName); - } - break; - - case DM_REALODAVATAR: - SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR)); - ChangeAvatar(hContact, true); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - - case DM_AVATARCHANGED: - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - - case WM_NCDESTROY: - delete dat; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; - } - return FALSE; -} +// Module entry point int OptInit(WPARAM wParam, LPARAM) { |