summaryrefslogtreecommitdiff
path: root/plugins/MetaContacts/src/edit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MetaContacts/src/edit.cpp')
-rw-r--r--plugins/MetaContacts/src/edit.cpp650
1 files changed, 266 insertions, 384 deletions
diff --git a/plugins/MetaContacts/src/edit.cpp b/plugins/MetaContacts/src/edit.cpp
index cf21c42edb..a908734c50 100644
--- a/plugins/MetaContacts/src/edit.cpp
+++ b/plugins/MetaContacts/src/edit.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Contains all the functions and all the structures
* needed to display and control the <b>'Edit'</b> Dialog.
*/
+
#include "metacontacts.h"
//! Holds the differents changes that have to made
@@ -44,132 +45,93 @@ CHANGES changes; //!< \c global CHANGES structure
*
* @param chg : Structure holding all the change info (See CHANGES).
*/
-void FillContactList(HWND hWndDlg, CHANGES *chg) {
- HWND hList = GetDlgItem(hWndDlg, IDC_LST_CONTACTS);
- char *proto, *field, buff[256];
- int i;
- LVITEM LvItem;
- DBVARIANT dbv;
- LVITEMW LvItemW; // for unicode nicks
+void FillContactList(HWND hWndDlg, CHANGES *chg)
+{
+ HWND hList = GetDlgItem(hWndDlg, IDC_LST_CONTACTS);
+ TCHAR buff[256];
- SendMessage(hList,LVM_DELETEALLITEMS,0,0);
+ SendMessage(hList, LVM_DELETEALLITEMS, 0, 0);
- ZeroMemory(&LvItem, sizeof(LvItem));
- LvItem.mask=LVIF_TEXT; // Text Style
+ LVITEM LvItem = { 0 };
+ LvItem.mask = LVIF_TEXT; // Text Style
LvItem.cchTextMax = 256; // Max size of test
- ZeroMemory(&LvItemW, sizeof(LvItemW));
- LvItemW.mask=LVIF_TEXT; // Text Style
- LvItemW.cchTextMax = 256; // Max size of test
-
- for (i = 0; i < chg->num_contacts; i++) {
+ for (int i = 0; i < chg->num_contacts; i++) {
LvItem.iItem = i;
- LvItemW.iItem = i;
-
- {
-
- char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], 0);
-
- if (os_unicode_enabled) {
- wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], GCDNF_UNICODE),
- *swzContactDisplayName;
-
- LvItemW.iSubItem = 0; // clist display name
-
- // detect if the clist provided unicode display name by comparing with non-unicode
- if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0 && wcslen(swzCDN) >= strlen(szCDN)) {
- swzContactDisplayName = swzCDN;
- } else {
- // no? convert to unicode
- if (szCDN) {
- swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1));
- MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1);
- } else {
- swzContactDisplayName = TranslateW(L"(Unknown Contact)");
- }
- }
-
- LvItemW.pszText = swzContactDisplayName;
- SendMessageW(hList, LVM_INSERTITEMW, 0, (LPARAM)&LvItemW);
- } else {
- LvItem.iSubItem = 0; // clist display name
- LvItem.pszText = szCDN;
- SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&LvItem);
- }
- }
-
+
+ TCHAR *ptszCDN = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], GCDNF_TCHAR);
+ if (ptszCDN == NULL)
+ ptszCDN = TranslateT("(Unknown Contact)");
+ LvItem.iSubItem = 0; // clist display name
+ LvItem.pszText = ptszCDN;
+ ListView_InsertItem(hList, &LvItem);
LvItem.iSubItem = 1; // id
+ char *szProto = GetContactProto(chg->hContact[i]);
+ if (szProto) {
+ char *szField = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- proto = GetContactProto(chg->hContact[i]);
- if (proto) {
- field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
-
- db_get(chg->hContact[i],proto,field,&dbv);
- switch(dbv.type)
- {
+ DBVARIANT dbv;
+ if ( !db_get(chg->hContact[i], szProto, szField, &dbv)) {
+ switch(dbv.type) {
case DBVT_ASCIIZ:
- sprintf(buff,"%s",dbv.pszVal);
+ _tcsncpy(buff, _A2T(dbv.pszVal), SIZEOF(buff));
+ break;
+ case DBVT_WCHAR:
+ _tcsncpy(buff, dbv.ptszVal, SIZEOF(buff));
break;
case DBVT_BYTE:
- sprintf(buff,"%d",dbv.bVal);
+ _itot(dbv.bVal, buff, 10);
break;
case DBVT_WORD:
- sprintf(buff,"%d",dbv.wVal);
+ _itot(dbv.wVal, buff, 10);
break;
case DBVT_DWORD:
- sprintf(buff,"%d",(int)dbv.dVal);
+ _itot(dbv.dVal, buff, 10);
break;
default:
- //sprintf(buff,"");
buff[0] = 0;
+ }
+ db_free(&dbv);
}
- db_free(&dbv);
+ else buff[0] = 0;
LvItem.pszText = buff;
SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
LvItem.iSubItem = 2; // protocol
- LvItem.pszText = proto;
- SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
- } else {
- LvItem.pszText = "Unknown";
- SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
+ _tcsncpy(buff, _A2T(szProto), SIZEOF(buff));
+ ListView_SetItem(hList, &LvItem);
+ }
+ else {
+ LvItem.pszText = _T("Unknown");
+ ListView_SetItem(hList, &LvItem);
LvItem.iSubItem = 2; // protocol
- LvItem.pszText = "Unknown";
- SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
+ ListView_SetItem(hList, &LvItem);
}
LvItem.iSubItem = 3; // Default (Yes/No)
- LvItem.pszText = (chg->hContact[i] == chg->hDefaultContact ? Translate("Yes") : Translate("No"));
- SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
+ LvItem.pszText = (chg->hContact[i] == chg->hDefaultContact ? TranslateT("Yes") : TranslateT("No"));
+ ListView_SetItem(hList, &LvItem);
LvItem.iSubItem = 4; // Offline (Yes/No)
- LvItem.pszText = (chg->hContact[i] == chg->hOfflineContact ? Translate("Yes") : Translate("No"));
- SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems
+ LvItem.pszText = (chg->hContact[i] == chg->hOfflineContact ? TranslateT("Yes") : TranslateT("No"));
+ ListView_SetItem(hList, &LvItem);
}
}
-
-void SetListSelection(HWND hList, int sel) {
- LVITEM LvItem;
-
- ZeroMemory(&LvItem, sizeof(LvItem));
- LvItem.iItem = sel;
- LvItem.mask = LVIF_STATE;
- LvItem.stateMask = LVIS_SELECTED|LVIS_FOCUSED;
- LvItem.state = LVIS_SELECTED|LVIS_FOCUSED;
-
- SendMessage(hList, LVM_SETITEMSTATE, (WPARAM)sel, (LPARAM)&LvItem);
-
+void SetListSelection(HWND hList, int sel)
+{
+ ListView_SetItemState(hList, sel, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
}
/** Scans the \c CHANGES and call the appropriate function for each change.
*
* @param chg : Structure holding all the change info (See CHANGES).
*/
+
void ApplyChanges(CHANGES *chg)
{
HANDLE most_online;
@@ -223,7 +185,7 @@ void ApplyChanges(CHANGES *chg)
_tcscpy(AI.filename, _T("X"));
if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
- DBWriteContactSettingTString(chg->hMeta, "ContactPhoto", "File",AI.filename);
+ db_set_ts(chg->hMeta, "ContactPhoto", "File",AI.filename);
}
if (MetaAPI_GetForceState((WPARAM)chg->hMeta, 0) != chg->force_default)
@@ -233,33 +195,19 @@ void ApplyChanges(CHANGES *chg)
LRESULT ProcessCustomDraw (LPARAM lParam)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
-
- switch(lplvcd->nmcd.dwDrawStage)
- {
- case CDDS_PREPAINT : //Before the paint cycle begins
- //request notifications for individual listview items
- return CDRF_NOTIFYITEMDRAW;
-
- case CDDS_ITEMPREPAINT: //Before an item is drawn
- /*
- if (((int)lplvcd->nmcd.dwItemSpec%2)==0)
- {
- //customize item appearance
- //lplvcd->clrText = RGB(255,0,0);
- lplvcd->clrTextBk = RGB(200,200,200);
- }
- else{
- //lplvcd->clrText = RGB(0,0,255);
- lplvcd->clrTextBk = RGB(255,255,255);
- }
- */
- if (changes.hContact[(int)lplvcd->nmcd.dwItemSpec] == changes.hDefaultContact) {
- lplvcd->clrText = RGB(255, 0, 0);
- }
- return CDRF_NEWFONT;
- }
-
- return 0;
+ switch(lplvcd->nmcd.dwDrawStage) {
+ case CDDS_PREPAINT : //Before the paint cycle begins
+ //request notifications for individual listview items
+ return CDRF_NOTIFYITEMDRAW;
+
+ case CDDS_ITEMPREPAINT: //Before an item is drawn
+ if (changes.hContact[(int)lplvcd->nmcd.dwItemSpec] == changes.hDefaultContact) {
+ lplvcd->clrText = RGB(255, 0, 0);
+ }
+ return CDRF_NEWFONT;
+ }
+
+ return 0;
}
/** Callback function for the <b>'Edit'</b> Dialog.
@@ -273,73 +221,59 @@ LRESULT ProcessCustomDraw (LPARAM lParam)
*
* @return \c TRUE if the dialog processed the message, \c FALSE if it did not.
*/
+
#define WMU_SETTITLE (WM_USER + 1)
INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwnd;
- char *str;
int sel, i;
- switch(msg)
- {
- case WM_INITDIALOG:
+ switch(msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault( hwndDlg );
+ SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_EDIT));
{
- // Font necessary for all controls created with CreateWindowsEx
- //HFONT hfDefault = GetStockObject(DEFAULT_GUI_FONT);
- //HWND combo = GetDlgItem(hwndDlg,IDC_DEFAULT);
- int nb_contacts, default_contact_number, offline_contact_number;
- LVCOLUMN LvCol;
-
- TranslateDialogDefault( hwndDlg );
-
- SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_EDIT));
-
// Disable the 'Apply' button.
EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE);
- // (from http://www.codeproject.com/listctrl/listview.asp)
- // initialize list
hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- SendMessage(hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT); // Set style
+ ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT);
// Create list columns
- ZeroMemory(&LvCol, sizeof(LvCol));
- LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // Type of mask
-
- // Inserting Couloms as much as we want
- LvCol.pszText=Translate("Contact"); // First Header Text
- LvCol.cx=100; // width of column
- SendMessage(hwnd,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); // Insert/Show the coloum
-
- LvCol.pszText=Translate("Id"); // Next coloum
- LvCol.cx=130; // width of column
- SendMessage(hwnd,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol); // ...
- LvCol.pszText=Translate("Protocol"); //
- LvCol.cx=100; // width of column
- SendMessage(hwnd,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol); //
- LvCol.pszText=Translate("Default"); //
- LvCol.cx=60; // width of column
- SendMessage(hwnd,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol); //
- LvCol.pszText=Translate("Send Offline"); //
- LvCol.cx=85; // width of column
- SendMessage(hwnd,LVM_INSERTCOLUMN,4,(LPARAM)&LvCol); //
-
+ LVCOLUMN LvCol = { 0 };
+ LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
+
+ LvCol.pszText = TranslateT("Contact");
+ LvCol.cx = 100;
+ ListView_InsertColumn(hwnd, 0, &LvCol);
+
+ LvCol.pszText = TranslateT("Id");
+ LvCol.cx = 130;
+ ListView_InsertColumn(hwnd, 1, &LvCol);
+
+ LvCol.pszText = TranslateT("Protocol");
+ LvCol.cx = 100;
+ ListView_InsertColumn(hwnd, 2, &LvCol);
+
+ LvCol.pszText = TranslateT("Default");
+ LvCol.cx = 60;
+ ListView_InsertColumn(hwnd, 3, &LvCol);
+
+ LvCol.pszText = TranslateT("Send Offline");
+ LvCol.cx = 85;
+ ListView_InsertColumn(hwnd, 4, &LvCol);
+
// disable buttons until a selection is made in the list
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
- EnableWindow(hwnd, FALSE);
-
- nb_contacts = db_get_dw((HANDLE)lParam, META_PROTO, "NumContacts", 0);
- default_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1);
- offline_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "OfflineSend", (DWORD)-1);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), FALSE);
+
+ int nb_contacts = db_get_dw((HANDLE)lParam, META_PROTO, "NumContacts", 0);
+ int default_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1);
+ int offline_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "OfflineSend", (DWORD)-1);
changes.hMeta = (HANDLE)lParam;
changes.num_contacts = nb_contacts;
@@ -355,230 +289,178 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
CheckDlgButton(hwndDlg, IDC_CHK_FORCEDEFAULT, changes.force_default);
FillContactList(hwndDlg, &changes);
- return TRUE;
}
- case WMU_SETTITLE:
- {
-
- char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, 0);
- if (os_unicode_enabled) {
- wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE),
- *swzContactDisplayName;
-
- // detect if the clist provided unicode display name by comparing with non-unicode
- if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0 && wcslen(swzCDN) >= strlen(szCDN)) {
- swzContactDisplayName = swzCDN;
- } else {
- // no? convert to unicode
- if (szCDN) {
- swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1));
- MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1);
- } else {
- swzContactDisplayName = TranslateW(L"(Unknown Contact)");
- }
- }
+ return TRUE;
+
+ case WMU_SETTITLE:
+ {
+ TCHAR *ptszCDN = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE);
+ if (ptszCDN == NULL)
+ ptszCDN = TranslateT("(Unknown Contact)");
- SetWindowTextW(GetDlgItem(hwndDlg,IDC_ED_NAME), swzContactDisplayName);
- } else {
- SetWindowText(GetDlgItem(hwndDlg,IDC_ED_NAME), szCDN);
+ SetWindowText(GetDlgItem(hwndDlg, IDC_ED_NAME), ptszCDN);
+ }
+ return TRUE;
+
+ case WM_NOTIFY: // the message that is being sent always
+ switch(LOWORD(wParam)) { // hit control
+ case IDC_LST_CONTACTS: // did we hit our ListView contorl?
+ if (((LPNMHDR)lParam)->code == NM_CLICK) {
+ sel = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LST_CONTACTS), -1, LVNI_FOCUSED|LVNI_SELECTED); // return item selected
+
+ // enable buttons
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), sel != -1);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), sel != -1 && changes.hContact[sel] != changes.hDefaultContact);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), sel != -1 && changes.hContact[sel] != changes.hOfflineContact);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), sel > 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel != -1 && sel < changes.num_contacts - 1));
+ }
+ }
+ break;
+
+ case WM_COMMAND:
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED: // A button ('Remove', 'Ok', 'Cancel' or 'Apply', normally) has been clicked
+ switch(LOWORD(wParam)) {
+ case IDC_VALIDATE: // Apply changes, if there is still one contact attached to the metacontact.
+ if (changes.num_contacts == 0) { // Otherwise, delete the metacontact.
+ if (IDYES == MessageBox(hwndDlg, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) {
+ Meta_Delete((WPARAM)changes.hMeta, 0);
+ DestroyWindow(hwndDlg);
+ }
+ return TRUE;
}
- }
- return TRUE;
- case WM_NOTIFY: // the message that is being sent always
- switch(LOWORD(wParam)) // hit control
- {
- case IDC_LST_CONTACTS: // did we hit our ListView contorl?
- if (((LPNMHDR)lParam)->code == NM_CLICK) {
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
- // enable buttons
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
- EnableWindow(hwnd, sel!=-1);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
- EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hDefaultContact);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
- EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hOfflineContact);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
- EnableWindow(hwnd, (sel > 0));
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
- EnableWindow(hwnd, (sel != -1) && (sel < changes.num_contacts - 1));
-/*
- // custom draw stuff - change colour of listview things - doesn't affect selection :(
- } else if (((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) {
- SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
- return TRUE;
-*/
- }
- break;
- }
- break;
- case WM_COMMAND:
- switch(HIWORD(wParam))
- {
- case BN_CLICKED: // A button ('Remove', 'Ok', 'Cancel' or 'Apply', normally) has been clicked
- switch(LOWORD(wParam))
- {
- case IDC_VALIDATE: // Apply changes, if there is still one contact attached to the metacontact.
- if (changes.num_contacts == 0) // Otherwise, delete the metacontact.
- {
- if (MessageBox(hwndDlg,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"),
- Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)!=IDYES)
- return TRUE;
- else
- {
- Meta_Delete((WPARAM)changes.hMeta,0);
- DestroyWindow(hwndDlg);
- return TRUE;
- }
- }
- ApplyChanges(&changes);
-
- // Disable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE);
- break;
- case IDOK:
- if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_VALIDATE)))
- { // If there are changes that could be made,
- if (changes.num_contacts == 0) // do the work that would have be done if
- { // the button 'Apply' has been clicked.
- if (MessageBox(hwndDlg,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"),
- Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)!=IDYES)
- {
- return TRUE;
- } else {
- Meta_Delete((WPARAM)changes.hMeta,0);
- DestroyWindow(hwndDlg);
- return TRUE;
- }
- }
- ApplyChanges(&changes);
- }
- EndDialog(hwndDlg, IDOK);
- return TRUE;
- case IDCANCEL: // Simply close the dialog
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- case IDC_BTN_SETDEFAULT:
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
- InvalidateRect(hwnd, 0, TRUE);
- changes.hDefaultContact = changes.hContact[sel];
- SendMessage(hwndDlg, WMU_SETTITLE, 0, (LPARAM)changes.hContact[sel]);
-
- FillContactList(hwndDlg, &changes);
- SetListSelection(hwnd, sel);
- // Disable set default button
- EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETDEFAULT),FALSE);
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
-
- // repaint list
- return TRUE;
- case IDC_BTN_SETOFFLINE:
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
- InvalidateRect(hwnd, 0, TRUE);
- changes.hOfflineContact = changes.hContact[sel];
-
- FillContactList(hwndDlg, &changes);
- SetListSelection(hwnd, sel);
- // Disable set offline button
- EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETOFFLINE),FALSE);
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
-
- // repaint list
- return TRUE;
- case IDC_BTN_REM:
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
- changes.num_contacts--;
- changes.hDeletedContacts[changes.num_deleted++] = changes.hContact[sel];
- if (changes.hDefaultContact == changes.hContact[sel]) {
- if (changes.num_contacts > 0) {
- changes.hDefaultContact = changes.hContact[0];
- str = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, 0);
- SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str);
- } else {
- changes.hDefaultContact = 0;
- SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),"None");
- }
-
- }
-
- for (i = sel; i < changes.num_contacts; i++)
- changes.hContact[i] = changes.hContact[i + 1];
- FillContactList(hwndDlg, &changes);
- // disable buttons
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
- EnableWindow(hwnd, FALSE);
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
- EnableWindow(hwnd, FALSE);
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
- return TRUE;
- case IDC_BTN_UP:
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
-
- {
- HANDLE temp = changes.hContact[sel];
- changes.hContact[sel] = changes.hContact[sel - 1];
- changes.hContact[sel - 1] = temp;
- }
- FillContactList(hwndDlg, &changes);
- sel--;
- SetListSelection(hwnd, sel);
-
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
- EnableWindow(hwnd, (sel > 0));
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
- EnableWindow(hwnd, (sel < changes.num_contacts - 1));
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
- return TRUE;
- case IDC_BTN_DOWN:
- hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
- sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected
-
- {
- HANDLE temp = changes.hContact[sel];
- changes.hContact[sel] = changes.hContact[sel + 1];
- changes.hContact[sel + 1] = temp;
- }
- FillContactList(hwndDlg, &changes);
- sel++;
- SetListSelection(hwnd, sel);
-
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP);
- EnableWindow(hwnd, (sel > 0));
- hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN);
- EnableWindow(hwnd, (sel < changes.num_contacts - 1));
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
- return TRUE;
- case IDC_CHK_FORCEDEFAULT:
- changes.force_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORCEDEFAULT);
- // Enable the 'Apply' button.
- EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
- return TRUE;
+ ApplyChanges(&changes);
+
+ // Disable the 'Apply' button.
+ EnableWindow(GetDlgItem(hwndDlg, IDC_VALIDATE), FALSE);
+ break;
+
+ case IDOK:
+ if ( IsWindowEnabled(GetDlgItem(hwndDlg, IDC_VALIDATE))) { // If there are changes that could be made,
+ if (changes.num_contacts == 0) { // do the work that would have be done if the 'Apply' button was clicked.
+ if (IDYES == MessageBox(hwndDlg, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) {
+ Meta_Delete((WPARAM)changes.hMeta,0);
+ DestroyWindow(hwndDlg);
+ }
+ return TRUE;
+ }
+ ApplyChanges(&changes);
+ }
+ EndDialog(hwndDlg, IDOK);
+ return TRUE;
+
+ case IDCANCEL: // Simply close the dialog
+ EndDialog(hwndDlg, IDCANCEL);
+ return TRUE;
+
+ case IDC_BTN_SETDEFAULT:
+ hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
+ sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
+ InvalidateRect(hwnd, 0, TRUE);
+ changes.hDefaultContact = changes.hContact[sel];
+ SendMessage(hwndDlg, WMU_SETTITLE, 0, (LPARAM)changes.hContact[sel]);
+
+ FillContactList(hwndDlg, &changes);
+ SetListSelection(hwnd, sel);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETDEFAULT),FALSE);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
+
+ case IDC_BTN_SETOFFLINE:
+ hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
+ sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
+ InvalidateRect(hwnd, 0, TRUE);
+ changes.hOfflineContact = changes.hContact[sel];
+
+ FillContactList(hwndDlg, &changes);
+ SetListSelection(hwnd, sel);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETOFFLINE),FALSE);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
+
+ case IDC_BTN_REM:
+ hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
+ sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
+ changes.num_contacts--;
+ changes.hDeletedContacts[changes.num_deleted++] = changes.hContact[sel];
+ if (changes.hDefaultContact == changes.hContact[sel]) {
+ if (changes.num_contacts > 0) {
+ changes.hDefaultContact = changes.hContact[0];
+ TCHAR *str = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, GCDNF_TCHAR);
+ SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str);
}
+ else {
+ changes.hDefaultContact = 0;
+ SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT), _T("None"));
+ }
+ }
+
+ for (i = sel; i < changes.num_contacts; i++)
+ changes.hContact[i] = changes.hContact[i + 1];
+ FillContactList(hwndDlg, &changes);
+
+ // disable buttons
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), FALSE);
+
+ // Enable the 'Apply' button.
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
+
+ case IDC_BTN_UP:
+ hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
+ sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
+ {
+ HANDLE temp = changes.hContact[sel];
+ changes.hContact[sel] = changes.hContact[sel - 1];
+ changes.hContact[sel - 1] = temp;
+ }
+ FillContactList(hwndDlg, &changes);
+ sel--;
+ SetListSelection(hwnd, sel);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), (sel > 0));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel < changes.num_contacts - 1));
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
+
+ case IDC_BTN_DOWN:
+ hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS);
+ sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
+ {
+ HANDLE temp = changes.hContact[sel];
+ changes.hContact[sel] = changes.hContact[sel + 1];
+ changes.hContact[sel + 1] = temp;
+ }
+ FillContactList(hwndDlg, &changes);
+ sel++;
+ SetListSelection(hwnd, sel);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), (sel > 0));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel < changes.num_contacts - 1));
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
+
+ case IDC_CHK_FORCEDEFAULT:
+ changes.force_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORCEDEFAULT);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE);
+ return TRUE;
}
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- return TRUE;
-
- case WM_DESTROY:
- ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
- EndDialog(hwndDlg, IDCANCEL);
- break;
+ }
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hwndDlg);
+ return TRUE;
+
+ case WM_DESTROY:
+ ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
+ EndDialog(hwndDlg, IDCANCEL);
+ break;
}
return FALSE;