soc.2009.vulture: 7ba356cc: Some buddy-icon work in main accounts pr...
gdick at soc.pidgin.im
gdick at soc.pidgin.im
Wed Sep 9 12:16:30 EDT 2009
-----------------------------------------------------------------
Revision: 7ba356cc366f1069b60235bdb0537386450bf5e0
Ancestor: 12884c0672921a5ca0c7b0a316e14d1c037c6774
Author: gdick at soc.pidgin.im
Date: 2009-09-09T16:13:20
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/7ba356cc366f1069b60235bdb0537386450bf5e0
Modified files:
vulture/acctmanager.c vulture/purplebicon.c
vulture/purplebicon.h vulture/vulture-res.rc
ChangeLog:
Some buddy-icon work in main accounts property page.
-------------- next part --------------
============================================================
--- vulture/acctmanager.c e9d2d6ff60f2f6d0bc5ce5c0a12b9d6e0ede16ed
+++ vulture/acctmanager.c 6c3e86ea823742ff08bff91ecd40521806f7e776
@@ -27,6 +27,8 @@
#include "vulture.h"
#include "resource.h"
#include "acctmanager.h"
+#include "purplebicon.h"
+#include "vultureblist.h"
@@ -41,9 +43,12 @@ static void EnableDisableBIconSelectCont
static void EditAccountByIndex(HWND hwndDlg, int iItem);
static INT_PTR CALLBACK AccountAccountPropPageProc(HWND hwndDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
static void EnableDisableBIconSelectControls(HWND hwndPropPage);
+static void UpdateBIconPreview(HWND hwndPropPage);
#define CCH_ACCMGR_HEADER 64
+#define BICON_CHANGE_TIMEOUT 500
+#define BICON_CHANGE_TIMER_ID 1
enum ENUM_ACCOUNT_PROP_PAGES
{
@@ -347,6 +352,7 @@ static INT_PTR CALLBACK AccountAccountPr
{
if(lpvac->szBIcon) SetDlgItemText(hwndPropPage, IDC_EDIT_BICON, lpvac->szBIcon);
CheckRadioButton(hwndPropPage, IDC_RADIO_BICONGLOBAL, IDC_RADIO_BICONNONE, lpvac->bOverrideBIcon ? (lpvac->szBIcon ? IDC_RADIO_BICONOVERRIDE : IDC_RADIO_BICONNONE) : IDC_RADIO_BICONGLOBAL);
+ UpdateBIconPreview(hwndPropPage);
}
else
{
@@ -373,6 +379,33 @@ static INT_PTR CALLBACK AccountAccountPr
case IDC_RADIO_BICONNONE:
EnableDisableBIconSelectControls(hwndPropPage);
return TRUE;
+
+ case IDC_EDIT_BICON:
+ if(HIWORD(wParam) == EN_CHANGE)
+ {
+ SetTimer(hwndPropPage, BICON_CHANGE_TIMER_ID, BICON_CHANGE_TIMEOUT, NULL);
+ return TRUE;
+ }
+
+ break;
+
+ case IDC_BUTTON_BICONBROWSE:
+ {
+ TCHAR szFilename[MAX_PATH];
+ TCHAR szFilter[256];
+ TCHAR szTitle[256];
+
+ VultureLoadAndFormatFilterString(IDS_BUDDYICON_FILTER, szFilter, NUM_ELEMENTS(szFilter));
+ LoadString(g_hInstance, IDS_BUDDYICON_TITLE, szTitle, NUM_ELEMENTS(szTitle));
+
+ if(VultureCommDlgOpen(g_hwndMain, szFilename, NUM_ELEMENTS(szFilename), szTitle, szFilter, TEXT("png"), NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY))
+ {
+ SetDlgItemText(hwndPropPage, IDC_EDIT_BICON, szFilename);
+ UpdateBIconPreview(hwndPropPage);
+ }
+ }
+
+ return TRUE;
}
break;
@@ -466,6 +499,16 @@ static INT_PTR CALLBACK AccountAccountPr
}
break;
+
+ case WM_TIMER:
+ if(wParam == BICON_CHANGE_TIMER_ID)
+ {
+ UpdateBIconPreview(hwndPropPage);
+ KillTimer(hwndPropPage, BICON_CHANGE_TIMER_ID);
+ return TRUE;
+ }
+
+ break;
}
return FALSE;
@@ -476,7 +519,7 @@ static INT_PTR CALLBACK AccountAccountPr
* Enables or disables the buddy-icon selection controls, according to the
* selected radio button.
*
- * @param hwndPropPage Property-page window handle.
+ * @param hwndPropPage Window handle for main accounts property page.
*/
static void EnableDisableBIconSelectControls(HWND hwndPropPage)
{
@@ -486,3 +529,34 @@ static void EnableDisableBIconSelectCont
EnableWindow(GetDlgItem(hwndPropPage, IDC_EDIT_BICON), bEnable);
EnableWindow(GetDlgItem(hwndPropPage, IDC_BUTTON_BICONBROWSE), bEnable);
}
+
+
+/**
+ * Updates the buddy-icon preview for the main accounts property page according
+ * to the value of the corresponding edit control.
+ *
+ * @param hwndPropPage Window handle for main accounts property page.
+ */
+static void UpdateBIconPreview(HWND hwndPropPage)
+{
+ HWND hwndEdit = GetDlgItem(hwndPropPage, IDC_EDIT_BICON);
+ int cchBIcon = GetWindowTextLength(hwndEdit) + 1;
+ HBITMAP hbitmap = NULL;
+
+ if(cchBIcon > 1)
+ {
+ LPTSTR szBIcon = ProcHeapAlloc(cchBIcon * sizeof(TCHAR));
+ RECT rcBIcon;
+
+ GetWindowRect(GetDlgItem(hwndPropPage, IDC_STATIC_BICON), &rcBIcon);
+ GetWindowText(hwndEdit, szBIcon, cchBIcon);
+ hbitmap = VultureLoadBuddyIcon(szBIcon, rcBIcon.right - rcBIcon.left, rcBIcon.bottom - rcBIcon.top);
+ ProcHeapFree(szBIcon);
+ }
+
+ hbitmap = (HBITMAP)SendDlgItemMessage(hwndPropPage, IDC_STATIC_BICON, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmap);
+
+ /* Delete former bitmap if there was one. */
+ if(hbitmap)
+ DeleteObject(hbitmap);
+}
============================================================
--- vulture/purplebicon.c cda8a6fddfb7bc0780191f6fe2cc48334bd6adf8
+++ vulture/purplebicon.c 1c47c141cfc1d65738888760aa98c15d79b431e5
@@ -516,3 +516,43 @@ void SetAccountBuddyIcon(PurpleAccount *
purple_account_set_buddy_icon_path(lpaccount, szFilename);
}
+
+
+/**
+ * Loads a bitmap from a file. It is scaled, with its aspect ratio maintained,
+ * so as not to exceed the specified dimensions, unless either of these is non-
+ * positive, in which case no scaling is performed.
+ *
+ * @param szFilename Filename.
+ * @param cxMax Maximum width.
+ * @param cyMax Maximum height.
+ *
+ * @return Bitmap handle, or NULL on error.
+ */
+HBITMAP VultureLoadBuddyIcon(LPCTSTR szFilename, int cxMax, int cyMax)
+{
+ HANDLE hFile = CreateFile(szFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if(hFile != INVALID_HANDLE_VALUE)
+ {
+ DWORD cbFile = GetFileSize(hFile, NULL);
+
+ if(cbFile != INVALID_FILE_SIZE)
+ {
+ HBITMAP hbitmap;
+ LPVOID lpvData = ProcHeapAlloc(cbFile);
+ DWORD cbRead;
+
+ ReadFile(hFile, lpvData, cbFile, &cbRead, NULL);
+ hbitmap = GetBuddyIcon(lpvData, cbRead, cxMax, cyMax);
+
+ ProcHeapFree(lpvData);
+
+ return hbitmap;
+ }
+
+ CloseHandle(hFile);
+ }
+
+ return NULL;
+}
============================================================
--- vulture/purplebicon.h e23b58bf6fdadd78c8eb326dc96471d14db38878
+++ vulture/purplebicon.h 8fbf5be9362e08158997bfba1acc3214b5d4af04
@@ -34,6 +34,7 @@ void SetAccountBuddyIcon(PurpleAccount *
void PurpleGlobalBuddyIconPrefChanged(const char *szName, PurplePrefType preftype, gconstpointer lpvValue, gpointer lpvData);
void PurpleRefreshBuddyIcon(const gchar *szFilename);
void SetAccountBuddyIcon(PurpleAccount *lpaccount, const gchar *szFilename);
+HBITMAP VultureLoadBuddyIcon(LPCTSTR szFilename, int cxMax, int cyMax);
#endif
============================================================
--- vulture/vulture-res.rc 35324fde12a57836118c5e58eac40ea4d820d1cf
+++ vulture/vulture-res.rc 06715c1aa6b83e175e70aff6d95b0e4e7c3a7ed6
@@ -183,7 +183,7 @@ FONT 8, "Ms Shell Dlg"
LTEXT "Choose the settings used to log into this account.", IDC_STATIC, 15, 20, 220, 9, SS_LEFT
LTEXT "Protocol:", IDC_STATIC, 15, 42, 55, 8, SS_LEFT
LTEXT "", IDC_STATIC_PROTOCOL, 125, 42, 110, 10, SS_LEFT
- CONTROL "", IDC_STATIC_PROTOICON, "Static", SS_CENTERIMAGE, 105, 42, 12, 9
+ CONTROL "", IDC_STATIC_PROTOICON, "Static", SS_BITMAP | SS_CENTERIMAGE, 105, 42, 12, 9
LTEXT "&Username:", IDC_STATIC, 15, 57, 55, 8, SS_LEFT
EDITTEXT IDC_EDIT_USERNAME, 75, 55, 160, 12, ES_AUTOHSCROLL
LTEXT "&Password:", IDC_STATIC, 15, 72, 55, 8, SS_LEFT
@@ -198,7 +198,7 @@ FONT 8, "Ms Shell Dlg"
AUTORADIOBUTTON "Use the &following buddy icon:", IDC_RADIO_BICONOVERRIDE, 15, 210, 215, 10
AUTORADIOBUTTON "&Don't show a buddy icon for this account", IDC_RADIO_BICONNONE, 15, 260, 215, 10
LTEXT "Buddy icons can be set on a per-account basis if desired.", IDC_STATIC, 15, 180, 220, 10, SS_LEFT
- CONTROL "", IDC_STATIC_BICON, "Static", SS_ETCHEDFRAME, 28, 225, 35, 30
+ CONTROL "", IDC_STATIC_BICON, "Static", SS_BITMAP | SS_CENTERIMAGE | SS_SUNKEN, 28, 225, 35, 30
EDITTEXT IDC_EDIT_BICON, 75, 226, 160, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Browse...", IDC_BUTTON_BICONBROWSE, 75, 240, 65, 15
}
More information about the Commits
mailing list